Implement gateway message callback for Windows, Wayland and X11 clients
authorMartin Fleisz <martin.fleisz@thincast.com>
Mon, 3 Aug 2020 10:06:08 +0000 (12:06 +0200)
committerArmin Novak <armin.novak@thincast.com>
Wed, 5 Aug 2020 08:59:50 +0000 (10:59 +0200)
(cherry picked from commit 2fe8e762d2b6765b486513159d18ffd98e267873)

client/Wayland/wlfreerdp.c
client/Windows/wf_client.c
client/X11/xf_client.c
client/common/client.c
include/freerdp/client.h

index 11b747e..329d120 100644 (file)
@@ -550,6 +550,7 @@ static BOOL wlf_client_new(freerdp* instance, rdpContext* context)
        instance->GatewayAuthenticate = client_cli_gw_authenticate;
        instance->VerifyCertificateEx = client_cli_verify_certificate_ex;
        instance->VerifyChangedCertificateEx = client_cli_verify_changed_certificate_ex;
+       instance->PresentGatewayMessage = client_cli_present_gateway_message;
        instance->LogonErrorInfo = wlf_logon_error_info;
        wfl->log = WLog_Get(TAG);
        wfl->display = UwacOpenDisplay(NULL, &status);
index a9a1d96..9ebad7a 100644 (file)
@@ -638,6 +638,33 @@ fail:
        }
 }
 
+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) */
+       if (type == 1 && isConsentMandatory)
+       {
+               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;
+}
+
 static DWORD WINAPI wf_input_thread(LPVOID arg)
 {
        int status;
@@ -1025,11 +1052,13 @@ static BOOL wfreerdp_client_new(freerdp* instance, rdpContext* context)
        {
                instance->VerifyCertificateEx = client_cli_verify_certificate_ex;
                instance->VerifyChangedCertificateEx = client_cli_verify_changed_certificate_ex;
+               instance->PresentGatewayMessage = client_cli_present_gateway_message;
        }
        else
        {
                instance->VerifyCertificateEx = wf_verify_certificate_ex;
                instance->VerifyChangedCertificateEx = wf_verify_changed_certificate_ex;
+               instance->PresentGatewayMessage = wf_present_gateway_message;
        }
 
        return TRUE;
index 2a5569d..6e9f85a 100644 (file)
@@ -1837,6 +1837,7 @@ static BOOL xfreerdp_client_new(freerdp* instance, rdpContext* context)
        instance->GatewayAuthenticate = client_cli_gw_authenticate;
        instance->VerifyCertificateEx = client_cli_verify_certificate_ex;
        instance->VerifyChangedCertificateEx = client_cli_verify_changed_certificate_ex;
+       instance->PresentGatewayMessage = client_cli_present_gateway_message;
        instance->LogonErrorInfo = xf_logon_error_info;
        PubSub_SubscribeTerminate(context->pubSub, xf_TerminateEventHandler);
 #ifdef WITH_XRENDER
index 380d7de..8a9c4bd 100644 (file)
@@ -663,6 +663,66 @@ DWORD client_cli_verify_changed_certificate_ex(freerdp* instance, const char* ho
        return client_cli_accept_certificate(instance->settings);
 }
 
+BOOL client_cli_present_gateway_message(freerdp* instance, UINT32 type, BOOL isDisplayMandatory,
+                                        BOOL isConsentMandatory, size_t length,
+                                        const WCHAR* message)
+{
+       char answer;
+       const char* msgType = (type == 1) ? "Consent message" : "Service message";
+
+       if (!isDisplayMandatory && !isConsentMandatory)
+               return TRUE;
+
+       printf("%s:\n", msgType);
+#if defined(WIN32)
+       printf("%.*S\n", (int)length, message);
+#else
+       {
+               LPSTR msg;
+               if (ConvertFromUnicode(CP_UTF8, 0, message, (int)(length / 2), &msg, 0, NULL, NULL) < 1)
+               {
+                       printf("Failed to convert message!\n");
+                       return FALSE;
+               }
+               printf("%s\n", msg);
+               free(msg);
+       }
+#endif
+
+       while (isConsentMandatory)
+       {
+               printf("I understand and agree to the terms of this policy (Y/N) \n");
+               fflush(stdout);
+               answer = fgetc(stdin);
+
+               if (feof(stdin))
+               {
+                       printf("\nError: Could not read answer from stdin.\n");
+                       return FALSE;
+               }
+
+               switch (answer)
+               {
+                       case 'y':
+                       case 'Y':
+                               fgetc(stdin);
+                               return TRUE;
+
+                       case 'n':
+                       case 'N':
+                               fgetc(stdin);
+                               return FALSE;
+
+                       default:
+                               break;
+               }
+
+               printf("\n");
+       }
+
+       return TRUE;
+}
+
 BOOL client_auto_reconnect(freerdp* instance)
 {
        return client_auto_reconnect_ex(instance, NULL);
index 942f550..37e01b0 100644 (file)
@@ -123,6 +123,12 @@ extern "C"
            freerdp* instance, const char* host, UINT16 port, const char* common_name,
            const char* subject, const char* issuer, const char* fingerprint, const char* old_subject,
            const char* old_issuer, const char* old_fingerprint, DWORD flags);
+
+       FREERDP_API BOOL client_cli_present_gateway_message(freerdp* instance, UINT32 type,
+                                                           BOOL isDisplayMandatory,
+                                                           BOOL isConsentMandatory, size_t length,
+                                                           const WCHAR* message);
+
        FREERDP_API BOOL client_auto_reconnect(freerdp* instance);
        FREERDP_API BOOL client_auto_reconnect_ex(freerdp* instance,
                                                  BOOL (*window_events)(freerdp* instance));