generalize udbsender in anticipation of UDB map classes
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Thu, 26 Aug 1993 04:19:41 +0000 (20:19 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Thu, 26 Aug 1993 04:19:41 +0000 (20:19 -0800)
SCCS-vsn: usr.sbin/sendmail/src/udb.c 8.3

usr/src/usr.sbin/sendmail/src/udb.c

index 1bafd81..483cd80 100644 (file)
@@ -10,9 +10,9 @@
 
 #ifndef lint
 #ifdef USERDB
 
 #ifndef lint
 #ifdef USERDB
-static char sccsid [] = "@(#)udb.c     8.2 (Berkeley) %G% (with USERDB)";
+static char sccsid [] = "@(#)udb.c     8.3 (Berkeley) %G% (with USERDB)";
 #else
 #else
-static char sccsid [] = "@(#)udb.c     8.2 (Berkeley) %G% (without USERDB)";
+static char sccsid [] = "@(#)udb.c     8.3 (Berkeley) %G% (without USERDB)";
 #endif
 #endif
 
 #endif
 #endif
 
@@ -321,6 +321,17 @@ udbexpand(a, sendq, e)
 char *
 udbsender(sender)
        char *sender;
 char *
 udbsender(sender)
        char *sender;
+{
+       extern char *udbmatch();
+
+       return udbmatch(sender, "mailname");
+}
+
+
+char *
+udbmatch(user, field)
+       char *user;
+       char *field;
 {
        register char *p;
        register struct udbent *up;
 {
        register char *p;
        register struct udbent *up;
@@ -330,7 +341,7 @@ udbsender(sender)
        char keybuf[MAXKEY];
 
        if (tTd(28, 1))
        char keybuf[MAXKEY];
 
        if (tTd(28, 1))
-               printf("udbsender(%s)\n", sender);
+               printf("udbmatch(%s, %s)\n", user, field);
 
        if (!UdbInitialized)
        {
 
        if (!UdbInitialized)
        {
@@ -343,16 +354,17 @@ udbsender(sender)
                return NULL;
 
        /* long names can never match and are a pain to deal with */
                return NULL;
 
        /* long names can never match and are a pain to deal with */
-       if (strlen(sender) > sizeof keybuf - 12)
+       if ((strlen(user) + strlen(field)) > sizeof keybuf - 4)
                return NULL;
 
        /* names beginning with colons indicate metadata */
                return NULL;
 
        /* names beginning with colons indicate metadata */
-       if (sender[0] == ':')
+       if (user[0] == ':')
                return NULL;
 
        /* build database key */
                return NULL;
 
        /* build database key */
-       (void) strcpy(keybuf, sender);
-       (void) strcat(keybuf, ":mailname");
+       (void) strcpy(keybuf, user);
+       (void) strcat(keybuf, ":");
+       (void) strcat(keybuf, field);
        keylen = strlen(keybuf);
 
        for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++)
        keylen = strlen(keybuf);
 
        for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++)
@@ -370,7 +382,7 @@ udbsender(sender)
                        if (i != 0 || info.size <= 0)
                        {
                                if (tTd(28, 2))
                        if (i != 0 || info.size <= 0)
                        {
                                if (tTd(28, 2))
-                                       printf("udbsender: no match on %s (%d)\n",
+                                       printf("udbmatch: no match on %s (%d)\n",
                                                        keybuf, keylen);
                                continue;
                        }
                                                        keybuf, keylen);
                                continue;
                        }
@@ -379,11 +391,14 @@ udbsender(sender)
                        bcopy(info.data, p, info.size);
                        p[info.size] = '\0';
                        if (tTd(28, 1))
                        bcopy(info.data, p, info.size);
                        p[info.size] = '\0';
                        if (tTd(28, 1))
-                               printf("udbsender ==> %s\n", p);
+                               printf("udbmatch ==> %s\n", p);
                        return p;
                }
        }
 
                        return p;
                }
        }
 
+       if (strcmp(field, "mailname") != 0)
+               return NULL;
+
        /*
        **  Nothing yet.  Search again for a default case.  But only
        **  use it if we also have a forward (:maildrop) pointer already
        /*
        **  Nothing yet.  Search again for a default case.  But only
        **  use it if we also have a forward (:maildrop) pointer already
@@ -391,7 +406,7 @@ udbsender(sender)
        */
 
        /* build database key */
        */
 
        /* build database key */
-       (void) strcpy(keybuf, sender);
+       (void) strcpy(keybuf, user);
        (void) strcat(keybuf, ":maildrop");
        keylen = strlen(keybuf);
 
        (void) strcat(keybuf, ":maildrop");
        keylen = strlen(keybuf);
 
@@ -432,12 +447,12 @@ udbsender(sender)
                        }
 
                        /* they exist -- build the actual address */
                        }
 
                        /* they exist -- build the actual address */
-                       p = xalloc(strlen(sender) + strlen(up->udb_default) + 2);
-                       (void) strcpy(p, sender);
+                       p = xalloc(strlen(user) + strlen(up->udb_default) + 2);
+                       (void) strcpy(p, user);
                        (void) strcat(p, "@");
                        (void) strcat(p, up->udb_default);
                        if (tTd(28, 1))
                        (void) strcat(p, "@");
                        (void) strcat(p, up->udb_default);
                        if (tTd(28, 1))
-                               printf("udbsender ==> %s\n", p);
+                               printf("udbmatch ==> %s\n", p);
                        return p;
                }
        }
                        return p;
                }
        }