xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 64326)
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*64326Seric static char sccsid[] = "@(#)readcf.c	8.11 (Berkeley) 08/21/93";
1133731Sbostic #endif /* not lint */
1222709Sdist 
133313Seric # include "sendmail.h"
1464133Seric # include <pwd.h>
1564133Seric # include <grp.h>
1657207Seric #ifdef NAMED_BIND
1757207Seric # include <arpa/nameser.h>
1857207Seric # include <resolv.h>
1957207Seric #endif
203308Seric 
213308Seric /*
223308Seric **  READCF -- read control file.
233308Seric **
243308Seric **	This routine reads the control file and builds the internal
253308Seric **	form.
263308Seric **
274432Seric **	The file is formatted as a sequence of lines, each taken
284432Seric **	atomically.  The first character of each line describes how
294432Seric **	the line is to be interpreted.  The lines are:
304432Seric **		Dxval		Define macro x to have value val.
314432Seric **		Cxword		Put word into class x.
324432Seric **		Fxfile [fmt]	Read file for lines to put into
334432Seric **				class x.  Use scanf string 'fmt'
344432Seric **				or "%s" if not present.  Fmt should
354432Seric **				only produce one string-valued result.
364432Seric **		Hname: value	Define header with field-name 'name'
374432Seric **				and value as specified; this will be
384432Seric **				macro expanded immediately before
394432Seric **				use.
404432Seric **		Sn		Use rewriting set n.
414432Seric **		Rlhs rhs	Rewrite addresses that match lhs to
424432Seric **				be rhs.
4324944Seric **		Mn arg=val...	Define mailer.  n is the internal name.
4424944Seric **				Args specify mailer parameters.
458252Seric **		Oxvalue		Set option x to value.
468252Seric **		Pname=value	Set precedence name to value.
4752645Seric **		Vversioncode	Version level of configuration syntax.
4853654Seric **		Kmapname mapclass arguments....
4953654Seric **				Define keyed lookup of a given class.
5053654Seric **				Arguments are class dependent.
514432Seric **
523308Seric **	Parameters:
533308Seric **		cfname -- control file name.
5454973Seric **		safe -- TRUE if this is the system config file;
5554973Seric **			FALSE otherwise.
5655012Seric **		e -- the main envelope.
573308Seric **
583308Seric **	Returns:
593308Seric **		none.
603308Seric **
613308Seric **	Side Effects:
623308Seric **		Builds several internal tables.
633308Seric */
643308Seric 
6555012Seric readcf(cfname, safe, e)
663308Seric 	char *cfname;
6754973Seric 	bool safe;
6855012Seric 	register ENVELOPE *e;
693308Seric {
703308Seric 	FILE *cf;
718547Seric 	int ruleset = 0;
728547Seric 	char *q;
739350Seric 	struct rewrite *rwp = NULL;
7457135Seric 	char *bp;
7557589Seric 	int nfuzzy;
7664133Seric 	char *file;
7764133Seric 	bool optional;
783308Seric 	char buf[MAXLINE];
793308Seric 	register char *p;
803308Seric 	extern char **copyplist();
8152647Seric 	struct stat statb;
825909Seric 	char exbuf[MAXLINE];
8316915Seric 	char pvpbuf[PSBUFSIZE];
8410709Seric 	extern char *munchstring();
8553654Seric 	extern void makemapentry();
863308Seric 
8752647Seric 	FileName = cfname;
8852647Seric 	LineNumber = 0;
8952647Seric 
903308Seric 	cf = fopen(cfname, "r");
913308Seric 	if (cf == NULL)
923308Seric 	{
9352647Seric 		syserr("cannot open");
943308Seric 		exit(EX_OSFILE);
953308Seric 	}
963308Seric 
9752647Seric 	if (fstat(fileno(cf), &statb) < 0)
9852647Seric 	{
9952647Seric 		syserr("cannot fstat");
10052647Seric 		exit(EX_OSFILE);
10152647Seric 	}
10252647Seric 
10352647Seric 	if (!S_ISREG(statb.st_mode))
10452647Seric 	{
10552647Seric 		syserr("not a plain file");
10652647Seric 		exit(EX_OSFILE);
10752647Seric 	}
10852647Seric 
10952647Seric 	if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
11052647Seric 	{
11153037Seric 		if (OpMode == MD_DAEMON || OpMode == MD_FREEZE)
11253037Seric 			fprintf(stderr, "%s: WARNING: dangerous write permissions\n",
11353037Seric 				FileName);
11453037Seric #ifdef LOG
11553037Seric 		if (LogLevel > 0)
11653037Seric 			syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions",
11753037Seric 				FileName);
11853037Seric #endif
11952647Seric 	}
12052647Seric 
12159254Seric #ifdef XLA
12259254Seric 	xla_zero();
12359254Seric #endif
12459254Seric 
12557135Seric 	while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL)
1263308Seric 	{
12757135Seric 		if (bp[0] == '#')
12857135Seric 		{
12957135Seric 			if (bp != buf)
13057135Seric 				free(bp);
13152637Seric 			continue;
13257135Seric 		}
13352637Seric 
13458050Seric 		/* map $ into \201 for macro expansion */
13557135Seric 		for (p = bp; *p != '\0'; p++)
13616157Seric 		{
13757135Seric 			if (*p == '#' && p > bp && ConfigLevel >= 3)
13852647Seric 			{
13952647Seric 				/* this is an on-line comment */
14052647Seric 				register char *e;
14152647Seric 
14258050Seric 				switch (*--p & 0377)
14352647Seric 				{
14458050Seric 				  case MACROEXPAND:
14552647Seric 					/* it's from $# -- let it go through */
14652647Seric 					p++;
14752647Seric 					break;
14852647Seric 
14952647Seric 				  case '\\':
15052647Seric 					/* it's backslash escaped */
15152647Seric 					(void) strcpy(p, p + 1);
15252647Seric 					break;
15352647Seric 
15452647Seric 				  default:
15552647Seric 					/* delete preceeding white space */
15658050Seric 					while (isascii(*p) && isspace(*p) && p > bp)
15752647Seric 						p--;
15856795Seric 					if ((e = strchr(++p, '\n')) != NULL)
15952647Seric 						(void) strcpy(p, e);
16052647Seric 					else
16152647Seric 						p[0] = p[1] = '\0';
16252647Seric 					break;
16352647Seric 				}
16452647Seric 				continue;
16552647Seric 			}
16652647Seric 
16716157Seric 			if (*p != '$')
16816157Seric 				continue;
16916157Seric 
17016157Seric 			if (p[1] == '$')
17116157Seric 			{
17216157Seric 				/* actual dollar sign.... */
17323111Seric 				(void) strcpy(p, p + 1);
17416157Seric 				continue;
17516157Seric 			}
17616157Seric 
17716157Seric 			/* convert to macro expansion character */
17858050Seric 			*p = MACROEXPAND;
17916157Seric 		}
18016157Seric 
18116157Seric 		/* interpret this line */
18257135Seric 		switch (bp[0])
1833308Seric 		{
1843308Seric 		  case '\0':
1853308Seric 		  case '#':		/* comment */
1863308Seric 			break;
1873308Seric 
1883308Seric 		  case 'R':		/* rewriting rule */
18957135Seric 			for (p = &bp[1]; *p != '\0' && *p != '\t'; p++)
1903308Seric 				continue;
1913308Seric 
1923308Seric 			if (*p == '\0')
1935909Seric 			{
19457135Seric 				syserr("invalid rewrite line \"%s\"", bp);
1955909Seric 				break;
1965909Seric 			}
1975909Seric 
1985909Seric 			/* allocate space for the rule header */
1995909Seric 			if (rwp == NULL)
2005909Seric 			{
2015909Seric 				RewriteRules[ruleset] = rwp =
2025909Seric 					(struct rewrite *) xalloc(sizeof *rwp);
2035909Seric 			}
2043308Seric 			else
2053308Seric 			{
2065909Seric 				rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
2075909Seric 				rwp = rwp->r_next;
2085909Seric 			}
2095909Seric 			rwp->r_next = NULL;
2103308Seric 
2115909Seric 			/* expand and save the LHS */
2125909Seric 			*p = '\0';
21357135Seric 			expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e);
21458333Seric 			rwp->r_lhs = prescan(exbuf, '\t', pvpbuf, NULL);
21557589Seric 			nfuzzy = 0;
2165909Seric 			if (rwp->r_lhs != NULL)
21757589Seric 			{
21857589Seric 				register char **ap;
21957589Seric 
2205909Seric 				rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
22157589Seric 
22257589Seric 				/* count the number of fuzzy matches in LHS */
22357589Seric 				for (ap = rwp->r_lhs; *ap != NULL; ap++)
22457589Seric 				{
22558148Seric 					char *botch;
22658148Seric 
22758148Seric 					botch = NULL;
22858050Seric 					switch (**ap & 0377)
22957589Seric 					{
23057589Seric 					  case MATCHZANY:
23157589Seric 					  case MATCHANY:
23257589Seric 					  case MATCHONE:
23357589Seric 					  case MATCHCLASS:
23457589Seric 					  case MATCHNCLASS:
23557589Seric 						nfuzzy++;
23658148Seric 						break;
23758148Seric 
23858148Seric 					  case MATCHREPL:
23958148Seric 						botch = "$0-$9";
24058148Seric 						break;
24158148Seric 
24258148Seric 					  case CANONNET:
24358148Seric 						botch = "$#";
24458148Seric 						break;
24558148Seric 
24658148Seric 					  case CANONUSER:
24758148Seric 						botch = "$:";
24858148Seric 						break;
24958148Seric 
25058148Seric 					  case CALLSUBR:
25158148Seric 						botch = "$>";
25258148Seric 						break;
25358148Seric 
25458148Seric 					  case CONDIF:
25558148Seric 						botch = "$?";
25658148Seric 						break;
25758148Seric 
25858148Seric 					  case CONDELSE:
25958148Seric 						botch = "$|";
26058148Seric 						break;
26158148Seric 
26258148Seric 					  case CONDFI:
26358148Seric 						botch = "$.";
26458148Seric 						break;
26558148Seric 
26658148Seric 					  case HOSTBEGIN:
26758148Seric 						botch = "$[";
26858148Seric 						break;
26958148Seric 
27058148Seric 					  case HOSTEND:
27158148Seric 						botch = "$]";
27258148Seric 						break;
27358148Seric 
27458148Seric 					  case LOOKUPBEGIN:
27558148Seric 						botch = "$(";
27658148Seric 						break;
27758148Seric 
27858148Seric 					  case LOOKUPEND:
27958148Seric 						botch = "$)";
28058148Seric 						break;
28157589Seric 					}
28258148Seric 					if (botch != NULL)
28358148Seric 						syserr("Inappropriate use of %s on LHS",
28458148Seric 							botch);
28557589Seric 				}
28657589Seric 			}
28756678Seric 			else
28856678Seric 				syserr("R line: null LHS");
2895909Seric 
2905909Seric 			/* expand and save the RHS */
2915909Seric 			while (*++p == '\t')
2925909Seric 				continue;
2937231Seric 			q = p;
2947231Seric 			while (*p != '\0' && *p != '\t')
2957231Seric 				p++;
2967231Seric 			*p = '\0';
29755012Seric 			expand(q, exbuf, &exbuf[sizeof exbuf], e);
29858333Seric 			rwp->r_rhs = prescan(exbuf, '\t', pvpbuf, NULL);
2995909Seric 			if (rwp->r_rhs != NULL)
30057589Seric 			{
30157589Seric 				register char **ap;
30257589Seric 
3035909Seric 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
30457589Seric 
30557589Seric 				/* check no out-of-bounds replacements */
30657589Seric 				nfuzzy += '0';
30757589Seric 				for (ap = rwp->r_rhs; *ap != NULL; ap++)
30857589Seric 				{
30958148Seric 					char *botch;
31058148Seric 
31158148Seric 					botch = NULL;
31258148Seric 					switch (**ap & 0377)
31357589Seric 					{
31458148Seric 					  case MATCHREPL:
31558148Seric 						if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy)
31658148Seric 						{
31758148Seric 							syserr("replacement $%c out of bounds",
31858148Seric 								(*ap)[1]);
31958148Seric 						}
32058148Seric 						break;
32158148Seric 
32258148Seric 					  case MATCHZANY:
32358148Seric 						botch = "$*";
32458148Seric 						break;
32558148Seric 
32658148Seric 					  case MATCHANY:
32758148Seric 						botch = "$+";
32858148Seric 						break;
32958148Seric 
33058148Seric 					  case MATCHONE:
33158148Seric 						botch = "$-";
33258148Seric 						break;
33358148Seric 
33458148Seric 					  case MATCHCLASS:
33558148Seric 						botch = "$=";
33658148Seric 						break;
33758148Seric 
33858148Seric 					  case MATCHNCLASS:
33958148Seric 						botch = "$~";
34058148Seric 						break;
34157589Seric 					}
34258148Seric 					if (botch != NULL)
34358148Seric 						syserr("Inappropriate use of %s on RHS",
34458148Seric 							botch);
34557589Seric 				}
34657589Seric 			}
34756678Seric 			else
34856678Seric 				syserr("R line: null RHS");
3493308Seric 			break;
3503308Seric 
3514072Seric 		  case 'S':		/* select rewriting set */
35257135Seric 			ruleset = atoi(&bp[1]);
3538056Seric 			if (ruleset >= MAXRWSETS || ruleset < 0)
3548056Seric 			{
3559381Seric 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
3568056Seric 				ruleset = 0;
3578056Seric 			}
3584072Seric 			rwp = NULL;
3594072Seric 			break;
3604072Seric 
3613308Seric 		  case 'D':		/* macro definition */
36264086Seric 			p = munchstring(&bp[2], NULL);
36364086Seric 			define(bp[1], newstr(p), e);
3643308Seric 			break;
3653308Seric 
3663387Seric 		  case 'H':		/* required header line */
36757135Seric 			(void) chompheader(&bp[1], TRUE, e);
3683387Seric 			break;
3693387Seric 
3704061Seric 		  case 'C':		/* word class */
3714432Seric 			/* scan the list of words and set class for all */
37264121Seric 			expand(&bp[2], exbuf, &exbuf[sizeof exbuf], e);
37364121Seric 			for (p = exbuf; *p != '\0'; )
3744061Seric 			{
3754061Seric 				register char *wd;
3764061Seric 				char delim;
3774061Seric 
37858050Seric 				while (*p != '\0' && isascii(*p) && isspace(*p))
3794061Seric 					p++;
3804061Seric 				wd = p;
38158050Seric 				while (*p != '\0' && !(isascii(*p) && isspace(*p)))
3824061Seric 					p++;
3834061Seric 				delim = *p;
3844061Seric 				*p = '\0';
3854061Seric 				if (wd[0] != '\0')
38657135Seric 					setclass(bp[1], wd);
3874061Seric 				*p = delim;
3884061Seric 			}
3894061Seric 			break;
3904061Seric 
39159272Seric 		  case 'F':		/* word class from file */
39264133Seric 			for (p = &bp[2]; isascii(*p) && isspace(*p); )
39364133Seric 				p++;
39464133Seric 			if (p[0] == '-' && p[1] == 'o')
39564133Seric 			{
39664133Seric 				optional = TRUE;
39764133Seric 				while (*p != '\0' && !(isascii(*p) && isspace(*p)))
39864133Seric 					p++;
39964133Seric 				while (isascii(*p) && isspace(*p))
40064133Seric 					*p++;
40164133Seric 			}
40264133Seric 			else
40364133Seric 				optional = FALSE;
40464133Seric 			file = p;
40564133Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
40664133Seric 				p++;
40759272Seric 			if (*p == '\0')
40859272Seric 				p = "%s";
40959272Seric 			else
41059272Seric 			{
41159272Seric 				*p = '\0';
41259272Seric 				while (isascii(*++p) && isspace(*p))
41359272Seric 					continue;
41459272Seric 			}
41564133Seric 			fileclass(bp[1], file, p, safe, optional);
41659272Seric 			break;
41759272Seric 
41859156Seric #ifdef XLA
41959156Seric 		  case 'L':		/* extended load average description */
42059156Seric 			xla_init(&bp[1]);
42159156Seric 			break;
42259156Seric #endif
42359156Seric 
4244096Seric 		  case 'M':		/* define mailer */
42557135Seric 			makemailer(&bp[1]);
4264096Seric 			break;
4274096Seric 
4288252Seric 		  case 'O':		/* set option */
42958734Seric 			setoption(bp[1], &bp[2], safe, FALSE, e);
4308252Seric 			break;
4318252Seric 
4328252Seric 		  case 'P':		/* set precedence */
4338252Seric 			if (NumPriorities >= MAXPRIORITIES)
4348252Seric 			{
4358547Seric 				toomany('P', MAXPRIORITIES);
4368252Seric 				break;
4378252Seric 			}
43857135Seric 			for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
4398252Seric 				continue;
4408252Seric 			if (*p == '\0')
4418252Seric 				goto badline;
4428252Seric 			*p = '\0';
44357135Seric 			Priorities[NumPriorities].pri_name = newstr(&bp[1]);
4448252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
4458252Seric 			NumPriorities++;
4468252Seric 			break;
4478252Seric 
4488547Seric 		  case 'T':		/* trusted user(s) */
44958161Seric 			/* this option is obsolete, but will be ignored */
4508547Seric 			break;
4518547Seric 
45252645Seric 		  case 'V':		/* configuration syntax version */
45357135Seric 			ConfigLevel = atoi(&bp[1]);
45464279Seric 			if (ConfigLevel >= 5)
45564279Seric 			{
45664279Seric 				/* level 5 configs have short name in $w */
45764279Seric 				p = macvalue('w', e);
45864279Seric 				if (p != NULL && (p = strchr(p, '.')) != NULL)
45964279Seric 					*p = '\0';
46064279Seric 			}
46152645Seric 			break;
46252645Seric 
46353654Seric 		  case 'K':
46457135Seric 			makemapentry(&bp[1]);
46553654Seric 			break;
46653654Seric 
4673308Seric 		  default:
4684061Seric 		  badline:
46957135Seric 			syserr("unknown control line \"%s\"", bp);
4703308Seric 		}
47157135Seric 		if (bp != buf)
47257135Seric 			free(bp);
4733308Seric 	}
47452637Seric 	if (ferror(cf))
47552637Seric 	{
47652647Seric 		syserr("I/O read error", cfname);
47752637Seric 		exit(EX_OSFILE);
47852637Seric 	}
47952637Seric 	fclose(cf);
4809381Seric 	FileName = NULL;
48156836Seric 
48257076Seric 	if (stab("host", ST_MAP, ST_FIND) == NULL)
48357076Seric 	{
48457076Seric 		/* user didn't initialize: set up host map */
48557076Seric 		strcpy(buf, "host host");
48657076Seric 		if (ConfigLevel >= 2)
48757076Seric 			strcat(buf, " -a.");
48857076Seric 		makemapentry(buf);
48957076Seric 	}
4904096Seric }
4914096Seric /*
4928547Seric **  TOOMANY -- signal too many of some option
4938547Seric **
4948547Seric **	Parameters:
4958547Seric **		id -- the id of the error line
4968547Seric **		maxcnt -- the maximum possible values
4978547Seric **
4988547Seric **	Returns:
4998547Seric **		none.
5008547Seric **
5018547Seric **	Side Effects:
5028547Seric **		gives a syserr.
5038547Seric */
5048547Seric 
5058547Seric toomany(id, maxcnt)
5068547Seric 	char id;
5078547Seric 	int maxcnt;
5088547Seric {
5099381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
5108547Seric }
5118547Seric /*
5124432Seric **  FILECLASS -- read members of a class from a file
5134432Seric **
5144432Seric **	Parameters:
5154432Seric **		class -- class to define.
5164432Seric **		filename -- name of file to read.
5174432Seric **		fmt -- scanf string to use for match.
51864133Seric **		safe -- if set, this is a safe read.
51964133Seric **		optional -- if set, it is not an error for the file to
52064133Seric **			not exist.
5214432Seric **
5224432Seric **	Returns:
5234432Seric **		none
5244432Seric **
5254432Seric **	Side Effects:
5264432Seric **
5274432Seric **		puts all lines in filename that match a scanf into
5284432Seric **			the named class.
5294432Seric */
5304432Seric 
53164133Seric fileclass(class, filename, fmt, safe, optional)
5324432Seric 	int class;
5334432Seric 	char *filename;
5344432Seric 	char *fmt;
53554973Seric 	bool safe;
53664133Seric 	bool optional;
5374432Seric {
53825808Seric 	FILE *f;
53954973Seric 	struct stat stbuf;
5404432Seric 	char buf[MAXLINE];
5414432Seric 
54254973Seric 	if (stat(filename, &stbuf) < 0)
54354973Seric 	{
54464133Seric 		if (!optional)
54564133Seric 			syserr("fileclass: cannot stat %s", filename);
54654973Seric 		return;
54754973Seric 	}
54854973Seric 	if (!S_ISREG(stbuf.st_mode))
54954973Seric 	{
55054973Seric 		syserr("fileclass: %s not a regular file", filename);
55154973Seric 		return;
55254973Seric 	}
55354973Seric 	if (!safe && access(filename, R_OK) < 0)
55454973Seric 	{
55554973Seric 		syserr("fileclass: access denied on %s", filename);
55654973Seric 		return;
55754973Seric 	}
55854973Seric 	f = fopen(filename, "r");
5594432Seric 	if (f == NULL)
5604432Seric 	{
56154973Seric 		syserr("fileclass: cannot open %s", filename);
5624432Seric 		return;
5634432Seric 	}
5644432Seric 
5654432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
5664432Seric 	{
5674432Seric 		register STAB *s;
56825808Seric 		register char *p;
56925808Seric # ifdef SCANF
5704432Seric 		char wordbuf[MAXNAME+1];
5714432Seric 
5724432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
5734432Seric 			continue;
57425808Seric 		p = wordbuf;
57556795Seric # else /* SCANF */
57625808Seric 		p = buf;
57756795Seric # endif /* SCANF */
57825808Seric 
57925808Seric 		/*
58025808Seric 		**  Break up the match into words.
58125808Seric 		*/
58225808Seric 
58325808Seric 		while (*p != '\0')
58425808Seric 		{
58525808Seric 			register char *q;
58625808Seric 
58725808Seric 			/* strip leading spaces */
58858050Seric 			while (isascii(*p) && isspace(*p))
58925808Seric 				p++;
59025808Seric 			if (*p == '\0')
59125808Seric 				break;
59225808Seric 
59325808Seric 			/* find the end of the word */
59425808Seric 			q = p;
59558050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
59625808Seric 				p++;
59725808Seric 			if (*p != '\0')
59825808Seric 				*p++ = '\0';
59925808Seric 
60025808Seric 			/* enter the word in the symbol table */
60125808Seric 			s = stab(q, ST_CLASS, ST_ENTER);
60225808Seric 			setbitn(class, s->s_class);
60325808Seric 		}
6044432Seric 	}
6054432Seric 
60654973Seric 	(void) fclose(f);
6074432Seric }
6084432Seric /*
6094096Seric **  MAKEMAILER -- define a new mailer.
6104096Seric **
6114096Seric **	Parameters:
61210327Seric **		line -- description of mailer.  This is in labeled
61310327Seric **			fields.  The fields are:
61410327Seric **			   P -- the path to the mailer
61510327Seric **			   F -- the flags associated with the mailer
61610327Seric **			   A -- the argv for this mailer
61710327Seric **			   S -- the sender rewriting set
61810327Seric **			   R -- the recipient rewriting set
61910327Seric **			   E -- the eol string
62010327Seric **			The first word is the canonical name of the mailer.
6214096Seric **
6224096Seric **	Returns:
6234096Seric **		none.
6244096Seric **
6254096Seric **	Side Effects:
6264096Seric **		enters the mailer into the mailer table.
6274096Seric */
6283308Seric 
62921066Seric makemailer(line)
6304096Seric 	char *line;
6314096Seric {
6324096Seric 	register char *p;
6338067Seric 	register struct mailer *m;
6348067Seric 	register STAB *s;
6358067Seric 	int i;
63610327Seric 	char fcode;
63758020Seric 	auto char *endp;
6384096Seric 	extern int NextMailer;
63910327Seric 	extern char **makeargv();
64010327Seric 	extern char *munchstring();
64110701Seric 	extern long atol();
6424096Seric 
64310327Seric 	/* allocate a mailer and set up defaults */
64410327Seric 	m = (struct mailer *) xalloc(sizeof *m);
64510327Seric 	bzero((char *) m, sizeof *m);
64610327Seric 	m->m_eol = "\n";
64710327Seric 
64810327Seric 	/* collect the mailer name */
64958050Seric 	for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++)
65010327Seric 		continue;
65110327Seric 	if (*p != '\0')
65210327Seric 		*p++ = '\0';
65310327Seric 	m->m_name = newstr(line);
65410327Seric 
65510327Seric 	/* now scan through and assign info from the fields */
65610327Seric 	while (*p != '\0')
65710327Seric 	{
65858333Seric 		auto char *delimptr;
65958333Seric 
66058050Seric 		while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p))))
66110327Seric 			p++;
66210327Seric 
66310327Seric 		/* p now points to field code */
66410327Seric 		fcode = *p;
66510327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
66610327Seric 			p++;
66710327Seric 		if (*p++ != '=')
66810327Seric 		{
66952637Seric 			syserr("mailer %s: `=' expected", m->m_name);
67010327Seric 			return;
67110327Seric 		}
67258050Seric 		while (isascii(*p) && isspace(*p))
67310327Seric 			p++;
67410327Seric 
67510327Seric 		/* p now points to the field body */
67658333Seric 		p = munchstring(p, &delimptr);
67710327Seric 
67810327Seric 		/* install the field into the mailer struct */
67910327Seric 		switch (fcode)
68010327Seric 		{
68110327Seric 		  case 'P':		/* pathname */
68210327Seric 			m->m_mailer = newstr(p);
68310327Seric 			break;
68410327Seric 
68510327Seric 		  case 'F':		/* flags */
68610687Seric 			for (; *p != '\0'; p++)
68758050Seric 				if (!(isascii(*p) && isspace(*p)))
68852637Seric 					setbitn(*p, m->m_flags);
68910327Seric 			break;
69010327Seric 
69110327Seric 		  case 'S':		/* sender rewriting ruleset */
69210327Seric 		  case 'R':		/* recipient rewriting ruleset */
69358020Seric 			i = strtol(p, &endp, 10);
69410327Seric 			if (i < 0 || i >= MAXRWSETS)
69510327Seric 			{
69610327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
69710327Seric 				return;
69810327Seric 			}
69910327Seric 			if (fcode == 'S')
70058020Seric 				m->m_sh_rwset = m->m_se_rwset = i;
70110327Seric 			else
70258020Seric 				m->m_rh_rwset = m->m_re_rwset = i;
70358020Seric 
70458020Seric 			p = endp;
70559985Seric 			if (*p++ == '/')
70658020Seric 			{
70758020Seric 				i = strtol(p, NULL, 10);
70858020Seric 				if (i < 0 || i >= MAXRWSETS)
70958020Seric 				{
71058020Seric 					syserr("invalid rewrite set, %d max",
71158020Seric 						MAXRWSETS);
71258020Seric 					return;
71358020Seric 				}
71458020Seric 				if (fcode == 'S')
71558020Seric 					m->m_sh_rwset = i;
71658020Seric 				else
71758020Seric 					m->m_rh_rwset = i;
71858020Seric 			}
71910327Seric 			break;
72010327Seric 
72110327Seric 		  case 'E':		/* end of line string */
72210327Seric 			m->m_eol = newstr(p);
72310327Seric 			break;
72410327Seric 
72510327Seric 		  case 'A':		/* argument vector */
72610327Seric 			m->m_argv = makeargv(p);
72710327Seric 			break;
72810701Seric 
72910701Seric 		  case 'M':		/* maximum message size */
73010701Seric 			m->m_maxsize = atol(p);
73110701Seric 			break;
73252106Seric 
73352106Seric 		  case 'L':		/* maximum line length */
73452106Seric 			m->m_linelimit = atoi(p);
73552106Seric 			break;
73658935Seric 
73758935Seric 		  case 'D':		/* working directory */
73858935Seric 			m->m_execdir = newstr(p);
73958935Seric 			break;
74010327Seric 		}
74110327Seric 
74258333Seric 		p = delimptr;
74310327Seric 	}
74410327Seric 
74552106Seric 	/* do some heuristic cleanup for back compatibility */
74652106Seric 	if (bitnset(M_LIMITS, m->m_flags))
74752106Seric 	{
74852106Seric 		if (m->m_linelimit == 0)
74952106Seric 			m->m_linelimit = SMTPLINELIM;
75055418Seric 		if (ConfigLevel < 2)
75152106Seric 			setbitn(M_7BITS, m->m_flags);
75252106Seric 	}
75352106Seric 
75458321Seric 	/* do some rationality checking */
75558321Seric 	if (m->m_argv == NULL)
75658321Seric 	{
75758321Seric 		syserr("M%s: A= argument required", m->m_name);
75858321Seric 		return;
75958321Seric 	}
76058321Seric 	if (m->m_mailer == NULL)
76158321Seric 	{
76258321Seric 		syserr("M%s: P= argument required", m->m_name);
76358321Seric 		return;
76458321Seric 	}
76558321Seric 
7664096Seric 	if (NextMailer >= MAXMAILERS)
7674096Seric 	{
7689381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
7694096Seric 		return;
7704096Seric 	}
77157402Seric 
77210327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
77357402Seric 	if (s->s_mailer != NULL)
77457402Seric 	{
77557402Seric 		i = s->s_mailer->m_mno;
77657402Seric 		free(s->s_mailer);
77757402Seric 	}
77857402Seric 	else
77957402Seric 	{
78057402Seric 		i = NextMailer++;
78157402Seric 	}
78257402Seric 	Mailer[i] = s->s_mailer = m;
78357454Seric 	m->m_mno = i;
78410327Seric }
78510327Seric /*
78610327Seric **  MUNCHSTRING -- translate a string into internal form.
78710327Seric **
78810327Seric **	Parameters:
78910327Seric **		p -- the string to munch.
79058333Seric **		delimptr -- if non-NULL, set to the pointer of the
79158333Seric **			field delimiter character.
79210327Seric **
79310327Seric **	Returns:
79410327Seric **		the munched string.
79510327Seric */
7964096Seric 
79710327Seric char *
79858333Seric munchstring(p, delimptr)
79910327Seric 	register char *p;
80058333Seric 	char **delimptr;
80110327Seric {
80210327Seric 	register char *q;
80310327Seric 	bool backslash = FALSE;
80410327Seric 	bool quotemode = FALSE;
80510327Seric 	static char buf[MAXLINE];
8064096Seric 
80710327Seric 	for (q = buf; *p != '\0'; p++)
8084096Seric 	{
80910327Seric 		if (backslash)
81010327Seric 		{
81110327Seric 			/* everything is roughly literal */
81210357Seric 			backslash = FALSE;
81310327Seric 			switch (*p)
81410327Seric 			{
81510327Seric 			  case 'r':		/* carriage return */
81610327Seric 				*q++ = '\r';
81710327Seric 				continue;
81810327Seric 
81910327Seric 			  case 'n':		/* newline */
82010327Seric 				*q++ = '\n';
82110327Seric 				continue;
82210327Seric 
82310327Seric 			  case 'f':		/* form feed */
82410327Seric 				*q++ = '\f';
82510327Seric 				continue;
82610327Seric 
82710327Seric 			  case 'b':		/* backspace */
82810327Seric 				*q++ = '\b';
82910327Seric 				continue;
83010327Seric 			}
83110327Seric 			*q++ = *p;
83210327Seric 		}
83310327Seric 		else
83410327Seric 		{
83510327Seric 			if (*p == '\\')
83610327Seric 				backslash = TRUE;
83710327Seric 			else if (*p == '"')
83810327Seric 				quotemode = !quotemode;
83910327Seric 			else if (quotemode || *p != ',')
84010327Seric 				*q++ = *p;
84110327Seric 			else
84210327Seric 				break;
84310327Seric 		}
8444096Seric 	}
8454096Seric 
84658333Seric 	if (delimptr != NULL)
84758333Seric 		*delimptr = p;
84810327Seric 	*q++ = '\0';
84910327Seric 	return (buf);
85010327Seric }
85110327Seric /*
85210327Seric **  MAKEARGV -- break up a string into words
85310327Seric **
85410327Seric **	Parameters:
85510327Seric **		p -- the string to break up.
85610327Seric **
85710327Seric **	Returns:
85810327Seric **		a char **argv (dynamically allocated)
85910327Seric **
86010327Seric **	Side Effects:
86110327Seric **		munges p.
86210327Seric */
8634096Seric 
86410327Seric char **
86510327Seric makeargv(p)
86610327Seric 	register char *p;
86710327Seric {
86810327Seric 	char *q;
86910327Seric 	int i;
87010327Seric 	char **avp;
87110327Seric 	char *argv[MAXPV + 1];
87210327Seric 
87310327Seric 	/* take apart the words */
87410327Seric 	i = 0;
87510327Seric 	while (*p != '\0' && i < MAXPV)
8764096Seric 	{
87710327Seric 		q = p;
87858050Seric 		while (*p != '\0' && !(isascii(*p) && isspace(*p)))
87910327Seric 			p++;
88058050Seric 		while (isascii(*p) && isspace(*p))
88110327Seric 			*p++ = '\0';
88210327Seric 		argv[i++] = newstr(q);
8834096Seric 	}
88410327Seric 	argv[i++] = NULL;
8854096Seric 
88610327Seric 	/* now make a copy of the argv */
88710327Seric 	avp = (char **) xalloc(sizeof *avp * i);
88816893Seric 	bcopy((char *) argv, (char *) avp, sizeof *avp * i);
88910327Seric 
89010327Seric 	return (avp);
8913308Seric }
8923308Seric /*
8933308Seric **  PRINTRULES -- print rewrite rules (for debugging)
8943308Seric **
8953308Seric **	Parameters:
8963308Seric **		none.
8973308Seric **
8983308Seric **	Returns:
8993308Seric **		none.
9003308Seric **
9013308Seric **	Side Effects:
9023308Seric **		prints rewrite rules.
9033308Seric */
9043308Seric 
9053308Seric printrules()
9063308Seric {
9073308Seric 	register struct rewrite *rwp;
9084072Seric 	register int ruleset;
9093308Seric 
9104072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
9113308Seric 	{
9124072Seric 		if (RewriteRules[ruleset] == NULL)
9134072Seric 			continue;
9148067Seric 		printf("\n----Rule Set %d:", ruleset);
9153308Seric 
9164072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
9173308Seric 		{
9188067Seric 			printf("\nLHS:");
9198067Seric 			printav(rwp->r_lhs);
9208067Seric 			printf("RHS:");
9218067Seric 			printav(rwp->r_rhs);
9223308Seric 		}
9233308Seric 	}
9243308Seric }
9254319Seric 
9264096Seric /*
9278256Seric **  SETOPTION -- set global processing option
9288256Seric **
9298256Seric **	Parameters:
9308256Seric **		opt -- option name.
9318256Seric **		val -- option value (as a text string).
93221755Seric **		safe -- set if this came from a configuration file.
93321755Seric **			Some options (if set from the command line) will
93421755Seric **			reset the user id to avoid security problems.
9358269Seric **		sticky -- if set, don't let other setoptions override
9368269Seric **			this value.
93758734Seric **		e -- the main envelope.
9388256Seric **
9398256Seric **	Returns:
9408256Seric **		none.
9418256Seric **
9428256Seric **	Side Effects:
9438256Seric **		Sets options as implied by the arguments.
9448256Seric */
9458256Seric 
94610687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
9478269Seric 
94857207Seric 
94957207Seric #ifdef NAMED_BIND
95057207Seric 
95157207Seric struct resolverflags
95257207Seric {
95357207Seric 	char	*rf_name;	/* name of the flag */
95457207Seric 	long	rf_bits;	/* bits to set/clear */
95557207Seric } ResolverFlags[] =
95657207Seric {
95757207Seric 	"debug",	RES_DEBUG,
95857207Seric 	"aaonly",	RES_AAONLY,
95957207Seric 	"usevc",	RES_USEVC,
96057207Seric 	"primary",	RES_PRIMARY,
96157207Seric 	"igntc",	RES_IGNTC,
96257207Seric 	"recurse",	RES_RECURSE,
96357207Seric 	"defnames",	RES_DEFNAMES,
96457207Seric 	"stayopen",	RES_STAYOPEN,
96557207Seric 	"dnsrch",	RES_DNSRCH,
96657207Seric 	NULL,		0
96757207Seric };
96857207Seric 
96957207Seric #endif
97057207Seric 
97158734Seric setoption(opt, val, safe, sticky, e)
9728256Seric 	char opt;
9738256Seric 	char *val;
97421755Seric 	bool safe;
9758269Seric 	bool sticky;
97658734Seric 	register ENVELOPE *e;
9778256Seric {
97857207Seric 	register char *p;
9798265Seric 	extern bool atobool();
98012633Seric 	extern time_t convtime();
98114879Seric 	extern int QueueLA;
98214879Seric 	extern int RefuseLA;
98317474Seric 	extern bool trusteduser();
9848256Seric 
9858256Seric 	if (tTd(37, 1))
9869341Seric 		printf("setoption %c=%s", opt, val);
9878256Seric 
9888256Seric 	/*
9898269Seric 	**  See if this option is preset for us.
9908256Seric 	*/
9918256Seric 
99259731Seric 	if (!sticky && bitnset(opt, StickyOpt))
9938269Seric 	{
9949341Seric 		if (tTd(37, 1))
9959341Seric 			printf(" (ignored)\n");
9968269Seric 		return;
9978269Seric 	}
9988269Seric 
99921755Seric 	/*
100021755Seric 	**  Check to see if this option can be specified by this user.
100121755Seric 	*/
100221755Seric 
100363787Seric 	if (!safe && RealUid == 0)
100421755Seric 		safe = TRUE;
100563837Seric 	if (!safe && strchr("bCdeEijLmoprsvw7", opt) == NULL)
100621755Seric 	{
100739111Srick 		if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
100821755Seric 		{
100936582Sbostic 			if (tTd(37, 1))
101036582Sbostic 				printf(" (unsafe)");
101163787Seric 			if (RealUid != geteuid())
101236582Sbostic 			{
101351210Seric 				if (tTd(37, 1))
101451210Seric 					printf("(Resetting uid)");
101563787Seric 				(void) setgid(RealGid);
101663787Seric 				(void) setuid(RealUid);
101736582Sbostic 			}
101821755Seric 		}
101921755Seric 	}
102051210Seric 	if (tTd(37, 1))
102117985Seric 		printf("\n");
10228269Seric 
10238256Seric 	switch (opt)
10248256Seric 	{
102559709Seric 	  case '7':		/* force seven-bit input */
102659709Seric 		SevenBit = atobool(val);
102752106Seric 		break;
102852106Seric 
10298256Seric 	  case 'A':		/* set default alias file */
10309381Seric 		if (val[0] == '\0')
103159672Seric 			setalias("aliases");
10329381Seric 		else
103359672Seric 			setalias(val);
10348256Seric 		break;
10358256Seric 
103617474Seric 	  case 'a':		/* look N minutes for "@:@" in alias file */
103717474Seric 		if (val[0] == '\0')
103817474Seric 			SafeAlias = 5;
103917474Seric 		else
104017474Seric 			SafeAlias = atoi(val);
104117474Seric 		break;
104217474Seric 
104316843Seric 	  case 'B':		/* substitution for blank character */
104416843Seric 		SpaceSub = val[0];
104516843Seric 		if (SpaceSub == '\0')
104616843Seric 			SpaceSub = ' ';
104716843Seric 		break;
104816843Seric 
104959283Seric 	  case 'b':		/* min blocks free on queue fs/max msg size */
105059283Seric 		p = strchr(val, '/');
105159283Seric 		if (p != NULL)
105259283Seric 		{
105359283Seric 			*p++ = '\0';
105459283Seric 			MaxMessageSize = atol(p);
105559283Seric 		}
105658082Seric 		MinBlocksFree = atol(val);
105758082Seric 		break;
105858082Seric 
10599284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
10609381Seric 		NoConnect = atobool(val);
10619284Seric 		break;
10629284Seric 
106351305Seric 	  case 'C':		/* checkpoint every N addresses */
106451305Seric 		CheckpointInterval = atoi(val);
106524944Seric 		break;
106624944Seric 
10679284Seric 	  case 'd':		/* delivery mode */
10689284Seric 		switch (*val)
10698269Seric 		{
10709284Seric 		  case '\0':
107158734Seric 			e->e_sendmode = SM_DELIVER;
10728269Seric 			break;
10738269Seric 
107410755Seric 		  case SM_QUEUE:	/* queue only */
107510755Seric #ifndef QUEUE
107610755Seric 			syserr("need QUEUE to set -odqueue");
107756795Seric #endif /* QUEUE */
107810755Seric 			/* fall through..... */
107910755Seric 
10809284Seric 		  case SM_DELIVER:	/* do everything */
10819284Seric 		  case SM_FORK:		/* fork after verification */
108258734Seric 			e->e_sendmode = *val;
10838269Seric 			break;
10848269Seric 
10858269Seric 		  default:
10869284Seric 			syserr("Unknown delivery mode %c", *val);
10878269Seric 			exit(EX_USAGE);
10888269Seric 		}
10898269Seric 		break;
10908269Seric 
10919146Seric 	  case 'D':		/* rebuild alias database as needed */
10929381Seric 		AutoRebuild = atobool(val);
10939146Seric 		break;
10949146Seric 
109555372Seric 	  case 'E':		/* error message header/header file */
109655379Seric 		if (*val != '\0')
109755379Seric 			ErrMsgFile = newstr(val);
109855372Seric 		break;
109955372Seric 
11008269Seric 	  case 'e':		/* set error processing mode */
11018269Seric 		switch (*val)
11028269Seric 		{
11039381Seric 		  case EM_QUIET:	/* be silent about it */
11049381Seric 		  case EM_MAIL:		/* mail back */
11059381Seric 		  case EM_BERKNET:	/* do berknet error processing */
11069381Seric 		  case EM_WRITE:	/* write back (or mail) */
11078269Seric 			HoldErrs = TRUE;
11089381Seric 			/* fall through... */
11098269Seric 
11109381Seric 		  case EM_PRINT:	/* print errors normally (default) */
111158734Seric 			e->e_errormode = *val;
11128269Seric 			break;
11138269Seric 		}
11148269Seric 		break;
11158269Seric 
11169049Seric 	  case 'F':		/* file mode */
111717975Seric 		FileMode = atooct(val) & 0777;
11189049Seric 		break;
11199049Seric 
11208269Seric 	  case 'f':		/* save Unix-style From lines on front */
11219381Seric 		SaveFrom = atobool(val);
11228269Seric 		break;
11238269Seric 
112453735Seric 	  case 'G':		/* match recipients against GECOS field */
112553735Seric 		MatchGecos = atobool(val);
112653735Seric 		break;
112753735Seric 
11288256Seric 	  case 'g':		/* default gid */
112964133Seric 		if (isascii(*val) && isdigit(*val))
113064133Seric 			DefGid = atoi(val);
113164133Seric 		else
113264133Seric 		{
113364133Seric 			register struct group *gr;
113464133Seric 
113564133Seric 			DefGid = -1;
113664133Seric 			gr = getgrnam(val);
113764133Seric 			if (gr == NULL)
113864133Seric 				syserr("readcf: option g: unknown group %s", val);
113964133Seric 			else
114064133Seric 				DefGid = gr->gr_gid;
114164133Seric 		}
11428256Seric 		break;
11438256Seric 
11448256Seric 	  case 'H':		/* help file */
11459381Seric 		if (val[0] == '\0')
11468269Seric 			HelpFile = "sendmail.hf";
11479381Seric 		else
11489381Seric 			HelpFile = newstr(val);
11498256Seric 		break;
11508256Seric 
115151305Seric 	  case 'h':		/* maximum hop count */
115251305Seric 		MaxHopCount = atoi(val);
115351305Seric 		break;
115451305Seric 
115535651Seric 	  case 'I':		/* use internet domain name server */
115657207Seric #ifdef NAMED_BIND
115757207Seric 		UseNameServer = TRUE;
115857207Seric 		for (p = val; *p != 0; )
115957207Seric 		{
116057207Seric 			bool clearmode;
116157207Seric 			char *q;
116257207Seric 			struct resolverflags *rfp;
116357207Seric 
116457207Seric 			while (*p == ' ')
116557207Seric 				p++;
116657207Seric 			if (*p == '\0')
116757207Seric 				break;
116857207Seric 			clearmode = FALSE;
116957207Seric 			if (*p == '-')
117057207Seric 				clearmode = TRUE;
117157207Seric 			else if (*p != '+')
117257207Seric 				p--;
117357207Seric 			p++;
117457207Seric 			q = p;
117558050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
117657207Seric 				p++;
117757207Seric 			if (*p != '\0')
117857207Seric 				*p++ = '\0';
117957207Seric 			for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
118057207Seric 			{
118157207Seric 				if (strcasecmp(q, rfp->rf_name) == 0)
118257207Seric 					break;
118357207Seric 			}
118457207Seric 			if (clearmode)
118557207Seric 				_res.options &= ~rfp->rf_bits;
118657207Seric 			else
118757207Seric 				_res.options |= rfp->rf_bits;
118857207Seric 		}
118957207Seric 		if (tTd(8, 2))
119057207Seric 			printf("_res.options = %x\n", _res.options);
119157207Seric #else
119257207Seric 		usrerr("name server (I option) specified but BIND not compiled in");
119357207Seric #endif
119435651Seric 		break;
119535651Seric 
11968269Seric 	  case 'i':		/* ignore dot lines in message */
11979381Seric 		IgnrDot = atobool(val);
11988269Seric 		break;
11998269Seric 
120059730Seric 	  case 'j':		/* send errors in MIME (RFC 1341) format */
120159730Seric 		SendMIMEErrors = atobool(val);
120259730Seric 		break;
120359730Seric 
120457136Seric 	  case 'J':		/* .forward search path */
120557136Seric 		ForwardPath = newstr(val);
120657136Seric 		break;
120757136Seric 
120854967Seric 	  case 'k':		/* connection cache size */
120954967Seric 		MaxMciCache = atoi(val);
121056215Seric 		if (MaxMciCache < 0)
121156215Seric 			MaxMciCache = 0;
121254967Seric 		break;
121354967Seric 
121454967Seric 	  case 'K':		/* connection cache timeout */
121558796Seric 		MciCacheTimeout = convtime(val, 'm');
121654967Seric 		break;
121754967Seric 
121861104Seric 	  case 'l':		/* use Errors-To: header */
121961104Seric 		UseErrorsTo = atobool(val);
122061104Seric 		break;
122161104Seric 
12228256Seric 	  case 'L':		/* log level */
122364140Seric 		if (safe || LogLevel < atoi(val))
122464140Seric 			LogLevel = atoi(val);
12258256Seric 		break;
12268256Seric 
12278269Seric 	  case 'M':		/* define macro */
12289381Seric 		define(val[0], newstr(&val[1]), CurEnv);
122916878Seric 		sticky = FALSE;
12308269Seric 		break;
12318269Seric 
12328269Seric 	  case 'm':		/* send to me too */
12339381Seric 		MeToo = atobool(val);
12348269Seric 		break;
12358269Seric 
123625820Seric 	  case 'n':		/* validate RHS in newaliases */
123725820Seric 		CheckAliases = atobool(val);
123825820Seric 		break;
123925820Seric 
124061104Seric 	    /* 'N' available -- was "net name" */
124161104Seric 
124258851Seric 	  case 'O':		/* daemon options */
124358851Seric 		setdaemonoptions(val);
124458851Seric 		break;
124558851Seric 
12468269Seric 	  case 'o':		/* assume old style headers */
12479381Seric 		if (atobool(val))
12489341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
12499341Seric 		else
12509341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
12518269Seric 		break;
12528269Seric 
125358082Seric 	  case 'p':		/* select privacy level */
125458082Seric 		p = val;
125558082Seric 		for (;;)
125658082Seric 		{
125758082Seric 			register struct prival *pv;
125858082Seric 			extern struct prival PrivacyValues[];
125958082Seric 
126058082Seric 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
126158082Seric 				p++;
126258082Seric 			if (*p == '\0')
126358082Seric 				break;
126458082Seric 			val = p;
126558082Seric 			while (isascii(*p) && isalnum(*p))
126658082Seric 				p++;
126758082Seric 			if (*p != '\0')
126858082Seric 				*p++ = '\0';
126958082Seric 
127058082Seric 			for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
127158082Seric 			{
127258082Seric 				if (strcasecmp(val, pv->pv_name) == 0)
127358082Seric 					break;
127458082Seric 			}
127558886Seric 			if (pv->pv_name == NULL)
127658886Seric 				syserr("readcf: Op line: %s unrecognized", val);
127758082Seric 			PrivacyFlags |= pv->pv_flag;
127858082Seric 		}
127958082Seric 		break;
128058082Seric 
128124944Seric 	  case 'P':		/* postmaster copy address for returned mail */
128224944Seric 		PostMasterCopy = newstr(val);
128324944Seric 		break;
128424944Seric 
128524944Seric 	  case 'q':		/* slope of queue only function */
128624944Seric 		QueueFactor = atoi(val);
128724944Seric 		break;
128824944Seric 
12898256Seric 	  case 'Q':		/* queue directory */
12909381Seric 		if (val[0] == '\0')
12918269Seric 			QueueDir = "mqueue";
12929381Seric 		else
12939381Seric 			QueueDir = newstr(val);
129458789Seric 		if (RealUid != 0 && !safe)
129558789Seric 			auth_warning(e, "Processed from queue %s", QueueDir);
12968256Seric 		break;
12978256Seric 
129858148Seric 	  case 'R':		/* don't prune routes */
129958148Seric 		DontPruneRoutes = atobool(val);
130058148Seric 		break;
130158148Seric 
13028256Seric 	  case 'r':		/* read timeout */
130358112Seric 		settimeouts(val);
13048256Seric 		break;
13058256Seric 
13068256Seric 	  case 'S':		/* status file */
13079381Seric 		if (val[0] == '\0')
13088269Seric 			StatFile = "sendmail.st";
13099381Seric 		else
13109381Seric 			StatFile = newstr(val);
13118256Seric 		break;
13128256Seric 
13138265Seric 	  case 's':		/* be super safe, even if expensive */
13149381Seric 		SuperSafe = atobool(val);
13158256Seric 		break;
13168256Seric 
13178256Seric 	  case 'T':		/* queue timeout */
131858737Seric 		p = strchr(val, '/');
131958737Seric 		if (p != NULL)
132058737Seric 		{
132158737Seric 			*p++ = '\0';
132258796Seric 			TimeOuts.to_q_warning = convtime(p, 'd');
132358737Seric 		}
132458796Seric 		TimeOuts.to_q_return = convtime(val, 'h');
132554967Seric 		break;
13268256Seric 
13278265Seric 	  case 't':		/* time zone name */
132852106Seric 		TimeZoneSpec = newstr(val);
13298265Seric 		break;
13308265Seric 
133150556Seric 	  case 'U':		/* location of user database */
133251360Seric 		UdbSpec = newstr(val);
133350556Seric 		break;
133450556Seric 
13358256Seric 	  case 'u':		/* set default uid */
133664133Seric 		if (isascii(*val) && isdigit(*val))
133764133Seric 			DefUid = atoi(val);
133864133Seric 		else
133964133Seric 		{
134064133Seric 			register struct passwd *pw;
134164133Seric 
134264133Seric 			DefUid = -1;
134364133Seric 			pw = getpwnam(val);
134464133Seric 			if (pw == NULL)
134564133Seric 				syserr("readcf: option u: unknown user %s", val);
134664133Seric 			else
134764133Seric 				DefUid = pw->pw_uid;
134864133Seric 		}
134940973Sbostic 		setdefuser();
13508256Seric 		break;
13518256Seric 
135258851Seric 	  case 'V':		/* fallback MX host */
135358851Seric 		FallBackMX = newstr(val);
135458851Seric 		break;
135558851Seric 
13568269Seric 	  case 'v':		/* run in verbose mode */
13579381Seric 		Verbose = atobool(val);
13588256Seric 		break;
13598256Seric 
136063837Seric 	  case 'w':		/* if we are best MX, try host directly */
136163837Seric 		TryNullMXList = atobool(val);
136263837Seric 		break;
136361104Seric 
136461104Seric 	    /* 'W' available -- was wizard password */
136561104Seric 
136614879Seric 	  case 'x':		/* load avg at which to auto-queue msgs */
136714879Seric 		QueueLA = atoi(val);
136814879Seric 		break;
136914879Seric 
137014879Seric 	  case 'X':		/* load avg at which to auto-reject connections */
137114879Seric 		RefuseLA = atoi(val);
137214879Seric 		break;
137314879Seric 
137424981Seric 	  case 'y':		/* work recipient factor */
137524981Seric 		WkRecipFact = atoi(val);
137624981Seric 		break;
137724981Seric 
137824981Seric 	  case 'Y':		/* fork jobs during queue runs */
137924952Seric 		ForkQueueRuns = atobool(val);
138024952Seric 		break;
138124952Seric 
138224981Seric 	  case 'z':		/* work message class factor */
138324981Seric 		WkClassFact = atoi(val);
138424981Seric 		break;
138524981Seric 
138624981Seric 	  case 'Z':		/* work time factor */
138724981Seric 		WkTimeFact = atoi(val);
138824981Seric 		break;
138924981Seric 
13908256Seric 	  default:
13918256Seric 		break;
13928256Seric 	}
139316878Seric 	if (sticky)
139416878Seric 		setbitn(opt, StickyOpt);
13959188Seric 	return;
13968256Seric }
139710687Seric /*
139810687Seric **  SETCLASS -- set a word into a class
139910687Seric **
140010687Seric **	Parameters:
140110687Seric **		class -- the class to put the word in.
140210687Seric **		word -- the word to enter
140310687Seric **
140410687Seric **	Returns:
140510687Seric **		none.
140610687Seric **
140710687Seric **	Side Effects:
140810687Seric **		puts the word into the symbol table.
140910687Seric */
141010687Seric 
141110687Seric setclass(class, word)
141210687Seric 	int class;
141310687Seric 	char *word;
141410687Seric {
141510687Seric 	register STAB *s;
141610687Seric 
141757943Seric 	if (tTd(37, 8))
1418*64326Seric 		printf("setclass(%c, %s)\n", class, word);
141910687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
142010687Seric 	setbitn(class, s->s_class);
142110687Seric }
142253654Seric /*
142353654Seric **  MAKEMAPENTRY -- create a map entry
142453654Seric **
142553654Seric **	Parameters:
142653654Seric **		line -- the config file line
142753654Seric **
142853654Seric **	Returns:
142953654Seric **		TRUE if it successfully entered the map entry.
143053654Seric **		FALSE otherwise (usually syntax error).
143153654Seric **
143253654Seric **	Side Effects:
143353654Seric **		Enters the map into the dictionary.
143453654Seric */
143553654Seric 
143653654Seric void
143753654Seric makemapentry(line)
143853654Seric 	char *line;
143953654Seric {
144053654Seric 	register char *p;
144153654Seric 	char *mapname;
144253654Seric 	char *classname;
144364078Seric 	register STAB *s;
144453654Seric 	STAB *class;
144553654Seric 
144658050Seric 	for (p = line; isascii(*p) && isspace(*p); p++)
144753654Seric 		continue;
144858050Seric 	if (!(isascii(*p) && isalnum(*p)))
144953654Seric 	{
145053654Seric 		syserr("readcf: config K line: no map name");
145153654Seric 		return;
145253654Seric 	}
145353654Seric 
145453654Seric 	mapname = p;
145558050Seric 	while (isascii(*++p) && isalnum(*p))
145653654Seric 		continue;
145753654Seric 	if (*p != '\0')
145853654Seric 		*p++ = '\0';
145958050Seric 	while (isascii(*p) && isspace(*p))
146053654Seric 		p++;
146158050Seric 	if (!(isascii(*p) && isalnum(*p)))
146253654Seric 	{
146353654Seric 		syserr("readcf: config K line, map %s: no map class", mapname);
146453654Seric 		return;
146553654Seric 	}
146653654Seric 	classname = p;
146758050Seric 	while (isascii(*++p) && isalnum(*p))
146853654Seric 		continue;
146953654Seric 	if (*p != '\0')
147053654Seric 		*p++ = '\0';
147158050Seric 	while (isascii(*p) && isspace(*p))
147253654Seric 		p++;
147353654Seric 
147453654Seric 	/* look up the class */
147553654Seric 	class = stab(classname, ST_MAPCLASS, ST_FIND);
147653654Seric 	if (class == NULL)
147753654Seric 	{
147853654Seric 		syserr("readcf: map %s: class %s not available", mapname, classname);
147953654Seric 		return;
148053654Seric 	}
148153654Seric 
148253654Seric 	/* enter the map */
148364078Seric 	s = stab(mapname, ST_MAP, ST_ENTER);
148464078Seric 	s->s_map.map_class = &class->s_mapclass;
148564078Seric 	s->s_map.map_mname = newstr(mapname);
148653654Seric 
148764078Seric 	if (class->s_mapclass.map_parse(&s->s_map, p))
148864078Seric 		s->s_map.map_mflags |= MF_VALID;
148964078Seric 
149064078Seric 	if (tTd(37, 5))
149164078Seric 	{
149264078Seric 		printf("map %s, class %s, flags %x, file %s,\n",
149364078Seric 			s->s_map.map_mname, s->s_map.map_class->map_cname,
149464078Seric 			s->s_map.map_mflags,
149564078Seric 			s->s_map.map_file == NULL ? "(null)" : s->s_map.map_file);
149664078Seric 		printf("\tapp %s, domain %s, rebuild %s\n",
149764078Seric 			s->s_map.map_app == NULL ? "(null)" : s->s_map.map_app,
149864078Seric 			s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain,
149964078Seric 			s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild);
150064078Seric 	}
150153654Seric }
150258112Seric /*
150358112Seric **  SETTIMEOUTS -- parse and set timeout values
150458112Seric **
150558112Seric **	Parameters:
150658112Seric **		val -- a pointer to the values.  If NULL, do initial
150758112Seric **			settings.
150858112Seric **
150958112Seric **	Returns:
151058112Seric **		none.
151158112Seric **
151258112Seric **	Side Effects:
151358112Seric **		Initializes the TimeOuts structure
151458112Seric */
151558112Seric 
151664255Seric #define SECONDS
151758112Seric #define MINUTES	* 60
151858112Seric #define HOUR	* 3600
151958112Seric 
152058112Seric settimeouts(val)
152158112Seric 	register char *val;
152258112Seric {
152358112Seric 	register char *p;
152458671Seric 	extern time_t convtime();
152558112Seric 
152658112Seric 	if (val == NULL)
152758112Seric 	{
152858112Seric 		TimeOuts.to_initial = (time_t) 5 MINUTES;
152958112Seric 		TimeOuts.to_helo = (time_t) 5 MINUTES;
153058112Seric 		TimeOuts.to_mail = (time_t) 10 MINUTES;
153158112Seric 		TimeOuts.to_rcpt = (time_t) 1 HOUR;
153258112Seric 		TimeOuts.to_datainit = (time_t) 5 MINUTES;
153358112Seric 		TimeOuts.to_datablock = (time_t) 1 HOUR;
153458112Seric 		TimeOuts.to_datafinal = (time_t) 1 HOUR;
153558112Seric 		TimeOuts.to_rset = (time_t) 5 MINUTES;
153658112Seric 		TimeOuts.to_quit = (time_t) 2 MINUTES;
153758112Seric 		TimeOuts.to_nextcommand = (time_t) 1 HOUR;
153858112Seric 		TimeOuts.to_miscshort = (time_t) 2 MINUTES;
153964255Seric 		TimeOuts.to_ident = (time_t) 30 SECONDS;
154058112Seric 		return;
154158112Seric 	}
154258112Seric 
154358112Seric 	for (;; val = p)
154458112Seric 	{
154558112Seric 		while (isascii(*val) && isspace(*val))
154658112Seric 			val++;
154758112Seric 		if (*val == '\0')
154858112Seric 			break;
154958112Seric 		for (p = val; *p != '\0' && *p != ','; p++)
155058112Seric 			continue;
155158112Seric 		if (*p != '\0')
155258112Seric 			*p++ = '\0';
155358112Seric 
155458112Seric 		if (isascii(*val) && isdigit(*val))
155558112Seric 		{
155658112Seric 			/* old syntax -- set everything */
155758796Seric 			TimeOuts.to_mail = convtime(val, 'm');
155858112Seric 			TimeOuts.to_rcpt = TimeOuts.to_mail;
155958112Seric 			TimeOuts.to_datainit = TimeOuts.to_mail;
156058112Seric 			TimeOuts.to_datablock = TimeOuts.to_mail;
156158112Seric 			TimeOuts.to_datafinal = TimeOuts.to_mail;
156258112Seric 			TimeOuts.to_nextcommand = TimeOuts.to_mail;
156358112Seric 			continue;
156458112Seric 		}
156558112Seric 		else
156658112Seric 		{
156758112Seric 			register char *q = strchr(val, '=');
156858112Seric 			time_t to;
156958112Seric 
157058112Seric 			if (q == NULL)
157158112Seric 			{
157258112Seric 				/* syntax error */
157358112Seric 				continue;
157458112Seric 			}
157558112Seric 			*q++ = '\0';
157658796Seric 			to = convtime(q, 'm');
157758112Seric 
157858112Seric 			if (strcasecmp(val, "initial") == 0)
157958112Seric 				TimeOuts.to_initial = to;
158058112Seric 			else if (strcasecmp(val, "mail") == 0)
158158112Seric 				TimeOuts.to_mail = to;
158258112Seric 			else if (strcasecmp(val, "rcpt") == 0)
158358112Seric 				TimeOuts.to_rcpt = to;
158458112Seric 			else if (strcasecmp(val, "datainit") == 0)
158558112Seric 				TimeOuts.to_datainit = to;
158658112Seric 			else if (strcasecmp(val, "datablock") == 0)
158758112Seric 				TimeOuts.to_datablock = to;
158858112Seric 			else if (strcasecmp(val, "datafinal") == 0)
158958112Seric 				TimeOuts.to_datafinal = to;
159058112Seric 			else if (strcasecmp(val, "command") == 0)
159158112Seric 				TimeOuts.to_nextcommand = to;
159258112Seric 			else if (strcasecmp(val, "rset") == 0)
159358112Seric 				TimeOuts.to_rset = to;
159458112Seric 			else if (strcasecmp(val, "helo") == 0)
159558112Seric 				TimeOuts.to_helo = to;
159658112Seric 			else if (strcasecmp(val, "quit") == 0)
159758112Seric 				TimeOuts.to_quit = to;
159858112Seric 			else if (strcasecmp(val, "misc") == 0)
159958112Seric 				TimeOuts.to_miscshort = to;
160064255Seric 			else if (strcasecmp(val, "ident") == 0)
160164255Seric 				TimeOuts.to_ident = to;
160258112Seric 			else
160358112Seric 				syserr("settimeouts: invalid timeout %s", val);
160458112Seric 		}
160558112Seric 	}
160658112Seric }
1607