From 76ef6332cce707edc31230e9a9463fdc9cf6bc88 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Sun, 26 Jan 2020 03:53:34 -0500 Subject: [PATCH] GUACAMOLE-221: Make lock, condition, and flags specific to credentials. --- src/protocols/rdp/argv.c | 19 ++++++++----------- src/protocols/rdp/client.c | 2 +- src/protocols/rdp/rdp.c | 12 ++++++------ src/protocols/rdp/rdp.h | 6 +++--- src/protocols/rdp/user.c | 1 + 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/protocols/rdp/argv.c b/src/protocols/rdp/argv.c index 96db4b9c..c256f6ea 100644 --- a/src/protocols/rdp/argv.c +++ b/src/protocols/rdp/argv.c @@ -123,29 +123,26 @@ static int guac_rdp_argv_end_handler(guac_user* user, /* Update RDP username. */ case GUAC_RDP_ARGV_SETTING_USERNAME: free(settings->username); - settings->username = malloc(strlen(argv->buffer) * sizeof(char)); - strcpy(settings->username, argv->buffer); - rdp_client->rdp_cond_flags ^= GUAC_RDP_COND_FLAG_USERNAME; + settings->username = strndup(argv->buffer, argv->length); + rdp_client->rdp_credential_flags &= ~GUAC_RDP_CRED_FLAG_USERNAME; break; case GUAC_RDP_ARGV_SETTING_PASSWORD: free(settings->password); - settings->password = malloc(strlen(argv->buffer) * sizeof(char)); - strcpy(settings->password, argv->buffer); - rdp_client->rdp_cond_flags ^= GUAC_RDP_COND_FLAG_PASSWORD; + settings->password = strndup(argv->buffer, argv->length); + rdp_client->rdp_credential_flags &= ~GUAC_RDP_CRED_FLAG_PASSWORD; break; case GUAC_RDP_ARGV_SETTING_DOMAIN: free(settings->domain); - settings->domain = malloc(strlen(argv->buffer) * sizeof(char)); - strcpy(settings->domain, argv->buffer); - rdp_client->rdp_cond_flags ^= GUAC_RDP_COND_FLAG_DOMAIN; + settings->domain = strndup(argv->buffer, argv->length); + rdp_client->rdp_credential_flags &= ~GUAC_RDP_CRED_FLAG_DOMAIN; break; } - if (!rdp_client->rdp_cond_flags) - pthread_cond_signal(&(rdp_client->rdp_cond)); + if (!rdp_client->rdp_credential_flags) + pthread_cond_signal(&(rdp_client->rdp_credential_cond)); free(argv); return 0; diff --git a/src/protocols/rdp/client.c b/src/protocols/rdp/client.c index f232e6a8..94998ddb 100644 --- a/src/protocols/rdp/client.c +++ b/src/protocols/rdp/client.c @@ -225,7 +225,7 @@ int guac_rdp_client_free_handler(guac_client* client) { guac_rdp_audio_buffer_free(rdp_client->audio_input); /* Destroy the pthread conditional handler */ - pthread_cond_destroy(&(rdp_client->rdp_cond)); + pthread_cond_destroy(&(rdp_client->rdp_credential_cond)); pthread_rwlock_destroy(&(rdp_client->lock)); diff --git a/src/protocols/rdp/rdp.c b/src/protocols/rdp/rdp.c index 4441d66c..fee73d3b 100644 --- a/src/protocols/rdp/rdp.c +++ b/src/protocols/rdp/rdp.c @@ -235,19 +235,19 @@ static BOOL rdp_freerdp_authenticate(freerdp* instance, char** username, if (settings->username == NULL || strcmp(settings->username, "") == 0) { params[i] = "username"; - rdp_client->rdp_cond_flags |= GUAC_RDP_COND_FLAG_USERNAME; + rdp_client->rdp_credential_flags |= GUAC_RDP_CRED_FLAG_USERNAME; i++; } if (settings->password == NULL || strcmp(settings->password, "") == 0) { params[i] = "password"; - rdp_client->rdp_cond_flags |= GUAC_RDP_COND_FLAG_PASSWORD; + rdp_client->rdp_credential_flags |= GUAC_RDP_CRED_FLAG_PASSWORD; i++; } if (settings->domain == NULL || strcmp(settings->domain, "") == 0) { params[i] = "domain"; - rdp_client->rdp_cond_flags |= GUAC_RDP_COND_FLAG_DOMAIN; + rdp_client->rdp_credential_flags |= GUAC_RDP_CRED_FLAG_DOMAIN; i++; } @@ -256,14 +256,14 @@ static BOOL rdp_freerdp_authenticate(freerdp* instance, char** username, if (i > 0) { /* Lock the client thread. */ - pthread_mutex_lock(&(rdp_client->rdp_lock)); + pthread_mutex_lock(&(rdp_client->rdp_credential_lock)); /* Send require params and flush socket. */ guac_protocol_send_required(client->socket, (const char**) params); guac_socket_flush(client->socket); /* Wait for condition. */ - pthread_cond_wait(&(rdp_client->rdp_cond), &(rdp_client->rdp_lock)); + pthread_cond_wait(&(rdp_client->rdp_credential_cond), &(rdp_client->rdp_credential_lock)); /* Get new values from settings. */ *username = settings->username; @@ -271,7 +271,7 @@ static BOOL rdp_freerdp_authenticate(freerdp* instance, char** username, *domain = settings->domain; /* Unlock the thread. */ - pthread_mutex_unlock(&(rdp_client->rdp_lock)); + pthread_mutex_unlock(&(rdp_client->rdp_credential_lock)); } /* Always return TRUE allowing connection to retry. */ diff --git a/src/protocols/rdp/rdp.h b/src/protocols/rdp/rdp.h index 418c908a..361f2da7 100644 --- a/src/protocols/rdp/rdp.h +++ b/src/protocols/rdp/rdp.h @@ -52,17 +52,17 @@ /** * A flag for tracking if we are waiting conditionally on a username. */ -#define GUAC_RDP_COND_FLAG_USERNAME 1 +#define GUAC_RDP_CRED_FLAG_USERNAME 1 /** * A flag for tracking if we are waiting conditionally on a password. */ -#define GUAC_RDP_COND_FLAG_PASSWORD 2 +#define GUAC_RDP_CRED_FLAG_PASSWORD 2 /** * A flag for tracking if we are waiting conditionally on a domain. */ -#define GUAC_RDP_COND_FLAG_DOMAIN 3 +#define GUAC_RDP_CRED_FLAG_DOMAIN 4 /** * RDP-specific client data. diff --git a/src/protocols/rdp/user.c b/src/protocols/rdp/user.c index f5eed822..8be53d3e 100644 --- a/src/protocols/rdp/user.c +++ b/src/protocols/rdp/user.c @@ -17,6 +17,7 @@ * under the License. */ +#include "argv.h" #include "channels/audio-input/audio-input.h" #include "channels/cliprdr.h" #include "channels/pipe-svc.h"