From d51e92eb312735ec857e7ede0a202728ae9dcb26 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 29 Jun 2017 15:48:23 -0700 Subject: [PATCH] GUACAMOLE-303: Add "sftp-root-directory" parameter to VNC, RDP, and SSH. --- src/protocols/rdp/rdp.c | 4 ++-- src/protocols/rdp/rdp_settings.c | 13 +++++++++++++ src/protocols/rdp/rdp_settings.h | 6 ++++++ src/protocols/ssh/settings.c | 15 +++++++++++++++ src/protocols/ssh/settings.h | 6 ++++++ src/protocols/ssh/ssh.c | 3 ++- src/protocols/vnc/settings.c | 13 +++++++++++++ src/protocols/vnc/settings.h | 6 ++++++ src/protocols/vnc/vnc.c | 4 ++-- 9 files changed, 65 insertions(+), 5 deletions(-) diff --git a/src/protocols/rdp/rdp.c b/src/protocols/rdp/rdp.c index c1be71e3..0b15d055 100644 --- a/src/protocols/rdp/rdp.c +++ b/src/protocols/rdp/rdp.c @@ -987,8 +987,8 @@ void* guac_rdp_client_thread(void* data) { /* Load and expose filesystem */ rdp_client->sftp_filesystem = - guac_common_ssh_create_sftp_filesystem( - rdp_client->sftp_session, "/", NULL); + guac_common_ssh_create_sftp_filesystem(rdp_client->sftp_session, + settings->sftp_root_directory, NULL); /* Expose filesystem to connection owner */ guac_client_for_owner(client, diff --git a/src/protocols/rdp/rdp_settings.c b/src/protocols/rdp/rdp_settings.c index f73ef9d9..57e60167 100644 --- a/src/protocols/rdp/rdp_settings.c +++ b/src/protocols/rdp/rdp_settings.c @@ -84,6 +84,7 @@ const char* GUAC_RDP_CLIENT_ARGS[] = { "sftp-private-key", "sftp-passphrase", "sftp-directory", + "sftp-root-directory", "sftp-server-alive-interval", #endif @@ -367,6 +368,12 @@ enum RDP_ARGS_IDX { */ IDX_SFTP_DIRECTORY, + /** + * The path of the directory within the SSH server to expose as a + * filesystem guac_object. If omitted, "/" will be used by default. + */ + IDX_SFTP_ROOT_DIRECTORY, + /** * The interval at which SSH keepalive messages are sent to the server for * SFTP connections. The default is 0 (disabling keepalives), and a value @@ -784,6 +791,11 @@ guac_rdp_settings* guac_rdp_parse_args(guac_user* user, guac_user_parse_args_string(user, GUAC_RDP_CLIENT_ARGS, argv, IDX_SFTP_DIRECTORY, NULL); + /* SFTP root directory */ + settings->sftp_root_directory = + guac_user_parse_args_string(user, GUAC_RDP_CLIENT_ARGS, argv, + IDX_SFTP_ROOT_DIRECTORY, "/"); + /* Default keepalive value */ settings->sftp_server_alive_interval = guac_user_parse_args_int(user, GUAC_RDP_CLIENT_ARGS, argv, @@ -909,6 +921,7 @@ void guac_rdp_settings_free(guac_rdp_settings* settings) { #ifdef ENABLE_COMMON_SSH /* Free SFTP settings */ free(settings->sftp_directory); + free(settings->sftp_root_directory); free(settings->sftp_hostname); free(settings->sftp_passphrase); free(settings->sftp_password); diff --git a/src/protocols/rdp/rdp_settings.h b/src/protocols/rdp/rdp_settings.h index 8edb79e4..ec540ef7 100644 --- a/src/protocols/rdp/rdp_settings.h +++ b/src/protocols/rdp/rdp_settings.h @@ -360,6 +360,12 @@ typedef struct guac_rdp_settings { */ char* sftp_directory; + /** + * The path of the directory within the SSH server to expose as a + * filesystem guac_object. + */ + char* sftp_root_directory; + /** * The interval at which SSH keepalive messages are sent to the server for * SFTP connections. The default is 0 (disabling keepalives), and a value diff --git a/src/protocols/ssh/settings.c b/src/protocols/ssh/settings.c index 8843923b..832dcfa9 100644 --- a/src/protocols/ssh/settings.c +++ b/src/protocols/ssh/settings.c @@ -37,6 +37,7 @@ const char* GUAC_SSH_CLIENT_ARGS[] = { "font-name", "font-size", "enable-sftp", + "sftp-root-directory", "private-key", "passphrase", #ifdef ENABLE_SSH_AGENT @@ -92,6 +93,12 @@ enum SSH_ARGS_IDX { */ IDX_ENABLE_SFTP, + /** + * The path of the directory within the SSH server to expose as a + * filesystem guac_object. If omitted, "/" will be used by default. + */ + IDX_SFTP_ROOT_DIRECTORY, + /** * The private key to use for authentication, if any. */ @@ -236,6 +243,11 @@ guac_ssh_settings* guac_ssh_parse_args(guac_user* user, guac_user_parse_args_boolean(user, GUAC_SSH_CLIENT_ARGS, argv, IDX_ENABLE_SFTP, false); + /* SFTP root directory */ + settings->sftp_root_directory = + guac_user_parse_args_string(user, GUAC_SSH_CLIENT_ARGS, argv, + IDX_SFTP_ROOT_DIRECTORY, "/"); + #ifdef ENABLE_SSH_AGENT settings->enable_agent = guac_user_parse_args_boolean(user, GUAC_SSH_CLIENT_ARGS, argv, @@ -316,6 +328,9 @@ void guac_ssh_settings_free(guac_ssh_settings* settings) { /* Free requested command */ free(settings->command); + /* Free SFTP settings */ + free(settings->sftp_root_directory); + /* Free typescript settings */ free(settings->typescript_name); free(settings->typescript_path); diff --git a/src/protocols/ssh/settings.h b/src/protocols/ssh/settings.h index f49d054d..f0930236 100644 --- a/src/protocols/ssh/settings.h +++ b/src/protocols/ssh/settings.h @@ -145,6 +145,12 @@ typedef struct guac_ssh_settings { */ bool enable_sftp; + /** + * The path of the directory within the SSH server to expose as a + * filesystem guac_object. + */ + char* sftp_root_directory; + #ifdef ENABLE_SSH_AGENT /** * Whether the SSH agent is enabled. diff --git a/src/protocols/ssh/ssh.c b/src/protocols/ssh/ssh.c index 18a0dcbe..b9bb59b3 100644 --- a/src/protocols/ssh/ssh.c +++ b/src/protocols/ssh/ssh.c @@ -266,7 +266,8 @@ void* ssh_client_thread(void* data) { /* Request SFTP */ ssh_client->sftp_filesystem = guac_common_ssh_create_sftp_filesystem( - ssh_client->sftp_session, "/", NULL); + ssh_client->sftp_session, settings->sftp_root_directory, + NULL); /* Expose filesystem to connection owner */ guac_client_for_owner(client, diff --git a/src/protocols/vnc/settings.c b/src/protocols/vnc/settings.c index 697466df..0bcd5abf 100644 --- a/src/protocols/vnc/settings.c +++ b/src/protocols/vnc/settings.c @@ -66,6 +66,7 @@ const char* GUAC_VNC_CLIENT_ARGS[] = { "sftp-private-key", "sftp-passphrase", "sftp-directory", + "sftp-root-directory", "sftp-server-alive-interval", #endif @@ -229,6 +230,12 @@ enum VNC_ARGS_IDX { */ IDX_SFTP_DIRECTORY, + /** + * The path of the directory within the SSH server to expose as a + * filesystem guac_object. If omitted, "/" will be used by default. + */ + IDX_SFTP_ROOT_DIRECTORY, + /** * The interval at which SSH keepalive messages are sent to the server for * SFTP connections. The default is 0 (disabling keepalives), and a value @@ -405,6 +412,11 @@ guac_vnc_settings* guac_vnc_parse_args(guac_user* user, guac_user_parse_args_string(user, GUAC_VNC_CLIENT_ARGS, argv, IDX_SFTP_DIRECTORY, NULL); + /* SFTP root directory */ + settings->sftp_root_directory = + guac_user_parse_args_string(user, GUAC_VNC_CLIENT_ARGS, argv, + IDX_SFTP_ROOT_DIRECTORY, "/"); + /* Default keepalive value */ settings->sftp_server_alive_interval = guac_user_parse_args_int(user, GUAC_VNC_CLIENT_ARGS, argv, @@ -447,6 +459,7 @@ void guac_vnc_settings_free(guac_vnc_settings* settings) { #ifdef ENABLE_COMMON_SSH /* Free SFTP settings */ free(settings->sftp_directory); + free(settings->sftp_root_directory); free(settings->sftp_hostname); free(settings->sftp_passphrase); free(settings->sftp_password); diff --git a/src/protocols/vnc/settings.h b/src/protocols/vnc/settings.h index 3c7b2587..4fa8eb4f 100644 --- a/src/protocols/vnc/settings.h +++ b/src/protocols/vnc/settings.h @@ -174,6 +174,12 @@ typedef struct guac_vnc_settings { */ char* sftp_directory; + /** + * The path of the directory within the SSH server to expose as a + * filesystem guac_object. + */ + char* sftp_root_directory; + /** * The interval at which SSH keepalive messages are sent to the server for * SFTP connections. The default is 0 (disabling keepalives), and a value diff --git a/src/protocols/vnc/vnc.c b/src/protocols/vnc/vnc.c index 2b7263a8..38c7cd60 100644 --- a/src/protocols/vnc/vnc.c +++ b/src/protocols/vnc/vnc.c @@ -271,8 +271,8 @@ void* guac_vnc_client_thread(void* data) { /* Load filesystem */ vnc_client->sftp_filesystem = - guac_common_ssh_create_sftp_filesystem( - vnc_client->sftp_session, "/", NULL); + guac_common_ssh_create_sftp_filesystem(vnc_client->sftp_session, + settings->sftp_root_directory, NULL); /* Expose filesystem to connection owner */ guac_client_for_owner(client,