From 78b8df86bc13f0c6eab46ca987510477072184d3 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 17 Jan 2023 12:39:29 +0100 Subject: [PATCH] [core] unify settings copy set/reset --- libfreerdp/core/freerdp.c | 9 +------- libfreerdp/core/peer.c | 2 +- libfreerdp/core/rdp.c | 43 ++++++++++++++++++++++++++++------- libfreerdp/core/rdp.h | 3 +++ libfreerdp/core/redirection.c | 10 ++------ 5 files changed, 42 insertions(+), 25 deletions(-) diff --git a/libfreerdp/core/freerdp.c b/libfreerdp/core/freerdp.c index 55bf2df37..ece93c44e 100644 --- a/libfreerdp/core/freerdp.c +++ b/libfreerdp/core/freerdp.c @@ -105,14 +105,7 @@ static int freerdp_connect_begin(freerdp* instance) if (status) { - freerdp_settings_free(rdp->originalSettings); - rdp->originalSettings = freerdp_settings_clone(settings); - if (!rdp->originalSettings) - return 0; - - freerdp_settings_free(rdp->remoteSettings); - rdp->remoteSettings = freerdp_settings_new(0); - if (!rdp->remoteSettings) + if (!rdp_set_backup_settings(rdp)) return 0; WINPR_ASSERT(instance->LoadChannels); diff --git a/libfreerdp/core/peer.c b/libfreerdp/core/peer.c index 7d788c08e..dc2c63c79 100644 --- a/libfreerdp/core/peer.c +++ b/libfreerdp/core/peer.c @@ -1240,7 +1240,7 @@ static BOOL freerdp_peer_send_server_redirection_pdu(freerdp_peer* peer, if (!rdp_send_pdu(peer->context->rdp, s, PDU_TYPE_SERVER_REDIRECTION, 0)) goto fail; - return TRUE; + return rdp_reset_runtime_settings(peer->context->rdp); fail: Stream_Release(s); return FALSE; diff --git a/libfreerdp/core/rdp.c b/libfreerdp/core/rdp.c index e83146aa2..72918e99a 100644 --- a/libfreerdp/core/rdp.c +++ b/libfreerdp/core/rdp.c @@ -2072,16 +2072,9 @@ rdpRdp* rdp_new(rdpContext* context) rdp->settings = context->settings; /* Keep a backup copy of settings for later comparisons */ - freerdp_settings_free(rdp->originalSettings); - rdp->originalSettings = freerdp_settings_clone(rdp->settings); - if (!rdp->originalSettings) + if (!rdp_set_backup_settings(rdp)) return FALSE; - freerdp_settings_free(rdp->remoteSettings); - rdp->remoteSettings = freerdp_settings_new(remoteFlags); - if (!rdp->remoteSettings) - return false; - rdp->settings->instance = context->instance; context->settings = rdp->settings; @@ -2487,3 +2480,37 @@ const char* rdp_security_flag_string(UINT32 securityFlags, char* buffer, size_t return buffer; } + +static BOOL rdp_reset_remote_settings(rdpRdp* rdp) +{ + UINT32 flags = 0; + WINPR_ASSERT(rdp); + freerdp_settings_free(rdp->remoteSettings); + + if (!freerdp_settings_get_bool(rdp->settings, FreeRDP_ServerMode)) + flags |= FREERDP_SETTINGS_SERVER_MODE; + rdp->remoteSettings = freerdp_settings_new(flags); + return rdp->remoteSettings != NULL; +} + +BOOL rdp_set_backup_settings(rdpRdp* rdp) +{ + WINPR_ASSERT(rdp); + freerdp_settings_free(rdp->originalSettings); + rdp->originalSettings = freerdp_settings_clone(rdp->settings); + if (!rdp->originalSettings) + return FALSE; + return rdp_reset_remote_settings(rdp); +} + +BOOL rdp_reset_runtime_settings(rdpRdp* rdp) +{ + WINPR_ASSERT(rdp); + + freerdp_settings_free(rdp->settings); + rdp->context->settings = rdp->settings = freerdp_settings_clone(rdp->originalSettings); + + if (!rdp->settings) + return FALSE; + return rdp_reset_remote_settings(rdp); +} diff --git a/libfreerdp/core/rdp.h b/libfreerdp/core/rdp.h index e4d412e5c..2b550ddde 100644 --- a/libfreerdp/core/rdp.h +++ b/libfreerdp/core/rdp.h @@ -286,4 +286,7 @@ BOOL rdp_reset_rc4_decrypt_keys(rdpRdp* rdp); const char* rdp_security_flag_string(UINT32 securityFlags, char* buffer, size_t size); +BOOL rdp_set_backup_settings(rdpRdp* rdp); +BOOL rdp_reset_runtime_settings(rdpRdp* rdp); + #endif /* FREERDP_LIB_CORE_RDP_H */ diff --git a/libfreerdp/core/redirection.c b/libfreerdp/core/redirection.c index 525b010b4..ffeb573fd 100644 --- a/libfreerdp/core/redirection.c +++ b/libfreerdp/core/redirection.c @@ -208,18 +208,12 @@ int rdp_redirection_apply_settings(rdpRdp* rdp) rdpSettings* settings; rdpRedirection* redirection; - WINPR_ASSERT(rdp); - - freerdp_settings_free(rdp->settings); - rdp->context->settings = rdp->settings = freerdp_settings_clone(rdp->originalSettings); + if (!rdp_reset_runtime_settings(rdp)) + return -1; settings = rdp->settings; WINPR_ASSERT(settings); - freerdp_settings_free(rdp->remoteSettings); - rdp->remoteSettings = freerdp_settings_new(0); - WINPR_ASSERT(rdp->remoteSettings); - redirection = rdp->redirection; WINPR_ASSERT(redirection);