xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 58161)
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*58161Seric static char sccsid[] = "@(#)readcf.c	6.12 (Berkeley) 02/23/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:
24357589Seric 						nfuzzy++;
24458148Seric 						break;
24558148Seric 
24658148Seric 					  case MATCHREPL:
24758148Seric 						botch = "$0-$9";
24858148Seric 						break;
24958148Seric 
25058148Seric 					  case CANONNET:
25158148Seric 						botch = "$#";
25258148Seric 						break;
25358148Seric 
25458148Seric 					  case CANONHOST:
25558148Seric 						botch = "$@";
25658148Seric 						break;
25758148Seric 
25858148Seric 					  case CANONUSER:
25958148Seric 						botch = "$:";
26058148Seric 						break;
26158148Seric 
26258148Seric 					  case CALLSUBR:
26358148Seric 						botch = "$>";
26458148Seric 						break;
26558148Seric 
26658148Seric 					  case CONDIF:
26758148Seric 						botch = "$?";
26858148Seric 						break;
26958148Seric 
27058148Seric 					  case CONDELSE:
27158148Seric 						botch = "$|";
27258148Seric 						break;
27358148Seric 
27458148Seric 					  case CONDFI:
27558148Seric 						botch = "$.";
27658148Seric 						break;
27758148Seric 
27858148Seric 					  case HOSTBEGIN:
27958148Seric 						botch = "$[";
28058148Seric 						break;
28158148Seric 
28258148Seric 					  case HOSTEND:
28358148Seric 						botch = "$]";
28458148Seric 						break;
28558148Seric 
28658148Seric 					  case LOOKUPBEGIN:
28758148Seric 						botch = "$(";
28858148Seric 						break;
28958148Seric 
29058148Seric 					  case LOOKUPEND:
29158148Seric 						botch = "$)";
29258148Seric 						break;
29357589Seric 					}
29458148Seric 					if (botch != NULL)
29558148Seric 						syserr("Inappropriate use of %s on LHS",
29658148Seric 							botch);
29757589Seric 				}
29857589Seric 			}
29956678Seric 			else
30056678Seric 				syserr("R line: null LHS");
3015909Seric 
3025909Seric 			/* expand and save the RHS */
3035909Seric 			while (*++p == '\t')
3045909Seric 				continue;
3057231Seric 			q = p;
3067231Seric 			while (*p != '\0' && *p != '\t')
3077231Seric 				p++;
3087231Seric 			*p = '\0';
30955012Seric 			expand(q, exbuf, &exbuf[sizeof exbuf], e);
31016915Seric 			rwp->r_rhs = prescan(exbuf, '\t', pvpbuf);
3115909Seric 			if (rwp->r_rhs != NULL)
31257589Seric 			{
31357589Seric 				register char **ap;
31457589Seric 
3155909Seric 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
31657589Seric 
31757589Seric 				/* check no out-of-bounds replacements */
31857589Seric 				nfuzzy += '0';
31957589Seric 				for (ap = rwp->r_rhs; *ap != NULL; ap++)
32057589Seric 				{
32158148Seric 					char *botch;
32258148Seric 
32358148Seric 					botch = NULL;
32458148Seric 					switch (**ap & 0377)
32557589Seric 					{
32658148Seric 					  case MATCHREPL:
32758148Seric 						if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy)
32858148Seric 						{
32958148Seric 							syserr("replacement $%c out of bounds",
33058148Seric 								(*ap)[1]);
33158148Seric 						}
33258148Seric 						break;
33358148Seric 
33458148Seric 					  case MATCHZANY:
33558148Seric 						botch = "$*";
33658148Seric 						break;
33758148Seric 
33858148Seric 					  case MATCHANY:
33958148Seric 						botch = "$+";
34058148Seric 						break;
34158148Seric 
34258148Seric 					  case MATCHONE:
34358148Seric 						botch = "$-";
34458148Seric 						break;
34558148Seric 
34658148Seric 					  case MATCHCLASS:
34758148Seric 						botch = "$=";
34858148Seric 						break;
34958148Seric 
35058148Seric 					  case MATCHNCLASS:
35158148Seric 						botch = "$~";
35258148Seric 						break;
35357589Seric 					}
35458148Seric 					if (botch != NULL)
35558148Seric 						syserr("Inappropriate use of %s on RHS",
35658148Seric 							botch);
35757589Seric 				}
35857589Seric 			}
35956678Seric 			else
36056678Seric 				syserr("R line: null RHS");
3613308Seric 			break;
3623308Seric 
3634072Seric 		  case 'S':		/* select rewriting set */
36457135Seric 			ruleset = atoi(&bp[1]);
3658056Seric 			if (ruleset >= MAXRWSETS || ruleset < 0)
3668056Seric 			{
3679381Seric 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
3688056Seric 				ruleset = 0;
3698056Seric 			}
3704072Seric 			rwp = NULL;
3714072Seric 			break;
3724072Seric 
3733308Seric 		  case 'D':		/* macro definition */
37457135Seric 			define(bp[1], newstr(munchstring(&bp[2])), e);
3753308Seric 			break;
3763308Seric 
3773387Seric 		  case 'H':		/* required header line */
37857135Seric 			(void) chompheader(&bp[1], TRUE, e);
3793387Seric 			break;
3803387Seric 
3814061Seric 		  case 'C':		/* word class */
3824432Seric 		  case 'F':		/* word class from file */
3834432Seric 			/* read list of words from argument or file */
38457135Seric 			if (bp[0] == 'F')
3854432Seric 			{
3864432Seric 				/* read from file */
38758050Seric 				for (p = &bp[2];
38858050Seric 				     *p != '\0' && !(isascii(*p) && isspace(*p));
38958050Seric 				     p++)
3904432Seric 					continue;
3914432Seric 				if (*p == '\0')
3924432Seric 					p = "%s";
3934432Seric 				else
3944432Seric 				{
3954432Seric 					*p = '\0';
39658050Seric 					while (isascii(*++p) && isspace(*p))
3974432Seric 						continue;
3984432Seric 				}
39957135Seric 				fileclass(bp[1], &bp[2], p, safe);
4004432Seric 				break;
4014432Seric 			}
4024061Seric 
4034432Seric 			/* scan the list of words and set class for all */
40457135Seric 			for (p = &bp[2]; *p != '\0'; )
4054061Seric 			{
4064061Seric 				register char *wd;
4074061Seric 				char delim;
4084061Seric 
40958050Seric 				while (*p != '\0' && isascii(*p) && isspace(*p))
4104061Seric 					p++;
4114061Seric 				wd = p;
41258050Seric 				while (*p != '\0' && !(isascii(*p) && isspace(*p)))
4134061Seric 					p++;
4144061Seric 				delim = *p;
4154061Seric 				*p = '\0';
4164061Seric 				if (wd[0] != '\0')
41758148Seric 				{
41858148Seric 					if (tTd(37, 2))
41958148Seric 						printf("setclass(%c, %s)\n",
42058148Seric 							bp[1], wd);
42157135Seric 					setclass(bp[1], wd);
42258148Seric 				}
4234061Seric 				*p = delim;
4244061Seric 			}
4254061Seric 			break;
4264061Seric 
4274096Seric 		  case 'M':		/* define mailer */
42857135Seric 			makemailer(&bp[1]);
4294096Seric 			break;
4304096Seric 
4318252Seric 		  case 'O':		/* set option */
43257135Seric 			setoption(bp[1], &bp[2], safe, FALSE);
4338252Seric 			break;
4348252Seric 
4358252Seric 		  case 'P':		/* set precedence */
4368252Seric 			if (NumPriorities >= MAXPRIORITIES)
4378252Seric 			{
4388547Seric 				toomany('P', MAXPRIORITIES);
4398252Seric 				break;
4408252Seric 			}
44157135Seric 			for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
4428252Seric 				continue;
4438252Seric 			if (*p == '\0')
4448252Seric 				goto badline;
4458252Seric 			*p = '\0';
44657135Seric 			Priorities[NumPriorities].pri_name = newstr(&bp[1]);
4478252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
4488252Seric 			NumPriorities++;
4498252Seric 			break;
4508252Seric 
4518547Seric 		  case 'T':		/* trusted user(s) */
452*58161Seric 			/* this option is obsolete, but will be ignored */
4538547Seric 			break;
4548547Seric 
45552645Seric 		  case 'V':		/* configuration syntax version */
45657135Seric 			ConfigLevel = atoi(&bp[1]);
45752645Seric 			break;
45852645Seric 
45953654Seric 		  case 'K':
46057135Seric 			makemapentry(&bp[1]);
46153654Seric 			break;
46253654Seric 
4633308Seric 		  default:
4644061Seric 		  badline:
46557135Seric 			syserr("unknown control line \"%s\"", bp);
4663308Seric 		}
46757135Seric 		if (bp != buf)
46857135Seric 			free(bp);
4693308Seric 	}
47052637Seric 	if (ferror(cf))
47152637Seric 	{
47252647Seric 		syserr("I/O read error", cfname);
47352637Seric 		exit(EX_OSFILE);
47452637Seric 	}
47552637Seric 	fclose(cf);
4769381Seric 	FileName = NULL;
47756836Seric 
47857076Seric 	if (stab("host", ST_MAP, ST_FIND) == NULL)
47957076Seric 	{
48057076Seric 		/* user didn't initialize: set up host map */
48157076Seric 		strcpy(buf, "host host");
48257076Seric 		if (ConfigLevel >= 2)
48357076Seric 			strcat(buf, " -a.");
48457076Seric 		makemapentry(buf);
48557076Seric 	}
4864096Seric }
4874096Seric /*
4888547Seric **  TOOMANY -- signal too many of some option
4898547Seric **
4908547Seric **	Parameters:
4918547Seric **		id -- the id of the error line
4928547Seric **		maxcnt -- the maximum possible values
4938547Seric **
4948547Seric **	Returns:
4958547Seric **		none.
4968547Seric **
4978547Seric **	Side Effects:
4988547Seric **		gives a syserr.
4998547Seric */
5008547Seric 
5018547Seric toomany(id, maxcnt)
5028547Seric 	char id;
5038547Seric 	int maxcnt;
5048547Seric {
5059381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
5068547Seric }
5078547Seric /*
5084432Seric **  FILECLASS -- read members of a class from a file
5094432Seric **
5104432Seric **	Parameters:
5114432Seric **		class -- class to define.
5124432Seric **		filename -- name of file to read.
5134432Seric **		fmt -- scanf string to use for match.
5144432Seric **
5154432Seric **	Returns:
5164432Seric **		none
5174432Seric **
5184432Seric **	Side Effects:
5194432Seric **
5204432Seric **		puts all lines in filename that match a scanf into
5214432Seric **			the named class.
5224432Seric */
5234432Seric 
52454973Seric fileclass(class, filename, fmt, safe)
5254432Seric 	int class;
5264432Seric 	char *filename;
5274432Seric 	char *fmt;
52854973Seric 	bool safe;
5294432Seric {
53025808Seric 	FILE *f;
53154973Seric 	struct stat stbuf;
5324432Seric 	char buf[MAXLINE];
5334432Seric 
53454973Seric 	if (stat(filename, &stbuf) < 0)
53554973Seric 	{
53654973Seric 		syserr("fileclass: cannot stat %s", filename);
53754973Seric 		return;
53854973Seric 	}
53954973Seric 	if (!S_ISREG(stbuf.st_mode))
54054973Seric 	{
54154973Seric 		syserr("fileclass: %s not a regular file", filename);
54254973Seric 		return;
54354973Seric 	}
54454973Seric 	if (!safe && access(filename, R_OK) < 0)
54554973Seric 	{
54654973Seric 		syserr("fileclass: access denied on %s", filename);
54754973Seric 		return;
54854973Seric 	}
54954973Seric 	f = fopen(filename, "r");
5504432Seric 	if (f == NULL)
5514432Seric 	{
55254973Seric 		syserr("fileclass: cannot open %s", filename);
5534432Seric 		return;
5544432Seric 	}
5554432Seric 
5564432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
5574432Seric 	{
5584432Seric 		register STAB *s;
55925808Seric 		register char *p;
56025808Seric # ifdef SCANF
5614432Seric 		char wordbuf[MAXNAME+1];
5624432Seric 
5634432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
5644432Seric 			continue;
56525808Seric 		p = wordbuf;
56656795Seric # else /* SCANF */
56725808Seric 		p = buf;
56856795Seric # endif /* SCANF */
56925808Seric 
57025808Seric 		/*
57125808Seric 		**  Break up the match into words.
57225808Seric 		*/
57325808Seric 
57425808Seric 		while (*p != '\0')
57525808Seric 		{
57625808Seric 			register char *q;
57725808Seric 
57825808Seric 			/* strip leading spaces */
57958050Seric 			while (isascii(*p) && isspace(*p))
58025808Seric 				p++;
58125808Seric 			if (*p == '\0')
58225808Seric 				break;
58325808Seric 
58425808Seric 			/* find the end of the word */
58525808Seric 			q = p;
58658050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
58725808Seric 				p++;
58825808Seric 			if (*p != '\0')
58925808Seric 				*p++ = '\0';
59025808Seric 
59125808Seric 			/* enter the word in the symbol table */
59225808Seric 			s = stab(q, ST_CLASS, ST_ENTER);
59325808Seric 			setbitn(class, s->s_class);
59425808Seric 		}
5954432Seric 	}
5964432Seric 
59754973Seric 	(void) fclose(f);
5984432Seric }
5994432Seric /*
6004096Seric **  MAKEMAILER -- define a new mailer.
6014096Seric **
6024096Seric **	Parameters:
60310327Seric **		line -- description of mailer.  This is in labeled
60410327Seric **			fields.  The fields are:
60510327Seric **			   P -- the path to the mailer
60610327Seric **			   F -- the flags associated with the mailer
60710327Seric **			   A -- the argv for this mailer
60810327Seric **			   S -- the sender rewriting set
60910327Seric **			   R -- the recipient rewriting set
61010327Seric **			   E -- the eol string
61110327Seric **			The first word is the canonical name of the mailer.
6124096Seric **
6134096Seric **	Returns:
6144096Seric **		none.
6154096Seric **
6164096Seric **	Side Effects:
6174096Seric **		enters the mailer into the mailer table.
6184096Seric */
6193308Seric 
62021066Seric makemailer(line)
6214096Seric 	char *line;
6224096Seric {
6234096Seric 	register char *p;
6248067Seric 	register struct mailer *m;
6258067Seric 	register STAB *s;
6268067Seric 	int i;
62710327Seric 	char fcode;
62858020Seric 	auto char *endp;
6294096Seric 	extern int NextMailer;
63010327Seric 	extern char **makeargv();
63110327Seric 	extern char *munchstring();
63210327Seric 	extern char *DelimChar;
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 	{
65058050Seric 		while (*p != '\0' && (*p == ',' || (isascii(*p) && isspace(*p))))
65110327Seric 			p++;
65210327Seric 
65310327Seric 		/* p now points to field code */
65410327Seric 		fcode = *p;
65510327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
65610327Seric 			p++;
65710327Seric 		if (*p++ != '=')
65810327Seric 		{
65952637Seric 			syserr("mailer %s: `=' expected", m->m_name);
66010327Seric 			return;
66110327Seric 		}
66258050Seric 		while (isascii(*p) && isspace(*p))
66310327Seric 			p++;
66410327Seric 
66510327Seric 		/* p now points to the field body */
66610327Seric 		p = munchstring(p);
66710327Seric 
66810327Seric 		/* install the field into the mailer struct */
66910327Seric 		switch (fcode)
67010327Seric 		{
67110327Seric 		  case 'P':		/* pathname */
67210327Seric 			m->m_mailer = newstr(p);
67310327Seric 			break;
67410327Seric 
67510327Seric 		  case 'F':		/* flags */
67610687Seric 			for (; *p != '\0'; p++)
67758050Seric 				if (!(isascii(*p) && isspace(*p)))
67852637Seric 					setbitn(*p, m->m_flags);
67910327Seric 			break;
68010327Seric 
68110327Seric 		  case 'S':		/* sender rewriting ruleset */
68210327Seric 		  case 'R':		/* recipient rewriting ruleset */
68358020Seric 			i = strtol(p, &endp, 10);
68410327Seric 			if (i < 0 || i >= MAXRWSETS)
68510327Seric 			{
68610327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
68710327Seric 				return;
68810327Seric 			}
68910327Seric 			if (fcode == 'S')
69058020Seric 				m->m_sh_rwset = m->m_se_rwset = i;
69110327Seric 			else
69258020Seric 				m->m_rh_rwset = m->m_re_rwset = i;
69358020Seric 
69458020Seric 			p = endp;
69558020Seric 			if (*p == '/')
69658020Seric 			{
69758020Seric 				i = strtol(p, NULL, 10);
69858020Seric 				if (i < 0 || i >= MAXRWSETS)
69958020Seric 				{
70058020Seric 					syserr("invalid rewrite set, %d max",
70158020Seric 						MAXRWSETS);
70258020Seric 					return;
70358020Seric 				}
70458020Seric 				if (fcode == 'S')
70558020Seric 					m->m_sh_rwset = i;
70658020Seric 				else
70758020Seric 					m->m_rh_rwset = i;
70858020Seric 			}
70910327Seric 			break;
71010327Seric 
71110327Seric 		  case 'E':		/* end of line string */
71210327Seric 			m->m_eol = newstr(p);
71310327Seric 			break;
71410327Seric 
71510327Seric 		  case 'A':		/* argument vector */
71610327Seric 			m->m_argv = makeargv(p);
71710327Seric 			break;
71810701Seric 
71910701Seric 		  case 'M':		/* maximum message size */
72010701Seric 			m->m_maxsize = atol(p);
72110701Seric 			break;
72252106Seric 
72352106Seric 		  case 'L':		/* maximum line length */
72452106Seric 			m->m_linelimit = atoi(p);
72552106Seric 			break;
72610327Seric 		}
72710327Seric 
72810327Seric 		p = DelimChar;
72910327Seric 	}
73010327Seric 
73152106Seric 	/* do some heuristic cleanup for back compatibility */
73252106Seric 	if (bitnset(M_LIMITS, m->m_flags))
73352106Seric 	{
73452106Seric 		if (m->m_linelimit == 0)
73552106Seric 			m->m_linelimit = SMTPLINELIM;
73655418Seric 		if (ConfigLevel < 2)
73752106Seric 			setbitn(M_7BITS, m->m_flags);
73852106Seric 	}
73952106Seric 
7404096Seric 	if (NextMailer >= MAXMAILERS)
7414096Seric 	{
7429381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
7434096Seric 		return;
7444096Seric 	}
74557402Seric 
74610327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
74757402Seric 	if (s->s_mailer != NULL)
74857402Seric 	{
74957402Seric 		i = s->s_mailer->m_mno;
75057402Seric 		free(s->s_mailer);
75157402Seric 	}
75257402Seric 	else
75357402Seric 	{
75457402Seric 		i = NextMailer++;
75557402Seric 	}
75657402Seric 	Mailer[i] = s->s_mailer = m;
75757454Seric 	m->m_mno = i;
75810327Seric }
75910327Seric /*
76010327Seric **  MUNCHSTRING -- translate a string into internal form.
76110327Seric **
76210327Seric **	Parameters:
76310327Seric **		p -- the string to munch.
76410327Seric **
76510327Seric **	Returns:
76610327Seric **		the munched string.
76710327Seric **
76810327Seric **	Side Effects:
76910327Seric **		Sets "DelimChar" to point to the string that caused us
77010327Seric **		to stop.
77110327Seric */
7724096Seric 
77310327Seric char *
77410327Seric munchstring(p)
77510327Seric 	register char *p;
77610327Seric {
77710327Seric 	register char *q;
77810327Seric 	bool backslash = FALSE;
77910327Seric 	bool quotemode = FALSE;
78010327Seric 	static char buf[MAXLINE];
78110327Seric 	extern char *DelimChar;
7824096Seric 
78310327Seric 	for (q = buf; *p != '\0'; p++)
7844096Seric 	{
78510327Seric 		if (backslash)
78610327Seric 		{
78710327Seric 			/* everything is roughly literal */
78810357Seric 			backslash = FALSE;
78910327Seric 			switch (*p)
79010327Seric 			{
79110327Seric 			  case 'r':		/* carriage return */
79210327Seric 				*q++ = '\r';
79310327Seric 				continue;
79410327Seric 
79510327Seric 			  case 'n':		/* newline */
79610327Seric 				*q++ = '\n';
79710327Seric 				continue;
79810327Seric 
79910327Seric 			  case 'f':		/* form feed */
80010327Seric 				*q++ = '\f';
80110327Seric 				continue;
80210327Seric 
80310327Seric 			  case 'b':		/* backspace */
80410327Seric 				*q++ = '\b';
80510327Seric 				continue;
80610327Seric 			}
80710327Seric 			*q++ = *p;
80810327Seric 		}
80910327Seric 		else
81010327Seric 		{
81110327Seric 			if (*p == '\\')
81210327Seric 				backslash = TRUE;
81310327Seric 			else if (*p == '"')
81410327Seric 				quotemode = !quotemode;
81510327Seric 			else if (quotemode || *p != ',')
81610327Seric 				*q++ = *p;
81710327Seric 			else
81810327Seric 				break;
81910327Seric 		}
8204096Seric 	}
8214096Seric 
82210327Seric 	DelimChar = p;
82310327Seric 	*q++ = '\0';
82410327Seric 	return (buf);
82510327Seric }
82610327Seric /*
82710327Seric **  MAKEARGV -- break up a string into words
82810327Seric **
82910327Seric **	Parameters:
83010327Seric **		p -- the string to break up.
83110327Seric **
83210327Seric **	Returns:
83310327Seric **		a char **argv (dynamically allocated)
83410327Seric **
83510327Seric **	Side Effects:
83610327Seric **		munges p.
83710327Seric */
8384096Seric 
83910327Seric char **
84010327Seric makeargv(p)
84110327Seric 	register char *p;
84210327Seric {
84310327Seric 	char *q;
84410327Seric 	int i;
84510327Seric 	char **avp;
84610327Seric 	char *argv[MAXPV + 1];
84710327Seric 
84810327Seric 	/* take apart the words */
84910327Seric 	i = 0;
85010327Seric 	while (*p != '\0' && i < MAXPV)
8514096Seric 	{
85210327Seric 		q = p;
85358050Seric 		while (*p != '\0' && !(isascii(*p) && isspace(*p)))
85410327Seric 			p++;
85558050Seric 		while (isascii(*p) && isspace(*p))
85610327Seric 			*p++ = '\0';
85710327Seric 		argv[i++] = newstr(q);
8584096Seric 	}
85910327Seric 	argv[i++] = NULL;
8604096Seric 
86110327Seric 	/* now make a copy of the argv */
86210327Seric 	avp = (char **) xalloc(sizeof *avp * i);
86316893Seric 	bcopy((char *) argv, (char *) avp, sizeof *avp * i);
86410327Seric 
86510327Seric 	return (avp);
8663308Seric }
8673308Seric /*
8683308Seric **  PRINTRULES -- print rewrite rules (for debugging)
8693308Seric **
8703308Seric **	Parameters:
8713308Seric **		none.
8723308Seric **
8733308Seric **	Returns:
8743308Seric **		none.
8753308Seric **
8763308Seric **	Side Effects:
8773308Seric **		prints rewrite rules.
8783308Seric */
8793308Seric 
8803308Seric printrules()
8813308Seric {
8823308Seric 	register struct rewrite *rwp;
8834072Seric 	register int ruleset;
8843308Seric 
8854072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
8863308Seric 	{
8874072Seric 		if (RewriteRules[ruleset] == NULL)
8884072Seric 			continue;
8898067Seric 		printf("\n----Rule Set %d:", ruleset);
8903308Seric 
8914072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
8923308Seric 		{
8938067Seric 			printf("\nLHS:");
8948067Seric 			printav(rwp->r_lhs);
8958067Seric 			printf("RHS:");
8968067Seric 			printav(rwp->r_rhs);
8973308Seric 		}
8983308Seric 	}
8993308Seric }
9004319Seric 
9014096Seric /*
9028256Seric **  SETOPTION -- set global processing option
9038256Seric **
9048256Seric **	Parameters:
9058256Seric **		opt -- option name.
9068256Seric **		val -- option value (as a text string).
90721755Seric **		safe -- set if this came from a configuration file.
90821755Seric **			Some options (if set from the command line) will
90921755Seric **			reset the user id to avoid security problems.
9108269Seric **		sticky -- if set, don't let other setoptions override
9118269Seric **			this value.
9128256Seric **
9138256Seric **	Returns:
9148256Seric **		none.
9158256Seric **
9168256Seric **	Side Effects:
9178256Seric **		Sets options as implied by the arguments.
9188256Seric */
9198256Seric 
92010687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
9218269Seric 
92257207Seric 
92357207Seric #ifdef NAMED_BIND
92457207Seric 
92557207Seric struct resolverflags
92657207Seric {
92757207Seric 	char	*rf_name;	/* name of the flag */
92857207Seric 	long	rf_bits;	/* bits to set/clear */
92957207Seric } ResolverFlags[] =
93057207Seric {
93157207Seric 	"debug",	RES_DEBUG,
93257207Seric 	"aaonly",	RES_AAONLY,
93357207Seric 	"usevc",	RES_USEVC,
93457207Seric 	"primary",	RES_PRIMARY,
93557207Seric 	"igntc",	RES_IGNTC,
93657207Seric 	"recurse",	RES_RECURSE,
93757207Seric 	"defnames",	RES_DEFNAMES,
93857207Seric 	"stayopen",	RES_STAYOPEN,
93957207Seric 	"dnsrch",	RES_DNSRCH,
94057207Seric 	NULL,		0
94157207Seric };
94257207Seric 
94357207Seric #endif
94457207Seric 
94521755Seric setoption(opt, val, safe, sticky)
9468256Seric 	char opt;
9478256Seric 	char *val;
94821755Seric 	bool safe;
9498269Seric 	bool sticky;
9508256Seric {
95157207Seric 	register char *p;
9528265Seric 	extern bool atobool();
95312633Seric 	extern time_t convtime();
95414879Seric 	extern int QueueLA;
95514879Seric 	extern int RefuseLA;
95617474Seric 	extern bool trusteduser();
95717474Seric 	extern char *username();
9588256Seric 
9598256Seric 	if (tTd(37, 1))
9609341Seric 		printf("setoption %c=%s", opt, val);
9618256Seric 
9628256Seric 	/*
9638269Seric 	**  See if this option is preset for us.
9648256Seric 	*/
9658256Seric 
96610687Seric 	if (bitnset(opt, StickyOpt))
9678269Seric 	{
9689341Seric 		if (tTd(37, 1))
9699341Seric 			printf(" (ignored)\n");
9708269Seric 		return;
9718269Seric 	}
9728269Seric 
97321755Seric 	/*
97421755Seric 	**  Check to see if this option can be specified by this user.
97521755Seric 	*/
97621755Seric 
97736238Skarels 	if (!safe && getuid() == 0)
97821755Seric 		safe = TRUE;
97958082Seric 	if (!safe && strchr("bdeEiLmoprsvC8", opt) == NULL)
98021755Seric 	{
98139111Srick 		if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
98221755Seric 		{
98336582Sbostic 			if (tTd(37, 1))
98436582Sbostic 				printf(" (unsafe)");
98536582Sbostic 			if (getuid() != geteuid())
98636582Sbostic 			{
98751210Seric 				if (tTd(37, 1))
98851210Seric 					printf("(Resetting uid)");
98936582Sbostic 				(void) setgid(getgid());
99036582Sbostic 				(void) setuid(getuid());
99136582Sbostic 			}
99221755Seric 		}
99321755Seric 	}
99451210Seric 	if (tTd(37, 1))
99517985Seric 		printf("\n");
9968269Seric 
9978256Seric 	switch (opt)
9988256Seric 	{
99952106Seric 	  case '8':		/* allow eight-bit input */
100052106Seric 		EightBit = atobool(val);
100152106Seric 		break;
100252106Seric 
10038256Seric 	  case 'A':		/* set default alias file */
10049381Seric 		if (val[0] == '\0')
10058269Seric 			AliasFile = "aliases";
10069381Seric 		else
10079381Seric 			AliasFile = newstr(val);
10088256Seric 		break;
10098256Seric 
101017474Seric 	  case 'a':		/* look N minutes for "@:@" in alias file */
101117474Seric 		if (val[0] == '\0')
101217474Seric 			SafeAlias = 5;
101317474Seric 		else
101417474Seric 			SafeAlias = atoi(val);
101517474Seric 		break;
101617474Seric 
101716843Seric 	  case 'B':		/* substitution for blank character */
101816843Seric 		SpaceSub = val[0];
101916843Seric 		if (SpaceSub == '\0')
102016843Seric 			SpaceSub = ' ';
102116843Seric 		break;
102216843Seric 
102358082Seric 	  case 'b':		/* minimum number of blocks free on queue fs */
102458082Seric 		MinBlocksFree = atol(val);
102558082Seric 		break;
102658082Seric 
10279284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
10289381Seric 		NoConnect = atobool(val);
10299284Seric 		break;
10309284Seric 
103151305Seric 	  case 'C':		/* checkpoint every N addresses */
103251305Seric 		CheckpointInterval = atoi(val);
103324944Seric 		break;
103424944Seric 
10359284Seric 	  case 'd':		/* delivery mode */
10369284Seric 		switch (*val)
10378269Seric 		{
10389284Seric 		  case '\0':
10399284Seric 			SendMode = SM_DELIVER;
10408269Seric 			break;
10418269Seric 
104210755Seric 		  case SM_QUEUE:	/* queue only */
104310755Seric #ifndef QUEUE
104410755Seric 			syserr("need QUEUE to set -odqueue");
104556795Seric #endif /* QUEUE */
104610755Seric 			/* fall through..... */
104710755Seric 
10489284Seric 		  case SM_DELIVER:	/* do everything */
10499284Seric 		  case SM_FORK:		/* fork after verification */
10509284Seric 			SendMode = *val;
10518269Seric 			break;
10528269Seric 
10538269Seric 		  default:
10549284Seric 			syserr("Unknown delivery mode %c", *val);
10558269Seric 			exit(EX_USAGE);
10568269Seric 		}
10578269Seric 		break;
10588269Seric 
10599146Seric 	  case 'D':		/* rebuild alias database as needed */
10609381Seric 		AutoRebuild = atobool(val);
10619146Seric 		break;
10629146Seric 
106355372Seric 	  case 'E':		/* error message header/header file */
106455379Seric 		if (*val != '\0')
106555379Seric 			ErrMsgFile = newstr(val);
106655372Seric 		break;
106755372Seric 
10688269Seric 	  case 'e':		/* set error processing mode */
10698269Seric 		switch (*val)
10708269Seric 		{
10719381Seric 		  case EM_QUIET:	/* be silent about it */
10729381Seric 		  case EM_MAIL:		/* mail back */
10739381Seric 		  case EM_BERKNET:	/* do berknet error processing */
10749381Seric 		  case EM_WRITE:	/* write back (or mail) */
10758269Seric 			HoldErrs = TRUE;
10769381Seric 			/* fall through... */
10778269Seric 
10789381Seric 		  case EM_PRINT:	/* print errors normally (default) */
10799381Seric 			ErrorMode = *val;
10808269Seric 			break;
10818269Seric 		}
10828269Seric 		break;
10838269Seric 
10849049Seric 	  case 'F':		/* file mode */
108517975Seric 		FileMode = atooct(val) & 0777;
10869049Seric 		break;
10879049Seric 
10888269Seric 	  case 'f':		/* save Unix-style From lines on front */
10899381Seric 		SaveFrom = atobool(val);
10908269Seric 		break;
10918269Seric 
109253735Seric 	  case 'G':		/* match recipients against GECOS field */
109353735Seric 		MatchGecos = atobool(val);
109453735Seric 		break;
109553735Seric 
10968256Seric 	  case 'g':		/* default gid */
109717474Seric 		DefGid = atoi(val);
10988256Seric 		break;
10998256Seric 
11008256Seric 	  case 'H':		/* help file */
11019381Seric 		if (val[0] == '\0')
11028269Seric 			HelpFile = "sendmail.hf";
11039381Seric 		else
11049381Seric 			HelpFile = newstr(val);
11058256Seric 		break;
11068256Seric 
110751305Seric 	  case 'h':		/* maximum hop count */
110851305Seric 		MaxHopCount = atoi(val);
110951305Seric 		break;
111051305Seric 
111135651Seric 	  case 'I':		/* use internet domain name server */
111257207Seric #ifdef NAMED_BIND
111357207Seric 		UseNameServer = TRUE;
111457207Seric 		for (p = val; *p != 0; )
111557207Seric 		{
111657207Seric 			bool clearmode;
111757207Seric 			char *q;
111857207Seric 			struct resolverflags *rfp;
111957207Seric 
112057207Seric 			while (*p == ' ')
112157207Seric 				p++;
112257207Seric 			if (*p == '\0')
112357207Seric 				break;
112457207Seric 			clearmode = FALSE;
112557207Seric 			if (*p == '-')
112657207Seric 				clearmode = TRUE;
112757207Seric 			else if (*p != '+')
112857207Seric 				p--;
112957207Seric 			p++;
113057207Seric 			q = p;
113158050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
113257207Seric 				p++;
113357207Seric 			if (*p != '\0')
113457207Seric 				*p++ = '\0';
113557207Seric 			for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
113657207Seric 			{
113757207Seric 				if (strcasecmp(q, rfp->rf_name) == 0)
113857207Seric 					break;
113957207Seric 			}
114057207Seric 			if (clearmode)
114157207Seric 				_res.options &= ~rfp->rf_bits;
114257207Seric 			else
114357207Seric 				_res.options |= rfp->rf_bits;
114457207Seric 		}
114557207Seric 		if (tTd(8, 2))
114657207Seric 			printf("_res.options = %x\n", _res.options);
114757207Seric #else
114857207Seric 		usrerr("name server (I option) specified but BIND not compiled in");
114957207Seric #endif
115035651Seric 		break;
115135651Seric 
11528269Seric 	  case 'i':		/* ignore dot lines in message */
11539381Seric 		IgnrDot = atobool(val);
11548269Seric 		break;
11558269Seric 
115657136Seric 	  case 'J':		/* .forward search path */
115757136Seric 		ForwardPath = newstr(val);
115857136Seric 		break;
115957136Seric 
116054967Seric 	  case 'k':		/* connection cache size */
116154967Seric 		MaxMciCache = atoi(val);
116256215Seric 		if (MaxMciCache < 0)
116356215Seric 			MaxMciCache = 0;
116454967Seric 		break;
116554967Seric 
116654967Seric 	  case 'K':		/* connection cache timeout */
116754967Seric 		MciCacheTimeout = convtime(val);
116854967Seric 		break;
116954967Seric 
11708256Seric 	  case 'L':		/* log level */
11719381Seric 		LogLevel = atoi(val);
11728256Seric 		break;
11738256Seric 
11748269Seric 	  case 'M':		/* define macro */
11759381Seric 		define(val[0], newstr(&val[1]), CurEnv);
117616878Seric 		sticky = FALSE;
11778269Seric 		break;
11788269Seric 
11798269Seric 	  case 'm':		/* send to me too */
11809381Seric 		MeToo = atobool(val);
11818269Seric 		break;
11828269Seric 
118325820Seric 	  case 'n':		/* validate RHS in newaliases */
118425820Seric 		CheckAliases = atobool(val);
118525820Seric 		break;
118625820Seric 
11878269Seric 	  case 'o':		/* assume old style headers */
11889381Seric 		if (atobool(val))
11899341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
11909341Seric 		else
11919341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
11928269Seric 		break;
11938269Seric 
119458082Seric 	  case 'p':		/* select privacy level */
119558082Seric 		p = val;
119658082Seric 		for (;;)
119758082Seric 		{
119858082Seric 			register struct prival *pv;
119958082Seric 			extern struct prival PrivacyValues[];
120058082Seric 
120158082Seric 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
120258082Seric 				p++;
120358082Seric 			if (*p == '\0')
120458082Seric 				break;
120558082Seric 			val = p;
120658082Seric 			while (isascii(*p) && isalnum(*p))
120758082Seric 				p++;
120858082Seric 			if (*p != '\0')
120958082Seric 				*p++ = '\0';
121058082Seric 
121158082Seric 			for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
121258082Seric 			{
121358082Seric 				if (strcasecmp(val, pv->pv_name) == 0)
121458082Seric 					break;
121558082Seric 			}
121658082Seric 			PrivacyFlags |= pv->pv_flag;
121758082Seric 		}
121858082Seric 		break;
121958082Seric 
122024944Seric 	  case 'P':		/* postmaster copy address for returned mail */
122124944Seric 		PostMasterCopy = newstr(val);
122224944Seric 		break;
122324944Seric 
122424944Seric 	  case 'q':		/* slope of queue only function */
122524944Seric 		QueueFactor = atoi(val);
122624944Seric 		break;
122724944Seric 
12288256Seric 	  case 'Q':		/* queue directory */
12299381Seric 		if (val[0] == '\0')
12308269Seric 			QueueDir = "mqueue";
12319381Seric 		else
12329381Seric 			QueueDir = newstr(val);
12338256Seric 		break;
12348256Seric 
123558148Seric 	  case 'R':		/* don't prune routes */
123658148Seric 		DontPruneRoutes = atobool(val);
123758148Seric 		break;
123858148Seric 
12398256Seric 	  case 'r':		/* read timeout */
124058112Seric 		settimeouts(val);
12418256Seric 		break;
12428256Seric 
12438256Seric 	  case 'S':		/* status file */
12449381Seric 		if (val[0] == '\0')
12458269Seric 			StatFile = "sendmail.st";
12469381Seric 		else
12479381Seric 			StatFile = newstr(val);
12488256Seric 		break;
12498256Seric 
12508265Seric 	  case 's':		/* be super safe, even if expensive */
12519381Seric 		SuperSafe = atobool(val);
12528256Seric 		break;
12538256Seric 
12548256Seric 	  case 'T':		/* queue timeout */
12559381Seric 		TimeOut = convtime(val);
125654967Seric 		break;
12578256Seric 
12588265Seric 	  case 't':		/* time zone name */
125952106Seric 		TimeZoneSpec = newstr(val);
12608265Seric 		break;
12618265Seric 
126250556Seric 	  case 'U':		/* location of user database */
126351360Seric 		UdbSpec = newstr(val);
126450556Seric 		break;
126550556Seric 
12668256Seric 	  case 'u':		/* set default uid */
126717474Seric 		DefUid = atoi(val);
126840973Sbostic 		setdefuser();
12698256Seric 		break;
12708256Seric 
12718269Seric 	  case 'v':		/* run in verbose mode */
12729381Seric 		Verbose = atobool(val);
12738256Seric 		break;
12748256Seric 
127514879Seric 	  case 'x':		/* load avg at which to auto-queue msgs */
127614879Seric 		QueueLA = atoi(val);
127714879Seric 		break;
127814879Seric 
127914879Seric 	  case 'X':		/* load avg at which to auto-reject connections */
128014879Seric 		RefuseLA = atoi(val);
128114879Seric 		break;
128214879Seric 
128324981Seric 	  case 'y':		/* work recipient factor */
128424981Seric 		WkRecipFact = atoi(val);
128524981Seric 		break;
128624981Seric 
128724981Seric 	  case 'Y':		/* fork jobs during queue runs */
128824952Seric 		ForkQueueRuns = atobool(val);
128924952Seric 		break;
129024952Seric 
129124981Seric 	  case 'z':		/* work message class factor */
129224981Seric 		WkClassFact = atoi(val);
129324981Seric 		break;
129424981Seric 
129524981Seric 	  case 'Z':		/* work time factor */
129624981Seric 		WkTimeFact = atoi(val);
129724981Seric 		break;
129824981Seric 
12998256Seric 	  default:
13008256Seric 		break;
13018256Seric 	}
130216878Seric 	if (sticky)
130316878Seric 		setbitn(opt, StickyOpt);
13049188Seric 	return;
13058256Seric }
130610687Seric /*
130710687Seric **  SETCLASS -- set a word into a class
130810687Seric **
130910687Seric **	Parameters:
131010687Seric **		class -- the class to put the word in.
131110687Seric **		word -- the word to enter
131210687Seric **
131310687Seric **	Returns:
131410687Seric **		none.
131510687Seric **
131610687Seric **	Side Effects:
131710687Seric **		puts the word into the symbol table.
131810687Seric */
131910687Seric 
132010687Seric setclass(class, word)
132110687Seric 	int class;
132210687Seric 	char *word;
132310687Seric {
132410687Seric 	register STAB *s;
132510687Seric 
132657943Seric 	if (tTd(37, 8))
132757943Seric 		printf("%s added to class %c\n", word, class);
132810687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
132910687Seric 	setbitn(class, s->s_class);
133010687Seric }
133153654Seric /*
133253654Seric **  MAKEMAPENTRY -- create a map entry
133353654Seric **
133453654Seric **	Parameters:
133553654Seric **		line -- the config file line
133653654Seric **
133753654Seric **	Returns:
133853654Seric **		TRUE if it successfully entered the map entry.
133953654Seric **		FALSE otherwise (usually syntax error).
134053654Seric **
134153654Seric **	Side Effects:
134253654Seric **		Enters the map into the dictionary.
134353654Seric */
134453654Seric 
134553654Seric void
134653654Seric makemapentry(line)
134753654Seric 	char *line;
134853654Seric {
134953654Seric 	register char *p;
135053654Seric 	char *mapname;
135153654Seric 	char *classname;
135253654Seric 	register STAB *map;
135353654Seric 	STAB *class;
135453654Seric 
135558050Seric 	for (p = line; isascii(*p) && isspace(*p); p++)
135653654Seric 		continue;
135758050Seric 	if (!(isascii(*p) && isalnum(*p)))
135853654Seric 	{
135953654Seric 		syserr("readcf: config K line: no map name");
136053654Seric 		return;
136153654Seric 	}
136253654Seric 
136353654Seric 	mapname = p;
136458050Seric 	while (isascii(*++p) && isalnum(*p))
136553654Seric 		continue;
136653654Seric 	if (*p != '\0')
136753654Seric 		*p++ = '\0';
136858050Seric 	while (isascii(*p) && isspace(*p))
136953654Seric 		p++;
137058050Seric 	if (!(isascii(*p) && isalnum(*p)))
137153654Seric 	{
137253654Seric 		syserr("readcf: config K line, map %s: no map class", mapname);
137353654Seric 		return;
137453654Seric 	}
137553654Seric 	classname = p;
137658050Seric 	while (isascii(*++p) && isalnum(*p))
137753654Seric 		continue;
137853654Seric 	if (*p != '\0')
137953654Seric 		*p++ = '\0';
138058050Seric 	while (isascii(*p) && isspace(*p))
138153654Seric 		p++;
138253654Seric 
138353654Seric 	/* look up the class */
138453654Seric 	class = stab(classname, ST_MAPCLASS, ST_FIND);
138553654Seric 	if (class == NULL)
138653654Seric 	{
138753654Seric 		syserr("readcf: map %s: class %s not available", mapname, classname);
138853654Seric 		return;
138953654Seric 	}
139053654Seric 
139153654Seric 	/* enter the map */
139253654Seric 	map = stab(mapname, ST_MAP, ST_ENTER);
139353654Seric 	map->s_map.map_class = &class->s_mapclass;
139453654Seric 
139556823Seric 	if ((*class->s_mapclass.map_init)(&map->s_map, mapname, p))
139653654Seric 		map->s_map.map_flags |= MF_VALID;
139753654Seric }
139858112Seric /*
139958112Seric **  SETTIMEOUTS -- parse and set timeout values
140058112Seric **
140158112Seric **	Parameters:
140258112Seric **		val -- a pointer to the values.  If NULL, do initial
140358112Seric **			settings.
140458112Seric **
140558112Seric **	Returns:
140658112Seric **		none.
140758112Seric **
140858112Seric **	Side Effects:
140958112Seric **		Initializes the TimeOuts structure
141058112Seric */
141158112Seric 
141258112Seric #define MINUTES	* 60
141358112Seric #define HOUR	* 3600
141458112Seric 
141558112Seric settimeouts(val)
141658112Seric 	register char *val;
141758112Seric {
141858112Seric 	register char *p;
141958112Seric 
142058112Seric 	if (val == NULL)
142158112Seric 	{
142258112Seric 		TimeOuts.to_initial = (time_t) 5 MINUTES;
142358112Seric 		TimeOuts.to_helo = (time_t) 5 MINUTES;
142458112Seric 		TimeOuts.to_mail = (time_t) 10 MINUTES;
142558112Seric 		TimeOuts.to_rcpt = (time_t) 1 HOUR;
142658112Seric 		TimeOuts.to_datainit = (time_t) 5 MINUTES;
142758112Seric 		TimeOuts.to_datablock = (time_t) 1 HOUR;
142858112Seric 		TimeOuts.to_datafinal = (time_t) 1 HOUR;
142958112Seric 		TimeOuts.to_rset = (time_t) 5 MINUTES;
143058112Seric 		TimeOuts.to_quit = (time_t) 2 MINUTES;
143158112Seric 		TimeOuts.to_nextcommand = (time_t) 1 HOUR;
143258112Seric 		TimeOuts.to_miscshort = (time_t) 2 MINUTES;
143358112Seric 		return;
143458112Seric 	}
143558112Seric 
143658112Seric 	for (;; val = p)
143758112Seric 	{
143858112Seric 		while (isascii(*val) && isspace(*val))
143958112Seric 			val++;
144058112Seric 		if (*val == '\0')
144158112Seric 			break;
144258112Seric 		for (p = val; *p != '\0' && *p != ','; p++)
144358112Seric 			continue;
144458112Seric 		if (*p != '\0')
144558112Seric 			*p++ = '\0';
144658112Seric 
144758112Seric 		if (isascii(*val) && isdigit(*val))
144858112Seric 		{
144958112Seric 			/* old syntax -- set everything */
145058112Seric 			TimeOuts.to_mail = convtime(val);
145158112Seric 			TimeOuts.to_rcpt = TimeOuts.to_mail;
145258112Seric 			TimeOuts.to_datainit = TimeOuts.to_mail;
145358112Seric 			TimeOuts.to_datablock = TimeOuts.to_mail;
145458112Seric 			TimeOuts.to_datafinal = TimeOuts.to_mail;
145558112Seric 			TimeOuts.to_nextcommand = TimeOuts.to_mail;
145658112Seric 			continue;
145758112Seric 		}
145858112Seric 		else
145958112Seric 		{
146058112Seric 			register char *q = strchr(val, '=');
146158112Seric 			time_t to;
146258112Seric 
146358112Seric 			if (q == NULL)
146458112Seric 			{
146558112Seric 				/* syntax error */
146658112Seric 				continue;
146758112Seric 			}
146858112Seric 			*q++ = '\0';
146958112Seric 			to = convtime(q);
147058112Seric 
147158112Seric 			if (strcasecmp(val, "initial") == 0)
147258112Seric 				TimeOuts.to_initial = to;
147358112Seric 			else if (strcasecmp(val, "mail") == 0)
147458112Seric 				TimeOuts.to_mail = to;
147558112Seric 			else if (strcasecmp(val, "rcpt") == 0)
147658112Seric 				TimeOuts.to_rcpt = to;
147758112Seric 			else if (strcasecmp(val, "datainit") == 0)
147858112Seric 				TimeOuts.to_datainit = to;
147958112Seric 			else if (strcasecmp(val, "datablock") == 0)
148058112Seric 				TimeOuts.to_datablock = to;
148158112Seric 			else if (strcasecmp(val, "datafinal") == 0)
148258112Seric 				TimeOuts.to_datafinal = to;
148358112Seric 			else if (strcasecmp(val, "command") == 0)
148458112Seric 				TimeOuts.to_nextcommand = to;
148558112Seric 			else if (strcasecmp(val, "rset") == 0)
148658112Seric 				TimeOuts.to_rset = to;
148758112Seric 			else if (strcasecmp(val, "helo") == 0)
148858112Seric 				TimeOuts.to_helo = to;
148958112Seric 			else if (strcasecmp(val, "quit") == 0)
149058112Seric 				TimeOuts.to_quit = to;
149158112Seric 			else if (strcasecmp(val, "misc") == 0)
149258112Seric 				TimeOuts.to_miscshort = to;
149358112Seric 			else
149458112Seric 				syserr("settimeouts: invalid timeout %s", val);
149558112Seric 		}
149658112Seric 	}
149758112Seric }
1498