xref: /csrg-svn/usr.sbin/sendmail/src/udb.c (revision 58755)
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*58755Seric static char sccsid [] = "@(#)udb.c	6.14 (Berkeley) 03/19/93 (with USERDB)";
1251360Seric #else
13*58755Seric static char sccsid [] = "@(#)udb.c	6.14 (Berkeley) 03/19/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;
18958099Seric 					return EX_OK;
19058154Seric 				}
19158099Seric 
19251830Seric 				breakout = TRUE;
19351362Seric 				if (info.size < sizeof buf)
19451362Seric 					user = buf;
19551362Seric 				else
19651362Seric 					user = xalloc(info.size + 1);
19751362Seric 				bcopy(info.data, user, info.size);
19851362Seric 				user[info.size] = '\0';
19950581Seric 
20058151Seric 				message("expanded to %s", user);
20157977Seric #ifdef LOG
20257977Seric 				if (LogLevel >= 10)
20357977Seric 					syslog(LOG_INFO, "%s: expand %s => %s",
20457977Seric 						e->e_id, e->e_to, user);
20557977Seric #endif
20651362Seric 				AliasLevel++;
20758082Seric 				naddrs += sendtolist(user, a, sendq, e);
20851362Seric 				AliasLevel--;
20951362Seric 
21051362Seric 				if (user != buf)
21151362Seric 					free(user);
21251362Seric 
21351362Seric 				/* get the next record */
21451362Seric 				i = (*up->udb_dbp->seq)(up->udb_dbp, &key, &info, R_NEXT);
21551830Seric 			}
21658082Seric 			if (naddrs > 0 && !bitset(QSELFREF, a->q_flags))
21758065Seric 			{
21858065Seric 				if (tTd(28, 5))
21958065Seric 				{
22058065Seric 					printf("udbexpand: QDONTSEND ");
22158065Seric 					printaddr(a, FALSE);
22258065Seric 				}
22358065Seric 				a->q_flags |= QDONTSEND;
22458065Seric 			}
22551923Seric 			if (i < 0)
22651923Seric 			{
22758010Seric 				syserr("udbexpand: db-get %.*s stat %d",
22858010Seric 					key.size, key.data, i);
22951923Seric 				return EX_TEMPFAIL;
23051923Seric 			}
23151360Seric 			break;
23251360Seric 
23351360Seric 		  case UDB_REMOTE:
23451741Seric 			/* not yet implemented */
23551741Seric 			continue;
23651362Seric 
23751360Seric 		  case UDB_FORWARD:
23858099Seric 			if (bitset(EF_VRFYONLY, e->e_flags))
23958099Seric 				return EX_OK;
24051360Seric 			i = strlen(up->udb_fwdhost) + strlen(a->q_user) + 1;
24151360Seric 			if (i < sizeof buf)
24251360Seric 				user = buf;
24351360Seric 			else
24451360Seric 				user = xalloc(i + 1);
24551360Seric 			(void) sprintf(user, "%s@%s", a->q_user, up->udb_fwdhost);
24658151Seric 			message("expanded to %s", user);
24758082Seric 			a->q_flags &= ~QSELFREF;
24851362Seric 			AliasLevel++;
24958082Seric 			naddrs = sendtolist(user, a, sendq, e);
25051362Seric 			AliasLevel--;
25158082Seric 			if (naddrs > 0 && !bitset(QSELFREF, a->q_flags))
25258065Seric 			{
25358065Seric 				if (tTd(28, 5))
25458065Seric 				{
25558065Seric 					printf("udbexpand: QDONTSEND ");
25658065Seric 					printaddr(a, FALSE);
25758065Seric 				}
25858065Seric 				a->q_flags |= QDONTSEND;
25958065Seric 			}
26051362Seric 			if (user != buf)
26151362Seric 				free(user);
26251362Seric 			breakout = TRUE;
26351360Seric 			break;
26451360Seric 
26551360Seric 		  case UDB_EOLIST:
26651360Seric 			breakout = TRUE;
26751360Seric 			continue;
26851360Seric 
26951360Seric 		  default:
27051360Seric 			/* unknown entry type */
27151360Seric 			continue;
27251360Seric 		}
27351362Seric 	}
27451923Seric 	return EX_OK;
27551362Seric }
27651951Seric /*
27751951Seric **  UDBSENDER -- return canonical external name of sender, given local name
27851951Seric **
27951951Seric **	Parameters:
28051951Seric **		sender -- the name of the sender on the local machine.
28151951Seric **
28251951Seric **	Returns:
28351951Seric **		The external name for this sender, if derivable from the
28451951Seric **			database.
28551951Seric **		NULL -- if nothing is changed from the database.
28651951Seric **
28751951Seric **	Side Effects:
28851951Seric **		none.
28951951Seric */
29051360Seric 
29151951Seric char *
29251951Seric udbsender(sender)
29351951Seric 	char *sender;
29451951Seric {
29551951Seric 	register char *p;
29651951Seric 	register struct udbent *up;
29751951Seric 	int i;
29851951Seric 	int keylen;
29951951Seric 	DBT key, info;
30057232Seric 	char keybuf[MAXKEY];
30151951Seric 
30251951Seric 	if (tTd(28, 1))
30351951Seric 		printf("udbsender(%s)\n", sender);
30451951Seric 
30551951Seric 	if (!UdbInitialized)
30651951Seric 	{
30751951Seric 		if (_udbx_init() == EX_TEMPFAIL)
30851951Seric 			return NULL;
30951951Seric 	}
31051951Seric 
31151951Seric 	/* short circuit if no spec */
31251951Seric 	if (UdbSpec == NULL || UdbSpec[0] == '\0')
31351951Seric 		return NULL;
31451951Seric 
31551951Seric 	/* long names can never match and are a pain to deal with */
31651951Seric 	if (strlen(sender) > sizeof keybuf - 12)
31751951Seric 		return NULL;
31851951Seric 
31951951Seric 	/* names beginning with colons indicate metadata */
32051951Seric 	if (sender[0] == ':')
32151951Seric 		return NULL;
32251951Seric 
32351951Seric 	/* build database key */
32451951Seric 	(void) strcpy(keybuf, sender);
32551951Seric 	(void) strcat(keybuf, ":mailname");
32651951Seric 	keylen = strlen(keybuf);
32751951Seric 
32851951Seric 	for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++)
32951951Seric 	{
33051951Seric 		/*
33151951Seric 		**  Select action based on entry type.
33251951Seric 		*/
33351951Seric 
33451951Seric 		switch (up->udb_type)
33551951Seric 		{
33651951Seric 		  case UDB_DBFETCH:
33751951Seric 			key.data = keybuf;
33851951Seric 			key.size = keylen;
33951951Seric 			i = (*up->udb_dbp->get)(up->udb_dbp, &key, &info, 0);
34051951Seric 			if (i != 0 || info.size <= 0)
34151951Seric 			{
34251951Seric 				if (tTd(28, 2))
34351951Seric 					printf("udbsender: no match on %s\n",
34451951Seric 							keybuf);
34551951Seric 				continue;
34651951Seric 			}
34751951Seric 
34851951Seric 			p = xalloc(info.size + 1);
34951951Seric 			bcopy(info.data, p, info.size);
35051951Seric 			p[info.size] = '\0';
35151951Seric 			if (tTd(28, 1))
35251951Seric 				printf("udbsender ==> %s\n", p);
35351951Seric 			return p;
35451951Seric 		}
35551951Seric 	}
35651951Seric 
35751951Seric 	/*
35851951Seric 	**  Nothing yet.  Search again for a default case.  But only
35951951Seric 	**  use it if we also have a forward (:maildrop) pointer already
36051951Seric 	**  in the database.
36151951Seric 	*/
36251951Seric 
36351951Seric 	/* build database key */
36451951Seric 	(void) strcpy(keybuf, sender);
36551951Seric 	(void) strcat(keybuf, ":maildrop");
36651951Seric 	keylen = strlen(keybuf);
36751951Seric 
36851951Seric 	for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++)
36951951Seric 	{
37051951Seric 		switch (up->udb_type)
37151951Seric 		{
37251951Seric 		  case UDB_DBFETCH:
37351951Seric 			/* get the default case for this database */
37451951Seric 			if (up->udb_default == NULL)
37551951Seric 			{
37651951Seric 				key.data = ":default:mailname";
37751951Seric 				key.size = strlen(key.data);
37851951Seric 				i = (*up->udb_dbp->get)(up->udb_dbp, &key, &info, 0);
37951951Seric 				if (i != 0 || info.size <= 0)
38051951Seric 				{
38151951Seric 					/* no default case */
38251951Seric 					up->udb_default = "";
38351951Seric 					continue;
38451951Seric 				}
38551951Seric 
38651951Seric 				/* save the default case */
38751951Seric 				up->udb_default = xalloc(info.size + 1);
38851951Seric 				bcopy(info.data, up->udb_default, info.size);
38951951Seric 				up->udb_default[info.size] = '\0';
39051951Seric 			}
39151951Seric 			else if (up->udb_default[0] == '\0')
39251951Seric 				continue;
39351951Seric 
39451951Seric 			/* we have a default case -- verify user:maildrop */
39551951Seric 			key.data = keybuf;
39651951Seric 			key.size = keylen;
39751951Seric 			i = (*up->udb_dbp->get)(up->udb_dbp, &key, &info, 0);
39851951Seric 			if (i != 0 || info.size <= 0)
39951951Seric 			{
40051951Seric 				/* nope -- no aliasing for this user */
40151951Seric 				continue;
40251951Seric 			}
40351951Seric 
40451951Seric 			/* they exist -- build the actual address */
40551951Seric 			p = xalloc(strlen(sender) + strlen(up->udb_default) + 2);
40651951Seric 			(void) strcpy(p, sender);
40751951Seric 			(void) strcat(p, "@");
40851951Seric 			(void) strcat(p, up->udb_default);
40951951Seric 			if (tTd(28, 1))
41051951Seric 				printf("udbsender ==> %s\n", p);
41151951Seric 			return p;
41251951Seric 		}
41351951Seric 	}
41451951Seric 
41551951Seric 	/* still nothing....  too bad */
41651951Seric 	return NULL;
41751951Seric }
41851951Seric /*
41951951Seric **  _UDBX_INIT -- parse the UDB specification, opening any valid entries.
42051951Seric **
42151951Seric **	Parameters:
42251951Seric **		none.
42351951Seric **
42451951Seric **	Returns:
42551951Seric **		EX_TEMPFAIL -- if it appeared it couldn't get hold of a
42651951Seric **			database due to a host being down or some similar
42751951Seric **			(recoverable) situation.
42851951Seric **		EX_OK -- otherwise.
42951951Seric **
43051951Seric **	Side Effects:
43151951Seric **		Fills in the UdbEnts structure from UdbSpec.
43251951Seric */
43351951Seric 
43451363Seric #define MAXUDBOPTS	27
43551363Seric 
43651953Seric int
43751362Seric _udbx_init()
43851362Seric {
43951362Seric 	register char *p;
44051362Seric 	int i;
44151362Seric 	register struct udbent *up;
44257232Seric 	char buf[BUFSIZ];
44351360Seric 
44451951Seric 	if (UdbInitialized)
44551951Seric 		return EX_OK;
44651951Seric 
44751908Seric # ifdef UDB_DEFAULT_SPEC
44851908Seric 	if (UdbSpec == NULL)
44951908Seric 		UdbSpec = UDB_DEFAULT_SPEC;
45051908Seric # endif
45151908Seric 
45251362Seric 	p = UdbSpec;
45351362Seric 	up = UdbEnts;
45451762Seric 	while (p != NULL)
45551362Seric 	{
45651362Seric 		char *spec;
45751362Seric 		auto int rcode;
45851363Seric 		int nopts;
45951362Seric 		int nmx;
46051362Seric 		register struct hostent *h;
46151362Seric 		char *mxhosts[MAXMXHOSTS + 1];
46251363Seric 		struct option opts[MAXUDBOPTS + 1];
46351362Seric 
46451362Seric 		while (*p == ' ' || *p == '\t' || *p == ',')
46551362Seric 			p++;
46651362Seric 		if (*p == '\0')
46751362Seric 			break;
46851362Seric 		spec = p;
46956795Seric 		p = strchr(p, ',');
47051761Seric 		if (p != NULL)
47151362Seric 			*p++ = '\0';
47251363Seric 
47351363Seric 		/* extract options */
47451363Seric 		nopts = _udb_parsespec(spec, opts, MAXUDBOPTS);
47551363Seric 
47651363Seric 		/*
47751363Seric 		**  Decode database specification.
47851363Seric 		**
47951363Seric 		**	In the sendmail tradition, the leading character
48051363Seric 		**	defines the semantics of the rest of the entry.
48151363Seric 		**
48251363Seric 		**	+hostname --	send a datagram to the udb server
48351363Seric 		**			on host "hostname" asking for the
48451363Seric 		**			home mail server for this user.
48551363Seric 		**	*hostname --	similar to +hostname, except that the
48651363Seric 		**			hostname is searched as an MX record;
48751363Seric 		**			resulting hosts are searched as for
48851363Seric 		**			+mxhostname.  If no MX host is found,
48951363Seric 		**			this is the same as +hostname.
49051363Seric 		**	@hostname --	forward email to the indicated host.
49151363Seric 		**			This should be the last in the list,
49251363Seric 		**			since it always matches the input.
49351363Seric 		**	/dbname	 --	search the named database on the local
49451363Seric 		**			host using the Berkeley db package.
49551363Seric 		*/
49651363Seric 
49751362Seric 		switch (*spec)
49851360Seric 		{
49951362Seric 		  case '+':	/* search remote database */
50051363Seric 		  case '*':	/* search remote database (expand MX) */
50151363Seric 			if (*spec == '*')
50251363Seric 			{
50357629Seric #ifdef NAMED_BIND
50451363Seric 				nmx = getmxrr(spec + 1, mxhosts, "", &rcode);
50557629Seric #else
50657629Seric 				mxhosts[0] = spec + 1;
50757629Seric 				nmx = 1;
50857629Seric 				rcode = 0;
50957629Seric #endif
51051363Seric 				if (tTd(28, 16))
51151363Seric 				{
51251363Seric 					int i;
51351362Seric 
51451363Seric 					printf("getmxrr(%s): %d", spec + 1, nmx);
51551363Seric 					for (i = 0; i <= nmx; i++)
51651363Seric 						printf(" %s", mxhosts[i]);
51751363Seric 					printf("\n");
51851363Seric 				}
51951363Seric 			}
52051363Seric 			else
52151362Seric 			{
52251363Seric 				nmx = 1;
52351363Seric 				mxhosts[0] = spec + 1;
52451362Seric 			}
52551362Seric 
52651362Seric 			for (i = 0; i < nmx; i++)
52751362Seric 			{
52851362Seric 				h = gethostbyname(mxhosts[i]);
52951362Seric 				if (h == NULL)
53051362Seric 					continue;
53151362Seric 				up->udb_type = UDB_REMOTE;
53251362Seric 				up->udb_addr.sin_family = h->h_addrtype;
533*58755Seric 				up->udb_addr.sin_len = h->h_length;
53451362Seric 				bcopy(h->h_addr_list[0],
53551362Seric 				      (char *) &up->udb_addr.sin_addr,
53651362Seric 				      h->h_length);
53751362Seric 				up->udb_addr.sin_port = UdbPort;
53851362Seric 				up->udb_timeout = UdbTimeout;
53951362Seric 				up++;
54051362Seric 			}
54151362Seric 
54251362Seric 			/* set up a datagram socket */
54351362Seric 			if (UdbSock < 0)
54451362Seric 			{
54551362Seric 				UdbSock = socket(AF_INET, SOCK_DGRAM, 0);
54651362Seric 				(void) fcntl(UdbSock, F_SETFD, 1);
54751362Seric 			}
54851362Seric 			break;
54951362Seric 
55051362Seric 		  case '@':	/* forward to remote host */
55151362Seric 			up->udb_type = UDB_FORWARD;
55251362Seric 			up->udb_fwdhost = spec + 1;
55351362Seric 			up++;
55451362Seric 			break;
55551362Seric 
55651362Seric 		  case '/':	/* look up remote name */
55751831Seric 			up->udb_dbname = spec;
55851923Seric 			errno = 0;
55951362Seric 			up->udb_dbp = dbopen(spec, O_RDONLY, 0644, DB_BTREE, NULL);
56051362Seric 			if (up->udb_dbp == NULL)
56151923Seric 			{
56251923Seric 				if (errno != ENOENT && errno != EACCES)
56351951Seric 				{
56451951Seric 					up->udb_type = UDB_EOLIST;
56551951Seric 					goto tempfail;
56651951Seric 				}
56751362Seric 				break;
56851923Seric 			}
56951951Seric 			up->udb_type = UDB_DBFETCH;
57051362Seric 			up++;
57151362Seric 			break;
57251360Seric 		}
57351362Seric 	}
57451362Seric 	up->udb_type = UDB_EOLIST;
57551360Seric 
57651362Seric 	if (tTd(28, 4))
57751362Seric 	{
57851951Seric 		for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++)
57951360Seric 		{
58051362Seric 			switch (up->udb_type)
58151362Seric 			{
58251362Seric 			  case UDB_REMOTE:
58351362Seric 				printf("REMOTE: addr %s, timeo %d\n",
584*58755Seric 					anynet_ntoa(&up->udb_addr),
58551362Seric 					up->udb_timeout);
58651362Seric 				break;
58751362Seric 
58851951Seric 			  case UDB_DBFETCH:
58951951Seric 				printf("FETCH: file %s\n",
59051830Seric 					up->udb_dbname);
59151362Seric 				break;
59251362Seric 
59351362Seric 			  case UDB_FORWARD:
59451362Seric 				printf("FORWARD: host %s\n",
59551362Seric 					up->udb_fwdhost);
59651362Seric 				break;
59751362Seric 
59851362Seric 			  default:
59951362Seric 				printf("UNKNOWN\n");
60051362Seric 				break;
60151362Seric 			}
60251360Seric 		}
60350581Seric 	}
60451951Seric 
60551951Seric 	UdbInitialized = TRUE;
60651955Seric 	errno = 0;
60751951Seric 	return EX_OK;
60851951Seric 
60951951Seric 	/*
61051951Seric 	**  On temporary failure, back out anything we've already done
61151951Seric 	*/
61251951Seric 
61351951Seric   tempfail:
61451951Seric 	for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++)
61551951Seric 	{
61651951Seric 		if (up->udb_type == UDB_DBFETCH)
61751951Seric 		{
61851951Seric 			(*up->udb_dbp->close)(up->udb_dbp);
61951951Seric 		}
62051951Seric 	}
62151951Seric 	return EX_TEMPFAIL;
62251360Seric }
62350581Seric 
62451363Seric int
62551363Seric _udb_parsespec(udbspec, opt, maxopts)
62651363Seric 	char *udbspec;
62751363Seric 	struct option opt[];
62851363Seric 	int maxopts;
62951363Seric {
63051363Seric 	register char *spec;
63151363Seric 	register char *spec_end;
63251363Seric 	register int optnum;
63351363Seric 
63456795Seric 	spec_end = strchr(udbspec, ':');
63551363Seric 	for (optnum = 0; optnum < maxopts && (spec = spec_end) != NULL; optnum++)
63651363Seric 	{
63751363Seric 		register char *p;
63851363Seric 
63958050Seric 		while (isascii(*spec) && isspace(*spec))
64051363Seric 			spec++;
64156795Seric 		spec_end = strchr(spec, ':');
64251363Seric 		if (spec_end != NULL)
64351363Seric 			*spec_end++ = '\0';
64451363Seric 
64551363Seric 		opt[optnum].name = spec;
64651363Seric 		opt[optnum].val = NULL;
64756795Seric 		p = strchr(spec, '=');
64851363Seric 		if (p != NULL)
64951363Seric 			opt[optnum].val = ++p;
65051363Seric 	}
65151363Seric 	return optnum;
65251363Seric }
65351363Seric 
65451360Seric #else /* not USERDB */
65551360Seric 
65651923Seric int
65755012Seric udbexpand(a, sendq, e)
65851360Seric 	ADDRESS *a;
65951360Seric 	ADDRESS **sendq;
66055012Seric 	ENVELOPE *e;
66151360Seric {
66251923Seric 	return EX_OK;
66350581Seric }
66450581Seric 
66550581Seric #endif /* USERDB */
666