xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 64078)
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*64078Seric static char sccsid[] = "@(#)readcf.c	8.4 (Berkeley) 07/28/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 */
35858333Seric 			define(bp[1], newstr(munchstring(&bp[2], NULL)), e);
3593308Seric 			break;
3603308Seric 
3613387Seric 		  case 'H':		/* required header line */
36257135Seric 			(void) chompheader(&bp[1], TRUE, e);
3633387Seric 			break;
3643387Seric 
3654061Seric 		  case 'C':		/* word class */
3664432Seric 			/* scan the list of words and set class for all */
36757135Seric 			for (p = &bp[2]; *p != '\0'; )
3684061Seric 			{
3694061Seric 				register char *wd;
3704061Seric 				char delim;
3714061Seric 
37258050Seric 				while (*p != '\0' && isascii(*p) && isspace(*p))
3734061Seric 					p++;
3744061Seric 				wd = p;
37558050Seric 				while (*p != '\0' && !(isascii(*p) && isspace(*p)))
3764061Seric 					p++;
3774061Seric 				delim = *p;
3784061Seric 				*p = '\0';
3794061Seric 				if (wd[0] != '\0')
38058148Seric 				{
38158148Seric 					if (tTd(37, 2))
38258148Seric 						printf("setclass(%c, %s)\n",
38358148Seric 							bp[1], wd);
38457135Seric 					setclass(bp[1], wd);
38558148Seric 				}
3864061Seric 				*p = delim;
3874061Seric 			}
3884061Seric 			break;
3894061Seric 
39059272Seric 		  case 'F':		/* word class from file */
39159272Seric 			/* read list of words from argument or file */
39259272Seric 			/* read from file */
39359272Seric 			for (p = &bp[2];
39459272Seric 			     *p != '\0' && !(isascii(*p) && isspace(*p));
39559272Seric 			     p++)
39659272Seric 				continue;
39759272Seric 			if (*p == '\0')
39859272Seric 				p = "%s";
39959272Seric 			else
40059272Seric 			{
40159272Seric 				*p = '\0';
40259272Seric 				while (isascii(*++p) && isspace(*p))
40359272Seric 					continue;
40459272Seric 			}
40559272Seric 			fileclass(bp[1], &bp[2], p, safe);
40659272Seric 			break;
40759272Seric 
40859156Seric #ifdef XLA
40959156Seric 		  case 'L':		/* extended load average description */
41059156Seric 			xla_init(&bp[1]);
41159156Seric 			break;
41259156Seric #endif
41359156Seric 
4144096Seric 		  case 'M':		/* define mailer */
41557135Seric 			makemailer(&bp[1]);
4164096Seric 			break;
4174096Seric 
4188252Seric 		  case 'O':		/* set option */
41958734Seric 			setoption(bp[1], &bp[2], safe, FALSE, e);
4208252Seric 			break;
4218252Seric 
4228252Seric 		  case 'P':		/* set precedence */
4238252Seric 			if (NumPriorities >= MAXPRIORITIES)
4248252Seric 			{
4258547Seric 				toomany('P', MAXPRIORITIES);
4268252Seric 				break;
4278252Seric 			}
42857135Seric 			for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
4298252Seric 				continue;
4308252Seric 			if (*p == '\0')
4318252Seric 				goto badline;
4328252Seric 			*p = '\0';
43357135Seric 			Priorities[NumPriorities].pri_name = newstr(&bp[1]);
4348252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
4358252Seric 			NumPriorities++;
4368252Seric 			break;
4378252Seric 
4388547Seric 		  case 'T':		/* trusted user(s) */
43958161Seric 			/* this option is obsolete, but will be ignored */
4408547Seric 			break;
4418547Seric 
44252645Seric 		  case 'V':		/* configuration syntax version */
44357135Seric 			ConfigLevel = atoi(&bp[1]);
44452645Seric 			break;
44552645Seric 
44653654Seric 		  case 'K':
44757135Seric 			makemapentry(&bp[1]);
44853654Seric 			break;
44953654Seric 
4503308Seric 		  default:
4514061Seric 		  badline:
45257135Seric 			syserr("unknown control line \"%s\"", bp);
4533308Seric 		}
45457135Seric 		if (bp != buf)
45557135Seric 			free(bp);
4563308Seric 	}
45752637Seric 	if (ferror(cf))
45852637Seric 	{
45952647Seric 		syserr("I/O read error", cfname);
46052637Seric 		exit(EX_OSFILE);
46152637Seric 	}
46252637Seric 	fclose(cf);
4639381Seric 	FileName = NULL;
46456836Seric 
46557076Seric 	if (stab("host", ST_MAP, ST_FIND) == NULL)
46657076Seric 	{
46757076Seric 		/* user didn't initialize: set up host map */
46857076Seric 		strcpy(buf, "host host");
46957076Seric 		if (ConfigLevel >= 2)
47057076Seric 			strcat(buf, " -a.");
47157076Seric 		makemapentry(buf);
47257076Seric 	}
4734096Seric }
4744096Seric /*
4758547Seric **  TOOMANY -- signal too many of some option
4768547Seric **
4778547Seric **	Parameters:
4788547Seric **		id -- the id of the error line
4798547Seric **		maxcnt -- the maximum possible values
4808547Seric **
4818547Seric **	Returns:
4828547Seric **		none.
4838547Seric **
4848547Seric **	Side Effects:
4858547Seric **		gives a syserr.
4868547Seric */
4878547Seric 
4888547Seric toomany(id, maxcnt)
4898547Seric 	char id;
4908547Seric 	int maxcnt;
4918547Seric {
4929381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
4938547Seric }
4948547Seric /*
4954432Seric **  FILECLASS -- read members of a class from a file
4964432Seric **
4974432Seric **	Parameters:
4984432Seric **		class -- class to define.
4994432Seric **		filename -- name of file to read.
5004432Seric **		fmt -- scanf string to use for match.
5014432Seric **
5024432Seric **	Returns:
5034432Seric **		none
5044432Seric **
5054432Seric **	Side Effects:
5064432Seric **
5074432Seric **		puts all lines in filename that match a scanf into
5084432Seric **			the named class.
5094432Seric */
5104432Seric 
51154973Seric fileclass(class, filename, fmt, safe)
5124432Seric 	int class;
5134432Seric 	char *filename;
5144432Seric 	char *fmt;
51554973Seric 	bool safe;
5164432Seric {
51725808Seric 	FILE *f;
51854973Seric 	struct stat stbuf;
5194432Seric 	char buf[MAXLINE];
5204432Seric 
52154973Seric 	if (stat(filename, &stbuf) < 0)
52254973Seric 	{
52354973Seric 		syserr("fileclass: cannot stat %s", filename);
52454973Seric 		return;
52554973Seric 	}
52654973Seric 	if (!S_ISREG(stbuf.st_mode))
52754973Seric 	{
52854973Seric 		syserr("fileclass: %s not a regular file", filename);
52954973Seric 		return;
53054973Seric 	}
53154973Seric 	if (!safe && access(filename, R_OK) < 0)
53254973Seric 	{
53354973Seric 		syserr("fileclass: access denied on %s", filename);
53454973Seric 		return;
53554973Seric 	}
53654973Seric 	f = fopen(filename, "r");
5374432Seric 	if (f == NULL)
5384432Seric 	{
53954973Seric 		syserr("fileclass: cannot open %s", filename);
5404432Seric 		return;
5414432Seric 	}
5424432Seric 
5434432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
5444432Seric 	{
5454432Seric 		register STAB *s;
54625808Seric 		register char *p;
54725808Seric # ifdef SCANF
5484432Seric 		char wordbuf[MAXNAME+1];
5494432Seric 
5504432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
5514432Seric 			continue;
55225808Seric 		p = wordbuf;
55356795Seric # else /* SCANF */
55425808Seric 		p = buf;
55556795Seric # endif /* SCANF */
55625808Seric 
55725808Seric 		/*
55825808Seric 		**  Break up the match into words.
55925808Seric 		*/
56025808Seric 
56125808Seric 		while (*p != '\0')
56225808Seric 		{
56325808Seric 			register char *q;
56425808Seric 
56525808Seric 			/* strip leading spaces */
56658050Seric 			while (isascii(*p) && isspace(*p))
56725808Seric 				p++;
56825808Seric 			if (*p == '\0')
56925808Seric 				break;
57025808Seric 
57125808Seric 			/* find the end of the word */
57225808Seric 			q = p;
57358050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
57425808Seric 				p++;
57525808Seric 			if (*p != '\0')
57625808Seric 				*p++ = '\0';
57725808Seric 
57825808Seric 			/* enter the word in the symbol table */
57925808Seric 			s = stab(q, ST_CLASS, ST_ENTER);
58025808Seric 			setbitn(class, s->s_class);
58125808Seric 		}
5824432Seric 	}
5834432Seric 
58454973Seric 	(void) fclose(f);
5854432Seric }
5864432Seric /*
5874096Seric **  MAKEMAILER -- define a new mailer.
5884096Seric **
5894096Seric **	Parameters:
59010327Seric **		line -- description of mailer.  This is in labeled
59110327Seric **			fields.  The fields are:
59210327Seric **			   P -- the path to the mailer
59310327Seric **			   F -- the flags associated with the mailer
59410327Seric **			   A -- the argv for this mailer
59510327Seric **			   S -- the sender rewriting set
59610327Seric **			   R -- the recipient rewriting set
59710327Seric **			   E -- the eol string
59810327Seric **			The first word is the canonical name of the mailer.
5994096Seric **
6004096Seric **	Returns:
6014096Seric **		none.
6024096Seric **
6034096Seric **	Side Effects:
6044096Seric **		enters the mailer into the mailer table.
6054096Seric */
6063308Seric 
60721066Seric makemailer(line)
6084096Seric 	char *line;
6094096Seric {
6104096Seric 	register char *p;
6118067Seric 	register struct mailer *m;
6128067Seric 	register STAB *s;
6138067Seric 	int i;
61410327Seric 	char fcode;
61558020Seric 	auto char *endp;
6164096Seric 	extern int NextMailer;
61710327Seric 	extern char **makeargv();
61810327Seric 	extern char *munchstring();
61910701Seric 	extern long atol();
6204096Seric 
62110327Seric 	/* allocate a mailer and set up defaults */
62210327Seric 	m = (struct mailer *) xalloc(sizeof *m);
62310327Seric 	bzero((char *) m, sizeof *m);
62410327Seric 	m->m_eol = "\n";
62510327Seric 
62610327Seric 	/* collect the mailer name */
62758050Seric 	for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++)
62810327Seric 		continue;
62910327Seric 	if (*p != '\0')
63010327Seric 		*p++ = '\0';
63110327Seric 	m->m_name = newstr(line);
63210327Seric 
63310327Seric 	/* now scan through and assign info from the fields */
63410327Seric 	while (*p != '\0')
63510327Seric 	{
63658333Seric 		auto char *delimptr;
63758333Seric 
63858050Seric 		while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p))))
63910327Seric 			p++;
64010327Seric 
64110327Seric 		/* p now points to field code */
64210327Seric 		fcode = *p;
64310327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
64410327Seric 			p++;
64510327Seric 		if (*p++ != '=')
64610327Seric 		{
64752637Seric 			syserr("mailer %s: `=' expected", m->m_name);
64810327Seric 			return;
64910327Seric 		}
65058050Seric 		while (isascii(*p) && isspace(*p))
65110327Seric 			p++;
65210327Seric 
65310327Seric 		/* p now points to the field body */
65458333Seric 		p = munchstring(p, &delimptr);
65510327Seric 
65610327Seric 		/* install the field into the mailer struct */
65710327Seric 		switch (fcode)
65810327Seric 		{
65910327Seric 		  case 'P':		/* pathname */
66010327Seric 			m->m_mailer = newstr(p);
66110327Seric 			break;
66210327Seric 
66310327Seric 		  case 'F':		/* flags */
66410687Seric 			for (; *p != '\0'; p++)
66558050Seric 				if (!(isascii(*p) && isspace(*p)))
66652637Seric 					setbitn(*p, m->m_flags);
66710327Seric 			break;
66810327Seric 
66910327Seric 		  case 'S':		/* sender rewriting ruleset */
67010327Seric 		  case 'R':		/* recipient rewriting ruleset */
67158020Seric 			i = strtol(p, &endp, 10);
67210327Seric 			if (i < 0 || i >= MAXRWSETS)
67310327Seric 			{
67410327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
67510327Seric 				return;
67610327Seric 			}
67710327Seric 			if (fcode == 'S')
67858020Seric 				m->m_sh_rwset = m->m_se_rwset = i;
67910327Seric 			else
68058020Seric 				m->m_rh_rwset = m->m_re_rwset = i;
68158020Seric 
68258020Seric 			p = endp;
68359985Seric 			if (*p++ == '/')
68458020Seric 			{
68558020Seric 				i = strtol(p, NULL, 10);
68658020Seric 				if (i < 0 || i >= MAXRWSETS)
68758020Seric 				{
68858020Seric 					syserr("invalid rewrite set, %d max",
68958020Seric 						MAXRWSETS);
69058020Seric 					return;
69158020Seric 				}
69258020Seric 				if (fcode == 'S')
69358020Seric 					m->m_sh_rwset = i;
69458020Seric 				else
69558020Seric 					m->m_rh_rwset = i;
69658020Seric 			}
69710327Seric 			break;
69810327Seric 
69910327Seric 		  case 'E':		/* end of line string */
70010327Seric 			m->m_eol = newstr(p);
70110327Seric 			break;
70210327Seric 
70310327Seric 		  case 'A':		/* argument vector */
70410327Seric 			m->m_argv = makeargv(p);
70510327Seric 			break;
70610701Seric 
70710701Seric 		  case 'M':		/* maximum message size */
70810701Seric 			m->m_maxsize = atol(p);
70910701Seric 			break;
71052106Seric 
71152106Seric 		  case 'L':		/* maximum line length */
71252106Seric 			m->m_linelimit = atoi(p);
71352106Seric 			break;
71458935Seric 
71558935Seric 		  case 'D':		/* working directory */
71658935Seric 			m->m_execdir = newstr(p);
71758935Seric 			break;
71810327Seric 		}
71910327Seric 
72058333Seric 		p = delimptr;
72110327Seric 	}
72210327Seric 
72352106Seric 	/* do some heuristic cleanup for back compatibility */
72452106Seric 	if (bitnset(M_LIMITS, m->m_flags))
72552106Seric 	{
72652106Seric 		if (m->m_linelimit == 0)
72752106Seric 			m->m_linelimit = SMTPLINELIM;
72855418Seric 		if (ConfigLevel < 2)
72952106Seric 			setbitn(M_7BITS, m->m_flags);
73052106Seric 	}
73152106Seric 
73258321Seric 	/* do some rationality checking */
73358321Seric 	if (m->m_argv == NULL)
73458321Seric 	{
73558321Seric 		syserr("M%s: A= argument required", m->m_name);
73658321Seric 		return;
73758321Seric 	}
73858321Seric 	if (m->m_mailer == NULL)
73958321Seric 	{
74058321Seric 		syserr("M%s: P= argument required", m->m_name);
74158321Seric 		return;
74258321Seric 	}
74358321Seric 
7444096Seric 	if (NextMailer >= MAXMAILERS)
7454096Seric 	{
7469381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
7474096Seric 		return;
7484096Seric 	}
74957402Seric 
75010327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
75157402Seric 	if (s->s_mailer != NULL)
75257402Seric 	{
75357402Seric 		i = s->s_mailer->m_mno;
75457402Seric 		free(s->s_mailer);
75557402Seric 	}
75657402Seric 	else
75757402Seric 	{
75857402Seric 		i = NextMailer++;
75957402Seric 	}
76057402Seric 	Mailer[i] = s->s_mailer = m;
76157454Seric 	m->m_mno = i;
76210327Seric }
76310327Seric /*
76410327Seric **  MUNCHSTRING -- translate a string into internal form.
76510327Seric **
76610327Seric **	Parameters:
76710327Seric **		p -- the string to munch.
76858333Seric **		delimptr -- if non-NULL, set to the pointer of the
76958333Seric **			field delimiter character.
77010327Seric **
77110327Seric **	Returns:
77210327Seric **		the munched string.
77310327Seric */
7744096Seric 
77510327Seric char *
77658333Seric munchstring(p, delimptr)
77710327Seric 	register char *p;
77858333Seric 	char **delimptr;
77910327Seric {
78010327Seric 	register char *q;
78110327Seric 	bool backslash = FALSE;
78210327Seric 	bool quotemode = FALSE;
78310327Seric 	static char buf[MAXLINE];
7844096Seric 
78510327Seric 	for (q = buf; *p != '\0'; p++)
7864096Seric 	{
78710327Seric 		if (backslash)
78810327Seric 		{
78910327Seric 			/* everything is roughly literal */
79010357Seric 			backslash = FALSE;
79110327Seric 			switch (*p)
79210327Seric 			{
79310327Seric 			  case 'r':		/* carriage return */
79410327Seric 				*q++ = '\r';
79510327Seric 				continue;
79610327Seric 
79710327Seric 			  case 'n':		/* newline */
79810327Seric 				*q++ = '\n';
79910327Seric 				continue;
80010327Seric 
80110327Seric 			  case 'f':		/* form feed */
80210327Seric 				*q++ = '\f';
80310327Seric 				continue;
80410327Seric 
80510327Seric 			  case 'b':		/* backspace */
80610327Seric 				*q++ = '\b';
80710327Seric 				continue;
80810327Seric 			}
80910327Seric 			*q++ = *p;
81010327Seric 		}
81110327Seric 		else
81210327Seric 		{
81310327Seric 			if (*p == '\\')
81410327Seric 				backslash = TRUE;
81510327Seric 			else if (*p == '"')
81610327Seric 				quotemode = !quotemode;
81710327Seric 			else if (quotemode || *p != ',')
81810327Seric 				*q++ = *p;
81910327Seric 			else
82010327Seric 				break;
82110327Seric 		}
8224096Seric 	}
8234096Seric 
82458333Seric 	if (delimptr != NULL)
82558333Seric 		*delimptr = p;
82610327Seric 	*q++ = '\0';
82710327Seric 	return (buf);
82810327Seric }
82910327Seric /*
83010327Seric **  MAKEARGV -- break up a string into words
83110327Seric **
83210327Seric **	Parameters:
83310327Seric **		p -- the string to break up.
83410327Seric **
83510327Seric **	Returns:
83610327Seric **		a char **argv (dynamically allocated)
83710327Seric **
83810327Seric **	Side Effects:
83910327Seric **		munges p.
84010327Seric */
8414096Seric 
84210327Seric char **
84310327Seric makeargv(p)
84410327Seric 	register char *p;
84510327Seric {
84610327Seric 	char *q;
84710327Seric 	int i;
84810327Seric 	char **avp;
84910327Seric 	char *argv[MAXPV + 1];
85010327Seric 
85110327Seric 	/* take apart the words */
85210327Seric 	i = 0;
85310327Seric 	while (*p != '\0' && i < MAXPV)
8544096Seric 	{
85510327Seric 		q = p;
85658050Seric 		while (*p != '\0' && !(isascii(*p) && isspace(*p)))
85710327Seric 			p++;
85858050Seric 		while (isascii(*p) && isspace(*p))
85910327Seric 			*p++ = '\0';
86010327Seric 		argv[i++] = newstr(q);
8614096Seric 	}
86210327Seric 	argv[i++] = NULL;
8634096Seric 
86410327Seric 	/* now make a copy of the argv */
86510327Seric 	avp = (char **) xalloc(sizeof *avp * i);
86616893Seric 	bcopy((char *) argv, (char *) avp, sizeof *avp * i);
86710327Seric 
86810327Seric 	return (avp);
8693308Seric }
8703308Seric /*
8713308Seric **  PRINTRULES -- print rewrite rules (for debugging)
8723308Seric **
8733308Seric **	Parameters:
8743308Seric **		none.
8753308Seric **
8763308Seric **	Returns:
8773308Seric **		none.
8783308Seric **
8793308Seric **	Side Effects:
8803308Seric **		prints rewrite rules.
8813308Seric */
8823308Seric 
8833308Seric printrules()
8843308Seric {
8853308Seric 	register struct rewrite *rwp;
8864072Seric 	register int ruleset;
8873308Seric 
8884072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
8893308Seric 	{
8904072Seric 		if (RewriteRules[ruleset] == NULL)
8914072Seric 			continue;
8928067Seric 		printf("\n----Rule Set %d:", ruleset);
8933308Seric 
8944072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
8953308Seric 		{
8968067Seric 			printf("\nLHS:");
8978067Seric 			printav(rwp->r_lhs);
8988067Seric 			printf("RHS:");
8998067Seric 			printav(rwp->r_rhs);
9003308Seric 		}
9013308Seric 	}
9023308Seric }
9034319Seric 
9044096Seric /*
9058256Seric **  SETOPTION -- set global processing option
9068256Seric **
9078256Seric **	Parameters:
9088256Seric **		opt -- option name.
9098256Seric **		val -- option value (as a text string).
91021755Seric **		safe -- set if this came from a configuration file.
91121755Seric **			Some options (if set from the command line) will
91221755Seric **			reset the user id to avoid security problems.
9138269Seric **		sticky -- if set, don't let other setoptions override
9148269Seric **			this value.
91558734Seric **		e -- the main envelope.
9168256Seric **
9178256Seric **	Returns:
9188256Seric **		none.
9198256Seric **
9208256Seric **	Side Effects:
9218256Seric **		Sets options as implied by the arguments.
9228256Seric */
9238256Seric 
92410687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
9258269Seric 
92657207Seric 
92757207Seric #ifdef NAMED_BIND
92857207Seric 
92957207Seric struct resolverflags
93057207Seric {
93157207Seric 	char	*rf_name;	/* name of the flag */
93257207Seric 	long	rf_bits;	/* bits to set/clear */
93357207Seric } ResolverFlags[] =
93457207Seric {
93557207Seric 	"debug",	RES_DEBUG,
93657207Seric 	"aaonly",	RES_AAONLY,
93757207Seric 	"usevc",	RES_USEVC,
93857207Seric 	"primary",	RES_PRIMARY,
93957207Seric 	"igntc",	RES_IGNTC,
94057207Seric 	"recurse",	RES_RECURSE,
94157207Seric 	"defnames",	RES_DEFNAMES,
94257207Seric 	"stayopen",	RES_STAYOPEN,
94357207Seric 	"dnsrch",	RES_DNSRCH,
94457207Seric 	NULL,		0
94557207Seric };
94657207Seric 
94757207Seric #endif
94857207Seric 
94958734Seric setoption(opt, val, safe, sticky, e)
9508256Seric 	char opt;
9518256Seric 	char *val;
95221755Seric 	bool safe;
9538269Seric 	bool sticky;
95458734Seric 	register ENVELOPE *e;
9558256Seric {
95657207Seric 	register char *p;
9578265Seric 	extern bool atobool();
95812633Seric 	extern time_t convtime();
95914879Seric 	extern int QueueLA;
96014879Seric 	extern int RefuseLA;
96117474Seric 	extern bool trusteduser();
9628256Seric 
9638256Seric 	if (tTd(37, 1))
9649341Seric 		printf("setoption %c=%s", opt, val);
9658256Seric 
9668256Seric 	/*
9678269Seric 	**  See if this option is preset for us.
9688256Seric 	*/
9698256Seric 
97059731Seric 	if (!sticky && bitnset(opt, StickyOpt))
9718269Seric 	{
9729341Seric 		if (tTd(37, 1))
9739341Seric 			printf(" (ignored)\n");
9748269Seric 		return;
9758269Seric 	}
9768269Seric 
97721755Seric 	/*
97821755Seric 	**  Check to see if this option can be specified by this user.
97921755Seric 	*/
98021755Seric 
98163787Seric 	if (!safe && RealUid == 0)
98221755Seric 		safe = TRUE;
98363837Seric 	if (!safe && strchr("bCdeEijLmoprsvw7", opt) == NULL)
98421755Seric 	{
98539111Srick 		if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
98621755Seric 		{
98736582Sbostic 			if (tTd(37, 1))
98836582Sbostic 				printf(" (unsafe)");
98963787Seric 			if (RealUid != geteuid())
99036582Sbostic 			{
99151210Seric 				if (tTd(37, 1))
99251210Seric 					printf("(Resetting uid)");
99363787Seric 				(void) setgid(RealGid);
99463787Seric 				(void) setuid(RealUid);
99536582Sbostic 			}
99621755Seric 		}
99721755Seric 	}
99851210Seric 	if (tTd(37, 1))
99917985Seric 		printf("\n");
10008269Seric 
10018256Seric 	switch (opt)
10028256Seric 	{
100359709Seric 	  case '7':		/* force seven-bit input */
100459709Seric 		SevenBit = atobool(val);
100552106Seric 		break;
100652106Seric 
10078256Seric 	  case 'A':		/* set default alias file */
10089381Seric 		if (val[0] == '\0')
100959672Seric 			setalias("aliases");
10109381Seric 		else
101159672Seric 			setalias(val);
10128256Seric 		break;
10138256Seric 
101417474Seric 	  case 'a':		/* look N minutes for "@:@" in alias file */
101517474Seric 		if (val[0] == '\0')
101617474Seric 			SafeAlias = 5;
101717474Seric 		else
101817474Seric 			SafeAlias = atoi(val);
101917474Seric 		break;
102017474Seric 
102116843Seric 	  case 'B':		/* substitution for blank character */
102216843Seric 		SpaceSub = val[0];
102316843Seric 		if (SpaceSub == '\0')
102416843Seric 			SpaceSub = ' ';
102516843Seric 		break;
102616843Seric 
102759283Seric 	  case 'b':		/* min blocks free on queue fs/max msg size */
102859283Seric 		p = strchr(val, '/');
102959283Seric 		if (p != NULL)
103059283Seric 		{
103159283Seric 			*p++ = '\0';
103259283Seric 			MaxMessageSize = atol(p);
103359283Seric 		}
103458082Seric 		MinBlocksFree = atol(val);
103558082Seric 		break;
103658082Seric 
10379284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
10389381Seric 		NoConnect = atobool(val);
10399284Seric 		break;
10409284Seric 
104151305Seric 	  case 'C':		/* checkpoint every N addresses */
104251305Seric 		CheckpointInterval = atoi(val);
104324944Seric 		break;
104424944Seric 
10459284Seric 	  case 'd':		/* delivery mode */
10469284Seric 		switch (*val)
10478269Seric 		{
10489284Seric 		  case '\0':
104958734Seric 			e->e_sendmode = SM_DELIVER;
10508269Seric 			break;
10518269Seric 
105210755Seric 		  case SM_QUEUE:	/* queue only */
105310755Seric #ifndef QUEUE
105410755Seric 			syserr("need QUEUE to set -odqueue");
105556795Seric #endif /* QUEUE */
105610755Seric 			/* fall through..... */
105710755Seric 
10589284Seric 		  case SM_DELIVER:	/* do everything */
10599284Seric 		  case SM_FORK:		/* fork after verification */
106058734Seric 			e->e_sendmode = *val;
10618269Seric 			break;
10628269Seric 
10638269Seric 		  default:
10649284Seric 			syserr("Unknown delivery mode %c", *val);
10658269Seric 			exit(EX_USAGE);
10668269Seric 		}
10678269Seric 		break;
10688269Seric 
10699146Seric 	  case 'D':		/* rebuild alias database as needed */
10709381Seric 		AutoRebuild = atobool(val);
10719146Seric 		break;
10729146Seric 
107355372Seric 	  case 'E':		/* error message header/header file */
107455379Seric 		if (*val != '\0')
107555379Seric 			ErrMsgFile = newstr(val);
107655372Seric 		break;
107755372Seric 
10788269Seric 	  case 'e':		/* set error processing mode */
10798269Seric 		switch (*val)
10808269Seric 		{
10819381Seric 		  case EM_QUIET:	/* be silent about it */
10829381Seric 		  case EM_MAIL:		/* mail back */
10839381Seric 		  case EM_BERKNET:	/* do berknet error processing */
10849381Seric 		  case EM_WRITE:	/* write back (or mail) */
10858269Seric 			HoldErrs = TRUE;
10869381Seric 			/* fall through... */
10878269Seric 
10889381Seric 		  case EM_PRINT:	/* print errors normally (default) */
108958734Seric 			e->e_errormode = *val;
10908269Seric 			break;
10918269Seric 		}
10928269Seric 		break;
10938269Seric 
10949049Seric 	  case 'F':		/* file mode */
109517975Seric 		FileMode = atooct(val) & 0777;
10969049Seric 		break;
10979049Seric 
10988269Seric 	  case 'f':		/* save Unix-style From lines on front */
10999381Seric 		SaveFrom = atobool(val);
11008269Seric 		break;
11018269Seric 
110253735Seric 	  case 'G':		/* match recipients against GECOS field */
110353735Seric 		MatchGecos = atobool(val);
110453735Seric 		break;
110553735Seric 
11068256Seric 	  case 'g':		/* default gid */
110717474Seric 		DefGid = atoi(val);
11088256Seric 		break;
11098256Seric 
11108256Seric 	  case 'H':		/* help file */
11119381Seric 		if (val[0] == '\0')
11128269Seric 			HelpFile = "sendmail.hf";
11139381Seric 		else
11149381Seric 			HelpFile = newstr(val);
11158256Seric 		break;
11168256Seric 
111751305Seric 	  case 'h':		/* maximum hop count */
111851305Seric 		MaxHopCount = atoi(val);
111951305Seric 		break;
112051305Seric 
112135651Seric 	  case 'I':		/* use internet domain name server */
112257207Seric #ifdef NAMED_BIND
112357207Seric 		UseNameServer = TRUE;
112457207Seric 		for (p = val; *p != 0; )
112557207Seric 		{
112657207Seric 			bool clearmode;
112757207Seric 			char *q;
112857207Seric 			struct resolverflags *rfp;
112957207Seric 
113057207Seric 			while (*p == ' ')
113157207Seric 				p++;
113257207Seric 			if (*p == '\0')
113357207Seric 				break;
113457207Seric 			clearmode = FALSE;
113557207Seric 			if (*p == '-')
113657207Seric 				clearmode = TRUE;
113757207Seric 			else if (*p != '+')
113857207Seric 				p--;
113957207Seric 			p++;
114057207Seric 			q = p;
114158050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
114257207Seric 				p++;
114357207Seric 			if (*p != '\0')
114457207Seric 				*p++ = '\0';
114557207Seric 			for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
114657207Seric 			{
114757207Seric 				if (strcasecmp(q, rfp->rf_name) == 0)
114857207Seric 					break;
114957207Seric 			}
115057207Seric 			if (clearmode)
115157207Seric 				_res.options &= ~rfp->rf_bits;
115257207Seric 			else
115357207Seric 				_res.options |= rfp->rf_bits;
115457207Seric 		}
115557207Seric 		if (tTd(8, 2))
115657207Seric 			printf("_res.options = %x\n", _res.options);
115757207Seric #else
115857207Seric 		usrerr("name server (I option) specified but BIND not compiled in");
115957207Seric #endif
116035651Seric 		break;
116135651Seric 
11628269Seric 	  case 'i':		/* ignore dot lines in message */
11639381Seric 		IgnrDot = atobool(val);
11648269Seric 		break;
11658269Seric 
116659730Seric 	  case 'j':		/* send errors in MIME (RFC 1341) format */
116759730Seric 		SendMIMEErrors = atobool(val);
116859730Seric 		break;
116959730Seric 
117057136Seric 	  case 'J':		/* .forward search path */
117157136Seric 		ForwardPath = newstr(val);
117257136Seric 		break;
117357136Seric 
117454967Seric 	  case 'k':		/* connection cache size */
117554967Seric 		MaxMciCache = atoi(val);
117656215Seric 		if (MaxMciCache < 0)
117756215Seric 			MaxMciCache = 0;
117854967Seric 		break;
117954967Seric 
118054967Seric 	  case 'K':		/* connection cache timeout */
118158796Seric 		MciCacheTimeout = convtime(val, 'm');
118254967Seric 		break;
118354967Seric 
118461104Seric 	  case 'l':		/* use Errors-To: header */
118561104Seric 		UseErrorsTo = atobool(val);
118661104Seric 		break;
118761104Seric 
11888256Seric 	  case 'L':		/* log level */
11899381Seric 		LogLevel = atoi(val);
11908256Seric 		break;
11918256Seric 
11928269Seric 	  case 'M':		/* define macro */
11939381Seric 		define(val[0], newstr(&val[1]), CurEnv);
119416878Seric 		sticky = FALSE;
11958269Seric 		break;
11968269Seric 
11978269Seric 	  case 'm':		/* send to me too */
11989381Seric 		MeToo = atobool(val);
11998269Seric 		break;
12008269Seric 
120125820Seric 	  case 'n':		/* validate RHS in newaliases */
120225820Seric 		CheckAliases = atobool(val);
120325820Seric 		break;
120425820Seric 
120561104Seric 	    /* 'N' available -- was "net name" */
120661104Seric 
120758851Seric 	  case 'O':		/* daemon options */
120858851Seric 		setdaemonoptions(val);
120958851Seric 		break;
121058851Seric 
12118269Seric 	  case 'o':		/* assume old style headers */
12129381Seric 		if (atobool(val))
12139341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
12149341Seric 		else
12159341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
12168269Seric 		break;
12178269Seric 
121858082Seric 	  case 'p':		/* select privacy level */
121958082Seric 		p = val;
122058082Seric 		for (;;)
122158082Seric 		{
122258082Seric 			register struct prival *pv;
122358082Seric 			extern struct prival PrivacyValues[];
122458082Seric 
122558082Seric 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
122658082Seric 				p++;
122758082Seric 			if (*p == '\0')
122858082Seric 				break;
122958082Seric 			val = p;
123058082Seric 			while (isascii(*p) && isalnum(*p))
123158082Seric 				p++;
123258082Seric 			if (*p != '\0')
123358082Seric 				*p++ = '\0';
123458082Seric 
123558082Seric 			for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
123658082Seric 			{
123758082Seric 				if (strcasecmp(val, pv->pv_name) == 0)
123858082Seric 					break;
123958082Seric 			}
124058886Seric 			if (pv->pv_name == NULL)
124158886Seric 				syserr("readcf: Op line: %s unrecognized", val);
124258082Seric 			PrivacyFlags |= pv->pv_flag;
124358082Seric 		}
124458082Seric 		break;
124558082Seric 
124624944Seric 	  case 'P':		/* postmaster copy address for returned mail */
124724944Seric 		PostMasterCopy = newstr(val);
124824944Seric 		break;
124924944Seric 
125024944Seric 	  case 'q':		/* slope of queue only function */
125124944Seric 		QueueFactor = atoi(val);
125224944Seric 		break;
125324944Seric 
12548256Seric 	  case 'Q':		/* queue directory */
12559381Seric 		if (val[0] == '\0')
12568269Seric 			QueueDir = "mqueue";
12579381Seric 		else
12589381Seric 			QueueDir = newstr(val);
125958789Seric 		if (RealUid != 0 && !safe)
126058789Seric 			auth_warning(e, "Processed from queue %s", QueueDir);
12618256Seric 		break;
12628256Seric 
126358148Seric 	  case 'R':		/* don't prune routes */
126458148Seric 		DontPruneRoutes = atobool(val);
126558148Seric 		break;
126658148Seric 
12678256Seric 	  case 'r':		/* read timeout */
126858112Seric 		settimeouts(val);
12698256Seric 		break;
12708256Seric 
12718256Seric 	  case 'S':		/* status file */
12729381Seric 		if (val[0] == '\0')
12738269Seric 			StatFile = "sendmail.st";
12749381Seric 		else
12759381Seric 			StatFile = newstr(val);
12768256Seric 		break;
12778256Seric 
12788265Seric 	  case 's':		/* be super safe, even if expensive */
12799381Seric 		SuperSafe = atobool(val);
12808256Seric 		break;
12818256Seric 
12828256Seric 	  case 'T':		/* queue timeout */
128358737Seric 		p = strchr(val, '/');
128458737Seric 		if (p != NULL)
128558737Seric 		{
128658737Seric 			*p++ = '\0';
128758796Seric 			TimeOuts.to_q_warning = convtime(p, 'd');
128858737Seric 		}
128958796Seric 		TimeOuts.to_q_return = convtime(val, 'h');
129054967Seric 		break;
12918256Seric 
12928265Seric 	  case 't':		/* time zone name */
129352106Seric 		TimeZoneSpec = newstr(val);
12948265Seric 		break;
12958265Seric 
129650556Seric 	  case 'U':		/* location of user database */
129751360Seric 		UdbSpec = newstr(val);
129850556Seric 		break;
129950556Seric 
13008256Seric 	  case 'u':		/* set default uid */
130117474Seric 		DefUid = atoi(val);
130240973Sbostic 		setdefuser();
13038256Seric 		break;
13048256Seric 
130558851Seric 	  case 'V':		/* fallback MX host */
130658851Seric 		FallBackMX = newstr(val);
130758851Seric 		break;
130858851Seric 
13098269Seric 	  case 'v':		/* run in verbose mode */
13109381Seric 		Verbose = atobool(val);
13118256Seric 		break;
13128256Seric 
131363837Seric 	  case 'w':		/* if we are best MX, try host directly */
131463837Seric 		TryNullMXList = atobool(val);
131563837Seric 		break;
131661104Seric 
131761104Seric 	    /* 'W' available -- was wizard password */
131861104Seric 
131914879Seric 	  case 'x':		/* load avg at which to auto-queue msgs */
132014879Seric 		QueueLA = atoi(val);
132114879Seric 		break;
132214879Seric 
132314879Seric 	  case 'X':		/* load avg at which to auto-reject connections */
132414879Seric 		RefuseLA = atoi(val);
132514879Seric 		break;
132614879Seric 
132724981Seric 	  case 'y':		/* work recipient factor */
132824981Seric 		WkRecipFact = atoi(val);
132924981Seric 		break;
133024981Seric 
133124981Seric 	  case 'Y':		/* fork jobs during queue runs */
133224952Seric 		ForkQueueRuns = atobool(val);
133324952Seric 		break;
133424952Seric 
133524981Seric 	  case 'z':		/* work message class factor */
133624981Seric 		WkClassFact = atoi(val);
133724981Seric 		break;
133824981Seric 
133924981Seric 	  case 'Z':		/* work time factor */
134024981Seric 		WkTimeFact = atoi(val);
134124981Seric 		break;
134224981Seric 
13438256Seric 	  default:
13448256Seric 		break;
13458256Seric 	}
134616878Seric 	if (sticky)
134716878Seric 		setbitn(opt, StickyOpt);
13489188Seric 	return;
13498256Seric }
135010687Seric /*
135110687Seric **  SETCLASS -- set a word into a class
135210687Seric **
135310687Seric **	Parameters:
135410687Seric **		class -- the class to put the word in.
135510687Seric **		word -- the word to enter
135610687Seric **
135710687Seric **	Returns:
135810687Seric **		none.
135910687Seric **
136010687Seric **	Side Effects:
136110687Seric **		puts the word into the symbol table.
136210687Seric */
136310687Seric 
136410687Seric setclass(class, word)
136510687Seric 	int class;
136610687Seric 	char *word;
136710687Seric {
136810687Seric 	register STAB *s;
136910687Seric 
137057943Seric 	if (tTd(37, 8))
137157943Seric 		printf("%s added to class %c\n", word, class);
137210687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
137310687Seric 	setbitn(class, s->s_class);
137410687Seric }
137553654Seric /*
137653654Seric **  MAKEMAPENTRY -- create a map entry
137753654Seric **
137853654Seric **	Parameters:
137953654Seric **		line -- the config file line
138053654Seric **
138153654Seric **	Returns:
138253654Seric **		TRUE if it successfully entered the map entry.
138353654Seric **		FALSE otherwise (usually syntax error).
138453654Seric **
138553654Seric **	Side Effects:
138653654Seric **		Enters the map into the dictionary.
138753654Seric */
138853654Seric 
138953654Seric void
139053654Seric makemapentry(line)
139153654Seric 	char *line;
139253654Seric {
139353654Seric 	register char *p;
139453654Seric 	char *mapname;
139553654Seric 	char *classname;
1396*64078Seric 	register STAB *s;
139753654Seric 	STAB *class;
139853654Seric 
139958050Seric 	for (p = line; isascii(*p) && isspace(*p); p++)
140053654Seric 		continue;
140158050Seric 	if (!(isascii(*p) && isalnum(*p)))
140253654Seric 	{
140353654Seric 		syserr("readcf: config K line: no map name");
140453654Seric 		return;
140553654Seric 	}
140653654Seric 
140753654Seric 	mapname = p;
140858050Seric 	while (isascii(*++p) && isalnum(*p))
140953654Seric 		continue;
141053654Seric 	if (*p != '\0')
141153654Seric 		*p++ = '\0';
141258050Seric 	while (isascii(*p) && isspace(*p))
141353654Seric 		p++;
141458050Seric 	if (!(isascii(*p) && isalnum(*p)))
141553654Seric 	{
141653654Seric 		syserr("readcf: config K line, map %s: no map class", mapname);
141753654Seric 		return;
141853654Seric 	}
141953654Seric 	classname = p;
142058050Seric 	while (isascii(*++p) && isalnum(*p))
142153654Seric 		continue;
142253654Seric 	if (*p != '\0')
142353654Seric 		*p++ = '\0';
142458050Seric 	while (isascii(*p) && isspace(*p))
142553654Seric 		p++;
142653654Seric 
142753654Seric 	/* look up the class */
142853654Seric 	class = stab(classname, ST_MAPCLASS, ST_FIND);
142953654Seric 	if (class == NULL)
143053654Seric 	{
143153654Seric 		syserr("readcf: map %s: class %s not available", mapname, classname);
143253654Seric 		return;
143353654Seric 	}
143453654Seric 
143553654Seric 	/* enter the map */
1436*64078Seric 	s = stab(mapname, ST_MAP, ST_ENTER);
1437*64078Seric 	s->s_map.map_class = &class->s_mapclass;
1438*64078Seric 	s->s_map.map_mname = newstr(mapname);
143953654Seric 
1440*64078Seric 	if (class->s_mapclass.map_parse(&s->s_map, p))
1441*64078Seric 		s->s_map.map_mflags |= MF_VALID;
1442*64078Seric 
1443*64078Seric 	if (tTd(37, 5))
1444*64078Seric 	{
1445*64078Seric 		printf("map %s, class %s, flags %x, file %s,\n",
1446*64078Seric 			s->s_map.map_mname, s->s_map.map_class->map_cname,
1447*64078Seric 			s->s_map.map_mflags,
1448*64078Seric 			s->s_map.map_file == NULL ? "(null)" : s->s_map.map_file);
1449*64078Seric 		printf("\tapp %s, domain %s, rebuild %s\n",
1450*64078Seric 			s->s_map.map_app == NULL ? "(null)" : s->s_map.map_app,
1451*64078Seric 			s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain,
1452*64078Seric 			s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild);
1453*64078Seric 	}
145453654Seric }
145558112Seric /*
145658112Seric **  SETTIMEOUTS -- parse and set timeout values
145758112Seric **
145858112Seric **	Parameters:
145958112Seric **		val -- a pointer to the values.  If NULL, do initial
146058112Seric **			settings.
146158112Seric **
146258112Seric **	Returns:
146358112Seric **		none.
146458112Seric **
146558112Seric **	Side Effects:
146658112Seric **		Initializes the TimeOuts structure
146758112Seric */
146858112Seric 
146958112Seric #define MINUTES	* 60
147058112Seric #define HOUR	* 3600
147158112Seric 
147258112Seric settimeouts(val)
147358112Seric 	register char *val;
147458112Seric {
147558112Seric 	register char *p;
147658671Seric 	extern time_t convtime();
147758112Seric 
147858112Seric 	if (val == NULL)
147958112Seric 	{
148058112Seric 		TimeOuts.to_initial = (time_t) 5 MINUTES;
148158112Seric 		TimeOuts.to_helo = (time_t) 5 MINUTES;
148258112Seric 		TimeOuts.to_mail = (time_t) 10 MINUTES;
148358112Seric 		TimeOuts.to_rcpt = (time_t) 1 HOUR;
148458112Seric 		TimeOuts.to_datainit = (time_t) 5 MINUTES;
148558112Seric 		TimeOuts.to_datablock = (time_t) 1 HOUR;
148658112Seric 		TimeOuts.to_datafinal = (time_t) 1 HOUR;
148758112Seric 		TimeOuts.to_rset = (time_t) 5 MINUTES;
148858112Seric 		TimeOuts.to_quit = (time_t) 2 MINUTES;
148958112Seric 		TimeOuts.to_nextcommand = (time_t) 1 HOUR;
149058112Seric 		TimeOuts.to_miscshort = (time_t) 2 MINUTES;
149158112Seric 		return;
149258112Seric 	}
149358112Seric 
149458112Seric 	for (;; val = p)
149558112Seric 	{
149658112Seric 		while (isascii(*val) && isspace(*val))
149758112Seric 			val++;
149858112Seric 		if (*val == '\0')
149958112Seric 			break;
150058112Seric 		for (p = val; *p != '\0' && *p != ','; p++)
150158112Seric 			continue;
150258112Seric 		if (*p != '\0')
150358112Seric 			*p++ = '\0';
150458112Seric 
150558112Seric 		if (isascii(*val) && isdigit(*val))
150658112Seric 		{
150758112Seric 			/* old syntax -- set everything */
150858796Seric 			TimeOuts.to_mail = convtime(val, 'm');
150958112Seric 			TimeOuts.to_rcpt = TimeOuts.to_mail;
151058112Seric 			TimeOuts.to_datainit = TimeOuts.to_mail;
151158112Seric 			TimeOuts.to_datablock = TimeOuts.to_mail;
151258112Seric 			TimeOuts.to_datafinal = TimeOuts.to_mail;
151358112Seric 			TimeOuts.to_nextcommand = TimeOuts.to_mail;
151458112Seric 			continue;
151558112Seric 		}
151658112Seric 		else
151758112Seric 		{
151858112Seric 			register char *q = strchr(val, '=');
151958112Seric 			time_t to;
152058112Seric 
152158112Seric 			if (q == NULL)
152258112Seric 			{
152358112Seric 				/* syntax error */
152458112Seric 				continue;
152558112Seric 			}
152658112Seric 			*q++ = '\0';
152758796Seric 			to = convtime(q, 'm');
152858112Seric 
152958112Seric 			if (strcasecmp(val, "initial") == 0)
153058112Seric 				TimeOuts.to_initial = to;
153158112Seric 			else if (strcasecmp(val, "mail") == 0)
153258112Seric 				TimeOuts.to_mail = to;
153358112Seric 			else if (strcasecmp(val, "rcpt") == 0)
153458112Seric 				TimeOuts.to_rcpt = to;
153558112Seric 			else if (strcasecmp(val, "datainit") == 0)
153658112Seric 				TimeOuts.to_datainit = to;
153758112Seric 			else if (strcasecmp(val, "datablock") == 0)
153858112Seric 				TimeOuts.to_datablock = to;
153958112Seric 			else if (strcasecmp(val, "datafinal") == 0)
154058112Seric 				TimeOuts.to_datafinal = to;
154158112Seric 			else if (strcasecmp(val, "command") == 0)
154258112Seric 				TimeOuts.to_nextcommand = to;
154358112Seric 			else if (strcasecmp(val, "rset") == 0)
154458112Seric 				TimeOuts.to_rset = to;
154558112Seric 			else if (strcasecmp(val, "helo") == 0)
154658112Seric 				TimeOuts.to_helo = to;
154758112Seric 			else if (strcasecmp(val, "quit") == 0)
154858112Seric 				TimeOuts.to_quit = to;
154958112Seric 			else if (strcasecmp(val, "misc") == 0)
155058112Seric 				TimeOuts.to_miscshort = to;
155158112Seric 			else
155258112Seric 				syserr("settimeouts: invalid timeout %s", val);
155358112Seric 		}
155458112Seric 	}
155558112Seric }
1556