change OA semantics so that all .cf entries are mapped into the
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Tue, 30 May 1995 22:31:08 +0000 (14:31 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Tue, 30 May 1995 22:31:08 +0000 (14:31 -0800)
"files" or "local" alias service type

SCCS-vsn: usr.sbin/sendmail/src/readcf.c 8.97
SCCS-vsn: usr.sbin/sendmail/src/conf.c 8.184
SCCS-vsn: usr.sbin/sendmail/src/alias.c 8.49

usr/src/usr.sbin/sendmail/src/alias.c
usr/src/usr.sbin/sendmail/src/conf.c
usr/src/usr.sbin/sendmail/src/readcf.c

index 6335fb2..7166db4 100644 (file)
@@ -9,12 +9,12 @@
 # include "sendmail.h"
 
 #ifndef lint
 # include "sendmail.h"
 
 #ifndef lint
-static char sccsid[] = "@(#)alias.c    8.48 (Berkeley) %G%";
+static char sccsid[] = "@(#)alias.c    8.49 (Berkeley) %G%";
 #endif /* not lint */
 
 
 #endif /* not lint */
 
 
-MAP    *AliasDB[MAXALIASDB + 1];       /* actual database list */
-int    NAliasDBs = 1;                  /* number of alias databases */
+MAP    *AliasFileMap = NULL;   /* the actual aliases.files map */
+int    NAliasFileMaps;         /* the number of entries in AliasFileMap */
 \f/*
 **  ALIAS -- Compute aliases.
 **
 \f/*
 **  ALIAS -- Compute aliases.
 **
@@ -170,20 +170,19 @@ aliaslookup(name, pstat, e)
        int *pstat;
        ENVELOPE *e;
 {
        int *pstat;
        ENVELOPE *e;
 {
-       register int dbno;
-       register MAP *map;
-       register char *p;
+       static MAP *map = NULL;
 
 
-       for (dbno = 0; dbno < NAliasDBs; dbno++)
+       if (map == NULL)
        {
        {
-               map = AliasDB[dbno];
-               if (map == NULL || !bitset(MF_OPEN, map->map_mflags))
-                       continue;
-               p = (*map->map_class->map_lookup)(map, name, NULL, pstat);
-               if (p != NULL)
-                       return p;
+               STAB *s = stab("aliases", ST_MAP, ST_FIND);
+
+               if (s == NULL)
+                       return NULL;
+               map = &s->s_map;
        }
        }
-       return NULL;
+       if (!bitset(MF_OPEN, map->map_mflags))
+               return NULL;
+       return (*map->map_class->map_lookup)(map, name, NULL, pstat);
 }
 \f/*
 **  SETALIAS -- set up an alias map
 }
 \f/*
 **  SETALIAS -- set up an alias map
@@ -205,45 +204,39 @@ setalias(spec)
        register MAP *map;
        char *class;
        STAB *s;
        register MAP *map;
        char *class;
        STAB *s;
-       static bool first_unqual = TRUE;
 
        if (tTd(27, 8))
                printf("setalias(%s)\n", spec);
 
        for (p = spec; p != NULL; )
        {
 
        if (tTd(27, 8))
                printf("setalias(%s)\n", spec);
 
        for (p = spec; p != NULL; )
        {
+               char buf[50];
+
                while (isspace(*p))
                        p++;
                if (*p == '\0')
                        break;
                spec = p;
 
                while (isspace(*p))
                        p++;
                if (*p == '\0')
                        break;
                spec = p;
 
-               /*
-               **  Treat simple filename specially -- this is the file name
-               **  for the files implementation, not necessarily in order.
-               */
-
-               if (spec[0] == '/' && first_unqual)
+               if (NAliasFileMaps >= MAXMAPSTACK)
                {
                {
-                       s = stab("aliases.files", ST_MAP, ST_ENTER);
-                       map = &s->s_map;
-                       first_unqual = FALSE;
+                       syserr("Too many alias databases defined, %d max",
+                               MAXMAPSTACK);
+                       return;
                }
                }
-               else
+               if (AliasFileMap == NULL)
                {
                {
-                       char aname[50];
-
-                       if (NAliasDBs >= MAXALIASDB)
+                       strcpy(buf, "aliases.files sequence");
+                       AliasFileMap = makemapentry(buf);
+                       if (AliasFileMap == NULL)
                        {
                        {
-                               syserr("Too many alias databases defined, %d max",
-                                       MAXALIASDB);
+                               syserr("setalias: cannot create aliases.files map");
                                return;
                        }
                                return;
                        }
-                       (void) sprintf(aname, "Alias%d", NAliasDBs);
-                       s = stab(aname, ST_MAP, ST_ENTER);
-                       map = &s->s_map;
-                       AliasDB[NAliasDBs] = map;
                }
                }
+               (void) sprintf(buf, "Alias%d", NAliasFileMaps);
+               s = stab(buf, ST_MAP, ST_ENTER);
+               map = &s->s_map;
                bzero(map, sizeof *map);
                map->map_mname = s->s_name;
 
                bzero(map, sizeof *map);
                map->map_mname = s->s_name;
 
@@ -288,8 +281,7 @@ setalias(spec)
                        if (map->map_class->map_parse(map, spec))
                        {
                                map->map_mflags |= MF_VALID|MF_ALIAS;
                        if (map->map_class->map_parse(map, spec))
                        {
                                map->map_mflags |= MF_VALID|MF_ALIAS;
-                               if (AliasDB[NAliasDBs] == map)
-                                       NAliasDBs++;
+                               AliasFileMap->map_stack[NAliasFileMaps++] = map;
                        }
                }
        }
                        }
                }
        }
