BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.sbin / sendmail / src / parseaddr.c
index d2381c6..2ee24e0 100644 (file)
@@ -1,6 +1,42 @@
-# include "sendmail.h"
+/*
+ * Copyright (c) 1983 Eric P. Allman
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)parseaddr.c        5.13 (Berkeley) 6/1/90";
+#endif /* not lint */
 
 
-SCCSID(@(#)parseaddr.c 4.6             %G%);
+# include "sendmail.h"
 
 /*
 **  PARSEADDR -- Parse an address
 
 /*
 **  PARSEADDR -- Parse an address
@@ -52,6 +88,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();
 
@@ -60,12 +97,10 @@ parseaddr(addr, a, copyf, delim)
        */
 
        CurEnv->e_to = addr;
        */
 
        CurEnv->e_to = addr;
-# ifdef DEBUG
        if (tTd(20, 1))
                printf("\n--parseaddr(%s)\n", addr);
        if (tTd(20, 1))
                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);
 
@@ -113,12 +148,15 @@ parseaddr(addr, a, copyf, delim)
        }
        else
                a->q_paddr = addr;
        }
        else
                a->q_paddr = addr;
+
+       if (a->q_user == NULL)
+               a->q_user = "";
+       if (a->q_host == NULL)
+               a->q_host = "";
+
        if (copyf >= 0)
        {
        if (copyf >= 0)
        {
-               if (a->q_host != NULL)
-                       a->q_host = newstr(a->q_host);
-               else
-                       a->q_host = "";
+               a->q_host = newstr(a->q_host);
                if (a->q_user != a->q_paddr)
                        a->q_user = newstr(a->q_user);
        }
                if (a->q_user != a->q_paddr)
                        a->q_user = newstr(a->q_user);
        }
@@ -135,13 +173,11 @@ parseaddr(addr, a, copyf, delim)
        **  Compute return value.
        */
 
        **  Compute return value.
        */
 
-# ifdef DEBUG
        if (tTd(20, 1))
        {
                printf("parseaddr-->");
                printaddr(a, FALSE);
        }
        if (tTd(20, 1))
        {
                printf("parseaddr-->");
                printaddr(a, FALSE);
        }
-# endif DEBUG
 
        return (a);
 }
 
        return (a);
 }
@@ -187,13 +223,15 @@ 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.
 **             NULL on error.
 **
 **     Side Effects:
 **
 **     Returns:
 **             A pointer to a vector of tokens.
 **             NULL on error.
 **
 **     Side Effects:
-**             none.
+**             sets DelimChar to point to the character matching 'delim'.
 */
 
 /* states and character types */
 */
 
 /* states and character types */
@@ -226,9 +264,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 +279,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;
@@ -255,14 +293,12 @@ prescan(addr, delim)
        state = OPR;
        c = NOCHAR;
        p = addr;
        state = OPR;
        c = NOCHAR;
        p = addr;
-# ifdef DEBUG
        if (tTd(22, 45))
        {
                printf("prescan: ");
                xputs(p);
        if (tTd(22, 45))
        {
                printf("prescan: ");
                xputs(p);
-               putchar('\n');
+               (void) putchar('\n');
        }
        }
-# endif DEBUG
 
        do
        {
 
        do
        {
@@ -274,7 +310,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;
@@ -291,16 +327,16 @@ prescan(addr, delim)
                                break;
                        c &= ~0200;
 
                                break;
                        c &= ~0200;
 
-# ifdef DEBUG
                        if (tTd(22, 101))
                                printf("c=%c, s=%d; ", c, state);
                        if (tTd(22, 101))
                                printf("c=%c, s=%d; ", c, state);
-# endif DEBUG
 
                        /* chew up special characters */
                        *q = '\0';
                        if (bslashmode)
                        {
 
                        /* chew up special characters */
                        *q = '\0';
                        if (bslashmode)
                        {
-                               c |= 0200;
+                               /* kludge \! for naive users */
+                               if (c != '!')
+                                       c |= 0200;
                                bslashmode = FALSE;
                        }
                        else if (c == '\\')
                                bslashmode = FALSE;
                        }
                        else if (c == '\\')
@@ -344,17 +380,6 @@ prescan(addr, delim)
                        }
                        else if (delim == ' ' && isspace(c))
                                c = ' ';
                        }
                        else if (delim == ' ' && isspace(c))
                                c = ' ';
