xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 59156)
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*59156Seric static char sccsid[] = "@(#)readcf.c	6.26 (Berkeley) 04/18/93";
1133731Sbostic #endif /* not lint */
1222709Sdist 
133313Seric # include "sendmail.h"
1452647Seric # include <sys/stat.h>
1557207Seric #ifdef NAMED_BIND
1657207Seric # include <arpa/nameser.h>
1757207Seric # include <resolv.h>
1857207Seric #endif
193308Seric 
2057736Seric /* System 5 compatibility */
2157736Seric #ifndef S_ISREG
2257736Seric #define S_ISREG(foo)	((foo & S_IFREG) == S_IFREG)
2357736Seric #endif
2457736Seric #ifndef S_IWGRP
2557736Seric #define S_IWGRP		020
2657736Seric #endif
2757736Seric #ifndef S_IWOTH
2857736Seric #define S_IWOTH		002
2957736Seric #endif
3057736Seric 
313308Seric /*
323308Seric **  READCF -- read control file.
333308Seric **
343308Seric **	This routine reads the control file and builds the internal
353308Seric **	form.
363308Seric **
374432Seric **	The file is formatted as a sequence of lines, each taken
384432Seric **	atomically.  The first character of each line describes how
394432Seric **	the line is to be interpreted.  The lines are:
404432Seric **		Dxval		Define macro x to have value val.
414432Seric **		Cxword		Put word into class x.
424432Seric **		Fxfile [fmt]	Read file for lines to put into
434432Seric **				class x.  Use scanf string 'fmt'
444432Seric **				or "%s" if not present.  Fmt should
454432Seric **				only produce one string-valued result.
464432Seric **		Hname: value	Define header with field-name 'name'
474432Seric **				and value as specified; this will be
484432Seric **				macro expanded immediately before
494432Seric **				use.
504432Seric **		Sn		Use rewriting set n.
514432Seric **		Rlhs rhs	Rewrite addresses that match lhs to
524432Seric **				be rhs.
5324944Seric **		Mn arg=val...	Define mailer.  n is the internal name.
5424944Seric **				Args specify mailer parameters.
558252Seric **		Oxvalue		Set option x to value.
568252Seric **		Pname=value	Set precedence name to value.
5752645Seric **		Vversioncode	Version level of configuration syntax.
5853654Seric **		Kmapname mapclass arguments....
5953654Seric **				Define keyed lookup of a given class.
6053654Seric **				Arguments are class dependent.
614432Seric **
623308Seric **	Parameters:
633308Seric **		cfname -- control file name.
6454973Seric **		safe -- TRUE if this is the system config file;
6554973Seric **			FALSE otherwise.
6655012Seric **		e -- the main envelope.
673308Seric **
683308Seric **	Returns:
693308Seric **		none.
703308Seric **
713308Seric **	Side Effects:
723308Seric **		Builds several internal tables.
733308Seric */
743308Seric 
7555012Seric readcf(cfname, safe, e)
763308Seric 	char *cfname;
7754973Seric 	bool safe;
7855012Seric 	register ENVELOPE *e;
793308Seric {
803308Seric 	FILE *cf;
818547Seric 	int ruleset = 0;
828547Seric 	char *q;
838547Seric 	char **pv;
849350Seric 	struct rewrite *rwp = NULL;
8557135Seric 	char *bp;
8657589Seric 	int nfuzzy;
873308Seric 	char buf[MAXLINE];
883308Seric 	register char *p;
893308Seric 	extern char **prescan();
903308Seric 	extern char **copyplist();
9152647Seric 	struct stat statb;
925909Seric 	char exbuf[MAXLINE];
9316915Seric 	char pvpbuf[PSBUFSIZE];
949350Seric 	extern char *fgetfolded();
9510709Seric 	extern char *munchstring();
9653654Seric 	extern void makemapentry();
973308Seric 
9852647Seric 	FileName = cfname;
9952647Seric 	LineNumber = 0;
10052647Seric 
1013308Seric 	cf = fopen(cfname, "r");
1023308Seric 	if (cf == NULL)
1033308Seric 	{
10452647Seric 		syserr("cannot open");
1053308Seric 		exit(EX_OSFILE);
1063308Seric 	}
1073308Seric 
10852647Seric 	if (fstat(fileno(cf), &statb) < 0)
10952647Seric 	{
11052647Seric 		syserr("cannot fstat");
11152647Seric 		exit(EX_OSFILE);
11252647Seric 	}
11352647Seric 
11452647Seric 	if (!S_ISREG(statb.st_mode))
11552647Seric 	{
11652647Seric 		syserr("not a plain file");
11752647Seric 		exit(EX_OSFILE);
11852647Seric 	}
11952647Seric 
12052647Seric 	if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
12152647Seric 	{
12253037Seric 		if (OpMode == MD_DAEMON || OpMode == MD_FREEZE)
12353037Seric 			fprintf(stderr, "%s: WARNING: dangerous write permissions\n",
12453037Seric 				FileName);
12553037Seric #ifdef LOG
12653037Seric 		if (LogLevel > 0)
12753037Seric 			syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions",
12853037Seric 				FileName);
12953037Seric #endif
13052647Seric 	}
13152647Seric 
13257135Seric 	while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL)
1333308Seric 	{
13457135Seric 		if (bp[0] == '#')
13557135Seric 		{
13657135Seric 			if (bp != buf)
13757135Seric 				free(bp);
13852637Seric 			continue;
13957135Seric 		}
14052637Seric 
14158050Seric 		/* map $ into \201 for macro expansion */
14257135Seric 		for (p = bp; *p != '\0'; p++)
14316157Seric 		{
14457135Seric 			if (*p == '#' && p > bp && ConfigLevel >= 3)
14552647Seric 			{
14652647Seric 				/* this is an on-line comment */
14752647Seric 				register char *e;
14852647Seric 
14958050Seric 				switch (*--p & 0377)
15052647Seric 				{
15158050Seric 				  case MACROEXPAND:
15252647Seric 					/* it's from $# -- let it go through */
15352647Seric 					p++;
15452647Seric 					break;
15552647Seric 
15652647Seric 				  case '\\':
15752647Seric 					/* it's backslash escaped */
15852647Seric 					(void) strcpy(p, p + 1);
15952647Seric 					break;
16052647Seric 
16152647Seric 				  default:
16252647Seric 					/* delete preceeding white space */
16358050Seric 					while (isascii(*p) && isspace(*p) && p > bp)
16452647Seric 						p--;
16556795Seric 					if ((e = strchr(++p, '\n')) != NULL)
16652647Seric 						(void) strcpy(p, e);
16752647Seric 					else
16852647Seric 						p[0] = p[1] = '\0';
16952647Seric 					break;
17052647Seric 				}
17152647Seric 				continue;
17252647Seric 			}
17352647Seric 
17416157Seric 			if (*p != '$')
17516157Seric 				continue;
17616157Seric 
17716157Seric 			if (p[1] == '$')
17816157Seric 			{
17916157Seric 				/* actual dollar sign.... */
18023111Seric 				(void) strcpy(p, p + 1);
18116157Seric 				continue;
18216157Seric 			}
18316157Seric 
18416157Seric 			/* convert to macro expansion character */
18558050Seric 			*p = MACROEXPAND;
18616157Seric 		}
18716157Seric 
18816157Seric 		/* interpret this line */
18957135Seric 		switch (bp[0])
1903308Seric 		{
1913308Seric 		  case '\0':
1923308Seric 		  case '#':		/* comment */
1933308Seric 			break;
1943308Seric 
1953308Seric 		  case 'R':		/* rewriting rule */
19657135Seric 			for (p = &bp[1]; *p != '\0' && *p != '\t'; p++)
1973308Seric 				continue;
1983308Seric 
1993308Seric 			if (*p == '\0')
2005909Seric 			{
20157135Seric 				syserr("invalid rewrite line \"%s\"", bp);
2025909Seric 				break;
2035909Seric 			}
2045909Seric 
2055909Seric 			/* allocate space for the rule header */
2065909Seric 			if (rwp == NULL)
2075909Seric 			{
2085909Seric 				RewriteRules[ruleset] = rwp =
2095909Seric 					(struct rewrite *) xalloc(sizeof *rwp);
2105909Seric 			}
2113308Seric 			else
2123308Seric 			{
2135909Seric 				rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
2145909Seric 				rwp = rwp->r_next;
2155909Seric 			}
2165909Seric 			rwp->r_next = NULL;
2173308Seric 
2185909Seric 			/* expand and save the LHS */
2195909Seric 			*p = '\0';
22057135Seric 			expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e);
22158333Seric 			rwp->r_lhs = prescan(exbuf, '\t', pvpbuf, NULL);
22257589Seric 			nfuzzy = 0;
2235909Seric 			if (rwp->r_lhs != NULL)
22457589Seric 			{
22557589Seric 				register char **ap;
22657589Seric 
2275909Seric 				rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
22857589Seric 
22957589Seric 				/* count the number of fuzzy matches in LHS */
23057589Seric 				for (ap = rwp->r_lhs; *ap != NULL; ap++)
23157589Seric 				{
23258148Seric 					char *botch;
23358148Seric 
23458148Seric 					botch = NULL;
23558050Seric 					switch (**ap & 0377)
23657589Seric 					{
23757589Seric 					  case MATCHZANY:
23857589Seric 					  case MATCHANY:
23957589Seric 					  case MATCHONE:
24057589Seric 					  case MATCHCLASS:
24157589Seric 					  case MATCHNCLASS:
24257589Seric 						nfuzzy++;
24358148Seric 						break;
24458148Seric 
24558148Seric 					  case MATCHREPL:
24658148Seric 						botch = "$0-$9";
24758148Seric 						break;
24858148Seric 
24958148Seric 					  case CANONNET:
25058148Seric 						botch = "$#";
25158148Seric 						break;
25258148Seric 
25358148Seric 					  case CANONUSER:
25458148Seric 						botch = "$:";
25558148Seric 						break;
25658148Seric 
25758148Seric 					  case CALLSUBR:
25858148Seric 						botch = "$>";
25958148Seric 						break;
26058148Seric 
26158148Seric 					  case CONDIF:
26258148Seric 						botch = "$?";
26358148Seric 						break;
26458148Seric 
26558148Seric 					  case CONDELSE:
26658148Seric 						botch = "$|";
26758148Seric 						break;
26858148Seric 
26958148Seric 					  case CONDFI:
27058148Seric 						botch = "$.";
27158148Seric 						break;
27258148Seric 
27358148Seric 					  case HOSTBEGIN:
27458148Seric 						botch = "$[";
27558148Seric 						break;
27658148Seric 
27758148Seric 					  case HOSTEND:
27858148Seric 						botch = "$]";
27958148Seric 						break;
28058148Seric 
28158148Seric 					  case LOOKUPBEGIN:
28258148Seric 						botch = "$(";
28358148Seric 						break;
28458148Seric 
28558148Seric 					  case LOOKUPEND:
28658148Seric 						botch = "$)";
28758148Seric 						break;
28857589Seric 					}
28958148Seric 					if (botch != NULL)
29058148Seric 						syserr("Inappropriate use of %s on LHS",
29158148Seric 							botch);
29257589Seric 				}
29357589Seric 			}
29456678Seric 			else
29556678Seric 				syserr("R line: null LHS");
2965909Seric 
2975909Seric 			/* expand and save the RHS */
2985909Seric 			while (*++p == '\t')
2995909Seric 				continue;
3007231Seric 			q = p;
3017231Seric 			while (*p != '\0' && *p != '\t')
3027231Seric 				p++;
3037231Seric 			*p = '\0';
30455012Seric 			expand(q, exbuf, &exbuf[sizeof exbuf], e);
30558333Seric 			rwp->r_rhs = prescan(exbuf, '\t', pvpbuf, NULL);
3065909Seric 			if (rwp->r_rhs != NULL)
30757589Seric 			{
30857589Seric 				register char **ap;
30957589Seric 
3105909Seric 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
31157589Seric 
31257589Seric 				/* check no out-of-bounds replacements */
31357589Seric 				nfuzzy += '0';
31457589Seric 				for (ap = rwp->r_rhs; *ap != NULL; ap++)
31557589Seric 				{
31658148Seric 					char *botch;
31758148Seric 
31858148Seric 					botch = NULL;
31958148Seric 					switch (**ap & 0377)
32057589Seric 					{
32158148Seric 					  case MATCHREPL:
32258148Seric 						if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy)
32358148Seric 						{
32458148Seric 							syserr("replacement $%c out of bounds",
32558148Seric 								(*ap)[1]);
32658148Seric 						}
32758148Seric 						break;
32858148Seric 
32958148Seric 					  case MATCHZANY:
33058148Seric 						botch = "$*";
33158148Seric 						break;
33258148Seric 
33358148Seric 					  case MATCHANY:
33458148Seric 						botch = "$+";
33558148Seric 						break;
33658148Seric 
33758148Seric 					  case MATCHONE:
33858148Seric 						botch = "$-";
33958148Seric 						break;
34058148Seric 
34158148Seric 					  case MATCHCLASS:
34258148Seric 						botch = "$=";
34358148Seric 						break;
34458148Seric 
34558148Seric 					  case MATCHNCLASS:
34658148Seric 						botch = "$~";
34758148Seric 						break;
34857589Seric 					}
34958148Seric 					if (botch != NULL)
35058148Seric 						syserr("Inappropriate use of %s on RHS",
35158148Seric 							botch);
35257589Seric 				}
35357589Seric 			}
35456678Seric 			else
35556678Seric 				syserr("R line: null RHS");
3563308Seric 			break;
3573308Seric 
3584072Seric 		  case 'S':		/* select rewriting set */
35957135Seric 			ruleset = atoi(&bp[1]);
3608056Seric 			if (ruleset >= MAXRWSETS || ruleset < 0)
3618056Seric 			{
3629381Seric 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
3638056Seric 				ruleset = 0;
3648056Seric 			}
3654072Seric 			rwp = NULL;
3664072Seric 			break;
3674072Seric 
3683308Seric 		  case 'D':		/* macro definition */
36958333Seric 			define(bp[1], newstr(munchstring(&bp[2], NULL)), e);
3703308Seric 			break;
3713308Seric 
3723387Seric 		  case 'H':		/* required header line */
37357135Seric 			(void) chompheader(&bp[1], TRUE, e);
3743387Seric 			break;
3753387Seric 
3764061Seric 		  case 'C':		/* word class */
3774432Seric 		  case 'F':		/* word class from file */
3784432Seric 			/* read list of words from argument or file */
37957135Seric 			if (bp[0] == 'F')
3804432Seric 			{
3814432Seric 				/* read from file */
38258050Seric 				for (p = &bp[2];
38358050Seric 				     *p != '\0' && !(isascii(*p) && isspace(*p));
38458050Seric 				     p++)
3854432Seric 					continue;
3864432Seric 				if (*p == '\0')
3874432Seric 					p = "%s";
3884432Seric 				else
3894432Seric 				{
3904432Seric 					*p = '\0';
39158050Seric 					while (isascii(*++p) && isspace(*p))
3924432Seric 						continue;
3934432Seric 				}
39457135Seric 				fileclass(bp[1], &bp[2], p, safe);
3954432Seric 				break;
3964432Seric 			}
3974061Seric 
3984432Seric 			/* scan the list of words and set class for all */
39957135Seric 			for (p = &bp[2]; *p != '\0'; )
4004061Seric 			{
4014061Seric 				register char *wd;
4024061Seric 				char delim;
4034061Seric 
40458050Seric 				while (*p != '\0' && isascii(*p) && isspace(*p))
4054061Seric 					p++;
4064061Seric 				wd = p;
40758050Seric 				while (*p != '\0' && !(isascii(*p) && isspace(*p)))
4084061Seric 					p++;
4094061Seric 				delim = *p;
4104061Seric 				*p = '\0';
4114061Seric 				if (wd[0] != '\0')
41258148Seric 				{
41358148Seric 					if (tTd(37, 2))
41458148Seric 						printf("setclass(%c, %s)\n",
41558148Seric 							bp[1], wd);
41657135Seric 					setclass(bp[1], wd);
41758148Seric 				}
4184061Seric 				*p = delim;
4194061Seric 			}
4204061Seric 			break;
4214061Seric 
422*59156Seric #ifdef XLA
423*59156Seric 		  case 'L':		/* extended load average description */
424*59156Seric 			xla_init(&bp[1]);
425*59156Seric 			break;
426*59156Seric #endif
427*59156Seric 
4284096Seric 		  case 'M':		/* define mailer */
42957135Seric 			makemailer(&bp[1]);
4304096Seric 			break;
4314096Seric 
4328252Seric 		  case 'O':		/* set option */
43358734Seric 			setoption(bp[1], &bp[2], safe, FALSE, e);
4348252Seric 			break;
4358252Seric 
4368252Seric 		  case 'P':		/* set precedence */
4378252Seric 			if (NumPriorities >= MAXPRIORITIES)
4388252Seric 			{
4398547Seric 				toomany('P', MAXPRIORITIES);
4408252Seric 				break;
4418252Seric 			}
44257135Seric 			for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
4438252Seric 				continue;
4448252Seric 			if (*p == '\0')
4458252Seric 				goto badline;
4468252Seric 			*p = '\0';
44757135Seric 			Priorities[NumPriorities].pri_name = newstr(&bp[1]);
4488252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
4498252Seric 			NumPriorities++;
4508252Seric 			break;
4518252Seric 
4528547Seric 		  case 'T':		/* trusted user(s) */
45358161Seric 			/* this option is obsolete, but will be ignored */
4548547Seric 			break;
4558547Seric 
45652645Seric 		  case 'V':		/* configuration syntax version */
45757135Seric 			ConfigLevel = atoi(&bp[1]);
45852645Seric 			break;
45952645Seric 
46053654Seric 		  case 'K':
46157135Seric 			makemapentry(&bp[1]);
46253654Seric 			break;
46353654Seric 
4643308Seric 		  default:
4654061Seric 		  badline:
46657135Seric 			syserr("unknown control line \"%s\"", bp);
4673308Seric 		}
46857135Seric 		if (bp != buf)
46957135Seric 			free(bp);
4703308Seric 	}
47152637Seric 	if (ferror(cf))
47252637Seric 	{
47352647Seric 		syserr("I/O read error", cfname);
47452637Seric 		exit(EX_OSFILE);
47552637Seric 	}
47652637Seric 	fclose(cf);
4779381Seric 	FileName = NULL;
47856836Seric 
47957076Seric 	if (stab("host", ST_MAP, ST_FIND) == NULL)
48057076Seric 	{
48157076Seric 		/* user didn't initialize: set up host map */
48257076Seric 		strcpy(buf, "host host");
48357076Seric 		if (ConfigLevel >= 2)
48457076Seric 			strcat(buf, " -a.");
48557076Seric 		makemapentry(buf);
48657076Seric 	}
4874096Seric }
4884096Seric /*
4898547Seric **  TOOMANY -- signal too many of some option
4908547Seric **
4918547Seric **	Parameters:
4928547Seric **		id -- the id of the error line
4938547Seric **		maxcnt -- the maximum possible values
4948547Seric **
4958547Seric **	Returns:
4968547Seric **		none.
4978547Seric **
4988547Seric **	Side Effects:
4998547Seric **		gives a syserr.
5008547Seric */
5018547Seric 
5028547Seric toomany(id, maxcnt)
5038547Seric 	char id;
5048547Seric 	int maxcnt;
5058547Seric {
5069381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
5078547Seric }
5088547Seric /*
5094432Seric **  FILECLASS -- read members of a class from a file
5104432Seric **
5114432Seric **	Parameters:
5124432Seric **		class -- class to define.
5134432Seric **		filename -- name of file to read.
5144432Seric **		fmt -- scanf string to use for match.
5154432Seric **
5164432Seric **	Returns:
5174432Seric **		none
5184432Seric **
5194432Seric **	Side Effects:
5204432Seric **
5214432Seric **		puts all lines in filename that match a scanf into
5224432Seric **			the named class.
5234432Seric */
5244432Seric 
52554973Seric fileclass(class, filename, fmt, safe)
5264432Seric 	int class;
5274432Seric 	char *filename;
5284432Seric 	char *fmt;
52954973Seric 	bool safe;
5304432Seric {
53125808Seric 	FILE *f;
53254973Seric 	struct stat stbuf;
5334432Seric 	char buf[MAXLINE];
5344432Seric 
53554973Seric 	if (stat(filename, &stbuf) < 0)
53654973Seric 	{
53754973Seric 		syserr("fileclass: cannot stat %s", filename);
53854973Seric 		return;
53954973Seric 	}
54054973Seric 	if (!S_ISREG(stbuf.st_mode))
54154973Seric 	{
54254973Seric 		syserr("fileclass: %s not a regular file", filename);
54354973Seric 		return;
54454973Seric 	}
54554973Seric 	if (!safe && access(filename, R_OK) < 0)
54654973Seric 	{
54754973Seric 		syserr("fileclass: access denied on %s", filename);
54854973Seric 		return;
54954973Seric 	}
55054973Seric 	f = fopen(filename, "r");
5514432Seric 	if (f == NULL)
5524432Seric 	{
55354973Seric 		syserr("fileclass: cannot open %s", filename);
5544432Seric 		return;
5554432Seric 	}
5564432Seric 
5574432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
5584432Seric 	{
5594432Seric 		register STAB *s;
56025808Seric 		register char *p;
56125808Seric # ifdef SCANF
5624432Seric 		char wordbuf[MAXNAME+1];
5634432Seric 
5644432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
5654432Seric 			continue;
56625808Seric 		p = wordbuf;
56756795Seric # else /* SCANF */
56825808Seric 		p = buf;
56956795Seric # endif /* SCANF */
57025808Seric 
57125808Seric 		/*
57225808Seric 		**  Break up the match into words.
57325808Seric 		*/
57425808Seric 
57525808Seric 		while (*p != '\0')
57625808Seric 		{
57725808Seric 			register char *q;
57825808Seric 
57925808Seric 			/* strip leading spaces */
58058050Seric 			while (isascii(*p) && isspace(*p))
58125808Seric 				p++;
58225808Seric 			if (*p == '\0')
58325808Seric 				break;
58425808Seric 
58525808Seric 			/* find the end of the word */
58625808Seric 			q = p;
58758050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
58825808Seric 				p++;
58925808Seric 			if (*p != '\0')
59025808Seric 				*p++ = '\0';
59125808Seric 
59225808Seric 			/* enter the word in the symbol table */
59325808Seric 			s = stab(q, ST_CLASS, ST_ENTER);
59425808Seric 			setbitn(class, s->s_class);
59525808Seric 		}
5964432Seric 	}
5974432Seric 
59854973Seric 	(void) fclose(f);
5994432Seric }
6004432Seric /*
6014096Seric **  MAKEMAILER -- define a new mailer.
6024096Seric **
6034096Seric **	Parameters:
60410327Seric **		line -- description of mailer.  This is in labeled
60510327Seric **			fields.  The fields are:
60610327Seric **			   P -- the path to the mailer
60710327Seric **			   F -- the flags associated with the mailer
60810327Seric **			   A -- the argv for this mailer
60910327Seric **			   S -- the sender rewriting set
61010327Seric **			   R -- the recipient rewriting set
61110327Seric **			   E -- the eol string
61210327Seric **			The first word is the canonical name of the mailer.
6134096Seric **
6144096Seric **	Returns:
6154096Seric **		none.
6164096Seric **
6174096Seric **	Side Effects:
6184096Seric **		enters the mailer into the mailer table.
6194096Seric */
6203308Seric 
62121066Seric makemailer(line)
6224096Seric 	char *line;
6234096Seric {
6244096Seric 	register char *p;
6258067Seric 	register struct mailer *m;
6268067Seric 	register STAB *s;
6278067Seric 	int i;
62810327Seric 	char fcode;
62958020Seric 	auto char *endp;
6304096Seric 	extern int NextMailer;
63110327Seric 	extern char **makeargv();
63210327Seric 	extern char *munchstring();
63310701Seric 	extern long atol();
6344096Seric 
63510327Seric 	/* allocate a mailer and set up defaults */
63610327Seric 	m = (struct mailer *) xalloc(sizeof *m);
63710327Seric 	bzero((char *) m, sizeof *m);
63810327Seric 	m->m_eol = "\n";
63910327Seric 
64010327Seric 	/* collect the mailer name */
64158050Seric 	for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++)
64210327Seric 		continue;
64310327Seric 	if (*p != '\0')
64410327Seric 		*p++ = '\0';
64510327Seric 	m->m_name = newstr(line);
64610327Seric 
64710327Seric 	/* now scan through and assign info from the fields */
64810327Seric 	while (*p != '\0')
64910327Seric 	{
65058333Seric 		auto char *delimptr;
65158333Seric 
65258050Seric 		while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p))))
65310327Seric 			p++;
65410327Seric 
65510327Seric 		/* p now points to field code */
65610327Seric 		fcode = *p;
65710327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
65810327Seric 			p++;
65910327Seric 		if (*p++ != '=')
66010327Seric 		{
66152637Seric 			syserr("mailer %s: `=' expected", m->m_name);
66210327Seric 			return;
66310327Seric 		}
66458050Seric 		while (isascii(*p) && isspace(*p))
66510327Seric 			p++;
66610327Seric 
66710327Seric 		/* p now points to the field body */
66858333Seric 		p = munchstring(p, &delimptr);
66910327Seric 
67010327Seric 		/* install the field into the mailer struct */
67110327Seric 		switch (fcode)
67210327Seric 		{
67310327Seric 		  case 'P':		/* pathname */
67410327Seric 			m->m_mailer = newstr(p);
67510327Seric 			break;
67610327Seric 
67710327Seric 		  case 'F':		/* flags */
67810687Seric 			for (; *p != '\0'; p++)
67958050Seric 				if (!(isascii(*p) && isspace(*p)))
68052637Seric 					setbitn(*p, m->m_flags);
68110327Seric 			break;
68210327Seric 
68310327Seric 		  case 'S':		/* sender rewriting ruleset */
68410327Seric 		  case 'R':		/* recipient rewriting ruleset */
68558020Seric 			i = strtol(p, &endp, 10);
68610327Seric 			if (i < 0 || i >= MAXRWSETS)
68710327Seric 			{
68810327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
68910327Seric 				return;
69010327Seric 			}
69110327Seric 			if (fcode == 'S')
69258020Seric 				m->m_sh_rwset = m->m_se_rwset = i;
69310327Seric 			else
69458020Seric 				m->m_rh_rwset = m->m_re_rwset = i;
69558020Seric 
69658020Seric 			p = endp;
69758020Seric 			if (*p == '/')
69858020Seric 			{
69958020Seric 				i = strtol(p, NULL, 10);
70058020Seric 				if (i < 0 || i >= MAXRWSETS)
70158020Seric 				{
70258020Seric 					syserr("invalid rewrite set, %d max",
70358020Seric 						MAXRWSETS);
70458020Seric 					return;
70558020Seric 				}
70658020Seric 				if (fcode == 'S')
70758020Seric 					m->m_sh_rwset = i;
70858020Seric 				else
70958020Seric 					m->m_rh_rwset = i;
71058020Seric 			}
71110327Seric 			break;
71210327Seric 
71310327Seric 		  case 'E':		/* end of line string */
71410327Seric 			m->m_eol = newstr(p);
71510327Seric 			break;
71610327Seric 
71710327Seric 		  case 'A':		/* argument vector */
71810327Seric 			m->m_argv = makeargv(p);
71910327Seric 			break;
72010701Seric 
72110701Seric 		  case 'M':		/* maximum message size */
72210701Seric 			m->m_maxsize = atol(p);
72310701Seric 			break;
72452106Seric 
72552106Seric 		  case 'L':		/* maximum line length */
72652106Seric 			m->m_linelimit = atoi(p);
72752106Seric 			break;
72858935Seric 
72958935Seric 		  case 'D':		/* working directory */
73058935Seric 			m->m_execdir = newstr(p);
73158935Seric 			break;
73210327Seric 		}
73310327Seric 
73458333Seric 		p = delimptr;
73510327Seric 	}
73610327Seric 
73752106Seric 	/* do some heuristic cleanup for back compatibility */
73852106Seric 	if (bitnset(M_LIMITS, m->m_flags))
73952106Seric 	{
74052106Seric 		if (m->m_linelimit == 0)
74152106Seric 			m->m_linelimit = SMTPLINELIM;
74255418Seric 		if (ConfigLevel < 2)
74352106Seric 			setbitn(M_7BITS, m->m_flags);
74452106Seric 	}
74552106Seric 
74658321Seric 	/* do some rationality checking */
74758321Seric 	if (m->m_argv == NULL)
74858321Seric 	{
74958321Seric 		syserr("M%s: A= argument required", m->m_name);
75058321Seric 		return;
75158321Seric 	}
75258321Seric 	if (m->m_mailer == NULL)
75358321Seric 	{
75458321Seric 		syserr("M%s: P= argument required", m->m_name);
75558321Seric 		return;
75658321Seric 	}
75758321Seric 
7584096Seric 	if (NextMailer >= MAXMAILERS)
7594096Seric 	{
7609381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
7614096Seric 		return;
7624096Seric 	}
76357402Seric 
76410327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
76557402Seric 	if (s->s_mailer != NULL)
76657402Seric 	{
76757402Seric 		i = s->s_mailer->m_mno;
76857402Seric 		free(s->s_mailer);
76957402Seric 	}
77057402Seric 	else
77157402Seric 	{
77257402Seric 		i = NextMailer++;
77357402Seric 	}
77457402Seric 	Mailer[i] = s->s_mailer = m;
77557454Seric 	m->m_mno = i;
77610327Seric }
77710327Seric /*
77810327Seric **  MUNCHSTRING -- translate a string into internal form.
77910327Seric **
78010327Seric **	Parameters:
78110327Seric **		p -- the string to munch.
78258333Seric **		delimptr -- if non-NULL, set to the pointer of the
78358333Seric **			field delimiter character.
78410327Seric **
78510327Seric **	Returns:
78610327Seric **		the munched string.
78710327Seric */
7884096Seric 
78910327Seric char *
79058333Seric munchstring(p, delimptr)
79110327Seric 	register char *p;
79258333Seric 	char **delimptr;
79310327Seric {
79410327Seric 	register char *q;
79510327Seric 	bool backslash = FALSE;
79610327Seric 	bool quotemode = FALSE;
79710327Seric 	static char buf[MAXLINE];
7984096Seric 
79910327Seric 	for (q = buf; *p != '\0'; p++)
8004096Seric 	{
80110327Seric 		if (backslash)
80210327Seric 		{
80310327Seric 			/* everything is roughly literal */
80410357Seric 			backslash = FALSE;
80510327Seric 			switch (*p)
80610327Seric 			{
80710327Seric 			  case 'r':		/* carriage return */
80810327Seric 				*q++ = '\r';
80910327Seric 				continue;
81010327Seric 
81110327Seric 			  case 'n':		/* newline */
81210327Seric 				*q++ = '\n';
81310327Seric 				continue;
81410327Seric 
81510327Seric 			  case 'f':		/* form feed */
81610327Seric 				*q++ = '\f';
81710327Seric 				continue;
81810327Seric 
81910327Seric 			  case 'b':		/* backspace */
82010327Seric 				*q++ = '\b';
82110327Seric 				continue;
82210327Seric 			}
82310327Seric 			*q++ = *p;
82410327Seric 		}
82510327Seric 		else
82610327Seric 		{
82710327Seric 			if (*p == '\\')
82810327Seric 				backslash = TRUE;
82910327Seric 			else if (*p == '"')
83010327Seric 				quotemode = !quotemode;
83110327Seric 			else if (quotemode || *p != ',')
83210327Seric 				*q++ = *p;
83310327Seric 			else
83410327Seric 				break;
83510327Seric 		}
8364096Seric 	}
8374096Seric 
83858333Seric 	if (delimptr != NULL)
83958333Seric 		*delimptr = p;
84010327Seric 	*q++ = '\0';
84110327Seric 	return (buf);
84210327Seric }
84310327Seric /*
84410327Seric **  MAKEARGV -- break up a string into words
84510327Seric **
84610327Seric **	Parameters:
84710327Seric **		p -- the string to break up.
84810327Seric **
84910327Seric **	Returns:
85010327Seric **		a char **argv (dynamically allocated)
85110327Seric **
85210327Seric **	Side Effects:
85310327Seric **		munges p.
85410327Seric */
8554096Seric 
85610327Seric char **
85710327Seric makeargv(p)
85810327Seric 	register char *p;
85910327Seric {
86010327Seric 	char *q;
86110327Seric 	int i;
86210327Seric 	char **avp;
86310327Seric 	char *argv[MAXPV + 1];
86410327Seric 
86510327Seric 	/* take apart the words */
86610327Seric 	i = 0;
86710327Seric 	while (*p != '\0' && i < MAXPV)
8684096Seric 	{
86910327Seric 		q = p;
87058050Seric 		while (*p != '\0' && !(isascii(*p) && isspace(*p)))
87110327Seric 			p++;
87258050Seric 		while (isascii(*p) && isspace(*p))
87310327Seric 			*p++ = '\0';
87410327Seric 		argv[i++] = newstr(q);
8754096Seric 	}
87610327Seric 	argv[i++] = NULL;
8774096Seric 
87810327Seric 	/* now make a copy of the argv */
87910327Seric 	avp = (char **) xalloc(sizeof *avp * i);
88016893Seric 	bcopy((char *) argv, (char *) avp, sizeof *avp * i);
88110327Seric 
88210327Seric 	return (avp);
8833308Seric }
8843308Seric /*
8853308Seric **  PRINTRULES -- print rewrite rules (for debugging)
8863308Seric **
8873308Seric **	Parameters:
8883308Seric **		none.
8893308Seric **
8903308Seric **	Returns:
8913308Seric **		none.
8923308Seric **
8933308Seric **	Side Effects:
8943308Seric **		prints rewrite rules.
8953308Seric */
8963308Seric 
8973308Seric printrules()
8983308Seric {
8993308Seric 	register struct rewrite *rwp;
9004072Seric 	register int ruleset;
9013308Seric 
9024072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
9033308Seric 	{
9044072Seric 		if (RewriteRules[ruleset] == NULL)
9054072Seric 			continue;
9068067Seric 		printf("\n----Rule Set %d:", ruleset);
9073308Seric 
9084072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
9093308Seric 		{
9108067Seric 			printf("\nLHS:");
9118067Seric 			printav(rwp->r_lhs);
9128067Seric 			printf("RHS:");
9138067Seric 			printav(rwp->r_rhs);
9143308Seric 		}
9153308Seric 	}
9163308Seric }
9174319Seric 
9184096Seric /*
9198256Seric **  SETOPTION -- set global processing option
9208256Seric **
9218256Seric **	Parameters:
9228256Seric **		opt -- option name.
9238256Seric **		val -- option value (as a text string).
92421755Seric **		safe -- set if this came from a configuration file.
92521755Seric **			Some options (if set from the command line) will
92621755Seric **			reset the user id to avoid security problems.
9278269Seric **		sticky -- if set, don't let other setoptions override
9288269Seric **			this value.
92958734Seric **		e -- the main envelope.
9308256Seric **
9318256Seric **	Returns:
9328256Seric **		none.
9338256Seric **
9348256Seric **	Side Effects:
9358256Seric **		Sets options as implied by the arguments.
9368256Seric */
9378256Seric 
93810687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
9398269Seric 
94057207Seric 
94157207Seric #ifdef NAMED_BIND
94257207Seric 
94357207Seric struct resolverflags
94457207Seric {
94557207Seric 	char	*rf_name;	/* name of the flag */
94657207Seric 	long	rf_bits;	/* bits to set/clear */
94757207Seric } ResolverFlags[] =
94857207Seric {
94957207Seric 	"debug",	RES_DEBUG,
95057207Seric 	"aaonly",	RES_AAONLY,
95157207Seric 	"usevc",	RES_USEVC,
95257207Seric 	"primary",	RES_PRIMARY,
95357207Seric 	"igntc",	RES_IGNTC,
95457207Seric 	"recurse",	RES_RECURSE,
95557207Seric 	"defnames",	RES_DEFNAMES,
95657207Seric 	"stayopen",	RES_STAYOPEN,
95757207Seric 	"dnsrch",	RES_DNSRCH,
95857207Seric 	NULL,		0
95957207Seric };
96057207Seric 
96157207Seric #endif
96257207Seric 
96358734Seric setoption(opt, val, safe, sticky, e)
9648256Seric 	char opt;
9658256Seric 	char *val;
96621755Seric 	bool safe;
9678269Seric 	bool sticky;
96858734Seric 	register ENVELOPE *e;
9698256Seric {
97057207Seric 	register char *p;
9718265Seric 	extern bool atobool();
97212633Seric 	extern time_t convtime();
97314879Seric 	extern int QueueLA;
97414879Seric 	extern int RefuseLA;
97517474Seric 	extern bool trusteduser();
97617474Seric 	extern char *username();
9778256Seric 
9788256Seric 	if (tTd(37, 1))
9799341Seric 		printf("setoption %c=%s", opt, val);
9808256Seric 
9818256Seric 	/*
9828269Seric 	**  See if this option is preset for us.
9838256Seric 	*/
9848256Seric 
98510687Seric 	if (bitnset(opt, StickyOpt))
9868269Seric 	{
9879341Seric 		if (tTd(37, 1))
9889341Seric 			printf(" (ignored)\n");
9898269Seric 		return;
9908269Seric 	}
9918269Seric 
99221755Seric 	/*
99321755Seric 	**  Check to see if this option can be specified by this user.
99421755Seric 	*/
99521755Seric 
99636238Skarels 	if (!safe && getuid() == 0)
99721755Seric 		safe = TRUE;
99858082Seric 	if (!safe && strchr("bdeEiLmoprsvC8", opt) == NULL)
99921755Seric 	{
100039111Srick 		if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
100121755Seric 		{
100236582Sbostic 			if (tTd(37, 1))
100336582Sbostic 				printf(" (unsafe)");
100436582Sbostic 			if (getuid() != geteuid())
100536582Sbostic 			{
100651210Seric 				if (tTd(37, 1))
100751210Seric 					printf("(Resetting uid)");
100836582Sbostic 				(void) setgid(getgid());
100936582Sbostic 				(void) setuid(getuid());
101036582Sbostic 			}
101121755Seric 		}
101221755Seric 	}
101351210Seric 	if (tTd(37, 1))
101417985Seric 		printf("\n");
10158269Seric 
10168256Seric 	switch (opt)
10178256Seric 	{
101852106Seric 	  case '8':		/* allow eight-bit input */
101952106Seric 		EightBit = atobool(val);
102052106Seric 		break;
102152106Seric 
10228256Seric 	  case 'A':		/* set default alias file */
10239381Seric 		if (val[0] == '\0')
10248269Seric 			AliasFile = "aliases";
10259381Seric 		else
10269381Seric 			AliasFile = newstr(val);
10278256Seric 		break;
10288256Seric 
102917474Seric 	  case 'a':		/* look N minutes for "@:@" in alias file */
103017474Seric 		if (val[0] == '\0')
103117474Seric 			SafeAlias = 5;
103217474Seric 		else
103317474Seric 			SafeAlias = atoi(val);
103417474Seric 		break;
103517474Seric 
103616843Seric 	  case 'B':		/* substitution for blank character */
103716843Seric 		SpaceSub = val[0];
103816843Seric 		if (SpaceSub == '\0')
103916843Seric 			SpaceSub = ' ';
104016843Seric 		break;
104116843Seric 
104258082Seric 	  case 'b':		/* minimum number of blocks free on queue fs */
104358082Seric 		MinBlocksFree = atol(val);
104458082Seric 		break;
104558082Seric 
10469284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
10479381Seric 		NoConnect = atobool(val);
10489284Seric 		break;
10499284Seric 
105051305Seric 	  case 'C':		/* checkpoint every N addresses */
105151305Seric 		CheckpointInterval = atoi(val);
105224944Seric 		break;
105324944Seric 
10549284Seric 	  case 'd':		/* delivery mode */
10559284Seric 		switch (*val)
10568269Seric 		{
10579284Seric 		  case '\0':
105858734Seric 			e->e_sendmode = SM_DELIVER;
10598269Seric 			break;
10608269Seric 
106110755Seric 		  case SM_QUEUE:	/* queue only */
106210755Seric #ifndef QUEUE
106310755Seric 			syserr("need QUEUE to set -odqueue");
106456795Seric #endif /* QUEUE */
106510755Seric 			/* fall through..... */
106610755Seric 
10679284Seric 		  case SM_DELIVER:	/* do everything */
10689284Seric 		  case SM_FORK:		/* fork after verification */
106958734Seric 			e->e_sendmode = *val;
10708269Seric 			break;
10718269Seric 
10728269Seric 		  default:
10739284Seric 			syserr("Unknown delivery mode %c", *val);
10748269Seric 			exit(EX_USAGE);
10758269Seric 		}
10768269Seric 		break;
10778269Seric 
10789146Seric 	  case 'D':		/* rebuild alias database as needed */
10799381Seric 		AutoRebuild = atobool(val);
10809146Seric 		break;
10819146Seric 
108255372Seric 	  case 'E':		/* error message header/header file */
108355379Seric 		if (*val != '\0')
108455379Seric 			ErrMsgFile = newstr(val);
108555372Seric 		break;
108655372Seric 
10878269Seric 	  case 'e':		/* set error processing mode */
10888269Seric 		switch (*val)
10898269Seric 		{
10909381Seric 		  case EM_QUIET:	/* be silent about it */
10919381Seric 		  case EM_MAIL:		/* mail back */
10929381Seric 		  case EM_BERKNET:	/* do berknet error processing */
10939381Seric 		  case EM_WRITE:	/* write back (or mail) */
10948269Seric 			HoldErrs = TRUE;
10959381Seric 			/* fall through... */
10968269Seric 
10979381Seric 		  case EM_PRINT:	/* print errors normally (default) */
109858734Seric 			e->e_errormode = *val;
10998269Seric 			break;
11008269Seric 		}
11018269Seric 		break;
11028269Seric 
11039049Seric 	  case 'F':		/* file mode */
110417975Seric 		FileMode = atooct(val) & 0777;
11059049Seric 		break;
11069049Seric 
11078269Seric 	  case 'f':		/* save Unix-style From lines on front */
11089381Seric 		SaveFrom = atobool(val);
11098269Seric 		break;
11108269Seric 
111153735Seric 	  case 'G':		/* match recipients against GECOS field */
111253735Seric 		MatchGecos = atobool(val);
111353735Seric 		break;
111453735Seric 
11158256Seric 	  case 'g':		/* default gid */
111617474Seric 		DefGid = atoi(val);
11178256Seric 		break;
11188256Seric 
11198256Seric 	  case 'H':		/* help file */
11209381Seric 		if (val[0] == '\0')
11218269Seric 			HelpFile = "sendmail.hf";
11229381Seric 		else
11239381Seric 			HelpFile = newstr(val);
11248256Seric 		break;
11258256Seric 
112651305Seric 	  case 'h':		/* maximum hop count */
112751305Seric 		MaxHopCount = atoi(val);
112851305Seric 		break;
112951305Seric 
113035651Seric 	  case 'I':		/* use internet domain name server */
113157207Seric #ifdef NAMED_BIND
113257207Seric 		UseNameServer = TRUE;
113357207Seric 		for (p = val; *p != 0; )
113457207Seric 		{
113557207Seric 			bool clearmode;
113657207Seric 			char *q;
113757207Seric 			struct resolverflags *rfp;
113857207Seric 
113957207Seric 			while (*p == ' ')
114057207Seric 				p++;
114157207Seric 			if (*p == '\0')
114257207Seric 				break;
114357207Seric 			clearmode = FALSE;
114457207Seric 			if (*p == '-')
114557207Seric 				clearmode = TRUE;
114657207Seric 			else if (*p != '+')
114757207Seric 				p--;
114857207Seric 			p++;
114957207Seric 			q = p;
115058050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
115157207Seric 				p++;
115257207Seric 			if (*p != '\0')
115357207Seric 				*p++ = '\0';
115457207Seric 			for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
115557207Seric 			{
115657207Seric 				if (strcasecmp(q, rfp->rf_name) == 0)
115757207Seric 					break;
115857207Seric 			}
115957207Seric 			if (clearmode)
116057207Seric 				_res.options &= ~rfp->rf_bits;
116157207Seric 			else
116257207Seric 				_res.options |= rfp->rf_bits;
116357207Seric 		}
116457207Seric 		if (tTd(8, 2))
116557207Seric 			printf("_res.options = %x\n", _res.options);
116657207Seric #else
116757207Seric 		usrerr("name server (I option) specified but BIND not compiled in");
116857207Seric #endif
116935651Seric 		break;
117035651Seric 
11718269Seric 	  case 'i':		/* ignore dot lines in message */
11729381Seric 		IgnrDot = atobool(val);
11738269Seric 		break;
11748269Seric 
117557136Seric 	  case 'J':		/* .forward search path */
117657136Seric 		ForwardPath = newstr(val);
117757136Seric 		break;
117857136Seric 
117954967Seric 	  case 'k':		/* connection cache size */
118054967Seric 		MaxMciCache = atoi(val);
118156215Seric 		if (MaxMciCache < 0)
118256215Seric 			MaxMciCache = 0;
118354967Seric 		break;
118454967Seric 
118554967Seric 	  case 'K':		/* connection cache timeout */
118658796Seric 		MciCacheTimeout = convtime(val, 'm');
118754967Seric 		break;
118854967Seric 
11898256Seric 	  case 'L':		/* log level */
11909381Seric 		LogLevel = atoi(val);
11918256Seric 		break;
11928256Seric 
11938269Seric 	  case 'M':		/* define macro */
11949381Seric 		define(val[0], newstr(&val[1]), CurEnv);
119516878Seric 		sticky = FALSE;
11968269Seric 		break;
11978269Seric 
11988269Seric 	  case 'm':		/* send to me too */
11999381Seric 		MeToo = atobool(val);
12008269Seric 		break;
12018269Seric 
120225820Seric 	  case 'n':		/* validate RHS in newaliases */
120325820Seric 		CheckAliases = atobool(val);
120425820Seric 		break;
120525820Seric 
120658851Seric 	  case 'O':		/* daemon options */
120758851Seric 		setdaemonoptions(val);
120858851Seric 		break;
120958851Seric 
12108269Seric 	  case 'o':		/* assume old style headers */
12119381Seric 		if (atobool(val))
12129341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
12139341Seric 		else
12149341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
12158269Seric 		break;
12168269Seric 
121758082Seric 	  case 'p':		/* select privacy level */
121858082Seric 		p = val;
121958082Seric 		for (;;)
122058082Seric 		{
122158082Seric 			register struct prival *pv;
122258082Seric 			extern struct prival PrivacyValues[];
122358082Seric 
122458082Seric 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
122558082Seric 				p++;
122658082Seric 			if (*p == '\0')
122758082Seric 				break;
122858082Seric 			val = p;
122958082Seric 			while (isascii(*p) && isalnum(*p))
123058082Seric 				p++;
123158082Seric 			if (*p != '\0')
123258082Seric 				*p++ = '\0';
123358082Seric 
123458082Seric 			for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
123558082Seric 			{
123658082Seric 				if (strcasecmp(val, pv->pv_name) == 0)
123758082Seric 					break;
123858082Seric 			}
123958886Seric 			if (pv->pv_name == NULL)
124058886Seric 				syserr("readcf: Op line: %s unrecognized", val);
124158082Seric 			PrivacyFlags |= pv->pv_flag;
124258082Seric 		}
124358082Seric 		break;
124458082Seric 
124524944Seric 	  case 'P':		/* postmaster copy address for returned mail */
124624944Seric 		PostMasterCopy = newstr(val);
124724944Seric 		break;
124824944Seric 
124924944Seric 	  case 'q':		/* slope of queue only function */
125024944Seric 		QueueFactor = atoi(val);
125124944Seric 		break;
125224944Seric 
12538256Seric 	  case 'Q':		/* queue directory */
12549381Seric 		if (val[0] == '\0')
12558269Seric 			QueueDir = "mqueue";
12569381Seric 		else
12579381Seric 			QueueDir = newstr(val);
125858789Seric 		if (RealUid != 0 && !safe)
125958789Seric 			auth_warning(e, "Processed from queue %s", QueueDir);
12608256Seric 		break;
12618256Seric 
126258148Seric 	  case 'R':		/* don't prune routes */
126358148Seric 		DontPruneRoutes = atobool(val);
126458148Seric 		break;
126558148Seric 
12668256Seric 	  case 'r':		/* read timeout */
126758112Seric 		settimeouts(val);
12688256Seric 		break;
12698256Seric 
12708256Seric 	  case 'S':		/* status file */
12719381Seric 		if (val[0] == '\0')
12728269Seric 			StatFile = "sendmail.st";
12739381Seric 		else
12749381Seric 			StatFile = newstr(val);
12758256Seric 		break;
12768256Seric 
12778265Seric 	  case 's':		/* be super safe, even if expensive */
12789381Seric 		SuperSafe = atobool(val);
12798256Seric 		break;
12808256Seric 
12818256Seric 	  case 'T':		/* queue timeout */
128258737Seric 		p = strchr(val, '/');
128358737Seric 		if (p != NULL)
128458737Seric 		{
128558737Seric 			*p++ = '\0';
128658796Seric 			TimeOuts.to_q_warning = convtime(p, 'd');
128758737Seric 		}
128858796Seric 		TimeOuts.to_q_return = convtime(val, 'h');
128954967Seric 		break;
12908256Seric 
12918265Seric 	  case 't':		/* time zone name */
129252106Seric 		TimeZoneSpec = newstr(val);
12938265Seric 		break;
12948265Seric 
129550556Seric 	  case 'U':		/* location of user database */
129651360Seric 		UdbSpec = newstr(val);
129750556Seric 		break;
129850556Seric 
12998256Seric 	  case 'u':		/* set default uid */
130017474Seric 		DefUid = atoi(val);
130140973Sbostic 		setdefuser();
13028256Seric 		break;
13038256Seric 
130458851Seric 	  case 'V':		/* fallback MX host */
130558851Seric 		FallBackMX = newstr(val);
130658851Seric 		break;
130758851Seric 
13088269Seric 	  case 'v':		/* run in verbose mode */
13099381Seric 		Verbose = atobool(val);
13108256Seric 		break;
13118256Seric 
131214879Seric 	  case 'x':		/* load avg at which to auto-queue msgs */
131314879Seric 		QueueLA = atoi(val);
131414879Seric 		break;
131514879Seric 
131614879Seric 	  case 'X':		/* load avg at which to auto-reject connections */
131714879Seric 		RefuseLA = atoi(val);
131814879Seric 		break;
131914879Seric 
132024981Seric 	  case 'y':		/* work recipient factor */
132124981Seric 		WkRecipFact = atoi(val);
132224981Seric 		break;
132324981Seric 
132424981Seric 	  case 'Y':		/* fork jobs during queue runs */
132524952Seric 		ForkQueueRuns = atobool(val);
132624952Seric 		break;
132724952Seric 
132824981Seric 	  case 'z':		/* work message class factor */
132924981Seric 		WkClassFact = atoi(val);
133024981Seric 		break;
133124981Seric 
133224981Seric 	  case 'Z':		/* work time factor */
133324981Seric 		WkTimeFact = atoi(val);
133424981Seric 		break;
133524981Seric 
13368256Seric 	  default:
13378256Seric 		break;
13388256Seric 	}
133916878Seric 	if (sticky)
134016878Seric 		setbitn(opt, StickyOpt);
13419188Seric 	return;
13428256Seric }
134310687Seric /*
134410687Seric **  SETCLASS -- set a word into a class
134510687Seric **
134610687Seric **	Parameters:
134710687Seric **		class -- the class to put the word in.
134810687Seric **		word -- the word to enter
134910687Seric **
135010687Seric **	Returns:
135110687Seric **		none.
135210687Seric **
135310687Seric **	Side Effects:
135410687Seric **		puts the word into the symbol table.
135510687Seric */
135610687Seric 
135710687Seric setclass(class, word)
135810687Seric 	int class;
135910687Seric 	char *word;
136010687Seric {
136110687Seric 	register STAB *s;
136210687Seric 
136357943Seric 	if (tTd(37, 8))
136457943Seric 		printf("%s added to class %c\n", word, class);
136510687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
136610687Seric 	setbitn(class, s->s_class);
136710687Seric }
136853654Seric /*
136953654Seric **  MAKEMAPENTRY -- create a map entry
137053654Seric **
137153654Seric **	Parameters:
137253654Seric **		line -- the config file line
137353654Seric **
137453654Seric **	Returns:
137553654Seric **		TRUE if it successfully entered the map entry.
137653654Seric **		FALSE otherwise (usually syntax error).
137753654Seric **
137853654Seric **	Side Effects:
137953654Seric **		Enters the map into the dictionary.
138053654Seric */
138153654Seric 
138253654Seric void
138353654Seric makemapentry(line)
138453654Seric 	char *line;
138553654Seric {
138653654Seric 	register char *p;
138753654Seric 	char *mapname;
138853654Seric 	char *classname;
138953654Seric 	register STAB *map;
139053654Seric 	STAB *class;
139153654Seric 
139258050Seric 	for (p = line; isascii(*p) && isspace(*p); p++)
139353654Seric 		continue;
139458050Seric 	if (!(isascii(*p) && isalnum(*p)))
139553654Seric 	{
139653654Seric 		syserr("readcf: config K line: no map name");
139753654Seric 		return;
139853654Seric 	}
139953654Seric 
140053654Seric 	mapname = p;
140158050Seric 	while (isascii(*++p) && isalnum(*p))
140253654Seric 		continue;
140353654Seric 	if (*p != '\0')
140453654Seric 		*p++ = '\0';
140558050Seric 	while (isascii(*p) && isspace(*p))
140653654Seric 		p++;
140758050Seric 	if (!(isascii(*p) && isalnum(*p)))
140853654Seric 	{
140953654Seric 		syserr("readcf: config K line, map %s: no map class", mapname);
141053654Seric 		return;
141153654Seric 	}
141253654Seric 	classname = p;
141358050Seric 	while (isascii(*++p) && isalnum(*p))
141453654Seric 		continue;
141553654Seric 	if (*p != '\0')
141653654Seric 		*p++ = '\0';
141758050Seric 	while (isascii(*p) && isspace(*p))
141853654Seric 		p++;
141953654Seric 
142053654Seric 	/* look up the class */
142153654Seric 	class = stab(classname, ST_MAPCLASS, ST_FIND);
142253654Seric 	if (class == NULL)
142353654Seric 	{
142453654Seric 		syserr("readcf: map %s: class %s not available", mapname, classname);
142553654Seric 		return;
142653654Seric 	}
142753654Seric 
142853654Seric 	/* enter the map */
142953654Seric 	map = stab(mapname, ST_MAP, ST_ENTER);
143053654Seric 	map->s_map.map_class = &class->s_mapclass;
143153654Seric 
143256823Seric 	if ((*class->s_mapclass.map_init)(&map->s_map, mapname, p))
143353654Seric 		map->s_map.map_flags |= MF_VALID;
143453654Seric }
143558112Seric /*
143658112Seric **  SETTIMEOUTS -- parse and set timeout values
143758112Seric **
143858112Seric **	Parameters:
143958112Seric **		val -- a pointer to the values.  If NULL, do initial
144058112Seric **			settings.
144158112Seric **
144258112Seric **	Returns:
144358112Seric **		none.
144458112Seric **
144558112Seric **	Side Effects:
144658112Seric **		Initializes the TimeOuts structure
144758112Seric */
144858112Seric 
144958112Seric #define MINUTES	* 60
145058112Seric #define HOUR	* 3600
145158112Seric 
145258112Seric settimeouts(val)
145358112Seric 	register char *val;
145458112Seric {
145558112Seric 	register char *p;
145658671Seric 	extern time_t convtime();
145758112Seric 
145858112Seric 	if (val == NULL)
145958112Seric 	{
146058112Seric 		TimeOuts.to_initial = (time_t) 5 MINUTES;
146158112Seric 		TimeOuts.to_helo = (time_t) 5 MINUTES;
146258112Seric 		TimeOuts.to_mail = (time_t) 10 MINUTES;
146358112Seric 		TimeOuts.to_rcpt = (time_t) 1 HOUR;
146458112Seric 		TimeOuts.to_datainit = (time_t) 5 MINUTES;
146558112Seric 		TimeOuts.to_datablock = (time_t) 1 HOUR;
146658112Seric 		TimeOuts.to_datafinal = (time_t) 1 HOUR;
146758112Seric 		TimeOuts.to_rset = (time_t) 5 MINUTES;
146858112Seric 		TimeOuts.to_quit = (time_t) 2 MINUTES;
146958112Seric 		TimeOuts.to_nextcommand = (time_t) 1 HOUR;
147058112Seric 		TimeOuts.to_miscshort = (time_t) 2 MINUTES;
147158112Seric 		return;
147258112Seric 	}
147358112Seric 
147458112Seric 	for (;; val = p)
147558112Seric 	{
147658112Seric 		while (isascii(*val) && isspace(*val))
147758112Seric 			val++;
147858112Seric 		if (*val == '\0')
147958112Seric 			break;
148058112Seric 		for (p = val; *p != '\0' && *p != ','; p++)
148158112Seric 			continue;
148258112Seric 		if (*p != '\0')
148358112Seric 			*p++ = '\0';
148458112Seric 
148558112Seric 		if (isascii(*val) && isdigit(*val))
148658112Seric 		{
148758112Seric 			/* old syntax -- set everything */
148858796Seric 			TimeOuts.to_mail = convtime(val, 'm');
148958112Seric 			TimeOuts.to_rcpt = TimeOuts.to_mail;
149058112Seric 			TimeOuts.to_datainit = TimeOuts.to_mail;
149158112Seric 			TimeOuts.to_datablock = TimeOuts.to_mail;
149258112Seric 			TimeOuts.to_datafinal = TimeOuts.to_mail;
149358112Seric 			TimeOuts.to_nextcommand = TimeOuts.to_mail;
149458112Seric 			continue;
149558112Seric 		}
149658112Seric 		else
149758112Seric 		{
149858112Seric 			register char *q = strchr(val, '=');
149958112Seric 			time_t to;
150058112Seric 
150158112Seric 			if (q == NULL)
150258112Seric 			{
150358112Seric 				/* syntax error */
150458112Seric 				continue;
150558112Seric 			}
150658112Seric 			*q++ = '\0';
150758796Seric 			to = convtime(q, 'm');
150858112Seric 
150958112Seric 			if (strcasecmp(val, "initial") == 0)
151058112Seric 				TimeOuts.to_initial = to;
151158112Seric 			else if (strcasecmp(val, "mail") == 0)
151258112Seric 				TimeOuts.to_mail = to;
151358112Seric 			else if (strcasecmp(val, "rcpt") == 0)
151458112Seric 				TimeOuts.to_rcpt = to;
151558112Seric 			else if (strcasecmp(val, "datainit") == 0)
151658112Seric 				TimeOuts.to_datainit = to;
151758112Seric 			else if (strcasecmp(val, "datablock") == 0)
151858112Seric 				TimeOuts.to_datablock = to;
151958112Seric 			else if (strcasecmp(val, "datafinal") == 0)
152058112Seric 				TimeOuts.to_datafinal = to;
152158112Seric 			else if (strcasecmp(val, "command") == 0)
152258112Seric 				TimeOuts.to_nextcommand = to;
152358112Seric 			else if (strcasecmp(val, "rset") == 0)
152458112Seric 				TimeOuts.to_rset = to;
152558112Seric 			else if (strcasecmp(val, "helo") == 0)
152658112Seric 				TimeOuts.to_helo = to;
152758112Seric 			else if (strcasecmp(val, "quit") == 0)
152858112Seric 				TimeOuts.to_quit = to;
152958112Seric 			else if (strcasecmp(val, "misc") == 0)
153058112Seric 				TimeOuts.to_miscshort = to;
153158112Seric 			else
153258112Seric 				syserr("settimeouts: invalid timeout %s", val);
153358112Seric 		}
153458112Seric 	}
153558112Seric }
1536