GUACAMOLE-221: Fix up style, comments, and variable names.
This commit is contained in:
parent
939d954810
commit
4318083511
@ -26,7 +26,7 @@
|
||||
#include <libssh2.h>
|
||||
|
||||
/**
|
||||
* A handler function for retrieving additional credentials for the client.
|
||||
* A handler function for retrieving additional credentials from the client.
|
||||
*
|
||||
* @param client
|
||||
* The Guacamole Client associated with this need for additional
|
||||
|
@ -128,8 +128,8 @@ static int __guac_protocol_send_args(guac_socket* socket, const char** args) {
|
||||
|| __guac_socket_write_length_string(socket, GUACAMOLE_PROTOCOL_VERSION))
|
||||
return -1;
|
||||
|
||||
if (__guac_socket_write_array(socket, args))
|
||||
return -1;
|
||||
if (__guac_socket_write_array(socket, args))
|
||||
return -1;
|
||||
|
||||
return guac_socket_write_string(socket, ";");
|
||||
|
||||
@ -330,10 +330,11 @@ int guac_protocol_send_close(guac_socket* socket, const guac_layer* layer) {
|
||||
|
||||
static int __guac_protocol_send_connect(guac_socket* socket, const char** args) {
|
||||
|
||||
if (guac_socket_write_string(socket, "7.connect")) return -1;
|
||||
if (guac_socket_write_string(socket, "7.connect"))
|
||||
return -1;
|
||||
|
||||
if (__guac_socket_write_array(socket, args))
|
||||
return -1;
|
||||
if (__guac_socket_write_array(socket, args))
|
||||
return -1;
|
||||
|
||||
return guac_socket_write_string(socket, ";");
|
||||
|
||||
@ -993,10 +994,11 @@ int guac_protocol_send_rect(guac_socket* socket,
|
||||
static int __guac_protocol_send_required(guac_socket* socket,
|
||||
const char** required) {
|
||||
|
||||
if (guac_socket_write_string(socket, "8.required")) return -1;
|
||||
if (guac_socket_write_string(socket, "8.required"))
|
||||
return -1;
|
||||
|
||||
if (__guac_socket_write_array(socket, required))
|
||||
return -1;
|
||||
if (__guac_socket_write_array(socket, required))
|
||||
return -1;
|
||||
|
||||
return guac_socket_write_string(socket, ";");
|
||||
|
||||
|
@ -38,7 +38,7 @@ nodist_libguac_client_rdp_la_SOURCES = \
|
||||
_generated_keymaps.c
|
||||
|
||||
libguac_client_rdp_la_SOURCES = \
|
||||
argv.c \
|
||||
argv.c \
|
||||
beep.c \
|
||||
bitmap.c \
|
||||
channels/audio-input/audio-buffer.c \
|
||||
@ -83,7 +83,7 @@ libguac_client_rdp_la_SOURCES = \
|
||||
user.c
|
||||
|
||||
noinst_HEADERS = \
|
||||
argv.h \
|
||||
argv.h \
|
||||
beep.h \
|
||||
bitmap.h \
|
||||
channels/audio-input/audio-buffer.h \
|
||||
|
@ -87,7 +87,7 @@ static int guac_rdp_argv_blob_handler(guac_user* user,
|
||||
guac_rdp_argv* argv = (guac_rdp_argv*) stream->data;
|
||||
|
||||
/* Calculate buffer size remaining, including space for null terminator,
|
||||
* adjusting received length accordingly */
|
||||
adjusting received length accordingly */
|
||||
int remaining = sizeof(argv->buffer) - argv->length - 1;
|
||||
if (length > remaining)
|
||||
length = remaining;
|
||||
|
@ -66,7 +66,6 @@
|
||||
#include <freerdp/update.h>
|
||||
#include <guacamole/audio.h>
|
||||
#include <guacamole/client.h>
|
||||
#include <guacamole/parser.h>
|
||||
#include <guacamole/protocol.h>
|
||||
#include <guacamole/socket.h>
|
||||
#include <guacamole/timestamp.h>
|
||||
|
@ -169,14 +169,15 @@ typedef struct guac_rdp_client {
|
||||
guac_common_list* available_svc;
|
||||
|
||||
/**
|
||||
* Lock which is locked and unlocked for each credential required
|
||||
* during the connection process.
|
||||
* Lock which is locked when one or more credentials are required to
|
||||
* complete the connection, and unlocked when credentials have been
|
||||
* provided by the client.
|
||||
*/
|
||||
pthread_mutex_t rdp_credential_lock;
|
||||
|
||||
/**
|
||||
* Condition which is used when the pthread needs to wait for a
|
||||
* particular credential to be provided.
|
||||
* Condition which is used when the pthread needs to wait for one or more
|
||||
* credentials to be provided by the client.
|
||||
*/
|
||||
pthread_cond_t rdp_credential_cond;
|
||||
|
||||
|
@ -58,9 +58,9 @@
|
||||
#include <sys/time.h>
|
||||
|
||||
/**
|
||||
* A function used to generate a prompt to gather additional credentials from
|
||||
* the guac_client during a connection, and using the specified parameter to
|
||||
* generate the prompt to the client.
|
||||
* This function generates a prompt to the specified instance of guac_client
|
||||
* for the credential specified in the cred_name parameter, which should
|
||||
* be a valid SSH connection parameter.
|
||||
*
|
||||
* @param client
|
||||
* The guac_client object associated with the current connection
|
||||
@ -73,12 +73,15 @@ static void guac_ssh_get_credential(guac_client *client, char* cred_name) {
|
||||
|
||||
guac_ssh_client* ssh_client = (guac_ssh_client*) client->data;
|
||||
|
||||
/* Lock the terminal thread while prompting for the credential. */
|
||||
pthread_mutex_lock(&(ssh_client->term_channel_lock));
|
||||
|
||||
/* Let the client know what we require and flush the socket. */
|
||||
guac_protocol_send_required(client->socket, (const char* []) {cred_name, NULL});
|
||||
guac_socket_flush(client->socket);
|
||||
|
||||
pthread_cond_wait(&(ssh_client->ssh_cond), &(ssh_client->term_channel_lock));
|
||||
/* Wait for the response, and then unlock the thread. */
|
||||
pthread_cond_wait(&(ssh_client->ssh_credential_cond), &(ssh_client->term_channel_lock));
|
||||
pthread_mutex_unlock(&(ssh_client->term_channel_lock));
|
||||
|
||||
}
|
||||
@ -281,7 +284,7 @@ void* ssh_client_thread(void* data) {
|
||||
}
|
||||
|
||||
pthread_mutex_init(&ssh_client->term_channel_lock, NULL);
|
||||
pthread_cond_init(&(ssh_client->ssh_cond), NULL);
|
||||
pthread_cond_init(&(ssh_client->ssh_credential_cond), NULL);
|
||||
|
||||
/* Open channel for terminal */
|
||||
ssh_client->term_channel =
|
||||
@ -496,7 +499,7 @@ void* ssh_client_thread(void* data) {
|
||||
guac_client_stop(client);
|
||||
pthread_join(input_thread, NULL);
|
||||
|
||||
pthread_cond_destroy(&(ssh_client->ssh_cond));
|
||||
pthread_cond_destroy(&(ssh_client->ssh_credential_cond));
|
||||
pthread_mutex_destroy(&ssh_client->term_channel_lock);
|
||||
|
||||
guac_client_log(client, GUAC_LOG_INFO, "SSH connection ended.");
|
||||
|
@ -92,9 +92,9 @@ typedef struct guac_ssh_client {
|
||||
|
||||
/**
|
||||
* Condition used when SSH client thread needs to wait for Guacamole
|
||||
* client response.
|
||||
* client to pass additional credentials before continuing the connection.
|
||||
*/
|
||||
pthread_cond_t ssh_cond;
|
||||
pthread_cond_t ssh_credential_cond;
|
||||
|
||||
/**
|
||||
* The current clipboard contents.
|
||||
|
@ -29,7 +29,7 @@ ACLOCAL_AMFLAGS = -I m4
|
||||
lib_LTLIBRARIES = libguac-client-vnc.la
|
||||
|
||||
libguac_client_vnc_la_SOURCES = \
|
||||
argv.c \
|
||||
argv.c \
|
||||
auth.c \
|
||||
client.c \
|
||||
clipboard.c \
|
||||
@ -42,7 +42,7 @@ libguac_client_vnc_la_SOURCES = \
|
||||
vnc.c
|
||||
|
||||
noinst_HEADERS = \
|
||||
argv.h \
|
||||
argv.h \
|
||||
auth.h \
|
||||
client.h \
|
||||
clipboard.h \
|
||||
|
@ -118,33 +118,29 @@ static int guac_vnc_argv_end_handler(guac_user* user, guac_stream* stream) {
|
||||
case GUAC_VNC_ARGV_SETTING_USERNAME:
|
||||
|
||||
/* Update username in settings. */
|
||||
if (settings->username != NULL)
|
||||
free(settings->username);
|
||||
settings->username = malloc(strlen(argv->buffer) * sizeof(char));
|
||||
strcpy(settings->username, argv->buffer);
|
||||
free(settings->username);
|
||||
settings->username = strndup(argv->buffer, argv->length);
|
||||
|
||||
/* Remove the username conditional flag. */
|
||||
vnc_client->argv_cond_flags ^= GUAC_VNC_COND_FLAG_USERNAME;
|
||||
vnc_client->vnc_credential_flags &= ~GUAC_VNC_COND_FLAG_USERNAME;
|
||||
break;
|
||||
|
||||
/* Update password */
|
||||
case GUAC_VNC_ARGV_SETTING_PASSWORD:
|
||||
|
||||
/* Update password in settings */
|
||||
if (settings->password != NULL)
|
||||
free(settings->password);
|
||||
settings->password = malloc(strlen(argv->buffer) * sizeof(char));
|
||||
strcpy(settings->password, argv->buffer);
|
||||
free(settings->password);
|
||||
settings->password = strndup(argv->buffer, argv->length);
|
||||
|
||||
/* Remove the password conditional flag. */
|
||||
vnc_client->argv_cond_flags ^= GUAC_VNC_COND_FLAG_PASSWORD;
|
||||
vnc_client->vnc_credential_flags &= ~GUAC_VNC_COND_FLAG_PASSWORD;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
/* If no flags are set, signal the conditional. */
|
||||
if (!vnc_client->argv_cond_flags)
|
||||
pthread_cond_broadcast(&(vnc_client->argv_cond));
|
||||
if (!vnc_client->vnc_credential_flags)
|
||||
pthread_cond_broadcast(&(vnc_client->vnc_credential_cond));
|
||||
|
||||
free(argv);
|
||||
return 0;
|
||||
|
@ -39,7 +39,7 @@ char* guac_vnc_get_password(rfbClient* client) {
|
||||
/* If password isn't around, prompt for it. */
|
||||
if (settings->password == NULL || strcmp(settings->password, "") == 0) {
|
||||
/* Lock the thread. */
|
||||
pthread_mutex_lock(&(vnc_client->argv_lock));
|
||||
pthread_mutex_lock(&(vnc_client->vnc_credential_lock));
|
||||
|
||||
/* Send the request for password and flush the socket. */
|
||||
guac_protocol_send_required(gc->socket,
|
||||
@ -47,13 +47,14 @@ char* guac_vnc_get_password(rfbClient* client) {
|
||||
guac_socket_flush(gc->socket);
|
||||
|
||||
/* Set the conditional flag. */
|
||||
vnc_client->argv_cond_flags |= GUAC_VNC_COND_FLAG_PASSWORD;
|
||||
vnc_client->vnc_credential_flags |= GUAC_VNC_COND_FLAG_PASSWORD;
|
||||
|
||||
/* Wait for the condition. */
|
||||
pthread_cond_wait(&(vnc_client->argv_cond), &(vnc_client->argv_lock));
|
||||
pthread_cond_wait(&(vnc_client->vnc_credential_cond),
|
||||
&(vnc_client->vnc_credential_lock));
|
||||
|
||||
/* Unlock the thread. */
|
||||
pthread_mutex_unlock(&(vnc_client->argv_lock));
|
||||
pthread_mutex_unlock(&(vnc_client->vnc_credential_lock));
|
||||
}
|
||||
|
||||
return settings->password;
|
||||
@ -75,34 +76,35 @@ rfbCredential* guac_vnc_get_credentials(rfbClient* client, int credentialType) {
|
||||
if (settings->username == NULL || strcmp(settings->username, "") == 0) {
|
||||
params[i] = "username";
|
||||
i++;
|
||||
vnc_client->argv_cond_flags |= GUAC_VNC_COND_FLAG_USERNAME;
|
||||
vnc_client->vnc_credential_flags |= GUAC_VNC_COND_FLAG_USERNAME;
|
||||
}
|
||||
|
||||
/* Check if password is null or empty. */
|
||||
if (settings->password == NULL || strcmp(settings->password, "") == 0) {
|
||||
params[i] = "password";
|
||||
i++;
|
||||
vnc_client->argv_cond_flags |= GUAC_VNC_COND_FLAG_PASSWORD;
|
||||
vnc_client->vnc_credential_flags |= GUAC_VNC_COND_FLAG_PASSWORD;
|
||||
}
|
||||
|
||||
/* If we have empty parameters, request them. */
|
||||
if (i > 0) {
|
||||
/* Lock the thread. */
|
||||
pthread_mutex_lock(&(vnc_client->argv_lock));
|
||||
pthread_mutex_lock(&(vnc_client->vnc_credential_lock));
|
||||
|
||||
/* Send required parameters to client and flush the socket. */
|
||||
guac_protocol_send_required(gc->socket, (const char**) params);
|
||||
guac_socket_flush(gc->socket);
|
||||
|
||||
/* Wait for the parameters to be returned. */
|
||||
pthread_cond_wait(&(vnc_client->argv_cond), &(vnc_client->argv_lock));
|
||||
pthread_cond_wait(&(vnc_client->vnc_credential_cond),
|
||||
&(vnc_client->vnc_credential_lock));
|
||||
|
||||
/* Pull the credentials from updated settings. */
|
||||
creds->userCredential.username = settings->username;
|
||||
creds->userCredential.password = settings->password;
|
||||
|
||||
/* Unlock the thread. */
|
||||
pthread_mutex_unlock(&(vnc_client->argv_lock));
|
||||
pthread_mutex_unlock(&(vnc_client->vnc_credential_lock));
|
||||
|
||||
return creds;
|
||||
|
||||
|
@ -54,10 +54,10 @@ int guac_client_init(guac_client* client) {
|
||||
pthread_mutex_init(&(vnc_client->tls_lock), NULL);
|
||||
#endif
|
||||
|
||||
/* Initialize argv lock and condition */
|
||||
pthread_mutex_init(&(vnc_client->argv_lock), NULL);
|
||||
pthread_cond_init(&(vnc_client->argv_cond), NULL);
|
||||
vnc_client->argv_cond_flags = 0;
|
||||
/* Initialize credential lock, cond, and flags */
|
||||
pthread_mutex_init(&(vnc_client->vnc_credential_lock), NULL);
|
||||
pthread_cond_init(&(vnc_client->vnc_credential_cond), NULL);
|
||||
vnc_client->vnc_credential_flags = 0;
|
||||
|
||||
/* Init clipboard */
|
||||
vnc_client->clipboard = guac_common_clipboard_alloc(GUAC_VNC_CLIPBOARD_MAX_LENGTH);
|
||||
@ -141,9 +141,9 @@ int guac_vnc_client_free_handler(guac_client* client) {
|
||||
pthread_mutex_destroy(&(vnc_client->tls_lock));
|
||||
#endif
|
||||
|
||||
/* Clean up argv mutex */
|
||||
pthread_cond_destroy(&(vnc_client->argv_cond));
|
||||
pthread_mutex_destroy(&(vnc_client->argv_lock));
|
||||
/* Clean up credential mutex */
|
||||
pthread_cond_destroy(&(vnc_client->vnc_credential_cond));
|
||||
pthread_mutex_destroy(&(vnc_client->vnc_credential_lock));
|
||||
|
||||
/* Free generic data struct */
|
||||
free(client->data);
|
||||
|
@ -71,21 +71,6 @@ typedef struct guac_vnc_client {
|
||||
*/
|
||||
pthread_mutex_t tls_lock;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The lock for tracking changes via argv.
|
||||
*/
|
||||
pthread_mutex_t argv_lock;
|
||||
|
||||
/**
|
||||
* The condition for signaling argv updates.
|
||||
*/
|
||||
pthread_cond_t argv_cond;
|
||||
|
||||
/**
|
||||
* Flags for conditional signaling for argv updates;
|
||||
*/
|
||||
unsigned argv_cond_flags;
|
||||
|
||||
/**
|
||||
* The underlying VNC client.
|
||||
@ -158,6 +143,24 @@ typedef struct guac_vnc_client {
|
||||
* Clipboard encoding-specific writer.
|
||||
*/
|
||||
guac_iconv_write* clipboard_writer;
|
||||
|
||||
/**
|
||||
* A lock that will be locked when retrieving required credentials from
|
||||
* the client, and unlocked when credentials have been retrieved.
|
||||
*/
|
||||
pthread_mutex_t vnc_credential_lock;
|
||||
|
||||
/**
|
||||
* A condition to use for signaling the thread when credentials have been
|
||||
* retrieved from the client.
|
||||
*/
|
||||
pthread_cond_t vnc_credential_cond;
|
||||
|
||||
/**
|
||||
* A field to track flags related to retrieving required credentials
|
||||
* from the client.
|
||||
*/
|
||||
unsigned vnc_credential_flags;
|
||||
|
||||
} guac_vnc_client;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user