aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2009-06-15 15:31:23 +0000
committerAndreas Schneider <mail@cynapses.org>2009-07-29 17:50:04 +0200
commit7fa1804cf1fb1c57c53a864e055deff0bceca1bb (patch)
treee27da9a7f92167647be02284a7bff87d9fe804b5
parentad86a378d9ef7eff8131a0495ca36ceb6a6eace0 (diff)
downloadlibssh-7fa1804cf1fb1c57c53a864e055deff0bceca1bb.tar.gz
libssh-7fa1804cf1fb1c57c53a864e055deff0bceca1bb.tar.xz
libssh-7fa1804cf1fb1c57c53a864e055deff0bceca1bb.zip
ssh_init()
fixes in client.c and server.c for this git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@778 7dcaeef0-15fb-0310-b436-a5af3365683c
-rw-r--r--include/libssh/libssh.h1
-rw-r--r--libssh/client.c7
-rw-r--r--libssh/init.c19
-rw-r--r--libssh/server.c6
4 files changed, 21 insertions, 12 deletions
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h
index 6c024649..18b69aeb 100644
--- a/include/libssh/libssh.h
+++ b/include/libssh/libssh.h
@@ -375,6 +375,7 @@ int ssh_userauth_kbdint_setanswer(SSH_SESSION *session, unsigned int i,
/* init.c */
+int ssh_init(void);
int ssh_finalize(void);
#ifdef __cplusplus
diff --git a/libssh/client.c b/libssh/client.c
index 2ef5568e..e6521d0c 100644
--- a/libssh/client.c
+++ b/libssh/client.c
@@ -491,15 +491,10 @@ int ssh_connect(SSH_SESSION *session) {
session->alive = 0;
session->client = 1;
- if (ssh_crypto_init() < 0) {
+ if (ssh_init() < 0) {
leave_function();
return SSH_ERROR;
}
- if (ssh_socket_init() < 0) {
- leave_function();
- return SSH_ERROR;
- }
-
if (options->fd == -1 && options->host == NULL) {
ssh_set_error(session, SSH_FATAL, "Hostname required");
leave_function();
diff --git a/libssh/init.c b/libssh/init.c
index b6c99443..8d2ae032 100644
--- a/libssh/init.c
+++ b/libssh/init.c
@@ -32,11 +32,28 @@
*/
/**
+ * @brief initialize global cryptographic data structures.
+ *
+ * This function should only be called once, at the begining of the program, in the main thread. It may be omitted if your program is not multithreaded.
+ *
+ * @returns 0
+ */
+int ssh_init(void) {
+ if(ssh_crypto_init())
+ return -1;
+ if(ssh_socket_init())
+ return -1;
+ return 0;
+}
+
+
+/**
* @brief Finalize and cleanup all libssh and cryptographic data structures.
*
* This function should only be called once, at the end of the program!
*
- * @returns 0
+ * @returns -1 in case of error
+ @returns 0 otherwise
*/
int ssh_finalize(void) {
ssh_crypto_finalize();
diff --git a/libssh/server.c b/libssh/server.c
index f1c156f4..25021f68 100644
--- a/libssh/server.c
+++ b/libssh/server.c
@@ -135,7 +135,7 @@ int ssh_bind_listen(SSH_BIND *ssh_bind) {
return -1;
}
- if (ssh_socket_init() < 0) {
+ if (ssh_init() < 0) {
return -1;
}
@@ -479,10 +479,6 @@ int ssh_accept(SSH_SESSION *session) {
return -1;
}
- if (ssh_crypto_init() < 0) {
- return -1;
- }
-
session->alive = 1;
session->clientbanner = ssh_get_banner(session);