Skip to content

Commit ff924a2

Browse files
committed
ssl cleanups
1 parent 7545d10 commit ff924a2

File tree

2 files changed

+19
-40
lines changed

2 files changed

+19
-40
lines changed

src/clientbase.c

+2-25
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,8 @@ extern SSL_CTX *tls_context;
3737
static void dm_tls_error(void)
3838
{
3939
unsigned long e;
40-
e = ERR_get_error();
41-
if (e == 0) {
42-
if (errno != 0) {
43-
int se = errno;
44-
switch (se) {
45-
case EAGAIN:
46-
case EINTR:
47-
break;
48-
default:
49-
TRACE(TRACE_INFO, "%s", strerror(se));
50-
break;
51-
}
52-
} else {
53-
TRACE(TRACE_INFO, "Unknown error");
54-
}
55-
return;
56-
}
57-
TRACE(TRACE_INFO, "%s", ERR_error_string(e, NULL));
40+
while ((e = ERR_get_error()))
41+
TRACE(TRACE_INFO, "%s", ERR_error_string(e, NULL));
5842
}
5943

6044
size_t client_wbuf_len(ClientBase_T *client)
@@ -368,13 +352,6 @@ void ci_read_cb(ClientBase_T *client)
368352
int64_t t = 0;
369353
char ibuf[IBUFLEN];
370354

371-
TRACE(TRACE_DEBUG,"[%p] reset timeout [%ld]", client, client->timeout->tv_sec);
372-
373-
if (client->sock->ssl && client->sock->ssl_state == FALSE) {
374-
ci_starttls(client);
375-
return;
376-
}
377-
378355
while (TRUE) {
379356
memset(ibuf, 0, sizeof(ibuf));
380357
if (client->sock->ssl) {

src/imap4.c

+17-15
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ const IMAP_COMMAND_HANDLER imap_handler_functions[] = {
131131
static int imap4_tokenizer(ImapSession *, char *);
132132
static int imap4(ImapSession *);
133133
static void imap_handle_input(ImapSession *);
134+
static void imap_handle_abort(ImapSession *);
134135

135136
void imap_cleanup_deferred(gpointer data)
136137
{
@@ -189,9 +190,11 @@ void socket_write_cb(int UNUSED fd, short UNUSED what, void *arg)
189190
case CLIENTSTATE_QUIT_QUEUED:
190191
break; // ignore
191192
case CLIENTSTATE_LOGOUT:
192-
case CLIENTSTATE_ERROR:
193193
imap_session_bailout(session);
194194
break;
195+
case CLIENTSTATE_ERROR:
196+
imap_handle_abort(session);
197+
break;
195198
default:
196199
ci_write_cb(session->ci);
197200
break;
@@ -213,8 +216,7 @@ void imap_cb_read(void *arg)
213216
TRACE(TRACE_DEBUG,"state [%d] enough %d: %" PRIu64 "/%" PRIu64 "", state, enough, have, need);
214217

215218
if (state & CLIENT_ERR) {
216-
dbmail_imap_session_set_state(session,CLIENTSTATE_ERROR);
217-
imap_session_bailout(session);
219+
imap_handle_abort(session);
218220
} else if (state & CLIENT_EOF) {
219221
ci_cork(session->ci);
220222
if (enough)
@@ -275,29 +277,29 @@ static void imap_session_reset(ImapSession *session)
275277
* only the main thread may write to the network event
276278
* worker threads must use an async queue
277279
*/
278-
static int64_t imap_session_printf(ImapSession * self, char * message, ...)
280+
static int64_t imap_session_printf(ImapSession * session, char * message, ...)
279281
{
280282
va_list ap, cp;
281283
uint64_t l;
282284
int e = 0;
283285

284-
p_string_truncate(self->buff, 0);
286+
p_string_truncate(session->buff, 0);
285287

286288
assert(message);
287289
va_start(ap, message);
288290
va_copy(cp, ap);
289-
p_string_append_vprintf(self->buff, message, cp);
291+
p_string_append_vprintf(session->buff, message, cp);
290292
va_end(cp);
291293
va_end(ap);
292294

293-
if ((e = ci_write(self->ci, (char *)p_string_str(self->buff))) < 0) {
295+
if ((e = ci_write(session->ci, (char *)p_string_str(session->buff))) < 0) {
294296
TRACE(TRACE_DEBUG, "ci_write failed [%s]", strerror(e));
295-
dbmail_imap_session_set_state(self,CLIENTSTATE_ERROR);
297+
imap_handle_abort(session);
296298
return e;
297299
}
298300

299-
l = p_string_len(self->buff);
300-
p_string_truncate(self->buff, 0);
301+
l = p_string_len(session->buff);
302+
p_string_truncate(session->buff, 0);
301303

302304
return (int64_t)l;
303305
}
@@ -360,7 +362,7 @@ static int checktag(const char *s)
360362
return 1;
361363
}
362364

363-
static void imap_handle_abort(ImapSession *session)
365+
void imap_handle_abort(ImapSession *session)
364366
{
365367
dbmail_imap_session_set_state(session,CLIENTSTATE_ERROR); /* fatal error occurred, kick this user */
366368
imap_session_reset(session);
@@ -375,7 +377,7 @@ static void imap_handle_continue(ImapSession *session)
375377
if ((e = ci_write(session->ci, (char *)p_string_str(session->buff))) < 0) {
376378
int serr = errno;
377379
TRACE(TRACE_DEBUG,"ci_write returned error [%s]", strerror(serr));
378-
dbmail_imap_session_set_state(session,CLIENTSTATE_ERROR);
380+
imap_handle_abort(session);
379381
return;
380382
}
381383
dbmail_imap_session_buff_clear(session);
@@ -493,8 +495,8 @@ void imap_handle_input(ImapSession *session)
493495
if (l == 0) break; // done
494496

495497
if (session->error_count >= MAX_FAULTY_RESPONSES) {
496-
dbmail_imap_session_set_state(session,CLIENTSTATE_ERROR);
497498
imap_session_printf(session, "* BYE [TRY RFC]\r\n");
499+
imap_handle_abort(session);
498500
break;
499501
}
500502

@@ -660,7 +662,7 @@ void _ic_cb_leave(gpointer data)
660662
);
661663

662664
if (state & CLIENT_ERR) {
663-
dbmail_imap_session_set_state(session,CLIENTSTATE_ERROR);
665+
imap_handle_abort(session);
664666
return;
665667
}
666668

@@ -710,7 +712,7 @@ int imap4(ImapSession *session)
710712
int j = 0;
711713

712714
if (! dm_db_ping()) {
713-
dbmail_imap_session_set_state(session,CLIENTSTATE_ERROR);
715+
imap_handle_abort(session);
714716
return DM_EQUERY;
715717
}
716718

0 commit comments

Comments
 (0)