Wietse Venema:
> I noticed that the Postfix implementation does the postfix<->milter
> setup while reporting the SMTP connect event.
> This evaluates the connect macros before the postfix<->milter setup
> has a chance to override them.
>
> Fix would be a some swap of some code.
As implemented in this patch: move the on-the-fly connect before
the macroi evaluation. Should work for Postfix 2.5 and later.
Wietse
diff '--exclude=man' '--exclude=html' '--exclude=README_FILES'
'--exclude=INSTALL' '--exclude=.indent.pro' '--exclude=Makefile.in' -r -ur
/var/tmp/postfix-3.5-20200111/HISTORY ./HISTORY
--- /var/tmp/postfix-3.5-20200111/HISTORY 2020-01-11 08:13:31.000000000
-0500
+++ ./HISTORY 2020-01-15 09:52:37.283727701 -0500
@@ -24534,3 +24534,10 @@
= smtp:foo.exmple, bar.example". Files: smtp/smtp.c,
smtp/smtp_connect.c, trivial-rewrite/resolve.c, proto/transport,
proto/postconf.proto, global/mail_params.c.
+
+20200115
+
+ Bugfix (introduced: Postfix 2.5): the Milter connect event
+ macros were evaluated before the Milter connection itself
+ had been negottiated. Problem reported by David Bürgin.
+ Files: milter/milter.h, milter/milter.c, milter/milter8.c
diff '--exclude=man' '--exclude=html' '--exclude=README_FILES'
'--exclude=INSTALL' '--exclude=.indent.pro' '--exclude=Makefile.in' -r -ur
/var/tmp/postfix-3.5-20200111/src/milter/milter8.c ./src/milter/milter8.c
--- /var/tmp/postfix-3.5-20200111/src/milter/milter8.c 2018-11-27
19:30:23.000000000 -0500
+++ ./src/milter/milter8.c 2020-01-15 09:32:31.488633919 -0500
@@ -1918,15 +1918,6 @@
#define STR_NE(x,y) (strcmp((x), (y)) != 0)
/*
- * XXX Sendmail 8 libmilter closes the MTA-to-filter socket when it finds
- * out that the SMTP client has disconnected. Because of this, Postfix
- * has to open a new MTA-to-filter socket for each SMTP client.
- */
-#ifdef LIBMILTER_AUTO_DISCONNECT
- milter8_connect(milter);
-#endif
-
- /*
* Report the event.
*/
switch (milter->state) {
@@ -2835,6 +2826,10 @@
/*
* Fill in the structure. Note: all strings must be copied.
+ *
+ * XXX Sendmail 8 libmilter closes the MTA-to-filter socket when it finds
+ * out that the SMTP client has disconnected. Because of this, Postfix
+ * has to open a new MTA-to-filter socket for each SMTP client.
*/
milter = (MILTER8 *) mymalloc(sizeof(*milter));
milter->m.name = mystrdup(name);
@@ -2842,6 +2837,11 @@
milter->m.next = 0;
milter->m.parent = parent;
milter->m.macros = 0;
+#ifdef LIBMILTER_AUTO_DISCONNECT
+ milter->m.connect_on_demand = (void (*) (struct MILTER *)) milter8_connect;
+#else
+ milter->m.connect_on_demand = 0;
+#endif
milter->m.conn_event = milter8_conn_event;
milter->m.helo_event = milter8_helo_event;
milter->m.mail_event = milter8_mail_event;
diff '--exclude=man' '--exclude=html' '--exclude=README_FILES'
'--exclude=INSTALL' '--exclude=.indent.pro' '--exclude=Makefile.in' -r -ur
/var/tmp/postfix-3.5-20200111/src/milter/milter.c ./src/milter/milter.c
--- /var/tmp/postfix-3.5-20200111/src/milter/milter.c 2017-02-21
17:32:57.000000000 -0500
+++ ./src/milter/milter.c 2020-01-15 09:37:43.834235726 -0500
@@ -417,6 +417,8 @@
if (msg_verbose)
msg_info("report connect to all milters");
for (resp = 0, m = milters->milter_list; resp == 0 && m != 0; m = m->next)
{
+ if (m->connect_on_demand != 0)
+ m->connect_on_demand(m);
any_macros = MILTER_MACRO_EVAL(global_macros, m, milters, conn_macros);
resp = m->conn_event(m, client_name, client_addr, client_port,
addr_family, any_macros);
diff '--exclude=man' '--exclude=html' '--exclude=README_FILES'
'--exclude=INSTALL' '--exclude=.indent.pro' '--exclude=Makefile.in' -r -ur
/var/tmp/postfix-3.5-20200111/src/milter/milter.h ./src/milter/milter.h
--- /var/tmp/postfix-3.5-20200111/src/milter/milter.h 2016-06-11
18:17:03.000000000 -0400
+++ ./src/milter/milter.h 2020-01-15 09:32:31.498634162 -0500
@@ -35,6 +35,7 @@
struct MILTER *next; /* linkage */
struct MILTERS *parent; /* parent information */
struct MILTER_MACROS *macros; /* private macros */
+ void (*connect_on_demand) (struct MILTER *);
const char *(*conn_event) (struct MILTER *, const char *, const char *,
const char *, unsigned, ARGV *);
const char *(*helo_event) (struct MILTER *, const char *, int, ARGV *);
const char *(*mail_event) (struct MILTER *, const char **, ARGV *);