From 5990a26531db1a1ba1ed4bc04554ba217c910b45 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Sat, 16 May 2020 16:36:08 +0100 Subject: [PATCH 1/1] Log additional command-history on too-many-syntax-errors --- src/src/smtp_in.c | 54 ++++++++++++++++++++++++++++----------------- test/log/0453 | 4 ++-- test/log/0566 | 2 +- test/log/0901 | 2 +- test/rejectlog/0453 | 4 ++-- test/rejectlog/0566 | 2 +- test/rejectlog/0901 | 2 +- test/stderr/0453 | 2 +- 8 files changed, 43 insertions(+), 29 deletions(-) diff --git a/src/src/smtp_in.c b/src/src/smtp_in.c index 4c3d995d6..526164c46 100644 --- a/src/src/smtp_in.c +++ b/src/src/smtp_in.c @@ -1816,6 +1816,29 @@ return g; } #endif + + +static gstring * +s_connhad_log(gstring * g) +{ +uschar * sep = smtp_connection_had[SMTP_HBUFF_SIZE-1] != SCH_NONE + ? US" C=..." : US" C="; + +for (int i = smtp_ch_index; i < SMTP_HBUFF_SIZE; i++) + if (smtp_connection_had[i] != SCH_NONE) + { + g = string_append(g, 2, sep, smtp_names[smtp_connection_had[i]]); + sep = US","; + } +for (int i = 0; i < smtp_ch_index; i++) + { + g = string_append(g, 2, sep, smtp_names[smtp_connection_had[i]]); + sep = US","; + } +return g; +} + + /************************************************* * Log lack of MAIL if so configured * *************************************************/ @@ -1831,7 +1854,7 @@ Returns: nothing void smtp_log_no_mail(void) { -uschar * sep, * s; +uschar * s; gstring * g = NULL; if (smtp_mailcmd_count > 0 || !LOGGING(smtp_no_mail)) @@ -1847,20 +1870,7 @@ if (sender_host_authenticated) g = s_tlslog(g); #endif -sep = smtp_connection_had[SMTP_HBUFF_SIZE-1] != SCH_NONE ? US" C=..." : US" C="; - -for (int i = smtp_ch_index; i < SMTP_HBUFF_SIZE; i++) - if (smtp_connection_had[i] != SCH_NONE) - { - g = string_append(g, 2, sep, smtp_names[smtp_connection_had[i]]); - sep = US","; - } - -for (int i = 0; i < smtp_ch_index; i++) - { - g = string_append(g, 2, sep, smtp_names[smtp_connection_had[i]]); - sep = US","; - } +g = s_connhad_log(g); if (!(s = string_from_gstring(g))) s = US""; @@ -3102,15 +3112,17 @@ synprot_error(int type, int code, uschar *data, uschar *errmess) int yield = -1; log_write(type, LOG_MAIN, "SMTP %s error in \"%s\" %s %s", - (type == L_smtp_syntax_error)? "syntax" : "protocol", + type == L_smtp_syntax_error ? "syntax" : "protocol", string_printing(smtp_cmd_buffer), host_and_ident(TRUE), errmess); if (++synprot_error_count > smtp_max_synprot_errors) { yield = 1; log_write(0, LOG_MAIN|LOG_REJECT, "SMTP call from %s dropped: too many " - "syntax or protocol errors (last command was \"%s\")", - host_and_ident(FALSE), string_printing(smtp_cmd_buffer)); + "syntax or protocol errors (last command was \"%s\", %s)", + host_and_ident(FALSE), string_printing(smtp_cmd_buffer), + string_from_gstring(s_connhad_log(NULL)) + ); } if (code > 0) @@ -4158,8 +4170,10 @@ while (done <= 0) if (++synprot_error_count > smtp_max_synprot_errors) { log_write(0, LOG_MAIN|LOG_REJECT, "SMTP call from %s dropped: too many " - "syntax or protocol errors (last command was \"%s\")", - host_and_ident(FALSE), string_printing(smtp_cmd_buffer)); + "syntax or protocol errors (last command was \"%s\", %s)", + host_and_ident(FALSE), string_printing(smtp_cmd_buffer), + string_from_gstring(s_connhad_log(NULL)) + ); done = 1; } diff --git a/test/log/0453 b/test/log/0453 index 5a2a89155..4ca61142b 100644 --- a/test/log/0453 +++ b/test/log/0453 @@ -2,5 +2,5 @@ 1999-03-02 09:44:33 rejected HELO from CALLER: syntactically invalid argument(s): (no argument given) 1999-03-02 09:44:33 rejected HELO from CALLER: syntactically invalid argument(s): (no argument given) 1999-03-02 09:44:33 rejected HELO from CALLER: syntactically invalid argument(s): (no argument given) -1999-03-02 09:44:33 SMTP call from CALLER dropped: too many syntax or protocol errors (last command was "helo") -1999-03-02 09:44:33 SMTP call from CALLER dropped: too many syntax or protocol errors (last command was "mail from:<>") +1999-03-02 09:44:33 SMTP call from CALLER dropped: too many syntax or protocol errors (last command was "helo", C=HELO,HELO,HELO,HELO) +1999-03-02 09:44:33 SMTP call from CALLER dropped: too many syntax or protocol errors (last command was "mail from:<>", C=MAIL,MAIL,MAIL) diff --git a/test/log/0566 b/test/log/0566 index 0922615b3..119b2d264 100644 --- a/test/log/0566 +++ b/test/log/0566 @@ -12,4 +12,4 @@ 1999-03-02 09:44:33 10HmaZ-0005vi-00 <= CALLER@myhost.test.ex U=CALLER P=local-esmtp S=sss M8S=8 1999-03-02 09:44:33 10HmaZ-0005vi-00 => userx R=r2 T=local_delivery 1999-03-02 09:44:33 10HmaZ-0005vi-00 Completed -1999-03-02 09:44:33 SMTP call from CALLER dropped: too many syntax or protocol errors (last command was "foo") +1999-03-02 09:44:33 SMTP call from CALLER dropped: too many syntax or protocol errors (last command was "foo", C=EHLO,MAIL,RCPT,DATA) diff --git a/test/log/0901 b/test/log/0901 index af07e730c..e4bb6a243 100644 --- a/test/log/0901 +++ b/test/log/0901 @@ -11,5 +11,5 @@ 1999-03-02 09:44:33 SMTP connection from (tester) [127.0.0.1] lost while reading message data 1999-03-02 09:44:33 10HmbD-0005vi-00 <= someone8@some.domain H=(tester) [127.0.0.1] P=esmtp K S=sss for CALLER@test.ex 1999-03-02 09:44:33 SMTP protocol synchronization error (next input sent too soon: pipelining was not advertised): rejected "BDAT 1" H=(tester) [127.0.0.1] next input="BDAT 87 last\r\no: Susan@random.co"... -1999-03-02 09:44:33 SMTP call from (tester) [127.0.0.1] dropped: too many syntax or protocol errors (last command was "From: Sam@random.com") +1999-03-02 09:44:33 SMTP call from (tester) [127.0.0.1] dropped: too many syntax or protocol errors (last command was "From: Sam@random.com", C=EHLO,MAIL,RCPT,BDAT) 1999-03-02 09:44:33 SMTP connection from (tester) [127.0.0.1] lost while reading message data (header) diff --git a/test/rejectlog/0453 b/test/rejectlog/0453 index 5a2a89155..4ca61142b 100644 --- a/test/rejectlog/0453 +++ b/test/rejectlog/0453 @@ -2,5 +2,5 @@ 1999-03-02 09:44:33 rejected HELO from CALLER: syntactically invalid argument(s): (no argument given) 1999-03-02 09:44:33 rejected HELO from CALLER: syntactically invalid argument(s): (no argument given) 1999-03-02 09:44:33 rejected HELO from CALLER: syntactically invalid argument(s): (no argument given) -1999-03-02 09:44:33 SMTP call from CALLER dropped: too many syntax or protocol errors (last command was "helo") -1999-03-02 09:44:33 SMTP call from CALLER dropped: too many syntax or protocol errors (last command was "mail from:<>") +1999-03-02 09:44:33 SMTP call from CALLER dropped: too many syntax or protocol errors (last command was "helo", C=HELO,HELO,HELO,HELO) +1999-03-02 09:44:33 SMTP call from CALLER dropped: too many syntax or protocol errors (last command was "mail from:<>", C=MAIL,MAIL,MAIL) diff --git a/test/rejectlog/0566 b/test/rejectlog/0566 index 7a420d042..bb4af83ef 100644 --- a/test/rejectlog/0566 +++ b/test/rejectlog/0566 @@ -1,3 +1,3 @@ 1999-03-02 09:44:33 U=CALLER F= rejected RCPT : SIZE value too big 1999-03-02 09:44:33 U=CALLER F= rejected RCPT : SIZE value too big -1999-03-02 09:44:33 SMTP call from CALLER dropped: too many syntax or protocol errors (last command was "foo") +1999-03-02 09:44:33 SMTP call from CALLER dropped: too many syntax or protocol errors (last command was "foo", C=EHLO,MAIL,RCPT,DATA) diff --git a/test/rejectlog/0901 b/test/rejectlog/0901 index a4185a966..79ecb9650 100644 --- a/test/rejectlog/0901 +++ b/test/rejectlog/0901 @@ -3,6 +3,6 @@ 1999-03-02 09:44:33 SMTP protocol synchronization error (next input sent too soon: pipelining was not advertised): rejected "BDAT 1" H=(tester) [127.0.0.1] next input="BDAT 87 last\r\no: Susan@random.co"... Envelope-from: Envelope-to: -1999-03-02 09:44:33 SMTP call from (tester) [127.0.0.1] dropped: too many syntax or protocol errors (last command was "From: Sam@random.com") +1999-03-02 09:44:33 SMTP call from (tester) [127.0.0.1] dropped: too many syntax or protocol errors (last command was "From: Sam@random.com", C=EHLO,MAIL,RCPT,BDAT) Envelope-from: Envelope-to: diff --git a/test/stderr/0453 b/test/stderr/0453 index 1911c67f2..dee833923 100644 --- a/test/stderr/0453 +++ b/test/stderr/0453 @@ -7,4 +7,4 @@ >>> host in helo_try_verify_hosts? no (option unset) >>> host in helo_accept_junk_hosts? no (option unset) >>> xxxx in helo_lookup_domains? no (end of list) -LOG: SMTP call from (xxxx) [V4NET.0.0.1] dropped: too many syntax or protocol errors (last command was "rcpt to:") +LOG: SMTP call from (xxxx) [V4NET.0.0.1] dropped: too many syntax or protocol errors (last command was "rcpt to:", C=HELO,MAIL,RCPT,RCPT,RCPT,RCPT) -- 2.30.2