diff --git a/src/cert.c b/src/cert.c index 6922e88..51acf3f 100644 --- a/src/cert.c +++ b/src/cert.c @@ -36,7 +36,7 @@ get_cert(session *ssn) mdlen = 0; - if (!(cert = SSL_get_peer_certificate(ssn->sslsocket))) + if (!(cert = SSL_get_peer_certificate(ssn->sslconn))) return -1; if (!(X509_digest(cert, EVP_md5(), md, &mdlen))) diff --git a/src/request.c b/src/request.c index 9fcc719..6c6fc2c 100644 --- a/src/request.c +++ b/src/request.c @@ -158,11 +158,11 @@ request_login(session **ssnptr, const char *server, const char *port, const if ((!strncasecmp(ssl, "tls1", 4) || !strncasecmp(ssl, "ssl3", 4) || !strncasecmp(ssl, "ssl2", 4))) - ssn->ssl = ssl; + ssn->sslproto = ssl; } else { - debug("recovering connection: %s://%s@%s:%s/%s\n", ssn->ssl ? - "imaps" : "imap", ssn->username, ssn->server, ssn->port, - ssn->selected ? ssn->selected : ""); + debug("recovering connection: %s://%s@%s:%s/%s\n", + ssn->sslproto ?"imaps" : "imap", ssn->username, ssn->server, + ssn->port, ssn->selected ? ssn->selected : ""); } if (open_connection(ssn) == -1) @@ -181,7 +181,7 @@ request_login(session **ssnptr, const char *server, const char *port, const if (response_capability(ssn, t) == -1) goto fail; - if (!ssn->ssl && ssn->capabilities & CAPABILITY_STARTTLS && + if (!ssn->sslproto && ssn->capabilities & CAPABILITY_STARTTLS && get_option_boolean("starttls")) { t = send_request(ssn, "STARTTLS"); switch (response_generic(ssn, t)) { diff --git a/src/session.c b/src/session.c index 9454902..15a2c1e 100644 --- a/src/session.c +++ b/src/session.c @@ -37,11 +37,11 @@ session_init(session *ssn) ssn->server = NULL; ssn->port = NULL; - ssn->ssl = NULL; + ssn->sslproto = NULL; ssn->username = NULL; ssn->password = NULL; ssn->socket = -1; - ssn->sslsocket = NULL; + ssn->sslconn = NULL; ssn->protocol = PROTOCOL_NONE; ssn->capabilities = CAPABILITY_NONE; ssn->ns.prefix = NULL; diff --git a/src/session.h b/src/session.h index ba1fe50..8714a86 100644 --- a/src/session.h +++ b/src/session.h @@ -9,11 +9,11 @@ typedef struct session { const char *server; /* Server hostname. */ const char *port; /* Server port. */ - const char *ssl; /* SSL protocol. */ + const char *sslproto; /* SSL protocol. */ const char *username; /* User name. */ const char *password; /* User password. */ int socket; /* Socket. */ - SSL *sslsocket; /* SSL socket. */ + SSL *sslconn; /* SSL connection. */ unsigned int protocol; /* IMAP protocol. Currently IMAP4rev1 and * IMAP4 are supported. */ unsigned int capabilities; /* Capabilities of the mail server. */ diff --git a/src/socket.c b/src/socket.c index ba9fb61..7c0794a 100644 --- a/src/socket.c +++ b/src/socket.c @@ -66,7 +66,7 @@ open_connection(session *ssn) ssn->socket = sockfd; - if (ssn->ssl) { + if (ssn->sslproto) { if (open_secure_connection(ssn) == -1) { close_connection(ssn); return -1; @@ -89,8 +89,8 @@ open_secure_connection(session *ssn) method = NULL; - if (ssn->ssl && (!strncasecmp(ssn->ssl, "ssl3", 4) || - !strncasecmp(ssn->ssl, "ssl2", 4))) + if (ssn->sslproto && (!strncasecmp(ssn->sslproto, "ssl3", 4) || + !strncasecmp(ssn->sslproto, "ssl2", 4))) method = SSLv23_client_method(); else method = TLSv1_client_method(); @@ -98,16 +98,16 @@ open_secure_connection(session *ssn) if (!(ctx = SSL_CTX_new(method))) goto fail; - if (!(ssn->sslsocket = SSL_new(ctx))) + if (!(ssn->sslconn = SSL_new(ctx))) goto fail; - SSL_set_fd(ssn->sslsocket, ssn->socket); + SSL_set_fd(ssn->sslconn, ssn->socket); for (;;) { - if ((r = SSL_connect(ssn->sslsocket)) > 0) + if ((r = SSL_connect(ssn->sslconn)) > 0) break; - switch (SSL_get_error(ssn->sslsocket, r)) { + switch (SSL_get_error(ssn->sslconn, r)) { case SSL_ERROR_ZERO_RETURN: error("initiating SSL connection to %s; the " "connection has been closed cleanly\n", @@ -149,7 +149,7 @@ open_secure_connection(session *ssn) return 0; fail: - ssn->sslsocket = NULL; + ssn->sslconn = NULL; SSL_CTX_free(ctx); return -1; @@ -186,10 +186,10 @@ int close_secure_connection(session *ssn) { - if (ssn->sslsocket) { - SSL_shutdown(ssn->sslsocket); - SSL_free(ssn->sslsocket); - ssn->sslsocket = NULL; + if (ssn->sslconn) { + SSL_shutdown(ssn->sslconn); + SSL_free(ssn->sslconn); + ssn->sslconn = NULL; } return 0; @@ -225,8 +225,8 @@ socket_read(session *ssn, char *buf, size_t len, long timeout, int timeoutfail) FD_ZERO(&fds); FD_SET(ssn->socket, &fds); - if (ssn->sslsocket) { - if (SSL_pending(ssn->sslsocket) > 0 || + if (ssn->sslconn) { + if (SSL_pending(ssn->sslconn) > 0 || ((s = select(ssn->socket + 1, &fds, NULL, NULL, tvp)) > 0 && FD_ISSET(ssn->socket, &fds))) { r = socket_secure_read(ssn, buf, len); @@ -274,13 +274,13 @@ socket_secure_read(session *ssn, char *buf, size_t len) int r, e; for (;;) { - if ((r = (ssize_t) SSL_read(ssn->sslsocket, buf, len)) > 0) + if ((r = (ssize_t) SSL_read(ssn->sslconn, buf, len)) > 0) break; - switch (SSL_get_error(ssn->sslsocket, r)) { + switch (SSL_get_error(ssn->sslconn, r)) { case SSL_ERROR_ZERO_RETURN: - error("reading data through SSL; the connection has been " - "closed cleanly\n"); + error("reading data through SSL; the connection has " + "been closed cleanly\n"); goto fail; case SSL_ERROR_NONE: case SSL_ERROR_WANT_READ: @@ -292,10 +292,11 @@ socket_secure_read(session *ssn, char *buf, size_t len) case SSL_ERROR_SYSCALL: e = ERR_get_error(); if (e == 0 && r == 0) - error("reading data through SSL; EOF in violation of " - "the protocol\n"); + error("reading data through SSL; EOF in " + "violation of the protocol\n"); else if (e == 0 && r == -1) - error("reading data through SSL; %s\n", strerror(errno)); + error("reading data through SSL; %s\n", + strerror(errno)); else error("reading data through SSL; %s\n", ERR_error_string(e, NULL)); @@ -311,7 +312,8 @@ socket_secure_read(session *ssn, char *buf, size_t len) return r; fail: - SSL_set_shutdown(ssn->sslsocket, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN); + SSL_set_shutdown(ssn->sslconn, SSL_SENT_SHUTDOWN | + SSL_RECEIVED_SHUTDOWN); return -1; @@ -337,7 +339,7 @@ socket_write(session *ssn, const char *buf, size_t len) while (len) { if ((s = select(ssn->socket + 1, NULL, &fds, NULL, NULL) > 0 && FD_ISSET(ssn->socket, &fds))) { - if (ssn->sslsocket) { + if (ssn->sslconn) { r = socket_secure_write(ssn, buf, len); if (r <= 0) @@ -387,13 +389,13 @@ socket_secure_write(session *ssn, const char *buf, size_t len) int r, e; for (;;) { - if ((r = (ssize_t) SSL_write(ssn->sslsocket, buf, len)) > 0) + if ((r = (ssize_t) SSL_write(ssn->sslconn, buf, len)) > 0) break; - switch (SSL_get_error(ssn->sslsocket, r)) { + switch (SSL_get_error(ssn->sslconn, r)) { case SSL_ERROR_ZERO_RETURN: - error("writing data through SSL; the connection has been " - "closed cleanly\n"); + error("writing data through SSL; the connection has " + "been closed cleanly\n"); goto fail; case SSL_ERROR_NONE: case SSL_ERROR_WANT_READ: @@ -405,10 +407,11 @@ socket_secure_write(session *ssn, const char *buf, size_t len) case SSL_ERROR_SYSCALL: e = ERR_get_error(); if (e == 0 && r == 0) - error("writing data through SSL; EOF in violation of " - "the protocol\n"); + error("writing data through SSL; EOF in " + "violation of the protocol\n"); else if (e == 0 && r == -1) - error("writing data through SSL; %s\n", strerror(errno)); + error("writing data through SSL; %s\n", + strerror(errno)); else error("writing data through SSL; %s\n", ERR_error_string(e, NULL)); @@ -424,7 +427,8 @@ socket_secure_write(session *ssn, const char *buf, size_t len) return r; fail: - SSL_set_shutdown(ssn->sslsocket, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN); + SSL_set_shutdown(ssn->sslconn, SSL_SENT_SHUTDOWN | + SSL_RECEIVED_SHUTDOWN); return -1; }