uses dbm package for alias file to make it faster
authorMark Horton <mark@ucbvax.Berkeley.EDU>
Sat, 18 Oct 1980 05:41:57 +0000 (21:41 -0800)
committerMark Horton <mark@ucbvax.Berkeley.EDU>
Sat, 18 Oct 1980 05:41:57 +0000 (21:41 -0800)
SCCS-vsn: usr.sbin/sendmail/src/alias.c 1.4
SCCS-vsn: usr.sbin/sendmail/src/deliver.c 1.6

usr/src/usr.sbin/sendmail/src/alias.c
usr/src/usr.sbin/sendmail/src/deliver.c

index 63bbb97..2503bcf 100644 (file)
@@ -3,14 +3,14 @@
 # include <pwd.h>
 # include "dlvrmail.h"
 
 # include <pwd.h>
 # include "dlvrmail.h"
 
-static char SccsId[] = "@(#)alias.c    1.3     %G%";
+static char SccsId[] = "@(#)alias.c    1.4     %G%";
 
 /*
 **  ALIAS -- Compute aliases.
 **
 
 /*
 **  ALIAS -- Compute aliases.
 **
-**     Scans the file /usr/lib/mailaliases for a set of aliases.
+**     Scans the file ALIASFILE for a set of aliases.
 **     If found, it arranges to deliver to them by inserting the
 **     If found, it arranges to deliver to them by inserting the
-**     new names onto the SendQ queue.
+**     new names onto the SendQ queue.  Uses libdbm database if -DDBM.
 **
 **     Parameters:
 **             none
 **
 **     Parameters:
 **             none
@@ -37,6 +37,9 @@ static char SccsId[] = "@(#)alias.c   1.3     %G%";
 **                     where 'alias' expands to all of
 **                     'name[i]'.  Continuations begin with
 **                     space or tab.
 **                     where 'alias' expands to all of
 **                     'name[i]'.  Continuations begin with
 **                     space or tab.
+**             ALIASFILE.pag, ALIASFILE.dir: libdbm version
+**                     of alias file.  Keys are aliases, datums
+**                     (data?) are name1,name2, ...
 **
 **     Notes:
 **             If NoAlias (the "-n" flag) is set, no aliasing is
 **
 **     Notes:
 **             If NoAlias (the "-n" flag) is set, no aliasing is
@@ -52,6 +55,11 @@ static char SccsId[] = "@(#)alias.c  1.3     %G%";
 # define ALIASFILE     "/usr/lib/mailaliases"
 # define MAXRCRSN      10
 
 # define ALIASFILE     "/usr/lib/mailaliases"
 # define MAXRCRSN      10
 
+#ifdef DBM
+typedef struct {char *dptr; int dsize;} datum;
+datum lhs, rhs;
+datum fetch();
+#endif DBM
 
 alias()
 {
 
 alias()
 {
@@ -74,6 +82,7 @@ alias()
 # endif
 
        /* open alias file if not already open */
 # endif
 
        /* open alias file if not already open */
+#ifndef DBM
 # ifdef DEBUG
        if (Debug && (af = fopen("mailaliases", "r")) != NULL)
                printf(" [using local alias file]\n");
 # ifdef DEBUG
        if (Debug && (af = fopen("mailaliases", "r")) != NULL)
                printf(" [using local alias file]\n");
@@ -88,7 +97,11 @@ alias()
                errno = 0;
                return;
        }
                errno = 0;
                return;
        }
+#else DBM
+       dbminit(ALIASFILE);
+#endif DBM
 
 
+#ifndef DBM
        /*
        **  Scan alias file.
        **      If we find any user that any line matches any user, we
        /*
        **  Scan alias file.
        **      If we find any user that any line matches any user, we
@@ -102,8 +115,7 @@ alias()
        **      continuation lines.
        */
 
        **      continuation lines.
        */
 
-       didalias = TRUE;
-       while (didalias)
+       do
        {
                didalias = FALSE;
                gotmatch = FALSE;
        {
                didalias = FALSE;
                gotmatch = FALSE;
@@ -119,10 +131,6 @@ alias()
                        {
                                if (gotmatch)
                                {
                        {
                                if (gotmatch)
                                {
-# ifdef DEBUG
-                                       if (Debug)
-                                               printf("   ... also aliased to %s", line);
-# endif
                                        sendto(line, 1);
                                }
                                continue;
                                        sendto(line, 1);
                                }
                                continue;
@@ -160,6 +168,28 @@ 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.
@@ -180,8 +210,10 @@ alias()
                                sendto(p, 1);
                        }
                }
                                sendto(p, 1);
                        }
                }
-       }
+       } while (didalias);
+#ifndef DBM
        fclose(af);
        fclose(af);
+#endif
 }
 \f/*
 **  FORWARD -- Try to forward mail
 }
 \f/*
 **  FORWARD -- Try to forward mail
index 8df6411..f6dc68d 100644 (file)
@@ -6,7 +6,7 @@
 # include <log.h>
 # endif LOG
 
 # include <log.h>
 # endif LOG
 
-static char SccsId[] = "@(#)deliver.c  1.5     %G%";
+static char SccsId[] = "@(#)deliver.c  1.6     %G%";
 
 /*
 **  DELIVER -- Deliver a message to a particular address.
 
 /*
 **  DELIVER -- Deliver a message to a particular address.
@@ -182,7 +182,11 @@ deliver(to, editfcn)
                syserr("pipe");
                return (-1);
        }
                syserr("pipe");
                return (-1);
        }
+# ifdef VFORK
+       pid = vfork();
+# else
        pid = fork();
        pid = fork();
+# endif
        if (pid < 0)
        {
                syserr("Cannot fork");
        if (pid < 0)
        {
                syserr("Cannot fork");
@@ -213,7 +217,20 @@ deliver(to, editfcn)
 # ifdef LOG
                initlog(NULL, 0, LOG_CLOSE);
 # endif LOG
 # ifdef LOG
                initlog(NULL, 0, LOG_CLOSE);
 # endif LOG
+# ifndef VFORK
+               /*
+                * We have to be careful with vfork - we can't mung up the
+                * memory but we don't want the mailer to inherit any extra
+                * open files.  Chances are the mailer won't
+                * care about an extra file, but then again you never know.
+                * Actually, we would like to close(fileno(pwf)), but it's
+                * declared static so we can't.  But if we fclose(pwf), which
+                * is what endpwent does, it closes it in the parent too and
+                * the next getpwnam will be slower.  If you have a weird mailer
+                * that chokes on the extra file you should do the endpwent().
+                */
                endpwent();
                endpwent();
+# endif
                execv(m->m_mailer, pvp);
                /* syserr fails because log is closed */
                /* syserr("Cannot exec %s", m->m_mailer); */
                execv(m->m_mailer, pvp);
                /* syserr fails because log is closed */
                /* syserr("Cannot exec %s", m->m_mailer); */