From 6de583e13793df5e4481d91237b607daee5048a5 Mon Sep 17 00:00:00 2001 From: Ondrej Holy Date: Wed, 22 Aug 2018 13:14:45 +0200 Subject: [PATCH] core/gateway/rpc: Format code by astyle Run ./scripts/format_code.sh before the following changes. --- libfreerdp/core/gateway/rpc.c | 8 +++--- libfreerdp/core/gateway/rpc_bind.c | 54 +++++--------------------------------- 2 files changed, 12 insertions(+), 50 deletions(-) diff --git a/libfreerdp/core/gateway/rpc.c b/libfreerdp/core/gateway/rpc.c index 24e7143..d01e309 100644 --- a/libfreerdp/core/gateway/rpc.c +++ b/libfreerdp/core/gateway/rpc.c @@ -734,8 +734,9 @@ static int rpc_channel_tls_connect(RpcChannel* channel, int timeout) rdpSettings* settings = context->settings; const char* peerHostname = settings->GatewayHostname; UINT16 peerPort = settings->GatewayPort; - const char *proxyUsername = settings->ProxyUsername, *proxyPassword = settings->ProxyPassword; - BOOL isProxyConnection = proxy_prepare(settings, &peerHostname, &peerPort, &proxyUsername, &proxyPassword); + const char* proxyUsername = settings->ProxyUsername, *proxyPassword = settings->ProxyPassword; + BOOL isProxyConnection = proxy_prepare(settings, &peerHostname, &peerPort, &proxyUsername, + &proxyPassword); sockfd = freerdp_tcp_connect(context, settings, peerHostname, peerPort, timeout); @@ -760,7 +761,8 @@ static int rpc_channel_tls_connect(RpcChannel* channel, int timeout) if (isProxyConnection) { - if (!proxy_connect(settings, bufferedBio, proxyUsername, proxyPassword, settings->GatewayHostname, settings->GatewayPort)) + if (!proxy_connect(settings, bufferedBio, proxyUsername, proxyPassword, settings->GatewayHostname, + settings->GatewayPort)) return -1; } diff --git a/libfreerdp/core/gateway/rpc_bind.c b/libfreerdp/core/gateway/rpc_bind.c index 906134c..54fd322 100644 --- a/libfreerdp/core/gateway/rpc_bind.c +++ b/libfreerdp/core/gateway/rpc_bind.c @@ -119,9 +119,7 @@ int rpc_send_bind_pdu(rdpRpc* rpc) freerdp* instance = (freerdp*) settings->instance; RpcVirtualConnection* connection = rpc->VirtualConnection; RpcInChannel* inChannel = connection->DefaultInChannel; - WLog_DBG(TAG, "Sending Bind PDU"); - ntlm_free(rpc->ntlm); rpc->ntlm = ntlm_new(); @@ -129,7 +127,7 @@ int rpc_send_bind_pdu(rdpRpc* rpc) return -1; if ((!settings->GatewayPassword) || (!settings->GatewayUsername) - || (!strlen(settings->GatewayPassword)) || (!strlen(settings->GatewayUsername))) + || (!strlen(settings->GatewayPassword)) || (!strlen(settings->GatewayUsername))) { promptPassword = TRUE; } @@ -139,7 +137,7 @@ int rpc_send_bind_pdu(rdpRpc* rpc) if (instance->GatewayAuthenticate) { BOOL proceed = instance->GatewayAuthenticate(instance, - &settings->GatewayUsername, &settings->GatewayPassword, &settings->GatewayDomain); + &settings->GatewayUsername, &settings->GatewayPassword, &settings->GatewayDomain); if (!proceed) { @@ -159,7 +157,8 @@ int rpc_send_bind_pdu(rdpRpc* rpc) } } - if (!ntlm_client_init(rpc->ntlm, FALSE, settings->GatewayUsername, settings->GatewayDomain, settings->GatewayPassword, NULL)) + if (!ntlm_client_init(rpc->ntlm, FALSE, settings->GatewayUsername, settings->GatewayDomain, + settings->GatewayPassword, NULL)) return -1; if (!ntlm_client_make_spn(rpc->ntlm, NULL, settings->GatewayHostname)) @@ -174,35 +173,29 @@ int rpc_send_bind_pdu(rdpRpc* rpc) return -1; rpc_pdu_header_init(rpc, (rpcconn_hdr_t*) bind_pdu); - bind_pdu->auth_length = (UINT16) rpc->ntlm->outputBuffer[0].cbBuffer; bind_pdu->auth_verifier.auth_value = rpc->ntlm->outputBuffer[0].pvBuffer; - bind_pdu->ptype = PTYPE_BIND; bind_pdu->pfc_flags = PFC_FIRST_FRAG | PFC_LAST_FRAG | PFC_SUPPORT_HEADER_SIGN | PFC_CONC_MPX; bind_pdu->call_id = 2; - bind_pdu->max_xmit_frag = rpc->max_xmit_frag; bind_pdu->max_recv_frag = rpc->max_recv_frag; bind_pdu->assoc_group_id = 0; - bind_pdu->p_context_elem.n_context_elem = 2; bind_pdu->p_context_elem.reserved = 0; bind_pdu->p_context_elem.reserved2 = 0; - - bind_pdu->p_context_elem.p_cont_elem = calloc(bind_pdu->p_context_elem.n_context_elem, sizeof(p_cont_elem_t)); + bind_pdu->p_context_elem.p_cont_elem = calloc(bind_pdu->p_context_elem.n_context_elem, + sizeof(p_cont_elem_t)); if (!bind_pdu->p_context_elem.p_cont_elem) return -1; p_cont_elem = &bind_pdu->p_context_elem.p_cont_elem[0]; - p_cont_elem->p_cont_id = 0; p_cont_elem->n_transfer_syn = 1; p_cont_elem->reserved = 0; CopyMemory(&(p_cont_elem->abstract_syntax.if_uuid), &TSGU_UUID, sizeof(p_uuid_t)); p_cont_elem->abstract_syntax.if_version = TSGU_SYNTAX_IF_VERSION; - p_cont_elem->transfer_syntaxes = malloc(sizeof(p_syntax_id_t)); if (!p_cont_elem->transfer_syntaxes) @@ -210,15 +203,12 @@ int rpc_send_bind_pdu(rdpRpc* rpc) CopyMemory(&(p_cont_elem->transfer_syntaxes[0].if_uuid), &NDR_UUID, sizeof(p_uuid_t)); p_cont_elem->transfer_syntaxes[0].if_version = NDR_SYNTAX_IF_VERSION; - p_cont_elem = &bind_pdu->p_context_elem.p_cont_elem[1]; - p_cont_elem->p_cont_id = 1; p_cont_elem->n_transfer_syn = 1; p_cont_elem->reserved = 0; CopyMemory(&(p_cont_elem->abstract_syntax.if_uuid), &TSGU_UUID, sizeof(p_uuid_t)); p_cont_elem->abstract_syntax.if_version = TSGU_SYNTAX_IF_VERSION; - p_cont_elem->transfer_syntaxes = malloc(sizeof(p_syntax_id_t)); if (!p_cont_elem->transfer_syntaxes) @@ -226,18 +216,14 @@ int rpc_send_bind_pdu(rdpRpc* rpc) CopyMemory(&(p_cont_elem->transfer_syntaxes[0].if_uuid), &BTFN_UUID, sizeof(p_uuid_t)); p_cont_elem->transfer_syntaxes[0].if_version = BTFN_SYNTAX_IF_VERSION; - offset = 116; bind_pdu->auth_verifier.auth_pad_length = rpc_offset_align(&offset, 4); - bind_pdu->auth_verifier.auth_type = RPC_C_AUTHN_WINNT; bind_pdu->auth_verifier.auth_level = RPC_C_AUTHN_LEVEL_PKT_INTEGRITY; bind_pdu->auth_verifier.auth_reserved = 0x00; bind_pdu->auth_verifier.auth_context_id = 0x00000000; offset += (8 + bind_pdu->auth_length); - bind_pdu->frag_length = offset; - buffer = (BYTE*) malloc(bind_pdu->frag_length); if (!buffer) @@ -249,16 +235,12 @@ int rpc_send_bind_pdu(rdpRpc* rpc) CopyMemory(&buffer[52], bind_pdu->p_context_elem.p_cont_elem[0].transfer_syntaxes, 20); CopyMemory(&buffer[72], &bind_pdu->p_context_elem.p_cont_elem[1], 24); CopyMemory(&buffer[96], bind_pdu->p_context_elem.p_cont_elem[1].transfer_syntaxes, 20); - offset = 116; rpc_offset_pad(&offset, bind_pdu->auth_verifier.auth_pad_length); - CopyMemory(&buffer[offset], &bind_pdu->auth_verifier.auth_type, 8); CopyMemory(&buffer[offset + 8], bind_pdu->auth_verifier.auth_value, bind_pdu->auth_length); offset += (8 + bind_pdu->auth_length); - length = bind_pdu->frag_length; - clientCall = rpc_client_call_new(bind_pdu->call_id, 0); if (!clientCall) @@ -274,14 +256,11 @@ int rpc_send_bind_pdu(rdpRpc* rpc) } status = rpc_in_channel_send_pdu(inChannel, buffer, length); - free(bind_pdu->p_context_elem.p_cont_elem[0].transfer_syntaxes); free(bind_pdu->p_context_elem.p_cont_elem[1].transfer_syntaxes); free(bind_pdu->p_context_elem.p_cont_elem); free(bind_pdu); - free(buffer); - return (status > 0) ? 1 : -1; } @@ -312,14 +291,10 @@ int rpc_recv_bind_ack_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length) { BYTE* auth_data; rpcconn_hdr_t* header; - header = (rpcconn_hdr_t*) buffer; - WLog_DBG(TAG, "Receiving BindAck PDU"); - rpc->max_recv_frag = header->bind_ack.max_xmit_frag; rpc->max_xmit_frag = header->bind_ack.max_recv_frag; - rpc->ntlm->inputBuffer[0].cbBuffer = header->common.auth_length; rpc->ntlm->inputBuffer[0].pvBuffer = malloc(header->common.auth_length); @@ -328,9 +303,7 @@ int rpc_recv_bind_ack_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length) auth_data = buffer + (header->common.frag_length - header->common.auth_length); CopyMemory(rpc->ntlm->inputBuffer[0].pvBuffer, auth_data, header->common.auth_length); - ntlm_authenticate(rpc->ntlm); - return (int) length; } @@ -351,54 +324,42 @@ int rpc_send_rpc_auth_3_pdu(rdpRpc* rpc) rpcconn_rpc_auth_3_hdr_t* auth_3_pdu; RpcVirtualConnection* connection = rpc->VirtualConnection; RpcInChannel* inChannel = connection->DefaultInChannel; - WLog_DBG(TAG, "Sending RpcAuth3 PDU"); - auth_3_pdu = (rpcconn_rpc_auth_3_hdr_t*) calloc(1, sizeof(rpcconn_rpc_auth_3_hdr_t)); if (!auth_3_pdu) return -1; rpc_pdu_header_init(rpc, (rpcconn_hdr_t*) auth_3_pdu); - auth_3_pdu->auth_length = (UINT16) rpc->ntlm->outputBuffer[0].cbBuffer; auth_3_pdu->auth_verifier.auth_value = rpc->ntlm->outputBuffer[0].pvBuffer; - auth_3_pdu->ptype = PTYPE_RPC_AUTH_3; auth_3_pdu->pfc_flags = PFC_FIRST_FRAG | PFC_LAST_FRAG | PFC_CONC_MPX; auth_3_pdu->call_id = 2; - auth_3_pdu->max_xmit_frag = rpc->max_xmit_frag; auth_3_pdu->max_recv_frag = rpc->max_recv_frag; - offset = 20; auth_3_pdu->auth_verifier.auth_pad_length = rpc_offset_align(&offset, 4); - auth_3_pdu->auth_verifier.auth_type = RPC_C_AUTHN_WINNT; auth_3_pdu->auth_verifier.auth_level = RPC_C_AUTHN_LEVEL_PKT_INTEGRITY; auth_3_pdu->auth_verifier.auth_reserved = 0x00; auth_3_pdu->auth_verifier.auth_context_id = 0x00000000; offset += (8 + auth_3_pdu->auth_length); - auth_3_pdu->frag_length = offset; - buffer = (BYTE*) malloc(auth_3_pdu->frag_length); if (!buffer) return -1; CopyMemory(buffer, auth_3_pdu, 20); - offset = 20; rpc_offset_pad(&offset, auth_3_pdu->auth_verifier.auth_pad_length); - CopyMemory(&buffer[offset], &auth_3_pdu->auth_verifier.auth_type, 8); CopyMemory(&buffer[offset + 8], auth_3_pdu->auth_verifier.auth_value, auth_3_pdu->auth_length); offset += (8 + auth_3_pdu->auth_length); - length = auth_3_pdu->frag_length; - clientCall = rpc_client_call_new(auth_3_pdu->call_id, 0); + if (ArrayList_Add(rpc->client->ClientCallList, clientCall) >= 0) { status = rpc_in_channel_send_pdu(inChannel, buffer, length); @@ -406,6 +367,5 @@ int rpc_send_rpc_auth_3_pdu(rdpRpc* rpc) free(auth_3_pdu); free(buffer); - return (status > 0) ? 1 : -1; } -- 2.7.4