BDAT fixes

Change-Id: Ifd5f7342378a2feddafa1faba69645107bee90a1
Signed-off-by: SJ <sj@acts.hu>
This commit is contained in:
SJ 2016-08-19 23:27:24 +02:00
parent 02bc3cffa7
commit 8695663104
2 changed files with 9 additions and 6 deletions

View File

@ -261,13 +261,14 @@ AFTER_PERIOD:
if(cfg->enable_chunking == 1 && strncasecmp(buf, SMTP_CMD_BDAT, strlen(SMTP_CMD_BDAT)) == 0){ if(cfg->enable_chunking == 1 && strncasecmp(buf, SMTP_CMD_BDAT, strlen(SMTP_CMD_BDAT)) == 0){
process_command_bdat(sctx, &sdata, data, &protocol_state, buf, &resp[0], sizeof(resp)-1); process_command_bdat(sctx, &sdata, data, &protocol_state, buf, &resp[0], sizeof(resp)-1);
if(protocol_state == SMTP_STATE_BDAT){ if(protocol_state == SMTP_STATE_BDAT){
snprintf(resp, sizeof(resp)-2, "250 octets received\r\n");
for(i=0; i<sctx->bdat_rounds-1; i++){ for(i=0; i<sctx->bdat_rounds-1; i++){
send_buffered_response(&sdata, data, starttls, sctx->new_sd, &resp[0], cfg); syslog(LOG_INFO, "%d, sending bdat response", i);
write1(sctx->new_sd, "250 octets received\r\n", strlen("250 octets received\r\n"), sdata.tls, data->ssl);
} }
process_written_file(sctx, &sdata, data, cfg); process_written_file(sctx, &sdata, data, cfg);

View File

@ -138,7 +138,7 @@ void process_command_bdat(struct session_ctx *sctx, struct session_data *sdata,
int n, expected_bdat_len; int n, expected_bdat_len;
char puf[MAXBUFSIZE]; char puf[MAXBUFSIZE];
if(*protocol_state == SMTP_STATE_RCPT_TO){ if(*protocol_state != SMTP_STATE_RCPT_TO){
strncat(resp, SMTP_RESP_503_ERR, resplen); strncat(resp, SMTP_RESP_503_ERR, resplen);
return; return;
} }
@ -166,15 +166,15 @@ void process_command_bdat(struct session_ctx *sctx, struct session_data *sdata,
else if(sctx->bdat_last_round != 1){ else if(sctx->bdat_last_round != 1){
if((n = recvtimeoutssl(sctx->new_sd, &puf[0], sizeof(puf), TIMEOUT, sdata->tls, data->ssl)) > 0){ if((n = recvtimeoutssl(sctx->new_sd, &puf[0], sizeof(puf), TIMEOUT, sdata->tls, data->ssl)) > 0){
expected_bdat_len = extract_bdat_command(sctx, sdata, puf); expected_bdat_len = extract_bdat_command(sctx, sdata, puf);
if(expected_bdat_len <= 0 && sctx->bdat_rounds > 0) sctx->bdat_rounds--;
} }
} }
if(expected_bdat_len > 0) sdata->tot_len += read_bdat_data(sctx, sdata, data, expected_bdat_len); if(expected_bdat_len > 0) sdata->tot_len += read_bdat_data(sctx, sdata, data, expected_bdat_len);
} }
close(sdata->fd);
fsync(sdata->fd); fsync(sdata->fd);
close(sdata->fd);
} }
@ -184,7 +184,7 @@ int extract_bdat_command(struct session_ctx *sctx, struct session_data *sdata, c
// determine if this is the last BDAT command // determine if this is the last BDAT command
p = strstr(buf, " LAST"); p = strcasestr(buf, " LAST");
if(p){ if(p){
sctx->bdat_last_round = 1; sctx->bdat_last_round = 1;
syslog(LOG_INFO, "%s: BDAT LAST", sdata->ttmpfile); syslog(LOG_INFO, "%s: BDAT LAST", sdata->ttmpfile);
@ -219,6 +219,8 @@ int read_bdat_data(struct session_ctx *sctx, struct session_data *sdata, struct
} }
} }
syslog(LOG_INFO, "%s: wrote %d bytes of BDAT data", sdata->ttmpfile, written_bdat_len);
return written_bdat_len; return written_bdat_len;
} }