cleanup for dbm stuff: Error => Errors; move local host
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Sun, 19 Oct 1980 08:50:03 +0000 (00:50 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Sun, 19 Oct 1980 08:50:03 +0000 (00:50 -0800)
detection into parse; misc cleanup

SCCS-vsn: usr.sbin/sendmail/src/version.c 1.7
SCCS-vsn: usr.sbin/sendmail/src/err.c 1.4
SCCS-vsn: usr.sbin/sendmail/src/alias.c 1.5
SCCS-vsn: usr.sbin/sendmail/src/sendmail.h 1.6
SCCS-vsn: usr.sbin/sendmail/src/parseaddr.c 1.5
SCCS-vsn: usr.sbin/sendmail/src/main.c 1.11
SCCS-vsn: usr.sbin/sendmail/src/deliver.c 1.7

usr/src/usr.sbin/sendmail/src/alias.c
usr/src/usr.sbin/sendmail/src/deliver.c
usr/src/usr.sbin/sendmail/src/err.c
usr/src/usr.sbin/sendmail/src/main.c
usr/src/usr.sbin/sendmail/src/parseaddr.c
usr/src/usr.sbin/sendmail/src/sendmail.h
usr/src/usr.sbin/sendmail/src/version.c

index 2503bcf..2461935 100644 (file)
@@ -3,7 +3,7 @@
 # include <pwd.h>
 # include "dlvrmail.h"
 
 # include <pwd.h>
 # include "dlvrmail.h"
 
-static char SccsId[] = "@(#)alias.c    1.4     %G%";
+static char SccsId[] = "@(#)alias.c    1.5     %G%";
 
 /*
 **  ALIAS -- Compute aliases.
 
 /*
 **  ALIAS -- Compute aliases.
@@ -25,7 +25,6 @@ static char SccsId[] = "@(#)alias.c   1.4     %G%";
 **
 **     Defined Constants:
 **             MAXRCRSN -- the maximum recursion depth.
 **
 **     Defined Constants:
 **             MAXRCRSN -- the maximum recursion depth.
-**             ALIASFILE -- the pathname of the alias file.
 **
 **     Called By:
 **             main
 **
 **     Called By:
 **             main
@@ -52,13 +51,12 @@ static char SccsId[] = "@(#)alias.c 1.4     %G%";
 */
 
 
 */
 
 
-# define ALIASFILE     "/usr/lib/mailaliases"
 # define MAXRCRSN      10
 
 #ifdef DBM
 typedef struct {char *dptr; int dsize;} datum;
 datum lhs, rhs;
 # define MAXRCRSN      10
 
 #ifdef DBM
 typedef struct {char *dptr; int dsize;} datum;
 datum lhs, rhs;
-datum fetch();
+extern datum fetch();
 #endif DBM
 
 alias()
 #endif DBM
 
 alias()
@@ -168,28 +166,6 @@ alias()
                        }
                        if (q != NULL)
                        {
                        }
                        if (q != NULL)
                        {
-#else DBM
-       /*
-       **  Scan SendQ
-       **      We pass through the queue several times.  Didalias tells
-       **      us if we took some alias on this pass through the queue;
-       **      when it goes false at the top of the loop we don't have
-       **      to scan any more.
-       */
-
-       do
-       {
-               didalias = FALSE;
-               /*  Scan SendQ for that canonical form. */
-               for (q = &SendQ; (q = nxtinq(q)) != NULL; )
-               {
-                       lhs.dptr = q -> q_paddr;
-                       lhs.dsize = strlen(lhs.dptr)+1;
-                       rhs = fetch(lhs);
-                       p = rhs.dptr;
-                       if (p != NULL)
-                       {
-#endif
                                /*
                                **  Match on Alias.
                                **      Deliver to the target list.
                                /*
                                **  Match on Alias.
                                **      Deliver to the target list.
@@ -211,9 +187,49 @@ alias()
                        }
                }
        } while (didalias);
                        }
                }
        } while (didalias);
-#ifndef DBM
        fclose(af);
        fclose(af);
-#endif
+#else DBM
+       /*
+       **  Scan SendQ
+       **      We only have to do this once, since anything we alias
+       **      two is being put at the end of the queue we are
+       **      scanning.
+       */
+
+       for (q = &SendQ; (q = nxtinq(q)) != NULL; )
+       {
+               /* only alias local users */
+               if (q->q_mailer != &Mailer[0])
+                       continue;
+
+               /* create a key for fetch */
+               lhs.dptr = q->q_user;
+               lhs.dsize = strlen(q->q_user) + 1;
+               lhs.dptr = line;
+               rhs = fetch(lhs);
+
+               /* find this alias? */
+               p = rhs.dptr;
+               if (p == NULL)
+                       continue;
+
+               /*
+               **  Match on Alias.
+               **      Deliver to the target list.
+               **      Remove the alias from the send queue
+               **        and put it on the Alias queue.
+               */
+
+# ifdef DEBUG
+               if (Debug)
+                       printf("%s (%s, %s) aliased to %s\n",
+                           q->q_paddr, q->q_host, q->q_user, p);
+# endif
+               tkoffq(q, &SendQ);
+               putonq(q, &AliasQ);
+               sendto(p, 1);
+       }
+#endif DBM
 }
 \f/*
 **  FORWARD -- Try to forward mail
 }
 \f/*
 **  FORWARD -- Try to forward mail
index f6dc68d..eecaf81 100644 (file)
@@ -6,7 +6,7 @@
 # include <log.h>
 # endif LOG
 
 # include <log.h>
 # endif LOG
 
-static char SccsId[] = "@(#)deliver.c  1.6     %G%";
+static char SccsId[] = "@(#)deliver.c  1.7     %G%";
 
 /*
 **  DELIVER -- Deliver a message to a particular address.
 
 /*
 **  DELIVER -- Deliver a message to a particular address.
@@ -81,7 +81,7 @@ deliver(to, editfcn)
        m = to->q_mailer;
        user = to->q_user;
        host = to->q_host;
        m = to->q_mailer;
        user = to->q_user;
        host = to->q_host;
-       Error = 0;
+       Errors = 0;
        errno = 0;
 # ifdef DEBUG
        if (Debug)
        errno = 0;
 # ifdef DEBUG
        if (Debug)
@@ -288,7 +288,7 @@ deliver(to, editfcn)
 **             none.
 **
 **     Side Effects:
 **             none.
 **
 **     Side Effects:
-**             Error may be set.
+**             Errors may be incremented.
 **             ExitStat may be set.
 **
 **     Called By:
 **             ExitStat may be set.
 **
 **     Called By:
@@ -314,7 +314,7 @@ giveresponse(stat, force, m)
                statmsg = "ok";
        else
        {
                statmsg = "ok";
        else
        {
-               Error++;
+               Errors++;
                if (statmsg == NULL && m->m_badstat != 0)
                {
                        stat = m->m_badstat;
                if (statmsg == NULL && m->m_badstat != 0)
                {
                        stat = m->m_badstat;
@@ -505,29 +505,6 @@ recipient(a, targetq)
                printf("recipient(%s)\n", To);
 # endif DEBUG
 
                printf("recipient(%s)\n", To);
 # endif DEBUG
 
-       /*
-       **  Don't go to the net if already on the target host.
-       **      This is important on the berkeley network, since
-       **      it get confused if we ask to send to ourselves.
-       **      For nets like the ARPANET, we probably will have
-       **      the local list set to NULL to simplify testing.
-       **      The canonical representation of the name is also set
-       **      to be just the local name so the duplicate letter
-       **      suppression algorithm will work.
-       */
-
-       if ((pvp = m->m_local) != NULL)
-       {
-               while (*pvp != NULL)
-               {
-                       if (strcmp(*pvp++, a->q_host) == 0)
-                       {
-                               a->q_mailer = m = &Mailer[0];
-                               break;
-                       }
-               }
-       }
-
        /*
        **  Look up this person in the recipient list.  If they
        **  are there already, return, otherwise continue.
        /*
        **  Look up this person in the recipient list.  If they
        **  are there already, return, otherwise continue.
index 6d86dd3..80905b8 100644 (file)
@@ -4,10 +4,10 @@
 # include <log.h>
 # endif LOG
 
 # include <log.h>
 # endif LOG
 
-static char    SccsId[] = "@(#)err.c   1.3     %G%";
+static char    SccsId[] = "@(#)err.c   1.4     %G%";
 
 /*
 
 /*
-**  ERR -- Print error message.
+**  SYSERR -- Print error message.
 **
 **     Prints an error message via printf to the diagnostic
 **     output.  If LOG is defined, it logs it also.
 **
 **     Prints an error message via printf to the diagnostic
 **     output.  If LOG is defined, it logs it also.
@@ -20,8 +20,8 @@ static char   SccsId[] = "@(#)err.c   1.3     %G%";
 **             -1 always
 **
 **     Side Effects:
 **             -1 always
 **
 **     Side Effects:
-**             Sets Error.
-**             Sets ExitStat.
+**             increments Errors.
+**             sets ExitStat.
 */
 
 /*VARARGS1*/
 */
 
 /*VARARGS1*/
@@ -44,7 +44,7 @@ syserr(fmt, a, b, c, d, e)
                        sprintf(p, ": error %d", errno);
        }
        printf("delivermail: %s\n", errbuf);
                        sprintf(p, ": error %d", errno);
        }
        printf("delivermail: %s\n", errbuf);
-       Error++;
+       Errors++;
 
        /* determine exit status if not already set */
        if (ExitStat == EX_OK)
 
        /* determine exit status if not already set */
        if (ExitStat == EX_OK)
@@ -73,7 +73,7 @@ syserr(fmt, a, b, c, d, e)
 **             -1
 **
 **     Side Effects:
 **             -1
 **
 **     Side Effects:
-**             sets Error.
+**             increments Errors.
 */
 
 /*VARARGS1*/
 */
 
 /*VARARGS1*/
@@ -85,7 +85,7 @@ usrerr(fmt, a, b, c, d, e)
        if (SuprErrs)
                return;
 
        if (SuprErrs)
                return;
 
-       Error++;
+       Errors++;
        if (To != NULL)
                printf("%s... ", To);
        printf(fmt, a, b, c, d, e);
        if (To != NULL)
                printf("%s... ", To);
        printf(fmt, a, b, c, d, e);
index 7b692fc..7efde78 100644 (file)
@@ -6,7 +6,7 @@
 # include <log.h>
 # endif LOG
 
 # include <log.h>
 # endif LOG
 
-static char    SccsId[] = "@(#)main.c  1.10    %G%";
+static char    SccsId[] = "@(#)main.c  1.11    %G%";
 
 /*
 **  DELIVERMAIL -- Deliver mail to a set of destinations
 
 /*
 **  DELIVERMAIL -- Deliver mail to a set of destinations
@@ -114,8 +114,8 @@ bool        ForceMail;      /* mail even if already sent a copy */
 bool   MeToo;          /* send to the sender also if in a group expansion */
 bool   SaveFrom;       /* save From lines on the front of messages */
 bool   IgnrDot;        /* if set, ignore dot when collecting mail */
 bool   MeToo;          /* send to the sender also if in a group expansion */
 bool   SaveFrom;       /* save From lines on the front of messages */
 bool   IgnrDot;        /* if set, ignore dot when collecting mail */
-bool   Error;          /* set if errors */
 bool   SuprErrs;       /* supress errors if set */
 bool   SuprErrs;       /* supress errors if set */
+int    Errors;         /* count of errors */
 char   InFileName[] = "/tmp/mailtXXXXXX";
 char   Transcript[] = "/tmp/mailxXXXXXX";
 addrq  From;           /* the from person */
 char   InFileName[] = "/tmp/mailtXXXXXX";
 char   Transcript[] = "/tmp/mailxXXXXXX";
 addrq  From;           /* the from person */
@@ -376,7 +376,7 @@ main(argc, argv)
        }
 
        /* if we have had errors sofar, drop out now */
        }
 
        /* if we have had errors sofar, drop out now */
