summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgilles <gilles@openbsd.org>2018-12-12 21:27:49 +0000
committergilles <gilles@openbsd.org>2018-12-12 21:27:49 +0000
commite7d82dd01f12492236af30873ed903fe440a9053 (patch)
treeeea0d2805691318870296de21bb887ad48aa6ed1
parentSimplify mbzero() by using mem_write with a NULL buf which does zero out (diff)
downloadwireguard-openbsd-e7d82dd01f12492236af30873ed903fe440a9053.tar.xz
wireguard-openbsd-e7d82dd01f12492236af30873ed903fe440a9053.zip
add tx-data reporting event
-rw-r--r--usr.sbin/smtpd/lka.c14
-rw-r--r--usr.sbin/smtpd/lka_report.c22
-rw-r--r--usr.sbin/smtpd/report_smtp.c14
-rw-r--r--usr.sbin/smtpd/smtp_session.c18
-rw-r--r--usr.sbin/smtpd/smtpd.h5
5 files changed, 64 insertions, 9 deletions
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c
index ba55e43ebb8..71e968aa359 100644
--- a/usr.sbin/smtpd/lka.c
+++ b/usr.sbin/smtpd/lka.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lka.c,v 1.225 2018/12/11 13:40:30 gilles Exp $ */
+/* $OpenBSD: lka.c,v 1.226 2018/12/12 21:27:49 gilles Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -516,6 +516,18 @@ lka_imsg(struct mproc *p, struct imsg *imsg)
lka_report_smtp_tx_envelope(direction, tm, reqid, msgid, evpid);
return;
+ case IMSG_REPORT_SMTP_TX_DATA:
+ m_msg(&m, imsg);
+ m_get_string(&m, &direction);
+ m_get_time(&m, &tm);
+ m_get_id(&m, &reqid);
+ m_get_u32(&m, &msgid);
+ m_get_int(&m, &ok);
+ m_end(&m);
+
+ lka_report_smtp_tx_data(direction, tm, reqid, msgid, ok);
+ return;
+
case IMSG_REPORT_SMTP_TX_COMMIT:
m_msg(&m, imsg);
m_get_string(&m, &direction);
diff --git a/usr.sbin/smtpd/lka_report.c b/usr.sbin/smtpd/lka_report.c
index 5ae549d4733..c368fbc6c38 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.13 2018/12/11 11:29:44 gilles Exp $ */
+/* $OpenBSD: lka_report.c,v 1.14 2018/12/12 21:27:49 gilles Exp $ */
/*
* Copyright (c) 2018 Gilles Chehade <gilles@poolp.org>
@@ -179,6 +179,26 @@ lka_report_smtp_tx_envelope(const char *direction, time_t tm, uint64_t reqid, ui
}
void
+lka_report_smtp_tx_data(const char *direction, time_t tm, uint64_t reqid, uint32_t msgid, int ok)
+{
+ const char *result;
+
+ switch (ok) {
+ case 1:
+ result = "ok";
+ break;
+ case 0:
+ result = "permfail";
+ break;
+ default:
+ result = "tempfail";
+ break;
+ }
+ report_smtp_broadcast(direction, tm,
+ "tx-data|%016"PRIx64"|%08x|%s\n", reqid, msgid, result);
+}
+
+void
lka_report_smtp_tx_commit(const char *direction, time_t tm, uint64_t reqid, uint32_t msgid, size_t msgsz)
{
report_smtp_broadcast(direction, tm,
diff --git a/usr.sbin/smtpd/report_smtp.c b/usr.sbin/smtpd/report_smtp.c
index d2299b55288..e2cac45f633 100644
--- a/usr.sbin/smtpd/report_smtp.c
+++ b/usr.sbin/smtpd/report_smtp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: report_smtp.c,v 1.1 2018/12/11 13:29:52 gilles Exp $ */
+/* $OpenBSD: report_smtp.c,v 1.2 2018/12/12 21:27:49 gilles Exp $ */
/*
* Copyright (c) 2018 Gilles Chehade <gilles@poolp.org>
@@ -141,6 +141,18 @@ report_smtp_tx_envelope(const char *direction, uint64_t qid, uint32_t msgid, uin
}
void
+report_smtp_tx_data(const char *direction, uint64_t qid, uint32_t msgid, int ok)
+{
+ m_create(p_lka, IMSG_REPORT_SMTP_TX_DATA, 0, 0, -1);
+ m_add_string(p_lka, direction);
+ m_add_time(p_lka, time(NULL));
+ m_add_id(p_lka, qid);
+ m_add_u32(p_lka, msgid);
+ m_add_int(p_lka, ok);
+ m_close(p_lka);
+}
+
+void
report_smtp_tx_commit(const char *direction, uint64_t qid, uint32_t msgid, size_t msgsz)
{
m_create(p_lka, IMSG_REPORT_SMTP_TX_COMMIT, 0, 0, -1);
diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c
index fbf57ebea11..322045ebdeb 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.373 2018/12/12 10:50:04 gilles Exp $ */
+/* $OpenBSD: smtp_session.c,v 1.374 2018/12/12 21:27:49 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -2030,8 +2030,6 @@ smtp_reply(struct smtp_session *s, char *fmt, ...)
log_trace(TRACE_SMTP, "smtp: %p: >>> %s", s, buf);
- io_xprintf(s->io, "%s\r\n", buf);
-
switch (buf[0]) {
case '2':
if (s->last_cmd == CMD_MAIL_FROM)
@@ -2039,6 +2037,10 @@ smtp_reply(struct smtp_session *s, char *fmt, ...)
else if (s->last_cmd == CMD_RCPT_TO)
report_smtp_tx_rcpt("smtp-in", s->id, s->tx->msgid, s->cmd + 8, 1);
break;
+ case '3':
+ if (s->last_cmd == CMD_DATA)
+ report_smtp_tx_data("smtp-in", s->id, s->tx->msgid, 1);
+ break;
case '5':
case '4':
/* do not report smtp_tx_mail/smtp_tx_rcpt errors
@@ -2051,6 +2053,9 @@ smtp_reply(struct smtp_session *s, char *fmt, ...)
else if (s->last_cmd == CMD_RCPT_TO)
report_smtp_tx_rcpt("smtp-in", s->id,
s->tx->msgid, s->cmd + 8, buf[0] == '4' ? -1 : 0);
+ else if (s->last_cmd == CMD_DATA && s->tx->rcptcount)
+ report_smtp_tx_data("smtp-in", s->id, s->tx->msgid,
+ buf[0] == '4' ? -1 : 0);
}
if (s->flags & SF_BADINPUT) {
@@ -2085,6 +2090,8 @@ smtp_reply(struct smtp_session *s, char *fmt, ...)
}
break;
}
+
+ io_xprintf(s->io, "%s\r\n", buf);
report_smtp_protocol_server("smtp-in", s->id, buf);
}
@@ -2808,6 +2815,9 @@ smtp_message_begin(struct smtp_tx *tx)
log_debug("smtp: %p: message begin", s);
+ smtp_reply(s, "354 Enter mail, end with \".\""
+ " on a line by itself");
+
m_printf(tx, "Received: ");
if (!(s->listener->flags & F_MASK_SOURCE)) {
m_printf(tx, "from %s (%s [%s])",
@@ -2849,8 +2859,6 @@ smtp_message_begin(struct smtp_tx *tx)
m_printf(tx, ";\n\t%s\n", time_to_text(time(&tx->time)));
smtp_enter_state(s, STATE_BODY);
- smtp_reply(s, "354 Enter mail, end with \".\""
- " on a line by itself");
}
static void
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index b5f67d3bfcc..bd2dff753d5 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.591 2018/12/11 13:40:30 gilles Exp $ */
+/* $OpenBSD: smtpd.h,v 1.592 2018/12/12 21:27:49 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -321,6 +321,7 @@ enum imsg_type {
IMSG_REPORT_SMTP_TX_MAIL,
IMSG_REPORT_SMTP_TX_RCPT,
IMSG_REPORT_SMTP_TX_ENVELOPE,
+ IMSG_REPORT_SMTP_TX_DATA,
IMSG_REPORT_SMTP_TX_COMMIT,
IMSG_REPORT_SMTP_TX_ROLLBACK,
IMSG_REPORT_SMTP_PROTOCOL_CLIENT,
@@ -1336,6 +1337,7 @@ void lka_report_smtp_tx_mail(const char *, time_t, uint64_t, uint32_t, const cha
void lka_report_smtp_tx_rcpt(const char *, time_t, uint64_t, uint32_t, const char *, int);
void lka_report_smtp_tx_envelope(const char *, time_t, uint64_t, uint32_t, uint64_t);
void lka_report_smtp_tx_commit(const char *, time_t, uint64_t, uint32_t, size_t);
+void lka_report_smtp_tx_data(const char *, time_t, uint64_t, uint32_t, int);
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 *);
@@ -1510,6 +1512,7 @@ void report_smtp_tx_begin(const char *, uint64_t, uint32_t);
void report_smtp_tx_mail(const char *, uint64_t, uint32_t, const char *, int);
void report_smtp_tx_rcpt(const char *, uint64_t, uint32_t, const char *, int);
void report_smtp_tx_envelope(const char *, uint64_t, uint32_t, uint64_t);
+void report_smtp_tx_data(const char *, uint64_t, uint32_t, int);
void report_smtp_tx_commit(const char *, uint64_t, uint32_t, size_t);
void report_smtp_tx_rollback(const char *, uint64_t, uint32_t);
void report_smtp_protocol_client(const char *, uint64_t, const char *);