From 98a4eb77ef1b002ae6ad58d4b31b1b22829a3ada Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 2 Nov 2023 15:38:13 +0100 Subject: [PATCH] [core] VirtualChannelChunkSize adjustments * add CHANNEL_CHUNK_MAX_LENGTH * remove duplicate definitions * default to CHANNEL_CHUNK_MAX_LENGTH --- include/freerdp/settings.h | 1 + libfreerdp/core/capabilities.c | 18 +++++++++++------- libfreerdp/core/rdp.c | 5 +---- libfreerdp/core/settings.c | 11 +++++++---- winpr/include/winpr/wtsapi.h | 2 ++ 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/include/freerdp/settings.h b/include/freerdp/settings.h index a39ad9cee..419e40768 100644 --- a/include/freerdp/settings.h +++ b/include/freerdp/settings.h @@ -1723,6 +1723,7 @@ extern "C" * rdpSettings creation flags */ #define FREERDP_SETTINGS_SERVER_MODE 0x00000001 +#define FREERDP_SETTINGS_REMOTE_MODE 0x00000002 /** \brief creates a new setting struct * diff --git a/libfreerdp/core/capabilities.c b/libfreerdp/core/capabilities.c index 3a885bb4e..837974565 100644 --- a/libfreerdp/core/capabilities.c +++ b/libfreerdp/core/capabilities.c @@ -17,6 +17,7 @@ * limitations under the License. */ +#include #include #include "capabilities.h" @@ -29,8 +30,6 @@ #define TAG FREERDP_TAG("core.capabilities") -#define CHANNEL_CHUNK_LENGTH 1600 - static const char* const CAPSET_TYPE_STRINGS[] = { "Unknown", "General", "Bitmap", @@ -2120,11 +2119,16 @@ static BOOL rdp_apply_virtual_channel_capability_set(rdpSettings* settings, cons * larger than CHANNEL_CHUNK_LENGTH (1600) bytes. * Also prevent an invalid 0 size. */ - if (!settings->ServerMode && - ((src->VirtualChannelChunkSize > 16256) || (src->VirtualChannelChunkSize == 0))) - settings->VirtualChannelChunkSize = CHANNEL_CHUNK_LENGTH; - else if (!settings->ServerMode) - settings->VirtualChannelChunkSize = src->VirtualChannelChunkSize; + if (!settings->ServerMode) + { + if ((src->VirtualChannelChunkSize > CHANNEL_CHUNK_MAX_LENGTH) || + (src->VirtualChannelChunkSize == 0)) + settings->VirtualChannelChunkSize = CHANNEL_CHUNK_LENGTH; + else + { + settings->VirtualChannelChunkSize = src->VirtualChannelChunkSize; + } + } return TRUE; } diff --git a/libfreerdp/core/rdp.c b/libfreerdp/core/rdp.c index 8dcd4c47d..58d771e72 100644 --- a/libfreerdp/core/rdp.c +++ b/libfreerdp/core/rdp.c @@ -2220,7 +2220,6 @@ rdpRdp* rdp_new(rdpContext* context) { rdpRdp* rdp; DWORD flags = 0; - DWORD remoteFlags = 0; rdp = (rdpRdp*)calloc(1, sizeof(rdpRdp)); if (!rdp) @@ -2238,8 +2237,6 @@ rdpRdp* rdp_new(rdpContext* context) if (context->ServerMode) flags |= FREERDP_SETTINGS_SERVER_MODE; - else - remoteFlags |= FREERDP_SETTINGS_SERVER_MODE; if (!context->settings) { @@ -2679,7 +2676,7 @@ const char* rdp_security_flag_string(UINT32 securityFlags, char* buffer, size_t static BOOL rdp_reset_remote_settings(rdpRdp* rdp) { - UINT32 flags = 0; + UINT32 flags = FREERDP_SETTINGS_REMOTE_MODE; WINPR_ASSERT(rdp); freerdp_settings_free(rdp->remoteSettings); diff --git a/libfreerdp/core/settings.c b/libfreerdp/core/settings.c index 315418ff4..105619bf9 100644 --- a/libfreerdp/core/settings.c +++ b/libfreerdp/core/settings.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -340,6 +341,8 @@ rdpSettings* freerdp_settings_new(DWORD flags) { char* base; char* issuers[] = { "FreeRDP", "FreeRDP-licenser" }; + const BOOL server = (flags & FREERDP_SETTINGS_SERVER_MODE) != 0 ? TRUE : FALSE; + const BOOL remote = (flags & FREERDP_SETTINGS_REMOTE_MODE) != 0 ? TRUE : FALSE; rdpSettings* settings = (rdpSettings*)calloc(1, sizeof(rdpSettings)); if (!settings) @@ -381,8 +384,7 @@ rdpSettings* freerdp_settings_new(DWORD flags) NEGOTIATE_ORDER_SUPPORT | ZERO_BOUNDS_DELTA_SUPPORT | COLOR_INDEX_SUPPORT) || !freerdp_settings_set_bool(settings, FreeRDP_SupportHeartbeatPdu, TRUE) || - !freerdp_settings_set_bool(settings, FreeRDP_ServerMode, - (flags & FREERDP_SETTINGS_SERVER_MODE) ? TRUE : FALSE) || + !freerdp_settings_set_bool(settings, FreeRDP_ServerMode, server) || !freerdp_settings_set_bool(settings, FreeRDP_WaitForOutputBufferFlush, TRUE) || !freerdp_settings_set_uint32(settings, FreeRDP_ClusterInfoFlags, REDIRECTION_SUPPORTED) || !freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, 1024) || @@ -627,11 +629,12 @@ rdpSettings* freerdp_settings_new(DWORD flags) !freerdp_settings_set_uint32(settings, FreeRDP_RemoteAppNumIconCaches, 3) || !freerdp_settings_set_uint32(settings, FreeRDP_RemoteAppNumIconCacheEntries, 12) || !freerdp_settings_set_uint32(settings, FreeRDP_VirtualChannelChunkSize, - CHANNEL_CHUNK_LENGTH) || + (server && !remote) ? CHANNEL_CHUNK_MAX_LENGTH + : CHANNEL_CHUNK_LENGTH) || /* [MS-RDPBCGR] 2.2.7.2.7 Large Pointer Capability Set (TS_LARGE_POINTER_CAPABILITYSET) requires at least this size */ !freerdp_settings_set_uint32(settings, FreeRDP_MultifragMaxRequestSize, - (flags & FREERDP_SETTINGS_SERVER_MODE) ? 0 : 608299) || + server ? 0 : 608299) || !freerdp_settings_set_bool(settings, FreeRDP_GatewayUseSameCredentials, FALSE) || !freerdp_settings_set_bool(settings, FreeRDP_GatewayBypassLocal, FALSE) || !freerdp_settings_set_bool(settings, FreeRDP_GatewayRpcTransport, TRUE) || diff --git a/winpr/include/winpr/wtsapi.h b/winpr/include/winpr/wtsapi.h index ac3b38176..bd5616f1d 100644 --- a/winpr/include/winpr/wtsapi.h +++ b/winpr/include/winpr/wtsapi.h @@ -27,6 +27,8 @@ #include +#define CHANNEL_CHUNK_MAX_LENGTH 16256 + #ifdef _WIN32 #define CurrentTime _CurrentTime /* Workaround for X11 "CurrentTime" header conflict */