GUACAMOLE-221: Make lock, condition, and flags specific to credentials.

This commit is contained in:
Nick Couchman 2020-01-26 03:53:34 -05:00
parent 7369bed22c
commit 76ef6332cc
5 changed files with 19 additions and 21 deletions

View File

@ -123,29 +123,26 @@ static int guac_rdp_argv_end_handler(guac_user* user,
/* Update RDP username. */ /* Update RDP username. */
case GUAC_RDP_ARGV_SETTING_USERNAME: case GUAC_RDP_ARGV_SETTING_USERNAME:
free(settings->username); free(settings->username);
settings->username = malloc(strlen(argv->buffer) * sizeof(char)); settings->username = strndup(argv->buffer, argv->length);
strcpy(settings->username, argv->buffer); rdp_client->rdp_credential_flags &= ~GUAC_RDP_CRED_FLAG_USERNAME;
rdp_client->rdp_cond_flags ^= GUAC_RDP_COND_FLAG_USERNAME;
break; break;
case GUAC_RDP_ARGV_SETTING_PASSWORD: case GUAC_RDP_ARGV_SETTING_PASSWORD:
free(settings->password); free(settings->password);
settings->password = malloc(strlen(argv->buffer) * sizeof(char)); settings->password = strndup(argv->buffer, argv->length);
strcpy(settings->password, argv->buffer); rdp_client->rdp_credential_flags &= ~GUAC_RDP_CRED_FLAG_PASSWORD;
rdp_client->rdp_cond_flags ^= GUAC_RDP_COND_FLAG_PASSWORD;
break; break;
case GUAC_RDP_ARGV_SETTING_DOMAIN: case GUAC_RDP_ARGV_SETTING_DOMAIN:
free(settings->domain); free(settings->domain);
settings->domain = malloc(strlen(argv->buffer) * sizeof(char)); settings->domain = strndup(argv->buffer, argv->length);
strcpy(settings->domain, argv->buffer); rdp_client->rdp_credential_flags &= ~GUAC_RDP_CRED_FLAG_DOMAIN;
rdp_client->rdp_cond_flags ^= GUAC_RDP_COND_FLAG_DOMAIN;
break; break;
} }
if (!rdp_client->rdp_cond_flags) if (!rdp_client->rdp_credential_flags)
pthread_cond_signal(&(rdp_client->rdp_cond)); pthread_cond_signal(&(rdp_client->rdp_credential_cond));
free(argv); free(argv);
return 0; return 0;

View File

@ -225,7 +225,7 @@ int guac_rdp_client_free_handler(guac_client* client) {
guac_rdp_audio_buffer_free(rdp_client->audio_input); guac_rdp_audio_buffer_free(rdp_client->audio_input);
/* Destroy the pthread conditional handler */ /* 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)); pthread_rwlock_destroy(&(rdp_client->lock));

View File

@ -235,19 +235,19 @@ static BOOL rdp_freerdp_authenticate(freerdp* instance, char** username,
if (settings->username == NULL || strcmp(settings->username, "") == 0) { if (settings->username == NULL || strcmp(settings->username, "") == 0) {
params[i] = "username"; params[i] = "username";
rdp_client->rdp_cond_flags |= GUAC_RDP_COND_FLAG_USERNAME; rdp_client->rdp_credential_flags |= GUAC_RDP_CRED_FLAG_USERNAME;
i++; i++;
} }
if (settings->password == NULL || strcmp(settings->password, "") == 0) { if (settings->password == NULL || strcmp(settings->password, "") == 0) {
params[i] = "password"; params[i] = "password";
rdp_client->rdp_cond_flags |= GUAC_RDP_COND_FLAG_PASSWORD; rdp_client->rdp_credential_flags |= GUAC_RDP_CRED_FLAG_PASSWORD;
i++; i++;
} }
if (settings->domain == NULL || strcmp(settings->domain, "") == 0) { if (settings->domain == NULL || strcmp(settings->domain, "") == 0) {
params[i] = "domain"; params[i] = "domain";
rdp_client->rdp_cond_flags |= GUAC_RDP_COND_FLAG_DOMAIN; rdp_client->rdp_credential_flags |= GUAC_RDP_CRED_FLAG_DOMAIN;
i++; i++;
} }
@ -256,14 +256,14 @@ static BOOL rdp_freerdp_authenticate(freerdp* instance, char** username,
if (i > 0) { if (i > 0) {
/* Lock the client thread. */ /* 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. */ /* Send require params and flush socket. */
guac_protocol_send_required(client->socket, (const char**) params); guac_protocol_send_required(client->socket, (const char**) params);
guac_socket_flush(client->socket); guac_socket_flush(client->socket);
/* Wait for condition. */ /* 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. */ /* Get new values from settings. */
*username = settings->username; *username = settings->username;
@ -271,7 +271,7 @@ static BOOL rdp_freerdp_authenticate(freerdp* instance, char** username,
*domain = settings->domain; *domain = settings->domain;
/* Unlock the thread. */ /* 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. */ /* Always return TRUE allowing connection to retry. */

View File

@ -52,17 +52,17 @@
/** /**
* A flag for tracking if we are waiting conditionally on a username. * 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. * 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. * 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. * RDP-specific client data.

View File

@ -17,6 +17,7 @@
* under the License. * under the License.
*/ */
#include "argv.h"
#include "channels/audio-input/audio-input.h" #include "channels/audio-input/audio-input.h"
#include "channels/cliprdr.h" #include "channels/cliprdr.h"
#include "channels/pipe-svc.h" #include "channels/pipe-svc.h"