Add $[ and $] as RHS operators to look up the contents and pass them
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Sun, 12 Aug 1984 14:21:13 +0000 (06:21 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Sun, 12 Aug 1984 14:21:13 +0000 (06:21 -0800)
to maphostname; maphostname currently looks them up in /etc/hosts and
converts them to canonical form, but could be turned into a general
name server.....   huzzah!!

SCCS-vsn: usr.sbin/sendmail/src/headers.c 4.5
SCCS-vsn: usr.sbin/sendmail/src/main.c 4.14
SCCS-vsn: usr.sbin/sendmail/src/daemon.c 4.11
SCCS-vsn: usr.sbin/sendmail/src/version.c 4.39
SCCS-vsn: usr.sbin/sendmail/src/envelope.c 4.7
SCCS-vsn: usr.sbin/sendmail/src/parseaddr.c 4.9
SCCS-vsn: usr.sbin/sendmail/src/readcf.c 4.8

usr/src/usr.sbin/sendmail/src/daemon.c
usr/src/usr.sbin/sendmail/src/envelope.c
usr/src/usr.sbin/sendmail/src/headers.c
usr/src/usr.sbin/sendmail/src/main.c
usr/src/usr.sbin/sendmail/src/parseaddr.c
usr/src/usr.sbin/sendmail/src/readcf.c
usr/src/usr.sbin/sendmail/src/version.c

index f9ed00d..4f91914 100644 (file)
@@ -3,7 +3,7 @@
 # include <sys/mx.h>
 
 #ifndef DAEMON
 # include <sys/mx.h>
 
 #ifndef DAEMON
-SCCSID(@(#)daemon.c    4.10            %G%     (w/o daemon mode));
+SCCSID(@(#)daemon.c    4.11            %G%     (w/o daemon mode));
 #else
 
 #include <sys/socket.h>
 #else
 
 #include <sys/socket.h>
@@ -11,7 +11,7 @@ SCCSID(@(#)daemon.c   4.10            %G%     (w/o daemon mode));
 #include <netdb.h>
 #include <sys/wait.h>
 
 #include <netdb.h>
 #include <sys/wait.h>
 
-SCCSID(@(#)daemon.c    4.10            %G%     (with daemon mode));
+SCCSID(@(#)daemon.c    4.11            %G%     (with daemon mode));
 
 /*
 **  DAEMON.C -- routines to use when running as a daemon.
 
 /*
 **  DAEMON.C -- routines to use when running as a daemon.
@@ -321,8 +321,44 @@ myhostname(hostbuf, size)
        else
                return (NULL);
 }
        else
                return (NULL);
 }
+\f/*
+**  MAPHOSTNAME -- turn a hostname into canonical form
+**
+**     Parameters:
+**             hbuf -- a buffer containing a hostname.
+**             hbsize -- the size of hbuf.
+**
+**     Returns:
+**             none.
+**
+**     Side Effects:
+**             Looks up the host specified in hbuf.  If it is not
+**             the canonical name for that host, replace it with
+**             the canonical name.  If the name is unknown, or it
+**             is already the canonical name, leave it unchanged.
+*/
+
+maphostname(hbuf, hbsize)
+       char *hbuf;
+       int hbsize;
+{
+       register struct hostent *hp;
+       extern struct hostent *gethostbyname();
+
+       makelower(hbuf);
+       hp = gethostbyname(hbuf);
+       if (hp != NULL)
+       {
+               int i = strlen(hp->h_name);
 
 
+               if (i >= hbsize)
+                       hp->h_name[--i] = '\0';
+               strcpy(hbuf, hp->h_name);
+       }
+}
+\f
 # else DAEMON
 # else DAEMON
+/* code for systems without sophisticated networking */
 
 /*
 **  MYHOSTNAME -- stub version for case of no daemon code.
 
 /*
 **  MYHOSTNAME -- stub version for case of no daemon code.
@@ -349,5 +385,30 @@ myhostname(hostbuf, size)
        }
        return (NULL);
 }
        }
        return (NULL);
 }
+\f/*
+**  MAPHOSTNAME -- turn a hostname into canonical form
+**
+**     Parameters:
+**             hbuf -- a buffer containing a hostname.
+**             hbsize -- the size of hbuf.
+**
+**     Returns:
+**             none.
+**
+**     Side Effects:
+**             Looks up the host specified in hbuf.  If it is not
+**             the canonical name for that host, replace it with
+**             the canonical name.  If the name is unknown, or it
+**             is already the canonical name, leave it unchanged.
+*/
+
+/*ARGSUSED*/
+maphostname(hbuf, hbsize)
+       char *hbuf;
+       int hbsize;
+{
+       return;
+}
+
 
 #endif DAEMON
 
 #endif DAEMON
index b0205cf..d70413d 100644 (file)
@@ -3,7 +3,7 @@
 #include "sendmail.h"
 #include <sys/stat.h>
 
 #include "sendmail.h"
 #include <sys/stat.h>
 
-SCCSID(@(#)envelope.c  4.6             %G%);
+SCCSID(@(#)envelope.c  4.7             %G%);
 
 /*
 **  NEWENVELOPE -- allocate a new envelope
 
 /*
 **  NEWENVELOPE -- allocate a new envelope
@@ -539,6 +539,7 @@ setsender(from)
        register struct passwd *pw = NULL;
        char *realname = NULL;
        char buf[MAXNAME];
        register struct passwd *pw = NULL;
        char *realname = NULL;
        char buf[MAXNAME];
+       char pvpbuf[PSBUFSIZE];
        extern char *macvalue();
        extern char **prescan();
        extern bool safefile();
        extern char *macvalue();
        extern char **prescan();
        extern bool safefile();
@@ -670,7 +671,7 @@ setsender(from)
        **      links in the net.
        */
 
        **      links in the net.
        */
 
-       pvp = prescan(from, '\0');
+       pvp = prescan(from, '\0', pvpbuf);
        if (pvp == NULL)
        {
                syserr("cannot prescan from (%s)", from);
        if (pvp == NULL)
        {
                syserr("cannot prescan from (%s)", from);
index fc4cd4a..006e2bb 100644 (file)
@@ -1,7 +1,7 @@
 # include <errno.h>
 # include "sendmail.h"
 
 # include <errno.h>
 # include "sendmail.h"
 
-SCCSID(@(#)headers.c   4.4.1.1         %G%);
+SCCSID(@(#)headers.c   4.5             %G%);
 
 /*
 **  CHOMPHEADER -- process and save a header line.
 
 /*
 **  CHOMPHEADER -- process and save a header line.
@@ -733,10 +733,11 @@ commaize(h, p, fp, oldstyle, m)
                for (;;)
                {
                        char *oldp;
                for (;;)
                {
                        char *oldp;
+                       char pvpbuf[PSBUFSIZE];
                        extern bool isatword();
                        extern char **prescan();
 
                        extern bool isatword();
                        extern char **prescan();
 
-                       (void) prescan(p, oldstyle ? ' ' : ',');
+                       (void) prescan(p, oldstyle ? ' ' : ',', pvpbuf);
                        p = DelimChar;
 
                        /* look to see if we have an at sign */
                        p = DelimChar;
 
                        /* look to see if we have an at sign */
index 5358e22..9cb30d6 100644 (file)
@@ -3,7 +3,7 @@
 # include <sgtty.h>
 # include "sendmail.h"
 
 # include <sgtty.h>
 # include "sendmail.h"
 
-SCCSID(@(#)main.c      4.13            %G%);
+SCCSID(@(#)main.c      4.14            %G%);
 
 /*
 **  SENDMAIL -- Post mail to a set of destinations.
 
 /*
 **  SENDMAIL -- Post mail to a set of destinations.
@@ -475,7 +475,6 @@ main(argc, argv, envp)
                {
                        register char **pvp;
                        char *q;
                {
                        register char **pvp;
                        char *q;
-                       extern char **prescan();
                        extern char *DelimChar;
 
                        printf("> ");
                        extern char *DelimChar;
 
                        printf("> ");
@@ -492,7 +491,10 @@ main(argc, argv, envp)
                        *p = '\0';
                        do
                        {
                        *p = '\0';
                        do
                        {
-                               pvp = prescan(++p, ',');
+                               extern char **prescan();
+                               char pvpbuf[PSBUFSIZE];
+
+                               pvp = prescan(++p, ',', pvpbuf);
                                if (pvp == NULL)
                                        continue;
                                rewrite(pvp, 3);
                                if (pvp == NULL)
                                        continue;
                                rewrite(pvp, 3);
@@ -729,7 +731,7 @@ struct metamac      MetaMacros[] =
        '?', CONDIF,    '|', CONDELSE,  '.', CONDFI,
 
        /* and finally the hostname lookup characters */
        '?', CONDIF,    '|', CONDELSE,  '.', CONDFI,
 
        /* and finally the hostname lookup characters */
-       '{', HOSTBEGIN, '}', HOSTEND,
+       '[', HOSTBEGIN, ']', HOSTEND,
 
        '\0'
 };
 
        '\0'
 };
index cb8a1a9..74f1ba6 100644 (file)
@@ -1,6 +1,6 @@
 # include "sendmail.h"
 
 # include "sendmail.h"
 
-SCCSID(@(#)parseaddr.c 4.8             %G%);
+SCCSID(@(#)parseaddr.c 4.9             %G%);
 
 /*
 **  PARSEADDR -- Parse an address
 
 /*
 **  PARSEADDR -- Parse an address
@@ -52,6 +52,7 @@ parseaddr(addr, a, copyf, delim)
 {
        register char **pvp;
        register struct mailer *m;
 {
        register char **pvp;
        register struct mailer *m;
+       char pvpbuf[PSBUFSIZE];
        extern char **prescan();
        extern ADDRESS *buildaddr();
 
        extern char **prescan();
        extern ADDRESS *buildaddr();
 
@@ -65,7 +66,7 @@ parseaddr(addr, a, copyf, delim)
                printf("\n--parseaddr(%s)\n", addr);
 # endif DEBUG
 
                printf("\n--parseaddr(%s)\n", addr);
 # endif DEBUG
 
-       pvp = prescan(addr, delim);
+       pvp = prescan(addr, delim, pvpbuf);
        if (pvp == NULL)
                return (NULL);
 
        if (pvp == NULL)
                return (NULL);
 
@@ -187,6 +188,8 @@ loweraddr(a)
 **             delim -- the delimiter for the address, normally
 **                     '\0' or ','; \0 is accepted in any case.
 **                     If '\t' then we are reading the .cf file.
 **             delim -- the delimiter for the address, normally
 **                     '\0' or ','; \0 is accepted in any case.
 **                     If '\t' then we are reading the .cf file.
+**             pvpbuf -- place to put the saved text -- note that
+**                     the pointers are static.
 **
 **     Returns:
 **             A pointer to a vector of tokens.
 **
 **     Returns:
 **             A pointer to a vector of tokens.
@@ -226,9 +229,10 @@ static short StateTab[NSTATES][NSTATES] =
 char   *DelimChar;             /* set to point to the delimiter */
 
 char **
 char   *DelimChar;             /* set to point to the delimiter */
 
 char **
-prescan(addr, delim)
+prescan(addr, delim, pvpbuf)
        char *addr;
        char delim;
        char *addr;
        char delim;
+       char pvpbuf[];
 {
        register char *p;
        register char *q;
 {
        register char *p;
        register char *q;
@@ -240,14 +244,13 @@ prescan(addr, delim)
        char *tok;
        int state;
        int newstate;
        char *tok;
        int state;
        int newstate;
-       static char buf[MAXNAME+MAXATOM];
        static char *av[MAXATOM+1];
        extern int errno;
 
        /* make sure error messages don't have garbage on them */
        errno = 0;
 
        static char *av[MAXATOM+1];
        extern int errno;
 
        /* make sure error messages don't have garbage on them */
        errno = 0;
 
-       q = buf;
+       q = pvpbuf;
        bslashmode = FALSE;
        cmntcnt = 0;
        anglecnt = 0;
        bslashmode = FALSE;
        cmntcnt = 0;
        anglecnt = 0;
@@ -274,7 +277,7 @@ prescan(addr, delim)
                        if (c != NOCHAR)
                        {
                                /* see if there is room */
                        if (c != NOCHAR)
                        {
                                /* see if there is room */
-                               if (q >= &buf[sizeof buf - 5])
+                               if (q >= &pvpbuf[PSBUFSIZE - 5])
                                {
                                        usrerr("Address too long");
                                        DelimChar = p;
                                {
                                        usrerr("Address too long");
                                        DelimChar = p;
@@ -678,49 +681,115 @@ rewrite(pvp, ruleset)
                                dolookup = TRUE;
 
                        /* see if there is substitution here */
                                dolookup = TRUE;
 
                        /* see if there is substitution here */
-                       if (*rp != MATCHREPL)
+                       if (*rp == MATCHREPL)
                        {
                        {
-                               if (avp >= &npvp[MAXATOM])
+                               /* substitute from LHS */
+                               m = &mlist[rp[1] - '1'];
+                               if (m >= mlp)
                                {
                                  toolong:
                                {
                                  toolong:
-                                       syserr("rewrite: expansion too long");
+                                       syserr("rewrite: ruleset %d: replacement out of bounds", ruleset);
                                        return;
                                }
                                        return;
                                }
-                               *avp++ = rp;
-                               continue;
-                       }
-
-                       /* substitute from LHS */
-                       m = &mlist[rp[1] - '1'];
-                       if (m >= mlp)
-                       {
-                               syserr("rewrite: ruleset %d: replacement out of bounds", ruleset);
-                               return;
-                       }
 # ifdef DEBUG
 # ifdef DEBUG
-                       if (tTd(21, 15))
-                       {
-                               printf("$%c:", rp[1]);
+                               if (tTd(21, 15))
+                               {
+                                       printf("$%c:", rp[1]);
+                                       pp = m->first;
+                                       while (pp <= m->last)
+                                       {
+                                               printf(" %x=\"", *pp);
+                                               (void) fflush(stdout);
+                                               printf("%s\"", *pp++);
+                                       }
+                                       printf("\n");
+                               }
+# endif DEBUG
                                pp = m->first;
                                while (pp <= m->last)
                                {
                                pp = m->first;
                                while (pp <= m->last)
                                {
-                                       printf(" %x=\"", *pp);
-                                       (void) fflush(stdout);
-                                       printf("%s\"", *pp++);
+                                       if (avp >= &npvp[MAXATOM])
+                                       {
+                                               syserr("rewrite: expansion too long");
+                                               return;
+                                       }
+                                       *avp++ = *pp++;
                                }
                                }
-                               printf("\n");
                        }
                        }
-# endif DEBUG
-                       pp = m->first;
-                       while (pp <= m->last)
+                       else
                        {
                        {
+                               /* vanilla replacement */
                                if (avp >= &npvp[MAXATOM])
                                        goto toolong;
                                if (avp >= &npvp[MAXATOM])
                                        goto toolong;
-                               *avp++ = *pp++;
+                               *avp++ = rp;
                        }
                }
                *avp++ = NULL;
 
                        }
                }
                *avp++ = NULL;
 
+               /*
+               **  Check for any hostname lookups.
+               */
+
+               for (rvp = npvp; *rvp != NULL; rvp++)
+               {
+                       char **hbrvp;
+                       char **xpvp;
+                       int trsize;
+                       int i;
+                       char buf[MAXATOM + 1];
+                       char *pvpb1[MAXATOM + 1];
+                       static char pvpbuf[PSBUFSIZE];
+
+                       if (**rvp != HOSTBEGIN)
+                               continue;
+
+                       /*
+                       **  Got a hostname lookup.
+                       **
+                       **      This could be optimized fairly easily.
+                       */
+
+                       hbrvp = rvp;
+
+                       /* extract the match part */
+                       while (*++rvp != NULL && **rvp != HOSTEND)
+                               continue;
+                       if (*rvp != NULL)
+                               *rvp++ = NULL;
+
+                       /* save the remainder of the input string */
+                       trsize = (int) (avp - rvp + 1) * sizeof *rvp;
+                       bcopy((char *) rvp, (char *) pvpb1, trsize);
+
+                       /* look it up */
+                       cataddr(++hbrvp, buf, sizeof buf);
+                       maphostname(buf, sizeof buf);
+
+                       /* scan the new host name */
+                       xpvp = prescan(buf, '\0', pvpbuf);
+                       if (xpvp == NULL)
+                       {
+                               syserr("rewrite: cannot prescan canonical hostname: %s", buf);
+                               return (NULL);
+                       }
+
+                       /* append it to the token list */
+                       rvp = --hbrvp;
+                       while ((*rvp++ = *xpvp++) != NULL)
+                               if (rvp >= &npvp[MAXATOM])
+                                       goto toolong;
+
+                       /* restore the old trailing information */
+                       for (xpvp = pvpb1, rvp--; (*rvp++ = *xpvp++) != NULL; )
+                               if (rvp >= &npvp[MAXATOM])
+                                       goto toolong;
+               }
+
+               /*
+               **  Check for subroutine calls.
+               */
+
+
                /*
                **  Do hostname lookup if requested.
                */
                /*
                **  Do hostname lookup if requested.
                */
@@ -1061,6 +1130,7 @@ remotename(name, m, senderaddress, canonical)
        char *oldg = macvalue('g', CurEnv);
        static char buf[MAXNAME];
        char lbuf[MAXNAME];
        char *oldg = macvalue('g', CurEnv);
        static char buf[MAXNAME];
        char lbuf[MAXNAME];
+       char pvpbuf[PSBUFSIZE];
        extern char **prescan();
        extern char *crackaddr();
 
        extern char **prescan();
        extern char *crackaddr();
 
@@ -1091,7 +1161,7 @@ remotename(name, m, senderaddress, canonical)
        **      domain will be appended.
        */
 
        **      domain will be appended.
        */
 
-       pvp = prescan(name, '\0');
+       pvp = prescan(name, '\0', pvpbuf);
        if (pvp == NULL)
                return (name);
        rewrite(pvp, 3);
        if (pvp == NULL)
                return (name);
        rewrite(pvp, 3);
index f645ea4..bc612c3 100644 (file)
@@ -1,6 +1,6 @@
 # include "sendmail.h"
 
 # include "sendmail.h"
 
-SCCSID(@(#)readcf.c    4.7             %G%);
+SCCSID(@(#)readcf.c    4.8             %G%);
 
 /*
 **  READCF -- read control file.
 
 /*
 **  READCF -- read control file.
@@ -59,6 +59,7 @@ readcf(cfname, safe)
        extern char **prescan();
        extern char **copyplist();
        char exbuf[MAXLINE];
        extern char **prescan();
        extern char **copyplist();
        char exbuf[MAXLINE];
+       char pvpbuf[PSBUFSIZE];
        extern char *fgetfolded();
        extern char *munchstring();
 
        extern char *fgetfolded();
        extern char *munchstring();
 
@@ -123,7 +124,7 @@ readcf(cfname, safe)
                        /* expand and save the LHS */
                        *p = '\0';
                        expand(&buf[1], exbuf, &exbuf[sizeof exbuf], CurEnv);
                        /* expand and save the LHS */
                        *p = '\0';
                        expand(&buf[1], exbuf, &exbuf[sizeof exbuf], CurEnv);
-                       rwp->r_lhs = prescan(exbuf, '\t');
+                       rwp->r_lhs = prescan(exbuf, '\t', pvpbuf);
                        if (rwp->r_lhs != NULL)
                                rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
 
                        if (rwp->r_lhs != NULL)
                                rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
 
@@ -135,7 +136,7 @@ readcf(cfname, safe)
                                p++;
                        *p = '\0';
                        expand(q, exbuf, &exbuf[sizeof exbuf], CurEnv);
                                p++;
                        *p = '\0';
                        expand(q, exbuf, &exbuf[sizeof exbuf], CurEnv);
-                       rwp->r_rhs = prescan(exbuf, '\t');
+                       rwp->r_rhs = prescan(exbuf, '\t', pvpbuf);
                        if (rwp->r_rhs != NULL)
                                rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
                        break;
                        if (rwp->r_rhs != NULL)
                                rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
                        break;
index 2c6731a..f094e0e 100644 (file)
@@ -1,5 +1,5 @@
 # ifndef lint
 # ifndef lint
-static char    SccsId[] = "@(#)SendMail version 4.38 of %G%";
+static char    SccsId[] = "@(#)SendMail version 4.39 of %G%";
 # endif lint
 
 # endif lint
 
-char   Version[] = "4.38";
+char   Version[] = "4.39";