xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 58173)
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*58173Seric static char sccsid[] = "@(#)readcf.c	6.13 (Berkeley) 02/24/93";
1133731Sbostic #endif /* not lint */
1222709Sdist 
133313Seric # include "sendmail.h"
1452647Seric # include <sys/stat.h>
1554973Seric # include <unistd.h>
1657207Seric #ifdef NAMED_BIND
1757207Seric # include <arpa/nameser.h>
1857207Seric # include <resolv.h>
1957207Seric #endif
203308Seric 
2157736Seric /* System 5 compatibility */
2257736Seric #ifndef S_ISREG
2357736Seric #define S_ISREG(foo)	((foo & S_IFREG) == S_IFREG)
2457736Seric #endif
2557736Seric #ifndef S_IWGRP
2657736Seric #define S_IWGRP		020
2757736Seric #endif
2857736Seric #ifndef S_IWOTH
2957736Seric #define S_IWOTH		002
3057736Seric #endif
3157736Seric 
323308Seric /*
333308Seric **  READCF -- read control file.
343308Seric **
353308Seric **	This routine reads the control file and builds the internal
363308Seric **	form.
373308Seric **
384432Seric **	The file is formatted as a sequence of lines, each taken
394432Seric **	atomically.  The first character of each line describes how
404432Seric **	the line is to be interpreted.  The lines are:
414432Seric **		Dxval		Define macro x to have value val.
424432Seric **		Cxword		Put word into class x.
434432Seric **		Fxfile [fmt]	Read file for lines to put into
444432Seric **				class x.  Use scanf string 'fmt'
454432Seric **				or "%s" if not present.  Fmt should
464432Seric **				only produce one string-valued result.
474432Seric **		Hname: value	Define header with field-name 'name'
484432Seric **				and value as specified; this will be
494432Seric **				macro expanded immediately before
504432Seric **				use.
514432Seric **		Sn		Use rewriting set n.
524432Seric **		Rlhs rhs	Rewrite addresses that match lhs to
534432Seric **				be rhs.
5424944Seric **		Mn arg=val...	Define mailer.  n is the internal name.
5524944Seric **				Args specify mailer parameters.
568252Seric **		Oxvalue		Set option x to value.
578252Seric **		Pname=value	Set precedence name to value.
5852645Seric **		Vversioncode	Version level of configuration syntax.
5953654Seric **		Kmapname mapclass arguments....
6053654Seric **				Define keyed lookup of a given class.
6153654Seric **				Arguments are class dependent.
624432Seric **
633308Seric **	Parameters:
643308Seric **		cfname -- control file name.
6554973Seric **		safe -- TRUE if this is the system config file;
6654973Seric **			FALSE otherwise.
6755012Seric **		e -- the main envelope.
683308Seric **
693308Seric **	Returns:
703308Seric **		none.
713308Seric **
723308Seric **	Side Effects:
733308Seric **		Builds several internal tables.
743308Seric */
753308Seric 
7655012Seric readcf(cfname, safe, e)
773308Seric 	char *cfname;
7854973Seric 	bool safe;
7955012Seric 	register ENVELOPE *e;
803308Seric {
813308Seric 	FILE *cf;
828547Seric 	int ruleset = 0;
838547Seric 	char *q;
848547Seric 	char **pv;
859350Seric 	struct rewrite *rwp = NULL;
8657135Seric 	char *bp;
8757589Seric 	int nfuzzy;
883308Seric 	char buf[MAXLINE];
893308Seric 	register char *p;
903308Seric 	extern char **prescan();
913308Seric 	extern char **copyplist();
9252647Seric 	struct stat statb;
935909Seric 	char exbuf[MAXLINE];
9416915Seric 	char pvpbuf[PSBUFSIZE];
959350Seric 	extern char *fgetfolded();
9610709Seric 	extern char *munchstring();
9753654Seric 	extern void makemapentry();
983308Seric 
9952647Seric 	FileName = cfname;
10052647Seric 	LineNumber = 0;
10152647Seric 
1023308Seric 	cf = fopen(cfname, "r");
1033308Seric 	if (cf == NULL)
1043308Seric 	{
10552647Seric 		syserr("cannot open");
1063308Seric 		exit(EX_OSFILE);
1073308Seric 	}
1083308Seric 
10952647Seric 	if (fstat(fileno(cf), &statb) < 0)
11052647Seric 	{
11152647Seric 		syserr("cannot fstat");
11252647Seric 		exit(EX_OSFILE);
11352647Seric 	}
11452647Seric 
11552647Seric 	if (!S_ISREG(statb.st_mode))
11652647Seric 	{
11752647Seric 		syserr("not a plain file");
11852647Seric 		exit(EX_OSFILE);
11952647Seric 	}
12052647Seric 
12152647Seric 	if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
12252647Seric 	{
12353037Seric 		if (OpMode == MD_DAEMON || OpMode == MD_FREEZE)
12453037Seric 			fprintf(stderr, "%s: WARNING: dangerous write permissions\n",
12553037Seric 				FileName);
12653037Seric #ifdef LOG
12753037Seric 		if (LogLevel > 0)
12853037Seric 			syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions",
12953037Seric 				FileName);
13053037Seric #endif
13152647Seric 	}
13252647Seric 
13357135Seric 	while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL)
1343308Seric 	{
13557135Seric 		if (bp[0] == '#')
13657135Seric 		{
13757135Seric 			if (bp != buf)
13857135Seric 				free(bp);
13952637Seric 			continue;
14057135Seric 		}
14152637Seric 
14258050Seric 		/* map $ into \201 for macro expansion */
14357135Seric 		for (p = bp; *p != '\0'; p++)
14416157Seric 		{
14557135Seric 			if (*p == '#' && p > bp && ConfigLevel >= 3)
14652647Seric 			{
14752647Seric 				/* this is an on-line comment */
14852647Seric 				register char *e;
14952647Seric 
15058050Seric 				switch (*--p & 0377)
15152647Seric 				{
15258050Seric 				  case MACROEXPAND:
15352647Seric 					/* it's from $# -- let it go through */
15452647Seric 					p++;
15552647Seric 					break;
15652647Seric 
15752647Seric 				  case '\\':
15852647Seric 					/* it's backslash escaped */
15952647Seric 					(void) strcpy(p, p + 1);
16052647Seric 					break;
16152647Seric 
16252647Seric 				  default:
16352647Seric 					/* delete preceeding white space */
16458050Seric 					while (isascii(*p) && isspace(*p) && p > bp)
16552647Seric 						p--;
16656795Seric 					if ((e = strchr(++p, '\n')) != NULL)
16752647Seric 						(void) strcpy(p, e);
16852647Seric 					else
16952647Seric 						p[0] = p[1] = '\0';
17052647Seric 					break;
17152647Seric 				}
17252647Seric 				continue;
17352647Seric 			}
17452647Seric 
17516157Seric 			if (*p != '$')
17616157Seric 				continue;
17716157Seric 
17816157Seric 			if (p[1] == '$')
17916157Seric 			{
18016157Seric 				/* actual dollar sign.... */
18123111Seric 				(void) strcpy(p, p + 1);
18216157Seric 				continue;
18316157Seric 			}
18416157Seric 
18516157Seric 			/* convert to macro expansion character */
18658050Seric 			*p = MACROEXPAND;
18716157Seric 		}
18816157Seric 
18916157Seric 		/* interpret this line */
19057135Seric 		switch (bp[0])
1913308Seric 		{
1923308Seric 		  case '\0':
1933308Seric 		  case '#':		/* comment */
1943308Seric 			break;
1953308Seric 
1963308Seric 		  case 'R':		/* rewriting rule */
19757135Seric 			for (p = &bp[1]; *p != '\0' && *p != '\t'; p++)
1983308Seric 				continue;
1993308Seric 
2003308Seric 			if (*p == '\0')
2015909Seric 			{
20257135Seric 				syserr("invalid rewrite line \"%s\"", bp);
2035909Seric 				break;
2045909Seric 			}
2055909Seric 
2065909Seric 			/* allocate space for the rule header */
2075909Seric 			if (rwp == NULL)
2085909Seric 			{
2095909Seric 				RewriteRules[ruleset] = rwp =
2105909Seric 					(struct rewrite *) xalloc(sizeof *rwp);
2115909Seric 			}
2123308Seric 			else
2133308Seric 			{
2145909Seric 				rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
2155909Seric 				rwp = rwp->r_next;
2165909Seric 			}
2175909Seric 			rwp->r_next = NULL;
2183308Seric 
2195909Seric 			/* expand and save the LHS */
2205909Seric 			*p = '\0';
22157135Seric 			expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e);
22216915Seric 			rwp->r_lhs = prescan(exbuf, '\t', pvpbuf);
22357589Seric 			nfuzzy = 0;
2245909Seric 			if (rwp->r_lhs != NULL)
22557589Seric 			{
22657589Seric 				register char **ap;
22757589Seric 
2285909Seric 				rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
22957589Seric 
23057589Seric 				/* count the number of fuzzy matches in LHS */
23157589Seric 				for (ap = rwp->r_lhs; *ap != NULL; ap++)
23257589Seric 				{
23358148Seric 					char *botch;
23458148Seric 
23558148Seric 					botch = NULL;
23658050Seric 					switch (**ap & 0377)
23757589Seric 					{
23857589Seric 					  case MATCHZANY:
23957589Seric 					  case MATCHANY:
24057589Seric 					  case MATCHONE:
24157589Seric 					  case MATCHCLASS:
24257589Seric 					  case MATCHNCLASS:
243*58173Seric 					  case CANONHOST:
24457589Seric 						nfuzzy++;
24558148Seric 						break;
24658148Seric 
24758148Seric 					  case MATCHREPL:
24858148Seric 						botch = "$0-$9";
24958148Seric 						break;
25058148Seric 
25158148Seric 					  case CANONNET:
25258148Seric 						botch = "$#";
25358148Seric 						break;
25458148Seric 
25558148Seric 					  case CANONUSER:
25658148Seric 						botch = "$:";
25758148Seric 						break;
25858148Seric 
25958148Seric 					  case CALLSUBR:
26058148Seric 						botch = "$>";
26158148Seric 						break;
26258148Seric 
26358148Seric 					  case CONDIF:
26458148Seric 						botch = "$?";
26558148Seric 						break;
26658148Seric 
26758148Seric 					  case CONDELSE:
26858148Seric 						botch = "$|";
26958148Seric 						break;
27058148Seric 
27158148Seric 					  case CONDFI:
27258148Seric 						botch = "$.";
27358148Seric 						break;
27458148Seric 
27558148Seric 					  case HOSTBEGIN:
27658148Seric 						botch = "$[";
27758148Seric 						break;
27858148Seric 
27958148Seric 					  case HOSTEND:
28058148Seric 						botch = "$]";
28158148Seric 						break;
28258148Seric 
28358148Seric 					  case LOOKUPBEGIN:
28458148Seric 						botch = "$(";
28558148Seric 						break;
28658148Seric 
28758148Seric 					  case LOOKUPEND:
28858148Seric 						botch = "$)";
28958148Seric 						break;
29057589Seric 					}
29158148Seric 					if (botch != NULL)
29258148Seric 						syserr("Inappropriate use of %s on LHS",
29358148Seric 							botch);
29457589Seric 				}
29557589Seric 			}
29656678Seric 			else
29756678Seric 				syserr("R line: null LHS");
2985909Seric 
2995909Seric 			/* expand and save the RHS */
3005909Seric 			while (*++p == '\t')
3015909Seric 				continue;
3027231Seric 			q = p;
3037231Seric 			while (*p != '\0' && *p != '\t')
3047231Seric 				p++;
3057231Seric 			*p = '\0';
30655012Seric 			expand(q, exbuf, &exbuf[sizeof exbuf], e);
30716915Seric 			rwp->r_rhs = prescan(exbuf, '\t', pvpbuf);
3085909Seric 			if (rwp->r_rhs != NULL)
30957589Seric 			{
31057589Seric 				register char **ap;
31157589Seric 
3125909Seric 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
31357589Seric 
31457589Seric 				/* check no out-of-bounds replacements */
31557589Seric 				nfuzzy += '0';
31657589Seric 				for (ap = rwp->r_rhs; *ap != NULL; ap++)
31757589Seric 				{
31858148Seric 					char *botch;
31958148Seric 
32058148Seric 					botch = NULL;
32158148Seric 					switch (**ap & 0377)
32257589Seric 					{
32358148Seric 					  case MATCHREPL:
32458148Seric 						if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy)
32558148Seric 						{
32658148Seric 							syserr("replacement $%c out of bounds",
32758148Seric 								(*ap)[1]);
32858148Seric 						}
32958148Seric 						break;
33058148Seric 
33158148Seric 					  case MATCHZANY:
33258148Seric 						botch = "$*";
33358148Seric 						break;
33458148Seric 
33558148Seric 					  case MATCHANY:
33658148Seric 						botch = "$+";
33758148Seric 						break;
33858148Seric 
33958148Seric 					  case MATCHONE:
34058148Seric 						botch = "$-";
34158148Seric 						break;
34258148Seric 
34358148Seric 					  case MATCHCLASS:
34458148Seric 						botch = "$=";
34558148Seric 						break;
34658148Seric 
34758148Seric 					  case MATCHNCLASS:
34858148Seric 						botch = "$~";
34958148Seric 						break;
35057589Seric 					}
35158148Seric 					if (botch != NULL)
35258148Seric 						syserr("Inappropriate use of %s on RHS",
35358148Seric 							botch);
35457589Seric 				}
35557589Seric 			}
35656678Seric 			else
35756678Seric 				syserr("R line: null RHS");
3583308Seric 			break;
3593308Seric 
3604072Seric 		  case 'S':		/* select rewriting set */
36157135Seric 			ruleset = atoi(&bp[1]);
3628056Seric 			if (ruleset >= MAXRWSETS || ruleset < 0)
3638056Seric 			{
3649381Seric 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
3658056Seric 				ruleset = 0;
3668056Seric 			}
3674072Seric 			rwp = NULL;
3684072Seric 			break;
3694072Seric 
3703308Seric 		  case 'D':		/* macro definition */
37157135Seric 			define(bp[1], newstr(munchstring(&bp[2])), e);
3723308Seric 			break;
3733308Seric 
3743387Seric 		  case 'H':		/* required header line */
37557135Seric 			(void) chompheader(&bp[1], TRUE, e);
3763387Seric 			break;
3773387Seric 
3784061Seric 		  case 'C':		/* word class */
3794432Seric 		  case 'F':		/* word class from file */
3804432Seric 			/* read list of words from argument or file */
38157135Seric 			if (bp[0] == 'F')
3824432Seric 			{
3834432Seric 				/* read from file */
38458050Seric 				for (p = &bp[2];
38558050Seric 				     *p != '\0' && !(isascii(*p) && isspace(*p));
38658050Seric 				     p++)
3874432Seric 					continue;
3884432Seric 				if (*p == '\0')
3894432Seric 					p = "%s";
3904432Seric 				else
3914432Seric 				{
3924432Seric 					*p = '\0';
39358050Seric 					while (isascii(*++p) && isspace(*p))
3944432Seric 						continue;
3954432Seric 				}
39657135Seric 				fileclass(bp[1], &bp[2], p, safe);
3974432Seric 				break;
3984432Seric 			}
3994061Seric 
4004432Seric 			/* scan the list of words and set class for all */
40157135Seric 			for (p = &bp[2]; *p != '\0'; )
4024061Seric 			{
4034061Seric 				register char *wd;
4044061Seric 				char delim;
4054061Seric 
40658050Seric 				while (*p != '\0' && isascii(*p) && isspace(*p))
4074061Seric 					p++;
4084061Seric 				wd = p;
40958050Seric 				while (*p != '\0' && !(isascii(*p) && isspace(*p)))
4104061Seric 					p++;
4114061Seric 				delim = *p;
4124061Seric 				*p = '\0';
4134061Seric 				if (wd[0] != '\0')
41458148Seric 				{
41558148Seric 					if (tTd(37, 2))
41658148Seric 						printf("setclass(%c, %s)\n",
41758148Seric 							bp[1], wd);
41857135Seric 					setclass(bp[1], wd);
41958148Seric 				}
4204061Seric 				*p = delim;
4214061Seric 			}
4224061Seric 			break;
4234061Seric 
4244096Seric 		  case 'M':		/* define mailer */
42557135Seric 			makemailer(&bp[1]);
4264096Seric 			break;
4274096Seric 
4288252Seric 		  case 'O':		/* set option */
42957135Seric 			setoption(bp[1], &bp[2], safe, FALSE);
4308252Seric 			break;
4318252Seric 
4328252Seric 		  case 'P':		/* set precedence */
4338252Seric 			if (NumPriorities >= MAXPRIORITIES)
4348252Seric 			{
4358547Seric 				toomany('P', MAXPRIORITIES);
4368252Seric 				break;
4378252Seric 			}
43857135Seric 			for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
4398252Seric 				continue;
4408252Seric 			if (*p == '\0')
4418252Seric 				goto badline;
4428252Seric 			*p = '\0';
44357135Seric 			Priorities[NumPriorities].pri_name = newstr(&bp[1]);
4448252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
4458252Seric 			NumPriorities++;
4468252Seric 			break;
4478252Seric 
4488547Seric 		  case 'T':		/* trusted user(s) */
44958161Seric 			/* this option is obsolete, but will be ignored */
4508547Seric 			break;
4518547Seric 
45252645Seric 		  case 'V':		/* configuration syntax version */
45357135Seric 			ConfigLevel = atoi(&bp[1]);
45452645Seric 			break;
45552645Seric 
45653654Seric 		  case 'K':
45757135Seric 			makemapentry(&bp[1]);
45853654Seric 			break;
45953654Seric 
4603308Seric 		  default:
4614061Seric 		  badline:
46257135Seric 			syserr("unknown control line \"%s\"", bp);
4633308Seric 		}
46457135Seric 		if (bp != buf)
46557135Seric 			free(bp);
4663308Seric 	}
46752637Seric 	if (ferror(cf))
46852637Seric 	{
46952647Seric 		syserr("I/O read error", cfname);
47052637Seric 		exit(EX_OSFILE);
47152637Seric 	}
47252637Seric 	fclose(cf);
4739381Seric 	FileName = NULL;
47456836Seric 
47557076Seric 	if (stab("host", ST_MAP, ST_FIND) == NULL)
47657076Seric 	{
47757076Seric 		/* user didn't initialize: set up host map */
47857076Seric 		strcpy(buf, "host host");
47957076Seric 		if (ConfigLevel >= 2)
48057076Seric 			strcat(buf, " -a.");
48157076Seric 		makemapentry(buf);
48257076Seric 	}
4834096Seric }
4844096Seric /*
4858547Seric **  TOOMANY -- signal too many of some option
4868547Seric **
4878547Seric **	Parameters:
4888547Seric **		id -- the id of the error line
4898547Seric **		maxcnt -- the maximum possible values
4908547Seric **
4918547Seric **	Returns:
4928547Seric **		none.
4938547Seric **
4948547Seric **	Side Effects:
4958547Seric **		gives a syserr.
4968547Seric */
4978547Seric 
4988547Seric toomany(id, maxcnt)
4998547Seric 	char id;
5008547Seric 	int maxcnt;
5018547Seric {
5029381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
5038547Seric }
5048547Seric /*
5054432Seric **  FILECLASS -- read members of a class from a file
5064432Seric **
5074432Seric **	Parameters:
5084432Seric **		class -- class to define.
5094432Seric **		filename -- name of file to read.
5104432Seric **		fmt -- scanf string to use for match.
5114432Seric **
5124432Seric **	Returns:
5134432Seric **		none
5144432Seric **
5154432Seric **	Side Effects:
5164432Seric **
5174432Seric **		puts all lines in filename that match a scanf into
5184432Seric **			the named class.
5194432Seric */
5204432Seric 
52154973Seric fileclass(class, filename, fmt, safe)
5224432Seric 	int class;
5234432Seric 	char *filename;
5244432Seric 	char *fmt;
52554973Seric 	bool safe;
5264432Seric {
52725808Seric 	FILE *f;
52854973Seric 	struct stat stbuf;
5294432Seric 	char buf[MAXLINE];
5304432Seric 
53154973Seric 	if (stat(filename, &stbuf) < 0)
53254973Seric 	{
53354973Seric 		syserr("fileclass: cannot stat %s", filename);
53454973Seric 		return;
53554973Seric 	}
53654973Seric 	if (!S_ISREG(stbuf.st_mode))
53754973Seric 	{
53854973Seric 		syserr("fileclass: %s not a regular file", filename);
53954973Seric 		return;
54054973Seric 	}
54154973Seric 	if (!safe && access(filename, R_OK) < 0)
54254973Seric 	{
54354973Seric 		syserr("fileclass: access denied on %s", filename);
54454973Seric 		return;
54554973Seric 	}
54654973Seric 	f = fopen(filename, "r");
5474432Seric 	if (f == NULL)
5484432Seric 	{
54954973Seric 		syserr("fileclass: cannot open %s", filename);
5504432Seric 		return;
5514432Seric 	}
5524432Seric 
5534432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
5544432Seric 	{
5554432Seric 		register STAB *s;
55625808Seric 		register char *p;
55725808Seric # ifdef SCANF
5584432Seric 		char wordbuf[MAXNAME+1];
5594432Seric 
5604432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
5614432Seric 			continue;
56225808Seric 		p = wordbuf;
56356795Seric # else /* SCANF */
56425808Seric 		p = buf;
56556795Seric # endif /* SCANF */
56625808Seric 
56725808Seric 		/*
56825808Seric 		**  Break up the match into words.
56925808Seric 		*/
57025808Seric 
57125808Seric 		while (*p != '\0')
57225808Seric 		{
57325808Seric 			register char *q;
57425808Seric 
57525808Seric 			/* strip leading spaces */
57658050Seric 			while (isascii(*p) && isspace(*p))
57725808Seric 				p++;
57825808Seric 			if (*p == '\0')
57925808Seric 				break;
58025808Seric 
58125808Seric 			/* find the end of the word */
58225808Seric 			q = p;
58358050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
58425808Seric 				p++;
58525808Seric 			if (*p != '\0')
58625808Seric 				*p++ = '\0';
58725808Seric 
58825808Seric 			/* enter the word in the symbol table */
58925808Seric 			s = stab(q, ST_CLASS, ST_ENTER);
59025808Seric 			setbitn(class, s->s_class);
59125808Seric 		}
5924432Seric 	}
5934432Seric 
59454973Seric 	(void) fclose(f);
5954432Seric }
5964432Seric /*
5974096Seric **  MAKEMAILER -- define a new mailer.
5984096Seric **
5994096Seric **	Parameters:
60010327Seric **		line -- description of mailer.  This is in labeled
60110327Seric **			fields.  The fields are:
60210327Seric **			   P -- the path to the mailer
60310327Seric **			   F -- the flags associated with the mailer
60410327Seric **			   A -- the argv for this mailer
60510327Seric **			   S -- the sender rewriting set
60610327Seric **			   R -- the recipient rewriting set
60710327Seric **			   E -- the eol string
60810327Seric **			The first word is the canonical name of the mailer.
6094096Seric **
6104096Seric **	Returns:
6114096Seric **		none.
6124096Seric **
6134096Seric **	Side Effects:
6144096Seric **		enters the mailer into the mailer table.
6154096Seric */
6163308Seric 
61721066Seric makemailer(line)
6184096Seric 	char *line;
6194096Seric {
6204096Seric 	register char *p;
6218067Seric 	register struct mailer *m;
6228067Seric 	register STAB *s;
6238067Seric 	int i;
62410327Seric 	char fcode;
62558020Seric 	auto char *endp;
6264096Seric 	extern int NextMailer;
62710327Seric 	extern char **makeargv();
62810327Seric 	extern char *munchstring();
62910327Seric 	extern char *DelimChar;
63010701Seric 	extern long atol();
6314096Seric 
63210327Seric 	/* allocate a mailer and set up defaults */
63310327Seric 	m = (struct mailer *) xalloc(sizeof *m);
63410327Seric 	bzero((char *) m, sizeof *m);
63510327Seric 	m->m_eol = "\n";
63610327Seric 
63710327Seric 	/* collect the mailer name */
63858050Seric 	for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++)
63910327Seric 		continue;
64010327Seric 	if (*p != '\0')
64110327Seric 		*p++ = '\0';
64210327Seric 	m->m_name = newstr(line);
64310327Seric 
64410327Seric 	/* now scan through and assign info from the fields */
64510327Seric 	while (*p != '\0')
64610327Seric 	{
64758050Seric 		while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p))))
64810327Seric 			p++;
64910327Seric 
65010327Seric 		/* p now points to field code */
65110327Seric 		fcode = *p;
65210327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
65310327Seric 			p++;
65410327Seric 		if (*p++ != '=')
65510327Seric 		{
65652637Seric 			syserr("mailer %s: `=' expected", m->m_name);
65710327Seric 			return;
65810327Seric 		}
65958050Seric 		while (isascii(*p) && isspace(*p))
66010327Seric 			p++;
66110327Seric 
66210327Seric 		/* p now points to the field body */
66310327Seric 		p = munchstring(p);
66410327Seric 
66510327Seric 		/* install the field into the mailer struct */
66610327Seric 		switch (fcode)
66710327Seric 		{
66810327Seric 		  case 'P':		/* pathname */
66910327Seric 			m->m_mailer = newstr(p);
67010327Seric 			break;
67110327Seric 
67210327Seric 		  case 'F':		/* flags */
67310687Seric 			for (; *p != '\0'; p++)
67458050Seric 				if (!(isascii(*p) && isspace(*p)))
67552637Seric 					setbitn(*p, m->m_flags);
67610327Seric 			break;
67710327Seric 
67810327Seric 		  case 'S':		/* sender rewriting ruleset */
67910327Seric 		  case 'R':		/* recipient rewriting ruleset */
68058020Seric 			i = strtol(p, &endp, 10);
68110327Seric 			if (i < 0 || i >= MAXRWSETS)
68210327Seric 			{
68310327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
68410327Seric 				return;
68510327Seric 			}
68610327Seric 			if (fcode == 'S')
68758020Seric 				m->m_sh_rwset = m->m_se_rwset = i;
68810327Seric 			else
68958020Seric 				m->m_rh_rwset = m->m_re_rwset = i;
69058020Seric 
69158020Seric 			p = endp;
69258020Seric 			if (*p == '/')
69358020Seric 			{
69458020Seric 				i = strtol(p, NULL, 10);
69558020Seric 				if (i < 0 || i >= MAXRWSETS)
69658020Seric 				{
69758020Seric 					syserr("invalid rewrite set, %d max",
69858020Seric 						MAXRWSETS);
69958020Seric 					return;
70058020Seric 				}
70158020Seric 				if (fcode == 'S')
70258020Seric 					m->m_sh_rwset = i;
70358020Seric 				else
70458020Seric 					m->m_rh_rwset = i;
70558020Seric 			}
70610327Seric 			break;
70710327Seric 
70810327Seric 		  case 'E':		/* end of line string */
70910327Seric 			m->m_eol = newstr(p);
71010327Seric 			break;
71110327Seric 
71210327Seric 		  case 'A':		/* argument vector */
71310327Seric 			m->m_argv = makeargv(p);
71410327Seric 			break;
71510701Seric 
71610701Seric 		  case 'M':		/* maximum message size */
71710701Seric 			m->m_maxsize = atol(p);
71810701Seric 			break;
71952106Seric 
72052106Seric 		  case 'L':		/* maximum line length */
72152106Seric 			m->m_linelimit = atoi(p);
72252106Seric 			break;
72310327Seric 		}
72410327Seric 
72510327Seric 		p = DelimChar;
72610327Seric 	}
72710327Seric 
72852106Seric 	/* do some heuristic cleanup for back compatibility */
72952106Seric 	if (bitnset(M_LIMITS, m->m_flags))
73052106Seric 	{
73152106Seric 		if (m->m_linelimit == 0)
73252106Seric 			m->m_linelimit = SMTPLINELIM;
73355418Seric 		if (ConfigLevel < 2)
73452106Seric 			setbitn(M_7BITS, m->m_flags);
73552106Seric 	}
73652106Seric 
7374096Seric 	if (NextMailer >= MAXMAILERS)
7384096Seric 	{
7399381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
7404096Seric 		return;
7414096Seric 	}
74257402Seric 
74310327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
74457402Seric 	if (s->s_mailer != NULL)
74557402Seric 	{
74657402Seric 		i = s->s_mailer->m_mno;
74757402Seric 		free(s->s_mailer);
74857402Seric 	}
74957402Seric 	else
75057402Seric 	{
75157402Seric 		i = NextMailer++;
75257402Seric 	}
75357402Seric 	Mailer[i] = s->s_mailer = m;
75457454Seric 	m->m_mno = i;
75510327Seric }
75610327Seric /*
75710327Seric **  MUNCHSTRING -- translate a string into internal form.
75810327Seric **
75910327Seric **	Parameters:
76010327Seric **		p -- the string to munch.
76110327Seric **
76210327Seric **	Returns:
76310327Seric **		the munched string.
76410327Seric **
76510327Seric **	Side Effects:
76610327Seric **		Sets "DelimChar" to point to the string that caused us
76710327Seric **		to stop.
76810327Seric */
7694096Seric 
77010327Seric char *
77110327Seric munchstring(p)
77210327Seric 	register char *p;
77310327Seric {
77410327Seric 	register char *q;
77510327Seric 	bool backslash = FALSE;
77610327Seric 	bool quotemode = FALSE;
77710327Seric 	static char buf[MAXLINE];
77810327Seric 	extern char *DelimChar;
7794096Seric 
78010327Seric 	for (q = buf; *p != '\0'; p++)
7814096Seric 	{
78210327Seric 		if (backslash)
78310327Seric 		{
78410327Seric 			/* everything is roughly literal */
78510357Seric 			backslash = FALSE;
78610327Seric 			switch (*p)
78710327Seric 			{
78810327Seric 			  case 'r':		/* carriage return */
78910327Seric 				*q++ = '\r';
79010327Seric 				continue;
79110327Seric 
79210327Seric 			  case 'n':		/* newline */
79310327Seric 				*q++ = '\n';
79410327Seric 				continue;
79510327Seric 
79610327Seric 			  case 'f':		/* form feed */
79710327Seric 				*q++ = '\f';
79810327Seric 				continue;
79910327Seric 
80010327Seric 			  case 'b':		/* backspace */
80110327Seric 				*q++ = '\b';
80210327Seric 				continue;
80310327Seric 			}
80410327Seric 			*q++ = *p;
80510327Seric 		}
80610327Seric 		else
80710327Seric 		{
80810327Seric 			if (*p == '\\')
80910327Seric 				backslash = TRUE;
81010327Seric 			else if (*p == '"')
81110327Seric 				quotemode = !quotemode;
81210327Seric 			else if (quotemode || *p != ',')
81310327Seric 				*q++ = *p;
81410327Seric 			else
81510327Seric 				break;
81610327Seric 		}
8174096Seric 	}
8184096Seric 
81910327Seric 	DelimChar = p;
82010327Seric 	*q++ = '\0';
82110327Seric 	return (buf);
82210327Seric }
82310327Seric /*
82410327Seric **  MAKEARGV -- break up a string into words
82510327Seric **
82610327Seric **	Parameters:
82710327Seric **		p -- the string to break up.
82810327Seric **
82910327Seric **	Returns:
83010327Seric **		a char **argv (dynamically allocated)
83110327Seric **
83210327Seric **	Side Effects:
83310327Seric **		munges p.
83410327Seric */
8354096Seric 
83610327Seric char **
83710327Seric makeargv(p)
83810327Seric 	register char *p;
83910327Seric {
84010327Seric 	char *q;
84110327Seric 	int i;
84210327Seric 	char **avp;
84310327Seric 	char *argv[MAXPV + 1];
84410327Seric 
84510327Seric 	/* take apart the words */
84610327Seric 	i = 0;
84710327Seric 	while (*p != '\0' && i < MAXPV)
8484096Seric 	{
84910327Seric 		q = p;
85058050Seric 		while (*p != '\0' && !(isascii(*p) && isspace(*p)))
85110327Seric 			p++;
85258050Seric 		while (isascii(*p) && isspace(*p))
85310327Seric 			*p++ = '\0';
85410327Seric 		argv[i++] = newstr(q);
8554096Seric 	}
85610327Seric 	argv[i++] = NULL;
8574096Seric 
85810327Seric 	/* now make a copy of the argv */
85910327Seric 	avp = (char **) xalloc(sizeof *avp * i);
86016893Seric 	bcopy((char *) argv, (char *) avp, sizeof *avp * i);
86110327Seric 
86210327Seric 	return (avp);
8633308Seric }
8643308Seric /*
8653308Seric **  PRINTRULES -- print rewrite rules (for debugging)
8663308Seric **
8673308Seric **	Parameters:
8683308Seric **		none.
8693308Seric **
8703308Seric **	Returns:
8713308Seric **		none.
8723308Seric **
8733308Seric **	Side Effects:
8743308Seric **		prints rewrite rules.
8753308Seric */
8763308Seric 
8773308Seric printrules()
8783308Seric {
8793308Seric 	register struct rewrite *rwp;
8804072Seric 	register int ruleset;
8813308Seric 
8824072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
8833308Seric 	{
8844072Seric 		if (RewriteRules[ruleset] == NULL)
8854072Seric 			continue;
8868067Seric 		printf("\n----Rule Set %d:", ruleset);
8873308Seric 
8884072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
8893308Seric 		{
8908067Seric 			printf("\nLHS:");
8918067Seric 			printav(rwp->r_lhs);
8928067Seric 			printf("RHS:");
8938067Seric 			printav(rwp->r_rhs);
8943308Seric 		}
8953308Seric 	}
8963308Seric }
8974319Seric 
8984096Seric /*
8998256Seric **  SETOPTION -- set global processing option
9008256Seric **
9018256Seric **	Parameters:
9028256Seric **		opt -- option name.
9038256Seric **		val -- option value (as a text string).
90421755Seric **		safe -- set if this came from a configuration file.
90521755Seric **			Some options (if set from the command line) will
90621755Seric **			reset the user id to avoid security problems.
9078269Seric **		sticky -- if set, don't let other setoptions override
9088269Seric **			this value.
9098256Seric **
9108256Seric **	Returns:
9118256Seric **		none.
9128256Seric **
9138256Seric **	Side Effects:
9148256Seric **		Sets options as implied by the arguments.
9158256Seric */
9168256Seric 
91710687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
9188269Seric 
91957207Seric 
92057207Seric #ifdef NAMED_BIND
92157207Seric 
92257207Seric struct resolverflags
92357207Seric {
92457207Seric 	char	*rf_name;	/* name of the flag */
92557207Seric 	long	rf_bits;	/* bits to set/clear */
92657207Seric } ResolverFlags[] =
92757207Seric {
92857207Seric 	"debug",	RES_DEBUG,
92957207Seric 	"aaonly",	RES_AAONLY,
93057207Seric 	"usevc",	RES_USEVC,
93157207Seric 	"primary",	RES_PRIMARY,
93257207Seric 	"igntc",	RES_IGNTC,
93357207Seric 	"recurse",	RES_RECURSE,
93457207Seric 	"defnames",	RES_DEFNAMES,
93557207Seric 	"stayopen",	RES_STAYOPEN,
93657207Seric 	"dnsrch",	RES_DNSRCH,
93757207Seric 	NULL,		0
93857207Seric };
93957207Seric 
94057207Seric #endif
94157207Seric 
94221755Seric setoption(opt, val, safe, sticky)
9438256Seric 	char opt;
9448256Seric 	char *val;
94521755Seric 	bool safe;
9468269Seric 	bool sticky;
9478256Seric {
94857207Seric 	register char *p;
9498265Seric 	extern bool atobool();
95012633Seric 	extern time_t convtime();
95114879Seric 	extern int QueueLA;
95214879Seric 	extern int RefuseLA;
95317474Seric 	extern bool trusteduser();
95417474Seric 	extern char *username();
9558256Seric 
9568256Seric 	if (tTd(37, 1))
9579341Seric 		printf("setoption %c=%s", opt, val);
9588256Seric 
9598256Seric 	/*
9608269Seric 	**  See if this option is preset for us.
9618256Seric 	*/
9628256Seric 
96310687Seric 	if (bitnset(opt, StickyOpt))
9648269Seric 	{
9659341Seric 		if (tTd(37, 1))
9669341Seric 			printf(" (ignored)\n");
9678269Seric 		return;
9688269Seric 	}
9698269Seric 
97021755Seric 	/*
97121755Seric 	**  Check to see if this option can be specified by this user.
97221755Seric 	*/
97321755Seric 
97436238Skarels 	if (!safe && getuid() == 0)
97521755Seric 		safe = TRUE;
97658082Seric 	if (!safe && strchr("bdeEiLmoprsvC8", opt) == NULL)
97721755Seric 	{
97839111Srick 		if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
97921755Seric 		{
98036582Sbostic 			if (tTd(37, 1))
98136582Sbostic 				printf(" (unsafe)");
98236582Sbostic 			if (getuid() != geteuid())
98336582Sbostic 			{
98451210Seric 				if (tTd(37, 1))
98551210Seric 					printf("(Resetting uid)");
98636582Sbostic 				(void) setgid(getgid());
98736582Sbostic 				(void) setuid(getuid());
98836582Sbostic 			}
98921755Seric 		}
99021755Seric 	}
99151210Seric 	if (tTd(37, 1))
99217985Seric 		printf("\n");
9938269Seric 
9948256Seric 	switch (opt)
9958256Seric 	{
99652106Seric 	  case '8':		/* allow eight-bit input */
99752106Seric 		EightBit = atobool(val);
99852106Seric 		break;
99952106Seric 
10008256Seric 	  case 'A':		/* set default alias file */
10019381Seric 		if (val[0] == '\0')
10028269Seric 			AliasFile = "aliases";
10039381Seric 		else
10049381Seric 			AliasFile = newstr(val);
10058256Seric 		break;
10068256Seric 
100717474Seric 	  case 'a':		/* look N minutes for "@:@" in alias file */
100817474Seric 		if (val[0] == '\0')
100917474Seric 			SafeAlias = 5;
101017474Seric 		else
101117474Seric 			SafeAlias = atoi(val);
101217474Seric 		break;
101317474Seric 
101416843Seric 	  case 'B':		/* substitution for blank character */
101516843Seric 		SpaceSub = val[0];
101616843Seric 		if (SpaceSub == '\0')
101716843Seric 			SpaceSub = ' ';
101816843Seric 		break;
101916843Seric 
102058082Seric 	  case 'b':		/* minimum number of blocks free on queue fs */
102158082Seric 		MinBlocksFree = atol(val);
102258082Seric 		break;
102358082Seric 
10249284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
10259381Seric 		NoConnect = atobool(val);
10269284Seric 		break;
10279284Seric 
102851305Seric 	  case 'C':		/* checkpoint every N addresses */
102951305Seric 		CheckpointInterval = atoi(val);
103024944Seric 		break;
103124944Seric 
10329284Seric 	  case 'd':		/* delivery mode */
10339284Seric 		switch (*val)
10348269Seric 		{
10359284Seric 		  case '\0':
10369284Seric 			SendMode = SM_DELIVER;
10378269Seric 			break;
10388269Seric 
103910755Seric 		  case SM_QUEUE:	/* queue only */
104010755Seric #ifndef QUEUE
104110755Seric 			syserr("need QUEUE to set -odqueue");
104256795Seric #endif /* QUEUE */
104310755Seric 			/* fall through..... */
104410755Seric 
10459284Seric 		  case SM_DELIVER:	/* do everything */
10469284Seric 		  case SM_FORK:		/* fork after verification */
10479284Seric 			SendMode = *val;
10488269Seric 			break;
10498269Seric 
10508269Seric 		  default:
10519284Seric 			syserr("Unknown delivery mode %c", *val);
10528269Seric 			exit(EX_USAGE);
10538269Seric 		}
10548269Seric 		break;
10558269Seric 
10569146Seric 	  case 'D':		/* rebuild alias database as needed */
10579381Seric 		AutoRebuild = atobool(val);
10589146Seric 		break;
10599146Seric 
106055372Seric 	  case 'E':		/* error message header/header file */
106155379Seric 		if (*val != '\0')
106255379Seric 			ErrMsgFile = newstr(val);
106355372Seric 		break;
106455372Seric 
10658269Seric 	  case 'e':		/* set error processing mode */
10668269Seric 		switch (*val)
10678269Seric 		{
10689381Seric 		  case EM_QUIET:	/* be silent about it */
10699381Seric 		  case EM_MAIL:		/* mail back */
10709381Seric 		  case EM_BERKNET:	/* do berknet error processing */
10719381Seric 		  case EM_WRITE:	/* write back (or mail) */
10728269Seric 			HoldErrs = TRUE;
10739381Seric 			/* fall through... */
10748269Seric 
10759381Seric 		  case EM_PRINT:	/* print errors normally (default) */
10769381Seric 			ErrorMode = *val;
10778269Seric 			break;
10788269Seric 		}
10798269Seric 		break;
10808269Seric 
10819049Seric 	  case 'F':		/* file mode */
108217975Seric 		FileMode = atooct(val) & 0777;
10839049Seric 		break;
10849049Seric 
10858269Seric 	  case 'f':		/* save Unix-style From lines on front */
10869381Seric 		SaveFrom = atobool(val);
10878269Seric 		break;
10888269Seric 
108953735Seric 	  case 'G':		/* match recipients against GECOS field */
109053735Seric 		MatchGecos = atobool(val);
109153735Seric 		break;
109253735Seric 
10938256Seric 	  case 'g':		/* default gid */
109417474Seric 		DefGid = atoi(val);
10958256Seric 		break;
10968256Seric 
10978256Seric 	  case 'H':		/* help file */
10989381Seric 		if (val[0] == '\0')
10998269Seric 			HelpFile = "sendmail.hf";
11009381Seric 		else
11019381Seric 			HelpFile = newstr(val);
11028256Seric 		break;
11038256Seric 
110451305Seric 	  case 'h':		/* maximum hop count */
110551305Seric 		MaxHopCount = atoi(val);
110651305Seric 		break;
110751305Seric 
110835651Seric 	  case 'I':		/* use internet domain name server */
110957207Seric #ifdef NAMED_BIND
111057207Seric 		UseNameServer = TRUE;
111157207Seric 		for (p = val; *p != 0; )
111257207Seric 		{
111357207Seric 			bool clearmode;
111457207Seric 			char *q;
111557207Seric 			struct resolverflags *rfp;
111657207Seric 
111757207Seric 			while (*p == ' ')
111857207Seric 				p++;
111957207Seric 			if (*p == '\0')
112057207Seric 				break;
112157207Seric 			clearmode = FALSE;
112257207Seric 			if (*p == '-')
112357207Seric 				clearmode = TRUE;
112457207Seric 			else if (*p != '+')
112557207Seric 				p--;
112657207Seric 			p++;
112757207Seric 			q = p;
112858050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
112957207Seric 				p++;
113057207Seric 			if (*p != '\0')
113157207Seric 				*p++ = '\0';
113257207Seric 			for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
113357207Seric 			{
113457207Seric 				if (strcasecmp(q, rfp->rf_name) == 0)
113557207Seric 					break;
113657207Seric 			}
113757207Seric 			if (clearmode)
113857207Seric 				_res.options &= ~rfp->rf_bits;
113957207Seric 			else
114057207Seric 				_res.options |= rfp->rf_bits;
114157207Seric 		}
114257207Seric 		if (tTd(8, 2))
114357207Seric 			printf("_res.options = %x\n", _res.options);
114457207Seric #else
114557207Seric 		usrerr("name server (I option) specified but BIND not compiled in");
114657207Seric #endif
114735651Seric 		break;
114835651Seric 
11498269Seric 	  case 'i':		/* ignore dot lines in message */
11509381Seric 		IgnrDot = atobool(val);
11518269Seric 		break;
11528269Seric 
115357136Seric 	  case 'J':		/* .forward search path */
115457136Seric 		ForwardPath = newstr(val);
115557136Seric 		break;
115657136Seric 
115754967Seric 	  case 'k':		/* connection cache size */
115854967Seric 		MaxMciCache = atoi(val);
115956215Seric 		if (MaxMciCache < 0)
116056215Seric 			MaxMciCache = 0;
116154967Seric 		break;
116254967Seric 
116354967Seric 	  case 'K':		/* connection cache timeout */
116454967Seric 		MciCacheTimeout = convtime(val);
116554967Seric 		break;
116654967Seric 
11678256Seric 	  case 'L':		/* log level */
11689381Seric 		LogLevel = atoi(val);
11698256Seric 		break;
11708256Seric 
11718269Seric 	  case 'M':		/* define macro */
11729381Seric 		define(val[0], newstr(&val[1]), CurEnv);
117316878Seric 		sticky = FALSE;
11748269Seric 		break;
11758269Seric 
11768269Seric 	  case 'm':		/* send to me too */
11779381Seric 		MeToo = atobool(val);
11788269Seric 		break;
11798269Seric 
118025820Seric 	  case 'n':		/* validate RHS in newaliases */
118125820Seric 		CheckAliases = atobool(val);
118225820Seric 		break;
118325820Seric 
11848269Seric 	  case 'o':		/* assume old style headers */
11859381Seric 		if (atobool(val))
11869341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
11879341Seric 		else
11889341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
11898269Seric 		break;
11908269Seric 
119158082Seric 	  case 'p':		/* select privacy level */
119258082Seric 		p = val;
119358082Seric 		for (;;)
119458082Seric 		{
119558082Seric 			register struct prival *pv;
119658082Seric 			extern struct prival PrivacyValues[];
119758082Seric 
119858082Seric 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
119958082Seric 				p++;
120058082Seric 			if (*p == '\0')
120158082Seric 				break;
120258082Seric 			val = p;
120358082Seric 			while (isascii(*p) && isalnum(*p))
120458082Seric 				p++;
120558082Seric 			if (*p != '\0')
120658082Seric 				*p++ = '\0';
120758082Seric 
120858082Seric 			for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
120958082Seric 			{
121058082Seric 				if (strcasecmp(val, pv->pv_name) == 0)
121158082Seric 					break;
121258082Seric 			}
121358082Seric 			PrivacyFlags |= pv->pv_flag;
121458082Seric 		}
121558082Seric 		break;
121658082Seric 
121724944Seric 	  case 'P':		/* postmaster copy address for returned mail */
121824944Seric 		PostMasterCopy = newstr(val);
121924944Seric 		break;
122024944Seric 
122124944Seric 	  case 'q':		/* slope of queue only function */
122224944Seric 		QueueFactor = atoi(val);
122324944Seric 		break;
122424944Seric 
12258256Seric 	  case 'Q':		/* queue directory */
12269381Seric 		if (val[0] == '\0')
12278269Seric 			QueueDir = "mqueue";
12289381Seric 		else
12299381Seric 			QueueDir = newstr(val);
12308256Seric 		break;
12318256Seric 
123258148Seric 	  case 'R':		/* don't prune routes */
123358148Seric 		DontPruneRoutes = atobool(val);
123458148Seric 		break;
123558148Seric 
12368256Seric 	  case 'r':		/* read timeout */
123758112Seric 		settimeouts(val);
12388256Seric 		break;
12398256Seric 
12408256Seric 	  case 'S':		/* status file */
12419381Seric 		if (val[0] == '\0')
12428269Seric 			StatFile = "sendmail.st";
12439381Seric 		else
12449381Seric 			StatFile = newstr(val);
12458256Seric 		break;
12468256Seric 
12478265Seric 	  case 's':		/* be super safe, even if expensive */
12489381Seric 		SuperSafe = atobool(val);
12498256Seric 		break;
12508256Seric 
12518256Seric 	  case 'T':		/* queue timeout */
12529381Seric 		TimeOut = convtime(val);
125354967Seric 		break;
12548256Seric 
12558265Seric 	  case 't':		/* time zone name */
125652106Seric 		TimeZoneSpec = newstr(val);
12578265Seric 		break;
12588265Seric 
125950556Seric 	  case 'U':		/* location of user database */
126051360Seric 		UdbSpec = newstr(val);
126150556Seric 		break;
126250556Seric 
12638256Seric 	  case 'u':		/* set default uid */
126417474Seric 		DefUid = atoi(val);
126540973Sbostic 		setdefuser();
12668256Seric 		break;
12678256Seric 
12688269Seric 	  case 'v':		/* run in verbose mode */
12699381Seric 		Verbose = atobool(val);
12708256Seric 		break;
12718256Seric 
127214879Seric 	  case 'x':		/* load avg at which to auto-queue msgs */
127314879Seric 		QueueLA = atoi(val);
127414879Seric 		break;
127514879Seric 
127614879Seric 	  case 'X':		/* load avg at which to auto-reject connections */
127714879Seric 		RefuseLA = atoi(val);
127814879Seric 		break;
127914879Seric 
128024981Seric 	  case 'y':		/* work recipient factor */
128124981Seric 		WkRecipFact = atoi(val);
128224981Seric 		break;
128324981Seric 
128424981Seric 	  case 'Y':		/* fork jobs during queue runs */
128524952Seric 		ForkQueueRuns = atobool(val);
128624952Seric 		break;
128724952Seric 
128824981Seric 	  case 'z':		/* work message class factor */
128924981Seric 		WkClassFact = atoi(val);
129024981Seric 		break;
129124981Seric 
129224981Seric 	  case 'Z':		/* work time factor */
129324981Seric 		WkTimeFact = atoi(val);
129424981Seric 		break;
129524981Seric 
12968256Seric 	  default:
12978256Seric 		break;
12988256Seric 	}
129916878Seric 	if (sticky)
130016878Seric 		setbitn(opt, StickyOpt);
13019188Seric 	return;
13028256Seric }
130310687Seric /*
130410687Seric **  SETCLASS -- set a word into a class
130510687Seric **
130610687Seric **	Parameters:
130710687Seric **		class -- the class to put the word in.
130810687Seric **		word -- the word to enter
130910687Seric **
131010687Seric **	Returns:
131110687Seric **		none.
131210687Seric **
131310687Seric **	Side Effects:
131410687Seric **		puts the word into the symbol table.
131510687Seric */
131610687Seric 
131710687Seric setclass(class, word)
131810687Seric 	int class;
131910687Seric 	char *word;
132010687Seric {
132110687Seric 	register STAB *s;
132210687Seric 
132357943Seric 	if (tTd(37, 8))
132457943Seric 		printf("%s added to class %c\n", word, class);
132510687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
132610687Seric 	setbitn(class, s->s_class);
132710687Seric }
132853654Seric /*
132953654Seric **  MAKEMAPENTRY -- create a map entry
133053654Seric **
133153654Seric **	Parameters:
133253654Seric **		line -- the config file line
133353654Seric **
133453654Seric **	Returns:
133553654Seric **		TRUE if it successfully entered the map entry.
133653654Seric **		FALSE otherwise (usually syntax error).
133753654Seric **
133853654Seric **	Side Effects:
133953654Seric **		Enters the map into the dictionary.
134053654Seric */
134153654Seric 
134253654Seric void
134353654Seric makemapentry(line)
134453654Seric 	char *line;
134553654Seric {
134653654Seric 	register char *p;
134753654Seric 	char *mapname;
134853654Seric 	char *classname;
134953654Seric 	register STAB *map;
135053654Seric 	STAB *class;
135153654Seric 
135258050Seric 	for (p = line; isascii(*p) && isspace(*p); p++)
135353654Seric 		continue;
135458050Seric 	if (!(isascii(*p) && isalnum(*p)))
135553654Seric 	{
135653654Seric 		syserr("readcf: config K line: no map name");
135753654Seric 		return;
135853654Seric 	}
135953654Seric 
136053654Seric 	mapname = p;
136158050Seric 	while (isascii(*++p) && isalnum(*p))
136253654Seric 		continue;
136353654Seric 	if (*p != '\0')
136453654Seric 		*p++ = '\0';
136558050Seric 	while (isascii(*p) && isspace(*p))
136653654Seric 		p++;
136758050Seric 	if (!(isascii(*p) && isalnum(*p)))
136853654Seric 	{
136953654Seric 		syserr("readcf: config K line, map %s: no map class", mapname);
137053654Seric 		return;
137153654Seric 	}
137253654Seric 	classname = p;
137358050Seric 	while (isascii(*++p) && isalnum(*p))
137453654Seric 		continue;
137553654Seric 	if (*p != '\0')
137653654Seric 		*p++ = '\0';
137758050Seric 	while (isascii(*p) && isspace(*p))
137853654Seric 		p++;
137953654Seric 
138053654Seric 	/* look up the class */
138153654Seric 	class = stab(classname, ST_MAPCLASS, ST_FIND);
138253654Seric 	if (class == NULL)
138353654Seric 	{
138453654Seric 		syserr("readcf: map %s: class %s not available", mapname, classname);
138553654Seric 		return;
138653654Seric 	}
138753654Seric 
138853654Seric 	/* enter the map */
138953654Seric 	map = stab(mapname, ST_MAP, ST_ENTER);
139053654Seric 	map->s_map.map_class = &class->s_mapclass;
139153654Seric 
139256823Seric 	if ((*class->s_mapclass.map_init)(&map->s_map, mapname, p))
139353654Seric 		map->s_map.map_flags |= MF_VALID;
139453654Seric }
139558112Seric /*
139658112Seric **  SETTIMEOUTS -- parse and set timeout values
139758112Seric **
139858112Seric **	Parameters:
139958112Seric **		val -- a pointer to the values.  If NULL, do initial
140058112Seric **			settings.
140158112Seric **
140258112Seric **	Returns:
140358112Seric **		none.
140458112Seric **
140558112Seric **	Side Effects:
140658112Seric **		Initializes the TimeOuts structure
140758112Seric */
140858112Seric 
140958112Seric #define MINUTES	* 60
141058112Seric #define HOUR	* 3600
141158112Seric 
141258112Seric settimeouts(val)
141358112Seric 	register char *val;
141458112Seric {
141558112Seric 	register char *p;
141658112Seric 
141758112Seric 	if (val == NULL)
141858112Seric 	{
141958112Seric 		TimeOuts.to_initial = (time_t) 5 MINUTES;
142058112Seric 		TimeOuts.to_helo = (time_t) 5 MINUTES;
142158112Seric 		TimeOuts.to_mail = (time_t) 10 MINUTES;
142258112Seric 		TimeOuts.to_rcpt = (time_t) 1 HOUR;
142358112Seric 		TimeOuts.to_datainit = (time_t) 5 MINUTES;
142458112Seric 		TimeOuts.to_datablock = (time_t) 1 HOUR;
142558112Seric 		TimeOuts.to_datafinal = (time_t) 1 HOUR;
142658112Seric 		TimeOuts.to_rset = (time_t) 5 MINUTES;
142758112Seric 		TimeOuts.to_quit = (time_t) 2 MINUTES;
142858112Seric 		TimeOuts.to_nextcommand = (time_t) 1 HOUR;
142958112Seric 		TimeOuts.to_miscshort = (time_t) 2 MINUTES;
143058112Seric 		return;
143158112Seric 	}
143258112Seric 
143358112Seric 	for (;; val = p)
143458112Seric 	{
143558112Seric 		while (isascii(*val) && isspace(*val))
143658112Seric 			val++;
143758112Seric 		if (*val == '\0')
143858112Seric 			break;
143958112Seric 		for (p = val; *p != '\0' && *p != ','; p++)
144058112Seric 			continue;
144158112Seric 		if (*p != '\0')
144258112Seric 			*p++ = '\0';
144358112Seric 
144458112Seric 		if (isascii(*val) && isdigit(*val))
144558112Seric 		{
144658112Seric 			/* old syntax -- set everything */
144758112Seric 			TimeOuts.to_mail = convtime(val);
144858112Seric 			TimeOuts.to_rcpt = TimeOuts.to_mail;
144958112Seric 			TimeOuts.to_datainit = TimeOuts.to_mail;
145058112Seric 			TimeOuts.to_datablock = TimeOuts.to_mail;
145158112Seric 			TimeOuts.to_datafinal = TimeOuts.to_mail;
145258112Seric 			TimeOuts.to_nextcommand = TimeOuts.to_mail;
145358112Seric 			continue;
145458112Seric 		}
145558112Seric 		else
145658112Seric 		{
145758112Seric 			register char *q = strchr(val, '=');
145858112Seric 			time_t to;
145958112Seric 
146058112Seric 			if (q == NULL)
146158112Seric 			{
146258112Seric 				/* syntax error */
146358112Seric 				continue;
146458112Seric 			}
146558112Seric 			*q++ = '\0';
146658112Seric 			to = convtime(q);
146758112Seric 
146858112Seric 			if (strcasecmp(val, "initial") == 0)
146958112Seric 				TimeOuts.to_initial = to;
147058112Seric 			else if (strcasecmp(val, "mail") == 0)
147158112Seric 				TimeOuts.to_mail = to;
147258112Seric 			else if (strcasecmp(val, "rcpt") == 0)
147358112Seric 				TimeOuts.to_rcpt = to;
147458112Seric 			else if (strcasecmp(val, "datainit") == 0)
147558112Seric 				TimeOuts.to_datainit = to;
147658112Seric 			else if (strcasecmp(val, "datablock") == 0)
147758112Seric 				TimeOuts.to_datablock = to;
147858112Seric 			else if (strcasecmp(val, "datafinal") == 0)
147958112Seric 				TimeOuts.to_datafinal = to;
148058112Seric 			else if (strcasecmp(val, "command") == 0)
148158112Seric 				TimeOuts.to_nextcommand = to;
148258112Seric 			else if (strcasecmp(val, "rset") == 0)
148358112Seric 				TimeOuts.to_rset = to;
148458112Seric 			else if (strcasecmp(val, "helo") == 0)
148558112Seric 				TimeOuts.to_helo = to;
148658112Seric 			else if (strcasecmp(val, "quit") == 0)
148758112Seric 				TimeOuts.to_quit = to;
148858112Seric 			else if (strcasecmp(val, "misc") == 0)
148958112Seric 				TimeOuts.to_miscshort = to;
149058112Seric 			else
149158112Seric 				syserr("settimeouts: invalid timeout %s", val);
149258112Seric 		}
149358112Seric 	}
149458112Seric }
1495