-                       else if (c == ':' && !CurEnv->e_oldstyle)
-                       {
-                               /* consume characters until a semicolon */
-                               while (*p != '\0' && *p != ';')
-                                       p++;
-                               if (*p == '\0')
-                                       usrerr("Unbalanced ':...;' group spec");
-                               else
-                                       p++;
-                               c = ' ';
-                       }
 
                        if (c == NOCHAR)
                                continue;
 
                        if (c == NOCHAR)
                                continue;
@@ -364,10 +389,8 @@ prescan(addr, delim)
                                break;
 
                        newstate = StateTab[state][toktype(c)];
                                break;
 
                        newstate = StateTab[state][toktype(c)];
-# ifdef DEBUG
                        if (tTd(22, 101))
                                printf("ns=%02o\n", newstate);
                        if (tTd(22, 101))
                                printf("ns=%02o\n", newstate);
-# endif DEBUG
                        state = newstate & TYPE;
                        if (bitset(M, newstate))
                                c = NOCHAR;
                        state = newstate & TYPE;
                        if (bitset(M, newstate))
                                c = NOCHAR;
@@ -379,14 +402,12 @@ prescan(addr, delim)
                if (tok != q)
                {
                        *q++ = '\0';
                if (tok != q)
                {
                        *q++ = '\0';
-# ifdef DEBUG
                        if (tTd(22, 36))
                        {
                                printf("tok=");
                                xputs(tok);
                        if (tTd(22, 36))
                        {
                                printf("tok=");
                                xputs(tok);
-                               putchar('\n');
+                               (void) putchar('\n');
                        }
                        }
-# endif DEBUG
                        if (avp >= &av[MAXATOM])
                        {
                                syserr("prescan: too many tokens");
                        if (avp >= &av[MAXATOM])
                        {
                                syserr("prescan: too many tokens");
@@ -498,7 +519,6 @@ rewrite(pvp, ruleset)
        register struct rewrite *rwr;   /* pointer to current rewrite rule */
        struct match mlist[MAXMATCH];   /* stores match on LHS */
        char *npvp[MAXATOM+1];          /* temporary space for rebuild */
        register struct rewrite *rwr;   /* pointer to current rewrite rule */
        struct match mlist[MAXMATCH];   /* stores match on LHS */
        char *npvp[MAXATOM+1];          /* temporary space for rebuild */
-       extern bool sameword();
 
        if (OpMode == MD_TEST || tTd(21, 2))
        {
 
        if (OpMode == MD_TEST || tTd(21, 2))
        {
@@ -515,13 +535,11 @@ rewrite(pvp, ruleset)
 
        for (rwr = RewriteRules[ruleset]; rwr != NULL; )
        {
 
        for (rwr = RewriteRules[ruleset]; rwr != NULL; )
        {
-# ifdef DEBUG
                if (tTd(21, 12))
                {
                        printf("-----trying rule:");
                        printav(rwr->r_lhs);
                }
                if (tTd(21, 12))
                {
                        printf("-----trying rule:");
                        printav(rwr->r_lhs);
                }
-# endif DEBUG
 
                /* try to match on this rule */
                mlp = mlist;
 
                /* try to match on this rule */
                mlp = mlist;
@@ -530,7 +548,6 @@ rewrite(pvp, ruleset)
                while ((ap = *avp) != NULL || *rvp != NULL)
                {
                        rp = *rvp;
                while ((ap = *avp) != NULL || *rvp != NULL)
                {
                        rp = *rvp;
-# ifdef DEBUG
                        if (tTd(21, 35))
                        {
                                printf("ap=");
                        if (tTd(21, 35))
                        {
                                printf("ap=");
@@ -539,7 +556,6 @@ rewrite(pvp, ruleset)
                                xputs(rp);
                                printf("\n");
                        }
                                xputs(rp);
                                printf("\n");
                        }
-# endif DEBUG
                        if (rp == NULL)
                        {
                                /* end-of-pattern before end-of-address */
                        if (rp == NULL)
                        {
                                /* end-of-pattern before end-of-address */
@@ -586,7 +602,7 @@ rewrite(pvp, ruleset)
 
                          default:
                                /* must have exact match */
 
                          default:
                                /* must have exact match */
-                               if (!sameword(rp, ap))
+                               if (strcasecmp(rp, ap))
                                        goto backup;
                                avp++;
                                break;
                                        goto backup;
                                avp++;
                                break;
@@ -631,22 +647,18 @@ rewrite(pvp, ruleset)
 
                if (rvp < rwr->r_lhs || *rvp != NULL)
                {
 
                if (rvp < rwr->r_lhs || *rvp != NULL)
                {
-# ifdef DEBUG
                        if (tTd(21, 10))
                                printf("----- rule fails\n");
                        if (tTd(21, 10))
                                printf("----- rule fails\n");
-# endif DEBUG
                        rwr = rwr->r_next;
                        continue;
                }
 
                rvp = rwr->r_rhs;
                        rwr = rwr->r_next;
                        continue;
                }
 
                rvp = rwr->r_rhs;
-# ifdef DEBUG
                if (tTd(21, 12))
                {
                        printf("-----rule matches:");
                        printav(rvp);
                }
                if (tTd(21, 12))
                {
                        printf("-----rule matches:");
                        printav(rvp);
                }
-# endif DEBUG
 
                rp = *rvp;
                if (*rp == CANONUSER)
 
                rp = *rvp;
                if (*rp == CANONUSER)
@@ -669,67 +681,140 @@ rewrite(pvp, ruleset)
                        register char **pp;
 
                        rp = *rvp;
                        register char **pp;
 
                        rp = *rvp;
-                       if (*rp != MATCHREPL)
+                       if (*rp == MATCHREPL)
                        {
                        {
-                               if (avp >= &npvp[MAXATOM])
+                               /* substitute from LHS */
+                               m = &mlist[rp[1] - '1'];
+                               if (m >= mlp)
                                {
                                {
-                                       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'];
-# 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");
+                               }
                                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])
                                {
                                if (avp >= &npvp[MAXATOM])
                                {
+       toolong:
                                        syserr("rewrite: expansion too long");
                                        return;
                                }
                                        syserr("rewrite: expansion too long");
                                        return;
                                }
-                               *avp++ = *pp++;
+                               *avp++ = rp;
                        }
                }
                *avp++ = NULL;
                        }
                }
                *avp++ = NULL;
-               if (**npvp == CALLSUBR)
+
+               /*
+               **  Check for any hostname lookups.
+               */
+
+               for (rvp = npvp; *rvp != NULL; rvp++)
+               {
+                       char **hbrvp;
+                       char **xpvp;
+                       int trsize;
+                       char *olddelimchar;
+                       char buf[MAXNAME + 1];
+                       char *pvpb1[MAXATOM + 1];
+                       char pvpbuf[PSBUFSIZE];
+                       extern char *DelimChar;
+
+                       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 */
+                       olddelimchar = DelimChar;
+                       xpvp = prescan(buf, '\0', pvpbuf);
+                       DelimChar = olddelimchar;
+                       if (xpvp == NULL)
+                       {
+                               syserr("rewrite: cannot prescan canonical hostname: %s", buf);
+                               return;
+                       }
+
+                       /* append it to the token list */
+                       for (avp = --hbrvp; *xpvp != NULL; xpvp++)
+                       {
+                               *avp++ = newstr(*xpvp);
+                               if (avp >= &npvp[MAXATOM])
+                                       goto toolong;
+                       }
+
+                       /* restore the old trailing information */
+                       for (xpvp = pvpb1; (*avp++ = *xpvp++) != NULL; )
+                               if (avp >= &npvp[MAXATOM])
+                                       goto toolong;
+
+                       break;
+               }
+
+               /*
+               **  Check for subroutine calls.
+               */
+
+               if (*npvp != NULL && **npvp == CALLSUBR)
                {
                {
-                       bmove((char *) &npvp[2], (char *) pvp,
-                               (avp - npvp - 2) * sizeof *avp);
-# ifdef DEBUG
+                       bcopy((char *) &npvp[2], (char *) pvp,
+                               (int) (avp - npvp - 2) * sizeof *avp);
                        if (tTd(21, 3))
                                printf("-----callsubr %s\n", npvp[1]);
                        if (tTd(21, 3))
                                printf("-----callsubr %s\n", npvp[1]);
-# endif DEBUG
                        rewrite(pvp, atoi(npvp[1]));
                }
                else
                {
                        rewrite(pvp, atoi(npvp[1]));
                }
                else
                {
-                       bmove((char *) npvp, (char *) pvp,
-                               (avp - npvp) * sizeof *avp);
+                       bcopy((char *) npvp, (char *) pvp,
+                               (int) (avp - npvp) * sizeof *avp);
                }
                }
-# ifdef DEBUG
                if (tTd(21, 4))
                {
                        printf("rewritten as:");
                        printav(pvp);
                }
                if (tTd(21, 4))
                {
                        printf("rewritten as:");
                        printav(pvp);
                }
-# endif DEBUG
        }
 
        if (OpMode == MD_TEST || tTd(21, 2))
        }
 
        if (OpMode == MD_TEST || tTd(21, 2))
@@ -762,11 +847,10 @@ buildaddr(tv, a)
        static char buf[MAXNAME];
        struct mailer **mp;
        register struct mailer *m;
        static char buf[MAXNAME];
        struct mailer **mp;
        register struct mailer *m;
-       extern bool sameword();
 
        if (a == NULL)
                a = (ADDRESS *) xalloc(sizeof *a);
 
        if (a == NULL)
                a = (ADDRESS *) xalloc(sizeof *a);
-       clear((char *) a, sizeof *a);
+       bzero((char *) a, sizeof *a);
 
        /* figure out what net/mailer to use */
        if (**tv != CANONNET)
 
        /* figure out what net/mailer to use */
        if (**tv != CANONNET)
@@ -775,7 +859,7 @@ buildaddr(tv, a)
                return (NULL);
        }
        tv++;
                return (NULL);
        }
        tv++;
-       if (sameword(*tv, "error"))
+       if (!strcasecmp(*tv, "error"))
        {
                if (**++tv == CANONHOST)
                {
        {
                if (**++tv == CANONHOST)
                {
@@ -796,12 +880,12 @@ buildaddr(tv, a)
        }
        for (mp = Mailer; (m = *mp++) != NULL; )
        {
        }
        for (mp = Mailer; (m = *mp++) != NULL; )
        {
-               if (sameword(m->m_name, *tv))
+               if (!strcasecmp(m->m_name, *tv))
                        break;
        }
        if (m == NULL)
        {
                        break;
        }
        if (m == NULL)
        {
-               syserr("buildaddr: unknown net %s", *tv);
+               syserr("buildaddr: unknown mailer %s", *tv);
                return (NULL);
        }
        a->q_mailer = m;
                return (NULL);
        }
        a->q_mailer = m;
@@ -824,12 +908,19 @@ buildaddr(tv, a)
                a->q_host = NULL;
 
        /* figure out the user */
                a->q_host = NULL;
 
        /* figure out the user */
-       if (**tv != CANONUSER)
+       if (*tv == NULL || **tv != CANONUSER)
        {
                syserr("buildaddr: no user");
                return (NULL);
        }
        {
                syserr("buildaddr: no user");
                return (NULL);
        }
-       rewrite(++tv, 4);
+
+       /* rewrite according recipient mailer rewriting rules */
+       rewrite(++tv, 2);
+       if (m->m_r_rwset > 0)
+               rewrite(tv, m->m_r_rwset);
+       rewrite(tv, 4);
+
+       /* save the result for the command line/RCPT argument */
        cataddr(tv, buf, sizeof buf);
        a->q_user = buf;
 
        cataddr(tv, buf, sizeof buf);
        a->q_user = buf;
 
@@ -862,7 +953,7 @@ cataddr(pvp, buf, sz)
 
        if (pvp == NULL)
        {
 
        if (pvp == NULL)
        {
-               strcpy(buf, "");
+               (void) strcpy(buf, "");
                return;
        }
        p = buf;
                return;
        }
        p = buf;
@@ -936,45 +1027,33 @@ sameaddr(a, b)
 **             none.
 */
 
 **             none.
 */
 
-# ifdef DEBUG
-
 printaddr(a, follow)
        register ADDRESS *a;
        bool follow;
 {
        bool first = TRUE;
 
 printaddr(a, follow)
        register ADDRESS *a;
        bool follow;
 {
        bool first = TRUE;
 
-       static int indent;
-       register int i;
-
        while (a != NULL)
        {
                first = FALSE;
        while (a != NULL)
        {
                first = FALSE;
-               for (i = indent; i > 0; i--)
-                       printf("\t");
                printf("%x=", a);
                (void) fflush(stdout);
                printf("%x=", a);
                (void) fflush(stdout);
-               printf("%s: mailer %d (%s), host `%s', user `%s'\n", a->q_paddr,
-               for (i = indent; i > 0; i--)
-                       printf("\t");
-               printf("\tnext=%x, flags=%o, rmailer %d, alias=%x, sibling=%x, child=%x\n",
-                      a->q_next, a->q_flags, a->q_rmailer, a->q_alias,
-                      a->q_sibling, a->q_child);
-               
-               /* follow the chain if appropriate */
+               printf("%s: mailer %d (%s), host `%s', user `%s', ruser `%s'\n",
+                      a->q_paddr, a->q_mailer->m_mno, a->q_mailer->m_name,
+                      a->q_host, a->q_user, a->q_ruser? a->q_ruser: "<null>");
+               printf("\tnext=%x, flags=%o, alias %x\n", a->q_next, a->q_flags,
+                      a->q_alias);
+               printf("\thome=\"%s\", fullname=\"%s\"\n", a->q_home,
+                      a->q_fullname);
+
                if (!follow)
                        return;
                if (!follow)
                        return;
-               
-               indent++;
-               printaddr(a->q_child, TRUE);
-               indent--;
-               a = a->q_sibling;
+               a = a->q_next;
        }
        if (first)
                printf("[NULL]\n");
 }
 
        }
        if (first)
                printf("[NULL]\n");
 }
 
-# endif DEBUG
 \f/*
 **  REMOTENAME -- return the name relative to the current mailer
 **
 \f/*
 **  REMOTENAME -- return the name relative to the current mailer
 **
@@ -1008,18 +1087,16 @@ remotename(name, m, senderaddress, canonical)
 {
        register char **pvp;
        char *fancy;
 {
        register char **pvp;
        char *fancy;
-       register char *p;
        extern char *macvalue();
        char *oldg = macvalue('g', CurEnv);
        static char buf[MAXNAME];
        char lbuf[MAXNAME];
        extern char *macvalue();
        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();
 
-# ifdef DEBUG
        if (tTd(12, 1))
                printf("remotename(%s)\n", name);
        if (tTd(12, 1))
                printf("remotename(%s)\n", name);
-# endif DEBUG
 
        /* don't do anything if we are tagging it as special */
        if ((senderaddress ? m->m_s_rwset : m->m_r_rwset) < 0)
 
        /* don't do anything if we are tagging it as special */
        if ((senderaddress ? m->m_s_rwset : m->m_r_rwset) < 0)
@@ -1043,7 +1120,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);
@@ -1104,9 +1181,7 @@ remotename(name, m, senderaddress, canonical)
        expand(fancy, buf, &buf[sizeof buf - 1], CurEnv);
        define('g', oldg, CurEnv);
 
        expand(fancy, buf, &buf[sizeof buf - 1], CurEnv);
        define('g', oldg, CurEnv);
 
-# ifdef DEBUG
        if (tTd(12, 1))
                printf("remotename => `%s'\n", buf);
        if (tTd(12, 1))
                printf("remotename => `%s'\n", buf);
-# endif DEBUG
        return (buf);
 }
        return (buf);
 }