2013-03-19 04:12:51 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Windows Client
|
|
|
|
*
|
|
|
|
* Copyright 2009-2011 Jay Sorg
|
|
|
|
* Copyright 2010-2011 Vic Lee
|
|
|
|
* Copyright 2010-2011 Marc-Andre Moreau <marcandre.moreau@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
|
|
|
|
*
|
2013-10-07 21:46:13 +04:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-03-19 04:12:51 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2013-03-19 04:12:51 +04:00
|
|
|
|
|
|
|
#include <winpr/windows.h>
|
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
2022-01-19 11:27:39 +03:00
|
|
|
#include <winpr/assert.h>
|
2013-03-19 04:12:51 +04:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <tchar.h>
|
2021-06-09 15:03:34 +03:00
|
|
|
#include <winpr/assert.h>
|
2013-03-19 04:12:51 +04:00
|
|
|
#include <sys/types.h>
|
2021-10-11 23:00:52 +03:00
|
|
|
#include <io.h>
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2021-10-21 18:59:17 +03:00
|
|
|
#ifdef WITH_PROGRESS_BAR
|
2021-10-21 01:29:00 +03:00
|
|
|
#include <shobjidl.h>
|
2021-10-21 18:59:17 +03:00
|
|
|
#endif
|
2021-10-21 01:29:00 +03:00
|
|
|
|
2021-10-22 17:06:04 +03:00
|
|
|
#ifdef WITH_WINDOWS_CERT_STORE
|
|
|
|
#include <wincrypt.h>
|
|
|
|
#endif
|
|
|
|
|
2014-09-12 19:13:01 +04:00
|
|
|
#include <freerdp/log.h>
|
2013-03-19 04:12:51 +04:00
|
|
|
#include <freerdp/freerdp.h>
|
|
|
|
#include <freerdp/constants.h>
|
|
|
|
|
2021-03-08 14:48:22 +03:00
|
|
|
#include <freerdp/locale/keyboard.h>
|
2014-10-25 03:46:02 +04:00
|
|
|
#include <freerdp/codec/region.h>
|
2013-03-19 04:12:51 +04:00
|
|
|
#include <freerdp/client/cmdline.h>
|
|
|
|
#include <freerdp/client/channels.h>
|
|
|
|
#include <freerdp/channels/channels.h>
|
|
|
|
|
|
|
|
#include "wf_gdi.h"
|
2014-10-25 03:46:02 +04:00
|
|
|
#include "wf_rail.h"
|
2014-09-13 00:30:57 +04:00
|
|
|
#include "wf_channels.h"
|
2013-03-19 04:12:51 +04:00
|
|
|
#include "wf_graphics.h"
|
|
|
|
#include "wf_cliprdr.h"
|
|
|
|
|
2014-09-13 00:30:57 +04:00
|
|
|
#include "wf_client.h"
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2021-11-12 13:20:04 +03:00
|
|
|
#include "resource/resource.h"
|
2013-03-19 19:11:14 +04:00
|
|
|
|
2014-09-12 19:13:01 +04:00
|
|
|
#define TAG CLIENT_TAG("windows")
|
|
|
|
|
2021-10-11 23:00:52 +03:00
|
|
|
static BOOL wf_has_console(void)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2021-11-23 22:21:27 +03:00
|
|
|
#ifdef WITH_WIN_CONSOLE
|
|
|
|
int file = _fileno(stdin);
|
|
|
|
int tty = _isatty(file);
|
|
|
|
#else
|
|
|
|
int file = -1;
|
|
|
|
int tty = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
WLog_INFO(TAG, "Detected stdin=%d -> %s mode", file, tty ? "console" : "gui");
|
|
|
|
return tty;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2016-08-10 15:45:55 +03:00
|
|
|
static BOOL wf_end_paint(rdpContext* context)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
rdpGdi* gdi;
|
|
|
|
int ninvalid;
|
2014-10-25 03:46:02 +04:00
|
|
|
RECT updateRect;
|
2013-03-19 04:12:51 +04:00
|
|
|
HGDI_RGN cinvalid;
|
2014-10-25 03:46:02 +04:00
|
|
|
REGION16 invalidRegion;
|
|
|
|
RECTANGLE_16 invalidRect;
|
2016-08-03 13:09:24 +03:00
|
|
|
const RECTANGLE_16* extents;
|
|
|
|
wfContext* wfc = (wfContext*)context;
|
2014-10-25 03:46:02 +04:00
|
|
|
gdi = context->gdi;
|
2013-03-19 04:12:51 +04:00
|
|
|
ninvalid = gdi->primary->hdc->hwnd->ninvalid;
|
|
|
|
cinvalid = gdi->primary->hdc->hwnd->cinvalid;
|
|
|
|
|
2014-10-25 03:46:02 +04:00
|
|
|
if (ninvalid < 1)
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2014-10-25 03:46:02 +04:00
|
|
|
|
|
|
|
region16_init(&invalidRegion);
|
|
|
|
|
2013-03-19 04:12:51 +04:00
|
|
|
for (i = 0; i < ninvalid; i++)
|
|
|
|
{
|
2014-10-25 03:46:02 +04:00
|
|
|
invalidRect.left = cinvalid[i].x;
|
|
|
|
invalidRect.top = cinvalid[i].y;
|
|
|
|
invalidRect.right = cinvalid[i].x + cinvalid[i].w;
|
|
|
|
invalidRect.bottom = cinvalid[i].y + cinvalid[i].h;
|
|
|
|
region16_union_rect(&invalidRegion, &invalidRegion, &invalidRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!region16_is_empty(&invalidRegion))
|
|
|
|
{
|
|
|
|
extents = region16_extents(&invalidRegion);
|
|
|
|
updateRect.left = extents->left;
|
|
|
|
updateRect.top = extents->top;
|
|
|
|
updateRect.right = extents->right;
|
|
|
|
updateRect.bottom = extents->bottom;
|
2022-01-10 14:22:18 +03:00
|
|
|
|
|
|
|
if (wfc->xScrollVisible)
|
|
|
|
{
|
|
|
|
updateRect.left -= MIN(updateRect.left, wfc->xCurrentScroll);
|
|
|
|
updateRect.right -= MIN(updateRect.right, wfc->xCurrentScroll);
|
|
|
|
}
|
|
|
|
if (wfc->yScrollVisible)
|
|
|
|
{
|
|
|
|
updateRect.top -= MIN(updateRect.top, wfc->yCurrentScroll);
|
|
|
|
updateRect.bottom -= MIN(updateRect.bottom, wfc->yCurrentScroll);
|
|
|
|
}
|
|
|
|
|
2014-10-25 03:46:02 +04:00
|
|
|
InvalidateRect(wfc->hwnd, &updateRect, FALSE);
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2014-10-25 03:46:02 +04:00
|
|
|
if (wfc->rail)
|
|
|
|
wf_rail_invalidate_region(wfc, &invalidRegion);
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
2014-10-25 03:46:02 +04:00
|
|
|
|
|
|
|
region16_uninit(&invalidRegion);
|
2021-10-21 01:29:00 +03:00
|
|
|
|
|
|
|
if (!wfc->is_shown)
|
|
|
|
{
|
2021-10-21 18:59:17 +03:00
|
|
|
wfc->is_shown = TRUE;
|
2021-10-21 01:29:00 +03:00
|
|
|
|
|
|
|
#ifdef WITH_PROGRESS_BAR
|
2021-10-21 18:59:17 +03:00
|
|
|
if (wfc->taskBarList)
|
2021-10-21 01:29:00 +03:00
|
|
|
{
|
2021-10-21 18:59:17 +03:00
|
|
|
wfc->taskBarList->lpVtbl->SetProgressState(wfc->taskBarList, wfc->hwnd,
|
|
|
|
TBPF_NOPROGRESS);
|
2021-10-21 01:29:00 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ShowWindow(wfc->hwnd, SW_SHOWNORMAL);
|
|
|
|
WLog_INFO(TAG, "Window is shown!");
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2016-08-10 14:12:54 +03:00
|
|
|
static BOOL wf_begin_paint(rdpContext* context)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2016-08-03 13:09:24 +03:00
|
|
|
HGDI_DC hdc;
|
2016-07-21 16:36:15 +03:00
|
|
|
|
2017-10-27 15:30:00 +03:00
|
|
|
if (!context || !context->gdi || !context->gdi->primary || !context->gdi->primary->hdc)
|
2016-08-03 13:09:24 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2017-10-27 15:30:00 +03:00
|
|
|
hdc = context->gdi->primary->hdc;
|
2016-07-21 16:36:15 +03:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
if (!hdc || !hdc->hwnd || !hdc->hwnd->invalid)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-10-06 14:41:52 +03:00
|
|
|
hdc->hwnd->invalid->null = TRUE;
|
2016-08-03 13:09:24 +03:00
|
|
|
hdc->hwnd->ninvalid = 0;
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2016-08-10 14:33:34 +03:00
|
|
|
static BOOL wf_desktop_resize(rdpContext* context)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
|
|
|
BOOL same;
|
|
|
|
RECT rect;
|
|
|
|
rdpSettings* settings;
|
2016-08-03 13:09:24 +03:00
|
|
|
wfContext* wfc = (wfContext*)context;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
if (!context || !context->settings)
|
|
|
|
return FALSE;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
settings = context->settings;
|
2013-03-19 05:54:50 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->primary)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
same = (wfc->primary == wfc->drawing) ? TRUE : FALSE;
|
|
|
|
wf_image_free(wfc->primary);
|
2019-11-06 17:24:51 +03:00
|
|
|
wfc->primary = wf_image_new(wfc, settings->DesktopWidth, settings->DesktopHeight,
|
|
|
|
context->gdi->dstFormat, NULL);
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
2013-03-19 19:11:14 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!gdi_resize_ex(context->gdi, settings->DesktopWidth, settings->DesktopHeight, 0,
|
2016-08-10 14:33:34 +03:00
|
|
|
context->gdi->dstFormat, wfc->primary->pdata, NULL))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (same)
|
|
|
|
wfc->drawing = wfc->primary;
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->fullscreen != TRUE)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->hwnd)
|
2016-08-03 13:09:24 +03:00
|
|
|
SetWindowPos(wfc->hwnd, HWND_TOP, -1, -1, settings->DesktopWidth + wfc->diff.x,
|
2016-08-09 13:04:06 +03:00
|
|
|
settings->DesktopHeight + wfc->diff.y, SWP_NOMOVE);
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_update_offset(wfc);
|
|
|
|
GetWindowRect(wfc->hwnd, &rect);
|
|
|
|
InvalidateRect(wfc->hwnd, &rect, TRUE);
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
2016-08-03 13:09:24 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
static BOOL wf_pre_connect(freerdp* instance)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2020-12-15 11:59:52 +03:00
|
|
|
UINT32 rc;
|
2013-06-16 06:57:21 +04:00
|
|
|
wfContext* wfc;
|
2021-03-08 14:48:22 +03:00
|
|
|
UINT32 desktopWidth;
|
|
|
|
UINT32 desktopHeight;
|
2013-06-16 06:57:21 +04:00
|
|
|
rdpContext* context;
|
2013-03-19 04:12:51 +04:00
|
|
|
rdpSettings* settings;
|
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
WINPR_ASSERT(instance);
|
|
|
|
WINPR_ASSERT(instance->context);
|
|
|
|
WINPR_ASSERT(instance->context->settings);
|
2016-07-21 16:36:15 +03:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
context = instance->context;
|
2019-11-06 17:24:51 +03:00
|
|
|
wfc = (wfContext*)instance->context;
|
2022-03-23 15:18:35 +03:00
|
|
|
settings = context->settings;
|
2013-03-19 04:12:51 +04:00
|
|
|
settings->OsMajorType = OSMAJORTYPE_WINDOWS;
|
|
|
|
settings->OsMinorType = OSMINORTYPE_WINDOWS_NT;
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->fullscreen = settings->Fullscreen;
|
2016-06-22 21:58:39 +03:00
|
|
|
wfc->fullscreen_toggle = settings->ToggleFullscreen;
|
2013-04-25 00:33:43 +04:00
|
|
|
desktopWidth = settings->DesktopWidth;
|
|
|
|
desktopHeight = settings->DesktopHeight;
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->percentscreen > 0)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
desktopWidth = (GetSystemMetrics(SM_CXSCREEN) * wfc->percentscreen) / 100;
|
2013-04-25 18:50:26 +04:00
|
|
|
settings->DesktopWidth = desktopWidth;
|
2013-06-16 06:57:21 +04:00
|
|
|
desktopHeight = (GetSystemMetrics(SM_CYSCREEN) * wfc->percentscreen) / 100;
|
2013-04-25 18:50:26 +04:00
|
|
|
settings->DesktopHeight = desktopHeight;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
2014-03-04 11:35:21 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->fullscreen)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2013-04-25 18:50:26 +04:00
|
|
|
if (settings->UseMultimon)
|
|
|
|
{
|
2014-02-26 07:34:48 +04:00
|
|
|
desktopWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
|
|
|
|
desktopHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);
|
2013-04-25 18:50:26 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-26 07:34:48 +04:00
|
|
|
desktopWidth = GetSystemMetrics(SM_CXSCREEN);
|
|
|
|
desktopHeight = GetSystemMetrics(SM_CYSCREEN);
|
2013-04-25 18:50:26 +04:00
|
|
|
}
|
2013-04-25 00:33:43 +04:00
|
|
|
}
|
|
|
|
|
2014-03-04 11:35:21 +04:00
|
|
|
/* FIXME: desktopWidth has a limitation that it should be divisible by 4,
|
|
|
|
* otherwise the screen will crash when connecting to an XP desktop.*/
|
|
|
|
desktopWidth = (desktopWidth + 3) & (~3);
|
|
|
|
|
2013-04-25 00:33:43 +04:00
|
|
|
if (desktopWidth != settings->DesktopWidth)
|
|
|
|
{
|
2021-03-08 14:48:22 +03:00
|
|
|
freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, desktopWidth);
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2013-04-25 00:33:43 +04:00
|
|
|
if (desktopHeight != settings->DesktopHeight)
|
|
|
|
{
|
2021-03-08 14:48:22 +03:00
|
|
|
freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, desktopHeight);
|
2013-04-25 00:33:43 +04:00
|
|
|
}
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2020-12-15 11:59:52 +03:00
|
|
|
rc = freerdp_keyboard_init(freerdp_settings_get_uint32(settings, FreeRDP_KeyboardLayout));
|
2021-03-08 14:48:22 +03:00
|
|
|
freerdp_settings_set_uint32(settings, FreeRDP_KeyboardLayout, rc);
|
2019-11-06 17:24:51 +03:00
|
|
|
PubSub_SubscribeChannelConnected(instance->context->pubSub, wf_OnChannelConnectedEventHandler);
|
2014-09-13 00:30:57 +04:00
|
|
|
PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
|
2018-02-14 12:14:33 +03:00
|
|
|
wf_OnChannelDisconnectedEventHandler);
|
2013-03-19 04:12:51 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
static void wf_add_system_menu(wfContext* wfc)
|
2013-04-30 19:15:04 +04:00
|
|
|
{
|
2016-06-22 21:58:39 +03:00
|
|
|
HMENU hMenu;
|
2013-04-30 19:15:04 +04:00
|
|
|
MENUITEMINFO item_info;
|
2018-11-16 12:33:29 +03:00
|
|
|
|
2016-06-22 21:58:39 +03:00
|
|
|
if (wfc->fullscreen && !wfc->fullscreen_toggle)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-11-16 12:33:29 +03:00
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
if (wfc->common.context.settings->DynamicResolutionUpdate)
|
2021-06-02 14:46:00 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-22 21:58:39 +03:00
|
|
|
hMenu = GetSystemMenu(wfc->hwnd, FALSE);
|
2013-04-30 19:15:04 +04:00
|
|
|
ZeroMemory(&item_info, sizeof(MENUITEMINFO));
|
2019-11-06 17:24:51 +03:00
|
|
|
item_info.fMask = MIIM_CHECKMARKS | MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_DATA;
|
2013-04-30 19:15:04 +04:00
|
|
|
item_info.cbSize = sizeof(MENUITEMINFO);
|
|
|
|
item_info.wID = SYSCOMMAND_ID_SMARTSIZING;
|
|
|
|
item_info.fType = MFT_STRING;
|
|
|
|
item_info.dwTypeData = _wcsdup(_T("Smart sizing"));
|
2019-11-06 17:24:51 +03:00
|
|
|
item_info.cch = (UINT)_wcslen(_T("Smart sizing"));
|
|
|
|
item_info.dwItemData = (ULONG_PTR)wfc;
|
2013-04-30 19:15:04 +04:00
|
|
|
InsertMenuItem(hMenu, 6, TRUE, &item_info);
|
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
if (wfc->common.context.settings->SmartSizing)
|
2013-04-30 19:15:04 +04:00
|
|
|
{
|
|
|
|
CheckMenuItem(hMenu, SYSCOMMAND_ID_SMARTSIZING, MF_CHECKED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:54:09 +03:00
|
|
|
static WCHAR* wf_window_get_title(rdpSettings* settings)
|
|
|
|
{
|
|
|
|
BOOL port;
|
2018-12-10 16:31:38 +03:00
|
|
|
WCHAR* windowTitle = NULL;
|
2018-11-21 11:54:09 +03:00
|
|
|
size_t size;
|
2018-12-07 17:45:05 +03:00
|
|
|
char* name;
|
2018-11-21 11:54:09 +03:00
|
|
|
WCHAR prefix[] = L"FreeRDP:";
|
|
|
|
|
|
|
|
if (!settings)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
name = settings->ServerHostname;
|
|
|
|
|
|
|
|
if (settings->WindowTitle)
|
|
|
|
{
|
|
|
|
ConvertToUnicode(CP_UTF8, 0, settings->WindowTitle, -1, &windowTitle, 0);
|
|
|
|
return windowTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
port = (settings->ServerPort != 3389);
|
2020-07-06 10:16:55 +03:00
|
|
|
size = strlen(name) + 16 + wcslen(prefix);
|
2018-11-21 11:54:09 +03:00
|
|
|
windowTitle = calloc(size, sizeof(WCHAR));
|
|
|
|
|
|
|
|
if (!windowTitle)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!port)
|
2018-12-07 17:45:05 +03:00
|
|
|
_snwprintf_s(windowTitle, size, _TRUNCATE, L"%s %S", prefix, name);
|
2018-11-21 11:54:09 +03:00
|
|
|
else
|
2018-12-07 17:45:05 +03:00
|
|
|
_snwprintf_s(windowTitle, size, _TRUNCATE, L"%s %S:%u", prefix, name, settings->ServerPort);
|
2018-11-21 11:54:09 +03:00
|
|
|
|
|
|
|
return windowTitle;
|
|
|
|
}
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
static BOOL wf_post_connect(freerdp* instance)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
|
|
|
rdpGdi* gdi;
|
2013-04-02 02:32:14 +04:00
|
|
|
DWORD dwStyle;
|
2013-03-19 04:12:51 +04:00
|
|
|
rdpCache* cache;
|
2013-06-16 06:57:21 +04:00
|
|
|
wfContext* wfc;
|
|
|
|
rdpContext* context;
|
2013-03-19 04:12:51 +04:00
|
|
|
rdpSettings* settings;
|
2013-10-07 21:46:13 +04:00
|
|
|
EmbedWindowEventArgs e;
|
2016-08-03 13:37:40 +03:00
|
|
|
const UINT32 format = PIXEL_FORMAT_BGRX32;
|
2022-03-23 15:18:35 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(instance);
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
context = instance->context;
|
2022-03-23 15:18:35 +03:00
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
|
|
|
settings = context->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
wfc = (wfContext*)instance->context;
|
2022-03-23 15:18:35 +03:00
|
|
|
WINPR_ASSERT(wfc);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
wfc->primary = wf_image_new(wfc, settings->DesktopWidth, settings->DesktopHeight, format, NULL);
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2016-08-10 14:33:34 +03:00
|
|
|
if (!gdi_init_ex(instance, format, 0, wfc->primary->pdata, NULL))
|
2016-08-03 13:09:24 +03:00
|
|
|
return FALSE;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2022-04-07 19:15:26 +03:00
|
|
|
cache = instance->context->cache;
|
|
|
|
WINPR_ASSERT(cache);
|
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
gdi = instance->context->gdi;
|
2014-09-11 17:51:44 +04:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
if (!settings->SoftwareGdi)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2022-03-23 15:18:35 +03:00
|
|
|
wf_gdi_register_update_callbacks(context->update);
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2018-11-21 11:54:09 +03:00
|
|
|
wfc->window_title = wf_window_get_title(settings);
|
|
|
|
|
|
|
|
if (!wfc->window_title)
|
|
|
|
return FALSE;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2013-10-07 21:46:13 +04:00
|
|
|
if (settings->EmbeddedWindow)
|
|
|
|
settings->Decorations = FALSE;
|
2015-03-17 15:02:41 +03:00
|
|
|
|
2014-08-20 00:59:22 +04:00
|
|
|
if (wfc->fullscreen)
|
|
|
|
dwStyle = WS_POPUP;
|
|
|
|
else if (!settings->Decorations)
|
2013-04-02 02:32:14 +04:00
|
|
|
dwStyle = WS_CHILD | WS_BORDER;
|
|
|
|
else
|
2019-11-06 17:24:51 +03:00
|
|
|
dwStyle =
|
|
|
|
WS_CAPTION | WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX | WS_SIZEBOX | WS_MAXIMIZEBOX;
|
2013-04-02 02:32:14 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (!wfc->hwnd)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2021-03-08 14:48:22 +03:00
|
|
|
wfc->hwnd = CreateWindowEx(0, wfc->wndClassName, wfc->window_title, dwStyle, 0, 0, 0, 0,
|
|
|
|
wfc->hWndParent, NULL, wfc->hInstance, NULL);
|
2019-11-06 17:24:51 +03:00
|
|
|
SetWindowLongPtr(wfc->hwnd, GWLP_USERDATA, (LONG_PTR)wfc);
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_resize_window(wfc);
|
|
|
|
wf_add_system_menu(wfc);
|
2019-11-06 17:24:51 +03:00
|
|
|
BitBlt(wfc->primary->hdc, 0, 0, settings->DesktopWidth, settings->DesktopHeight, NULL, 0, 0,
|
|
|
|
BLACKNESS);
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->drawing = wfc->primary;
|
2013-10-07 21:46:13 +04:00
|
|
|
EventArgsInit(&e, "wfreerdp");
|
|
|
|
e.embed = FALSE;
|
2019-11-06 17:24:51 +03:00
|
|
|
e.handle = (void*)wfc->hwnd;
|
2015-03-17 15:02:41 +03:00
|
|
|
PubSub_OnEmbedWindow(context->pubSub, context, &e);
|
2021-10-21 01:29:00 +03:00
|
|
|
#ifdef WITH_PROGRESS_BAR
|
2021-10-21 18:59:17 +03:00
|
|
|
if (wfc->taskBarList)
|
2021-10-21 01:29:00 +03:00
|
|
|
{
|
|
|
|
ShowWindow(wfc->hwnd, SW_SHOWMINIMIZED);
|
2021-10-21 18:59:17 +03:00
|
|
|
wfc->taskBarList->lpVtbl->SetProgressState(wfc->taskBarList, wfc->hwnd, TBPF_INDETERMINATE);
|
2021-10-21 01:29:00 +03:00
|
|
|
}
|
|
|
|
#endif
|
2013-06-16 06:57:21 +04:00
|
|
|
UpdateWindow(wfc->hwnd);
|
2022-03-23 15:18:35 +03:00
|
|
|
context->update->BeginPaint = wf_begin_paint;
|
|
|
|
context->update->DesktopResize = wf_desktop_resize;
|
|
|
|
context->update->EndPaint = wf_end_paint;
|
2014-09-12 19:34:30 +04:00
|
|
|
wf_register_pointer(context->graphics);
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2014-09-12 19:34:30 +04:00
|
|
|
if (!settings->SoftwareGdi)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2016-08-03 13:09:24 +03:00
|
|
|
wf_register_graphics(context->graphics);
|
2022-03-23 15:18:35 +03:00
|
|
|
wf_gdi_register_update_callbacks(context->update);
|
|
|
|
brush_cache_register_callbacks(context->update);
|
|
|
|
glyph_cache_register_callbacks(context->update);
|
|
|
|
bitmap_cache_register_callbacks(context->update);
|
|
|
|
offscreen_cache_register_callbacks(context->update);
|
|
|
|
palette_cache_register_callbacks(context->update);
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2018-11-16 12:33:29 +03:00
|
|
|
wfc->floatbar = wf_floatbar_new(wfc, wfc->hInstance, settings->Floatbar);
|
2013-03-19 04:12:51 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-08-29 16:17:59 +03:00
|
|
|
static void wf_post_disconnect(freerdp* instance)
|
2016-08-10 14:33:34 +03:00
|
|
|
{
|
2018-11-21 11:54:09 +03:00
|
|
|
wfContext* wfc;
|
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
if (!instance || !instance->context)
|
2019-08-29 16:17:59 +03:00
|
|
|
return;
|
2018-11-21 11:54:09 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
wfc = (wfContext*)instance->context;
|
2018-11-21 11:54:09 +03:00
|
|
|
free(wfc->window_title);
|
2016-08-10 14:33:34 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static CREDUI_INFOA wfUiInfo = { sizeof(CREDUI_INFOA), NULL, "Enter your credentials",
|
|
|
|
"Remote Desktop Security", NULL };
|
|
|
|
|
|
|
|
static BOOL wf_authenticate_raw(freerdp* instance, const char* title, char** username,
|
|
|
|
char** password, char** domain)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2019-08-29 20:28:50 +03:00
|
|
|
wfContext* wfc;
|
2013-03-19 04:12:51 +04:00
|
|
|
BOOL fSave;
|
|
|
|
DWORD status;
|
|
|
|
DWORD dwFlags;
|
2019-08-29 20:28:50 +03:00
|
|
|
char UserName[CREDUI_MAX_USERNAME_LENGTH + 1] = { 0 };
|
|
|
|
char Password[CREDUI_MAX_PASSWORD_LENGTH + 1] = { 0 };
|
|
|
|
char User[CREDUI_MAX_USERNAME_LENGTH + 1] = { 0 };
|
|
|
|
char Domain[CREDUI_MAX_DOMAIN_TARGET_LENGTH + 1] = { 0 };
|
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
WINPR_ASSERT(instance);
|
|
|
|
WINPR_ASSERT(instance->context);
|
|
|
|
WINPR_ASSERT(instance->context->settings);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
wfc = (wfContext*)instance->context;
|
2019-08-29 20:28:50 +03:00
|
|
|
|
2013-03-19 04:12:51 +04:00
|
|
|
fSave = FALSE;
|
|
|
|
dwFlags = CREDUI_FLAGS_DO_NOT_PERSIST | CREDUI_FLAGS_EXCLUDE_CERTIFICATES;
|
2019-08-29 20:28:50 +03:00
|
|
|
|
2020-05-15 03:50:20 +03:00
|
|
|
if (username && *username)
|
2021-10-11 23:00:52 +03:00
|
|
|
{
|
2020-05-15 03:50:20 +03:00
|
|
|
strncpy(UserName, *username, CREDUI_MAX_USERNAME_LENGTH);
|
2021-10-11 23:00:52 +03:00
|
|
|
strncpy(User, UserName, CREDUI_MAX_USERNAME_LENGTH);
|
|
|
|
}
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2021-10-11 23:00:52 +03:00
|
|
|
if (password && *password)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2021-10-11 23:00:52 +03:00
|
|
|
strncpy(Password, *password, CREDUI_MAX_PASSWORD_LENGTH);
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2021-10-11 23:00:52 +03:00
|
|
|
if (domain && *domain)
|
|
|
|
{
|
|
|
|
strncpy(Domain, *domain, CREDUI_MAX_DOMAIN_TARGET_LENGTH);
|
|
|
|
}
|
|
|
|
|
2022-06-23 08:57:38 +03:00
|
|
|
if (!(*UserName && *Password))
|
2021-10-11 23:00:52 +03:00
|
|
|
{
|
2022-01-19 11:27:39 +03:00
|
|
|
if (!wfc->isConsole && wfc->common.context.settings->CredentialsFromStdin)
|
2021-10-11 23:00:52 +03:00
|
|
|
WLog_ERR(TAG, "Flag for stdin read present but stdin is redirected; using GUI");
|
2022-01-19 11:27:39 +03:00
|
|
|
if (wfc->isConsole && wfc->common.context.settings->CredentialsFromStdin)
|
2021-10-11 23:00:52 +03:00
|
|
|
status = CredUICmdLinePromptForCredentialsA(
|
|
|
|
title, NULL, 0, UserName, CREDUI_MAX_USERNAME_LENGTH + 1, Password,
|
|
|
|
CREDUI_MAX_PASSWORD_LENGTH + 1, &fSave, dwFlags);
|
|
|
|
else
|
|
|
|
status = CredUIPromptForCredentialsA(&wfUiInfo, title, NULL, 0, UserName,
|
|
|
|
CREDUI_MAX_USERNAME_LENGTH + 1, Password,
|
|
|
|
CREDUI_MAX_PASSWORD_LENGTH + 1, &fSave, dwFlags);
|
|
|
|
|
|
|
|
if (status != NO_ERROR)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "CredUIPromptForCredentials unexpected status: 0x%08lX", status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = CredUIParseUserNameA(UserName, User, CREDUI_MAX_USERNAME_LENGTH, Domain,
|
|
|
|
CREDUI_MAX_DOMAIN_TARGET_LENGTH);
|
|
|
|
if (status != NO_ERROR)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse UserName: %s into User: %s Domain: %s", UserName, User,
|
|
|
|
Domain);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2013-03-19 04:12:51 +04:00
|
|
|
*username = _strdup(User);
|
2016-08-03 13:09:24 +03:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!(*username))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "strdup failed", status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-03-19 04:12:51 +04:00
|
|
|
|
|
|
|
if (strlen(Domain) > 0)
|
|
|
|
*domain = _strdup(Domain);
|
2015-06-18 14:01:28 +03:00
|
|
|
else
|
|
|
|
*domain = _strdup("\0");
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!(*domain))
|
|
|
|
{
|
|
|
|
free(*username);
|
|
|
|
WLog_ERR(TAG, "strdup failed", status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-03-19 04:12:51 +04:00
|
|
|
*password = _strdup(Password);
|
2016-08-03 13:09:24 +03:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!(*password))
|
|
|
|
{
|
|
|
|
free(*username);
|
|
|
|
free(*domain);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-03-19 04:12:51 +04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL wf_authenticate(freerdp* instance, char** username, char** password, char** domain)
|
2015-06-23 15:59:54 +03:00
|
|
|
{
|
2022-03-23 15:18:35 +03:00
|
|
|
rdpSettings* settings;
|
|
|
|
|
|
|
|
WINPR_ASSERT(instance);
|
|
|
|
WINPR_ASSERT(instance->context);
|
|
|
|
|
|
|
|
settings = instance->context->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
|
|
|
return wf_authenticate_raw(instance, settings->ServerHostname, username, password, domain);
|
2015-06-23 15:59:54 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL wf_gw_authenticate(freerdp* instance, char** username, char** password, char** domain)
|
2015-06-23 15:59:54 +03:00
|
|
|
{
|
|
|
|
char tmp[MAX_PATH];
|
2022-03-23 15:18:35 +03:00
|
|
|
rdpSettings* settings;
|
|
|
|
|
|
|
|
WINPR_ASSERT(instance);
|
|
|
|
WINPR_ASSERT(instance->context);
|
|
|
|
|
|
|
|
settings = instance->context->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
|
|
|
sprintf_s(tmp, sizeof(tmp), "Gateway %s", settings->GatewayHostname);
|
2015-06-23 15:59:54 +03:00
|
|
|
return wf_authenticate_raw(instance, tmp, username, password, domain);
|
|
|
|
}
|
|
|
|
|
2019-08-29 16:17:59 +03:00
|
|
|
static WCHAR* wf_format_text(const WCHAR* fmt, ...)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2019-08-29 16:17:59 +03:00
|
|
|
int rc;
|
2022-02-28 13:32:08 +03:00
|
|
|
size_t size = 0;
|
|
|
|
WCHAR* buffer = NULL;
|
2019-08-29 16:17:59 +03:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
WCHAR* tmp;
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
2022-02-28 13:32:08 +03:00
|
|
|
rc = _vsnwprintf(buffer, size, fmt, ap);
|
2019-08-29 16:17:59 +03:00
|
|
|
va_end(ap);
|
|
|
|
if (rc <= 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if ((size_t)rc < size)
|
|
|
|
return buffer;
|
|
|
|
|
|
|
|
size = (size_t)rc + 1;
|
|
|
|
tmp = realloc(buffer, size * sizeof(WCHAR));
|
|
|
|
if (!tmp)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
buffer = tmp;
|
2019-11-06 17:24:51 +03:00
|
|
|
} while (TRUE);
|
2019-08-29 16:17:59 +03:00
|
|
|
|
|
|
|
fail:
|
|
|
|
free(buffer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-22 17:06:04 +03:00
|
|
|
#ifdef WITH_WINDOWS_CERT_STORE
|
|
|
|
/* https://stackoverflow.com/questions/1231178/load-an-pem-encoded-x-509-certificate-into-windows-cryptoapi/3803333#3803333
|
|
|
|
*/
|
|
|
|
/* https://github.com/microsoft/Windows-classic-samples/blob/main/Samples/Win7Samples/security/cryptoapi/peertrust/cpp/peertrust.cpp
|
|
|
|
*/
|
|
|
|
/* https://stackoverflow.com/questions/7340504/whats-the-correct-way-to-verify-an-ssl-certificate-in-win32
|
|
|
|
*/
|
|
|
|
|
2021-10-22 16:41:49 +03:00
|
|
|
static void wf_report_error(char* wszMessage, DWORD dwErrCode)
|
2021-10-22 17:06:04 +03:00
|
|
|
{
|
|
|
|
LPSTR pwszMsgBuf = NULL;
|
|
|
|
|
|
|
|
if (NULL != wszMessage && 0 != *wszMessage)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "%s", wszMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
NULL, // Location of message
|
|
|
|
// definition ignored
|
|
|
|
dwErrCode, // Message identifier for
|
|
|
|
// the requested message
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Language identifier for
|
|
|
|
// the requested message
|
|
|
|
(LPSTR)&pwszMsgBuf, // Buffer that receives
|
|
|
|
// the formatted message
|
|
|
|
0, // Size of output buffer
|
|
|
|
// not needed as allocate
|
|
|
|
// buffer flag is set
|
|
|
|
NULL // Array of insert values
|
|
|
|
);
|
|
|
|
|
|
|
|
if (NULL != pwszMsgBuf)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Error: 0x%08x (%d) %s", dwErrCode, dwErrCode, pwszMsgBuf);
|
|
|
|
LocalFree(pwszMsgBuf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Error: 0x%08x (%d)", dwErrCode, dwErrCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD wf_is_x509_certificate_trusted(const char* common_name, const char* subject,
|
|
|
|
const char* issuer, const char* fingerprint)
|
|
|
|
{
|
2021-10-22 16:41:49 +03:00
|
|
|
size_t derPubKeyLen;
|
|
|
|
char* derPubKey;
|
2021-10-22 17:06:04 +03:00
|
|
|
|
2021-10-22 16:41:49 +03:00
|
|
|
HRESULT hr = CRYPT_E_NOT_FOUND;
|
2021-10-22 17:06:04 +03:00
|
|
|
|
|
|
|
DWORD dwChainFlags = CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT;
|
|
|
|
PCCERT_CONTEXT pCert = NULL;
|
|
|
|
HCERTSTORE hStore = NULL;
|
|
|
|
HCERTCHAINENGINE hChainEngine = NULL;
|
|
|
|
PCCERT_CHAIN_CONTEXT pChainContext = NULL;
|
|
|
|
|
|
|
|
CERT_ENHKEY_USAGE EnhkeyUsage = { 0 };
|
|
|
|
CERT_USAGE_MATCH CertUsage = { 0 };
|
|
|
|
CERT_CHAIN_PARA ChainPara = { 0 };
|
|
|
|
CERT_CHAIN_POLICY_PARA ChainPolicy = { 0 };
|
|
|
|
CERT_CHAIN_POLICY_STATUS PolicyStatus = { 0 };
|
|
|
|
CERT_CHAIN_ENGINE_CONFIG EngineConfig = { 0 };
|
|
|
|
|
2021-10-22 16:41:49 +03:00
|
|
|
derPubKeyLen = strlen(fingerprint);
|
|
|
|
derPubKey = calloc(derPubKeyLen, sizeof(char));
|
|
|
|
if (NULL == derPubKey)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Could not allocate derPubKey");
|
|
|
|
goto CleanUp;
|
|
|
|
}
|
|
|
|
|
2021-10-22 17:06:04 +03:00
|
|
|
/*
|
|
|
|
* Convert from PEM format to DER format - removes header and footer and decodes from base64
|
|
|
|
*/
|
|
|
|
if (!CryptStringToBinaryA(fingerprint, 0, CRYPT_STRING_BASE64HEADER, derPubKey, &derPubKeyLen,
|
|
|
|
NULL, NULL))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "CryptStringToBinary failed. Err: %d", GetLastError());
|
|
|
|
goto CleanUp;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// Initialize data structures for chain building.
|
|
|
|
|
|
|
|
EnhkeyUsage.cUsageIdentifier = 0;
|
|
|
|
EnhkeyUsage.rgpszUsageIdentifier = NULL;
|
|
|
|
|
|
|
|
CertUsage.dwType = USAGE_MATCH_TYPE_AND;
|
|
|
|
CertUsage.Usage = EnhkeyUsage;
|
|
|
|
|
|
|
|
ChainPara.cbSize = sizeof(ChainPara);
|
|
|
|
ChainPara.RequestedUsage = CertUsage;
|
|
|
|
|
|
|
|
ChainPolicy.cbSize = sizeof(ChainPolicy);
|
|
|
|
|
|
|
|
PolicyStatus.cbSize = sizeof(PolicyStatus);
|
|
|
|
|
|
|
|
EngineConfig.cbSize = sizeof(EngineConfig);
|
|
|
|
EngineConfig.dwUrlRetrievalTimeout = 0;
|
|
|
|
|
|
|
|
pCert = CertCreateCertificateContext(X509_ASN_ENCODING, derPubKey, derPubKeyLen);
|
|
|
|
if (NULL == pCert)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "FAILED: Certificate could not be parsed.");
|
|
|
|
goto CleanUp;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwChainFlags |= CERT_CHAIN_ENABLE_PEER_TRUST;
|
|
|
|
|
|
|
|
// When this flag is set, end entity certificates in the
|
|
|
|
// Trusted People store are trusted without doing any chain building
|
|
|
|
// This optimizes the chain building process.
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// Create chain engine.
|
|
|
|
|
|
|
|
if (!CertCreateCertificateChainEngine(&EngineConfig, &hChainEngine))
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
goto CleanUp;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Build a chain using CertGetCertificateChain
|
|
|
|
|
|
|
|
if (!CertGetCertificateChain(hChainEngine, // use the default chain engine
|
|
|
|
pCert, // pointer to the end certificate
|
|
|
|
NULL, // use the default time
|
|
|
|
NULL, // search no additional stores
|
|
|
|
&ChainPara, // use AND logic and enhanced key usage
|
|
|
|
// as indicated in the ChainPara
|
|
|
|
// data structure
|
|
|
|
dwChainFlags,
|
|
|
|
NULL, // currently reserved
|
|
|
|
&pChainContext)) // return a pointer to the chain created
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
goto CleanUp;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------
|
|
|
|
// Verify that the chain complies with policy
|
|
|
|
|
|
|
|
if (!CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE, // use the base policy
|
|
|
|
pChainContext, // pointer to the chain
|
|
|
|
&ChainPolicy,
|
|
|
|
&PolicyStatus)) // return a pointer to the policy status
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
goto CleanUp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PolicyStatus.dwError != S_OK)
|
|
|
|
{
|
|
|
|
wf_report_error("CertVerifyCertificateChainPolicy: Chain Status", PolicyStatus.dwError);
|
|
|
|
hr = PolicyStatus.dwError;
|
|
|
|
// Instruction: If the PolicyStatus.dwError is CRYPT_E_NO_REVOCATION_CHECK or
|
|
|
|
// CRYPT_E_REVOCATION_OFFLINE, it indicates errors in obtaining
|
|
|
|
// revocation information. These can be ignored since the retrieval of
|
|
|
|
// revocation information depends on network availability
|
|
|
|
|
2021-10-22 16:41:49 +03:00
|
|
|
if (PolicyStatus.dwError == CRYPT_E_NO_REVOCATION_CHECK ||
|
|
|
|
PolicyStatus.dwError == CRYPT_E_REVOCATION_OFFLINE)
|
|
|
|
{
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
|
2021-10-22 17:06:04 +03:00
|
|
|
goto CleanUp;
|
|
|
|
}
|
|
|
|
|
2022-06-23 08:57:38 +03:00
|
|
|
WLog_INFO(TAG, "CertVerifyCertificateChainPolicy succeeded for %s (%s) issued by %s",
|
|
|
|
common_name, subject, issuer);
|
2021-10-22 17:06:04 +03:00
|
|
|
|
|
|
|
hr = S_OK;
|
|
|
|
CleanUp:
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WLog_INFO(TAG, "CertVerifyCertificateChainPolicy failed for %s (%s) issued by %s",
|
|
|
|
common_name, subject, issuer);
|
|
|
|
wf_report_error(NULL, hr);
|
|
|
|
}
|
|
|
|
|
2022-06-23 08:57:38 +03:00
|
|
|
free(derPubKey);
|
2021-10-22 16:41:49 +03:00
|
|
|
|
2021-10-22 17:06:04 +03:00
|
|
|
if (NULL != pChainContext)
|
|
|
|
{
|
|
|
|
CertFreeCertificateChain(pChainContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL != hChainEngine)
|
|
|
|
{
|
|
|
|
CertFreeCertificateChainEngine(hChainEngine);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL != pCert)
|
|
|
|
{
|
|
|
|
CertFreeCertificateContext(pCert);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (DWORD)hr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static DWORD wf_cli_verify_certificate_ex(freerdp* instance, const char* host, UINT16 port,
|
|
|
|
const char* common_name, const char* subject,
|
|
|
|
const char* issuer, const char* fingerprint, DWORD flags)
|
|
|
|
{
|
|
|
|
#ifdef WITH_WINDOWS_CERT_STORE
|
|
|
|
if (flags & VERIFY_CERT_FLAG_FP_IS_PEM && !(flags & VERIFY_CERT_FLAG_MISMATCH))
|
|
|
|
{
|
|
|
|
if (wf_is_x509_certificate_trusted(common_name, subject, issuer, fingerprint) == S_OK)
|
|
|
|
{
|
2021-10-29 00:33:51 +03:00
|
|
|
return 2;
|
2021-10-22 17:06:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return client_cli_verify_certificate_ex(instance, host, port, common_name, subject, issuer,
|
|
|
|
fingerprint, flags);
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static DWORD wf_verify_certificate_ex(freerdp* instance, const char* host, UINT16 port,
|
|
|
|
const char* common_name, const char* subject,
|
|
|
|
const char* issuer, const char* fingerprint, DWORD flags)
|
2019-08-29 16:17:59 +03:00
|
|
|
{
|
2021-10-22 16:41:49 +03:00
|
|
|
WCHAR* buffer;
|
|
|
|
WCHAR* caption;
|
|
|
|
int what = IDCANCEL;
|
|
|
|
|
2021-10-22 17:06:04 +03:00
|
|
|
#ifdef WITH_WINDOWS_CERT_STORE
|
|
|
|
if (flags & VERIFY_CERT_FLAG_FP_IS_PEM && !(flags & VERIFY_CERT_FLAG_MISMATCH))
|
|
|
|
{
|
|
|
|
if (wf_is_x509_certificate_trusted(common_name, subject, issuer, fingerprint) == S_OK)
|
|
|
|
{
|
2021-10-29 00:33:51 +03:00
|
|
|
return 2;
|
2021-10-22 17:06:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
buffer = wf_format_text(
|
|
|
|
L"Certificate details:\n"
|
|
|
|
L"\tCommonName: %S\n"
|
|
|
|
L"\tSubject: %S\n"
|
|
|
|
L"\tIssuer: %S\n"
|
|
|
|
L"\tThumbprint: %S\n"
|
|
|
|
L"\tHostMismatch: %S\n"
|
|
|
|
L"\n"
|
|
|
|
L"The above X.509 certificate could not be verified, possibly because you do not have "
|
|
|
|
L"the CA certificate in your certificate store, or the certificate has expired. "
|
|
|
|
L"Please look at the OpenSSL documentation on how to add a private CA to the store.\n"
|
|
|
|
L"\n"
|
|
|
|
L"YES\tAccept permanently\n"
|
|
|
|
L"NO\tAccept for this session only\n"
|
|
|
|
L"CANCEL\tAbort connection\n",
|
|
|
|
common_name, subject, issuer, fingerprint,
|
|
|
|
flags & VERIFY_CERT_FLAG_MISMATCH ? "Yes" : "No");
|
2019-08-29 16:17:59 +03:00
|
|
|
caption = wf_format_text(L"Verify certificate for %S:%hu", host, port);
|
|
|
|
|
2021-03-08 14:48:22 +03:00
|
|
|
WINPR_UNUSED(instance);
|
|
|
|
|
2019-08-29 16:17:59 +03:00
|
|
|
if (!buffer || !caption)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
what = MessageBoxW(NULL, buffer, caption, MB_YESNOCANCEL);
|
|
|
|
fail:
|
|
|
|
free(buffer);
|
|
|
|
free(caption);
|
|
|
|
|
2016-06-04 18:13:07 +03:00
|
|
|
/* return 1 to accept and store a certificate, 2 to accept
|
|
|
|
* a certificate only for this session, 0 otherwise */
|
2019-11-06 17:24:51 +03:00
|
|
|
switch (what)
|
2019-08-29 16:17:59 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
case IDYES:
|
|
|
|
return 1;
|
|
|
|
case IDNO:
|
|
|
|
return 2;
|
|
|
|
default:
|
|
|
|
return 0;
|
2019-08-29 16:17:59 +03:00
|
|
|
}
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static DWORD wf_verify_changed_certificate_ex(freerdp* instance, const char* host, UINT16 port,
|
|
|
|
const char* common_name, const char* subject,
|
|
|
|
const char* issuer, const char* new_fingerprint,
|
|
|
|
const char* old_subject, const char* old_issuer,
|
|
|
|
const char* old_fingerprint, DWORD flags)
|
2015-12-14 16:02:49 +03:00
|
|
|
{
|
2019-08-29 16:17:59 +03:00
|
|
|
WCHAR* buffer;
|
|
|
|
WCHAR* caption;
|
|
|
|
int what = IDCANCEL;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
buffer = wf_format_text(
|
|
|
|
L"New Certificate details:\n"
|
|
|
|
L"\tCommonName: %S\n"
|
|
|
|
L"\tSubject: %S\n"
|
|
|
|
L"\tIssuer: %S\n"
|
|
|
|
L"\tThumbprint: %S\n"
|
|
|
|
L"\tHostMismatch: %S\n"
|
|
|
|
L"\n"
|
|
|
|
L"Old Certificate details:\n"
|
|
|
|
L"\tSubject: %S\n"
|
|
|
|
L"\tIssuer: %S\n"
|
|
|
|
L"\tThumbprint: %S"
|
|
|
|
L"The above X.509 certificate could not be verified, possibly because you do not have "
|
|
|
|
L"the CA certificate in your certificate store, or the certificate has expired. "
|
|
|
|
L"Please look at the OpenSSL documentation on how to add a private CA to the store.\n"
|
|
|
|
L"\n"
|
|
|
|
L"YES\tAccept permanently\n"
|
|
|
|
L"NO\tAccept for this session only\n"
|
|
|
|
L"CANCEL\tAbort connection\n",
|
|
|
|
common_name, subject, issuer, new_fingerprint,
|
|
|
|
flags & VERIFY_CERT_FLAG_MISMATCH ? "Yes" : "No", old_subject, old_issuer, old_fingerprint);
|
2019-08-29 16:17:59 +03:00
|
|
|
caption = wf_format_text(L"Verify certificate change for %S:%hu", host, port);
|
|
|
|
|
2021-03-08 14:48:22 +03:00
|
|
|
WINPR_UNUSED(instance);
|
2019-08-29 16:17:59 +03:00
|
|
|
if (!buffer || !caption)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
what = MessageBoxW(NULL, buffer, caption, MB_YESNOCANCEL);
|
|
|
|
fail:
|
|
|
|
free(buffer);
|
|
|
|
free(caption);
|
|
|
|
|
|
|
|
/* return 1 to accept and store a certificate, 2 to accept
|
|
|
|
* a certificate only for this session, 0 otherwise */
|
2019-11-06 17:24:51 +03:00
|
|
|
switch (what)
|
2019-08-29 16:17:59 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
case IDYES:
|
|
|
|
return 1;
|
|
|
|
case IDNO:
|
|
|
|
return 2;
|
|
|
|
default:
|
|
|
|
return 0;
|
2019-08-29 16:17:59 +03:00
|
|
|
}
|
2015-12-14 16:02:49 +03:00
|
|
|
}
|
|
|
|
|
2020-08-03 13:06:08 +03:00
|
|
|
static BOOL wf_present_gateway_message(freerdp* instance, UINT32 type, BOOL isDisplayMandatory,
|
|
|
|
BOOL isConsentMandatory, size_t length, const WCHAR* message)
|
|
|
|
{
|
|
|
|
if (!isDisplayMandatory && !isConsentMandatory)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* special handling for consent messages (show modal dialog) */
|
2020-08-04 10:11:41 +03:00
|
|
|
if (type == GATEWAY_MESSAGE_CONSENT && isConsentMandatory)
|
2020-08-03 13:06:08 +03:00
|
|
|
{
|
|
|
|
int mbRes;
|
|
|
|
WCHAR* msg;
|
|
|
|
|
|
|
|
msg = wf_format_text(L"%.*s\n\nI understand and agree to the terms of this policy", length,
|
|
|
|
message);
|
|
|
|
mbRes = MessageBoxW(NULL, msg, L"Consent Message", MB_YESNO);
|
|
|
|
free(msg);
|
|
|
|
|
|
|
|
if (mbRes != IDYES)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return client_cli_present_gateway_message(instance, type, isDisplayMandatory,
|
|
|
|
isConsentMandatory, length, message);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
static DWORD WINAPI wf_client_thread(LPVOID lpParam)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
|
|
|
MSG msg;
|
2013-04-11 00:58:14 +04:00
|
|
|
int width;
|
|
|
|
int height;
|
2013-03-19 04:12:51 +04:00
|
|
|
BOOL msg_ret;
|
|
|
|
int quit_msg;
|
2017-11-20 15:16:49 +03:00
|
|
|
DWORD error;
|
2013-06-16 06:57:21 +04:00
|
|
|
wfContext* wfc;
|
2013-03-19 19:11:14 +04:00
|
|
|
freerdp* instance;
|
2015-01-30 06:57:58 +03:00
|
|
|
rdpContext* context;
|
2013-03-19 04:12:51 +04:00
|
|
|
rdpChannels* channels;
|
2014-05-21 10:52:57 +04:00
|
|
|
rdpSettings* settings;
|
2022-03-23 15:18:35 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
instance = (freerdp*)lpParam;
|
2022-03-23 15:18:35 +03:00
|
|
|
WINPR_ASSERT(instance);
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2015-01-30 06:57:58 +03:00
|
|
|
if (!freerdp_connect(instance))
|
2017-11-20 15:16:49 +03:00
|
|
|
goto end;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
context = instance->context;
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
|
|
|
wfc = (wfContext*)instance->context;
|
|
|
|
WINPR_ASSERT(wfc);
|
|
|
|
|
|
|
|
channels = context->channels;
|
|
|
|
WINPR_ASSERT(channels);
|
|
|
|
|
|
|
|
settings = context->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
2014-05-21 10:52:57 +04:00
|
|
|
|
2013-03-19 04:12:51 +04:00
|
|
|
while (1)
|
|
|
|
{
|
2022-03-23 15:18:35 +03:00
|
|
|
HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
|
|
|
|
DWORD nCount = 0;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2014-10-03 18:27:47 +04:00
|
|
|
if (freerdp_focus_required(instance))
|
|
|
|
{
|
|
|
|
wf_event_focus_in(wfc);
|
|
|
|
wf_event_focus_in(wfc);
|
|
|
|
}
|
|
|
|
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2015-04-21 13:24:50 +03:00
|
|
|
DWORD tmp = freerdp_get_event_handles(context, &handles[nCount], 64 - nCount);
|
|
|
|
|
|
|
|
if (tmp == 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "freerdp_get_event_handles failed");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nCount += tmp;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
2014-05-21 10:52:57 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (MsgWaitForMultipleObjects(nCount, handles, FALSE, 1000, QS_ALLINPUT) == WAIT_FAILED)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "wfreerdp_run: WaitForMultipleObjects failed: 0x%08lX", GetLastError());
|
2013-03-19 04:12:51 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2015-01-30 06:57:58 +03:00
|
|
|
if (!freerdp_check_event_handles(context))
|
2014-05-21 10:52:57 +04:00
|
|
|
{
|
2018-09-24 11:30:59 +03:00
|
|
|
if (client_auto_reconnect(instance))
|
2014-05-21 10:52:57 +04:00
|
|
|
continue;
|
2014-04-27 16:52:45 +04:00
|
|
|
|
2015-01-30 06:57:58 +03:00
|
|
|
WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
|
2021-10-21 18:59:17 +03:00
|
|
|
fflush(stdout);
|
2014-05-21 10:52:57 +04:00
|
|
|
break;
|
|
|
|
}
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
2015-01-30 06:57:58 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (freerdp_shall_disconnect_context(instance->context))
|
2013-03-19 04:12:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
quit_msg = FALSE;
|
2013-03-19 05:54:50 +04:00
|
|
|
|
2013-03-19 04:12:51 +04:00
|
|
|
while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
|
|
|
|
{
|
|
|
|
msg_ret = GetMessage(&msg, NULL, 0, 0);
|
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
if (settings->EmbeddedWindow)
|
2013-04-11 00:58:14 +04:00
|
|
|
{
|
|
|
|
if ((msg.message == WM_SETFOCUS) && (msg.lParam == 1))
|
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
PostMessage(wfc->hwnd, WM_SETFOCUS, 0, 0);
|
2013-04-11 00:58:14 +04:00
|
|
|
}
|
|
|
|
else if ((msg.message == WM_KILLFOCUS) && (msg.lParam == 1))
|
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
PostMessage(wfc->hwnd, WM_KILLFOCUS, 0, 0);
|
2013-04-11 00:58:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg.message == WM_SIZE)
|
|
|
|
{
|
|
|
|
width = LOWORD(msg.lParam);
|
|
|
|
height = HIWORD(msg.lParam);
|
2013-06-16 06:57:21 +04:00
|
|
|
SetWindowPos(wfc->hwnd, HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED);
|
2013-04-11 00:58:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((msg_ret == 0) || (msg_ret == -1))
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
|
|
|
quit_msg = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (quit_msg)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cleanup */
|
2014-05-21 10:52:57 +04:00
|
|
|
|
2015-05-05 14:55:48 +03:00
|
|
|
disconnect:
|
2013-06-16 06:57:21 +04:00
|
|
|
freerdp_disconnect(instance);
|
2016-08-09 17:48:02 +03:00
|
|
|
|
2017-11-20 15:16:49 +03:00
|
|
|
end:
|
|
|
|
error = freerdp_get_last_error(instance->context);
|
|
|
|
WLog_DBG(TAG, "Main thread exited with %" PRIu32, error);
|
|
|
|
ExitThread(error);
|
|
|
|
return error;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
static DWORD WINAPI wf_keyboard_thread(LPVOID lpParam)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
BOOL status;
|
2013-06-16 06:57:21 +04:00
|
|
|
wfContext* wfc;
|
2013-03-19 04:12:51 +04:00
|
|
|
HHOOK hook_handle;
|
2019-11-06 17:24:51 +03:00
|
|
|
wfc = (wfContext*)lpParam;
|
2021-06-09 15:03:34 +03:00
|
|
|
WINPR_ASSERT(NULL != wfc);
|
2019-11-06 17:24:51 +03:00
|
|
|
hook_handle = SetWindowsHookEx(WH_KEYBOARD_LL, wf_ll_kbd_proc, wfc->hInstance, 0);
|
2013-03-19 04:12:51 +04:00
|
|
|
|
|
|
|
if (hook_handle)
|
|
|
|
{
|
2013-03-19 05:54:50 +04:00
|
|
|
while ((status = GetMessage(&msg, NULL, 0, 0)) != 0)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
|
|
|
if (status == -1)
|
|
|
|
{
|
2015-01-30 06:57:58 +03:00
|
|
|
WLog_ERR(TAG, "keyboard thread error getting message");
|
2013-03-19 04:12:51 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
}
|
2013-03-19 05:54:50 +04:00
|
|
|
|
2013-03-19 04:12:51 +04:00
|
|
|
UnhookWindowsHookEx(hook_handle);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-30 06:57:58 +03:00
|
|
|
WLog_ERR(TAG, "failed to install keyboard hook");
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_DBG(TAG, "Keyboard thread exited.");
|
2013-09-05 15:39:43 +04:00
|
|
|
ExitThread(0);
|
2013-04-11 00:58:14 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-09 11:54:31 +03:00
|
|
|
int freerdp_client_set_window_size(wfContext* wfc, int width, int height)
|
2013-04-30 23:18:26 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_DBG(TAG, "freerdp_client_set_window_size %d, %d", width, height);
|
2014-09-12 19:13:01 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if ((width != wfc->client_width) || (height != wfc->client_height))
|
2013-04-11 00:58:14 +04:00
|
|
|
{
|
2016-08-03 13:09:24 +03:00
|
|
|
PostThreadMessage(wfc->mainThreadId, WM_SIZE, SIZE_RESTORED,
|
2019-11-06 17:24:51 +03:00
|
|
|
((UINT)height << 16) | (UINT)width);
|
2013-04-11 00:58:14 +04:00
|
|
|
}
|
|
|
|
|
2013-03-19 05:54:50 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
void wf_size_scrollbars(wfContext* wfc, UINT32 client_width, UINT32 client_height)
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
2022-01-19 11:27:39 +03:00
|
|
|
const rdpSettings* settings;
|
|
|
|
WINPR_ASSERT(wfc);
|
|
|
|
|
|
|
|
settings = wfc->common.context.settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2014-02-10 09:34:17 +04:00
|
|
|
if (wfc->disablewindowtracking)
|
2013-04-26 23:46:36 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
// prevent infinite message loop
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->disablewindowtracking = TRUE;
|
2013-04-26 23:46:36 +04:00
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
if (settings->SmartSizing || settings->DynamicResolutionUpdate)
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->xCurrentScroll = 0;
|
|
|
|
wfc->yCurrentScroll = 0;
|
2013-04-30 19:15:04 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->xScrollVisible || wfc->yScrollVisible)
|
2013-04-30 19:15:04 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
if (ShowScrollBar(wfc->hwnd, SB_BOTH, FALSE))
|
2013-04-30 19:15:04 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->xScrollVisible = FALSE;
|
|
|
|
wfc->yScrollVisible = FALSE;
|
2013-04-30 19:15:04 +04:00
|
|
|
}
|
|
|
|
}
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCROLLINFO si;
|
2013-06-16 06:57:21 +04:00
|
|
|
BOOL horiz = wfc->xScrollVisible;
|
2019-05-08 13:58:01 +03:00
|
|
|
BOOL vert = wfc->yScrollVisible;
|
2013-04-26 23:46:36 +04:00
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
if (!horiz && client_width < settings->DesktopWidth)
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
2015-03-17 15:02:41 +03:00
|
|
|
horiz = TRUE;
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
else if (horiz &&
|
2022-01-19 11:27:39 +03:00
|
|
|
client_width >= settings->DesktopWidth /* - GetSystemMetrics(SM_CXVSCROLL)*/)
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
2015-03-17 15:02:41 +03:00
|
|
|
horiz = FALSE;
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
if (!vert && client_height < settings->DesktopHeight)
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
|
|
|
vert = TRUE;
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
else if (vert &&
|
2022-01-19 11:27:39 +03:00
|
|
|
client_height >= settings->DesktopHeight /* - GetSystemMetrics(SM_CYHSCROLL)*/)
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
|
|
|
vert = FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (horiz == vert && (horiz != wfc->xScrollVisible && vert != wfc->yScrollVisible))
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
if (ShowScrollBar(wfc->hwnd, SB_BOTH, horiz))
|
2013-04-30 19:15:04 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->xScrollVisible = horiz;
|
|
|
|
wfc->yScrollVisible = vert;
|
2013-04-30 19:15:04 +04:00
|
|
|
}
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (horiz != wfc->xScrollVisible)
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
if (ShowScrollBar(wfc->hwnd, SB_HORZ, horiz))
|
2013-04-30 19:15:04 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->xScrollVisible = horiz;
|
2013-04-30 19:15:04 +04:00
|
|
|
}
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (vert != wfc->yScrollVisible)
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
if (ShowScrollBar(wfc->hwnd, SB_VERT, vert))
|
2013-04-30 19:15:04 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->yScrollVisible = vert;
|
2013-04-30 19:15:04 +04:00
|
|
|
}
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (horiz)
|
|
|
|
{
|
2015-03-17 15:02:41 +03:00
|
|
|
// The horizontal scrolling range is defined by
|
|
|
|
// (bitmap_width) - (client_width). The current horizontal
|
|
|
|
// scroll value remains within the horizontal scrolling range.
|
2022-01-19 11:27:39 +03:00
|
|
|
wfc->xMaxScroll = MAX(settings->DesktopWidth - client_width, 0);
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->xCurrentScroll = MIN(wfc->xCurrentScroll, wfc->xMaxScroll);
|
2015-03-17 15:02:41 +03:00
|
|
|
si.cbSize = sizeof(si);
|
2019-11-06 17:24:51 +03:00
|
|
|
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
|
|
|
|
si.nMin = wfc->xMinScroll;
|
2022-01-19 11:27:39 +03:00
|
|
|
si.nMax = settings->DesktopWidth;
|
2019-11-06 17:24:51 +03:00
|
|
|
si.nPage = client_width;
|
|
|
|
si.nPos = wfc->xCurrentScroll;
|
2013-06-16 06:57:21 +04:00
|
|
|
SetScrollInfo(wfc->hwnd, SB_HORZ, &si, TRUE);
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vert)
|
|
|
|
{
|
2015-03-17 15:02:41 +03:00
|
|
|
// The vertical scrolling range is defined by
|
|
|
|
// (bitmap_height) - (client_height). The current vertical
|
|
|
|
// scroll value remains within the vertical scrolling range.
|
2022-01-19 11:27:39 +03:00
|
|
|
wfc->yMaxScroll = MAX(settings->DesktopHeight - client_height, 0);
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->yCurrentScroll = MIN(wfc->yCurrentScroll, wfc->yMaxScroll);
|
2015-03-17 15:02:41 +03:00
|
|
|
si.cbSize = sizeof(si);
|
2019-11-06 17:24:51 +03:00
|
|
|
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
|
|
|
|
si.nMin = wfc->yMinScroll;
|
2022-01-19 11:27:39 +03:00
|
|
|
si.nMax = settings->DesktopHeight;
|
2019-11-06 17:24:51 +03:00
|
|
|
si.nPage = client_height;
|
|
|
|
si.nPos = wfc->yCurrentScroll;
|
2013-06-16 06:57:21 +04:00
|
|
|
SetScrollInfo(wfc->hwnd, SB_VERT, &si, TRUE);
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
}
|
2013-04-30 19:15:04 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->disablewindowtracking = FALSE;
|
|
|
|
wf_update_canvas_diff(wfc);
|
|
|
|
}
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
static BOOL wfreerdp_client_global_init(void)
|
2013-06-16 06:57:21 +04:00
|
|
|
{
|
|
|
|
WSADATA wsaData;
|
|
|
|
|
|
|
|
WSAStartup(0x101, &wsaData);
|
2019-08-29 14:47:53 +03:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
freerdp_register_addin_provider(freerdp_channels_load_static_addin_entry, 0);
|
2021-10-21 01:29:00 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2013-06-16 06:57:21 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
static void wfreerdp_client_global_uninit(void)
|
2013-06-16 06:57:21 +04:00
|
|
|
{
|
|
|
|
WSACleanup();
|
|
|
|
}
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
static BOOL wfreerdp_client_new(freerdp* instance, rdpContext* context)
|
2013-06-16 06:57:21 +04:00
|
|
|
{
|
2019-08-29 16:17:59 +03:00
|
|
|
wfContext* wfc = (wfContext*)context;
|
|
|
|
if (!wfc)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-08-29 20:28:50 +03:00
|
|
|
// AttachConsole and stdin do not work well.
|
|
|
|
// Use GUI input dialogs instead of command line ones.
|
2021-10-11 23:00:52 +03:00
|
|
|
wfc->isConsole = wf_has_console();
|
2019-08-29 16:17:59 +03:00
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(wfreerdp_client_global_init()))
|
|
|
|
return FALSE;
|
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
WINPR_ASSERT(instance);
|
2013-06-16 06:57:21 +04:00
|
|
|
instance->PreConnect = wf_pre_connect;
|
|
|
|
instance->PostConnect = wf_post_connect;
|
2016-08-10 14:33:34 +03:00
|
|
|
instance->PostDisconnect = wf_post_disconnect;
|
2013-06-16 06:57:21 +04:00
|
|
|
instance->Authenticate = wf_authenticate;
|
2015-06-23 15:59:54 +03:00
|
|
|
instance->GatewayAuthenticate = wf_gw_authenticate;
|
2021-10-22 17:06:04 +03:00
|
|
|
|
|
|
|
#ifdef WITH_WINDOWS_CERT_STORE
|
2022-03-23 15:18:35 +03:00
|
|
|
freerdp_settings_set_bool(context->settings, FreeRDP_CertificateCallbackPreferPEM, TRUE);
|
2021-10-22 17:06:04 +03:00
|
|
|
#endif
|
|
|
|
|
2019-08-29 20:28:50 +03:00
|
|
|
if (wfc->isConsole)
|
|
|
|
{
|
2021-10-22 17:06:04 +03:00
|
|
|
instance->VerifyCertificateEx = wf_cli_verify_certificate_ex;
|
2019-08-29 20:28:50 +03:00
|
|
|
instance->VerifyChangedCertificateEx = client_cli_verify_changed_certificate_ex;
|
2020-08-03 13:06:08 +03:00
|
|
|
instance->PresentGatewayMessage = client_cli_present_gateway_message;
|
2019-08-29 20:28:50 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
instance->VerifyCertificateEx = wf_verify_certificate_ex;
|
|
|
|
instance->VerifyChangedCertificateEx = wf_verify_changed_certificate_ex;
|
2020-08-03 13:06:08 +03:00
|
|
|
instance->PresentGatewayMessage = wf_present_gateway_message;
|
2019-08-29 20:28:50 +03:00
|
|
|
}
|
2022-06-23 08:57:38 +03:00
|
|
|
|
2021-10-21 18:59:17 +03:00
|
|
|
#ifdef WITH_PROGRESS_BAR
|
|
|
|
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
CoCreateInstance(&CLSID_TaskbarList, NULL, CLSCTX_ALL, &IID_ITaskbarList3,
|
|
|
|
(void**)&wfc->taskBarList);
|
|
|
|
#endif
|
2019-08-29 16:17:59 +03:00
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
return TRUE;
|
2013-06-16 06:57:21 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
static void wfreerdp_client_free(freerdp* instance, rdpContext* context)
|
2013-06-16 06:57:21 +04:00
|
|
|
{
|
2021-03-08 14:48:22 +03:00
|
|
|
WINPR_UNUSED(instance);
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!context)
|
|
|
|
return;
|
2021-10-21 18:59:17 +03:00
|
|
|
|
|
|
|
#ifdef WITH_PROGRESS_BAR
|
|
|
|
CoUninitialize();
|
|
|
|
#endif
|
2013-06-16 06:57:21 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
static int wfreerdp_client_start(rdpContext* context)
|
2013-06-16 06:57:21 +04:00
|
|
|
{
|
|
|
|
HWND hWndParent;
|
|
|
|
HINSTANCE hInstance;
|
2019-11-06 17:24:51 +03:00
|
|
|
wfContext* wfc = (wfContext*)context;
|
2022-03-23 15:18:35 +03:00
|
|
|
freerdp* instance;
|
|
|
|
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(context->settings);
|
|
|
|
|
|
|
|
instance = context->instance;
|
|
|
|
WINPR_ASSERT(instance);
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
hInstance = GetModuleHandle(NULL);
|
2022-03-23 15:18:35 +03:00
|
|
|
hWndParent = (HWND)context->settings->ParentWindowId;
|
|
|
|
context->settings->EmbeddedWindow = (hWndParent) ? TRUE : FALSE;
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->hWndParent = hWndParent;
|
|
|
|
wfc->hInstance = hInstance;
|
|
|
|
wfc->cursor = LoadCursor(NULL, IDC_ARROW);
|
|
|
|
wfc->icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
|
|
|
|
wfc->wndClassName = _tcsdup(_T("FreeRDP"));
|
|
|
|
wfc->wndClass.cbSize = sizeof(WNDCLASSEX);
|
|
|
|
wfc->wndClass.style = CS_HREDRAW | CS_VREDRAW;
|
|
|
|
wfc->wndClass.lpfnWndProc = wf_event_proc;
|
|
|
|
wfc->wndClass.cbClsExtra = 0;
|
|
|
|
wfc->wndClass.cbWndExtra = 0;
|
|
|
|
wfc->wndClass.hCursor = wfc->cursor;
|
2019-11-06 17:24:51 +03:00
|
|
|
wfc->wndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->wndClass.lpszMenuName = NULL;
|
|
|
|
wfc->wndClass.lpszClassName = wfc->wndClassName;
|
|
|
|
wfc->wndClass.hInstance = hInstance;
|
|
|
|
wfc->wndClass.hIcon = wfc->icon;
|
|
|
|
wfc->wndClass.hIconSm = wfc->icon;
|
|
|
|
RegisterClassEx(&(wfc->wndClass));
|
2019-11-06 17:24:51 +03:00
|
|
|
wfc->keyboardThread =
|
|
|
|
CreateThread(NULL, 0, wf_keyboard_thread, (void*)wfc, 0, &wfc->keyboardThreadId);
|
2013-06-16 06:57:21 +04:00
|
|
|
|
|
|
|
if (!wfc->keyboardThread)
|
|
|
|
return -1;
|
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
wfc->common.thread =
|
|
|
|
CreateThread(NULL, 0, wf_client_thread, (void*)instance, 0, &wfc->mainThreadId);
|
2013-06-16 06:57:21 +04:00
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
if (!wfc->common.thread)
|
2013-06-16 06:57:21 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
static int wfreerdp_client_stop(rdpContext* context)
|
2013-06-16 06:57:21 +04:00
|
|
|
{
|
2022-01-19 14:11:48 +03:00
|
|
|
int rc;
|
2019-11-06 17:24:51 +03:00
|
|
|
wfContext* wfc = (wfContext*)context;
|
2013-06-16 06:57:21 +04:00
|
|
|
|
2022-01-19 14:11:48 +03:00
|
|
|
WINPR_ASSERT(wfc);
|
|
|
|
PostThreadMessage(wfc->mainThreadId, WM_QUIT, 0, 0);
|
|
|
|
rc = freerdp_client_common_stop(context);
|
|
|
|
wfc->mainThreadId = 0;
|
2013-09-05 15:39:43 +04:00
|
|
|
|
|
|
|
if (wfc->keyboardThread)
|
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
PostThreadMessage(wfc->keyboardThreadId, WM_QUIT, 0, 0);
|
2013-09-05 15:39:43 +04:00
|
|
|
WaitForSingleObject(wfc->keyboardThread, INFINITE);
|
|
|
|
CloseHandle(wfc->keyboardThread);
|
|
|
|
wfc->keyboardThread = NULL;
|
|
|
|
wfc->keyboardThreadId = 0;
|
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
|
|
|
|
{
|
|
|
|
pEntryPoints->Version = 1;
|
|
|
|
pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
|
|
|
|
pEntryPoints->GlobalInit = wfreerdp_client_global_init;
|
|
|
|
pEntryPoints->GlobalUninit = wfreerdp_client_global_uninit;
|
|
|
|
pEntryPoints->ContextSize = sizeof(wfContext);
|
|
|
|
pEntryPoints->ClientNew = wfreerdp_client_new;
|
|
|
|
pEntryPoints->ClientFree = wfreerdp_client_free;
|
|
|
|
pEntryPoints->ClientStart = wfreerdp_client_start;
|
|
|
|
pEntryPoints->ClientStop = wfreerdp_client_stop;
|
|
|
|
return 0;
|
2013-05-31 22:54:15 +04:00
|
|
|
}
|