xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 64086)
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*64086Seric static char sccsid[] = "@(#)readcf.c	8.5 (Berkeley) 07/29/93";
1133731Sbostic #endif /* not lint */
1222709Sdist 
133313Seric # include "sendmail.h"
1457207Seric #ifdef NAMED_BIND
1557207Seric # include <arpa/nameser.h>
1657207Seric # include <resolv.h>
1757207Seric #endif
183308Seric 
193308Seric /*
203308Seric **  READCF -- read control file.
213308Seric **
223308Seric **	This routine reads the control file and builds the internal
233308Seric **	form.
243308Seric **
254432Seric **	The file is formatted as a sequence of lines, each taken
264432Seric **	atomically.  The first character of each line describes how
274432Seric **	the line is to be interpreted.  The lines are:
284432Seric **		Dxval		Define macro x to have value val.
294432Seric **		Cxword		Put word into class x.
304432Seric **		Fxfile [fmt]	Read file for lines to put into
314432Seric **				class x.  Use scanf string 'fmt'
324432Seric **				or "%s" if not present.  Fmt should
334432Seric **				only produce one string-valued result.
344432Seric **		Hname: value	Define header with field-name 'name'
354432Seric **				and value as specified; this will be
364432Seric **				macro expanded immediately before
374432Seric **				use.
384432Seric **		Sn		Use rewriting set n.
394432Seric **		Rlhs rhs	Rewrite addresses that match lhs to
404432Seric **				be rhs.
4124944Seric **		Mn arg=val...	Define mailer.  n is the internal name.
4224944Seric **				Args specify mailer parameters.
438252Seric **		Oxvalue		Set option x to value.
448252Seric **		Pname=value	Set precedence name to value.
4552645Seric **		Vversioncode	Version level of configuration syntax.
4653654Seric **		Kmapname mapclass arguments....
4753654Seric **				Define keyed lookup of a given class.
4853654Seric **				Arguments are class dependent.
494432Seric **
503308Seric **	Parameters:
513308Seric **		cfname -- control file name.
5254973Seric **		safe -- TRUE if this is the system config file;
5354973Seric **			FALSE otherwise.
5455012Seric **		e -- the main envelope.
553308Seric **
563308Seric **	Returns:
573308Seric **		none.
583308Seric **
593308Seric **	Side Effects:
603308Seric **		Builds several internal tables.
613308Seric */
623308Seric 
6355012Seric readcf(cfname, safe, e)
643308Seric 	char *cfname;
6554973Seric 	bool safe;
6655012Seric 	register ENVELOPE *e;
673308Seric {
683308Seric 	FILE *cf;
698547Seric 	int ruleset = 0;
708547Seric 	char *q;
719350Seric 	struct rewrite *rwp = NULL;
7257135Seric 	char *bp;
7357589Seric 	int nfuzzy;
743308Seric 	char buf[MAXLINE];
753308Seric 	register char *p;
763308Seric 	extern char **copyplist();
7752647Seric 	struct stat statb;
785909Seric 	char exbuf[MAXLINE];
7916915Seric 	char pvpbuf[PSBUFSIZE];
8010709Seric 	extern char *munchstring();
8153654Seric 	extern void makemapentry();
823308Seric 
8352647Seric 	FileName = cfname;
8452647Seric 	LineNumber = 0;
8552647Seric 
863308Seric 	cf = fopen(cfname, "r");
873308Seric 	if (cf == NULL)
883308Seric 	{
8952647Seric 		syserr("cannot open");
903308Seric 		exit(EX_OSFILE);
913308Seric 	}
923308Seric 
9352647Seric 	if (fstat(fileno(cf), &statb) < 0)
9452647Seric 	{
9552647Seric 		syserr("cannot fstat");
9652647Seric 		exit(EX_OSFILE);
9752647Seric 	}
9852647Seric 
9952647Seric 	if (!S_ISREG(statb.st_mode))
10052647Seric 	{
10152647Seric 		syserr("not a plain file");
10252647Seric 		exit(EX_OSFILE);
10352647Seric 	}
10452647Seric 
10552647Seric 	if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
10652647Seric 	{
10753037Seric 		if (OpMode == MD_DAEMON || OpMode == MD_FREEZE)
10853037Seric 			fprintf(stderr, "%s: WARNING: dangerous write permissions\n",
10953037Seric 				FileName);
11053037Seric #ifdef LOG
11153037Seric 		if (LogLevel > 0)
11253037Seric 			syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions",
11353037Seric 				FileName);
11453037Seric #endif
11552647Seric 	}
11652647Seric 
11759254Seric #ifdef XLA
11859254Seric 	xla_zero();
11959254Seric #endif
12059254Seric 
12157135Seric 	while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL)
1223308Seric 	{
12357135Seric 		if (bp[0] == '#')
12457135Seric 		{
12557135Seric 			if (bp != buf)
12657135Seric 				free(bp);
12752637Seric 			continue;
12857135Seric 		}
12952637Seric 
13058050Seric 		/* map $ into \201 for macro expansion */
13157135Seric 		for (p = bp; *p != '\0'; p++)
13216157Seric 		{
13357135Seric 			if (*p == '#' && p > bp && ConfigLevel >= 3)
13452647Seric 			{
13552647Seric 				/* this is an on-line comment */
13652647Seric 				register char *e;
13752647Seric 
13858050Seric 				switch (*--p & 0377)
13952647Seric 				{
14058050Seric 				  case MACROEXPAND:
14152647Seric 					/* it's from $# -- let it go through */
14252647Seric 					p++;
14352647Seric 					break;
14452647Seric 
14552647Seric 				  case '\\':
14652647Seric 					/* it's backslash escaped */
14752647Seric 					(void) strcpy(p, p + 1);
14852647Seric 					break;
14952647Seric 
15052647Seric 				  default:
15152647Seric 					/* delete preceeding white space */
15258050Seric 					while (isascii(*p) && isspace(*p) && p > bp)
15352647Seric 						p--;
15456795Seric 					if ((e = strchr(++p, '\n')) != NULL)
15552647Seric 						(void) strcpy(p, e);
15652647Seric 					else
15752647Seric 						p[0] = p[1] = '\0';
15852647Seric 					break;
15952647Seric 				}
16052647Seric 				continue;
16152647Seric 			}
16252647Seric 
16316157Seric 			if (*p != '$')
16416157Seric 				continue;
16516157Seric 
16616157Seric 			if (p[1] == '$')
16716157Seric 			{
16816157Seric 				/* actual dollar sign.... */
16923111Seric 				(void) strcpy(p, p + 1);
17016157Seric 				continue;
17116157Seric 			}
17216157Seric 
17316157Seric 			/* convert to macro expansion character */
17458050Seric 			*p = MACROEXPAND;
17516157Seric 		}
17616157Seric 
17716157Seric 		/* interpret this line */
17857135Seric 		switch (bp[0])
1793308Seric 		{
1803308Seric 		  case '\0':
1813308Seric 		  case '#':		/* comment */
1823308Seric 			break;
1833308Seric 
1843308Seric 		  case 'R':		/* rewriting rule */
18557135Seric 			for (p = &bp[1]; *p != '\0' && *p != '\t'; p++)
1863308Seric 				continue;
1873308Seric 
1883308Seric 			if (*p == '\0')
1895909Seric 			{
19057135Seric 				syserr("invalid rewrite line \"%s\"", bp);
1915909Seric 				break;
1925909Seric 			}
1935909Seric 
1945909Seric 			/* allocate space for the rule header */
1955909Seric 			if (rwp == NULL)
1965909Seric 			{
1975909Seric 				RewriteRules[ruleset] = rwp =
1985909Seric 					(struct rewrite *) xalloc(sizeof *rwp);
1995909Seric 			}
2003308Seric 			else
2013308Seric 			{
2025909Seric 				rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
2035909Seric 				rwp = rwp->r_next;
2045909Seric 			}
2055909Seric 			rwp->r_next = NULL;
2063308Seric 
2075909Seric 			/* expand and save the LHS */
2085909Seric 			*p = '\0';
20957135Seric 			expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e);
21058333Seric 			rwp->r_lhs = prescan(exbuf, '\t', pvpbuf, NULL);
21157589Seric 			nfuzzy = 0;
2125909Seric 			if (rwp->r_lhs != NULL)
21357589Seric 			{
21457589Seric 				register char **ap;
21557589Seric 
2165909Seric 				rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
21757589Seric 
21857589Seric 				/* count the number of fuzzy matches in LHS */
21957589Seric 				for (ap = rwp->r_lhs; *ap != NULL; ap++)
22057589Seric 				{
22158148Seric 					char *botch;
22258148Seric 
22358148Seric 					botch = NULL;
22458050Seric 					switch (**ap & 0377)
22557589Seric 					{
22657589Seric 					  case MATCHZANY:
22757589Seric 					  case MATCHANY:
22857589Seric 					  case MATCHONE:
22957589Seric 					  case MATCHCLASS:
23057589Seric 					  case MATCHNCLASS:
23157589Seric 						nfuzzy++;
23258148Seric 						break;
23358148Seric 
23458148Seric 					  case MATCHREPL:
23558148Seric 						botch = "$0-$9";
23658148Seric 						break;
23758148Seric 
23858148Seric 					  case CANONNET:
23958148Seric 						botch = "$#";
24058148Seric 						break;
24158148Seric 
24258148Seric 					  case CANONUSER:
24358148Seric 						botch = "$:";
24458148Seric 						break;
24558148Seric 
24658148Seric 					  case CALLSUBR:
24758148Seric 						botch = "$>";
24858148Seric 						break;
24958148Seric 
25058148Seric 					  case CONDIF:
25158148Seric 						botch = "$?";
25258148Seric 						break;
25358148Seric 
25458148Seric 					  case CONDELSE:
25558148Seric 						botch = "$|";
25658148Seric 						break;
25758148Seric 
25858148Seric 					  case CONDFI:
25958148Seric 						botch = "$.";
26058148Seric 						break;
26158148Seric 
26258148Seric 					  case HOSTBEGIN:
26358148Seric 						botch = "$[";
26458148Seric 						break;
26558148Seric 
26658148Seric 					  case HOSTEND:
26758148Seric 						botch = "$]";
26858148Seric 						break;
26958148Seric 
27058148Seric 					  case LOOKUPBEGIN:
27158148Seric 						botch = "$(";
27258148Seric 						break;
27358148Seric 
27458148Seric 					  case LOOKUPEND:
27558148Seric 						botch = "$)";
27658148Seric 						break;
27757589Seric 					}
27858148Seric 					if (botch != NULL)
27958148Seric 						syserr("Inappropriate use of %s on LHS",
28058148Seric 							botch);
28157589Seric 				}
28257589Seric 			}
28356678Seric 			else
28456678Seric 				syserr("R line: null LHS");
2855909Seric 
2865909Seric 			/* expand and save the RHS */
2875909Seric 			while (*++p == '\t')
2885909Seric 				continue;
2897231Seric 			q = p;
2907231Seric 			while (*p != '\0' && *p != '\t')
2917231Seric 				p++;
2927231Seric 			*p = '\0';
29355012Seric 			expand(q, exbuf, &exbuf[sizeof exbuf], e);
29458333Seric 			rwp->r_rhs = prescan(exbuf, '\t', pvpbuf, NULL);
2955909Seric 			if (rwp->r_rhs != NULL)
29657589Seric 			{
29757589Seric 				register char **ap;
29857589Seric 
2995909Seric 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
30057589Seric 
30157589Seric 				/* check no out-of-bounds replacements */
30257589Seric 				nfuzzy += '0';
30357589Seric 				for (ap = rwp->r_rhs; *ap != NULL; ap++)
30457589Seric 				{
30558148Seric 					char *botch;
30658148Seric 
30758148Seric 					botch = NULL;
30858148Seric 					switch (**ap & 0377)
30957589Seric 					{
31058148Seric 					  case MATCHREPL:
31158148Seric 						if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy)
31258148Seric 						{
31358148Seric 							syserr("replacement $%c out of bounds",
31458148Seric 								(*ap)[1]);
31558148Seric 						}
31658148Seric 						break;
31758148Seric 
31858148Seric 					  case MATCHZANY:
31958148Seric 						botch = "$*";
32058148Seric 						break;
32158148Seric 
32258148Seric 					  case MATCHANY:
32358148Seric 						botch = "$+";
32458148Seric 						break;
32558148Seric 
32658148Seric 					  case MATCHONE:
32758148Seric 						botch = "$-";
32858148Seric 						break;
32958148Seric 
33058148Seric 					  case MATCHCLASS:
33158148Seric 						botch = "$=";
33258148Seric 						break;
33358148Seric 
33458148Seric 					  case MATCHNCLASS:
33558148Seric 						botch = "$~";
33658148Seric 						break;
33757589Seric 					}
33858148Seric 					if (botch != NULL)
33958148Seric 						syserr("Inappropriate use of %s on RHS",
34058148Seric 							botch);
34157589Seric 				}
34257589Seric 			}
34356678Seric 			else
34456678Seric 				syserr("R line: null RHS");
3453308Seric 			break;
3463308Seric 
3474072Seric 		  case 'S':		/* select rewriting set */
34857135Seric 			ruleset = atoi(&bp[1]);
3498056Seric 			if (ruleset >= MAXRWSETS || ruleset < 0)
3508056Seric 			{
3519381Seric 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
3528056Seric 				ruleset = 0;
3538056Seric 			}
3544072Seric 			rwp = NULL;
3554072Seric 			break;
3564072Seric 
3573308Seric 		  case 'D':		/* macro definition */
358*64086Seric 			p = munchstring(&bp[2], NULL);
359*64086Seric 			define(bp[1], newstr(p), e);
3603308Seric 			break;
3613308Seric 
3623387Seric 		  case 'H':		/* required header line */
36357135Seric 			(void) chompheader(&bp[1], TRUE, e);
3643387Seric 			break;
3653387Seric 
3664061Seric 		  case 'C':		/* word class */
3674432Seric 			/* scan the list of words and set class for all */
36857135Seric 			for (p = &bp[2]; *p != '\0'; )
3694061Seric 			{
3704061Seric 				register char *wd;
3714061Seric 				char delim;
3724061Seric 
37358050Seric 				while (*p != '\0' && isascii(*p) && isspace(*p))
3744061Seric 					p++;
3754061Seric 				wd = p;
37658050Seric 				while (*p != '\0' && !(isascii(*p) && isspace(*p)))
3774061Seric 					p++;
3784061Seric 				delim = *p;
3794061Seric 				*p = '\0';
3804061Seric 				if (wd[0] != '\0')
38158148Seric 				{
38258148Seric 					if (tTd(37, 2))
38358148Seric 						printf("setclass(%c, %s)\n",
38458148Seric 							bp[1], wd);
38557135Seric 					setclass(bp[1], wd);
38658148Seric 				}
3874061Seric 				*p = delim;
3884061Seric 			}
3894061Seric 			break;
3904061Seric 
39159272Seric 		  case 'F':		/* word class from file */
39259272Seric 			/* read list of words from argument or file */
39359272Seric 			/* read from file */
39459272Seric 			for (p = &bp[2];
39559272Seric 			     *p != '\0' && !(isascii(*p) && isspace(*p));
39659272Seric 			     p++)
39759272Seric 				continue;
39859272Seric 			if (*p == '\0')
39959272Seric 				p = "%s";
40059272Seric 			else
40159272Seric 			{
40259272Seric 				*p = '\0';
40359272Seric 				while (isascii(*++p) && isspace(*p))
40459272Seric 					continue;
40559272Seric 			}
40659272Seric 			fileclass(bp[1], &bp[2], p, safe);
40759272Seric 			break;
40859272Seric 
40959156Seric #ifdef XLA
41059156Seric 		  case 'L':		/* extended load average description */
41159156Seric 			xla_init(&bp[1]);
41259156Seric 			break;
41359156Seric #endif
41459156Seric 
4154096Seric 		  case 'M':		/* define mailer */
41657135Seric 			makemailer(&bp[1]);
4174096Seric 			break;
4184096Seric 
4198252Seric 		  case 'O':		/* set option */
42058734Seric 			setoption(bp[1], &bp[2], safe, FALSE, e);
4218252Seric 			break;
4228252Seric 
4238252Seric 		  case 'P':		/* set precedence */
4248252Seric 			if (NumPriorities >= MAXPRIORITIES)
4258252Seric 			{
4268547Seric 				toomany('P', MAXPRIORITIES);
4278252Seric 				break;
4288252Seric 			}
42957135Seric 			for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
4308252Seric 				continue;
4318252Seric 			if (*p == '\0')
4328252Seric 				goto badline;
4338252Seric 			*p = '\0';
43457135Seric 			Priorities[NumPriorities].pri_name = newstr(&bp[1]);
4358252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
4368252Seric 			NumPriorities++;
4378252Seric 			break;
4388252Seric 
4398547Seric 		  case 'T':		/* trusted user(s) */
44058161Seric 			/* this option is obsolete, but will be ignored */
4418547Seric 			break;
4428547Seric 
44352645Seric 		  case 'V':		/* configuration syntax version */
44457135Seric 			ConfigLevel = atoi(&bp[1]);
44552645Seric 			break;
44652645Seric 
44753654Seric 		  case 'K':
44857135Seric 			makemapentry(&bp[1]);
44953654Seric 			break;
45053654Seric 
4513308Seric 		  default:
4524061Seric 		  badline:
45357135Seric 			syserr("unknown control line \"%s\"", bp);
4543308Seric 		}
45557135Seric 		if (bp != buf)
45657135Seric 			free(bp);
4573308Seric 	}
45852637Seric 	if (ferror(cf))
45952637Seric 	{
46052647Seric 		syserr("I/O read error", cfname);
46152637Seric 		exit(EX_OSFILE);
46252637Seric 	}
46352637Seric 	fclose(cf);
4649381Seric 	FileName = NULL;
46556836Seric 
46657076Seric 	if (stab("host", ST_MAP, ST_FIND) == NULL)
46757076Seric 	{
46857076Seric 		/* user didn't initialize: set up host map */
46957076Seric 		strcpy(buf, "host host");
47057076Seric 		if (ConfigLevel >= 2)
47157076Seric 			strcat(buf, " -a.");
47257076Seric 		makemapentry(buf);
47357076Seric 	}
4744096Seric }
4754096Seric /*
4768547Seric **  TOOMANY -- signal too many of some option
4778547Seric **
4788547Seric **	Parameters:
4798547Seric **		id -- the id of the error line
4808547Seric **		maxcnt -- the maximum possible values
4818547Seric **
4828547Seric **	Returns:
4838547Seric **		none.
4848547Seric **
4858547Seric **	Side Effects:
4868547Seric **		gives a syserr.
4878547Seric */
4888547Seric 
4898547Seric toomany(id, maxcnt)
4908547Seric 	char id;
4918547Seric 	int maxcnt;
4928547Seric {
4939381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
4948547Seric }
4958547Seric /*
4964432Seric **  FILECLASS -- read members of a class from a file
4974432Seric **
4984432Seric **	Parameters:
4994432Seric **		class -- class to define.
5004432Seric **		filename -- name of file to read.
5014432Seric **		fmt -- scanf string to use for match.
5024432Seric **
5034432Seric **	Returns:
5044432Seric **		none
5054432Seric **
5064432Seric **	Side Effects:
5074432Seric **
5084432Seric **		puts all lines in filename that match a scanf into
5094432Seric **			the named class.
5104432Seric */
5114432Seric 
51254973Seric fileclass(class, filename, fmt, safe)
5134432Seric 	int class;
5144432Seric 	char *filename;
5154432Seric 	char *fmt;
51654973Seric 	bool safe;
5174432Seric {
51825808Seric 	FILE *f;
51954973Seric 	struct stat stbuf;
5204432Seric 	char buf[MAXLINE];
5214432Seric 
52254973Seric 	if (stat(filename, &stbuf) < 0)
52354973Seric 	{
52454973Seric 		syserr("fileclass: cannot stat %s", filename);
52554973Seric 		return;
52654973Seric 	}
52754973Seric 	if (!S_ISREG(stbuf.st_mode))
52854973Seric 	{
52954973Seric 		syserr("fileclass: %s not a regular file", filename);
53054973Seric 		return;
53154973Seric 	}
53254973Seric 	if (!safe && access(filename, R_OK) < 0)
53354973Seric 	{
53454973Seric 		syserr("fileclass: access denied on %s", filename);
53554973Seric 		return;
53654973Seric 	}
53754973Seric 	f = fopen(filename, "r");
5384432Seric 	if (f == NULL)
5394432Seric 	{
54054973Seric 		syserr("fileclass: cannot open %s", filename);
5414432Seric 		return;
5424432Seric 	}
5434432Seric 
5444432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
5454432Seric 	{
5464432Seric 		register STAB *s;
54725808Seric 		register char *p;
54825808Seric # ifdef SCANF
5494432Seric 		char wordbuf[MAXNAME+1];
5504432Seric 
5514432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
5524432Seric 			continue;
55325808Seric 		p = wordbuf;
55456795Seric # else /* SCANF */
55525808Seric 		p = buf;
55656795Seric # endif /* SCANF */
55725808Seric 
55825808Seric 		/*
55925808Seric 		**  Break up the match into words.
56025808Seric 		*/
56125808Seric 
56225808Seric 		while (*p != '\0')
56325808Seric 		{
56425808Seric 			register char *q;
56525808Seric 
56625808Seric 			/* strip leading spaces */
56758050Seric 			while (isascii(*p) && isspace(*p))
56825808Seric 				p++;
56925808Seric 			if (*p == '\0')
57025808Seric 				break;
57125808Seric 
57225808Seric 			/* find the end of the word */
57325808Seric 			q = p;
57458050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
57525808Seric 				p++;
57625808Seric 			if (*p != '\0')
57725808Seric 				*p++ = '\0';
57825808Seric 
57925808Seric 			/* enter the word in the symbol table */
58025808Seric 			s = stab(q, ST_CLASS, ST_ENTER);
58125808Seric 			setbitn(class, s->s_class);
58225808Seric 		}
5834432Seric 	}
5844432Seric 
58554973Seric 	(void) fclose(f);
5864432Seric }
5874432Seric /*
5884096Seric **  MAKEMAILER -- define a new mailer.
5894096Seric **
5904096Seric **	Parameters:
59110327Seric **		line -- description of mailer.  This is in labeled
59210327Seric **			fields.  The fields are:
59310327Seric **			   P -- the path to the mailer
59410327Seric **			   F -- the flags associated with the mailer
59510327Seric **			   A -- the argv for this mailer
59610327Seric **			   S -- the sender rewriting set
59710327Seric **			   R -- the recipient rewriting set
59810327Seric **			   E -- the eol string
59910327Seric **			The first word is the canonical name of the mailer.
6004096Seric **
6014096Seric **	Returns:
6024096Seric **		none.
6034096Seric **
6044096Seric **	Side Effects:
6054096Seric **		enters the mailer into the mailer table.
6064096Seric */
6073308Seric 
60821066Seric makemailer(line)
6094096Seric 	char *line;
6104096Seric {
6114096Seric 	register char *p;
6128067Seric 	register struct mailer *m;
6138067Seric 	register STAB *s;
6148067Seric 	int i;
61510327Seric 	char fcode;
61658020Seric 	auto char *endp;
6174096Seric 	extern int NextMailer;
61810327Seric 	extern char **makeargv();
61910327Seric 	extern char *munchstring();
62010701Seric 	extern long atol();
6214096Seric 
62210327Seric 	/* allocate a mailer and set up defaults */
62310327Seric 	m = (struct mailer *) xalloc(sizeof *m);
62410327Seric 	bzero((char *) m, sizeof *m);
62510327Seric 	m->m_eol = "\n";
62610327Seric 
62710327Seric 	/* collect the mailer name */
62858050Seric 	for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++)
62910327Seric 		continue;
63010327Seric 	if (*p != '\0')
63110327Seric 		*p++ = '\0';
63210327Seric 	m->m_name = newstr(line);
63310327Seric 
63410327Seric 	/* now scan through and assign info from the fields */
63510327Seric 	while (*p != '\0')
63610327Seric 	{
63758333Seric 		auto char *delimptr;
63858333Seric 
63958050Seric 		while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p))))
64010327Seric 			p++;
64110327Seric 
64210327Seric 		/* p now points to field code */
64310327Seric 		fcode = *p;
64410327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
64510327Seric 			p++;
64610327Seric 		if (*p++ != '=')
64710327Seric 		{
64852637Seric 			syserr("mailer %s: `=' expected", m->m_name);
64910327Seric 			return;
65010327Seric 		}
65158050Seric 		while (isascii(*p) && isspace(*p))
65210327Seric 			p++;
65310327Seric 
65410327Seric 		/* p now points to the field body */
65558333Seric 		p = munchstring(p, &delimptr);
65610327Seric 
65710327Seric 		/* install the field into the mailer struct */
65810327Seric 		switch (fcode)
65910327Seric 		{
66010327Seric 		  case 'P':		/* pathname */
66110327Seric 			m->m_mailer = newstr(p);
66210327Seric 			break;
66310327Seric 
66410327Seric 		  case 'F':		/* flags */
66510687Seric 			for (; *p != '\0'; p++)
66658050Seric 				if (!(isascii(*p) && isspace(*p)))
66752637Seric 					setbitn(*p, m->m_flags);
66810327Seric 			break;
66910327Seric 
67010327Seric 		  case 'S':		/* sender rewriting ruleset */
67110327Seric 		  case 'R':		/* recipient rewriting ruleset */
67258020Seric 			i = strtol(p, &endp, 10);
67310327Seric 			if (i < 0 || i >= MAXRWSETS)
67410327Seric 			{
67510327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
67610327Seric 				return;
67710327Seric 			}
67810327Seric 			if (fcode == 'S')
67958020Seric 				m->m_sh_rwset = m->m_se_rwset = i;
68010327Seric 			else
68158020Seric 				m->m_rh_rwset = m->m_re_rwset = i;
68258020Seric 
68358020Seric 			p = endp;
68459985Seric 			if (*p++ == '/')
68558020Seric 			{
68658020Seric 				i = strtol(p, NULL, 10);
68758020Seric 				if (i < 0 || i >= MAXRWSETS)
68858020Seric 				{
68958020Seric 					syserr("invalid rewrite set, %d max",
69058020Seric 						MAXRWSETS);
69158020Seric 					return;
69258020Seric 				}
69358020Seric 				if (fcode == 'S')
69458020Seric 					m->m_sh_rwset = i;
69558020Seric 				else
69658020Seric 					m->m_rh_rwset = i;
69758020Seric 			}
69810327Seric 			break;
69910327Seric 
70010327Seric 		  case 'E':		/* end of line string */
70110327Seric 			m->m_eol = newstr(p);
70210327Seric 			break;
70310327Seric 
70410327Seric 		  case 'A':		/* argument vector */
70510327Seric 			m->m_argv = makeargv(p);
70610327Seric 			break;
70710701Seric 
70810701Seric 		  case 'M':		/* maximum message size */
70910701Seric 			m->m_maxsize = atol(p);
71010701Seric 			break;
71152106Seric 
71252106Seric 		  case 'L':		/* maximum line length */
71352106Seric 			m->m_linelimit = atoi(p);
71452106Seric 			break;
71558935Seric 
71658935Seric 		  case 'D':		/* working directory */
71758935Seric 			m->m_execdir = newstr(p);
71858935Seric 			break;
71910327Seric 		}
72010327Seric 
72158333Seric 		p = delimptr;
72210327Seric 	}
72310327Seric 
72452106Seric 	/* do some heuristic cleanup for back compatibility */
72552106Seric 	if (bitnset(M_LIMITS, m->m_flags))
72652106Seric 	{
72752106Seric 		if (m->m_linelimit == 0)
72852106Seric 			m->m_linelimit = SMTPLINELIM;
72955418Seric 		if (ConfigLevel < 2)
73052106Seric 			setbitn(M_7BITS, m->m_flags);
73152106Seric 	}
73252106Seric 
73358321Seric 	/* do some rationality checking */
73458321Seric 	if (m->m_argv == NULL)
73558321Seric 	{
73658321Seric 		syserr("M%s: A= argument required", m->m_name);
73758321Seric 		return;
73858321Seric 	}
73958321Seric 	if (m->m_mailer == NULL)
74058321Seric 	{
74158321Seric 		syserr("M%s: P= argument required", m->m_name);
74258321Seric 		return;
74358321Seric 	}
74458321Seric 
7454096Seric 	if (NextMailer >= MAXMAILERS)
7464096Seric 	{
7479381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
7484096Seric 		return;
7494096Seric 	}
75057402Seric 
75110327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
75257402Seric 	if (s->s_mailer != NULL)
75357402Seric 	{
75457402Seric 		i = s->s_mailer->m_mno;
75557402Seric 		free(s->s_mailer);
75657402Seric 	}
75757402Seric 	else
75857402Seric 	{
75957402Seric 		i = NextMailer++;
76057402Seric 	}
76157402Seric 	Mailer[i] = s->s_mailer = m;
76257454Seric 	m->m_mno = i;
76310327Seric }
76410327Seric /*
76510327Seric **  MUNCHSTRING -- translate a string into internal form.
76610327Seric **
76710327Seric **	Parameters:
76810327Seric **		p -- the string to munch.
76958333Seric **		delimptr -- if non-NULL, set to the pointer of the
77058333Seric **			field delimiter character.
77110327Seric **
77210327Seric **	Returns:
77310327Seric **		the munched string.
77410327Seric */
7754096Seric 
77610327Seric char *
77758333Seric munchstring(p, delimptr)
77810327Seric 	register char *p;
77958333Seric 	char **delimptr;
78010327Seric {
78110327Seric 	register char *q;
78210327Seric 	bool backslash = FALSE;
78310327Seric 	bool quotemode = FALSE;
78410327Seric 	static char buf[MAXLINE];
7854096Seric 
78610327Seric 	for (q = buf; *p != '\0'; p++)
7874096Seric 	{
78810327Seric 		if (backslash)
78910327Seric 		{
79010327Seric 			/* everything is roughly literal */
79110357Seric 			backslash = FALSE;
79210327Seric 			switch (*p)
79310327Seric 			{
79410327Seric 			  case 'r':		/* carriage return */
79510327Seric 				*q++ = '\r';
79610327Seric 				continue;
79710327Seric 
79810327Seric 			  case 'n':		/* newline */
79910327Seric 				*q++ = '\n';
80010327Seric 				continue;
80110327Seric 
80210327Seric 			  case 'f':		/* form feed */
80310327Seric 				*q++ = '\f';
80410327Seric 				continue;
80510327Seric 
80610327Seric 			  case 'b':		/* backspace */
80710327Seric 				*q++ = '\b';
80810327Seric 				continue;
80910327Seric 			}
81010327Seric 			*q++ = *p;
81110327Seric 		}
81210327Seric 		else
81310327Seric 		{
81410327Seric 			if (*p == '\\')
81510327Seric 				backslash = TRUE;
81610327Seric 			else if (*p == '"')
81710327Seric 				quotemode = !quotemode;
81810327Seric 			else if (quotemode || *p != ',')
81910327Seric 				*q++ = *p;
82010327Seric 			else
82110327Seric 				break;
82210327Seric 		}
8234096Seric 	}
8244096Seric 
82558333Seric 	if (delimptr != NULL)
82658333Seric 		*delimptr = p;
82710327Seric 	*q++ = '\0';
82810327Seric 	return (buf);
82910327Seric }
83010327Seric /*
83110327Seric **  MAKEARGV -- break up a string into words
83210327Seric **
83310327Seric **	Parameters:
83410327Seric **		p -- the string to break up.
83510327Seric **
83610327Seric **	Returns:
83710327Seric **		a char **argv (dynamically allocated)
83810327Seric **
83910327Seric **	Side Effects:
84010327Seric **		munges p.
84110327Seric */
8424096Seric 
84310327Seric char **
84410327Seric makeargv(p)
84510327Seric 	register char *p;
84610327Seric {
84710327Seric 	char *q;
84810327Seric 	int i;
84910327Seric 	char **avp;
85010327Seric 	char *argv[MAXPV + 1];
85110327Seric 
85210327Seric 	/* take apart the words */
85310327Seric 	i = 0;
85410327Seric 	while (*p != '\0' && i < MAXPV)
8554096Seric 	{
85610327Seric 		q = p;
85758050Seric 		while (*p != '\0' && !(isascii(*p) && isspace(*p)))
85810327Seric 			p++;
85958050Seric 		while (isascii(*p) && isspace(*p))
86010327Seric 			*p++ = '\0';
86110327Seric 		argv[i++] = newstr(q);
8624096Seric 	}
86310327Seric 	argv[i++] = NULL;
8644096Seric 
86510327Seric 	/* now make a copy of the argv */
86610327Seric 	avp = (char **) xalloc(sizeof *avp * i);
86716893Seric 	bcopy((char *) argv, (char *) avp, sizeof *avp * i);
86810327Seric 
86910327Seric 	return (avp);
8703308Seric }
8713308Seric /*
8723308Seric **  PRINTRULES -- print rewrite rules (for debugging)
8733308Seric **
8743308Seric **	Parameters:
8753308Seric **		none.
8763308Seric **
8773308Seric **	Returns:
8783308Seric **		none.
8793308Seric **
8803308Seric **	Side Effects:
8813308Seric **		prints rewrite rules.
8823308Seric */
8833308Seric 
8843308Seric printrules()
8853308Seric {
8863308Seric 	register struct rewrite *rwp;
8874072Seric 	register int ruleset;
8883308Seric 
8894072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
8903308Seric 	{
8914072Seric 		if (RewriteRules[ruleset] == NULL)
8924072Seric 			continue;
8938067Seric 		printf("\n----Rule Set %d:", ruleset);
8943308Seric 
8954072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
8963308Seric 		{
8978067Seric 			printf("\nLHS:");
8988067Seric 			printav(rwp->r_lhs);
8998067Seric 			printf("RHS:");
9008067Seric 			printav(rwp->r_rhs);
9013308Seric 		}
9023308Seric 	}
9033308Seric }
9044319Seric 
9054096Seric /*
9068256Seric **  SETOPTION -- set global processing option
9078256Seric **
9088256Seric **	Parameters:
9098256Seric **		opt -- option name.
9108256Seric **		val -- option value (as a text string).
91121755Seric **		safe -- set if this came from a configuration file.
91221755Seric **			Some options (if set from the command line) will
91321755Seric **			reset the user id to avoid security problems.
9148269Seric **		sticky -- if set, don't let other setoptions override
9158269Seric **			this value.
91658734Seric **		e -- the main envelope.
9178256Seric **
9188256Seric **	Returns:
9198256Seric **		none.
9208256Seric **
9218256Seric **	Side Effects:
9228256Seric **		Sets options as implied by the arguments.
9238256Seric */
9248256Seric 
92510687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
9268269Seric 
92757207Seric 
92857207Seric #ifdef NAMED_BIND
92957207Seric 
93057207Seric struct resolverflags
93157207Seric {
93257207Seric 	char	*rf_name;	/* name of the flag */
93357207Seric 	long	rf_bits;	/* bits to set/clear */
93457207Seric } ResolverFlags[] =
93557207Seric {
93657207Seric 	"debug",	RES_DEBUG,
93757207Seric 	"aaonly",	RES_AAONLY,
93857207Seric 	"usevc",	RES_USEVC,
93957207Seric 	"primary",	RES_PRIMARY,
94057207Seric 	"igntc",	RES_IGNTC,
94157207Seric 	"recurse",	RES_RECURSE,
94257207Seric 	"defnames",	RES_DEFNAMES,
94357207Seric 	"stayopen",	RES_STAYOPEN,
94457207Seric 	"dnsrch",	RES_DNSRCH,
94557207Seric 	NULL,		0
94657207Seric };
94757207Seric 
94857207Seric #endif
94957207Seric 
95058734Seric setoption(opt, val, safe, sticky, e)
9518256Seric 	char opt;
9528256Seric 	char *val;
95321755Seric 	bool safe;
9548269Seric 	bool sticky;
95558734Seric 	register ENVELOPE *e;
9568256Seric {
95757207Seric 	register char *p;
9588265Seric 	extern bool atobool();
95912633Seric 	extern time_t convtime();
96014879Seric 	extern int QueueLA;
96114879Seric 	extern int RefuseLA;
96217474Seric 	extern bool trusteduser();
9638256Seric 
9648256Seric 	if (tTd(37, 1))
9659341Seric 		printf("setoption %c=%s", opt, val);
9668256Seric 
9678256Seric 	/*
9688269Seric 	**  See if this option is preset for us.
9698256Seric 	*/
9708256Seric 
97159731Seric 	if (!sticky && bitnset(opt, StickyOpt))
9728269Seric 	{
9739341Seric 		if (tTd(37, 1))
9749341Seric 			printf(" (ignored)\n");
9758269Seric 		return;
9768269Seric 	}
9778269Seric 
97821755Seric 	/*
97921755Seric 	**  Check to see if this option can be specified by this user.
98021755Seric 	*/
98121755Seric 
98263787Seric 	if (!safe && RealUid == 0)
98321755Seric 		safe = TRUE;
98463837Seric 	if (!safe && strchr("bCdeEijLmoprsvw7", opt) == NULL)
98521755Seric 	{
98639111Srick 		if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
98721755Seric 		{
98836582Sbostic 			if (tTd(37, 1))
98936582Sbostic 				printf(" (unsafe)");
99063787Seric 			if (RealUid != geteuid())
99136582Sbostic 			{
99251210Seric 				if (tTd(37, 1))
99351210Seric 					printf("(Resetting uid)");
99463787Seric 				(void) setgid(RealGid);
99563787Seric 				(void) setuid(RealUid);
99636582Sbostic 			}
99721755Seric 		}
99821755Seric 	}
99951210Seric 	if (tTd(37, 1))
100017985Seric 		printf("\n");
10018269Seric 
10028256Seric 	switch (opt)
10038256Seric 	{
100459709Seric 	  case '7':		/* force seven-bit input */
100559709Seric 		SevenBit = atobool(val);
100652106Seric 		break;
100752106Seric 
10088256Seric 	  case 'A':		/* set default alias file */
10099381Seric 		if (val[0] == '\0')
101059672Seric 			setalias("aliases");
10119381Seric 		else
101259672Seric 			setalias(val);
10138256Seric 		break;
10148256Seric 
101517474Seric 	  case 'a':		/* look N minutes for "@:@" in alias file */
101617474Seric 		if (val[0] == '\0')
101717474Seric 			SafeAlias = 5;
101817474Seric 		else
101917474Seric 			SafeAlias = atoi(val);
102017474Seric 		break;
102117474Seric 
102216843Seric 	  case 'B':		/* substitution for blank character */
102316843Seric 		SpaceSub = val[0];
102416843Seric 		if (SpaceSub == '\0')
102516843Seric 			SpaceSub = ' ';
102616843Seric 		break;
102716843Seric 
102859283Seric 	  case 'b':		/* min blocks free on queue fs/max msg size */
102959283Seric 		p = strchr(val, '/');
103059283Seric 		if (p != NULL)
103159283Seric 		{
103259283Seric 			*p++ = '\0';
103359283Seric 			MaxMessageSize = atol(p);
103459283Seric 		}
103558082Seric 		MinBlocksFree = atol(val);
103658082Seric 		break;
103758082Seric 
10389284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
10399381Seric 		NoConnect = atobool(val);
10409284Seric 		break;
10419284Seric 
104251305Seric 	  case 'C':		/* checkpoint every N addresses */
104351305Seric 		CheckpointInterval = atoi(val);
104424944Seric 		break;
104524944Seric 
10469284Seric 	  case 'd':		/* delivery mode */
10479284Seric 		switch (*val)
10488269Seric 		{
10499284Seric 		  case '\0':
105058734Seric 			e->e_sendmode = SM_DELIVER;
10518269Seric 			break;
10528269Seric 
105310755Seric 		  case SM_QUEUE:	/* queue only */
105410755Seric #ifndef QUEUE
105510755Seric 			syserr("need QUEUE to set -odqueue");
105656795Seric #endif /* QUEUE */
105710755Seric 			/* fall through..... */
105810755Seric 
10599284Seric 		  case SM_DELIVER:	/* do everything */
10609284Seric 		  case SM_FORK:		/* fork after verification */
106158734Seric 			e->e_sendmode = *val;
10628269Seric 			break;
10638269Seric 
10648269Seric 		  default:
10659284Seric 			syserr("Unknown delivery mode %c", *val);
10668269Seric 			exit(EX_USAGE);
10678269Seric 		}
10688269Seric 		break;
10698269Seric 
10709146Seric 	  case 'D':		/* rebuild alias database as needed */
10719381Seric 		AutoRebuild = atobool(val);
10729146Seric 		break;
10739146Seric 
107455372Seric 	  case 'E':		/* error message header/header file */
107555379Seric 		if (*val != '\0')
107655379Seric 			ErrMsgFile = newstr(val);
107755372Seric 		break;
107855372Seric 
10798269Seric 	  case 'e':		/* set error processing mode */
10808269Seric 		switch (*val)
10818269Seric 		{
10829381Seric 		  case EM_QUIET:	/* be silent about it */
10839381Seric 		  case EM_MAIL:		/* mail back */
10849381Seric 		  case EM_BERKNET:	/* do berknet error processing */
10859381Seric 		  case EM_WRITE:	/* write back (or mail) */
10868269Seric 			HoldErrs = TRUE;
10879381Seric 			/* fall through... */
10888269Seric 
10899381Seric 		  case EM_PRINT:	/* print errors normally (default) */
109058734Seric 			e->e_errormode = *val;
10918269Seric 			break;
10928269Seric 		}
10938269Seric 		break;
10948269Seric 
10959049Seric 	  case 'F':		/* file mode */
109617975Seric 		FileMode = atooct(val) & 0777;
10979049Seric 		break;
10989049Seric 
10998269Seric 	  case 'f':		/* save Unix-style From lines on front */
11009381Seric 		SaveFrom = atobool(val);
11018269Seric 		break;
11028269Seric 
110353735Seric 	  case 'G':		/* match recipients against GECOS field */
110453735Seric 		MatchGecos = atobool(val);
110553735Seric 		break;
110653735Seric 
11078256Seric 	  case 'g':		/* default gid */
110817474Seric 		DefGid = atoi(val);
11098256Seric 		break;
11108256Seric 
11118256Seric 	  case 'H':		/* help file */
11129381Seric 		if (val[0] == '\0')
11138269Seric 			HelpFile = "sendmail.hf";
11149381Seric 		else
11159381Seric 			HelpFile = newstr(val);
11168256Seric 		break;
11178256Seric 
111851305Seric 	  case 'h':		/* maximum hop count */
111951305Seric 		MaxHopCount = atoi(val);
112051305Seric 		break;
112151305Seric 
112235651Seric 	  case 'I':		/* use internet domain name server */
112357207Seric #ifdef NAMED_BIND
112457207Seric 		UseNameServer = TRUE;
112557207Seric 		for (p = val; *p != 0; )
112657207Seric 		{
112757207Seric 			bool clearmode;
112857207Seric 			char *q;
112957207Seric 			struct resolverflags *rfp;
113057207Seric 
113157207Seric 			while (*p == ' ')
113257207Seric 				p++;
113357207Seric 			if (*p == '\0')
113457207Seric 				break;
113557207Seric 			clearmode = FALSE;
113657207Seric 			if (*p == '-')
113757207Seric 				clearmode = TRUE;
113857207Seric 			else if (*p != '+')
113957207Seric 				p--;
114057207Seric 			p++;
114157207Seric 			q = p;
114258050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
114357207Seric 				p++;
114457207Seric 			if (*p != '\0')
114557207Seric 				*p++ = '\0';
114657207Seric 			for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
114757207Seric 			{
114857207Seric 				if (strcasecmp(q, rfp->rf_name) == 0)
114957207Seric 					break;
115057207Seric 			}
115157207Seric 			if (clearmode)
115257207Seric 				_res.options &= ~rfp->rf_bits;
115357207Seric 			else
115457207Seric 				_res.options |= rfp->rf_bits;
115557207Seric 		}
115657207Seric 		if (tTd(8, 2))
115757207Seric 			printf("_res.options = %x\n", _res.options);
115857207Seric #else
115957207Seric 		usrerr("name server (I option) specified but BIND not compiled in");
116057207Seric #endif
116135651Seric 		break;
116235651Seric 
11638269Seric 	  case 'i':		/* ignore dot lines in message */
11649381Seric 		IgnrDot = atobool(val);
11658269Seric 		break;
11668269Seric 
116759730Seric 	  case 'j':		/* send errors in MIME (RFC 1341) format */
116859730Seric 		SendMIMEErrors = atobool(val);
116959730Seric 		break;
117059730Seric 
117157136Seric 	  case 'J':		/* .forward search path */
117257136Seric 		ForwardPath = newstr(val);
117357136Seric 		break;
117457136Seric 
117554967Seric 	  case 'k':		/* connection cache size */
117654967Seric 		MaxMciCache = atoi(val);
117756215Seric 		if (MaxMciCache < 0)
117856215Seric 			MaxMciCache = 0;
117954967Seric 		break;
118054967Seric 
118154967Seric 	  case 'K':		/* connection cache timeout */
118258796Seric 		MciCacheTimeout = convtime(val, 'm');
118354967Seric 		break;
118454967Seric 
118561104Seric 	  case 'l':		/* use Errors-To: header */
118661104Seric 		UseErrorsTo = atobool(val);
118761104Seric 		break;
118861104Seric 
11898256Seric 	  case 'L':		/* log level */
11909381Seric 		LogLevel = atoi(val);
11918256Seric 		break;
11928256Seric 
11938269Seric 	  case 'M':		/* define macro */
11949381Seric 		define(val[0], newstr(&val[1]), CurEnv);
119516878Seric 		sticky = FALSE;
11968269Seric 		break;
11978269Seric 
11988269Seric 	  case 'm':		/* send to me too */
11999381Seric 		MeToo = atobool(val);
12008269Seric 		break;
12018269Seric 
120225820Seric 	  case 'n':		/* validate RHS in newaliases */
120325820Seric 		CheckAliases = atobool(val);
120425820Seric 		break;
120525820Seric 
120661104Seric 	    /* 'N' available -- was "net name" */
120761104Seric 
120858851Seric 	  case 'O':		/* daemon options */
120958851Seric 		setdaemonoptions(val);
121058851Seric 		break;
121158851Seric 
12128269Seric 	  case 'o':		/* assume old style headers */
12139381Seric 		if (atobool(val))
12149341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
12159341Seric 		else
12169341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
12178269Seric 		break;
12188269Seric 
121958082Seric 	  case 'p':		/* select privacy level */
122058082Seric 		p = val;
122158082Seric 		for (;;)
122258082Seric 		{
122358082Seric 			register struct prival *pv;
122458082Seric 			extern struct prival PrivacyValues[];
122558082Seric 
122658082Seric 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
122758082Seric 				p++;
122858082Seric 			if (*p == '\0')
122958082Seric 				break;
123058082Seric 			val = p;
123158082Seric 			while (isascii(*p) && isalnum(*p))
123258082Seric 				p++;
123358082Seric 			if (*p != '\0')
123458082Seric 				*p++ = '\0';
123558082Seric 
123658082Seric 			for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
123758082Seric 			{
123858082Seric 				if (strcasecmp(val, pv->pv_name) == 0)
123958082Seric 					break;
124058082Seric 			}
124158886Seric 			if (pv->pv_name == NULL)
124258886Seric 				syserr("readcf: Op line: %s unrecognized", val);
124358082Seric 			PrivacyFlags |= pv->pv_flag;
124458082Seric 		}
124558082Seric 		break;
124658082Seric 
124724944Seric 	  case 'P':		/* postmaster copy address for returned mail */
124824944Seric 		PostMasterCopy = newstr(val);
124924944Seric 		break;
125024944Seric 
125124944Seric 	  case 'q':		/* slope of queue only function */
125224944Seric 		QueueFactor = atoi(val);
125324944Seric 		break;
125424944Seric 
12558256Seric 	  case 'Q':		/* queue directory */
12569381Seric 		if (val[0] == '\0')
12578269Seric 			QueueDir = "mqueue";
12589381Seric 		else
12599381Seric 			QueueDir = newstr(val);
126058789Seric 		if (RealUid != 0 && !safe)
126158789Seric 			auth_warning(e, "Processed from queue %s", QueueDir);
12628256Seric 		break;
12638256Seric 
126458148Seric 	  case 'R':		/* don't prune routes */
126558148Seric 		DontPruneRoutes = atobool(val);
126658148Seric 		break;
126758148Seric 
12688256Seric 	  case 'r':		/* read timeout */
126958112Seric 		settimeouts(val);
12708256Seric 		break;
12718256Seric 
12728256Seric 	  case 'S':		/* status file */
12739381Seric 		if (val[0] == '\0')
12748269Seric 			StatFile = "sendmail.st";
12759381Seric 		else
12769381Seric 			StatFile = newstr(val);
12778256Seric 		break;
12788256Seric 
12798265Seric 	  case 's':		/* be super safe, even if expensive */
12809381Seric 		SuperSafe = atobool(val);
12818256Seric 		break;
12828256Seric 
12838256Seric 	  case 'T':		/* queue timeout */
128458737Seric 		p = strchr(val, '/');
128558737Seric 		if (p != NULL)
128658737Seric 		{
128758737Seric 			*p++ = '\0';
128858796Seric 			TimeOuts.to_q_warning = convtime(p, 'd');
128958737Seric 		}
129058796Seric 		TimeOuts.to_q_return = convtime(val, 'h');
129154967Seric 		break;
12928256Seric 
12938265Seric 	  case 't':		/* time zone name */
129452106Seric 		TimeZoneSpec = newstr(val);
12958265Seric 		break;
12968265Seric 
129750556Seric 	  case 'U':		/* location of user database */
129851360Seric 		UdbSpec = newstr(val);
129950556Seric 		break;
130050556Seric 
13018256Seric 	  case 'u':		/* set default uid */
130217474Seric 		DefUid = atoi(val);
130340973Sbostic 		setdefuser();
13048256Seric 		break;
13058256Seric 
130658851Seric 	  case 'V':		/* fallback MX host */
130758851Seric 		FallBackMX = newstr(val);
130858851Seric 		break;
130958851Seric 
13108269Seric 	  case 'v':		/* run in verbose mode */
13119381Seric 		Verbose = atobool(val);
13128256Seric 		break;
13138256Seric 
131463837Seric 	  case 'w':		/* if we are best MX, try host directly */
131563837Seric 		TryNullMXList = atobool(val);
131663837Seric 		break;
131761104Seric 
131861104Seric 	    /* 'W' available -- was wizard password */
131961104Seric 
132014879Seric 	  case 'x':		/* load avg at which to auto-queue msgs */
132114879Seric 		QueueLA = atoi(val);
132214879Seric 		break;
132314879Seric 
132414879Seric 	  case 'X':		/* load avg at which to auto-reject connections */
132514879Seric 		RefuseLA = atoi(val);
132614879Seric 		break;
132714879Seric 
132824981Seric 	  case 'y':		/* work recipient factor */
132924981Seric 		WkRecipFact = atoi(val);
133024981Seric 		break;
133124981Seric 
133224981Seric 	  case 'Y':		/* fork jobs during queue runs */
133324952Seric 		ForkQueueRuns = atobool(val);
133424952Seric 		break;
133524952Seric 
133624981Seric 	  case 'z':		/* work message class factor */
133724981Seric 		WkClassFact = atoi(val);
133824981Seric 		break;
133924981Seric 
134024981Seric 	  case 'Z':		/* work time factor */
134124981Seric 		WkTimeFact = atoi(val);
134224981Seric 		break;
134324981Seric 
13448256Seric 	  default:
13458256Seric 		break;
13468256Seric 	}
134716878Seric 	if (sticky)
134816878Seric 		setbitn(opt, StickyOpt);
13499188Seric 	return;
13508256Seric }
135110687Seric /*
135210687Seric **  SETCLASS -- set a word into a class
135310687Seric **
135410687Seric **	Parameters:
135510687Seric **		class -- the class to put the word in.
135610687Seric **		word -- the word to enter
135710687Seric **
135810687Seric **	Returns:
135910687Seric **		none.
136010687Seric **
136110687Seric **	Side Effects:
136210687Seric **		puts the word into the symbol table.
136310687Seric */
136410687Seric 
136510687Seric setclass(class, word)
136610687Seric 	int class;
136710687Seric 	char *word;
136810687Seric {
136910687Seric 	register STAB *s;
137010687Seric 
137157943Seric 	if (tTd(37, 8))
137257943Seric 		printf("%s added to class %c\n", word, class);
137310687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
137410687Seric 	setbitn(class, s->s_class);
137510687Seric }
137653654Seric /*
137753654Seric **  MAKEMAPENTRY -- create a map entry
137853654Seric **
137953654Seric **	Parameters:
138053654Seric **		line -- the config file line
138153654Seric **
138253654Seric **	Returns:
138353654Seric **		TRUE if it successfully entered the map entry.
138453654Seric **		FALSE otherwise (usually syntax error).
138553654Seric **
138653654Seric **	Side Effects:
138753654Seric **		Enters the map into the dictionary.
138853654Seric */
138953654Seric 
139053654Seric void
139153654Seric makemapentry(line)
139253654Seric 	char *line;
139353654Seric {
139453654Seric 	register char *p;
139553654Seric 	char *mapname;
139653654Seric 	char *classname;
139764078Seric 	register STAB *s;
139853654Seric 	STAB *class;
139953654Seric 
140058050Seric 	for (p = line; isascii(*p) && isspace(*p); p++)
140153654Seric 		continue;
140258050Seric 	if (!(isascii(*p) && isalnum(*p)))
140353654Seric 	{
140453654Seric 		syserr("readcf: config K line: no map name");
140553654Seric 		return;
140653654Seric 	}
140753654Seric 
140853654Seric 	mapname = p;
140958050Seric 	while (isascii(*++p) && isalnum(*p))
141053654Seric 		continue;
141153654Seric 	if (*p != '\0')
141253654Seric 		*p++ = '\0';
141358050Seric 	while (isascii(*p) && isspace(*p))
141453654Seric 		p++;
141558050Seric 	if (!(isascii(*p) && isalnum(*p)))
141653654Seric 	{
141753654Seric 		syserr("readcf: config K line, map %s: no map class", mapname);
141853654Seric 		return;
141953654Seric 	}
142053654Seric 	classname = p;
142158050Seric 	while (isascii(*++p) && isalnum(*p))
142253654Seric 		continue;
142353654Seric 	if (*p != '\0')
142453654Seric 		*p++ = '\0';
142558050Seric 	while (isascii(*p) && isspace(*p))
142653654Seric 		p++;
142753654Seric 
142853654Seric 	/* look up the class */
142953654Seric 	class = stab(classname, ST_MAPCLASS, ST_FIND);
143053654Seric 	if (class == NULL)
143153654Seric 	{
143253654Seric 		syserr("readcf: map %s: class %s not available", mapname, classname);
143353654Seric 		return;
143453654Seric 	}
143553654Seric 
143653654Seric 	/* enter the map */
143764078Seric 	s = stab(mapname, ST_MAP, ST_ENTER);
143864078Seric 	s->s_map.map_class = &class->s_mapclass;
143964078Seric 	s->s_map.map_mname = newstr(mapname);
144053654Seric 
144164078Seric 	if (class->s_mapclass.map_parse(&s->s_map, p))
144264078Seric 		s->s_map.map_mflags |= MF_VALID;
144364078Seric 
144464078Seric 	if (tTd(37, 5))
144564078Seric 	{
144664078Seric 		printf("map %s, class %s, flags %x, file %s,\n",
144764078Seric 			s->s_map.map_mname, s->s_map.map_class->map_cname,
144864078Seric 			s->s_map.map_mflags,
144964078Seric 			s->s_map.map_file == NULL ? "(null)" : s->s_map.map_file);
145064078Seric 		printf("\tapp %s, domain %s, rebuild %s\n",
145164078Seric 			s->s_map.map_app == NULL ? "(null)" : s->s_map.map_app,
145264078Seric 			s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain,
145364078Seric 			s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild);
145464078Seric 	}
145553654Seric }
145658112Seric /*
145758112Seric **  SETTIMEOUTS -- parse and set timeout values
145858112Seric **
145958112Seric **	Parameters:
146058112Seric **		val -- a pointer to the values.  If NULL, do initial
146158112Seric **			settings.
146258112Seric **
146358112Seric **	Returns:
146458112Seric **		none.
146558112Seric **
146658112Seric **	Side Effects:
146758112Seric **		Initializes the TimeOuts structure
146858112Seric */
146958112Seric 
147058112Seric #define MINUTES	* 60
147158112Seric #define HOUR	* 3600
147258112Seric 
147358112Seric settimeouts(val)
147458112Seric 	register char *val;
147558112Seric {
147658112Seric 	register char *p;
147758671Seric 	extern time_t convtime();
147858112Seric 
147958112Seric 	if (val == NULL)
148058112Seric 	{
148158112Seric 		TimeOuts.to_initial = (time_t) 5 MINUTES;
148258112Seric 		TimeOuts.to_helo = (time_t) 5 MINUTES;
148358112Seric 		TimeOuts.to_mail = (time_t) 10 MINUTES;
148458112Seric 		TimeOuts.to_rcpt = (time_t) 1 HOUR;
148558112Seric 		TimeOuts.to_datainit = (time_t) 5 MINUTES;
148658112Seric 		TimeOuts.to_datablock = (time_t) 1 HOUR;
148758112Seric 		TimeOuts.to_datafinal = (time_t) 1 HOUR;
148858112Seric 		TimeOuts.to_rset = (time_t) 5 MINUTES;
148958112Seric 		TimeOuts.to_quit = (time_t) 2 MINUTES;
149058112Seric 		TimeOuts.to_nextcommand = (time_t) 1 HOUR;
149158112Seric 		TimeOuts.to_miscshort = (time_t) 2 MINUTES;
149258112Seric 		return;
149358112Seric 	}
149458112Seric 
149558112Seric 	for (;; val = p)
149658112Seric 	{
149758112Seric 		while (isascii(*val) && isspace(*val))
149858112Seric 			val++;
149958112Seric 		if (*val == '\0')
150058112Seric 			break;
150158112Seric 		for (p = val; *p != '\0' && *p != ','; p++)
150258112Seric 			continue;
150358112Seric 		if (*p != '\0')
150458112Seric 			*p++ = '\0';
150558112Seric 
150658112Seric 		if (isascii(*val) && isdigit(*val))
150758112Seric 		{
150858112Seric 			/* old syntax -- set everything */
150958796Seric 			TimeOuts.to_mail = convtime(val, 'm');
151058112Seric 			TimeOuts.to_rcpt = TimeOuts.to_mail;
151158112Seric 			TimeOuts.to_datainit = TimeOuts.to_mail;
151258112Seric 			TimeOuts.to_datablock = TimeOuts.to_mail;
151358112Seric 			TimeOuts.to_datafinal = TimeOuts.to_mail;
151458112Seric 			TimeOuts.to_nextcommand = TimeOuts.to_mail;
151558112Seric 			continue;
151658112Seric 		}
151758112Seric 		else
151858112Seric 		{
151958112Seric 			register char *q = strchr(val, '=');
152058112Seric 			time_t to;
152158112Seric 
152258112Seric 			if (q == NULL)
152358112Seric 			{
152458112Seric 				/* syntax error */
152558112Seric 				continue;
152658112Seric 			}
152758112Seric 			*q++ = '\0';
152858796Seric 			to = convtime(q, 'm');
152958112Seric 
153058112Seric 			if (strcasecmp(val, "initial") == 0)
153158112Seric 				TimeOuts.to_initial = to;
153258112Seric 			else if (strcasecmp(val, "mail") == 0)
153358112Seric 				TimeOuts.to_mail = to;
153458112Seric 			else if (strcasecmp(val, "rcpt") == 0)
153558112Seric 				TimeOuts.to_rcpt = to;
153658112Seric 			else if (strcasecmp(val, "datainit") == 0)
153758112Seric 				TimeOuts.to_datainit = to;
153858112Seric 			else if (strcasecmp(val, "datablock") == 0)
153958112Seric 				TimeOuts.to_datablock = to;
154058112Seric 			else if (strcasecmp(val, "datafinal") == 0)
154158112Seric 				TimeOuts.to_datafinal = to;
154258112Seric 			else if (strcasecmp(val, "command") == 0)
154358112Seric 				TimeOuts.to_nextcommand = to;
154458112Seric 			else if (strcasecmp(val, "rset") == 0)
154558112Seric 				TimeOuts.to_rset = to;
154658112Seric 			else if (strcasecmp(val, "helo") == 0)
154758112Seric 				TimeOuts.to_helo = to;
154858112Seric 			else if (strcasecmp(val, "quit") == 0)
154958112Seric 				TimeOuts.to_quit = to;
155058112Seric 			else if (strcasecmp(val, "misc") == 0)
155158112Seric 				TimeOuts.to_miscshort = to;
155258112Seric 			else
155358112Seric 				syserr("settimeouts: invalid timeout %s", val);
155458112Seric 		}
155558112Seric 	}
155658112Seric }
1557