diff options
author | Jeremy Harris <jgh146exb@wizmail.org> | 2017-07-05 14:30:05 +0100 |
---|---|---|
committer | Jeremy Harris <jgh146exb@wizmail.org> | 2017-07-09 16:23:24 +0100 |
commit | a09f294202729d7e532a1584536fa14e491a0b71 (patch) | |
tree | 7f9fdad88216ecbf8cb8d88f0f6a00dfcefe34cb | |
parent | ef698bf6a7a59d28c93fca18e4509ca6c67d7dca (diff) |
Add $smtp_command_history variable
-rw-r--r-- | doc/doc-docbook/spec.xfpt | 9 | ||||
-rw-r--r-- | doc/doc-txt/NewStuff | 3 | ||||
-rw-r--r-- | src/src/expand.c | 1 | ||||
-rw-r--r-- | src/src/functions.h | 1 | ||||
-rw-r--r-- | src/src/smtp_in.c | 22 | ||||
-rw-r--r-- | test/confs/0021 | 2 | ||||
-rw-r--r-- | test/paniclog/0021 | 8 | ||||
-rw-r--r-- | test/stderr/0021 | 17 |
8 files changed, 50 insertions, 13 deletions
diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt index aab8c00d5..84540508f 100644 --- a/doc/doc-docbook/spec.xfpt +++ b/doc/doc-docbook/spec.xfpt @@ -12793,6 +12793,15 @@ argument, that is, the text that follows the command name, with leading white space removed. Following the introduction of &$smtp_command$&, this variable is somewhat redundant, but is retained for backwards compatibility. +.new +.vitem &$smtp_command_history$& +.cindex SMTP "command history" +.vindex "&$smtp_command_history$&" +A comma-separated list (with no whitespace) of the most-recent SMTP commands +received, in time-order left to right. Only a limited number of commands +are remembered. +.wen + .vitem &$smtp_count_at_connection_start$& .vindex "&$smtp_count_at_connection_start$&" This variable is set greater than zero only in processes spawned by the Exim diff --git a/doc/doc-txt/NewStuff b/doc/doc-txt/NewStuff index 17fe1979a..f3050a950 100644 --- a/doc/doc-txt/NewStuff +++ b/doc/doc-txt/NewStuff @@ -41,6 +41,9 @@ Version 4.90 9. New option modifier "no_check" for quota and quota_filecount appendfile transport. +10. Variable $smtp_command_history returning a comma-sep list of recent + SMTP commands. + Version 4.89 ------------ diff --git a/src/src/expand.c b/src/src/expand.c index a064e34e4..4eb1818f1 100644 --- a/src/src/expand.c +++ b/src/src/expand.c @@ -680,6 +680,7 @@ static var_entry var_table[] = { { "smtp_active_hostname", vtype_stringptr, &smtp_active_hostname }, { "smtp_command", vtype_stringptr, &smtp_cmd_buffer }, { "smtp_command_argument", vtype_stringptr, &smtp_cmd_argument }, + { "smtp_command_history", vtype_string_func, &smtp_cmd_hist }, { "smtp_count_at_connection_start", vtype_int, &smtp_accept_count }, { "smtp_notquit_reason", vtype_stringptr, &smtp_notquit_reason }, { "sn0", vtype_filter_int, &filter_sn[0] }, diff --git a/src/src/functions.h b/src/src/functions.h index f7173576b..9c9caaf97 100644 --- a/src/src/functions.h +++ b/src/src/functions.h @@ -394,6 +394,7 @@ extern int sieve_interpret(uschar *, int, uschar *, uschar *, uschar *, extern void sigalrm_handler(int); extern BOOL smtp_buffered(void); extern void smtp_closedown(uschar *); +extern uschar *smtp_cmd_hist(void); extern int smtp_connect(host_item *, int, uschar *, int, transport_instance *); extern int smtp_sock_connect(host_item *, int, int, uschar *, diff --git a/src/src/smtp_in.c b/src/src/smtp_in.c index 92dbac4ce..629634267 100644 --- a/src/src/smtp_in.c +++ b/src/src/smtp_in.c @@ -1795,7 +1795,7 @@ for (i = 0; i < smtp_ch_index; i++) sep = US","; } -if (s != NULL) s[ptr] = 0; else s = US""; +if (s) s[ptr] = 0; else s = US""; log_write(0, LOG_MAIN, "no MAIL in SMTP connection from %s D=%s%s", host_and_ident(FALSE), readconf_printtime( (int) ((long)time(NULL) - (long)smtp_connection_start)), @@ -1803,6 +1803,26 @@ log_write(0, LOG_MAIN, "no MAIL in SMTP connection from %s D=%s%s", } +/* Return list of recent smtp commands */ + +uschar * +smtp_cmd_hist(void) +{ +uschar * list = NULL; +int size = 0, len = 0, i; + +for (i = smtp_ch_index; i < SMTP_HBUFF_SIZE; i++) + if (smtp_connection_had[i] != SCH_NONE) + list = string_append_listele(list, &size, &len, ',', + smtp_names[smtp_connection_had[i]]); +for (i = 0; i < smtp_ch_index; i++) + list = string_append_listele(list, &size, &len, ',', + smtp_names[smtp_connection_had[i]]); +return list ? list : US""; +} + + + /************************************************* * Check HELO line and set sender_helo_name * diff --git a/test/confs/0021 b/test/confs/0021 index ae5a309b9..cb057386e 100644 --- a/test/confs/0021 +++ b/test/confs/0021 @@ -67,7 +67,7 @@ mail: rcpt: accept senders = +ok_senders sender_domains = +ok_sender_domains - logwrite = :panic: rcpt accepted + logwrite = :panic: rcpt accepted C=$smtp_command_history # ----- Routers ----- diff --git a/test/paniclog/0021 b/test/paniclog/0021 index dae415203..d6e91d346 100644 --- a/test/paniclog/0021 +++ b/test/paniclog/0021 @@ -1,6 +1,6 @@ -1999-03-02 09:44:33 rcpt accepted -1999-03-02 09:44:33 rcpt accepted +1999-03-02 09:44:33 rcpt accepted C=MAIL,MAIL,RCPT +1999-03-02 09:44:33 rcpt accepted C=MAIL,MAIL,RCPT,RCPT 1999-03-02 09:44:33 ACL "warn" with "message" setting found in a non-message (EHLO or HELO) ACL: cannot specify header lines here: message ignored -1999-03-02 09:44:33 rcpt accepted +1999-03-02 09:44:33 rcpt accepted C=MAIL,RCPT 1999-03-02 09:44:33 ACL "warn" with "message" setting found in a non-message (EHLO or HELO) ACL: cannot specify header lines here: message ignored -1999-03-02 09:44:33 rcpt accepted +1999-03-02 09:44:33 rcpt accepted C=EHLO,MAIL,RCPT diff --git a/test/stderr/0021 b/test/stderr/0021 index 7c5a79ee9..299cc4974 100644 --- a/test/stderr/0021 +++ b/test/stderr/0021 @@ -80,9 +80,10 @@ ok@test1 in "+ok_senders"? yes (matched "+ok_senders") check sender_domains = +ok_sender_domains test1 in "somewhere : test1 : test3"? yes (matched "test1") test1 in "+ok_sender_domains"? yes (matched "+ok_sender_domains") -check logwrite = :panic: rcpt accepted +check logwrite = :panic: rcpt accepted C=$smtp_command_history + = :panic: rcpt accepted C=MAIL,MAIL,RCPT LOG: PANIC - rcpt accepted + rcpt accepted C=MAIL,MAIL,RCPT accept: condition test succeeded in ACL "rcpt" end of ACL "rcpt": ACCEPT using ACL "rcpt" @@ -94,9 +95,10 @@ ok@test1 in "+ok_senders"? yes (matched "+ok_senders" - cached) check sender_domains = +ok_sender_domains cached yes match for +ok_sender_domains test1 in "+ok_sender_domains"? yes (matched "+ok_sender_domains" - cached) -check logwrite = :panic: rcpt accepted +check logwrite = :panic: rcpt accepted C=$smtp_command_history + = :panic: rcpt accepted C=MAIL,MAIL,RCPT,RCPT LOG: PANIC - rcpt accepted + rcpt accepted C=MAIL,MAIL,RCPT,RCPT accept: condition test succeeded in ACL "rcpt" end of ACL "rcpt": ACCEPT LOG: smtp_connection MAIN @@ -173,9 +175,10 @@ ok@test3 in "+ok_senders"? yes (matched "+ok_senders") check sender_domains = +ok_sender_domains test3 in "somewhere : test1 : test3"? yes (matched "test3") test3 in "+ok_sender_domains"? yes (matched "+ok_sender_domains") -check logwrite = :panic: rcpt accepted +check logwrite = :panic: rcpt accepted C=$smtp_command_history + = :panic: rcpt accepted C=MAIL,RCPT LOG: PANIC - rcpt accepted + rcpt accepted C=MAIL,RCPT accept: condition test succeeded in ACL "rcpt" end of ACL "rcpt": ACCEPT >>Headers added by MAIL or RCPT ACL: @@ -197,4 +200,4 @@ LOG: smtp_connection MAIN SMTP connection from CALLER closed by QUIT >>>>>>>>>>>>>>>> Exim pid=pppp terminating with rc=0 >>>>>>>>>>>>>>>> 1999-03-02 09:44:33 ACL "warn" with "message" setting found in a non-message (EHLO or HELO) ACL: cannot specify header lines here: message ignored -1999-03-02 09:44:33 rcpt accepted +1999-03-02 09:44:33 rcpt accepted C=EHLO,MAIL,RCPT |