implement $&x for deferred macro expansion; some POSIX compatibility
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Sun, 11 Apr 1993 00:28:28 +0000 (16:28 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Sun, 11 Apr 1993 00:28:28 +0000 (16:28 -0800)
SCCS-vsn: usr.sbin/sendmail/src/main.c 6.54
SCCS-vsn: usr.sbin/sendmail/src/envelope.c 6.30
SCCS-vsn: usr.sbin/sendmail/src/parseaddr.c 6.37

usr/src/usr.sbin/sendmail/src/envelope.c
usr/src/usr.sbin/sendmail/src/main.c
usr/src/usr.sbin/sendmail/src/parseaddr.c

index 5ee246e..8d340cc 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)envelope.c 6.29 (Berkeley) %G%";
+static char sccsid[] = "@(#)envelope.c 6.30 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "sendmail.h"
 #endif /* not lint */
 
 #include "sendmail.h"
@@ -456,9 +456,9 @@ setsender(from, e, delimptr, internal)
                realname = username();
        }
 
                realname = username();
        }
 
-/*
-       SuprErrs = TRUE;
-*/
+       if (ConfigLevel < 2)
+               SuprErrs = TRUE;
+
        delimchar = internal ? '\0' : ' ';
        if (from == NULL ||
            parseaddr(from, &e->e_from, 1, delimchar, delimptr, e) == NULL)
        delimchar = internal ? '\0' : ' ';
        if (from == NULL ||
            parseaddr(from, &e->e_from, 1, delimchar, delimptr, e) == NULL)
@@ -586,9 +586,9 @@ setsender(from, e, delimptr, internal)
 # endif
                finis();
        }
 # endif
                finis();
        }
-       rewrite(pvp, 3);
-       rewrite(pvp, 1);
-       rewrite(pvp, 4);
+       rewrite(pvp, 3, e);
+       rewrite(pvp, 1, e);
+       rewrite(pvp, 4, e);
        cataddr(pvp, NULL, buf, sizeof buf, '\0');
        e->e_sender = newstr(buf);
        define('f', e->e_sender, e);
        cataddr(pvp, NULL, buf, sizeof buf, '\0');
        e->e_sender = newstr(buf);
        define('f', e->e_sender, e);
index d8fd814..75eafe9 100644 (file)
@@ -13,7 +13,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     6.53 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     6.54 (Berkeley) %G%";
 #endif /* not lint */
 
 #define        _DEFINE
 #endif /* not lint */
 
 #define        _DEFINE
@@ -818,7 +818,7 @@ main(argc, argv, envp)
                                p = q;
                                while (*p != '\0')
                                {
                                p = q;
                                while (*p != '\0')
                                {
-                                       rewrite(pvp, atoi(p));
+                                       rewrite(pvp, atoi(p), CurEnv);
                                        while (*p != '\0' && *p++ != ',')
                                                continue;
                                }
                                        while (*p != '\0' && *p++ != ',')
                                                continue;
                                }
@@ -921,9 +921,13 @@ main(argc, argv, envp)
        **  Do basic system initialization and set the sender
        */
 
        **  Do basic system initialization and set the sender
        */
 
-# ifndef SYSTEM5
        /* make sendmail immune from process group signals */
        /* make sendmail immune from process group signals */
+# ifdef _POSIX_JOB_CONTROL
+       (void) setpgid(0, getpid());
+# else
+# ifndef SYSTEM5
        (void) setpgrp(0, getpid());
        (void) setpgrp(0, getpid());
+# endif
 # endif
 
        initsys(CurEnv);
 # endif
 
        initsys(CurEnv);
@@ -1079,10 +1083,13 @@ struct metamac  MetaMacros[] =
        /* the conditional operations */
        '?', CONDIF,            '|', CONDELSE,          '.', CONDFI,
 
        /* the conditional operations */
        '?', CONDIF,            '|', CONDELSE,          '.', CONDFI,
 
