xref: /titanic_50/usr/src/cmd/sendmail/src/readcf.c (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
1 /*
2  * Copyright (c) 1998-2006 Sendmail, Inc. and its suppliers.
3  *	All rights reserved.
4  * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
5  * Copyright (c) 1988, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * By using this file, you agree to the terms and conditions set
9  * forth in the LICENSE file which can be found at the top level of
10  * the sendmail distribution.
11  *
12  */
13 
14 #pragma ident	"%Z%%M%	%I%	%E% SMI"
15 
16 #include <sendmail.h>
17 #include <sm/sendmail.h>
18 
19 SM_RCSID("@(#)$Id: readcf.c,v 8.664 2007/07/10 17:01:22 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 
2255 	{ NULL,				'\0',		OI_NONE	}
2256 };
2257 
2258 # define CANONIFY(val)
2259 
2260 # define SET_OPT_DEFAULT(opt, val)	opt = val
2261 
2262 /* set a string option by expanding the value and assigning it */
2263 /* WARNING this belongs ONLY into a case statement! */
2264 #define SET_STRING_EXP(str)	\
2265 		expand(val, exbuf, sizeof(exbuf), e);	\
2266 		newval = sm_pstrdup_x(exbuf);		\
2267 		if (str != NULL)	\
2268 			sm_free(str);	\
2269 		CANONIFY(newval);	\
2270 		str = newval;		\
2271 		break
2272 
2273 #define OPTNAME	o->o_name == NULL ? "<unknown>" : o->o_name
2274 
2275 void
2276 setoption(opt, val, safe, sticky, e)
2277 	int opt;
2278 	char *val;
2279 	bool safe;
2280 	bool sticky;
2281 	register ENVELOPE *e;
2282 {
2283 	register char *p;
2284 	register struct optioninfo *o;
2285 	char *subopt;
2286 	int mid;
2287 	bool can_setuid = RunAsUid == 0;
2288 	auto char *ep;
2289 	char buf[50];
2290 	extern bool Warn_Q_option;
2291 #if _FFR_ALLOW_SASLINFO
2292 	extern unsigned int SubmitMode;
2293 #endif /* _FFR_ALLOW_SASLINFO */
2294 #if STARTTLS || SM_CONF_SHM
2295 	char *newval;
2296 	char exbuf[MAXLINE];
2297 #endif /* STARTTLS || SM_CONF_SHM */
2298 
2299 	errno = 0;
2300 	if (opt == ' ')
2301 	{
2302 		/* full word options */
2303 		struct optioninfo *sel;
2304 
2305 		p = strchr(val, '=');
2306 		if (p == NULL)
2307 			p = &val[strlen(val)];
2308 		while (*--p == ' ')
2309 			continue;
2310 		while (*++p == ' ')
2311 			*p = '\0';
2312 		if (p == val)
2313 		{
2314 			syserr("readcf: null option name");
2315 			return;
2316 		}
2317 		if (*p == '=')
2318 			*p++ = '\0';
2319 		while (*p == ' ')
2320 			p++;
2321 		subopt = strchr(val, '.');
2322 		if (subopt != NULL)
2323 			*subopt++ = '\0';
2324 		sel = NULL;
2325 		for (o = OptionTab; o->o_name != NULL; o++)
2326 		{
2327 			if (sm_strncasecmp(o->o_name, val, strlen(val)) != 0)
2328 				continue;
2329 			if (strlen(o->o_name) == strlen(val))
2330 			{
2331 				/* completely specified -- this must be it */
2332 				sel = NULL;
2333 				break;
2334 			}
2335 			if (sel != NULL)
2336 				break;
2337 			sel = o;
2338 		}
2339 		if (sel != NULL && o->o_name == NULL)
2340 			o = sel;
2341 		else if (o->o_name == NULL)
2342 		{
2343 			syserr("readcf: unknown option name %s", val);
2344 			return;
2345 		}
2346 		else if (sel != NULL)
2347 		{
2348 			syserr("readcf: ambiguous option name %s (matches %s and %s)",
2349 				val, sel->o_name, o->o_name);
2350 			return;
2351 		}
2352 		if (strlen(val) != strlen(o->o_name))
2353 		{
2354 			int oldVerbose = Verbose;
2355 
2356 			Verbose = 1;
2357 			message("Option %s used as abbreviation for %s",
2358 				val, o->o_name);
2359 			Verbose = oldVerbose;
2360 		}
2361 		opt = o->o_code;
2362 		val = p;
2363 	}
2364 	else
2365 	{
2366 		for (o = OptionTab; o->o_name != NULL; o++)
2367 		{
2368 			if (o->o_code == opt)
2369 				break;
2370 		}
2371 		if (o->o_name == NULL)
2372 		{
2373 			syserr("readcf: unknown option name 0x%x", opt & 0xff);
2374 			return;
2375 		}
2376 		subopt = NULL;
2377 	}
2378 
2379 	if (subopt != NULL && !bitset(OI_SUBOPT, o->o_flags))
2380 	{
2381 		if (tTd(37, 1))
2382 			sm_dprintf("setoption: %s does not support suboptions, ignoring .%s\n",
2383 				   OPTNAME, subopt);
2384 		subopt = NULL;
2385 	}
2386 
2387 	if (tTd(37, 1))
2388 	{
2389 		sm_dprintf(isascii(opt) && isprint(opt) ?
2390 			   "setoption %s (%c)%s%s=" :
2391 			   "setoption %s (0x%x)%s%s=",
2392 			   OPTNAME, opt, subopt == NULL ? "" : ".",
2393 			   subopt == NULL ? "" : subopt);
2394 		xputs(sm_debug_file(), val);
2395 	}
2396 
2397 	/*
2398 	**  See if this option is preset for us.
2399 	*/
2400 
2401 	if (!sticky && bitnset(opt, StickyOpt))
2402 	{
2403 		if (tTd(37, 1))
2404 			sm_dprintf(" (ignored)\n");
2405 		return;
2406 	}
2407 
2408 	/*
2409 	**  Check to see if this option can be specified by this user.
2410 	*/
2411 
2412 	if (!safe && RealUid == 0)
2413 		safe = true;
2414 	if (!safe && !bitset(OI_SAFE, o->o_flags))
2415 	{
2416 		if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
2417 		{
2418 			int dp;
2419 
2420 			if (tTd(37, 1))
2421 				sm_dprintf(" (unsafe)");
2422 			dp = drop_privileges(true);
2423 			setstat(dp);
2424 		}
2425 	}
2426 	if (tTd(37, 1))
2427 		sm_dprintf("\n");
2428 
2429 	switch (opt & 0xff)
2430 	{
2431 	  case '7':		/* force seven-bit input */
2432 		SevenBitInput = atobool(val);
2433 		break;
2434 
2435 	  case '8':		/* handling of 8-bit input */
2436 #if MIME8TO7
2437 		switch (*val)
2438 		{
2439 		  case 'p':		/* pass 8 bit, convert MIME */
2440 			MimeMode = MM_CVTMIME|MM_PASS8BIT;
2441 			break;
2442 
2443 		  case 'm':		/* convert 8-bit, convert MIME */
2444 			MimeMode = MM_CVTMIME|MM_MIME8BIT;
2445 			break;
2446 
2447 		  case 's':		/* strict adherence */
2448 			MimeMode = MM_CVTMIME;
2449 			break;
2450 
2451 # if 0
2452 		  case 'r':		/* reject 8-bit, don't convert MIME */
2453 			MimeMode = 0;
2454 			break;
2455 
2456 		  case 'j':		/* "just send 8" */
2457 			MimeMode = MM_PASS8BIT;
2458 			break;
2459 
2460 		  case 'a':		/* encode 8 bit if available */
2461 			MimeMode = MM_MIME8BIT|MM_PASS8BIT|MM_CVTMIME;
2462 			break;
2463 
2464 		  case 'c':		/* convert 8 bit to MIME, never 7 bit */
2465 			MimeMode = MM_MIME8BIT;
2466 			break;
2467 # endif /* 0 */
2468 
2469 		  default:
2470 			syserr("Unknown 8-bit mode %c", *val);
2471 			finis(false, true, EX_USAGE);
2472 		}
2473 #else /* MIME8TO7 */
2474 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
2475 				     "Warning: Option: %s requires MIME8TO7 support\n",
2476 				     OPTNAME);
2477 #endif /* MIME8TO7 */
2478 		break;
2479 
2480 	  case 'A':		/* set default alias file */
2481 		if (val[0] == '\0')
2482 		{
2483 			char *al;
2484 
2485 			SET_OPT_DEFAULT(al, "aliases");
2486 			setalias(al);
2487 		}
2488 		else
2489 			setalias(val);
2490 		break;
2491 
2492 	  case 'a':		/* look N minutes for "@:@" in alias file */
2493 		if (val[0] == '\0')
2494 			SafeAlias = 5 MINUTES;
2495 		else
2496 			SafeAlias = convtime(val, 'm');
2497 		break;
2498 
2499 	  case 'B':		/* substitution for blank character */
2500 		SpaceSub = val[0];
2501 		if (SpaceSub == '\0')
2502 			SpaceSub = ' ';
2503 		break;
2504 
2505 	  case 'b':		/* min blocks free on queue fs/max msg size */
2506 		p = strchr(val, '/');
2507 		if (p != NULL)
2508 		{
2509 			*p++ = '\0';
2510 			MaxMessageSize = atol(p);
2511 		}
2512 		MinBlocksFree = atol(val);
2513 		break;
2514 
2515 	  case 'c':		/* don't connect to "expensive" mailers */
2516 		NoConnect = atobool(val);
2517 		break;
2518 
2519 	  case 'C':		/* checkpoint every N addresses */
2520 		if (safe || CheckpointInterval > atoi(val))
2521 			CheckpointInterval = atoi(val);
2522 		break;
2523 
2524 	  case 'd':		/* delivery mode */
2525 		switch (*val)
2526 		{
2527 		  case '\0':
2528 			set_delivery_mode(SM_DELIVER, e);
2529 			break;
2530 
2531 		  case SM_QUEUE:	/* queue only */
2532 		  case SM_DEFER:	/* queue only and defer map lookups */
2533 		  case SM_DELIVER:	/* do everything */
2534 		  case SM_FORK:		/* fork after verification */
2535 #if _FFR_DM_ONE
2536 		/* deliver first TA in background, then queue */
2537 		  case SM_DM_ONE:
2538 #endif /* _FFR_DM_ONE */
2539 			set_delivery_mode(*val, e);
2540 			break;
2541 
2542 		  default:
2543 			syserr("Unknown delivery mode %c", *val);
2544 			finis(false, true, EX_USAGE);
2545 		}
2546 		break;
2547 
2548 	  case 'E':		/* error message header/header file */
2549 		if (*val != '\0')
2550 			ErrMsgFile = newstr(val);
2551 		break;
2552 
2553 	  case 'e':		/* set error processing mode */
2554 		switch (*val)
2555 		{
2556 		  case EM_QUIET:	/* be silent about it */
2557 		  case EM_MAIL:		/* mail back */
2558 		  case EM_BERKNET:	/* do berknet error processing */
2559 		  case EM_WRITE:	/* write back (or mail) */
2560 		  case EM_PRINT:	/* print errors normally (default) */
2561 			e->e_errormode = *val;
2562 			break;
2563 		}
2564 		break;
2565 
2566 	  case 'F':		/* file mode */
2567 		FileMode = atooct(val) & 0777;
2568 		break;
2569 
2570 	  case 'f':		/* save Unix-style From lines on front */
2571 		SaveFrom = atobool(val);
2572 		break;
2573 
2574 	  case 'G':		/* match recipients against GECOS field */
2575 		MatchGecos = atobool(val);
2576 		break;
2577 
2578 	  case 'g':		/* default gid */
2579   g_opt:
2580 		if (isascii(*val) && isdigit(*val))
2581 			DefGid = atoi(val);
2582 		else
2583 		{
2584 			register struct group *gr;
2585 
2586 			DefGid = -1;
2587 			gr = getgrnam(val);
2588 			if (gr == NULL)
2589 				syserr("readcf: option %c: unknown group %s",
2590 					opt, val);
2591 			else
2592 				DefGid = gr->gr_gid;
2593 		}
2594 		break;
2595 
2596 	  case 'H':		/* help file */
2597 		if (val[0] == '\0')
2598 		{
2599 			SET_OPT_DEFAULT(HelpFile, "helpfile");
2600 		}
2601 		else
2602 		{
2603 			CANONIFY(val);
2604 			HelpFile = newstr(val);
2605 		}
2606 		break;
2607 
2608 	  case 'h':		/* maximum hop count */
2609 		MaxHopCount = atoi(val);
2610 		break;
2611 
2612 	  case 'I':		/* use internet domain name server */
2613 #if NAMED_BIND
2614 		for (p = val; *p != 0; )
2615 		{
2616 			bool clearmode;
2617 			char *q;
2618 			struct resolverflags *rfp;
2619 
2620 			while (*p == ' ')
2621 				p++;
2622 			if (*p == '\0')
2623 				break;
2624 			clearmode = false;
2625 			if (*p == '-')
2626 				clearmode = true;
2627 			else if (*p != '+')
2628 				p--;
2629 			p++;
2630 			q = p;
2631 			while (*p != '\0' && !(isascii(*p) && isspace(*p)))
2632 				p++;
2633 			if (*p != '\0')
2634 				*p++ = '\0';
2635 			if (sm_strcasecmp(q, "HasWildcardMX") == 0)
2636 			{
2637 				HasWildcardMX = !clearmode;
2638 				continue;
2639 			}
2640 			if (sm_strcasecmp(q, "WorkAroundBrokenAAAA") == 0)
2641 			{
2642 				WorkAroundBrokenAAAA = !clearmode;
2643 				continue;
2644 			}
2645 			for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
2646 			{
2647 				if (sm_strcasecmp(q, rfp->rf_name) == 0)
2648 					break;
2649 			}
2650 			if (rfp->rf_name == NULL)
2651 				syserr("readcf: I option value %s unrecognized", q);
2652 			else if (clearmode)
2653 				_res.options &= ~rfp->rf_bits;
2654 			else
2655 				_res.options |= rfp->rf_bits;
2656 		}
2657 		if (tTd(8, 2))
2658 			sm_dprintf("_res.options = %x, HasWildcardMX = %d\n",
2659 				   (unsigned int) _res.options, HasWildcardMX);
2660 #else /* NAMED_BIND */
2661 		usrerr("name server (I option) specified but BIND not compiled in");
2662 #endif /* NAMED_BIND */
2663 		break;
2664 
2665 	  case 'i':		/* ignore dot lines in message */
2666 		IgnrDot = atobool(val);
2667 		break;
2668 
2669 	  case 'j':		/* send errors in MIME (RFC 1341) format */
2670 		SendMIMEErrors = atobool(val);
2671 		break;
2672 
2673 	  case 'J':		/* .forward search path */
2674 		CANONIFY(val);
2675 		ForwardPath = newstr(val);
2676 		break;
2677 
2678 	  case 'k':		/* connection cache size */
2679 		MaxMciCache = atoi(val);
2680 		if (MaxMciCache < 0)
2681 			MaxMciCache = 0;
2682 		break;
2683 
2684 	  case 'K':		/* connection cache timeout */
2685 		MciCacheTimeout = convtime(val, 'm');
2686 		break;
2687 
2688 	  case 'l':		/* use Errors-To: header */
2689 		UseErrorsTo = atobool(val);
2690 		break;
2691 
2692 	  case 'L':		/* log level */
2693 		if (safe || LogLevel < atoi(val))
2694 			LogLevel = atoi(val);
2695 		break;
2696 
2697 	  case 'M':		/* define macro */
2698 		sticky = false;
2699 		mid = macid_parse(val, &ep);
2700 		if (mid == 0)
2701 			break;
2702 		p = newstr(ep);
2703 		if (!safe)
2704 			cleanstrcpy(p, p, strlen(p) + 1);
2705 		macdefine(&CurEnv->e_macro, A_TEMP, mid, p);
2706 		break;
2707 
2708 	  case 'm':		/* send to me too */
2709 		MeToo = atobool(val);
2710 		break;
2711 
2712 	  case 'n':		/* validate RHS in newaliases */
2713 		CheckAliases = atobool(val);
2714 		break;
2715 
2716 	    /* 'N' available -- was "net name" */
2717 
2718 	  case 'O':		/* daemon options */
2719 		if (!setdaemonoptions(val))
2720 			syserr("too many daemons defined (%d max)", MAXDAEMONS);
2721 		break;
2722 
2723 	  case 'o':		/* assume old style headers */
2724 		if (atobool(val))
2725 			CurEnv->e_flags |= EF_OLDSTYLE;
2726 		else
2727 			CurEnv->e_flags &= ~EF_OLDSTYLE;
2728 		break;
2729 
2730 	  case 'p':		/* select privacy level */
2731 		p = val;
2732 		for (;;)
2733 		{
2734 			register struct prival *pv;
2735 			extern struct prival PrivacyValues[];
2736 
2737 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
2738 				p++;
2739 			if (*p == '\0')
2740 				break;
2741 			val = p;
2742 			while (isascii(*p) && isalnum(*p))
2743 				p++;
2744 			if (*p != '\0')
2745 				*p++ = '\0';
2746 
2747 			for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
2748 			{
2749 				if (sm_strcasecmp(val, pv->pv_name) == 0)
2750 					break;
2751 			}
2752 			if (pv->pv_name == NULL)
2753 				syserr("readcf: Op line: %s unrecognized", val);
2754 			else
2755 				PrivacyFlags |= pv->pv_flag;
2756 		}
2757 		sticky = false;
2758 		break;
2759 
2760 	  case 'P':		/* postmaster copy address for returned mail */
2761 		PostMasterCopy = newstr(val);
2762 		break;
2763 
2764 	  case 'q':		/* slope of queue only function */
2765 		QueueFactor = atoi(val);
2766 		break;
2767 
2768 	  case 'Q':		/* queue directory */
2769 		if (val[0] == '\0')
2770 		{
2771 			QueueDir = "mqueue";
2772 		}
2773 		else
2774 		{
2775 			QueueDir = newstr(val);
2776 		}
2777 		if (RealUid != 0 && !safe)
2778 			Warn_Q_option = true;
2779 		break;
2780 
2781 	  case 'R':		/* don't prune routes */
2782 		DontPruneRoutes = atobool(val);
2783 		break;
2784 
2785 	  case 'r':		/* read timeout */
2786 		if (subopt == NULL)
2787 			inittimeouts(val, sticky);
2788 		else
2789 			settimeout(subopt, val, sticky);
2790 		break;
2791 
2792 	  case 'S':		/* status file */
2793 		if (val[0] == '\0')
2794 		{
2795 			SET_OPT_DEFAULT(StatFile, "statistics");
2796 		}
2797 		else
2798 		{
2799 			CANONIFY(val);
2800 			StatFile = newstr(val);
2801 		}
2802 		break;
2803 
2804 	  case 's':		/* be super safe, even if expensive */
2805 		if (tolower(*val) == 'i')
2806 			SuperSafe = SAFE_INTERACTIVE;
2807 		else if (tolower(*val) == 'p')
2808 #if MILTER
2809 			SuperSafe = SAFE_REALLY_POSTMILTER;
2810 #else /* MILTER */
2811 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
2812 				"Warning: SuperSafe=PostMilter requires Milter support (-DMILTER)\n");
2813 #endif /* MILTER */
2814 		else
2815 			SuperSafe = atobool(val) ? SAFE_REALLY : SAFE_NO;
2816 		break;
2817 
2818 	  case 'T':		/* queue timeout */
2819 		p = strchr(val, '/');
2820 		if (p != NULL)
2821 		{
2822 			*p++ = '\0';
2823 			settimeout("queuewarn", p, sticky);
2824 		}
2825 		settimeout("queuereturn", val, sticky);
2826 		break;
2827 
2828 	  case 't':		/* time zone name */
2829 		TimeZoneSpec = newstr(val);
2830 		break;
2831 
2832 	  case 'U':		/* location of user database */
2833 		UdbSpec = newstr(val);
2834 		break;
2835 
2836 	  case 'u':		/* set default uid */
2837 		for (p = val; *p != '\0'; p++)
2838 		{
2839 # if _FFR_DOTTED_USERNAMES
2840 			if (*p == '/' || *p == ':')
2841 # else /* _FFR_DOTTED_USERNAMES */
2842 			if (*p == '.' || *p == '/' || *p == ':')
2843 # endif /* _FFR_DOTTED_USERNAMES */
2844 			{
2845 				*p++ = '\0';
2846 				break;
2847 			}
2848 		}
2849 		if (isascii(*val) && isdigit(*val))
2850 		{
2851 			DefUid = atoi(val);
2852 			setdefuser();
2853 		}
2854 		else
2855 		{
2856 			register struct passwd *pw;
2857 
2858 			DefUid = -1;
2859 			pw = sm_getpwnam(val);
2860 			if (pw == NULL)
2861 			{
2862 				syserr("readcf: option u: unknown user %s", val);
2863 				break;
2864 			}
2865 			else
2866 			{
2867 				DefUid = pw->pw_uid;
2868 				DefGid = pw->pw_gid;
2869 				DefUser = newstr(pw->pw_name);
2870 			}
2871 		}
2872 
2873 # ifdef UID_MAX
2874 		if (DefUid > UID_MAX)
2875 		{
2876 			syserr("readcf: option u: uid value (%ld) > UID_MAX (%ld); ignored",
2877 				(long)DefUid, (long)UID_MAX);
2878 			break;
2879 		}
2880 # endif /* UID_MAX */
2881 
2882 		/* handle the group if it is there */
2883 		if (*p == '\0')
2884 			break;
2885 		val = p;
2886 		goto g_opt;
2887 
2888 	  case 'V':		/* fallback MX host */
2889 		if (val[0] != '\0')
2890 			FallbackMX = newstr(val);
2891 		break;
2892 
2893 	  case 'v':		/* run in verbose mode */
2894 		Verbose = atobool(val) ? 1 : 0;
2895 		break;
2896 
2897 	  case 'w':		/* if we are best MX, try host directly */
2898 		TryNullMXList = atobool(val);
2899 		break;
2900 
2901 	    /* 'W' available -- was wizard password */
2902 
2903 	  case 'x':		/* load avg at which to auto-queue msgs */
2904 		QueueLA = atoi(val);
2905 		break;
2906 
2907 	  case 'X':	/* load avg at which to auto-reject connections */
2908 		RefuseLA = atoi(val);
2909 		break;
2910 
2911 	  case O_DELAY_LA:	/* load avg at which to delay connections */
2912 		DelayLA = atoi(val);
2913 		break;
2914 
2915 	  case 'y':		/* work recipient factor */
2916 		WkRecipFact = atoi(val);
2917 		break;
2918 
2919 	  case 'Y':		/* fork jobs during queue runs */
2920 		ForkQueueRuns = atobool(val);
2921 		break;
2922 
2923 	  case 'z':		/* work message class factor */
2924 		WkClassFact = atoi(val);
2925 		break;
2926 
2927 	  case 'Z':		/* work time factor */
2928 		WkTimeFact = atoi(val);
2929 		break;
2930 
2931 
2932 #if _FFR_QUEUE_GROUP_SORTORDER
2933 	/* coordinate this with makequeue() */
2934 #endif /* _FFR_QUEUE_GROUP_SORTORDER */
2935 	  case O_QUEUESORTORD:	/* queue sorting order */
2936 		switch (*val)
2937 		{
2938 		  case 'f':	/* File Name */
2939 		  case 'F':
2940 			QueueSortOrder = QSO_BYFILENAME;
2941 			break;
2942 
2943 		  case 'h':	/* Host first */
2944 		  case 'H':
2945 			QueueSortOrder = QSO_BYHOST;
2946 			break;
2947 
2948 		  case 'm':	/* Modification time */
2949 		  case 'M':
2950 			QueueSortOrder = QSO_BYMODTIME;
2951 			break;
2952 
2953 		  case 'p':	/* Priority order */
2954 		  case 'P':
2955 			QueueSortOrder = QSO_BYPRIORITY;
2956 			break;
2957 
2958 		  case 't':	/* Submission time */
2959 		  case 'T':
2960 			QueueSortOrder = QSO_BYTIME;
2961 			break;
2962 
2963 		  case 'r':	/* Random */
2964 		  case 'R':
2965 			QueueSortOrder = QSO_RANDOM;
2966 			break;
2967 
2968 #if _FFR_RHS
2969 		  case 's':	/* Shuffled host name */
2970 		  case 'S':
2971 			QueueSortOrder = QSO_BYSHUFFLE;
2972 			break;
2973 #endif /* _FFR_RHS */
2974 
2975 		  case 'n':	/* none */
2976 		  case 'N':
2977 			QueueSortOrder = QSO_NONE;
2978 			break;
2979 
2980 		  default:
2981 			syserr("Invalid queue sort order \"%s\"", val);
2982 		}
2983 		break;
2984 
2985 	  case O_HOSTSFILE:	/* pathname of /etc/hosts file */
2986 		CANONIFY(val);
2987 		HostsFile = newstr(val);
2988 		break;
2989 
2990 	  case O_MQA:		/* minimum queue age between deliveries */
2991 		MinQueueAge = convtime(val, 'm');
2992 		break;
2993 
2994 	  case O_DEFCHARSET:	/* default character set for mimefying */
2995 		DefaultCharSet = newstr(denlstring(val, true, true));
2996 		break;
2997 
2998 	  case O_SSFILE:	/* service switch file */
2999 		CANONIFY(val);
3000 		ServiceSwitchFile = newstr(val);
3001 		break;
3002 
3003 	  case O_DIALDELAY:	/* delay for dial-on-demand operation */
3004 		DialDelay = convtime(val, 's');
3005 		break;
3006 
3007 	  case O_NORCPTACTION:	/* what to do if no recipient */
3008 		if (sm_strcasecmp(val, "none") == 0)
3009 			NoRecipientAction = NRA_NO_ACTION;
3010 		else if (sm_strcasecmp(val, "add-to") == 0)
3011 			NoRecipientAction = NRA_ADD_TO;
3012 		else if (sm_strcasecmp(val, "add-apparently-to") == 0)
3013 			NoRecipientAction = NRA_ADD_APPARENTLY_TO;
3014 		else if (sm_strcasecmp(val, "add-bcc") == 0)
3015 			NoRecipientAction = NRA_ADD_BCC;
3016 		else if (sm_strcasecmp(val, "add-to-undisclosed") == 0)
3017 			NoRecipientAction = NRA_ADD_TO_UNDISCLOSED;
3018 		else
3019 			syserr("Invalid NoRecipientAction: %s", val);
3020 		break;
3021 
3022 	  case O_SAFEFILEENV:	/* chroot() environ for writing to files */
3023 		if (*val == '\0')
3024 			break;
3025 
3026 		/* strip trailing slashes */
3027 		p = val + strlen(val) - 1;
3028 		while (p >= val && *p == '/')
3029 			*p-- = '\0';
3030 
3031 		if (*val == '\0')
3032 			break;
3033 
3034 		SafeFileEnv = newstr(val);
3035 		break;
3036 
3037 	  case O_MAXMSGSIZE:	/* maximum message size */
3038 		MaxMessageSize = atol(val);
3039 		break;
3040 
3041 	  case O_COLONOKINADDR:	/* old style handling of colon addresses */
3042 		ColonOkInAddr = atobool(val);
3043 		break;
3044 
3045 	  case O_MAXQUEUERUN:	/* max # of jobs in a single queue run */
3046 		MaxQueueRun = atoi(val);
3047 		break;
3048 
3049 	  case O_MAXCHILDREN:	/* max # of children of daemon */
3050 		MaxChildren = atoi(val);
3051 		break;
3052 
3053 	  case O_MAXQUEUECHILDREN: /* max # of children of daemon */
3054 		MaxQueueChildren = atoi(val);
3055 		break;
3056 
3057 	  case O_MAXRUNNERSPERQUEUE: /* max # runners in a queue group */
3058 		MaxRunnersPerQueue = atoi(val);
3059 		break;
3060 
3061 	  case O_NICEQUEUERUN:		/* nice queue runs */
3062 #if !HASNICE
3063 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3064 				     "Warning: NiceQueueRun set on system that doesn't support nice()\n");
3065 #endif /* !HASNICE */
3066 
3067 		/* XXX do we want to check the range? > 0 ? */
3068 		NiceQueueRun = atoi(val);
3069 		break;
3070 
3071 	  case O_SHMKEY:		/* shared memory key */
3072 #if SM_CONF_SHM
3073 		ShmKey = atol(val);
3074 #else /* SM_CONF_SHM */
3075 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3076 				     "Warning: Option: %s requires shared memory support (-DSM_CONF_SHM)\n",
3077 				     OPTNAME);
3078 #endif /* SM_CONF_SHM */
3079 		break;
3080 
3081 	  case O_SHMKEYFILE:		/* shared memory key file */
3082 #if SM_CONF_SHM
3083 		SET_STRING_EXP(ShmKeyFile);
3084 #else /* SM_CONF_SHM */
3085 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3086 				     "Warning: Option: %s requires shared memory support (-DSM_CONF_SHM)\n",
3087 				     OPTNAME);
3088 		break;
3089 #endif /* SM_CONF_SHM */
3090 
3091 #if _FFR_MAX_FORWARD_ENTRIES
3092 	  case O_MAXFORWARD:	/* max # of forward entries */
3093 		MaxForwardEntries = atoi(val);
3094 		break;
3095 #endif /* _FFR_MAX_FORWARD_ENTRIES */
3096 
3097 	  case O_KEEPCNAMES:	/* don't expand CNAME records */
3098 		DontExpandCnames = atobool(val);
3099 		break;
3100 
3101 	  case O_MUSTQUOTE:	/* must quote these characters in phrases */
3102 		(void) sm_strlcpy(buf, "@,;:\\()[]", sizeof(buf));
3103 		if (strlen(val) < sizeof(buf) - 10)
3104 			(void) sm_strlcat(buf, val, sizeof(buf));
3105 		else
3106 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3107 					     "Warning: MustQuoteChars too long, ignored.\n");
3108 		MustQuoteChars = newstr(buf);
3109 		break;
3110 
3111 	  case O_SMTPGREETING:	/* SMTP greeting message (old $e macro) */
3112 		SmtpGreeting = newstr(munchstring(val, NULL, '\0'));
3113 		break;
3114 
3115 	  case O_UNIXFROM:	/* UNIX From_ line (old $l macro) */
3116 		UnixFromLine = newstr(munchstring(val, NULL, '\0'));
3117 		break;
3118 
3119 	  case O_OPCHARS:	/* operator characters (old $o macro) */
3120 		if (OperatorChars != NULL)
3121 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3122 					     "Warning: OperatorChars is being redefined.\n         It should only be set before ruleset definitions.\n");
3123 		OperatorChars = newstr(munchstring(val, NULL, '\0'));
3124 		break;
3125 
3126 	  case O_DONTINITGRPS:	/* don't call initgroups(3) */
3127 		DontInitGroups = atobool(val);
3128 		break;
3129 
3130 	  case O_SLFH:		/* make sure from fits on one line */
3131 		SingleLineFromHeader = atobool(val);
3132 		break;
3133 
3134 	  case O_ABH:		/* allow HELO commands with syntax errors */
3135 		AllowBogusHELO = atobool(val);
3136 		break;
3137 
3138 	  case O_CONNTHROT:	/* connection rate throttle */
3139 		ConnRateThrottle = atoi(val);
3140 		break;
3141 
3142 	  case O_UGW:		/* group writable files are unsafe */
3143 		if (!atobool(val))
3144 		{
3145 			setbitn(DBS_GROUPWRITABLEFORWARDFILESAFE,
3146 				DontBlameSendmail);
3147 			setbitn(DBS_GROUPWRITABLEINCLUDEFILESAFE,
3148 				DontBlameSendmail);
3149 		}
3150 		break;
3151 
3152 	  case O_DBLBOUNCE:	/* address to which to send double bounces */
3153 		DoubleBounceAddr = newstr(val);
3154 		break;
3155 
3156 	  case O_HSDIR:		/* persistent host status directory */
3157 		if (val[0] != '\0')
3158 		{
3159 			CANONIFY(val);
3160 			HostStatDir = newstr(val);
3161 		}
3162 		break;
3163 
3164 	  case O_SINGTHREAD:	/* single thread deliveries (requires hsdir) */
3165 		SingleThreadDelivery = atobool(val);
3166 		break;
3167 
3168 	  case O_RUNASUSER:	/* run bulk of code as this user */
3169 		for (p = val; *p != '\0'; p++)
3170 		{
3171 # if _FFR_DOTTED_USERNAMES
3172 			if (*p == '/' || *p == ':')
3173 # else /* _FFR_DOTTED_USERNAMES */
3174 			if (*p == '.' || *p == '/' || *p == ':')
3175 # endif /* _FFR_DOTTED_USERNAMES */
3176 			{
3177 				*p++ = '\0';
3178 				break;
3179 			}
3180 		}
3181 		if (isascii(*val) && isdigit(*val))
3182 		{
3183 			if (can_setuid)
3184 				RunAsUid = atoi(val);
3185 		}
3186 		else
3187 		{
3188 			register struct passwd *pw;
3189 
3190 			pw = sm_getpwnam(val);
3191 			if (pw == NULL)
3192 			{
3193 				syserr("readcf: option RunAsUser: unknown user %s", val);
3194 				break;
3195 			}
3196 			else if (can_setuid)
3197 			{
3198 				if (*p == '\0')
3199 					RunAsUserName = newstr(val);
3200 				RunAsUid = pw->pw_uid;
3201 				RunAsGid = pw->pw_gid;
3202 			}
3203 			else if (EffGid == pw->pw_gid)
3204 				RunAsGid = pw->pw_gid;
3205 			else if (UseMSP && *p == '\0')
3206 				(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3207 						     "WARNING: RunAsUser for MSP ignored, check group ids (egid=%d, want=%d)\n",
3208 						     (int) EffGid,
3209 						     (int) pw->pw_gid);
3210 		}
3211 # ifdef UID_MAX
3212 		if (RunAsUid > UID_MAX)
3213 		{
3214 			syserr("readcf: option RunAsUser: uid value (%ld) > UID_MAX (%ld); ignored",
3215 				(long) RunAsUid, (long) UID_MAX);
3216 			break;
3217 		}
3218 # endif /* UID_MAX */
3219 		if (*p != '\0')
3220 		{
3221 			if (isascii(*p) && isdigit(*p))
3222 			{
3223 				gid_t runasgid;
3224 
3225 				runasgid = (gid_t) atoi(p);
3226 				if (can_setuid || EffGid == runasgid)
3227 					RunAsGid = runasgid;
3228 				else if (UseMSP)
3229 					(void) sm_io_fprintf(smioout,
3230 							     SM_TIME_DEFAULT,
3231 							     "WARNING: RunAsUser for MSP ignored, check group ids (egid=%d, want=%d)\n",
3232 							     (int) EffGid,
3233 							     (int) runasgid);
3234 			}
3235 			else
3236 			{
3237 				register struct group *gr;
3238 
3239 				gr = getgrnam(p);
3240 				if (gr == NULL)
3241 					syserr("readcf: option RunAsUser: unknown group %s",
3242 						p);
3243 				else if (can_setuid || EffGid == gr->gr_gid)
3244 					RunAsGid = gr->gr_gid;
3245 				else if (UseMSP)
3246 					(void) sm_io_fprintf(smioout,
3247 							     SM_TIME_DEFAULT,
3248 							     "WARNING: RunAsUser for MSP ignored, check group ids (egid=%d, want=%d)\n",
3249 							     (int) EffGid,
3250 							     (int) gr->gr_gid);
3251 			}
3252 		}
3253 		if (tTd(47, 5))
3254 			sm_dprintf("readcf: RunAsUser = %d:%d\n",
3255 				   (int) RunAsUid, (int) RunAsGid);
3256 		break;
3257 
3258 	  case O_DSN_RRT:
3259 		RrtImpliesDsn = atobool(val);
3260 		break;
3261 
3262 	  case O_PIDFILE:
3263 		PSTRSET(PidFile, val);
3264 		break;
3265 
3266 	  case O_DONTBLAMESENDMAIL:
3267 		p = val;
3268 		for (;;)
3269 		{
3270 			register struct dbsval *dbs;
3271 			extern struct dbsval DontBlameSendmailValues[];
3272 
3273 			while (isascii(*p) && (isspace(*p) || ispunct(*p)))
3274 				p++;
3275 			if (*p == '\0')
3276 				break;
3277 			val = p;
3278 			while (isascii(*p) && isalnum(*p))
3279 				p++;
3280 			if (*p != '\0')
3281 				*p++ = '\0';
3282 
3283 			for (dbs = DontBlameSendmailValues;
3284 			     dbs->dbs_name != NULL; dbs++)
3285 			{
3286 				if (sm_strcasecmp(val, dbs->dbs_name) == 0)
3287 					break;
3288 			}
3289 			if (dbs->dbs_name == NULL)
3290 				syserr("readcf: DontBlameSendmail option: %s unrecognized", val);
3291 			else if (dbs->dbs_flag == DBS_SAFE)
3292 				clrbitmap(DontBlameSendmail);
3293 			else
3294 				setbitn(dbs->dbs_flag, DontBlameSendmail);
3295 		}
3296 		sticky = false;
3297 		break;
3298 
3299 	  case O_DPI:
3300 		if (sm_strcasecmp(val, "loopback") == 0)
3301 			DontProbeInterfaces = DPI_SKIPLOOPBACK;
3302 		else if (atobool(val))
3303 			DontProbeInterfaces = DPI_PROBENONE;
3304 		else
3305 			DontProbeInterfaces = DPI_PROBEALL;
3306 		break;
3307 
3308 	  case O_MAXRCPT:
3309 		MaxRcptPerMsg = atoi(val);
3310 		break;
3311 
3312 	  case O_RCPTTHROT:
3313 		BadRcptThrottle = atoi(val);
3314 		break;
3315 
3316 	  case O_DEADLETTER:
3317 		CANONIFY(val);
3318 		PSTRSET(DeadLetterDrop, val);
3319 		break;
3320 
3321 #if _FFR_DONTLOCKFILESFORREAD_OPTION
3322 	  case O_DONTLOCK:
3323 		DontLockReadFiles = atobool(val);
3324 		break;
3325 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
3326 
3327 	  case O_MAXALIASRCSN:
3328 		MaxAliasRecursion = atoi(val);
3329 		break;
3330 
3331 	  case O_CNCTONLYTO:
3332 		/* XXX should probably use gethostbyname */
3333 #if NETINET || NETINET6
3334 		ConnectOnlyTo.sa.sa_family = AF_UNSPEC;
3335 # if NETINET6
3336 		if (anynet_pton(AF_INET6, val,
3337 				&ConnectOnlyTo.sin6.sin6_addr) != 1)
3338 			ConnectOnlyTo.sa.sa_family = AF_INET6;
3339 		else
3340 # endif /* NETINET6 */
3341 # if NETINET
3342 		{
3343 			ConnectOnlyTo.sin.sin_addr.s_addr = inet_addr(val);
3344 			if (ConnectOnlyTo.sin.sin_addr.s_addr != INADDR_NONE)
3345 				ConnectOnlyTo.sa.sa_family = AF_INET;
3346 		}
3347 
3348 # endif /* NETINET */
3349 		if (ConnectOnlyTo.sa.sa_family == AF_UNSPEC)
3350 		{
3351 			syserr("readcf: option ConnectOnlyTo: invalid IP address %s",
3352 			       val);
3353 			break;
3354 		}
3355 #endif /* NETINET || NETINET6 */
3356 		break;
3357 
3358 	  case O_TRUSTUSER:
3359 # if !HASFCHOWN && !defined(_FFR_DROP_TRUSTUSER_WARNING)
3360 		if (!UseMSP)
3361 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3362 					     "readcf: option TrustedUser may cause problems on systems\n        which do not support fchown() if UseMSP is not set.\n");
3363 # endif /* !HASFCHOWN && !defined(_FFR_DROP_TRUSTUSER_WARNING) */
3364 		if (isascii(*val) && isdigit(*val))
3365 			TrustedUid = atoi(val);
3366 		else
3367 		{
3368 			register struct passwd *pw;
3369 
3370 			TrustedUid = 0;
3371 			pw = sm_getpwnam(val);
3372 			if (pw == NULL)
3373 			{
3374 				syserr("readcf: option TrustedUser: unknown user %s", val);
3375 				break;
3376 			}
3377 			else
3378 				TrustedUid = pw->pw_uid;
3379 		}
3380 
3381 # ifdef UID_MAX
3382 		if (TrustedUid > UID_MAX)
3383 		{
3384 			syserr("readcf: option TrustedUser: uid value (%ld) > UID_MAX (%ld)",
3385 				(long) TrustedUid, (long) UID_MAX);
3386 			TrustedUid = 0;
3387 		}
3388 # endif /* UID_MAX */
3389 		break;
3390 
3391 	  case O_MAXMIMEHDRLEN:
3392 		p = strchr(val, '/');
3393 		if (p != NULL)
3394 			*p++ = '\0';
3395 		MaxMimeHeaderLength = atoi(val);
3396 		if (p != NULL && *p != '\0')
3397 			MaxMimeFieldLength = atoi(p);
3398 		else
3399 			MaxMimeFieldLength = MaxMimeHeaderLength / 2;
3400 
3401 		if (MaxMimeHeaderLength <= 0)
3402 			MaxMimeHeaderLength = 0;
3403 		else if (MaxMimeHeaderLength < 128)
3404 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3405 					     "Warning: MaxMimeHeaderLength: header length limit set lower than 128\n");
3406 
3407 		if (MaxMimeFieldLength <= 0)
3408 			MaxMimeFieldLength = 0;
3409 		else if (MaxMimeFieldLength < 40)
3410 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3411 					     "Warning: MaxMimeHeaderLength: field length limit set lower than 40\n");
3412 
3413 		/*
3414 		**  Headers field values now include leading space, so let's
3415 		**  adjust the values to be "backward compatible".
3416 		*/
3417 
3418 		if (MaxMimeHeaderLength > 0)
3419 			MaxMimeHeaderLength++;
3420 		if (MaxMimeFieldLength > 0)
3421 			MaxMimeFieldLength++;
3422 		break;
3423 
3424 	  case O_CONTROLSOCKET:
3425 		PSTRSET(ControlSocketName, val);
3426 		break;
3427 
3428 	  case O_MAXHDRSLEN:
3429 		MaxHeadersLength = atoi(val);
3430 
3431 		if (MaxHeadersLength > 0 &&
3432 		    MaxHeadersLength < (MAXHDRSLEN / 2))
3433 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3434 					     "Warning: MaxHeadersLength: headers length limit set lower than %d\n",
3435 					     (MAXHDRSLEN / 2));
3436 		break;
3437 
3438 	  case O_PROCTITLEPREFIX:
3439 		PSTRSET(ProcTitlePrefix, val);
3440 		break;
3441 
3442 #if SASL
3443 	  case O_SASLINFO:
3444 # if _FFR_ALLOW_SASLINFO
3445 		/*
3446 		**  Allow users to select their own authinfo file
3447 		**  under certain circumstances, otherwise just ignore
3448 		**  the option.  If the option isn't ignored, several
3449 		**  commands don't work very well, e.g., mailq.
3450 		**  However, this is not a "perfect" solution.
3451 		**  If mail is queued, the authentication info
3452 		**  will not be used in subsequent delivery attempts.
3453 		**  If we really want to support this, then it has
3454 		**  to be stored in the queue file.
3455 		*/
3456 		if (!bitset(SUBMIT_MSA, SubmitMode) && RealUid != 0 &&
3457 		    RunAsUid != RealUid)
3458 			break;
3459 # endif /* _FFR_ALLOW_SASLINFO */
3460 		PSTRSET(SASLInfo, val);
3461 		break;
3462 
3463 	  case O_SASLMECH:
3464 		if (AuthMechanisms != NULL)
3465 			sm_free(AuthMechanisms); /* XXX */
3466 		if (*val != '\0')
3467 			AuthMechanisms = newstr(val);
3468 		else
3469 			AuthMechanisms = NULL;
3470 		break;
3471 
3472 	  case O_SASLREALM:
3473 		if (AuthRealm != NULL)
3474 			sm_free(AuthRealm);
3475 		if (*val != '\0')
3476 			AuthRealm = newstr(val);
3477 		else
3478 			AuthRealm = NULL;
3479 		break;
3480 
3481 	  case O_SASLOPTS:
3482 		while (val != NULL && *val != '\0')
3483 		{
3484 			switch (*val)
3485 			{
3486 			  case 'A':
3487 				SASLOpts |= SASL_AUTH_AUTH;
3488 				break;
3489 
3490 			  case 'a':
3491 				SASLOpts |= SASL_SEC_NOACTIVE;
3492 				break;
3493 
3494 			  case 'c':
3495 				SASLOpts |= SASL_SEC_PASS_CREDENTIALS;
3496 				break;
3497 
3498 			  case 'd':
3499 				SASLOpts |= SASL_SEC_NODICTIONARY;
3500 				break;
3501 
3502 			  case 'f':
3503 				SASLOpts |= SASL_SEC_FORWARD_SECRECY;
3504 				break;
3505 
3506 #  if SASL >= 20101
3507 			  case 'm':
3508 				SASLOpts |= SASL_SEC_MUTUAL_AUTH;
3509 				break;
3510 #  endif /* SASL >= 20101 */
3511 
3512 			  case 'p':
3513 				SASLOpts |= SASL_SEC_NOPLAINTEXT;
3514 				break;
3515 
3516 			  case 'y':
3517 				SASLOpts |= SASL_SEC_NOANONYMOUS;
3518 				break;
3519 
3520 			  case ' ':	/* ignore */
3521 			  case '\t':	/* ignore */
3522 			  case ',':	/* ignore */
3523 				break;
3524 
3525 			  default:
3526 				(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3527 						     "Warning: Option: %s unknown parameter '%c'\n",
3528 						     OPTNAME,
3529 						     (isascii(*val) &&
3530 							isprint(*val))
3531 							? *val : '?');
3532 				break;
3533 			}
3534 			++val;
3535 			val = strpbrk(val, ", \t");
3536 			if (val != NULL)
3537 				++val;
3538 		}
3539 		break;
3540 
3541 	  case O_SASLBITS:
3542 		MaxSLBits = atoi(val);
3543 		break;
3544 
3545 #else /* SASL */
3546 	  case O_SASLINFO:
3547 	  case O_SASLMECH:
3548 	  case O_SASLREALM:
3549 	  case O_SASLOPTS:
3550 	  case O_SASLBITS:
3551 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3552 				     "Warning: Option: %s requires SASL support (-DSASL)\n",
3553 				     OPTNAME);
3554 		break;
3555 #endif /* SASL */
3556 
3557 #if STARTTLS
3558 	  case O_SRVCERTFILE:
3559 		SET_STRING_EXP(SrvCertFile);
3560 	  case O_SRVKEYFILE:
3561 		SET_STRING_EXP(SrvKeyFile);
3562 	  case O_CLTCERTFILE:
3563 		SET_STRING_EXP(CltCertFile);
3564 	  case O_CLTKEYFILE:
3565 		SET_STRING_EXP(CltKeyFile);
3566 	  case O_CACERTFILE:
3567 		SET_STRING_EXP(CACertFile);
3568 	  case O_CACERTPATH:
3569 		SET_STRING_EXP(CACertPath);
3570 	  case O_DHPARAMS:
3571 		SET_STRING_EXP(DHParams);
3572 # if _FFR_TLS_1
3573 	  case O_DHPARAMS5:
3574 		SET_STRING_EXP(DHParams5);
3575 	  case O_CIPHERLIST:
3576 		SET_STRING_EXP(CipherList);
3577 # endif /* _FFR_TLS_1 */
3578 	  case O_CRLFILE:
3579 # if OPENSSL_VERSION_NUMBER > 0x00907000L
3580 		SET_STRING_EXP(CRLFile);
3581 # else /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3582 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3583 				     "Warning: Option: %s requires at least OpenSSL 0.9.7\n",
3584 				     OPTNAME);
3585 		break;
3586 # endif /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3587 
3588 # if _FFR_CRLPATH
3589 	  case O_CRLPATH:
3590 #  if OPENSSL_VERSION_NUMBER > 0x00907000L
3591 		SET_STRING_EXP(CRLPath);
3592 #  else /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3593 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3594 				     "Warning: Option: %s requires at least OpenSSL 0.9.7\n",
3595 				     OPTNAME);
3596 		break;
3597 #  endif /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3598 # endif /* _FFR_CRLPATH */
3599 
3600 	/*
3601 	**  XXX How about options per daemon/client instead of globally?
3602 	**  This doesn't work well for some options, e.g., no server cert,
3603 	**  but fine for others.
3604 	**
3605 	**  XXX Some people may want different certs per server.
3606 	**
3607 	**  See also srvfeatures()
3608 	*/
3609 
3610 	  case O_TLS_SRV_OPTS:
3611 		while (val != NULL && *val != '\0')
3612 		{
3613 			switch (*val)
3614 			{
3615 			  case 'V':
3616 				TLS_Srv_Opts |= TLS_I_NO_VRFY;
3617 				break;
3618 # if _FFR_TLS_1
3619 			/*
3620 			**  Server without a cert? That works only if
3621 			**  AnonDH is enabled as cipher, which is not in the
3622 			**  default list. Hence the CipherList option must
3623 			**  be available. Moreover: which clients support this
3624 			**  besides sendmail with this setting?
3625 			*/
3626 
3627 			  case 'C':
3628 				TLS_Srv_Opts &= ~TLS_I_SRV_CERT;
3629 				break;
3630 # endif /* _FFR_TLS_1 */
3631 			  case ' ':	/* ignore */
3632 			  case '\t':	/* ignore */
3633 			  case ',':	/* ignore */
3634 				break;
3635 			  default:
3636 				(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3637 						     "Warning: Option: %s unknown parameter '%c'\n",
3638 						     OPTNAME,
3639 						     (isascii(*val) &&
3640 							isprint(*val))
3641 							? *val : '?');
3642 				break;
3643 			}
3644 			++val;
3645 			val = strpbrk(val, ", \t");
3646 			if (val != NULL)
3647 				++val;
3648 		}
3649 		break;
3650 
3651 	  case O_RANDFILE:
3652 		PSTRSET(RandFile, val);
3653 		break;
3654 
3655 #else /* STARTTLS */
3656 	  case O_SRVCERTFILE:
3657 	  case O_SRVKEYFILE:
3658 	  case O_CLTCERTFILE:
3659 	  case O_CLTKEYFILE:
3660 	  case O_CACERTFILE:
3661 	  case O_CACERTPATH:
3662 	  case O_DHPARAMS:
3663 # if _FFR_TLS_1
3664 	  case O_DHPARAMS5:
3665 	  case O_CIPHERLIST:
3666 # endif /* _FFR_TLS_1 */
3667 	  case O_CRLFILE:
3668 # if _FFR_CRLPATH
3669 	  case O_CRLPATH:
3670 # endif /* _FFR_CRLPATH */
3671 	  case O_RANDFILE:
3672 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3673 				     "Warning: Option: %s requires TLS support\n",
3674 				     OPTNAME);
3675 		break;
3676 
3677 #endif /* STARTTLS */
3678 
3679 	  case O_CLIENTPORT:
3680 		setclientoptions(val);
3681 		break;
3682 
3683 	  case O_DF_BUFSIZE:
3684 		DataFileBufferSize = atoi(val);
3685 		break;
3686 
3687 	  case O_XF_BUFSIZE:
3688 		XscriptFileBufferSize = atoi(val);
3689 		break;
3690 
3691 	  case O_LDAPDEFAULTSPEC:
3692 #if LDAPMAP
3693 		ldapmap_set_defaults(val);
3694 #else /* LDAPMAP */
3695 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3696 				     "Warning: Option: %s requires LDAP support (-DLDAPMAP)\n",
3697 				     OPTNAME);
3698 #endif /* LDAPMAP */
3699 		break;
3700 
3701 	  case O_INPUTMILTER:
3702 #if MILTER
3703 		InputFilterList = newstr(val);
3704 #else /* MILTER */
3705 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3706 				     "Warning: Option: %s requires Milter support (-DMILTER)\n",
3707 				     OPTNAME);
3708 #endif /* MILTER */
3709 		break;
3710 
3711 	  case O_MILTER:
3712 #if MILTER
3713 		milter_set_option(subopt, val, sticky);
3714 #else /* MILTER */
3715 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3716 				     "Warning: Option: %s requires Milter support (-DMILTER)\n",
3717 				     OPTNAME);
3718 #endif /* MILTER */
3719 		break;
3720 
3721 	  case O_QUEUE_FILE_MODE:	/* queue file mode */
3722 		QueueFileMode = atooct(val) & 0777;
3723 		break;
3724 
3725 	  case O_DLVR_MIN:	/* deliver by minimum time */
3726 		DeliverByMin = convtime(val, 's');
3727 		break;
3728 
3729 	  /* modifiers {daemon_flags} for direct submissions */
3730 	  case O_DIRECTSUBMODIFIERS:
3731 		{
3732 			BITMAP256 m;	/* ignored */
3733 			extern ENVELOPE BlankEnvelope;
3734 
3735 			macdefine(&BlankEnvelope.e_macro, A_PERM,
3736 				  macid("{daemon_flags}"),
3737 				  getmodifiers(val, m));
3738 		}
3739 		break;
3740 
3741 	  case O_FASTSPLIT:
3742 		FastSplit = atoi(val);
3743 		break;
3744 
3745 	  case O_MBDB:
3746 		Mbdb = newstr(val);
3747 		break;
3748 
3749 	  case O_MSQ:
3750 		UseMSP = atobool(val);
3751 		break;
3752 
3753 	  case O_SOFTBOUNCE:
3754 		SoftBounce = atobool(val);
3755 		break;
3756 
3757 	  case O_REJECTLOGINTERVAL:	/* time btwn log msgs while refusing */
3758 		RejectLogInterval = convtime(val, 'h');
3759 		break;
3760 
3761 	  case O_REQUIRES_DIR_FSYNC:
3762 #if REQUIRES_DIR_FSYNC
3763 		RequiresDirfsync = atobool(val);
3764 #else /* REQUIRES_DIR_FSYNC */
3765 		/* silently ignored... required for cf file option */
3766 #endif /* REQUIRES_DIR_FSYNC */
3767 		break;
3768 
3769 	  case O_CONNECTION_RATE_WINDOW_SIZE:
3770 		ConnectionRateWindowSize = convtime(val, 's');
3771 		break;
3772 
3773 	  case O_FALLBACKSMARTHOST:	/* fallback smart host */
3774 		if (val[0] != '\0')
3775 			FallbackSmartHost = newstr(val);
3776 		break;
3777 
3778 	  case O_HELONAME:
3779 		HeloName = newstr(val);
3780 		break;
3781 
3782 #if _FFR_MEMSTAT
3783 	  case O_REFUSELOWMEM:
3784 		RefuseLowMem = atoi(val);
3785 		break;
3786 	  case O_QUEUELOWMEM:
3787 		QueueLowMem = atoi(val);
3788 		break;
3789 	  case O_MEMRESOURCE:
3790 		MemoryResource = newstr(val);
3791 		break;
3792 #endif /* _FFR_MEMSTAT */
3793 
3794 	  case O_MAXNOOPCOMMANDS:
3795 		MaxNOOPCommands = atoi(val);
3796 		break;
3797 
3798 #if _FFR_MSG_ACCEPT
3799 	  case O_MSG_ACCEPT:
3800 		MessageAccept = newstr(val);
3801 		break;
3802 #endif /* _FFR_MSG_ACCEPT */
3803 
3804 #if _FFR_QUEUE_RUN_PARANOIA
3805 	  case O_CHK_Q_RUNNERS:
3806 		CheckQueueRunners = atoi(val);
3807 		break;
3808 #endif /* _FFR_QUEUE_RUN_PARANOIA */
3809 
3810 #if _FFR_EIGHT_BIT_ADDR_OK
3811 	  case O_EIGHT_BIT_ADDR_OK:
3812 		EightBitAddrOK = atobool(val);
3813 		break;
3814 #endif /* _FFR_EIGHT_BIT_ADDR_OK */
3815 
3816 #if _FFR_ADDR_TYPE_MODES
3817 	  case O_ADDR_TYPE_MODES:
3818 		AddrTypeModes = atobool(val);
3819 		break;
3820 #endif /* _FFR_ADDR_TYPE_MODES */
3821 
3822 	  default:
3823 		if (tTd(37, 1))
3824 		{
3825 			if (isascii(opt) && isprint(opt))
3826 				sm_dprintf("Warning: option %c unknown\n", opt);
3827 			else
3828 				sm_dprintf("Warning: option 0x%x unknown\n", opt);
3829 		}
3830 		break;
3831 	}
3832 
3833 	/*
3834 	**  Options with suboptions are responsible for taking care
3835 	**  of sticky-ness (e.g., that a command line setting is kept
3836 	**  when reading in the sendmail.cf file).  This has to be done
3837 	**  when the suboptions are parsed since each suboption must be
3838 	**  sticky, not the root option.
3839 	*/
3840 
3841 	if (sticky && !bitset(OI_SUBOPT, o->o_flags))
3842 		setbitn(opt, StickyOpt);
3843 }
3844 /*
3845 **  SETCLASS -- set a string into a class
3846 **
3847 **	Parameters:
3848 **		class -- the class to put the string in.
3849 **		str -- the string to enter
3850 **
3851 **	Returns:
3852 **		none.
3853 **
3854 **	Side Effects:
3855 **		puts the word into the symbol table.
3856 */
3857 
3858 void
3859 setclass(class, str)
3860 	int class;
3861 	char *str;
3862 {
3863 	register STAB *s;
3864 
3865 	if ((str[0] & 0377) == MATCHCLASS)
3866 	{
3867 		int mid;
3868 
3869 		str++;
3870 		mid = macid(str);
3871 		if (mid == 0)
3872 			return;
3873 
3874 		if (tTd(37, 8))
3875 			sm_dprintf("setclass(%s, $=%s)\n",
3876 				   macname(class), macname(mid));
3877 		copy_class(mid, class);
3878 	}
3879 	else
3880 	{
3881 		if (tTd(37, 8))
3882 			sm_dprintf("setclass(%s, %s)\n", macname(class), str);
3883 
3884 		s = stab(str, ST_CLASS, ST_ENTER);
3885 		setbitn(bitidx(class), s->s_class);
3886 	}
3887 }
3888 /*
3889 **  MAKEMAPENTRY -- create a map entry
3890 **
3891 **	Parameters:
3892 **		line -- the config file line
3893 **
3894 **	Returns:
3895 **		A pointer to the map that has been created.
3896 **		NULL if there was a syntax error.
3897 **
3898 **	Side Effects:
3899 **		Enters the map into the dictionary.
3900 */
3901 
3902 MAP *
3903 makemapentry(line)
3904 	char *line;
3905 {
3906 	register char *p;
3907 	char *mapname;
3908 	char *classname;
3909 	register STAB *s;
3910 	STAB *class;
3911 
3912 	for (p = line; isascii(*p) && isspace(*p); p++)
3913 		continue;
3914 	if (!(isascii(*p) && isalnum(*p)))
3915 	{
3916 		syserr("readcf: config K line: no map name");
3917 		return NULL;
3918 	}
3919 
3920 	mapname = p;
3921 	while ((isascii(*++p) && isalnum(*p)) || *p == '_' || *p == '.')
3922 		continue;
3923 	if (*p != '\0')
3924 		*p++ = '\0';
3925 	while (isascii(*p) && isspace(*p))
3926 		p++;
3927 	if (!(isascii(*p) && isalnum(*p)))
3928 	{
3929 		syserr("readcf: config K line, map %s: no map class", mapname);
3930 		return NULL;
3931 	}
3932 	classname = p;
3933 	while (isascii(*++p) && isalnum(*p))
3934 		continue;
3935 	if (*p != '\0')
3936 		*p++ = '\0';
3937 	while (isascii(*p) && isspace(*p))
3938 		p++;
3939 
3940 	/* look up the class */
3941 	class = stab(classname, ST_MAPCLASS, ST_FIND);
3942 	if (class == NULL)
3943 	{
3944 		syserr("readcf: map %s: class %s not available", mapname,
3945 			classname);
3946 		return NULL;
3947 	}
3948 
3949 	/* enter the map */
3950 	s = stab(mapname, ST_MAP, ST_ENTER);
3951 	s->s_map.map_class = &class->s_mapclass;
3952 	s->s_map.map_mname = newstr(mapname);
3953 
3954 	if (class->s_mapclass.map_parse(&s->s_map, p))
3955 		s->s_map.map_mflags |= MF_VALID;
3956 
3957 	if (tTd(37, 5))
3958 	{
3959 		sm_dprintf("map %s, class %s, flags %lx, file %s,\n",
3960 			   s->s_map.map_mname, s->s_map.map_class->map_cname,
3961 			   s->s_map.map_mflags, s->s_map.map_file);
3962 		sm_dprintf("\tapp %s, domain %s, rebuild %s\n",
3963 			   s->s_map.map_app, s->s_map.map_domain,
3964 			   s->s_map.map_rebuild);
3965 	}
3966 	return &s->s_map;
3967 }
3968 /*
3969 **  STRTORWSET -- convert string to rewriting set number
3970 **
3971 **	Parameters:
3972 **		p -- the pointer to the string to decode.
3973 **		endp -- if set, store the trailing delimiter here.
3974 **		stabmode -- ST_ENTER to create this entry, ST_FIND if
3975 **			it must already exist.
3976 **
3977 **	Returns:
3978 **		The appropriate ruleset number.
3979 **		-1 if it is not valid (error already printed)
3980 */
3981 
3982 int
3983 strtorwset(p, endp, stabmode)
3984 	char *p;
3985 	char **endp;
3986 	int stabmode;
3987 {
3988 	int ruleset;
3989 	static int nextruleset = MAXRWSETS;
3990 
3991 	while (isascii(*p) && isspace(*p))
3992 		p++;
3993 	if (!isascii(*p))
3994 	{
3995 		syserr("invalid ruleset name: \"%.20s\"", p);
3996 		return -1;
3997 	}
3998 	if (isdigit(*p))
3999 	{
4000 		ruleset = strtol(p, endp, 10);
4001 		if (ruleset >= MAXRWSETS / 2 || ruleset < 0)
4002 		{
4003 			syserr("bad ruleset %d (%d max)",
4004 				ruleset, MAXRWSETS / 2);
4005 			ruleset = -1;
4006 		}
4007 	}
4008 	else
4009 	{
4010 		STAB *s;
4011 		char delim;
4012 		char *q = NULL;
4013 
4014 		q = p;
4015 		while (*p != '\0' && isascii(*p) &&
4016 		       (isalnum(*p) || *p == '_'))
4017 			p++;
4018 		if (q == p || !(isascii(*q) && isalpha(*q)))
4019 		{
4020 			/* no valid characters */
4021 			syserr("invalid ruleset name: \"%.20s\"", q);
4022 			return -1;
4023 		}
4024 		while (isascii(*p) && isspace(*p))
4025 			*p++ = '\0';
4026 		delim = *p;
4027 		if (delim != '\0')
4028 			*p = '\0';
4029 		s = stab(q, ST_RULESET, stabmode);
4030 		if (delim != '\0')
4031 			*p = delim;
4032 
4033 		if (s == NULL)
4034 			return -1;
4035 
4036 		if (stabmode == ST_ENTER && delim == '=')
4037 		{
4038 			while (isascii(*++p) && isspace(*p))
4039 				continue;
4040 			if (!(isascii(*p) && isdigit(*p)))
4041 			{
4042 				syserr("bad ruleset definition \"%s\" (number required after `=')", q);
4043 				ruleset = -1;
4044 			}
4045 			else
4046 			{
4047 				ruleset = strtol(p, endp, 10);
4048 				if (ruleset >= MAXRWSETS / 2 || ruleset < 0)
4049 				{
4050 					syserr("bad ruleset number %d in \"%s\" (%d max)",
4051 						ruleset, q, MAXRWSETS / 2);
4052 					ruleset = -1;
4053 				}
4054 			}
4055 		}
4056 		else
4057 		{
4058 			if (endp != NULL)
4059 				*endp = p;
4060 			if (s->s_ruleset >= 0)
4061 				ruleset = s->s_ruleset;
4062 			else if ((ruleset = --nextruleset) < MAXRWSETS / 2)
4063 			{
4064 				syserr("%s: too many named rulesets (%d max)",
4065 					q, MAXRWSETS / 2);
4066 				ruleset = -1;
4067 			}
4068 		}
4069 		if (s->s_ruleset >= 0 &&
4070 		    ruleset >= 0 &&
4071 		    ruleset != s->s_ruleset)
4072 		{
4073 			syserr("%s: ruleset changed value (old %d, new %d)",
4074 				q, s->s_ruleset, ruleset);
4075 			ruleset = s->s_ruleset;
4076 		}
4077 		else if (ruleset >= 0)
4078 		{
4079 			s->s_ruleset = ruleset;
4080 		}
4081 		if (stabmode == ST_ENTER && ruleset >= 0)
4082 		{
4083 			char *h = NULL;
4084 
4085 			if (RuleSetNames[ruleset] != NULL)
4086 				sm_free(RuleSetNames[ruleset]); /* XXX */
4087 			if (delim != '\0' && (h = strchr(q, delim)) != NULL)
4088 				*h = '\0';
4089 			RuleSetNames[ruleset] = newstr(q);
4090 			if (delim == '/' && h != NULL)
4091 				*h = delim;	/* put back delim */
4092 		}
4093 	}
4094 	return ruleset;
4095 }
4096 /*
4097 **  SETTIMEOUT -- set an individual timeout
4098 **
4099 **	Parameters:
4100 **		name -- the name of the timeout.
4101 **		val -- the value of the timeout.
4102 **		sticky -- if set, don't let other setoptions override
4103 **			this value.
4104 **
4105 **	Returns:
4106 **		none.
4107 */
4108 
4109 /* set if Timeout sub-option is stuck */
4110 static BITMAP256	StickyTimeoutOpt;
4111 
4112 static struct timeoutinfo
4113 {
4114 	char		*to_name;	/* long name of timeout */
4115 	unsigned char	to_code;	/* code for option */
4116 } TimeOutTab[] =
4117 {
4118 #define TO_INITIAL			0x01
4119 	{ "initial",			TO_INITIAL			},
4120 #define TO_MAIL				0x02
4121 	{ "mail",			TO_MAIL				},
4122 #define TO_RCPT				0x03
4123 	{ "rcpt",			TO_RCPT				},
4124 #define TO_DATAINIT			0x04
4125 	{ "datainit",			TO_DATAINIT			},
4126 #define TO_DATABLOCK			0x05
4127 	{ "datablock",			TO_DATABLOCK			},
4128 #define TO_DATAFINAL			0x06
4129 	{ "datafinal",			TO_DATAFINAL			},
4130 #define TO_COMMAND			0x07
4131 	{ "command",			TO_COMMAND			},
4132 #define TO_RSET				0x08
4133 	{ "rset",			TO_RSET				},
4134 #define TO_HELO				0x09
4135 	{ "helo",			TO_HELO				},
4136 #define TO_QUIT				0x0A
4137 	{ "quit",			TO_QUIT				},
4138 #define TO_MISC				0x0B
4139 	{ "misc",			TO_MISC				},
4140 #define TO_IDENT			0x0C
4141 	{ "ident",			TO_IDENT			},
4142 #define TO_FILEOPEN			0x0D
4143 	{ "fileopen",			TO_FILEOPEN			},
4144 #define TO_CONNECT			0x0E
4145 	{ "connect",			TO_CONNECT			},
4146 #define TO_ICONNECT			0x0F
4147 	{ "iconnect",			TO_ICONNECT			},
4148 #define TO_QUEUEWARN			0x10
4149 	{ "queuewarn",			TO_QUEUEWARN			},
4150 	{ "queuewarn.*",		TO_QUEUEWARN			},
4151 #define TO_QUEUEWARN_NORMAL		0x11
4152 	{ "queuewarn.normal",		TO_QUEUEWARN_NORMAL		},
4153 #define TO_QUEUEWARN_URGENT		0x12
4154 	{ "queuewarn.urgent",		TO_QUEUEWARN_URGENT		},
4155 #define TO_QUEUEWARN_NON_URGENT		0x13
4156 	{ "queuewarn.non-urgent",	TO_QUEUEWARN_NON_URGENT		},
4157 #define TO_QUEUERETURN			0x14
4158 	{ "queuereturn",		TO_QUEUERETURN			},
4159 	{ "queuereturn.*",		TO_QUEUERETURN			},
4160 #define TO_QUEUERETURN_NORMAL		0x15
4161 	{ "queuereturn.normal",		TO_QUEUERETURN_NORMAL		},
4162 #define TO_QUEUERETURN_URGENT		0x16
4163 	{ "queuereturn.urgent",		TO_QUEUERETURN_URGENT		},
4164 #define TO_QUEUERETURN_NON_URGENT	0x17
4165 	{ "queuereturn.non-urgent",	TO_QUEUERETURN_NON_URGENT	},
4166 #define TO_HOSTSTATUS			0x18
4167 	{ "hoststatus",			TO_HOSTSTATUS			},
4168 #define TO_RESOLVER_RETRANS		0x19
4169 	{ "resolver.retrans",		TO_RESOLVER_RETRANS		},
4170 #define TO_RESOLVER_RETRANS_NORMAL	0x1A
4171 	{ "resolver.retrans.normal",	TO_RESOLVER_RETRANS_NORMAL	},
4172 #define TO_RESOLVER_RETRANS_FIRST	0x1B
4173 	{ "resolver.retrans.first",	TO_RESOLVER_RETRANS_FIRST	},
4174 #define TO_RESOLVER_RETRY		0x1C
4175 	{ "resolver.retry",		TO_RESOLVER_RETRY		},
4176 #define TO_RESOLVER_RETRY_NORMAL	0x1D
4177 	{ "resolver.retry.normal",	TO_RESOLVER_RETRY_NORMAL	},
4178 #define TO_RESOLVER_RETRY_FIRST		0x1E
4179 	{ "resolver.retry.first",	TO_RESOLVER_RETRY_FIRST		},
4180 #define TO_CONTROL			0x1F
4181 	{ "control",			TO_CONTROL			},
4182 #define TO_LHLO				0x20
4183 	{ "lhlo",			TO_LHLO				},
4184 #define TO_AUTH				0x21
4185 	{ "auth",			TO_AUTH				},
4186 #define TO_STARTTLS			0x22
4187 	{ "starttls",			TO_STARTTLS			},
4188 #define TO_ACONNECT			0x23
4189 	{ "aconnect",			TO_ACONNECT			},
4190 #define TO_QUEUEWARN_DSN		0x24
4191 	{ "queuewarn.dsn",		TO_QUEUEWARN_DSN		},
4192 #define TO_QUEUERETURN_DSN		0x25
4193 	{ "queuereturn.dsn",		TO_QUEUERETURN_DSN		},
4194 	{ NULL,				0				},
4195 };
4196 
4197 
4198 static void
4199 settimeout(name, val, sticky)
4200 	char *name;
4201 	char *val;
4202 	bool sticky;
4203 {
4204 	register struct timeoutinfo *to;
4205 	int i, addopts;
4206 	time_t toval;
4207 
4208 	if (tTd(37, 2))
4209 		sm_dprintf("settimeout(%s = %s)", name, val);
4210 
4211 	for (to = TimeOutTab; to->to_name != NULL; to++)
4212 	{
4213 		if (sm_strcasecmp(to->to_name, name) == 0)
4214 			break;
4215 	}
4216 
4217 	if (to->to_name == NULL)
4218 	{
4219 		errno = 0; /* avoid bogus error text */
4220 		syserr("settimeout: invalid timeout %s", name);
4221 		return;
4222 	}
4223 
4224 	/*
4225 	**  See if this option is preset for us.
4226 	*/
4227 
4228 	if (!sticky && bitnset(to->to_code, StickyTimeoutOpt))
4229 	{
4230 		if (tTd(37, 2))
4231 			sm_dprintf(" (ignored)\n");
4232 		return;
4233 	}
4234 
4235 	if (tTd(37, 2))
4236 		sm_dprintf("\n");
4237 
4238 	toval = convtime(val, 'm');
4239 	addopts = 0;
4240 
4241 	switch (to->to_code)
4242 	{
4243 	  case TO_INITIAL:
4244 		TimeOuts.to_initial = toval;
4245 		break;
4246 
4247 	  case TO_MAIL:
4248 		TimeOuts.to_mail = toval;
4249 		break;
4250 
4251 	  case TO_RCPT:
4252 		TimeOuts.to_rcpt = toval;
4253 		break;
4254 
4255 	  case TO_DATAINIT:
4256 		TimeOuts.to_datainit = toval;
4257 		break;
4258 
4259 	  case TO_DATABLOCK:
4260 		TimeOuts.to_datablock = toval;
4261 		break;
4262 
4263 	  case TO_DATAFINAL:
4264 		TimeOuts.to_datafinal = toval;
4265 		break;
4266 
4267 	  case TO_COMMAND:
4268 		TimeOuts.to_nextcommand = toval;
4269 		break;
4270 
4271 	  case TO_RSET:
4272 		TimeOuts.to_rset = toval;
4273 		break;
4274 
4275 	  case TO_HELO:
4276 		TimeOuts.to_helo = toval;
4277 		break;
4278 
4279 	  case TO_QUIT:
4280 		TimeOuts.to_quit = toval;
4281 		break;
4282 
4283 	  case TO_MISC:
4284 		TimeOuts.to_miscshort = toval;
4285 		break;
4286 
4287 	  case TO_IDENT:
4288 		TimeOuts.to_ident = toval;
4289 		break;
4290 
4291 	  case TO_FILEOPEN:
4292 		TimeOuts.to_fileopen = toval;
4293 		break;
4294 
4295 	  case TO_CONNECT:
4296 		TimeOuts.to_connect = toval;
4297 		break;
4298 
4299 	  case TO_ICONNECT:
4300 		TimeOuts.to_iconnect = toval;
4301 		break;
4302 
4303 	  case TO_ACONNECT:
4304 		TimeOuts.to_aconnect = toval;
4305 		break;
4306 
4307 	  case TO_QUEUEWARN:
4308 		toval = convtime(val, 'h');
4309 		TimeOuts.to_q_warning[TOC_NORMAL] = toval;
4310 		TimeOuts.to_q_warning[TOC_URGENT] = toval;
4311 		TimeOuts.to_q_warning[TOC_NONURGENT] = toval;
4312 		TimeOuts.to_q_warning[TOC_DSN] = toval;
4313 		addopts = 2;
4314 		break;
4315 
4316 	  case TO_QUEUEWARN_NORMAL:
4317 		toval = convtime(val, 'h');
4318 		TimeOuts.to_q_warning[TOC_NORMAL] = toval;
4319 		break;
4320 
4321 	  case TO_QUEUEWARN_URGENT:
4322 		toval = convtime(val, 'h');
4323 		TimeOuts.to_q_warning[TOC_URGENT] = toval;
4324 		break;
4325 
4326 	  case TO_QUEUEWARN_NON_URGENT:
4327 		toval = convtime(val, 'h');
4328 		TimeOuts.to_q_warning[TOC_NONURGENT] = toval;
4329 		break;
4330 
4331 	  case TO_QUEUEWARN_DSN:
4332 		toval = convtime(val, 'h');
4333 		TimeOuts.to_q_warning[TOC_DSN] = toval;
4334 		break;
4335 
4336 	  case TO_QUEUERETURN:
4337 		toval = convtime(val, 'd');
4338 		TimeOuts.to_q_return[TOC_NORMAL] = toval;
4339 		TimeOuts.to_q_return[TOC_URGENT] = toval;
4340 		TimeOuts.to_q_return[TOC_NONURGENT] = toval;
4341 		TimeOuts.to_q_return[TOC_DSN] = toval;
4342 		addopts = 2;
4343 		break;
4344 
4345 	  case TO_QUEUERETURN_NORMAL:
4346 		toval = convtime(val, 'd');
4347 		TimeOuts.to_q_return[TOC_NORMAL] = toval;
4348 		break;
4349 
4350 	  case TO_QUEUERETURN_URGENT:
4351 		toval = convtime(val, 'd');
4352 		TimeOuts.to_q_return[TOC_URGENT] = toval;
4353 		break;
4354 
4355 	  case TO_QUEUERETURN_NON_URGENT:
4356 		toval = convtime(val, 'd');
4357 		TimeOuts.to_q_return[TOC_NONURGENT] = toval;
4358 		break;
4359 
4360 	  case TO_QUEUERETURN_DSN:
4361 		toval = convtime(val, 'd');
4362 		TimeOuts.to_q_return[TOC_DSN] = toval;
4363 		break;
4364 
4365 	  case TO_HOSTSTATUS:
4366 		MciInfoTimeout = toval;
4367 		break;
4368 
4369 	  case TO_RESOLVER_RETRANS:
4370 		toval = convtime(val, 's');
4371 		TimeOuts.res_retrans[RES_TO_DEFAULT] = toval;
4372 		TimeOuts.res_retrans[RES_TO_FIRST] = toval;
4373 		TimeOuts.res_retrans[RES_TO_NORMAL] = toval;
4374 		addopts = 2;
4375 		break;
4376 
4377 	  case TO_RESOLVER_RETRY:
4378 		i = atoi(val);
4379 		TimeOuts.res_retry[RES_TO_DEFAULT] = i;
4380 		TimeOuts.res_retry[RES_TO_FIRST] = i;
4381 		TimeOuts.res_retry[RES_TO_NORMAL] = i;
4382 		addopts = 2;
4383 		break;
4384 
4385 	  case TO_RESOLVER_RETRANS_NORMAL:
4386 		TimeOuts.res_retrans[RES_TO_NORMAL] = convtime(val, 's');
4387 		break;
4388 
4389 	  case TO_RESOLVER_RETRY_NORMAL:
4390 		TimeOuts.res_retry[RES_TO_NORMAL] = atoi(val);
4391 		break;
4392 
4393 	  case TO_RESOLVER_RETRANS_FIRST:
4394 		TimeOuts.res_retrans[RES_TO_FIRST] = convtime(val, 's');
4395 		break;
4396 
4397 	  case TO_RESOLVER_RETRY_FIRST:
4398 		TimeOuts.res_retry[RES_TO_FIRST] = atoi(val);
4399 		break;
4400 
4401 	  case TO_CONTROL:
4402 		TimeOuts.to_control = toval;
4403 		break;
4404 
4405 	  case TO_LHLO:
4406 		TimeOuts.to_lhlo = toval;
4407 		break;
4408 
4409 #if SASL
4410 	  case TO_AUTH:
4411 		TimeOuts.to_auth = toval;
4412 		break;
4413 #endif /* SASL */
4414 
4415 #if STARTTLS
4416 	  case TO_STARTTLS:
4417 		TimeOuts.to_starttls = toval;
4418 		break;
4419 #endif /* STARTTLS */
4420 
4421 	  default:
4422 		syserr("settimeout: invalid timeout %s", name);
4423 		break;
4424 	}
4425 
4426 	if (sticky)
4427 	{
4428 		for (i = 0; i <= addopts; i++)
4429 			setbitn(to->to_code + i, StickyTimeoutOpt);
4430 	}
4431 }
4432 /*
4433 **  INITTIMEOUTS -- parse and set timeout values
4434 **
4435 **	Parameters:
4436 **		val -- a pointer to the values.  If NULL, do initial
4437 **			settings.
4438 **		sticky -- if set, don't let other setoptions override
4439 **			this suboption value.
4440 **
4441 **	Returns:
4442 **		none.
4443 **
4444 **	Side Effects:
4445 **		Initializes the TimeOuts structure
4446 */
4447 
4448 void
4449 inittimeouts(val, sticky)
4450 	register char *val;
4451 	bool sticky;
4452 {
4453 	register char *p;
4454 
4455 	if (tTd(37, 2))
4456 		sm_dprintf("inittimeouts(%s)\n", val == NULL ? "<NULL>" : val);
4457 	if (val == NULL)
4458 	{
4459 		TimeOuts.to_connect = (time_t) 0 SECONDS;
4460 		TimeOuts.to_aconnect = (time_t) 0 SECONDS;
4461 		TimeOuts.to_iconnect = (time_t) 0 SECONDS;
4462 		TimeOuts.to_initial = (time_t) 5 MINUTES;
4463 		TimeOuts.to_helo = (time_t) 5 MINUTES;
4464 		TimeOuts.to_mail = (time_t) 10 MINUTES;
4465 		TimeOuts.to_rcpt = (time_t) 1 HOUR;
4466 		TimeOuts.to_datainit = (time_t) 5 MINUTES;
4467 		TimeOuts.to_datablock = (time_t) 1 HOUR;
4468 		TimeOuts.to_datafinal = (time_t) 1 HOUR;
4469 		TimeOuts.to_rset = (time_t) 5 MINUTES;
4470 		TimeOuts.to_quit = (time_t) 2 MINUTES;
4471 		TimeOuts.to_nextcommand = (time_t) 1 HOUR;
4472 		TimeOuts.to_miscshort = (time_t) 2 MINUTES;
4473 #if IDENTPROTO
4474 		TimeOuts.to_ident = (time_t) 5 SECONDS;
4475 #else /* IDENTPROTO */
4476 		TimeOuts.to_ident = (time_t) 0 SECONDS;
4477 #endif /* IDENTPROTO */
4478 		TimeOuts.to_fileopen = (time_t) 60 SECONDS;
4479 		TimeOuts.to_control = (time_t) 2 MINUTES;
4480 		TimeOuts.to_lhlo = (time_t) 2 MINUTES;
4481 #if SASL
4482 		TimeOuts.to_auth = (time_t) 10 MINUTES;
4483 #endif /* SASL */
4484 #if STARTTLS
4485 		TimeOuts.to_starttls = (time_t) 1 HOUR;
4486 #endif /* STARTTLS */
4487 		if (tTd(37, 5))
4488 		{
4489 			sm_dprintf("Timeouts:\n");
4490 			sm_dprintf("  connect = %ld\n",
4491 				   (long) TimeOuts.to_connect);
4492 			sm_dprintf("  aconnect = %ld\n",
4493 				   (long) TimeOuts.to_aconnect);
4494 			sm_dprintf("  initial = %ld\n",
4495 				   (long) TimeOuts.to_initial);
4496 			sm_dprintf("  helo = %ld\n", (long) TimeOuts.to_helo);
4497 			sm_dprintf("  mail = %ld\n", (long) TimeOuts.to_mail);
4498 			sm_dprintf("  rcpt = %ld\n", (long) TimeOuts.to_rcpt);
4499 			sm_dprintf("  datainit = %ld\n",
4500 				   (long) TimeOuts.to_datainit);
4501 			sm_dprintf("  datablock = %ld\n",
4502 				   (long) TimeOuts.to_datablock);
4503 			sm_dprintf("  datafinal = %ld\n",
4504 				   (long) TimeOuts.to_datafinal);
4505 			sm_dprintf("  rset = %ld\n", (long) TimeOuts.to_rset);
4506 			sm_dprintf("  quit = %ld\n", (long) TimeOuts.to_quit);
4507 			sm_dprintf("  nextcommand = %ld\n",
4508 				   (long) TimeOuts.to_nextcommand);
4509 			sm_dprintf("  miscshort = %ld\n",
4510 				   (long) TimeOuts.to_miscshort);
4511 			sm_dprintf("  ident = %ld\n", (long) TimeOuts.to_ident);
4512 			sm_dprintf("  fileopen = %ld\n",
4513 				   (long) TimeOuts.to_fileopen);
4514 			sm_dprintf("  lhlo = %ld\n",
4515 				   (long) TimeOuts.to_lhlo);
4516 			sm_dprintf("  control = %ld\n",
4517 				   (long) TimeOuts.to_control);
4518 		}
4519 		return;
4520 	}
4521 
4522 	for (;; val = p)
4523 	{
4524 		while (isascii(*val) && isspace(*val))
4525 			val++;
4526 		if (*val == '\0')
4527 			break;
4528 		for (p = val; *p != '\0' && *p != ','; p++)
4529 			continue;
4530 		if (*p != '\0')
4531 			*p++ = '\0';
4532 
4533 		if (isascii(*val) && isdigit(*val))
4534 		{
4535 			/* old syntax -- set everything */
4536 			TimeOuts.to_mail = convtime(val, 'm');
4537 			TimeOuts.to_rcpt = TimeOuts.to_mail;
4538 			TimeOuts.to_datainit = TimeOuts.to_mail;
4539 			TimeOuts.to_datablock = TimeOuts.to_mail;
4540 			TimeOuts.to_datafinal = TimeOuts.to_mail;
4541 			TimeOuts.to_nextcommand = TimeOuts.to_mail;
4542 			if (sticky)
4543 			{
4544 				setbitn(TO_MAIL, StickyTimeoutOpt);
4545 				setbitn(TO_RCPT, StickyTimeoutOpt);
4546 				setbitn(TO_DATAINIT, StickyTimeoutOpt);
4547 				setbitn(TO_DATABLOCK, StickyTimeoutOpt);
4548 				setbitn(TO_DATAFINAL, StickyTimeoutOpt);
4549 				setbitn(TO_COMMAND, StickyTimeoutOpt);
4550 			}
4551 			continue;
4552 		}
4553 		else
4554 		{
4555 			register char *q = strchr(val, ':');
4556 
4557 			if (q == NULL && (q = strchr(val, '=')) == NULL)
4558 			{
4559 				/* syntax error */
4560 				continue;
4561 			}
4562 			*q++ = '\0';
4563 			settimeout(val, q, sticky);
4564 		}
4565 	}
4566 }
4567