-       if (Error && ExitStat == EX_OK)
+       if (Errors > 0 && ExitStat == EX_OK)
                ExitStat = EX_USAGE;
        if (ExitStat != EX_OK)
                finis();
                ExitStat = EX_USAGE;
        if (ExitStat != EX_OK)
                finis();
index d897dbd..d314971 100644 (file)
@@ -2,7 +2,7 @@
 # include <ctype.h>
 # include "dlvrmail.h"
 
 # include <ctype.h>
 # include "dlvrmail.h"
 
-static char    SccsId[] = "@(#)parseaddr.c     1.4     %G%";
+static char    SccsId[] = "@(#)parseaddr.c     1.5     %G%";
 
 /*
 **  PARSE -- Parse an address
 
 /*
 **  PARSE -- Parse an address
@@ -61,6 +61,7 @@ parse(addr, a, copyf)
        bool got_one;
        extern char *prescan();
        extern char *xalloc();
        bool got_one;
        extern char *prescan();
        extern char *xalloc();
+       char **pvp;
 
        /*
        **  Initialize and prescan address.
 
        /*
        **  Initialize and prescan address.
@@ -205,6 +206,43 @@ parse(addr, a, copyf)
                        a->q_host = buf;
                        a->q_user = q;
                }
                        a->q_host = buf;
                        a->q_user = q;
                }
+
+               /*
+               **  Don't go to the net if already on the target host.
+               **      This is important on the berkeley network, since
+               **      it get confused if we ask to send to ourselves.
+               **      For nets like the ARPANET, we probably will have
+               **      the local list set to NULL to simplify testing.
+               **      The canonical representation of the name is also set
+               **      to be just the local name so the duplicate letter
+               **      suppression algorithm will work.
+               */
+
+               if ((pvp = a->q_mailer->m_local) != NULL)
+               {
+                       while (*pvp != NULL)
+                       {
+                               auto char buf2[MAXNAME];
+
+                               strcpy(buf2, a->q_host);
+                               if (!flagset(P_HST_UPPER, t->p_flags))
+                                       makelower(buf2);
+                               if (strcmp(*pvp++, buf2) == 0)
+                               {
+                                       strcpy(buf2, a->q_user);
+                                       p = a->q_paddr;
+                                       if (parse(buf2, a, -1) == NULL)
+                                       {
+                                               To = addr;
+                                               return (NULL);
+                                       }
+                                       To = a->q_paddr = p;
+                                       break;
+                               }
+                       }
+               }
+
+               /* make copies if specified */
                if (copyf >= 0)
                {
                        p = xalloc((unsigned) strlen(a->q_host) + 1);
                if (copyf >= 0)
                {
                        p = xalloc((unsigned) strlen(a->q_host) + 1);
index 538bdc0..70b456c 100644 (file)
@@ -3,7 +3,7 @@
 **
 **     Most of these are actually allocated in globals.c
 **
 **
 **     Most of these are actually allocated in globals.c
 **
-**     @(#)sendmail.h  1.5     %G%
+**     @(#)sendmail.h  1.6     %G%
 */
 
 
 */
 
 
@@ -20,6 +20,7 @@
 # define MAXFIELD      2500    /* maximum total length of a header field */
 # define MAXPV         15      /* maximum # of parms to mailers */
 # define MAXHOP                30      /* maximum value of HopCount */
 # define MAXFIELD      2500    /* maximum total length of a header field */
 # define MAXPV         15      /* maximum # of parms to mailers */
 # define MAXHOP                30      /* maximum value of HopCount */
+# define ALIASFILE     "/usr/lib/aliases"      /* location of alias file */
 
 
 
 
 
 
@@ -120,10 +121,10 @@ extern bool       WriteBack;      /* write back response on error */
 extern bool    NoAlias;        /* if set, don't do any aliasing */
 extern bool    ForceMail;      /* if set, mail even if already got a copy */
 extern bool    MeToo;          /* send to the sender also */
 extern bool    NoAlias;        /* if set, don't do any aliasing */
 extern bool    ForceMail;      /* if set, mail even if already got a copy */
 extern bool    MeToo;          /* send to the sender also */
-extern bool    Error;          /* set if errors */
 extern bool    UseMsgId;       /* put msg-id's in all msgs [conf.c] */
 extern bool    IgnrDot;        /* don't let dot end messages */
 extern bool    SaveFrom;       /* save leading "From" lines */
 extern bool    UseMsgId;       /* put msg-id's in all msgs [conf.c] */
 extern bool    IgnrDot;        /* don't let dot end messages */
 extern bool    SaveFrom;       /* save leading "From" lines */
+extern int     Errors;         /* set if errors */
 extern int     ExitStat;       /* exit status code */
 extern char    InFileName[];   /* input file name */
 extern char    Transcript[];   /* the transcript file name */
 extern int     ExitStat;       /* exit status code */
 extern char    InFileName[];   /* input file name */
 extern char    Transcript[];   /* the transcript file name */
index b50b3b7..44c9cdb 100644 (file)
@@ -1 +1 @@
-char   Version[] = "@(#)Delivermail version 1.6 of %G%";
+char   Version[] = "@(#)Delivermail version 1.7 of %G%";