Skip to content

Commit

Permalink
GUACAMOLE-649: Merge add support for setting LANG environment variabl…
Browse files Browse the repository at this point in the history
…e via SSH.
  • Loading branch information
necouchman committed Nov 10, 2018
2 parents 6f49194 + edbdd08 commit e132c79
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/protocols/ssh/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const char* GUAC_SSH_CLIENT_ARGS[] = {
"backspace",
"terminal-type",
"scrollback",
"locale",
NULL
};

Expand Down Expand Up @@ -238,6 +239,14 @@ enum SSH_ARGS_IDX {
*/
IDX_SCROLLBACK,

/**
* The locale that should be forwarded to the remote system via the LANG
* environment variable. By default, no locale is forwarded. This setting
* will only have an effect if the SSH server allows the LANG environment
* variable to be set.
*/
IDX_LOCALE,

SSH_ARGS_COUNT
};

Expand Down Expand Up @@ -396,6 +405,11 @@ guac_ssh_settings* guac_ssh_parse_args(guac_user* user,
guac_user_parse_args_string(user, GUAC_SSH_CLIENT_ARGS, argv,
IDX_TERMINAL_TYPE, "linux");

/* Read locale */
settings->locale =
guac_user_parse_args_string(user, GUAC_SSH_CLIENT_ARGS, argv,
IDX_LOCALE, NULL);

/* Parsing was successful */
return settings;

Expand Down Expand Up @@ -435,6 +449,9 @@ void guac_ssh_settings_free(guac_ssh_settings* settings) {
/* Free terminal emulator type. */
free(settings->terminal_type);

/* Free locale */
free(settings->locale);

/* Free overall structure */
free(settings);

Expand Down
6 changes: 6 additions & 0 deletions src/protocols/ssh/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ typedef struct guac_ssh_settings {
*/
char* terminal_type;

/**
* The locale that should be forwarded to the remote system via the LANG
* environment variable.
*/
char* locale;

} guac_ssh_settings;

/**
Expand Down
10 changes: 10 additions & 0 deletions src/protocols/ssh/ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,16 @@ void* ssh_client_thread(void* data) {
return NULL;
}

/* Forward specified locale */
if (settings->locale != NULL) {
if (libssh2_channel_setenv(ssh_client->term_channel, "LANG",
settings->locale)) {
guac_client_log(client, GUAC_LOG_WARNING,
"Unable to forward locale: SSH server refused to set "
"\"LANG\" environment variable.");
}
}

/* If a command is specified, run that instead of a shell */
if (settings->command != NULL) {
if (libssh2_channel_exec(ssh_client->term_channel, settings->command)) {
Expand Down

0 comments on commit e132c79

Please sign in to comment.