aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormilo <milo@r0ot.me>2010-08-10 00:14:03 +0200
committerAndreas Schneider <asn@cynapses.org>2010-08-10 00:30:25 +0200
commit855b73de8745adfef145dba0b07ab37dcb83c142 (patch)
tree866f428455b401c6f143864765e77f43e8cad9e7
parent136f4d3b0d7475ae212dcf824c3ff624a97a08ad (diff)
downloadlibssh-855b73de8745adfef145dba0b07ab37dcb83c142.tar.gz
libssh-855b73de8745adfef145dba0b07ab37dcb83c142.tar.xz
libssh-855b73de8745adfef145dba0b07ab37dcb83c142.zip
server: Split ssh_bind_accept and create ssh_handle_key_exchange.
Signed-off-by: Andreas Schneider <asn@cynapses.org>
-rw-r--r--examples/samplesshd.c4
-rw-r--r--include/libssh/server.h11
-rw-r--r--libssh/legacy.c4
-rw-r--r--libssh/server.c9
4 files changed, 23 insertions, 5 deletions
diff --git a/examples/samplesshd.c b/examples/samplesshd.c
index 1af866c..6f540c7 100644
--- a/examples/samplesshd.c
+++ b/examples/samplesshd.c
@@ -205,6 +205,10 @@ int main(int argc, char **argv){
printf("error accepting a connection : %s\n",ssh_get_error(sshbind));
return 1;
}
+ if (ssh_bind_accept(session)) {
+ printf("ssh_bind_accept: %s\n", ssh_get_error(session));
+ return 1;
+ }
do {
message=ssh_message_get(session);
if(!message)
diff --git a/include/libssh/server.h b/include/libssh/server.h
index 1079165..70b4bd6 100644
--- a/include/libssh/server.h
+++ b/include/libssh/server.h
@@ -120,11 +120,20 @@ LIBSSH_API void ssh_bind_fd_toaccept(ssh_bind ssh_bind_o);
* @param ssh_bind_o The ssh server bind to accept a connection.
* @param session A preallocated ssh session
* @see ssh_new
- * @return A newly allocated ssh session, NULL on error.
+ * @return SSH_OK when a connection is established
*/
LIBSSH_API int ssh_bind_accept(ssh_bind ssh_bind_o, ssh_session session);
/**
+ * @brief Handles the key exchange and set up encryption
+ *
+ * @param session A connected ssh session
+ * @see ssh_bind_accept
+ * @return SSH_OK if the key exchange was successful
+ */
+LIBSSH_API int ssh_handle_key_exchange(ssh_session session);
+
+/**
* @brief Free a ssh servers bind.
*
* @param ssh_bind_o The ssh server bind to free.
diff --git a/libssh/legacy.c b/libssh/legacy.c
index b2ecc0e..83fb97a 100644
--- a/libssh/legacy.c
+++ b/libssh/legacy.c
@@ -233,7 +233,5 @@ char *string_to_char(ssh_string str){
}
int ssh_accept(ssh_session session) {
- (void) session;
-
- return SSH_OK;
+ return ssh_handle_key_exchange(session);
}
diff --git a/libssh/server.c b/libssh/server.c
index f0b6237..f6ddf3d 100644
--- a/libssh/server.c
+++ b/libssh/server.c
@@ -666,7 +666,7 @@ int ssh_bind_accept(ssh_bind sshbind, ssh_session session) {
ssh_private_key dsa = NULL;
ssh_private_key rsa = NULL;
socket_t fd = SSH_INVALID_SOCKET;
- int i, rc;
+ int i;
if (sshbind->bindfd == SSH_INVALID_SOCKET) {
ssh_set_error(sshbind, SSH_FATAL,
@@ -747,6 +747,13 @@ int ssh_bind_accept(ssh_bind sshbind, ssh_session session) {
session->dsa_key = dsa;
session->rsa_key = rsa;
+return SSH_OK;
+}
+
+/* Do the banner and key exchange */
+int ssh_handle_key_exchange(ssh_session session) {
+ int rc;
+
rc = ssh_send_banner(session, 1);
if (rc < 0) {
return SSH_ERROR;