xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 58886)
122709Sdist /*
234921Sbostic  * Copyright (c) 1983 Eric P. Allman
333731Sbostic  * Copyright (c) 1988 Regents of the University of California.
433731Sbostic  * All rights reserved.
533731Sbostic  *
642829Sbostic  * %sccs.include.redist.c%
733731Sbostic  */
822709Sdist 
922709Sdist #ifndef lint
10*58886Seric static char sccsid[] = "@(#)readcf.c	6.24 (Berkeley) 03/30/93";
1133731Sbostic #endif /* not lint */
1222709Sdist 
133313Seric # include "sendmail.h"
1452647Seric # include <sys/stat.h>
1557207Seric #ifdef NAMED_BIND
1657207Seric # include <arpa/nameser.h>
1757207Seric # include <resolv.h>
1857207Seric #endif
193308Seric 
2057736Seric /* System 5 compatibility */
2157736Seric #ifndef S_ISREG
2257736Seric #define S_ISREG(foo)	((foo & S_IFREG) == S_IFREG)
2357736Seric #endif
2457736Seric #ifndef S_IWGRP
2557736Seric #define S_IWGRP		020
2657736Seric #endif
2757736Seric #ifndef S_IWOTH
2857736Seric #define S_IWOTH		002
2957736Seric #endif
3057736Seric 
313308Seric /*
323308Seric **  READCF -- read control file.
333308Seric **
343308Seric **	This routine reads the control file and builds the internal
353308Seric **	form.
363308Seric **
374432Seric **	The file is formatted as a sequence of lines, each taken
384432Seric **	atomically.  The first character of each line describes how
394432Seric **	the line is to be interpreted.  The lines are:
404432Seric **		Dxval		Define macro x to have value val.
414432Seric **		Cxword		Put word into class x.
424432Seric **		Fxfile [fmt]	Read file for lines to put into
434432Seric **				class x.  Use scanf string 'fmt'
444432Seric **				or "%s" if not present.  Fmt should
454432Seric **				only produce one string-valued result.
464432Seric **		Hname: value	Define header with field-name 'name'
474432Seric **				and value as specified; this will be
484432Seric **				macro expanded immediately before
494432Seric **				use.
504432Seric **		Sn		Use rewriting set n.
514432Seric **		Rlhs rhs	Rewrite addresses that match lhs to
524432Seric **				be rhs.
5324944Seric **		Mn arg=val...	Define mailer.  n is the internal name.
5424944Seric **				Args specify mailer parameters.
558252Seric **		Oxvalue		Set option x to value.
568252Seric **		Pname=value	Set precedence name to value.
5752645Seric **		Vversioncode	Version level of configuration syntax.
5853654Seric **		Kmapname mapclass arguments....
5953654Seric **				Define keyed lookup of a given class.
6053654Seric **				Arguments are class dependent.
614432Seric **
623308Seric **	Parameters:
633308Seric **		cfname -- control file name.
6454973Seric **		safe -- TRUE if this is the system config file;
6554973Seric **			FALSE otherwise.
6655012Seric **		e -- the main envelope.
673308Seric **
683308Seric **	Returns:
693308Seric **		none.
703308Seric **
713308Seric **	Side Effects:
723308Seric **		Builds several internal tables.
733308Seric */
743308Seric 
7555012Seric readcf(cfname, safe, e)
763308Seric 	char *cfname;
7754973Seric 	bool safe;
7855012Seric 	register ENVELOPE *e;
793308Seric {
803308Seric 	FILE *cf;
818547Seric 	int ruleset = 0;
828547Seric 	char *q;
838547Seric 	char **pv;
849350Seric 	struct rewrite *rwp = NULL;
8557135Seric 	char *bp;
8657589Seric 	int nfuzzy;
873308Seric 	char buf[MAXLINE];
883308Seric 	register char *p;
893308Seric 	extern char **prescan();
903308Seric 	extern char **copyplist();
9152647Seric 	struct stat statb;
925909Seric 	char exbuf[MAXLINE];
9316915Seric 	char pvpbuf[PSBUFSIZE];
949350Seric 	extern char *fgetfolded();
9510709Seric 	extern char *munchstring();
9653654Seric 	extern void makemapentry();
973308Seric 
9852647Seric 	FileName = cfname;
9952647Seric 	LineNumber = 0;
10052647Seric 
1013308Seric 	cf = fopen(cfname, "r");
1023308Seric 	if (cf == NULL)
1033308Seric 	{
10452647Seric 		syserr("cannot open");
1053308Seric 		exit(EX_OSFILE);
1063308Seric 	}
1073308Seric 
10852647Seric 	if (fstat(fileno(cf), &statb) < 0)
10952647Seric 	{
11052647Seric 		syserr("cannot fstat");
11152647Seric 		exit(EX_OSFILE);
11252647Seric 	}
11352647Seric 
11452647Seric 	if (!S_ISREG(statb.st_mode))
11552647Seric 	{
11652647Seric 		syserr("not a plain file");
11752647Seric 		exit(EX_OSFILE);
11852647Seric 	}
11952647Seric 
12052647Seric 	if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
12152647Seric 	{
12253037Seric 		if (OpMode == MD_DAEMON || OpMode == MD_FREEZE)
12353037Seric 			fprintf(stderr, "%s: WARNING: dangerous write permissions\n",
12453037Seric 				FileName);
12553037Seric #ifdef LOG
12653037Seric 		if (LogLevel > 0)
12753037Seric 			syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions",
12853037Seric 				FileName);
12953037Seric #endif
13052647Seric 	}
13152647Seric 
13257135Seric 	while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL)
1333308Seric 	{
13457135Seric 		if (bp[0] == '#')
13557135Seric 		{
13657135Seric 			if (bp != buf)
13757135Seric 				free(bp);
13852637Seric 			continue;
13957135Seric 		}
14052637Seric 
14158050Seric 		/* map $ into \201 for macro expansion */
14257135Seric 		for (p = bp; *p != '\0'; p++)
14316157Seric 		{
14457135Seric 			if (*p == '#' && p > bp && ConfigLevel >= 3)
14552647Seric 			{
14652647Seric 				/* this is an on-line comment */
14752647Seric 				register char *e;
14852647Seric 
14958050Seric 				switch (*--p & 0377)
15052647Seric 				{
15158050Seric 				  case MACROEXPAND:
15252647Seric 					/* it's from $# -- let it go through */
15352647Seric 					p++;
15452647Seric 					break;
15552647Seric 
15652647Seric 				  case '\\':
15752647Seric 					/* it's backslash escaped */
15852647Seric 					(void) strcpy(p, p + 1);
15952647Seric 					break;
16052647Seric 
16152647Seric 				  default:
16252647Seric 					/* delete preceeding white space */
16358050Seric 					while (isascii(*p) && isspace(*p) && p > bp)
16452647Seric 						p--;
16556795Seric 					if ((e = strchr(++p, '\n')) != NULL)
16652647Seric 						(void) strcpy(p, e);
16752647Seric 					else
16852647Seric 						p[0] = p[1] = '\0';
16952647Seric 					break;
17052647Seric 				}
17152647Seric 				continue;
17252647Seric 			}
17352647Seric 
17416157Seric 			if (*p != '$')
17516157Seric 				continue;
17616157Seric 
17716157Seric 			if (p[1] == '$')
17816157Seric 			{
17916157Seric 				/* actual dollar sign.... */
18023111Seric 				(void) strcpy(p, p + 1);
18116157Seric 				continue;
18216157Seric 			}
18316157Seric 
18416157Seric 			/* convert to macro expansion character */
18558050Seric 			*p = MACROEXPAND;
18616157Seric 		}
18716157Seric 
18816157Seric 		/* interpret this line */
18957135Seric 		switch (bp[0])
1903308Seric 		{
1913308Seric 		  case '\0':
1923308Seric 		  case '#':		/* comment */
1933308Seric 			break;
1943308Seric 
1953308Seric 		  case 'R':		/* rewriting rule */
19657135Seric 			for (p = &bp[1]; *p != '\0' && *p != '\t'; p++)
1973308Seric 				continue;
1983308Seric 
1993308Seric 			if (*p == '\0')
2005909Seric 			{
20157135Seric 				syserr("invalid rewrite line \"%s\"", bp);
2025909Seric 				break;
2035909Seric 			}
2045909Seric 
2055909Seric 			/* allocate space for the rule header */
2065909Seric 			if (rwp == NULL)
2075909Seric 			{
2085909Seric 				RewriteRules[ruleset] = rwp =
2095909Seric 					(struct rewrite *) xalloc(sizeof *rwp);
2105909Seric 			}
2113308Seric 			else
2123308Seric 			{
2135909Seric 				rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
2145909Seric 				rwp = rwp->r_next;
2155909Seric 			}
2165909Seric 			rwp->r_next = NULL;
2173308Seric 
2185909Seric 			/* expand and save the LHS */
2195909Seric 			*p = '\0';
22057135Seric 			expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e);
22158333Seric 			rwp->r_lhs = prescan(exbuf, '\t', pvpbuf, NULL);
22257589Seric 			nfuzzy = 0;
2235909Seric 			if (rwp->r_lhs != NULL)
22457589Seric 			{
22557589Seric 				register char **ap;
22657589Seric 
2275909Seric 				rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
22857589Seric 
22957589Seric 				/* count the number of fuzzy matches in LHS */
23057589Seric 				for (ap = rwp->r_lhs; *ap != NULL; ap++)
23157589Seric 				{
23258148Seric 					char *botch;
23358148Seric 
23458148Seric 					botch = NULL;
23558050Seric 					switch (**ap & 0377)
23657589Seric 					{
23757589Seric 					  case MATCHZANY:
23857589Seric 					  case MATCHANY:
23957589Seric 					  case MATCHONE:
24057589Seric 					  case MATCHCLASS:
24157589Seric 					  case MATCHNCLASS:
24257589Seric 						nfuzzy++;
24358148Seric 						break;
24458148Seric 
24558148Seric 					  case MATCHREPL:
24658148Seric 						botch = "$0-$9";
24758148Seric 						break;
24858148Seric 
24958148Seric 					  case CANONNET:
25058148Seric 						botch = "$#";
25158148Seric 						break;
25258148Seric 
25358148Seric 					  case CANONUSER:
25458148Seric 						botch = "$:";
25558148Seric 						break;
25658148Seric 
25758148Seric 					  case CALLSUBR:
25858148Seric 						botch = "$>";
25958148Seric 						break;
26058148Seric 
26158148Seric 					  case CONDIF:
26258148Seric 						botch = "$?";
26358148Seric 						break;
26458148Seric 
26558148Seric 					  case CONDELSE:
26658148Seric 						botch = "$|";
26758148Seric 						break;
26858148Seric 
26958148Seric 					  case CONDFI:
27058148Seric 						botch = "$.";
27158148Seric 						break;
27258148Seric 
27358148Seric 					  case HOSTBEGIN:
27458148Seric 						botch = "$[";
27558148Seric 						break;
27658148Seric 
27758148Seric 					  case HOSTEND:
27858148Seric 						botch = "$]";
27958148Seric 						break;
28058148Seric 
28158148Seric 					  case LOOKUPBEGIN:
28258148Seric 						botch = "$(";
28358148Seric 						break;
28458148Seric 
28558148Seric 					  case LOOKUPEND:
28658148Seric 						botch = "$)";
28758148Seric 						break;
28857589Seric 					}
28958148Seric 					if (botch != NULL)
29058148Seric 						syserr("Inappropriate use of %s on LHS",
29158148Seric 							botch);
29257589Seric 				}
29357589Seric 			}
29456678Seric 			else
29556678Seric 				syserr("R line: null LHS");
2965909Seric 
2975909Seric 			/* expand and save the RHS */
2985909Seric 			while (*++p == '\t')
2995909Seric 				continue;
3007231Seric 			q = p;
3017231Seric 			while (*p != '\0' && *p != '\t')
3027231Seric 				p++;
3037231Seric 			*p = '\0';
30455012Seric 			expand(q, exbuf, &exbuf[sizeof exbuf], e);
30558333Seric 			rwp->r_rhs = prescan(exbuf, '\t', pvpbuf, NULL);
3065909Seric 			if (rwp->r_rhs != NULL)
30757589Seric 			{
30857589Seric 				register char **ap;
30957589Seric 
3105909Seric 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
31157589Seric 
31257589Seric 				/* check no out-of-bounds replacements */
31357589Seric 				nfuzzy += '0';
31457589Seric 				for (ap = rwp->r_rhs; *ap != NULL; ap++)
31557589Seric 				{
31658148Seric 					char *botch;
31758148Seric 
31858148Seric 					botch = NULL;
31958148Seric 					switch (**ap & 0377)
32057589Seric 					{
32158148Seric 					  case MATCHREPL:
32258148Seric 						if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy)
32358148Seric 						{
32458148Seric 							syserr("replacement $%c out of bounds",
32558148Seric 								(*ap)[1]);
32658148Seric 						}
32758148Seric 						break;
32858148Seric 
32958148Seric 					  case MATCHZANY:
33058148Seric 						botch = "$*";
33158148Seric 						break;
33258148Seric 
33358148Seric 					  case MATCHANY:
33458148Seric 						botch = "$+";
33558148Seric 						break;
33658148Seric 
33758148Seric 					  case MATCHONE:
33858148Seric 						botch = "$-";
33958148Seric 						break;
34058148Seric 
34158148Seric 					  case MATCHCLASS:
34258148Seric 						botch = "$=";
34358148Seric 						break;
34458148Seric 
34558148Seric 					  case MATCHNCLASS:
34658148Seric 						botch = "$~";
34758148Seric 						break;
34857589Seric 					}
34958148Seric 					if (botch != NULL)
35058148Seric 						syserr("Inappropriate use of %s on RHS",
35158148Seric 							botch);
35257589Seric 				}
35357589Seric 			}
35456678Seric 			else
35556678Seric 				syserr("R line: null RHS");
3563308Seric 			break;
3573308Seric 
3584072Seric 		  case 'S':		/* select rewriting set */
35957135Seric 			ruleset = atoi(&bp[1]);
3608056Seric 			if (ruleset >= MAXRWSETS || ruleset < 0)
3618056Seric 			{
3629381Seric 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
3638056Seric 				ruleset = 0;
3648056Seric 			}
3654072Seric 			rwp = NULL;
3664072Seric 			break;
3674072Seric 
3683308Seric 		  case 'D':		/* macro definition */
36958333Seric 			define(bp[1], newstr(munchstring(&bp[2], NULL)), e);
3703308Seric 			break;
3713308Seric 
3723387Seric 		  case 'H':		/* required header line */
37357135Seric 			(void) chompheader(&bp[1], TRUE, e);
3743387Seric 			break;
3753387Seric 
3764061Seric 		  case 'C':		/* word class */
3774432Seric 		  case 'F':		/* word class from file */
3784432Seric 			/* read list of words from argument or file */
37957135Seric 			if (bp[0] == 'F')
3804432Seric 			{
3814432Seric 				/* read from file */
38258050Seric 				for (p = &bp[2];
38358050Seric 				     *p != '\0' && !(isascii(*p) && isspace(*p));
38458050Seric 				     p++)
3854432Seric 					continue;
3864432Seric 				if (*p == '\0')
3874432Seric 					p = "%s";
3884432Seric 				else
3894432Seric 				{
3904432Seric 					*p = '\0';
39158050Seric 					while (isascii(*++p) && isspace(*p))
3924432Seric 						continue;
3934432Seric 				}
39457135Seric 				fileclass(bp[1], &bp[2], p, safe);
3954432Seric 				break;
3964432Seric 			}
3974061Seric 
3984432Seric 			/* scan the list of words and set class for all */
39957135Seric 			for (p = &bp[2]; *p != '\0'; )
4004061Seric 			{
4014061Seric 				register char *wd;
4024061Seric 				char delim;
4034061Seric 
40458050Seric 				while (*p != '\0' && isascii(*p) && isspace(*p))
4054061Seric 					p++;
4064061Seric 				wd = p;
40758050Seric 				while (*p != '\0' && !(isascii(*p) && isspace(*p)))
4084061Seric 					p++;
4094061Seric 				delim = *p;
4104061Seric 				*p = '\0';
4114061Seric 				if (wd[0] != '\0')
41258148Seric 				{
41358148Seric 					if (tTd(37, 2))
41458148Seric 						printf("setclass(%c, %s)\n",
41558148Seric 							bp[1], wd);
41657135Seric 					setclass(bp[1], wd);
41758148Seric 				}
4184061Seric 				*p = delim;
4194061Seric 			}
4204061Seric 			break;
4214061Seric 
4224096Seric 		  case 'M':		/* define mailer */
42357135Seric 			makemailer(&bp[1]);
4244096Seric 			break;
4254096Seric 
4268252Seric 		  case 'O':		/* set option */
42758734Seric 			setoption(bp[1], &bp[2], safe, FALSE, e);
4288252Seric 			break;
4298252Seric 
4308252Seric 		  case 'P':		/* set precedence */
4318252Seric 			if (NumPriorities >= MAXPRIORITIES)
4328252Seric 			{
4338547Seric 				toomany('P', MAXPRIORITIES);
4348252Seric 				break;
4358252Seric 			}
43657135Seric 			for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
4378252Seric 				continue;
4388252Seric 			if (*p == '\0')
4398252Seric 				goto badline;
4408252Seric 			*p = '\0';
44157135Seric 			Priorities[NumPriorities].pri_name = newstr(&bp[1]);
4428252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
4438252Seric 			NumPriorities++;
4448252Seric 			break;
4458252Seric 
4468547Seric 		  case 'T':		/* trusted user(s) */
44758161Seric 			/* this option is obsolete, but will be ignored */
4488547Seric 			break;
4498547Seric 
45052645Seric 		  case 'V':		/* configuration syntax version */
45157135Seric 			ConfigLevel = atoi(&bp[1]);
45252645Seric 			break;
45352645Seric 
45453654Seric 		  case 'K':
45557135Seric 			makemapentry(&bp[1]);
45653654Seric 			break;
45753654Seric 
4583308Seric 		  default:
4594061Seric 		  badline:
46057135Seric 			syserr("unknown control line \"%s\"", bp);
4613308Seric 		}
46257135Seric 		if (bp != buf)
46357135Seric 			free(bp);
4643308Seric 	}
46552637Seric 	if (ferror(cf))
46652637Seric 	{
46752647Seric 		syserr("I/O read error", cfname);
46852637Seric 		exit(EX_OSFILE);
46952637Seric 	}
47052637Seric 	fclose(cf);
4719381Seric 	FileName = NULL;
47256836Seric 
47357076Seric 	if (stab("host", ST_MAP, ST_FIND) == NULL)
47457076Seric 	{
47557076Seric 		/* user didn't initialize: set up host map */
47657076Seric 		strcpy(buf, "host host");
47757076Seric 		if (ConfigLevel >= 2)
47857076Seric 			strcat(buf, " -a.");
47957076Seric 		makemapentry(buf);
48057076Seric 	}
4814096Seric }
4824096Seric /*
4838547Seric **  TOOMANY -- signal too many of some option
4848547Seric **
4858547Seric **	Parameters:
4868547Seric **		id -- the id of the error line
4878547Seric **		maxcnt -- the maximum possible values
4888547Seric **
4898547Seric **	Returns:
4908547Seric **		none.
4918547Seric **
4928547Seric **	Side Effects:
4938547Seric **		gives a syserr.
4948547Seric */
4958547Seric 
4968547Seric toomany(id, maxcnt)
4978547Seric 	char id;
4988547Seric 	int maxcnt;
4998547Seric {
5009381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
5018547Seric }
5028547Seric /*
5034432Seric **  FILECLASS -- read members of a class from a file
5044432Seric **
5054432Seric **	Parameters:
5064432Seric **		class -- class to define.
5074432Seric **		filename -- name of file to read.
5084432Seric **		fmt -- scanf string to use for match.
5094432Seric **
5104432Seric **	Returns:
5114432Seric **		none
5124432Seric **
5134432Seric **	Side Effects:
5144432Seric **
5154432Seric **		puts all lines in filename that match a scanf into
5164432Seric **			the named class.
5174432Seric */
5184432Seric 
51954973Seric fileclass(class, filename, fmt, safe)
5204432Seric 	int class;
5214432Seric 	char *filename;
5224432Seric 	char *fmt;
52354973Seric 	bool safe;
5244432Seric {
52525808Seric 	FILE *f;
52654973Seric 	struct stat stbuf;
5274432Seric 	char buf[MAXLINE];
5284432Seric 
52954973Seric 	if (stat(filename, &stbuf) < 0)
53054973Seric 	{
53154973Seric 		syserr("fileclass: cannot stat %s", filename);
53254973Seric 		return;
53354973Seric 	}
53454973Seric 	if (!S_ISREG(stbuf.st_mode))
53554973Seric 	{
53654973Seric 		syserr("fileclass: %s not a regular file", filename);
53754973Seric 		return;
53854973Seric 	}
53954973Seric 	if (!safe && access(filename, R_OK) < 0)
54054973Seric 	{
54154973Seric 		syserr("fileclass: access denied on %s", filename);
54254973Seric 		return;
54354973Seric 	}
54454973Seric 	f = fopen(filename, "r");
5454432Seric 	if (f == NULL)
5464432Seric 	{
54754973Seric 		syserr("fileclass: cannot open %s", filename);
5484432Seric 		return;
5494432Seric 	}
5504432Seric 
5514432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
5524432Seric 	{
5534432Seric 		register STAB *s;
55425808Seric 		register char *p;
55525808Seric # ifdef SCANF
5564432Seric 		char wordbuf[MAXNAME+1];
5574432Seric 
5584432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
5594432Seric 			continue;
56025808Seric 		p = wordbuf;
56156795Seric # else /* SCANF */
56225808Seric 		p = buf;
56356795Seric # endif /* SCANF */
56425808Seric 
56525808Seric 		/*
56625808Seric 		**  Break up the match into words.
56725808Seric 		*/
56825808Seric 
56925808Seric 		while (*p != '\0')
57025808Seric 		{
57125808Seric 			register char *q;
57225808Seric 
57325808Seric 			/* strip leading spaces */
57458050Seric 			while (isascii(*p) && isspace(*p))
57525808Seric 				p++;
57625808Seric 			if (*p == '\0')
57725808Seric 				break;
57825808Seric 
57925808Seric 			/* find the end of the word */
58025808Seric 			q = p;
58158050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
58225808Seric 				p++;
58325808Seric 			if (*p != '\0')
58425808Seric 				*p++ = '\0';
58525808Seric 
58625808Seric 			/* enter the word in the symbol table */
58725808Seric 			s = stab(q, ST_CLASS, ST_ENTER);
58825808Seric 			setbitn(class, s->s_class);
58925808Seric 		}
5904432Seric 	}
5914432Seric 
59254973Seric 	(void) fclose(f);
5934432Seric }
5944432Seric /*
5954096Seric **  MAKEMAILER -- define a new mailer.
5964096Seric **
5974096Seric **	Parameters:
59810327Seric **		line -- description of mailer.  This is in labeled
59910327Seric **			fields.  The fields are:
60010327Seric **			   P -- the path to the mailer
60110327Seric **			   F -- the flags associated with the mailer
60210327Seric **			   A -- the argv for this mailer
60310327Seric **			   S -- the sender rewriting set
60410327Seric **			   R -- the recipient rewriting set
60510327Seric **			   E -- the eol string
60610327Seric **			The first word is the canonical name of the mailer.
6074096Seric **
6084096Seric **	Returns:
6094096Seric **		none.
6104096Seric **
6114096Seric **	Side Effects:
6124096Seric **		enters the mailer into the mailer table.
6134096Seric */
6143308Seric 
61521066Seric makemailer(line)
6164096Seric 	char *line;
6174096Seric {
6184096Seric 	register char *p;
6198067Seric 	register struct mailer *m;
6208067Seric 	register STAB *s;
6218067Seric 	int i;
62210327Seric 	char fcode;
62358020Seric 	auto char *endp;
6244096Seric 	extern int NextMailer;
62510327Seric 	extern char **makeargv();
62610327Seric 	extern char *munchstring();
62710701Seric 	extern long atol();
6284096Seric 
62910327Seric 	/* allocate a mailer and set up defaults */
63010327Seric 	m = (struct mailer *) xalloc(sizeof *m);
63110327Seric 	bzero((char *) m, sizeof *m);
63210327Seric 	m->m_eol = "\n";
63310327Seric 
63410327Seric 	/* collect the mailer name */
63558050Seric 	for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++)
63610327Seric 		continue;
63710327Seric 	if (*p != '\0')
63810327Seric 		*p++ = '\0';
63910327Seric 	m->m_name = newstr(line);
64010327Seric 
64110327Seric 	/* now scan through and assign info from the fields */
64210327Seric 	while (*p != '\0')
64310327Seric 	{
64458333Seric 		auto char *delimptr;
64558333Seric 
64658050Seric 		while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p))))
64710327Seric 			p++;
64810327Seric 
64910327Seric 		/* p now points to field code */
65010327Seric 		fcode = *p;
65110327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
65210327Seric 			p++;
65310327Seric 		if (*p++ != '=')
65410327Seric 		{
65552637Seric 			syserr("mailer %s: `=' expected", m->m_name);
65610327Seric 			return;
65710327Seric 		}
65858050Seric 		while (isascii(*p) && isspace(*p))
65910327Seric 			p++;
66010327Seric 
66110327Seric 		/* p now points to the field body */
66258333Seric 		p = munchstring(p, &delimptr);
66310327Seric 
66410327Seric 		/* install the field into the mailer struct */
66510327Seric 		switch (fcode)
66610327Seric 		{
66710327Seric 		  case 'P':		/* pathname */
66810327Seric 			m->m_mailer = newstr(p);
66910327Seric 			break;
67010327Seric 
67110327Seric 		  case 'F':		/* flags */
67210687Seric 			for (; *p != '\0'; p++)
67358050Seric 				if (!(isascii(*p) && isspace(*p)))
67452637Seric 					setbitn(*p, m->m_flags);
67510327Seric 			break;
67610327Seric 
67710327Seric 		  case 'S':		/* sender rewriting ruleset */
67810327Seric 		  case 'R':		/* recipient rewriting ruleset */
67958020Seric 			i = strtol(p, &endp, 10);
68010327Seric 			if (i < 0 || i >= MAXRWSETS)
68110327Seric 			{
68210327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
68310327Seric 				return;
68410327Seric 			}
68510327Seric 			if (fcode == 'S')
68658020Seric 				m->m_sh_rwset = m->m_se_rwset = i;
68710327Seric 			else
68858020Seric 				m->m_rh_rwset = m->m_re_rwset = i;
68958020Seric 
69058020Seric 			p = endp;
69158020Seric 			if (*p == '/')
69258020Seric 			{
69358020Seric 				i = strtol(p, NULL, 10);
69458020Seric 				if (i < 0 || i >= MAXRWSETS)
69558020Seric 				{
69658020Seric 					syserr("invalid rewrite set, %d max",
69758020Seric 						MAXRWSETS);
69858020Seric 					return;
69958020Seric 				}
70058020Seric 				if (fcode == 'S')
70158020Seric 					m->m_sh_rwset = i;
70258020Seric 				else
70358020Seric 					m->m_rh_rwset = i;
70458020Seric 			}
70510327Seric 			break;
70610327Seric 
70710327Seric 		  case 'E':		/* end of line string */
70810327Seric 			m->m_eol = newstr(p);
70910327Seric 			break;
71010327Seric 
71110327Seric 		  case 'A':		/* argument vector */
71210327Seric 			m->m_argv = makeargv(p);
71310327Seric 			break;
71410701Seric 
71510701Seric 		  case 'M':		/* maximum message size */
71610701Seric 			m->m_maxsize = atol(p);
71710701Seric 			break;
71852106Seric 
71952106Seric 		  case 'L':		/* maximum line length */
72052106Seric 			m->m_linelimit = atoi(p);
72152106Seric 			break;
72210327Seric 		}
72310327Seric 
72458333Seric 		p = delimptr;
72510327Seric 	}
72610327Seric 
72752106Seric 	/* do some heuristic cleanup for back compatibility */
72852106Seric 	if (bitnset(M_LIMITS, m->m_flags))
72952106Seric 	{
73052106Seric 		if (m->m_linelimit == 0)
73152106Seric 			m->m_linelimit = SMTPLINELIM;
73255418Seric 		if (ConfigLevel < 2)
73352106Seric 			setbitn(M_7BITS, m->m_flags);
73452106Seric 	}
73552106Seric 
73658321Seric 	/* do some rationality checking */
73758321Seric 	if (m->m_argv == NULL)
73858321Seric 	{
73958321Seric 		syserr("M%s: A= argument required", m->m_name);
74058321Seric 		return;
74158321Seric 	}
74258321Seric 	if (m->m_mailer == NULL)
74358321Seric 	{
74458321Seric 		syserr("M%s: P= argument required", m->m_name);
74558321Seric 		return;
74658321Seric 	}
74758321Seric 
7484096Seric 	if (NextMailer >= MAXMAILERS)
7494096Seric 	{
7509381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
7514096Seric 		return;
7524096Seric 	}
75357402Seric 
75410327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
75557402Seric 	if (s->s_mailer != NULL)
75657402Seric 	{
75757402Seric 		i = s->s_mailer->m_mno;
75857402Seric 		free(s->s_mailer);
75957402Seric 	}
76057402Seric 	else
76157402Seric 	{
76257402Seric 		i = NextMailer++;
76357402Seric 	}
76457402Seric 	Mailer[i] = s->s_mailer = m;
76557454Seric 	m->m_mno = i;
76610327Seric }
76710327Seric /*
76810327Seric **  MUNCHSTRING -- translate a string into internal form.
76910327Seric **
77010327Seric **	Parameters:
77110327Seric **		p -- the string to munch.
77258333Seric **		delimptr -- if non-NULL, set to the pointer of the
77358333Seric **			field delimiter character.
77410327Seric **
77510327Seric **	Returns:
77610327Seric **		the munched string.
77710327Seric */
7784096Seric 
77910327Seric char *
78058333Seric munchstring(p, delimptr)
78110327Seric 	register char *p;
78258333Seric 	char **delimptr;
78310327Seric {
78410327Seric 	register char *q;
78510327Seric 	bool backslash = FALSE;
78610327Seric 	bool quotemode = FALSE;
78710327Seric 	static char buf[MAXLINE];
7884096Seric 
78910327Seric 	for (q = buf; *p != '\0'; p++)
7904096Seric 	{
79110327Seric 		if (backslash)
79210327Seric 		{
79310327Seric 			/* everything is roughly literal */
79410357Seric 			backslash = FALSE;
79510327Seric 			switch (*p)
79610327Seric 			{
79710327Seric 			  case 'r':		/* carriage return */
79810327Seric 				*q++ = '\r';
79910327Seric 				continue;
80010327Seric 
80110327Seric 			  case 'n':		/* newline */
80210327Seric 				*q++ = '\n';
80310327Seric 				continue;
80410327Seric 
80510327Seric 			  case 'f':		/* form feed */
80610327Seric 				*q++ = '\f';
80710327Seric 				continue;
80810327Seric 
80910327Seric 			  case 'b':		/* backspace */
81010327Seric 				*q++ = '\b';
81110327Seric 				continue;
81210327Seric 			}
81310327Seric 			*q++ = *p;
81410327Seric 		}
81510327Seric 		else
81610327Seric 		{
81710327Seric 			if (*p == '\\')
81810327Seric 				backslash = TRUE;
81910327Seric 			else if (*p == '"')
82010327Seric 				quotemode = !quotemode;
82110327Seric 			else if (quotemode || *p != ',')
82210327Seric 				*q++ = *p;
82310327Seric 			else
82410327Seric 				break;
82510327Seric 		}
8264096Seric 	}
8274096Seric 
82858333Seric 	if (delimptr != NULL)
82958333Seric 		*delimptr = p;
83010327Seric 	*q++ = '\0';
83110327Seric 	return (buf);
83210327Seric }
83310327Seric /*
83410327Seric **  MAKEARGV -- break up a string into words
83510327Seric **
83610327Seric **	Parameters:
83710327Seric **		p -- the string to break up.
83810327Seric **
83910327Seric **	Returns:
84010327Seric **		a char **argv (dynamically allocated)
84110327Seric **
84210327Seric **	Side Effects:
84310327Seric **		munges p.
84410327Seric */
8454096Seric 
84610327Seric char **
84710327Seric makeargv(p)
84810327Seric 	register char *p;
84910327Seric {
85010327Seric 	char *q;
85110327Seric 	int i;
85210327Seric 	char **avp;
85310327Seric 	char *argv[MAXPV + 1];
85410327Seric 
85510327Seric 	/* take apart the words */
85610327Seric 	i = 0;
85710327Seric 	while (*p != '\0' && i < MAXPV)
8584096Seric 	{
85910327Seric 		q = p;
86058050Seric 		while (*p != '\0' && !(isascii(*p) && isspace(*p)))
86110327Seric 			p++;
86258050Seric 		while (isascii(*p) && isspace(*p))
86310327Seric 			*p++ = '\0';
86410327Seric 		argv[i++] = newstr(q);
8654096Seric 	}
86610327Seric 	argv[i++] = NULL;
8674096Seric 
86810327Seric 	/* now make a copy of the argv */
86910327Seric 	avp = (char **) xalloc(sizeof *avp * i);
87016893Seric 	bcopy((char *) argv, (char *) avp, sizeof *avp * i);
87110327Seric 
87210327Seric 	return (avp);
8733308Seric }
8743308Seric /*
8753308Seric **  PRINTRULES -- print rewrite rules (for debugging)
8763308Seric **
8773308Seric **	Parameters:
8783308Seric **		none.
8793308Seric **
8803308Seric **	Returns:
8813308Seric **		none.
8823308Seric **
8833308Seric **	Side Effects:
8843308Seric **		prints rewrite rules.
8853308Seric */
8863308Seric 
8873308Seric printrules()
8883308Seric {
8893308Seric 	register struct rewrite *rwp;
8904072Seric 	register int ruleset;
8913308Seric 
8924072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
8933308Seric 	{
8944072Seric 		if (RewriteRules[ruleset] == NULL)
8954072Seric 			continue;
8968067Seric 		printf("\n----Rule Set %d:", ruleset);
8973308Seric 
8984072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
8993308Seric 		{
9008067Seric 			printf("\nLHS:");
9018067Seric 			printav(rwp->r_lhs);
9028067Seric 			printf("RHS:");
9038067Seric 			printav(rwp->r_rhs);
9043308Seric 		}
9053308Seric 	}
9063308Seric }
9074319Seric 
9084096Seric /*
9098256Seric **  SETOPTION -- set global processing option
9108256Seric **
9118256Seric **	Parameters:
9128256Seric **		opt -- option name.
9138256Seric **		val -- option value (as a text string).
91421755Seric **		safe -- set if this came from a configuration file.
91521755Seric **			Some options (if set from the command line) will
91621755Seric **			reset the user id to avoid security problems.
9178269Seric **		sticky -- if set, don't let other setoptions override
9188269Seric **			this value.
91958734Seric **		e -- the main envelope.
9208256Seric **
9218256Seric **	Returns:
9228256Seric **		none.
9238256Seric **
9248256Seric **	Side Effects:
9258256Seric **		Sets options as implied by the arguments.
9268256Seric */
9278256Seric 
92810687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
9298269Seric 
93057207Seric 
93157207Seric #ifdef NAMED_BIND
93257207Seric 
93357207Seric struct resolverflags
93457207Seric {
93557207Seric 	char	*rf_name;	/* name of the flag */
93657207Seric 	long	rf_bits;	/* bits to set/clear */
93757207Seric } ResolverFlags[] =
93857207Seric {
93957207Seric 	"debug",	RES_DEBUG,
94057207Seric 	"aaonly",	RES_AAONLY,
94157207Seric 	"usevc",	RES_USEVC,
94257207Seric 	"primary",	RES_PRIMARY,
94357207Seric 	"igntc",	RES_IGNTC,
94457207Seric 	"recurse",	RES_RECURSE,
94557207Seric 	"defnames",	RES_DEFNAMES,
94657207Seric 	"stayopen",	RES_STAYOPEN,
94757207Seric 	"dnsrch",	RES_DNSRCH,
94857207Seric 	NULL,		0
94957207Seric };
95057207Seric 
95157207Seric #endif
95257207Seric 
95358734Seric setoption(opt, val, safe, sticky, e)
9548256Seric 	char opt;
9558256Seric 	char *val;
95621755Seric 	bool safe;
9578269Seric 	bool sticky;
95858734Seric 	register ENVELOPE *e;
9598256Seric {
96057207Seric 	register char *p;
9618265Seric 	extern bool atobool();
96212633Seric 	extern time_t convtime();
96314879Seric 	extern int QueueLA;
96414879Seric 	extern int RefuseLA;
96517474Seric 	extern bool trusteduser();
96617474Seric 	extern char *username();
9678256Seric 
9688256Seric 	if (tTd(37, 1))
9699341Seric 		printf("setoption %c=%s", opt, val);
9708256Seric 
9718256Seric 	/*
9728269Seric 	**  See if this option is preset for us.
9738256Seric 	*/
9748256Seric 
97510687Seric 	if (bitnset(opt, StickyOpt))
9768269Seric 	{
9779341Seric 		if (tTd(37, 1))
9789341Seric 			printf(" (ignored)\n");
9798269Seric 		return;
9808269Seric 	}
9818269Seric 
98221755Seric 	/*
98321755Seric 	**  Check to see if this option can be specified by this user.
98421755Seric 	*/
98521755Seric 
98636238Skarels 	if (!safe && getuid() == 0)
98721755Seric 		safe = TRUE;
98858082Seric 	if (!safe && strchr("bdeEiLmoprsvC8", opt) == NULL)
98921755Seric 	{
99039111Srick 		if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
99121755Seric 		{
99236582Sbostic 			if (tTd(37, 1))
99336582Sbostic 				printf(" (unsafe)");
99436582Sbostic 			if (getuid() != geteuid())
99536582Sbostic 			{
99651210Seric 				if (tTd(37, 1))
99751210Seric 					printf("(Resetting uid)");
99836582Sbostic 				(void) setgid(getgid());
99936582Sbostic 				(void) setuid(getuid());
100036582Sbostic 			}
100121755Seric 		}
100221755Seric 	}
100351210Seric 	if (tTd(37, 1))
100417985Seric 		printf("\n");
10058269Seric 
10068256Seric 	switch (opt)
10078256Seric 	{
100852106Seric 	  case '8':		/* allow eight-bit input */
100952106Seric 		EightBit = atobool(val);
101052106Seric 		break;
101152106Seric 
10128256Seric 	  case 'A':		/* set default alias file */
10139381Seric 		if (val[0] == '\0')
10148269Seric 			AliasFile = "aliases";
10159381Seric 		else
10169381Seric 			AliasFile = newstr(val);
10178256Seric 		break;
10188256Seric 
101917474Seric 	  case 'a':		/* look N minutes for "@:@" in alias file */
102017474Seric 		if (val[0] == '\0')
102117474Seric 			SafeAlias = 5;
102217474Seric 		else
102317474Seric 			SafeAlias = atoi(val);
102417474Seric 		break;
102517474Seric 
102616843Seric 	  case 'B':		/* substitution for blank character */
102716843Seric 		SpaceSub = val[0];
102816843Seric 		if (SpaceSub == '\0')
102916843Seric 			SpaceSub = ' ';
103016843Seric 		break;
103116843Seric 
103258082Seric 	  case 'b':		/* minimum number of blocks free on queue fs */
103358082Seric 		MinBlocksFree = atol(val);
103458082Seric 		break;
103558082Seric 
10369284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
10379381Seric 		NoConnect = atobool(val);
10389284Seric 		break;
10399284Seric 
104051305Seric 	  case 'C':		/* checkpoint every N addresses */
104151305Seric 		CheckpointInterval = atoi(val);
104224944Seric 		break;
104324944Seric 
10449284Seric 	  case 'd':		/* delivery mode */
10459284Seric 		switch (*val)
10468269Seric 		{
10479284Seric 		  case '\0':
104858734Seric 			e->e_sendmode = SM_DELIVER;
10498269Seric 			break;
10508269Seric 
105110755Seric 		  case SM_QUEUE:	/* queue only */
105210755Seric #ifndef QUEUE
105310755Seric 			syserr("need QUEUE to set -odqueue");
105456795Seric #endif /* QUEUE */
105510755Seric 			/* fall through..... */
105610755Seric 
10579284Seric 		  case SM_DELIVER:	/* do everything */
10589284Seric 		  case SM_FORK:		/* fork after verification */
105958734Seric 			e->e_sendmode = *val;
10608269Seric 			break;
10618269Seric 
10628269Seric 		  default:
10639284Seric 			syserr("Unknown delivery mode %c", *val);
10648269Seric 			exit(EX_USAGE);
10658269Seric 		}
10668269Seric 		break;
10678269Seric 
10689146Seric 	  case 'D':		/* rebuild alias database as needed */
10699381Seric 		AutoRebuild = atobool(val);
10709146Seric 		break;
10719146Seric 
107255372Seric 	  case 'E':		/* error message header/header file */
107355379Seric 		if (*val != '\0')
107455379Seric 			ErrMsgFile = newstr(val);
107555372Seric 		break;
107655372Seric 
10778269Seric 	  case 'e':		/* set error processing mode */
10788269Seric 		switch (*val)
10798269Seric 		{
10809381Seric 		  case EM_QUIET:	/* be silent about it */
10819381Seric 		  case EM_MAIL:		/* mail back */
10829381Seric 		  case EM_BERKNET:	/* do berknet error processing */
10839381Seric 		  case EM_WRITE:	/* write back (or mail) */
10848269Seric 			HoldErrs = TRUE;
10859381Seric 			/* fall through... */
10868269Seric 
10879381Seric 		  case EM_PRINT:	/* print errors normally (default) */
108858734Seric 			e->e_errormode = *val;
10898269Seric 			break;
10908269Seric 		}
10918269Seric 		break;
10928269Seric 
10939049Seric 	  case 'F':		/* file mode */
109417975Seric 		FileMode = atooct(val) & 0777;
10959049Seric 		break;
10969049Seric 
10978269Seric 	  case 'f':		/* save Unix-style From lines on front */
10989381Seric 		SaveFrom = atobool(val);
10998269Seric 		break;
11008269Seric 
110153735Seric 	  case 'G':		/* match recipients against GECOS field */
110253735Seric 		MatchGecos = atobool(val);
110353735Seric 		break;
110453735Seric 
11058256Seric 	  case 'g':		/* default gid */
110617474Seric 		DefGid = atoi(val);
11078256Seric 		break;
11088256Seric 
11098256Seric 	  case 'H':		/* help file */
11109381Seric 		if (val[0] == '\0')
11118269Seric 			HelpFile = "sendmail.hf";
11129381Seric 		else
11139381Seric 			HelpFile = newstr(val);
11148256Seric 		break;
11158256Seric 
111651305Seric 	  case 'h':		/* maximum hop count */
111751305Seric 		MaxHopCount = atoi(val);
111851305Seric 		break;
111951305Seric 
112035651Seric 	  case 'I':		/* use internet domain name server */
112157207Seric #ifdef NAMED_BIND
112257207Seric 		UseNameServer = TRUE;
112357207Seric 		for (p = val; *p != 0; )
112457207Seric 		{
112557207Seric 			bool clearmode;
112657207Seric 			char *q;
112757207Seric 			struct resolverflags *rfp;
112857207Seric 
112957207Seric 			while (*p == ' ')
113057207Seric 				p++;
113157207Seric 			if (*p == '\0')
113257207Seric 				break;
113357207Seric 			clearmode = FALSE;
113457207Seric 			if (*p == '-')
113557207Seric 				clearmode = TRUE;
113657207Seric 			else if (*p != '+')
113757207Seric 				p--;
113857207Seric 			p++;
113957207Seric 			q = p;
114058050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
114157207Seric 				p++;
114257207Seric 			if (*p != '\0')
114357207Seric 				*p++ = '\0';
114457207Seric 			for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
114557207Seric 			{
114657207Seric 				if (strcasecmp(q, rfp->rf_name) == 0)
114757207Seric 					break;
114857207Seric 			}
114957207Seric 			if (clearmode)
115057207Seric 				_res.options &= ~rfp->rf_bits;
115157207Seric 			else
115257207Seric 				_res.options |= rfp->rf_bits;
115357207Seric 		}
115457207Seric 		if (tTd(8, 2))
115557207Seric 			printf("_res.options = %x\n", _res.options);
115657207Seric #else
115757207Seric 		usrerr("name server (I option) specified but BIND not compiled in");
115857207Seric #endif
115935651Seric 		break;
116035651Seric 
11618269Seric 	  case 'i':		/* ignore dot lines in message */
11629381Seric 		IgnrDot = atobool(val);
11638269Seric 		break;
11648269Seric 
116557136Seric 	  case 'J':		/* .forward search path */
116657136Seric 		ForwardPath = newstr(val);
116757136Seric 		break;
116857136Seric 
116954967Seric 	  case 'k':		/* connection cache size */
117054967Seric 		MaxMciCache = atoi(val);
117156215Seric 		if (MaxMciCache < 0)
117256215Seric 			MaxMciCache = 0;
117354967Seric 		break;
117454967Seric 
117554967Seric 	  case 'K':		/* connection cache timeout */
117658796Seric 		MciCacheTimeout = convtime(val, 'm');
117754967Seric 		break;
117854967Seric 
11798256Seric 	  case 'L':		/* log level */
11809381Seric 		LogLevel = atoi(val);
11818256Seric 		break;
11828256Seric 
11838269Seric 	  case 'M':		/* define macro */
11849381Seric 		define(val[0], newstr(&val[1]), CurEnv);
118516878Seric 		sticky = FALSE;
11868269Seric 		break;
11878269Seric 
11888269Seric 	  case 'm':		/* send to me too */
11899381Seric 		MeToo = atobool(val);
11908269Seric 		break;
11918269Seric 
119225820Seric 	  case 'n':		/* validate RHS in newaliases */
119325820Seric 		CheckAliases = atobool(val);
119425820Seric 		break;
119525820Seric 
119658851Seric 	  case 'O':		/* daemon options */
119758851Seric 		setdaemonoptions(val);
119858851Seric 		break;
119958851Seric 
12008269Seric 	  case 'o':		/* assume old style headers */
12019381Seric 		if (atobool(val))
12029341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
12039341Seric 		else
12049341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
12058269Seric 		break;
12068269Seric 
120758082Seric 	  case 'p':		/* select privacy level */
120858082Seric 		p = val;
120958082Seric 		for (;;)
121058082Seric 		{
121158082Seric 			register struct prival *pv;
121258082Seric 			extern struct prival PrivacyValues[];
121358082Seric 
121458082Seric 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
121558082Seric 				p++;
121658082Seric 			if (*p == '\0')
121758082Seric 				break;
121858082Seric 			val = p;
121958082Seric 			while (isascii(*p) && isalnum(*p))
122058082Seric 				p++;
122158082Seric 			if (*p != '\0')
122258082Seric 				*p++ = '\0';
122358082Seric 
122458082Seric 			for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
122558082Seric 			{
122658082Seric 				if (strcasecmp(val, pv->pv_name) == 0)
122758082Seric 					break;
122858082Seric 			}
1229*58886Seric 			if (pv->pv_name == NULL)
1230*58886Seric 				syserr("readcf: Op line: %s unrecognized", val);
123158082Seric 			PrivacyFlags |= pv->pv_flag;
123258082Seric 		}
123358082Seric 		break;
123458082Seric 
123524944Seric 	  case 'P':		/* postmaster copy address for returned mail */
123624944Seric 		PostMasterCopy = newstr(val);
123724944Seric 		break;
123824944Seric 
123924944Seric 	  case 'q':		/* slope of queue only function */
124024944Seric 		QueueFactor = atoi(val);
124124944Seric 		break;
124224944Seric 
12438256Seric 	  case 'Q':		/* queue directory */
12449381Seric 		if (val[0] == '\0')
12458269Seric 			QueueDir = "mqueue";
12469381Seric 		else
12479381Seric 			QueueDir = newstr(val);
124858789Seric 		if (RealUid != 0 && !safe)
124958789Seric 			auth_warning(e, "Processed from queue %s", QueueDir);
12508256Seric 		break;
12518256Seric 
125258148Seric 	  case 'R':		/* don't prune routes */
125358148Seric 		DontPruneRoutes = atobool(val);
125458148Seric 		break;
125558148Seric 
12568256Seric 	  case 'r':		/* read timeout */
125758112Seric 		settimeouts(val);
12588256Seric 		break;
12598256Seric 
12608256Seric 	  case 'S':		/* status file */
12619381Seric 		if (val[0] == '\0')
12628269Seric 			StatFile = "sendmail.st";
12639381Seric 		else
12649381Seric 			StatFile = newstr(val);
12658256Seric 		break;
12668256Seric 
12678265Seric 	  case 's':		/* be super safe, even if expensive */
12689381Seric 		SuperSafe = atobool(val);
12698256Seric 		break;
12708256Seric 
12718256Seric 	  case 'T':		/* queue timeout */
127258737Seric 		p = strchr(val, '/');
127358737Seric 		if (p != NULL)
127458737Seric 		{
127558737Seric 			*p++ = '\0';
127658796Seric 			TimeOuts.to_q_warning = convtime(p, 'd');
127758737Seric 		}
127858796Seric 		TimeOuts.to_q_return = convtime(val, 'h');
127954967Seric 		break;
12808256Seric 
12818265Seric 	  case 't':		/* time zone name */
128252106Seric 		TimeZoneSpec = newstr(val);
12838265Seric 		break;
12848265Seric 
128550556Seric 	  case 'U':		/* location of user database */
128651360Seric 		UdbSpec = newstr(val);
128750556Seric 		break;
128850556Seric 
12898256Seric 	  case 'u':		/* set default uid */
129017474Seric 		DefUid = atoi(val);
129140973Sbostic 		setdefuser();
12928256Seric 		break;
12938256Seric 
129458851Seric 	  case 'V':		/* fallback MX host */
129558851Seric 		FallBackMX = newstr(val);
129658851Seric 		break;
129758851Seric 
12988269Seric 	  case 'v':		/* run in verbose mode */
12999381Seric 		Verbose = atobool(val);
13008256Seric 		break;
13018256Seric 
130214879Seric 	  case 'x':		/* load avg at which to auto-queue msgs */
130314879Seric 		QueueLA = atoi(val);
130414879Seric 		break;
130514879Seric 
130614879Seric 	  case 'X':		/* load avg at which to auto-reject connections */
130714879Seric 		RefuseLA = atoi(val);
130814879Seric 		break;
130914879Seric 
131024981Seric 	  case 'y':		/* work recipient factor */
131124981Seric 		WkRecipFact = atoi(val);
131224981Seric 		break;
131324981Seric 
131424981Seric 	  case 'Y':		/* fork jobs during queue runs */
131524952Seric 		ForkQueueRuns = atobool(val);
131624952Seric 		break;
131724952Seric 
131824981Seric 	  case 'z':		/* work message class factor */
131924981Seric 		WkClassFact = atoi(val);
132024981Seric 		break;
132124981Seric 
132224981Seric 	  case 'Z':		/* work time factor */
132324981Seric 		WkTimeFact = atoi(val);
132424981Seric 		break;
132524981Seric 
13268256Seric 	  default:
13278256Seric 		break;
13288256Seric 	}
132916878Seric 	if (sticky)
133016878Seric 		setbitn(opt, StickyOpt);
13319188Seric 	return;
13328256Seric }
133310687Seric /*
133410687Seric **  SETCLASS -- set a word into a class
133510687Seric **
133610687Seric **	Parameters:
133710687Seric **		class -- the class to put the word in.
133810687Seric **		word -- the word to enter
133910687Seric **
134010687Seric **	Returns:
134110687Seric **		none.
134210687Seric **
134310687Seric **	Side Effects:
134410687Seric **		puts the word into the symbol table.
134510687Seric */
134610687Seric 
134710687Seric setclass(class, word)
134810687Seric 	int class;
134910687Seric 	char *word;
135010687Seric {
135110687Seric 	register STAB *s;
135210687Seric 
135357943Seric 	if (tTd(37, 8))
135457943Seric 		printf("%s added to class %c\n", word, class);
135510687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
135610687Seric 	setbitn(class, s->s_class);
135710687Seric }
135853654Seric /*
135953654Seric **  MAKEMAPENTRY -- create a map entry
136053654Seric **
136153654Seric **	Parameters:
136253654Seric **		line -- the config file line
136353654Seric **
136453654Seric **	Returns:
136553654Seric **		TRUE if it successfully entered the map entry.
136653654Seric **		FALSE otherwise (usually syntax error).
136753654Seric **
136853654Seric **	Side Effects:
136953654Seric **		Enters the map into the dictionary.
137053654Seric */
137153654Seric 
137253654Seric void
137353654Seric makemapentry(line)
137453654Seric 	char *line;
137553654Seric {
137653654Seric 	register char *p;
137753654Seric 	char *mapname;
137853654Seric 	char *classname;
137953654Seric 	register STAB *map;
138053654Seric 	STAB *class;
138153654Seric 
138258050Seric 	for (p = line; isascii(*p) && isspace(*p); p++)
138353654Seric 		continue;
138458050Seric 	if (!(isascii(*p) && isalnum(*p)))
138553654Seric 	{
138653654Seric 		syserr("readcf: config K line: no map name");
138753654Seric 		return;
138853654Seric 	}
138953654Seric 
139053654Seric 	mapname = p;
139158050Seric 	while (isascii(*++p) && isalnum(*p))
139253654Seric 		continue;
139353654Seric 	if (*p != '\0')
139453654Seric 		*p++ = '\0';
139558050Seric 	while (isascii(*p) && isspace(*p))
139653654Seric 		p++;
139758050Seric 	if (!(isascii(*p) && isalnum(*p)))
139853654Seric 	{
139953654Seric 		syserr("readcf: config K line, map %s: no map class", mapname);
140053654Seric 		return;
140153654Seric 	}
140253654Seric 	classname = p;
140358050Seric 	while (isascii(*++p) && isalnum(*p))
140453654Seric 		continue;
140553654Seric 	if (*p != '\0')
140653654Seric 		*p++ = '\0';
140758050Seric 	while (isascii(*p) && isspace(*p))
140853654Seric 		p++;
140953654Seric 
141053654Seric 	/* look up the class */
141153654Seric 	class = stab(classname, ST_MAPCLASS, ST_FIND);
141253654Seric 	if (class == NULL)
141353654Seric 	{
141453654Seric 		syserr("readcf: map %s: class %s not available", mapname, classname);
141553654Seric 		return;
141653654Seric 	}
141753654Seric 
141853654Seric 	/* enter the map */
141953654Seric 	map = stab(mapname, ST_MAP, ST_ENTER);
142053654Seric 	map->s_map.map_class = &class->s_mapclass;
142153654Seric 
142256823Seric 	if ((*class->s_mapclass.map_init)(&map->s_map, mapname, p))
142353654Seric 		map->s_map.map_flags |= MF_VALID;
142453654Seric }
142558112Seric /*
142658112Seric **  SETTIMEOUTS -- parse and set timeout values
142758112Seric **
142858112Seric **	Parameters:
142958112Seric **		val -- a pointer to the values.  If NULL, do initial
143058112Seric **			settings.
143158112Seric **
143258112Seric **	Returns:
143358112Seric **		none.
143458112Seric **
143558112Seric **	Side Effects:
143658112Seric **		Initializes the TimeOuts structure
143758112Seric */
143858112Seric 
143958112Seric #define MINUTES	* 60
144058112Seric #define HOUR	* 3600
144158112Seric 
144258112Seric settimeouts(val)
144358112Seric 	register char *val;
144458112Seric {
144558112Seric 	register char *p;
144658671Seric 	extern time_t convtime();
144758112Seric 
144858112Seric 	if (val == NULL)
144958112Seric 	{
145058112Seric 		TimeOuts.to_initial = (time_t) 5 MINUTES;
145158112Seric 		TimeOuts.to_helo = (time_t) 5 MINUTES;
145258112Seric 		TimeOuts.to_mail = (time_t) 10 MINUTES;
145358112Seric 		TimeOuts.to_rcpt = (time_t) 1 HOUR;
145458112Seric 		TimeOuts.to_datainit = (time_t) 5 MINUTES;
145558112Seric 		TimeOuts.to_datablock = (time_t) 1 HOUR;
145658112Seric 		TimeOuts.to_datafinal = (time_t) 1 HOUR;
145758112Seric 		TimeOuts.to_rset = (time_t) 5 MINUTES;
145858112Seric 		TimeOuts.to_quit = (time_t) 2 MINUTES;
145958112Seric 		TimeOuts.to_nextcommand = (time_t) 1 HOUR;
146058112Seric 		TimeOuts.to_miscshort = (time_t) 2 MINUTES;
146158112Seric 		return;
146258112Seric 	}
146358112Seric 
146458112Seric 	for (;; val = p)
146558112Seric 	{
146658112Seric 		while (isascii(*val) && isspace(*val))
146758112Seric 			val++;
146858112Seric 		if (*val == '\0')
146958112Seric 			break;
147058112Seric 		for (p = val; *p != '\0' && *p != ','; p++)
147158112Seric 			continue;
147258112Seric 		if (*p != '\0')
147358112Seric 			*p++ = '\0';
147458112Seric 
147558112Seric 		if (isascii(*val) && isdigit(*val))
147658112Seric 		{
147758112Seric 			/* old syntax -- set everything */
147858796Seric 			TimeOuts.to_mail = convtime(val, 'm');
147958112Seric 			TimeOuts.to_rcpt = TimeOuts.to_mail;
148058112Seric 			TimeOuts.to_datainit = TimeOuts.to_mail;
148158112Seric 			TimeOuts.to_datablock = TimeOuts.to_mail;
148258112Seric 			TimeOuts.to_datafinal = TimeOuts.to_mail;
148358112Seric 			TimeOuts.to_nextcommand = TimeOuts.to_mail;
148458112Seric 			continue;
148558112Seric 		}
148658112Seric 		else
148758112Seric 		{
148858112Seric 			register char *q = strchr(val, '=');
148958112Seric 			time_t to;
149058112Seric 
149158112Seric 			if (q == NULL)
149258112Seric 			{
149358112Seric 				/* syntax error */
149458112Seric 				continue;
149558112Seric 			}
149658112Seric 			*q++ = '\0';
149758796Seric 			to = convtime(q, 'm');
149858112Seric 
149958112Seric 			if (strcasecmp(val, "initial") == 0)
150058112Seric 				TimeOuts.to_initial = to;
150158112Seric 			else if (strcasecmp(val, "mail") == 0)
150258112Seric 				TimeOuts.to_mail = to;
150358112Seric 			else if (strcasecmp(val, "rcpt") == 0)
150458112Seric 				TimeOuts.to_rcpt = to;
150558112Seric 			else if (strcasecmp(val, "datainit") == 0)
150658112Seric 				TimeOuts.to_datainit = to;
150758112Seric 			else if (strcasecmp(val, "datablock") == 0)
150858112Seric 				TimeOuts.to_datablock = to;
150958112Seric 			else if (strcasecmp(val, "datafinal") == 0)
151058112Seric 				TimeOuts.to_datafinal = to;
151158112Seric 			else if (strcasecmp(val, "command") == 0)
151258112Seric 				TimeOuts.to_nextcommand = to;
151358112Seric 			else if (strcasecmp(val, "rset") == 0)
151458112Seric 				TimeOuts.to_rset = to;
151558112Seric 			else if (strcasecmp(val, "helo") == 0)
151658112Seric 				TimeOuts.to_helo = to;
151758112Seric 			else if (strcasecmp(val, "quit") == 0)
151858112Seric 				TimeOuts.to_quit = to;
151958112Seric 			else if (strcasecmp(val, "misc") == 0)
152058112Seric 				TimeOuts.to_miscshort = to;
152158112Seric 			else
152258112Seric 				syserr("settimeouts: invalid timeout %s", val);
152358112Seric 		}
152458112Seric 	}
152558112Seric }
1526