From ef289eaa4a72cefad959232826e28d0c05f72d55 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Sat, 9 Sep 2017 14:45:11 -0400 Subject: [PATCH] TELNET: Add ability to override detected echo setting. --- src/protocols/telnet/settings.c | 12 ++++++++++++ src/protocols/telnet/settings.h | 5 +++++ src/protocols/telnet/telnet.c | 12 ++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/protocols/telnet/settings.c b/src/protocols/telnet/settings.c index df7b2958..5f83b269 100644 --- a/src/protocols/telnet/settings.c +++ b/src/protocols/telnet/settings.c @@ -39,6 +39,7 @@ const char* GUAC_TELNET_CLIENT_ARGS[] = { "password-regex", "font-name", "font-size", + "override-echo", "color-scheme", "typescript-path", "typescript-name", @@ -94,6 +95,11 @@ enum TELNET_ARGS_IDX { */ IDX_FONT_SIZE, + /** + * Whether or not to override the local telnet echo. + */ + IDX_OVERRIDE_ECHO, + /** * The name of the color scheme to use. Currently valid color schemes are: * "black-white", "white-black", "gray-black", and "green-black", each @@ -239,6 +245,11 @@ guac_telnet_settings* guac_telnet_parse_args(guac_user* user, guac_user_parse_args_int(user, GUAC_TELNET_CLIENT_ARGS, argv, IDX_FONT_SIZE, GUAC_TELNET_DEFAULT_FONT_SIZE); + /* Read echo override */ + settings->override_echo = + guac_user_parse_args_string(user, GUAC_TELNET_CLIENT_ARGS, argv, + IDX_OVERRIDE_ECHO, NULL); + /* Copy requested color scheme */ settings->color_scheme = guac_user_parse_args_string(user, GUAC_TELNET_CLIENT_ARGS, argv, @@ -314,6 +325,7 @@ void guac_telnet_settings_free(guac_telnet_settings* settings) { /* Free display preferences */ free(settings->font_name); free(settings->color_scheme); + free(settings->override_echo); /* Free typescript settings */ free(settings->typescript_name); diff --git a/src/protocols/telnet/settings.h b/src/protocols/telnet/settings.h index 434e5938..304e88b7 100644 --- a/src/protocols/telnet/settings.h +++ b/src/protocols/telnet/settings.h @@ -127,6 +127,11 @@ typedef struct guac_telnet_settings { */ int font_size; + /** + * Override the local echo detection. + */ + char* override_echo; + /** * The name of the color scheme to use. */ diff --git a/src/protocols/telnet/telnet.c b/src/protocols/telnet/telnet.c index 82f6dd4d..6df97e82 100644 --- a/src/protocols/telnet/telnet.c +++ b/src/protocols/telnet/telnet.c @@ -195,13 +195,21 @@ static void __guac_telnet_event_handler(telnet_t* telnet, telnet_event_t* event, /* Remote feature enabled */ case TELNET_EV_WILL: - if (event->neg.telopt == TELNET_TELOPT_ECHO) + if (settings->override_echo != NULL && strcmp(settings->override_echo, "disabled") == 0) + telnet_client->echo_enabled = 0; + else if (settings->override_echo != NULL && strcmp(settings->override_echo, "enabled") == 0) + telnet_client->echo_enabled = 1; + else if (event->neg.telopt == TELNET_TELOPT_ECHO) telnet_client->echo_enabled = 0; /* Disable local echo, as remote will echo */ break; /* Remote feature disabled */ case TELNET_EV_WONT: - if (event->neg.telopt == TELNET_TELOPT_ECHO) + if (settings->override_echo != NULL && strcmp(settings->override_echo, "enabled") == 0) + telnet_client->echo_enabled = 1; + else if (settings->override_echo != NULL && strcmp(settings->override_echo, "disabled") == 0) + telnet_client->echo_enabled = 0; + else if (event->neg.telopt == TELNET_TELOPT_ECHO) telnet_client->echo_enabled = 1; /* Enable local echo, as remote won't echo */ break;