From 284e20b140a31788c066f6d88993342bdc94cff2 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 19 Jan 2021 08:44:14 +0100 Subject: [PATCH] Fixed #6696: Implement HandshakeEx in windows client Special thanks to @byteboon for bisecting the issue --- client/Windows/wf_rail.c | 91 +++++++++++++++++++++++++++++----------- client/Windows/wf_rail.h | 16 ------- 2 files changed, 66 insertions(+), 41 deletions(-) diff --git a/client/Windows/wf_rail.c b/client/Windows/wf_rail.c index 0d97f85ec..85fbc8390 100644 --- a/client/Windows/wf_rail.c +++ b/client/Windows/wf_rail.c @@ -32,6 +32,22 @@ #define GET_X_LPARAM(lParam) ((UINT16)(lParam & 0xFFFF)) #define GET_Y_LPARAM(lParam) ((UINT16)((lParam >> 16) & 0xFFFF)) +struct wf_rail_window +{ + wfContext* wfc; + + HWND hWnd; + + DWORD dwStyle; + DWORD dwExStyle; + + int x; + int y; + int width; + int height; + char* title; +}; + /* RemoteApp Core Protocol Extension */ struct _WINDOW_STYLE @@ -95,7 +111,7 @@ static const WINDOW_STYLE EXTENDED_WINDOW_STYLES[] = { { WS_EX_WINDOWEDGE, "WS_EX_WINDOWEDGE", FALSE } }; -void PrintWindowStyles(UINT32 style) +static void PrintWindowStyles(UINT32 style) { int i; WLog_INFO(TAG, "\tWindow Styles:\t{"); @@ -115,7 +131,7 @@ void PrintWindowStyles(UINT32 style) } } -void PrintExtendedWindowStyles(UINT32 style) +static void PrintExtendedWindowStyles(UINT32 style) { int i; WLog_INFO(TAG, "\tExtended Window Styles:\t{"); @@ -854,34 +870,46 @@ static UINT wf_rail_server_system_param(RailClientContext* context, return CHANNEL_RC_OK; } -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT wf_rail_server_handshake(RailClientContext* context, - const RAIL_HANDSHAKE_ORDER* handshake) +static UINT wf_rail_server_start_cmd(RailClientContext* context) { - RAIL_EXEC_ORDER exec; - RAIL_SYSPARAM_ORDER sysparam; - RAIL_HANDSHAKE_ORDER clientHandshake; - RAIL_CLIENT_STATUS_ORDER clientStatus; + UINT status; + RAIL_EXEC_ORDER exec = { 0 }; + RAIL_SYSPARAM_ORDER sysparam = { 0 }; + RAIL_CLIENT_STATUS_ORDER clientStatus = { 0 }; wfContext* wfc = (wfContext*)context->custom; rdpSettings* settings = wfc->context.settings; - clientHandshake.buildNumber = 0x00001DB0; - context->ClientHandshake(context, &clientHandshake); - ZeroMemory(&clientStatus, sizeof(RAIL_CLIENT_STATUS_ORDER)); - clientStatus.flags = RAIL_CLIENTSTATUS_ALLOWLOCALMOVESIZE; - context->ClientInformation(context, &clientStatus); + clientStatus.flags = TS_RAIL_CLIENTSTATUS_ALLOWLOCALMOVESIZE; + + if (settings->AutoReconnectionEnabled) + clientStatus.flags |= TS_RAIL_CLIENTSTATUS_AUTORECONNECT; + + clientStatus.flags |= TS_RAIL_CLIENTSTATUS_ZORDER_SYNC; + clientStatus.flags |= TS_RAIL_CLIENTSTATUS_WINDOW_RESIZE_MARGIN_SUPPORTED; + clientStatus.flags |= TS_RAIL_CLIENTSTATUS_APPBAR_REMOTING_SUPPORTED; + clientStatus.flags |= TS_RAIL_CLIENTSTATUS_POWER_DISPLAY_REQUEST_SUPPORTED; + clientStatus.flags |= TS_RAIL_CLIENTSTATUS_BIDIRECTIONAL_CLOAK_SUPPORTED; + status = context->ClientInformation(context, &clientStatus); + + if (status != CHANNEL_RC_OK) + return status; if (settings->RemoteAppLanguageBarSupported) { RAIL_LANGBAR_INFO_ORDER langBarInfo; langBarInfo.languageBarStatus = 0x00000008; /* TF_SFT_HIDDEN */ - context->ClientLanguageBarInfo(context, &langBarInfo); + status = context->ClientLanguageBarInfo(context, &langBarInfo); + + /* We want the language bar, but the server might not support it. */ + switch (status) + { + case CHANNEL_RC_OK: + case ERROR_BAD_CONFIGURATION: + break; + default: + return status; + } } - ZeroMemory(&sysparam, sizeof(RAIL_SYSPARAM_ORDER)); sysparam.params = 0; sysparam.params |= SPI_MASK_SET_HIGH_CONTRAST; sysparam.highContrast.colorScheme.string = NULL; @@ -901,13 +929,26 @@ static UINT wf_rail_server_handshake(RailClientContext* context, sysparam.workArea.right = settings->DesktopWidth; sysparam.workArea.bottom = settings->DesktopHeight; sysparam.dragFullWindows = FALSE; - context->ClientSystemParam(context, &sysparam); - ZeroMemory(&exec, sizeof(RAIL_EXEC_ORDER)); + status = context->ClientSystemParam(context, &sysparam); + + if (status != CHANNEL_RC_OK) + return status; + exec.RemoteApplicationProgram = settings->RemoteApplicationProgram; exec.RemoteApplicationWorkingDir = settings->ShellWorkingDirectory; exec.RemoteApplicationArguments = settings->RemoteApplicationCmdLine; - context->ClientExecute(context, &exec); - return CHANNEL_RC_OK; + return context->ClientExecute(context, &exec); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT wf_rail_server_handshake(RailClientContext* context, + const RAIL_HANDSHAKE_ORDER* handshake) +{ + return wf_rail_server_start_cmd(context); } /** @@ -918,7 +959,7 @@ static UINT wf_rail_server_handshake(RailClientContext* context, static UINT wf_rail_server_handshake_ex(RailClientContext* context, const RAIL_HANDSHAKE_EX_ORDER* handshakeEx) { - return CHANNEL_RC_OK; + return wf_rail_server_start_cmd(context); } /** diff --git a/client/Windows/wf_rail.h b/client/Windows/wf_rail.h index 1bf8c27a6..2b73821e1 100644 --- a/client/Windows/wf_rail.h +++ b/client/Windows/wf_rail.h @@ -25,22 +25,6 @@ typedef struct wf_rail_window wfRailWindow; #include -struct wf_rail_window -{ - wfContext* wfc; - - HWND hWnd; - - DWORD dwStyle; - DWORD dwExStyle; - - int x; - int y; - int width; - int height; - char* title; -}; - BOOL wf_rail_init(wfContext* wfc, RailClientContext* rail); void wf_rail_uninit(wfContext* wfc, RailClientContext* rail);