xref: /csrg-svn/usr.sbin/sendmail/src/readcf.c (revision 54973)
1 /*
2  * Copyright (c) 1983 Eric P. Allman
3  * Copyright (c) 1988 Regents of the University of California.
4  * All rights reserved.
5  *
6  * %sccs.include.redist.c%
7  */
8 
9 #ifndef lint
10 static char sccsid[] = "@(#)readcf.c	5.40 (Berkeley) 07/12/92";
11 #endif /* not lint */
12 
13 # include "sendmail.h"
14 # include <sys/stat.h>
15 # include <unistd.h>
16 
17 /*
18 **  READCF -- read control file.
19 **
20 **	This routine reads the control file and builds the internal
21 **	form.
22 **
23 **	The file is formatted as a sequence of lines, each taken
24 **	atomically.  The first character of each line describes how
25 **	the line is to be interpreted.  The lines are:
26 **		Dxval		Define macro x to have value val.
27 **		Cxword		Put word into class x.
28 **		Fxfile [fmt]	Read file for lines to put into
29 **				class x.  Use scanf string 'fmt'
30 **				or "%s" if not present.  Fmt should
31 **				only produce one string-valued result.
32 **		Hname: value	Define header with field-name 'name'
33 **				and value as specified; this will be
34 **				macro expanded immediately before
35 **				use.
36 **		Sn		Use rewriting set n.
37 **		Rlhs rhs	Rewrite addresses that match lhs to
38 **				be rhs.
39 **		Mn arg=val...	Define mailer.  n is the internal name.
40 **				Args specify mailer parameters.
41 **		Oxvalue		Set option x to value.
42 **		Pname=value	Set precedence name to value.
43 **		Vversioncode	Version level of configuration syntax.
44 **		Kmapname mapclass arguments....
45 **				Define keyed lookup of a given class.
46 **				Arguments are class dependent.
47 **
48 **	Parameters:
49 **		cfname -- control file name.
50 **		safe -- TRUE if this is the system config file;
51 **			FALSE otherwise.
52 **
53 **	Returns:
54 **		none.
55 **
56 **	Side Effects:
57 **		Builds several internal tables.
58 */
59 
60 readcf(cfname, safe)
61 	char *cfname;
62 	bool safe;
63 {
64 	FILE *cf;
65 	int ruleset = 0;
66 	char *q;
67 	char **pv;
68 	struct rewrite *rwp = NULL;
69 	char buf[MAXLINE];
70 	register char *p;
71 	extern char **prescan();
72 	extern char **copyplist();
73 	struct stat statb;
74 	char exbuf[MAXLINE];
75 	char pvpbuf[PSBUFSIZE];
76 	extern char *fgetfolded();
77 	extern char *munchstring();
78 	extern void makemapentry();
79 
80 	FileName = cfname;
81 	LineNumber = 0;
82 
83 	cf = fopen(cfname, "r");
84 	if (cf == NULL)
85 	{
86 		syserr("cannot open");
87 		exit(EX_OSFILE);
88 	}
89 
90 	if (fstat(fileno(cf), &statb) < 0)
91 	{
92 		syserr("cannot fstat");
93 		exit(EX_OSFILE);
94 	}
95 
96 	if (!S_ISREG(statb.st_mode))
97 	{
98 		syserr("not a plain file");
99 		exit(EX_OSFILE);
100 	}
101 
102 	if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
103 	{
104 		if (OpMode == MD_DAEMON || OpMode == MD_FREEZE)
105 			fprintf(stderr, "%s: WARNING: dangerous write permissions\n",
106 				FileName);
107 #ifdef LOG
108 		if (LogLevel > 0)
109 			syslog(LOG_CRIT, "%s: WARNING: dangerous write permissions",
110 				FileName);
111 #endif
112 	}
113 
114 	while (fgetfolded(buf, sizeof buf, cf) != NULL)
115 	{
116 		if (buf[0] == '#')
117 			continue;
118 
119 		/* map $ into \001 (ASCII SOH) for macro expansion */
120 		for (p = buf; *p != '\0'; p++)
121 		{
122 			if (*p == '#' && p > buf && ConfigLevel >= 3)
123 			{
124 				/* this is an on-line comment */
125 				register char *e;
126 
127 				switch (*--p)
128 				{
129 				  case '\001':
130 					/* it's from $# -- let it go through */
131 					p++;
132 					break;
133 
134 				  case '\\':
135 					/* it's backslash escaped */
136 					(void) strcpy(p, p + 1);
137 					break;
138 
139 				  default:
140 					/* delete preceeding white space */
141 					while (isspace(*p) && p > buf)
142 						p--;
143 					if ((e = index(++p, '\n')) != NULL)
144 						(void) strcpy(p, e);
145 					else
146 						p[0] = p[1] = '\0';
147 					break;
148 				}
149 				continue;
150 			}
151 
152 			if (*p != '$')
153 				continue;
154 
155 			if (p[1] == '$')
156 			{
157 				/* actual dollar sign.... */
158 				(void) strcpy(p, p + 1);
159 				continue;
160 			}
161 
162 			/* convert to macro expansion character */
163 			*p = '\001';
164 		}
165 
166 		/* interpret this line */
167 		switch (buf[0])
168 		{
169 		  case '\0':
170 		  case '#':		/* comment */
171 			break;
172 
173 		  case 'R':		/* rewriting rule */
174 			for (p = &buf[1]; *p != '\0' && *p != '\t'; p++)
175 				continue;
176 
177 			if (*p == '\0')
178 			{
179 				syserr("invalid rewrite line \"%s\"", buf);
180 				break;
181 			}
182 
183 			/* allocate space for the rule header */
184 			if (rwp == NULL)
185 			{
186 				RewriteRules[ruleset] = rwp =
187 					(struct rewrite *) xalloc(sizeof *rwp);
188 			}
189 			else
190 			{
191 				rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
192 				rwp = rwp->r_next;
193 			}
194 			rwp->r_next = NULL;
195 
196 			/* expand and save the LHS */
197 			*p = '\0';
198 			expand(&buf[1], exbuf, &exbuf[sizeof exbuf], CurEnv);
199 			rwp->r_lhs = prescan(exbuf, '\t', pvpbuf);
200 			if (rwp->r_lhs != NULL)
201 				rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
202 
203 			/* expand and save the RHS */
204 			while (*++p == '\t')
205 				continue;
206 			q = p;
207 			while (*p != '\0' && *p != '\t')
208 				p++;
209 			*p = '\0';
210 			expand(q, exbuf, &exbuf[sizeof exbuf], CurEnv);
211 			rwp->r_rhs = prescan(exbuf, '\t', pvpbuf);
212 			if (rwp->r_rhs != NULL)
213 				rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
214 			break;
215 
216 		  case 'S':		/* select rewriting set */
217 			ruleset = atoi(&buf[1]);
218 			if (ruleset >= MAXRWSETS || ruleset < 0)
219 			{
220 				syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
221 				ruleset = 0;
222 			}
223 			rwp = NULL;
224 			break;
225 
226 		  case 'D':		/* macro definition */
227 			define(buf[1], newstr(munchstring(&buf[2])), CurEnv);
228 			break;
229 
230 		  case 'H':		/* required header line */
231 			(void) chompheader(&buf[1], TRUE);
232 			break;
233 
234 		  case 'C':		/* word class */
235 		  case 'F':		/* word class from file */
236 			/* read list of words from argument or file */
237 			if (buf[0] == 'F')
238 			{
239 				/* read from file */
240 				for (p = &buf[2]; *p != '\0' && !isspace(*p); p++)
241 					continue;
242 				if (*p == '\0')
243 					p = "%s";
244 				else
245 				{
246 					*p = '\0';
247 					while (isspace(*++p))
248 						continue;
249 				}
250 				fileclass(buf[1], &buf[2], p, safe);
251 				break;
252 			}
253 
254 			/* scan the list of words and set class for all */
255 			for (p = &buf[2]; *p != '\0'; )
256 			{
257 				register char *wd;
258 				char delim;
259 
260 				while (*p != '\0' && isspace(*p))
261 					p++;
262 				wd = p;
263 				while (*p != '\0' && !isspace(*p))
264 					p++;
265 				delim = *p;
266 				*p = '\0';
267 				if (wd[0] != '\0')
268 					setclass(buf[1], wd);
269 				*p = delim;
270 			}
271 			break;
272 
273 		  case 'M':		/* define mailer */
274 			makemailer(&buf[1]);
275 			break;
276 
277 		  case 'O':		/* set option */
278 			setoption(buf[1], &buf[2], safe, FALSE);
279 			break;
280 
281 		  case 'P':		/* set precedence */
282 			if (NumPriorities >= MAXPRIORITIES)
283 			{
284 				toomany('P', MAXPRIORITIES);
285 				break;
286 			}
287 			for (p = &buf[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
288 				continue;
289 			if (*p == '\0')
290 				goto badline;
291 			*p = '\0';
292 			Priorities[NumPriorities].pri_name = newstr(&buf[1]);
293 			Priorities[NumPriorities].pri_val = atoi(++p);
294 			NumPriorities++;
295 			break;
296 
297 		  case 'T':		/* trusted user(s) */
298 			p = &buf[1];
299 			while (*p != '\0')
300 			{
301 				while (isspace(*p))
302 					p++;
303 				q = p;
304 				while (*p != '\0' && !isspace(*p))
305 					p++;
306 				if (*p != '\0')
307 					*p++ = '\0';
308 				if (*q == '\0')
309 					continue;
310 				for (pv = TrustedUsers; *pv != NULL; pv++)
311 					continue;
312 				if (pv >= &TrustedUsers[MAXTRUST])
313 				{
314 					toomany('T', MAXTRUST);
315 					break;
316 				}
317 				*pv = newstr(q);
318 			}
319 			break;
320 
321 		  case 'V':		/* configuration syntax version */
322 			ConfigLevel = atoi(&buf[1]);
323 			break;
324 
325 		  case 'K':
326 			makemapentry(&buf[1]);
327 			break;
328 
329 		  default:
330 		  badline:
331 			syserr("unknown control line \"%s\"", buf);
332 		}
333 	}
334 	if (ferror(cf))
335 	{
336 		syserr("I/O read error", cfname);
337 		exit(EX_OSFILE);
338 	}
339 	fclose(cf);
340 	FileName = NULL;
341 }
342 /*
343 **  TOOMANY -- signal too many of some option
344 **
345 **	Parameters:
346 **		id -- the id of the error line
347 **		maxcnt -- the maximum possible values
348 **
349 **	Returns:
350 **		none.
351 **
352 **	Side Effects:
353 **		gives a syserr.
354 */
355 
356 toomany(id, maxcnt)
357 	char id;
358 	int maxcnt;
359 {
360 	syserr("too many %c lines, %d max", id, maxcnt);
361 }
362 /*
363 **  FILECLASS -- read members of a class from a file
364 **
365 **	Parameters:
366 **		class -- class to define.
367 **		filename -- name of file to read.
368 **		fmt -- scanf string to use for match.
369 **
370 **	Returns:
371 **		none
372 **
373 **	Side Effects:
374 **
375 **		puts all lines in filename that match a scanf into
376 **			the named class.
377 */
378 
379 fileclass(class, filename, fmt, safe)
380 	int class;
381 	char *filename;
382 	char *fmt;
383 	bool safe;
384 {
385 	FILE *f;
386 	struct stat stbuf;
387 	char buf[MAXLINE];
388 
389 	if (stat(filename, &stbuf) < 0)
390 	{
391 		syserr("fileclass: cannot stat %s", filename);
392 		return;
393 	}
394 	if (!S_ISREG(stbuf.st_mode))
395 	{
396 		syserr("fileclass: %s not a regular file", filename);
397 		return;
398 	}
399 	if (!safe && access(filename, R_OK) < 0)
400 	{
401 		syserr("fileclass: access denied on %s", filename);
402 		return;
403 	}
404 	f = fopen(filename, "r");
405 	if (f == NULL)
406 	{
407 		syserr("fileclass: cannot open %s", filename);
408 		return;
409 	}
410 
411 	while (fgets(buf, sizeof buf, f) != NULL)
412 	{
413 		register STAB *s;
414 		register char *p;
415 # ifdef SCANF
416 		char wordbuf[MAXNAME+1];
417 
418 		if (sscanf(buf, fmt, wordbuf) != 1)
419 			continue;
420 		p = wordbuf;
421 # else SCANF
422 		p = buf;
423 # endif SCANF
424 
425 		/*
426 		**  Break up the match into words.
427 		*/
428 
429 		while (*p != '\0')
430 		{
431 			register char *q;
432 
433 			/* strip leading spaces */
434 			while (isspace(*p))
435 				p++;
436 			if (*p == '\0')
437 				break;
438 
439 			/* find the end of the word */
440 			q = p;
441 			while (*p != '\0' && !isspace(*p))
442 				p++;
443 			if (*p != '\0')
444 				*p++ = '\0';
445 
446 			/* enter the word in the symbol table */
447 			s = stab(q, ST_CLASS, ST_ENTER);
448 			setbitn(class, s->s_class);
449 		}
450 	}
451 
452 	(void) fclose(f);
453 }
454 /*
455 **  MAKEMAILER -- define a new mailer.
456 **
457 **	Parameters:
458 **		line -- description of mailer.  This is in labeled
459 **			fields.  The fields are:
460 **			   P -- the path to the mailer
461 **			   F -- the flags associated with the mailer
462 **			   A -- the argv for this mailer
463 **			   S -- the sender rewriting set
464 **			   R -- the recipient rewriting set
465 **			   E -- the eol string
466 **			The first word is the canonical name of the mailer.
467 **
468 **	Returns:
469 **		none.
470 **
471 **	Side Effects:
472 **		enters the mailer into the mailer table.
473 */
474 
475 makemailer(line)
476 	char *line;
477 {
478 	register char *p;
479 	register struct mailer *m;
480 	register STAB *s;
481 	int i;
482 	char fcode;
483 	extern int NextMailer;
484 	extern char **makeargv();
485 	extern char *munchstring();
486 	extern char *DelimChar;
487 	extern long atol();
488 
489 	/* allocate a mailer and set up defaults */
490 	m = (struct mailer *) xalloc(sizeof *m);
491 	bzero((char *) m, sizeof *m);
492 	m->m_mno = NextMailer;
493 	m->m_eol = "\n";
494 
495 	/* collect the mailer name */
496 	for (p = line; *p != '\0' && *p != ',' && !isspace(*p); p++)
497 		continue;
498 	if (*p != '\0')
499 		*p++ = '\0';
500 	m->m_name = newstr(line);
501 
502 	/* now scan through and assign info from the fields */
503 	while (*p != '\0')
504 	{
505 		while (*p != '\0' && (*p == ',' || isspace(*p)))
506 			p++;
507 
508 		/* p now points to field code */
509 		fcode = *p;
510 		while (*p != '\0' && *p != '=' && *p != ',')
511 			p++;
512 		if (*p++ != '=')
513 		{
514 			syserr("mailer %s: `=' expected", m->m_name);
515 			return;
516 		}
517 		while (isspace(*p))
518 			p++;
519 
520 		/* p now points to the field body */
521 		p = munchstring(p);
522 
523 		/* install the field into the mailer struct */
524 		switch (fcode)
525 		{
526 		  case 'P':		/* pathname */
527 			m->m_mailer = newstr(p);
528 			break;
529 
530 		  case 'F':		/* flags */
531 			for (; *p != '\0'; p++)
532 				if (!isspace(*p))
533 					setbitn(*p, m->m_flags);
534 			break;
535 
536 		  case 'S':		/* sender rewriting ruleset */
537 		  case 'R':		/* recipient rewriting ruleset */
538 			i = atoi(p);
539 			if (i < 0 || i >= MAXRWSETS)
540 			{
541 				syserr("invalid rewrite set, %d max", MAXRWSETS);
542 				return;
543 			}
544 			if (fcode == 'S')
545 				m->m_s_rwset = i;
546 			else
547 				m->m_r_rwset = i;
548 			break;
549 
550 		  case 'E':		/* end of line string */
551 			m->m_eol = newstr(p);
552 			break;
553 
554 		  case 'A':		/* argument vector */
555 			m->m_argv = makeargv(p);
556 			break;
557 
558 		  case 'M':		/* maximum message size */
559 			m->m_maxsize = atol(p);
560 			break;
561 
562 		  case 'L':		/* maximum line length */
563 			m->m_linelimit = atoi(p);
564 			break;
565 		}
566 
567 		p = DelimChar;
568 	}
569 
570 	/* do some heuristic cleanup for back compatibility */
571 	if (bitnset(M_LIMITS, m->m_flags))
572 	{
573 		if (m->m_linelimit == 0)
574 			m->m_linelimit = SMTPLINELIM;
575 		if (!bitnset(M_8BITS, m->m_flags))
576 			setbitn(M_7BITS, m->m_flags);
577 	}
578 
579 	/* now store the mailer away */
580 	if (NextMailer >= MAXMAILERS)
581 	{
582 		syserr("too many mailers defined (%d max)", MAXMAILERS);
583 		return;
584 	}
585 	Mailer[NextMailer++] = m;
586 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
587 	s->s_mailer = m;
588 }
589 /*
590 **  MUNCHSTRING -- translate a string into internal form.
591 **
592 **	Parameters:
593 **		p -- the string to munch.
594 **
595 **	Returns:
596 **		the munched string.
597 **
598 **	Side Effects:
599 **		Sets "DelimChar" to point to the string that caused us
600 **		to stop.
601 */
602 
603 char *
604 munchstring(p)
605 	register char *p;
606 {
607 	register char *q;
608 	bool backslash = FALSE;
609 	bool quotemode = FALSE;
610 	static char buf[MAXLINE];
611 	extern char *DelimChar;
612 
613 	for (q = buf; *p != '\0'; p++)
614 	{
615 		if (backslash)
616 		{
617 			/* everything is roughly literal */
618 			backslash = FALSE;
619 			switch (*p)
620 			{
621 			  case 'r':		/* carriage return */
622 				*q++ = '\r';
623 				continue;
624 
625 			  case 'n':		/* newline */
626 				*q++ = '\n';
627 				continue;
628 
629 			  case 'f':		/* form feed */
630 				*q++ = '\f';
631 				continue;
632 
633 			  case 'b':		/* backspace */
634 				*q++ = '\b';
635 				continue;
636 			}
637 			*q++ = *p;
638 		}
639 		else
640 		{
641 			if (*p == '\\')
642 				backslash = TRUE;
643 			else if (*p == '"')
644 				quotemode = !quotemode;
645 			else if (quotemode || *p != ',')
646 				*q++ = *p;
647 			else
648 				break;
649 		}
650 	}
651 
652 	DelimChar = p;
653 	*q++ = '\0';
654 	return (buf);
655 }
656 /*
657 **  MAKEARGV -- break up a string into words
658 **
659 **	Parameters:
660 **		p -- the string to break up.
661 **
662 **	Returns:
663 **		a char **argv (dynamically allocated)
664 **
665 **	Side Effects:
666 **		munges p.
667 */
668 
669 char **
670 makeargv(p)
671 	register char *p;
672 {
673 	char *q;
674 	int i;
675 	char **avp;
676 	char *argv[MAXPV + 1];
677 
678 	/* take apart the words */
679 	i = 0;
680 	while (*p != '\0' && i < MAXPV)
681 	{
682 		q = p;
683 		while (*p != '\0' && !isspace(*p))
684 			p++;
685 		while (isspace(*p))
686 			*p++ = '\0';
687 		argv[i++] = newstr(q);
688 	}
689 	argv[i++] = NULL;
690 
691 	/* now make a copy of the argv */
692 	avp = (char **) xalloc(sizeof *avp * i);
693 	bcopy((char *) argv, (char *) avp, sizeof *avp * i);
694 
695 	return (avp);
696 }
697 /*
698 **  PRINTRULES -- print rewrite rules (for debugging)
699 **
700 **	Parameters:
701 **		none.
702 **
703 **	Returns:
704 **		none.
705 **
706 **	Side Effects:
707 **		prints rewrite rules.
708 */
709 
710 printrules()
711 {
712 	register struct rewrite *rwp;
713 	register int ruleset;
714 
715 	for (ruleset = 0; ruleset < 10; ruleset++)
716 	{
717 		if (RewriteRules[ruleset] == NULL)
718 			continue;
719 		printf("\n----Rule Set %d:", ruleset);
720 
721 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
722 		{
723 			printf("\nLHS:");
724 			printav(rwp->r_lhs);
725 			printf("RHS:");
726 			printav(rwp->r_rhs);
727 		}
728 	}
729 }
730 
731 /*
732 **  SETOPTION -- set global processing option
733 **
734 **	Parameters:
735 **		opt -- option name.
736 **		val -- option value (as a text string).
737 **		safe -- set if this came from a configuration file.
738 **			Some options (if set from the command line) will
739 **			reset the user id to avoid security problems.
740 **		sticky -- if set, don't let other setoptions override
741 **			this value.
742 **
743 **	Returns:
744 **		none.
745 **
746 **	Side Effects:
747 **		Sets options as implied by the arguments.
748 */
749 
750 static BITMAP	StickyOpt;		/* set if option is stuck */
751 
752 setoption(opt, val, safe, sticky)
753 	char opt;
754 	char *val;
755 	bool safe;
756 	bool sticky;
757 {
758 	extern bool atobool();
759 	extern time_t convtime();
760 	extern int QueueLA;
761 	extern int RefuseLA;
762 	extern bool trusteduser();
763 	extern char *username();
764 
765 	if (tTd(37, 1))
766 		printf("setoption %c=%s", opt, val);
767 
768 	/*
769 	**  See if this option is preset for us.
770 	*/
771 
772 	if (bitnset(opt, StickyOpt))
773 	{
774 		if (tTd(37, 1))
775 			printf(" (ignored)\n");
776 		return;
777 	}
778 
779 	/*
780 	**  Check to see if this option can be specified by this user.
781 	*/
782 
783 	if (!safe && getuid() == 0)
784 		safe = TRUE;
785 	if (!safe && index("deiLmorsvC", opt) == NULL)
786 	{
787 		if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
788 		{
789 			if (tTd(37, 1))
790 				printf(" (unsafe)");
791 			if (getuid() != geteuid())
792 			{
793 				if (tTd(37, 1))
794 					printf("(Resetting uid)");
795 				(void) setgid(getgid());
796 				(void) setuid(getuid());
797 			}
798 		}
799 	}
800 	if (tTd(37, 1))
801 		printf("\n");
802 
803 	switch (opt)
804 	{
805 	  case '=':		/* config file generation level */
806 		ConfigLevel = atoi(val);
807 		break;
808 
809 	  case '8':		/* allow eight-bit input */
810 		EightBit = atobool(val);
811 		break;
812 
813 	  case 'A':		/* set default alias file */
814 		if (val[0] == '\0')
815 			AliasFile = "aliases";
816 		else
817 			AliasFile = newstr(val);
818 		break;
819 
820 	  case 'a':		/* look N minutes for "@:@" in alias file */
821 		if (val[0] == '\0')
822 			SafeAlias = 5;
823 		else
824 			SafeAlias = atoi(val);
825 		break;
826 
827 	  case 'B':		/* substitution for blank character */
828 		SpaceSub = val[0];
829 		if (SpaceSub == '\0')
830 			SpaceSub = ' ';
831 		break;
832 
833 	  case 'c':		/* don't connect to "expensive" mailers */
834 		NoConnect = atobool(val);
835 		break;
836 
837 	  case 'C':		/* checkpoint every N addresses */
838 		CheckpointInterval = atoi(val);
839 		break;
840 
841 	  case 'd':		/* delivery mode */
842 		switch (*val)
843 		{
844 		  case '\0':
845 			SendMode = SM_DELIVER;
846 			break;
847 
848 		  case SM_QUEUE:	/* queue only */
849 #ifndef QUEUE
850 			syserr("need QUEUE to set -odqueue");
851 #endif QUEUE
852 			/* fall through..... */
853 
854 		  case SM_DELIVER:	/* do everything */
855 		  case SM_FORK:		/* fork after verification */
856 			SendMode = *val;
857 			break;
858 
859 		  default:
860 			syserr("Unknown delivery mode %c", *val);
861 			exit(EX_USAGE);
862 		}
863 		break;
864 
865 	  case 'D':		/* rebuild alias database as needed */
866 		AutoRebuild = atobool(val);
867 		break;
868 
869 	  case 'e':		/* set error processing mode */
870 		switch (*val)
871 		{
872 		  case EM_QUIET:	/* be silent about it */
873 		  case EM_MAIL:		/* mail back */
874 		  case EM_BERKNET:	/* do berknet error processing */
875 		  case EM_WRITE:	/* write back (or mail) */
876 			HoldErrs = TRUE;
877 			/* fall through... */
878 
879 		  case EM_PRINT:	/* print errors normally (default) */
880 			ErrorMode = *val;
881 			break;
882 		}
883 		break;
884 
885 	  case 'F':		/* file mode */
886 		FileMode = atooct(val) & 0777;
887 		break;
888 
889 	  case 'f':		/* save Unix-style From lines on front */
890 		SaveFrom = atobool(val);
891 		break;
892 
893 	  case 'G':		/* match recipients against GECOS field */
894 		MatchGecos = atobool(val);
895 		break;
896 
897 	  case 'g':		/* default gid */
898 		DefGid = atoi(val);
899 		break;
900 
901 	  case 'H':		/* help file */
902 		if (val[0] == '\0')
903 			HelpFile = "sendmail.hf";
904 		else
905 			HelpFile = newstr(val);
906 		break;
907 
908 	  case 'h':		/* maximum hop count */
909 		MaxHopCount = atoi(val);
910 		break;
911 
912 	  case 'I':		/* use internet domain name server */
913 		UseNameServer = atobool(val);
914 		break;
915 
916 	  case 'i':		/* ignore dot lines in message */
917 		IgnrDot = atobool(val);
918 		break;
919 
920 	  case 'k':		/* connection cache size */
921 		MaxMciCache = atoi(val);
922 		if (MaxMciCache <= 0)
923 			MaxMciCache = 1;
924 		break;
925 
926 	  case 'K':		/* connection cache timeout */
927 		MciCacheTimeout = convtime(val);
928 		break;
929 
930 	  case 'L':		/* log level */
931 		LogLevel = atoi(val);
932 		break;
933 
934 	  case 'M':		/* define macro */
935 		define(val[0], newstr(&val[1]), CurEnv);
936 		sticky = FALSE;
937 		break;
938 
939 	  case 'm':		/* send to me too */
940 		MeToo = atobool(val);
941 		break;
942 
943 	  case 'n':		/* validate RHS in newaliases */
944 		CheckAliases = atobool(val);
945 		break;
946 
947 	  case 'o':		/* assume old style headers */
948 		if (atobool(val))
949 			CurEnv->e_flags |= EF_OLDSTYLE;
950 		else
951 			CurEnv->e_flags &= ~EF_OLDSTYLE;
952 		break;
953 
954 	  case 'P':		/* postmaster copy address for returned mail */
955 		PostMasterCopy = newstr(val);
956 		break;
957 
958 	  case 'q':		/* slope of queue only function */
959 		QueueFactor = atoi(val);
960 		break;
961 
962 	  case 'Q':		/* queue directory */
963 		if (val[0] == '\0')
964 			QueueDir = "mqueue";
965 		else
966 			QueueDir = newstr(val);
967 		break;
968 
969 	  case 'r':		/* read timeout */
970 		ReadTimeout = convtime(val);
971 		break;
972 
973 	  case 'S':		/* status file */
974 		if (val[0] == '\0')
975 			StatFile = "sendmail.st";
976 		else
977 			StatFile = newstr(val);
978 		break;
979 
980 	  case 's':		/* be super safe, even if expensive */
981 		SuperSafe = atobool(val);
982 		break;
983 
984 	  case 'T':		/* queue timeout */
985 		TimeOut = convtime(val);
986 		break;
987 
988 	  case 't':		/* time zone name */
989 		TimeZoneSpec = newstr(val);
990 		break;
991 
992 	  case 'U':		/* location of user database */
993 		UdbSpec = newstr(val);
994 		break;
995 
996 	  case 'u':		/* set default uid */
997 		DefUid = atoi(val);
998 		setdefuser();
999 		break;
1000 
1001 	  case 'v':		/* run in verbose mode */
1002 		Verbose = atobool(val);
1003 		break;
1004 
1005 	  case 'w':		/* we don't have wildcard MX records */
1006 		NoWildcardMX = atobool(val);
1007 		break;
1008 
1009 	  case 'x':		/* load avg at which to auto-queue msgs */
1010 		QueueLA = atoi(val);
1011 		break;
1012 
1013 	  case 'X':		/* load avg at which to auto-reject connections */
1014 		RefuseLA = atoi(val);
1015 		break;
1016 
1017 	  case 'y':		/* work recipient factor */
1018 		WkRecipFact = atoi(val);
1019 		break;
1020 
1021 	  case 'Y':		/* fork jobs during queue runs */
1022 		ForkQueueRuns = atobool(val);
1023 		break;
1024 
1025 	  case 'z':		/* work message class factor */
1026 		WkClassFact = atoi(val);
1027 		break;
1028 
1029 	  case 'Z':		/* work time factor */
1030 		WkTimeFact = atoi(val);
1031 		break;
1032 
1033 	  default:
1034 		break;
1035 	}
1036 	if (sticky)
1037 		setbitn(opt, StickyOpt);
1038 	return;
1039 }
1040 /*
1041 **  SETCLASS -- set a word into a class
1042 **
1043 **	Parameters:
1044 **		class -- the class to put the word in.
1045 **		word -- the word to enter
1046 **
1047 **	Returns:
1048 **		none.
1049 **
1050 **	Side Effects:
1051 **		puts the word into the symbol table.
1052 */
1053 
1054 setclass(class, word)
1055 	int class;
1056 	char *word;
1057 {
1058 	register STAB *s;
1059 
1060 	s = stab(word, ST_CLASS, ST_ENTER);
1061 	setbitn(class, s->s_class);
1062 }
1063 /*
1064 **  MAKEMAPENTRY -- create a map entry
1065 **
1066 **	Parameters:
1067 **		line -- the config file line
1068 **
1069 **	Returns:
1070 **		TRUE if it successfully entered the map entry.
1071 **		FALSE otherwise (usually syntax error).
1072 **
1073 **	Side Effects:
1074 **		Enters the map into the dictionary.
1075 */
1076 
1077 void
1078 makemapentry(line)
1079 	char *line;
1080 {
1081 	register char *p;
1082 	char *mapname;
1083 	char *classname;
1084 	register STAB *map;
1085 	STAB *class;
1086 
1087 	for (p = line; isspace(*p); p++)
1088 		continue;
1089 	if (!isalnum(*p))
1090 	{
1091 		syserr("readcf: config K line: no map name");
1092 		return;
1093 	}
1094 
1095 	mapname = p;
1096 	while (isalnum(*++p))
1097 		continue;
1098 	if (*p != '\0')
1099 		*p++ = '\0';
1100 	while (isspace(*p))
1101 		p++;
1102 	if (!isalnum(*p))
1103 	{
1104 		syserr("readcf: config K line, map %s: no map class", mapname);
1105 		return;
1106 	}
1107 	classname = p;
1108 	while (isalnum(*++p))
1109 		continue;
1110 	if (*p != '\0')
1111 		*p++ = '\0';
1112 	while (isspace(*p))
1113 		p++;
1114 
1115 	/* look up the class */
1116 	class = stab(classname, ST_MAPCLASS, ST_FIND);
1117 	if (class == NULL)
1118 	{
1119 		syserr("readcf: map %s: class %s not available", mapname, classname);
1120 		return;
1121 	}
1122 
1123 	/* enter the map */
1124 	map = stab(mapname, ST_MAP, ST_ENTER);
1125 	map->s_map.map_class = &class->s_mapclass;
1126 
1127 	if ((*class->s_mapclass.map_init)(&map->s_map, p))
1128 		map->s_map.map_flags |= MF_VALID;
1129 }
1130