Log EHLO response on getting conn-close response for HELO. Bug 1832
authorJeremy Harris <jgh146exb@wizmail.org>
Sat, 10 Sep 2016 20:37:56 +0000 (21:37 +0100)
committerJeremy Harris <jgh146exb@wizmail.org>
Sun, 11 Sep 2016 15:13:03 +0000 (16:13 +0100)
doc/doc-txt/ChangeLog
src/src/transports/smtp.c
test/log/0211
test/scripts/0000-Basic/0211
test/scripts/5730-OCSP-GnuTLS-events/5730
test/stdout/0211

index aeb67ecfaa7256ff1ac95969bcc2f88eb70152cc..40f06dc2912fb4015dfead254fce6c0b2745dccf 100644 (file)
@@ -88,6 +88,8 @@ JH/23 Bug 1874: fix continued use of a connection for further deliveries.
       (has no matching addresses), we lost track of needing to mark it
       deferred.  As a result mail would be lost.
 
       (has no matching addresses), we lost track of needing to mark it
       deferred.  As a result mail would be lost.
 
+JH/24 Bug 1832: Log EHLO response on getting conn-close response for HELO.
+
 
 Exim version 4.87
 -----------------
 
 Exim version 4.87
 -----------------
index 677ce4ee105854ada74a841ff4df8d5c48a5f032..85582e7535523f14316e30aeb31ad7477e446caf 100644 (file)
@@ -1525,6 +1525,7 @@ struct lflags {
   BOOL send_quit:1;
   BOOL setting_up:1;
   BOOL esmtp:1;
   BOOL send_quit:1;
   BOOL setting_up:1;
   BOOL esmtp:1;
+  BOOL esmtp_sent:1;
   BOOL pending_MAIL:1;
 #ifndef DISABLE_PRDR
   BOOL prdr_active:1;
   BOOL pending_MAIL:1;
 #ifndef DISABLE_PRDR
   BOOL prdr_active:1;
@@ -1572,6 +1573,7 @@ lflags.send_rset = TRUE;
 lflags.send_quit = TRUE;
 lflags.setting_up = TRUE;
 lflags.esmtp = TRUE;
 lflags.send_quit = TRUE;
 lflags.setting_up = TRUE;
 lflags.esmtp = TRUE;
+lflags.esmtp_sent = FALSE;
 lflags.pending_MAIL;
 #ifndef DISABLE_PRDR
 lflags.prdr_active;
 lflags.pending_MAIL;
 #ifndef DISABLE_PRDR
 lflags.prdr_active;
@@ -1800,6 +1802,7 @@ goto SEND_QUIT;
     if (smtp_write_command(&outblock, FALSE, "%s %s\r\n",
          lflags.lmtp ? "LHLO" : "EHLO", helo_data) < 0)
       goto SEND_FAILED;
     if (smtp_write_command(&outblock, FALSE, "%s %s\r\n",
          lflags.lmtp ? "LHLO" : "EHLO", helo_data) < 0)
       goto SEND_FAILED;
+    lflags.esmtp_sent = TRUE;
     if (!smtp_read_response(&inblock, buffer, sizeof(buffer), '2',
            ob->command_timeout))
       {
     if (!smtp_read_response(&inblock, buffer, sizeof(buffer), '2',
            ob->command_timeout))
       {
@@ -1823,15 +1826,37 @@ goto SEND_QUIT;
   if (!lflags.esmtp)
     {
     BOOL good_response;
   if (!lflags.esmtp)
     {
     BOOL good_response;
+    int n = sizeof(buffer);
+    uschar * rsp = buffer;
+
+    if (lflags.esmtp_sent && (n = Ustrlen(buffer)) < sizeof(buffer)/2)
+      { rsp = buffer + n + 1; n = sizeof(buffer) - n; }
 
     if (smtp_write_command(&outblock, FALSE, "HELO %s\r\n", helo_data) < 0)
       goto SEND_FAILED;
 
     if (smtp_write_command(&outblock, FALSE, "HELO %s\r\n", helo_data) < 0)
       goto SEND_FAILED;
-    good_response = smtp_read_response(&inblock, buffer, sizeof(buffer),
+    good_response = smtp_read_response(&inblock, rsp, n,
       '2', ob->command_timeout);
 #ifdef EXPERIMENTAL_DSN_INFO
       '2', ob->command_timeout);
 #ifdef EXPERIMENTAL_DSN_INFO
-    helo_response = string_copy(buffer);
+    helo_response = string_copy(rsp);
 #endif
 #endif
-    if (!good_response) goto RESPONSE_FAILED;
+    if (!good_response)
+      {
+      /* Handle special logging for a closed connection after HELO
+      when had previously sent EHLO */
+
+      if (rsp != buffer && rsp[0] == 0 && (errno == 0 || errno == ECONNRESET))
+       {
+       message = NULL;
+       lflags.send_quit = FALSE;
+       save_errno = ERRNO_SMTPCLOSED;
+       message = string_sprintf("Remote host closed connection "
+             "in response to %s (EHLO response was: %s)",
+             smtp_command, buffer);
+       goto FAILED;
+       }
+      Ustrncpy(buffer, rsp, sizeof(buffer)/2);
+      goto RESPONSE_FAILED;
+      }
     }
 
   peer_offered = smtp_peer_options = 0;
     }
 
   peer_offered = smtp_peer_options = 0;
index 9a5824674f72939a1252f8164fe5577196798c88..cbf33c6126c401dbe26e2fce8aed1fc7b7529c35 100644 (file)
@@ -28,3 +28,7 @@
 1999-03-02 09:44:33 10HmbA-0005vi-00 => CALLER <CALLER@test.ex> F=<> R=all T=local_delivery
 1999-03-02 09:44:33 10HmbA-0005vi-00 Completed
 1999-03-02 09:44:33 10HmaZ-0005vi-00 Completed
 1999-03-02 09:44:33 10HmbA-0005vi-00 => CALLER <CALLER@test.ex> F=<> R=all T=local_delivery
 1999-03-02 09:44:33 10HmbA-0005vi-00 Completed
 1999-03-02 09:44:33 10HmaZ-0005vi-00 Completed
+1999-03-02 09:44:33 Test: reject ehlo, then close (late, giving time for HELO)
+1999-03-02 09:44:33 10HmbB-0005vi-00 <= CALLER@test.ex U=CALLER P=local S=sss
+1999-03-02 09:44:33 10HmbB-0005vi-00 H=localhost4.test.ex [127.0.0.1]: Remote host closed connection in response to HELO the.local.host.name (EHLO response was: 550 You are banned)
+1999-03-02 09:44:33 10HmbB-0005vi-00 == userx@domain1 R=others T=smtp defer (-18) H=localhost4.test.ex [127.0.0.1]: Remote host closed connection in response to HELO the.local.host.name (EHLO response was: 550 You are banned)
index f8750d2e84e55413e62c06b111faa57457d67a36..dbe41c723b15d53ed06ce96119e0ab1921e99426 100644 (file)
@@ -59,3 +59,19 @@ QUIT
 exim -odi userx@domain1 usery@domain2
 Test message 2
 ****
 exim -odi userx@domain1 usery@domain2
 Test message 2
 ****
+#
+exim -z "Test: reject ehlo, then close (late, giving time for HELO)"
+****
+sudo rm DIR/spool/db/retry
+server PORT_S
+220 Connected OK
+EHLO
+550 You are banned
+HELO
+****
+exim -odi userx@domain1
+Test message 4
+****
+#
+#
+no_msglog_check
index b86b03264a10d9d00cc85000e36d9267e650fce3..d22a1aa1f1c8d037f21565909b0d432ab16c2e91 100644 (file)
@@ -52,7 +52,7 @@ test message.
 ****
 sleep 1
 killdaemon
 ****
 sleep 1
 killdaemon
-no_msglog_check
+sudo rm DIR/spool/db/retry
 #
 #
 #
 #
 #
 #
@@ -65,6 +65,7 @@ test message.
 ****
 sleep 1
 killdaemon
 ****
 sleep 1
 killdaemon
+sudo rm DIR/spool/db/retry
 #
 #
 #
 #
 #
 #
@@ -82,3 +83,4 @@ killdaemon
 #
 #
 #
 #
 #
 #
+no_msglog_check
index ebe8246b0d9fee1a95576831ed59cc17cc9ce6b2..93e271c6ad7bdbebe444c745770f35c4f961a6ba 100644 (file)
@@ -36,3 +36,10 @@ HELO the.local.host.name
 QUIT
 250 OK
 End of script
 QUIT
 250 OK
 End of script
+Listening on port 1224 ... 
+Connection request from [127.0.0.1]
+220 Connected OK
+EHLO the.local.host.name
+550 You are banned
+HELO the.local.host.name
+End of script