xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 10174)
13313Seric # include "sendmail.h"
23308Seric 
3*10174Seric SCCSID(@(#)readcf.c	3.49		01/06/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 class;
548547Seric 	int ruleset = 0;
558547Seric 	char *q;
568547Seric 	char **pv;
579350Seric 	struct rewrite *rwp = NULL;
583308Seric 	char buf[MAXLINE];
593308Seric 	register char *p;
603308Seric 	extern char **prescan();
613308Seric 	extern char **copyplist();
625909Seric 	char exbuf[MAXLINE];
639350Seric 	extern char *fgetfolded();
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 	{
763308Seric 		switch (buf[0])
773308Seric 		{
783308Seric 		  case '\0':
793308Seric 		  case '#':		/* comment */
803308Seric 			break;
813308Seric 
823308Seric 		  case 'R':		/* rewriting rule */
833308Seric 			for (p = &buf[1]; *p != '\0' && *p != '\t'; p++)
843308Seric 				continue;
853308Seric 
863308Seric 			if (*p == '\0')
875909Seric 			{
889381Seric 				syserr("invalid rewrite line \"%s\"", buf);
895909Seric 				break;
905909Seric 			}
915909Seric 
925909Seric 			/* allocate space for the rule header */
935909Seric 			if (rwp == NULL)
945909Seric 			{
955909Seric 				RewriteRules[ruleset] = rwp =
965909Seric 					(struct rewrite *) xalloc(sizeof *rwp);
975909Seric 			}
983308Seric 			else
993308Seric 			{
1005909Seric 				rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
1015909Seric 				rwp = rwp->r_next;
1025909Seric 			}
1035909Seric 			rwp->r_next = NULL;
1043308Seric 
1055909Seric 			/* expand and save the LHS */
1065909Seric 			*p = '\0';
1076991Seric 			expand(&buf[1], exbuf, &exbuf[sizeof exbuf], CurEnv);
1085909Seric 			rwp->r_lhs = prescan(exbuf, '\t');
1095909Seric 			if (rwp->r_lhs != NULL)
1105909Seric 				rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
1115909Seric 
1125909Seric 			/* expand and save the RHS */
1135909Seric 			while (*++p == '\t')
1145909Seric 				continue;
1157231Seric 			q = p;
1167231Seric 			while (*p != '\0' && *p != '\t')
1177231Seric 				p++;
1187231Seric 			*p = '\0';
1197231Seric 			expand(q, exbuf, &exbuf[sizeof exbuf], CurEnv);
1205909Seric 			rwp->r_rhs = prescan(exbuf, '\t');
1215909Seric 			if (rwp->r_rhs != NULL)
1225909Seric 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
1233308Seric 			break;
1243308Seric 
1254072Seric 		  case 'S':		/* select rewriting set */
1264072Seric 			ruleset = atoi(&buf[1]);
1278056Seric 			if (ruleset >= MAXRWSETS || ruleset < 0)
1288056Seric 			{
1299381Seric 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
1308056Seric 				ruleset = 0;
1318056Seric 			}
1324072Seric 			rwp = NULL;
1334072Seric 			break;
1344072Seric 
1353308Seric 		  case 'D':		/* macro definition */
1369381Seric 			define(buf[1], newstr(&buf[2]), CurEnv);
1373308Seric 			break;
1383308Seric 
1393387Seric 		  case 'H':		/* required header line */
1404088Seric 			(void) chompheader(&buf[1], TRUE);
1413387Seric 			break;
1423387Seric 
1434061Seric 		  case 'C':		/* word class */
1444432Seric 		  case 'F':		/* word class from file */
1454061Seric 			class = buf[1];
1464061Seric 			if (!isalpha(class))
1479381Seric 			{
1489381Seric 				syserr("illegal class name %c", class);
1499381Seric 				break;
1509381Seric 			}
1514061Seric 			if (isupper(class))
1524061Seric 				class -= 'A';
1534061Seric 			else
1544061Seric 				class -= 'a';
1554432Seric 
1564432Seric 			/* read list of words from argument or file */
1574432Seric 			if (buf[0] == 'F')
1584432Seric 			{
1594432Seric 				/* read from file */
1604432Seric 				for (p = &buf[2]; *p != '\0' && !isspace(*p); p++)
1614432Seric 					continue;
1624432Seric 				if (*p == '\0')
1634432Seric 					p = "%s";
1644432Seric 				else
1654432Seric 				{
1664432Seric 					*p = '\0';
1674432Seric 					while (isspace(*++p))
1684432Seric 						continue;
1694432Seric 				}
1704432Seric 				fileclass(class, &buf[2], p);
1714432Seric 				break;
1724432Seric 			}
1734061Seric 
1744432Seric 			/* scan the list of words and set class for all */
1754061Seric 			for (p = &buf[2]; *p != '\0'; )
1764061Seric 			{
1774061Seric 				register char *wd;
1784061Seric 				char delim;
1794061Seric 				register STAB *s;
1804061Seric 
1814061Seric 				while (*p != '\0' && isspace(*p))
1824061Seric 					p++;
1834061Seric 				wd = p;
1844061Seric 				while (*p != '\0' && !isspace(*p))
1854061Seric 					p++;
1864061Seric 				delim = *p;
1874061Seric 				*p = '\0';
1884061Seric 				if (wd[0] != '\0')
1894061Seric 				{
1904103Seric 					s = stab(wd, ST_CLASS, ST_ENTER);
1916275Seric 					s->s_class |= 1L << class;
1924061Seric 				}
1934061Seric 				*p = delim;
1944061Seric 			}
1954061Seric 			break;
1964061Seric 
1974096Seric 		  case 'M':		/* define mailer */
1984217Seric 			makemailer(&buf[1], safe);
1994096Seric 			break;
2004096Seric 
2018252Seric 		  case 'O':		/* set option */
2028269Seric 			setoption(buf[1], &buf[2], safe, FALSE);
2038252Seric 			break;
2048252Seric 
2058252Seric 		  case 'P':		/* set precedence */
2068252Seric 			if (NumPriorities >= MAXPRIORITIES)
2078252Seric 			{
2088547Seric 				toomany('P', MAXPRIORITIES);
2098252Seric 				break;
2108252Seric 			}
2119381Seric 			for (p = &buf[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
2128252Seric 				continue;
2138252Seric 			if (*p == '\0')
2148252Seric 				goto badline;
2158252Seric 			*p = '\0';
2168252Seric 			Priorities[NumPriorities].pri_name = newstr(&buf[1]);
2178252Seric 			Priorities[NumPriorities].pri_val = atoi(++p);
2188252Seric 			NumPriorities++;
2198252Seric 			break;
2208252Seric 
2218547Seric 		  case 'T':		/* trusted user(s) */
2228547Seric 			p = &buf[1];
2238547Seric 			while (*p != '\0')
2248547Seric 			{
2258547Seric 				while (isspace(*p))
2268547Seric 					p++;
2278547Seric 				q = p;
2288547Seric 				while (*p != '\0' && !isspace(*p))
2298547Seric 					p++;
2308547Seric 				if (*p != '\0')
2318547Seric 					*p++ = '\0';
2328547Seric 				if (*q == '\0')
2338547Seric 					continue;
2348547Seric 				for (pv = TrustedUsers; *pv != NULL; pv++)
2358547Seric 					continue;
2368547Seric 				if (pv >= &TrustedUsers[MAXTRUST])
2378547Seric 				{
2388547Seric 					toomany('T', MAXTRUST);
2398547Seric 					break;
2408547Seric 				}
2418547Seric 				*pv = newstr(q);
2428547Seric 			}
2438547Seric 			break;
2448547Seric 
2453308Seric 		  default:
2464061Seric 		  badline:
2479381Seric 			syserr("unknown control line \"%s\"", buf);
2483308Seric 		}
2493308Seric 	}
2509381Seric 	FileName = NULL;
2514096Seric }
2524096Seric /*
2538547Seric **  TOOMANY -- signal too many of some option
2548547Seric **
2558547Seric **	Parameters:
2568547Seric **		id -- the id of the error line
2578547Seric **		maxcnt -- the maximum possible values
2588547Seric **
2598547Seric **	Returns:
2608547Seric **		none.
2618547Seric **
2628547Seric **	Side Effects:
2638547Seric **		gives a syserr.
2648547Seric */
2658547Seric 
2668547Seric toomany(id, maxcnt)
2678547Seric 	char id;
2688547Seric 	int maxcnt;
2698547Seric {
2709381Seric 	syserr("too many %c lines, %d max", id, maxcnt);
2718547Seric }
2728547Seric /*
2734432Seric **  FILECLASS -- read members of a class from a file
2744432Seric **
2754432Seric **	Parameters:
2764432Seric **		class -- class to define.
2774432Seric **		filename -- name of file to read.
2784432Seric **		fmt -- scanf string to use for match.
2794432Seric **
2804432Seric **	Returns:
2814432Seric **		none
2824432Seric **
2834432Seric **	Side Effects:
2844432Seric **
2854432Seric **		puts all lines in filename that match a scanf into
2864432Seric **			the named class.
2874432Seric */
2884432Seric 
2894432Seric fileclass(class, filename, fmt)
2904432Seric 	int class;
2914432Seric 	char *filename;
2924432Seric 	char *fmt;
2934432Seric {
2944432Seric 	register FILE *f;
2954432Seric 	char buf[MAXLINE];
2964432Seric 
2974432Seric 	f = fopen(filename, "r");
2984432Seric 	if (f == NULL)
2994432Seric 	{
3004432Seric 		syserr("cannot open %s", filename);
3014432Seric 		return;
3024432Seric 	}
3034432Seric 
3044432Seric 	while (fgets(buf, sizeof buf, f) != NULL)
3054432Seric 	{
3064432Seric 		register STAB *s;
3074432Seric 		char wordbuf[MAXNAME+1];
3084432Seric 
3094432Seric 		if (sscanf(buf, fmt, wordbuf) != 1)
3104432Seric 			continue;
3114432Seric 		s = stab(wordbuf, ST_CLASS, ST_ENTER);
3126275Seric 		s->s_class |= 1L << class;
3134432Seric 	}
3144432Seric 
3154627Seric 	(void) fclose(f);
3164432Seric }
3174432Seric /*
3184096Seric **  MAKEMAILER -- define a new mailer.
3194096Seric **
3204096Seric **	Parameters:
3214096Seric **		line -- description of mailer.  This is in tokens
3224096Seric **			separated by white space.  The fields are:
3234096Seric **			* the name of the mailer, as refered to
3244096Seric **			  in the rewriting rules.
3254096Seric **			* the pathname of the program to fork to
3264096Seric **			  execute it.
3274096Seric **			* the options needed by this program.
3284096Seric **			* the macro string needed to translate
3294096Seric **			  a local "from" name to one that can be
3304096Seric **			  returned to this machine.
3314096Seric **			* the argument vector (a series of parameters).
3324217Seric **		safe -- set if this is a safe configuration file.
3334096Seric **
3344096Seric **	Returns:
3354096Seric **		none.
3364096Seric **
3374096Seric **	Side Effects:
3384096Seric **		enters the mailer into the mailer table.
3394096Seric */
3403308Seric 
3414096Seric # define SETWORD \
3424096Seric 		{ \
3434096Seric 			while (*p != '\0' && isspace(*p)) \
3444096Seric 				p++; \
3454096Seric 			q = p; \
3464096Seric 			while (*p != '\0' && !isspace(*p)) \
3474096Seric 				p++; \
3484096Seric 			if (*p != '\0') \
3494096Seric 				*p++ = '\0'; \
3504096Seric 		}
3514096Seric 
3524217Seric makemailer(line, safe)
3534096Seric 	char *line;
3544217Seric 	bool safe;
3554096Seric {
3564096Seric 	register char *p;
3574096Seric 	register char *q;
3588067Seric 	register struct mailer *m;
3598067Seric 	register STAB *s;
3608067Seric 	int i;
3614096Seric 	char *mname;
3624096Seric 	char *mpath;
3634627Seric 	u_long mopts;
3648067Seric 	short mrset, msset;
3658067Seric 	char *margv[MAXPV + 1];
3664627Seric 	extern u_long mfencode();
3674096Seric 	extern int NextMailer;
3684096Seric 
3694096Seric 	if (NextMailer >= MAXMAILERS)
3704096Seric 	{
3719381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
3724096Seric 		return;
3734096Seric 	}
3744096Seric 
3754096Seric 	/* collect initial information */
3764096Seric 	p = line;
3774096Seric 	SETWORD;
3784096Seric 	mname = q;
3794096Seric 	SETWORD;
3804096Seric 	mpath = q;
3814096Seric 	SETWORD;
3824627Seric 	mopts = mfencode(q);
3834217Seric 	if (!safe)
3844217Seric 		mopts &= ~M_RESTR;
3854096Seric 	SETWORD;
3868067Seric 	msset = atoi(q);
3878067Seric 	SETWORD;
3888067Seric 	mrset = atoi(q);
3894096Seric 
3904096Seric 	if (*p == '\0')
3914096Seric 	{
3929381Seric 		syserr("invalid M line in configuration file");
3934096Seric 		return;
3944096Seric 	}
3958067Seric 	if (msset >= MAXRWSETS || mrset >= MAXRWSETS)
3968067Seric 	{
3978067Seric 		syserr("readcf: line %d: invalid rewrite set, %d max",
3988067Seric 			LineNumber, MAXRWSETS);
3998067Seric 		return;
4008067Seric 	}
4014096Seric 
4024096Seric 	/* allocate a mailer */
4034096Seric 	m = (struct mailer *) xalloc(sizeof *m);
4044096Seric 	m->m_name = newstr(mname);
4054096Seric 	m->m_mailer = newstr(mpath);
4064096Seric 	m->m_flags = mopts;
4078067Seric 	m->m_r_rwset = mrset;
4088067Seric 	m->m_s_rwset = msset;
4094439Seric 	m->m_mno = NextMailer;
4104096Seric 	Mailer[NextMailer++] = m;
4114096Seric 
4124096Seric 	/* collect the argument vector */
4134096Seric 	for (i = 0; i < MAXPV - 1 && *p != '\0'; i++)
4144096Seric 	{
4154096Seric 		SETWORD;
4164096Seric 		margv[i] = newstr(q);
4174096Seric 	}
4184096Seric 	margv[i++] = NULL;
4194096Seric 
4204096Seric 	/* save the argv */
4217009Seric 	m->m_argv = (char **) xalloc(sizeof margv[0] * i);
4224096Seric 	bmove((char *) margv, (char *) m->m_argv, sizeof margv[0] * i);
4234439Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
4244439Seric 	s->s_mailer = m;
4253308Seric }
4263308Seric /*
4273308Seric **  PRINTRULES -- print rewrite rules (for debugging)
4283308Seric **
4293308Seric **	Parameters:
4303308Seric **		none.
4313308Seric **
4323308Seric **	Returns:
4333308Seric **		none.
4343308Seric **
4353308Seric **	Side Effects:
4363308Seric **		prints rewrite rules.
4373308Seric */
4383308Seric 
4394319Seric # ifdef DEBUG
4404319Seric 
4413308Seric printrules()
4423308Seric {
4433308Seric 	register struct rewrite *rwp;
4444072Seric 	register int ruleset;
4453308Seric 
4464072Seric 	for (ruleset = 0; ruleset < 10; ruleset++)
4473308Seric 	{
4484072Seric 		if (RewriteRules[ruleset] == NULL)
4494072Seric 			continue;
4508067Seric 		printf("\n----Rule Set %d:", ruleset);
4513308Seric 
4524072Seric 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
4533308Seric 		{
4548067Seric 			printf("\nLHS:");
4558067Seric 			printav(rwp->r_lhs);
4568067Seric 			printf("RHS:");
4578067Seric 			printav(rwp->r_rhs);
4583308Seric 		}
4593308Seric 	}
4603308Seric }
4614319Seric 
4624319Seric # endif DEBUG
4634096Seric /*
4644627Seric **  MFENCODE -- crack mailer options
4654096Seric **
4664096Seric **	These options modify the functioning of the mailer
4674096Seric **	from the configuration table.
4684096Seric **
4694096Seric **	Parameters:
4704096Seric **		p -- pointer to vector of options.
4714096Seric **
4724096Seric **	Returns:
4734096Seric **		option list in binary.
4744096Seric **
4754096Seric **	Side Effects:
4764096Seric **		none.
4774096Seric */
4784096Seric 
4794096Seric struct optlist
4804096Seric {
4814096Seric 	char	opt_name;	/* external name of option */
4826275Seric 	u_long	opt_value;	/* internal name of option */
4834096Seric };
4844096Seric struct optlist	OptList[] =
4854096Seric {
486*10174Seric 	'A',	M_ARPAFMT,
487*10174Seric 	'C',	M_CANONICAL,
488*10174Seric 	'D',	M_NEEDDATE,
489*10174Seric 	'e',	M_EXPENSIVE,
490*10174Seric 	'F',	M_NEEDFROM,
4914096Seric 	'f',	M_FOPT,
492*10174Seric 	'h',	M_HST_UPPER,
493*10174Seric 	'I',	M_INTERNAL,
494*10174Seric 	'L',	M_LIMITS,
495*10174Seric 	'l',	M_LOCAL,
496*10174Seric 	'M',	M_MSGID,
497*10174Seric 	'm',	M_MUSER,
498*10174Seric 	'n',	M_NHDR,
499*10174Seric 	'P',	M_RPATH,
500*10174Seric 	'p',	M_FROMPATH,
501*10174Seric 	'R',	M_CRLF,
5024096Seric 	'r',	M_ROPT,
5034096Seric 	'S',	M_RESTR,
5044096Seric 	's',	M_STRIPQ,
505*10174Seric 	'U',	M_UGLYUUCP,
5064096Seric 	'u',	M_USR_UPPER,
5074096Seric 	'x',	M_FULLNAME,
508*10174Seric 	'X',	M_XDOT,
5094319Seric 	'\0',	0
5104096Seric };
5114096Seric 
5124627Seric u_long
5134627Seric mfencode(p)
5144096Seric 	register char *p;
5154096Seric {
5164096Seric 	register struct optlist *o;
5174627Seric 	register u_long opts = 0;
5184096Seric 
5194096Seric 	while (*p != '\0')
5204096Seric 	{
5214096Seric 		for (o = OptList; o->opt_name != '\0' && o->opt_name != *p; o++)
5224096Seric 			continue;
5234096Seric 		if (o->opt_name == '\0')
5244096Seric 			syserr("bad mailer option %c", *p);
5254096Seric 		opts |= o->opt_value;
5264096Seric 		p++;
5274096Seric 	}
5284096Seric 	return (opts);
5294096Seric }
5304627Seric /*
5314627Seric **  MFDECODE -- decode mailer flags into external form.
5324627Seric **
5334627Seric **	Parameters:
5344627Seric **		flags -- value of flags to decode.
5354627Seric **		f -- file to write them onto.
5364627Seric **
5374627Seric **	Returns:
5384627Seric **		none.
5394627Seric **
5404627Seric **	Side Effects:
5414627Seric **		none.
5424627Seric */
5434627Seric 
5444627Seric mfdecode(flags, f)
5454627Seric 	u_long flags;
5464627Seric 	FILE *f;
5474627Seric {
5484627Seric 	register struct optlist *o;
5494627Seric 
5504627Seric 	putc('?', f);
5514627Seric 	for (o = OptList; o->opt_name != '\0'; o++)
5524627Seric 	{
5534627Seric 		if ((o->opt_value & flags) == o->opt_value)
5544627Seric 		{
5554627Seric 			flags &= ~o->opt_value;
5564627Seric 			putc(o->opt_name, f);
5574627Seric 		}
5584627Seric 	}
5594627Seric 	putc('?', f);
5604627Seric }
5618256Seric /*
5628256Seric **  SETOPTION -- set global processing option
5638256Seric **
5648256Seric **	Parameters:
5658256Seric **		opt -- option name.
5668256Seric **		val -- option value (as a text string).
5678269Seric **		safe -- if set, this came from a system configuration file.
5688269Seric **		sticky -- if set, don't let other setoptions override
5698269Seric **			this value.
5708256Seric **
5718256Seric **	Returns:
5728256Seric **		none.
5738256Seric **
5748256Seric **	Side Effects:
5758256Seric **		Sets options as implied by the arguments.
5768256Seric */
5778256Seric 
5788544Seric static int	StickyOpt[128 / sizeof (int)];	/* set if option is stuck */
5798544Seric extern char	*WizWord;			/* the stored wizard password */
5808269Seric 
5818269Seric setoption(opt, val, safe, sticky)
5828256Seric 	char opt;
5838256Seric 	char *val;
5848269Seric 	bool safe;
5858269Seric 	bool sticky;
5868256Seric {
5878269Seric 	int smask;
5888269Seric 	int sindex;
5898265Seric 	extern bool atobool();
5908256Seric 
5918256Seric # ifdef DEBUG
5928256Seric 	if (tTd(37, 1))
5939341Seric 		printf("setoption %c=%s", opt, val);
5948256Seric # endif DEBUG
5958256Seric 
5968256Seric 	/*
5978269Seric 	**  See if this option is preset for us.
5988256Seric 	*/
5998256Seric 
6008269Seric 	sindex = opt;
6018269Seric 	smask = 1 << (sindex % sizeof (int));
6028269Seric 	sindex /= sizeof (int);
6038269Seric 	if (bitset(smask, StickyOpt[sindex]))
6048269Seric 	{
6058269Seric # ifdef DEBUG
6069341Seric 		if (tTd(37, 1))
6079341Seric 			printf(" (ignored)\n");
6088269Seric # endif DEBUG
6098269Seric 		return;
6108269Seric 	}
6119341Seric #ifdef DEBUG
6129341Seric 	else if (tTd(37, 1))
6139341Seric 		printf("\n");
6149341Seric #endif DEBUG
6158269Seric 	if (sticky)
6168269Seric 		StickyOpt[sindex] |= smask;
6178269Seric 
6188269Seric 	if (getruid() == 0)
6198269Seric 		safe = TRUE;
6208269Seric 
6218256Seric 	switch (opt)
6228256Seric 	{
6238256Seric 	  case 'A':		/* set default alias file */
6249381Seric 		if (val[0] == '\0')
6258269Seric 			AliasFile = "aliases";
6269381Seric 		else
6279381Seric 			AliasFile = newstr(val);
6288256Seric 		break;
6298256Seric 
6308931Seric 	  case 'a':		/* look for "@:@" in alias file */
6319381Seric 		SafeAlias = atobool(val);
6328931Seric 		break;
6338931Seric 
6349284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
6359381Seric 		NoConnect = atobool(val);
6369284Seric 		break;
6379284Seric 
6389284Seric 	  case 'd':		/* delivery mode */
6399284Seric 		switch (*val)
6408269Seric 		{
6419284Seric 		  case '\0':
6429284Seric 			SendMode = SM_DELIVER;
6438269Seric 			break;
6448269Seric 
6459284Seric 		  case SM_DELIVER:	/* do everything */
6469284Seric 		  case SM_FORK:		/* fork after verification */
6479284Seric 		  case SM_QUEUE:	/* queue only */
6489284Seric 			SendMode = *val;
6498269Seric 			break;
6508269Seric 
6518269Seric 		  default:
6529284Seric 			syserr("Unknown delivery mode %c", *val);
6538269Seric 			exit(EX_USAGE);
6548269Seric 		}
6558269Seric 		break;
6568269Seric 
6579146Seric 	  case 'D':		/* rebuild alias database as needed */
6589381Seric 		AutoRebuild = atobool(val);
6599146Seric 		break;
6609146Seric 
6618269Seric 	  case 'e':		/* set error processing mode */
6628269Seric 		switch (*val)
6638269Seric 		{
6649381Seric 		  case EM_QUIET:	/* be silent about it */
6658269Seric 			(void) freopen("/dev/null", "w", stdout);
6669381Seric 			/* fall through... */
6678269Seric 
6689381Seric 		  case EM_MAIL:		/* mail back */
6699381Seric 		  case EM_BERKNET:	/* do berknet error processing */
6709381Seric 		  case EM_WRITE:	/* write back (or mail) */
6718269Seric 			HoldErrs = TRUE;
6729381Seric 			/* fall through... */
6738269Seric 
6749381Seric 		  case EM_PRINT:	/* print errors normally (default) */
6759381Seric 			ErrorMode = *val;
6768269Seric 			break;
6778269Seric 		}
6788269Seric 		break;
6798269Seric 
6809049Seric 	  case 'F':		/* file mode */
6819381Seric 		FileMode = atooct(val);
6829049Seric 		break;
6839049Seric 
6848269Seric 	  case 'f':		/* save Unix-style From lines on front */
6859381Seric 		SaveFrom = atobool(val);
6868269Seric 		break;
6878269Seric 
6888256Seric 	  case 'g':		/* default gid */
6899105Seric 		if (safe)
6909381Seric 			DefGid = atoi(val);
6918256Seric 		break;
6928256Seric 
6938256Seric 	  case 'H':		/* help file */
6949381Seric 		if (val[0] == '\0')
6958269Seric 			HelpFile = "sendmail.hf";
6969381Seric 		else
6979381Seric 			HelpFile = newstr(val);
6988256Seric 		break;
6998256Seric 
7008269Seric 	  case 'i':		/* ignore dot lines in message */
7019381Seric 		IgnrDot = atobool(val);
7028269Seric 		break;
7038269Seric 
7048256Seric 	  case 'L':		/* log level */
7059381Seric 		LogLevel = atoi(val);
7068256Seric 		break;
7078256Seric 
7088269Seric 	  case 'M':		/* define macro */
7099381Seric 		define(val[0], newstr(&val[1]), CurEnv);
7108269Seric 		break;
7118269Seric 
7128269Seric 	  case 'm':		/* send to me too */
7139381Seric 		MeToo = atobool(val);
7148269Seric 		break;
7158269Seric 
7168269Seric 	  case 'o':		/* assume old style headers */
7179381Seric 		if (atobool(val))
7189341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
7199341Seric 		else
7209341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
7218269Seric 		break;
7228269Seric 
7238256Seric 	  case 'Q':		/* queue directory */
7249381Seric 		if (val[0] == '\0')
7258269Seric 			QueueDir = "mqueue";
7269381Seric 		else
7279381Seric 			QueueDir = newstr(val);
7288256Seric 		break;
7298256Seric 
7308256Seric 	  case 'r':		/* read timeout */
7319381Seric 		ReadTimeout = convtime(val);
7328256Seric 		break;
7338256Seric 
7348256Seric 	  case 'S':		/* status file */
7359381Seric 		if (val[0] == '\0')
7368269Seric 			StatFile = "sendmail.st";
7379381Seric 		else
7389381Seric 			StatFile = newstr(val);
7398256Seric 		break;
7408256Seric 
7418265Seric 	  case 's':		/* be super safe, even if expensive */
7429381Seric 		SuperSafe = atobool(val);
7438256Seric 		break;
7448256Seric 
7458256Seric 	  case 'T':		/* queue timeout */
7469381Seric 		TimeOut = convtime(val);
7478256Seric 		break;
7488256Seric 
7498265Seric 	  case 't':		/* time zone name */
7508265Seric # ifdef V6
7519381Seric 		StdTimezone = newstr(val);
7529381Seric 		DstTimezone = index(StdTimeZone, ',');
7538265Seric 		if (DstTimezone == NULL)
7549381Seric 			syserr("bad time zone spec");
7559381Seric 		else
7569381Seric 			*DstTimezone++ = '\0';
7578265Seric # endif V6
7588265Seric 		break;
7598265Seric 
7608256Seric 	  case 'u':		/* set default uid */
7619105Seric 		if (safe)
7629381Seric 			DefUid = atoi(val);
7638256Seric 		break;
7648256Seric 
7658269Seric 	  case 'v':		/* run in verbose mode */
7669381Seric 		Verbose = atobool(val);
7678256Seric 		break;
7688256Seric 
7698544Seric # ifdef DEBUG
7708544Seric 	  case 'W':		/* set the wizards password */
7719105Seric 		if (safe)
7729381Seric 			WizWord = newstr(val);
7738544Seric 		break;
7748544Seric # endif DEBUG
7758544Seric 
7768256Seric 	  default:
7778256Seric 		break;
7788256Seric 	}
7799188Seric 	return;
7808256Seric }
781