xref: /illumos-gate/usr/src/cmd/sendmail/src/readcf.c (revision 058561cb)
1 /*
2  * Copyright (c) 1998-2006 Sendmail, Inc. and its suppliers.
3  *	All rights reserved.
4  * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
5  * Copyright (c) 1988, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * By using this file, you agree to the terms and conditions set
9  * forth in the LICENSE file which can be found at the top level of
10  * the sendmail distribution.
11  *
12  */
13 
14 #pragma ident	"%Z%%M%	%I%	%E% SMI"
15 
16 #include <sendmail.h>
17 #include <sm/sendmail.h>
18 
19 SM_RCSID("@(#)$Id: readcf.c,v 8.663 2006/10/05 20:58:59 ca Exp $")
20 
21 #if NETINET || NETINET6
22 # include <arpa/inet.h>
23 #endif /* NETINET || NETINET6 */
24 
25 #define SECONDS
26 #define MINUTES	* 60
27 #define HOUR	* 3600
28 #define HOURS	HOUR
29 
30 static void	fileclass __P((int, char *, char *, bool, bool, bool));
31 static char	**makeargv __P((char *));
32 static void	settimeout __P((char *, char *, bool));
33 static void	toomany __P((int, int));
34 static char	*extrquotstr __P((char *, char **, char *, bool *));
35 static void	parse_class_words __P((int, char *));
36 
37 /*
38 **  READCF -- read configuration file.
39 **
40 **	This routine reads the configuration file and builds the internal
41 **	form.
42 **
43 **	The file is formatted as a sequence of lines, each taken
44 **	atomically.  The first character of each line describes how
45 **	the line is to be interpreted.  The lines are:
46 **		Dxval		Define macro x to have value val.
47 **		Cxword		Put word into class x.
48 **		Fxfile [fmt]	Read file for lines to put into
49 **				class x.  Use scanf string 'fmt'
50 **				or "%s" if not present.  Fmt should
51 **				only produce one string-valued result.
52 **		Hname: value	Define header with field-name 'name'
53 **				and value as specified; this will be
54 **				macro expanded immediately before
55 **				use.
56 **		Sn		Use rewriting set n.
57 **		Rlhs rhs	Rewrite addresses that match lhs to
58 **				be rhs.
59 **		Mn arg=val...	Define mailer.  n is the internal name.
60 **				Args specify mailer parameters.
61 **		Oxvalue		Set option x to value.
62 **		O option value	Set option (long name) to value.
63 **		Pname=value	Set precedence name to value.
64 **		Qn arg=val...	Define queue groups.  n is the internal name.
65 **				Args specify queue parameters.
66 **		Vversioncode[/vendorcode]
67 **				Version level/vendor name of
68 **				configuration syntax.
69 **		Kmapname mapclass arguments....
70 **				Define keyed lookup of a given class.
71 **				Arguments are class dependent.
72 **		Eenvar=value	Set the environment value to the given value.
73 **
74 **	Parameters:
75 **		cfname -- configuration file name.
76 **		safe -- true if this is the system config file;
77 **			false otherwise.
78 **		e -- the main envelope.
79 **
80 **	Returns:
81 **		none.
82 **
83 **	Side Effects:
84 **		Builds several internal tables.
85 */
86 
87 void
88 readcf(cfname, safe, e)
89 	char *cfname;
90 	bool safe;
91 	register ENVELOPE *e;
92 {
93 	SM_FILE_T *cf;
94 	int ruleset = -1;
95 	char *q;
96 	struct rewrite *rwp = NULL;
97 	char *bp;
98 	auto char *ep;
99 	int nfuzzy;
100 	char *file;
101 	bool optional;
102 	bool ok;
103 	bool ismap;
104 	int mid;
105 	register char *p;
106 	long sff = SFF_OPENASROOT;
107 	struct stat statb;
108 	char buf[MAXLINE];
109 	int bufsize;
110 	char exbuf[MAXLINE];
111 	char pvpbuf[MAXLINE + MAXATOM];
112 	static char *null_list[1] = { NULL };
113 	extern unsigned char TokTypeNoC[];
114 
115 	FileName = cfname;
116 	LineNumber = 0;
117 
118 	if (DontLockReadFiles)
119 		sff |= SFF_NOLOCK;
120 	cf = safefopen(cfname, O_RDONLY, 0444, sff);
121 	if (cf == NULL)
122 	{
123 		syserr("cannot open");
124 		finis(false, true, EX_OSFILE);
125 	}
126 
127 	if (fstat(sm_io_getinfo(cf, SM_IO_WHAT_FD, NULL), &statb) < 0)
128 	{
129 		syserr("cannot fstat");
130 		finis(false, true, EX_OSFILE);
131 	}
132 
133 	if (!S_ISREG(statb.st_mode))
134 	{
135 		syserr("not a plain file");
136 		finis(false, true, EX_OSFILE);
137 	}
138 
139 	if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
140 	{
141 		if (OpMode == MD_DAEMON || OpMode == MD_INITALIAS)
142 			(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
143 					     "%s: WARNING: dangerous write permissions\n",
144 					     FileName);
145 		if (LogLevel > 0)
146 			sm_syslog(LOG_CRIT, NOQID,
147 				  "%s: WARNING: dangerous write permissions",
148 				  FileName);
149 	}
150 
151 #if XLA
152 	xla_zero();
153 #endif /* XLA */
154 
155 	while (bufsize = sizeof(buf),
156 	       (bp = fgetfolded(buf, &bufsize, cf)) != NULL)
157 	{
158 		char *nbp;
159 
160 		if (bp[0] == '#')
161 		{
162 			if (bp != buf)
163 				sm_free(bp); /* XXX */
164 			continue;
165 		}
166 
167 		/* do macro expansion mappings */
168 		nbp = translate_dollars(bp, bp, &bufsize);
169 		if (nbp != bp && bp != buf)
170 			sm_free(bp);
171 		bp = nbp;
172 
173 		/* interpret this line */
174 		errno = 0;
175 		switch (bp[0])
176 		{
177 		  case '\0':
178 		  case '#':		/* comment */
179 			break;
180 
181 		  case 'R':		/* rewriting rule */
182 			if (ruleset < 0)
183 			{
184 				syserr("missing valid ruleset for \"%s\"", bp);
185 				break;
186 			}
187 			for (p = &bp[1]; *p != '\0' && *p != '\t'; p++)
188 				continue;
189 
190 			if (*p == '\0')
191 			{
192 				syserr("invalid rewrite line \"%s\" (tab expected)", bp);
193 				break;
194 			}
195 
196 			/* allocate space for the rule header */
197 			if (rwp == NULL)
198 			{
199 				RewriteRules[ruleset] = rwp =
200 					(struct rewrite *) xalloc(sizeof(*rwp));
201 			}
202 			else
203 			{
204 				rwp->r_next = (struct rewrite *) xalloc(sizeof(*rwp));
205 				rwp = rwp->r_next;
206 			}
207 			rwp->r_next = NULL;
208 
209 			/* expand and save the LHS */
210 			*p = '\0';
211 			expand(&bp[1], exbuf, sizeof(exbuf), e);
212 			rwp->r_lhs = prescan(exbuf, '\t', pvpbuf,
213 					     sizeof(pvpbuf), NULL,
214 					     ConfigLevel >= 9 ? TokTypeNoC : IntTokenTab,
215 					     true);
216 			nfuzzy = 0;
217 			if (rwp->r_lhs != NULL)
218 			{
219 				register char **ap;
220 
221 				rwp->r_lhs = copyplist(rwp->r_lhs, true, NULL);
222 
223 				/* count the number of fuzzy matches in LHS */
224 				for (ap = rwp->r_lhs; *ap != NULL; ap++)
225 				{
226 					char *botch;
227 
228 					botch = NULL;
229 					switch (ap[0][0] & 0377)
230 					{
231 					  case MATCHZANY:
232 					  case MATCHANY:
233 					  case MATCHONE:
234 					  case MATCHCLASS:
235 					  case MATCHNCLASS:
236 						nfuzzy++;
237 						break;
238 
239 					  case MATCHREPL:
240 						botch = "$1-$9";
241 						break;
242 
243 					  case CANONUSER:
244 						botch = "$:";
245 						break;
246 
247 					  case CALLSUBR:
248 						botch = "$>";
249 						break;
250 
251 					  case CONDIF:
252 						botch = "$?";
253 						break;
254 
255 					  case CONDFI:
256 						botch = "$.";
257 						break;
258 
259 					  case HOSTBEGIN:
260 						botch = "$[";
261 						break;
262 
263 					  case HOSTEND:
264 						botch = "$]";
265 						break;
266 
267 					  case LOOKUPBEGIN:
268 						botch = "$(";
269 						break;
270 
271 					  case LOOKUPEND:
272 						botch = "$)";
273 						break;
274 					}
275 					if (botch != NULL)
276 						syserr("Inappropriate use of %s on LHS",
277 							botch);
278 				}
279 				rwp->r_line = LineNumber;
280 			}
281 			else
282 			{
283 				syserr("R line: null LHS");
284 				rwp->r_lhs = null_list;
285 			}
286 			if (nfuzzy > MAXMATCH)
287 			{
288 				syserr("R line: too many wildcards");
289 				rwp->r_lhs = null_list;
290 			}
291 
292 			/* expand and save the RHS */
293 			while (*++p == '\t')
294 				continue;
295 			q = p;
296 			while (*p != '\0' && *p != '\t')
297 				p++;
298 			*p = '\0';
299 			expand(q, exbuf, sizeof(exbuf), e);
300 			rwp->r_rhs = prescan(exbuf, '\t', pvpbuf,
301 					     sizeof(pvpbuf), NULL,
302 					     ConfigLevel >= 9 ? TokTypeNoC : IntTokenTab,
303 					     true);
304 			if (rwp->r_rhs != NULL)
305 			{
306 				register char **ap;
307 				int args, endtoken;
308 #if _FFR_EXTRA_MAP_CHECK
309 				int nexttoken;
310 #endif /* _FFR_EXTRA_MAP_CHECK */
311 				bool inmap;
312 
313 				rwp->r_rhs = copyplist(rwp->r_rhs, true, NULL);
314 
315 				/* check no out-of-bounds replacements */
316 				nfuzzy += '0';
317 				inmap = false;
318 				args = 0;
319 				endtoken = 0;
320 				for (ap = rwp->r_rhs; *ap != NULL; ap++)
321 				{
322 					char *botch;
323 
324 					botch = NULL;
325 					switch (ap[0][0] & 0377)
326 					{
327 					  case MATCHREPL:
328 						if (ap[0][1] <= '0' ||
329 						    ap[0][1] > nfuzzy)
330 						{
331 							syserr("replacement $%c out of bounds",
332 								ap[0][1]);
333 						}
334 						break;
335 
336 					  case MATCHZANY:
337 						botch = "$*";
338 						break;
339 
340 					  case MATCHANY:
341 						botch = "$+";
342 						break;
343 
344 					  case MATCHONE:
345 						botch = "$-";
346 						break;
347 
348 					  case MATCHCLASS:
349 						botch = "$=";
350 						break;
351 
352 					  case MATCHNCLASS:
353 						botch = "$~";
354 						break;
355 
356 					  case CANONHOST:
357 						if (!inmap)
358 							break;
359 						if (++args >= MAX_MAP_ARGS)
360 							syserr("too many arguments for map lookup");
361 						break;
362 
363 					  case HOSTBEGIN:
364 						endtoken = HOSTEND;
365 						/* FALLTHROUGH */
366 					  case LOOKUPBEGIN:
367 						/* see above... */
368 						if ((ap[0][0] & 0377) == LOOKUPBEGIN)
369 							endtoken = LOOKUPEND;
370 						if (inmap)
371 							syserr("cannot nest map lookups");
372 						inmap = true;
373 						args = 0;
374 #if _FFR_EXTRA_MAP_CHECK
375 						if (ap[1] == NULL)
376 						{
377 							syserr("syntax error in map lookup");
378 							break;
379 						}
380 						nexttoken = ap[1][0] & 0377;
381 						if (nexttoken == CANONHOST ||
382 						    nexttoken == CANONUSER ||
383 						    nexttoken == endtoken))
384 						{
385 							syserr("missing map name for lookup");
386 							break;
387 						}
388 						if (ap[2] == NULL)
389 						{
390 							syserr("syntax error in map lookup");
391 							break;
392 						}
393 						if (ap[0][0] == HOSTBEGIN)
394 							break;
395 						nexttoken = ap[2][0] & 0377;
396 						if (nexttoken == CANONHOST ||
397 						    nexttoken == CANONUSER ||
398 						    nexttoken == endtoken)
399 						{
400 							syserr("missing key name for lookup");
401 							break;
402 						}
403 #endif /* _FFR_EXTRA_MAP_CHECK */
404 						break;
405 
406 					  case HOSTEND:
407 					  case LOOKUPEND:
408 						if ((ap[0][0] & 0377) != endtoken)
409 							break;
410 						inmap = false;
411 						endtoken = 0;
412 						break;
413 
414 
415 #if 0
416 /*
417 **  This doesn't work yet as there are maps defined *after* the cf
418 **  is read such as host, user, and alias.  So for now, it's removed.
419 **  When it comes back, the RELEASE_NOTES entry will be:
420 **	Emit warnings for unknown maps when reading the .cf file.  Based on
421 **		patch from Robert Harker of Harker Systems.
422 */
423 
424 					  case LOOKUPBEGIN:
425 						/*
426 						**  Got a database lookup,
427 						**  check if map is defined.
428 						*/
429 
430 						ep = ap[1];
431 						if ((ep[0] & 0377) != MACRODEXPAND &&
432 						    stab(ep, ST_MAP, ST_FIND) == NULL)
433 						{
434 							(void) sm_io_fprintf(smioout,
435 									     SM_TIME_DEFAULT,
436 									     "Warning: %s: line %d: map %s not found\n",
437 									     FileName,
438 									     LineNumber,
439 									     ep);
440 						}
441 						break;
442 #endif /* 0 */
443 					}
444 					if (botch != NULL)
445 						syserr("Inappropriate use of %s on RHS",
446 							botch);
447 				}
448 				if (inmap)
449 					syserr("missing map closing token");
450 			}
451 			else
452 			{
453 				syserr("R line: null RHS");
454 				rwp->r_rhs = null_list;
455 			}
456 			break;
457 
458 		  case 'S':		/* select rewriting set */
459 			expand(&bp[1], exbuf, sizeof(exbuf), e);
460 			ruleset = strtorwset(exbuf, NULL, ST_ENTER);
461 			if (ruleset < 0)
462 				break;
463 
464 			rwp = RewriteRules[ruleset];
465 			if (rwp != NULL)
466 			{
467 				if (OpMode == MD_TEST)
468 					(void) sm_io_fprintf(smioout,
469 							     SM_TIME_DEFAULT,
470 							     "WARNING: Ruleset %s has multiple definitions\n",
471 							    &bp[1]);
472 				if (tTd(37, 1))
473 					sm_dprintf("WARNING: Ruleset %s has multiple definitions\n",
474 						   &bp[1]);
475 				while (rwp->r_next != NULL)
476 					rwp = rwp->r_next;
477 			}
478 			break;
479 
480 		  case 'D':		/* macro definition */
481 			mid = macid_parse(&bp[1], &ep);
482 			if (mid == 0)
483 				break;
484 			p = munchstring(ep, NULL, '\0');
485 			macdefine(&e->e_macro, A_TEMP, mid, p);
486 			break;
487 
488 		  case 'H':		/* required header line */
489 			(void) chompheader(&bp[1], CHHDR_DEF, NULL, e);
490 			break;
491 
492 		  case 'C':		/* word class */
493 		  case 'T':		/* trusted user (set class `t') */
494 			if (bp[0] == 'C')
495 			{
496 				mid = macid_parse(&bp[1], &ep);
497 				if (mid == 0)
498 					break;
499 				expand(ep, exbuf, sizeof(exbuf), e);
500 				p = exbuf;
501 			}
502 			else
503 			{
504 				mid = 't';
505 				p = &bp[1];
506 			}
507 			while (*p != '\0')
508 			{
509 				register char *wd;
510 				char delim;
511 
512 				while (*p != '\0' && isascii(*p) && isspace(*p))
513 					p++;
514 				wd = p;
515 				while (*p != '\0' && !(isascii(*p) && isspace(*p)))
516 					p++;
517 				delim = *p;
518 				*p = '\0';
519 				if (wd[0] != '\0')
520 					setclass(mid, wd);
521 				*p = delim;
522 			}
523 			break;
524 
525 		  case 'F':		/* word class from file */
526 			mid = macid_parse(&bp[1], &ep);
527 			if (mid == 0)
528 				break;
529 			for (p = ep; isascii(*p) && isspace(*p); )
530 				p++;
531 			if (p[0] == '-' && p[1] == 'o')
532 			{
533 				optional = true;
534 				while (*p != '\0' &&
535 				       !(isascii(*p) && isspace(*p)))
536 					p++;
537 				while (isascii(*p) && isspace(*p))
538 					p++;
539 				file = p;
540 			}
541 			else
542 				optional = false;
543 
544 			/* check if [key]@map:spec */
545 			ismap = false;
546 			if (!SM_IS_DIR_DELIM(*p) &&
547 			    *p != '|' &&
548 			    (q = strchr(p, '@')) != NULL)
549 			{
550 				q++;
551 
552 				/* look for @LDAP or @map: in string */
553 				if (strcmp(q, "LDAP") == 0 ||
554 				    (*q != ':' &&
555 				     strchr(q, ':') != NULL))
556 					ismap = true;
557 			}
558 
559 			if (ismap)
560 			{
561 				/* use entire spec */
562 				file = p;
563 			}
564 			else
565 			{
566 				file = extrquotstr(p, &q, " ", &ok);
567 				if (!ok)
568 				{
569 					syserr("illegal filename '%s'", p);
570 					break;
571 				}
572 			}
573 
574 			if (*file == '|' || ismap)
575 				p = "%s";
576 			else
577 			{
578 				p = q;
579 				if (*p == '\0')
580 					p = "%s";
581 				else
582 				{
583 					*p = '\0';
584 					while (isascii(*++p) && isspace(*p))
585 						continue;
586 				}
587 			}
588 			fileclass(mid, file, p, ismap, safe, optional);
589 			break;
590 
591 #if XLA
592 		  case 'L':		/* extended load average description */
593 			xla_init(&bp[1]);
594 			break;
595 #endif /* XLA */
596 
597 #if defined(SUN_EXTENSIONS) && defined(SUN_LOOKUP_MACRO)
598 		  case 'L':		/* lookup macro */
599 		  case 'G':		/* lookup class */
600 			/* reserved for Sun -- NIS+ database lookup */
601 			if (VendorCode != VENDOR_SUN)
602 				goto badline;
603 			sun_lg_config_line(bp, e);
604 			break;
605 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_LOOKUP_MACRO) */
606 
607 		  case 'M':		/* define mailer */
608 			makemailer(&bp[1]);
609 			break;
610 
611 		  case 'O':		/* set option */
612 			setoption(bp[1], &bp[2], safe, false, e);
613 			break;
614 
615 		  case 'P':		/* set precedence */
616 			if (NumPriorities >= MAXPRIORITIES)
617 			{
618 				toomany('P', MAXPRIORITIES);
619 				break;
620 			}
621 			for (p = &bp[1]; *p != '\0' && *p != '='; p++)
622 				continue;
623 			if (*p == '\0')
624 				goto badline;
625 			*p = '\0';
626 			Priorities[NumPriorities].pri_name = newstr(&bp[1]);
627 			Priorities[NumPriorities].pri_val = atoi(++p);
628 			NumPriorities++;
629 			break;
630 
631 		  case 'Q':		/* define queue */
632 			makequeue(&bp[1], true);
633 			break;
634 
635 		  case 'V':		/* configuration syntax version */
636 			for (p = &bp[1]; isascii(*p) && isspace(*p); p++)
637 				continue;
638 			if (!isascii(*p) || !isdigit(*p))
639 			{
640 				syserr("invalid argument to V line: \"%.20s\"",
641 					&bp[1]);
642 				break;
643 			}
644 			ConfigLevel = strtol(p, &ep, 10);
645 
646 			/*
647 			**  Do heuristic tweaking for back compatibility.
648 			*/
649 
650 			if (ConfigLevel >= 5)
651 			{
652 				/* level 5 configs have short name in $w */
653 				p = macvalue('w', e);
654 				if (p != NULL && (p = strchr(p, '.')) != NULL)
655 				{
656 					*p = '\0';
657 					macdefine(&e->e_macro, A_TEMP, 'w',
658 						  macvalue('w', e));
659 				}
660 			}
661 			if (ConfigLevel >= 6)
662 			{
663 				ColonOkInAddr = false;
664 			}
665 
666 			/*
667 			**  Look for vendor code.
668 			*/
669 
670 			if (*ep++ == '/')
671 			{
672 				/* extract vendor code */
673 				for (p = ep; isascii(*p) && isalpha(*p); )
674 					p++;
675 				*p = '\0';
676 
677 				if (!setvendor(ep))
678 					syserr("invalid V line vendor code: \"%s\"",
679 						ep);
680 			}
681 			break;
682 
683 		  case 'K':
684 			expand(&bp[1], exbuf, sizeof(exbuf), e);
685 			(void) makemapentry(exbuf);
686 			break;
687 
688 		  case 'E':
689 			p = strchr(bp, '=');
690 			if (p != NULL)
691 				*p++ = '\0';
692 			sm_setuserenv(&bp[1], p);
693 			break;
694 
695 		  case 'X':		/* mail filter */
696 #if MILTER
697 			milter_setup(&bp[1]);
698 #else /* MILTER */
699 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
700 					     "Warning: Filter usage ('X') requires Milter support (-DMILTER)\n");
701 #endif /* MILTER */
702 			break;
703 
704 		  default:
705 		  badline:
706 			syserr("unknown configuration line \"%s\"", bp);
707 		}
708 		if (bp != buf)
709 			sm_free(bp); /* XXX */
710 	}
711 	if (sm_io_error(cf))
712 	{
713 		syserr("I/O read error");
714 		finis(false, true, EX_OSFILE);
715 	}
716 	(void) sm_io_close(cf, SM_TIME_DEFAULT);
717 	FileName = NULL;
718 
719 	/* initialize host maps from local service tables */
720 	inithostmaps();
721 
722 	/* initialize daemon (if not defined yet) */
723 	initdaemon();
724 
725 	/* determine if we need to do special name-server frotz */
726 	{
727 		int nmaps;
728 		char *maptype[MAXMAPSTACK];
729 		short mapreturn[MAXMAPACTIONS];
730 
731 		nmaps = switch_map_find("hosts", maptype, mapreturn);
732 		UseNameServer = false;
733 		if (nmaps > 0 && nmaps <= MAXMAPSTACK)
734 		{
735 			register int mapno;
736 
737 			for (mapno = 0; mapno < nmaps && !UseNameServer;
738 			     mapno++)
739 			{
740 				if (strcmp(maptype[mapno], "dns") == 0)
741 					UseNameServer = true;
742 			}
743 		}
744 	}
745 }
746 
747 /*
748 **  TRANSLATE_DOLLARS -- convert $x into internal form
749 **
750 **	Actually does all appropriate pre-processing of a config line
751 **	to turn it into internal form.
752 **
753 **	Parameters:
754 **		ibp -- the buffer to translate.
755 **		obp -- where to put the translation; may be the same as obp
756 **		bsp -- a pointer to the size of obp; will be updated if
757 **			the buffer needs to be replaced.
758 **
759 **	Returns:
760 **		The buffer pointer; may differ from obp if the expansion
761 **		is larger then *bsp, in which case this will point to
762 **		malloc()ed memory which must be free()d by the caller.
763 */
764 
765 char *
766 translate_dollars(ibp, obp, bsp)
767 	char *ibp;
768 	char *obp;
769 	int *bsp;
770 {
771 	register char *p;
772 	auto char *ep;
773 	char *bp;
774 
775 	if (tTd(37, 53))
776 	{
777 		sm_dprintf("translate_dollars(");
778 		xputs(sm_debug_file(), ibp);
779 		sm_dprintf(")\n");
780 	}
781 
782 	bp = quote_internal_chars(ibp, obp, bsp);
783 
784 	for (p = bp; *p != '\0'; p++)
785 	{
786 		if (*p == '#' && p > bp && ConfigLevel >= 3)
787 		{
788 			register char *e;
789 
790 			switch (*--p & 0377)
791 			{
792 			  case MACROEXPAND:
793 				/* it's from $# -- let it go through */
794 				p++;
795 				break;
796 
797 			  case '\\':
798 				/* it's backslash escaped */
799 				(void) sm_strlcpy(p, p + 1, strlen(p));
800 				break;
801 
802 			  default:
803 				/* delete leading white space */
804 				while (isascii(*p) && isspace(*p) &&
805 				       *p != '\n' && p > bp)
806 				{
807 					p--;
808 				}
809 				if ((e = strchr(++p, '\n')) != NULL)
810 					(void) sm_strlcpy(p, e, strlen(p));
811 				else
812 					*p-- = '\0';
813 				break;
814 			}
815 			continue;
816 		}
817 
818 		if (*p != '$' || p[1] == '\0')
819 			continue;
820 
821 		if (p[1] == '$')
822 		{
823 			/* actual dollar sign.... */
824 			(void) sm_strlcpy(p, p + 1, strlen(p));
825 			continue;
826 		}
827 
828 		/* convert to macro expansion character */
829 		*p++ = MACROEXPAND;
830 
831 		/* special handling for $=, $~, $&, and $? */
832 		if (*p == '=' || *p == '~' || *p == '&' || *p == '?')
833 			p++;
834 
835 		/* convert macro name to code */
836 		*p = macid_parse(p, &ep);
837 		if (ep != p + 1)
838 			(void) sm_strlcpy(p + 1, ep, strlen(p + 1));
839 	}
840 
841 	/* strip trailing white space from the line */
842 	while (--p > bp && isascii(*p) && isspace(*p))
843 		*p = '\0';
844 
845 	if (tTd(37, 53))
846 	{
847 		sm_dprintf("  translate_dollars => ");
848 		xputs(sm_debug_file(), bp);
849 		sm_dprintf("\n");
850 	}
851 
852 	return bp;
853 }
854 /*
855 **  TOOMANY -- signal too many of some option
856 **
857 **	Parameters:
858 **		id -- the id of the error line
859 **		maxcnt -- the maximum possible values
860 **
861 **	Returns:
862 **		none.
863 **
864 **	Side Effects:
865 **		gives a syserr.
866 */
867 
868 static void
869 toomany(id, maxcnt)
870 	int id;
871 	int maxcnt;
872 {
873 	syserr("too many %c lines, %d max", id, maxcnt);
874 }
875 /*
876 **  FILECLASS -- read members of a class from a file
877 **
878 **	Parameters:
879 **		class -- class to define.
880 **		filename -- name of file to read.
881 **		fmt -- scanf string to use for match.
882 **		ismap -- if set, this is a map lookup.
883 **		safe -- if set, this is a safe read.
884 **		optional -- if set, it is not an error for the file to
885 **			not exist.
886 **
887 **	Returns:
888 **		none
889 **
890 **	Side Effects:
891 **		puts all lines in filename that match a scanf into
892 **			the named class.
893 */
894 
895 /*
896 **  Break up the match into words and add to class.
897 */
898 
899 static void
900 parse_class_words(class, line)
901 	int class;
902 	char *line;
903 {
904 	while (line != NULL && *line != '\0')
905 	{
906 		register char *q;
907 
908 		/* strip leading spaces */
909 		while (isascii(*line) && isspace(*line))
910 			line++;
911 		if (*line == '\0')
912 			break;
913 
914 		/* find the end of the word */
915 		q = line;
916 		while (*line != '\0' && !(isascii(*line) && isspace(*line)))
917 			line++;
918 		if (*line != '\0')
919 			*line++ = '\0';
920 
921 		/* enter the word in the symbol table */
922 		setclass(class, q);
923 	}
924 }
925 
926 static void
927 fileclass(class, filename, fmt, ismap, safe, optional)
928 	int class;
929 	char *filename;
930 	char *fmt;
931 	bool ismap;
932 	bool safe;
933 	bool optional;
934 {
935 	SM_FILE_T *f;
936 	long sff;
937 	pid_t pid;
938 	register char *p;
939 	char buf[MAXLINE];
940 
941 	if (tTd(37, 2))
942 		sm_dprintf("fileclass(%s, fmt=%s)\n", filename, fmt);
943 
944 	if (*filename == '\0')
945 	{
946 		syserr("fileclass: missing file name");
947 		return;
948 	}
949 	else if (ismap)
950 	{
951 		int status = 0;
952 		char *key;
953 		char *mn;
954 		char *cl, *spec;
955 		STAB *mapclass;
956 		MAP map;
957 
958 		mn = newstr(macname(class));
959 
960 		key = filename;
961 
962 		/* skip past key */
963 		if ((p = strchr(filename, '@')) == NULL)
964 		{
965 			/* should not happen */
966 			syserr("fileclass: bogus map specification");
967 			sm_free(mn);
968 			return;
969 		}
970 
971 		/* skip past '@' */
972 		*p++ = '\0';
973 		cl = p;
974 
975 #if LDAPMAP
976 		if (strcmp(cl, "LDAP") == 0)
977 		{
978 			int n;
979 			char *lc;
980 			char jbuf[MAXHOSTNAMELEN];
981 			char lcbuf[MAXLINE];
982 
983 			/* Get $j */
984 			expand("\201j", jbuf, sizeof(jbuf), &BlankEnvelope);
985 			if (jbuf[0] == '\0')
986 			{
987 				(void) sm_strlcpy(jbuf, "localhost",
988 						  sizeof(jbuf));
989 			}
990 
991 			/* impose the default schema */
992 			lc = macvalue(macid("{sendmailMTACluster}"), CurEnv);
993 			if (lc == NULL)
994 				lc = "";
995 			else
996 			{
997 				expand(lc, lcbuf, sizeof(lcbuf), CurEnv);
998 				lc = lcbuf;
999 			}
1000 
1001 			cl = "ldap";
1002 			n = sm_snprintf(buf, sizeof(buf),
1003 					"-k (&(objectClass=sendmailMTAClass)(sendmailMTAClassName=%s)(|(sendmailMTACluster=%s)(sendmailMTAHost=%s))) -v sendmailMTAClassValue,sendmailMTAClassSearch:FILTER:sendmailMTAClass,sendmailMTAClassURL:URL:sendmailMTAClass",
1004 					mn, lc, jbuf);
1005 			if (n >= sizeof(buf))
1006 			{
1007 				syserr("fileclass: F{%s}: Default LDAP string too long",
1008 				       mn);
1009 				sm_free(mn);
1010 				return;
1011 			}
1012 			spec = buf;
1013 		}
1014 		else
1015 #endif /* LDAPMAP */
1016 		{
1017 			if ((spec = strchr(cl, ':')) == NULL)
1018 			{
1019 				syserr("fileclass: F{%s}: missing map class",
1020 				       mn);
1021 				sm_free(mn);
1022 				return;
1023 			}
1024 			*spec++ ='\0';
1025 		}
1026 
1027 		/* set up map structure */
1028 		mapclass = stab(cl, ST_MAPCLASS, ST_FIND);
1029 		if (mapclass == NULL)
1030 		{
1031 			syserr("fileclass: F{%s}: class %s not available",
1032 			       mn, cl);
1033 			sm_free(mn);
1034 			return;
1035 		}
1036 		memset(&map, '\0', sizeof(map));
1037 		map.map_class = &mapclass->s_mapclass;
1038 		map.map_mname = mn;
1039 		map.map_mflags |= MF_FILECLASS;
1040 
1041 		if (tTd(37, 5))
1042 			sm_dprintf("fileclass: F{%s}: map class %s, key %s, spec %s\n",
1043 				   mn, cl, key, spec);
1044 
1045 
1046 		/* parse map spec */
1047 		if (!map.map_class->map_parse(&map, spec))
1048 		{
1049 			/* map_parse() showed the error already */
1050 			sm_free(mn);
1051 			return;
1052 		}
1053 		map.map_mflags |= MF_VALID;
1054 
1055 		/* open map */
1056 		if (map.map_class->map_open(&map, O_RDONLY))
1057 		{
1058 			map.map_mflags |= MF_OPEN;
1059 			map.map_pid = getpid();
1060 		}
1061 		else
1062 		{
1063 			if (!optional &&
1064 			    !bitset(MF_OPTIONAL, map.map_mflags))
1065 				syserr("fileclass: F{%s}: map open failed",
1066 				       mn);
1067 			sm_free(mn);
1068 			return;
1069 		}
1070 
1071 		/* lookup */
1072 		p = (*map.map_class->map_lookup)(&map, key, NULL, &status);
1073 		if (status != EX_OK && status != EX_NOTFOUND)
1074 		{
1075 			if (!optional)
1076 				syserr("fileclass: F{%s}: map lookup failed",
1077 				       mn);
1078 			p = NULL;
1079 		}
1080 
1081 		/* use the results */
1082 		if (p != NULL)
1083 			parse_class_words(class, p);
1084 
1085 		/* close map */
1086 		map.map_mflags |= MF_CLOSING;
1087 		map.map_class->map_close(&map);
1088 		map.map_mflags &= ~(MF_OPEN|MF_WRITABLE|MF_CLOSING);
1089 		sm_free(mn);
1090 		return;
1091 	}
1092 	else if (filename[0] == '|')
1093 	{
1094 		auto int fd;
1095 		int i;
1096 		char *argv[MAXPV + 1];
1097 
1098 		i = 0;
1099 		for (p = strtok(&filename[1], " \t");
1100 		     p != NULL && i < MAXPV;
1101 		     p = strtok(NULL, " \t"))
1102 			argv[i++] = p;
1103 		argv[i] = NULL;
1104 		pid = prog_open(argv, &fd, CurEnv);
1105 		if (pid < 0)
1106 			f = NULL;
1107 		else
1108 			f = sm_io_open(SmFtStdiofd, SM_TIME_DEFAULT,
1109 				       (void *) &fd, SM_IO_RDONLY, NULL);
1110 	}
1111 	else
1112 	{
1113 		pid = -1;
1114 		sff = SFF_REGONLY;
1115 		if (!bitnset(DBS_CLASSFILEINUNSAFEDIRPATH, DontBlameSendmail))
1116 			sff |= SFF_SAFEDIRPATH;
1117 		if (!bitnset(DBS_LINKEDCLASSFILEINWRITABLEDIR,
1118 			     DontBlameSendmail))
1119 			sff |= SFF_NOWLINK;
1120 		if (safe)
1121 			sff |= SFF_OPENASROOT;
1122 		else if (RealUid == 0)
1123 			sff |= SFF_ROOTOK;
1124 		if (DontLockReadFiles)
1125 			sff |= SFF_NOLOCK;
1126 		f = safefopen(filename, O_RDONLY, 0, sff);
1127 	}
1128 	if (f == NULL)
1129 	{
1130 		if (!optional)
1131 			syserr("fileclass: cannot open '%s'", filename);
1132 		return;
1133 	}
1134 
1135 	while (sm_io_fgets(f, SM_TIME_DEFAULT, buf, sizeof(buf)) != NULL)
1136 	{
1137 #if SCANF
1138 		char wordbuf[MAXLINE + 1];
1139 #endif /* SCANF */
1140 
1141 		if (buf[0] == '#')
1142 			continue;
1143 #if SCANF
1144 		if (sm_io_sscanf(buf, fmt, wordbuf) != 1)
1145 			continue;
1146 		p = wordbuf;
1147 #else /* SCANF */
1148 		p = buf;
1149 #endif /* SCANF */
1150 
1151 		parse_class_words(class, p);
1152 
1153 		/*
1154 		**  If anything else is added here,
1155 		**  check if the '@' map case above
1156 		**  needs the code as well.
1157 		*/
1158 	}
1159 
1160 	(void) sm_io_close(f, SM_TIME_DEFAULT);
1161 	if (pid > 0)
1162 		(void) waitfor(pid);
1163 }
1164 /*
1165 **  MAKEMAILER -- define a new mailer.
1166 **
1167 **	Parameters:
1168 **		line -- description of mailer.  This is in labeled
1169 **			fields.  The fields are:
1170 **			   A -- the argv for this mailer
1171 **			   C -- the character set for MIME conversions
1172 **			   D -- the directory to run in
1173 **			   E -- the eol string
1174 **			   F -- the flags associated with the mailer
1175 **			   L -- the maximum line length
1176 **			   M -- the maximum message size
1177 **			   N -- the niceness at which to run
1178 **			   P -- the path to the mailer
1179 **			   Q -- the queue group for the mailer
1180 **			   R -- the recipient rewriting set
1181 **			   S -- the sender rewriting set
1182 **			   T -- the mailer type (for DSNs)
1183 **			   U -- the uid to run as
1184 **			   W -- the time to wait at the end
1185 **			   m -- maximum messages per connection
1186 **			   r -- maximum number of recipients per message
1187 **			   / -- new root directory
1188 **			The first word is the canonical name of the mailer.
1189 **
1190 **	Returns:
1191 **		none.
1192 **
1193 **	Side Effects:
1194 **		enters the mailer into the mailer table.
1195 */
1196 
1197 void
1198 makemailer(line)
1199 	char *line;
1200 {
1201 	register char *p;
1202 	register struct mailer *m;
1203 	register STAB *s;
1204 	int i;
1205 	char fcode;
1206 	auto char *endp;
1207 	static int nextmailer = 0;	/* "free" index into Mailer struct */
1208 
1209 	/* allocate a mailer and set up defaults */
1210 	m = (struct mailer *) xalloc(sizeof(*m));
1211 	memset((char *) m, '\0', sizeof(*m));
1212 	errno = 0; /* avoid bogus error text */
1213 
1214 	/* collect the mailer name */
1215 	for (p = line;
1216 	     *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p));
1217 	     p++)
1218 		continue;
1219 	if (*p != '\0')
1220 		*p++ = '\0';
1221 	if (line[0] == '\0')
1222 	{
1223 		syserr("name required for mailer");
1224 		return;
1225 	}
1226 	m->m_name = newstr(line);
1227 	m->m_qgrp = NOQGRP;
1228 	m->m_uid = NO_UID;
1229 	m->m_gid = NO_GID;
1230 
1231 	/* now scan through and assign info from the fields */
1232 	while (*p != '\0')
1233 	{
1234 		auto char *delimptr;
1235 
1236 		while (*p != '\0' &&
1237 		       (*p == ',' || (isascii(*p) && isspace(*p))))
1238 			p++;
1239 
1240 		/* p now points to field code */
1241 		fcode = *p;
1242 		while (*p != '\0' && *p != '=' && *p != ',')
1243 			p++;
1244 		if (*p++ != '=')
1245 		{
1246 			syserr("mailer %s: `=' expected", m->m_name);
1247 			return;
1248 		}
1249 		while (isascii(*p) && isspace(*p))
1250 			p++;
1251 
1252 		/* p now points to the field body */
1253 		p = munchstring(p, &delimptr, ',');
1254 
1255 		/* install the field into the mailer struct */
1256 		switch (fcode)
1257 		{
1258 		  case 'P':		/* pathname */
1259 			if (*p != '\0')	/* error is issued below */
1260 				m->m_mailer = newstr(p);
1261 			break;
1262 
1263 		  case 'F':		/* flags */
1264 			for (; *p != '\0'; p++)
1265 			{
1266 				if (!(isascii(*p) && isspace(*p)))
1267 				{
1268 #if _FFR_DEPRECATE_MAILER_FLAG_I
1269 					if (*p == M_INTERNAL)
1270 						sm_syslog(LOG_WARNING, NOQID,
1271 							  "WARNING: mailer=%s, flag=%c deprecated",
1272 							  m->m_name, *p);
1273 #endif /* _FFR_DEPRECATE_MAILER_FLAG_I */
1274 					setbitn(bitidx(*p), m->m_flags);
1275 				}
1276 			}
1277 			break;
1278 
1279 		  case 'S':		/* sender rewriting ruleset */
1280 		  case 'R':		/* recipient rewriting ruleset */
1281 			i = strtorwset(p, &endp, ST_ENTER);
1282 			if (i < 0)
1283 				return;
1284 			if (fcode == 'S')
1285 				m->m_sh_rwset = m->m_se_rwset = i;
1286 			else
1287 				m->m_rh_rwset = m->m_re_rwset = i;
1288 
1289 			p = endp;
1290 			if (*p++ == '/')
1291 			{
1292 				i = strtorwset(p, NULL, ST_ENTER);
1293 				if (i < 0)
1294 					return;
1295 				if (fcode == 'S')
1296 					m->m_sh_rwset = i;
1297 				else
1298 					m->m_rh_rwset = i;
1299 			}
1300 			break;
1301 
1302 		  case 'E':		/* end of line string */
1303 			if (*p == '\0')
1304 				syserr("mailer %s: null end-of-line string",
1305 					m->m_name);
1306 			else
1307 				m->m_eol = newstr(p);
1308 			break;
1309 
1310 		  case 'A':		/* argument vector */
1311 			if (*p != '\0')	/* error is issued below */
1312 				m->m_argv = makeargv(p);
1313 			break;
1314 
1315 		  case 'M':		/* maximum message size */
1316 			m->m_maxsize = atol(p);
1317 			break;
1318 
1319 		  case 'm':		/* maximum messages per connection */
1320 			m->m_maxdeliveries = atoi(p);
1321 			break;
1322 
1323 		  case 'r':		/* max recipient per envelope */
1324 			m->m_maxrcpt = atoi(p);
1325 			break;
1326 
1327 		  case 'L':		/* maximum line length */
1328 			m->m_linelimit = atoi(p);
1329 			if (m->m_linelimit < 0)
1330 				m->m_linelimit = 0;
1331 			break;
1332 
1333 		  case 'N':		/* run niceness */
1334 			m->m_nice = atoi(p);
1335 			break;
1336 
1337 		  case 'D':		/* working directory */
1338 			if (*p == '\0')
1339 				syserr("mailer %s: null working directory",
1340 					m->m_name);
1341 			else
1342 				m->m_execdir = newstr(p);
1343 			break;
1344 
1345 		  case 'C':		/* default charset */
1346 			if (*p == '\0')
1347 				syserr("mailer %s: null charset", m->m_name);
1348 			else
1349 				m->m_defcharset = newstr(p);
1350 			break;
1351 
1352 		  case 'Q':		/* queue for this mailer */
1353 			if (*p == '\0')
1354 			{
1355 				syserr("mailer %s: null queue", m->m_name);
1356 				break;
1357 			}
1358 			s = stab(p, ST_QUEUE, ST_FIND);
1359 			if (s == NULL)
1360 				syserr("mailer %s: unknown queue %s",
1361 					m->m_name, p);
1362 			else
1363 				m->m_qgrp = s->s_quegrp->qg_index;
1364 			break;
1365 
1366 		  case 'T':		/* MTA-Name/Address/Diagnostic types */
1367 			/* extract MTA name type; default to "dns" */
1368 			m->m_mtatype = newstr(p);
1369 			p = strchr(m->m_mtatype, '/');
1370 			if (p != NULL)
1371 			{
1372 				*p++ = '\0';
1373 				if (*p == '\0')
1374 					p = NULL;
1375 			}
1376 			if (*m->m_mtatype == '\0')
1377 				m->m_mtatype = "dns";
1378 
1379 			/* extract address type; default to "rfc822" */
1380 			m->m_addrtype = p;
1381 			if (p != NULL)
1382 				p = strchr(p, '/');
1383 			if (p != NULL)
1384 			{
1385 				*p++ = '\0';
1386 				if (*p == '\0')
1387 					p = NULL;
1388 			}
1389 			if (m->m_addrtype == NULL || *m->m_addrtype == '\0')
1390 				m->m_addrtype = "rfc822";
1391 
1392 			/* extract diagnostic type; default to "smtp" */
1393 			m->m_diagtype = p;
1394 			if (m->m_diagtype == NULL || *m->m_diagtype == '\0')
1395 				m->m_diagtype = "smtp";
1396 			break;
1397 
1398 		  case 'U':		/* user id */
1399 			if (isascii(*p) && !isdigit(*p))
1400 			{
1401 				char *q = p;
1402 				struct passwd *pw;
1403 
1404 				while (*p != '\0' && isascii(*p) &&
1405 				       (isalnum(*p) || strchr("-_", *p) != NULL))
1406 					p++;
1407 				while (isascii(*p) && isspace(*p))
1408 					*p++ = '\0';
1409 				if (*p != '\0')
1410 					*p++ = '\0';
1411 				if (*q == '\0')
1412 				{
1413 					syserr("mailer %s: null user name",
1414 						m->m_name);
1415 					break;
1416 				}
1417 				pw = sm_getpwnam(q);
1418 				if (pw == NULL)
1419 				{
1420 					syserr("readcf: mailer U= flag: unknown user %s", q);
1421 					break;
1422 				}
1423 				else
1424 				{
1425 					m->m_uid = pw->pw_uid;
1426 					m->m_gid = pw->pw_gid;
1427 				}
1428 			}
1429 			else
1430 			{
1431 				auto char *q;
1432 
1433 				m->m_uid = strtol(p, &q, 0);
1434 				p = q;
1435 				while (isascii(*p) && isspace(*p))
1436 					p++;
1437 				if (*p != '\0')
1438 					p++;
1439 			}
1440 			while (isascii(*p) && isspace(*p))
1441 				p++;
1442 			if (*p == '\0')
1443 				break;
1444 			if (isascii(*p) && !isdigit(*p))
1445 			{
1446 				char *q = p;
1447 				struct group *gr;
1448 
1449 				while (isascii(*p) && isalnum(*p))
1450 					p++;
1451 				*p++ = '\0';
1452 				if (*q == '\0')
1453 				{
1454 					syserr("mailer %s: null group name",
1455 						m->m_name);
1456 					break;
1457 				}
1458 				gr = getgrnam(q);
1459 				if (gr == NULL)
1460 				{
1461 					syserr("readcf: mailer U= flag: unknown group %s", q);
1462 					break;
1463 				}
1464 				else
1465 					m->m_gid = gr->gr_gid;
1466 			}
1467 			else
1468 			{
1469 				m->m_gid = strtol(p, NULL, 0);
1470 			}
1471 			break;
1472 
1473 		  case 'W':		/* wait timeout */
1474 			m->m_wait = convtime(p, 's');
1475 			break;
1476 
1477 		  case '/':		/* new root directory */
1478 			if (*p == '\0')
1479 				syserr("mailer %s: null root directory",
1480 					m->m_name);
1481 			else
1482 				m->m_rootdir = newstr(p);
1483 			break;
1484 
1485 		  default:
1486 			syserr("M%s: unknown mailer equate %c=",
1487 			       m->m_name, fcode);
1488 			break;
1489 		}
1490 
1491 		p = delimptr;
1492 	}
1493 
1494 #if !HASRRESVPORT
1495 	if (bitnset(M_SECURE_PORT, m->m_flags))
1496 	{
1497 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1498 				     "M%s: Warning: F=%c set on system that doesn't support rresvport()\n",
1499 				     m->m_name, M_SECURE_PORT);
1500 	}
1501 #endif /* !HASRRESVPORT */
1502 
1503 #if !HASNICE
1504 	if (m->m_nice != 0)
1505 	{
1506 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1507 				     "M%s: Warning: N= set on system that doesn't support nice()\n",
1508 				     m->m_name);
1509 	}
1510 #endif /* !HASNICE */
1511 
1512 	/* do some rationality checking */
1513 	if (m->m_argv == NULL)
1514 	{
1515 		syserr("M%s: A= argument required", m->m_name);
1516 		return;
1517 	}
1518 	if (m->m_mailer == NULL)
1519 	{
1520 		syserr("M%s: P= argument required", m->m_name);
1521 		return;
1522 	}
1523 
1524 	if (nextmailer >= MAXMAILERS)
1525 	{
1526 		syserr("too many mailers defined (%d max)", MAXMAILERS);
1527 		return;
1528 	}
1529 
1530 	if (m->m_maxrcpt <= 0)
1531 		m->m_maxrcpt = DEFAULT_MAX_RCPT;
1532 
1533 	/* do some heuristic cleanup for back compatibility */
1534 	if (bitnset(M_LIMITS, m->m_flags))
1535 	{
1536 		if (m->m_linelimit == 0)
1537 			m->m_linelimit = SMTPLINELIM;
1538 		if (ConfigLevel < 2)
1539 			setbitn(M_7BITS, m->m_flags);
1540 	}
1541 
1542 	if (strcmp(m->m_mailer, "[TCP]") == 0)
1543 	{
1544 		syserr("M%s: P=[TCP] must be replaced by P=[IPC]", m->m_name);
1545 		return;
1546 	}
1547 
1548 	if (strcmp(m->m_mailer, "[IPC]") == 0)
1549 	{
1550 		/* Use the second argument for host or path to socket */
1551 		if (m->m_argv[0] == NULL || m->m_argv[1] == NULL ||
1552 		    m->m_argv[1][0] == '\0')
1553 		{
1554 			syserr("M%s: too few parameters for %s mailer",
1555 			       m->m_name, m->m_mailer);
1556 			return;
1557 		}
1558 		if (strcmp(m->m_argv[0], "TCP") != 0
1559 #if NETUNIX
1560 		    && strcmp(m->m_argv[0], "FILE") != 0
1561 #endif /* NETUNIX */
1562 		    )
1563 		{
1564 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1565 					     "M%s: Warning: first argument in %s mailer must be %s\n",
1566 					     m->m_name, m->m_mailer,
1567 #if NETUNIX
1568 					     "TCP or FILE"
1569 #else /* NETUNIX */
1570 					     "TCP"
1571 #endif /* NETUNIX */
1572 				     );
1573 		}
1574 		if (m->m_mtatype == NULL)
1575 			m->m_mtatype = "dns";
1576 		if (m->m_addrtype == NULL)
1577 			m->m_addrtype = "rfc822";
1578 		if (m->m_diagtype == NULL)
1579 		{
1580 			if (m->m_argv[0] != NULL &&
1581 			    strcmp(m->m_argv[0], "FILE") == 0)
1582 				m->m_diagtype = "x-unix";
1583 			else
1584 				m->m_diagtype = "smtp";
1585 		}
1586 	}
1587 	else if (strcmp(m->m_mailer, "[FILE]") == 0)
1588 	{
1589 		/* Use the second argument for filename */
1590 		if (m->m_argv[0] == NULL || m->m_argv[1] == NULL ||
1591 		    m->m_argv[2] != NULL)
1592 		{
1593 			syserr("M%s: too %s parameters for [FILE] mailer",
1594 			       m->m_name,
1595 			       (m->m_argv[0] == NULL ||
1596 				m->m_argv[1] == NULL) ? "few" : "many");
1597 			return;
1598 		}
1599 		else if (strcmp(m->m_argv[0], "FILE") != 0)
1600 		{
1601 			syserr("M%s: first argument in [FILE] mailer must be FILE",
1602 			       m->m_name);
1603 			return;
1604 		}
1605 	}
1606 
1607 	if (m->m_eol == NULL)
1608 	{
1609 		char **pp;
1610 
1611 		/* default for SMTP is \r\n; use \n for local delivery */
1612 		for (pp = m->m_argv; *pp != NULL; pp++)
1613 		{
1614 			for (p = *pp; *p != '\0'; )
1615 			{
1616 				if ((*p++ & 0377) == MACROEXPAND && *p == 'u')
1617 					break;
1618 			}
1619 			if (*p != '\0')
1620 				break;
1621 		}
1622 		if (*pp == NULL)
1623 			m->m_eol = "\r\n";
1624 		else
1625 			m->m_eol = "\n";
1626 	}
1627 
1628 	/* enter the mailer into the symbol table */
1629 	s = stab(m->m_name, ST_MAILER, ST_ENTER);
1630 	if (s->s_mailer != NULL)
1631 	{
1632 		i = s->s_mailer->m_mno;
1633 		sm_free(s->s_mailer); /* XXX */
1634 	}
1635 	else
1636 	{
1637 		i = nextmailer++;
1638 	}
1639 	Mailer[i] = s->s_mailer = m;
1640 	m->m_mno = i;
1641 }
1642 /*
1643 **  MUNCHSTRING -- translate a string into internal form.
1644 **
1645 **	Parameters:
1646 **		p -- the string to munch.
1647 **		delimptr -- if non-NULL, set to the pointer of the
1648 **			field delimiter character.
1649 **		delim -- the delimiter for the field.
1650 **
1651 **	Returns:
1652 **		the munched string.
1653 **
1654 **	Side Effects:
1655 **		the munched string is a local static buffer.
1656 **		it must be copied before the function is called again.
1657 */
1658 
1659 char *
1660 munchstring(p, delimptr, delim)
1661 	register char *p;
1662 	char **delimptr;
1663 	int delim;
1664 {
1665 	register char *q;
1666 	bool backslash = false;
1667 	bool quotemode = false;
1668 	static char buf[MAXLINE];
1669 
1670 	for (q = buf; *p != '\0' && q < &buf[sizeof(buf) - 1]; p++)
1671 	{
1672 		if (backslash)
1673 		{
1674 			/* everything is roughly literal */
1675 			backslash = false;
1676 			switch (*p)
1677 			{
1678 			  case 'r':		/* carriage return */
1679 				*q++ = '\r';
1680 				continue;
1681 
1682 			  case 'n':		/* newline */
1683 				*q++ = '\n';
1684 				continue;
1685 
1686 			  case 'f':		/* form feed */
1687 				*q++ = '\f';
1688 				continue;
1689 
1690 			  case 'b':		/* backspace */
1691 				*q++ = '\b';
1692 				continue;
1693 			}
1694 			*q++ = *p;
1695 		}
1696 		else
1697 		{
1698 			if (*p == '\\')
1699 				backslash = true;
1700 			else if (*p == '"')
1701 				quotemode = !quotemode;
1702 			else if (quotemode || *p != delim)
1703 				*q++ = *p;
1704 			else
1705 				break;
1706 		}
1707 	}
1708 
1709 	if (delimptr != NULL)
1710 		*delimptr = p;
1711 	*q++ = '\0';
1712 	return buf;
1713 }
1714 /*
1715 **  EXTRQUOTSTR -- extract a (quoted) string.
1716 **
1717 **	This routine deals with quoted (") strings and escaped
1718 **	spaces (\\ ).
1719 **
1720 **	Parameters:
1721 **		p -- source string.
1722 **		delimptr -- if non-NULL, set to the pointer of the
1723 **			field delimiter character.
1724 **		delimbuf -- delimiters for the field.
1725 **		st -- if non-NULL, store the return value (whether the
1726 **			string was correctly quoted) here.
1727 **
1728 **	Returns:
1729 **		the extracted string.
1730 **
1731 **	Side Effects:
1732 **		the returned string is a local static buffer.
1733 **		it must be copied before the function is called again.
1734 */
1735 
1736 static char *
1737 extrquotstr(p, delimptr, delimbuf, st)
1738 	register char *p;
1739 	char **delimptr;
1740 	char *delimbuf;
1741 	bool *st;
1742 {
1743 	register char *q;
1744 	bool backslash = false;
1745 	bool quotemode = false;
1746 	static char buf[MAXLINE];
1747 
1748 	for (q = buf; *p != '\0' && q < &buf[sizeof(buf) - 1]; p++)
1749 	{
1750 		if (backslash)
1751 		{
1752 			backslash = false;
1753 			if (*p != ' ')
1754 				*q++ = '\\';
1755 		}
1756 		if (*p == '\\')
1757 			backslash = true;
1758 		else if (*p == '"')
1759 			quotemode = !quotemode;
1760 		else if (quotemode ||
1761 			 strchr(delimbuf, (int) *p) == NULL)
1762 			*q++ = *p;
1763 		else
1764 			break;
1765 	}
1766 
1767 	if (delimptr != NULL)
1768 		*delimptr = p;
1769 	*q++ = '\0';
1770 	if (st != NULL)
1771 		*st = !(quotemode || backslash);
1772 	return buf;
1773 }
1774 /*
1775 **  MAKEARGV -- break up a string into words
1776 **
1777 **	Parameters:
1778 **		p -- the string to break up.
1779 **
1780 **	Returns:
1781 **		a char **argv (dynamically allocated)
1782 **
1783 **	Side Effects:
1784 **		munges p.
1785 */
1786 
1787 static char **
1788 makeargv(p)
1789 	register char *p;
1790 {
1791 	char *q;
1792 	int i;
1793 	char **avp;
1794 	char *argv[MAXPV + 1];
1795 
1796 	/* take apart the words */
1797 	i = 0;
1798 	while (*p != '\0' && i < MAXPV)
1799 	{
1800 		q = p;
1801 		while (*p != '\0' && !(isascii(*p) && isspace(*p)))
1802 			p++;
1803 		while (isascii(*p) && isspace(*p))
1804 			*p++ = '\0';
1805 		argv[i++] = newstr(q);
1806 	}
1807 	argv[i++] = NULL;
1808 
1809 	/* now make a copy of the argv */
1810 	avp = (char **) xalloc(sizeof(*avp) * i);
1811 	memmove((char *) avp, (char *) argv, sizeof(*avp) * i);
1812 
1813 	return avp;
1814 }
1815 /*
1816 **  PRINTRULES -- print rewrite rules (for debugging)
1817 **
1818 **	Parameters:
1819 **		none.
1820 **
1821 **	Returns:
1822 **		none.
1823 **
1824 **	Side Effects:
1825 **		prints rewrite rules.
1826 */
1827 
1828 void
1829 printrules()
1830 {
1831 	register struct rewrite *rwp;
1832 	register int ruleset;
1833 
1834 	for (ruleset = 0; ruleset < 10; ruleset++)
1835 	{
1836 		if (RewriteRules[ruleset] == NULL)
1837 			continue;
1838 		sm_dprintf("\n----Rule Set %d:", ruleset);
1839 
1840 		for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
1841 		{
1842 			sm_dprintf("\nLHS:");
1843 			printav(sm_debug_file(), rwp->r_lhs);
1844 			sm_dprintf("RHS:");
1845 			printav(sm_debug_file(), rwp->r_rhs);
1846 		}
1847 	}
1848 }
1849 /*
1850 **  PRINTMAILER -- print mailer structure (for debugging)
1851 **
1852 **	Parameters:
1853 **		fp -- output file
1854 **		m -- the mailer to print
1855 **
1856 **	Returns:
1857 **		none.
1858 */
1859 
1860 void
1861 printmailer(fp, m)
1862 	SM_FILE_T *fp;
1863 	register MAILER *m;
1864 {
1865 	int j;
1866 
1867 	(void) sm_io_fprintf(fp, SM_TIME_DEFAULT,
1868 			     "mailer %d (%s): P=%s S=", m->m_mno, m->m_name,
1869 			     m->m_mailer);
1870 	if (RuleSetNames[m->m_se_rwset] == NULL)
1871 		(void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d/",
1872 				     m->m_se_rwset);
1873 	else
1874 		(void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s/",
1875 				     RuleSetNames[m->m_se_rwset]);
1876 	if (RuleSetNames[m->m_sh_rwset] == NULL)
1877 		(void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d R=",
1878 				     m->m_sh_rwset);
1879 	else
1880 		(void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s R=",
1881 				     RuleSetNames[m->m_sh_rwset]);
1882 	if (RuleSetNames[m->m_re_rwset] == NULL)
1883 		(void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d/",
1884 				     m->m_re_rwset);
1885 	else
1886 		(void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s/",
1887 				     RuleSetNames[m->m_re_rwset]);
1888 	if (RuleSetNames[m->m_rh_rwset] == NULL)
1889 		(void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d ",
1890 				     m->m_rh_rwset);
1891 	else
1892 		(void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s ",
1893 				     RuleSetNames[m->m_rh_rwset]);
1894 	(void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "M=%ld U=%d:%d F=",
1895 			     m->m_maxsize, (int) m->m_uid, (int) m->m_gid);
1896 	for (j = '\0'; j <= '\177'; j++)
1897 		if (bitnset(j, m->m_flags))
1898 			(void) sm_io_putc(fp, SM_TIME_DEFAULT, j);
1899 	(void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " L=%d E=",
1900 			     m->m_linelimit);
1901 	xputs(fp, m->m_eol);
1902 	if (m->m_defcharset != NULL)
1903 		(void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " C=%s",
1904 				     m->m_defcharset);
1905 	(void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " T=%s/%s/%s",
1906 			     m->m_mtatype == NULL
1907 				? "<undefined>" : m->m_mtatype,
1908 			     m->m_addrtype == NULL
1909 				? "<undefined>" : m->m_addrtype,
1910 			     m->m_diagtype == NULL
1911 				? "<undefined>" : m->m_diagtype);
1912 	(void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " r=%d", m->m_maxrcpt);
1913 	if (m->m_argv != NULL)
1914 	{
1915 		char **a = m->m_argv;
1916 
1917 		(void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " A=");
1918 		while (*a != NULL)
1919 		{
1920 			if (a != m->m_argv)
1921 				(void) sm_io_fprintf(fp, SM_TIME_DEFAULT,
1922 						     " ");
1923 			xputs(fp, *a++);
1924 		}
1925 	}
1926 	(void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "\n");
1927 }
1928 /*
1929 **  SETOPTION -- set global processing option
1930 **
1931 **	Parameters:
1932 **		opt -- option name.
1933 **		val -- option value (as a text string).
1934 **		safe -- set if this came from a configuration file.
1935 **			Some options (if set from the command line) will
1936 **			reset the user id to avoid security problems.
1937 **		sticky -- if set, don't let other setoptions override
1938 **			this value.
1939 **		e -- the main envelope.
1940 **
1941 **	Returns:
1942 **		none.
1943 **
1944 **	Side Effects:
1945 **		Sets options as implied by the arguments.
1946 */
1947 
1948 static BITMAP256	StickyOpt;		/* set if option is stuck */
1949 
1950 #if NAMED_BIND
1951 
1952 static struct resolverflags
1953 {
1954 	char	*rf_name;	/* name of the flag */
1955 	long	rf_bits;	/* bits to set/clear */
1956 } ResolverFlags[] =
1957 {
1958 	{ "debug",	RES_DEBUG	},
1959 	{ "aaonly",	RES_AAONLY	},
1960 	{ "usevc",	RES_USEVC	},
1961 	{ "primary",	RES_PRIMARY	},
1962 	{ "igntc",	RES_IGNTC	},
1963 	{ "recurse",	RES_RECURSE	},
1964 	{ "defnames",	RES_DEFNAMES	},
1965 	{ "stayopen",	RES_STAYOPEN	},
1966 	{ "dnsrch",	RES_DNSRCH	},
1967 # ifdef RES_USE_INET6
1968 	{ "use_inet6",	RES_USE_INET6	},
1969 # endif /* RES_USE_INET6 */
1970 	{ "true",	0		},	/* avoid error on old syntax */
1971 	{ NULL,		0		}
1972 };
1973 
1974 #endif /* NAMED_BIND */
1975 
1976 #define OI_NONE		0	/* no special treatment */
1977 #define OI_SAFE		0x0001	/* safe for random people to use */
1978 #define OI_SUBOPT	0x0002	/* option has suboptions */
1979 
1980 static struct optioninfo
1981 {
1982 	char		*o_name;	/* long name of option */
1983 	unsigned char	o_code;		/* short name of option */
1984 	unsigned short	o_flags;	/* option flags */
1985 } OptionTab[] =
1986 {
1987 #if defined(SUN_EXTENSIONS) && defined(REMOTE_MODE)
1988 	{ "RemoteMode",			'>',		OI_NONE	},
1989 #endif /* defined(SUN_EXTENSIONS) && defined(REMOTE_MODE) */
1990 	{ "SevenBitInput",		'7',		OI_SAFE	},
1991 	{ "EightBitMode",		'8',		OI_SAFE	},
1992 	{ "AliasFile",			'A',		OI_NONE	},
1993 	{ "AliasWait",			'a',		OI_NONE	},
1994 	{ "BlankSub",			'B',		OI_NONE	},
1995 	{ "MinFreeBlocks",		'b',		OI_SAFE	},
1996 	{ "CheckpointInterval",		'C',		OI_SAFE	},
1997 	{ "HoldExpensive",		'c',		OI_NONE	},
1998 	{ "DeliveryMode",		'd',		OI_SAFE	},
1999 	{ "ErrorHeader",		'E',		OI_NONE	},
2000 	{ "ErrorMode",			'e',		OI_SAFE	},
2001 	{ "TempFileMode",		'F',		OI_NONE	},
2002 	{ "SaveFromLine",		'f',		OI_NONE	},
2003 	{ "MatchGECOS",			'G',		OI_NONE	},
2004 
2005 	/* no long name, just here to avoid problems in setoption */
2006 	{ "",				'g',		OI_NONE	},
2007 	{ "HelpFile",			'H',		OI_NONE	},
2008 	{ "MaxHopCount",		'h',		OI_NONE	},
2009 	{ "ResolverOptions",		'I',		OI_NONE	},
2010 	{ "IgnoreDots",			'i',		OI_SAFE	},
2011 	{ "ForwardPath",		'J',		OI_NONE	},
2012 	{ "SendMimeErrors",		'j',		OI_SAFE	},
2013 	{ "ConnectionCacheSize",	'k',		OI_NONE	},
2014 	{ "ConnectionCacheTimeout",	'K',		OI_NONE	},
2015 	{ "UseErrorsTo",		'l',		OI_NONE	},
2016 	{ "LogLevel",			'L',		OI_SAFE	},
2017 	{ "MeToo",			'm',		OI_SAFE	},
2018 
2019 	/* no long name, just here to avoid problems in setoption */
2020 	{ "",				'M',		OI_NONE	},
2021 	{ "CheckAliases",		'n',		OI_NONE	},
2022 	{ "OldStyleHeaders",		'o',		OI_SAFE	},
2023 	{ "DaemonPortOptions",		'O',		OI_NONE	},
2024 	{ "PrivacyOptions",		'p',		OI_SAFE	},
2025 	{ "PostmasterCopy",		'P',		OI_NONE	},
2026 	{ "QueueFactor",		'q',		OI_NONE	},
2027 	{ "QueueDirectory",		'Q',		OI_NONE	},
2028 	{ "DontPruneRoutes",		'R',		OI_NONE	},
2029 	{ "Timeout",			'r',		OI_SUBOPT },
2030 	{ "StatusFile",			'S',		OI_NONE	},
2031 	{ "SuperSafe",			's',		OI_SAFE	},
2032 	{ "QueueTimeout",		'T',		OI_NONE	},
2033 	{ "TimeZoneSpec",		't',		OI_NONE	},
2034 	{ "UserDatabaseSpec",		'U',		OI_NONE	},
2035 	{ "DefaultUser",		'u',		OI_NONE	},
2036 	{ "FallbackMXhost",		'V',		OI_NONE	},
2037 	{ "Verbose",			'v',		OI_SAFE	},
2038 	{ "TryNullMXList",		'w',		OI_NONE	},
2039 	{ "QueueLA",			'x',		OI_NONE	},
2040 	{ "RefuseLA",			'X',		OI_NONE	},
2041 	{ "RecipientFactor",		'y',		OI_NONE	},
2042 	{ "ForkEachJob",		'Y',		OI_NONE	},
2043 	{ "ClassFactor",		'z',		OI_NONE	},
2044 	{ "RetryFactor",		'Z',		OI_NONE	},
2045 #define O_QUEUESORTORD	0x81
2046 	{ "QueueSortOrder",		O_QUEUESORTORD,	OI_SAFE	},
2047 #define O_HOSTSFILE	0x82
2048 	{ "HostsFile",			O_HOSTSFILE,	OI_NONE	},
2049 #define O_MQA		0x83
2050 	{ "MinQueueAge",		O_MQA,		OI_SAFE	},
2051 #define O_DEFCHARSET	0x85
2052 	{ "DefaultCharSet",		O_DEFCHARSET,	OI_SAFE	},
2053 #define O_SSFILE	0x86
2054 	{ "ServiceSwitchFile",		O_SSFILE,	OI_NONE	},
2055 #define O_DIALDELAY	0x87
2056 	{ "DialDelay",			O_DIALDELAY,	OI_SAFE	},
2057 #define O_NORCPTACTION	0x88
2058 	{ "NoRecipientAction",		O_NORCPTACTION,	OI_SAFE	},
2059 #define O_SAFEFILEENV	0x89
2060 	{ "SafeFileEnvironment",	O_SAFEFILEENV,	OI_NONE	},
2061 #define O_MAXMSGSIZE	0x8a
2062 	{ "MaxMessageSize",		O_MAXMSGSIZE,	OI_NONE	},
2063 #define O_COLONOKINADDR	0x8b
2064 	{ "ColonOkInAddr",		O_COLONOKINADDR, OI_SAFE },
2065 #define O_MAXQUEUERUN	0x8c
2066 	{ "MaxQueueRunSize",		O_MAXQUEUERUN,	OI_SAFE	},
2067 #define O_MAXCHILDREN	0x8d
2068 	{ "MaxDaemonChildren",		O_MAXCHILDREN,	OI_NONE	},
2069 #define O_KEEPCNAMES	0x8e
2070 	{ "DontExpandCnames",		O_KEEPCNAMES,	OI_NONE	},
2071 #define O_MUSTQUOTE	0x8f
2072 	{ "MustQuoteChars",		O_MUSTQUOTE,	OI_NONE	},
2073 #define O_SMTPGREETING	0x90
2074 	{ "SmtpGreetingMessage",	O_SMTPGREETING,	OI_NONE	},
2075 #define O_UNIXFROM	0x91
2076 	{ "UnixFromLine",		O_UNIXFROM,	OI_NONE	},
2077 #define O_OPCHARS	0x92
2078 	{ "OperatorChars",		O_OPCHARS,	OI_NONE	},
2079 #define O_DONTINITGRPS	0x93
2080 	{ "DontInitGroups",		O_DONTINITGRPS,	OI_NONE	},
2081 #define O_SLFH		0x94
2082 	{ "SingleLineFromHeader",	O_SLFH,		OI_SAFE	},
2083 #define O_ABH		0x95
2084 	{ "AllowBogusHELO",		O_ABH,		OI_SAFE	},
2085 #define O_CONNTHROT	0x97
2086 	{ "ConnectionRateThrottle",	O_CONNTHROT,	OI_NONE	},
2087 #define O_UGW		0x99
2088 	{ "UnsafeGroupWrites",		O_UGW,		OI_NONE	},
2089 #define O_DBLBOUNCE	0x9a
2090 	{ "DoubleBounceAddress",	O_DBLBOUNCE,	OI_NONE	},
2091 #define O_HSDIR		0x9b
2092 	{ "HostStatusDirectory",	O_HSDIR,	OI_NONE	},
2093 #define O_SINGTHREAD	0x9c
2094 	{ "SingleThreadDelivery",	O_SINGTHREAD,	OI_NONE	},
2095 #define O_RUNASUSER	0x9d
2096 	{ "RunAsUser",			O_RUNASUSER,	OI_NONE	},
2097 #define O_DSN_RRT	0x9e
2098 	{ "RrtImpliesDsn",		O_DSN_RRT,	OI_NONE	},
2099 #define O_PIDFILE	0x9f
2100 	{ "PidFile",			O_PIDFILE,	OI_NONE	},
2101 #define O_DONTBLAMESENDMAIL	0xa0
2102 	{ "DontBlameSendmail",		O_DONTBLAMESENDMAIL,	OI_NONE	},
2103 #define O_DPI		0xa1
2104 	{ "DontProbeInterfaces",	O_DPI,		OI_NONE	},
2105 #define O_MAXRCPT	0xa2
2106 	{ "MaxRecipientsPerMessage",	O_MAXRCPT,	OI_SAFE	},
2107 #define O_DEADLETTER	0xa3
2108 	{ "DeadLetterDrop",		O_DEADLETTER,	OI_NONE	},
2109 #if _FFR_DONTLOCKFILESFORREAD_OPTION
2110 # define O_DONTLOCK	0xa4
2111 	{ "DontLockFilesForRead",	O_DONTLOCK,	OI_NONE	},
2112 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
2113 #define O_MAXALIASRCSN	0xa5
2114 	{ "MaxAliasRecursion",		O_MAXALIASRCSN,	OI_NONE	},
2115 #define O_CNCTONLYTO	0xa6
2116 	{ "ConnectOnlyTo",		O_CNCTONLYTO,	OI_NONE	},
2117 #define O_TRUSTUSER	0xa7
2118 	{ "TrustedUser",		O_TRUSTUSER,	OI_NONE	},
2119 #define O_MAXMIMEHDRLEN	0xa8
2120 	{ "MaxMimeHeaderLength",	O_MAXMIMEHDRLEN,	OI_NONE	},
2121 #define O_CONTROLSOCKET	0xa9
2122 	{ "ControlSocketName",		O_CONTROLSOCKET,	OI_NONE	},
2123 #define O_MAXHDRSLEN	0xaa
2124 	{ "MaxHeadersLength",		O_MAXHDRSLEN,	OI_NONE	},
2125 #if _FFR_MAX_FORWARD_ENTRIES
2126 # define O_MAXFORWARD	0xab
2127 	{ "MaxForwardEntries",		O_MAXFORWARD,	OI_NONE	},
2128 #endif /* _FFR_MAX_FORWARD_ENTRIES */
2129 #define O_PROCTITLEPREFIX	0xac
2130 	{ "ProcessTitlePrefix",		O_PROCTITLEPREFIX,	OI_NONE	},
2131 #define O_SASLINFO	0xad
2132 #if _FFR_ALLOW_SASLINFO
2133 	{ "DefaultAuthInfo",		O_SASLINFO,	OI_SAFE	},
2134 #else /* _FFR_ALLOW_SASLINFO */
2135 	{ "DefaultAuthInfo",		O_SASLINFO,	OI_NONE	},
2136 #endif /* _FFR_ALLOW_SASLINFO */
2137 #define O_SASLMECH	0xae
2138 	{ "AuthMechanisms",		O_SASLMECH,	OI_NONE	},
2139 #define O_CLIENTPORT	0xaf
2140 	{ "ClientPortOptions",		O_CLIENTPORT,	OI_NONE	},
2141 #define O_DF_BUFSIZE	0xb0
2142 	{ "DataFileBufferSize",		O_DF_BUFSIZE,	OI_NONE	},
2143 #define O_XF_BUFSIZE	0xb1
2144 	{ "XscriptFileBufferSize",	O_XF_BUFSIZE,	OI_NONE	},
2145 #define O_LDAPDEFAULTSPEC	0xb2
2146 	{ "LDAPDefaultSpec",		O_LDAPDEFAULTSPEC,	OI_NONE	},
2147 #define O_SRVCERTFILE	0xb4
2148 	{ "ServerCertFile",		O_SRVCERTFILE,	OI_NONE	},
2149 #define O_SRVKEYFILE	0xb5
2150 	{ "ServerKeyFile",		O_SRVKEYFILE,	OI_NONE	},
2151 #define O_CLTCERTFILE	0xb6
2152 	{ "ClientCertFile",		O_CLTCERTFILE,	OI_NONE	},
2153 #define O_CLTKEYFILE	0xb7
2154 	{ "ClientKeyFile",		O_CLTKEYFILE,	OI_NONE	},
2155 #define O_CACERTFILE	0xb8
2156 	{ "CACertFile",			O_CACERTFILE,	OI_NONE	},
2157 #define O_CACERTPATH	0xb9
2158 	{ "CACertPath",			O_CACERTPATH,	OI_NONE	},
2159 #define O_DHPARAMS	0xba
2160 	{ "DHParameters",		O_DHPARAMS,	OI_NONE	},
2161 #define O_INPUTMILTER	0xbb
2162 	{ "InputMailFilters",		O_INPUTMILTER,	OI_NONE	},
2163 #define O_MILTER	0xbc
2164 	{ "Milter",			O_MILTER,	OI_SUBOPT	},
2165 #define O_SASLOPTS	0xbd
2166 	{ "AuthOptions",		O_SASLOPTS,	OI_NONE	},
2167 #define O_QUEUE_FILE_MODE	0xbe
2168 	{ "QueueFileMode",		O_QUEUE_FILE_MODE, OI_NONE	},
2169 #if _FFR_TLS_1
2170 # define O_DHPARAMS5	0xbf
2171 	{ "DHParameters512",		O_DHPARAMS5,	OI_NONE	},
2172 # define O_CIPHERLIST	0xc0
2173 	{ "CipherList",			O_CIPHERLIST,	OI_NONE	},
2174 #endif /* _FFR_TLS_1 */
2175 #define O_RANDFILE	0xc1
2176 	{ "RandFile",			O_RANDFILE,	OI_NONE	},
2177 #define O_TLS_SRV_OPTS	0xc2
2178 	{ "TLSSrvOptions",		O_TLS_SRV_OPTS,	OI_NONE	},
2179 #define O_RCPTTHROT	0xc3
2180 	{ "BadRcptThrottle",		O_RCPTTHROT,	OI_SAFE	},
2181 #define O_DLVR_MIN	0xc4
2182 	{ "DeliverByMin",		O_DLVR_MIN,	OI_NONE	},
2183 #define O_MAXQUEUECHILDREN	0xc5
2184 	{ "MaxQueueChildren",		O_MAXQUEUECHILDREN,	OI_NONE	},
2185 #define O_MAXRUNNERSPERQUEUE	0xc6
2186 	{ "MaxRunnersPerQueue",		O_MAXRUNNERSPERQUEUE,	OI_NONE },
2187 #define O_DIRECTSUBMODIFIERS	0xc7
2188 	{ "DirectSubmissionModifiers",	O_DIRECTSUBMODIFIERS,	OI_NONE },
2189 #define O_NICEQUEUERUN	0xc8
2190 	{ "NiceQueueRun",		O_NICEQUEUERUN,	OI_NONE	},
2191 #define O_SHMKEY	0xc9
2192 	{ "SharedMemoryKey",		O_SHMKEY,	OI_NONE	},
2193 #define O_SASLBITS	0xca
2194 	{ "AuthMaxBits",		O_SASLBITS,	OI_NONE	},
2195 #define O_MBDB		0xcb
2196 	{ "MailboxDatabase",		O_MBDB,		OI_NONE	},
2197 #define O_MSQ		0xcc
2198 	{ "UseMSP",	O_MSQ,		OI_NONE	},
2199 #define O_DELAY_LA	0xcd
2200 	{ "DelayLA",	O_DELAY_LA,	OI_NONE	},
2201 #define O_FASTSPLIT	0xce
2202 	{ "FastSplit",	O_FASTSPLIT,	OI_NONE	},
2203 #define O_SOFTBOUNCE	0xcf
2204 	{ "SoftBounce",	O_SOFTBOUNCE,	OI_NONE	},
2205 #define O_SHMKEYFILE	0xd0
2206 	{ "SharedMemoryKeyFile",	O_SHMKEYFILE,	OI_NONE	},
2207 #define O_REJECTLOGINTERVAL	0xd1
2208 	{ "RejectLogInterval",	O_REJECTLOGINTERVAL,	OI_NONE	},
2209 #define O_REQUIRES_DIR_FSYNC	0xd2
2210 	{ "RequiresDirfsync",	O_REQUIRES_DIR_FSYNC,	OI_NONE	},
2211 #define O_CONNECTION_RATE_WINDOW_SIZE	0xd3
2212 	{ "ConnectionRateWindowSize", O_CONNECTION_RATE_WINDOW_SIZE, OI_NONE },
2213 #define O_CRLFILE	0xd4
2214 	{ "CRLFile",		O_CRLFILE,	OI_NONE	},
2215 #define O_FALLBACKSMARTHOST	0xd5
2216 	{ "FallbackSmartHost",		O_FALLBACKSMARTHOST,	OI_NONE	},
2217 #define O_SASLREALM	0xd6
2218 	{ "AuthRealm",		O_SASLREALM,	OI_NONE	},
2219 #if _FFR_CRLPATH
2220 # define O_CRLPATH	0xd7
2221 	{ "CRLPath",		O_CRLPATH,	OI_NONE	},
2222 #endif /* _FFR_CRLPATH */
2223 #define O_HELONAME 0xd8
2224 	{ "HeloName",   O_HELONAME,     OI_NONE },
2225 #if _FFR_MEMSTAT
2226 # define O_REFUSELOWMEM	0xd9
2227 	{ "RefuseLowMem",	O_REFUSELOWMEM,	OI_NONE },
2228 # define O_QUEUELOWMEM	0xda
2229 	{ "QueueLowMem",	O_QUEUELOWMEM,	OI_NONE },
2230 # define O_MEMRESOURCE	0xdb
2231 	{ "MemoryResource",	O_MEMRESOURCE,	OI_NONE },
2232 #endif /* _FFR_MEMSTAT */
2233 #define O_MAXNOOPCOMMANDS 0xdc
2234 	{ "MaxNOOPCommands",	O_MAXNOOPCOMMANDS,	OI_NONE },
2235 #if _FFR_MSG_ACCEPT
2236 # define O_MSG_ACCEPT 0xdd
2237 	{ "MessageAccept",	O_MSG_ACCEPT,	OI_NONE },
2238 #endif /* _FFR_MSG_ACCEPT */
2239 #if _FFR_QUEUE_RUN_PARANOIA
2240 # define O_CHK_Q_RUNNERS 0xde
2241 	{ "CheckQueueRunners",	O_CHK_Q_RUNNERS,	OI_NONE },
2242 #endif /* _FFR_QUEUE_RUN_PARANOIA */
2243 #if _FFR_EIGHT_BIT_ADDR_OK
2244 # if !ALLOW_255
2245 #  ERROR FFR_EIGHT_BIT_ADDR_OK requires _ALLOW_255
2246 # endif /* !ALLOW_255 */
2247 # define O_EIGHT_BIT_ADDR_OK	0xdf
2248 	{ "EightBitAddrOK",	O_EIGHT_BIT_ADDR_OK,	OI_NONE },
2249 #endif /* _FFR_EIGHT_BIT_ADDR_OK */
2250 
2251 	{ NULL,				'\0',		OI_NONE	}
2252 };
2253 
2254 # define CANONIFY(val)
2255 
2256 # define SET_OPT_DEFAULT(opt, val)	opt = val
2257 
2258 /* set a string option by expanding the value and assigning it */
2259 /* WARNING this belongs ONLY into a case statement! */
2260 #define SET_STRING_EXP(str)	\
2261 		expand(val, exbuf, sizeof(exbuf), e);	\
2262 		newval = sm_pstrdup_x(exbuf);		\
2263 		if (str != NULL)	\
2264 			sm_free(str);	\
2265 		CANONIFY(newval);	\
2266 		str = newval;		\
2267 		break
2268 
2269 #define OPTNAME	o->o_name == NULL ? "<unknown>" : o->o_name
2270 
2271 void
2272 setoption(opt, val, safe, sticky, e)
2273 	int opt;
2274 	char *val;
2275 	bool safe;
2276 	bool sticky;
2277 	register ENVELOPE *e;
2278 {
2279 	register char *p;
2280 	register struct optioninfo *o;
2281 	char *subopt;
2282 	int mid;
2283 	bool can_setuid = RunAsUid == 0;
2284 	auto char *ep;
2285 	char buf[50];
2286 	extern bool Warn_Q_option;
2287 #if _FFR_ALLOW_SASLINFO
2288 	extern unsigned int SubmitMode;
2289 #endif /* _FFR_ALLOW_SASLINFO */
2290 #if STARTTLS || SM_CONF_SHM
2291 	char *newval;
2292 	char exbuf[MAXLINE];
2293 #endif /* STARTTLS || SM_CONF_SHM */
2294 
2295 	errno = 0;
2296 	if (opt == ' ')
2297 	{
2298 		/* full word options */
2299 		struct optioninfo *sel;
2300 
2301 		p = strchr(val, '=');
2302 		if (p == NULL)
2303 			p = &val[strlen(val)];
2304 		while (*--p == ' ')
2305 			continue;
2306 		while (*++p == ' ')
2307 			*p = '\0';
2308 		if (p == val)
2309 		{
2310 			syserr("readcf: null option name");
2311 			return;
2312 		}
2313 		if (*p == '=')
2314 			*p++ = '\0';
2315 		while (*p == ' ')
2316 			p++;
2317 		subopt = strchr(val, '.');
2318 		if (subopt != NULL)
2319 			*subopt++ = '\0';
2320 		sel = NULL;
2321 		for (o = OptionTab; o->o_name != NULL; o++)
2322 		{
2323 			if (sm_strncasecmp(o->o_name, val, strlen(val)) != 0)
2324 				continue;
2325 			if (strlen(o->o_name) == strlen(val))
2326 			{
2327 				/* completely specified -- this must be it */
2328 				sel = NULL;
2329 				break;
2330 			}
2331 			if (sel != NULL)
2332 				break;
2333 			sel = o;
2334 		}
2335 		if (sel != NULL && o->o_name == NULL)
2336 			o = sel;
2337 		else if (o->o_name == NULL)
2338 		{
2339 			syserr("readcf: unknown option name %s", val);
2340 			return;
2341 		}
2342 		else if (sel != NULL)
2343 		{
2344 			syserr("readcf: ambiguous option name %s (matches %s and %s)",
2345 				val, sel->o_name, o->o_name);
2346 			return;
2347 		}
2348 		if (strlen(val) != strlen(o->o_name))
2349 		{
2350 			int oldVerbose = Verbose;
2351 
2352 			Verbose = 1;
2353 			message("Option %s used as abbreviation for %s",
2354 				val, o->o_name);
2355 			Verbose = oldVerbose;
2356 		}
2357 		opt = o->o_code;
2358 		val = p;
2359 	}
2360 	else
2361 	{
2362 		for (o = OptionTab; o->o_name != NULL; o++)
2363 		{
2364 			if (o->o_code == opt)
2365 				break;
2366 		}
2367 		if (o->o_name == NULL)
2368 		{
2369 			syserr("readcf: unknown option name 0x%x", opt & 0xff);
2370 			return;
2371 		}
2372 		subopt = NULL;
2373 	}
2374 
2375 	if (subopt != NULL && !bitset(OI_SUBOPT, o->o_flags))
2376 	{
2377 		if (tTd(37, 1))
2378 			sm_dprintf("setoption: %s does not support suboptions, ignoring .%s\n",
2379 				   OPTNAME, subopt);
2380 		subopt = NULL;
2381 	}
2382 
2383 	if (tTd(37, 1))
2384 	{
2385 		sm_dprintf(isascii(opt) && isprint(opt) ?
2386 			   "setoption %s (%c)%s%s=" :
2387 			   "setoption %s (0x%x)%s%s=",
2388 			   OPTNAME, opt, subopt == NULL ? "" : ".",
2389 			   subopt == NULL ? "" : subopt);
2390 		xputs(sm_debug_file(), val);
2391 	}
2392 
2393 	/*
2394 	**  See if this option is preset for us.
2395 	*/
2396 
2397 	if (!sticky && bitnset(opt, StickyOpt))
2398 	{
2399 		if (tTd(37, 1))
2400 			sm_dprintf(" (ignored)\n");
2401 		return;
2402 	}
2403 
2404 	/*
2405 	**  Check to see if this option can be specified by this user.
2406 	*/
2407 
2408 	if (!safe && RealUid == 0)
2409 		safe = true;
2410 	if (!safe && !bitset(OI_SAFE, o->o_flags))
2411 	{
2412 		if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
2413 		{
2414 			int dp;
2415 
2416 			if (tTd(37, 1))
2417 				sm_dprintf(" (unsafe)");
2418 			dp = drop_privileges(true);
2419 			setstat(dp);
2420 		}
2421 	}
2422 	if (tTd(37, 1))
2423 		sm_dprintf("\n");
2424 
2425 	switch (opt & 0xff)
2426 	{
2427 	  case '7':		/* force seven-bit input */
2428 		SevenBitInput = atobool(val);
2429 		break;
2430 
2431 	  case '8':		/* handling of 8-bit input */
2432 #if MIME8TO7
2433 		switch (*val)
2434 		{
2435 		  case 'p':		/* pass 8 bit, convert MIME */
2436 			MimeMode = MM_CVTMIME|MM_PASS8BIT;
2437 			break;
2438 
2439 		  case 'm':		/* convert 8-bit, convert MIME */
2440 			MimeMode = MM_CVTMIME|MM_MIME8BIT;
2441 			break;
2442 
2443 		  case 's':		/* strict adherence */
2444 			MimeMode = MM_CVTMIME;
2445 			break;
2446 
2447 # if 0
2448 		  case 'r':		/* reject 8-bit, don't convert MIME */
2449 			MimeMode = 0;
2450 			break;
2451 
2452 		  case 'j':		/* "just send 8" */
2453 			MimeMode = MM_PASS8BIT;
2454 			break;
2455 
2456 		  case 'a':		/* encode 8 bit if available */
2457 			MimeMode = MM_MIME8BIT|MM_PASS8BIT|MM_CVTMIME;
2458 			break;
2459 
2460 		  case 'c':		/* convert 8 bit to MIME, never 7 bit */
2461 			MimeMode = MM_MIME8BIT;
2462 			break;
2463 # endif /* 0 */
2464 
2465 		  default:
2466 			syserr("Unknown 8-bit mode %c", *val);
2467 			finis(false, true, EX_USAGE);
2468 		}
2469 #else /* MIME8TO7 */
2470 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
2471 				     "Warning: Option: %s requires MIME8TO7 support\n",
2472 				     OPTNAME);
2473 #endif /* MIME8TO7 */
2474 		break;
2475 
2476 	  case 'A':		/* set default alias file */
2477 		if (val[0] == '\0')
2478 		{
2479 			char *al;
2480 
2481 			SET_OPT_DEFAULT(al, "aliases");
2482 			setalias(al);
2483 		}
2484 		else
2485 			setalias(val);
2486 		break;
2487 
2488 	  case 'a':		/* look N minutes for "@:@" in alias file */
2489 		if (val[0] == '\0')
2490 			SafeAlias = 5 MINUTES;
2491 		else
2492 			SafeAlias = convtime(val, 'm');
2493 		break;
2494 
2495 	  case 'B':		/* substitution for blank character */
2496 		SpaceSub = val[0];
2497 		if (SpaceSub == '\0')
2498 			SpaceSub = ' ';
2499 		break;
2500 
2501 	  case 'b':		/* min blocks free on queue fs/max msg size */
2502 		p = strchr(val, '/');
2503 		if (p != NULL)
2504 		{
2505 			*p++ = '\0';
2506 			MaxMessageSize = atol(p);
2507 		}
2508 		MinBlocksFree = atol(val);
2509 		break;
2510 
2511 	  case 'c':		/* don't connect to "expensive" mailers */
2512 		NoConnect = atobool(val);
2513 		break;
2514 
2515 	  case 'C':		/* checkpoint every N addresses */
2516 		if (safe || CheckpointInterval > atoi(val))
2517 			CheckpointInterval = atoi(val);
2518 		break;
2519 
2520 	  case 'd':		/* delivery mode */
2521 		switch (*val)
2522 		{
2523 		  case '\0':
2524 			set_delivery_mode(SM_DELIVER, e);
2525 			break;
2526 
2527 		  case SM_QUEUE:	/* queue only */
2528 		  case SM_DEFER:	/* queue only and defer map lookups */
2529 		  case SM_DELIVER:	/* do everything */
2530 		  case SM_FORK:		/* fork after verification */
2531 #if _FFR_DM_ONE
2532 		/* deliver first TA in background, then queue */
2533 		  case SM_DM_ONE:
2534 #endif /* _FFR_DM_ONE */
2535 			set_delivery_mode(*val, e);
2536 			break;
2537 
2538 		  default:
2539 			syserr("Unknown delivery mode %c", *val);
2540 			finis(false, true, EX_USAGE);
2541 		}
2542 		break;
2543 
2544 	  case 'E':		/* error message header/header file */
2545 		if (*val != '\0')
2546 			ErrMsgFile = newstr(val);
2547 		break;
2548 
2549 	  case 'e':		/* set error processing mode */
2550 		switch (*val)
2551 		{
2552 		  case EM_QUIET:	/* be silent about it */
2553 		  case EM_MAIL:		/* mail back */
2554 		  case EM_BERKNET:	/* do berknet error processing */
2555 		  case EM_WRITE:	/* write back (or mail) */
2556 		  case EM_PRINT:	/* print errors normally (default) */
2557 			e->e_errormode = *val;
2558 			break;
2559 		}
2560 		break;
2561 
2562 	  case 'F':		/* file mode */
2563 		FileMode = atooct(val) & 0777;
2564 		break;
2565 
2566 	  case 'f':		/* save Unix-style From lines on front */
2567 		SaveFrom = atobool(val);
2568 		break;
2569 
2570 	  case 'G':		/* match recipients against GECOS field */
2571 		MatchGecos = atobool(val);
2572 		break;
2573 
2574 	  case 'g':		/* default gid */
2575   g_opt:
2576 		if (isascii(*val) && isdigit(*val))
2577 			DefGid = atoi(val);
2578 		else
2579 		{
2580 			register struct group *gr;
2581 
2582 			DefGid = -1;
2583 			gr = getgrnam(val);
2584 			if (gr == NULL)
2585 				syserr("readcf: option %c: unknown group %s",
2586 					opt, val);
2587 			else
2588 				DefGid = gr->gr_gid;
2589 		}
2590 		break;
2591 
2592 	  case 'H':		/* help file */
2593 		if (val[0] == '\0')
2594 		{
2595 			SET_OPT_DEFAULT(HelpFile, "helpfile");
2596 		}
2597 		else
2598 		{
2599 			CANONIFY(val);
2600 			HelpFile = newstr(val);
2601 		}
2602 		break;
2603 
2604 	  case 'h':		/* maximum hop count */
2605 		MaxHopCount = atoi(val);
2606 		break;
2607 
2608 	  case 'I':		/* use internet domain name server */
2609 #if NAMED_BIND
2610 		for (p = val; *p != 0; )
2611 		{
2612 			bool clearmode;
2613 			char *q;
2614 			struct resolverflags *rfp;
2615 
2616 			while (*p == ' ')
2617 				p++;
2618 			if (*p == '\0')
2619 				break;
2620 			clearmode = false;
2621 			if (*p == '-')
2622 				clearmode = true;
2623 			else if (*p != '+')
2624 				p--;
2625 			p++;
2626 			q = p;
2627 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
2628 				p++;
2629 			if (*p != '\0')
2630 				*p++ = '\0';
2631 			if (sm_strcasecmp(q, "HasWildcardMX") == 0)
2632 			{
2633 				HasWildcardMX = !clearmode;
2634 				continue;
2635 			}
2636 			if (sm_strcasecmp(q, "WorkAroundBrokenAAAA") == 0)
2637 			{
2638 				WorkAroundBrokenAAAA = !clearmode;
2639 				continue;
2640 			}
2641 			for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
2642 			{
2643 				if (sm_strcasecmp(q, rfp->rf_name) == 0)
2644 					break;
2645 			}
2646 			if (rfp->rf_name == NULL)
2647 				syserr("readcf: I option value %s unrecognized", q);
2648 			else if (clearmode)
2649 				_res.options &= ~rfp->rf_bits;
2650 			else
2651 				_res.options |= rfp->rf_bits;
2652 		}
2653 		if (tTd(8, 2))
2654 			sm_dprintf("_res.options = %x, HasWildcardMX = %d\n",
2655 				   (unsigned int) _res.options, HasWildcardMX);
2656 #else /* NAMED_BIND */
2657 		usrerr("name server (I option) specified but BIND not compiled in");
2658 #endif /* NAMED_BIND */
2659 		break;
2660 
2661 	  case 'i':		/* ignore dot lines in message */
2662 		IgnrDot = atobool(val);
2663 		break;
2664 
2665 	  case 'j':		/* send errors in MIME (RFC 1341) format */
2666 		SendMIMEErrors = atobool(val);
2667 		break;
2668 
2669 	  case 'J':		/* .forward search path */
2670 		CANONIFY(val);
2671 		ForwardPath = newstr(val);
2672 		break;
2673 
2674 	  case 'k':		/* connection cache size */
2675 		MaxMciCache = atoi(val);
2676 		if (MaxMciCache < 0)
2677 			MaxMciCache = 0;
2678 		break;
2679 
2680 	  case 'K':		/* connection cache timeout */
2681 		MciCacheTimeout = convtime(val, 'm');
2682 		break;
2683 
2684 	  case 'l':		/* use Errors-To: header */
2685 		UseErrorsTo = atobool(val);
2686 		break;
2687 
2688 	  case 'L':		/* log level */
2689 		if (safe || LogLevel < atoi(val))
2690 			LogLevel = atoi(val);
2691 		break;
2692 
2693 	  case 'M':		/* define macro */
2694 		sticky = false;
2695 		mid = macid_parse(val, &ep);
2696 		if (mid == 0)
2697 			break;
2698 		p = newstr(ep);
2699 		if (!safe)
2700 			cleanstrcpy(p, p, strlen(p) + 1);
2701 		macdefine(&CurEnv->e_macro, A_TEMP, mid, p);
2702 		break;
2703 
2704 	  case 'm':		/* send to me too */
2705 		MeToo = atobool(val);
2706 		break;
2707 
2708 	  case 'n':		/* validate RHS in newaliases */
2709 		CheckAliases = atobool(val);
2710 		break;
2711 
2712 	    /* 'N' available -- was "net name" */
2713 
2714 	  case 'O':		/* daemon options */
2715 		if (!setdaemonoptions(val))
2716 			syserr("too many daemons defined (%d max)", MAXDAEMONS);
2717 		break;
2718 
2719 	  case 'o':		/* assume old style headers */
2720 		if (atobool(val))
2721 			CurEnv->e_flags |= EF_OLDSTYLE;
2722 		else
2723 			CurEnv->e_flags &= ~EF_OLDSTYLE;
2724 		break;
2725 
2726 	  case 'p':		/* select privacy level */
2727 		p = val;
2728 		for (;;)
2729 		{
2730 			register struct prival *pv;
2731 			extern struct prival PrivacyValues[];
2732 
2733 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
2734 				p++;
2735 			if (*p == '\0')
2736 				break;
2737 			val = p;
2738 			while (isascii(*p) && isalnum(*p))
2739 				p++;
2740 			if (*p != '\0')
2741 				*p++ = '\0';
2742 
2743 			for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
2744 			{
2745 				if (sm_strcasecmp(val, pv->pv_name) == 0)
2746 					break;
2747 			}
2748 			if (pv->pv_name == NULL)
2749 				syserr("readcf: Op line: %s unrecognized", val);
2750 			else
2751 				PrivacyFlags |= pv->pv_flag;
2752 		}
2753 		sticky = false;
2754 		break;
2755 
2756 	  case 'P':		/* postmaster copy address for returned mail */
2757 		PostMasterCopy = newstr(val);
2758 		break;
2759 
2760 	  case 'q':		/* slope of queue only function */
2761 		QueueFactor = atoi(val);
2762 		break;
2763 
2764 	  case 'Q':		/* queue directory */
2765 		if (val[0] == '\0')
2766 		{
2767 			QueueDir = "mqueue";
2768 		}
2769 		else
2770 		{
2771 			QueueDir = newstr(val);
2772 		}
2773 		if (RealUid != 0 && !safe)
2774 			Warn_Q_option = true;
2775 		break;
2776 
2777 	  case 'R':		/* don't prune routes */
2778 		DontPruneRoutes = atobool(val);
2779 		break;
2780 
2781 	  case 'r':		/* read timeout */
2782 		if (subopt == NULL)
2783 			inittimeouts(val, sticky);
2784 		else
2785 			settimeout(subopt, val, sticky);
2786 		break;
2787 
2788 	  case 'S':		/* status file */
2789 		if (val[0] == '\0')
2790 		{
2791 			SET_OPT_DEFAULT(StatFile, "statistics");
2792 		}
2793 		else
2794 		{
2795 			CANONIFY(val);
2796 			StatFile = newstr(val);
2797 		}
2798 		break;
2799 
2800 	  case 's':		/* be super safe, even if expensive */
2801 		if (tolower(*val) == 'i')
2802 			SuperSafe = SAFE_INTERACTIVE;
2803 		else if (tolower(*val) == 'p')
2804 #if MILTER
2805 			SuperSafe = SAFE_REALLY_POSTMILTER;
2806 #else /* MILTER */
2807 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
2808 				"Warning: SuperSafe=PostMilter requires Milter support (-DMILTER)\n");
2809 #endif /* MILTER */
2810 		else
2811 			SuperSafe = atobool(val) ? SAFE_REALLY : SAFE_NO;
2812 		break;
2813 
2814 	  case 'T':		/* queue timeout */
2815 		p = strchr(val, '/');
2816 		if (p != NULL)
2817 		{
2818 			*p++ = '\0';
2819 			settimeout("queuewarn", p, sticky);
2820 		}
2821 		settimeout("queuereturn", val, sticky);
2822 		break;
2823 
2824 	  case 't':		/* time zone name */
2825 		TimeZoneSpec = newstr(val);
2826 		break;
2827 
2828 	  case 'U':		/* location of user database */
2829 		UdbSpec = newstr(val);
2830 		break;
2831 
2832 	  case 'u':		/* set default uid */
2833 		for (p = val; *p != '\0'; p++)
2834 		{
2835 # if _FFR_DOTTED_USERNAMES
2836 			if (*p == '/' || *p == ':')
2837 # else /* _FFR_DOTTED_USERNAMES */
2838 			if (*p == '.' || *p == '/' || *p == ':')
2839 # endif /* _FFR_DOTTED_USERNAMES */
2840 			{
2841 				*p++ = '\0';
2842 				break;
2843 			}
2844 		}
2845 		if (isascii(*val) && isdigit(*val))
2846 		{
2847 			DefUid = atoi(val);
2848 			setdefuser();
2849 		}
2850 		else
2851 		{
2852 			register struct passwd *pw;
2853 
2854 			DefUid = -1;
2855 			pw = sm_getpwnam(val);
2856 			if (pw == NULL)
2857 			{
2858 				syserr("readcf: option u: unknown user %s", val);
2859 				break;
2860 			}
2861 			else
2862 			{
2863 				DefUid = pw->pw_uid;
2864 				DefGid = pw->pw_gid;
2865 				DefUser = newstr(pw->pw_name);
2866 			}
2867 		}
2868 
2869 # ifdef UID_MAX
2870 		if (DefUid > UID_MAX)
2871 		{
2872 			syserr("readcf: option u: uid value (%ld) > UID_MAX (%ld); ignored",
2873 				(long)DefUid, (long)UID_MAX);
2874 			break;
2875 		}
2876 # endif /* UID_MAX */
2877 
2878 		/* handle the group if it is there */
2879 		if (*p == '\0')
2880 			break;
2881 		val = p;
2882 		goto g_opt;
2883 
2884 	  case 'V':		/* fallback MX host */
2885 		if (val[0] != '\0')
2886 			FallbackMX = newstr(val);
2887 		break;
2888 
2889 	  case 'v':		/* run in verbose mode */
2890 		Verbose = atobool(val) ? 1 : 0;
2891 		break;
2892 
2893 	  case 'w':		/* if we are best MX, try host directly */
2894 		TryNullMXList = atobool(val);
2895 		break;
2896 
2897 	    /* 'W' available -- was wizard password */
2898 
2899 	  case 'x':		/* load avg at which to auto-queue msgs */
2900 		QueueLA = atoi(val);
2901 		break;
2902 
2903 	  case 'X':	/* load avg at which to auto-reject connections */
2904 		RefuseLA = atoi(val);
2905 		break;
2906 
2907 	  case O_DELAY_LA:	/* load avg at which to delay connections */
2908 		DelayLA = atoi(val);
2909 		break;
2910 
2911 	  case 'y':		/* work recipient factor */
2912 		WkRecipFact = atoi(val);
2913 		break;
2914 
2915 	  case 'Y':		/* fork jobs during queue runs */
2916 		ForkQueueRuns = atobool(val);
2917 		break;
2918 
2919 	  case 'z':		/* work message class factor */
2920 		WkClassFact = atoi(val);
2921 		break;
2922 
2923 	  case 'Z':		/* work time factor */
2924 		WkTimeFact = atoi(val);
2925 		break;
2926 
2927 
2928 #if _FFR_QUEUE_GROUP_SORTORDER
2929 	/* coordinate this with makequeue() */
2930 #endif /* _FFR_QUEUE_GROUP_SORTORDER */
2931 	  case O_QUEUESORTORD:	/* queue sorting order */
2932 		switch (*val)
2933 		{
2934 		  case 'f':	/* File Name */
2935 		  case 'F':
2936 			QueueSortOrder = QSO_BYFILENAME;
2937 			break;
2938 
2939 		  case 'h':	/* Host first */
2940 		  case 'H':
2941 			QueueSortOrder = QSO_BYHOST;
2942 			break;
2943 
2944 		  case 'm':	/* Modification time */
2945 		  case 'M':
2946 			QueueSortOrder = QSO_BYMODTIME;
2947 			break;
2948 
2949 		  case 'p':	/* Priority order */
2950 		  case 'P':
2951 			QueueSortOrder = QSO_BYPRIORITY;
2952 			break;
2953 
2954 		  case 't':	/* Submission time */
2955 		  case 'T':
2956 			QueueSortOrder = QSO_BYTIME;
2957 			break;
2958 
2959 		  case 'r':	/* Random */
2960 		  case 'R':
2961 			QueueSortOrder = QSO_RANDOM;
2962 			break;
2963 
2964 #if _FFR_RHS
2965 		  case 's':	/* Shuffled host name */
2966 		  case 'S':
2967 			QueueSortOrder = QSO_BYSHUFFLE;
2968 			break;
2969 #endif /* _FFR_RHS */
2970 
2971 		  case 'n':	/* none */
2972 		  case 'N':
2973 			QueueSortOrder = QSO_NONE;
2974 			break;
2975 
2976 		  default:
2977 			syserr("Invalid queue sort order \"%s\"", val);
2978 		}
2979 		break;
2980 
2981 	  case O_HOSTSFILE:	/* pathname of /etc/hosts file */
2982 		CANONIFY(val);
2983 		HostsFile = newstr(val);
2984 		break;
2985 
2986 	  case O_MQA:		/* minimum queue age between deliveries */
2987 		MinQueueAge = convtime(val, 'm');
2988 		break;
2989 
2990 	  case O_DEFCHARSET:	/* default character set for mimefying */
2991 		DefaultCharSet = newstr(denlstring(val, true, true));
2992 		break;
2993 
2994 	  case O_SSFILE:	/* service switch file */
2995 		CANONIFY(val);
2996 		ServiceSwitchFile = newstr(val);
2997 		break;
2998 
2999 	  case O_DIALDELAY:	/* delay for dial-on-demand operation */
3000 		DialDelay = convtime(val, 's');
3001 		break;
3002 
3003 	  case O_NORCPTACTION:	/* what to do if no recipient */
3004 		if (sm_strcasecmp(val, "none") == 0)
3005 			NoRecipientAction = NRA_NO_ACTION;
3006 		else if (sm_strcasecmp(val, "add-to") == 0)
3007 			NoRecipientAction = NRA_ADD_TO;
3008 		else if (sm_strcasecmp(val, "add-apparently-to") == 0)
3009 			NoRecipientAction = NRA_ADD_APPARENTLY_TO;
3010 		else if (sm_strcasecmp(val, "add-bcc") == 0)
3011 			NoRecipientAction = NRA_ADD_BCC;
3012 		else if (sm_strcasecmp(val, "add-to-undisclosed") == 0)
3013 			NoRecipientAction = NRA_ADD_TO_UNDISCLOSED;
3014 		else
3015 			syserr("Invalid NoRecipientAction: %s", val);
3016 		break;
3017 
3018 	  case O_SAFEFILEENV:	/* chroot() environ for writing to files */
3019 		if (*val == '\0')
3020 			break;
3021 
3022 		/* strip trailing slashes */
3023 		p = val + strlen(val) - 1;
3024 		while (p >= val && *p == '/')
3025 			*p-- = '\0';
3026 
3027 		if (*val == '\0')
3028 			break;
3029 
3030 		SafeFileEnv = newstr(val);
3031 		break;
3032 
3033 	  case O_MAXMSGSIZE:	/* maximum message size */
3034 		MaxMessageSize = atol(val);
3035 		break;
3036 
3037 	  case O_COLONOKINADDR:	/* old style handling of colon addresses */
3038 		ColonOkInAddr = atobool(val);
3039 		break;
3040 
3041 	  case O_MAXQUEUERUN:	/* max # of jobs in a single queue run */
3042 		MaxQueueRun = atoi(val);
3043 		break;
3044 
3045 	  case O_MAXCHILDREN:	/* max # of children of daemon */
3046 		MaxChildren = atoi(val);
3047 		break;
3048 
3049 	  case O_MAXQUEUECHILDREN: /* max # of children of daemon */
3050 		MaxQueueChildren = atoi(val);
3051 		break;
3052 
3053 	  case O_MAXRUNNERSPERQUEUE: /* max # runners in a queue group */
3054 		MaxRunnersPerQueue = atoi(val);
3055 		break;
3056 
3057 	  case O_NICEQUEUERUN:		/* nice queue runs */
3058 #if !HASNICE
3059 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3060 				     "Warning: NiceQueueRun set on system that doesn't support nice()\n");
3061 #endif /* !HASNICE */
3062 
3063 		/* XXX do we want to check the range? > 0 ? */
3064 		NiceQueueRun = atoi(val);
3065 		break;
3066 
3067 	  case O_SHMKEY:		/* shared memory key */
3068 #if SM_CONF_SHM
3069 		ShmKey = atol(val);
3070 #else /* SM_CONF_SHM */
3071 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3072 				     "Warning: Option: %s requires shared memory support (-DSM_CONF_SHM)\n",
3073 				     OPTNAME);
3074 #endif /* SM_CONF_SHM */
3075 		break;
3076 
3077 	  case O_SHMKEYFILE:		/* shared memory key file */
3078 #if SM_CONF_SHM
3079 		SET_STRING_EXP(ShmKeyFile);
3080 #else /* SM_CONF_SHM */
3081 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3082 				     "Warning: Option: %s requires shared memory support (-DSM_CONF_SHM)\n",
3083 				     OPTNAME);
3084 		break;
3085 #endif /* SM_CONF_SHM */
3086 
3087 #if _FFR_MAX_FORWARD_ENTRIES
3088 	  case O_MAXFORWARD:	/* max # of forward entries */
3089 		MaxForwardEntries = atoi(val);
3090 		break;
3091 #endif /* _FFR_MAX_FORWARD_ENTRIES */
3092 
3093 	  case O_KEEPCNAMES:	/* don't expand CNAME records */
3094 		DontExpandCnames = atobool(val);
3095 		break;
3096 
3097 	  case O_MUSTQUOTE:	/* must quote these characters in phrases */
3098 		(void) sm_strlcpy(buf, "@,;:\\()[]", sizeof(buf));
3099 		if (strlen(val) < sizeof(buf) - 10)
3100 			(void) sm_strlcat(buf, val, sizeof(buf));
3101 		else
3102 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3103 					     "Warning: MustQuoteChars too long, ignored.\n");
3104 		MustQuoteChars = newstr(buf);
3105 		break;
3106 
3107 	  case O_SMTPGREETING:	/* SMTP greeting message (old $e macro) */
3108 		SmtpGreeting = newstr(munchstring(val, NULL, '\0'));
3109 		break;
3110 
3111 	  case O_UNIXFROM:	/* UNIX From_ line (old $l macro) */
3112 		UnixFromLine = newstr(munchstring(val, NULL, '\0'));
3113 		break;
3114 
3115 	  case O_OPCHARS:	/* operator characters (old $o macro) */
3116 		if (OperatorChars != NULL)
3117 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3118 					     "Warning: OperatorChars is being redefined.\n         It should only be set before ruleset definitions.\n");
3119 		OperatorChars = newstr(munchstring(val, NULL, '\0'));
3120 		break;
3121 
3122 	  case O_DONTINITGRPS:	/* don't call initgroups(3) */
3123 		DontInitGroups = atobool(val);
3124 		break;
3125 
3126 	  case O_SLFH:		/* make sure from fits on one line */
3127 		SingleLineFromHeader = atobool(val);
3128 		break;
3129 
3130 	  case O_ABH:		/* allow HELO commands with syntax errors */
3131 		AllowBogusHELO = atobool(val);
3132 		break;
3133 
3134 	  case O_CONNTHROT:	/* connection rate throttle */
3135 		ConnRateThrottle = atoi(val);
3136 		break;
3137 
3138 	  case O_UGW:		/* group writable files are unsafe */
3139 		if (!atobool(val))
3140 		{
3141 			setbitn(DBS_GROUPWRITABLEFORWARDFILESAFE,
3142 				DontBlameSendmail);
3143 			setbitn(DBS_GROUPWRITABLEINCLUDEFILESAFE,
3144 				DontBlameSendmail);
3145 		}
3146 		break;
3147 
3148 	  case O_DBLBOUNCE:	/* address to which to send double bounces */
3149 		DoubleBounceAddr = newstr(val);
3150 		break;
3151 
3152 	  case O_HSDIR:		/* persistent host status directory */
3153 		if (val[0] != '\0')
3154 		{
3155 			CANONIFY(val);
3156 			HostStatDir = newstr(val);
3157 		}
3158 		break;
3159 
3160 	  case O_SINGTHREAD:	/* single thread deliveries (requires hsdir) */
3161 		SingleThreadDelivery = atobool(val);
3162 		break;
3163 
3164 	  case O_RUNASUSER:	/* run bulk of code as this user */
3165 		for (p = val; *p != '\0'; p++)
3166 		{
3167 # if _FFR_DOTTED_USERNAMES
3168 			if (*p == '/' || *p == ':')
3169 # else /* _FFR_DOTTED_USERNAMES */
3170 			if (*p == '.' || *p == '/' || *p == ':')
3171 # endif /* _FFR_DOTTED_USERNAMES */
3172 			{
3173 				*p++ = '\0';
3174 				break;
3175 			}
3176 		}
3177 		if (isascii(*val) && isdigit(*val))
3178 		{
3179 			if (can_setuid)
3180 				RunAsUid = atoi(val);
3181 		}
3182 		else
3183 		{
3184 			register struct passwd *pw;
3185 
3186 			pw = sm_getpwnam(val);
3187 			if (pw == NULL)
3188 			{
3189 				syserr("readcf: option RunAsUser: unknown user %s", val);
3190 				break;
3191 			}
3192 			else if (can_setuid)
3193 			{
3194 				if (*p == '\0')
3195 					RunAsUserName = newstr(val);
3196 				RunAsUid = pw->pw_uid;
3197 				RunAsGid = pw->pw_gid;
3198 			}
3199 			else if (EffGid == pw->pw_gid)
3200 				RunAsGid = pw->pw_gid;
3201 			else if (UseMSP && *p == '\0')
3202 				(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3203 						     "WARNING: RunAsUser for MSP ignored, check group ids (egid=%d, want=%d)\n",
3204 						     (int) EffGid,
3205 						     (int) pw->pw_gid);
3206 		}
3207 # ifdef UID_MAX
3208 		if (RunAsUid > UID_MAX)
3209 		{
3210 			syserr("readcf: option RunAsUser: uid value (%ld) > UID_MAX (%ld); ignored",
3211 				(long) RunAsUid, (long) UID_MAX);
3212 			break;
3213 		}
3214 # endif /* UID_MAX */
3215 		if (*p != '\0')
3216 		{
3217 			if (isascii(*p) && isdigit(*p))
3218 			{
3219 				gid_t runasgid;
3220 
3221 				runasgid = (gid_t) atoi(p);
3222 				if (can_setuid || EffGid == runasgid)
3223 					RunAsGid = runasgid;
3224 				else if (UseMSP)
3225 					(void) sm_io_fprintf(smioout,
3226 							     SM_TIME_DEFAULT,
3227 							     "WARNING: RunAsUser for MSP ignored, check group ids (egid=%d, want=%d)\n",
3228 							     (int) EffGid,
3229 							     (int) runasgid);
3230 			}
3231 			else
3232 			{
3233 				register struct group *gr;
3234 
3235 				gr = getgrnam(p);
3236 				if (gr == NULL)
3237 					syserr("readcf: option RunAsUser: unknown group %s",
3238 						p);
3239 				else if (can_setuid || EffGid == gr->gr_gid)
3240 					RunAsGid = gr->gr_gid;
3241 				else if (UseMSP)
3242 					(void) sm_io_fprintf(smioout,
3243 							     SM_TIME_DEFAULT,
3244 							     "WARNING: RunAsUser for MSP ignored, check group ids (egid=%d, want=%d)\n",
3245 							     (int) EffGid,
3246 							     (int) gr->gr_gid);
3247 			}
3248 		}
3249 		if (tTd(47, 5))
3250 			sm_dprintf("readcf: RunAsUser = %d:%d\n",
3251 				   (int) RunAsUid, (int) RunAsGid);
3252 		break;
3253 
3254 	  case O_DSN_RRT:
3255 		RrtImpliesDsn = atobool(val);
3256 		break;
3257 
3258 	  case O_PIDFILE:
3259 		PSTRSET(PidFile, val);
3260 		break;
3261 
3262 	  case O_DONTBLAMESENDMAIL:
3263 		p = val;
3264 		for (;;)
3265 		{
3266 			register struct dbsval *dbs;
3267 			extern struct dbsval DontBlameSendmailValues[];
3268 
3269 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
3270 				p++;
3271 			if (*p == '\0')
3272 				break;
3273 			val = p;
3274 			while (isascii(*p) && isalnum(*p))
3275 				p++;
3276 			if (*p != '\0')
3277 				*p++ = '\0';
3278 
3279 			for (dbs = DontBlameSendmailValues;
3280 			     dbs->dbs_name != NULL; dbs++)
3281 			{
3282 				if (sm_strcasecmp(val, dbs->dbs_name) == 0)
3283 					break;
3284 			}
3285 			if (dbs->dbs_name == NULL)
3286 				syserr("readcf: DontBlameSendmail option: %s unrecognized", val);
3287 			else if (dbs->dbs_flag == DBS_SAFE)
3288 				clrbitmap(DontBlameSendmail);
3289 			else
3290 				setbitn(dbs->dbs_flag, DontBlameSendmail);
3291 		}
3292 		sticky = false;
3293 		break;
3294 
3295 	  case O_DPI:
3296 		if (sm_strcasecmp(val, "loopback") == 0)
3297 			DontProbeInterfaces = DPI_SKIPLOOPBACK;
3298 		else if (atobool(val))
3299 			DontProbeInterfaces = DPI_PROBENONE;
3300 		else
3301 			DontProbeInterfaces = DPI_PROBEALL;
3302 		break;
3303 
3304 	  case O_MAXRCPT:
3305 		MaxRcptPerMsg = atoi(val);
3306 		break;
3307 
3308 	  case O_RCPTTHROT:
3309 		BadRcptThrottle = atoi(val);
3310 		break;
3311 
3312 	  case O_DEADLETTER:
3313 		CANONIFY(val);
3314 		PSTRSET(DeadLetterDrop, val);
3315 		break;
3316 
3317 #if _FFR_DONTLOCKFILESFORREAD_OPTION
3318 	  case O_DONTLOCK:
3319 		DontLockReadFiles = atobool(val);
3320 		break;
3321 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
3322 
3323 	  case O_MAXALIASRCSN:
3324 		MaxAliasRecursion = atoi(val);
3325 		break;
3326 
3327 	  case O_CNCTONLYTO:
3328 		/* XXX should probably use gethostbyname */
3329 #if NETINET || NETINET6
3330 		ConnectOnlyTo.sa.sa_family = AF_UNSPEC;
3331 # if NETINET6
3332 		if (anynet_pton(AF_INET6, val,
3333 				&ConnectOnlyTo.sin6.sin6_addr) != 1)
3334 			ConnectOnlyTo.sa.sa_family = AF_INET6;
3335 		else
3336 # endif /* NETINET6 */
3337 # if NETINET
3338 		{
3339 			ConnectOnlyTo.sin.sin_addr.s_addr = inet_addr(val);
3340 			if (ConnectOnlyTo.sin.sin_addr.s_addr != INADDR_NONE)
3341 				ConnectOnlyTo.sa.sa_family = AF_INET;
3342 		}
3343 
3344 # endif /* NETINET */
3345 		if (ConnectOnlyTo.sa.sa_family == AF_UNSPEC)
3346 		{
3347 			syserr("readcf: option ConnectOnlyTo: invalid IP address %s",
3348 			       val);
3349 			break;
3350 		}
3351 #endif /* NETINET || NETINET6 */
3352 		break;
3353 
3354 	  case O_TRUSTUSER:
3355 # if !HASFCHOWN && !defined(_FFR_DROP_TRUSTUSER_WARNING)
3356 		if (!UseMSP)
3357 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3358 					     "readcf: option TrustedUser may cause problems on systems\n        which do not support fchown() if UseMSP is not set.\n");
3359 # endif /* !HASFCHOWN && !defined(_FFR_DROP_TRUSTUSER_WARNING) */
3360 		if (isascii(*val) && isdigit(*val))
3361 			TrustedUid = atoi(val);
3362 		else
3363 		{
3364 			register struct passwd *pw;
3365 
3366 			TrustedUid = 0;
3367 			pw = sm_getpwnam(val);
3368 			if (pw == NULL)
3369 			{
3370 				syserr("readcf: option TrustedUser: unknown user %s", val);
3371 				break;
3372 			}
3373 			else
3374 				TrustedUid = pw->pw_uid;
3375 		}
3376 
3377 # ifdef UID_MAX
3378 		if (TrustedUid > UID_MAX)
3379 		{
3380 			syserr("readcf: option TrustedUser: uid value (%ld) > UID_MAX (%ld)",
3381 				(long) TrustedUid, (long) UID_MAX);
3382 			TrustedUid = 0;
3383 		}
3384 # endif /* UID_MAX */
3385 		break;
3386 
3387 	  case O_MAXMIMEHDRLEN:
3388 		p = strchr(val, '/');
3389 		if (p != NULL)
3390 			*p++ = '\0';
3391 		MaxMimeHeaderLength = atoi(val);
3392 		if (p != NULL && *p != '\0')
3393 			MaxMimeFieldLength = atoi(p);
3394 		else
3395 			MaxMimeFieldLength = MaxMimeHeaderLength / 2;
3396 
3397 		if (MaxMimeHeaderLength <= 0)
3398 			MaxMimeHeaderLength = 0;
3399 		else if (MaxMimeHeaderLength < 128)
3400 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3401 					     "Warning: MaxMimeHeaderLength: header length limit set lower than 128\n");
3402 
3403 		if (MaxMimeFieldLength <= 0)
3404 			MaxMimeFieldLength = 0;
3405 		else if (MaxMimeFieldLength < 40)
3406 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3407 					     "Warning: MaxMimeHeaderLength: field length limit set lower than 40\n");
3408 
3409 		/*
3410 		**  Headers field values now include leading space, so let's
3411 		**  adjust the values to be "backward compatible".
3412 		*/
3413 
3414 		if (MaxMimeHeaderLength > 0)
3415 			MaxMimeHeaderLength++;
3416 		if (MaxMimeFieldLength > 0)
3417 			MaxMimeFieldLength++;
3418 		break;
3419 
3420 	  case O_CONTROLSOCKET:
3421 		PSTRSET(ControlSocketName, val);
3422 		break;
3423 
3424 	  case O_MAXHDRSLEN:
3425 		MaxHeadersLength = atoi(val);
3426 
3427 		if (MaxHeadersLength > 0 &&
3428 		    MaxHeadersLength < (MAXHDRSLEN / 2))
3429 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3430 					     "Warning: MaxHeadersLength: headers length limit set lower than %d\n",
3431 					     (MAXHDRSLEN / 2));
3432 		break;
3433 
3434 	  case O_PROCTITLEPREFIX:
3435 		PSTRSET(ProcTitlePrefix, val);
3436 		break;
3437 
3438 #if SASL
3439 	  case O_SASLINFO:
3440 # if _FFR_ALLOW_SASLINFO
3441 		/*
3442 		**  Allow users to select their own authinfo file
3443 		**  under certain circumstances, otherwise just ignore
3444 		**  the option.  If the option isn't ignored, several
3445 		**  commands don't work very well, e.g., mailq.
3446 		**  However, this is not a "perfect" solution.
3447 		**  If mail is queued, the authentication info
3448 		**  will not be used in subsequent delivery attempts.
3449 		**  If we really want to support this, then it has
3450 		**  to be stored in the queue file.
3451 		*/
3452 		if (!bitset(SUBMIT_MSA, SubmitMode) && RealUid != 0 &&
3453 		    RunAsUid != RealUid)
3454 			break;
3455 # endif /* _FFR_ALLOW_SASLINFO */
3456 		PSTRSET(SASLInfo, val);
3457 		break;
3458 
3459 	  case O_SASLMECH:
3460 		if (AuthMechanisms != NULL)
3461 			sm_free(AuthMechanisms); /* XXX */
3462 		if (*val != '\0')
3463 			AuthMechanisms = newstr(val);
3464 		else
3465 			AuthMechanisms = NULL;
3466 		break;
3467 
3468 	  case O_SASLREALM:
3469 		if (AuthRealm != NULL)
3470 			sm_free(AuthRealm);
3471 		if (*val != '\0')
3472 			AuthRealm = newstr(val);
3473 		else
3474 			AuthRealm = NULL;
3475 		break;
3476 
3477 	  case O_SASLOPTS:
3478 		while (val != NULL && *val != '\0')
3479 		{
3480 			switch (*val)
3481 			{
3482 			  case 'A':
3483 				SASLOpts |= SASL_AUTH_AUTH;
3484 				break;
3485 
3486 			  case 'a':
3487 				SASLOpts |= SASL_SEC_NOACTIVE;
3488 				break;
3489 
3490 			  case 'c':
3491 				SASLOpts |= SASL_SEC_PASS_CREDENTIALS;
3492 				break;
3493 
3494 			  case 'd':
3495 				SASLOpts |= SASL_SEC_NODICTIONARY;
3496 				break;
3497 
3498 			  case 'f':
3499 				SASLOpts |= SASL_SEC_FORWARD_SECRECY;
3500 				break;
3501 
3502 #  if SASL >= 20101
3503 			  case 'm':
3504 				SASLOpts |= SASL_SEC_MUTUAL_AUTH;
3505 				break;
3506 #  endif /* SASL >= 20101 */
3507 
3508 			  case 'p':
3509 				SASLOpts |= SASL_SEC_NOPLAINTEXT;
3510 				break;
3511 
3512 			  case 'y':
3513 				SASLOpts |= SASL_SEC_NOANONYMOUS;
3514 				break;
3515 
3516 			  case ' ':	/* ignore */
3517 			  case '\t':	/* ignore */
3518 			  case ',':	/* ignore */
3519 				break;
3520 
3521 			  default:
3522 				(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3523 						     "Warning: Option: %s unknown parameter '%c'\n",
3524 						     OPTNAME,
3525 						     (isascii(*val) &&
3526 							isprint(*val))
3527 							? *val : '?');
3528 				break;
3529 			}
3530 			++val;
3531 			val = strpbrk(val, ", \t");
3532 			if (val != NULL)
3533 				++val;
3534 		}
3535 		break;
3536 
3537 	  case O_SASLBITS:
3538 		MaxSLBits = atoi(val);
3539 		break;
3540 
3541 #else /* SASL */
3542 	  case O_SASLINFO:
3543 	  case O_SASLMECH:
3544 	  case O_SASLREALM:
3545 	  case O_SASLOPTS:
3546 	  case O_SASLBITS:
3547 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3548 				     "Warning: Option: %s requires SASL support (-DSASL)\n",
3549 				     OPTNAME);
3550 		break;
3551 #endif /* SASL */
3552 
3553 #if STARTTLS
3554 	  case O_SRVCERTFILE:
3555 		SET_STRING_EXP(SrvCertFile);
3556 	  case O_SRVKEYFILE:
3557 		SET_STRING_EXP(SrvKeyFile);
3558 	  case O_CLTCERTFILE:
3559 		SET_STRING_EXP(CltCertFile);
3560 	  case O_CLTKEYFILE:
3561 		SET_STRING_EXP(CltKeyFile);
3562 	  case O_CACERTFILE:
3563 		SET_STRING_EXP(CACertFile);
3564 	  case O_CACERTPATH:
3565 		SET_STRING_EXP(CACertPath);
3566 	  case O_DHPARAMS:
3567 		SET_STRING_EXP(DHParams);
3568 # if _FFR_TLS_1
3569 	  case O_DHPARAMS5:
3570 		SET_STRING_EXP(DHParams5);
3571 	  case O_CIPHERLIST:
3572 		SET_STRING_EXP(CipherList);
3573 # endif /* _FFR_TLS_1 */
3574 	  case O_CRLFILE:
3575 # if OPENSSL_VERSION_NUMBER > 0x00907000L
3576 		SET_STRING_EXP(CRLFile);
3577 # else /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3578 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3579 				     "Warning: Option: %s requires at least OpenSSL 0.9.7\n",
3580 				     OPTNAME);
3581 		break;
3582 # endif /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3583 
3584 # if _FFR_CRLPATH
3585 	  case O_CRLPATH:
3586 #  if OPENSSL_VERSION_NUMBER > 0x00907000L
3587 		SET_STRING_EXP(CRLPath);
3588 #  else /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3589 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3590 				     "Warning: Option: %s requires at least OpenSSL 0.9.7\n",
3591 				     OPTNAME);
3592 		break;
3593 #  endif /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3594 # endif /* _FFR_CRLPATH */
3595 
3596 	/*
3597 	**  XXX How about options per daemon/client instead of globally?
3598 	**  This doesn't work well for some options, e.g., no server cert,
3599 	**  but fine for others.
3600 	**
3601 	**  XXX Some people may want different certs per server.
3602 	**
3603 	**  See also srvfeatures()
3604 	*/
3605 
3606 	  case O_TLS_SRV_OPTS:
3607 		while (val != NULL && *val != '\0')
3608 		{
3609 			switch (*val)
3610 			{
3611 			  case 'V':
3612 				TLS_Srv_Opts |= TLS_I_NO_VRFY;
3613 				break;
3614 # if _FFR_TLS_1
3615 			/*
3616 			**  Server without a cert? That works only if
3617 			**  AnonDH is enabled as cipher, which is not in the
3618 			**  default list. Hence the CipherList option must
3619 			**  be available. Moreover: which clients support this
3620 			**  besides sendmail with this setting?
3621 			*/
3622 
3623 			  case 'C':
3624 				TLS_Srv_Opts &= ~TLS_I_SRV_CERT;
3625 				break;
3626 # endif /* _FFR_TLS_1 */
3627 			  case ' ':	/* ignore */
3628 			  case '\t':	/* ignore */
3629 			  case ',':	/* ignore */
3630 				break;
3631 			  default:
3632 				(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3633 						     "Warning: Option: %s unknown parameter '%c'\n",
3634 						     OPTNAME,
3635 						     (isascii(*val) &&
3636 							isprint(*val))
3637 							? *val : '?');
3638 				break;
3639 			}
3640 			++val;
3641 			val = strpbrk(val, ", \t");
3642 			if (val != NULL)
3643 				++val;
3644 		}
3645 		break;
3646 
3647 	  case O_RANDFILE:
3648 		PSTRSET(RandFile, val);
3649 		break;
3650 
3651 #else /* STARTTLS */
3652 	  case O_SRVCERTFILE:
3653 	  case O_SRVKEYFILE:
3654 	  case O_CLTCERTFILE:
3655 	  case O_CLTKEYFILE:
3656 	  case O_CACERTFILE:
3657 	  case O_CACERTPATH:
3658 	  case O_DHPARAMS:
3659 # if _FFR_TLS_1
3660 	  case O_DHPARAMS5:
3661 	  case O_CIPHERLIST:
3662 # endif /* _FFR_TLS_1 */
3663 	  case O_CRLFILE:
3664 # if _FFR_CRLPATH
3665 	  case O_CRLPATH:
3666 # endif /* _FFR_CRLPATH */
3667 	  case O_RANDFILE:
3668 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3669 				     "Warning: Option: %s requires TLS support\n",
3670 				     OPTNAME);
3671 		break;
3672 
3673 #endif /* STARTTLS */
3674 
3675 	  case O_CLIENTPORT:
3676 		setclientoptions(val);
3677 		break;
3678 
3679 	  case O_DF_BUFSIZE:
3680 		DataFileBufferSize = atoi(val);
3681 		break;
3682 
3683 	  case O_XF_BUFSIZE:
3684 		XscriptFileBufferSize = atoi(val);
3685 		break;
3686 
3687 	  case O_LDAPDEFAULTSPEC:
3688 #if LDAPMAP
3689 		ldapmap_set_defaults(val);
3690 #else /* LDAPMAP */
3691 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3692 				     "Warning: Option: %s requires LDAP support (-DLDAPMAP)\n",
3693 				     OPTNAME);
3694 #endif /* LDAPMAP */
3695 		break;
3696 
3697 	  case O_INPUTMILTER:
3698 #if MILTER
3699 		InputFilterList = newstr(val);
3700 #else /* MILTER */
3701 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3702 				     "Warning: Option: %s requires Milter support (-DMILTER)\n",
3703 				     OPTNAME);
3704 #endif /* MILTER */
3705 		break;
3706 
3707 	  case O_MILTER:
3708 #if MILTER
3709 		milter_set_option(subopt, val, sticky);
3710 #else /* MILTER */
3711 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3712 				     "Warning: Option: %s requires Milter support (-DMILTER)\n",
3713 				     OPTNAME);
3714 #endif /* MILTER */
3715 		break;
3716 
3717 	  case O_QUEUE_FILE_MODE:	/* queue file mode */
3718 		QueueFileMode = atooct(val) & 0777;
3719 		break;
3720 
3721 	  case O_DLVR_MIN:	/* deliver by minimum time */
3722 		DeliverByMin = convtime(val, 's');
3723 		break;
3724 
3725 	  /* modifiers {daemon_flags} for direct submissions */
3726 	  case O_DIRECTSUBMODIFIERS:
3727 		{
3728 			BITMAP256 m;	/* ignored */
3729 			extern ENVELOPE BlankEnvelope;
3730 
3731 			macdefine(&BlankEnvelope.e_macro, A_PERM,
3732 				  macid("{daemon_flags}"),
3733 				  getmodifiers(val, m));
3734 		}
3735 		break;
3736 
3737 	  case O_FASTSPLIT:
3738 		FastSplit = atoi(val);
3739 		break;
3740 
3741 	  case O_MBDB:
3742 		Mbdb = newstr(val);
3743 		break;
3744 
3745 	  case O_MSQ:
3746 		UseMSP = atobool(val);
3747 		break;
3748 
3749 	  case O_SOFTBOUNCE:
3750 		SoftBounce = atobool(val);
3751 		break;
3752 
3753 	  case O_REJECTLOGINTERVAL:	/* time btwn log msgs while refusing */
3754 		RejectLogInterval = convtime(val, 'h');
3755 		break;
3756 
3757 	  case O_REQUIRES_DIR_FSYNC:
3758 #if REQUIRES_DIR_FSYNC
3759 		RequiresDirfsync = atobool(val);
3760 #else /* REQUIRES_DIR_FSYNC */
3761 		/* silently ignored... required for cf file option */
3762 #endif /* REQUIRES_DIR_FSYNC */
3763 		break;
3764 
3765 	  case O_CONNECTION_RATE_WINDOW_SIZE:
3766 		ConnectionRateWindowSize = convtime(val, 's');
3767 		break;
3768 
3769 	  case O_FALLBACKSMARTHOST:	/* fallback smart host */
3770 		if (val[0] != '\0')
3771 			FallbackSmartHost = newstr(val);
3772 		break;
3773 
3774 	  case O_HELONAME:
3775 		HeloName = newstr(val);
3776 		break;
3777 
3778 #if _FFR_MEMSTAT
3779 	  case O_REFUSELOWMEM:
3780 		RefuseLowMem = atoi(val);
3781 		break;
3782 	  case O_QUEUELOWMEM:
3783 		QueueLowMem = atoi(val);
3784 		break;
3785 	  case O_MEMRESOURCE:
3786 		MemoryResource = newstr(val);
3787 		break;
3788 #endif /* _FFR_MEMSTAT */
3789 
3790 	  case O_MAXNOOPCOMMANDS:
3791 		MaxNOOPCommands = atoi(val);
3792 		break;
3793 
3794 #if _FFR_MSG_ACCEPT
3795 	  case O_MSG_ACCEPT:
3796 		MessageAccept = newstr(val);
3797 		break;
3798 #endif /* _FFR_MSG_ACCEPT */
3799 
3800 #if _FFR_QUEUE_RUN_PARANOIA
3801 	  case O_CHK_Q_RUNNERS:
3802 		CheckQueueRunners = atoi(val);
3803 		break;
3804 #endif /* _FFR_QUEUE_RUN_PARANOIA */
3805 
3806 #if _FFR_EIGHT_BIT_ADDR_OK
3807 	  case O_EIGHT_BIT_ADDR_OK:
3808 		EightBitAddrOK = atobool(val);
3809 		break;
3810 #endif /* _FFR_EIGHT_BIT_ADDR_OK */
3811 
3812 	  default:
3813 		if (tTd(37, 1))
3814 		{
3815 			if (isascii(opt) && isprint(opt))
3816 				sm_dprintf("Warning: option %c unknown\n", opt);
3817 			else
3818 				sm_dprintf("Warning: option 0x%x unknown\n", opt);
3819 		}
3820 		break;
3821 	}
3822 
3823 	/*
3824 	**  Options with suboptions are responsible for taking care
3825 	**  of sticky-ness (e.g., that a command line setting is kept
3826 	**  when reading in the sendmail.cf file).  This has to be done
3827 	**  when the suboptions are parsed since each suboption must be
3828 	**  sticky, not the root option.
3829 	*/
3830 
3831 	if (sticky && !bitset(OI_SUBOPT, o->o_flags))
3832 		setbitn(opt, StickyOpt);
3833 }
3834 /*
3835 **  SETCLASS -- set a string into a class
3836 **
3837 **	Parameters:
3838 **		class -- the class to put the string in.
3839 **		str -- the string to enter
3840 **
3841 **	Returns:
3842 **		none.
3843 **
3844 **	Side Effects:
3845 **		puts the word into the symbol table.
3846 */
3847 
3848 void
3849 setclass(class, str)
3850 	int class;
3851 	char *str;
3852 {
3853 	register STAB *s;
3854 
3855 	if ((str[0] & 0377) == MATCHCLASS)
3856 	{
3857 		int mid;
3858 
3859 		str++;
3860 		mid = macid(str);
3861 		if (mid == 0)
3862 			return;
3863 
3864 		if (tTd(37, 8))
3865 			sm_dprintf("setclass(%s, $=%s)\n",
3866 				   macname(class), macname(mid));
3867 		copy_class(mid, class);
3868 	}
3869 	else
3870 	{
3871 		if (tTd(37, 8))
3872 			sm_dprintf("setclass(%s, %s)\n", macname(class), str);
3873 
3874 		s = stab(str, ST_CLASS, ST_ENTER);
3875 		setbitn(bitidx(class), s->s_class);
3876 	}
3877 }
3878 /*
3879 **  MAKEMAPENTRY -- create a map entry
3880 **
3881 **	Parameters:
3882 **		line -- the config file line
3883 **
3884 **	Returns:
3885 **		A pointer to the map that has been created.
3886 **		NULL if there was a syntax error.
3887 **
3888 **	Side Effects:
3889 **		Enters the map into the dictionary.
3890 */
3891 
3892 MAP *
3893 makemapentry(line)
3894 	char *line;
3895 {
3896 	register char *p;
3897 	char *mapname;
3898 	char *classname;
3899 	register STAB *s;
3900 	STAB *class;
3901 
3902 	for (p = line; isascii(*p) && isspace(*p); p++)
3903 		continue;
3904 	if (!(isascii(*p) && isalnum(*p)))
3905 	{
3906 		syserr("readcf: config K line: no map name");
3907 		return NULL;
3908 	}
3909 
3910 	mapname = p;
3911 	while ((isascii(*++p) && isalnum(*p)) || *p == '_' || *p == '.')
3912 		continue;
3913 	if (*p != '\0')
3914 		*p++ = '\0';
3915 	while (isascii(*p) && isspace(*p))
3916 		p++;
3917 	if (!(isascii(*p) && isalnum(*p)))
3918 	{
3919 		syserr("readcf: config K line, map %s: no map class", mapname);
3920 		return NULL;
3921 	}
3922 	classname = p;
3923 	while (isascii(*++p) && isalnum(*p))
3924 		continue;
3925 	if (*p != '\0')
3926 		*p++ = '\0';
3927 	while (isascii(*p) && isspace(*p))
3928 		p++;
3929 
3930 	/* look up the class */
3931 	class = stab(classname, ST_MAPCLASS, ST_FIND);
3932 	if (class == NULL)
3933 	{
3934 		syserr("readcf: map %s: class %s not available", mapname,
3935 			classname);
3936 		return NULL;
3937 	}
3938 
3939 	/* enter the map */
3940 	s = stab(mapname, ST_MAP, ST_ENTER);
3941 	s->s_map.map_class = &class->s_mapclass;
3942 	s->s_map.map_mname = newstr(mapname);
3943 
3944 	if (class->s_mapclass.map_parse(&s->s_map, p))
3945 		s->s_map.map_mflags |= MF_VALID;
3946 
3947 	if (tTd(37, 5))
3948 	{
3949 		sm_dprintf("map %s, class %s, flags %lx, file %s,\n",
3950 			   s->s_map.map_mname, s->s_map.map_class->map_cname,
3951 			   s->s_map.map_mflags, s->s_map.map_file);
3952 		sm_dprintf("\tapp %s, domain %s, rebuild %s\n",
3953 			   s->s_map.map_app, s->s_map.map_domain,
3954 			   s->s_map.map_rebuild);
3955 	}
3956 	return &s->s_map;
3957 }
3958 /*
3959 **  STRTORWSET -- convert string to rewriting set number
3960 **
3961 **	Parameters:
3962 **		p -- the pointer to the string to decode.
3963 **		endp -- if set, store the trailing delimiter here.
3964 **		stabmode -- ST_ENTER to create this entry, ST_FIND if
3965 **			it must already exist.
3966 **
3967 **	Returns:
3968 **		The appropriate ruleset number.
3969 **		-1 if it is not valid (error already printed)
3970 */
3971 
3972 int
3973 strtorwset(p, endp, stabmode)
3974 	char *p;
3975 	char **endp;
3976 	int stabmode;
3977 {
3978 	int ruleset;
3979 	static int nextruleset = MAXRWSETS;
3980 
3981 	while (isascii(*p) && isspace(*p))
3982 		p++;
3983 	if (!isascii(*p))
3984 	{
3985 		syserr("invalid ruleset name: \"%.20s\"", p);
3986 		return -1;
3987 	}
3988 	if (isdigit(*p))
3989 	{
3990 		ruleset = strtol(p, endp, 10);
3991 		if (ruleset >= MAXRWSETS / 2 || ruleset < 0)
3992 		{
3993 			syserr("bad ruleset %d (%d max)",
3994 				ruleset, MAXRWSETS / 2);
3995 			ruleset = -1;
3996 		}
3997 	}
3998 	else
3999 	{
4000 		STAB *s;
4001 		char delim;
4002 		char *q = NULL;
4003 
4004 		q = p;
4005 		while (*p != '\0' && isascii(*p) &&
4006 		       (isalnum(*p) || *p == '_'))
4007