-       /* and finally the hostname lookup characters */
+       /* the hostname lookup characters */
        '[', HOSTBEGIN,         ']', HOSTEND,
        '(', LOOKUPBEGIN,       ')', LOOKUPEND,
 
        '[', HOSTBEGIN,         ']', HOSTEND,
        '(', LOOKUPBEGIN,       ')', LOOKUPEND,
 
+       /* miscellaneous control characters */
+       '&', MACRODEXPAND,
+
        '\0'
 };
 
        '\0'
 };
 
index bea09dd..53c2473 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)parseaddr.c        6.36 (Berkeley) %G%";
+static char sccsid[] = "@(#)parseaddr.c        6.37 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "sendmail.h"
 #endif /* not lint */
 
 #include "sendmail.h"
@@ -128,8 +128,8 @@ parseaddr(addr, a, copyf, delim, delimptr, e)
        **      Ruleset 0 does basic parsing.  It must resolve.
        */
 
        **      Ruleset 0 does basic parsing.  It must resolve.
        */
 
-       rewrite(pvp, 3);
-       rewrite(pvp, 0);
+       rewrite(pvp, 3, e);
+       rewrite(pvp, 0, e);
 
        /*
        **  See if we resolved to a real mailer.
 
        /*
        **  See if we resolved to a real mailer.
@@ -590,6 +590,8 @@ toktype(c)
        c &= 0377;
        if (c == MATCHCLASS || c == MATCHREPL || c == MATCHNCLASS)
                return (ONE);
        c &= 0377;
        if (c == MATCHCLASS || c == MATCHREPL || c == MATCHNCLASS)
                return (ONE);
+       if (c == MACRODEXPAND)
+               return (ONE);
 #ifdef MACVALUE
        if (c == MACVALUE)
                return (ONE);
 #ifdef MACVALUE
        if (c == MACVALUE)
                return (ONE);
@@ -630,6 +632,8 @@ toktype(c)
 **
 **     Parameters:
 **             pvp -- pointer to token vector.
 **
 **     Parameters:
 **             pvp -- pointer to token vector.
+**             ruleset -- the ruleset to use for rewriting.
+**             e -- the current envelope.
 **
 **     Returns:
 **             none.
 **
 **     Returns:
 **             none.
@@ -671,9 +675,10 @@ static char control_init_data[] = {
 static int nrw;
 
 void
 static int nrw;
 
 void
-rewrite(pvp, ruleset)
+rewrite(pvp, ruleset, e)
        char **pvp;
        int ruleset;
        char **pvp;
        int ruleset;
+       register ENVELOPE *e;
 {
        nrw = 0;
        _rewrite(pvp, ruleset);
 {
        nrw = 0;
        _rewrite(pvp, ruleset);
@@ -694,6 +699,7 @@ _rewrite(pvp, ruleset)
        int subr;                       /* subroutine number if >= 0 */
        bool dolookup;                  /* do host aliasing */
        char *npvp[MAXATOM+1];          /* temporary space for rebuild */
        int subr;                       /* subroutine number if >= 0 */
        bool dolookup;                  /* do host aliasing */
        char *npvp[MAXATOM+1];          /* temporary space for rebuild */
+       extern char *macvalue();
        char tokbuf[MAXNAME+1];         /* for concatenated class tokens */
        int nloops, nmatches = 0;       /* for looping rule checks */
        struct rewrite *prev_rwr;       /* pointer to previous rewrite rule */
        char tokbuf[MAXNAME+1];         /* for concatenated class tokens */
        int nloops, nmatches = 0;       /* for looping rule checks */
        struct rewrite *prev_rwr;       /* pointer to previous rewrite rule */
@@ -898,6 +904,39 @@ _rewrite(pvp, ruleset)
                                continue;
                        }
 
                                continue;
                        }
 
