Fix #7793: Do not expose internal input API (#7794)

* Fixed GetFileInformationByHandle initializers

* Fix #7793: Do not expose internal input API

Slow-Path input uses UINT16 for scancodes on wire, but only the
lower byte is actually used. (the extended fields are sent in
keyboardFlags field)
Hide this implementation detail and adjust the API to use UINT8
for the code instead just like the corresponding Fast-Path PDU

* Added a warning for problematic slow path keyCodes
This commit is contained in:
akallabeth 2022-04-13 09:34:05 +02:00 committed by GitHub
parent a152dec687
commit 752ac3b479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 142 additions and 91 deletions

View File

@ -96,14 +96,15 @@ static BOOL android_process_event(ANDROID_EVENT_QUEUE* queue, freerdp* inst)
if (event->type == EVENT_TYPE_KEY)
{
ANDROID_EVENT_KEY* key_event = (ANDROID_EVENT_KEY*)event;
context->input->KeyboardEvent(context->input, key_event->flags, key_event->scancode);
freerdp_input_send_keyboard_event(context->input, key_event->flags,
key_event->scancode);
android_event_free((ANDROID_EVENT*)key_event);
}
else if (event->type == EVENT_TYPE_KEY_UNICODE)
{
ANDROID_EVENT_KEY* key_event = (ANDROID_EVENT_KEY*)event;
context->input->UnicodeKeyboardEvent(context->input, key_event->flags,
key_event->scancode);
freerdp_input_send_keyboard_event(context->input, key_event->flags,
key_event->scancode);
android_event_free((ANDROID_EVENT*)key_event);
}
else if (event->type == EVENT_TYPE_CURSOR)

View File

