TSG improvements

* Respect connection timeout during connect
* Better debug output
* Cleaned up data types,
This commit is contained in:
Armin Novak 2020-06-17 08:41:21 +02:00 committed by akallabeth
parent 529e30c273
commit ff79636d33
16 changed files with 402 additions and 216 deletions

View File

@ -1167,7 +1167,7 @@ static BOOL rdg_tunnel_connect(rdpRdg* rdg)
return TRUE;
}
BOOL rdg_connect(rdpRdg* rdg, int timeout, BOOL* rpcFallback)
BOOL rdg_connect(rdpRdg* rdg, DWORD timeout, BOOL* rpcFallback)
{
BOOL status;
SOCKET outConnSocket = 0;

View File

@ -44,7 +44,7 @@ FREERDP_LOCAL void rdg_free(rdpRdg* rdg);
FREERDP_LOCAL BIO* rdg_get_front_bio_and_take_ownership(rdpRdg* rdg);
FREERDP_LOCAL BOOL rdg_connect(rdpRdg* rdg, int timeout, BOOL* rpcFallback);
FREERDP_LOCAL BOOL rdg_connect(rdpRdg* rdg, DWORD timeout, BOOL* rpcFallback);
FREERDP_LOCAL DWORD rdg_get_event_handles(rdpRdg* rdg, HANDLE* events, DWORD count);
#endif /* FREERDP_LIB_CORE_GATEWAY_RDG_H */

View File

@ -139,14 +139,14 @@ void rpc_pdu_header_print(rpcconn_hdr_t* header)
}
}
void rpc_pdu_header_init(rdpRpc* rpc, rpcconn_hdr_t* header)
void rpc_pdu_header_init(rdpRpc* rpc, rpcconn_common_hdr_t* header)
{
header->common.rpc_vers = rpc->rpc_vers;
header->common.rpc_vers_minor = rpc->rpc_vers_minor;
header->common.packed_drep[0] = rpc->packed_drep[0];
header->common.packed_drep[1] = rpc->packed_drep[1];
header->common.packed_drep[2] = rpc->packed_drep[2];
header->common.packed_drep[3] = rpc->packed_drep[3];
header->rpc_vers = rpc->rpc_vers;
header->rpc_vers_minor = rpc->rpc_vers_minor;
header->packed_drep[0] = rpc->packed_drep[0];
header->packed_drep[1] = rpc->packed_drep[1];
header->packed_drep[2] = rpc->packed_drep[2];
header->packed_drep[3] = rpc->packed_drep[3];
}
UINT32 rpc_offset_align(UINT32* offset, UINT32 alignment)

View File

