From 683800f4947033c25c7225b790dde0d4b9013340 Mon Sep 17 00:00:00 2001 From: Corentin SORIANO Date: Tue, 29 Oct 2024 13:42:53 +0100 Subject: [PATCH] GUACAMOLE-288: Add parameter to limit the usage of multiple monitors. --- src/protocols/rdp/channels/disp.c | 8 ++++++++ src/protocols/rdp/client.c | 11 +++++++++++ src/protocols/rdp/settings.c | 12 ++++++++++++ src/protocols/rdp/settings.h | 5 +++++ 4 files changed, 36 insertions(+) diff --git a/src/protocols/rdp/channels/disp.c b/src/protocols/rdp/channels/disp.c index bad459b94..44be6198c 100644 --- a/src/protocols/rdp/channels/disp.c +++ b/src/protocols/rdp/channels/disp.c @@ -195,6 +195,14 @@ void guac_rdp_disp_update_size(guac_rdp_disp* disp, int height = disp->requested_height; int monitors_count = disp->requested_monitors; + /* Prevent opening too many monitors than allowed */ + if (settings->max_secondary_monitors + 1 < monitors_count) + monitors_count = settings->max_secondary_monitors + 1; + + /* At least one monitor is required */ + if (monitors_count < 1) + monitors_count = 1; + /* Do not update size if no requests have been received */ if (width == 0 || height == 0) return; diff --git a/src/protocols/rdp/client.c b/src/protocols/rdp/client.c index 263ab8d20..2daff84fe 100644 --- a/src/protocols/rdp/client.c +++ b/src/protocols/rdp/client.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -130,6 +131,16 @@ static int guac_rdp_join_pending_handler(guac_client* client) { /* Bring user up to date with any registered static channels */ guac_rdp_pipe_svc_send_pipes(client, broadcast_socket); + /* Get max secondary monitors */ + char* max_monitors = guac_mem_alloc(12); + guac_itoa(max_monitors, + (unsigned int) rdp_client->settings->max_secondary_monitors); + + /* Send current max allowed secondary monitors */ + guac_client_stream_argv(client, broadcast_socket, "text/plain", + "secondary-monitors", max_monitors); + guac_mem_free(max_monitors); + /* Synchronize with current display */ if (rdp_client->display != NULL) { guac_display_dup(rdp_client->display, broadcast_socket); diff --git a/src/protocols/rdp/settings.c b/src/protocols/rdp/settings.c index eb7c45d5f..6a5586a03 100644 --- a/src/protocols/rdp/settings.c +++ b/src/protocols/rdp/settings.c @@ -128,6 +128,7 @@ const char* GUAC_RDP_CLIENT_ARGS[] = { "create-recording-path", "recording-write-existing", "resize-method", + "secondary-monitors", "enable-audio-input", "enable-touch", "read-only", @@ -598,6 +599,12 @@ enum RDP_ARGS_IDX { */ IDX_RESIZE_METHOD, + /** + * The maximum allowed count of secondary monitors. + * 0 to disable. + */ + IDX_SECONDARY_MONITORS, + /** * "true" if audio input (microphone) should be enabled for the RDP * connection, "false" or blank otherwise. @@ -1234,6 +1241,11 @@ guac_rdp_settings* guac_rdp_parse_args(guac_user* user, settings->resize_method = GUAC_RESIZE_NONE; } + /* Maximum secondary monitors (default 0 = disabled) */ + settings->max_secondary_monitors = + guac_user_parse_args_int(user, GUAC_RDP_CLIENT_ARGS, argv, + IDX_SECONDARY_MONITORS, 0); + /* RDP Graphics Pipeline enable/disable */ settings->enable_gfx = !guac_user_parse_args_boolean(user, GUAC_RDP_CLIENT_ARGS, argv, diff --git a/src/protocols/rdp/settings.h b/src/protocols/rdp/settings.h index 253b7628b..b337e7b44 100644 --- a/src/protocols/rdp/settings.h +++ b/src/protocols/rdp/settings.h @@ -596,6 +596,11 @@ typedef struct guac_rdp_settings { */ guac_rdp_resize_method resize_method; + /** + * The maximum allowed count of secondary monitors. + */ + int max_secondary_monitors; + /** * Whether audio input (microphone) is enabled. */