BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.sbin / sendmail / src / parseaddr.c
index 00d4a4e..2ee24e0 100644 (file)
@@ -3,11 +3,37 @@
  * Copyright (c) 1988 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1988 Regents of the University of California.
  * All rights reserved.
  *
- * %sccs.include.redist.c%
+ * 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
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)parseaddr.c        5.13 (Berkeley) %G%";
+static char sccsid[] = "@(#)parseaddr.c        5.13 (Berkeley) 6/1/90";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -354,17 +380,6 @@ prescan(addr, delim, pvpbuf)
                        }
                        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;
@@ -502,8 +517,6 @@ rewrite(pvp, ruleset)
        register char **rvp;            /* rewrite vector pointer */
        register struct match *mlp;     /* cur ptr into mlist */
        register struct rewrite *rwr;   /* pointer to current rewrite rule */
        register char **rvp;            /* rewrite vector pointer */
        register struct match *mlp;     /* cur ptr into mlist */
        register struct rewrite *rwr;   /* pointer to current rewrite rule */
-       int subr;                       /* subroutine number if >= 0 */
-       bool dolookup;                  /* do host aliasing */
        struct match mlist[MAXMATCH];   /* stores match on LHS */
        char *npvp[MAXATOM+1];          /* temporary space for rebuild */
 
        struct match mlist[MAXMATCH];   /* stores match on LHS */
        char *npvp[MAXATOM+1];          /* temporary space for rebuild */
 
@@ -662,26 +675,18 @@ rewrite(pvp, ruleset)
                        rwr = NULL;
 
                /* substitute */
                        rwr = NULL;
 
                /* substitute */
-               dolookup = FALSE;
                for (avp = npvp; *rvp != NULL; rvp++)
                {
                        register struct match *m;
                        register char **pp;
 
                        rp = *rvp;
                for (avp = npvp; *rvp != NULL; rvp++)
                {
                        register struct match *m;
                        register char **pp;
 
                        rp = *rvp;
-
-                       /* check to see if we should do a lookup */
-                       if (*rp == MATCHLOOKUP)
-                               dolookup = TRUE;
-
-                       /* see if there is substitution here */
                        if (*rp == MATCHREPL)
                        {
                                /* substitute from LHS */
                                m = &mlist[rp[1] - '1'];
                                if (m >= mlp)
                                {
                        if (*rp == MATCHREPL)
                        {
                                /* substitute from LHS */
                                m = &mlist[rp[1] - '1'];
                                if (m >= mlp)
                                {
-                                 toolong:
                                        syserr("rewrite: ruleset %d: replacement out of bounds", ruleset);
                                        return;
                                }
                                        syserr("rewrite: ruleset %d: replacement out of bounds", ruleset);
                                        return;
                                }
@@ -712,7 +717,11 @@ rewrite(pvp, ruleset)
                        {
                                /* vanilla replacement */
                                if (avp >= &npvp[MAXATOM])
                        {
                                /* vanilla replacement */
                                if (avp >= &npvp[MAXATOM])
-                                       goto toolong;
+                               {
+       toolong:
+                                       syserr("rewrite: expansion too long");
+                                       return;
+                               }
                                *avp++ = rp;
                        }
                }
                                *avp++ = rp;
                        }
                }
@@ -788,57 +797,19 @@ rewrite(pvp, ruleset)
                **  Check for subroutine calls.
                */
 
                **  Check for subroutine calls.
                */
 
-
-               /*
-               **  Do hostname lookup if requested.
-               */
-
-               if (dolookup)
+               if (*npvp != NULL && **npvp == CALLSUBR)
                {
                {
-                       extern char **maphost();
-
-                       rvp = maphost(npvp);
-               }
-               else
-                       rvp = npvp;
-
-               /*
-               **  See if this is a subroutine call.
-               */
-
-               if (**rvp == CALLSUBR)
-               {
-                       subr = atoi(*++rvp);
-                       rvp++;
+                       bcopy((char *) &npvp[2], (char *) pvp,
+                               (int) (avp - npvp - 2) * sizeof *avp);
+                       if (tTd(21, 3))
+                               printf("-----callsubr %s\n", npvp[1]);
+                       rewrite(pvp, atoi(npvp[1]));
                }
                else
                }
                else
-                       subr = -1;
-
-               /*
-               **  Copy result back to original string.
-               */
-
-               for (avp = pvp; *rvp != NULL; rvp++)
-                       *avp++ = *rvp;
-               *avp = NULL;
-
-               /*
-               **  If this specified a subroutine, call it.
-               */
-
-               if (subr >= 0)
                {
                {
-# ifdef DEBUG
-                       if (tTd(21, 3))
-                               printf("-----callsubr %s\n", subr);
-# endif DEBUG
-                       rewrite(pvp, subr);
+                       bcopy((char *) npvp, (char *) pvp,
+                               (int) (avp - npvp) * sizeof *avp);
                }
                }
-
-               /*
-               **  Done with rewriting this pass.
-               */
-
                if (tTd(21, 4))
                {
                        printf("rewritten as:");
                if (tTd(21, 4))
                {
                        printf("rewritten as:");
@@ -879,7 +850,7 @@ buildaddr(tv, a)
 
        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)
@@ -1062,30 +1033,22 @@ printaddr(a, follow)
 {
        bool first = TRUE;
 
 {
        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);
-               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");