xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 59272)
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*59272Seric static char sccsid[] = "@(#)readcf.c	6.28 (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 
405*59272Seric 		  case 'F':		/* word class from file */
406*59272Seric 			/* read list of words from argument or file */
407*59272Seric 			/* read from file */
408*59272Seric 			for (p = &bp[2];
409*59272Seric 			     *p != '\0' && !(isascii(*p) && isspace(*p));
410*59272Seric 			     p++)
411*59272Seric 				continue;
412*59272Seric 			if (*p == '\0')
413*59272Seric 				p = "%s";
414*59272Seric 			else
415*59272Seric 			{
416*59272Seric 				*p = '\0';
417*59272Seric 				while (isascii(*++p) && isspace(*p))
418*59272Seric 					continue;
419*59272Seric 			}
420*59272Seric 			fileclass(bp[1], &bp[2], p, safe);
421*59272Seric 			break;
422*59272Seric 
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 
104358082Seric 	  case 'b':		/* minimum number of blocks free on queue fs */
104458082Seric 		MinBlocksFree = atol(val);
104558082Seric 		break;
104658082Seric 
10479284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
10489381Seric 		NoConnect = atobool(val);
10499284Seric 		break;
10509284Seric 
105151305Seric 	  case 'C':		/* checkpoint every N addresses */
105251305Seric 		CheckpointInterval = atoi(val);
105324944Seric 		break;
105424944Seric 
10559284Seric 	  case 'd':		/* delivery mode */
10569284Seric 		switch (*val)
10578269Seric 		{
10589284Seric 		  case '\0':
105958734Seric 			e->e_sendmode = SM_DELIVER;
10608269Seric 			break;
10618269Seric 
106210755Seric 		  case SM_QUEUE:	/* queue only */
106310755Seric #ifndef QUEUE
106410755Seric 			syserr("need QUEUE to set -odqueue");
106556795Seric #endif /* QUEUE */
106610755Seric 			/* fall through..... */
106710755Seric 
10689284Seric 		  case SM_DELIVER:	/* do everything */
10699284Seric 		  case SM_FORK:		/* fork after verification */
107058734Seric 			e->e_sendmode = *val;
10718269Seric 			break;
10728269Seric 
10738269Seric 		  default:
10749284Seric 			syserr("Unknown delivery mode %c", *val);
10758269Seric 			exit(EX_USAGE);
10768269Seric 		}
10778269Seric 		break;
10788269Seric 
10799146Seric 	  case 'D':		/* rebuild alias database as needed */
10809381Seric 		AutoRebuild = atobool(val);
10819146Seric 		break;
10829146Seric 
108355372Seric 	  case 'E':		/* error message header/header file */
108455379Seric 		if (*val != '\0')
108555379Seric 			ErrMsgFile = newstr(val);
108655372Seric 		break;
108755372Seric 
10888269Seric 	  case 'e':		/* set error processing mode */
10898269Seric 		switch (*val)
10908269Seric 		{
10919381Seric 		  case EM_QUIET:	/* be silent about it */
10929381Seric 		  case EM_MAIL:		/* mail back */
10939381Seric 		  case EM_BERKNET:	/* do berknet error processing */
10949381Seric 		  case EM_WRITE:	/* write back (or mail) */
10958269Seric 			HoldErrs = TRUE;
10969381Seric 			/* fall through... */
10978269Seric 
10989381Seric 		  case EM_PRINT:	/* print errors normally (default) */
109958734Seric 			e->e_errormode = *val;
11008269Seric 			break;
11018269Seric 		}
11028269Seric 		break;
11038269Seric 
11049049Seric 	  case 'F':		/* file mode */
110517975Seric 		FileMode = atooct(val) & 0777;
11069049Seric 		break;
11079049Seric 
11088269Seric 	  case 'f':		/* save Unix-style From lines on front */
11099381Seric 		SaveFrom = atobool(val);
11108269Seric 		break;
11118269Seric 
111253735Seric 	  case 'G':		/* match recipients against GECOS field */
111353735Seric 		MatchGecos = atobool(val);
111453735Seric 		break;
111553735Seric 
11168256Seric 	  case 'g':		/* default gid */
111717474Seric 		DefGid = atoi(val);
11188256Seric 		break;
11198256Seric 
11208256Seric 	  case 'H':		/* help file */
11219381Seric 		if (val[0] == '\0')
11228269Seric 			HelpFile = "sendmail.hf";
11239381Seric 		else
11249381Seric 			HelpFile = newstr(val);
11258256Seric 		break;
11268256Seric 
112751305Seric 	  case 'h':		/* maximum hop count */
112851305Seric 		MaxHopCount = atoi(val);
112951305Seric 		break;
113051305Seric 
113135651Seric 	  case 'I':		/* use internet domain name server */
113257207Seric #ifdef NAMED_BIND
113357207Seric 		UseNameServer = TRUE;
113457207Seric 		for (p = val; *p != 0; )
113557207Seric 		{
113657207Seric 			bool clearmode;
113757207Seric 			char *q;
113857207Seric 			struct resolverflags *rfp;
113957207Seric 
114057207Seric 			while (*p == ' ')
114157207Seric 				p++;
114257207Seric 			if (*p == '\0')
114357207Seric 				break;
114457207Seric 			clearmode = FALSE;
114557207Seric 			if (*p == '-')
114657207Seric 				clearmode = TRUE;
114757207Seric 			else if (*p != '+')
114857207Seric 				p--;
114957207Seric 			p++;
115057207Seric 			q = p;
115158050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
115257207Seric 				p++;
115357207Seric 			if (*p != '\0')
115457207Seric 				*p++ = '\0';
115557207Seric 			for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
115657207Seric 			{
115757207Seric 				if (strcasecmp(q, rfp->rf_name) == 0)
115857207Seric 					break;
115957207Seric 			}
116057207Seric 			if (clearmode)
116157207Seric 				_res.options &= ~rfp->rf_bits;
116257207Seric 			else
116357207Seric 				_res.options |= rfp->rf_bits;
116457207Seric 		}
116557207Seric 		if (tTd(8, 2))
116657207Seric 			printf("_res.options = %x\n", _res.options);
116757207Seric #else
116857207Seric 		usrerr("name server (I option) specified but BIND not compiled in");
116957207Seric #endif
117035651Seric 		break;
117135651Seric 
11728269Seric 	  case 'i':		/* ignore dot lines in message */
11739381Seric 		IgnrDot = atobool(val);
11748269Seric 		break;
11758269Seric 
117657136Seric 	  case 'J':		/* .forward search path */
117757136Seric 		ForwardPath = newstr(val);
117857136Seric 		break;
117957136Seric 
118054967Seric 	  case 'k':		/* connection cache size */
118154967Seric 		MaxMciCache = atoi(val);
118256215Seric 		if (MaxMciCache < 0)
118356215Seric 			MaxMciCache = 0;
118454967Seric 		break;
118554967Seric 
118654967Seric 	  case 'K':		/* connection cache timeout */
118758796Seric 		MciCacheTimeout = convtime(val, 'm');
118854967Seric 		break;
118954967Seric 
11908256Seric 	  case 'L':		/* log level */
11919381Seric 		LogLevel = atoi(val);
11928256Seric 		break;
11938256Seric 
11948269Seric 	  case 'M':		/* define macro */
11959381Seric 		define(val[0], newstr(&val[1]), CurEnv);
119616878Seric 		sticky = FALSE;
11978269Seric 		break;
11988269Seric 
11998269Seric 	  case 'm':		/* send to me too */
12009381Seric 		MeToo = atobool(val);
12018269Seric 		break;
12028269Seric 
120325820Seric 	  case 'n':		/* validate RHS in newaliases */
120425820Seric 		CheckAliases = atobool(val);
120525820Seric 		break;
120625820Seric 
120758851Seric 	  case 'O':		/* daemon options */
120858851Seric 		setdaemonoptions(val);
120958851Seric 		break;
121058851Seric 
12118269Seric 	  case 'o':		/* assume old style headers */
12129381Seric 		if (atobool(val))
12139341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
12149341Seric 		else
12159341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
12168269Seric 		break;
12178269Seric 
121858082Seric 	  case 'p':		/* select privacy level */
121958082Seric 		p = val;
122058082Seric 		for (;;)
122158082Seric 		{
122258082Seric 			register struct prival *pv;
122358082Seric 			extern struct prival PrivacyValues[];
122458082Seric 
122558082Seric 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
122658082Seric 				p++;
122758082Seric 			if (*p == '\0')
122858082Seric 				break;
122958082Seric 			val = p;
123058082Seric 			while (isascii(*p) && isalnum(*p))
123158082Seric 				p++;
123258082Seric 			if (*p != '\0')
123358082Seric 				*p++ = '\0';
123458082Seric 
123558082Seric 			for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
123658082Seric 			{
123758082Seric 				if (strcasecmp(val, pv->pv_name) == 0)
123858082Seric 					break;
123958082Seric 			}
124058886Seric 			if (pv->pv_name == NULL)
124158886Seric 				syserr("readcf: Op line: %s unrecognized", val);
124258082Seric 			PrivacyFlags |= pv->pv_flag;
124358082Seric 		}
124458082Seric 		break;
124558082Seric 
124624944Seric 	  case 'P':		/* postmaster copy address for returned mail */
124724944Seric 		PostMasterCopy = newstr(val);
124824944Seric 		break;
124924944Seric 
125024944Seric 	  case 'q':		/* slope of queue only function */
125124944Seric 		QueueFactor = atoi(val);
125224944Seric 		break;
125324944Seric 
12548256Seric 	  case 'Q':		/* queue directory */
12559381Seric 		if (val[0] == '\0')
12568269Seric 			QueueDir = "mqueue";
12579381Seric 		else
12589381Seric 			QueueDir = newstr(val);
125958789Seric 		if (RealUid != 0 && !safe)
126058789Seric 			auth_warning(e, "Processed from queue %s", QueueDir);
12618256Seric 		break;
12628256Seric 
126358148Seric 	  case 'R':		/* don't prune routes */
126458148Seric 		DontPruneRoutes = atobool(val);
126558148Seric 		break;
126658148Seric 
12678256Seric 	  case 'r':		/* read timeout */
126858112Seric 		settimeouts(val);
12698256Seric 		break;
12708256Seric 
12718256Seric 	  case 'S':		/* status file */
12729381Seric 		if (val[0] == '\0')
12738269Seric 			StatFile = "sendmail.st";
12749381Seric 		else
12759381Seric 			StatFile = newstr(val);
12768256Seric 		break;
12778256Seric 
12788265Seric 	  case 's':		/* be super safe, even if expensive */
12799381Seric 		SuperSafe = atobool(val);
12808256Seric 		break;
12818256Seric 
12828256Seric 	  case 'T':		/* queue timeout */
128358737Seric 		p = strchr(val, '/');
128458737Seric 		if (p != NULL)
128558737Seric 		{
128658737Seric 			*p++ = '\0';
128758796Seric 			TimeOuts.to_q_warning = convtime(p, 'd');
128858737Seric 		}
128958796Seric 		TimeOuts.to_q_return = convtime(val, 'h');
129054967Seric 		break;
12918256Seric 
12928265Seric 	  case 't':		/* time zone name */
129352106Seric 		TimeZoneSpec = newstr(val);
12948265Seric 		break;
12958265Seric 
129650556Seric 	  case 'U':		/* location of user database */
129751360Seric 		UdbSpec = newstr(val);
129850556Seric 		break;
129950556Seric 
13008256Seric 	  case 'u':		/* set default uid */
130117474Seric 		DefUid = atoi(val);
130240973Sbostic 		setdefuser();
13038256Seric 		break;
13048256Seric 
130558851Seric 	  case 'V':		/* fallback MX host */
130658851Seric 		FallBackMX = newstr(val);
130758851Seric 		break;
130858851Seric 
13098269Seric 	  case 'v':		/* run in verbose mode */
13109381Seric 		Verbose = atobool(val);
13118256Seric 		break;
13128256Seric 
131314879Seric 	  case 'x':		/* load avg at which to auto-queue msgs */
131414879Seric 		QueueLA = atoi(val);
131514879Seric 		break;
131614879Seric 
131714879Seric 	  case 'X':		/* load avg at which to auto-reject connections */
131814879Seric 		RefuseLA = atoi(val);
131914879Seric 		break;
132014879Seric 
132124981Seric 	  case 'y':		/* work recipient factor */
132224981Seric 		WkRecipFact = atoi(val);
132324981Seric 		break;
132424981Seric 
132524981Seric 	  case 'Y':		/* fork jobs during queue runs */
132624952Seric 		ForkQueueRuns = atobool(val);
132724952Seric 		break;
132824952Seric 
132924981Seric 	  case 'z':		/* work message class factor */
133024981Seric 		WkClassFact = atoi(val);
133124981Seric 		break;
133224981Seric 
133324981Seric 	  case 'Z':		/* work time factor */
133424981Seric 		WkTimeFact = atoi(val);
133524981Seric 		break;
133624981Seric 
13378256Seric 	  default:
13388256Seric 		break;
13398256Seric 	}
134016878Seric 	if (sticky)
134116878Seric 		setbitn(opt, StickyOpt);
13429188Seric 	return;
13438256Seric }
134410687Seric /*
134510687Seric **  SETCLASS -- set a word into a class
134610687Seric **
134710687Seric **	Parameters:
134810687Seric **		class -- the class to put the word in.
134910687Seric **		word -- the word to enter
135010687Seric **
135110687Seric **	Returns:
135210687Seric **		none.
135310687Seric **
135410687Seric **	Side Effects:
135510687Seric **		puts the word into the symbol table.
135610687Seric */
135710687Seric 
135810687Seric setclass(class, word)
135910687Seric 	int class;
136010687Seric 	char *word;
136110687Seric {
136210687Seric 	register STAB *s;
136310687Seric 
136457943Seric 	if (tTd(37, 8))
136557943Seric 		printf("%s added to class %c\n", word, class);
136610687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
136710687Seric 	setbitn(class, s->s_class);
136810687Seric }
136953654Seric /*
137053654Seric **  MAKEMAPENTRY -- create a map entry
137153654Seric **
137253654Seric **	Parameters:
137353654Seric **		line -- the config file line
137453654Seric **
137553654Seric **	Returns:
137653654Seric **		TRUE if it successfully entered the map entry.
137753654Seric **		FALSE otherwise (usually syntax error).
137853654Seric **
137953654Seric **	Side Effects:
138053654Seric **		Enters the map into the dictionary.
138153654Seric */
138253654Seric 
138353654Seric void
138453654Seric makemapentry(line)
138553654Seric 	char *line;
138653654Seric {
138753654Seric 	register char *p;
138853654Seric 	char *mapname;
138953654Seric 	char *classname;
139053654Seric 	register STAB *map;
139153654Seric 	STAB *class;
139253654Seric 
139358050Seric 	for (p = line; isascii(*p) && isspace(*p); p++)
139453654Seric 		continue;
139558050Seric 	if (!(isascii(*p) && isalnum(*p)))
139653654Seric 	{
139753654Seric 		syserr("readcf: config K line: no map name");
139853654Seric 		return;
139953654Seric 	}
140053654Seric 
140153654Seric 	mapname = p;
140258050Seric 	while (isascii(*++p) && isalnum(*p))
140353654Seric 		continue;
140453654Seric 	if (*p != '\0')
140553654Seric 		*p++ = '\0';
140658050Seric 	while (isascii(*p) && isspace(*p))
140753654Seric 		p++;
140858050Seric 	if (!(isascii(*p) && isalnum(*p)))
140953654Seric 	{
141053654Seric 		syserr("readcf: config K line, map %s: no map class", mapname);
141153654Seric 		return;
141253654Seric 	}
141353654Seric 	classname = p;
141458050Seric 	while (isascii(*++p) && isalnum(*p))
141553654Seric 		continue;
141653654Seric 	if (*p != '\0')
141753654Seric 		*p++ = '\0';
141858050Seric 	while (isascii(*p) && isspace(*p))
141953654Seric 		p++;
142053654Seric 
142153654Seric 	/* look up the class */
142253654Seric 	class = stab(classname, ST_MAPCLASS, ST_FIND);
142353654Seric 	if (class == NULL)
142453654Seric 	{
142553654Seric 		syserr("readcf: map %s: class %s not available", mapname, classname);
142653654Seric 		return;
142753654Seric 	}
142853654Seric 
142953654Seric 	/* enter the map */
143053654Seric 	map = stab(mapname, ST_MAP, ST_ENTER);
143153654Seric 	map->s_map.map_class = &class->s_mapclass;
143253654Seric 
143356823Seric 	if ((*class->s_mapclass.map_init)(&map->s_map, mapname, p))
143453654Seric 		map->s_map.map_flags |= MF_VALID;
143553654Seric }
143658112Seric /*
143758112Seric **  SETTIMEOUTS -- parse and set timeout values
143858112Seric **
143958112Seric **	Parameters:
144058112Seric **		val -- a pointer to the values.  If NULL, do initial
144158112Seric **			settings.
144258112Seric **
144358112Seric **	Returns:
144458112Seric **		none.
144558112Seric **
144658112Seric **	Side Effects:
144758112Seric **		Initializes the TimeOuts structure
144858112Seric */
144958112Seric 
145058112Seric #define MINUTES	* 60
145158112Seric #define HOUR	* 3600
145258112Seric 
145358112Seric settimeouts(val)
145458112Seric 	register char *val;
145558112Seric {
145658112Seric 	register char *p;
145758671Seric 	extern time_t convtime();
145858112Seric 
145958112Seric 	if (val == NULL)
146058112Seric 	{
146158112Seric 		TimeOuts.to_initial = (time_t) 5 MINUTES;
146258112Seric 		TimeOuts.to_helo = (time_t) 5 MINUTES;
146358112Seric 		TimeOuts.to_mail = (time_t) 10 MINUTES;
146458112Seric 		TimeOuts.to_rcpt = (time_t) 1 HOUR;
146558112Seric 		TimeOuts.to_datainit = (time_t) 5 MINUTES;
146658112Seric 		TimeOuts.to_datablock = (time_t) 1 HOUR;
146758112Seric 		TimeOuts.to_datafinal = (time_t) 1 HOUR;
146858112Seric 		TimeOuts.to_rset = (time_t) 5 MINUTES;
146958112Seric 		TimeOuts.to_quit = (time_t) 2 MINUTES;
147058112Seric 		TimeOuts.to_nextcommand = (time_t) 1 HOUR;
147158112Seric 		TimeOuts.to_miscshort = (time_t) 2 MINUTES;
147258112Seric 		return;
147358112Seric 	}
147458112Seric 
147558112Seric 	for (;; val = p)
147658112Seric 	{
147758112Seric 		while (isascii(*val) && isspace(*val))
147858112Seric 			val++;
147958112Seric 		if (*val == '\0')
148058112Seric 			break;
148158112Seric 		for (p = val; *p != '\0' && *p != ','; p++)
148258112Seric 			continue;
148358112Seric 		if (*p != '\0')
148458112Seric 			*p++ = '\0';
148558112Seric 
148658112Seric 		if (isascii(*val) && isdigit(*val))
148758112Seric 		{
148858112Seric 			/* old syntax -- set everything */
148958796Seric 			TimeOuts.to_mail = convtime(val, 'm');
149058112Seric 			TimeOuts.to_rcpt = TimeOuts.to_mail;
149158112Seric 			TimeOuts.to_datainit = TimeOuts.to_mail;
149258112Seric 			TimeOuts.to_datablock = TimeOuts.to_mail;
149358112Seric 			TimeOuts.to_datafinal = TimeOuts.to_mail;
149458112Seric 			TimeOuts.to_nextcommand = TimeOuts.to_mail;
149558112Seric 			continue;
149658112Seric 		}
149758112Seric 		else
149858112Seric 		{
149958112Seric 			register char *q = strchr(val, '=');
150058112Seric 			time_t to;
150158112Seric 
150258112Seric 			if (q == NULL)
150358112Seric 			{
150458112Seric 				/* syntax error */
150558112Seric 				continue;
150658112Seric 			}
150758112Seric 			*q++ = '\0';
150858796Seric 			to = convtime(q, 'm');
150958112Seric 
151058112Seric 			if (strcasecmp(val, "initial") == 0)
151158112Seric 				TimeOuts.to_initial = to;
151258112Seric 			else if (strcasecmp(val, "mail") == 0)
151358112Seric 				TimeOuts.to_mail = to;
151458112Seric 			else if (strcasecmp(val, "rcpt") == 0)
151558112Seric 				TimeOuts.to_rcpt = to;
151658112Seric 			else if (strcasecmp(val, "datainit") == 0)
151758112Seric 				TimeOuts.to_datainit = to;
151858112Seric 			else if (strcasecmp(val, "datablock") == 0)
151958112Seric 				TimeOuts.to_datablock = to;
152058112Seric 			else if (strcasecmp(val, "datafinal") == 0)
152158112Seric 				TimeOuts.to_datafinal = to;
152258112Seric 			else if (strcasecmp(val, "command") == 0)
152358112Seric 				TimeOuts.to_nextcommand = to;
152458112Seric 			else if (strcasecmp(val, "rset") == 0)
152558112Seric 				TimeOuts.to_rset = to;
152658112Seric 			else if (strcasecmp(val, "helo") == 0)
152758112Seric 				TimeOuts.to_helo = to;
152858112Seric 			else if (strcasecmp(val, "quit") == 0)
152958112Seric 				TimeOuts.to_quit = to;
153058112Seric 			else if (strcasecmp(val, "misc") == 0)
153158112Seric 				TimeOuts.to_miscshort = to;
153258112Seric 			else
153358112Seric 				syserr("settimeouts: invalid timeout %s", val);
153458112Seric 		}
153558112Seric 	}
153658112Seric }
1537