xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 16915)
13313Seric # include "sendmail.h"
23308Seric 
3*16915Seric SCCSID(@(#)readcf.c	4.8		08/11/84);
43308Seric 
53308Seric /*
63308Seric **  READCF -- read control file.
73308Seric **
83308Seric **	This routine reads the control file and builds the internal
93308Seric **	form.
103308Seric **
114432Seric **	The file is formatted as a sequence of lines, each taken
124432Seric **	atomically.  The first character of each line describes how
134432Seric **	the line is to be interpreted.  The lines are:
144432Seric **		Dxval		Define macro x to have value val.
154432Seric **		Cxword		Put word into class x.
164432Seric **		Fxfile [fmt]	Read file for lines to put into
174432Seric **				class x.  Use scanf string 'fmt'
184432Seric **				or "%s" if not present.  Fmt should
194432Seric **				only produce one string-valued result.
204432Seric **		Hname: value	Define header with field-name 'name'
214432Seric **				and value as specified; this will be
224432Seric **				macro expanded immediately before
234432Seric **				use.
244432Seric **		Sn		Use rewriting set n.
254432Seric **		Rlhs rhs	Rewrite addresses that match lhs to
264432Seric **				be rhs.
278252Seric **		Mn p f s r a	Define mailer.  n - internal name,
288252Seric **				p - pathname, f - flags, s - rewriting
298252Seric **				ruleset for sender, s - rewriting ruleset
308252Seric **				for recipients, a - argument vector.
318252Seric **		Oxvalue		Set option x to value.
328252Seric **		Pname=value	Set precedence name to value.
334432Seric **
343308Seric **	Parameters:
353308Seric **		cfname -- control file name.
364217Seric **		safe -- set if this is a system configuration file.
374217Seric **			Non-system configuration files can not do
384217Seric **			certain things (e.g., leave the SUID bit on
394217Seric **			when executing mailers).
403308Seric **
413308Seric **	Returns:
423308Seric **		none.
433308Seric **
443308Seric **	Side Effects:
453308Seric **		Builds several internal tables.
463308Seric */
473308Seric 
484217Seric readcf(cfname, safe)
493308Seric 	char *cfname;
504217Seric 	bool safe;
513308Seric {
523308Seric 	FILE *cf;
538547Seric 	int ruleset = 0;
548547Seric 	char *q;
558547Seric 	char **pv;
569350Seric 	struct rewrite *rwp = NULL;
573308Seric 	char buf[MAXLINE];
583308Seric 	register char *p;
593308Seric 	extern char **prescan();
603308Seric 	extern char **copyplist();
615909Seric 	char exbuf[MAXLINE];
62*16915Seric 	char pvpbuf[PSBUFSIZE];
639350Seric 	extern char *fgetfolded();
6410709Seric 	extern char *munchstring();
653308Seric 
663308Seric 	cf = fopen(cfname, "r");
673308Seric 	if (cf == NULL)
683308Seric 	{
693308Seric 		syserr("cannot open %s", cfname);
703308Seric 		exit(EX_OSFILE);
713308Seric 	}
723308Seric 
739381Seric 	FileName = cfname;
748056Seric 	LineNumber = 0;
757854Seric 	while (fgetfolded(buf, sizeof buf, cf) != NULL)
763308Seric 	{
7716157Seric 		/* map $ into \001 (ASCII SOH) for macro expansion */
7816157Seric 		for (p = buf; *p != '\0'; p++)
7916157Seric 		{
8016157Seric 			if (*p != '$')
8116157Seric 				continue;
8216157Seric 
8316157Seric 			if (p[1] == '$')
8416157Seric 			{
8516157Seric 				/* actual dollar sign.... */
8616157Seric 				strcpy(p, p + 1);
8716157Seric 				continue;
8816157Seric 			}
8916157Seric 
9016157Seric 			/* convert to macro expansion character */
9116157Seric 			*p = '\001';
9216157Seric 		}
9316157Seric 
9416157Seric 		/* interpret this line */
953308Seric 		switch (buf[0])
963308Seric 		{
973308Seric 		  case '\0':
983308Seric 		  case '#':		/* comment */
993308Seric 			break;
1003308Seric 
1013308Seric 		  case 'R':		/* rewriting rule */
1023308Seric 			for (p = &buf[1]; *p != '\0' && *p != '\t'; p++)
1033308Seric 				continue;
1043308Seric 
1053308Seric 			if (*p == '\0')
1065909Seric 			{
1079381Seric 				syserr("invalid rewrite line \"%s\"", buf);
1085909Seric 				break;
1095909Seric 			}
1105909Seric 
1115909Seric 			/* allocate space for the rule header */
1125909Seric 			if (rwp == NULL)
1135909Seric 			{
1145909Seric 				RewriteRules[ruleset] = rwp =
1155909Seric 					(struct rewrite *) xalloc(sizeof *rwp);
1165909Seric 			}
1173308Seric 			else
1183308Seric 			{
1195909Seric 				rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
1205909Seric 				rwp = rwp->r_next;
1215909Seric 			}
1225909Seric 			rwp->r_next = NULL;
1233308Seric 
1245909Seric 			/* expand and save the LHS */
1255909Seric 			*p = '\0';
1266991Seric 			expand(&buf[1], exbuf, &exbuf[sizeof exbuf], CurEnv);
127*16915Seric 			rwp->r_lhs = prescan(exbuf, '\t', pvpbuf);
1285909Seric 			if (rwp->r_lhs != NULL)
1295909Seric 				rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
1305909Seric 
1315909Seric 			/* expand and save the RHS */
1325909Seric 			while (*++p == '\t')
1335909Seric 				continue;
1347231Seric 			q = p;
1357231Seric 			while (*p != '\0' && *p != '\t')
1367231Seric 				p++;
1377231Seric 			*p = '\0';
1387231Seric 			expand(q, exbuf, &exbuf[sizeof exbuf], CurEnv);
139*16915Seric 			rwp->r_rhs = prescan(exbuf, '\t', pvpbuf);
1405909Seric 			if (rwp->r_rhs != NULL)
1415909Seric 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
1423308Seric 			break;
1433308Seric 
1444072Seric 		  case 'S':		/* select rewriting set */
1454072Seric 			ruleset = atoi(&buf[1]);
1468056Seric 			if (ruleset >= MAXRWSETS || ruleset < 0)
1478056Seric 			{
1489381Seric 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
1498056Seric 				ruleset = 0;
1508056Seric 			}
1514072Seric 			rwp = NULL;
1524072Seric 			break;
1534072Seric 
1543308Seric 		  case 'D':		/* macro definition */
15510709Seric 			define(buf[1], newstr(munchstring(&buf[2])), CurEnv);
1563308Seric 			break;
1573308Seric 
1583387Seric 		  case 'H':		/* required header line */
1594088Seric 			(void) chompheader(&buf[1], TRUE);
1603387Seric 			break;
1613387Seric 
1624061Seric 		  case 'C':		/* word class */
1634432Seric 		  case 'F':		/* word class from file */
1644432Seric 			/* read list of words from argument or file */
1654432Seric 			if (buf[0] == 'F')
1664432Seric 			{
1674432Seric 				/* read from file */
1684432Seric 				for (p = &buf[2]; *p != '\0' && !isspace(*p); p++)
1694432Seric 					continue;
1704432Seric 				if (*p == '\0')
1714432Seric 					p = "%s";
1724432Seric 				else
1734432Seric 				{
1744432Seric 					*p = '\0';
1754432Seric 					while (isspace(*++p))
1764432Seric 						continue;
1774432Seric 				}
17810687Seric 				fileclass(buf[1], &buf[2], p);
1794432Seric 				break;
1804432Seric 			}
1814061Seric 
1824432Seric 			/* scan the list of words and set class for all */
1834061Seric 			for (p = &buf[2]; *p != '\0'; )
1844061Seric 			{
1854061Seric 				register char *wd;
1864061Seric 				char delim;
1874061Seric 
1884061Seric 				while (*p != '\0' && isspace(*p))
1894061Seric 					p++;
1904061Seric 				wd = p;
1914061Seric 				while (*p != '\0' && !isspace(*p))
1924061Seric 					p++;
1934061Seric 				delim = *p;
1944061Seric 				*p = '\0';
1954061Seric 				if (wd[0] != '\0')
19610687Seric 					setclass(buf[1], wd);
1974061Seric 				*p = delim;
1984061Seric 			}
1994061Seric 			break;
2004061Seric 
2014096Seric 		  case 'M':		/* define mailer */
2024217Seric 			makemailer(&buf[1], safe);
2034096Seric 			break;
2044096Seric 
2058252Seric 		  case 'O':		/* set option */
2068269Seric 			setoption(buf[1], &buf[2], safe, FALSE);
2078252Seric 			break;
2088252Seric 
2098252Seric 		  case 'P':		/* set precedence */
2108252Seric 			if (NumPriorities >= MAXPRIORITIES)
2118252Seric 			{
2128547Seric 				toomany('P', MAXPRIORITIES);
2138252Seric 				break;
2148252Seric 			}
2159381Seric 			for (p = &buf[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
2168252Seric 				continue;
2178252Seric 			if (*p == '\0')
2188252Seric 				goto badline;
2198252Seric 			*p = '\0';
2208252Seric 			Priorities[NumPriorities].pri_name = newstr(&buf[1]);
2218252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
2228252Seric 			NumPriorities++;
2238252Seric 			break;
2248252Seric 
2258547Seric 		  case 'T':		/* trusted user(s) */
2268547Seric 			p = &buf[1];
2278547Seric 			while (*p != '\0')
2288547Seric 			{
2298547Seric 				while (isspace(*p))
2308547Seric 					p++;
2318547Seric 				q = p;
2328547Seric 				while (*p != '\0' && !isspace(*p))
2338547Seric 					p++;
2348547Seric 				if (*p != '\0')
2358547Seric 					*p++ = '\0';
2368547Seric 				if (*q == '\0')
2378547Seric 					continue;
2388547Seric 				for (pv = TrustedUsers; *pv != NULL; pv++)
2398547Seric 					continue;
2408547Seric 				if (pv >= &TrustedUsers[MAXTRUST])
2418547Seric 				{
2428547Seric 					toomany('T', MAXTRUST);
2438547Seric 					break;
2448547Seric 				}
2458547Seric 				*pv = newstr(q);
2468547Seric 			}
2478547Seric 			break;
2488547Seric 
2493308Seric 		  default:
2504061Seric 		  badline:
2519381Seric 			syserr("unknown control line \"%s\"", buf);
2523308Seric 		}
2533308Seric 	}
2549381Seric 	FileName = NULL;
2554096Seric }
2564096Seric /*
2578547Seric **  TOOMANY -- signal too many of some option
2588547Seric **
2598547Seric **	Parameters:
2608547Seric **		id -- the id of the error line
2618547Seric **		maxcnt -- the maximum possible values
2628547Seric **
2638547Seric **	Returns:
2648547Seric **		none.
2658547Seric **
2668547Seric **	Side Effects:
2678547Seric **		gives a syserr.
2688547Seric */
2698547Seric 
2708547Seric toomany(id, maxcnt)
2718547Seric 	char id;
2728547Seric 	int maxcnt;
2738547Seric {
2749381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
2758547Seric }
2768547Seric /*
2774432Seric **  FILECLASS -- read members of a class from a file
2784432Seric **
2794432Seric **	Parameters:
2804432Seric **		class -- class to define.
2814432Seric **		filename -- name of file to read.
2824432Seric **		fmt -- scanf string to use for match.
2834432Seric **
2844432Seric **	Returns:
2854432Seric **		none
2864432Seric **
2874432Seric **	Side Effects:
2884432Seric **
2894432Seric **		puts all lines in filename that match a scanf into
2904432Seric **			the named class.
2914432Seric */
2924432Seric 
2934432Seric fileclass(class, filename, fmt)
2944432Seric 	int class;
2954432Seric 	char *filename;
2964432Seric 	char *fmt;
2974432Seric {
2984432Seric 	register FILE *f;
2994432Seric 	char buf[MAXLINE];
3004432Seric 
3014432Seric 	f = fopen(filename, "r");
3024432Seric 	if (f == NULL)
3034432Seric 	{
3044432Seric 		syserr("cannot open %s", filename);
3054432Seric 		return;
3064432Seric 	}
3074432Seric 
3084432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
3094432Seric 	{
3104432Seric 		register STAB *s;
3114432Seric 		char wordbuf[MAXNAME+1];
3124432Seric 
3134432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
3144432Seric 			continue;
3154432Seric 		s = stab(wordbuf, ST_CLASS, ST_ENTER);
31610687Seric 		setbitn(class, s->s_class);
3174432Seric 	}
3184432Seric 
3194627Seric 	(void) fclose(f);
3204432Seric }
3214432Seric /*
3224096Seric **  MAKEMAILER -- define a new mailer.
3234096Seric **
3244096Seric **	Parameters:
32510327Seric **		line -- description of mailer.  This is in labeled
32610327Seric **			fields.  The fields are:
32710327Seric **			   P -- the path to the mailer
32810327Seric **			   F -- the flags associated with the mailer
32910327Seric **			   A -- the argv for this mailer
33010327Seric **			   S -- the sender rewriting set
33110327Seric **			   R -- the recipient rewriting set
33210327Seric **			   E -- the eol string
33310327Seric **			The first word is the canonical name of the mailer.
3344217Seric **		safe -- set if this is a safe configuration file.
3354096Seric **
3364096Seric **	Returns:
3374096Seric **		none.
3384096Seric **
3394096Seric **	Side Effects:
3404096Seric **		enters the mailer into the mailer table.
3414096Seric */
3423308Seric 
3434217Seric makemailer(line, safe)
3444096Seric 	char *line;
3454217Seric 	bool safe;
3464096Seric {
3474096Seric 	register char *p;
3488067Seric 	register struct mailer *m;
3498067Seric 	register STAB *s;
3508067Seric 	int i;
35110327Seric 	char fcode;
3524096Seric 	extern int NextMailer;
35310327Seric 	extern char **makeargv();
35410327Seric 	extern char *munchstring();
35510327Seric 	extern char *DelimChar;
35610701Seric 	extern long atol();
3574096Seric 
35810327Seric 	/* allocate a mailer and set up defaults */
35910327Seric 	m = (struct mailer *) xalloc(sizeof *m);
36010327Seric 	bzero((char *) m, sizeof *m);
36110327Seric 	m->m_mno = NextMailer;
36210327Seric 	m->m_eol = "\n";
36310327Seric 
36410327Seric 	/* collect the mailer name */
36510327Seric 	for (p = line; *p != '\0' && *p != ',' && !isspace(*p); p++)
36610327Seric 		continue;
36710327Seric 	if (*p != '\0')
36810327Seric 		*p++ = '\0';
36910327Seric 	m->m_name = newstr(line);
37010327Seric 
37110327Seric 	/* now scan through and assign info from the fields */
37210327Seric 	while (*p != '\0')
37310327Seric 	{
37410327Seric 		while (*p != '\0' && (*p == ',' || isspace(*p)))
37510327Seric 			p++;
37610327Seric 
37710327Seric 		/* p now points to field code */
37810327Seric 		fcode = *p;
37910327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
38010327Seric 			p++;
38110327Seric 		if (*p++ != '=')
38210327Seric 		{
38310327Seric 			syserr("`=' expected");
38410327Seric 			return;
38510327Seric 		}
38610327Seric 		while (isspace(*p))
38710327Seric 			p++;
38810327Seric 
38910327Seric 		/* p now points to the field body */
39010327Seric 		p = munchstring(p);
39110327Seric 
39210327Seric 		/* install the field into the mailer struct */
39310327Seric 		switch (fcode)
39410327Seric 		{
39510327Seric 		  case 'P':		/* pathname */
39610327Seric 			m->m_mailer = newstr(p);
39710327Seric 			break;
39810327Seric 
39910327Seric 		  case 'F':		/* flags */
40010687Seric 			for (; *p != '\0'; p++)
40110687Seric 				setbitn(*p, m->m_flags);
40210327Seric 			if (!safe)
40310687Seric 				clrbitn(M_RESTR, m->m_flags);
40410327Seric 			break;
40510327Seric 
40610327Seric 		  case 'S':		/* sender rewriting ruleset */
40710327Seric 		  case 'R':		/* recipient rewriting ruleset */
40810327Seric 			i = atoi(p);
40910327Seric 			if (i < 0 || i >= MAXRWSETS)
41010327Seric 			{
41110327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
41210327Seric 				return;
41310327Seric 			}
41410327Seric 			if (fcode == 'S')
41510327Seric 				m->m_s_rwset = i;
41610327Seric 			else
41710327Seric 				m->m_r_rwset = i;
41810327Seric 			break;
41910327Seric 
42010327Seric 		  case 'E':		/* end of line string */
42110327Seric 			m->m_eol = newstr(p);
42210327Seric 			break;
42310327Seric 
42410327Seric 		  case 'A':		/* argument vector */
42510327Seric 			m->m_argv = makeargv(p);
42610327Seric 			break;
42710701Seric 
42810701Seric 		  case 'M':		/* maximum message size */
42910701Seric 			m->m_maxsize = atol(p);
43010701Seric 			break;
43110327Seric 		}
43210327Seric 
43310327Seric 		p = DelimChar;
43410327Seric 	}
43510327Seric 
43610327Seric 	/* now store the mailer away */
4374096Seric 	if (NextMailer >= MAXMAILERS)
4384096Seric 	{
4399381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
4404096Seric 		return;
4414096Seric 	}
44210327Seric 	Mailer[NextMailer++] = m;
44310327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
44410327Seric 	s->s_mailer = m;
44510327Seric }
44610327Seric /*
44710327Seric **  MUNCHSTRING -- translate a string into internal form.
44810327Seric **
44910327Seric **	Parameters:
45010327Seric **		p -- the string to munch.
45110327Seric **
45210327Seric **	Returns:
45310327Seric **		the munched string.
45410327Seric **
45510327Seric **	Side Effects:
45610327Seric **		Sets "DelimChar" to point to the string that caused us
45710327Seric **		to stop.
45810327Seric */
4594096Seric 
46010327Seric char *
46110327Seric munchstring(p)
46210327Seric 	register char *p;
46310327Seric {
46410327Seric 	register char *q;
46510327Seric 	bool backslash = FALSE;
46610327Seric 	bool quotemode = FALSE;
46710327Seric 	static char buf[MAXLINE];
46810327Seric 	extern char *DelimChar;
4694096Seric 
47010327Seric 	for (q = buf; *p != '\0'; p++)
4714096Seric 	{
47210327Seric 		if (backslash)
47310327Seric 		{
47410327Seric 			/* everything is roughly literal */
47510357Seric 			backslash = FALSE;
47610327Seric 			switch (*p)
47710327Seric 			{
47810327Seric 			  case 'r':		/* carriage return */
47910327Seric 				*q++ = '\r';
48010327Seric 				continue;
48110327Seric 
48210327Seric 			  case 'n':		/* newline */
48310327Seric 				*q++ = '\n';
48410327Seric 				continue;
48510327Seric 
48610327Seric 			  case 'f':		/* form feed */
48710327Seric 				*q++ = '\f';
48810327Seric 				continue;
48910327Seric 
49010327Seric 			  case 'b':		/* backspace */
49110327Seric 				*q++ = '\b';
49210327Seric 				continue;
49310327Seric 			}
49410327Seric 			*q++ = *p;
49510327Seric 		}
49610327Seric 		else
49710327Seric 		{
49810327Seric 			if (*p == '\\')
49910327Seric 				backslash = TRUE;
50010327Seric 			else if (*p == '"')
50110327Seric 				quotemode = !quotemode;
50210327Seric 			else if (quotemode || *p != ',')
50310327Seric 				*q++ = *p;
50410327Seric 			else
50510327Seric 				break;
50610327Seric 		}
5074096Seric 	}
5084096Seric 
50910327Seric 	DelimChar = p;
51010327Seric 	*q++ = '\0';
51110327Seric 	return (buf);
51210327Seric }
51310327Seric /*
51410327Seric **  MAKEARGV -- break up a string into words
51510327Seric **
51610327Seric **	Parameters:
51710327Seric **		p -- the string to break up.
51810327Seric **
51910327Seric **	Returns:
52010327Seric **		a char **argv (dynamically allocated)
52110327Seric **
52210327Seric **	Side Effects:
52310327Seric **		munges p.
52410327Seric */
5254096Seric 
52610327Seric char **
52710327Seric makeargv(p)
52810327Seric 	register char *p;
52910327Seric {
53010327Seric 	char *q;
53110327Seric 	int i;
53210327Seric 	char **avp;
53310327Seric 	char *argv[MAXPV + 1];
53410327Seric 
53510327Seric 	/* take apart the words */
53610327Seric 	i = 0;
53710327Seric 	while (*p != '\0' && i < MAXPV)
5384096Seric 	{
53910327Seric 		q = p;
54010327Seric 		while (*p != '\0' && !isspace(*p))
54110327Seric 			p++;
54210327Seric 		while (isspace(*p))
54310327Seric 			*p++ = '\0';
54410327Seric 		argv[i++] = newstr(q);
5454096Seric 	}
54610327Seric 	argv[i++] = NULL;
5474096Seric 
54810327Seric 	/* now make a copy of the argv */
54910327Seric 	avp = (char **) xalloc(sizeof *avp * i);
55016893Seric 	bcopy((char *) argv, (char *) avp, sizeof *avp * i);
55110327Seric 
55210327Seric 	return (avp);
5533308Seric }
5543308Seric /*
5553308Seric **  PRINTRULES -- print rewrite rules (for debugging)
5563308Seric **
5573308Seric **	Parameters:
5583308Seric **		none.
5593308Seric **
5603308Seric **	Returns:
5613308Seric **		none.
5623308Seric **
5633308Seric **	Side Effects:
5643308Seric **		prints rewrite rules.
5653308Seric */
5663308Seric 
5674319Seric # ifdef DEBUG
5684319Seric 
5693308Seric printrules()
5703308Seric {
5713308Seric 	register struct rewrite *rwp;
5724072Seric 	register int ruleset;
5733308Seric 
5744072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
5753308Seric 	{
5764072Seric 		if (RewriteRules[ruleset] == NULL)
5774072Seric 			continue;
5788067Seric 		printf("\n----Rule Set %d:", ruleset);
5793308Seric 
5804072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
5813308Seric 		{
5828067Seric 			printf("\nLHS:");
5838067Seric 			printav(rwp->r_lhs);
5848067Seric 			printf("RHS:");
5858067Seric 			printav(rwp->r_rhs);
5863308Seric 		}
5873308Seric 	}
5883308Seric }
5894319Seric 
5904319Seric # endif DEBUG
5914096Seric /*
5928256Seric **  SETOPTION -- set global processing option
5938256Seric **
5948256Seric **	Parameters:
5958256Seric **		opt -- option name.
5968256Seric **		val -- option value (as a text string).
5978269Seric **		safe -- if set, this came from a system configuration file.
5988269Seric **		sticky -- if set, don't let other setoptions override
5998269Seric **			this value.
6008256Seric **
6018256Seric **	Returns:
6028256Seric **		none.
6038256Seric **
6048256Seric **	Side Effects:
6058256Seric **		Sets options as implied by the arguments.
6068256Seric */
6078256Seric 
60810687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
60910687Seric extern char	*WizWord;		/* the stored wizard password */
61016143Seric extern char	*NetName;		/* name of home (local) network */
6118269Seric 
6128269Seric setoption(opt, val, safe, sticky)
6138256Seric 	char opt;
6148256Seric 	char *val;
6158269Seric 	bool safe;
6168269Seric 	bool sticky;
6178256Seric {
6188265Seric 	extern bool atobool();
61912633Seric 	extern time_t convtime();
62014879Seric 	extern int QueueLA;
62114879Seric 	extern int RefuseLA;
6228256Seric 
6238256Seric # ifdef DEBUG
6248256Seric 	if (tTd(37, 1))
6259341Seric 		printf("setoption %c=%s", opt, val);
6268256Seric # endif DEBUG
6278256Seric 
6288256Seric 	/*
6298269Seric 	**  See if this option is preset for us.
6308256Seric 	*/
6318256Seric 
63210687Seric 	if (bitnset(opt, StickyOpt))
6338269Seric 	{
6348269Seric # ifdef DEBUG
6359341Seric 		if (tTd(37, 1))
6369341Seric 			printf(" (ignored)\n");
6378269Seric # endif DEBUG
6388269Seric 		return;
6398269Seric 	}
6409341Seric #ifdef DEBUG
6419341Seric 	else if (tTd(37, 1))
6429341Seric 		printf("\n");
6439341Seric #endif DEBUG
6448269Seric 
6458269Seric 	if (getruid() == 0)
6468269Seric 		safe = TRUE;
6478269Seric 
6488256Seric 	switch (opt)
6498256Seric 	{
6508256Seric 	  case 'A':		/* set default alias file */
6519381Seric 		if (val[0] == '\0')
6528269Seric 			AliasFile = "aliases";
6539381Seric 		else
6549381Seric 			AliasFile = newstr(val);
6558256Seric 		break;
6568256Seric 
65716843Seric 	  case 'B':		/* substitution for blank character */
65816843Seric 		SpaceSub = val[0];
65916843Seric 		if (SpaceSub == '\0')
66016843Seric 			SpaceSub = ' ';
66116843Seric 		break;
66216843Seric 
6638931Seric 	  case 'a':		/* look for "@:@" in alias file */
6649381Seric 		SafeAlias = atobool(val);
6658931Seric 		break;
6668931Seric 
6679284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
6689381Seric 		NoConnect = atobool(val);
6699284Seric 		break;
6709284Seric 
6719284Seric 	  case 'd':		/* delivery mode */
6729284Seric 		switch (*val)
6738269Seric 		{
6749284Seric 		  case '\0':
6759284Seric 			SendMode = SM_DELIVER;
6768269Seric 			break;
6778269Seric 
67810755Seric 		  case SM_QUEUE:	/* queue only */
67910755Seric #ifndef QUEUE
68010755Seric 			syserr("need QUEUE to set -odqueue");
68110755Seric #endif QUEUE
68210755Seric 			/* fall through..... */
68310755Seric 
6849284Seric 		  case SM_DELIVER:	/* do everything */
6859284Seric 		  case SM_FORK:		/* fork after verification */
6869284Seric 			SendMode = *val;
6878269Seric 			break;
6888269Seric 
6898269Seric 		  default:
6909284Seric 			syserr("Unknown delivery mode %c", *val);
6918269Seric 			exit(EX_USAGE);
6928269Seric 		}
6938269Seric 		break;
6948269Seric 
6959146Seric 	  case 'D':		/* rebuild alias database as needed */
6969381Seric 		AutoRebuild = atobool(val);
6979146Seric 		break;
6989146Seric 
6998269Seric 	  case 'e':		/* set error processing mode */
7008269Seric 		switch (*val)
7018269Seric 		{
7029381Seric 		  case EM_QUIET:	/* be silent about it */
7039381Seric 		  case EM_MAIL:		/* mail back */
7049381Seric 		  case EM_BERKNET:	/* do berknet error processing */
7059381Seric 		  case EM_WRITE:	/* write back (or mail) */
7068269Seric 			HoldErrs = TRUE;
7079381Seric 			/* fall through... */
7088269Seric 
7099381Seric 		  case EM_PRINT:	/* print errors normally (default) */
7109381Seric 			ErrorMode = *val;
7118269Seric 			break;
7128269Seric 		}
7138269Seric 		break;
7148269Seric 
7159049Seric 	  case 'F':		/* file mode */
7169381Seric 		FileMode = atooct(val);
7179049Seric 		break;
7189049Seric 
7198269Seric 	  case 'f':		/* save Unix-style From lines on front */
7209381Seric 		SaveFrom = atobool(val);
7218269Seric 		break;
7228269Seric 
7238256Seric 	  case 'g':		/* default gid */
7249105Seric 		if (safe)
7259381Seric 			DefGid = atoi(val);
7268256Seric 		break;
7278256Seric 
7288256Seric 	  case 'H':		/* help file */
7299381Seric 		if (val[0] == '\0')
7308269Seric 			HelpFile = "sendmail.hf";
7319381Seric 		else
7329381Seric 			HelpFile = newstr(val);
7338256Seric 		break;
7348256Seric 
7358269Seric 	  case 'i':		/* ignore dot lines in message */
7369381Seric 		IgnrDot = atobool(val);
7378269Seric 		break;
7388269Seric 
7398256Seric 	  case 'L':		/* log level */
7409381Seric 		LogLevel = atoi(val);
7418256Seric 		break;
7428256Seric 
7438269Seric 	  case 'M':		/* define macro */
7449381Seric 		define(val[0], newstr(&val[1]), CurEnv);
74516878Seric 		sticky = FALSE;
7468269Seric 		break;
7478269Seric 
7488269Seric 	  case 'm':		/* send to me too */
7499381Seric 		MeToo = atobool(val);
7508269Seric 		break;
7518269Seric 
75216143Seric # ifdef DAEMON
75316143Seric 	  case 'N':		/* home (local?) network name */
75416143Seric 		NetName = newstr(val);
75516143Seric 		break;
75616143Seric # endif DAEMON
75716143Seric 
7588269Seric 	  case 'o':		/* assume old style headers */
7599381Seric 		if (atobool(val))
7609341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
7619341Seric 		else
7629341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
7638269Seric 		break;
7648269Seric 
7658256Seric 	  case 'Q':		/* queue directory */
7669381Seric 		if (val[0] == '\0')
7678269Seric 			QueueDir = "mqueue";
7689381Seric 		else
7699381Seric 			QueueDir = newstr(val);
7708256Seric 		break;
7718256Seric 
7728256Seric 	  case 'r':		/* read timeout */
7739381Seric 		ReadTimeout = convtime(val);
7748256Seric 		break;
7758256Seric 
7768256Seric 	  case 'S':		/* status file */
7779381Seric 		if (val[0] == '\0')
7788269Seric 			StatFile = "sendmail.st";
7799381Seric 		else
7809381Seric 			StatFile = newstr(val);
7818256Seric 		break;
7828256Seric 
7838265Seric 	  case 's':		/* be super safe, even if expensive */
7849381Seric 		SuperSafe = atobool(val);
7858256Seric 		break;
7868256Seric 
7878256Seric 	  case 'T':		/* queue timeout */
7889381Seric 		TimeOut = convtime(val);
7898256Seric 		break;
7908256Seric 
7918265Seric 	  case 't':		/* time zone name */
7928265Seric # ifdef V6
7939381Seric 		StdTimezone = newstr(val);
7949381Seric 		DstTimezone = index(StdTimeZone, ',');
7958265Seric 		if (DstTimezone == NULL)
7969381Seric 			syserr("bad time zone spec");
7979381Seric 		else
7989381Seric 			*DstTimezone++ = '\0';
7998265Seric # endif V6
8008265Seric 		break;
8018265Seric 
8028256Seric 	  case 'u':		/* set default uid */
8039105Seric 		if (safe)
8049381Seric 			DefUid = atoi(val);
8058256Seric 		break;
8068256Seric 
8078269Seric 	  case 'v':		/* run in verbose mode */
8089381Seric 		Verbose = atobool(val);
8098256Seric 		break;
8108256Seric 
8118544Seric # ifdef DEBUG
8128544Seric 	  case 'W':		/* set the wizards password */
8139105Seric 		if (safe)
8149381Seric 			WizWord = newstr(val);
8158544Seric 		break;
8168544Seric # endif DEBUG
8178544Seric 
81814879Seric 	  case 'x':		/* load avg at which to auto-queue msgs */
81914879Seric 		QueueLA = atoi(val);
82014879Seric 		break;
82114879Seric 
82214879Seric 	  case 'X':		/* load avg at which to auto-reject connections */
82314879Seric 		RefuseLA = atoi(val);
82414879Seric 		break;
82514879Seric 
8268256Seric 	  default:
8278256Seric 		break;
8288256Seric 	}
82916878Seric 	if (sticky)
83016878Seric 		setbitn(opt, StickyOpt);
8319188Seric 	return;
8328256Seric }
83310687Seric /*
83410687Seric **  SETCLASS -- set a word into a class
83510687Seric **
83610687Seric **	Parameters:
83710687Seric **		class -- the class to put the word in.
83810687Seric **		word -- the word to enter
83910687Seric **
84010687Seric **	Returns:
84110687Seric **		none.
84210687Seric **
84310687Seric **	Side Effects:
84410687Seric **		puts the word into the symbol table.
84510687Seric */
84610687Seric 
84710687Seric setclass(class, word)
84810687Seric 	int class;
84910687Seric 	char *word;
85010687Seric {
85110687Seric 	register STAB *s;
85210687Seric 
85310687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
85410687Seric 	setbitn(class, s->s_class);
85510687Seric }
856