summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2011-12-12 16:52:30 +0000
committerMarc-André Lureau <marcandre.lureau@redhat.com>2012-01-09 18:57:57 +0100
commit803be1bea790381e30ef0eb0752992736441b4ff (patch)
tree68042bcff741987e4b7b5e475f8f4ea9e0a9b5a5
parent3a3a32ebbc3dbb644bdf53394ce5f925a7398f3a (diff)
downloadspice-803be1bea790381e30ef0eb0752992736441b4ff.tar.gz
spice-803be1bea790381e30ef0eb0752992736441b4ff.tar.xz
spice-803be1bea790381e30ef0eb0752992736441b4ff.zip
Move SSL setup out of reds_accept_ssl_connection
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@redhat.com>
-rw-r--r--server/reds.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/server/reds.c b/server/reds.c
index fea09ad6..3ba55c1b 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;