Implement gateway message callback for Windows, Wayland and X11 clients

This commit is contained in:
Martin Fleisz 2020-08-03 12:06:08 +02:00
parent 130494e34a
commit 2fe8e762d2
5 changed files with 97 additions and 0 deletions

View 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);

View 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;

View 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

View 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);

View 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));