xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 67547)
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*67547Seric static char sccsid[] = "@(#)readcf.c	8.27 (Berkeley) 07/23/94";
1133731Sbostic #endif /* not lint */
1222709Sdist 
133313Seric # include "sendmail.h"
1464133Seric # include <pwd.h>
1564133Seric # include <grp.h>
1666334Seric #if NAMED_BIND
1757207Seric # include <resolv.h>
1857207Seric #endif
193308Seric 
203308Seric /*
213308Seric **  READCF -- read control file.
223308Seric **
233308Seric **	This routine reads the control file and builds the internal
243308Seric **	form.
253308Seric **
264432Seric **	The file is formatted as a sequence of lines, each taken
274432Seric **	atomically.  The first character of each line describes how
284432Seric **	the line is to be interpreted.  The lines are:
294432Seric **		Dxval		Define macro x to have value val.
304432Seric **		Cxword		Put word into class x.
314432Seric **		Fxfile [fmt]	Read file for lines to put into
324432Seric **				class x.  Use scanf string 'fmt'
334432Seric **				or "%s" if not present.  Fmt should
344432Seric **				only produce one string-valued result.
354432Seric **		Hname: value	Define header with field-name 'name'
364432Seric **				and value as specified; this will be
374432Seric **				macro expanded immediately before
384432Seric **				use.
394432Seric **		Sn		Use rewriting set n.
404432Seric **		Rlhs rhs	Rewrite addresses that match lhs to
414432Seric **				be rhs.
4224944Seric **		Mn arg=val...	Define mailer.  n is the internal name.
4324944Seric **				Args specify mailer parameters.
448252Seric **		Oxvalue		Set option x to value.
458252Seric **		Pname=value	Set precedence name to value.
4664718Seric **		Vversioncode[/vendorcode]
4764718Seric **				Version level/vendor name of
4864718Seric **				configuration syntax.
4953654Seric **		Kmapname mapclass arguments....
5053654Seric **				Define keyed lookup of a given class.
5153654Seric **				Arguments are class dependent.
524432Seric **
533308Seric **	Parameters:
543308Seric **		cfname -- control file name.
5554973Seric **		safe -- TRUE if this is the system config file;
5654973Seric **			FALSE otherwise.
5755012Seric **		e -- the main envelope.
583308Seric **
593308Seric **	Returns:
603308Seric **		none.
613308Seric **
623308Seric **	Side Effects:
633308Seric **		Builds several internal tables.
643308Seric */
653308Seric 
6655012Seric readcf(cfname, safe, e)
673308Seric 	char *cfname;
6854973Seric 	bool safe;
6955012Seric 	register ENVELOPE *e;
703308Seric {
713308Seric 	FILE *cf;
728547Seric 	int ruleset = 0;
738547Seric 	char *q;
749350Seric 	struct rewrite *rwp = NULL;
7557135Seric 	char *bp;
7664718Seric 	auto char *ep;
7757589Seric 	int nfuzzy;
7864133Seric 	char *file;
7964133Seric 	bool optional;
803308Seric 	char buf[MAXLINE];
813308Seric 	register char *p;
823308Seric 	extern char **copyplist();
8352647Seric 	struct stat statb;
845909Seric 	char exbuf[MAXLINE];
8565066Seric 	char pvpbuf[MAXLINE + MAXATOM];
8610709Seric 	extern char *munchstring();
8753654Seric 	extern void makemapentry();
883308Seric 
8952647Seric 	FileName = cfname;
9052647Seric 	LineNumber = 0;
9152647Seric 
923308Seric 	cf = fopen(cfname, "r");
933308Seric 	if (cf == NULL)
943308Seric 	{
9552647Seric 		syserr("cannot open");
963308Seric 		exit(EX_OSFILE);
973308Seric 	}
983308Seric 
9952647Seric 	if (fstat(fileno(cf), &statb) < 0)
10052647Seric 	{
10152647Seric 		syserr("cannot fstat");
10252647Seric 		exit(EX_OSFILE);
10352647Seric 	}
10452647Seric 
10552647Seric 	if (!S_ISREG(statb.st_mode))
10652647Seric 	{
10752647Seric 		syserr("not a plain file");
10852647Seric 		exit(EX_OSFILE);
10952647Seric 	}
11052647Seric 
11152647Seric 	if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
11252647Seric 	{
11353037Seric 		if (OpMode == MD_DAEMON || OpMode == MD_FREEZE)
11453037Seric 			fprintf(stderr, "%s: WARNING: dangerous write permissions\n",
11553037Seric 				FileName);
11653037Seric #ifdef LOG
11753037Seric 		if (LogLevel > 0)
11853037Seric 			syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions",
11953037Seric 				FileName);
12053037Seric #endif
12152647Seric 	}
12252647Seric 
12359254Seric #ifdef XLA
12459254Seric 	xla_zero();
12559254Seric #endif
12659254Seric 
12757135Seric 	while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL)
1283308Seric 	{
12957135Seric 		if (bp[0] == '#')
13057135Seric 		{
13157135Seric 			if (bp != buf)
13257135Seric 				free(bp);
13352637Seric 			continue;
13457135Seric 		}
13552637Seric 
13658050Seric 		/* map $ into \201 for macro expansion */
13757135Seric 		for (p = bp; *p != '\0'; p++)
13816157Seric 		{
13957135Seric 			if (*p == '#' && p > bp && ConfigLevel >= 3)
14052647Seric 			{
14152647Seric 				/* this is an on-line comment */
14252647Seric 				register char *e;
14352647Seric 
14458050Seric 				switch (*--p & 0377)
14552647Seric 				{
14658050Seric 				  case MACROEXPAND:
14752647Seric 					/* it's from $# -- let it go through */
14852647Seric 					p++;
14952647Seric 					break;
15052647Seric 
15152647Seric 				  case '\\':
15252647Seric 					/* it's backslash escaped */
15352647Seric 					(void) strcpy(p, p + 1);
15452647Seric 					break;
15552647Seric 
15652647Seric 				  default:
15752647Seric 					/* delete preceeding white space */
15858050Seric 					while (isascii(*p) && isspace(*p) && p > bp)
15952647Seric 						p--;
16056795Seric 					if ((e = strchr(++p, '\n')) != NULL)
16152647Seric 						(void) strcpy(p, e);
16252647Seric 					else
16352647Seric 						p[0] = p[1] = '\0';
16452647Seric 					break;
16552647Seric 				}
16652647Seric 				continue;
16752647Seric 			}
16852647Seric 
16916157Seric 			if (*p != '$')
17016157Seric 				continue;
17116157Seric 
17216157Seric 			if (p[1] == '$')
17316157Seric 			{
17416157Seric 				/* actual dollar sign.... */
17523111Seric 				(void) strcpy(p, p + 1);
17616157Seric 				continue;
17716157Seric 			}
17816157Seric 
17916157Seric 			/* convert to macro expansion character */
18058050Seric 			*p = MACROEXPAND;
18116157Seric 		}
18216157Seric 
18316157Seric 		/* interpret this line */
18464718Seric 		errno = 0;
18557135Seric 		switch (bp[0])
1863308Seric 		{
1873308Seric 		  case '\0':
1883308Seric 		  case '#':		/* comment */
1893308Seric 			break;
1903308Seric 
1913308Seric 		  case 'R':		/* rewriting rule */
19257135Seric 			for (p = &bp[1]; *p != '\0' && *p != '\t'; p++)
1933308Seric 				continue;
1943308Seric 
1953308Seric 			if (*p == '\0')
1965909Seric 			{
19765821Seric 				syserr("invalid rewrite line \"%s\" (tab expected)", bp);
1985909Seric 				break;
1995909Seric 			}
2005909Seric 
2015909Seric 			/* allocate space for the rule header */
2025909Seric 			if (rwp == NULL)
2035909Seric 			{
2045909Seric 				RewriteRules[ruleset] = rwp =
2055909Seric 					(struct rewrite *) xalloc(sizeof *rwp);
2065909Seric 			}
2073308Seric 			else
2083308Seric 			{
2095909Seric 				rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
2105909Seric 				rwp = rwp->r_next;
2115909Seric 			}
2125909Seric 			rwp->r_next = NULL;
2133308Seric 
2145909Seric 			/* expand and save the LHS */
2155909Seric 			*p = '\0';
21657135Seric 			expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e);
21765066Seric 			rwp->r_lhs = prescan(exbuf, '\t', pvpbuf,
21865066Seric 					     sizeof pvpbuf, NULL);
21957589Seric 			nfuzzy = 0;
2205909Seric 			if (rwp->r_lhs != NULL)
22157589Seric 			{
22257589Seric 				register char **ap;
22357589Seric 
2245909Seric 				rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
22557589Seric 
22657589Seric 				/* count the number of fuzzy matches in LHS */
22757589Seric 				for (ap = rwp->r_lhs; *ap != NULL; ap++)
22857589Seric 				{
22958148Seric 					char *botch;
23058148Seric 
23158148Seric 					botch = NULL;
23258050Seric 					switch (**ap & 0377)
23357589Seric 					{
23457589Seric 					  case MATCHZANY:
23557589Seric 					  case MATCHANY:
23657589Seric 					  case MATCHONE:
23757589Seric 					  case MATCHCLASS:
23857589Seric 					  case MATCHNCLASS:
23957589Seric 						nfuzzy++;
24058148Seric 						break;
24158148Seric 
24258148Seric 					  case MATCHREPL:
24358148Seric 						botch = "$0-$9";
24458148Seric 						break;
24558148Seric 
24658148Seric 					  case CANONNET:
24758148Seric 						botch = "$#";
24858148Seric 						break;
24958148Seric 
25058148Seric 					  case CANONUSER:
25158148Seric 						botch = "$:";
25258148Seric 						break;
25358148Seric 
25458148Seric 					  case CALLSUBR:
25558148Seric 						botch = "$>";
25658148Seric 						break;
25758148Seric 
25858148Seric 					  case CONDIF:
25958148Seric 						botch = "$?";
26058148Seric 						break;
26158148Seric 
26258148Seric 					  case CONDELSE:
26358148Seric 						botch = "$|";
26458148Seric 						break;
26558148Seric 
26658148Seric 					  case CONDFI:
26758148Seric 						botch = "$.";
26858148Seric 						break;
26958148Seric 
27058148Seric 					  case HOSTBEGIN:
27158148Seric 						botch = "$[";
27258148Seric 						break;
27358148Seric 
27458148Seric 					  case HOSTEND:
27558148Seric 						botch = "$]";
27658148Seric 						break;
27758148Seric 
27858148Seric 					  case LOOKUPBEGIN:
27958148Seric 						botch = "$(";
28058148Seric 						break;
28158148Seric 
28258148Seric 					  case LOOKUPEND:
28358148Seric 						botch = "$)";
28458148Seric 						break;
28557589Seric 					}
28658148Seric 					if (botch != NULL)
28758148Seric 						syserr("Inappropriate use of %s on LHS",
28858148Seric 							botch);
28957589Seric 				}
29057589Seric 			}
29156678Seric 			else
29256678Seric 				syserr("R line: null LHS");
2935909Seric 
2945909Seric 			/* expand and save the RHS */
2955909Seric 			while (*++p == '\t')
2965909Seric 				continue;
2977231Seric 			q = p;
2987231Seric 			while (*p != '\0' && *p != '\t')
2997231Seric 				p++;
3007231Seric 			*p = '\0';
30155012Seric 			expand(q, exbuf, &exbuf[sizeof exbuf], e);
30265066Seric 			rwp->r_rhs = prescan(exbuf, '\t', pvpbuf,
30365066Seric 					     sizeof pvpbuf, NULL);
3045909Seric 			if (rwp->r_rhs != NULL)
30557589Seric 			{
30657589Seric 				register char **ap;
30757589Seric 
3085909Seric 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
30957589Seric 
31057589Seric 				/* check no out-of-bounds replacements */
31157589Seric 				nfuzzy += '0';
31257589Seric 				for (ap = rwp->r_rhs; *ap != NULL; ap++)
31357589Seric 				{
31458148Seric 					char *botch;
31558148Seric 
31658148Seric 					botch = NULL;
31758148Seric 					switch (**ap & 0377)
31857589Seric 					{
31958148Seric 					  case MATCHREPL:
32058148Seric 						if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy)
32158148Seric 						{
32258148Seric 							syserr("replacement $%c out of bounds",
32358148Seric 								(*ap)[1]);
32458148Seric 						}
32558148Seric 						break;
32658148Seric 
32758148Seric 					  case MATCHZANY:
32858148Seric 						botch = "$*";
32958148Seric 						break;
33058148Seric 
33158148Seric 					  case MATCHANY:
33258148Seric 						botch = "$+";
33358148Seric 						break;
33458148Seric 
33558148Seric 					  case MATCHONE:
33658148Seric 						botch = "$-";
33758148Seric 						break;
33858148Seric 
33958148Seric 					  case MATCHCLASS:
34058148Seric 						botch = "$=";
34158148Seric 						break;
34258148Seric 
34358148Seric 					  case MATCHNCLASS:
34458148Seric 						botch = "$~";
34558148Seric 						break;
34657589Seric 					}
34758148Seric 					if (botch != NULL)
34858148Seric 						syserr("Inappropriate use of %s on RHS",
34958148Seric 							botch);
35057589Seric 				}
35157589Seric 			}
35256678Seric 			else
35356678Seric 				syserr("R line: null RHS");
3543308Seric 			break;
3553308Seric 
3564072Seric 		  case 'S':		/* select rewriting set */
35764440Seric 			for (p = &bp[1]; isascii(*p) && isspace(*p); p++)
35864440Seric 				continue;
35964440Seric 			if (!isascii(*p) || !isdigit(*p))
36064440Seric 			{
36164440Seric 				syserr("invalid argument to S line: \"%.20s\"",
36264440Seric 					&bp[1]);
36364440Seric 				break;
36464440Seric 			}
36564440Seric 			ruleset = atoi(p);
3668056Seric 			if (ruleset >= MAXRWSETS || ruleset < 0)
3678056Seric 			{
3689381Seric 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
3698056Seric 				ruleset = 0;
3708056Seric 			}
3714072Seric 			rwp = NULL;
3724072Seric 			break;
3734072Seric 
3743308Seric 		  case 'D':		/* macro definition */
37564086Seric 			p = munchstring(&bp[2], NULL);
37664086Seric 			define(bp[1], newstr(p), e);
3773308Seric 			break;
3783308Seric 
3793387Seric 		  case 'H':		/* required header line */
38057135Seric 			(void) chompheader(&bp[1], TRUE, e);
3813387Seric 			break;
3823387Seric 
3834061Seric 		  case 'C':		/* word class */
3844432Seric 			/* scan the list of words and set class for all */
38564121Seric 			expand(&bp[2], exbuf, &exbuf[sizeof exbuf], e);
38664121Seric 			for (p = exbuf; *p != '\0'; )
3874061Seric 			{
3884061Seric 				register char *wd;
3894061Seric 				char delim;
3904061Seric 
39158050Seric 				while (*p != '\0' && isascii(*p) && isspace(*p))
3924061Seric 					p++;
3934061Seric 				wd = p;
39458050Seric 				while (*p != '\0' && !(isascii(*p) && isspace(*p)))
3954061Seric 					p++;
3964061Seric 				delim = *p;
3974061Seric 				*p = '\0';
3984061Seric 				if (wd[0] != '\0')
39957135Seric 					setclass(bp[1], wd);
4004061Seric 				*p = delim;
4014061Seric 			}
4024061Seric 			break;
4034061Seric 
40459272Seric 		  case 'F':		/* word class from file */
40564133Seric 			for (p = &bp[2]; isascii(*p) && isspace(*p); )
40664133Seric 				p++;
40764133Seric 			if (p[0] == '-' && p[1] == 'o')
40864133Seric 			{
40964133Seric 				optional = TRUE;
41064133Seric 				while (*p != '\0' && !(isascii(*p) && isspace(*p)))
41164133Seric 					p++;
41264133Seric 				while (isascii(*p) && isspace(*p))
41364133Seric 					*p++;
41464133Seric 			}
41564133Seric 			else
41664133Seric 				optional = FALSE;
41764133Seric 			file = p;
41864133Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
41964133Seric 				p++;
42059272Seric 			if (*p == '\0')
42159272Seric 				p = "%s";
42259272Seric 			else
42359272Seric 			{
42459272Seric 				*p = '\0';
42559272Seric 				while (isascii(*++p) && isspace(*p))
42659272Seric 					continue;
42759272Seric 			}
42864133Seric 			fileclass(bp[1], file, p, safe, optional);
42959272Seric 			break;
43059272Seric 
43159156Seric #ifdef XLA
43259156Seric 		  case 'L':		/* extended load average description */
43359156Seric 			xla_init(&bp[1]);
43459156Seric 			break;
43559156Seric #endif
43659156Seric 
4374096Seric 		  case 'M':		/* define mailer */
43857135Seric 			makemailer(&bp[1]);
4394096Seric 			break;
4404096Seric 
4418252Seric 		  case 'O':		/* set option */
44258734Seric 			setoption(bp[1], &bp[2], safe, FALSE, e);
4438252Seric 			break;
4448252Seric 
4458252Seric 		  case 'P':		/* set precedence */
4468252Seric 			if (NumPriorities >= MAXPRIORITIES)
4478252Seric 			{
4488547Seric 				toomany('P', MAXPRIORITIES);
4498252Seric 				break;
4508252Seric 			}
45157135Seric 			for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
4528252Seric 				continue;
4538252Seric 			if (*p == '\0')
4548252Seric 				goto badline;
4558252Seric 			*p = '\0';
45657135Seric 			Priorities[NumPriorities].pri_name = newstr(&bp[1]);
4578252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
4588252Seric 			NumPriorities++;
4598252Seric 			break;
4608252Seric 
4618547Seric 		  case 'T':		/* trusted user(s) */
46258161Seric 			/* this option is obsolete, but will be ignored */
4638547Seric 			break;
4648547Seric 
46552645Seric 		  case 'V':		/* configuration syntax version */
46664440Seric 			for (p = &bp[1]; isascii(*p) && isspace(*p); p++)
46764440Seric 				continue;
46864440Seric 			if (!isascii(*p) || !isdigit(*p))
46964440Seric 			{
47064440Seric 				syserr("invalid argument to V line: \"%.20s\"",
47164440Seric 					&bp[1]);
47264440Seric 				break;
47364440Seric 			}
47464718Seric 			ConfigLevel = strtol(p, &ep, 10);
47564279Seric 			if (ConfigLevel >= 5)
47664279Seric 			{
47764279Seric 				/* level 5 configs have short name in $w */
47864279Seric 				p = macvalue('w', e);
47964279Seric 				if (p != NULL && (p = strchr(p, '.')) != NULL)
48064279Seric 					*p = '\0';
48164279Seric 			}
48264718Seric 			if (*ep++ == '/')
48364718Seric 			{
48464718Seric 				/* extract vendor code */
48564718Seric 				for (p = ep; isascii(*p) && isalpha(*p); )
48664718Seric 					p++;
48764718Seric 				*p = '\0';
48864718Seric 
48964718Seric 				if (!setvendor(ep))
49064718Seric 					syserr("invalid V line vendor code: \"%s\"",
49164718Seric 						ep);
49264718Seric 			}
49352645Seric 			break;
49452645Seric 
49553654Seric 		  case 'K':
49657135Seric 			makemapentry(&bp[1]);
49753654Seric 			break;
49853654Seric 
4993308Seric 		  default:
5004061Seric 		  badline:
50157135Seric 			syserr("unknown control line \"%s\"", bp);
5023308Seric 		}
50357135Seric 		if (bp != buf)
50457135Seric 			free(bp);
5053308Seric 	}
50652637Seric 	if (ferror(cf))
50752637Seric 	{
50852647Seric 		syserr("I/O read error", cfname);
50952637Seric 		exit(EX_OSFILE);
51052637Seric 	}
51152637Seric 	fclose(cf);
5129381Seric 	FileName = NULL;
51356836Seric 
51457076Seric 	if (stab("host", ST_MAP, ST_FIND) == NULL)
51557076Seric 	{
51657076Seric 		/* user didn't initialize: set up host map */
51757076Seric 		strcpy(buf, "host host");
51866334Seric #if NAMED_BIND
51957076Seric 		if (ConfigLevel >= 2)
52057076Seric 			strcat(buf, " -a.");
52164947Seric #endif
52257076Seric 		makemapentry(buf);
52357076Seric 	}
5244096Seric }
5254096Seric /*
5268547Seric **  TOOMANY -- signal too many of some option
5278547Seric **
5288547Seric **	Parameters:
5298547Seric **		id -- the id of the error line
5308547Seric **		maxcnt -- the maximum possible values
5318547Seric **
5328547Seric **	Returns:
5338547Seric **		none.
5348547Seric **
5358547Seric **	Side Effects:
5368547Seric **		gives a syserr.
5378547Seric */
5388547Seric 
5398547Seric toomany(id, maxcnt)
5408547Seric 	char id;
5418547Seric 	int maxcnt;
5428547Seric {
5439381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
5448547Seric }
5458547Seric /*
5464432Seric **  FILECLASS -- read members of a class from a file
5474432Seric **
5484432Seric **	Parameters:
5494432Seric **		class -- class to define.
5504432Seric **		filename -- name of file to read.
5514432Seric **		fmt -- scanf string to use for match.
55264133Seric **		safe -- if set, this is a safe read.
55364133Seric **		optional -- if set, it is not an error for the file to
55464133Seric **			not exist.
5554432Seric **
5564432Seric **	Returns:
5574432Seric **		none
5584432Seric **
5594432Seric **	Side Effects:
5604432Seric **
5614432Seric **		puts all lines in filename that match a scanf into
5624432Seric **			the named class.
5634432Seric */
5644432Seric 
56564133Seric fileclass(class, filename, fmt, safe, optional)
5664432Seric 	int class;
5674432Seric 	char *filename;
5684432Seric 	char *fmt;
56954973Seric 	bool safe;
57064133Seric 	bool optional;
5714432Seric {
57225808Seric 	FILE *f;
57354973Seric 	struct stat stbuf;
5744432Seric 	char buf[MAXLINE];
5754432Seric 
57666101Seric 	if (tTd(37, 2))
57766101Seric 		printf("fileclass(%s, fmt=%s)\n", filename, fmt);
57866101Seric 
57966031Seric 	if (filename[0] == '|')
58066031Seric 	{
58166031Seric 		syserr("fileclass: pipes (F%c%s) not supported due to security problems",
58266031Seric 			class, filename);
58366031Seric 		return;
58466031Seric 	}
58554973Seric 	if (stat(filename, &stbuf) < 0)
58654973Seric 	{
58766101Seric 		if (tTd(37, 2))
58866101Seric 			printf("  cannot stat (%s)\n", errstring(errno));
58964133Seric 		if (!optional)
59064133Seric 			syserr("fileclass: cannot stat %s", filename);
59154973Seric 		return;
59254973Seric 	}
59354973Seric 	if (!S_ISREG(stbuf.st_mode))
59454973Seric 	{
59554973Seric 		syserr("fileclass: %s not a regular file", filename);
59654973Seric 		return;
59754973Seric 	}
59854973Seric 	if (!safe && access(filename, R_OK) < 0)
59954973Seric 	{
60054973Seric 		syserr("fileclass: access denied on %s", filename);
60154973Seric 		return;
60254973Seric 	}
60354973Seric 	f = fopen(filename, "r");
6044432Seric 	if (f == NULL)
6054432Seric 	{
60654973Seric 		syserr("fileclass: cannot open %s", filename);
6074432Seric 		return;
6084432Seric 	}
6094432Seric 
6104432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
6114432Seric 	{
6124432Seric 		register STAB *s;
61325808Seric 		register char *p;
61425808Seric # ifdef SCANF
6154432Seric 		char wordbuf[MAXNAME+1];
6164432Seric 
6174432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
6184432Seric 			continue;
61925808Seric 		p = wordbuf;
62056795Seric # else /* SCANF */
62125808Seric 		p = buf;
62256795Seric # endif /* SCANF */
62325808Seric 
62425808Seric 		/*
62525808Seric 		**  Break up the match into words.
62625808Seric 		*/
62725808Seric 
62825808Seric 		while (*p != '\0')
62925808Seric 		{
63025808Seric 			register char *q;
63125808Seric 
63225808Seric 			/* strip leading spaces */
63358050Seric 			while (isascii(*p) && isspace(*p))
63425808Seric 				p++;
63525808Seric 			if (*p == '\0')
63625808Seric 				break;
63725808Seric 
63825808Seric 			/* find the end of the word */
63925808Seric 			q = p;
64058050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
64125808Seric 				p++;
64225808Seric 			if (*p != '\0')
64325808Seric 				*p++ = '\0';
64425808Seric 
64525808Seric 			/* enter the word in the symbol table */
64666101Seric 			setclass(class, q);
64725808Seric 		}
6484432Seric 	}
6494432Seric 
65054973Seric 	(void) fclose(f);
6514432Seric }
6524432Seric /*
6534096Seric **  MAKEMAILER -- define a new mailer.
6544096Seric **
6554096Seric **	Parameters:
65610327Seric **		line -- description of mailer.  This is in labeled
65710327Seric **			fields.  The fields are:
65810327Seric **			   P -- the path to the mailer
65910327Seric **			   F -- the flags associated with the mailer
66010327Seric **			   A -- the argv for this mailer
66110327Seric **			   S -- the sender rewriting set
66210327Seric **			   R -- the recipient rewriting set
66310327Seric **			   E -- the eol string
66410327Seric **			The first word is the canonical name of the mailer.
6654096Seric **
6664096Seric **	Returns:
6674096Seric **		none.
6684096Seric **
6694096Seric **	Side Effects:
6704096Seric **		enters the mailer into the mailer table.
6714096Seric */
6723308Seric 
67321066Seric makemailer(line)
6744096Seric 	char *line;
6754096Seric {
6764096Seric 	register char *p;
6778067Seric 	register struct mailer *m;
6788067Seric 	register STAB *s;
6798067Seric 	int i;
68010327Seric 	char fcode;
68158020Seric 	auto char *endp;
6824096Seric 	extern int NextMailer;
68310327Seric 	extern char **makeargv();
68410327Seric 	extern char *munchstring();
68510701Seric 	extern long atol();
6864096Seric 
68710327Seric 	/* allocate a mailer and set up defaults */
68810327Seric 	m = (struct mailer *) xalloc(sizeof *m);
68910327Seric 	bzero((char *) m, sizeof *m);
69010327Seric 	m->m_eol = "\n";
69110327Seric 
69210327Seric 	/* collect the mailer name */
69358050Seric 	for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++)
69410327Seric 		continue;
69510327Seric 	if (*p != '\0')
69610327Seric 		*p++ = '\0';
69710327Seric 	m->m_name = newstr(line);
69810327Seric 
69910327Seric 	/* now scan through and assign info from the fields */
70010327Seric 	while (*p != '\0')
70110327Seric 	{
70258333Seric 		auto char *delimptr;
70358333Seric 
70458050Seric 		while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p))))
70510327Seric 			p++;
70610327Seric 
70710327Seric 		/* p now points to field code */
70810327Seric 		fcode = *p;
70910327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
71010327Seric 			p++;
71110327Seric 		if (*p++ != '=')
71210327Seric 		{
71352637Seric 			syserr("mailer %s: `=' expected", m->m_name);
71410327Seric 			return;
71510327Seric 		}
71658050Seric 		while (isascii(*p) && isspace(*p))
71710327Seric 			p++;
71810327Seric 
71910327Seric 		/* p now points to the field body */
72058333Seric 		p = munchstring(p, &delimptr);
72110327Seric 
72210327Seric 		/* install the field into the mailer struct */
72310327Seric 		switch (fcode)
72410327Seric 		{
72510327Seric 		  case 'P':		/* pathname */
72610327Seric 			m->m_mailer = newstr(p);
72710327Seric 			break;
72810327Seric 
72910327Seric 		  case 'F':		/* flags */
73010687Seric 			for (; *p != '\0'; p++)
73158050Seric 				if (!(isascii(*p) && isspace(*p)))
73252637Seric 					setbitn(*p, m->m_flags);
73310327Seric 			break;
73410327Seric 
73510327Seric 		  case 'S':		/* sender rewriting ruleset */
73610327Seric 		  case 'R':		/* recipient rewriting ruleset */
73758020Seric 			i = strtol(p, &endp, 10);
73810327Seric 			if (i < 0 || i >= MAXRWSETS)
73910327Seric 			{
74010327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
74110327Seric 				return;
74210327Seric 			}
74310327Seric 			if (fcode == 'S')
74458020Seric 				m->m_sh_rwset = m->m_se_rwset = i;
74510327Seric 			else
74658020Seric 				m->m_rh_rwset = m->m_re_rwset = i;
74758020Seric 
74858020Seric 			p = endp;
74959985Seric 			if (*p++ == '/')
75058020Seric 			{
75158020Seric 				i = strtol(p, NULL, 10);
75258020Seric 				if (i < 0 || i >= MAXRWSETS)
75358020Seric 				{
75458020Seric 					syserr("invalid rewrite set, %d max",
75558020Seric 						MAXRWSETS);
75658020Seric 					return;
75758020Seric 				}
75858020Seric 				if (fcode == 'S')
75958020Seric 					m->m_sh_rwset = i;
76058020Seric 				else
76158020Seric 					m->m_rh_rwset = i;
76258020Seric 			}
76310327Seric 			break;
76410327Seric 
76510327Seric 		  case 'E':		/* end of line string */
76610327Seric 			m->m_eol = newstr(p);
76710327Seric 			break;
76810327Seric 
76910327Seric 		  case 'A':		/* argument vector */
77010327Seric 			m->m_argv = makeargv(p);
77110327Seric 			break;
77210701Seric 
77310701Seric 		  case 'M':		/* maximum message size */
77410701Seric 			m->m_maxsize = atol(p);
77510701Seric 			break;
77652106Seric 
77752106Seric 		  case 'L':		/* maximum line length */
77852106Seric 			m->m_linelimit = atoi(p);
77952106Seric 			break;
78058935Seric 
78158935Seric 		  case 'D':		/* working directory */
78258935Seric 			m->m_execdir = newstr(p);
78358935Seric 			break;
78410327Seric 		}
78510327Seric 
78658333Seric 		p = delimptr;
78710327Seric 	}
78810327Seric 
78952106Seric 	/* do some heuristic cleanup for back compatibility */
79052106Seric 	if (bitnset(M_LIMITS, m->m_flags))
79152106Seric 	{
79252106Seric 		if (m->m_linelimit == 0)
79352106Seric 			m->m_linelimit = SMTPLINELIM;
79455418Seric 		if (ConfigLevel < 2)
79552106Seric 			setbitn(M_7BITS, m->m_flags);
79652106Seric 	}
79752106Seric 
79858321Seric 	/* do some rationality checking */
79958321Seric 	if (m->m_argv == NULL)
80058321Seric 	{
80158321Seric 		syserr("M%s: A= argument required", m->m_name);
80258321Seric 		return;
80358321Seric 	}
80458321Seric 	if (m->m_mailer == NULL)
80558321Seric 	{
80658321Seric 		syserr("M%s: P= argument required", m->m_name);
80758321Seric 		return;
80858321Seric 	}
80958321Seric 
8104096Seric 	if (NextMailer >= MAXMAILERS)
8114096Seric 	{
8129381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
8134096Seric 		return;
8144096Seric 	}
81557402Seric 
81610327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
81757402Seric 	if (s->s_mailer != NULL)
81857402Seric 	{
81957402Seric 		i = s->s_mailer->m_mno;
82057402Seric 		free(s->s_mailer);
82157402Seric 	}
82257402Seric 	else
82357402Seric 	{
82457402Seric 		i = NextMailer++;
82557402Seric 	}
82657402Seric 	Mailer[i] = s->s_mailer = m;
82757454Seric 	m->m_mno = i;
82810327Seric }
82910327Seric /*
83010327Seric **  MUNCHSTRING -- translate a string into internal form.
83110327Seric **
83210327Seric **	Parameters:
83310327Seric **		p -- the string to munch.
83458333Seric **		delimptr -- if non-NULL, set to the pointer of the
83558333Seric **			field delimiter character.
83610327Seric **
83710327Seric **	Returns:
83810327Seric **		the munched string.
83910327Seric */
8404096Seric 
84110327Seric char *
84258333Seric munchstring(p, delimptr)
84310327Seric 	register char *p;
84458333Seric 	char **delimptr;
84510327Seric {
84610327Seric 	register char *q;
84710327Seric 	bool backslash = FALSE;
84810327Seric 	bool quotemode = FALSE;
84910327Seric 	static char buf[MAXLINE];
8504096Seric 
85110327Seric 	for (q = buf; *p != '\0'; p++)
8524096Seric 	{
85310327Seric 		if (backslash)
85410327Seric 		{
85510327Seric 			/* everything is roughly literal */
85610357Seric 			backslash = FALSE;
85710327Seric 			switch (*p)
85810327Seric 			{
85910327Seric 			  case 'r':		/* carriage return */
86010327Seric 				*q++ = '\r';
86110327Seric 				continue;
86210327Seric 
86310327Seric 			  case 'n':		/* newline */
86410327Seric 				*q++ = '\n';
86510327Seric 				continue;
86610327Seric 
86710327Seric 			  case 'f':		/* form feed */
86810327Seric 				*q++ = '\f';
86910327Seric 				continue;
87010327Seric 
87110327Seric 			  case 'b':		/* backspace */
87210327Seric 				*q++ = '\b';
87310327Seric 				continue;
87410327Seric 			}
87510327Seric 			*q++ = *p;
87610327Seric 		}
87710327Seric 		else
87810327Seric 		{
87910327Seric 			if (*p == '\\')
88010327Seric 				backslash = TRUE;
88110327Seric 			else if (*p == '"')
88210327Seric 				quotemode = !quotemode;
88310327Seric 			else if (quotemode || *p != ',')
88410327Seric 				*q++ = *p;
88510327Seric 			else
88610327Seric 				break;
88710327Seric 		}
8884096Seric 	}
8894096Seric 
89058333Seric 	if (delimptr != NULL)
89158333Seric 		*delimptr = p;
89210327Seric 	*q++ = '\0';
89310327Seric 	return (buf);
89410327Seric }
89510327Seric /*
89610327Seric **  MAKEARGV -- break up a string into words
89710327Seric **
89810327Seric **	Parameters:
89910327Seric **		p -- the string to break up.
90010327Seric **
90110327Seric **	Returns:
90210327Seric **		a char **argv (dynamically allocated)
90310327Seric **
90410327Seric **	Side Effects:
90510327Seric **		munges p.
90610327Seric */
9074096Seric 
90810327Seric char **
90910327Seric makeargv(p)
91010327Seric 	register char *p;
91110327Seric {
91210327Seric 	char *q;
91310327Seric 	int i;
91410327Seric 	char **avp;
91510327Seric 	char *argv[MAXPV + 1];
91610327Seric 
91710327Seric 	/* take apart the words */
91810327Seric 	i = 0;
91910327Seric 	while (*p != '\0' && i < MAXPV)
9204096Seric 	{
92110327Seric 		q = p;
92258050Seric 		while (*p != '\0' && !(isascii(*p) && isspace(*p)))
92310327Seric 			p++;
92458050Seric 		while (isascii(*p) && isspace(*p))
92510327Seric 			*p++ = '\0';
92610327Seric 		argv[i++] = newstr(q);
9274096Seric 	}
92810327Seric 	argv[i++] = NULL;
9294096Seric 
93010327Seric 	/* now make a copy of the argv */
93110327Seric 	avp = (char **) xalloc(sizeof *avp * i);
93216893Seric 	bcopy((char *) argv, (char *) avp, sizeof *avp * i);
93310327Seric 
93410327Seric 	return (avp);
9353308Seric }
9363308Seric /*
9373308Seric **  PRINTRULES -- print rewrite rules (for debugging)
9383308Seric **
9393308Seric **	Parameters:
9403308Seric **		none.
9413308Seric **
9423308Seric **	Returns:
9433308Seric **		none.
9443308Seric **
9453308Seric **	Side Effects:
9463308Seric **		prints rewrite rules.
9473308Seric */
9483308Seric 
9493308Seric printrules()
9503308Seric {
9513308Seric 	register struct rewrite *rwp;
9524072Seric 	register int ruleset;
9533308Seric 
9544072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
9553308Seric 	{
9564072Seric 		if (RewriteRules[ruleset] == NULL)
9574072Seric 			continue;
9588067Seric 		printf("\n----Rule Set %d:", ruleset);
9593308Seric 
9604072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
9613308Seric 		{
9628067Seric 			printf("\nLHS:");
9638067Seric 			printav(rwp->r_lhs);
9648067Seric 			printf("RHS:");
9658067Seric 			printav(rwp->r_rhs);
9663308Seric 		}
9673308Seric 	}
9683308Seric }
9694319Seric 
9704096Seric /*
9718256Seric **  SETOPTION -- set global processing option
9728256Seric **
9738256Seric **	Parameters:
9748256Seric **		opt -- option name.
9758256Seric **		val -- option value (as a text string).
97621755Seric **		safe -- set if this came from a configuration file.
97721755Seric **			Some options (if set from the command line) will
97821755Seric **			reset the user id to avoid security problems.
9798269Seric **		sticky -- if set, don't let other setoptions override
9808269Seric **			this value.
98158734Seric **		e -- the main envelope.
9828256Seric **
9838256Seric **	Returns:
9848256Seric **		none.
9858256Seric **
9868256Seric **	Side Effects:
9878256Seric **		Sets options as implied by the arguments.
9888256Seric */
9898256Seric 
99010687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
9918269Seric 
99257207Seric 
99366334Seric #if NAMED_BIND
99457207Seric 
99557207Seric struct resolverflags
99657207Seric {
99757207Seric 	char	*rf_name;	/* name of the flag */
99857207Seric 	long	rf_bits;	/* bits to set/clear */
99957207Seric } ResolverFlags[] =
100057207Seric {
100157207Seric 	"debug",	RES_DEBUG,
100257207Seric 	"aaonly",	RES_AAONLY,
100357207Seric 	"usevc",	RES_USEVC,
100457207Seric 	"primary",	RES_PRIMARY,
100557207Seric 	"igntc",	RES_IGNTC,
100657207Seric 	"recurse",	RES_RECURSE,
100757207Seric 	"defnames",	RES_DEFNAMES,
100857207Seric 	"stayopen",	RES_STAYOPEN,
100957207Seric 	"dnsrch",	RES_DNSRCH,
101065583Seric 	"true",		0,		/* to avoid error on old syntax */
101157207Seric 	NULL,		0
101257207Seric };
101357207Seric 
101457207Seric #endif
101557207Seric 
101658734Seric setoption(opt, val, safe, sticky, e)
10178256Seric 	char opt;
10188256Seric 	char *val;
101921755Seric 	bool safe;
10208269Seric 	bool sticky;
102158734Seric 	register ENVELOPE *e;
10228256Seric {
102357207Seric 	register char *p;
10248265Seric 	extern bool atobool();
102512633Seric 	extern time_t convtime();
102614879Seric 	extern int QueueLA;
102714879Seric 	extern int RefuseLA;
102864718Seric 	extern bool Warn_Q_option;
102917474Seric 	extern bool trusteduser();
10308256Seric 
10318256Seric 	if (tTd(37, 1))
10329341Seric 		printf("setoption %c=%s", opt, val);
10338256Seric 
10348256Seric 	/*
10358269Seric 	**  See if this option is preset for us.
10368256Seric 	*/
10378256Seric 
103859731Seric 	if (!sticky && bitnset(opt, StickyOpt))
10398269Seric 	{
10409341Seric 		if (tTd(37, 1))
10419341Seric 			printf(" (ignored)\n");
10428269Seric 		return;
10438269Seric 	}
10448269Seric 
104521755Seric 	/*
104621755Seric 	**  Check to see if this option can be specified by this user.
104721755Seric 	*/
104821755Seric 
104963787Seric 	if (!safe && RealUid == 0)
105021755Seric 		safe = TRUE;
105166383Scorrigan 	if (!safe && strchr("bCdeijLmoprsvw7", opt) == NULL)
105221755Seric 	{
105339111Srick 		if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
105421755Seric 		{
105536582Sbostic 			if (tTd(37, 1))
105636582Sbostic 				printf(" (unsafe)");
105763787Seric 			if (RealUid != geteuid())
105836582Sbostic 			{
105951210Seric 				if (tTd(37, 1))
106051210Seric 					printf("(Resetting uid)");
106163787Seric 				(void) setgid(RealGid);
106263787Seric 				(void) setuid(RealUid);
106336582Sbostic 			}
106421755Seric 		}
106521755Seric 	}
106651210Seric 	if (tTd(37, 1))
106717985Seric 		printf("\n");
10688269Seric 
10698256Seric 	switch (opt)
10708256Seric 	{
107159709Seric 	  case '7':		/* force seven-bit input */
107267546Seric 		SevenBitInput = atobool(val);
107352106Seric 		break;
107452106Seric 
107567546Seric 	  case '8':		/* handling of 8-bit input */
107667546Seric 		switch (*val)
107767546Seric 		{
1078*67547Seric 		  case 'r':		/* reject 8-bit, don't convert MIME */
107967546Seric 			MimeMode = 0;
108067546Seric 			break;
108167546Seric 
1082*67547Seric 		  case 'm':		/* convert 8-bit, convert MIME */
108367546Seric 			MimeMode = MM_CVTMIME|MM_MIME8BIT;
108467546Seric 			break;
108567546Seric 
1086*67547Seric 		  case 'j':		/* "just send 8" */
108767546Seric 			MimeMode = MM_PASS8BIT;
108867546Seric 			break;
108967546Seric 
109067546Seric 		  case 'p':		/* pass 8 bit, convert MIME */
109167546Seric 			MimeMode = MM_PASS8BIT|MM_CVTMIME;
109267546Seric 			break;
109367546Seric 
109467546Seric 		  case 's':		/* strict adherence */
109567546Seric 			MimeMode = MM_CVTMIME;
109667546Seric 			break;
109767546Seric 
1098*67547Seric 		  case 'a':		/* encode 8 bit if available */
109967546Seric 			MimeMode = MM_MIME8BIT|MM_PASS8BIT|MM_CVTMIME;
110067546Seric 			break;
110167546Seric 
1102*67547Seric 		  case 'c':		/* convert 8 bit to MIME, never 7 bit */
1103*67547Seric 			MimeMode = MM_MIME8BIT;
1104*67547Seric 			break;
1105*67547Seric 
110667546Seric 		  default:
110767546Seric 			syserr("Unknown 8-bit mode %c", *val);
110867546Seric 			exit(EX_USAGE);
110967546Seric 		}
111067546Seric 		break;
111167546Seric 
11128256Seric 	  case 'A':		/* set default alias file */
11139381Seric 		if (val[0] == '\0')
111459672Seric 			setalias("aliases");
11159381Seric 		else
111659672Seric 			setalias(val);
11178256Seric 		break;
11188256Seric 
111917474Seric 	  case 'a':		/* look N minutes for "@:@" in alias file */
112017474Seric 		if (val[0] == '\0')
112164796Seric 			SafeAlias = 5 * 60;		/* five minutes */
112217474Seric 		else
112364796Seric 			SafeAlias = convtime(val, 'm');
112417474Seric 		break;
112517474Seric 
112616843Seric 	  case 'B':		/* substitution for blank character */
112716843Seric 		SpaceSub = val[0];
112816843Seric 		if (SpaceSub == '\0')
112916843Seric 			SpaceSub = ' ';
113016843Seric 		break;
113116843Seric 
113259283Seric 	  case 'b':		/* min blocks free on queue fs/max msg size */
113359283Seric 		p = strchr(val, '/');
113459283Seric 		if (p != NULL)
113559283Seric 		{
113659283Seric 			*p++ = '\0';
113759283Seric 			MaxMessageSize = atol(p);
113859283Seric 		}
113958082Seric 		MinBlocksFree = atol(val);
114058082Seric 		break;
114158082Seric 
11429284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
11439381Seric 		NoConnect = atobool(val);
11449284Seric 		break;
11459284Seric 
114651305Seric 	  case 'C':		/* checkpoint every N addresses */
114751305Seric 		CheckpointInterval = atoi(val);
114824944Seric 		break;
114924944Seric 
11509284Seric 	  case 'd':		/* delivery mode */
11519284Seric 		switch (*val)
11528269Seric 		{
11539284Seric 		  case '\0':
115458734Seric 			e->e_sendmode = SM_DELIVER;
11558269Seric 			break;
11568269Seric 
115710755Seric 		  case SM_QUEUE:	/* queue only */
115810755Seric #ifndef QUEUE
115910755Seric 			syserr("need QUEUE to set -odqueue");
116056795Seric #endif /* QUEUE */
116110755Seric 			/* fall through..... */
116210755Seric 
11639284Seric 		  case SM_DELIVER:	/* do everything */
11649284Seric 		  case SM_FORK:		/* fork after verification */
116558734Seric 			e->e_sendmode = *val;
11668269Seric 			break;
11678269Seric 
11688269Seric 		  default:
11699284Seric 			syserr("Unknown delivery mode %c", *val);
11708269Seric 			exit(EX_USAGE);
11718269Seric 		}
11728269Seric 		break;
11738269Seric 
11749146Seric 	  case 'D':		/* rebuild alias database as needed */
11759381Seric 		AutoRebuild = atobool(val);
11769146Seric 		break;
11779146Seric 
117855372Seric 	  case 'E':		/* error message header/header file */
117955379Seric 		if (*val != '\0')
118055379Seric 			ErrMsgFile = newstr(val);
118155372Seric 		break;
118255372Seric 
11838269Seric 	  case 'e':		/* set error processing mode */
11848269Seric 		switch (*val)
11858269Seric 		{
11869381Seric 		  case EM_QUIET:	/* be silent about it */
11879381Seric 		  case EM_MAIL:		/* mail back */
11889381Seric 		  case EM_BERKNET:	/* do berknet error processing */
11899381Seric 		  case EM_WRITE:	/* write back (or mail) */
11909381Seric 		  case EM_PRINT:	/* print errors normally (default) */
119158734Seric 			e->e_errormode = *val;
11928269Seric 			break;
11938269Seric 		}
11948269Seric 		break;
11958269Seric 
11969049Seric 	  case 'F':		/* file mode */
119717975Seric 		FileMode = atooct(val) & 0777;
11989049Seric 		break;
11999049Seric 
12008269Seric 	  case 'f':		/* save Unix-style From lines on front */
12019381Seric 		SaveFrom = atobool(val);
12028269Seric 		break;
12038269Seric 
120453735Seric 	  case 'G':		/* match recipients against GECOS field */
120553735Seric 		MatchGecos = atobool(val);
120653735Seric 		break;
120753735Seric 
12088256Seric 	  case 'g':		/* default gid */
120964133Seric 		if (isascii(*val) && isdigit(*val))
121064133Seric 			DefGid = atoi(val);
121164133Seric 		else
121264133Seric 		{
121364133Seric 			register struct group *gr;
121464133Seric 
121564133Seric 			DefGid = -1;
121664133Seric 			gr = getgrnam(val);
121764133Seric 			if (gr == NULL)
121864133Seric 				syserr("readcf: option g: unknown group %s", val);
121964133Seric 			else
122064133Seric 				DefGid = gr->gr_gid;
122164133Seric 		}
12228256Seric 		break;
12238256Seric 
12248256Seric 	  case 'H':		/* help file */
12259381Seric 		if (val[0] == '\0')
12268269Seric 			HelpFile = "sendmail.hf";
12279381Seric 		else
12289381Seric 			HelpFile = newstr(val);
12298256Seric 		break;
12308256Seric 
123151305Seric 	  case 'h':		/* maximum hop count */
123251305Seric 		MaxHopCount = atoi(val);
123351305Seric 		break;
123451305Seric 
123535651Seric 	  case 'I':		/* use internet domain name server */
123666334Seric #if NAMED_BIND
123757207Seric 		UseNameServer = TRUE;
123857207Seric 		for (p = val; *p != 0; )
123957207Seric 		{
124057207Seric 			bool clearmode;
124157207Seric 			char *q;
124257207Seric 			struct resolverflags *rfp;
124357207Seric 
124457207Seric 			while (*p == ' ')
124557207Seric 				p++;
124657207Seric 			if (*p == '\0')
124757207Seric 				break;
124857207Seric 			clearmode = FALSE;
124957207Seric 			if (*p == '-')
125057207Seric 				clearmode = TRUE;
125157207Seric 			else if (*p != '+')
125257207Seric 				p--;
125357207Seric 			p++;
125457207Seric 			q = p;
125558050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
125657207Seric 				p++;
125757207Seric 			if (*p != '\0')
125857207Seric 				*p++ = '\0';
125957207Seric 			for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
126057207Seric 			{
126157207Seric 				if (strcasecmp(q, rfp->rf_name) == 0)
126257207Seric 					break;
126357207Seric 			}
126464923Seric 			if (rfp->rf_name == NULL)
126564923Seric 				syserr("readcf: I option value %s unrecognized", q);
126664923Seric 			else if (clearmode)
126757207Seric 				_res.options &= ~rfp->rf_bits;
126857207Seric 			else
126957207Seric 				_res.options |= rfp->rf_bits;
127057207Seric 		}
127157207Seric 		if (tTd(8, 2))
127257207Seric 			printf("_res.options = %x\n", _res.options);
127357207Seric #else
127457207Seric 		usrerr("name server (I option) specified but BIND not compiled in");
127557207Seric #endif
127635651Seric 		break;
127735651Seric 
12788269Seric 	  case 'i':		/* ignore dot lines in message */
12799381Seric 		IgnrDot = atobool(val);
12808269Seric 		break;
12818269Seric 
128259730Seric 	  case 'j':		/* send errors in MIME (RFC 1341) format */
128359730Seric 		SendMIMEErrors = atobool(val);
128459730Seric 		break;
128559730Seric 
128657136Seric 	  case 'J':		/* .forward search path */
128757136Seric 		ForwardPath = newstr(val);
128857136Seric 		break;
128957136Seric 
129054967Seric 	  case 'k':		/* connection cache size */
129154967Seric 		MaxMciCache = atoi(val);
129256215Seric 		if (MaxMciCache < 0)
129356215Seric 			MaxMciCache = 0;
129454967Seric 		break;
129554967Seric 
129654967Seric 	  case 'K':		/* connection cache timeout */
129758796Seric 		MciCacheTimeout = convtime(val, 'm');
129854967Seric 		break;
129954967Seric 
130061104Seric 	  case 'l':		/* use Errors-To: header */
130161104Seric 		UseErrorsTo = atobool(val);
130261104Seric 		break;
130361104Seric 
13048256Seric 	  case 'L':		/* log level */
130564140Seric 		if (safe || LogLevel < atoi(val))
130664140Seric 			LogLevel = atoi(val);
13078256Seric 		break;
13088256Seric 
13098269Seric 	  case 'M':		/* define macro */
13109381Seric 		define(val[0], newstr(&val[1]), CurEnv);
131116878Seric 		sticky = FALSE;
13128269Seric 		break;
13138269Seric 
13148269Seric 	  case 'm':		/* send to me too */
13159381Seric 		MeToo = atobool(val);
13168269Seric 		break;
13178269Seric 
131825820Seric 	  case 'n':		/* validate RHS in newaliases */
131925820Seric 		CheckAliases = atobool(val);
132025820Seric 		break;
132125820Seric 
132261104Seric 	    /* 'N' available -- was "net name" */
132361104Seric 
132458851Seric 	  case 'O':		/* daemon options */
132558851Seric 		setdaemonoptions(val);
132658851Seric 		break;
132758851Seric 
13288269Seric 	  case 'o':		/* assume old style headers */
13299381Seric 		if (atobool(val))
13309341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
13319341Seric 		else
13329341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
13338269Seric 		break;
13348269Seric 
133558082Seric 	  case 'p':		/* select privacy level */
133658082Seric 		p = val;
133758082Seric 		for (;;)
133858082Seric 		{
133958082Seric 			register struct prival *pv;
134058082Seric 			extern struct prival PrivacyValues[];
134158082Seric 
134258082Seric 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
134358082Seric 				p++;
134458082Seric 			if (*p == '\0')
134558082Seric 				break;
134658082Seric 			val = p;
134758082Seric 			while (isascii(*p) && isalnum(*p))
134858082Seric 				p++;
134958082Seric 			if (*p != '\0')
135058082Seric 				*p++ = '\0';
135158082Seric 
135258082Seric 			for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
135358082Seric 			{
135458082Seric 				if (strcasecmp(val, pv->pv_name) == 0)
135558082Seric 					break;
135658082Seric 			}
135758886Seric 			if (pv->pv_name == NULL)
135858886Seric 				syserr("readcf: Op line: %s unrecognized", val);
135958082Seric 			PrivacyFlags |= pv->pv_flag;
136058082Seric 		}
136158082Seric 		break;
136258082Seric 
136324944Seric 	  case 'P':		/* postmaster copy address for returned mail */
136424944Seric 		PostMasterCopy = newstr(val);
136524944Seric 		break;
136624944Seric 
136724944Seric 	  case 'q':		/* slope of queue only function */
136824944Seric 		QueueFactor = atoi(val);
136924944Seric 		break;
137024944Seric 
13718256Seric 	  case 'Q':		/* queue directory */
13729381Seric 		if (val[0] == '\0')
13738269Seric 			QueueDir = "mqueue";
13749381Seric 		else
13759381Seric 			QueueDir = newstr(val);
137658789Seric 		if (RealUid != 0 && !safe)
137764718Seric 			Warn_Q_option = TRUE;
13788256Seric 		break;
13798256Seric 
138058148Seric 	  case 'R':		/* don't prune routes */
138158148Seric 		DontPruneRoutes = atobool(val);
138258148Seric 		break;
138358148Seric 
13848256Seric 	  case 'r':		/* read timeout */
138558112Seric 		settimeouts(val);
13868256Seric 		break;
13878256Seric 
13888256Seric 	  case 'S':		/* status file */
13899381Seric 		if (val[0] == '\0')
13908269Seric 			StatFile = "sendmail.st";
13919381Seric 		else
13929381Seric 			StatFile = newstr(val);
13938256Seric 		break;
13948256Seric 
13958265Seric 	  case 's':		/* be super safe, even if expensive */
13969381Seric 		SuperSafe = atobool(val);
13978256Seric 		break;
13988256Seric 
13998256Seric 	  case 'T':		/* queue timeout */
140058737Seric 		p = strchr(val, '/');
140158737Seric 		if (p != NULL)
140258737Seric 		{
140358737Seric 			*p++ = '\0';
140458796Seric 			TimeOuts.to_q_warning = convtime(p, 'd');
140558737Seric 		}
140658796Seric 		TimeOuts.to_q_return = convtime(val, 'h');
140754967Seric 		break;
14088256Seric 
14098265Seric 	  case 't':		/* time zone name */
141052106Seric 		TimeZoneSpec = newstr(val);
14118265Seric 		break;
14128265Seric 
141350556Seric 	  case 'U':		/* location of user database */
141451360Seric 		UdbSpec = newstr(val);
141550556Seric 		break;
141650556Seric 
14178256Seric 	  case 'u':		/* set default uid */
141864133Seric 		if (isascii(*val) && isdigit(*val))
141964133Seric 			DefUid = atoi(val);
142064133Seric 		else
142164133Seric 		{
142264133Seric 			register struct passwd *pw;
142364133Seric 
142464133Seric 			DefUid = -1;
142564133Seric 			pw = getpwnam(val);
142664133Seric 			if (pw == NULL)
142764133Seric 				syserr("readcf: option u: unknown user %s", val);
142864133Seric 			else
142964133Seric 				DefUid = pw->pw_uid;
143064133Seric 		}
143140973Sbostic 		setdefuser();
14328256Seric 		break;
14338256Seric 
143458851Seric 	  case 'V':		/* fallback MX host */
143558851Seric 		FallBackMX = newstr(val);
143658851Seric 		break;
143758851Seric 
14388269Seric 	  case 'v':		/* run in verbose mode */
14399381Seric 		Verbose = atobool(val);
14408256Seric 		break;
14418256Seric 
144263837Seric 	  case 'w':		/* if we are best MX, try host directly */
144363837Seric 		TryNullMXList = atobool(val);
144463837Seric 		break;
144561104Seric 
144661104Seric 	    /* 'W' available -- was wizard password */
144761104Seric 
144814879Seric 	  case 'x':		/* load avg at which to auto-queue msgs */
144914879Seric 		QueueLA = atoi(val);
145014879Seric 		break;
145114879Seric 
145214879Seric 	  case 'X':		/* load avg at which to auto-reject connections */
145314879Seric 		RefuseLA = atoi(val);
145414879Seric 		break;
145514879Seric 
145624981Seric 	  case 'y':		/* work recipient factor */
145724981Seric 		WkRecipFact = atoi(val);
145824981Seric 		break;
145924981Seric 
146024981Seric 	  case 'Y':		/* fork jobs during queue runs */
146124952Seric 		ForkQueueRuns = atobool(val);
146224952Seric 		break;
146324952Seric 
146424981Seric 	  case 'z':		/* work message class factor */
146524981Seric 		WkClassFact = atoi(val);
146624981Seric 		break;
146724981Seric 
146824981Seric 	  case 'Z':		/* work time factor */
146924981Seric 		WkTimeFact = atoi(val);
147024981Seric 		break;
147124981Seric 
14728256Seric 	  default:
14738256Seric 		break;
14748256Seric 	}
147516878Seric 	if (sticky)
147616878Seric 		setbitn(opt, StickyOpt);
14779188Seric 	return;
14788256Seric }
147910687Seric /*
148010687Seric **  SETCLASS -- set a word into a class
148110687Seric **
148210687Seric **	Parameters:
148310687Seric **		class -- the class to put the word in.
148410687Seric **		word -- the word to enter
148510687Seric **
148610687Seric **	Returns:
148710687Seric **		none.
148810687Seric **
148910687Seric **	Side Effects:
149010687Seric **		puts the word into the symbol table.
149110687Seric */
149210687Seric 
149310687Seric setclass(class, word)
149410687Seric 	int class;
149510687Seric 	char *word;
149610687Seric {
149710687Seric 	register STAB *s;
149810687Seric 
149957943Seric 	if (tTd(37, 8))
150064326Seric 		printf("setclass(%c, %s)\n", class, word);
150110687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
150210687Seric 	setbitn(class, s->s_class);
150310687Seric }
150453654Seric /*
150553654Seric **  MAKEMAPENTRY -- create a map entry
150653654Seric **
150753654Seric **	Parameters:
150853654Seric **		line -- the config file line
150953654Seric **
151053654Seric **	Returns:
151153654Seric **		TRUE if it successfully entered the map entry.
151253654Seric **		FALSE otherwise (usually syntax error).
151353654Seric **
151453654Seric **	Side Effects:
151553654Seric **		Enters the map into the dictionary.
151653654Seric */
151753654Seric 
151853654Seric void
151953654Seric makemapentry(line)
152053654Seric 	char *line;
152153654Seric {
152253654Seric 	register char *p;
152353654Seric 	char *mapname;
152453654Seric 	char *classname;
152564078Seric 	register STAB *s;
152653654Seric 	STAB *class;
152753654Seric 
152858050Seric 	for (p = line; isascii(*p) && isspace(*p); p++)
152953654Seric 		continue;
153058050Seric 	if (!(isascii(*p) && isalnum(*p)))
153153654Seric 	{
153253654Seric 		syserr("readcf: config K line: no map name");
153353654Seric 		return;
153453654Seric 	}
153553654Seric 
153653654Seric 	mapname = p;
153758050Seric 	while (isascii(*++p) && isalnum(*p))
153853654Seric 		continue;
153953654Seric 	if (*p != '\0')
154053654Seric 		*p++ = '\0';
154158050Seric 	while (isascii(*p) && isspace(*p))
154253654Seric 		p++;
154358050Seric 	if (!(isascii(*p) && isalnum(*p)))
154453654Seric 	{
154553654Seric 		syserr("readcf: config K line, map %s: no map class", mapname);
154653654Seric 		return;
154753654Seric 	}
154853654Seric 	classname = p;
154958050Seric 	while (isascii(*++p) && isalnum(*p))
155053654Seric 		continue;
155153654Seric 	if (*p != '\0')
155253654Seric 		*p++ = '\0';
155358050Seric 	while (isascii(*p) && isspace(*p))
155453654Seric 		p++;
155553654Seric 
155653654Seric 	/* look up the class */
155753654Seric 	class = stab(classname, ST_MAPCLASS, ST_FIND);
155853654Seric 	if (class == NULL)
155953654Seric 	{
156053654Seric 		syserr("readcf: map %s: class %s not available", mapname, classname);
156153654Seric 		return;
156253654Seric 	}
156353654Seric 
156453654Seric 	/* enter the map */
156564078Seric 	s = stab(mapname, ST_MAP, ST_ENTER);
156664078Seric 	s->s_map.map_class = &class->s_mapclass;
156764078Seric 	s->s_map.map_mname = newstr(mapname);
156853654Seric 
156964078Seric 	if (class->s_mapclass.map_parse(&s->s_map, p))
157064078Seric 		s->s_map.map_mflags |= MF_VALID;
157164078Seric 
157264078Seric 	if (tTd(37, 5))
157364078Seric 	{
157464078Seric 		printf("map %s, class %s, flags %x, file %s,\n",
157564078Seric 			s->s_map.map_mname, s->s_map.map_class->map_cname,
157664078Seric 			s->s_map.map_mflags,
157764078Seric 			s->s_map.map_file == NULL ? "(null)" : s->s_map.map_file);
157864078Seric 		printf("\tapp %s, domain %s, rebuild %s\n",
157964078Seric 			s->s_map.map_app == NULL ? "(null)" : s->s_map.map_app,
158064078Seric 			s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain,
158164078Seric 			s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild);
158264078Seric 	}
158353654Seric }
158458112Seric /*
158558112Seric **  SETTIMEOUTS -- parse and set timeout values
158658112Seric **
158758112Seric **	Parameters:
158858112Seric **		val -- a pointer to the values.  If NULL, do initial
158958112Seric **			settings.
159058112Seric **
159158112Seric **	Returns:
159258112Seric **		none.
159358112Seric **
159458112Seric **	Side Effects:
159558112Seric **		Initializes the TimeOuts structure
159658112Seric */
159758112Seric 
159864255Seric #define SECONDS
159958112Seric #define MINUTES	* 60
160058112Seric #define HOUR	* 3600
160158112Seric 
160258112Seric settimeouts(val)
160358112Seric 	register char *val;
160458112Seric {
160558112Seric 	register char *p;
160658671Seric 	extern time_t convtime();
160758112Seric 
160858112Seric 	if (val == NULL)
160958112Seric 	{
161058112Seric 		TimeOuts.to_initial = (time_t) 5 MINUTES;
161158112Seric 		TimeOuts.to_helo = (time_t) 5 MINUTES;
161258112Seric 		TimeOuts.to_mail = (time_t) 10 MINUTES;
161358112Seric 		TimeOuts.to_rcpt = (time_t) 1 HOUR;
161458112Seric 		TimeOuts.to_datainit = (time_t) 5 MINUTES;
161558112Seric 		TimeOuts.to_datablock = (time_t) 1 HOUR;
161658112Seric 		TimeOuts.to_datafinal = (time_t) 1 HOUR;
161758112Seric 		TimeOuts.to_rset = (time_t) 5 MINUTES;
161858112Seric 		TimeOuts.to_quit = (time_t) 2 MINUTES;
161958112Seric 		TimeOuts.to_nextcommand = (time_t) 1 HOUR;
162058112Seric 		TimeOuts.to_miscshort = (time_t) 2 MINUTES;
162164255Seric 		TimeOuts.to_ident = (time_t) 30 SECONDS;
162258112Seric 		return;
162358112Seric 	}
162458112Seric 
162558112Seric 	for (;; val = p)
162658112Seric 	{
162758112Seric 		while (isascii(*val) && isspace(*val))
162858112Seric 			val++;
162958112Seric 		if (*val == '\0')
163058112Seric 			break;
163158112Seric 		for (p = val; *p != '\0' && *p != ','; p++)
163258112Seric 			continue;
163358112Seric 		if (*p != '\0')
163458112Seric 			*p++ = '\0';
163558112Seric 
163658112Seric 		if (isascii(*val) && isdigit(*val))
163758112Seric 		{
163858112Seric 			/* old syntax -- set everything */
163958796Seric 			TimeOuts.to_mail = convtime(val, 'm');
164058112Seric 			TimeOuts.to_rcpt = TimeOuts.to_mail;
164158112Seric 			TimeOuts.to_datainit = TimeOuts.to_mail;
164258112Seric 			TimeOuts.to_datablock = TimeOuts.to_mail;
164358112Seric 			TimeOuts.to_datafinal = TimeOuts.to_mail;
164458112Seric 			TimeOuts.to_nextcommand = TimeOuts.to_mail;
164558112Seric 			continue;
164658112Seric 		}
164758112Seric 		else
164858112Seric 		{
164958112Seric 			register char *q = strchr(val, '=');
165058112Seric 			time_t to;
165158112Seric 
165258112Seric 			if (q == NULL)
165358112Seric 			{
165458112Seric 				/* syntax error */
165558112Seric 				continue;
165658112Seric 			}
165758112Seric 			*q++ = '\0';
165858796Seric 			to = convtime(q, 'm');
165958112Seric 
166058112Seric 			if (strcasecmp(val, "initial") == 0)
166158112Seric 				TimeOuts.to_initial = to;
166258112Seric 			else if (strcasecmp(val, "mail") == 0)
166358112Seric 				TimeOuts.to_mail = to;
166458112Seric 			else if (strcasecmp(val, "rcpt") == 0)
166558112Seric 				TimeOuts.to_rcpt = to;
166658112Seric 			else if (strcasecmp(val, "datainit") == 0)
166758112Seric 				TimeOuts.to_datainit = to;
166858112Seric 			else if (strcasecmp(val, "datablock") == 0)
166958112Seric 				TimeOuts.to_datablock = to;
167058112Seric 			else if (strcasecmp(val, "datafinal") == 0)
167158112Seric 				TimeOuts.to_datafinal = to;
167258112Seric 			else if (strcasecmp(val, "command") == 0)
167358112Seric 				TimeOuts.to_nextcommand = to;
167458112Seric 			else if (strcasecmp(val, "rset") == 0)
167558112Seric 				TimeOuts.to_rset = to;
167658112Seric 			else if (strcasecmp(val, "helo") == 0)
167758112Seric 				TimeOuts.to_helo = to;
167858112Seric 			else if (strcasecmp(val, "quit") == 0)
167958112Seric 				TimeOuts.to_quit = to;
168058112Seric 			else if (strcasecmp(val, "misc") == 0)
168158112Seric 				TimeOuts.to_miscshort = to;
168264255Seric 			else if (strcasecmp(val, "ident") == 0)
168364255Seric 				TimeOuts.to_ident = to;
168458112Seric 			else
168558112Seric 				syserr("settimeouts: invalid timeout %s", val);
168658112Seric 		}
168758112Seric 	}
168858112Seric }
1689