index 4c850e7..d15a885 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)conf.c     8.183 (Berkeley) %G%";
+static char sccsid[] = "@(#)conf.c     8.184 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -426,7 +426,6 @@ inithostmaps()
 {
        register int i;
        int nmaps;
 {
        register int i;
        int nmaps;
-       STAB *s;
        char *maptype[MAXMAPSTACK];
        short mapreturn[MAXMAPACTIONS];
        char buf[MAXLINE];
        char *maptype[MAXMAPSTACK];
        short mapreturn[MAXMAPACTIONS];
        char buf[MAXLINE];
@@ -443,14 +442,14 @@ inithostmaps()
                    stab("hosts.files", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "hosts.files text -k 0 -v 1 /etc/hosts");
                    stab("hosts.files", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "hosts.files text -k 0 -v 1 /etc/hosts");
-                       makemapentry(buf);
+                       (void) makemapentry(buf);
                }
 #if NAMED_BIND
                else if (strcmp(maptype[i], "dns") == 0 &&
                    stab("hosts.dns", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "hosts.dns dns A");
                }
 #if NAMED_BIND
                else if (strcmp(maptype[i], "dns") == 0 &&
                    stab("hosts.dns", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "hosts.dns dns A");
-                       makemapentry(buf);
+                       (void) makemapentry(buf);
                }
 #endif
 #ifdef NISPLUS
                }
 #endif
 #ifdef NISPLUS
@@ -458,7 +457,7 @@ inithostmaps()
                    stab("hosts.nisplus", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "hosts.nisplus nisplus -k name -v address -d hosts.org_dir");
                    stab("hosts.nisplus", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "hosts.nisplus nisplus -k name -v address -d hosts.org_dir");
-                       makemapentry(buf);
+                       (void) makemapentry(buf);
                }
 #endif
 #ifdef NIS
                }
 #endif
 #ifdef NIS
@@ -466,7 +465,7 @@ inithostmaps()
                    stab("hosts.nis", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "hosts.nis nis -d -k 0 -v 1 hosts.byname");
                    stab("hosts.nis", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "hosts.nis nis -d -k 0 -v 1 hosts.byname");
