xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 22709)
1*22709Sdist /*
2*22709Sdist **  Sendmail
3*22709Sdist **  Copyright (c) 1983  Eric P. Allman
4*22709Sdist **  Berkeley, California
5*22709Sdist **
6*22709Sdist **  Copyright (c) 1983 Regents of the University of California.
7*22709Sdist **  All rights reserved.  The Berkeley software License Agreement
8*22709Sdist **  specifies the terms and conditions for redistribution.
9*22709Sdist */
10*22709Sdist 
11*22709Sdist #ifndef lint
12*22709Sdist static char	SccsId[] = "@(#)readcf.c	5.1 (Berkeley) 06/07/85";
13*22709Sdist #endif not lint
14*22709Sdist 
153313Seric # include "sendmail.h"
163308Seric 
17*22709Sdist SCCSID(@(#)readcf.c	5.1		06/07/85);
183308Seric 
193308Seric /*
203308Seric **  READCF -- read control file.
213308Seric **
223308Seric **	This routine reads the control file and builds the internal
233308Seric **	form.
243308Seric **
254432Seric **	The file is formatted as a sequence of lines, each taken
264432Seric **	atomically.  The first character of each line describes how
274432Seric **	the line is to be interpreted.  The lines are:
284432Seric **		Dxval		Define macro x to have value val.
294432Seric **		Cxword		Put word into class x.
304432Seric **		Fxfile [fmt]	Read file for lines to put into
314432Seric **				class x.  Use scanf string 'fmt'
324432Seric **				or "%s" if not present.  Fmt should
334432Seric **				only produce one string-valued result.
344432Seric **		Hname: value	Define header with field-name 'name'
354432Seric **				and value as specified; this will be
364432Seric **				macro expanded immediately before
374432Seric **				use.
384432Seric **		Sn		Use rewriting set n.
394432Seric **		Rlhs rhs	Rewrite addresses that match lhs to
404432Seric **				be rhs.
418252Seric **		Mn p f s r a	Define mailer.  n - internal name,
428252Seric **				p - pathname, f - flags, s - rewriting
438252Seric **				ruleset for sender, s - rewriting ruleset
448252Seric **				for recipients, a - argument vector.
458252Seric **		Oxvalue		Set option x to value.
468252Seric **		Pname=value	Set precedence name to value.
474432Seric **
483308Seric **	Parameters:
493308Seric **		cfname -- control file name.
503308Seric **
513308Seric **	Returns:
523308Seric **		none.
533308Seric **
543308Seric **	Side Effects:
553308Seric **		Builds several internal tables.
563308Seric */
573308Seric 
5821066Seric readcf(cfname)
593308Seric 	char *cfname;
603308Seric {
613308Seric 	FILE *cf;
628547Seric 	int ruleset = 0;
638547Seric 	char *q;
648547Seric 	char **pv;
659350Seric 	struct rewrite *rwp = NULL;
663308Seric 	char buf[MAXLINE];
673308Seric 	register char *p;
683308Seric 	extern char **prescan();
693308Seric 	extern char **copyplist();
705909Seric 	char exbuf[MAXLINE];
7116915Seric 	char pvpbuf[PSBUFSIZE];
729350Seric 	extern char *fgetfolded();
7310709Seric 	extern char *munchstring();
743308Seric 
753308Seric 	cf = fopen(cfname, "r");
763308Seric 	if (cf == NULL)
773308Seric 	{
783308Seric 		syserr("cannot open %s", cfname);
793308Seric 		exit(EX_OSFILE);
803308Seric 	}
813308Seric 
829381Seric 	FileName = cfname;
838056Seric 	LineNumber = 0;
847854Seric 	while (fgetfolded(buf, sizeof buf, cf) != NULL)
853308Seric 	{
8616157Seric 		/* map $ into \001 (ASCII SOH) for macro expansion */
8716157Seric 		for (p = buf; *p != '\0'; p++)
8816157Seric 		{
8916157Seric 			if (*p != '$')
9016157Seric 				continue;
9116157Seric 
9216157Seric 			if (p[1] == '$')
9316157Seric 			{
9416157Seric 				/* actual dollar sign.... */
9516157Seric 				strcpy(p, p + 1);
9616157Seric 				continue;
9716157Seric 			}
9816157Seric 
9916157Seric 			/* convert to macro expansion character */
10016157Seric 			*p = '\001';
10116157Seric 		}
10216157Seric 
10316157Seric 		/* interpret this line */
1043308Seric 		switch (buf[0])
1053308Seric 		{
1063308Seric 		  case '\0':
1073308Seric 		  case '#':		/* comment */
1083308Seric 			break;
1093308Seric 
1103308Seric 		  case 'R':		/* rewriting rule */
1113308Seric 			for (p = &buf[1]; *p != '\0' && *p != '\t'; p++)
1123308Seric 				continue;
1133308Seric 
1143308Seric 			if (*p == '\0')
1155909Seric 			{
1169381Seric 				syserr("invalid rewrite line \"%s\"", buf);
1175909Seric 				break;
1185909Seric 			}
1195909Seric 
1205909Seric 			/* allocate space for the rule header */
1215909Seric 			if (rwp == NULL)
1225909Seric 			{
1235909Seric 				RewriteRules[ruleset] = rwp =
1245909Seric 					(struct rewrite *) xalloc(sizeof *rwp);
1255909Seric 			}
1263308Seric 			else
1273308Seric 			{
1285909Seric 				rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
1295909Seric 				rwp = rwp->r_next;
1305909Seric 			}
1315909Seric 			rwp->r_next = NULL;
1323308Seric 
1335909Seric 			/* expand and save the LHS */
1345909Seric 			*p = '\0';
1356991Seric 			expand(&buf[1], exbuf, &exbuf[sizeof exbuf], CurEnv);
13616915Seric 			rwp->r_lhs = prescan(exbuf, '\t', pvpbuf);
1375909Seric 			if (rwp->r_lhs != NULL)
1385909Seric 				rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
1395909Seric 
1405909Seric 			/* expand and save the RHS */
1415909Seric 			while (*++p == '\t')
1425909Seric 				continue;
1437231Seric 			q = p;
1447231Seric 			while (*p != '\0' && *p != '\t')
1457231Seric 				p++;
1467231Seric 			*p = '\0';
1477231Seric 			expand(q, exbuf, &exbuf[sizeof exbuf], CurEnv);
14816915Seric 			rwp->r_rhs = prescan(exbuf, '\t', pvpbuf);
1495909Seric 			if (rwp->r_rhs != NULL)
1505909Seric 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
1513308Seric 			break;
1523308Seric 
1534072Seric 		  case 'S':		/* select rewriting set */
1544072Seric 			ruleset = atoi(&buf[1]);
1558056Seric 			if (ruleset >= MAXRWSETS || ruleset < 0)
1568056Seric 			{
1579381Seric 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
1588056Seric 				ruleset = 0;
1598056Seric 			}
1604072Seric 			rwp = NULL;
1614072Seric 			break;
1624072Seric 
1633308Seric 		  case 'D':		/* macro definition */
16410709Seric 			define(buf[1], newstr(munchstring(&buf[2])), CurEnv);
1653308Seric 			break;
1663308Seric 
1673387Seric 		  case 'H':		/* required header line */
1684088Seric 			(void) chompheader(&buf[1], TRUE);
1693387Seric 			break;
1703387Seric 
1714061Seric 		  case 'C':		/* word class */
1724432Seric 		  case 'F':		/* word class from file */
1734432Seric 			/* read list of words from argument or file */
1744432Seric 			if (buf[0] == 'F')
1754432Seric 			{
1764432Seric 				/* read from file */
1774432Seric 				for (p = &buf[2]; *p != '\0' && !isspace(*p); p++)
1784432Seric 					continue;
1794432Seric 				if (*p == '\0')
1804432Seric 					p = "%s";
1814432Seric 				else
1824432Seric 				{
1834432Seric 					*p = '\0';
1844432Seric 					while (isspace(*++p))
1854432Seric 						continue;
1864432Seric 				}
18710687Seric 				fileclass(buf[1], &buf[2], p);
1884432Seric 				break;
1894432Seric 			}
1904061Seric 
1914432Seric 			/* scan the list of words and set class for all */
1924061Seric 			for (p = &buf[2]; *p != '\0'; )
1934061Seric 			{
1944061Seric 				register char *wd;
1954061Seric 				char delim;
1964061Seric 
1974061Seric 				while (*p != '\0' && isspace(*p))
1984061Seric 					p++;
1994061Seric 				wd = p;
2004061Seric 				while (*p != '\0' && !isspace(*p))
2014061Seric 					p++;
2024061Seric 				delim = *p;
2034061Seric 				*p = '\0';
2044061Seric 				if (wd[0] != '\0')
20510687Seric 					setclass(buf[1], wd);
2064061Seric 				*p = delim;
2074061Seric 			}
2084061Seric 			break;
2094061Seric 
2104096Seric 		  case 'M':		/* define mailer */
21121066Seric 			makemailer(&buf[1]);
2124096Seric 			break;
2134096Seric 
2148252Seric 		  case 'O':		/* set option */
21521755Seric 			setoption(buf[1], &buf[2], TRUE, FALSE);
2168252Seric 			break;
2178252Seric 
2188252Seric 		  case 'P':		/* set precedence */
2198252Seric 			if (NumPriorities >= MAXPRIORITIES)
2208252Seric 			{
2218547Seric 				toomany('P', MAXPRIORITIES);
2228252Seric 				break;
2238252Seric 			}
2249381Seric 			for (p = &buf[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
2258252Seric 				continue;
2268252Seric 			if (*p == '\0')
2278252Seric 				goto badline;
2288252Seric 			*p = '\0';
2298252Seric 			Priorities[NumPriorities].pri_name = newstr(&buf[1]);
2308252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
2318252Seric 			NumPriorities++;
2328252Seric 			break;
2338252Seric 
2348547Seric 		  case 'T':		/* trusted user(s) */
2358547Seric 			p = &buf[1];
2368547Seric 			while (*p != '\0')
2378547Seric 			{
2388547Seric 				while (isspace(*p))
2398547Seric 					p++;
2408547Seric 				q = p;
2418547Seric 				while (*p != '\0' && !isspace(*p))
2428547Seric 					p++;
2438547Seric 				if (*p != '\0')
2448547Seric 					*p++ = '\0';
2458547Seric 				if (*q == '\0')
2468547Seric 					continue;
2478547Seric 				for (pv = TrustedUsers; *pv != NULL; pv++)
2488547Seric 					continue;
2498547Seric 				if (pv >= &TrustedUsers[MAXTRUST])
2508547Seric 				{
2518547Seric 					toomany('T', MAXTRUST);
2528547Seric 					break;
2538547Seric 				}
2548547Seric 				*pv = newstr(q);
2558547Seric 			}
2568547Seric 			break;
2578547Seric 
2583308Seric 		  default:
2594061Seric 		  badline:
2609381Seric 			syserr("unknown control line \"%s\"", buf);
2613308Seric 		}
2623308Seric 	}
2639381Seric 	FileName = NULL;
2644096Seric }
2654096Seric /*
2668547Seric **  TOOMANY -- signal too many of some option
2678547Seric **
2688547Seric **	Parameters:
2698547Seric **		id -- the id of the error line
2708547Seric **		maxcnt -- the maximum possible values
2718547Seric **
2728547Seric **	Returns:
2738547Seric **		none.
2748547Seric **
2758547Seric **	Side Effects:
2768547Seric **		gives a syserr.
2778547Seric */
2788547Seric 
2798547Seric toomany(id, maxcnt)
2808547Seric 	char id;
2818547Seric 	int maxcnt;
2828547Seric {
2839381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
2848547Seric }
2858547Seric /*
2864432Seric **  FILECLASS -- read members of a class from a file
2874432Seric **
2884432Seric **	Parameters:
2894432Seric **		class -- class to define.
2904432Seric **		filename -- name of file to read.
2914432Seric **		fmt -- scanf string to use for match.
2924432Seric **
2934432Seric **	Returns:
2944432Seric **		none
2954432Seric **
2964432Seric **	Side Effects:
2974432Seric **
2984432Seric **		puts all lines in filename that match a scanf into
2994432Seric **			the named class.
3004432Seric */
3014432Seric 
3024432Seric fileclass(class, filename, fmt)
3034432Seric 	int class;
3044432Seric 	char *filename;
3054432Seric 	char *fmt;
3064432Seric {
3074432Seric 	register FILE *f;
3084432Seric 	char buf[MAXLINE];
3094432Seric 
3104432Seric 	f = fopen(filename, "r");
3114432Seric 	if (f == NULL)
3124432Seric 	{
3134432Seric 		syserr("cannot open %s", filename);
3144432Seric 		return;
3154432Seric 	}
3164432Seric 
3174432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
3184432Seric 	{
3194432Seric 		register STAB *s;
3204432Seric 		char wordbuf[MAXNAME+1];
3214432Seric 
3224432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
3234432Seric 			continue;
3244432Seric 		s = stab(wordbuf, ST_CLASS, ST_ENTER);
32510687Seric 		setbitn(class, s->s_class);
3264432Seric 	}
3274432Seric 
3284627Seric 	(void) fclose(f);
3294432Seric }
3304432Seric /*
3314096Seric **  MAKEMAILER -- define a new mailer.
3324096Seric **
3334096Seric **	Parameters:
33410327Seric **		line -- description of mailer.  This is in labeled
33510327Seric **			fields.  The fields are:
33610327Seric **			   P -- the path to the mailer
33710327Seric **			   F -- the flags associated with the mailer
33810327Seric **			   A -- the argv for this mailer
33910327Seric **			   S -- the sender rewriting set
34010327Seric **			   R -- the recipient rewriting set
34110327Seric **			   E -- the eol string
34210327Seric **			The first word is the canonical name of the mailer.
3434096Seric **
3444096Seric **	Returns:
3454096Seric **		none.
3464096Seric **
3474096Seric **	Side Effects:
3484096Seric **		enters the mailer into the mailer table.
3494096Seric */
3503308Seric 
35121066Seric makemailer(line)
3524096Seric 	char *line;
3534096Seric {
3544096Seric 	register char *p;
3558067Seric 	register struct mailer *m;
3568067Seric 	register STAB *s;
3578067Seric 	int i;
35810327Seric 	char fcode;
3594096Seric 	extern int NextMailer;
36010327Seric 	extern char **makeargv();
36110327Seric 	extern char *munchstring();
36210327Seric 	extern char *DelimChar;
36310701Seric 	extern long atol();
3644096Seric 
36510327Seric 	/* allocate a mailer and set up defaults */
36610327Seric 	m = (struct mailer *) xalloc(sizeof *m);
36710327Seric 	bzero((char *) m, sizeof *m);
36810327Seric 	m->m_mno = NextMailer;
36910327Seric 	m->m_eol = "\n";
37010327Seric 
37110327Seric 	/* collect the mailer name */
37210327Seric 	for (p = line; *p != '\0' && *p != ',' && !isspace(*p); p++)
37310327Seric 		continue;
37410327Seric 	if (*p != '\0')
37510327Seric 		*p++ = '\0';
37610327Seric 	m->m_name = newstr(line);
37710327Seric 
37810327Seric 	/* now scan through and assign info from the fields */
37910327Seric 	while (*p != '\0')
38010327Seric 	{
38110327Seric 		while (*p != '\0' && (*p == ',' || isspace(*p)))
38210327Seric 			p++;
38310327Seric 
38410327Seric 		/* p now points to field code */
38510327Seric 		fcode = *p;
38610327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
38710327Seric 			p++;
38810327Seric 		if (*p++ != '=')
38910327Seric 		{
39010327Seric 			syserr("`=' expected");
39110327Seric 			return;
39210327Seric 		}
39310327Seric 		while (isspace(*p))
39410327Seric 			p++;
39510327Seric 
39610327Seric 		/* p now points to the field body */
39710327Seric 		p = munchstring(p);
39810327Seric 
39910327Seric 		/* install the field into the mailer struct */
40010327Seric 		switch (fcode)
40110327Seric 		{
40210327Seric 		  case 'P':		/* pathname */
40310327Seric 			m->m_mailer = newstr(p);
40410327Seric 			break;
40510327Seric 
40610327Seric 		  case 'F':		/* flags */
40710687Seric 			for (; *p != '\0'; p++)
40810687Seric 				setbitn(*p, m->m_flags);
40910327Seric 			break;
41010327Seric 
41110327Seric 		  case 'S':		/* sender rewriting ruleset */
41210327Seric 		  case 'R':		/* recipient rewriting ruleset */
41310327Seric 			i = atoi(p);
41410327Seric 			if (i < 0 || i >= MAXRWSETS)
41510327Seric 			{
41610327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
41710327Seric 				return;
41810327Seric 			}
41910327Seric 			if (fcode == 'S')
42010327Seric 				m->m_s_rwset = i;
42110327Seric 			else
42210327Seric 				m->m_r_rwset = i;
42310327Seric 			break;
42410327Seric 
42510327Seric 		  case 'E':		/* end of line string */
42610327Seric 			m->m_eol = newstr(p);
42710327Seric 			break;
42810327Seric 
42910327Seric 		  case 'A':		/* argument vector */
43010327Seric 			m->m_argv = makeargv(p);
43110327Seric 			break;
43210701Seric 
43310701Seric 		  case 'M':		/* maximum message size */
43410701Seric 			m->m_maxsize = atol(p);
43510701Seric 			break;
43610327Seric 		}
43710327Seric 
43810327Seric 		p = DelimChar;
43910327Seric 	}
44010327Seric 
44110327Seric 	/* now store the mailer away */
4424096Seric 	if (NextMailer >= MAXMAILERS)
4434096Seric 	{
4449381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
4454096Seric 		return;
4464096Seric 	}
44710327Seric 	Mailer[NextMailer++] = m;
44810327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
44910327Seric 	s->s_mailer = m;
45010327Seric }
45110327Seric /*
45210327Seric **  MUNCHSTRING -- translate a string into internal form.
45310327Seric **
45410327Seric **	Parameters:
45510327Seric **		p -- the string to munch.
45610327Seric **
45710327Seric **	Returns:
45810327Seric **		the munched string.
45910327Seric **
46010327Seric **	Side Effects:
46110327Seric **		Sets "DelimChar" to point to the string that caused us
46210327Seric **		to stop.
46310327Seric */
4644096Seric 
46510327Seric char *
46610327Seric munchstring(p)
46710327Seric 	register char *p;
46810327Seric {
46910327Seric 	register char *q;
47010327Seric 	bool backslash = FALSE;
47110327Seric 	bool quotemode = FALSE;
47210327Seric 	static char buf[MAXLINE];
47310327Seric 	extern char *DelimChar;
4744096Seric 
47510327Seric 	for (q = buf; *p != '\0'; p++)
4764096Seric 	{
47710327Seric 		if (backslash)
47810327Seric 		{
47910327Seric 			/* everything is roughly literal */
48010357Seric 			backslash = FALSE;
48110327Seric 			switch (*p)
48210327Seric 			{
48310327Seric 			  case 'r':		/* carriage return */
48410327Seric 				*q++ = '\r';
48510327Seric 				continue;
48610327Seric 
48710327Seric 			  case 'n':		/* newline */
48810327Seric 				*q++ = '\n';
48910327Seric 				continue;
49010327Seric 
49110327Seric 			  case 'f':		/* form feed */
49210327Seric 				*q++ = '\f';
49310327Seric 				continue;
49410327Seric 
49510327Seric 			  case 'b':		/* backspace */
49610327Seric 				*q++ = '\b';
49710327Seric 				continue;
49810327Seric 			}
49910327Seric 			*q++ = *p;
50010327Seric 		}
50110327Seric 		else
50210327Seric 		{
50310327Seric 			if (*p == '\\')
50410327Seric 				backslash = TRUE;
50510327Seric 			else if (*p == '"')
50610327Seric 				quotemode = !quotemode;
50710327Seric 			else if (quotemode || *p != ',')
50810327Seric 				*q++ = *p;
50910327Seric 			else
51010327Seric 				break;
51110327Seric 		}
5124096Seric 	}
5134096Seric 
51410327Seric 	DelimChar = p;
51510327Seric 	*q++ = '\0';
51610327Seric 	return (buf);
51710327Seric }
51810327Seric /*
51910327Seric **  MAKEARGV -- break up a string into words
52010327Seric **
52110327Seric **	Parameters:
52210327Seric **		p -- the string to break up.
52310327Seric **
52410327Seric **	Returns:
52510327Seric **		a char **argv (dynamically allocated)
52610327Seric **
52710327Seric **	Side Effects:
52810327Seric **		munges p.
52910327Seric */
5304096Seric 
53110327Seric char **
53210327Seric makeargv(p)
53310327Seric 	register char *p;
53410327Seric {
53510327Seric 	char *q;
53610327Seric 	int i;
53710327Seric 	char **avp;
53810327Seric 	char *argv[MAXPV + 1];
53910327Seric 
54010327Seric 	/* take apart the words */
54110327Seric 	i = 0;
54210327Seric 	while (*p != '\0' && i < MAXPV)
5434096Seric 	{
54410327Seric 		q = p;
54510327Seric 		while (*p != '\0' && !isspace(*p))
54610327Seric 			p++;
54710327Seric 		while (isspace(*p))
54810327Seric 			*p++ = '\0';
54910327Seric 		argv[i++] = newstr(q);
5504096Seric 	}
55110327Seric 	argv[i++] = NULL;
5524096Seric 
55310327Seric 	/* now make a copy of the argv */
55410327Seric 	avp = (char **) xalloc(sizeof *avp * i);
55516893Seric 	bcopy((char *) argv, (char *) avp, sizeof *avp * i);
55610327Seric 
55710327Seric 	return (avp);
5583308Seric }
5593308Seric /*
5603308Seric **  PRINTRULES -- print rewrite rules (for debugging)
5613308Seric **
5623308Seric **	Parameters:
5633308Seric **		none.
5643308Seric **
5653308Seric **	Returns:
5663308Seric **		none.
5673308Seric **
5683308Seric **	Side Effects:
5693308Seric **		prints rewrite rules.
5703308Seric */
5713308Seric 
5724319Seric # ifdef DEBUG
5734319Seric 
5743308Seric printrules()
5753308Seric {
5763308Seric 	register struct rewrite *rwp;
5774072Seric 	register int ruleset;
5783308Seric 
5794072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
5803308Seric 	{
5814072Seric 		if (RewriteRules[ruleset] == NULL)
5824072Seric 			continue;
5838067Seric 		printf("\n----Rule Set %d:", ruleset);
5843308Seric 
5854072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
5863308Seric 		{
5878067Seric 			printf("\nLHS:");
5888067Seric 			printav(rwp->r_lhs);
5898067Seric 			printf("RHS:");
5908067Seric 			printav(rwp->r_rhs);
5913308Seric 		}
5923308Seric 	}
5933308Seric }
5944319Seric 
5954319Seric # endif DEBUG
5964096Seric /*
5978256Seric **  SETOPTION -- set global processing option
5988256Seric **
5998256Seric **	Parameters:
6008256Seric **		opt -- option name.
6018256Seric **		val -- option value (as a text string).
60221755Seric **		safe -- set if this came from a configuration file.
60321755Seric **			Some options (if set from the command line) will
60421755Seric **			reset the user id to avoid security problems.
6058269Seric **		sticky -- if set, don't let other setoptions override
6068269Seric **			this value.
6078256Seric **
6088256Seric **	Returns:
6098256Seric **		none.
6108256Seric **
6118256Seric **	Side Effects:
6128256Seric **		Sets options as implied by the arguments.
6138256Seric */
6148256Seric 
61510687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
61610687Seric extern char	*WizWord;		/* the stored wizard password */
61716143Seric extern char	*NetName;		/* name of home (local) network */
6188269Seric 
61921755Seric setoption(opt, val, safe, sticky)
6208256Seric 	char opt;
6218256Seric 	char *val;
62221755Seric 	bool safe;
6238269Seric 	bool sticky;
6248256Seric {
6258265Seric 	extern bool atobool();
62612633Seric 	extern time_t convtime();
62714879Seric 	extern int QueueLA;
62814879Seric 	extern int RefuseLA;
62917474Seric 	extern bool trusteduser();
63017474Seric 	extern char *username();
6318256Seric 
6328256Seric # ifdef DEBUG
6338256Seric 	if (tTd(37, 1))
6349341Seric 		printf("setoption %c=%s", opt, val);
6358256Seric # endif DEBUG
6368256Seric 
6378256Seric 	/*
6388269Seric 	**  See if this option is preset for us.
6398256Seric 	*/
6408256Seric 
64110687Seric 	if (bitnset(opt, StickyOpt))
6428269Seric 	{
6438269Seric # ifdef DEBUG
6449341Seric 		if (tTd(37, 1))
6459341Seric 			printf(" (ignored)\n");
6468269Seric # endif DEBUG
6478269Seric 		return;
6488269Seric 	}
6498269Seric 
65021755Seric 	/*
65121755Seric 	**  Check to see if this option can be specified by this user.
65221755Seric 	*/
65321755Seric 
65421755Seric 	if (!safe && getruid())
65521755Seric 		safe = TRUE;
65621755Seric 	if (!safe && index("deiLmorsv", opt) == NULL)
65721755Seric 	{
65821755Seric # ifdef DEBUG
65921755Seric 		if (tTd(37, 1))
66021755Seric 			printf(" (unsafe)");
66121755Seric # endif DEBUG
66221755Seric 		if (getruid() != geteuid())
66321755Seric 		{
66421755Seric 			printf("(Resetting uid)\n");
66521755Seric 			setgid(getgid());
66621755Seric 			setuid(getuid());
66721755Seric 		}
66821755Seric 	}
66917985Seric #ifdef DEBUG
67021755Seric 	else if (tTd(37, 1))
67117985Seric 		printf("\n");
67217985Seric #endif DEBUG
6738269Seric 
6748256Seric 	switch (opt)
6758256Seric 	{
6768256Seric 	  case 'A':		/* set default alias file */
6779381Seric 		if (val[0] == '\0')
6788269Seric 			AliasFile = "aliases";
6799381Seric 		else
6809381Seric 			AliasFile = newstr(val);
6818256Seric 		break;
6828256Seric 
68317474Seric 	  case 'a':		/* look N minutes for "@:@" in alias file */
68417474Seric 		if (val[0] == '\0')
68517474Seric 			SafeAlias = 5;
68617474Seric 		else
68717474Seric 			SafeAlias = atoi(val);
68817474Seric 		break;
68917474Seric 
69016843Seric 	  case 'B':		/* substitution for blank character */
69116843Seric 		SpaceSub = val[0];
69216843Seric 		if (SpaceSub == '\0')
69316843Seric 			SpaceSub = ' ';
69416843Seric 		break;
69516843Seric 
6969284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
6979381Seric 		NoConnect = atobool(val);
6989284Seric 		break;
6999284Seric 
7009284Seric 	  case 'd':		/* delivery mode */
7019284Seric 		switch (*val)
7028269Seric 		{
7039284Seric 		  case '\0':
7049284Seric 			SendMode = SM_DELIVER;
7058269Seric 			break;
7068269Seric 
70710755Seric 		  case SM_QUEUE:	/* queue only */
70810755Seric #ifndef QUEUE
70910755Seric 			syserr("need QUEUE to set -odqueue");
71010755Seric #endif QUEUE
71110755Seric 			/* fall through..... */
71210755Seric 
7139284Seric 		  case SM_DELIVER:	/* do everything */
7149284Seric 		  case SM_FORK:		/* fork after verification */
7159284Seric 			SendMode = *val;
7168269Seric 			break;
7178269Seric 
7188269Seric 		  default:
7199284Seric 			syserr("Unknown delivery mode %c", *val);
7208269Seric 			exit(EX_USAGE);
7218269Seric 		}
7228269Seric 		break;
7238269Seric 
7249146Seric 	  case 'D':		/* rebuild alias database as needed */
7259381Seric 		AutoRebuild = atobool(val);
7269146Seric 		break;
7279146Seric 
7288269Seric 	  case 'e':		/* set error processing mode */
7298269Seric 		switch (*val)
7308269Seric 		{
7319381Seric 		  case EM_QUIET:	/* be silent about it */
7329381Seric 		  case EM_MAIL:		/* mail back */
7339381Seric 		  case EM_BERKNET:	/* do berknet error processing */
7349381Seric 		  case EM_WRITE:	/* write back (or mail) */
7358269Seric 			HoldErrs = TRUE;
7369381Seric 			/* fall through... */
7378269Seric 
7389381Seric 		  case EM_PRINT:	/* print errors normally (default) */
7399381Seric 			ErrorMode = *val;
7408269Seric 			break;
7418269Seric 		}
7428269Seric 		break;
7438269Seric 
7449049Seric 	  case 'F':		/* file mode */
74517975Seric 		FileMode = atooct(val) & 0777;
7469049Seric 		break;
7479049Seric 
7488269Seric 	  case 'f':		/* save Unix-style From lines on front */
7499381Seric 		SaveFrom = atobool(val);
7508269Seric 		break;
7518269Seric 
7528256Seric 	  case 'g':		/* default gid */
75317474Seric 		DefGid = atoi(val);
7548256Seric 		break;
7558256Seric 
7568256Seric 	  case 'H':		/* help file */
7579381Seric 		if (val[0] == '\0')
7588269Seric 			HelpFile = "sendmail.hf";
7599381Seric 		else
7609381Seric 			HelpFile = newstr(val);
7618256Seric 		break;
7628256Seric 
7638269Seric 	  case 'i':		/* ignore dot lines in message */
7649381Seric 		IgnrDot = atobool(val);
7658269Seric 		break;
7668269Seric 
7678256Seric 	  case 'L':		/* log level */
7689381Seric 		LogLevel = atoi(val);
7698256Seric 		break;
7708256Seric 
7718269Seric 	  case 'M':		/* define macro */
7729381Seric 		define(val[0], newstr(&val[1]), CurEnv);
77316878Seric 		sticky = FALSE;
7748269Seric 		break;
7758269Seric 
7768269Seric 	  case 'm':		/* send to me too */
7779381Seric 		MeToo = atobool(val);
7788269Seric 		break;
7798269Seric 
78016143Seric # ifdef DAEMON
78116143Seric 	  case 'N':		/* home (local?) network name */
78216143Seric 		NetName = newstr(val);
78316143Seric 		break;
78416143Seric # endif DAEMON
78516143Seric 
7868269Seric 	  case 'o':		/* assume old style headers */
7879381Seric 		if (atobool(val))
7889341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
7899341Seric 		else
7909341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
7918269Seric 		break;
7928269Seric 
7938256Seric 	  case 'Q':		/* queue directory */
7949381Seric 		if (val[0] == '\0')
7958269Seric 			QueueDir = "mqueue";
7969381Seric 		else
7979381Seric 			QueueDir = newstr(val);
7988256Seric 		break;
7998256Seric 
8008256Seric 	  case 'r':		/* read timeout */
8019381Seric 		ReadTimeout = convtime(val);
8028256Seric 		break;
8038256Seric 
8048256Seric 	  case 'S':		/* status file */
8059381Seric 		if (val[0] == '\0')
8068269Seric 			StatFile = "sendmail.st";
8079381Seric 		else
8089381Seric 			StatFile = newstr(val);
8098256Seric 		break;
8108256Seric 
8118265Seric 	  case 's':		/* be super safe, even if expensive */
8129381Seric 		SuperSafe = atobool(val);
8138256Seric 		break;
8148256Seric 
8158256Seric 	  case 'T':		/* queue timeout */
8169381Seric 		TimeOut = convtime(val);
8178256Seric 		break;
8188256Seric 
8198265Seric 	  case 't':		/* time zone name */
8208265Seric # ifdef V6
8219381Seric 		StdTimezone = newstr(val);
8229381Seric 		DstTimezone = index(StdTimeZone, ',');
8238265Seric 		if (DstTimezone == NULL)
8249381Seric 			syserr("bad time zone spec");
8259381Seric 		else
8269381Seric 			*DstTimezone++ = '\0';
8278265Seric # endif V6
8288265Seric 		break;
8298265Seric 
8308256Seric 	  case 'u':		/* set default uid */
83117474Seric 		DefUid = atoi(val);
8328256Seric 		break;
8338256Seric 
8348269Seric 	  case 'v':		/* run in verbose mode */
8359381Seric 		Verbose = atobool(val);
8368256Seric 		break;
8378256Seric 
8388544Seric # ifdef DEBUG
8398544Seric 	  case 'W':		/* set the wizards password */
84017474Seric 		WizWord = newstr(val);
8418544Seric 		break;
8428544Seric # endif DEBUG
8438544Seric 
84414879Seric 	  case 'x':		/* load avg at which to auto-queue msgs */
84514879Seric 		QueueLA = atoi(val);
84614879Seric 		break;
84714879Seric 
84814879Seric 	  case 'X':		/* load avg at which to auto-reject connections */
84914879Seric 		RefuseLA = atoi(val);
85014879Seric 		break;
85114879Seric 
8528256Seric 	  default:
8538256Seric 		break;
8548256Seric 	}
85516878Seric 	if (sticky)
85616878Seric 		setbitn(opt, StickyOpt);
8579188Seric 	return;
8588256Seric }
85910687Seric /*
86010687Seric **  SETCLASS -- set a word into a class
86110687Seric **
86210687Seric **	Parameters:
86310687Seric **		class -- the class to put the word in.
86410687Seric **		word -- the word to enter
86510687Seric **
86610687Seric **	Returns:
86710687Seric **		none.
86810687Seric **
86910687Seric **	Side Effects:
87010687Seric **		puts the word into the symbol table.
87110687Seric */
87210687Seric 
87310687Seric setclass(class, word)
87410687Seric 	int class;
87510687Seric 	char *word;
87610687Seric {
87710687Seric 	register STAB *s;
87810687Seric 
87910687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
88010687Seric 	setbitn(class, s->s_class);
88110687Seric }
882