xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 66031)
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*66031Seric static char sccsid[] = "@(#)readcf.c	8.20 (Berkeley) 02/08/94";
1133731Sbostic #endif /* not lint */
1222709Sdist 
133313Seric # include "sendmail.h"
1464133Seric # include <pwd.h>
1564133Seric # include <grp.h>
1657207Seric #ifdef 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");
51964947Seric #ifdef 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 
577*66031Seric 	if (filename[0] == '|')
578*66031Seric 	{
579*66031Seric 		syserr("fileclass: pipes (F%c%s) not supported due to security problems",
580*66031Seric 			class, filename);
581*66031Seric 		return;
582*66031Seric 	}
58354973Seric 	if (stat(filename, &stbuf) < 0)
58454973Seric 	{
58564133Seric 		if (!optional)
58664133Seric 			syserr("fileclass: cannot stat %s", filename);
58754973Seric 		return;
58854973Seric 	}
58954973Seric 	if (!S_ISREG(stbuf.st_mode))
59054973Seric 	{
59154973Seric 		syserr("fileclass: %s not a regular file", filename);
59254973Seric 		return;
59354973Seric 	}
59454973Seric 	if (!safe && access(filename, R_OK) < 0)
59554973Seric 	{
59654973Seric 		syserr("fileclass: access denied on %s", filename);
59754973Seric 		return;
59854973Seric 	}
59954973Seric 	f = fopen(filename, "r");
6004432Seric 	if (f == NULL)
6014432Seric 	{
60254973Seric 		syserr("fileclass: cannot open %s", filename);
6034432Seric 		return;
6044432Seric 	}
6054432Seric 
6064432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
6074432Seric 	{
6084432Seric 		register STAB *s;
60925808Seric 		register char *p;
61025808Seric # ifdef SCANF
6114432Seric 		char wordbuf[MAXNAME+1];
6124432Seric 
6134432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
6144432Seric 			continue;
61525808Seric 		p = wordbuf;
61656795Seric # else /* SCANF */
61725808Seric 		p = buf;
61856795Seric # endif /* SCANF */
61925808Seric 
62025808Seric 		/*
62125808Seric 		**  Break up the match into words.
62225808Seric 		*/
62325808Seric 
62425808Seric 		while (*p != '\0')
62525808Seric 		{
62625808Seric 			register char *q;
62725808Seric 
62825808Seric 			/* strip leading spaces */
62958050Seric 			while (isascii(*p) && isspace(*p))
63025808Seric 				p++;
63125808Seric 			if (*p == '\0')
63225808Seric 				break;
63325808Seric 
63425808Seric 			/* find the end of the word */
63525808Seric 			q = p;
63658050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
63725808Seric 				p++;
63825808Seric 			if (*p != '\0')
63925808Seric 				*p++ = '\0';
64025808Seric 
64125808Seric 			/* enter the word in the symbol table */
64225808Seric 			s = stab(q, ST_CLASS, ST_ENTER);
64325808Seric 			setbitn(class, s->s_class);
64425808Seric 		}
6454432Seric 	}
6464432Seric 
64754973Seric 	(void) fclose(f);
6484432Seric }
6494432Seric /*
6504096Seric **  MAKEMAILER -- define a new mailer.
6514096Seric **
6524096Seric **	Parameters:
65310327Seric **		line -- description of mailer.  This is in labeled
65410327Seric **			fields.  The fields are:
65510327Seric **			   P -- the path to the mailer
65610327Seric **			   F -- the flags associated with the mailer
65710327Seric **			   A -- the argv for this mailer
65810327Seric **			   S -- the sender rewriting set
65910327Seric **			   R -- the recipient rewriting set
66010327Seric **			   E -- the eol string
66110327Seric **			The first word is the canonical name of the mailer.
6624096Seric **
6634096Seric **	Returns:
6644096Seric **		none.
6654096Seric **
6664096Seric **	Side Effects:
6674096Seric **		enters the mailer into the mailer table.
6684096Seric */
6693308Seric 
67021066Seric makemailer(line)
6714096Seric 	char *line;
6724096Seric {
6734096Seric 	register char *p;
6748067Seric 	register struct mailer *m;
6758067Seric 	register STAB *s;
6768067Seric 	int i;
67710327Seric 	char fcode;
67858020Seric 	auto char *endp;
6794096Seric 	extern int NextMailer;
68010327Seric 	extern char **makeargv();
68110327Seric 	extern char *munchstring();
68210701Seric 	extern long atol();
6834096Seric 
68410327Seric 	/* allocate a mailer and set up defaults */
68510327Seric 	m = (struct mailer *) xalloc(sizeof *m);
68610327Seric 	bzero((char *) m, sizeof *m);
68710327Seric 	m->m_eol = "\n";
68810327Seric 
68910327Seric 	/* collect the mailer name */
69058050Seric 	for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++)
69110327Seric 		continue;
69210327Seric 	if (*p != '\0')
69310327Seric 		*p++ = '\0';
69410327Seric 	m->m_name = newstr(line);
69510327Seric 
69610327Seric 	/* now scan through and assign info from the fields */
69710327Seric 	while (*p != '\0')
69810327Seric 	{
69958333Seric 		auto char *delimptr;
70058333Seric 
70158050Seric 		while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p))))
70210327Seric 			p++;
70310327Seric 
70410327Seric 		/* p now points to field code */
70510327Seric 		fcode = *p;
70610327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
70710327Seric 			p++;
70810327Seric 		if (*p++ != '=')
70910327Seric 		{
71052637Seric 			syserr("mailer %s: `=' expected", m->m_name);
71110327Seric 			return;
71210327Seric 		}
71358050Seric 		while (isascii(*p) && isspace(*p))
71410327Seric 			p++;
71510327Seric 
71610327Seric 		/* p now points to the field body */
71758333Seric 		p = munchstring(p, &delimptr);
71810327Seric 
71910327Seric 		/* install the field into the mailer struct */
72010327Seric 		switch (fcode)
72110327Seric 		{
72210327Seric 		  case 'P':		/* pathname */
72310327Seric 			m->m_mailer = newstr(p);
72410327Seric 			break;
72510327Seric 
72610327Seric 		  case 'F':		/* flags */
72710687Seric 			for (; *p != '\0'; p++)
72858050Seric 				if (!(isascii(*p) && isspace(*p)))
72952637Seric 					setbitn(*p, m->m_flags);
73010327Seric 			break;
73110327Seric 
73210327Seric 		  case 'S':		/* sender rewriting ruleset */
73310327Seric 		  case 'R':		/* recipient rewriting ruleset */
73458020Seric 			i = strtol(p, &endp, 10);
73510327Seric 			if (i < 0 || i >= MAXRWSETS)
73610327Seric 			{
73710327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
73810327Seric 				return;
73910327Seric 			}
74010327Seric 			if (fcode == 'S')
74158020Seric 				m->m_sh_rwset = m->m_se_rwset = i;
74210327Seric 			else
74358020Seric 				m->m_rh_rwset = m->m_re_rwset = i;
74458020Seric 
74558020Seric 			p = endp;
74659985Seric 			if (*p++ == '/')
74758020Seric 			{
74858020Seric 				i = strtol(p, NULL, 10);
74958020Seric 				if (i < 0 || i >= MAXRWSETS)
75058020Seric 				{
75158020Seric 					syserr("invalid rewrite set, %d max",
75258020Seric 						MAXRWSETS);
75358020Seric 					return;
75458020Seric 				}
75558020Seric 				if (fcode == 'S')
75658020Seric 					m->m_sh_rwset = i;
75758020Seric 				else
75858020Seric 					m->m_rh_rwset = i;
75958020Seric 			}
76010327Seric 			break;
76110327Seric 
76210327Seric 		  case 'E':		/* end of line string */
76310327Seric 			m->m_eol = newstr(p);
76410327Seric 			break;
76510327Seric 
76610327Seric 		  case 'A':		/* argument vector */
76710327Seric 			m->m_argv = makeargv(p);
76810327Seric 			break;
76910701Seric 
77010701Seric 		  case 'M':		/* maximum message size */
77110701Seric 			m->m_maxsize = atol(p);
77210701Seric 			break;
77352106Seric 
77452106Seric 		  case 'L':		/* maximum line length */
77552106Seric 			m->m_linelimit = atoi(p);
77652106Seric 			break;
77758935Seric 
77858935Seric 		  case 'D':		/* working directory */
77958935Seric 			m->m_execdir = newstr(p);
78058935Seric 			break;
78110327Seric 		}
78210327Seric 
78358333Seric 		p = delimptr;
78410327Seric 	}
78510327Seric 
78652106Seric 	/* do some heuristic cleanup for back compatibility */
78752106Seric 	if (bitnset(M_LIMITS, m->m_flags))
78852106Seric 	{
78952106Seric 		if (m->m_linelimit == 0)
79052106Seric 			m->m_linelimit = SMTPLINELIM;
79155418Seric 		if (ConfigLevel < 2)
79252106Seric 			setbitn(M_7BITS, m->m_flags);
79352106Seric 	}
79452106Seric 
79558321Seric 	/* do some rationality checking */
79658321Seric 	if (m->m_argv == NULL)
79758321Seric 	{
79858321Seric 		syserr("M%s: A= argument required", m->m_name);
79958321Seric 		return;
80058321Seric 	}
80158321Seric 	if (m->m_mailer == NULL)
80258321Seric 	{
80358321Seric 		syserr("M%s: P= argument required", m->m_name);
80458321Seric 		return;
80558321Seric 	}
80658321Seric 
8074096Seric 	if (NextMailer >= MAXMAILERS)
8084096Seric 	{
8099381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
8104096Seric 		return;
8114096Seric 	}
81257402Seric 
81310327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
81457402Seric 	if (s->s_mailer != NULL)
81557402Seric 	{
81657402Seric 		i = s->s_mailer->m_mno;
81757402Seric 		free(s->s_mailer);
81857402Seric 	}
81957402Seric 	else
82057402Seric 	{
82157402Seric 		i = NextMailer++;
82257402Seric 	}
82357402Seric 	Mailer[i] = s->s_mailer = m;
82457454Seric 	m->m_mno = i;
82510327Seric }
82610327Seric /*
82710327Seric **  MUNCHSTRING -- translate a string into internal form.
82810327Seric **
82910327Seric **	Parameters:
83010327Seric **		p -- the string to munch.
83158333Seric **		delimptr -- if non-NULL, set to the pointer of the
83258333Seric **			field delimiter character.
83310327Seric **
83410327Seric **	Returns:
83510327Seric **		the munched string.
83610327Seric */
8374096Seric 
83810327Seric char *
83958333Seric munchstring(p, delimptr)
84010327Seric 	register char *p;
84158333Seric 	char **delimptr;
84210327Seric {
84310327Seric 	register char *q;
84410327Seric 	bool backslash = FALSE;
84510327Seric 	bool quotemode = FALSE;
84610327Seric 	static char buf[MAXLINE];
8474096Seric 
84810327Seric 	for (q = buf; *p != '\0'; p++)
8494096Seric 	{
85010327Seric 		if (backslash)
85110327Seric 		{
85210327Seric 			/* everything is roughly literal */
85310357Seric 			backslash = FALSE;
85410327Seric 			switch (*p)
85510327Seric 			{
85610327Seric 			  case 'r':		/* carriage return */
85710327Seric 				*q++ = '\r';
85810327Seric 				continue;
85910327Seric 
86010327Seric 			  case 'n':		/* newline */
86110327Seric 				*q++ = '\n';
86210327Seric 				continue;
86310327Seric 
86410327Seric 			  case 'f':		/* form feed */
86510327Seric 				*q++ = '\f';
86610327Seric 				continue;
86710327Seric 
86810327Seric 			  case 'b':		/* backspace */
86910327Seric 				*q++ = '\b';
87010327Seric 				continue;
87110327Seric 			}
87210327Seric 			*q++ = *p;
87310327Seric 		}
87410327Seric 		else
87510327Seric 		{
87610327Seric 			if (*p == '\\')
87710327Seric 				backslash = TRUE;
87810327Seric 			else if (*p == '"')
87910327Seric 				quotemode = !quotemode;
88010327Seric 			else if (quotemode || *p != ',')
88110327Seric 				*q++ = *p;
88210327Seric 			else
88310327Seric 				break;
88410327Seric 		}
8854096Seric 	}
8864096Seric 
88758333Seric 	if (delimptr != NULL)
88858333Seric 		*delimptr = p;
88910327Seric 	*q++ = '\0';
89010327Seric 	return (buf);
89110327Seric }
89210327Seric /*
89310327Seric **  MAKEARGV -- break up a string into words
89410327Seric **
89510327Seric **	Parameters:
89610327Seric **		p -- the string to break up.
89710327Seric **
89810327Seric **	Returns:
89910327Seric **		a char **argv (dynamically allocated)
90010327Seric **
90110327Seric **	Side Effects:
90210327Seric **		munges p.
90310327Seric */
9044096Seric 
90510327Seric char **
90610327Seric makeargv(p)
90710327Seric 	register char *p;
90810327Seric {
90910327Seric 	char *q;
91010327Seric 	int i;
91110327Seric 	char **avp;
91210327Seric 	char *argv[MAXPV + 1];
91310327Seric 
91410327Seric 	/* take apart the words */
91510327Seric 	i = 0;
91610327Seric 	while (*p != '\0' && i < MAXPV)
9174096Seric 	{
91810327Seric 		q = p;
91958050Seric 		while (*p != '\0' && !(isascii(*p) && isspace(*p)))
92010327Seric 			p++;
92158050Seric 		while (isascii(*p) && isspace(*p))
92210327Seric 			*p++ = '\0';
92310327Seric 		argv[i++] = newstr(q);
9244096Seric 	}
92510327Seric 	argv[i++] = NULL;
9264096Seric 
92710327Seric 	/* now make a copy of the argv */
92810327Seric 	avp = (char **) xalloc(sizeof *avp * i);
92916893Seric 	bcopy((char *) argv, (char *) avp, sizeof *avp * i);
93010327Seric 
93110327Seric 	return (avp);
9323308Seric }
9333308Seric /*
9343308Seric **  PRINTRULES -- print rewrite rules (for debugging)
9353308Seric **
9363308Seric **	Parameters:
9373308Seric **		none.
9383308Seric **
9393308Seric **	Returns:
9403308Seric **		none.
9413308Seric **
9423308Seric **	Side Effects:
9433308Seric **		prints rewrite rules.
9443308Seric */
9453308Seric 
9463308Seric printrules()
9473308Seric {
9483308Seric 	register struct rewrite *rwp;
9494072Seric 	register int ruleset;
9503308Seric 
9514072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
9523308Seric 	{
9534072Seric 		if (RewriteRules[ruleset] == NULL)
9544072Seric 			continue;
9558067Seric 		printf("\n----Rule Set %d:", ruleset);
9563308Seric 
9574072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
9583308Seric 		{
9598067Seric 			printf("\nLHS:");
9608067Seric 			printav(rwp->r_lhs);
9618067Seric 			printf("RHS:");
9628067Seric 			printav(rwp->r_rhs);
9633308Seric 		}
9643308Seric 	}
9653308Seric }
9664319Seric 
9674096Seric /*
9688256Seric **  SETOPTION -- set global processing option
9698256Seric **
9708256Seric **	Parameters:
9718256Seric **		opt -- option name.
9728256Seric **		val -- option value (as a text string).
97321755Seric **		safe -- set if this came from a configuration file.
97421755Seric **			Some options (if set from the command line) will
97521755Seric **			reset the user id to avoid security problems.
9768269Seric **		sticky -- if set, don't let other setoptions override
9778269Seric **			this value.
97858734Seric **		e -- the main envelope.
9798256Seric **
9808256Seric **	Returns:
9818256Seric **		none.
9828256Seric **
9838256Seric **	Side Effects:
9848256Seric **		Sets options as implied by the arguments.
9858256Seric */
9868256Seric 
98710687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
9888269Seric 
98957207Seric 
99057207Seric #ifdef NAMED_BIND
99157207Seric 
99257207Seric struct resolverflags
99357207Seric {
99457207Seric 	char	*rf_name;	/* name of the flag */
99557207Seric 	long	rf_bits;	/* bits to set/clear */
99657207Seric } ResolverFlags[] =
99757207Seric {
99857207Seric 	"debug",	RES_DEBUG,
99957207Seric 	"aaonly",	RES_AAONLY,
100057207Seric 	"usevc",	RES_USEVC,
100157207Seric 	"primary",	RES_PRIMARY,
100257207Seric 	"igntc",	RES_IGNTC,
100357207Seric 	"recurse",	RES_RECURSE,
100457207Seric 	"defnames",	RES_DEFNAMES,
100557207Seric 	"stayopen",	RES_STAYOPEN,
100657207Seric 	"dnsrch",	RES_DNSRCH,
100765583Seric 	"true",		0,		/* to avoid error on old syntax */
100857207Seric 	NULL,		0
100957207Seric };
101057207Seric 
101157207Seric #endif
101257207Seric 
101358734Seric setoption(opt, val, safe, sticky, e)
10148256Seric 	char opt;
10158256Seric 	char *val;
101621755Seric 	bool safe;
10178269Seric 	bool sticky;
101858734Seric 	register ENVELOPE *e;
10198256Seric {
102057207Seric 	register char *p;
10218265Seric 	extern bool atobool();
102212633Seric 	extern time_t convtime();
102314879Seric 	extern int QueueLA;
102414879Seric 	extern int RefuseLA;
102564718Seric 	extern bool Warn_Q_option;
102617474Seric 	extern bool trusteduser();
10278256Seric 
10288256Seric 	if (tTd(37, 1))
10299341Seric 		printf("setoption %c=%s", opt, val);
10308256Seric 
10318256Seric 	/*
10328269Seric 	**  See if this option is preset for us.
10338256Seric 	*/
10348256Seric 
103559731Seric 	if (!sticky && bitnset(opt, StickyOpt))
10368269Seric 	{
10379341Seric 		if (tTd(37, 1))
10389341Seric 			printf(" (ignored)\n");
10398269Seric 		return;
10408269Seric 	}
10418269Seric 
104221755Seric 	/*
104321755Seric 	**  Check to see if this option can be specified by this user.
104421755Seric 	*/
104521755Seric 
104663787Seric 	if (!safe && RealUid == 0)
104721755Seric 		safe = TRUE;
104863837Seric 	if (!safe && strchr("bCdeEijLmoprsvw7", opt) == NULL)
104921755Seric 	{
105039111Srick 		if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
105121755Seric 		{
105236582Sbostic 			if (tTd(37, 1))
105336582Sbostic 				printf(" (unsafe)");
105463787Seric 			if (RealUid != geteuid())
105536582Sbostic 			{
105651210Seric 				if (tTd(37, 1))
105751210Seric 					printf("(Resetting uid)");
105863787Seric 				(void) setgid(RealGid);
105963787Seric 				(void) setuid(RealUid);
106036582Sbostic 			}
106121755Seric 		}
106221755Seric 	}
106351210Seric 	if (tTd(37, 1))
106417985Seric 		printf("\n");
10658269Seric 
10668256Seric 	switch (opt)
10678256Seric 	{
106859709Seric 	  case '7':		/* force seven-bit input */
106959709Seric 		SevenBit = atobool(val);
107052106Seric 		break;
107152106Seric 
10728256Seric 	  case 'A':		/* set default alias file */
10739381Seric 		if (val[0] == '\0')
107459672Seric 			setalias("aliases");
10759381Seric 		else
107659672Seric 			setalias(val);
10778256Seric 		break;
10788256Seric 
107917474Seric 	  case 'a':		/* look N minutes for "@:@" in alias file */
108017474Seric 		if (val[0] == '\0')
108164796Seric 			SafeAlias = 5 * 60;		/* five minutes */
108217474Seric 		else
108364796Seric 			SafeAlias = convtime(val, 'm');
108417474Seric 		break;
108517474Seric 
108616843Seric 	  case 'B':		/* substitution for blank character */
108716843Seric 		SpaceSub = val[0];
108816843Seric 		if (SpaceSub == '\0')
108916843Seric 			SpaceSub = ' ';
109016843Seric 		break;
109116843Seric 
109259283Seric 	  case 'b':		/* min blocks free on queue fs/max msg size */
109359283Seric 		p = strchr(val, '/');
109459283Seric 		if (p != NULL)
109559283Seric 		{
109659283Seric 			*p++ = '\0';
109759283Seric 			MaxMessageSize = atol(p);
109859283Seric 		}
109958082Seric 		MinBlocksFree = atol(val);
110058082Seric 		break;
110158082Seric 
11029284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
11039381Seric 		NoConnect = atobool(val);
11049284Seric 		break;
11059284Seric 
110651305Seric 	  case 'C':		/* checkpoint every N addresses */
110751305Seric 		CheckpointInterval = atoi(val);
110824944Seric 		break;
110924944Seric 
11109284Seric 	  case 'd':		/* delivery mode */
11119284Seric 		switch (*val)
11128269Seric 		{
11139284Seric 		  case '\0':
111458734Seric 			e->e_sendmode = SM_DELIVER;
11158269Seric 			break;
11168269Seric 
111710755Seric 		  case SM_QUEUE:	/* queue only */
111810755Seric #ifndef QUEUE
111910755Seric 			syserr("need QUEUE to set -odqueue");
112056795Seric #endif /* QUEUE */
112110755Seric 			/* fall through..... */
112210755Seric 
11239284Seric 		  case SM_DELIVER:	/* do everything */
11249284Seric 		  case SM_FORK:		/* fork after verification */
112558734Seric 			e->e_sendmode = *val;
11268269Seric 			break;
11278269Seric 
11288269Seric 		  default:
11299284Seric 			syserr("Unknown delivery mode %c", *val);
11308269Seric 			exit(EX_USAGE);
11318269Seric 		}
11328269Seric 		break;
11338269Seric 
11349146Seric 	  case 'D':		/* rebuild alias database as needed */
11359381Seric 		AutoRebuild = atobool(val);
11369146Seric 		break;
11379146Seric 
113855372Seric 	  case 'E':		/* error message header/header file */
113955379Seric 		if (*val != '\0')
114055379Seric 			ErrMsgFile = newstr(val);
114155372Seric 		break;
114255372Seric 
11438269Seric 	  case 'e':		/* set error processing mode */
11448269Seric 		switch (*val)
11458269Seric 		{
11469381Seric 		  case EM_QUIET:	/* be silent about it */
11479381Seric 		  case EM_MAIL:		/* mail back */
11489381Seric 		  case EM_BERKNET:	/* do berknet error processing */
11499381Seric 		  case EM_WRITE:	/* write back (or mail) */
11508269Seric 			HoldErrs = TRUE;
11519381Seric 			/* fall through... */
11528269Seric 
11539381Seric 		  case EM_PRINT:	/* print errors normally (default) */
115458734Seric 			e->e_errormode = *val;
11558269Seric 			break;
11568269Seric 		}
11578269Seric 		break;
11588269Seric 
11599049Seric 	  case 'F':		/* file mode */
116017975Seric 		FileMode = atooct(val) & 0777;
11619049Seric 		break;
11629049Seric 
11638269Seric 	  case 'f':		/* save Unix-style From lines on front */
11649381Seric 		SaveFrom = atobool(val);
11658269Seric 		break;
11668269Seric 
116753735Seric 	  case 'G':		/* match recipients against GECOS field */
116853735Seric 		MatchGecos = atobool(val);
116953735Seric 		break;
117053735Seric 
11718256Seric 	  case 'g':		/* default gid */
117264133Seric 		if (isascii(*val) && isdigit(*val))
117364133Seric 			DefGid = atoi(val);
117464133Seric 		else
117564133Seric 		{
117664133Seric 			register struct group *gr;
117764133Seric 
117864133Seric 			DefGid = -1;
117964133Seric 			gr = getgrnam(val);
118064133Seric 			if (gr == NULL)
118164133Seric 				syserr("readcf: option g: unknown group %s", val);
118264133Seric 			else
118364133Seric 				DefGid = gr->gr_gid;
118464133Seric 		}
11858256Seric 		break;
11868256Seric 
11878256Seric 	  case 'H':		/* help file */
11889381Seric 		if (val[0] == '\0')
11898269Seric 			HelpFile = "sendmail.hf";
11909381Seric 		else
11919381Seric 			HelpFile = newstr(val);
11928256Seric 		break;
11938256Seric 
119451305Seric 	  case 'h':		/* maximum hop count */
119551305Seric 		MaxHopCount = atoi(val);
119651305Seric 		break;
119751305Seric 
119835651Seric 	  case 'I':		/* use internet domain name server */
119957207Seric #ifdef NAMED_BIND
120057207Seric 		UseNameServer = TRUE;
120157207Seric 		for (p = val; *p != 0; )
120257207Seric 		{
120357207Seric 			bool clearmode;
120457207Seric 			char *q;
120557207Seric 			struct resolverflags *rfp;
120657207Seric 
120757207Seric 			while (*p == ' ')
120857207Seric 				p++;
120957207Seric 			if (*p == '\0')
121057207Seric 				break;
121157207Seric 			clearmode = FALSE;
121257207Seric 			if (*p == '-')
121357207Seric 				clearmode = TRUE;
121457207Seric 			else if (*p != '+')
121557207Seric 				p--;
121657207Seric 			p++;
121757207Seric 			q = p;
121858050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
121957207Seric 				p++;
122057207Seric 			if (*p != '\0')
122157207Seric 				*p++ = '\0';
122257207Seric 			for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
122357207Seric 			{
122457207Seric 				if (strcasecmp(q, rfp->rf_name) == 0)
122557207Seric 					break;
122657207Seric 			}
122764923Seric 			if (rfp->rf_name == NULL)
122864923Seric 				syserr("readcf: I option value %s unrecognized", q);
122964923Seric 			else if (clearmode)
123057207Seric 				_res.options &= ~rfp->rf_bits;
123157207Seric 			else
123257207Seric 				_res.options |= rfp->rf_bits;
123357207Seric 		}
123457207Seric 		if (tTd(8, 2))
123557207Seric 			printf("_res.options = %x\n", _res.options);
123657207Seric #else
123757207Seric 		usrerr("name server (I option) specified but BIND not compiled in");
123857207Seric #endif
123935651Seric 		break;
124035651Seric 
12418269Seric 	  case 'i':		/* ignore dot lines in message */
12429381Seric 		IgnrDot = atobool(val);
12438269Seric 		break;
12448269Seric 
124559730Seric 	  case 'j':		/* send errors in MIME (RFC 1341) format */
124659730Seric 		SendMIMEErrors = atobool(val);
124759730Seric 		break;
124859730Seric 
124957136Seric 	  case 'J':		/* .forward search path */
125057136Seric 		ForwardPath = newstr(val);
125157136Seric 		break;
125257136Seric 
125354967Seric 	  case 'k':		/* connection cache size */
125454967Seric 		MaxMciCache = atoi(val);
125556215Seric 		if (MaxMciCache < 0)
125656215Seric 			MaxMciCache = 0;
125754967Seric 		break;
125854967Seric 
125954967Seric 	  case 'K':		/* connection cache timeout */
126058796Seric 		MciCacheTimeout = convtime(val, 'm');
126154967Seric 		break;
126254967Seric 
126361104Seric 	  case 'l':		/* use Errors-To: header */
126461104Seric 		UseErrorsTo = atobool(val);
126561104Seric 		break;
126661104Seric 
12678256Seric 	  case 'L':		/* log level */
126864140Seric 		if (safe || LogLevel < atoi(val))
126964140Seric 			LogLevel = atoi(val);
12708256Seric 		break;
12718256Seric 
12728269Seric 	  case 'M':		/* define macro */
12739381Seric 		define(val[0], newstr(&val[1]), CurEnv);
127416878Seric 		sticky = FALSE;
12758269Seric 		break;
12768269Seric 
12778269Seric 	  case 'm':		/* send to me too */
12789381Seric 		MeToo = atobool(val);
12798269Seric 		break;
12808269Seric 
128125820Seric 	  case 'n':		/* validate RHS in newaliases */
128225820Seric 		CheckAliases = atobool(val);
128325820Seric 		break;
128425820Seric 
128561104Seric 	    /* 'N' available -- was "net name" */
128661104Seric 
128758851Seric 	  case 'O':		/* daemon options */
128858851Seric 		setdaemonoptions(val);
128958851Seric 		break;
129058851Seric 
12918269Seric 	  case 'o':		/* assume old style headers */
12929381Seric 		if (atobool(val))
12939341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
12949341Seric 		else
12959341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
12968269Seric 		break;
12978269Seric 
129858082Seric 	  case 'p':		/* select privacy level */
129958082Seric 		p = val;
130058082Seric 		for (;;)
130158082Seric 		{
130258082Seric 			register struct prival *pv;
130358082Seric 			extern struct prival PrivacyValues[];
130458082Seric 
130558082Seric 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
130658082Seric 				p++;
130758082Seric 			if (*p == '\0')
130858082Seric 				break;
130958082Seric 			val = p;
131058082Seric 			while (isascii(*p) && isalnum(*p))
131158082Seric 				p++;
131258082Seric 			if (*p != '\0')
131358082Seric 				*p++ = '\0';
131458082Seric 
131558082Seric 			for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
131658082Seric 			{
131758082Seric 				if (strcasecmp(val, pv->pv_name) == 0)
131858082Seric 					break;
131958082Seric 			}
132058886Seric 			if (pv->pv_name == NULL)
132158886Seric 				syserr("readcf: Op line: %s unrecognized", val);
132258082Seric 			PrivacyFlags |= pv->pv_flag;
132358082Seric 		}
132458082Seric 		break;
132558082Seric 
132624944Seric 	  case 'P':		/* postmaster copy address for returned mail */
132724944Seric 		PostMasterCopy = newstr(val);
132824944Seric 		break;
132924944Seric 
133024944Seric 	  case 'q':		/* slope of queue only function */
133124944Seric 		QueueFactor = atoi(val);
133224944Seric 		break;
133324944Seric 
13348256Seric 	  case 'Q':		/* queue directory */
13359381Seric 		if (val[0] == '\0')
13368269Seric 			QueueDir = "mqueue";
13379381Seric 		else
13389381Seric 			QueueDir = newstr(val);
133958789Seric 		if (RealUid != 0 && !safe)
134064718Seric 			Warn_Q_option = TRUE;
13418256Seric 		break;
13428256Seric 
134358148Seric 	  case 'R':		/* don't prune routes */
134458148Seric 		DontPruneRoutes = atobool(val);
134558148Seric 		break;
134658148Seric 
13478256Seric 	  case 'r':		/* read timeout */
134858112Seric 		settimeouts(val);
13498256Seric 		break;
13508256Seric 
13518256Seric 	  case 'S':		/* status file */
13529381Seric 		if (val[0] == '\0')
13538269Seric 			StatFile = "sendmail.st";
13549381Seric 		else
13559381Seric 			StatFile = newstr(val);
13568256Seric 		break;
13578256Seric 
13588265Seric 	  case 's':		/* be super safe, even if expensive */
13599381Seric 		SuperSafe = atobool(val);
13608256Seric 		break;
13618256Seric 
13628256Seric 	  case 'T':		/* queue timeout */
136358737Seric 		p = strchr(val, '/');
136458737Seric 		if (p != NULL)
136558737Seric 		{
136658737Seric 			*p++ = '\0';
136758796Seric 			TimeOuts.to_q_warning = convtime(p, 'd');
136858737Seric 		}
136958796Seric 		TimeOuts.to_q_return = convtime(val, 'h');
137054967Seric 		break;
13718256Seric 
13728265Seric 	  case 't':		/* time zone name */
137352106Seric 		TimeZoneSpec = newstr(val);
13748265Seric 		break;
13758265Seric 
137650556Seric 	  case 'U':		/* location of user database */
137751360Seric 		UdbSpec = newstr(val);
137850556Seric 		break;
137950556Seric 
13808256Seric 	  case 'u':		/* set default uid */
138164133Seric 		if (isascii(*val) && isdigit(*val))
138264133Seric 			DefUid = atoi(val);
138364133Seric 		else
138464133Seric 		{
138564133Seric 			register struct passwd *pw;
138664133Seric 
138764133Seric 			DefUid = -1;
138864133Seric 			pw = getpwnam(val);
138964133Seric 			if (pw == NULL)
139064133Seric 				syserr("readcf: option u: unknown user %s", val);
139164133Seric 			else
139264133Seric 				DefUid = pw->pw_uid;
139364133Seric 		}
139440973Sbostic 		setdefuser();
13958256Seric 		break;
13968256Seric 
139758851Seric 	  case 'V':		/* fallback MX host */
139858851Seric 		FallBackMX = newstr(val);
139958851Seric 		break;
140058851Seric 
14018269Seric 	  case 'v':		/* run in verbose mode */
14029381Seric 		Verbose = atobool(val);
14038256Seric 		break;
14048256Seric 
140563837Seric 	  case 'w':		/* if we are best MX, try host directly */
140663837Seric 		TryNullMXList = atobool(val);
140763837Seric 		break;
140861104Seric 
140961104Seric 	    /* 'W' available -- was wizard password */
141061104Seric 
141114879Seric 	  case 'x':		/* load avg at which to auto-queue msgs */
141214879Seric 		QueueLA = atoi(val);
141314879Seric 		break;
141414879Seric 
141514879Seric 	  case 'X':		/* load avg at which to auto-reject connections */
141614879Seric 		RefuseLA = atoi(val);
141714879Seric 		break;
141814879Seric 
141924981Seric 	  case 'y':		/* work recipient factor */
142024981Seric 		WkRecipFact = atoi(val);
142124981Seric 		break;
142224981Seric 
142324981Seric 	  case 'Y':		/* fork jobs during queue runs */
142424952Seric 		ForkQueueRuns = atobool(val);
142524952Seric 		break;
142624952Seric 
142724981Seric 	  case 'z':		/* work message class factor */
142824981Seric 		WkClassFact = atoi(val);
142924981Seric 		break;
143024981Seric 
143124981Seric 	  case 'Z':		/* work time factor */
143224981Seric 		WkTimeFact = atoi(val);
143324981Seric 		break;
143424981Seric 
14358256Seric 	  default:
14368256Seric 		break;
14378256Seric 	}
143816878Seric 	if (sticky)
143916878Seric 		setbitn(opt, StickyOpt);
14409188Seric 	return;
14418256Seric }
144210687Seric /*
144310687Seric **  SETCLASS -- set a word into a class
144410687Seric **
144510687Seric **	Parameters:
144610687Seric **		class -- the class to put the word in.
144710687Seric **		word -- the word to enter
144810687Seric **
144910687Seric **	Returns:
145010687Seric **		none.
145110687Seric **
145210687Seric **	Side Effects:
145310687Seric **		puts the word into the symbol table.
145410687Seric */
145510687Seric 
145610687Seric setclass(class, word)
145710687Seric 	int class;
145810687Seric 	char *word;
145910687Seric {
146010687Seric 	register STAB *s;
146110687Seric 
146257943Seric 	if (tTd(37, 8))
146364326Seric 		printf("setclass(%c, %s)\n", class, word);
146410687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
146510687Seric 	setbitn(class, s->s_class);
146610687Seric }
146753654Seric /*
146853654Seric **  MAKEMAPENTRY -- create a map entry
146953654Seric **
147053654Seric **	Parameters:
147153654Seric **		line -- the config file line
147253654Seric **
147353654Seric **	Returns:
147453654Seric **		TRUE if it successfully entered the map entry.
147553654Seric **		FALSE otherwise (usually syntax error).
147653654Seric **
147753654Seric **	Side Effects:
147853654Seric **		Enters the map into the dictionary.
147953654Seric */
148053654Seric 
148153654Seric void
148253654Seric makemapentry(line)
148353654Seric 	char *line;
148453654Seric {
148553654Seric 	register char *p;
148653654Seric 	char *mapname;
148753654Seric 	char *classname;
148864078Seric 	register STAB *s;
148953654Seric 	STAB *class;
149053654Seric 
149158050Seric 	for (p = line; isascii(*p) && isspace(*p); p++)
149253654Seric 		continue;
149358050Seric 	if (!(isascii(*p) && isalnum(*p)))
149453654Seric 	{
149553654Seric 		syserr("readcf: config K line: no map name");
149653654Seric 		return;
149753654Seric 	}
149853654Seric 
149953654Seric 	mapname = p;
150058050Seric 	while (isascii(*++p) && isalnum(*p))
150153654Seric 		continue;
150253654Seric 	if (*p != '\0')
150353654Seric 		*p++ = '\0';
150458050Seric 	while (isascii(*p) && isspace(*p))
150553654Seric 		p++;
150658050Seric 	if (!(isascii(*p) && isalnum(*p)))
150753654Seric 	{
150853654Seric 		syserr("readcf: config K line, map %s: no map class", mapname);
150953654Seric 		return;
151053654Seric 	}
151153654Seric 	classname = p;
151258050Seric 	while (isascii(*++p) && isalnum(*p))
151353654Seric 		continue;
151453654Seric 	if (*p != '\0')
151553654Seric 		*p++ = '\0';
151658050Seric 	while (isascii(*p) && isspace(*p))
151753654Seric 		p++;
151853654Seric 
151953654Seric 	/* look up the class */
152053654Seric 	class = stab(classname, ST_MAPCLASS, ST_FIND);
152153654Seric 	if (class == NULL)
152253654Seric 	{
152353654Seric 		syserr("readcf: map %s: class %s not available", mapname, classname);
152453654Seric 		return;
152553654Seric 	}
152653654Seric 
152753654Seric 	/* enter the map */
152864078Seric 	s = stab(mapname, ST_MAP, ST_ENTER);
152964078Seric 	s->s_map.map_class = &class->s_mapclass;
153064078Seric 	s->s_map.map_mname = newstr(mapname);
153153654Seric 
153264078Seric 	if (class->s_mapclass.map_parse(&s->s_map, p))
153364078Seric 		s->s_map.map_mflags |= MF_VALID;
153464078Seric 
153564078Seric 	if (tTd(37, 5))
153664078Seric 	{
153764078Seric 		printf("map %s, class %s, flags %x, file %s,\n",
153864078Seric 			s->s_map.map_mname, s->s_map.map_class->map_cname,
153964078Seric 			s->s_map.map_mflags,
154064078Seric 			s->s_map.map_file == NULL ? "(null)" : s->s_map.map_file);
154164078Seric 		printf("\tapp %s, domain %s, rebuild %s\n",
154264078Seric 			s->s_map.map_app == NULL ? "(null)" : s->s_map.map_app,
154364078Seric 			s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain,
154464078Seric 			s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild);
154564078Seric 	}
154653654Seric }
154758112Seric /*
154858112Seric **  SETTIMEOUTS -- parse and set timeout values
154958112Seric **
155058112Seric **	Parameters:
155158112Seric **		val -- a pointer to the values.  If NULL, do initial
155258112Seric **			settings.
155358112Seric **
155458112Seric **	Returns:
155558112Seric **		none.
155658112Seric **
155758112Seric **	Side Effects:
155858112Seric **		Initializes the TimeOuts structure
155958112Seric */
156058112Seric 
156164255Seric #define SECONDS
156258112Seric #define MINUTES	* 60
156358112Seric #define HOUR	* 3600
156458112Seric 
156558112Seric settimeouts(val)
156658112Seric 	register char *val;
156758112Seric {
156858112Seric 	register char *p;
156958671Seric 	extern time_t convtime();
157058112Seric 
157158112Seric 	if (val == NULL)
157258112Seric 	{
157358112Seric 		TimeOuts.to_initial = (time_t) 5 MINUTES;
157458112Seric 		TimeOuts.to_helo = (time_t) 5 MINUTES;
157558112Seric 		TimeOuts.to_mail = (time_t) 10 MINUTES;
157658112Seric 		TimeOuts.to_rcpt = (time_t) 1 HOUR;
157758112Seric 		TimeOuts.to_datainit = (time_t) 5 MINUTES;
157858112Seric 		TimeOuts.to_datablock = (time_t) 1 HOUR;
157958112Seric 		TimeOuts.to_datafinal = (time_t) 1 HOUR;
158058112Seric 		TimeOuts.to_rset = (time_t) 5 MINUTES;
158158112Seric 		TimeOuts.to_quit = (time_t) 2 MINUTES;
158258112Seric 		TimeOuts.to_nextcommand = (time_t) 1 HOUR;
158358112Seric 		TimeOuts.to_miscshort = (time_t) 2 MINUTES;
158464255Seric 		TimeOuts.to_ident = (time_t) 30 SECONDS;
158558112Seric 		return;
158658112Seric 	}
158758112Seric 
158858112Seric 	for (;; val = p)
158958112Seric 	{
159058112Seric 		while (isascii(*val) && isspace(*val))
159158112Seric 			val++;
159258112Seric 		if (*val == '\0')
159358112Seric 			break;
159458112Seric 		for (p = val; *p != '\0' && *p != ','; p++)
159558112Seric 			continue;
159658112Seric 		if (*p != '\0')
159758112Seric 			*p++ = '\0';
159858112Seric 
159958112Seric 		if (isascii(*val) && isdigit(*val))
160058112Seric 		{
160158112Seric 			/* old syntax -- set everything */
160258796Seric 			TimeOuts.to_mail = convtime(val, 'm');
160358112Seric 			TimeOuts.to_rcpt = TimeOuts.to_mail;
160458112Seric 			TimeOuts.to_datainit = TimeOuts.to_mail;
160558112Seric 			TimeOuts.to_datablock = TimeOuts.to_mail;
160658112Seric 			TimeOuts.to_datafinal = TimeOuts.to_mail;
160758112Seric 			TimeOuts.to_nextcommand = TimeOuts.to_mail;
160858112Seric 			continue;
160958112Seric 		}
161058112Seric 		else
161158112Seric 		{
161258112Seric 			register char *q = strchr(val, '=');
161358112Seric 			time_t to;
161458112Seric 
161558112Seric 			if (q == NULL)
161658112Seric 			{
161758112Seric 				/* syntax error */
161858112Seric 				continue;
161958112Seric 			}
162058112Seric 			*q++ = '\0';
162158796Seric 			to = convtime(q, 'm');
162258112Seric 
162358112Seric 			if (strcasecmp(val, "initial") == 0)
162458112Seric 				TimeOuts.to_initial = to;
162558112Seric 			else if (strcasecmp(val, "mail") == 0)
162658112Seric 				TimeOuts.to_mail = to;
162758112Seric 			else if (strcasecmp(val, "rcpt") == 0)
162858112Seric 				TimeOuts.to_rcpt = to;
162958112Seric 			else if (strcasecmp(val, "datainit") == 0)
163058112Seric 				TimeOuts.to_datainit = to;
163158112Seric 			else if (strcasecmp(val, "datablock") == 0)
163258112Seric 				TimeOuts.to_datablock = to;
163358112Seric 			else if (strcasecmp(val, "datafinal") == 0)
163458112Seric 				TimeOuts.to_datafinal = to;
163558112Seric 			else if (strcasecmp(val, "command") == 0)
163658112Seric 				TimeOuts.to_nextcommand = to;
163758112Seric 			else if (strcasecmp(val, "rset") == 0)
163858112Seric 				TimeOuts.to_rset = to;
163958112Seric 			else if (strcasecmp(val, "helo") == 0)
164058112Seric 				TimeOuts.to_helo = to;
164158112Seric 			else if (strcasecmp(val, "quit") == 0)
164258112Seric 				TimeOuts.to_quit = to;
164358112Seric 			else if (strcasecmp(val, "misc") == 0)
164458112Seric 				TimeOuts.to_miscshort = to;
164564255Seric 			else if (strcasecmp(val, "ident") == 0)
164664255Seric 				TimeOuts.to_ident = to;
164758112Seric 			else
164858112Seric 				syserr("settimeouts: invalid timeout %s", val);
164958112Seric 		}
165058112Seric 	}
165158112Seric }
1652