From ffdc98d024e658dc868c6ba52e250e64dc25c6f1 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Tue, 10 Apr 2018 21:31:50 -0400 Subject: [PATCH 01/11] GUACAMOLE-422: Support timezone redirection in RDP via TZ variable. --- src/protocols/rdp/rdp_settings.c | 15 +++++++++++++++ src/protocols/rdp/rdp_settings.h | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/src/protocols/rdp/rdp_settings.c b/src/protocols/rdp/rdp_settings.c index a3bd3482..21114d44 100644 --- a/src/protocols/rdp/rdp_settings.c +++ b/src/protocols/rdp/rdp_settings.c @@ -79,6 +79,7 @@ const char* GUAC_RDP_CLIENT_ARGS[] = { "disable-glyph-caching", "preconnection-id", "preconnection-blob", + "timezone", #ifdef ENABLE_COMMON_SSH "enable-sftp", @@ -356,6 +357,11 @@ enum RDP_ARGS_IDX { */ IDX_PRECONNECTION_BLOB, + /** + * The timezone to pass through to the RDP connection. + */ + IDX_TIMEZONE, + #ifdef ENABLE_COMMON_SSH /** * "true" if SFTP should be enabled for the RDP connection, "false" or @@ -840,6 +846,11 @@ guac_rdp_settings* guac_rdp_parse_args(guac_user* user, if (settings->server_layout == NULL) settings->server_layout = guac_rdp_keymap_find(GUAC_DEFAULT_KEYMAP); + /* Timezone if provied by client */ + settings->timezone = + guac_user_parse_args_string(user, GUAC_RDP_CLIENT_ARGS, argv, + IDX_TIMEZONE, NULL); + #ifdef ENABLE_COMMON_SSH /* SFTP enable/disable */ settings->enable_sftp = @@ -1013,6 +1024,7 @@ void guac_rdp_settings_free(guac_rdp_settings* settings) { free(settings->remote_app); free(settings->remote_app_args); free(settings->remote_app_dir); + free(settings->timezone); free(settings->username); free(settings->printer_name); @@ -1265,6 +1277,9 @@ void guac_rdp_push_settings(guac_rdp_settings* guac_settings, freerdp* rdp) { #endif /* Device redirection */ + if (guac_settings->timezone) + setenv("TZ", guac_settings->timezone, 1); + #ifdef LEGACY_RDPSETTINGS #ifdef HAVE_RDPSETTINGS_DEVICEREDIRECTION rdp_settings->device_redirection = guac_settings->audio_enabled diff --git a/src/protocols/rdp/rdp_settings.h b/src/protocols/rdp/rdp_settings.h index d521a87c..ece399df 100644 --- a/src/protocols/rdp/rdp_settings.h +++ b/src/protocols/rdp/rdp_settings.h @@ -341,6 +341,11 @@ typedef struct guac_rdp_settings { */ char* preconnection_blob; + /** + * The timezone to pass through to the RDP connection. + */ + char* timezone; + #ifdef ENABLE_COMMON_SSH /** * Whether SFTP should be enabled for the VNC connection. From 5536b836addb27dc6c8433b6afef2f9ad24d399d Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Sat, 2 Jun 2018 12:00:22 -0400 Subject: [PATCH 02/11] GUACAMOLE-422: Add support for passing through TZ in SSH. --- src/protocols/ssh/settings.c | 18 ++++++++++++++++++ src/protocols/ssh/settings.h | 4 ++++ src/protocols/ssh/ssh.c | 4 ++++ 3 files changed, 26 insertions(+) diff --git a/src/protocols/ssh/settings.c b/src/protocols/ssh/settings.c index 82f7eb20..820da51e 100644 --- a/src/protocols/ssh/settings.c +++ b/src/protocols/ssh/settings.c @@ -61,6 +61,7 @@ const char* GUAC_SSH_CLIENT_ARGS[] = { "terminal-type", "scrollback", "locale", + "timezone", NULL }; @@ -246,6 +247,15 @@ enum SSH_ARGS_IDX { * variable to be set. */ IDX_LOCALE, + + /** + * The timezone that is passed from the client system to the + * remote server, or null if not specified. If set, and allowed + * by the remote SSH server, the TZ environment variable will be + * set on the remote session, causing the session to be localized + * to the specified timezone. + */ + IDX_TIMEZONE, SSH_ARGS_COUNT }; @@ -410,6 +420,11 @@ guac_ssh_settings* guac_ssh_parse_args(guac_user* user, guac_user_parse_args_string(user, GUAC_SSH_CLIENT_ARGS, argv, IDX_LOCALE, NULL); + /* Read the client timezone. */ + settings->timezone = + guac_user_parse_args_string(user, GUAC_SSH_CLIENT_ARGS, argv, + IDX_TIMEZONE, NULL); + /* Parsing was successful */ return settings; @@ -452,6 +467,9 @@ void guac_ssh_settings_free(guac_ssh_settings* settings) { /* Free locale */ free(settings->locale); + /* Free the client timezone. */ + free(settings->timezone); + /* Free overall structure */ free(settings); diff --git a/src/protocols/ssh/settings.h b/src/protocols/ssh/settings.h index 03abd91d..e4d99e14 100644 --- a/src/protocols/ssh/settings.h +++ b/src/protocols/ssh/settings.h @@ -253,6 +253,10 @@ typedef struct guac_ssh_settings { * environment variable. */ char* locale; + /** + * The client timezone to pass to the remote system. + */ + char* timezone; } guac_ssh_settings; diff --git a/src/protocols/ssh/ssh.c b/src/protocols/ssh/ssh.c index 80b84de1..9e79454b 100644 --- a/src/protocols/ssh/ssh.c +++ b/src/protocols/ssh/ssh.c @@ -256,6 +256,10 @@ void* ssh_client_thread(void* data) { return NULL; } + /* Set the client timezone */ + if (settings->timezone != NULL) + libssh2_channel_setenv(ssh_client->term_channel, "TZ", settings->timezone); + #ifdef ENABLE_SSH_AGENT /* Start SSH agent forwarding, if enabled */ if (ssh_client->enable_agent) { From d7ed452d699f19504a861caff187b72709afcd78 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Sun, 11 Nov 2018 15:30:17 -0500 Subject: [PATCH 03/11] GUACAMOLE-422: Update comments on timezone settings. --- src/protocols/rdp/rdp_settings.c | 5 ++++- src/protocols/ssh/settings.c | 11 ++++++----- src/protocols/ssh/settings.h | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/protocols/rdp/rdp_settings.c b/src/protocols/rdp/rdp_settings.c index 21114d44..f37c156e 100644 --- a/src/protocols/rdp/rdp_settings.c +++ b/src/protocols/rdp/rdp_settings.c @@ -358,7 +358,10 @@ enum RDP_ARGS_IDX { IDX_PRECONNECTION_BLOB, /** - * The timezone to pass through to the RDP connection. + * The timezone to pass through to the RDP connection, in IANA format, which + * will be translated into Windows formats. See the following page for + * information and list of valid values: + * https://en.wikipedia.org/wiki/List_of_tz_database_time_zones */ IDX_TIMEZONE, diff --git a/src/protocols/ssh/settings.c b/src/protocols/ssh/settings.c index 820da51e..962524ce 100644 --- a/src/protocols/ssh/settings.c +++ b/src/protocols/ssh/settings.c @@ -249,11 +249,12 @@ enum SSH_ARGS_IDX { IDX_LOCALE, /** - * The timezone that is passed from the client system to the - * remote server, or null if not specified. If set, and allowed - * by the remote SSH server, the TZ environment variable will be - * set on the remote session, causing the session to be localized - * to the specified timezone. + * The timezone that is to be passed to the remote system, via the + * TZ environment variable. By default, no timezone is forwarded + * and the timezone of the remote system will be used. This + * setting will only work if the SSH server allows the TZ variable + * to be set. Timezones should be in standard IANA format, see: + * https://en.wikipedia.org/wiki/List_of_tz_database_time_zones */ IDX_TIMEZONE, diff --git a/src/protocols/ssh/settings.h b/src/protocols/ssh/settings.h index e4d99e14..baa634ad 100644 --- a/src/protocols/ssh/settings.h +++ b/src/protocols/ssh/settings.h @@ -253,6 +253,7 @@ typedef struct guac_ssh_settings { * environment variable. */ char* locale; + /** * The client timezone to pass to the remote system. */ From e2b4de9d95571609e28c63d4b02583df6e4574a7 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Sun, 11 Nov 2018 15:45:24 -0500 Subject: [PATCH 04/11] GAUCAMOLE-422: Add warning messages when TZ cannot be set. --- src/protocols/rdp/rdp_settings.c | 11 +++++++++-- src/protocols/ssh/ssh.c | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/protocols/rdp/rdp_settings.c b/src/protocols/rdp/rdp_settings.c index f37c156e..78e97078 100644 --- a/src/protocols/rdp/rdp_settings.c +++ b/src/protocols/rdp/rdp_settings.c @@ -1280,8 +1280,15 @@ void guac_rdp_push_settings(guac_rdp_settings* guac_settings, freerdp* rdp) { #endif /* Device redirection */ - if (guac_settings->timezone) - setenv("TZ", guac_settings->timezone, 1); + if (guac_settings->timezone) { + + /* Set the TZ env variable */ + if (setenv("TZ", guac_settings->timezone, 1)) { + guac_user_log(user, GUAC_LOG_WARNING, "Could not set TZ " + "variable. Received error %i", errno); + } + + } #ifdef LEGACY_RDPSETTINGS #ifdef HAVE_RDPSETTINGS_DEVICEREDIRECTION diff --git a/src/protocols/ssh/ssh.c b/src/protocols/ssh/ssh.c index 9e79454b..22ba960f 100644 --- a/src/protocols/ssh/ssh.c +++ b/src/protocols/ssh/ssh.c @@ -257,8 +257,15 @@ void* ssh_client_thread(void* data) { } /* Set the client timezone */ - if (settings->timezone != NULL) - libssh2_channel_setenv(ssh_client->term_channel, "TZ", settings->timezone); + if (settings->timezone != NULL) { + if (libssh2_channel_setenv(ssh_client->term_channel, "TZ", + settings->timezone)) { + guac_client_log(client, GUAC_LOG_WARNING, + "Unable to set the timzeone: SSH server " + "refused to set \"TZ\" variable."); + } + } + #ifdef ENABLE_SSH_AGENT /* Start SSH agent forwarding, if enabled */ From 0b715590170139a17c33b931d4d10ee2ce9fb163 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Sun, 11 Nov 2018 15:48:02 -0500 Subject: [PATCH 05/11] GUACAMOLE-422: Add errno header. --- src/protocols/rdp/rdp_settings.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/protocols/rdp/rdp_settings.c b/src/protocols/rdp/rdp_settings.c index 78e97078..27553e3b 100644 --- a/src/protocols/rdp/rdp_settings.c +++ b/src/protocols/rdp/rdp_settings.c @@ -35,6 +35,7 @@ #include "compat/winpr-wtypes.h" #endif +#include #include #include From b3be9eb8692e6c1c4516f0905cb7e113d18dd190 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Sun, 11 Nov 2018 16:07:20 -0500 Subject: [PATCH 06/11] GUACAMOLE-422: Revert addition of logging for setting TZ variable. --- src/protocols/rdp/rdp_settings.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/protocols/rdp/rdp_settings.c b/src/protocols/rdp/rdp_settings.c index 27553e3b..e9b81c21 100644 --- a/src/protocols/rdp/rdp_settings.c +++ b/src/protocols/rdp/rdp_settings.c @@ -1281,15 +1281,8 @@ void guac_rdp_push_settings(guac_rdp_settings* guac_settings, freerdp* rdp) { #endif /* Device redirection */ - if (guac_settings->timezone) { - - /* Set the TZ env variable */ - if (setenv("TZ", guac_settings->timezone, 1)) { - guac_user_log(user, GUAC_LOG_WARNING, "Could not set TZ " - "variable. Received error %i", errno); - } - - } + if (guac_settings->timezone) + setenv("TZ", guac_settings->timezone, 1) #ifdef LEGACY_RDPSETTINGS #ifdef HAVE_RDPSETTINGS_DEVICEREDIRECTION From 4bd19160ded3e824fb46ea066b08182eafffdbeb Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Sun, 11 Nov 2018 17:22:03 -0500 Subject: [PATCH 07/11] GUACAMOLE-422: Add logging for RDP timzeone. --- src/protocols/rdp/rdp.c | 2 +- src/protocols/rdp/rdp_settings.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/protocols/rdp/rdp.c b/src/protocols/rdp/rdp.c index 4d484320..042d3893 100644 --- a/src/protocols/rdp/rdp.c +++ b/src/protocols/rdp/rdp.c @@ -719,7 +719,7 @@ static int guac_rdp_handle_connection(guac_client* client) { guac_common_cursor_set_pointer(rdp_client->display->cursor); /* Push desired settings to FreeRDP */ - guac_rdp_push_settings(settings, rdp_inst); + guac_rdp_push_settings(client, settings, rdp_inst); /* Connect to RDP server */ if (!freerdp_connect(rdp_inst)) { diff --git a/src/protocols/rdp/rdp_settings.c b/src/protocols/rdp/rdp_settings.c index e9b81c21..ed77bf62 100644 --- a/src/protocols/rdp/rdp_settings.c +++ b/src/protocols/rdp/rdp_settings.c @@ -1169,7 +1169,8 @@ static char* guac_rdp_strdup(const char* str) { } -void guac_rdp_push_settings(guac_rdp_settings* guac_settings, freerdp* rdp) { +void guac_rdp_push_settings(guac_client* client, + guac_rdp_settings* guac_settings, freerdp* rdp) { BOOL bitmap_cache = !guac_settings->disable_bitmap_caching; rdpSettings* rdp_settings = rdp->settings; @@ -1280,10 +1281,15 @@ void guac_rdp_push_settings(guac_rdp_settings* guac_settings, freerdp* rdp) { #endif #endif - /* Device redirection */ - if (guac_settings->timezone) - setenv("TZ", guac_settings->timezone, 1) + /* Timezone redirection */ + if (guac_settings->timezone) { + if(setenv("TZ", guac_settings->timezone, 1)) { + guac_client_log(client, GUAC_LOG_WARNING, + "Unable to set TZ variable, error %i", errno); + } + } + /* Device redirection */ #ifdef LEGACY_RDPSETTINGS #ifdef HAVE_RDPSETTINGS_DEVICEREDIRECTION rdp_settings->device_redirection = guac_settings->audio_enabled From 9a944637be73570857034ab492342c54dd742cfd Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Sun, 11 Nov 2018 17:25:12 -0500 Subject: [PATCH 08/11] GUACAMOLE-422: Fix function declaration for pushing settings. --- src/protocols/rdp/rdp_settings.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/protocols/rdp/rdp_settings.h b/src/protocols/rdp/rdp_settings.h index ece399df..6955ed58 100644 --- a/src/protocols/rdp/rdp_settings.h +++ b/src/protocols/rdp/rdp_settings.h @@ -552,13 +552,17 @@ extern const char* GUAC_RDP_CLIENT_ARGS[]; /** * Save all given settings to the given freerdp instance. * + * @param client + * The guac_client object providing the settings. + * * @param guac_settings * The guac_rdp_settings object to save. * * @param rdp * The RDP instance to save settings to. */ -void guac_rdp_push_settings(guac_rdp_settings* guac_settings, freerdp* rdp); +void guac_rdp_push_settings(guac_client* client, + guac_rdp_settings* guac_settings, freerdp* rdp); /** * Returns the width of the RDP session display. From f61539c4e75c9e55fbfcf3a71a0ed0c3548bbb4e Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Mon, 12 Nov 2018 11:55:07 -0500 Subject: [PATCH 09/11] GUACAMOLE-422: Quick fixes for style and logging. --- src/protocols/rdp/rdp_settings.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/protocols/rdp/rdp_settings.c b/src/protocols/rdp/rdp_settings.c index ed77bf62..810253dd 100644 --- a/src/protocols/rdp/rdp_settings.c +++ b/src/protocols/rdp/rdp_settings.c @@ -1283,9 +1283,10 @@ void guac_rdp_push_settings(guac_client* client, /* Timezone redirection */ if (guac_settings->timezone) { - if(setenv("TZ", guac_settings->timezone, 1)) { + if (setenv("TZ", guac_settings->timezone, 1)) { guac_client_log(client, GUAC_LOG_WARNING, - "Unable to set TZ variable, error %i", errno); + "Unable to forward timezone: TZ environment variable " + "could not be set: %s", sterror(errno)); } } From d1b369528288be97f79786bbf517fef185f6d4e0 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Mon, 12 Nov 2018 11:56:57 -0500 Subject: [PATCH 10/11] GUACAMOLE-422: Fix type in strerror() --- src/protocols/rdp/rdp_settings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/protocols/rdp/rdp_settings.c b/src/protocols/rdp/rdp_settings.c index 810253dd..88d9bc7f 100644 --- a/src/protocols/rdp/rdp_settings.c +++ b/src/protocols/rdp/rdp_settings.c @@ -1286,7 +1286,7 @@ void guac_rdp_push_settings(guac_client* client, if (setenv("TZ", guac_settings->timezone, 1)) { guac_client_log(client, GUAC_LOG_WARNING, "Unable to forward timezone: TZ environment variable " - "could not be set: %s", sterror(errno)); + "could not be set: %s", strerror(errno)); } } From 7b1ba3f2699de9a59d7819b6edc6992e02117e27 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Mon, 12 Nov 2018 12:09:51 -0500 Subject: [PATCH 11/11] GUACAMOLE-422: Fix spelling mistake. --- src/protocols/ssh/ssh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/protocols/ssh/ssh.c b/src/protocols/ssh/ssh.c index 22ba960f..9db545bf 100644 --- a/src/protocols/ssh/ssh.c +++ b/src/protocols/ssh/ssh.c @@ -261,7 +261,7 @@ void* ssh_client_thread(void* data) { if (libssh2_channel_setenv(ssh_client->term_channel, "TZ", settings->timezone)) { guac_client_log(client, GUAC_LOG_WARNING, - "Unable to set the timzeone: SSH server " + "Unable to set the timezone: SSH server " "refused to set \"TZ\" variable."); } }