diff --git a/libfreerdp/core/gateway/rpc_client.c b/libfreerdp/core/gateway/rpc_client.c index 9166e59db..b99efa089 100644 --- a/libfreerdp/core/gateway/rpc_client.c +++ b/libfreerdp/core/gateway/rpc_client.c @@ -191,6 +191,7 @@ static int rpc_client_recv_pdu(rdpRpc* rpc, RPC_PDU* pdu) if (rpc->VirtualConnection->State < VIRTUAL_CONNECTION_STATE_OPENED) { + RtsPduSignature found = { 0 }; switch (rpc->VirtualConnection->State) { case VIRTUAL_CONNECTION_STATE_INITIAL: @@ -200,9 +201,11 @@ static int rpc_client_recv_pdu(rdpRpc* rpc, RPC_PDU* pdu) break; case VIRTUAL_CONNECTION_STATE_WAIT_A3W: - if (!rts_match_pdu_signature(&RTS_PDU_CONN_A3_SIGNATURE, pdu->s, NULL)) + if (!rts_match_pdu_signature_ex(&RTS_PDU_CONN_A3_SIGNATURE, pdu->s, NULL, &found)) { - WLog_ERR(TAG, "unexpected RTS PDU: Expected CONN/A3"); + wLog* log = WLog_Get(TAG); + WLog_Print(log, WLOG_ERROR, "unexpected RTS PDU: Expected CONN/A3"); + rts_print_pdu_signature(log, WLOG_ERROR, &found); return -1; } @@ -218,9 +221,11 @@ static int rpc_client_recv_pdu(rdpRpc* rpc, RPC_PDU* pdu) break; case VIRTUAL_CONNECTION_STATE_WAIT_C2: - if (!rts_match_pdu_signature(&RTS_PDU_CONN_C2_SIGNATURE, pdu->s, NULL)) + if (!rts_match_pdu_signature_ex(&RTS_PDU_CONN_C2_SIGNATURE, pdu->s, NULL, &found)) { - WLog_ERR(TAG, "unexpected RTS PDU: Expected CONN/C2"); + wLog* log = WLog_Get(TAG); + WLog_Print(log, WLOG_ERROR, "unexpected RTS PDU: Expected CONN/C2"); + rts_print_pdu_signature(log, WLOG_ERROR, &found); return -1; } diff --git a/libfreerdp/core/gateway/rts.c b/libfreerdp/core/gateway/rts.c index 41b0099eb..50d1323b1 100644 --- a/libfreerdp/core/gateway/rts.c +++ b/libfreerdp/core/gateway/rts.c @@ -2182,8 +2182,10 @@ BOOL rts_recv_out_of_sequence_pdu(rdpRpc* rpc, wStream* buffer, const rpcconn_hd if (!status) { - WLog_ERR(TAG, "error parsing RTS PDU with signature id: 0x%08" PRIX32 "", SignatureId); - rts_print_pdu_signature(&signature); + wLog* log = WLog_Get(TAG); + WLog_Print(log, WLOG_ERROR, "error parsing RTS PDU with signature id: 0x%08" PRIX32 "", + SignatureId); + rts_print_pdu_signature(log, WLOG_ERROR, &signature); } return status; diff --git a/libfreerdp/core/gateway/rts_signature.c b/libfreerdp/core/gateway/rts_signature.c index ce7d785ea..e08c2c600 100644 --- a/libfreerdp/core/gateway/rts_signature.c +++ b/libfreerdp/core/gateway/rts_signature.c @@ -284,6 +284,12 @@ static const RTS_PDU_SIGNATURE_ENTRY RTS_PDU_SIGNATURE_TABLE[] = { BOOL rts_match_pdu_signature(const RtsPduSignature* signature, wStream* src, const rpcconn_hdr_t* header) +{ + return rts_match_pdu_signature_ex(signature, src, header, NULL); +} + +BOOL rts_match_pdu_signature_ex(const RtsPduSignature* signature, wStream* src, + const rpcconn_hdr_t* header, RtsPduSignature* found_signature) { RtsPduSignature extracted = { 0 }; @@ -293,6 +299,8 @@ BOOL rts_match_pdu_signature(const RtsPduSignature* signature, wStream* src, if (!rts_extract_pdu_signature(&extracted, src, header)) return FALSE; + if (found_signature) + *found_signature = extracted; return memcmp(signature, &extracted, sizeof(extracted)) == 0; } @@ -385,7 +393,7 @@ UINT32 rts_identify_pdu_signature(const RtsPduSignature* signature, return 0; } -BOOL rts_print_pdu_signature(const RtsPduSignature* signature) +BOOL rts_print_pdu_signature(wLog* log, DWORD level, const RtsPduSignature* signature) { UINT32 SignatureId; const RTS_PDU_SIGNATURE_ENTRY* entry; @@ -393,12 +401,13 @@ BOOL rts_print_pdu_signature(const RtsPduSignature* signature) if (!signature) return FALSE; - WLog_INFO(TAG, "RTS PDU Signature: Flags: 0x%04" PRIX16 " NumberOfCommands: %" PRIu16 "", - signature->Flags, signature->NumberOfCommands); + WLog_Print(log, level, + "RTS PDU Signature: Flags: 0x%04" PRIX16 " NumberOfCommands: %" PRIu16 "", + signature->Flags, signature->NumberOfCommands); SignatureId = rts_identify_pdu_signature(signature, &entry); if (SignatureId) - WLog_ERR(TAG, "Identified %s RTS PDU", entry->PduName); + WLog_Print(log, level, "Identified %s RTS PDU", entry->PduName); return TRUE; } diff --git a/libfreerdp/core/gateway/rts_signature.h b/libfreerdp/core/gateway/rts_signature.h index c883296c7..58b8711b9 100644 --- a/libfreerdp/core/gateway/rts_signature.h +++ b/libfreerdp/core/gateway/rts_signature.h @@ -177,10 +177,14 @@ FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_FLOW_CONTROL_ACK_WITH_DESTINA FREERDP_LOCAL BOOL rts_match_pdu_signature(const RtsPduSignature* signature, wStream* s, const rpcconn_hdr_t* header); +FREERDP_LOCAL BOOL rts_match_pdu_signature_ex(const RtsPduSignature* signature, wStream* s, + const rpcconn_hdr_t* header, + RtsPduSignature* found_signature); FREERDP_LOCAL BOOL rts_extract_pdu_signature(RtsPduSignature* signature, wStream* s, const rpcconn_hdr_t* header); FREERDP_LOCAL UINT32 rts_identify_pdu_signature(const RtsPduSignature* signature, const RTS_PDU_SIGNATURE_ENTRY** entry); -FREERDP_LOCAL BOOL rts_print_pdu_signature(const RtsPduSignature* signature); +FREERDP_LOCAL BOOL rts_print_pdu_signature(wLog* log, DWORD level, + const RtsPduSignature* signature); #endif /* FREERDP_LIB_CORE_GATEWAY_RTS_SIGNATURE_H */