From d49c07c786cfbc18357be57b78b5771525d1b8bb Mon Sep 17 00:00:00 2001 From: op Date: Mon, 12 Aug 2024 09:32:44 +0000 Subject: [PATCH] implement the report response for proc-filters too Reported by renegm on GitHub: ok gilles@ --- usr.sbin/smtpd/lka_filter.c | 18 +++++++++++++++++- usr.sbin/smtpd/smtp_session.c | 3 ++- usr.sbin/smtpd/smtpd.h | 3 ++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/usr.sbin/smtpd/lka_filter.c b/usr.sbin/smtpd/lka_filter.c index 08db127c4c0..b9c5d55c15f 100644 --- a/usr.sbin/smtpd/lka_filter.c +++ b/usr.sbin/smtpd/lka_filter.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka_filter.c,v 1.77 2024/05/14 13:38:54 op Exp $ */ +/* $OpenBSD: lka_filter.c,v 1.78 2024/08/12 09:32:44 op Exp $ */ /* * Copyright (c) 2018 Gilles Chehade @@ -47,6 +47,7 @@ static int filter_builtins_data(struct filter_session *, struct filter *, uint64 static int filter_builtins_commit(struct filter_session *, struct filter *, uint64_t, const char *); static void filter_result_proceed(uint64_t); +static void filter_result_report(uint64_t, const char *); static void filter_result_junk(uint64_t); static void filter_result_rewrite(uint64_t, const char *); static void filter_result_reject(uint64_t, const char *); @@ -657,6 +658,8 @@ lka_filter_process_response(const char *name, const char *line) filter_result_reject(reqid, parameter); else if (strncmp(response, "disconnect|", 11) == 0) filter_result_disconnect(reqid, parameter); + else if (strncmp(response, "report|", 7) == 0) + filter_result_report(reqid, parameter); else fatalx("Invalid directive: %s", line); } @@ -956,6 +959,16 @@ filter_result_proceed(uint64_t reqid) m_close(p_dispatcher); } +static void +filter_result_report(uint64_t reqid, const char *param) +{ + m_create(p_dispatcher, IMSG_FILTER_SMTP_PROTOCOL, 0, 0, -1); + m_add_id(p_dispatcher, reqid); + m_add_int(p_dispatcher, FILTER_REPORT); + m_add_string(p_dispatcher, param); + m_close(p_dispatcher); +} + static void filter_result_junk(uint64_t reqid) { @@ -1633,6 +1646,9 @@ lka_report_smtp_filter_response(const char *direction, struct timeval *tv, uint6 case FILTER_PROCEED: response_name = "proceed"; break; + case FILTER_REPORT: + response_name = "report"; + break; case FILTER_JUNK: response_name = "junk"; break; diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c index b72d2959182..85659829f54 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.442 2024/03/20 17:52:43 op Exp $ */ +/* $OpenBSD: smtp_session.c,v 1.443 2024/08/12 09:32:44 op Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -1026,6 +1026,7 @@ smtp_session_imsg(struct mproc *p, struct imsg *imsg) filter_param = s->filter_param; /* fallthrough */ + case FILTER_REPORT: case FILTER_REWRITE: smtp_report_filter_response(s, s->filter_phase, filter_response, diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 6eddff3c725..2be11bf2b53 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.686 2024/06/02 23:26:39 jsg Exp $ */ +/* $OpenBSD: smtpd.h,v 1.687 2024/08/12 09:32:44 op Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -1125,6 +1125,7 @@ struct filter_config { enum filter_status { FILTER_PROCEED, + FILTER_REPORT, FILTER_REWRITE, FILTER_REJECT, FILTER_DISCONNECT, -- 2.20.1