From 0031c4918e5b7e804d87cbd1468ad7742443fb11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Thu, 14 Mar 2013 12:57:45 -0400 Subject: [PATCH] libfreerdp-core: add TS Gateway system message support --- libfreerdp/codec/rfx_sse2.c | 2 -- libfreerdp/core/gateway/rpc.c | 3 ++- libfreerdp/core/gateway/rpc_client.c | 17 +++++++++++--- libfreerdp/core/gateway/tsg.c | 35 +++++++++++++++++----------- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/libfreerdp/codec/rfx_sse2.c b/libfreerdp/codec/rfx_sse2.c index 6142aa84d..232fc522c 100644 --- a/libfreerdp/codec/rfx_sse2.c +++ b/libfreerdp/codec/rfx_sse2.c @@ -491,11 +491,9 @@ static void rfx_dwt_2d_encode_sse2(INT16* buffer, INT16* dwt_buffer) void rfx_init_sse2(RFX_CONTEXT* context) { - if (!IsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE)) return; - printf("\n\nIs this causing crashes???\n\n"); DEBUG_RFX("Using SSE2 optimizations"); IF_PROFILER(context->priv->prof_rfx_quantization_decode->name = "rfx_quantization_decode_sse2"); diff --git a/libfreerdp/core/gateway/rpc.c b/libfreerdp/core/gateway/rpc.c index 5d0e00b6a..69a5addb8 100644 --- a/libfreerdp/core/gateway/rpc.c +++ b/libfreerdp/core/gateway/rpc.c @@ -335,9 +335,10 @@ int rpc_in_write(rdpRpc* rpc, BYTE* data, int length) int status; #ifdef WITH_DEBUG_TSG - rpc_pdu_header_print((rpcconn_hdr_t*) data); printf("Sending PDU (length: %d)\n", length); + rpc_pdu_header_print((rpcconn_hdr_t*) data); winpr_HexDump(data, length); + printf("\n"); #endif status = tls_write_all(rpc->TlsIn, data, length); diff --git a/libfreerdp/core/gateway/rpc_client.c b/libfreerdp/core/gateway/rpc_client.c index e2afd946b..60999bc4d 100644 --- a/libfreerdp/core/gateway/rpc_client.c +++ b/libfreerdp/core/gateway/rpc_client.c @@ -191,15 +191,16 @@ int rpc_client_on_fragment_received_event(rdpRpc* rpc) if (header->response.alloc_hint == StubLength) { - rpc->StubCallId = 0; - rpc->StubFragCount = 0; - rpc->client->pdu->Flags = RPC_PDU_FLAG_STUB; rpc->client->pdu->CallId = rpc->StubCallId; Stream_Length(rpc->client->pdu->s) = Stream_Position(rpc->client->pdu->s); + rpc->StubFragCount = 0; + rpc->StubCallId = 0; + Queue_Enqueue(rpc->client->ReceiveQueue, rpc->client->pdu); + rpc->client->pdu = NULL; return 0; @@ -408,6 +409,16 @@ RPC_PDU* rpc_recv_dequeue_pdu(rdpRpc* rpc) if (WaitForSingleObject(Queue_Event(rpc->client->ReceiveQueue), dwMilliseconds) == WAIT_OBJECT_0) { pdu = (RPC_PDU*) Queue_Dequeue(rpc->client->ReceiveQueue); + +#ifdef WITH_DEBUG_TSG + if (pdu) + { + printf("Receiving PDU (length: %d, CallId: %d)\n", pdu->s->length, pdu->CallId); + winpr_HexDump(pdu->s->buffer, pdu->s->length); + printf("\n"); + } +#endif + return pdu; } diff --git a/libfreerdp/core/gateway/tsg.c b/libfreerdp/core/gateway/tsg.c index 2a9c432cf..47a1f570d 100644 --- a/libfreerdp/core/gateway/tsg.c +++ b/libfreerdp/core/gateway/tsg.c @@ -684,6 +684,7 @@ BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, RPC_PDU* pdu) UINT32 ActualCount; UINT32 SwitchValue; PTSG_PACKET packet; + char* messageText = NULL; PTSG_PACKET_MSG_RESPONSE packetMsgResponse; PTSG_PACKET_STRING_MESSAGE packetStringMessage = NULL; PTSG_PACKET_REAUTH_MESSAGE packetReauthMessage = NULL; @@ -740,7 +741,9 @@ BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, RPC_PDU* pdu) /* Offset */ ActualCount = *((UINT32*) &buffer[offset + 56]); /* ActualCount */ - winpr_HexDump(&buffer[offset + 60], ActualCount * 2); + ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) &buffer[offset + 60], ActualCount, &messageText, 0, NULL, NULL); + printf("Consent Message: %s\n", messageText); + free(messageText); break; @@ -759,7 +762,9 @@ BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, RPC_PDU* pdu) /* Offset */ ActualCount = *((UINT32*) &buffer[offset + 56]); /* ActualCount */ - winpr_HexDump(&buffer[offset + 60], ActualCount * 2); + ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) &buffer[offset + 60], ActualCount, &messageText, 0, NULL, NULL); + printf("Service Message: %s\n", messageText); + free(messageText); break; @@ -777,8 +782,6 @@ BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, RPC_PDU* pdu) break; } - exit(0); - return TRUE; } @@ -1130,6 +1133,7 @@ BOOL TsProxySetupReceivePipe(handle_t IDL_handle, BYTE* pRpcMessage) BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port) { RPC_PDU* pdu = NULL; + RpcClientCall* call; rdpRpc* rpc = tsg->rpc; rdpSettings* settings = rpc->settings; @@ -1265,16 +1269,6 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port) if (!TsProxyMakeTunnelCall(tsg, &tsg->TunnelContext, TSG_TUNNEL_CALL_ASYNC_MSG_REQUEST, NULL, NULL)) return FALSE; -#if 0 - pdu = rpc_recv_dequeue_pdu(rpc); - - if (!TsProxyMakeTunnelCallReadResponse(tsg, pdu)) - { - printf("TsProxyMakeTunnelCall: error reading response\n"); - return FALSE; - } -#endif - /** * Sequential processing rules for connection process (continued): * @@ -1296,6 +1290,19 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port) pdu = rpc_recv_dequeue_pdu(rpc); + call = rpc_client_call_find_by_id(rpc, pdu->CallId); + + if (call->OpNum == TsProxyMakeTunnelCallOpnum) + { + if (!TsProxyMakeTunnelCallReadResponse(tsg, pdu)) + { + printf("TsProxyMakeTunnelCall: error reading response\n"); + return FALSE; + } + + pdu = rpc_recv_dequeue_pdu(rpc); + } + if (!TsProxyCreateChannelReadResponse(tsg, pdu)) { printf("TsProxyCreateChannel: error reading response\n");