From 228cea4af10750238b40d6b3f98fba4b00558f69 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 19 Feb 2019 12:11:14 -0800 Subject: [PATCH] GUACAMOLE-381: Disable outbound transfers from terminal protocols if "disable-copy" is set. --- src/protocols/kubernetes/kubernetes.c | 2 +- src/protocols/ssh/ssh.c | 7 ++++--- src/protocols/telnet/telnet.c | 2 +- src/terminal/select.c | 6 ++++-- src/terminal/terminal.c | 5 +++-- src/terminal/terminal/terminal.h | 18 ++++++++++++++++-- 6 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/protocols/kubernetes/kubernetes.c b/src/protocols/kubernetes/kubernetes.c index 7c22c420..931f8ca3 100644 --- a/src/protocols/kubernetes/kubernetes.c +++ b/src/protocols/kubernetes/kubernetes.c @@ -237,7 +237,7 @@ void* guac_kubernetes_client_thread(void* data) { /* Create terminal */ kubernetes_client->term = guac_terminal_create(client, - kubernetes_client->clipboard, + kubernetes_client->clipboard, settings->disable_copy, settings->max_scrollback, settings->font_name, settings->font_size, settings->resolution, settings->width, settings->height, settings->color_scheme, settings->backspace); diff --git a/src/protocols/ssh/ssh.c b/src/protocols/ssh/ssh.c index 9db545bf..777172ec 100644 --- a/src/protocols/ssh/ssh.c +++ b/src/protocols/ssh/ssh.c @@ -207,9 +207,10 @@ void* ssh_client_thread(void* data) { /* Create terminal */ ssh_client->term = guac_terminal_create(client, ssh_client->clipboard, - settings->max_scrollback, settings->font_name, settings->font_size, - settings->resolution, settings->width, settings->height, - settings->color_scheme, settings->backspace); + settings->disable_copy, settings->max_scrollback, + settings->font_name, settings->font_size, settings->resolution, + settings->width, settings->height, settings->color_scheme, + settings->backspace); /* Fail if terminal init failed */ if (ssh_client->term == NULL) { diff --git a/src/protocols/telnet/telnet.c b/src/protocols/telnet/telnet.c index 17abd681..d8fc5e09 100644 --- a/src/protocols/telnet/telnet.c +++ b/src/protocols/telnet/telnet.c @@ -568,7 +568,7 @@ void* guac_telnet_client_thread(void* data) { /* Create terminal */ telnet_client->term = guac_terminal_create(client, - telnet_client->clipboard, + telnet_client->clipboard, settings->disable_copy, settings->max_scrollback, settings->font_name, settings->font_size, settings->resolution, settings->width, settings->height, settings->color_scheme, settings->backspace); diff --git a/src/terminal/select.c b/src/terminal/select.c index 20fc3cda..0a075ebd 100644 --- a/src/terminal/select.c +++ b/src/terminal/select.c @@ -375,8 +375,10 @@ void guac_terminal_select_end(guac_terminal* terminal) { } /* Send data */ - guac_common_clipboard_send(terminal->clipboard, client); - guac_socket_flush(socket); + if (!terminal->disable_copy) { + guac_common_clipboard_send(terminal->clipboard, client); + guac_socket_flush(socket); + } guac_terminal_notify(terminal); diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index cf70f92d..7ddcb2f1 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -306,8 +306,8 @@ void* guac_terminal_thread(void* data) { } guac_terminal* guac_terminal_create(guac_client* client, - guac_common_clipboard* clipboard, int max_scrollback, - const char* font_name, int font_size, int dpi, + guac_common_clipboard* clipboard, bool disable_copy, + int max_scrollback, const char* font_name, int font_size, int dpi, int width, int height, const char* color_scheme, const int backspace) { @@ -404,6 +404,7 @@ guac_terminal* guac_terminal_create(guac_client* client, term->current_attributes = default_char.attributes; term->default_char = default_char; term->clipboard = clipboard; + term->disable_copy = disable_copy; /* Calculate character size */ int rows = height / term->display->char_height; diff --git a/src/terminal/terminal/terminal.h b/src/terminal/terminal/terminal.h index ac1217eb..28e69357 100644 --- a/src/terminal/terminal/terminal.h +++ b/src/terminal/terminal/terminal.h @@ -511,6 +511,14 @@ struct guac_terminal { */ char backspace; + /** + * Whether copying from the terminal clipboard should be blocked. If set, + * the contents of the terminal can still be copied, but will be usable + * only within the terminal itself. The clipboard contents will not be + * automatically streamed to the client. + */ + bool disable_copy; + }; /** @@ -533,6 +541,12 @@ struct guac_terminal { * clipboard instructions. This clipboard will not be automatically * freed when this terminal is freed. * + * @param disable_copy + * Whether copying from the terminal clipboard should be blocked. If set, + * the contents of the terminal can still be copied, but will be usable + * only within the terminal itself. The clipboard contents will not be + * automatically streamed to the client. + * * @param max_scrollback * The maximum number of rows to allow within the scrollback buffer. The * user may still alter the size of the scrollback buffer using terminal @@ -575,8 +589,8 @@ struct guac_terminal { * which renders all text to the given client. */ guac_terminal* guac_terminal_create(guac_client* client, - guac_common_clipboard* clipboard, int max_scrollback, - const char* font_name, int font_size, int dpi, + guac_common_clipboard* clipboard, bool disable_copy, + int max_scrollback, const char* font_name, int font_size, int dpi, int width, int height, const char* color_scheme, const int backspace);