Hi,
The current code for aliases_get() is a bit contorted I think.
This diff makes it clearer.
Eric.
Index: aliases.c
===================================================================
RCS file: /cvs/src/usr.sbin/smtpd/aliases.c,v
retrieving revision 1.77
diff -u -p -r1.77 aliases.c
--- aliases.c 28 Dec 2018 12:47:28 -0000 1.77
+++ aliases.c 25 Apr 2020 11:35:08 -0000
@@ -53,23 +53,18 @@ aliases_get(struct expand *expand, const
xlowercase(buf, username, sizeof(buf));
- /* first, check if entry has a user-part tag */
- pbuf = strchr(buf, *env->sc_subaddressing_delim);
- if (pbuf) {
- ret = table_lookup(mapping, K_ALIAS, buf, &lk);
- if (ret < 0)
- return (-1);
- if (ret)
- goto expand;
+ /* First, check the username as given. */
+ ret = table_lookup(mapping, K_ALIAS, buf, &lk);
+ if (ret == 0 && (pbuf = strchr(buf, *env->sc_subaddressing_delim))) {
+ /* Not found, retry without the tag if there is one. */
*pbuf = '\0';
+ ret = table_lookup(mapping, K_ALIAS, buf, &lk);
}
- /* no user-part tag, try looking up user */
- ret = table_lookup(mapping, K_ALIAS, buf, &lk);
+ /* Not found or error */
if (ret <= 0)
return ret;
-expand:
/* foreach node in table_alias expandtree, we merge */
nbaliases = 0;
RB_FOREACH(xn, expandtree, &lk.expand->tree) {