2 * Copyright (c) 1998-2003 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.
16 SM_RCSID("@(#)$Id: readcf.c,v 8.607.2.11 2003/04/03 23:04:06 ca Exp $")
18 #if NETINET || NETINET6
19 # include <arpa/inet.h>
20 #endif /* NETINET || NETINET6 */
27 static void fileclass __P((int, char *, char *, bool, bool, bool));
28 static char **makeargv __P((char *));
29 static void settimeout __P((char *, char *, bool));
30 static void toomany __P((int, int));
31 static char *extrquotstr __P((char *, char **, char *, bool *));
34 ** READCF -- read configuration file.
36 ** This routine reads the configuration file and builds the internal
39 ** The file is formatted as a sequence of lines, each taken
40 ** atomically. The first character of each line describes how
41 ** the line is to be interpreted. The lines are:
42 ** Dxval Define macro x to have value val.
43 ** Cxword Put word into class x.
44 ** Fxfile [fmt] Read file for lines to put into
45 ** class x. Use scanf string 'fmt'
46 ** or "%s" if not present. Fmt should
47 ** only produce one string-valued result.
48 ** Hname: value Define header with field-name 'name'
49 ** and value as specified; this will be
50 ** macro expanded immediately before
52 ** Sn Use rewriting set n.
53 ** Rlhs rhs Rewrite addresses that match lhs to
55 ** Mn arg=val... Define mailer. n is the internal name.
56 ** Args specify mailer parameters.
57 ** Oxvalue Set option x to value.
58 ** O option value Set option (long name) to value.
59 ** Pname=value Set precedence name to value.
60 ** Qn arg=val... Define queue groups. n is the internal name.
61 ** Args specify queue parameters.
62 ** Vversioncode[/vendorcode]
63 ** Version level/vendor name of
64 ** configuration syntax.
65 ** Kmapname mapclass arguments....
66 ** Define keyed lookup of a given class.
67 ** Arguments are class dependent.
68 ** Eenvar=value Set the environment value to the given value.
71 ** cfname -- configuration file name.
72 ** safe -- true if this is the system config file;
74 ** e -- the main envelope.
80 ** Builds several internal tables.
84 readcf(cfname, safe, e)
92 struct rewrite *rwp = NULL;
102 long sff = SFF_OPENASROOT;
106 char pvpbuf[MAXLINE + MAXATOM];
107 static char *null_list[1] = { NULL };
108 extern unsigned char TokTypeNoC[];
113 if (DontLockReadFiles)
115 cf = safefopen(cfname, O_RDONLY, 0444, sff);
118 syserr("cannot open");
119 finis(false, true, EX_OSFILE);
122 if (fstat(sm_io_getinfo(cf, SM_IO_WHAT_FD, NULL), &statb) < 0)
124 syserr("cannot fstat");
125 finis(false, true, EX_OSFILE);
128 if (!S_ISREG(statb.st_mode))
130 syserr("not a plain file");
131 finis(false, true, EX_OSFILE);
134 if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
136 if (OpMode == MD_DAEMON || OpMode == MD_INITALIAS)
137 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
138 "%s: WARNING: dangerous write permissions\n",
141 sm_syslog(LOG_CRIT, NOQID,
142 "%s: WARNING: dangerous write permissions",
150 while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL)
155 sm_free(bp); /* XXX */
159 /* do macro expansion mappings */
160 translate_dollars(bp);
162 /* interpret this line */
167 case '#': /* comment */
170 case 'R': /* rewriting rule */
173 syserr("missing valid ruleset for \"%s\"", bp);
176 for (p = &bp[1]; *p != '\0' && *p != '\t'; p++)
181 syserr("invalid rewrite line \"%s\" (tab expected)", bp);
185 /* allocate space for the rule header */
188 RewriteRules[ruleset] = rwp =
189 (struct rewrite *) xalloc(sizeof *rwp);
193 rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
198 /* expand and save the LHS */
200 expand(&bp[1], exbuf, sizeof exbuf, e);
201 rwp->r_lhs = prescan(exbuf, '\t', pvpbuf,
203 ConfigLevel >= 9 ? TokTypeNoC : NULL);
205 if (rwp->r_lhs != NULL)
209 rwp->r_lhs = copyplist(rwp->r_lhs, true, NULL);
211 /* count the number of fuzzy matches in LHS */
212 for (ap = rwp->r_lhs; *ap != NULL; ap++)
264 syserr("Inappropriate use of %s on LHS",
267 rwp->r_line = LineNumber;
271 syserr("R line: null LHS");
272 rwp->r_lhs = null_list;
274 if (nfuzzy > MAXMATCH)
276 syserr("R line: too many wildcards");
277 rwp->r_lhs = null_list;
280 /* expand and save the RHS */
284 while (*p != '\0' && *p != '\t')
287 expand(q, exbuf, sizeof exbuf, e);
288 rwp->r_rhs = prescan(exbuf, '\t', pvpbuf,
290 ConfigLevel >= 9 ? TokTypeNoC : NULL);
291 if (rwp->r_rhs != NULL)
295 #if _FFR_EXTRA_MAP_CHECK
297 #endif /* _FFR_EXTRA_MAP_CHECK */
300 rwp->r_rhs = copyplist(rwp->r_rhs, true, NULL);
302 /* check no out-of-bounds replacements */
307 for (ap = rwp->r_rhs; *ap != NULL; ap++)
315 if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy)
317 syserr("replacement $%c out of bounds",
345 if (++args >= MAX_MAP_ARGS)
346 syserr("too many arguments for map lookup");
354 if ((**ap & 0377) == LOOKUPBEGIN)
355 endtoken = LOOKUPEND;
357 syserr("cannot nest map lookups");
360 #if _FFR_EXTRA_MAP_CHECK
361 if (*(ap + 1) == NULL)
363 syserr("syntax error in map lookup");
366 nexttoken = **(ap + 1) & 0377;
367 if (nexttoken == CANONHOST ||
368 nexttoken == CANONUSER ||
369 nexttoken == endtoken)
371 syserr("missing map name for lookup");
374 if (*(ap + 2) == NULL)
376 syserr("syntax error in map lookup");
379 if ((**ap & 0377) == HOSTBEGIN)
381 nexttoken = **(ap + 2) & 0377;
382 if (nexttoken == CANONHOST ||
383 nexttoken == CANONUSER ||
384 nexttoken == endtoken)
386 syserr("missing key name for lookup");
389 #endif /* _FFR_EXTRA_MAP_CHECK */
394 if ((**ap & 0377) != endtoken)
403 ** This doesn't work yet as there are maps defined *after* the cf
404 ** is read such as host, user, and alias. So for now, it's removed.
405 ** When it comes back, the RELEASE_NOTES entry will be:
406 ** Emit warnings for unknown maps when reading the .cf file. Based on
407 ** patch from Robert Harker of Harker Systems.
412 ** Got a database lookup,
413 ** check if map is defined.
417 if ((*ep & 0377) != MACRODEXPAND &&
421 (void) sm_io_fprintf(smioout,
423 "Warning: %s: line %d: map %s not found\n",
432 syserr("Inappropriate use of %s on RHS",
436 syserr("missing map closing token");
440 syserr("R line: null RHS");
441 rwp->r_rhs = null_list;
445 case 'S': /* select rewriting set */
446 expand(&bp[1], exbuf, sizeof exbuf, e);
447 ruleset = strtorwset(exbuf, NULL, ST_ENTER);
451 rwp = RewriteRules[ruleset];
454 if (OpMode == MD_TEST)
455 (void) sm_io_fprintf(smioout,
457 "WARNING: Ruleset %s has multiple definitions\n",
460 sm_dprintf("WARNING: Ruleset %s has multiple definitions\n",
462 while (rwp->r_next != NULL)
467 case 'D': /* macro definition */
468 mid = macid_parse(&bp[1], &ep);
471 p = munchstring(ep, NULL, '\0');
472 macdefine(&e->e_macro, A_TEMP, mid, p);
475 case 'H': /* required header line */
476 (void) chompheader(&bp[1], CHHDR_DEF, NULL, e);
479 case 'C': /* word class */
480 case 'T': /* trusted user (set class `t') */
483 mid = macid_parse(&bp[1], &ep);
486 expand(ep, exbuf, sizeof exbuf, e);
499 while (*p != '\0' && isascii(*p) && isspace(*p))
502 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
512 case 'F': /* word class from file */
513 mid = macid_parse(&bp[1], &ep);
516 for (p = ep; isascii(*p) && isspace(*p); )
518 if (p[0] == '-' && p[1] == 'o')
522 !(isascii(*p) && isspace(*p)))
524 while (isascii(*p) && isspace(*p))
531 /* check if [key]@map:spec */
533 if (!SM_IS_DIR_DELIM(*p) &&
535 (q = strchr(p, '@')) != NULL)
539 /* look for @LDAP or @map: in string */
540 if (strcmp(q, "LDAP") == 0 ||
542 strchr(q, ':') != NULL))
548 /* use entire spec */
553 file = extrquotstr(p, &q, " ", &ok);
556 syserr("illegal filename '%s'", p);
561 if (*file == '|' || ismap)
571 while (isascii(*++p) && isspace(*p))
575 fileclass(mid, file, p, ismap, safe, optional);
579 case 'L': /* extended load average description */
584 #if defined(SUN_EXTENSIONS) && defined(SUN_LOOKUP_MACRO)
585 case 'L': /* lookup macro */
586 case 'G': /* lookup class */
587 /* reserved for Sun -- NIS+ database lookup */
588 if (VendorCode != VENDOR_SUN)
590 sun_lg_config_line(bp, e);
592 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_LOOKUP_MACRO) */
594 case 'M': /* define mailer */
598 case 'O': /* set option */
599 setoption(bp[1], &bp[2], safe, false, e);
602 case 'P': /* set precedence */
603 if (NumPriorities >= MAXPRIORITIES)
605 toomany('P', MAXPRIORITIES);
608 for (p = &bp[1]; *p != '\0' && *p != '='; p++)
613 Priorities[NumPriorities].pri_name = newstr(&bp[1]);
614 Priorities[NumPriorities].pri_val = atoi(++p);
618 case 'Q': /* define queue */
619 makequeue(&bp[1], true);
622 case 'V': /* configuration syntax version */
623 for (p = &bp[1]; isascii(*p) && isspace(*p); p++)
625 if (!isascii(*p) || !isdigit(*p))
627 syserr("invalid argument to V line: \"%.20s\"",
631 ConfigLevel = strtol(p, &ep, 10);
634 ** Do heuristic tweaking for back compatibility.
637 if (ConfigLevel >= 5)
639 /* level 5 configs have short name in $w */
640 p = macvalue('w', e);
641 if (p != NULL && (p = strchr(p, '.')) != NULL)
644 macdefine(&e->e_macro, A_TEMP, 'w',
648 if (ConfigLevel >= 6)
650 ColonOkInAddr = false;
654 ** Look for vendor code.
659 /* extract vendor code */
660 for (p = ep; isascii(*p) && isalpha(*p); )
665 syserr("invalid V line vendor code: \"%s\"",
671 expand(&bp[1], exbuf, sizeof exbuf, e);
672 (void) makemapentry(exbuf);
679 setuserenv(&bp[1], p);
682 case 'X': /* mail filter */
684 milter_setup(&bp[1]);
686 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
687 "Warning: Filter usage ('X') requires Milter support (-DMILTER)\n");
693 syserr("unknown configuration line \"%s\"", bp);
696 sm_free(bp); /* XXX */
700 syserr("I/O read error");
701 finis(false, true, EX_OSFILE);
703 (void) sm_io_close(cf, SM_TIME_DEFAULT);
706 /* initialize host maps from local service tables */
709 /* initialize daemon (if not defined yet) */
712 /* determine if we need to do special name-server frotz */
715 char *maptype[MAXMAPSTACK];
716 short mapreturn[MAXMAPACTIONS];
718 nmaps = switch_map_find("hosts", maptype, mapreturn);
719 UseNameServer = false;
720 if (nmaps > 0 && nmaps <= MAXMAPSTACK)
724 for (mapno = 0; mapno < nmaps && !UseNameServer;
727 if (strcmp(maptype[mapno], "dns") == 0)
728 UseNameServer = true;
734 ** TRANSLATE_DOLLARS -- convert $x into internal form
736 ** Actually does all appropriate pre-processing of a config line
737 ** to turn it into internal form.
740 ** bp -- the buffer to translate.
743 ** None. The buffer is translated in place. Since the
744 ** translations always make the buffer shorter, this is
745 ** safe without a size parameter.
749 translate_dollars(bp)
755 for (p = bp; *p != '\0'; p++)
757 if (*p == '#' && p > bp && ConfigLevel >= 3)
764 /* it's from $# -- let it go through */
769 /* it's backslash escaped */
770 (void) sm_strlcpy(p, p + 1, strlen(p));
774 /* delete leading white space */
775 while (isascii(*p) && isspace(*p) &&
776 *p != '\n' && p > bp)
778 if ((e = strchr(++p, '\n')) != NULL)
779 (void) sm_strlcpy(p, e, strlen(p));
787 if (*p != '$' || p[1] == '\0')
792 /* actual dollar sign.... */
793 (void) sm_strlcpy(p, p + 1, strlen(p));
797 /* convert to macro expansion character */
800 /* special handling for $=, $~, $&, and $? */
801 if (*p == '=' || *p == '~' || *p == '&' || *p == '?')
804 /* convert macro name to code */
805 *p = macid_parse(p, &ep);
807 (void) sm_strlcpy(p + 1, ep, strlen(p + 1));
810 /* strip trailing white space from the line */
811 while (--p > bp && isascii(*p) && isspace(*p))
815 ** TOOMANY -- signal too many of some option
818 ** id -- the id of the error line
819 ** maxcnt -- the maximum possible values
833 syserr("too many %c lines, %d max", id, maxcnt);
836 ** FILECLASS -- read members of a class from a file
839 ** class -- class to define.
840 ** filename -- name of file to read.
841 ** fmt -- scanf string to use for match.
842 ** ismap -- if set, this is a map lookup.
843 ** safe -- if set, this is a safe read.
844 ** optional -- if set, it is not an error for the file to
851 ** puts all lines in filename that match a scanf into
856 ** Break up the match into words and add to class.
860 parse_class_words(class, line)
864 while (line != NULL && *line != '\0')
868 /* strip leading spaces */
869 while (isascii(*line) && isspace(*line))
874 /* find the end of the word */
876 while (*line != '\0' && !(isascii(*line) && isspace(*line)))
881 /* enter the word in the symbol table */
887 fileclass(class, filename, fmt, ismap, safe, optional)
902 sm_dprintf("fileclass(%s, fmt=%s)\n", filename, fmt);
904 if (*filename == '\0')
906 syserr("fileclass: missing file name");
918 mn = newstr(macname(class));
923 if ((p = strchr(filename, '@')) == NULL)
925 /* should not happen */
926 syserr("fileclass: bogus map specification");
936 if (strcmp(cl, "LDAP") == 0)
940 char jbuf[MAXHOSTNAMELEN];
944 expand("\201j", jbuf, sizeof jbuf, &BlankEnvelope);
947 (void) sm_strlcpy(jbuf, "localhost",
951 /* impose the default schema */
952 lc = macvalue(macid("{sendmailMTACluster}"), CurEnv);
957 expand(lc, lcbuf, sizeof lcbuf, CurEnv);
962 n = sm_snprintf(buf, sizeof buf,
963 "-k (&(objectClass=sendmailMTAClass)(sendmailMTAClassName=%s)(|(sendmailMTACluster=%s)(sendmailMTAHost=%s))) -v sendmailMTAClassValue",
967 syserr("fileclass: F{%s}: Default LDAP string too long",
977 if ((spec = strchr(cl, ':')) == NULL)
979 syserr("fileclass: F{%s}: missing map class",
987 /* set up map structure */
988 mapclass = stab(cl, ST_MAPCLASS, ST_FIND);
989 if (mapclass == NULL)
991 syserr("fileclass: F{%s}: class %s not available",
996 memset(&map, '\0', sizeof map);
997 map.map_class = &mapclass->s_mapclass;
999 map.map_mflags |= MF_FILECLASS;
1002 sm_dprintf("fileclass: F{%s}: map class %s, key %s, spec %s\n",
1006 /* parse map spec */
1007 if (!map.map_class->map_parse(&map, spec))
1009 /* map_parse() showed the error already */
1013 map.map_mflags |= MF_VALID;
1016 if (map.map_class->map_open(&map, O_RDONLY))
1018 map.map_mflags |= MF_OPEN;
1019 map.map_pid = getpid();
1024 !bitset(MF_OPTIONAL, map.map_mflags))
1025 syserr("fileclass: F{%s}: map open failed",
1032 p = (*map.map_class->map_lookup)(&map, key, NULL, &status);
1033 if (status != EX_OK && status != EX_NOTFOUND)
1036 syserr("fileclass: F{%s}: map lookup failed",
1041 /* use the results */
1043 parse_class_words(class, p);
1046 map.map_mflags |= MF_CLOSING;
1047 map.map_class->map_close(&map);
1048 map.map_mflags &= ~(MF_OPEN|MF_WRITABLE|MF_CLOSING);
1052 else if (filename[0] == '|')
1056 char *argv[MAXPV + 1];
1059 for (p = strtok(&filename[1], " \t");
1060 p != NULL && i < MAXPV;
1061 p = strtok(NULL, " \t"))
1064 pid = prog_open(argv, &fd, CurEnv);
1068 f = sm_io_open(SmFtStdiofd, SM_TIME_DEFAULT,
1069 (void *) &fd, SM_IO_RDONLY, NULL);
1075 if (!bitnset(DBS_CLASSFILEINUNSAFEDIRPATH, DontBlameSendmail))
1076 sff |= SFF_SAFEDIRPATH;
1077 if (!bitnset(DBS_LINKEDCLASSFILEINWRITABLEDIR,
1081 sff |= SFF_OPENASROOT;
1082 else if (RealUid == 0)
1084 if (DontLockReadFiles)
1086 f = safefopen(filename, O_RDONLY, 0, sff);
1091 syserr("fileclass: cannot open '%s'", filename);
1095 while (sm_io_fgets(f, SM_TIME_DEFAULT, buf, sizeof buf) != NULL)
1098 char wordbuf[MAXLINE + 1];
1104 if (sm_io_sscanf(buf, fmt, wordbuf) != 1)
1111 parse_class_words(class, p);
1114 ** If anything else is added here,
1115 ** check if the '@' map case above
1116 ** needs the code as well.
1120 (void) sm_io_close(f, SM_TIME_DEFAULT);
1122 (void) waitfor(pid);
1125 ** MAKEMAILER -- define a new mailer.
1128 ** line -- description of mailer. This is in labeled
1129 ** fields. The fields are:
1130 ** A -- the argv for this mailer
1131 ** C -- the character set for MIME conversions
1132 ** D -- the directory to run in
1133 ** E -- the eol string
1134 ** F -- the flags associated with the mailer
1135 ** L -- the maximum line length
1136 ** M -- the maximum message size
1137 ** N -- the niceness at which to run
1138 ** P -- the path to the mailer
1139 ** Q -- the queue group for the mailer
1140 ** R -- the recipient rewriting set
1141 ** S -- the sender rewriting set
1142 ** T -- the mailer type (for DSNs)
1143 ** U -- the uid to run as
1144 ** W -- the time to wait at the end
1145 ** m -- maximum messages per connection
1146 ** r -- maximum number of recipients per message
1147 ** / -- new root directory
1148 ** The first word is the canonical name of the mailer.
1154 ** enters the mailer into the mailer table.
1162 register struct mailer *m;
1167 static int nextmailer = 0; /* "free" index into Mailer struct */
1169 /* allocate a mailer and set up defaults */
1170 m = (struct mailer *) xalloc(sizeof *m);
1171 memset((char *) m, '\0', sizeof *m);
1172 errno = 0; /* avoid bogus error text */
1174 /* collect the mailer name */
1176 *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p));
1181 if (line[0] == '\0')
1183 syserr("name required for mailer");
1186 m->m_name = newstr(line);
1189 /* now scan through and assign info from the fields */
1192 auto char *delimptr;
1194 while (*p != '\0' &&
1195 (*p == ',' || (isascii(*p) && isspace(*p))))
1198 /* p now points to field code */
1200 while (*p != '\0' && *p != '=' && *p != ',')
1204 syserr("mailer %s: `=' expected", m->m_name);
1207 while (isascii(*p) && isspace(*p))
1210 /* p now points to the field body */
1211 p = munchstring(p, &delimptr, ',');
1213 /* install the field into the mailer struct */
1216 case 'P': /* pathname */
1217 if (*p != '\0') /* error is issued below */
1218 m->m_mailer = newstr(p);
1221 case 'F': /* flags */
1222 for (; *p != '\0'; p++)
1224 if (!(isascii(*p) && isspace(*p)))
1226 #if _FFR_DEPRECATE_MAILER_FLAG_I
1227 if (*p == M_INTERNAL)
1228 sm_syslog(LOG_WARNING, NOQID,
1229 "WARNING: mailer=%s, flag=%c deprecated",
1231 #endif /* _FFR_DEPRECATE_MAILER_FLAG_I */
1232 setbitn(bitidx(*p), m->m_flags);
1237 case 'S': /* sender rewriting ruleset */
1238 case 'R': /* recipient rewriting ruleset */
1239 i = strtorwset(p, &endp, ST_ENTER);
1243 m->m_sh_rwset = m->m_se_rwset = i;
1245 m->m_rh_rwset = m->m_re_rwset = i;
1250 i = strtorwset(p, NULL, ST_ENTER);
1260 case 'E': /* end of line string */
1262 syserr("mailer %s: null end-of-line string",
1265 m->m_eol = newstr(p);
1268 case 'A': /* argument vector */
1269 if (*p != '\0') /* error is issued below */
1270 m->m_argv = makeargv(p);
1273 case 'M': /* maximum message size */
1274 m->m_maxsize = atol(p);
1277 case 'm': /* maximum messages per connection */
1278 m->m_maxdeliveries = atoi(p);
1281 case 'r': /* max recipient per envelope */
1282 m->m_maxrcpt = atoi(p);
1285 case 'L': /* maximum line length */
1286 m->m_linelimit = atoi(p);
1287 if (m->m_linelimit < 0)
1291 case 'N': /* run niceness */
1292 m->m_nice = atoi(p);
1295 case 'D': /* working directory */
1297 syserr("mailer %s: null working directory",
1300 m->m_execdir = newstr(p);
1303 case 'C': /* default charset */
1305 syserr("mailer %s: null charset", m->m_name);
1307 m->m_defcharset = newstr(p);
1310 case 'Q': /* queue for this mailer */
1313 syserr("mailer %s: null queue", m->m_name);
1316 s = stab(p, ST_QUEUE, ST_FIND);
1318 syserr("mailer %s: unknown queue %s",
1321 m->m_qgrp = s->s_quegrp->qg_index;
1324 case 'T': /* MTA-Name/Address/Diagnostic types */
1325 /* extract MTA name type; default to "dns" */
1326 m->m_mtatype = newstr(p);
1327 p = strchr(m->m_mtatype, '/');
1334 if (*m->m_mtatype == '\0')
1335 m->m_mtatype = "dns";
1337 /* extract address type; default to "rfc822" */
1347 if (m->m_addrtype == NULL || *m->m_addrtype == '\0')
1348 m->m_addrtype = "rfc822";
1350 /* extract diagnostic type; default to "smtp" */
1352 if (m->m_diagtype == NULL || *m->m_diagtype == '\0')
1353 m->m_diagtype = "smtp";
1356 case 'U': /* user id */
1357 if (isascii(*p) && !isdigit(*p))
1362 while (*p != '\0' && isascii(*p) &&
1363 (isalnum(*p) || strchr("-_", *p) != NULL))
1365 while (isascii(*p) && isspace(*p))
1371 syserr("mailer %s: null user name",
1375 pw = sm_getpwnam(q);
1378 syserr("readcf: mailer U= flag: unknown user %s", q);
1383 m->m_uid = pw->pw_uid;
1384 m->m_gid = pw->pw_gid;
1391 m->m_uid = strtol(p, &q, 0);
1393 while (isascii(*p) && isspace(*p))
1398 while (isascii(*p) && isspace(*p))
1402 if (isascii(*p) && !isdigit(*p))
1407 while (isascii(*p) && isalnum(*p))
1412 syserr("mailer %s: null group name",
1419 syserr("readcf: mailer U= flag: unknown group %s", q);
1423 m->m_gid = gr->gr_gid;
1427 m->m_gid = strtol(p, NULL, 0);
1431 case 'W': /* wait timeout */
1432 m->m_wait = convtime(p, 's');
1435 case '/': /* new root directory */
1437 syserr("mailer %s: null root directory",
1440 m->m_rootdir = newstr(p);
1444 syserr("M%s: unknown mailer equate %c=",
1453 if (bitnset(M_SECURE_PORT, m->m_flags))
1455 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1456 "M%s: Warning: F=%c set on system that doesn't support rresvport()\n",
1457 m->m_name, M_SECURE_PORT);
1459 #endif /* !HASRRESVPORT */
1464 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1465 "M%s: Warning: N= set on system that doesn't support nice()\n",
1468 #endif /* !HASNICE */
1470 /* do some rationality checking */
1471 if (m->m_argv == NULL)
1473 syserr("M%s: A= argument required", m->m_name);
1476 if (m->m_mailer == NULL)
1478 syserr("M%s: P= argument required", m->m_name);
1482 if (nextmailer >= MAXMAILERS)
1484 syserr("too many mailers defined (%d max)", MAXMAILERS);
1488 if (m->m_maxrcpt <= 0)
1489 m->m_maxrcpt = DEFAULT_MAX_RCPT;
1491 /* do some heuristic cleanup for back compatibility */
1492 if (bitnset(M_LIMITS, m->m_flags))
1494 if (m->m_linelimit == 0)
1495 m->m_linelimit = SMTPLINELIM;
1496 if (ConfigLevel < 2)
1497 setbitn(M_7BITS, m->m_flags);
1500 if (strcmp(m->m_mailer, "[TCP]") == 0)
1502 syserr("M%s: P=[TCP] must be replaced by P=[IPC]", m->m_name);
1506 if (strcmp(m->m_mailer, "[IPC]") == 0)
1508 /* Use the second argument for host or path to socket */
1509 if (m->m_argv[0] == NULL || m->m_argv[1] == NULL ||
1510 m->m_argv[1][0] == '\0')
1512 syserr("M%s: too few parameters for %s mailer",
1513 m->m_name, m->m_mailer);
1516 if (strcmp(m->m_argv[0], "TCP") != 0
1518 && strcmp(m->m_argv[0], "FILE") != 0
1519 #endif /* NETUNIX */
1522 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1523 "M%s: Warning: first argument in %s mailer must be %s\n",
1524 m->m_name, m->m_mailer,
1529 #endif /* NETUNIX */
1532 if (m->m_mtatype == NULL)
1533 m->m_mtatype = "dns";
1534 if (m->m_addrtype == NULL)
1535 m->m_addrtype = "rfc822";
1536 if (m->m_diagtype == NULL)
1538 if (m->m_argv[0] != NULL &&
1539 strcmp(m->m_argv[0], "FILE") == 0)
1540 m->m_diagtype = "x-unix";
1542 m->m_diagtype = "smtp";
1545 else if (strcmp(m->m_mailer, "[FILE]") == 0)
1547 /* Use the second argument for filename */
1548 if (m->m_argv[0] == NULL || m->m_argv[1] == NULL ||
1549 m->m_argv[2] != NULL)
1551 syserr("M%s: too %s parameters for [FILE] mailer",
1553 (m->m_argv[0] == NULL ||
1554 m->m_argv[1] == NULL) ? "few" : "many");
1557 else if (strcmp(m->m_argv[0], "FILE") != 0)
1559 syserr("M%s: first argument in [FILE] mailer must be FILE",
1565 if (m->m_eol == NULL)
1569 /* default for SMTP is \r\n; use \n for local delivery */
1570 for (pp = m->m_argv; *pp != NULL; pp++)
1572 for (p = *pp; *p != '\0'; )
1574 if ((*p++ & 0377) == MACROEXPAND && *p == 'u')
1586 /* enter the mailer into the symbol table */
1587 s = stab(m->m_name, ST_MAILER, ST_ENTER);
1588 if (s->s_mailer != NULL)
1590 i = s->s_mailer->m_mno;
1591 sm_free(s->s_mailer); /* XXX */
1597 Mailer[i] = s->s_mailer = m;
1601 ** MUNCHSTRING -- translate a string into internal form.
1604 ** p -- the string to munch.
1605 ** delimptr -- if non-NULL, set to the pointer of the
1606 ** field delimiter character.
1607 ** delim -- the delimiter for the field.
1610 ** the munched string.
1613 ** the munched string is a local static buffer.
1614 ** it must be copied before the function is called again.
1618 munchstring(p, delimptr, delim)
1624 bool backslash = false;
1625 bool quotemode = false;
1626 static char buf[MAXLINE];
1628 for (q = buf; *p != '\0' && q < &buf[sizeof buf - 1]; p++)
1632 /* everything is roughly literal */
1636 case 'r': /* carriage return */
1640 case 'n': /* newline */
1644 case 'f': /* form feed */
1648 case 'b': /* backspace */
1659 quotemode = !quotemode;
1660 else if (quotemode || *p != delim)
1667 if (delimptr != NULL)
1673 ** EXTRQUOTSTR -- extract a (quoted) string.
1675 ** This routine deals with quoted (") strings and escaped
1679 ** p -- source string.
1680 ** delimptr -- if non-NULL, set to the pointer of the
1681 ** field delimiter character.
1682 ** delimbuf -- delimiters for the field.
1683 ** st -- if non-NULL, store the return value (whether the
1684 ** string was correctly quoted) here.
1687 ** the extracted string.
1690 ** the returned string is a local static buffer.
1691 ** it must be copied before the function is called again.
1695 extrquotstr(p, delimptr, delimbuf, st)
1702 bool backslash = false;
1703 bool quotemode = false;
1704 static char buf[MAXLINE];
1706 for (q = buf; *p != '\0' && q < &buf[sizeof buf - 1]; p++)
1717 quotemode = !quotemode;
1718 else if (quotemode ||
1719 strchr(delimbuf, (int) *p) == NULL)
1725 if (delimptr != NULL)
1729 *st = !(quotemode || backslash);
1733 ** MAKEARGV -- break up a string into words
1736 ** p -- the string to break up.
1739 ** a char **argv (dynamically allocated)
1752 char *argv[MAXPV + 1];
1754 /* take apart the words */
1756 while (*p != '\0' && i < MAXPV)
1759 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
1761 while (isascii(*p) && isspace(*p))
1763 argv[i++] = newstr(q);
1767 /* now make a copy of the argv */
1768 avp = (char **) xalloc(sizeof *avp * i);
1769 memmove((char *) avp, (char *) argv, sizeof *avp * i);
1774 ** PRINTRULES -- print rewrite rules (for debugging)
1783 ** prints rewrite rules.
1789 register struct rewrite *rwp;
1790 register int ruleset;
1792 for (ruleset = 0; ruleset < 10; ruleset++)
1794 if (RewriteRules[ruleset] == NULL)
1796 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1797 "\n----Rule Set %d:", ruleset);
1799 for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
1801 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1803 printav(rwp->r_lhs);
1804 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1806 printav(rwp->r_rhs);
1811 ** PRINTMAILER -- print mailer structure (for debugging)
1814 ** m -- the mailer to print
1826 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1827 "mailer %d (%s): P=%s S=", m->m_mno, m->m_name,
1829 if (RuleSetNames[m->m_se_rwset] == NULL)
1830 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "%d/",
1833 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "%s/",
1834 RuleSetNames[m->m_se_rwset]);
1835 if (RuleSetNames[m->m_sh_rwset] == NULL)
1836 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "%d R=",
1839 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "%s R=",
1840 RuleSetNames[m->m_sh_rwset]);
1841 if (RuleSetNames[m->m_re_rwset] == NULL)
1842 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "%d/",
1845 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "%s/",
1846 RuleSetNames[m->m_re_rwset]);
1847 if (RuleSetNames[m->m_rh_rwset] == NULL)
1848 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "%d ",
1851 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "%s ",
1852 RuleSetNames[m->m_rh_rwset]);
1853 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "M=%ld U=%d:%d F=",
1854 m->m_maxsize, (int) m->m_uid, (int) m->m_gid);
1855 for (j = '\0'; j <= '\177'; j++)
1856 if (bitnset(j, m->m_flags))
1857 (void) sm_io_putc(smioout, SM_TIME_DEFAULT, j);
1858 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, " L=%d E=",
1861 if (m->m_defcharset != NULL)
1862 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, " C=%s",
1864 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, " T=%s/%s/%s",
1865 m->m_mtatype == NULL
1866 ? "<undefined>" : m->m_mtatype,
1867 m->m_addrtype == NULL
1868 ? "<undefined>" : m->m_addrtype,
1869 m->m_diagtype == NULL
1870 ? "<undefined>" : m->m_diagtype);
1871 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, " r=%d", m->m_maxrcpt);
1872 if (m->m_argv != NULL)
1874 char **a = m->m_argv;
1876 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, " A=");
1880 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1885 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "\n");
1888 ** SETOPTION -- set global processing option
1891 ** opt -- option name.
1892 ** val -- option value (as a text string).
1893 ** safe -- set if this came from a configuration file.
1894 ** Some options (if set from the command line) will
1895 ** reset the user id to avoid security problems.
1896 ** sticky -- if set, don't let other setoptions override
1898 ** e -- the main envelope.
1904 ** Sets options as implied by the arguments.
1907 static BITMAP256 StickyOpt; /* set if option is stuck */
1911 static struct resolverflags
1913 char *rf_name; /* name of the flag */
1914 long rf_bits; /* bits to set/clear */
1917 { "debug", RES_DEBUG },
1918 { "aaonly", RES_AAONLY },
1919 { "usevc", RES_USEVC },
1920 { "primary", RES_PRIMARY },
1921 { "igntc", RES_IGNTC },
1922 { "recurse", RES_RECURSE },
1923 { "defnames", RES_DEFNAMES },
1924 { "stayopen", RES_STAYOPEN },
1925 { "dnsrch", RES_DNSRCH },
1926 # ifdef RES_USE_INET6
1927 { "use_inet6", RES_USE_INET6 },
1928 # endif /* RES_USE_INET6 */
1929 { "true", 0 }, /* avoid error on old syntax */
1933 #endif /* NAMED_BIND */
1935 #define OI_NONE 0 /* no special treatment */
1936 #define OI_SAFE 0x0001 /* safe for random people to use */
1937 #define OI_SUBOPT 0x0002 /* option has suboptions */
1939 static struct optioninfo
1941 char *o_name; /* long name of option */
1942 unsigned char o_code; /* short name of option */
1943 unsigned short o_flags; /* option flags */
1946 #if defined(SUN_EXTENSIONS) && defined(REMOTE_MODE)
1947 { "RemoteMode", '>', OI_NONE },
1948 #endif /* defined(SUN_EXTENSIONS) && defined(REMOTE_MODE) */
1949 { "SevenBitInput", '7', OI_SAFE },
1950 { "EightBitMode", '8', OI_SAFE },
1951 { "AliasFile", 'A', OI_NONE },
1952 { "AliasWait", 'a', OI_NONE },
1953 { "BlankSub", 'B', OI_NONE },
1954 { "MinFreeBlocks", 'b', OI_SAFE },
1955 { "CheckpointInterval", 'C', OI_SAFE },
1956 { "HoldExpensive", 'c', OI_NONE },
1957 { "DeliveryMode", 'd', OI_SAFE },
1958 { "ErrorHeader", 'E', OI_NONE },
1959 { "ErrorMode", 'e', OI_SAFE },
1960 { "TempFileMode", 'F', OI_NONE },
1961 { "SaveFromLine", 'f', OI_NONE },
1962 { "MatchGECOS", 'G', OI_NONE },
1964 /* no long name, just here to avoid problems in setoption */
1965 { "", 'g', OI_NONE },
1966 { "HelpFile", 'H', OI_NONE },
1967 { "MaxHopCount", 'h', OI_NONE },
1968 { "ResolverOptions", 'I', OI_NONE },
1969 { "IgnoreDots", 'i', OI_SAFE },
1970 { "ForwardPath", 'J', OI_NONE },
1971 { "SendMimeErrors", 'j', OI_SAFE },
1972 { "ConnectionCacheSize", 'k', OI_NONE },
1973 { "ConnectionCacheTimeout", 'K', OI_NONE },
1974 { "UseErrorsTo", 'l', OI_NONE },
1975 { "LogLevel", 'L', OI_SAFE },
1976 { "MeToo", 'm', OI_SAFE },
1978 /* no long name, just here to avoid problems in setoption */
1979 { "", 'M', OI_NONE },
1980 { "CheckAliases", 'n', OI_NONE },
1981 { "OldStyleHeaders", 'o', OI_SAFE },
1982 { "DaemonPortOptions", 'O', OI_NONE },
1983 { "PrivacyOptions", 'p', OI_SAFE },
1984 { "PostmasterCopy", 'P', OI_NONE },
1985 { "QueueFactor", 'q', OI_NONE },
1986 { "QueueDirectory", 'Q', OI_NONE },
1987 { "DontPruneRoutes", 'R', OI_NONE },
1988 { "Timeout", 'r', OI_SUBOPT },
1989 { "StatusFile", 'S', OI_NONE },
1990 { "SuperSafe", 's', OI_SAFE },
1991 { "QueueTimeout", 'T', OI_NONE },
1992 { "TimeZoneSpec", 't', OI_NONE },
1993 { "UserDatabaseSpec", 'U', OI_NONE },
1994 { "DefaultUser", 'u', OI_NONE },
1995 { "FallbackMXhost", 'V', OI_NONE },
1996 { "Verbose", 'v', OI_SAFE },
1997 { "TryNullMXList", 'w', OI_NONE },
1998 { "QueueLA", 'x', OI_NONE },
1999 { "RefuseLA", 'X', OI_NONE },
2000 { "RecipientFactor", 'y', OI_NONE },
2001 { "ForkEachJob", 'Y', OI_NONE },
2002 { "ClassFactor", 'z', OI_NONE },
2003 { "RetryFactor", 'Z', OI_NONE },
2004 #define O_QUEUESORTORD 0x81
2005 { "QueueSortOrder", O_QUEUESORTORD, OI_SAFE },
2006 #define O_HOSTSFILE 0x82
2007 { "HostsFile", O_HOSTSFILE, OI_NONE },
2009 { "MinQueueAge", O_MQA, OI_SAFE },
2010 #define O_DEFCHARSET 0x85
2011 { "DefaultCharSet", O_DEFCHARSET, OI_SAFE },
2012 #define O_SSFILE 0x86
2013 { "ServiceSwitchFile", O_SSFILE, OI_NONE },
2014 #define O_DIALDELAY 0x87
2015 { "DialDelay", O_DIALDELAY, OI_SAFE },
2016 #define O_NORCPTACTION 0x88
2017 { "NoRecipientAction", O_NORCPTACTION, OI_SAFE },
2018 #define O_SAFEFILEENV 0x89
2019 { "SafeFileEnvironment", O_SAFEFILEENV, OI_NONE },
2020 #define O_MAXMSGSIZE 0x8a
2021 { "MaxMessageSize", O_MAXMSGSIZE, OI_NONE },
2022 #define O_COLONOKINADDR 0x8b
2023 { "ColonOkInAddr", O_COLONOKINADDR, OI_SAFE },
2024 #define O_MAXQUEUERUN 0x8c
2025 { "MaxQueueRunSize", O_MAXQUEUERUN, OI_SAFE },
2026 #define O_MAXCHILDREN 0x8d
2027 { "MaxDaemonChildren", O_MAXCHILDREN, OI_NONE },
2028 #define O_KEEPCNAMES 0x8e
2029 { "DontExpandCnames", O_KEEPCNAMES, OI_NONE },
2030 #define O_MUSTQUOTE 0x8f
2031 { "MustQuoteChars", O_MUSTQUOTE, OI_NONE },
2032 #define O_SMTPGREETING 0x90
2033 { "SmtpGreetingMessage", O_SMTPGREETING, OI_NONE },
2034 #define O_UNIXFROM 0x91
2035 { "UnixFromLine", O_UNIXFROM, OI_NONE },
2036 #define O_OPCHARS 0x92
2037 { "OperatorChars", O_OPCHARS, OI_NONE },
2038 #define O_DONTINITGRPS 0x93
2039 { "DontInitGroups", O_DONTINITGRPS, OI_NONE },
2041 { "SingleLineFromHeader", O_SLFH, OI_SAFE },
2043 { "AllowBogusHELO", O_ABH, OI_SAFE },
2044 #define O_CONNTHROT 0x97
2045 { "ConnectionRateThrottle", O_CONNTHROT, OI_NONE },
2047 { "UnsafeGroupWrites", O_UGW, OI_NONE },
2048 #define O_DBLBOUNCE 0x9a
2049 { "DoubleBounceAddress", O_DBLBOUNCE, OI_NONE },
2050 #define O_HSDIR 0x9b
2051 { "HostStatusDirectory", O_HSDIR, OI_NONE },
2052 #define O_SINGTHREAD 0x9c
2053 { "SingleThreadDelivery", O_SINGTHREAD, OI_NONE },
2054 #define O_RUNASUSER 0x9d
2055 { "RunAsUser", O_RUNASUSER, OI_NONE },
2056 #define O_DSN_RRT 0x9e
2057 { "RrtImpliesDsn", O_DSN_RRT, OI_NONE },
2058 #define O_PIDFILE 0x9f
2059 { "PidFile", O_PIDFILE, OI_NONE },
2060 #define O_DONTBLAMESENDMAIL 0xa0
2061 { "DontBlameSendmail", O_DONTBLAMESENDMAIL, OI_NONE },
2063 { "DontProbeInterfaces", O_DPI, OI_NONE },
2064 #define O_MAXRCPT 0xa2
2065 { "MaxRecipientsPerMessage", O_MAXRCPT, OI_SAFE },
2066 #define O_DEADLETTER 0xa3
2067 { "DeadLetterDrop", O_DEADLETTER, OI_NONE },
2068 #if _FFR_DONTLOCKFILESFORREAD_OPTION
2069 # define O_DONTLOCK 0xa4
2070 { "DontLockFilesForRead", O_DONTLOCK, OI_NONE },
2071 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
2072 #define O_MAXALIASRCSN 0xa5
2073 { "MaxAliasRecursion", O_MAXALIASRCSN, OI_NONE },
2074 #define O_CNCTONLYTO 0xa6
2075 { "ConnectOnlyTo", O_CNCTONLYTO, OI_NONE },
2076 #define O_TRUSTUSER 0xa7
2077 { "TrustedUser", O_TRUSTUSER, OI_NONE },
2078 #define O_MAXMIMEHDRLEN 0xa8
2079 { "MaxMimeHeaderLength", O_MAXMIMEHDRLEN, OI_NONE },
2080 #define O_CONTROLSOCKET 0xa9
2081 { "ControlSocketName", O_CONTROLSOCKET, OI_NONE },
2082 #define O_MAXHDRSLEN 0xaa
2083 { "MaxHeadersLength", O_MAXHDRSLEN, OI_NONE },
2084 #if _FFR_MAX_FORWARD_ENTRIES
2085 # define O_MAXFORWARD 0xab
2086 { "MaxForwardEntries", O_MAXFORWARD, OI_NONE },
2087 #endif /* _FFR_MAX_FORWARD_ENTRIES */
2088 #define O_PROCTITLEPREFIX 0xac
2089 { "ProcessTitlePrefix", O_PROCTITLEPREFIX, OI_NONE },
2090 #define O_SASLINFO 0xad
2091 #if _FFR_ALLOW_SASLINFO
2092 { "DefaultAuthInfo", O_SASLINFO, OI_SAFE },
2093 #else /* _FFR_ALLOW_SASLINFO */
2094 { "DefaultAuthInfo", O_SASLINFO, OI_NONE },
2095 #endif /* _FFR_ALLOW_SASLINFO */
2096 #define O_SASLMECH 0xae
2097 { "AuthMechanisms", O_SASLMECH, OI_NONE },
2098 #define O_CLIENTPORT 0xaf
2099 { "ClientPortOptions", O_CLIENTPORT, OI_NONE },
2100 #define O_DF_BUFSIZE 0xb0
2101 { "DataFileBufferSize", O_DF_BUFSIZE, OI_NONE },
2102 #define O_XF_BUFSIZE 0xb1
2103 { "XscriptFileBufferSize", O_XF_BUFSIZE, OI_NONE },
2104 #define O_LDAPDEFAULTSPEC 0xb2
2105 { "LDAPDefaultSpec", O_LDAPDEFAULTSPEC, OI_NONE },
2107 # define O_QUEUEDELAY 0xb3
2108 { "QueueDelay", O_QUEUEDELAY, OI_NONE },
2109 #endif /* _FFR_QUEUEDELAY */
2110 #define O_SRVCERTFILE 0xb4
2111 { "ServerCertFile", O_SRVCERTFILE, OI_NONE },
2112 #define O_SRVKEYFILE 0xb5
2113 { "ServerKeyFile", O_SRVKEYFILE, OI_NONE },
2114 #define O_CLTCERTFILE 0xb6
2115 { "ClientCertFile", O_CLTCERTFILE, OI_NONE },
2116 #define O_CLTKEYFILE 0xb7
2117 { "ClientKeyFile", O_CLTKEYFILE, OI_NONE },
2118 #define O_CACERTFILE 0xb8
2119 { "CACertFile", O_CACERTFILE, OI_NONE },
2120 #define O_CACERTPATH 0xb9
2121 { "CACertPath", O_CACERTPATH, OI_NONE },
2122 #define O_DHPARAMS 0xba
2123 { "DHParameters", O_DHPARAMS, OI_NONE },
2124 #define O_INPUTMILTER 0xbb
2125 { "InputMailFilters", O_INPUTMILTER, OI_NONE },
2126 #define O_MILTER 0xbc
2127 { "Milter", O_MILTER, OI_SUBOPT },
2128 #define O_SASLOPTS 0xbd
2129 { "AuthOptions", O_SASLOPTS, OI_NONE },
2130 #define O_QUEUE_FILE_MODE 0xbe
2131 { "QueueFileMode", O_QUEUE_FILE_MODE, OI_NONE },
2133 # define O_DHPARAMS5 0xbf
2134 { "DHParameters512", O_DHPARAMS5, OI_NONE },
2135 # define O_CIPHERLIST 0xc0
2136 { "CipherList", O_CIPHERLIST, OI_NONE },
2137 #endif /* _FFR_TLS_1 */
2138 #define O_RANDFILE 0xc1
2139 { "RandFile", O_RANDFILE, OI_NONE },
2140 #define O_TLS_SRV_OPTS 0xc2
2141 { "TLSSrvOptions", O_TLS_SRV_OPTS, OI_NONE },
2142 #define O_RCPTTHROT 0xc3
2143 { "BadRcptThrottle", O_RCPTTHROT, OI_SAFE },
2144 #define O_DLVR_MIN 0xc4
2145 { "DeliverByMin", O_DLVR_MIN, OI_NONE },
2146 #define O_MAXQUEUECHILDREN 0xc5
2147 { "MaxQueueChildren", O_MAXQUEUECHILDREN, OI_NONE },
2148 #define O_MAXRUNNERSPERQUEUE 0xc6
2149 { "MaxRunnersPerQueue", O_MAXRUNNERSPERQUEUE, OI_NONE },
2150 #define O_DIRECTSUBMODIFIERS 0xc7
2151 { "DirectSubmissionModifiers", O_DIRECTSUBMODIFIERS, OI_NONE },
2152 #define O_NICEQUEUERUN 0xc8
2153 { "NiceQueueRun", O_NICEQUEUERUN, OI_NONE },
2154 #define O_SHMKEY 0xc9
2155 { "SharedMemoryKey", O_SHMKEY, OI_NONE },
2156 #define O_SASLBITS 0xca
2157 { "AuthMaxBits", O_SASLBITS, OI_NONE },
2159 { "MailboxDatabase", O_MBDB, OI_NONE },
2161 { "UseMSP", O_MSQ, OI_NONE },
2162 #define O_DELAY_LA 0xcd
2163 { "DelayLA", O_DELAY_LA, OI_NONE },
2164 #define O_FASTSPLIT 0xce
2165 { "FastSplit", O_FASTSPLIT, OI_NONE },
2166 #if _FFR_SOFT_BOUNCE
2167 # define O_SOFTBOUNCE 0xcf
2168 { "SoftBounce", O_SOFTBOUNCE, OI_NONE },
2169 #endif /* _FFR_SOFT_BOUNCE */
2171 # define O_SHMKEYFILE 0xd0
2172 { "SharedMemoryKeyFile", O_SHMKEYFILE, OI_NONE },
2173 #endif /* _FFR_SELECT_SHM */
2175 # define O_REJECTLOGINTERVAL 0xd1
2176 { "RejectLogInterval", O_REJECTLOGINTERVAL, OI_NONE },
2177 #endif /* _FFR_REJECT_LOG */
2178 #if _FFR_REQ_DIR_FSYNC_OPT
2179 # define O_REQUIRES_DIR_FSYNC 0xd2
2180 { "RequiresDirfsync", O_REQUIRES_DIR_FSYNC, OI_NONE },
2181 #endif /* _FFR_REQ_DIR_FSYNC_OPT */
2182 { NULL, '\0', OI_NONE }
2185 # define CANONIFY(val)
2187 # define SET_OPT_DEFAULT(opt, val) opt = val
2189 /* set a string option by expanding the value and assigning it */
2190 /* WARNING this belongs ONLY into a case statement! */
2191 #define SET_STRING_EXP(str) \
2192 expand(val, exbuf, sizeof exbuf, e); \
2193 newval = sm_pstrdup_x(exbuf); \
2200 #define OPTNAME o->o_name == NULL ? "<unknown>" : o->o_name
2203 setoption(opt, val, safe, sticky, e)
2208 register ENVELOPE *e;
2211 register struct optioninfo *o;
2214 bool can_setuid = RunAsUid == 0;
2217 extern bool Warn_Q_option;
2218 #if _FFR_ALLOW_SASLINFO
2219 extern unsigned int SubmitMode;
2220 #endif /* _FFR_ALLOW_SASLINFO */
2223 char exbuf[MAXLINE];
2224 #endif /* STARTTLS */
2229 /* full word options */
2230 struct optioninfo *sel;
2232 p = strchr(val, '=');
2234 p = &val[strlen(val)];
2241 syserr("readcf: null option name");
2248 subopt = strchr(val, '.');
2252 for (o = OptionTab; o->o_name != NULL; o++)
2254 if (sm_strncasecmp(o->o_name, val, strlen(val)) != 0)
2256 if (strlen(o->o_name) == strlen(val))
2258 /* completely specified -- this must be it */
2266 if (sel != NULL && o->o_name == NULL)
2268 else if (o->o_name == NULL)
2270 syserr("readcf: unknown option name %s", val);
2273 else if (sel != NULL)
2275 syserr("readcf: ambiguous option name %s (matches %s and %s)",
2276 val, sel->o_name, o->o_name);
2279 if (strlen(val) != strlen(o->o_name))
2281 int oldVerbose = Verbose;
2284 message("Option %s used as abbreviation for %s",
2286 Verbose = oldVerbose;
2293 for (o = OptionTab; o->o_name != NULL; o++)
2295 if (o->o_code == opt)
2298 if (o->o_name == NULL)
2300 syserr("readcf: unknown option name 0x%x", opt & 0xff);
2306 if (subopt != NULL && !bitset(OI_SUBOPT, o->o_flags))
2309 sm_dprintf("setoption: %s does not support suboptions, ignoring .%s\n",
2316 sm_dprintf(isascii(opt) && isprint(opt) ?
2317 "setoption %s (%c)%s%s=" :
2318 "setoption %s (0x%x)%s%s=",
2319 OPTNAME, opt, subopt == NULL ? "" : ".",
2320 subopt == NULL ? "" : subopt);
2325 ** See if this option is preset for us.
2328 if (!sticky && bitnset(opt, StickyOpt))
2331 sm_dprintf(" (ignored)\n");
2336 ** Check to see if this option can be specified by this user.
2339 if (!safe && RealUid == 0)
2341 if (!safe && !bitset(OI_SAFE, o->o_flags))
2343 if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
2348 sm_dprintf(" (unsafe)");
2349 dp = drop_privileges(true);
2358 case '7': /* force seven-bit input */
2359 SevenBitInput = atobool(val);
2362 case '8': /* handling of 8-bit input */
2366 case 'p': /* pass 8 bit, convert MIME */
2367 MimeMode = MM_CVTMIME|MM_PASS8BIT;
2370 case 'm': /* convert 8-bit, convert MIME */
2371 MimeMode = MM_CVTMIME|MM_MIME8BIT;
2374 case 's': /* strict adherence */
2375 MimeMode = MM_CVTMIME;
2379 case 'r': /* reject 8-bit, don't convert MIME */
2383 case 'j': /* "just send 8" */
2384 MimeMode = MM_PASS8BIT;
2387 case 'a': /* encode 8 bit if available */
2388 MimeMode = MM_MIME8BIT|MM_PASS8BIT|MM_CVTMIME;
2391 case 'c': /* convert 8 bit to MIME, never 7 bit */
2392 MimeMode = MM_MIME8BIT;
2397 syserr("Unknown 8-bit mode %c", *val);
2398 finis(false, true, EX_USAGE);
2400 #else /* MIME8TO7 */
2401 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
2402 "Warning: Option: %s requires MIME8TO7 support\n",
2404 #endif /* MIME8TO7 */
2407 case 'A': /* set default alias file */
2412 SET_OPT_DEFAULT(al, "aliases");
2419 case 'a': /* look N minutes for "@:@" in alias file */
2421 SafeAlias = 5 MINUTES;
2423 SafeAlias = convtime(val, 'm');
2426 case 'B': /* substitution for blank character */
2428 if (SpaceSub == '\0')
2432 case 'b': /* min blocks free on queue fs/max msg size */
2433 p = strchr(val, '/');
2437 MaxMessageSize = atol(p);
2439 MinBlocksFree = atol(val);
2442 case 'c': /* don't connect to "expensive" mailers */
2443 NoConnect = atobool(val);
2446 case 'C': /* checkpoint every N addresses */
2447 CheckpointInterval = atoi(val);
2450 case 'd': /* delivery mode */
2454 set_delivery_mode(SM_DELIVER, e);
2457 case SM_QUEUE: /* queue only */
2458 case SM_DEFER: /* queue only and defer map lookups */
2459 case SM_DELIVER: /* do everything */
2460 case SM_FORK: /* fork after verification */
2461 set_delivery_mode(*val, e);
2465 syserr("Unknown delivery mode %c", *val);
2466 finis(false, true, EX_USAGE);
2470 case 'E': /* error message header/header file */
2472 ErrMsgFile = newstr(val);
2475 case 'e': /* set error processing mode */
2478 case EM_QUIET: /* be silent about it */
2479 case EM_MAIL: /* mail back */
2480 case EM_BERKNET: /* do berknet error processing */
2481 case EM_WRITE: /* write back (or mail) */
2482 case EM_PRINT: /* print errors normally (default) */
2483 e->e_errormode = *val;
2488 case 'F': /* file mode */
2489 FileMode = atooct(val) & 0777;
2492 case 'f': /* save Unix-style From lines on front */
2493 SaveFrom = atobool(val);
2496 case 'G': /* match recipients against GECOS field */
2497 MatchGecos = atobool(val);
2500 case 'g': /* default gid */
2502 if (isascii(*val) && isdigit(*val))
2506 register struct group *gr;
2511 syserr("readcf: option %c: unknown group %s",
2514 DefGid = gr->gr_gid;
2518 case 'H': /* help file */
2521 SET_OPT_DEFAULT(HelpFile, "helpfile");
2526 HelpFile = newstr(val);
2530 case 'h': /* maximum hop count */
2531 MaxHopCount = atoi(val);
2534 case 'I': /* use internet domain name server */
2536 for (p = val; *p != 0; )
2540 struct resolverflags *rfp;
2553 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
2557 if (sm_strcasecmp(q, "HasWildcardMX") == 0)
2559 HasWildcardMX = !clearmode;
2562 if (sm_strcasecmp(q, "WorkAroundBrokenAAAA") == 0)
2564 WorkAroundBrokenAAAA = !clearmode;
2567 for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
2569 if (sm_strcasecmp(q, rfp->rf_name) == 0)
2572 if (rfp->rf_name == NULL)
2573 syserr("readcf: I option value %s unrecognized", q);
2575 _res.options &= ~rfp->rf_bits;
2577 _res.options |= rfp->rf_bits;
2580 sm_dprintf("_res.options = %x, HasWildcardMX = %d\n",
2581 (unsigned int) _res.options, HasWildcardMX);
2582 #else /* NAMED_BIND */
2583 usrerr("name server (I option) specified but BIND not compiled in");
2584 #endif /* NAMED_BIND */
2587 case 'i': /* ignore dot lines in message */
2588 IgnrDot = atobool(val);
2591 case 'j': /* send errors in MIME (RFC 1341) format */
2592 SendMIMEErrors = atobool(val);
2595 case 'J': /* .forward search path */
2597 ForwardPath = newstr(val);
2600 case 'k': /* connection cache size */
2601 MaxMciCache = atoi(val);
2602 if (MaxMciCache < 0)
2606 case 'K': /* connection cache timeout */
2607 MciCacheTimeout = convtime(val, 'm');
2610 case 'l': /* use Errors-To: header */
2611 UseErrorsTo = atobool(val);
2614 case 'L': /* log level */
2615 if (safe || LogLevel < atoi(val))
2616 LogLevel = atoi(val);
2619 case 'M': /* define macro */
2621 mid = macid_parse(val, &ep);
2626 cleanstrcpy(p, p, strlen(p) + 1);
2627 macdefine(&CurEnv->e_macro, A_TEMP, mid, p);
2630 case 'm': /* send to me too */
2631 MeToo = atobool(val);
2634 case 'n': /* validate RHS in newaliases */
2635 CheckAliases = atobool(val);
2638 /* 'N' available -- was "net name" */
2640 case 'O': /* daemon options */
2641 if (!setdaemonoptions(val))
2642 syserr("too many daemons defined (%d max)", MAXDAEMONS);
2645 case 'o': /* assume old style headers */
2647 CurEnv->e_flags |= EF_OLDSTYLE;
2649 CurEnv->e_flags &= ~EF_OLDSTYLE;
2652 case 'p': /* select privacy level */
2656 register struct prival *pv;
2657 extern struct prival PrivacyValues[];
2659 while (isascii(*p) && (isspace(*p) || ispunct(*p)))
2664 while (isascii(*p) && isalnum(*p))
2669 for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
2671 if (sm_strcasecmp(val, pv->pv_name) == 0)
2674 if (pv->pv_name == NULL)
2675 syserr("readcf: Op line: %s unrecognized", val);
2677 PrivacyFlags |= pv->pv_flag;
2682 case 'P': /* postmaster copy address for returned mail */
2683 PostMasterCopy = newstr(val);
2686 case 'q': /* slope of queue only function */
2687 QueueFactor = atoi(val);
2690 case 'Q': /* queue directory */
2693 QueueDir = "mqueue";
2697 QueueDir = newstr(val);
2699 if (RealUid != 0 && !safe)
2700 Warn_Q_option = true;
2703 case 'R': /* don't prune routes */
2704 DontPruneRoutes = atobool(val);
2707 case 'r': /* read timeout */
2709 inittimeouts(val, sticky);
2711 settimeout(subopt, val, sticky);
2714 case 'S': /* status file */
2717 SET_OPT_DEFAULT(StatFile, "statistics");
2722 StatFile = newstr(val);
2726 case 's': /* be super safe, even if expensive */
2727 if (tolower(*val) == 'i')
2728 SuperSafe = SAFE_INTERACTIVE;
2730 SuperSafe = atobool(val) ? SAFE_REALLY : SAFE_NO;
2733 case 'T': /* queue timeout */
2734 p = strchr(val, '/');
2738 settimeout("queuewarn", p, sticky);
2740 settimeout("queuereturn", val, sticky);
2743 case 't': /* time zone name */
2744 TimeZoneSpec = newstr(val);
2747 case 'U': /* location of user database */
2748 UdbSpec = newstr(val);
2751 case 'u': /* set default uid */
2752 for (p = val; *p != '\0'; p++)
2754 # if _FFR_DOTTED_USERNAMES
2755 if (*p == '/' || *p == ':')
2756 # else /* _FFR_DOTTED_USERNAMES */
2757 if (*p == '.' || *p == '/' || *p == ':')
2758 # endif /* _FFR_DOTTED_USERNAMES */
2764 if (isascii(*val) && isdigit(*val))
2771 register struct passwd *pw;
2774 pw = sm_getpwnam(val);
2777 syserr("readcf: option u: unknown user %s", val);
2782 DefUid = pw->pw_uid;
2783 DefGid = pw->pw_gid;
2784 DefUser = newstr(pw->pw_name);
2789 if (DefUid > UID_MAX)
2791 syserr("readcf: option u: uid value (%ld) > UID_MAX (%ld); ignored",
2792 (long)DefUid, (long)UID_MAX);
2795 # endif /* UID_MAX */
2797 /* handle the group if it is there */
2803 case 'V': /* fallback MX host */
2805 FallBackMX = newstr(val);
2808 case 'v': /* run in verbose mode */
2809 Verbose = atobool(val) ? 1 : 0;
2812 case 'w': /* if we are best MX, try host directly */
2813 TryNullMXList = atobool(val);
2816 /* 'W' available -- was wizard password */
2818 case 'x': /* load avg at which to auto-queue msgs */
2819 QueueLA = atoi(val);
2822 case 'X': /* load avg at which to auto-reject connections */
2823 RefuseLA = atoi(val);
2826 case O_DELAY_LA: /* load avg at which to delay connections */
2827 DelayLA = atoi(val);
2830 case 'y': /* work recipient factor */
2831 WkRecipFact = atoi(val);
2834 case 'Y': /* fork jobs during queue runs */
2835 ForkQueueRuns = atobool(val);
2838 case 'z': /* work message class factor */
2839 WkClassFact = atoi(val);
2842 case 'Z': /* work time factor */
2843 WkTimeFact = atoi(val);
2847 #if _FFR_QUEUE_GROUP_SORTORDER
2848 /* coordinate this with makequeue() */
2849 #endif /* _FFR_QUEUE_GROUP_SORTORDER */
2850 case O_QUEUESORTORD: /* queue sorting order */
2853 case 'f': /* File Name */
2855 QueueSortOrder = QSO_BYFILENAME;
2858 case 'h': /* Host first */
2860 QueueSortOrder = QSO_BYHOST;
2863 case 'm': /* Modification time */
2865 QueueSortOrder = QSO_BYMODTIME;
2868 case 'p': /* Priority order */
2870 QueueSortOrder = QSO_BYPRIORITY;
2873 case 't': /* Submission time */
2875 QueueSortOrder = QSO_BYTIME;
2878 case 'r': /* Random */
2880 QueueSortOrder = QSO_RANDOM;
2884 case 's': /* Shuffled host name */
2886 QueueSortOrder = QSO_BYSHUFFLE;
2888 #endif /* _FFR_RHS */
2891 syserr("Invalid queue sort order \"%s\"", val);
2896 case O_QUEUEDELAY: /* queue delay algorithm */
2899 case 'e': /* exponential */
2902 QueueInitDelay = 10 MINUTES;
2903 QueueMaxDelay = 2 HOURS;
2904 p = strchr(val, '/');
2913 QueueInitDelay = convtime(p, 's');
2916 QueueMaxDelay = convtime(q, 's');
2921 case 'l': /* linear */
2923 QueueAlg = QD_LINEAR;
2927 syserr("Invalid queue delay algorithm \"%s\"", val);
2930 #endif /* _FFR_QUEUEDELAY */
2932 case O_HOSTSFILE: /* pathname of /etc/hosts file */
2934 HostsFile = newstr(val);
2937 case O_MQA: /* minimum queue age between deliveries */
2938 MinQueueAge = convtime(val, 'm');
2941 case O_DEFCHARSET: /* default character set for mimefying */
2942 DefaultCharSet = newstr(denlstring(val, true, true));
2945 case O_SSFILE: /* service switch file */
2947 ServiceSwitchFile = newstr(val);
2950 case O_DIALDELAY: /* delay for dial-on-demand operation */
2951 DialDelay = convtime(val, 's');
2954 case O_NORCPTACTION: /* what to do if no recipient */
2955 if (sm_strcasecmp(val, "none") == 0)
2956 NoRecipientAction = NRA_NO_ACTION;
2957 else if (sm_strcasecmp(val, "add-to") == 0)
2958 NoRecipientAction = NRA_ADD_TO;
2959 else if (sm_strcasecmp(val, "add-apparently-to") == 0)
2960 NoRecipientAction = NRA_ADD_APPARENTLY_TO;
2961 else if (sm_strcasecmp(val, "add-bcc") == 0)
2962 NoRecipientAction = NRA_ADD_BCC;
2963 else if (sm_strcasecmp(val, "add-to-undisclosed") == 0)
2964 NoRecipientAction = NRA_ADD_TO_UNDISCLOSED;
2966 syserr("Invalid NoRecipientAction: %s", val);
2969 case O_SAFEFILEENV: /* chroot() environ for writing to files */
2973 /* strip trailing slashes */
2974 p = val + strlen(val) - 1;
2975 while (p >= val && *p == '/')
2981 SafeFileEnv = newstr(val);
2984 case O_MAXMSGSIZE: /* maximum message size */
2985 MaxMessageSize = atol(val);
2988 case O_COLONOKINADDR: /* old style handling of colon addresses */
2989 ColonOkInAddr = atobool(val);
2992 case O_MAXQUEUERUN: /* max # of jobs in a single queue run */
2993 MaxQueueRun = atoi(val);
2996 case O_MAXCHILDREN: /* max # of children of daemon */
2997 MaxChildren = atoi(val);
3000 case O_MAXQUEUECHILDREN: /* max # of children of daemon */
3001 MaxQueueChildren = atoi(val);
3004 case O_MAXRUNNERSPERQUEUE: /* max # runners in a queue group */
3005 MaxRunnersPerQueue = atoi(val);
3008 case O_NICEQUEUERUN: /* nice queue runs */
3010 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3011 "Warning: NiceQueueRun set on system that doesn't support nice()\n");
3012 #endif /* !HASNICE */
3014 /* XXX do we want to check the range? > 0 ? */
3015 NiceQueueRun = atoi(val);
3018 case O_SHMKEY: /* shared memory key */
3021 #else /* SM_CONF_SHM */
3022 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3023 "Warning: Option: %s requires shared memory support (-DSM_CONF_SHM)\n",
3025 #endif /* SM_CONF_SHM */
3029 case O_SHMKEYFILE: /* shared memory key file */
3031 SET_STRING_EXP(ShmKeyFile);
3032 # else /* SM_CONF_SHM */
3033 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3034 "Warning: Option: %s requires shared memory support (-DSM_CONF_SHM)\n",
3037 # endif /* SM_CONF_SHM */
3038 #endif /* _FFR_SELECT_SHM */
3040 #if _FFR_MAX_FORWARD_ENTRIES
3041 case O_MAXFORWARD: /* max # of forward entries */
3042 MaxForwardEntries = atoi(val);
3044 #endif /* _FFR_MAX_FORWARD_ENTRIES */
3046 case O_KEEPCNAMES: /* don't expand CNAME records */
3047 DontExpandCnames = atobool(val);
3050 case O_MUSTQUOTE: /* must quote these characters in phrases */
3051 (void) sm_strlcpy(buf, "@,;:\\()[]", sizeof buf);
3052 if (strlen(val) < sizeof buf - 10)
3053 (void) sm_strlcat(buf, val, sizeof buf);
3055 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3056 "Warning: MustQuoteChars too long, ignored.\n");
3057 MustQuoteChars = newstr(buf);
3060 case O_SMTPGREETING: /* SMTP greeting message (old $e macro) */
3061 SmtpGreeting = newstr(munchstring(val, NULL, '\0'));
3064 case O_UNIXFROM: /* UNIX From_ line (old $l macro) */
3065 UnixFromLine = newstr(munchstring(val, NULL, '\0'));
3068 case O_OPCHARS: /* operator characters (old $o macro) */
3069 if (OperatorChars != NULL)
3070 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3071 "Warning: OperatorChars is being redefined.\n It should only be set before ruleset definitions.\n");
3072 OperatorChars = newstr(munchstring(val, NULL, '\0'));
3075 case O_DONTINITGRPS: /* don't call initgroups(3) */
3076 DontInitGroups = atobool(val);
3079 case O_SLFH: /* make sure from fits on one line */
3080 SingleLineFromHeader = atobool(val);
3083 case O_ABH: /* allow HELO commands with syntax errors */
3084 AllowBogusHELO = atobool(val);
3087 case O_CONNTHROT: /* connection rate throttle */
3088 ConnRateThrottle = atoi(val);
3091 case O_UGW: /* group writable files are unsafe */
3094 setbitn(DBS_GROUPWRITABLEFORWARDFILESAFE,
3096 setbitn(DBS_GROUPWRITABLEINCLUDEFILESAFE,
3101 case O_DBLBOUNCE: /* address to which to send double bounces */
3102 DoubleBounceAddr = newstr(val);
3105 case O_HSDIR: /* persistent host status directory */
3109 HostStatDir = newstr(val);
3113 case O_SINGTHREAD: /* single thread deliveries (requires hsdir) */
3114 SingleThreadDelivery = atobool(val);
3117 case O_RUNASUSER: /* run bulk of code as this user */
3118 for (p = val; *p != '\0'; p++)
3120 # if _FFR_DOTTED_USERNAMES
3121 if (*p == '/' || *p == ':')
3122 # else /* _FFR_DOTTED_USERNAMES */
3123 if (*p == '.' || *p == '/' || *p == ':')
3124 # endif /* _FFR_DOTTED_USERNAMES */
3130 if (isascii(*val) && isdigit(*val))
3133 RunAsUid = atoi(val);
3137 register struct passwd *pw;
3139 pw = sm_getpwnam(val);
3142 syserr("readcf: option RunAsUser: unknown user %s", val);
3145 else if (can_setuid)
3148 RunAsUserName = newstr(val);
3149 RunAsUid = pw->pw_uid;
3150 RunAsGid = pw->pw_gid;
3152 else if (EffGid == pw->pw_gid)
3153 RunAsGid = pw->pw_gid;
3154 else if (UseMSP && *p == '\0')
3155 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3156 "WARNING: RunAsGid for MSP ignored, check group ids (egid=%d, want=%d)\n",
3161 if (RunAsUid > UID_MAX)
3163 syserr("readcf: option RunAsUser: uid value (%ld) > UID_MAX (%ld); ignored",
3164 (long) RunAsUid, (long) UID_MAX);
3167 # endif /* UID_MAX */
3170 if (isascii(*p) && isdigit(*p))
3174 runasgid = (gid_t) atoi(p);
3175 if (can_setuid || EffGid == runasgid)
3176 RunAsGid = runasgid;
3178 (void) sm_io_fprintf(smioout,
3180 "WARNING: RunAsGid for MSP ignored, check group ids (egid=%d, want=%d)\n",
3186 register struct group *gr;
3190 syserr("readcf: option RunAsUser: unknown group %s",
3192 else if (can_setuid || EffGid == gr->gr_gid)
3193 RunAsGid = gr->gr_gid;
3195 (void) sm_io_fprintf(smioout,
3197 "WARNING: RunAsGid for MSP ignored, check group ids (egid=%d, want=%d)\n",
3203 sm_dprintf("readcf: RunAsUser = %d:%d\n",
3204 (int) RunAsUid, (int) RunAsGid);
3208 RrtImpliesDsn = atobool(val);
3212 PSTRSET(PidFile, val);
3215 case O_DONTBLAMESENDMAIL:
3219 register struct dbsval *dbs;
3220 extern struct dbsval DontBlameSendmailValues[];
3222 while (isascii(*p) && (isspace(*p) || ispunct(*p)))
3227 while (isascii(*p) && isalnum(*p))
3232 for (dbs = DontBlameSendmailValues;
3233 dbs->dbs_name != NULL; dbs++)
3235 if (sm_strcasecmp(val, dbs->dbs_name) == 0)
3238 if (dbs->dbs_name == NULL)
3239 syserr("readcf: DontBlameSendmail option: %s unrecognized", val);
3240 else if (dbs->dbs_flag == DBS_SAFE)
3241 clrbitmap(DontBlameSendmail);
3243 setbitn(dbs->dbs_flag, DontBlameSendmail);
3249 if (sm_strcasecmp(val, "loopback") == 0)
3250 DontProbeInterfaces = DPI_SKIPLOOPBACK;
3251 else if (atobool(val))
3252 DontProbeInterfaces = DPI_PROBENONE;
3254 DontProbeInterfaces = DPI_PROBEALL;
3258 MaxRcptPerMsg = atoi(val);
3262 BadRcptThrottle = atoi(val);
3267 PSTRSET(DeadLetterDrop, val);
3270 #if _FFR_DONTLOCKFILESFORREAD_OPTION
3272 DontLockReadFiles = atobool(val);
3274 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
3276 case O_MAXALIASRCSN:
3277 MaxAliasRecursion = atoi(val);
3281 /* XXX should probably use gethostbyname */
3282 #if NETINET || NETINET6
3283 ConnectOnlyTo.sa.sa_family = AF_UNSPEC;
3285 if (anynet_pton(AF_INET6, val,
3286 &ConnectOnlyTo.sin6.sin6_addr) != 1)
3287 ConnectOnlyTo.sa.sa_family = AF_INET6;
3289 # endif /* NETINET6 */
3292 ConnectOnlyTo.sin.sin_addr.s_addr = inet_addr(val);
3293 if (ConnectOnlyTo.sin.sin_addr.s_addr != INADDR_NONE)
3294 ConnectOnlyTo.sa.sa_family = AF_INET;
3297 # endif /* NETINET */
3298 if (ConnectOnlyTo.sa.sa_family == AF_UNSPEC)
3300 syserr("readcf: option ConnectOnlyTo: invalid IP address %s",
3304 #endif /* NETINET || NETINET6 */
3308 # if !HASFCHOWN && !defined(_FFR_DROP_TRUSTUSER_WARNING)
3310 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3311 "readcf: option TrustedUser may cause problems on systems\n which do not support fchown() if UseMSP is not set.\n");
3312 # endif /* !HASFCHOWN && !defined(_FFR_DROP_TRUSTUSER_WARNING) */
3313 if (isascii(*val) && isdigit(*val))
3314 TrustedUid = atoi(val);
3317 register struct passwd *pw;
3320 pw = sm_getpwnam(val);
3323 syserr("readcf: option TrustedUser: unknown user %s", val);
3327 TrustedUid = pw->pw_uid;
3331 if (TrustedUid > UID_MAX)
3333 syserr("readcf: option TrustedUser: uid value (%ld) > UID_MAX (%ld)",
3334 (long) TrustedUid, (long) UID_MAX);
3337 # endif /* UID_MAX */
3340 case O_MAXMIMEHDRLEN:
3341 p = strchr(val, '/');
3344 MaxMimeHeaderLength = atoi(val);
3345 if (p != NULL && *p != '\0')
3346 MaxMimeFieldLength = atoi(p);
3348 MaxMimeFieldLength = MaxMimeHeaderLength / 2;
3350 if (MaxMimeHeaderLength <= 0)
3351 MaxMimeHeaderLength = 0;
3352 else if (MaxMimeHeaderLength < 128)
3353 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3354 "Warning: MaxMimeHeaderLength: header length limit set lower than 128\n");
3356 if (MaxMimeFieldLength <= 0)
3357 MaxMimeFieldLength = 0;
3358 else if (MaxMimeFieldLength < 40)
3359 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3360 "Warning: MaxMimeHeaderLength: field length limit set lower than 40\n");
3363 case O_CONTROLSOCKET:
3364 PSTRSET(ControlSocketName, val);
3368 MaxHeadersLength = atoi(val);
3370 if (MaxHeadersLength > 0 &&
3371 MaxHeadersLength < (MAXHDRSLEN / 2))
3372 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3373 "Warning: MaxHeadersLength: headers length limit set lower than %d\n",
3377 case O_PROCTITLEPREFIX:
3378 PSTRSET(ProcTitlePrefix, val);
3383 # if _FFR_ALLOW_SASLINFO
3385 ** Allow users to select their own authinfo file
3386 ** under certain circumstances, otherwise just ignore
3387 ** the option. If the option isn't ignored, several
3388 ** commands don't work very well, e.g., mailq.
3389 ** However, this is not a "perfect" solution.
3390 ** If mail is queued, the authentication info
3391 ** will not be used in subsequent delivery attempts.
3392 ** If we really want to support this, then it has
3393 ** to be stored in the queue file.
3395 if (!bitset(SUBMIT_MSA, SubmitMode) && RealUid != 0 &&
3396 RunAsUid != RealUid)
3398 # endif /* _FFR_ALLOW_SASLINFO */
3399 PSTRSET(SASLInfo, val);
3403 if (AuthMechanisms != NULL)
3404 sm_free(AuthMechanisms); /* XXX */
3406 AuthMechanisms = newstr(val);
3408 AuthMechanisms = NULL;
3412 while (val != NULL && *val != '\0')
3417 SASLOpts |= SASL_AUTH_AUTH;
3421 SASLOpts |= SASL_SEC_NOACTIVE;
3425 SASLOpts |= SASL_SEC_PASS_CREDENTIALS;
3429 SASLOpts |= SASL_SEC_NODICTIONARY;
3433 SASLOpts |= SASL_SEC_FORWARD_SECRECY;
3436 # if _FFR_SASL_OPT_M
3437 /* to be activated in 8.13 */
3440 SASLOpts |= SASL_SEC_MUTUAL_AUTH;
3442 # endif /* SASL >= 20101 */
3443 # endif /* _FFR_SASL_OPT_M */
3446 SASLOpts |= SASL_SEC_NOPLAINTEXT;
3450 SASLOpts |= SASL_SEC_NOANONYMOUS;
3453 case ' ': /* ignore */
3454 case '\t': /* ignore */
3455 case ',': /* ignore */
3459 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3460 "Warning: Option: %s unknown parameter '%c'\n",
3468 val = strpbrk(val, ", \t");
3475 MaxSLBits = atoi(val);
3483 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3484 "Warning: Option: %s requires SASL support (-DSASL)\n",
3491 SET_STRING_EXP(SrvCertFile);
3493 SET_STRING_EXP(SrvKeyFile);
3495 SET_STRING_EXP(CltCertFile);
3497 SET_STRING_EXP(CltKeyFile);
3499 SET_STRING_EXP(CACertFile);
3501 SET_STRING_EXP(CACertPath);
3503 SET_STRING_EXP(DHParams);
3506 SET_STRING_EXP(DHParams5);
3508 SET_STRING_EXP(CipherList);
3509 # endif /* _FFR_TLS_1 */
3512 ** XXX How about options per daemon/client instead of globally?
3513 ** This doesn't work well for some options, e.g., no server cert,
3514 ** but fine for others.
3516 ** XXX Some people may want different certs per server.
3518 ** See also srvfeatures()
3521 case O_TLS_SRV_OPTS:
3522 while (val != NULL && *val != '\0')
3527 TLS_Srv_Opts |= TLS_I_NO_VRFY;
3531 ** Server without a cert? That works only if
3532 ** AnonDH is enabled as cipher, which is not in the
3533 ** default list. Hence the CipherList option must
3534 ** be available. Moreover: which clients support this
3535 ** besides sendmail with this setting?
3539 TLS_Srv_Opts &= ~TLS_I_SRV_CERT;
3541 # endif /* _FFR_TLS_1 */
3542 case ' ': /* ignore */
3543 case '\t': /* ignore */
3544 case ',': /* ignore */
3547 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3548 "Warning: Option: %s unknown parameter '%c'\n",
3556 val = strpbrk(val, ", \t");
3563 PSTRSET(RandFile, val);
3566 #else /* STARTTLS */
3577 # endif /* _FFR_TLS_1 */
3579 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3580 "Warning: Option: %s requires TLS support\n",
3584 #endif /* STARTTLS */
3587 setclientoptions(val);
3591 DataFileBufferSize = atoi(val);
3595 XscriptFileBufferSize = atoi(val);
3598 case O_LDAPDEFAULTSPEC:
3600 ldapmap_set_defaults(val);
3602 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3603 "Warning: Option: %s requires LDAP support (-DLDAPMAP)\n",
3605 #endif /* LDAPMAP */
3610 InputFilterList = newstr(val);
3612 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3613 "Warning: Option: %s requires Milter support (-DMILTER)\n",
3620 milter_set_option(subopt, val, sticky);
3622 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3623 "Warning: Option: %s requires Milter support (-DMILTER)\n",
3628 case O_QUEUE_FILE_MODE: /* queue file mode */
3629 QueueFileMode = atooct(val) & 0777;
3632 case O_DLVR_MIN: /* deliver by minimum time */
3633 DeliverByMin = convtime(val, 's');
3636 /* modifiers {daemon_flags} for direct submissions */
3637 case O_DIRECTSUBMODIFIERS:
3639 BITMAP256 m; /* ignored */
3640 extern ENVELOPE BlankEnvelope;
3642 macdefine(&BlankEnvelope.e_macro, A_PERM,
3643 macid("{daemon_flags}"),
3644 getmodifiers(val, m));
3649 FastSplit = atoi(val);
3657 UseMSP = atobool(val);
3660 #if _FFR_SOFT_BOUNCE
3662 SoftBounce = atobool(val);
3664 #endif /* _FFR_SOFT_BOUNCE */
3667 case O_REJECTLOGINTERVAL: /* time btwn log msgs while refusing */
3668 RejectLogInterval = convtime(val, 'h');
3670 #endif /* _FFR_REJECT_LOG */
3672 #if _FFR_REQ_DIR_FSYNC_OPT
3673 case O_REQUIRES_DIR_FSYNC:
3674 # if REQUIRES_DIR_FSYNC
3675 RequiresDirfsync = atobool(val);
3676 # else /* REQUIRES_DIR_FSYNC */
3677 /* silently ignored... required for cf file option */
3678 # endif /* REQUIRES_DIR_FSYNC */
3680 #endif /* _FFR_REQ_DIR_FSYNC_OPT */
3685 if (isascii(opt) && isprint(opt))
3686 sm_dprintf("Warning: option %c unknown\n", opt);
3688 sm_dprintf("Warning: option 0x%x unknown\n", opt);
3694 ** Options with suboptions are responsible for taking care
3695 ** of sticky-ness (e.g., that a command line setting is kept
3696 ** when reading in the sendmail.cf file). This has to be done
3697 ** when the suboptions are parsed since each suboption must be
3698 ** sticky, not the root option.
3701 if (sticky && !bitset(OI_SUBOPT, o->o_flags))
3702 setbitn(opt, StickyOpt);
3705 ** SETCLASS -- set a string into a class
3708 ** class -- the class to put the string in.
3709 ** str -- the string to enter
3715 ** puts the word into the symbol table.
3719 setclass(class, str)
3725 if ((*str & 0377) == MATCHCLASS)
3735 sm_dprintf("setclass(%s, $=%s)\n",
3736 macname(class), macname(mid));
3737 copy_class(mid, class);
3742 sm_dprintf("setclass(%s, %s)\n", macname(class), str);
3744 s = stab(str, ST_CLASS, ST_ENTER);
3745 setbitn(bitidx(class), s->s_class);
3749 ** MAKEMAPENTRY -- create a map entry
3752 ** line -- the config file line
3755 ** A pointer to the map that has been created.
3756 ** NULL if there was a syntax error.
3759 ** Enters the map into the dictionary.
3772 for (p = line; isascii(*p) && isspace(*p); p++)
3774 if (!(isascii(*p) && isalnum(*p)))
3776 syserr("readcf: config K line: no map name");
3781 while ((isascii(*++p) && isalnum(*p)) || *p == '_' || *p == '.')
3785 while (isascii(*p) && isspace(*p))
3787 if (!(isascii(*p) && isalnum(*p)))
3789 syserr("readcf: config K line, map %s: no map class", mapname);
3793 while (isascii(*++p) && isalnum(*p))
3797 while (isascii(*p) && isspace(*p))
3800 /* look up the class */
3801 class = stab(classname, ST_MAPCLASS, ST_FIND);
3804 syserr("readcf: map %s: class %s not available", mapname,
3810 s = stab(mapname, ST_MAP, ST_ENTER);
3811 s->s_map.map_class = &class->s_mapclass;
3812 s->s_map.map_mname = newstr(mapname);
3814 if (class->s_mapclass.map_parse(&s->s_map, p))
3815 s->s_map.map_mflags |= MF_VALID;
3819 sm_dprintf("map %s, class %s, flags %lx, file %s,\n",
3820 s->s_map.map_mname, s->s_map.map_class->map_cname,
3821 s->s_map.map_mflags, s->s_map.map_file);
3822 sm_dprintf("\tapp %s, domain %s, rebuild %s\n",
3823 s->s_map.map_app, s->s_map.map_domain,
3824 s->s_map.map_rebuild);
3829 ** STRTORWSET -- convert string to rewriting set number
3832 ** p -- the pointer to the string to decode.
3833 ** endp -- if set, store the trailing delimiter here.
3834 ** stabmode -- ST_ENTER to create this entry, ST_FIND if
3835 ** it must already exist.
3838 ** The appropriate ruleset number.
3839 ** -1 if it is not valid (error already printed)
3843 strtorwset(p, endp, stabmode)
3849 static int nextruleset = MAXRWSETS;
3851 while (isascii(*p) && isspace(*p))
3855 syserr("invalid ruleset name: \"%.20s\"", p);
3860 ruleset = strtol(p, endp, 10);
3861 if (ruleset >= MAXRWSETS / 2 || ruleset < 0)
3863 syserr("bad ruleset %d (%d max)",
3864 ruleset, MAXRWSETS / 2);
3875 while (*p != '\0' && isascii(*p) &&
3876 (isalnum(*p) || *p == '_'))
3878 if (q == p || !(isascii(*q) && isalpha(*q)))
3880 /* no valid characters */
3881 syserr("invalid ruleset name: \"%.20s\"", q);
3884 while (isascii(*p) && isspace(*p))
3889 s = stab(q, ST_RULESET, stabmode);
3896 if (stabmode == ST_ENTER && delim == '=')
3898 while (isascii(*++p) && isspace(*p))
3900 if (!(isascii(*p) && isdigit(*p)))
3902 syserr("bad ruleset definition \"%s\" (number required after `=')", q);
3907 ruleset = strtol(p, endp, 10);
3908 if (ruleset >= MAXRWSETS / 2 || ruleset < 0)
3910 syserr("bad ruleset number %d in \"%s\" (%d max)",
3911 ruleset, q, MAXRWSETS / 2);
3920 if (s->s_ruleset >= 0)
3921 ruleset = s->s_ruleset;
3922 else if ((ruleset = --nextruleset) < MAXRWSETS / 2)
3924 syserr("%s: too many named rulesets (%d max)",
3929 if (s->s_ruleset >= 0 &&
3931 ruleset != s->s_ruleset)
3933 syserr("%s: ruleset changed value (old %d, new %d)",
3934 q, s->s_ruleset, ruleset);
3935 ruleset = s->s_ruleset;
3937 else if (ruleset >= 0)
3939 s->s_ruleset = ruleset;
3941 if (stabmode == ST_ENTER && ruleset >= 0)
3945 if (RuleSetNames[ruleset] != NULL)
3946 sm_free(RuleSetNames[ruleset]); /* XXX */
3947 if (delim != '\0' && (h = strchr(q, delim)) != NULL)
3949 RuleSetNames[ruleset] = newstr(q);
3950 if (delim == '/' && h != NULL)
3951 *h = delim; /* put back delim */
3957 ** SETTIMEOUT -- set an individual timeout
3960 ** name -- the name of the timeout.
3961 ** val -- the value of the timeout.
3962 ** sticky -- if set, don't let other setoptions override
3969 /* set if Timeout sub-option is stuck */
3970 static BITMAP256 StickyTimeoutOpt;
3972 static struct timeoutinfo
3974 char *to_name; /* long name of timeout */
3975 unsigned char to_code; /* code for option */
3978 #define TO_INITIAL 0x01
3979 { "initial", TO_INITIAL },
3980 #define TO_MAIL 0x02
3981 { "mail", TO_MAIL },
3982 #define TO_RCPT 0x03
3983 { "rcpt", TO_RCPT },
3984 #define TO_DATAINIT 0x04
3985 { "datainit", TO_DATAINIT },
3986 #define TO_DATABLOCK 0x05
3987 { "datablock", TO_DATABLOCK },
3988 #define TO_DATAFINAL 0x06
3989 { "datafinal", TO_DATAFINAL },
3990 #define TO_COMMAND 0x07
3991 { "command", TO_COMMAND },
3992 #define TO_RSET 0x08
3993 { "rset", TO_RSET },
3994 #define TO_HELO 0x09
3995 { "helo", TO_HELO },
3996 #define TO_QUIT 0x0A
3997 { "quit", TO_QUIT },
3998 #define TO_MISC 0x0B
3999 { "misc", TO_MISC },
4000 #define TO_IDENT 0x0C
4001 { "ident", TO_IDENT },
4002 #define TO_FILEOPEN 0x0D
4003 { "fileopen", TO_FILEOPEN },
4004 #define TO_CONNECT 0x0E
4005 { "connect", TO_CONNECT },
4006 #define TO_ICONNECT 0x0F
4007 { "iconnect", TO_ICONNECT },
4008 #define TO_QUEUEWARN 0x10
4009 { "queuewarn", TO_QUEUEWARN },
4010 { "queuewarn.*", TO_QUEUEWARN },
4011 #define TO_QUEUEWARN_NORMAL 0x11
4012 { "queuewarn.normal", TO_QUEUEWARN_NORMAL },
4013 #define TO_QUEUEWARN_URGENT 0x12
4014 { "queuewarn.urgent", TO_QUEUEWARN_URGENT },
4015 #define TO_QUEUEWARN_NON_URGENT 0x13
4016 { "queuewarn.non-urgent", TO_QUEUEWARN_NON_URGENT },
4017 #define TO_QUEUERETURN 0x14
4018 { "queuereturn", TO_QUEUERETURN },
4019 { "queuereturn.*", TO_QUEUERETURN },
4020 #define TO_QUEUERETURN_NORMAL 0x15
4021 { "queuereturn.normal", TO_QUEUERETURN_NORMAL },
4022 #define TO_QUEUERETURN_URGENT 0x16
4023 { "queuereturn.urgent", TO_QUEUERETURN_URGENT },
4024 #define TO_QUEUERETURN_NON_URGENT 0x17
4025 { "queuereturn.non-urgent", TO_QUEUERETURN_NON_URGENT },
4026 #define TO_HOSTSTATUS 0x18
4027 { "hoststatus", TO_HOSTSTATUS },
4028 #define TO_RESOLVER_RETRANS 0x19
4029 { "resolver.retrans", TO_RESOLVER_RETRANS },
4030 #define TO_RESOLVER_RETRANS_NORMAL 0x1A
4031 { "resolver.retrans.normal", TO_RESOLVER_RETRANS_NORMAL },
4032 #define TO_RESOLVER_RETRANS_FIRST 0x1B
4033 { "resolver.retrans.first", TO_RESOLVER_RETRANS_FIRST },
4034 #define TO_RESOLVER_RETRY 0x1C
4035 { "resolver.retry", TO_RESOLVER_RETRY },
4036 #define TO_RESOLVER_RETRY_NORMAL 0x1D
4037 { "resolver.retry.normal", TO_RESOLVER_RETRY_NORMAL },
4038 #define TO_RESOLVER_RETRY_FIRST 0x1E
4039 { "resolver.retry.first", TO_RESOLVER_RETRY_FIRST },
4040 #define TO_CONTROL 0x1F
4041 { "control", TO_CONTROL },
4042 #define TO_LHLO 0x20
4043 { "lhlo", TO_LHLO },
4044 #define TO_AUTH 0x21
4045 { "auth", TO_AUTH },
4046 #define TO_STARTTLS 0x22
4047 { "starttls", TO_STARTTLS },
4048 #define TO_ACONNECT 0x23
4049 { "aconnect", TO_ACONNECT },
4050 #if _FFR_QUEUERETURN_DSN
4051 # define TO_QUEUEWARN_DSN 0x24
4052 { "queuewarn.dsn", TO_QUEUEWARN_DSN },
4053 # define TO_QUEUERETURN_DSN 0x25
4054 { "queuereturn.dsn", TO_QUEUERETURN_DSN },
4055 #endif /* _FFR_QUEUERETURN_DSN */
4061 settimeout(name, val, sticky)
4066 register struct timeoutinfo *to;
4071 sm_dprintf("settimeout(%s = %s)", name, val);
4073 for (to = TimeOutTab; to->to_name != NULL; to++)
4075 if (sm_strcasecmp(to->to_name, name) == 0)
4079 if (to->to_name == NULL)
4081 errno = 0; /* avoid bogus error text */
4082 syserr("settimeout: invalid timeout %s", name);
4087 ** See if this option is preset for us.
4090 if (!sticky && bitnset(to->to_code, StickyTimeoutOpt))
4093 sm_dprintf(" (ignored)\n");
4100 toval = convtime(val, 'm');
4103 switch (to->to_code)
4106 TimeOuts.to_initial = toval;
4110 TimeOuts.to_mail = toval;
4114 TimeOuts.to_rcpt = toval;
4118 TimeOuts.to_datainit = toval;
4122 TimeOuts.to_datablock = toval;
4126 TimeOuts.to_datafinal = toval;
4130 TimeOuts.to_nextcommand = toval;
4134 TimeOuts.to_rset = toval;
4138 TimeOuts.to_helo = toval;
4142 TimeOuts.to_quit = toval;
4146 TimeOuts.to_miscshort = toval;
4150 TimeOuts.to_ident = toval;
4154 TimeOuts.to_fileopen = toval;
4158 TimeOuts.to_connect = toval;
4162 TimeOuts.to_iconnect = toval;
4166 TimeOuts.to_aconnect = toval;
4170 toval = convtime(val, 'h');
4171 TimeOuts.to_q_warning[TOC_NORMAL] = toval;
4172 TimeOuts.to_q_warning[TOC_URGENT] = toval;
4173 TimeOuts.to_q_warning[TOC_NONURGENT] = toval;
4174 #if _FFR_QUEUERETURN_DSN
4175 TimeOuts.to_q_warning[TOC_DSN] = toval;
4176 #endif /* _FFR_QUEUERETURN_DSN */
4180 case TO_QUEUEWARN_NORMAL:
4181 toval = convtime(val, 'h');
4182 TimeOuts.to_q_warning[TOC_NORMAL] = toval;
4185 case TO_QUEUEWARN_URGENT:
4186 toval = convtime(val, 'h');
4187 TimeOuts.to_q_warning[TOC_URGENT] = toval;
4190 case TO_QUEUEWARN_NON_URGENT:
4191 toval = convtime(val, 'h');
4192 TimeOuts.to_q_warning[TOC_NONURGENT] = toval;
4195 #if _FFR_QUEUERETURN_DSN
4196 case TO_QUEUEWARN_DSN:
4197 toval = convtime(val, 'h');
4198 TimeOuts.to_q_warning[TOC_DSN] = toval;
4200 #endif /* _FFR_QUEUERETURN_DSN */
4202 case TO_QUEUERETURN:
4203 toval = convtime(val, 'd');
4204 TimeOuts.to_q_return[TOC_NORMAL] = toval;
4205 TimeOuts.to_q_return[TOC_URGENT] = toval;
4206 TimeOuts.to_q_return[TOC_NONURGENT] = toval;
4207 #if _FFR_QUEUERETURN_DSN
4208 TimeOuts.to_q_return[TOC_DSN] = toval;
4209 #endif /* _FFR_QUEUERETURN_DSN */
4213 case TO_QUEUERETURN_NORMAL:
4214 toval = convtime(val, 'd');
4215 TimeOuts.to_q_return[TOC_NORMAL] = toval;
4218 case TO_QUEUERETURN_URGENT:
4219 toval = convtime(val, 'd');
4220 TimeOuts.to_q_return[TOC_URGENT] = toval;
4223 case TO_QUEUERETURN_NON_URGENT:
4224 toval = convtime(val, 'd');
4225 TimeOuts.to_q_return[TOC_NONURGENT] = toval;
4228 #if _FFR_QUEUERETURN_DSN
4229 case TO_QUEUERETURN_DSN:
4230 toval = convtime(val, 'd');
4231 TimeOuts.to_q_return[TOC_DSN] = toval;
4233 #endif /* _FFR_QUEUERETURN_DSN */
4236 MciInfoTimeout = toval;
4239 case TO_RESOLVER_RETRANS:
4240 toval = convtime(val, 's');
4241 TimeOuts.res_retrans[RES_TO_DEFAULT] = toval;
4242 TimeOuts.res_retrans[RES_TO_FIRST] = toval;
4243 TimeOuts.res_retrans[RES_TO_NORMAL] = toval;
4247 case TO_RESOLVER_RETRY:
4249 TimeOuts.res_retry[RES_TO_DEFAULT] = i;
4250 TimeOuts.res_retry[RES_TO_FIRST] = i;
4251 TimeOuts.res_retry[RES_TO_NORMAL] = i;
4255 case TO_RESOLVER_RETRANS_NORMAL:
4256 TimeOuts.res_retrans[RES_TO_NORMAL] = convtime(val, 's');
4259 case TO_RESOLVER_RETRY_NORMAL:
4260 TimeOuts.res_retry[RES_TO_NORMAL] = atoi(val);
4263 case TO_RESOLVER_RETRANS_FIRST:
4264 TimeOuts.res_retrans[RES_TO_FIRST] = convtime(val, 's');
4267 case TO_RESOLVER_RETRY_FIRST:
4268 TimeOuts.res_retry[RES_TO_FIRST] = atoi(val);
4272 TimeOuts.to_control = toval;
4276 TimeOuts.to_lhlo = toval;
4281 TimeOuts.to_auth = toval;
4287 TimeOuts.to_starttls = toval;
4289 #endif /* STARTTLS */
4292 syserr("settimeout: invalid timeout %s", name);
4298 for (i = 0; i <= addopts; i++)
4299 setbitn(to->to_code + i, StickyTimeoutOpt);
4303 ** INITTIMEOUTS -- parse and set timeout values
4306 ** val -- a pointer to the values. If NULL, do initial
4308 ** sticky -- if set, don't let other setoptions override
4309 ** this suboption value.
4315 ** Initializes the TimeOuts structure
4319 inittimeouts(val, sticky)
4326 sm_dprintf("inittimeouts(%s)\n", val == NULL ? "<NULL>" : val);
4329 TimeOuts.to_connect = (time_t) 0 SECONDS;
4330 TimeOuts.to_aconnect = (time_t) 0 SECONDS;
4331 TimeOuts.to_iconnect = (time_t) 0 SECONDS;
4332 TimeOuts.to_initial = (time_t) 5 MINUTES;
4333 TimeOuts.to_helo = (time_t) 5 MINUTES;
4334 TimeOuts.to_mail = (time_t) 10 MINUTES;
4335 TimeOuts.to_rcpt = (time_t) 1 HOUR;
4336 TimeOuts.to_datainit = (time_t) 5 MINUTES;
4337 TimeOuts.to_datablock = (time_t) 1 HOUR;
4338 TimeOuts.to_datafinal = (time_t) 1 HOUR;
4339 TimeOuts.to_rset = (time_t) 5 MINUTES;
4340 TimeOuts.to_quit = (time_t) 2 MINUTES;
4341 TimeOuts.to_nextcommand = (time_t) 1 HOUR;
4342 TimeOuts.to_miscshort = (time_t) 2 MINUTES;
4344 TimeOuts.to_ident = (time_t) 5 SECONDS;
4345 #else /* IDENTPROTO */
4346 TimeOuts.to_ident = (time_t) 0 SECONDS;
4347 #endif /* IDENTPROTO */
4348 TimeOuts.to_fileopen = (time_t) 60 SECONDS;
4349 TimeOuts.to_control = (time_t) 2 MINUTES;
4350 TimeOuts.to_lhlo = (time_t) 2 MINUTES;
4352 TimeOuts.to_auth = (time_t) 10 MINUTES;
4355 TimeOuts.to_starttls = (time_t) 1 HOUR;
4356 #endif /* STARTTLS */
4359 sm_dprintf("Timeouts:\n");
4360 sm_dprintf(" connect = %ld\n",
4361 (long) TimeOuts.to_connect);
4362 sm_dprintf(" aconnect = %ld\n",
4363 (long) TimeOuts.to_aconnect);
4364 sm_dprintf(" initial = %ld\n",
4365 (long) TimeOuts.to_initial);
4366 sm_dprintf(" helo = %ld\n", (long) TimeOuts.to_helo);
4367 sm_dprintf(" mail = %ld\n", (long) TimeOuts.to_mail);
4368 sm_dprintf(" rcpt = %ld\n", (long) TimeOuts.to_rcpt);
4369 sm_dprintf(" datainit = %ld\n",
4370 (long) TimeOuts.to_datainit);
4371 sm_dprintf(" datablock = %ld\n",
4372 (long) TimeOuts.to_datablock);
4373 sm_dprintf(" datafinal = %ld\n",
4374 (long) TimeOuts.to_datafinal);
4375 sm_dprintf(" rset = %ld\n", (long) TimeOuts.to_rset);
4376 sm_dprintf(" quit = %ld\n", (long) TimeOuts.to_quit);
4377 sm_dprintf(" nextcommand = %ld\n",
4378 (long) TimeOuts.to_nextcommand);
4379 sm_dprintf(" miscshort = %ld\n",
4380 (long) TimeOuts.to_miscshort);
4381 sm_dprintf(" ident = %ld\n", (long) TimeOuts.to_ident);
4382 sm_dprintf(" fileopen = %ld\n",
4383 (long) TimeOuts.to_fileopen);
4384 sm_dprintf(" lhlo = %ld\n",
4385 (long) TimeOuts.to_lhlo);
4386 sm_dprintf(" control = %ld\n",
4387 (long) TimeOuts.to_control);
4394 while (isascii(*val) && isspace(*val))
4398 for (p = val; *p != '\0' && *p != ','; p++)
4403 if (isascii(*val) && isdigit(*val))
4405 /* old syntax -- set everything */
4406 TimeOuts.to_mail = convtime(val, 'm');
4407 TimeOuts.to_rcpt = TimeOuts.to_mail;
4408 TimeOuts.to_datainit = TimeOuts.to_mail;
4409 TimeOuts.to_datablock = TimeOuts.to_mail;
4410 TimeOuts.to_datafinal = TimeOuts.to_mail;
4411 TimeOuts.to_nextcommand = TimeOuts.to_mail;
4414 setbitn(TO_MAIL, StickyTimeoutOpt);
4415 setbitn(TO_RCPT, StickyTimeoutOpt);
4416 setbitn(TO_DATAINIT, StickyTimeoutOpt);
4417 setbitn(TO_DATABLOCK, StickyTimeoutOpt);
4418 setbitn(TO_DATAFINAL, StickyTimeoutOpt);
4419 setbitn(TO_COMMAND, StickyTimeoutOpt);
4425 register char *q = strchr(val, ':');
4427 if (q == NULL && (q = strchr(val, '=')) == NULL)
4433 settimeout(val, q, sticky);