src: fixed ssl_accept handling

Change-Id: Ibebe79a3e740eded4238061ab5feac51d45af0d8
Signed-off-by: SJ <sj@acts.hu>
This commit is contained in:
SJ 2017-04-14 17:38:55 +02:00
parent 2165c810b2
commit 0489af6cbb

View File

@ -111,33 +111,38 @@ void process_data(struct smtp_session *session, char *readbuf, int readlen){
}
void send_smtp_response(struct smtp_session *session, char *buf){
void wait_for_ssl_accept(struct smtp_session *session){
int rc;
char ssl_error[SMALLBUFSIZE];
write1(session->socket, buf, strlen(buf), session->use_ssl, session->ssl);
if(session->cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "sent: %s", buf);
if(session->starttls == 1 && session->use_ssl == 0){
if(session->cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "waiting for ssl handshake");
rc = SSL_accept(session->ssl);
if(session->cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "SSL_accept() finished");
// Since we use non-blocking IO, SSL_accept() is likely to return with -1
// "In this case a call to SSL_get_error() with the return value of SSL_accept()
// will yield SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE."
//
// In this case we may proceed.
if(rc == 1){
if(rc == 1 || SSL_get_error(session->ssl, rc) == SSL_ERROR_WANT_READ){
session->use_ssl = 1;
}
else {
if(session->cfg->verbosity >= _LOG_DEBUG || session->use_ssl == 0){
ERR_error_string_n(ERR_get_error(), ssl_error, SMALLBUFSIZE);
syslog(LOG_PRIORITY, "%s: SSL_accept() failed, rc=%d, errorcode: %d, error text: %s\n", session->ttmpfile, rc, SSL_get_error(session->ssl, rc), ssl_error);
}
syslog(LOG_PRIORITY, "SSL_accept() result, rc=%d, errorcode: %d, error text: %s",
rc, SSL_get_error(session->ssl, rc), ssl_error);
}
}
void send_smtp_response(struct smtp_session *session, char *buf){
write1(session->socket, buf, strlen(buf), session->use_ssl, session->ssl);
if(session->cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "sent: %s", buf);
}
void process_command_helo(struct smtp_session *session, char *buf, int buflen){
if(session->protocol_state == SMTP_STATE_INIT) session->protocol_state = SMTP_STATE_HELO;