xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 10701)
13313Seric # include "sendmail.h"
23308Seric 
3*10701Seric SCCSID(@(#)readcf.c	3.54		02/03/83);
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();
633308Seric 
643308Seric 	cf = fopen(cfname, "r");
653308Seric 	if (cf == NULL)
663308Seric 	{
673308Seric 		syserr("cannot open %s", cfname);
683308Seric 		exit(EX_OSFILE);
693308Seric 	}
703308Seric 
719381Seric 	FileName = cfname;
728056Seric 	LineNumber = 0;
737854Seric 	while (fgetfolded(buf, sizeof buf, cf) != NULL)
743308Seric 	{
753308Seric 		switch (buf[0])
763308Seric 		{
773308Seric 		  case '\0':
783308Seric 		  case '#':		/* comment */
793308Seric 			break;
803308Seric 
813308Seric 		  case 'R':		/* rewriting rule */
823308Seric 			for (p = &buf[1]; *p != '\0' && *p != '\t'; p++)
833308Seric 				continue;
843308Seric 
853308Seric 			if (*p == '\0')
865909Seric 			{
879381Seric 				syserr("invalid rewrite line \"%s\"", buf);
885909Seric 				break;
895909Seric 			}
905909Seric 
915909Seric 			/* allocate space for the rule header */
925909Seric 			if (rwp == NULL)
935909Seric 			{
945909Seric 				RewriteRules[ruleset] = rwp =
955909Seric 					(struct rewrite *) xalloc(sizeof *rwp);
965909Seric 			}
973308Seric 			else
983308Seric 			{
995909Seric 				rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
1005909Seric 				rwp = rwp->r_next;
1015909Seric 			}
1025909Seric 			rwp->r_next = NULL;
1033308Seric 
1045909Seric 			/* expand and save the LHS */
1055909Seric 			*p = '\0';
1066991Seric 			expand(&buf[1], exbuf, &exbuf[sizeof exbuf], CurEnv);
1075909Seric 			rwp->r_lhs = prescan(exbuf, '\t');
1085909Seric 			if (rwp->r_lhs != NULL)
1095909Seric 				rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
1105909Seric 
1115909Seric 			/* expand and save the RHS */
1125909Seric 			while (*++p == '\t')
1135909Seric 				continue;
1147231Seric 			q = p;
1157231Seric 			while (*p != '\0' && *p != '\t')
1167231Seric 				p++;
1177231Seric 			*p = '\0';
1187231Seric 			expand(q, exbuf, &exbuf[sizeof exbuf], CurEnv);
1195909Seric 			rwp->r_rhs = prescan(exbuf, '\t');
1205909Seric 			if (rwp->r_rhs != NULL)
1215909Seric 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
1223308Seric 			break;
1233308Seric 
1244072Seric 		  case 'S':		/* select rewriting set */
1254072Seric 			ruleset = atoi(&buf[1]);
1268056Seric 			if (ruleset >= MAXRWSETS || ruleset < 0)
1278056Seric 			{
1289381Seric 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
1298056Seric 				ruleset = 0;
1308056Seric 			}
1314072Seric 			rwp = NULL;
1324072Seric 			break;
1334072Seric 
1343308Seric 		  case 'D':		/* macro definition */
1359381Seric 			define(buf[1], newstr(&buf[2]), CurEnv);
1363308Seric 			break;
1373308Seric 
1383387Seric 		  case 'H':		/* required header line */
1394088Seric 			(void) chompheader(&buf[1], TRUE);
1403387Seric 			break;
1413387Seric 
1424061Seric 		  case 'C':		/* word class */
1434432Seric 		  case 'F':		/* word class from file */
1444432Seric 			/* read list of words from argument or file */
1454432Seric 			if (buf[0] == 'F')
1464432Seric 			{
1474432Seric 				/* read from file */
1484432Seric 				for (p = &buf[2]; *p != '\0' && !isspace(*p); p++)
1494432Seric 					continue;
1504432Seric 				if (*p == '\0')
1514432Seric 					p = "%s";
1524432Seric 				else
1534432Seric 				{
1544432Seric 					*p = '\0';
1554432Seric 					while (isspace(*++p))
1564432Seric 						continue;
1574432Seric 				}
15810687Seric 				fileclass(buf[1], &buf[2], p);
1594432Seric 				break;
1604432Seric 			}
1614061Seric 
1624432Seric 			/* scan the list of words and set class for all */
1634061Seric 			for (p = &buf[2]; *p != '\0'; )
1644061Seric 			{
1654061Seric 				register char *wd;
1664061Seric 				char delim;
1674061Seric 				register STAB *s;
1684061Seric 
1694061Seric 				while (*p != '\0' && isspace(*p))
1704061Seric 					p++;
1714061Seric 				wd = p;
1724061Seric 				while (*p != '\0' && !isspace(*p))
1734061Seric 					p++;
1744061Seric 				delim = *p;
1754061Seric 				*p = '\0';
1764061Seric 				if (wd[0] != '\0')
17710687Seric 					setclass(buf[1], wd);
1784061Seric 				*p = delim;
1794061Seric 			}
1804061Seric 			break;
1814061Seric 
1824096Seric 		  case 'M':		/* define mailer */
1834217Seric 			makemailer(&buf[1], safe);
1844096Seric 			break;
1854096Seric 
1868252Seric 		  case 'O':		/* set option */
1878269Seric 			setoption(buf[1], &buf[2], safe, FALSE);
1888252Seric 			break;
1898252Seric 
1908252Seric 		  case 'P':		/* set precedence */
1918252Seric 			if (NumPriorities >= MAXPRIORITIES)
1928252Seric 			{
1938547Seric 				toomany('P', MAXPRIORITIES);
1948252Seric 				break;
1958252Seric 			}
1969381Seric 			for (p = &buf[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
1978252Seric 				continue;
1988252Seric 			if (*p == '\0')
1998252Seric 				goto badline;
2008252Seric 			*p = '\0';
2018252Seric 			Priorities[NumPriorities].pri_name = newstr(&buf[1]);
2028252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
2038252Seric 			NumPriorities++;
2048252Seric 			break;
2058252Seric 
2068547Seric 		  case 'T':		/* trusted user(s) */
2078547Seric 			p = &buf[1];
2088547Seric 			while (*p != '\0')
2098547Seric 			{
2108547Seric 				while (isspace(*p))
2118547Seric 					p++;
2128547Seric 				q = p;
2138547Seric 				while (*p != '\0' && !isspace(*p))
2148547Seric 					p++;
2158547Seric 				if (*p != '\0')
2168547Seric 					*p++ = '\0';
2178547Seric 				if (*q == '\0')
2188547Seric 					continue;
2198547Seric 				for (pv = TrustedUsers; *pv != NULL; pv++)
2208547Seric 					continue;
2218547Seric 				if (pv >= &TrustedUsers[MAXTRUST])
2228547Seric 				{
2238547Seric 					toomany('T', MAXTRUST);
2248547Seric 					break;
2258547Seric 				}
2268547Seric 				*pv = newstr(q);
2278547Seric 			}
2288547Seric 			break;
2298547Seric 
2303308Seric 		  default:
2314061Seric 		  badline:
2329381Seric 			syserr("unknown control line \"%s\"", buf);
2333308Seric 		}
2343308Seric 	}
2359381Seric 	FileName = NULL;
2364096Seric }
2374096Seric /*
2388547Seric **  TOOMANY -- signal too many of some option
2398547Seric **
2408547Seric **	Parameters:
2418547Seric **		id -- the id of the error line
2428547Seric **		maxcnt -- the maximum possible values
2438547Seric **
2448547Seric **	Returns:
2458547Seric **		none.
2468547Seric **
2478547Seric **	Side Effects:
2488547Seric **		gives a syserr.
2498547Seric */
2508547Seric 
2518547Seric toomany(id, maxcnt)
2528547Seric 	char id;
2538547Seric 	int maxcnt;
2548547Seric {
2559381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
2568547Seric }
2578547Seric /*
2584432Seric **  FILECLASS -- read members of a class from a file
2594432Seric **
2604432Seric **	Parameters:
2614432Seric **		class -- class to define.
2624432Seric **		filename -- name of file to read.
2634432Seric **		fmt -- scanf string to use for match.
2644432Seric **
2654432Seric **	Returns:
2664432Seric **		none
2674432Seric **
2684432Seric **	Side Effects:
2694432Seric **
2704432Seric **		puts all lines in filename that match a scanf into
2714432Seric **			the named class.
2724432Seric */
2734432Seric 
2744432Seric fileclass(class, filename, fmt)
2754432Seric 	int class;
2764432Seric 	char *filename;
2774432Seric 	char *fmt;
2784432Seric {
2794432Seric 	register FILE *f;
2804432Seric 	char buf[MAXLINE];
2814432Seric 
2824432Seric 	f = fopen(filename, "r");
2834432Seric 	if (f == NULL)
2844432Seric 	{
2854432Seric 		syserr("cannot open %s", filename);
2864432Seric 		return;
2874432Seric 	}
2884432Seric 
2894432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
2904432Seric 	{
2914432Seric 		register STAB *s;
2924432Seric 		char wordbuf[MAXNAME+1];
2934432Seric 
2944432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
2954432Seric 			continue;
2964432Seric 		s = stab(wordbuf, ST_CLASS, ST_ENTER);
29710687Seric 		setbitn(class, s->s_class);
2984432Seric 	}
2994432Seric 
3004627Seric 	(void) fclose(f);
3014432Seric }
3024432Seric /*
3034096Seric **  MAKEMAILER -- define a new mailer.
3044096Seric **
3054096Seric **	Parameters:
30610327Seric **		line -- description of mailer.  This is in labeled
30710327Seric **			fields.  The fields are:
30810327Seric **			   P -- the path to the mailer
30910327Seric **			   F -- the flags associated with the mailer
31010327Seric **			   A -- the argv for this mailer
31110327Seric **			   S -- the sender rewriting set
31210327Seric **			   R -- the recipient rewriting set
31310327Seric **			   E -- the eol string
31410327Seric **			The first word is the canonical name of the mailer.
3154217Seric **		safe -- set if this is a safe configuration file.
3164096Seric **
3174096Seric **	Returns:
3184096Seric **		none.
3194096Seric **
3204096Seric **	Side Effects:
3214096Seric **		enters the mailer into the mailer table.
3224096Seric */
3233308Seric 
3244217Seric makemailer(line, safe)
3254096Seric 	char *line;
3264217Seric 	bool safe;
3274096Seric {
3284096Seric 	register char *p;
3298067Seric 	register struct mailer *m;
3308067Seric 	register STAB *s;
3318067Seric 	int i;
33210327Seric 	char fcode;
3334096Seric 	extern int NextMailer;
33410327Seric 	extern char **makeargv();
33510327Seric 	extern char *munchstring();
33610327Seric 	extern char *DelimChar;
337*10701Seric 	extern long atol();
3384096Seric 
33910327Seric 	/* allocate a mailer and set up defaults */
34010327Seric 	m = (struct mailer *) xalloc(sizeof *m);
34110327Seric 	bzero((char *) m, sizeof *m);
34210327Seric 	m->m_mno = NextMailer;
34310327Seric 	m->m_eol = "\n";
34410327Seric 
34510327Seric 	/* collect the mailer name */
34610327Seric 	for (p = line; *p != '\0' && *p != ',' && !isspace(*p); p++)
34710327Seric 		continue;
34810327Seric 	if (*p != '\0')
34910327Seric 		*p++ = '\0';
35010327Seric 	m->m_name = newstr(line);
35110327Seric 
35210327Seric 	/* now scan through and assign info from the fields */
35310327Seric 	while (*p != '\0')
35410327Seric 	{
35510327Seric 		while (*p != '\0' && (*p == ',' || isspace(*p)))
35610327Seric 			p++;
35710327Seric 
35810327Seric 		/* p now points to field code */
35910327Seric 		fcode = *p;
36010327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
36110327Seric 			p++;
36210327Seric 		if (*p++ != '=')
36310327Seric 		{
36410327Seric 			syserr("`=' expected");
36510327Seric 			return;
36610327Seric 		}
36710327Seric 		while (isspace(*p))
36810327Seric 			p++;
36910327Seric 
37010327Seric 		/* p now points to the field body */
37110327Seric 		p = munchstring(p);
37210327Seric 
37310327Seric 		/* install the field into the mailer struct */
37410327Seric 		switch (fcode)
37510327Seric 		{
37610327Seric 		  case 'P':		/* pathname */
37710327Seric 			m->m_mailer = newstr(p);
37810327Seric 			break;
37910327Seric 
38010327Seric 		  case 'F':		/* flags */
38110687Seric 			for (; *p != '\0'; p++)
38210687Seric 				setbitn(*p, m->m_flags);
38310327Seric 			if (!safe)
38410687Seric 				clrbitn(M_RESTR, m->m_flags);
38510327Seric 			break;
38610327Seric 
38710327Seric 		  case 'S':		/* sender rewriting ruleset */
38810327Seric 		  case 'R':		/* recipient rewriting ruleset */
38910327Seric 			i = atoi(p);
39010327Seric 			if (i < 0 || i >= MAXRWSETS)
39110327Seric 			{
39210327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
39310327Seric 				return;
39410327Seric 			}
39510327Seric 			if (fcode == 'S')
39610327Seric 				m->m_s_rwset = i;
39710327Seric 			else
39810327Seric 				m->m_r_rwset = i;
39910327Seric 			break;
40010327Seric 
40110327Seric 		  case 'E':		/* end of line string */
40210327Seric 			m->m_eol = newstr(p);
40310327Seric 			break;
40410327Seric 
40510327Seric 		  case 'A':		/* argument vector */
40610327Seric 			m->m_argv = makeargv(p);
40710327Seric 			break;
408*10701Seric 
409*10701Seric 		  case 'M':		/* maximum message size */
410*10701Seric 			m->m_maxsize = atol(p);
411*10701Seric 			break;
41210327Seric 		}
41310327Seric 
41410327Seric 		p = DelimChar;
41510327Seric 	}
41610327Seric 
41710327Seric 	/* now store the mailer away */
4184096Seric 	if (NextMailer >= MAXMAILERS)
4194096Seric 	{
4209381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
4214096Seric 		return;
4224096Seric 	}
42310327Seric 	Mailer[NextMailer++] = m;
42410327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
42510327Seric 	s->s_mailer = m;
42610327Seric }
42710327Seric /*
42810327Seric **  MUNCHSTRING -- translate a string into internal form.
42910327Seric **
43010327Seric **	Parameters:
43110327Seric **		p -- the string to munch.
43210327Seric **
43310327Seric **	Returns:
43410327Seric **		the munched string.
43510327Seric **
43610327Seric **	Side Effects:
43710327Seric **		Sets "DelimChar" to point to the string that caused us
43810327Seric **		to stop.
43910327Seric */
4404096Seric 
44110327Seric char *
44210327Seric munchstring(p)
44310327Seric 	register char *p;
44410327Seric {
44510327Seric 	register char *q;
44610327Seric 	bool backslash = FALSE;
44710327Seric 	bool quotemode = FALSE;
44810327Seric 	static char buf[MAXLINE];
44910327Seric 	extern char *DelimChar;
4504096Seric 
45110327Seric 	for (q = buf; *p != '\0'; p++)
4524096Seric 	{
45310327Seric 		if (backslash)
45410327Seric 		{
45510327Seric 			/* everything is roughly literal */
45610357Seric 			backslash = FALSE;
45710327Seric 			switch (*p)
45810327Seric 			{
45910327Seric 			  case 'r':		/* carriage return */
46010327Seric 				*q++ = '\r';
46110327Seric 				continue;
46210327Seric 
46310327Seric 			  case 'n':		/* newline */
46410327Seric 				*q++ = '\n';
46510327Seric 				continue;
46610327Seric 
46710327Seric 			  case 'f':		/* form feed */
46810327Seric 				*q++ = '\f';
46910327Seric 				continue;
47010327Seric 
47110327Seric 			  case 'b':		/* backspace */
47210327Seric 				*q++ = '\b';
47310327Seric 				continue;
47410327Seric 			}
47510327Seric 			*q++ = *p;
47610327Seric 		}
47710327Seric 		else
47810327Seric 		{
47910327Seric 			if (*p == '\\')
48010327Seric 				backslash = TRUE;
48110327Seric 			else if (*p == '"')
48210327Seric 				quotemode = !quotemode;
48310327Seric 			else if (quotemode || *p != ',')
48410327Seric 				*q++ = *p;
48510327Seric 			else
48610327Seric 				break;
48710327Seric 		}
4884096Seric 	}
4894096Seric 
49010327Seric 	DelimChar = p;
49110327Seric 	*q++ = '\0';
49210327Seric 	return (buf);
49310327Seric }
49410327Seric /*
49510327Seric **  MAKEARGV -- break up a string into words
49610327Seric **
49710327Seric **	Parameters:
49810327Seric **		p -- the string to break up.
49910327Seric **
50010327Seric **	Returns:
50110327Seric **		a char **argv (dynamically allocated)
50210327Seric **
50310327Seric **	Side Effects:
50410327Seric **		munges p.
50510327Seric */
5064096Seric 
50710327Seric char **
50810327Seric makeargv(p)
50910327Seric 	register char *p;
51010327Seric {
51110327Seric 	char *q;
51210327Seric 	int i;
51310327Seric 	char **avp;
51410327Seric 	char *argv[MAXPV + 1];
51510327Seric 
51610327Seric 	/* take apart the words */
51710327Seric 	i = 0;
51810327Seric 	while (*p != '\0' && i < MAXPV)
5194096Seric 	{
52010327Seric 		q = p;
52110327Seric 		while (*p != '\0' && !isspace(*p))
52210327Seric 			p++;
52310327Seric 		while (isspace(*p))
52410327Seric 			*p++ = '\0';
52510327Seric 		argv[i++] = newstr(q);
5264096Seric 	}
52710327Seric 	argv[i++] = NULL;
5284096Seric 
52910327Seric 	/* now make a copy of the argv */
53010327Seric 	avp = (char **) xalloc(sizeof *avp * i);
53110327Seric 	bmove((char *) argv, (char *) avp, sizeof *avp * i);
53210327Seric 
53310327Seric 	return (avp);
5343308Seric }
5353308Seric /*
5363308Seric **  PRINTRULES -- print rewrite rules (for debugging)
5373308Seric **
5383308Seric **	Parameters:
5393308Seric **		none.
5403308Seric **
5413308Seric **	Returns:
5423308Seric **		none.
5433308Seric **
5443308Seric **	Side Effects:
5453308Seric **		prints rewrite rules.
5463308Seric */
5473308Seric 
5484319Seric # ifdef DEBUG
5494319Seric 
5503308Seric printrules()
5513308Seric {
5523308Seric 	register struct rewrite *rwp;
5534072Seric 	register int ruleset;
5543308Seric 
5554072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
5563308Seric 	{
5574072Seric 		if (RewriteRules[ruleset] == NULL)
5584072Seric 			continue;
5598067Seric 		printf("\n----Rule Set %d:", ruleset);
5603308Seric 
5614072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
5623308Seric 		{
5638067Seric 			printf("\nLHS:");
5648067Seric 			printav(rwp->r_lhs);
5658067Seric 			printf("RHS:");
5668067Seric 			printav(rwp->r_rhs);
5673308Seric 		}
5683308Seric 	}
5693308Seric }
5704319Seric 
5714319Seric # endif DEBUG
5724096Seric /*
5738256Seric **  SETOPTION -- set global processing option
5748256Seric **
5758256Seric **	Parameters:
5768256Seric **		opt -- option name.
5778256Seric **		val -- option value (as a text string).
5788269Seric **		safe -- if set, this came from a system configuration file.
5798269Seric **		sticky -- if set, don't let other setoptions override
5808269Seric **			this value.
5818256Seric **
5828256Seric **	Returns:
5838256Seric **		none.
5848256Seric **
5858256Seric **	Side Effects:
5868256Seric **		Sets options as implied by the arguments.
5878256Seric */
5888256Seric 
58910687Seric static BITMAP	StickyOpt;		/* set if option is stuck */
59010687Seric extern char	*WizWord;		/* the stored wizard password */
59110343Seric #ifdef DAEMON
59210687Seric extern int	MaxConnections;		/* max simult. SMTP conns */
59310343Seric #endif DAEMON
5948269Seric 
5958269Seric setoption(opt, val, safe, sticky)
5968256Seric 	char opt;
5978256Seric 	char *val;
5988269Seric 	bool safe;
5998269Seric 	bool sticky;
6008256Seric {
6018265Seric 	extern bool atobool();
6028256Seric 
6038256Seric # ifdef DEBUG
6048256Seric 	if (tTd(37, 1))
6059341Seric 		printf("setoption %c=%s", opt, val);
6068256Seric # endif DEBUG
6078256Seric 
6088256Seric 	/*
6098269Seric 	**  See if this option is preset for us.
6108256Seric 	*/
6118256Seric 
61210687Seric 	if (bitnset(opt, StickyOpt))
6138269Seric 	{
6148269Seric # ifdef DEBUG
6159341Seric 		if (tTd(37, 1))
6169341Seric 			printf(" (ignored)\n");
6178269Seric # endif DEBUG
6188269Seric 		return;
6198269Seric 	}
6209341Seric #ifdef DEBUG
6219341Seric 	else if (tTd(37, 1))
6229341Seric 		printf("\n");
6239341Seric #endif DEBUG
6248269Seric 	if (sticky)
62510687Seric 		setbitn(opt, StickyOpt);
6268269Seric 
6278269Seric 	if (getruid() == 0)
6288269Seric 		safe = TRUE;
6298269Seric 
6308256Seric 	switch (opt)
6318256Seric 	{
6328256Seric 	  case 'A':		/* set default alias file */
6339381Seric 		if (val[0] == '\0')
6348269Seric 			AliasFile = "aliases";
6359381Seric 		else
6369381Seric 			AliasFile = newstr(val);
6378256Seric 		break;
6388256Seric 
6398931Seric 	  case 'a':		/* look for "@:@" in alias file */
6409381Seric 		SafeAlias = atobool(val);
6418931Seric 		break;
6428931Seric 
6439284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
6449381Seric 		NoConnect = atobool(val);
6459284Seric 		break;
6469284Seric 
6479284Seric 	  case 'd':		/* delivery mode */
6489284Seric 		switch (*val)
6498269Seric 		{
6509284Seric 		  case '\0':
6519284Seric 			SendMode = SM_DELIVER;
6528269Seric 			break;
6538269Seric 
6549284Seric 		  case SM_DELIVER:	/* do everything */
6559284Seric 		  case SM_FORK:		/* fork after verification */
6569284Seric 		  case SM_QUEUE:	/* queue only */
6579284Seric 			SendMode = *val;
6588269Seric 			break;
6598269Seric 
6608269Seric 		  default:
6619284Seric 			syserr("Unknown delivery mode %c", *val);
6628269Seric 			exit(EX_USAGE);
6638269Seric 		}
6648269Seric 		break;
6658269Seric 
6669146Seric 	  case 'D':		/* rebuild alias database as needed */
6679381Seric 		AutoRebuild = atobool(val);
6689146Seric 		break;
6699146Seric 
6708269Seric 	  case 'e':		/* set error processing mode */
6718269Seric 		switch (*val)
6728269Seric 		{
6739381Seric 		  case EM_QUIET:	/* be silent about it */
6748269Seric 			(void) freopen("/dev/null", "w", stdout);
6759381Seric 			/* fall through... */
6768269Seric 
6779381Seric 		  case EM_MAIL:		/* mail back */
6789381Seric 		  case EM_BERKNET:	/* do berknet error processing */
6799381Seric 		  case EM_WRITE:	/* write back (or mail) */
6808269Seric 			HoldErrs = TRUE;
6819381Seric 			/* fall through... */
6828269Seric 
6839381Seric 		  case EM_PRINT:	/* print errors normally (default) */
6849381Seric 			ErrorMode = *val;
6858269Seric 			break;
6868269Seric 		}
6878269Seric 		break;
6888269Seric 
6899049Seric 	  case 'F':		/* file mode */
6909381Seric 		FileMode = atooct(val);
6919049Seric 		break;
6929049Seric 
6938269Seric 	  case 'f':		/* save Unix-style From lines on front */
6949381Seric 		SaveFrom = atobool(val);
6958269Seric 		break;
6968269Seric 
6978256Seric 	  case 'g':		/* default gid */
6989105Seric 		if (safe)
6999381Seric 			DefGid = atoi(val);
7008256Seric 		break;
7018256Seric 
7028256Seric 	  case 'H':		/* help file */
7039381Seric 		if (val[0] == '\0')
7048269Seric 			HelpFile = "sendmail.hf";
7059381Seric 		else
7069381Seric 			HelpFile = newstr(val);
7078256Seric 		break;
7088256Seric 
7098269Seric 	  case 'i':		/* ignore dot lines in message */
7109381Seric 		IgnrDot = atobool(val);
7118269Seric 		break;
7128269Seric 
7138256Seric 	  case 'L':		/* log level */
7149381Seric 		LogLevel = atoi(val);
7158256Seric 		break;
7168256Seric 
7178269Seric 	  case 'M':		/* define macro */
7189381Seric 		define(val[0], newstr(&val[1]), CurEnv);
7198269Seric 		break;
7208269Seric 
7218269Seric 	  case 'm':		/* send to me too */
7229381Seric 		MeToo = atobool(val);
7238269Seric 		break;
7248269Seric 
72510343Seric #ifdef DAEMON
72610343Seric 	  case 'N':		/* maximum simultaneous SMTP connections */
72710343Seric 		MaxConnections = atoi(val);
72810343Seric 		break;
72910343Seric #endif DAEMON
73010343Seric 
7318269Seric 	  case 'o':		/* assume old style headers */
7329381Seric 		if (atobool(val))
7339341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
7349341Seric 		else
7359341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
7368269Seric 		break;
7378269Seric 
7388256Seric 	  case 'Q':		/* queue directory */
7399381Seric 		if (val[0] == '\0')
7408269Seric 			QueueDir = "mqueue";
7419381Seric 		else
7429381Seric 			QueueDir = newstr(val);
7438256Seric 		break;
7448256Seric 
7458256Seric 	  case 'r':		/* read timeout */
7469381Seric 		ReadTimeout = convtime(val);
7478256Seric 		break;
7488256Seric 
7498256Seric 	  case 'S':		/* status file */
7509381Seric 		if (val[0] == '\0')
7518269Seric 			StatFile = "sendmail.st";
7529381Seric 		else
7539381Seric 			StatFile = newstr(val);
7548256Seric 		break;
7558256Seric 
7568265Seric 	  case 's':		/* be super safe, even if expensive */
7579381Seric 		SuperSafe = atobool(val);
7588256Seric 		break;
7598256Seric 
7608256Seric 	  case 'T':		/* queue timeout */
7619381Seric 		TimeOut = convtime(val);
7628256Seric 		break;
7638256Seric 
7648265Seric 	  case 't':		/* time zone name */
7658265Seric # ifdef V6
7669381Seric 		StdTimezone = newstr(val);
7679381Seric 		DstTimezone = index(StdTimeZone, ',');
7688265Seric 		if (DstTimezone == NULL)
7699381Seric 			syserr("bad time zone spec");
7709381Seric 		else
7719381Seric 			*DstTimezone++ = '\0';
7728265Seric # endif V6
7738265Seric 		break;
7748265Seric 
7758256Seric 	  case 'u':		/* set default uid */
7769105Seric 		if (safe)
7779381Seric 			DefUid = atoi(val);
7788256Seric 		break;
7798256Seric 
7808269Seric 	  case 'v':		/* run in verbose mode */
7819381Seric 		Verbose = atobool(val);
7828256Seric 		break;
7838256Seric 
7848544Seric # ifdef DEBUG
7858544Seric 	  case 'W':		/* set the wizards password */
7869105Seric 		if (safe)
7879381Seric 			WizWord = newstr(val);
7888544Seric 		break;
7898544Seric # endif DEBUG
7908544Seric 
7918256Seric 	  default:
7928256Seric 		break;
7938256Seric 	}
7949188Seric 	return;
7958256Seric }
79610687Seric /*
79710687Seric **  SETCLASS -- set a word into a class
79810687Seric **
79910687Seric **	Parameters:
80010687Seric **		class -- the class to put the word in.
80110687Seric **		word -- the word to enter
80210687Seric **
80310687Seric **	Returns:
80410687Seric **		none.
80510687Seric **
80610687Seric **	Side Effects:
80710687Seric **		puts the word into the symbol table.
80810687Seric */
80910687Seric 
81010687Seric setclass(class, word)
81110687Seric 	int class;
81210687Seric 	char *word;
81310687Seric {
81410687Seric 	register STAB *s;
81510687Seric 
81610687Seric 	s = stab(word, ST_CLASS, ST_ENTER);
81710687Seric 	setbitn(class, s->s_class);
81810687Seric }
819