Skip to content

Commit 0d435e2

Browse files
committed
GUACAMOLE-422: Merge support for specifying the timezone of RDP and SSH sessions.
2 parents 381c5d1 + 7b1ba3f commit 0d435e2

6 files changed

Lines changed: 73 additions & 3 deletions

File tree

‎src/protocols/rdp/rdp.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ static int guac_rdp_handle_connection(guac_client* client) {
719719
guac_common_cursor_set_pointer(rdp_client->display->cursor);
720720

721721
/* Push desired settings to FreeRDP */
722-
guac_rdp_push_settings(settings, rdp_inst);
722+
guac_rdp_push_settings(client, settings, rdp_inst);
723723

724724
/* Connect to RDP server */
725725
if (!freerdp_connect(rdp_inst)) {

‎src/protocols/rdp/rdp_settings.c‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "compat/winpr-wtypes.h"
3636
#endif
3737

38+
#include <errno.h>
3839
#include <stddef.h>
3940
#include <string.h>
4041

@@ -79,6 +80,7 @@ const char* GUAC_RDP_CLIENT_ARGS[] = {
7980
"disable-glyph-caching",
8081
"preconnection-id",
8182
"preconnection-blob",
83+
"timezone",
8284

8385
#ifdef ENABLE_COMMON_SSH
8486
"enable-sftp",
@@ -356,6 +358,14 @@ enum RDP_ARGS_IDX {
356358
*/
357359
IDX_PRECONNECTION_BLOB,
358360

361+
/**
362+
* The timezone to pass through to the RDP connection, in IANA format, which
363+
* will be translated into Windows formats. See the following page for
364+
* information and list of valid values:
365+
* https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
366+
*/
367+
IDX_TIMEZONE,
368+
359369
#ifdef ENABLE_COMMON_SSH
360370
/**
361371
* "true" if SFTP should be enabled for the RDP connection, "false" or
@@ -840,6 +850,11 @@ guac_rdp_settings* guac_rdp_parse_args(guac_user* user,
840850
if (settings->server_layout == NULL)
841851
settings->server_layout = guac_rdp_keymap_find(GUAC_DEFAULT_KEYMAP);
842852

853+
/* Timezone if provied by client */
854+
settings->timezone =
855+
guac_user_parse_args_string(user, GUAC_RDP_CLIENT_ARGS, argv,
856+
IDX_TIMEZONE, NULL);
857+
843858
#ifdef ENABLE_COMMON_SSH
844859
/* SFTP enable/disable */
845860
settings->enable_sftp =
@@ -1013,6 +1028,7 @@ void guac_rdp_settings_free(guac_rdp_settings* settings) {
10131028
free(settings->remote_app);
10141029
free(settings->remote_app_args);
10151030
free(settings->remote_app_dir);
1031+
free(settings->timezone);
10161032
free(settings->username);
10171033
free(settings->printer_name);
10181034

@@ -1153,7 +1169,8 @@ static char* guac_rdp_strdup(const char* str) {
11531169

11541170
}
11551171

1156-
void guac_rdp_push_settings(guac_rdp_settings* guac_settings, freerdp* rdp) {
1172+
void guac_rdp_push_settings(guac_client* client,
1173+
guac_rdp_settings* guac_settings, freerdp* rdp) {
11571174

11581175
BOOL bitmap_cache = !guac_settings->disable_bitmap_caching;
11591176
rdpSettings* rdp_settings = rdp->settings;
@@ -1264,6 +1281,15 @@ void guac_rdp_push_settings(guac_rdp_settings* guac_settings, freerdp* rdp) {
12641281
#endif
12651282
#endif
12661283

1284+
/* Timezone redirection */
1285+
if (guac_settings->timezone) {
1286+
if (setenv("TZ", guac_settings->timezone, 1)) {
1287+
guac_client_log(client, GUAC_LOG_WARNING,
1288+
"Unable to forward timezone: TZ environment variable "
1289+
"could not be set: %s", strerror(errno));
1290+
}
1291+
}
1292+
12671293
/* Device redirection */
12681294
#ifdef LEGACY_RDPSETTINGS
12691295
#ifdef HAVE_RDPSETTINGS_DEVICEREDIRECTION

‎src/protocols/rdp/rdp_settings.h‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@ typedef struct guac_rdp_settings {
341341
*/
342342
char* preconnection_blob;
343343

344+
/**
345+
* The timezone to pass through to the RDP connection.
346+
*/
347+
char* timezone;
348+
344349
#ifdef ENABLE_COMMON_SSH
345350
/**
346351
* Whether SFTP should be enabled for the VNC connection.
@@ -547,13 +552,17 @@ extern const char* GUAC_RDP_CLIENT_ARGS[];
547552
/**
548553
* Save all given settings to the given freerdp instance.
549554
*
555+
* @param client
556+
* The guac_client object providing the settings.
557+
*
550558
* @param guac_settings
551559
* The guac_rdp_settings object to save.
552560
*
553561
* @param rdp
554562
* The RDP instance to save settings to.
555563
*/
556-
void guac_rdp_push_settings(guac_rdp_settings* guac_settings, freerdp* rdp);
564+
void guac_rdp_push_settings(guac_client* client,
565+
guac_rdp_settings* guac_settings, freerdp* rdp);
557566

558567
/**
559568
* Returns the width of the RDP session display.

‎src/protocols/ssh/settings.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const char* GUAC_SSH_CLIENT_ARGS[] = {
6161
"terminal-type",
6262
"scrollback",
6363
"locale",
64+
"timezone",
6465
NULL
6566
};
6667

@@ -246,6 +247,16 @@ enum SSH_ARGS_IDX {
246247
* variable to be set.
247248
*/
248249
IDX_LOCALE,
250+
251+
/**
252+
* The timezone that is to be passed to the remote system, via the
253+
* TZ environment variable. By default, no timezone is forwarded
254+
* and the timezone of the remote system will be used. This
255+
* setting will only work if the SSH server allows the TZ variable
256+
* to be set. Timezones should be in standard IANA format, see:
257+
* https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
258+
*/
259+
IDX_TIMEZONE,
249260

250261
SSH_ARGS_COUNT
251262
};
@@ -410,6 +421,11 @@ guac_ssh_settings* guac_ssh_parse_args(guac_user* user,
410421
guac_user_parse_args_string(user, GUAC_SSH_CLIENT_ARGS, argv,
411422
IDX_LOCALE, NULL);
412423

424+
/* Read the client timezone. */
425+
settings->timezone =
426+
guac_user_parse_args_string(user, GUAC_SSH_CLIENT_ARGS, argv,
427+
IDX_TIMEZONE, NULL);
428+
413429
/* Parsing was successful */
414430
return settings;
415431

@@ -452,6 +468,9 @@ void guac_ssh_settings_free(guac_ssh_settings* settings) {
452468
/* Free locale */
453469
free(settings->locale);
454470

471+
/* Free the client timezone. */
472+
free(settings->timezone);
473+
455474
/* Free overall structure */
456475
free(settings);
457476

‎src/protocols/ssh/settings.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ typedef struct guac_ssh_settings {
254254
*/
255255
char* locale;
256256

257+
/**
258+
* The client timezone to pass to the remote system.
259+
*/
260+
char* timezone;
261+
257262
} guac_ssh_settings;
258263

259264
/**

‎src/protocols/ssh/ssh.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,17 @@ void* ssh_client_thread(void* data) {
256256
return NULL;
257257
}
258258

259+
/* Set the client timezone */
260+
if (settings->timezone != NULL) {
261+
if (libssh2_channel_setenv(ssh_client->term_channel, "TZ",
262+
settings->timezone)) {
263+
guac_client_log(client, GUAC_LOG_WARNING,
264+
"Unable to set the timezone: SSH server "
265+
"refused to set \"TZ\" variable.");
266+
}
267+
}
268+
269+
259270
#ifdef ENABLE_SSH_AGENT
260271
/* Start SSH agent forwarding, if enabled */
261272
if (ssh_client->enable_agent) {

0 commit comments

Comments
 (0)