From 35cb729f317919d94523cdf0be04828d2c1f3ce1 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Fri, 23 Aug 2019 09:57:26 +0200 Subject: [PATCH 1/6] Added drivestoredirect option value parser --- client/common/file.c | 110 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 107 insertions(+), 3 deletions(-) diff --git a/client/common/file.c b/client/common/file.c index a1f0a487e..16a3eea46 100644 --- a/client/common/file.c +++ b/client/common/file.c @@ -44,12 +44,14 @@ #include #include +#include #include #define TAG CLIENT_TAG("common") /*#define DEBUG_CLIENT_FILE 1*/ -static BYTE BOM_UTF16_LE[2] = { 0xFF, 0xFE }; +static const BYTE BOM_UTF16_LE[2] = { 0xFF, 0xFE }; +static const char DynamicDrives[] = "DynamicDrives"; #define INVALID_INTEGER_VALUE 0xFFFFFFFF @@ -1045,6 +1047,62 @@ size_t freerdp_client_write_rdp_file_buffer(const rdpFile* file, char* buffer, s return totalSize; } +static BOOL freerdp_client_add_drive(rdpSettings* settings, const char* path, const char* name) +{ + RDPDR_DRIVE* drive; + + drive = (RDPDR_DRIVE*) calloc(1, sizeof(RDPDR_DRIVE)); + + if (!drive) + return FALSE; + + drive->Type = RDPDR_DTYP_FILESYSTEM; + + if (name) + { + /* Path was entered as secondary argument, swap */ + if (PathFileExistsA(name)) + { + const char* tmp = path; + path = name; + name = tmp; + } + } + + if (name) + { + if (!(drive->Name = _strdup(name))) + goto fail; + } + + if (!path) + goto fail; + else + { + const BOOL isPath = PathFileExistsA(path); + const BOOL isSpecial = (strncmp(path, "*", 2) == 0) || + (strncmp(path, DynamicDrives, sizeof(DynamicDrives)) == 0) || + (strncmp(path, "%", 2) == 0) ? TRUE : FALSE; + + if (isSpecial && name) + goto fail; + + if ((!isPath && !isSpecial) || !(drive->Path = _strdup(path))) + goto fail; + } + + if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) drive)) + goto fail; + + return TRUE; + + fail: + free(drive->Path); + free(drive->Name); + free(drive); + return FALSE; +} + BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings* settings) { if (~((size_t)file->Domain)) @@ -1556,8 +1614,53 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings* */ const BOOL empty = !file->DrivesToRedirect || (strlen(file->DrivesToRedirect) == 0); - if (!freerdp_settings_set_bool(settings, FreeRDP_RedirectDrives, !empty)) - return FALSE; + if (!empty) + { + char* value; + char* tok; + char* context = NULL; + + value = _strdup(file->DrivesToRedirect); + if (!value) + return FALSE; + + tok = strtok_s(value, ";", &context); + if (!tok) + { + free(value); + return FALSE; + } + + while(tok) + { + /* Syntax: Comma seperated list of the following entries: + * '*' ... Redirect all drives, including hotplug + * 'DynamicDrives' ... hotplug + *