2 * Copyright (c) 1998-2006, 2008, 2009 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.674 2009/10/26 17:47:00 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[];
117 Srv_SSL_Options = Clt_SSL_Options = SSL_OP_ALL;
118 #endif /* STARTTLS */
119 if (DontLockReadFiles)
121 cf = safefopen(cfname, O_RDONLY, 0444, sff);
124 syserr("cannot open");
125 finis(false, true, EX_OSFILE);
128 if (fstat(sm_io_getinfo(cf, SM_IO_WHAT_FD, NULL), &statb) < 0)
130 syserr("cannot fstat");
131 finis(false, true, EX_OSFILE);
134 if (!S_ISREG(statb.st_mode))
136 syserr("not a plain file");
137 finis(false, true, EX_OSFILE);
140 if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
142 if (OpMode == MD_DAEMON || OpMode == MD_INITALIAS || OpMode == MD_CHECKCONFIG)
143 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
144 "%s: WARNING: dangerous write permissions\n",
147 sm_syslog(LOG_CRIT, NOQID,
148 "%s: WARNING: dangerous write permissions",
156 while (bufsize = sizeof(buf),
157 (bp = fgetfolded(buf, &bufsize, cf)) != NULL)
164 sm_free(bp); /* XXX */
168 /* do macro expansion mappings */
169 nbp = translate_dollars(bp, bp, &bufsize);
170 if (nbp != bp && bp != buf)
174 /* interpret this line */
179 case '#': /* comment */
182 case 'R': /* rewriting rule */
185 syserr("missing valid ruleset for \"%s\"", bp);
188 for (p = &bp[1]; *p != '\0' && *p != '\t'; p++)
193 syserr("invalid rewrite line \"%s\" (tab expected)", bp);
197 /* allocate space for the rule header */
200 RewriteRules[ruleset] = rwp =
201 (struct rewrite *) xalloc(sizeof(*rwp));
205 rwp->r_next = (struct rewrite *) xalloc(sizeof(*rwp));
210 /* expand and save the LHS */
212 expand(&bp[1], exbuf, sizeof(exbuf), e);
213 rwp->r_lhs = prescan(exbuf, '\t', pvpbuf,
214 sizeof(pvpbuf), NULL,
215 ConfigLevel >= 9 ? TokTypeNoC : IntTokenTab,
218 if (rwp->r_lhs != NULL)
222 rwp->r_lhs = copyplist(rwp->r_lhs, true, NULL);
224 /* count the number of fuzzy matches in LHS */
225 for (ap = rwp->r_lhs; *ap != NULL; ap++)
230 switch (ap[0][0] & 0377)
277 syserr("Inappropriate use of %s on LHS",
280 rwp->r_line = LineNumber;
284 syserr("R line: null LHS");
285 rwp->r_lhs = null_list;
287 if (nfuzzy > MAXMATCH)
289 syserr("R line: too many wildcards");
290 rwp->r_lhs = null_list;
293 /* expand and save the RHS */
297 while (*p != '\0' && *p != '\t')
300 expand(q, exbuf, sizeof(exbuf), e);
301 rwp->r_rhs = prescan(exbuf, '\t', pvpbuf,
302 sizeof(pvpbuf), NULL,
303 ConfigLevel >= 9 ? TokTypeNoC : IntTokenTab,
305 if (rwp->r_rhs != NULL)
309 #if _FFR_EXTRA_MAP_CHECK
311 #endif /* _FFR_EXTRA_MAP_CHECK */
314 rwp->r_rhs = copyplist(rwp->r_rhs, true, NULL);
316 /* check no out-of-bounds replacements */
321 for (ap = rwp->r_rhs; *ap != NULL; ap++)
326 switch (ap[0][0] & 0377)
329 if (ap[0][1] <= '0' ||
332 syserr("replacement $%c out of bounds",
360 if (++args >= MAX_MAP_ARGS)
361 syserr("too many arguments for map lookup");
369 if ((ap[0][0] & 0377) == LOOKUPBEGIN)
370 endtoken = LOOKUPEND;
372 syserr("cannot nest map lookups");
375 #if _FFR_EXTRA_MAP_CHECK
378 syserr("syntax error in map lookup");
381 nexttoken = ap[1][0] & 0377;
382 if (nexttoken == CANONHOST ||
383 nexttoken == CANONUSER ||
384 nexttoken == endtoken))
386 syserr("missing map name for lookup");
391 syserr("syntax error in map lookup");
394 if (ap[0][0] == HOSTBEGIN)
396 nexttoken = ap[2][0] & 0377;
397 if (nexttoken == CANONHOST ||
398 nexttoken == CANONUSER ||
399 nexttoken == endtoken)
401 syserr("missing key name for lookup");
404 #endif /* _FFR_EXTRA_MAP_CHECK */
409 if ((ap[0][0] & 0377) != endtoken)
418 ** This doesn't work yet as there are maps defined *after* the cf
419 ** is read such as host, user, and alias. So for now, it's removed.
420 ** When it comes back, the RELEASE_NOTES entry will be:
421 ** Emit warnings for unknown maps when reading the .cf file. Based on
422 ** patch from Robert Harker of Harker Systems.
427 ** Got a database lookup,
428 ** check if map is defined.
432 if ((ep[0] & 0377) != MACRODEXPAND &&
433 stab(ep, ST_MAP, ST_FIND) == NULL)
435 (void) sm_io_fprintf(smioout,
437 "Warning: %s: line %d: map %s not found\n",
446 syserr("Inappropriate use of %s on RHS",
450 syserr("missing map closing token");
454 syserr("R line: null RHS");
455 rwp->r_rhs = null_list;
459 case 'S': /* select rewriting set */
460 expand(&bp[1], exbuf, sizeof(exbuf), e);
461 ruleset = strtorwset(exbuf, NULL, ST_ENTER);
465 rwp = RewriteRules[ruleset];
468 if (OpMode == MD_TEST || OpMode == MD_CHECKCONFIG)
469 (void) sm_io_fprintf(smioout,
471 "WARNING: Ruleset %s has multiple definitions\n",
474 sm_dprintf("WARNING: Ruleset %s has multiple definitions\n",
476 while (rwp->r_next != NULL)
481 case 'D': /* macro definition */
482 mid = macid_parse(&bp[1], &ep);
485 p = munchstring(ep, NULL, '\0');
486 macdefine(&e->e_macro, A_TEMP, mid, p);
489 case 'H': /* required header line */
490 (void) chompheader(&bp[1], CHHDR_DEF, NULL, e);
493 case 'C': /* word class */
494 case 'T': /* trusted user (set class `t') */
497 mid = macid_parse(&bp[1], &ep);
500 expand(ep, exbuf, sizeof(exbuf), e);
513 while (*p != '\0' && isascii(*p) && isspace(*p))
516 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
526 case 'F': /* word class from file */
527 mid = macid_parse(&bp[1], &ep);
530 for (p = ep; isascii(*p) && isspace(*p); )
532 if (p[0] == '-' && p[1] == 'o')
536 !(isascii(*p) && isspace(*p)))
538 while (isascii(*p) && isspace(*p))
544 /* check if [key]@map:spec */
546 if (!SM_IS_DIR_DELIM(*p) &&
548 (q = strchr(p, '@')) != NULL)
552 /* look for @LDAP or @map: in string */
553 if (strcmp(q, "LDAP") == 0 ||
555 strchr(q, ':') != NULL))
561 /* use entire spec */
566 file = extrquotstr(p, &q, " ", &ok);
569 syserr("illegal filename '%s'", p);
574 if (*file == '|' || ismap)
584 while (isascii(*++p) && isspace(*p))
588 fileclass(mid, file, p, ismap, safe, optional);
592 case 'L': /* extended load average description */
597 #if defined(SUN_EXTENSIONS) && defined(SUN_LOOKUP_MACRO)
598 case 'L': /* lookup macro */
599 case 'G': /* lookup class */
600 /* reserved for Sun -- NIS+ database lookup */
601 if (VendorCode != VENDOR_SUN)
603 sun_lg_config_line(bp, e);
605 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_LOOKUP_MACRO) */
607 case 'M': /* define mailer */
611 case 'O': /* set option */
612 setoption(bp[1], &bp[2], safe, false, e);
615 case 'P': /* set precedence */
616 if (NumPriorities >= MAXPRIORITIES)
618 toomany('P', MAXPRIORITIES);
621 for (p = &bp[1]; *p != '\0' && *p != '='; p++)
626 Priorities[NumPriorities].pri_name = newstr(&bp[1]);
627 Priorities[NumPriorities].pri_val = atoi(++p);
631 case 'Q': /* define queue */
632 makequeue(&bp[1], true);
635 case 'V': /* configuration syntax version */
636 for (p = &bp[1]; isascii(*p) && isspace(*p); p++)
638 if (!isascii(*p) || !isdigit(*p))
640 syserr("invalid argument to V line: \"%.20s\"",
644 ConfigLevel = strtol(p, &ep, 10);
647 ** Do heuristic tweaking for back compatibility.
650 if (ConfigLevel >= 5)
652 /* level 5 configs have short name in $w */
653 p = macvalue('w', e);
654 if (p != NULL && (p = strchr(p, '.')) != NULL)
657 macdefine(&e->e_macro, A_TEMP, 'w',
661 if (ConfigLevel >= 6)
663 ColonOkInAddr = false;
667 ** Look for vendor code.
672 /* extract vendor code */
673 for (p = ep; isascii(*p) && isalpha(*p); )
678 syserr("invalid V line vendor code: \"%s\"",
684 expand(&bp[1], exbuf, sizeof(exbuf), e);
685 (void) makemapentry(exbuf);
692 sm_setuserenv(&bp[1], p);
695 case 'X': /* mail filter */
697 milter_setup(&bp[1]);
699 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
700 "Warning: Filter usage ('X') requires Milter support (-DMILTER)\n");
706 syserr("unknown configuration line \"%s\"", bp);
709 sm_free(bp); /* XXX */
713 syserr("I/O read error");
714 finis(false, true, EX_OSFILE);
716 (void) sm_io_close(cf, SM_TIME_DEFAULT);
719 /* initialize host maps from local service tables */
722 /* initialize daemon (if not defined yet) */
725 /* determine if we need to do special name-server frotz */
728 char *maptype[MAXMAPSTACK];
729 short mapreturn[MAXMAPACTIONS];
731 nmaps = switch_map_find("hosts", maptype, mapreturn);
732 UseNameServer = false;
733 if (nmaps > 0 && nmaps <= MAXMAPSTACK)
737 for (mapno = 0; mapno < nmaps && !UseNameServer;
740 if (strcmp(maptype[mapno], "dns") == 0)
741 UseNameServer = true;
748 ** TRANSLATE_DOLLARS -- convert $x into internal form
750 ** Actually does all appropriate pre-processing of a config line
751 ** to turn it into internal form.
754 ** ibp -- the buffer to translate.
755 ** obp -- where to put the translation; may be the same as obp
756 ** bsp -- a pointer to the size of obp; will be updated if
757 ** the buffer needs to be replaced.
760 ** The buffer pointer; may differ from obp if the expansion
761 ** is larger then *bsp, in which case this will point to
762 ** malloc()ed memory which must be free()d by the caller.
766 translate_dollars(ibp, obp, bsp)
777 sm_dprintf("translate_dollars(");
778 xputs(sm_debug_file(), ibp);
782 bp = quote_internal_chars(ibp, obp, bsp);
784 for (p = bp; *p != '\0'; p++)
786 if (*p == '#' && p > bp && ConfigLevel >= 3)
793 /* it's from $# -- let it go through */
798 /* it's backslash escaped */
799 (void) sm_strlcpy(p, p + 1, strlen(p));
803 /* delete leading white space */
804 while (isascii(*p) && isspace(*p) &&
805 *p != '\n' && p > bp)
809 if ((e = strchr(++p, '\n')) != NULL)
810 (void) sm_strlcpy(p, e, strlen(p));
818 if (*p != '$' || p[1] == '\0')
823 /* actual dollar sign.... */
824 (void) sm_strlcpy(p, p + 1, strlen(p));
828 /* convert to macro expansion character */
831 /* special handling for $=, $~, $&, and $? */
832 if (*p == '=' || *p == '~' || *p == '&' || *p == '?')
835 /* convert macro name to code */
836 *p = macid_parse(p, &ep);
838 (void) sm_strlcpy(p + 1, ep, strlen(p + 1));
841 /* strip trailing white space from the line */
842 while (--p > bp && isascii(*p) && isspace(*p))
847 sm_dprintf(" translate_dollars => ");
848 xputs(sm_debug_file(), bp);
855 ** TOOMANY -- signal too many of some option
858 ** id -- the id of the error line
859 ** maxcnt -- the maximum possible values
873 syserr("too many %c lines, %d max", id, maxcnt);
876 ** FILECLASS -- read members of a class from a file
879 ** class -- class to define.
880 ** filename -- name of file to read.
881 ** fmt -- scanf string to use for match.
882 ** ismap -- if set, this is a map lookup.
883 ** safe -- if set, this is a safe read.
884 ** optional -- if set, it is not an error for the file to
891 ** puts all lines in filename that match a scanf into
896 ** Break up the match into words and add to class.
900 parse_class_words(class, line)
904 while (line != NULL && *line != '\0')
908 /* strip leading spaces */
909 while (isascii(*line) && isspace(*line))
914 /* find the end of the word */
916 while (*line != '\0' && !(isascii(*line) && isspace(*line)))
921 /* enter the word in the symbol table */
927 fileclass(class, filename, fmt, ismap, safe, optional)
942 sm_dprintf("fileclass(%s, fmt=%s)\n", filename, fmt);
944 if (*filename == '\0')
946 syserr("fileclass: missing file name");
958 mn = newstr(macname(class));
963 if ((p = strchr(filename, '@')) == NULL)
965 /* should not happen */
966 syserr("fileclass: bogus map specification");
976 if (strcmp(cl, "LDAP") == 0)
980 char jbuf[MAXHOSTNAMELEN];
984 expand("\201j", jbuf, sizeof(jbuf), &BlankEnvelope);
987 (void) sm_strlcpy(jbuf, "localhost",
991 /* impose the default schema */
992 lc = macvalue(macid("{sendmailMTACluster}"), CurEnv);
997 expand(lc, lcbuf, sizeof(lcbuf), CurEnv);
1002 n = sm_snprintf(buf, sizeof(buf),
1003 "-k (&(objectClass=sendmailMTAClass)(sendmailMTAClassName=%s)(|(sendmailMTACluster=%s)(sendmailMTAHost=%s))) -v sendmailMTAClassValue,sendmailMTAClassSearch:FILTER:sendmailMTAClass,sendmailMTAClassURL:URL:sendmailMTAClass",
1005 if (n >= sizeof(buf))
1007 syserr("fileclass: F{%s}: Default LDAP string too long",
1015 #endif /* LDAPMAP */
1017 if ((spec = strchr(cl, ':')) == NULL)
1019 syserr("fileclass: F{%s}: missing map class",
1027 /* set up map structure */
1028 mapclass = stab(cl, ST_MAPCLASS, ST_FIND);
1029 if (mapclass == NULL)
1031 syserr("fileclass: F{%s}: class %s not available",
1036 memset(&map, '\0', sizeof(map));
1037 map.map_class = &mapclass->s_mapclass;
1039 map.map_mflags |= MF_FILECLASS;
1042 sm_dprintf("fileclass: F{%s}: map class %s, key %s, spec %s\n",
1046 /* parse map spec */
1047 if (!map.map_class->map_parse(&map, spec))
1049 /* map_parse() showed the error already */
1053 map.map_mflags |= MF_VALID;
1056 if (map.map_class->map_open(&map, O_RDONLY))
1058 map.map_mflags |= MF_OPEN;
1059 map.map_pid = getpid();
1064 !bitset(MF_OPTIONAL, map.map_mflags))
1065 syserr("fileclass: F{%s}: map open failed",
1072 p = (*map.map_class->map_lookup)(&map, key, NULL, &status);
1073 if (status != EX_OK && status != EX_NOTFOUND)
1076 syserr("fileclass: F{%s}: map lookup failed",
1081 /* use the results */
1083 parse_class_words(class, p);
1086 map.map_mflags |= MF_CLOSING;
1087 map.map_class->map_close(&map);
1088 map.map_mflags &= ~(MF_OPEN|MF_WRITABLE|MF_CLOSING);
1092 else if (filename[0] == '|')
1096 char *argv[MAXPV + 1];
1099 for (p = strtok(&filename[1], " \t");
1100 p != NULL && i < MAXPV;
1101 p = strtok(NULL, " \t"))
1104 pid = prog_open(argv, &fd, CurEnv);
1108 f = sm_io_open(SmFtStdiofd, SM_TIME_DEFAULT,
1109 (void *) &fd, SM_IO_RDONLY, NULL);
1115 if (!bitnset(DBS_CLASSFILEINUNSAFEDIRPATH, DontBlameSendmail))
1116 sff |= SFF_SAFEDIRPATH;
1117 if (!bitnset(DBS_LINKEDCLASSFILEINWRITABLEDIR,
1121 sff |= SFF_OPENASROOT;
1122 else if (RealUid == 0)
1124 if (DontLockReadFiles)
1126 f = safefopen(filename, O_RDONLY, 0, sff);
1131 syserr("fileclass: cannot open '%s'", filename);
1135 while (sm_io_fgets(f, SM_TIME_DEFAULT, buf, sizeof(buf)) != NULL)
1138 char wordbuf[MAXLINE + 1];
1144 if (sm_io_sscanf(buf, fmt, wordbuf) != 1)
1151 parse_class_words(class, p);
1154 ** If anything else is added here,
1155 ** check if the '@' map case above
1156 ** needs the code as well.
1160 (void) sm_io_close(f, SM_TIME_DEFAULT);
1162 (void) waitfor(pid);
1165 ** MAKEMAILER -- define a new mailer.
1168 ** line -- description of mailer. This is in labeled
1169 ** fields. The fields are:
1170 ** A -- the argv for this mailer
1171 ** C -- the character set for MIME conversions
1172 ** D -- the directory to run in
1173 ** E -- the eol string
1174 ** F -- the flags associated with the mailer
1175 ** L -- the maximum line length
1176 ** M -- the maximum message size
1177 ** N -- the niceness at which to run
1178 ** P -- the path to the mailer
1179 ** Q -- the queue group for the mailer
1180 ** R -- the recipient rewriting set
1181 ** S -- the sender rewriting set
1182 ** T -- the mailer type (for DSNs)
1183 ** U -- the uid to run as
1184 ** W -- the time to wait at the end
1185 ** m -- maximum messages per connection
1186 ** r -- maximum number of recipients per message
1187 ** / -- new root directory
1188 ** The first word is the canonical name of the mailer.
1194 ** enters the mailer into the mailer table.
1202 register struct mailer *m;
1207 static int nextmailer = 0; /* "free" index into Mailer struct */
1209 /* allocate a mailer and set up defaults */
1210 m = (struct mailer *) xalloc(sizeof(*m));
1211 memset((char *) m, '\0', sizeof(*m));
1212 errno = 0; /* avoid bogus error text */
1214 /* collect the mailer name */
1216 *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p));
1221 if (line[0] == '\0')
1223 syserr("name required for mailer");
1226 m->m_name = newstr(line);
1231 /* now scan through and assign info from the fields */
1234 auto char *delimptr;
1236 while (*p != '\0' &&
1237 (*p == ',' || (isascii(*p) && isspace(*p))))
1240 /* p now points to field code */
1242 while (*p != '\0' && *p != '=' && *p != ',')
1246 syserr("mailer %s: `=' expected", m->m_name);
1249 while (isascii(*p) && isspace(*p))
1252 /* p now points to the field body */
1253 p = munchstring(p, &delimptr, ',');
1255 /* install the field into the mailer struct */
1258 case 'P': /* pathname */
1259 if (*p != '\0') /* error is issued below */
1260 m->m_mailer = newstr(p);
1263 case 'F': /* flags */
1264 for (; *p != '\0'; p++)
1266 if (!(isascii(*p) && isspace(*p)))
1268 #if _FFR_DEPRECATE_MAILER_FLAG_I
1269 if (*p == M_INTERNAL)
1270 sm_syslog(LOG_WARNING, NOQID,
1271 "WARNING: mailer=%s, flag=%c deprecated",
1273 #endif /* _FFR_DEPRECATE_MAILER_FLAG_I */
1274 setbitn(bitidx(*p), m->m_flags);
1279 case 'S': /* sender rewriting ruleset */
1280 case 'R': /* recipient rewriting ruleset */
1281 i = strtorwset(p, &endp, ST_ENTER);
1285 m->m_sh_rwset = m->m_se_rwset = i;
1287 m->m_rh_rwset = m->m_re_rwset = i;
1292 i = strtorwset(p, NULL, ST_ENTER);
1302 case 'E': /* end of line string */
1304 syserr("mailer %s: null end-of-line string",
1307 m->m_eol = newstr(p);
1310 case 'A': /* argument vector */
1311 if (*p != '\0') /* error is issued below */
1312 m->m_argv = makeargv(p);
1315 case 'M': /* maximum message size */
1316 m->m_maxsize = atol(p);
1319 case 'm': /* maximum messages per connection */
1320 m->m_maxdeliveries = atoi(p);
1323 case 'r': /* max recipient per envelope */
1324 m->m_maxrcpt = atoi(p);
1327 case 'L': /* maximum line length */
1328 m->m_linelimit = atoi(p);
1329 if (m->m_linelimit < 0)
1333 case 'N': /* run niceness */
1334 m->m_nice = atoi(p);
1337 case 'D': /* working directory */
1339 syserr("mailer %s: null working directory",
1342 m->m_execdir = newstr(p);
1345 case 'C': /* default charset */
1347 syserr("mailer %s: null charset", m->m_name);
1349 m->m_defcharset = newstr(p);
1352 case 'Q': /* queue for this mailer */
1355 syserr("mailer %s: null queue", m->m_name);
1358 s = stab(p, ST_QUEUE, ST_FIND);
1360 syserr("mailer %s: unknown queue %s",
1363 m->m_qgrp = s->s_quegrp->qg_index;
1366 case 'T': /* MTA-Name/Address/Diagnostic types */
1367 /* extract MTA name type; default to "dns" */
1368 m->m_mtatype = newstr(p);
1369 p = strchr(m->m_mtatype, '/');
1376 if (*m->m_mtatype == '\0')
1377 m->m_mtatype = "dns";
1379 /* extract address type; default to "rfc822" */
1389 if (m->m_addrtype == NULL || *m->m_addrtype == '\0')
1390 m->m_addrtype = "rfc822";
1392 /* extract diagnostic type; default to "smtp" */
1394 if (m->m_diagtype == NULL || *m->m_diagtype == '\0')
1395 m->m_diagtype = "smtp";
1398 case 'U': /* user id */
1399 if (isascii(*p) && !isdigit(*p))
1404 while (*p != '\0' && isascii(*p) &&
1405 (isalnum(*p) || strchr("-_", *p) != NULL))
1407 while (isascii(*p) && isspace(*p))
1413 syserr("mailer %s: null user name",
1417 pw = sm_getpwnam(q);
1420 syserr("readcf: mailer U= flag: unknown user %s", q);
1425 m->m_uid = pw->pw_uid;
1426 m->m_gid = pw->pw_gid;
1433 m->m_uid = strtol(p, &q, 0);
1435 while (isascii(*p) && isspace(*p))
1440 while (isascii(*p) && isspace(*p))
1444 if (isascii(*p) && !isdigit(*p))
1449 while (isascii(*p) && isalnum(*p))
1454 syserr("mailer %s: null group name",
1461 syserr("readcf: mailer U= flag: unknown group %s", q);
1465 m->m_gid = gr->gr_gid;
1469 m->m_gid = strtol(p, NULL, 0);
1473 case 'W': /* wait timeout */
1474 m->m_wait = convtime(p, 's');
1477 case '/': /* new root directory */
1479 syserr("mailer %s: null root directory",
1482 m->m_rootdir = newstr(p);
1486 syserr("M%s: unknown mailer equate %c=",
1495 if (bitnset(M_SECURE_PORT, m->m_flags))
1497 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1498 "M%s: Warning: F=%c set on system that doesn't support rresvport()\n",
1499 m->m_name, M_SECURE_PORT);
1501 #endif /* !HASRRESVPORT */
1506 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1507 "M%s: Warning: N= set on system that doesn't support nice()\n",
1510 #endif /* !HASNICE */
1512 /* do some rationality checking */
1513 if (m->m_argv == NULL)
1515 syserr("M%s: A= argument required", m->m_name);
1518 if (m->m_mailer == NULL)
1520 syserr("M%s: P= argument required", m->m_name);
1524 if (nextmailer >= MAXMAILERS)
1526 syserr("too many mailers defined (%d max)", MAXMAILERS);
1530 if (m->m_maxrcpt <= 0)
1531 m->m_maxrcpt = DEFAULT_MAX_RCPT;
1533 /* do some heuristic cleanup for back compatibility */
1534 if (bitnset(M_LIMITS, m->m_flags))
1536 if (m->m_linelimit == 0)
1537 m->m_linelimit = SMTPLINELIM;
1538 if (ConfigLevel < 2)
1539 setbitn(M_7BITS, m->m_flags);
1542 if (strcmp(m->m_mailer, "[TCP]") == 0)
1544 syserr("M%s: P=[TCP] must be replaced by P=[IPC]", m->m_name);
1548 if (strcmp(m->m_mailer, "[IPC]") == 0)
1550 /* Use the second argument for host or path to socket */
1551 if (m->m_argv[0] == NULL || m->m_argv[1] == NULL ||
1552 m->m_argv[1][0] == '\0')
1554 syserr("M%s: too few parameters for %s mailer",
1555 m->m_name, m->m_mailer);
1558 if (strcmp(m->m_argv[0], "TCP") != 0
1560 && strcmp(m->m_argv[0], "FILE") != 0
1561 #endif /* NETUNIX */
1564 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1565 "M%s: Warning: first argument in %s mailer must be %s\n",
1566 m->m_name, m->m_mailer,
1571 #endif /* NETUNIX */
1574 if (m->m_mtatype == NULL)
1575 m->m_mtatype = "dns";
1576 if (m->m_addrtype == NULL)
1577 m->m_addrtype = "rfc822";
1578 if (m->m_diagtype == NULL)
1580 if (m->m_argv[0] != NULL &&
1581 strcmp(m->m_argv[0], "FILE") == 0)
1582 m->m_diagtype = "x-unix";
1584 m->m_diagtype = "smtp";
1587 else if (strcmp(m->m_mailer, "[FILE]") == 0)
1589 /* Use the second argument for filename */
1590 if (m->m_argv[0] == NULL || m->m_argv[1] == NULL ||
1591 m->m_argv[2] != NULL)
1593 syserr("M%s: too %s parameters for [FILE] mailer",
1595 (m->m_argv[0] == NULL ||
1596 m->m_argv[1] == NULL) ? "few" : "many");
1599 else if (strcmp(m->m_argv[0], "FILE") != 0)
1601 syserr("M%s: first argument in [FILE] mailer must be FILE",
1607 if (m->m_eol == NULL)
1611 /* default for SMTP is \r\n; use \n for local delivery */
1612 for (pp = m->m_argv; *pp != NULL; pp++)
1614 for (p = *pp; *p != '\0'; )
1616 if ((*p++ & 0377) == MACROEXPAND && *p == 'u')
1628 /* enter the mailer into the symbol table */
1629 s = stab(m->m_name, ST_MAILER, ST_ENTER);
1630 if (s->s_mailer != NULL)
1632 i = s->s_mailer->m_mno;
1633 sm_free(s->s_mailer); /* XXX */
1639 Mailer[i] = s->s_mailer = m;
1643 ** MUNCHSTRING -- translate a string into internal form.
1646 ** p -- the string to munch.
1647 ** delimptr -- if non-NULL, set to the pointer of the
1648 ** field delimiter character.
1649 ** delim -- the delimiter for the field.
1652 ** the munched string.
1655 ** the munched string is a local static buffer.
1656 ** it must be copied before the function is called again.
1660 munchstring(p, delimptr, delim)
1666 bool backslash = false;
1667 bool quotemode = false;
1668 static char buf[MAXLINE];
1670 for (q = buf; *p != '\0' && q < &buf[sizeof(buf) - 1]; p++)
1674 /* everything is roughly literal */
1678 case 'r': /* carriage return */
1682 case 'n': /* newline */
1686 case 'f': /* form feed */
1690 case 'b': /* backspace */
1701 quotemode = !quotemode;
1702 else if (quotemode || *p != delim)
1709 if (delimptr != NULL)
1715 ** EXTRQUOTSTR -- extract a (quoted) string.
1717 ** This routine deals with quoted (") strings and escaped
1721 ** p -- source string.
1722 ** delimptr -- if non-NULL, set to the pointer of the
1723 ** field delimiter character.
1724 ** delimbuf -- delimiters for the field.
1725 ** st -- if non-NULL, store the return value (whether the
1726 ** string was correctly quoted) here.
1729 ** the extracted string.
1732 ** the returned string is a local static buffer.
1733 ** it must be copied before the function is called again.
1737 extrquotstr(p, delimptr, delimbuf, st)
1744 bool backslash = false;
1745 bool quotemode = false;
1746 static char buf[MAXLINE];
1748 for (q = buf; *p != '\0' && q < &buf[sizeof(buf) - 1]; p++)
1759 quotemode = !quotemode;
1760 else if (quotemode ||
1761 strchr(delimbuf, (int) *p) == NULL)
1767 if (delimptr != NULL)
1771 *st = !(quotemode || backslash);
1775 ** MAKEARGV -- break up a string into words
1778 ** p -- the string to break up.
1781 ** a char **argv (dynamically allocated)
1794 char *argv[MAXPV + 1];
1796 /* take apart the words */
1798 while (*p != '\0' && i < MAXPV)
1801 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
1803 while (isascii(*p) && isspace(*p))
1805 argv[i++] = newstr(q);
1809 /* now make a copy of the argv */
1810 avp = (char **) xalloc(sizeof(*avp) * i);
1811 memmove((char *) avp, (char *) argv, sizeof(*avp) * i);
1816 ** PRINTRULES -- print rewrite rules (for debugging)
1825 ** prints rewrite rules.
1831 register struct rewrite *rwp;
1832 register int ruleset;
1834 for (ruleset = 0; ruleset < 10; ruleset++)
1836 if (RewriteRules[ruleset] == NULL)
1838 sm_dprintf("\n----Rule Set %d:", ruleset);
1840 for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
1842 sm_dprintf("\nLHS:");
1843 printav(sm_debug_file(), rwp->r_lhs);
1845 printav(sm_debug_file(), rwp->r_rhs);
1850 ** PRINTMAILER -- print mailer structure (for debugging)
1853 ** fp -- output file
1854 ** m -- the mailer to print
1867 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT,
1868 "mailer %d (%s): P=%s S=", m->m_mno, m->m_name,
1870 if (RuleSetNames[m->m_se_rwset] == NULL)
1871 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d/",
1874 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s/",
1875 RuleSetNames[m->m_se_rwset]);
1876 if (RuleSetNames[m->m_sh_rwset] == NULL)
1877 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d R=",
1880 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s R=",
1881 RuleSetNames[m->m_sh_rwset]);
1882 if (RuleSetNames[m->m_re_rwset] == NULL)
1883 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d/",
1886 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s/",
1887 RuleSetNames[m->m_re_rwset]);
1888 if (RuleSetNames[m->m_rh_rwset] == NULL)
1889 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d ",
1892 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s ",
1893 RuleSetNames[m->m_rh_rwset]);
1894 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "M=%ld U=%d:%d F=",
1895 m->m_maxsize, (int) m->m_uid, (int) m->m_gid);
1896 for (j = '\0'; j <= '\177'; j++)
1897 if (bitnset(j, m->m_flags))
1898 (void) sm_io_putc(fp, SM_TIME_DEFAULT, j);
1899 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " L=%d E=",
1901 xputs(fp, m->m_eol);
1902 if (m->m_defcharset != NULL)
1903 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " C=%s",
1905 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " T=%s/%s/%s",
1906 m->m_mtatype == NULL
1907 ? "<undefined>" : m->m_mtatype,
1908 m->m_addrtype == NULL
1909 ? "<undefined>" : m->m_addrtype,
1910 m->m_diagtype == NULL
1911 ? "<undefined>" : m->m_diagtype);
1912 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " r=%d", m->m_maxrcpt);
1913 if (m->m_argv != NULL)
1915 char **a = m->m_argv;
1917 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " A=");
1921 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT,
1926 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "\n");
1929 ** SETOPTION -- set global processing option
1932 ** opt -- option name.
1933 ** val -- option value (as a text string).
1934 ** safe -- set if this came from a configuration file.
1935 ** Some options (if set from the command line) will
1936 ** reset the user id to avoid security problems.
1937 ** sticky -- if set, don't let other setoptions override
1939 ** e -- the main envelope.
1945 ** Sets options as implied by the arguments.
1948 static BITMAP256 StickyOpt; /* set if option is stuck */
1952 static struct resolverflags
1954 char *rf_name; /* name of the flag */
1955 long rf_bits; /* bits to set/clear */
1958 { "debug", RES_DEBUG },
1959 { "aaonly", RES_AAONLY },
1960 { "usevc", RES_USEVC },
1961 { "primary", RES_PRIMARY },
1962 { "igntc", RES_IGNTC },
1963 { "recurse", RES_RECURSE },
1964 { "defnames", RES_DEFNAMES },
1965 { "stayopen", RES_STAYOPEN },
1966 { "dnsrch", RES_DNSRCH },
1967 # ifdef RES_USE_INET6
1968 { "use_inet6", RES_USE_INET6 },
1969 # endif /* RES_USE_INET6 */
1970 { "true", 0 }, /* avoid error on old syntax */
1974 #endif /* NAMED_BIND */
1976 #define OI_NONE 0 /* no special treatment */
1977 #define OI_SAFE 0x0001 /* safe for random people to use */
1978 #define OI_SUBOPT 0x0002 /* option has suboptions */
1980 static struct optioninfo
1982 char *o_name; /* long name of option */
1983 unsigned char o_code; /* short name of option */
1984 unsigned short o_flags; /* option flags */
1987 #if defined(SUN_EXTENSIONS) && defined(REMOTE_MODE)
1988 { "RemoteMode", '>', OI_NONE },
1989 #endif /* defined(SUN_EXTENSIONS) && defined(REMOTE_MODE) */
1990 { "SevenBitInput", '7', OI_SAFE },
1991 { "EightBitMode", '8', OI_SAFE },
1992 { "AliasFile", 'A', OI_NONE },
1993 { "AliasWait", 'a', OI_NONE },
1994 { "BlankSub", 'B', OI_NONE },
1995 { "MinFreeBlocks", 'b', OI_SAFE },
1996 { "CheckpointInterval", 'C', OI_SAFE },
1997 { "HoldExpensive", 'c', OI_NONE },
1998 { "DeliveryMode", 'd', OI_SAFE },
1999 { "ErrorHeader", 'E', OI_NONE },
2000 { "ErrorMode", 'e', OI_SAFE },
2001 { "TempFileMode", 'F', OI_NONE },
2002 { "SaveFromLine", 'f', OI_NONE },
2003 { "MatchGECOS", 'G', OI_NONE },
2005 /* no long name, just here to avoid problems in setoption */
2006 { "", 'g', OI_NONE },
2007 { "HelpFile", 'H', OI_NONE },
2008 { "MaxHopCount", 'h', OI_NONE },
2009 { "ResolverOptions", 'I', OI_NONE },
2010 { "IgnoreDots", 'i', OI_SAFE },
2011 { "ForwardPath", 'J', OI_NONE },
2012 { "SendMimeErrors", 'j', OI_SAFE },
2013 { "ConnectionCacheSize", 'k', OI_NONE },
2014 { "ConnectionCacheTimeout", 'K', OI_NONE },
2015 { "UseErrorsTo", 'l', OI_NONE },
2016 { "LogLevel", 'L', OI_SAFE },
2017 { "MeToo", 'm', OI_SAFE },
2019 /* no long name, just here to avoid problems in setoption */
2020 { "", 'M', OI_NONE },
2021 { "CheckAliases", 'n', OI_NONE },
2022 { "OldStyleHeaders", 'o', OI_SAFE },
2023 { "DaemonPortOptions", 'O', OI_NONE },
2024 { "PrivacyOptions", 'p', OI_SAFE },
2025 { "PostmasterCopy", 'P', OI_NONE },
2026 { "QueueFactor", 'q', OI_NONE },
2027 { "QueueDirectory", 'Q', OI_NONE },
2028 { "DontPruneRoutes", 'R', OI_NONE },
2029 { "Timeout", 'r', OI_SUBOPT },
2030 { "StatusFile", 'S', OI_NONE },
2031 { "SuperSafe", 's', OI_SAFE },
2032 { "QueueTimeout", 'T', OI_NONE },
2033 { "TimeZoneSpec", 't', OI_NONE },
2034 { "UserDatabaseSpec", 'U', OI_NONE },
2035 { "DefaultUser", 'u', OI_NONE },
2036 { "FallbackMXhost", 'V', OI_NONE },
2037 { "Verbose", 'v', OI_SAFE },
2038 { "TryNullMXList", 'w', OI_NONE },
2039 { "QueueLA", 'x', OI_NONE },
2040 { "RefuseLA", 'X', OI_NONE },
2041 { "RecipientFactor", 'y', OI_NONE },
2042 { "ForkEachJob", 'Y', OI_NONE },
2043 { "ClassFactor", 'z', OI_NONE },
2044 { "RetryFactor", 'Z', OI_NONE },
2045 #define O_QUEUESORTORD 0x81
2046 { "QueueSortOrder", O_QUEUESORTORD, OI_SAFE },
2047 #define O_HOSTSFILE 0x82
2048 { "HostsFile", O_HOSTSFILE, OI_NONE },
2050 { "MinQueueAge", O_MQA, OI_SAFE },
2051 #define O_DEFCHARSET 0x85
2052 { "DefaultCharSet", O_DEFCHARSET, OI_SAFE },
2053 #define O_SSFILE 0x86
2054 { "ServiceSwitchFile", O_SSFILE, OI_NONE },
2055 #define O_DIALDELAY 0x87
2056 { "DialDelay", O_DIALDELAY, OI_SAFE },
2057 #define O_NORCPTACTION 0x88
2058 { "NoRecipientAction", O_NORCPTACTION, OI_SAFE },
2059 #define O_SAFEFILEENV 0x89
2060 { "SafeFileEnvironment", O_SAFEFILEENV, OI_NONE },
2061 #define O_MAXMSGSIZE 0x8a
2062 { "MaxMessageSize", O_MAXMSGSIZE, OI_NONE },
2063 #define O_COLONOKINADDR 0x8b
2064 { "ColonOkInAddr", O_COLONOKINADDR, OI_SAFE },
2065 #define O_MAXQUEUERUN 0x8c
2066 { "MaxQueueRunSize", O_MAXQUEUERUN, OI_SAFE },
2067 #define O_MAXCHILDREN 0x8d
2068 { "MaxDaemonChildren", O_MAXCHILDREN, OI_NONE },
2069 #define O_KEEPCNAMES 0x8e
2070 { "DontExpandCnames", O_KEEPCNAMES, OI_NONE },
2071 #define O_MUSTQUOTE 0x8f
2072 { "MustQuoteChars", O_MUSTQUOTE, OI_NONE },
2073 #define O_SMTPGREETING 0x90
2074 { "SmtpGreetingMessage", O_SMTPGREETING, OI_NONE },
2075 #define O_UNIXFROM 0x91
2076 { "UnixFromLine", O_UNIXFROM, OI_NONE },
2077 #define O_OPCHARS 0x92
2078 { "OperatorChars", O_OPCHARS, OI_NONE },
2079 #define O_DONTINITGRPS 0x93
2080 { "DontInitGroups", O_DONTINITGRPS, OI_NONE },
2082 { "SingleLineFromHeader", O_SLFH, OI_SAFE },
2084 { "AllowBogusHELO", O_ABH, OI_SAFE },
2085 #define O_CONNTHROT 0x97
2086 { "ConnectionRateThrottle", O_CONNTHROT, OI_NONE },
2088 { "UnsafeGroupWrites", O_UGW, OI_NONE },
2089 #define O_DBLBOUNCE 0x9a
2090 { "DoubleBounceAddress", O_DBLBOUNCE, OI_NONE },
2091 #define O_HSDIR 0x9b
2092 { "HostStatusDirectory", O_HSDIR, OI_NONE },
2093 #define O_SINGTHREAD 0x9c
2094 { "SingleThreadDelivery", O_SINGTHREAD, OI_NONE },
2095 #define O_RUNASUSER 0x9d
2096 { "RunAsUser", O_RUNASUSER, OI_NONE },
2097 #define O_DSN_RRT 0x9e
2098 { "RrtImpliesDsn", O_DSN_RRT, OI_NONE },
2099 #define O_PIDFILE 0x9f
2100 { "PidFile", O_PIDFILE, OI_NONE },
2101 #define O_DONTBLAMESENDMAIL 0xa0
2102 { "DontBlameSendmail", O_DONTBLAMESENDMAIL, OI_NONE },
2104 { "DontProbeInterfaces", O_DPI, OI_NONE },
2105 #define O_MAXRCPT 0xa2
2106 { "MaxRecipientsPerMessage", O_MAXRCPT, OI_SAFE },
2107 #define O_DEADLETTER 0xa3
2108 { "DeadLetterDrop", O_DEADLETTER, OI_NONE },
2109 #if _FFR_DONTLOCKFILESFORREAD_OPTION
2110 # define O_DONTLOCK 0xa4
2111 { "DontLockFilesForRead", O_DONTLOCK, OI_NONE },
2112 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
2113 #define O_MAXALIASRCSN 0xa5
2114 { "MaxAliasRecursion", O_MAXALIASRCSN, OI_NONE },
2115 #define O_CNCTONLYTO 0xa6
2116 { "ConnectOnlyTo", O_CNCTONLYTO, OI_NONE },
2117 #define O_TRUSTUSER 0xa7
2118 { "TrustedUser", O_TRUSTUSER, OI_NONE },
2119 #define O_MAXMIMEHDRLEN 0xa8
2120 { "MaxMimeHeaderLength", O_MAXMIMEHDRLEN, OI_NONE },
2121 #define O_CONTROLSOCKET 0xa9
2122 { "ControlSocketName", O_CONTROLSOCKET, OI_NONE },
2123 #define O_MAXHDRSLEN 0xaa
2124 { "MaxHeadersLength", O_MAXHDRSLEN, OI_NONE },
2125 #if _FFR_MAX_FORWARD_ENTRIES
2126 # define O_MAXFORWARD 0xab
2127 { "MaxForwardEntries", O_MAXFORWARD, OI_NONE },
2128 #endif /* _FFR_MAX_FORWARD_ENTRIES */
2129 #define O_PROCTITLEPREFIX 0xac
2130 { "ProcessTitlePrefix", O_PROCTITLEPREFIX, OI_NONE },
2131 #define O_SASLINFO 0xad
2132 #if _FFR_ALLOW_SASLINFO
2133 { "DefaultAuthInfo", O_SASLINFO, OI_SAFE },
2134 #else /* _FFR_ALLOW_SASLINFO */
2135 { "DefaultAuthInfo", O_SASLINFO, OI_NONE },
2136 #endif /* _FFR_ALLOW_SASLINFO */
2137 #define O_SASLMECH 0xae
2138 { "AuthMechanisms", O_SASLMECH, OI_NONE },
2139 #define O_CLIENTPORT 0xaf
2140 { "ClientPortOptions", O_CLIENTPORT, OI_NONE },
2141 #define O_DF_BUFSIZE 0xb0
2142 { "DataFileBufferSize", O_DF_BUFSIZE, OI_NONE },
2143 #define O_XF_BUFSIZE 0xb1
2144 { "XscriptFileBufferSize", O_XF_BUFSIZE, OI_NONE },
2145 #define O_LDAPDEFAULTSPEC 0xb2
2146 { "LDAPDefaultSpec", O_LDAPDEFAULTSPEC, OI_NONE },
2147 #define O_SRVCERTFILE 0xb4
2148 { "ServerCertFile", O_SRVCERTFILE, OI_NONE },
2149 #define O_SRVKEYFILE 0xb5
2150 { "ServerKeyFile", O_SRVKEYFILE, OI_NONE },
2151 #define O_CLTCERTFILE 0xb6
2152 { "ClientCertFile", O_CLTCERTFILE, OI_NONE },
2153 #define O_CLTKEYFILE 0xb7
2154 { "ClientKeyFile", O_CLTKEYFILE, OI_NONE },
2155 #define O_CACERTFILE 0xb8
2156 { "CACertFile", O_CACERTFILE, OI_NONE },
2157 #define O_CACERTPATH 0xb9
2158 { "CACertPath", O_CACERTPATH, OI_NONE },
2159 #define O_DHPARAMS 0xba
2160 { "DHParameters", O_DHPARAMS, OI_NONE },
2161 #define O_INPUTMILTER 0xbb
2162 { "InputMailFilters", O_INPUTMILTER, OI_NONE },
2163 #define O_MILTER 0xbc
2164 { "Milter", O_MILTER, OI_SUBOPT },
2165 #define O_SASLOPTS 0xbd
2166 { "AuthOptions", O_SASLOPTS, OI_NONE },
2167 #define O_QUEUE_FILE_MODE 0xbe
2168 { "QueueFileMode", O_QUEUE_FILE_MODE, OI_NONE },
2170 # define O_DHPARAMS5 0xbf
2171 { "DHParameters512", O_DHPARAMS5, OI_NONE },
2172 # define O_CIPHERLIST 0xc0
2173 { "CipherList", O_CIPHERLIST, OI_NONE },
2174 #endif /* _FFR_TLS_1 */
2175 #define O_RANDFILE 0xc1
2176 { "RandFile", O_RANDFILE, OI_NONE },
2177 #define O_TLS_SRV_OPTS 0xc2
2178 { "TLSSrvOptions", O_TLS_SRV_OPTS, OI_NONE },
2179 #define O_RCPTTHROT 0xc3
2180 { "BadRcptThrottle", O_RCPTTHROT, OI_SAFE },
2181 #define O_DLVR_MIN 0xc4
2182 { "DeliverByMin", O_DLVR_MIN, OI_NONE },
2183 #define O_MAXQUEUECHILDREN 0xc5
2184 { "MaxQueueChildren", O_MAXQUEUECHILDREN, OI_NONE },
2185 #define O_MAXRUNNERSPERQUEUE 0xc6
2186 { "MaxRunnersPerQueue", O_MAXRUNNERSPERQUEUE, OI_NONE },
2187 #define O_DIRECTSUBMODIFIERS 0xc7
2188 { "DirectSubmissionModifiers", O_DIRECTSUBMODIFIERS, OI_NONE },
2189 #define O_NICEQUEUERUN 0xc8
2190 { "NiceQueueRun", O_NICEQUEUERUN, OI_NONE },
2191 #define O_SHMKEY 0xc9
2192 { "SharedMemoryKey", O_SHMKEY, OI_NONE },
2193 #define O_SASLBITS 0xca
2194 { "AuthMaxBits", O_SASLBITS, OI_NONE },
2196 { "MailboxDatabase", O_MBDB, OI_NONE },
2198 { "UseMSP", O_MSQ, OI_NONE },
2199 #define O_DELAY_LA 0xcd
2200 { "DelayLA", O_DELAY_LA, OI_NONE },
2201 #define O_FASTSPLIT 0xce
2202 { "FastSplit", O_FASTSPLIT, OI_NONE },
2203 #define O_SOFTBOUNCE 0xcf
2204 { "SoftBounce", O_SOFTBOUNCE, OI_NONE },
2205 #define O_SHMKEYFILE 0xd0
2206 { "SharedMemoryKeyFile", O_SHMKEYFILE, OI_NONE },
2207 #define O_REJECTLOGINTERVAL 0xd1
2208 { "RejectLogInterval", O_REJECTLOGINTERVAL, OI_NONE },
2209 #define O_REQUIRES_DIR_FSYNC 0xd2
2210 { "RequiresDirfsync", O_REQUIRES_DIR_FSYNC, OI_NONE },
2211 #define O_CONNECTION_RATE_WINDOW_SIZE 0xd3
2212 { "ConnectionRateWindowSize", O_CONNECTION_RATE_WINDOW_SIZE, OI_NONE },
2213 #define O_CRLFILE 0xd4
2214 { "CRLFile", O_CRLFILE, OI_NONE },
2215 #define O_FALLBACKSMARTHOST 0xd5
2216 { "FallbackSmartHost", O_FALLBACKSMARTHOST, OI_NONE },
2217 #define O_SASLREALM 0xd6
2218 { "AuthRealm", O_SASLREALM, OI_NONE },
2220 # define O_CRLPATH 0xd7
2221 { "CRLPath", O_CRLPATH, OI_NONE },
2222 #endif /* _FFR_CRLPATH */
2223 #define O_HELONAME 0xd8
2224 { "HeloName", O_HELONAME, OI_NONE },
2226 # define O_REFUSELOWMEM 0xd9
2227 { "RefuseLowMem", O_REFUSELOWMEM, OI_NONE },
2228 # define O_QUEUELOWMEM 0xda
2229 { "QueueLowMem", O_QUEUELOWMEM, OI_NONE },
2230 # define O_MEMRESOURCE 0xdb
2231 { "MemoryResource", O_MEMRESOURCE, OI_NONE },
2232 #endif /* _FFR_MEMSTAT */
2233 #define O_MAXNOOPCOMMANDS 0xdc
2234 { "MaxNOOPCommands", O_MAXNOOPCOMMANDS, OI_NONE },
2236 # define O_MSG_ACCEPT 0xdd
2237 { "MessageAccept", O_MSG_ACCEPT, OI_NONE },
2238 #endif /* _FFR_MSG_ACCEPT */
2239 #if _FFR_QUEUE_RUN_PARANOIA
2240 # define O_CHK_Q_RUNNERS 0xde
2241 { "CheckQueueRunners", O_CHK_Q_RUNNERS, OI_NONE },
2242 #endif /* _FFR_QUEUE_RUN_PARANOIA */
2243 #if _FFR_EIGHT_BIT_ADDR_OK
2245 # ERROR FFR_EIGHT_BIT_ADDR_OK requires _ALLOW_255
2246 # endif /* !ALLOW_255 */
2247 # define O_EIGHT_BIT_ADDR_OK 0xdf
2248 { "EightBitAddrOK", O_EIGHT_BIT_ADDR_OK, OI_NONE },
2249 #endif /* _FFR_EIGHT_BIT_ADDR_OK */
2250 #if _FFR_ADDR_TYPE_MODES
2251 # define O_ADDR_TYPE_MODES 0xe0
2252 { "AddrTypeModes", O_ADDR_TYPE_MODES, OI_NONE },
2253 #endif /* _FFR_ADDR_TYPE_MODES */
2254 #if _FFR_BADRCPT_SHUTDOWN
2255 # define O_RCPTSHUTD 0xe1
2256 { "BadRcptShutdown", O_RCPTSHUTD, OI_SAFE },
2257 # define O_RCPTSHUTDG 0xe2
2258 { "BadRcptShutdownGood", O_RCPTSHUTDG, OI_SAFE },
2259 #endif /* _FFR_BADRCPT_SHUTDOWN */
2260 #if STARTTLS && _FFR_TLS_1
2261 # define O_SRV_SSL_OPTIONS 0xe3
2262 { "ServerSSLOptions", O_SRV_SSL_OPTIONS, OI_NONE },
2263 # define O_CLT_SSL_OPTIONS 0xe4
2264 { "ClientSSLOptions", O_CLT_SSL_OPTIONS, OI_NONE },
2265 #endif /* STARTTLS && _FFR_TLS_1 */
2267 # define O_MAX_QUEUE_AGE 0xe5
2268 { "MaxQueueAge", O_MAX_QUEUE_AGE, OI_NONE },
2269 #endif /* _FFR_EXPDELAY */
2270 #if _FFR_RCPTTHROTDELAY
2271 # define O_RCPTTHROTDELAY 0xe6
2272 { "BadRcptThrottleDelay", O_RCPTTHROTDELAY, OI_SAFE },
2273 #endif /* _FFR_RCPTTHROTDELAY */
2275 { NULL, '\0', OI_NONE }
2278 #if STARTTLS && _FFR_TLS_1
2279 static struct ssl_options
2281 const char *sslopt_name; /* name of the flag */
2282 long sslopt_bits; /* bits to set/clear */
2285 /* these are turned on by default */
2286 #ifdef SSL_OP_MICROSOFT_SESS_ID_BUG
2287 { "SSL_OP_MICROSOFT_SESS_ID_BUG", SSL_OP_MICROSOFT_SESS_ID_BUG },
2288 #endif /* SSL_OP_MICROSOFT_SESS_ID_BUG */
2289 #ifdef SSL_OP_NETSCAPE_CHALLENGE_BUG
2290 { "SSL_OP_NETSCAPE_CHALLENGE_BUG", SSL_OP_NETSCAPE_CHALLENGE_BUG },
2291 #endif /* SSL_OP_NETSCAPE_CHALLENGE_BUG */
2292 #ifdef SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG
2293 { "SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG", SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG },
2294 #endif /* SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG */
2295 #ifdef SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG
2296 { "SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG", SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG },
2297 #endif /* SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG */
2298 #ifdef SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER
2299 { "SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER", SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER },
2300 #endif /* SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER */
2301 #ifdef SSL_OP_MSIE_SSLV2_RSA_PADDING
2302 { "SSL_OP_MSIE_SSLV2_RSA_PADDING", SSL_OP_MSIE_SSLV2_RSA_PADDING },
2303 #endif /* SSL_OP_MSIE_SSLV2_RSA_PADDING */
2304 #ifdef SSL_OP_SSLEAY_080_CLIENT_DH_BUG
2305 { "SSL_OP_SSLEAY_080_CLIENT_DH_BUG", SSL_OP_SSLEAY_080_CLIENT_DH_BUG },
2306 #endif /* SSL_OP_SSLEAY_080_CLIENT_DH_BUG */
2307 #ifdef SSL_OP_TLS_D5_BUG
2308 { "SSL_OP_TLS_D5_BUG", SSL_OP_TLS_D5_BUG },
2309 #endif /* SSL_OP_TLS_D5_BUG */
2310 #ifdef SSL_OP_TLS_BLOCK_PADDING_BUG
2311 { "SSL_OP_TLS_BLOCK_PADDING_BUG", SSL_OP_TLS_BLOCK_PADDING_BUG },
2312 #endif /* SSL_OP_TLS_BLOCK_PADDING_BUG */
2313 #ifdef SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
2314 { "SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS", SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS },
2315 #endif /* SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS */
2316 { "SSL_OP_ALL", SSL_OP_ALL },
2317 #ifdef SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
2318 { "SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION", SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION },
2319 #endif /* SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION */
2320 #ifdef SSL_OP_EPHEMERAL_RSA
2321 { "SSL_OP_EPHEMERAL_RSA", SSL_OP_EPHEMERAL_RSA },
2322 #endif /* SSL_OP_EPHEMERAL_RSA */
2323 #ifdef SSL_OP_CIPHER_SERVER_PREFERENCE
2324 { "SSL_OP_CIPHER_SERVER_PREFERENCE", SSL_OP_CIPHER_SERVER_PREFERENCE },
2325 #endif /* SSL_OP_CIPHER_SERVER_PREFERENCE */
2326 #ifdef SSL_OP_TLS_ROLLBACK_BUG
2327 { "SSL_OP_TLS_ROLLBACK_BUG", SSL_OP_TLS_ROLLBACK_BUG },
2328 #endif /* SSL_OP_TLS_ROLLBACK_BUG */
2329 #ifdef SSL_OP_NO_SSLv2
2330 { "SSL_OP_NO_SSLv2", SSL_OP_NO_SSLv2 },
2331 #endif /* SSL_OP_NO_SSLv2 */
2332 #ifdef SSL_OP_NO_SSLv3
2333 { "SSL_OP_NO_SSLv3", SSL_OP_NO_SSLv3 },
2334 #endif /* SSL_OP_NO_SSLv3 */
2335 #ifdef SSL_OP_NO_TLSv1
2336 { "SSL_OP_NO_TLSv1", SSL_OP_NO_TLSv1 },
2337 #endif /* SSL_OP_NO_TLSv1 */
2338 #ifdef SSL_OP_PKCS1_CHECK_1
2339 { "SSL_OP_PKCS1_CHECK_1", SSL_OP_PKCS1_CHECK_1 },
2340 #endif /* SSL_OP_PKCS1_CHECK_1 */
2341 #ifdef SSL_OP_PKCS1_CHECK_2
2342 { "SSL_OP_PKCS1_CHECK_2", SSL_OP_PKCS1_CHECK_2 },
2343 #endif /* SSL_OP_PKCS1_CHECK_2 */
2344 #ifdef SSL_OP_NETSCAPE_CA_DN_BUG
2345 { "SSL_OP_NETSCAPE_CA_DN_BUG", SSL_OP_NETSCAPE_CA_DN_BUG },
2346 #endif /* SSL_OP_NETSCAPE_CA_DN_BUG */
2347 #ifdef SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG
2348 { "SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG", SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG },
2349 #endif /* SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG */
2352 #endif /* STARTTLS && _FFR_TLS_1 */
2355 # define CANONIFY(val)
2357 # define SET_OPT_DEFAULT(opt, val) opt = val
2359 /* set a string option by expanding the value and assigning it */
2360 /* WARNING this belongs ONLY into a case statement! */
2361 #define SET_STRING_EXP(str) \
2362 expand(val, exbuf, sizeof(exbuf), e); \
2363 newval = sm_pstrdup_x(exbuf); \
2370 #define OPTNAME o->o_name == NULL ? "<unknown>" : o->o_name
2373 setoption(opt, val, safe, sticky, e)
2378 register ENVELOPE *e;
2381 register struct optioninfo *o;
2384 bool can_setuid = RunAsUid == 0;
2387 extern bool Warn_Q_option;
2388 #if _FFR_ALLOW_SASLINFO
2389 extern unsigned int SubmitMode;
2390 #endif /* _FFR_ALLOW_SASLINFO */
2391 #if STARTTLS || SM_CONF_SHM
2393 char exbuf[MAXLINE];
2394 #endif /* STARTTLS || SM_CONF_SHM */
2395 #if STARTTLS && _FFR_TLS_1
2396 long *pssloptions = NULL;
2397 #endif /* STARTTLS && _FFR_TLS_1 */
2402 /* full word options */
2403 struct optioninfo *sel;
2405 p = strchr(val, '=');
2407 p = &val[strlen(val)];
2414 syserr("readcf: null option name");
2421 subopt = strchr(val, '.');
2425 for (o = OptionTab; o->o_name != NULL; o++)
2427 if (sm_strncasecmp(o->o_name, val, strlen(val)) != 0)
2429 if (strlen(o->o_name) == strlen(val))
2431 /* completely specified -- this must be it */
2439 if (sel != NULL && o->o_name == NULL)
2441 else if (o->o_name == NULL)
2443 syserr("readcf: unknown option name %s", val);
2446 else if (sel != NULL)
2448 syserr("readcf: ambiguous option name %s (matches %s and %s)",
2449 val, sel->o_name, o->o_name);
2452 if (strlen(val) != strlen(o->o_name))
2454 int oldVerbose = Verbose;
2457 message("Option %s used as abbreviation for %s",
2459 Verbose = oldVerbose;
2466 for (o = OptionTab; o->o_name != NULL; o++)
2468 if (o->o_code == opt)
2471 if (o->o_name == NULL)
2473 syserr("readcf: unknown option name 0x%x", opt & 0xff);
2479 if (subopt != NULL && !bitset(OI_SUBOPT, o->o_flags))
2482 sm_dprintf("setoption: %s does not support suboptions, ignoring .%s\n",
2489 sm_dprintf(isascii(opt) && isprint(opt) ?
2490 "setoption %s (%c)%s%s=" :
2491 "setoption %s (0x%x)%s%s=",
2492 OPTNAME, opt, subopt == NULL ? "" : ".",
2493 subopt == NULL ? "" : subopt);
2494 xputs(sm_debug_file(), val);
2498 ** See if this option is preset for us.
2501 if (!sticky && bitnset(opt, StickyOpt))
2504 sm_dprintf(" (ignored)\n");
2509 ** Check to see if this option can be specified by this user.
2512 if (!safe && RealUid == 0)
2514 if (!safe && !bitset(OI_SAFE, o->o_flags))
2516 if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
2521 sm_dprintf(" (unsafe)");
2522 dp = drop_privileges(true);
2531 case '7': /* force seven-bit input */
2532 SevenBitInput = atobool(val);
2535 case '8': /* handling of 8-bit input */
2539 case 'p': /* pass 8 bit, convert MIME */
2540 MimeMode = MM_CVTMIME|MM_PASS8BIT;
2543 case 'm': /* convert 8-bit, convert MIME */
2544 MimeMode = MM_CVTMIME|MM_MIME8BIT;
2547 case 's': /* strict adherence */
2548 MimeMode = MM_CVTMIME;
2552 case 'r': /* reject 8-bit, don't convert MIME */
2556 case 'j': /* "just send 8" */
2557 MimeMode = MM_PASS8BIT;
2560 case 'a': /* encode 8 bit if available */
2561 MimeMode = MM_MIME8BIT|MM_PASS8BIT|MM_CVTMIME;
2564 case 'c': /* convert 8 bit to MIME, never 7 bit */
2565 MimeMode = MM_MIME8BIT;
2570 syserr("Unknown 8-bit mode %c", *val);
2571 finis(false, true, EX_USAGE);
2573 #else /* MIME8TO7 */
2574 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
2575 "Warning: Option: %s requires MIME8TO7 support\n",
2577 #endif /* MIME8TO7 */
2580 case 'A': /* set default alias file */
2585 SET_OPT_DEFAULT(al, "aliases");
2592 case 'a': /* look N minutes for "@:@" in alias file */
2594 SafeAlias = 5 MINUTES;
2596 SafeAlias = convtime(val, 'm');
2599 case 'B': /* substitution for blank character */
2601 if (SpaceSub == '\0')
2605 case 'b': /* min blocks free on queue fs/max msg size */
2606 p = strchr(val, '/');
2610 MaxMessageSize = atol(p);
2612 MinBlocksFree = atol(val);
2615 case 'c': /* don't connect to "expensive" mailers */
2616 NoConnect = atobool(val);
2619 case 'C': /* checkpoint every N addresses */
2620 if (safe || CheckpointInterval > atoi(val))
2621 CheckpointInterval = atoi(val);
2624 case 'd': /* delivery mode */
2628 set_delivery_mode(SM_DELIVER, e);
2631 case SM_QUEUE: /* queue only */
2632 case SM_DEFER: /* queue only and defer map lookups */
2633 case SM_DELIVER: /* do everything */
2634 case SM_FORK: /* fork after verification */
2636 /* deliver first TA in background, then queue */
2638 #endif /* _FFR_DM_ONE */
2639 set_delivery_mode(*val, e);
2643 syserr("Unknown delivery mode %c", *val);
2644 finis(false, true, EX_USAGE);
2648 case 'E': /* error message header/header file */
2650 ErrMsgFile = newstr(val);
2653 case 'e': /* set error processing mode */
2656 case EM_QUIET: /* be silent about it */
2657 case EM_MAIL: /* mail back */
2658 case EM_BERKNET: /* do berknet error processing */
2659 case EM_WRITE: /* write back (or mail) */
2660 case EM_PRINT: /* print errors normally (default) */
2661 e->e_errormode = *val;
2666 case 'F': /* file mode */
2667 FileMode = atooct(val) & 0777;
2670 case 'f': /* save Unix-style From lines on front */
2671 SaveFrom = atobool(val);
2674 case 'G': /* match recipients against GECOS field */
2675 MatchGecos = atobool(val);
2678 case 'g': /* default gid */
2680 if (isascii(*val) && isdigit(*val))
2684 register struct group *gr;
2689 syserr("readcf: option %c: unknown group %s",
2692 DefGid = gr->gr_gid;
2696 case 'H': /* help file */
2699 SET_OPT_DEFAULT(HelpFile, "helpfile");
2704 HelpFile = newstr(val);
2708 case 'h': /* maximum hop count */
2709 MaxHopCount = atoi(val);
2712 case 'I': /* use internet domain name server */
2714 for (p = val; *p != 0; )
2718 struct resolverflags *rfp;
2731 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
2735 if (sm_strcasecmp(q, "HasWildcardMX") == 0)
2737 HasWildcardMX = !clearmode;
2740 if (sm_strcasecmp(q, "WorkAroundBrokenAAAA") == 0)
2742 WorkAroundBrokenAAAA = !clearmode;
2745 for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
2747 if (sm_strcasecmp(q, rfp->rf_name) == 0)
2750 if (rfp->rf_name == NULL)
2751 syserr("readcf: I option value %s unrecognized", q);
2753 _res.options &= ~rfp->rf_bits;
2755 _res.options |= rfp->rf_bits;
2758 sm_dprintf("_res.options = %x, HasWildcardMX = %d\n",
2759 (unsigned int) _res.options, HasWildcardMX);
2760 #else /* NAMED_BIND */
2761 usrerr("name server (I option) specified but BIND not compiled in");
2762 #endif /* NAMED_BIND */
2765 case 'i': /* ignore dot lines in message */
2766 IgnrDot = atobool(val);
2769 case 'j': /* send errors in MIME (RFC 1341) format */
2770 SendMIMEErrors = atobool(val);
2773 case 'J': /* .forward search path */
2775 ForwardPath = newstr(val);
2778 case 'k': /* connection cache size */
2779 MaxMciCache = atoi(val);
2780 if (MaxMciCache < 0)
2784 case 'K': /* connection cache timeout */
2785 MciCacheTimeout = convtime(val, 'm');
2788 case 'l': /* use Errors-To: header */
2789 UseErrorsTo = atobool(val);
2792 case 'L': /* log level */
2793 if (safe || LogLevel < atoi(val))
2794 LogLevel = atoi(val);
2797 case 'M': /* define macro */
2799 mid = macid_parse(val, &ep);
2804 cleanstrcpy(p, p, strlen(p) + 1);
2805 macdefine(&CurEnv->e_macro, A_TEMP, mid, p);
2808 case 'm': /* send to me too */
2809 MeToo = atobool(val);
2812 case 'n': /* validate RHS in newaliases */
2813 CheckAliases = atobool(val);
2816 /* 'N' available -- was "net name" */
2818 case 'O': /* daemon options */
2819 if (!setdaemonoptions(val))
2820 syserr("too many daemons defined (%d max)", MAXDAEMONS);
2823 case 'o': /* assume old style headers */
2825 CurEnv->e_flags |= EF_OLDSTYLE;
2827 CurEnv->e_flags &= ~EF_OLDSTYLE;
2830 case 'p': /* select privacy level */
2834 register struct prival *pv;
2835 extern struct prival PrivacyValues[];
2837 while (isascii(*p) && (isspace(*p) || ispunct(*p)))
2842 while (isascii(*p) && isalnum(*p))
2847 for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
2849 if (sm_strcasecmp(val, pv->pv_name) == 0)
2852 if (pv->pv_name == NULL)
2853 syserr("readcf: Op line: %s unrecognized", val);
2855 PrivacyFlags |= pv->pv_flag;
2860 case 'P': /* postmaster copy address for returned mail */
2861 PostMasterCopy = newstr(val);
2864 case 'q': /* slope of queue only function */
2865 QueueFactor = atoi(val);
2868 case 'Q': /* queue directory */
2871 QueueDir = "mqueue";
2875 QueueDir = newstr(val);
2877 if (RealUid != 0 && !safe)
2878 Warn_Q_option = true;
2881 case 'R': /* don't prune routes */
2882 DontPruneRoutes = atobool(val);
2885 case 'r': /* read timeout */
2887 inittimeouts(val, sticky);
2889 settimeout(subopt, val, sticky);
2892 case 'S': /* status file */
2895 SET_OPT_DEFAULT(StatFile, "statistics");
2900 StatFile = newstr(val);
2904 case 's': /* be super safe, even if expensive */
2905 if (tolower(*val) == 'i')
2906 SuperSafe = SAFE_INTERACTIVE;
2907 else if (tolower(*val) == 'p')
2909 SuperSafe = SAFE_REALLY_POSTMILTER;
2911 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
2912 "Warning: SuperSafe=PostMilter requires Milter support (-DMILTER)\n");
2915 SuperSafe = atobool(val) ? SAFE_REALLY : SAFE_NO;
2918 case 'T': /* queue timeout */
2919 p = strchr(val, '/');
2923 settimeout("queuewarn", p, sticky);
2925 settimeout("queuereturn", val, sticky);
2928 case 't': /* time zone name */
2929 TimeZoneSpec = newstr(val);
2932 case 'U': /* location of user database */
2933 UdbSpec = newstr(val);
2936 case 'u': /* set default uid */
2937 for (p = val; *p != '\0'; p++)
2939 # if _FFR_DOTTED_USERNAMES
2940 if (*p == '/' || *p == ':')
2941 # else /* _FFR_DOTTED_USERNAMES */
2942 if (*p == '.' || *p == '/' || *p == ':')
2943 # endif /* _FFR_DOTTED_USERNAMES */
2949 if (isascii(*val) && isdigit(*val))
2956 register struct passwd *pw;
2959 pw = sm_getpwnam(val);
2962 syserr("readcf: option u: unknown user %s", val);
2967 DefUid = pw->pw_uid;
2968 DefGid = pw->pw_gid;
2969 DefUser = newstr(pw->pw_name);
2974 if (DefUid > UID_MAX)
2976 syserr("readcf: option u: uid value (%ld) > UID_MAX (%ld); ignored",
2977 (long)DefUid, (long)UID_MAX);
2980 # endif /* UID_MAX */
2982 /* handle the group if it is there */
2988 case 'V': /* fallback MX host */
2990 FallbackMX = newstr(val);
2993 case 'v': /* run in verbose mode */
2994 Verbose = atobool(val) ? 1 : 0;
2997 case 'w': /* if we are best MX, try host directly */
2998 TryNullMXList = atobool(val);
3001 /* 'W' available -- was wizard password */
3003 case 'x': /* load avg at which to auto-queue msgs */
3004 QueueLA = atoi(val);
3007 case 'X': /* load avg at which to auto-reject connections */
3008 RefuseLA = atoi(val);
3011 case O_DELAY_LA: /* load avg at which to delay connections */
3012 DelayLA = atoi(val);
3015 case 'y': /* work recipient factor */
3016 WkRecipFact = atoi(val);
3019 case 'Y': /* fork jobs during queue runs */
3020 ForkQueueRuns = atobool(val);
3023 case 'z': /* work message class factor */
3024 WkClassFact = atoi(val);
3027 case 'Z': /* work time factor */
3028 WkTimeFact = atoi(val);
3032 #if _FFR_QUEUE_GROUP_SORTORDER
3033 /* coordinate this with makequeue() */
3034 #endif /* _FFR_QUEUE_GROUP_SORTORDER */
3035 case O_QUEUESORTORD: /* queue sorting order */
3038 case 'f': /* File Name */
3040 QueueSortOrder = QSO_BYFILENAME;
3043 case 'h': /* Host first */
3045 QueueSortOrder = QSO_BYHOST;
3048 case 'm': /* Modification time */
3050 QueueSortOrder = QSO_BYMODTIME;
3053 case 'p': /* Priority order */
3055 QueueSortOrder = QSO_BYPRIORITY;
3058 case 't': /* Submission time */
3060 QueueSortOrder = QSO_BYTIME;
3063 case 'r': /* Random */
3065 QueueSortOrder = QSO_RANDOM;
3069 case 's': /* Shuffled host name */
3071 QueueSortOrder = QSO_BYSHUFFLE;
3073 #endif /* _FFR_RHS */
3075 case 'n': /* none */
3077 QueueSortOrder = QSO_NONE;
3081 syserr("Invalid queue sort order \"%s\"", val);
3085 case O_HOSTSFILE: /* pathname of /etc/hosts file */
3087 HostsFile = newstr(val);
3090 case O_MQA: /* minimum queue age between deliveries */
3091 MinQueueAge = convtime(val, 'm');
3095 case O_MAX_QUEUE_AGE:
3096 MaxQueueAge = convtime(val, 'm');
3098 #endif /* _FFR_EXPDELAY */
3100 case O_DEFCHARSET: /* default character set for mimefying */
3101 DefaultCharSet = newstr(denlstring(val, true, true));
3104 case O_SSFILE: /* service switch file */
3106 ServiceSwitchFile = newstr(val);
3109 case O_DIALDELAY: /* delay for dial-on-demand operation */
3110 DialDelay = convtime(val, 's');
3113 case O_NORCPTACTION: /* what to do if no recipient */
3114 if (sm_strcasecmp(val, "none") == 0)
3115 NoRecipientAction = NRA_NO_ACTION;
3116 else if (sm_strcasecmp(val, "add-to") == 0)
3117 NoRecipientAction = NRA_ADD_TO;
3118 else if (sm_strcasecmp(val, "add-apparently-to") == 0)
3119 NoRecipientAction = NRA_ADD_APPARENTLY_TO;
3120 else if (sm_strcasecmp(val, "add-bcc") == 0)
3121 NoRecipientAction = NRA_ADD_BCC;
3122 else if (sm_strcasecmp(val, "add-to-undisclosed") == 0)
3123 NoRecipientAction = NRA_ADD_TO_UNDISCLOSED;
3125 syserr("Invalid NoRecipientAction: %s", val);
3128 case O_SAFEFILEENV: /* chroot() environ for writing to files */
3132 /* strip trailing slashes */
3133 p = val + strlen(val) - 1;
3134 while (p >= val && *p == '/')
3140 SafeFileEnv = newstr(val);
3143 case O_MAXMSGSIZE: /* maximum message size */
3144 MaxMessageSize = atol(val);
3147 case O_COLONOKINADDR: /* old style handling of colon addresses */
3148 ColonOkInAddr = atobool(val);
3151 case O_MAXQUEUERUN: /* max # of jobs in a single queue run */
3152 MaxQueueRun = atoi(val);
3155 case O_MAXCHILDREN: /* max # of children of daemon */
3156 MaxChildren = atoi(val);
3159 case O_MAXQUEUECHILDREN: /* max # of children of daemon */
3160 MaxQueueChildren = atoi(val);
3163 case O_MAXRUNNERSPERQUEUE: /* max # runners in a queue group */
3164 MaxRunnersPerQueue = atoi(val);
3167 case O_NICEQUEUERUN: /* nice queue runs */
3169 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3170 "Warning: NiceQueueRun set on system that doesn't support nice()\n");
3171 #endif /* !HASNICE */
3173 /* XXX do we want to check the range? > 0 ? */
3174 NiceQueueRun = atoi(val);
3177 case O_SHMKEY: /* shared memory key */
3180 #else /* SM_CONF_SHM */
3181 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3182 "Warning: Option: %s requires shared memory support (-DSM_CONF_SHM)\n",
3184 #endif /* SM_CONF_SHM */
3187 case O_SHMKEYFILE: /* shared memory key file */
3189 SET_STRING_EXP(ShmKeyFile);
3190 #else /* SM_CONF_SHM */
3191 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3192 "Warning: Option: %s requires shared memory support (-DSM_CONF_SHM)\n",
3195 #endif /* SM_CONF_SHM */
3197 #if _FFR_MAX_FORWARD_ENTRIES
3198 case O_MAXFORWARD: /* max # of forward entries */
3199 MaxForwardEntries = atoi(val);
3201 #endif /* _FFR_MAX_FORWARD_ENTRIES */
3203 case O_KEEPCNAMES: /* don't expand CNAME records */
3204 DontExpandCnames = atobool(val);
3207 case O_MUSTQUOTE: /* must quote these characters in phrases */
3208 (void) sm_strlcpy(buf, "@,;:\\()[]", sizeof(buf));
3209 if (strlen(val) < sizeof(buf) - 10)
3210 (void) sm_strlcat(buf, val, sizeof(buf));
3212 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3213 "Warning: MustQuoteChars too long, ignored.\n");
3214 MustQuoteChars = newstr(buf);
3217 case O_SMTPGREETING: /* SMTP greeting message (old $e macro) */
3218 SmtpGreeting = newstr(munchstring(val, NULL, '\0'));
3221 case O_UNIXFROM: /* UNIX From_ line (old $l macro) */
3222 UnixFromLine = newstr(munchstring(val, NULL, '\0'));
3225 case O_OPCHARS: /* operator characters (old $o macro) */
3226 if (OperatorChars != NULL)
3227 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3228 "Warning: OperatorChars is being redefined.\n It should only be set before ruleset definitions.\n");
3229 OperatorChars = newstr(munchstring(val, NULL, '\0'));
3232 case O_DONTINITGRPS: /* don't call initgroups(3) */
3233 DontInitGroups = atobool(val);
3236 case O_SLFH: /* make sure from fits on one line */
3237 SingleLineFromHeader = atobool(val);
3240 case O_ABH: /* allow HELO commands with syntax errors */
3241 AllowBogusHELO = atobool(val);
3244 case O_CONNTHROT: /* connection rate throttle */
3245 ConnRateThrottle = atoi(val);
3248 case O_UGW: /* group writable files are unsafe */
3251 setbitn(DBS_GROUPWRITABLEFORWARDFILESAFE,
3253 setbitn(DBS_GROUPWRITABLEINCLUDEFILESAFE,
3258 case O_DBLBOUNCE: /* address to which to send double bounces */
3259 DoubleBounceAddr = newstr(val);
3262 case O_HSDIR: /* persistent host status directory */
3266 HostStatDir = newstr(val);
3270 case O_SINGTHREAD: /* single thread deliveries (requires hsdir) */
3271 SingleThreadDelivery = atobool(val);
3274 case O_RUNASUSER: /* run bulk of code as this user */
3275 for (p = val; *p != '\0'; p++)
3277 # if _FFR_DOTTED_USERNAMES
3278 if (*p == '/' || *p == ':')
3279 # else /* _FFR_DOTTED_USERNAMES */
3280 if (*p == '.' || *p == '/' || *p == ':')
3281 # endif /* _FFR_DOTTED_USERNAMES */
3287 if (isascii(*val) && isdigit(*val))
3290 RunAsUid = atoi(val);
3294 register struct passwd *pw;
3296 pw = sm_getpwnam(val);
3299 syserr("readcf: option RunAsUser: unknown user %s", val);
3302 else if (can_setuid)
3305 RunAsUserName = newstr(val);
3306 RunAsUid = pw->pw_uid;
3307 RunAsGid = pw->pw_gid;
3309 else if (EffGid == pw->pw_gid)
3310 RunAsGid = pw->pw_gid;
3311 else if (UseMSP && *p == '\0')
3312 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3313 "WARNING: RunAsUser for MSP ignored, check group ids (egid=%d, want=%d)\n",
3318 if (RunAsUid > UID_MAX)
3320 syserr("readcf: option RunAsUser: uid value (%ld) > UID_MAX (%ld); ignored",
3321 (long) RunAsUid, (long) UID_MAX);
3324 # endif /* UID_MAX */
3327 if (isascii(*p) && isdigit(*p))
3331 runasgid = (gid_t) atoi(p);
3332 if (can_setuid || EffGid == runasgid)
3333 RunAsGid = runasgid;
3335 (void) sm_io_fprintf(smioout,
3337 "WARNING: RunAsUser for MSP ignored, check group ids (egid=%d, want=%d)\n",
3343 register struct group *gr;
3347 syserr("readcf: option RunAsUser: unknown group %s",
3349 else if (can_setuid || EffGid == gr->gr_gid)
3350 RunAsGid = gr->gr_gid;
3352 (void) sm_io_fprintf(smioout,
3354 "WARNING: RunAsUser for MSP ignored, check group ids (egid=%d, want=%d)\n",
3360 sm_dprintf("readcf: RunAsUser = %d:%d\n",
3361 (int) RunAsUid, (int) RunAsGid);
3365 RrtImpliesDsn = atobool(val);
3369 PSTRSET(PidFile, val);
3372 case O_DONTBLAMESENDMAIL:
3376 register struct dbsval *dbs;
3377 extern struct dbsval DontBlameSendmailValues[];
3379 while (isascii(*p) && (isspace(*p) || ispunct(*p)))
3384 while (isascii(*p) && isalnum(*p))
3389 for (dbs = DontBlameSendmailValues;
3390 dbs->dbs_name != NULL; dbs++)
3392 if (sm_strcasecmp(val, dbs->dbs_name) == 0)
3395 if (dbs->dbs_name == NULL)
3396 syserr("readcf: DontBlameSendmail option: %s unrecognized", val);
3397 else if (dbs->dbs_flag == DBS_SAFE)
3398 clrbitmap(DontBlameSendmail);
3400 setbitn(dbs->dbs_flag, DontBlameSendmail);
3406 if (sm_strcasecmp(val, "loopback") == 0)
3407 DontProbeInterfaces = DPI_SKIPLOOPBACK;
3408 else if (atobool(val))
3409 DontProbeInterfaces = DPI_PROBENONE;
3411 DontProbeInterfaces = DPI_PROBEALL;
3415 MaxRcptPerMsg = atoi(val);
3419 BadRcptThrottle = atoi(val);
3422 #if _FFR_RCPTTHROTDELAY
3423 case O_RCPTTHROTDELAY:
3424 BadRcptThrottleDelay = atoi(val);
3426 #endif /* _FFR_RCPTTHROTDELAY */
3430 PSTRSET(DeadLetterDrop, val);
3433 #if _FFR_DONTLOCKFILESFORREAD_OPTION
3435 DontLockReadFiles = atobool(val);
3437 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
3439 case O_MAXALIASRCSN:
3440 MaxAliasRecursion = atoi(val);
3444 /* XXX should probably use gethostbyname */
3445 #if NETINET || NETINET6
3446 ConnectOnlyTo.sa.sa_family = AF_UNSPEC;
3448 if (anynet_pton(AF_INET6, val,
3449 &ConnectOnlyTo.sin6.sin6_addr) != 1)
3450 ConnectOnlyTo.sa.sa_family = AF_INET6;
3452 # endif /* NETINET6 */
3455 ConnectOnlyTo.sin.sin_addr.s_addr = inet_addr(val);
3456 if (ConnectOnlyTo.sin.sin_addr.s_addr != INADDR_NONE)
3457 ConnectOnlyTo.sa.sa_family = AF_INET;
3460 # endif /* NETINET */
3461 if (ConnectOnlyTo.sa.sa_family == AF_UNSPEC)
3463 syserr("readcf: option ConnectOnlyTo: invalid IP address %s",
3467 #endif /* NETINET || NETINET6 */
3471 # if !HASFCHOWN && !defined(_FFR_DROP_TRUSTUSER_WARNING)
3473 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3474 "readcf: option TrustedUser may cause problems on systems\n which do not support fchown() if UseMSP is not set.\n");
3475 # endif /* !HASFCHOWN && !defined(_FFR_DROP_TRUSTUSER_WARNING) */
3476 if (isascii(*val) && isdigit(*val))
3477 TrustedUid = atoi(val);
3480 register struct passwd *pw;
3483 pw = sm_getpwnam(val);
3486 syserr("readcf: option TrustedUser: unknown user %s", val);
3490 TrustedUid = pw->pw_uid;
3494 if (TrustedUid > UID_MAX)
3496 syserr("readcf: option TrustedUser: uid value (%ld) > UID_MAX (%ld)",
3497 (long) TrustedUid, (long) UID_MAX);
3500 # endif /* UID_MAX */
3503 case O_MAXMIMEHDRLEN:
3504 p = strchr(val, '/');
3507 MaxMimeHeaderLength = atoi(val);
3508 if (p != NULL && *p != '\0')
3509 MaxMimeFieldLength = atoi(p);
3511 MaxMimeFieldLength = MaxMimeHeaderLength / 2;
3513 if (MaxMimeHeaderLength <= 0)
3514 MaxMimeHeaderLength = 0;
3515 else if (MaxMimeHeaderLength < 128)
3516 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3517 "Warning: MaxMimeHeaderLength: header length limit set lower than 128\n");
3519 if (MaxMimeFieldLength <= 0)
3520 MaxMimeFieldLength = 0;
3521 else if (MaxMimeFieldLength < 40)
3522 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3523 "Warning: MaxMimeHeaderLength: field length limit set lower than 40\n");
3526 ** Headers field values now include leading space, so let's
3527 ** adjust the values to be "backward compatible".
3530 if (MaxMimeHeaderLength > 0)
3531 MaxMimeHeaderLength++;
3532 if (MaxMimeFieldLength > 0)
3533 MaxMimeFieldLength++;
3536 case O_CONTROLSOCKET:
3537 PSTRSET(ControlSocketName, val);
3541 MaxHeadersLength = atoi(val);
3543 if (MaxHeadersLength > 0 &&
3544 MaxHeadersLength < (MAXHDRSLEN / 2))
3545 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3546 "Warning: MaxHeadersLength: headers length limit set lower than %d\n",
3550 case O_PROCTITLEPREFIX:
3551 PSTRSET(ProcTitlePrefix, val);
3556 # if _FFR_ALLOW_SASLINFO
3558 ** Allow users to select their own authinfo file
3559 ** under certain circumstances, otherwise just ignore
3560 ** the option. If the option isn't ignored, several
3561 ** commands don't work very well, e.g., mailq.
3562 ** However, this is not a "perfect" solution.
3563 ** If mail is queued, the authentication info
3564 ** will not be used in subsequent delivery attempts.
3565 ** If we really want to support this, then it has
3566 ** to be stored in the queue file.
3568 if (!bitset(SUBMIT_MSA, SubmitMode) && RealUid != 0 &&
3569 RunAsUid != RealUid)
3571 # endif /* _FFR_ALLOW_SASLINFO */
3572 PSTRSET(SASLInfo, val);
3576 if (AuthMechanisms != NULL)
3577 sm_free(AuthMechanisms); /* XXX */
3579 AuthMechanisms = newstr(val);
3581 AuthMechanisms = NULL;
3585 if (AuthRealm != NULL)
3588 AuthRealm = newstr(val);
3594 while (val != NULL && *val != '\0')
3599 SASLOpts |= SASL_AUTH_AUTH;
3603 SASLOpts |= SASL_SEC_NOACTIVE;
3607 SASLOpts |= SASL_SEC_PASS_CREDENTIALS;
3611 SASLOpts |= SASL_SEC_NODICTIONARY;
3615 SASLOpts |= SASL_SEC_FORWARD_SECRECY;
3620 SASLOpts |= SASL_SEC_MUTUAL_AUTH;
3622 # endif /* SASL >= 20101 */
3625 SASLOpts |= SASL_SEC_NOPLAINTEXT;
3629 SASLOpts |= SASL_SEC_NOANONYMOUS;
3632 case ' ': /* ignore */
3633 case '\t': /* ignore */
3634 case ',': /* ignore */
3638 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3639 "Warning: Option: %s unknown parameter '%c'\n",
3647 val = strpbrk(val, ", \t");
3654 MaxSLBits = atoi(val);
3663 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3664 "Warning: Option: %s requires SASL support (-DSASL)\n",
3671 SET_STRING_EXP(SrvCertFile);
3673 SET_STRING_EXP(SrvKeyFile);
3675 SET_STRING_EXP(CltCertFile);
3677 SET_STRING_EXP(CltKeyFile);
3679 SET_STRING_EXP(CACertFile);
3681 SET_STRING_EXP(CACertPath);
3683 SET_STRING_EXP(DHParams);
3686 SET_STRING_EXP(DHParams5);
3688 SET_STRING_EXP(CipherList);
3689 case O_SRV_SSL_OPTIONS:
3690 pssloptions = &Srv_SSL_Options;
3691 case O_CLT_SSL_OPTIONS:
3692 if (pssloptions == NULL)
3693 pssloptions = &Clt_SSL_Options;
3694 for (p = val; *p != 0; )
3698 struct ssl_options *sslopts;
3705 if (*p == '-' || *p == '+')
3706 clearmode = *p++ == '-';
3708 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
3712 for (sslopts = SSL_Option;
3713 sslopts->sslopt_name != NULL; sslopts++)
3715 if (sm_strcasecmp(q, sslopts->sslopt_name) == 0)
3718 if (sslopts->sslopt_name == NULL)
3721 syserr("readcf: %s option value %s unrecognized",
3725 *pssloptions &= ~sslopts->sslopt_bits;
3727 *pssloptions |= sslopts->sslopt_bits;
3732 # endif /* _FFR_TLS_1 */
3735 # if OPENSSL_VERSION_NUMBER > 0x00907000L
3736 SET_STRING_EXP(CRLFile);
3737 # else /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3738 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3739 "Warning: Option: %s requires at least OpenSSL 0.9.7\n",
3742 # endif /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3746 # if OPENSSL_VERSION_NUMBER > 0x00907000L
3747 SET_STRING_EXP(CRLPath);
3748 # else /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3749 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3750 "Warning: Option: %s requires at least OpenSSL 0.9.7\n",
3753 # endif /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3754 # endif /* _FFR_CRLPATH */
3757 ** XXX How about options per daemon/client instead of globally?
3758 ** This doesn't work well for some options, e.g., no server cert,
3759 ** but fine for others.
3761 ** XXX Some people may want different certs per server.
3763 ** See also srvfeatures()
3766 case O_TLS_SRV_OPTS:
3767 while (val != NULL && *val != '\0')
3772 TLS_Srv_Opts |= TLS_I_NO_VRFY;
3776 ** Server without a cert? That works only if
3777 ** AnonDH is enabled as cipher, which is not in the
3778 ** default list. Hence the CipherList option must
3779 ** be available. Moreover: which clients support this
3780 ** besides sendmail with this setting?
3784 TLS_Srv_Opts &= ~TLS_I_SRV_CERT;
3786 # endif /* _FFR_TLS_1 */
3787 case ' ': /* ignore */
3788 case '\t': /* ignore */
3789 case ',': /* ignore */
3792 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3793 "Warning: Option: %s unknown parameter '%c'\n",
3801 val = strpbrk(val, ", \t");
3808 PSTRSET(RandFile, val);
3811 #else /* STARTTLS */
3822 # endif /* _FFR_TLS_1 */
3826 # endif /* _FFR_CRLPATH */
3828 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3829 "Warning: Option: %s requires TLS support\n",
3833 #endif /* STARTTLS */
3836 setclientoptions(val);
3840 DataFileBufferSize = atoi(val);
3844 XscriptFileBufferSize = atoi(val);
3847 case O_LDAPDEFAULTSPEC:
3849 ldapmap_set_defaults(val);
3851 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3852 "Warning: Option: %s requires LDAP support (-DLDAPMAP)\n",
3854 #endif /* LDAPMAP */
3859 InputFilterList = newstr(val);
3861 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3862 "Warning: Option: %s requires Milter support (-DMILTER)\n",
3869 milter_set_option(subopt, val, sticky);
3871 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3872 "Warning: Option: %s requires Milter support (-DMILTER)\n",
3877 case O_QUEUE_FILE_MODE: /* queue file mode */
3878 QueueFileMode = atooct(val) & 0777;
3881 case O_DLVR_MIN: /* deliver by minimum time */
3882 DeliverByMin = convtime(val, 's');
3885 /* modifiers {daemon_flags} for direct submissions */
3886 case O_DIRECTSUBMODIFIERS:
3888 BITMAP256 m; /* ignored */
3889 extern ENVELOPE BlankEnvelope;
3891 macdefine(&BlankEnvelope.e_macro, A_PERM,
3892 macid("{daemon_flags}"),
3893 getmodifiers(val, m));
3898 FastSplit = atoi(val);
3906 UseMSP = atobool(val);
3910 SoftBounce = atobool(val);
3913 case O_REJECTLOGINTERVAL: /* time btwn log msgs while refusing */
3914 RejectLogInterval = convtime(val, 'h');
3917 case O_REQUIRES_DIR_FSYNC:
3918 #if REQUIRES_DIR_FSYNC
3919 RequiresDirfsync = atobool(val);
3920 #else /* REQUIRES_DIR_FSYNC */
3921 /* silently ignored... required for cf file option */
3922 #endif /* REQUIRES_DIR_FSYNC */
3925 case O_CONNECTION_RATE_WINDOW_SIZE:
3926 ConnectionRateWindowSize = convtime(val, 's');
3929 case O_FALLBACKSMARTHOST: /* fallback smart host */
3931 FallbackSmartHost = newstr(val);
3935 HeloName = newstr(val);
3939 case O_REFUSELOWMEM:
3940 RefuseLowMem = atoi(val);
3943 QueueLowMem = atoi(val);
3946 MemoryResource = newstr(val);
3948 #endif /* _FFR_MEMSTAT */
3950 case O_MAXNOOPCOMMANDS:
3951 MaxNOOPCommands = atoi(val);
3956 MessageAccept = newstr(val);
3958 #endif /* _FFR_MSG_ACCEPT */
3960 #if _FFR_QUEUE_RUN_PARANOIA
3961 case O_CHK_Q_RUNNERS:
3962 CheckQueueRunners = atoi(val);
3964 #endif /* _FFR_QUEUE_RUN_PARANOIA */
3966 #if _FFR_EIGHT_BIT_ADDR_OK
3967 case O_EIGHT_BIT_ADDR_OK:
3968 EightBitAddrOK = atobool(val);
3970 #endif /* _FFR_EIGHT_BIT_ADDR_OK */
3972 #if _FFR_ADDR_TYPE_MODES
3973 case O_ADDR_TYPE_MODES:
3974 AddrTypeModes = atobool(val);
3976 #endif /* _FFR_ADDR_TYPE_MODES */
3978 #if _FFR_BADRCPT_SHUTDOWN
3980 BadRcptShutdown = atoi(val);
3984 BadRcptShutdownGood = atoi(val);
3986 #endif /* _FFR_BADRCPT_SHUTDOWN */
3991 if (isascii(opt) && isprint(opt))
3992 sm_dprintf("Warning: option %c unknown\n", opt);
3994 sm_dprintf("Warning: option 0x%x unknown\n", opt);
4000 ** Options with suboptions are responsible for taking care
4001 ** of sticky-ness (e.g., that a command line setting is kept
4002 ** when reading in the sendmail.cf file). This has to be done
4003 ** when the suboptions are parsed since each suboption must be
4004 ** sticky, not the root option.
4007 if (sticky && !bitset(OI_SUBOPT, o->o_flags))
4008 setbitn(opt, StickyOpt);
4011 ** SETCLASS -- set a string into a class
4014 ** class -- the class to put the string in.
4015 ** str -- the string to enter
4021 ** puts the word into the symbol table.
4025 setclass(class, str)
4031 if ((str[0] & 0377) == MATCHCLASS)
4041 sm_dprintf("setclass(%s, $=%s)\n",
4042 macname(class), macname(mid));
4043 copy_class(mid, class);
4048 sm_dprintf("setclass(%s, %s)\n", macname(class), str);
4050 s = stab(str, ST_CLASS, ST_ENTER);
4051 setbitn(bitidx(class), s->s_class);
4055 ** MAKEMAPENTRY -- create a map entry
4058 ** line -- the config file line
4061 ** A pointer to the map that has been created.
4062 ** NULL if there was a syntax error.
4065 ** Enters the map into the dictionary.
4078 for (p = line; isascii(*p) && isspace(*p); p++)
4080 if (!(isascii(*p) && isalnum(*p)))
4082 syserr("readcf: config K line: no map name");
4087 while ((isascii(*++p) && isalnum(*p)) || *p == '_' || *p == '.')
4091 while (isascii(*p) && isspace(*p))
4093 if (!(isascii(*p) && isalnum(*p)))
4095 syserr("readcf: config K line, map %s: no map class", mapname);
4099 while (isascii(*++p) && isalnum(*p))
4103 while (isascii(*p) && isspace(*p))
4106 /* look up the class */
4107 class = stab(classname, ST_MAPCLASS, ST_FIND);
4110 syserr("readcf: map %s: class %s not available", mapname,
4116 s = stab(mapname, ST_MAP, ST_ENTER);
4117 s->s_map.map_class = &class->s_mapclass;
4118 s->s_map.map_mname = newstr(mapname);
4120 if (class->s_mapclass.map_parse(&s->s_map, p))
4121 s->s_map.map_mflags |= MF_VALID;
4125 sm_dprintf("map %s, class %s, flags %lx, file %s,\n",
4126 s->s_map.map_mname, s->s_map.map_class->map_cname,
4127 s->s_map.map_mflags, s->s_map.map_file);
4128 sm_dprintf("\tapp %s, domain %s, rebuild %s\n",
4129 s->s_map.map_app, s->s_map.map_domain,
4130 s->s_map.map_rebuild);
4135 ** STRTORWSET -- convert string to rewriting set number
4138 ** p -- the pointer to the string to decode.
4139 ** endp -- if set, store the trailing delimiter here.
4140 ** stabmode -- ST_ENTER to create this entry, ST_FIND if
4141 ** it must already exist.
4144 ** The appropriate ruleset number.
4145 ** -1 if it is not valid (error already printed)
4149 strtorwset(p, endp, stabmode)
4155 static int nextruleset = MAXRWSETS;
4157 while (isascii(*p) && isspace(*p))
4161 syserr("invalid ruleset name: \"%.20s\"", p);
4166 ruleset = strtol(p, endp, 10);
4167 if (ruleset >= MAXRWSETS / 2 || ruleset < 0)
4169 syserr("bad ruleset %d (%d max)",
4170 ruleset, MAXRWSETS / 2);
4181 while (*p != '\0' && isascii(*p) && (isalnum(*p) || *p == '_'))
4183 if (q == p || !(isascii(*q) && isalpha(*q)))
4185 /* no valid characters */
4186 syserr("invalid ruleset name: \"%.20s\"", q);
4189 while (isascii(*p) && isspace(*p))
4194 s = stab(q, ST_RULESET, stabmode);
4201 if (stabmode == ST_ENTER && delim == '=')
4203 while (isascii(*++p) && isspace(*p))
4205 if (!(isascii(*p) && isdigit(*p)))
4207 syserr("bad ruleset definition \"%s\" (number required after `=')", q);
4212 ruleset = strtol(p, endp, 10);
4213 if (ruleset >= MAXRWSETS / 2 || ruleset < 0)
4215 syserr("bad ruleset number %d in \"%s\" (%d max)",
4216 ruleset, q, MAXRWSETS / 2);
4225 if (s->s_ruleset >= 0)
4226 ruleset = s->s_ruleset;
4227 else if ((ruleset = --nextruleset) < MAXRWSETS / 2)
4229 syserr("%s: too many named rulesets (%d max)",
4234 if (s->s_ruleset >= 0 &&
4236 ruleset != s->s_ruleset)
4238 syserr("%s: ruleset changed value (old %d, new %d)",
4239 q, s->s_ruleset, ruleset);
4240 ruleset = s->s_ruleset;
4242 else if (ruleset >= 0)
4244 s->s_ruleset = ruleset;
4246 if (stabmode == ST_ENTER && ruleset >= 0)
4250 if (RuleSetNames[ruleset] != NULL)
4251 sm_free(RuleSetNames[ruleset]); /* XXX */
4252 if (delim != '\0' && (h = strchr(q, delim)) != NULL)
4254 RuleSetNames[ruleset] = newstr(q);
4255 if (delim == '/' && h != NULL)
4256 *h = delim; /* put back delim */
4262 ** SETTIMEOUT -- set an individual timeout
4265 ** name -- the name of the timeout.
4266 ** val -- the value of the timeout.
4267 ** sticky -- if set, don't let other setoptions override
4274 /* set if Timeout sub-option is stuck */
4275 static BITMAP256 StickyTimeoutOpt;
4277 static struct timeoutinfo
4279 char *to_name; /* long name of timeout */
4280 unsigned char to_code; /* code for option */
4283 #define TO_INITIAL 0x01
4284 { "initial", TO_INITIAL },
4285 #define TO_MAIL 0x02
4286 { "mail", TO_MAIL },
4287 #define TO_RCPT 0x03
4288 { "rcpt", TO_RCPT },
4289 #define TO_DATAINIT 0x04
4290 { "datainit", TO_DATAINIT },
4291 #define TO_DATABLOCK 0x05
4292 { "datablock", TO_DATABLOCK },
4293 #define TO_DATAFINAL 0x06
4294 { "datafinal", TO_DATAFINAL },
4295 #define TO_COMMAND 0x07
4296 { "command", TO_COMMAND },
4297 #define TO_RSET 0x08
4298 { "rset", TO_RSET },
4299 #define TO_HELO 0x09
4300 { "helo", TO_HELO },
4301 #define TO_QUIT 0x0A
4302 { "quit", TO_QUIT },
4303 #define TO_MISC 0x0B
4304 { "misc", TO_MISC },
4305 #define TO_IDENT 0x0C
4306 { "ident", TO_IDENT },
4307 #define TO_FILEOPEN 0x0D
4308 { "fileopen", TO_FILEOPEN },
4309 #define TO_CONNECT 0x0E
4310 { "connect", TO_CONNECT },
4311 #define TO_ICONNECT 0x0F
4312 { "iconnect", TO_ICONNECT },
4313 #define TO_QUEUEWARN 0x10
4314 { "queuewarn", TO_QUEUEWARN },
4315 { "queuewarn.*", TO_QUEUEWARN },
4316 #define TO_QUEUEWARN_NORMAL 0x11
4317 { "queuewarn.normal", TO_QUEUEWARN_NORMAL },
4318 #define TO_QUEUEWARN_URGENT 0x12
4319 { "queuewarn.urgent", TO_QUEUEWARN_URGENT },
4320 #define TO_QUEUEWARN_NON_URGENT 0x13
4321 { "queuewarn.non-urgent", TO_QUEUEWARN_NON_URGENT },
4322 #define TO_QUEUERETURN 0x14
4323 { "queuereturn", TO_QUEUERETURN },
4324 { "queuereturn.*", TO_QUEUERETURN },
4325 #define TO_QUEUERETURN_NORMAL 0x15
4326 { "queuereturn.normal", TO_QUEUERETURN_NORMAL },
4327 #define TO_QUEUERETURN_URGENT 0x16
4328 { "queuereturn.urgent", TO_QUEUERETURN_URGENT },
4329 #define TO_QUEUERETURN_NON_URGENT 0x17
4330 { "queuereturn.non-urgent", TO_QUEUERETURN_NON_URGENT },
4331 #define TO_HOSTSTATUS 0x18
4332 { "hoststatus", TO_HOSTSTATUS },
4333 #define TO_RESOLVER_RETRANS 0x19
4334 { "resolver.retrans", TO_RESOLVER_RETRANS },
4335 #define TO_RESOLVER_RETRANS_NORMAL 0x1A
4336 { "resolver.retrans.normal", TO_RESOLVER_RETRANS_NORMAL },
4337 #define TO_RESOLVER_RETRANS_FIRST 0x1B
4338 { "resolver.retrans.first", TO_RESOLVER_RETRANS_FIRST },
4339 #define TO_RESOLVER_RETRY 0x1C
4340 { "resolver.retry", TO_RESOLVER_RETRY },
4341 #define TO_RESOLVER_RETRY_NORMAL 0x1D
4342 { "resolver.retry.normal", TO_RESOLVER_RETRY_NORMAL },
4343 #define TO_RESOLVER_RETRY_FIRST 0x1E
4344 { "resolver.retry.first", TO_RESOLVER_RETRY_FIRST },
4345 #define TO_CONTROL 0x1F
4346 { "control", TO_CONTROL },
4347 #define TO_LHLO 0x20
4348 { "lhlo", TO_LHLO },
4349 #define TO_AUTH 0x21
4350 { "auth", TO_AUTH },
4351 #define TO_STARTTLS 0x22
4352 { "starttls", TO_STARTTLS },
4353 #define TO_ACONNECT 0x23
4354 { "aconnect", TO_ACONNECT },
4355 #define TO_QUEUEWARN_DSN 0x24
4356 { "queuewarn.dsn", TO_QUEUEWARN_DSN },
4357 #define TO_QUEUERETURN_DSN 0x25
4358 { "queuereturn.dsn", TO_QUEUERETURN_DSN },
4364 settimeout(name, val, sticky)
4369 register struct timeoutinfo *to;
4374 sm_dprintf("settimeout(%s = %s)", name, val);
4376 for (to = TimeOutTab; to->to_name != NULL; to++)
4378 if (sm_strcasecmp(to->to_name, name) == 0)
4382 if (to->to_name == NULL)
4384 errno = 0; /* avoid bogus error text */
4385 syserr("settimeout: invalid timeout %s", name);
4390 ** See if this option is preset for us.
4393 if (!sticky && bitnset(to->to_code, StickyTimeoutOpt))
4396 sm_dprintf(" (ignored)\n");
4403 toval = convtime(val, 'm');
4406 switch (to->to_code)
4409 TimeOuts.to_initial = toval;
4413 TimeOuts.to_mail = toval;
4417 TimeOuts.to_rcpt = toval;
4421 TimeOuts.to_datainit = toval;
4425 TimeOuts.to_datablock = toval;
4429 TimeOuts.to_datafinal = toval;
4433 TimeOuts.to_nextcommand = toval;
4437 TimeOuts.to_rset = toval;
4441 TimeOuts.to_helo = toval;
4445 TimeOuts.to_quit = toval;
4449 TimeOuts.to_miscshort = toval;
4453 TimeOuts.to_ident = toval;
4457 TimeOuts.to_fileopen = toval;
4461 TimeOuts.to_connect = toval;
4465 TimeOuts.to_iconnect = toval;
4469 TimeOuts.to_aconnect = toval;
4473 toval = convtime(val, 'h');
4474 TimeOuts.to_q_warning[TOC_NORMAL] = toval;
4475 TimeOuts.to_q_warning[TOC_URGENT] = toval;
4476 TimeOuts.to_q_warning[TOC_NONURGENT] = toval;
4477 TimeOuts.to_q_warning[TOC_DSN] = toval;
4481 case TO_QUEUEWARN_NORMAL:
4482 toval = convtime(val, 'h');
4483 TimeOuts.to_q_warning[TOC_NORMAL] = toval;
4486 case TO_QUEUEWARN_URGENT:
4487 toval = convtime(val, 'h');
4488 TimeOuts.to_q_warning[TOC_URGENT] = toval;
4491 case TO_QUEUEWARN_NON_URGENT:
4492 toval = convtime(val, 'h');
4493 TimeOuts.to_q_warning[TOC_NONURGENT] = toval;
4496 case TO_QUEUEWARN_DSN:
4497 toval = convtime(val, 'h');
4498 TimeOuts.to_q_warning[TOC_DSN] = toval;
4501 case TO_QUEUERETURN:
4502 toval = convtime(val, 'd');
4503 TimeOuts.to_q_return[TOC_NORMAL] = toval;
4504 TimeOuts.to_q_return[TOC_URGENT] = toval;
4505 TimeOuts.to_q_return[TOC_NONURGENT] = toval;
4506 TimeOuts.to_q_return[TOC_DSN] = toval;
4510 case TO_QUEUERETURN_NORMAL:
4511 toval = convtime(val, 'd');
4512 TimeOuts.to_q_return[TOC_NORMAL] = toval;
4515 case TO_QUEUERETURN_URGENT:
4516 toval = convtime(val, 'd');
4517 TimeOuts.to_q_return[TOC_URGENT] = toval;
4520 case TO_QUEUERETURN_NON_URGENT:
4521 toval = convtime(val, 'd');
4522 TimeOuts.to_q_return[TOC_NONURGENT] = toval;
4525 case TO_QUEUERETURN_DSN:
4526 toval = convtime(val, 'd');
4527 TimeOuts.to_q_return[TOC_DSN] = toval;
4531 MciInfoTimeout = toval;
4534 case TO_RESOLVER_RETRANS:
4535 toval = convtime(val, 's');
4536 TimeOuts.res_retrans[RES_TO_DEFAULT] = toval;
4537 TimeOuts.res_retrans[RES_TO_FIRST] = toval;
4538 TimeOuts.res_retrans[RES_TO_NORMAL] = toval;
4542 case TO_RESOLVER_RETRY:
4544 TimeOuts.res_retry[RES_TO_DEFAULT] = i;
4545 TimeOuts.res_retry[RES_TO_FIRST] = i;
4546 TimeOuts.res_retry[RES_TO_NORMAL] = i;
4550 case TO_RESOLVER_RETRANS_NORMAL:
4551 TimeOuts.res_retrans[RES_TO_NORMAL] = convtime(val, 's');
4554 case TO_RESOLVER_RETRY_NORMAL:
4555 TimeOuts.res_retry[RES_TO_NORMAL] = atoi(val);
4558 case TO_RESOLVER_RETRANS_FIRST:
4559 TimeOuts.res_retrans[RES_TO_FIRST] = convtime(val, 's');
4562 case TO_RESOLVER_RETRY_FIRST:
4563 TimeOuts.res_retry[RES_TO_FIRST] = atoi(val);
4567 TimeOuts.to_control = toval;
4571 TimeOuts.to_lhlo = toval;
4576 TimeOuts.to_auth = toval;
4582 TimeOuts.to_starttls = toval;
4584 #endif /* STARTTLS */
4587 syserr("settimeout: invalid timeout %s", name);
4593 for (i = 0; i <= addopts; i++)
4594 setbitn(to->to_code + i, StickyTimeoutOpt);
4598 ** INITTIMEOUTS -- parse and set timeout values
4601 ** val -- a pointer to the values. If NULL, do initial
4603 ** sticky -- if set, don't let other setoptions override
4604 ** this suboption value.
4610 ** Initializes the TimeOuts structure
4614 inittimeouts(val, sticky)
4621 sm_dprintf("inittimeouts(%s)\n", val == NULL ? "<NULL>" : val);
4624 TimeOuts.to_connect = (time_t) 0 SECONDS;
4625 TimeOuts.to_aconnect = (time_t) 0 SECONDS;
4626 TimeOuts.to_iconnect = (time_t) 0 SECONDS;
4627 TimeOuts.to_initial = (time_t) 5 MINUTES;
4628 TimeOuts.to_helo = (time_t) 5 MINUTES;
4629 TimeOuts.to_mail = (time_t) 10 MINUTES;
4630 TimeOuts.to_rcpt = (time_t) 1 HOUR;
4631 TimeOuts.to_datainit = (time_t) 5 MINUTES;
4632 TimeOuts.to_datablock = (time_t) 1 HOUR;
4633 TimeOuts.to_datafinal = (time_t) 1 HOUR;
4634 TimeOuts.to_rset = (time_t) 5 MINUTES;
4635 TimeOuts.to_quit = (time_t) 2 MINUTES;
4636 TimeOuts.to_nextcommand = (time_t) 1 HOUR;
4637 TimeOuts.to_miscshort = (time_t) 2 MINUTES;
4639 TimeOuts.to_ident = (time_t) 5 SECONDS;
4640 #else /* IDENTPROTO */
4641 TimeOuts.to_ident = (time_t) 0 SECONDS;
4642 #endif /* IDENTPROTO */
4643 TimeOuts.to_fileopen = (time_t) 60 SECONDS;
4644 TimeOuts.to_control = (time_t) 2 MINUTES;
4645 TimeOuts.to_lhlo = (time_t) 2 MINUTES;
4647 TimeOuts.to_auth = (time_t) 10 MINUTES;
4650 TimeOuts.to_starttls = (time_t) 1 HOUR;
4651 #endif /* STARTTLS */
4654 sm_dprintf("Timeouts:\n");
4655 sm_dprintf(" connect = %ld\n",
4656 (long) TimeOuts.to_connect);
4657 sm_dprintf(" aconnect = %ld\n",
4658 (long) TimeOuts.to_aconnect);
4659 sm_dprintf(" initial = %ld\n",
4660 (long) TimeOuts.to_initial);
4661 sm_dprintf(" helo = %ld\n", (long) TimeOuts.to_helo);
4662 sm_dprintf(" mail = %ld\n", (long) TimeOuts.to_mail);
4663 sm_dprintf(" rcpt = %ld\n", (long) TimeOuts.to_rcpt);
4664 sm_dprintf(" datainit = %ld\n",
4665 (long) TimeOuts.to_datainit);
4666 sm_dprintf(" datablock = %ld\n",
4667 (long) TimeOuts.to_datablock);
4668 sm_dprintf(" datafinal = %ld\n",
4669 (long) TimeOuts.to_datafinal);
4670 sm_dprintf(" rset = %ld\n", (long) TimeOuts.to_rset);
4671 sm_dprintf(" quit = %ld\n", (long) TimeOuts.to_quit);
4672 sm_dprintf(" nextcommand = %ld\n",
4673 (long) TimeOuts.to_nextcommand);
4674 sm_dprintf(" miscshort = %ld\n",
4675 (long) TimeOuts.to_miscshort);
4676 sm_dprintf(" ident = %ld\n", (long) TimeOuts.to_ident);
4677 sm_dprintf(" fileopen = %ld\n",
4678 (long) TimeOuts.to_fileopen);
4679 sm_dprintf(" lhlo = %ld\n",
4680 (long) TimeOuts.to_lhlo);
4681 sm_dprintf(" control = %ld\n",
4682 (long) TimeOuts.to_control);
4689 while (isascii(*val) && isspace(*val))
4693 for (p = val; *p != '\0' && *p != ','; p++)
4698 if (isascii(*val) && isdigit(*val))
4700 /* old syntax -- set everything */
4701 TimeOuts.to_mail = convtime(val, 'm');
4702 TimeOuts.to_rcpt = TimeOuts.to_mail;
4703 TimeOuts.to_datainit = TimeOuts.to_mail;
4704 TimeOuts.to_datablock = TimeOuts.to_mail;
4705 TimeOuts.to_datafinal = TimeOuts.to_mail;
4706 TimeOuts.to_nextcommand = TimeOuts.to_mail;
4709 setbitn(TO_MAIL, StickyTimeoutOpt);
4710 setbitn(TO_RCPT, StickyTimeoutOpt);
4711 setbitn(TO_DATAINIT, StickyTimeoutOpt);
4712 setbitn(TO_DATABLOCK, StickyTimeoutOpt);
4713 setbitn(TO_DATAFINAL, StickyTimeoutOpt);
4714 setbitn(TO_COMMAND, StickyTimeoutOpt);
4720 register char *q = strchr(val, ':');
4722 if (q == NULL && (q = strchr(val, '=')) == NULL)
4728 settimeout(val, q, sticky);