xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 16843)
13313Seric # include "sendmail.h"
23308Seric 
3*16843Seric SCCSID(@(#)readcf.c	4.5		08/05/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];
629350Seric 	extern char *fgetfolded();
6310709Seric 	extern char *munchstring();
643308Seric 
653308Seric 	cf = fopen(cfname, "r");
663308Seric 	if (cf == NULL)
673308Seric 	{
683308Seric 		syserr("cannot open %s", cfname);
693308Seric 		exit(EX_OSFILE);
703308Seric 	}
713308Seric 
729381Seric 	FileName = cfname;
738056Seric 	LineNumber = 0;
747854Seric 	while (fgetfolded(buf, sizeof buf, cf) != NULL)
753308Seric 	{
7616157Seric 		/* map $ into \001 (ASCII SOH) for macro expansion */
7716157Seric 		for (p = buf; *p != '\0'; p++)
7816157Seric 		{
7916157Seric 			if (*p != '$')
8016157Seric 				continue;
8116157Seric 
8216157Seric 			if (p[1] == '$')
8316157Seric 			{
8416157Seric 				/* actual dollar sign.... */
8516157Seric 				strcpy(p, p + 1);
8616157Seric 				continue;
8716157Seric 			}
8816157Seric 
8916157Seric 			/* convert to macro expansion character */
9016157Seric 			*p = '\001';
9116157Seric 		}
9216157Seric 
9316157Seric 		/* interpret this line */
943308Seric 		switch (buf[0])
953308Seric 		{
963308Seric 		  case '\0':
973308Seric 		  case '#':		/* comment */
983308Seric 			break;
993308Seric 
1003308Seric 		  case 'R':		/* rewriting rule */
1013308Seric 			for (p = &buf[1]; *p != '\0' && *p != '\t'; p++)
1023308Seric 				continue;
1033308Seric 
1043308Seric 			if (*p == '\0')
1055909Seric 			{
1069381Seric 				syserr("invalid rewrite line \"%s\"", buf);
1075909Seric 				break;
1085909Seric 			}
1095909Seric 
1105909Seric 			/* allocate space for the rule header */
1115909Seric 			if (rwp == NULL)
1125909Seric 			{
1135909Seric 				RewriteRules[ruleset] = rwp =
1145909Seric 					(struct rewrite *) xalloc(sizeof *rwp);
1155909Seric 			}
1163308Seric 			else
1173308Seric 			{
1185909Seric 				rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
1195909Seric 				rwp = rwp->r_next;
1205909Seric 			}
1215909Seric 			rwp->r_next = NULL;
1223308Seric 
1235909Seric 			/* expand and save the LHS */
1245909Seric 			*p = '\0';
1256991Seric 			expand(&buf[1], exbuf, &exbuf[sizeof exbuf], CurEnv);
1265909Seric 			rwp->r_lhs = prescan(exbuf, '\t');
1275909Seric 			if (rwp->r_lhs != NULL)
1285909Seric 				rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
1295909Seric 
1305909Seric 			/* expand and save the RHS */
1315909Seric 			while (*++p == '\t')
1325909Seric 				continue;
1337231Seric 			q = p;
1347231Seric 			while (*p != '\0' && *p != '\t')
1357231Seric 				p++;
1367231Seric 			*p = '\0';
1377231Seric 			expand(q, exbuf, &exbuf[sizeof exbuf], CurEnv);
1385909Seric 			rwp->r_rhs = prescan(exbuf, '\t');
1395909Seric 			if (rwp->r_rhs != NULL)
1405909Seric 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
1413308Seric 			break;
1423308Seric 
1434072Seric 		  case 'S':		/* select rewriting set */
1444072Seric 			ruleset = atoi(&buf[1]);
1458056Seric 			if (ruleset >= MAXRWSETS || ruleset < 0)
1468056Seric 			{
1479381Seric 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
1488056Seric 				ruleset = 0;
1498056Seric 			}
1504072Seric 			rwp = NULL;
1514072Seric 			break;
1524072Seric 
1533308Seric 		  case 'D':		/* macro definition */
15410709Seric 			define(buf[1], newstr(munchstring(&buf[2])), CurEnv);
1553308Seric 			break;
1563308Seric 
1573387Seric 		  case 'H':		/* required header line */
1584088Seric 			(void) chompheader(&buf[1], TRUE);
1593387Seric 			break;
1603387Seric 
1614061Seric 		  case 'C':		/* word class */
1624432Seric 		  case 'F':		/* word class from file */
1634432Seric 			/* read list of words from argument or file */
1644432Seric 			if (buf[0] == 'F')
1654432Seric 			{
1664432Seric 				/* read from file */
1674432Seric 				for (p = &buf[2]; *p != '\0' && !isspace(*p); p++)
1684432Seric 					continue;
1694432Seric 				if (*p == '\0')
1704432Seric 					p = "%s";
1714432Seric 				else
1724432Seric 				{
1734432Seric 					*p = '\0';
1744432Seric 					while (isspace(*++p))
1754432Seric 						continue;
1764432Seric 				}
17710687Seric 				fileclass(buf[1], &buf[2], p);
1784432Seric 				break;
1794432Seric 			}
1804061Seric 
1814432Seric 			/* scan the list of words and set class for all */
1824061Seric 			for (p = &buf[2]; *p != '\0'; )
1834061Seric 			{
1844061Seric 				register char *wd;
1854061Seric 				char delim;
1864061Seric 
1874061Seric 				while (*p != '\0' && isspace(*p))
1884061Seric 					p++;
1894061Seric 				wd = p;
1904061Seric 				while (*p != '\0' && !isspace(*p))
1914061Seric 					p++;
1924061Seric 				delim = *p;
1934061Seric 				*p = '\0';
1944061Seric 				if (wd[0] != '\0')
19510687Seric 					setclass(buf[1], wd);
1964061Seric 				*p = delim;
1974061Seric 			}
1984061Seric 			break;
1994061Seric 
2004096Seric 		  case 'M':		/* define mailer */
2014217Seric 			makemailer(&buf[1], safe);
2024096Seric 			break;
2034096Seric 
2048252Seric 		  case 'O':		/* set option */
2058269Seric 			setoption(buf[1], &buf[2], safe, FALSE);
2068252Seric 			break;
2078252Seric 
2088252Seric 		  case 'P':		/* set precedence */
2098252Seric 			if (NumPriorities >= MAXPRIORITIES)
2108252Seric 			{
2118547Seric 				toomany('P', MAXPRIORITIES);
2128252Seric 				break;
2138252Seric 			}
2149381Seric 			for (p = &buf[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
2158252Seric 				continue;
2168252Seric 			if (*p == '\0')
2178252Seric 				goto badline;
2188252Seric 			*p = '\0';
2198252Seric 			Priorities[NumPriorities].pri_name = newstr(&buf[1]);
2208252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
2218252Seric 			NumPriorities++;
2228252Seric 			break;
2238252Seric 
2248547Seric 		  case 'T':		/* trusted user(s) */
2258547Seric 			p = &buf[1];
2268547Seric 			while (*p != '\0')
2278547Seric 			{
2288547Seric 				while (isspace(*p))
2298547Seric 					p++;
2308547Seric 				q = p;
2318547Seric 				while (*p != '\0' && !isspace(*p))
2328547Seric 					p++;
2338547Seric 				if (*p != '\0')
2348547Seric 					*p++ = '\0';
2358547Seric 				if (*q == '\0')
2368547Seric 					continue;
2378547Seric 				for (pv = TrustedUsers; *pv != NULL; pv++)
2388547Seric 					continue;
2398547Seric 				if (pv >= &TrustedUsers[MAXTRUST])
2408547Seric 				{
2418547Seric 					toomany('T', MAXTRUST);
2428547Seric 					break;
2438547Seric 				}
2448547Seric 				*pv = newstr(q);
2458547Seric 			}
2468547Seric 			break;
2478547Seric 
2483308Seric 		  default:
2494061Seric 		  badline:
2509381Seric 			syserr("unknown control line \"%s\"", buf);
2513308Seric 		}
2523308Seric 	}
2539381Seric 	FileName = NULL;
2544096Seric }
2554096Seric /*
2568547Seric **  TOOMANY -- signal too many of some option
2578547Seric **
2588547Seric **	Parameters:
2598547Seric **		id -- the id of the error line
2608547Seric **		maxcnt -- the maximum possible values
2618547Seric **
2628547Seric **	Returns:
2638547Seric **		none.
2648547Seric **
2658547Seric **	Side Effects:
2668547Seric **		gives a syserr.
2678547Seric */
2688547Seric 
2698547Seric toomany(id, maxcnt)
2708547Seric 	char id;
2718547Seric 	int maxcnt;
2728547Seric {
2739381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
2748547Seric }
2758547Seric /*
2764432Seric **  FILECLASS -- read members of a class from a file
2774432Seric **
2784432Seric **	Parameters:
2794432Seric **		class -- class to define.
2804432Seric **		filename -- name of file to read.
2814432Seric **		fmt -- scanf string to use for match.
2824432Seric **
2834432Seric **	Returns:
2844432Seric **		none
2854432Seric **
2864432Seric **	Side Effects:
2874432Seric **
2884432Seric **		puts all lines in filename that match a scanf into
2894432Seric **			the named class.
2904432Seric */
2914432Seric 
2924432Seric fileclass(class, filename, fmt)
2934432Seric 	int class;
2944432Seric 	char *filename;
2954432Seric 	char *fmt;
2964432Seric {
2974432Seric 	register FILE *f;
2984432Seric 	char buf[MAXLINE];
2994432Seric 
3004432Seric 	f = fopen(filename, "r");
3014432Seric 	if (f == NULL)
3024432Seric 	{
3034432Seric 		syserr("cannot open %s", filename);
3044432Seric 		return;
3054432Seric 	}
3064432Seric 
3074432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
3084432Seric 	{
3094432Seric 		register STAB *s;
3104432Seric 		char wordbuf[MAXNAME+1];
3114432Seric 
3124432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
3134432Seric 			continue;
3144432Seric 		s = stab(wordbuf, ST_CLASS, ST_ENTER);
31510687Seric 		setbitn(class, s->s_class);
3164432Seric 	}
3174432Seric 
3184627Seric 	(void) fclose(f);
3194432Seric }
3204432Seric /*
3214096Seric **  MAKEMAILER -- define a new mailer.
3224096Seric **
3234096Seric **	Parameters:
32410327Seric **		line -- description of mailer.  This is in labeled
32510327Seric **			fields.  The fields are:
32610327Seric **			   P -- the path to the mailer
32710327Seric **			   F -- the flags associated with the mailer
32810327Seric **			   A -- the argv for this mailer
32910327Seric **			   S -- the sender rewriting set
33010327Seric **			   R -- the recipient rewriting set
33110327Seric **			   E -- the eol string
33210327Seric **			The first word is the canonical name of the mailer.
3334217Seric **		safe -- set if this is a safe configuration file.
3344096Seric **
3354096Seric **	Returns:
3364096Seric **		none.
3374096Seric **
3384096Seric **	Side Effects:
3394096Seric **		enters the mailer into the mailer table.
3404096Seric */
3413308Seric 
3424217Seric makemailer(line, safe)
3434096Seric 	char *line;
3444217Seric 	bool safe;
3454096Seric {
3464096Seric 	register char *p;
3478067Seric 	register struct mailer *m;
3488067Seric 	register STAB *s;
3498067Seric 	int i;
35010327Seric 	char fcode;
3514096Seric 	extern int NextMailer;
35210327Seric 	extern char **makeargv();
35310327Seric 	extern char *munchstring();
35410327Seric 	extern char *DelimChar;
35510701Seric 	extern long atol();
3564096Seric 
35710327Seric 	/* allocate a mailer and set up defaults */
35810327Seric 	m = (struct mailer *) xalloc(sizeof *m);
35910327Seric 	bzero((char *) m, sizeof *m);
36010327Seric 	m->m_mno = NextMailer;
36110327Seric 	m->m_eol = "\n";
36210327Seric 
36310327Seric 	/* collect the mailer name */
36410327Seric 	for (p = line; *p != '\0' && *p != ',' && !isspace(*p); p++)
36510327Seric 		continue;
36610327Seric 	if (*p != '\0')
36710327Seric 		*p++ = '\0';
36810327Seric 	m->m_name = newstr(line);
36910327Seric 
37010327Seric 	/* now scan through and assign info from the fields */
37110327Seric 	while (*p != '\0')
37210327Seric 	{
37310327Seric 		while (*p != '\0' && (*p == ',' || isspace(*p)))
37410327Seric 			p++;
37510327Seric 
37610327Seric 		/* p now points to field code */
37710327Seric 		fcode = *p;
37810327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
37910327Seric 			p++;
38010327Seric 		if (*p++ != '=')
38110327Seric 		{
38210327Seric 			syserr("`=' expected");
38310327Seric 			return;
38410327Seric 		}
38510327Seric 		while (isspace(*p))
38610327Seric 			p++;
38710327Seric 
38810327Seric 		/* p now points to the field body */
38910327Seric 		p = munchstring(p);
39010327Seric 
39110327Seric 		/* install the field into the mailer struct */
39210327Seric 		switch (fcode)
39310327Seric 		{
39410327Seric 		  case 'P':		/* pathname */
39510327Seric 			m->m_mailer = newstr(p);
39610327Seric 			break;
39710327Seric 
39810327Seric 		  case 'F':		/* flags */
39910687Seric 			for (; *p != '\0'; p++)
40010687Seric 				setbitn(*p, m->m_flags);
40110327Seric 			if (!safe)
40210687Seric 				clrbitn(M_RESTR, m->m_flags);
40310327Seric 			break;
40410327Seric 
40510327Seric 		  case 'S':		/* sender rewriting ruleset */
40610327Seric 		  case 'R':		/* recipient rewriting ruleset */
40710327Seric 			i = atoi(p);
40810327Seric 			if (i < 0 || i >= MAXRWSETS)
40910327Seric 			{
41010327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
41110327Seric 				return;
41210327Seric 			}
41310327Seric 			if (fcode == 'S')
41410327Seric 				m->m_s_rwset = i;
41510327Seric 			else
41610327Seric 				m->m_r_rwset = i;
41710327Seric 			break;
41810327Seric 
41910327Seric 		  case 'E':		/* end of line string */
42010327Seric 			m->m_eol = newstr(p);
42110327Seric 			break;
42210327Seric 
42310327Seric 		  case 'A':		/* argument vector */
42410327Seric 			m->m_argv = makeargv(p);
42510327Seric 			break;
42610701Seric 
42710701Seric 		  case 'M':		/* maximum message size */
42810701Seric 			m->m_maxsize = atol(p);
42910701Seric 			break;
43010327Seric 		}
43110327Seric 
43210327Seric 		p = DelimChar;
43310327Seric 	}
43410327Seric 
43510327Seric 	/* now store the mailer away */
4364096Seric 	if (NextMailer >= MAXMAILERS)
4374096Seric 	{
4389381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
4394096Seric 		return;
4404096Seric 	}
44110327Seric 	Mailer[NextMailer++] = m;
44210327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
44310327Seric 	s->s_mailer = m;
44410327Seric }
44510327Seric /*
44610327Seric **  MUNCHSTRING -- translate a string into internal form.
44710327Seric **
44810327Seric **	Parameters:
44910327Seric **		p -- the string to munch.
45010327Seric **
45110327Seric **	Returns:
45210327Seric **		the munched string.
45310327Seric **
45410327Seric **	Side Effects:
45510327Seric **		Sets "DelimChar" to point to the string that caused us
45610327Seric **		to stop.
45710327Seric */
4584096Seric 
45910327Seric char *
46010327Seric munchstring(p)
46110327Seric 	register char *p;
46210327Seric {
46310327Seric 	register char *q;
46410327Seric 	bool backslash = FALSE;
46510327Seric 	bool quotemode = FALSE;
46610327Seric 	static char buf[MAXLINE];
46710327Seric 	extern char *DelimChar;
4684096Seric 
46910327Seric 	for (q = buf; *p != '\0'; p++)
4704096Seric 	{
47110327Seric 		if (backslash)
47210327Seric 		{
47310327Seric 			/* everything is roughly literal */
47410357Seric 			backslash = FALSE;
47510327Seric 			switch (*p)
47610327Seric 			{
47710327Seric 			  case 'r':		/* carriage return */
47810327Seric 				*q++ = '\r';
47910327Seric 				continue;
48010327Seric 
48110327Seric 			  case 'n':		/* newline */
48210327Seric 				*q++ = '\n';
48310327Seric 				continue;
48410327Seric 
48510327Seric 			  case 'f':		/* form feed */
48610327Seric 				*q++ = '\f';
48710327Seric 				continue;
48810327Seric 
48910327Seric 			  case 'b':		/* backspace */
49010327Seric 				*q++ = '\b';
49110327Seric 				continue;
49210327Seric 			}
49310327Seric 			*q++ = *p;
49410327Seric 		}
49510327Seric 		else
49610327Seric 		{
49710327Seric 			if (*p == '\\')
49810327Seric 				backslash = TRUE;
49910327Seric 			else if (*p == '"')
50010327Seric 				quotemode = !quotemode;
50110327Seric 			else if (quotemode || *p != ',')
50210327Seric 				*q++ = *p;
50310327Seric 			else
50410327Seric 				break;
50510327Seric 		}
5064096Seric 	}
5074096Seric 
50810327Seric 	DelimChar = p;
50910327Seric 	*q++ = '\0';
51010327Seric 	return (buf);
51110327Seric }
51210327Seric /*
51310327Seric **  MAKEARGV -- break up a string into words
51410327Seric **
51510327Seric **	Parameters:
51610327Seric **		p -- the string to break up.
51710327Seric **
51810327Seric **	Returns:
51910327Seric **		a char **argv (dynamically allocated)
52010327Seric **
52110327Seric **	Side Effects:
52210327Seric **		munges p.
52310327Seric */
5244096Seric 
52510327Seric char **
52610327Seric makeargv(p)
52710327Seric 	register char *p;
52810327Seric {
52910327Seric 	char *q;
53010327Seric 	int i;
53110327Seric 	char **avp;
53210327Seric 	char *argv[MAXPV + 1];
53310327Seric 
53410327Seric 	/* take apart the words */
53510327Seric 	i = 0;
53610327Seric 	while (*p != '\0' && i < MAXPV)
5374096Seric 	{
53810327Seric 		q = p;
53910327Seric 		while (*p != '\0' && !isspace(*p))
54010327Seric 			p++;
54110327Seric 		while (isspace(*p))
54210327Seric 			*p++ = '\0';
54310327Seric 		argv[i++] = newstr(q);
5444096Seric 	}
54510327Seric 	argv[i++] = NULL;
5464096Seric 
54710327Seric 	/* now make a copy of the argv */
54810327Seric 	avp = (char **) xalloc(sizeof *avp * i);
54910327Seric 	bmove((char *) argv, (char *) avp, sizeof *avp * i);
55010327Seric 
55110327Seric 	return (avp);
5523308Seric }
5533308Seric /*
5543308Seric **  PRINTRULES -- print rewrite rules (for debugging)
5553308Seric **
5563308Seric **	Parameters:
5573308Seric **		none.
5583308Seric **
5593308Seric **	Returns:
5603308Seric **		none.
5613308Seric **
5623308Seric **	Side Effects:
5633308Seric **		prints rewrite rules.
5643308Seric */
5653308Seric 
5664319Seric # ifdef DEBUG
5674319Seric 
5683308Seric printrules()
5693308Seric {
5703308Seric 	register struct rewrite *rwp;
5714072Seric 	register int ruleset;
5723308Seric 
5734072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
5743308Seric 	{
5754072Seric 		if (RewriteRules[ruleset] == NULL)
5764072Seric 			continue;
5778067Seric 		printf("\n----Rule Set %d:", ruleset);
5783308Seric 
5794072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
5803308Seric 		{
5818067Seric 			printf("\nLHS:");
5828067Seric 			printav(rwp->r_lhs);
5838067Seric 			printf("RHS:");
5848067Seric 			printav(rwp->r_rhs);
5853308Seric 		}
5863308Seric 	}
5873308Seric }
5884319Seric 
5894319Seric # endif DEBUG
5904096Seric /*
5918256Seric **  SETOPTION -- set global processing option
5928256Seric **
5938256Seric **	Parameters:
5948256Seric **		opt -- option name.
5958256Seric **		val -- option value (as a text string).
5968269Seric **		safe -- if set, this came from a system configuration file.
5978269Seric **		sticky -- if set, don't let other setoptions override
5988269Seric **			this value.
5998256Seric **
6008256Seric **	Returns:
6018256Seric **		none.
6028256Seric **
6038256Seric **	Side Effects:
6048256Seric **		Sets options as implied by the arguments.
6058256Seric */
6068256Seric 
60710687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
60810687Seric extern char	*WizWord;		/* the stored wizard password */
60916143Seric extern char	*NetName;		/* name of home (local) network */
6108269Seric 
6118269Seric setoption(opt, val, safe, sticky)
6128256Seric 	char opt;
6138256Seric 	char *val;
6148269Seric 	bool safe;
6158269Seric 	bool sticky;
6168256Seric {
6178265Seric 	extern bool atobool();
61812633Seric 	extern time_t convtime();
61914879Seric 	extern int QueueLA;
62014879Seric 	extern int RefuseLA;
6218256Seric 
6228256Seric # ifdef DEBUG
6238256Seric 	if (tTd(37, 1))
6249341Seric 		printf("setoption %c=%s", opt, val);
6258256Seric # endif DEBUG
6268256Seric 
6278256Seric 	/*
6288269Seric 	**  See if this option is preset for us.
6298256Seric 	*/
6308256Seric 
63110687Seric 	if (bitnset(opt, StickyOpt))
6328269Seric 	{
6338269Seric # ifdef DEBUG
6349341Seric 		if (tTd(37, 1))
6359341Seric 			printf(" (ignored)\n");
6368269Seric # endif DEBUG
6378269Seric 		return;
6388269Seric 	}
6399341Seric #ifdef DEBUG
6409341Seric 	else if (tTd(37, 1))
6419341Seric 		printf("\n");
6429341Seric #endif DEBUG
6438269Seric 	if (sticky)
64410687Seric 		setbitn(opt, StickyOpt);
6458269Seric 
6468269Seric 	if (getruid() == 0)
6478269Seric 		safe = TRUE;
6488269Seric 
6498256Seric 	switch (opt)
6508256Seric 	{
6518256Seric 	  case 'A':		/* set default alias file */
6529381Seric 		if (val[0] == '\0')
6538269Seric 			AliasFile = "aliases";
6549381Seric 		else
6559381Seric 			AliasFile = newstr(val);
6568256Seric 		break;
6578256Seric 
658*16843Seric 	  case 'B':		/* substitution for blank character */
659*16843Seric 		SpaceSub = val[0];
660*16843Seric 		if (SpaceSub == '\0')
661*16843Seric 			SpaceSub = ' ';
662*16843Seric 		break;
663*16843Seric 
6648931Seric 	  case 'a':		/* look for "@:@" in alias file */
6659381Seric 		SafeAlias = atobool(val);
6668931Seric 		break;
6678931Seric 
6689284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
6699381Seric 		NoConnect = atobool(val);
6709284Seric 		break;
6719284Seric 
6729284Seric 	  case 'd':		/* delivery mode */
6739284Seric 		switch (*val)
6748269Seric 		{
6759284Seric 		  case '\0':
6769284Seric 			SendMode = SM_DELIVER;
6778269Seric 			break;
6788269Seric 
67910755Seric 		  case SM_QUEUE:	/* queue only */
68010755Seric #ifndef QUEUE
68110755Seric 			syserr("need QUEUE to set -odqueue");
68210755Seric #endif QUEUE
68310755Seric 			/* fall through..... */
68410755Seric 
6859284Seric 		  case SM_DELIVER:	/* do everything */
6869284Seric 		  case SM_FORK:		/* fork after verification */
6879284Seric 			SendMode = *val;
6888269Seric 			break;
6898269Seric 
6908269Seric 		  default:
6919284Seric 			syserr("Unknown delivery mode %c", *val);
6928269Seric 			exit(EX_USAGE);
6938269Seric 		}
6948269Seric 		break;
6958269Seric 
6969146Seric 	  case 'D':		/* rebuild alias database as needed */
6979381Seric 		AutoRebuild = atobool(val);
6989146Seric 		break;
6999146Seric 
7008269Seric 	  case 'e':		/* set error processing mode */
7018269Seric 		switch (*val)
7028269Seric 		{
7039381Seric 		  case EM_QUIET:	/* be silent about it */
7049381Seric 		  case EM_MAIL:		/* mail back */
7059381Seric 		  case EM_BERKNET:	/* do berknet error processing */
7069381Seric 		  case EM_WRITE:	/* write back (or mail) */
7078269Seric 			HoldErrs = TRUE;
7089381Seric 			/* fall through... */
7098269Seric 
7109381Seric 		  case EM_PRINT:	/* print errors normally (default) */
7119381Seric 			ErrorMode = *val;
7128269Seric 			break;
7138269Seric 		}
7148269Seric 		break;
7158269Seric 
7169049Seric 	  case 'F':		/* file mode */
7179381Seric 		FileMode = atooct(val);
7189049Seric 		break;
7199049Seric 
7208269Seric 	  case 'f':		/* save Unix-style From lines on front */
7219381Seric 		SaveFrom = atobool(val);
7228269Seric 		break;
7238269Seric 
7248256Seric 	  case 'g':		/* default gid */
7259105Seric 		if (safe)
7269381Seric 			DefGid = atoi(val);
7278256Seric 		break;
7288256Seric 
7298256Seric 	  case 'H':		/* help file */
7309381Seric 		if (val[0] == '\0')
7318269Seric 			HelpFile = "sendmail.hf";
7329381Seric 		else
7339381Seric 			HelpFile = newstr(val);
7348256Seric 		break;
7358256Seric 
7368269Seric 	  case 'i':		/* ignore dot lines in message */
7379381Seric 		IgnrDot = atobool(val);
7388269Seric 		break;
7398269Seric 
7408256Seric 	  case 'L':		/* log level */
7419381Seric 		LogLevel = atoi(val);
7428256Seric 		break;
7438256Seric 
7448269Seric 	  case 'M':		/* define macro */
7459381Seric 		define(val[0], newstr(&val[1]), CurEnv);
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 	}
8299188Seric 	return;
8308256Seric }
83110687Seric /*
83210687Seric **  SETCLASS -- set a word into a class
83310687Seric **
83410687Seric **	Parameters:
83510687Seric **		class -- the class to put the word in.
83610687Seric **		word -- the word to enter
83710687Seric **
83810687Seric **	Returns:
83910687Seric **		none.
84010687Seric **
84110687Seric **	Side Effects:
84210687Seric **		puts the word into the symbol table.
84310687Seric */
84410687Seric 
84510687Seric setclass(class, word)
84610687Seric 	int class;
84710687Seric 	char *word;
84810687Seric {
84910687Seric 	register STAB *s;
85010687Seric 
85110687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
85210687Seric 	setbitn(class, s->s_class);
85310687Seric }
854