@ -61,11 +61,11 @@ static BOOL ios_events_handle_event(mfInfo *mfi, NSDictionary *event_description
else if ([event_type isEqualToString:@"keyboard"])
{
if ([[event_description objectForKey:@"subtype"] isEqualToString:@"scancode"])
instance->input->KeyboardEvent(
freerdp_input_send_keyboard_event(
instance->input, [[event_description objectForKey:@"flags"] unsignedShortValue],
[[event_description objectForKey:@"scancode"] unsignedShortValue]);
else if ([[event_description objectForKey:@"subtype"] isEqualToString:@"unicode"])
instance->input->UnicodeKeyboardEvent(
freerdp_input_send_unicode_keyboard_event(
instance->input, [[event_description objectForKey:@"flags"] unsignedShortValue],
[[event_description objectForKey:@"unicode_char"] unsignedShortValue]);
else

View File

@ -65,7 +65,7 @@ typedef struct rdp_input_proxy rdpInputProxy;
/* Input Interface */
typedef BOOL (*pSynchronizeEvent)(rdpInput* input, UINT32 flags);
typedef BOOL (*pKeyboardEvent)(rdpInput* input, UINT16 flags, UINT16 code);
typedef BOOL (*pKeyboardEvent)(rdpInput* input, UINT16 flags, UINT8 code);
typedef BOOL (*pUnicodeKeyboardEvent)(rdpInput* input, UINT16 flags, UINT16 code);
typedef BOOL (*pMouseEvent)(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
typedef BOOL (*pExtendedMouseEvent)(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
@ -95,7 +95,7 @@ extern "C"
#endif
FREERDP_API BOOL freerdp_input_send_synchronize_event(rdpInput* input, UINT32 flags);
FREERDP_API BOOL freerdp_input_send_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code);
FREERDP_API BOOL freerdp_input_send_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code);
FREERDP_API BOOL freerdp_input_send_keyboard_event_ex(rdpInput* input, BOOL down,
UINT32 rdp_scancode);
FREERDP_API BOOL freerdp_input_send_keyboard_pause_event(rdpInput* input);

View File

@ -75,7 +75,7 @@ typedef BOOL (*pfnShadowClientCapabilities)(rdpShadowSubsystem* subsystem, rdpSh
typedef BOOL (*pfnShadowSynchronizeEvent)(rdpShadowSubsystem* subsystem, rdpShadowClient* client,
UINT32 flags);
typedef BOOL (*pfnShadowKeyboardEvent)(rdpShadowSubsystem* subsystem, rdpShadowClient* client,
UINT16 flags, UINT16 code);
UINT16 flags, UINT8 code);
typedef BOOL (*pfnShadowUnicodeKeyboardEvent)(rdpShadowSubsystem* subsystem,
rdpShadowClient* client, UINT16 flags, UINT16 code);
typedef BOOL (*pfnShadowMouseEvent)(rdpShadowSubsystem* subsystem, rdpShadowClient* client,

View File

@ -674,7 +674,7 @@ static BOOL fastpath_recv_input_event_scancode(rdpFastPath* fastpath, wStream* s
{
rdpInput* input;
UINT16 flags;
UINT16 code;
UINT8 code;
if (!fastpath || !fastpath->rdp || !fastpath->rdp->input || !s)
return FALSE;

View File

@ -38,11 +38,9 @@
#define INPUT_EVENT_MOUSE 0x8001
#define INPUT_EVENT_MOUSEX 0x8002
#define RDP_CLIENT_INPUT_PDU_HEADER_LENGTH 4
static void rdp_write_client_input_pdu_header(wStream* s, UINT16 number)
{
Stream_Write_UINT16(s, 1); /* numberEvents (2 bytes) */
Stream_Write_UINT16(s, number); /* numberEvents (2 bytes) */
Stream_Write_UINT16(s, 0); /* pad2Octets (2 bytes) */
}
@ -67,6 +65,8 @@ static wStream* rdp_client_input_pdu_init(rdpRdp* rdp, UINT16 type)
static BOOL rdp_send_client_input_pdu(rdpRdp* rdp, wStream* s)
{
WINPR_ASSERT(rdp);
WINPR_ASSERT(rdp->mcs);
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_INPUT, rdp->mcs->userId);
}
@ -96,12 +96,15 @@ static BOOL input_send_synchronize_event(rdpInput* input, UINT32 flags)
static void input_write_keyboard_event(wStream* s, UINT16 flags, UINT16 code)
{
WINPR_ASSERT(s);
WINPR_ASSERT(code <= UINT8_MAX);
Stream_Write_UINT16(s, flags); /* keyboardFlags (2 bytes) */
Stream_Write_UINT16(s, code); /* keyCode (2 bytes) */
Stream_Write_UINT16(s, 0); /* pad2Octets (2 bytes) */
}
static BOOL input_send_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
static BOOL input_send_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
{
wStream* s;
rdpRdp* rdp;
@ -280,7 +283,7 @@ static BOOL input_send_fastpath_synchronize_event(rdpInput* input, UINT32 flags)
return fastpath_send_input_pdu(rdp->fastpath, s);
}
static BOOL input_send_fastpath_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
static BOOL input_send_fastpath_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
{
wStream* s;
BYTE eventFlags = 0;
@ -494,7 +497,13 @@ static BOOL input_recv_keyboard_event(rdpInput* input, wStream* s)
else
keyboardFlags |= KBD_FLAGS_DOWN;
return IFCALLRESULT(TRUE, input->KeyboardEvent, input, keyboardFlags, keyCode);
if (keyCode & 0xFF00)
WLog_WARN(TAG,
"Problematic [MS-RDPBCGR] 2.2.8.1.1.3.1.1.1 Keyboard Event (TS_KEYBOARD_EVENT) "
"keyCode=0x%04" PRIx16
", high byte values should be sent in keyboardFlags field, ignoring.",
keyCode);
return IFCALLRESULT(TRUE, input->KeyboardEvent, input, keyboardFlags, keyCode & 0xFF);
}
static BOOL input_recv_unicode_keyboard_event(rdpInput* input, wStream* s)
@ -625,7 +634,6 @@ BOOL input_recv(rdpInput* input, wStream* s)
BOOL input_register_client_callbacks(rdpInput* input)
{
rdpSettings* settings;
rdp_input_internal* in = input_cast(input);
if (!input->context)
return FALSE;
@ -670,7 +678,7 @@ BOOL freerdp_input_send_synchronize_event(rdpInput* input, UINT32 flags)
return IFCALLRESULT(TRUE, input->SynchronizeEvent, input, flags);
}
BOOL freerdp_input_send_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
BOOL freerdp_input_send_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
{
if (!input || !input->context)
return FALSE;

View File

@ -2967,7 +2967,7 @@ static int input_message_process_input_class(rdpInputProxy* proxy, wMessage* msg
case Input_KeyboardEvent:
IFCALL(proxy->KeyboardEvent, msg->context, (UINT16)(size_t)msg->wParam,
(UINT16)(size_t)msg->lParam);
(UINT8)(size_t)msg->lParam);
break;
case Input_UnicodeKeyboardEvent:

View File

@ -329,13 +329,11 @@ static BOOL mf_peer_synchronize_event(rdpInput* input, UINT32 flags)
return TRUE;
}
void mf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
void mf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
{
UINT16 down = 0x4000;
// UINT16 up = 0x8000;
bool state_down = FALSE;
if (flags == down)
if (flags == KBD_FLAGS_DOWN)
{
state_down = TRUE;
}

View File

@ -761,7 +761,7 @@ static BOOL tf_peer_synchronize_event(rdpInput* input, UINT32 flags)
return TRUE;
}
static BOOL tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
static BOOL tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
{
freerdp_peer* client;
rdpUpdate* update;
@ -786,10 +786,10 @@ static BOOL tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
tcontext = (testPeerContext*)context;
WINPR_ASSERT(tcontext);
WLog_DBG(TAG, "Client sent a keyboard event (flags:0x%04" PRIX16 " code:0x%04" PRIX16 ")",
flags, code);
WLog_DBG(TAG, "Client sent a keyboard event (flags:0x%04" PRIX16 " code:0x%04" PRIX8 ")", flags,
code);
if ((flags & 0x4000) && code == 0x22) /* 'g' key */
if ((flags & KBD_FLAGS_DOWN) && (code == RDP_SCANCODE_KEY_G)) /* 'g' key */
{
if (settings->DesktopWidth != 800)
{
@ -810,7 +810,7 @@ static BOOL tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
update->DesktopResize(update->context);
tcontext->activated = FALSE;
}
else if ((flags & 0x4000) && code == RDP_SCANCODE_KEY_C) /* 'c' key */
else if ((flags & KBD_FLAGS_DOWN) && code == RDP_SCANCODE_KEY_C) /* 'c' key */
{
if (tcontext->debug_channel)
{
@ -818,22 +818,22 @@ static BOOL tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
WTSVirtualChannelWrite(tcontext->debug_channel, (PCHAR) "test2", 5, &written);
}
}
else if ((flags & 0x4000) && code == RDP_SCANCODE_KEY_X) /* 'x' key */
else if ((flags & KBD_FLAGS_DOWN) && code == RDP_SCANCODE_KEY_X) /* 'x' key */
{
WINPR_ASSERT(client->Close);
client->Close(client);
}
else if ((flags & 0x4000) && code == RDP_SCANCODE_KEY_R) /* 'r' key */
else if ((flags & KBD_FLAGS_DOWN) && code == RDP_SCANCODE_KEY_R) /* 'r' key */
{
tcontext->audin_open = !tcontext->audin_open;
}
#if defined(CHANNEL_AINPUT_SERVER)
else if ((flags & 0x4000) && code == RDP_SCANCODE_KEY_I) /* 'i' key */
else if ((flags & KBD_FLAGS_DOWN) && code == RDP_SCANCODE_KEY_I) /* 'i' key */
{
tcontext->ainput_open = !tcontext->ainput_open;
}
#endif
else if ((flags & 0x4000) && code == RDP_SCANCODE_KEY_S) /* 's' key */
else if ((flags & KBD_FLAGS_DOWN) && code == RDP_SCANCODE_KEY_S) /* 's' key */
{
}

View File

@ -24,7 +24,7 @@
#include "wf_input.h"
#include "wf_info.h"
BOOL wf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
BOOL wf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
{
INPUT keyboard_event;
WINPR_UNUSED(input);
@ -188,7 +188,7 @@ BOOL wf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT1
return TRUE;
}
BOOL wf_peer_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code)
BOOL wf_peer_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT8 code)
{
WINPR_UNUSED(input);
WINPR_UNUSED(flags);

View File

@ -22,13 +22,13 @@
#include "wf_interface.h"
BOOL wf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code);
BOOL wf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code);
BOOL wf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code);
BOOL wf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
BOOL wf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
// dummy versions
BOOL wf_peer_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code);
BOOL wf_peer_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT8 code);
BOOL wf_peer_unicode_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code);
BOOL wf_peer_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
BOOL wf_peer_extended_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);

