[Spice-devel] [PATCH 3/6] Move SSL setup out of reds_accept_ssl_connection

Daniel P. Berrange berrange at redhat.com
Fri Oct 28 05:09:47 PDT 2011


From: "Daniel P. Berrange" <berrange at redhat.com>

To allow setup of an SSL client, from a passed in client
socket, move all the SSL client initialization code out
of reds_accept_ssl_connection and into a new method called
reds_init_client_ssl_connection

* server/reds.c: Introduce reds_init_client_ssl_connection

Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
---
 server/reds.c |   31 +++++++++++++++++++++----------
 1 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/server/reds.c b/server/reds.c
index e7c9512..977ff90 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -2624,18 +2624,12 @@ error:
 }
 
 
-static void reds_accept_ssl_connection(int fd, int event, void *data)
+static RedLinkInfo *reds_init_client_ssl_connection(int socket)
 {
     RedLinkInfo *link;
     int return_code;
     int ssl_error;
     BIO *sbio;
-    int socket;
-
-    if ((socket = accept(reds->secure_listen_socket, NULL, 0)) == -1) {
-        red_printf("accept failed, %s", strerror(errno));
-        return;
-    }
 
     link = reds_init_client_connection(socket);
     if (link == NULL)
@@ -2663,7 +2657,7 @@ static void reds_accept_ssl_connection(int fd, int event, void *data)
     return_code = SSL_accept(link->stream->ssl);
     if (return_code == 1) {
         reds_handle_new_link(link);
-        return;
+        return link;
     }
 
     ssl_error = SSL_get_error(link->stream->ssl, return_code);
@@ -2673,7 +2667,7 @@ static void reds_accept_ssl_connection(int fd, int event, void *data)
             SPICE_WATCH_EVENT_READ : SPICE_WATCH_EVENT_WRITE;
         link->stream->watch = core->watch_add(link->stream->socket, eventmask,
                                             reds_handle_ssl_accept, link);
-        return;
+        return link;
     }
 
     ERR_print_errors_fp(stderr);
@@ -2681,12 +2675,29 @@ static void reds_accept_ssl_connection(int fd, int event, void *data)
     SSL_free(link->stream->ssl);
 
 error:
-    close(socket);
     free(link->stream);
     BN_free(link->tiTicketing.bn);
     free(link);
+    return NULL;
+}
+
+static void reds_accept_ssl_connection(int fd, int event, void *data)
+{
+    RedLinkInfo *link;
+    int socket;
+
+    if ((socket = accept(reds->secure_listen_socket, NULL, 0)) == -1) {
+        red_printf("accept failed, %s", strerror(errno));
+        return;
+    }
+
+    if (!(link = reds_init_client_ssl_connection(socket))) {
+        close(socket);
+        return;
+    }
 }
 
+
 static void reds_accept(int fd, int event, void *data)
 {
     RedLinkInfo *link;
-- 
1.7.6.4



More information about the Spice-devel mailing list