xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 64440)
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*64440Seric static char sccsid[] = "@(#)readcf.c	8.12 (Berkeley) 09/05/93";
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.
4752645Seric **		Vversioncode	Version level of configuration syntax.
4853654Seric **		Kmapname mapclass arguments....
4953654Seric **				Define keyed lookup of a given class.
5053654Seric **				Arguments are class dependent.
514432Seric **
523308Seric **	Parameters:
533308Seric **		cfname -- control file name.
5454973Seric **		safe -- TRUE if this is the system config file;
5554973Seric **			FALSE otherwise.
5655012Seric **		e -- the main envelope.
573308Seric **
583308Seric **	Returns:
593308Seric **		none.
603308Seric **
613308Seric **	Side Effects:
623308Seric **		Builds several internal tables.
633308Seric */
643308Seric 
6555012Seric readcf(cfname, safe, e)
663308Seric 	char *cfname;
6754973Seric 	bool safe;
6855012Seric 	register ENVELOPE *e;
693308Seric {
703308Seric 	FILE *cf;
718547Seric 	int ruleset = 0;
728547Seric 	char *q;
739350Seric 	struct rewrite *rwp = NULL;
7457135Seric 	char *bp;
7557589Seric 	int nfuzzy;
7664133Seric 	char *file;
7764133Seric 	bool optional;
783308Seric 	char buf[MAXLINE];
793308Seric 	register char *p;
803308Seric 	extern char **copyplist();
8152647Seric 	struct stat statb;
825909Seric 	char exbuf[MAXLINE];
8316915Seric 	char pvpbuf[PSBUFSIZE];
8410709Seric 	extern char *munchstring();
8553654Seric 	extern void makemapentry();
863308Seric 
8752647Seric 	FileName = cfname;
8852647Seric 	LineNumber = 0;
8952647Seric 
903308Seric 	cf = fopen(cfname, "r");
913308Seric 	if (cf == NULL)
923308Seric 	{
9352647Seric 		syserr("cannot open");
943308Seric 		exit(EX_OSFILE);
953308Seric 	}
963308Seric 
9752647Seric 	if (fstat(fileno(cf), &statb) < 0)
9852647Seric 	{
9952647Seric 		syserr("cannot fstat");
10052647Seric 		exit(EX_OSFILE);
10152647Seric 	}
10252647Seric 
10352647Seric 	if (!S_ISREG(statb.st_mode))
10452647Seric 	{
10552647Seric 		syserr("not a plain file");
10652647Seric 		exit(EX_OSFILE);
10752647Seric 	}
10852647Seric 
10952647Seric 	if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
11052647Seric 	{
11153037Seric 		if (OpMode == MD_DAEMON || OpMode == MD_FREEZE)
11253037Seric 			fprintf(stderr, "%s: WARNING: dangerous write permissions\n",
11353037Seric 				FileName);
11453037Seric #ifdef LOG
11553037Seric 		if (LogLevel > 0)
11653037Seric 			syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions",
11753037Seric 				FileName);
11853037Seric #endif
11952647Seric 	}
12052647Seric 
12159254Seric #ifdef XLA
12259254Seric 	xla_zero();
12359254Seric #endif
12459254Seric 
12557135Seric 	while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL)
1263308Seric 	{
12757135Seric 		if (bp[0] == '#')
12857135Seric 		{
12957135Seric 			if (bp != buf)
13057135Seric 				free(bp);
13152637Seric 			continue;
13257135Seric 		}
13352637Seric 
13458050Seric 		/* map $ into \201 for macro expansion */
13557135Seric 		for (p = bp; *p != '\0'; p++)
13616157Seric 		{
13757135Seric 			if (*p == '#' && p > bp && ConfigLevel >= 3)
13852647Seric 			{
13952647Seric 				/* this is an on-line comment */
14052647Seric 				register char *e;
14152647Seric 
14258050Seric 				switch (*--p & 0377)
14352647Seric 				{
14458050Seric 				  case MACROEXPAND:
14552647Seric 					/* it's from $# -- let it go through */
14652647Seric 					p++;
14752647Seric 					break;
14852647Seric 
14952647Seric 				  case '\\':
15052647Seric 					/* it's backslash escaped */
15152647Seric 					(void) strcpy(p, p + 1);
15252647Seric 					break;
15352647Seric 
15452647Seric 				  default:
15552647Seric 					/* delete preceeding white space */
15658050Seric 					while (isascii(*p) && isspace(*p) && p > bp)
15752647Seric 						p--;
15856795Seric 					if ((e = strchr(++p, '\n')) != NULL)
15952647Seric 						(void) strcpy(p, e);
16052647Seric 					else
16152647Seric 						p[0] = p[1] = '\0';
16252647Seric 					break;
16352647Seric 				}
16452647Seric 				continue;
16552647Seric 			}
16652647Seric 
16716157Seric 			if (*p != '$')
16816157Seric 				continue;
16916157Seric 
17016157Seric 			if (p[1] == '$')
17116157Seric 			{
17216157Seric 				/* actual dollar sign.... */
17323111Seric 				(void) strcpy(p, p + 1);
17416157Seric 				continue;
17516157Seric 			}
17616157Seric 
17716157Seric 			/* convert to macro expansion character */
17858050Seric 			*p = MACROEXPAND;
17916157Seric 		}
18016157Seric 
18116157Seric 		/* interpret this line */
18257135Seric 		switch (bp[0])
1833308Seric 		{
1843308Seric 		  case '\0':
1853308Seric 		  case '#':		/* comment */
1863308Seric 			break;
1873308Seric 
1883308Seric 		  case 'R':		/* rewriting rule */
18957135Seric 			for (p = &bp[1]; *p != '\0' && *p != '\t'; p++)
1903308Seric 				continue;
1913308Seric 
1923308Seric 			if (*p == '\0')
1935909Seric 			{
19457135Seric 				syserr("invalid rewrite line \"%s\"", bp);
1955909Seric 				break;
1965909Seric 			}
1975909Seric 
1985909Seric 			/* allocate space for the rule header */
1995909Seric 			if (rwp == NULL)
2005909Seric 			{
2015909Seric 				RewriteRules[ruleset] = rwp =
2025909Seric 					(struct rewrite *) xalloc(sizeof *rwp);
2035909Seric 			}
2043308Seric 			else
2053308Seric 			{
2065909Seric 				rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
2075909Seric 				rwp = rwp->r_next;
2085909Seric 			}
2095909Seric 			rwp->r_next = NULL;
2103308Seric 
2115909Seric 			/* expand and save the LHS */
2125909Seric 			*p = '\0';
21357135Seric 			expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e);
21458333Seric 			rwp->r_lhs = prescan(exbuf, '\t', pvpbuf, NULL);
21557589Seric 			nfuzzy = 0;
2165909Seric 			if (rwp->r_lhs != NULL)
21757589Seric 			{
21857589Seric 				register char **ap;
21957589Seric 
2205909Seric 				rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
22157589Seric 
22257589Seric 				/* count the number of fuzzy matches in LHS */
22357589Seric 				for (ap = rwp->r_lhs; *ap != NULL; ap++)
22457589Seric 				{
22558148Seric 					char *botch;
22658148Seric 
22758148Seric 					botch = NULL;
22858050Seric 					switch (**ap & 0377)
22957589Seric 					{
23057589Seric 					  case MATCHZANY:
23157589Seric 					  case MATCHANY:
23257589Seric 					  case MATCHONE:
23357589Seric 					  case MATCHCLASS:
23457589Seric 					  case MATCHNCLASS:
23557589Seric 						nfuzzy++;
23658148Seric 						break;
23758148Seric 
23858148Seric 					  case MATCHREPL:
23958148Seric 						botch = "$0-$9";
24058148Seric 						break;
24158148Seric 
24258148Seric 					  case CANONNET:
24358148Seric 						botch = "$#";
24458148Seric 						break;
24558148Seric 
24658148Seric 					  case CANONUSER:
24758148Seric 						botch = "$:";
24858148Seric 						break;
24958148Seric 
25058148Seric 					  case CALLSUBR:
25158148Seric 						botch = "$>";
25258148Seric 						break;
25358148Seric 
25458148Seric 					  case CONDIF:
25558148Seric 						botch = "$?";
25658148Seric 						break;
25758148Seric 
25858148Seric 					  case CONDELSE:
25958148Seric 						botch = "$|";
26058148Seric 						break;
26158148Seric 
26258148Seric 					  case CONDFI:
26358148Seric 						botch = "$.";
26458148Seric 						break;
26558148Seric 
26658148Seric 					  case HOSTBEGIN:
26758148Seric 						botch = "$[";
26858148Seric 						break;
26958148Seric 
27058148Seric 					  case HOSTEND:
27158148Seric 						botch = "$]";
27258148Seric 						break;
27358148Seric 
27458148Seric 					  case LOOKUPBEGIN:
27558148Seric 						botch = "$(";
27658148Seric 						break;
27758148Seric 
27858148Seric 					  case LOOKUPEND:
27958148Seric 						botch = "$)";
28058148Seric 						break;
28157589Seric 					}
28258148Seric 					if (botch != NULL)
28358148Seric 						syserr("Inappropriate use of %s on LHS",
28458148Seric 							botch);
28557589Seric 				}
28657589Seric 			}
28756678Seric 			else
28856678Seric 				syserr("R line: null LHS");
2895909Seric 
2905909Seric 			/* expand and save the RHS */
2915909Seric 			while (*++p == '\t')
2925909Seric 				continue;
2937231Seric 			q = p;
2947231Seric 			while (*p != '\0' && *p != '\t')
2957231Seric 				p++;
2967231Seric 			*p = '\0';
29755012Seric 			expand(q, exbuf, &exbuf[sizeof exbuf], e);
29858333Seric 			rwp->r_rhs = prescan(exbuf, '\t', pvpbuf, NULL);
2995909Seric 			if (rwp->r_rhs != NULL)
30057589Seric 			{
30157589Seric 				register char **ap;
30257589Seric 
3035909Seric 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
30457589Seric 
30557589Seric 				/* check no out-of-bounds replacements */
30657589Seric 				nfuzzy += '0';
30757589Seric 				for (ap = rwp->r_rhs; *ap != NULL; ap++)
30857589Seric 				{
30958148Seric 					char *botch;
31058148Seric 
31158148Seric 					botch = NULL;
31258148Seric 					switch (**ap & 0377)
31357589Seric 					{
31458148Seric 					  case MATCHREPL:
31558148Seric 						if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy)
31658148Seric 						{
31758148Seric 							syserr("replacement $%c out of bounds",
31858148Seric 								(*ap)[1]);
31958148Seric 						}
32058148Seric 						break;
32158148Seric 
32258148Seric 					  case MATCHZANY:
32358148Seric 						botch = "$*";
32458148Seric 						break;
32558148Seric 
32658148Seric 					  case MATCHANY:
32758148Seric 						botch = "$+";
32858148Seric 						break;
32958148Seric 
33058148Seric 					  case MATCHONE:
33158148Seric 						botch = "$-";
33258148Seric 						break;
33358148Seric 
33458148Seric 					  case MATCHCLASS:
33558148Seric 						botch = "$=";
33658148Seric 						break;
33758148Seric 
33858148Seric 					  case MATCHNCLASS:
33958148Seric 						botch = "$~";
34058148Seric 						break;
34157589Seric 					}
34258148Seric 					if (botch != NULL)
34358148Seric 						syserr("Inappropriate use of %s on RHS",
34458148Seric 							botch);
34557589Seric 				}
34657589Seric 			}
34756678Seric 			else
34856678Seric 				syserr("R line: null RHS");
3493308Seric 			break;
3503308Seric 
3514072Seric 		  case 'S':		/* select rewriting set */
352*64440Seric 			for (p = &bp[1]; isascii(*p) && isspace(*p); p++)
353*64440Seric 				continue;
354*64440Seric 			if (!isascii(*p) || !isdigit(*p))
355*64440Seric 			{
356*64440Seric 				syserr("invalid argument to S line: \"%.20s\"",
357*64440Seric 					&bp[1]);
358*64440Seric 				break;
359*64440Seric 			}
360*64440Seric 			ruleset = atoi(p);
3618056Seric 			if (ruleset >= MAXRWSETS || ruleset < 0)
3628056Seric 			{
3639381Seric 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
3648056Seric 				ruleset = 0;
3658056Seric 			}
3664072Seric 			rwp = NULL;
3674072Seric 			break;
3684072Seric 
3693308Seric 		  case 'D':		/* macro definition */
37064086Seric 			p = munchstring(&bp[2], NULL);
37164086Seric 			define(bp[1], newstr(p), e);
3723308Seric 			break;
3733308Seric 
3743387Seric 		  case 'H':		/* required header line */
37557135Seric 			(void) chompheader(&bp[1], TRUE, e);
3763387Seric 			break;
3773387Seric 
3784061Seric 		  case 'C':		/* word class */
3794432Seric 			/* scan the list of words and set class for all */
38064121Seric 			expand(&bp[2], exbuf, &exbuf[sizeof exbuf], e);
38164121Seric 			for (p = exbuf; *p != '\0'; )
3824061Seric 			{
3834061Seric 				register char *wd;
3844061Seric 				char delim;
3854061Seric 
38658050Seric 				while (*p != '\0' && isascii(*p) && isspace(*p))
3874061Seric 					p++;
3884061Seric 				wd = p;
38958050Seric 				while (*p != '\0' && !(isascii(*p) && isspace(*p)))
3904061Seric 					p++;
3914061Seric 				delim = *p;
3924061Seric 				*p = '\0';
3934061Seric 				if (wd[0] != '\0')
39457135Seric 					setclass(bp[1], wd);
3954061Seric 				*p = delim;
3964061Seric 			}
3974061Seric 			break;
3984061Seric 
39959272Seric 		  case 'F':		/* word class from file */
40064133Seric 			for (p = &bp[2]; isascii(*p) && isspace(*p); )
40164133Seric 				p++;
40264133Seric 			if (p[0] == '-' && p[1] == 'o')
40364133Seric 			{
40464133Seric 				optional = TRUE;
40564133Seric 				while (*p != '\0' && !(isascii(*p) && isspace(*p)))
40664133Seric 					p++;
40764133Seric 				while (isascii(*p) && isspace(*p))
40864133Seric 					*p++;
40964133Seric 			}
41064133Seric 			else
41164133Seric 				optional = FALSE;
41264133Seric 			file = p;
41364133Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
41464133Seric 				p++;
41559272Seric 			if (*p == '\0')
41659272Seric 				p = "%s";
41759272Seric 			else
41859272Seric 			{
41959272Seric 				*p = '\0';
42059272Seric 				while (isascii(*++p) && isspace(*p))
42159272Seric 					continue;
42259272Seric 			}
42364133Seric 			fileclass(bp[1], file, p, safe, optional);
42459272Seric 			break;
42559272Seric 
42659156Seric #ifdef XLA
42759156Seric 		  case 'L':		/* extended load average description */
42859156Seric 			xla_init(&bp[1]);
42959156Seric 			break;
43059156Seric #endif
43159156Seric 
4324096Seric 		  case 'M':		/* define mailer */
43357135Seric 			makemailer(&bp[1]);
4344096Seric 			break;
4354096Seric 
4368252Seric 		  case 'O':		/* set option */
43758734Seric 			setoption(bp[1], &bp[2], safe, FALSE, e);
4388252Seric 			break;
4398252Seric 
4408252Seric 		  case 'P':		/* set precedence */
4418252Seric 			if (NumPriorities >= MAXPRIORITIES)
4428252Seric 			{
4438547Seric 				toomany('P', MAXPRIORITIES);
4448252Seric 				break;
4458252Seric 			}
44657135Seric 			for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
4478252Seric 				continue;
4488252Seric 			if (*p == '\0')
4498252Seric 				goto badline;
4508252Seric 			*p = '\0';
45157135Seric 			Priorities[NumPriorities].pri_name = newstr(&bp[1]);
4528252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
4538252Seric 			NumPriorities++;
4548252Seric 			break;
4558252Seric 
4568547Seric 		  case 'T':		/* trusted user(s) */
45758161Seric 			/* this option is obsolete, but will be ignored */
4588547Seric 			break;
4598547Seric 
46052645Seric 		  case 'V':		/* configuration syntax version */
461*64440Seric 			for (p = &bp[1]; isascii(*p) && isspace(*p); p++)
462*64440Seric 				continue;
463*64440Seric 			if (!isascii(*p) || !isdigit(*p))
464*64440Seric 			{
465*64440Seric 				syserr("invalid argument to V line: \"%.20s\"",
466*64440Seric 					&bp[1]);
467*64440Seric 				break;
468*64440Seric 			}
469*64440Seric 			ConfigLevel = atoi(p);
47064279Seric 			if (ConfigLevel >= 5)
47164279Seric 			{
47264279Seric 				/* level 5 configs have short name in $w */
47364279Seric 				p = macvalue('w', e);
47464279Seric 				if (p != NULL && (p = strchr(p, '.')) != NULL)
47564279Seric 					*p = '\0';
47664279Seric 			}
47752645Seric 			break;
47852645Seric 
47953654Seric 		  case 'K':
48057135Seric 			makemapentry(&bp[1]);
48153654Seric 			break;
48253654Seric 
4833308Seric 		  default:
4844061Seric 		  badline:
48557135Seric 			syserr("unknown control line \"%s\"", bp);
4863308Seric 		}
48757135Seric 		if (bp != buf)
48857135Seric 			free(bp);
4893308Seric 	}
49052637Seric 	if (ferror(cf))
49152637Seric 	{
49252647Seric 		syserr("I/O read error", cfname);
49352637Seric 		exit(EX_OSFILE);
49452637Seric 	}
49552637Seric 	fclose(cf);
4969381Seric 	FileName = NULL;
49756836Seric 
49857076Seric 	if (stab("host", ST_MAP, ST_FIND) == NULL)
49957076Seric 	{
50057076Seric 		/* user didn't initialize: set up host map */
50157076Seric 		strcpy(buf, "host host");
50257076Seric 		if (ConfigLevel >= 2)
50357076Seric 			strcat(buf, " -a.");
50457076Seric 		makemapentry(buf);
50557076Seric 	}
5064096Seric }
5074096Seric /*
5088547Seric **  TOOMANY -- signal too many of some option
5098547Seric **
5108547Seric **	Parameters:
5118547Seric **		id -- the id of the error line
5128547Seric **		maxcnt -- the maximum possible values
5138547Seric **
5148547Seric **	Returns:
5158547Seric **		none.
5168547Seric **
5178547Seric **	Side Effects:
5188547Seric **		gives a syserr.
5198547Seric */
5208547Seric 
5218547Seric toomany(id, maxcnt)
5228547Seric 	char id;
5238547Seric 	int maxcnt;
5248547Seric {
5259381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
5268547Seric }
5278547Seric /*
5284432Seric **  FILECLASS -- read members of a class from a file
5294432Seric **
5304432Seric **	Parameters:
5314432Seric **		class -- class to define.
5324432Seric **		filename -- name of file to read.
5334432Seric **		fmt -- scanf string to use for match.
53464133Seric **		safe -- if set, this is a safe read.
53564133Seric **		optional -- if set, it is not an error for the file to
53664133Seric **			not exist.
5374432Seric **
5384432Seric **	Returns:
5394432Seric **		none
5404432Seric **
5414432Seric **	Side Effects:
5424432Seric **
5434432Seric **		puts all lines in filename that match a scanf into
5444432Seric **			the named class.
5454432Seric */
5464432Seric 
54764133Seric fileclass(class, filename, fmt, safe, optional)
5484432Seric 	int class;
5494432Seric 	char *filename;
5504432Seric 	char *fmt;
55154973Seric 	bool safe;
55264133Seric 	bool optional;
5534432Seric {
55425808Seric 	FILE *f;
55554973Seric 	struct stat stbuf;
5564432Seric 	char buf[MAXLINE];
5574432Seric 
55854973Seric 	if (stat(filename, &stbuf) < 0)
55954973Seric 	{
56064133Seric 		if (!optional)
56164133Seric 			syserr("fileclass: cannot stat %s", filename);
56254973Seric 		return;
56354973Seric 	}
56454973Seric 	if (!S_ISREG(stbuf.st_mode))
56554973Seric 	{
56654973Seric 		syserr("fileclass: %s not a regular file", filename);
56754973Seric 		return;
56854973Seric 	}
56954973Seric 	if (!safe && access(filename, R_OK) < 0)
57054973Seric 	{
57154973Seric 		syserr("fileclass: access denied on %s", filename);
57254973Seric 		return;
57354973Seric 	}
57454973Seric 	f = fopen(filename, "r");
5754432Seric 	if (f == NULL)
5764432Seric 	{
57754973Seric 		syserr("fileclass: cannot open %s", filename);
5784432Seric 		return;
5794432Seric 	}
5804432Seric 
5814432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
5824432Seric 	{
5834432Seric 		register STAB *s;
58425808Seric 		register char *p;
58525808Seric # ifdef SCANF
5864432Seric 		char wordbuf[MAXNAME+1];
5874432Seric 
5884432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
5894432Seric 			continue;
59025808Seric 		p = wordbuf;
59156795Seric # else /* SCANF */
59225808Seric 		p = buf;
59356795Seric # endif /* SCANF */
59425808Seric 
59525808Seric 		/*
59625808Seric 		**  Break up the match into words.
59725808Seric 		*/
59825808Seric 
59925808Seric 		while (*p != '\0')
60025808Seric 		{
60125808Seric 			register char *q;
60225808Seric 
60325808Seric 			/* strip leading spaces */
60458050Seric 			while (isascii(*p) && isspace(*p))
60525808Seric 				p++;
60625808Seric 			if (*p == '\0')
60725808Seric 				break;
60825808Seric 
60925808Seric 			/* find the end of the word */
61025808Seric 			q = p;
61158050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
61225808Seric 				p++;
61325808Seric 			if (*p != '\0')
61425808Seric 				*p++ = '\0';
61525808Seric 
61625808Seric 			/* enter the word in the symbol table */
61725808Seric 			s = stab(q, ST_CLASS, ST_ENTER);
61825808Seric 			setbitn(class, s->s_class);
61925808Seric 		}
6204432Seric 	}
6214432Seric 
62254973Seric 	(void) fclose(f);
6234432Seric }
6244432Seric /*
6254096Seric **  MAKEMAILER -- define a new mailer.
6264096Seric **
6274096Seric **	Parameters:
62810327Seric **		line -- description of mailer.  This is in labeled
62910327Seric **			fields.  The fields are:
63010327Seric **			   P -- the path to the mailer
63110327Seric **			   F -- the flags associated with the mailer
63210327Seric **			   A -- the argv for this mailer
63310327Seric **			   S -- the sender rewriting set
63410327Seric **			   R -- the recipient rewriting set
63510327Seric **			   E -- the eol string
63610327Seric **			The first word is the canonical name of the mailer.
6374096Seric **
6384096Seric **	Returns:
6394096Seric **		none.
6404096Seric **
6414096Seric **	Side Effects:
6424096Seric **		enters the mailer into the mailer table.
6434096Seric */
6443308Seric 
64521066Seric makemailer(line)
6464096Seric 	char *line;
6474096Seric {
6484096Seric 	register char *p;
6498067Seric 	register struct mailer *m;
6508067Seric 	register STAB *s;
6518067Seric 	int i;
65210327Seric 	char fcode;
65358020Seric 	auto char *endp;
6544096Seric 	extern int NextMailer;
65510327Seric 	extern char **makeargv();
65610327Seric 	extern char *munchstring();
65710701Seric 	extern long atol();
6584096Seric 
65910327Seric 	/* allocate a mailer and set up defaults */
66010327Seric 	m = (struct mailer *) xalloc(sizeof *m);
66110327Seric 	bzero((char *) m, sizeof *m);
66210327Seric 	m->m_eol = "\n";
66310327Seric 
66410327Seric 	/* collect the mailer name */
66558050Seric 	for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++)
66610327Seric 		continue;
66710327Seric 	if (*p != '\0')
66810327Seric 		*p++ = '\0';
66910327Seric 	m->m_name = newstr(line);
67010327Seric 
67110327Seric 	/* now scan through and assign info from the fields */
67210327Seric 	while (*p != '\0')
67310327Seric 	{
67458333Seric 		auto char *delimptr;
67558333Seric 
67658050Seric 		while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p))))
67710327Seric 			p++;
67810327Seric 
67910327Seric 		/* p now points to field code */
68010327Seric 		fcode = *p;
68110327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
68210327Seric 			p++;
68310327Seric 		if (*p++ != '=')
68410327Seric 		{
68552637Seric 			syserr("mailer %s: `=' expected", m->m_name);
68610327Seric 			return;
68710327Seric 		}
68858050Seric 		while (isascii(*p) && isspace(*p))
68910327Seric 			p++;
69010327Seric 
69110327Seric 		/* p now points to the field body */
69258333Seric 		p = munchstring(p, &delimptr);
69310327Seric 
69410327Seric 		/* install the field into the mailer struct */
69510327Seric 		switch (fcode)
69610327Seric 		{
69710327Seric 		  case 'P':		/* pathname */
69810327Seric 			m->m_mailer = newstr(p);
69910327Seric 			break;
70010327Seric 
70110327Seric 		  case 'F':		/* flags */
70210687Seric 			for (; *p != '\0'; p++)
70358050Seric 				if (!(isascii(*p) && isspace(*p)))
70452637Seric 					setbitn(*p, m->m_flags);
70510327Seric 			break;
70610327Seric 
70710327Seric 		  case 'S':		/* sender rewriting ruleset */
70810327Seric 		  case 'R':		/* recipient rewriting ruleset */
70958020Seric 			i = strtol(p, &endp, 10);
71010327Seric 			if (i < 0 || i >= MAXRWSETS)
71110327Seric 			{
71210327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
71310327Seric 				return;
71410327Seric 			}
71510327Seric 			if (fcode == 'S')
71658020Seric 				m->m_sh_rwset = m->m_se_rwset = i;
71710327Seric 			else
71858020Seric 				m->m_rh_rwset = m->m_re_rwset = i;
71958020Seric 
72058020Seric 			p = endp;
72159985Seric 			if (*p++ == '/')
72258020Seric 			{
72358020Seric 				i = strtol(p, NULL, 10);
72458020Seric 				if (i < 0 || i >= MAXRWSETS)
72558020Seric 				{
72658020Seric 					syserr("invalid rewrite set, %d max",
72758020Seric 						MAXRWSETS);
72858020Seric 					return;
72958020Seric 				}
73058020Seric 				if (fcode == 'S')
73158020Seric 					m->m_sh_rwset = i;
73258020Seric 				else
73358020Seric 					m->m_rh_rwset = i;
73458020Seric 			}
73510327Seric 			break;
73610327Seric 
73710327Seric 		  case 'E':		/* end of line string */
73810327Seric 			m->m_eol = newstr(p);
73910327Seric 			break;
74010327Seric 
74110327Seric 		  case 'A':		/* argument vector */
74210327Seric 			m->m_argv = makeargv(p);
74310327Seric 			break;
74410701Seric 
74510701Seric 		  case 'M':		/* maximum message size */
74610701Seric 			m->m_maxsize = atol(p);
74710701Seric 			break;
74852106Seric 
74952106Seric 		  case 'L':		/* maximum line length */
75052106Seric 			m->m_linelimit = atoi(p);
75152106Seric 			break;
75258935Seric 
75358935Seric 		  case 'D':		/* working directory */
75458935Seric 			m->m_execdir = newstr(p);
75558935Seric 			break;
75610327Seric 		}
75710327Seric 
75858333Seric 		p = delimptr;
75910327Seric 	}
76010327Seric 
76152106Seric 	/* do some heuristic cleanup for back compatibility */
76252106Seric 	if (bitnset(M_LIMITS, m->m_flags))
76352106Seric 	{
76452106Seric 		if (m->m_linelimit == 0)
76552106Seric 			m->m_linelimit = SMTPLINELIM;
76655418Seric 		if (ConfigLevel < 2)
76752106Seric 			setbitn(M_7BITS, m->m_flags);
76852106Seric 	}
76952106Seric 
77058321Seric 	/* do some rationality checking */
77158321Seric 	if (m->m_argv == NULL)
77258321Seric 	{
77358321Seric 		syserr("M%s: A= argument required", m->m_name);
77458321Seric 		return;
77558321Seric 	}
77658321Seric 	if (m->m_mailer == NULL)
77758321Seric 	{
77858321Seric 		syserr("M%s: P= argument required", m->m_name);
77958321Seric 		return;
78058321Seric 	}
78158321Seric 
7824096Seric 	if (NextMailer >= MAXMAILERS)
7834096Seric 	{
7849381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
7854096Seric 		return;
7864096Seric 	}
78757402Seric 
78810327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
78957402Seric 	if (s->s_mailer != NULL)
79057402Seric 	{
79157402Seric 		i = s->s_mailer->m_mno;
79257402Seric 		free(s->s_mailer);
79357402Seric 	}
79457402Seric 	else
79557402Seric 	{
79657402Seric 		i = NextMailer++;
79757402Seric 	}
79857402Seric 	Mailer[i] = s->s_mailer = m;
79957454Seric 	m->m_mno = i;
80010327Seric }
80110327Seric /*
80210327Seric **  MUNCHSTRING -- translate a string into internal form.
80310327Seric **
80410327Seric **	Parameters:
80510327Seric **		p -- the string to munch.
80658333Seric **		delimptr -- if non-NULL, set to the pointer of the
80758333Seric **			field delimiter character.
80810327Seric **
80910327Seric **	Returns:
81010327Seric **		the munched string.
81110327Seric */
8124096Seric 
81310327Seric char *
81458333Seric munchstring(p, delimptr)
81510327Seric 	register char *p;
81658333Seric 	char **delimptr;
81710327Seric {
81810327Seric 	register char *q;
81910327Seric 	bool backslash = FALSE;
82010327Seric 	bool quotemode = FALSE;
82110327Seric 	static char buf[MAXLINE];
8224096Seric 
82310327Seric 	for (q = buf; *p != '\0'; p++)
8244096Seric 	{
82510327Seric 		if (backslash)
82610327Seric 		{
82710327Seric 			/* everything is roughly literal */
82810357Seric 			backslash = FALSE;
82910327Seric 			switch (*p)
83010327Seric 			{
83110327Seric 			  case 'r':		/* carriage return */
83210327Seric 				*q++ = '\r';
83310327Seric 				continue;
83410327Seric 
83510327Seric 			  case 'n':		/* newline */
83610327Seric 				*q++ = '\n';
83710327Seric 				continue;
83810327Seric 
83910327Seric 			  case 'f':		/* form feed */
84010327Seric 				*q++ = '\f';
84110327Seric 				continue;
84210327Seric 
84310327Seric 			  case 'b':		/* backspace */
84410327Seric 				*q++ = '\b';
84510327Seric 				continue;
84610327Seric 			}
84710327Seric 			*q++ = *p;
84810327Seric 		}
84910327Seric 		else
85010327Seric 		{
85110327Seric 			if (*p == '\\')
85210327Seric 				backslash = TRUE;
85310327Seric 			else if (*p == '"')
85410327Seric 				quotemode = !quotemode;
85510327Seric 			else if (quotemode || *p != ',')
85610327Seric 				*q++ = *p;
85710327Seric 			else
85810327Seric 				break;
85910327Seric 		}
8604096Seric 	}
8614096Seric 
86258333Seric 	if (delimptr != NULL)
86358333Seric 		*delimptr = p;
86410327Seric 	*q++ = '\0';
86510327Seric 	return (buf);
86610327Seric }
86710327Seric /*
86810327Seric **  MAKEARGV -- break up a string into words
86910327Seric **
87010327Seric **	Parameters:
87110327Seric **		p -- the string to break up.
87210327Seric **
87310327Seric **	Returns:
87410327Seric **		a char **argv (dynamically allocated)
87510327Seric **
87610327Seric **	Side Effects:
87710327Seric **		munges p.
87810327Seric */
8794096Seric 
88010327Seric char **
88110327Seric makeargv(p)
88210327Seric 	register char *p;
88310327Seric {
88410327Seric 	char *q;
88510327Seric 	int i;
88610327Seric 	char **avp;
88710327Seric 	char *argv[MAXPV + 1];
88810327Seric 
88910327Seric 	/* take apart the words */
89010327Seric 	i = 0;
89110327Seric 	while (*p != '\0' && i < MAXPV)
8924096Seric 	{
89310327Seric 		q = p;
89458050Seric 		while (*p != '\0' && !(isascii(*p) && isspace(*p)))
89510327Seric 			p++;
89658050Seric 		while (isascii(*p) && isspace(*p))
89710327Seric 			*p++ = '\0';
89810327Seric 		argv[i++] = newstr(q);
8994096Seric 	}
90010327Seric 	argv[i++] = NULL;
9014096Seric 
90210327Seric 	/* now make a copy of the argv */
90310327Seric 	avp = (char **) xalloc(sizeof *avp * i);
90416893Seric 	bcopy((char *) argv, (char *) avp, sizeof *avp * i);
90510327Seric 
90610327Seric 	return (avp);
9073308Seric }
9083308Seric /*
9093308Seric **  PRINTRULES -- print rewrite rules (for debugging)
9103308Seric **
9113308Seric **	Parameters:
9123308Seric **		none.
9133308Seric **
9143308Seric **	Returns:
9153308Seric **		none.
9163308Seric **
9173308Seric **	Side Effects:
9183308Seric **		prints rewrite rules.
9193308Seric */
9203308Seric 
9213308Seric printrules()
9223308Seric {
9233308Seric 	register struct rewrite *rwp;
9244072Seric 	register int ruleset;
9253308Seric 
9264072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
9273308Seric 	{
9284072Seric 		if (RewriteRules[ruleset] == NULL)
9294072Seric 			continue;
9308067Seric 		printf("\n----Rule Set %d:", ruleset);
9313308Seric 
9324072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
9333308Seric 		{
9348067Seric 			printf("\nLHS:");
9358067Seric 			printav(rwp->r_lhs);
9368067Seric 			printf("RHS:");
9378067Seric 			printav(rwp->r_rhs);
9383308Seric 		}
9393308Seric 	}
9403308Seric }
9414319Seric 
9424096Seric /*
9438256Seric **  SETOPTION -- set global processing option
9448256Seric **
9458256Seric **	Parameters:
9468256Seric **		opt -- option name.
9478256Seric **		val -- option value (as a text string).
94821755Seric **		safe -- set if this came from a configuration file.
94921755Seric **			Some options (if set from the command line) will
95021755Seric **			reset the user id to avoid security problems.
9518269Seric **		sticky -- if set, don't let other setoptions override
9528269Seric **			this value.
95358734Seric **		e -- the main envelope.
9548256Seric **
9558256Seric **	Returns:
9568256Seric **		none.
9578256Seric **
9588256Seric **	Side Effects:
9598256Seric **		Sets options as implied by the arguments.
9608256Seric */
9618256Seric 
96210687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
9638269Seric 
96457207Seric 
96557207Seric #ifdef NAMED_BIND
96657207Seric 
96757207Seric struct resolverflags
96857207Seric {
96957207Seric 	char	*rf_name;	/* name of the flag */
97057207Seric 	long	rf_bits;	/* bits to set/clear */
97157207Seric } ResolverFlags[] =
97257207Seric {
97357207Seric 	"debug",	RES_DEBUG,
97457207Seric 	"aaonly",	RES_AAONLY,
97557207Seric 	"usevc",	RES_USEVC,
97657207Seric 	"primary",	RES_PRIMARY,
97757207Seric 	"igntc",	RES_IGNTC,
97857207Seric 	"recurse",	RES_RECURSE,
97957207Seric 	"defnames",	RES_DEFNAMES,
98057207Seric 	"stayopen",	RES_STAYOPEN,
98157207Seric 	"dnsrch",	RES_DNSRCH,
98257207Seric 	NULL,		0
98357207Seric };
98457207Seric 
98557207Seric #endif
98657207Seric 
98758734Seric setoption(opt, val, safe, sticky, e)
9888256Seric 	char opt;
9898256Seric 	char *val;
99021755Seric 	bool safe;
9918269Seric 	bool sticky;
99258734Seric 	register ENVELOPE *e;
9938256Seric {
99457207Seric 	register char *p;
9958265Seric 	extern bool atobool();
99612633Seric 	extern time_t convtime();
99714879Seric 	extern int QueueLA;
99814879Seric 	extern int RefuseLA;
99917474Seric 	extern bool trusteduser();
10008256Seric 
10018256Seric 	if (tTd(37, 1))
10029341Seric 		printf("setoption %c=%s", opt, val);
10038256Seric 
10048256Seric 	/*
10058269Seric 	**  See if this option is preset for us.
10068256Seric 	*/
10078256Seric 
100859731Seric 	if (!sticky && bitnset(opt, StickyOpt))
10098269Seric 	{
10109341Seric 		if (tTd(37, 1))
10119341Seric 			printf(" (ignored)\n");
10128269Seric 		return;
10138269Seric 	}
10148269Seric 
101521755Seric 	/*
101621755Seric 	**  Check to see if this option can be specified by this user.
101721755Seric 	*/
101821755Seric 
101963787Seric 	if (!safe && RealUid == 0)
102021755Seric 		safe = TRUE;
102163837Seric 	if (!safe && strchr("bCdeEijLmoprsvw7", opt) == NULL)
102221755Seric 	{
102339111Srick 		if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
102421755Seric 		{
102536582Sbostic 			if (tTd(37, 1))
102636582Sbostic 				printf(" (unsafe)");
102763787Seric 			if (RealUid != geteuid())
102836582Sbostic 			{
102951210Seric 				if (tTd(37, 1))
103051210Seric 					printf("(Resetting uid)");
103163787Seric 				(void) setgid(RealGid);
103263787Seric 				(void) setuid(RealUid);
103336582Sbostic 			}
103421755Seric 		}
103521755Seric 	}
103651210Seric 	if (tTd(37, 1))
103717985Seric 		printf("\n");
10388269Seric 
10398256Seric 	switch (opt)
10408256Seric 	{
104159709Seric 	  case '7':		/* force seven-bit input */
104259709Seric 		SevenBit = atobool(val);
104352106Seric 		break;
104452106Seric 
10458256Seric 	  case 'A':		/* set default alias file */
10469381Seric 		if (val[0] == '\0')
104759672Seric 			setalias("aliases");
10489381Seric 		else
104959672Seric 			setalias(val);
10508256Seric 		break;
10518256Seric 
105217474Seric 	  case 'a':		/* look N minutes for "@:@" in alias file */
105317474Seric 		if (val[0] == '\0')
105417474Seric 			SafeAlias = 5;
105517474Seric 		else
105617474Seric 			SafeAlias = atoi(val);
105717474Seric 		break;
105817474Seric 
105916843Seric 	  case 'B':		/* substitution for blank character */
106016843Seric 		SpaceSub = val[0];
106116843Seric 		if (SpaceSub == '\0')
106216843Seric 			SpaceSub = ' ';
106316843Seric 		break;
106416843Seric 
106559283Seric 	  case 'b':		/* min blocks free on queue fs/max msg size */
106659283Seric 		p = strchr(val, '/');
106759283Seric 		if (p != NULL)
106859283Seric 		{
106959283Seric 			*p++ = '\0';
107059283Seric 			MaxMessageSize = atol(p);
107159283Seric 		}
107258082Seric 		MinBlocksFree = atol(val);
107358082Seric 		break;
107458082Seric 
10759284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
10769381Seric 		NoConnect = atobool(val);
10779284Seric 		break;
10789284Seric 
107951305Seric 	  case 'C':		/* checkpoint every N addresses */
108051305Seric 		CheckpointInterval = atoi(val);
108124944Seric 		break;
108224944Seric 
10839284Seric 	  case 'd':		/* delivery mode */
10849284Seric 		switch (*val)
10858269Seric 		{
10869284Seric 		  case '\0':
108758734Seric 			e->e_sendmode = SM_DELIVER;
10888269Seric 			break;
10898269Seric 
109010755Seric 		  case SM_QUEUE:	/* queue only */
109110755Seric #ifndef QUEUE
109210755Seric 			syserr("need QUEUE to set -odqueue");
109356795Seric #endif /* QUEUE */
109410755Seric 			/* fall through..... */
109510755Seric 
10969284Seric 		  case SM_DELIVER:	/* do everything */
10979284Seric 		  case SM_FORK:		/* fork after verification */
109858734Seric 			e->e_sendmode = *val;
10998269Seric 			break;
11008269Seric 
11018269Seric 		  default:
11029284Seric 			syserr("Unknown delivery mode %c", *val);
11038269Seric 			exit(EX_USAGE);
11048269Seric 		}
11058269Seric 		break;
11068269Seric 
11079146Seric 	  case 'D':		/* rebuild alias database as needed */
11089381Seric 		AutoRebuild = atobool(val);
11099146Seric 		break;
11109146Seric 
111155372Seric 	  case 'E':		/* error message header/header file */
111255379Seric 		if (*val != '\0')
111355379Seric 			ErrMsgFile = newstr(val);
111455372Seric 		break;
111555372Seric 
11168269Seric 	  case 'e':		/* set error processing mode */
11178269Seric 		switch (*val)
11188269Seric 		{
11199381Seric 		  case EM_QUIET:	/* be silent about it */
11209381Seric 		  case EM_MAIL:		/* mail back */
11219381Seric 		  case EM_BERKNET:	/* do berknet error processing */
11229381Seric 		  case EM_WRITE:	/* write back (or mail) */
11238269Seric 			HoldErrs = TRUE;
11249381Seric 			/* fall through... */
11258269Seric 
11269381Seric 		  case EM_PRINT:	/* print errors normally (default) */
112758734Seric 			e->e_errormode = *val;
11288269Seric 			break;
11298269Seric 		}
11308269Seric 		break;
11318269Seric 
11329049Seric 	  case 'F':		/* file mode */
113317975Seric 		FileMode = atooct(val) & 0777;
11349049Seric 		break;
11359049Seric 
11368269Seric 	  case 'f':		/* save Unix-style From lines on front */
11379381Seric 		SaveFrom = atobool(val);
11388269Seric 		break;
11398269Seric 
114053735Seric 	  case 'G':		/* match recipients against GECOS field */
114153735Seric 		MatchGecos = atobool(val);
114253735Seric 		break;
114353735Seric 
11448256Seric 	  case 'g':		/* default gid */
114564133Seric 		if (isascii(*val) && isdigit(*val))
114664133Seric 			DefGid = atoi(val);
114764133Seric 		else
114864133Seric 		{
114964133Seric 			register struct group *gr;
115064133Seric 
115164133Seric 			DefGid = -1;
115264133Seric 			gr = getgrnam(val);
115364133Seric 			if (gr == NULL)
115464133Seric 				syserr("readcf: option g: unknown group %s", val);
115564133Seric 			else
115664133Seric 				DefGid = gr->gr_gid;
115764133Seric 		}
11588256Seric 		break;
11598256Seric 
11608256Seric 	  case 'H':		/* help file */
11619381Seric 		if (val[0] == '\0')
11628269Seric 			HelpFile = "sendmail.hf";
11639381Seric 		else
11649381Seric 			HelpFile = newstr(val);
11658256Seric 		break;
11668256Seric 
116751305Seric 	  case 'h':		/* maximum hop count */
116851305Seric 		MaxHopCount = atoi(val);
116951305Seric 		break;
117051305Seric 
117135651Seric 	  case 'I':		/* use internet domain name server */
117257207Seric #ifdef NAMED_BIND
117357207Seric 		UseNameServer = TRUE;
117457207Seric 		for (p = val; *p != 0; )
117557207Seric 		{
117657207Seric 			bool clearmode;
117757207Seric 			char *q;
117857207Seric 			struct resolverflags *rfp;
117957207Seric 
118057207Seric 			while (*p == ' ')
118157207Seric 				p++;
118257207Seric 			if (*p == '\0')
118357207Seric 				break;
118457207Seric 			clearmode = FALSE;
118557207Seric 			if (*p == '-')
118657207Seric 				clearmode = TRUE;
118757207Seric 			else if (*p != '+')
118857207Seric 				p--;
118957207Seric 			p++;
119057207Seric 			q = p;
119158050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
119257207Seric 				p++;
119357207Seric 			if (*p != '\0')
119457207Seric 				*p++ = '\0';
119557207Seric 			for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
119657207Seric 			{
119757207Seric 				if (strcasecmp(q, rfp->rf_name) == 0)
119857207Seric 					break;
119957207Seric 			}
120057207Seric 			if (clearmode)
120157207Seric 				_res.options &= ~rfp->rf_bits;
120257207Seric 			else
120357207Seric 				_res.options |= rfp->rf_bits;
120457207Seric 		}
120557207Seric 		if (tTd(8, 2))
120657207Seric 			printf("_res.options = %x\n", _res.options);
120757207Seric #else
120857207Seric 		usrerr("name server (I option) specified but BIND not compiled in");
120957207Seric #endif
121035651Seric 		break;
121135651Seric 
12128269Seric 	  case 'i':		/* ignore dot lines in message */
12139381Seric 		IgnrDot = atobool(val);
12148269Seric 		break;
12158269Seric 
121659730Seric 	  case 'j':		/* send errors in MIME (RFC 1341) format */
121759730Seric 		SendMIMEErrors = atobool(val);
121859730Seric 		break;
121959730Seric 
122057136Seric 	  case 'J':		/* .forward search path */
122157136Seric 		ForwardPath = newstr(val);
122257136Seric 		break;
122357136Seric 
122454967Seric 	  case 'k':		/* connection cache size */
122554967Seric 		MaxMciCache = atoi(val);
122656215Seric 		if (MaxMciCache < 0)
122756215Seric 			MaxMciCache = 0;
122854967Seric 		break;
122954967Seric 
123054967Seric 	  case 'K':		/* connection cache timeout */
123158796Seric 		MciCacheTimeout = convtime(val, 'm');
123254967Seric 		break;
123354967Seric 
123461104Seric 	  case 'l':		/* use Errors-To: header */
123561104Seric 		UseErrorsTo = atobool(val);
123661104Seric 		break;
123761104Seric 
12388256Seric 	  case 'L':		/* log level */
123964140Seric 		if (safe || LogLevel < atoi(val))
124064140Seric 			LogLevel = atoi(val);
12418256Seric 		break;
12428256Seric 
12438269Seric 	  case 'M':		/* define macro */
12449381Seric 		define(val[0], newstr(&val[1]), CurEnv);
124516878Seric 		sticky = FALSE;
12468269Seric 		break;
12478269Seric 
12488269Seric 	  case 'm':		/* send to me too */
12499381Seric 		MeToo = atobool(val);
12508269Seric 		break;
12518269Seric 
125225820Seric 	  case 'n':		/* validate RHS in newaliases */
125325820Seric 		CheckAliases = atobool(val);
125425820Seric 		break;
125525820Seric 
125661104Seric 	    /* 'N' available -- was "net name" */
125761104Seric 
125858851Seric 	  case 'O':		/* daemon options */
125958851Seric 		setdaemonoptions(val);
126058851Seric 		break;
126158851Seric 
12628269Seric 	  case 'o':		/* assume old style headers */
12639381Seric 		if (atobool(val))
12649341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
12659341Seric 		else
12669341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
12678269Seric 		break;
12688269Seric 
126958082Seric 	  case 'p':		/* select privacy level */
127058082Seric 		p = val;
127158082Seric 		for (;;)
127258082Seric 		{
127358082Seric 			register struct prival *pv;
127458082Seric 			extern struct prival PrivacyValues[];
127558082Seric 
127658082Seric 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
127758082Seric 				p++;
127858082Seric 			if (*p == '\0')
127958082Seric 				break;
128058082Seric 			val = p;
128158082Seric 			while (isascii(*p) && isalnum(*p))
128258082Seric 				p++;
128358082Seric 			if (*p != '\0')
128458082Seric 				*p++ = '\0';
128558082Seric 
128658082Seric 			for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
128758082Seric 			{
128858082Seric 				if (strcasecmp(val, pv->pv_name) == 0)
128958082Seric 					break;
129058082Seric 			}
129158886Seric 			if (pv->pv_name == NULL)
129258886Seric 				syserr("readcf: Op line: %s unrecognized", val);
129358082Seric 			PrivacyFlags |= pv->pv_flag;
129458082Seric 		}
129558082Seric 		break;
129658082Seric 
129724944Seric 	  case 'P':		/* postmaster copy address for returned mail */
129824944Seric 		PostMasterCopy = newstr(val);
129924944Seric 		break;
130024944Seric 
130124944Seric 	  case 'q':		/* slope of queue only function */
130224944Seric 		QueueFactor = atoi(val);
130324944Seric 		break;
130424944Seric 
13058256Seric 	  case 'Q':		/* queue directory */
13069381Seric 		if (val[0] == '\0')
13078269Seric 			QueueDir = "mqueue";
13089381Seric 		else
13099381Seric 			QueueDir = newstr(val);
131058789Seric 		if (RealUid != 0 && !safe)
131158789Seric 			auth_warning(e, "Processed from queue %s", QueueDir);
13128256Seric 		break;
13138256Seric 
131458148Seric 	  case 'R':		/* don't prune routes */
131558148Seric 		DontPruneRoutes = atobool(val);
131658148Seric 		break;
131758148Seric 
13188256Seric 	  case 'r':		/* read timeout */
131958112Seric 		settimeouts(val);
13208256Seric 		break;
13218256Seric 
13228256Seric 	  case 'S':		/* status file */
13239381Seric 		if (val[0] == '\0')
13248269Seric 			StatFile = "sendmail.st";
13259381Seric 		else
13269381Seric 			StatFile = newstr(val);
13278256Seric 		break;
13288256Seric 
13298265Seric 	  case 's':		/* be super safe, even if expensive */
13309381Seric 		SuperSafe = atobool(val);
13318256Seric 		break;
13328256Seric 
13338256Seric 	  case 'T':		/* queue timeout */
133458737Seric 		p = strchr(val, '/');
133558737Seric 		if (p != NULL)
133658737Seric 		{
133758737Seric 			*p++ = '\0';
133858796Seric 			TimeOuts.to_q_warning = convtime(p, 'd');
133958737Seric 		}
134058796Seric 		TimeOuts.to_q_return = convtime(val, 'h');
134154967Seric 		break;
13428256Seric 
13438265Seric 	  case 't':		/* time zone name */
134452106Seric 		TimeZoneSpec = newstr(val);
13458265Seric 		break;
13468265Seric 
134750556Seric 	  case 'U':		/* location of user database */
134851360Seric 		UdbSpec = newstr(val);
134950556Seric 		break;
135050556Seric 
13518256Seric 	  case 'u':		/* set default uid */
135264133Seric 		if (isascii(*val) && isdigit(*val))
135364133Seric 			DefUid = atoi(val);
135464133Seric 		else
135564133Seric 		{
135664133Seric 			register struct passwd *pw;
135764133Seric 
135864133Seric 			DefUid = -1;
135964133Seric 			pw = getpwnam(val);
136064133Seric 			if (pw == NULL)
136164133Seric 				syserr("readcf: option u: unknown user %s", val);
136264133Seric 			else
136364133Seric 				DefUid = pw->pw_uid;
136464133Seric 		}
136540973Sbostic 		setdefuser();
13668256Seric 		break;
13678256Seric 
136858851Seric 	  case 'V':		/* fallback MX host */
136958851Seric 		FallBackMX = newstr(val);
137058851Seric 		break;
137158851Seric 
13728269Seric 	  case 'v':		/* run in verbose mode */
13739381Seric 		Verbose = atobool(val);
13748256Seric 		break;
13758256Seric 
137663837Seric 	  case 'w':		/* if we are best MX, try host directly */
137763837Seric 		TryNullMXList = atobool(val);
137863837Seric 		break;
137961104Seric 
138061104Seric 	    /* 'W' available -- was wizard password */
138161104Seric 
138214879Seric 	  case 'x':		/* load avg at which to auto-queue msgs */
138314879Seric 		QueueLA = atoi(val);
138414879Seric 		break;
138514879Seric 
138614879Seric 	  case 'X':		/* load avg at which to auto-reject connections */
138714879Seric 		RefuseLA = atoi(val);
138814879Seric 		break;
138914879Seric 
139024981Seric 	  case 'y':		/* work recipient factor */
139124981Seric 		WkRecipFact = atoi(val);
139224981Seric 		break;
139324981Seric 
139424981Seric 	  case 'Y':		/* fork jobs during queue runs */
139524952Seric 		ForkQueueRuns = atobool(val);
139624952Seric 		break;
139724952Seric 
139824981Seric 	  case 'z':		/* work message class factor */
139924981Seric 		WkClassFact = atoi(val);
140024981Seric 		break;
140124981Seric 
140224981Seric 	  case 'Z':		/* work time factor */
140324981Seric 		WkTimeFact = atoi(val);
140424981Seric 		break;
140524981Seric 
14068256Seric 	  default:
14078256Seric 		break;
14088256Seric 	}
140916878Seric 	if (sticky)
141016878Seric 		setbitn(opt, StickyOpt);
14119188Seric 	return;
14128256Seric }
141310687Seric /*
141410687Seric **  SETCLASS -- set a word into a class
141510687Seric **
141610687Seric **	Parameters:
141710687Seric **		class -- the class to put the word in.
141810687Seric **		word -- the word to enter
141910687Seric **
142010687Seric **	Returns:
142110687Seric **		none.
142210687Seric **
142310687Seric **	Side Effects:
142410687Seric **		puts the word into the symbol table.
142510687Seric */
142610687Seric 
142710687Seric setclass(class, word)
142810687Seric 	int class;
142910687Seric 	char *word;
143010687Seric {
143110687Seric 	register STAB *s;
143210687Seric 
143357943Seric 	if (tTd(37, 8))
143464326Seric 		printf("setclass(%c, %s)\n", class, word);
143510687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
143610687Seric 	setbitn(class, s->s_class);
143710687Seric }
143853654Seric /*
143953654Seric **  MAKEMAPENTRY -- create a map entry
144053654Seric **
144153654Seric **	Parameters:
144253654Seric **		line -- the config file line
144353654Seric **
144453654Seric **	Returns:
144553654Seric **		TRUE if it successfully entered the map entry.
144653654Seric **		FALSE otherwise (usually syntax error).
144753654Seric **
144853654Seric **	Side Effects:
144953654Seric **		Enters the map into the dictionary.
145053654Seric */
145153654Seric 
145253654Seric void
145353654Seric makemapentry(line)
145453654Seric 	char *line;
145553654Seric {
145653654Seric 	register char *p;
145753654Seric 	char *mapname;
145853654Seric 	char *classname;
145964078Seric 	register STAB *s;
146053654Seric 	STAB *class;
146153654Seric 
146258050Seric 	for (p = line; isascii(*p) && isspace(*p); p++)
146353654Seric 		continue;
146458050Seric 	if (!(isascii(*p) && isalnum(*p)))
146553654Seric 	{
146653654Seric 		syserr("readcf: config K line: no map name");
146753654Seric 		return;
146853654Seric 	}
146953654Seric 
147053654Seric 	mapname = p;
147158050Seric 	while (isascii(*++p) && isalnum(*p))
147253654Seric 		continue;
147353654Seric 	if (*p != '\0')
147453654Seric 		*p++ = '\0';
147558050Seric 	while (isascii(*p) && isspace(*p))
147653654Seric 		p++;
147758050Seric 	if (!(isascii(*p) && isalnum(*p)))
147853654Seric 	{
147953654Seric 		syserr("readcf: config K line, map %s: no map class", mapname);
148053654Seric 		return;
148153654Seric 	}
148253654Seric 	classname = p;
148358050Seric 	while (isascii(*++p) && isalnum(*p))
148453654Seric 		continue;
148553654Seric 	if (*p != '\0')
148653654Seric 		*p++ = '\0';
148758050Seric 	while (isascii(*p) && isspace(*p))
148853654Seric 		p++;
148953654Seric 
149053654Seric 	/* look up the class */
149153654Seric 	class = stab(classname, ST_MAPCLASS, ST_FIND);
149253654Seric 	if (class == NULL)
149353654Seric 	{
149453654Seric 		syserr("readcf: map %s: class %s not available", mapname, classname);
149553654Seric 		return;
149653654Seric 	}
149753654Seric 
149853654Seric 	/* enter the map */
149964078Seric 	s = stab(mapname, ST_MAP, ST_ENTER);
150064078Seric 	s->s_map.map_class = &class->s_mapclass;
150164078Seric 	s->s_map.map_mname = newstr(mapname);
150253654Seric 
150364078Seric 	if (class->s_mapclass.map_parse(&s->s_map, p))
150464078Seric 		s->s_map.map_mflags |= MF_VALID;
150564078Seric 
150664078Seric 	if (tTd(37, 5))
150764078Seric 	{
150864078Seric 		printf("map %s, class %s, flags %x, file %s,\n",
150964078Seric 			s->s_map.map_mname, s->s_map.map_class->map_cname,
151064078Seric 			s->s_map.map_mflags,
151164078Seric 			s->s_map.map_file == NULL ? "(null)" : s->s_map.map_file);
151264078Seric 		printf("\tapp %s, domain %s, rebuild %s\n",
151364078Seric 			s->s_map.map_app == NULL ? "(null)" : s->s_map.map_app,
151464078Seric 			s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain,
151564078Seric 			s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild);
151664078Seric 	}
151753654Seric }
151858112Seric /*
151958112Seric **  SETTIMEOUTS -- parse and set timeout values
152058112Seric **
152158112Seric **	Parameters:
152258112Seric **		val -- a pointer to the values.  If NULL, do initial
152358112Seric **			settings.
152458112Seric **
152558112Seric **	Returns:
152658112Seric **		none.
152758112Seric **
152858112Seric **	Side Effects:
152958112Seric **		Initializes the TimeOuts structure
153058112Seric */
153158112Seric 
153264255Seric #define SECONDS
153358112Seric #define MINUTES	* 60
153458112Seric #define HOUR	* 3600
153558112Seric 
153658112Seric settimeouts(val)
153758112Seric 	register char *val;
153858112Seric {
153958112Seric 	register char *p;
154058671Seric 	extern time_t convtime();
154158112Seric 
154258112Seric 	if (val == NULL)
154358112Seric 	{
154458112Seric 		TimeOuts.to_initial = (time_t) 5 MINUTES;
154558112Seric 		TimeOuts.to_helo = (time_t) 5 MINUTES;
154658112Seric 		TimeOuts.to_mail = (time_t) 10 MINUTES;
154758112Seric 		TimeOuts.to_rcpt = (time_t) 1 HOUR;
154858112Seric 		TimeOuts.to_datainit = (time_t) 5 MINUTES;
154958112Seric 		TimeOuts.to_datablock = (time_t) 1 HOUR;
155058112Seric 		TimeOuts.to_datafinal = (time_t) 1 HOUR;
155158112Seric 		TimeOuts.to_rset = (time_t) 5 MINUTES;
155258112Seric 		TimeOuts.to_quit = (time_t) 2 MINUTES;
155358112Seric 		TimeOuts.to_nextcommand = (time_t) 1 HOUR;
155458112Seric 		TimeOuts.to_miscshort = (time_t) 2 MINUTES;
155564255Seric 		TimeOuts.to_ident = (time_t) 30 SECONDS;
155658112Seric 		return;
155758112Seric 	}
155858112Seric 
155958112Seric 	for (;; val = p)
156058112Seric 	{
156158112Seric 		while (isascii(*val) && isspace(*val))
156258112Seric 			val++;
156358112Seric 		if (*val == '\0')
156458112Seric 			break;
156558112Seric 		for (p = val; *p != '\0' && *p != ','; p++)
156658112Seric 			continue;
156758112Seric 		if (*p != '\0')
156858112Seric 			*p++ = '\0';
156958112Seric 
157058112Seric 		if (isascii(*val) && isdigit(*val))
157158112Seric 		{
157258112Seric 			/* old syntax -- set everything */
157358796Seric 			TimeOuts.to_mail = convtime(val, 'm');
157458112Seric 			TimeOuts.to_rcpt = TimeOuts.to_mail;
157558112Seric 			TimeOuts.to_datainit = TimeOuts.to_mail;
157658112Seric 			TimeOuts.to_datablock = TimeOuts.to_mail;
157758112Seric 			TimeOuts.to_datafinal = TimeOuts.to_mail;
157858112Seric 			TimeOuts.to_nextcommand = TimeOuts.to_mail;
157958112Seric 			continue;
158058112Seric 		}
158158112Seric 		else
158258112Seric 		{
158358112Seric 			register char *q = strchr(val, '=');
158458112Seric 			time_t to;
158558112Seric 
158658112Seric 			if (q == NULL)
158758112Seric 			{
158858112Seric 				/* syntax error */
158958112Seric 				continue;
159058112Seric 			}
159158112Seric 			*q++ = '\0';
159258796Seric 			to = convtime(q, 'm');
159358112Seric 
159458112Seric 			if (strcasecmp(val, "initial") == 0)
159558112Seric 				TimeOuts.to_initial = to;
159658112Seric 			else if (strcasecmp(val, "mail") == 0)
159758112Seric 				TimeOuts.to_mail = to;
159858112Seric 			else if (strcasecmp(val, "rcpt") == 0)
159958112Seric 				TimeOuts.to_rcpt = to;
160058112Seric 			else if (strcasecmp(val, "datainit") == 0)
160158112Seric 				TimeOuts.to_datainit = to;
160258112Seric 			else if (strcasecmp(val, "datablock") == 0)
160358112Seric 				TimeOuts.to_datablock = to;
160458112Seric 			else if (strcasecmp(val, "datafinal") == 0)
160558112Seric 				TimeOuts.to_datafinal = to;
160658112Seric 			else if (strcasecmp(val, "command") == 0)
160758112Seric 				TimeOuts.to_nextcommand = to;
160858112Seric 			else if (strcasecmp(val, "rset") == 0)
160958112Seric 				TimeOuts.to_rset = to;
161058112Seric 			else if (strcasecmp(val, "helo") == 0)
161158112Seric 				TimeOuts.to_helo = to;
161258112Seric 			else if (strcasecmp(val, "quit") == 0)
161358112Seric 				TimeOuts.to_quit = to;
161458112Seric 			else if (strcasecmp(val, "misc") == 0)
161558112Seric 				TimeOuts.to_miscshort = to;
161664255Seric 			else if (strcasecmp(val, "ident") == 0)
161764255Seric 				TimeOuts.to_ident = to;
161858112Seric 			else
161958112Seric 				syserr("settimeouts: invalid timeout %s", val);
162058112Seric 		}
162158112Seric 	}
162258112Seric }
1623