BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.sbin / sendmail / src / alias.c
index 74b0c15..c2a784f 100644 (file)
@@ -3,14 +3,40 @@
  * 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
 #ifdef DBM
  */
 
 #ifndef lint
 #ifdef DBM
-static char sccsid[] = "@(#)alias.c    5.22 (Berkeley) %G% (with DBM)";
+static char sccsid[] = "@(#)alias.c    5.22 (Berkeley) 3/2/91 (with DBM)";
 #else
 #else
-static char sccsid[] = "@(#)alias.c    5.22 (Berkeley) %G% (without DBM)";
+static char sccsid[] = "@(#)alias.c    5.22 (Berkeley) 3/2/91 (without DBM)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -64,7 +90,6 @@ alias(a, sendq)
        ADDRESS **sendq;
 {
        register char *p;
        ADDRESS **sendq;
 {
        register char *p;
-       extern ADDRESS *sendto();
        extern char *aliaslookup();
 
        if (tTd(27, 1))
        extern char *aliaslookup();
 
        if (tTd(27, 1))
@@ -97,7 +122,7 @@ alias(a, sendq)
                    a->q_paddr, a->q_host, a->q_user, p);
        message(Arpa_Info, "aliased to %s", p);
        AliasLevel++;
                    a->q_paddr, a->q_host, a->q_user, p);
        message(Arpa_Info, "aliased to %s", p);
        AliasLevel++;
-       a->q_child = sendto(p, 1, a, 0);
+       sendtolist(p, a, sendq);
        AliasLevel--;
 }
 \f/*
        AliasLevel--;
 }
 \f/*
@@ -299,7 +324,6 @@ readaliases(aliasfile, init)
        bool init;
 {
        register char *p;
        bool init;
 {
        register char *p;
-       char *lhs;
        char *rhs;
        bool skipping;
        int naliases, bytes, longest;
        char *rhs;
        bool skipping;
        int naliases, bytes, longest;
@@ -395,79 +419,33 @@ readaliases(aliasfile, init)
 
                /*
                **  Process the LHS
 
                /*
                **  Process the LHS
-               **
                **      Find the final colon, and parse the address.
                **      Find the final colon, and parse the address.
-               **      It should resolve to a local name.
-               **
-               **      Alternatively, it can be "@hostname" for host
-               **      aliases -- all we do here is map case.  Hostname
-               **      need not be a single token.
+               **      It should resolve to a local name -- this will
+               **      be checked later (we want to optionally do
+               **      parsing of the RHS first to maximize error
+               **      detection).
                */
 
                for (p = line; *p != '\0' && *p != ':' && *p != '\n'; p++)
                        continue;
                */
 
                for (p = line; *p != '\0' && *p != ':' && *p != '\n'; p++)
                        continue;
-               if (*p != ':')
+               if (*p++ != ':')
                {
                {
-                       syserr("%s, line %d: syntax error", aliasfile, lineno);
+                       syserr("missing colon");
                        continue;
                }
                        continue;
                }
-               *p++ = '\0';
-               if (line[0] == '@')
-               {
-                       /* a host alias */
-                       makelower(line);
-                       lhs = line;
-               }
-               else
+               if (parseaddr(line, &al, 1, ':') == NULL)
                {
                {
-                       /* a user alias */
-                       if (parseaddr(line, &al, 1, ':') == NULL)
-                       {
-                               syserr("illegal alias name");
-                               continue;
-                       }
-                       loweraddr(&al);
-                       if (al.q_mailer != LocalMailer)
-                       {
-                               syserr("cannot alias non-local names");
-                               continue;
-                       }
-                       lhs = al.q_user;
+                       syserr("illegal alias name");
+                       continue;
                }
                }
+               loweraddr(&al);
 
                /*
                **  Process the RHS.
                **      'al' is the internal form of the LHS address.
                **      'p' points to the text of the RHS.
 
                /*
                **  Process the RHS.
                **      'al' is the internal form of the LHS address.
                **      'p' points to the text of the RHS.
-               **              'p' may begin with a colon (i.e., the
-               **              separator was "::") which will use the
-               **              first address as the person to send
-               **              errors to -- i.e., designates the
-               **              list maintainer.
                */
 
                */
 
