client/X11: Relieve CLIPRDR filename restriction when possible

Microsoft Windows imposes strict filename restrictions on its platform.
As RDP is developed by Microsoft and the RDS in MS Windows is typically
used as remote desktop server for the RDP protocol, these filename
restrictions are also enforced in WinPR, when copy-pasting files over
the clipboard.
However, in some connections no peer on MS Windows is involved and in
these situations, these filename restrictions are just an annoyance.

With a recent API addition in WinPR, it is now possible to override the
callback, where the filename is checked, whether it is valid.
So, use this new API to relieve the filename restriction, when the
connected remote desktop server is not on MS Windows.
This commit is contained in:
Pascal Nowack 2022-07-06 13:46:39 +02:00 committed by akallabeth
parent 5f9c519f03
commit 28d968a4d6
4 changed files with 43 additions and 23 deletions

View File

@ -1254,6 +1254,7 @@ static BOOL xf_post_connect(freerdp* instance)
context = instance->context; context = instance->context;
settings = instance->settings; settings = instance->settings;
update = context->update; update = context->update;
BOOL serverIsWindowsPlatform;
if (!gdi_init(instance, xf_get_local_color_format(xfc, TRUE))) if (!gdi_init(instance, xf_get_local_color_format(xfc, TRUE)))
return FALSE; return FALSE;
@ -1323,7 +1324,8 @@ static BOOL xf_post_connect(freerdp* instance)
update->SetKeyboardIndicators = xf_keyboard_set_indicators; update->SetKeyboardIndicators = xf_keyboard_set_indicators;
update->SetKeyboardImeStatus = xf_keyboard_set_ime_status; update->SetKeyboardImeStatus = xf_keyboard_set_ime_status;
if (!(xfc->clipboard = xf_clipboard_new(xfc))) serverIsWindowsPlatform = (settings->OsMajorType == OSMAJORTYPE_WINDOWS);
if (!(xfc->clipboard = xf_clipboard_new(xfc, !serverIsWindowsPlatform)))
return FALSE; return FALSE;
if (!(xfc->xfDisp = xf_disp_new(xfc))) if (!(xfc->xfDisp = xf_disp_new(xfc)))

View File