+                         case MACRODEXPAND:
+                               /*
+                               **  Match against run-time macro.
+                               **  This algorithm is broken for the
+                               **  general case (no recursive macros,
+                               **  improper tokenization) but should
+                               **  work for the usual cases.
+                               */
+
+                               ap = macvalue(rp[1], e);
+                               mlp->first = avp;
+                               if (tTd(21, 2))
+                                       printf("rewrite: LHS $&%c => \"%s\"\n",
+                                               rp[1],
+                                               ap == NULL ? "(NULL)" : ap);
+
+                               if (ap == NULL)
+                                       break;
+                               while (*ap != NULL)
+                               {
+                                       if (*avp == NULL ||
+                                           strncasecmp(ap, *avp, strlen(*avp)) != 0)
+                                       {
+                                               /* no match */
+                                               avp = mlp->first;
+                                               goto backup;
+                                       }
+                                       ap += strlen(*avp++);
+                               }
+
+                               /* match */
+                               break;
+
                        /*
                        **  We now have a variable length item.  It could
                        **  be $+ or $* in which case no special checking
                        /*
                        **  We now have a variable length item.  It could
                        **  be $+ or $* in which case no special checking
@@ -1601,7 +1640,7 @@ buildaddr(tv, a, e)
 
        if (m->m_r_rwset > 0)
                rewrite(tv, m->m_r_rwset);
 
        if (m->m_r_rwset > 0)
                rewrite(tv, m->m_r_rwset);
-       rewrite(tv, 4);
+       rewrite(tv, 4, e);
 
        /* save the result for the command line/RCPT argument */
        cataddr(tv, NULL, buf, sizeof buf, '\0');
 
        /* save the result for the command line/RCPT argument */
        cataddr(tv, NULL, buf, sizeof buf, '\0');
@@ -1860,7 +1899,7 @@ remotename(name, m, senderaddress, header, canonical, adddomain, e)
        pvp = prescan(name, '\0', pvpbuf, NULL);
        if (pvp == NULL)
                return (name);
        pvp = prescan(name, '\0', pvpbuf, NULL);
        if (pvp == NULL)
                return (name);
-       rewrite(pvp, 3);
+       rewrite(pvp, 3, e);
        if (adddomain && e->e_fromdomain != NULL)
        {
                /* append from domain to this address */
        if (adddomain && e->e_fromdomain != NULL)
        {
                /* append from domain to this address */
@@ -1876,7 +1915,7 @@ remotename(name, m, senderaddress, header, canonical, adddomain, e)
 
                        while ((*pxp++ = *qxq++) != NULL)
                                continue;
 
                        while ((*pxp++ = *qxq++) != NULL)
                                continue;
-                       rewrite(pvp, 3);
+                       rewrite(pvp, 3, e);
                }
        }
 
                }
        }
 
@@ -1891,7 +1930,7 @@ remotename(name, m, senderaddress, header, canonical, adddomain, e)
        if (senderaddress)
        else
        if (rwset > 0)
        if (senderaddress)
        else
        if (rwset > 0)
-               rewrite(pvp, rwset);
+               rewrite(pvp, rwset, e);
 
        /*
        **  Do any final sanitation the address may require.
 
        /*
        **  Do any final sanitation the address may require.
@@ -1900,7 +1939,7 @@ remotename(name, m, senderaddress, header, canonical, adddomain, e)
        **      may be used as a default to the above rules.
        */
 
        **      may be used as a default to the above rules.
        */
 
-       rewrite(pvp, 4);
+       rewrite(pvp, 4, e);
 
        /*
        **  Now restore the comment information we had at the beginning.
 
        /*
        **  Now restore the comment information we had at the beginning.
@@ -2016,7 +2055,7 @@ maplocaluser(a, sendq, e)
        if (pvp == NULL)
                return;
 
        if (pvp == NULL)
                return;
 
-       rewrite(pvp, 5);
+       rewrite(pvp, 5, e);
        if (pvp[0] == NULL || (pvp[0][0] & 0377) != CANONNET)
                return;
 
        if (pvp[0] == NULL || (pvp[0][0] & 0377) != CANONNET)
                return;