From d79b1f97c7378254613f8d17301a0439c14d89bf Mon Sep 17 00:00:00 2001 From: SJ Date: Tue, 1 Jul 2014 11:43:36 +0200 Subject: [PATCH] verp fix --- src/avir.c | 2 +- src/config.h | 2 +- src/import.c | 5 +++++ src/misc.c | 1 + src/parser.c | 53 ++++++++++++++++----------------------------------- src/piler.h | 2 +- src/session.c | 16 ++++++---------- 7 files changed, 31 insertions(+), 50 deletions(-) diff --git a/src/avir.c b/src/avir.c index f0cd6f8a..8904bf1d 100644 --- a/src/avir.c +++ b/src/avir.c @@ -10,7 +10,7 @@ #include -int do_av_check(struct session_data *sdata, char *rcpttoemail, char *virusinfo, struct __data *data, struct __config *cfg){ +int do_av_check(struct session_data *sdata, char *virusinfo, struct __data *data, struct __config *cfg){ int rav = AVIR_OK; char avengine[SMALLBUFSIZE]; diff --git a/src/config.h b/src/config.h index 6a71769a..8fd9ae8b 100644 --- a/src/config.h +++ b/src/config.h @@ -14,7 +14,7 @@ #define VERSION "0.1.25-rc3" -#define BUILD 877 +#define BUILD 878 #define HOSTID "mailarchiver" diff --git a/src/import.c b/src/import.c index 66560630..c590e32b 100644 --- a/src/import.c +++ b/src/import.c @@ -28,6 +28,11 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da init_session_data(sdata, cfg); + if(data->import->extra_recipient){ + snprintf(sdata->rcptto[0], SMALLBUFSIZE-1, "%s", data->import->extra_recipient); + sdata->num_of_rcpt_to = 1; + } + if(cfg->verbosity > 1) printf("processing: %s\n", filename); if(strcmp(filename, "-") == 0){ diff --git a/src/misc.c b/src/misc.c index e2e1f93d..6efba741 100644 --- a/src/misc.c +++ b/src/misc.c @@ -211,6 +211,7 @@ int extractEmail(char *rawmail, char *email){ *p = '\0'; *q2 = '@'; snprintf(email, SMALLBUFSIZE-1, "%s", q1+1); + *p = '@'; return 1; } } diff --git a/src/parser.c b/src/parser.c index c6f068b1..43fcb36f 100644 --- a/src/parser.c +++ b/src/parser.c @@ -32,56 +32,35 @@ struct _state parse_message(struct session_data *sdata, int take_into_pieces, st } - if(sdata->import == 1 && data->import->extra_recipient){ - len = strlen(data->import->extra_recipient); - - addnode(state.journal_recipient, data->import->extra_recipient); - - memcpy(&(state.b_journal_to[state.journaltolen]), data->import->extra_recipient, len); - state.journaltolen += len; - memcpy(&(state.b_journal_to[state.journaltolen]), " ", 1); - state.journaltolen++; - strtolower(state.b_journal_to); - - memcpy(&(state.b_to[state.tolen]), data->import->extra_recipient, len); - state.tolen += len; - memcpy(&(state.b_to[state.tolen]), " ", 1); - state.tolen++; - strtolower(state.b_to); - } - - if(sdata->num_of_rcpt_to > 0){ for(i=0; inum_of_rcpt_to; i++){ - extractEmail(sdata->rcptto[i], puf); - if(strlen(puf) > 5){ + snprintf(puf, sizeof(puf)-1, "%s ", sdata->rcptto[i]); + + if(does_it_seem_like_an_email_address(puf) == 1){ p = strstr(puf, cfg->hostid); - if(p && *(p-1) == '.'){ - - *(p-1) = ' '; - *p = '\0'; + if(!p){ + strtolower(puf); len = strlen(puf); - if(does_it_seem_like_an_email_address(puf) == 1){ + if(state.tolen < MAXBUFSIZE-len-1){ - if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: processing rcpt to address: *%s*", sdata->ttmpfile, puf); + if(findnode(state.rcpt, puf) == NULL){ + addnode(state.journal_recipient, puf); - if(state.tolen < MAXBUFSIZE-len-1){ - if(findnode(state.rcpt, puf) == NULL){ - addnode(state.rcpt, puf); + memcpy(&(state.b_journal_to[state.journaltolen]), puf, len); + state.journaltolen += len; + + memcpy(&(state.b_to[state.tolen]), puf, len); + state.tolen += len; + + if(state.tolen < MAXBUFSIZE-len-1){ + split_email_address(puf); memcpy(&(state.b_to[state.tolen]), puf, len); state.tolen += len; - - if(state.tolen < MAXBUFSIZE-len-1){ - split_email_address(puf); - memcpy(&(state.b_to[state.tolen]), puf, len); - state.tolen += len; - } } } - } } } diff --git a/src/piler.h b/src/piler.h index e8b0a3e9..94821583 100644 --- a/src/piler.h +++ b/src/piler.h @@ -28,7 +28,7 @@ int read_key(struct __config *cfg); void insert_offset(struct session_data *sdata, int server_id); -int do_av_check(struct session_data *sdata, char *rcpttoemail, char *virusinfo, struct __data *data, struct __config *cfg); +int do_av_check(struct session_data *sdata, char *virusinfo, struct __data *data, struct __config *cfg); int make_digests(struct session_data *sdata, struct __config *cfg); void digest_file(char *filename, char *digest); diff --git a/src/session.c b/src/session.c index 127e776c..16ff463c 100644 --- a/src/session.c +++ b/src/session.c @@ -22,7 +22,7 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){ int i, ret, pos, n, inj=ERR, state, prevlen=0; char *p, buf[MAXBUFSIZE], puf[MAXBUFSIZE], resp[MAXBUFSIZE], prevbuf[MAXBUFSIZE], last2buf[2*MAXBUFSIZE+1]; - char rcpttoemail[SMALLBUFSIZE], virusinfo[SMALLBUFSIZE], delay[SMALLBUFSIZE]; + char virusinfo[SMALLBUFSIZE], delay[SMALLBUFSIZE]; char *arule = NULL; char *status = NULL; struct session_data sdata; @@ -167,7 +167,7 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){ remove_stripped_attachments(&sstate); inj = ERR_MYDOMAINS; - snprintf(sdata.acceptbuf, SMALLBUFSIZE-1, "250 Ok %s <%s>\r\n", sdata.ttmpfile, rcpttoemail); + snprintf(sdata.acceptbuf, SMALLBUFSIZE-1, "250 Ok %s\r\n", sdata.ttmpfile); write1(new_sd, sdata.acceptbuf, strlen(sdata.acceptbuf), sdata.tls, data->ssl); syslog(LOG_PRIORITY, "%s: discarding: not on mydomains, from=%s, message-id=%s", sdata.ttmpfile, sdata.fromemail, sstate.message_id); @@ -182,7 +182,7 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){ #ifdef HAVE_ANTIVIRUS if(cfg->use_antivirus == 1){ gettimeofday(&tv1, &tz); - sdata.rav = do_av_check(&sdata, rcpttoemail, &virusinfo[0], data, cfg); + sdata.rav = do_av_check(&sdata, &virusinfo[0], data, cfg); gettimeofday(&tv2, &tz); sdata.__av = tvdiff(tv2, tv1); } @@ -197,8 +197,6 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){ #endif if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: round %d in injection", sdata.ttmpfile, i); - extractEmail(sdata.rcptto[i], rcpttoemail); - inj = ERR; status = S_STATUS_UNDEF; @@ -249,10 +247,10 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){ /* set the accept buffer */ - snprintf(sdata.acceptbuf, SMALLBUFSIZE-1, "250 Ok %s <%s>\r\n", sdata.ttmpfile, rcpttoemail); + snprintf(sdata.acceptbuf, SMALLBUFSIZE-1, "250 Ok %s <%s>\r\n", sdata.ttmpfile, sdata.rcptto[i]); if(inj == ERR){ - snprintf(sdata.acceptbuf, SMALLBUFSIZE-1, "451 %s <%s>\r\n", sdata.ttmpfile, rcpttoemail); + snprintf(sdata.acceptbuf, SMALLBUFSIZE-1, "451 %s <%s>\r\n", sdata.ttmpfile, sdata.rcptto[i]); status = S_STATUS_ERROR; } @@ -418,13 +416,11 @@ AFTER_PERIOD: } if(sdata.num_of_rcpt_to < MAX_RCPT_TO-1){ - snprintf(sdata.rcptto[sdata.num_of_rcpt_to], SMALLBUFSIZE-1, "%s\r\n", buf); + extractEmail(buf, sdata.rcptto[sdata.num_of_rcpt_to]); } state = SMTP_STATE_RCPT_TO; - extractEmail(buf, rcpttoemail); - if(sdata.num_of_rcpt_to < MAX_RCPT_TO-1) sdata.num_of_rcpt_to++;