diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/src/exim.c | 12 | ||||
-rw-r--r-- | src/src/macros.h | 4 | ||||
-rw-r--r-- | src/src/readconf.c | 22 | ||||
-rw-r--r-- | src/src/retry.c | 25 | ||||
-rw-r--r-- | src/src/transports/lmtp.c | 32 | ||||
-rw-r--r-- | src/src/transports/smtp.c | 161 |
6 files changed, 176 insertions, 80 deletions
diff --git a/src/src/exim.c b/src/src/exim.c index ec36d4940..30ea05c41 100644 --- a/src/src/exim.c +++ b/src/src/exim.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/exim.c,v 1.36 2006/02/23 10:25:01 ph10 Exp $ */ +/* $Cambridge: exim/src/src/exim.c,v 1.37 2006/03/09 15:10:16 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -3725,11 +3725,13 @@ if (test_retry_arg >= 0) return EXIT_FAILURE; } - /* For the rcpt_4xx errors, a value of 255 means "any", and a code > 100 as - an error is for matching codes to the decade. Turn them into a real error - code, off the decade. */ + /* For the {MAIL,RCPT,DATA}_4xx errors, a value of 255 means "any", and a + code > 100 as an error is for matching codes to the decade. Turn them into + a real error code, off the decade. */ - if (basic_errno == ERRNO_RCPT4XX) + if (basic_errno == ERRNO_MAIL4XX || + basic_errno == ERRNO_RCPT4XX || + basic_errno == ERRNO_DATA4XX) { int code = (more_errno >> 8) & 255; if (code == 255) diff --git a/src/src/macros.h b/src/src/macros.h index 497589023..7de0c4bfc 100644 --- a/src/src/macros.h +++ b/src/src/macros.h @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/macros.h,v 1.23 2006/02/14 14:55:37 ph10 Exp $ */ +/* $Cambridge: exim/src/src/macros.h,v 1.24 2006/03/09 15:10:16 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -452,6 +452,8 @@ to conflict with system errno values. */ #define ERRNO_AUTHFAIL (-42) /* When required by client */ #define ERRNO_CONNECTTIMEOUT (-43) /* Used internally in smtp transport */ #define ERRNO_RCPT4XX (-44) /* RCPT gave 4xx error */ +#define ERRNO_MAIL4XX (-45) /* MAIL gave 4xx error */ +#define ERRNO_DATA4XX (-46) /* DATA gave 4xx error */ /* These must be last, so all retry deferments can easily be identified */ diff --git a/src/src/readconf.c b/src/src/readconf.c index 59e75d0a4..d1911a7b6 100644 --- a/src/src/readconf.c +++ b/src/src/readconf.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/readconf.c,v 1.21 2006/02/22 15:08:20 ph10 Exp $ */ +/* $Cambridge: exim/src/src/readconf.c,v 1.22 2006/03/09 15:10:16 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -3421,7 +3421,9 @@ else if (len == 7 && strncmpic(pp, US"timeout", len) == 0) } } -else if (strncmpic(pp, US"rcpt_4", 6) == 0) +else if (strncmpic(pp, US"mail_4", 6) == 0 || + strncmpic(pp, US"rcpt_4", 6) == 0 || + strncmpic(pp, US"data_4", 6) == 0) { BOOL bad = FALSE; int x = 255; /* means "any 4xx code" */ @@ -3438,18 +3440,24 @@ else if (strncmpic(pp, US"rcpt_4", 6) == 0) else if (a != 'x' || b != 'x') bad = TRUE; } - if (bad) return US"rcpt_4 must be followed by xx, dx, or dd, where " - "x is literal and d is any digit"; + if (bad) + return string_sprintf("%.4s_4 must be followed by xx, dx, or dd, where " + "x is literal and d is any digit", pp); - *basic_errno = ERRNO_RCPT4XX; + *basic_errno = (*pp == 'm')? ERRNO_MAIL4XX : + (*pp == 'r')? ERRNO_RCPT4XX : ERRNO_DATA4XX; *more_errno = x << 8; } else if (len == 4 && strncmpic(pp, US"auth", len) == 0 && strncmpic(q+1, US"failed", p-q-1) == 0) - { *basic_errno = ERRNO_AUTHFAIL; - } + +else if (strcmpic(pp, US"lost_connection") == 0) + *basic_errno = ERRNO_SMTPCLOSED; + +else if (strcmpic(pp, US"tls_required") == 0) + *basic_errno = ERRNO_TLSREQUIRED; else if (len != 1 || Ustrncmp(pp, "*", 1) != 0) return string_sprintf("unknown or malformed retry error \"%.*s\"", p-pp, pp); diff --git a/src/src/retry.c b/src/src/retry.c index dbfd3cee8..ca61e5c0c 100644 --- a/src/src/retry.c +++ b/src/src/retry.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/retry.c,v 1.8 2006/02/16 16:37:57 ph10 Exp $ */ +/* $Cambridge: exim/src/src/retry.c,v 1.9 2006/03/09 15:10:16 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -414,20 +414,31 @@ for (yield = retries; yield != NULL; yield = yield->next) continue; } - /* Handle 4xx responses to RCPT. The code that was received is in the 2nd - least significant byte of more_errno (with 400 subtracted). The required - value is coded in the 2nd least significant byte of the yield->more_errno - field as follows: + /* The TLSREQUIRED error also covers TLSFAILURE. These are subtly different + errors, but not worth separating at this level. */ + + else if (yield->basic_errno == ERRNO_TLSREQUIRED) + { + if (basic_errno != ERRNO_TLSREQUIRED && basic_errno != ERRNO_TLSFAILURE) + continue; + } + + /* Handle 4xx responses to MAIL, RCPT, or DATA. The code that was received + is in the 2nd least significant byte of more_errno (with 400 subtracted). + The required value is coded in the 2nd least significant byte of the + yield->more_errno field as follows: 255 => any 4xx code >= 100 => the decade must match the value less 100 < 100 => the exact value must match */ - else if (yield->basic_errno == ERRNO_RCPT4XX) + else if (yield->basic_errno == ERRNO_MAIL4XX || + yield->basic_errno == ERRNO_RCPT4XX || + yield->basic_errno == ERRNO_DATA4XX) { int wanted; - if (basic_errno != ERRNO_RCPT4XX) continue; + if (basic_errno != yield->basic_errno) continue; wanted = (yield->more_errno >> 8) & 255; if (wanted != 255) { diff --git a/src/src/transports/lmtp.c b/src/src/transports/lmtp.c index 79ad67d01..969e45d60 100644 --- a/src/src/transports/lmtp.c +++ b/src/src/transports/lmtp.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/transports/lmtp.c,v 1.7 2006/02/07 11:19:03 ph10 Exp $ */ +/* $Cambridge: exim/src/src/transports/lmtp.c,v 1.8 2006/03/09 15:10:16 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -578,7 +578,14 @@ if (!lmtp_write_command(fd_in, "MAIL FROM:<%s>\r\n", return_path)) goto WRITE_FAILED; if (!lmtp_read_response(out, buffer, sizeof(buffer), '2', timeout)) + { + if (errno == 0 && buffer[0] == '4') + { + errno = ERRNO_MAIL4XX; + addrlist->more_errno |= ((buffer[1] - '0')*10 + buffer[2] - '0') << 8; + } goto RESPONSE_FAILED; + } /* Next, we hand over all the recipients. Some may be permanently or temporarily rejected; others may be accepted, for now. */ @@ -601,9 +608,8 @@ for (addr = addrlist; addr != NULL; addr = addr->next) string_printing(buffer)); if (buffer[0] == '5') addr->transport_return = FAIL; else { - int bincode = (buffer[1] - '0')*10 + buffer[2] - '0'; addr->basic_errno = ERRNO_RCPT4XX; - addr->more_errno |= bincode << 8; + addr->more_errno |= ((buffer[1] - '0')*10 + buffer[2] - '0') << 8; } } } @@ -616,7 +622,14 @@ if (send_data) if (!lmtp_write_command(fd_in, "DATA\r\n")) goto WRITE_FAILED; if (!lmtp_read_response(out, buffer, sizeof(buffer), '3', timeout)) + { + if (errno == 0 && buffer[0] == '4') + { + errno = ERRNO_DATA4XX; + addrlist->more_errno |= ((buffer[1] - '0')*10 + buffer[2] - '0') << 8; + } goto RESPONSE_FAILED; + } sigalrm_seen = FALSE; transport_write_timeout = timeout; @@ -676,6 +689,11 @@ if (send_data) else { + if (buffer[0] == '4') + { + addr->basic_errno = ERRNO_DATA4XX; + addr->more_errno |= ((buffer[1] - '0')*10 + buffer[2] - '0') << 8; + } addr->message = string_sprintf("LMTP error after %s: %s", big_buffer, string_printing(buffer)); addr->transport_return = (buffer[0] == '5')? FAIL : DEFER; @@ -696,13 +714,15 @@ goto RETURN; /* Come here if any call to read_response, other than a response after the data phase, failed. Put the error in the top address - this will be replicated -because the yield is still FALSE. Analyse the error, and if if isn't too bad, -send a QUIT command. Wait for the response with a short timeout, so we don't -wind up this process before the far end has had time to read the QUIT. */ +because the yield is still FALSE. (But omit ETIMEDOUT, as there will already be +a suitable message.) Analyse the error, and if if isn't too bad, send a QUIT +command. Wait for the response with a short timeout, so we don't wind up this +process before the far end has had time to read the QUIT. */ RESPONSE_FAILED: save_errno = errno; +if (errno != ETIMEDOUT && errno != 0) addrlist->basic_errno = errno; addrlist->message = NULL; if (check_response(&save_errno, addrlist->more_errno, diff --git a/src/src/transports/smtp.c b/src/src/transports/smtp.c index 9b204e064..e223bb183 100644 --- a/src/src/transports/smtp.c +++ b/src/src/transports/smtp.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/transports/smtp.c,v 1.24 2006/03/01 16:07:16 ph10 Exp $ */ +/* $Cambridge: exim/src/src/transports/smtp.c,v 1.25 2006/03/09 15:10:16 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -598,6 +598,12 @@ if (pending_MAIL) if (errno == 0 && buffer[0] != 0) { uschar flushbuffer[4096]; + int save_errno = 0; + if (buffer[0] == '4') + { + save_errno = ERRNO_MAIL4XX; + addr->more_errno |= ((buffer[1] - '0')*10 + buffer[2] - '0') << 8; + } while (count-- > 0) { if (!smtp_read_response(inblock, flushbuffer, sizeof(flushbuffer), @@ -605,6 +611,7 @@ if (pending_MAIL) && (errno != 0 || flushbuffer[0] == 0)) break; } + errno = save_errno; } return -3; } @@ -683,11 +690,9 @@ while (count-- > 0) else { - int bincode = (buffer[1] - '0')*10 + buffer[2] - '0'; - addr->transport_return = DEFER; addr->basic_errno = ERRNO_RCPT4XX; - addr->more_errno |= bincode << 8; + addr->more_errno |= ((buffer[1] - '0')*10 + buffer[2] - '0') << 8; /* Log temporary errors if there are more hosts to be tried. */ @@ -720,7 +725,15 @@ if (pending_DATA != 0 && int code; uschar *msg; BOOL pass_message; - if (pending_DATA > 0 || (yield & 1) != 0) return -3; + if (pending_DATA > 0 || (yield & 1) != 0) + { + if (errno == 0 && buffer[0] == '4') + { + errno = ERRNO_DATA4XX; + addrlist->more_errno |= ((buffer[1] - '0')*10 + buffer[2] - '0') << 8; + } + return -3; + } (void)check_response(host, &errno, 0, buffer, &code, &msg, &pass_message); DEBUG(D_transport) debug_printf("%s\nerror for DATA ignored: pipelining " "is in use and there were no good recipients\n", msg); @@ -1340,7 +1353,15 @@ switch(rc) case +1: /* Block was sent */ if (!smtp_read_response(&inblock, buffer, sizeof(buffer), '2', - ob->command_timeout)) goto RESPONSE_FAILED; + ob->command_timeout)) + { + if (errno == 0 && buffer[0] == '4') + { + errno = ERRNO_MAIL4XX; + addrlist->more_errno |= ((buffer[1] - '0')*10 + buffer[2] - '0') << 8; + } + goto RESPONSE_FAILED; + } pending_MAIL = FALSE; break; } @@ -1521,8 +1542,16 @@ if (!ok) ok = TRUE; else /* For SMTP, we now read a single response that applies to the whole message. If it is OK, then all the addresses have been delivered. */ - if (!lmtp) ok = smtp_read_response(&inblock, buffer, sizeof(buffer), '2', - ob->final_timeout); + if (!lmtp) + { + ok = smtp_read_response(&inblock, buffer, sizeof(buffer), '2', + ob->final_timeout); + if (!ok && errno == 0 && buffer[0] == '4') + { + errno = ERRNO_DATA4XX; + addrlist->more_errno |= ((buffer[1] - '0')*10 + buffer[2] - '0') << 8; + } + } /* For LMTP, we get back a response for every RCPT command that we sent; some may be accepted and some rejected. For those that get a response, their @@ -1590,6 +1619,8 @@ if (!ok) ok = TRUE; else addr->transport_return = FAIL; else { + errno = ERRNO_DATA4XX; + addr->more_errno |= ((buffer[1] - '0')*10 + buffer[2] - '0') << 8; addr->transport_return = DEFER; retry_add_item(addr, addr->address_retry_key, 0); } @@ -1694,61 +1725,83 @@ if (!ok) } } - /* If there was an I/O error or timeout or other transportation error, - indicated by errno being non-zero, defer all addresses and yield DEFER, - except for the case of failed add_headers expansion, or a transport filter - failure, when the yield should be ERROR, to stop it trying other hosts. - - However, handle timeouts after MAIL FROM or "." and loss of connection after + /* We want to handle timeouts after MAIL or "." and loss of connection after "." specially. They can indicate a problem with the sender address or with - the contents of the message rather than a real error on the connection. - Therefore, treat these cases in the same way as a 4xx response. + the contents of the message rather than a real error on the connection. These + cases are treated in the same way as a 4xx response. This next bit of code + does the classification. */ - The following condition tests for NOT these special cases. */ - - else if (save_errno != 0 && - (save_errno != ETIMEDOUT || - (Ustrncmp(smtp_command,"MAIL",4) != 0 && - Ustrncmp(smtp_command,"end ",4) != 0)) && - (save_errno != ERRNO_SMTPCLOSED || - Ustrncmp(smtp_command,"end ",4) != 0)) + else { - yield = (save_errno == ERRNO_CHHEADER_FAIL || - save_errno == ERRNO_FILTER_FAIL)? ERROR : DEFER; - set_errno(addrlist, save_errno, message, DEFER, pass_message); - } + BOOL message_error; - /* Otherwise we have a message-specific error response from the remote - host. This is one of - (a) negative response or timeout after "mail from" - (b) negative response after "data" - (c) negative response or timeout or dropped connection after "." - It won't be a negative response or timeout after "rcpt to", as that is dealt - with separately above. The action in all cases is to set an appropriate - error code for all the addresses, but to leave yield set to OK because - the host itself has not failed. [It might in practice have failed for a - timeout after MAIL FROM, or "." but if so, we'll discover that at the next - delivery attempt.] For a temporary error, set the message_defer flag, and - write to the logs for information if this is not the last host. The error for - the last host will be logged as part of the address's log line. */ + switch(save_errno) + { + case 0: + case ERRNO_MAIL4XX: + case ERRNO_DATA4XX: + message_error = TRUE; + break; - else - { - if (mua_wrapper) code = '5'; /* Force hard failure in wrapper mode */ + case ETIMEDOUT: + message_error = Ustrncmp(smtp_command,"MAIL",4) == 0 || + Ustrncmp(smtp_command,"end ",4) == 0; + break; + + case ERRNO_SMTPCLOSED: + message_error = Ustrncmp(smtp_command,"end ",4) == 0; + break; + + default: + message_error = FALSE; + break; + } - set_errno(addrlist, save_errno, message, (code == '5')? FAIL : DEFER, - pass_message); + /* Handle the cases that are treated as message errors. These are: - /* If there's an errno, the message contains just the identity of - the host. */ + (a) negative response or timeout after MAIL + (b) negative response after DATA + (c) negative response or timeout or dropped connection after "." - if (code != '5') /* Anything other than 5 is treated as temporary */ + It won't be a negative response or timeout after RCPT, as that is dealt + with separately above. The action in all cases is to set an appropriate + error code for all the addresses, but to leave yield set to OK because the + host itself has not failed. Of course, it might in practice have failed + when we've had a timeout, but if so, we'll discover that at the next + delivery attempt. For a temporary error, set the message_defer flag, and + write to the logs for information if this is not the last host. The error + for the last host will be logged as part of the address's log line. */ + + if (message_error) { - if (save_errno > 0) - message = US string_sprintf("%s: %s", message, strerror(save_errno)); - if (host->next != NULL) log_write(0, LOG_MAIN, "%s", message); - deliver_msglog("%s %s\n", tod_stamp(tod_log), message); - *message_defer = TRUE; + if (mua_wrapper) code = '5'; /* Force hard failure in wrapper mode */ + set_errno(addrlist, save_errno, message, (code == '5')? FAIL : DEFER, + pass_message); + + /* If there's an errno, the message contains just the identity of + the host. */ + + if (code != '5') /* Anything other than 5 is treated as temporary */ + { + if (save_errno > 0) + message = US string_sprintf("%s: %s", message, strerror(save_errno)); + if (host->next != NULL) log_write(0, LOG_MAIN, "%s", message); + deliver_msglog("%s %s\n", tod_stamp(tod_log), message); + *message_defer = TRUE; + } + } + + /* Otherwise, we have an I/O error or a timeout other than after MAIL or + ".", or some other transportation error. We defer all addresses and yield + DEFER, except for the case of failed add_headers expansion, or a transport + filter failure, when the yield should be ERROR, to stop it trying other + hosts. */ + + else + { + yield = (save_errno == ERRNO_CHHEADER_FAIL || + save_errno == ERRNO_FILTER_FAIL)? ERROR : DEFER; + set_errno(addrlist, save_errno, message, DEFER, pass_message); } } } |