2 * Copyright (c) 1998-2006, 2008 Sendmail, Inc. and its suppliers.
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.
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.
15 #include <sm/sendmail.h>
17 SM_RCSID("@(#)$Id: readcf.c,v 8.666 2008/02/14 17:25:14 ca Exp $")
19 #if NETINET || NETINET6
20 # include <arpa/inet.h>
21 #endif /* NETINET || NETINET6 */
28 static void fileclass __P((int, char *, char *, bool, bool, bool));
29 static char **makeargv __P((char *));
30 static void settimeout __P((char *, char *, bool));
31 static void toomany __P((int, int));
32 static char *extrquotstr __P((char *, char **, char *, bool *));
33 static void parse_class_words __P((int, char *));
36 ** READCF -- read configuration file.
38 ** This routine reads the configuration file and builds the internal
41 ** The file is formatted as a sequence of lines, each taken
42 ** atomically. The first character of each line describes how
43 ** the line is to be interpreted. The lines are:
44 ** Dxval Define macro x to have value val.
45 ** Cxword Put word into class x.
46 ** Fxfile [fmt] Read file for lines to put into
47 ** class x. Use scanf string 'fmt'
48 ** or "%s" if not present. Fmt should
49 ** only produce one string-valued result.
50 ** Hname: value Define header with field-name 'name'
51 ** and value as specified; this will be
52 ** macro expanded immediately before
54 ** Sn Use rewriting set n.
55 ** Rlhs rhs Rewrite addresses that match lhs to
57 ** Mn arg=val... Define mailer. n is the internal name.
58 ** Args specify mailer parameters.
59 ** Oxvalue Set option x to value.
60 ** O option value Set option (long name) to value.
61 ** Pname=value Set precedence name to value.
62 ** Qn arg=val... Define queue groups. n is the internal name.
63 ** Args specify queue parameters.
64 ** Vversioncode[/vendorcode]
65 ** Version level/vendor name of
66 ** configuration syntax.
67 ** Kmapname mapclass arguments....
68 ** Define keyed lookup of a given class.
69 ** Arguments are class dependent.
70 ** Eenvar=value Set the environment value to the given value.
73 ** cfname -- configuration file name.
74 ** safe -- true if this is the system config file;
76 ** e -- the main envelope.
82 ** Builds several internal tables.
86 readcf(cfname, safe, e)
94 struct rewrite *rwp = NULL;
104 long sff = SFF_OPENASROOT;
109 char pvpbuf[MAXLINE + MAXATOM];
110 static char *null_list[1] = { NULL };
111 extern unsigned char TokTypeNoC[];
116 if (DontLockReadFiles)
118 cf = safefopen(cfname, O_RDONLY, 0444, sff);
121 syserr("cannot open");
122 finis(false, true, EX_OSFILE);
125 if (fstat(sm_io_getinfo(cf, SM_IO_WHAT_FD, NULL), &statb) < 0)
127 syserr("cannot fstat");
128 finis(false, true, EX_OSFILE);
131 if (!S_ISREG(statb.st_mode))
133 syserr("not a plain file");
134 finis(false, true, EX_OSFILE);
137 if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
139 if (OpMode == MD_DAEMON || OpMode == MD_INITALIAS)
140 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
141 "%s: WARNING: dangerous write permissions\n",
144 sm_syslog(LOG_CRIT, NOQID,
145 "%s: WARNING: dangerous write permissions",
153 while (bufsize = sizeof(buf),
154 (bp = fgetfolded(buf, &bufsize, cf)) != NULL)
161 sm_free(bp); /* XXX */
165 /* do macro expansion mappings */
166 nbp = translate_dollars(bp, bp, &bufsize);
167 if (nbp != bp && bp != buf)
171 /* interpret this line */
176 case '#': /* comment */
179 case 'R': /* rewriting rule */
182 syserr("missing valid ruleset for \"%s\"", bp);
185 for (p = &bp[1]; *p != '\0' && *p != '\t'; p++)
190 syserr("invalid rewrite line \"%s\" (tab expected)", bp);
194 /* allocate space for the rule header */
197 RewriteRules[ruleset] = rwp =
198 (struct rewrite *) xalloc(sizeof(*rwp));
202 rwp->r_next = (struct rewrite *) xalloc(sizeof(*rwp));
207 /* expand and save the LHS */
209 expand(&bp[1], exbuf, sizeof(exbuf), e);
210 rwp->r_lhs = prescan(exbuf, '\t', pvpbuf,
211 sizeof(pvpbuf), NULL,
212 ConfigLevel >= 9 ? TokTypeNoC : IntTokenTab,
215 if (rwp->r_lhs != NULL)
219 rwp->r_lhs = copyplist(rwp->r_lhs, true, NULL);
221 /* count the number of fuzzy matches in LHS */
222 for (ap = rwp->r_lhs; *ap != NULL; ap++)
227 switch (ap[0][0] & 0377)
274 syserr("Inappropriate use of %s on LHS",
277 rwp->r_line = LineNumber;
281 syserr("R line: null LHS");
282 rwp->r_lhs = null_list;
284 if (nfuzzy > MAXMATCH)
286 syserr("R line: too many wildcards");
287 rwp->r_lhs = null_list;
290 /* expand and save the RHS */
294 while (*p != '\0' && *p != '\t')
297 expand(q, exbuf, sizeof(exbuf), e);
298 rwp->r_rhs = prescan(exbuf, '\t', pvpbuf,
299 sizeof(pvpbuf), NULL,
300 ConfigLevel >= 9 ? TokTypeNoC : IntTokenTab,
302 if (rwp->r_rhs != NULL)
306 #if _FFR_EXTRA_MAP_CHECK
308 #endif /* _FFR_EXTRA_MAP_CHECK */
311 rwp->r_rhs = copyplist(rwp->r_rhs, true, NULL);
313 /* check no out-of-bounds replacements */
318 for (ap = rwp->r_rhs; *ap != NULL; ap++)
323 switch (ap[0][0] & 0377)
326 if (ap[0][1] <= '0' ||
329 syserr("replacement $%c out of bounds",
357 if (++args >= MAX_MAP_ARGS)
358 syserr("too many arguments for map lookup");
366 if ((ap[0][0] & 0377) == LOOKUPBEGIN)
367 endtoken = LOOKUPEND;
369 syserr("cannot nest map lookups");
372 #if _FFR_EXTRA_MAP_CHECK
375 syserr("syntax error in map lookup");
378 nexttoken = ap[1][0] & 0377;
379 if (nexttoken == CANONHOST ||
380 nexttoken == CANONUSER ||
381 nexttoken == endtoken))
383 syserr("missing map name for lookup");
388 syserr("syntax error in map lookup");
391 if (ap[0][0] == HOSTBEGIN)
393 nexttoken = ap[2][0] & 0377;
394 if (nexttoken == CANONHOST ||
395 nexttoken == CANONUSER ||
396 nexttoken == endtoken)
398 syserr("missing key name for lookup");
401 #endif /* _FFR_EXTRA_MAP_CHECK */
406 if ((ap[0][0] & 0377) != endtoken)
415 ** This doesn't work yet as there are maps defined *after* the cf
416 ** is read such as host, user, and alias. So for now, it's removed.
417 ** When it comes back, the RELEASE_NOTES entry will be:
418 ** Emit warnings for unknown maps when reading the .cf file. Based on
419 ** patch from Robert Harker of Harker Systems.
424 ** Got a database lookup,
425 ** check if map is defined.
429 if ((ep[0] & 0377) != MACRODEXPAND &&
430 stab(ep, ST_MAP, ST_FIND) == NULL)
432 (void) sm_io_fprintf(smioout,
434 "Warning: %s: line %d: map %s not found\n",
443 syserr("Inappropriate use of %s on RHS",
447 syserr("missing map closing token");
451 syserr("R line: null RHS");
452 rwp->r_rhs = null_list;
456 case 'S': /* select rewriting set */
457 expand(&bp[1], exbuf, sizeof(exbuf), e);
458 ruleset = strtorwset(exbuf, NULL, ST_ENTER);
462 rwp = RewriteRules[ruleset];
465 if (OpMode == MD_TEST)
466 (void) sm_io_fprintf(smioout,
468 "WARNING: Ruleset %s has multiple definitions\n",
471 sm_dprintf("WARNING: Ruleset %s has multiple definitions\n",
473 while (rwp->r_next != NULL)
478 case 'D': /* macro definition */
479 mid = macid_parse(&bp[1], &ep);
482 p = munchstring(ep, NULL, '\0');
483 macdefine(&e->e_macro, A_TEMP, mid, p);
486 case 'H': /* required header line */
487 (void) chompheader(&bp[1], CHHDR_DEF, NULL, e);
490 case 'C': /* word class */
491 case 'T': /* trusted user (set class `t') */
494 mid = macid_parse(&bp[1], &ep);
497 expand(ep, exbuf, sizeof(exbuf), e);
510 while (*p != '\0' && isascii(*p) && isspace(*p))
513 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
523 case 'F': /* word class from file */
524 mid = macid_parse(&bp[1], &ep);
527 for (p = ep; isascii(*p) && isspace(*p); )
529 if (p[0] == '-' && p[1] == 'o')
533 !(isascii(*p) && isspace(*p)))
535 while (isascii(*p) && isspace(*p))
542 /* check if [key]@map:spec */
544 if (!SM_IS_DIR_DELIM(*p) &&
546 (q = strchr(p, '@')) != NULL)
550 /* look for @LDAP or @map: in string */
551 if (strcmp(q, "LDAP") == 0 ||
553 strchr(q, ':') != NULL))
559 /* use entire spec */
564 file = extrquotstr(p, &q, " ", &ok);
567 syserr("illegal filename '%s'", p);
572 if (*file == '|' || ismap)
582 while (isascii(*++p) && isspace(*p))
586 fileclass(mid, file, p, ismap, safe, optional);
590 case 'L': /* extended load average description */
595 #if defined(SUN_EXTENSIONS) && defined(SUN_LOOKUP_MACRO)
596 case 'L': /* lookup macro */
597 case 'G': /* lookup class */
598 /* reserved for Sun -- NIS+ database lookup */
599 if (VendorCode != VENDOR_SUN)
601 sun_lg_config_line(bp, e);
603 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_LOOKUP_MACRO) */
605 case 'M': /* define mailer */
609 case 'O': /* set option */
610 setoption(bp[1], &bp[2], safe, false, e);
613 case 'P': /* set precedence */
614 if (NumPriorities >= MAXPRIORITIES)
616 toomany('P', MAXPRIORITIES);
619 for (p = &bp[1]; *p != '\0' && *p != '='; p++)
624 Priorities[NumPriorities].pri_name = newstr(&bp[1]);
625 Priorities[NumPriorities].pri_val = atoi(++p);
629 case 'Q': /* define queue */
630 makequeue(&bp[1], true);
633 case 'V': /* configuration syntax version */
634 for (p = &bp[1]; isascii(*p) && isspace(*p); p++)
636 if (!isascii(*p) || !isdigit(*p))
638 syserr("invalid argument to V line: \"%.20s\"",
642 ConfigLevel = strtol(p, &ep, 10);
645 ** Do heuristic tweaking for back compatibility.
648 if (ConfigLevel >= 5)
650 /* level 5 configs have short name in $w */
651 p = macvalue('w', e);
652 if (p != NULL && (p = strchr(p, '.')) != NULL)
655 macdefine(&e->e_macro, A_TEMP, 'w',
659 if (ConfigLevel >= 6)
661 ColonOkInAddr = false;
665 ** Look for vendor code.
670 /* extract vendor code */
671 for (p = ep; isascii(*p) && isalpha(*p); )
676 syserr("invalid V line vendor code: \"%s\"",
682 expand(&bp[1], exbuf, sizeof(exbuf), e);
683 (void) makemapentry(exbuf);
690 sm_setuserenv(&bp[1], p);
693 case 'X': /* mail filter */
695 milter_setup(&bp[1]);
697 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
698 "Warning: Filter usage ('X') requires Milter support (-DMILTER)\n");
704 syserr("unknown configuration line \"%s\"", bp);
707 sm_free(bp); /* XXX */
711 syserr("I/O read error");
712 finis(false, true, EX_OSFILE);
714 (void) sm_io_close(cf, SM_TIME_DEFAULT);
717 /* initialize host maps from local service tables */
720 /* initialize daemon (if not defined yet) */
723 /* determine if we need to do special name-server frotz */
726 char *maptype[MAXMAPSTACK];
727 short mapreturn[MAXMAPACTIONS];
729 nmaps = switch_map_find("hosts", maptype, mapreturn);
730 UseNameServer = false;
731 if (nmaps > 0 && nmaps <= MAXMAPSTACK)
735 for (mapno = 0; mapno < nmaps && !UseNameServer;
738 if (strcmp(maptype[mapno], "dns") == 0)
739 UseNameServer = true;
746 ** TRANSLATE_DOLLARS -- convert $x into internal form
748 ** Actually does all appropriate pre-processing of a config line
749 ** to turn it into internal form.
752 ** ibp -- the buffer to translate.
753 ** obp -- where to put the translation; may be the same as obp
754 ** bsp -- a pointer to the size of obp; will be updated if
755 ** the buffer needs to be replaced.
758 ** The buffer pointer; may differ from obp if the expansion
759 ** is larger then *bsp, in which case this will point to
760 ** malloc()ed memory which must be free()d by the caller.
764 translate_dollars(ibp, obp, bsp)
775 sm_dprintf("translate_dollars(");
776 xputs(sm_debug_file(), ibp);
780 bp = quote_internal_chars(ibp, obp, bsp);
782 for (p = bp; *p != '\0'; p++)
784 if (*p == '#' && p > bp && ConfigLevel >= 3)
791 /* it's from $# -- let it go through */
796 /* it's backslash escaped */
797 (void) sm_strlcpy(p, p + 1, strlen(p));
801 /* delete leading white space */
802 while (isascii(*p) && isspace(*p) &&
803 *p != '\n' && p > bp)
807 if ((e = strchr(++p, '\n')) != NULL)
808 (void) sm_strlcpy(p, e, strlen(p));
816 if (*p != '$' || p[1] == '\0')
821 /* actual dollar sign.... */
822 (void) sm_strlcpy(p, p + 1, strlen(p));
826 /* convert to macro expansion character */
829 /* special handling for $=, $~, $&, and $? */
830 if (*p == '=' || *p == '~' || *p == '&' || *p == '?')
833 /* convert macro name to code */
834 *p = macid_parse(p, &ep);
836 (void) sm_strlcpy(p + 1, ep, strlen(p + 1));
839 /* strip trailing white space from the line */
840 while (--p > bp && isascii(*p) && isspace(*p))
845 sm_dprintf(" translate_dollars => ");
846 xputs(sm_debug_file(), bp);
853 ** TOOMANY -- signal too many of some option
856 ** id -- the id of the error line
857 ** maxcnt -- the maximum possible values
871 syserr("too many %c lines, %d max", id, maxcnt);
874 ** FILECLASS -- read members of a class from a file
877 ** class -- class to define.
878 ** filename -- name of file to read.
879 ** fmt -- scanf string to use for match.
880 ** ismap -- if set, this is a map lookup.
881 ** safe -- if set, this is a safe read.
882 ** optional -- if set, it is not an error for the file to
889 ** puts all lines in filename that match a scanf into
894 ** Break up the match into words and add to class.
898 parse_class_words(class, line)
902 while (line != NULL && *line != '\0')
906 /* strip leading spaces */
907 while (isascii(*line) && isspace(*line))
912 /* find the end of the word */
914 while (*line != '\0' && !(isascii(*line) && isspace(*line)))
919 /* enter the word in the symbol table */
925 fileclass(class, filename, fmt, ismap, safe, optional)
940 sm_dprintf("fileclass(%s, fmt=%s)\n", filename, fmt);
942 if (*filename == '\0')
944 syserr("fileclass: missing file name");
956 mn = newstr(macname(class));
961 if ((p = strchr(filename, '@')) == NULL)
963 /* should not happen */
964 syserr("fileclass: bogus map specification");
974 if (strcmp(cl, "LDAP") == 0)
978 char jbuf[MAXHOSTNAMELEN];
982 expand("\201j", jbuf, sizeof(jbuf), &BlankEnvelope);
985 (void) sm_strlcpy(jbuf, "localhost",
989 /* impose the default schema */
990 lc = macvalue(macid("{sendmailMTACluster}"), CurEnv);
995 expand(lc, lcbuf, sizeof(lcbuf), CurEnv);
1000 n = sm_snprintf(buf, sizeof(buf),
1001 "-k (&(objectClass=sendmailMTAClass)(sendmailMTAClassName=%s)(|(sendmailMTACluster=%s)(sendmailMTAHost=%s))) -v sendmailMTAClassValue,sendmailMTAClassSearch:FILTER:sendmailMTAClass,sendmailMTAClassURL:URL:sendmailMTAClass",
1003 if (n >= sizeof(buf))
1005 syserr("fileclass: F{%s}: Default LDAP string too long",
1013 #endif /* LDAPMAP */
1015 if ((spec = strchr(cl, ':')) == NULL)
1017 syserr("fileclass: F{%s}: missing map class",
1025 /* set up map structure */
1026 mapclass = stab(cl, ST_MAPCLASS, ST_FIND);
1027 if (mapclass == NULL)
1029 syserr("fileclass: F{%s}: class %s not available",
1034 memset(&map, '\0', sizeof(map));
1035 map.map_class = &mapclass->s_mapclass;
1037 map.map_mflags |= MF_FILECLASS;
1040 sm_dprintf("fileclass: F{%s}: map class %s, key %s, spec %s\n",
1044 /* parse map spec */
1045 if (!map.map_class->map_parse(&map, spec))
1047 /* map_parse() showed the error already */
1051 map.map_mflags |= MF_VALID;
1054 if (map.map_class->map_open(&map, O_RDONLY))
1056 map.map_mflags |= MF_OPEN;
1057 map.map_pid = getpid();
1062 !bitset(MF_OPTIONAL, map.map_mflags))
1063 syserr("fileclass: F{%s}: map open failed",
1070 p = (*map.map_class->map_lookup)(&map, key, NULL, &status);
1071 if (status != EX_OK && status != EX_NOTFOUND)
1074 syserr("fileclass: F{%s}: map lookup failed",
1079 /* use the results */
1081 parse_class_words(class, p);
1084 map.map_mflags |= MF_CLOSING;
1085 map.map_class->map_close(&map);
1086 map.map_mflags &= ~(MF_OPEN|MF_WRITABLE|MF_CLOSING);
1090 else if (filename[0] == '|')
1094 char *argv[MAXPV + 1];
1097 for (p = strtok(&filename[1], " \t");
1098 p != NULL && i < MAXPV;
1099 p = strtok(NULL, " \t"))
1102 pid = prog_open(argv, &fd, CurEnv);
1106 f = sm_io_open(SmFtStdiofd, SM_TIME_DEFAULT,
1107 (void *) &fd, SM_IO_RDONLY, NULL);
1113 if (!bitnset(DBS_CLASSFILEINUNSAFEDIRPATH, DontBlameSendmail))
1114 sff |= SFF_SAFEDIRPATH;
1115 if (!bitnset(DBS_LINKEDCLASSFILEINWRITABLEDIR,
1119 sff |= SFF_OPENASROOT;
1120 else if (RealUid == 0)
1122 if (DontLockReadFiles)
1124 f = safefopen(filename, O_RDONLY, 0, sff);
1129 syserr("fileclass: cannot open '%s'", filename);
1133 while (sm_io_fgets(f, SM_TIME_DEFAULT, buf, sizeof(buf)) != NULL)
1136 char wordbuf[MAXLINE + 1];
1142 if (sm_io_sscanf(buf, fmt, wordbuf) != 1)
1149 parse_class_words(class, p);
1152 ** If anything else is added here,
1153 ** check if the '@' map case above
1154 ** needs the code as well.
1158 (void) sm_io_close(f, SM_TIME_DEFAULT);
1160 (void) waitfor(pid);
1163 ** MAKEMAILER -- define a new mailer.
1166 ** line -- description of mailer. This is in labeled
1167 ** fields. The fields are:
1168 ** A -- the argv for this mailer
1169 ** C -- the character set for MIME conversions
1170 ** D -- the directory to run in
1171 ** E -- the eol string
1172 ** F -- the flags associated with the mailer
1173 ** L -- the maximum line length
1174 ** M -- the maximum message size
1175 ** N -- the niceness at which to run
1176 ** P -- the path to the mailer
1177 ** Q -- the queue group for the mailer
1178 ** R -- the recipient rewriting set
1179 ** S -- the sender rewriting set
1180 ** T -- the mailer type (for DSNs)
1181 ** U -- the uid to run as
1182 ** W -- the time to wait at the end
1183 ** m -- maximum messages per connection
1184 ** r -- maximum number of recipients per message
1185 ** / -- new root directory
1186 ** The first word is the canonical name of the mailer.
1192 ** enters the mailer into the mailer table.
1200 register struct mailer *m;
1205 static int nextmailer = 0; /* "free" index into Mailer struct */
1207 /* allocate a mailer and set up defaults */
1208 m = (struct mailer *) xalloc(sizeof(*m));
1209 memset((char *) m, '\0', sizeof(*m));
1210 errno = 0; /* avoid bogus error text */
1212 /* collect the mailer name */
1214 *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p));
1219 if (line[0] == '\0')
1221 syserr("name required for mailer");
1224 m->m_name = newstr(line);
1229 /* now scan through and assign info from the fields */
1232 auto char *delimptr;
1234 while (*p != '\0' &&
1235 (*p == ',' || (isascii(*p) && isspace(*p))))
1238 /* p now points to field code */
1240 while (*p != '\0' && *p != '=' && *p != ',')
1244 syserr("mailer %s: `=' expected", m->m_name);
1247 while (isascii(*p) && isspace(*p))
1250 /* p now points to the field body */
1251 p = munchstring(p, &delimptr, ',');
1253 /* install the field into the mailer struct */
1256 case 'P': /* pathname */
1257 if (*p != '\0') /* error is issued below */
1258 m->m_mailer = newstr(p);
1261 case 'F': /* flags */
1262 for (; *p != '\0'; p++)
1264 if (!(isascii(*p) && isspace(*p)))
1266 #if _FFR_DEPRECATE_MAILER_FLAG_I
1267 if (*p == M_INTERNAL)
1268 sm_syslog(LOG_WARNING, NOQID,
1269 "WARNING: mailer=%s, flag=%c deprecated",
1271 #endif /* _FFR_DEPRECATE_MAILER_FLAG_I */
1272 setbitn(bitidx(*p), m->m_flags);
1277 case 'S': /* sender rewriting ruleset */
1278 case 'R': /* recipient rewriting ruleset */
1279 i = strtorwset(p, &endp, ST_ENTER);
1283 m->m_sh_rwset = m->m_se_rwset = i;
1285 m->m_rh_rwset = m->m_re_rwset = i;
1290 i = strtorwset(p, NULL, ST_ENTER);
1300 case 'E': /* end of line string */
1302 syserr("mailer %s: null end-of-line string",
1305 m->m_eol = newstr(p);
1308 case 'A': /* argument vector */
1309 if (*p != '\0') /* error is issued below */
1310 m->m_argv = makeargv(p);
1313 case 'M': /* maximum message size */
1314 m->m_maxsize = atol(p);
1317 case 'm': /* maximum messages per connection */
1318 m->m_maxdeliveries = atoi(p);
1321 case 'r': /* max recipient per envelope */
1322 m->m_maxrcpt = atoi(p);
1325 case 'L': /* maximum line length */
1326 m->m_linelimit = atoi(p);
1327 if (m->m_linelimit < 0)
1331 case 'N': /* run niceness */
1332 m->m_nice = atoi(p);
1335 case 'D': /* working directory */
1337 syserr("mailer %s: null working directory",
1340 m->m_execdir = newstr(p);
1343 case 'C': /* default charset */
1345 syserr("mailer %s: null charset", m->m_name);
1347 m->m_defcharset = newstr(p);
1350 case 'Q': /* queue for this mailer */
1353 syserr("mailer %s: null queue", m->m_name);
1356 s = stab(p, ST_QUEUE, ST_FIND);
1358 syserr("mailer %s: unknown queue %s",
1361 m->m_qgrp = s->s_quegrp->qg_index;
1364 case 'T': /* MTA-Name/Address/Diagnostic types */
1365 /* extract MTA name type; default to "dns" */
1366 m->m_mtatype = newstr(p);
1367 p = strchr(m->m_mtatype, '/');
1374 if (*m->m_mtatype == '\0')
1375 m->m_mtatype = "dns";
1377 /* extract address type; default to "rfc822" */
1387 if (m->m_addrtype == NULL || *m->m_addrtype == '\0')
1388 m->m_addrtype = "rfc822";
1390 /* extract diagnostic type; default to "smtp" */
1392 if (m->m_diagtype == NULL || *m->m_diagtype == '\0')
1393 m->m_diagtype = "smtp";
1396 case 'U': /* user id */
1397 if (isascii(*p) && !isdigit(*p))
1402 while (*p != '\0' && isascii(*p) &&
1403 (isalnum(*p) || strchr("-_", *p) != NULL))
1405 while (isascii(*p) && isspace(*p))
1411 syserr("mailer %s: null user name",
1415 pw = sm_getpwnam(q);
1418 syserr("readcf: mailer U= flag: unknown user %s", q);
1423 m->m_uid = pw->pw_uid;
1424 m->m_gid = pw->pw_gid;
1431 m->m_uid = strtol(p, &q, 0);
1433 while (isascii(*p) && isspace(*p))
1438 while (isascii(*p) && isspace(*p))
1442 if (isascii(*p) && !isdigit(*p))
1447 while (isascii(*p) && isalnum(*p))
1452 syserr("mailer %s: null group name",
1459 syserr("readcf: mailer U= flag: unknown group %s", q);
1463 m->m_gid = gr->gr_gid;
1467 m->m_gid = strtol(p, NULL, 0);
1471 case 'W': /* wait timeout */
1472 m->m_wait = convtime(p, 's');
1475 case '/': /* new root directory */
1477 syserr("mailer %s: null root directory",
1480 m->m_rootdir = newstr(p);
1484 syserr("M%s: unknown mailer equate %c=",
1493 if (bitnset(M_SECURE_PORT, m->m_flags))
1495 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1496 "M%s: Warning: F=%c set on system that doesn't support rresvport()\n",
1497 m->m_name, M_SECURE_PORT);
1499 #endif /* !HASRRESVPORT */
1504 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1505 "M%s: Warning: N= set on system that doesn't support nice()\n",
1508 #endif /* !HASNICE */
1510 /* do some rationality checking */
1511 if (m->m_argv == NULL)
1513 syserr("M%s: A= argument required", m->m_name);
1516 if (m->m_mailer == NULL)
1518 syserr("M%s: P= argument required", m->m_name);
1522 if (nextmailer >= MAXMAILERS)
1524 syserr("too many mailers defined (%d max)", MAXMAILERS);
1528 if (m->m_maxrcpt <= 0)
1529 m->m_maxrcpt = DEFAULT_MAX_RCPT;
1531 /* do some heuristic cleanup for back compatibility */
1532 if (bitnset(M_LIMITS, m->m_flags))
1534 if (m->m_linelimit == 0)
1535 m->m_linelimit = SMTPLINELIM;
1536 if (ConfigLevel < 2)
1537 setbitn(M_7BITS, m->m_flags);
1540 if (strcmp(m->m_mailer, "[TCP]") == 0)
1542 syserr("M%s: P=[TCP] must be replaced by P=[IPC]", m->m_name);
1546 if (strcmp(m->m_mailer, "[IPC]") == 0)
1548 /* Use the second argument for host or path to socket */
1549 if (m->m_argv[0] == NULL || m->m_argv[1] == NULL ||
1550 m->m_argv[1][0] == '\0')
1552 syserr("M%s: too few parameters for %s mailer",
1553 m->m_name, m->m_mailer);
1556 if (strcmp(m->m_argv[0], "TCP") != 0
1558 && strcmp(m->m_argv[0], "FILE") != 0
1559 #endif /* NETUNIX */
1562 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1563 "M%s: Warning: first argument in %s mailer must be %s\n",
1564 m->m_name, m->m_mailer,
1569 #endif /* NETUNIX */
1572 if (m->m_mtatype == NULL)
1573 m->m_mtatype = "dns";
1574 if (m->m_addrtype == NULL)
1575 m->m_addrtype = "rfc822";
1576 if (m->m_diagtype == NULL)
1578 if (m->m_argv[0] != NULL &&
1579 strcmp(m->m_argv[0], "FILE") == 0)
1580 m->m_diagtype = "x-unix";
1582 m->m_diagtype = "smtp";
1585 else if (strcmp(m->m_mailer, "[FILE]") == 0)
1587 /* Use the second argument for filename */
1588 if (m->m_argv[0] == NULL || m->m_argv[1] == NULL ||
1589 m->m_argv[2] != NULL)
1591 syserr("M%s: too %s parameters for [FILE] mailer",
1593 (m->m_argv[0] == NULL ||
1594 m->m_argv[1] == NULL) ? "few" : "many");
1597 else if (strcmp(m->m_argv[0], "FILE") != 0)
1599 syserr("M%s: first argument in [FILE] mailer must be FILE",
1605 if (m->m_eol == NULL)
1609 /* default for SMTP is \r\n; use \n for local delivery */
1610 for (pp = m->m_argv; *pp != NULL; pp++)
1612 for (p = *pp; *p != '\0'; )
1614 if ((*p++ & 0377) == MACROEXPAND && *p == 'u')
1626 /* enter the mailer into the symbol table */
1627 s = stab(m->m_name, ST_MAILER, ST_ENTER);
1628 if (s->s_mailer != NULL)
1630 i = s->s_mailer->m_mno;
1631 sm_free(s->s_mailer); /* XXX */
1637 Mailer[i] = s->s_mailer = m;
1641 ** MUNCHSTRING -- translate a string into internal form.
1644 ** p -- the string to munch.
1645 ** delimptr -- if non-NULL, set to the pointer of the
1646 ** field delimiter character.
1647 ** delim -- the delimiter for the field.
1650 ** the munched string.
1653 ** the munched string is a local static buffer.
1654 ** it must be copied before the function is called again.
1658 munchstring(p, delimptr, delim)
1664 bool backslash = false;
1665 bool quotemode = false;
1666 static char buf[MAXLINE];
1668 for (q = buf; *p != '\0' && q < &buf[sizeof(buf) - 1]; p++)
1672 /* everything is roughly literal */
1676 case 'r': /* carriage return */
1680 case 'n': /* newline */
1684 case 'f': /* form feed */
1688 case 'b': /* backspace */
1699 quotemode = !quotemode;
1700 else if (quotemode || *p != delim)
1707 if (delimptr != NULL)
1713 ** EXTRQUOTSTR -- extract a (quoted) string.
1715 ** This routine deals with quoted (") strings and escaped
1719 ** p -- source string.
1720 ** delimptr -- if non-NULL, set to the pointer of the
1721 ** field delimiter character.
1722 ** delimbuf -- delimiters for the field.
1723 ** st -- if non-NULL, store the return value (whether the
1724 ** string was correctly quoted) here.
1727 ** the extracted string.
1730 ** the returned string is a local static buffer.
1731 ** it must be copied before the function is called again.
1735 extrquotstr(p, delimptr, delimbuf, st)
1742 bool backslash = false;
1743 bool quotemode = false;
1744 static char buf[MAXLINE];
1746 for (q = buf; *p != '\0' && q < &buf[sizeof(buf) - 1]; p++)
1757 quotemode = !quotemode;
1758 else if (quotemode ||
1759 strchr(delimbuf, (int) *p) == NULL)
1765 if (delimptr != NULL)
1769 *st = !(quotemode || backslash);
1773 ** MAKEARGV -- break up a string into words
1776 ** p -- the string to break up.
1779 ** a char **argv (dynamically allocated)
1792 char *argv[MAXPV + 1];
1794 /* take apart the words */
1796 while (*p != '\0' && i < MAXPV)
1799 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
1801 while (isascii(*p) && isspace(*p))
1803 argv[i++] = newstr(q);
1807 /* now make a copy of the argv */
1808 avp = (char **) xalloc(sizeof(*avp) * i);
1809 memmove((char *) avp, (char *) argv, sizeof(*avp) * i);
1814 ** PRINTRULES -- print rewrite rules (for debugging)
1823 ** prints rewrite rules.
1829 register struct rewrite *rwp;
1830 register int ruleset;
1832 for (ruleset = 0; ruleset < 10; ruleset++)
1834 if (RewriteRules[ruleset] == NULL)
1836 sm_dprintf("\n----Rule Set %d:", ruleset);
1838 for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
1840 sm_dprintf("\nLHS:");
1841 printav(sm_debug_file(), rwp->r_lhs);
1843 printav(sm_debug_file(), rwp->r_rhs);
1848 ** PRINTMAILER -- print mailer structure (for debugging)
1851 ** fp -- output file
1852 ** m -- the mailer to print
1865 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT,
1866 "mailer %d (%s): P=%s S=", m->m_mno, m->m_name,
1868 if (RuleSetNames[m->m_se_rwset] == NULL)
1869 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d/",
1872 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s/",
1873 RuleSetNames[m->m_se_rwset]);
1874 if (RuleSetNames[m->m_sh_rwset] == NULL)
1875 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d R=",
1878 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s R=",
1879 RuleSetNames[m->m_sh_rwset]);
1880 if (RuleSetNames[m->m_re_rwset] == NULL)
1881 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d/",
1884 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s/",
1885 RuleSetNames[m->m_re_rwset]);
1886 if (RuleSetNames[m->m_rh_rwset] == NULL)
1887 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d ",
1890 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s ",
1891 RuleSetNames[m->m_rh_rwset]);
1892 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "M=%ld U=%d:%d F=",
1893 m->m_maxsize, (int) m->m_uid, (int) m->m_gid);
1894 for (j = '\0'; j <= '\177'; j++)
1895 if (bitnset(j, m->m_flags))
1896 (void) sm_io_putc(fp, SM_TIME_DEFAULT, j);
1897 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " L=%d E=",
1899 xputs(fp, m->m_eol);
1900 if (m->m_defcharset != NULL)
1901 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " C=%s",
1903 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " T=%s/%s/%s",
1904 m->m_mtatype == NULL
1905 ? "<undefined>" : m->m_mtatype,
1906 m->m_addrtype == NULL
1907 ? "<undefined>" : m->m_addrtype,
1908 m->m_diagtype == NULL
1909 ? "<undefined>" : m->m_diagtype);
1910 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " r=%d", m->m_maxrcpt);
1911 if (m->m_argv != NULL)
1913 char **a = m->m_argv;
1915 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " A=");
1919 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT,
1924 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "\n");
1927 ** SETOPTION -- set global processing option
1930 ** opt -- option name.
1931 ** val -- option value (as a text string).
1932 ** safe -- set if this came from a configuration file.
1933 ** Some options (if set from the command line) will
1934 ** reset the user id to avoid security problems.
1935 ** sticky -- if set, don't let other setoptions override
1937 ** e -- the main envelope.
1943 ** Sets options as implied by the arguments.
1946 static BITMAP256 StickyOpt; /* set if option is stuck */
1950 static struct resolverflags
1952 char *rf_name; /* name of the flag */
1953 long rf_bits; /* bits to set/clear */
1956 { "debug", RES_DEBUG },
1957 { "aaonly", RES_AAONLY },
1958 { "usevc", RES_USEVC },
1959 { "primary", RES_PRIMARY },
1960 { "igntc", RES_IGNTC },
1961 { "recurse", RES_RECURSE },
1962 { "defnames", RES_DEFNAMES },
1963 { "stayopen", RES_STAYOPEN },
1964 { "dnsrch", RES_DNSRCH },
1965 # ifdef RES_USE_INET6
1966 { "use_inet6", RES_USE_INET6 },
1967 # endif /* RES_USE_INET6 */
1968 { "true", 0 }, /* avoid error on old syntax */
1972 #endif /* NAMED_BIND */
1974 #define OI_NONE 0 /* no special treatment */
1975 #define OI_SAFE 0x0001 /* safe for random people to use */
1976 #define OI_SUBOPT 0x0002 /* option has suboptions */
1978 static struct optioninfo
1980 char *o_name; /* long name of option */
1981 unsigned char o_code; /* short name of option */
1982 unsigned short o_flags; /* option flags */
1985 #if defined(SUN_EXTENSIONS) && defined(REMOTE_MODE)
1986 { "RemoteMode", '>', OI_NONE },
1987 #endif /* defined(SUN_EXTENSIONS) && defined(REMOTE_MODE) */
1988 { "SevenBitInput", '7', OI_SAFE },
1989 { "EightBitMode", '8', OI_SAFE },
1990 { "AliasFile", 'A', OI_NONE },
1991 { "AliasWait", 'a', OI_NONE },
1992 { "BlankSub", 'B', OI_NONE },
1993 { "MinFreeBlocks", 'b', OI_SAFE },
1994 { "CheckpointInterval", 'C', OI_SAFE },
1995 { "HoldExpensive", 'c', OI_NONE },
1996 { "DeliveryMode", 'd', OI_SAFE },
1997 { "ErrorHeader", 'E', OI_NONE },
1998 { "ErrorMode", 'e', OI_SAFE },
1999 { "TempFileMode", 'F', OI_NONE },
2000 { "SaveFromLine", 'f', OI_NONE },
2001 { "MatchGECOS", 'G', OI_NONE },
2003 /* no long name, just here to avoid problems in setoption */
2004 { "", 'g', OI_NONE },
2005 { "HelpFile", 'H', OI_NONE },
2006 { "MaxHopCount", 'h', OI_NONE },
2007 { "ResolverOptions", 'I', OI_NONE },
2008 { "IgnoreDots", 'i', OI_SAFE },
2009 { "ForwardPath", 'J', OI_NONE },
2010 { "SendMimeErrors", 'j', OI_SAFE },
2011 { "ConnectionCacheSize", 'k', OI_NONE },
2012 { "ConnectionCacheTimeout", 'K', OI_NONE },
2013 { "UseErrorsTo", 'l', OI_NONE },
2014 { "LogLevel", 'L', OI_SAFE },
2015 { "MeToo", 'm', OI_SAFE },
2017 /* no long name, just here to avoid problems in setoption */
2018 { "", 'M', OI_NONE },
2019 { "CheckAliases", 'n', OI_NONE },
2020 { "OldStyleHeaders", 'o', OI_SAFE },
2021 { "DaemonPortOptions", 'O', OI_NONE },
2022 { "PrivacyOptions", 'p', OI_SAFE },
2023 { "PostmasterCopy", 'P', OI_NONE },
2024 { "QueueFactor", 'q', OI_NONE },
2025 { "QueueDirectory", 'Q', OI_NONE },
2026 { "DontPruneRoutes", 'R', OI_NONE },
2027 { "Timeout", 'r', OI_SUBOPT },
2028 { "StatusFile", 'S', OI_NONE },
2029 { "SuperSafe", 's', OI_SAFE },
2030 { "QueueTimeout", 'T', OI_NONE },
2031 { "TimeZoneSpec", 't', OI_NONE },
2032 { "UserDatabaseSpec", 'U', OI_NONE },
2033 { "DefaultUser", 'u', OI_NONE },
2034 { "FallbackMXhost", 'V', OI_NONE },
2035 { "Verbose", 'v', OI_SAFE },
2036 { "TryNullMXList", 'w', OI_NONE },
2037 { "QueueLA", 'x', OI_NONE },
2038 { "RefuseLA", 'X', OI_NONE },
2039 { "RecipientFactor", 'y', OI_NONE },
2040 { "ForkEachJob", 'Y', OI_NONE },
2041 { "ClassFactor", 'z', OI_NONE },
2042 { "RetryFactor", 'Z', OI_NONE },
2043 #define O_QUEUESORTORD 0x81
2044 { "QueueSortOrder", O_QUEUESORTORD, OI_SAFE },
2045 #define O_HOSTSFILE 0x82
2046 { "HostsFile", O_HOSTSFILE, OI_NONE },
2048 { "MinQueueAge", O_MQA, OI_SAFE },
2049 #define O_DEFCHARSET 0x85
2050 { "DefaultCharSet", O_DEFCHARSET, OI_SAFE },
2051 #define O_SSFILE 0x86
2052 { "ServiceSwitchFile", O_SSFILE, OI_NONE },
2053 #define O_DIALDELAY 0x87
2054 { "DialDelay", O_DIALDELAY, OI_SAFE },
2055 #define O_NORCPTACTION 0x88
2056 { "NoRecipientAction", O_NORCPTACTION, OI_SAFE },
2057 #define O_SAFEFILEENV 0x89
2058 { "SafeFileEnvironment", O_SAFEFILEENV, OI_NONE },
2059 #define O_MAXMSGSIZE 0x8a
2060 { "MaxMessageSize", O_MAXMSGSIZE, OI_NONE },
2061 #define O_COLONOKINADDR 0x8b
2062 { "ColonOkInAddr", O_COLONOKINADDR, OI_SAFE },
2063 #define O_MAXQUEUERUN 0x8c
2064 { "MaxQueueRunSize", O_MAXQUEUERUN, OI_SAFE },
2065 #define O_MAXCHILDREN 0x8d
2066 { "MaxDaemonChildren", O_MAXCHILDREN, OI_NONE },
2067 #define O_KEEPCNAMES 0x8e
2068 { "DontExpandCnames", O_KEEPCNAMES, OI_NONE },
2069 #define O_MUSTQUOTE 0x8f
2070 { "MustQuoteChars", O_MUSTQUOTE, OI_NONE },
2071 #define O_SMTPGREETING 0x90
2072 { "SmtpGreetingMessage", O_SMTPGREETING, OI_NONE },
2073 #define O_UNIXFROM 0x91
2074 { "UnixFromLine", O_UNIXFROM, OI_NONE },
2075 #define O_OPCHARS 0x92
2076 { "OperatorChars", O_OPCHARS, OI_NONE },
2077 #define O_DONTINITGRPS 0x93
2078 { "DontInitGroups", O_DONTINITGRPS, OI_NONE },
2080 { "SingleLineFromHeader", O_SLFH, OI_SAFE },
2082 { "AllowBogusHELO", O_ABH, OI_SAFE },
2083 #define O_CONNTHROT 0x97
2084 { "ConnectionRateThrottle", O_CONNTHROT, OI_NONE },
2086 { "UnsafeGroupWrites", O_UGW, OI_NONE },
2087 #define O_DBLBOUNCE 0x9a
2088 { "DoubleBounceAddress", O_DBLBOUNCE, OI_NONE },
2089 #define O_HSDIR 0x9b
2090 { "HostStatusDirectory", O_HSDIR, OI_NONE },
2091 #define O_SINGTHREAD 0x9c
2092 { "SingleThreadDelivery", O_SINGTHREAD, OI_NONE },
2093 #define O_RUNASUSER 0x9d
2094 { "RunAsUser", O_RUNASUSER, OI_NONE },
2095 #define O_DSN_RRT 0x9e
2096 { "RrtImpliesDsn", O_DSN_RRT, OI_NONE },
2097 #define O_PIDFILE 0x9f
2098 { "PidFile", O_PIDFILE, OI_NONE },
2099 #define O_DONTBLAMESENDMAIL 0xa0
2100 { "DontBlameSendmail", O_DONTBLAMESENDMAIL, OI_NONE },
2102 { "DontProbeInterfaces", O_DPI, OI_NONE },
2103 #define O_MAXRCPT 0xa2
2104 { "MaxRecipientsPerMessage", O_MAXRCPT, OI_SAFE },
2105 #define O_DEADLETTER 0xa3
2106 { "DeadLetterDrop", O_DEADLETTER, OI_NONE },
2107 #if _FFR_DONTLOCKFILESFORREAD_OPTION
2108 # define O_DONTLOCK 0xa4
2109 { "DontLockFilesForRead", O_DONTLOCK, OI_NONE },
2110 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
2111 #define O_MAXALIASRCSN 0xa5
2112 { "MaxAliasRecursion", O_MAXALIASRCSN, OI_NONE },
2113 #define O_CNCTONLYTO 0xa6
2114 { "ConnectOnlyTo", O_CNCTONLYTO, OI_NONE },
2115 #define O_TRUSTUSER 0xa7
2116 { "TrustedUser", O_TRUSTUSER, OI_NONE },
2117 #define O_MAXMIMEHDRLEN 0xa8
2118 { "MaxMimeHeaderLength", O_MAXMIMEHDRLEN, OI_NONE },
2119 #define O_CONTROLSOCKET 0xa9
2120 { "ControlSocketName", O_CONTROLSOCKET, OI_NONE },
2121 #define O_MAXHDRSLEN 0xaa
2122 { "MaxHeadersLength", O_MAXHDRSLEN, OI_NONE },
2123 #if _FFR_MAX_FORWARD_ENTRIES
2124 # define O_MAXFORWARD 0xab
2125 { "MaxForwardEntries", O_MAXFORWARD, OI_NONE },
2126 #endif /* _FFR_MAX_FORWARD_ENTRIES */
2127 #define O_PROCTITLEPREFIX 0xac
2128 { "ProcessTitlePrefix", O_PROCTITLEPREFIX, OI_NONE },
2129 #define O_SASLINFO 0xad
2130 #if _FFR_ALLOW_SASLINFO
2131 { "DefaultAuthInfo", O_SASLINFO, OI_SAFE },
2132 #else /* _FFR_ALLOW_SASLINFO */
2133 { "DefaultAuthInfo", O_SASLINFO, OI_NONE },
2134 #endif /* _FFR_ALLOW_SASLINFO */
2135 #define O_SASLMECH 0xae
2136 { "AuthMechanisms", O_SASLMECH, OI_NONE },
2137 #define O_CLIENTPORT 0xaf
2138 { "ClientPortOptions", O_CLIENTPORT, OI_NONE },
2139 #define O_DF_BUFSIZE 0xb0
2140 { "DataFileBufferSize", O_DF_BUFSIZE, OI_NONE },
2141 #define O_XF_BUFSIZE 0xb1
2142 { "XscriptFileBufferSize", O_XF_BUFSIZE, OI_NONE },
2143 #define O_LDAPDEFAULTSPEC 0xb2
2144 { "LDAPDefaultSpec", O_LDAPDEFAULTSPEC, OI_NONE },
2145 #define O_SRVCERTFILE 0xb4
2146 { "ServerCertFile", O_SRVCERTFILE, OI_NONE },
2147 #define O_SRVKEYFILE 0xb5
2148 { "ServerKeyFile", O_SRVKEYFILE, OI_NONE },
2149 #define O_CLTCERTFILE 0xb6
2150 { "ClientCertFile", O_CLTCERTFILE, OI_NONE },
2151 #define O_CLTKEYFILE 0xb7
2152 { "ClientKeyFile", O_CLTKEYFILE, OI_NONE },
2153 #define O_CACERTFILE 0xb8
2154 { "CACertFile", O_CACERTFILE, OI_NONE },
2155 #define O_CACERTPATH 0xb9
2156 { "CACertPath", O_CACERTPATH, OI_NONE },
2157 #define O_DHPARAMS 0xba
2158 { "DHParameters", O_DHPARAMS, OI_NONE },
2159 #define O_INPUTMILTER 0xbb
2160 { "InputMailFilters", O_INPUTMILTER, OI_NONE },
2161 #define O_MILTER 0xbc
2162 { "Milter", O_MILTER, OI_SUBOPT },
2163 #define O_SASLOPTS 0xbd
2164 { "AuthOptions", O_SASLOPTS, OI_NONE },
2165 #define O_QUEUE_FILE_MODE 0xbe
2166 { "QueueFileMode", O_QUEUE_FILE_MODE, OI_NONE },
2168 # define O_DHPARAMS5 0xbf
2169 { "DHParameters512", O_DHPARAMS5, OI_NONE },
2170 # define O_CIPHERLIST 0xc0
2171 { "CipherList", O_CIPHERLIST, OI_NONE },
2172 #endif /* _FFR_TLS_1 */
2173 #define O_RANDFILE 0xc1
2174 { "RandFile", O_RANDFILE, OI_NONE },
2175 #define O_TLS_SRV_OPTS 0xc2
2176 { "TLSSrvOptions", O_TLS_SRV_OPTS, OI_NONE },
2177 #define O_RCPTTHROT 0xc3
2178 { "BadRcptThrottle", O_RCPTTHROT, OI_SAFE },
2179 #define O_DLVR_MIN 0xc4
2180 { "DeliverByMin", O_DLVR_MIN, OI_NONE },
2181 #define O_MAXQUEUECHILDREN 0xc5
2182 { "MaxQueueChildren", O_MAXQUEUECHILDREN, OI_NONE },
2183 #define O_MAXRUNNERSPERQUEUE 0xc6
2184 { "MaxRunnersPerQueue", O_MAXRUNNERSPERQUEUE, OI_NONE },
2185 #define O_DIRECTSUBMODIFIERS 0xc7
2186 { "DirectSubmissionModifiers", O_DIRECTSUBMODIFIERS, OI_NONE },
2187 #define O_NICEQUEUERUN 0xc8
2188 { "NiceQueueRun", O_NICEQUEUERUN, OI_NONE },
2189 #define O_SHMKEY 0xc9
2190 { "SharedMemoryKey", O_SHMKEY, OI_NONE },
2191 #define O_SASLBITS 0xca
2192 { "AuthMaxBits", O_SASLBITS, OI_NONE },
2194 { "MailboxDatabase", O_MBDB, OI_NONE },
2196 { "UseMSP", O_MSQ, OI_NONE },
2197 #define O_DELAY_LA 0xcd
2198 { "DelayLA", O_DELAY_LA, OI_NONE },
2199 #define O_FASTSPLIT 0xce
2200 { "FastSplit", O_FASTSPLIT, OI_NONE },
2201 #define O_SOFTBOUNCE 0xcf
2202 { "SoftBounce", O_SOFTBOUNCE, OI_NONE },
2203 #define O_SHMKEYFILE 0xd0
2204 { "SharedMemoryKeyFile", O_SHMKEYFILE, OI_NONE },
2205 #define O_REJECTLOGINTERVAL 0xd1
2206 { "RejectLogInterval", O_REJECTLOGINTERVAL, OI_NONE },
2207 #define O_REQUIRES_DIR_FSYNC 0xd2
2208 { "RequiresDirfsync", O_REQUIRES_DIR_FSYNC, OI_NONE },
2209 #define O_CONNECTION_RATE_WINDOW_SIZE 0xd3
2210 { "ConnectionRateWindowSize", O_CONNECTION_RATE_WINDOW_SIZE, OI_NONE },
2211 #define O_CRLFILE 0xd4
2212 { "CRLFile", O_CRLFILE, OI_NONE },
2213 #define O_FALLBACKSMARTHOST 0xd5
2214 { "FallbackSmartHost", O_FALLBACKSMARTHOST, OI_NONE },
2215 #define O_SASLREALM 0xd6
2216 { "AuthRealm", O_SASLREALM, OI_NONE },
2218 # define O_CRLPATH 0xd7
2219 { "CRLPath", O_CRLPATH, OI_NONE },
2220 #endif /* _FFR_CRLPATH */
2221 #define O_HELONAME 0xd8
2222 { "HeloName", O_HELONAME, OI_NONE },
2224 # define O_REFUSELOWMEM 0xd9
2225 { "RefuseLowMem", O_REFUSELOWMEM, OI_NONE },
2226 # define O_QUEUELOWMEM 0xda
2227 { "QueueLowMem", O_QUEUELOWMEM, OI_NONE },
2228 # define O_MEMRESOURCE 0xdb
2229 { "MemoryResource", O_MEMRESOURCE, OI_NONE },
2230 #endif /* _FFR_MEMSTAT */
2231 #define O_MAXNOOPCOMMANDS 0xdc
2232 { "MaxNOOPCommands", O_MAXNOOPCOMMANDS, OI_NONE },
2234 # define O_MSG_ACCEPT 0xdd
2235 { "MessageAccept", O_MSG_ACCEPT, OI_NONE },
2236 #endif /* _FFR_MSG_ACCEPT */
2237 #if _FFR_QUEUE_RUN_PARANOIA
2238 # define O_CHK_Q_RUNNERS 0xde
2239 { "CheckQueueRunners", O_CHK_Q_RUNNERS, OI_NONE },
2240 #endif /* _FFR_QUEUE_RUN_PARANOIA */
2241 #if _FFR_EIGHT_BIT_ADDR_OK
2243 # ERROR FFR_EIGHT_BIT_ADDR_OK requires _ALLOW_255
2244 # endif /* !ALLOW_255 */
2245 # define O_EIGHT_BIT_ADDR_OK 0xdf
2246 { "EightBitAddrOK", O_EIGHT_BIT_ADDR_OK, OI_NONE },
2247 #endif /* _FFR_EIGHT_BIT_ADDR_OK */
2248 #if _FFR_ADDR_TYPE_MODES
2249 # define O_ADDR_TYPE_MODES 0xe0
2250 { "AddrTypeModes", O_ADDR_TYPE_MODES, OI_NONE },
2251 #endif /* _FFR_ADDR_TYPE_MODES */
2252 #if _FFR_BADRCPT_SHUTDOWN
2253 # define O_RCPTSHUTD 0xe1
2254 { "BadRcptShutdown", O_RCPTSHUTD, OI_SAFE },
2255 # define O_RCPTSHUTDG 0xe2
2256 { "BadRcptShutdownGood", O_RCPTSHUTDG, OI_SAFE },
2257 #endif /* _FFR_BADRCPT_SHUTDOWN */
2259 { NULL, '\0', OI_NONE }
2262 # define CANONIFY(val)
2264 # define SET_OPT_DEFAULT(opt, val) opt = val
2266 /* set a string option by expanding the value and assigning it */
2267 /* WARNING this belongs ONLY into a case statement! */
2268 #define SET_STRING_EXP(str) \
2269 expand(val, exbuf, sizeof(exbuf), e); \
2270 newval = sm_pstrdup_x(exbuf); \
2277 #define OPTNAME o->o_name == NULL ? "<unknown>" : o->o_name
2280 setoption(opt, val, safe, sticky, e)
2285 register ENVELOPE *e;
2288 register struct optioninfo *o;
2291 bool can_setuid = RunAsUid == 0;
2294 extern bool Warn_Q_option;
2295 #if _FFR_ALLOW_SASLINFO
2296 extern unsigned int SubmitMode;
2297 #endif /* _FFR_ALLOW_SASLINFO */
2298 #if STARTTLS || SM_CONF_SHM
2300 char exbuf[MAXLINE];
2301 #endif /* STARTTLS || SM_CONF_SHM */
2306 /* full word options */
2307 struct optioninfo *sel;
2309 p = strchr(val, '=');
2311 p = &val[strlen(val)];
2318 syserr("readcf: null option name");
2325 subopt = strchr(val, '.');
2329 for (o = OptionTab; o->o_name != NULL; o++)
2331 if (sm_strncasecmp(o->o_name, val, strlen(val)) != 0)
2333 if (strlen(o->o_name) == strlen(val))
2335 /* completely specified -- this must be it */
2343 if (sel != NULL && o->o_name == NULL)
2345 else if (o->o_name == NULL)
2347 syserr("readcf: unknown option name %s", val);
2350 else if (sel != NULL)
2352 syserr("readcf: ambiguous option name %s (matches %s and %s)",
2353 val, sel->o_name, o->o_name);
2356 if (strlen(val) != strlen(o->o_name))
2358 int oldVerbose = Verbose;
2361 message("Option %s used as abbreviation for %s",
2363 Verbose = oldVerbose;
2370 for (o = OptionTab; o->o_name != NULL; o++)
2372 if (o->o_code == opt)
2375 if (o->o_name == NULL)
2377 syserr("readcf: unknown option name 0x%x", opt & 0xff);
2383 if (subopt != NULL && !bitset(OI_SUBOPT, o->o_flags))
2386 sm_dprintf("setoption: %s does not support suboptions, ignoring .%s\n",
2393 sm_dprintf(isascii(opt) && isprint(opt) ?
2394 "setoption %s (%c)%s%s=" :
2395 "setoption %s (0x%x)%s%s=",
2396 OPTNAME, opt, subopt == NULL ? "" : ".",
2397 subopt == NULL ? "" : subopt);
2398 xputs(sm_debug_file(), val);
2402 ** See if this option is preset for us.
2405 if (!sticky && bitnset(opt, StickyOpt))
2408 sm_dprintf(" (ignored)\n");
2413 ** Check to see if this option can be specified by this user.
2416 if (!safe && RealUid == 0)
2418 if (!safe && !bitset(OI_SAFE, o->o_flags))
2420 if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
2425 sm_dprintf(" (unsafe)");
2426 dp = drop_privileges(true);
2435 case '7': /* force seven-bit input */
2436 SevenBitInput = atobool(val);
2439 case '8': /* handling of 8-bit input */
2443 case 'p': /* pass 8 bit, convert MIME */
2444 MimeMode = MM_CVTMIME|MM_PASS8BIT;
2447 case 'm': /* convert 8-bit, convert MIME */
2448 MimeMode = MM_CVTMIME|MM_MIME8BIT;
2451 case 's': /* strict adherence */
2452 MimeMode = MM_CVTMIME;
2456 case 'r': /* reject 8-bit, don't convert MIME */
2460 case 'j': /* "just send 8" */
2461 MimeMode = MM_PASS8BIT;
2464 case 'a': /* encode 8 bit if available */
2465 MimeMode = MM_MIME8BIT|MM_PASS8BIT|MM_CVTMIME;
2468 case 'c': /* convert 8 bit to MIME, never 7 bit */
2469 MimeMode = MM_MIME8BIT;
2474 syserr("Unknown 8-bit mode %c", *val);
2475 finis(false, true, EX_USAGE);
2477 #else /* MIME8TO7 */
2478 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
2479 "Warning: Option: %s requires MIME8TO7 support\n",
2481 #endif /* MIME8TO7 */
2484 case 'A': /* set default alias file */
2489 SET_OPT_DEFAULT(al, "aliases");
2496 case 'a': /* look N minutes for "@:@" in alias file */
2498 SafeAlias = 5 MINUTES;
2500 SafeAlias = convtime(val, 'm');
2503 case 'B': /* substitution for blank character */
2505 if (SpaceSub == '\0')
2509 case 'b': /* min blocks free on queue fs/max msg size */
2510 p = strchr(val, '/');
2514 MaxMessageSize = atol(p);
2516 MinBlocksFree = atol(val);
2519 case 'c': /* don't connect to "expensive" mailers */
2520 NoConnect = atobool(val);
2523 case 'C': /* checkpoint every N addresses */
2524 if (safe || CheckpointInterval > atoi(val))
2525 CheckpointInterval = atoi(val);
2528 case 'd': /* delivery mode */
2532 set_delivery_mode(SM_DELIVER, e);
2535 case SM_QUEUE: /* queue only */
2536 case SM_DEFER: /* queue only and defer map lookups */
2537 case SM_DELIVER: /* do everything */
2538 case SM_FORK: /* fork after verification */
2540 /* deliver first TA in background, then queue */
2542 #endif /* _FFR_DM_ONE */
2543 set_delivery_mode(*val, e);
2547 syserr("Unknown delivery mode %c", *val);
2548 finis(false, true, EX_USAGE);
2552 case 'E': /* error message header/header file */
2554 ErrMsgFile = newstr(val);
2557 case 'e': /* set error processing mode */
2560 case EM_QUIET: /* be silent about it */
2561 case EM_MAIL: /* mail back */
2562 case EM_BERKNET: /* do berknet error processing */
2563 case EM_WRITE: /* write back (or mail) */
2564 case EM_PRINT: /* print errors normally (default) */
2565 e->e_errormode = *val;
2570 case 'F': /* file mode */
2571 FileMode = atooct(val) & 0777;
2574 case 'f': /* save Unix-style From lines on front */
2575 SaveFrom = atobool(val);
2578 case 'G': /* match recipients against GECOS field */
2579 MatchGecos = atobool(val);
2582 case 'g': /* default gid */
2584 if (isascii(*val) && isdigit(*val))
2588 register struct group *gr;
2593 syserr("readcf: option %c: unknown group %s",
2596 DefGid = gr->gr_gid;
2600 case 'H': /* help file */
2603 SET_OPT_DEFAULT(HelpFile, "helpfile");
2608 HelpFile = newstr(val);
2612 case 'h': /* maximum hop count */
2613 MaxHopCount = atoi(val);
2616 case 'I': /* use internet domain name server */
2618 for (p = val; *p != 0; )
2622 struct resolverflags *rfp;
2635 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
2639 if (sm_strcasecmp(q, "HasWildcardMX") == 0)
2641 HasWildcardMX = !clearmode;
2644 if (sm_strcasecmp(q, "WorkAroundBrokenAAAA") == 0)
2646 WorkAroundBrokenAAAA = !clearmode;
2649 for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
2651 if (sm_strcasecmp(q, rfp->rf_name) == 0)
2654 if (rfp->rf_name == NULL)
2655 syserr("readcf: I option value %s unrecognized", q);
2657 _res.options &= ~rfp->rf_bits;
2659 _res.options |= rfp->rf_bits;
2662 sm_dprintf("_res.options = %x, HasWildcardMX = %d\n",
2663 (unsigned int) _res.options, HasWildcardMX);
2664 #else /* NAMED_BIND */
2665 usrerr("name server (I option) specified but BIND not compiled in");
2666 #endif /* NAMED_BIND */
2669 case 'i': /* ignore dot lines in message */
2670 IgnrDot = atobool(val);
2673 case 'j': /* send errors in MIME (RFC 1341) format */
2674 SendMIMEErrors = atobool(val);
2677 case 'J': /* .forward search path */
2679 ForwardPath = newstr(val);
2682 case 'k': /* connection cache size */
2683 MaxMciCache = atoi(val);
2684 if (MaxMciCache < 0)
2688 case 'K': /* connection cache timeout */
2689 MciCacheTimeout = convtime(val, 'm');
2692 case 'l': /* use Errors-To: header */
2693 UseErrorsTo = atobool(val);
2696 case 'L': /* log level */
2697 if (safe || LogLevel < atoi(val))
2698 LogLevel = atoi(val);
2701 case 'M': /* define macro */
2703 mid = macid_parse(val, &ep);
2708 cleanstrcpy(p, p, strlen(p) + 1);
2709 macdefine(&CurEnv->e_macro, A_TEMP, mid, p);
2712 case 'm': /* send to me too */
2713 MeToo = atobool(val);
2716 case 'n': /* validate RHS in newaliases */
2717 CheckAliases = atobool(val);
2720 /* 'N' available -- was "net name" */
2722 case 'O': /* daemon options */
2723 if (!setdaemonoptions(val))
2724 syserr("too many daemons defined (%d max)", MAXDAEMONS);
2727 case 'o': /* assume old style headers */
2729 CurEnv->e_flags |= EF_OLDSTYLE;
2731 CurEnv->e_flags &= ~EF_OLDSTYLE;
2734 case 'p': /* select privacy level */
2738 register struct prival *pv;
2739 extern struct prival PrivacyValues[];
2741 while (isascii(*p) && (isspace(*p) || ispunct(*p)))
2746 while (isascii(*p) && isalnum(*p))
2751 for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
2753 if (sm_strcasecmp(val, pv->pv_name) == 0)
2756 if (pv->pv_name == NULL)
2757 syserr("readcf: Op line: %s unrecognized", val);
2759 PrivacyFlags |= pv->pv_flag;
2764 case 'P': /* postmaster copy address for returned mail */
2765 PostMasterCopy = newstr(val);
2768 case 'q': /* slope of queue only function */
2769 QueueFactor = atoi(val);
2772 case 'Q': /* queue directory */
2775 QueueDir = "mqueue";
2779 QueueDir = newstr(val);
2781 if (RealUid != 0 && !safe)
2782 Warn_Q_option = true;
2785 case 'R': /* don't prune routes */
2786 DontPruneRoutes = atobool(val);
2789 case 'r': /* read timeout */
2791 inittimeouts(val, sticky);
2793 settimeout(subopt, val, sticky);
2796 case 'S': /* status file */
2799 SET_OPT_DEFAULT(StatFile, "statistics");
2804 StatFile = newstr(val);
2808 case 's': /* be super safe, even if expensive */
2809 if (tolower(*val) == 'i')
2810 SuperSafe = SAFE_INTERACTIVE;
2811 else if (tolower(*val) == 'p')
2813 SuperSafe = SAFE_REALLY_POSTMILTER;
2815 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
2816 "Warning: SuperSafe=PostMilter requires Milter support (-DMILTER)\n");
2819 SuperSafe = atobool(val) ? SAFE_REALLY : SAFE_NO;
2822 case 'T': /* queue timeout */
2823 p = strchr(val, '/');
2827 settimeout("queuewarn", p, sticky);
2829 settimeout("queuereturn", val, sticky);
2832 case 't': /* time zone name */
2833 TimeZoneSpec = newstr(val);
2836 case 'U': /* location of user database */
2837 UdbSpec = newstr(val);
2840 case 'u': /* set default uid */
2841 for (p = val; *p != '\0'; p++)
2843 # if _FFR_DOTTED_USERNAMES
2844 if (*p == '/' || *p == ':')
2845 # else /* _FFR_DOTTED_USERNAMES */
2846 if (*p == '.' || *p == '/' || *p == ':')
2847 # endif /* _FFR_DOTTED_USERNAMES */
2853 if (isascii(*val) && isdigit(*val))
2860 register struct passwd *pw;
2863 pw = sm_getpwnam(val);
2866 syserr("readcf: option u: unknown user %s", val);
2871 DefUid = pw->pw_uid;
2872 DefGid = pw->pw_gid;
2873 DefUser = newstr(pw->pw_name);
2878 if (DefUid > UID_MAX)
2880 syserr("readcf: option u: uid value (%ld) > UID_MAX (%ld); ignored",
2881 (long)DefUid, (long)UID_MAX);
2884 # endif /* UID_MAX */
2886 /* handle the group if it is there */
2892 case 'V': /* fallback MX host */
2894 FallbackMX = newstr(val);
2897 case 'v': /* run in verbose mode */
2898 Verbose = atobool(val) ? 1 : 0;
2901 case 'w': /* if we are best MX, try host directly */
2902 TryNullMXList = atobool(val);
2905 /* 'W' available -- was wizard password */
2907 case 'x': /* load avg at which to auto-queue msgs */
2908 QueueLA = atoi(val);
2911 case 'X': /* load avg at which to auto-reject connections */
2912 RefuseLA = atoi(val);
2915 case O_DELAY_LA: /* load avg at which to delay connections */
2916 DelayLA = atoi(val);
2919 case 'y': /* work recipient factor */
2920 WkRecipFact = atoi(val);
2923 case 'Y': /* fork jobs during queue runs */
2924 ForkQueueRuns = atobool(val);
2927 case 'z': /* work message class factor */
2928 WkClassFact = atoi(val);
2931 case 'Z': /* work time factor */
2932 WkTimeFact = atoi(val);
2936 #if _FFR_QUEUE_GROUP_SORTORDER
2937 /* coordinate this with makequeue() */
2938 #endif /* _FFR_QUEUE_GROUP_SORTORDER */
2939 case O_QUEUESORTORD: /* queue sorting order */
2942 case 'f': /* File Name */
2944 QueueSortOrder = QSO_BYFILENAME;
2947 case 'h': /* Host first */
2949 QueueSortOrder = QSO_BYHOST;
2952 case 'm': /* Modification time */
2954 QueueSortOrder = QSO_BYMODTIME;
2957 case 'p': /* Priority order */
2959 QueueSortOrder = QSO_BYPRIORITY;
2962 case 't': /* Submission time */
2964 QueueSortOrder = QSO_BYTIME;
2967 case 'r': /* Random */
2969 QueueSortOrder = QSO_RANDOM;
2973 case 's': /* Shuffled host name */
2975 QueueSortOrder = QSO_BYSHUFFLE;
2977 #endif /* _FFR_RHS */
2979 case 'n': /* none */
2981 QueueSortOrder = QSO_NONE;
2985 syserr("Invalid queue sort order \"%s\"", val);
2989 case O_HOSTSFILE: /* pathname of /etc/hosts file */
2991 HostsFile = newstr(val);
2994 case O_MQA: /* minimum queue age between deliveries */
2995 MinQueueAge = convtime(val, 'm');
2998 case O_DEFCHARSET: /* default character set for mimefying */
2999 DefaultCharSet = newstr(denlstring(val, true, true));
3002 case O_SSFILE: /* service switch file */
3004 ServiceSwitchFile = newstr(val);
3007 case O_DIALDELAY: /* delay for dial-on-demand operation */
3008 DialDelay = convtime(val, 's');
3011 case O_NORCPTACTION: /* what to do if no recipient */
3012 if (sm_strcasecmp(val, "none") == 0)
3013 NoRecipientAction = NRA_NO_ACTION;
3014 else if (sm_strcasecmp(val, "add-to") == 0)
3015 NoRecipientAction = NRA_ADD_TO;
3016 else if (sm_strcasecmp(val, "add-apparently-to") == 0)
3017 NoRecipientAction = NRA_ADD_APPARENTLY_TO;
3018 else if (sm_strcasecmp(val, "add-bcc") == 0)
3019 NoRecipientAction = NRA_ADD_BCC;
3020 else if (sm_strcasecmp(val, "add-to-undisclosed") == 0)
3021 NoRecipientAction = NRA_ADD_TO_UNDISCLOSED;
3023 syserr("Invalid NoRecipientAction: %s", val);
3026 case O_SAFEFILEENV: /* chroot() environ for writing to files */
3030 /* strip trailing slashes */
3031 p = val + strlen(val) - 1;
3032 while (p >= val && *p == '/')
3038 SafeFileEnv = newstr(val);
3041 case O_MAXMSGSIZE: /* maximum message size */
3042 MaxMessageSize = atol(val);
3045 case O_COLONOKINADDR: /* old style handling of colon addresses */
3046 ColonOkInAddr = atobool(val);
3049 case O_MAXQUEUERUN: /* max # of jobs in a single queue run */
3050 MaxQueueRun = atoi(val);
3053 case O_MAXCHILDREN: /* max # of children of daemon */
3054 MaxChildren = atoi(val);
3057 case O_MAXQUEUECHILDREN: /* max # of children of daemon */
3058 MaxQueueChildren = atoi(val);
3061 case O_MAXRUNNERSPERQUEUE: /* max # runners in a queue group */
3062 MaxRunnersPerQueue = atoi(val);
3065 case O_NICEQUEUERUN: /* nice queue runs */
3067 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3068 "Warning: NiceQueueRun set on system that doesn't support nice()\n");
3069 #endif /* !HASNICE */
3071 /* XXX do we want to check the range? > 0 ? */
3072 NiceQueueRun = atoi(val);
3075 case O_SHMKEY: /* shared memory key */
3078 #else /* SM_CONF_SHM */
3079 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3080 "Warning: Option: %s requires shared memory support (-DSM_CONF_SHM)\n",
3082 #endif /* SM_CONF_SHM */
3085 case O_SHMKEYFILE: /* shared memory key file */
3087 SET_STRING_EXP(ShmKeyFile);
3088 #else /* SM_CONF_SHM */
3089 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3090 "Warning: Option: %s requires shared memory support (-DSM_CONF_SHM)\n",
3093 #endif /* SM_CONF_SHM */
3095 #if _FFR_MAX_FORWARD_ENTRIES
3096 case O_MAXFORWARD: /* max # of forward entries */
3097 MaxForwardEntries = atoi(val);
3099 #endif /* _FFR_MAX_FORWARD_ENTRIES */
3101 case O_KEEPCNAMES: /* don't expand CNAME records */
3102 DontExpandCnames = atobool(val);
3105 case O_MUSTQUOTE: /* must quote these characters in phrases */
3106 (void) sm_strlcpy(buf, "@,;:\\()[]", sizeof(buf));
3107 if (strlen(val) < sizeof(buf) - 10)
3108 (void) sm_strlcat(buf, val, sizeof(buf));
3110 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3111 "Warning: MustQuoteChars too long, ignored.\n");
3112 MustQuoteChars = newstr(buf);
3115 case O_SMTPGREETING: /* SMTP greeting message (old $e macro) */
3116 SmtpGreeting = newstr(munchstring(val, NULL, '\0'));
3119 case O_UNIXFROM: /* UNIX From_ line (old $l macro) */
3120 UnixFromLine = newstr(munchstring(val, NULL, '\0'));
3123 case O_OPCHARS: /* operator characters (old $o macro) */
3124 if (OperatorChars != NULL)
3125 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3126 "Warning: OperatorChars is being redefined.\n It should only be set before ruleset definitions.\n");
3127 OperatorChars = newstr(munchstring(val, NULL, '\0'));
3130 case O_DONTINITGRPS: /* don't call initgroups(3) */
3131 DontInitGroups = atobool(val);
3134 case O_SLFH: /* make sure from fits on one line */
3135 SingleLineFromHeader = atobool(val);
3138 case O_ABH: /* allow HELO commands with syntax errors */
3139 AllowBogusHELO = atobool(val);
3142 case O_CONNTHROT: /* connection rate throttle */
3143 ConnRateThrottle = atoi(val);
3146 case O_UGW: /* group writable files are unsafe */
3149 setbitn(DBS_GROUPWRITABLEFORWARDFILESAFE,
3151 setbitn(DBS_GROUPWRITABLEINCLUDEFILESAFE,
3156 case O_DBLBOUNCE: /* address to which to send double bounces */
3157 DoubleBounceAddr = newstr(val);
3160 case O_HSDIR: /* persistent host status directory */
3164 HostStatDir = newstr(val);
3168 case O_SINGTHREAD: /* single thread deliveries (requires hsdir) */
3169 SingleThreadDelivery = atobool(val);
3172 case O_RUNASUSER: /* run bulk of code as this user */
3173 for (p = val; *p != '\0'; p++)
3175 # if _FFR_DOTTED_USERNAMES
3176 if (*p == '/' || *p == ':')
3177 # else /* _FFR_DOTTED_USERNAMES */
3178 if (*p == '.' || *p == '/' || *p == ':')
3179 # endif /* _FFR_DOTTED_USERNAMES */
3185 if (isascii(*val) && isdigit(*val))
3188 RunAsUid = atoi(val);
3192 register struct passwd *pw;
3194 pw = sm_getpwnam(val);
3197 syserr("readcf: option RunAsUser: unknown user %s", val);
3200 else if (can_setuid)
3203 RunAsUserName = newstr(val);
3204 RunAsUid = pw->pw_uid;
3205 RunAsGid = pw->pw_gid;
3207 else if (EffGid == pw->pw_gid)
3208 RunAsGid = pw->pw_gid;
3209 else if (UseMSP && *p == '\0')
3210 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3211 "WARNING: RunAsUser for MSP ignored, check group ids (egid=%d, want=%d)\n",
3216 if (RunAsUid > UID_MAX)
3218 syserr("readcf: option RunAsUser: uid value (%ld) > UID_MAX (%ld); ignored",
3219 (long) RunAsUid, (long) UID_MAX);
3222 # endif /* UID_MAX */
3225 if (isascii(*p) && isdigit(*p))
3229 runasgid = (gid_t) atoi(p);
3230 if (can_setuid || EffGid == runasgid)
3231 RunAsGid = runasgid;
3233 (void) sm_io_fprintf(smioout,
3235 "WARNING: RunAsUser for MSP ignored, check group ids (egid=%d, want=%d)\n",
3241 register struct group *gr;
3245 syserr("readcf: option RunAsUser: unknown group %s",
3247 else if (can_setuid || EffGid == gr->gr_gid)
3248 RunAsGid = gr->gr_gid;
3250 (void) sm_io_fprintf(smioout,
3252 "WARNING: RunAsUser for MSP ignored, check group ids (egid=%d, want=%d)\n",
3258 sm_dprintf("readcf: RunAsUser = %d:%d\n",
3259 (int) RunAsUid, (int) RunAsGid);
3263 RrtImpliesDsn = atobool(val);
3267 PSTRSET(PidFile, val);
3270 case O_DONTBLAMESENDMAIL:
3274 register struct dbsval *dbs;
3275 extern struct dbsval DontBlameSendmailValues[];
3277 while (isascii(*p) && (isspace(*p) || ispunct(*p)))
3282 while (isascii(*p) && isalnum(*p))
3287 for (dbs = DontBlameSendmailValues;
3288 dbs->dbs_name != NULL; dbs++)
3290 if (sm_strcasecmp(val, dbs->dbs_name) == 0)
3293 if (dbs->dbs_name == NULL)
3294 syserr("readcf: DontBlameSendmail option: %s unrecognized", val);
3295 else if (dbs->dbs_flag == DBS_SAFE)
3296 clrbitmap(DontBlameSendmail);
3298 setbitn(dbs->dbs_flag, DontBlameSendmail);
3304 if (sm_strcasecmp(val, "loopback") == 0)
3305 DontProbeInterfaces = DPI_SKIPLOOPBACK;
3306 else if (atobool(val))
3307 DontProbeInterfaces = DPI_PROBENONE;
3309 DontProbeInterfaces = DPI_PROBEALL;
3313 MaxRcptPerMsg = atoi(val);
3317 BadRcptThrottle = atoi(val);
3322 PSTRSET(DeadLetterDrop, val);
3325 #if _FFR_DONTLOCKFILESFORREAD_OPTION
3327 DontLockReadFiles = atobool(val);
3329 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
3331 case O_MAXALIASRCSN:
3332 MaxAliasRecursion = atoi(val);
3336 /* XXX should probably use gethostbyname */
3337 #if NETINET || NETINET6
3338 ConnectOnlyTo.sa.sa_family = AF_UNSPEC;
3340 if (anynet_pton(AF_INET6, val,
3341 &ConnectOnlyTo.sin6.sin6_addr) != 1)
3342 ConnectOnlyTo.sa.sa_family = AF_INET6;
3344 # endif /* NETINET6 */
3347 ConnectOnlyTo.sin.sin_addr.s_addr = inet_addr(val);
3348 if (ConnectOnlyTo.sin.sin_addr.s_addr != INADDR_NONE)
3349 ConnectOnlyTo.sa.sa_family = AF_INET;
3352 # endif /* NETINET */
3353 if (ConnectOnlyTo.sa.sa_family == AF_UNSPEC)
3355 syserr("readcf: option ConnectOnlyTo: invalid IP address %s",
3359 #endif /* NETINET || NETINET6 */
3363 # if !HASFCHOWN && !defined(_FFR_DROP_TRUSTUSER_WARNING)
3365 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3366 "readcf: option TrustedUser may cause problems on systems\n which do not support fchown() if UseMSP is not set.\n");
3367 # endif /* !HASFCHOWN && !defined(_FFR_DROP_TRUSTUSER_WARNING) */
3368 if (isascii(*val) && isdigit(*val))
3369 TrustedUid = atoi(val);
3372 register struct passwd *pw;
3375 pw = sm_getpwnam(val);
3378 syserr("readcf: option TrustedUser: unknown user %s", val);
3382 TrustedUid = pw->pw_uid;
3386 if (TrustedUid > UID_MAX)
3388 syserr("readcf: option TrustedUser: uid value (%ld) > UID_MAX (%ld)",
3389 (long) TrustedUid, (long) UID_MAX);
3392 # endif /* UID_MAX */
3395 case O_MAXMIMEHDRLEN:
3396 p = strchr(val, '/');
3399 MaxMimeHeaderLength = atoi(val);
3400 if (p != NULL && *p != '\0')
3401 MaxMimeFieldLength = atoi(p);
3403 MaxMimeFieldLength = MaxMimeHeaderLength / 2;
3405 if (MaxMimeHeaderLength <= 0)
3406 MaxMimeHeaderLength = 0;
3407 else if (MaxMimeHeaderLength < 128)
3408 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3409 "Warning: MaxMimeHeaderLength: header length limit set lower than 128\n");
3411 if (MaxMimeFieldLength <= 0)
3412 MaxMimeFieldLength = 0;
3413 else if (MaxMimeFieldLength < 40)
3414 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3415 "Warning: MaxMimeHeaderLength: field length limit set lower than 40\n");
3418 ** Headers field values now include leading space, so let's
3419 ** adjust the values to be "backward compatible".
3422 if (MaxMimeHeaderLength > 0)
3423 MaxMimeHeaderLength++;
3424 if (MaxMimeFieldLength > 0)
3425 MaxMimeFieldLength++;
3428 case O_CONTROLSOCKET:
3429 PSTRSET(ControlSocketName, val);
3433 MaxHeadersLength = atoi(val);
3435 if (MaxHeadersLength > 0 &&
3436 MaxHeadersLength < (MAXHDRSLEN / 2))
3437 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3438 "Warning: MaxHeadersLength: headers length limit set lower than %d\n",
3442 case O_PROCTITLEPREFIX:
3443 PSTRSET(ProcTitlePrefix, val);
3448 # if _FFR_ALLOW_SASLINFO
3450 ** Allow users to select their own authinfo file
3451 ** under certain circumstances, otherwise just ignore
3452 ** the option. If the option isn't ignored, several
3453 ** commands don't work very well, e.g., mailq.
3454 ** However, this is not a "perfect" solution.
3455 ** If mail is queued, the authentication info
3456 ** will not be used in subsequent delivery attempts.
3457 ** If we really want to support this, then it has
3458 ** to be stored in the queue file.
3460 if (!bitset(SUBMIT_MSA, SubmitMode) && RealUid != 0 &&
3461 RunAsUid != RealUid)
3463 # endif /* _FFR_ALLOW_SASLINFO */
3464 PSTRSET(SASLInfo, val);
3468 if (AuthMechanisms != NULL)
3469 sm_free(AuthMechanisms); /* XXX */
3471 AuthMechanisms = newstr(val);
3473 AuthMechanisms = NULL;
3477 if (AuthRealm != NULL)
3480 AuthRealm = newstr(val);
3486 while (val != NULL && *val != '\0')
3491 SASLOpts |= SASL_AUTH_AUTH;
3495 SASLOpts |= SASL_SEC_NOACTIVE;
3499 SASLOpts |= SASL_SEC_PASS_CREDENTIALS;
3503 SASLOpts |= SASL_SEC_NODICTIONARY;
3507 SASLOpts |= SASL_SEC_FORWARD_SECRECY;
3512 SASLOpts |= SASL_SEC_MUTUAL_AUTH;
3514 # endif /* SASL >= 20101 */
3517 SASLOpts |= SASL_SEC_NOPLAINTEXT;
3521 SASLOpts |= SASL_SEC_NOANONYMOUS;
3524 case ' ': /* ignore */
3525 case '\t': /* ignore */
3526 case ',': /* ignore */
3530 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3531 "Warning: Option: %s unknown parameter '%c'\n",
3539 val = strpbrk(val, ", \t");
3546 MaxSLBits = atoi(val);
3555 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3556 "Warning: Option: %s requires SASL support (-DSASL)\n",
3563 SET_STRING_EXP(SrvCertFile);
3565 SET_STRING_EXP(SrvKeyFile);
3567 SET_STRING_EXP(CltCertFile);
3569 SET_STRING_EXP(CltKeyFile);
3571 SET_STRING_EXP(CACertFile);
3573 SET_STRING_EXP(CACertPath);
3575 SET_STRING_EXP(DHParams);
3578 SET_STRING_EXP(DHParams5);
3580 SET_STRING_EXP(CipherList);
3581 # endif /* _FFR_TLS_1 */
3583 # if OPENSSL_VERSION_NUMBER > 0x00907000L
3584 SET_STRING_EXP(CRLFile);
3585 # else /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3586 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3587 "Warning: Option: %s requires at least OpenSSL 0.9.7\n",
3590 # endif /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3594 # if OPENSSL_VERSION_NUMBER > 0x00907000L
3595 SET_STRING_EXP(CRLPath);
3596 # else /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3597 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3598 "Warning: Option: %s requires at least OpenSSL 0.9.7\n",
3601 # endif /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3602 # endif /* _FFR_CRLPATH */
3605 ** XXX How about options per daemon/client instead of globally?
3606 ** This doesn't work well for some options, e.g., no server cert,
3607 ** but fine for others.
3609 ** XXX Some people may want different certs per server.
3611 ** See also srvfeatures()
3614 case O_TLS_SRV_OPTS:
3615 while (val != NULL && *val != '\0')
3620 TLS_Srv_Opts |= TLS_I_NO_VRFY;
3624 ** Server without a cert? That works only if
3625 ** AnonDH is enabled as cipher, which is not in the
3626 ** default list. Hence the CipherList option must
3627 ** be available. Moreover: which clients support this
3628 ** besides sendmail with this setting?
3632 TLS_Srv_Opts &= ~TLS_I_SRV_CERT;
3634 # endif /* _FFR_TLS_1 */
3635 case ' ': /* ignore */
3636 case '\t': /* ignore */
3637 case ',': /* ignore */
3640 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3641 "Warning: Option: %s unknown parameter '%c'\n",
3649 val = strpbrk(val, ", \t");
3656 PSTRSET(RandFile, val);
3659 #else /* STARTTLS */
3670 # endif /* _FFR_TLS_1 */
3674 # endif /* _FFR_CRLPATH */
3676 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3677 "Warning: Option: %s requires TLS support\n",
3681 #endif /* STARTTLS */
3684 setclientoptions(val);
3688 DataFileBufferSize = atoi(val);
3692 XscriptFileBufferSize = atoi(val);
3695 case O_LDAPDEFAULTSPEC:
3697 ldapmap_set_defaults(val);
3699 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3700 "Warning: Option: %s requires LDAP support (-DLDAPMAP)\n",
3702 #endif /* LDAPMAP */
3707 InputFilterList = newstr(val);
3709 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3710 "Warning: Option: %s requires Milter support (-DMILTER)\n",
3717 milter_set_option(subopt, val, sticky);
3719 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3720 "Warning: Option: %s requires Milter support (-DMILTER)\n",
3725 case O_QUEUE_FILE_MODE: /* queue file mode */
3726 QueueFileMode = atooct(val) & 0777;
3729 case O_DLVR_MIN: /* deliver by minimum time */
3730 DeliverByMin = convtime(val, 's');
3733 /* modifiers {daemon_flags} for direct submissions */
3734 case O_DIRECTSUBMODIFIERS:
3736 BITMAP256 m; /* ignored */
3737 extern ENVELOPE BlankEnvelope;
3739 macdefine(&BlankEnvelope.e_macro, A_PERM,
3740 macid("{daemon_flags}"),
3741 getmodifiers(val, m));
3746 FastSplit = atoi(val);
3754 UseMSP = atobool(val);
3758 SoftBounce = atobool(val);
3761 case O_REJECTLOGINTERVAL: /* time btwn log msgs while refusing */
3762 RejectLogInterval = convtime(val, 'h');
3765 case O_REQUIRES_DIR_FSYNC:
3766 #if REQUIRES_DIR_FSYNC
3767 RequiresDirfsync = atobool(val);
3768 #else /* REQUIRES_DIR_FSYNC */
3769 /* silently ignored... required for cf file option */
3770 #endif /* REQUIRES_DIR_FSYNC */
3773 case O_CONNECTION_RATE_WINDOW_SIZE:
3774 ConnectionRateWindowSize = convtime(val, 's');
3777 case O_FALLBACKSMARTHOST: /* fallback smart host */
3779 FallbackSmartHost = newstr(val);
3783 HeloName = newstr(val);
3787 case O_REFUSELOWMEM:
3788 RefuseLowMem = atoi(val);
3791 QueueLowMem = atoi(val);
3794 MemoryResource = newstr(val);
3796 #endif /* _FFR_MEMSTAT */
3798 case O_MAXNOOPCOMMANDS:
3799 MaxNOOPCommands = atoi(val);
3804 MessageAccept = newstr(val);
3806 #endif /* _FFR_MSG_ACCEPT */
3808 #if _FFR_QUEUE_RUN_PARANOIA
3809 case O_CHK_Q_RUNNERS:
3810 CheckQueueRunners = atoi(val);
3812 #endif /* _FFR_QUEUE_RUN_PARANOIA */
3814 #if _FFR_EIGHT_BIT_ADDR_OK
3815 case O_EIGHT_BIT_ADDR_OK:
3816 EightBitAddrOK = atobool(val);
3818 #endif /* _FFR_EIGHT_BIT_ADDR_OK */
3820 #if _FFR_ADDR_TYPE_MODES
3821 case O_ADDR_TYPE_MODES:
3822 AddrTypeModes = atobool(val);
3824 #endif /* _FFR_ADDR_TYPE_MODES */
3826 #if _FFR_BADRCPT_SHUTDOWN
3828 BadRcptShutdown = atoi(val);
3832 BadRcptShutdownGood = atoi(val);
3834 #endif /* _FFR_BADRCPT_SHUTDOWN */
3839 if (isascii(opt) && isprint(opt))
3840 sm_dprintf("Warning: option %c unknown\n", opt);
3842 sm_dprintf("Warning: option 0x%x unknown\n", opt);
3848 ** Options with suboptions are responsible for taking care
3849 ** of sticky-ness (e.g., that a command line setting is kept
3850 ** when reading in the sendmail.cf file). This has to be done
3851 ** when the suboptions are parsed since each suboption must be
3852 ** sticky, not the root option.
3855 if (sticky && !bitset(OI_SUBOPT, o->o_flags))
3856 setbitn(opt, StickyOpt);
3859 ** SETCLASS -- set a string into a class
3862 ** class -- the class to put the string in.
3863 ** str -- the string to enter
3869 ** puts the word into the symbol table.
3873 setclass(class, str)
3879 if ((str[0] & 0377) == MATCHCLASS)
3889 sm_dprintf("setclass(%s, $=%s)\n",
3890 macname(class), macname(mid));
3891 copy_class(mid, class);
3896 sm_dprintf("setclass(%s, %s)\n", macname(class), str);
3898 s = stab(str, ST_CLASS, ST_ENTER);
3899 setbitn(bitidx(class), s->s_class);
3903 ** MAKEMAPENTRY -- create a map entry
3906 ** line -- the config file line
3909 ** A pointer to the map that has been created.
3910 ** NULL if there was a syntax error.
3913 ** Enters the map into the dictionary.
3926 for (p = line; isascii(*p) && isspace(*p); p++)
3928 if (!(isascii(*p) && isalnum(*p)))
3930 syserr("readcf: config K line: no map name");
3935 while ((isascii(*++p) && isalnum(*p)) || *p == '_' || *p == '.')
3939 while (isascii(*p) && isspace(*p))
3941 if (!(isascii(*p) && isalnum(*p)))
3943 syserr("readcf: config K line, map %s: no map class", mapname);
3947 while (isascii(*++p) && isalnum(*p))
3951 while (isascii(*p) && isspace(*p))
3954 /* look up the class */
3955 class = stab(classname, ST_MAPCLASS, ST_FIND);
3958 syserr("readcf: map %s: class %s not available", mapname,
3964 s = stab(mapname, ST_MAP, ST_ENTER);
3965 s->s_map.map_class = &class->s_mapclass;
3966 s->s_map.map_mname = newstr(mapname);
3968 if (class->s_mapclass.map_parse(&s->s_map, p))
3969 s->s_map.map_mflags |= MF_VALID;
3973 sm_dprintf("map %s, class %s, flags %lx, file %s,\n",
3974 s->s_map.map_mname, s->s_map.map_class->map_cname,
3975 s->s_map.map_mflags, s->s_map.map_file);
3976 sm_dprintf("\tapp %s, domain %s, rebuild %s\n",
3977 s->s_map.map_app, s->s_map.map_domain,
3978 s->s_map.map_rebuild);
3983 ** STRTORWSET -- convert string to rewriting set number
3986 ** p -- the pointer to the string to decode.
3987 ** endp -- if set, store the trailing delimiter here.
3988 ** stabmode -- ST_ENTER to create this entry, ST_FIND if
3989 ** it must already exist.
3992 ** The appropriate ruleset number.
3993 ** -1 if it is not valid (error already printed)
3997 strtorwset(p, endp, stabmode)
4003 static int nextruleset = MAXRWSETS;
4005 while (isascii(*p) && isspace(*p))
4009 syserr("invalid ruleset name: \"%.20s\"", p);
4014 ruleset = strtol(p, endp, 10);
4015 if (ruleset >= MAXRWSETS / 2 || ruleset < 0)
4017 syserr("bad ruleset %d (%d max)",
4018 ruleset, MAXRWSETS / 2);
4029 while (*p != '\0' && isascii(*p) &&
4030 (isalnum(*p) || *p == '_'))
4032 if (q == p || !(isascii(*q) && isalpha(*q)))
4034 /* no valid characters */
4035 syserr("invalid ruleset name: \"%.20s\"", q);
4038 while (isascii(*p) && isspace(*p))
4043 s = stab(q, ST_RULESET, stabmode);
4050 if (stabmode == ST_ENTER && delim == '=')
4052 while (isascii(*++p) && isspace(*p))
4054 if (!(isascii(*p) && isdigit(*p)))
4056 syserr("bad ruleset definition \"%s\" (number required after `=')", q);
4061 ruleset = strtol(p, endp, 10);
4062 if (ruleset >= MAXRWSETS / 2 || ruleset < 0)
4064 syserr("bad ruleset number %d in \"%s\" (%d max)",
4065 ruleset, q, MAXRWSETS / 2);
4074 if (s->s_ruleset >= 0)
4075 ruleset = s->s_ruleset;
4076 else if ((ruleset = --nextruleset) < MAXRWSETS / 2)
4078 syserr("%s: too many named rulesets (%d max)",
4083 if (s->s_ruleset >= 0 &&
4085 ruleset != s->s_ruleset)
4087 syserr("%s: ruleset changed value (old %d, new %d)",
4088 q, s->s_ruleset, ruleset);
4089 ruleset = s->s_ruleset;
4091 else if (ruleset >= 0)
4093 s->s_ruleset = ruleset;
4095 if (stabmode == ST_ENTER && ruleset >= 0)
4099 if (RuleSetNames[ruleset] != NULL)
4100 sm_free(RuleSetNames[ruleset]); /* XXX */
4101 if (delim != '\0' && (h = strchr(q, delim)) != NULL)
4103 RuleSetNames[ruleset] = newstr(q);
4104 if (delim == '/' && h != NULL)
4105 *h = delim; /* put back delim */
4111 ** SETTIMEOUT -- set an individual timeout
4114 ** name -- the name of the timeout.
4115 ** val -- the value of the timeout.
4116 ** sticky -- if set, don't let other setoptions override
4123 /* set if Timeout sub-option is stuck */
4124 static BITMAP256 StickyTimeoutOpt;
4126 static struct timeoutinfo
4128 char *to_name; /* long name of timeout */
4129 unsigned char to_code; /* code for option */
4132 #define TO_INITIAL 0x01
4133 { "initial", TO_INITIAL },
4134 #define TO_MAIL 0x02
4135 { "mail", TO_MAIL },
4136 #define TO_RCPT 0x03
4137 { "rcpt", TO_RCPT },
4138 #define TO_DATAINIT 0x04
4139 { "datainit", TO_DATAINIT },
4140 #define TO_DATABLOCK 0x05
4141 { "datablock", TO_DATABLOCK },
4142 #define TO_DATAFINAL 0x06
4143 { "datafinal", TO_DATAFINAL },
4144 #define TO_COMMAND 0x07
4145 { "command", TO_COMMAND },
4146 #define TO_RSET 0x08
4147 { "rset", TO_RSET },
4148 #define TO_HELO 0x09
4149 { "helo", TO_HELO },
4150 #define TO_QUIT 0x0A
4151 { "quit", TO_QUIT },
4152 #define TO_MISC 0x0B
4153 { "misc", TO_MISC },
4154 #define TO_IDENT 0x0C
4155 { "ident", TO_IDENT },
4156 #define TO_FILEOPEN 0x0D
4157 { "fileopen", TO_FILEOPEN },
4158 #define TO_CONNECT 0x0E
4159 { "connect", TO_CONNECT },
4160 #define TO_ICONNECT 0x0F
4161 { "iconnect", TO_ICONNECT },
4162 #define TO_QUEUEWARN 0x10
4163 { "queuewarn", TO_QUEUEWARN },
4164 { "queuewarn.*", TO_QUEUEWARN },
4165 #define TO_QUEUEWARN_NORMAL 0x11
4166 { "queuewarn.normal", TO_QUEUEWARN_NORMAL },
4167 #define TO_QUEUEWARN_URGENT 0x12
4168 { "queuewarn.urgent", TO_QUEUEWARN_URGENT },
4169 #define TO_QUEUEWARN_NON_URGENT 0x13
4170 { "queuewarn.non-urgent", TO_QUEUEWARN_NON_URGENT },
4171 #define TO_QUEUERETURN 0x14
4172 { "queuereturn", TO_QUEUERETURN },
4173 { "queuereturn.*", TO_QUEUERETURN },
4174 #define TO_QUEUERETURN_NORMAL 0x15
4175 { "queuereturn.normal", TO_QUEUERETURN_NORMAL },
4176 #define TO_QUEUERETURN_URGENT 0x16
4177 { "queuereturn.urgent", TO_QUEUERETURN_URGENT },
4178 #define TO_QUEUERETURN_NON_URGENT 0x17
4179 { "queuereturn.non-urgent", TO_QUEUERETURN_NON_URGENT },
4180 #define TO_HOSTSTATUS 0x18
4181 { "hoststatus", TO_HOSTSTATUS },
4182 #define TO_RESOLVER_RETRANS 0x19
4183 { "resolver.retrans", TO_RESOLVER_RETRANS },
4184 #define TO_RESOLVER_RETRANS_NORMAL 0x1A
4185 { "resolver.retrans.normal", TO_RESOLVER_RETRANS_NORMAL },
4186 #define TO_RESOLVER_RETRANS_FIRST 0x1B
4187 { "resolver.retrans.first", TO_RESOLVER_RETRANS_FIRST },
4188 #define TO_RESOLVER_RETRY 0x1C
4189 { "resolver.retry", TO_RESOLVER_RETRY },
4190 #define TO_RESOLVER_RETRY_NORMAL 0x1D
4191 { "resolver.retry.normal", TO_RESOLVER_RETRY_NORMAL },
4192 #define TO_RESOLVER_RETRY_FIRST 0x1E
4193 { "resolver.retry.first", TO_RESOLVER_RETRY_FIRST },
4194 #define TO_CONTROL 0x1F
4195 { "control", TO_CONTROL },
4196 #define TO_LHLO 0x20
4197 { "lhlo", TO_LHLO },
4198 #define TO_AUTH 0x21
4199 { "auth", TO_AUTH },
4200 #define TO_STARTTLS 0x22
4201 { "starttls", TO_STARTTLS },
4202 #define TO_ACONNECT 0x23
4203 { "aconnect", TO_ACONNECT },
4204 #define TO_QUEUEWARN_DSN 0x24
4205 { "queuewarn.dsn", TO_QUEUEWARN_DSN },
4206 #define TO_QUEUERETURN_DSN 0x25
4207 { "queuereturn.dsn", TO_QUEUERETURN_DSN },
4213 settimeout(name, val, sticky)
4218 register struct timeoutinfo *to;
4223 sm_dprintf("settimeout(%s = %s)", name, val);
4225 for (to = TimeOutTab; to->to_name != NULL; to++)
4227 if (sm_strcasecmp(to->to_name, name) == 0)
4231 if (to->to_name == NULL)
4233 errno = 0; /* avoid bogus error text */
4234 syserr("settimeout: invalid timeout %s", name);
4239 ** See if this option is preset for us.
4242 if (!sticky && bitnset(to->to_code, StickyTimeoutOpt))
4245 sm_dprintf(" (ignored)\n");
4252 toval = convtime(val, 'm');
4255 switch (to->to_code)
4258 TimeOuts.to_initial = toval;
4262 TimeOuts.to_mail = toval;
4266 TimeOuts.to_rcpt = toval;
4270 TimeOuts.to_datainit = toval;
4274 TimeOuts.to_datablock = toval;
4278 TimeOuts.to_datafinal = toval;
4282 TimeOuts.to_nextcommand = toval;
4286 TimeOuts.to_rset = toval;
4290 TimeOuts.to_helo = toval;
4294 TimeOuts.to_quit = toval;
4298 TimeOuts.to_miscshort = toval;
4302 TimeOuts.to_ident = toval;
4306 TimeOuts.to_fileopen = toval;
4310 TimeOuts.to_connect = toval;
4314 TimeOuts.to_iconnect = toval;
4318 TimeOuts.to_aconnect = toval;
4322 toval = convtime(val, 'h');
4323 TimeOuts.to_q_warning[TOC_NORMAL] = toval;
4324 TimeOuts.to_q_warning[TOC_URGENT] = toval;
4325 TimeOuts.to_q_warning[TOC_NONURGENT] = toval;
4326 TimeOuts.to_q_warning[TOC_DSN] = toval;
4330 case TO_QUEUEWARN_NORMAL:
4331 toval = convtime(val, 'h');
4332 TimeOuts.to_q_warning[TOC_NORMAL] = toval;
4335 case TO_QUEUEWARN_URGENT:
4336 toval = convtime(val, 'h');
4337 TimeOuts.to_q_warning[TOC_URGENT] = toval;
4340 case TO_QUEUEWARN_NON_URGENT:
4341 toval = convtime(val, 'h');
4342 TimeOuts.to_q_warning[TOC_NONURGENT] = toval;
4345 case TO_QUEUEWARN_DSN:
4346 toval = convtime(val, 'h');
4347 TimeOuts.to_q_warning[TOC_DSN] = toval;
4350 case TO_QUEUERETURN:
4351 toval = convtime(val, 'd');
4352 TimeOuts.to_q_return[TOC_NORMAL] = toval;
4353 TimeOuts.to_q_return[TOC_URGENT] = toval;
4354 TimeOuts.to_q_return[TOC_NONURGENT] = toval;
4355 TimeOuts.to_q_return[TOC_DSN] = toval;
4359 case TO_QUEUERETURN_NORMAL:
4360 toval = convtime(val, 'd');
4361 TimeOuts.to_q_return[TOC_NORMAL] = toval;
4364 case TO_QUEUERETURN_URGENT:
4365 toval = convtime(val, 'd');
4366 TimeOuts.to_q_return[TOC_URGENT] = toval;
4369 case TO_QUEUERETURN_NON_URGENT:
4370 toval = convtime(val, 'd');
4371 TimeOuts.to_q_return[TOC_NONURGENT] = toval;
4374 case TO_QUEUERETURN_DSN:
4375 toval = convtime(val, 'd');
4376 TimeOuts.to_q_return[TOC_DSN] = toval;
4380 MciInfoTimeout = toval;
4383 case TO_RESOLVER_RETRANS:
4384 toval = convtime(val, 's');
4385 TimeOuts.res_retrans[RES_TO_DEFAULT] = toval;
4386 TimeOuts.res_retrans[RES_TO_FIRST] = toval;
4387 TimeOuts.res_retrans[RES_TO_NORMAL] = toval;
4391 case TO_RESOLVER_RETRY:
4393 TimeOuts.res_retry[RES_TO_DEFAULT] = i;
4394 TimeOuts.res_retry[RES_TO_FIRST] = i;
4395 TimeOuts.res_retry[RES_TO_NORMAL] = i;
4399 case TO_RESOLVER_RETRANS_NORMAL:
4400 TimeOuts.res_retrans[RES_TO_NORMAL] = convtime(val, 's');
4403 case TO_RESOLVER_RETRY_NORMAL:
4404 TimeOuts.res_retry[RES_TO_NORMAL] = atoi(val);
4407 case TO_RESOLVER_RETRANS_FIRST:
4408 TimeOuts.res_retrans[RES_TO_FIRST] = convtime(val, 's');
4411 case TO_RESOLVER_RETRY_FIRST:
4412 TimeOuts.res_retry[RES_TO_FIRST] = atoi(val);
4416 TimeOuts.to_control = toval;
4420 TimeOuts.to_lhlo = toval;
4425 TimeOuts.to_auth = toval;
4431 TimeOuts.to_starttls = toval;
4433 #endif /* STARTTLS */
4436 syserr("settimeout: invalid timeout %s", name);
4442 for (i = 0; i <= addopts; i++)
4443 setbitn(to->to_code + i, StickyTimeoutOpt);
4447 ** INITTIMEOUTS -- parse and set timeout values
4450 ** val -- a pointer to the values. If NULL, do initial
4452 ** sticky -- if set, don't let other setoptions override
4453 ** this suboption value.
4459 ** Initializes the TimeOuts structure
4463 inittimeouts(val, sticky)
4470 sm_dprintf("inittimeouts(%s)\n", val == NULL ? "<NULL>" : val);
4473 TimeOuts.to_connect = (time_t) 0 SECONDS;
4474 TimeOuts.to_aconnect = (time_t) 0 SECONDS;
4475 TimeOuts.to_iconnect = (time_t) 0 SECONDS;
4476 TimeOuts.to_initial = (time_t) 5 MINUTES;
4477 TimeOuts.to_helo = (time_t) 5 MINUTES;
4478 TimeOuts.to_mail = (time_t) 10 MINUTES;
4479 TimeOuts.to_rcpt = (time_t) 1 HOUR;
4480 TimeOuts.to_datainit = (time_t) 5 MINUTES;
4481 TimeOuts.to_datablock = (time_t) 1 HOUR;
4482 TimeOuts.to_datafinal = (time_t) 1 HOUR;
4483 TimeOuts.to_rset = (time_t) 5 MINUTES;
4484 TimeOuts.to_quit = (time_t) 2 MINUTES;
4485 TimeOuts.to_nextcommand = (time_t) 1 HOUR;
4486 TimeOuts.to_miscshort = (time_t) 2 MINUTES;
4488 TimeOuts.to_ident = (time_t) 5 SECONDS;
4489 #else /* IDENTPROTO */
4490 TimeOuts.to_ident = (time_t) 0 SECONDS;
4491 #endif /* IDENTPROTO */
4492 TimeOuts.to_fileopen = (time_t) 60 SECONDS;
4493 TimeOuts.to_control = (time_t) 2 MINUTES;
4494 TimeOuts.to_lhlo = (time_t) 2 MINUTES;
4496 TimeOuts.to_auth = (time_t) 10 MINUTES;
4499 TimeOuts.to_starttls = (time_t) 1 HOUR;
4500 #endif /* STARTTLS */
4503 sm_dprintf("Timeouts:\n");
4504 sm_dprintf(" connect = %ld\n",
4505 (long) TimeOuts.to_connect);
4506 sm_dprintf(" aconnect = %ld\n",
4507 (long) TimeOuts.to_aconnect);
4508 sm_dprintf(" initial = %ld\n",
4509 (long) TimeOuts.to_initial);
4510 sm_dprintf(" helo = %ld\n", (long) TimeOuts.to_helo);
4511 sm_dprintf(" mail = %ld\n", (long) TimeOuts.to_mail);
4512 sm_dprintf(" rcpt = %ld\n", (long) TimeOuts.to_rcpt);
4513 sm_dprintf(" datainit = %ld\n",
4514 (long) TimeOuts.to_datainit);
4515 sm_dprintf(" datablock = %ld\n",
4516 (long) TimeOuts.to_datablock);
4517 sm_dprintf(" datafinal = %ld\n",
4518 (long) TimeOuts.to_datafinal);
4519 sm_dprintf(" rset = %ld\n", (long) TimeOuts.to_rset);
4520 sm_dprintf(" quit = %ld\n", (long) TimeOuts.to_quit);
4521 sm_dprintf(" nextcommand = %ld\n",
4522 (long) TimeOuts.to_nextcommand);
4523 sm_dprintf(" miscshort = %ld\n",
4524 (long) TimeOuts.to_miscshort);
4525 sm_dprintf(" ident = %ld\n", (long) TimeOuts.to_ident);
4526 sm_dprintf(" fileopen = %ld\n",
4527 (long) TimeOuts.to_fileopen);
4528 sm_dprintf(" lhlo = %ld\n",
4529 (long) TimeOuts.to_lhlo);
4530 sm_dprintf(" control = %ld\n",
4531 (long) TimeOuts.to_control);
4538 while (isascii(*val) && isspace(*val))
4542 for (p = val; *p != '\0' && *p != ','; p++)
4547 if (isascii(*val) && isdigit(*val))
4549 /* old syntax -- set everything */
4550 TimeOuts.to_mail = convtime(val, 'm');
4551 TimeOuts.to_rcpt = TimeOuts.to_mail;
4552 TimeOuts.to_datainit = TimeOuts.to_mail;
4553 TimeOuts.to_datablock = TimeOuts.to_mail;
4554 TimeOuts.to_datafinal = TimeOuts.to_mail;
4555 TimeOuts.to_nextcommand = TimeOuts.to_mail;
4558 setbitn(TO_MAIL, StickyTimeoutOpt);
4559 setbitn(TO_RCPT, StickyTimeoutOpt);
4560 setbitn(TO_DATAINIT, StickyTimeoutOpt);
4561 setbitn(TO_DATABLOCK, StickyTimeoutOpt);
4562 setbitn(TO_DATAFINAL, StickyTimeoutOpt);
4563 setbitn(TO_COMMAND, StickyTimeoutOpt);
4569 register char *q = strchr(val, ':');
4571 if (q == NULL && (q = strchr(val, '=')) == NULL)
4577 settimeout(val, q, sticky);