diff options
-rw-r--r-- | NEWS | 12 | ||||
-rw-r--r-- | TODO.txt | 2 | ||||
-rw-r--r-- | etrn.c | 2 | ||||
-rw-r--r-- | odmr.c | 2 | ||||
-rw-r--r-- | sink.c | 10 | ||||
-rw-r--r-- | smtp.c | 42 | ||||
-rw-r--r-- | smtp.h | 12 |
7 files changed, 55 insertions, 27 deletions
@@ -81,6 +81,18 @@ fetchmail 6.3.10 (not yet released): * Non-delivery notice ("bounce mail") now mentions the original reason again, before the address list. This fixes a regression introduced in 6.3.0. * Several compiler warnings were fixed. +* The minimum recommended SMTP (RFC-5321) timeouts are enforced to leave + sufficient time for the listener to respond. Some synchronous listeners, + particularly when used with spam filtering and other policy enforcement + services, take extended amounts of time to process messages after the sender, + recipient, or data block and EOM line. This can cause fetchmail to not wait + long enough for the "250 Ok" and make fetchmail believe the message wasn't + properly delivered when in fact it was; fetchmail would then retry the + download next time and never make progress. + Fixes Berlios Bug #10972, reported by Viktor Binzberger. +* The ESMTP/LMTP client will now apply an application-specific timeout while + waiting for the EHLO/LHLO response, rather than wait for the server or TCP + connection timeout. # CHANGES * Make the comparison of the SSL fingerprints case insensitive, to @@ -1,8 +1,6 @@ Note that there is a separate todo.html with different content than this. soon - MUST: -- BerliOS Bug #10972, Fetchmail refetches big messages repeatedly (SMTP listener - issue) - Debian Bug #475239, MIME decoder may break up words (need to quote results) - Replace sscanf/fscanf by functions that do range checking (strtol/strtoul) :-/ See http://sourceware.org/bugzilla/show_bug.cgi?id=6453 @@ -26,7 +26,7 @@ static int etrn_ok (int sock, char *argbuf) int ok; (void)argbuf; - ok = SMTP_ok(sock, SMTP_MODE); + ok = SMTP_ok(sock, SMTP_MODE, TIMEOUT_DEFAULT); if (ok == SM_UNRECOVERABLE) return(PS_PROTOCOL); else @@ -36,7 +36,7 @@ static int odmr_ok (int sock, char *argbuf) int ok; (void)argbuf; - ok = SMTP_ok(sock, SMTP_MODE); + ok = SMTP_ok(sock, SMTP_MODE, TIMEOUT_DEFAULT); if (ok == SM_UNRECOVERABLE) return(PS_PROTOCOL); else @@ -158,7 +158,7 @@ int smtp_open(struct query *ctl) } /* first, probe for ESMTP */ - if (SMTP_ok(ctl->smtp_socket, ctl->smtphostmode) == SM_OK && + if (SMTP_ok(ctl->smtp_socket, ctl->smtphostmode, TIMEOUT_STARTSMTP) == SM_OK && SMTP_ehlo(ctl->smtp_socket, ctl->smtphostmode, id_me, ctl->server.esmtp_name, ctl->server.esmtp_password, &ctl->server.esmtp_options) == SM_OK) @@ -186,7 +186,7 @@ int smtp_open(struct query *ctl) } } - if (SMTP_ok(ctl->smtp_socket, ctl->smtphostmode) == SM_OK && + if (SMTP_ok(ctl->smtp_socket, ctl->smtphostmode, TIMEOUT_STARTSMTP) == SM_OK && SMTP_helo(ctl->smtp_socket, ctl->smtphostmode, id_me) == SM_OK) break; /* success */ @@ -282,7 +282,7 @@ static int send_bouncemail(struct query *ctl, struct msgblk *msg, if ((sock = SockOpen("localhost", SMTP_PORT, NULL, &ai1)) == -1) return(FALSE); - if (SMTP_ok(sock, SMTP_MODE) != SM_OK) + if (SMTP_ok(sock, SMTP_MODE, TIMEOUT_STARTSMTP) != SM_OK) { SockClose(sock); return FALSE; @@ -1422,7 +1422,7 @@ int close_sink(struct query *ctl, struct msgblk *msg, flag forward) { if (lmtp_responses == 0) { - SMTP_ok(ctl->smtp_socket, ctl->smtphostmode); + SMTP_ok(ctl->smtp_socket, ctl->smtphostmode, TIMEOUT_EOM); /* * According to RFC2033, 503 is the only legal response @@ -1455,7 +1455,7 @@ int close_sink(struct query *ctl, struct msgblk *msg, flag forward) responses = (char **)xmalloc(sizeof(char *) * lmtp_responses); for (errors = i = 0; i < lmtp_responses; i++) { - if ((smtp_err = SMTP_ok(ctl->smtp_socket, ctl->smtphostmode)) + if ((smtp_err = SMTP_ok(ctl->smtp_socket, ctl->smtphostmode, TIMEOUT_EOM)) == SM_UNRECOVERABLE) { smtp_close(ctl, 0); @@ -39,6 +39,7 @@ static struct opt extensions[] = char smtp_response[MSGBUFSIZE]; +/* XXX: this must not be used for LMTP! */ int SMTP_helo(int sock, char smtp_mode, const char *host) /* send a "HELO" message to the SMTP listener */ { @@ -47,7 +48,7 @@ int SMTP_helo(int sock, char smtp_mode, const char *host) SockPrintf(sock,"HELO %s\r\n", host); if (outlevel >= O_MONITOR) report(stdout, "%cMTP> HELO %s\n", smtp_mode, host); - ok = SMTP_ok(sock, smtp_mode); + ok = SMTP_ok(sock, smtp_mode, TIMEOUT_HELO); return ok; } @@ -107,7 +108,7 @@ static void SMTP_auth(int sock, char smtp_mode, char *username, char *password, to64frombits(b64buf, tmp, strlen(tmp)); SockPrintf(sock, "%s\r\n", b64buf); - SMTP_ok(sock, smtp_mode); + SMTP_ok(sock, smtp_mode, TIMEOUT_DEFAULT); } else if (strstr(buf, "PLAIN")) { int len; @@ -123,7 +124,7 @@ static void SMTP_auth(int sock, char smtp_mode, char *username, char *password, } to64frombits(b64buf, tmp, len); SockPrintf(sock, "AUTH PLAIN %s\r\n", b64buf); - SMTP_ok(sock, smtp_mode); + SMTP_ok(sock, smtp_mode, TIMEOUT_DEFAULT); } else if (strstr(buf, "LOGIN")) { if (outlevel >= O_MONITOR) @@ -162,7 +163,7 @@ static void SMTP_auth(int sock, char smtp_mode, char *username, char *password, } to64frombits(b64buf, password, strlen(password)); SockPrintf(sock, "%s\r\n", b64buf); - SMTP_ok(sock, smtp_mode); + SMTP_ok(sock, smtp_mode, TIMEOUT_DEFAULT); } return; } @@ -172,17 +173,25 @@ int SMTP_ehlo(int sock, char smtp_mode, const char *host, char *name, char *pass { struct opt *hp; char auth_response[511]; + SIGHANDLERTYPE alrmsave; + const int tmout = (mytimeout >= TIMEOUT_HELO ? mytimeout : TIMEOUT_HELO); SockPrintf(sock,"%cHLO %s\r\n", (smtp_mode == 'S') ? 'E' : smtp_mode, host); if (outlevel >= O_MONITOR) report(stdout, "%cMTP> %cHLO %s\n", smtp_mode, (smtp_mode == 'S') ? 'E' : smtp_mode, host); + alrmsave = set_signal_handler(SIGALRM, null_signal_handler); + set_timeout(tmout); + *opt = 0; while ((SockRead(sock, smtp_response, sizeof(smtp_response)-1)) != -1) { int n = strlen(smtp_response); + set_timeout(0); + (void)set_signal_handler(SIGALRM, alrmsave); + if (smtp_response[strlen(smtp_response)-1] == '\n') smtp_response[strlen(smtp_response)-1] = '\0'; if (smtp_response[strlen(smtp_response)-1] == '\r') @@ -206,6 +215,9 @@ int SMTP_ehlo(int sock, char smtp_mode, const char *host, char *name, char *pass } else if (smtp_response[3] != '-') return SM_ERROR; + + alrmsave = set_signal_handler(SIGALRM, null_signal_handler); + set_timeout(tmout); } return SM_UNRECOVERABLE; } @@ -225,7 +237,7 @@ int SMTP_from(int sock, char smtp_mode, const char *from, const char *opts) SockPrintf(sock,"%s\r\n", buf); if (outlevel >= O_MONITOR) report(stdout, "%cMTP> %s\n", smtp_mode, buf); - ok = SMTP_ok(sock, smtp_mode); + ok = SMTP_ok(sock, smtp_mode, TIMEOUT_MAIL); return ok; } @@ -237,7 +249,7 @@ int SMTP_rcpt(int sock, char smtp_mode, const char *to) SockPrintf(sock,"RCPT TO:<%s>\r\n", to); if (outlevel >= O_MONITOR) report(stdout, "%cMTP> RCPT TO:<%s>\n", smtp_mode, to); - ok = SMTP_ok(sock, smtp_mode); + ok = SMTP_ok(sock, smtp_mode, TIMEOUT_RCPT); return ok; } @@ -249,7 +261,7 @@ int SMTP_data(int sock, char smtp_mode) SockPrintf(sock,"DATA\r\n"); if (outlevel >= O_MONITOR) report(stdout, "%cMTP> DATA\n", smtp_mode); - ok = SMTP_ok(sock, smtp_mode); + ok = SMTP_ok(sock, smtp_mode, TIMEOUT_DATA); return ok; } @@ -261,7 +273,7 @@ int SMTP_rset(int sock, char smtp_mode) SockPrintf(sock,"RSET\r\n"); if (outlevel >= O_MONITOR) report(stdout, "%cMTP> RSET\n", smtp_mode); - ok = SMTP_ok(sock, smtp_mode); + ok = SMTP_ok(sock, smtp_mode, TIMEOUT_DEFAULT); return ok; } @@ -273,15 +285,13 @@ int SMTP_quit(int sock, char smtp_mode) SockPrintf(sock,"QUIT\r\n"); if (outlevel >= O_MONITOR) report(stdout, "%cMTP> QUIT\n", smtp_mode); - ok = SMTP_ok(sock, smtp_mode); + ok = SMTP_ok(sock, smtp_mode, TIMEOUT_DEFAULT); return ok; } int SMTP_eom(int sock, char smtp_mode) /* send a message data terminator to the SMTP listener */ { - int ok; - SockPrintf(sock,".\r\n"); if (outlevel >= O_MONITOR) report(stdout, "%cMTP>. (EOM)\n", smtp_mode); @@ -290,23 +300,21 @@ int SMTP_eom(int sock, char smtp_mode) * When doing LMTP, must process many of these at the outer level. */ if (smtp_mode == 'S') - ok = SMTP_ok(sock, smtp_mode); + return SMTP_ok(sock, smtp_mode, TIMEOUT_EOM); else - ok = SM_OK; - - return ok; + return SM_OK; } time_t last_smtp_ok = 0; -int SMTP_ok(int sock, char smtp_mode) +int SMTP_ok(int sock, char smtp_mode, int mintimeout) /* returns status of SMTP connection */ { SIGHANDLERTYPE alrmsave; /* set an alarm for smtp ok */ alrmsave = set_signal_handler(SIGALRM, null_signal_handler); - set_timeout(mytimeout); + set_timeout(mytimeout >= mintimeout ? mytimeout : mintimeout); while ((SockRead(sock, smtp_response, sizeof(smtp_response)-1)) != -1) { @@ -23,6 +23,16 @@ #define ESMTP_ATRN 0x08 /* used with ODMR, RFC 2645 */ #define ESMTP_AUTH 0x10 +/* SMTP timeouts (seconds) - SHOULD clauses from RFC-5321 sec. 4.5.3.2. */ +#define TIMEOUT_STARTSMTP 300 +#define TIMEOUT_HELO 300 /* not in RFC-5321, also for EHLO/LHLO */ +#define TIMEOUT_MAIL 300 +#define TIMEOUT_RCPT 300 +#define TIMEOUT_DATA 120 +#define TIMEOUT_DATALINE 180 +#define TIMEOUT_EOM 600 +#define TIMEOUT_DEFAULT 300 /* not in RFC-5321, all other client timeouts */ + extern time_t last_smtp_ok; int SMTP_helo(int socket, char smtp_mode, const char *host); @@ -33,7 +43,7 @@ int SMTP_data(int socket, char smtp_mode); int SMTP_eom(int socket, char smtp_mode); int SMTP_rset(int socket, char smtp_mode); int SMTP_quit(int socket, char smtp_mode); -int SMTP_ok(int socket, char smtp_mode); +int SMTP_ok(int socket, char smtp_mode, int mintimeout); extern char smtp_response[MSGBUFSIZE]; |