-               if (*p == ':')
-               {
-                       ADDRESS *maint;
-
-                       while (isspace(*++p))
-                               continue;
-                       rhs = p;
-                       while (*p != '\0' && *p != ',')
-                               p++;
-                       if (*p != ',')
-                               goto syntaxerr;
-                       *p++ = '\0';
-                       maint = parse(p, (ADDRESS *) NULL, 1);
-                       if (maint == NULL)
-                               syserr("Illegal list maintainer for list %s", al.q_user);
-                       else if (CurEnv->e_returnto == &CurEnv->e_from)
-                       {
-                               CurEnv->e_returnto = maint;
-                               MailBack++;
-                       }
-               }
-                       
                rhs = p;
                for (;;)
                {
                rhs = p;
                for (;;)
                {
@@ -508,12 +486,17 @@ readaliases(aliasfile, init)
                                break;
                        LineNumber++;
                }
                                break;
                        LineNumber++;
                }
+               if (al.q_mailer != LocalMailer)
+               {
+                       syserr("cannot alias non-local names");
+                       continue;
+               }
 
                /*
                **  Insert alias into symbol table or DBM file
                */
 
 
                /*
                **  Insert alias into symbol table or DBM file
                */
 
-               lhssize = strlen(lhs) + 1;
+               lhssize = strlen(al.q_user) + 1;
                rhssize = strlen(rhs) + 1;
 
 # ifdef DBM
                rhssize = strlen(rhs) + 1;
 
 # ifdef DBM
@@ -612,86 +595,3 @@ forward(user, sendq)
        /* we do have an address to forward to -- do it */
        include(buf, "forwarding", user, sendq);
 }
        /* we do have an address to forward to -- do it */
        include(buf, "forwarding", user, sendq);
 }
-\f/*
-**  MAPHOST -- given a host description, produce a mapping.
-**
-**     This is done by looking up the name in the alias file,
-**     preceeded by an "@".  This can be used for UUCP mapping.
-**     For example, a call with {blia, ., UUCP} as arguments
-**     might return {ucsfcgl, !, blia, ., UUCP} as the result.
-**
-**     We first break the input into three parts -- before the
-**     lookup, the lookup itself, and after the lookup.  We
-**     then do the lookup, concatenate them together, and rescan
-**     the result.
-**
-**     Parameters:
-**             pvp -- the parameter vector to map.
-**
-**     Returns:
-**             The result of the mapping.  If nothing found, it
-**             should just concatenate the three parts together and
-**             return that.
-**
-**     Side Effects:
-**             none.
-*/
-
-char **
-maphost(pvp)
-       char **pvp;
-{
-       register char **avp;
-       register char **bvp;
-       char *p;
-       char buf1[MAXNAME];
-       char buf2[MAXNAME];
-       char buf3[MAXNAME];
-       extern char **prescan();
-
-       /*
-       **  Extract the three parts of the input as strings.
-       */
-
-       /* find the part before the lookup */
-       for (bvp = pvp; *bvp != NULL && **bvp != MATCHLOOKUP; bvp++)
-               continue;
-       if (*bvp == NULL)
-               return (pvp);
-       p = *bvp;
-       *bvp = NULL;
-       cataddr(pvp, buf1, sizeof buf1);
-       *bvp++ = p;
-
-       /* find the rest of the lookup */
-       for (avp = bvp; *pvp != NULL && **bvp != MATCHELOOKUP; bvp++)
-               continue;
-       if (*bvp == NULL)
-               return (pvp);
-       p = *bvp;
-       *bvp = NULL;
-       cataddr(avp, buf2, sizeof buf2);
-       *bvp++ = p;
-
-       /* save the part after the lookup */
-       cataddr(bvp, buf3, sizeof buf3);
-
-       /*
-       **  Now look up the middle part.
-       */
-
-       p = aliaslookup(buf2);
-       if (p != NULL)
-               strcpy(buf2, p);
-
-       /*
-       **  Put the three parts back together and break into tokens.
-       */
-
-       strcat(buf1, buf2);
-       strcat(buf1, buf3);
-       avp = prescan(buf1, '\0');
-
-       /* return this mapping */
-       return (avp);
-}