detect self-destructing alias loop more generally for better diagnostics
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Sun, 18 Jul 1993 04:46:53 +0000 (20:46 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Sun, 18 Jul 1993 04:46:53 +0000 (20:46 -0800)
SCCS-vsn: usr.sbin/sendmail/src/recipient.c 8.4
SCCS-vsn: usr.sbin/sendmail/src/srvrsmtp.c 8.5

usr/src/usr.sbin/sendmail/src/recipient.c
usr/src/usr.sbin/sendmail/src/srvrsmtp.c

index 8c64238..9d23203 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)recipient.c        8.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)recipient.c        8.4 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -58,6 +58,7 @@ sendto(list, copyf, ctladdr, qflags)
        bool firstone;          /* set on first address sent */
        char delimiter;         /* the address delimiter */
        int naddrs;
        bool firstone;          /* set on first address sent */
        char delimiter;         /* the address delimiter */
        int naddrs;
+       char *oldto = e->e_to;
        ADDRESS *sibl;          /* sibling pointer in tree */
        ADDRESS *prev;          /* previous sibling */
 
        ADDRESS *sibl;          /* sibling pointer in tree */
        ADDRESS *prev;          /* previous sibling */
 
@@ -137,7 +138,7 @@ sendto(list, copyf, ctladdr, qflags)
                }
        }
 
                }
        }
 
-       e->e_to = NULL;
+       e->e_to = oldto;
        return (naddrs);
        if (ctladdr != NULL)
                ctladdr->q_child = prev;
        return (naddrs);
        if (ctladdr != NULL)
                ctladdr->q_child = prev;
@@ -249,7 +250,7 @@ recipient(a, sendq, e)
            !bitset(EF_QUEUERUN, e->e_flags))
        {
                a->q_flags |= QBADADDR;
            !bitset(EF_QUEUERUN, e->e_flags))
        {
                a->q_flags |= QBADADDR;
-               usrerr("550 Cannot mail directly to programs", m->m_name);
+               usrerr("550 Cannot mail directly to programs");
        }
 
        /*
        }
 
        /*
@@ -304,7 +305,7 @@ recipient(a, sendq, e)
                printf("at trylocaluser %s\n", a->q_user);
 
        if (bitset(QDONTSEND|QBADADDR|QVERIFIED, a->q_flags))
                printf("at trylocaluser %s\n", a->q_user);
 
        if (bitset(QDONTSEND|QBADADDR|QVERIFIED, a->q_flags))
-               return (a);
+               goto testselfdestruct;
 
        if (m == InclMailer)
        {
 
        if (m == InclMailer)
        {
@@ -363,7 +364,7 @@ recipient(a, sendq, e)
        {
                if (!bitset(QDONTSEND, a->q_flags))
                        e->e_nrcpts++;
        {
                if (!bitset(QDONTSEND, a->q_flags))
                        e->e_nrcpts++;
-               return (a);
+               goto testselfdestruct;
        }
 
        /* try aliasing */
        }
 
        /* try aliasing */
@@ -389,14 +390,14 @@ recipient(a, sendq, e)
                        message("queued (user database error): %s",
                                errstring(errno));
                        e->e_nrcpts++;
                        message("queued (user database error): %s",
                                errstring(errno));
                        e->e_nrcpts++;
-                       return (a);
+                       goto testselfdestruct;
                }
        }
 # endif
 
        /* if it was an alias or a UDB expansion, just return now */
        if (bitset(QDONTSEND|QQUEUEUP|QVERIFIED, a->q_flags))
                }
        }
 # endif
 
        /* if it was an alias or a UDB expansion, just return now */
        if (bitset(QDONTSEND|QQUEUEUP|QVERIFIED, a->q_flags))
-               return (a);
+               goto testselfdestruct;
 
        /*
        **  If we have a level two config file, then pass the name through
 
        /*
        **  If we have a level two config file, then pass the name through
@@ -469,6 +470,19 @@ recipient(a, sendq, e)
        }
        if (!bitset(QDONTSEND, a->q_flags))
                e->e_nrcpts++;
        }
        if (!bitset(QDONTSEND, a->q_flags))
                e->e_nrcpts++;
+
+  testselfdestruct:
+       if (a->q_alias == NULL && a != &e->e_from)
+       {
+               q = a->q_next;
+               while (q != NULL && bitset(QDONTSEND|QBADADDR, q->q_flags))
+                       q = q->q_next;
+               if (bitset(QDONTSEND|QBADADDR, a->q_flags) && q == NULL)
+               {
+                       a->q_flags |= QBADADDR;
+                       usrerr("554 aliasing/forwarding loop broken");
+               }
+       }
        return (a);
 
        return (a);
        return (a);
 
        return (a);
@@ -769,6 +783,7 @@ include(fname, forwarding, ctladdr, sendq, e)
        (void) xfclose(fp, "include", fname);
        FileName = oldfilename;
        LineNumber = oldlinenumber;
        (void) xfclose(fp, "include", fname);
        FileName = oldfilename;
        LineNumber = oldlinenumber;
+       e->e_to = oldto;
        return 0;
 }
 
        return 0;
 }
 
index d544846..a50614b 100644 (file)
@@ -10,9 +10,9 @@
 
 #ifndef lint
 #ifdef SMTP
 
 #ifndef lint
 #ifdef SMTP
-static char sccsid[] = "@(#)srvrsmtp.c 8.4 (Berkeley) %G% (with SMTP)";
+static char sccsid[] = "@(#)srvrsmtp.c 8.5 (Berkeley) %G% (with SMTP)";
 #else
 #else
-static char sccsid[] = "@(#)srvrsmtp.c 8.4 (Berkeley) %G% (without SMTP)";
+static char sccsid[] = "@(#)srvrsmtp.c 8.5 (Berkeley) %G% (without SMTP)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */