From e5736fa7534d2ad9d87f176770464d55b5069edc Mon Sep 17 00:00:00 2001 From: Eric Allman Date: Wed, 25 Aug 1993 20:19:41 -0800 Subject: [PATCH] generalize udbsender in anticipation of UDB map classes SCCS-vsn: usr.sbin/sendmail/src/udb.c 8.3 --- usr/src/usr.sbin/sendmail/src/udb.c | 41 ++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/usr/src/usr.sbin/sendmail/src/udb.c b/usr/src/usr.sbin/sendmail/src/udb.c index 1bafd811f6..483cd8045d 100644 --- a/usr/src/usr.sbin/sendmail/src/udb.c +++ b/usr/src/usr.sbin/sendmail/src/udb.c @@ -10,9 +10,9 @@ #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 -static char sccsid [] = "@(#)udb.c 8.2 (Berkeley) %G% (without USERDB)"; +static char sccsid [] = "@(#)udb.c 8.3 (Berkeley) %G% (without USERDB)"; #endif #endif @@ -321,6 +321,17 @@ udbexpand(a, sendq, e) 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; @@ -330,7 +341,7 @@ udbsender(sender) char keybuf[MAXKEY]; if (tTd(28, 1)) - printf("udbsender(%s)\n", sender); + printf("udbmatch(%s, %s)\n", user, field); if (!UdbInitialized) { @@ -343,16 +354,17 @@ udbsender(sender) 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 */ - if (sender[0] == ':') + if (user[0] == ':') 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++) @@ -370,7 +382,7 @@ udbsender(sender) 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; } @@ -379,11 +391,14 @@ udbsender(sender) 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; } } + 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 @@ -391,7 +406,7 @@ udbsender(sender) */ /* build database key */ - (void) strcpy(keybuf, sender); + (void) strcpy(keybuf, user); (void) strcat(keybuf, ":maildrop"); keylen = strlen(keybuf); @@ -432,12 +447,12 @@ udbsender(sender) } /* 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)) - printf("udbsender ==> %s\n", p); + printf("udbmatch ==> %s\n", p); return p; } } -- 2.20.1