diff --git a/src/protocols/rdp/client.c b/src/protocols/rdp/client.c index a2665c7b..e7a8f58c 100644 --- a/src/protocols/rdp/client.c +++ b/src/protocols/rdp/client.c @@ -111,6 +111,7 @@ const char* GUAC_CLIENT_ARGS[] = { "enable-printing", "enable-drive", "drive-path", + "create-drive-path", "console", "console-audio", "server-layout", @@ -158,6 +159,7 @@ enum RDP_ARGS_IDX { IDX_ENABLE_PRINTING, IDX_ENABLE_DRIVE, IDX_DRIVE_PATH, + IDX_CREATE_DRIVE_PATH, IDX_CONSOLE, IDX_CONSOLE_AUDIO, IDX_SERVER_LAYOUT, @@ -303,7 +305,8 @@ BOOL rdp_freerdp_pre_connect(freerdp* instance) { /* Load filesystem if drive enabled */ if (guac_client_data->settings.drive_enabled) { guac_client_data->filesystem = - guac_rdp_fs_alloc(client, guac_client_data->settings.drive_path); + guac_rdp_fs_alloc(client, guac_client_data->settings.drive_path, + guac_client_data->settings.create_drive_path); client->file_handler = guac_rdp_upload_file_handler; } @@ -773,6 +776,9 @@ int guac_client_init(guac_client* client, int argc, char** argv) { guac_client_data->settings.drive_path = strdup(argv[IDX_DRIVE_PATH]); + guac_client_data->settings.create_drive_path = + (strcmp(argv[IDX_CREATE_DRIVE_PATH], "true") == 0); + /* Store client data */ guac_client_data->rdp_inst = rdp_inst; guac_client_data->mouse_button_mask = 0; diff --git a/src/protocols/rdp/rdp_fs.c b/src/protocols/rdp/rdp_fs.c index 6a31a95d..025ee883 100644 --- a/src/protocols/rdp/rdp_fs.c +++ b/src/protocols/rdp/rdp_fs.c @@ -40,7 +40,22 @@ #include #include -guac_rdp_fs* guac_rdp_fs_alloc(guac_client* client, const char* drive_path) { +guac_rdp_fs* guac_rdp_fs_alloc(guac_client* client, const char* drive_path, int create_drive_path) { + + /* Create drive path if it does not exist */ + if (create_drive_path) { + guac_client_log(client, GUAC_LOG_DEBUG, + "%s: Creating directory \"%s\".", + __func__, drive_path); + + if (mkdir(drive_path, S_IRWXU)) { + if (errno != EEXIST) { + guac_client_log(client, GUAC_LOG_DEBUG, + "%s: mkdir() failed: %s", + __func__, strerror(errno)); + } + } + } guac_rdp_fs* fs = malloc(sizeof(guac_rdp_fs)); diff --git a/src/protocols/rdp/rdp_fs.h b/src/protocols/rdp/rdp_fs.h index 7981f8cb..48cf6eab 100644 --- a/src/protocols/rdp/rdp_fs.h +++ b/src/protocols/rdp/rdp_fs.h @@ -325,7 +325,7 @@ typedef struct guac_rdp_fs_info { /** * Allocates a new filesystem given a root path. */ -guac_rdp_fs* guac_rdp_fs_alloc(guac_client* client, const char* drive_path); +guac_rdp_fs* guac_rdp_fs_alloc(guac_client* client, const char* drive_path, int create_drive_path); /** * Frees the given filesystem. diff --git a/src/protocols/rdp/rdp_settings.h b/src/protocols/rdp/rdp_settings.h index b87e1cdf..e77db5a0 100644 --- a/src/protocols/rdp/rdp_settings.h +++ b/src/protocols/rdp/rdp_settings.h @@ -155,6 +155,11 @@ typedef struct guac_rdp_settings { */ char* drive_path; + /** + * Whether to automatically create the local system path if it does not exist. + */ + int create_drive_path; + /** * Whether this session is a console session. */