xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 21755)
13313Seric # include "sendmail.h"
23308Seric 
3*21755Seric SCCSID(@(#)readcf.c	4.13		06/02/85);
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.
363308Seric **
373308Seric **	Returns:
383308Seric **		none.
393308Seric **
403308Seric **	Side Effects:
413308Seric **		Builds several internal tables.
423308Seric */
433308Seric 
4421066Seric readcf(cfname)
453308Seric 	char *cfname;
463308Seric {
473308Seric 	FILE *cf;
488547Seric 	int ruleset = 0;
498547Seric 	char *q;
508547Seric 	char **pv;
519350Seric 	struct rewrite *rwp = NULL;
523308Seric 	char buf[MAXLINE];
533308Seric 	register char *p;
543308Seric 	extern char **prescan();
553308Seric 	extern char **copyplist();
565909Seric 	char exbuf[MAXLINE];
5716915Seric 	char pvpbuf[PSBUFSIZE];
589350Seric 	extern char *fgetfolded();
5910709Seric 	extern char *munchstring();
603308Seric 
613308Seric 	cf = fopen(cfname, "r");
623308Seric 	if (cf == NULL)
633308Seric 	{
643308Seric 		syserr("cannot open %s", cfname);
653308Seric 		exit(EX_OSFILE);
663308Seric 	}
673308Seric 
689381Seric 	FileName = cfname;
698056Seric 	LineNumber = 0;
707854Seric 	while (fgetfolded(buf, sizeof buf, cf) != NULL)
713308Seric 	{
7216157Seric 		/* map $ into \001 (ASCII SOH) for macro expansion */
7316157Seric 		for (p = buf; *p != '\0'; p++)
7416157Seric 		{
7516157Seric 			if (*p != '$')
7616157Seric 				continue;
7716157Seric 
7816157Seric 			if (p[1] == '$')
7916157Seric 			{
8016157Seric 				/* actual dollar sign.... */
8116157Seric 				strcpy(p, p + 1);
8216157Seric 				continue;
8316157Seric 			}
8416157Seric 
8516157Seric 			/* convert to macro expansion character */
8616157Seric 			*p = '\001';
8716157Seric 		}
8816157Seric 
8916157Seric 		/* interpret this line */
903308Seric 		switch (buf[0])
913308Seric 		{
923308Seric 		  case '\0':
933308Seric 		  case '#':		/* comment */
943308Seric 			break;
953308Seric 
963308Seric 		  case 'R':		/* rewriting rule */
973308Seric 			for (p = &buf[1]; *p != '\0' && *p != '\t'; p++)
983308Seric 				continue;
993308Seric 
1003308Seric 			if (*p == '\0')
1015909Seric 			{
1029381Seric 				syserr("invalid rewrite line \"%s\"", buf);
1035909Seric 				break;
1045909Seric 			}
1055909Seric 
1065909Seric 			/* allocate space for the rule header */
1075909Seric 			if (rwp == NULL)
1085909Seric 			{
1095909Seric 				RewriteRules[ruleset] = rwp =
1105909Seric 					(struct rewrite *) xalloc(sizeof *rwp);
1115909Seric 			}
1123308Seric 			else
1133308Seric 			{
1145909Seric 				rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
1155909Seric 				rwp = rwp->r_next;
1165909Seric 			}
1175909Seric 			rwp->r_next = NULL;
1183308Seric 
1195909Seric 			/* expand and save the LHS */
1205909Seric 			*p = '\0';
1216991Seric 			expand(&buf[1], exbuf, &exbuf[sizeof exbuf], CurEnv);
12216915Seric 			rwp->r_lhs = prescan(exbuf, '\t', pvpbuf);
1235909Seric 			if (rwp->r_lhs != NULL)
1245909Seric 				rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
1255909Seric 
1265909Seric 			/* expand and save the RHS */
1275909Seric 			while (*++p == '\t')
1285909Seric 				continue;
1297231Seric 			q = p;
1307231Seric 			while (*p != '\0' && *p != '\t')
1317231Seric 				p++;
1327231Seric 			*p = '\0';
1337231Seric 			expand(q, exbuf, &exbuf[sizeof exbuf], CurEnv);
13416915Seric 			rwp->r_rhs = prescan(exbuf, '\t', pvpbuf);
1355909Seric 			if (rwp->r_rhs != NULL)
1365909Seric 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
1373308Seric 			break;
1383308Seric 
1394072Seric 		  case 'S':		/* select rewriting set */
1404072Seric 			ruleset = atoi(&buf[1]);
1418056Seric 			if (ruleset >= MAXRWSETS || ruleset < 0)
1428056Seric 			{
1439381Seric 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
1448056Seric 				ruleset = 0;
1458056Seric 			}
1464072Seric 			rwp = NULL;
1474072Seric 			break;
1484072Seric 
1493308Seric 		  case 'D':		/* macro definition */
15010709Seric 			define(buf[1], newstr(munchstring(&buf[2])), CurEnv);
1513308Seric 			break;
1523308Seric 
1533387Seric 		  case 'H':		/* required header line */
1544088Seric 			(void) chompheader(&buf[1], TRUE);
1553387Seric 			break;
1563387Seric 
1574061Seric 		  case 'C':		/* word class */
1584432Seric 		  case 'F':		/* word class from file */
1594432Seric 			/* read list of words from argument or file */
1604432Seric 			if (buf[0] == 'F')
1614432Seric 			{
1624432Seric 				/* read from file */
1634432Seric 				for (p = &buf[2]; *p != '\0' && !isspace(*p); p++)
1644432Seric 					continue;
1654432Seric 				if (*p == '\0')
1664432Seric 					p = "%s";
1674432Seric 				else
1684432Seric 				{
1694432Seric 					*p = '\0';
1704432Seric 					while (isspace(*++p))
1714432Seric 						continue;
1724432Seric 				}
17310687Seric 				fileclass(buf[1], &buf[2], p);
1744432Seric 				break;
1754432Seric 			}
1764061Seric 
1774432Seric 			/* scan the list of words and set class for all */
1784061Seric 			for (p = &buf[2]; *p != '\0'; )
1794061Seric 			{
1804061Seric 				register char *wd;
1814061Seric 				char delim;
1824061Seric 
1834061Seric 				while (*p != '\0' && isspace(*p))
1844061Seric 					p++;
1854061Seric 				wd = p;
1864061Seric 				while (*p != '\0' && !isspace(*p))
1874061Seric 					p++;
1884061Seric 				delim = *p;
1894061Seric 				*p = '\0';
1904061Seric 				if (wd[0] != '\0')
19110687Seric 					setclass(buf[1], wd);
1924061Seric 				*p = delim;
1934061Seric 			}
1944061Seric 			break;
1954061Seric 
1964096Seric 		  case 'M':		/* define mailer */
19721066Seric 			makemailer(&buf[1]);
1984096Seric 			break;
1994096Seric 
2008252Seric 		  case 'O':		/* set option */
201*21755Seric 			setoption(buf[1], &buf[2], TRUE, FALSE);
2028252Seric 			break;
2038252Seric 
2048252Seric 		  case 'P':		/* set precedence */
2058252Seric 			if (NumPriorities >= MAXPRIORITIES)
2068252Seric 			{
2078547Seric 				toomany('P', MAXPRIORITIES);
2088252Seric 				break;
2098252Seric 			}
2109381Seric 			for (p = &buf[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
2118252Seric 				continue;
2128252Seric 			if (*p == '\0')
2138252Seric 				goto badline;
2148252Seric 			*p = '\0';
2158252Seric 			Priorities[NumPriorities].pri_name = newstr(&buf[1]);
2168252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
2178252Seric 			NumPriorities++;
2188252Seric 			break;
2198252Seric 
2208547Seric 		  case 'T':		/* trusted user(s) */
2218547Seric 			p = &buf[1];
2228547Seric 			while (*p != '\0')
2238547Seric 			{
2248547Seric 				while (isspace(*p))
2258547Seric 					p++;
2268547Seric 				q = p;
2278547Seric 				while (*p != '\0' && !isspace(*p))
2288547Seric 					p++;
2298547Seric 				if (*p != '\0')
2308547Seric 					*p++ = '\0';
2318547Seric 				if (*q == '\0')
2328547Seric 					continue;
2338547Seric 				for (pv = TrustedUsers; *pv != NULL; pv++)
2348547Seric 					continue;
2358547Seric 				if (pv >= &TrustedUsers[MAXTRUST])
2368547Seric 				{
2378547Seric 					toomany('T', MAXTRUST);
2388547Seric 					break;
2398547Seric 				}
2408547Seric 				*pv = newstr(q);
2418547Seric 			}
2428547Seric 			break;
2438547Seric 
2443308Seric 		  default:
2454061Seric 		  badline:
2469381Seric 			syserr("unknown control line \"%s\"", buf);
2473308Seric 		}
2483308Seric 	}
2499381Seric 	FileName = NULL;
2504096Seric }
2514096Seric /*
2528547Seric **  TOOMANY -- signal too many of some option
2538547Seric **
2548547Seric **	Parameters:
2558547Seric **		id -- the id of the error line
2568547Seric **		maxcnt -- the maximum possible values
2578547Seric **
2588547Seric **	Returns:
2598547Seric **		none.
2608547Seric **
2618547Seric **	Side Effects:
2628547Seric **		gives a syserr.
2638547Seric */
2648547Seric 
2658547Seric toomany(id, maxcnt)
2668547Seric 	char id;
2678547Seric 	int maxcnt;
2688547Seric {
2699381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
2708547Seric }
2718547Seric /*
2724432Seric **  FILECLASS -- read members of a class from a file
2734432Seric **
2744432Seric **	Parameters:
2754432Seric **		class -- class to define.
2764432Seric **		filename -- name of file to read.
2774432Seric **		fmt -- scanf string to use for match.
2784432Seric **
2794432Seric **	Returns:
2804432Seric **		none
2814432Seric **
2824432Seric **	Side Effects:
2834432Seric **
2844432Seric **		puts all lines in filename that match a scanf into
2854432Seric **			the named class.
2864432Seric */
2874432Seric 
2884432Seric fileclass(class, filename, fmt)
2894432Seric 	int class;
2904432Seric 	char *filename;
2914432Seric 	char *fmt;
2924432Seric {
2934432Seric 	register FILE *f;
2944432Seric 	char buf[MAXLINE];
2954432Seric 
2964432Seric 	f = fopen(filename, "r");
2974432Seric 	if (f == NULL)
2984432Seric 	{
2994432Seric 		syserr("cannot open %s", filename);
3004432Seric 		return;
3014432Seric 	}
3024432Seric 
3034432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
3044432Seric 	{
3054432Seric 		register STAB *s;
3064432Seric 		char wordbuf[MAXNAME+1];
3074432Seric 
3084432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
3094432Seric 			continue;
3104432Seric 		s = stab(wordbuf, ST_CLASS, ST_ENTER);
31110687Seric 		setbitn(class, s->s_class);
3124432Seric 	}
3134432Seric 
3144627Seric 	(void) fclose(f);
3154432Seric }
3164432Seric /*
3174096Seric **  MAKEMAILER -- define a new mailer.
3184096Seric **
3194096Seric **	Parameters:
32010327Seric **		line -- description of mailer.  This is in labeled
32110327Seric **			fields.  The fields are:
32210327Seric **			   P -- the path to the mailer
32310327Seric **			   F -- the flags associated with the mailer
32410327Seric **			   A -- the argv for this mailer
32510327Seric **			   S -- the sender rewriting set
32610327Seric **			   R -- the recipient rewriting set
32710327Seric **			   E -- the eol string
32810327Seric **			The first word is the canonical name of the mailer.
3294096Seric **
3304096Seric **	Returns:
3314096Seric **		none.
3324096Seric **
3334096Seric **	Side Effects:
3344096Seric **		enters the mailer into the mailer table.
3354096Seric */
3363308Seric 
33721066Seric makemailer(line)
3384096Seric 	char *line;
3394096Seric {
3404096Seric 	register char *p;
3418067Seric 	register struct mailer *m;
3428067Seric 	register STAB *s;
3438067Seric 	int i;
34410327Seric 	char fcode;
3454096Seric 	extern int NextMailer;
34610327Seric 	extern char **makeargv();
34710327Seric 	extern char *munchstring();
34810327Seric 	extern char *DelimChar;
34910701Seric 	extern long atol();
3504096Seric 
35110327Seric 	/* allocate a mailer and set up defaults */
35210327Seric 	m = (struct mailer *) xalloc(sizeof *m);
35310327Seric 	bzero((char *) m, sizeof *m);
35410327Seric 	m->m_mno = NextMailer;
35510327Seric 	m->m_eol = "\n";
35610327Seric 
35710327Seric 	/* collect the mailer name */
35810327Seric 	for (p = line; *p != '\0' && *p != ',' && !isspace(*p); p++)
35910327Seric 		continue;
36010327Seric 	if (*p != '\0')
36110327Seric 		*p++ = '\0';
36210327Seric 	m->m_name = newstr(line);
36310327Seric 
36410327Seric 	/* now scan through and assign info from the fields */
36510327Seric 	while (*p != '\0')
36610327Seric 	{
36710327Seric 		while (*p != '\0' && (*p == ',' || isspace(*p)))
36810327Seric 			p++;
36910327Seric 
37010327Seric 		/* p now points to field code */
37110327Seric 		fcode = *p;
37210327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
37310327Seric 			p++;
37410327Seric 		if (*p++ != '=')
37510327Seric 		{
37610327Seric 			syserr("`=' expected");
37710327Seric 			return;
37810327Seric 		}
37910327Seric 		while (isspace(*p))
38010327Seric 			p++;
38110327Seric 
38210327Seric 		/* p now points to the field body */
38310327Seric 		p = munchstring(p);
38410327Seric 
38510327Seric 		/* install the field into the mailer struct */
38610327Seric 		switch (fcode)
38710327Seric 		{
38810327Seric 		  case 'P':		/* pathname */
38910327Seric 			m->m_mailer = newstr(p);
39010327Seric 			break;
39110327Seric 
39210327Seric 		  case 'F':		/* flags */
39310687Seric 			for (; *p != '\0'; p++)
39410687Seric 				setbitn(*p, m->m_flags);
39510327Seric 			break;
39610327Seric 
39710327Seric 		  case 'S':		/* sender rewriting ruleset */
39810327Seric 		  case 'R':		/* recipient rewriting ruleset */
39910327Seric 			i = atoi(p);
40010327Seric 			if (i < 0 || i >= MAXRWSETS)
40110327Seric 			{
40210327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
40310327Seric 				return;
40410327Seric 			}
40510327Seric 			if (fcode == 'S')
40610327Seric 				m->m_s_rwset = i;
40710327Seric 			else
40810327Seric 				m->m_r_rwset = i;
40910327Seric 			break;
41010327Seric 
41110327Seric 		  case 'E':		/* end of line string */
41210327Seric 			m->m_eol = newstr(p);
41310327Seric 			break;
41410327Seric 
41510327Seric 		  case 'A':		/* argument vector */
41610327Seric 			m->m_argv = makeargv(p);
41710327Seric 			break;
41810701Seric 
41910701Seric 		  case 'M':		/* maximum message size */
42010701Seric 			m->m_maxsize = atol(p);
42110701Seric 			break;
42210327Seric 		}
42310327Seric 
42410327Seric 		p = DelimChar;
42510327Seric 	}
42610327Seric 
42710327Seric 	/* now store the mailer away */
4284096Seric 	if (NextMailer >= MAXMAILERS)
4294096Seric 	{
4309381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
4314096Seric 		return;
4324096Seric 	}
43310327Seric 	Mailer[NextMailer++] = m;
43410327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
43510327Seric 	s->s_mailer = m;
43610327Seric }
43710327Seric /*
43810327Seric **  MUNCHSTRING -- translate a string into internal form.
43910327Seric **
44010327Seric **	Parameters:
44110327Seric **		p -- the string to munch.
44210327Seric **
44310327Seric **	Returns:
44410327Seric **		the munched string.
44510327Seric **
44610327Seric **	Side Effects:
44710327Seric **		Sets "DelimChar" to point to the string that caused us
44810327Seric **		to stop.
44910327Seric */
4504096Seric 
45110327Seric char *
45210327Seric munchstring(p)
45310327Seric 	register char *p;
45410327Seric {
45510327Seric 	register char *q;
45610327Seric 	bool backslash = FALSE;
45710327Seric 	bool quotemode = FALSE;
45810327Seric 	static char buf[MAXLINE];
45910327Seric 	extern char *DelimChar;
4604096Seric 
46110327Seric 	for (q = buf; *p != '\0'; p++)
4624096Seric 	{
46310327Seric 		if (backslash)
46410327Seric 		{
46510327Seric 			/* everything is roughly literal */
46610357Seric 			backslash = FALSE;
46710327Seric 			switch (*p)
46810327Seric 			{
46910327Seric 			  case 'r':		/* carriage return */
47010327Seric 				*q++ = '\r';
47110327Seric 				continue;
47210327Seric 
47310327Seric 			  case 'n':		/* newline */
47410327Seric 				*q++ = '\n';
47510327Seric 				continue;
47610327Seric 
47710327Seric 			  case 'f':		/* form feed */
47810327Seric 				*q++ = '\f';
47910327Seric 				continue;
48010327Seric 
48110327Seric 			  case 'b':		/* backspace */
48210327Seric 				*q++ = '\b';
48310327Seric 				continue;
48410327Seric 			}
48510327Seric 			*q++ = *p;
48610327Seric 		}
48710327Seric 		else
48810327Seric 		{
48910327Seric 			if (*p == '\\')
49010327Seric 				backslash = TRUE;
49110327Seric 			else if (*p == '"')
49210327Seric 				quotemode = !quotemode;
49310327Seric 			else if (quotemode || *p != ',')
49410327Seric 				*q++ = *p;
49510327Seric 			else
49610327Seric 				break;
49710327Seric 		}
4984096Seric 	}
4994096Seric 
50010327Seric 	DelimChar = p;
50110327Seric 	*q++ = '\0';
50210327Seric 	return (buf);
50310327Seric }
50410327Seric /*
50510327Seric **  MAKEARGV -- break up a string into words
50610327Seric **
50710327Seric **	Parameters:
50810327Seric **		p -- the string to break up.
50910327Seric **
51010327Seric **	Returns:
51110327Seric **		a char **argv (dynamically allocated)
51210327Seric **
51310327Seric **	Side Effects:
51410327Seric **		munges p.
51510327Seric */
5164096Seric 
51710327Seric char **
51810327Seric makeargv(p)
51910327Seric 	register char *p;
52010327Seric {
52110327Seric 	char *q;
52210327Seric 	int i;
52310327Seric 	char **avp;
52410327Seric 	char *argv[MAXPV + 1];
52510327Seric 
52610327Seric 	/* take apart the words */
52710327Seric 	i = 0;
52810327Seric 	while (*p != '\0' && i < MAXPV)
5294096Seric 	{
53010327Seric 		q = p;
53110327Seric 		while (*p != '\0' && !isspace(*p))
53210327Seric 			p++;
53310327Seric 		while (isspace(*p))
53410327Seric 			*p++ = '\0';
53510327Seric 		argv[i++] = newstr(q);
5364096Seric 	}
53710327Seric 	argv[i++] = NULL;
5384096Seric 
53910327Seric 	/* now make a copy of the argv */
54010327Seric 	avp = (char **) xalloc(sizeof *avp * i);
54116893Seric 	bcopy((char *) argv, (char *) avp, sizeof *avp * i);
54210327Seric 
54310327Seric 	return (avp);
5443308Seric }
5453308Seric /*
5463308Seric **  PRINTRULES -- print rewrite rules (for debugging)
5473308Seric **
5483308Seric **	Parameters:
5493308Seric **		none.
5503308Seric **
5513308Seric **	Returns:
5523308Seric **		none.
5533308Seric **
5543308Seric **	Side Effects:
5553308Seric **		prints rewrite rules.
5563308Seric */
5573308Seric 
5584319Seric # ifdef DEBUG
5594319Seric 
5603308Seric printrules()
5613308Seric {
5623308Seric 	register struct rewrite *rwp;
5634072Seric 	register int ruleset;
5643308Seric 
5654072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
5663308Seric 	{
5674072Seric 		if (RewriteRules[ruleset] == NULL)
5684072Seric 			continue;
5698067Seric 		printf("\n----Rule Set %d:", ruleset);
5703308Seric 
5714072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
5723308Seric 		{
5738067Seric 			printf("\nLHS:");
5748067Seric 			printav(rwp->r_lhs);
5758067Seric 			printf("RHS:");
5768067Seric 			printav(rwp->r_rhs);
5773308Seric 		}
5783308Seric 	}
5793308Seric }
5804319Seric 
5814319Seric # endif DEBUG
5824096Seric /*
5838256Seric **  SETOPTION -- set global processing option
5848256Seric **
5858256Seric **	Parameters:
5868256Seric **		opt -- option name.
5878256Seric **		val -- option value (as a text string).
588*21755Seric **		safe -- set if this came from a configuration file.
589*21755Seric **			Some options (if set from the command line) will
590*21755Seric **			reset the user id to avoid security problems.
5918269Seric **		sticky -- if set, don't let other setoptions override
5928269Seric **			this value.
5938256Seric **
5948256Seric **	Returns:
5958256Seric **		none.
5968256Seric **
5978256Seric **	Side Effects:
5988256Seric **		Sets options as implied by the arguments.
5998256Seric */
6008256Seric 
60110687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
60210687Seric extern char	*WizWord;		/* the stored wizard password */
60316143Seric extern char	*NetName;		/* name of home (local) network */
6048269Seric 
605*21755Seric setoption(opt, val, safe, sticky)
6068256Seric 	char opt;
6078256Seric 	char *val;
608*21755Seric 	bool safe;
6098269Seric 	bool sticky;
6108256Seric {
6118265Seric 	extern bool atobool();
61212633Seric 	extern time_t convtime();
61314879Seric 	extern int QueueLA;
61414879Seric 	extern int RefuseLA;
61517474Seric 	extern bool trusteduser();
61617474Seric 	extern char *username();
6178256Seric 
6188256Seric # ifdef DEBUG
6198256Seric 	if (tTd(37, 1))
6209341Seric 		printf("setoption %c=%s", opt, val);
6218256Seric # endif DEBUG
6228256Seric 
6238256Seric 	/*
6248269Seric 	**  See if this option is preset for us.
6258256Seric 	*/
6268256Seric 
62710687Seric 	if (bitnset(opt, StickyOpt))
6288269Seric 	{
6298269Seric # ifdef DEBUG
6309341Seric 		if (tTd(37, 1))
6319341Seric 			printf(" (ignored)\n");
6328269Seric # endif DEBUG
6338269Seric 		return;
6348269Seric 	}
6358269Seric 
636*21755Seric 	/*
637*21755Seric 	**  Check to see if this option can be specified by this user.
638*21755Seric 	*/
639*21755Seric 
640*21755Seric 	if (!safe && getruid())
641*21755Seric 		safe = TRUE;
642*21755Seric 	if (!safe && index("deiLmorsv", opt) == NULL)
643*21755Seric 	{
644*21755Seric # ifdef DEBUG
645*21755Seric 		if (tTd(37, 1))
646*21755Seric 			printf(" (unsafe)");
647*21755Seric # endif DEBUG
648*21755Seric 		if (getruid() != geteuid())
649*21755Seric 		{
650*21755Seric 			printf("(Resetting uid)\n");
651*21755Seric 			setgid(getgid());
652*21755Seric 			setuid(getuid());
653*21755Seric 		}
654*21755Seric 	}
65517985Seric #ifdef DEBUG
656*21755Seric 	else if (tTd(37, 1))
65717985Seric 		printf("\n");
65817985Seric #endif DEBUG
6598269Seric 
6608256Seric 	switch (opt)
6618256Seric 	{
6628256Seric 	  case 'A':		/* set default alias file */
6639381Seric 		if (val[0] == '\0')
6648269Seric 			AliasFile = "aliases";
6659381Seric 		else
6669381Seric 			AliasFile = newstr(val);
6678256Seric 		break;
6688256Seric 
66917474Seric 	  case 'a':		/* look N minutes for "@:@" in alias file */
67017474Seric 		if (val[0] == '\0')
67117474Seric 			SafeAlias = 5;
67217474Seric 		else
67317474Seric 			SafeAlias = atoi(val);
67417474Seric 		break;
67517474Seric 
67616843Seric 	  case 'B':		/* substitution for blank character */
67716843Seric 		SpaceSub = val[0];
67816843Seric 		if (SpaceSub == '\0')
67916843Seric 			SpaceSub = ' ';
68016843Seric 		break;
68116843Seric 
6829284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
6839381Seric 		NoConnect = atobool(val);
6849284Seric 		break;
6859284Seric 
6869284Seric 	  case 'd':		/* delivery mode */
6879284Seric 		switch (*val)
6888269Seric 		{
6899284Seric 		  case '\0':
6909284Seric 			SendMode = SM_DELIVER;
6918269Seric 			break;
6928269Seric 
69310755Seric 		  case SM_QUEUE:	/* queue only */
69410755Seric #ifndef QUEUE
69510755Seric 			syserr("need QUEUE to set -odqueue");
69610755Seric #endif QUEUE
69710755Seric 			/* fall through..... */
69810755Seric 
6999284Seric 		  case SM_DELIVER:	/* do everything */
7009284Seric 		  case SM_FORK:		/* fork after verification */
7019284Seric 			SendMode = *val;
7028269Seric 			break;
7038269Seric 
7048269Seric 		  default:
7059284Seric 			syserr("Unknown delivery mode %c", *val);
7068269Seric 			exit(EX_USAGE);
7078269Seric 		}
7088269Seric 		break;
7098269Seric 
7109146Seric 	  case 'D':		/* rebuild alias database as needed */
7119381Seric 		AutoRebuild = atobool(val);
7129146Seric 		break;
7139146Seric 
7148269Seric 	  case 'e':		/* set error processing mode */
7158269Seric 		switch (*val)
7168269Seric 		{
7179381Seric 		  case EM_QUIET:	/* be silent about it */
7189381Seric 		  case EM_MAIL:		/* mail back */
7199381Seric 		  case EM_BERKNET:	/* do berknet error processing */
7209381Seric 		  case EM_WRITE:	/* write back (or mail) */
7218269Seric 			HoldErrs = TRUE;
7229381Seric 			/* fall through... */
7238269Seric 
7249381Seric 		  case EM_PRINT:	/* print errors normally (default) */
7259381Seric 			ErrorMode = *val;
7268269Seric 			break;
7278269Seric 		}
7288269Seric 		break;
7298269Seric 
7309049Seric 	  case 'F':		/* file mode */
73117975Seric 		FileMode = atooct(val) & 0777;
7329049Seric 		break;
7339049Seric 
7348269Seric 	  case 'f':		/* save Unix-style From lines on front */
7359381Seric 		SaveFrom = atobool(val);
7368269Seric 		break;
7378269Seric 
7388256Seric 	  case 'g':		/* default gid */
73917474Seric 		DefGid = atoi(val);
7408256Seric 		break;
7418256Seric 
7428256Seric 	  case 'H':		/* help file */
7439381Seric 		if (val[0] == '\0')
7448269Seric 			HelpFile = "sendmail.hf";
7459381Seric 		else
7469381Seric 			HelpFile = newstr(val);
7478256Seric 		break;
7488256Seric 
7498269Seric 	  case 'i':		/* ignore dot lines in message */
7509381Seric 		IgnrDot = atobool(val);
7518269Seric 		break;
7528269Seric 
7538256Seric 	  case 'L':		/* log level */
7549381Seric 		LogLevel = atoi(val);
7558256Seric 		break;
7568256Seric 
7578269Seric 	  case 'M':		/* define macro */
7589381Seric 		define(val[0], newstr(&val[1]), CurEnv);
75916878Seric 		sticky = FALSE;
7608269Seric 		break;
7618269Seric 
7628269Seric 	  case 'm':		/* send to me too */
7639381Seric 		MeToo = atobool(val);
7648269Seric 		break;
7658269Seric 
76616143Seric # ifdef DAEMON
76716143Seric 	  case 'N':		/* home (local?) network name */
76816143Seric 		NetName = newstr(val);
76916143Seric 		break;
77016143Seric # endif DAEMON
77116143Seric 
7728269Seric 	  case 'o':		/* assume old style headers */
7739381Seric 		if (atobool(val))
7749341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
7759341Seric 		else
7769341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
7778269Seric 		break;
7788269Seric 
7798256Seric 	  case 'Q':		/* queue directory */
7809381Seric 		if (val[0] == '\0')
7818269Seric 			QueueDir = "mqueue";
7829381Seric 		else
7839381Seric 			QueueDir = newstr(val);
7848256Seric 		break;
7858256Seric 
7868256Seric 	  case 'r':		/* read timeout */
7879381Seric 		ReadTimeout = convtime(val);
7888256Seric 		break;
7898256Seric 
7908256Seric 	  case 'S':		/* status file */
7919381Seric 		if (val[0] == '\0')
7928269Seric 			StatFile = "sendmail.st";
7939381Seric 		else
7949381Seric 			StatFile = newstr(val);
7958256Seric 		break;
7968256Seric 
7978265Seric 	  case 's':		/* be super safe, even if expensive */
7989381Seric 		SuperSafe = atobool(val);
7998256Seric 		break;
8008256Seric 
8018256Seric 	  case 'T':		/* queue timeout */
8029381Seric 		TimeOut = convtime(val);
8038256Seric 		break;
8048256Seric 
8058265Seric 	  case 't':		/* time zone name */
8068265Seric # ifdef V6
8079381Seric 		StdTimezone = newstr(val);
8089381Seric 		DstTimezone = index(StdTimeZone, ',');
8098265Seric 		if (DstTimezone == NULL)
8109381Seric 			syserr("bad time zone spec");
8119381Seric 		else
8129381Seric 			*DstTimezone++ = '\0';
8138265Seric # endif V6
8148265Seric 		break;
8158265Seric 
8168256Seric 	  case 'u':		/* set default uid */
81717474Seric 		DefUid = atoi(val);
8188256Seric 		break;
8198256Seric 
8208269Seric 	  case 'v':		/* run in verbose mode */
8219381Seric 		Verbose = atobool(val);
8228256Seric 		break;
8238256Seric 
8248544Seric # ifdef DEBUG
8258544Seric 	  case 'W':		/* set the wizards password */
82617474Seric 		WizWord = newstr(val);
8278544Seric 		break;
8288544Seric # endif DEBUG
8298544Seric 
83014879Seric 	  case 'x':		/* load avg at which to auto-queue msgs */
83114879Seric 		QueueLA = atoi(val);
83214879Seric 		break;
83314879Seric 
83414879Seric 	  case 'X':		/* load avg at which to auto-reject connections */
83514879Seric 		RefuseLA = atoi(val);
83614879Seric 		break;
83714879Seric 
8388256Seric 	  default:
8398256Seric 		break;
8408256Seric 	}
84116878Seric 	if (sticky)
84216878Seric 		setbitn(opt, StickyOpt);
8439188Seric 	return;
8448256Seric }
84510687Seric /*
84610687Seric **  SETCLASS -- set a word into a class
84710687Seric **
84810687Seric **	Parameters:
84910687Seric **		class -- the class to put the word in.
85010687Seric **		word -- the word to enter
85110687Seric **
85210687Seric **	Returns:
85310687Seric **		none.
85410687Seric **
85510687Seric **	Side Effects:
85610687Seric **		puts the word into the symbol table.
85710687Seric */
85810687Seric 
85910687Seric setclass(class, word)
86010687Seric 	int class;
86110687Seric 	char *word;
86210687Seric {
86310687Seric 	register STAB *s;
86410687Seric 
86510687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
86610687Seric 	setbitn(class, s->s_class);
86710687Seric }
868