xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 10327)
13313Seric # include "sendmail.h"
23308Seric 
3*10327Seric SCCSID(@(#)readcf.c	3.50		01/16/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:
321*10327Seric **		line -- description of mailer.  This is in labeled
322*10327Seric **			fields.  The fields are:
323*10327Seric **			   P -- the path to the mailer
324*10327Seric **			   F -- the flags associated with the mailer
325*10327Seric **			   A -- the argv for this mailer
326*10327Seric **			   S -- the sender rewriting set
327*10327Seric **			   R -- the recipient rewriting set
328*10327Seric **			   E -- the eol string
329*10327Seric **			The first word is the canonical name of the mailer.
3304217Seric **		safe -- set if this is a safe configuration file.
3314096Seric **
3324096Seric **	Returns:
3334096Seric **		none.
3344096Seric **
3354096Seric **	Side Effects:
3364096Seric **		enters the mailer into the mailer table.
3374096Seric */
3383308Seric 
3394217Seric makemailer(line, safe)
3404096Seric 	char *line;
3414217Seric 	bool safe;
3424096Seric {
3434096Seric 	register char *p;
3448067Seric 	register struct mailer *m;
3458067Seric 	register STAB *s;
3468067Seric 	int i;
347*10327Seric 	char fcode;
3484627Seric 	extern u_long mfencode();
3494096Seric 	extern int NextMailer;
350*10327Seric 	extern char **makeargv();
351*10327Seric 	extern char *munchstring();
352*10327Seric 	extern char *DelimChar;
3534096Seric 
354*10327Seric 	/* allocate a mailer and set up defaults */
355*10327Seric 	m = (struct mailer *) xalloc(sizeof *m);
356*10327Seric 	bzero((char *) m, sizeof *m);
357*10327Seric 	m->m_mno = NextMailer;
358*10327Seric 	m->m_eol = "\n";
359*10327Seric 
360*10327Seric 	/* collect the mailer name */
361*10327Seric 	for (p = line; *p != '\0' && *p != ',' && !isspace(*p); p++)
362*10327Seric 		continue;
363*10327Seric 	if (*p != '\0')
364*10327Seric 		*p++ = '\0';
365*10327Seric 	m->m_name = newstr(line);
366*10327Seric 
367*10327Seric 	/* now scan through and assign info from the fields */
368*10327Seric 	while (*p != '\0')
369*10327Seric 	{
370*10327Seric 		while (*p != '\0' && (*p == ',' || isspace(*p)))
371*10327Seric 			p++;
372*10327Seric 
373*10327Seric 		/* p now points to field code */
374*10327Seric 		fcode = *p;
375*10327Seric 		while (*p != '\0' && *p != '=' && *p != ',')
376*10327Seric 			p++;
377*10327Seric 		if (*p++ != '=')
378*10327Seric 		{
379*10327Seric 			syserr("`=' expected");
380*10327Seric 			return;
381*10327Seric 		}
382*10327Seric 		while (isspace(*p))
383*10327Seric 			p++;
384*10327Seric 
385*10327Seric 		/* p now points to the field body */
386*10327Seric 		p = munchstring(p);
387*10327Seric 
388*10327Seric 		/* install the field into the mailer struct */
389*10327Seric 		switch (fcode)
390*10327Seric 		{
391*10327Seric 		  case 'P':		/* pathname */
392*10327Seric 			m->m_mailer = newstr(p);
393*10327Seric 			break;
394*10327Seric 
395*10327Seric 		  case 'F':		/* flags */
396*10327Seric 			m->m_flags = mfencode(p);
397*10327Seric 			if (!safe)
398*10327Seric 				m->m_flags &= ~M_RESTR;
399*10327Seric 			break;
400*10327Seric 
401*10327Seric 		  case 'S':		/* sender rewriting ruleset */
402*10327Seric 		  case 'R':		/* recipient rewriting ruleset */
403*10327Seric 			i = atoi(p);
404*10327Seric 			if (i < 0 || i >= MAXRWSETS)
405*10327Seric 			{
406*10327Seric 				syserr("invalid rewrite set, %d max", MAXRWSETS);
407*10327Seric 				return;
408*10327Seric 			}
409*10327Seric 			if (fcode == 'S')
410*10327Seric 				m->m_s_rwset = i;
411*10327Seric 			else
412*10327Seric 				m->m_r_rwset = i;
413*10327Seric 			break;
414*10327Seric 
415*10327Seric 		  case 'E':		/* end of line string */
416*10327Seric 			m->m_eol = newstr(p);
417*10327Seric 			break;
418*10327Seric 
419*10327Seric 		  case 'A':		/* argument vector */
420*10327Seric 			m->m_argv = makeargv(p);
421*10327Seric 			break;
422*10327Seric 		}
423*10327Seric 
424*10327Seric 		p = DelimChar;
425*10327Seric 	}
426*10327Seric 
427*10327Seric 	/* now store the mailer away */
4284096Seric 	if (NextMailer >= MAXMAILERS)
4294096Seric 	{
4309381Seric 		syserr("too many mailers defined (%d max)", MAXMAILERS);
4314096Seric 		return;
4324096Seric 	}
433*10327Seric 	Mailer[NextMailer++] = m;
434*10327Seric 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
435*10327Seric 	s->s_mailer = m;
436*10327Seric }
437*10327Seric /*
438*10327Seric **  MUNCHSTRING -- translate a string into internal form.
439*10327Seric **
440*10327Seric **	Parameters:
441*10327Seric **		p -- the string to munch.
442*10327Seric **
443*10327Seric **	Returns:
444*10327Seric **		the munched string.
445*10327Seric **
446*10327Seric **	Side Effects:
447*10327Seric **		Sets "DelimChar" to point to the string that caused us
448*10327Seric **		to stop.
449*10327Seric */
4504096Seric 
451*10327Seric char *
452*10327Seric munchstring(p)
453*10327Seric 	register char *p;
454*10327Seric {
455*10327Seric 	register char *q;
456*10327Seric 	bool backslash = FALSE;
457*10327Seric 	bool quotemode = FALSE;
458*10327Seric 	static char buf[MAXLINE];
459*10327Seric 	extern char *DelimChar;
4604096Seric 
461*10327Seric 	for (q = buf; *p != '\0'; p++)
4624096Seric 	{
463*10327Seric 		if (backslash)
464*10327Seric 		{
465*10327Seric 			/* everything is roughly literal */
466*10327Seric 			switch (*p)
467*10327Seric 			{
468*10327Seric 			  case 'r':		/* carriage return */
469*10327Seric 				*q++ = '\r';
470*10327Seric 				continue;
471*10327Seric 
472*10327Seric 			  case 'n':		/* newline */
473*10327Seric 				*q++ = '\n';
474*10327Seric 				continue;
475*10327Seric 
476*10327Seric 			  case 'f':		/* form feed */
477*10327Seric 				*q++ = '\f';
478*10327Seric 				continue;
479*10327Seric 
480*10327Seric 			  case 'b':		/* backspace */
481*10327Seric 				*q++ = '\b';
482*10327Seric 				continue;
483*10327Seric 			}
484*10327Seric 			*q++ = *p;
485*10327Seric 			backslash = FALSE;
486*10327Seric 		}
487*10327Seric 		else
488*10327Seric 		{
489*10327Seric 			if (*p == '\\')
490*10327Seric 				backslash = TRUE;
491*10327Seric 			else if (*p == '"')
492*10327Seric 				quotemode = !quotemode;
493*10327Seric 			else if (quotemode || *p != ',')
494*10327Seric 				*q++ = *p;
495*10327Seric 			else
496*10327Seric 				break;
497*10327Seric 		}
4984096Seric 	}
4994096Seric 
500*10327Seric 	DelimChar = p;
501*10327Seric 	*q++ = '\0';
502*10327Seric 	return (buf);
503*10327Seric }
504*10327Seric /*
505*10327Seric **  MAKEARGV -- break up a string into words
506*10327Seric **
507*10327Seric **	Parameters:
508*10327Seric **		p -- the string to break up.
509*10327Seric **
510*10327Seric **	Returns:
511*10327Seric **		a char **argv (dynamically allocated)
512*10327Seric **
513*10327Seric **	Side Effects:
514*10327Seric **		munges p.
515*10327Seric */
5164096Seric 
517*10327Seric char **
518*10327Seric makeargv(p)
519*10327Seric 	register char *p;
520*10327Seric {
521*10327Seric 	char *q;
522*10327Seric 	int i;
523*10327Seric 	char **avp;
524*10327Seric 	char *argv[MAXPV + 1];
525*10327Seric 
526*10327Seric 	/* take apart the words */
527*10327Seric 	i = 0;
528*10327Seric 	while (*p != '\0' && i < MAXPV)
5294096Seric 	{
530*10327Seric 		q = p;
531*10327Seric 		while (*p != '\0' && !isspace(*p))
532*10327Seric 			p++;
533*10327Seric 		while (isspace(*p))
534*10327Seric 			*p++ = '\0';
535*10327Seric 		argv[i++] = newstr(q);
5364096Seric 	}
537*10327Seric 	argv[i++] = NULL;
5384096Seric 
539*10327Seric 	/* now make a copy of the argv */
540*10327Seric 	avp = (char **) xalloc(sizeof *avp * i);
541*10327Seric 	bmove((char *) argv, (char *) avp, sizeof *avp * i);
542*10327Seric 
543*10327Seric 	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 /*
5834627Seric **  MFENCODE -- crack mailer options
5844096Seric **
5854096Seric **	These options modify the functioning of the mailer
5864096Seric **	from the configuration table.
5874096Seric **
5884096Seric **	Parameters:
5894096Seric **		p -- pointer to vector of options.
5904096Seric **
5914096Seric **	Returns:
5924096Seric **		option list in binary.
5934096Seric **
5944096Seric **	Side Effects:
5954096Seric **		none.
5964096Seric */
5974096Seric 
5984096Seric struct optlist
5994096Seric {
6004096Seric 	char	opt_name;	/* external name of option */
6016275Seric 	u_long	opt_value;	/* internal name of option */
6024096Seric };
6034096Seric struct optlist	OptList[] =
6044096Seric {
60510174Seric 	'A',	M_ARPAFMT,
60610174Seric 	'C',	M_CANONICAL,
60710174Seric 	'D',	M_NEEDDATE,
60810174Seric 	'e',	M_EXPENSIVE,
60910174Seric 	'F',	M_NEEDFROM,
6104096Seric 	'f',	M_FOPT,
61110174Seric 	'h',	M_HST_UPPER,
61210174Seric 	'I',	M_INTERNAL,
61310174Seric 	'L',	M_LIMITS,
61410174Seric 	'l',	M_LOCAL,
61510174Seric 	'M',	M_MSGID,
61610174Seric 	'm',	M_MUSER,
61710174Seric 	'n',	M_NHDR,
61810174Seric 	'P',	M_RPATH,
61910174Seric 	'p',	M_FROMPATH,
6204096Seric 	'r',	M_ROPT,
6214096Seric 	'S',	M_RESTR,
6224096Seric 	's',	M_STRIPQ,
62310174Seric 	'U',	M_UGLYUUCP,
6244096Seric 	'u',	M_USR_UPPER,
6254096Seric 	'x',	M_FULLNAME,
62610174Seric 	'X',	M_XDOT,
6274319Seric 	'\0',	0
6284096Seric };
6294096Seric 
6304627Seric u_long
6314627Seric mfencode(p)
6324096Seric 	register char *p;
6334096Seric {
6344096Seric 	register struct optlist *o;
6354627Seric 	register u_long opts = 0;
6364096Seric 
6374096Seric 	while (*p != '\0')
6384096Seric 	{
6394096Seric 		for (o = OptList; o->opt_name != '\0' && o->opt_name != *p; o++)
6404096Seric 			continue;
6414096Seric 		opts |= o->opt_value;
6424096Seric 		p++;
6434096Seric 	}
6444096Seric 	return (opts);
6454096Seric }
6464627Seric /*
6474627Seric **  MFDECODE -- decode mailer flags into external form.
6484627Seric **
6494627Seric **	Parameters:
6504627Seric **		flags -- value of flags to decode.
6514627Seric **		f -- file to write them onto.
6524627Seric **
6534627Seric **	Returns:
6544627Seric **		none.
6554627Seric **
6564627Seric **	Side Effects:
6574627Seric **		none.
6584627Seric */
6594627Seric 
6604627Seric mfdecode(flags, f)
6614627Seric 	u_long flags;
6624627Seric 	FILE *f;
6634627Seric {
6644627Seric 	register struct optlist *o;
6654627Seric 
6664627Seric 	putc('?', f);
6674627Seric 	for (o = OptList; o->opt_name != '\0'; o++)
6684627Seric 	{
6694627Seric 		if ((o->opt_value & flags) == o->opt_value)
6704627Seric 		{
6714627Seric 			flags &= ~o->opt_value;
6724627Seric 			putc(o->opt_name, f);
6734627Seric 		}
6744627Seric 	}
6754627Seric 	putc('?', f);
6764627Seric }
6778256Seric /*
6788256Seric **  SETOPTION -- set global processing option
6798256Seric **
6808256Seric **	Parameters:
6818256Seric **		opt -- option name.
6828256Seric **		val -- option value (as a text string).
6838269Seric **		safe -- if set, this came from a system configuration file.
6848269Seric **		sticky -- if set, don't let other setoptions override
6858269Seric **			this value.
6868256Seric **
6878256Seric **	Returns:
6888256Seric **		none.
6898256Seric **
6908256Seric **	Side Effects:
6918256Seric **		Sets options as implied by the arguments.
6928256Seric */
6938256Seric 
6948544Seric static int	StickyOpt[128 / sizeof (int)];	/* set if option is stuck */
6958544Seric extern char	*WizWord;			/* the stored wizard password */
6968269Seric 
6978269Seric setoption(opt, val, safe, sticky)
6988256Seric 	char opt;
6998256Seric 	char *val;
7008269Seric 	bool safe;
7018269Seric 	bool sticky;
7028256Seric {
7038269Seric 	int smask;
7048269Seric 	int sindex;
7058265Seric 	extern bool atobool();
7068256Seric 
7078256Seric # ifdef DEBUG
7088256Seric 	if (tTd(37, 1))
7099341Seric 		printf("setoption %c=%s", opt, val);
7108256Seric # endif DEBUG
7118256Seric 
7128256Seric 	/*
7138269Seric 	**  See if this option is preset for us.
7148256Seric 	*/
7158256Seric 
7168269Seric 	sindex = opt;
7178269Seric 	smask = 1 << (sindex % sizeof (int));
7188269Seric 	sindex /= sizeof (int);
7198269Seric 	if (bitset(smask, StickyOpt[sindex]))
7208269Seric 	{
7218269Seric # ifdef DEBUG
7229341Seric 		if (tTd(37, 1))
7239341Seric 			printf(" (ignored)\n");
7248269Seric # endif DEBUG
7258269Seric 		return;
7268269Seric 	}
7279341Seric #ifdef DEBUG
7289341Seric 	else if (tTd(37, 1))
7299341Seric 		printf("\n");
7309341Seric #endif DEBUG
7318269Seric 	if (sticky)
7328269Seric 		StickyOpt[sindex] |= smask;
7338269Seric 
7348269Seric 	if (getruid() == 0)
7358269Seric 		safe = TRUE;
7368269Seric 
7378256Seric 	switch (opt)
7388256Seric 	{
7398256Seric 	  case 'A':		/* set default alias file */
7409381Seric 		if (val[0] == '\0')
7418269Seric 			AliasFile = "aliases";
7429381Seric 		else
7439381Seric 			AliasFile = newstr(val);
7448256Seric 		break;
7458256Seric 
7468931Seric 	  case 'a':		/* look for "@:@" in alias file */
7479381Seric 		SafeAlias = atobool(val);
7488931Seric 		break;
7498931Seric 
7509284Seric 	  case 'c':		/* don't connect to "expensive" mailers */
7519381Seric 		NoConnect = atobool(val);
7529284Seric 		break;
7539284Seric 
7549284Seric 	  case 'd':		/* delivery mode */
7559284Seric 		switch (*val)
7568269Seric 		{
7579284Seric 		  case '\0':
7589284Seric 			SendMode = SM_DELIVER;
7598269Seric 			break;
7608269Seric 
7619284Seric 		  case SM_DELIVER:	/* do everything */
7629284Seric 		  case SM_FORK:		/* fork after verification */
7639284Seric 		  case SM_QUEUE:	/* queue only */
7649284Seric 			SendMode = *val;
7658269Seric 			break;
7668269Seric 
7678269Seric 		  default:
7689284Seric 			syserr("Unknown delivery mode %c", *val);
7698269Seric 			exit(EX_USAGE);
7708269Seric 		}
7718269Seric 		break;
7728269Seric 
7739146Seric 	  case 'D':		/* rebuild alias database as needed */
7749381Seric 		AutoRebuild = atobool(val);
7759146Seric 		break;
7769146Seric 
7778269Seric 	  case 'e':		/* set error processing mode */
7788269Seric 		switch (*val)
7798269Seric 		{
7809381Seric 		  case EM_QUIET:	/* be silent about it */
7818269Seric 			(void) freopen("/dev/null", "w", stdout);
7829381Seric 			/* fall through... */
7838269Seric 
7849381Seric 		  case EM_MAIL:		/* mail back */
7859381Seric 		  case EM_BERKNET:	/* do berknet error processing */
7869381Seric 		  case EM_WRITE:	/* write back (or mail) */
7878269Seric 			HoldErrs = TRUE;
7889381Seric 			/* fall through... */
7898269Seric 
7909381Seric 		  case EM_PRINT:	/* print errors normally (default) */
7919381Seric 			ErrorMode = *val;
7928269Seric 			break;
7938269Seric 		}
7948269Seric 		break;
7958269Seric 
7969049Seric 	  case 'F':		/* file mode */
7979381Seric 		FileMode = atooct(val);
7989049Seric 		break;
7999049Seric 
8008269Seric 	  case 'f':		/* save Unix-style From lines on front */
8019381Seric 		SaveFrom = atobool(val);
8028269Seric 		break;
8038269Seric 
8048256Seric 	  case 'g':		/* default gid */
8059105Seric 		if (safe)
8069381Seric 			DefGid = atoi(val);
8078256Seric 		break;
8088256Seric 
8098256Seric 	  case 'H':		/* help file */
8109381Seric 		if (val[0] == '\0')
8118269Seric 			HelpFile = "sendmail.hf";
8129381Seric 		else
8139381Seric 			HelpFile = newstr(val);
8148256Seric 		break;
8158256Seric 
8168269Seric 	  case 'i':		/* ignore dot lines in message */
8179381Seric 		IgnrDot = atobool(val);
8188269Seric 		break;
8198269Seric 
8208256Seric 	  case 'L':		/* log level */
8219381Seric 		LogLevel = atoi(val);
8228256Seric 		break;
8238256Seric 
8248269Seric 	  case 'M':		/* define macro */
8259381Seric 		define(val[0], newstr(&val[1]), CurEnv);
8268269Seric 		break;
8278269Seric 
8288269Seric 	  case 'm':		/* send to me too */
8299381Seric 		MeToo = atobool(val);
8308269Seric 		break;
8318269Seric 
8328269Seric 	  case 'o':		/* assume old style headers */
8339381Seric 		if (atobool(val))
8349341Seric 			CurEnv->e_flags |= EF_OLDSTYLE;
8359341Seric 		else
8369341Seric 			CurEnv->e_flags &= ~EF_OLDSTYLE;
8378269Seric 		break;
8388269Seric 
8398256Seric 	  case 'Q':		/* queue directory */
8409381Seric 		if (val[0] == '\0')
8418269Seric 			QueueDir = "mqueue";
8429381Seric 		else
8439381Seric 			QueueDir = newstr(val);
8448256Seric 		break;
8458256Seric 
8468256Seric 	  case 'r':		/* read timeout */
8479381Seric 		ReadTimeout = convtime(val);
8488256Seric 		break;
8498256Seric 
8508256Seric 	  case 'S':		/* status file */
8519381Seric 		if (val[0] == '\0')
8528269Seric 			StatFile = "sendmail.st";
8539381Seric 		else
8549381Seric 			StatFile = newstr(val);
8558256Seric 		break;
8568256Seric 
8578265Seric 	  case 's':		/* be super safe, even if expensive */
8589381Seric 		SuperSafe = atobool(val);
8598256Seric 		break;
8608256Seric 
8618256Seric 	  case 'T':		/* queue timeout */
8629381Seric 		TimeOut = convtime(val);
8638256Seric 		break;
8648256Seric 
8658265Seric 	  case 't':		/* time zone name */
8668265Seric # ifdef V6
8679381Seric 		StdTimezone = newstr(val);
8689381Seric 		DstTimezone = index(StdTimeZone, ',');
8698265Seric 		if (DstTimezone == NULL)
8709381Seric 			syserr("bad time zone spec");
8719381Seric 		else
8729381Seric 			*DstTimezone++ = '\0';
8738265Seric # endif V6
8748265Seric 		break;
8758265Seric 
8768256Seric 	  case 'u':		/* set default uid */
8779105Seric 		if (safe)
8789381Seric 			DefUid = atoi(val);
8798256Seric 		break;
8808256Seric 
8818269Seric 	  case 'v':		/* run in verbose mode */
8829381Seric 		Verbose = atobool(val);
8838256Seric 		break;
8848256Seric 
8858544Seric # ifdef DEBUG
8868544Seric 	  case 'W':		/* set the wizards password */
8879105Seric 		if (safe)
8889381Seric 			WizWord = newstr(val);
8898544Seric 		break;
8908544Seric # endif DEBUG
8918544Seric 
8928256Seric 	  default:
8938256Seric 		break;
8948256Seric 	}
8959188Seric 	return;
8968256Seric }
897