From 70ca0284537f26881e7616e8c2a60c4008eeb64c Mon Sep 17 00:00:00 2001 From: kubistika Date: Tue, 16 Jul 2019 16:08:45 +0300 Subject: [PATCH 1/6] server: proxy: remove unnecessary files --- server/proxy/CMakeLists.txt | 2 - server/proxy/pf_client.c | 1 - server/proxy/pf_common.c | 112 ------------------------------------ server/proxy/pf_common.h | 31 ---------- server/proxy/pf_context.c | 1 - server/proxy/pf_server.c | 1 - 6 files changed, 148 deletions(-) delete mode 100644 server/proxy/pf_common.c delete mode 100644 server/proxy/pf_common.h diff --git a/server/proxy/CMakeLists.txt b/server/proxy/CMakeLists.txt index 4133a3aa9..727d469cc 100644 --- a/server/proxy/CMakeLists.txt +++ b/server/proxy/CMakeLists.txt @@ -37,8 +37,6 @@ set(${MODULE_PREFIX}_SRCS pf_disp.h pf_server.c pf_server.h - pf_common.c - pf_common.h pf_gdi.c pf_gdi.h pf_config.c diff --git a/server/proxy/pf_client.c b/server/proxy/pf_client.c index 8c9cb5391..ad1a13529 100644 --- a/server/proxy/pf_client.c +++ b/server/proxy/pf_client.c @@ -45,7 +45,6 @@ #include "pf_channels.h" #include "pf_gdi.h" #include "pf_graphics.h" -#include "pf_common.h" #include "pf_client.h" #include "pf_context.h" #include "pf_update.h" diff --git a/server/proxy/pf_common.c b/server/proxy/pf_common.c deleted file mode 100644 index b9dcf4cfb..000000000 --- a/server/proxy/pf_common.c +++ /dev/null @@ -1,112 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * FreeRDP Proxy Server - * - * Copyright 2019 Mati Shabtay - * Copyright 2019 Kobi Mizrachi - * Copyright 2019 Idan Freiberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "pf_common.h" - -BOOL pf_common_connection_aborted_by_peer(proxyData* pdata) -{ - return WaitForSingleObject(pdata->connectionClosed, 0) == WAIT_OBJECT_0; -} - -void pf_common_copy_settings(rdpSettings* dst, rdpSettings* src) -{ - /* Client/server CORE options */ - dst->RdpVersion = src->RdpVersion; - dst->DesktopWidth = src->DesktopWidth; - dst->DesktopHeight = src->DesktopHeight; - dst->ColorDepth = src->ColorDepth; - dst->ConnectionType = src->ConnectionType; - dst->ClientBuild = src->ClientBuild; - dst->ClientHostname = _strdup(src->ClientHostname); - dst->ClientProductId = _strdup(src->ClientProductId); - dst->EarlyCapabilityFlags = src->EarlyCapabilityFlags; - dst->NetworkAutoDetect = src->NetworkAutoDetect; - dst->SupportAsymetricKeys = src->SupportAsymetricKeys; - dst->SupportErrorInfoPdu = src->SupportErrorInfoPdu; - dst->SupportStatusInfoPdu = src->SupportStatusInfoPdu; - dst->SupportMonitorLayoutPdu = src->SupportMonitorLayoutPdu; - dst->SupportGraphicsPipeline = src->SupportGraphicsPipeline; - dst->SupportDynamicTimeZone = src->SupportDynamicTimeZone; - dst->SupportHeartbeatPdu = src->SupportHeartbeatPdu; - dst->DesktopPhysicalWidth = src->DesktopPhysicalWidth; - dst->DesktopPhysicalHeight = src->DesktopPhysicalHeight; - dst->DesktopOrientation = src->DesktopOrientation; - dst->DesktopScaleFactor = src->DesktopScaleFactor; - dst->DeviceScaleFactor = src->DeviceScaleFactor; - dst->SupportMonitorLayoutPdu = src->SupportMonitorLayoutPdu; - /* client info */ - dst->AutoLogonEnabled = src->AutoLogonEnabled; - dst->CompressionEnabled = src->CompressionEnabled; - dst->DisableCtrlAltDel = src->DisableCtrlAltDel; - dst->EnableWindowsKey = src->EnableWindowsKey; - dst->MaximizeShell = src->MaximizeShell; - dst->LogonNotify = src->LogonNotify; - dst->LogonErrors = src->LogonErrors; - dst->MouseAttached = src->MouseAttached; - dst->MouseHasWheel = src->MouseHasWheel; - dst->RemoteConsoleAudio = src->RemoteConsoleAudio; - dst->AudioPlayback = src->AudioPlayback; - dst->AudioCapture = src->AudioCapture; - dst->VideoDisable = src->VideoDisable; - dst->PasswordIsSmartcardPin = src->PasswordIsSmartcardPin; - dst->UsingSavedCredentials = src->UsingSavedCredentials; - dst->ForceEncryptedCsPdu = src->ForceEncryptedCsPdu; - dst->HiDefRemoteApp = src->HiDefRemoteApp; - dst->CompressionLevel = src->CompressionLevel; - dst->PerformanceFlags = src->PerformanceFlags; - dst->AllowFontSmoothing = src->AllowFontSmoothing; - dst->DisableWallpaper = src->DisableWallpaper; - dst->DisableFullWindowDrag = src->DisableFullWindowDrag; - dst->DisableMenuAnims = src->DisableMenuAnims; - dst->DisableThemes = src->DisableThemes; - dst->DisableCursorShadow = src->DisableCursorShadow; - dst->DisableCursorBlinking = src->DisableCursorBlinking; - dst->AllowDesktopComposition = src->AllowDesktopComposition; - dst->DisableThemes = src->DisableThemes; - /* Remote App */ - dst->RemoteApplicationMode = src->RemoteApplicationMode; - dst->RemoteApplicationName = src->RemoteApplicationName; - dst->RemoteApplicationIcon = src->RemoteApplicationIcon; - dst->RemoteApplicationProgram = src->RemoteApplicationProgram; - dst->RemoteApplicationFile = src->RemoteApplicationFile; - dst->RemoteApplicationGuid = src->RemoteApplicationGuid; - dst->RemoteApplicationCmdLine = src->RemoteApplicationCmdLine; - dst->RemoteApplicationExpandCmdLine = src->RemoteApplicationExpandCmdLine; - dst->RemoteApplicationExpandWorkingDir = src->RemoteApplicationExpandWorkingDir; - dst->DisableRemoteAppCapsCheck = src->DisableRemoteAppCapsCheck; - dst->RemoteAppNumIconCaches = src->RemoteAppNumIconCaches; - dst->RemoteAppNumIconCacheEntries = src->RemoteAppNumIconCacheEntries; - dst->RemoteAppLanguageBarSupported = src->RemoteAppLanguageBarSupported; - dst->RemoteWndSupportLevel = src->RemoteWndSupportLevel; - /* GFX */ - dst->GfxThinClient = src->GfxThinClient; - dst->GfxSmallCache = src->GfxSmallCache; - dst->GfxProgressive = src->GfxProgressive; - dst->GfxProgressiveV2 = src->GfxProgressiveV2; - dst->GfxH264 = src->GfxH264; - dst->GfxAVC444 = src->GfxAVC444; - dst->GfxSendQoeAck = src->GfxSendQoeAck; - dst->GfxAVC444v2 = src->GfxAVC444v2; - dst->SupportDisplayControl = src->SupportDisplayControl; - dst->SupportMonitorLayoutPdu = src->SupportMonitorLayoutPdu; - dst->DynamicResolutionUpdate = src->DynamicResolutionUpdate; - dst->DesktopResize = src->DesktopResize; -} diff --git a/server/proxy/pf_common.h b/server/proxy/pf_common.h deleted file mode 100644 index 9cca30ddb..000000000 --- a/server/proxy/pf_common.h +++ /dev/null @@ -1,31 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * FreeRDP Proxy Server - * - * Copyright 2019 Mati Shabtay - * Copyright 2019 Kobi Mizrachi - * Copyright 2019 Idan Freiberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FREERDP_SERVER_PROXY_PFCOMMON_H -#define FREERDP_SERVER_PROXY_PFCOMMON_H - -#include -#include "pf_context.h" - -BOOL pf_common_connection_aborted_by_peer(proxyData* pdata); -void pf_common_copy_settings(rdpSettings* dst, rdpSettings* src); - -#endif /* FREERDP_SERVER_PROXY_PFCOMMON_H */ diff --git a/server/proxy/pf_context.c b/server/proxy/pf_context.c index 2d29c5457..3729d9db8 100644 --- a/server/proxy/pf_context.c +++ b/server/proxy/pf_context.c @@ -21,7 +21,6 @@ #include "pf_client.h" #include "pf_context.h" -#include "pf_common.h" /* Proxy context initialization callback */ static BOOL client_to_proxy_context_new(freerdp_peer* client, diff --git a/server/proxy/pf_server.c b/server/proxy/pf_server.c index 5bf65122a..4a69864be 100644 --- a/server/proxy/pf_server.c +++ b/server/proxy/pf_server.c @@ -41,7 +41,6 @@ #include #include "pf_server.h" -#include "pf_common.h" #include "pf_log.h" #include "pf_config.h" #include "pf_client.h" From e9e1c5d74834b994b828116791b1fc60ab2c2706 Mon Sep 17 00:00:00 2001 From: kubistika Date: Tue, 16 Jul 2019 16:13:12 +0300 Subject: [PATCH 2/6] server: proxy: naming refactor --- server/proxy/pf_client.c | 16 ++++++++++------ server/proxy/pf_context.c | 24 ++++++++++++++++++++---- server/proxy/pf_context.h | 13 ++++++++++--- server/proxy/pf_server.c | 17 +++++++++-------- 4 files changed, 49 insertions(+), 21 deletions(-) diff --git a/server/proxy/pf_client.c b/server/proxy/pf_client.c index ad1a13529..ea945e9d3 100644 --- a/server/proxy/pf_client.c +++ b/server/proxy/pf_client.c @@ -213,7 +213,7 @@ static void pf_client_post_disconnect(freerdp* instance) /* proxy's client failed to connect, and now it's trying to connect without NLA, no need to shutdown * the connection between proxy's server and the original client. */ - SetEvent(pdata->connectionClosed); + proxy_data_abort_connect(pdata); } /* It's important to avoid calling `freerdp_peer_context_free` and `freerdp_peer_free` here, @@ -396,14 +396,18 @@ static BOOL pf_client_client_new(freerdp* instance, rdpContext* context) static int pf_client_client_stop(rdpContext* context) { pClientContext* pc = (pClientContext*) context; - pServerContext* ps = pc->pdata->ps; + proxyData* pdata = pc->pdata; + WLog_DBG(TAG, "aborting client connection"); freerdp_abort_connect(context->instance); - if (ps->thread) + if (pdata->client_thread) { - WaitForSingleObject(ps->thread, INFINITE); - CloseHandle(ps->thread); - ps->thread = NULL; + /* Wait for client thread to finish. No need to call CloseHandle() here, as + * it is the responsibility of `proxy_data_free`. + */ + WLog_DBG(TAG, "pf_client_client_stop(): waiting for thread to finish"); + WaitForSingleObject(pdata->client_thread, INFINITE); + WLog_DBG(TAG, "pf_client_client_stop(): thread finished"); } return 0; diff --git a/server/proxy/pf_context.c b/server/proxy/pf_context.c index 3729d9db8..bcca78e4a 100644 --- a/server/proxy/pf_context.c +++ b/server/proxy/pf_context.c @@ -161,7 +161,7 @@ proxyData* proxy_data_new() return NULL; } - if (!(pdata->connectionClosed = CreateEvent(NULL, TRUE, FALSE, NULL))) + if (!(pdata->abort_event = CreateEvent(NULL, TRUE, FALSE, NULL))) { proxy_data_free(pdata); return NULL; @@ -191,11 +191,27 @@ out_fail: void proxy_data_free(proxyData* pdata) { connection_info_free(pdata->info); - if (pdata->connectionClosed) + if (pdata->abort_event) { - CloseHandle(pdata->connectionClosed); - pdata->connectionClosed = NULL; + CloseHandle(pdata->abort_event); + pdata->abort_event = NULL; + } + + if (pdata->client_thread) + { + CloseHandle(pdata->client_thread); + pdata->client_thread = NULL; } free(pdata); } + +void proxy_data_abort_connect(proxyData* pdata) +{ + SetEvent(pdata->abort_event); +} + +BOOL proxy_data_shall_disconnect(proxyData* pdata) +{ + return WaitForSingleObject(pdata->abort_event, 0) == WAIT_OBJECT_0; +} diff --git a/server/proxy/pf_context.h b/server/proxy/pf_context.h index 015a88bf7..7777500c0 100644 --- a/server/proxy/pf_context.h +++ b/server/proxy/pf_context.h @@ -46,7 +46,6 @@ struct p_server_context proxyData* pdata; HANDLE vcm; - HANDLE thread; HANDLE dynvcReady; RdpgfxServerContext* gfx; @@ -91,17 +90,25 @@ struct proxy_data pServerContext* ps; pClientContext* pc; - HANDLE connectionClosed; + HANDLE abort_event; + HANDLE client_thread; connectionInfo* info; filters_list* filters; }; -BOOL init_p_server_context(freerdp_peer* client); +/* client */ rdpContext* p_client_context_create(rdpSettings* clientSettings); + +/* pdata */ proxyData* proxy_data_new(); BOOL proxy_data_set_connection_info(proxyData* pdata, rdpSettings* ps, rdpSettings* pc); void proxy_data_free(proxyData* pdata); void pf_context_copy_settings(rdpSettings* dst, const rdpSettings* src, BOOL is_server); +void proxy_data_abort_connect(proxyData* pdata); +BOOL proxy_data_shall_disconnect(proxyData* pdata); + +/* server */ +BOOL init_p_server_context(freerdp_peer* client); #endif /* FREERDP_SERVER_PROXY_PFCONTEXT_H */ diff --git a/server/proxy/pf_server.c b/server/proxy/pf_server.c index 4a69864be..de55c3da1 100644 --- a/server/proxy/pf_server.c +++ b/server/proxy/pf_server.c @@ -182,7 +182,7 @@ static BOOL pf_server_post_connect(freerdp_peer* client) pf_server_disp_init(ps); /* Start a proxy's client in it's own thread */ - if (!(ps->thread = CreateThread(NULL, 0, pf_client_start, pc, 0, NULL))) + if (!(pdata->client_thread = CreateThread(NULL, 0, pf_client_start, pc, 0, NULL))) { WLog_ERR(TAG, "CreateThread failed!"); return FALSE; @@ -295,7 +295,7 @@ static DWORD WINAPI pf_server_handle_client(LPVOID arg) eventCount += tmp; } eventHandles[eventCount++] = ChannelEvent; - eventHandles[eventCount++] = pdata->connectionClosed; + eventHandles[eventCount++] = pdata->abort_event; eventHandles[eventCount++] = WTSVirtualChannelManagerGetEventHandle(ps->vcm); status = WaitForMultipleObjects(eventCount, eventHandles, FALSE, INFINITE); @@ -305,12 +305,6 @@ static DWORD WINAPI pf_server_handle_client(LPVOID arg) break; } - if (pf_common_connection_aborted_by_peer(pdata)) - { - WLog_INFO(TAG, "proxy's client disconnected, closing connection with client %s", client->hostname); - break; - } - if (client->CheckFileDescriptor(client) != TRUE) break; @@ -323,6 +317,13 @@ static DWORD WINAPI pf_server_handle_client(LPVOID arg) } } + /* only disconnect after checking client's and vcm's file descriptors */ + if (proxy_data_shall_disconnect(pdata)) + { + WLog_INFO(TAG, "abort_event is set, closing connection with client %s", client->hostname); + break; + } + switch (WTSVirtualChannelManagerGetDrdynvcState(ps->vcm)) { /* Dynamic channel status may have been changed after processing */ From 95851b25e75534df7feb758f9f6ad1b04317d24a Mon Sep 17 00:00:00 2001 From: kubistika Date: Tue, 16 Jul 2019 16:14:06 +0300 Subject: [PATCH 3/6] server: proxy: set nla fallback flag flag only if NLASecurity is enabled --- server/proxy/pf_client.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/proxy/pf_client.c b/server/proxy/pf_client.c index ea945e9d3..7ae584297 100644 --- a/server/proxy/pf_client.c +++ b/server/proxy/pf_client.c @@ -234,7 +234,12 @@ static DWORD WINAPI pf_client_thread_proc(LPVOID arg) DWORD status; HANDLE handles[64]; - pc->during_connect_process = TRUE; + /* Only set the `during_connect_process` flag if NlaSecurity is enabled. + * If NLASecurity isn't enabled, the connection should be closed right after the first failure. + */ + if (instance->settings->NlaSecurity) + pc->during_connect_process = TRUE; + if (!freerdp_connect(instance)) { if (instance->settings->NlaSecurity) From b12ee3288c2e22b49eb3b7f26401e43145c2ea3d Mon Sep 17 00:00:00 2001 From: kubistika Date: Tue, 16 Jul 2019 16:14:38 +0300 Subject: [PATCH 4/6] server: proxy: adjust log levels --- server/proxy/pf_filters.c | 2 +- server/proxy/pf_rdpgfx.c | 48 +++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/server/proxy/pf_filters.c b/server/proxy/pf_filters.c index 774146e85..121a839df 100644 --- a/server/proxy/pf_filters.c +++ b/server/proxy/pf_filters.c @@ -93,7 +93,7 @@ PF_FILTER_RESULT pf_filters_run_by_type(filters_list* list, PF_FILTER_TYPE type, { filter = (proxyFilter*) ArrayList_GetItem(list, index); events = filter->events; - WLog_DBG(TAG, "pf_filters_run_by_type(): Running filter: %s", filter->name); + WLog_VRB(TAG, "pf_filters_run_by_type(): Running filter: %s", filter->name); switch (type) { diff --git a/server/proxy/pf_rdpgfx.c b/server/proxy/pf_rdpgfx.c index a729dc871..56de9302d 100644 --- a/server/proxy/pf_rdpgfx.c +++ b/server/proxy/pf_rdpgfx.c @@ -49,7 +49,7 @@ static UINT pf_rdpgfx_reset_graphics(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->ResetGraphics(server, resetGraphics); } @@ -58,7 +58,7 @@ static UINT pf_rdpgfx_start_frame(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->StartFrame(server, startFrame); } @@ -67,7 +67,7 @@ static UINT pf_rdpgfx_end_frame(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->EndFrame(server, endFrame); } @@ -76,7 +76,7 @@ static UINT pf_rdpgfx_surface_command(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->SurfaceCommand(server, cmd); } @@ -85,7 +85,7 @@ static UINT pf_rdpgfx_delete_encoding_context(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->DeleteEncodingContext(server, deleteEncodingContext); } @@ -94,7 +94,7 @@ static UINT pf_rdpgfx_create_surface(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->CreateSurface(server, createSurface); } @@ -103,7 +103,7 @@ static UINT pf_rdpgfx_delete_surface(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->DeleteSurface(server, deleteSurface); } @@ -112,7 +112,7 @@ static UINT pf_rdpgfx_solid_fill(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->SolidFill(server, solidFill); } @@ -121,7 +121,7 @@ static UINT pf_rdpgfx_surface_to_surface(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->SurfaceToSurface(server, surfaceToSurface); } @@ -130,7 +130,7 @@ static UINT pf_rdpgfx_surface_to_cache(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->SurfaceToCache(server, surfaceToCache); } @@ -139,7 +139,7 @@ static UINT pf_rdpgfx_cache_to_surface(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->CacheToSurface(server, cacheToSurface); } @@ -148,7 +148,7 @@ static UINT pf_rdpgfx_cache_import_reply(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->CacheImportReply(server, cacheImportReply); } @@ -157,7 +157,7 @@ static UINT pf_rdpgfx_evict_cache_entry(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->EvictCacheEntry(server, evictCacheEntry); } @@ -166,7 +166,7 @@ static UINT pf_rdpgfx_map_surface_to_output(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->MapSurfaceToOutput(server, surfaceToOutput); } @@ -175,7 +175,7 @@ static UINT pf_rdpgfx_map_surface_to_window(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->MapSurfaceToWindow(server, surfaceToWindow); } @@ -184,7 +184,7 @@ static UINT pf_rdpgfx_map_surface_to_scaled_window(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->MapSurfaceToScaledWindow(server, surfaceToScaledWindow); } @@ -194,7 +194,7 @@ static UINT pf_rdpgfx_map_surface_to_scaled_output(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->MapSurfaceToScaledOutput(server, surfaceToScaledOutput); } @@ -203,7 +203,7 @@ static UINT pf_rdpgfx_on_open(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); if (NULL != do_caps_advertise) *do_caps_advertise = FALSE; @@ -229,7 +229,7 @@ static UINT pf_rdpgfx_on_close(RdpgfxClientContext* context) { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->Close(server) ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR; } @@ -238,7 +238,7 @@ static UINT pf_rdpgfx_caps_confirm(RdpgfxClientContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxServerContext* server = (RdpgfxServerContext*) pdata->ps->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return server->CapsConfirm(server, capsConfirm); } @@ -273,7 +273,7 @@ static UINT pf_rdpgfx_caps_advertise(RdpgfxServerContext* context, supportedCapsAdvertise.capsSetCount = proxySupportedCapsSetCount; supportedCapsAdvertise.capsSets = proxySupportedCapsSets; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return client->CapsAdvertise(client, &supportedCapsAdvertise); } @@ -282,7 +282,7 @@ static UINT pf_rdpgfx_frame_acknowledge(RdpgfxServerContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxClientContext* client = (RdpgfxClientContext*) pdata->pc->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return client->FrameAcknowledge(client, frameAcknowledge); } @@ -291,7 +291,7 @@ static UINT pf_rdpgfx_qoe_frame_acknowledge(RdpgfxServerContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxClientContext* client = (RdpgfxClientContext*) pdata->pc->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return client->QoeFrameAcknowledge(client, qoeFrameAcknowledge); } @@ -300,7 +300,7 @@ static UINT pf_rdpgfx_cache_import_offer(RdpgfxServerContext* context, { proxyData* pdata = (proxyData*) context->custom; RdpgfxClientContext* client = (RdpgfxClientContext*) pdata->pc->gfx; - WLog_DBG(TAG, __FUNCTION__); + WLog_VRB(TAG, __FUNCTION__); return client->CacheImportOffer(client, cacheImportOffer); } From d0065ee9a155ec28104343884836d76ea1549309 Mon Sep 17 00:00:00 2001 From: kubistika Date: Tue, 16 Jul 2019 16:18:26 +0300 Subject: [PATCH 5/6] server: proxy: remove unnecessary function handle_client_disconnection --- server/proxy/pf_server.c | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/server/proxy/pf_server.c b/server/proxy/pf_server.c index de55c3da1..5e4c78225 100644 --- a/server/proxy/pf_server.c +++ b/server/proxy/pf_server.c @@ -52,23 +52,6 @@ #define TAG PROXY_TAG("server") -static void pf_server_handle_client_disconnection(freerdp_peer* client) -{ - pServerContext* ps = (pServerContext*)client->context; - rdpContext* pc = (rdpContext*) ps->pdata->pc; - proxyData* pdata = ps->pdata; - WLog_INFO(TAG, "Connection with %s was closed; closing proxy's client <> target server connection %s", - client->hostname, pc->settings->ServerHostname); - /* Mark connection closed for sContext */ - SetEvent(pdata->connectionClosed); - freerdp_abort_connect(pc->instance); - /* Close connection to remote host */ - WLog_DBG(TAG, "Waiting for proxy's client thread to finish"); - WaitForSingleObject(ps->thread, INFINITE); - CloseHandle(ps->thread); - ps->thread = NULL; -} - static BOOL pf_server_parse_target_from_routing_token(rdpContext* context, char** target, DWORD* port) { @@ -366,11 +349,6 @@ fail: if (ps->gfx) rdpgfx_server_context_free(ps->gfx); - - if (client->connected && !pf_common_connection_aborted_by_peer(pdata)) - { - pf_server_handle_client_disconnection(client); - } pc = (rdpContext*) pdata->pc; freerdp_client_stop(pc); From 908d6ebe1e6a608a29470087a5d7e5f939076caa Mon Sep 17 00:00:00 2001 From: kubistika Date: Tue, 16 Jul 2019 16:19:15 +0300 Subject: [PATCH 6/6] server: proxy: Add logs, call client->Close to send disconnection ultimatum --- server/proxy/pf_server.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/proxy/pf_server.c b/server/proxy/pf_server.c index 5e4c78225..12252d4c6 100644 --- a/server/proxy/pf_server.c +++ b/server/proxy/pf_server.c @@ -351,9 +351,13 @@ fail: rdpgfx_server_context_free(ps->gfx); pc = (rdpContext*) pdata->pc; + WLog_INFO(TAG, "pf_server_handle_client(): starting shutdown of connection (client %s)", client->hostname); + WLog_INFO(TAG, "pf_server_handle_client(): stopping proxy's client"); freerdp_client_stop(pc); + WLog_INFO(TAG, "pf_server_handle_client(): freeing proxy data"); proxy_data_free(pdata); freerdp_client_context_free(pc); + client->Close(client); client->Disconnect(client); out_free_peer: freerdp_peer_context_free(client);