gateway: Fix consent/service message in legacy gateway code
authorMartin Fleisz <martin.fleisz@thincast.com>
Wed, 27 Jan 2021 08:44:19 +0000 (09:44 +0100)
committerakallabeth <akallabeth@users.noreply.github.com>
Thu, 25 Feb 2021 08:51:41 +0000 (09:51 +0100)
(cherry picked from commit 00d56429211c2b1275e1122450e5bb87094c9678)

libfreerdp/core/gateway/rpc_client.c
libfreerdp/core/gateway/tsg.c

index 4b82388..875cc0b 100644 (file)
@@ -383,7 +383,8 @@ static int rpc_client_recv_fragment(rdpRpc* rpc, wStream* fragment)
                                pdu->Type = PTYPE_RESPONSE;
                                pdu->CallId = rpc->StubCallId;
                                Stream_SealLength(pdu->s);
-                               rpc_client_recv_pdu(rpc, pdu);
+                               if (rpc_client_recv_pdu(rpc, pdu) < 0)
+                                       return -1;
                                rpc_pdu_reset(pdu);
                                rpc->StubFragCount = 0;
                                rpc->StubCallId = 0;
@@ -983,7 +984,7 @@ BOOL rpc_client_write_call(rdpRpc* rpc, wStream* s, UINT16 opnum)
        CopyMemory(&buffer[offset], &request_pdu.auth_verifier.auth_type, 8);
        offset += 8;
        Buffers[0].BufferType = SECBUFFER_DATA | SECBUFFER_READONLY; /* auth_data */
-       Buffers[1].BufferType = SECBUFFER_TOKEN; /* signature */
+       Buffers[1].BufferType = SECBUFFER_TOKEN;                     /* signature */
        Buffers[0].pvBuffer = buffer;
        Buffers[0].cbBuffer = offset;
        Buffers[1].cbBuffer = size;
index 26c4ba2..9d01c9f 100644 (file)
@@ -74,7 +74,8 @@ typedef struct _TSG_CAPABILITY_NAP
        UINT32 capabilities;
 } TSG_CAPABILITY_NAP, *PTSG_CAPABILITY_NAP;
 
-typedef union {
+typedef union
+{
        TSG_CAPABILITY_NAP tsgCapNap;
 } TSG_CAPABILITIES_UNION, *PTSG_CAPABILITIES_UNION;
 
@@ -176,7 +177,8 @@ typedef struct _TSG_PACKET_AUTH
        BYTE* cookie;
 } TSG_PACKET_AUTH, *PTSG_PACKET_AUTH;
 
-typedef union {
+typedef union
+{
        PTSG_PACKET_VERSIONCAPS packetVersionCaps;
        PTSG_PACKET_AUTH packetAuth;
 } TSG_INITIAL_PACKET_TYPE_UNION, *PTSG_INITIAL_PACKET_TYPE_UNION;
@@ -188,7 +190,8 @@ typedef struct TSG_PACKET_REAUTH
        TSG_INITIAL_PACKET_TYPE_UNION tsgInitialPacket;
 } TSG_PACKET_REAUTH, *PTSG_PACKET_REAUTH;
 
-typedef union {
+typedef union
+{
        PTSG_PACKET_HEADER packetHeader;
        PTSG_PACKET_VERSIONCAPS packetVersionCaps;
        PTSG_PACKET_QUARCONFIGREQUEST packetQuarConfigRequest;
@@ -722,9 +725,9 @@ static BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu,
        UINT32 SwitchValue;
        UINT32 MessageSwitchValue = 0;
        UINT32 IsMessagePresent;
-       UINT32 MsgBytes;
        PTSG_PACKET_CAPABILITIES tsgCaps = NULL;
        PTSG_PACKET_VERSIONCAPS versionCaps = NULL;
+       TSG_PACKET_STRING_MESSAGE packetStringMessage;
        PTSG_PACKET_CAPS_RESPONSE packetCapsResponse = NULL;
        PTSG_PACKET_QUARENC_RESPONSE packetQuarEncResponse = NULL;
 
@@ -874,9 +877,9 @@ static BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu,
                                if (Stream_GetRemainingLength(pdu->s) < 16)
                                        goto fail;
 
-                               Stream_Seek_UINT32(pdu->s); /* IsDisplayMandatory (4 bytes) */
-                               Stream_Seek_UINT32(pdu->s); /* IsConsent Mandatory (4 bytes) */
-                               Stream_Read_UINT32(pdu->s, MsgBytes);
+                               Stream_Read_UINT32(pdu->s, packetStringMessage.isDisplayMandatory);
+                               Stream_Read_UINT32(pdu->s, packetStringMessage.isConsentMandatory);
+                               Stream_Read_UINT32(pdu->s, packetStringMessage.msgBytes);
                                Stream_Read_UINT32(pdu->s, Pointer);
 
                                if (Pointer)
@@ -889,15 +892,36 @@ static BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu,
                                        Stream_Seek_UINT32(pdu->s); /* Length (4 bytes) */
                                }
 
-                               if (MsgBytes > TSG_MESSAGING_MAX_MESSAGE_LENGTH)
+                               if (packetStringMessage.msgBytes > TSG_MESSAGING_MAX_MESSAGE_LENGTH)
                                {
-                                       WLog_ERR(TAG, "Out of Spec Message Length %" PRIu32 "", MsgBytes);
+                                       WLog_ERR(TAG, "Out of Spec Message Length %" PRIu32 "",
+                                                packetStringMessage.msgBytes);
                                        goto fail;
                                }
 
-                               if (!Stream_SafeSeek(pdu->s, MsgBytes))
+                               packetStringMessage.msgBuffer = (WCHAR*)Stream_Pointer(pdu->s);
+                               if (Stream_GetRemainingLength(pdu->s) < packetStringMessage.msgBytes)
+                               {
+                                       WLog_ERR(TAG, "Unable to read message (%" PRIu32 " remaining %" PRId32 ")",
+                                                packetStringMessage.msgBytes, Stream_GetRemainingLength(pdu->s));
                                        goto fail;
+                               }
+
+                               if (tsg->rpc && tsg->rpc->context && tsg->rpc->context->instance)
+                               {
+                                       rc = IFCALLRESULT(TRUE, tsg->rpc->context->instance->PresentGatewayMessage,
+                                                         tsg->rpc->context->instance,
+                                                         TSG_ASYNC_MESSAGE_CONSENT_MESSAGE
+                                                             ? GATEWAY_MESSAGE_CONSENT
+                                                             : TSG_ASYNC_MESSAGE_SERVICE_MESSAGE,
+                                                         packetStringMessage.isDisplayMandatory != 0,
+                                                         packetStringMessage.isConsentMandatory != 0,
+                                                         packetStringMessage.msgBytes, packetStringMessage.msgBuffer);
+                                       if (!rc)
+                                               goto fail;
+                               }
 
+                               Stream_Seek(pdu->s, packetStringMessage.msgBytes);
                                break;
 
                        case TSG_ASYNC_MESSAGE_REAUTH: