Sorry but on a second thought, this is wrong for several reasons. The main one is that aliases transforms recipient addresses BEFORE they are matched to a local user, so imagine you have something like:
root: gilles @: gilles If I send mail to e...@poolp.org and there's a local user eric, what should it do ? Either you consider that local user eric should get it but this contradicts aliases configuration as it now explicitly states that *@poolp.org should resolve to gilles and, if that's what I really wanted, it would be the only way to express it. Or you consider that gilles is supposed to get it but then it means that a catchall will get mail for any recipient that is not listed in the aliases configuration. So to receive mail for eric, you'd need to list him as such: root: gilles eric: eric @: gilles ... and it turns domain aliases into virtual domains aliases as the main difference between both is precisely that aliases are allowed to not resolve to a user whereas virtual requires resolution to succeed. You want a mechanism that has enough knowledge of the recipients to determine which ones do not exist and should be handled by the catchall but aliases aren't meant to do that: they are expectedly allowed to have missing keys for bypass. If I were you, I'd try to fit my use-case in virtual rather than aliases as this is the mechanism intended for what you're trying to do. I had a look at Postfix and if I'm not mistaken they also have catchall part of virtual rather than aliases, which would likely be for the same reasons. Gilles April 15, 2022 1:10 AM, gil...@poolp.org wrote: > Forget about the whole fallback idea, it can't work because an envelope can > only > successfully match a single rule for _very_ good reasons that are not related > to > the implementation itself but to how SMTP works more generally. The ruleset > does > a first-match evaluation and once it found a rule that matched, that is the > only > rule it can consider for that envelope otherwise TONS of unfixable issues > arise. > I can explain if there's interest, but it's very technical and unrelated to > your > issue. > > The only reason you are trying to fallback is because aliases_get() did not > have > the same wildcard logic as virtual_get(), otherwise with a configuration like: > > match from any for domain "domain.com" action "local_mail" > > and an alias record of "@: username" (or an inlined { "@" = username }), the > use > case you have is solved without having to think about a fallback rule. > > Care to try the following diff ? > > Index: aliases.c > =================================================================== > RCS file: /cvs/src/usr.sbin/smtpd/aliases.c,v > retrieving revision 1.78 > diff -u -p -r1.78 aliases.c > --- aliases.c 28 Apr 2020 21:46:43 -0000 1.78 > +++ aliases.c 14 Apr 2022 22:40:24 -0000 > @@ -66,8 +66,15 @@ aliases_get(struct expand *expand, const > > /* no user-part tag, try looking up user */ > ret = table_lookup(mapping, K_ALIAS, buf, &lk); > + if (ret < 0) > + return (-1); > + if (ret) > + goto expand; > + > + /* Failed ? We lookup for a *global* catch all */ > + ret = table_lookup(mapping, K_ALIAS, "@", &lk); > if (ret <= 0) > - return ret; > + return (ret); > > expand: > /* foreach node in table_alias expandtree, we merge */ > > April 14, 2022 9:00 PM, "Beau Ford" <bf...@0x.co> wrote: > >> On Thu, 14 Apr 2022, Beau Ford wrote: > > 1) Am I still using my aliases that are defined in: > > table aliases file:/usr/local/etc/mail/aliases > action "local_mail" mbox alias <aliases> > > ... or are those superceded now by the catchall ? >> It turns out I am *not* using my aliases anymore and that my rules, as >> they are written, are mutually exclusive. >> >> If I order them like this: >> >> match from any for domain "domain.com" action "local_mail" >> match from any for domain "domain.com" action "catchall" >> >> ... then my aliases table is processed, like normal, and the catchall is >> ignored. This makes sense, because the rule matches and it completes - >> there is no reason to move on to the catchall address. >> >> Nonexistent addresses (that I hoped to get with the catchall) bomb out >> with 550 Invalid recipient. >> >> HOWEVER, if I reverse the order: >> >> match from any for domain "domain.com" action "catchall" >> match from any for domain "domain.com" action "local_mail" >> >> ... then the catch-all works and I lose all of my aliases. My aliases >> table is not used. Again, makes sense - the first rule matches and >> completes. >> >> ----- >> >> So, how can I say (pseudocode): >> >> match from any person actually a user or in my aliases table action >> "local_mail" >> >> ... which would fail for nonexistent addresses, which is GOOD, and then >> successfully move down to the catchall match ?