From 39f7d5a843111c11d7b6f444ad5510b10cd8e0f6 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 17 Jan 2020 15:29:36 -0800 Subject: [PATCH 1/2] GUACAMOLE-927: Automatically set $HOME for sake of FreeRDP initialization process. --- src/protocols/rdp/client.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/protocols/rdp/client.c b/src/protocols/rdp/client.c index c79e59d8..db98d9b7 100644 --- a/src/protocols/rdp/client.c +++ b/src/protocols/rdp/client.c @@ -38,11 +38,45 @@ #include #include +#include #include +#include #include +#include +#include int guac_client_init(guac_client* client, int argc, char** argv) { + /* Automatically set HOME environment variable if unset (FreeRDP's + * initialization process will fail within freerdp_settings_new() if this + * is unset) */ + const char* current_home = getenv("HOME"); + if (current_home == NULL) { + + /* Warn if the correct home directory cannot be determined */ + struct passwd* passwd = getpwuid(getuid()); + if (passwd == NULL) + guac_client_log(client, GUAC_LOG_WARNING, "FreeRDP initialization " + "may fail: The \"HOME\" environment variable is unset and " + "its correct value could not be automatically determined: " + "%s", strerror(errno)); + + /* Warn if the correct home directory could be determined but can't be + * assigned */ + else if (setenv("HOME", passwd->pw_dir, 1)) + guac_client_log(client, GUAC_LOG_WARNING, "FreeRDP initialization " + "may fail: The \"HOME\" environment variable is unset " + "and its correct value (detected as \"%s\") could not be " + "assigned: %s", passwd->pw_dir, strerror(errno)); + + /* HOME has been successfully set */ + else + guac_client_log(client, GUAC_LOG_DEBUG, "\"HOME\" " + "environment variable was unset and has been " + "automatically set to \"%s\"", passwd->pw_dir); + + } + /* Set client args */ client->args = GUAC_RDP_CLIENT_ARGS; From 0676e703253f19b70762e5b2727687ee80d591bb Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 17 Jan 2020 15:30:36 -0800 Subject: [PATCH 2/2] GUACAMOLE-927: Abort RDP connection if FreeRDP fails to initialize. --- src/protocols/rdp/rdp.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/protocols/rdp/rdp.c b/src/protocols/rdp/rdp.c index 5cf651ad..7e6b3e82 100644 --- a/src/protocols/rdp/rdp.c +++ b/src/protocols/rdp/rdp.c @@ -367,7 +367,14 @@ static int guac_rdp_handle_connection(guac_client* client) { /* Allocate FreeRDP context */ rdp_inst->ContextSize = sizeof(rdp_freerdp_context); - freerdp_context_new(rdp_inst); + if (!freerdp_context_new(rdp_inst)) { + guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, + "FreeRDP initialization failed before connecting. Please " + "check for errors earlier in the logs and/or enable " + "debug-level logging for guacd."); + return 1; + } + ((rdp_freerdp_context*) rdp_inst->context)->client = client; /* Load keymap into client */