@ -1756,7 +1756,27 @@ static UINT xf_cliprdr_clipboard_file_range_failure(wClipboardDelegate* delegate
return clipboard->context->ClientFileContentsResponse(clipboard->context, &response); return clipboard->context->ClientFileContentsResponse(clipboard->context, &response);
} }
xfClipboard* xf_clipboard_new(xfContext* xfc) static BOOL xf_cliprdr_clipboard_is_valid_unix_filename(LPCWSTR filename)
{
LPCWSTR c;
if (!filename)
return FALSE;
if (filename[0] == L'\0')
return FALSE;
/* Reserved characters */
for (c = filename; *c; ++c)
{
if (*c == L'/')
return FALSE;
}
return TRUE;
}
xfClipboard* xf_clipboard_new(xfContext* xfc, BOOL relieveFilenameRestriction)
{ {
int i, n = 0; int i, n = 0;
rdpChannels* channels; rdpChannels* channels;
@ -1885,6 +1905,13 @@ xfClipboard* xf_clipboard_new(xfContext* xfc)
clipboard->delegate->ClipboardFileSizeFailure = xf_cliprdr_clipboard_file_size_failure; clipboard->delegate->ClipboardFileSizeFailure = xf_cliprdr_clipboard_file_size_failure;
clipboard->delegate->ClipboardFileRangeSuccess = xf_cliprdr_clipboard_file_range_success; clipboard->delegate->ClipboardFileRangeSuccess = xf_cliprdr_clipboard_file_range_success;
clipboard->delegate->ClipboardFileRangeFailure = xf_cliprdr_clipboard_file_range_failure; clipboard->delegate->ClipboardFileRangeFailure = xf_cliprdr_clipboard_file_range_failure;
if (relieveFilenameRestriction)
{
WLog_DBG(TAG, "Relieving CLIPRDR filename restriction");
clipboard->delegate->IsFileNameComponentValid = xf_cliprdr_clipboard_is_valid_unix_filename;
}
return clipboard; return clipboard;
error: error:

View File

@ -25,7 +25,7 @@
#include <freerdp/client/cliprdr.h> #include <freerdp/client/cliprdr.h>
xfClipboard* xf_clipboard_new(xfContext* xfc); xfClipboard* xf_clipboard_new(xfContext* xfc, BOOL relieveFilenameRestriction);
void xf_clipboard_free(xfClipboard* clipboard); void xf_clipboard_free(xfClipboard* clipboard);
void xf_cliprdr_init(xfContext* xfc, CliprdrClientContext* cliprdr); void xf_cliprdr_init(xfContext* xfc, CliprdrClientContext* cliprdr);

View File

@ -162,26 +162,17 @@ static BOOL rdp_read_general_capability_set(wStream* s, rdpSettings* settings)
if (Stream_GetRemainingLength(s) < 20) if (Stream_GetRemainingLength(s) < 20)
return FALSE; return FALSE;
if (settings->ServerMode) Stream_Read_UINT16(s, settings->OsMajorType); /* osMajorType (2 bytes) */
{ Stream_Read_UINT16(s, settings->OsMinorType); /* osMinorType (2 bytes) */
Stream_Read_UINT16(s, settings->OsMajorType); /* osMajorType (2 bytes) */ Stream_Seek_UINT16(s); /* protocolVersion (2 bytes) */
Stream_Read_UINT16(s, settings->OsMinorType); /* osMinorType (2 bytes) */ Stream_Seek_UINT16(s); /* pad2OctetsA (2 bytes) */
} Stream_Seek_UINT16(s); /* generalCompressionTypes (2 bytes) */
else Stream_Read_UINT16(s, extraFlags); /* extraFlags (2 bytes) */
{ Stream_Seek_UINT16(s); /* updateCapabilityFlag (2 bytes) */
Stream_Seek_UINT16(s); /* osMajorType (2 bytes) */ Stream_Seek_UINT16(s); /* remoteUnshareFlag (2 bytes) */
Stream_Seek_UINT16(s); /* osMinorType (2 bytes) */ Stream_Seek_UINT16(s); /* generalCompressionLevel (2 bytes) */
} Stream_Read_UINT8(s, refreshRectSupport); /* refreshRectSupport (1 byte) */
Stream_Read_UINT8(s, suppressOutputSupport); /* suppressOutputSupport (1 byte) */
Stream_Seek_UINT16(s); /* protocolVersion (2 bytes) */
Stream_Seek_UINT16(s); /* pad2OctetsA (2 bytes) */
Stream_Seek_UINT16(s); /* generalCompressionTypes (2 bytes) */
Stream_Read_UINT16(s, extraFlags); /* extraFlags (2 bytes) */
Stream_Seek_UINT16(s); /* updateCapabilityFlag (2 bytes) */
Stream_Seek_UINT16(s); /* remoteUnshareFlag (2 bytes) */
Stream_Seek_UINT16(s); /* generalCompressionLevel (2 bytes) */
Stream_Read_UINT8(s, refreshRectSupport); /* refreshRectSupport (1 byte) */
Stream_Read_UINT8(s, suppressOutputSupport); /* suppressOutputSupport (1 byte) */
settings->NoBitmapCompressionHeader = (extraFlags & NO_BITMAP_COMPRESSION_HDR) ? TRUE : FALSE; settings->NoBitmapCompressionHeader = (extraFlags & NO_BITMAP_COMPRESSION_HDR) ? TRUE : FALSE;
settings->LongCredentialsSupported = (extraFlags & LONG_CREDENTIALS_SUPPORTED) ? TRUE : FALSE; settings->LongCredentialsSupported = (extraFlags & LONG_CREDENTIALS_SUPPORTED) ? TRUE : FALSE;