xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 59283)
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*59283Seric static char sccsid[] = "@(#)readcf.c	6.29 (Berkeley) 04/26/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 
13259254Seric #ifdef XLA
13359254Seric 	xla_zero();
13459254Seric #endif
13559254Seric 
13657135Seric 	while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL)
1373308Seric 	{
13857135Seric 		if (bp[0] == '#')
13957135Seric 		{
14057135Seric 			if (bp != buf)
14157135Seric 				free(bp);
14252637Seric 			continue;
14357135Seric 		}
14452637Seric 
14558050Seric 		/* map $ into \201 for macro expansion */
14657135Seric 		for (p = bp; *p != '\0'; p++)
14716157Seric 		{
14857135Seric 			if (*p == '#' && p > bp && ConfigLevel >= 3)
14952647Seric 			{
15052647Seric 				/* this is an on-line comment */
15152647Seric 				register char *e;
15252647Seric 
15358050Seric 				switch (*--p & 0377)
15452647Seric 				{
15558050Seric 				  case MACROEXPAND:
15652647Seric 					/* it's from $# -- let it go through */
15752647Seric 					p++;
15852647Seric 					break;
15952647Seric 
16052647Seric 				  case '\\':
16152647Seric 					/* it's backslash escaped */
16252647Seric 					(void) strcpy(p, p + 1);
16352647Seric 					break;
16452647Seric 
16552647Seric 				  default:
16652647Seric 					/* delete preceeding white space */
16758050Seric 					while (isascii(*p) && isspace(*p) && p > bp)
16852647Seric 						p--;
16956795Seric 					if ((e = strchr(++p, '\n')) != NULL)
17052647Seric 						(void) strcpy(p, e);
17152647Seric 					else
17252647Seric 						p[0] = p[1] = '\0';
17352647Seric 					break;
17452647Seric 				}
17552647Seric 				continue;
17652647Seric 			}
17752647Seric 
17816157Seric 			if (*p != '$')
17916157Seric 				continue;
18016157Seric 
18116157Seric 			if (p[1] == '$')
18216157Seric 			{
18316157Seric 				/* actual dollar sign.... */
18423111Seric 				(void) strcpy(p, p + 1);
18516157Seric 				continue;
18616157Seric 			}
18716157Seric 
18816157Seric 			/* convert to macro expansion character */
18958050Seric 			*p = MACROEXPAND;
19016157Seric 		}
19116157Seric 
19216157Seric 		/* interpret this line */
19357135Seric 		switch (bp[0])
1943308Seric 		{
1953308Seric 		  case '\0':
1963308Seric 		  case '#':		/* comment */
1973308Seric 			break;
1983308Seric 
1993308Seric 		  case 'R':		/* rewriting rule */
20057135Seric 			for (p = &bp[1]; *p != '\0' && *p != '\t'; p++)
2013308Seric 				continue;
2023308Seric 
2033308Seric 			if (*p == '\0')
2045909Seric 			{
20557135Seric 				syserr("invalid rewrite line \"%s\"", bp);
2065909Seric 				break;
2075909Seric 			}
2085909Seric 
2095909Seric 			/* allocate space for the rule header */
2105909Seric 			if (rwp == NULL)
2115909Seric 			{
2125909Seric 				RewriteRules[ruleset] = rwp =
2135909Seric 					(struct rewrite *) xalloc(sizeof *rwp);
2145909Seric 			}
2153308Seric 			else
2163308Seric 			{
2175909Seric 				rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
2185909Seric 				rwp = rwp->r_next;
2195909Seric 			}
2205909Seric 			rwp->r_next = NULL;
2213308Seric 
2225909Seric 			/* expand and save the LHS */
2235909Seric 			*p = '\0';
22457135Seric 			expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e);
22558333Seric 			rwp->r_lhs = prescan(exbuf, '\t', pvpbuf, NULL);
22657589Seric 			nfuzzy = 0;
2275909Seric 			if (rwp->r_lhs != NULL)
22857589Seric 			{
22957589Seric 				register char **ap;
23057589Seric 
2315909Seric 				rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
23257589Seric 
23357589Seric 				/* count the number of fuzzy matches in LHS */
23457589Seric 				for (ap = rwp->r_lhs; *ap != NULL; ap++)
23557589Seric 				{
23658148Seric 					char *botch;
23758148Seric 
23858148Seric 					botch = NULL;
23958050Seric 					switch (**ap & 0377)
24057589Seric 					{
24157589Seric 					  case MATCHZANY:
24257589Seric 					  case MATCHANY:
24357589Seric 					  case MATCHONE:
24457589Seric 					  case MATCHCLASS:
24557589Seric 					  case MATCHNCLASS:
24657589Seric 						nfuzzy++;
24758148Seric 						break;
24858148Seric 
24958148Seric 					  case MATCHREPL:
25058148Seric 						botch = "$0-$9";
25158148Seric 						break;
25258148Seric 
25358148Seric 					  case CANONNET:
25458148Seric 						botch = "$#";
25558148Seric 						break;
25658148Seric 
25758148Seric 					  case CANONUSER:
25858148Seric 						botch = "$:";
25958148Seric 						break;
26058148Seric 
26158148Seric 					  case CALLSUBR:
26258148Seric 						botch = "$>";
26358148Seric 						break;
26458148Seric 
26558148Seric 					  case CONDIF:
26658148Seric 						botch = "$?";
26758148Seric 						break;
26858148Seric 
26958148Seric 					  case CONDELSE:
27058148Seric 						botch = "$|";
27158148Seric 						break;
27258148Seric 
27358148Seric 					  case CONDFI:
27458148Seric 						botch = "$.";
27558148Seric 						break;
27658148Seric 
27758148Seric 					  case HOSTBEGIN:
27858148Seric 						botch = "$[";
27958148Seric 						break;
28058148Seric 
28158148Seric 					  case HOSTEND:
28258148Seric 						botch = "$]";
28358148Seric 						break;
28458148Seric 
28558148Seric 					  case LOOKUPBEGIN:
28658148Seric 						botch = "$(";
28758148Seric 						break;
28858148Seric 
28958148Seric 					  case LOOKUPEND:
29058148Seric 						botch = "$)";
29158148Seric 						break;
29257589Seric 					}
29358148Seric 					if (botch != NULL)
29458148Seric 						syserr("Inappropriate use of %s on LHS",
29558148Seric 							botch);
29657589Seric 				}
29757589Seric 			}
29856678Seric 			else
29956678Seric 				syserr("R line: null LHS");
3005909Seric 
3015909Seric 			/* expand and save the RHS */
3025909Seric 			while (*++p == '\t')
3035909Seric 				continue;
3047231Seric 			q = p;
3057231Seric 			while (*p != '\0' && *p != '\t')
3067231Seric 				p++;
3077231Seric 			*p = '\0';
30855012Seric 			expand(q, exbuf, &exbuf[sizeof exbuf], e);
30958333Seric 			rwp->r_rhs = prescan(exbuf, '\t', pvpbuf, NULL);
3105909Seric 			if (rwp->r_rhs != NULL)
31157589Seric 			{
31257589Seric 				register char **ap;
31357589Seric 
3145909Seric 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
31557589Seric 
31657589Seric 				/* check no out-of-bounds replacements */
31757589Seric 				nfuzzy += '0';
31857589Seric 				for (ap = rwp->r_rhs; *ap != NULL; ap++)
31957589Seric 				{
32058148Seric 					char *botch;
32158148Seric 
32258148Seric 					botch = NULL;
32358148Seric 					switch (**ap & 0377)
32457589Seric 					{
32558148Seric 					  case MATCHREPL:
32658148Seric 						if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy)
32758148Seric 						{
32858148Seric 							syserr("replacement $%c out of bounds",
32958148Seric 								(*ap)[1]);
33058148Seric 						}
33158148Seric 						break;
33258148Seric 
33358148Seric 					  case MATCHZANY:
33458148Seric 						botch = "$*";
33558148Seric 						break;
33658148Seric 
33758148Seric 					  case MATCHANY:
33858148Seric 						botch = "$+";
33958148Seric 						break;
34058148Seric 
34158148Seric 					  case MATCHONE:
34258148Seric 						botch = "$-";
34358148Seric 						break;
34458148Seric 
34558148Seric 					  case MATCHCLASS:
34658148Seric 						botch = "$=";
34758148Seric 						break;
34858148Seric 
34958148Seric 					  case MATCHNCLASS:
35058148Seric 						botch = "$~";
35158148Seric 						break;
35257589Seric 					}
35358148Seric 					if (botch != NULL)
35458148Seric 						syserr("Inappropriate use of %s on RHS",
35558148Seric 							botch);
35657589Seric 				}
35757589Seric 			}
35856678Seric 			else
35956678Seric 				syserr("R line: null RHS");
3603308Seric 			break;
3613308Seric 
3624072Seric 		  case 'S':		/* select rewriting set */
36357135Seric 			ruleset = atoi(&bp[1]);
3648056Seric 			if (ruleset >= MAXRWSETS || ruleset < 0)
3658056Seric 			{
3669381Seric 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
3678056Seric 				ruleset = 0;
3688056Seric 			}
3694072Seric 			rwp = NULL;
3704072Seric 			break;
3714072Seric 
3723308Seric 		  case 'D':		/* macro definition */
37358333Seric 			define(bp[1], newstr(munchstring(&bp[2], NULL)), e);
3743308Seric 			break;
3753308Seric 
3763387Seric 		  case 'H':		/* required header line */
37757135Seric 			(void) chompheader(&bp[1], TRUE, e);
3783387Seric 			break;
3793387Seric 
3804061Seric 		  case 'C':		/* word class */
3814432Seric 			/* scan the list of words and set class for all */
38257135Seric 			for (p = &bp[2]; *p != '\0'; )
3834061Seric 			{
3844061Seric 				register char *wd;
3854061Seric 				char delim;
3864061Seric 
38758050Seric 				while (*p != '\0' && isascii(*p) && isspace(*p))
3884061Seric 					p++;
3894061Seric 				wd = p;
39058050Seric 				while (*p != '\0' && !(isascii(*p) && isspace(*p)))
3914061Seric 					p++;
3924061Seric 				delim = *p;
3934061Seric 				*p = '\0';
3944061Seric 				if (wd[0] != '\0')
39558148Seric 				{
39658148Seric 					if (tTd(37, 2))
39758148Seric 						printf("setclass(%c, %s)\n",
39858148Seric 							bp[1], wd);
39957135Seric 					setclass(bp[1], wd);
40058148Seric 				}
4014061Seric 				*p = delim;
4024061Seric 			}
4034061Seric 			break;
4044061Seric 
40559272Seric 		  case 'F':		/* word class from file */
40659272Seric 			/* read list of words from argument or file */
40759272Seric 			/* read from file */
40859272Seric 			for (p = &bp[2];
40959272Seric 			     *p != '\0' && !(isascii(*p) && isspace(*p));
41059272Seric 			     p++)
41159272Seric 				continue;
41259272Seric 			if (*p == '\0')
41359272Seric 				p = "%s";
41459272Seric 			else
41559272Seric 			{
41659272Seric 				*p = '\0';
41759272Seric 				while (isascii(*++p) && isspace(*p))
41859272Seric 					continue;
41959272Seric 			}
42059272Seric 			fileclass(bp[1], &bp[2], p, safe);
42159272Seric 			break;
42259272Seric 
42359156Seric #ifdef XLA
42459156Seric 		  case 'L':		/* extended load average description */
42559156Seric 			xla_init(&bp[1]);
42659156Seric 			break;
42759156Seric #endif
42859156Seric 
4294096Seric 		  case 'M':		/* define mailer */
43057135Seric 			makemailer(&bp[1]);
4314096Seric 			break;
4324096Seric 
4338252Seric 		  case 'O':		/* set option */
43458734Seric 			setoption(bp[1], &bp[2], safe, FALSE, e);
4358252Seric 			break;
4368252Seric 
4378252Seric 		  case 'P':		/* set precedence */
4388252Seric 			if (NumPriorities >= MAXPRIORITIES)
4398252Seric 			{
4408547Seric 				toomany('P', MAXPRIORITIES);
4418252Seric 				break;
4428252Seric 			}
44357135Seric 			for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
4448252Seric 				continue;
4458252Seric 			if (*p == '\0')
4468252Seric 				goto badline;
4478252Seric 			*p = '\0';
44857135Seric 			Priorities[NumPriorities].pri_name = newstr(&bp[1]);
4498252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
4508252Seric 			NumPriorities++;
4518252Seric 			break;
4528252Seric 
4538547Seric 		  case 'T':		/* trusted user(s) */
45458161Seric 			/* this option is obsolete, but will be ignored */
4558547Seric 			break;
4568547Seric 
45752645Seric 		  case 'V':		/* configuration syntax version */
45857135Seric 			ConfigLevel = atoi(&bp[1]);
45952645Seric 			break;
46052645Seric 
46153654Seric 		  case 'K':
46257135Seric 			makemapentry(&bp[1]);
46353654Seric 			break;
46453654Seric 
4653308Seric 		  default:
4664061Seric 		  badline:
46757135Seric 			syserr("unknown control line \"%s\"", bp);
4683308Seric 		}
46957135Seric 		if (bp != buf)
47057135Seric 			free(bp);
4713308Seric 	}
47252637Seric 	if (ferror(cf))
47352637Seric 	{
47452647Seric 		syserr("I/O read error", cfname);
47552637Seric 		exit(EX_OSFILE);
47652637Seric 	}
47752637Seric 	fclose(cf);
4789381Seric 	FileName = NULL;
47956836Seric 
48057076Seric 	if (stab("host", ST_MAP, ST_FIND) == NULL)
48157076Seric 	{
48257076Seric 		/* user didn't initialize: set up host map */
48357076Seric 		strcpy(buf, "host host");
48457076Seric 		if (ConfigLevel >= 2)
48557076Seric 			strcat(buf, " -a.");
48657076Seric 		makemapentry(buf);
48757076Seric 	}
4884096Seric }
4894096Seric /*
4908547Seric **  TOOMANY -- signal too many of some option
4918547Seric **
4928547Seric **	Parameters:
4938547Seric **		id -- the id of the error line
4948547Seric **		maxcnt -- the maximum possible values
4958547Seric **
4968547Seric **	Returns:
4978547Seric **		none.
4988547Seric **
4998547Seric **	Side Effects:
5008547Seric **		gives a syserr.
5018547Seric */
5028547Seric 
5038547Seric toomany(id, maxcnt)
5048547Seric 	char id;
5058547Seric 	int maxcnt;
5068547Seric {
5079381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
5088547Seric }
5098547Seric /*
5104432Seric **  FILECLASS -- read members of a class from a file
5114432Seric **
5124432Seric **	Parameters:
5134432Seric **		class -- class to define.
5144432Seric **		filename -- name of file to read.
5154432Seric **		fmt -- scanf string to use for match.
5164432Seric **
5174432Seric **	Returns:
5184432Seric **		none
5194432Seric **
5204432Seric **	Side Effects:
5214432Seric **
5224432Seric **		puts all lines in filename that match a scanf into
5234432Seric **			the named class.
5244432Seric */
5254432Seric 
52654973Seric fileclass(class, filename, fmt, safe)
5274432Seric 	int class;
5284432Seric 	char *filename;
5294432Seric 	char *fmt;
53054973Seric 	bool safe;
5314432Seric {
53225808Seric 	FILE *f;
53354973Seric 	struct stat stbuf;
5344432Seric 	char buf[MAXLINE];
5354432Seric 
53654973Seric 	if (stat(filename, &stbuf) < 0)
53754973Seric 	{
53854973Seric 		syserr("fileclass: cannot stat %s", filename);
53954973Seric 		return;
54054973Seric 	}
54154973Seric 	if (!S_ISREG(stbuf.st_mode))
54254973Seric 	{
54354973Seric 		syserr("fileclass: %s not a regular file", filename);
54454973Seric 		return;
54554973Seric 	}
54654973Seric 	if (!safe && access(filename, R_OK) < 0)
54754973Seric 	{
54854973Seric 		syserr("fileclass: access denied on %s", filename);
54954973Seric 		return;
55054973Seric 	}
55154973Seric 	f = fopen(filename, "r");
5524432Seric 	if (f == NULL)
5534432Seric 	{
55454973Seric 		syserr("fileclass: cannot open %s", filename);
5554432Seric 		return;
5564432Seric 	}
5574432Seric 
5584432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
5594432Seric 	{
5604432Seric 		register STAB *s;
56125808Seric 		register char *p;
56225808Seric # ifdef SCANF
5634432Seric 		char wordbuf[MAXNAME+1];
5644432Seric 
5654432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
5664432Seric 			continue;
56725808Seric 		p = wordbuf;
56856795Seric # else /* SCANF */
56925808Seric 		p = buf;
57056795Seric # endif /* SCANF */
57125808Seric 
57225808Seric 		/*
57325808Seric 		**  Break up the match into words.
57425808Seric 		*/
57525808Seric 
57625808Seric 		while (*p != '\0')
57725808Seric 		{
57825808Seric 			register char *q;
57925808Seric 
58025808Seric 			/* strip leading spaces */
58158050Seric 			while (isascii(*p) && isspace(*p))
58225808Seric 				p++;
58325808Seric 			if (*p == '\0')
58425808Seric 				break;
58525808Seric 
58625808Seric 			/* find the end of the word */
58725808Seric 			q = p;
58858050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
58925808Seric 				p++;
59025808Seric 			if (*p != '\0')
59125808Seric 				*p++ = '\0';
59225808Seric 
59325808Seric 			/* enter the word in the symbol table */
59425808Seric 			s = stab(q, ST_CLASS, ST_ENTER);
59525808Seric 			setbitn(class, s->s_class);
59625808Seric 		}
5974432Seric 	}
5984432Seric 
59954973Seric 	(void) fclose(f);
6004432Seric }
6014432Seric /*
6024096Seric **  MAKEMAILER -- define a new mailer.
6034096Seric **
6044096Seric **	Parameters:
60510327Seric **		line -- description of mailer.  This is in labeled
60610327Seric **			fields.  The fields are:
60710327Seric **			   P -- the path to the mailer
60810327Seric **			   F -- the flags associated with the mailer
60910327Seric **			   A -- the argv for this mailer
61010327Seric **			   S -- the sender rewriting set
61110327Seric **			   R -- the recipient rewriting set
61210327Seric **			   E -- the eol string
61310327Seric **			The first word is the canonical name of the mailer.
6144096Seric **
6154096Seric **	Returns:
6164096Seric **		none.
6174096Seric **
6184096Seric **	Side Effects:
6194096Seric **		enters the mailer into the mailer table.
6204096Seric */
6213308Seric 
62221066Seric makemailer(line)
6234096Seric 	char *line;
6244096Seric {
6254096Seric 	register char *p;
6268067Seric 	register struct mailer *m;
6278067Seric 	register STAB *s;
6288067Seric 	int i;
62910327Seric 	char fcode;
63058020Seric 	auto char *endp;
6314096Seric 	extern int NextMailer;
63210327Seric 	extern char **makeargv();
63310327Seric 	extern char *munchstring();
63410701Seric 	extern long atol();
6354096Seric 
63610327Seric 	/* allocate a mailer and set up defaults */
63710327Seric 	m = (struct mailer *) xalloc(sizeof *m);
63810327Seric 	bzero((char *) m, sizeof *m);
63910327Seric 	m->m_eol = "\n";
64010327Seric 
64110327Seric 	/* collect the mailer name */
64258050Seric 	for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++)
64310327Seric 		continue;
64410327Seric 	if (*p != '\0')
64510327Seric 		*p++ = '\0';
64610327Seric 	m->m_name = newstr(line);
64710327Seric 
64810327Seric 	/* now scan through and assign info from the fields */
64910327Seric 	while (*p != '\0')
65010327Seric 	{
65158333Seric 		auto char *delimptr;
65258333Seric 
65358050Seric 		while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p))))
65410327Seric 			p++;
65510327Seric 
65610327Seric 		/* p now points to field code */
65710327Seric 		fcode = *p;
65810327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
65910327Seric 			p++;
66010327Seric 		if (*p++ != '=')
66110327Seric 		{
66252637Seric 			syserr("mailer %s: `=' expected", m->m_name);
66310327Seric 			return;
66410327Seric 		}
66558050Seric 		while (isascii(*p) && isspace(*p))
66610327Seric 			p++;
66710327Seric 
66810327Seric 		/* p now points to the field body */
66958333Seric 		p = munchstring(p, &delimptr);
67010327Seric 
67110327Seric 		/* install the field into the mailer struct */
67210327Seric 		switch (fcode)
67310327Seric 		{
67410327Seric 		  case 'P':		/* pathname */
67510327Seric 			m->m_mailer = newstr(p);
67610327Seric 			break;
67710327Seric 
67810327Seric 		  case 'F':		/* flags */
67910687Seric 			for (; *p != '\0'; p++)
68058050Seric 				if (!(isascii(*p) && isspace(*p)))
68152637Seric 					setbitn(*p, m->m_flags);
68210327Seric 			break;
68310327Seric 
68410327Seric 		  case 'S':		/* sender rewriting ruleset */
68510327Seric 		  case 'R':		/* recipient rewriting ruleset */
68658020Seric 			i = strtol(p, &endp, 10);
68710327Seric 			if (i < 0 || i >= MAXRWSETS)
68810327Seric 			{
68910327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
69010327Seric 				return;
69110327Seric 			}
69210327Seric 			if (fcode == 'S')
69358020Seric 				m->m_sh_rwset = m->m_se_rwset = i;
69410327Seric 			else
69558020Seric 				m->m_rh_rwset = m->m_re_rwset = i;
69658020Seric 
69758020Seric 			p = endp;
69858020Seric 			if (*p == '/')
69958020Seric 			{
70058020Seric 				i = strtol(p, NULL, 10);
70158020Seric 				if (i < 0 || i >= MAXRWSETS)
70258020Seric 				{
70358020Seric 					syserr("invalid rewrite set, %d max",
70458020Seric 						MAXRWSETS);
70558020Seric 					return;
70658020Seric 				}
70758020Seric 				if (fcode == 'S')
70858020Seric 					m->m_sh_rwset = i;
70958020Seric 				else
71058020Seric 					m->m_rh_rwset = i;
71158020Seric 			}
71210327Seric 			break;
71310327Seric 
71410327Seric 		  case 'E':		/* end of line string */
71510327Seric 			m->m_eol = newstr(p);
71610327Seric 			break;
71710327Seric 
71810327Seric 		  case 'A':		/* argument vector */
71910327Seric 			m->m_argv = makeargv(p);
72010327Seric 			break;
72110701Seric 
72210701Seric 		  case 'M':		/* maximum message size */
72310701Seric 			m->m_maxsize = atol(p);
72410701Seric 			break;
72552106Seric 
72652106Seric 		  case 'L':		/* maximum line length */
72752106Seric 			m->m_linelimit = atoi(p);
72852106Seric 			break;
72958935Seric 
73058935Seric 		  case 'D':		/* working directory */
73158935Seric 			m->m_execdir = newstr(p);
73258935Seric 			break;
73310327Seric 		}
73410327Seric 
73558333Seric 		p = delimptr;
73610327Seric 	}
73710327Seric 
73852106Seric 	/* do some heuristic cleanup for back compatibility */
73952106Seric 	if (bitnset(M_LIMITS, m->m_flags))
74052106Seric 	{
74152106Seric 		if (m->m_linelimit == 0)
74252106Seric 			m->m_linelimit = SMTPLINELIM;
74355418Seric 		if (ConfigLevel < 2)
74452106Seric 			setbitn(M_7BITS, m->m_flags);
74552106Seric 	}
74652106Seric 
74758321Seric 	/* do some rationality checking */
74858321Seric 	if (m->m_argv == NULL)
74958321Seric 	{
75058321Seric 		syserr("M%s: A= argument required", m->m_name);
75158321Seric 		return;
75258321Seric 	}
75358321Seric 	if (m->m_mailer == NULL)
75458321Seric 	{
75558321Seric 		syserr("M%s: P= argument required", m->m_name);
75658321Seric 		return;
75758321Seric 	}
75858321Seric 
7594096Seric 	if (NextMailer >= MAXMAILERS)
7604096Seric 	{
7619381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
7624096Seric 		return;
7634096Seric 	}
76457402Seric 
76510327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
76657402Seric 	if (s->s_mailer != NULL)
76757402Seric 	{
76857402Seric 		i = s->s_mailer->m_mno;
76957402Seric 		free(s->s_mailer);
77057402Seric 	}
77157402Seric 	else
77257402Seric 	{
77357402Seric 		i = NextMailer++;
77457402Seric 	}
77557402Seric 	Mailer[i] = s->s_mailer = m;
77657454Seric 	m->m_mno = i;
77710327Seric }
77810327Seric /*
77910327Seric **  MUNCHSTRING -- translate a string into internal form.
78010327Seric **
78110327Seric **	Parameters:
78210327Seric **		p -- the string to munch.
78358333Seric **		delimptr -- if non-NULL, set to the pointer of the
78458333Seric **			field delimiter character.
78510327Seric **
78610327Seric **	Returns:
78710327Seric **		the munched string.
78810327Seric */
7894096Seric 
79010327Seric char *
79158333Seric munchstring(p, delimptr)
79210327Seric 	register char *p;
79358333Seric 	char **delimptr;
79410327Seric {
79510327Seric 	register char *q;
79610327Seric 	bool backslash = FALSE;
79710327Seric 	bool quotemode = FALSE;
79810327Seric 	static char buf[MAXLINE];
7994096Seric 
80010327Seric 	for (q = buf; *p != '\0'; p++)
8014096Seric 	{
80210327Seric 		if (backslash)
80310327Seric 		{
80410327Seric 			/* everything is roughly literal */
80510357Seric 			backslash = FALSE;
80610327Seric 			switch (*p)
80710327Seric 			{
80810327Seric 			  case 'r':		/* carriage return */
80910327Seric 				*q++ = '\r';
81010327Seric 				continue;
81110327Seric 
81210327Seric 			  case 'n':		/* newline */
81310327Seric 				*q++ = '\n';
81410327Seric 				continue;
81510327Seric 
81610327Seric 			  case 'f':		/* form feed */
81710327Seric 				*q++ = '\f';
81810327Seric 				continue;
81910327Seric 
82010327Seric 			  case 'b':		/* backspace */
82110327Seric 				*q++ = '\b';
82210327Seric 				continue;
82310327Seric 			}
82410327Seric 			*q++ = *p;
82510327Seric 		}
82610327Seric 		else
82710327Seric 		{
82810327Seric 			if (*p == '\\')
82910327Seric 				backslash = TRUE;
83010327Seric 			else if (*p == '"')
83110327Seric 				quotemode = !quotemode;
83210327Seric 			else if (quotemode || *p != ',')
83310327Seric 				*q++ = *p;
83410327Seric 			else
83510327Seric 				break;
83610327Seric 		}
8374096Seric 	}
8384096Seric 
83958333Seric 	if (delimptr != NULL)
84058333Seric 		*delimptr = p;
84110327Seric 	*q++ = '\0';
84210327Seric 	return (buf);
84310327Seric }
84410327Seric /*
84510327Seric **  MAKEARGV -- break up a string into words
84610327Seric **
84710327Seric **	Parameters:
84810327Seric **		p -- the string to break up.
84910327Seric **
85010327Seric **	Returns:
85110327Seric **		a char **argv (dynamically allocated)
85210327Seric **
85310327Seric **	Side Effects:
85410327Seric **		munges p.
85510327Seric */
8564096Seric 
85710327Seric char **
85810327Seric makeargv(p)
85910327Seric 	register char *p;
86010327Seric {
86110327Seric 	char *q;
86210327Seric 	int i;
86310327Seric 	char **avp;
86410327Seric 	char *argv[MAXPV + 1];
86510327Seric 
86610327Seric 	/* take apart the words */
86710327Seric 	i = 0;
86810327Seric 	while (*p != '\0' && i < MAXPV)
8694096Seric 	{
87010327Seric 		q = p;
87158050Seric 		while (*p != '\0' && !(isascii(*p) && isspace(*p)))
87210327Seric 			p++;
87358050Seric 		while (isascii(*p) && isspace(*p))
87410327Seric 			*p++ = '\0';
87510327Seric 		argv[i++] = newstr(q);
8764096Seric 	}
87710327Seric 	argv[i++] = NULL;
8784096Seric 
87910327Seric 	/* now make a copy of the argv */
88010327Seric 	avp = (char **) xalloc(sizeof *avp * i);
88116893Seric 	bcopy((char *) argv, (char *) avp, sizeof *avp * i);
88210327Seric 
88310327Seric 	return (avp);
8843308Seric }
8853308Seric /*
8863308Seric **  PRINTRULES -- print rewrite rules (for debugging)
8873308Seric **
8883308Seric **	Parameters:
8893308Seric **		none.
8903308Seric **
8913308Seric **	Returns:
8923308Seric **		none.
8933308Seric **
8943308Seric **	Side Effects:
8953308Seric **		prints rewrite rules.
8963308Seric */
8973308Seric 
8983308Seric printrules()
8993308Seric {
9003308Seric 	register struct rewrite *rwp;
9014072Seric 	register int ruleset;
9023308Seric 
9034072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
9043308Seric 	{
9054072Seric 		if (RewriteRules[ruleset] == NULL)
9064072Seric 			continue;
9078067Seric 		printf("\n----Rule Set %d:", ruleset);
9083308Seric 
9094072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
9103308Seric 		{
9118067Seric 			printf("\nLHS:");
9128067Seric 			printav(rwp->r_lhs);
9138067Seric 			printf("RHS:");
9148067Seric 			printav(rwp->r_rhs);
9153308Seric 		}
9163308Seric 	}
9173308Seric }
9184319Seric 
9194096Seric /*
9208256Seric **  SETOPTION -- set global processing option
9218256Seric **
9228256Seric **	Parameters:
9238256Seric **		opt -- option name.
9248256Seric **		val -- option value (as a text string).
92521755Seric **		safe -- set if this came from a configuration file.
92621755Seric **			Some options (if set from the command line) will
92721755Seric **			reset the user id to avoid security problems.
9288269Seric **		sticky -- if set, don't let other setoptions override
9298269Seric **			this value.
93058734Seric **		e -- the main envelope.
9318256Seric **
9328256Seric **	Returns:
9338256Seric **		none.
9348256Seric **
9358256Seric **	Side Effects:
9368256Seric **		Sets options as implied by the arguments.
9378256Seric */
9388256Seric 
93910687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
9408269Seric 
94157207Seric 
94257207Seric #ifdef NAMED_BIND
94357207Seric 
94457207Seric struct resolverflags
94557207Seric {
94657207Seric 	char	*rf_name;	/* name of the flag */
94757207Seric 	long	rf_bits;	/* bits to set/clear */
94857207Seric } ResolverFlags[] =
94957207Seric {
95057207Seric 	"debug",	RES_DEBUG,
95157207Seric 	"aaonly",	RES_AAONLY,
95257207Seric 	"usevc",	RES_USEVC,
95357207Seric 	"primary",	RES_PRIMARY,
95457207Seric 	"igntc",	RES_IGNTC,
95557207Seric 	"recurse",	RES_RECURSE,
95657207Seric 	"defnames",	RES_DEFNAMES,
95757207Seric 	"stayopen",	RES_STAYOPEN,
95857207Seric 	"dnsrch",	RES_DNSRCH,
95957207Seric 	NULL,		0
96057207Seric };
96157207Seric 
96257207Seric #endif
96357207Seric 
96458734Seric setoption(opt, val, safe, sticky, e)
9658256Seric 	char opt;
9668256Seric 	char *val;
96721755Seric 	bool safe;
9688269Seric 	bool sticky;
96958734Seric 	register ENVELOPE *e;
9708256Seric {
97157207Seric 	register char *p;
9728265Seric 	extern bool atobool();
97312633Seric 	extern time_t convtime();
97414879Seric 	extern int QueueLA;
97514879Seric 	extern int RefuseLA;
97617474Seric 	extern bool trusteduser();
97717474Seric 	extern char *username();
9788256Seric 
9798256Seric 	if (tTd(37, 1))
9809341Seric 		printf("setoption %c=%s", opt, val);
9818256Seric 
9828256Seric 	/*
9838269Seric 	**  See if this option is preset for us.
9848256Seric 	*/
9858256Seric 
98610687Seric 	if (bitnset(opt, StickyOpt))
9878269Seric 	{
9889341Seric 		if (tTd(37, 1))
9899341Seric 			printf(" (ignored)\n");
9908269Seric 		return;
9918269Seric 	}
9928269Seric 
99321755Seric 	/*
99421755Seric 	**  Check to see if this option can be specified by this user.
99521755Seric 	*/
99621755Seric 
99736238Skarels 	if (!safe && getuid() == 0)
99821755Seric 		safe = TRUE;
99958082Seric 	if (!safe && strchr("bdeEiLmoprsvC8", opt) == NULL)
100021755Seric 	{
100139111Srick 		if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
100221755Seric 		{
100336582Sbostic 			if (tTd(37, 1))
100436582Sbostic 				printf(" (unsafe)");
100536582Sbostic 			if (getuid() != geteuid())
100636582Sbostic 			{
100751210Seric 				if (tTd(37, 1))
100851210Seric 					printf("(Resetting uid)");
100936582Sbostic 				(void) setgid(getgid());
101036582Sbostic 				(void) setuid(getuid());
101136582Sbostic 			}
101221755Seric 		}
101321755Seric 	}
101451210Seric 	if (tTd(37, 1))
101517985Seric 		printf("\n");
10168269Seric 
10178256Seric 	switch (opt)
10188256Seric 	{
101952106Seric 	  case '8':		/* allow eight-bit input */
102052106Seric 		EightBit = atobool(val);
102152106Seric 		break;
102252106Seric 
10238256Seric 	  case 'A':		/* set default alias file */
10249381Seric 		if (val[0] == '\0')
10258269Seric 			AliasFile = "aliases";
10269381Seric 		else
10279381Seric 			AliasFile = newstr(val);
10288256Seric 		break;
10298256Seric 
103017474Seric 	  case 'a':		/* look N minutes for "@:@" in alias file */
103117474Seric 		if (val[0] == '\0')
103217474Seric 			SafeAlias = 5;
103317474Seric 		else
103417474Seric 			SafeAlias = atoi(val);
103517474Seric 		break;
103617474Seric 
103716843Seric 	  case 'B':		/* substitution for blank character */
103816843Seric 		SpaceSub = val[0];
103916843Seric 		if (SpaceSub == '\0')
104016843Seric 			SpaceSub = ' ';
104116843Seric 		break;
104216843Seric 
1043*59283Seric 	  case 'b':		/* min blocks free on queue fs/max msg size */
1044*59283Seric 		p = strchr(val, '/');
1045*59283Seric 		if (p != NULL)
1046*59283Seric 		{
1047*59283Seric 			*p++ = '\0';
1048*59283Seric 			MaxMessageSize = atol(p);
1049*59283Seric 		}
105058082Seric 		MinBlocksFree = atol(val);
105158082Seric 		break;
105258082Seric 
10539284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
10549381Seric 		NoConnect = atobool(val);
10559284Seric 		break;
10569284Seric 
105751305Seric 	  case 'C':		/* checkpoint every N addresses */
105851305Seric 		CheckpointInterval = atoi(val);
105924944Seric 		break;
106024944Seric 
10619284Seric 	  case 'd':		/* delivery mode */
10629284Seric 		switch (*val)
10638269Seric 		{
10649284Seric 		  case '\0':
106558734Seric 			e->e_sendmode = SM_DELIVER;
10668269Seric 			break;
10678269Seric 
106810755Seric 		  case SM_QUEUE:	/* queue only */
106910755Seric #ifndef QUEUE
107010755Seric 			syserr("need QUEUE to set -odqueue");
107156795Seric #endif /* QUEUE */
107210755Seric 			/* fall through..... */
107310755Seric 
10749284Seric 		  case SM_DELIVER:	/* do everything */
10759284Seric 		  case SM_FORK:		/* fork after verification */
107658734Seric 			e->e_sendmode = *val;
10778269Seric 			break;
10788269Seric 
10798269Seric 		  default:
10809284Seric 			syserr("Unknown delivery mode %c", *val);
10818269Seric 			exit(EX_USAGE);
10828269Seric 		}
10838269Seric 		break;
10848269Seric 
10859146Seric 	  case 'D':		/* rebuild alias database as needed */
10869381Seric 		AutoRebuild = atobool(val);
10879146Seric 		break;
10889146Seric 
108955372Seric 	  case 'E':		/* error message header/header file */
109055379Seric 		if (*val != '\0')
109155379Seric 			ErrMsgFile = newstr(val);
109255372Seric 		break;
109355372Seric 
10948269Seric 	  case 'e':		/* set error processing mode */
10958269Seric 		switch (*val)
10968269Seric 		{
10979381Seric 		  case EM_QUIET:	/* be silent about it */
10989381Seric 		  case EM_MAIL:		/* mail back */
10999381Seric 		  case EM_BERKNET:	/* do berknet error processing */
11009381Seric 		  case EM_WRITE:	/* write back (or mail) */
11018269Seric 			HoldErrs = TRUE;
11029381Seric 			/* fall through... */
11038269Seric 
11049381Seric 		  case EM_PRINT:	/* print errors normally (default) */
110558734Seric 			e->e_errormode = *val;
11068269Seric 			break;
11078269Seric 		}
11088269Seric 		break;
11098269Seric 
11109049Seric 	  case 'F':		/* file mode */
111117975Seric 		FileMode = atooct(val) & 0777;
11129049Seric 		break;
11139049Seric 
11148269Seric 	  case 'f':		/* save Unix-style From lines on front */
11159381Seric 		SaveFrom = atobool(val);
11168269Seric 		break;
11178269Seric 
111853735Seric 	  case 'G':		/* match recipients against GECOS field */
111953735Seric 		MatchGecos = atobool(val);
112053735Seric 		break;
112153735Seric 
11228256Seric 	  case 'g':		/* default gid */
112317474Seric 		DefGid = atoi(val);
11248256Seric 		break;
11258256Seric 
11268256Seric 	  case 'H':		/* help file */
11279381Seric 		if (val[0] == '\0')
11288269Seric 			HelpFile = "sendmail.hf";
11299381Seric 		else
11309381Seric 			HelpFile = newstr(val);
11318256Seric 		break;
11328256Seric 
113351305Seric 	  case 'h':		/* maximum hop count */
113451305Seric 		MaxHopCount = atoi(val);
113551305Seric 		break;
113651305Seric 
113735651Seric 	  case 'I':		/* use internet domain name server */
113857207Seric #ifdef NAMED_BIND
113957207Seric 		UseNameServer = TRUE;
114057207Seric 		for (p = val; *p != 0; )
114157207Seric 		{
114257207Seric 			bool clearmode;
114357207Seric 			char *q;
114457207Seric 			struct resolverflags *rfp;
114557207Seric 
114657207Seric 			while (*p == ' ')
114757207Seric 				p++;
114857207Seric 			if (*p == '\0')
114957207Seric 				break;
115057207Seric 			clearmode = FALSE;
115157207Seric 			if (*p == '-')
115257207Seric 				clearmode = TRUE;
115357207Seric 			else if (*p != '+')
115457207Seric 				p--;
115557207Seric 			p++;
115657207Seric 			q = p;
115758050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
115857207Seric 				p++;
115957207Seric 			if (*p != '\0')
116057207Seric 				*p++ = '\0';
116157207Seric 			for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
116257207Seric 			{
116357207Seric 				if (strcasecmp(q, rfp->rf_name) == 0)
116457207Seric 					break;
116557207Seric 			}
116657207Seric 			if (clearmode)
116757207Seric 				_res.options &= ~rfp->rf_bits;
116857207Seric 			else
116957207Seric 				_res.options |= rfp->rf_bits;
117057207Seric 		}
117157207Seric 		if (tTd(8, 2))
117257207Seric 			printf("_res.options = %x\n", _res.options);
117357207Seric #else
117457207Seric 		usrerr("name server (I option) specified but BIND not compiled in");
117557207Seric #endif
117635651Seric 		break;
117735651Seric 
11788269Seric 	  case 'i':		/* ignore dot lines in message */
11799381Seric 		IgnrDot = atobool(val);
11808269Seric 		break;
11818269Seric 
118257136Seric 	  case 'J':		/* .forward search path */
118357136Seric 		ForwardPath = newstr(val);
118457136Seric 		break;
118557136Seric 
118654967Seric 	  case 'k':		/* connection cache size */
118754967Seric 		MaxMciCache = atoi(val);
118856215Seric 		if (MaxMciCache < 0)
118956215Seric 			MaxMciCache = 0;
119054967Seric 		break;
119154967Seric 
119254967Seric 	  case 'K':		/* connection cache timeout */
119358796Seric 		MciCacheTimeout = convtime(val, 'm');
119454967Seric 		break;
119554967Seric 
11968256Seric 	  case 'L':		/* log level */
11979381Seric 		LogLevel = atoi(val);
11988256Seric 		break;
11998256Seric 
12008269Seric 	  case 'M':		/* define macro */
12019381Seric 		define(val[0], newstr(&val[1]), CurEnv);
120216878Seric 		sticky = FALSE;
12038269Seric 		break;
12048269Seric 
12058269Seric 	  case 'm':		/* send to me too */
12069381Seric 		MeToo = atobool(val);
12078269Seric 		break;
12088269Seric 
120925820Seric 	  case 'n':		/* validate RHS in newaliases */
121025820Seric 		CheckAliases = atobool(val);
121125820Seric 		break;
121225820Seric 
121358851Seric 	  case 'O':		/* daemon options */
121458851Seric 		setdaemonoptions(val);
121558851Seric 		break;
121658851Seric 
12178269Seric 	  case 'o':		/* assume old style headers */
12189381Seric 		if (atobool(val))
12199341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
12209341Seric 		else
12219341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
12228269Seric 		break;
12238269Seric 
122458082Seric 	  case 'p':		/* select privacy level */
122558082Seric 		p = val;
122658082Seric 		for (;;)
122758082Seric 		{
122858082Seric 			register struct prival *pv;
122958082Seric 			extern struct prival PrivacyValues[];
123058082Seric 
123158082Seric 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
123258082Seric 				p++;
123358082Seric 			if (*p == '\0')
123458082Seric 				break;
123558082Seric 			val = p;
123658082Seric 			while (isascii(*p) && isalnum(*p))
123758082Seric 				p++;
123858082Seric 			if (*p != '\0')
123958082Seric 				*p++ = '\0';
124058082Seric 
124158082Seric 			for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
124258082Seric 			{
124358082Seric 				if (strcasecmp(val, pv->pv_name) == 0)
124458082Seric 					break;
124558082Seric 			}
124658886Seric 			if (pv->pv_name == NULL)
124758886Seric 				syserr("readcf: Op line: %s unrecognized", val);
124858082Seric 			PrivacyFlags |= pv->pv_flag;
124958082Seric 		}
125058082Seric 		break;
125158082Seric 
125224944Seric 	  case 'P':		/* postmaster copy address for returned mail */
125324944Seric 		PostMasterCopy = newstr(val);
125424944Seric 		break;
125524944Seric 
125624944Seric 	  case 'q':		/* slope of queue only function */
125724944Seric 		QueueFactor = atoi(val);
125824944Seric 		break;
125924944Seric 
12608256Seric 	  case 'Q':		/* queue directory */
12619381Seric 		if (val[0] == '\0')
12628269Seric 			QueueDir = "mqueue";
12639381Seric 		else
12649381Seric 			QueueDir = newstr(val);
126558789Seric 		if (RealUid != 0 && !safe)
126658789Seric 			auth_warning(e, "Processed from queue %s", QueueDir);
12678256Seric 		break;
12688256Seric 
126958148Seric 	  case 'R':		/* don't prune routes */
127058148Seric 		DontPruneRoutes = atobool(val);
127158148Seric 		break;
127258148Seric 
12738256Seric 	  case 'r':		/* read timeout */
127458112Seric 		settimeouts(val);
12758256Seric 		break;
12768256Seric 
12778256Seric 	  case 'S':		/* status file */
12789381Seric 		if (val[0] == '\0')
12798269Seric 			StatFile = "sendmail.st";
12809381Seric 		else
12819381Seric 			StatFile = newstr(val);
12828256Seric 		break;
12838256Seric 
12848265Seric 	  case 's':		/* be super safe, even if expensive */
12859381Seric 		SuperSafe = atobool(val);
12868256Seric 		break;
12878256Seric 
12888256Seric 	  case 'T':		/* queue timeout */
128958737Seric 		p = strchr(val, '/');
129058737Seric 		if (p != NULL)
129158737Seric 		{
129258737Seric 			*p++ = '\0';
129358796Seric 			TimeOuts.to_q_warning = convtime(p, 'd');
129458737Seric 		}
129558796Seric 		TimeOuts.to_q_return = convtime(val, 'h');
129654967Seric 		break;
12978256Seric 
12988265Seric 	  case 't':		/* time zone name */
129952106Seric 		TimeZoneSpec = newstr(val);
13008265Seric 		break;
13018265Seric 
130250556Seric 	  case 'U':		/* location of user database */
130351360Seric 		UdbSpec = newstr(val);
130450556Seric 		break;
130550556Seric 
13068256Seric 	  case 'u':		/* set default uid */
130717474Seric 		DefUid = atoi(val);
130840973Sbostic 		setdefuser();
13098256Seric 		break;
13108256Seric 
131158851Seric 	  case 'V':		/* fallback MX host */
131258851Seric 		FallBackMX = newstr(val);
131358851Seric 		break;
131458851Seric 
13158269Seric 	  case 'v':		/* run in verbose mode */
13169381Seric 		Verbose = atobool(val);
13178256Seric 		break;
13188256Seric 
131914879Seric 	  case 'x':		/* load avg at which to auto-queue msgs */
132014879Seric 		QueueLA = atoi(val);
132114879Seric 		break;
132214879Seric 
132314879Seric 	  case 'X':		/* load avg at which to auto-reject connections */
132414879Seric 		RefuseLA = atoi(val);
132514879Seric 		break;
132614879Seric 
132724981Seric 	  case 'y':		/* work recipient factor */
132824981Seric 		WkRecipFact = atoi(val);
132924981Seric 		break;
133024981Seric 
133124981Seric 	  case 'Y':		/* fork jobs during queue runs */
133224952Seric 		ForkQueueRuns = atobool(val);
133324952Seric 		break;
133424952Seric 
133524981Seric 	  case 'z':		/* work message class factor */
133624981Seric 		WkClassFact = atoi(val);
133724981Seric 		break;
133824981Seric 
133924981Seric 	  case 'Z':		/* work time factor */
134024981Seric 		WkTimeFact = atoi(val);
134124981Seric 		break;
134224981Seric 
13438256Seric 	  default:
13448256Seric 		break;
13458256Seric 	}
134616878Seric 	if (sticky)
134716878Seric 		setbitn(opt, StickyOpt);
13489188Seric 	return;
13498256Seric }
135010687Seric /*
135110687Seric **  SETCLASS -- set a word into a class
135210687Seric **
135310687Seric **	Parameters:
135410687Seric **		class -- the class to put the word in.
135510687Seric **		word -- the word to enter
135610687Seric **
135710687Seric **	Returns:
135810687Seric **		none.
135910687Seric **
136010687Seric **	Side Effects:
136110687Seric **		puts the word into the symbol table.
136210687Seric */
136310687Seric 
136410687Seric setclass(class, word)
136510687Seric 	int class;
136610687Seric 	char *word;
136710687Seric {
136810687Seric 	register STAB *s;
136910687Seric 
137057943Seric 	if (tTd(37, 8))
137157943Seric 		printf("%s added to class %c\n", word, class);
137210687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
137310687Seric 	setbitn(class, s->s_class);
137410687Seric }
137553654Seric /*
137653654Seric **  MAKEMAPENTRY -- create a map entry
137753654Seric **
137853654Seric **	Parameters:
137953654Seric **		line -- the config file line
138053654Seric **
138153654Seric **	Returns:
138253654Seric **		TRUE if it successfully entered the map entry.
138353654Seric **		FALSE otherwise (usually syntax error).
138453654Seric **
138553654Seric **	Side Effects:
138653654Seric **		Enters the map into the dictionary.
138753654Seric */
138853654Seric 
138953654Seric void
139053654Seric makemapentry(line)
139153654Seric 	char *line;
139253654Seric {
139353654Seric 	register char *p;
139453654Seric 	char *mapname;
139553654Seric 	char *classname;
139653654Seric 	register STAB *map;
139753654Seric 	STAB *class;
139853654Seric 
139958050Seric 	for (p = line; isascii(*p) && isspace(*p); p++)
140053654Seric 		continue;
140158050Seric 	if (!(isascii(*p) && isalnum(*p)))
140253654Seric 	{
140353654Seric 		syserr("readcf: config K line: no map name");
140453654Seric 		return;
140553654Seric 	}
140653654Seric 
140753654Seric 	mapname = p;
140858050Seric 	while (isascii(*++p) && isalnum(*p))
140953654Seric 		continue;
141053654Seric 	if (*p != '\0')
141153654Seric 		*p++ = '\0';
141258050Seric 	while (isascii(*p) && isspace(*p))
141353654Seric 		p++;
141458050Seric 	if (!(isascii(*p) && isalnum(*p)))
141553654Seric 	{
141653654Seric 		syserr("readcf: config K line, map %s: no map class", mapname);
141753654Seric 		return;
141853654Seric 	}
141953654Seric 	classname = p;
142058050Seric 	while (isascii(*++p) && isalnum(*p))
142153654Seric 		continue;
142253654Seric 	if (*p != '\0')
142353654Seric 		*p++ = '\0';
142458050Seric 	while (isascii(*p) && isspace(*p))
142553654Seric 		p++;
142653654Seric 
142753654Seric 	/* look up the class */
142853654Seric 	class = stab(classname, ST_MAPCLASS, ST_FIND);
142953654Seric 	if (class == NULL)
143053654Seric 	{
143153654Seric 		syserr("readcf: map %s: class %s not available", mapname, classname);
143253654Seric 		return;
143353654Seric 	}
143453654Seric 
143553654Seric 	/* enter the map */
143653654Seric 	map = stab(mapname, ST_MAP, ST_ENTER);
143753654Seric 	map->s_map.map_class = &class->s_mapclass;
143853654Seric 
143956823Seric 	if ((*class->s_mapclass.map_init)(&map->s_map, mapname, p))
144053654Seric 		map->s_map.map_flags |= MF_VALID;
144153654Seric }
144258112Seric /*
144358112Seric **  SETTIMEOUTS -- parse and set timeout values
144458112Seric **
144558112Seric **	Parameters:
144658112Seric **		val -- a pointer to the values.  If NULL, do initial
144758112Seric **			settings.
144858112Seric **
144958112Seric **	Returns:
145058112Seric **		none.
145158112Seric **
145258112Seric **	Side Effects:
145358112Seric **		Initializes the TimeOuts structure
145458112Seric */
145558112Seric 
145658112Seric #define MINUTES	* 60
145758112Seric #define HOUR	* 3600
145858112Seric 
145958112Seric settimeouts(val)
146058112Seric 	register char *val;
146158112Seric {
146258112Seric 	register char *p;
146358671Seric 	extern time_t convtime();
146458112Seric 
146558112Seric 	if (val == NULL)
146658112Seric 	{
146758112Seric 		TimeOuts.to_initial = (time_t) 5 MINUTES;
146858112Seric 		TimeOuts.to_helo = (time_t) 5 MINUTES;
146958112Seric 		TimeOuts.to_mail = (time_t) 10 MINUTES;
147058112Seric 		TimeOuts.to_rcpt = (time_t) 1 HOUR;
147158112Seric 		TimeOuts.to_datainit = (time_t) 5 MINUTES;
147258112Seric 		TimeOuts.to_datablock = (time_t) 1 HOUR;
147358112Seric 		TimeOuts.to_datafinal = (time_t) 1 HOUR;
147458112Seric 		TimeOuts.to_rset = (time_t) 5 MINUTES;
147558112Seric 		TimeOuts.to_quit = (time_t) 2 MINUTES;
147658112Seric 		TimeOuts.to_nextcommand = (time_t) 1 HOUR;
147758112Seric 		TimeOuts.to_miscshort = (time_t) 2 MINUTES;
147858112Seric 		return;
147958112Seric 	}
148058112Seric 
148158112Seric 	for (;; val = p)
148258112Seric 	{
148358112Seric 		while (isascii(*val) && isspace(*val))
148458112Seric 			val++;
148558112Seric 		if (*val == '\0')
148658112Seric 			break;
148758112Seric 		for (p = val; *p != '\0' && *p != ','; p++)
148858112Seric 			continue;
148958112Seric 		if (*p != '\0')
149058112Seric 			*p++ = '\0';
149158112Seric 
149258112Seric 		if (isascii(*val) && isdigit(*val))
149358112Seric 		{
149458112Seric 			/* old syntax -- set everything */
149558796Seric 			TimeOuts.to_mail = convtime(val, 'm');
149658112Seric 			TimeOuts.to_rcpt = TimeOuts.to_mail;
149758112Seric 			TimeOuts.to_datainit = TimeOuts.to_mail;
149858112Seric 			TimeOuts.to_datablock = TimeOuts.to_mail;
149958112Seric 			TimeOuts.to_datafinal = TimeOuts.to_mail;
150058112Seric 			TimeOuts.to_nextcommand = TimeOuts.to_mail;
150158112Seric 			continue;
150258112Seric 		}
150358112Seric 		else
150458112Seric 		{
150558112Seric 			register char *q = strchr(val, '=');
150658112Seric 			time_t to;
150758112Seric 
150858112Seric 			if (q == NULL)
150958112Seric 			{
151058112Seric 				/* syntax error */
151158112Seric 				continue;
151258112Seric 			}
151358112Seric 			*q++ = '\0';
151458796Seric 			to = convtime(q, 'm');
151558112Seric 
151658112Seric 			if (strcasecmp(val, "initial") == 0)
151758112Seric 				TimeOuts.to_initial = to;
151858112Seric 			else if (strcasecmp(val, "mail") == 0)
151958112Seric 				TimeOuts.to_mail = to;
152058112Seric 			else if (strcasecmp(val, "rcpt") == 0)
152158112Seric 				TimeOuts.to_rcpt = to;
152258112Seric 			else if (strcasecmp(val, "datainit") == 0)
152358112Seric 				TimeOuts.to_datainit = to;
152458112Seric 			else if (strcasecmp(val, "datablock") == 0)
152558112Seric 				TimeOuts.to_datablock = to;
152658112Seric 			else if (strcasecmp(val, "datafinal") == 0)
152758112Seric 				TimeOuts.to_datafinal = to;
152858112Seric 			else if (strcasecmp(val, "command") == 0)
152958112Seric 				TimeOuts.to_nextcommand = to;
153058112Seric 			else if (strcasecmp(val, "rset") == 0)
153158112Seric 				TimeOuts.to_rset = to;
153258112Seric 			else if (strcasecmp(val, "helo") == 0)
153358112Seric 				TimeOuts.to_helo = to;
153458112Seric 			else if (strcasecmp(val, "quit") == 0)
153558112Seric 				TimeOuts.to_quit = to;
153658112Seric 			else if (strcasecmp(val, "misc") == 0)
153758112Seric 				TimeOuts.to_miscshort = to;
153858112Seric 			else
153958112Seric 				syserr("settimeouts: invalid timeout %s", val);
154058112Seric 		}
154158112Seric 	}
154258112Seric }
1543