Further improved the session timeout handling

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2021-02-17 05:42:56 +01:00
parent 50a2328f64
commit 1283e33e50
2 changed files with 8 additions and 9 deletions

View File

@ -40,6 +40,7 @@ struct passwd *pwd;
struct smtp_session *session, **sessions=NULL; struct smtp_session *session, **sessions=NULL;
struct smtp_acl *smtp_acl[MAXHASH]; struct smtp_acl *smtp_acl[MAXHASH];
time_t prev_timeout_check = 0;
void usage(){ void usage(){
printf("\nusage: piler\n\n"); printf("\nusage: piler\n\n");
@ -90,6 +91,8 @@ void check_for_client_timeout(){
if(cfg.verbosity >= LOG_DEBUG) syslog(LOG_PRIORITY, "%s @%ld", __func__, now); if(cfg.verbosity >= LOG_DEBUG) syslog(LOG_PRIORITY, "%s @%ld", __func__, now);
if(now - prev_timeout_check < cfg.smtp_timeout) return;
if(num_connections > 0){ if(num_connections > 0){
for(int i=0; i<cfg.max_connections; i++){ for(int i=0; i<cfg.max_connections; i++){
if(sessions[i] && now - sessions[i]->lasttime >= cfg.smtp_timeout){ if(sessions[i] && now - sessions[i]->lasttime >= cfg.smtp_timeout){
@ -98,6 +101,8 @@ void check_for_client_timeout(){
} }
} }
} }
time(&prev_timeout_check);
} }
@ -194,6 +199,7 @@ int main(int argc, char **argv){
set_signal_handler(SIGSEGV, p_clean_exit); set_signal_handler(SIGSEGV, p_clean_exit);
set_signal_handler(SIGPIPE, SIG_IGN); set_signal_handler(SIGPIPE, SIG_IGN);
set_signal_handler(SIGALRM, SIG_IGN);
set_signal_handler(SIGHUP, initialise_configuration); set_signal_handler(SIGHUP, initialise_configuration);
@ -216,7 +222,7 @@ int main(int argc, char **argv){
#endif #endif
for(;;){ for(;;){
int n = epoll_wait(efd, events, cfg.max_connections, 10000); int n = epoll_wait(efd, events, cfg.max_connections, 1000);
for(i=0; i<n; i++){ for(i=0; i<n; i++){
// Office365 sometimes behaves oddly: when it receives the 250 OK // Office365 sometimes behaves oddly: when it receives the 250 OK
@ -295,8 +301,6 @@ int main(int argc, char **argv){
time(&(session->lasttime)); time(&(session->lasttime));
while(1){ while(1){
memset(readbuf, 0, sizeof(readbuf));
if(session->net.use_ssl == 1) if(session->net.use_ssl == 1)
readlen = SSL_read(session->net.ssl, (char*)&readbuf[0], sizeof(readbuf)-1); readlen = SSL_read(session->net.ssl, (char*)&readbuf[0], sizeof(readbuf)-1);
else else

View File

@ -119,23 +119,17 @@ void init_smtp_session(struct smtp_session *session, int slot, int sd, char *cli
void free_smtp_session(struct smtp_session *session){ void free_smtp_session(struct smtp_session *session){
if(session){ if(session){
syslog(LOG_PRIORITY, "free_smtp_session()");
if(session->net.use_ssl == 1){ if(session->net.use_ssl == 1){
syslog(LOG_PRIORITY, "SSL_shutdown()");
SSL_shutdown(session->net.ssl); SSL_shutdown(session->net.ssl);
SSL_free(session->net.ssl); SSL_free(session->net.ssl);
syslog(LOG_PRIORITY, "SSL_free()");
} }
if(session->net.ctx){ if(session->net.ctx){
syslog(LOG_PRIORITY, "SSL_CTX_free");
SSL_CTX_free(session->net.ctx); SSL_CTX_free(session->net.ctx);
} }
syslog(LOG_PRIORITY, "freeing session");
free(session); free(session);
syslog(LOG_PRIORITY, "free(session) done");
} }
} }
@ -183,6 +177,7 @@ void handle_data(struct smtp_session *session, char *readbuf, int readlen, struc
p = &copybuf[0]; p = &copybuf[0];
} }
else { else {
readbuf[readlen] = 0;
p = readbuf; p = readbuf;
} }