2 * Copyright (c) 1998-2006, 2008-2010, 2013 Proofpoint, 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.692 2013-11-22 20:51:56 ca Exp $")
19 #if NETINET || NETINET6
20 # include <arpa/inet.h>
21 #endif /* NETINET || NETINET6 */
29 static void fileclass __P((int, char *, char *, bool, bool, bool));
30 static char **makeargv __P((char *));
31 static void settimeout __P((char *, char *, bool));
32 static void toomany __P((int, int));
33 static char *extrquotstr __P((char *, char **, char *, bool *));
34 static void parse_class_words __P((int, char *));
38 static char *bouncequeue = NULL;
39 static void initbouncequeue __P((void));
42 ** INITBOUNCEQUEUE -- determine BounceQueue if option is set.
60 if (bouncequeue == NULL || bouncequeue[0] == '\0')
63 s = stab(bouncequeue, ST_QUEUE, ST_FIND);
66 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
67 "Warning: option BounceQueue: unknown queue group %s\n",
71 BounceQueue = s->s_quegrp->qg_index;
73 #endif /* _FFR_BOUNCE_QUEUE */
76 void setupdynmailers __P((void));
78 #define setupdynmailers()
82 ** READCF -- read configuration file.
84 ** This routine reads the configuration file and builds the internal
87 ** The file is formatted as a sequence of lines, each taken
88 ** atomically. The first character of each line describes how
89 ** the line is to be interpreted. The lines are:
90 ** Dxval Define macro x to have value val.
91 ** Cxword Put word into class x.
92 ** Fxfile [fmt] Read file for lines to put into
93 ** class x. Use scanf string 'fmt'
94 ** or "%s" if not present. Fmt should
95 ** only produce one string-valued result.
96 ** Hname: value Define header with field-name 'name'
97 ** and value as specified; this will be
98 ** macro expanded immediately before
100 ** Sn Use rewriting set n.
101 ** Rlhs rhs Rewrite addresses that match lhs to
103 ** Mn arg=val... Define mailer. n is the internal name.
104 ** Args specify mailer parameters.
105 ** Oxvalue Set option x to value.
106 ** O option value Set option (long name) to value.
107 ** Pname=value Set precedence name to value.
108 ** Qn arg=val... Define queue groups. n is the internal name.
109 ** Args specify queue parameters.
110 ** Vversioncode[/vendorcode]
111 ** Version level/vendor name of
112 ** configuration syntax.
113 ** Kmapname mapclass arguments....
114 ** Define keyed lookup of a given class.
115 ** Arguments are class dependent.
116 ** Eenvar=value Set the environment value to the given value.
119 ** cfname -- configuration file name.
120 ** safe -- true if this is the system config file;
122 ** e -- the main envelope.
128 ** Builds several internal tables.
132 readcf(cfname, safe, e)
135 register ENVELOPE *e;
140 struct rewrite *rwp = NULL;
150 long sff = SFF_OPENASROOT;
155 char pvpbuf[MAXLINE + MAXATOM];
156 static char *null_list[1] = { NULL };
157 extern unsigned char TokTypeNoC[];
162 if (DontLockReadFiles)
164 cf = safefopen(cfname, O_RDONLY, 0444, sff);
167 syserr("cannot open");
168 finis(false, true, EX_OSFILE);
171 if (fstat(sm_io_getinfo(cf, SM_IO_WHAT_FD, NULL), &statb) < 0)
173 syserr("cannot fstat");
174 finis(false, true, EX_OSFILE);
177 if (!S_ISREG(statb.st_mode))
179 syserr("not a plain file");
180 finis(false, true, EX_OSFILE);
183 if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
185 if (OpMode == MD_DAEMON || OpMode == MD_INITALIAS || OpMode == MD_CHECKCONFIG)
186 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
187 "%s: WARNING: dangerous write permissions\n",
190 sm_syslog(LOG_CRIT, NOQID,
191 "%s: WARNING: dangerous write permissions",
199 while (bufsize = sizeof(buf),
200 (bp = fgetfolded(buf, &bufsize, cf)) != NULL)
207 sm_free(bp); /* XXX */
211 /* do macro expansion mappings */
212 nbp = translate_dollars(bp, bp, &bufsize);
213 if (nbp != bp && bp != buf)
217 /* interpret this line */
222 case '#': /* comment */
225 case 'R': /* rewriting rule */
228 syserr("missing valid ruleset for \"%s\"", bp);
231 for (p = &bp[1]; *p != '\0' && *p != '\t'; p++)
236 syserr("invalid rewrite line \"%s\" (tab expected)", bp);
240 /* allocate space for the rule header */
243 RewriteRules[ruleset] = rwp =
244 (struct rewrite *) xalloc(sizeof(*rwp));
248 rwp->r_next = (struct rewrite *) xalloc(sizeof(*rwp));
253 /* expand and save the LHS */
255 expand(&bp[1], exbuf, sizeof(exbuf), e);
256 rwp->r_lhs = prescan(exbuf, '\t', pvpbuf,
257 sizeof(pvpbuf), NULL,
258 ConfigLevel >= 9 ? TokTypeNoC : IntTokenTab,
261 if (rwp->r_lhs != NULL)
265 rwp->r_lhs = copyplist(rwp->r_lhs, true, NULL);
267 /* count the number of fuzzy matches in LHS */
268 for (ap = rwp->r_lhs; *ap != NULL; ap++)
273 switch (ap[0][0] & 0377)
320 syserr("Inappropriate use of %s on LHS",
323 rwp->r_line = LineNumber;
327 syserr("R line: null LHS");
328 rwp->r_lhs = null_list;
330 if (nfuzzy > MAXMATCH)
332 syserr("R line: too many wildcards");
333 rwp->r_lhs = null_list;
336 /* expand and save the RHS */
340 while (*p != '\0' && *p != '\t')
343 expand(q, exbuf, sizeof(exbuf), e);
344 rwp->r_rhs = prescan(exbuf, '\t', pvpbuf,
345 sizeof(pvpbuf), NULL,
346 ConfigLevel >= 9 ? TokTypeNoC : IntTokenTab,
348 if (rwp->r_rhs != NULL)
352 #if _FFR_EXTRA_MAP_CHECK
354 #endif /* _FFR_EXTRA_MAP_CHECK */
357 rwp->r_rhs = copyplist(rwp->r_rhs, true, NULL);
359 /* check no out-of-bounds replacements */
364 for (ap = rwp->r_rhs; *ap != NULL; ap++)
369 switch (ap[0][0] & 0377)
372 if (ap[0][1] <= '0' ||
375 syserr("replacement $%c out of bounds",
403 if (++args >= MAX_MAP_ARGS)
404 syserr("too many arguments for map lookup");
412 if ((ap[0][0] & 0377) == LOOKUPBEGIN)
413 endtoken = LOOKUPEND;
415 syserr("cannot nest map lookups");
418 #if _FFR_EXTRA_MAP_CHECK
421 syserr("syntax error in map lookup");
424 nexttoken = ap[1][0] & 0377;
425 if (nexttoken == CANONHOST ||
426 nexttoken == CANONUSER ||
427 nexttoken == endtoken))
429 syserr("missing map name for lookup");
434 syserr("syntax error in map lookup");
437 if (ap[0][0] == HOSTBEGIN)
439 nexttoken = ap[2][0] & 0377;
440 if (nexttoken == CANONHOST ||
441 nexttoken == CANONUSER ||
442 nexttoken == endtoken)
444 syserr("missing key name for lookup");
447 #endif /* _FFR_EXTRA_MAP_CHECK */
452 if ((ap[0][0] & 0377) != endtoken)
461 ** This doesn't work yet as there are maps defined *after* the cf
462 ** is read such as host, user, and alias. So for now, it's removed.
463 ** When it comes back, the RELEASE_NOTES entry will be:
464 ** Emit warnings for unknown maps when reading the .cf file. Based on
465 ** patch from Robert Harker of Harker Systems.
470 ** Got a database lookup,
471 ** check if map is defined.
475 if ((ep[0] & 0377) != MACRODEXPAND &&
476 stab(ep, ST_MAP, ST_FIND) == NULL)
478 (void) sm_io_fprintf(smioout,
480 "Warning: %s: line %d: map %s not found\n",
489 syserr("Inappropriate use of %s on RHS",
493 syserr("missing map closing token");
497 syserr("R line: null RHS");
498 rwp->r_rhs = null_list;
502 case 'S': /* select rewriting set */
503 expand(&bp[1], exbuf, sizeof(exbuf), e);
504 ruleset = strtorwset(exbuf, NULL, ST_ENTER);
508 rwp = RewriteRules[ruleset];
511 if (OpMode == MD_TEST || OpMode == MD_CHECKCONFIG)
512 (void) sm_io_fprintf(smioout,
514 "WARNING: Ruleset %s has multiple definitions\n",
517 sm_dprintf("WARNING: Ruleset %s has multiple definitions\n",
519 while (rwp->r_next != NULL)
524 case 'D': /* macro definition */
525 mid = macid_parse(&bp[1], &ep);
528 p = munchstring(ep, NULL, '\0');
529 macdefine(&e->e_macro, A_TEMP, mid, p);
532 case 'H': /* required header line */
533 (void) chompheader(&bp[1], CHHDR_DEF, NULL, e);
536 case 'C': /* word class */
537 case 'T': /* trusted user (set class `t') */
540 mid = macid_parse(&bp[1], &ep);
543 expand(ep, exbuf, sizeof(exbuf), e);
556 while (*p != '\0' && isascii(*p) && isspace(*p))
559 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
569 case 'F': /* word class from file */
570 mid = macid_parse(&bp[1], &ep);
573 for (p = ep; isascii(*p) && isspace(*p); )
575 if (p[0] == '-' && p[1] == 'o')
579 !(isascii(*p) && isspace(*p)))
581 while (isascii(*p) && isspace(*p))
587 /* check if [key]@map:spec */
589 if (!SM_IS_DIR_DELIM(*p) &&
591 (q = strchr(p, '@')) != NULL)
595 /* look for @LDAP or @map: in string */
596 if (strcmp(q, "LDAP") == 0 ||
598 strchr(q, ':') != NULL))
604 /* use entire spec */
609 file = extrquotstr(p, &q, " ", &ok);
612 syserr("illegal filename '%s'", p);
617 if (*file == '|' || ismap)
627 while (isascii(*++p) && isspace(*p))
631 fileclass(mid, file, p, ismap, safe, optional);
635 case 'L': /* extended load average description */
640 #if defined(SUN_EXTENSIONS) && defined(SUN_LOOKUP_MACRO)
641 case 'L': /* lookup macro */
642 case 'G': /* lookup class */
643 /* reserved for Sun -- NIS+ database lookup */
644 if (VendorCode != VENDOR_SUN)
646 sun_lg_config_line(bp, e);
648 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_LOOKUP_MACRO) */
650 case 'M': /* define mailer */
654 case 'O': /* set option */
655 setoption(bp[1], &bp[2], safe, false, e);
658 case 'P': /* set precedence */
659 if (NumPriorities >= MAXPRIORITIES)
661 toomany('P', MAXPRIORITIES);
664 for (p = &bp[1]; *p != '\0' && *p != '='; p++)
669 Priorities[NumPriorities].pri_name = newstr(&bp[1]);
670 Priorities[NumPriorities].pri_val = atoi(++p);
674 case 'Q': /* define queue */
675 makequeue(&bp[1], true);
678 case 'V': /* configuration syntax version */
679 for (p = &bp[1]; isascii(*p) && isspace(*p); p++)
681 if (!isascii(*p) || !isdigit(*p))
683 syserr("invalid argument to V line: \"%.20s\"",
687 ConfigLevel = strtol(p, &ep, 10);
690 ** Do heuristic tweaking for back compatibility.
693 if (ConfigLevel >= 5)
695 /* level 5 configs have short name in $w */
696 p = macvalue('w', e);
697 if (p != NULL && (p = strchr(p, '.')) != NULL)
700 macdefine(&e->e_macro, A_TEMP, 'w',
704 if (ConfigLevel >= 6)
706 ColonOkInAddr = false;
710 ** Look for vendor code.
715 /* extract vendor code */
716 for (p = ep; isascii(*p) && isalpha(*p); )
721 syserr("invalid V line vendor code: \"%s\"",
727 expand(&bp[1], exbuf, sizeof(exbuf), e);
728 (void) makemapentry(exbuf);
735 sm_setuserenv(&bp[1], p);
738 case 'X': /* mail filter */
740 milter_setup(&bp[1]);
742 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
743 "Warning: Filter usage ('X') requires Milter support (-DMILTER)\n");
749 syserr("unknown configuration line \"%s\"", bp);
752 sm_free(bp); /* XXX */
756 syserr("I/O read error");
757 finis(false, true, EX_OSFILE);
759 (void) sm_io_close(cf, SM_TIME_DEFAULT);
762 #if _FFR_BOUNCE_QUEUE
766 /* initialize host maps from local service tables */
769 /* initialize daemon (if not defined yet) */
772 /* determine if we need to do special name-server frotz */
775 char *maptype[MAXMAPSTACK];
776 short mapreturn[MAXMAPACTIONS];
778 nmaps = switch_map_find("hosts", maptype, mapreturn);
779 UseNameServer = false;
780 if (nmaps > 0 && nmaps <= MAXMAPSTACK)
784 for (mapno = 0; mapno < nmaps && !UseNameServer;
787 if (strcmp(maptype[mapno], "dns") == 0)
788 UseNameServer = true;
796 ** TRANSLATE_DOLLARS -- convert $x into internal form
798 ** Actually does all appropriate pre-processing of a config line
799 ** to turn it into internal form.
802 ** ibp -- the buffer to translate.
803 ** obp -- where to put the translation; may be the same as obp
804 ** bsp -- a pointer to the size of obp; will be updated if
805 ** the buffer needs to be replaced.
808 ** The buffer pointer; may differ from obp if the expansion
809 ** is larger then *bsp, in which case this will point to
810 ** malloc()ed memory which must be free()d by the caller.
814 translate_dollars(ibp, obp, bsp)
825 sm_dprintf("translate_dollars(");
826 xputs(sm_debug_file(), ibp);
830 bp = quote_internal_chars(ibp, obp, bsp);
832 for (p = bp; *p != '\0'; p++)
834 if (*p == '#' && p > bp && ConfigLevel >= 3)
841 /* it's from $# -- let it go through */
846 /* it's backslash escaped */
847 (void) sm_strlcpy(p, p + 1, strlen(p));
851 /* delete leading white space */
852 while (isascii(*p) && isspace(*p) &&
853 *p != '\n' && p > bp)
857 if ((e = strchr(++p, '\n')) != NULL)
858 (void) sm_strlcpy(p, e, strlen(p));
866 if (*p != '$' || p[1] == '\0')
871 /* actual dollar sign.... */
872 (void) sm_strlcpy(p, p + 1, strlen(p));
876 /* convert to macro expansion character */
879 /* special handling for $=, $~, $&, and $? */
880 if (*p == '=' || *p == '~' || *p == '&' || *p == '?')
883 /* convert macro name to code */
884 *p = macid_parse(p, &ep);
886 (void) sm_strlcpy(p + 1, ep, strlen(p + 1));
889 /* strip trailing white space from the line */
890 while (--p > bp && isascii(*p) && isspace(*p))
895 sm_dprintf(" translate_dollars => ");
896 xputs(sm_debug_file(), bp);
903 ** TOOMANY -- signal too many of some option
906 ** id -- the id of the error line
907 ** maxcnt -- the maximum possible values
921 syserr("too many %c lines, %d max", id, maxcnt);
924 ** FILECLASS -- read members of a class from a file
927 ** class -- class to define.
928 ** filename -- name of file to read.
929 ** fmt -- scanf string to use for match.
930 ** ismap -- if set, this is a map lookup.
931 ** safe -- if set, this is a safe read.
932 ** optional -- if set, it is not an error for the file to
939 ** puts all lines in filename that match a scanf into
944 ** Break up the match into words and add to class.
948 parse_class_words(class, line)
952 while (line != NULL && *line != '\0')
956 /* strip leading spaces */
957 while (isascii(*line) && isspace(*line))
962 /* find the end of the word */
964 while (*line != '\0' && !(isascii(*line) && isspace(*line)))
969 /* enter the word in the symbol table */
975 fileclass(class, filename, fmt, ismap, safe, optional)
990 sm_dprintf("fileclass(%s, fmt=%s)\n", filename, fmt);
992 if (*filename == '\0')
994 syserr("fileclass: missing file name");
1006 mn = newstr(macname(class));
1011 if ((p = strchr(filename, '@')) == NULL)
1013 /* should not happen */
1014 syserr("fileclass: bogus map specification");
1024 if (strcmp(cl, "LDAP") == 0)
1028 char jbuf[MAXHOSTNAMELEN];
1029 char lcbuf[MAXLINE];
1032 expand("\201j", jbuf, sizeof(jbuf), &BlankEnvelope);
1033 if (jbuf[0] == '\0')
1035 (void) sm_strlcpy(jbuf, "localhost",
1039 /* impose the default schema */
1040 lc = macvalue(macid("{sendmailMTACluster}"), CurEnv);
1045 expand(lc, lcbuf, sizeof(lcbuf), CurEnv);
1050 n = sm_snprintf(buf, sizeof(buf),
1051 "-k (&(objectClass=sendmailMTAClass)(sendmailMTAClassName=%s)(|(sendmailMTACluster=%s)(sendmailMTAHost=%s))) -v sendmailMTAClassValue,sendmailMTAClassSearch:FILTER:sendmailMTAClass,sendmailMTAClassURL:URL:sendmailMTAClass",
1053 if (n >= sizeof(buf))
1055 syserr("fileclass: F{%s}: Default LDAP string too long",
1063 #endif /* LDAPMAP */
1065 if ((spec = strchr(cl, ':')) == NULL)
1067 syserr("fileclass: F{%s}: missing map class",
1075 /* set up map structure */
1076 mapclass = stab(cl, ST_MAPCLASS, ST_FIND);
1077 if (mapclass == NULL)
1079 syserr("fileclass: F{%s}: class %s not available",
1084 memset(&map, '\0', sizeof(map));
1085 map.map_class = &mapclass->s_mapclass;
1087 map.map_mflags |= MF_FILECLASS;
1090 sm_dprintf("fileclass: F{%s}: map class %s, key %s, spec %s\n",
1094 /* parse map spec */
1095 if (!map.map_class->map_parse(&map, spec))
1097 /* map_parse() showed the error already */
1101 map.map_mflags |= MF_VALID;
1104 if (map.map_class->map_open(&map, O_RDONLY))
1106 map.map_mflags |= MF_OPEN;
1107 map.map_pid = getpid();
1112 !bitset(MF_OPTIONAL, map.map_mflags))
1113 syserr("fileclass: F{%s}: map open failed",
1120 p = (*map.map_class->map_lookup)(&map, key, NULL, &status);
1121 if (status != EX_OK && status != EX_NOTFOUND)
1124 syserr("fileclass: F{%s}: map lookup failed",
1129 /* use the results */
1131 parse_class_words(class, p);
1134 map.map_mflags |= MF_CLOSING;
1135 map.map_class->map_close(&map);
1136 map.map_mflags &= ~(MF_OPEN|MF_WRITABLE|MF_CLOSING);
1140 else if (filename[0] == '|')
1144 char *argv[MAXPV + 1];
1147 for (p = strtok(&filename[1], " \t");
1148 p != NULL && i < MAXPV;
1149 p = strtok(NULL, " \t"))
1152 pid = prog_open(argv, &fd, CurEnv);
1156 f = sm_io_open(SmFtStdiofd, SM_TIME_DEFAULT,
1157 (void *) &fd, SM_IO_RDONLY, NULL);
1163 if (!bitnset(DBS_CLASSFILEINUNSAFEDIRPATH, DontBlameSendmail))
1164 sff |= SFF_SAFEDIRPATH;
1165 if (!bitnset(DBS_LINKEDCLASSFILEINWRITABLEDIR,
1169 sff |= SFF_OPENASROOT;
1170 else if (RealUid == 0)
1172 if (DontLockReadFiles)
1174 f = safefopen(filename, O_RDONLY, 0, sff);
1179 syserr("fileclass: cannot open '%s'", filename);
1183 while (sm_io_fgets(f, SM_TIME_DEFAULT, buf, sizeof(buf)) >= 0)
1186 char wordbuf[MAXLINE + 1];
1192 if (sm_io_sscanf(buf, fmt, wordbuf) != 1)
1199 parse_class_words(class, p);
1202 ** If anything else is added here,
1203 ** check if the '@' map case above
1204 ** needs the code as well.
1208 (void) sm_io_close(f, SM_TIME_DEFAULT);
1210 (void) waitfor(pid);
1214 /* first character for dynamically created mailers */
1215 static char dynmailerp = ' ';
1217 /* list of first characters for cf defined mailers */
1218 static char frst[MAXMAILERS + 1];
1221 ** SETUPDYNMAILERS -- find a char that isn't used as first element of any
1230 ** Note: space is not valid in cf defined mailers hence the function
1231 ** will always find a char. It's not nice, but this is for
1232 ** internal names only.
1239 char pp[] = "YXZ0123456789ABCDEFGHIJKLMNOPQRSTUVWyxzabcfghijkmnoqtuvw ";
1241 frst[MAXMAILERS] = '\0';
1242 for (i = 0; i < strlen(pp); i++)
1244 if (strchr(frst, pp[i]) == NULL)
1248 sm_dprintf("dynmailerp=%c\n", dynmailerp);
1258 ** NEWMODMAILER -- Create a new mailer with modifications
1261 ** rcpt -- current RCPT
1262 ** fl -- flag to set
1265 ** true iff successful.
1267 ** Note: this creates a copy of the mailer for the rcpt and
1268 ** modifies exactly one flag. It does not work
1269 ** for multiple flags!
1273 newmodmailer(rcpt, fl)
1282 SM_REQUIRE(rcpt != NULL);
1283 if (rcpt->q_mailer == NULL)
1286 sm_dprintf("newmodmailer: rcpt=%s\n", rcpt->q_paddr);
1287 SM_REQUIRE(rcpt->q_mailer->m_name != NULL);
1288 SM_REQUIRE(rcpt->q_mailer->m_name[0] != '\0');
1289 sm_strlcpy(mname, rcpt->q_mailer->m_name, sizeof(mname));
1290 mname[0] = dynmailerp;
1292 sm_dprintf("newmodmailer: name=%s\n", mname);
1293 s = stab(mname, ST_MAILER, ST_ENTER);
1294 if (s->s_mailer != NULL)
1296 idx = s->s_mailer->m_mno;
1298 sm_dprintf("newmodmailer: found idx=%d\n", idx);
1302 idx = rcpt->q_mailer->m_mno;
1305 sm_dprintf("newmodmailer: idx=%d\n", idx);
1306 if (idx > SM_ARRAY_SIZE(Mailer))
1312 m = (struct mailer *) xalloc(sizeof(*m));
1313 memset((char *) m, '\0', sizeof(*m));
1314 STRUCTCOPY(*rcpt->q_mailer, *m);
1317 /* "modify" the mailer */
1318 setbitn(bitidx(fl), m->m_flags);
1321 m->m_name = newstr(mname);
1323 sm_dprintf("newmodmailer: mailer[%d]=%s %p\n",
1324 idx, Mailer[idx]->m_name, Mailer[idx]);
1329 #endif /* _FFR_RCPTFLAGS */
1332 ** MAKEMAILER -- define a new mailer.
1335 ** line -- description of mailer. This is in labeled
1336 ** fields. The fields are:
1337 ** A -- the argv for this mailer
1338 ** C -- the character set for MIME conversions
1339 ** D -- the directory to run in
1340 ** E -- the eol string
1341 ** F -- the flags associated with the mailer
1342 ** L -- the maximum line length
1343 ** M -- the maximum message size
1344 ** N -- the niceness at which to run
1345 ** P -- the path to the mailer
1346 ** Q -- the queue group for the mailer
1347 ** R -- the recipient rewriting set
1348 ** S -- the sender rewriting set
1349 ** T -- the mailer type (for DSNs)
1350 ** U -- the uid to run as
1351 ** W -- the time to wait at the end
1352 ** m -- maximum messages per connection
1353 ** r -- maximum number of recipients per message
1354 ** / -- new root directory
1355 ** The first word is the canonical name of the mailer.
1361 ** enters the mailer into the mailer table.
1370 register struct mailer *m;
1375 static int nextmailer = 0; /* "free" index into Mailer struct */
1377 /* allocate a mailer and set up defaults */
1378 m = (struct mailer *) xalloc(sizeof(*m));
1379 memset((char *) m, '\0', sizeof(*m));
1380 errno = 0; /* avoid bogus error text */
1382 /* collect the mailer name */
1384 *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p));
1389 if (line[0] == '\0')
1391 syserr("name required for mailer");
1394 m->m_name = newstr(line);
1396 frst[nextmailer] = line[0];
1402 /* now scan through and assign info from the fields */
1405 auto char *delimptr;
1407 while (*p != '\0' &&
1408 (*p == ',' || (isascii(*p) && isspace(*p))))
1411 /* p now points to field code */
1413 while (*p != '\0' && *p != '=' && *p != ',')
1417 syserr("mailer %s: `=' expected", m->m_name);
1420 while (isascii(*p) && isspace(*p))
1423 /* p now points to the field body */
1424 p = munchstring(p, &delimptr, ',');
1426 /* install the field into the mailer struct */
1429 case 'P': /* pathname */
1430 if (*p != '\0') /* error is issued below */
1431 m->m_mailer = newstr(p);
1434 case 'F': /* flags */
1435 for (; *p != '\0'; p++)
1437 if (!(isascii(*p) && isspace(*p)))
1439 if (*p == M_INTERNAL)
1440 sm_syslog(LOG_WARNING, NOQID,
1441 "WARNING: mailer=%s, flag=%c deprecated",
1443 setbitn(bitidx(*p), m->m_flags);
1448 case 'S': /* sender rewriting ruleset */
1449 case 'R': /* recipient rewriting ruleset */
1450 i = strtorwset(p, &endp, ST_ENTER);
1454 m->m_sh_rwset = m->m_se_rwset = i;
1456 m->m_rh_rwset = m->m_re_rwset = i;
1461 i = strtorwset(p, NULL, ST_ENTER);
1471 case 'E': /* end of line string */
1473 syserr("mailer %s: null end-of-line string",
1476 m->m_eol = newstr(p);
1479 case 'A': /* argument vector */
1480 if (*p != '\0') /* error is issued below */
1481 m->m_argv = makeargv(p);
1484 case 'M': /* maximum message size */
1485 m->m_maxsize = atol(p);
1488 case 'm': /* maximum messages per connection */
1489 m->m_maxdeliveries = atoi(p);
1492 case 'r': /* max recipient per envelope */
1493 m->m_maxrcpt = atoi(p);
1496 case 'L': /* maximum line length */
1497 m->m_linelimit = atoi(p);
1498 if (m->m_linelimit < 0)
1502 case 'N': /* run niceness */
1503 m->m_nice = atoi(p);
1506 case 'D': /* working directory */
1508 syserr("mailer %s: null working directory",
1511 m->m_execdir = newstr(p);
1514 case 'C': /* default charset */
1516 syserr("mailer %s: null charset", m->m_name);
1518 m->m_defcharset = newstr(p);
1521 case 'Q': /* queue for this mailer */
1524 syserr("mailer %s: null queue", m->m_name);
1527 s = stab(p, ST_QUEUE, ST_FIND);
1529 syserr("mailer %s: unknown queue %s",
1532 m->m_qgrp = s->s_quegrp->qg_index;
1535 case 'T': /* MTA-Name/Address/Diagnostic types */
1536 /* extract MTA name type; default to "dns" */
1537 m->m_mtatype = newstr(p);
1538 p = strchr(m->m_mtatype, '/');
1545 if (*m->m_mtatype == '\0')
1546 m->m_mtatype = "dns";
1548 /* extract address type; default to "rfc822" */
1558 if (m->m_addrtype == NULL || *m->m_addrtype == '\0')
1559 m->m_addrtype = "rfc822";
1561 /* extract diagnostic type; default to "smtp" */
1563 if (m->m_diagtype == NULL || *m->m_diagtype == '\0')
1564 m->m_diagtype = "smtp";
1567 case 'U': /* user id */
1568 if (isascii(*p) && !isdigit(*p))
1573 while (*p != '\0' && isascii(*p) &&
1574 # if _FFR_DOTTED_USERNAMES
1575 (isalnum(*p) || strchr(SM_PWN_CHARS, *p) != NULL))
1576 # else /* _FFR_DOTTED_USERNAMES */
1577 (isalnum(*p) || strchr("-_", *p) != NULL))
1578 # endif /* _FFR_DOTTED_USERNAMES */
1580 while (isascii(*p) && isspace(*p))
1586 syserr("mailer %s: null user name",
1590 pw = sm_getpwnam(q);
1593 syserr("readcf: mailer U= flag: unknown user %s", q);
1598 m->m_uid = pw->pw_uid;
1599 m->m_gid = pw->pw_gid;
1606 m->m_uid = strtol(p, &q, 0);
1608 while (isascii(*p) && isspace(*p))
1613 while (isascii(*p) && isspace(*p))
1617 if (isascii(*p) && !isdigit(*p))
1622 while (isascii(*p) &&
1623 (isalnum(*p) || strchr(SM_PWN_CHARS, *p) != NULL))
1628 syserr("mailer %s: null group name",
1635 syserr("readcf: mailer U= flag: unknown group %s", q);
1639 m->m_gid = gr->gr_gid;
1643 m->m_gid = strtol(p, NULL, 0);
1647 case 'W': /* wait timeout */
1648 m->m_wait = convtime(p, 's');
1651 case '/': /* new root directory */
1653 syserr("mailer %s: null root directory",
1656 m->m_rootdir = newstr(p);
1660 syserr("M%s: unknown mailer equate %c=",
1669 if (bitnset(M_SECURE_PORT, m->m_flags))
1671 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1672 "M%s: Warning: F=%c set on system that doesn't support rresvport()\n",
1673 m->m_name, M_SECURE_PORT);
1675 #endif /* !HASRRESVPORT */
1680 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1681 "M%s: Warning: N= set on system that doesn't support nice()\n",
1684 #endif /* !HASNICE */
1686 /* do some rationality checking */
1687 if (m->m_argv == NULL)
1689 syserr("M%s: A= argument required", m->m_name);
1692 if (m->m_mailer == NULL)
1694 syserr("M%s: P= argument required", m->m_name);
1698 if (nextmailer >= MAXMAILERS)
1700 syserr("too many mailers defined (%d max)", MAXMAILERS);
1704 if (m->m_maxrcpt <= 0)
1705 m->m_maxrcpt = DEFAULT_MAX_RCPT;
1707 /* do some heuristic cleanup for back compatibility */
1708 if (bitnset(M_LIMITS, m->m_flags))
1710 if (m->m_linelimit == 0)
1711 m->m_linelimit = SMTPLINELIM;
1712 if (ConfigLevel < 2)
1713 setbitn(M_7BITS, m->m_flags);
1716 if (strcmp(m->m_mailer, "[TCP]") == 0)
1718 syserr("M%s: P=[TCP] must be replaced by P=[IPC]", m->m_name);
1722 if (strcmp(m->m_mailer, "[IPC]") == 0)
1724 /* Use the second argument for host or path to socket */
1725 if (m->m_argv[0] == NULL || m->m_argv[1] == NULL ||
1726 m->m_argv[1][0] == '\0')
1728 syserr("M%s: too few parameters for %s mailer",
1729 m->m_name, m->m_mailer);
1732 if (strcmp(m->m_argv[0], "TCP") != 0
1734 && strcmp(m->m_argv[0], "FILE") != 0
1735 #endif /* NETUNIX */
1738 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1739 "M%s: Warning: first argument in %s mailer must be %s\n",
1740 m->m_name, m->m_mailer,
1745 #endif /* NETUNIX */
1748 if (m->m_mtatype == NULL)
1749 m->m_mtatype = "dns";
1750 if (m->m_addrtype == NULL)
1751 m->m_addrtype = "rfc822";
1752 if (m->m_diagtype == NULL)
1754 if (m->m_argv[0] != NULL &&
1755 strcmp(m->m_argv[0], "FILE") == 0)
1756 m->m_diagtype = "x-unix";
1758 m->m_diagtype = "smtp";
1761 else if (strcmp(m->m_mailer, "[FILE]") == 0)
1763 /* Use the second argument for filename */
1764 if (m->m_argv[0] == NULL || m->m_argv[1] == NULL ||
1765 m->m_argv[2] != NULL)
1767 syserr("M%s: too %s parameters for [FILE] mailer",
1769 (m->m_argv[0] == NULL ||
1770 m->m_argv[1] == NULL) ? "few" : "many");
1773 else if (strcmp(m->m_argv[0], "FILE") != 0)
1775 syserr("M%s: first argument in [FILE] mailer must be FILE",
1781 if (m->m_eol == NULL)
1785 /* default for SMTP is \r\n; use \n for local delivery */
1786 for (pp = m->m_argv; *pp != NULL; pp++)
1788 for (p = *pp; *p != '\0'; )
1790 if ((*p++ & 0377) == MACROEXPAND && *p == 'u')
1802 /* enter the mailer into the symbol table */
1803 s = stab(m->m_name, ST_MAILER, ST_ENTER);
1804 if (s->s_mailer != NULL)
1806 i = s->s_mailer->m_mno;
1807 sm_free(s->s_mailer); /* XXX */
1813 Mailer[i] = s->s_mailer = m;
1817 ** MUNCHSTRING -- translate a string into internal form.
1820 ** p -- the string to munch.
1821 ** delimptr -- if non-NULL, set to the pointer of the
1822 ** field delimiter character.
1823 ** delim -- the delimiter for the field.
1826 ** the munched string.
1829 ** the munched string is a local static buffer.
1830 ** it must be copied before the function is called again.
1834 munchstring(p, delimptr, delim)
1840 bool backslash = false;
1841 bool quotemode = false;
1842 static char buf[MAXLINE];
1844 for (q = buf; *p != '\0' && q < &buf[sizeof(buf) - 1]; p++)
1848 /* everything is roughly literal */
1852 case 'r': /* carriage return */
1856 case 'n': /* newline */
1860 case 'f': /* form feed */
1864 case 'b': /* backspace */
1875 quotemode = !quotemode;
1876 else if (quotemode || *p != delim)
1883 if (delimptr != NULL)
1889 ** EXTRQUOTSTR -- extract a (quoted) string.
1891 ** This routine deals with quoted (") strings and escaped
1895 ** p -- source string.
1896 ** delimptr -- if non-NULL, set to the pointer of the
1897 ** field delimiter character.
1898 ** delimbuf -- delimiters for the field.
1899 ** st -- if non-NULL, store the return value (whether the
1900 ** string was correctly quoted) here.
1903 ** the extracted string.
1906 ** the returned string is a local static buffer.
1907 ** it must be copied before the function is called again.
1911 extrquotstr(p, delimptr, delimbuf, st)
1918 bool backslash = false;
1919 bool quotemode = false;
1920 static char buf[MAXLINE];
1922 for (q = buf; *p != '\0' && q < &buf[sizeof(buf) - 1]; p++)
1933 quotemode = !quotemode;
1934 else if (quotemode ||
1935 strchr(delimbuf, (int) *p) == NULL)
1941 if (delimptr != NULL)
1945 *st = !(quotemode || backslash);
1949 ** MAKEARGV -- break up a string into words
1952 ** p -- the string to break up.
1955 ** a char **argv (dynamically allocated)
1968 char *argv[MAXPV + 1];
1970 /* take apart the words */
1972 while (*p != '\0' && i < MAXPV)
1975 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
1977 while (isascii(*p) && isspace(*p))
1979 argv[i++] = newstr(q);
1983 /* now make a copy of the argv */
1984 avp = (char **) xalloc(sizeof(*avp) * i);
1985 memmove((char *) avp, (char *) argv, sizeof(*avp) * i);
1990 ** PRINTRULES -- print rewrite rules (for debugging)
1999 ** prints rewrite rules.
2005 register struct rewrite *rwp;
2006 register int ruleset;
2008 for (ruleset = 0; ruleset < 10; ruleset++)
2010 if (RewriteRules[ruleset] == NULL)
2012 sm_dprintf("\n----Rule Set %d:", ruleset);
2014 for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
2016 sm_dprintf("\nLHS:");
2017 printav(sm_debug_file(), rwp->r_lhs);
2019 printav(sm_debug_file(), rwp->r_rhs);
2024 ** PRINTMAILER -- print mailer structure (for debugging)
2027 ** fp -- output file
2028 ** m -- the mailer to print
2041 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT,
2042 "mailer %d (%s): P=%s S=", m->m_mno, m->m_name,
2044 if (RuleSetNames[m->m_se_rwset] == NULL)
2045 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d/",
2048 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s/",
2049 RuleSetNames[m->m_se_rwset]);
2050 if (RuleSetNames[m->m_sh_rwset] == NULL)
2051 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d R=",
2054 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s R=",
2055 RuleSetNames[m->m_sh_rwset]);
2056 if (RuleSetNames[m->m_re_rwset] == NULL)
2057 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d/",
2060 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s/",
2061 RuleSetNames[m->m_re_rwset]);
2062 if (RuleSetNames[m->m_rh_rwset] == NULL)
2063 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d ",
2066 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s ",
2067 RuleSetNames[m->m_rh_rwset]);
2068 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "M=%ld U=%d:%d F=",
2069 m->m_maxsize, (int) m->m_uid, (int) m->m_gid);
2070 for (j = '\0'; j <= '\177'; j++)
2071 if (bitnset(j, m->m_flags))
2072 (void) sm_io_putc(fp, SM_TIME_DEFAULT, j);
2073 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " L=%d E=",
2075 xputs(fp, m->m_eol);
2076 if (m->m_defcharset != NULL)
2077 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " C=%s",
2079 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " T=%s/%s/%s",
2080 m->m_mtatype == NULL
2081 ? "<undefined>" : m->m_mtatype,
2082 m->m_addrtype == NULL
2083 ? "<undefined>" : m->m_addrtype,
2084 m->m_diagtype == NULL
2085 ? "<undefined>" : m->m_diagtype);
2086 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " r=%d", m->m_maxrcpt);
2087 if (m->m_argv != NULL)
2089 char **a = m->m_argv;
2091 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " A=");
2095 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT,
2100 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "\n");
2104 static struct ssl_options
2106 const char *sslopt_name; /* name of the flag */
2107 long sslopt_bits; /* bits to set/clear */
2110 /* Workaround for bugs are turned on by default (as well as some others) */
2111 #ifdef SSL_OP_MICROSOFT_SESS_ID_BUG
2112 { "SSL_OP_MICROSOFT_SESS_ID_BUG", SSL_OP_MICROSOFT_SESS_ID_BUG },
2114 #ifdef SSL_OP_NETSCAPE_CHALLENGE_BUG
2115 { "SSL_OP_NETSCAPE_CHALLENGE_BUG", SSL_OP_NETSCAPE_CHALLENGE_BUG },
2117 #ifdef SSL_OP_LEGACY_SERVER_CONNECT
2118 { "SSL_OP_LEGACY_SERVER_CONNECT", SSL_OP_LEGACY_SERVER_CONNECT },
2120 #ifdef SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG
2121 { "SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG", SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG },
2123 #ifdef SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG
2124 { "SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG", SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG },
2126 #ifdef SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER
2127 { "SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER", SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER },
2129 #ifdef SSL_OP_MSIE_SSLV2_RSA_PADDING
2130 { "SSL_OP_MSIE_SSLV2_RSA_PADDING", SSL_OP_MSIE_SSLV2_RSA_PADDING },
2132 #ifdef SSL_OP_SSLEAY_080_CLIENT_DH_BUG
2133 { "SSL_OP_SSLEAY_080_CLIENT_DH_BUG", SSL_OP_SSLEAY_080_CLIENT_DH_BUG },
2135 #ifdef SSL_OP_TLS_D5_BUG
2136 { "SSL_OP_TLS_D5_BUG", SSL_OP_TLS_D5_BUG },
2138 #ifdef SSL_OP_TLS_BLOCK_PADDING_BUG
2139 { "SSL_OP_TLS_BLOCK_PADDING_BUG", SSL_OP_TLS_BLOCK_PADDING_BUG },
2141 #ifdef SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
2142 { "SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS", SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS },
2145 { "SSL_OP_ALL", SSL_OP_ALL },
2147 #ifdef SSL_OP_NO_QUERY_MTU
2148 { "SSL_OP_NO_QUERY_MTU", SSL_OP_NO_QUERY_MTU },
2150 #ifdef SSL_OP_COOKIE_EXCHANGE
2151 { "SSL_OP_COOKIE_EXCHANGE", SSL_OP_COOKIE_EXCHANGE },
2153 #ifdef SSL_OP_NO_TICKET
2154 { "SSL_OP_NO_TICKET", SSL_OP_NO_TICKET },
2156 #ifdef SSL_OP_CISCO_ANYCONNECT
2157 { "SSL_OP_CISCO_ANYCONNECT", SSL_OP_CISCO_ANYCONNECT },
2159 #ifdef SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
2160 { "SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION", SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION },
2162 #ifdef SSL_OP_NO_COMPRESSION
2163 { "SSL_OP_NO_COMPRESSION", SSL_OP_NO_COMPRESSION },
2165 #ifdef SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION
2166 { "SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION", SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION },
2168 #ifdef SSL_OP_SINGLE_ECDH_USE
2169 { "SSL_OP_SINGLE_ECDH_USE", SSL_OP_SINGLE_ECDH_USE },
2171 #ifdef SSL_OP_SINGLE_DH_USE
2172 { "SSL_OP_SINGLE_DH_USE", SSL_OP_SINGLE_DH_USE },
2174 #ifdef SSL_OP_EPHEMERAL_RSA
2175 { "SSL_OP_EPHEMERAL_RSA", SSL_OP_EPHEMERAL_RSA },
2177 #ifdef SSL_OP_CIPHER_SERVER_PREFERENCE
2178 { "SSL_OP_CIPHER_SERVER_PREFERENCE", SSL_OP_CIPHER_SERVER_PREFERENCE },
2180 #ifdef SSL_OP_TLS_ROLLBACK_BUG
2181 { "SSL_OP_TLS_ROLLBACK_BUG", SSL_OP_TLS_ROLLBACK_BUG },
2183 #ifdef SSL_OP_NO_SSLv2
2184 { "SSL_OP_NO_SSLv2", SSL_OP_NO_SSLv2 },
2186 #ifdef SSL_OP_NO_SSLv3
2187 { "SSL_OP_NO_SSLv3", SSL_OP_NO_SSLv3 },
2189 #ifdef SSL_OP_NO_TLSv1
2190 { "SSL_OP_NO_TLSv1", SSL_OP_NO_TLSv1 },
2192 #ifdef SSL_OP_NO_TLSv1_2
2193 { "SSL_OP_NO_TLSv1_2", SSL_OP_NO_TLSv1_2 },
2195 #ifdef SSL_OP_NO_TLSv1_1
2196 { "SSL_OP_NO_TLSv1_1", SSL_OP_NO_TLSv1_1 },
2198 #ifdef SSL_OP_PKCS1_CHECK_1
2199 { "SSL_OP_PKCS1_CHECK_1", SSL_OP_PKCS1_CHECK_1 },
2201 #ifdef SSL_OP_PKCS1_CHECK_2
2202 { "SSL_OP_PKCS1_CHECK_2", SSL_OP_PKCS1_CHECK_2 },
2204 #ifdef SSL_OP_NETSCAPE_CA_DN_BUG
2205 { "SSL_OP_NETSCAPE_CA_DN_BUG", SSL_OP_NETSCAPE_CA_DN_BUG },
2207 #ifdef SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG
2208 { "SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG", SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG },
2210 #ifdef SSL_OP_CRYPTOPRO_TLSEXT_BUG
2211 { "SSL_OP_CRYPTOPRO_TLSEXT_BUG", SSL_OP_CRYPTOPRO_TLSEXT_BUG },
2213 #ifdef SSL_OP_TLSEXT_PADDING
2214 { "SSL_OP_TLSEXT_PADDING", SSL_OP_TLSEXT_PADDING },
2220 ** READSSLOPTIONS -- read SSL_OP_* values
2223 ** opt -- name of option (can be NULL)
2224 ** val -- string with SSL_OP_* values or hex value
2225 ** delim -- end of string (e.g., '\0' or ';')
2226 ** pssloptions -- return value (output)
2232 #define SSLOPERR_NAN 1
2233 #define SSLOPERR_NOTFOUND 2
2234 #define SM_ISSPACE(c) (isascii(c) && isspace(c))
2237 readssloptions(opt, val, pssloptions, delim)
2240 unsigned long *pssloptions;
2247 for (p = val; *p != '\0' && *p != delim; )
2251 unsigned long sslopt_val;
2252 struct ssl_options *sslopts;
2259 if (*p == '-' || *p == '+')
2260 clearmode = *p++ == '-';
2262 while (*p != '\0' && !(SM_ISSPACE(*p)) && *p != ',')
2271 sslopt_val = strtoul(q, &end, 0);
2273 /* not a complete "syntax" check but good enough */
2279 syserr("readcf: %s option value %s not a number",
2286 for (sslopts = SSL_Option;
2287 sslopts->sslopt_name != NULL; sslopts++)
2289 if (sm_strcasecmp(q, sslopts->sslopt_name) == 0)
2291 sslopt_val = sslopts->sslopt_bits;
2295 if (sslopts->sslopt_name == NULL)
2298 ret = SSLOPERR_NOTFOUND;
2300 syserr("readcf: %s option value %s unrecognized",
2304 if (sslopt_val != 0)
2307 *pssloptions &= ~sslopt_val;
2309 *pssloptions |= sslopt_val;
2315 # if _FFR_TLS_SE_OPTS
2317 ** GET_TLS_SE_OPTIONS -- get TLS session options (from ruleset)
2321 ** ssl -- TLS session context
2329 get_tls_se_options(e, ssl, srv)
2334 bool saveQuickAbort, saveSuprErrs, ok;
2335 char *optionlist, *opt, *val;
2336 char *keyfile, *certfile;
2340 # define who (srv ? "server" : "client")
2341 # define NAME_C_S macvalue(macid(srv ? "{client_name}" : "{server_name}"), e)
2342 # define ADDR_C_S macvalue(macid(srv ? "{client_addr}" : "{server_addr}"), e)
2343 # define WHICH srv ? "srv" : "clt"
2346 keyfile = certfile = opt = val = NULL;
2347 saveQuickAbort = QuickAbort;
2348 saveSuprErrs = SuprErrs;
2353 ok = rscheck(srv ? "tls_srv_features" : "tls_clt_features",
2354 NAME_C_S, ADDR_C_S, e,
2355 RSF_RMCOMM|RSF_ADDR|RSF_STRING,
2356 5, NULL, NOQID, NULL, &optionlist) == EX_OK;
2357 if (!ok && LogLevel > 8)
2359 sm_syslog(LOG_NOTICE, NOQID,
2360 "rscheck(tls_%s_features)=failed, relay=%s [%s], errors=%d",
2361 WHICH, NAME_C_S, ADDR_C_S,
2364 QuickAbort = saveQuickAbort;
2365 SuprErrs = saveSuprErrs;
2366 if (ok && LogLevel > 9)
2368 sm_syslog(LOG_INFO, NOQID,
2369 "tls_%s_features=%s, relay=%s [%s]",
2370 WHICH, optionlist, NAME_C_S, ADDR_C_S);
2372 if (!ok || optionlist == NULL || (len = strlen(optionlist)) < 2)
2375 sm_syslog(LOG_INFO, NOQID,
2376 "tls_%s_features=empty, relay=%s [%s]",
2377 WHICH, NAME_C_S, ADDR_C_S);
2383 if (optionlist[0] == '"' && optionlist[len - 1] == '"')
2385 optionlist[0] = ' ';
2386 optionlist[--len] = '\0';
2389 if (LogLevel > 9 && len > 1)
2390 sm_syslog(LOG_INFO, NOQID,
2391 "tls_%s_features=too_short, relay=%s [%s]",
2392 WHICH, NAME_C_S, ADDR_C_S);
2394 /* this is not treated as error! */
2400 # define INVALIDSYNTAX \
2403 sm_syslog(LOG_INFO, NOQID, \
2404 "tls_%s_features=invalid_syntax, opt=%s, relay=%s [%s]", \
2405 WHICH, opt, NAME_C_S, ADDR_C_S); \
2417 while (i < len && SM_ISSPACE(optionlist[i])) \
2422 /* parse and handle opt=val; */
2427 opt = optionlist + i;
2429 while (i < len && optionlist[i] != sep
2430 && optionlist[i] != '\0' && !SM_ISSPACE(optionlist[i]))
2433 while (i < len && SM_ISSPACE(optionlist[i]))
2434 optionlist[i++] = '\0';
2436 if (optionlist[i] != sep)
2438 optionlist[i++] = '\0';
2441 val = optionlist + i;
2443 while (i < len && optionlist[i] != sep && optionlist[i] != '\0')
2445 if (optionlist[i] != '\0')
2448 optionlist[i++] = '\0';
2452 sm_syslog(LOG_DEBUG, NOQID,
2453 "tls_%s_features=parsed, %s=%s, relay=%s [%s]",
2454 WHICH, opt, val, NAME_C_S, ADDR_C_S);
2456 if (sm_strcasecmp(opt, "options") == 0)
2458 unsigned long ssloptions;
2461 ret = readssloptions(NULL, val, &ssloptions, ';');
2463 (void) SSL_set_options(ssl, (long) ssloptions);
2464 else if (LogLevel > 8)
2466 sm_syslog(LOG_WARNING, NOQID,
2467 "tls_%s_features=%s, error=%s, relay=%s [%s]",
2469 (ret == SSLOPERR_NAN) ? "not a number" :
2470 ((ret == SSLOPERR_NOTFOUND) ? "SSL_OP not found" :
2472 NAME_C_S, ADDR_C_S);
2475 else if (sm_strcasecmp(opt, "cipherlist") == 0)
2477 if (SSL_set_cipher_list(ssl, val) <= 0)
2482 sm_syslog(LOG_WARNING, NOQID,
2483 "STARTTLS=%s, error: SSL_set_cipher_list(%s) failed",
2487 tlslogerr(LOG_WARNING, who);
2491 else if (sm_strcasecmp(opt, "keyfile") == 0)
2493 else if (sm_strcasecmp(opt, "certfile") == 0)
2500 sm_syslog(LOG_INFO, NOQID,
2501 "tls_%s_features=unknown_option, opt=%s, relay=%s [%s]",
2502 WHICH, opt, NAME_C_S, ADDR_C_S);
2506 } while (optionlist[i] != '\0' && i < len);
2508 /* need cert and key before we can use the options */
2509 /* does not implement the "," hack for 2nd cert/key pair */
2510 if (keyfile != NULL && certfile != NULL)
2512 load_certkey(ssl, srv, certfile, keyfile);
2513 keyfile = certfile = NULL;
2515 else if (keyfile != NULL || certfile != NULL)
2520 sm_syslog(LOG_INFO, NOQID,
2521 "tls_%s_features=only_one_of_CertFile/KeyFile_specified, relay=%s [%s]",
2522 WHICH, NAME_C_S, ADDR_C_S);
2532 # endif /* _FFR_TLS_SE_OPTS */
2533 #endif /* STARTTLS */
2536 ** SETOPTION -- set global processing option
2539 ** opt -- option name.
2540 ** val -- option value (as a text string).
2541 ** safe -- set if this came from a configuration file.
2542 ** Some options (if set from the command line) will
2543 ** reset the user id to avoid security problems.
2544 ** sticky -- if set, don't let other setoptions override
2546 ** e -- the main envelope.
2552 ** Sets options as implied by the arguments.
2555 static BITMAP256 StickyOpt; /* set if option is stuck */
2559 static struct resolverflags
2561 char *rf_name; /* name of the flag */
2562 long rf_bits; /* bits to set/clear */
2565 { "debug", RES_DEBUG },
2566 { "aaonly", RES_AAONLY },
2567 { "usevc", RES_USEVC },
2568 { "primary", RES_PRIMARY },
2569 { "igntc", RES_IGNTC },
2570 { "recurse", RES_RECURSE },
2571 { "defnames", RES_DEFNAMES },
2572 { "stayopen", RES_STAYOPEN },
2573 { "dnsrch", RES_DNSRCH },
2574 # ifdef RES_USE_INET6
2575 { "use_inet6", RES_USE_INET6 },
2576 # endif /* RES_USE_INET6 */
2577 { "true", 0 }, /* avoid error on old syntax */
2581 #endif /* NAMED_BIND */
2583 #define OI_NONE 0 /* no special treatment */
2584 #define OI_SAFE 0x0001 /* safe for random people to use */
2585 #define OI_SUBOPT 0x0002 /* option has suboptions */
2587 static struct optioninfo
2589 char *o_name; /* long name of option */
2590 unsigned char o_code; /* short name of option */
2591 unsigned short o_flags; /* option flags */
2594 #if defined(SUN_EXTENSIONS) && defined(REMOTE_MODE)
2595 { "RemoteMode", '>', OI_NONE },
2596 #endif /* defined(SUN_EXTENSIONS) && defined(REMOTE_MODE) */
2597 { "SevenBitInput", '7', OI_SAFE },
2598 { "EightBitMode", '8', OI_SAFE },
2599 { "AliasFile", 'A', OI_NONE },
2600 { "AliasWait", 'a', OI_NONE },
2601 { "BlankSub", 'B', OI_NONE },
2602 { "MinFreeBlocks", 'b', OI_SAFE },
2603 { "CheckpointInterval", 'C', OI_SAFE },
2604 { "HoldExpensive", 'c', OI_NONE },
2605 { "DeliveryMode", 'd', OI_SAFE },
2606 { "ErrorHeader", 'E', OI_NONE },
2607 { "ErrorMode", 'e', OI_SAFE },
2608 { "TempFileMode", 'F', OI_NONE },
2609 { "SaveFromLine", 'f', OI_NONE },
2610 { "MatchGECOS", 'G', OI_NONE },
2612 /* no long name, just here to avoid problems in setoption */
2613 { "", 'g', OI_NONE },
2614 { "HelpFile", 'H', OI_NONE },
2615 { "MaxHopCount", 'h', OI_NONE },
2616 { "ResolverOptions", 'I', OI_NONE },
2617 { "IgnoreDots", 'i', OI_SAFE },
2618 { "ForwardPath", 'J', OI_NONE },
2619 { "SendMimeErrors", 'j', OI_SAFE },
2620 { "ConnectionCacheSize", 'k', OI_NONE },
2621 { "ConnectionCacheTimeout", 'K', OI_NONE },
2622 { "UseErrorsTo", 'l', OI_NONE },
2623 { "LogLevel", 'L', OI_SAFE },
2624 { "MeToo", 'm', OI_SAFE },
2626 /* no long name, just here to avoid problems in setoption */
2627 { "", 'M', OI_NONE },
2628 { "CheckAliases", 'n', OI_NONE },
2629 { "OldStyleHeaders", 'o', OI_SAFE },
2630 { "DaemonPortOptions", 'O', OI_NONE },
2631 { "PrivacyOptions", 'p', OI_SAFE },
2632 { "PostmasterCopy", 'P', OI_NONE },
2633 { "QueueFactor", 'q', OI_NONE },
2634 { "QueueDirectory", 'Q', OI_NONE },
2635 { "DontPruneRoutes", 'R', OI_NONE },
2636 { "Timeout", 'r', OI_SUBOPT },
2637 { "StatusFile", 'S', OI_NONE },
2638 { "SuperSafe", 's', OI_SAFE },
2639 { "QueueTimeout", 'T', OI_NONE },
2640 { "TimeZoneSpec", 't', OI_NONE },
2641 { "UserDatabaseSpec", 'U', OI_NONE },
2642 { "DefaultUser", 'u', OI_NONE },
2643 { "FallbackMXhost", 'V', OI_NONE },
2644 { "Verbose", 'v', OI_SAFE },
2645 { "TryNullMXList", 'w', OI_NONE },
2646 { "QueueLA", 'x', OI_NONE },
2647 { "RefuseLA", 'X', OI_NONE },
2648 { "RecipientFactor", 'y', OI_NONE },
2649 { "ForkEachJob", 'Y', OI_NONE },
2650 { "ClassFactor", 'z', OI_NONE },
2651 { "RetryFactor", 'Z', OI_NONE },
2652 #define O_QUEUESORTORD 0x81
2653 { "QueueSortOrder", O_QUEUESORTORD, OI_SAFE },
2654 #define O_HOSTSFILE 0x82
2655 { "HostsFile", O_HOSTSFILE, OI_NONE },
2657 { "MinQueueAge", O_MQA, OI_SAFE },
2658 #define O_DEFCHARSET 0x85
2659 { "DefaultCharSet", O_DEFCHARSET, OI_SAFE },
2660 #define O_SSFILE 0x86
2661 { "ServiceSwitchFile", O_SSFILE, OI_NONE },
2662 #define O_DIALDELAY 0x87
2663 { "DialDelay", O_DIALDELAY, OI_SAFE },
2664 #define O_NORCPTACTION 0x88
2665 { "NoRecipientAction", O_NORCPTACTION, OI_SAFE },
2666 #define O_SAFEFILEENV 0x89
2667 { "SafeFileEnvironment", O_SAFEFILEENV, OI_NONE },
2668 #define O_MAXMSGSIZE 0x8a
2669 { "MaxMessageSize", O_MAXMSGSIZE, OI_NONE },
2670 #define O_COLONOKINADDR 0x8b
2671 { "ColonOkInAddr", O_COLONOKINADDR, OI_SAFE },
2672 #define O_MAXQUEUERUN 0x8c
2673 { "MaxQueueRunSize", O_MAXQUEUERUN, OI_SAFE },
2674 #define O_MAXCHILDREN 0x8d
2675 { "MaxDaemonChildren", O_MAXCHILDREN, OI_NONE },
2676 #define O_KEEPCNAMES 0x8e
2677 { "DontExpandCnames", O_KEEPCNAMES, OI_NONE },
2678 #define O_MUSTQUOTE 0x8f
2679 { "MustQuoteChars", O_MUSTQUOTE, OI_NONE },
2680 #define O_SMTPGREETING 0x90
2681 { "SmtpGreetingMessage", O_SMTPGREETING, OI_NONE },
2682 #define O_UNIXFROM 0x91
2683 { "UnixFromLine", O_UNIXFROM, OI_NONE },
2684 #define O_OPCHARS 0x92
2685 { "OperatorChars", O_OPCHARS, OI_NONE },
2686 #define O_DONTINITGRPS 0x93
2687 { "DontInitGroups", O_DONTINITGRPS, OI_NONE },
2689 { "SingleLineFromHeader", O_SLFH, OI_SAFE },
2691 { "AllowBogusHELO", O_ABH, OI_SAFE },
2692 #define O_CONNTHROT 0x97
2693 { "ConnectionRateThrottle", O_CONNTHROT, OI_NONE },
2695 { "UnsafeGroupWrites", O_UGW, OI_NONE },
2696 #define O_DBLBOUNCE 0x9a
2697 { "DoubleBounceAddress", O_DBLBOUNCE, OI_NONE },
2698 #define O_HSDIR 0x9b
2699 { "HostStatusDirectory", O_HSDIR, OI_NONE },
2700 #define O_SINGTHREAD 0x9c
2701 { "SingleThreadDelivery", O_SINGTHREAD, OI_NONE },
2702 #define O_RUNASUSER 0x9d
2703 { "RunAsUser", O_RUNASUSER, OI_NONE },
2704 #define O_DSN_RRT 0x9e
2705 { "RrtImpliesDsn", O_DSN_RRT, OI_NONE },
2706 #define O_PIDFILE 0x9f
2707 { "PidFile", O_PIDFILE, OI_NONE },
2708 #define O_DONTBLAMESENDMAIL 0xa0
2709 { "DontBlameSendmail", O_DONTBLAMESENDMAIL, OI_NONE },
2711 { "DontProbeInterfaces", O_DPI, OI_NONE },
2712 #define O_MAXRCPT 0xa2
2713 { "MaxRecipientsPerMessage", O_MAXRCPT, OI_SAFE },
2714 #define O_DEADLETTER 0xa3
2715 { "DeadLetterDrop", O_DEADLETTER, OI_NONE },
2716 #if _FFR_DONTLOCKFILESFORREAD_OPTION
2717 # define O_DONTLOCK 0xa4
2718 { "DontLockFilesForRead", O_DONTLOCK, OI_NONE },
2719 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
2720 #define O_MAXALIASRCSN 0xa5
2721 { "MaxAliasRecursion", O_MAXALIASRCSN, OI_NONE },
2722 #define O_CNCTONLYTO 0xa6
2723 { "ConnectOnlyTo", O_CNCTONLYTO, OI_NONE },
2724 #define O_TRUSTUSER 0xa7
2725 { "TrustedUser", O_TRUSTUSER, OI_NONE },
2726 #define O_MAXMIMEHDRLEN 0xa8
2727 { "MaxMimeHeaderLength", O_MAXMIMEHDRLEN, OI_NONE },
2728 #define O_CONTROLSOCKET 0xa9
2729 { "ControlSocketName", O_CONTROLSOCKET, OI_NONE },
2730 #define O_MAXHDRSLEN 0xaa
2731 { "MaxHeadersLength", O_MAXHDRSLEN, OI_NONE },
2732 #if _FFR_MAX_FORWARD_ENTRIES
2733 # define O_MAXFORWARD 0xab
2734 { "MaxForwardEntries", O_MAXFORWARD, OI_NONE },
2735 #endif /* _FFR_MAX_FORWARD_ENTRIES */
2736 #define O_PROCTITLEPREFIX 0xac
2737 { "ProcessTitlePrefix", O_PROCTITLEPREFIX, OI_NONE },
2738 #define O_SASLINFO 0xad
2739 #if _FFR_ALLOW_SASLINFO
2740 { "DefaultAuthInfo", O_SASLINFO, OI_SAFE },
2741 #else /* _FFR_ALLOW_SASLINFO */
2742 { "DefaultAuthInfo", O_SASLINFO, OI_NONE },
2743 #endif /* _FFR_ALLOW_SASLINFO */
2744 #define O_SASLMECH 0xae
2745 { "AuthMechanisms", O_SASLMECH, OI_NONE },
2746 #define O_CLIENTPORT 0xaf
2747 { "ClientPortOptions", O_CLIENTPORT, OI_NONE },
2748 #define O_DF_BUFSIZE 0xb0
2749 { "DataFileBufferSize", O_DF_BUFSIZE, OI_NONE },
2750 #define O_XF_BUFSIZE 0xb1
2751 { "XscriptFileBufferSize", O_XF_BUFSIZE, OI_NONE },
2752 #define O_LDAPDEFAULTSPEC 0xb2
2753 { "LDAPDefaultSpec", O_LDAPDEFAULTSPEC, OI_NONE },
2754 #define O_SRVCERTFILE 0xb4
2755 { "ServerCertFile", O_SRVCERTFILE, OI_NONE },
2756 #define O_SRVKEYFILE 0xb5
2757 { "ServerKeyFile", O_SRVKEYFILE, OI_NONE },
2758 #define O_CLTCERTFILE 0xb6
2759 { "ClientCertFile", O_CLTCERTFILE, OI_NONE },
2760 #define O_CLTKEYFILE 0xb7
2761 { "ClientKeyFile", O_CLTKEYFILE, OI_NONE },
2762 #define O_CACERTFILE 0xb8
2763 { "CACertFile", O_CACERTFILE, OI_NONE },
2764 #define O_CACERTPATH 0xb9
2765 { "CACertPath", O_CACERTPATH, OI_NONE },
2766 #define O_DHPARAMS 0xba
2767 { "DHParameters", O_DHPARAMS, OI_NONE },
2768 #define O_INPUTMILTER 0xbb
2769 { "InputMailFilters", O_INPUTMILTER, OI_NONE },
2770 #define O_MILTER 0xbc
2771 { "Milter", O_MILTER, OI_SUBOPT },
2772 #define O_SASLOPTS 0xbd
2773 { "AuthOptions", O_SASLOPTS, OI_NONE },
2774 #define O_QUEUE_FILE_MODE 0xbe
2775 { "QueueFileMode", O_QUEUE_FILE_MODE, OI_NONE },
2776 #define O_DIG_ALG 0xbf
2777 { "CertFingerprintAlgorithm", O_DIG_ALG, OI_NONE },
2778 #define O_CIPHERLIST 0xc0
2779 { "CipherList", O_CIPHERLIST, OI_NONE },
2780 #define O_RANDFILE 0xc1
2781 { "RandFile", O_RANDFILE, OI_NONE },
2782 #define O_TLS_SRV_OPTS 0xc2
2783 { "TLSSrvOptions", O_TLS_SRV_OPTS, OI_NONE },
2784 #define O_RCPTTHROT 0xc3
2785 { "BadRcptThrottle", O_RCPTTHROT, OI_SAFE },
2786 #define O_DLVR_MIN 0xc4
2787 { "DeliverByMin", O_DLVR_MIN, OI_NONE },
2788 #define O_MAXQUEUECHILDREN 0xc5
2789 { "MaxQueueChildren", O_MAXQUEUECHILDREN, OI_NONE },
2790 #define O_MAXRUNNERSPERQUEUE 0xc6
2791 { "MaxRunnersPerQueue", O_MAXRUNNERSPERQUEUE, OI_NONE },
2792 #define O_DIRECTSUBMODIFIERS 0xc7
2793 { "DirectSubmissionModifiers", O_DIRECTSUBMODIFIERS, OI_NONE },
2794 #define O_NICEQUEUERUN 0xc8
2795 { "NiceQueueRun", O_NICEQUEUERUN, OI_NONE },
2796 #define O_SHMKEY 0xc9
2797 { "SharedMemoryKey", O_SHMKEY, OI_NONE },
2798 #define O_SASLBITS 0xca
2799 { "AuthMaxBits", O_SASLBITS, OI_NONE },
2801 { "MailboxDatabase", O_MBDB, OI_NONE },
2803 { "UseMSP", O_MSQ, OI_NONE },
2804 #define O_DELAY_LA 0xcd
2805 { "DelayLA", O_DELAY_LA, OI_NONE },
2806 #define O_FASTSPLIT 0xce
2807 { "FastSplit", O_FASTSPLIT, OI_NONE },
2808 #define O_SOFTBOUNCE 0xcf
2809 { "SoftBounce", O_SOFTBOUNCE, OI_NONE },
2810 #define O_SHMKEYFILE 0xd0
2811 { "SharedMemoryKeyFile", O_SHMKEYFILE, OI_NONE },
2812 #define O_REJECTLOGINTERVAL 0xd1
2813 { "RejectLogInterval", O_REJECTLOGINTERVAL, OI_NONE },
2814 #define O_REQUIRES_DIR_FSYNC 0xd2
2815 { "RequiresDirfsync", O_REQUIRES_DIR_FSYNC, OI_NONE },
2816 #define O_CONNECTION_RATE_WINDOW_SIZE 0xd3
2817 { "ConnectionRateWindowSize", O_CONNECTION_RATE_WINDOW_SIZE, OI_NONE },
2818 #define O_CRLFILE 0xd4
2819 { "CRLFile", O_CRLFILE, OI_NONE },
2820 #define O_FALLBACKSMARTHOST 0xd5
2821 { "FallbackSmartHost", O_FALLBACKSMARTHOST, OI_NONE },
2822 #define O_SASLREALM 0xd6
2823 { "AuthRealm", O_SASLREALM, OI_NONE },
2825 # define O_CRLPATH 0xd7
2826 { "CRLPath", O_CRLPATH, OI_NONE },
2827 #endif /* _FFR_CRLPATH */
2828 #define O_HELONAME 0xd8
2829 { "HeloName", O_HELONAME, OI_NONE },
2831 # define O_REFUSELOWMEM 0xd9
2832 { "RefuseLowMem", O_REFUSELOWMEM, OI_NONE },
2833 # define O_QUEUELOWMEM 0xda
2834 { "QueueLowMem", O_QUEUELOWMEM, OI_NONE },
2835 # define O_MEMRESOURCE 0xdb
2836 { "MemoryResource", O_MEMRESOURCE, OI_NONE },
2837 #endif /* _FFR_MEMSTAT */
2838 #define O_MAXNOOPCOMMANDS 0xdc
2839 { "MaxNOOPCommands", O_MAXNOOPCOMMANDS, OI_NONE },
2841 # define O_MSG_ACCEPT 0xdd
2842 { "MessageAccept", O_MSG_ACCEPT, OI_NONE },
2843 #endif /* _FFR_MSG_ACCEPT */
2844 #if _FFR_QUEUE_RUN_PARANOIA
2845 # define O_CHK_Q_RUNNERS 0xde
2846 { "CheckQueueRunners", O_CHK_Q_RUNNERS, OI_NONE },
2847 #endif /* _FFR_QUEUE_RUN_PARANOIA */
2848 #if _FFR_EIGHT_BIT_ADDR_OK
2850 # ERROR FFR_EIGHT_BIT_ADDR_OK requires _ALLOW_255
2851 # endif /* !ALLOW_255 */
2852 # define O_EIGHT_BIT_ADDR_OK 0xdf
2853 { "EightBitAddrOK", O_EIGHT_BIT_ADDR_OK, OI_NONE },
2854 #endif /* _FFR_EIGHT_BIT_ADDR_OK */
2855 #if _FFR_ADDR_TYPE_MODES
2856 # define O_ADDR_TYPE_MODES 0xe0
2857 { "AddrTypeModes", O_ADDR_TYPE_MODES, OI_NONE },
2858 #endif /* _FFR_ADDR_TYPE_MODES */
2859 #if _FFR_BADRCPT_SHUTDOWN
2860 # define O_RCPTSHUTD 0xe1
2861 { "BadRcptShutdown", O_RCPTSHUTD, OI_SAFE },
2862 # define O_RCPTSHUTDG 0xe2
2863 { "BadRcptShutdownGood", O_RCPTSHUTDG, OI_SAFE },
2864 #endif /* _FFR_BADRCPT_SHUTDOWN */
2865 #define O_SRV_SSL_OPTIONS 0xe3
2866 { "ServerSSLOptions", O_SRV_SSL_OPTIONS, OI_NONE },
2867 #define O_CLT_SSL_OPTIONS 0xe4
2868 { "ClientSSLOptions", O_CLT_SSL_OPTIONS, OI_NONE },
2869 #define O_MAX_QUEUE_AGE 0xe5
2870 { "MaxQueueAge", O_MAX_QUEUE_AGE, OI_NONE },
2871 #if _FFR_RCPTTHROTDELAY
2872 # define O_RCPTTHROTDELAY 0xe6
2873 { "BadRcptThrottleDelay", O_RCPTTHROTDELAY, OI_SAFE },
2874 #endif /* _FFR_RCPTTHROTDELAY */
2875 #if 0 && _FFR_QOS && defined(SOL_IP) && defined(IP_TOS)
2876 # define O_INETQOS 0xe7 /* reserved for FFR_QOS */
2877 { "InetQoS", O_INETQOS, OI_NONE },
2879 #if STARTTLS && _FFR_FIPSMODE
2880 # define O_FIPSMODE 0xe8
2881 { "FIPSMode", O_FIPSMODE, OI_NONE },
2882 #endif /* STARTTLS && _FFR_FIPSMODE */
2883 #if _FFR_REJECT_NUL_BYTE
2884 # define O_REJECTNUL 0xe9
2885 { "RejectNUL", O_REJECTNUL, OI_SAFE },
2886 #endif /* _FFR_REJECT_NUL_BYTE */
2887 #if _FFR_BOUNCE_QUEUE
2888 # define O_BOUNCEQUEUE 0xea
2889 { "BounceQueue", O_BOUNCEQUEUE, OI_NONE },
2890 #endif /* _FFR_BOUNCE_QUEUE */
2892 # define O_ADDBCC 0xeb
2893 { "AddBcc", O_ADDBCC, OI_NONE },
2895 #define O_USECOMPRESSEDIPV6ADDRESSES 0xec
2896 { "UseCompressedIPv6Addresses", O_USECOMPRESSEDIPV6ADDRESSES, OI_NONE },
2898 { NULL, '\0', OI_NONE }
2901 # define CANONIFY(val)
2903 # define SET_OPT_DEFAULT(opt, val) opt = val
2905 /* set a string option by expanding the value and assigning it */
2906 /* WARNING this belongs ONLY into a case statement! */
2907 #define SET_STRING_EXP(str) \
2908 expand(val, exbuf, sizeof(exbuf), e); \
2909 newval = sm_pstrdup_x(exbuf); \
2916 #define OPTNAME o->o_name == NULL ? "<unknown>" : o->o_name
2919 setoption(opt, val, safe, sticky, e)
2924 register ENVELOPE *e;
2927 register struct optioninfo *o;
2930 bool can_setuid = RunAsUid == 0;
2933 extern bool Warn_Q_option;
2934 #if _FFR_ALLOW_SASLINFO
2935 extern unsigned int SubmitMode;
2936 #endif /* _FFR_ALLOW_SASLINFO */
2937 #if STARTTLS || SM_CONF_SHM
2939 char exbuf[MAXLINE];
2940 #endif /* STARTTLS || SM_CONF_SHM */
2942 unsigned long *pssloptions = NULL;
2948 /* full word options */
2949 struct optioninfo *sel;
2951 p = strchr(val, '=');
2953 p = &val[strlen(val)];
2960 syserr("readcf: null option name");
2967 subopt = strchr(val, '.');
2971 for (o = OptionTab; o->o_name != NULL; o++)
2973 if (sm_strncasecmp(o->o_name, val, strlen(val)) != 0)
2975 if (strlen(o->o_name) == strlen(val))
2977 /* completely specified -- this must be it */
2985 if (sel != NULL && o->o_name == NULL)
2987 else if (o->o_name == NULL)
2989 syserr("readcf: unknown option name %s", val);
2992 else if (sel != NULL)
2994 syserr("readcf: ambiguous option name %s (matches %s and %s)",
2995 val, sel->o_name, o->o_name);
2998 if (strlen(val) != strlen(o->o_name))
3000 int oldVerbose = Verbose;
3003 message("Option %s used as abbreviation for %s",
3005 Verbose = oldVerbose;
3012 for (o = OptionTab; o->o_name != NULL; o++)
3014 if (o->o_code == opt)
3017 if (o->o_name == NULL)
3019 syserr("readcf: unknown option name 0x%x", opt & 0xff);
3025 if (subopt != NULL && !bitset(OI_SUBOPT, o->o_flags))
3028 sm_dprintf("setoption: %s does not support suboptions, ignoring .%s\n",
3035 sm_dprintf(isascii(opt) && isprint(opt) ?
3036 "setoption %s (%c)%s%s=" :
3037 "setoption %s (0x%x)%s%s=",
3038 OPTNAME, opt, subopt == NULL ? "" : ".",
3039 subopt == NULL ? "" : subopt);
3040 xputs(sm_debug_file(), val);
3044 ** See if this option is preset for us.
3047 if (!sticky && bitnset(opt, StickyOpt))
3050 sm_dprintf(" (ignored)\n");
3055 ** Check to see if this option can be specified by this user.
3058 if (!safe && RealUid == 0)
3060 if (!safe && !bitset(OI_SAFE, o->o_flags))
3062 if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
3067 sm_dprintf(" (unsafe)");
3068 dp = drop_privileges(true);
3077 case '7': /* force seven-bit input */
3078 SevenBitInput = atobool(val);
3081 case '8': /* handling of 8-bit input */
3085 case 'p': /* pass 8 bit, convert MIME */
3086 MimeMode = MM_CVTMIME|MM_PASS8BIT;
3089 case 'm': /* convert 8-bit, convert MIME */
3090 MimeMode = MM_CVTMIME|MM_MIME8BIT;
3093 case 's': /* strict adherence */
3094 MimeMode = MM_CVTMIME;
3098 case 'r': /* reject 8-bit, don't convert MIME */
3102 case 'j': /* "just send 8" */
3103 MimeMode = MM_PASS8BIT;
3106 case 'a': /* encode 8 bit if available */
3107 MimeMode = MM_MIME8BIT|MM_PASS8BIT|MM_CVTMIME;
3110 case 'c': /* convert 8 bit to MIME, never 7 bit */
3111 MimeMode = MM_MIME8BIT;
3116 syserr("Unknown 8-bit mode %c", *val);
3117 finis(false, true, EX_USAGE);
3119 #else /* MIME8TO7 */
3120 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3121 "Warning: Option: %s requires MIME8TO7 support\n",
3123 #endif /* MIME8TO7 */
3126 case 'A': /* set default alias file */
3131 SET_OPT_DEFAULT(al, "aliases");
3138 case 'a': /* look N minutes for "@:@" in alias file */
3140 SafeAlias = 5 MINUTES;
3142 SafeAlias = convtime(val, 'm');
3145 case 'B': /* substitution for blank character */
3147 if (SpaceSub == '\0')
3151 case 'b': /* min blocks free on queue fs/max msg size */
3152 p = strchr(val, '/');
3156 MaxMessageSize = atol(p);
3158 MinBlocksFree = atol(val);
3161 case 'c': /* don't connect to "expensive" mailers */
3162 NoConnect = atobool(val);
3165 case 'C': /* checkpoint every N addresses */
3166 if (safe || CheckpointInterval > atoi(val))
3167 CheckpointInterval = atoi(val);
3170 case 'd': /* delivery mode */
3174 set_delivery_mode(SM_DELIVER, e);
3177 case SM_QUEUE: /* queue only */
3178 case SM_DEFER: /* queue only and defer map lookups */
3179 case SM_DELIVER: /* do everything */
3180 case SM_FORK: /* fork after verification */
3182 /* deliver first TA in background, then queue */
3184 #endif /* _FFR_DM_ONE */
3185 set_delivery_mode(*val, e);
3190 set_delivery_mode(*val, e);
3192 #endif /* _FFR_PROXY */
3195 syserr("Unknown delivery mode %c", *val);
3196 finis(false, true, EX_USAGE);
3200 case 'E': /* error message header/header file */
3202 ErrMsgFile = newstr(val);
3205 case 'e': /* set error processing mode */
3208 case EM_QUIET: /* be silent about it */
3209 case EM_MAIL: /* mail back */
3210 case EM_BERKNET: /* do berknet error processing */
3211 case EM_WRITE: /* write back (or mail) */
3212 case EM_PRINT: /* print errors normally (default) */
3213 e->e_errormode = *val;
3218 case 'F': /* file mode */
3219 FileMode = atooct(val) & 0777;
3222 case 'f': /* save Unix-style From lines on front */
3223 SaveFrom = atobool(val);
3226 case 'G': /* match recipients against GECOS field */
3227 MatchGecos = atobool(val);
3230 case 'g': /* default gid */
3232 if (isascii(*val) && isdigit(*val))
3236 register struct group *gr;
3241 syserr("readcf: option %c: unknown group %s",
3244 DefGid = gr->gr_gid;
3248 case 'H': /* help file */
3251 SET_OPT_DEFAULT(HelpFile, "helpfile");
3256 HelpFile = newstr(val);
3260 case 'h': /* maximum hop count */
3261 MaxHopCount = atoi(val);
3264 case 'I': /* use internet domain name server */
3266 for (p = val; *p != 0; )
3270 struct resolverflags *rfp;
3283 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
3287 if (sm_strcasecmp(q, "HasWildcardMX") == 0)
3289 HasWildcardMX = !clearmode;
3292 if (sm_strcasecmp(q, "WorkAroundBrokenAAAA") == 0)
3294 WorkAroundBrokenAAAA = !clearmode;
3297 for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
3299 if (sm_strcasecmp(q, rfp->rf_name) == 0)
3302 if (rfp->rf_name == NULL)
3303 syserr("readcf: I option value %s unrecognized", q);
3305 _res.options &= ~rfp->rf_bits;
3307 _res.options |= rfp->rf_bits;
3310 sm_dprintf("_res.options = %x, HasWildcardMX = %d\n",
3311 (unsigned int) _res.options, HasWildcardMX);
3312 #else /* NAMED_BIND */
3313 usrerr("name server (I option) specified but BIND not compiled in");
3314 #endif /* NAMED_BIND */
3317 case 'i': /* ignore dot lines in message */
3318 IgnrDot = atobool(val);
3321 case 'j': /* send errors in MIME (RFC 1341) format */
3322 SendMIMEErrors = atobool(val);
3325 case 'J': /* .forward search path */
3327 ForwardPath = newstr(val);
3330 case 'k': /* connection cache size */
3331 MaxMciCache = atoi(val);
3332 if (MaxMciCache < 0)
3336 case 'K': /* connection cache timeout */
3337 MciCacheTimeout = convtime(val, 'm');
3340 case 'l': /* use Errors-To: header */
3341 UseErrorsTo = atobool(val);
3344 case 'L': /* log level */
3345 if (safe || LogLevel < atoi(val))
3346 LogLevel = atoi(val);
3349 case 'M': /* define macro */
3351 mid = macid_parse(val, &ep);
3356 cleanstrcpy(p, p, strlen(p) + 1);
3357 macdefine(&CurEnv->e_macro, A_TEMP, mid, p);
3360 case 'm': /* send to me too */
3361 MeToo = atobool(val);
3364 case 'n': /* validate RHS in newaliases */
3365 CheckAliases = atobool(val);
3368 /* 'N' available -- was "net name" */
3370 case 'O': /* daemon options */
3371 if (!setdaemonoptions(val))
3372 syserr("too many daemons defined (%d max)", MAXDAEMONS);
3375 case 'o': /* assume old style headers */
3377 CurEnv->e_flags |= EF_OLDSTYLE;
3379 CurEnv->e_flags &= ~EF_OLDSTYLE;
3382 case 'p': /* select privacy level */
3386 register struct prival *pv;
3387 extern struct prival PrivacyValues[];
3389 while (isascii(*p) && (isspace(*p) || ispunct(*p)))
3394 while (isascii(*p) && isalnum(*p))
3399 for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
3401 if (sm_strcasecmp(val, pv->pv_name) == 0)
3404 if (pv->pv_name == NULL)
3405 syserr("readcf: Op line: %s unrecognized", val);
3407 PrivacyFlags |= pv->pv_flag;
3412 case 'P': /* postmaster copy address for returned mail */
3413 PostMasterCopy = newstr(val);
3416 case 'q': /* slope of queue only function */
3417 QueueFactor = atoi(val);
3420 case 'Q': /* queue directory */
3423 QueueDir = "mqueue";
3427 QueueDir = newstr(val);
3429 if (RealUid != 0 && !safe)
3430 Warn_Q_option = true;
3433 case 'R': /* don't prune routes */
3434 DontPruneRoutes = atobool(val);
3437 case 'r': /* read timeout */
3439 inittimeouts(val, sticky);
3441 settimeout(subopt, val, sticky);
3444 case 'S': /* status file */
3447 SET_OPT_DEFAULT(StatFile, "statistics");
3452 StatFile = newstr(val);
3456 case 's': /* be super safe, even if expensive */
3457 if (tolower(*val) == 'i')
3458 SuperSafe = SAFE_INTERACTIVE;
3459 else if (tolower(*val) == 'p')
3461 SuperSafe = SAFE_REALLY_POSTMILTER;
3463 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3464 "Warning: SuperSafe=PostMilter requires Milter support (-DMILTER)\n");
3467 SuperSafe = atobool(val) ? SAFE_REALLY : SAFE_NO;
3470 case 'T': /* queue timeout */
3471 p = strchr(val, '/');
3475 settimeout("queuewarn", p, sticky);
3477 settimeout("queuereturn", val, sticky);
3480 case 't': /* time zone name */
3481 TimeZoneSpec = newstr(val);
3484 case 'U': /* location of user database */
3485 UdbSpec = newstr(val);
3488 case 'u': /* set default uid */
3489 for (p = val; *p != '\0'; p++)
3491 # if _FFR_DOTTED_USERNAMES
3492 if (*p == '/' || *p == ':')
3493 # else /* _FFR_DOTTED_USERNAMES */
3494 if (*p == '.' || *p == '/' || *p == ':')
3495 # endif /* _FFR_DOTTED_USERNAMES */
3501 if (isascii(*val) && isdigit(*val))
3508 register struct passwd *pw;
3511 pw = sm_getpwnam(val);
3514 syserr("readcf: option u: unknown user %s", val);
3519 DefUid = pw->pw_uid;
3520 DefGid = pw->pw_gid;
3521 DefUser = newstr(pw->pw_name);
3526 if (DefUid > UID_MAX)
3528 syserr("readcf: option u: uid value (%ld) > UID_MAX (%ld); ignored",
3529 (long)DefUid, (long)UID_MAX);
3532 # endif /* UID_MAX */
3534 /* handle the group if it is there */
3540 case 'V': /* fallback MX host */
3542 FallbackMX = newstr(val);
3545 case 'v': /* run in verbose mode */
3546 Verbose = atobool(val) ? 1 : 0;
3549 case 'w': /* if we are best MX, try host directly */
3550 TryNullMXList = atobool(val);
3553 /* 'W' available -- was wizard password */
3555 case 'x': /* load avg at which to auto-queue msgs */
3556 QueueLA = atoi(val);
3559 case 'X': /* load avg at which to auto-reject connections */
3560 RefuseLA = atoi(val);
3563 case O_DELAY_LA: /* load avg at which to delay connections */
3564 DelayLA = atoi(val);
3567 case 'y': /* work recipient factor */
3568 WkRecipFact = atoi(val);
3571 case 'Y': /* fork jobs during queue runs */
3572 ForkQueueRuns = atobool(val);
3575 case 'z': /* work message class factor */
3576 WkClassFact = atoi(val);
3579 case 'Z': /* work time factor */
3580 WkTimeFact = atoi(val);
3584 #if _FFR_QUEUE_GROUP_SORTORDER
3585 /* coordinate this with makequeue() */
3586 #endif /* _FFR_QUEUE_GROUP_SORTORDER */
3587 case O_QUEUESORTORD: /* queue sorting order */
3590 case 'f': /* File Name */
3592 QueueSortOrder = QSO_BYFILENAME;
3595 case 'h': /* Host first */
3597 QueueSortOrder = QSO_BYHOST;
3600 case 'm': /* Modification time */
3602 QueueSortOrder = QSO_BYMODTIME;
3605 case 'p': /* Priority order */
3607 QueueSortOrder = QSO_BYPRIORITY;
3610 case 't': /* Submission time */
3612 QueueSortOrder = QSO_BYTIME;
3615 case 'r': /* Random */
3617 QueueSortOrder = QSO_RANDOM;
3621 case 's': /* Shuffled host name */
3623 QueueSortOrder = QSO_BYSHUFFLE;
3625 #endif /* _FFR_RHS */
3627 case 'n': /* none */
3629 QueueSortOrder = QSO_NONE;
3633 syserr("Invalid queue sort order \"%s\"", val);
3637 case O_HOSTSFILE: /* pathname of /etc/hosts file */
3639 HostsFile = newstr(val);
3642 case O_MQA: /* minimum queue age between deliveries */
3643 MinQueueAge = convtime(val, 'm');
3646 case O_MAX_QUEUE_AGE:
3647 MaxQueueAge = convtime(val, 'm');
3650 case O_DEFCHARSET: /* default character set for mimefying */
3651 DefaultCharSet = newstr(denlstring(val, true, true));
3654 case O_SSFILE: /* service switch file */
3656 ServiceSwitchFile = newstr(val);
3659 case O_DIALDELAY: /* delay for dial-on-demand operation */
3660 DialDelay = convtime(val, 's');
3663 case O_NORCPTACTION: /* what to do if no recipient */
3664 if (sm_strcasecmp(val, "none") == 0)
3665 NoRecipientAction = NRA_NO_ACTION;
3666 else if (sm_strcasecmp(val, "add-to") == 0)
3667 NoRecipientAction = NRA_ADD_TO;
3668 else if (sm_strcasecmp(val, "add-apparently-to") == 0)
3669 NoRecipientAction = NRA_ADD_APPARENTLY_TO;
3670 else if (sm_strcasecmp(val, "add-bcc") == 0)
3671 NoRecipientAction = NRA_ADD_BCC;
3672 else if (sm_strcasecmp(val, "add-to-undisclosed") == 0)
3673 NoRecipientAction = NRA_ADD_TO_UNDISCLOSED;
3675 syserr("Invalid NoRecipientAction: %s", val);
3678 case O_SAFEFILEENV: /* chroot() environ for writing to files */
3682 /* strip trailing slashes */
3683 p = val + strlen(val) - 1;
3684 while (p >= val && *p == '/')
3690 SafeFileEnv = newstr(val);
3693 case O_MAXMSGSIZE: /* maximum message size */
3694 MaxMessageSize = atol(val);
3697 case O_COLONOKINADDR: /* old style handling of colon addresses */
3698 ColonOkInAddr = atobool(val);
3701 case O_MAXQUEUERUN: /* max # of jobs in a single queue run */
3702 MaxQueueRun = atoi(val);
3705 case O_MAXCHILDREN: /* max # of children of daemon */
3706 MaxChildren = atoi(val);
3709 case O_MAXQUEUECHILDREN: /* max # of children of daemon */
3710 MaxQueueChildren = atoi(val);
3713 case O_MAXRUNNERSPERQUEUE: /* max # runners in a queue group */
3714 MaxRunnersPerQueue = atoi(val);
3717 case O_NICEQUEUERUN: /* nice queue runs */
3719 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3720 "Warning: NiceQueueRun set on system that doesn't support nice()\n");
3721 #endif /* !HASNICE */
3723 /* XXX do we want to check the range? > 0 ? */
3724 NiceQueueRun = atoi(val);
3727 case O_SHMKEY: /* shared memory key */
3730 #else /* SM_CONF_SHM */
3731 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3732 "Warning: Option: %s requires shared memory support (-DSM_CONF_SHM)\n",
3734 #endif /* SM_CONF_SHM */
3737 case O_SHMKEYFILE: /* shared memory key file */
3739 SET_STRING_EXP(ShmKeyFile);
3740 #else /* SM_CONF_SHM */
3741 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3742 "Warning: Option: %s requires shared memory support (-DSM_CONF_SHM)\n",
3745 #endif /* SM_CONF_SHM */
3747 #if _FFR_MAX_FORWARD_ENTRIES
3748 case O_MAXFORWARD: /* max # of forward entries */
3749 MaxForwardEntries = atoi(val);
3751 #endif /* _FFR_MAX_FORWARD_ENTRIES */
3753 case O_KEEPCNAMES: /* don't expand CNAME records */
3754 DontExpandCnames = atobool(val);
3757 case O_MUSTQUOTE: /* must quote these characters in phrases */
3758 (void) sm_strlcpy(buf, "@,;:\\()[]", sizeof(buf));
3759 if (strlen(val) < sizeof(buf) - 10)
3760 (void) sm_strlcat(buf, val, sizeof(buf));
3762 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3763 "Warning: MustQuoteChars too long, ignored.\n");
3764 MustQuoteChars = newstr(buf);
3767 case O_SMTPGREETING: /* SMTP greeting message (old $e macro) */
3768 SmtpGreeting = newstr(munchstring(val, NULL, '\0'));
3771 case O_UNIXFROM: /* UNIX From_ line (old $l macro) */
3772 UnixFromLine = newstr(munchstring(val, NULL, '\0'));
3775 case O_OPCHARS: /* operator characters (old $o macro) */
3776 if (OperatorChars != NULL)
3777 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3778 "Warning: OperatorChars is being redefined.\n It should only be set before ruleset definitions.\n");
3779 OperatorChars = newstr(munchstring(val, NULL, '\0'));
3782 case O_DONTINITGRPS: /* don't call initgroups(3) */
3783 DontInitGroups = atobool(val);
3786 case O_SLFH: /* make sure from fits on one line */
3787 SingleLineFromHeader = atobool(val);
3790 case O_ABH: /* allow HELO commands with syntax errors */
3791 AllowBogusHELO = atobool(val);
3794 case O_CONNTHROT: /* connection rate throttle */
3795 ConnRateThrottle = atoi(val);
3798 case O_UGW: /* group writable files are unsafe */
3801 setbitn(DBS_GROUPWRITABLEFORWARDFILESAFE,
3803 setbitn(DBS_GROUPWRITABLEINCLUDEFILESAFE,
3808 case O_DBLBOUNCE: /* address to which to send double bounces */
3809 DoubleBounceAddr = newstr(val);
3812 case O_HSDIR: /* persistent host status directory */
3816 HostStatDir = newstr(val);
3820 case O_SINGTHREAD: /* single thread deliveries (requires hsdir) */
3821 SingleThreadDelivery = atobool(val);
3824 case O_RUNASUSER: /* run bulk of code as this user */
3825 for (p = val; *p != '\0'; p++)
3827 # if _FFR_DOTTED_USERNAMES
3828 if (*p == '/' || *p == ':')
3829 # else /* _FFR_DOTTED_USERNAMES */
3830 if (*p == '.' || *p == '/' || *p == ':')
3831 # endif /* _FFR_DOTTED_USERNAMES */
3837 if (isascii(*val) && isdigit(*val))
3840 RunAsUid = atoi(val);
3844 register struct passwd *pw;
3846 pw = sm_getpwnam(val);
3849 syserr("readcf: option RunAsUser: unknown user %s", val);
3852 else if (can_setuid)
3855 RunAsUserName = newstr(val);
3856 RunAsUid = pw->pw_uid;
3857 RunAsGid = pw->pw_gid;
3859 else if (EffGid == pw->pw_gid)
3860 RunAsGid = pw->pw_gid;
3861 else if (UseMSP && *p == '\0')
3862 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3863 "WARNING: RunAsUser for MSP ignored, check group ids (egid=%ld, want=%ld)\n",
3868 if (RunAsUid > UID_MAX)
3870 syserr("readcf: option RunAsUser: uid value (%ld) > UID_MAX (%ld); ignored",
3871 (long) RunAsUid, (long) UID_MAX);
3874 # endif /* UID_MAX */
3877 if (isascii(*p) && isdigit(*p))
3881 runasgid = (gid_t) atoi(p);
3882 if (can_setuid || EffGid == runasgid)
3883 RunAsGid = runasgid;
3885 (void) sm_io_fprintf(smioout,
3887 "WARNING: RunAsUser for MSP ignored, check group ids (egid=%ld, want=%ld)\n",
3893 register struct group *gr;
3897 syserr("readcf: option RunAsUser: unknown group %s",
3899 else if (can_setuid || EffGid == gr->gr_gid)
3900 RunAsGid = gr->gr_gid;
3902 (void) sm_io_fprintf(smioout,
3904 "WARNING: RunAsUser for MSP ignored, check group ids (egid=%ld, want=%ld)\n",
3910 sm_dprintf("readcf: RunAsUser = %d:%d\n",
3911 (int) RunAsUid, (int) RunAsGid);
3915 RrtImpliesDsn = atobool(val);
3919 PSTRSET(PidFile, val);
3922 case O_DONTBLAMESENDMAIL:
3926 register struct dbsval *dbs;
3927 extern struct dbsval DontBlameSendmailValues[];
3929 while (isascii(*p) && (isspace(*p) || ispunct(*p)))
3934 while (isascii(*p) && isalnum(*p))
3939 for (dbs = DontBlameSendmailValues;
3940 dbs->dbs_name != NULL; dbs++)
3942 if (sm_strcasecmp(val, dbs->dbs_name) == 0)
3945 if (dbs->dbs_name == NULL)
3946 syserr("readcf: DontBlameSendmail option: %s unrecognized", val);
3947 else if (dbs->dbs_flag == DBS_SAFE)
3948 clrbitmap(DontBlameSendmail);
3950 setbitn(dbs->dbs_flag, DontBlameSendmail);
3956 if (sm_strcasecmp(val, "loopback") == 0)
3957 DontProbeInterfaces = DPI_SKIPLOOPBACK;
3958 else if (atobool(val))
3959 DontProbeInterfaces = DPI_PROBENONE;
3961 DontProbeInterfaces = DPI_PROBEALL;
3965 MaxRcptPerMsg = atoi(val);
3969 BadRcptThrottle = atoi(val);
3972 #if _FFR_RCPTTHROTDELAY
3973 case O_RCPTTHROTDELAY:
3974 BadRcptThrottleDelay = atoi(val);
3976 #endif /* _FFR_RCPTTHROTDELAY */
3980 PSTRSET(DeadLetterDrop, val);
3983 #if _FFR_DONTLOCKFILESFORREAD_OPTION
3985 DontLockReadFiles = atobool(val);
3987 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
3989 case O_MAXALIASRCSN:
3990 MaxAliasRecursion = atoi(val);
3994 /* XXX should probably use gethostbyname */
3995 #if NETINET || NETINET6
3996 ConnectOnlyTo.sa.sa_family = AF_UNSPEC;
3998 if (anynet_pton(AF_INET6, val,
3999 &ConnectOnlyTo.sin6.sin6_addr) == 1)
4000 ConnectOnlyTo.sa.sa_family = AF_INET6;
4002 # endif /* NETINET6 */
4005 ConnectOnlyTo.sin.sin_addr.s_addr = inet_addr(val);
4006 if (ConnectOnlyTo.sin.sin_addr.s_addr != INADDR_NONE)
4007 ConnectOnlyTo.sa.sa_family = AF_INET;
4010 # endif /* NETINET */
4011 if (ConnectOnlyTo.sa.sa_family == AF_UNSPEC)
4013 syserr("readcf: option ConnectOnlyTo: invalid IP address %s",
4017 #endif /* NETINET || NETINET6 */
4021 # if !HASFCHOWN && !defined(_FFR_DROP_TRUSTUSER_WARNING)
4023 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4024 "readcf: option TrustedUser may cause problems on systems\n which do not support fchown() if UseMSP is not set.\n");
4025 # endif /* !HASFCHOWN && !defined(_FFR_DROP_TRUSTUSER_WARNING) */
4026 if (isascii(*val) && isdigit(*val))
4027 TrustedUid = atoi(val);
4030 register struct passwd *pw;
4033 pw = sm_getpwnam(val);
4036 syserr("readcf: option TrustedUser: unknown user %s", val);
4040 TrustedUid = pw->pw_uid;
4044 if (TrustedUid > UID_MAX)
4046 syserr("readcf: option TrustedUser: uid value (%ld) > UID_MAX (%ld)",
4047 (long) TrustedUid, (long) UID_MAX);
4050 # endif /* UID_MAX */
4053 case O_MAXMIMEHDRLEN:
4054 p = strchr(val, '/');
4057 MaxMimeHeaderLength = atoi(val);
4058 if (p != NULL && *p != '\0')
4059 MaxMimeFieldLength = atoi(p);
4061 MaxMimeFieldLength = MaxMimeHeaderLength / 2;
4063 if (MaxMimeHeaderLength <= 0)
4064 MaxMimeHeaderLength = 0;
4065 else if (MaxMimeHeaderLength < 128)
4066 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4067 "Warning: MaxMimeHeaderLength: header length limit set lower than 128\n");
4069 if (MaxMimeFieldLength <= 0)
4070 MaxMimeFieldLength = 0;
4071 else if (MaxMimeFieldLength < 40)
4072 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4073 "Warning: MaxMimeHeaderLength: field length limit set lower than 40\n");
4076 ** Headers field values now include leading space, so let's
4077 ** adjust the values to be "backward compatible".
4080 if (MaxMimeHeaderLength > 0)
4081 MaxMimeHeaderLength++;
4082 if (MaxMimeFieldLength > 0)
4083 MaxMimeFieldLength++;
4086 case O_CONTROLSOCKET:
4087 PSTRSET(ControlSocketName, val);
4091 MaxHeadersLength = atoi(val);
4093 if (MaxHeadersLength > 0 &&
4094 MaxHeadersLength < (MAXHDRSLEN / 2))
4095 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4096 "Warning: MaxHeadersLength: headers length limit set lower than %d\n",
4100 case O_PROCTITLEPREFIX:
4101 PSTRSET(ProcTitlePrefix, val);
4106 # if _FFR_ALLOW_SASLINFO
4108 ** Allow users to select their own authinfo file
4109 ** under certain circumstances, otherwise just ignore
4110 ** the option. If the option isn't ignored, several
4111 ** commands don't work very well, e.g., mailq.
4112 ** However, this is not a "perfect" solution.
4113 ** If mail is queued, the authentication info
4114 ** will not be used in subsequent delivery attempts.
4115 ** If we really want to support this, then it has
4116 ** to be stored in the queue file.
4118 if (!bitset(SUBMIT_MSA, SubmitMode) && RealUid != 0 &&
4119 RunAsUid != RealUid)
4121 # endif /* _FFR_ALLOW_SASLINFO */
4122 PSTRSET(SASLInfo, val);
4126 if (AuthMechanisms != NULL)
4127 sm_free(AuthMechanisms); /* XXX */
4129 AuthMechanisms = newstr(val);
4131 AuthMechanisms = NULL;
4135 if (AuthRealm != NULL)
4138 AuthRealm = newstr(val);
4144 while (val != NULL && *val != '\0')
4149 SASLOpts |= SASL_AUTH_AUTH;
4153 SASLOpts |= SASL_SEC_NOACTIVE;
4157 SASLOpts |= SASL_SEC_PASS_CREDENTIALS;
4161 SASLOpts |= SASL_SEC_NODICTIONARY;
4165 SASLOpts |= SASL_SEC_FORWARD_SECRECY;
4170 SASLOpts |= SASL_SEC_MUTUAL_AUTH;
4172 # endif /* SASL >= 20101 */
4175 SASLOpts |= SASL_SEC_NOPLAINTEXT;
4179 SASLOpts |= SASL_SEC_NOANONYMOUS;
4182 case ' ': /* ignore */
4183 case '\t': /* ignore */
4184 case ',': /* ignore */
4188 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4189 "Warning: Option: %s unknown parameter '%c'\n",
4197 val = strpbrk(val, ", \t");
4204 MaxSLBits = atoi(val);
4213 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4214 "Warning: Option: %s requires SASL support (-DSASL)\n",
4221 SET_STRING_EXP(SrvCertFile);
4223 SET_STRING_EXP(SrvKeyFile);
4225 SET_STRING_EXP(CltCertFile);
4227 SET_STRING_EXP(CltKeyFile);
4229 SET_STRING_EXP(CACertFile);
4231 SET_STRING_EXP(CACertPath);
4233 SET_STRING_EXP(DHParams);
4235 SET_STRING_EXP(CipherList);
4237 SET_STRING_EXP(CertFingerprintAlgorithm);
4238 case O_SRV_SSL_OPTIONS:
4239 pssloptions = &Srv_SSL_Options;
4240 case O_CLT_SSL_OPTIONS:
4241 if (pssloptions == NULL)
4242 pssloptions = &Clt_SSL_Options;
4243 (void) readssloptions(o->o_name, val, pssloptions, '\0');
4245 sm_dprintf("ssloptions=%#lx\n", *pssloptions);
4251 # if OPENSSL_VERSION_NUMBER > 0x00907000L
4252 SET_STRING_EXP(CRLFile);
4253 # else /* OPENSSL_VERSION_NUMBER > 0x00907000L */
4254 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4255 "Warning: Option: %s requires at least OpenSSL 0.9.7\n",
4258 # endif /* OPENSSL_VERSION_NUMBER > 0x00907000L */
4262 # if OPENSSL_VERSION_NUMBER > 0x00907000L
4263 SET_STRING_EXP(CRLPath);
4264 # else /* OPENSSL_VERSION_NUMBER > 0x00907000L */
4265 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4266 "Warning: Option: %s requires at least OpenSSL 0.9.7\n",
4269 # endif /* OPENSSL_VERSION_NUMBER > 0x00907000L */
4270 # endif /* _FFR_CRLPATH */
4273 ** XXX How about options per daemon/client instead of globally?
4274 ** This doesn't work well for some options, e.g., no server cert,
4275 ** but fine for others.
4277 ** XXX Some people may want different certs per server.
4279 ** See also srvfeatures()
4282 case O_TLS_SRV_OPTS:
4283 while (val != NULL && *val != '\0')
4288 TLS_Srv_Opts |= TLS_I_NO_VRFY;
4291 ** Server without a cert? That works only if
4292 ** AnonDH is enabled as cipher, which is not in the
4293 ** default list. Hence the CipherList option must
4294 ** be available. Moreover: which clients support this
4295 ** besides sendmail with this setting?
4299 TLS_Srv_Opts &= ~TLS_I_SRV_CERT;
4301 case ' ': /* ignore */
4302 case '\t': /* ignore */
4303 case ',': /* ignore */
4306 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4307 "Warning: Option: %s unknown parameter '%c'\n",
4315 val = strpbrk(val, ", \t");
4322 PSTRSET(RandFile, val);
4325 #else /* STARTTLS */
4333 case O_SRV_SSL_OPTIONS:
4334 case O_CLT_SSL_OPTIONS:
4339 # endif /* _FFR_CRLPATH */
4341 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4342 "Warning: Option: %s requires TLS support\n",
4346 #endif /* STARTTLS */
4347 #if STARTTLS && _FFR_FIPSMODE
4349 FipsMode = atobool(val);
4351 #endif /* STARTTLS && _FFR_FIPSMODE */
4354 setclientoptions(val);
4358 DataFileBufferSize = atoi(val);
4362 XscriptFileBufferSize = atoi(val);
4365 case O_LDAPDEFAULTSPEC:
4367 ldapmap_set_defaults(val);
4369 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4370 "Warning: Option: %s requires LDAP support (-DLDAPMAP)\n",
4372 #endif /* LDAPMAP */
4377 InputFilterList = newstr(val);
4379 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4380 "Warning: Option: %s requires Milter support (-DMILTER)\n",
4387 milter_set_option(subopt, val, sticky);
4389 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4390 "Warning: Option: %s requires Milter support (-DMILTER)\n",
4395 case O_QUEUE_FILE_MODE: /* queue file mode */
4396 QueueFileMode = atooct(val) & 0777;
4399 case O_DLVR_MIN: /* deliver by minimum time */
4400 DeliverByMin = convtime(val, 's');
4403 /* modifiers {daemon_flags} for direct submissions */
4404 case O_DIRECTSUBMODIFIERS:
4406 BITMAP256 m; /* ignored */
4407 extern ENVELOPE BlankEnvelope;
4409 macdefine(&BlankEnvelope.e_macro, A_PERM,
4410 macid("{daemon_flags}"),
4411 getmodifiers(val, m));
4416 FastSplit = atoi(val);
4424 UseMSP = atobool(val);
4428 SoftBounce = atobool(val);
4431 case O_REJECTLOGINTERVAL: /* time btwn log msgs while refusing */
4432 RejectLogInterval = convtime(val, 'h');
4435 case O_REQUIRES_DIR_FSYNC:
4436 #if REQUIRES_DIR_FSYNC
4437 RequiresDirfsync = atobool(val);
4438 #else /* REQUIRES_DIR_FSYNC */
4439 /* silently ignored... required for cf file option */
4440 #endif /* REQUIRES_DIR_FSYNC */
4443 case O_CONNECTION_RATE_WINDOW_SIZE:
4444 ConnectionRateWindowSize = convtime(val, 's');
4447 case O_FALLBACKSMARTHOST: /* fallback smart host */
4449 FallbackSmartHost = newstr(val);
4453 HeloName = newstr(val);
4457 case O_REFUSELOWMEM:
4458 RefuseLowMem = atoi(val);
4461 QueueLowMem = atoi(val);
4464 MemoryResource = newstr(val);
4466 #endif /* _FFR_MEMSTAT */
4468 case O_MAXNOOPCOMMANDS:
4469 MaxNOOPCommands = atoi(val);
4474 MessageAccept = newstr(val);
4476 #endif /* _FFR_MSG_ACCEPT */
4478 #if _FFR_QUEUE_RUN_PARANOIA
4479 case O_CHK_Q_RUNNERS:
4480 CheckQueueRunners = atoi(val);
4482 #endif /* _FFR_QUEUE_RUN_PARANOIA */
4484 #if _FFR_EIGHT_BIT_ADDR_OK
4485 case O_EIGHT_BIT_ADDR_OK:
4486 EightBitAddrOK = atobool(val);
4488 #endif /* _FFR_EIGHT_BIT_ADDR_OK */
4490 #if _FFR_ADDR_TYPE_MODES
4491 case O_ADDR_TYPE_MODES:
4492 AddrTypeModes = atobool(val);
4494 #endif /* _FFR_ADDR_TYPE_MODES */
4496 #if _FFR_BADRCPT_SHUTDOWN
4498 BadRcptShutdown = atoi(val);
4502 BadRcptShutdownGood = atoi(val);
4504 #endif /* _FFR_BADRCPT_SHUTDOWN */
4506 #if _FFR_REJECT_NUL_BYTE
4508 RejectNUL = atobool(val);
4510 #endif /* _FFR_REJECT_NUL_BYTE */
4512 #if _FFR_BOUNCE_QUEUE
4514 bouncequeue = newstr(val);
4516 #endif /* _FFR_BOUNCE_QUEUE */
4520 AddBcc = atobool(val);
4523 case O_USECOMPRESSEDIPV6ADDRESSES:
4524 UseCompressedIPv6Addresses = atobool(val);
4530 if (isascii(opt) && isprint(opt))
4531 sm_dprintf("Warning: option %c unknown\n", opt);
4533 sm_dprintf("Warning: option 0x%x unknown\n", opt);
4539 ** Options with suboptions are responsible for taking care
4540 ** of sticky-ness (e.g., that a command line setting is kept
4541 ** when reading in the sendmail.cf file). This has to be done
4542 ** when the suboptions are parsed since each suboption must be
4543 ** sticky, not the root option.
4546 if (sticky && !bitset(OI_SUBOPT, o->o_flags))
4547 setbitn(opt, StickyOpt);
4550 ** SETCLASS -- set a string into a class
4553 ** class -- the class to put the string in.
4554 ** str -- the string to enter
4560 ** puts the word into the symbol table.
4564 setclass(class, str)
4570 if ((str[0] & 0377) == MATCHCLASS)
4580 sm_dprintf("setclass(%s, $=%s)\n",
4581 macname(class), macname(mid));
4582 copy_class(mid, class);
4587 sm_dprintf("setclass(%s, %s)\n", macname(class), str);
4589 s = stab(str, ST_CLASS, ST_ENTER);
4590 setbitn(bitidx(class), s->s_class);
4594 ** MAKEMAPENTRY -- create a map entry
4597 ** line -- the config file line
4600 ** A pointer to the map that has been created.
4601 ** NULL if there was a syntax error.
4604 ** Enters the map into the dictionary.
4617 for (p = line; isascii(*p) && isspace(*p); p++)
4619 if (!(isascii(*p) && isalnum(*p)))
4621 syserr("readcf: config K line: no map name");
4626 while ((isascii(*++p) && isalnum(*p)) || *p == '_' || *p == '.')
4630 while (isascii(*p) && isspace(*p))
4632 if (!(isascii(*p) && isalnum(*p)))
4634 syserr("readcf: config K line, map %s: no map class", mapname);
4638 while (isascii(*++p) && isalnum(*p))
4642 while (isascii(*p) && isspace(*p))
4645 /* look up the class */
4646 class = stab(classname, ST_MAPCLASS, ST_FIND);
4649 syserr("readcf: map %s: class %s not available", mapname,
4655 s = stab(mapname, ST_MAP, ST_ENTER);
4656 s->s_map.map_class = &class->s_mapclass;
4657 s->s_map.map_mname = newstr(mapname);
4659 if (class->s_mapclass.map_parse(&s->s_map, p))
4660 s->s_map.map_mflags |= MF_VALID;
4664 sm_dprintf("map %s, class %s, flags %lx, file %s,\n",
4665 s->s_map.map_mname, s->s_map.map_class->map_cname,
4666 s->s_map.map_mflags, s->s_map.map_file);
4667 sm_dprintf("\tapp %s, domain %s, rebuild %s\n",
4668 s->s_map.map_app, s->s_map.map_domain,
4669 s->s_map.map_rebuild);
4674 ** STRTORWSET -- convert string to rewriting set number
4677 ** p -- the pointer to the string to decode.
4678 ** endp -- if set, store the trailing delimiter here.
4679 ** stabmode -- ST_ENTER to create this entry, ST_FIND if
4680 ** it must already exist.
4683 ** The appropriate ruleset number.
4684 ** -1 if it is not valid (error already printed)
4688 strtorwset(p, endp, stabmode)
4694 static int nextruleset = MAXRWSETS;
4696 while (isascii(*p) && isspace(*p))
4700 syserr("invalid ruleset name: \"%.20s\"", p);
4705 ruleset = strtol(p, endp, 10);
4706 if (ruleset >= MAXRWSETS / 2 || ruleset < 0)
4708 syserr("bad ruleset %d (%d max)",
4709 ruleset, MAXRWSETS / 2);
4720 while (*p != '\0' && isascii(*p) && (isalnum(*p) || *p == '_'))
4722 if (q == p || !(isascii(*q) && isalpha(*q)))
4724 /* no valid characters */
4725 syserr("invalid ruleset name: \"%.20s\"", q);
4728 while (isascii(*p) && isspace(*p))
4733 s = stab(q, ST_RULESET, stabmode);
4740 if (stabmode == ST_ENTER && delim == '=')
4742 while (isascii(*++p) && isspace(*p))
4744 if (!(isascii(*p) && isdigit(*p)))
4746 syserr("bad ruleset definition \"%s\" (number required after `=')", q);
4751 ruleset = strtol(p, endp, 10);
4752 if (ruleset >= MAXRWSETS / 2 || ruleset < 0)
4754 syserr("bad ruleset number %d in \"%s\" (%d max)",
4755 ruleset, q, MAXRWSETS / 2);
4764 if (s->s_ruleset >= 0)
4765 ruleset = s->s_ruleset;
4766 else if ((ruleset = --nextruleset) < MAXRWSETS / 2)
4768 syserr("%s: too many named rulesets (%d max)",
4773 if (s->s_ruleset >= 0 &&
4775 ruleset != s->s_ruleset)
4777 syserr("%s: ruleset changed value (old %d, new %d)",
4778 q, s->s_ruleset, ruleset);
4779 ruleset = s->s_ruleset;
4781 else if (ruleset >= 0)
4783 s->s_ruleset = ruleset;
4785 if (stabmode == ST_ENTER && ruleset >= 0)
4789 if (RuleSetNames[ruleset] != NULL)
4790 sm_free(RuleSetNames[ruleset]); /* XXX */
4791 if (delim != '\0' && (h = strchr(q, delim)) != NULL)
4793 RuleSetNames[ruleset] = newstr(q);
4794 if (delim == '/' && h != NULL)
4795 *h = delim; /* put back delim */
4801 ** SETTIMEOUT -- set an individual timeout
4804 ** name -- the name of the timeout.
4805 ** val -- the value of the timeout.
4806 ** sticky -- if set, don't let other setoptions override
4813 /* set if Timeout sub-option is stuck */
4814 static BITMAP256 StickyTimeoutOpt;
4816 static struct timeoutinfo
4818 char *to_name; /* long name of timeout */
4819 unsigned char to_code; /* code for option */
4822 #define TO_INITIAL 0x01
4823 { "initial", TO_INITIAL },
4824 #define TO_MAIL 0x02
4825 { "mail", TO_MAIL },
4826 #define TO_RCPT 0x03
4827 { "rcpt", TO_RCPT },
4828 #define TO_DATAINIT 0x04
4829 { "datainit", TO_DATAINIT },
4830 #define TO_DATABLOCK 0x05
4831 { "datablock", TO_DATABLOCK },
4832 #define TO_DATAFINAL 0x06
4833 { "datafinal", TO_DATAFINAL },
4834 #define TO_COMMAND 0x07
4835 { "command", TO_COMMAND },
4836 #define TO_RSET 0x08
4837 { "rset", TO_RSET },
4838 #define TO_HELO 0x09
4839 { "helo", TO_HELO },
4840 #define TO_QUIT 0x0A
4841 { "quit", TO_QUIT },
4842 #define TO_MISC 0x0B
4843 { "misc", TO_MISC },
4844 #define TO_IDENT 0x0C
4845 { "ident", TO_IDENT },
4846 #define TO_FILEOPEN 0x0D
4847 { "fileopen", TO_FILEOPEN },
4848 #define TO_CONNECT 0x0E
4849 { "connect", TO_CONNECT },
4850 #define TO_ICONNECT 0x0F
4851 { "iconnect", TO_ICONNECT },
4852 #define TO_QUEUEWARN 0x10
4853 { "queuewarn", TO_QUEUEWARN },
4854 { "queuewarn.*", TO_QUEUEWARN },
4855 #define TO_QUEUEWARN_NORMAL 0x11
4856 { "queuewarn.normal", TO_QUEUEWARN_NORMAL },
4857 #define TO_QUEUEWARN_URGENT 0x12
4858 { "queuewarn.urgent", TO_QUEUEWARN_URGENT },
4859 #define TO_QUEUEWARN_NON_URGENT 0x13
4860 { "queuewarn.non-urgent", TO_QUEUEWARN_NON_URGENT },
4861 #define TO_QUEUERETURN 0x14
4862 { "queuereturn", TO_QUEUERETURN },
4863 { "queuereturn.*", TO_QUEUERETURN },
4864 #define TO_QUEUERETURN_NORMAL 0x15
4865 { "queuereturn.normal", TO_QUEUERETURN_NORMAL },
4866 #define TO_QUEUERETURN_URGENT 0x16
4867 { "queuereturn.urgent", TO_QUEUERETURN_URGENT },
4868 #define TO_QUEUERETURN_NON_URGENT 0x17
4869 { "queuereturn.non-urgent", TO_QUEUERETURN_NON_URGENT },
4870 #define TO_HOSTSTATUS 0x18
4871 { "hoststatus", TO_HOSTSTATUS },
4872 #define TO_RESOLVER_RETRANS 0x19
4873 { "resolver.retrans", TO_RESOLVER_RETRANS },
4874 #define TO_RESOLVER_RETRANS_NORMAL 0x1A
4875 { "resolver.retrans.normal", TO_RESOLVER_RETRANS_NORMAL },
4876 #define TO_RESOLVER_RETRANS_FIRST 0x1B
4877 { "resolver.retrans.first", TO_RESOLVER_RETRANS_FIRST },
4878 #define TO_RESOLVER_RETRY 0x1C
4879 { "resolver.retry", TO_RESOLVER_RETRY },
4880 #define TO_RESOLVER_RETRY_NORMAL 0x1D
4881 { "resolver.retry.normal", TO_RESOLVER_RETRY_NORMAL },
4882 #define TO_RESOLVER_RETRY_FIRST 0x1E
4883 { "resolver.retry.first", TO_RESOLVER_RETRY_FIRST },
4884 #define TO_CONTROL 0x1F
4885 { "control", TO_CONTROL },
4886 #define TO_LHLO 0x20
4887 { "lhlo", TO_LHLO },
4888 #define TO_AUTH 0x21
4889 { "auth", TO_AUTH },
4890 #define TO_STARTTLS 0x22
4891 { "starttls", TO_STARTTLS },
4892 #define TO_ACONNECT 0x23
4893 { "aconnect", TO_ACONNECT },
4894 #define TO_QUEUEWARN_DSN 0x24
4895 { "queuewarn.dsn", TO_QUEUEWARN_DSN },
4896 #define TO_QUEUERETURN_DSN 0x25
4897 { "queuereturn.dsn", TO_QUEUERETURN_DSN },
4903 settimeout(name, val, sticky)
4908 register struct timeoutinfo *to;
4913 sm_dprintf("settimeout(%s = %s)", name, val);
4915 for (to = TimeOutTab; to->to_name != NULL; to++)
4917 if (sm_strcasecmp(to->to_name, name) == 0)
4921 if (to->to_name == NULL)
4923 errno = 0; /* avoid bogus error text */
4924 syserr("settimeout: invalid timeout %s", name);
4929 ** See if this option is preset for us.
4932 if (!sticky && bitnset(to->to_code, StickyTimeoutOpt))
4935 sm_dprintf(" (ignored)\n");
4942 toval = convtime(val, 'm');
4945 switch (to->to_code)
4948 TimeOuts.to_initial = toval;
4952 TimeOuts.to_mail = toval;
4956 TimeOuts.to_rcpt = toval;
4960 TimeOuts.to_datainit = toval;
4964 TimeOuts.to_datablock = toval;
4968 TimeOuts.to_datafinal = toval;
4972 TimeOuts.to_nextcommand = toval;
4976 TimeOuts.to_rset = toval;
4980 TimeOuts.to_helo = toval;
4984 TimeOuts.to_quit = toval;
4988 TimeOuts.to_miscshort = toval;
4992 TimeOuts.to_ident = toval;
4996 TimeOuts.to_fileopen = toval;
5000 TimeOuts.to_connect = toval;
5004 TimeOuts.to_iconnect = toval;
5008 TimeOuts.to_aconnect = toval;
5012 toval = convtime(val, 'h');
5013 TimeOuts.to_q_warning[TOC_NORMAL] = toval;
5014 TimeOuts.to_q_warning[TOC_URGENT] = toval;
5015 TimeOuts.to_q_warning[TOC_NONURGENT] = toval;
5016 TimeOuts.to_q_warning[TOC_DSN] = toval;
5020 case TO_QUEUEWARN_NORMAL:
5021 toval = convtime(val, 'h');
5022 TimeOuts.to_q_warning[TOC_NORMAL] = toval;
5025 case TO_QUEUEWARN_URGENT:
5026 toval = convtime(val, 'h');
5027 TimeOuts.to_q_warning[TOC_URGENT] = toval;
5030 case TO_QUEUEWARN_NON_URGENT:
5031 toval = convtime(val, 'h');
5032 TimeOuts.to_q_warning[TOC_NONURGENT] = toval;
5035 case TO_QUEUEWARN_DSN:
5036 toval = convtime(val, 'h');
5037 TimeOuts.to_q_warning[TOC_DSN] = toval;
5040 case TO_QUEUERETURN:
5041 toval = convtime(val, 'd');
5042 TimeOuts.to_q_return[TOC_NORMAL] = toval;
5043 TimeOuts.to_q_return[TOC_URGENT] = toval;
5044 TimeOuts.to_q_return[TOC_NONURGENT] = toval;
5045 TimeOuts.to_q_return[TOC_DSN] = toval;
5049 case TO_QUEUERETURN_NORMAL:
5050 toval = convtime(val, 'd');
5051 TimeOuts.to_q_return[TOC_NORMAL] = toval;
5054 case TO_QUEUERETURN_URGENT:
5055 toval = convtime(val, 'd');
5056 TimeOuts.to_q_return[TOC_URGENT] = toval;
5059 case TO_QUEUERETURN_NON_URGENT:
5060 toval = convtime(val, 'd');
5061 TimeOuts.to_q_return[TOC_NONURGENT] = toval;
5064 case TO_QUEUERETURN_DSN:
5065 toval = convtime(val, 'd');
5066 TimeOuts.to_q_return[TOC_DSN] = toval;
5070 MciInfoTimeout = toval;
5073 case TO_RESOLVER_RETRANS:
5074 toval = convtime(val, 's');
5075 TimeOuts.res_retrans[RES_TO_DEFAULT] = toval;
5076 TimeOuts.res_retrans[RES_TO_FIRST] = toval;
5077 TimeOuts.res_retrans[RES_TO_NORMAL] = toval;
5081 case TO_RESOLVER_RETRY:
5083 TimeOuts.res_retry[RES_TO_DEFAULT] = i;
5084 TimeOuts.res_retry[RES_TO_FIRST] = i;
5085 TimeOuts.res_retry[RES_TO_NORMAL] = i;
5089 case TO_RESOLVER_RETRANS_NORMAL:
5090 TimeOuts.res_retrans[RES_TO_NORMAL] = convtime(val, 's');
5093 case TO_RESOLVER_RETRY_NORMAL:
5094 TimeOuts.res_retry[RES_TO_NORMAL] = atoi(val);
5097 case TO_RESOLVER_RETRANS_FIRST:
5098 TimeOuts.res_retrans[RES_TO_FIRST] = convtime(val, 's');
5101 case TO_RESOLVER_RETRY_FIRST:
5102 TimeOuts.res_retry[RES_TO_FIRST] = atoi(val);
5106 TimeOuts.to_control = toval;
5110 TimeOuts.to_lhlo = toval;
5115 TimeOuts.to_auth = toval;
5121 TimeOuts.to_starttls = toval;
5123 #endif /* STARTTLS */
5126 syserr("settimeout: invalid timeout %s", name);
5132 for (i = 0; i <= addopts; i++)
5133 setbitn(to->to_code + i, StickyTimeoutOpt);
5137 ** INITTIMEOUTS -- parse and set timeout values
5140 ** val -- a pointer to the values. If NULL, do initial
5142 ** sticky -- if set, don't let other setoptions override
5143 ** this suboption value.
5149 ** Initializes the TimeOuts structure
5153 inittimeouts(val, sticky)
5160 sm_dprintf("inittimeouts(%s)\n", val == NULL ? "<NULL>" : val);
5163 TimeOuts.to_connect = (time_t) 0 SECONDS;
5164 TimeOuts.to_aconnect = (time_t) 0 SECONDS;
5165 TimeOuts.to_iconnect = (time_t) 0 SECONDS;
5166 TimeOuts.to_initial = (time_t) 5 MINUTES;
5167 TimeOuts.to_helo = (time_t) 5 MINUTES;
5168 TimeOuts.to_mail = (time_t) 10 MINUTES;
5169 TimeOuts.to_rcpt = (time_t) 1 HOUR;
5170 TimeOuts.to_datainit = (time_t) 5 MINUTES;
5171 TimeOuts.to_datablock = (time_t) 1 HOUR;
5172 TimeOuts.to_datafinal = (time_t) 1 HOUR;
5173 TimeOuts.to_rset = (time_t) 5 MINUTES;
5174 TimeOuts.to_quit = (time_t) 2 MINUTES;
5175 TimeOuts.to_nextcommand = (time_t) 1 HOUR;
5176 TimeOuts.to_miscshort = (time_t) 2 MINUTES;
5178 TimeOuts.to_ident = (time_t) 5 SECONDS;
5179 #else /* IDENTPROTO */
5180 TimeOuts.to_ident = (time_t) 0 SECONDS;
5181 #endif /* IDENTPROTO */
5182 TimeOuts.to_fileopen = (time_t) 60 SECONDS;
5183 TimeOuts.to_control = (time_t) 2 MINUTES;
5184 TimeOuts.to_lhlo = (time_t) 2 MINUTES;
5186 TimeOuts.to_auth = (time_t) 10 MINUTES;
5189 TimeOuts.to_starttls = (time_t) 1 HOUR;
5190 #endif /* STARTTLS */
5193 sm_dprintf("Timeouts:\n");
5194 sm_dprintf(" connect = %ld\n",
5195 (long) TimeOuts.to_connect);
5196 sm_dprintf(" aconnect = %ld\n",
5197 (long) TimeOuts.to_aconnect);
5198 sm_dprintf(" initial = %ld\n",
5199 (long) TimeOuts.to_initial);
5200 sm_dprintf(" helo = %ld\n", (long) TimeOuts.to_helo);
5201 sm_dprintf(" mail = %ld\n", (long) TimeOuts.to_mail);
5202 sm_dprintf(" rcpt = %ld\n", (long) TimeOuts.to_rcpt);
5203 sm_dprintf(" datainit = %ld\n",
5204 (long) TimeOuts.to_datainit);
5205 sm_dprintf(" datablock = %ld\n",
5206 (long) TimeOuts.to_datablock);
5207 sm_dprintf(" datafinal = %ld\n",
5208 (long) TimeOuts.to_datafinal);
5209 sm_dprintf(" rset = %ld\n", (long) TimeOuts.to_rset);
5210 sm_dprintf(" quit = %ld\n", (long) TimeOuts.to_quit);
5211 sm_dprintf(" nextcommand = %ld\n",
5212 (long) TimeOuts.to_nextcommand);
5213 sm_dprintf(" miscshort = %ld\n",
5214 (long) TimeOuts.to_miscshort);
5215 sm_dprintf(" ident = %ld\n", (long) TimeOuts.to_ident);
5216 sm_dprintf(" fileopen = %ld\n",
5217 (long) TimeOuts.to_fileopen);
5218 sm_dprintf(" lhlo = %ld\n",
5219 (long) TimeOuts.to_lhlo);
5220 sm_dprintf(" control = %ld\n",
5221 (long) TimeOuts.to_control);
5228 while (isascii(*val) && isspace(*val))
5232 for (p = val; *p != '\0' && *p != ','; p++)
5237 if (isascii(*val) && isdigit(*val))
5239 /* old syntax -- set everything */
5240 TimeOuts.to_mail = convtime(val, 'm');
5241 TimeOuts.to_rcpt = TimeOuts.to_mail;
5242 TimeOuts.to_datainit = TimeOuts.to_mail;
5243 TimeOuts.to_datablock = TimeOuts.to_mail;
5244 TimeOuts.to_datafinal = TimeOuts.to_mail;
5245 TimeOuts.to_nextcommand = TimeOuts.to_mail;
5248 setbitn(TO_MAIL, StickyTimeoutOpt);
5249 setbitn(TO_RCPT, StickyTimeoutOpt);
5250 setbitn(TO_DATAINIT, StickyTimeoutOpt);
5251 setbitn(TO_DATABLOCK, StickyTimeoutOpt);
5252 setbitn(TO_DATAFINAL, StickyTimeoutOpt);
5253 setbitn(TO_COMMAND, StickyTimeoutOpt);
5259 register char *q = strchr(val, ':');
5261 if (q == NULL && (q = strchr(val, '=')) == NULL)
5267 settimeout(val, q, sticky);