From: Thadeu Lima de Souza Cascardo Date: Mon, 20 Jul 2009 18:37:43 +0000 (-0300) Subject: Only connect to server when SSL handshake is completed. X-Git-Tag: v0.1.3~7 X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Frnetproxy.git;a=commitdiff_plain;h=420d54ee44ea5495b62e3539df67b9bc3bffba99 Only connect to server when SSL handshake is completed. --- diff --git a/popproxy.c b/popproxy.c index d2ccbf7..5e3a91f 100644 --- a/popproxy.c +++ b/popproxy.c @@ -130,11 +130,34 @@ push_other (HCConn *conn, HCEvent event, gpointer data) } } +static void +ssl_connected (HCConn *client_conn, HCEvent event, gpointer data) +{ + struct pop_address *address = data; + HCConn *server_conn; + if (event != HC_EVENT_CONNECT) + { + g_debug ("Did not get connect event when trying to handshake:" + " got %d", event); + hc_conn_close (client_conn); + return; + } + server_conn = server_conn_new (address->server, address->port, + address->ssl); + if (server_conn == NULL) + { + g_debug ("Failure to create connection to server."); + hc_conn_close (client_conn); + return; + } + hc_conn_set_callback (client_conn, push_other, server_conn); + hc_conn_set_callback (server_conn, push_other, client_conn); +} + static void new_client (int fd, struct sockaddr *addr, socklen_t saddr, gpointer data) { HCConn *client_conn; - HCConn *server_conn; struct pop_address *address = data; if (fd < 0) { @@ -146,21 +169,16 @@ new_client (int fd, struct sockaddr *addr, socklen_t saddr, gpointer data) g_message ("Received connection from %s.", inet_ntoa (((struct sockaddr_in *) addr)->sin_addr)); - server_conn = server_conn_new (address->server, address->port, - address->ssl); - if (server_conn == NULL) - { - return; - } client_conn = client_conn_new (fd); if (client_conn == NULL) { - hc_conn_close (server_conn); return; } - hc_conn_set_callback (client_conn, push_other, server_conn); - hc_conn_set_callback (server_conn, push_other, client_conn); + if (address->ssl) + hc_conn_set_callback (client_conn, ssl_connected, address); + else + ssl_connected (client_conn, HC_EVENT_CONNECT, address); }