-                       makemapentry(buf);
+                       (void) makemapentry(buf);
                }
 #endif
        }
                }
 #endif
        }
@@ -484,7 +483,7 @@ inithostmaps()
                if (ConfigLevel >= 2)
                        strcat(buf, " -a.");
 #endif
                if (ConfigLevel >= 2)
                        strcat(buf, " -a.");
 #endif
-               makemapentry(buf);
+               (void) makemapentry(buf);
        }
 
        /*
        }
 
        /*
@@ -498,14 +497,14 @@ inithostmaps()
                    stab("aliases.files", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "aliases.files implicit /etc/aliases");
                    stab("aliases.files", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "aliases.files implicit /etc/aliases");
-                       makemapentry(buf);
+                       (void) makemapentry(buf);
                }
 #ifdef NISPLUS
                else if (strcmp(maptype[i], "nisplus") == 0 &&
                    stab("aliases.nisplus", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "aliases.nisplus nisplus -kalias -vexpansion -d mail_aliases.org_dir");
                }
 #ifdef NISPLUS
                else if (strcmp(maptype[i], "nisplus") == 0 &&
                    stab("aliases.nisplus", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "aliases.nisplus nisplus -kalias -vexpansion -d mail_aliases.org_dir");
-                       makemapentry(buf);
+                       (void) makemapentry(buf);
                }
 #endif
 #ifdef NIS
                }
 #endif
 #ifdef NIS
@@ -513,24 +512,22 @@ inithostmaps()
                    stab("aliases.nis", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "aliases.nis nis -d mail.aliases");
                    stab("aliases.nis", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "aliases.nis nis -d mail.aliases");
-                       makemapentry(buf);
+                       (void) makemapentry(buf);
+               }
+#endif
+#ifdef HESIOD
+               else if (strcmp(maptype[i], "hesiod") == 0 &&
+                   stab("aliases.hesiod", ST_MAP, ST_FIND) == NULL)
+               {
+                       strcpy(buf, "aliases.hesiod hesiod aliases");
+                       (void) makemapentry(buf);
                }
 #endif
        }
                }
 #endif
        }
-       s = stab("aliases", ST_MAP, ST_FIND);
-       if (s == NULL)
+       if (stab("aliases", ST_MAP, ST_FIND) == NULL)
        {
                strcpy(buf, "aliases switch aliases");
        {
                strcpy(buf, "aliases switch aliases");
-               makemapentry(buf);
-               s = stab("aliases", ST_MAP, ST_FIND);
-       }
-       if (s == NULL)
-               syserr("inithostmaps: cannot initialize default aliases map");
-       else
-       {
-               extern MAP *AliasDB[MAXALIASDB + 1];
-
-               AliasDB[0] = &s->s_map;
+               (void) makemapentry(buf);
        }
 
 #if 0          /* "user" map class is a better choice */
        }
 
 #if 0          /* "user" map class is a better choice */
@@ -545,14 +542,14 @@ inithostmaps()
                    stab("users.files", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "users.files text -m -z: -k0 -v6 /etc/passwd");
                    stab("users.files", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "users.files text -m -z: -k0 -v6 /etc/passwd");
-                       makemapentry(buf);
+                       (void) makemapentry(buf);
                }
 #ifdef NISPLUS
                else if (strcmp(maptype[i], "nisplus") == 0 &&
                    stab("users.nisplus", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "users.nisplus nisplus -m -kname -vhome -d passwd.org_dir");
                }
 #ifdef NISPLUS
                else if (strcmp(maptype[i], "nisplus") == 0 &&
                    stab("users.nisplus", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "users.nisplus nisplus -m -kname -vhome -d passwd.org_dir");
-                       makemapentry(buf);
+                       (void) makemapentry(buf);
                }
 #endif
 #ifdef NIS
                }
 #endif
 #ifdef NIS
