[Spice-devel] [PATCH 3/6] Move SSL setup out of reds_accept_ssl_connection
Daniel P. Berrange
berrange at redhat.com
Mon Dec 12 08:52:30 PST 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 fea09ad..3ba55c1 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -2729,18 +2729,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)
@@ -2768,7 +2762,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);
@@ -2778,7 +2772,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);
@@ -2786,12 +2780,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.7.3
More information about the Spice-devel
mailing list