xref: /csrg-svn/usr.sbin/sendmail/src/udb.c (revision 58065)
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*58065Seric static char sccsid [] = "@(#)udb.c	6.8 (Berkeley) 02/19/93 (with USERDB)";
1251360Seric #else
13*58065Seric static char sccsid [] = "@(#)udb.c	6.8 (Berkeley) 02/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 <fcntl.h>
2451360Seric #include <netdb.h>
2550581Seric #include <db.h>
2650581Seric 
2750581Seric /*
2853654Seric **  UDB.C -- interface between sendmail and Berkeley User Data Base.
2950581Seric **
3051363Seric **	This depends on the 4.4BSD db package.
3150581Seric */
3250581Seric 
3351362Seric 
3451360Seric struct udbent
3551360Seric {
3651360Seric 	char	*udb_spec;		/* string version of spec */
3751360Seric 	int	udb_type;		/* type of entry */
3851951Seric 	char	*udb_default;		/* default host for outgoing mail */
3951360Seric 	union
4051360Seric 	{
4151360Seric 		/* type UE_REMOTE -- do remote call for lookup */
4251360Seric 		struct
4351360Seric 		{
4451360Seric 			struct sockaddr_in _udb_addr;	/* address */
4551360Seric 			int		_udb_timeout;	/* timeout */
4651360Seric 		} udb_remote;
4751360Seric #define udb_addr	udb_u.udb_remote._udb_addr
4851360Seric #define udb_timeout	udb_u.udb_remote._udb_timeout
4951360Seric 
5051360Seric 		/* type UE_FORWARD -- forward message to remote */
5151360Seric 		struct
5251360Seric 		{
5351360Seric 			char	*_udb_fwdhost;	/* name of forward host */
5451360Seric 		} udb_forward;
5551360Seric #define udb_fwdhost	udb_u.udb_forward._udb_fwdhost
5651360Seric 
5751951Seric 		/* type UE_FETCH -- lookup in local database */
5851360Seric 		struct
5951360Seric 		{
6051360Seric 			char	*_udb_dbname;	/* pathname of database */
6151360Seric 			DB	*_udb_dbp;	/* open database ptr */
6251360Seric 		} udb_lookup;
6351360Seric #define udb_dbname	udb_u.udb_lookup._udb_dbname
6451360Seric #define udb_dbp		udb_u.udb_lookup._udb_dbp
6551360Seric 	} udb_u;
6651360Seric };
6751360Seric 
6851360Seric #define UDB_EOLIST	0	/* end of list */
6951360Seric #define UDB_SKIP	1	/* skip this entry */
7051360Seric #define UDB_REMOTE	2	/* look up in remote database */
7151951Seric #define UDB_DBFETCH	3	/* look up in local database */
7251360Seric #define UDB_FORWARD	4	/* forward to remote host */
7351360Seric 
7451360Seric #define MAXUDBENT	10	/* maximum number of UDB entries */
7551360Seric 
7651363Seric 
7751363Seric struct option
7851363Seric {
7951363Seric 	char	*name;
8051363Seric 	char	*val;
8151363Seric };
8251363Seric /*
8351363Seric **  UDBEXPAND -- look up user in database and expand
8451363Seric **
8551363Seric **	Parameters:
8651363Seric **		a -- address to expand.
8751363Seric **		sendq -- pointer to head of sendq to put the expansions in.
8851363Seric **
8951363Seric **	Returns:
9051923Seric **		EX_TEMPFAIL -- if something "odd" happened -- probably due
9151923Seric **			to accessing a file on an NFS server that is down.
9251923Seric **		EX_OK -- otherwise.
9351363Seric **
9451363Seric **	Side Effects:
9551363Seric **		Modifies sendq.
9651363Seric */
9751363Seric 
9851363Seric int	UdbPort = 1616;
9951363Seric int	UdbTimeout = 10;
10051363Seric 
10151953Seric struct udbent	UdbEnts[MAXUDBENT + 1];
10251953Seric int		UdbSock = -1;
10351953Seric bool		UdbInitialized = FALSE;
10451360Seric 
10551923Seric int
10655012Seric udbexpand(a, sendq, e)
10750581Seric 	register ADDRESS *a;
10850581Seric 	ADDRESS **sendq;
10955012Seric 	register ENVELOPE *e;
11050581Seric {
11150581Seric 	int i;
11250581Seric 	register char *p;
11350581Seric 	DBT key;
11450581Seric 	DBT info;
11551360Seric 	bool breakout;
11651360Seric 	register struct udbent *up;
11751362Seric 	int keylen;
11857232Seric 	char keybuf[MAXKEY];
11957232Seric 	char buf[BUFSIZ];
12050581Seric 
12150581Seric 	if (tTd(28, 1))
122*58065Seric 		printf("udbexpand(%s)\n", a->q_paddr);
12350581Seric 
12450581Seric 	/* make certain we are supposed to send to this address */
12551909Seric 	if (bitset(QDONTSEND, 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))
177*58065Seric 					printf("udbexpand: no match on %s\n", keybuf);
17851360Seric 				continue;
17951360Seric 			}
18050581Seric 
18151830Seric 			while (i == 0 && key.size == keylen &&
18251830Seric 					bcmp(key.data, keybuf, keylen) == 0)
18351362Seric 			{
18451830Seric 				breakout = TRUE;
18551362Seric 				if (info.size < sizeof buf)
18651362Seric 					user = buf;
18751362Seric 				else
18851362Seric 					user = xalloc(info.size + 1);
18951362Seric 				bcopy(info.data, user, info.size);
19051362Seric 				user[info.size] = '\0';
19150581Seric 
19251362Seric 				message(Arpa_Info, "expanded to %s", user);
19357977Seric #ifdef LOG
19457977Seric 				if (LogLevel >= 10)
19557977Seric 					syslog(LOG_INFO, "%s: expand %s => %s",
19657977Seric 						e->e_id, e->e_to, user);
19757977Seric #endif
19851362Seric 				AliasLevel++;
19955012Seric 				sendtolist(user, a, sendq, e);
20051362Seric 				AliasLevel--;
20151362Seric 
20251362Seric 				if (user != buf)
20351362Seric 					free(user);
20451362Seric 
20551362Seric 				/* get the next record */
20651362Seric 				i = (*up->udb_dbp->seq)(up->udb_dbp, &key, &info, R_NEXT);
20751830Seric 			}
208*58065Seric 			if (!bitset(QSELFREF, a->q_flags))
209*58065Seric 			{
210*58065Seric 				if (tTd(28, 5))
211*58065Seric 				{
212*58065Seric 					printf("udbexpand: QDONTSEND ");
213*58065Seric 					printaddr(a, FALSE);
214*58065Seric 				}
215*58065Seric 				a->q_flags |= QDONTSEND;
216*58065Seric 			}
21751923Seric 			if (i < 0)
21851923Seric 			{
21958010Seric 				syserr("udbexpand: db-get %.*s stat %d",
22058010Seric 					key.size, key.data, i);
22151923Seric 				return EX_TEMPFAIL;
22251923Seric 			}
22351360Seric 			break;
22451360Seric 
22551360Seric 		  case UDB_REMOTE:
22651741Seric 			/* not yet implemented */
22751741Seric 			continue;
22851362Seric 
22951360Seric 		  case UDB_FORWARD:
23051360Seric 			i = strlen(up->udb_fwdhost) + strlen(a->q_user) + 1;
23151360Seric 			if (i < sizeof buf)
23251360Seric 				user = buf;
23351360Seric 			else
23451360Seric 				user = xalloc(i + 1);
23551360Seric 			(void) sprintf(user, "%s@%s", a->q_user, up->udb_fwdhost);
23651362Seric 			message(Arpa_Info, "expanded to %s", user);
23751362Seric 			AliasLevel++;
23855012Seric 			sendtolist(user, a, sendq, e);
23951362Seric 			AliasLevel--;
240*58065Seric 			if (!bitset(QSELFREF, a->q_flags))
241*58065Seric 			{
242*58065Seric 				if (tTd(28, 5))
243*58065Seric 				{
244*58065Seric 					printf("udbexpand: QDONTSEND ");
245*58065Seric 					printaddr(a, FALSE);
246*58065Seric 				}
247*58065Seric 				a->q_flags |= QDONTSEND;
248*58065Seric 			}
24951362Seric 			if (user != buf)
25051362Seric 				free(user);
25151362Seric 			breakout = TRUE;
25251360Seric 			break;
25351360Seric 
25451360Seric 		  case UDB_EOLIST:
25551360Seric 			breakout = TRUE;
25651360Seric 			continue;
25751360Seric 
25851360Seric 		  default:
25951360Seric 			/* unknown entry type */
26051360Seric 			continue;
26151360Seric 		}
26251362Seric 	}
26351923Seric 	return EX_OK;
26451362Seric }
26551951Seric /*
26651951Seric **  UDBSENDER -- return canonical external name of sender, given local name
26751951Seric **
26851951Seric **	Parameters:
26951951Seric **		sender -- the name of the sender on the local machine.
27051951Seric **
27151951Seric **	Returns:
27251951Seric **		The external name for this sender, if derivable from the
27351951Seric **			database.
27451951Seric **		NULL -- if nothing is changed from the database.
27551951Seric **
27651951Seric **	Side Effects:
27751951Seric **		none.
27851951Seric */
27951360Seric 
28051951Seric char *
28151951Seric udbsender(sender)
28251951Seric 	char *sender;
28351951Seric {
28451951Seric 	register char *p;
28551951Seric 	register struct udbent *up;
28651951Seric 	int i;
28751951Seric 	int keylen;
28851951Seric 	DBT key, info;
28957232Seric 	char keybuf[MAXKEY];
29051951Seric 
29151951Seric 	if (tTd(28, 1))
29251951Seric 		printf("udbsender(%s)\n", sender);
29351951Seric 
29451951Seric 	if (!UdbInitialized)
29551951Seric 	{
29651951Seric 		if (_udbx_init() == EX_TEMPFAIL)
29751951Seric 			return NULL;
29851951Seric 	}
29951951Seric 
30051951Seric 	/* short circuit if no spec */
30151951Seric 	if (UdbSpec == NULL || UdbSpec[0] == '\0')
30251951Seric 		return NULL;
30351951Seric 
30451951Seric 	/* long names can never match and are a pain to deal with */
30551951Seric 	if (strlen(sender) > sizeof keybuf - 12)
30651951Seric 		return NULL;
30751951Seric 
30851951Seric 	/* names beginning with colons indicate metadata */
30951951Seric 	if (sender[0] == ':')
31051951Seric 		return NULL;
31151951Seric 
31251951Seric 	/* build database key */
31351951Seric 	(void) strcpy(keybuf, sender);
31451951Seric 	(void) strcat(keybuf, ":mailname");
31551951Seric 	keylen = strlen(keybuf);
31651951Seric 
31751951Seric 	for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++)
31851951Seric 	{
31951951Seric 		/*
32051951Seric 		**  Select action based on entry type.
32151951Seric 		*/
32251951Seric 
32351951Seric 		switch (up->udb_type)
32451951Seric 		{
32551951Seric 		  case UDB_DBFETCH:
32651951Seric 			key.data = keybuf;
32751951Seric 			key.size = keylen;
32851951Seric 			i = (*up->udb_dbp->get)(up->udb_dbp, &key, &info, 0);
32951951Seric 			if (i != 0 || info.size <= 0)
33051951Seric 			{
33151951Seric 				if (tTd(28, 2))
33251951Seric 					printf("udbsender: no match on %s\n",
33351951Seric 							keybuf);
33451951Seric 				continue;
33551951Seric 			}
33651951Seric 
33751951Seric 			p = xalloc(info.size + 1);
33851951Seric 			bcopy(info.data, p, info.size);
33951951Seric 			p[info.size] = '\0';
34051951Seric 			if (tTd(28, 1))
34151951Seric 				printf("udbsender ==> %s\n", p);
34251951Seric 			return p;
34351951Seric 		}
34451951Seric 	}
34551951Seric 
34651951Seric 	/*
34751951Seric 	**  Nothing yet.  Search again for a default case.  But only
34851951Seric 	**  use it if we also have a forward (:maildrop) pointer already
34951951Seric 	**  in the database.
35051951Seric 	*/
35151951Seric 
35251951Seric 	/* build database key */
35351951Seric 	(void) strcpy(keybuf, sender);
35451951Seric 	(void) strcat(keybuf, ":maildrop");
35551951Seric 	keylen = strlen(keybuf);
35651951Seric 
35751951Seric 	for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++)
35851951Seric 	{
35951951Seric 		switch (up->udb_type)
36051951Seric 		{
36151951Seric 		  case UDB_DBFETCH:
36251951Seric 			/* get the default case for this database */
36351951Seric 			if (up->udb_default == NULL)
36451951Seric 			{
36551951Seric 				key.data = ":default:mailname";
36651951Seric 				key.size = strlen(key.data);
36751951Seric 				i = (*up->udb_dbp->get)(up->udb_dbp, &key, &info, 0);
36851951Seric 				if (i != 0 || info.size <= 0)
36951951Seric 				{
37051951Seric 					/* no default case */
37151951Seric 					up->udb_default = "";
37251951Seric 					continue;
37351951Seric 				}
37451951Seric 
37551951Seric 				/* save the default case */
37651951Seric 				up->udb_default = xalloc(info.size + 1);
37751951Seric 				bcopy(info.data, up->udb_default, info.size);
37851951Seric 				up->udb_default[info.size] = '\0';
37951951Seric 			}
38051951Seric 			else if (up->udb_default[0] == '\0')
38151951Seric 				continue;
38251951Seric 
38351951Seric 			/* we have a default case -- verify user:maildrop */
38451951Seric 			key.data = keybuf;
38551951Seric 			key.size = keylen;
38651951Seric 			i = (*up->udb_dbp->get)(up->udb_dbp, &key, &info, 0);
38751951Seric 			if (i != 0 || info.size <= 0)
38851951Seric 			{
38951951Seric 				/* nope -- no aliasing for this user */
39051951Seric 				continue;
39151951Seric 			}
39251951Seric 
39351951Seric 			/* they exist -- build the actual address */
39451951Seric 			p = xalloc(strlen(sender) + strlen(up->udb_default) + 2);
39551951Seric 			(void) strcpy(p, sender);
39651951Seric 			(void) strcat(p, "@");
39751951Seric 			(void) strcat(p, up->udb_default);
39851951Seric 			if (tTd(28, 1))
39951951Seric 				printf("udbsender ==> %s\n", p);
40051951Seric 			return p;
40151951Seric 		}
40251951Seric 	}
40351951Seric 
40451951Seric 	/* still nothing....  too bad */
40551951Seric 	return NULL;
40651951Seric }
40751951Seric /*
40851951Seric **  _UDBX_INIT -- parse the UDB specification, opening any valid entries.
40951951Seric **
41051951Seric **	Parameters:
41151951Seric **		none.
41251951Seric **
41351951Seric **	Returns:
41451951Seric **		EX_TEMPFAIL -- if it appeared it couldn't get hold of a
41551951Seric **			database due to a host being down or some similar
41651951Seric **			(recoverable) situation.
41751951Seric **		EX_OK -- otherwise.
41851951Seric **
41951951Seric **	Side Effects:
42051951Seric **		Fills in the UdbEnts structure from UdbSpec.
42151951Seric */
42251951Seric 
42351363Seric #define MAXUDBOPTS	27
42451363Seric 
42551953Seric int
42651362Seric _udbx_init()
42751362Seric {
42851362Seric 	register char *p;
42951362Seric 	int i;
43051362Seric 	register struct udbent *up;
43157232Seric 	char buf[BUFSIZ];
43251360Seric 
43351951Seric 	if (UdbInitialized)
43451951Seric 		return EX_OK;
43551951Seric 
43651908Seric # ifdef UDB_DEFAULT_SPEC
43751908Seric 	if (UdbSpec == NULL)
43851908Seric 		UdbSpec = UDB_DEFAULT_SPEC;
43951908Seric # endif
44051908Seric 
44151362Seric 	p = UdbSpec;
44251362Seric 	up = UdbEnts;
44351762Seric 	while (p != NULL)
44451362Seric 	{
44551362Seric 		char *spec;
44651362Seric 		auto int rcode;
44751363Seric 		int nopts;
44851362Seric 		int nmx;
44951362Seric 		register struct hostent *h;
45051362Seric 		char *mxhosts[MAXMXHOSTS + 1];
45151363Seric 		struct option opts[MAXUDBOPTS + 1];
45251362Seric 
45351362Seric 		while (*p == ' ' || *p == '\t' || *p == ',')
45451362Seric 			p++;
45551362Seric 		if (*p == '\0')
45651362Seric 			break;
45751362Seric 		spec = p;
45856795Seric 		p = strchr(p, ',');
45951761Seric 		if (p != NULL)
46051362Seric 			*p++ = '\0';
46151363Seric 
46251363Seric 		/* extract options */
46351363Seric 		nopts = _udb_parsespec(spec, opts, MAXUDBOPTS);
46451363Seric 
46551363Seric 		/*
46651363Seric 		**  Decode database specification.
46751363Seric 		**
46851363Seric 		**	In the sendmail tradition, the leading character
46951363Seric 		**	defines the semantics of the rest of the entry.
47051363Seric 		**
47151363Seric 		**	+hostname --	send a datagram to the udb server
47251363Seric 		**			on host "hostname" asking for the
47351363Seric 		**			home mail server for this user.
47451363Seric 		**	*hostname --	similar to +hostname, except that the
47551363Seric 		**			hostname is searched as an MX record;
47651363Seric 		**			resulting hosts are searched as for
47751363Seric 		**			+mxhostname.  If no MX host is found,
47851363Seric 		**			this is the same as +hostname.
47951363Seric 		**	@hostname --	forward email to the indicated host.
48051363Seric 		**			This should be the last in the list,
48151363Seric 		**			since it always matches the input.
48251363Seric 		**	/dbname	 --	search the named database on the local
48351363Seric 		**			host using the Berkeley db package.
48451363Seric 		*/
48551363Seric 
48651362Seric 		switch (*spec)
48751360Seric 		{
48851362Seric 		  case '+':	/* search remote database */
48951363Seric 		  case '*':	/* search remote database (expand MX) */
49051363Seric 			if (*spec == '*')
49151363Seric 			{
49257629Seric #ifdef NAMED_BIND
49351363Seric 				nmx = getmxrr(spec + 1, mxhosts, "", &rcode);
49457629Seric #else
49557629Seric 				mxhosts[0] = spec + 1;
49657629Seric 				nmx = 1;
49757629Seric 				rcode = 0;
49857629Seric #endif
49951363Seric 				if (tTd(28, 16))
50051363Seric 				{
50151363Seric 					int i;
50251362Seric 
50351363Seric 					printf("getmxrr(%s): %d", spec + 1, nmx);
50451363Seric 					for (i = 0; i <= nmx; i++)
50551363Seric 						printf(" %s", mxhosts[i]);
50651363Seric 					printf("\n");
50751363Seric 				}
50851363Seric 			}
50951363Seric 			else
51051362Seric 			{
51151363Seric 				nmx = 1;
51251363Seric 				mxhosts[0] = spec + 1;
51351362Seric 			}
51451362Seric 
51551362Seric 			for (i = 0; i < nmx; i++)
51651362Seric 			{
51751362Seric 				h = gethostbyname(mxhosts[i]);
51851362Seric 				if (h == NULL)
51951362Seric 					continue;
52051362Seric 				up->udb_type = UDB_REMOTE;
52151362Seric 				up->udb_addr.sin_family = h->h_addrtype;
52251362Seric 				bcopy(h->h_addr_list[0],
52351362Seric 				      (char *) &up->udb_addr.sin_addr,
52451362Seric 				      h->h_length);
52551362Seric 				up->udb_addr.sin_port = UdbPort;
52651362Seric 				up->udb_timeout = UdbTimeout;
52751362Seric 				up++;
52851362Seric 			}
52951362Seric 
53051362Seric 			/* set up a datagram socket */
53151362Seric 			if (UdbSock < 0)
53251362Seric 			{
53351362Seric 				UdbSock = socket(AF_INET, SOCK_DGRAM, 0);
53451362Seric 				(void) fcntl(UdbSock, F_SETFD, 1);
53551362Seric 			}
53651362Seric 			break;
53751362Seric 
53851362Seric 		  case '@':	/* forward to remote host */
53951362Seric 			up->udb_type = UDB_FORWARD;
54051362Seric 			up->udb_fwdhost = spec + 1;
54151362Seric 			up++;
54251362Seric 			break;
54351362Seric 
54451362Seric 		  case '/':	/* look up remote name */
54551831Seric 			up->udb_dbname = spec;
54651923Seric 			errno = 0;
54751362Seric 			up->udb_dbp = dbopen(spec, O_RDONLY, 0644, DB_BTREE, NULL);
54851362Seric 			if (up->udb_dbp == NULL)
54951923Seric 			{
55051923Seric 				if (errno != ENOENT && errno != EACCES)
55151951Seric 				{
55251951Seric 					up->udb_type = UDB_EOLIST;
55351951Seric 					goto tempfail;
55451951Seric 				}
55551362Seric 				break;
55651923Seric 			}
55751951Seric 			up->udb_type = UDB_DBFETCH;
55851362Seric 			up++;
55951362Seric 			break;
56051360Seric 		}
56151362Seric 	}
56251362Seric 	up->udb_type = UDB_EOLIST;
56351360Seric 
56451362Seric 	if (tTd(28, 4))
56551362Seric 	{
56651951Seric 		for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++)
56751360Seric 		{
56851362Seric 			switch (up->udb_type)
56951362Seric 			{
57051362Seric 			  case UDB_REMOTE:
57151362Seric 				printf("REMOTE: addr %s, timeo %d\n",
57251362Seric 					inet_ntoa(up->udb_addr.sin_addr),
57351362Seric 					up->udb_timeout);
57451362Seric 				break;
57551362Seric 
57651951Seric 			  case UDB_DBFETCH:
57751951Seric 				printf("FETCH: file %s\n",
57851830Seric 					up->udb_dbname);
57951362Seric 				break;
58051362Seric 
58151362Seric 			  case UDB_FORWARD:
58251362Seric 				printf("FORWARD: host %s\n",
58351362Seric 					up->udb_fwdhost);
58451362Seric 				break;
58551362Seric 
58651362Seric 			  default:
58751362Seric 				printf("UNKNOWN\n");
58851362Seric 				break;
58951362Seric 			}
59051360Seric 		}
59150581Seric 	}
59251951Seric 
59351951Seric 	UdbInitialized = TRUE;
59451955Seric 	errno = 0;
59551951Seric 	return EX_OK;
59651951Seric 
59751951Seric 	/*
59851951Seric 	**  On temporary failure, back out anything we've already done
59951951Seric 	*/
60051951Seric 
60151951Seric   tempfail:
60251951Seric 	for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++)
60351951Seric 	{
60451951Seric 		if (up->udb_type == UDB_DBFETCH)
60551951Seric 		{
60651951Seric 			(*up->udb_dbp->close)(up->udb_dbp);
60751951Seric 		}
60851951Seric 	}
60951951Seric 	return EX_TEMPFAIL;
61051360Seric }
61150581Seric 
61251363Seric int
61351363Seric _udb_parsespec(udbspec, opt, maxopts)
61451363Seric 	char *udbspec;
61551363Seric 	struct option opt[];
61651363Seric 	int maxopts;
61751363Seric {
61851363Seric 	register char *spec;
61951363Seric 	register char *spec_end;
62051363Seric 	register int optnum;
62151363Seric 
62256795Seric 	spec_end = strchr(udbspec, ':');
62351363Seric 	for (optnum = 0; optnum < maxopts && (spec = spec_end) != NULL; optnum++)
62451363Seric 	{
62551363Seric 		register char *p;
62651363Seric 
62758050Seric 		while (isascii(*spec) && isspace(*spec))
62851363Seric 			spec++;
62956795Seric 		spec_end = strchr(spec, ':');
63051363Seric 		if (spec_end != NULL)
63151363Seric 			*spec_end++ = '\0';
63251363Seric 
63351363Seric 		opt[optnum].name = spec;
63451363Seric 		opt[optnum].val = NULL;
63556795Seric 		p = strchr(spec, '=');
63651363Seric 		if (p != NULL)
63751363Seric 			opt[optnum].val = ++p;
63851363Seric 	}
63951363Seric 	return optnum;
64051363Seric }
64151363Seric 
64251360Seric #else /* not USERDB */
64351360Seric 
64451923Seric int
64555012Seric udbexpand(a, sendq, e)
64651360Seric 	ADDRESS *a;
64751360Seric 	ADDRESS **sendq;
64855012Seric 	ENVELOPE *e;
64951360Seric {
65051923Seric 	return EX_OK;
65150581Seric }
65250581Seric 
65350581Seric #endif /* USERDB */
654