View File

@ -62,7 +62,7 @@ static BOOL pf_server_synchronize_event(rdpInput* input, UINT32 flags)
return TRUE;
}
static BOOL pf_server_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
static BOOL pf_server_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
{
const proxyConfig* config;
proxyKeyboardEventInfo event;

View File

@ -41,7 +41,7 @@ static BOOL mac_shadow_input_synchronize_event(rdpShadowSubsystem* subsystem,
}
static BOOL mac_shadow_input_keyboard_event(rdpShadowSubsystem* subsystem, rdpShadowClient* client,
UINT16 flags, UINT16 code)
UINT16 flags, UINT8 code)
{
DWORD vkcode;
DWORD keycode;

View File

@ -45,7 +45,7 @@ static BOOL win_shadow_input_synchronize_event(rdpShadowSubsystem* subsystem,
}
static BOOL win_shadow_input_keyboard_event(rdpShadowSubsystem* subsystem, rdpShadowClient* client,
UINT16 flags, UINT16 code)
UINT16 flags, UINT8 code)
{
UINT rc;
INPUT event;

View File

@ -206,7 +206,7 @@ static BOOL x11_shadow_input_synchronize_event(rdpShadowSubsystem* subsystem,
}
static BOOL x11_shadow_input_keyboard_event(rdpShadowSubsystem* subsystem, rdpShadowClient* client,
UINT16 flags, UINT16 code)
UINT16 flags, UINT8 code)
{
#ifdef WITH_XTEST
x11ShadowSubsystem* x11 = (x11ShadowSubsystem*)subsystem;

View File

@ -31,7 +31,7 @@ static BOOL shadow_input_synchronize_event(rdpInput* input, UINT32 flags)
return IFCALLRESULT(TRUE, subsystem->SynchronizeEvent, subsystem, client, flags);
}
static BOOL shadow_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
static BOOL shadow_input_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
{
rdpShadowClient* client = (rdpShadowClient*)input->context;
rdpShadowSubsystem* subsystem = client->server->subsystem;

View File

@ -1177,7 +1177,8 @@ static HANDLE_OPS ops = { CommIsHandled, CommCloseHandle,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL };
NULL, NULL,
NULL };
/**
* http://msdn.microsoft.com/en-us/library/windows/desktop/aa363198%28v=vs.85%29.aspx

View File

@ -73,6 +73,7 @@ static HANDLE_OPS ops = { NoneHandleIsHandle,
NULL,
NULL,
NULL,
NULL,
NULL };
HANDLE CreateNoneHandle()

View File

@ -598,7 +598,7 @@ DWORD GetVirtualKeyCodeFromKeycode(DWORD keycode, DWORD dwFlags)
DWORD GetKeycodeFromVirtualKeyCode(DWORD vkcode, DWORD dwFlags)
{
int index;
DWORD index;
DWORD keycode = 0;
if (dwFlags & KEYCODE_TYPE_APPLE)

View File

@ -133,7 +133,7 @@ DWORD GetVirtualKeyCodeFromVirtualScanCode(DWORD scancode, DWORD dwKeyboardType)
DWORD GetVirtualScanCodeFromVirtualKeyCode(DWORD vkcode, DWORD dwKeyboardType)
{
size_t i;
DWORD i;
DWORD scancode;
DWORD codeIndex;

View File

@ -184,24 +184,28 @@ static BOOL PipeWrite(PVOID Object, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrit
return TRUE;
}
static HANDLE_OPS ops = {
PipeIsHandled, PipeCloseHandle,
PipeGetFd, NULL, /* CleanupHandle */
PipeRead, NULL, /* FileReadEx */
NULL, /* FileReadScatter */
PipeWrite, NULL, /* FileWriteEx */
NULL, /* FileWriteGather */
NULL, /* FileGetFileSize */
NULL, /* FlushFileBuffers */
NULL, /* FileSetEndOfFile */
NULL, /* FileSetFilePointer */
NULL, /* SetFilePointerEx */
NULL, /* FileLockFile */
NULL, /* FileLockFileEx */
NULL, /* FileUnlockFile */
NULL, /* FileUnlockFileEx */
NULL /* SetFileTime */
};
static HANDLE_OPS ops = { PipeIsHandled,
PipeCloseHandle,
PipeGetFd,
NULL, /* CleanupHandle */
PipeRead,
NULL, /* FileReadEx */
NULL, /* FileReadScatter */
PipeWrite,
NULL, /* FileWriteEx */
NULL, /* FileWriteGather */
NULL, /* FileGetFileSize */
NULL, /* FlushFileBuffers */
NULL, /* FileSetEndOfFile */
NULL, /* FileSetFilePointer */
NULL, /* SetFilePointerEx */
NULL, /* FileLockFile */
NULL, /* FileLockFileEx */
NULL, /* FileUnlockFile */
NULL, /* FileUnlockFileEx */
NULL /* SetFileTime */
,
NULL };
static BOOL NamedPipeIsHandled(HANDLE handle)
{
@ -457,6 +461,7 @@ static HANDLE_OPS namedOps = { NamedPipeIsHandled,
NULL,
NULL,
NULL,
NULL,
NULL };
static BOOL InitWinPRPipeModule()

View File

@ -133,6 +133,7 @@ static HANDLE_OPS ops = { LogonUserIsHandled,
NULL,
NULL,
NULL,
NULL,
NULL };
BOOL LogonUserA(LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword, DWORD dwLogonType,

View File

@ -245,16 +245,27 @@ static BOOL EventCloseHandle(HANDLE handle)
return EventCloseHandle_(event);
}
static HANDLE_OPS ops = { EventIsHandled, EventCloseHandle,
EventGetFd, NULL, /* CleanupHandle */
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL };
static HANDLE_OPS ops = { EventIsHandled,
EventCloseHandle,
EventGetFd,
NULL, /* CleanupHandle */
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL };
HANDLE CreateEventW(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState,
LPCWSTR lpName)

View File

@ -103,16 +103,27 @@ BOOL MutexCloseHandle(HANDLE handle)
return TRUE;
}
static HANDLE_OPS ops = { MutexIsHandled, MutexCloseHandle,
MutexGetFd, NULL, /* CleanupHandle */
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL };
static HANDLE_OPS ops = { MutexIsHandled,
MutexCloseHandle,
MutexGetFd,
NULL, /* CleanupHandle */
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL };
HANDLE CreateMutexW(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner, LPCWSTR lpName)
{

View File

@ -129,6 +129,7 @@ static HANDLE_OPS ops = { SemaphoreIsHandled,
NULL,
NULL,
NULL,
NULL,
NULL };
HANDLE CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount,

View File

@ -300,16 +300,27 @@ static BOOL timer_drain_fd(int fd)
return ret >= 0;
}
static HANDLE_OPS ops = { TimerIsHandled, TimerCloseHandle,
TimerGetFd, TimerCleanupHandle,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL };
static HANDLE_OPS ops = { TimerIsHandled,
TimerCloseHandle,
TimerGetFd,
TimerCleanupHandle,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL };
/**
* Waitable Timer

View File

@ -526,6 +526,7 @@ static HANDLE_OPS ops = { ProcessHandleIsHandle,
NULL,
NULL,
NULL,
NULL,
NULL };
HANDLE CreateProcessHandle(pid_t pid)

View File

@ -177,6 +177,7 @@ static HANDLE_OPS ops = { ThreadIsHandled,
NULL,
NULL,
NULL,
NULL,
NULL };
static void dump_thread(WINPR_THREAD* thread)