From f5d32f46178070a4704af79daf1b38d22968dfb5 Mon Sep 17 00:00:00 2001 From: kubistika Date: Sun, 8 Sep 2019 15:18:45 +0300 Subject: [PATCH] server: proxy: refactor usage of pf_context_copy_settings --- server/proxy/pf_client.c | 13 ++++++++----- server/proxy/pf_context.c | 15 ++++----------- server/proxy/pf_context.h | 4 ++-- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/server/proxy/pf_client.c b/server/proxy/pf_client.c index 4cdf701ff..05be67142 100644 --- a/server/proxy/pf_client.c +++ b/server/proxy/pf_client.c @@ -57,14 +57,18 @@ * Re-negotiate with original client after negotiation between the proxy * and the target has finished. */ -static void proxy_server_reactivate(rdpContext* ps, const rdpContext* target) +static BOOL proxy_server_reactivate(rdpContext* ps, const rdpContext* pc) { - pf_context_copy_settings(ps->settings, target->settings, TRUE); + if (!pf_context_copy_settings(ps->settings, pc->settings)) + return FALSE; /* DesktopResize causes internal function rdp_server_reactivate to be called, * which causes the reactivation. */ - ps->update->DesktopResize(ps); + if (!ps->update->DesktopResize(ps)) + return FALSE; + + return TRUE; } static void pf_OnErrorInfo(void* ctx, ErrorInfoEventArgs* e) @@ -220,8 +224,7 @@ static BOOL pf_client_post_connect(freerdp* instance) } pf_client_register_update_callbacks(update); - proxy_server_reactivate(ps, context); - return TRUE; + return proxy_server_reactivate(ps, context); } diff --git a/server/proxy/pf_context.c b/server/proxy/pf_context.c index 361b1f152..48e4c0911 100644 --- a/server/proxy/pf_context.c +++ b/server/proxy/pf_context.c @@ -75,7 +75,7 @@ BOOL init_p_server_context(freerdp_peer* client) * when using this function, is_dst_server must be set to TRUE if the destination * settings are server's settings. otherwise, they must be set to FALSE. */ -BOOL pf_context_copy_settings(rdpSettings* dst, const rdpSettings* src, BOOL is_dst_server) +BOOL pf_context_copy_settings(rdpSettings* dst, const rdpSettings* src) { rdpSettings* before_copy = freerdp_settings_clone(dst); if (!before_copy) @@ -97,7 +97,7 @@ BOOL pf_context_copy_settings(rdpSettings* dst, const rdpSettings* src, BOOL is_ free(dst->CertificateContent); /* adjust pointer to instance pointer */ - dst->ServerMode = is_dst_server; + dst->ServerMode = before_copy->ServerMode; /* revert some values that must not be changed */ dst->ConfigPath = _strdup(before_copy->ConfigPath); @@ -109,12 +109,7 @@ BOOL pf_context_copy_settings(rdpSettings* dst, const rdpSettings* src, BOOL is_ dst->CertificateName = _strdup(before_copy->CertificateName); dst->CertificateContent = _strdup(before_copy->CertificateContent); - if (is_dst_server) - { - free(dst->ServerCertificate); - dst->ServerCertificateLength = before_copy->ServerCertificateLength; - } - else + if (!dst->ServerMode) { /* adjust instance pointer for client's context */ dst->instance = before_copy->instance; @@ -137,9 +132,7 @@ rdpContext* p_client_context_create(rdpSettings* clientSettings) if (!context) return NULL; - pf_context_copy_settings(context->settings, clientSettings, FALSE); - - if (!context->settings) + if (!pf_context_copy_settings(context->settings, clientSettings)) goto error; return context; diff --git a/server/proxy/pf_context.h b/server/proxy/pf_context.h index 310689804..ffce87072 100644 --- a/server/proxy/pf_context.h +++ b/server/proxy/pf_context.h @@ -107,9 +107,9 @@ rdpContext* p_client_context_create(rdpSettings* clientSettings); proxyData* proxy_data_new(void); void proxy_data_free(proxyData* pdata); -BOOL pf_context_copy_settings(rdpSettings* dst, const rdpSettings* src, BOOL is_dst_server); -void proxy_data_abort_connect(proxyData* pdata); +BOOL pf_context_copy_settings(rdpSettings* dst, const rdpSettings* src); BOOL proxy_data_shall_disconnect(proxyData* pdata); +void proxy_data_abort_connect(proxyData* pdata); /* server */ BOOL init_p_server_context(freerdp_peer* client);