mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 10:40:27 +09:00
Fix initialization of threading
This commit is contained in:
@@ -701,10 +701,11 @@ int ssh_connect(ssh_session session) {
|
|||||||
|
|
||||||
/*, session->timeout * 1000 + session->timeout_usec); */
|
/*, session->timeout * 1000 + session->timeout_usec); */
|
||||||
}
|
}
|
||||||
if (ret != SSH_OK) {
|
if (ret == SSH_ERROR) {
|
||||||
leave_function();
|
leave_function();
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_status(session, 0.2f);
|
set_status(session, 0.2f);
|
||||||
|
|
||||||
session->alive = 1;
|
session->alive = 1;
|
||||||
|
|||||||
@@ -55,7 +55,6 @@
|
|||||||
#include "libssh/session.h"
|
#include "libssh/session.h"
|
||||||
#include "libssh/keys.h"
|
#include "libssh/keys.h"
|
||||||
#include "libssh/dh.h"
|
#include "libssh/dh.h"
|
||||||
#include "libssh/threads.h"
|
|
||||||
|
|
||||||
/* todo: remove it */
|
/* todo: remove it */
|
||||||
#include "libssh/string.h"
|
#include "libssh/string.h"
|
||||||
@@ -156,7 +155,7 @@ void ssh_crypto_finalize(void) {
|
|||||||
bignum_free(p);
|
bignum_free(p);
|
||||||
p = NULL;
|
p = NULL;
|
||||||
ssh_crypto_initialized=0;
|
ssh_crypto_initialized=0;
|
||||||
ssh_threads_finalize();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ int ssh_init(void) {
|
|||||||
@returns 0 otherwise
|
@returns 0 otherwise
|
||||||
*/
|
*/
|
||||||
int ssh_finalize(void) {
|
int ssh_finalize(void) {
|
||||||
|
ssh_threads_finalize();
|
||||||
ssh_free_global_poll_ctx();
|
ssh_free_global_poll_ctx();
|
||||||
ssh_regex_finalize();
|
ssh_regex_finalize();
|
||||||
ssh_crypto_finalize();
|
ssh_crypto_finalize();
|
||||||
|
|||||||
@@ -1615,6 +1615,12 @@ int ssh_is_server_known(ssh_session session) {
|
|||||||
return SSH_SERVER_ERROR;
|
return SSH_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (session->current_crypto == NULL){
|
||||||
|
ssh_set_error(session, SSH_FATAL,
|
||||||
|
"ssh_is_host_known called without cryptographic context");
|
||||||
|
leave_function();
|
||||||
|
return SSH_SERVER_ERROR;
|
||||||
|
}
|
||||||
host = ssh_lowercase(session->host);
|
host = ssh_lowercase(session->host);
|
||||||
hostport = ssh_hostport(host,session->port);
|
hostport = ssh_hostport(host,session->port);
|
||||||
if (host == NULL || hostport == NULL) {
|
if (host == NULL || hostport == NULL) {
|
||||||
|
|||||||
@@ -153,6 +153,10 @@ static void libcrypto_thread_finalize(){
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
int ssh_threads_init(void){
|
int ssh_threads_init(void){
|
||||||
|
static int threads_initialized=0;
|
||||||
|
int ret;
|
||||||
|
if(threads_initialized)
|
||||||
|
return SSH_OK;
|
||||||
/* first initialize the user_callbacks with our default handlers if not
|
/* first initialize the user_callbacks with our default handlers if not
|
||||||
* already the case
|
* already the case
|
||||||
*/
|
*/
|
||||||
@@ -166,11 +170,13 @@ int ssh_threads_init(void){
|
|||||||
|
|
||||||
/* Then initialize the crypto libraries threading callbacks */
|
/* Then initialize the crypto libraries threading callbacks */
|
||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
return libgcrypt_thread_init();
|
ret = libgcrypt_thread_init();
|
||||||
#else /* Libcrypto */
|
#else /* Libcrypto */
|
||||||
return libcrypto_thread_init();
|
ret = libcrypto_thread_init();
|
||||||
#endif
|
#endif
|
||||||
return SSH_ERROR;
|
if(ret == SSH_OK)
|
||||||
|
threads_initialized=1;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ssh_threads_finalize(void){
|
void ssh_threads_finalize(void){
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ START_TEST (torture_knownhosts_port)
|
|||||||
int rc;
|
int rc;
|
||||||
char buffer[200];
|
char buffer[200];
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
//int verbosity=SSH_LOG_FUNCTIONS;
|
||||||
/* Connect to localhost:22, force the port to 1234 and then write
|
/* Connect to localhost:22, force the port to 1234 and then write
|
||||||
* the known hosts file. Then check that the entry written is
|
* the known hosts file. Then check that the entry written is
|
||||||
* [localhost]:1234
|
* [localhost]:1234
|
||||||
@@ -68,6 +69,7 @@ START_TEST (torture_knownhosts_port)
|
|||||||
session=ssh_new();
|
session=ssh_new();
|
||||||
ssh_options_set(session,SSH_OPTIONS_HOST,"localhost");
|
ssh_options_set(session,SSH_OPTIONS_HOST,"localhost");
|
||||||
ssh_options_set(session,SSH_OPTIONS_KNOWNHOSTS,KNOWNHOSTFILES);
|
ssh_options_set(session,SSH_OPTIONS_KNOWNHOSTS,KNOWNHOSTFILES);
|
||||||
|
//ssh_options_set(session,SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
|
||||||
rc=ssh_connect(session);
|
rc=ssh_connect(session);
|
||||||
ck_assert_msg(rc==SSH_OK,ssh_get_error(session));
|
ck_assert_msg(rc==SSH_OK,ssh_get_error(session));
|
||||||
session->port=1234;
|
session->port=1234;
|
||||||
|
|||||||
Reference in New Issue
Block a user