@@ -560,7 +557,7 @@ inithostmaps()
                    stab("users.nis", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "users.nis nis -m -d passwd.byname");
                    stab("users.nis", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "users.nis nis -m -d passwd.byname");
-                       makemapentry(buf);
+                       (void) makemapentry(buf);
                }
 #endif
 #ifdef HESIOD
                }
 #endif
 #ifdef HESIOD
@@ -568,14 +565,14 @@ inithostmaps()
                    stab("users.hesiod", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "users.hesiod hesiod");
                    stab("users.hesiod", ST_MAP, ST_FIND) == NULL)
                {
                        strcpy(buf, "users.hesiod hesiod");
-                       makemapentry(buf);
+                       (void) makemapentry(buf);
                }
 #endif
        }
        if (stab("users", ST_MAP, ST_FIND) == NULL)
        {
                strcpy(buf, "users switch -m passwd");
                }
 #endif
        }
        if (stab("users", ST_MAP, ST_FIND) == NULL)
        {
                strcpy(buf, "users switch -m passwd");
-               makemapentry(buf);
+               (void) makemapentry(buf);
        }
 #endif
 }
        }
 #endif
 }
index c54a2fe..0f056aa 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)readcf.c   8.96 (Berkeley) %G%";
+static char sccsid[] = "@(#)readcf.c   8.97 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -572,7 +572,7 @@ readcf(cfname)
                        break;
 
                  case 'K':
                        break;
 
                  case 'K':
-                       makemapentry(&bp[1]);
+                       (void) makemapentry(&bp[1]);
                        break;
 
                  case 'E':
                        break;
 
                  case 'E':
@@ -2136,13 +2136,14 @@ setclass(class, str)
 **             line -- the config file line
 **
 **     Returns:
 **             line -- the config file line
 **
 **     Returns:
-**             none.
+**             A pointer to the map that has been created.
+**             NULL if there was a syntax error.
 **
 **     Side Effects:
 **             Enters the map into the dictionary.
 */
 
 **
 **     Side Effects:
 **             Enters the map into the dictionary.
 */
 
-void
+MAP *
 makemapentry(line)
        char *line;
 {
 makemapentry(line)
        char *line;
 {
@@ -2157,7 +2158,7 @@ makemapentry(line)
        if (!(isascii(*p) && isalnum(*p)))
        {
                syserr("readcf: config K line: no map name");
        if (!(isascii(*p) && isalnum(*p)))
        {
                syserr("readcf: config K line: no map name");
-               return;
+               return NULL;
        }
 
        mapname = p;
        }
 
        mapname = p;
@@ -2170,7 +2171,7 @@ makemapentry(line)
        if (!(isascii(*p) && isalnum(*p)))
        {
                syserr("readcf: config K line, map %s: no map class", mapname);
        if (!(isascii(*p) && isalnum(*p)))
        {
                syserr("readcf: config K line, map %s: no map class", mapname);
-               return;
+               return NULL;
        }
        classname = p;
        while (isascii(*++p) && isalnum(*p))
        }
        classname = p;
        while (isascii(*++p) && isalnum(*p))
@@ -2185,7 +2186,7 @@ makemapentry(line)
        if (class == NULL)
        {
                syserr("readcf: map %s: class %s not available", mapname, classname);
        if (class == NULL)
        {
                syserr("readcf: map %s: class %s not available", mapname, classname);
-               return;
+               return NULL;
        }
 
        /* enter the map */
        }
 
        /* enter the map */
@@ -2207,6 +2208,8 @@ makemapentry(line)
                        s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain,
                        s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild);
        }
                        s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain,
                        s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild);
        }
+
+       return &s->s_map;
 }
 \f/*
 **  INITTIMEOUTS -- parse and set timeout values
 }
 \f/*
 **  INITTIMEOUTS -- parse and set timeout values