Download raw body.
smtpd: implement the report response for proc-filters too
August 9, 2024 12:52 PM, "Omar Polo" <op@omarpolo.com> wrote:
> We don't seem to allow proc filters to report, unlike built-in ones. We
> document the report response thought, so I guess it's just an omission.
>
> I'm attaching a diff that adds the missing bits, I've quickly tried with
> a hacked version of Gilles' filter-kicker that does a report instead of
> a disconnect and I can see the report being broadcasted.
>
> This was reported by renegm on github:
> <https://github.com/OpenSMTPD/OpenSMTPD/issues/1257>
>
> Thoughts/clues?
>
Initial clue:
That was an "I'll implement it for proc filters later" moment that never came.
diff reads ok but I'd like to read it in context before giving an actual ok,
I'll try to do it today
> Thanks,
>
> Omar Polo
>
> diff /usr/src
> commit - 055349ebc95a6766143567ec24bc3f785a470f34
> path + /usr/src
> blob - 08db127c4c062f988b52fd483423388103bebacc
> file + usr.sbin/smtpd/lka_filter.c
> --- usr.sbin/smtpd/lka_filter.c
> +++ usr.sbin/smtpd/lka_filter.c
> @@ -47,6 +47,7 @@ static int filter_builtins_data(struct filter_session
> 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 ch
> 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);
> }
> @@ -957,6 +960,16 @@ filter_result_proceed(uint64_t reqid)
> }
>
> 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)
> {
> m_create(p_dispatcher, IMSG_FILTER_SMTP_PROTOCOL, 0, 0, -1);
> @@ -1633,6 +1646,9 @@ lka_report_smtp_filter_response(const char *direction,
> case FILTER_PROCEED:
> response_name = "proceed";
> break;
> + case FILTER_REPORT:
> + response_name = "report";
> + break;
> case FILTER_JUNK:
> response_name = "junk";
> break;
> blob - b72d295918243c5c57959ee721fe3117562d44ea
> file + usr.sbin/smtpd/smtp_session.c
> --- usr.sbin/smtpd/smtp_session.c
> +++ usr.sbin/smtpd/smtp_session.c
> @@ -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,
> blob - 6eddff3c72575c5bb29a1bf6788cfc4df950bb0a
> file + usr.sbin/smtpd/smtpd.h
> --- usr.sbin/smtpd/smtpd.h
> +++ usr.sbin/smtpd/smtpd.h
> @@ -1125,6 +1125,7 @@ struct filter_config {
>
> enum filter_status {
> FILTER_PROCEED,
> + FILTER_REPORT,
> FILTER_REWRITE,
> FILTER_REJECT,
> FILTER_DISCONNECT,
smtpd: implement the report response for proc-filters too