server/proxy: Refactor pdata_set_connection_info
authorkubistika <kmizrachi18@gmail.com>
Tue, 11 Jun 2019 15:51:21 +0000 (18:51 +0300)
committerakallabeth <akallabeth@users.noreply.github.com>
Wed, 26 Jun 2019 12:25:07 +0000 (14:25 +0200)
Connection info must be set after the proxy's client connection
established, because if the client didn't provide credentials in .rdp
file, we don't know its username yet.

server/proxy/pf_client.c
server/proxy/pf_context.c
server/proxy/pf_context.h
server/proxy/pf_server.c

index 348843c..8491eb2 100644 (file)
@@ -142,13 +142,20 @@ static BOOL pf_client_post_connect(freerdp* instance)
        pClientContext* pc;
        rdpContext* ps;
 
-       if (!gdi_init(instance, PIXEL_FORMAT_XRGB32))
-               return FALSE;
-
        context = instance->context;
        settings = instance->settings;
        update = instance->update;
        pc = (pClientContext*) context;
+       ps = (rdpContext*) pc->pdata->ps;
+
+       if (!proxy_data_set_connection_info(pc->pdata, ps->settings, settings))
+       {
+               WLog_ERR(TAG, "proxy_data_set_connection_info failed!");
+               return FALSE;
+       }
+
+       if (!gdi_init(instance, PIXEL_FORMAT_XRGB32))
+               return FALSE;
 
        if (!pf_register_pointer(context->graphics))
                return FALSE;
@@ -170,7 +177,6 @@ static BOOL pf_client_post_connect(freerdp* instance)
        }
        
        pf_client_register_update_callbacks(update);
-       ps = (rdpContext*) pc->pdata->ps;
        proxy_server_reactivate(ps, context);
        return TRUE;
 }
index 05ee2d2..4817d17 100644 (file)
@@ -159,16 +159,16 @@ proxyData* proxy_data_new()
        return pdata;
 }
 
-BOOL proxy_data_set_connection_info(proxyData* pdata, rdpSettings* clientSettings,
-                                    const char* target)
+/* sets connection info values using the settings of both server & client */
+BOOL proxy_data_set_connection_info(proxyData* pdata, rdpSettings* ps, rdpSettings* pc)
 {
-       if (!(pdata->info->TargetHostname = _strdup(target)))
+       if (!(pdata->info->TargetHostname = _strdup(pc->ServerHostname)))
                goto out_fail;
 
-       if (!(pdata->info->ClientHostname = _strdup(clientSettings->ClientHostname)))
+       if (!(pdata->info->Username = _strdup(pc->Username)))
                goto out_fail;
 
-       if (!(pdata->info->Username = _strdup(clientSettings->Username)))
+       if (!(pdata->info->ClientHostname = _strdup(ps->ClientHostname)))
                goto out_fail;
 
        return TRUE;
index d4c0ea5..2cd7fe6 100644 (file)
@@ -90,8 +90,7 @@ struct proxy_data
 BOOL init_p_server_context(freerdp_peer* client);
 rdpContext* p_client_context_create(rdpSettings* clientSettings);
 proxyData* proxy_data_new();
-BOOL proxy_data_set_connection_info(proxyData* pdata, rdpSettings* clientSettings,
-                                    const char* target);
+BOOL proxy_data_set_connection_info(proxyData* pdata, rdpSettings* ps, rdpSettings* pc);
 void proxy_data_free(proxyData* pdata);
 
 #endif /* FREERDP_SERVER_PROXY_PFCONTEXT_H */
index 8cb9f3b..98e2ba1 100644 (file)
@@ -176,12 +176,6 @@ static BOOL pf_server_post_connect(freerdp_peer* client)
                return FALSE;
        }
 
-       if (!proxy_data_set_connection_info(pdata, client->settings, pc->settings->ServerHostname))
-       {
-               WLog_ERR(TAG, "proxy_data_set_connection_info failed!");
-               return FALSE;
-       }
-
        pf_server_rdpgfx_init(ps);
        pf_server_disp_init(ps);