xref: /illumos-gate/usr/src/cmd/sendmail/src/readcf.c (revision d4660949)
1 /*
2  * Copyright (c) 1998-2006, 2008 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.666 2008/02/14 17:25:14 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 #if _FFR_ADDR_TYPE_MODES
2251 # define O_ADDR_TYPE_MODES	0xe0
2252 	{ "AddrTypeModes",	O_ADDR_TYPE_MODES,	OI_NONE },
2253 #endif /* _FFR_ADDR_TYPE_MODES */
2254 #if _FFR_BADRCPT_SHUTDOWN
2255 # define O_RCPTSHUTD	0xe1
2256 	{ "BadRcptShutdown",		O_RCPTSHUTD,	OI_SAFE },
2257 # define O_RCPTSHUTDG	0xe2
2258 	{ "BadRcptShutdownGood",	O_RCPTSHUTDG,	OI_SAFE	},
2259 #endif /* _FFR_BADRCPT_SHUTDOWN */
2260 
2261 	{ NULL,				'\0',		OI_NONE	}
2262 };
2263 
2264 # define CANONIFY(val)
2265 
2266 # define SET_OPT_DEFAULT(opt, val)	opt = val
2267 
2268 /* set a string option by expanding the value and assigning it */
2269 /* WARNING this belongs ONLY into a case statement! */
2270 #define SET_STRING_EXP(str)	\
2271 		expand(val, exbuf, sizeof(exbuf), e);	\
2272 		newval = sm_pstrdup_x(exbuf);		\
2273 		if (str != NULL)	\
2274 			sm_free(str);	\
2275 		CANONIFY(newval);	\
2276 		str = newval;		\
2277 		break
2278 
2279 #define OPTNAME	o->o_name == NULL ? "<unknown>" : o->o_name
2280 
2281 void
2282 setoption(opt, val, safe, sticky, e)
2283 	int opt;
2284 	char *val;
2285 	bool safe;
2286 	bool sticky;
2287 	register ENVELOPE *e;
2288 {
2289 	register char *p;
2290 	register struct optioninfo *o;
2291 	char *subopt;
2292 	int mid;
2293 	bool can_setuid = RunAsUid == 0;
2294 	auto char *ep;
2295 	char buf[50];
2296 	extern bool Warn_Q_option;
2297 #if _FFR_ALLOW_SASLINFO
2298 	extern unsigned int SubmitMode;
2299 #endif /* _FFR_ALLOW_SASLINFO */
2300 #if STARTTLS || SM_CONF_SHM
2301 	char *newval;
2302 	char exbuf[MAXLINE];
2303 #endif /* STARTTLS || SM_CONF_SHM */
2304 
2305 	errno = 0;
2306 	if (opt == ' ')
2307 	{
2308 		/* full word options */
2309 		struct optioninfo *sel;
2310 
2311 		p = strchr(val, '=');
2312 		if (p == NULL)
2313 			p = &val[strlen(val)];
2314 		while (*--p == ' ')
2315 			continue;
2316 		while (*++p == ' ')
2317 			*p = '\0';
2318 		if (p == val)
2319 		{
2320 			syserr("readcf: null option name");
2321 			return;
2322 		}
2323 		if (*p == '=')
2324 			*p++ = '\0';
2325 		while (*p == ' ')
2326 			p++;
2327 		subopt = strchr(val, '.');
2328 		if (subopt != NULL)
2329 			*subopt++ = '\0';
2330 		sel = NULL;
2331 		for (o = OptionTab; o->o_name != NULL; o++)
2332 		{
2333 			if (sm_strncasecmp(o->o_name, val, strlen(val)) != 0)
2334 				continue;
2335 			if (strlen(o->o_name) == strlen(val))
2336 			{
2337 				/* completely specified -- this must be it */
2338 				sel = NULL;
2339 				break;
2340 			}
2341 			if (sel != NULL)
2342 				break;
2343 			sel = o;
2344 		}
2345 		if (sel != NULL && o->o_name == NULL)
2346 			o = sel;
2347 		else if (o->o_name == NULL)
2348 		{
2349 			syserr("readcf: unknown option name %s", val);
2350 			return;
2351 		}
2352 		else if (sel != NULL)
2353 		{
2354 			syserr("readcf: ambiguous option name %s (matches %s and %s)",
2355 				val, sel->o_name, o->o_name);
2356 			return;
2357 		}
2358 		if (strlen(val) != strlen(o->o_name))
2359 		{
2360 			int oldVerbose = Verbose;
2361 
2362 			Verbose = 1;
2363 			message("Option %s used as abbreviation for %s",
2364 				val, o->o_name);
2365 			Verbose = oldVerbose;
2366 		}
2367 		opt = o->o_code;
2368 		val = p;
2369 	}
2370 	else
2371 	{
2372 		for (o = OptionTab; o->o_name != NULL; o++)
2373 		{
2374 			if (o->o_code == opt)
2375 				break;
2376 		}
2377 		if (o->o_name == NULL)
2378 		{
2379 			syserr("readcf: unknown option name 0x%x", opt & 0xff);
2380 			return;
2381 		}
2382 		subopt = NULL;
2383 	}
2384 
2385 	if (subopt != NULL && !bitset(OI_SUBOPT, o->o_flags))
2386 	{
2387 		if (tTd(37, 1))
2388 			sm_dprintf("setoption: %s does not support suboptions, ignoring .%s\n",
2389 				   OPTNAME, subopt);
2390 		subopt = NULL;
2391 	}
2392 
2393 	if (tTd(37, 1))
2394 	{
2395 		sm_dprintf(isascii(opt) && isprint(opt) ?
2396 			   "setoption %s (%c)%s%s=" :
2397 			   "setoption %s (0x%x)%s%s=",
2398 			   OPTNAME, opt, subopt == NULL ? "" : ".",
2399 			   subopt == NULL ? "" : subopt);
2400 		xputs(sm_debug_file(), val);
2401 	}
2402 
2403 	/*
2404 	**  See if this option is preset for us.
2405 	*/
2406 
2407 	if (!sticky && bitnset(opt, StickyOpt))
2408 	{
2409 		if (tTd(37, 1))
2410 			sm_dprintf(" (ignored)\n");
2411 		return;
2412 	}
2413 
2414 	/*
2415 	**  Check to see if this option can be specified by this user.
2416 	*/
2417 
2418 	if (!safe && RealUid == 0)
2419 		safe = true;
2420 	if (!safe && !bitset(OI_SAFE, o->o_flags))
2421 	{
2422 		if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
2423 		{
2424 			int dp;
2425 
2426 			if (tTd(37, 1))
2427 				sm_dprintf(" (unsafe)");
2428 			dp = drop_privileges(true);
2429 			setstat(dp);
2430 		}
2431 	}
2432 	if (tTd(37, 1))
2433 		sm_dprintf("\n");
2434 
2435 	switch (opt & 0xff)
2436 	{
2437 	  case '7':		/* force seven-bit input */
2438 		SevenBitInput = atobool(val);
2439 		break;
2440 
2441 	  case '8':		/* handling of 8-bit input */
2442 #if MIME8TO7
2443 		switch (*val)
2444 		{
2445 		  case 'p':		/* pass 8 bit, convert MIME */
2446 			MimeMode = MM_CVTMIME|MM_PASS8BIT;
2447 			break;
2448 
2449 		  case 'm':		/* convert 8-bit, convert MIME */
2450 			MimeMode = MM_CVTMIME|MM_MIME8BIT;
2451 			break;
2452 
2453 		  case 's':		/* strict adherence */
2454 			MimeMode = MM_CVTMIME;
2455 			break;
2456 
2457 # if 0
2458 		  case 'r':		/* reject 8-bit, don't convert MIME */
2459 			MimeMode = 0;
2460 			break;
2461 
2462 		  case 'j':		/* "just send 8" */
2463 			MimeMode = MM_PASS8BIT;
2464 			break;
2465 
2466 		  case 'a':		/* encode 8 bit if available */
2467 			MimeMode = MM_MIME8BIT|MM_PASS8BIT|MM_CVTMIME;
2468 			break;
2469 
2470 		  case 'c':		/* convert 8 bit to MIME, never 7 bit */
2471 			MimeMode = MM_MIME8BIT;
2472 			break;
2473 # endif /* 0 */
2474 
2475 		  default:
2476 			syserr("Unknown 8-bit mode %c", *val);
2477 			finis(false, true, EX_USAGE);
2478 		}
2479 #else /* MIME8TO7 */
2480 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
2481 				     "Warning: Option: %s requires MIME8TO7 support\n",
2482 				     OPTNAME);
2483 #endif /* MIME8TO7 */
2484 		break;
2485 
2486 	  case 'A':		/* set default alias file */
2487 		if (val[0] == '\0')
2488 		{
2489 			char *al;
2490 
2491 			SET_OPT_DEFAULT(al, "aliases");
2492 			setalias(al);
2493 		}
2494 		else
2495 			setalias(val);
2496 		break;
2497 
2498 	  case 'a':		/* look N minutes for "@:@" in alias file */
2499 		if (val[0] == '\0')
2500 			SafeAlias = 5 MINUTES;
2501 		else
2502 			SafeAlias = convtime(val, 'm');
2503 		break;
2504 
2505 	  case 'B':		/* substitution for blank character */
2506 		SpaceSub = val[0];
2507 		if (SpaceSub == '\0')
2508 			SpaceSub = ' ';
2509 		break;
2510 
2511 	  case 'b':		/* min blocks free on queue fs/max msg size */
2512 		p = strchr(val, '/');
2513 		if (p != NULL)
2514 		{
2515 			*p++ = '\0';
2516 			MaxMessageSize = atol(p);
2517 		}
2518 		MinBlocksFree = atol(val);
2519 		break;
2520 
2521 	  case 'c':		/* don't connect to "expensive" mailers */
2522 		NoConnect = atobool(val);
2523 		break;
2524 
2525 	  case 'C':		/* checkpoint every N addresses */
2526 		if (safe || CheckpointInterval > atoi(val))
2527 			CheckpointInterval = atoi(val);
2528 		break;
2529 
2530 	  case 'd':		/* delivery mode */
2531 		switch (*val)
2532 		{
2533 		  case '\0':
2534 			set_delivery_mode(SM_DELIVER, e);
2535 			break;
2536 
2537 		  case SM_QUEUE:	/* queue only */
2538 		  case SM_DEFER:	/* queue only and defer map lookups */
2539 		  case SM_DELIVER:	/* do everything */
2540 		  case SM_FORK:		/* fork after verification */
2541 #if _FFR_DM_ONE
2542 		/* deliver first TA in background, then queue */
2543 		  case SM_DM_ONE:
2544 #endif /* _FFR_DM_ONE */
2545 			set_delivery_mode(*val, e);
2546 			break;
2547 
2548 		  default:
2549 			syserr("Unknown delivery mode %c", *val);
2550 			finis(false, true, EX_USAGE);
2551 		}
2552 		break;
2553 
2554 	  case 'E':		/* error message header/header file */
2555 		if (*val != '\0')
2556 			ErrMsgFile = newstr(val);
2557 		break;
2558 
2559 	  case 'e':		/* set error processing mode */
2560 		switch (*val)
2561 		{
2562 		  case EM_QUIET:	/* be silent about it */
2563 		  case EM_MAIL:		/* mail back */
2564 		  case EM_BERKNET:	/* do berknet error processing */
2565 		  case EM_WRITE:	/* write back (or mail) */
2566 		  case EM_PRINT:	/* print errors normally (default) */
2567 			e->e_errormode = *val;
2568 			break;
2569 		}
2570 		break;
2571 
2572 	  case 'F':		/* file mode */
2573 		FileMode = atooct(val) & 0777;
2574 		break;
2575 
2576 	  case 'f':		/* save Unix-style From lines on front */
2577 		SaveFrom = atobool(val);
2578 		break;
2579 
2580 	  case 'G':		/* match recipients against GECOS field */
2581 		MatchGecos = atobool(val);
2582 		break;
2583 
2584 	  case 'g':		/* default gid */
2585   g_opt:
2586 		if (isascii(*val) && isdigit(*val))
2587 			DefGid = atoi(val);
2588 		else
2589 		{
2590 			register struct group *gr;
2591 
2592 			DefGid = -1;
2593 			gr = getgrnam(val);
2594 			if (gr == NULL)
2595 				syserr("readcf: option %c: unknown group %s",
2596 					opt, val);
2597 			else
2598 				DefGid = gr->gr_gid;
2599 		}
2600 		break;
2601 
2602 	  case 'H':		/* help file */
2603 		if (val[0] == '\0')
2604 		{
2605 			SET_OPT_DEFAULT(HelpFile, "helpfile");
2606 		}
2607 		else
2608 		{
2609 			CANONIFY(val);
2610 			HelpFile = newstr(val);
2611 		}
2612 		break;
2613 
2614 	  case 'h':		/* maximum hop count */
2615 		MaxHopCount = atoi(val);
2616 		break;
2617 
2618 	  case 'I':		/* use internet domain name server */
2619 #if NAMED_BIND
2620 		for (p = val; *p != 0; )
2621 		{
2622 			bool clearmode;
2623 			char *q;
2624 			struct resolverflags *rfp;
2625 
2626 			while (*p == ' ')
2627 				p++;
2628 			if (*p == '\0')
2629 				break;
2630 			clearmode = false;
2631 			if (*p == '-')
2632 				clearmode = true;
2633 			else if (*p != '+')
2634 				p--;
2635 			p++;
2636 			q = p;
2637 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
2638 				p++;
2639 			if (*p != '\0')
2640 				*p++ = '\0';
2641 			if (sm_strcasecmp(q, "HasWildcardMX") == 0)
2642 			{
2643 				HasWildcardMX = !clearmode;
2644 				continue;
2645 			}
2646 			if (sm_strcasecmp(q, "WorkAroundBrokenAAAA") == 0)
2647 			{
2648 				WorkAroundBrokenAAAA = !clearmode;
2649 				continue;
2650 			}
2651 			for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
2652 			{
2653 				if (sm_strcasecmp(q, rfp->rf_name) == 0)
2654 					break;
2655 			}
2656 			if (rfp->rf_name == NULL)
2657 				syserr("readcf: I option value %s unrecognized", q);
2658 			else if (clearmode)
2659 				_res.options &= ~rfp->rf_bits;
2660 			else
2661 				_res.options |= rfp->rf_bits;
2662 		}
2663 		if (tTd(8, 2))
2664 			sm_dprintf("_res.options = %x, HasWildcardMX = %d\n",
2665 				   (unsigned int) _res.options, HasWildcardMX);
2666 #else /* NAMED_BIND */
2667 		usrerr("name server (I option) specified but BIND not compiled in");
2668 #endif /* NAMED_BIND */
2669 		break;
2670 
2671 	  case 'i':		/* ignore dot lines in message */
2672 		IgnrDot = atobool(val);
2673 		break;
2674 
2675 	  case 'j':		/* send errors in MIME (RFC 1341) format */
2676 		SendMIMEErrors = atobool(val);
2677 		break;
2678 
2679 	  case 'J':		/* .forward search path */
2680 		CANONIFY(val);
2681 		ForwardPath = newstr(val);
2682 		break;
2683 
2684 	  case 'k':		/* connection cache size */
2685 		MaxMciCache = atoi(val);
2686 		if (MaxMciCache < 0)
2687 			MaxMciCache = 0;
2688 		break;
2689 
2690 	  case 'K':		/* connection cache timeout */
2691 		MciCacheTimeout = convtime(val, 'm');
2692 		break;
2693 
2694 	  case 'l':		/* use Errors-To: header */
2695 		UseErrorsTo = atobool(val);
2696 		break;
2697 
2698 	  case 'L':		/* log level */
2699 		if (safe || LogLevel < atoi(val))
2700 			LogLevel = atoi(val);
2701 		break;
2702 
2703 	  case 'M':		/* define macro */
2704 		sticky = false;
2705 		mid = macid_parse(val, &ep);
2706 		if (mid == 0)
2707 			break;
2708 		p = newstr(ep);
2709 		if (!safe)
2710 			cleanstrcpy(p, p, strlen(p) + 1);
2711 		macdefine(&CurEnv->e_macro, A_TEMP, mid, p);
2712 		break;
2713 
2714 	  case 'm':		/* send to me too */
2715 		MeToo = atobool(val);
2716 		break;
2717 
2718 	  case 'n':		/* validate RHS in newaliases */
2719 		CheckAliases = atobool(val);
2720 		break;
2721 
2722 	    /* 'N' available -- was "net name" */
2723 
2724 	  case 'O':		/* daemon options */
2725 		if (!setdaemonoptions(val))
2726 			syserr("too many daemons defined (%d max)", MAXDAEMONS);
2727 		break;
2728 
2729 	  case 'o':		/* assume old style headers */
2730 		if (atobool(val))
2731 			CurEnv->e_flags |= EF_OLDSTYLE;
2732 		else
2733 			CurEnv->e_flags &= ~EF_OLDSTYLE;
2734 		break;
2735 
2736 	  case 'p':		/* select privacy level */
2737 		p = val;
2738 		for (;;)
2739 		{
2740 			register struct prival *pv;
2741 			extern struct prival PrivacyValues[];
2742 
2743 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
2744 				p++;
2745 			if (*p == '\0')
2746 				break;
2747 			val = p;
2748 			while (isascii(*p) && isalnum(*p))
2749 				p++;
2750 			if (*p != '\0')
2751 				*p++ = '\0';
2752 
2753 			for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
2754 			{
2755 				if (sm_strcasecmp(val, pv->pv_name) == 0)
2756 					break;
2757 			}
2758 			if (pv->pv_name == NULL)
2759 				syserr("readcf: Op line: %s unrecognized", val);
2760 			else
2761 				PrivacyFlags |= pv->pv_flag;
2762 		}
2763 		sticky = false;
2764 		break;
2765 
2766 	  case 'P':		/* postmaster copy address for returned mail */
2767 		PostMasterCopy = newstr(val);
2768 		break;
2769 
2770 	  case 'q':		/* slope of queue only function */
2771 		QueueFactor = atoi(val);
2772 		break;
2773 
2774 	  case 'Q':		/* queue directory */
2775 		if (val[0] == '\0')
2776 		{
2777 			QueueDir = "mqueue";
2778 		}
2779 		else
2780 		{
2781 			QueueDir = newstr(val);
2782 		}
2783 		if (RealUid != 0 && !safe)
2784 			Warn_Q_option = true;
2785 		break;
2786 
2787 	  case 'R':		/* don't prune routes */
2788 		DontPruneRoutes = atobool(val);
2789 		break;
2790 
2791 	  case 'r':		/* read timeout */
2792 		if (subopt == NULL)
2793 			inittimeouts(val, sticky);
2794 		else
2795 			settimeout(subopt, val, sticky);
2796 		break;
2797 
2798 	  case 'S':		/* status file */
2799 		if (val[0] == '\0')
2800 		{
2801 			SET_OPT_DEFAULT(StatFile, "statistics");
2802 		}
2803 		else
2804 		{
2805 			CANONIFY(val);
2806 			StatFile = newstr(val);
2807 		}
2808 		break;
2809 
2810 	  case 's':		/* be super safe, even if expensive */
2811 		if (tolower(*val) == 'i')
2812 			SuperSafe = SAFE_INTERACTIVE;
2813 		else if (tolower(*val) == 'p')
2814 #if MILTER
2815 			SuperSafe = SAFE_REALLY_POSTMILTER;
2816 #else /* MILTER */
2817 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
2818 				"Warning: SuperSafe=PostMilter requires Milter support (-DMILTER)\n");
2819 #endif /* MILTER */
2820 		else
2821 			SuperSafe = atobool(val) ? SAFE_REALLY : SAFE_NO;
2822 		break;
2823 
2824 	  case 'T':		/* queue timeout */
2825 		p = strchr(val, '/');
2826 		if (p != NULL)
2827 		{
2828 			*p++ = '\0';
2829 			settimeout("queuewarn", p, sticky);
2830 		}
2831 		settimeout("queuereturn", val, sticky);
2832 		break;
2833 
2834 	  case 't':		/* time zone name */
2835 		TimeZoneSpec = newstr(val);
2836 		break;
2837 
2838 	  case 'U':		/* location of user database */
2839 		UdbSpec = newstr(val);
2840 		break;
2841 
2842 	  case 'u':		/* set default uid */
2843 		for (p = val; *p != '\0'; p++)
2844 		{
2845 # if _FFR_DOTTED_USERNAMES
2846 			if (*p == '/' || *p == ':')
2847 # else /* _FFR_DOTTED_USERNAMES */
2848 			if (*p == '.' || *p == '/' || *p == ':')
2849 # endif /* _FFR_DOTTED_USERNAMES */
2850 			{
2851 				*p++ = '\0';
2852 				break;
2853 			}
2854 		}
2855 		if (isascii(*val) && isdigit(*val))
2856 		{
2857 			DefUid = atoi(val);
2858 			setdefuser();
2859 		}
2860 		else
2861 		{
2862 			register struct passwd *pw;
2863 
2864 			DefUid = -1;
2865 			pw = sm_getpwnam(val);
2866 			if (pw == NULL)
2867 			{
2868 				syserr("readcf: option u: unknown user %s", val);
2869 				break;
2870 			}
2871 			else
2872 			{
2873 				DefUid = pw->pw_uid;
2874 				DefGid = pw->pw_gid;
2875 				DefUser = newstr(pw->pw_name);
2876 			}
2877 		}
2878 
2879 # ifdef UID_MAX
2880 		if (DefUid > UID_MAX)
2881 		{
2882 			syserr("readcf: option u: uid value (%ld) > UID_MAX (%ld); ignored",
2883 				(long)DefUid, (long)UID_MAX);
2884 			break;
2885 		}
2886 # endif /* UID_MAX */
2887 
2888 		/* handle the group if it is there */
2889 		if (*p == '\0')
2890 			break;
2891 		val = p;
2892 		goto g_opt;
2893 
2894 	  case 'V':		/* fallback MX host */
2895 		if (val[0] != '\0')
2896 			FallbackMX = newstr(val);
2897 		break;
2898 
2899 	  case 'v':		/* run in verbose mode */
2900 		Verbose = atobool(val) ? 1 : 0;
2901 		break;
2902 
2903 	  case 'w':		/* if we are best MX, try host directly */
2904 		TryNullMXList = atobool(val);
2905 		break;
2906 
2907 	    /* 'W' available -- was wizard password */
2908 
2909 	  case 'x':		/* load avg at which to auto-queue msgs */
2910 		QueueLA = atoi(val);
2911 		break;
2912 
2913 	  case 'X':	/* load avg at which to auto-reject connections */
2914 		RefuseLA = atoi(val);
2915 		break;
2916 
2917 	  case O_DELAY_LA:	/* load avg at which to delay connections */
2918 		DelayLA = atoi(val);
2919 		break;
2920 
2921 	  case 'y':		/* work recipient factor */
2922 		WkRecipFact = atoi(val);
2923 		break;
2924 
2925 	  case 'Y':		/* fork jobs during queue runs */
2926 		ForkQueueRuns = atobool(val);
2927 		break;
2928 
2929 	  case 'z':		/* work message class factor */
2930 		WkClassFact = atoi(val);
2931 		break;
2932 
2933 	  case 'Z':		/* work time factor */
2934 		WkTimeFact = atoi(val);
2935 		break;
2936 
2937 
2938 #if _FFR_QUEUE_GROUP_SORTORDER
2939 	/* coordinate this with makequeue() */
2940 #endif /* _FFR_QUEUE_GROUP_SORTORDER */
2941 	  case O_QUEUESORTORD:	/* queue sorting order */
2942 		switch (*val)
2943 		{
2944 		  case 'f':	/* File Name */
2945 		  case 'F':
2946 			QueueSortOrder = QSO_BYFILENAME;
2947 			break;
2948 
2949 		  case 'h':	/* Host first */
2950 		  case 'H':
2951 			QueueSortOrder = QSO_BYHOST;
2952 			break;
2953 
2954 		  case 'm':	/* Modification time */
2955 		  case 'M':
2956 			QueueSortOrder = QSO_BYMODTIME;
2957 			break;
2958 
2959 		  case 'p':	/* Priority order */
2960 		  case 'P':
2961 			QueueSortOrder = QSO_BYPRIORITY;
2962 			break;
2963 
2964 		  case 't':	/* Submission time */
2965 		  case 'T':
2966 			QueueSortOrder = QSO_BYTIME;
2967 			break;
2968 
2969 		  case 'r':	/* Random */
2970 		  case 'R':
2971 			QueueSortOrder = QSO_RANDOM;
2972 			break;
2973 
2974 #if _FFR_RHS
2975 		  case 's':	/* Shuffled host name */
2976 		  case 'S':
2977 			QueueSortOrder = QSO_BYSHUFFLE;
2978 			break;
2979 #endif /* _FFR_RHS */
2980 
2981 		  case 'n':	/* none */
2982 		  case 'N':
2983 			QueueSortOrder = QSO_NONE;
2984 			break;
2985 
2986 		  default:
2987 			syserr("Invalid queue sort order \"%s\"", val);
2988 		}
2989 		break;
2990 
2991 	  case O_HOSTSFILE:	/* pathname of /etc/hosts file */
2992 		CANONIFY(val);
2993 		HostsFile = newstr(val);
2994 		break;
2995 
2996 	  case O_MQA:		/* minimum queue age between deliveries */
2997 		MinQueueAge = convtime(val, 'm');
2998 		break;
2999 
3000 	  case O_DEFCHARSET:	/* default character set for mimefying */
3001 		DefaultCharSet = newstr(denlstring(val, true, true));
3002 		break;
3003 
3004 	  case O_SSFILE:	/* service switch file */
3005 		CANONIFY(val);
3006 		ServiceSwitchFile = newstr(val);
3007 		break;
3008 
3009 	  case O_DIALDELAY:	/* delay for dial-on-demand operation */
3010 		DialDelay = convtime(val, 's');
3011 		break;
3012 
3013 	  case O_NORCPTACTION:	/* what to do if no recipient */
3014 		if (sm_strcasecmp(val, "none") == 0)
3015 			NoRecipientAction = NRA_NO_ACTION;
3016 		else if (sm_strcasecmp(val, "add-to") == 0)
3017 			NoRecipientAction = NRA_ADD_TO;
3018 		else if (sm_strcasecmp(val, "add-apparently-to") == 0)
3019 			NoRecipientAction = NRA_ADD_APPARENTLY_TO;
3020 		else if (sm_strcasecmp(val, "add-bcc") == 0)
3021 			NoRecipientAction = NRA_ADD_BCC;
3022 		else if (sm_strcasecmp(val, "add-to-undisclosed") == 0)
3023 			NoRecipientAction = NRA_ADD_TO_UNDISCLOSED;
3024 		else
3025 			syserr("Invalid NoRecipientAction: %s", val);
3026 		break;
3027 
3028 	  case O_SAFEFILEENV:	/* chroot() environ for writing to files */
3029 		if (*val == '\0')
3030 			break;
3031 
3032 		/* strip trailing slashes */
3033 		p = val + strlen(val) - 1;
3034 		while (p >= val && *p == '/')
3035 			*p-- = '\0';
3036 
3037 		if (*val == '\0')
3038 			break;
3039 
3040 		SafeFileEnv = newstr(val);
3041 		break;
3042 
3043 	  case O_MAXMSGSIZE:	/* maximum message size */
3044 		MaxMessageSize = atol(val);
3045 		break;
3046 
3047 	  case O_COLONOKINADDR:	/* old style handling of colon addresses */
3048 		ColonOkInAddr = atobool(val);
3049 		break;
3050 
3051 	  case O_MAXQUEUERUN:	/* max # of jobs in a single queue run */
3052 		MaxQueueRun = atoi(val);
3053 		break;
3054 
3055 	  case O_MAXCHILDREN:	/* max # of children of daemon */
3056 		MaxChildren = atoi(val);
3057 		break;
3058 
3059 	  case O_MAXQUEUECHILDREN: /* max # of children of daemon */
3060 		MaxQueueChildren = atoi(val);
3061 		break;
3062 
3063 	  case O_MAXRUNNERSPERQUEUE: /* max # runners in a queue group */
3064 		MaxRunnersPerQueue = atoi(val);
3065 		break;
3066 
3067 	  case O_NICEQUEUERUN:		/* nice queue runs */
3068 #if !HASNICE
3069 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3070 				     "Warning: NiceQueueRun set on system that doesn't support nice()\n");
3071 #endif /* !HASNICE */
3072 
3073 		/* XXX do we want to check the range? > 0 ? */
3074 		NiceQueueRun = atoi(val);
3075 		break;
3076 
3077 	  case O_SHMKEY:		/* shared memory key */
3078 #if SM_CONF_SHM
3079 		ShmKey = atol(val);
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 #endif /* SM_CONF_SHM */
3085 		break;
3086 
3087 	  case O_SHMKEYFILE:		/* shared memory key file */
3088 #if SM_CONF_SHM
3089 		SET_STRING_EXP(ShmKeyFile);
3090 #else /* SM_CONF_SHM */
3091 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3092 				     "Warning: Option: %s requires shared memory support (-DSM_CONF_SHM)\n",
3093 				     OPTNAME);
3094 		break;
3095 #endif /* SM_CONF_SHM */
3096 
3097 #if _FFR_MAX_FORWARD_ENTRIES
3098 	  case O_MAXFORWARD:	/* max # of forward entries */
3099 		MaxForwardEntries = atoi(val);
3100 		break;
3101 #endif /* _FFR_MAX_FORWARD_ENTRIES */
3102 
3103 	  case O_KEEPCNAMES:	/* don't expand CNAME records */
3104 		DontExpandCnames = atobool(val);
3105 		break;
3106 
3107 	  case O_MUSTQUOTE:	/* must quote these characters in phrases */
3108 		(void) sm_strlcpy(buf, "@,;:\\()[]", sizeof(buf));
3109 		if (strlen(val) < sizeof(buf) - 10)
3110 			(void) sm_strlcat(buf, val, sizeof(buf));
3111 		else
3112 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3113 					     "Warning: MustQuoteChars too long, ignored.\n");
3114 		MustQuoteChars = newstr(buf);
3115 		break;
3116 
3117 	  case O_SMTPGREETING:	/* SMTP greeting message (old $e macro) */
3118 		SmtpGreeting = newstr(munchstring(val, NULL, '\0'));
3119 		break;
3120 
3121 	  case O_UNIXFROM:	/* UNIX From_ line (old $l macro) */
3122 		UnixFromLine = newstr(munchstring(val, NULL, '\0'));
3123 		break;
3124 
3125 	  case O_OPCHARS:	/* operator characters (old $o macro) */
3126 		if (OperatorChars != NULL)
3127 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3128 					     "Warning: OperatorChars is being redefined.\n         It should only be set before ruleset definitions.\n");
3129 		OperatorChars = newstr(munchstring(val, NULL, '\0'));
3130 		break;
3131 
3132 	  case O_DONTINITGRPS:	/* don't call initgroups(3) */
3133 		DontInitGroups = atobool(val);
3134 		break;
3135 
3136 	  case O_SLFH:		/* make sure from fits on one line */
3137 		SingleLineFromHeader = atobool(val);
3138 		break;
3139 
3140 	  case O_ABH:		/* allow HELO commands with syntax errors */
3141 		AllowBogusHELO = atobool(val);
3142 		break;
3143 
3144 	  case O_CONNTHROT:	/* connection rate throttle */
3145 		ConnRateThrottle = atoi(val);
3146 		break;
3147 
3148 	  case O_UGW:		/* group writable files are unsafe */
3149 		if (!atobool(val))
3150 		{
3151 			setbitn(DBS_GROUPWRITABLEFORWARDFILESAFE,
3152 				DontBlameSendmail);
3153 			setbitn(DBS_GROUPWRITABLEINCLUDEFILESAFE,
3154 				DontBlameSendmail);
3155 		}
3156 		break;
3157 
3158 	  case O_DBLBOUNCE:	/* address to which to send double bounces */
3159 		DoubleBounceAddr = newstr(val);
3160 		break;
3161 
3162 	  case O_HSDIR:		/* persistent host status directory */
3163 		if (val[0] != '\0')
3164 		{
3165 			CANONIFY(val);
3166 			HostStatDir = newstr(val);
3167 		}
3168 		break;
3169 
3170 	  case O_SINGTHREAD:	/* single thread deliveries (requires hsdir) */
3171 		SingleThreadDelivery = atobool(val);
3172 		break;
3173 
3174 	  case O_RUNASUSER:	/* run bulk of code as this user */
3175 		for (p = val; *p != '\0'; p++)
3176 		{
3177 # if _FFR_DOTTED_USERNAMES
3178 			if (*p == '/' || *p == ':')
3179 # else /* _FFR_DOTTED_USERNAMES */
3180 			if (*p == '.' || *p == '/' || *p == ':')
3181 # endif /* _FFR_DOTTED_USERNAMES */
3182 			{
3183 				*p++ = '\0';
3184 				break;
3185 			}
3186 		}
3187 		if (isascii(*val) && isdigit(*val))
3188 		{
3189 			if (can_setuid)
3190 				RunAsUid = atoi(val);
3191 		}
3192 		else
3193 		{
3194 			register struct passwd *pw;
3195 
3196 			pw = sm_getpwnam(val);
3197 			if (pw == NULL)
3198 			{
3199 				syserr("readcf: option RunAsUser: unknown user %s", val);
3200 				break;
3201 			}
3202 			else if (can_setuid)
3203 			{
3204 				if (*p == '\0')
3205 					RunAsUserName = newstr(val);
3206 				RunAsUid = pw->pw_uid;
3207 				RunAsGid = pw->pw_gid;
3208 			}
3209 			else if (EffGid == pw->pw_gid)
3210 				RunAsGid = pw->pw_gid;
3211 			else if (UseMSP && *p == '\0')
3212 				(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3213 						     "WARNING: RunAsUser for MSP ignored, check group ids (egid=%d, want=%d)\n",
3214 						     (int) EffGid,
3215 						     (int) pw->pw_gid);
3216 		}
3217 # ifdef UID_MAX
3218 		if (RunAsUid > UID_MAX)
3219 		{
3220 			syserr("readcf: option RunAsUser: uid value (%ld) > UID_MAX (%ld); ignored",
3221 				(long) RunAsUid, (long) UID_MAX);
3222 			break;
3223 		}
3224 # endif /* UID_MAX */
3225 		if (*p != '\0')
3226 		{
3227 			if (isascii(*p) && isdigit(*p))
3228 			{
3229 				gid_t runasgid;
3230 
3231 				runasgid = (gid_t) atoi(p);
3232 				if (can_setuid || EffGid == runasgid)
3233 					RunAsGid = runasgid;
3234 				else if (UseMSP)
3235 					(void) sm_io_fprintf(smioout,
3236 							     SM_TIME_DEFAULT,
3237 							     "WARNING: RunAsUser for MSP ignored, check group ids (egid=%d, want=%d)\n",
3238 							     (int) EffGid,
3239 							     (int) runasgid);
3240 			}
3241 			else
3242 			{
3243 				register struct group *gr;
3244 
3245 				gr = getgrnam(p);
3246 				if (gr == NULL)
3247 					syserr("readcf: option RunAsUser: unknown group %s",
3248 						p);
3249 				else if (can_setuid || EffGid == gr->gr_gid)
3250 					RunAsGid = gr->gr_gid;
3251 				else if (UseMSP)
3252 					(void) sm_io_fprintf(smioout,
3253 							     SM_TIME_DEFAULT,
3254 							     "WARNING: RunAsUser for MSP ignored, check group ids (egid=%d, want=%d)\n",
3255 							     (int) EffGid,
3256 							     (int) gr->gr_gid);
3257 			}
3258 		}
3259 		if (tTd(47, 5))
3260 			sm_dprintf("readcf: RunAsUser = %d:%d\n",
3261 				   (int) RunAsUid, (int) RunAsGid);
3262 		break;
3263 
3264 	  case O_DSN_RRT:
3265 		RrtImpliesDsn = atobool(val);
3266 		break;
3267 
3268 	  case O_PIDFILE:
3269 		PSTRSET(PidFile, val);
3270 		break;
3271 
3272 	  case O_DONTBLAMESENDMAIL:
3273 		p = val;
3274 		for (;;)
3275 		{
3276 			register struct dbsval *dbs;
3277 			extern struct dbsval DontBlameSendmailValues[];
3278 
3279 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
3280 				p++;
3281 			if (*p == '\0')
3282 				break;
3283 			val = p;
3284 			while (isascii(*p) && isalnum(*p))
3285 				p++;
3286 			if (*p != '\0')
3287 				*p++ = '\0';
3288 
3289 			for (dbs = DontBlameSendmailValues;
3290 			     dbs->dbs_name != NULL; dbs++)
3291 			{
3292 				if (sm_strcasecmp(val, dbs->dbs_name) == 0)
3293 					break;
3294 			}
3295 			if (dbs->dbs_name == NULL)
3296 				syserr("readcf: DontBlameSendmail option: %s unrecognized", val);
3297 			else if (dbs->dbs_flag == DBS_SAFE)
3298 				clrbitmap(DontBlameSendmail);
3299 			else
3300 				setbitn(dbs->dbs_flag, DontBlameSendmail);
3301 		}
3302 		sticky = false;
3303 		break;
3304 
3305 	  case O_DPI:
3306 		if (sm_strcasecmp(val, "loopback") == 0)
3307 			DontProbeInterfaces = DPI_SKIPLOOPBACK;
3308 		else if (atobool(val))
3309 			DontProbeInterfaces = DPI_PROBENONE;
3310 		else
3311 			DontProbeInterfaces = DPI_PROBEALL;
3312 		break;
3313 
3314 	  case O_MAXRCPT:
3315 		MaxRcptPerMsg = atoi(val);
3316 		break;
3317 
3318 	  case O_RCPTTHROT:
3319 		BadRcptThrottle = atoi(val);
3320 		break;
3321 
3322 	  case O_DEADLETTER:
3323 		CANONIFY(val);
3324 		PSTRSET(DeadLetterDrop, val);
3325 		break;
3326 
3327 #if _FFR_DONTLOCKFILESFORREAD_OPTION
3328 	  case O_DONTLOCK:
3329 		DontLockReadFiles = atobool(val);
3330 		break;
3331 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
3332 
3333 	  case O_MAXALIASRCSN:
3334 		MaxAliasRecursion = atoi(val);
3335 		break;
3336 
3337 	  case O_CNCTONLYTO:
3338 		/* XXX should probably use gethostbyname */
3339 #if NETINET || NETINET6
3340 		ConnectOnlyTo.sa.sa_family = AF_UNSPEC;
3341 # if NETINET6
3342 		if (anynet_pton(AF_INET6, val,
3343 				&ConnectOnlyTo.sin6.sin6_addr) != 1)
3344 			ConnectOnlyTo.sa.sa_family = AF_INET6;
3345 		else
3346 # endif /* NETINET6 */
3347 # if NETINET
3348 		{
3349 			ConnectOnlyTo.sin.sin_addr.s_addr = inet_addr(val);
3350 			if (ConnectOnlyTo.sin.sin_addr.s_addr != INADDR_NONE)
3351 				ConnectOnlyTo.sa.sa_family = AF_INET;
3352 		}
3353 
3354 # endif /* NETINET */
3355 		if (ConnectOnlyTo.sa.sa_family == AF_UNSPEC)
3356 		{
3357 			syserr("readcf: option ConnectOnlyTo: invalid IP address %s",
3358 			       val);
3359 			break;
3360 		}
3361 #endif /* NETINET || NETINET6 */
3362 		break;
3363 
3364 	  case O_TRUSTUSER:
3365 # if !HASFCHOWN && !defined(_FFR_DROP_TRUSTUSER_WARNING)
3366 		if (!UseMSP)
3367 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3368 					     "readcf: option TrustedUser may cause problems on systems\n        which do not support fchown() if UseMSP is not set.\n");
3369 # endif /* !HASFCHOWN && !defined(_FFR_DROP_TRUSTUSER_WARNING) */
3370 		if (isascii(*val) && isdigit(*val))
3371 			TrustedUid = atoi(val);
3372 		else
3373 		{
3374 			register struct passwd *pw;
3375 
3376 			TrustedUid = 0;
3377 			pw = sm_getpwnam(val);
3378 			if (pw == NULL)
3379 			{
3380 				syserr("readcf: option TrustedUser: unknown user %s", val);
3381 				break;
3382 			}
3383 			else
3384 				TrustedUid = pw->pw_uid;
3385 		}
3386 
3387 # ifdef UID_MAX
3388 		if (TrustedUid > UID_MAX)
3389 		{
3390 			syserr("readcf: option TrustedUser: uid value (%ld) > UID_MAX (%ld)",
3391 				(long) TrustedUid, (long) UID_MAX);
3392 			TrustedUid = 0;
3393 		}
3394 # endif /* UID_MAX */
3395 		break;
3396 
3397 	  case O_MAXMIMEHDRLEN:
3398 		p = strchr(val, '/');
3399 		if (p != NULL)
3400 			*p++ = '\0';
3401 		MaxMimeHeaderLength = atoi(val);
3402 		if (p != NULL && *p != '\0')
3403 			MaxMimeFieldLength = atoi(p);
3404 		else
3405 			MaxMimeFieldLength = MaxMimeHeaderLength / 2;
3406 
3407 		if (MaxMimeHeaderLength <= 0)
3408 			MaxMimeHeaderLength = 0;
3409 		else if (MaxMimeHeaderLength < 128)
3410 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3411 					     "Warning: MaxMimeHeaderLength: header length limit set lower than 128\n");
3412 
3413 		if (MaxMimeFieldLength <= 0)
3414 			MaxMimeFieldLength = 0;
3415 		else if (MaxMimeFieldLength < 40)
3416 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3417 					     "Warning: MaxMimeHeaderLength: field length limit set lower than 40\n");
3418 
3419 		/*
3420 		**  Headers field values now include leading space, so let's
3421 		**  adjust the values to be "backward compatible".
3422 		*/
3423 
3424 		if (MaxMimeHeaderLength > 0)
3425 			MaxMimeHeaderLength++;
3426 		if (MaxMimeFieldLength > 0)
3427 			MaxMimeFieldLength++;
3428 		break;
3429 
3430 	  case O_CONTROLSOCKET:
3431 		PSTRSET(ControlSocketName, val);
3432 		break;
3433 
3434 	  case O_MAXHDRSLEN:
3435 		MaxHeadersLength = atoi(val);
3436 
3437 		if (MaxHeadersLength > 0 &&
3438 		    MaxHeadersLength < (MAXHDRSLEN / 2))
3439 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3440 					     "Warning: MaxHeadersLength: headers length limit set lower than %d\n",
3441 					     (MAXHDRSLEN / 2));
3442 		break;
3443 
3444 	  case O_PROCTITLEPREFIX:
3445 		PSTRSET(ProcTitlePrefix, val);
3446 		break;
3447 
3448 #if SASL
3449 	  case O_SASLINFO:
3450 # if _FFR_ALLOW_SASLINFO
3451 		/*
3452 		**  Allow users to select their own authinfo file
3453 		**  under certain circumstances, otherwise just ignore
3454 		**  the option.  If the option isn't ignored, several
3455 		**  commands don't work very well, e.g., mailq.
3456 		**  However, this is not a "perfect" solution.
3457 		**  If mail is queued, the authentication info
3458 		**  will not be used in subsequent delivery attempts.
3459 		**  If we really want to support this, then it has
3460 		**  to be stored in the queue file.
3461 		*/
3462 		if (!bitset(SUBMIT_MSA, SubmitMode) && RealUid != 0 &&
3463 		    RunAsUid != RealUid)
3464 			break;
3465 # endif /* _FFR_ALLOW_SASLINFO */
3466 		PSTRSET(SASLInfo, val);
3467 		break;
3468 
3469 	  case O_SASLMECH:
3470 		if (AuthMechanisms != NULL)
3471 			sm_free(AuthMechanisms); /* XXX */
3472 		if (*val != '\0')
3473 			AuthMechanisms = newstr(val);
3474 		else
3475 			AuthMechanisms = NULL;
3476 		break;
3477 
3478 	  case O_SASLREALM:
3479 		if (AuthRealm != NULL)
3480 			sm_free(AuthRealm);
3481 		if (*val != '\0')
3482 			AuthRealm = newstr(val);
3483 		else
3484 			AuthRealm = NULL;
3485 		break;
3486 
3487 	  case O_SASLOPTS:
3488 		while (val != NULL && *val != '\0')
3489 		{
3490 			switch (*val)
3491 			{
3492 			  case 'A':
3493 				SASLOpts |= SASL_AUTH_AUTH;
3494 				break;
3495 
3496 			  case 'a':
3497 				SASLOpts |= SASL_SEC_NOACTIVE;
3498 				break;
3499 
3500 			  case 'c':
3501 				SASLOpts |= SASL_SEC_PASS_CREDENTIALS;
3502 				break;
3503 
3504 			  case 'd':
3505 				SASLOpts |= SASL_SEC_NODICTIONARY;
3506 				break;
3507 
3508 			  case 'f':
3509 				SASLOpts |= SASL_SEC_FORWARD_SECRECY;
3510 				break;
3511 
3512 #  if SASL >= 20101
3513 			  case 'm':
3514 				SASLOpts |= SASL_SEC_MUTUAL_AUTH;
3515 				break;
3516 #  endif /* SASL >= 20101 */
3517 
3518 			  case 'p':
3519 				SASLOpts |= SASL_SEC_NOPLAINTEXT;
3520 				break;
3521 
3522 			  case 'y':
3523 				SASLOpts |= SASL_SEC_NOANONYMOUS;
3524 				break;
3525 
3526 			  case ' ':	/* ignore */
3527 			  case '\t':	/* ignore */
3528 			  case ',':	/* ignore */
3529 				break;
3530 
3531 			  default:
3532 				(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3533 						     "Warning: Option: %s unknown parameter '%c'\n",
3534 						     OPTNAME,
3535 						     (isascii(*val) &&
3536 							isprint(*val))
3537 							? *val : '?');
3538 				break;
3539 			}
3540 			++val;
3541 			val = strpbrk(val, ", \t");
3542 			if (val != NULL)
3543 				++val;
3544 		}
3545 		break;
3546 
3547 	  case O_SASLBITS:
3548 		MaxSLBits = atoi(val);
3549 		break;
3550 
3551 #else /* SASL */
3552 	  case O_SASLINFO:
3553 	  case O_SASLMECH:
3554 	  case O_SASLREALM:
3555 	  case O_SASLOPTS:
3556 	  case O_SASLBITS:
3557 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3558 				     "Warning: Option: %s requires SASL support (-DSASL)\n",
3559 				     OPTNAME);
3560 		break;
3561 #endif /* SASL */
3562 
3563 #if STARTTLS
3564 	  case O_SRVCERTFILE:
3565 		SET_STRING_EXP(SrvCertFile);
3566 	  case O_SRVKEYFILE:
3567 		SET_STRING_EXP(SrvKeyFile);
3568 	  case O_CLTCERTFILE:
3569 		SET_STRING_EXP(CltCertFile);
3570 	  case O_CLTKEYFILE:
3571 		SET_STRING_EXP(CltKeyFile);
3572 	  case O_CACERTFILE:
3573 		SET_STRING_EXP(CACertFile);
3574 	  case O_CACERTPATH:
3575 		SET_STRING_EXP(CACertPath);
3576 	  case O_DHPARAMS:
3577 		SET_STRING_EXP(DHParams);
3578 # if _FFR_TLS_1
3579 	  case O_DHPARAMS5:
3580 		SET_STRING_EXP(DHParams5);
3581 	  case O_CIPHERLIST:
3582 		SET_STRING_EXP(CipherList);
3583 # endif /* _FFR_TLS_1 */
3584 	  case O_CRLFILE:
3585 # if OPENSSL_VERSION_NUMBER > 0x00907000L
3586 		SET_STRING_EXP(CRLFile);
3587 # else /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3588 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3589 				     "Warning: Option: %s requires at least OpenSSL 0.9.7\n",
3590 				     OPTNAME);
3591 		break;
3592 # endif /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3593 
3594 # if _FFR_CRLPATH
3595 	  case O_CRLPATH:
3596 #  if OPENSSL_VERSION_NUMBER > 0x00907000L
3597 		SET_STRING_EXP(CRLPath);
3598 #  else /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3599 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3600 				     "Warning: Option: %s requires at least OpenSSL 0.9.7\n",
3601 				     OPTNAME);
3602 		break;
3603 #  endif /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3604 # endif /* _FFR_CRLPATH */
3605 
3606 	/*
3607 	**  XXX How about options per daemon/client instead of globally?
3608 	**  This doesn't work well for some options, e.g., no server cert,
3609 	**  but fine for others.
3610 	**
3611 	**  XXX Some people may want different certs per server.
3612 	**
3613 	**  See also srvfeatures()
3614 	*/
3615 
3616 	  case O_TLS_SRV_OPTS:
3617 		while (val != NULL && *val != '\0')
3618 		{
3619 			switch (*val)
3620 			{
3621 			  case 'V':
3622 				TLS_Srv_Opts |= TLS_I_NO_VRFY;
3623 				break;
3624 # if _FFR_TLS_1
3625 			/*
3626 			**  Server without a cert? That works only if
3627 			**  AnonDH is enabled as cipher, which is not in the
3628 			**  default list. Hence the CipherList option must
3629 			**  be available. Moreover: which clients support this
3630 			**  besides sendmail with this setting?
3631 			*/
3632 
3633 			  case 'C':
3634 				TLS_Srv_Opts &= ~TLS_I_SRV_CERT;
3635 				break;
3636 # endif /* _FFR_TLS_1 */
3637 			  case ' ':	/* ignore */
3638 			  case '\t':	/* ignore */
3639 			  case ',':	/* ignore */
3640 				break;
3641 			  default:
3642 				(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3643 						     "Warning: Option: %s unknown parameter '%c'\n",
3644 						     OPTNAME,
3645 						     (isascii(*val) &&
3646 							isprint(*val))
3647 							? *val : '?');
3648 				break;
3649 			}
3650 			++val;
3651 			val = strpbrk(val, ", \t");
3652 			if (val != NULL)
3653 				++val;
3654 		}
3655 		break;
3656 
3657 	  case O_RANDFILE:
3658 		PSTRSET(RandFile, val);
3659 		break;
3660 
3661 #else /* STARTTLS */
3662 	  case O_SRVCERTFILE:
3663 	  case O_SRVKEYFILE:
3664 	  case O_CLTCERTFILE:
3665 	  case O_CLTKEYFILE:
3666 	  case O_CACERTFILE:
3667 	  case O_CACERTPATH:
3668 	  case O_DHPARAMS:
3669 # if _FFR_TLS_1
3670 	  case O_DHPARAMS5:
3671 	  case O_CIPHERLIST:
3672 # endif /* _FFR_TLS_1 */
3673 	  case O_CRLFILE:
3674 # if _FFR_CRLPATH
3675 	  case O_CRLPATH:
3676 # endif /* _FFR_CRLPATH */
3677 	  case O_RANDFILE:
3678 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3679 				     "Warning: Option: %s requires TLS support\n",
3680 				     OPTNAME);
3681 		break;
3682 
3683 #endif /* STARTTLS */
3684 
3685 	  case O_CLIENTPORT:
3686 		setclientoptions(val);
3687 		break;
3688 
3689 	  case O_DF_BUFSIZE:
3690 		DataFileBufferSize = atoi(val);
3691 		break;
3692 
3693 	  case O_XF_BUFSIZE:
3694 		XscriptFileBufferSize = atoi(val);
3695 		break;
3696 
3697 	  case O_LDAPDEFAULTSPEC:
3698 #if LDAPMAP
3699 		ldapmap_set_defaults(val);
3700 #else /* LDAPMAP */
3701 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3702 				     "Warning: Option: %s requires LDAP support (-DLDAPMAP)\n",
3703 				     OPTNAME);
3704 #endif /* LDAPMAP */
3705 		break;
3706 
3707 	  case O_INPUTMILTER:
3708 #if MILTER
3709 		InputFilterList = newstr(val);
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_MILTER:
3718 #if MILTER
3719 		milter_set_option(subopt, val, sticky);
3720 #else /* MILTER */
3721 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3722 				     "Warning: Option: %s requires Milter support (-DMILTER)\n",
3723 				     OPTNAME);
3724 #endif /* MILTER */
3725 		break;
3726 
3727 	  case O_QUEUE_FILE_MODE:	/* queue file mode */
3728 		QueueFileMode = atooct(val) & 0777;
3729 		break;
3730 
3731 	  case O_DLVR_MIN:	/* deliver by minimum time */
3732 		DeliverByMin = convtime(val, 's');
3733 		break;
3734 
3735 	  /* modifiers {daemon_flags} for direct submissions */
3736 	  case O_DIRECTSUBMODIFIERS:
3737 		{
3738 			BITMAP256 m;	/* ignored */
3739 			extern ENVELOPE BlankEnvelope;
3740 
3741 			macdefine(&BlankEnvelope.e_macro, A_PERM,
3742 				  macid("{daemon_flags}"),
3743 				  getmodifiers(val, m));
3744 		}
3745 		break;
3746 
3747 	  case O_FASTSPLIT:
3748 		FastSplit = atoi(val);
3749 		break;
3750 
3751 	  case O_MBDB:
3752 		Mbdb = newstr(val);
3753 		break;
3754 
3755 	  case O_MSQ:
3756 		UseMSP = atobool(val);
3757 		break;
3758 
3759 	  case O_SOFTBOUNCE:
3760 		SoftBounce = atobool(val);
3761 		break;
3762 
3763 	  case O_REJECTLOGINTERVAL:	/* time btwn log msgs while refusing */
3764 		RejectLogInterval = convtime(val, 'h');
3765 		break;
3766 
3767 	  case O_REQUIRES_DIR_FSYNC:
3768 #if REQUIRES_DIR_FSYNC
3769 		RequiresDirfsync = atobool(val);
3770 #else /* REQUIRES_DIR_FSYNC */
3771 		/* silently ignored... required for cf file option */
3772 #endif /* REQUIRES_DIR_FSYNC */
3773 		break;
3774 
3775 	  case O_CONNECTION_RATE_WINDOW_SIZE:
3776 		ConnectionRateWindowSize = convtime(val, 's');
3777 		break;
3778 
3779 	  case O_FALLBACKSMARTHOST:	/* fallback smart host */
3780 		if (val[0] != '\0')
3781 			FallbackSmartHost = newstr(val);
3782 		break;
3783 
3784 	  case O_HELONAME:
3785 		HeloName = newstr(val);
3786 		break;
3787 
3788 #if _FFR_MEMSTAT
3789 	  case O_REFUSELOWMEM:
3790 		RefuseLowMem = atoi(val);
3791 		break;
3792 	  case O_QUEUELOWMEM:
3793 		QueueLowMem = atoi(val);
3794 		break;
3795 	  case O_MEMRESOURCE:
3796 		MemoryResource = newstr(val);
3797 		break;
3798 #endif /* _FFR_MEMSTAT */
3799 
3800 	  case O_MAXNOOPCOMMANDS:
3801 		MaxNOOPCommands = atoi(val);
3802 		break;
3803 
3804 #if _FFR_MSG_ACCEPT
3805 	  case O_MSG_ACCEPT:
3806 		MessageAccept = newstr(val);
3807 		break;
3808 #endif /* _FFR_MSG_ACCEPT */
3809 
3810 #if _FFR_QUEUE_RUN_PARANOIA
3811 	  case O_CHK_Q_RUNNERS:
3812 		CheckQueueRunners = atoi(val);
3813 		break;
3814 #endif /* _FFR_QUEUE_RUN_PARANOIA */
3815 
3816 #if _FFR_EIGHT_BIT_ADDR_OK
3817 	  case O_EIGHT_BIT_ADDR_OK:
3818 		EightBitAddrOK = atobool(val);
3819 		break;
3820 #endif /* _FFR_EIGHT_BIT_ADDR_OK */
3821 
3822 #if _FFR_ADDR_TYPE_MODES
3823 	  case O_ADDR_TYPE_MODES:
3824 		AddrTypeModes = atobool(val);
3825 		break;
3826 #endif /* _FFR_ADDR_TYPE_MODES */
3827 
3828 #if _FFR_BADRCPT_SHUTDOWN
3829 	  case O_RCPTSHUTD:
3830 		BadRcptShutdown = atoi(val);
3831 		break;
3832 
3833 	  case O_RCPTSHUTDG:
3834 		BadRcptShutdownGood = atoi(val);
3835 		break;
3836 #endif /* _FFR_BADRCPT_SHUTDOWN */
3837 
3838 	  default:
3839 		if (tTd(37, 1))
3840 		{
3841 			if (isascii(opt) && isprint(opt))
3842 				sm_dprintf("Warning: option %c unknown\n", opt);
3843 			else
3844 				sm_dprintf("Warning: option 0x%x unknown\n", opt);
3845 		}
3846 		break;
3847 	}
3848 
3849 	/*
3850 	**  Options with suboptions are responsible for taking care
3851 	**  of sticky-ness (e.g., that a command line setting is kept
3852 	**  when reading in the sendmail.cf file).  This has to be done
3853 	**  when the suboptions are parsed since each suboption must be
3854 	**  sticky, not the root option.
3855 	*/
3856 
3857 	if (sticky && !bitset(OI_SUBOPT, o->o_flags))
3858 		setbitn(opt, StickyOpt);
3859 }
3860 /*
3861 **  SETCLASS -- set a string into a class
3862 **
3863 **	Parameters:
3864 **		class -- the class to put the string in.
3865 **		str -- the string to enter
3866 **
3867 **	Returns:
3868 **		none.
3869 **
3870 **	Side Effects:
3871 **		puts the word into the symbol table.
3872 */
3873 
3874 void
3875 setclass(class, str)
3876 	int class;
3877 	char *str;
3878 {
3879 	register STAB *s;
3880 
3881 	if ((str[0] & 0377) == MATCHCLASS)
3882 	{
3883 		int mid;
3884 
3885 		str++;
3886 		mid = macid(str);
3887 		if (mid == 0)
3888 			return;
3889 
3890 		if (tTd(37, 8))
3891 			sm_dprintf("setclass(%s, $=%s)\n",
3892 				   macname(class), macname(mid));
3893 		copy_class(mid, class);
3894 	}
3895 	else
3896 	{
3897 		if (tTd(37, 8))
3898 			sm_dprintf("setclass(%s, %s)\n", macname(class), str);
3899 
3900 		s = stab(str, ST_CLASS, ST_ENTER);
3901 		setbitn(bitidx(class), s->s_class);
3902 	}
3903 }
3904 /*
3905 **  MAKEMAPENTRY -- create a map entry
3906 **
3907 **	Parameters:
3908 **		line -- the config file line
3909 **
3910 **	Returns:
3911 **		A pointer to the map that has been created.
3912 **		NULL if there was a syntax error.
3913 **
3914 **	Side Effects:
3915 **		Enters the map into the dictionary.
3916 */
3917 
3918 MAP *
3919 makemapentry(line)
3920 	char *line;
3921 {
3922 	register char *p;
3923 	char *mapname;
3924 	char *classname;
3925 	register STAB *s;
3926 	STAB *class;
3927 
3928 	for (p = line; isascii(*p) && isspace(*p); p++)
3929 		continue;
3930 	if (!(isascii(*p) && isalnum(*p)))
3931 	{
3932 		syserr("readcf: config K line: no map name");
3933 		return NULL;
3934 	}
3935 
3936 	mapname = p;
3937 	while ((isascii(*++p) && isalnum(*p)) || *p == '_' || *p == '.')
3938 		continue;
3939 	if (*p != '\0')
3940 		*p++ = '\0';
3941 	while (isascii(*p) && isspace(*p))
3942 		p++;
3943 	if (!(isascii(*p) && isalnum(*p)))
3944 	{
3945 		syserr("readcf: config K line, map %s: no map class", mapname);
3946 		return NULL;
3947 	}
3948 	classname = p;
3949 	while (isascii(*++p) && isalnum(*p))
3950 		continue;
3951 	if (*p != '\0')
3952 		*p++ = '\0';
3953 	while (isascii(*p) && isspace(*p))
3954 		p++;
3955 
3956 	/* look up the class */
3957 	class = stab(classname, ST_MAPCLASS, ST_FIND);
3958 	if (class == NULL)
3959 	{
3960 		syserr("readcf: map %s: class %s not available", mapname,
3961 			classname);
3962 		return NULL;
3963 	}
3964 
3965 	/* enter the map */
3966 	s = stab(mapname, ST_MAP, ST_ENTER);
3967 	s->s_map.map_class = &class->s_mapclass;
3968 	s->s_map.map_mname = newstr(mapname);
3969 
3970 	if (class->s_mapclass.map_parse(&s->s_map, p))
3971 		s->s_map.map_mflags |= MF_VALID;
3972 
3973 	if (tTd(37, 5))
3974 	{
3975 		sm_dprintf("map %s, class %s, flags %lx, file %s,\n",
3976 			   s->s_map.map_mname, s->s_map.map_class->map_cname,
3977 			   s->s_map.map_mflags, s->s_map.map_file);
3978 		sm_dprintf("\tapp %s, domain %s, rebuild %s\n",
3979 			   s->s_map.map_app, s->s_map.map_domain,
3980 			   s->s_map.map_rebuild);
3981 	}
3982 	return &s->s_map;
3983 }
3984 /*
3985 **  STRTORWSET -- convert string to rewriting set number
3986 **
3987 **	Parameters:
3988 **		p -- the pointer to the string to decode.
3989 **		endp -- if set, store the trailing delimiter here.
3990 **		stabmode -- ST_ENTER to create this entry, ST_FIND if
3991 **			it must already exist.
3992 **
3993 **	Returns:
3994 **		The appropriate ruleset number.
3995 **		-1 if it is not valid (error already printed)
3996 */
3997 
3998 int
3999 strtorwset(p, endp, stabmode)
4000 	char *p;
4001 	char **endp;
4002 	int stabmode;
4003 {
4004 	int ruleset;
4005 	static int nextruleset = MAXRWSETS;
4006 
4007 	while (isascii(*p) && isspace(*p))
4008 		p++;
4009 	if (!