From 99f3a9c0e6be54f4db7380d3087c545550be73c5 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 25 Oct 2023 16:53:22 +0200 Subject: [PATCH] [core,gateway] add rts_recv_ping_pdu --- libfreerdp/core/gateway/rpc_client.c | 8 +++----- libfreerdp/core/gateway/rts.c | 30 ++++++++++++++++++++++++++++ libfreerdp/core/gateway/rts.h | 2 ++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/libfreerdp/core/gateway/rpc_client.c b/libfreerdp/core/gateway/rpc_client.c index 42ef9bf53..e04e69b48 100644 --- a/libfreerdp/core/gateway/rpc_client.c +++ b/libfreerdp/core/gateway/rpc_client.c @@ -195,15 +195,13 @@ static int rpc_client_recv_pdu_int(rdpRpc* rpc, RPC_PDU* pdu) WLog_VRB(TAG, "client state %s, vc state %s", rpc_client_state_str(rpc->State), rpc_vc_state_str(rpc->VirtualConnection->State)); - if (!rts_extract_pdu_signature(&found, pdu->s, NULL)) - return FALSE; + const BOOL rc = rts_match_pdu_signature_ex(&RTS_PDU_PING_SIGNATURE, pdu->s, NULL, &found); rts_print_pdu_signature(rpc->log, WLOG_TRACE, &found); + if (rc) + return rts_recv_ping_pdu(rpc, pdu->s); if (rpc->VirtualConnection->State < VIRTUAL_CONNECTION_STATE_OPENED) { - if (rts_match_pdu_signature_ex(&RTS_PDU_PING_SIGNATURE, pdu->s, NULL, &found)) - return 1; - switch (rpc->VirtualConnection->State) { case VIRTUAL_CONNECTION_STATE_INITIAL: diff --git a/libfreerdp/core/gateway/rts.c b/libfreerdp/core/gateway/rts.c index 04e19ec95..fefac17e2 100644 --- a/libfreerdp/core/gateway/rts.c +++ b/libfreerdp/core/gateway/rts.c @@ -1862,6 +1862,36 @@ static int rts_recv_flow_control_ack_with_destination_pdu(rdpRpc* rpc, wStream* return 1; } +BOOL rts_recv_ping_pdu(rdpRpc* rpc, wStream* s) +{ + BOOL rc = FALSE; + rpcconn_hdr_t header = { 0 }; + + WINPR_ASSERT(rpc); + WINPR_ASSERT(rpc->auth); + WINPR_ASSERT(s); + + if (!rts_read_pdu_header(s, &header)) + goto fail; + + rc = TRUE; + if (header.common.ptype != PTYPE_RTS) + { + WLog_Print(rpc->log, WLOG_ERROR, "received invalid ping PDU, type is 0x%" PRIx32, + header.common.ptype); + rc = FALSE; + } + if (header.rts.Flags != RTS_FLAG_PING) + { + WLog_Print(rpc->log, WLOG_ERROR, "received unexpected ping PDU::Flags 0x%" PRIx32, + header.rts.Flags); + rc = FALSE; + } +fail: + rts_free_pdu_header(&header, FALSE); + return rc; +} + static int rts_send_ping_pdu(rdpRpc* rpc) { BOOL status = FALSE; diff --git a/libfreerdp/core/gateway/rts.h b/libfreerdp/core/gateway/rts.h index 77c44affd..a76efb566 100644 --- a/libfreerdp/core/gateway/rts.h +++ b/libfreerdp/core/gateway/rts.h @@ -104,4 +104,6 @@ FREERDP_LOCAL BOOL rts_send_flow_control_ack_pdu(rdpRpc* rpc); FREERDP_LOCAL BOOL rts_recv_out_of_sequence_pdu(rdpRpc* rpc, wStream* buffer, const rpcconn_hdr_t* header); +FREERDP_LOCAL BOOL rts_recv_ping_pdu(rdpRpc* rpc, wStream* s); + #endif /* FREERDP_LIB_CORE_GATEWAY_RTS_H */