From 84582661837b0b787486c888d51eba522a9da8d7 Mon Sep 17 00:00:00 2001 From: rbarnett <43044166+r-barnett@users.noreply.github.com> Date: Tue, 18 Sep 2018 15:31:10 -0500 Subject: [PATCH] Store the disconnect provider ulimatum reason in a new field in struct rdp_context and move the test for a logoff reason to xf_client.c --- client/X11/xf_client.c | 18 ++++++++++++++++++ include/freerdp/freerdp.h | 6 +++++- libfreerdp/core/freerdp.c | 11 +++++++++++ libfreerdp/core/rdp.c | 9 +-------- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index 11501ec50..6943c7d3e 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -71,6 +71,13 @@ #include #include +/* + * X11/Xlib.h defines Status, but winpr/rpc.h, which is eventually included by + * mcs.h, declares a few functions that have a parameter named Status. + */ +#undef Status +#include + #include #include #include @@ -101,6 +108,7 @@ #include "xf_channels.h" #include "xfreerdp.h" + #include #define TAG CLIENT_TAG("x11") @@ -1631,8 +1639,18 @@ static DWORD WINAPI xf_client_thread(LPVOID param) } if (!exit_code) + { exit_code = freerdp_error_info(instance); + if (exit_code == XF_EXIT_DISCONNECT && freerdp_get_dpu_reason(context) == MCS_Reason_user_requested) + { + /* This situation might be limited to Windows XP. */ + WLog_INFO(TAG, + "Error info says user did not initiate but MCS ultimatum says they did; treat this as a user logoff"); + exit_code = XF_EXIT_LOGOFF; + } + } + disconnect: if (timer) diff --git a/include/freerdp/freerdp.h b/include/freerdp/freerdp.h index 80726337a..527537fd0 100644 --- a/include/freerdp/freerdp.h +++ b/include/freerdp/freerdp.h @@ -179,7 +179,8 @@ struct rdp_context ALIGN64 rdpCodecs* codecs; /* 42 */ ALIGN64 rdpAutoDetect* autodetect; /* 43 */ ALIGN64 HANDLE abortEvent; /* 44 */ - UINT64 paddingC[64 - 45]; /* 45 */ + ALIGN64 int dpuReason; /* 45 */ + UINT64 paddingC[64 - 46]; /* 46 */ UINT64 paddingD[96 - 64]; /* 64 */ UINT64 paddingE[128 - 96]; /* 96 */ @@ -360,6 +361,9 @@ FREERDP_API void freerdp_free(freerdp* instance); FREERDP_API BOOL freerdp_focus_required(freerdp* instance); FREERDP_API void freerdp_set_focus(freerdp* instance); +FREERDP_API int freerdp_get_dpu_reason(rdpContext* context); +FREERDP_API void freerdp_set_dpu_reason(rdpContext* context, int reason); + FREERDP_API UINT32 freerdp_get_last_error(rdpContext* context); FREERDP_API const char* freerdp_get_last_error_name(UINT32 error); FREERDP_API const char* freerdp_get_last_error_string(UINT32 error); diff --git a/libfreerdp/core/freerdp.c b/libfreerdp/core/freerdp.c index baf56ff27..8167b38c9 100644 --- a/libfreerdp/core/freerdp.c +++ b/libfreerdp/core/freerdp.c @@ -658,6 +658,7 @@ BOOL freerdp_context_new(freerdp* instance) context->instance = instance; context->ServerMode = FALSE; context->settings = instance->settings; + context->dpuReason = 0; context->pubSub = PubSub_New(TRUE); if (!context->pubSub) @@ -760,6 +761,16 @@ void freerdp_context_free(freerdp* instance) instance->context = NULL; } +void freerdp_set_dpu_reason(rdpContext* context, int reason) +{ + context->dpuReason = reason; +} + +int freerdp_get_dpu_reason(rdpContext* context) +{ + return context->dpuReason; +} + UINT32 freerdp_error_info(freerdp* instance) { return instance->context->rdp->errorInfo; diff --git a/libfreerdp/core/rdp.c b/libfreerdp/core/rdp.c index f01e037b1..616052837 100644 --- a/libfreerdp/core/rdp.c +++ b/libfreerdp/core/rdp.c @@ -358,6 +358,7 @@ BOOL rdp_read_header(rdpRdp* rdp, wStream* s, UINT16* length, UINT16* channelId) return FALSE; context = rdp->instance->context; + freerdp_set_dpu_reason(context, reason); if (rdp->errorInfo == ERRINFO_SUCCESS) { @@ -373,14 +374,6 @@ BOOL rdp_read_header(rdpRdp* rdp, wStream* s, UINT16* length, UINT16* channelId) else rdp_set_error_info(rdp, ERRINFO_RPC_INITIATED_DISCONNECT); } - else if ((rdp->errorInfo == ERRINFO_RPC_INITIATED_DISCONNECT) && (reason == MCS_Reason_user_requested)) - { - /* - * This situation might be limited to Windows XP. - */ - WLog_INFO(TAG, "Error info says user did not initiate but MCS ultimatum sa they did; treat this as a user logoff"); - rdp_set_error_info(rdp, ERRINFO_LOGOFF_BY_USER); - } WLog_DBG(TAG, "DisconnectProviderUltimatum: reason: %d", reason); freerdp_abort_connect(rdp->instance);