]> git.ipfire.org Git - people/ms/dma.git/commitdiff
implement the "*" catch-all alias
authorSimon Schubert <2@0x2c.org>
Wed, 16 Nov 2011 12:32:05 +0000 (13:32 +0100)
committerSimon Schubert <2@0x2c.org>
Wed, 16 Nov 2011 12:32:05 +0000 (13:32 +0100)
dma.8
dma.c
dma.h
mail.c

diff --git a/dma.8 b/dma.8
index d34b3d6df0f5ee3ce25c505f57797bc99c164468..e5c7182334de4f8bb3595ba466c6d3db744f1bc5 100644 (file)
--- a/dma.8
+++ b/dma.8
@@ -185,6 +185,22 @@ or not.
 .Xc
 Path to the local aliases file.
 Just stick with the default.
 .Xc
 Path to the local aliases file.
 Just stick with the default.
+The aliases file is of the format
+.Dl nam: dest1 dest2 ...
+In this case, mails to
+.Li nam
+will instead be delivered to
+.Li dest1
+and
+.Li dest2 ,
+which in turn could be entries in
+.Pa /etc/aliases .
+The special name
+.Ql *
+can be used to create a catch-all alias, which gets used if no other
+matching alias is found.
+Use the catch-all alias only if you don't want any local mail to be
+delivered.
 .It Ic SPOOLDIR Xo
 (string, default=/var/spool/dma)
 .Xc
 .It Ic SPOOLDIR Xo
 (string, default=/var/spool/dma)
 .Xc
diff --git a/dma.c b/dma.c
index 3b1aeb1eac88f7ee2edcf919d98caff6c0cefb84..48c429c443543e2c822bd82c7da8322d2bac453a 100644 (file)
--- a/dma.c
+++ b/dma.c
@@ -144,12 +144,30 @@ read_aliases(void)
        return (0);
 }
 
        return (0);
 }
 
+static int
+do_alias(struct queue *queue, const char *addr)
+{
+       struct alias *al;
+        struct stritem *sit;
+       int aliased = 0;
+
+        LIST_FOREACH(al, &aliases, next) {
+                if (strcmp(al->alias, addr) != 0)
+                        continue;
+               SLIST_FOREACH(sit, &al->dests, next) {
+                       if (add_recp(queue, sit->str, EXPAND_ADDR) != 0)
+                               return (-1);
+               }
+               aliased = 1;
+        }
+
+        return (aliased);
+}
+
 int
 add_recp(struct queue *queue, const char *str, int expand)
 {
        struct qitem *it, *tit;
 int
 add_recp(struct queue *queue, const char *str, int expand)
 {
        struct qitem *it, *tit;
-       struct stritem *sit;
-       struct alias *al;
        struct passwd *pw;
        char *host;
        int aliased = 0;
        struct passwd *pw;
        char *host;
        int aliased = 0;
@@ -180,15 +198,11 @@ add_recp(struct queue *queue, const char *str, int expand)
        if (strrchr(it->addr, '@') == NULL) {
                it->remote = 0;
                if (expand) {
        if (strrchr(it->addr, '@') == NULL) {
                it->remote = 0;
                if (expand) {
-                       LIST_FOREACH(al, &aliases, next) {
-                               if (strcmp(al->alias, it->addr) != 0)
-                                       continue;
-                               SLIST_FOREACH(sit, &al->dests, next) {
-                                       if (add_recp(queue, sit->str, 1) != 0)
-                                               return (-1);
-                               }
-                               aliased = 1;
-                       }
+                       aliased = do_alias(queue, it->addr);
+                       if (!aliased && expand == EXPAND_WILDCARD)
+                               aliased = do_alias(queue, "*");
+                       if (aliased < 0)
+                               return (-1);
                        if (aliased) {
                                LIST_REMOVE(it, next);
                        } else {
                        if (aliased) {
                                LIST_REMOVE(it, next);
                        } else {
@@ -544,7 +558,7 @@ skipopts:
        setlogident("%s", queue.id);
 
        for (i = 0; i < argc; i++) {
        setlogident("%s", queue.id);
 
        for (i = 0; i < argc; i++) {
-               if (add_recp(&queue, argv[i], 1) != 0)
+               if (add_recp(&queue, argv[i], EXPAND_WILDCARD) != 0)
                        errlogx(1, "invalid recipient `%s'", argv[i]);
        }
 
                        errlogx(1, "invalid recipient `%s'", argv[i]);
        }
 
diff --git a/dma.h b/dma.h
index 69c981b86a624de68adefb4eba1094fff1035cd8..a1e4b8c4f5a8b0c7b67b2ef01223f8874553f8e7 100644 (file)
--- a/dma.h
+++ b/dma.h
@@ -187,6 +187,8 @@ int base64_encode(const void *, int, char **);
 int base64_decode(const char *, void *);
 
 /* dma.c */
 int base64_decode(const char *, void *);
 
 /* dma.c */
+#define EXPAND_ADDR    1
+#define EXPAND_WILDCARD        2
 int add_recp(struct queue *, const char *, int);
 void run_queue(struct queue *);
 
 int add_recp(struct queue *, const char *, int);
 void run_queue(struct queue *);
 
diff --git a/mail.c b/mail.c
index e0a22af19c8d55a57a21711525a4158aa506a2ad..b9e13e0dd94c5d5c70e268adcbaeef66a0cea254 100644 (file)
--- a/mail.c
+++ b/mail.c
@@ -57,7 +57,7 @@ bounce(struct qitem *it, const char *reason)
        bzero(&bounceq, sizeof(bounceq));
        LIST_INIT(&bounceq.queue);
        bounceq.sender = "";
        bzero(&bounceq, sizeof(bounceq));
        LIST_INIT(&bounceq.queue);
        bounceq.sender = "";
-       if (add_recp(&bounceq, it->sender, 1) != 0)
+       if (add_recp(&bounceq, it->sender, EXPAND_WILDCARD) != 0)
                goto fail;
 
        if (newspoolf(&bounceq) != 0)
                goto fail;
 
        if (newspoolf(&bounceq) != 0)
@@ -334,7 +334,7 @@ newaddr:
        if (addr == NULL)
                errlog(1, NULL);
 
        if (addr == NULL)
                errlog(1, NULL);
 
-       if (add_recp(queue, addr, 1) != 0)
+       if (add_recp(queue, addr, EXPAND_WILDCARD) != 0)
                errlogx(1, "invalid recipient `%s'", addr);
 
        goto again;
                errlogx(1, "invalid recipient `%s'", addr);
 
        goto again;