2 * Copyright (c) 1998-2004 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.642 2004/08/04 21:17:57 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 *));
32 static void parse_class_words __P((int, char *));
35 ** READCF -- read configuration file.
37 ** This routine reads the configuration file and builds the internal
40 ** The file is formatted as a sequence of lines, each taken
41 ** atomically. The first character of each line describes how
42 ** the line is to be interpreted. The lines are:
43 ** Dxval Define macro x to have value val.
44 ** Cxword Put word into class x.
45 ** Fxfile [fmt] Read file for lines to put into
46 ** class x. Use scanf string 'fmt'
47 ** or "%s" if not present. Fmt should
48 ** only produce one string-valued result.
49 ** Hname: value Define header with field-name 'name'
50 ** and value as specified; this will be
51 ** macro expanded immediately before
53 ** Sn Use rewriting set n.
54 ** Rlhs rhs Rewrite addresses that match lhs to
56 ** Mn arg=val... Define mailer. n is the internal name.
57 ** Args specify mailer parameters.
58 ** Oxvalue Set option x to value.
59 ** O option value Set option (long name) to value.
60 ** Pname=value Set precedence name to value.
61 ** Qn arg=val... Define queue groups. n is the internal name.
62 ** Args specify queue parameters.
63 ** Vversioncode[/vendorcode]
64 ** Version level/vendor name of
65 ** configuration syntax.
66 ** Kmapname mapclass arguments....
67 ** Define keyed lookup of a given class.
68 ** Arguments are class dependent.
69 ** Eenvar=value Set the environment value to the given value.
72 ** cfname -- configuration file name.
73 ** safe -- true if this is the system config file;
75 ** e -- the main envelope.
81 ** Builds several internal tables.
85 readcf(cfname, safe, e)
93 struct rewrite *rwp = NULL;
103 long sff = SFF_OPENASROOT;
107 char pvpbuf[MAXLINE + MAXATOM];
108 static char *null_list[1] = { NULL };
109 extern unsigned char TokTypeNoC[];
114 if (DontLockReadFiles)
116 cf = safefopen(cfname, O_RDONLY, 0444, sff);
119 syserr("cannot open");
120 finis(false, true, EX_OSFILE);
123 if (fstat(sm_io_getinfo(cf, SM_IO_WHAT_FD, NULL), &statb) < 0)
125 syserr("cannot fstat");
126 finis(false, true, EX_OSFILE);
129 if (!S_ISREG(statb.st_mode))
131 syserr("not a plain file");
132 finis(false, true, EX_OSFILE);
135 if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
137 if (OpMode == MD_DAEMON || OpMode == MD_INITALIAS)
138 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
139 "%s: WARNING: dangerous write permissions\n",
142 sm_syslog(LOG_CRIT, NOQID,
143 "%s: WARNING: dangerous write permissions",
151 while ((bp = fgetfolded(buf, sizeof buf, cf)) != NULL)
156 sm_free(bp); /* XXX */
160 /* do macro expansion mappings */
161 translate_dollars(bp);
163 /* interpret this line */
168 case '#': /* comment */
171 case 'R': /* rewriting rule */
174 syserr("missing valid ruleset for \"%s\"", bp);
177 for (p = &bp[1]; *p != '\0' && *p != '\t'; p++)
182 syserr("invalid rewrite line \"%s\" (tab expected)", bp);
186 /* allocate space for the rule header */
189 RewriteRules[ruleset] = rwp =
190 (struct rewrite *) xalloc(sizeof *rwp);
194 rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
199 /* expand and save the LHS */
201 expand(&bp[1], exbuf, sizeof exbuf, e);
202 rwp->r_lhs = prescan(exbuf, '\t', pvpbuf,
204 ConfigLevel >= 9 ? TokTypeNoC : NULL,
207 if (rwp->r_lhs != NULL)
211 rwp->r_lhs = copyplist(rwp->r_lhs, true, NULL);
213 /* count the number of fuzzy matches in LHS */
214 for (ap = rwp->r_lhs; *ap != NULL; ap++)
266 syserr("Inappropriate use of %s on LHS",
269 rwp->r_line = LineNumber;
273 syserr("R line: null LHS");
274 rwp->r_lhs = null_list;
276 if (nfuzzy > MAXMATCH)
278 syserr("R line: too many wildcards");
279 rwp->r_lhs = null_list;
282 /* expand and save the RHS */
286 while (*p != '\0' && *p != '\t')
289 expand(q, exbuf, sizeof exbuf, e);
290 rwp->r_rhs = prescan(exbuf, '\t', pvpbuf,
292 ConfigLevel >= 9 ? TokTypeNoC : NULL,
294 if (rwp->r_rhs != NULL)
298 #if _FFR_EXTRA_MAP_CHECK
300 #endif /* _FFR_EXTRA_MAP_CHECK */
303 rwp->r_rhs = copyplist(rwp->r_rhs, true, NULL);
305 /* check no out-of-bounds replacements */
310 for (ap = rwp->r_rhs; *ap != NULL; ap++)
318 if ((*ap)[1] <= '0' || (*ap)[1] > nfuzzy)
320 syserr("replacement $%c out of bounds",
348 if (++args >= MAX_MAP_ARGS)
349 syserr("too many arguments for map lookup");
357 if ((**ap & 0377) == LOOKUPBEGIN)
358 endtoken = LOOKUPEND;
360 syserr("cannot nest map lookups");
363 #if _FFR_EXTRA_MAP_CHECK
364 if (*(ap + 1) == NULL)
366 syserr("syntax error in map lookup");
369 nexttoken = **(ap + 1) & 0377;
370 if (nexttoken == CANONHOST ||
371 nexttoken == CANONUSER ||
372 nexttoken == endtoken)
374 syserr("missing map name for lookup");
377 if (*(ap + 2) == NULL)
379 syserr("syntax error in map lookup");
382 if ((**ap & 0377) == HOSTBEGIN)
384 nexttoken = **(ap + 2) & 0377;
385 if (nexttoken == CANONHOST ||
386 nexttoken == CANONUSER ||
387 nexttoken == endtoken)
389 syserr("missing key name for lookup");
392 #endif /* _FFR_EXTRA_MAP_CHECK */
397 if ((**ap & 0377) != endtoken)
406 ** This doesn't work yet as there are maps defined *after* the cf
407 ** is read such as host, user, and alias. So for now, it's removed.
408 ** When it comes back, the RELEASE_NOTES entry will be:
409 ** Emit warnings for unknown maps when reading the .cf file. Based on
410 ** patch from Robert Harker of Harker Systems.
415 ** Got a database lookup,
416 ** check if map is defined.
420 if ((*ep & 0377) != MACRODEXPAND &&
424 (void) sm_io_fprintf(smioout,
426 "Warning: %s: line %d: map %s not found\n",
435 syserr("Inappropriate use of %s on RHS",
439 syserr("missing map closing token");
443 syserr("R line: null RHS");
444 rwp->r_rhs = null_list;
448 case 'S': /* select rewriting set */
449 expand(&bp[1], exbuf, sizeof exbuf, e);
450 ruleset = strtorwset(exbuf, NULL, ST_ENTER);
454 rwp = RewriteRules[ruleset];
457 if (OpMode == MD_TEST)
458 (void) sm_io_fprintf(smioout,
460 "WARNING: Ruleset %s has multiple definitions\n",
463 sm_dprintf("WARNING: Ruleset %s has multiple definitions\n",
465 while (rwp->r_next != NULL)
470 case 'D': /* macro definition */
471 mid = macid_parse(&bp[1], &ep);
474 p = munchstring(ep, NULL, '\0');
475 macdefine(&e->e_macro, A_TEMP, mid, p);
478 case 'H': /* required header line */
479 (void) chompheader(&bp[1], CHHDR_DEF, NULL, e);
482 case 'C': /* word class */
483 case 'T': /* trusted user (set class `t') */
486 mid = macid_parse(&bp[1], &ep);
489 expand(ep, exbuf, sizeof exbuf, e);
502 while (*p != '\0' && isascii(*p) && isspace(*p))
505 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
515 case 'F': /* word class from file */
516 mid = macid_parse(&bp[1], &ep);
519 for (p = ep; isascii(*p) && isspace(*p); )
521 if (p[0] == '-' && p[1] == 'o')
525 !(isascii(*p) && isspace(*p)))
527 while (isascii(*p) && isspace(*p))
534 /* check if [key]@map:spec */
536 if (!SM_IS_DIR_DELIM(*p) &&
538 (q = strchr(p, '@')) != NULL)
542 /* look for @LDAP or @map: in string */
543 if (strcmp(q, "LDAP") == 0 ||
545 strchr(q, ':') != NULL))
551 /* use entire spec */
556 file = extrquotstr(p, &q, " ", &ok);
559 syserr("illegal filename '%s'", p);
564 if (*file == '|' || ismap)
574 while (isascii(*++p) && isspace(*p))
578 fileclass(mid, file, p, ismap, safe, optional);
582 case 'L': /* extended load average description */
587 #if defined(SUN_EXTENSIONS) && defined(SUN_LOOKUP_MACRO)
588 case 'L': /* lookup macro */
589 case 'G': /* lookup class */
590 /* reserved for Sun -- NIS+ database lookup */
591 if (VendorCode != VENDOR_SUN)
593 sun_lg_config_line(bp, e);
595 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_LOOKUP_MACRO) */
597 case 'M': /* define mailer */
601 case 'O': /* set option */
602 setoption(bp[1], &bp[2], safe, false, e);
605 case 'P': /* set precedence */
606 if (NumPriorities >= MAXPRIORITIES)
608 toomany('P', MAXPRIORITIES);
611 for (p = &bp[1]; *p != '\0' && *p != '='; p++)
616 Priorities[NumPriorities].pri_name = newstr(&bp[1]);
617 Priorities[NumPriorities].pri_val = atoi(++p);
621 case 'Q': /* define queue */
622 makequeue(&bp[1], true);
625 case 'V': /* configuration syntax version */
626 for (p = &bp[1]; isascii(*p) && isspace(*p); p++)
628 if (!isascii(*p) || !isdigit(*p))
630 syserr("invalid argument to V line: \"%.20s\"",
634 ConfigLevel = strtol(p, &ep, 10);
637 ** Do heuristic tweaking for back compatibility.
640 if (ConfigLevel >= 5)
642 /* level 5 configs have short name in $w */
643 p = macvalue('w', e);
644 if (p != NULL && (p = strchr(p, '.')) != NULL)
647 macdefine(&e->e_macro, A_TEMP, 'w',
651 if (ConfigLevel >= 6)
653 ColonOkInAddr = false;
657 ** Look for vendor code.
662 /* extract vendor code */
663 for (p = ep; isascii(*p) && isalpha(*p); )
668 syserr("invalid V line vendor code: \"%s\"",
674 expand(&bp[1], exbuf, sizeof exbuf, e);
675 (void) makemapentry(exbuf);
682 setuserenv(&bp[1], p);
685 case 'X': /* mail filter */
687 milter_setup(&bp[1]);
689 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
690 "Warning: Filter usage ('X') requires Milter support (-DMILTER)\n");
696 syserr("unknown configuration line \"%s\"", bp);
699 sm_free(bp); /* XXX */
703 syserr("I/O read error");
704 finis(false, true, EX_OSFILE);
706 (void) sm_io_close(cf, SM_TIME_DEFAULT);
709 /* initialize host maps from local service tables */
712 /* initialize daemon (if not defined yet) */
715 /* determine if we need to do special name-server frotz */
718 char *maptype[MAXMAPSTACK];
719 short mapreturn[MAXMAPACTIONS];
721 nmaps = switch_map_find("hosts", maptype, mapreturn);
722 UseNameServer = false;
723 if (nmaps > 0 && nmaps <= MAXMAPSTACK)
727 for (mapno = 0; mapno < nmaps && !UseNameServer;
730 if (strcmp(maptype[mapno], "dns") == 0)
731 UseNameServer = true;
737 ** TRANSLATE_DOLLARS -- convert $x into internal form
739 ** Actually does all appropriate pre-processing of a config line
740 ** to turn it into internal form.
743 ** bp -- the buffer to translate.
746 ** None. The buffer is translated in place. Since the
747 ** translations always make the buffer shorter, this is
748 ** safe without a size parameter.
752 translate_dollars(bp)
758 for (p = bp; *p != '\0'; p++)
760 if (*p == '#' && p > bp && ConfigLevel >= 3)
767 /* it's from $# -- let it go through */
772 /* it's backslash escaped */
773 (void) sm_strlcpy(p, p + 1, strlen(p));
777 /* delete leading white space */
778 while (isascii(*p) && isspace(*p) &&
779 *p != '\n' && p > bp)
781 if ((e = strchr(++p, '\n')) != NULL)
782 (void) sm_strlcpy(p, e, strlen(p));
790 if (*p != '$' || p[1] == '\0')
795 /* actual dollar sign.... */
796 (void) sm_strlcpy(p, p + 1, strlen(p));
800 /* convert to macro expansion character */
803 /* special handling for $=, $~, $&, and $? */
804 if (*p == '=' || *p == '~' || *p == '&' || *p == '?')
807 /* convert macro name to code */
808 *p = macid_parse(p, &ep);
810 (void) sm_strlcpy(p + 1, ep, strlen(p + 1));
813 /* strip trailing white space from the line */
814 while (--p > bp && isascii(*p) && isspace(*p))
818 ** TOOMANY -- signal too many of some option
821 ** id -- the id of the error line
822 ** maxcnt -- the maximum possible values
836 syserr("too many %c lines, %d max", id, maxcnt);
839 ** FILECLASS -- read members of a class from a file
842 ** class -- class to define.
843 ** filename -- name of file to read.
844 ** fmt -- scanf string to use for match.
845 ** ismap -- if set, this is a map lookup.
846 ** safe -- if set, this is a safe read.
847 ** optional -- if set, it is not an error for the file to
854 ** puts all lines in filename that match a scanf into
859 ** Break up the match into words and add to class.
863 parse_class_words(class, line)
867 while (line != NULL && *line != '\0')
871 /* strip leading spaces */
872 while (isascii(*line) && isspace(*line))
877 /* find the end of the word */
879 while (*line != '\0' && !(isascii(*line) && isspace(*line)))
884 /* enter the word in the symbol table */
890 fileclass(class, filename, fmt, ismap, safe, optional)
905 sm_dprintf("fileclass(%s, fmt=%s)\n", filename, fmt);
907 if (*filename == '\0')
909 syserr("fileclass: missing file name");
921 mn = newstr(macname(class));
926 if ((p = strchr(filename, '@')) == NULL)
928 /* should not happen */
929 syserr("fileclass: bogus map specification");
939 if (strcmp(cl, "LDAP") == 0)
943 char jbuf[MAXHOSTNAMELEN];
947 expand("\201j", jbuf, sizeof jbuf, &BlankEnvelope);
950 (void) sm_strlcpy(jbuf, "localhost",
954 /* impose the default schema */
955 lc = macvalue(macid("{sendmailMTACluster}"), CurEnv);
960 expand(lc, lcbuf, sizeof lcbuf, CurEnv);
965 n = sm_snprintf(buf, sizeof buf,
966 "-k (&(objectClass=sendmailMTAClass)(sendmailMTAClassName=%s)(|(sendmailMTACluster=%s)(sendmailMTAHost=%s))) -v sendmailMTAClassValue,sendmailMTAClassSearch:FILTER:sendmailMTAClass,sendmailMTAClassURL:URL:sendmailMTAClass",
970 syserr("fileclass: F{%s}: Default LDAP string too long",
980 if ((spec = strchr(cl, ':')) == NULL)
982 syserr("fileclass: F{%s}: missing map class",
990 /* set up map structure */
991 mapclass = stab(cl, ST_MAPCLASS, ST_FIND);
992 if (mapclass == NULL)
994 syserr("fileclass: F{%s}: class %s not available",
999 memset(&map, '\0', sizeof map);
1000 map.map_class = &mapclass->s_mapclass;
1002 map.map_mflags |= MF_FILECLASS;
1005 sm_dprintf("fileclass: F{%s}: map class %s, key %s, spec %s\n",
1009 /* parse map spec */
1010 if (!map.map_class->map_parse(&map, spec))
1012 /* map_parse() showed the error already */
1016 map.map_mflags |= MF_VALID;
1019 if (map.map_class->map_open(&map, O_RDONLY))
1021 map.map_mflags |= MF_OPEN;
1022 map.map_pid = getpid();
1027 !bitset(MF_OPTIONAL, map.map_mflags))
1028 syserr("fileclass: F{%s}: map open failed",
1035 p = (*map.map_class->map_lookup)(&map, key, NULL, &status);
1036 if (status != EX_OK && status != EX_NOTFOUND)
1039 syserr("fileclass: F{%s}: map lookup failed",
1044 /* use the results */
1046 parse_class_words(class, p);
1049 map.map_mflags |= MF_CLOSING;
1050 map.map_class->map_close(&map);
1051 map.map_mflags &= ~(MF_OPEN|MF_WRITABLE|MF_CLOSING);
1055 else if (filename[0] == '|')
1059 char *argv[MAXPV + 1];
1062 for (p = strtok(&filename[1], " \t");
1063 p != NULL && i < MAXPV;
1064 p = strtok(NULL, " \t"))
1067 pid = prog_open(argv, &fd, CurEnv);
1071 f = sm_io_open(SmFtStdiofd, SM_TIME_DEFAULT,
1072 (void *) &fd, SM_IO_RDONLY, NULL);
1078 if (!bitnset(DBS_CLASSFILEINUNSAFEDIRPATH, DontBlameSendmail))
1079 sff |= SFF_SAFEDIRPATH;
1080 if (!bitnset(DBS_LINKEDCLASSFILEINWRITABLEDIR,
1084 sff |= SFF_OPENASROOT;
1085 else if (RealUid == 0)
1087 if (DontLockReadFiles)
1089 f = safefopen(filename, O_RDONLY, 0, sff);
1094 syserr("fileclass: cannot open '%s'", filename);
1098 while (sm_io_fgets(f, SM_TIME_DEFAULT, buf, sizeof buf) != NULL)
1101 char wordbuf[MAXLINE + 1];
1107 if (sm_io_sscanf(buf, fmt, wordbuf) != 1)
1114 parse_class_words(class, p);
1117 ** If anything else is added here,
1118 ** check if the '@' map case above
1119 ** needs the code as well.
1123 (void) sm_io_close(f, SM_TIME_DEFAULT);
1125 (void) waitfor(pid);
1128 ** MAKEMAILER -- define a new mailer.
1131 ** line -- description of mailer. This is in labeled
1132 ** fields. The fields are:
1133 ** A -- the argv for this mailer
1134 ** C -- the character set for MIME conversions
1135 ** D -- the directory to run in
1136 ** E -- the eol string
1137 ** F -- the flags associated with the mailer
1138 ** L -- the maximum line length
1139 ** M -- the maximum message size
1140 ** N -- the niceness at which to run
1141 ** P -- the path to the mailer
1142 ** Q -- the queue group for the mailer
1143 ** R -- the recipient rewriting set
1144 ** S -- the sender rewriting set
1145 ** T -- the mailer type (for DSNs)
1146 ** U -- the uid to run as
1147 ** W -- the time to wait at the end
1148 ** m -- maximum messages per connection
1149 ** r -- maximum number of recipients per message
1150 ** / -- new root directory
1151 ** The first word is the canonical name of the mailer.
1157 ** enters the mailer into the mailer table.
1165 register struct mailer *m;
1170 static int nextmailer = 0; /* "free" index into Mailer struct */
1172 /* allocate a mailer and set up defaults */
1173 m = (struct mailer *) xalloc(sizeof *m);
1174 memset((char *) m, '\0', sizeof *m);
1175 errno = 0; /* avoid bogus error text */
1177 /* collect the mailer name */
1179 *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p));
1184 if (line[0] == '\0')
1186 syserr("name required for mailer");
1189 m->m_name = newstr(line);
1194 /* now scan through and assign info from the fields */
1197 auto char *delimptr;
1199 while (*p != '\0' &&
1200 (*p == ',' || (isascii(*p) && isspace(*p))))
1203 /* p now points to field code */
1205 while (*p != '\0' && *p != '=' && *p != ',')
1209 syserr("mailer %s: `=' expected", m->m_name);
1212 while (isascii(*p) && isspace(*p))
1215 /* p now points to the field body */
1216 p = munchstring(p, &delimptr, ',');
1218 /* install the field into the mailer struct */
1221 case 'P': /* pathname */
1222 if (*p != '\0') /* error is issued below */
1223 m->m_mailer = newstr(p);
1226 case 'F': /* flags */
1227 for (; *p != '\0'; p++)
1229 if (!(isascii(*p) && isspace(*p)))
1231 #if _FFR_DEPRECATE_MAILER_FLAG_I
1232 if (*p == M_INTERNAL)
1233 sm_syslog(LOG_WARNING, NOQID,
1234 "WARNING: mailer=%s, flag=%c deprecated",
1236 #endif /* _FFR_DEPRECATE_MAILER_FLAG_I */
1237 setbitn(bitidx(*p), m->m_flags);
1242 case 'S': /* sender rewriting ruleset */
1243 case 'R': /* recipient rewriting ruleset */
1244 i = strtorwset(p, &endp, ST_ENTER);
1248 m->m_sh_rwset = m->m_se_rwset = i;
1250 m->m_rh_rwset = m->m_re_rwset = i;
1255 i = strtorwset(p, NULL, ST_ENTER);
1265 case 'E': /* end of line string */
1267 syserr("mailer %s: null end-of-line string",
1270 m->m_eol = newstr(p);
1273 case 'A': /* argument vector */
1274 if (*p != '\0') /* error is issued below */
1275 m->m_argv = makeargv(p);
1278 case 'M': /* maximum message size */
1279 m->m_maxsize = atol(p);
1282 case 'm': /* maximum messages per connection */
1283 m->m_maxdeliveries = atoi(p);
1286 case 'r': /* max recipient per envelope */
1287 m->m_maxrcpt = atoi(p);
1290 case 'L': /* maximum line length */
1291 m->m_linelimit = atoi(p);
1292 if (m->m_linelimit < 0)
1296 case 'N': /* run niceness */
1297 m->m_nice = atoi(p);
1300 case 'D': /* working directory */
1302 syserr("mailer %s: null working directory",
1305 m->m_execdir = newstr(p);
1308 case 'C': /* default charset */
1310 syserr("mailer %s: null charset", m->m_name);
1312 m->m_defcharset = newstr(p);
1315 case 'Q': /* queue for this mailer */
1318 syserr("mailer %s: null queue", m->m_name);
1321 s = stab(p, ST_QUEUE, ST_FIND);
1323 syserr("mailer %s: unknown queue %s",
1326 m->m_qgrp = s->s_quegrp->qg_index;
1329 case 'T': /* MTA-Name/Address/Diagnostic types */
1330 /* extract MTA name type; default to "dns" */
1331 m->m_mtatype = newstr(p);
1332 p = strchr(m->m_mtatype, '/');
1339 if (*m->m_mtatype == '\0')
1340 m->m_mtatype = "dns";
1342 /* extract address type; default to "rfc822" */
1352 if (m->m_addrtype == NULL || *m->m_addrtype == '\0')
1353 m->m_addrtype = "rfc822";
1355 /* extract diagnostic type; default to "smtp" */
1357 if (m->m_diagtype == NULL || *m->m_diagtype == '\0')
1358 m->m_diagtype = "smtp";
1361 case 'U': /* user id */
1362 if (isascii(*p) && !isdigit(*p))
1367 while (*p != '\0' && isascii(*p) &&
1368 (isalnum(*p) || strchr("-_", *p) != NULL))
1370 while (isascii(*p) && isspace(*p))
1376 syserr("mailer %s: null user name",
1380 pw = sm_getpwnam(q);
1383 syserr("readcf: mailer U= flag: unknown user %s", q);
1388 m->m_uid = pw->pw_uid;
1389 m->m_gid = pw->pw_gid;
1396 m->m_uid = strtol(p, &q, 0);
1398 while (isascii(*p) && isspace(*p))
1403 while (isascii(*p) && isspace(*p))
1407 if (isascii(*p) && !isdigit(*p))
1412 while (isascii(*p) && isalnum(*p))
1417 syserr("mailer %s: null group name",
1424 syserr("readcf: mailer U= flag: unknown group %s", q);
1428 m->m_gid = gr->gr_gid;
1432 m->m_gid = strtol(p, NULL, 0);
1436 case 'W': /* wait timeout */
1437 m->m_wait = convtime(p, 's');
1440 case '/': /* new root directory */
1442 syserr("mailer %s: null root directory",
1445 m->m_rootdir = newstr(p);
1449 syserr("M%s: unknown mailer equate %c=",
1458 if (bitnset(M_SECURE_PORT, m->m_flags))
1460 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1461 "M%s: Warning: F=%c set on system that doesn't support rresvport()\n",
1462 m->m_name, M_SECURE_PORT);
1464 #endif /* !HASRRESVPORT */
1469 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1470 "M%s: Warning: N= set on system that doesn't support nice()\n",
1473 #endif /* !HASNICE */
1475 /* do some rationality checking */
1476 if (m->m_argv == NULL)
1478 syserr("M%s: A= argument required", m->m_name);
1481 if (m->m_mailer == NULL)
1483 syserr("M%s: P= argument required", m->m_name);
1487 if (nextmailer >= MAXMAILERS)
1489 syserr("too many mailers defined (%d max)", MAXMAILERS);
1493 if (m->m_maxrcpt <= 0)
1494 m->m_maxrcpt = DEFAULT_MAX_RCPT;
1496 /* do some heuristic cleanup for back compatibility */
1497 if (bitnset(M_LIMITS, m->m_flags))
1499 if (m->m_linelimit == 0)
1500 m->m_linelimit = SMTPLINELIM;
1501 if (ConfigLevel < 2)
1502 setbitn(M_7BITS, m->m_flags);
1505 if (strcmp(m->m_mailer, "[TCP]") == 0)
1507 syserr("M%s: P=[TCP] must be replaced by P=[IPC]", m->m_name);
1511 if (strcmp(m->m_mailer, "[IPC]") == 0)
1513 /* Use the second argument for host or path to socket */
1514 if (m->m_argv[0] == NULL || m->m_argv[1] == NULL ||
1515 m->m_argv[1][0] == '\0')
1517 syserr("M%s: too few parameters for %s mailer",
1518 m->m_name, m->m_mailer);
1521 if (strcmp(m->m_argv[0], "TCP") != 0
1523 && strcmp(m->m_argv[0], "FILE") != 0
1524 #endif /* NETUNIX */
1527 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1528 "M%s: Warning: first argument in %s mailer must be %s\n",
1529 m->m_name, m->m_mailer,
1534 #endif /* NETUNIX */
1537 if (m->m_mtatype == NULL)
1538 m->m_mtatype = "dns";
1539 if (m->m_addrtype == NULL)
1540 m->m_addrtype = "rfc822";
1541 if (m->m_diagtype == NULL)
1543 if (m->m_argv[0] != NULL &&
1544 strcmp(m->m_argv[0], "FILE") == 0)
1545 m->m_diagtype = "x-unix";
1547 m->m_diagtype = "smtp";
1550 else if (strcmp(m->m_mailer, "[FILE]") == 0)
1552 /* Use the second argument for filename */
1553 if (m->m_argv[0] == NULL || m->m_argv[1] == NULL ||
1554 m->m_argv[2] != NULL)
1556 syserr("M%s: too %s parameters for [FILE] mailer",
1558 (m->m_argv[0] == NULL ||
1559 m->m_argv[1] == NULL) ? "few" : "many");
1562 else if (strcmp(m->m_argv[0], "FILE") != 0)
1564 syserr("M%s: first argument in [FILE] mailer must be FILE",
1570 if (m->m_eol == NULL)
1574 /* default for SMTP is \r\n; use \n for local delivery */
1575 for (pp = m->m_argv; *pp != NULL; pp++)
1577 for (p = *pp; *p != '\0'; )
1579 if ((*p++ & 0377) == MACROEXPAND && *p == 'u')
1591 /* enter the mailer into the symbol table */
1592 s = stab(m->m_name, ST_MAILER, ST_ENTER);
1593 if (s->s_mailer != NULL)
1595 i = s->s_mailer->m_mno;
1596 sm_free(s->s_mailer); /* XXX */
1602 Mailer[i] = s->s_mailer = m;
1606 ** MUNCHSTRING -- translate a string into internal form.
1609 ** p -- the string to munch.
1610 ** delimptr -- if non-NULL, set to the pointer of the
1611 ** field delimiter character.
1612 ** delim -- the delimiter for the field.
1615 ** the munched string.
1618 ** the munched string is a local static buffer.
1619 ** it must be copied before the function is called again.
1623 munchstring(p, delimptr, delim)
1629 bool backslash = false;
1630 bool quotemode = false;
1631 static char buf[MAXLINE];
1633 for (q = buf; *p != '\0' && q < &buf[sizeof buf - 1]; p++)
1637 /* everything is roughly literal */
1641 case 'r': /* carriage return */
1645 case 'n': /* newline */
1649 case 'f': /* form feed */
1653 case 'b': /* backspace */
1664 quotemode = !quotemode;
1665 else if (quotemode || *p != delim)
1672 if (delimptr != NULL)
1678 ** EXTRQUOTSTR -- extract a (quoted) string.
1680 ** This routine deals with quoted (") strings and escaped
1684 ** p -- source string.
1685 ** delimptr -- if non-NULL, set to the pointer of the
1686 ** field delimiter character.
1687 ** delimbuf -- delimiters for the field.
1688 ** st -- if non-NULL, store the return value (whether the
1689 ** string was correctly quoted) here.
1692 ** the extracted string.
1695 ** the returned string is a local static buffer.
1696 ** it must be copied before the function is called again.
1700 extrquotstr(p, delimptr, delimbuf, st)
1707 bool backslash = false;
1708 bool quotemode = false;
1709 static char buf[MAXLINE];
1711 for (q = buf; *p != '\0' && q < &buf[sizeof buf - 1]; p++)
1722 quotemode = !quotemode;
1723 else if (quotemode ||
1724 strchr(delimbuf, (int) *p) == NULL)
1730 if (delimptr != NULL)
1734 *st = !(quotemode || backslash);
1738 ** MAKEARGV -- break up a string into words
1741 ** p -- the string to break up.
1744 ** a char **argv (dynamically allocated)
1757 char *argv[MAXPV + 1];
1759 /* take apart the words */
1761 while (*p != '\0' && i < MAXPV)
1764 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
1766 while (isascii(*p) && isspace(*p))
1768 argv[i++] = newstr(q);
1772 /* now make a copy of the argv */
1773 avp = (char **) xalloc(sizeof *avp * i);
1774 memmove((char *) avp, (char *) argv, sizeof *avp * i);
1779 ** PRINTRULES -- print rewrite rules (for debugging)
1788 ** prints rewrite rules.
1794 register struct rewrite *rwp;
1795 register int ruleset;
1797 for (ruleset = 0; ruleset < 10; ruleset++)
1799 if (RewriteRules[ruleset] == NULL)
1801 sm_dprintf("\n----Rule Set %d:", ruleset);
1803 for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
1805 sm_dprintf("\nLHS:");
1806 printav(sm_debug_file(), rwp->r_lhs);
1808 printav(sm_debug_file(), rwp->r_rhs);
1813 ** PRINTMAILER -- print mailer structure (for debugging)
1816 ** fp -- output file
1817 ** m -- the mailer to print
1830 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT,
1831 "mailer %d (%s): P=%s S=", m->m_mno, m->m_name,
1833 if (RuleSetNames[m->m_se_rwset] == NULL)
1834 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d/",
1837 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s/",
1838 RuleSetNames[m->m_se_rwset]);
1839 if (RuleSetNames[m->m_sh_rwset] == NULL)
1840 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d R=",
1843 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s R=",
1844 RuleSetNames[m->m_sh_rwset]);
1845 if (RuleSetNames[m->m_re_rwset] == NULL)
1846 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d/",
1849 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s/",
1850 RuleSetNames[m->m_re_rwset]);
1851 if (RuleSetNames[m->m_rh_rwset] == NULL)
1852 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d ",
1855 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s ",
1856 RuleSetNames[m->m_rh_rwset]);
1857 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "M=%ld U=%d:%d F=",
1858 m->m_maxsize, (int) m->m_uid, (int) m->m_gid);
1859 for (j = '\0'; j <= '\177'; j++)
1860 if (bitnset(j, m->m_flags))
1861 (void) sm_io_putc(fp, SM_TIME_DEFAULT, j);
1862 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " L=%d E=",
1864 xputs(fp, m->m_eol);
1865 if (m->m_defcharset != NULL)
1866 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " C=%s",
1868 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " T=%s/%s/%s",
1869 m->m_mtatype == NULL
1870 ? "<undefined>" : m->m_mtatype,
1871 m->m_addrtype == NULL
1872 ? "<undefined>" : m->m_addrtype,
1873 m->m_diagtype == NULL
1874 ? "<undefined>" : m->m_diagtype);
1875 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " r=%d", m->m_maxrcpt);
1876 if (m->m_argv != NULL)
1878 char **a = m->m_argv;
1880 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " A=");
1884 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT,
1889 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "\n");
1892 ** SETOPTION -- set global processing option
1895 ** opt -- option name.
1896 ** val -- option value (as a text string).
1897 ** safe -- set if this came from a configuration file.
1898 ** Some options (if set from the command line) will
1899 ** reset the user id to avoid security problems.
1900 ** sticky -- if set, don't let other setoptions override
1902 ** e -- the main envelope.
1908 ** Sets options as implied by the arguments.
1911 static BITMAP256 StickyOpt; /* set if option is stuck */
1915 static struct resolverflags
1917 char *rf_name; /* name of the flag */
1918 long rf_bits; /* bits to set/clear */
1921 { "debug", RES_DEBUG },
1922 { "aaonly", RES_AAONLY },
1923 { "usevc", RES_USEVC },
1924 { "primary", RES_PRIMARY },
1925 { "igntc", RES_IGNTC },
1926 { "recurse", RES_RECURSE },
1927 { "defnames", RES_DEFNAMES },
1928 { "stayopen", RES_STAYOPEN },
1929 { "dnsrch", RES_DNSRCH },
1930 # ifdef RES_USE_INET6
1931 { "use_inet6", RES_USE_INET6 },
1932 # endif /* RES_USE_INET6 */
1933 { "true", 0 }, /* avoid error on old syntax */
1937 #endif /* NAMED_BIND */
1939 #define OI_NONE 0 /* no special treatment */
1940 #define OI_SAFE 0x0001 /* safe for random people to use */
1941 #define OI_SUBOPT 0x0002 /* option has suboptions */
1943 static struct optioninfo
1945 char *o_name; /* long name of option */
1946 unsigned char o_code; /* short name of option */
1947 unsigned short o_flags; /* option flags */
1950 #if defined(SUN_EXTENSIONS) && defined(REMOTE_MODE)
1951 { "RemoteMode", '>', OI_NONE },
1952 #endif /* defined(SUN_EXTENSIONS) && defined(REMOTE_MODE) */
1953 { "SevenBitInput", '7', OI_SAFE },
1954 { "EightBitMode", '8', OI_SAFE },
1955 { "AliasFile", 'A', OI_NONE },
1956 { "AliasWait", 'a', OI_NONE },
1957 { "BlankSub", 'B', OI_NONE },
1958 { "MinFreeBlocks", 'b', OI_SAFE },
1959 { "CheckpointInterval", 'C', OI_SAFE },
1960 { "HoldExpensive", 'c', OI_NONE },
1961 { "DeliveryMode", 'd', OI_SAFE },
1962 { "ErrorHeader", 'E', OI_NONE },
1963 { "ErrorMode", 'e', OI_SAFE },
1964 { "TempFileMode", 'F', OI_NONE },
1965 { "SaveFromLine", 'f', OI_NONE },
1966 { "MatchGECOS", 'G', OI_NONE },
1968 /* no long name, just here to avoid problems in setoption */
1969 { "", 'g', OI_NONE },
1970 { "HelpFile", 'H', OI_NONE },
1971 { "MaxHopCount", 'h', OI_NONE },
1972 { "ResolverOptions", 'I', OI_NONE },
1973 { "IgnoreDots", 'i', OI_SAFE },
1974 { "ForwardPath", 'J', OI_NONE },
1975 { "SendMimeErrors", 'j', OI_SAFE },
1976 { "ConnectionCacheSize", 'k', OI_NONE },
1977 { "ConnectionCacheTimeout", 'K', OI_NONE },
1978 { "UseErrorsTo", 'l', OI_NONE },
1979 { "LogLevel", 'L', OI_SAFE },
1980 { "MeToo", 'm', OI_SAFE },
1982 /* no long name, just here to avoid problems in setoption */
1983 { "", 'M', OI_NONE },
1984 { "CheckAliases", 'n', OI_NONE },
1985 { "OldStyleHeaders", 'o', OI_SAFE },
1986 { "DaemonPortOptions", 'O', OI_NONE },
1987 { "PrivacyOptions", 'p', OI_SAFE },
1988 { "PostmasterCopy", 'P', OI_NONE },
1989 { "QueueFactor", 'q', OI_NONE },
1990 { "QueueDirectory", 'Q', OI_NONE },
1991 { "DontPruneRoutes", 'R', OI_NONE },
1992 { "Timeout", 'r', OI_SUBOPT },
1993 { "StatusFile", 'S', OI_NONE },
1994 { "SuperSafe", 's', OI_SAFE },
1995 { "QueueTimeout", 'T', OI_NONE },
1996 { "TimeZoneSpec", 't', OI_NONE },
1997 { "UserDatabaseSpec", 'U', OI_NONE },
1998 { "DefaultUser", 'u', OI_NONE },
1999 { "FallbackMXhost", 'V', OI_NONE },
2000 { "Verbose", 'v', OI_SAFE },
2001 { "TryNullMXList", 'w', OI_NONE },
2002 { "QueueLA", 'x', OI_NONE },
2003 { "RefuseLA", 'X', OI_NONE },
2004 { "RecipientFactor", 'y', OI_NONE },
2005 { "ForkEachJob", 'Y', OI_NONE },
2006 { "ClassFactor", 'z', OI_NONE },
2007 { "RetryFactor", 'Z', OI_NONE },
2008 #define O_QUEUESORTORD 0x81
2009 { "QueueSortOrder", O_QUEUESORTORD, OI_SAFE },
2010 #define O_HOSTSFILE 0x82
2011 { "HostsFile", O_HOSTSFILE, OI_NONE },
2013 { "MinQueueAge", O_MQA, OI_SAFE },
2014 #define O_DEFCHARSET 0x85
2015 { "DefaultCharSet", O_DEFCHARSET, OI_SAFE },
2016 #define O_SSFILE 0x86
2017 { "ServiceSwitchFile", O_SSFILE, OI_NONE },
2018 #define O_DIALDELAY 0x87
2019 { "DialDelay", O_DIALDELAY, OI_SAFE },
2020 #define O_NORCPTACTION 0x88
2021 { "NoRecipientAction", O_NORCPTACTION, OI_SAFE },
2022 #define O_SAFEFILEENV 0x89
2023 { "SafeFileEnvironment", O_SAFEFILEENV, OI_NONE },
2024 #define O_MAXMSGSIZE 0x8a
2025 { "MaxMessageSize", O_MAXMSGSIZE, OI_NONE },
2026 #define O_COLONOKINADDR 0x8b
2027 { "ColonOkInAddr", O_COLONOKINADDR, OI_SAFE },
2028 #define O_MAXQUEUERUN 0x8c
2029 { "MaxQueueRunSize", O_MAXQUEUERUN, OI_SAFE },
2030 #define O_MAXCHILDREN 0x8d
2031 { "MaxDaemonChildren", O_MAXCHILDREN, OI_NONE },
2032 #define O_KEEPCNAMES 0x8e
2033 { "DontExpandCnames", O_KEEPCNAMES, OI_NONE },
2034 #define O_MUSTQUOTE 0x8f
2035 { "MustQuoteChars", O_MUSTQUOTE, OI_NONE },
2036 #define O_SMTPGREETING 0x90
2037 { "SmtpGreetingMessage", O_SMTPGREETING, OI_NONE },
2038 #define O_UNIXFROM 0x91
2039 { "UnixFromLine", O_UNIXFROM, OI_NONE },
2040 #define O_OPCHARS 0x92
2041 { "OperatorChars", O_OPCHARS, OI_NONE },
2042 #define O_DONTINITGRPS 0x93
2043 { "DontInitGroups", O_DONTINITGRPS, OI_NONE },
2045 { "SingleLineFromHeader", O_SLFH, OI_SAFE },
2047 { "AllowBogusHELO", O_ABH, OI_SAFE },
2048 #define O_CONNTHROT 0x97
2049 { "ConnectionRateThrottle", O_CONNTHROT, OI_NONE },
2051 { "UnsafeGroupWrites", O_UGW, OI_NONE },
2052 #define O_DBLBOUNCE 0x9a
2053 { "DoubleBounceAddress", O_DBLBOUNCE, OI_NONE },
2054 #define O_HSDIR 0x9b
2055 { "HostStatusDirectory", O_HSDIR, OI_NONE },
2056 #define O_SINGTHREAD 0x9c
2057 { "SingleThreadDelivery", O_SINGTHREAD, OI_NONE },
2058 #define O_RUNASUSER 0x9d
2059 { "RunAsUser", O_RUNASUSER, OI_NONE },
2060 #define O_DSN_RRT 0x9e
2061 { "RrtImpliesDsn", O_DSN_RRT, OI_NONE },
2062 #define O_PIDFILE 0x9f
2063 { "PidFile", O_PIDFILE, OI_NONE },
2064 #define O_DONTBLAMESENDMAIL 0xa0
2065 { "DontBlameSendmail", O_DONTBLAMESENDMAIL, OI_NONE },
2067 { "DontProbeInterfaces", O_DPI, OI_NONE },
2068 #define O_MAXRCPT 0xa2
2069 { "MaxRecipientsPerMessage", O_MAXRCPT, OI_SAFE },
2070 #define O_DEADLETTER 0xa3
2071 { "DeadLetterDrop", O_DEADLETTER, OI_NONE },
2072 #if _FFR_DONTLOCKFILESFORREAD_OPTION
2073 # define O_DONTLOCK 0xa4
2074 { "DontLockFilesForRead", O_DONTLOCK, OI_NONE },
2075 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
2076 #define O_MAXALIASRCSN 0xa5
2077 { "MaxAliasRecursion", O_MAXALIASRCSN, OI_NONE },
2078 #define O_CNCTONLYTO 0xa6
2079 { "ConnectOnlyTo", O_CNCTONLYTO, OI_NONE },
2080 #define O_TRUSTUSER 0xa7
2081 { "TrustedUser", O_TRUSTUSER, OI_NONE },
2082 #define O_MAXMIMEHDRLEN 0xa8
2083 { "MaxMimeHeaderLength", O_MAXMIMEHDRLEN, OI_NONE },
2084 #define O_CONTROLSOCKET 0xa9
2085 { "ControlSocketName", O_CONTROLSOCKET, OI_NONE },
2086 #define O_MAXHDRSLEN 0xaa
2087 { "MaxHeadersLength", O_MAXHDRSLEN, OI_NONE },
2088 #if _FFR_MAX_FORWARD_ENTRIES
2089 # define O_MAXFORWARD 0xab
2090 { "MaxForwardEntries", O_MAXFORWARD, OI_NONE },
2091 #endif /* _FFR_MAX_FORWARD_ENTRIES */
2092 #define O_PROCTITLEPREFIX 0xac
2093 { "ProcessTitlePrefix", O_PROCTITLEPREFIX, OI_NONE },
2094 #define O_SASLINFO 0xad
2095 #if _FFR_ALLOW_SASLINFO
2096 { "DefaultAuthInfo", O_SASLINFO, OI_SAFE },
2097 #else /* _FFR_ALLOW_SASLINFO */
2098 { "DefaultAuthInfo", O_SASLINFO, OI_NONE },
2099 #endif /* _FFR_ALLOW_SASLINFO */
2100 #define O_SASLMECH 0xae
2101 { "AuthMechanisms", O_SASLMECH, OI_NONE },
2102 #define O_CLIENTPORT 0xaf
2103 { "ClientPortOptions", O_CLIENTPORT, OI_NONE },
2104 #define O_DF_BUFSIZE 0xb0
2105 { "DataFileBufferSize", O_DF_BUFSIZE, OI_NONE },
2106 #define O_XF_BUFSIZE 0xb1
2107 { "XscriptFileBufferSize", O_XF_BUFSIZE, OI_NONE },
2108 #define O_LDAPDEFAULTSPEC 0xb2
2109 { "LDAPDefaultSpec", O_LDAPDEFAULTSPEC, OI_NONE },
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 */
2174 #define O_REJECTLOGINTERVAL 0xd1
2175 { "RejectLogInterval", O_REJECTLOGINTERVAL, OI_NONE },
2176 #define O_REQUIRES_DIR_FSYNC 0xd2
2177 { "RequiresDirfsync", O_REQUIRES_DIR_FSYNC, OI_NONE },
2178 #define O_CONNECTION_RATE_WINDOW_SIZE 0xd3
2179 { "ConnectionRateWindowSize", O_CONNECTION_RATE_WINDOW_SIZE, OI_NONE },
2180 #define O_CRLFILE 0xd4
2181 { "CRLFile", O_CRLFILE, OI_NONE },
2182 #define O_FALLBACKSMARTHOST 0xd5
2183 { "FallbackSmartHost", O_FALLBACKSMARTHOST, OI_NONE },
2184 #define O_SASLREALM 0xd6
2185 { "AuthRealm", O_SASLREALM, OI_NONE },
2187 # define O_CRLPATH 0xd7
2188 { "CRLPath", O_CRLPATH, OI_NONE },
2189 #endif /* _FFR_CRLPATH */
2191 # define O_HELONAME 0xd8
2192 { "HeloName", O_HELONAME, OI_NONE },
2193 #endif /* _FFR_HELONAME */
2195 { NULL, '\0', OI_NONE }
2198 # define CANONIFY(val)
2200 # define SET_OPT_DEFAULT(opt, val) opt = val
2202 /* set a string option by expanding the value and assigning it */
2203 /* WARNING this belongs ONLY into a case statement! */
2204 #define SET_STRING_EXP(str) \
2205 expand(val, exbuf, sizeof exbuf, e); \
2206 newval = sm_pstrdup_x(exbuf); \
2213 #define OPTNAME o->o_name == NULL ? "<unknown>" : o->o_name
2216 setoption(opt, val, safe, sticky, e)
2221 register ENVELOPE *e;
2224 register struct optioninfo *o;
2227 bool can_setuid = RunAsUid == 0;
2230 extern bool Warn_Q_option;
2231 #if _FFR_ALLOW_SASLINFO
2232 extern unsigned int SubmitMode;
2233 #endif /* _FFR_ALLOW_SASLINFO */
2236 char exbuf[MAXLINE];
2237 #endif /* STARTTLS */
2242 /* full word options */
2243 struct optioninfo *sel;
2245 p = strchr(val, '=');
2247 p = &val[strlen(val)];
2254 syserr("readcf: null option name");
2261 subopt = strchr(val, '.');
2265 for (o = OptionTab; o->o_name != NULL; o++)
2267 if (sm_strncasecmp(o->o_name, val, strlen(val)) != 0)
2269 if (strlen(o->o_name) == strlen(val))
2271 /* completely specified -- this must be it */
2279 if (sel != NULL && o->o_name == NULL)
2281 else if (o->o_name == NULL)
2283 syserr("readcf: unknown option name %s", val);
2286 else if (sel != NULL)
2288 syserr("readcf: ambiguous option name %s (matches %s and %s)",
2289 val, sel->o_name, o->o_name);
2292 if (strlen(val) != strlen(o->o_name))
2294 int oldVerbose = Verbose;
2297 message("Option %s used as abbreviation for %s",
2299 Verbose = oldVerbose;
2306 for (o = OptionTab; o->o_name != NULL; o++)
2308 if (o->o_code == opt)
2311 if (o->o_name == NULL)
2313 syserr("readcf: unknown option name 0x%x", opt & 0xff);
2319 if (subopt != NULL && !bitset(OI_SUBOPT, o->o_flags))
2322 sm_dprintf("setoption: %s does not support suboptions, ignoring .%s\n",
2329 sm_dprintf(isascii(opt) && isprint(opt) ?
2330 "setoption %s (%c)%s%s=" :
2331 "setoption %s (0x%x)%s%s=",
2332 OPTNAME, opt, subopt == NULL ? "" : ".",
2333 subopt == NULL ? "" : subopt);
2334 xputs(sm_debug_file(), val);
2338 ** See if this option is preset for us.
2341 if (!sticky && bitnset(opt, StickyOpt))
2344 sm_dprintf(" (ignored)\n");
2349 ** Check to see if this option can be specified by this user.
2352 if (!safe && RealUid == 0)
2354 if (!safe && !bitset(OI_SAFE, o->o_flags))
2356 if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
2361 sm_dprintf(" (unsafe)");
2362 dp = drop_privileges(true);
2371 case '7': /* force seven-bit input */
2372 SevenBitInput = atobool(val);
2375 case '8': /* handling of 8-bit input */
2379 case 'p': /* pass 8 bit, convert MIME */
2380 MimeMode = MM_CVTMIME|MM_PASS8BIT;
2383 case 'm': /* convert 8-bit, convert MIME */
2384 MimeMode = MM_CVTMIME|MM_MIME8BIT;
2387 case 's': /* strict adherence */
2388 MimeMode = MM_CVTMIME;
2392 case 'r': /* reject 8-bit, don't convert MIME */
2396 case 'j': /* "just send 8" */
2397 MimeMode = MM_PASS8BIT;
2400 case 'a': /* encode 8 bit if available */
2401 MimeMode = MM_MIME8BIT|MM_PASS8BIT|MM_CVTMIME;
2404 case 'c': /* convert 8 bit to MIME, never 7 bit */
2405 MimeMode = MM_MIME8BIT;
2410 syserr("Unknown 8-bit mode %c", *val);
2411 finis(false, true, EX_USAGE);
2413 #else /* MIME8TO7 */
2414 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
2415 "Warning: Option: %s requires MIME8TO7 support\n",
2417 #endif /* MIME8TO7 */
2420 case 'A': /* set default alias file */
2425 SET_OPT_DEFAULT(al, "aliases");
2432 case 'a': /* look N minutes for "@:@" in alias file */
2434 SafeAlias = 5 MINUTES;
2436 SafeAlias = convtime(val, 'm');
2439 case 'B': /* substitution for blank character */
2441 if (SpaceSub == '\0')
2445 case 'b': /* min blocks free on queue fs/max msg size */
2446 p = strchr(val, '/');
2450 MaxMessageSize = atol(p);
2452 MinBlocksFree = atol(val);
2455 case 'c': /* don't connect to "expensive" mailers */
2456 NoConnect = atobool(val);
2459 case 'C': /* checkpoint every N addresses */
2460 if (safe || CheckpointInterval > atoi(val))
2461 CheckpointInterval = atoi(val);
2464 case 'd': /* delivery mode */
2468 set_delivery_mode(SM_DELIVER, e);
2471 case SM_QUEUE: /* queue only */
2472 case SM_DEFER: /* queue only and defer map lookups */
2473 case SM_DELIVER: /* do everything */
2474 case SM_FORK: /* fork after verification */
2475 set_delivery_mode(*val, e);
2479 syserr("Unknown delivery mode %c", *val);
2480 finis(false, true, EX_USAGE);
2484 case 'E': /* error message header/header file */
2486 ErrMsgFile = newstr(val);
2489 case 'e': /* set error processing mode */
2492 case EM_QUIET: /* be silent about it */
2493 case EM_MAIL: /* mail back */
2494 case EM_BERKNET: /* do berknet error processing */
2495 case EM_WRITE: /* write back (or mail) */
2496 case EM_PRINT: /* print errors normally (default) */
2497 e->e_errormode = *val;
2502 case 'F': /* file mode */
2503 FileMode = atooct(val) & 0777;
2506 case 'f': /* save Unix-style From lines on front */
2507 SaveFrom = atobool(val);
2510 case 'G': /* match recipients against GECOS field */
2511 MatchGecos = atobool(val);
2514 case 'g': /* default gid */
2516 if (isascii(*val) && isdigit(*val))
2520 register struct group *gr;
2525 syserr("readcf: option %c: unknown group %s",
2528 DefGid = gr->gr_gid;
2532 case 'H': /* help file */
2535 SET_OPT_DEFAULT(HelpFile, "helpfile");
2540 HelpFile = newstr(val);
2544 case 'h': /* maximum hop count */
2545 MaxHopCount = atoi(val);
2548 case 'I': /* use internet domain name server */
2550 for (p = val; *p != 0; )
2554 struct resolverflags *rfp;
2567 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
2571 if (sm_strcasecmp(q, "HasWildcardMX") == 0)
2573 HasWildcardMX = !clearmode;
2576 if (sm_strcasecmp(q, "WorkAroundBrokenAAAA") == 0)
2578 WorkAroundBrokenAAAA = !clearmode;
2581 for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
2583 if (sm_strcasecmp(q, rfp->rf_name) == 0)
2586 if (rfp->rf_name == NULL)
2587 syserr("readcf: I option value %s unrecognized", q);
2589 _res.options &= ~rfp->rf_bits;
2591 _res.options |= rfp->rf_bits;
2594 sm_dprintf("_res.options = %x, HasWildcardMX = %d\n",
2595 (unsigned int) _res.options, HasWildcardMX);
2596 #else /* NAMED_BIND */
2597 usrerr("name server (I option) specified but BIND not compiled in");
2598 #endif /* NAMED_BIND */
2601 case 'i': /* ignore dot lines in message */
2602 IgnrDot = atobool(val);
2605 case 'j': /* send errors in MIME (RFC 1341) format */
2606 SendMIMEErrors = atobool(val);
2609 case 'J': /* .forward search path */
2611 ForwardPath = newstr(val);
2614 case 'k': /* connection cache size */
2615 MaxMciCache = atoi(val);
2616 if (MaxMciCache < 0)
2620 case 'K': /* connection cache timeout */
2621 MciCacheTimeout = convtime(val, 'm');
2624 case 'l': /* use Errors-To: header */
2625 UseErrorsTo = atobool(val);
2628 case 'L': /* log level */
2629 if (safe || LogLevel < atoi(val))
2630 LogLevel = atoi(val);
2633 case 'M': /* define macro */
2635 mid = macid_parse(val, &ep);
2640 cleanstrcpy(p, p, strlen(p) + 1);
2641 macdefine(&CurEnv->e_macro, A_TEMP, mid, p);
2644 case 'm': /* send to me too */
2645 MeToo = atobool(val);
2648 case 'n': /* validate RHS in newaliases */
2649 CheckAliases = atobool(val);
2652 /* 'N' available -- was "net name" */
2654 case 'O': /* daemon options */
2655 if (!setdaemonoptions(val))
2656 syserr("too many daemons defined (%d max)", MAXDAEMONS);
2659 case 'o': /* assume old style headers */
2661 CurEnv->e_flags |= EF_OLDSTYLE;
2663 CurEnv->e_flags &= ~EF_OLDSTYLE;
2666 case 'p': /* select privacy level */
2670 register struct prival *pv;
2671 extern struct prival PrivacyValues[];
2673 while (isascii(*p) && (isspace(*p) || ispunct(*p)))
2678 while (isascii(*p) && isalnum(*p))
2683 for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
2685 if (sm_strcasecmp(val, pv->pv_name) == 0)
2688 if (pv->pv_name == NULL)
2689 syserr("readcf: Op line: %s unrecognized", val);
2691 PrivacyFlags |= pv->pv_flag;
2696 case 'P': /* postmaster copy address for returned mail */
2697 PostMasterCopy = newstr(val);
2700 case 'q': /* slope of queue only function */
2701 QueueFactor = atoi(val);
2704 case 'Q': /* queue directory */
2707 QueueDir = "mqueue";
2711 QueueDir = newstr(val);
2713 if (RealUid != 0 && !safe)
2714 Warn_Q_option = true;
2717 case 'R': /* don't prune routes */
2718 DontPruneRoutes = atobool(val);
2721 case 'r': /* read timeout */
2723 inittimeouts(val, sticky);
2725 settimeout(subopt, val, sticky);
2728 case 'S': /* status file */
2731 SET_OPT_DEFAULT(StatFile, "statistics");
2736 StatFile = newstr(val);
2740 case 's': /* be super safe, even if expensive */
2741 if (tolower(*val) == 'i')
2742 SuperSafe = SAFE_INTERACTIVE;
2743 else if (tolower(*val) == 'p')
2745 SuperSafe = SAFE_REALLY_POSTMILTER;
2747 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
2748 "Warning: SuperSafe=PostMilter requires Milter support (-DMILTER)\n");
2751 SuperSafe = atobool(val) ? SAFE_REALLY : SAFE_NO;
2754 case 'T': /* queue timeout */
2755 p = strchr(val, '/');
2759 settimeout("queuewarn", p, sticky);
2761 settimeout("queuereturn", val, sticky);
2764 case 't': /* time zone name */
2765 TimeZoneSpec = newstr(val);
2768 case 'U': /* location of user database */
2769 UdbSpec = newstr(val);
2772 case 'u': /* set default uid */
2773 for (p = val; *p != '\0'; p++)
2775 # if _FFR_DOTTED_USERNAMES
2776 if (*p == '/' || *p == ':')
2777 # else /* _FFR_DOTTED_USERNAMES */
2778 if (*p == '.' || *p == '/' || *p == ':')
2779 # endif /* _FFR_DOTTED_USERNAMES */
2785 if (isascii(*val) && isdigit(*val))
2792 register struct passwd *pw;
2795 pw = sm_getpwnam(val);
2798 syserr("readcf: option u: unknown user %s", val);
2803 DefUid = pw->pw_uid;
2804 DefGid = pw->pw_gid;
2805 DefUser = newstr(pw->pw_name);
2810 if (DefUid > UID_MAX)
2812 syserr("readcf: option u: uid value (%ld) > UID_MAX (%ld); ignored",
2813 (long)DefUid, (long)UID_MAX);
2816 # endif /* UID_MAX */
2818 /* handle the group if it is there */
2824 case 'V': /* fallback MX host */
2826 FallbackMX = newstr(val);
2829 case 'v': /* run in verbose mode */
2830 Verbose = atobool(val) ? 1 : 0;
2833 case 'w': /* if we are best MX, try host directly */
2834 TryNullMXList = atobool(val);
2837 /* 'W' available -- was wizard password */
2839 case 'x': /* load avg at which to auto-queue msgs */
2840 QueueLA = atoi(val);
2843 case 'X': /* load avg at which to auto-reject connections */
2844 RefuseLA = atoi(val);
2847 case O_DELAY_LA: /* load avg at which to delay connections */
2848 DelayLA = atoi(val);
2851 case 'y': /* work recipient factor */
2852 WkRecipFact = atoi(val);
2855 case 'Y': /* fork jobs during queue runs */
2856 ForkQueueRuns = atobool(val);
2859 case 'z': /* work message class factor */
2860 WkClassFact = atoi(val);
2863 case 'Z': /* work time factor */
2864 WkTimeFact = atoi(val);
2868 #if _FFR_QUEUE_GROUP_SORTORDER
2869 /* coordinate this with makequeue() */
2870 #endif /* _FFR_QUEUE_GROUP_SORTORDER */
2871 case O_QUEUESORTORD: /* queue sorting order */
2874 case 'f': /* File Name */
2876 QueueSortOrder = QSO_BYFILENAME;
2879 case 'h': /* Host first */
2881 QueueSortOrder = QSO_BYHOST;
2884 case 'm': /* Modification time */
2886 QueueSortOrder = QSO_BYMODTIME;
2889 case 'p': /* Priority order */
2891 QueueSortOrder = QSO_BYPRIORITY;
2894 case 't': /* Submission time */
2896 QueueSortOrder = QSO_BYTIME;
2899 case 'r': /* Random */
2901 QueueSortOrder = QSO_RANDOM;
2905 case 's': /* Shuffled host name */
2907 QueueSortOrder = QSO_BYSHUFFLE;
2909 #endif /* _FFR_RHS */
2911 case 'n': /* none */
2913 QueueSortOrder = QSO_NONE;
2917 syserr("Invalid queue sort order \"%s\"", val);
2921 case O_HOSTSFILE: /* pathname of /etc/hosts file */
2923 HostsFile = newstr(val);
2926 case O_MQA: /* minimum queue age between deliveries */
2927 MinQueueAge = convtime(val, 'm');
2930 case O_DEFCHARSET: /* default character set for mimefying */
2931 DefaultCharSet = newstr(denlstring(val, true, true));
2934 case O_SSFILE: /* service switch file */
2936 ServiceSwitchFile = newstr(val);
2939 case O_DIALDELAY: /* delay for dial-on-demand operation */
2940 DialDelay = convtime(val, 's');
2943 case O_NORCPTACTION: /* what to do if no recipient */
2944 if (sm_strcasecmp(val, "none") == 0)
2945 NoRecipientAction = NRA_NO_ACTION;
2946 else if (sm_strcasecmp(val, "add-to") == 0)
2947 NoRecipientAction = NRA_ADD_TO;
2948 else if (sm_strcasecmp(val, "add-apparently-to") == 0)
2949 NoRecipientAction = NRA_ADD_APPARENTLY_TO;
2950 else if (sm_strcasecmp(val, "add-bcc") == 0)
2951 NoRecipientAction = NRA_ADD_BCC;
2952 else if (sm_strcasecmp(val, "add-to-undisclosed") == 0)
2953 NoRecipientAction = NRA_ADD_TO_UNDISCLOSED;
2955 syserr("Invalid NoRecipientAction: %s", val);
2958 case O_SAFEFILEENV: /* chroot() environ for writing to files */
2962 /* strip trailing slashes */
2963 p = val + strlen(val) - 1;
2964 while (p >= val && *p == '/')
2970 SafeFileEnv = newstr(val);
2973 case O_MAXMSGSIZE: /* maximum message size */
2974 MaxMessageSize = atol(val);
2977 case O_COLONOKINADDR: /* old style handling of colon addresses */
2978 ColonOkInAddr = atobool(val);
2981 case O_MAXQUEUERUN: /* max # of jobs in a single queue run */
2982 MaxQueueRun = atoi(val);
2985 case O_MAXCHILDREN: /* max # of children of daemon */
2986 MaxChildren = atoi(val);
2989 case O_MAXQUEUECHILDREN: /* max # of children of daemon */
2990 MaxQueueChildren = atoi(val);
2993 case O_MAXRUNNERSPERQUEUE: /* max # runners in a queue group */
2994 MaxRunnersPerQueue = atoi(val);
2997 case O_NICEQUEUERUN: /* nice queue runs */
2999 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3000 "Warning: NiceQueueRun set on system that doesn't support nice()\n");
3001 #endif /* !HASNICE */
3003 /* XXX do we want to check the range? > 0 ? */
3004 NiceQueueRun = atoi(val);
3007 case O_SHMKEY: /* shared memory key */
3010 #else /* SM_CONF_SHM */
3011 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3012 "Warning: Option: %s requires shared memory support (-DSM_CONF_SHM)\n",
3014 #endif /* SM_CONF_SHM */
3018 case O_SHMKEYFILE: /* shared memory key file */
3020 SET_STRING_EXP(ShmKeyFile);
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",
3026 # endif /* SM_CONF_SHM */
3027 #endif /* _FFR_SELECT_SHM */
3029 #if _FFR_MAX_FORWARD_ENTRIES
3030 case O_MAXFORWARD: /* max # of forward entries */
3031 MaxForwardEntries = atoi(val);
3033 #endif /* _FFR_MAX_FORWARD_ENTRIES */
3035 case O_KEEPCNAMES: /* don't expand CNAME records */
3036 DontExpandCnames = atobool(val);
3039 case O_MUSTQUOTE: /* must quote these characters in phrases */
3040 (void) sm_strlcpy(buf, "@,;:\\()[]", sizeof buf);
3041 if (strlen(val) < sizeof buf - 10)
3042 (void) sm_strlcat(buf, val, sizeof buf);
3044 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3045 "Warning: MustQuoteChars too long, ignored.\n");
3046 MustQuoteChars = newstr(buf);
3049 case O_SMTPGREETING: /* SMTP greeting message (old $e macro) */
3050 SmtpGreeting = newstr(munchstring(val, NULL, '\0'));
3053 case O_UNIXFROM: /* UNIX From_ line (old $l macro) */
3054 UnixFromLine = newstr(munchstring(val, NULL, '\0'));
3057 case O_OPCHARS: /* operator characters (old $o macro) */
3058 if (OperatorChars != NULL)
3059 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3060 "Warning: OperatorChars is being redefined.\n It should only be set before ruleset definitions.\n");
3061 OperatorChars = newstr(munchstring(val, NULL, '\0'));
3064 case O_DONTINITGRPS: /* don't call initgroups(3) */
3065 DontInitGroups = atobool(val);
3068 case O_SLFH: /* make sure from fits on one line */
3069 SingleLineFromHeader = atobool(val);
3072 case O_ABH: /* allow HELO commands with syntax errors */
3073 AllowBogusHELO = atobool(val);
3076 case O_CONNTHROT: /* connection rate throttle */
3077 ConnRateThrottle = atoi(val);
3080 case O_UGW: /* group writable files are unsafe */
3083 setbitn(DBS_GROUPWRITABLEFORWARDFILESAFE,
3085 setbitn(DBS_GROUPWRITABLEINCLUDEFILESAFE,
3090 case O_DBLBOUNCE: /* address to which to send double bounces */
3091 DoubleBounceAddr = newstr(val);
3094 case O_HSDIR: /* persistent host status directory */
3098 HostStatDir = newstr(val);
3102 case O_SINGTHREAD: /* single thread deliveries (requires hsdir) */
3103 SingleThreadDelivery = atobool(val);
3106 case O_RUNASUSER: /* run bulk of code as this user */
3107 for (p = val; *p != '\0'; p++)
3109 # if _FFR_DOTTED_USERNAMES
3110 if (*p == '/' || *p == ':')
3111 # else /* _FFR_DOTTED_USERNAMES */
3112 if (*p == '.' || *p == '/' || *p == ':')
3113 # endif /* _FFR_DOTTED_USERNAMES */
3119 if (isascii(*val) && isdigit(*val))
3122 RunAsUid = atoi(val);
3126 register struct passwd *pw;
3128 pw = sm_getpwnam(val);
3131 syserr("readcf: option RunAsUser: unknown user %s", val);
3134 else if (can_setuid)
3137 RunAsUserName = newstr(val);
3138 RunAsUid = pw->pw_uid;
3139 RunAsGid = pw->pw_gid;
3141 else if (EffGid == pw->pw_gid)
3142 RunAsGid = pw->pw_gid;
3143 else if (UseMSP && *p == '\0')
3144 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3145 "WARNING: RunAsUser for MSP ignored, check group ids (egid=%d, want=%d)\n",
3150 if (RunAsUid > UID_MAX)
3152 syserr("readcf: option RunAsUser: uid value (%ld) > UID_MAX (%ld); ignored",
3153 (long) RunAsUid, (long) UID_MAX);
3156 # endif /* UID_MAX */
3159 if (isascii(*p) && isdigit(*p))
3163 runasgid = (gid_t) atoi(p);
3164 if (can_setuid || EffGid == runasgid)
3165 RunAsGid = runasgid;
3167 (void) sm_io_fprintf(smioout,
3169 "WARNING: RunAsUser for MSP ignored, check group ids (egid=%d, want=%d)\n",
3175 register struct group *gr;
3179 syserr("readcf: option RunAsUser: unknown group %s",
3181 else if (can_setuid || EffGid == gr->gr_gid)
3182 RunAsGid = gr->gr_gid;
3184 (void) sm_io_fprintf(smioout,
3186 "WARNING: RunAsUser for MSP ignored, check group ids (egid=%d, want=%d)\n",
3192 sm_dprintf("readcf: RunAsUser = %d:%d\n",
3193 (int) RunAsUid, (int) RunAsGid);
3197 RrtImpliesDsn = atobool(val);
3201 PSTRSET(PidFile, val);
3204 case O_DONTBLAMESENDMAIL:
3208 register struct dbsval *dbs;
3209 extern struct dbsval DontBlameSendmailValues[];
3211 while (isascii(*p) && (isspace(*p) || ispunct(*p)))
3216 while (isascii(*p) && isalnum(*p))
3221 for (dbs = DontBlameSendmailValues;
3222 dbs->dbs_name != NULL; dbs++)
3224 if (sm_strcasecmp(val, dbs->dbs_name) == 0)
3227 if (dbs->dbs_name == NULL)
3228 syserr("readcf: DontBlameSendmail option: %s unrecognized", val);
3229 else if (dbs->dbs_flag == DBS_SAFE)
3230 clrbitmap(DontBlameSendmail);
3232 setbitn(dbs->dbs_flag, DontBlameSendmail);
3238 if (sm_strcasecmp(val, "loopback") == 0)
3239 DontProbeInterfaces = DPI_SKIPLOOPBACK;
3240 else if (atobool(val))
3241 DontProbeInterfaces = DPI_PROBENONE;
3243 DontProbeInterfaces = DPI_PROBEALL;
3247 MaxRcptPerMsg = atoi(val);
3251 BadRcptThrottle = atoi(val);
3256 PSTRSET(DeadLetterDrop, val);
3259 #if _FFR_DONTLOCKFILESFORREAD_OPTION
3261 DontLockReadFiles = atobool(val);
3263 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
3265 case O_MAXALIASRCSN:
3266 MaxAliasRecursion = atoi(val);
3270 /* XXX should probably use gethostbyname */
3271 #if NETINET || NETINET6
3272 ConnectOnlyTo.sa.sa_family = AF_UNSPEC;
3274 if (anynet_pton(AF_INET6, val,
3275 &ConnectOnlyTo.sin6.sin6_addr) != 1)
3276 ConnectOnlyTo.sa.sa_family = AF_INET6;
3278 # endif /* NETINET6 */
3281 ConnectOnlyTo.sin.sin_addr.s_addr = inet_addr(val);
3282 if (ConnectOnlyTo.sin.sin_addr.s_addr != INADDR_NONE)
3283 ConnectOnlyTo.sa.sa_family = AF_INET;
3286 # endif /* NETINET */
3287 if (ConnectOnlyTo.sa.sa_family == AF_UNSPEC)
3289 syserr("readcf: option ConnectOnlyTo: invalid IP address %s",
3293 #endif /* NETINET || NETINET6 */
3297 # if !HASFCHOWN && !defined(_FFR_DROP_TRUSTUSER_WARNING)
3299 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3300 "readcf: option TrustedUser may cause problems on systems\n which do not support fchown() if UseMSP is not set.\n");
3301 # endif /* !HASFCHOWN && !defined(_FFR_DROP_TRUSTUSER_WARNING) */
3302 if (isascii(*val) && isdigit(*val))
3303 TrustedUid = atoi(val);
3306 register struct passwd *pw;
3309 pw = sm_getpwnam(val);
3312 syserr("readcf: option TrustedUser: unknown user %s", val);
3316 TrustedUid = pw->pw_uid;
3320 if (TrustedUid > UID_MAX)
3322 syserr("readcf: option TrustedUser: uid value (%ld) > UID_MAX (%ld)",
3323 (long) TrustedUid, (long) UID_MAX);
3326 # endif /* UID_MAX */
3329 case O_MAXMIMEHDRLEN:
3330 p = strchr(val, '/');
3333 MaxMimeHeaderLength = atoi(val);
3334 if (p != NULL && *p != '\0')
3335 MaxMimeFieldLength = atoi(p);
3337 MaxMimeFieldLength = MaxMimeHeaderLength / 2;
3339 if (MaxMimeHeaderLength <= 0)
3340 MaxMimeHeaderLength = 0;
3341 else if (MaxMimeHeaderLength < 128)
3342 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3343 "Warning: MaxMimeHeaderLength: header length limit set lower than 128\n");
3345 if (MaxMimeFieldLength <= 0)
3346 MaxMimeFieldLength = 0;
3347 else if (MaxMimeFieldLength < 40)
3348 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3349 "Warning: MaxMimeHeaderLength: field length limit set lower than 40\n");
3352 case O_CONTROLSOCKET:
3353 PSTRSET(ControlSocketName, val);
3357 MaxHeadersLength = atoi(val);
3359 if (MaxHeadersLength > 0 &&
3360 MaxHeadersLength < (MAXHDRSLEN / 2))
3361 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3362 "Warning: MaxHeadersLength: headers length limit set lower than %d\n",
3366 case O_PROCTITLEPREFIX:
3367 PSTRSET(ProcTitlePrefix, val);
3372 # if _FFR_ALLOW_SASLINFO
3374 ** Allow users to select their own authinfo file
3375 ** under certain circumstances, otherwise just ignore
3376 ** the option. If the option isn't ignored, several
3377 ** commands don't work very well, e.g., mailq.
3378 ** However, this is not a "perfect" solution.
3379 ** If mail is queued, the authentication info
3380 ** will not be used in subsequent delivery attempts.
3381 ** If we really want to support this, then it has
3382 ** to be stored in the queue file.
3384 if (!bitset(SUBMIT_MSA, SubmitMode) && RealUid != 0 &&
3385 RunAsUid != RealUid)
3387 # endif /* _FFR_ALLOW_SASLINFO */
3388 PSTRSET(SASLInfo, val);
3392 if (AuthMechanisms != NULL)
3393 sm_free(AuthMechanisms); /* XXX */
3395 AuthMechanisms = newstr(val);
3397 AuthMechanisms = NULL;
3401 if (AuthRealm != NULL)
3404 AuthRealm = newstr(val);
3410 while (val != NULL && *val != '\0')
3415 SASLOpts |= SASL_AUTH_AUTH;
3419 SASLOpts |= SASL_SEC_NOACTIVE;
3423 SASLOpts |= SASL_SEC_PASS_CREDENTIALS;
3427 SASLOpts |= SASL_SEC_NODICTIONARY;
3431 SASLOpts |= SASL_SEC_FORWARD_SECRECY;
3436 SASLOpts |= SASL_SEC_MUTUAL_AUTH;
3438 # endif /* SASL >= 20101 */
3441 SASLOpts |= SASL_SEC_NOPLAINTEXT;
3445 SASLOpts |= SASL_SEC_NOANONYMOUS;
3448 case ' ': /* ignore */
3449 case '\t': /* ignore */
3450 case ',': /* ignore */
3454 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3455 "Warning: Option: %s unknown parameter '%c'\n",
3463 val = strpbrk(val, ", \t");
3470 MaxSLBits = atoi(val);
3479 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3480 "Warning: Option: %s requires SASL support (-DSASL)\n",
3487 SET_STRING_EXP(SrvCertFile);
3489 SET_STRING_EXP(SrvKeyFile);
3491 SET_STRING_EXP(CltCertFile);
3493 SET_STRING_EXP(CltKeyFile);
3495 SET_STRING_EXP(CACertFile);
3497 SET_STRING_EXP(CACertPath);
3499 SET_STRING_EXP(DHParams);
3502 SET_STRING_EXP(DHParams5);
3504 SET_STRING_EXP(CipherList);
3505 # endif /* _FFR_TLS_1 */
3507 # if OPENSSL_VERSION_NUMBER > 0x00907000L
3508 SET_STRING_EXP(CRLFile);
3509 # else /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3510 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3511 "Warning: Option: %s requires at least OpenSSL 0.9.7\n",
3514 # endif /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3518 # if OPENSSL_VERSION_NUMBER > 0x00907000L
3519 SET_STRING_EXP(CRLPath);
3520 # else /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3521 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3522 "Warning: Option: %s requires at least OpenSSL 0.9.7\n",
3525 # endif /* OPENSSL_VERSION_NUMBER > 0x00907000L */
3526 # endif /* _FFR_CRLPATH */
3529 ** XXX How about options per daemon/client instead of globally?
3530 ** This doesn't work well for some options, e.g., no server cert,
3531 ** but fine for others.
3533 ** XXX Some people may want different certs per server.
3535 ** See also srvfeatures()
3538 case O_TLS_SRV_OPTS:
3539 while (val != NULL && *val != '\0')
3544 TLS_Srv_Opts |= TLS_I_NO_VRFY;
3548 ** Server without a cert? That works only if
3549 ** AnonDH is enabled as cipher, which is not in the
3550 ** default list. Hence the CipherList option must
3551 ** be available. Moreover: which clients support this
3552 ** besides sendmail with this setting?
3556 TLS_Srv_Opts &= ~TLS_I_SRV_CERT;
3558 # endif /* _FFR_TLS_1 */
3559 case ' ': /* ignore */
3560 case '\t': /* ignore */
3561 case ',': /* ignore */
3564 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3565 "Warning: Option: %s unknown parameter '%c'\n",
3573 val = strpbrk(val, ", \t");
3580 PSTRSET(RandFile, val);
3583 #else /* STARTTLS */
3594 # endif /* _FFR_TLS_1 */
3598 # endif /* _FFR_CRLPATH */
3600 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3601 "Warning: Option: %s requires TLS support\n",
3605 #endif /* STARTTLS */
3608 setclientoptions(val);
3612 DataFileBufferSize = atoi(val);
3616 XscriptFileBufferSize = atoi(val);
3619 case O_LDAPDEFAULTSPEC:
3621 ldapmap_set_defaults(val);
3623 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3624 "Warning: Option: %s requires LDAP support (-DLDAPMAP)\n",
3626 #endif /* LDAPMAP */
3631 InputFilterList = newstr(val);
3633 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3634 "Warning: Option: %s requires Milter support (-DMILTER)\n",
3641 milter_set_option(subopt, val, sticky);
3643 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3644 "Warning: Option: %s requires Milter support (-DMILTER)\n",
3649 case O_QUEUE_FILE_MODE: /* queue file mode */
3650 QueueFileMode = atooct(val) & 0777;
3653 case O_DLVR_MIN: /* deliver by minimum time */
3654 DeliverByMin = convtime(val, 's');
3657 /* modifiers {daemon_flags} for direct submissions */
3658 case O_DIRECTSUBMODIFIERS:
3660 BITMAP256 m; /* ignored */
3661 extern ENVELOPE BlankEnvelope;
3663 macdefine(&BlankEnvelope.e_macro, A_PERM,
3664 macid("{daemon_flags}"),
3665 getmodifiers(val, m));
3670 FastSplit = atoi(val);
3678 UseMSP = atobool(val);
3681 #if _FFR_SOFT_BOUNCE
3683 SoftBounce = atobool(val);
3685 #endif /* _FFR_SOFT_BOUNCE */
3687 case O_REJECTLOGINTERVAL: /* time btwn log msgs while refusing */
3688 RejectLogInterval = convtime(val, 'h');
3691 case O_REQUIRES_DIR_FSYNC:
3692 #if REQUIRES_DIR_FSYNC
3693 RequiresDirfsync = atobool(val);
3694 #else /* REQUIRES_DIR_FSYNC */
3695 /* silently ignored... required for cf file option */
3696 #endif /* REQUIRES_DIR_FSYNC */
3699 case O_CONNECTION_RATE_WINDOW_SIZE:
3700 ConnectionRateWindowSize = convtime(val, 's');
3703 case O_FALLBACKSMARTHOST: /* fallback smart host */
3705 FallbackSmartHost = newstr(val);
3710 HeloName = newstr(val);
3712 #endif /* _FFR_HELONAME */
3717 if (isascii(opt) && isprint(opt))
3718 sm_dprintf("Warning: option %c unknown\n", opt);
3720 sm_dprintf("Warning: option 0x%x unknown\n", opt);
3726 ** Options with suboptions are responsible for taking care
3727 ** of sticky-ness (e.g., that a command line setting is kept
3728 ** when reading in the sendmail.cf file). This has to be done
3729 ** when the suboptions are parsed since each suboption must be
3730 ** sticky, not the root option.
3733 if (sticky && !bitset(OI_SUBOPT, o->o_flags))
3734 setbitn(opt, StickyOpt);
3737 ** SETCLASS -- set a string into a class
3740 ** class -- the class to put the string in.
3741 ** str -- the string to enter
3747 ** puts the word into the symbol table.
3751 setclass(class, str)
3757 if ((*str & 0377) == MATCHCLASS)
3767 sm_dprintf("setclass(%s, $=%s)\n",
3768 macname(class), macname(mid));
3769 copy_class(mid, class);
3774 sm_dprintf("setclass(%s, %s)\n", macname(class), str);
3776 s = stab(str, ST_CLASS, ST_ENTER);
3777 setbitn(bitidx(class), s->s_class);
3781 ** MAKEMAPENTRY -- create a map entry
3784 ** line -- the config file line
3787 ** A pointer to the map that has been created.
3788 ** NULL if there was a syntax error.
3791 ** Enters the map into the dictionary.
3804 for (p = line; isascii(*p) && isspace(*p); p++)
3806 if (!(isascii(*p) && isalnum(*p)))
3808 syserr("readcf: config K line: no map name");
3813 while ((isascii(*++p) && isalnum(*p)) || *p == '_' || *p == '.')
3817 while (isascii(*p) && isspace(*p))
3819 if (!(isascii(*p) && isalnum(*p)))
3821 syserr("readcf: config K line, map %s: no map class", mapname);
3825 while (isascii(*++p) && isalnum(*p))
3829 while (isascii(*p) && isspace(*p))
3832 /* look up the class */
3833 class = stab(classname, ST_MAPCLASS, ST_FIND);
3836 syserr("readcf: map %s: class %s not available", mapname,
3842 s = stab(mapname, ST_MAP, ST_ENTER);
3843 s->s_map.map_class = &class->s_mapclass;
3844 s->s_map.map_mname = newstr(mapname);
3846 if (class->s_mapclass.map_parse(&s->s_map, p))
3847 s->s_map.map_mflags |= MF_VALID;
3851 sm_dprintf("map %s, class %s, flags %lx, file %s,\n",
3852 s->s_map.map_mname, s->s_map.map_class->map_cname,
3853 s->s_map.map_mflags, s->s_map.map_file);
3854 sm_dprintf("\tapp %s, domain %s, rebuild %s\n",
3855 s->s_map.map_app, s->s_map.map_domain,
3856 s->s_map.map_rebuild);
3861 ** STRTORWSET -- convert string to rewriting set number
3864 ** p -- the pointer to the string to decode.
3865 ** endp -- if set, store the trailing delimiter here.
3866 ** stabmode -- ST_ENTER to create this entry, ST_FIND if
3867 ** it must already exist.
3870 ** The appropriate ruleset number.
3871 ** -1 if it is not valid (error already printed)
3875 strtorwset(p, endp, stabmode)
3881 static int nextruleset = MAXRWSETS;
3883 while (isascii(*p) && isspace(*p))
3887 syserr("invalid ruleset name: \"%.20s\"", p);
3892 ruleset = strtol(p, endp, 10);
3893 if (ruleset >= MAXRWSETS / 2 || ruleset < 0)
3895 syserr("bad ruleset %d (%d max)",
3896 ruleset, MAXRWSETS / 2);
3907 while (*p != '\0' && isascii(*p) &&
3908 (isalnum(*p) || *p == '_'))
3910 if (q == p || !(isascii(*q) && isalpha(*q)))
3912 /* no valid characters */
3913 syserr("invalid ruleset name: \"%.20s\"", q);
3916 while (isascii(*p) && isspace(*p))
3921 s = stab(q, ST_RULESET, stabmode);
3928 if (stabmode == ST_ENTER && delim == '=')
3930 while (isascii(*++p) && isspace(*p))
3932 if (!(isascii(*p) && isdigit(*p)))
3934 syserr("bad ruleset definition \"%s\" (number required after `=')", q);
3939 ruleset = strtol(p, endp, 10);
3940 if (ruleset >= MAXRWSETS / 2 || ruleset < 0)
3942 syserr("bad ruleset number %d in \"%s\" (%d max)",
3943 ruleset, q, MAXRWSETS / 2);
3952 if (s->s_ruleset >= 0)
3953 ruleset = s->s_ruleset;
3954 else if ((ruleset = --nextruleset) < MAXRWSETS / 2)
3956 syserr("%s: too many named rulesets (%d max)",
3961 if (s->s_ruleset >= 0 &&
3963 ruleset != s->s_ruleset)
3965 syserr("%s: ruleset changed value (old %d, new %d)",
3966 q, s->s_ruleset, ruleset);
3967 ruleset = s->s_ruleset;
3969 else if (ruleset >= 0)
3971 s->s_ruleset = ruleset;
3973 if (stabmode == ST_ENTER && ruleset >= 0)
3977 if (RuleSetNames[ruleset] != NULL)
3978 sm_free(RuleSetNames[ruleset]); /* XXX */
3979 if (delim != '\0' && (h = strchr(q, delim)) != NULL)
3981 RuleSetNames[ruleset] = newstr(q);
3982 if (delim == '/' && h != NULL)
3983 *h = delim; /* put back delim */
3989 ** SETTIMEOUT -- set an individual timeout
3992 ** name -- the name of the timeout.
3993 ** val -- the value of the timeout.
3994 ** sticky -- if set, don't let other setoptions override
4001 /* set if Timeout sub-option is stuck */
4002 static BITMAP256 StickyTimeoutOpt;
4004 static struct timeoutinfo
4006 char *to_name; /* long name of timeout */
4007 unsigned char to_code; /* code for option */
4010 #define TO_INITIAL 0x01
4011 { "initial", TO_INITIAL },
4012 #define TO_MAIL 0x02
4013 { "mail", TO_MAIL },
4014 #define TO_RCPT 0x03
4015 { "rcpt", TO_RCPT },
4016 #define TO_DATAINIT 0x04
4017 { "datainit", TO_DATAINIT },
4018 #define TO_DATABLOCK 0x05
4019 { "datablock", TO_DATABLOCK },
4020 #define TO_DATAFINAL 0x06
4021 { "datafinal", TO_DATAFINAL },
4022 #define TO_COMMAND 0x07
4023 { "command", TO_COMMAND },
4024 #define TO_RSET 0x08
4025 { "rset", TO_RSET },
4026 #define TO_HELO 0x09
4027 { "helo", TO_HELO },
4028 #define TO_QUIT 0x0A
4029 { "quit", TO_QUIT },
4030 #define TO_MISC 0x0B
4031 { "misc", TO_MISC },
4032 #define TO_IDENT 0x0C
4033 { "ident", TO_IDENT },
4034 #define TO_FILEOPEN 0x0D
4035 { "fileopen", TO_FILEOPEN },
4036 #define TO_CONNECT 0x0E
4037 { "connect", TO_CONNECT },
4038 #define TO_ICONNECT 0x0F
4039 { "iconnect", TO_ICONNECT },
4040 #define TO_QUEUEWARN 0x10
4041 { "queuewarn", TO_QUEUEWARN },
4042 { "queuewarn.*", TO_QUEUEWARN },
4043 #define TO_QUEUEWARN_NORMAL 0x11
4044 { "queuewarn.normal", TO_QUEUEWARN_NORMAL },
4045 #define TO_QUEUEWARN_URGENT 0x12
4046 { "queuewarn.urgent", TO_QUEUEWARN_URGENT },
4047 #define TO_QUEUEWARN_NON_URGENT 0x13
4048 { "queuewarn.non-urgent", TO_QUEUEWARN_NON_URGENT },
4049 #define TO_QUEUERETURN 0x14
4050 { "queuereturn", TO_QUEUERETURN },
4051 { "queuereturn.*", TO_QUEUERETURN },
4052 #define TO_QUEUERETURN_NORMAL 0x15
4053 { "queuereturn.normal", TO_QUEUERETURN_NORMAL },
4054 #define TO_QUEUERETURN_URGENT 0x16
4055 { "queuereturn.urgent", TO_QUEUERETURN_URGENT },
4056 #define TO_QUEUERETURN_NON_URGENT 0x17
4057 { "queuereturn.non-urgent", TO_QUEUERETURN_NON_URGENT },
4058 #define TO_HOSTSTATUS 0x18
4059 { "hoststatus", TO_HOSTSTATUS },
4060 #define TO_RESOLVER_RETRANS 0x19
4061 { "resolver.retrans", TO_RESOLVER_RETRANS },
4062 #define TO_RESOLVER_RETRANS_NORMAL 0x1A
4063 { "resolver.retrans.normal", TO_RESOLVER_RETRANS_NORMAL },
4064 #define TO_RESOLVER_RETRANS_FIRST 0x1B
4065 { "resolver.retrans.first", TO_RESOLVER_RETRANS_FIRST },
4066 #define TO_RESOLVER_RETRY 0x1C
4067 { "resolver.retry", TO_RESOLVER_RETRY },
4068 #define TO_RESOLVER_RETRY_NORMAL 0x1D
4069 { "resolver.retry.normal", TO_RESOLVER_RETRY_NORMAL },
4070 #define TO_RESOLVER_RETRY_FIRST 0x1E
4071 { "resolver.retry.first", TO_RESOLVER_RETRY_FIRST },
4072 #define TO_CONTROL 0x1F
4073 { "control", TO_CONTROL },
4074 #define TO_LHLO 0x20
4075 { "lhlo", TO_LHLO },
4076 #define TO_AUTH 0x21
4077 { "auth", TO_AUTH },
4078 #define TO_STARTTLS 0x22
4079 { "starttls", TO_STARTTLS },
4080 #define TO_ACONNECT 0x23
4081 { "aconnect", TO_ACONNECT },
4082 #define TO_QUEUEWARN_DSN 0x24
4083 { "queuewarn.dsn", TO_QUEUEWARN_DSN },
4084 #define TO_QUEUERETURN_DSN 0x25
4085 { "queuereturn.dsn", TO_QUEUERETURN_DSN },
4091 settimeout(name, val, sticky)
4096 register struct timeoutinfo *to;
4101 sm_dprintf("settimeout(%s = %s)", name, val);
4103 for (to = TimeOutTab; to->to_name != NULL; to++)
4105 if (sm_strcasecmp(to->to_name, name) == 0)
4109 if (to->to_name == NULL)
4111 errno = 0; /* avoid bogus error text */
4112 syserr("settimeout: invalid timeout %s", name);
4117 ** See if this option is preset for us.
4120 if (!sticky && bitnset(to->to_code, StickyTimeoutOpt))
4123 sm_dprintf(" (ignored)\n");
4130 toval = convtime(val, 'm');
4133 switch (to->to_code)
4136 TimeOuts.to_initial = toval;
4140 TimeOuts.to_mail = toval;
4144 TimeOuts.to_rcpt = toval;
4148 TimeOuts.to_datainit = toval;
4152 TimeOuts.to_datablock = toval;
4156 TimeOuts.to_datafinal = toval;
4160 TimeOuts.to_nextcommand = toval;
4164 TimeOuts.to_rset = toval;
4168 TimeOuts.to_helo = toval;
4172 TimeOuts.to_quit = toval;
4176 TimeOuts.to_miscshort = toval;
4180 TimeOuts.to_ident = toval;
4184 TimeOuts.to_fileopen = toval;
4188 TimeOuts.to_connect = toval;
4192 TimeOuts.to_iconnect = toval;
4196 TimeOuts.to_aconnect = toval;
4200 toval = convtime(val, 'h');
4201 TimeOuts.to_q_warning[TOC_NORMAL] = toval;
4202 TimeOuts.to_q_warning[TOC_URGENT] = toval;
4203 TimeOuts.to_q_warning[TOC_NONURGENT] = toval;
4204 TimeOuts.to_q_warning[TOC_DSN] = toval;
4208 case TO_QUEUEWARN_NORMAL:
4209 toval = convtime(val, 'h');
4210 TimeOuts.to_q_warning[TOC_NORMAL] = toval;
4213 case TO_QUEUEWARN_URGENT:
4214 toval = convtime(val, 'h');
4215 TimeOuts.to_q_warning[TOC_URGENT] = toval;
4218 case TO_QUEUEWARN_NON_URGENT:
4219 toval = convtime(val, 'h');
4220 TimeOuts.to_q_warning[TOC_NONURGENT] = toval;
4223 case TO_QUEUEWARN_DSN:
4224 toval = convtime(val, 'h');
4225 TimeOuts.to_q_warning[TOC_DSN] = toval;
4228 case TO_QUEUERETURN:
4229 toval = convtime(val, 'd');
4230 TimeOuts.to_q_return[TOC_NORMAL] = toval;
4231 TimeOuts.to_q_return[TOC_URGENT] = toval;
4232 TimeOuts.to_q_return[TOC_NONURGENT] = toval;
4233 TimeOuts.to_q_return[TOC_DSN] = toval;
4237 case TO_QUEUERETURN_NORMAL:
4238 toval = convtime(val, 'd');
4239 TimeOuts.to_q_return[TOC_NORMAL] = toval;
4242 case TO_QUEUERETURN_URGENT:
4243 toval = convtime(val, 'd');
4244 TimeOuts.to_q_return[TOC_URGENT] = toval;
4247 case TO_QUEUERETURN_NON_URGENT:
4248 toval = convtime(val, 'd');
4249 TimeOuts.to_q_return[TOC_NONURGENT] = toval;
4252 case TO_QUEUERETURN_DSN:
4253 toval = convtime(val, 'd');
4254 TimeOuts.to_q_return[TOC_DSN] = toval;
4258 MciInfoTimeout = toval;
4261 case TO_RESOLVER_RETRANS:
4262 toval = convtime(val, 's');
4263 TimeOuts.res_retrans[RES_TO_DEFAULT] = toval;
4264 TimeOuts.res_retrans[RES_TO_FIRST] = toval;
4265 TimeOuts.res_retrans[RES_TO_NORMAL] = toval;
4269 case TO_RESOLVER_RETRY:
4271 TimeOuts.res_retry[RES_TO_DEFAULT] = i;
4272 TimeOuts.res_retry[RES_TO_FIRST] = i;
4273 TimeOuts.res_retry[RES_TO_NORMAL] = i;
4277 case TO_RESOLVER_RETRANS_NORMAL:
4278 TimeOuts.res_retrans[RES_TO_NORMAL] = convtime(val, 's');
4281 case TO_RESOLVER_RETRY_NORMAL:
4282 TimeOuts.res_retry[RES_TO_NORMAL] = atoi(val);
4285 case TO_RESOLVER_RETRANS_FIRST:
4286 TimeOuts.res_retrans[RES_TO_FIRST] = convtime(val, 's');
4289 case TO_RESOLVER_RETRY_FIRST:
4290 TimeOuts.res_retry[RES_TO_FIRST] = atoi(val);
4294 TimeOuts.to_control = toval;
4298 TimeOuts.to_lhlo = toval;
4303 TimeOuts.to_auth = toval;
4309 TimeOuts.to_starttls = toval;
4311 #endif /* STARTTLS */
4314 syserr("settimeout: invalid timeout %s", name);
4320 for (i = 0; i <= addopts; i++)
4321 setbitn(to->to_code + i, StickyTimeoutOpt);
4325 ** INITTIMEOUTS -- parse and set timeout values
4328 ** val -- a pointer to the values. If NULL, do initial
4330 ** sticky -- if set, don't let other setoptions override
4331 ** this suboption value.
4337 ** Initializes the TimeOuts structure
4341 inittimeouts(val, sticky)
4348 sm_dprintf("inittimeouts(%s)\n", val == NULL ? "<NULL>" : val);
4351 TimeOuts.to_connect = (time_t) 0 SECONDS;
4352 TimeOuts.to_aconnect = (time_t) 0 SECONDS;
4353 TimeOuts.to_iconnect = (time_t) 0 SECONDS;
4354 TimeOuts.to_initial = (time_t) 5 MINUTES;
4355 TimeOuts.to_helo = (time_t) 5 MINUTES;
4356 TimeOuts.to_mail = (time_t) 10 MINUTES;
4357 TimeOuts.to_rcpt = (time_t) 1 HOUR;
4358 TimeOuts.to_datainit = (time_t) 5 MINUTES;
4359 TimeOuts.to_datablock = (time_t) 1 HOUR;
4360 TimeOuts.to_datafinal = (time_t) 1 HOUR;
4361 TimeOuts.to_rset = (time_t) 5 MINUTES;
4362 TimeOuts.to_quit = (time_t) 2 MINUTES;
4363 TimeOuts.to_nextcommand = (time_t) 1 HOUR;
4364 TimeOuts.to_miscshort = (time_t) 2 MINUTES;
4366 TimeOuts.to_ident = (time_t) 5 SECONDS;
4367 #else /* IDENTPROTO */
4368 TimeOuts.to_ident = (time_t) 0 SECONDS;
4369 #endif /* IDENTPROTO */
4370 TimeOuts.to_fileopen = (time_t) 60 SECONDS;
4371 TimeOuts.to_control = (time_t) 2 MINUTES;
4372 TimeOuts.to_lhlo = (time_t) 2 MINUTES;
4374 TimeOuts.to_auth = (time_t) 10 MINUTES;
4377 TimeOuts.to_starttls = (time_t) 1 HOUR;
4378 #endif /* STARTTLS */
4381 sm_dprintf("Timeouts:\n");
4382 sm_dprintf(" connect = %ld\n",
4383 (long) TimeOuts.to_connect);
4384 sm_dprintf(" aconnect = %ld\n",
4385 (long) TimeOuts.to_aconnect);
4386 sm_dprintf(" initial = %ld\n",
4387 (long) TimeOuts.to_initial);
4388 sm_dprintf(" helo = %ld\n", (long) TimeOuts.to_helo);
4389 sm_dprintf(" mail = %ld\n", (long) TimeOuts.to_mail);
4390 sm_dprintf(" rcpt = %ld\n", (long) TimeOuts.to_rcpt);
4391 sm_dprintf(" datainit = %ld\n",
4392 (long) TimeOuts.to_datainit);
4393 sm_dprintf(" datablock = %ld\n",
4394 (long) TimeOuts.to_datablock);
4395 sm_dprintf(" datafinal = %ld\n",
4396 (long) TimeOuts.to_datafinal);
4397 sm_dprintf(" rset = %ld\n", (long) TimeOuts.to_rset);
4398 sm_dprintf(" quit = %ld\n", (long) TimeOuts.to_quit);
4399 sm_dprintf(" nextcommand = %ld\n",
4400 (long) TimeOuts.to_nextcommand);
4401 sm_dprintf(" miscshort = %ld\n",
4402 (long) TimeOuts.to_miscshort);
4403 sm_dprintf(" ident = %ld\n", (long) TimeOuts.to_ident);
4404 sm_dprintf(" fileopen = %ld\n",
4405 (long) TimeOuts.to_fileopen);
4406 sm_dprintf(" lhlo = %ld\n",
4407 (long) TimeOuts.to_lhlo);
4408 sm_dprintf(" control = %ld\n",
4409 (long) TimeOuts.to_control);
4416 while (isascii(*val) && isspace(*val))
4420 for (p = val; *p != '\0' && *p != ','; p++)
4425 if (isascii(*val) && isdigit(*val))
4427 /* old syntax -- set everything */
4428 TimeOuts.to_mail = convtime(val, 'm');
4429 TimeOuts.to_rcpt = TimeOuts.to_mail;
4430 TimeOuts.to_datainit = TimeOuts.to_mail;
4431 TimeOuts.to_datablock = TimeOuts.to_mail;
4432 TimeOuts.to_datafinal = TimeOuts.to_mail;
4433 TimeOuts.to_nextcommand = TimeOuts.to_mail;
4436 setbitn(TO_MAIL, StickyTimeoutOpt);
4437 setbitn(TO_RCPT, StickyTimeoutOpt);
4438 setbitn(TO_DATAINIT, StickyTimeoutOpt);
4439 setbitn(TO_DATABLOCK, StickyTimeoutOpt);
4440 setbitn(TO_DATAFINAL, StickyTimeoutOpt);
4441 setbitn(TO_COMMAND, StickyTimeoutOpt);
4447 register char *q = strchr(val, ':');
4449 if (q == NULL && (q = strchr(val, '=')) == NULL)
4455 settimeout(val, q, sticky);