@ -34,21 +34,23 @@ typedef struct rdp_rpc rdpRpc;
#pragma pack(push, 1)
#define DEFINE_RPC_COMMON_FIELDS() \
BYTE rpc_vers; \
BYTE rpc_vers_minor; \
BYTE ptype; \
BYTE pfc_flags; \
BYTE packed_drep[4]; \
UINT16 frag_length; \
UINT16 auth_length; \
UINT32 call_id
typedef struct
{
BYTE rpc_vers;
BYTE rpc_vers_minor;
BYTE ptype;
BYTE pfc_flags;
BYTE packed_drep[4];
UINT16 frag_length;
UINT16 auth_length;
UINT32 call_id;
} rpcconn_common_hdr_t;
#define RPC_COMMON_FIELDS_LENGTH 16
#define RPC_COMMON_FIELDS_LENGTH sizeof(rpcconn_common_hdr_t)
typedef struct
{
DEFINE_RPC_COMMON_FIELDS();
rpcconn_common_hdr_t header;
UINT16 Flags;
UINT16 NumberOfCommands;
@ -141,11 +143,6 @@ typedef struct _RPC_PDU
#pragma pack(push, 1)
typedef struct
{
DEFINE_RPC_COMMON_FIELDS();
} rpcconn_common_hdr_t;
typedef UINT16 p_context_id_t;
typedef UINT16 p_reject_reason_t;
@ -314,7 +311,7 @@ typedef struct auth_verifier_co_s auth_verifier_co_t;
typedef struct
{
DEFINE_RPC_COMMON_FIELDS();
rpcconn_common_hdr_t header;
UINT16 max_xmit_frag;
UINT16 max_recv_frag;
@ -328,7 +325,7 @@ typedef struct
typedef struct
{
DEFINE_RPC_COMMON_FIELDS();
rpcconn_common_hdr_t header;
UINT16 max_xmit_frag;
UINT16 max_recv_frag;
@ -345,7 +342,7 @@ typedef struct
/* bind header */
typedef struct
{
DEFINE_RPC_COMMON_FIELDS();
rpcconn_common_hdr_t header;
UINT16 max_xmit_frag;
UINT16 max_recv_frag;
@ -358,7 +355,7 @@ typedef struct
typedef struct
{
DEFINE_RPC_COMMON_FIELDS();
rpcconn_common_hdr_t header;
UINT16 max_xmit_frag;
UINT16 max_recv_frag;
@ -375,7 +372,7 @@ typedef struct
typedef struct
{
DEFINE_RPC_COMMON_FIELDS();
rpcconn_common_hdr_t header;
UINT16 max_xmit_frag;
UINT16 max_recv_frag;
@ -385,7 +382,7 @@ typedef struct
typedef struct
{
DEFINE_RPC_COMMON_FIELDS();
rpcconn_common_hdr_t header;
p_reject_reason_t provider_reject_reason;
@ -394,7 +391,7 @@ typedef struct
typedef struct
{
DEFINE_RPC_COMMON_FIELDS();
rpcconn_common_hdr_t header;
auth_verifier_co_t auth_verifier;
@ -460,7 +457,7 @@ typedef struct _RPC_FAULT_CODE RPC_FAULT_CODE;
typedef struct
{
DEFINE_RPC_COMMON_FIELDS();
rpcconn_common_hdr_t header;
UINT32 alloc_hint;
p_context_id_t p_cont_id;
@ -479,14 +476,14 @@ typedef struct
typedef struct
{
DEFINE_RPC_COMMON_FIELDS();
rpcconn_common_hdr_t header;
auth_verifier_co_t auth_verifier;
} rpcconn_orphaned_hdr_t;
typedef struct
{
DEFINE_RPC_COMMON_FIELDS();
rpcconn_common_hdr_t header;
UINT32 alloc_hint;
@ -505,7 +502,7 @@ typedef struct
typedef struct
{
DEFINE_RPC_COMMON_FIELDS();
rpcconn_common_hdr_t header;
UINT32 alloc_hint;
p_context_id_t p_cont_id;
@ -522,7 +519,7 @@ typedef struct
typedef struct
{
DEFINE_RPC_COMMON_FIELDS();
rpcconn_common_hdr_t header;
} rpcconn_shutdown_hdr_t;
typedef union {
@ -768,7 +765,7 @@ struct rdp_rpc
};
FREERDP_LOCAL void rpc_pdu_header_print(rpcconn_hdr_t* header);
FREERDP_LOCAL void rpc_pdu_header_init(rdpRpc* rpc, rpcconn_hdr_t* header);
FREERDP_LOCAL void rpc_pdu_header_init(rdpRpc* rpc, rpcconn_common_hdr_t* header);
FREERDP_LOCAL UINT32 rpc_offset_align(UINT32* offset, UINT32 alignment);
FREERDP_LOCAL UINT32 rpc_offset_pad(UINT32* offset, UINT32 pad);

View File

@ -190,12 +190,13 @@ int rpc_send_bind_pdu(rdpRpc* rpc)
if (!sbuffer)
goto fail;
rpc_pdu_header_init(rpc, (rpcconn_hdr_t*)bind_pdu);
bind_pdu->auth_length = (UINT16)sbuffer->cbBuffer;
rpc_pdu_header_init(rpc, &bind_pdu->header);
bind_pdu->header.auth_length = (UINT16)sbuffer->cbBuffer;
bind_pdu->auth_verifier.auth_value = sbuffer->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->header.ptype = PTYPE_BIND;
bind_pdu->header.pfc_flags =
PFC_FIRST_FRAG | PFC_LAST_FRAG | PFC_SUPPORT_HEADER_SIGN | PFC_CONC_MPX;
bind_pdu->header.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;
@ -240,9 +241,9 @@ int rpc_send_bind_pdu(rdpRpc* rpc)
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);
offset += (8 + bind_pdu->header.auth_length);
bind_pdu->header.frag_length = offset;
buffer = (BYTE*)malloc(bind_pdu->header.frag_length);
if (!buffer)
goto fail;
@ -256,10 +257,11 @@ int rpc_send_bind_pdu(rdpRpc* rpc)
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);
CopyMemory(&buffer[offset + 8], bind_pdu->auth_verifier.auth_value,
bind_pdu->header.auth_length);
offset += (8 + bind_pdu->header.auth_length);
length = bind_pdu->header.frag_length;
clientCall = rpc_client_call_new(bind_pdu->header.call_id, 0);
if (!clientCall)
goto fail;
@ -374,12 +376,12 @@ int rpc_send_rpc_auth_3_pdu(rdpRpc* rpc)
return -1;
}
rpc_pdu_header_init(rpc, (rpcconn_hdr_t*)auth_3_pdu);
auth_3_pdu->auth_length = (UINT16)sbuffer->cbBuffer;
rpc_pdu_header_init(rpc, &auth_3_pdu->header);
auth_3_pdu->header.auth_length = (UINT16)sbuffer->cbBuffer;
auth_3_pdu->auth_verifier.auth_value = sbuffer->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->header.ptype = PTYPE_RPC_AUTH_3;
auth_3_pdu->header.pfc_flags = PFC_FIRST_FRAG | PFC_LAST_FRAG | PFC_CONC_MPX;
auth_3_pdu->header.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;
@ -388,9 +390,9 @@ int rpc_send_rpc_auth_3_pdu(rdpRpc* rpc)
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);
offset += (8 + auth_3_pdu->header.auth_length);
auth_3_pdu->header.frag_length = offset;
buffer = (BYTE*)malloc(auth_3_pdu->header.frag_length);
if (!buffer)
{
@ -402,10 +404,11 @@ int rpc_send_rpc_auth_3_pdu(rdpRpc* rpc)
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);
CopyMemory(&buffer[offset + 8], auth_3_pdu->auth_verifier.auth_value,
auth_3_pdu->header.auth_length);
offset += (8 + auth_3_pdu->header.auth_length);
length = auth_3_pdu->header.frag_length;
clientCall = rpc_client_call_new(auth_3_pdu->header.call_id, 0);
if (ArrayList_Add(rpc->client->ClientCallList, clientCall) >= 0)
{

View File

@ -895,7 +895,7 @@ BOOL rpc_client_write_call(rdpRpc* rpc, wStream* s, UINT16 opnum)
SecBufferDesc Message;
RpcClientCall* clientCall = NULL;
rdpNtlm* ntlm;
rpcconn_request_hdr_t* request_pdu = NULL;
rpcconn_request_hdr_t request_pdu = { 0 };
RpcVirtualConnection* connection;
RpcInChannel* inChannel;
size_t length;
@ -931,25 +931,20 @@ BOOL rpc_client_write_call(rdpRpc* rpc, wStream* s, UINT16 opnum)
if (ntlm_client_query_auth_size(ntlm) < 0)
goto fail;
request_pdu = (rpcconn_request_hdr_t*)calloc(1, sizeof(rpcconn_request_hdr_t));
if (!request_pdu)
goto fail;
size = ntlm_client_get_context_max_size(ntlm);
if (size < 0)
goto fail;
rpc_pdu_header_init(rpc, (rpcconn_hdr_t*)request_pdu);
request_pdu->ptype = PTYPE_REQUEST;
request_pdu->pfc_flags = PFC_FIRST_FRAG | PFC_LAST_FRAG;
request_pdu->auth_length = (UINT16)size;
request_pdu->call_id = rpc->CallId++;
request_pdu->alloc_hint = length;
request_pdu->p_cont_id = 0x0000;
request_pdu->opnum = opnum;
clientCall = rpc_client_call_new(request_pdu->call_id, request_pdu->opnum);
rpc_pdu_header_init(rpc, &request_pdu.header);
request_pdu.header.ptype = PTYPE_REQUEST;
request_pdu.header.pfc_flags = PFC_FIRST_FRAG | PFC_LAST_FRAG;
request_pdu.header.auth_length = (UINT16)size;
request_pdu.header.call_id = rpc->CallId++;
request_pdu.alloc_hint = length;
request_pdu.p_cont_id = 0x0000;
request_pdu.opnum = opnum;
clientCall = rpc_client_call_new(request_pdu.header.call_id, request_pdu.opnum);
if (!clientCall)
goto fail;
@ -960,32 +955,32 @@ BOOL rpc_client_write_call(rdpRpc* rpc, wStream* s, UINT16 opnum)
goto fail;
}
if (request_pdu->opnum == TsProxySetupReceivePipeOpnum)
rpc->PipeCallId = request_pdu->call_id;
if (request_pdu.opnum == TsProxySetupReceivePipeOpnum)
rpc->PipeCallId = request_pdu.header.call_id;
request_pdu->stub_data = Stream_Buffer(s);
request_pdu.stub_data = Stream_Buffer(s);
offset = 24;
stub_data_pad = rpc_offset_align(&offset, 8);
offset += length;
request_pdu->auth_verifier.auth_pad_length = rpc_offset_align(&offset, 4);
request_pdu->auth_verifier.auth_type = RPC_C_AUTHN_WINNT;
request_pdu->auth_verifier.auth_level = RPC_C_AUTHN_LEVEL_PKT_INTEGRITY;
request_pdu->auth_verifier.auth_reserved = 0x00;
request_pdu->auth_verifier.auth_context_id = 0x00000000;
offset += (8 + request_pdu->auth_length);
request_pdu->frag_length = offset;
buffer = (BYTE*)calloc(1, request_pdu->frag_length);
request_pdu.auth_verifier.auth_pad_length = rpc_offset_align(&offset, 4);
request_pdu.auth_verifier.auth_type = RPC_C_AUTHN_WINNT;
request_pdu.auth_verifier.auth_level = RPC_C_AUTHN_LEVEL_PKT_INTEGRITY;
request_pdu.auth_verifier.auth_reserved = 0x00;
request_pdu.auth_verifier.auth_context_id = 0x00000000;
offset += (8 + request_pdu.header.auth_length);
request_pdu.header.frag_length = offset;
buffer = (BYTE*)calloc(1, request_pdu.header.frag_length);
if (!buffer)
goto fail;
CopyMemory(buffer, request_pdu, 24);
CopyMemory(buffer, &request_pdu, 24);
offset = 24;
rpc_offset_pad(&offset, stub_data_pad);
CopyMemory(&buffer[offset], request_pdu->stub_data, length);
CopyMemory(&buffer[offset], request_pdu.stub_data, length);
offset += length;
rpc_offset_pad(&offset, request_pdu->auth_verifier.auth_pad_length);
CopyMemory(&buffer[offset], &request_pdu->auth_verifier.auth_type, 8);
rpc_offset_pad(&offset, request_pdu.auth_verifier.auth_pad_length);
CopyMemory(&buffer[offset], &request_pdu.auth_verifier.auth_type, 8);
offset += 8;
Buffers[0].BufferType = SECBUFFER_DATA; /* auth_data */
Buffers[1].BufferType = SECBUFFER_TOKEN; /* signature */
@ -1007,14 +1002,13 @@ BOOL rpc_client_write_call(rdpRpc* rpc, wStream* s, UINT16 opnum)
CopyMemory(&buffer[offset], Buffers[1].pvBuffer, Buffers[1].cbBuffer);
offset += Buffers[1].cbBuffer;
if (rpc_in_channel_send_pdu(inChannel, buffer, request_pdu->frag_length) < 0)
if (rpc_in_channel_send_pdu(inChannel, buffer, request_pdu.header.frag_length) < 0)
goto fail;
rc = TRUE;
fail:
free(buffer);
free(Buffers[1].pvBuffer);
free(request_pdu);
Stream_Free(s, TRUE);
return rc;
}

View File

@ -67,19 +67,21 @@
*
*/
static void rts_pdu_header_init(rpcconn_rts_hdr_t* header)
static rpcconn_rts_hdr_t rts_pdu_header_init(void)
{
ZeroMemory(header, sizeof(*header));
header->rpc_vers = 5;
header->rpc_vers_minor = 0;
header->ptype = PTYPE_RTS;
header->packed_drep[0] = 0x10;
header->packed_drep[1] = 0x00;
header->packed_drep[2] = 0x00;
header->packed_drep[3] = 0x00;
header->pfc_flags = PFC_FIRST_FRAG | PFC_LAST_FRAG;
header->auth_length = 0;
header->call_id = 0;
rpcconn_rts_hdr_t header = { 0 };
header.header.rpc_vers = 5;
header.header.rpc_vers_minor = 0;
header.header.ptype = PTYPE_RTS;
header.header.packed_drep[0] = 0x10;
header.header.packed_drep[1] = 0x00;
header.header.packed_drep[2] = 0x00;
header.header.packed_drep[3] = 0x00;
header.header.pfc_flags = PFC_FIRST_FRAG | PFC_LAST_FRAG;
header.header.auth_length = 0;
header.header.call_id = 0;
return header;
}
static int rts_receive_window_size_command_read(rdpRpc* rpc, BYTE* buffer, UINT32 length,
@ -406,21 +408,21 @@ int rts_send_CONN_A1_pdu(rdpRpc* rpc)
{
int status;
BYTE* buffer;
rpcconn_rts_hdr_t header;
rpcconn_rts_hdr_t header = rts_pdu_header_init();
UINT32 ReceiveWindowSize;
BYTE* OUTChannelCookie;
BYTE* VirtualConnectionCookie;
RpcVirtualConnection* connection = rpc->VirtualConnection;
RpcOutChannel* outChannel = connection->DefaultOutChannel;
rts_pdu_header_init(&header);
header.frag_length = 76;
header.header.frag_length = 76;
header.Flags = RTS_FLAG_NONE;
header.NumberOfCommands = 4;
WLog_DBG(TAG, "Sending CONN/A1 RTS PDU");
VirtualConnectionCookie = (BYTE*)&(connection->Cookie);
OUTChannelCookie = (BYTE*)&(outChannel->common.Cookie);
ReceiveWindowSize = outChannel->ReceiveWindow;
buffer = (BYTE*)malloc(header.frag_length);
buffer = (BYTE*)malloc(header.header.frag_length);
if (!buffer)
return -1;
@ -432,7 +434,7 @@ int rts_send_CONN_A1_pdu(rdpRpc* rpc)
rts_cookie_command_write(&buffer[48], OUTChannelCookie); /* OUTChannelCookie (20 bytes) */
rts_receive_window_size_command_write(&buffer[68],
ReceiveWindowSize); /* ReceiveWindowSize (8 bytes) */
status = rpc_channel_write(&outChannel->common, buffer, header.frag_length);
status = rpc_channel_write(&outChannel->common, buffer, header.header.frag_length);
free(buffer);
return (status > 0) ? 1 : -1;
}
@ -453,21 +455,21 @@ int rts_send_CONN_B1_pdu(rdpRpc* rpc)
int status;
BYTE* buffer;
UINT32 length;
rpcconn_rts_hdr_t header;
rpcconn_rts_hdr_t header = rts_pdu_header_init();
BYTE* INChannelCookie;
BYTE* AssociationGroupId;
BYTE* VirtualConnectionCookie;
RpcVirtualConnection* connection = rpc->VirtualConnection;
RpcInChannel* inChannel = connection->DefaultInChannel;
rts_pdu_header_init(&header);
header.frag_length = 104;
header.header.frag_length = 104;
header.Flags = RTS_FLAG_NONE;
header.NumberOfCommands = 6;
WLog_DBG(TAG, "Sending CONN/B1 RTS PDU");
VirtualConnectionCookie = (BYTE*)&(connection->Cookie);
INChannelCookie = (BYTE*)&(inChannel->common.Cookie);
AssociationGroupId = (BYTE*)&(connection->AssociationGroupId);
buffer = (BYTE*)malloc(header.frag_length);
buffer = (BYTE*)malloc(header.header.frag_length);
if (!buffer)
return -1;
@ -483,7 +485,7 @@ int rts_send_CONN_B1_pdu(rdpRpc* rpc)
rpc->KeepAliveInterval); /* ClientKeepalive (8 bytes) */
rts_association_group_id_command_write(&buffer[84],
AssociationGroupId); /* AssociationGroupId (20 bytes) */
length = header.frag_length;
length = header.header.frag_length;
status = rpc_channel_write(&inChannel->common, buffer, length);
free(buffer);
return (status > 0) ? 1 : -1;
@ -520,14 +522,14 @@ static int rts_send_keep_alive_pdu(rdpRpc* rpc)
int status;
BYTE* buffer;
UINT32 length;
rpcconn_rts_hdr_t header;
rpcconn_rts_hdr_t header = rts_pdu_header_init();
RpcInChannel* inChannel = rpc->VirtualConnection->DefaultInChannel;
rts_pdu_header_init(&header);
header.frag_length = 28;
header.header.frag_length = 28;
header.Flags = RTS_FLAG_OTHER_CMD;
header.NumberOfCommands = 1;
WLog_DBG(TAG, "Sending Keep-Alive RTS PDU");
buffer = (BYTE*)malloc(header.frag_length);
buffer = (BYTE*)malloc(header.header.frag_length);
if (!buffer)
return -1;
@ -535,7 +537,7 @@ static int rts_send_keep_alive_pdu(rdpRpc* rpc)
CopyMemory(buffer, ((BYTE*)&header), 20); /* RTS Header (20 bytes) */
rts_client_keepalive_command_write(
&buffer[20], rpc->CurrentKeepAliveInterval); /* ClientKeepAlive (8 bytes) */
length = header.frag_length;
length = header.header.frag_length;
status = rpc_channel_write(&inChannel->common, buffer, length);
free(buffer);
return (status > 0) ? 1 : -1;
@ -546,15 +548,15 @@ int rts_send_flow_control_ack_pdu(rdpRpc* rpc)
int status;
BYTE* buffer;
UINT32 length;
rpcconn_rts_hdr_t header;
rpcconn_rts_hdr_t header = rts_pdu_header_init();
UINT32 BytesReceived;
UINT32 AvailableWindow;
BYTE* ChannelCookie;
RpcVirtualConnection* connection = rpc->VirtualConnection;
RpcInChannel* inChannel = connection->DefaultInChannel;
RpcOutChannel* outChannel = connection->DefaultOutChannel;
rts_pdu_header_init(&header);
header.frag_length = 56;
header.header.frag_length = 56;
header.Flags = RTS_FLAG_OTHER_CMD;
header.NumberOfCommands = 2;
WLog_DBG(TAG, "Sending FlowControlAck RTS PDU");
@ -562,7 +564,7 @@ int rts_send_flow_control_ack_pdu(rdpRpc* rpc)
AvailableWindow = outChannel->AvailableWindowAdvertised;
ChannelCookie = (BYTE*)&(outChannel->common.Cookie);
outChannel->ReceiverAvailableWindow = outChannel->AvailableWindowAdvertised;
buffer = (BYTE*)malloc(header.frag_length);
buffer = (BYTE*)malloc(header.header.frag_length);
if (!buffer)
return -1;
@ -571,7 +573,7 @@ int rts_send_flow_control_ack_pdu(rdpRpc* rpc)
rts_destination_command_write(&buffer[20], FDOutProxy); /* Destination Command (8 bytes) */
/* FlowControlAck Command (28 bytes) */
rts_flow_control_ack_command_write(&buffer[28], BytesReceived, AvailableWindow, ChannelCookie);
length = header.frag_length;
length = header.header.frag_length;
status = rpc_channel_write(&inChannel->common, buffer, length);
free(buffer);
return (status > 0) ? 1 : -1;
@ -640,20 +642,20 @@ static int rts_send_ping_pdu(rdpRpc* rpc)
int status;
BYTE* buffer;
UINT32 length;
rpcconn_rts_hdr_t header;
rpcconn_rts_hdr_t header = rts_pdu_header_init();
RpcInChannel* inChannel = rpc->VirtualConnection->DefaultInChannel;
rts_pdu_header_init(&header);
header.frag_length = 20;
header.header.frag_length = 20;
header.Flags = RTS_FLAG_PING;
header.NumberOfCommands = 0;
WLog_DBG(TAG, "Sending Ping RTS PDU");
buffer = (BYTE*)malloc(header.frag_length);
buffer = (BYTE*)malloc(header.header.frag_length);
if (!buffer)
return -1;
CopyMemory(buffer, ((BYTE*)&header), 20); /* RTS Header (20 bytes) */
length = header.frag_length;
length = header.header.frag_length;
status = rpc_channel_write(&inChannel->common, buffer, length);
free(buffer);
return (status > 0) ? 1 : -1;
@ -737,17 +739,17 @@ static int rts_send_OUT_R2_A7_pdu(rdpRpc* rpc)
{
int status;
BYTE* buffer;
rpcconn_rts_hdr_t header;
rpcconn_rts_hdr_t header = rts_pdu_header_init();
BYTE* SuccessorChannelCookie;
RpcInChannel* inChannel = rpc->VirtualConnection->DefaultInChannel;
RpcOutChannel* nextOutChannel = rpc->VirtualConnection->NonDefaultOutChannel;
rts_pdu_header_init(&header);
header.frag_length = 56;
header.header.frag_length = 56;
header.Flags = RTS_FLAG_OUT_CHANNEL;
header.NumberOfCommands = 3;
WLog_DBG(TAG, "Sending OUT_R2/A7 RTS PDU");
SuccessorChannelCookie = (BYTE*)&(nextOutChannel->common.Cookie);
buffer = (BYTE*)malloc(header.frag_length);
buffer = (BYTE*)malloc(header.header.frag_length);
if (!buffer)
return -1;
@ -757,7 +759,7 @@ static int rts_send_OUT_R2_A7_pdu(rdpRpc* rpc)
rts_cookie_command_write(&buffer[28],
SuccessorChannelCookie); /* SuccessorChannelCookie (20 bytes) */
rts_version_command_write(&buffer[48]); /* Version (8 bytes) */
status = rpc_channel_write(&inChannel->common, buffer, header.frag_length);
status = rpc_channel_write(&inChannel->common, buffer, header.header.frag_length);
free(buffer);
return (status > 0) ? 1 : -1;
}
@ -766,21 +768,21 @@ static int rts_send_OUT_R2_C1_pdu(rdpRpc* rpc)
{
int status;
BYTE* buffer;
rpcconn_rts_hdr_t header;
rpcconn_rts_hdr_t header = rts_pdu_header_init();
RpcOutChannel* nextOutChannel = rpc->VirtualConnection->NonDefaultOutChannel;
rts_pdu_header_init(&header);
header.frag_length = 24;
header.header.frag_length = 24;
header.Flags = RTS_FLAG_PING;
header.NumberOfCommands = 1;
WLog_DBG(TAG, "Sending OUT_R2/C1 RTS PDU");
buffer = (BYTE*)malloc(header.frag_length);
buffer = (BYTE*)malloc(header.header.frag_length);
if (!buffer)
return -1;
CopyMemory(buffer, ((BYTE*)&header), 20); /* RTS Header (20 bytes) */
rts_empty_command_write(&buffer[20]); /* Empty command (4 bytes) */
status = rpc_channel_write(&nextOutChannel->common, buffer, header.frag_length);
status = rpc_channel_write(&nextOutChannel->common, buffer, header.header.frag_length);
free(buffer);
return (status > 0) ? 1 : -1;
}
@ -789,7 +791,7 @@ int rts_send_OUT_R1_A3_pdu(rdpRpc* rpc)
{
int status;
BYTE* buffer;
rpcconn_rts_hdr_t header;
rpcconn_rts_hdr_t header = rts_pdu_header_init();
UINT32 ReceiveWindowSize;
BYTE* VirtualConnectionCookie;
BYTE* PredecessorChannelCookie;
@ -797,8 +799,8 @@ int rts_send_OUT_R1_A3_pdu(rdpRpc* rpc)
RpcVirtualConnection* connection = rpc->VirtualConnection;
RpcOutChannel* outChannel = connection->DefaultOutChannel;
RpcOutChannel* nextOutChannel = connection->NonDefaultOutChannel;
rts_pdu_header_init(&header);
header.frag_length = 96;
header.header.frag_length = 96;
header.Flags = RTS_FLAG_RECYCLE_CHANNEL;
header.NumberOfCommands = 5;
WLog_DBG(TAG, "Sending OUT_R1/A3 RTS PDU");
@ -806,7 +808,7 @@ int rts_send_OUT_R1_A3_pdu(rdpRpc* rpc)
PredecessorChannelCookie = (BYTE*)&(outChannel->common.Cookie);
SuccessorChannelCookie = (BYTE*)&(nextOutChannel->common.Cookie);
ReceiveWindowSize = outChannel->ReceiveWindow;
buffer = (BYTE*)malloc(header.frag_length);
buffer = (BYTE*)malloc(header.header.frag_length);
if (!buffer)
return -1;
@ -821,7 +823,7 @@ int rts_send_OUT_R1_A3_pdu(rdpRpc* rpc)
SuccessorChannelCookie); /* SuccessorChannelCookie (20 bytes) */
rts_receive_window_size_command_write(&buffer[88],
ReceiveWindowSize); /* ReceiveWindowSize (8 bytes) */
status = rpc_channel_write(&nextOutChannel->common, buffer, header.frag_length);
status = rpc_channel_write(&nextOutChannel->common, buffer, header.header.frag_length);
free(buffer);
return (status > 0) ? 1 : -1;
}

View File

@ -302,7 +302,7 @@ BOOL rts_match_pdu_signature(const RtsPduSignature* signature, const rpcconn_rts
buffer = (const BYTE*)rts;
offset = RTS_PDU_HEADER_LENGTH;
length = rts->frag_length - offset;
length = rts->header.frag_length - offset;
for (i = 0; i < rts->NumberOfCommands; i++)
{
@ -319,7 +319,7 @@ BOOL rts_match_pdu_signature(const RtsPduSignature* signature, const rpcconn_rts
CommandLength = (UINT32)status;
offset += CommandLength;
length = rts->frag_length - offset;
length = rts->header.frag_length - offset;
}
return TRUE;
@ -342,7 +342,7 @@ BOOL rts_extract_pdu_signature(RtsPduSignature* signature, const rpcconn_rts_hdr
signature->NumberOfCommands = rts->NumberOfCommands;
buffer = (BYTE*)rts;
offset = RTS_PDU_HEADER_LENGTH;
length = rts->frag_length - offset;
length = rts->header.frag_length - offset;
for (i = 0; i < rts->NumberOfCommands; i++)
{
@ -356,7 +356,7 @@ BOOL rts_extract_pdu_signature(RtsPduSignature* signature, const rpcconn_rts_hdr
CommandLength = (UINT32)status;
offset += CommandLength;
length = rts->frag_length - offset;
length = rts->header.frag_length - offset;
}
return TRUE;

View File

@ -39,6 +39,19 @@
#define TAG FREERDP_TAG("core.gateway.tsg")
#define TSG_PACKET_TYPE_HEADER 0x00004844
#define TSG_PACKET_TYPE_VERSIONCAPS 0x00005643
#define TSG_PACKET_TYPE_QUARCONFIGREQUEST 0x00005143
#define TSG_PACKET_TYPE_QUARREQUEST 0x00005152
#define TSG_PACKET_TYPE_RESPONSE 0x00005052
#define TSG_PACKET_TYPE_QUARENC_RESPONSE 0x00004552
#define TSG_CAPABILITY_TYPE_NAP 0x00000001
#define TSG_PACKET_TYPE_CAPS_RESPONSE 0x00004350
#define TSG_PACKET_TYPE_MSGREQUEST_PACKET 0x00004752
#define TSG_PACKET_TYPE_MESSAGE_PACKET 0x00004750
#define TSG_PACKET_TYPE_AUTH 0x00004054
#define TSG_PACKET_TYPE_REAUTH 0x00005250
typedef WCHAR* RESOURCENAME;
typedef struct _tsendpointinfo
@ -218,6 +231,214 @@ struct rdp_tsg
TSG_PACKET_VERSIONCAPS packetVersionCaps;
};
static const char* tsg_packet_id_to_string(UINT32 packetId)
{
switch (packetId)
{
case TSG_PACKET_TYPE_HEADER:
return "TSG_PACKET_TYPE_HEADER";
case TSG_PACKET_TYPE_VERSIONCAPS:
return "TSG_PACKET_TYPE_VERSIONCAPS";
case TSG_PACKET_TYPE_QUARCONFIGREQUEST:
return "TSG_PACKET_TYPE_QUARCONFIGREQUEST";
case TSG_PACKET_TYPE_QUARREQUEST:
return "TSG_PACKET_TYPE_QUARREQUEST";
case TSG_PACKET_TYPE_RESPONSE:
return "TSG_PACKET_TYPE_RESPONSE";
case TSG_PACKET_TYPE_QUARENC_RESPONSE:
return "TSG_PACKET_TYPE_QUARENC_RESPONSE";
case TSG_CAPABILITY_TYPE_NAP:
return "TSG_CAPABILITY_TYPE_NAP";
case TSG_PACKET_TYPE_CAPS_RESPONSE:
return "TSG_PACKET_TYPE_CAPS_RESPONSE";
case TSG_PACKET_TYPE_MSGREQUEST_PACKET:
return "TSG_PACKET_TYPE_MSGREQUEST_PACKET";
case TSG_PACKET_TYPE_MESSAGE_PACKET:
return "TSG_PACKET_TYPE_MESSAGE_PACKET";
case TSG_PACKET_TYPE_AUTH:
return "TSG_PACKET_TYPE_AUTH";
case TSG_PACKET_TYPE_REAUTH:
return "TSG_PACKET_TYPE_REAUTH";
default:
return "UNKNOWN";
}
}
static const char* tsg_state_to_string(TSG_STATE state)
{
switch (state)
{
case TSG_STATE_INITIAL:
return "TSG_STATE_INITIAL";
case TSG_STATE_CONNECTED:
return "TSG_STATE_CONNECTED";
case TSG_STATE_AUTHORIZED:
return "TSG_STATE_AUTHORIZED";
case TSG_STATE_CHANNEL_CREATED:
return "TSG_STATE_CHANNEL_CREATED";
case TSG_STATE_PIPE_CREATED:
return "TSG_STATE_PIPE_CREATED";
case TSG_STATE_TUNNEL_CLOSE_PENDING:
return "TSG_STATE_TUNNEL_CLOSE_PENDING";
case TSG_STATE_CHANNEL_CLOSE_PENDING:
return "TSG_STATE_CHANNEL_CLOSE_PENDING";
case TSG_STATE_FINAL:
return "TSG_STATE_FINAL";
default:
return "TSG_STATE_UNKNOWN";
}
}
static BOOL tsg_print(char** buffer, size_t* len, const char* fmt, ...)
{
int rc;
va_list ap;
if (!buffer || !len || !fmt)
return FALSE;
va_start(ap, fmt);
rc = vsnprintf(*buffer, *len, fmt, ap);
va_end(ap);
if ((rc < 0) || ((size_t)rc > *len))
return FALSE;
*len -= (size_t)rc;
*buffer += (size_t)rc;
return TRUE;
}
static BOOL tsg_packet_header_to_string(char** buffer, size_t* length,
const TSG_PACKET_HEADER* header)
{
return tsg_print(buffer, length,
"header { ComponentId=0x%04" PRIx16 ", PacketId=0x%04" PRIx16 " }",
header->ComponentId, header->PacketId);
}
static BOOL tsg_packet_capabilities_to_string(char** buffer, size_t* length,
const TSG_PACKET_CAPABILITIES* caps, UINT32 numCaps)
{
UINT32 x;
if (!tsg_print(buffer, length, "capabilities { "))
return FALSE;
for (x = 0; x < numCaps; x++)
{
const TSG_PACKET_CAPABILITIES* cur = &caps[x];
switch (cur->capabilityType)
{
case TSG_CAPABILITY_TYPE_NAP:
if (!tsg_print(buffer, length, "%s { capabilities=0x%08" PRIx32 " }",
tsg_packet_id_to_string(cur->capabilityType),
cur->tsgPacket.tsgCapNap.capabilities))
return FALSE;
break;
default:
if (!tsg_print(buffer, length, "TSG_UNKNOWN_CAPABILITY"))
return FALSE;
break;
}
}
return tsg_print(buffer, length, " }");
}
static BOOL tsg_packet_versioncaps_to_string(char** buffer, size_t* length,
const TSG_PACKET_VERSIONCAPS* caps)
{
if (!tsg_print(buffer, length, "versioncaps { "))
return FALSE;
if (!tsg_packet_header_to_string(buffer, length, &caps->tsgHeader))
return FALSE;
if (!tsg_print(buffer, length, " "))
return FALSE;
if (!tsg_packet_capabilities_to_string(buffer, length, caps->tsgCaps, caps->numCapabilities))
return FALSE;
if (!tsg_print(buffer, length,
" numCapabilities=0x%08" PRIx32 ", majorVersion=0x%04" PRIx16
", minorVersion=0x%04" PRIx16 ", quarantineCapabilities=0x%04" PRIx16,
caps->numCapabilities, caps->majorVersion, caps->minorVersion,
caps->quarantineCapabilities))
return FALSE;
return tsg_print(buffer, length, " }");
}
static const char* tsg_packet_to_string(const TSG_PACKET* packet)
{
size_t len = 8192;
static char sbuffer[8193] = { 0 };
char* buffer = sbuffer;
if (!tsg_print(&buffer, &len, "TSG_PACKET { packetId=%s [0x%08" PRIx32 "], ",
tsg_packet_id_to_string(packet->packetId), packet->packetId))
goto fail;
switch (packet->packetId)
{
case TSG_PACKET_TYPE_HEADER:
if (!tsg_packet_header_to_string(&buffer, &len, packet->tsgPacket.packetHeader))
goto fail;
break;
case TSG_PACKET_TYPE_VERSIONCAPS:
if (!tsg_packet_versioncaps_to_string(&buffer, &len,
packet->tsgPacket.packetVersionCaps))
goto fail;
break;
case TSG_PACKET_TYPE_QUARCONFIGREQUEST:
if (!tsg_print(&buffer, &len, "TODO"))
goto fail;
break;
case TSG_PACKET_TYPE_QUARREQUEST:
if (!tsg_print(&buffer, &len, "TODO"))
goto fail;
break;
case TSG_PACKET_TYPE_RESPONSE:
if (!tsg_print(&buffer, &len, "TODO"))
goto fail;
break;
case TSG_PACKET_TYPE_QUARENC_RESPONSE:
if (!tsg_print(&buffer, &len, "TODO"))
goto fail;
break;
case TSG_CAPABILITY_TYPE_NAP:
if (!tsg_print(&buffer, &len, "TODO"))
goto fail;
break;
case TSG_PACKET_TYPE_CAPS_RESPONSE:
if (!tsg_print(&buffer, &len, "TODO"))
goto fail;
break;
case TSG_PACKET_TYPE_MSGREQUEST_PACKET:
if (!tsg_print(&buffer, &len, "TODO"))
goto fail;
break;
case TSG_PACKET_TYPE_MESSAGE_PACKET:
if (!tsg_print(&buffer, &len, "TODO"))
goto fail;
break;
case TSG_PACKET_TYPE_AUTH:
if (!tsg_print(&buffer, &len, "TODO"))
goto fail;
break;
case TSG_PACKET_TYPE_REAUTH:
if (!tsg_print(&buffer, &len, "TODO"))
goto fail;
break;
default:
if (!tsg_print(&buffer, &len, "INVALID"))
goto fail;
break;
}
if (!tsg_print(&buffer, &len, " }"))
goto fail;
fail:
return sbuffer;
}
static BOOL tsg_stream_align(wStream* s, size_t align)
{
size_t pos;
@ -362,7 +583,7 @@ static int TsProxySendToServer(handle_t IDL_handle, const byte pRpcMessage[], UI
* );
*/
static BOOL TsProxyCreateTunnelWriteRequest(rdpTsg* tsg, PTSG_PACKET tsgPacket)
static BOOL TsProxyCreateTunnelWriteRequest(rdpTsg* tsg, const PTSG_PACKET tsgPacket)
{
BOOL rc = FALSE;
BOOL write = TRUE;
@ -374,7 +595,7 @@ static BOOL TsProxyCreateTunnelWriteRequest(rdpTsg* tsg, PTSG_PACKET tsgPacket)
return FALSE;
rpc = tsg->rpc;
WLog_DBG(TAG, "TsProxyCreateTunnelWriteRequest");
WLog_DBG(TAG, "%s: %s", __FUNCTION__, tsg_packet_to_string(tsgPacket));
s = Stream_New(NULL, 108);
if (!s)
@ -506,7 +727,6 @@ static BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu,
PTSG_PACKET_VERSIONCAPS versionCaps = NULL;
PTSG_PACKET_CAPS_RESPONSE packetCapsResponse = NULL;
PTSG_PACKET_QUARENC_RESPONSE packetQuarEncResponse = NULL;
WLog_DBG(TAG, "TsProxyCreateTunnelReadResponse");
if (!pdu)
return FALSE;
@ -523,6 +743,8 @@ static BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu,
Stream_Read_UINT32(pdu->s, packet->packetId); /* PacketId (4 bytes) */
Stream_Read_UINT32(pdu->s, SwitchValue); /* SwitchValue (4 bytes) */
WLog_DBG(TAG, "%s: %s", __FUNCTION__, tsg_packet_id_to_string(packet->packetId));
if ((packet->packetId == TSG_PACKET_TYPE_CAPS_RESPONSE) &&
(SwitchValue == TSG_PACKET_TYPE_CAPS_RESPONSE))
{
@ -885,7 +1107,6 @@ static BOOL TsProxyAuthorizeTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
UINT32 idleTimeout;
PTSG_PACKET packet = NULL;
PTSG_PACKET_RESPONSE packetResponse = NULL;
WLog_DBG(TAG, "TsProxyAuthorizeTunnelReadResponse");
if (!pdu)
return FALSE;
@ -902,6 +1123,8 @@ static BOOL TsProxyAuthorizeTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
Stream_Read_UINT32(pdu->s, packet->packetId); /* PacketId (4 bytes) */
Stream_Read_UINT32(pdu->s, SwitchValue); /* SwitchValue (4 bytes) */
WLog_DBG(TAG, "%s: %s", __FUNCTION__, tsg_packet_id_to_string(packet->packetId));
if (packet->packetId == E_PROXY_NAP_ACCESSDENIED)
{
WLog_ERR(TAG, "status: E_PROXY_NAP_ACCESSDENIED (0x%08X)", E_PROXY_NAP_ACCESSDENIED);
@ -1059,7 +1282,6 @@ static BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
TSG_PACKET_MSG_RESPONSE packetMsgResponse = { 0 };
TSG_PACKET_STRING_MESSAGE packetStringMessage = { 0 };
TSG_PACKET_REAUTH_MESSAGE packetReauthMessage = { 0 };
WLog_DBG(TAG, "TsProxyMakeTunnelCallReadResponse");
/* This is an asynchronous response */
@ -1073,6 +1295,8 @@ static BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
Stream_Read_UINT32(pdu->s, packet.packetId); /* PacketId (4 bytes) */
Stream_Read_UINT32(pdu->s, SwitchValue); /* SwitchValue (4 bytes) */
WLog_DBG(TAG, "%s: %s", __FUNCTION__, tsg_packet_id_to_string(packet.packetId));
if ((packet.packetId != TSG_PACKET_TYPE_MESSAGE_PACKET) ||
(SwitchValue != TSG_PACKET_TYPE_MESSAGE_PACKET))
{
@ -1357,50 +1581,16 @@ static BOOL TsProxySetupReceivePipeWriteRequest(rdpTsg* tsg, CONTEXT_HANDLE* cha
static BOOL tsg_transition_to_state(rdpTsg* tsg, TSG_STATE state)
{
const char* str = "TSG_STATE_UNKNOWN";
const char* oldState = tsg_state_to_string(tsg->state);
const char* newState = tsg_state_to_string(state);
switch (state)
{
case TSG_STATE_INITIAL:
str = "TSG_STATE_INITIAL";
break;
case TSG_STATE_CONNECTED:
str = "TSG_STATE_CONNECTED";
break;
case TSG_STATE_AUTHORIZED:
str = "TSG_STATE_AUTHORIZED";
break;
case TSG_STATE_CHANNEL_CREATED:
str = "TSG_STATE_CHANNEL_CREATED";
break;
case TSG_STATE_PIPE_CREATED:
str = "TSG_STATE_PIPE_CREATED";
break;
case TSG_STATE_TUNNEL_CLOSE_PENDING:
str = "TSG_STATE_TUNNEL_CLOSE_PENDING";
break;
case TSG_STATE_CHANNEL_CLOSE_PENDING:
str = "TSG_STATE_CHANNEL_CLOSE_PENDING";
break;
case TSG_STATE_FINAL:
str = "TSG_STATE_FINAL";
break;
}
WLog_DBG(TAG, "%s", str);
WLog_DBG(TAG, "%s -> %s", oldState, newState);
return tsg_set_state(tsg, state);
}
BOOL tsg_proxy_begin(rdpTsg* tsg)
{
TSG_PACKET tsgPacket;
TSG_PACKET tsgPacket = { 0 };
PTSG_CAPABILITY_NAP tsgCapNap;
PTSG_PACKET_VERSIONCAPS packetVersionCaps;
@ -1443,7 +1633,7 @@ BOOL tsg_proxy_begin(rdpTsg* tsg)
static BOOL tsg_proxy_reauth(rdpTsg* tsg)
{
TSG_PACKET tsgPacket;
TSG_PACKET tsgPacket = { 0 };
PTSG_PACKET_REAUTH packetReauth;
PTSG_PACKET_VERSIONCAPS packetVersionCaps;
@ -1815,8 +2005,9 @@ static BOOL tsg_set_machine_name(rdpTsg* tsg, const char* machineName)
return TRUE;
}
BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port, int timeout)
BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port, DWORD timeout)
{
UINT64 looptimeout = timeout * 1000ULL;
DWORD nCount;
HANDLE events[64];
rdpRpc* rpc = tsg->rpc;
@ -1847,7 +2038,19 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port, int timeout)
while (tsg->state != TSG_STATE_PIPE_CREATED)
{
WaitForMultipleObjects(nCount, events, FALSE, 250);
const DWORD polltimeout = 250;
DWORD status = WaitForMultipleObjects(nCount, events, FALSE, polltimeout);
if (status == WAIT_TIMEOUT)
{
if (timeout > 0)
{
if (looptimeout < polltimeout)
return FALSE;
looptimeout -= polltimeout;
}
}
else
looptimeout = timeout * 1000ULL;
if (!tsg_check_event_handles(tsg))
{

View File

@ -62,19 +62,6 @@ typedef enum _TSG_STATE TSG_STATE;
#define TS_GATEWAY_TRANSPORT 0x5452
#define TSG_PACKET_TYPE_HEADER 0x00004844
#define TSG_PACKET_TYPE_VERSIONCAPS 0x00005643
#define TSG_PACKET_TYPE_QUARCONFIGREQUEST 0x00005143
#define TSG_PACKET_TYPE_QUARREQUEST 0x00005152
#define TSG_PACKET_TYPE_RESPONSE 0x00005052
#define TSG_PACKET_TYPE_QUARENC_RESPONSE 0x00004552
#define TSG_CAPABILITY_TYPE_NAP 0x00000001
#define TSG_PACKET_TYPE_CAPS_RESPONSE 0x00004350
#define TSG_PACKET_TYPE_MSGREQUEST_PACKET 0x00004752
#define TSG_PACKET_TYPE_MESSAGE_PACKET 0x00004750
#define TSG_PACKET_TYPE_AUTH 0x00004054
#define TSG_PACKET_TYPE_REAUTH 0x00005250
#define TSG_ASYNC_MESSAGE_CONSENT_MESSAGE 0x00000001
#define TSG_ASYNC_MESSAGE_SERVICE_MESSAGE 0x00000002
#define TSG_ASYNC_MESSAGE_REAUTH 0x00000003
@ -118,7 +105,7 @@ FREERDP_LOCAL void tsg_free(rdpTsg* tsg);
FREERDP_LOCAL BOOL tsg_proxy_begin(rdpTsg* tsg);
FREERDP_LOCAL BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port, int timeout);
FREERDP_LOCAL BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port, DWORD timeout);
FREERDP_LOCAL BOOL tsg_disconnect(rdpTsg* tsg);
FREERDP_LOCAL BOOL tsg_recv_pdu(rdpTsg* tsg, RPC_PDU* pdu);

View File

@ -3506,7 +3506,7 @@ static BOOL update_recv_secondary_order(rdpUpdate* update, wStream* s, BYTE flag
Stream_Read_UINT16(s, orderLength); /* orderLength (2 bytes) */
Stream_Read_UINT16(s, extraFlags); /* extraFlags (2 bytes) */
Stream_Read_UINT8(s, orderType); /* orderType (1 byte) */
if (Stream_GetRemainingLength(s) < orderLength + 7)
if (Stream_GetRemainingLength(s) < orderLength + 7U)
{
WLog_Print(update->log, WLOG_ERROR, "Stream_GetRemainingLength(s) %" PRIuz " < %" PRIu16,
Stream_GetRemainingLength(s), orderLength + 7);

View File

@ -167,7 +167,7 @@ BOOL rdp_read_share_control_header(wStream* s, UINT16* tpktLength, UINT16* remai
return TRUE;
}
if ((len < 4) || ((len - 2) > Stream_GetRemainingLength(s)))
if ((len < 4U) || ((len - 2U) > Stream_GetRemainingLength(s)))
return FALSE;
if (tpktLength)

View File

@ -1060,7 +1060,7 @@ static BOOL freerdp_tcp_set_keep_alive_mode(const rdpSettings* settings, int soc
}
int freerdp_tcp_connect(rdpContext* context, rdpSettings* settings, const char* hostname, int port,
int timeout)
DWORD timeout)
{
int sockfd;
UINT32 optval;

View File

@ -64,7 +64,7 @@ FREERDP_LOCAL BIO_METHOD* BIO_s_simple_socket(void);
FREERDP_LOCAL BIO_METHOD* BIO_s_buffered_socket(void);
FREERDP_LOCAL int freerdp_tcp_connect(rdpContext* context, rdpSettings* settings,
const char* hostname, int port, int timeout);
const char* hostname, int port, DWORD timeout);
FREERDP_LOCAL char* freerdp_tcp_get_peer_address(SOCKET sockfd);

View File

@ -354,7 +354,7 @@ BOOL transport_connect_nla(rdpTransport* transport)
return TRUE;
}
BOOL transport_connect(rdpTransport* transport, const char* hostname, UINT16 port, int timeout)
BOOL transport_connect(rdpTransport* transport, const char* hostname, UINT16 port, DWORD timeout)
{
int sockfd;
BOOL status = FALSE;

View File

@ -81,7 +81,7 @@ struct rdp_transport
FREERDP_LOCAL wStream* transport_send_stream_init(rdpTransport* transport, int size);
FREERDP_LOCAL BOOL transport_connect(rdpTransport* transport, const char* hostname, UINT16 port,
int timeout);
DWORD timeout);
FREERDP_LOCAL BOOL transport_attach(rdpTransport* transport, int sockfd);
FREERDP_LOCAL BOOL transport_disconnect(rdpTransport* transport);
FREERDP_LOCAL BOOL transport_connect_rdp(rdpTransport* transport);