xref: /illumos-gate/usr/src/cmd/sendmail/src/readcf.c (revision e9af4bc0)
17c478bd9Sstevel@tonic-gate /*
2*e9af4bc0SJohn Beck  * Copyright (c) 1998-2006, 2008, 2009 Sendmail, Inc. and its suppliers.
37c478bd9Sstevel@tonic-gate  *	All rights reserved.
47c478bd9Sstevel@tonic-gate  * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
57c478bd9Sstevel@tonic-gate  * Copyright (c) 1988, 1993
67c478bd9Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
97c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
107c478bd9Sstevel@tonic-gate  * the sendmail distribution.
117c478bd9Sstevel@tonic-gate  *
127c478bd9Sstevel@tonic-gate  */
137c478bd9Sstevel@tonic-gate 
147c478bd9Sstevel@tonic-gate #include <sendmail.h>
15058561cbSjbeck #include <sm/sendmail.h>
167c478bd9Sstevel@tonic-gate 
17*e9af4bc0SJohn Beck SM_RCSID("@(#)$Id: readcf.c,v 8.674 2009/10/26 17:47:00 ca Exp $")
187c478bd9Sstevel@tonic-gate 
197c478bd9Sstevel@tonic-gate #if NETINET || NETINET6
207c478bd9Sstevel@tonic-gate # include <arpa/inet.h>
217c478bd9Sstevel@tonic-gate #endif /* NETINET || NETINET6 */
227c478bd9Sstevel@tonic-gate 
237c478bd9Sstevel@tonic-gate #define SECONDS
247c478bd9Sstevel@tonic-gate #define MINUTES	* 60
257c478bd9Sstevel@tonic-gate #define HOUR	* 3600
267c478bd9Sstevel@tonic-gate #define HOURS	HOUR
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate static void	fileclass __P((int, char *, char *, bool, bool, bool));
297c478bd9Sstevel@tonic-gate static char	**makeargv __P((char *));
307c478bd9Sstevel@tonic-gate static void	settimeout __P((char *, char *, bool));
317c478bd9Sstevel@tonic-gate static void	toomany __P((int, int));
327c478bd9Sstevel@tonic-gate static char	*extrquotstr __P((char *, char **, char *, bool *));
337c478bd9Sstevel@tonic-gate static void	parse_class_words __P((int, char *));
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate **  READCF -- read configuration file.
377c478bd9Sstevel@tonic-gate **
387c478bd9Sstevel@tonic-gate **	This routine reads the configuration file and builds the internal
397c478bd9Sstevel@tonic-gate **	form.
407c478bd9Sstevel@tonic-gate **
417c478bd9Sstevel@tonic-gate **	The file is formatted as a sequence of lines, each taken
427c478bd9Sstevel@tonic-gate **	atomically.  The first character of each line describes how
437c478bd9Sstevel@tonic-gate **	the line is to be interpreted.  The lines are:
447c478bd9Sstevel@tonic-gate **		Dxval		Define macro x to have value val.
457c478bd9Sstevel@tonic-gate **		Cxword		Put word into class x.
467c478bd9Sstevel@tonic-gate **		Fxfile [fmt]	Read file for lines to put into
477c478bd9Sstevel@tonic-gate **				class x.  Use scanf string 'fmt'
487c478bd9Sstevel@tonic-gate **				or "%s" if not present.  Fmt should
497c478bd9Sstevel@tonic-gate **				only produce one string-valued result.
507c478bd9Sstevel@tonic-gate **		Hname: value	Define header with field-name 'name'
517c478bd9Sstevel@tonic-gate **				and value as specified; this will be
527c478bd9Sstevel@tonic-gate **				macro expanded immediately before
537c478bd9Sstevel@tonic-gate **				use.
547c478bd9Sstevel@tonic-gate **		Sn		Use rewriting set n.
557c478bd9Sstevel@tonic-gate **		Rlhs rhs	Rewrite addresses that match lhs to
567c478bd9Sstevel@tonic-gate **				be rhs.
577c478bd9Sstevel@tonic-gate **		Mn arg=val...	Define mailer.  n is the internal name.
587c478bd9Sstevel@tonic-gate **				Args specify mailer parameters.
597c478bd9Sstevel@tonic-gate **		Oxvalue		Set option x to value.
607c478bd9Sstevel@tonic-gate **		O option value	Set option (long name) to value.
617c478bd9Sstevel@tonic-gate **		Pname=value	Set precedence name to value.
627c478bd9Sstevel@tonic-gate **		Qn arg=val...	Define queue groups.  n is the internal name.
637c478bd9Sstevel@tonic-gate **				Args specify queue parameters.
647c478bd9Sstevel@tonic-gate **		Vversioncode[/vendorcode]
657c478bd9Sstevel@tonic-gate **				Version level/vendor name of
667c478bd9Sstevel@tonic-gate **				configuration syntax.
677c478bd9Sstevel@tonic-gate **		Kmapname mapclass arguments....
687c478bd9Sstevel@tonic-gate **				Define keyed lookup of a given class.
697c478bd9Sstevel@tonic-gate **				Arguments are class dependent.
707c478bd9Sstevel@tonic-gate **		Eenvar=value	Set the environment value to the given value.
717c478bd9Sstevel@tonic-gate **
727c478bd9Sstevel@tonic-gate **	Parameters:
737c478bd9Sstevel@tonic-gate **		cfname -- configuration file name.
747c478bd9Sstevel@tonic-gate **		safe -- true if this is the system config file;
757c478bd9Sstevel@tonic-gate **			false otherwise.
767c478bd9Sstevel@tonic-gate **		e -- the main envelope.
777c478bd9Sstevel@tonic-gate **
787c478bd9Sstevel@tonic-gate **	Returns:
797c478bd9Sstevel@tonic-gate **		none.
807c478bd9Sstevel@tonic-gate **
817c478bd9Sstevel@tonic-gate **	Side Effects:
827c478bd9Sstevel@tonic-gate **		Builds several internal tables.
837c478bd9Sstevel@tonic-gate */
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate void
readcf(cfname,safe,e)867c478bd9Sstevel@tonic-gate readcf(cfname, safe, e)
877c478bd9Sstevel@tonic-gate 	char *cfname;
887c478bd9Sstevel@tonic-gate 	bool safe;
897c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
907c478bd9Sstevel@tonic-gate {
917c478bd9Sstevel@tonic-gate 	SM_FILE_T *cf;
927c478bd9Sstevel@tonic-gate 	int ruleset = -1;
937c478bd9Sstevel@tonic-gate 	char *q;
947c478bd9Sstevel@tonic-gate 	struct rewrite *rwp = NULL;
957c478bd9Sstevel@tonic-gate 	char *bp;
967c478bd9Sstevel@tonic-gate 	auto char *ep;
977c478bd9Sstevel@tonic-gate 	int nfuzzy;
987c478bd9Sstevel@tonic-gate 	char *file;
997c478bd9Sstevel@tonic-gate 	bool optional;
1007c478bd9Sstevel@tonic-gate 	bool ok;
1017c478bd9Sstevel@tonic-gate 	bool ismap;
1027c478bd9Sstevel@tonic-gate 	int mid;
1037c478bd9Sstevel@tonic-gate 	register char *p;
1047c478bd9Sstevel@tonic-gate 	long sff = SFF_OPENASROOT;
1057c478bd9Sstevel@tonic-gate 	struct stat statb;
1067c478bd9Sstevel@tonic-gate 	char buf[MAXLINE];
107058561cbSjbeck 	int bufsize;
1087c478bd9Sstevel@tonic-gate 	char exbuf[MAXLINE];
1097c478bd9Sstevel@tonic-gate 	char pvpbuf[MAXLINE + MAXATOM];
1107c478bd9Sstevel@tonic-gate 	static char *null_list[1] = { NULL };
1117c478bd9Sstevel@tonic-gate 	extern unsigned char TokTypeNoC[];
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 	FileName = cfname;
1147c478bd9Sstevel@tonic-gate 	LineNumber = 0;
1157c478bd9Sstevel@tonic-gate 
116*e9af4bc0SJohn Beck #if STARTTLS
117*e9af4bc0SJohn Beck 	Srv_SSL_Options = Clt_SSL_Options = SSL_OP_ALL;
118*e9af4bc0SJohn Beck #endif /* STARTTLS */
1197c478bd9Sstevel@tonic-gate 	if (DontLockReadFiles)
1207c478bd9Sstevel@tonic-gate 		sff |= SFF_NOLOCK;
1217c478bd9Sstevel@tonic-gate 	cf = safefopen(cfname, O_RDONLY, 0444, sff);
1227c478bd9Sstevel@tonic-gate 	if (cf == NULL)
1237c478bd9Sstevel@tonic-gate 	{
1247c478bd9Sstevel@tonic-gate 		syserr("cannot open");
1257c478bd9Sstevel@tonic-gate 		finis(false, true, EX_OSFILE);
1267c478bd9Sstevel@tonic-gate 	}
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	if (fstat(sm_io_getinfo(cf, SM_IO_WHAT_FD, NULL), &statb) < 0)
1297c478bd9Sstevel@tonic-gate 	{
1307c478bd9Sstevel@tonic-gate 		syserr("cannot fstat");
1317c478bd9Sstevel@tonic-gate 		finis(false, true, EX_OSFILE);
1327c478bd9Sstevel@tonic-gate 	}
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	if (!S_ISREG(statb.st_mode))
1357c478bd9Sstevel@tonic-gate 	{
1367c478bd9Sstevel@tonic-gate 		syserr("not a plain file");
1377c478bd9Sstevel@tonic-gate 		finis(false, true, EX_OSFILE);
1387c478bd9Sstevel@tonic-gate 	}
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 	if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
1417c478bd9Sstevel@tonic-gate 	{
142*e9af4bc0SJohn Beck 		if (OpMode == MD_DAEMON || OpMode == MD_INITALIAS || OpMode == MD_CHECKCONFIG)
1437c478bd9Sstevel@tonic-gate 			(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
1447c478bd9Sstevel@tonic-gate 					     "%s: WARNING: dangerous write permissions\n",
1457c478bd9Sstevel@tonic-gate 					     FileName);
1467c478bd9Sstevel@tonic-gate 		if (LogLevel > 0)
1477c478bd9Sstevel@tonic-gate 			sm_syslog(LOG_CRIT, NOQID,
1487c478bd9Sstevel@tonic-gate 				  "%s: WARNING: dangerous write permissions",
1497c478bd9Sstevel@tonic-gate 				  FileName);
1507c478bd9Sstevel@tonic-gate 	}
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate #if XLA
1537c478bd9Sstevel@tonic-gate 	xla_zero();
1547c478bd9Sstevel@tonic-gate #endif /* XLA */
1557c478bd9Sstevel@tonic-gate 
156058561cbSjbeck 	while (bufsize = sizeof(buf),
157058561cbSjbeck 	       (bp = fgetfolded(buf, &bufsize, cf)) != NULL)
1587c478bd9Sstevel@tonic-gate 	{
159058561cbSjbeck 		char *nbp;
160058561cbSjbeck 
1617c478bd9Sstevel@tonic-gate 		if (bp[0] == '#')
1627c478bd9Sstevel@tonic-gate 		{
1637c478bd9Sstevel@tonic-gate 			if (bp != buf)
1647c478bd9Sstevel@tonic-gate 				sm_free(bp); /* XXX */
1657c478bd9Sstevel@tonic-gate 			continue;
1667c478bd9Sstevel@tonic-gate 		}
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 		/* do macro expansion mappings */
169058561cbSjbeck 		nbp = translate_dollars(bp, bp, &bufsize);
170058561cbSjbeck 		if (nbp != bp && bp != buf)
171058561cbSjbeck 			sm_free(bp);
172058561cbSjbeck 		bp = nbp;
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate 		/* interpret this line */
1757c478bd9Sstevel@tonic-gate 		errno = 0;
1767c478bd9Sstevel@tonic-gate 		switch (bp[0])
1777c478bd9Sstevel@tonic-gate 		{
1787c478bd9Sstevel@tonic-gate 		  case '\0':
1797c478bd9Sstevel@tonic-gate 		  case '#':		/* comment */
1807c478bd9Sstevel@tonic-gate 			break;
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 		  case 'R':		/* rewriting rule */
1837c478bd9Sstevel@tonic-gate 			if (ruleset < 0)
1847c478bd9Sstevel@tonic-gate 			{
1857c478bd9Sstevel@tonic-gate 				syserr("missing valid ruleset for \"%s\"", bp);
1867c478bd9Sstevel@tonic-gate 				break;
1877c478bd9Sstevel@tonic-gate 			}
1887c478bd9Sstevel@tonic-gate 			for (p = &bp[1]; *p != '\0' && *p != '\t'; p++)
1897c478bd9Sstevel@tonic-gate 				continue;
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 			if (*p == '\0')
1927c478bd9Sstevel@tonic-gate 			{
1937c478bd9Sstevel@tonic-gate 				syserr("invalid rewrite line \"%s\" (tab expected)", bp);
1947c478bd9Sstevel@tonic-gate 				break;
1957c478bd9Sstevel@tonic-gate 			}
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 			/* allocate space for the rule header */
1987c478bd9Sstevel@tonic-gate 			if (rwp == NULL)
1997c478bd9Sstevel@tonic-gate 			{
2007c478bd9Sstevel@tonic-gate 				RewriteRules[ruleset] = rwp =
201058561cbSjbeck 					(struct rewrite *) xalloc(sizeof(*rwp));
2027c478bd9Sstevel@tonic-gate 			}
2037c478bd9Sstevel@tonic-gate 			else
2047c478bd9Sstevel@tonic-gate 			{
205058561cbSjbeck 				rwp->r_next = (struct rewrite *) xalloc(sizeof(*rwp));
2067c478bd9Sstevel@tonic-gate 				rwp = rwp->r_next;
2077c478bd9Sstevel@tonic-gate 			}
2087c478bd9Sstevel@tonic-gate 			rwp->r_next = NULL;
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 			/* expand and save the LHS */
2117c478bd9Sstevel@tonic-gate 			*p = '\0';
212058561cbSjbeck 			expand(&bp[1], exbuf, sizeof(exbuf), e);
2137c478bd9Sstevel@tonic-gate 			rwp->r_lhs = prescan(exbuf, '\t', pvpbuf,
214058561cbSjbeck 					     sizeof(pvpbuf), NULL,
215058561cbSjbeck 					     ConfigLevel >= 9 ? TokTypeNoC : IntTokenTab,
2167c478bd9Sstevel@tonic-gate 					     true);
2177c478bd9Sstevel@tonic-gate 			nfuzzy = 0;
2187c478bd9Sstevel@tonic-gate 			if (rwp->r_lhs != NULL)
2197c478bd9Sstevel@tonic-gate 			{
2207c478bd9Sstevel@tonic-gate 				register char **ap;
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 				rwp->r_lhs = copyplist(rwp->r_lhs, true, NULL);
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 				/* count the number of fuzzy matches in LHS */
2257c478bd9Sstevel@tonic-gate 				for (ap = rwp->r_lhs; *ap != NULL; ap++)
2267c478bd9Sstevel@tonic-gate 				{
2277c478bd9Sstevel@tonic-gate 					char *botch;
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 					botch = NULL;
230058561cbSjbeck 					switch (ap[0][0] & 0377)
2317c478bd9Sstevel@tonic-gate 					{
2327c478bd9Sstevel@tonic-gate 					  case MATCHZANY:
2337c478bd9Sstevel@tonic-gate 					  case MATCHANY:
2347c478bd9Sstevel@tonic-gate 					  case MATCHONE:
2357c478bd9Sstevel@tonic-gate 					  case MATCHCLASS:
2367c478bd9Sstevel@tonic-gate 					  case MATCHNCLASS:
2377c478bd9Sstevel@tonic-gate 						nfuzzy++;
2387c478bd9Sstevel@tonic-gate 						break;
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 					  case MATCHREPL:
241058561cbSjbeck 						botch = "$1-$9";
2427c478bd9Sstevel@tonic-gate 						break;
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 					  case CANONUSER:
2457c478bd9Sstevel@tonic-gate 						botch = "$:";
2467c478bd9Sstevel@tonic-gate 						break;
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 					  case CALLSUBR:
2497c478bd9Sstevel@tonic-gate 						botch = "$>";
2507c478bd9Sstevel@tonic-gate 						break;
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate 					  case CONDIF:
2537c478bd9Sstevel@tonic-gate 						botch = "$?";
2547c478bd9Sstevel@tonic-gate 						break;
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate 					  case CONDFI:
2577c478bd9Sstevel@tonic-gate 						botch = "$.";
2587c478bd9Sstevel@tonic-gate 						break;
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate 					  case HOSTBEGIN:
2617c478bd9Sstevel@tonic-gate 						botch = "$[";
2627c478bd9Sstevel@tonic-gate 						break;
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 					  case HOSTEND:
2657c478bd9Sstevel@tonic-gate 						botch = "$]";
2667c478bd9Sstevel@tonic-gate 						break;
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 					  case LOOKUPBEGIN:
2697c478bd9Sstevel@tonic-gate 						botch = "$(";
2707c478bd9Sstevel@tonic-gate 						break;
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 					  case LOOKUPEND:
2737c478bd9Sstevel@tonic-gate 						botch = "$)";
2747c478bd9Sstevel@tonic-gate 						break;
2757c478bd9Sstevel@tonic-gate 					}
2767c478bd9Sstevel@tonic-gate 					if (botch != NULL)
2777c478bd9Sstevel@tonic-gate 						syserr("Inappropriate use of %s on LHS",
2787c478bd9Sstevel@tonic-gate 							botch);
2797c478bd9Sstevel@tonic-gate 				}
2807c478bd9Sstevel@tonic-gate 				rwp->r_line = LineNumber;
2817c478bd9Sstevel@tonic-gate 			}
2827c478bd9Sstevel@tonic-gate 			else
2837c478bd9Sstevel@tonic-gate 			{
2847c478bd9Sstevel@tonic-gate 				syserr("R line: null LHS");
2857c478bd9Sstevel@tonic-gate 				rwp->r_lhs = null_list;
2867c478bd9Sstevel@tonic-gate 			}
2877c478bd9Sstevel@tonic-gate 			if (nfuzzy > MAXMATCH)
2887c478bd9Sstevel@tonic-gate 			{
2897c478bd9Sstevel@tonic-gate 				syserr("R line: too many wildcards");
2907c478bd9Sstevel@tonic-gate 				rwp->r_lhs = null_list;
2917c478bd9Sstevel@tonic-gate 			}
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 			/* expand and save the RHS */
2947c478bd9Sstevel@tonic-gate 			while (*++p == '\t')
2957c478bd9Sstevel@tonic-gate 				continue;
2967c478bd9Sstevel@tonic-gate 			q = p;
2977c478bd9Sstevel@tonic-gate 			while (*p != '\0' && *p != '\t')
2987c478bd9Sstevel@tonic-gate 				p++;
2997c478bd9Sstevel@tonic-gate 			*p = '\0';
300058561cbSjbeck 			expand(q, exbuf, sizeof(exbuf), e);
3017c478bd9Sstevel@tonic-gate 			rwp->r_rhs = prescan(exbuf, '\t', pvpbuf,
302058561cbSjbeck 					     sizeof(pvpbuf), NULL,
303058561cbSjbeck 					     ConfigLevel >= 9 ? TokTypeNoC : IntTokenTab,
3047c478bd9Sstevel@tonic-gate 					     true);
3057c478bd9Sstevel@tonic-gate 			if (rwp->r_rhs != NULL)
3067c478bd9Sstevel@tonic-gate 			{
3077c478bd9Sstevel@tonic-gate 				register char **ap;
3087c478bd9Sstevel@tonic-gate 				int args, endtoken;
3097c478bd9Sstevel@tonic-gate #if _FFR_EXTRA_MAP_CHECK
3107c478bd9Sstevel@tonic-gate 				int nexttoken;
3117c478bd9Sstevel@tonic-gate #endif /* _FFR_EXTRA_MAP_CHECK */
3127c478bd9Sstevel@tonic-gate 				bool inmap;
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 				rwp->r_rhs = copyplist(rwp->r_rhs, true, NULL);
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 				/* check no out-of-bounds replacements */
3177c478bd9Sstevel@tonic-gate 				nfuzzy += '0';
3187c478bd9Sstevel@tonic-gate 				inmap = false;
3197c478bd9Sstevel@tonic-gate 				args = 0;
3207c478bd9Sstevel@tonic-gate 				endtoken = 0;
3217c478bd9Sstevel@tonic-gate 				for (ap = rwp->r_rhs; *ap != NULL; ap++)
3227c478bd9Sstevel@tonic-gate 				{
3237c478bd9Sstevel@tonic-gate 					char *botch;
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 					botch = NULL;
326058561cbSjbeck 					switch (ap[0][0] & 0377)
3277c478bd9Sstevel@tonic-gate 					{
3287c478bd9Sstevel@tonic-gate 					  case MATCHREPL:
329058561cbSjbeck 						if (ap[0][1] <= '0' ||
330058561cbSjbeck 						    ap[0][1] > nfuzzy)
3317c478bd9Sstevel@tonic-gate 						{
3327c478bd9Sstevel@tonic-gate 							syserr("replacement $%c out of bounds",
333058561cbSjbeck 								ap[0][1]);
3347c478bd9Sstevel@tonic-gate 						}
3357c478bd9Sstevel@tonic-gate 						break;
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate 					  case MATCHZANY:
3387c478bd9Sstevel@tonic-gate 						botch = "$*";
3397c478bd9Sstevel@tonic-gate 						break;
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 					  case MATCHANY:
3427c478bd9Sstevel@tonic-gate 						botch = "$+";
3437c478bd9Sstevel@tonic-gate 						break;
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 					  case MATCHONE:
3467c478bd9Sstevel@tonic-gate 						botch = "$-";
3477c478bd9Sstevel@tonic-gate 						break;
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate 					  case MATCHCLASS:
3507c478bd9Sstevel@tonic-gate 						botch = "$=";
3517c478bd9Sstevel@tonic-gate 						break;
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate 					  case MATCHNCLASS:
3547c478bd9Sstevel@tonic-gate 						botch = "$~";
3557c478bd9Sstevel@tonic-gate 						break;
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 					  case CANONHOST:
3587c478bd9Sstevel@tonic-gate 						if (!inmap)
3597c478bd9Sstevel@tonic-gate 							break;
3607c478bd9Sstevel@tonic-gate 						if (++args >= MAX_MAP_ARGS)
3617c478bd9Sstevel@tonic-gate 							syserr("too many arguments for map lookup");
3627c478bd9Sstevel@tonic-gate 						break;
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate 					  case HOSTBEGIN:
3657c478bd9Sstevel@tonic-gate 						endtoken = HOSTEND;
3667c478bd9Sstevel@tonic-gate 						/* FALLTHROUGH */
3677c478bd9Sstevel@tonic-gate 					  case LOOKUPBEGIN:
3687c478bd9Sstevel@tonic-gate 						/* see above... */
369058561cbSjbeck 						if ((ap[0][0] & 0377) == LOOKUPBEGIN)
3707c478bd9Sstevel@tonic-gate 							endtoken = LOOKUPEND;
3717c478bd9Sstevel@tonic-gate 						if (inmap)
3727c478bd9Sstevel@tonic-gate 							syserr("cannot nest map lookups");
3737c478bd9Sstevel@tonic-gate 						inmap = true;
3747c478bd9Sstevel@tonic-gate 						args = 0;
3757c478bd9Sstevel@tonic-gate #if _FFR_EXTRA_MAP_CHECK
376058561cbSjbeck 						if (ap[1] == NULL)
3777c478bd9Sstevel@tonic-gate 						{
3787c478bd9Sstevel@tonic-gate 							syserr("syntax error in map lookup");
3797c478bd9Sstevel@tonic-gate 							break;
3807c478bd9Sstevel@tonic-gate 						}
381058561cbSjbeck 						nexttoken = ap[1][0] & 0377;
3827c478bd9Sstevel@tonic-gate 						if (nexttoken == CANONHOST ||
3837c478bd9Sstevel@tonic-gate 						    nexttoken == CANONUSER ||
384058561cbSjbeck 						    nexttoken == endtoken))
3857c478bd9Sstevel@tonic-gate 						{
3867c478bd9Sstevel@tonic-gate 							syserr("missing map name for lookup");
3877c478bd9Sstevel@tonic-gate 							break;
3887c478bd9Sstevel@tonic-gate 						}
389058561cbSjbeck 						if (ap[2] == NULL)
3907c478bd9Sstevel@tonic-gate 						{
3917c478bd9Sstevel@tonic-gate 							syserr("syntax error in map lookup");
3927c478bd9Sstevel@tonic-gate 							break;
3937c478bd9Sstevel@tonic-gate 						}
394058561cbSjbeck 						if (ap[0][0] == HOSTBEGIN)
3957c478bd9Sstevel@tonic-gate 							break;
396058561cbSjbeck 						nexttoken = ap[2][0] & 0377;
3977c478bd9Sstevel@tonic-gate 						if (nexttoken == CANONHOST ||
3987c478bd9Sstevel@tonic-gate 						    nexttoken == CANONUSER ||
3997c478bd9Sstevel@tonic-gate 						    nexttoken == endtoken)
4007c478bd9Sstevel@tonic-gate 						{
4017c478bd9Sstevel@tonic-gate 							syserr("missing key name for lookup");
4027c478bd9Sstevel@tonic-gate 							break;
4037c478bd9Sstevel@tonic-gate 						}
4047c478bd9Sstevel@tonic-gate #endif /* _FFR_EXTRA_MAP_CHECK */
4057c478bd9Sstevel@tonic-gate 						break;
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate 					  case HOSTEND:
4087c478bd9Sstevel@tonic-gate 					  case LOOKUPEND:
409058561cbSjbeck 						if ((ap[0][0] & 0377) != endtoken)
4107c478bd9Sstevel@tonic-gate 							break;
4117c478bd9Sstevel@tonic-gate 						inmap = false;
4127c478bd9Sstevel@tonic-gate 						endtoken = 0;
4137c478bd9Sstevel@tonic-gate 						break;
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate #if 0
4177c478bd9Sstevel@tonic-gate /*
4187c478bd9Sstevel@tonic-gate **  This doesn't work yet as there are maps defined *after* the cf
4197c478bd9Sstevel@tonic-gate **  is read such as host, user, and alias.  So for now, it's removed.
4207c478bd9Sstevel@tonic-gate **  When it comes back, the RELEASE_NOTES entry will be:
4217c478bd9Sstevel@tonic-gate **	Emit warnings for unknown maps when reading the .cf file.  Based on
4227c478bd9Sstevel@tonic-gate **		patch from Robert Harker of Harker Systems.
4237c478bd9Sstevel@tonic-gate */
4247c478bd9Sstevel@tonic-gate 
4257c478bd9Sstevel@tonic-gate 					  case LOOKUPBEGIN:
4267c478bd9Sstevel@tonic-gate 						/*
4277c478bd9Sstevel@tonic-gate 						**  Got a database lookup,
4287c478bd9Sstevel@tonic-gate 						**  check if map is defined.
4297c478bd9Sstevel@tonic-gate 						*/
4307c478bd9Sstevel@tonic-gate 
431058561cbSjbeck 						ep = ap[1];
432058561cbSjbeck 						if ((ep[0] & 0377) != MACRODEXPAND &&
433058561cbSjbeck 						    stab(ep, ST_MAP, ST_FIND) == NULL)
4347c478bd9Sstevel@tonic-gate 						{
4357c478bd9Sstevel@tonic-gate 							(void) sm_io_fprintf(smioout,
4367c478bd9Sstevel@tonic-gate 									     SM_TIME_DEFAULT,
4377c478bd9Sstevel@tonic-gate 									     "Warning: %s: line %d: map %s not found\n",
4387c478bd9Sstevel@tonic-gate 									     FileName,
4397c478bd9Sstevel@tonic-gate 									     LineNumber,
4407c478bd9Sstevel@tonic-gate 									     ep);
4417c478bd9Sstevel@tonic-gate 						}
4427c478bd9Sstevel@tonic-gate 						break;
4437c478bd9Sstevel@tonic-gate #endif /* 0 */
4447c478bd9Sstevel@tonic-gate 					}
4457c478bd9Sstevel@tonic-gate 					if (botch != NULL)
4467c478bd9Sstevel@tonic-gate 						syserr("Inappropriate use of %s on RHS",
4477c478bd9Sstevel@tonic-gate 							botch);
4487c478bd9Sstevel@tonic-gate 				}
4497c478bd9Sstevel@tonic-gate 				if (inmap)
4507c478bd9Sstevel@tonic-gate 					syserr("missing map closing token");
4517c478bd9Sstevel@tonic-gate 			}
4527c478bd9Sstevel@tonic-gate 			else
4537c478bd9Sstevel@tonic-gate 			{
4547c478bd9Sstevel@tonic-gate 				syserr("R line: null RHS");
4557c478bd9Sstevel@tonic-gate 				rwp->r_rhs = null_list;
4567c478bd9Sstevel@tonic-gate 			}
4577c478bd9Sstevel@tonic-gate 			break;
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate 		  case 'S':		/* select rewriting set */
460058561cbSjbeck 			expand(&bp[1], exbuf, sizeof(exbuf), e);
4617c478bd9Sstevel@tonic-gate 			ruleset = strtorwset(exbuf, NULL, ST_ENTER);
4627c478bd9Sstevel@tonic-gate 			if (ruleset < 0)
4637c478bd9Sstevel@tonic-gate 				break;
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 			rwp = RewriteRules[ruleset];
4667c478bd9Sstevel@tonic-gate 			if (rwp != NULL)
4677c478bd9Sstevel@tonic-gate 			{
468*e9af4bc0SJohn Beck 				if (OpMode == MD_TEST || OpMode == MD_CHECKCONFIG)
4697c478bd9Sstevel@tonic-gate 					(void) sm_io_fprintf(smioout,
4707c478bd9Sstevel@tonic-gate 							     SM_TIME_DEFAULT,
4717c478bd9Sstevel@tonic-gate 							     "WARNING: Ruleset %s has multiple definitions\n",
4727c478bd9Sstevel@tonic-gate 							    &bp[1]);
4737c478bd9Sstevel@tonic-gate 				if (tTd(37, 1))
4747c478bd9Sstevel@tonic-gate 					sm_dprintf("WARNING: Ruleset %s has multiple definitions\n",
4757c478bd9Sstevel@tonic-gate 						   &bp[1]);
4767c478bd9Sstevel@tonic-gate 				while (rwp->r_next != NULL)
4777c478bd9Sstevel@tonic-gate 					rwp = rwp->r_next;
4787c478bd9Sstevel@tonic-gate 			}
4797c478bd9Sstevel@tonic-gate 			break;
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate 		  case 'D':		/* macro definition */
4827c478bd9Sstevel@tonic-gate 			mid = macid_parse(&bp[1], &ep);
4837c478bd9Sstevel@tonic-gate 			if (mid == 0)
4847c478bd9Sstevel@tonic-gate 				break;
4857c478bd9Sstevel@tonic-gate 			p = munchstring(ep, NULL, '\0');
4867c478bd9Sstevel@tonic-gate 			macdefine(&e->e_macro, A_TEMP, mid, p);
4877c478bd9Sstevel@tonic-gate 			break;
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate 		  case 'H':		/* required header line */
4907c478bd9Sstevel@tonic-gate 			(void) chompheader(&bp[1], CHHDR_DEF, NULL, e);
4917c478bd9Sstevel@tonic-gate 			break;
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 		  case 'C':		/* word class */
4947c478bd9Sstevel@tonic-gate 		  case 'T':		/* trusted user (set class `t') */
4957c478bd9Sstevel@tonic-gate 			if (bp[0] == 'C')
4967c478bd9Sstevel@tonic-gate 			{
4977c478bd9Sstevel@tonic-gate 				mid = macid_parse(&bp[1], &ep);
4987c478bd9Sstevel@tonic-gate 				if (mid == 0)
4997c478bd9Sstevel@tonic-gate 					break;
500058561cbSjbeck 				expand(ep, exbuf, sizeof(exbuf), e);
5017c478bd9Sstevel@tonic-gate 				p = exbuf;
5027c478bd9Sstevel@tonic-gate 			}
5037c478bd9Sstevel@tonic-gate 			else
5047c478bd9Sstevel@tonic-gate 			{
5057c478bd9Sstevel@tonic-gate 				mid = 't';
5067c478bd9Sstevel@tonic-gate 				p = &bp[1];
5077c478bd9Sstevel@tonic-gate 			}
5087c478bd9Sstevel@tonic-gate 			while (*p != '\0')
5097c478bd9Sstevel@tonic-gate 			{
5107c478bd9Sstevel@tonic-gate 				register char *wd;
5117c478bd9Sstevel@tonic-gate 				char delim;
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate 				while (*p != '\0' && isascii(*p) && isspace(*p))
5147c478bd9Sstevel@tonic-gate 					p++;
5157c478bd9Sstevel@tonic-gate 				wd = p;
5167c478bd9Sstevel@tonic-gate 				while (*p != '\0' && !(isascii(*p) && isspace(*p)))
5177c478bd9Sstevel@tonic-gate 					p++;
5187c478bd9Sstevel@tonic-gate 				delim = *p;
5197c478bd9Sstevel@tonic-gate 				*p = '\0';
5207c478bd9Sstevel@tonic-gate 				if (wd[0] != '\0')
5217c478bd9Sstevel@tonic-gate 					setclass(mid, wd);
5227c478bd9Sstevel@tonic-gate 				*p = delim;
5237c478bd9Sstevel@tonic-gate 			}
5247c478bd9Sstevel@tonic-gate 			break;
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 		  case 'F':		/* word class from file */
5277c478bd9Sstevel@tonic-gate 			mid = macid_parse(&bp[1], &ep);
5287c478bd9Sstevel@tonic-gate 			if (mid == 0)
5297c478bd9Sstevel@tonic-gate 				break;
5307c478bd9Sstevel@tonic-gate 			for (p = ep; isascii(*p) && isspace(*p); )
5317c478bd9Sstevel@tonic-gate 				p++;
5327c478bd9Sstevel@tonic-gate 			if (p[0] == '-' && p[1] == 'o')
5337c478bd9Sstevel@tonic-gate 			{
5347c478bd9Sstevel@tonic-gate 				optional = true;
5357c478bd9Sstevel@tonic-gate 				while (*p != '\0' &&
5367c478bd9Sstevel@tonic-gate 				       !(isascii(*p) && isspace(*p)))
5377c478bd9Sstevel@tonic-gate 					p++;
5387c478bd9Sstevel@tonic-gate 				while (isascii(*p) && isspace(*p))
5397c478bd9Sstevel@tonic-gate 					p++;
5407c478bd9Sstevel@tonic-gate 			}
5417c478bd9Sstevel@tonic-gate 			else
5427c478bd9Sstevel@tonic-gate 				optional = false;
5437c478bd9Sstevel@tonic-gate 
5447c478bd9Sstevel@tonic-gate 			/* check if [key]@map:spec */
5457c478bd9Sstevel@tonic-gate 			ismap = false;
5467c478bd9Sstevel@tonic-gate 			if (!SM_IS_DIR_DELIM(*p) &&
5477c478bd9Sstevel@tonic-gate 			    *p != '|' &&
5487c478bd9Sstevel@tonic-gate 			    (q = strchr(p, '@')) != NULL)
5497c478bd9Sstevel@tonic-gate 			{
5507c478bd9Sstevel@tonic-gate 				q++;
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate 				/* look for @LDAP or @map: in string */
5537c478bd9Sstevel@tonic-gate 				if (strcmp(q, "LDAP") == 0 ||
5547c478bd9Sstevel@tonic-gate 				    (*q != ':' &&
5557c478bd9Sstevel@tonic-gate 				     strchr(q, ':') != NULL))
5567c478bd9Sstevel@tonic-gate 					ismap = true;
5577c478bd9Sstevel@tonic-gate 			}
5587c478bd9Sstevel@tonic-gate 
5597c478bd9Sstevel@tonic-gate 			if (ismap)
5607c478bd9Sstevel@tonic-gate 			{
5617c478bd9Sstevel@tonic-gate 				/* use entire spec */
5627c478bd9Sstevel@tonic-gate 				file = p;
5637c478bd9Sstevel@tonic-gate 			}
5647c478bd9Sstevel@tonic-gate 			else
5657c478bd9Sstevel@tonic-gate 			{
5667c478bd9Sstevel@tonic-gate 				file = extrquotstr(p, &q, " ", &ok);
5677c478bd9Sstevel@tonic-gate 				if (!ok)
5687c478bd9Sstevel@tonic-gate 				{
5697c478bd9Sstevel@tonic-gate 					syserr("illegal filename '%s'", p);
5707c478bd9Sstevel@tonic-gate 					break;
5717c478bd9Sstevel@tonic-gate 				}
5727c478bd9Sstevel@tonic-gate 			}
5737c478bd9Sstevel@tonic-gate 
5747c478bd9Sstevel@tonic-gate 			if (*file == '|' || ismap)
5757c478bd9Sstevel@tonic-gate 				p = "%s";
5767c478bd9Sstevel@tonic-gate 			else
5777c478bd9Sstevel@tonic-gate 			{
5787c478bd9Sstevel@tonic-gate 				p = q;
5797c478bd9Sstevel@tonic-gate 				if (*p == '\0')
5807c478bd9Sstevel@tonic-gate 					p = "%s";
5817c478bd9Sstevel@tonic-gate 				else
5827c478bd9Sstevel@tonic-gate 				{
5837c478bd9Sstevel@tonic-gate 					*p = '\0';
5847c478bd9Sstevel@tonic-gate 					while (isascii(*++p) && isspace(*p))
5857c478bd9Sstevel@tonic-gate 						continue;
5867c478bd9Sstevel@tonic-gate 				}
5877c478bd9Sstevel@tonic-gate 			}
5887c478bd9Sstevel@tonic-gate 			fileclass(mid, file, p, ismap, safe, optional);
5897c478bd9Sstevel@tonic-gate 			break;
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate #if XLA
5927c478bd9Sstevel@tonic-gate 		  case 'L':		/* extended load average description */
5937c478bd9Sstevel@tonic-gate 			xla_init(&bp[1]);
5947c478bd9Sstevel@tonic-gate 			break;
5957c478bd9Sstevel@tonic-gate #endif /* XLA */
5967c478bd9Sstevel@tonic-gate 
5977c478bd9Sstevel@tonic-gate #if defined(SUN_EXTENSIONS) && defined(SUN_LOOKUP_MACRO)
5987c478bd9Sstevel@tonic-gate 		  case 'L':		/* lookup macro */
5997c478bd9Sstevel@tonic-gate 		  case 'G':		/* lookup class */
6007c478bd9Sstevel@tonic-gate 			/* reserved for Sun -- NIS+ database lookup */
6017c478bd9Sstevel@tonic-gate 			if (VendorCode != VENDOR_SUN)
6027c478bd9Sstevel@tonic-gate 				goto badline;
6037c478bd9Sstevel@tonic-gate 			sun_lg_config_line(bp, e);
6047c478bd9Sstevel@tonic-gate 			break;
6057c478bd9Sstevel@tonic-gate #endif /* defined(SUN_EXTENSIONS) && defined(SUN_LOOKUP_MACRO) */
6067c478bd9Sstevel@tonic-gate 
6077c478bd9Sstevel@tonic-gate 		  case 'M':		/* define mailer */
6087c478bd9Sstevel@tonic-gate 			makemailer(&bp[1]);
6097c478bd9Sstevel@tonic-gate 			break;
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate 		  case 'O':		/* set option */
6127c478bd9Sstevel@tonic-gate 			setoption(bp[1], &bp[2], safe, false, e);
6137c478bd9Sstevel@tonic-gate 			break;
6147c478bd9Sstevel@tonic-gate 
6157c478bd9Sstevel@tonic-gate 		  case 'P':		/* set precedence */
6167c478bd9Sstevel@tonic-gate 			if (NumPriorities >= MAXPRIORITIES)
6177c478bd9Sstevel@tonic-gate 			{
6187c478bd9Sstevel@tonic-gate 				toomany('P', MAXPRIORITIES);
6197c478bd9Sstevel@tonic-gate 				break;
6207c478bd9Sstevel@tonic-gate 			}
6217c478bd9Sstevel@tonic-gate 			for (p = &bp[1]; *p != '\0' && *p != '='; p++)
6227c478bd9Sstevel@tonic-gate 				continue;
6237c478bd9Sstevel@tonic-gate 			if (*p == '\0')
6247c478bd9Sstevel@tonic-gate 				goto badline;
6257c478bd9Sstevel@tonic-gate 			*p = '\0';
6267c478bd9Sstevel@tonic-gate 			Priorities[NumPriorities].pri_name = newstr(&bp[1]);
6277c478bd9Sstevel@tonic-gate 			Priorities[NumPriorities].pri_val = atoi(++p);
6287c478bd9Sstevel@tonic-gate 			NumPriorities++;
6297c478bd9Sstevel@tonic-gate 			break;
6307c478bd9Sstevel@tonic-gate 
6317c478bd9Sstevel@tonic-gate 		  case 'Q':		/* define queue */
6327c478bd9Sstevel@tonic-gate 			makequeue(&bp[1], true);
6337c478bd9Sstevel@tonic-gate 			break;
6347c478bd9Sstevel@tonic-gate 
6357c478bd9Sstevel@tonic-gate 		  case 'V':		/* configuration syntax version */
6367c478bd9Sstevel@tonic-gate 			for (p = &bp[1]; isascii(*p) && isspace(*p); p++)
6377c478bd9Sstevel@tonic-gate 				continue;
6387c478bd9Sstevel@tonic-gate 			if (!isascii(*p) || !isdigit(*p))
6397c478bd9Sstevel@tonic-gate 			{
6407c478bd9Sstevel@tonic-gate 				syserr("invalid argument to V line: \"%.20s\"",
6417c478bd9Sstevel@tonic-gate 					&bp[1]);
6427c478bd9Sstevel@tonic-gate 				break;
6437c478bd9Sstevel@tonic-gate 			}
6447c478bd9Sstevel@tonic-gate 			ConfigLevel = strtol(p, &ep, 10);
6457c478bd9Sstevel@tonic-gate 
6467c478bd9Sstevel@tonic-gate 			/*
6477c478bd9Sstevel@tonic-gate 			**  Do heuristic tweaking for back compatibility.
6487c478bd9Sstevel@tonic-gate 			*/
6497c478bd9Sstevel@tonic-gate 
6507c478bd9Sstevel@tonic-gate 			if (ConfigLevel >= 5)
6517c478bd9Sstevel@tonic-gate 			{
6527c478bd9Sstevel@tonic-gate 				/* level 5 configs have short name in $w */
6537c478bd9Sstevel@tonic-gate 				p = macvalue('w', e);
6547c478bd9Sstevel@tonic-gate 				if (p != NULL && (p = strchr(p, '.')) != NULL)
6557c478bd9Sstevel@tonic-gate 				{
6567c478bd9Sstevel@tonic-gate 					*p = '\0';
6577c478bd9Sstevel@tonic-gate 					macdefine(&e->e_macro, A_TEMP, 'w',
6587c478bd9Sstevel@tonic-gate 						  macvalue('w', e));
6597c478bd9Sstevel@tonic-gate 				}
6607c478bd9Sstevel@tonic-gate 			}
6617c478bd9Sstevel@tonic-gate 			if (ConfigLevel >= 6)
6627c478bd9Sstevel@tonic-gate 			{
6637c478bd9Sstevel@tonic-gate 				ColonOkInAddr = false;
6647c478bd9Sstevel@tonic-gate 			}
6657c478bd9Sstevel@tonic-gate 
6667c478bd9Sstevel@tonic-gate 			/*
6677c478bd9Sstevel@tonic-gate 			**  Look for vendor code.
6687c478bd9Sstevel@tonic-gate 			*/
6697c478bd9Sstevel@tonic-gate 
6707c478bd9Sstevel@tonic-gate 			if (*ep++ == '/')
6717c478bd9Sstevel@tonic-gate 			{
6727c478bd9Sstevel@tonic-gate 				/* extract vendor code */
6737c478bd9Sstevel@tonic-gate 				for (p = ep; isascii(*p) && isalpha(*p); )
6747c478bd9Sstevel@tonic-gate 					p++;
6757c478bd9Sstevel@tonic-gate 				*p = '\0';
6767c478bd9Sstevel@tonic-gate 
6777c478bd9Sstevel@tonic-gate 				if (!setvendor(ep))
6787c478bd9Sstevel@tonic-gate 					syserr("invalid V line vendor code: \"%s\"",
6797c478bd9Sstevel@tonic-gate 						ep);
6807c478bd9Sstevel@tonic-gate 			}
6817c478bd9Sstevel@tonic-gate 			break;
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate 		  case 'K':
684058561cbSjbeck 			expand(&bp[1], exbuf, sizeof(exbuf), e);
6857c478bd9Sstevel@tonic-gate 			(void) makemapentry(exbuf);
6867c478bd9Sstevel@tonic-gate 			break;
6877c478bd9Sstevel@tonic-gate 
6887c478bd9Sstevel@tonic-gate 		  case 'E':
6897c478bd9Sstevel@tonic-gate 			p = strchr(bp, '=');
6907c478bd9Sstevel@tonic-gate 			if (p != NULL)
6917c478bd9Sstevel@tonic-gate 				*p++ = '\0';
692445f2479Sjbeck 			sm_setuserenv(&bp[1], p);
6937c478bd9Sstevel@tonic-gate 			break;
6947c478bd9Sstevel@tonic-gate 
6957c478bd9Sstevel@tonic-gate 		  case 'X':		/* mail filter */
6967c478bd9Sstevel@tonic-gate #if MILTER
6977c478bd9Sstevel@tonic-gate 			milter_setup(&bp[1]);
6987c478bd9Sstevel@tonic-gate #else /* MILTER */
6997c478bd9Sstevel@tonic-gate 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
7007c478bd9Sstevel@tonic-gate 					     "Warning: Filter usage ('X') requires Milter support (-DMILTER)\n");
7017c478bd9Sstevel@tonic-gate #endif /* MILTER */
7027c478bd9Sstevel@tonic-gate 			break;
7037c478bd9Sstevel@tonic-gate 
7047c478bd9Sstevel@tonic-gate 		  default:
7057c478bd9Sstevel@tonic-gate 		  badline:
7067c478bd9Sstevel@tonic-gate 			syserr("unknown configuration line \"%s\"", bp);
7077c478bd9Sstevel@tonic-gate 		}
7087c478bd9Sstevel@tonic-gate 		if (bp != buf)
7097c478bd9Sstevel@tonic-gate 			sm_free(bp); /* XXX */
7107c478bd9Sstevel@tonic-gate 	}
7117c478bd9Sstevel@tonic-gate 	if (sm_io_error(cf))
7127c478bd9Sstevel@tonic-gate 	{
7137c478bd9Sstevel@tonic-gate 		syserr("I/O read error");
7147c478bd9Sstevel@tonic-gate 		finis(false, true, EX_OSFILE);
7157c478bd9Sstevel@tonic-gate 	}
7167c478bd9Sstevel@tonic-gate 	(void) sm_io_close(cf, SM_TIME_DEFAULT);
7177c478bd9Sstevel@tonic-gate 	FileName = NULL;
7187c478bd9Sstevel@tonic-gate 
7197c478bd9Sstevel@tonic-gate 	/* initialize host maps from local service tables */
7207c478bd9Sstevel@tonic-gate 	inithostmaps();
7217c478bd9Sstevel@tonic-gate 
7227c478bd9Sstevel@tonic-gate 	/* initialize daemon (if not defined yet) */
7237c478bd9Sstevel@tonic-gate 	initdaemon();
7247c478bd9Sstevel@tonic-gate 
7257c478bd9Sstevel@tonic-gate 	/* determine if we need to do special name-server frotz */
7267c478bd9Sstevel@tonic-gate 	{
7277c478bd9Sstevel@tonic-gate 		int nmaps;
7287c478bd9Sstevel@tonic-gate 		char *maptype[MAXMAPSTACK];
7297c478bd9Sstevel@tonic-gate 		short mapreturn[MAXMAPACTIONS];
7307c478bd9Sstevel@tonic-gate 
7317c478bd9Sstevel@tonic-gate 		nmaps = switch_map_find("hosts", maptype, mapreturn);
7327c478bd9Sstevel@tonic-gate 		UseNameServer = false;
7337c478bd9Sstevel@tonic-gate 		if (nmaps > 0 && nmaps <= MAXMAPSTACK)
7347c478bd9Sstevel@tonic-gate 		{
7357c478bd9Sstevel@tonic-gate 			register int mapno;
7367c478bd9Sstevel@tonic-gate 
7377c478bd9Sstevel@tonic-gate 			for (mapno = 0; mapno < nmaps && !UseNameServer;
7387c478bd9Sstevel@tonic-gate 			     mapno++)
7397c478bd9Sstevel@tonic-gate 			{
7407c478bd9Sstevel@tonic-gate 				if (strcmp(maptype[mapno], "dns") == 0)
7417c478bd9Sstevel@tonic-gate 					UseNameServer = true;
7427c478bd9Sstevel@tonic-gate 			}
7437c478bd9Sstevel@tonic-gate 		}
7447c478bd9Sstevel@tonic-gate 	}
7457c478bd9Sstevel@tonic-gate }
746058561cbSjbeck 
7477c478bd9Sstevel@tonic-gate /*
7487c478bd9Sstevel@tonic-gate **  TRANSLATE_DOLLARS -- convert $x into internal form
7497c478bd9Sstevel@tonic-gate **
7507c478bd9Sstevel@tonic-gate **	Actually does all appropriate pre-processing of a config line
7517c478bd9Sstevel@tonic-gate **	to turn it into internal form.
7527c478bd9Sstevel@tonic-gate **
7537c478bd9Sstevel@tonic-gate **	Parameters:
754058561cbSjbeck **		ibp -- the buffer to translate.
755058561cbSjbeck **		obp -- where to put the translation; may be the same as obp
756058561cbSjbeck **		bsp -- a pointer to the size of obp; will be updated if
757058561cbSjbeck **			the buffer needs to be replaced.
7587c478bd9Sstevel@tonic-gate **
7597c478bd9Sstevel@tonic-gate **	Returns:
760058561cbSjbeck **		The buffer pointer; may differ from obp if the expansion
761058561cbSjbeck **		is larger then *bsp, in which case this will point to
762058561cbSjbeck **		malloc()ed memory which must be free()d by the caller.
7637c478bd9Sstevel@tonic-gate */
7647c478bd9Sstevel@tonic-gate 
765058561cbSjbeck char *
translate_dollars(ibp,obp,bsp)766058561cbSjbeck translate_dollars(ibp, obp, bsp)
767058561cbSjbeck 	char *ibp;
768058561cbSjbeck 	char *obp;
769058561cbSjbeck 	int *bsp;
7707c478bd9Sstevel@tonic-gate {
7717c478bd9Sstevel@tonic-gate 	register char *p;
7727c478bd9Sstevel@tonic-gate 	auto char *ep;
773058561cbSjbeck 	char *bp;
774058561cbSjbeck 
775058561cbSjbeck 	if (tTd(37, 53))
776058561cbSjbeck 	{
777058561cbSjbeck 		sm_dprintf("translate_dollars(");
778058561cbSjbeck 		xputs(sm_debug_file(), ibp);
779058561cbSjbeck 		sm_dprintf(")\n");
780058561cbSjbeck 	}
781058561cbSjbeck 
782058561cbSjbeck 	bp = quote_internal_chars(ibp, obp, bsp);
7837c478bd9Sstevel@tonic-gate 
7847c478bd9Sstevel@tonic-gate 	for (p = bp; *p != '\0'; p++)
7857c478bd9Sstevel@tonic-gate 	{
7867c478bd9Sstevel@tonic-gate 		if (*p == '#' && p > bp && ConfigLevel >= 3)
7877c478bd9Sstevel@tonic-gate 		{
7887c478bd9Sstevel@tonic-gate 			register char *e;
7897c478bd9Sstevel@tonic-gate 
7907c478bd9Sstevel@tonic-gate 			switch (*--p & 0377)
7917c478bd9Sstevel@tonic-gate 			{
7927c478bd9Sstevel@tonic-gate 			  case MACROEXPAND:
7937c478bd9Sstevel@tonic-gate 				/* it's from $# -- let it go through */
7947c478bd9Sstevel@tonic-gate 				p++;
7957c478bd9Sstevel@tonic-gate 				break;
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate 			  case '\\':
7987c478bd9Sstevel@tonic-gate 				/* it's backslash escaped */
7997c478bd9Sstevel@tonic-gate 				(void) sm_strlcpy(p, p + 1, strlen(p));
8007c478bd9Sstevel@tonic-gate 				break;
8017c478bd9Sstevel@tonic-gate 
8027c478bd9Sstevel@tonic-gate 			  default:
8037c478bd9Sstevel@tonic-gate 				/* delete leading white space */
8047c478bd9Sstevel@tonic-gate 				while (isascii(*p) && isspace(*p) &&
8057c478bd9Sstevel@tonic-gate 				       *p != '\n' && p > bp)
806058561cbSjbeck 				{
8077c478bd9Sstevel@tonic-gate 					p--;
808058561cbSjbeck 				}
8097c478bd9Sstevel@tonic-gate 				if ((e = strchr(++p, '\n')) != NULL)
8107c478bd9Sstevel@tonic-gate 					(void) sm_strlcpy(p, e, strlen(p));
8117c478bd9Sstevel@tonic-gate 				else
8127c478bd9Sstevel@tonic-gate 					*p-- = '\0';
8137c478bd9Sstevel@tonic-gate 				break;
8147c478bd9Sstevel@tonic-gate 			}
8157c478bd9Sstevel@tonic-gate 			continue;
8167c478bd9Sstevel@tonic-gate 		}
8177c478bd9Sstevel@tonic-gate 
8187c478bd9Sstevel@tonic-gate 		if (*p != '$' || p[1] == '\0')
8197c478bd9Sstevel@tonic-gate 			continue;
8207c478bd9Sstevel@tonic-gate 
8217c478bd9Sstevel@tonic-gate 		if (p[1] == '$')
8227c478bd9Sstevel@tonic-gate 		{
8237c478bd9Sstevel@tonic-gate 			/* actual dollar sign.... */
8247c478bd9Sstevel@tonic-gate 			(void) sm_strlcpy(p, p + 1, strlen(p));
8257c478bd9Sstevel@tonic-gate 			continue;
8267c478bd9Sstevel@tonic-gate 		}
8277c478bd9Sstevel@tonic-gate 
8287c478bd9Sstevel@tonic-gate 		/* convert to macro expansion character */
8297c478bd9Sstevel@tonic-gate 		*p++ = MACROEXPAND;
8307c478bd9Sstevel@tonic-gate 
8317c478bd9Sstevel@tonic-gate 		/* special handling for $=, $~, $&, and $? */
8327c478bd9Sstevel@tonic-gate 		if (*p == '=' || *p == '~' || *p == '&' || *p == '?')
8337c478bd9Sstevel@tonic-gate 			p++;
8347c478bd9Sstevel@tonic-gate 
8357c478bd9Sstevel@tonic-gate 		/* convert macro name to code */
8367c478bd9Sstevel@tonic-gate 		*p = macid_parse(p, &ep);
8377c478bd9Sstevel@tonic-gate 		if (ep != p + 1)
8387c478bd9Sstevel@tonic-gate 			(void) sm_strlcpy(p + 1, ep, strlen(p + 1));
8397c478bd9Sstevel@tonic-gate 	}
8407c478bd9Sstevel@tonic-gate 
8417c478bd9Sstevel@tonic-gate 	/* strip trailing white space from the line */
8427c478bd9Sstevel@tonic-gate 	while (--p > bp && isascii(*p) && isspace(*p))
8437c478bd9Sstevel@tonic-gate 		*p = '\0';
844058561cbSjbeck 
845058561cbSjbeck 	if (tTd(37, 53))
846058561cbSjbeck 	{
847058561cbSjbeck 		sm_dprintf("  translate_dollars => ");
848058561cbSjbeck 		xputs(sm_debug_file(), bp);
849058561cbSjbeck 		sm_dprintf("\n");
850058561cbSjbeck 	}
851058561cbSjbeck 
852058561cbSjbeck 	return bp;
8537c478bd9Sstevel@tonic-gate }
8547c478bd9Sstevel@tonic-gate /*
8557c478bd9Sstevel@tonic-gate **  TOOMANY -- signal too many of some option
8567c478bd9Sstevel@tonic-gate **
8577c478bd9Sstevel@tonic-gate **	Parameters:
8587c478bd9Sstevel@tonic-gate **		id -- the id of the error line
8597c478bd9Sstevel@tonic-gate **		maxcnt -- the maximum possible values
8607c478bd9Sstevel@tonic-gate **
8617c478bd9Sstevel@tonic-gate **	Returns:
8627c478bd9Sstevel@tonic-gate **		none.
8637c478bd9Sstevel@tonic-gate **
8647c478bd9Sstevel@tonic-gate **	Side Effects:
8657c478bd9Sstevel@tonic-gate **		gives a syserr.
8667c478bd9Sstevel@tonic-gate */
8677c478bd9Sstevel@tonic-gate 
8687c478bd9Sstevel@tonic-gate static void
toomany(id,maxcnt)8697c478bd9Sstevel@tonic-gate toomany(id, maxcnt)
8707c478bd9Sstevel@tonic-gate 	int id;
8717c478bd9Sstevel@tonic-gate 	int maxcnt;
8727c478bd9Sstevel@tonic-gate {
8737c478bd9Sstevel@tonic-gate 	syserr("too many %c lines, %d max", id, maxcnt);
8747c478bd9Sstevel@tonic-gate }
8757c478bd9Sstevel@tonic-gate /*
8767c478bd9Sstevel@tonic-gate **  FILECLASS -- read members of a class from a file
8777c478bd9Sstevel@tonic-gate **
8787c478bd9Sstevel@tonic-gate **	Parameters:
8797c478bd9Sstevel@tonic-gate **		class -- class to define.
8807c478bd9Sstevel@tonic-gate **		filename -- name of file to read.
8817c478bd9Sstevel@tonic-gate **		fmt -- scanf string to use for match.
8827c478bd9Sstevel@tonic-gate **		ismap -- if set, this is a map lookup.
8837c478bd9Sstevel@tonic-gate **		safe -- if set, this is a safe read.
8847c478bd9Sstevel@tonic-gate **		optional -- if set, it is not an error for the file to
8857c478bd9Sstevel@tonic-gate **			not exist.
8867c478bd9Sstevel@tonic-gate **
8877c478bd9Sstevel@tonic-gate **	Returns:
8887c478bd9Sstevel@tonic-gate **		none
8897c478bd9Sstevel@tonic-gate **
8907c478bd9Sstevel@tonic-gate **	Side Effects:
8917c478bd9Sstevel@tonic-gate **		puts all lines in filename that match a scanf into
8927c478bd9Sstevel@tonic-gate **			the named class.
8937c478bd9Sstevel@tonic-gate */
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate /*
8967c478bd9Sstevel@tonic-gate **  Break up the match into words and add to class.
8977c478bd9Sstevel@tonic-gate */
8987c478bd9Sstevel@tonic-gate 
8997c478bd9Sstevel@tonic-gate static void
parse_class_words(class,line)9007c478bd9Sstevel@tonic-gate parse_class_words(class, line)
9017c478bd9Sstevel@tonic-gate 	int class;
9027c478bd9Sstevel@tonic-gate 	char *line;
9037c478bd9Sstevel@tonic-gate {
9047c478bd9Sstevel@tonic-gate 	while (line != NULL && *line != '\0')
9057c478bd9Sstevel@tonic-gate 	{
9067c478bd9Sstevel@tonic-gate 		register char *q;
9077c478bd9Sstevel@tonic-gate 
9087c478bd9Sstevel@tonic-gate 		/* strip leading spaces */
9097c478bd9Sstevel@tonic-gate 		while (isascii(*line) && isspace(*line))
9107c478bd9Sstevel@tonic-gate 			line++;
9117c478bd9Sstevel@tonic-gate 		if (*line == '\0')
9127c478bd9Sstevel@tonic-gate 			break;
9137c478bd9Sstevel@tonic-gate 
9147c478bd9Sstevel@tonic-gate 		/* find the end of the word */
9157c478bd9Sstevel@tonic-gate 		q = line;
9167c478bd9Sstevel@tonic-gate 		while (*line != '\0' && !(isascii(*line) && isspace(*line)))
9177c478bd9Sstevel@tonic-gate 			line++;
9187c478bd9Sstevel@tonic-gate 		if (*line != '\0')
9197c478bd9Sstevel@tonic-gate 			*line++ = '\0';
9207c478bd9Sstevel@tonic-gate 
9217c478bd9Sstevel@tonic-gate 		/* enter the word in the symbol table */
9227c478bd9Sstevel@tonic-gate 		setclass(class, q);
9237c478bd9Sstevel@tonic-gate 	}
9247c478bd9Sstevel@tonic-gate }
9257c478bd9Sstevel@tonic-gate 
9267c478bd9Sstevel@tonic-gate static void
fileclass(class,filename,fmt,ismap,safe,optional)9277c478bd9Sstevel@tonic-gate fileclass(class, filename, fmt, ismap, safe, optional)
9287c478bd9Sstevel@tonic-gate 	int class;
9297c478bd9Sstevel@tonic-gate 	char *filename;
9307c478bd9Sstevel@tonic-gate 	char *fmt;
9317c478bd9Sstevel@tonic-gate 	bool ismap;
9327c478bd9Sstevel@tonic-gate 	bool safe;
9337c478bd9Sstevel@tonic-gate 	bool optional;
9347c478bd9Sstevel@tonic-gate {
9357c478bd9Sstevel@tonic-gate 	SM_FILE_T *f;
9367c478bd9Sstevel@tonic-gate 	long sff;
9377c478bd9Sstevel@tonic-gate 	pid_t pid;
9387c478bd9Sstevel@tonic-gate 	register char *p;
9397c478bd9Sstevel@tonic-gate 	char buf[MAXLINE];
9407c478bd9Sstevel@tonic-gate 
9417c478bd9Sstevel@tonic-gate 	if (tTd(37, 2))
9427c478bd9Sstevel@tonic-gate 		sm_dprintf("fileclass(%s, fmt=%s)\n", filename, fmt);
9437c478bd9Sstevel@tonic-gate 
9447c478bd9Sstevel@tonic-gate 	if (*filename == '\0')
9457c478bd9Sstevel@tonic-gate 	{
9467c478bd9Sstevel@tonic-gate 		syserr("fileclass: missing file name");
9477c478bd9Sstevel@tonic-gate 		return;
9487c478bd9Sstevel@tonic-gate 	}
9497c478bd9Sstevel@tonic-gate 	else if (ismap)
9507c478bd9Sstevel@tonic-gate 	{
9517c478bd9Sstevel@tonic-gate 		int status = 0;
9527c478bd9Sstevel@tonic-gate 		char *key;
9537c478bd9Sstevel@tonic-gate 		char *mn;
9547c478bd9Sstevel@tonic-gate 		char *cl, *spec;
9557c478bd9Sstevel@tonic-gate 		STAB *mapclass;
9567c478bd9Sstevel@tonic-gate 		MAP map;
9577c478bd9Sstevel@tonic-gate 
9587c478bd9Sstevel@tonic-gate 		mn = newstr(macname(class));
9597c478bd9Sstevel@tonic-gate 
9607c478bd9Sstevel@tonic-gate 		key = filename;
9617c478bd9Sstevel@tonic-gate 
9627c478bd9Sstevel@tonic-gate 		/* skip past key */
9637c478bd9Sstevel@tonic-gate 		if ((p = strchr(filename, '@')) == NULL)
9647c478bd9Sstevel@tonic-gate 		{
9657c478bd9Sstevel@tonic-gate 			/* should not happen */
9667c478bd9Sstevel@tonic-gate 			syserr("fileclass: bogus map specification");
9677c478bd9Sstevel@tonic-gate 			sm_free(mn);
9687c478bd9Sstevel@tonic-gate 			return;
9697c478bd9Sstevel@tonic-gate 		}
9707c478bd9Sstevel@tonic-gate 
9717c478bd9Sstevel@tonic-gate 		/* skip past '@' */
9727c478bd9Sstevel@tonic-gate 		*p++ = '\0';
9737c478bd9Sstevel@tonic-gate 		cl = p;
9747c478bd9Sstevel@tonic-gate 
9757c478bd9Sstevel@tonic-gate #if LDAPMAP
9767c478bd9Sstevel@tonic-gate 		if (strcmp(cl, "LDAP") == 0)
9777c478bd9Sstevel@tonic-gate 		{
9787c478bd9Sstevel@tonic-gate 			int n;
9797c478bd9Sstevel@tonic-gate 			char *lc;
9807c478bd9Sstevel@tonic-gate 			char jbuf[MAXHOSTNAMELEN];
9817c478bd9Sstevel@tonic-gate 			char lcbuf[MAXLINE];
9827c478bd9Sstevel@tonic-gate 
9837c478bd9Sstevel@tonic-gate 			/* Get $j */
984058561cbSjbeck 			expand("\201j", jbuf, sizeof(jbuf), &BlankEnvelope);
9857c478bd9Sstevel@tonic-gate 			if (jbuf[0] == '\0')
9867c478bd9Sstevel@tonic-gate 			{
9877c478bd9Sstevel@tonic-gate 				(void) sm_strlcpy(jbuf, "localhost",
988058561cbSjbeck 						  sizeof(jbuf));
9897c478bd9Sstevel@tonic-gate 			}
9907c478bd9Sstevel@tonic-gate 
9917c478bd9Sstevel@tonic-gate 			/* impose the default schema */
9927c478bd9Sstevel@tonic-gate 			lc = macvalue(macid("{sendmailMTACluster}"), CurEnv);
9937c478bd9Sstevel@tonic-gate 			if (lc == NULL)
9947c478bd9Sstevel@tonic-gate 				lc = "";
9957c478bd9Sstevel@tonic-gate 			else
9967c478bd9Sstevel@tonic-gate 			{
997058561cbSjbeck 				expand(lc, lcbuf, sizeof(lcbuf), CurEnv);
9987c478bd9Sstevel@tonic-gate 				lc = lcbuf;
9997c478bd9Sstevel@tonic-gate 			}
10007c478bd9Sstevel@tonic-gate 
10017c478bd9Sstevel@tonic-gate 			cl = "ldap";
1002058561cbSjbeck 			n = sm_snprintf(buf, sizeof(buf),
10037c478bd9Sstevel@tonic-gate 					"-k (&(objectClass=sendmailMTAClass)(sendmailMTAClassName=%s)(|(sendmailMTACluster=%s)(sendmailMTAHost=%s))) -v sendmailMTAClassValue,sendmailMTAClassSearch:FILTER:sendmailMTAClass,sendmailMTAClassURL:URL:sendmailMTAClass",
10047c478bd9Sstevel@tonic-gate 					mn, lc, jbuf);
1005058561cbSjbeck 			if (n >= sizeof(buf))
10067c478bd9Sstevel@tonic-gate 			{
10077c478bd9Sstevel@tonic-gate 				syserr("fileclass: F{%s}: Default LDAP string too long",
10087c478bd9Sstevel@tonic-gate 				       mn);
10097c478bd9Sstevel@tonic-gate 				sm_free(mn);
10107c478bd9Sstevel@tonic-gate 				return;
10117c478bd9Sstevel@tonic-gate 			}
10127c478bd9Sstevel@tonic-gate 			spec = buf;
10137c478bd9Sstevel@tonic-gate 		}
10147c478bd9Sstevel@tonic-gate 		else
10157c478bd9Sstevel@tonic-gate #endif /* LDAPMAP */
10167c478bd9Sstevel@tonic-gate 		{
10177c478bd9Sstevel@tonic-gate 			if ((spec = strchr(cl, ':')) == NULL)
10187c478bd9Sstevel@tonic-gate 			{
10197c478bd9Sstevel@tonic-gate 				syserr("fileclass: F{%s}: missing map class",
10207c478bd9Sstevel@tonic-gate 				       mn);
10217c478bd9Sstevel@tonic-gate 				sm_free(mn);
10227c478bd9Sstevel@tonic-gate 				return;
10237c478bd9Sstevel@tonic-gate 			}
10247c478bd9Sstevel@tonic-gate 			*spec++ ='\0';
10257c478bd9Sstevel@tonic-gate 		}
10267c478bd9Sstevel@tonic-gate 
10277c478bd9Sstevel@tonic-gate 		/* set up map structure */
10287c478bd9Sstevel@tonic-gate 		mapclass = stab(cl, ST_MAPCLASS, ST_FIND);
10297c478bd9Sstevel@tonic-gate 		if (mapclass == NULL)
10307c478bd9Sstevel@tonic-gate 		{
10317c478bd9Sstevel@tonic-gate 			syserr("fileclass: F{%s}: class %s not available",
10327c478bd9Sstevel@tonic-gate 			       mn, cl);
10337c478bd9Sstevel@tonic-gate 			sm_free(mn);
10347c478bd9Sstevel@tonic-gate 			return;
10357c478bd9Sstevel@tonic-gate 		}
1036058561cbSjbeck 		memset(&map, '\0', sizeof(map));
10377c478bd9Sstevel@tonic-gate 		map.map_class = &mapclass->s_mapclass;
10387c478bd9Sstevel@tonic-gate 		map.map_mname = mn;
10397c478bd9Sstevel@tonic-gate 		map.map_mflags |= MF_FILECLASS;
10407c478bd9Sstevel@tonic-gate 
10417c478bd9Sstevel@tonic-gate 		if (tTd(37, 5))
10427c478bd9Sstevel@tonic-gate 			sm_dprintf("fileclass: F{%s}: map class %s, key %s, spec %s\n",
10437c478bd9Sstevel@tonic-gate 				   mn, cl, key, spec);
10447c478bd9Sstevel@tonic-gate 
10457c478bd9Sstevel@tonic-gate 
10467c478bd9Sstevel@tonic-gate 		/* parse map spec */
10477c478bd9Sstevel@tonic-gate 		if (!map.map_class->map_parse(&map, spec))
10487c478bd9Sstevel@tonic-gate 		{
10497c478bd9Sstevel@tonic-gate 			/* map_parse() showed the error already */
10507c478bd9Sstevel@tonic-gate 			sm_free(mn);
10517c478bd9Sstevel@tonic-gate 			return;
10527c478bd9Sstevel@tonic-gate 		}
10537c478bd9Sstevel@tonic-gate 		map.map_mflags |= MF_VALID;
10547c478bd9Sstevel@tonic-gate 
10557c478bd9Sstevel@tonic-gate 		/* open map */
10567c478bd9Sstevel@tonic-gate 		if (map.map_class->map_open(&map, O_RDONLY))
10577c478bd9Sstevel@tonic-gate 		{
10587c478bd9Sstevel@tonic-gate 			map.map_mflags |= MF_OPEN;
10597c478bd9Sstevel@tonic-gate 			map.map_pid = getpid();
10607c478bd9Sstevel@tonic-gate 		}
10617c478bd9Sstevel@tonic-gate 		else
10627c478bd9Sstevel@tonic-gate 		{
10637c478bd9Sstevel@tonic-gate 			if (!optional &&
10647c478bd9Sstevel@tonic-gate 			    !bitset(MF_OPTIONAL, map.map_mflags))
10657c478bd9Sstevel@tonic-gate 				syserr("fileclass: F{%s}: map open failed",
10667c478bd9Sstevel@tonic-gate 				       mn);
10677c478bd9Sstevel@tonic-gate 			sm_free(mn);
10687c478bd9Sstevel@tonic-gate 			return;
10697c478bd9Sstevel@tonic-gate 		}
10707c478bd9Sstevel@tonic-gate 
10717c478bd9Sstevel@tonic-gate 		/* lookup */
10727c478bd9Sstevel@tonic-gate 		p = (*map.map_class->map_lookup)(&map, key, NULL, &status);
10737c478bd9Sstevel@tonic-gate 		if (status != EX_OK && status != EX_NOTFOUND)
10747c478bd9Sstevel@tonic-gate 		{
10757c478bd9Sstevel@tonic-gate 			if (!optional)
10767c478bd9Sstevel@tonic-gate 				syserr("fileclass: F{%s}: map lookup failed",
10777c478bd9Sstevel@tonic-gate 				       mn);
10787c478bd9Sstevel@tonic-gate 			p = NULL;
10797c478bd9Sstevel@tonic-gate 		}
10807c478bd9Sstevel@tonic-gate 
10817c478bd9Sstevel@tonic-gate 		/* use the results */
10827c478bd9Sstevel@tonic-gate 		if (p != NULL)
10837c478bd9Sstevel@tonic-gate 			parse_class_words(class, p);
10847c478bd9Sstevel@tonic-gate 
10857c478bd9Sstevel@tonic-gate 		/* close map */
10867c478bd9Sstevel@tonic-gate 		map.map_mflags |= MF_CLOSING;
10877c478bd9Sstevel@tonic-gate 		map.map_class->map_close(&map);
10887c478bd9Sstevel@tonic-gate 		map.map_mflags &= ~(MF_OPEN|MF_WRITABLE|MF_CLOSING);
10897c478bd9Sstevel@tonic-gate 		sm_free(mn);
10907c478bd9Sstevel@tonic-gate 		return;
10917c478bd9Sstevel@tonic-gate 	}
10927c478bd9Sstevel@tonic-gate 	else if (filename[0] == '|')
10937c478bd9Sstevel@tonic-gate 	{
10947c478bd9Sstevel@tonic-gate 		auto int fd;
10957c478bd9Sstevel@tonic-gate 		int i;
10967c478bd9Sstevel@tonic-gate 		char *argv[MAXPV + 1];
10977c478bd9Sstevel@tonic-gate 
10987c478bd9Sstevel@tonic-gate 		i = 0;
10997c478bd9Sstevel@tonic-gate 		for (p = strtok(&filename[1], " \t");
11007c478bd9Sstevel@tonic-gate 		     p != NULL && i < MAXPV;
11017c478bd9Sstevel@tonic-gate 		     p = strtok(NULL, " \t"))
11027c478bd9Sstevel@tonic-gate 			argv[i++] = p;
11037c478bd9Sstevel@tonic-gate 		argv[i] = NULL;
11047c478bd9Sstevel@tonic-gate 		pid = prog_open(argv, &fd, CurEnv);
11057c478bd9Sstevel@tonic-gate 		if (pid < 0)
11067c478bd9Sstevel@tonic-gate 			f = NULL;
11077c478bd9Sstevel@tonic-gate 		else
11087c478bd9Sstevel@tonic-gate 			f = sm_io_open(SmFtStdiofd, SM_TIME_DEFAULT,
11097c478bd9Sstevel@tonic-gate 				       (void *) &fd, SM_IO_RDONLY, NULL);
11107c478bd9Sstevel@tonic-gate 	}
11117c478bd9Sstevel@tonic-gate 	else
11127c478bd9Sstevel@tonic-gate 	{
11137c478bd9Sstevel@tonic-gate 		pid = -1;
11147c478bd9Sstevel@tonic-gate 		sff = SFF_REGONLY;
11157c478bd9Sstevel@tonic-gate 		if (!bitnset(DBS_CLASSFILEINUNSAFEDIRPATH, DontBlameSendmail))
11167c478bd9Sstevel@tonic-gate 			sff |= SFF_SAFEDIRPATH;
11177c478bd9Sstevel@tonic-gate 		if (!bitnset(DBS_LINKEDCLASSFILEINWRITABLEDIR,
11187c478bd9Sstevel@tonic-gate 			     DontBlameSendmail))
11197c478bd9Sstevel@tonic-gate 			sff |= SFF_NOWLINK;
11207c478bd9Sstevel@tonic-gate 		if (safe)
11217c478bd9Sstevel@tonic-gate 			sff |= SFF_OPENASROOT;
11227c478bd9Sstevel@tonic-gate 		else if (RealUid == 0)
11237c478bd9Sstevel@tonic-gate 			sff |= SFF_ROOTOK;
11247c478bd9Sstevel@tonic-gate 		if (DontLockReadFiles)
11257c478bd9Sstevel@tonic-gate 			sff |= SFF_NOLOCK;
11267c478bd9Sstevel@tonic-gate 		f = safefopen(filename, O_RDONLY, 0, sff);
11277c478bd9Sstevel@tonic-gate 	}
11287c478bd9Sstevel@tonic-gate 	if (f == NULL)
11297c478bd9Sstevel@tonic-gate 	{
11307c478bd9Sstevel@tonic-gate 		if (!optional)
11317c478bd9Sstevel@tonic-gate 			syserr("fileclass: cannot open '%s'", filename);
11327c478bd9Sstevel@tonic-gate 		return;
11337c478bd9Sstevel@tonic-gate 	}
11347c478bd9Sstevel@tonic-gate 
1135058561cbSjbeck 	while (sm_io_fgets(f, SM_TIME_DEFAULT, buf, sizeof(buf)) != NULL)
11367c478bd9Sstevel@tonic-gate 	{
11377c478bd9Sstevel@tonic-gate #if SCANF
11387c478bd9Sstevel@tonic-gate 		char wordbuf[MAXLINE + 1];
11397c478bd9Sstevel@tonic-gate #endif /* SCANF */
11407c478bd9Sstevel@tonic-gate 
11417c478bd9Sstevel@tonic-gate 		if (buf[0] == '#')
11427c478bd9Sstevel@tonic-gate 			continue;
11437c478bd9Sstevel@tonic-gate #if SCANF
11447c478bd9Sstevel@tonic-gate 		if (sm_io_sscanf(buf, fmt, wordbuf) != 1)
11457c478bd9Sstevel@tonic-gate 			continue;
11467c478bd9Sstevel@tonic-gate 		p = wordbuf;
11477c478bd9Sstevel@tonic-gate #else /* SCANF */
11487c478bd9Sstevel@tonic-gate 		p = buf;
11497c478bd9Sstevel@tonic-gate #endif /* SCANF */
11507c478bd9Sstevel@tonic-gate 
11517c478bd9Sstevel@tonic-gate 		parse_class_words(class, p);
11527c478bd9Sstevel@tonic-gate 
11537c478bd9Sstevel@tonic-gate 		/*
11547c478bd9Sstevel@tonic-gate 		**  If anything else is added here,
11557c478bd9Sstevel@tonic-gate 		**  check if the '@' map case above
11567c478bd9Sstevel@tonic-gate 		**  needs the code as well.
11577c478bd9Sstevel@tonic-gate 		*/
11587c478bd9Sstevel@tonic-gate 	}
11597c478bd9Sstevel@tonic-gate 
11607c478bd9Sstevel@tonic-gate 	(void) sm_io_close(f, SM_TIME_DEFAULT);
11617c478bd9Sstevel@tonic-gate 	if (pid > 0)
11627c478bd9Sstevel@tonic-gate 		(void) waitfor(pid);
11637c478bd9Sstevel@tonic-gate }
11647c478bd9Sstevel@tonic-gate /*
11657c478bd9Sstevel@tonic-gate **  MAKEMAILER -- define a new mailer.
11667c478bd9Sstevel@tonic-gate **
11677c478bd9Sstevel@tonic-gate **	Parameters:
11687c478bd9Sstevel@tonic-gate **		line -- description of mailer.  This is in labeled
11697c478bd9Sstevel@tonic-gate **			fields.  The fields are:
11707c478bd9Sstevel@tonic-gate **			   A -- the argv for this mailer
11717c478bd9Sstevel@tonic-gate **			   C -- the character set for MIME conversions
11727c478bd9Sstevel@tonic-gate **			   D -- the directory to run in
11737c478bd9Sstevel@tonic-gate **			   E -- the eol string
11747c478bd9Sstevel@tonic-gate **			   F -- the flags associated with the mailer
11757c478bd9Sstevel@tonic-gate **			   L -- the maximum line length
11767c478bd9Sstevel@tonic-gate **			   M -- the maximum message size
11777c478bd9Sstevel@tonic-gate **			   N -- the niceness at which to run
11787c478bd9Sstevel@tonic-gate **			   P -- the path to the mailer
11797c478bd9Sstevel@tonic-gate **			   Q -- the queue group for the mailer
11807c478bd9Sstevel@tonic-gate **			   R -- the recipient rewriting set
11817c478bd9Sstevel@tonic-gate **			   S -- the sender rewriting set
11827c478bd9Sstevel@tonic-gate **			   T -- the mailer type (for DSNs)
11837c478bd9Sstevel@tonic-gate **			   U -- the uid to run as
11847c478bd9Sstevel@tonic-gate **			   W -- the time to wait at the end
11857c478bd9Sstevel@tonic-gate **			   m -- maximum messages per connection
11867c478bd9Sstevel@tonic-gate **			   r -- maximum number of recipients per message
11877c478bd9Sstevel@tonic-gate **			   / -- new root directory
11887c478bd9Sstevel@tonic-gate **			The first word is the canonical name of the mailer.
11897c478bd9Sstevel@tonic-gate **
11907c478bd9Sstevel@tonic-gate **	Returns:
11917c478bd9Sstevel@tonic-gate **		none.
11927c478bd9Sstevel@tonic-gate **
11937c478bd9Sstevel@tonic-gate **	Side Effects:
11947c478bd9Sstevel@tonic-gate **		enters the mailer into the mailer table.
11957c478bd9Sstevel@tonic-gate */
11967c478bd9Sstevel@tonic-gate 
11977c478bd9Sstevel@tonic-gate void
makemailer(line)11987c478bd9Sstevel@tonic-gate makemailer(line)
11997c478bd9Sstevel@tonic-gate 	char *line;
12007c478bd9Sstevel@tonic-gate {
12017c478bd9Sstevel@tonic-gate 	register char *p;
12027c478bd9Sstevel@tonic-gate 	register struct mailer *m;
12037c478bd9Sstevel@tonic-gate 	register STAB *s;
12047c478bd9Sstevel@tonic-gate 	int i;
12057c478bd9Sstevel@tonic-gate 	char fcode;
12067c478bd9Sstevel@tonic-gate 	auto char *endp;
12077c478bd9Sstevel@tonic-gate 	static int nextmailer = 0;	/* "free" index into Mailer struct */
12087c478bd9Sstevel@tonic-gate 
12097c478bd9Sstevel@tonic-gate 	/* allocate a mailer and set up defaults */
1210058561cbSjbeck 	m = (struct mailer *) xalloc(sizeof(*m));
1211058561cbSjbeck 	memset((char *) m, '\0', sizeof(*m));
12127c478bd9Sstevel@tonic-gate 	errno = 0; /* avoid bogus error text */
12137c478bd9Sstevel@tonic-gate 
12147c478bd9Sstevel@tonic-gate 	/* collect the mailer name */
12157c478bd9Sstevel@tonic-gate 	for (p = line;
12167c478bd9Sstevel@tonic-gate 	     *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p));
12177c478bd9Sstevel@tonic-gate 	     p++)
12187c478bd9Sstevel@tonic-gate 		continue;
12197c478bd9Sstevel@tonic-gate 	if (*p != '\0')
12207c478bd9Sstevel@tonic-gate 		*p++ = '\0';
12217c478bd9Sstevel@tonic-gate 	if (line[0] == '\0')
12227c478bd9Sstevel@tonic-gate 	{
12237c478bd9Sstevel@tonic-gate 		syserr("name required for mailer");
12247c478bd9Sstevel@tonic-gate 		return;
12257c478bd9Sstevel@tonic-gate 	}
12267c478bd9Sstevel@tonic-gate 	m->m_name = newstr(line);
12277c478bd9Sstevel@tonic-gate 	m->m_qgrp = NOQGRP;
12287c478bd9Sstevel@tonic-gate 	m->m_uid = NO_UID;
12297c478bd9Sstevel@tonic-gate 	m->m_gid = NO_GID;
12307c478bd9Sstevel@tonic-gate 
12317c478bd9Sstevel@tonic-gate 	/* now scan through and assign info from the fields */
12327c478bd9Sstevel@tonic-gate 	while (*p != '\0')
12337c478bd9Sstevel@tonic-gate 	{
12347c478bd9Sstevel@tonic-gate 		auto char *delimptr;
12357c478bd9Sstevel@tonic-gate 
12367c478bd9Sstevel@tonic-gate 		while (*p != '\0' &&
12377c478bd9Sstevel@tonic-gate 		       (*p == ',' || (isascii(*p) && isspace(*p))))
12387c478bd9Sstevel@tonic-gate 			p++;
12397c478bd9Sstevel@tonic-gate 
12407c478bd9Sstevel@tonic-gate 		/* p now points to field code */
1241