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>
|
#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
|
* @param client
|
||||||
* The Guacamole Client associated with this need for additional
|
* The Guacamole Client associated with this need for additional
|
||||||
|
@ -330,7 +330,8 @@ int guac_protocol_send_close(guac_socket* socket, const guac_layer* layer) {
|
|||||||
|
|
||||||
static int __guac_protocol_send_connect(guac_socket* socket, const char** args) {
|
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))
|
if (__guac_socket_write_array(socket, args))
|
||||||
return -1;
|
return -1;
|
||||||
@ -993,7 +994,8 @@ int guac_protocol_send_rect(guac_socket* socket,
|
|||||||
static int __guac_protocol_send_required(guac_socket* socket,
|
static int __guac_protocol_send_required(guac_socket* socket,
|
||||||
const char** required) {
|
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))
|
if (__guac_socket_write_array(socket, required))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -87,7 +87,7 @@ static int guac_rdp_argv_blob_handler(guac_user* user,
|
|||||||
guac_rdp_argv* argv = (guac_rdp_argv*) stream->data;
|
guac_rdp_argv* argv = (guac_rdp_argv*) stream->data;
|
||||||
|
|
||||||
/* Calculate buffer size remaining, including space for null terminator,
|
/* 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;
|
int remaining = sizeof(argv->buffer) - argv->length - 1;
|
||||||
if (length > remaining)
|
if (length > remaining)
|
||||||
length = remaining;
|
length = remaining;
|
||||||
|
@ -66,7 +66,6 @@
|
|||||||
#include <freerdp/update.h>
|
#include <freerdp/update.h>
|
||||||
#include <guacamole/audio.h>
|
#include <guacamole/audio.h>
|
||||||
#include <guacamole/client.h>
|
#include <guacamole/client.h>
|
||||||
#include <guacamole/parser.h>
|
|
||||||
#include <guacamole/protocol.h>
|
#include <guacamole/protocol.h>
|
||||||
#include <guacamole/socket.h>
|
#include <guacamole/socket.h>
|
||||||
#include <guacamole/timestamp.h>
|
#include <guacamole/timestamp.h>
|
||||||
|
@ -169,14 +169,15 @@ typedef struct guac_rdp_client {
|
|||||||
guac_common_list* available_svc;
|
guac_common_list* available_svc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lock which is locked and unlocked for each credential required
|
* Lock which is locked when one or more credentials are required to
|
||||||
* during the connection process.
|
* complete the connection, and unlocked when credentials have been
|
||||||
|
* provided by the client.
|
||||||
*/
|
*/
|
||||||
pthread_mutex_t rdp_credential_lock;
|
pthread_mutex_t rdp_credential_lock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Condition which is used when the pthread needs to wait for a
|
* Condition which is used when the pthread needs to wait for one or more
|
||||||
* particular credential to be provided.
|
* credentials to be provided by the client.
|
||||||
*/
|
*/
|
||||||
pthread_cond_t rdp_credential_cond;
|
pthread_cond_t rdp_credential_cond;
|
||||||
|
|
||||||
|
@ -58,9 +58,9 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function used to generate a prompt to gather additional credentials from
|
* This function generates a prompt to the specified instance of guac_client
|
||||||
* the guac_client during a connection, and using the specified parameter to
|
* for the credential specified in the cred_name parameter, which should
|
||||||
* generate the prompt to the client.
|
* be a valid SSH connection parameter.
|
||||||
*
|
*
|
||||||
* @param client
|
* @param client
|
||||||
* The guac_client object associated with the current connection
|
* 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;
|
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));
|
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_protocol_send_required(client->socket, (const char* []) {cred_name, NULL});
|
||||||
guac_socket_flush(client->socket);
|
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));
|
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_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 */
|
/* Open channel for terminal */
|
||||||
ssh_client->term_channel =
|
ssh_client->term_channel =
|
||||||
@ -496,7 +499,7 @@ void* ssh_client_thread(void* data) {
|
|||||||
guac_client_stop(client);
|
guac_client_stop(client);
|
||||||
pthread_join(input_thread, NULL);
|
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);
|
pthread_mutex_destroy(&ssh_client->term_channel_lock);
|
||||||
|
|
||||||
guac_client_log(client, GUAC_LOG_INFO, "SSH connection ended.");
|
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
|
* 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.
|
* The current clipboard contents.
|
||||||
|
@ -118,33 +118,29 @@ static int guac_vnc_argv_end_handler(guac_user* user, guac_stream* stream) {
|
|||||||
case GUAC_VNC_ARGV_SETTING_USERNAME:
|
case GUAC_VNC_ARGV_SETTING_USERNAME:
|
||||||
|
|
||||||
/* Update username in settings. */
|
/* Update username in settings. */
|
||||||
if (settings->username != NULL)
|
|
||||||
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);
|
|
||||||
|
|
||||||
/* Remove the username conditional flag. */
|
/* 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;
|
break;
|
||||||
|
|
||||||
/* Update password */
|
/* Update password */
|
||||||
case GUAC_VNC_ARGV_SETTING_PASSWORD:
|
case GUAC_VNC_ARGV_SETTING_PASSWORD:
|
||||||
|
|
||||||
/* Update password in settings */
|
/* Update password in settings */
|
||||||
if (settings->password != NULL)
|
|
||||||
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);
|
|
||||||
|
|
||||||
/* Remove the password conditional flag. */
|
/* 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;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If no flags are set, signal the conditional. */
|
/* If no flags are set, signal the conditional. */
|
||||||
if (!vnc_client->argv_cond_flags)
|
if (!vnc_client->vnc_credential_flags)
|
||||||
pthread_cond_broadcast(&(vnc_client->argv_cond));
|
pthread_cond_broadcast(&(vnc_client->vnc_credential_cond));
|
||||||
|
|
||||||
free(argv);
|
free(argv);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -39,7 +39,7 @@ char* guac_vnc_get_password(rfbClient* client) {
|
|||||||
/* If password isn't around, prompt for it. */
|
/* If password isn't around, prompt for it. */
|
||||||
if (settings->password == NULL || strcmp(settings->password, "") == 0) {
|
if (settings->password == NULL || strcmp(settings->password, "") == 0) {
|
||||||
/* Lock the thread. */
|
/* 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. */
|
/* Send the request for password and flush the socket. */
|
||||||
guac_protocol_send_required(gc->socket,
|
guac_protocol_send_required(gc->socket,
|
||||||
@ -47,13 +47,14 @@ char* guac_vnc_get_password(rfbClient* client) {
|
|||||||
guac_socket_flush(gc->socket);
|
guac_socket_flush(gc->socket);
|
||||||
|
|
||||||
/* Set the conditional flag. */
|
/* 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. */
|
/* 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. */
|
/* Unlock the thread. */
|
||||||
pthread_mutex_unlock(&(vnc_client->argv_lock));
|
pthread_mutex_unlock(&(vnc_client->vnc_credential_lock));
|
||||||
}
|
}
|
||||||
|
|
||||||
return settings->password;
|
return settings->password;
|
||||||
@ -75,34 +76,35 @@ rfbCredential* guac_vnc_get_credentials(rfbClient* client, int credentialType) {
|
|||||||
if (settings->username == NULL || strcmp(settings->username, "") == 0) {
|
if (settings->username == NULL || strcmp(settings->username, "") == 0) {
|
||||||
params[i] = "username";
|
params[i] = "username";
|
||||||
i++;
|
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. */
|
/* Check if password is null or empty. */
|
||||||
if (settings->password == NULL || strcmp(settings->password, "") == 0) {
|
if (settings->password == NULL || strcmp(settings->password, "") == 0) {
|
||||||
params[i] = "password";
|
params[i] = "password";
|
||||||
i++;
|
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 we have empty parameters, request them. */
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
/* Lock the thread. */
|
/* 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. */
|
/* Send required parameters to client and flush the socket. */
|
||||||
guac_protocol_send_required(gc->socket, (const char**) params);
|
guac_protocol_send_required(gc->socket, (const char**) params);
|
||||||
guac_socket_flush(gc->socket);
|
guac_socket_flush(gc->socket);
|
||||||
|
|
||||||
/* Wait for the parameters to be returned. */
|
/* 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. */
|
/* Pull the credentials from updated settings. */
|
||||||
creds->userCredential.username = settings->username;
|
creds->userCredential.username = settings->username;
|
||||||
creds->userCredential.password = settings->password;
|
creds->userCredential.password = settings->password;
|
||||||
|
|
||||||
/* Unlock the thread. */
|
/* Unlock the thread. */
|
||||||
pthread_mutex_unlock(&(vnc_client->argv_lock));
|
pthread_mutex_unlock(&(vnc_client->vnc_credential_lock));
|
||||||
|
|
||||||
return creds;
|
return creds;
|
||||||
|
|
||||||
|
@ -54,10 +54,10 @@ int guac_client_init(guac_client* client) {
|
|||||||
pthread_mutex_init(&(vnc_client->tls_lock), NULL);
|
pthread_mutex_init(&(vnc_client->tls_lock), NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Initialize argv lock and condition */
|
/* Initialize credential lock, cond, and flags */
|
||||||
pthread_mutex_init(&(vnc_client->argv_lock), NULL);
|
pthread_mutex_init(&(vnc_client->vnc_credential_lock), NULL);
|
||||||
pthread_cond_init(&(vnc_client->argv_cond), NULL);
|
pthread_cond_init(&(vnc_client->vnc_credential_cond), NULL);
|
||||||
vnc_client->argv_cond_flags = 0;
|
vnc_client->vnc_credential_flags = 0;
|
||||||
|
|
||||||
/* Init clipboard */
|
/* Init clipboard */
|
||||||
vnc_client->clipboard = guac_common_clipboard_alloc(GUAC_VNC_CLIPBOARD_MAX_LENGTH);
|
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));
|
pthread_mutex_destroy(&(vnc_client->tls_lock));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Clean up argv mutex */
|
/* Clean up credential mutex */
|
||||||
pthread_cond_destroy(&(vnc_client->argv_cond));
|
pthread_cond_destroy(&(vnc_client->vnc_credential_cond));
|
||||||
pthread_mutex_destroy(&(vnc_client->argv_lock));
|
pthread_mutex_destroy(&(vnc_client->vnc_credential_lock));
|
||||||
|
|
||||||
/* Free generic data struct */
|
/* Free generic data struct */
|
||||||
free(client->data);
|
free(client->data);
|
||||||
|
@ -72,21 +72,6 @@ typedef struct guac_vnc_client {
|
|||||||
pthread_mutex_t tls_lock;
|
pthread_mutex_t tls_lock;
|
||||||
#endif
|
#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.
|
* The underlying VNC client.
|
||||||
*/
|
*/
|
||||||
@ -159,6 +144,24 @@ typedef struct guac_vnc_client {
|
|||||||
*/
|
*/
|
||||||
guac_iconv_write* clipboard_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;
|
} guac_vnc_client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user