Re: smtpd(8): running as backup MX with +TAG addresses

2015-01-05 Thread Gilles Chehade
On Sat, Dec 27, 2014 at 11:56:29AM +, Florian Obser wrote:
> Hi,
> 
> so I want to run smtpd(8) as a backup MX and configure the list of
> valid email addresses so that the backup MX rejects invalid
> email addresses on accepting the message and not bounce
> the mail alter on when it tries to deliver to the primary
> mail server.
> Currently I have this:
> accept from any for domain  recipient  \
>   relay backup hostname "primary.mx.example.com"
> 
> Assuming I have example.com in the domains table and
> u...@example.com in the recipient table smptd rejects
> rcpt to: 
> with
> 550 Invalid recipient
> 
> rcpt to: 
> works just fine.
> 
> This is on -current.
> 
> How can I get +TAG to work on the backup MX?
> 

This diff should do the trick.
It teaches "sender" and "recipient" how to cope with tags in addresses.

Let me know how it goes for you.


diff --git a/smtpd/table.c b/smtpd/table.c
index 66fdb7a..cc61e74 100644
--- a/smtpd/table.c
+++ b/smtpd/table.c
@@ -347,6 +347,12 @@ table_update(struct table *t)
return (t->t_backend->update(t));
 }
 
+
+/*
+ * quick reminder:
+ * in *_match() s1 comes from session, s2 comes from table
+ */
+
 int
 table_domain_match(const char *s1, const char *s2)
 {
@@ -358,6 +364,7 @@ table_mailaddr_match(const char *s1, const char *s2)
 {
struct mailaddr m1;
struct mailaddr m2;
+   char   *p;
 
if (! text_to_mailaddr(&m1, s1))
return 0;
@@ -367,9 +374,17 @@ table_mailaddr_match(const char *s1, const char *s2)
if (! table_domain_match(m1.domain, m2.domain))
return 0;
 
-   if (m2.user[0])
+   if (m2.user[0]) {
+   /* if address from table has a tag, we must respect it */
+   if (strchr(m2.user, '+') == NULL) {
+   /* otherwise, strip tag from session address if any */
+   p = strchr(m1.user, '+');
+   if (p)
+   *p = '\0';
+   }
if (strcasecmp(m1.user, m2.user))
return 0;
+   }
return 1;
 }
 


-- 
Gilles Chehade

https://www.poolp.org  @poolpOrg



Re: smtpd(8): running as backup MX with +TAG addresses

2015-01-05 Thread Gilles Chehade
On Sat, Dec 27, 2014 at 11:56:29AM +, Florian Obser wrote:
> Hi,
> 
> so I want to run smtpd(8) as a backup MX and configure the list of
> valid email addresses so that the backup MX rejects invalid
> email addresses on accepting the message and not bounce
> the mail alter on when it tries to deliver to the primary
> mail server.
> Currently I have this:
> accept from any for domain  recipient  \
>   relay backup hostname "primary.mx.example.com"
> 
> Assuming I have example.com in the domains table and
> u...@example.com in the recipient table smptd rejects
> rcpt to: 
> with
> 550 Invalid recipient
> 
> rcpt to: 
> works just fine.
> 
> This is on -current.
> 
> How can I get +TAG to work on the backup MX?
> 

At the moment, "recipient" is unaware of "+" tagging you can only backup
a full domain or specific untagged recipients.

This doesn't seem too hard to implement though, I'll see if I can get it
done this week.

-- 
Gilles Chehade

https://www.poolp.org  @poolpOrg



smtpd(8): running as backup MX with +TAG addresses

2014-12-27 Thread Florian Obser
Hi,

so I want to run smtpd(8) as a backup MX and configure the list of
valid email addresses so that the backup MX rejects invalid
email addresses on accepting the message and not bounce
the mail alter on when it tries to deliver to the primary
mail server.
Currently I have this:
accept from any for domain  recipient  \
relay backup hostname "primary.mx.example.com"

Assuming I have example.com in the domains table and
u...@example.com in the recipient table smptd rejects
rcpt to: 
with
550 Invalid recipient

rcpt to: 
works just fine.

This is on -current.

How can I get +TAG to work on the backup MX?

Thanks,
Florian

-- 
I'm not entirely sure you are real.