From 87df97317fa1b345ad9465accd15900b90ceb0b3 Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Tue, 9 Jan 2018 23:11:12 -0500 Subject: [PATCH] GUACAMOLE-565: Add terminal-type parameter for SSH and Telnet. Add a terminal-type parameter for SSH and Telnet connections, to specify the terminal emulator type that is passed to programs. If not specified, the default type of "linux" is used in keep with existing behavior. --- src/protocols/ssh/settings.c | 15 +++++++++++++++ src/protocols/ssh/settings.h | 5 +++++ src/protocols/ssh/ssh.c | 3 ++- src/protocols/telnet/settings.c | 15 +++++++++++++++ src/protocols/telnet/settings.h | 5 +++++ src/protocols/telnet/telnet.c | 2 +- 6 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/protocols/ssh/settings.c b/src/protocols/ssh/settings.c index 983f7f08..6f71d86d 100644 --- a/src/protocols/ssh/settings.c +++ b/src/protocols/ssh/settings.c @@ -57,6 +57,7 @@ const char* GUAC_SSH_CLIENT_ARGS[] = { "read-only", "server-alive-interval", "backspace", + "terminal-type", NULL }; @@ -217,6 +218,12 @@ enum SSH_ARGS_IDX { */ IDX_BACKSPACE, + /** + * The terminal emulator type that is passed to the remote system (e.g. + * "xterm" or "xterm-256color"). "linux" is used if unspecified. + */ + IDX_TERMINAL_TYPE, + SSH_ARGS_COUNT }; @@ -361,6 +368,11 @@ guac_ssh_settings* guac_ssh_parse_args(guac_user* user, guac_user_parse_args_int(user, GUAC_SSH_CLIENT_ARGS, argv, IDX_BACKSPACE, 127); + /* Read terminal emulator type. */ + settings->terminal_type = + guac_user_parse_args_string(user, GUAC_SSH_CLIENT_ARGS, argv, + IDX_TERMINAL_TYPE, "linux"); + /* Parsing was successful */ return settings; @@ -396,6 +408,9 @@ void guac_ssh_settings_free(guac_ssh_settings* settings) { free(settings->recording_name); free(settings->recording_path); + /* Free terminal emulator type. */ + free(settings->terminal_type); + /* Free overall structure */ free(settings); diff --git a/src/protocols/ssh/settings.h b/src/protocols/ssh/settings.h index 175ece93..393cfc0c 100644 --- a/src/protocols/ssh/settings.h +++ b/src/protocols/ssh/settings.h @@ -228,6 +228,11 @@ typedef struct guac_ssh_settings { */ int backspace; + /** + * The terminal emulator type that is passed to the remote system. + */ + char* terminal_type; + } guac_ssh_settings; /** diff --git a/src/protocols/ssh/ssh.c b/src/protocols/ssh/ssh.c index 7c76037a..a614f813 100644 --- a/src/protocols/ssh/ssh.c +++ b/src/protocols/ssh/ssh.c @@ -307,7 +307,8 @@ void* ssh_client_thread(void* data) { " Backspace may not work as expected."); /* Request PTY */ - if (libssh2_channel_request_pty_ex(ssh_client->term_channel, "linux", sizeof("linux")-1, + if (libssh2_channel_request_pty_ex(ssh_client->term_channel, + settings->terminal_type, strlen(settings->terminal_type), ssh_ttymodes, ttymodeBytes, ssh_client->term->term_width, ssh_client->term->term_height, 0, 0)) { guac_client_abort(client, GUAC_PROTOCOL_STATUS_UPSTREAM_ERROR, "Unable to allocate PTY."); diff --git a/src/protocols/telnet/settings.c b/src/protocols/telnet/settings.c index 8f802915..dcd75b6a 100644 --- a/src/protocols/telnet/settings.c +++ b/src/protocols/telnet/settings.c @@ -51,6 +51,7 @@ const char* GUAC_TELNET_CLIENT_ARGS[] = { "create-recording-path", "read-only", "backspace", + "terminal-type", NULL }; @@ -181,6 +182,12 @@ enum TELNET_ARGS_IDX { */ IDX_BACKSPACE, + /** + * The terminal emulator type that is passed to the remote system (e.g. + * "xterm" or "xterm-256color"). "linux" is used if unspecified. + */ + IDX_TERMINAL_TYPE, + TELNET_ARGS_COUNT }; @@ -340,6 +347,11 @@ guac_telnet_settings* guac_telnet_parse_args(guac_user* user, guac_user_parse_args_int(user, GUAC_TELNET_CLIENT_ARGS, argv, IDX_BACKSPACE, 127); + /* Read terminal emulator type. */ + settings->terminal_type = + guac_user_parse_args_string(user, GUAC_TELNET_CLIENT_ARGS, argv, + IDX_TERMINAL_TYPE, "linux"); + /* Parsing was successful */ return settings; @@ -379,6 +391,9 @@ void guac_telnet_settings_free(guac_telnet_settings* settings) { free(settings->recording_name); free(settings->recording_path); + /* Free terminal emulator type. */ + free(settings->terminal_type); + /* Free overall structure */ free(settings); diff --git a/src/protocols/telnet/settings.h b/src/protocols/telnet/settings.h index 9bc3dc37..7d8d6eee 100644 --- a/src/protocols/telnet/settings.h +++ b/src/protocols/telnet/settings.h @@ -214,6 +214,11 @@ typedef struct guac_telnet_settings { */ int backspace; + /** + * The terminal emulator type that is passed to the remote system. + */ + char* terminal_type; + } guac_telnet_settings; /** diff --git a/src/protocols/telnet/telnet.c b/src/protocols/telnet/telnet.c index 040d10be..e902c3b3 100644 --- a/src/protocols/telnet/telnet.c +++ b/src/protocols/telnet/telnet.c @@ -216,7 +216,7 @@ static void __guac_telnet_event_handler(telnet_t* telnet, telnet_event_t* event, /* Terminal type request */ case TELNET_EV_TTYPE: if (event->ttype.cmd == TELNET_TTYPE_SEND) - telnet_ttype_is(telnet_client->telnet, "linux"); + telnet_ttype_is(telnet_client->telnet, settings->terminal_type); break; /* Environment request */