From: Eric Allman Date: Sun, 12 Aug 1984 14:21:13 +0000 (-0800) Subject: Add $[ and $] as RHS operators to look up the contents and pass them X-Git-Tag: BSD-4_3-Snapshot-Development~9673 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/217a0102c0455e4d5c27e837555aaf43a07adfe5?hp=96f6c5b6e0f06ee000fb0a3df7037de36085e77d Add $[ and $] as RHS operators to look up the contents and pass them 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 --- diff --git a/usr/src/usr.sbin/sendmail/src/daemon.c b/usr/src/usr.sbin/sendmail/src/daemon.c index f9ed00d946..4f91914b5c 100644 --- a/usr/src/usr.sbin/sendmail/src/daemon.c +++ b/usr/src/usr.sbin/sendmail/src/daemon.c @@ -3,7 +3,7 @@ # include #ifndef DAEMON -SCCSID(@(#)daemon.c 4.10 %G% (w/o daemon mode)); +SCCSID(@(#)daemon.c 4.11 %G% (w/o daemon mode)); #else #include @@ -11,7 +11,7 @@ SCCSID(@(#)daemon.c 4.10 %G% (w/o daemon mode)); #include #include -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. @@ -321,8 +321,44 @@ myhostname(hostbuf, size) else return (NULL); } + /* +** 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); + } +} + # else DAEMON +/* code for systems without sophisticated networking */ /* ** MYHOSTNAME -- stub version for case of no daemon code. @@ -349,5 +385,30 @@ myhostname(hostbuf, size) } return (NULL); } + /* +** 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 diff --git a/usr/src/usr.sbin/sendmail/src/envelope.c b/usr/src/usr.sbin/sendmail/src/envelope.c index b0205cf2e5..d70413d266 100644 --- a/usr/src/usr.sbin/sendmail/src/envelope.c +++ b/usr/src/usr.sbin/sendmail/src/envelope.c @@ -3,7 +3,7 @@ #include "sendmail.h" #include -SCCSID(@(#)envelope.c 4.6 %G%); +SCCSID(@(#)envelope.c 4.7 %G%); /* ** NEWENVELOPE -- allocate a new envelope @@ -539,6 +539,7 @@ setsender(from) register struct passwd *pw = NULL; char *realname = NULL; char buf[MAXNAME]; + char pvpbuf[PSBUFSIZE]; extern char *macvalue(); extern char **prescan(); extern bool safefile(); @@ -670,7 +671,7 @@ setsender(from) ** links in the net. */ - pvp = prescan(from, '\0'); + pvp = prescan(from, '\0', pvpbuf); if (pvp == NULL) { syserr("cannot prescan from (%s)", from); diff --git a/usr/src/usr.sbin/sendmail/src/headers.c b/usr/src/usr.sbin/sendmail/src/headers.c index fc4cd4aaad..006e2bb7f1 100644 --- a/usr/src/usr.sbin/sendmail/src/headers.c +++ b/usr/src/usr.sbin/sendmail/src/headers.c @@ -1,7 +1,7 @@ # include # include "sendmail.h" -SCCSID(@(#)headers.c 4.4.1.1 %G%); +SCCSID(@(#)headers.c 4.5 %G%); /* ** CHOMPHEADER -- process and save a header line. @@ -733,10 +733,11 @@ commaize(h, p, fp, oldstyle, m) for (;;) { char *oldp; + char pvpbuf[PSBUFSIZE]; 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 */ diff --git a/usr/src/usr.sbin/sendmail/src/main.c b/usr/src/usr.sbin/sendmail/src/main.c index 5358e221cc..9cb30d6e09 100644 --- a/usr/src/usr.sbin/sendmail/src/main.c +++ b/usr/src/usr.sbin/sendmail/src/main.c @@ -3,7 +3,7 @@ # include # include "sendmail.h" -SCCSID(@(#)main.c 4.13 %G%); +SCCSID(@(#)main.c 4.14 %G%); /* ** SENDMAIL -- Post mail to a set of destinations. @@ -475,7 +475,6 @@ main(argc, argv, envp) { register char **pvp; char *q; - extern char **prescan(); extern char *DelimChar; printf("> "); @@ -492,7 +491,10 @@ main(argc, argv, envp) *p = '\0'; do { - pvp = prescan(++p, ','); + extern char **prescan(); + char pvpbuf[PSBUFSIZE]; + + pvp = prescan(++p, ',', pvpbuf); if (pvp == NULL) continue; rewrite(pvp, 3); @@ -729,7 +731,7 @@ struct metamac MetaMacros[] = '?', CONDIF, '|', CONDELSE, '.', CONDFI, /* and finally the hostname lookup characters */ - '{', HOSTBEGIN, '}', HOSTEND, + '[', HOSTBEGIN, ']', HOSTEND, '\0' }; diff --git a/usr/src/usr.sbin/sendmail/src/parseaddr.c b/usr/src/usr.sbin/sendmail/src/parseaddr.c index cb8a1a99d5..74f1ba69c7 100644 --- a/usr/src/usr.sbin/sendmail/src/parseaddr.c +++ b/usr/src/usr.sbin/sendmail/src/parseaddr.c @@ -1,6 +1,6 @@ # include "sendmail.h" -SCCSID(@(#)parseaddr.c 4.8 %G%); +SCCSID(@(#)parseaddr.c 4.9 %G%); /* ** PARSEADDR -- Parse an address @@ -52,6 +52,7 @@ parseaddr(addr, a, copyf, delim) { register char **pvp; register struct mailer *m; + char pvpbuf[PSBUFSIZE]; extern char **prescan(); extern ADDRESS *buildaddr(); @@ -65,7 +66,7 @@ parseaddr(addr, a, copyf, delim) printf("\n--parseaddr(%s)\n", addr); # endif DEBUG - pvp = prescan(addr, delim); + pvp = prescan(addr, delim, pvpbuf); 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. +** pvpbuf -- place to put the saved text -- note that +** the pointers are static. ** ** 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 ** -prescan(addr, delim) +prescan(addr, delim, pvpbuf) char *addr; char delim; + char pvpbuf[]; { register char *p; register char *q; @@ -240,14 +244,13 @@ prescan(addr, delim) 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; - q = buf; + q = pvpbuf; bslashmode = FALSE; cmntcnt = 0; anglecnt = 0; @@ -274,7 +277,7 @@ prescan(addr, delim) 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; @@ -678,49 +681,115 @@ rewrite(pvp, ruleset) 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: - syserr("rewrite: expansion too long"); + syserr("rewrite: ruleset %d: replacement out of bounds", ruleset); 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 - 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) { - 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; - *avp++ = *pp++; + *avp++ = rp; } } *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. */ @@ -1061,6 +1130,7 @@ remotename(name, m, senderaddress, canonical) char *oldg = macvalue('g', CurEnv); static char buf[MAXNAME]; char lbuf[MAXNAME]; + char pvpbuf[PSBUFSIZE]; extern char **prescan(); extern char *crackaddr(); @@ -1091,7 +1161,7 @@ remotename(name, m, senderaddress, canonical) ** domain will be appended. */ - pvp = prescan(name, '\0'); + pvp = prescan(name, '\0', pvpbuf); if (pvp == NULL) return (name); rewrite(pvp, 3); diff --git a/usr/src/usr.sbin/sendmail/src/readcf.c b/usr/src/usr.sbin/sendmail/src/readcf.c index f645ea41db..bc612c3a26 100644 --- a/usr/src/usr.sbin/sendmail/src/readcf.c +++ b/usr/src/usr.sbin/sendmail/src/readcf.c @@ -1,6 +1,6 @@ # include "sendmail.h" -SCCSID(@(#)readcf.c 4.7 %G%); +SCCSID(@(#)readcf.c 4.8 %G%); /* ** READCF -- read control file. @@ -59,6 +59,7 @@ readcf(cfname, safe) extern char **prescan(); extern char **copyplist(); char exbuf[MAXLINE]; + char pvpbuf[PSBUFSIZE]; 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); - 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); @@ -135,7 +136,7 @@ readcf(cfname, safe) 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; diff --git a/usr/src/usr.sbin/sendmail/src/version.c b/usr/src/usr.sbin/sendmail/src/version.c index 2c6731a99a..f094e0ee07 100644 --- a/usr/src/usr.sbin/sendmail/src/version.c +++ b/usr/src/usr.sbin/sendmail/src/version.c @@ -1,5 +1,5 @@ # ifndef lint -static char SccsId[] = "@(#)SendMail version 4.38 of %G%"; +static char SccsId[] = "@(#)SendMail version 4.39 of %G%"; # endif lint -char Version[] = "4.38"; +char Version[] = "4.39";