2019-05-17 15:32:54 +03:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* FreeRDP Proxy Server
|
|
|
|
*
|
|
|
|
* Copyright 2019 Mati Shabtay <matishabtay@gmail.com>
|
|
|
|
* Copyright 2019 Kobi Mizrachi <kmizrachi18@gmail.com>
|
|
|
|
* Copyright 2019 Idan Freiberg <speidy@gmail.com>
|
|
|
|
*
|
|
|
|
* 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_client.h"
|
|
|
|
#include "pf_context.h"
|
|
|
|
#include "pf_common.h"
|
|
|
|
|
|
|
|
/* Proxy context initialization callback */
|
|
|
|
static BOOL client_to_proxy_context_new(freerdp_peer* client,
|
|
|
|
pServerContext* context)
|
|
|
|
{
|
|
|
|
context->vcm = WTSOpenServerA((LPSTR) client->context);
|
|
|
|
|
|
|
|
if (!context->vcm || context->vcm == INVALID_HANDLE_VALUE)
|
|
|
|
goto fail_open_server;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
fail_open_server:
|
|
|
|
context->vcm = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Proxy context free callback */
|
|
|
|
static void client_to_proxy_context_free(freerdp_peer* client,
|
|
|
|
pServerContext* context)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(client);
|
|
|
|
|
|
|
|
if (context)
|
|
|
|
WTSCloseServer((HANDLE) context->vcm);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL init_p_server_context(freerdp_peer* client)
|
|
|
|
{
|
|
|
|
client->ContextSize = sizeof(pServerContext);
|
|
|
|
client->ContextNew = (psPeerContextNew) client_to_proxy_context_new;
|
|
|
|
client->ContextFree = (psPeerContextFree) client_to_proxy_context_free;
|
|
|
|
return freerdp_peer_context_new(client);
|
|
|
|
}
|
|
|
|
|
2019-05-26 15:33:28 +03:00
|
|
|
rdpContext* p_client_context_create(rdpSettings* clientSettings)
|
2019-05-17 15:32:54 +03:00
|
|
|
{
|
|
|
|
RDP_CLIENT_ENTRY_POINTS clientEntryPoints;
|
|
|
|
rdpContext* context;
|
|
|
|
rdpSettings* settings;
|
|
|
|
RdpClientEntry(&clientEntryPoints);
|
|
|
|
context = freerdp_client_context_new(&clientEntryPoints);
|
|
|
|
|
|
|
|
if (!context)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
settings = context->settings;
|
|
|
|
pf_common_copy_settings(settings, clientSettings);
|
|
|
|
settings->Username = _strdup(clientSettings->Username);
|
|
|
|
settings->Password = _strdup(clientSettings->Password);
|
|
|
|
settings->Domain = _strdup(clientSettings->Domain);
|
|
|
|
settings->SoftwareGdi = FALSE;
|
|
|
|
settings->RedirectClipboard = FALSE;
|
2019-05-20 14:09:12 +03:00
|
|
|
/* Client Monitor Data */
|
|
|
|
settings->MonitorCount = clientSettings->MonitorCount;
|
|
|
|
settings->SpanMonitors = clientSettings->SpanMonitors;
|
|
|
|
settings->UseMultimon = clientSettings->UseMultimon;
|
|
|
|
settings->ForceMultimon = clientSettings->ForceMultimon;
|
|
|
|
settings->DesktopPosX = clientSettings->DesktopPosX;
|
|
|
|
settings->DesktopPosY = clientSettings->DesktopPosY;
|
|
|
|
settings->ListMonitors = clientSettings->ListMonitors;
|
|
|
|
settings->NumMonitorIds = clientSettings->NumMonitorIds;
|
|
|
|
settings->MonitorLocalShiftX = clientSettings->MonitorLocalShiftX;
|
|
|
|
settings->MonitorLocalShiftY = clientSettings->MonitorLocalShiftY;
|
|
|
|
settings->HasMonitorAttributes = clientSettings->HasMonitorAttributes;
|
|
|
|
settings->MonitorCount = clientSettings->MonitorCount;
|
|
|
|
settings->MonitorDefArraySize = clientSettings->MonitorDefArraySize;
|
|
|
|
|
|
|
|
if (clientSettings->MonitorDefArraySize > 0)
|
|
|
|
{
|
|
|
|
settings->MonitorDefArray = (rdpMonitor*) calloc(clientSettings->MonitorDefArraySize,
|
|
|
|
sizeof(rdpMonitor));
|
|
|
|
|
|
|
|
if (!settings->MonitorDefArray)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyMemory(settings->MonitorDefArray, clientSettings->MonitorDefArray,
|
|
|
|
sizeof(rdpMonitor) * clientSettings->MonitorDefArraySize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
settings->MonitorDefArray = NULL;
|
|
|
|
|
|
|
|
settings->MonitorIds = (UINT32*) calloc(16, sizeof(UINT32));
|
|
|
|
|
|
|
|
if (!settings->MonitorIds)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
CopyMemory(settings->MonitorIds, clientSettings->MonitorIds, 16 * sizeof(UINT32));
|
2019-05-17 15:32:54 +03:00
|
|
|
return context;
|
2019-05-20 14:09:12 +03:00
|
|
|
error:
|
|
|
|
freerdp_client_context_free(context);
|
|
|
|
return NULL;
|
2019-05-17 15:32:54 +03:00
|
|
|
}
|
2019-05-12 20:48:51 +03:00
|
|
|
|
2019-05-26 15:33:28 +03:00
|
|
|
static void connection_info_free(connectionInfo* info)
|
2019-05-12 20:48:51 +03:00
|
|
|
{
|
|
|
|
free(info->TargetHostname);
|
|
|
|
free(info->ClientHostname);
|
|
|
|
free(info->Username);
|
|
|
|
free(info);
|
|
|
|
}
|
|
|
|
|
2019-05-26 15:33:28 +03:00
|
|
|
proxyData* proxy_data_new()
|
2019-05-12 20:48:51 +03:00
|
|
|
{
|
2019-05-13 11:11:24 +03:00
|
|
|
proxyData* pdata = calloc(1, sizeof(proxyData));
|
2019-05-12 20:48:51 +03:00
|
|
|
|
|
|
|
if (pdata == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-05-13 11:11:24 +03:00
|
|
|
pdata->info = calloc(1, sizeof(connectionInfo));
|
2019-05-12 20:48:51 +03:00
|
|
|
|
|
|
|
if (pdata->info == NULL)
|
|
|
|
{
|
|
|
|
free(pdata);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-05-26 15:33:28 +03:00
|
|
|
if (!(pdata->connectionClosed = CreateEvent(NULL, TRUE, FALSE, NULL)))
|
|
|
|
{
|
|
|
|
proxy_data_free(pdata);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-05-12 20:48:51 +03:00
|
|
|
return pdata;
|
|
|
|
}
|
|
|
|
|
2019-05-26 15:33:28 +03:00
|
|
|
BOOL proxy_data_set_connection_info(proxyData* pdata, rdpSettings* clientSettings,
|
|
|
|
const char* target)
|
|
|
|
{
|
|
|
|
if (!(pdata->info->TargetHostname = _strdup(target)))
|
|
|
|
goto out_fail;
|
|
|
|
|
|
|
|
if (!(pdata->info->ClientHostname = _strdup(clientSettings->ClientHostname)))
|
|
|
|
goto out_fail;
|
|
|
|
|
|
|
|
if (!(pdata->info->Username = _strdup(clientSettings->Username)))
|
|
|
|
goto out_fail;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
out_fail:
|
|
|
|
proxy_data_free(pdata);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void proxy_data_free(proxyData* pdata)
|
2019-05-12 20:48:51 +03:00
|
|
|
{
|
2019-05-26 15:33:28 +03:00
|
|
|
connection_info_free(pdata->info);
|
2019-05-12 20:48:51 +03:00
|
|
|
free(pdata);
|
|
|
|
}
|