diff --git a/src/protocols/ssh/ssh_client.c b/src/protocols/ssh/ssh_client.c index 5e3fea12..946069ab 100644 --- a/src/protocols/ssh/ssh_client.c +++ b/src/protocols/ssh/ssh_client.c @@ -268,6 +268,55 @@ static LIBSSH2_SESSION* __guac_ssh_create_session(guac_client* client, GCRY_THREAD_OPTION_PTHREAD_IMPL; #endif +/** + * Array of mutexes, used by OpenSSL. + */ +static pthread_mutex_t* __openssl_locks; + +/** + * Called by OpenSSL when locking or unlocking the Nth mutex. + */ +static void __openssl_locking_callback(int mode, int n, const char* file, int line){ + if (mode & CRYPTO_LOCK) + pthread_mutex_lock(&(__openssl_locks[n])); + else if (mode & CRYPTO_UNLOCK) + pthread_mutex_unlock(&(__openssl_locks[n])); +} + +/** + * Called by OpenSSL when determining the current thread ID. + */ +static unsigned long __openssl_id_callback() { + return (unsigned long) pthread_self(); +} + +/** + * Creates the given number of mutexes, such that OpenSSL will have at least + * this number of mutexes at its disposal. + */ +static void __openssl_init_locks(int count) { + + int i; + + __openssl_locks = malloc(sizeof(pthread_mutex_t) * CRYPTO_num_locks()); + + for (i=0; i