xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 66383)
122709Sdist /*
234921Sbostic  * Copyright (c) 1983 Eric P. Allman
362530Sbostic  * Copyright (c) 1988, 1993
462530Sbostic  *	The Regents of the University of California.  All rights reserved.
533731Sbostic  *
642829Sbostic  * %sccs.include.redist.c%
733731Sbostic  */
822709Sdist 
922709Sdist #ifndef lint
10*66383Scorrigan static char sccsid[] = "@(#)readcf.c	8.23 (Berkeley) 03/18/94";
1133731Sbostic #endif /* not lint */
1222709Sdist 
133313Seric # include "sendmail.h"
1464133Seric # include <pwd.h>
1564133Seric # include <grp.h>
1666334Seric #if NAMED_BIND
1757207Seric # include <arpa/nameser.h>
1857207Seric # include <resolv.h>
1957207Seric #endif
203308Seric 
213308Seric /*
223308Seric **  READCF -- read control file.
233308Seric **
243308Seric **	This routine reads the control file and builds the internal
253308Seric **	form.
263308Seric **
274432Seric **	The file is formatted as a sequence of lines, each taken
284432Seric **	atomically.  The first character of each line describes how
294432Seric **	the line is to be interpreted.  The lines are:
304432Seric **		Dxval		Define macro x to have value val.
314432Seric **		Cxword		Put word into class x.
324432Seric **		Fxfile [fmt]	Read file for lines to put into
334432Seric **				class x.  Use scanf string 'fmt'
344432Seric **				or "%s" if not present.  Fmt should
354432Seric **				only produce one string-valued result.
364432Seric **		Hname: value	Define header with field-name 'name'
374432Seric **				and value as specified; this will be
384432Seric **				macro expanded immediately before
394432Seric **				use.
404432Seric **		Sn		Use rewriting set n.
414432Seric **		Rlhs rhs	Rewrite addresses that match lhs to
424432Seric **				be rhs.
4324944Seric **		Mn arg=val...	Define mailer.  n is the internal name.
4424944Seric **				Args specify mailer parameters.
458252Seric **		Oxvalue		Set option x to value.
468252Seric **		Pname=value	Set precedence name to value.
4764718Seric **		Vversioncode[/vendorcode]
4864718Seric **				Version level/vendor name of
4964718Seric **				configuration syntax.
5053654Seric **		Kmapname mapclass arguments....
5153654Seric **				Define keyed lookup of a given class.
5253654Seric **				Arguments are class dependent.
534432Seric **
543308Seric **	Parameters:
553308Seric **		cfname -- control file name.
5654973Seric **		safe -- TRUE if this is the system config file;
5754973Seric **			FALSE otherwise.
5855012Seric **		e -- the main envelope.
593308Seric **
603308Seric **	Returns:
613308Seric **		none.
623308Seric **
633308Seric **	Side Effects:
643308Seric **		Builds several internal tables.
653308Seric */
663308Seric 
6755012Seric readcf(cfname, safe, e)
683308Seric 	char *cfname;
6954973Seric 	bool safe;
7055012Seric 	register ENVELOPE *e;
713308Seric {
723308Seric 	FILE *cf;
738547Seric 	int ruleset = 0;
748547Seric 	char *q;
759350Seric 	struct rewrite *rwp = NULL;
7657135Seric 	char *bp;
7764718Seric 	auto char *ep;
7857589Seric 	int nfuzzy;
7964133Seric 	char *file;
8064133Seric 	bool optional;
813308Seric 	char buf[MAXLINE];
823308Seric 	register char *p;
833308Seric 	extern char **copyplist();
8452647Seric 	struct stat statb;
855909Seric 	char exbuf[MAXLINE];
8665066Seric 	char pvpbuf[MAXLINE + MAXATOM];
8710709Seric 	extern char *munchstring();
8853654Seric 	extern void makemapentry();
893308Seric 
9052647Seric 	FileName = cfname;
9152647Seric 	LineNumber = 0;
9252647Seric 
933308Seric 	cf = fopen(cfname, "r");
943308Seric 	if (cf == NULL)
953308Seric 	{
9652647Seric 		syserr("cannot open");
973308Seric 		exit(EX_OSFILE);
983308Seric 	}
993308Seric 
10052647Seric 	if (fstat(fileno(cf), &statb) < 0)
10152647Seric 	{
10252647Seric 		syserr("cannot fstat");
10352647Seric 		exit(EX_OSFILE);
10452647Seric 	}
10552647Seric 
10652647Seric 	if (!S_ISREG(statb.st_mode))
10752647Seric 	{
10852647Seric 		syserr("not a plain file");
10952647Seric 		exit(EX_OSFILE);
11052647Seric 	}
11152647Seric 
11252647Seric 	if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
11352647Seric 	{
11453037Seric 		if (OpMode == MD_DAEMON || OpMode == MD_FREEZE)
11553037Seric 			fprintf(stderr, "%s: WARNING: dangerous write permissions\n",
11653037Seric 				FileName);
11753037Seric #ifdef LOG
11853037Seric 		if (LogLevel > 0)
11953037Seric 			syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions",
12053037Seric 				FileName);
12153037Seric #endif
12252647Seric 	}
12352647Seric 
12459254Seric #ifdef XLA
12559254Seric 	xla_zero();
12659254Seric #endif
12759254Seric 
12857135Seric 	while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL)
1293308Seric 	{
13057135Seric 		if (bp[0] == '#')
13157135Seric 		{
13257135Seric 			if (bp != buf)
13357135Seric 				free(bp);
13452637Seric 			continue;
13557135Seric 		}
13652637Seric 
13758050Seric 		/* map $ into \201 for macro expansion */
13857135Seric 		for (p = bp; *p != '\0'; p++)
13916157Seric 		{
14057135Seric 			if (*p == '#' && p > bp && ConfigLevel >= 3)
14152647Seric 			{
14252647Seric 				/* this is an on-line comment */
14352647Seric 				register char *e;
14452647Seric 
14558050Seric 				switch (*--p & 0377)
14652647Seric 				{
14758050Seric 				  case MACROEXPAND:
14852647Seric 					/* it's from $# -- let it go through */
14952647Seric 					p++;
15052647Seric 					break;
15152647Seric 
15252647Seric 				  case '\\':
15352647Seric 					/* it's backslash escaped */
15452647Seric 					(void) strcpy(p, p + 1);
15552647Seric 					break;
15652647Seric 
15752647Seric 				  default:
15852647Seric 					/* delete preceeding white space */
15958050Seric 					while (isascii(*p) && isspace(*p) && p > bp)
16052647Seric 						p--;
16156795Seric 					if ((e = strchr(++p, '\n')) != NULL)
16252647Seric 						(void) strcpy(p, e);
16352647Seric 					else
16452647Seric 						p[0] = p[1] = '\0';
16552647Seric 					break;
16652647Seric 				}
16752647Seric 				continue;
16852647Seric 			}
16952647Seric 
17016157Seric 			if (*p != '$')
17116157Seric 				continue;
17216157Seric 
17316157Seric 			if (p[1] == '$')
17416157Seric 			{
17516157Seric 				/* actual dollar sign.... */
17623111Seric 				(void) strcpy(p, p + 1);
17716157Seric 				continue;
17816157Seric 			}
17916157Seric 
18016157Seric 			/* convert to macro expansion character */
18158050Seric 			*p = MACROEXPAND;
18216157Seric 		}
18316157Seric 
18416157Seric 		/* interpret this line */
18564718Seric 		errno = 0;
18657135Seric 		switch (bp[0])
1873308Seric 		{
1883308Seric 		  case '\0':
1893308Seric 		  case '#':		/* comment */
1903308Seric 			break;
1913308Seric 
1923308Seric 		  case 'R':		/* rewriting rule */
19357135Seric 			for (p = &bp[1]; *p != '\0' && *p != '\t'; p++)
1943308Seric 				continue;
1953308Seric 
1963308Seric 			if (*p == '\0')
1975909Seric 			{
19865821Seric 				syserr("invalid rewrite line \"%s\" (tab expected)", bp);
1995909Seric 				break;
2005909Seric 			}
2015909Seric 
2025909Seric 			/* allocate space for the rule header */
2035909Seric 			if (rwp == NULL)
2045909Seric 			{
2055909Seric 				RewriteRules[ruleset] = rwp =
2065909Seric 					(struct rewrite *) xalloc(sizeof *rwp);
2075909Seric 			}
2083308Seric 			else
2093308Seric 			{
2105909Seric 				rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
2115909Seric 				rwp = rwp->r_next;
2125909Seric 			}
2135909Seric 			rwp->r_next = NULL;
2143308Seric 
2155909Seric 			/* expand and save the LHS */
2165909Seric 			*p = '\0';
21757135Seric 			expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e);
21865066Seric 			rwp->r_lhs = prescan(exbuf, '\t', pvpbuf,
21965066Seric 					     sizeof pvpbuf, NULL);
22057589Seric 			nfuzzy = 0;
2215909Seric 			if (rwp->r_lhs != NULL)
22257589Seric 			{
22357589Seric 				register char **ap;
22457589Seric 
2255909Seric 				rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
22657589Seric 
22757589Seric 				/* count the number of fuzzy matches in LHS */
22857589Seric 				for (ap = rwp->r_lhs; *ap != NULL; ap++)
22957589Seric 				{
23058148Seric 					char *botch;
23158148Seric 
23258148Seric 					botch = NULL;
23358050Seric 					switch (**ap & 0377)
23457589Seric 					{
23557589Seric 					  case MATCHZANY:
23657589Seric 					  case MATCHANY:
23757589Seric 					  case MATCHONE:
23857589Seric 					  case MATCHCLASS:
23957589Seric 					  case MATCHNCLASS:
24057589Seric 						nfuzzy++;
24158148Seric 						break;
24258148Seric 
24358148Seric 					  case MATCHREPL:
24458148Seric 						botch = "$0-$9";
24558148Seric 						break;
24658148Seric 
24758148Seric 					  case CANONNET:
24858148Seric 						botch = "$#";
24958148Seric 						break;
25058148Seric 
25158148Seric 					  case CANONUSER:
25258148Seric 						botch = "$:";
25358148Seric 						break;
25458148Seric 
25558148Seric 					  case CALLSUBR:
25658148Seric 						botch = "$>";
25758148Seric 						break;
25858148Seric 
25958148Seric 					  case CONDIF:
26058148Seric 						botch = "$?";
26158148Seric 						break;
26258148Seric 
26358148Seric 					  case CONDELSE:
26458148Seric 						botch = "$|";
26558148Seric 						break;
26658148Seric 
26758148Seric 					  case CONDFI:
26858148Seric 						botch = "$.";
26958148Seric 						break;
27058148Seric 
27158148Seric 					  case HOSTBEGIN:
27258148Seric 						botch = "$[";
27358148Seric 						break;
27458148Seric 
27558148Seric 					  case HOSTEND:
27658148Seric 						botch = "$]";
27758148Seric 						break;
27858148Seric 
27958148Seric 					  case LOOKUPBEGIN:
28058148Seric 						botch = "$(";
28158148Seric 						break;
28258148Seric 
28358148Seric 					  case LOOKUPEND:
28458148Seric 						botch = "$)";
28558148Seric 						break;
28657589Seric 					}
28758148Seric 					if (botch != NULL)
28858148Seric 						syserr("Inappropriate use of %s on LHS",
28958148Seric 							botch);
29057589Seric 				}
29157589Seric 			}
29256678Seric 			else
29356678Seric 				syserr("R line: null LHS");
2945909Seric 
2955909Seric 			/* expand and save the RHS */
2965909Seric 			while (*++p == '\t')
2975909Seric 				continue;
2987231Seric 			q = p;
2997231Seric 			while (*p != '\0' && *p != '\t')
3007231Seric 				p++;
3017231Seric 			*p = '\0';
30255012Seric 			expand(q, exbuf, &exbuf[sizeof exbuf], e);
30365066Seric 			rwp->r_rhs = prescan(exbuf, '\t', pvpbuf,
30465066Seric 					     sizeof pvpbuf, NULL);
3055909Seric 			if (rwp->r_rhs != NULL)
30657589Seric 			{
30757589Seric 				register char **ap;
30857589Seric 
3095909Seric 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
31057589Seric 
31157589Seric 				/* check no out-of-bounds replacements */
31257589Seric 				nfuzzy += '0';
31357589Seric 				for (ap = rwp->r_rhs; *ap != NULL; ap++)
31457589Seric 				{
31558148Seric 					char *botch;
31658148Seric 
31758148Seric 					botch = NULL;
31858148Seric 					switch (**ap & 0377)
31957589Seric 					{
32058148Seric 					  case MATCHREPL:
32158148Seric 						if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy)
32258148Seric 						{
32358148Seric 							syserr("replacement $%c out of bounds",
32458148Seric 								(*ap)[1]);
32558148Seric 						}
32658148Seric 						break;
32758148Seric 
32858148Seric 					  case MATCHZANY:
32958148Seric 						botch = "$*";
33058148Seric 						break;
33158148Seric 
33258148Seric 					  case MATCHANY:
33358148Seric 						botch = "$+";
33458148Seric 						break;
33558148Seric 
33658148Seric 					  case MATCHONE:
33758148Seric 						botch = "$-";
33858148Seric 						break;
33958148Seric 
34058148Seric 					  case MATCHCLASS:
34158148Seric 						botch = "$=";
34258148Seric 						break;
34358148Seric 
34458148Seric 					  case MATCHNCLASS:
34558148Seric 						botch = "$~";
34658148Seric 						break;
34757589Seric 					}
34858148Seric 					if (botch != NULL)
34958148Seric 						syserr("Inappropriate use of %s on RHS",
35058148Seric 							botch);
35157589Seric 				}
35257589Seric 			}
35356678Seric 			else
35456678Seric 				syserr("R line: null RHS");
3553308Seric 			break;
3563308Seric 
3574072Seric 		  case 'S':		/* select rewriting set */
35864440Seric 			for (p = &bp[1]; isascii(*p) && isspace(*p); p++)
35964440Seric 				continue;
36064440Seric 			if (!isascii(*p) || !isdigit(*p))
36164440Seric 			{
36264440Seric 				syserr("invalid argument to S line: \"%.20s\"",
36364440Seric 					&bp[1]);
36464440Seric 				break;
36564440Seric 			}
36664440Seric 			ruleset = atoi(p);
3678056Seric 			if (ruleset >= MAXRWSETS || ruleset < 0)
3688056Seric 			{
3699381Seric 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
3708056Seric 				ruleset = 0;
3718056Seric 			}
3724072Seric 			rwp = NULL;
3734072Seric 			break;
3744072Seric 
3753308Seric 		  case 'D':		/* macro definition */
37664086Seric 			p = munchstring(&bp[2], NULL);
37764086Seric 			define(bp[1], newstr(p), e);
3783308Seric 			break;
3793308Seric 
3803387Seric 		  case 'H':		/* required header line */
38157135Seric 			(void) chompheader(&bp[1], TRUE, e);
3823387Seric 			break;
3833387Seric 
3844061Seric 		  case 'C':		/* word class */
3854432Seric 			/* scan the list of words and set class for all */
38664121Seric 			expand(&bp[2], exbuf, &exbuf[sizeof exbuf], e);
38764121Seric 			for (p = exbuf; *p != '\0'; )
3884061Seric 			{
3894061Seric 				register char *wd;
3904061Seric 				char delim;
3914061Seric 
39258050Seric 				while (*p != '\0' && isascii(*p) && isspace(*p))
3934061Seric 					p++;
3944061Seric 				wd = p;
39558050Seric 				while (*p != '\0' && !(isascii(*p) && isspace(*p)))
3964061Seric 					p++;
3974061Seric 				delim = *p;
3984061Seric 				*p = '\0';
3994061Seric 				if (wd[0] != '\0')
40057135Seric 					setclass(bp[1], wd);
4014061Seric 				*p = delim;
4024061Seric 			}
4034061Seric 			break;
4044061Seric 
40559272Seric 		  case 'F':		/* word class from file */
40664133Seric 			for (p = &bp[2]; isascii(*p) && isspace(*p); )
40764133Seric 				p++;
40864133Seric 			if (p[0] == '-' && p[1] == 'o')
40964133Seric 			{
41064133Seric 				optional = TRUE;
41164133Seric 				while (*p != '\0' && !(isascii(*p) && isspace(*p)))
41264133Seric 					p++;
41364133Seric 				while (isascii(*p) && isspace(*p))
41464133Seric 					*p++;
41564133Seric 			}
41664133Seric 			else
41764133Seric 				optional = FALSE;
41864133Seric 			file = p;
41964133Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
42064133Seric 				p++;
42159272Seric 			if (*p == '\0')
42259272Seric 				p = "%s";
42359272Seric 			else
42459272Seric 			{
42559272Seric 				*p = '\0';
42659272Seric 				while (isascii(*++p) && isspace(*p))
42759272Seric 					continue;
42859272Seric 			}
42964133Seric 			fileclass(bp[1], file, p, safe, optional);
43059272Seric 			break;
43159272Seric 
43259156Seric #ifdef XLA
43359156Seric 		  case 'L':		/* extended load average description */
43459156Seric 			xla_init(&bp[1]);
43559156Seric 			break;
43659156Seric #endif
43759156Seric 
4384096Seric 		  case 'M':		/* define mailer */
43957135Seric 			makemailer(&bp[1]);
4404096Seric 			break;
4414096Seric 
4428252Seric 		  case 'O':		/* set option */
44358734Seric 			setoption(bp[1], &bp[2], safe, FALSE, e);
4448252Seric 			break;
4458252Seric 
4468252Seric 		  case 'P':		/* set precedence */
4478252Seric 			if (NumPriorities >= MAXPRIORITIES)
4488252Seric 			{
4498547Seric 				toomany('P', MAXPRIORITIES);
4508252Seric 				break;
4518252Seric 			}
45257135Seric 			for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
4538252Seric 				continue;
4548252Seric 			if (*p == '\0')
4558252Seric 				goto badline;
4568252Seric 			*p = '\0';
45757135Seric 			Priorities[NumPriorities].pri_name = newstr(&bp[1]);
4588252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
4598252Seric 			NumPriorities++;
4608252Seric 			break;
4618252Seric 
4628547Seric 		  case 'T':		/* trusted user(s) */
46358161Seric 			/* this option is obsolete, but will be ignored */
4648547Seric 			break;
4658547Seric 
46652645Seric 		  case 'V':		/* configuration syntax version */
46764440Seric 			for (p = &bp[1]; isascii(*p) && isspace(*p); p++)
46864440Seric 				continue;
46964440Seric 			if (!isascii(*p) || !isdigit(*p))
47064440Seric 			{
47164440Seric 				syserr("invalid argument to V line: \"%.20s\"",
47264440Seric 					&bp[1]);
47364440Seric 				break;
47464440Seric 			}
47564718Seric 			ConfigLevel = strtol(p, &ep, 10);
47664279Seric 			if (ConfigLevel >= 5)
47764279Seric 			{
47864279Seric 				/* level 5 configs have short name in $w */
47964279Seric 				p = macvalue('w', e);
48064279Seric 				if (p != NULL && (p = strchr(p, '.')) != NULL)
48164279Seric 					*p = '\0';
48264279Seric 			}
48364718Seric 			if (*ep++ == '/')
48464718Seric 			{
48564718Seric 				/* extract vendor code */
48664718Seric 				for (p = ep; isascii(*p) && isalpha(*p); )
48764718Seric 					p++;
48864718Seric 				*p = '\0';
48964718Seric 
49064718Seric 				if (!setvendor(ep))
49164718Seric 					syserr("invalid V line vendor code: \"%s\"",
49264718Seric 						ep);
49364718Seric 			}
49452645Seric 			break;
49552645Seric 
49653654Seric 		  case 'K':
49757135Seric 			makemapentry(&bp[1]);
49853654Seric 			break;
49953654Seric 
5003308Seric 		  default:
5014061Seric 		  badline:
50257135Seric 			syserr("unknown control line \"%s\"", bp);
5033308Seric 		}
50457135Seric 		if (bp != buf)
50557135Seric 			free(bp);
5063308Seric 	}
50752637Seric 	if (ferror(cf))
50852637Seric 	{
50952647Seric 		syserr("I/O read error", cfname);
51052637Seric 		exit(EX_OSFILE);
51152637Seric 	}
51252637Seric 	fclose(cf);
5139381Seric 	FileName = NULL;
51456836Seric 
51557076Seric 	if (stab("host", ST_MAP, ST_FIND) == NULL)
51657076Seric 	{
51757076Seric 		/* user didn't initialize: set up host map */
51857076Seric 		strcpy(buf, "host host");
51966334Seric #if NAMED_BIND
52057076Seric 		if (ConfigLevel >= 2)
52157076Seric 			strcat(buf, " -a.");
52264947Seric #endif
52357076Seric 		makemapentry(buf);
52457076Seric 	}
5254096Seric }
5264096Seric /*
5278547Seric **  TOOMANY -- signal too many of some option
5288547Seric **
5298547Seric **	Parameters:
5308547Seric **		id -- the id of the error line
5318547Seric **		maxcnt -- the maximum possible values
5328547Seric **
5338547Seric **	Returns:
5348547Seric **		none.
5358547Seric **
5368547Seric **	Side Effects:
5378547Seric **		gives a syserr.
5388547Seric */
5398547Seric 
5408547Seric toomany(id, maxcnt)
5418547Seric 	char id;
5428547Seric 	int maxcnt;
5438547Seric {
5449381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
5458547Seric }
5468547Seric /*
5474432Seric **  FILECLASS -- read members of a class from a file
5484432Seric **
5494432Seric **	Parameters:
5504432Seric **		class -- class to define.
5514432Seric **		filename -- name of file to read.
5524432Seric **		fmt -- scanf string to use for match.
55364133Seric **		safe -- if set, this is a safe read.
55464133Seric **		optional -- if set, it is not an error for the file to
55564133Seric **			not exist.
5564432Seric **
5574432Seric **	Returns:
5584432Seric **		none
5594432Seric **
5604432Seric **	Side Effects:
5614432Seric **
5624432Seric **		puts all lines in filename that match a scanf into
5634432Seric **			the named class.
5644432Seric */
5654432Seric 
56664133Seric fileclass(class, filename, fmt, safe, optional)
5674432Seric 	int class;
5684432Seric 	char *filename;
5694432Seric 	char *fmt;
57054973Seric 	bool safe;
57164133Seric 	bool optional;
5724432Seric {
57325808Seric 	FILE *f;
57454973Seric 	struct stat stbuf;
5754432Seric 	char buf[MAXLINE];
5764432Seric 
57766101Seric 	if (tTd(37, 2))
57866101Seric 		printf("fileclass(%s, fmt=%s)\n", filename, fmt);
57966101Seric 
58066031Seric 	if (filename[0] == '|')
58166031Seric 	{
58266031Seric 		syserr("fileclass: pipes (F%c%s) not supported due to security problems",
58366031Seric 			class, filename);
58466031Seric 		return;
58566031Seric 	}
58654973Seric 	if (stat(filename, &stbuf) < 0)
58754973Seric 	{
58866101Seric 		if (tTd(37, 2))
58966101Seric 			printf("  cannot stat (%s)\n", errstring(errno));
59064133Seric 		if (!optional)
59164133Seric 			syserr("fileclass: cannot stat %s", filename);
59254973Seric 		return;
59354973Seric 	}
59454973Seric 	if (!S_ISREG(stbuf.st_mode))
59554973Seric 	{
59654973Seric 		syserr("fileclass: %s not a regular file", filename);
59754973Seric 		return;
59854973Seric 	}
59954973Seric 	if (!safe && access(filename, R_OK) < 0)
60054973Seric 	{
60154973Seric 		syserr("fileclass: access denied on %s", filename);
60254973Seric 		return;
60354973Seric 	}
60454973Seric 	f = fopen(filename, "r");
6054432Seric 	if (f == NULL)
6064432Seric 	{
60754973Seric 		syserr("fileclass: cannot open %s", filename);
6084432Seric 		return;
6094432Seric 	}
6104432Seric 
6114432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
6124432Seric 	{
6134432Seric 		register STAB *s;
61425808Seric 		register char *p;
61525808Seric # ifdef SCANF
6164432Seric 		char wordbuf[MAXNAME+1];
6174432Seric 
6184432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
6194432Seric 			continue;
62025808Seric 		p = wordbuf;
62156795Seric # else /* SCANF */
62225808Seric 		p = buf;
62356795Seric # endif /* SCANF */
62425808Seric 
62525808Seric 		/*
62625808Seric 		**  Break up the match into words.
62725808Seric 		*/
62825808Seric 
62925808Seric 		while (*p != '\0')
63025808Seric 		{
63125808Seric 			register char *q;
63225808Seric 
63325808Seric 			/* strip leading spaces */
63458050Seric 			while (isascii(*p) && isspace(*p))
63525808Seric 				p++;
63625808Seric 			if (*p == '\0')
63725808Seric 				break;
63825808Seric 
63925808Seric 			/* find the end of the word */
64025808Seric 			q = p;
64158050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
64225808Seric 				p++;
64325808Seric 			if (*p != '\0')
64425808Seric 				*p++ = '\0';
64525808Seric 
64625808Seric 			/* enter the word in the symbol table */
64766101Seric 			setclass(class, q);
64825808Seric 		}
6494432Seric 	}
6504432Seric 
65154973Seric 	(void) fclose(f);
6524432Seric }
6534432Seric /*
6544096Seric **  MAKEMAILER -- define a new mailer.
6554096Seric **
6564096Seric **	Parameters:
65710327Seric **		line -- description of mailer.  This is in labeled
65810327Seric **			fields.  The fields are:
65910327Seric **			   P -- the path to the mailer
66010327Seric **			   F -- the flags associated with the mailer
66110327Seric **			   A -- the argv for this mailer
66210327Seric **			   S -- the sender rewriting set
66310327Seric **			   R -- the recipient rewriting set
66410327Seric **			   E -- the eol string
66510327Seric **			The first word is the canonical name of the mailer.
6664096Seric **
6674096Seric **	Returns:
6684096Seric **		none.
6694096Seric **
6704096Seric **	Side Effects:
6714096Seric **		enters the mailer into the mailer table.
6724096Seric */
6733308Seric 
67421066Seric makemailer(line)
6754096Seric 	char *line;
6764096Seric {
6774096Seric 	register char *p;
6788067Seric 	register struct mailer *m;
6798067Seric 	register STAB *s;
6808067Seric 	int i;
68110327Seric 	char fcode;
68258020Seric 	auto char *endp;
6834096Seric 	extern int NextMailer;
68410327Seric 	extern char **makeargv();
68510327Seric 	extern char *munchstring();
68610701Seric 	extern long atol();
6874096Seric 
68810327Seric 	/* allocate a mailer and set up defaults */
68910327Seric 	m = (struct mailer *) xalloc(sizeof *m);
69010327Seric 	bzero((char *) m, sizeof *m);
69110327Seric 	m->m_eol = "\n";
69210327Seric 
69310327Seric 	/* collect the mailer name */
69458050Seric 	for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++)
69510327Seric 		continue;
69610327Seric 	if (*p != '\0')
69710327Seric 		*p++ = '\0';
69810327Seric 	m->m_name = newstr(line);
69910327Seric 
70010327Seric 	/* now scan through and assign info from the fields */
70110327Seric 	while (*p != '\0')
70210327Seric 	{
70358333Seric 		auto char *delimptr;
70458333Seric 
70558050Seric 		while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p))))
70610327Seric 			p++;
70710327Seric 
70810327Seric 		/* p now points to field code */
70910327Seric 		fcode = *p;
71010327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
71110327Seric 			p++;
71210327Seric 		if (*p++ != '=')
71310327Seric 		{
71452637Seric 			syserr("mailer %s: `=' expected", m->m_name);
71510327Seric 			return;
71610327Seric 		}
71758050Seric 		while (isascii(*p) && isspace(*p))
71810327Seric 			p++;
71910327Seric 
72010327Seric 		/* p now points to the field body */
72158333Seric 		p = munchstring(p, &delimptr);
72210327Seric 
72310327Seric 		/* install the field into the mailer struct */
72410327Seric 		switch (fcode)
72510327Seric 		{
72610327Seric 		  case 'P':		/* pathname */
72710327Seric 			m->m_mailer = newstr(p);
72810327Seric 			break;
72910327Seric 
73010327Seric 		  case 'F':		/* flags */
73110687Seric 			for (; *p != '\0'; p++)
73258050Seric 				if (!(isascii(*p) && isspace(*p)))
73352637Seric 					setbitn(*p, m->m_flags);
73410327Seric 			break;
73510327Seric 
73610327Seric 		  case 'S':		/* sender rewriting ruleset */
73710327Seric 		  case 'R':		/* recipient rewriting ruleset */
73858020Seric 			i = strtol(p, &endp, 10);
73910327Seric 			if (i < 0 || i >= MAXRWSETS)
74010327Seric 			{
74110327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
74210327Seric 				return;
74310327Seric 			}
74410327Seric 			if (fcode == 'S')
74558020Seric 				m->m_sh_rwset = m->m_se_rwset = i;
74610327Seric 			else
74758020Seric 				m->m_rh_rwset = m->m_re_rwset = i;
74858020Seric 
74958020Seric 			p = endp;
75059985Seric 			if (*p++ == '/')
75158020Seric 			{
75258020Seric 				i = strtol(p, NULL, 10);
75358020Seric 				if (i < 0 || i >= MAXRWSETS)
75458020Seric 				{
75558020Seric 					syserr("invalid rewrite set, %d max",
75658020Seric 						MAXRWSETS);
75758020Seric 					return;
75858020Seric 				}
75958020Seric 				if (fcode == 'S')
76058020Seric 					m->m_sh_rwset = i;
76158020Seric 				else
76258020Seric 					m->m_rh_rwset = i;
76358020Seric 			}
76410327Seric 			break;
76510327Seric 
76610327Seric 		  case 'E':		/* end of line string */
76710327Seric 			m->m_eol = newstr(p);
76810327Seric 			break;
76910327Seric 
77010327Seric 		  case 'A':		/* argument vector */
77110327Seric 			m->m_argv = makeargv(p);
77210327Seric 			break;
77310701Seric 
77410701Seric 		  case 'M':		/* maximum message size */
77510701Seric 			m->m_maxsize = atol(p);
77610701Seric 			break;
77752106Seric 
77852106Seric 		  case 'L':		/* maximum line length */
77952106Seric 			m->m_linelimit = atoi(p);
78052106Seric 			break;
78158935Seric 
78258935Seric 		  case 'D':		/* working directory */
78358935Seric 			m->m_execdir = newstr(p);
78458935Seric 			break;
78510327Seric 		}
78610327Seric 
78758333Seric 		p = delimptr;
78810327Seric 	}
78910327Seric 
79052106Seric 	/* do some heuristic cleanup for back compatibility */
79152106Seric 	if (bitnset(M_LIMITS, m->m_flags))
79252106Seric 	{
79352106Seric 		if (m->m_linelimit == 0)
79452106Seric 			m->m_linelimit = SMTPLINELIM;
79555418Seric 		if (ConfigLevel < 2)
79652106Seric 			setbitn(M_7BITS, m->m_flags);
79752106Seric 	}
79852106Seric 
79958321Seric 	/* do some rationality checking */
80058321Seric 	if (m->m_argv == NULL)
80158321Seric 	{
80258321Seric 		syserr("M%s: A= argument required", m->m_name);
80358321Seric 		return;
80458321Seric 	}
80558321Seric 	if (m->m_mailer == NULL)
80658321Seric 	{
80758321Seric 		syserr("M%s: P= argument required", m->m_name);
80858321Seric 		return;
80958321Seric 	}
81058321Seric 
8114096Seric 	if (NextMailer >= MAXMAILERS)
8124096Seric 	{
8139381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
8144096Seric 		return;
8154096Seric 	}
81657402Seric 
81710327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
81857402Seric 	if (s->s_mailer != NULL)
81957402Seric 	{
82057402Seric 		i = s->s_mailer->m_mno;
82157402Seric 		free(s->s_mailer);
82257402Seric 	}
82357402Seric 	else
82457402Seric 	{
82557402Seric 		i = NextMailer++;
82657402Seric 	}
82757402Seric 	Mailer[i] = s->s_mailer = m;
82857454Seric 	m->m_mno = i;
82910327Seric }
83010327Seric /*
83110327Seric **  MUNCHSTRING -- translate a string into internal form.
83210327Seric **
83310327Seric **	Parameters:
83410327Seric **		p -- the string to munch.
83558333Seric **		delimptr -- if non-NULL, set to the pointer of the
83658333Seric **			field delimiter character.
83710327Seric **
83810327Seric **	Returns:
83910327Seric **		the munched string.
84010327Seric */
8414096Seric 
84210327Seric char *
84358333Seric munchstring(p, delimptr)
84410327Seric 	register char *p;
84558333Seric 	char **delimptr;
84610327Seric {
84710327Seric 	register char *q;
84810327Seric 	bool backslash = FALSE;
84910327Seric 	bool quotemode = FALSE;
85010327Seric 	static char buf[MAXLINE];
8514096Seric 
85210327Seric 	for (q = buf; *p != '\0'; p++)
8534096Seric 	{
85410327Seric 		if (backslash)
85510327Seric 		{
85610327Seric 			/* everything is roughly literal */
85710357Seric 			backslash = FALSE;
85810327Seric 			switch (*p)
85910327Seric 			{
86010327Seric 			  case 'r':		/* carriage return */
86110327Seric 				*q++ = '\r';
86210327Seric 				continue;
86310327Seric 
86410327Seric 			  case 'n':		/* newline */
86510327Seric 				*q++ = '\n';
86610327Seric 				continue;
86710327Seric 
86810327Seric 			  case 'f':		/* form feed */
86910327Seric 				*q++ = '\f';
87010327Seric 				continue;
87110327Seric 
87210327Seric 			  case 'b':		/* backspace */
87310327Seric 				*q++ = '\b';
87410327Seric 				continue;
87510327Seric 			}
87610327Seric 			*q++ = *p;
87710327Seric 		}
87810327Seric 		else
87910327Seric 		{
88010327Seric 			if (*p == '\\')
88110327Seric 				backslash = TRUE;
88210327Seric 			else if (*p == '"')
88310327Seric 				quotemode = !quotemode;
88410327Seric 			else if (quotemode || *p != ',')
88510327Seric 				*q++ = *p;
88610327Seric 			else
88710327Seric 				break;
88810327Seric 		}
8894096Seric 	}
8904096Seric 
89158333Seric 	if (delimptr != NULL)
89258333Seric 		*delimptr = p;
89310327Seric 	*q++ = '\0';
89410327Seric 	return (buf);
89510327Seric }
89610327Seric /*
89710327Seric **  MAKEARGV -- break up a string into words
89810327Seric **
89910327Seric **	Parameters:
90010327Seric **		p -- the string to break up.
90110327Seric **
90210327Seric **	Returns:
90310327Seric **		a char **argv (dynamically allocated)
90410327Seric **
90510327Seric **	Side Effects:
90610327Seric **		munges p.
90710327Seric */
9084096Seric 
90910327Seric char **
91010327Seric makeargv(p)
91110327Seric 	register char *p;
91210327Seric {
91310327Seric 	char *q;
91410327Seric 	int i;
91510327Seric 	char **avp;
91610327Seric 	char *argv[MAXPV + 1];
91710327Seric 
91810327Seric 	/* take apart the words */
91910327Seric 	i = 0;
92010327Seric 	while (*p != '\0' && i < MAXPV)
9214096Seric 	{
92210327Seric 		q = p;
92358050Seric 		while (*p != '\0' && !(isascii(*p) && isspace(*p)))
92410327Seric 			p++;
92558050Seric 		while (isascii(*p) && isspace(*p))
92610327Seric 			*p++ = '\0';
92710327Seric 		argv[i++] = newstr(q);
9284096Seric 	}
92910327Seric 	argv[i++] = NULL;
9304096Seric 
93110327Seric 	/* now make a copy of the argv */
93210327Seric 	avp = (char **) xalloc(sizeof *avp * i);
93316893Seric 	bcopy((char *) argv, (char *) avp, sizeof *avp * i);
93410327Seric 
93510327Seric 	return (avp);
9363308Seric }
9373308Seric /*
9383308Seric **  PRINTRULES -- print rewrite rules (for debugging)
9393308Seric **
9403308Seric **	Parameters:
9413308Seric **		none.
9423308Seric **
9433308Seric **	Returns:
9443308Seric **		none.
9453308Seric **
9463308Seric **	Side Effects:
9473308Seric **		prints rewrite rules.
9483308Seric */
9493308Seric 
9503308Seric printrules()
9513308Seric {
9523308Seric 	register struct rewrite *rwp;
9534072Seric 	register int ruleset;
9543308Seric 
9554072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
9563308Seric 	{
9574072Seric 		if (RewriteRules[ruleset] == NULL)
9584072Seric 			continue;
9598067Seric 		printf("\n----Rule Set %d:", ruleset);
9603308Seric 
9614072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
9623308Seric 		{
9638067Seric 			printf("\nLHS:");
9648067Seric 			printav(rwp->r_lhs);
9658067Seric 			printf("RHS:");
9668067Seric 			printav(rwp->r_rhs);
9673308Seric 		}
9683308Seric 	}
9693308Seric }
9704319Seric 
9714096Seric /*
9728256Seric **  SETOPTION -- set global processing option
9738256Seric **
9748256Seric **	Parameters:
9758256Seric **		opt -- option name.
9768256Seric **		val -- option value (as a text string).
97721755Seric **		safe -- set if this came from a configuration file.
97821755Seric **			Some options (if set from the command line) will
97921755Seric **			reset the user id to avoid security problems.
9808269Seric **		sticky -- if set, don't let other setoptions override
9818269Seric **			this value.
98258734Seric **		e -- the main envelope.
9838256Seric **
9848256Seric **	Returns:
9858256Seric **		none.
9868256Seric **
9878256Seric **	Side Effects:
9888256Seric **		Sets options as implied by the arguments.
9898256Seric */
9908256Seric 
99110687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
9928269Seric 
99357207Seric 
99466334Seric #if NAMED_BIND
99557207Seric 
99657207Seric struct resolverflags
99757207Seric {
99857207Seric 	char	*rf_name;	/* name of the flag */
99957207Seric 	long	rf_bits;	/* bits to set/clear */
100057207Seric } ResolverFlags[] =
100157207Seric {
100257207Seric 	"debug",	RES_DEBUG,
100357207Seric 	"aaonly",	RES_AAONLY,
100457207Seric 	"usevc",	RES_USEVC,
100557207Seric 	"primary",	RES_PRIMARY,
100657207Seric 	"igntc",	RES_IGNTC,
100757207Seric 	"recurse",	RES_RECURSE,
100857207Seric 	"defnames",	RES_DEFNAMES,
100957207Seric 	"stayopen",	RES_STAYOPEN,
101057207Seric 	"dnsrch",	RES_DNSRCH,
101165583Seric 	"true",		0,		/* to avoid error on old syntax */
101257207Seric 	NULL,		0
101357207Seric };
101457207Seric 
101557207Seric #endif
101657207Seric 
101758734Seric setoption(opt, val, safe, sticky, e)
10188256Seric 	char opt;
10198256Seric 	char *val;
102021755Seric 	bool safe;
10218269Seric 	bool sticky;
102258734Seric 	register ENVELOPE *e;
10238256Seric {
102457207Seric 	register char *p;
10258265Seric 	extern bool atobool();
102612633Seric 	extern time_t convtime();
102714879Seric 	extern int QueueLA;
102814879Seric 	extern int RefuseLA;
102964718Seric 	extern bool Warn_Q_option;
103017474Seric 	extern bool trusteduser();
10318256Seric 
10328256Seric 	if (tTd(37, 1))
10339341Seric 		printf("setoption %c=%s", opt, val);
10348256Seric 
10358256Seric 	/*
10368269Seric 	**  See if this option is preset for us.
10378256Seric 	*/
10388256Seric 
103959731Seric 	if (!sticky && bitnset(opt, StickyOpt))
10408269Seric 	{
10419341Seric 		if (tTd(37, 1))
10429341Seric 			printf(" (ignored)\n");
10438269Seric 		return;
10448269Seric 	}
10458269Seric 
104621755Seric 	/*
104721755Seric 	**  Check to see if this option can be specified by this user.
104821755Seric 	*/
104921755Seric 
105063787Seric 	if (!safe && RealUid == 0)
105121755Seric 		safe = TRUE;
1052*66383Scorrigan 	if (!safe && strchr("bCdeijLmoprsvw7", opt) == NULL)
105321755Seric 	{
105439111Srick 		if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
105521755Seric 		{
105636582Sbostic 			if (tTd(37, 1))
105736582Sbostic 				printf(" (unsafe)");
105863787Seric 			if (RealUid != geteuid())
105936582Sbostic 			{
106051210Seric 				if (tTd(37, 1))
106151210Seric 					printf("(Resetting uid)");
106263787Seric 				(void) setgid(RealGid);
106363787Seric 				(void) setuid(RealUid);
106436582Sbostic 			}
106521755Seric 		}
106621755Seric 	}
106751210Seric 	if (tTd(37, 1))
106817985Seric 		printf("\n");
10698269Seric 
10708256Seric 	switch (opt)
10718256Seric 	{
107259709Seric 	  case '7':		/* force seven-bit input */
107359709Seric 		SevenBit = atobool(val);
107452106Seric 		break;
107552106Seric 
10768256Seric 	  case 'A':		/* set default alias file */
10779381Seric 		if (val[0] == '\0')
107859672Seric 			setalias("aliases");
10799381Seric 		else
108059672Seric 			setalias(val);
10818256Seric 		break;
10828256Seric 
108317474Seric 	  case 'a':		/* look N minutes for "@:@" in alias file */
108417474Seric 		if (val[0] == '\0')
108564796Seric 			SafeAlias = 5 * 60;		/* five minutes */
108617474Seric 		else
108764796Seric 			SafeAlias = convtime(val, 'm');
108817474Seric 		break;
108917474Seric 
109016843Seric 	  case 'B':		/* substitution for blank character */
109116843Seric 		SpaceSub = val[0];
109216843Seric 		if (SpaceSub == '\0')
109316843Seric 			SpaceSub = ' ';
109416843Seric 		break;
109516843Seric 
109659283Seric 	  case 'b':		/* min blocks free on queue fs/max msg size */
109759283Seric 		p = strchr(val, '/');
109859283Seric 		if (p != NULL)
109959283Seric 		{
110059283Seric 			*p++ = '\0';
110159283Seric 			MaxMessageSize = atol(p);
110259283Seric 		}
110358082Seric 		MinBlocksFree = atol(val);
110458082Seric 		break;
110558082Seric 
11069284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
11079381Seric 		NoConnect = atobool(val);
11089284Seric 		break;
11099284Seric 
111051305Seric 	  case 'C':		/* checkpoint every N addresses */
111151305Seric 		CheckpointInterval = atoi(val);
111224944Seric 		break;
111324944Seric 
11149284Seric 	  case 'd':		/* delivery mode */
11159284Seric 		switch (*val)
11168269Seric 		{
11179284Seric 		  case '\0':
111858734Seric 			e->e_sendmode = SM_DELIVER;
11198269Seric 			break;
11208269Seric 
112110755Seric 		  case SM_QUEUE:	/* queue only */
112210755Seric #ifndef QUEUE
112310755Seric 			syserr("need QUEUE to set -odqueue");
112456795Seric #endif /* QUEUE */
112510755Seric 			/* fall through..... */
112610755Seric 
11279284Seric 		  case SM_DELIVER:	/* do everything */
11289284Seric 		  case SM_FORK:		/* fork after verification */
112958734Seric 			e->e_sendmode = *val;
11308269Seric 			break;
11318269Seric 
11328269Seric 		  default:
11339284Seric 			syserr("Unknown delivery mode %c", *val);
11348269Seric 			exit(EX_USAGE);
11358269Seric 		}
11368269Seric 		break;
11378269Seric 
11389146Seric 	  case 'D':		/* rebuild alias database as needed */
11399381Seric 		AutoRebuild = atobool(val);
11409146Seric 		break;
11419146Seric 
114255372Seric 	  case 'E':		/* error message header/header file */
114355379Seric 		if (*val != '\0')
114455379Seric 			ErrMsgFile = newstr(val);
114555372Seric 		break;
114655372Seric 
11478269Seric 	  case 'e':		/* set error processing mode */
11488269Seric 		switch (*val)
11498269Seric 		{
11509381Seric 		  case EM_QUIET:	/* be silent about it */
11519381Seric 		  case EM_MAIL:		/* mail back */
11529381Seric 		  case EM_BERKNET:	/* do berknet error processing */
11539381Seric 		  case EM_WRITE:	/* write back (or mail) */
11548269Seric 			HoldErrs = TRUE;
11559381Seric 			/* fall through... */
11568269Seric 
11579381Seric 		  case EM_PRINT:	/* print errors normally (default) */
115858734Seric 			e->e_errormode = *val;
11598269Seric 			break;
11608269Seric 		}
11618269Seric 		break;
11628269Seric 
11639049Seric 	  case 'F':		/* file mode */
116417975Seric 		FileMode = atooct(val) & 0777;
11659049Seric 		break;
11669049Seric 
11678269Seric 	  case 'f':		/* save Unix-style From lines on front */
11689381Seric 		SaveFrom = atobool(val);
11698269Seric 		break;
11708269Seric 
117153735Seric 	  case 'G':		/* match recipients against GECOS field */
117253735Seric 		MatchGecos = atobool(val);
117353735Seric 		break;
117453735Seric 
11758256Seric 	  case 'g':		/* default gid */
117664133Seric 		if (isascii(*val) && isdigit(*val))
117764133Seric 			DefGid = atoi(val);
117864133Seric 		else
117964133Seric 		{
118064133Seric 			register struct group *gr;
118164133Seric 
118264133Seric 			DefGid = -1;
118364133Seric 			gr = getgrnam(val);
118464133Seric 			if (gr == NULL)
118564133Seric 				syserr("readcf: option g: unknown group %s", val);
118664133Seric 			else
118764133Seric 				DefGid = gr->gr_gid;
118864133Seric 		}
11898256Seric 		break;
11908256Seric 
11918256Seric 	  case 'H':		/* help file */
11929381Seric 		if (val[0] == '\0')
11938269Seric 			HelpFile = "sendmail.hf";
11949381Seric 		else
11959381Seric 			HelpFile = newstr(val);
11968256Seric 		break;
11978256Seric 
119851305Seric 	  case 'h':		/* maximum hop count */
119951305Seric 		MaxHopCount = atoi(val);
120051305Seric 		break;
120151305Seric 
120235651Seric 	  case 'I':		/* use internet domain name server */
120366334Seric #if NAMED_BIND
120457207Seric 		UseNameServer = TRUE;
120557207Seric 		for (p = val; *p != 0; )
120657207Seric 		{
120757207Seric 			bool clearmode;
120857207Seric 			char *q;
120957207Seric 			struct resolverflags *rfp;
121057207Seric 
121157207Seric 			while (*p == ' ')
121257207Seric 				p++;
121357207Seric 			if (*p == '\0')
121457207Seric 				break;
121557207Seric 			clearmode = FALSE;
121657207Seric 			if (*p == '-')
121757207Seric 				clearmode = TRUE;
121857207Seric 			else if (*p != '+')
121957207Seric 				p--;
122057207Seric 			p++;
122157207Seric 			q = p;
122258050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
122357207Seric 				p++;
122457207Seric 			if (*p != '\0')
122557207Seric 				*p++ = '\0';
122657207Seric 			for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
122757207Seric 			{
122857207Seric 				if (strcasecmp(q, rfp->rf_name) == 0)
122957207Seric 					break;
123057207Seric 			}
123164923Seric 			if (rfp->rf_name == NULL)
123264923Seric 				syserr("readcf: I option value %s unrecognized", q);
123364923Seric 			else if (clearmode)
123457207Seric 				_res.options &= ~rfp->rf_bits;
123557207Seric 			else
123657207Seric 				_res.options |= rfp->rf_bits;
123757207Seric 		}
123857207Seric 		if (tTd(8, 2))
123957207Seric 			printf("_res.options = %x\n", _res.options);
124057207Seric #else
124157207Seric 		usrerr("name server (I option) specified but BIND not compiled in");
124257207Seric #endif
124335651Seric 		break;
124435651Seric 
12458269Seric 	  case 'i':		/* ignore dot lines in message */
12469381Seric 		IgnrDot = atobool(val);
12478269Seric 		break;
12488269Seric 
124959730Seric 	  case 'j':		/* send errors in MIME (RFC 1341) format */
125059730Seric 		SendMIMEErrors = atobool(val);
125159730Seric 		break;
125259730Seric 
125357136Seric 	  case 'J':		/* .forward search path */
125457136Seric 		ForwardPath = newstr(val);
125557136Seric 		break;
125657136Seric 
125754967Seric 	  case 'k':		/* connection cache size */
125854967Seric 		MaxMciCache = atoi(val);
125956215Seric 		if (MaxMciCache < 0)
126056215Seric 			MaxMciCache = 0;
126154967Seric 		break;
126254967Seric 
126354967Seric 	  case 'K':		/* connection cache timeout */
126458796Seric 		MciCacheTimeout = convtime(val, 'm');
126554967Seric 		break;
126654967Seric 
126761104Seric 	  case 'l':		/* use Errors-To: header */
126861104Seric 		UseErrorsTo = atobool(val);
126961104Seric 		break;
127061104Seric 
12718256Seric 	  case 'L':		/* log level */
127264140Seric 		if (safe || LogLevel < atoi(val))
127364140Seric 			LogLevel = atoi(val);
12748256Seric 		break;
12758256Seric 
12768269Seric 	  case 'M':		/* define macro */
12779381Seric 		define(val[0], newstr(&val[1]), CurEnv);
127816878Seric 		sticky = FALSE;
12798269Seric 		break;
12808269Seric 
12818269Seric 	  case 'm':		/* send to me too */
12829381Seric 		MeToo = atobool(val);
12838269Seric 		break;
12848269Seric 
128525820Seric 	  case 'n':		/* validate RHS in newaliases */
128625820Seric 		CheckAliases = atobool(val);
128725820Seric 		break;
128825820Seric 
128961104Seric 	    /* 'N' available -- was "net name" */
129061104Seric 
129158851Seric 	  case 'O':		/* daemon options */
129258851Seric 		setdaemonoptions(val);
129358851Seric 		break;
129458851Seric 
12958269Seric 	  case 'o':		/* assume old style headers */
12969381Seric 		if (atobool(val))
12979341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
12989341Seric 		else
12999341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
13008269Seric 		break;
13018269Seric 
130258082Seric 	  case 'p':		/* select privacy level */
130358082Seric 		p = val;
130458082Seric 		for (;;)
130558082Seric 		{
130658082Seric 			register struct prival *pv;
130758082Seric 			extern struct prival PrivacyValues[];
130858082Seric 
130958082Seric 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
131058082Seric 				p++;
131158082Seric 			if (*p == '\0')
131258082Seric 				break;
131358082Seric 			val = p;
131458082Seric 			while (isascii(*p) && isalnum(*p))
131558082Seric 				p++;
131658082Seric 			if (*p != '\0')
131758082Seric 				*p++ = '\0';
131858082Seric 
131958082Seric 			for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
132058082Seric 			{
132158082Seric 				if (strcasecmp(val, pv->pv_name) == 0)
132258082Seric 					break;
132358082Seric 			}
132458886Seric 			if (pv->pv_name == NULL)
132558886Seric 				syserr("readcf: Op line: %s unrecognized", val);
132658082Seric 			PrivacyFlags |= pv->pv_flag;
132758082Seric 		}
132858082Seric 		break;
132958082Seric 
133024944Seric 	  case 'P':		/* postmaster copy address for returned mail */
133124944Seric 		PostMasterCopy = newstr(val);
133224944Seric 		break;
133324944Seric 
133424944Seric 	  case 'q':		/* slope of queue only function */
133524944Seric 		QueueFactor = atoi(val);
133624944Seric 		break;
133724944Seric 
13388256Seric 	  case 'Q':		/* queue directory */
13399381Seric 		if (val[0] == '\0')
13408269Seric 			QueueDir = "mqueue";
13419381Seric 		else
13429381Seric 			QueueDir = newstr(val);
134358789Seric 		if (RealUid != 0 && !safe)
134464718Seric 			Warn_Q_option = TRUE;
13458256Seric 		break;
13468256Seric 
134758148Seric 	  case 'R':		/* don't prune routes */
134858148Seric 		DontPruneRoutes = atobool(val);
134958148Seric 		break;
135058148Seric 
13518256Seric 	  case 'r':		/* read timeout */
135258112Seric 		settimeouts(val);
13538256Seric 		break;
13548256Seric 
13558256Seric 	  case 'S':		/* status file */
13569381Seric 		if (val[0] == '\0')
13578269Seric 			StatFile = "sendmail.st";
13589381Seric 		else
13599381Seric 			StatFile = newstr(val);
13608256Seric 		break;
13618256Seric 
13628265Seric 	  case 's':		/* be super safe, even if expensive */
13639381Seric 		SuperSafe = atobool(val);
13648256Seric 		break;
13658256Seric 
13668256Seric 	  case 'T':		/* queue timeout */
136758737Seric 		p = strchr(val, '/');
136858737Seric 		if (p != NULL)
136958737Seric 		{
137058737Seric 			*p++ = '\0';
137158796Seric 			TimeOuts.to_q_warning = convtime(p, 'd');
137258737Seric 		}
137358796Seric 		TimeOuts.to_q_return = convtime(val, 'h');
137454967Seric 		break;
13758256Seric 
13768265Seric 	  case 't':		/* time zone name */
137752106Seric 		TimeZoneSpec = newstr(val);
13788265Seric 		break;
13798265Seric 
138050556Seric 	  case 'U':		/* location of user database */
138151360Seric 		UdbSpec = newstr(val);
138250556Seric 		break;
138350556Seric 
13848256Seric 	  case 'u':		/* set default uid */
138564133Seric 		if (isascii(*val) && isdigit(*val))
138664133Seric 			DefUid = atoi(val);
138764133Seric 		else
138864133Seric 		{
138964133Seric 			register struct passwd *pw;
139064133Seric 
139164133Seric 			DefUid = -1;
139264133Seric 			pw = getpwnam(val);
139364133Seric 			if (pw == NULL)
139464133Seric 				syserr("readcf: option u: unknown user %s", val);
139564133Seric 			else
139664133Seric 				DefUid = pw->pw_uid;
139764133Seric 		}
139840973Sbostic 		setdefuser();
13998256Seric 		break;
14008256Seric 
140158851Seric 	  case 'V':		/* fallback MX host */
140258851Seric 		FallBackMX = newstr(val);
140358851Seric 		break;
140458851Seric 
14058269Seric 	  case 'v':		/* run in verbose mode */
14069381Seric 		Verbose = atobool(val);
14078256Seric 		break;
14088256Seric 
140963837Seric 	  case 'w':		/* if we are best MX, try host directly */
141063837Seric 		TryNullMXList = atobool(val);
141163837Seric 		break;
141261104Seric 
141361104Seric 	    /* 'W' available -- was wizard password */
141461104Seric 
141514879Seric 	  case 'x':		/* load avg at which to auto-queue msgs */
141614879Seric 		QueueLA = atoi(val);
141714879Seric 		break;
141814879Seric 
141914879Seric 	  case 'X':		/* load avg at which to auto-reject connections */
142014879Seric 		RefuseLA = atoi(val);
142114879Seric 		break;
142214879Seric 
142324981Seric 	  case 'y':		/* work recipient factor */
142424981Seric 		WkRecipFact = atoi(val);
142524981Seric 		break;
142624981Seric 
142724981Seric 	  case 'Y':		/* fork jobs during queue runs */
142824952Seric 		ForkQueueRuns = atobool(val);
142924952Seric 		break;
143024952Seric 
143124981Seric 	  case 'z':		/* work message class factor */
143224981Seric 		WkClassFact = atoi(val);
143324981Seric 		break;
143424981Seric 
143524981Seric 	  case 'Z':		/* work time factor */
143624981Seric 		WkTimeFact = atoi(val);
143724981Seric 		break;
143824981Seric 
14398256Seric 	  default:
14408256Seric 		break;
14418256Seric 	}
144216878Seric 	if (sticky)
144316878Seric 		setbitn(opt, StickyOpt);
14449188Seric 	return;
14458256Seric }
144610687Seric /*
144710687Seric **  SETCLASS -- set a word into a class
144810687Seric **
144910687Seric **	Parameters:
145010687Seric **		class -- the class to put the word in.
145110687Seric **		word -- the word to enter
145210687Seric **
145310687Seric **	Returns:
145410687Seric **		none.
145510687Seric **
145610687Seric **	Side Effects:
145710687Seric **		puts the word into the symbol table.
145810687Seric */
145910687Seric 
146010687Seric setclass(class, word)
146110687Seric 	int class;
146210687Seric 	char *word;
146310687Seric {
146410687Seric 	register STAB *s;
146510687Seric 
146657943Seric 	if (tTd(37, 8))
146764326Seric 		printf("setclass(%c, %s)\n", class, word);
146810687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
146910687Seric 	setbitn(class, s->s_class);
147010687Seric }
147153654Seric /*
147253654Seric **  MAKEMAPENTRY -- create a map entry
147353654Seric **
147453654Seric **	Parameters:
147553654Seric **		line -- the config file line
147653654Seric **
147753654Seric **	Returns:
147853654Seric **		TRUE if it successfully entered the map entry.
147953654Seric **		FALSE otherwise (usually syntax error).
148053654Seric **
148153654Seric **	Side Effects:
148253654Seric **		Enters the map into the dictionary.
148353654Seric */
148453654Seric 
148553654Seric void
148653654Seric makemapentry(line)
148753654Seric 	char *line;
148853654Seric {
148953654Seric 	register char *p;
149053654Seric 	char *mapname;
149153654Seric 	char *classname;
149264078Seric 	register STAB *s;
149353654Seric 	STAB *class;
149453654Seric 
149558050Seric 	for (p = line; isascii(*p) && isspace(*p); p++)
149653654Seric 		continue;
149758050Seric 	if (!(isascii(*p) && isalnum(*p)))
149853654Seric 	{
149953654Seric 		syserr("readcf: config K line: no map name");
150053654Seric 		return;
150153654Seric 	}
150253654Seric 
150353654Seric 	mapname = p;
150458050Seric 	while (isascii(*++p) && isalnum(*p))
150553654Seric 		continue;
150653654Seric 	if (*p != '\0')
150753654Seric 		*p++ = '\0';
150858050Seric 	while (isascii(*p) && isspace(*p))
150953654Seric 		p++;
151058050Seric 	if (!(isascii(*p) && isalnum(*p)))
151153654Seric 	{
151253654Seric 		syserr("readcf: config K line, map %s: no map class", mapname);
151353654Seric 		return;
151453654Seric 	}
151553654Seric 	classname = p;
151658050Seric 	while (isascii(*++p) && isalnum(*p))
151753654Seric 		continue;
151853654Seric 	if (*p != '\0')
151953654Seric 		*p++ = '\0';
152058050Seric 	while (isascii(*p) && isspace(*p))
152153654Seric 		p++;
152253654Seric 
152353654Seric 	/* look up the class */
152453654Seric 	class = stab(classname, ST_MAPCLASS, ST_FIND);
152553654Seric 	if (class == NULL)
152653654Seric 	{
152753654Seric 		syserr("readcf: map %s: class %s not available", mapname, classname);
152853654Seric 		return;
152953654Seric 	}
153053654Seric 
153153654Seric 	/* enter the map */
153264078Seric 	s = stab(mapname, ST_MAP, ST_ENTER);
153364078Seric 	s->s_map.map_class = &class->s_mapclass;
153464078Seric 	s->s_map.map_mname = newstr(mapname);
153553654Seric 
153664078Seric 	if (class->s_mapclass.map_parse(&s->s_map, p))
153764078Seric 		s->s_map.map_mflags |= MF_VALID;
153864078Seric 
153964078Seric 	if (tTd(37, 5))
154064078Seric 	{
154164078Seric 		printf("map %s, class %s, flags %x, file %s,\n",
154264078Seric 			s->s_map.map_mname, s->s_map.map_class->map_cname,
154364078Seric 			s->s_map.map_mflags,
154464078Seric 			s->s_map.map_file == NULL ? "(null)" : s->s_map.map_file);
154564078Seric 		printf("\tapp %s, domain %s, rebuild %s\n",
154664078Seric 			s->s_map.map_app == NULL ? "(null)" : s->s_map.map_app,
154764078Seric 			s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain,
154864078Seric 			s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild);
154964078Seric 	}
155053654Seric }
155158112Seric /*
155258112Seric **  SETTIMEOUTS -- parse and set timeout values
155358112Seric **
155458112Seric **	Parameters:
155558112Seric **		val -- a pointer to the values.  If NULL, do initial
155658112Seric **			settings.
155758112Seric **
155858112Seric **	Returns:
155958112Seric **		none.
156058112Seric **
156158112Seric **	Side Effects:
156258112Seric **		Initializes the TimeOuts structure
156358112Seric */
156458112Seric 
156564255Seric #define SECONDS
156658112Seric #define MINUTES	* 60
156758112Seric #define HOUR	* 3600
156858112Seric 
156958112Seric settimeouts(val)
157058112Seric 	register char *val;
157158112Seric {
157258112Seric 	register char *p;
157358671Seric 	extern time_t convtime();
157458112Seric 
157558112Seric 	if (val == NULL)
157658112Seric 	{
157758112Seric 		TimeOuts.to_initial = (time_t) 5 MINUTES;
157858112Seric 		TimeOuts.to_helo = (time_t) 5 MINUTES;
157958112Seric 		TimeOuts.to_mail = (time_t) 10 MINUTES;
158058112Seric 		TimeOuts.to_rcpt = (time_t) 1 HOUR;
158158112Seric 		TimeOuts.to_datainit = (time_t) 5 MINUTES;
158258112Seric 		TimeOuts.to_datablock = (time_t) 1 HOUR;
158358112Seric 		TimeOuts.to_datafinal = (time_t) 1 HOUR;
158458112Seric 		TimeOuts.to_rset = (time_t) 5 MINUTES;
158558112Seric 		TimeOuts.to_quit = (time_t) 2 MINUTES;
158658112Seric 		TimeOuts.to_nextcommand = (time_t) 1 HOUR;
158758112Seric 		TimeOuts.to_miscshort = (time_t) 2 MINUTES;
158864255Seric 		TimeOuts.to_ident = (time_t) 30 SECONDS;
158958112Seric 		return;
159058112Seric 	}
159158112Seric 
159258112Seric 	for (;; val = p)
159358112Seric 	{
159458112Seric 		while (isascii(*val) && isspace(*val))
159558112Seric 			val++;
159658112Seric 		if (*val == '\0')
159758112Seric 			break;
159858112Seric 		for (p = val; *p != '\0' && *p != ','; p++)
159958112Seric 			continue;
160058112Seric 		if (*p != '\0')
160158112Seric 			*p++ = '\0';
160258112Seric 
160358112Seric 		if (isascii(*val) && isdigit(*val))
160458112Seric 		{
160558112Seric 			/* old syntax -- set everything */
160658796Seric 			TimeOuts.to_mail = convtime(val, 'm');
160758112Seric 			TimeOuts.to_rcpt = TimeOuts.to_mail;
160858112Seric 			TimeOuts.to_datainit = TimeOuts.to_mail;
160958112Seric 			TimeOuts.to_datablock = TimeOuts.to_mail;
161058112Seric 			TimeOuts.to_datafinal = TimeOuts.to_mail;
161158112Seric 			TimeOuts.to_nextcommand = TimeOuts.to_mail;
161258112Seric 			continue;
161358112Seric 		}
161458112Seric 		else
161558112Seric 		{
161658112Seric 			register char *q = strchr(val, '=');
161758112Seric 			time_t to;
161858112Seric 
161958112Seric 			if (q == NULL)
162058112Seric 			{
162158112Seric 				/* syntax error */
162258112Seric 				continue;
162358112Seric 			}
162458112Seric 			*q++ = '\0';
162558796Seric 			to = convtime(q, 'm');
162658112Seric 
162758112Seric 			if (strcasecmp(val, "initial") == 0)
162858112Seric 				TimeOuts.to_initial = to;
162958112Seric 			else if (strcasecmp(val, "mail") == 0)
163058112Seric 				TimeOuts.to_mail = to;
163158112Seric 			else if (strcasecmp(val, "rcpt") == 0)
163258112Seric 				TimeOuts.to_rcpt = to;
163358112Seric 			else if (strcasecmp(val, "datainit") == 0)
163458112Seric 				TimeOuts.to_datainit = to;
163558112Seric 			else if (strcasecmp(val, "datablock") == 0)
163658112Seric 				TimeOuts.to_datablock = to;
163758112Seric 			else if (strcasecmp(val, "datafinal") == 0)
163858112Seric 				TimeOuts.to_datafinal = to;
163958112Seric 			else if (strcasecmp(val, "command") == 0)
164058112Seric 				TimeOuts.to_nextcommand = to;
164158112Seric 			else if (strcasecmp(val, "rset") == 0)
164258112Seric 				TimeOuts.to_rset = to;
164358112Seric 			else if (strcasecmp(val, "helo") == 0)
164458112Seric 				TimeOuts.to_helo = to;
164558112Seric 			else if (strcasecmp(val, "quit") == 0)
164658112Seric 				TimeOuts.to_quit = to;
164758112Seric 			else if (strcasecmp(val, "misc") == 0)
164858112Seric 				TimeOuts.to_miscshort = to;
164964255Seric 			else if (strcasecmp(val, "ident") == 0)
165064255Seric 				TimeOuts.to_ident = to;
165158112Seric 			else
165258112Seric 				syserr("settimeouts: invalid timeout %s", val);
165358112Seric 		}
165458112Seric 	}
165558112Seric }
1656