From 0bf225ec6095ea3bb225cb530adf981dc3e6633f Mon Sep 17 00:00:00 2001 From: Kobi Mizrachi Date: Wed, 10 Jun 2020 10:16:59 +0300 Subject: [PATCH] server: proxy: capture: send sid in SessionInfo --- server/proxy/modules/capture/cap_main.c | 4 +--- server/proxy/modules/capture/cap_protocol.c | 19 +++++++++++++------ server/proxy/modules/capture/cap_protocol.h | 6 ++++-- server/proxy/pf_client.c | 3 --- server/proxy/pf_context.c | 14 +++++++++----- server/proxy/pf_context.h | 4 +++- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/server/proxy/modules/capture/cap_main.c b/server/proxy/modules/capture/cap_main.c index 0f5d5bc4f..e71ffe8b9 100644 --- a/server/proxy/modules/capture/cap_main.c +++ b/server/proxy/modules/capture/cap_main.c @@ -209,8 +209,6 @@ static BOOL capture_plugin_client_post_connect(proxyData* pdata) { SOCKET socket; wStream* s; - pClientContext* pc = pdata->pc; - rdpSettings* settings = pc->context.settings; socket = capture_plugin_init_socket(); if (socket == -1) @@ -221,7 +219,7 @@ static BOOL capture_plugin_client_post_connect(proxyData* pdata) g_plugins_manager->SetPluginData(PLUGIN_NAME, pdata, (void*)socket); - s = capture_plugin_create_session_info_packet(settings); + s = capture_plugin_create_session_info_packet(pdata->pc); if (!s) return FALSE; diff --git a/server/proxy/modules/capture/cap_protocol.c b/server/proxy/modules/capture/cap_protocol.c index b56393838..7e61fcd98 100644 --- a/server/proxy/modules/capture/cap_protocol.c +++ b/server/proxy/modules/capture/cap_protocol.c @@ -31,10 +31,16 @@ wStream* capture_plugin_packet_new(UINT32 payload_size, UINT16 type) return stream; } -wStream* capture_plugin_create_session_info_packet(rdpSettings* settings) +wStream* capture_plugin_create_session_info_packet(pClientContext* pc) { UINT16 username_length; wStream* s = NULL; + rdpSettings* settings; + + if (!pc) + return NULL; + + settings = pc->context.settings; if (!settings || !settings->Username) return NULL; @@ -48,10 +54,11 @@ wStream* capture_plugin_create_session_info_packet(rdpSettings* settings) if (!s) return NULL; - Stream_Write_UINT16(s, username_length); /* username length (2 bytes) */ - Stream_Write(s, settings->Username, username_length); /* username */ - Stream_Write_UINT32(s, settings->DesktopWidth); /* desktop width (4 bytes) */ - Stream_Write_UINT32(s, settings->DesktopHeight); /* desktop height (4 bytes) */ - Stream_Write_UINT32(s, settings->ColorDepth); /* color depth (4 bytes) */ + Stream_Write_UINT16(s, username_length); /* username length (2 bytes) */ + Stream_Write(s, settings->Username, username_length); /* username */ + Stream_Write_UINT32(s, settings->DesktopWidth); /* desktop width (4 bytes) */ + Stream_Write_UINT32(s, settings->DesktopHeight); /* desktop height (4 bytes) */ + Stream_Write_UINT32(s, settings->ColorDepth); /* color depth (4 bytes) */ + Stream_Write(s, pc->pdata->session_id, PROXY_SESSION_ID_LENGTH); /* color depth (32 bytes) */ return s; } diff --git a/server/proxy/modules/capture/cap_protocol.h b/server/proxy/modules/capture/cap_protocol.h index 655eb69bd..fcc7f3d65 100644 --- a/server/proxy/modules/capture/cap_protocol.h +++ b/server/proxy/modules/capture/cap_protocol.h @@ -20,9 +20,11 @@ #include #include +#include "pf_context.h" + /* protocol message sizes */ #define HEADER_SIZE 6 -#define SESSION_INFO_PDU_BASE_SIZE 14 +#define SESSION_INFO_PDU_BASE_SIZE 46 #define SESSION_END_PDU_BASE_SIZE 0 #define CAPTURED_FRAME_PDU_BASE_SIZE 0 @@ -32,4 +34,4 @@ #define MESSAGE_TYPE_SESSION_END 3 wStream* capture_plugin_packet_new(UINT32 payload_size, UINT16 type); -wStream* capture_plugin_create_session_info_packet(rdpSettings* settings); +wStream* capture_plugin_create_session_info_packet(pClientContext* pc); diff --git a/server/proxy/pf_client.c b/server/proxy/pf_client.c index 1bb5fe027..13cc9739b 100644 --- a/server/proxy/pf_client.c +++ b/server/proxy/pf_client.c @@ -604,9 +604,6 @@ static void pf_client_context_free(freerdp* instance, rdpContext* context) if (!pc) return; - free(pc->frames_dir); - pc->frames_dir = NULL; - HashTable_Free(pc->vc_ids); } diff --git a/server/proxy/pf_context.c b/server/proxy/pf_context.c index 0ff8b5f15..4bbb5c397 100644 --- a/server/proxy/pf_context.c +++ b/server/proxy/pf_context.c @@ -201,8 +201,10 @@ error: proxyData* proxy_data_new(void) { BYTE temp[16]; - proxyData* pdata = calloc(1, sizeof(proxyData)); + char* hex; + proxyData* pdata; + pdata = calloc(1, sizeof(proxyData)); if (!pdata) return NULL; @@ -213,9 +215,14 @@ proxyData* proxy_data_new(void) goto error; winpr_RAND((BYTE*)&temp, 16); - if (!(pdata->session_id = winpr_BinToHexString(temp, 16, FALSE))) + hex = winpr_BinToHexString(temp, 16, FALSE); + if (!hex) goto error; + CopyMemory(pdata->session_id, hex, PROXY_SESSION_ID_LENGTH); + pdata->session_id[PROXY_SESSION_ID_LENGTH] = '\0'; + free(hex); + if (!(pdata->modules_info = HashTable_New(FALSE))) goto error; @@ -265,9 +272,6 @@ void proxy_data_free(proxyData* pdata) pdata->gfx_server_ready = NULL; } - if (pdata->session_id) - free(pdata->session_id); - if (pdata->modules_info) HashTable_Free(pdata->modules_info); diff --git a/server/proxy/pf_context.h b/server/proxy/pf_context.h index 06be4b034..c4f6a5bb7 100644 --- a/server/proxy/pf_context.h +++ b/server/proxy/pf_context.h @@ -37,6 +37,8 @@ #include "pf_config.h" #include "pf_server.h" +#define PROXY_SESSION_ID_LENGTH 32 + typedef struct proxy_data proxyData; /** @@ -107,7 +109,7 @@ struct proxy_data HANDLE client_thread; HANDLE gfx_server_ready; - char* session_id; + char session_id[PROXY_SESSION_ID_LENGTH + 1]; /* used to external modules to store per-session info */ wHashTable* modules_info;