xref: /csrg-svn/usr.sbin/sendmail/src/udb.c (revision 58082)
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*58082Seric static char sccsid [] = "@(#)udb.c	6.9 (Berkeley) 02/20/93 (with USERDB)";
1251360Seric #else
13*58082Seric static char sccsid [] = "@(#)udb.c	6.9 (Berkeley) 02/20/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;
118*58082Seric 	int naddrs;
11957232Seric 	char keybuf[MAXKEY];
12057232Seric 	char buf[BUFSIZ];
12150581Seric 
12250581Seric 	if (tTd(28, 1))
12358065Seric 		printf("udbexpand(%s)\n", a->q_paddr);
12450581Seric 
12550581Seric 	/* make certain we are supposed to send to this address */
12651909Seric 	if (bitset(QDONTSEND, a->q_flags))
12751923Seric 		return EX_OK;
12855012Seric 	e->e_to = a->q_paddr;
12950581Seric 
13051360Seric 	/* on first call, locate the database */
13151951Seric 	if (!UdbInitialized)
13250581Seric 	{
13351923Seric 		extern int _udbx_init();
13451362Seric 
13551923Seric 		if (_udbx_init() == EX_TEMPFAIL)
13651923Seric 			return EX_TEMPFAIL;
13751362Seric 	}
13850581Seric 
13951909Seric 	/* short circuit the process if no chance of a match */
14051909Seric 	if (UdbSpec == NULL || UdbSpec[0] == '\0')
14151923Seric 		return EX_OK;
14251909Seric 
14351362Seric 	/* if name is too long, assume it won't match */
14451362Seric 	if (strlen(a->q_user) > sizeof keybuf - 12)
14551923Seric 		return EX_OK;
14651360Seric 
14751362Seric 	/* if name begins with a colon, it indicates our metadata */
14851362Seric 	if (a->q_user[0] == ':')
14951923Seric 		return EX_OK;
15051360Seric 
15151362Seric 	/* build actual database key */
15251362Seric 	(void) strcpy(keybuf, a->q_user);
15351362Seric 	(void) strcat(keybuf, ":maildrop");
15451362Seric 	keylen = strlen(keybuf);
15551360Seric 
15651360Seric 	breakout = FALSE;
15751362Seric 	for (up = UdbEnts; !breakout; up++)
15850581Seric 	{
15951360Seric 		char *user;
16050581Seric 
16151360Seric 		/*
16251360Seric 		**  Select action based on entry type.
16351360Seric 		**
16451360Seric 		**	On dropping out of this switch, "class" should
16551360Seric 		**	explain the type of the data, and "user" should
16651360Seric 		**	contain the user information.
16751360Seric 		*/
16850581Seric 
16951360Seric 		switch (up->udb_type)
17051360Seric 		{
17151951Seric 		  case UDB_DBFETCH:
17251362Seric 			key.data = keybuf;
17351362Seric 			key.size = keylen;
17451362Seric 			i = (*up->udb_dbp->seq)(up->udb_dbp, &key, &info, R_CURSOR);
17551923Seric 			if (i > 0 || info.size <= 0)
17651360Seric 			{
17751360Seric 				if (tTd(28, 2))
17858065Seric 					printf("udbexpand: no match on %s\n", keybuf);
17951360Seric 				continue;
18051360Seric 			}
18150581Seric 
182*58082Seric 			naddrs = 0;
183*58082Seric 			a->q_flags &= ~QSELFREF;
18451830Seric 			while (i == 0 && key.size == keylen &&
18551830Seric 					bcmp(key.data, keybuf, keylen) == 0)
18651362Seric 			{
18751830Seric 				breakout = TRUE;
18851362Seric 				if (info.size < sizeof buf)
18951362Seric 					user = buf;
19051362Seric 				else
19151362Seric 					user = xalloc(info.size + 1);
19251362Seric 				bcopy(info.data, user, info.size);
19351362Seric 				user[info.size] = '\0';
19450581Seric 
19551362Seric 				message(Arpa_Info, "expanded to %s", user);
19657977Seric #ifdef LOG
19757977Seric 				if (LogLevel >= 10)
19857977Seric 					syslog(LOG_INFO, "%s: expand %s => %s",
19957977Seric 						e->e_id, e->e_to, user);
20057977Seric #endif
20151362Seric 				AliasLevel++;
202*58082Seric 				naddrs += sendtolist(user, a, sendq, e);
20351362Seric 				AliasLevel--;
20451362Seric 
20551362Seric 				if (user != buf)
20651362Seric 					free(user);
20751362Seric 
20851362Seric 				/* get the next record */
20951362Seric 				i = (*up->udb_dbp->seq)(up->udb_dbp, &key, &info, R_NEXT);
21051830Seric 			}
211*58082Seric 			if (naddrs > 0 && !bitset(QSELFREF, a->q_flags))
21258065Seric 			{
21358065Seric 				if (tTd(28, 5))
21458065Seric 				{
21558065Seric 					printf("udbexpand: QDONTSEND ");
21658065Seric 					printaddr(a, FALSE);
21758065Seric 				}
21858065Seric 				a->q_flags |= QDONTSEND;
21958065Seric 			}
22051923Seric 			if (i < 0)
22151923Seric 			{
22258010Seric 				syserr("udbexpand: db-get %.*s stat %d",
22358010Seric 					key.size, key.data, i);
22451923Seric 				return EX_TEMPFAIL;
22551923Seric 			}
22651360Seric 			break;
22751360Seric 
22851360Seric 		  case UDB_REMOTE:
22951741Seric 			/* not yet implemented */
23051741Seric 			continue;
23151362Seric 
23251360Seric 		  case UDB_FORWARD:
23351360Seric 			i = strlen(up->udb_fwdhost) + strlen(a->q_user) + 1;
23451360Seric 			if (i < sizeof buf)
23551360Seric 				user = buf;
23651360Seric 			else
23751360Seric 				user = xalloc(i + 1);
23851360Seric 			(void) sprintf(user, "%s@%s", a->q_user, up->udb_fwdhost);
23951362Seric 			message(Arpa_Info, "expanded to %s", user);
240*58082Seric 			a->q_flags &= ~QSELFREF;
24151362Seric 			AliasLevel++;
242*58082Seric 			naddrs = sendtolist(user, a, sendq, e);
24351362Seric 			AliasLevel--;
244*58082Seric 			if (naddrs > 0 && !bitset(QSELFREF, a->q_flags))
24558065Seric 			{
24658065Seric 				if (tTd(28, 5))
24758065Seric 				{
24858065Seric 					printf("udbexpand: QDONTSEND ");
24958065Seric 					printaddr(a, FALSE);
25058065Seric 				}
25158065Seric 				a->q_flags |= QDONTSEND;
25258065Seric 			}
25351362Seric 			if (user != buf)
25451362Seric 				free(user);
25551362Seric 			breakout = TRUE;
25651360Seric 			break;
25751360Seric 
25851360Seric 		  case UDB_EOLIST:
25951360Seric 			breakout = TRUE;
26051360Seric 			continue;
26151360Seric 
26251360Seric 		  default:
26351360Seric 			/* unknown entry type */
26451360Seric 			continue;
26551360Seric 		}
26651362Seric 	}
26751923Seric 	return EX_OK;
26851362Seric }
26951951Seric /*
27051951Seric **  UDBSENDER -- return canonical external name of sender, given local name
27151951Seric **
27251951Seric **	Parameters:
27351951Seric **		sender -- the name of the sender on the local machine.
27451951Seric **
27551951Seric **	Returns:
27651951Seric **		The external name for this sender, if derivable from the
27751951Seric **			database.
27851951Seric **		NULL -- if nothing is changed from the database.
27951951Seric **
28051951Seric **	Side Effects:
28151951Seric **		none.
28251951Seric */
28351360Seric 
28451951Seric char *
28551951Seric udbsender(sender)
28651951Seric 	char *sender;
28751951Seric {
28851951Seric 	register char *p;
28951951Seric 	register struct udbent *up;
29051951Seric 	int i;
29151951Seric 	int keylen;
29251951Seric 	DBT key, info;
29357232Seric 	char keybuf[MAXKEY];
29451951Seric 
29551951Seric 	if (tTd(28, 1))
29651951Seric 		printf("udbsender(%s)\n", sender);
29751951Seric 
29851951Seric 	if (!UdbInitialized)
29951951Seric 	{
30051951Seric 		if (_udbx_init() == EX_TEMPFAIL)
30151951Seric 			return NULL;
30251951Seric 	}
30351951Seric 
30451951Seric 	/* short circuit if no spec */
30551951Seric 	if (UdbSpec == NULL || UdbSpec[0] == '\0')
30651951Seric 		return NULL;
30751951Seric 
30851951Seric 	/* long names can never match and are a pain to deal with */
30951951Seric 	if (strlen(sender) > sizeof keybuf - 12)
31051951Seric 		return NULL;
31151951Seric 
31251951Seric 	/* names beginning with colons indicate metadata */
31351951Seric 	if (sender[0] == ':')
31451951Seric 		return NULL;
31551951Seric 
31651951Seric 	/* build database key */
31751951Seric 	(void) strcpy(keybuf, sender);
31851951Seric 	(void) strcat(keybuf, ":mailname");
31951951Seric 	keylen = strlen(keybuf);
32051951Seric 
32151951Seric 	for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++)
32251951Seric 	{
32351951Seric 		/*
32451951Seric 		**  Select action based on entry type.
32551951Seric 		*/
32651951Seric 
32751951Seric 		switch (up->udb_type)
32851951Seric 		{
32951951Seric 		  case UDB_DBFETCH:
33051951Seric 			key.data = keybuf;
33151951Seric 			key.size = keylen;
33251951Seric 			i = (*up->udb_dbp->get)(up->udb_dbp, &key, &info, 0);
33351951Seric 			if (i != 0 || info.size <= 0)
33451951Seric 			{
33551951Seric 				if (tTd(28, 2))
33651951Seric 					printf("udbsender: no match on %s\n",
33751951Seric 							keybuf);
33851951Seric 				continue;
33951951Seric 			}
34051951Seric 
34151951Seric 			p = xalloc(info.size + 1);
34251951Seric 			bcopy(info.data, p, info.size);
34351951Seric 			p[info.size] = '\0';
34451951Seric 			if (tTd(28, 1))
34551951Seric 				printf("udbsender ==> %s\n", p);
34651951Seric 			return p;
34751951Seric 		}
34851951Seric 	}
34951951Seric 
35051951Seric 	/*
35151951Seric 	**  Nothing yet.  Search again for a default case.  But only
35251951Seric 	**  use it if we also have a forward (:maildrop) pointer already
35351951Seric 	**  in the database.
35451951Seric 	*/
35551951Seric 
35651951Seric 	/* build database key */
35751951Seric 	(void) strcpy(keybuf, sender);
35851951Seric 	(void) strcat(keybuf, ":maildrop");
35951951Seric 	keylen = strlen(keybuf);
36051951Seric 
36151951Seric 	for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++)
36251951Seric 	{
36351951Seric 		switch (up->udb_type)
36451951Seric 		{
36551951Seric 		  case UDB_DBFETCH:
36651951Seric 			/* get the default case for this database */
36751951Seric 			if (up->udb_default == NULL)
36851951Seric 			{
36951951Seric 				key.data = ":default:mailname";
37051951Seric 				key.size = strlen(key.data);
37151951Seric 				i = (*up->udb_dbp->get)(up->udb_dbp, &key, &info, 0);
37251951Seric 				if (i != 0 || info.size <= 0)
37351951Seric 				{
37451951Seric 					/* no default case */
37551951Seric 					up->udb_default = "";
37651951Seric 					continue;
37751951Seric 				}
37851951Seric 
37951951Seric 				/* save the default case */
38051951Seric 				up->udb_default = xalloc(info.size + 1);
38151951Seric 				bcopy(info.data, up->udb_default, info.size);
38251951Seric 				up->udb_default[info.size] = '\0';
38351951Seric 			}
38451951Seric 			else if (up->udb_default[0] == '\0')
38551951Seric 				continue;
38651951Seric 
38751951Seric 			/* we have a default case -- verify user:maildrop */
38851951Seric 			key.data = keybuf;
38951951Seric 			key.size = keylen;
39051951Seric 			i = (*up->udb_dbp->get)(up->udb_dbp, &key, &info, 0);
39151951Seric 			if (i != 0 || info.size <= 0)
39251951Seric 			{
39351951Seric 				/* nope -- no aliasing for this user */
39451951Seric 				continue;
39551951Seric 			}
39651951Seric 
39751951Seric 			/* they exist -- build the actual address */
39851951Seric 			p = xalloc(strlen(sender) + strlen(up->udb_default) + 2);
39951951Seric 			(void) strcpy(p, sender);
40051951Seric 			(void) strcat(p, "@");
40151951Seric 			(void) strcat(p, up->udb_default);
40251951Seric 			if (tTd(28, 1))
40351951Seric 				printf("udbsender ==> %s\n", p);
40451951Seric 			return p;
40551951Seric 		}
40651951Seric 	}
40751951Seric 
40851951Seric 	/* still nothing....  too bad */
40951951Seric 	return NULL;
41051951Seric }
41151951Seric /*
41251951Seric **  _UDBX_INIT -- parse the UDB specification, opening any valid entries.
41351951Seric **
41451951Seric **	Parameters:
41551951Seric **		none.
41651951Seric **
41751951Seric **	Returns:
41851951Seric **		EX_TEMPFAIL -- if it appeared it couldn't get hold of a
41951951Seric **			database due to a host being down or some similar
42051951Seric **			(recoverable) situation.
42151951Seric **		EX_OK -- otherwise.
42251951Seric **
42351951Seric **	Side Effects:
42451951Seric **		Fills in the UdbEnts structure from UdbSpec.
42551951Seric */
42651951Seric 
42751363Seric #define MAXUDBOPTS	27
42851363Seric 
42951953Seric int
43051362Seric _udbx_init()
43151362Seric {
43251362Seric 	register char *p;
43351362Seric 	int i;
43451362Seric 	register struct udbent *up;
43557232Seric 	char buf[BUFSIZ];
43651360Seric 
43751951Seric 	if (UdbInitialized)
43851951Seric 		return EX_OK;
43951951Seric 
44051908Seric # ifdef UDB_DEFAULT_SPEC
44151908Seric 	if (UdbSpec == NULL)
44251908Seric 		UdbSpec = UDB_DEFAULT_SPEC;
44351908Seric # endif
44451908Seric 
44551362Seric 	p = UdbSpec;
44651362Seric 	up = UdbEnts;
44751762Seric 	while (p != NULL)
44851362Seric 	{
44951362Seric 		char *spec;
45051362Seric 		auto int rcode;
45151363Seric 		int nopts;
45251362Seric 		int nmx;
45351362Seric 		register struct hostent *h;
45451362Seric 		char *mxhosts[MAXMXHOSTS + 1];
45551363Seric 		struct option opts[MAXUDBOPTS + 1];
45651362Seric 
45751362Seric 		while (*p == ' ' || *p == '\t' || *p == ',')
45851362Seric 			p++;
45951362Seric 		if (*p == '\0')
46051362Seric 			break;
46151362Seric 		spec = p;
46256795Seric 		p = strchr(p, ',');
46351761Seric 		if (p != NULL)
46451362Seric 			*p++ = '\0';
46551363Seric 
46651363Seric 		/* extract options */
46751363Seric 		nopts = _udb_parsespec(spec, opts, MAXUDBOPTS);
46851363Seric 
46951363Seric 		/*
47051363Seric 		**  Decode database specification.
47151363Seric 		**
47251363Seric 		**	In the sendmail tradition, the leading character
47351363Seric 		**	defines the semantics of the rest of the entry.
47451363Seric 		**
47551363Seric 		**	+hostname --	send a datagram to the udb server
47651363Seric 		**			on host "hostname" asking for the
47751363Seric 		**			home mail server for this user.
47851363Seric 		**	*hostname --	similar to +hostname, except that the
47951363Seric 		**			hostname is searched as an MX record;
48051363Seric 		**			resulting hosts are searched as for
48151363Seric 		**			+mxhostname.  If no MX host is found,
48251363Seric 		**			this is the same as +hostname.
48351363Seric 		**	@hostname --	forward email to the indicated host.
48451363Seric 		**			This should be the last in the list,
48551363Seric 		**			since it always matches the input.
48651363Seric 		**	/dbname	 --	search the named database on the local
48751363Seric 		**			host using the Berkeley db package.
48851363Seric 		*/
48951363Seric 
49051362Seric 		switch (*spec)
49151360Seric 		{
49251362Seric 		  case '+':	/* search remote database */
49351363Seric 		  case '*':	/* search remote database (expand MX) */
49451363Seric 			if (*spec == '*')
49551363Seric 			{
49657629Seric #ifdef NAMED_BIND
49751363Seric 				nmx = getmxrr(spec + 1, mxhosts, "", &rcode);
49857629Seric #else
49957629Seric 				mxhosts[0] = spec + 1;
50057629Seric 				nmx = 1;
50157629Seric 				rcode = 0;
50257629Seric #endif
50351363Seric 				if (tTd(28, 16))
50451363Seric 				{
50551363Seric 					int i;
50651362Seric 
50751363Seric 					printf("getmxrr(%s): %d", spec + 1, nmx);
50851363Seric 					for (i = 0; i <= nmx; i++)
50951363Seric 						printf(" %s", mxhosts[i]);
51051363Seric 					printf("\n");
51151363Seric 				}
51251363Seric 			}
51351363Seric 			else
51451362Seric 			{
51551363Seric 				nmx = 1;
51651363Seric 				mxhosts[0] = spec + 1;
51751362Seric 			}
51851362Seric 
51951362Seric 			for (i = 0; i < nmx; i++)
52051362Seric 			{
52151362Seric 				h = gethostbyname(mxhosts[i]);
52251362Seric 				if (h == NULL)
52351362Seric 					continue;
52451362Seric 				up->udb_type = UDB_REMOTE;
52551362Seric 				up->udb_addr.sin_family = h->h_addrtype;
52651362Seric 				bcopy(h->h_addr_list[0],
52751362Seric 				      (char *) &up->udb_addr.sin_addr,
52851362Seric 				      h->h_length);
52951362Seric 				up->udb_addr.sin_port = UdbPort;
53051362Seric 				up->udb_timeout = UdbTimeout;
53151362Seric 				up++;
53251362Seric 			}
53351362Seric 
53451362Seric 			/* set up a datagram socket */
53551362Seric 			if (UdbSock < 0)
53651362Seric 			{
53751362Seric 				UdbSock = socket(AF_INET, SOCK_DGRAM, 0);
53851362Seric 				(void) fcntl(UdbSock, F_SETFD, 1);
53951362Seric 			}
54051362Seric 			break;
54151362Seric 
54251362Seric 		  case '@':	/* forward to remote host */
54351362Seric 			up->udb_type = UDB_FORWARD;
54451362Seric 			up->udb_fwdhost = spec + 1;
54551362Seric 			up++;
54651362Seric 			break;
54751362Seric 
54851362Seric 		  case '/':	/* look up remote name */
54951831Seric 			up->udb_dbname = spec;
55051923Seric 			errno = 0;
55151362Seric 			up->udb_dbp = dbopen(spec, O_RDONLY, 0644, DB_BTREE, NULL);
55251362Seric 			if (up->udb_dbp == NULL)
55351923Seric 			{
55451923Seric 				if (errno != ENOENT && errno != EACCES)
55551951Seric 				{
55651951Seric 					up->udb_type = UDB_EOLIST;
55751951Seric 					goto tempfail;
55851951Seric 				}
55951362Seric 				break;
56051923Seric 			}
56151951Seric 			up->udb_type = UDB_DBFETCH;
56251362Seric 			up++;
56351362Seric 			break;
56451360Seric 		}
56551362Seric 	}
56651362Seric 	up->udb_type = UDB_EOLIST;
56751360Seric 
56851362Seric 	if (tTd(28, 4))
56951362Seric 	{
57051951Seric 		for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++)
57151360Seric 		{
57251362Seric 			switch (up->udb_type)
57351362Seric 			{
57451362Seric 			  case UDB_REMOTE:
57551362Seric 				printf("REMOTE: addr %s, timeo %d\n",
57651362Seric 					inet_ntoa(up->udb_addr.sin_addr),
57751362Seric 					up->udb_timeout);
57851362Seric 				break;
57951362Seric 
58051951Seric 			  case UDB_DBFETCH:
58151951Seric 				printf("FETCH: file %s\n",
58251830Seric 					up->udb_dbname);
58351362Seric 				break;
58451362Seric 
58551362Seric 			  case UDB_FORWARD:
58651362Seric 				printf("FORWARD: host %s\n",
58751362Seric 					up->udb_fwdhost);
58851362Seric 				break;
58951362Seric 
59051362Seric 			  default:
59151362Seric 				printf("UNKNOWN\n");
59251362Seric 				break;
59351362Seric 			}
59451360Seric 		}
59550581Seric 	}
59651951Seric 
59751951Seric 	UdbInitialized = TRUE;
59851955Seric 	errno = 0;
59951951Seric 	return EX_OK;
60051951Seric 
60151951Seric 	/*
60251951Seric 	**  On temporary failure, back out anything we've already done
60351951Seric 	*/
60451951Seric 
60551951Seric   tempfail:
60651951Seric 	for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++)
60751951Seric 	{
60851951Seric 		if (up->udb_type == UDB_DBFETCH)
60951951Seric 		{
61051951Seric 			(*up->udb_dbp->close)(up->udb_dbp);
61151951Seric 		}
61251951Seric 	}
61351951Seric 	return EX_TEMPFAIL;
61451360Seric }
61550581Seric 
61651363Seric int
61751363Seric _udb_parsespec(udbspec, opt, maxopts)
61851363Seric 	char *udbspec;
61951363Seric 	struct option opt[];
62051363Seric 	int maxopts;
62151363Seric {
62251363Seric 	register char *spec;
62351363Seric 	register char *spec_end;
62451363Seric 	register int optnum;
62551363Seric 
62656795Seric 	spec_end = strchr(udbspec, ':');
62751363Seric 	for (optnum = 0; optnum < maxopts && (spec = spec_end) != NULL; optnum++)
62851363Seric 	{
62951363Seric 		register char *p;
63051363Seric 
63158050Seric 		while (isascii(*spec) && isspace(*spec))
63251363Seric 			spec++;
63356795Seric 		spec_end = strchr(spec, ':');
63451363Seric 		if (spec_end != NULL)
63551363Seric 			*spec_end++ = '\0';
63651363Seric 
63751363Seric 		opt[optnum].name = spec;
63851363Seric 		opt[optnum].val = NULL;
63956795Seric 		p = strchr(spec, '=');
64051363Seric 		if (p != NULL)
64151363Seric 			opt[optnum].val = ++p;
64251363Seric 	}
64351363Seric 	return optnum;
64451363Seric }
64551363Seric 
64651360Seric #else /* not USERDB */
64751360Seric 
64851923Seric int
64955012Seric udbexpand(a, sendq, e)
65051360Seric 	ADDRESS *a;
65151360Seric 	ADDRESS **sendq;
65255012Seric 	ENVELOPE *e;
65351360Seric {
65451923Seric 	return EX_OK;
65550581Seric }
65650581Seric 
65750581Seric #endif /* USERDB */
658