Discussion:
Patch to make sender_canonical_maps work in all circumstances
(too old to reply)
Stephen R. van den Berg
2016-11-23 19:31:00 UTC
Permalink
Without this patch, running a second smtpd using something like this:

127.0.0.1:26 inet n - y - - smtpd
-o sender_canonical_maps=tcp:127.0.0.1:20001
-o sender_canonical_classes=envelope_sender
-o recipient_canonical_maps=tcp:127.0.0.1:20002
-o recipient_canonical_classes=envelope_recipient
-o local_recipient_maps=
-o smtpd_reject_unlisted_sender=yes

Is impossible (support in postfix is missing to parse all commandline options).
Also, it would be nice to add to the documentation that activating sender_canonical_maps *requires* setting smtpd_reject_unlisted_sender to yes.

Patch follows:
--------------------------cut here---------------------
diff -ru postfix-3.1.3/src/smtpd/smtpd.c pf313patched/src/smtpd/smtpd.c
--- postfix-3.1.3/src/smtpd/smtpd.c 2016-09-11 15:43:12.000000000 +0200
+++ pf313patched/src/smtpd/smtpd.c 2016-11-23 16:30:28.342629774 +0100
@@ -1239,6 +1239,7 @@
int var_strict_rfc821_env;
bool var_disable_vrfy_cmd;
char *var_canonical_maps;
+char *var_send_canon_maps;
char *var_rcpt_canon_maps;
char *var_virt_alias_maps;
char *var_virt_mailbox_maps;
@@ -5742,6 +5743,7 @@
VAR_ERROR_RCPT, DEF_ERROR_RCPT, &var_error_rcpt, 1, 0,
VAR_REST_CLASSES, DEF_REST_CLASSES, &var_rest_classes, 0, 0,
VAR_CANONICAL_MAPS, DEF_CANONICAL_MAPS, &var_canonical_maps, 0, 0,
+ VAR_SEND_CANON_MAPS, DEF_SEND_CANON_MAPS, &var_send_canon_maps, 0, 0,
VAR_RCPT_CANON_MAPS, DEF_RCPT_CANON_MAPS, &var_rcpt_canon_maps, 0, 0,
VAR_VIRT_ALIAS_MAPS, DEF_VIRT_ALIAS_MAPS, &var_virt_alias_maps, 0, 0,
VAR_VIRT_MAILBOX_MAPS, DEF_VIRT_MAILBOX_MAPS, &var_virt_mailbox_maps, 0, 0,
diff -ru postfix-3.1.3/src/smtpd/smtpd_check.c pf313patched/src/smtpd/smtpd_check.c
--- postfix-3.1.3/src/smtpd/smtpd_check.c 2016-02-15 18:06:11.000000000 +0100
+++ pf313patched/src/smtpd/smtpd_check.c 2016-11-23 18:27:58.628375511 +0100
@@ -278,6 +278,7 @@
* trivial-rewrite resolver.
*/
static MAPS *local_rcpt_maps;
+static MAPS *send_canon_maps;
static MAPS *rcpt_canon_maps;
static MAPS *canonical_maps;
static MAPS *virt_alias_maps;
@@ -737,6 +738,9 @@
local_rcpt_maps = maps_create(VAR_LOCAL_RCPT_MAPS, var_local_rcpt_maps,
DICT_FLAG_LOCK | DICT_FLAG_FOLD_FIX
| DICT_FLAG_UTF8_REQUEST);
+ send_canon_maps = maps_create(VAR_SEND_CANON_MAPS, var_send_canon_maps,
+ DICT_FLAG_LOCK | DICT_FLAG_FOLD_FIX
+ | DICT_FLAG_UTF8_REQUEST);
rcpt_canon_maps = maps_create(VAR_RCPT_CANON_MAPS, var_rcpt_canon_maps,
DICT_FLAG_LOCK | DICT_FLAG_FOLD_FIX
| DICT_FLAG_UTF8_REQUEST);
@@ -5103,7 +5107,7 @@
DSN_SPLIT dp;

if (msg_verbose)
- msg_info(">>> CHECKING RECIPIENT MAPS <<<");
+ msg_info(">>> CHECKING %s MAPS <<<", reply_class);

/*
* Resolve the address.
@@ -5128,7 +5132,9 @@
* stream. See also the next comment block on recipients in virtual alias
* domains.
*/
- if (MATCH(rcpt_canon_maps, CONST_STR(reply->recipient))
+
+ if (MATCH(strcmp(reply_class, SMTPD_NAME_SENDER) == 0
+ ? send_canon_maps : rcpt_canon_maps, CONST_STR(reply->recipient))
|| MATCH(canonical_maps, CONST_STR(reply->recipient))
|| MATCH(virt_alias_maps, CONST_STR(reply->recipient)))
return (0);
@@ -5476,6 +5482,7 @@
char *var_rcpt_delim;
char *var_rest_classes;
char *var_alias_maps;
+char *var_send_canon_maps;
char *var_rcpt_canon_maps;
char *var_canonical_maps;
char *var_virt_alias_maps;
@@ -5526,6 +5533,7 @@
VAR_RCPT_DELIM, DEF_RCPT_DELIM, &var_rcpt_delim,
VAR_REST_CLASSES, DEF_REST_CLASSES, &var_rest_classes,
VAR_ALIAS_MAPS, DEF_ALIAS_MAPS, &var_alias_maps,
+ VAR_SEND_CANON_MAPS, DEF_SEND_CANON_MAPS, &var_send_canon_maps,
VAR_RCPT_CANON_MAPS, DEF_RCPT_CANON_MAPS, &var_rcpt_canon_maps,
VAR_CANONICAL_MAPS, DEF_CANONICAL_MAPS, &var_canonical_maps,
VAR_VIRT_ALIAS_MAPS, DEF_VIRT_ALIAS_MAPS, &var_virt_alias_maps,
--------------------------cut here---------------------
--
Stephen R. van den Berg <***@cuci.nl>
Original author of procmail.
Stephen R. van den Berg
2016-11-23 22:23:52 UTC
Permalink
Maybe I should rephrase that: without this patch specifying
sender_canonical_maps anywhere has no tangible effect.
w***@gmail.com
2016-12-22 00:54:21 UTC
Permalink
[smtpd does not check sender_canonical_maps when reject_unlisted_sender or equivalent are specified]

Thanks for this patch!

Wietse

Loading...