150581Seric /* 250581Seric * Copyright (c) 1983 Eric P. Allman 350581Seric * Copyright (c) 1988 Regents of the University of California. 450581Seric * All rights reserved. 550581Seric * 650581Seric * %sccs.include.redist.c% 750581Seric */ 850581Seric 950581Seric #ifndef lint 1051360Seric #ifdef USERDB 11*60494Seric static char sccsid [] = "@(#)udb.c 6.21 (Berkeley) 05/27/93 (with USERDB)"; 1251360Seric #else 13*60494Seric static char sccsid [] = "@(#)udb.c 6.21 (Berkeley) 05/27/93 (without USERDB)"; 1450581Seric #endif 1551360Seric #endif 1650581Seric 1750581Seric #include "sendmail.h" 1850581Seric 1950581Seric #ifdef USERDB 2050581Seric 2151360Seric #include <sys/time.h> 2251923Seric #include <errno.h> 2351360Seric #include <netdb.h> 2450581Seric #include <db.h> 2550581Seric 2650581Seric /* 2753654Seric ** UDB.C -- interface between sendmail and Berkeley User Data Base. 2850581Seric ** 2951363Seric ** This depends on the 4.4BSD db package. 3050581Seric */ 3150581Seric 3251362Seric 3351360Seric struct udbent 3451360Seric { 3551360Seric char *udb_spec; /* string version of spec */ 3651360Seric int udb_type; /* type of entry */ 3751951Seric char *udb_default; /* default host for outgoing mail */ 3851360Seric union 3951360Seric { 4051360Seric /* type UE_REMOTE -- do remote call for lookup */ 4151360Seric struct 4251360Seric { 4351360Seric struct sockaddr_in _udb_addr; /* address */ 4451360Seric int _udb_timeout; /* timeout */ 4551360Seric } udb_remote; 4651360Seric #define udb_addr udb_u.udb_remote._udb_addr 4751360Seric #define udb_timeout udb_u.udb_remote._udb_timeout 4851360Seric 4951360Seric /* type UE_FORWARD -- forward message to remote */ 5051360Seric struct 5151360Seric { 5251360Seric char *_udb_fwdhost; /* name of forward host */ 5351360Seric } udb_forward; 5451360Seric #define udb_fwdhost udb_u.udb_forward._udb_fwdhost 5551360Seric 5651951Seric /* type UE_FETCH -- lookup in local database */ 5751360Seric struct 5851360Seric { 5951360Seric char *_udb_dbname; /* pathname of database */ 6051360Seric DB *_udb_dbp; /* open database ptr */ 6151360Seric } udb_lookup; 6251360Seric #define udb_dbname udb_u.udb_lookup._udb_dbname 6351360Seric #define udb_dbp udb_u.udb_lookup._udb_dbp 6451360Seric } udb_u; 6551360Seric }; 6651360Seric 6751360Seric #define UDB_EOLIST 0 /* end of list */ 6851360Seric #define UDB_SKIP 1 /* skip this entry */ 6951360Seric #define UDB_REMOTE 2 /* look up in remote database */ 7051951Seric #define UDB_DBFETCH 3 /* look up in local database */ 7151360Seric #define UDB_FORWARD 4 /* forward to remote host */ 7251360Seric 7351360Seric #define MAXUDBENT 10 /* maximum number of UDB entries */ 7451360Seric 7551363Seric 7651363Seric struct option 7751363Seric { 7851363Seric char *name; 7951363Seric char *val; 8051363Seric }; 8151363Seric /* 8251363Seric ** UDBEXPAND -- look up user in database and expand 8351363Seric ** 8451363Seric ** Parameters: 8551363Seric ** a -- address to expand. 8651363Seric ** sendq -- pointer to head of sendq to put the expansions in. 8751363Seric ** 8851363Seric ** Returns: 8951923Seric ** EX_TEMPFAIL -- if something "odd" happened -- probably due 9051923Seric ** to accessing a file on an NFS server that is down. 9151923Seric ** EX_OK -- otherwise. 9251363Seric ** 9351363Seric ** Side Effects: 9451363Seric ** Modifies sendq. 9551363Seric */ 9651363Seric 9751363Seric int UdbPort = 1616; 9851363Seric int UdbTimeout = 10; 9951363Seric 10051953Seric struct udbent UdbEnts[MAXUDBENT + 1]; 10151953Seric int UdbSock = -1; 10251953Seric bool UdbInitialized = FALSE; 10351360Seric 10451923Seric int 10555012Seric udbexpand(a, sendq, e) 10650581Seric register ADDRESS *a; 10750581Seric ADDRESS **sendq; 10855012Seric register ENVELOPE *e; 10950581Seric { 11050581Seric int i; 11150581Seric register char *p; 11250581Seric DBT key; 11350581Seric DBT info; 11451360Seric bool breakout; 11551360Seric register struct udbent *up; 11651362Seric int keylen; 11758082Seric int naddrs; 11857232Seric char keybuf[MAXKEY]; 11957232Seric char buf[BUFSIZ]; 12050581Seric 12150581Seric if (tTd(28, 1)) 12258065Seric printf("udbexpand(%s)\n", a->q_paddr); 12350581Seric 12450581Seric /* make certain we are supposed to send to this address */ 12558154Seric if (bitset(QDONTSEND|QVERIFIED, a->q_flags)) 12651923Seric return EX_OK; 12755012Seric e->e_to = a->q_paddr; 12850581Seric 12951360Seric /* on first call, locate the database */ 13051951Seric if (!UdbInitialized) 13150581Seric { 13251923Seric extern int _udbx_init(); 13351362Seric 13451923Seric if (_udbx_init() == EX_TEMPFAIL) 13551923Seric return EX_TEMPFAIL; 13651362Seric } 13750581Seric 13851909Seric /* short circuit the process if no chance of a match */ 13951909Seric if (UdbSpec == NULL || UdbSpec[0] == '\0') 14051923Seric return EX_OK; 14151909Seric 14251362Seric /* if name is too long, assume it won't match */ 14351362Seric if (strlen(a->q_user) > sizeof keybuf - 12) 14451923Seric return EX_OK; 14551360Seric 14651362Seric /* if name begins with a colon, it indicates our metadata */ 14751362Seric if (a->q_user[0] == ':') 14851923Seric return EX_OK; 14951360Seric 15051362Seric /* build actual database key */ 15151362Seric (void) strcpy(keybuf, a->q_user); 15251362Seric (void) strcat(keybuf, ":maildrop"); 15351362Seric keylen = strlen(keybuf); 15451360Seric 15551360Seric breakout = FALSE; 15651362Seric for (up = UdbEnts; !breakout; up++) 15750581Seric { 15851360Seric char *user; 15950581Seric 16051360Seric /* 16151360Seric ** Select action based on entry type. 16251360Seric ** 16351360Seric ** On dropping out of this switch, "class" should 16451360Seric ** explain the type of the data, and "user" should 16551360Seric ** contain the user information. 16651360Seric */ 16750581Seric 16851360Seric switch (up->udb_type) 16951360Seric { 17051951Seric case UDB_DBFETCH: 17151362Seric key.data = keybuf; 17251362Seric key.size = keylen; 17351362Seric i = (*up->udb_dbp->seq)(up->udb_dbp, &key, &info, R_CURSOR); 17451923Seric if (i > 0 || info.size <= 0) 17551360Seric { 17651360Seric if (tTd(28, 2)) 17758065Seric printf("udbexpand: no match on %s\n", keybuf); 17851360Seric continue; 17951360Seric } 18050581Seric 18158082Seric naddrs = 0; 18258082Seric a->q_flags &= ~QSELFREF; 18351830Seric while (i == 0 && key.size == keylen && 18451830Seric bcmp(key.data, keybuf, keylen) == 0) 18551362Seric { 18658099Seric if (bitset(EF_VRFYONLY, e->e_flags)) 18758154Seric { 18858154Seric a->q_flags |= QVERIFIED; 18958884Seric e->e_nrcpts++; 19058099Seric return EX_OK; 19158154Seric } 19258099Seric 19351830Seric breakout = TRUE; 19451362Seric if (info.size < sizeof buf) 19551362Seric user = buf; 19651362Seric else 19751362Seric user = xalloc(info.size + 1); 19851362Seric bcopy(info.data, user, info.size); 19951362Seric user[info.size] = '\0'; 20050581Seric 20158151Seric message("expanded to %s", user); 20257977Seric #ifdef LOG 20357977Seric if (LogLevel >= 10) 20457977Seric syslog(LOG_INFO, "%s: expand %s => %s", 20557977Seric e->e_id, e->e_to, user); 20657977Seric #endif 20751362Seric AliasLevel++; 20858082Seric naddrs += sendtolist(user, a, sendq, e); 20951362Seric AliasLevel--; 21051362Seric 21151362Seric if (user != buf) 21251362Seric free(user); 21351362Seric 21451362Seric /* get the next record */ 21551362Seric i = (*up->udb_dbp->seq)(up->udb_dbp, &key, &info, R_NEXT); 21651830Seric } 21758082Seric if (naddrs > 0 && !bitset(QSELFREF, a->q_flags)) 21858065Seric { 21958065Seric if (tTd(28, 5)) 22058065Seric { 22158065Seric printf("udbexpand: QDONTSEND "); 22258065Seric printaddr(a, FALSE); 22358065Seric } 22458065Seric a->q_flags |= QDONTSEND; 22558065Seric } 22651923Seric if (i < 0) 22751923Seric { 22858010Seric syserr("udbexpand: db-get %.*s stat %d", 22958010Seric key.size, key.data, i); 23051923Seric return EX_TEMPFAIL; 23151923Seric } 23259707Seric 23359707Seric /* 23459707Seric ** If this address has a -request address, reflect 23559707Seric ** it into the envelope. 23659707Seric */ 23759707Seric 23859707Seric (void) strcpy(keybuf, a->q_user); 23959707Seric (void) strcat(keybuf, ":mailsender"); 24059707Seric keylen = strlen(keybuf); 24159707Seric key.data = keybuf; 24259707Seric key.size = keylen; 24359707Seric i = (*up->udb_dbp->get)(up->udb_dbp, &key, &info, 0); 24459707Seric if (i != 0 || info.size <= 0) 24559707Seric break; 24659707Seric a->q_owner = xalloc(info.size + 1); 24759707Seric bcopy(info.data, a->q_owner, info.size); 24859707Seric a->q_owner[info.size] = '\0'; 24951360Seric break; 25051360Seric 25151360Seric case UDB_REMOTE: 25251741Seric /* not yet implemented */ 25351741Seric continue; 25451362Seric 25551360Seric case UDB_FORWARD: 25658099Seric if (bitset(EF_VRFYONLY, e->e_flags)) 25758099Seric return EX_OK; 25851360Seric i = strlen(up->udb_fwdhost) + strlen(a->q_user) + 1; 25951360Seric if (i < sizeof buf) 26051360Seric user = buf; 26151360Seric else 26251360Seric user = xalloc(i + 1); 26351360Seric (void) sprintf(user, "%s@%s", a->q_user, up->udb_fwdhost); 26458151Seric message("expanded to %s", user); 26558082Seric a->q_flags &= ~QSELFREF; 26651362Seric AliasLevel++; 26758082Seric naddrs = sendtolist(user, a, sendq, e); 26851362Seric AliasLevel--; 26958082Seric if (naddrs > 0 && !bitset(QSELFREF, a->q_flags)) 27058065Seric { 27158065Seric if (tTd(28, 5)) 27258065Seric { 27358065Seric printf("udbexpand: QDONTSEND "); 27458065Seric printaddr(a, FALSE); 27558065Seric } 27658065Seric a->q_flags |= QDONTSEND; 27758065Seric } 27851362Seric if (user != buf) 27951362Seric free(user); 28051362Seric breakout = TRUE; 28151360Seric break; 28251360Seric 28351360Seric case UDB_EOLIST: 28451360Seric breakout = TRUE; 28551360Seric continue; 28651360Seric 28751360Seric default: 28851360Seric /* unknown entry type */ 28951360Seric continue; 29051360Seric } 29151362Seric } 29251923Seric return EX_OK; 29351362Seric } 29451951Seric /* 29551951Seric ** UDBSENDER -- return canonical external name of sender, given local name 29651951Seric ** 29751951Seric ** Parameters: 29851951Seric ** sender -- the name of the sender on the local machine. 29951951Seric ** 30051951Seric ** Returns: 30151951Seric ** The external name for this sender, if derivable from the 30251951Seric ** database. 30351951Seric ** NULL -- if nothing is changed from the database. 30451951Seric ** 30551951Seric ** Side Effects: 30651951Seric ** none. 30751951Seric */ 30851360Seric 30951951Seric char * 31051951Seric udbsender(sender) 31151951Seric char *sender; 31251951Seric { 31351951Seric register char *p; 31451951Seric register struct udbent *up; 31551951Seric int i; 31651951Seric int keylen; 31751951Seric DBT key, info; 31857232Seric char keybuf[MAXKEY]; 31951951Seric 32051951Seric if (tTd(28, 1)) 32151951Seric printf("udbsender(%s)\n", sender); 32251951Seric 32351951Seric if (!UdbInitialized) 32451951Seric { 32551951Seric if (_udbx_init() == EX_TEMPFAIL) 32651951Seric return NULL; 32751951Seric } 32851951Seric 32951951Seric /* short circuit if no spec */ 33051951Seric if (UdbSpec == NULL || UdbSpec[0] == '\0') 33151951Seric return NULL; 33251951Seric 33351951Seric /* long names can never match and are a pain to deal with */ 33451951Seric if (strlen(sender) > sizeof keybuf - 12) 33551951Seric return NULL; 33651951Seric 33751951Seric /* names beginning with colons indicate metadata */ 33851951Seric if (sender[0] == ':') 33951951Seric return NULL; 34051951Seric 34151951Seric /* build database key */ 34251951Seric (void) strcpy(keybuf, sender); 34351951Seric (void) strcat(keybuf, ":mailname"); 34451951Seric keylen = strlen(keybuf); 34551951Seric 34651951Seric for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++) 34751951Seric { 34851951Seric /* 34951951Seric ** Select action based on entry type. 35051951Seric */ 35151951Seric 35251951Seric switch (up->udb_type) 35351951Seric { 35451951Seric case UDB_DBFETCH: 35551951Seric key.data = keybuf; 35651951Seric key.size = keylen; 35751951Seric i = (*up->udb_dbp->get)(up->udb_dbp, &key, &info, 0); 35851951Seric if (i != 0 || info.size <= 0) 35951951Seric { 36051951Seric if (tTd(28, 2)) 36151951Seric printf("udbsender: no match on %s\n", 36251951Seric keybuf); 36351951Seric continue; 36451951Seric } 36551951Seric 36651951Seric p = xalloc(info.size + 1); 36751951Seric bcopy(info.data, p, info.size); 36851951Seric p[info.size] = '\0'; 36951951Seric if (tTd(28, 1)) 37051951Seric printf("udbsender ==> %s\n", p); 37151951Seric return p; 37251951Seric } 37351951Seric } 37451951Seric 37551951Seric /* 37651951Seric ** Nothing yet. Search again for a default case. But only 37751951Seric ** use it if we also have a forward (:maildrop) pointer already 37851951Seric ** in the database. 37951951Seric */ 38051951Seric 38151951Seric /* build database key */ 38251951Seric (void) strcpy(keybuf, sender); 38351951Seric (void) strcat(keybuf, ":maildrop"); 38451951Seric keylen = strlen(keybuf); 38551951Seric 38651951Seric for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++) 38751951Seric { 38851951Seric switch (up->udb_type) 38951951Seric { 39051951Seric case UDB_DBFETCH: 39151951Seric /* get the default case for this database */ 39251951Seric if (up->udb_default == NULL) 39351951Seric { 39451951Seric key.data = ":default:mailname"; 39551951Seric key.size = strlen(key.data); 39651951Seric i = (*up->udb_dbp->get)(up->udb_dbp, &key, &info, 0); 39751951Seric if (i != 0 || info.size <= 0) 39851951Seric { 39951951Seric /* no default case */ 40051951Seric up->udb_default = ""; 40151951Seric continue; 40251951Seric } 40351951Seric 40451951Seric /* save the default case */ 40551951Seric up->udb_default = xalloc(info.size + 1); 40651951Seric bcopy(info.data, up->udb_default, info.size); 40751951Seric up->udb_default[info.size] = '\0'; 40851951Seric } 40951951Seric else if (up->udb_default[0] == '\0') 41051951Seric continue; 41151951Seric 41251951Seric /* we have a default case -- verify user:maildrop */ 41351951Seric key.data = keybuf; 41451951Seric key.size = keylen; 41551951Seric i = (*up->udb_dbp->get)(up->udb_dbp, &key, &info, 0); 41651951Seric if (i != 0 || info.size <= 0) 41751951Seric { 41851951Seric /* nope -- no aliasing for this user */ 41951951Seric continue; 42051951Seric } 42151951Seric 42251951Seric /* they exist -- build the actual address */ 42351951Seric p = xalloc(strlen(sender) + strlen(up->udb_default) + 2); 42451951Seric (void) strcpy(p, sender); 42551951Seric (void) strcat(p, "@"); 42651951Seric (void) strcat(p, up->udb_default); 42751951Seric if (tTd(28, 1)) 42851951Seric printf("udbsender ==> %s\n", p); 42951951Seric return p; 43051951Seric } 43151951Seric } 43251951Seric 43351951Seric /* still nothing.... too bad */ 43451951Seric return NULL; 43551951Seric } 43651951Seric /* 43751951Seric ** _UDBX_INIT -- parse the UDB specification, opening any valid entries. 43851951Seric ** 43951951Seric ** Parameters: 44051951Seric ** none. 44151951Seric ** 44251951Seric ** Returns: 44351951Seric ** EX_TEMPFAIL -- if it appeared it couldn't get hold of a 44451951Seric ** database due to a host being down or some similar 44551951Seric ** (recoverable) situation. 44651951Seric ** EX_OK -- otherwise. 44751951Seric ** 44851951Seric ** Side Effects: 44951951Seric ** Fills in the UdbEnts structure from UdbSpec. 45051951Seric */ 45151951Seric 45251363Seric #define MAXUDBOPTS 27 45351363Seric 45451953Seric int 45551362Seric _udbx_init() 45651362Seric { 45751362Seric register char *p; 45851362Seric int i; 45951362Seric register struct udbent *up; 46057232Seric char buf[BUFSIZ]; 46151360Seric 46251951Seric if (UdbInitialized) 46351951Seric return EX_OK; 46451951Seric 46551908Seric # ifdef UDB_DEFAULT_SPEC 46651908Seric if (UdbSpec == NULL) 46751908Seric UdbSpec = UDB_DEFAULT_SPEC; 46851908Seric # endif 46951908Seric 47051362Seric p = UdbSpec; 47151362Seric up = UdbEnts; 47251762Seric while (p != NULL) 47351362Seric { 47451362Seric char *spec; 47551362Seric auto int rcode; 47651363Seric int nopts; 47751362Seric int nmx; 47851362Seric register struct hostent *h; 47951362Seric char *mxhosts[MAXMXHOSTS + 1]; 48051363Seric struct option opts[MAXUDBOPTS + 1]; 48151362Seric 48251362Seric while (*p == ' ' || *p == '\t' || *p == ',') 48351362Seric p++; 48451362Seric if (*p == '\0') 48551362Seric break; 48651362Seric spec = p; 48756795Seric p = strchr(p, ','); 48851761Seric if (p != NULL) 48951362Seric *p++ = '\0'; 49051363Seric 49151363Seric /* extract options */ 49251363Seric nopts = _udb_parsespec(spec, opts, MAXUDBOPTS); 49351363Seric 49451363Seric /* 49551363Seric ** Decode database specification. 49651363Seric ** 49751363Seric ** In the sendmail tradition, the leading character 49851363Seric ** defines the semantics of the rest of the entry. 49951363Seric ** 50051363Seric ** +hostname -- send a datagram to the udb server 50151363Seric ** on host "hostname" asking for the 50251363Seric ** home mail server for this user. 50351363Seric ** *hostname -- similar to +hostname, except that the 50451363Seric ** hostname is searched as an MX record; 50551363Seric ** resulting hosts are searched as for 50651363Seric ** +mxhostname. If no MX host is found, 50751363Seric ** this is the same as +hostname. 50851363Seric ** @hostname -- forward email to the indicated host. 50951363Seric ** This should be the last in the list, 51051363Seric ** since it always matches the input. 51151363Seric ** /dbname -- search the named database on the local 51251363Seric ** host using the Berkeley db package. 51351363Seric */ 51451363Seric 51551362Seric switch (*spec) 51651360Seric { 51751362Seric case '+': /* search remote database */ 51851363Seric case '*': /* search remote database (expand MX) */ 51951363Seric if (*spec == '*') 52051363Seric { 52157629Seric #ifdef NAMED_BIND 52259273Seric nmx = getmxrr(spec + 1, mxhosts, FALSE, &rcode); 52357629Seric #else 52457629Seric mxhosts[0] = spec + 1; 52557629Seric nmx = 1; 52657629Seric rcode = 0; 52757629Seric #endif 52851363Seric if (tTd(28, 16)) 52951363Seric { 53051363Seric int i; 53151362Seric 53251363Seric printf("getmxrr(%s): %d", spec + 1, nmx); 53351363Seric for (i = 0; i <= nmx; i++) 53451363Seric printf(" %s", mxhosts[i]); 53551363Seric printf("\n"); 53651363Seric } 53751363Seric } 53851363Seric else 53951362Seric { 54051363Seric nmx = 1; 54151363Seric mxhosts[0] = spec + 1; 54251362Seric } 54351362Seric 54451362Seric for (i = 0; i < nmx; i++) 54551362Seric { 54651362Seric h = gethostbyname(mxhosts[i]); 54751362Seric if (h == NULL) 54851362Seric continue; 54951362Seric up->udb_type = UDB_REMOTE; 55051362Seric up->udb_addr.sin_family = h->h_addrtype; 55151362Seric bcopy(h->h_addr_list[0], 55251362Seric (char *) &up->udb_addr.sin_addr, 55351362Seric h->h_length); 55451362Seric up->udb_addr.sin_port = UdbPort; 55551362Seric up->udb_timeout = UdbTimeout; 55651362Seric up++; 55751362Seric } 55851362Seric 55951362Seric /* set up a datagram socket */ 56051362Seric if (UdbSock < 0) 56151362Seric { 56251362Seric UdbSock = socket(AF_INET, SOCK_DGRAM, 0); 56351362Seric (void) fcntl(UdbSock, F_SETFD, 1); 56451362Seric } 56551362Seric break; 56651362Seric 56751362Seric case '@': /* forward to remote host */ 56851362Seric up->udb_type = UDB_FORWARD; 56951362Seric up->udb_fwdhost = spec + 1; 57051362Seric up++; 57151362Seric break; 57251362Seric 57351362Seric case '/': /* look up remote name */ 57451831Seric up->udb_dbname = spec; 57551923Seric errno = 0; 57651362Seric up->udb_dbp = dbopen(spec, O_RDONLY, 0644, DB_BTREE, NULL); 57751362Seric if (up->udb_dbp == NULL) 57851923Seric { 57951923Seric if (errno != ENOENT && errno != EACCES) 58051951Seric { 58159615Seric #ifdef LOG 58259615Seric if (LogLevel > 2) 58359625Seric syslog(LOG_ERR, "dbopen(%s): %s", 58459625Seric spec, errstring(errno)); 58559615Seric #endif 58651951Seric up->udb_type = UDB_EOLIST; 58751951Seric goto tempfail; 58851951Seric } 58951362Seric break; 59051923Seric } 59151951Seric up->udb_type = UDB_DBFETCH; 59251362Seric up++; 59351362Seric break; 59451360Seric } 59551362Seric } 59651362Seric up->udb_type = UDB_EOLIST; 59751360Seric 59851362Seric if (tTd(28, 4)) 59951362Seric { 60051951Seric for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++) 60151360Seric { 60251362Seric switch (up->udb_type) 60351362Seric { 60451362Seric case UDB_REMOTE: 60551362Seric printf("REMOTE: addr %s, timeo %d\n", 606*60494Seric anynet_ntoa((SOCKADDR *) &up->udb_addr), 60751362Seric up->udb_timeout); 60851362Seric break; 60951362Seric 61051951Seric case UDB_DBFETCH: 61151951Seric printf("FETCH: file %s\n", 61251830Seric up->udb_dbname); 61351362Seric break; 61451362Seric 61551362Seric case UDB_FORWARD: 61651362Seric printf("FORWARD: host %s\n", 61751362Seric up->udb_fwdhost); 61851362Seric break; 61951362Seric 62051362Seric default: 62151362Seric printf("UNKNOWN\n"); 62251362Seric break; 62351362Seric } 62451360Seric } 62550581Seric } 62651951Seric 62751951Seric UdbInitialized = TRUE; 62851955Seric errno = 0; 62951951Seric return EX_OK; 63051951Seric 63151951Seric /* 63251951Seric ** On temporary failure, back out anything we've already done 63351951Seric */ 63451951Seric 63551951Seric tempfail: 63651951Seric for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++) 63751951Seric { 63851951Seric if (up->udb_type == UDB_DBFETCH) 63951951Seric { 64051951Seric (*up->udb_dbp->close)(up->udb_dbp); 64151951Seric } 64251951Seric } 64351951Seric return EX_TEMPFAIL; 64451360Seric } 64550581Seric 64651363Seric int 64751363Seric _udb_parsespec(udbspec, opt, maxopts) 64851363Seric char *udbspec; 64951363Seric struct option opt[]; 65051363Seric int maxopts; 65151363Seric { 65251363Seric register char *spec; 65351363Seric register char *spec_end; 65451363Seric register int optnum; 65551363Seric 65656795Seric spec_end = strchr(udbspec, ':'); 65751363Seric for (optnum = 0; optnum < maxopts && (spec = spec_end) != NULL; optnum++) 65851363Seric { 65951363Seric register char *p; 66051363Seric 66158050Seric while (isascii(*spec) && isspace(*spec)) 66251363Seric spec++; 66356795Seric spec_end = strchr(spec, ':'); 66451363Seric if (spec_end != NULL) 66551363Seric *spec_end++ = '\0'; 66651363Seric 66751363Seric opt[optnum].name = spec; 66851363Seric opt[optnum].val = NULL; 66956795Seric p = strchr(spec, '='); 67051363Seric if (p != NULL) 67151363Seric opt[optnum].val = ++p; 67251363Seric } 67351363Seric return optnum; 67451363Seric } 67551363Seric 67651360Seric #else /* not USERDB */ 67751360Seric 67851923Seric int 67955012Seric udbexpand(a, sendq, e) 68051360Seric ADDRESS *a; 68151360Seric ADDRESS **sendq; 68255012Seric ENVELOPE *e; 68351360Seric { 68451923Seric return EX_OK; 68550581Seric } 68650581Seric 68750581Seric #endif /* USERDB */ 688