diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2018-12-11 11:29:45 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2018-12-11 11:29:45 +0000 |
commit | eb1a5256215b68eae3deae39a0068cb71df3f392 (patch) | |
tree | f551291c08f738672a3fc7efeded18dba32c1005 /usr.sbin/smtpd | |
parent | 6e758b79727840d5b9d78c9d7b7d78fee4a055f4 (diff) |
report filter responses to smtp
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r-- | usr.sbin/smtpd/lka.c | 16 | ||||
-rw-r--r-- | usr.sbin/smtpd/lka_report.c | 81 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtp_report.c | 14 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtp_session.c | 10 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 6 |
5 files changed, 122 insertions, 5 deletions
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c index 42ff622b599..d721e5f7c31 100644 --- a/usr.sbin/smtpd/lka.c +++ b/usr.sbin/smtpd/lka.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka.c,v 1.222 2018/12/11 08:40:56 gilles Exp $ */ +/* $OpenBSD: lka.c,v 1.223 2018/12/11 11:29:44 gilles Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -89,6 +89,7 @@ lka_imsg(struct mproc *p, struct imsg *imsg) const char *address; const char *heloname; struct sockaddr_storage ss_src, ss_dest; + int filter_response; int filter_phase; const char *filter_param; uint32_t msgid; @@ -547,6 +548,19 @@ lka_imsg(struct mproc *p, struct imsg *imsg) lka_report_smtp_protocol_server("smtp-in", tm, reqid, response); return; + case IMSG_SMTP_REPORT_FILTER_RESPONSE: + m_msg(&m, imsg); + m_get_time(&m, &tm); + m_get_id(&m, &reqid); + m_get_int(&m, &filter_phase); + m_get_int(&m, &filter_response); + m_get_string(&m, &filter_param); + m_end(&m); + + lka_report_smtp_filter_response("smtp-in", tm, reqid, + filter_phase, filter_response, filter_param); + return; + case IMSG_MTA_REPORT_LINK_CONNECT: m_msg(&m, imsg); m_get_time(&m, &tm); diff --git a/usr.sbin/smtpd/lka_report.c b/usr.sbin/smtpd/lka_report.c index 2839cbbf13d..5ae549d4733 100644 --- a/usr.sbin/smtpd/lka_report.c +++ b/usr.sbin/smtpd/lka_report.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka_report.c,v 1.12 2018/12/11 08:40:56 gilles Exp $ */ +/* $OpenBSD: lka_report.c,v 1.13 2018/12/11 11:29:44 gilles Exp $ */ /* * Copyright (c) 2018 Gilles Chehade <gilles@poolp.org> @@ -209,3 +209,82 @@ lka_report_smtp_protocol_server(const char *direction, time_t tm, uint64_t reqid "protocol-server|%016"PRIx64"|%s\n", reqid, response); } + +void +lka_report_smtp_filter_response(const char *direction, time_t tm, uint64_t reqid, + int phase, int response, const char *param) +{ + const char *phase_name; + const char *response_name; + + switch (phase) { + case FILTER_CONNECTED: + phase_name = "connected"; + break; + case FILTER_HELO: + phase_name = "helo"; + break; + case FILTER_EHLO: + phase_name = "ehlo"; + break; + case FILTER_STARTTLS: + phase_name = "tls"; + break; + case FILTER_AUTH: + phase_name = "auth"; + break; + case FILTER_MAIL_FROM: + phase_name = "mail-from"; + break; + case FILTER_RCPT_TO: + phase_name = "rcpt-to"; + break; + case FILTER_DATA: + phase_name = "data"; + break; + case FILTER_DATA_LINE: + phase_name = "data-line"; + break; + case FILTER_RSET: + phase_name = "rset"; + break; + case FILTER_QUIT: + phase_name = "quit"; + break; + case FILTER_NOOP: + phase_name = "noop"; + break; + case FILTER_HELP: + phase_name = "help"; + break; + case FILTER_WIZ: + phase_name = "wiz"; + break; + case FILTER_COMMIT: + phase_name = "commit"; + break; + default: + phase_name = ""; + } + + switch (response) { + case FILTER_PROCEED: + response_name = "proceed"; + break; + case FILTER_REWRITE: + response_name = "rewrite"; + break; + case FILTER_REJECT: + response_name = "reject"; + break; + case FILTER_DISCONNECT: + response_name = "disconnect"; + break; + default: + response_name = ""; + } + + report_smtp_broadcast(direction, tm, + "filter-response|%016"PRIx64"|%s|%s|%s\n", + reqid, phase_name, response_name, param ? param : ""); +} diff --git a/usr.sbin/smtpd/smtp_report.c b/usr.sbin/smtpd/smtp_report.c index 68fe959bc7d..c8f95be7ca9 100644 --- a/usr.sbin/smtpd/smtp_report.c +++ b/usr.sbin/smtpd/smtp_report.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtp_report.c,v 1.8 2018/12/11 08:40:56 gilles Exp $ */ +/* $OpenBSD: smtp_report.c,v 1.9 2018/12/11 11:29:44 gilles Exp $ */ /* * Copyright (c) 2018 Gilles Chehade <gilles@poolp.org> @@ -172,3 +172,15 @@ smtp_report_protocol_server(uint64_t qid, const char *response) m_add_string(p_lka, response); m_close(p_lka); } + +void +smtp_report_filter_response(uint64_t qid, int phase, int response, const char *param) +{ + m_create(p_lka, IMSG_SMTP_REPORT_FILTER_RESPONSE, 0, 0, -1); + m_add_time(p_lka, time(NULL)); + m_add_id(p_lka, qid); + m_add_int(p_lka, phase); + m_add_int(p_lka, response); + m_add_string(p_lka, param); + m_close(p_lka); +} diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c index fe23897548a..68ab063df24 100644 --- a/usr.sbin/smtpd/smtp_session.c +++ b/usr.sbin/smtpd/smtp_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtp_session.c,v 1.369 2018/12/11 10:31:45 eric Exp $ */ +/* $OpenBSD: smtp_session.c,v 1.370 2018/12/11 11:29:44 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -994,6 +994,8 @@ smtp_session_imsg(struct mproc *p, struct imsg *imsg) m_get_int(&m, &filter_response); if (filter_response != FILTER_PROCEED) m_get_string(&m, &filter_param); + else + filter_param = NULL; m_end(&m); s = tree_xpop(&wait_filters, reqid); @@ -1007,6 +1009,9 @@ smtp_session_imsg(struct mproc *p, struct imsg *imsg) if (!strncmp(filter_param, "421", 3)) filter_response = FILTER_DISCONNECT; + smtp_report_filter_response(s->id, s->filter_phase, + filter_response, filter_param); + smtp_reply(s, "%s", filter_param); if (filter_response == FILTER_DISCONNECT) @@ -1020,6 +1025,9 @@ smtp_session_imsg(struct mproc *p, struct imsg *imsg) /* fallthrough*/ case FILTER_REWRITE: + smtp_report_filter_response(s->id, s->filter_phase, + filter_response, + filter_param == s->filter_param ? NULL : filter_param); if (s->filter_phase == FILTER_CONNECTED) { smtp_proceed_connected(s); return; diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 4ce139640cf..29fdc9477b4 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.587 2018/12/11 08:40:56 gilles Exp $ */ +/* $OpenBSD: smtpd.h,v 1.588 2018/12/11 11:29:44 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -327,6 +327,7 @@ enum imsg_type { IMSG_SMTP_REPORT_TX_ROLLBACK, IMSG_SMTP_REPORT_PROTOCOL_CLIENT, IMSG_SMTP_REPORT_PROTOCOL_SERVER, + IMSG_SMTP_REPORT_FILTER_RESPONSE, IMSG_SMTP_FILTER_BEGIN, IMSG_SMTP_FILTER_END, @@ -1353,6 +1354,8 @@ void lka_report_smtp_tx_commit(const char *, time_t, uint64_t, uint32_t, size_t) void lka_report_smtp_tx_rollback(const char *, time_t, uint64_t, uint32_t); void lka_report_smtp_protocol_client(const char *, time_t, uint64_t, const char *); void lka_report_smtp_protocol_server(const char *, time_t, uint64_t, const char *); +void lka_report_smtp_filter_response(const char *, time_t, uint64_t, + int, int, const char *); /* lka_filter.c */ @@ -1561,6 +1564,7 @@ void smtp_report_tx_commit(uint64_t, uint32_t, size_t); void smtp_report_tx_rollback(uint64_t, uint32_t); void smtp_report_protocol_client(uint64_t, const char *); void smtp_report_protocol_server(uint64_t, const char *); +void smtp_report_filter_response(uint64_t, int, int, const char *); /* smtp_session.c */ |