xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 36238)
122709Sdist /*
234921Sbostic  * Copyright (c) 1983 Eric P. Allman
333731Sbostic  * Copyright (c) 1988 Regents of the University of California.
433731Sbostic  * All rights reserved.
533731Sbostic  *
633731Sbostic  * Redistribution and use in source and binary forms are permitted
734921Sbostic  * provided that the above copyright notice and this paragraph are
834921Sbostic  * duplicated in all such forms and that any documentation,
934921Sbostic  * advertising materials, and other materials related to such
1034921Sbostic  * distribution and use acknowledge that the software was developed
1134921Sbostic  * by the University of California, Berkeley.  The name of the
1234921Sbostic  * University may not be used to endorse or promote products derived
1334921Sbostic  * from this software without specific prior written permission.
1434921Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1534921Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1634921Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1733731Sbostic  */
1822709Sdist 
1922709Sdist #ifndef lint
20*36238Skarels static char sccsid[] = "@(#)readcf.c	5.15 (Berkeley) 11/18/88";
2133731Sbostic #endif /* not lint */
2222709Sdist 
233313Seric # include "sendmail.h"
243308Seric 
253308Seric /*
263308Seric **  READCF -- read control file.
273308Seric **
283308Seric **	This routine reads the control file and builds the internal
293308Seric **	form.
303308Seric **
314432Seric **	The file is formatted as a sequence of lines, each taken
324432Seric **	atomically.  The first character of each line describes how
334432Seric **	the line is to be interpreted.  The lines are:
344432Seric **		Dxval		Define macro x to have value val.
354432Seric **		Cxword		Put word into class x.
364432Seric **		Fxfile [fmt]	Read file for lines to put into
374432Seric **				class x.  Use scanf string 'fmt'
384432Seric **				or "%s" if not present.  Fmt should
394432Seric **				only produce one string-valued result.
404432Seric **		Hname: value	Define header with field-name 'name'
414432Seric **				and value as specified; this will be
424432Seric **				macro expanded immediately before
434432Seric **				use.
444432Seric **		Sn		Use rewriting set n.
454432Seric **		Rlhs rhs	Rewrite addresses that match lhs to
464432Seric **				be rhs.
4724944Seric **		Mn arg=val...	Define mailer.  n is the internal name.
4824944Seric **				Args specify mailer parameters.
498252Seric **		Oxvalue		Set option x to value.
508252Seric **		Pname=value	Set precedence name to value.
514432Seric **
523308Seric **	Parameters:
533308Seric **		cfname -- control file name.
543308Seric **
553308Seric **	Returns:
563308Seric **		none.
573308Seric **
583308Seric **	Side Effects:
593308Seric **		Builds several internal tables.
603308Seric */
613308Seric 
6221066Seric readcf(cfname)
633308Seric 	char *cfname;
643308Seric {
653308Seric 	FILE *cf;
668547Seric 	int ruleset = 0;
678547Seric 	char *q;
688547Seric 	char **pv;
699350Seric 	struct rewrite *rwp = NULL;
703308Seric 	char buf[MAXLINE];
713308Seric 	register char *p;
723308Seric 	extern char **prescan();
733308Seric 	extern char **copyplist();
745909Seric 	char exbuf[MAXLINE];
7516915Seric 	char pvpbuf[PSBUFSIZE];
769350Seric 	extern char *fgetfolded();
7710709Seric 	extern char *munchstring();
783308Seric 
793308Seric 	cf = fopen(cfname, "r");
803308Seric 	if (cf == NULL)
813308Seric 	{
823308Seric 		syserr("cannot open %s", cfname);
833308Seric 		exit(EX_OSFILE);
843308Seric 	}
853308Seric 
869381Seric 	FileName = cfname;
878056Seric 	LineNumber = 0;
887854Seric 	while (fgetfolded(buf, sizeof buf, cf) != NULL)
893308Seric 	{
9016157Seric 		/* map $ into \001 (ASCII SOH) for macro expansion */
9116157Seric 		for (p = buf; *p != '\0'; p++)
9216157Seric 		{
9316157Seric 			if (*p != '$')
9416157Seric 				continue;
9516157Seric 
9616157Seric 			if (p[1] == '$')
9716157Seric 			{
9816157Seric 				/* actual dollar sign.... */
9923111Seric 				(void) strcpy(p, p + 1);
10016157Seric 				continue;
10116157Seric 			}
10216157Seric 
10316157Seric 			/* convert to macro expansion character */
10416157Seric 			*p = '\001';
10516157Seric 		}
10616157Seric 
10716157Seric 		/* interpret this line */
1083308Seric 		switch (buf[0])
1093308Seric 		{
1103308Seric 		  case '\0':
1113308Seric 		  case '#':		/* comment */
1123308Seric 			break;
1133308Seric 
1143308Seric 		  case 'R':		/* rewriting rule */
1153308Seric 			for (p = &buf[1]; *p != '\0' && *p != '\t'; p++)
1163308Seric 				continue;
1173308Seric 
1183308Seric 			if (*p == '\0')
1195909Seric 			{
1209381Seric 				syserr("invalid rewrite line \"%s\"", buf);
1215909Seric 				break;
1225909Seric 			}
1235909Seric 
1245909Seric 			/* allocate space for the rule header */
1255909Seric 			if (rwp == NULL)
1265909Seric 			{
1275909Seric 				RewriteRules[ruleset] = rwp =
1285909Seric 					(struct rewrite *) xalloc(sizeof *rwp);
1295909Seric 			}
1303308Seric 			else
1313308Seric 			{
1325909Seric 				rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
1335909Seric 				rwp = rwp->r_next;
1345909Seric 			}
1355909Seric 			rwp->r_next = NULL;
1363308Seric 
1375909Seric 			/* expand and save the LHS */
1385909Seric 			*p = '\0';
1396991Seric 			expand(&buf[1], exbuf, &exbuf[sizeof exbuf], CurEnv);
14016915Seric 			rwp->r_lhs = prescan(exbuf, '\t', pvpbuf);
1415909Seric 			if (rwp->r_lhs != NULL)
1425909Seric 				rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
1435909Seric 
1445909Seric 			/* expand and save the RHS */
1455909Seric 			while (*++p == '\t')
1465909Seric 				continue;
1477231Seric 			q = p;
1487231Seric 			while (*p != '\0' && *p != '\t')
1497231Seric 				p++;
1507231Seric 			*p = '\0';
1517231Seric 			expand(q, exbuf, &exbuf[sizeof exbuf], CurEnv);
15216915Seric 			rwp->r_rhs = prescan(exbuf, '\t', pvpbuf);
1535909Seric 			if (rwp->r_rhs != NULL)
1545909Seric 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
1553308Seric 			break;
1563308Seric 
1574072Seric 		  case 'S':		/* select rewriting set */
1584072Seric 			ruleset = atoi(&buf[1]);
1598056Seric 			if (ruleset >= MAXRWSETS || ruleset < 0)
1608056Seric 			{
1619381Seric 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
1628056Seric 				ruleset = 0;
1638056Seric 			}
1644072Seric 			rwp = NULL;
1654072Seric 			break;
1664072Seric 
1673308Seric 		  case 'D':		/* macro definition */
16810709Seric 			define(buf[1], newstr(munchstring(&buf[2])), CurEnv);
1693308Seric 			break;
1703308Seric 
1713387Seric 		  case 'H':		/* required header line */
1724088Seric 			(void) chompheader(&buf[1], TRUE);
1733387Seric 			break;
1743387Seric 
1754061Seric 		  case 'C':		/* word class */
1764432Seric 		  case 'F':		/* word class from file */
1774432Seric 			/* read list of words from argument or file */
1784432Seric 			if (buf[0] == 'F')
1794432Seric 			{
1804432Seric 				/* read from file */
1814432Seric 				for (p = &buf[2]; *p != '\0' && !isspace(*p); p++)
1824432Seric 					continue;
1834432Seric 				if (*p == '\0')
1844432Seric 					p = "%s";
1854432Seric 				else
1864432Seric 				{
1874432Seric 					*p = '\0';
1884432Seric 					while (isspace(*++p))
1894432Seric 						continue;
1904432Seric 				}
19110687Seric 				fileclass(buf[1], &buf[2], p);
1924432Seric 				break;
1934432Seric 			}
1944061Seric 
1954432Seric 			/* scan the list of words and set class for all */
1964061Seric 			for (p = &buf[2]; *p != '\0'; )
1974061Seric 			{
1984061Seric 				register char *wd;
1994061Seric 				char delim;
2004061Seric 
2014061Seric 				while (*p != '\0' && isspace(*p))
2024061Seric 					p++;
2034061Seric 				wd = p;
2044061Seric 				while (*p != '\0' && !isspace(*p))
2054061Seric 					p++;
2064061Seric 				delim = *p;
2074061Seric 				*p = '\0';
2084061Seric 				if (wd[0] != '\0')
20910687Seric 					setclass(buf[1], wd);
2104061Seric 				*p = delim;
2114061Seric 			}
2124061Seric 			break;
2134061Seric 
2144096Seric 		  case 'M':		/* define mailer */
21521066Seric 			makemailer(&buf[1]);
2164096Seric 			break;
2174096Seric 
2188252Seric 		  case 'O':		/* set option */
21921755Seric 			setoption(buf[1], &buf[2], TRUE, FALSE);
2208252Seric 			break;
2218252Seric 
2228252Seric 		  case 'P':		/* set precedence */
2238252Seric 			if (NumPriorities >= MAXPRIORITIES)
2248252Seric 			{
2258547Seric 				toomany('P', MAXPRIORITIES);
2268252Seric 				break;
2278252Seric 			}
2289381Seric 			for (p = &buf[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
2298252Seric 				continue;
2308252Seric 			if (*p == '\0')
2318252Seric 				goto badline;
2328252Seric 			*p = '\0';
2338252Seric 			Priorities[NumPriorities].pri_name = newstr(&buf[1]);
2348252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
2358252Seric 			NumPriorities++;
2368252Seric 			break;
2378252Seric 
2388547Seric 		  case 'T':		/* trusted user(s) */
2398547Seric 			p = &buf[1];
2408547Seric 			while (*p != '\0')
2418547Seric 			{
2428547Seric 				while (isspace(*p))
2438547Seric 					p++;
2448547Seric 				q = p;
2458547Seric 				while (*p != '\0' && !isspace(*p))
2468547Seric 					p++;
2478547Seric 				if (*p != '\0')
2488547Seric 					*p++ = '\0';
2498547Seric 				if (*q == '\0')
2508547Seric 					continue;
2518547Seric 				for (pv = TrustedUsers; *pv != NULL; pv++)
2528547Seric 					continue;
2538547Seric 				if (pv >= &TrustedUsers[MAXTRUST])
2548547Seric 				{
2558547Seric 					toomany('T', MAXTRUST);
2568547Seric 					break;
2578547Seric 				}
2588547Seric 				*pv = newstr(q);
2598547Seric 			}
2608547Seric 			break;
2618547Seric 
2623308Seric 		  default:
2634061Seric 		  badline:
2649381Seric 			syserr("unknown control line \"%s\"", buf);
2653308Seric 		}
2663308Seric 	}
2679381Seric 	FileName = NULL;
2684096Seric }
2694096Seric /*
2708547Seric **  TOOMANY -- signal too many of some option
2718547Seric **
2728547Seric **	Parameters:
2738547Seric **		id -- the id of the error line
2748547Seric **		maxcnt -- the maximum possible values
2758547Seric **
2768547Seric **	Returns:
2778547Seric **		none.
2788547Seric **
2798547Seric **	Side Effects:
2808547Seric **		gives a syserr.
2818547Seric */
2828547Seric 
2838547Seric toomany(id, maxcnt)
2848547Seric 	char id;
2858547Seric 	int maxcnt;
2868547Seric {
2879381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
2888547Seric }
2898547Seric /*
2904432Seric **  FILECLASS -- read members of a class from a file
2914432Seric **
2924432Seric **	Parameters:
2934432Seric **		class -- class to define.
2944432Seric **		filename -- name of file to read.
2954432Seric **		fmt -- scanf string to use for match.
2964432Seric **
2974432Seric **	Returns:
2984432Seric **		none
2994432Seric **
3004432Seric **	Side Effects:
3014432Seric **
3024432Seric **		puts all lines in filename that match a scanf into
3034432Seric **			the named class.
3044432Seric */
3054432Seric 
3064432Seric fileclass(class, filename, fmt)
3074432Seric 	int class;
3084432Seric 	char *filename;
3094432Seric 	char *fmt;
3104432Seric {
31125808Seric 	FILE *f;
3124432Seric 	char buf[MAXLINE];
3134432Seric 
3144432Seric 	f = fopen(filename, "r");
3154432Seric 	if (f == NULL)
3164432Seric 	{
3174432Seric 		syserr("cannot open %s", filename);
3184432Seric 		return;
3194432Seric 	}
3204432Seric 
3214432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
3224432Seric 	{
3234432Seric 		register STAB *s;
32425808Seric 		register char *p;
32525808Seric # ifdef SCANF
3264432Seric 		char wordbuf[MAXNAME+1];
3274432Seric 
3284432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
3294432Seric 			continue;
33025808Seric 		p = wordbuf;
33125808Seric # else SCANF
33225808Seric 		p = buf;
33325808Seric # endif SCANF
33425808Seric 
33525808Seric 		/*
33625808Seric 		**  Break up the match into words.
33725808Seric 		*/
33825808Seric 
33925808Seric 		while (*p != '\0')
34025808Seric 		{
34125808Seric 			register char *q;
34225808Seric 
34325808Seric 			/* strip leading spaces */
34425808Seric 			while (isspace(*p))
34525808Seric 				p++;
34625808Seric 			if (*p == '\0')
34725808Seric 				break;
34825808Seric 
34925808Seric 			/* find the end of the word */
35025808Seric 			q = p;
35125808Seric 			while (*p != '\0' && !isspace(*p))
35225808Seric 				p++;
35325808Seric 			if (*p != '\0')
35425808Seric 				*p++ = '\0';
35525808Seric 
35625808Seric 			/* enter the word in the symbol table */
35725808Seric 			s = stab(q, ST_CLASS, ST_ENTER);
35825808Seric 			setbitn(class, s->s_class);
35925808Seric 		}
3604432Seric 	}
3614432Seric 
3624627Seric 	(void) fclose(f);
3634432Seric }
3644432Seric /*
3654096Seric **  MAKEMAILER -- define a new mailer.
3664096Seric **
3674096Seric **	Parameters:
36810327Seric **		line -- description of mailer.  This is in labeled
36910327Seric **			fields.  The fields are:
37010327Seric **			   P -- the path to the mailer
37110327Seric **			   F -- the flags associated with the mailer
37210327Seric **			   A -- the argv for this mailer
37310327Seric **			   S -- the sender rewriting set
37410327Seric **			   R -- the recipient rewriting set
37510327Seric **			   E -- the eol string
37610327Seric **			The first word is the canonical name of the mailer.
3774096Seric **
3784096Seric **	Returns:
3794096Seric **		none.
3804096Seric **
3814096Seric **	Side Effects:
3824096Seric **		enters the mailer into the mailer table.
3834096Seric */
3843308Seric 
38521066Seric makemailer(line)
3864096Seric 	char *line;
3874096Seric {
3884096Seric 	register char *p;
3898067Seric 	register struct mailer *m;
3908067Seric 	register STAB *s;
3918067Seric 	int i;
39210327Seric 	char fcode;
3934096Seric 	extern int NextMailer;
39410327Seric 	extern char **makeargv();
39510327Seric 	extern char *munchstring();
39610327Seric 	extern char *DelimChar;
39710701Seric 	extern long atol();
3984096Seric 
39910327Seric 	/* allocate a mailer and set up defaults */
40010327Seric 	m = (struct mailer *) xalloc(sizeof *m);
40110327Seric 	bzero((char *) m, sizeof *m);
40210327Seric 	m->m_mno = NextMailer;
40310327Seric 	m->m_eol = "\n";
40410327Seric 
40510327Seric 	/* collect the mailer name */
40610327Seric 	for (p = line; *p != '\0' && *p != ',' && !isspace(*p); p++)
40710327Seric 		continue;
40810327Seric 	if (*p != '\0')
40910327Seric 		*p++ = '\0';
41010327Seric 	m->m_name = newstr(line);
41110327Seric 
41210327Seric 	/* now scan through and assign info from the fields */
41310327Seric 	while (*p != '\0')
41410327Seric 	{
41510327Seric 		while (*p != '\0' && (*p == ',' || isspace(*p)))
41610327Seric 			p++;
41710327Seric 
41810327Seric 		/* p now points to field code */
41910327Seric 		fcode = *p;
42010327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
42110327Seric 			p++;
42210327Seric 		if (*p++ != '=')
42310327Seric 		{
42410327Seric 			syserr("`=' expected");
42510327Seric 			return;
42610327Seric 		}
42710327Seric 		while (isspace(*p))
42810327Seric 			p++;
42910327Seric 
43010327Seric 		/* p now points to the field body */
43110327Seric 		p = munchstring(p);
43210327Seric 
43310327Seric 		/* install the field into the mailer struct */
43410327Seric 		switch (fcode)
43510327Seric 		{
43610327Seric 		  case 'P':		/* pathname */
43710327Seric 			m->m_mailer = newstr(p);
43810327Seric 			break;
43910327Seric 
44010327Seric 		  case 'F':		/* flags */
44110687Seric 			for (; *p != '\0'; p++)
44210687Seric 				setbitn(*p, m->m_flags);
44310327Seric 			break;
44410327Seric 
44510327Seric 		  case 'S':		/* sender rewriting ruleset */
44610327Seric 		  case 'R':		/* recipient rewriting ruleset */
44710327Seric 			i = atoi(p);
44810327Seric 			if (i < 0 || i >= MAXRWSETS)
44910327Seric 			{
45010327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
45110327Seric 				return;
45210327Seric 			}
45310327Seric 			if (fcode == 'S')
45410327Seric 				m->m_s_rwset = i;
45510327Seric 			else
45610327Seric 				m->m_r_rwset = i;
45710327Seric 			break;
45810327Seric 
45910327Seric 		  case 'E':		/* end of line string */
46010327Seric 			m->m_eol = newstr(p);
46110327Seric 			break;
46210327Seric 
46310327Seric 		  case 'A':		/* argument vector */
46410327Seric 			m->m_argv = makeargv(p);
46510327Seric 			break;
46610701Seric 
46710701Seric 		  case 'M':		/* maximum message size */
46810701Seric 			m->m_maxsize = atol(p);
46910701Seric 			break;
47010327Seric 		}
47110327Seric 
47210327Seric 		p = DelimChar;
47310327Seric 	}
47410327Seric 
47510327Seric 	/* now store the mailer away */
4764096Seric 	if (NextMailer >= MAXMAILERS)
4774096Seric 	{
4789381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
4794096Seric 		return;
4804096Seric 	}
48110327Seric 	Mailer[NextMailer++] = m;
48210327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
48310327Seric 	s->s_mailer = m;
48410327Seric }
48510327Seric /*
48610327Seric **  MUNCHSTRING -- translate a string into internal form.
48710327Seric **
48810327Seric **	Parameters:
48910327Seric **		p -- the string to munch.
49010327Seric **
49110327Seric **	Returns:
49210327Seric **		the munched string.
49310327Seric **
49410327Seric **	Side Effects:
49510327Seric **		Sets "DelimChar" to point to the string that caused us
49610327Seric **		to stop.
49710327Seric */
4984096Seric 
49910327Seric char *
50010327Seric munchstring(p)
50110327Seric 	register char *p;
50210327Seric {
50310327Seric 	register char *q;
50410327Seric 	bool backslash = FALSE;
50510327Seric 	bool quotemode = FALSE;
50610327Seric 	static char buf[MAXLINE];
50710327Seric 	extern char *DelimChar;
5084096Seric 
50910327Seric 	for (q = buf; *p != '\0'; p++)
5104096Seric 	{
51110327Seric 		if (backslash)
51210327Seric 		{
51310327Seric 			/* everything is roughly literal */
51410357Seric 			backslash = FALSE;
51510327Seric 			switch (*p)
51610327Seric 			{
51710327Seric 			  case 'r':		/* carriage return */
51810327Seric 				*q++ = '\r';
51910327Seric 				continue;
52010327Seric 
52110327Seric 			  case 'n':		/* newline */
52210327Seric 				*q++ = '\n';
52310327Seric 				continue;
52410327Seric 
52510327Seric 			  case 'f':		/* form feed */
52610327Seric 				*q++ = '\f';
52710327Seric 				continue;
52810327Seric 
52910327Seric 			  case 'b':		/* backspace */
53010327Seric 				*q++ = '\b';
53110327Seric 				continue;
53210327Seric 			}
53310327Seric 			*q++ = *p;
53410327Seric 		}
53510327Seric 		else
53610327Seric 		{
53710327Seric 			if (*p == '\\')
53810327Seric 				backslash = TRUE;
53910327Seric 			else if (*p == '"')
54010327Seric 				quotemode = !quotemode;
54110327Seric 			else if (quotemode || *p != ',')
54210327Seric 				*q++ = *p;
54310327Seric 			else
54410327Seric 				break;
54510327Seric 		}
5464096Seric 	}
5474096Seric 
54810327Seric 	DelimChar = p;
54910327Seric 	*q++ = '\0';
55010327Seric 	return (buf);
55110327Seric }
55210327Seric /*
55310327Seric **  MAKEARGV -- break up a string into words
55410327Seric **
55510327Seric **	Parameters:
55610327Seric **		p -- the string to break up.
55710327Seric **
55810327Seric **	Returns:
55910327Seric **		a char **argv (dynamically allocated)
56010327Seric **
56110327Seric **	Side Effects:
56210327Seric **		munges p.
56310327Seric */
5644096Seric 
56510327Seric char **
56610327Seric makeargv(p)
56710327Seric 	register char *p;
56810327Seric {
56910327Seric 	char *q;
57010327Seric 	int i;
57110327Seric 	char **avp;
57210327Seric 	char *argv[MAXPV + 1];
57310327Seric 
57410327Seric 	/* take apart the words */
57510327Seric 	i = 0;
57610327Seric 	while (*p != '\0' && i < MAXPV)
5774096Seric 	{
57810327Seric 		q = p;
57910327Seric 		while (*p != '\0' && !isspace(*p))
58010327Seric 			p++;
58110327Seric 		while (isspace(*p))
58210327Seric 			*p++ = '\0';
58310327Seric 		argv[i++] = newstr(q);
5844096Seric 	}
58510327Seric 	argv[i++] = NULL;
5864096Seric 
58710327Seric 	/* now make a copy of the argv */
58810327Seric 	avp = (char **) xalloc(sizeof *avp * i);
58916893Seric 	bcopy((char *) argv, (char *) avp, sizeof *avp * i);
59010327Seric 
59110327Seric 	return (avp);
5923308Seric }
5933308Seric /*
5943308Seric **  PRINTRULES -- print rewrite rules (for debugging)
5953308Seric **
5963308Seric **	Parameters:
5973308Seric **		none.
5983308Seric **
5993308Seric **	Returns:
6003308Seric **		none.
6013308Seric **
6023308Seric **	Side Effects:
6033308Seric **		prints rewrite rules.
6043308Seric */
6053308Seric 
6064319Seric # ifdef DEBUG
6074319Seric 
6083308Seric printrules()
6093308Seric {
6103308Seric 	register struct rewrite *rwp;
6114072Seric 	register int ruleset;
6123308Seric 
6134072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
6143308Seric 	{
6154072Seric 		if (RewriteRules[ruleset] == NULL)
6164072Seric 			continue;
6178067Seric 		printf("\n----Rule Set %d:", ruleset);
6183308Seric 
6194072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
6203308Seric 		{
6218067Seric 			printf("\nLHS:");
6228067Seric 			printav(rwp->r_lhs);
6238067Seric 			printf("RHS:");
6248067Seric 			printav(rwp->r_rhs);
6253308Seric 		}
6263308Seric 	}
6273308Seric }
6284319Seric 
6294319Seric # endif DEBUG
6304096Seric /*
6318256Seric **  SETOPTION -- set global processing option
6328256Seric **
6338256Seric **	Parameters:
6348256Seric **		opt -- option name.
6358256Seric **		val -- option value (as a text string).
63621755Seric **		safe -- set if this came from a configuration file.
63721755Seric **			Some options (if set from the command line) will
63821755Seric **			reset the user id to avoid security problems.
6398269Seric **		sticky -- if set, don't let other setoptions override
6408269Seric **			this value.
6418256Seric **
6428256Seric **	Returns:
6438256Seric **		none.
6448256Seric **
6458256Seric **	Side Effects:
6468256Seric **		Sets options as implied by the arguments.
6478256Seric */
6488256Seric 
64910687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
65025700Seric extern char	*NetName;		/* name of home (local) network */
65125700Seric # ifdef SMTP
65225700Seric # ifdef WIZ
65310687Seric extern char	*WizWord;		/* the stored wizard password */
65425700Seric # endif WIZ
65525700Seric # endif SMTP
6568269Seric 
65721755Seric setoption(opt, val, safe, sticky)
6588256Seric 	char opt;
6598256Seric 	char *val;
66021755Seric 	bool safe;
6618269Seric 	bool sticky;
6628256Seric {
6638265Seric 	extern bool atobool();
66412633Seric 	extern time_t convtime();
66514879Seric 	extern int QueueLA;
66614879Seric 	extern int RefuseLA;
66717474Seric 	extern bool trusteduser();
66817474Seric 	extern char *username();
6698256Seric 
6708256Seric # ifdef DEBUG
6718256Seric 	if (tTd(37, 1))
6729341Seric 		printf("setoption %c=%s", opt, val);
6738256Seric # endif DEBUG
6748256Seric 
6758256Seric 	/*
6768269Seric 	**  See if this option is preset for us.
6778256Seric 	*/
6788256Seric 
67910687Seric 	if (bitnset(opt, StickyOpt))
6808269Seric 	{
6818269Seric # ifdef DEBUG
6829341Seric 		if (tTd(37, 1))
6839341Seric 			printf(" (ignored)\n");
6848269Seric # endif DEBUG
6858269Seric 		return;
6868269Seric 	}
6878269Seric 
68821755Seric 	/*
68921755Seric 	**  Check to see if this option can be specified by this user.
69021755Seric 	*/
69121755Seric 
692*36238Skarels 	if (!safe && getuid() == 0)
69321755Seric 		safe = TRUE;
69421755Seric 	if (!safe && index("deiLmorsv", opt) == NULL)
69521755Seric 	{
69621755Seric # ifdef DEBUG
69721755Seric 		if (tTd(37, 1))
69821755Seric 			printf(" (unsafe)");
69921755Seric # endif DEBUG
700*36238Skarels 		if (getuid() != geteuid())
70121755Seric 		{
70221755Seric 			printf("(Resetting uid)\n");
70323111Seric 			(void) setgid(getgid());
70423111Seric 			(void) setuid(getuid());
70521755Seric 		}
70621755Seric 	}
70717985Seric #ifdef DEBUG
70821755Seric 	else if (tTd(37, 1))
70917985Seric 		printf("\n");
71017985Seric #endif DEBUG
7118269Seric 
7128256Seric 	switch (opt)
7138256Seric 	{
7148256Seric 	  case 'A':		/* set default alias file */
7159381Seric 		if (val[0] == '\0')
7168269Seric 			AliasFile = "aliases";
7179381Seric 		else
7189381Seric 			AliasFile = newstr(val);
7198256Seric 		break;
7208256Seric 
72117474Seric 	  case 'a':		/* look N minutes for "@:@" in alias file */
72217474Seric 		if (val[0] == '\0')
72317474Seric 			SafeAlias = 5;
72417474Seric 		else
72517474Seric 			SafeAlias = atoi(val);
72617474Seric 		break;
72717474Seric 
72816843Seric 	  case 'B':		/* substitution for blank character */
72916843Seric 		SpaceSub = val[0];
73016843Seric 		if (SpaceSub == '\0')
73116843Seric 			SpaceSub = ' ';
73216843Seric 		break;
73316843Seric 
7349284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
7359381Seric 		NoConnect = atobool(val);
7369284Seric 		break;
7379284Seric 
73824944Seric 	  case 'C':		/* checkpoint after N connections */
73924944Seric 		CheckPointLimit = atoi(val);
74024944Seric 		break;
74124944Seric 
7429284Seric 	  case 'd':		/* delivery mode */
7439284Seric 		switch (*val)
7448269Seric 		{
7459284Seric 		  case '\0':
7469284Seric 			SendMode = SM_DELIVER;
7478269Seric 			break;
7488269Seric 
74910755Seric 		  case SM_QUEUE:	/* queue only */
75010755Seric #ifndef QUEUE
75110755Seric 			syserr("need QUEUE to set -odqueue");
75210755Seric #endif QUEUE
75310755Seric 			/* fall through..... */
75410755Seric 
7559284Seric 		  case SM_DELIVER:	/* do everything */
7569284Seric 		  case SM_FORK:		/* fork after verification */
7579284Seric 			SendMode = *val;
7588269Seric 			break;
7598269Seric 
7608269Seric 		  default:
7619284Seric 			syserr("Unknown delivery mode %c", *val);
7628269Seric 			exit(EX_USAGE);
7638269Seric 		}
7648269Seric 		break;
7658269Seric 
7669146Seric 	  case 'D':		/* rebuild alias database as needed */
7679381Seric 		AutoRebuild = atobool(val);
7689146Seric 		break;
7699146Seric 
7708269Seric 	  case 'e':		/* set error processing mode */
7718269Seric 		switch (*val)
7728269Seric 		{
7739381Seric 		  case EM_QUIET:	/* be silent about it */
7749381Seric 		  case EM_MAIL:		/* mail back */
7759381Seric 		  case EM_BERKNET:	/* do berknet error processing */
7769381Seric 		  case EM_WRITE:	/* write back (or mail) */
7778269Seric 			HoldErrs = TRUE;
7789381Seric 			/* fall through... */
7798269Seric 
7809381Seric 		  case EM_PRINT:	/* print errors normally (default) */
7819381Seric 			ErrorMode = *val;
7828269Seric 			break;
7838269Seric 		}
7848269Seric 		break;
7858269Seric 
7869049Seric 	  case 'F':		/* file mode */
78717975Seric 		FileMode = atooct(val) & 0777;
7889049Seric 		break;
7899049Seric 
7908269Seric 	  case 'f':		/* save Unix-style From lines on front */
7919381Seric 		SaveFrom = atobool(val);
7928269Seric 		break;
7938269Seric 
7948256Seric 	  case 'g':		/* default gid */
79517474Seric 		DefGid = atoi(val);
7968256Seric 		break;
7978256Seric 
7988256Seric 	  case 'H':		/* help file */
7999381Seric 		if (val[0] == '\0')
8008269Seric 			HelpFile = "sendmail.hf";
8019381Seric 		else
8029381Seric 			HelpFile = newstr(val);
8038256Seric 		break;
8048256Seric 
80535651Seric 	  case 'I':		/* use internet domain name server */
80635651Seric 		UseNameServer = atobool(val);
80735651Seric 		break;
80835651Seric 
8098269Seric 	  case 'i':		/* ignore dot lines in message */
8109381Seric 		IgnrDot = atobool(val);
8118269Seric 		break;
8128269Seric 
8138256Seric 	  case 'L':		/* log level */
8149381Seric 		LogLevel = atoi(val);
8158256Seric 		break;
8168256Seric 
8178269Seric 	  case 'M':		/* define macro */
8189381Seric 		define(val[0], newstr(&val[1]), CurEnv);
81916878Seric 		sticky = FALSE;
8208269Seric 		break;
8218269Seric 
8228269Seric 	  case 'm':		/* send to me too */
8239381Seric 		MeToo = atobool(val);
8248269Seric 		break;
8258269Seric 
82625820Seric 	  case 'n':		/* validate RHS in newaliases */
82725820Seric 		CheckAliases = atobool(val);
82825820Seric 		break;
82925820Seric 
83016143Seric # ifdef DAEMON
83116143Seric 	  case 'N':		/* home (local?) network name */
83216143Seric 		NetName = newstr(val);
83316143Seric 		break;
83416143Seric # endif DAEMON
83516143Seric 
8368269Seric 	  case 'o':		/* assume old style headers */
8379381Seric 		if (atobool(val))
8389341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
8399341Seric 		else
8409341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
8418269Seric 		break;
8428269Seric 
84324944Seric 	  case 'P':		/* postmaster copy address for returned mail */
84424944Seric 		PostMasterCopy = newstr(val);
84524944Seric 		break;
84624944Seric 
84724944Seric 	  case 'q':		/* slope of queue only function */
84824944Seric 		QueueFactor = atoi(val);
84924944Seric 		break;
85024944Seric 
8518256Seric 	  case 'Q':		/* queue directory */
8529381Seric 		if (val[0] == '\0')
8538269Seric 			QueueDir = "mqueue";
8549381Seric 		else
8559381Seric 			QueueDir = newstr(val);
8568256Seric 		break;
8578256Seric 
8588256Seric 	  case 'r':		/* read timeout */
8599381Seric 		ReadTimeout = convtime(val);
8608256Seric 		break;
8618256Seric 
8628256Seric 	  case 'S':		/* status file */
8639381Seric 		if (val[0] == '\0')
8648269Seric 			StatFile = "sendmail.st";
8659381Seric 		else
8669381Seric 			StatFile = newstr(val);
8678256Seric 		break;
8688256Seric 
8698265Seric 	  case 's':		/* be super safe, even if expensive */
8709381Seric 		SuperSafe = atobool(val);
8718256Seric 		break;
8728256Seric 
8738256Seric 	  case 'T':		/* queue timeout */
8749381Seric 		TimeOut = convtime(val);
87533936Sbostic 		/*FALLTHROUGH*/
8768256Seric 
8778265Seric 	  case 't':		/* time zone name */
8788265Seric 		break;
8798265Seric 
8808256Seric 	  case 'u':		/* set default uid */
88117474Seric 		DefUid = atoi(val);
8828256Seric 		break;
8838256Seric 
8848269Seric 	  case 'v':		/* run in verbose mode */
8859381Seric 		Verbose = atobool(val);
8868256Seric 		break;
8878256Seric 
88825700Seric # ifdef SMTP
88925700Seric # ifdef WIZ
8908544Seric 	  case 'W':		/* set the wizards password */
89117474Seric 		WizWord = newstr(val);
8928544Seric 		break;
89325700Seric # endif WIZ
89425700Seric # endif SMTP
8958544Seric 
89614879Seric 	  case 'x':		/* load avg at which to auto-queue msgs */
89714879Seric 		QueueLA = atoi(val);
89814879Seric 		break;
89914879Seric 
90014879Seric 	  case 'X':		/* load avg at which to auto-reject connections */
90114879Seric 		RefuseLA = atoi(val);
90214879Seric 		break;
90314879Seric 
90424981Seric 	  case 'y':		/* work recipient factor */
90524981Seric 		WkRecipFact = atoi(val);
90624981Seric 		break;
90724981Seric 
90824981Seric 	  case 'Y':		/* fork jobs during queue runs */
90924952Seric 		ForkQueueRuns = atobool(val);
91024952Seric 		break;
91124952Seric 
91224981Seric 	  case 'z':		/* work message class factor */
91324981Seric 		WkClassFact = atoi(val);
91424981Seric 		break;
91524981Seric 
91624981Seric 	  case 'Z':		/* work time factor */
91724981Seric 		WkTimeFact = atoi(val);
91824981Seric 		break;
91924981Seric 
9208256Seric 	  default:
9218256Seric 		break;
9228256Seric 	}
92316878Seric 	if (sticky)
92416878Seric 		setbitn(opt, StickyOpt);
9259188Seric 	return;
9268256Seric }
92710687Seric /*
92810687Seric **  SETCLASS -- set a word into a class
92910687Seric **
93010687Seric **	Parameters:
93110687Seric **		class -- the class to put the word in.
93210687Seric **		word -- the word to enter
93310687Seric **
93410687Seric **	Returns:
93510687Seric **		none.
93610687Seric **
93710687Seric **	Side Effects:
93810687Seric **		puts the word into the symbol table.
93910687Seric */
94010687Seric 
94110687Seric setclass(class, word)
94210687Seric 	int class;
94310687Seric 	char *word;
94410687Seric {
94510687Seric 	register STAB *s;
94610687Seric 
94710687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
94810687Seric 	setbitn(class, s->s_class);
94910687Seric }
950