xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 58737)
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*58737Seric static char sccsid[] = "@(#)readcf.c	6.19 (Berkeley) 03/19/93";
1133731Sbostic #endif /* not lint */
1222709Sdist 
133313Seric # include "sendmail.h"
1452647Seric # include <sys/stat.h>
1557207Seric #ifdef NAMED_BIND
1657207Seric # include <arpa/nameser.h>
1757207Seric # include <resolv.h>
1857207Seric #endif
193308Seric 
2057736Seric /* System 5 compatibility */
2157736Seric #ifndef S_ISREG
2257736Seric #define S_ISREG(foo)	((foo & S_IFREG) == S_IFREG)
2357736Seric #endif
2457736Seric #ifndef S_IWGRP
2557736Seric #define S_IWGRP		020
2657736Seric #endif
2757736Seric #ifndef S_IWOTH
2857736Seric #define S_IWOTH		002
2957736Seric #endif
3057736Seric 
313308Seric /*
323308Seric **  READCF -- read control file.
333308Seric **
343308Seric **	This routine reads the control file and builds the internal
353308Seric **	form.
363308Seric **
374432Seric **	The file is formatted as a sequence of lines, each taken
384432Seric **	atomically.  The first character of each line describes how
394432Seric **	the line is to be interpreted.  The lines are:
404432Seric **		Dxval		Define macro x to have value val.
414432Seric **		Cxword		Put word into class x.
424432Seric **		Fxfile [fmt]	Read file for lines to put into
434432Seric **				class x.  Use scanf string 'fmt'
444432Seric **				or "%s" if not present.  Fmt should
454432Seric **				only produce one string-valued result.
464432Seric **		Hname: value	Define header with field-name 'name'
474432Seric **				and value as specified; this will be
484432Seric **				macro expanded immediately before
494432Seric **				use.
504432Seric **		Sn		Use rewriting set n.
514432Seric **		Rlhs rhs	Rewrite addresses that match lhs to
524432Seric **				be rhs.
5324944Seric **		Mn arg=val...	Define mailer.  n is the internal name.
5424944Seric **				Args specify mailer parameters.
558252Seric **		Oxvalue		Set option x to value.
568252Seric **		Pname=value	Set precedence name to value.
5752645Seric **		Vversioncode	Version level of configuration syntax.
5853654Seric **		Kmapname mapclass arguments....
5953654Seric **				Define keyed lookup of a given class.
6053654Seric **				Arguments are class dependent.
614432Seric **
623308Seric **	Parameters:
633308Seric **		cfname -- control file name.
6454973Seric **		safe -- TRUE if this is the system config file;
6554973Seric **			FALSE otherwise.
6655012Seric **		e -- the main envelope.
673308Seric **
683308Seric **	Returns:
693308Seric **		none.
703308Seric **
713308Seric **	Side Effects:
723308Seric **		Builds several internal tables.
733308Seric */
743308Seric 
7555012Seric readcf(cfname, safe, e)
763308Seric 	char *cfname;
7754973Seric 	bool safe;
7855012Seric 	register ENVELOPE *e;
793308Seric {
803308Seric 	FILE *cf;
818547Seric 	int ruleset = 0;
828547Seric 	char *q;
838547Seric 	char **pv;
849350Seric 	struct rewrite *rwp = NULL;
8557135Seric 	char *bp;
8657589Seric 	int nfuzzy;
873308Seric 	char buf[MAXLINE];
883308Seric 	register char *p;
893308Seric 	extern char **prescan();
903308Seric 	extern char **copyplist();
9152647Seric 	struct stat statb;
925909Seric 	char exbuf[MAXLINE];
9316915Seric 	char pvpbuf[PSBUFSIZE];
949350Seric 	extern char *fgetfolded();
9510709Seric 	extern char *munchstring();
9653654Seric 	extern void makemapentry();
973308Seric 
9852647Seric 	FileName = cfname;
9952647Seric 	LineNumber = 0;
10052647Seric 
1013308Seric 	cf = fopen(cfname, "r");
1023308Seric 	if (cf == NULL)
1033308Seric 	{
10452647Seric 		syserr("cannot open");
1053308Seric 		exit(EX_OSFILE);
1063308Seric 	}
1073308Seric 
10852647Seric 	if (fstat(fileno(cf), &statb) < 0)
10952647Seric 	{
11052647Seric 		syserr("cannot fstat");
11152647Seric 		exit(EX_OSFILE);
11252647Seric 	}
11352647Seric 
11452647Seric 	if (!S_ISREG(statb.st_mode))
11552647Seric 	{
11652647Seric 		syserr("not a plain file");
11752647Seric 		exit(EX_OSFILE);
11852647Seric 	}
11952647Seric 
12052647Seric 	if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
12152647Seric 	{
12253037Seric 		if (OpMode == MD_DAEMON || OpMode == MD_FREEZE)
12353037Seric 			fprintf(stderr, "%s: WARNING: dangerous write permissions\n",
12453037Seric 				FileName);
12553037Seric #ifdef LOG
12653037Seric 		if (LogLevel > 0)
12753037Seric 			syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions",
12853037Seric 				FileName);
12953037Seric #endif
13052647Seric 	}
13152647Seric 
13257135Seric 	while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL)
1333308Seric 	{
13457135Seric 		if (bp[0] == '#')
13557135Seric 		{
13657135Seric 			if (bp != buf)
13757135Seric 				free(bp);
13852637Seric 			continue;
13957135Seric 		}
14052637Seric 
14158050Seric 		/* map $ into \201 for macro expansion */
14257135Seric 		for (p = bp; *p != '\0'; p++)
14316157Seric 		{
14457135Seric 			if (*p == '#' && p > bp && ConfigLevel >= 3)
14552647Seric 			{
14652647Seric 				/* this is an on-line comment */
14752647Seric 				register char *e;
14852647Seric 
14958050Seric 				switch (*--p & 0377)
15052647Seric 				{
15158050Seric 				  case MACROEXPAND:
15252647Seric 					/* it's from $# -- let it go through */
15352647Seric 					p++;
15452647Seric 					break;
15552647Seric 
15652647Seric 				  case '\\':
15752647Seric 					/* it's backslash escaped */
15852647Seric 					(void) strcpy(p, p + 1);
15952647Seric 					break;
16052647Seric 
16152647Seric 				  default:
16252647Seric 					/* delete preceeding white space */
16358050Seric 					while (isascii(*p) && isspace(*p) && p > bp)
16452647Seric 						p--;
16556795Seric 					if ((e = strchr(++p, '\n')) != NULL)
16652647Seric 						(void) strcpy(p, e);
16752647Seric 					else
16852647Seric 						p[0] = p[1] = '\0';
16952647Seric 					break;
17052647Seric 				}
17152647Seric 				continue;
17252647Seric 			}
17352647Seric 
17416157Seric 			if (*p != '$')
17516157Seric 				continue;
17616157Seric 
17716157Seric 			if (p[1] == '$')
17816157Seric 			{
17916157Seric 				/* actual dollar sign.... */
18023111Seric 				(void) strcpy(p, p + 1);
18116157Seric 				continue;
18216157Seric 			}
18316157Seric 
18416157Seric 			/* convert to macro expansion character */
18558050Seric 			*p = MACROEXPAND;
18616157Seric 		}
18716157Seric 
18816157Seric 		/* interpret this line */
18957135Seric 		switch (bp[0])
1903308Seric 		{
1913308Seric 		  case '\0':
1923308Seric 		  case '#':		/* comment */
1933308Seric 			break;
1943308Seric 
1953308Seric 		  case 'R':		/* rewriting rule */
19657135Seric 			for (p = &bp[1]; *p != '\0' && *p != '\t'; p++)
1973308Seric 				continue;
1983308Seric 
1993308Seric 			if (*p == '\0')
2005909Seric 			{
20157135Seric 				syserr("invalid rewrite line \"%s\"", bp);
2025909Seric 				break;
2035909Seric 			}
2045909Seric 
2055909Seric 			/* allocate space for the rule header */
2065909Seric 			if (rwp == NULL)
2075909Seric 			{
2085909Seric 				RewriteRules[ruleset] = rwp =
2095909Seric 					(struct rewrite *) xalloc(sizeof *rwp);
2105909Seric 			}
2113308Seric 			else
2123308Seric 			{
2135909Seric 				rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
2145909Seric 				rwp = rwp->r_next;
2155909Seric 			}
2165909Seric 			rwp->r_next = NULL;
2173308Seric 
2185909Seric 			/* expand and save the LHS */
2195909Seric 			*p = '\0';
22057135Seric 			expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e);
22158333Seric 			rwp->r_lhs = prescan(exbuf, '\t', pvpbuf, NULL);
22257589Seric 			nfuzzy = 0;
2235909Seric 			if (rwp->r_lhs != NULL)
22457589Seric 			{
22557589Seric 				register char **ap;
22657589Seric 
2275909Seric 				rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
22857589Seric 
22957589Seric 				/* count the number of fuzzy matches in LHS */
23057589Seric 				for (ap = rwp->r_lhs; *ap != NULL; ap++)
23157589Seric 				{
23258148Seric 					char *botch;
23358148Seric 
23458148Seric 					botch = NULL;
23558050Seric 					switch (**ap & 0377)
23657589Seric 					{
23757589Seric 					  case MATCHZANY:
23857589Seric 					  case MATCHANY:
23957589Seric 					  case MATCHONE:
24057589Seric 					  case MATCHCLASS:
24157589Seric 					  case MATCHNCLASS:
24258173Seric 					  case CANONHOST:
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 CANONUSER:
25558148Seric 						botch = "$:";
25658148Seric 						break;
25758148Seric 
25858148Seric 					  case CALLSUBR:
25958148Seric 						botch = "$>";
26058148Seric 						break;
26158148Seric 
26258148Seric 					  case CONDIF:
26358148Seric 						botch = "$?";
26458148Seric 						break;
26558148Seric 
26658148Seric 					  case CONDELSE:
26758148Seric 						botch = "$|";
26858148Seric 						break;
26958148Seric 
27058148Seric 					  case CONDFI:
27158148Seric 						botch = "$.";
27258148Seric 						break;
27358148Seric 
27458148Seric 					  case HOSTBEGIN:
27558148Seric 						botch = "$[";
27658148Seric 						break;
27758148Seric 
27858148Seric 					  case HOSTEND:
27958148Seric 						botch = "$]";
28058148Seric 						break;
28158148Seric 
28258148Seric 					  case LOOKUPBEGIN:
28358148Seric 						botch = "$(";
28458148Seric 						break;
28558148Seric 
28658148Seric 					  case LOOKUPEND:
28758148Seric 						botch = "$)";
28858148Seric 						break;
28957589Seric 					}
29058148Seric 					if (botch != NULL)
29158148Seric 						syserr("Inappropriate use of %s on LHS",
29258148Seric 							botch);
29357589Seric 				}
29457589Seric 			}
29556678Seric 			else
29656678Seric 				syserr("R line: null LHS");
2975909Seric 
2985909Seric 			/* expand and save the RHS */
2995909Seric 			while (*++p == '\t')
3005909Seric 				continue;
3017231Seric 			q = p;
3027231Seric 			while (*p != '\0' && *p != '\t')
3037231Seric 				p++;
3047231Seric 			*p = '\0';
30555012Seric 			expand(q, exbuf, &exbuf[sizeof exbuf], e);
30658333Seric 			rwp->r_rhs = prescan(exbuf, '\t', pvpbuf, NULL);
3075909Seric 			if (rwp->r_rhs != NULL)
30857589Seric 			{
30957589Seric 				register char **ap;
31057589Seric 
3115909Seric 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
31257589Seric 
31357589Seric 				/* check no out-of-bounds replacements */
31457589Seric 				nfuzzy += '0';
31557589Seric 				for (ap = rwp->r_rhs; *ap != NULL; ap++)
31657589Seric 				{
31758148Seric 					char *botch;
31858148Seric 
31958148Seric 					botch = NULL;
32058148Seric 					switch (**ap & 0377)
32157589Seric 					{
32258148Seric 					  case MATCHREPL:
32358148Seric 						if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy)
32458148Seric 						{
32558148Seric 							syserr("replacement $%c out of bounds",
32658148Seric 								(*ap)[1]);
32758148Seric 						}
32858148Seric 						break;
32958148Seric 
33058148Seric 					  case MATCHZANY:
33158148Seric 						botch = "$*";
33258148Seric 						break;
33358148Seric 
33458148Seric 					  case MATCHANY:
33558148Seric 						botch = "$+";
33658148Seric 						break;
33758148Seric 
33858148Seric 					  case MATCHONE:
33958148Seric 						botch = "$-";
34058148Seric 						break;
34158148Seric 
34258148Seric 					  case MATCHCLASS:
34358148Seric 						botch = "$=";
34458148Seric 						break;
34558148Seric 
34658148Seric 					  case MATCHNCLASS:
34758148Seric 						botch = "$~";
34858148Seric 						break;
34957589Seric 					}
35058148Seric 					if (botch != NULL)
35158148Seric 						syserr("Inappropriate use of %s on RHS",
35258148Seric 							botch);
35357589Seric 				}
35457589Seric 			}
35556678Seric 			else
35656678Seric 				syserr("R line: null RHS");
3573308Seric 			break;
3583308Seric 
3594072Seric 		  case 'S':		/* select rewriting set */
36057135Seric 			ruleset = atoi(&bp[1]);
3618056Seric 			if (ruleset >= MAXRWSETS || ruleset < 0)
3628056Seric 			{
3639381Seric 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
3648056Seric 				ruleset = 0;
3658056Seric 			}
3664072Seric 			rwp = NULL;
3674072Seric 			break;
3684072Seric 
3693308Seric 		  case 'D':		/* macro definition */
37058333Seric 			define(bp[1], newstr(munchstring(&bp[2], NULL)), e);
3713308Seric 			break;
3723308Seric 
3733387Seric 		  case 'H':		/* required header line */
37457135Seric 			(void) chompheader(&bp[1], TRUE, e);
3753387Seric 			break;
3763387Seric 
3774061Seric 		  case 'C':		/* word class */
3784432Seric 		  case 'F':		/* word class from file */
3794432Seric 			/* read list of words from argument or file */
38057135Seric 			if (bp[0] == 'F')
3814432Seric 			{
3824432Seric 				/* read from file */
38358050Seric 				for (p = &bp[2];
38458050Seric 				     *p != '\0' && !(isascii(*p) && isspace(*p));
38558050Seric 				     p++)
3864432Seric 					continue;
3874432Seric 				if (*p == '\0')
3884432Seric 					p = "%s";
3894432Seric 				else
3904432Seric 				{
3914432Seric 					*p = '\0';
39258050Seric 					while (isascii(*++p) && isspace(*p))
3934432Seric 						continue;
3944432Seric 				}
39557135Seric 				fileclass(bp[1], &bp[2], p, safe);
3964432Seric 				break;
3974432Seric 			}
3984061Seric 
3994432Seric 			/* scan the list of words and set class for all */
40057135Seric 			for (p = &bp[2]; *p != '\0'; )
4014061Seric 			{
4024061Seric 				register char *wd;
4034061Seric 				char delim;
4044061Seric 
40558050Seric 				while (*p != '\0' && isascii(*p) && isspace(*p))
4064061Seric 					p++;
4074061Seric 				wd = p;
40858050Seric 				while (*p != '\0' && !(isascii(*p) && isspace(*p)))
4094061Seric 					p++;
4104061Seric 				delim = *p;
4114061Seric 				*p = '\0';
4124061Seric 				if (wd[0] != '\0')
41358148Seric 				{
41458148Seric 					if (tTd(37, 2))
41558148Seric 						printf("setclass(%c, %s)\n",
41658148Seric 							bp[1], wd);
41757135Seric 					setclass(bp[1], wd);
41858148Seric 				}
4194061Seric 				*p = delim;
4204061Seric 			}
4214061Seric 			break;
4224061Seric 
4234096Seric 		  case 'M':		/* define mailer */
42457135Seric 			makemailer(&bp[1]);
4254096Seric 			break;
4264096Seric 
4278252Seric 		  case 'O':		/* set option */
42858734Seric 			setoption(bp[1], &bp[2], safe, FALSE, e);
4298252Seric 			break;
4308252Seric 
4318252Seric 		  case 'P':		/* set precedence */
4328252Seric 			if (NumPriorities >= MAXPRIORITIES)
4338252Seric 			{
4348547Seric 				toomany('P', MAXPRIORITIES);
4358252Seric 				break;
4368252Seric 			}
43757135Seric 			for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
4388252Seric 				continue;
4398252Seric 			if (*p == '\0')
4408252Seric 				goto badline;
4418252Seric 			*p = '\0';
44257135Seric 			Priorities[NumPriorities].pri_name = newstr(&bp[1]);
4438252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
4448252Seric 			NumPriorities++;
4458252Seric 			break;
4468252Seric 
4478547Seric 		  case 'T':		/* trusted user(s) */
44858161Seric 			/* this option is obsolete, but will be ignored */
4498547Seric 			break;
4508547Seric 
45152645Seric 		  case 'V':		/* configuration syntax version */
45257135Seric 			ConfigLevel = atoi(&bp[1]);
45352645Seric 			break;
45452645Seric 
45553654Seric 		  case 'K':
45657135Seric 			makemapentry(&bp[1]);
45753654Seric 			break;
45853654Seric 
4593308Seric 		  default:
4604061Seric 		  badline:
46157135Seric 			syserr("unknown control line \"%s\"", bp);
4623308Seric 		}
46357135Seric 		if (bp != buf)
46457135Seric 			free(bp);
4653308Seric 	}
46652637Seric 	if (ferror(cf))
46752637Seric 	{
46852647Seric 		syserr("I/O read error", cfname);
46952637Seric 		exit(EX_OSFILE);
47052637Seric 	}
47152637Seric 	fclose(cf);
4729381Seric 	FileName = NULL;
47356836Seric 
47457076Seric 	if (stab("host", ST_MAP, ST_FIND) == NULL)
47557076Seric 	{
47657076Seric 		/* user didn't initialize: set up host map */
47757076Seric 		strcpy(buf, "host host");
47857076Seric 		if (ConfigLevel >= 2)
47957076Seric 			strcat(buf, " -a.");
48057076Seric 		makemapentry(buf);
48157076Seric 	}
4824096Seric }
4834096Seric /*
4848547Seric **  TOOMANY -- signal too many of some option
4858547Seric **
4868547Seric **	Parameters:
4878547Seric **		id -- the id of the error line
4888547Seric **		maxcnt -- the maximum possible values
4898547Seric **
4908547Seric **	Returns:
4918547Seric **		none.
4928547Seric **
4938547Seric **	Side Effects:
4948547Seric **		gives a syserr.
4958547Seric */
4968547Seric 
4978547Seric toomany(id, maxcnt)
4988547Seric 	char id;
4998547Seric 	int maxcnt;
5008547Seric {
5019381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
5028547Seric }
5038547Seric /*
5044432Seric **  FILECLASS -- read members of a class from a file
5054432Seric **
5064432Seric **	Parameters:
5074432Seric **		class -- class to define.
5084432Seric **		filename -- name of file to read.
5094432Seric **		fmt -- scanf string to use for match.
5104432Seric **
5114432Seric **	Returns:
5124432Seric **		none
5134432Seric **
5144432Seric **	Side Effects:
5154432Seric **
5164432Seric **		puts all lines in filename that match a scanf into
5174432Seric **			the named class.
5184432Seric */
5194432Seric 
52054973Seric fileclass(class, filename, fmt, safe)
5214432Seric 	int class;
5224432Seric 	char *filename;
5234432Seric 	char *fmt;
52454973Seric 	bool safe;
5254432Seric {
52625808Seric 	FILE *f;
52754973Seric 	struct stat stbuf;
5284432Seric 	char buf[MAXLINE];
5294432Seric 
53054973Seric 	if (stat(filename, &stbuf) < 0)
53154973Seric 	{
53254973Seric 		syserr("fileclass: cannot stat %s", filename);
53354973Seric 		return;
53454973Seric 	}
53554973Seric 	if (!S_ISREG(stbuf.st_mode))
53654973Seric 	{
53754973Seric 		syserr("fileclass: %s not a regular file", filename);
53854973Seric 		return;
53954973Seric 	}
54054973Seric 	if (!safe && access(filename, R_OK) < 0)
54154973Seric 	{
54254973Seric 		syserr("fileclass: access denied on %s", filename);
54354973Seric 		return;
54454973Seric 	}
54554973Seric 	f = fopen(filename, "r");
5464432Seric 	if (f == NULL)
5474432Seric 	{
54854973Seric 		syserr("fileclass: cannot open %s", filename);
5494432Seric 		return;
5504432Seric 	}
5514432Seric 
5524432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
5534432Seric 	{
5544432Seric 		register STAB *s;
55525808Seric 		register char *p;
55625808Seric # ifdef SCANF
5574432Seric 		char wordbuf[MAXNAME+1];
5584432Seric 
5594432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
5604432Seric 			continue;
56125808Seric 		p = wordbuf;
56256795Seric # else /* SCANF */
56325808Seric 		p = buf;
56456795Seric # endif /* SCANF */
56525808Seric 
56625808Seric 		/*
56725808Seric 		**  Break up the match into words.
56825808Seric 		*/
56925808Seric 
57025808Seric 		while (*p != '\0')
57125808Seric 		{
57225808Seric 			register char *q;
57325808Seric 
57425808Seric 			/* strip leading spaces */
57558050Seric 			while (isascii(*p) && isspace(*p))
57625808Seric 				p++;
57725808Seric 			if (*p == '\0')
57825808Seric 				break;
57925808Seric 
58025808Seric 			/* find the end of the word */
58125808Seric 			q = p;
58258050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
58325808Seric 				p++;
58425808Seric 			if (*p != '\0')
58525808Seric 				*p++ = '\0';
58625808Seric 
58725808Seric 			/* enter the word in the symbol table */
58825808Seric 			s = stab(q, ST_CLASS, ST_ENTER);
58925808Seric 			setbitn(class, s->s_class);
59025808Seric 		}
5914432Seric 	}
5924432Seric 
59354973Seric 	(void) fclose(f);
5944432Seric }
5954432Seric /*
5964096Seric **  MAKEMAILER -- define a new mailer.
5974096Seric **
5984096Seric **	Parameters:
59910327Seric **		line -- description of mailer.  This is in labeled
60010327Seric **			fields.  The fields are:
60110327Seric **			   P -- the path to the mailer
60210327Seric **			   F -- the flags associated with the mailer
60310327Seric **			   A -- the argv for this mailer
60410327Seric **			   S -- the sender rewriting set
60510327Seric **			   R -- the recipient rewriting set
60610327Seric **			   E -- the eol string
60710327Seric **			The first word is the canonical name of the mailer.
6084096Seric **
6094096Seric **	Returns:
6104096Seric **		none.
6114096Seric **
6124096Seric **	Side Effects:
6134096Seric **		enters the mailer into the mailer table.
6144096Seric */
6153308Seric 
61621066Seric makemailer(line)
6174096Seric 	char *line;
6184096Seric {
6194096Seric 	register char *p;
6208067Seric 	register struct mailer *m;
6218067Seric 	register STAB *s;
6228067Seric 	int i;
62310327Seric 	char fcode;
62458020Seric 	auto char *endp;
6254096Seric 	extern int NextMailer;
62610327Seric 	extern char **makeargv();
62710327Seric 	extern char *munchstring();
62810701Seric 	extern long atol();
6294096Seric 
63010327Seric 	/* allocate a mailer and set up defaults */
63110327Seric 	m = (struct mailer *) xalloc(sizeof *m);
63210327Seric 	bzero((char *) m, sizeof *m);
63310327Seric 	m->m_eol = "\n";
63410327Seric 
63510327Seric 	/* collect the mailer name */
63658050Seric 	for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++)
63710327Seric 		continue;
63810327Seric 	if (*p != '\0')
63910327Seric 		*p++ = '\0';
64010327Seric 	m->m_name = newstr(line);
64110327Seric 
64210327Seric 	/* now scan through and assign info from the fields */
64310327Seric 	while (*p != '\0')
64410327Seric 	{
64558333Seric 		auto char *delimptr;
64658333Seric 
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 */
66358333Seric 		p = munchstring(p, &delimptr);
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 
72558333Seric 		p = delimptr;
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 
73758321Seric 	/* do some rationality checking */
73858321Seric 	if (m->m_argv == NULL)
73958321Seric 	{
74058321Seric 		syserr("M%s: A= argument required", m->m_name);
74158321Seric 		return;
74258321Seric 	}
74358321Seric 	if (m->m_mailer == NULL)
74458321Seric 	{
74558321Seric 		syserr("M%s: P= argument required", m->m_name);
74658321Seric 		return;
74758321Seric 	}
74858321Seric 
7494096Seric 	if (NextMailer >= MAXMAILERS)
7504096Seric 	{
7519381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
7524096Seric 		return;
7534096Seric 	}
75457402Seric 
75510327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
75657402Seric 	if (s->s_mailer != NULL)
75757402Seric 	{
75857402Seric 		i = s->s_mailer->m_mno;
75957402Seric 		free(s->s_mailer);
76057402Seric 	}
76157402Seric 	else
76257402Seric 	{
76357402Seric 		i = NextMailer++;
76457402Seric 	}
76557402Seric 	Mailer[i] = s->s_mailer = m;
76657454Seric 	m->m_mno = i;
76710327Seric }
76810327Seric /*
76910327Seric **  MUNCHSTRING -- translate a string into internal form.
77010327Seric **
77110327Seric **	Parameters:
77210327Seric **		p -- the string to munch.
77358333Seric **		delimptr -- if non-NULL, set to the pointer of the
77458333Seric **			field delimiter character.
77510327Seric **
77610327Seric **	Returns:
77710327Seric **		the munched string.
77810327Seric */
7794096Seric 
78010327Seric char *
78158333Seric munchstring(p, delimptr)
78210327Seric 	register char *p;
78358333Seric 	char **delimptr;
78410327Seric {
78510327Seric 	register char *q;
78610327Seric 	bool backslash = FALSE;
78710327Seric 	bool quotemode = FALSE;
78810327Seric 	static char buf[MAXLINE];
7894096Seric 
79010327Seric 	for (q = buf; *p != '\0'; p++)
7914096Seric 	{
79210327Seric 		if (backslash)
79310327Seric 		{
79410327Seric 			/* everything is roughly literal */
79510357Seric 			backslash = FALSE;
79610327Seric 			switch (*p)
79710327Seric 			{
79810327Seric 			  case 'r':		/* carriage return */
79910327Seric 				*q++ = '\r';
80010327Seric 				continue;
80110327Seric 
80210327Seric 			  case 'n':		/* newline */
80310327Seric 				*q++ = '\n';
80410327Seric 				continue;
80510327Seric 
80610327Seric 			  case 'f':		/* form feed */
80710327Seric 				*q++ = '\f';
80810327Seric 				continue;
80910327Seric 
81010327Seric 			  case 'b':		/* backspace */
81110327Seric 				*q++ = '\b';
81210327Seric 				continue;
81310327Seric 			}
81410327Seric 			*q++ = *p;
81510327Seric 		}
81610327Seric 		else
81710327Seric 		{
81810327Seric 			if (*p == '\\')
81910327Seric 				backslash = TRUE;
82010327Seric 			else if (*p == '"')
82110327Seric 				quotemode = !quotemode;
82210327Seric 			else if (quotemode || *p != ',')
82310327Seric 				*q++ = *p;
82410327Seric 			else
82510327Seric 				break;
82610327Seric 		}
8274096Seric 	}
8284096Seric 
82958333Seric 	if (delimptr != NULL)
83058333Seric 		*delimptr = p;
83110327Seric 	*q++ = '\0';
83210327Seric 	return (buf);
83310327Seric }
83410327Seric /*
83510327Seric **  MAKEARGV -- break up a string into words
83610327Seric **
83710327Seric **	Parameters:
83810327Seric **		p -- the string to break up.
83910327Seric **
84010327Seric **	Returns:
84110327Seric **		a char **argv (dynamically allocated)
84210327Seric **
84310327Seric **	Side Effects:
84410327Seric **		munges p.
84510327Seric */
8464096Seric 
84710327Seric char **
84810327Seric makeargv(p)
84910327Seric 	register char *p;
85010327Seric {
85110327Seric 	char *q;
85210327Seric 	int i;
85310327Seric 	char **avp;
85410327Seric 	char *argv[MAXPV + 1];
85510327Seric 
85610327Seric 	/* take apart the words */
85710327Seric 	i = 0;
85810327Seric 	while (*p != '\0' && i < MAXPV)
8594096Seric 	{
86010327Seric 		q = p;
86158050Seric 		while (*p != '\0' && !(isascii(*p) && isspace(*p)))
86210327Seric 			p++;
86358050Seric 		while (isascii(*p) && isspace(*p))
86410327Seric 			*p++ = '\0';
86510327Seric 		argv[i++] = newstr(q);
8664096Seric 	}
86710327Seric 	argv[i++] = NULL;
8684096Seric 
86910327Seric 	/* now make a copy of the argv */
87010327Seric 	avp = (char **) xalloc(sizeof *avp * i);
87116893Seric 	bcopy((char *) argv, (char *) avp, sizeof *avp * i);
87210327Seric 
87310327Seric 	return (avp);
8743308Seric }
8753308Seric /*
8763308Seric **  PRINTRULES -- print rewrite rules (for debugging)
8773308Seric **
8783308Seric **	Parameters:
8793308Seric **		none.
8803308Seric **
8813308Seric **	Returns:
8823308Seric **		none.
8833308Seric **
8843308Seric **	Side Effects:
8853308Seric **		prints rewrite rules.
8863308Seric */
8873308Seric 
8883308Seric printrules()
8893308Seric {
8903308Seric 	register struct rewrite *rwp;
8914072Seric 	register int ruleset;
8923308Seric 
8934072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
8943308Seric 	{
8954072Seric 		if (RewriteRules[ruleset] == NULL)
8964072Seric 			continue;
8978067Seric 		printf("\n----Rule Set %d:", ruleset);
8983308Seric 
8994072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
9003308Seric 		{
9018067Seric 			printf("\nLHS:");
9028067Seric 			printav(rwp->r_lhs);
9038067Seric 			printf("RHS:");
9048067Seric 			printav(rwp->r_rhs);
9053308Seric 		}
9063308Seric 	}
9073308Seric }
9084319Seric 
9094096Seric /*
9108256Seric **  SETOPTION -- set global processing option
9118256Seric **
9128256Seric **	Parameters:
9138256Seric **		opt -- option name.
9148256Seric **		val -- option value (as a text string).
91521755Seric **		safe -- set if this came from a configuration file.
91621755Seric **			Some options (if set from the command line) will
91721755Seric **			reset the user id to avoid security problems.
9188269Seric **		sticky -- if set, don't let other setoptions override
9198269Seric **			this value.
92058734Seric **		e -- the main envelope.
9218256Seric **
9228256Seric **	Returns:
9238256Seric **		none.
9248256Seric **
9258256Seric **	Side Effects:
9268256Seric **		Sets options as implied by the arguments.
9278256Seric */
9288256Seric 
92910687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
9308269Seric 
93157207Seric 
93257207Seric #ifdef NAMED_BIND
93357207Seric 
93457207Seric struct resolverflags
93557207Seric {
93657207Seric 	char	*rf_name;	/* name of the flag */
93757207Seric 	long	rf_bits;	/* bits to set/clear */
93857207Seric } ResolverFlags[] =
93957207Seric {
94057207Seric 	"debug",	RES_DEBUG,
94157207Seric 	"aaonly",	RES_AAONLY,
94257207Seric 	"usevc",	RES_USEVC,
94357207Seric 	"primary",	RES_PRIMARY,
94457207Seric 	"igntc",	RES_IGNTC,
94557207Seric 	"recurse",	RES_RECURSE,
94657207Seric 	"defnames",	RES_DEFNAMES,
94757207Seric 	"stayopen",	RES_STAYOPEN,
94857207Seric 	"dnsrch",	RES_DNSRCH,
94957207Seric 	NULL,		0
95057207Seric };
95157207Seric 
95257207Seric #endif
95357207Seric 
95458734Seric setoption(opt, val, safe, sticky, e)
9558256Seric 	char opt;
9568256Seric 	char *val;
95721755Seric 	bool safe;
9588269Seric 	bool sticky;
95958734Seric 	register ENVELOPE *e;
9608256Seric {
96157207Seric 	register char *p;
9628265Seric 	extern bool atobool();
96312633Seric 	extern time_t convtime();
96414879Seric 	extern int QueueLA;
96514879Seric 	extern int RefuseLA;
96617474Seric 	extern bool trusteduser();
96717474Seric 	extern char *username();
9688256Seric 
9698256Seric 	if (tTd(37, 1))
9709341Seric 		printf("setoption %c=%s", opt, val);
9718256Seric 
9728256Seric 	/*
9738269Seric 	**  See if this option is preset for us.
9748256Seric 	*/
9758256Seric 
97610687Seric 	if (bitnset(opt, StickyOpt))
9778269Seric 	{
9789341Seric 		if (tTd(37, 1))
9799341Seric 			printf(" (ignored)\n");
9808269Seric 		return;
9818269Seric 	}
9828269Seric 
98321755Seric 	/*
98421755Seric 	**  Check to see if this option can be specified by this user.
98521755Seric 	*/
98621755Seric 
98736238Skarels 	if (!safe && getuid() == 0)
98821755Seric 		safe = TRUE;
98958082Seric 	if (!safe && strchr("bdeEiLmoprsvC8", opt) == NULL)
99021755Seric 	{
99139111Srick 		if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
99221755Seric 		{
99336582Sbostic 			if (tTd(37, 1))
99436582Sbostic 				printf(" (unsafe)");
99536582Sbostic 			if (getuid() != geteuid())
99636582Sbostic 			{
99751210Seric 				if (tTd(37, 1))
99851210Seric 					printf("(Resetting uid)");
99936582Sbostic 				(void) setgid(getgid());
100036582Sbostic 				(void) setuid(getuid());
100136582Sbostic 			}
100221755Seric 		}
100321755Seric 	}
100451210Seric 	if (tTd(37, 1))
100517985Seric 		printf("\n");
10068269Seric 
10078256Seric 	switch (opt)
10088256Seric 	{
100952106Seric 	  case '8':		/* allow eight-bit input */
101052106Seric 		EightBit = atobool(val);
101152106Seric 		break;
101252106Seric 
10138256Seric 	  case 'A':		/* set default alias file */
10149381Seric 		if (val[0] == '\0')
10158269Seric 			AliasFile = "aliases";
10169381Seric 		else
10179381Seric 			AliasFile = newstr(val);
10188256Seric 		break;
10198256Seric 
102017474Seric 	  case 'a':		/* look N minutes for "@:@" in alias file */
102117474Seric 		if (val[0] == '\0')
102217474Seric 			SafeAlias = 5;
102317474Seric 		else
102417474Seric 			SafeAlias = atoi(val);
102517474Seric 		break;
102617474Seric 
102716843Seric 	  case 'B':		/* substitution for blank character */
102816843Seric 		SpaceSub = val[0];
102916843Seric 		if (SpaceSub == '\0')
103016843Seric 			SpaceSub = ' ';
103116843Seric 		break;
103216843Seric 
103358082Seric 	  case 'b':		/* minimum number of blocks free on queue fs */
103458082Seric 		MinBlocksFree = atol(val);
103558082Seric 		break;
103658082Seric 
10379284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
10389381Seric 		NoConnect = atobool(val);
10399284Seric 		break;
10409284Seric 
104151305Seric 	  case 'C':		/* checkpoint every N addresses */
104251305Seric 		CheckpointInterval = atoi(val);
104324944Seric 		break;
104424944Seric 
10459284Seric 	  case 'd':		/* delivery mode */
10469284Seric 		switch (*val)
10478269Seric 		{
10489284Seric 		  case '\0':
104958734Seric 			e->e_sendmode = SM_DELIVER;
10508269Seric 			break;
10518269Seric 
105210755Seric 		  case SM_QUEUE:	/* queue only */
105310755Seric #ifndef QUEUE
105410755Seric 			syserr("need QUEUE to set -odqueue");
105556795Seric #endif /* QUEUE */
105610755Seric 			/* fall through..... */
105710755Seric 
10589284Seric 		  case SM_DELIVER:	/* do everything */
10599284Seric 		  case SM_FORK:		/* fork after verification */
106058734Seric 			e->e_sendmode = *val;
10618269Seric 			break;
10628269Seric 
10638269Seric 		  default:
10649284Seric 			syserr("Unknown delivery mode %c", *val);
10658269Seric 			exit(EX_USAGE);
10668269Seric 		}
10678269Seric 		break;
10688269Seric 
10699146Seric 	  case 'D':		/* rebuild alias database as needed */
10709381Seric 		AutoRebuild = atobool(val);
10719146Seric 		break;
10729146Seric 
107355372Seric 	  case 'E':		/* error message header/header file */
107455379Seric 		if (*val != '\0')
107555379Seric 			ErrMsgFile = newstr(val);
107655372Seric 		break;
107755372Seric 
10788269Seric 	  case 'e':		/* set error processing mode */
10798269Seric 		switch (*val)
10808269Seric 		{
10819381Seric 		  case EM_QUIET:	/* be silent about it */
10829381Seric 		  case EM_MAIL:		/* mail back */
10839381Seric 		  case EM_BERKNET:	/* do berknet error processing */
10849381Seric 		  case EM_WRITE:	/* write back (or mail) */
10858269Seric 			HoldErrs = TRUE;
10869381Seric 			/* fall through... */
10878269Seric 
10889381Seric 		  case EM_PRINT:	/* print errors normally (default) */
108958734Seric 			e->e_errormode = *val;
10908269Seric 			break;
10918269Seric 		}
10928269Seric 		break;
10938269Seric 
10949049Seric 	  case 'F':		/* file mode */
109517975Seric 		FileMode = atooct(val) & 0777;
10969049Seric 		break;
10979049Seric 
10988269Seric 	  case 'f':		/* save Unix-style From lines on front */
10999381Seric 		SaveFrom = atobool(val);
11008269Seric 		break;
11018269Seric 
110253735Seric 	  case 'G':		/* match recipients against GECOS field */
110353735Seric 		MatchGecos = atobool(val);
110453735Seric 		break;
110553735Seric 
11068256Seric 	  case 'g':		/* default gid */
110717474Seric 		DefGid = atoi(val);
11088256Seric 		break;
11098256Seric 
11108256Seric 	  case 'H':		/* help file */
11119381Seric 		if (val[0] == '\0')
11128269Seric 			HelpFile = "sendmail.hf";
11139381Seric 		else
11149381Seric 			HelpFile = newstr(val);
11158256Seric 		break;
11168256Seric 
111751305Seric 	  case 'h':		/* maximum hop count */
111851305Seric 		MaxHopCount = atoi(val);
111951305Seric 		break;
112051305Seric 
112135651Seric 	  case 'I':		/* use internet domain name server */
112257207Seric #ifdef NAMED_BIND
112357207Seric 		UseNameServer = TRUE;
112457207Seric 		for (p = val; *p != 0; )
112557207Seric 		{
112657207Seric 			bool clearmode;
112757207Seric 			char *q;
112857207Seric 			struct resolverflags *rfp;
112957207Seric 
113057207Seric 			while (*p == ' ')
113157207Seric 				p++;
113257207Seric 			if (*p == '\0')
113357207Seric 				break;
113457207Seric 			clearmode = FALSE;
113557207Seric 			if (*p == '-')
113657207Seric 				clearmode = TRUE;
113757207Seric 			else if (*p != '+')
113857207Seric 				p--;
113957207Seric 			p++;
114057207Seric 			q = p;
114158050Seric 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
114257207Seric 				p++;
114357207Seric 			if (*p != '\0')
114457207Seric 				*p++ = '\0';
114557207Seric 			for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
114657207Seric 			{
114757207Seric 				if (strcasecmp(q, rfp->rf_name) == 0)
114857207Seric 					break;
114957207Seric 			}
115057207Seric 			if (clearmode)
115157207Seric 				_res.options &= ~rfp->rf_bits;
115257207Seric 			else
115357207Seric 				_res.options |= rfp->rf_bits;
115457207Seric 		}
115557207Seric 		if (tTd(8, 2))
115657207Seric 			printf("_res.options = %x\n", _res.options);
115757207Seric #else
115857207Seric 		usrerr("name server (I option) specified but BIND not compiled in");
115957207Seric #endif
116035651Seric 		break;
116135651Seric 
11628269Seric 	  case 'i':		/* ignore dot lines in message */
11639381Seric 		IgnrDot = atobool(val);
11648269Seric 		break;
11658269Seric 
116657136Seric 	  case 'J':		/* .forward search path */
116757136Seric 		ForwardPath = newstr(val);
116857136Seric 		break;
116957136Seric 
117054967Seric 	  case 'k':		/* connection cache size */
117154967Seric 		MaxMciCache = atoi(val);
117256215Seric 		if (MaxMciCache < 0)
117356215Seric 			MaxMciCache = 0;
117454967Seric 		break;
117554967Seric 
117654967Seric 	  case 'K':		/* connection cache timeout */
117754967Seric 		MciCacheTimeout = convtime(val);
117854967Seric 		break;
117954967Seric 
11808256Seric 	  case 'L':		/* log level */
11819381Seric 		LogLevel = atoi(val);
11828256Seric 		break;
11838256Seric 
11848269Seric 	  case 'M':		/* define macro */
11859381Seric 		define(val[0], newstr(&val[1]), CurEnv);
118616878Seric 		sticky = FALSE;
11878269Seric 		break;
11888269Seric 
11898269Seric 	  case 'm':		/* send to me too */
11909381Seric 		MeToo = atobool(val);
11918269Seric 		break;
11928269Seric 
119325820Seric 	  case 'n':		/* validate RHS in newaliases */
119425820Seric 		CheckAliases = atobool(val);
119525820Seric 		break;
119625820Seric 
11978269Seric 	  case 'o':		/* assume old style headers */
11989381Seric 		if (atobool(val))
11999341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
12009341Seric 		else
12019341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
12028269Seric 		break;
12038269Seric 
120458082Seric 	  case 'p':		/* select privacy level */
120558082Seric 		p = val;
120658082Seric 		for (;;)
120758082Seric 		{
120858082Seric 			register struct prival *pv;
120958082Seric 			extern struct prival PrivacyValues[];
121058082Seric 
121158082Seric 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
121258082Seric 				p++;
121358082Seric 			if (*p == '\0')
121458082Seric 				break;
121558082Seric 			val = p;
121658082Seric 			while (isascii(*p) && isalnum(*p))
121758082Seric 				p++;
121858082Seric 			if (*p != '\0')
121958082Seric 				*p++ = '\0';
122058082Seric 
122158082Seric 			for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
122258082Seric 			{
122358082Seric 				if (strcasecmp(val, pv->pv_name) == 0)
122458082Seric 					break;
122558082Seric 			}
122658082Seric 			PrivacyFlags |= pv->pv_flag;
122758082Seric 		}
122858082Seric 		break;
122958082Seric 
123024944Seric 	  case 'P':		/* postmaster copy address for returned mail */
123124944Seric 		PostMasterCopy = newstr(val);
123224944Seric 		break;
123324944Seric 
123424944Seric 	  case 'q':		/* slope of queue only function */
123524944Seric 		QueueFactor = atoi(val);
123624944Seric 		break;
123724944Seric 
12388256Seric 	  case 'Q':		/* queue directory */
12399381Seric 		if (val[0] == '\0')
12408269Seric 			QueueDir = "mqueue";
12419381Seric 		else
12429381Seric 			QueueDir = newstr(val);
12438256Seric 		break;
12448256Seric 
124558148Seric 	  case 'R':		/* don't prune routes */
124658148Seric 		DontPruneRoutes = atobool(val);
124758148Seric 		break;
124858148Seric 
12498256Seric 	  case 'r':		/* read timeout */
125058112Seric 		settimeouts(val);
12518256Seric 		break;
12528256Seric 
12538256Seric 	  case 'S':		/* status file */
12549381Seric 		if (val[0] == '\0')
12558269Seric 			StatFile = "sendmail.st";
12569381Seric 		else
12579381Seric 			StatFile = newstr(val);
12588256Seric 		break;
12598256Seric 
12608265Seric 	  case 's':		/* be super safe, even if expensive */
12619381Seric 		SuperSafe = atobool(val);
12628256Seric 		break;
12638256Seric 
12648256Seric 	  case 'T':		/* queue timeout */
1265*58737Seric 		p = strchr(val, '/');
1266*58737Seric 		if (p != NULL)
1267*58737Seric 		{
1268*58737Seric 			*p++ = '\0';
1269*58737Seric 			TimeOuts.to_q_warning = convtime(p);
1270*58737Seric 		}
1271*58737Seric 		TimeOuts.to_q_return = convtime(val);
127254967Seric 		break;
12738256Seric 
12748265Seric 	  case 't':		/* time zone name */
127552106Seric 		TimeZoneSpec = newstr(val);
12768265Seric 		break;
12778265Seric 
127850556Seric 	  case 'U':		/* location of user database */
127951360Seric 		UdbSpec = newstr(val);
128050556Seric 		break;
128150556Seric 
12828256Seric 	  case 'u':		/* set default uid */
128317474Seric 		DefUid = atoi(val);
128440973Sbostic 		setdefuser();
12858256Seric 		break;
12868256Seric 
12878269Seric 	  case 'v':		/* run in verbose mode */
12889381Seric 		Verbose = atobool(val);
12898256Seric 		break;
12908256Seric 
129114879Seric 	  case 'x':		/* load avg at which to auto-queue msgs */
129214879Seric 		QueueLA = atoi(val);
129314879Seric 		break;
129414879Seric 
129514879Seric 	  case 'X':		/* load avg at which to auto-reject connections */
129614879Seric 		RefuseLA = atoi(val);
129714879Seric 		break;
129814879Seric 
129924981Seric 	  case 'y':		/* work recipient factor */
130024981Seric 		WkRecipFact = atoi(val);
130124981Seric 		break;
130224981Seric 
130324981Seric 	  case 'Y':		/* fork jobs during queue runs */
130424952Seric 		ForkQueueRuns = atobool(val);
130524952Seric 		break;
130624952Seric 
130724981Seric 	  case 'z':		/* work message class factor */
130824981Seric 		WkClassFact = atoi(val);
130924981Seric 		break;
131024981Seric 
131124981Seric 	  case 'Z':		/* work time factor */
131224981Seric 		WkTimeFact = atoi(val);
131324981Seric 		break;
131424981Seric 
13158256Seric 	  default:
13168256Seric 		break;
13178256Seric 	}
131816878Seric 	if (sticky)
131916878Seric 		setbitn(opt, StickyOpt);
13209188Seric 	return;
13218256Seric }
132210687Seric /*
132310687Seric **  SETCLASS -- set a word into a class
132410687Seric **
132510687Seric **	Parameters:
132610687Seric **		class -- the class to put the word in.
132710687Seric **		word -- the word to enter
132810687Seric **
132910687Seric **	Returns:
133010687Seric **		none.
133110687Seric **
133210687Seric **	Side Effects:
133310687Seric **		puts the word into the symbol table.
133410687Seric */
133510687Seric 
133610687Seric setclass(class, word)
133710687Seric 	int class;
133810687Seric 	char *word;
133910687Seric {
134010687Seric 	register STAB *s;
134110687Seric 
134257943Seric 	if (tTd(37, 8))
134357943Seric 		printf("%s added to class %c\n", word, class);
134410687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
134510687Seric 	setbitn(class, s->s_class);
134610687Seric }
134753654Seric /*
134853654Seric **  MAKEMAPENTRY -- create a map entry
134953654Seric **
135053654Seric **	Parameters:
135153654Seric **		line -- the config file line
135253654Seric **
135353654Seric **	Returns:
135453654Seric **		TRUE if it successfully entered the map entry.
135553654Seric **		FALSE otherwise (usually syntax error).
135653654Seric **
135753654Seric **	Side Effects:
135853654Seric **		Enters the map into the dictionary.
135953654Seric */
136053654Seric 
136153654Seric void
136253654Seric makemapentry(line)
136353654Seric 	char *line;
136453654Seric {
136553654Seric 	register char *p;
136653654Seric 	char *mapname;
136753654Seric 	char *classname;
136853654Seric 	register STAB *map;
136953654Seric 	STAB *class;
137053654Seric 
137158050Seric 	for (p = line; isascii(*p) && isspace(*p); p++)
137253654Seric 		continue;
137358050Seric 	if (!(isascii(*p) && isalnum(*p)))
137453654Seric 	{
137553654Seric 		syserr("readcf: config K line: no map name");
137653654Seric 		return;
137753654Seric 	}
137853654Seric 
137953654Seric 	mapname = p;
138058050Seric 	while (isascii(*++p) && isalnum(*p))
138153654Seric 		continue;
138253654Seric 	if (*p != '\0')
138353654Seric 		*p++ = '\0';
138458050Seric 	while (isascii(*p) && isspace(*p))
138553654Seric 		p++;
138658050Seric 	if (!(isascii(*p) && isalnum(*p)))
138753654Seric 	{
138853654Seric 		syserr("readcf: config K line, map %s: no map class", mapname);
138953654Seric 		return;
139053654Seric 	}
139153654Seric 	classname = p;
139258050Seric 	while (isascii(*++p) && isalnum(*p))
139353654Seric 		continue;
139453654Seric 	if (*p != '\0')
139553654Seric 		*p++ = '\0';
139658050Seric 	while (isascii(*p) && isspace(*p))
139753654Seric 		p++;
139853654Seric 
139953654Seric 	/* look up the class */
140053654Seric 	class = stab(classname, ST_MAPCLASS, ST_FIND);
140153654Seric 	if (class == NULL)
140253654Seric 	{
140353654Seric 		syserr("readcf: map %s: class %s not available", mapname, classname);
140453654Seric 		return;
140553654Seric 	}
140653654Seric 
140753654Seric 	/* enter the map */
140853654Seric 	map = stab(mapname, ST_MAP, ST_ENTER);
140953654Seric 	map->s_map.map_class = &class->s_mapclass;
141053654Seric 
141156823Seric 	if ((*class->s_mapclass.map_init)(&map->s_map, mapname, p))
141253654Seric 		map->s_map.map_flags |= MF_VALID;
141353654Seric }
141458112Seric /*
141558112Seric **  SETTIMEOUTS -- parse and set timeout values
141658112Seric **
141758112Seric **	Parameters:
141858112Seric **		val -- a pointer to the values.  If NULL, do initial
141958112Seric **			settings.
142058112Seric **
142158112Seric **	Returns:
142258112Seric **		none.
142358112Seric **
142458112Seric **	Side Effects:
142558112Seric **		Initializes the TimeOuts structure
142658112Seric */
142758112Seric 
142858112Seric #define MINUTES	* 60
142958112Seric #define HOUR	* 3600
143058112Seric 
143158112Seric settimeouts(val)
143258112Seric 	register char *val;
143358112Seric {
143458112Seric 	register char *p;
143558671Seric 	extern time_t convtime();
143658112Seric 
143758112Seric 	if (val == NULL)
143858112Seric 	{
143958112Seric 		TimeOuts.to_initial = (time_t) 5 MINUTES;
144058112Seric 		TimeOuts.to_helo = (time_t) 5 MINUTES;
144158112Seric 		TimeOuts.to_mail = (time_t) 10 MINUTES;
144258112Seric 		TimeOuts.to_rcpt = (time_t) 1 HOUR;
144358112Seric 		TimeOuts.to_datainit = (time_t) 5 MINUTES;
144458112Seric 		TimeOuts.to_datablock = (time_t) 1 HOUR;
144558112Seric 		TimeOuts.to_datafinal = (time_t) 1 HOUR;
144658112Seric 		TimeOuts.to_rset = (time_t) 5 MINUTES;
144758112Seric 		TimeOuts.to_quit = (time_t) 2 MINUTES;
144858112Seric 		TimeOuts.to_nextcommand = (time_t) 1 HOUR;
144958112Seric 		TimeOuts.to_miscshort = (time_t) 2 MINUTES;
145058112Seric 		return;
145158112Seric 	}
145258112Seric 
145358112Seric 	for (;; val = p)
145458112Seric 	{
145558112Seric 		while (isascii(*val) && isspace(*val))
145658112Seric 			val++;
145758112Seric 		if (*val == '\0')
145858112Seric 			break;
145958112Seric 		for (p = val; *p != '\0' && *p != ','; p++)
146058112Seric 			continue;
146158112Seric 		if (*p != '\0')
146258112Seric 			*p++ = '\0';
146358112Seric 
146458112Seric 		if (isascii(*val) && isdigit(*val))
146558112Seric 		{
146658112Seric 			/* old syntax -- set everything */
146758112Seric 			TimeOuts.to_mail = convtime(val);
146858112Seric 			TimeOuts.to_rcpt = TimeOuts.to_mail;
146958112Seric 			TimeOuts.to_datainit = TimeOuts.to_mail;
147058112Seric 			TimeOuts.to_datablock = TimeOuts.to_mail;
147158112Seric 			TimeOuts.to_datafinal = TimeOuts.to_mail;
147258112Seric 			TimeOuts.to_nextcommand = TimeOuts.to_mail;
147358112Seric 			continue;
147458112Seric 		}
147558112Seric 		else
147658112Seric 		{
147758112Seric 			register char *q = strchr(val, '=');
147858112Seric 			time_t to;
147958112Seric 
148058112Seric 			if (q == NULL)
148158112Seric 			{
148258112Seric 				/* syntax error */
148358112Seric 				continue;
148458112Seric 			}
148558112Seric 			*q++ = '\0';
148658112Seric 			to = convtime(q);
148758112Seric 
148858112Seric 			if (strcasecmp(val, "initial") == 0)
148958112Seric 				TimeOuts.to_initial = to;
149058112Seric 			else if (strcasecmp(val, "mail") == 0)
149158112Seric 				TimeOuts.to_mail = to;
149258112Seric 			else if (strcasecmp(val, "rcpt") == 0)
149358112Seric 				TimeOuts.to_rcpt = to;
149458112Seric 			else if (strcasecmp(val, "datainit") == 0)
149558112Seric 				TimeOuts.to_datainit = to;
149658112Seric 			else if (strcasecmp(val, "datablock") == 0)
149758112Seric 				TimeOuts.to_datablock = to;
149858112Seric 			else if (strcasecmp(val, "datafinal") == 0)
149958112Seric 				TimeOuts.to_datafinal = to;
150058112Seric 			else if (strcasecmp(val, "command") == 0)
150158112Seric 				TimeOuts.to_nextcommand = to;
150258112Seric 			else if (strcasecmp(val, "rset") == 0)
150358112Seric 				TimeOuts.to_rset = to;
150458112Seric 			else if (strcasecmp(val, "helo") == 0)
150558112Seric 				TimeOuts.to_helo = to;
150658112Seric 			else if (strcasecmp(val, "quit") == 0)
150758112Seric 				TimeOuts.to_quit = to;
150858112Seric 			else if (strcasecmp(val, "misc") == 0)
150958112Seric 				TimeOuts.to_miscshort = to;
151058112Seric 			else
151158112Seric 				syserr("settimeouts: invalid timeout %s", val);
151258112Seric 		}
151358112Seric 	}
151458112Seric }
1515