change alias initialization to general map initialization
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Fri, 28 May 1993 22:00:57 +0000 (14:00 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Fri, 28 May 1993 22:00:57 +0000 (14:00 -0800)
SCCS-vsn: usr.sbin/sendmail/src/convtime.c 6.4
SCCS-vsn: usr.sbin/sendmail/src/main.c 6.68
SCCS-vsn: usr.sbin/sendmail/src/stab.c 6.3
SCCS-vsn: usr.sbin/sendmail/src/srvrsmtp.c 6.57
SCCS-vsn: usr.sbin/sendmail/src/queue.c 6.59
SCCS-vsn: usr.sbin/sendmail/src/alias.c 6.51
SCCS-vsn: usr.sbin/sendmail/src/map.c 6.22

usr/src/usr.sbin/sendmail/src/alias.c
usr/src/usr.sbin/sendmail/src/convtime.c
usr/src/usr.sbin/sendmail/src/main.c
usr/src/usr.sbin/sendmail/src/map.c
usr/src/usr.sbin/sendmail/src/queue.c
usr/src/usr.sbin/sendmail/src/srvrsmtp.c
usr/src/usr.sbin/sendmail/src/stab.c

index 2582d79..f1055f7 100644 (file)
 # include <pwd.h>
 
 #ifndef lint
 # include <pwd.h>
 
 #ifndef lint
-static char sccsid[] = "@(#)alias.c    6.50 (Berkeley) %G%";
+static char sccsid[] = "@(#)alias.c    6.51 (Berkeley) %G%";
 #endif /* not lint */
 
 
 #endif /* not lint */
 
 
-MAP    AliasDB[MAXALIASDB + 1];        /* actual database list */
+MAP    *AliasDB[MAXALIASDB + 1];       /* actual database list */
 int    NAliasDBs;                      /* number of alias databases */
 \f/*
 **  ALIAS -- Compute aliases.
 int    NAliasDBs;                      /* number of alias databases */
 \f/*
 **  ALIAS -- Compute aliases.
@@ -155,7 +155,7 @@ aliaslookup(name, e)
        {
                auto int stat;
 
        {
                auto int stat;
 
-               map = &AliasDB[dbno];
+               map = AliasDB[dbno];
                if (!bitset(MF_OPEN, map->map_mflags))
                        continue;
                p = (*map->map_class->map_lookup)(map, name, NULL, &stat);
                if (!bitset(MF_OPEN, map->map_mflags))
                        continue;
                p = (*map->map_class->map_lookup)(map, name, NULL, &stat);
@@ -189,6 +189,8 @@ setalias(spec)
 
        for (p = spec; p != NULL; )
        {
 
        for (p = spec; p != NULL; )
        {
+               char aname[50];
+
                while (isspace(*p))
                        p++;
                if (*p == '\0')
                while (isspace(*p))
                        p++;
                if (*p == '\0')
@@ -200,7 +202,10 @@ setalias(spec)
                        syserr("Too many alias databases defined, %d max", MAXALIASDB);
                        return;
                }
                        syserr("Too many alias databases defined, %d max", MAXALIASDB);
                        return;
                }
-               map = &AliasDB[NAliasDBs];
+               (void) sprintf(aname, "Alias%d", NAliasDBs);
+               s = stab(aname, ST_MAP, ST_ENTER);
+               map = &s->s_map;
+               AliasDB[NAliasDBs] = map;
                bzero(map, sizeof *map);
 
                p = strpbrk(p, " ,/:");
                bzero(map, sizeof *map);
 
                p = strpbrk(p, " ,/:");
@@ -247,72 +252,6 @@ setalias(spec)
        }
 }
 \f/*
        }
 }
 \f/*
-**  INITALIASES -- initialize for aliasing
-**
-**     Very different depending on whether we are running NDBM or not.
-**
-**     Parameters:
-**             rebuild -- if TRUE, this rebuilds the cached versions.
-**             e -- current envelope.
-**
-**     Returns:
-**             none.
-**
-**     Side Effects:
-**             initializes aliases:
-**             if NDBM:  opens the database.
-**             if ~NDBM: reads the aliases into the symbol table.
-*/
-
-initaliases(rebuild, e)
-       bool rebuild;
-       register ENVELOPE *e;
-{
-       int dbno;
-       register MAP *map;
-
-       CurEnv = e;
-       for (dbno = 0; dbno < NAliasDBs; dbno++)
-       {
-               map = &AliasDB[dbno];
-               if (!bitset(MF_VALID, map->map_mflags))
-                       continue;
-
-               if (tTd(27, 2))
-                       printf("initaliases(%s:%s)\n",
-                               map->map_class->map_cname, map->map_file);
-
-               /* if already open, close it (for nested open) */
-               if (bitset(MF_OPEN, map->map_mflags))
-               {
-                       map->map_class->map_close(map);
-                       map->map_mflags &= ~(MF_OPEN|MF_WRITABLE);
-               }
-
-               if (rebuild)
-               {
-                       if (bitset(MCF_REBUILDABLE, map->map_class->map_cflags))
-                               rebuildaliases(map, FALSE);
-               }
-               else
-               {
-                       if (map->map_class->map_open(map, O_RDONLY))
-                       {
-                               if (tTd(27, 4))
-                                       printf("%s:%s: valid\n",
-                                               map->map_class->map_cname,
-                                               map->map_file);
-                               map->map_mflags |= MF_OPEN;
-                       }
-                       else if (tTd(27, 4))
-                               printf("%s:%s: invalid: %s\n",
-                                       map->map_class->map_cname,
-                                       map->map_file,
-                                       errstring(errno));
-               }
-       }
-}
-\f/*
 **  ALIASWAIT -- wait for distinguished @:@ token to appear.
 **
 **     This can decide to reopen or rebuild the alias file
 **  ALIASWAIT -- wait for distinguished @:@ token to appear.
 **
 **     This can decide to reopen or rebuild the alias file
index a13cefb..99bccff 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)convtime.c 6.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)convtime.c 6.4 (Berkeley) %G%";
 #endif /* not lint */
 
 # include <ctype.h>
 #endif /* not lint */
 
 # include <ctype.h>
@@ -48,7 +48,7 @@ convtime(p, units)
        while (*p != '\0')
        {
                t = 0;
        while (*p != '\0')
        {
                t = 0;
-               while (isascii(c = *p++) && isdigit(c))
+               while ((c = *p++) != '\0' && isascii(c) && isdigit(c))
                        t = t * 10 + (c - '0');
                if (c == '\0')
                {
                        t = t * 10 + (c - '0');
                if (c == '\0')
                {
index 330e6ed..a4ca2ab 100644 (file)
@@ -13,7 +13,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     6.67 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     6.68 (Berkeley) %G%";
 #endif /* not lint */
 
 #define        _DEFINE
 #endif /* not lint */
 
 #define        _DEFINE
@@ -708,7 +708,7 @@ main(argc, argv, envp)
 
          case MD_INITALIAS:
                /* initialize alias database */
 
          case MD_INITALIAS:
                /* initialize alias database */
-               initaliases(TRUE, CurEnv);
+               initmaps(TRUE, CurEnv);
                exit(EX_OK);
 
          case MD_DAEMON:
                exit(EX_OK);
 
          case MD_DAEMON:
@@ -717,7 +717,7 @@ main(argc, argv, envp)
 
          default:
                /* open the alias database */
 
          default:
                /* open the alias database */
-               initaliases(FALSE, CurEnv);
+               initmaps(FALSE, CurEnv);
                break;
        }
 
                break;
        }
 
index 3dcce95..ed6e4c6 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)map.c      6.21 (Berkeley) %G%";
+static char sccsid[] = "@(#)map.c      6.22 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "sendmail.h"
 #endif /* not lint */
 
 #include "sendmail.h"
@@ -184,7 +184,7 @@ map_rewrite(map, s, slen, av)
        int i;
        int len;
 
        int i;
        int len;
 
-       if (tTd(23, 1))
+       if (tTd(39, 1))
        {
                printf("map_rewrite(%.*s), av =", slen, s);
                if (av == NULL)
        {
                printf("map_rewrite(%.*s), av =", slen, s);
                if (av == NULL)
@@ -274,11 +274,85 @@ map_rewrite(map, s, slen, av)
                strcpy(bp, map->map_app);
        else
                *bp = '\0';
                strcpy(bp, map->map_app);
        else
                *bp = '\0';
-       if (tTd(23, 1))
+       if (tTd(39, 1))
                printf("map_rewrite => %s\n", rwb->rwb_buf);
        return rwb->rwb_buf;
 }
 \f/*
                printf("map_rewrite => %s\n", rwb->rwb_buf);
        return rwb->rwb_buf;
 }
 \f/*
+**  INITMAPS -- initialize for aliasing
+**
+**     Parameters:
+**             rebuild -- if TRUE, this rebuilds the cached versions.
+**             e -- current envelope.
+**
+**     Returns:
+**             none.
+**
+**     Side Effects:
+**             initializes aliases:
+**             if NDBM:  opens the database.
+**             if ~NDBM: reads the aliases into the symbol table.
+*/
+
+initmaps(rebuild, e)
+       bool rebuild;
+       register ENVELOPE *e;
+{
+       extern void map_init();
+
+       CurEnv = e;
+       stabapply(map_init, rebuild);
+}
+
+void
+map_init(s, rebuild)
+       register STAB *s;
+       int rebuild;
+{
+       register MAP *map;
+
+       /* has to be a map */
+       if (s->s_type != ST_MAP)
+               return;
+
+       map = &s->s_map;
+       if (!bitset(MF_VALID, map->map_mflags))
+               return;
+
+       if (tTd(38, 2))
+               printf("map_init(%s:%s)\n",
+                       map->map_class->map_cname, map->map_file);
+
+       /* if already open, close it (for nested open) */
+       if (bitset(MF_OPEN, map->map_mflags))
+       {
+               map->map_class->map_close(map);
+               map->map_mflags &= ~(MF_OPEN|MF_WRITABLE);
+       }
+
+       if (rebuild)
+       {
+               if (bitset(MCF_REBUILDABLE, map->map_class->map_cflags))
+                       rebuildaliases(map, FALSE);
+       }
+       else
+       {
+               if (map->map_class->map_open(map, O_RDONLY))
+               {
+                       if (tTd(38, 4))
+                               printf("%s:%s: valid\n",
+                                       map->map_class->map_cname,
+                                       map->map_file);
+                       map->map_mflags |= MF_OPEN;
+               }
+               else if (tTd(38, 4))
+                       printf("%s:%s: invalid: %s\n",
+                               map->map_class->map_cname,
+                               map->map_file,
+                               errstring(errno));
+       }
+}
+\f/*
 **  NDBM modules
 */
 
 **  NDBM modules
 */
 
@@ -295,7 +369,7 @@ ndbm_map_open(map, mode)
 {
        DBM *dbm;
 
 {
        DBM *dbm;
 
-       if (tTd(27, 2))
+       if (tTd(38, 2))
                printf("ndbm_map_open(%s, %d)\n", map->map_file, mode);
 
        if (mode == O_RDWR)
                printf("ndbm_map_open(%s, %d)\n", map->map_file, mode);
 
        if (mode == O_RDWR)
@@ -330,7 +404,7 @@ ndbm_map_lookup(map, name, av, statp)
        datum key, val;
        char keybuf[MAXNAME + 1];
 
        datum key, val;
        char keybuf[MAXNAME + 1];
 
-       if (tTd(27, 20))
+       if (tTd(38, 20))
                printf("ndbm_map_lookup(%s)\n", name);
 
        key.dptr = name;
                printf("ndbm_map_lookup(%s)\n", name);
 
        key.dptr = name;
@@ -370,7 +444,7 @@ ndbm_map_store(map, lhs, rhs)
        datum data;
        int stat;
 
        datum data;
        int stat;
 
-       if (tTd(27, 12))
+       if (tTd(38, 12))
                printf("ndbm_map_store(%s, %s)\n", lhs, rhs);
 
        key.dsize = strlen(lhs);
                printf("ndbm_map_store(%s, %s)\n", lhs, rhs);
 
        key.dsize = strlen(lhs);
@@ -442,7 +516,7 @@ bt_map_open(map, mode)
        int i;
        char buf[MAXNAME];
 
        int i;
        char buf[MAXNAME];
 
-       if (tTd(27, 2))
+       if (tTd(38, 2))
                printf("bt_map_open(%s, %d)\n", map->map_file, mode);
 
        if (mode == O_RDWR)
                printf("bt_map_open(%s, %d)\n", map->map_file, mode);
 
        if (mode == O_RDWR)
@@ -479,7 +553,7 @@ hash_map_open(map, mode)
        int i;
        char buf[MAXNAME];
 
        int i;
        char buf[MAXNAME];
 
-       if (tTd(27, 2))
+       if (tTd(38, 2))
                printf("hash_map_open(%s, %d)\n", map->map_file, mode);
 
        if (mode == O_RDWR)
                printf("hash_map_open(%s, %d)\n", map->map_file, mode);
 
        if (mode == O_RDWR)
@@ -520,7 +594,7 @@ db_map_lookup(map, name, av, statp)
        int saveerrno;
        char keybuf[MAXNAME + 1];
 
        int saveerrno;
        char keybuf[MAXNAME + 1];
 
-       if (tTd(27, 20))
+       if (tTd(38, 20))
                printf("db_map_lookup(%s)\n", name);
 
        key.size = strlen(name);
                printf("db_map_lookup(%s)\n", name);
 
        key.size = strlen(name);
@@ -568,7 +642,7 @@ db_map_store(map, lhs, rhs)
        DBT data;
        register DB *db = map->map_db2;
 
        DBT data;
        register DB *db = map->map_db2;
 
-       if (tTd(27, 20))
+       if (tTd(38, 20))
                printf("db_map_store(%s, %s)\n", lhs, rhs);
 
        key.size = strlen(lhs);
                printf("db_map_store(%s, %s)\n", lhs, rhs);
 
        key.size = strlen(lhs);
@@ -604,7 +678,7 @@ db_map_close(map)
 {
        register DB *db = map->map_db2;
 
 {
        register DB *db = map->map_db2;
 
-       if (tTd(27, 9))
+       if (tTd(38, 9))
                printf("db_map_close(%s, %x)\n", map->map_file, map->map_mflags);
 
        if (bitset(MF_WRITABLE, map->map_mflags))
                printf("db_map_close(%s, %x)\n", map->map_file, map->map_mflags);
 
        if (bitset(MF_WRITABLE, map->map_mflags))
@@ -639,7 +713,7 @@ nis_map_open(map, mode)
        auto int vsize;
        char *master;
 
        auto int vsize;
        char *master;
 
-       if (tTd(27, 2))
+       if (tTd(38, 2))
                printf("nis_map_open(%s)\n", map->map_file);
 
        if (mode != O_RDONLY)
                printf("nis_map_open(%s)\n", map->map_file);
 
        if (mode != O_RDONLY)
@@ -665,7 +739,7 @@ nis_map_open(map, mode)
        /* check to see if this map actually exists */
        yperr = yp_match(map->map_domain, map->map_file, "@", 1,
                        &vp, &vsize);
        /* check to see if this map actually exists */
        yperr = yp_match(map->map_domain, map->map_file, "@", 1,
                        &vp, &vsize);
-       if (tTd(27, 10))
+       if (tTd(38, 10))
                printf("nis_map_open: yp_match(%s, %s) => %s\n",
                        map->map_domain, map->map_file, yperr_string(yperr));
        if (yperr == 0 || yperr == YPERR_KEY || yperr == YPERR_BUSY)
                printf("nis_map_open: yp_match(%s, %s) => %s\n",
                        map->map_domain, map->map_file, yperr_string(yperr));
        if (yperr == 0 || yperr == YPERR_KEY || yperr == YPERR_BUSY)
@@ -696,7 +770,7 @@ nis_map_lookup(map, name, av, statp)
        int yperr;
        char keybuf[MAXNAME + 1];
 
        int yperr;
        char keybuf[MAXNAME + 1];
 
-       if (tTd(27, 20))
+       if (tTd(38, 20))
                printf("nis_map_lookup(%s)\n", name);
 
        buflen = strlen(name);
                printf("nis_map_lookup(%s)\n", name);
 
        buflen = strlen(name);
@@ -763,7 +837,7 @@ stab_map_lookup(map, name)
 {
        register STAB *s;
 
 {
        register STAB *s;
 
-       if (tTd(27, 20))
+       if (tTd(38, 20))
                printf("stab_lookup(%s)\n", name);
 
        s = stab(name, ST_ALIAS, ST_FIND);
                printf("stab_lookup(%s)\n", name);
 
        s = stab(name, ST_ALIAS, ST_FIND);
@@ -806,7 +880,7 @@ stab_map_open(map, mode)
 {
        FILE *af;
 
 {
        FILE *af;
 
-       if (tTd(27, 2))
+       if (tTd(38, 2))
                printf("stab_map_open(%s)\n", map->map_file);
 
        if (mode != O_RDONLY)
                printf("stab_map_open(%s)\n", map->map_file);
 
        if (mode != O_RDONLY)
@@ -847,7 +921,7 @@ impl_map_lookup(map, name, av, pstat)
        char **av;
        int *pstat;
 {
        char **av;
        int *pstat;
 {
-       if (tTd(27, 20))
+       if (tTd(38, 20))
                printf("impl_map_lookup(%s)\n", name);
 
 #ifdef NEWDB
                printf("impl_map_lookup(%s)\n", name);
 
 #ifdef NEWDB
@@ -893,7 +967,7 @@ impl_map_open(map, mode)
 {
        struct stat stb;
 
 {
        struct stat stb;
 
-       if (tTd(27, 2))
+       if (tTd(38, 2))
                printf("impl_map_open(%s)\n", map->map_file);
 
        if (stat(map->map_file, &stb) < 0)
                printf("impl_map_open(%s)\n", map->map_file);
 
        if (stat(map->map_file, &stb) < 0)
index b59e53a..c3a1efb 100644 (file)
@@ -10,9 +10,9 @@
 
 #ifndef lint
 #ifdef QUEUE
 
 #ifndef lint
 #ifdef QUEUE
-static char sccsid[] = "@(#)queue.c    6.58 (Berkeley) %G% (with queueing)";
+static char sccsid[] = "@(#)queue.c    6.59 (Berkeley) %G% (with queueing)";
 #else
 #else
-static char sccsid[] = "@(#)queue.c    6.58 (Berkeley) %G% (without queueing)";
+static char sccsid[] = "@(#)queue.c    6.59 (Berkeley) %G% (without queueing)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -456,7 +456,7 @@ runqueue(forkflag)
        **  Make sure the alias database is open.
        */
 
        **  Make sure the alias database is open.
        */
 
-       initaliases(FALSE, e);
+       initmaps(FALSE, e);
 
        /*
        **  Start making passes through the queue.
 
        /*
        **  Start making passes through the queue.
index 65783b2..ae395ef 100644 (file)
@@ -10,9 +10,9 @@
 
 #ifndef lint
 #ifdef SMTP
 
 #ifndef lint
 #ifdef SMTP
-static char sccsid[] = "@(#)srvrsmtp.c 6.56 (Berkeley) %G% (with SMTP)";
+static char sccsid[] = "@(#)srvrsmtp.c 6.57 (Berkeley) %G% (with SMTP)";
 #else
 #else
-static char sccsid[] = "@(#)srvrsmtp.c 6.56 (Berkeley) %G% (without SMTP)";
+static char sccsid[] = "@(#)srvrsmtp.c 6.57 (Berkeley) %G% (without SMTP)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -843,7 +843,7 @@ runinchild(label, e)
        }
 
        /* open alias database */
        }
 
        /* open alias database */
-       initaliases(FALSE, e);
+       initmaps(FALSE, e);
 
        return (0);
 }
 
        return (0);
 }
index daf9994..ab494eb 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)stab.c     6.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)stab.c     6.3 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -113,14 +113,16 @@ stab(name, type, op)
 **     Parameters:
 **             func -- the function to apply.  It will be given one
 **                     parameter (the stab entry).
 **     Parameters:
 **             func -- the function to apply.  It will be given one
 **                     parameter (the stab entry).
+**             arg -- an arbitrary argument, passed to func.
 **
 **     Returns:
 **             none.
 */
 
 void
 **
 **     Returns:
 **             none.
 */
 
 void
-stabapply(func)
-       void (*func)__P((STAB *));
+stabapply(func, arg)
+       void (*func)__P((STAB *, int));
+       int arg;
 {
        register STAB **shead;
        register STAB *s;
 {
        register STAB **shead;
        register STAB *s;
@@ -128,6 +130,11 @@ stabapply(func)
        for (shead = SymTab; shead < &SymTab[STABSIZE]; shead++)
        {
                for (s = *shead; s != NULL; s = s->s_next)
        for (shead = SymTab; shead < &SymTab[STABSIZE]; shead++)
        {
                for (s = *shead; s != NULL; s = s->s_next)
-                       func(s);
+               {
+                       if (tTd(38, 90))
+                               printf("stabapply: trying %d/%s\n",
+                                       s->s_type, s->s_name);
+                       func(s, arg);
+               }
        }
 }
        }
 }