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[];
163 Srv_SSL_Options = SSL_OP_ALL;
164 Clt_SSL_Options = SSL_OP_ALL
165 # ifdef SSL_OP_NO_SSLv2
168 # ifdef SSL_OP_NO_TICKET
172 # ifdef SSL_OP_TLSEXT_PADDING
173 /* SSL_OP_TLSEXT_PADDING breaks compatibility with some sites */
174 Srv_SSL_Options &= ~SSL_OP_TLSEXT_PADDING;
175 Clt_SSL_Options &= ~SSL_OP_TLSEXT_PADDING;
176 # endif /* SSL_OP_TLSEXT_PADDING */
177 #endif /* STARTTLS */
178 if (DontLockReadFiles)
180 cf = safefopen(cfname, O_RDONLY, 0444, sff);
183 syserr("cannot open");
184 finis(false, true, EX_OSFILE);
187 if (fstat(sm_io_getinfo(cf, SM_IO_WHAT_FD, NULL), &statb) < 0)
189 syserr("cannot fstat");
190 finis(false, true, EX_OSFILE);
193 if (!S_ISREG(statb.st_mode))
195 syserr("not a plain file");
196 finis(false, true, EX_OSFILE);
199 if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
201 if (OpMode == MD_DAEMON || OpMode == MD_INITALIAS || OpMode == MD_CHECKCONFIG)
202 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
203 "%s: WARNING: dangerous write permissions\n",
206 sm_syslog(LOG_CRIT, NOQID,
207 "%s: WARNING: dangerous write permissions",
215 while (bufsize = sizeof(buf),
216 (bp = fgetfolded(buf, &bufsize, cf)) != NULL)
223 sm_free(bp); /* XXX */
227 /* do macro expansion mappings */
228 nbp = translate_dollars(bp, bp, &bufsize);
229 if (nbp != bp && bp != buf)
233 /* interpret this line */
238 case '#': /* comment */
241 case 'R': /* rewriting rule */
244 syserr("missing valid ruleset for \"%s\"", bp);
247 for (p = &bp[1]; *p != '\0' && *p != '\t'; p++)
252 syserr("invalid rewrite line \"%s\" (tab expected)", bp);
256 /* allocate space for the rule header */
259 RewriteRules[ruleset] = rwp =
260 (struct rewrite *) xalloc(sizeof(*rwp));
264 rwp->r_next = (struct rewrite *) xalloc(sizeof(*rwp));
269 /* expand and save the LHS */
271 expand(&bp[1], exbuf, sizeof(exbuf), e);
272 rwp->r_lhs = prescan(exbuf, '\t', pvpbuf,
273 sizeof(pvpbuf), NULL,
274 ConfigLevel >= 9 ? TokTypeNoC : IntTokenTab,
277 if (rwp->r_lhs != NULL)
281 rwp->r_lhs = copyplist(rwp->r_lhs, true, NULL);
283 /* count the number of fuzzy matches in LHS */
284 for (ap = rwp->r_lhs; *ap != NULL; ap++)
289 switch (ap[0][0] & 0377)
336 syserr("Inappropriate use of %s on LHS",
339 rwp->r_line = LineNumber;
343 syserr("R line: null LHS");
344 rwp->r_lhs = null_list;
346 if (nfuzzy > MAXMATCH)
348 syserr("R line: too many wildcards");
349 rwp->r_lhs = null_list;
352 /* expand and save the RHS */
356 while (*p != '\0' && *p != '\t')
359 expand(q, exbuf, sizeof(exbuf), e);
360 rwp->r_rhs = prescan(exbuf, '\t', pvpbuf,
361 sizeof(pvpbuf), NULL,
362 ConfigLevel >= 9 ? TokTypeNoC : IntTokenTab,
364 if (rwp->r_rhs != NULL)
368 #if _FFR_EXTRA_MAP_CHECK
370 #endif /* _FFR_EXTRA_MAP_CHECK */
373 rwp->r_rhs = copyplist(rwp->r_rhs, true, NULL);
375 /* check no out-of-bounds replacements */
380 for (ap = rwp->r_rhs; *ap != NULL; ap++)
385 switch (ap[0][0] & 0377)
388 if (ap[0][1] <= '0' ||
391 syserr("replacement $%c out of bounds",
419 if (++args >= MAX_MAP_ARGS)
420 syserr("too many arguments for map lookup");
428 if ((ap[0][0] & 0377) == LOOKUPBEGIN)
429 endtoken = LOOKUPEND;
431 syserr("cannot nest map lookups");
434 #if _FFR_EXTRA_MAP_CHECK
437 syserr("syntax error in map lookup");
440 nexttoken = ap[1][0] & 0377;
441 if (nexttoken == CANONHOST ||
442 nexttoken == CANONUSER ||
443 nexttoken == endtoken))
445 syserr("missing map name for lookup");
450 syserr("syntax error in map lookup");
453 if (ap[0][0] == HOSTBEGIN)
455 nexttoken = ap[2][0] & 0377;
456 if (nexttoken == CANONHOST ||
457 nexttoken == CANONUSER ||
458 nexttoken == endtoken)
460 syserr("missing key name for lookup");
463 #endif /* _FFR_EXTRA_MAP_CHECK */
468 if ((ap[0][0] & 0377) != endtoken)
477 ** This doesn't work yet as there are maps defined *after* the cf
478 ** is read such as host, user, and alias. So for now, it's removed.
479 ** When it comes back, the RELEASE_NOTES entry will be:
480 ** Emit warnings for unknown maps when reading the .cf file. Based on
481 ** patch from Robert Harker of Harker Systems.
486 ** Got a database lookup,
487 ** check if map is defined.
491 if ((ep[0] & 0377) != MACRODEXPAND &&
492 stab(ep, ST_MAP, ST_FIND) == NULL)
494 (void) sm_io_fprintf(smioout,
496 "Warning: %s: line %d: map %s not found\n",
505 syserr("Inappropriate use of %s on RHS",
509 syserr("missing map closing token");
513 syserr("R line: null RHS");
514 rwp->r_rhs = null_list;
518 case 'S': /* select rewriting set */
519 expand(&bp[1], exbuf, sizeof(exbuf), e);
520 ruleset = strtorwset(exbuf, NULL, ST_ENTER);
524 rwp = RewriteRules[ruleset];
527 if (OpMode == MD_TEST || OpMode == MD_CHECKCONFIG)
528 (void) sm_io_fprintf(smioout,
530 "WARNING: Ruleset %s has multiple definitions\n",
533 sm_dprintf("WARNING: Ruleset %s has multiple definitions\n",
535 while (rwp->r_next != NULL)
540 case 'D': /* macro definition */
541 mid = macid_parse(&bp[1], &ep);
544 p = munchstring(ep, NULL, '\0');
545 macdefine(&e->e_macro, A_TEMP, mid, p);
548 case 'H': /* required header line */
549 (void) chompheader(&bp[1], CHHDR_DEF, NULL, e);
552 case 'C': /* word class */
553 case 'T': /* trusted user (set class `t') */
556 mid = macid_parse(&bp[1], &ep);
559 expand(ep, exbuf, sizeof(exbuf), e);
572 while (*p != '\0' && isascii(*p) && isspace(*p))
575 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
585 case 'F': /* word class from file */
586 mid = macid_parse(&bp[1], &ep);
589 for (p = ep; isascii(*p) && isspace(*p); )
591 if (p[0] == '-' && p[1] == 'o')
595 !(isascii(*p) && isspace(*p)))
597 while (isascii(*p) && isspace(*p))
603 /* check if [key]@map:spec */
605 if (!SM_IS_DIR_DELIM(*p) &&
607 (q = strchr(p, '@')) != NULL)
611 /* look for @LDAP or @map: in string */
612 if (strcmp(q, "LDAP") == 0 ||
614 strchr(q, ':') != NULL))
620 /* use entire spec */
625 file = extrquotstr(p, &q, " ", &ok);
628 syserr("illegal filename '%s'", p);
633 if (*file == '|' || ismap)
643 while (isascii(*++p) && isspace(*p))
647 fileclass(mid, file, p, ismap, safe, optional);
651 case 'L': /* extended load average description */
656 #if defined(SUN_EXTENSIONS) && defined(SUN_LOOKUP_MACRO)
657 case 'L': /* lookup macro */
658 case 'G': /* lookup class */
659 /* reserved for Sun -- NIS+ database lookup */
660 if (VendorCode != VENDOR_SUN)
662 sun_lg_config_line(bp, e);
664 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_LOOKUP_MACRO) */
666 case 'M': /* define mailer */
670 case 'O': /* set option */
671 setoption(bp[1], &bp[2], safe, false, e);
674 case 'P': /* set precedence */
675 if (NumPriorities >= MAXPRIORITIES)
677 toomany('P', MAXPRIORITIES);
680 for (p = &bp[1]; *p != '\0' && *p != '='; p++)
685 Priorities[NumPriorities].pri_name = newstr(&bp[1]);
686 Priorities[NumPriorities].pri_val = atoi(++p);
690 case 'Q': /* define queue */
691 makequeue(&bp[1], true);
694 case 'V': /* configuration syntax version */
695 for (p = &bp[1]; isascii(*p) && isspace(*p); p++)
697 if (!isascii(*p) || !isdigit(*p))
699 syserr("invalid argument to V line: \"%.20s\"",
703 ConfigLevel = strtol(p, &ep, 10);
706 ** Do heuristic tweaking for back compatibility.
709 if (ConfigLevel >= 5)
711 /* level 5 configs have short name in $w */
712 p = macvalue('w', e);
713 if (p != NULL && (p = strchr(p, '.')) != NULL)
716 macdefine(&e->e_macro, A_TEMP, 'w',
720 if (ConfigLevel >= 6)
722 ColonOkInAddr = false;
726 ** Look for vendor code.
731 /* extract vendor code */
732 for (p = ep; isascii(*p) && isalpha(*p); )
737 syserr("invalid V line vendor code: \"%s\"",
743 expand(&bp[1], exbuf, sizeof(exbuf), e);
744 (void) makemapentry(exbuf);
751 sm_setuserenv(&bp[1], p);
754 case 'X': /* mail filter */
756 milter_setup(&bp[1]);
758 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
759 "Warning: Filter usage ('X') requires Milter support (-DMILTER)\n");
765 syserr("unknown configuration line \"%s\"", bp);
768 sm_free(bp); /* XXX */
772 syserr("I/O read error");
773 finis(false, true, EX_OSFILE);
775 (void) sm_io_close(cf, SM_TIME_DEFAULT);
778 #if _FFR_BOUNCE_QUEUE
782 /* initialize host maps from local service tables */
785 /* initialize daemon (if not defined yet) */
788 /* determine if we need to do special name-server frotz */
791 char *maptype[MAXMAPSTACK];
792 short mapreturn[MAXMAPACTIONS];
794 nmaps = switch_map_find("hosts", maptype, mapreturn);
795 UseNameServer = false;
796 if (nmaps > 0 && nmaps <= MAXMAPSTACK)
800 for (mapno = 0; mapno < nmaps && !UseNameServer;
803 if (strcmp(maptype[mapno], "dns") == 0)
804 UseNameServer = true;
812 ** TRANSLATE_DOLLARS -- convert $x into internal form
814 ** Actually does all appropriate pre-processing of a config line
815 ** to turn it into internal form.
818 ** ibp -- the buffer to translate.
819 ** obp -- where to put the translation; may be the same as obp
820 ** bsp -- a pointer to the size of obp; will be updated if
821 ** the buffer needs to be replaced.
824 ** The buffer pointer; may differ from obp if the expansion
825 ** is larger then *bsp, in which case this will point to
826 ** malloc()ed memory which must be free()d by the caller.
830 translate_dollars(ibp, obp, bsp)
841 sm_dprintf("translate_dollars(");
842 xputs(sm_debug_file(), ibp);
846 bp = quote_internal_chars(ibp, obp, bsp);
848 for (p = bp; *p != '\0'; p++)
850 if (*p == '#' && p > bp && ConfigLevel >= 3)
857 /* it's from $# -- let it go through */
862 /* it's backslash escaped */
863 (void) sm_strlcpy(p, p + 1, strlen(p));
867 /* delete leading white space */
868 while (isascii(*p) && isspace(*p) &&
869 *p != '\n' && p > bp)
873 if ((e = strchr(++p, '\n')) != NULL)
874 (void) sm_strlcpy(p, e, strlen(p));
882 if (*p != '$' || p[1] == '\0')
887 /* actual dollar sign.... */
888 (void) sm_strlcpy(p, p + 1, strlen(p));
892 /* convert to macro expansion character */
895 /* special handling for $=, $~, $&, and $? */
896 if (*p == '=' || *p == '~' || *p == '&' || *p == '?')
899 /* convert macro name to code */
900 *p = macid_parse(p, &ep);
902 (void) sm_strlcpy(p + 1, ep, strlen(p + 1));
905 /* strip trailing white space from the line */
906 while (--p > bp && isascii(*p) && isspace(*p))
911 sm_dprintf(" translate_dollars => ");
912 xputs(sm_debug_file(), bp);
919 ** TOOMANY -- signal too many of some option
922 ** id -- the id of the error line
923 ** maxcnt -- the maximum possible values
937 syserr("too many %c lines, %d max", id, maxcnt);
940 ** FILECLASS -- read members of a class from a file
943 ** class -- class to define.
944 ** filename -- name of file to read.
945 ** fmt -- scanf string to use for match.
946 ** ismap -- if set, this is a map lookup.
947 ** safe -- if set, this is a safe read.
948 ** optional -- if set, it is not an error for the file to
955 ** puts all lines in filename that match a scanf into
960 ** Break up the match into words and add to class.
964 parse_class_words(class, line)
968 while (line != NULL && *line != '\0')
972 /* strip leading spaces */
973 while (isascii(*line) && isspace(*line))
978 /* find the end of the word */
980 while (*line != '\0' && !(isascii(*line) && isspace(*line)))
985 /* enter the word in the symbol table */
991 fileclass(class, filename, fmt, ismap, safe, optional)
1006 sm_dprintf("fileclass(%s, fmt=%s)\n", filename, fmt);
1008 if (*filename == '\0')
1010 syserr("fileclass: missing file name");
1022 mn = newstr(macname(class));
1027 if ((p = strchr(filename, '@')) == NULL)
1029 /* should not happen */
1030 syserr("fileclass: bogus map specification");
1040 if (strcmp(cl, "LDAP") == 0)
1044 char jbuf[MAXHOSTNAMELEN];
1045 char lcbuf[MAXLINE];
1048 expand("\201j", jbuf, sizeof(jbuf), &BlankEnvelope);
1049 if (jbuf[0] == '\0')
1051 (void) sm_strlcpy(jbuf, "localhost",
1055 /* impose the default schema */
1056 lc = macvalue(macid("{sendmailMTACluster}"), CurEnv);
1061 expand(lc, lcbuf, sizeof(lcbuf), CurEnv);
1066 n = sm_snprintf(buf, sizeof(buf),
1067 "-k (&(objectClass=sendmailMTAClass)(sendmailMTAClassName=%s)(|(sendmailMTACluster=%s)(sendmailMTAHost=%s))) -v sendmailMTAClassValue,sendmailMTAClassSearch:FILTER:sendmailMTAClass,sendmailMTAClassURL:URL:sendmailMTAClass",
1069 if (n >= sizeof(buf))
1071 syserr("fileclass: F{%s}: Default LDAP string too long",
1079 #endif /* LDAPMAP */
1081 if ((spec = strchr(cl, ':')) == NULL)
1083 syserr("fileclass: F{%s}: missing map class",
1091 /* set up map structure */
1092 mapclass = stab(cl, ST_MAPCLASS, ST_FIND);
1093 if (mapclass == NULL)
1095 syserr("fileclass: F{%s}: class %s not available",
1100 memset(&map, '\0', sizeof(map));
1101 map.map_class = &mapclass->s_mapclass;
1103 map.map_mflags |= MF_FILECLASS;
1106 sm_dprintf("fileclass: F{%s}: map class %s, key %s, spec %s\n",
1110 /* parse map spec */
1111 if (!map.map_class->map_parse(&map, spec))
1113 /* map_parse() showed the error already */
1117 map.map_mflags |= MF_VALID;
1120 if (map.map_class->map_open(&map, O_RDONLY))
1122 map.map_mflags |= MF_OPEN;
1123 map.map_pid = getpid();
1128 !bitset(MF_OPTIONAL, map.map_mflags))
1129 syserr("fileclass: F{%s}: map open failed",
1136 p = (*map.map_class->map_lookup)(&map, key, NULL, &status);
1137 if (status != EX_OK && status != EX_NOTFOUND)
1140 syserr("fileclass: F{%s}: map lookup failed",
1145 /* use the results */
1147 parse_class_words(class, p);
1150 map.map_mflags |= MF_CLOSING;
1151 map.map_class->map_close(&map);
1152 map.map_mflags &= ~(MF_OPEN|MF_WRITABLE|MF_CLOSING);
1156 else if (filename[0] == '|')
1160 char *argv[MAXPV + 1];
1163 for (p = strtok(&filename[1], " \t");
1164 p != NULL && i < MAXPV;
1165 p = strtok(NULL, " \t"))
1168 pid = prog_open(argv, &fd, CurEnv);
1172 f = sm_io_open(SmFtStdiofd, SM_TIME_DEFAULT,
1173 (void *) &fd, SM_IO_RDONLY, NULL);
1179 if (!bitnset(DBS_CLASSFILEINUNSAFEDIRPATH, DontBlameSendmail))
1180 sff |= SFF_SAFEDIRPATH;
1181 if (!bitnset(DBS_LINKEDCLASSFILEINWRITABLEDIR,
1185 sff |= SFF_OPENASROOT;
1186 else if (RealUid == 0)
1188 if (DontLockReadFiles)
1190 f = safefopen(filename, O_RDONLY, 0, sff);
1195 syserr("fileclass: cannot open '%s'", filename);
1199 while (sm_io_fgets(f, SM_TIME_DEFAULT, buf, sizeof(buf)) >= 0)
1202 char wordbuf[MAXLINE + 1];
1208 if (sm_io_sscanf(buf, fmt, wordbuf) != 1)
1215 parse_class_words(class, p);
1218 ** If anything else is added here,
1219 ** check if the '@' map case above
1220 ** needs the code as well.
1224 (void) sm_io_close(f, SM_TIME_DEFAULT);
1226 (void) waitfor(pid);
1230 /* first character for dynamically created mailers */
1231 static char dynmailerp = ' ';
1233 /* list of first characters for cf defined mailers */
1234 static char frst[MAXMAILERS + 1];
1237 ** SETUPDYNMAILERS -- find a char that isn't used as first element of any
1246 ** Note: space is not valid in cf defined mailers hence the function
1247 ** will always find a char. It's not nice, but this is for
1248 ** internal names only.
1255 char pp[] = "YXZ0123456789ABCDEFGHIJKLMNOPQRSTUVWyxzabcfghijkmnoqtuvw ";
1257 frst[MAXMAILERS] = '\0';
1258 for (i = 0; i < strlen(pp); i++)
1260 if (strchr(frst, pp[i]) == NULL)
1264 sm_dprintf("dynmailerp=%c\n", dynmailerp);
1274 ** NEWMODMAILER -- Create a new mailer with modifications
1277 ** rcpt -- current RCPT
1278 ** fl -- flag to set
1281 ** true iff successful.
1283 ** Note: this creates a copy of the mailer for the rcpt and
1284 ** modifies exactly one flag. It does not work
1285 ** for multiple flags!
1289 newmodmailer(rcpt, fl)
1298 SM_REQUIRE(rcpt != NULL);
1299 if (rcpt->q_mailer == NULL)
1302 sm_dprintf("newmodmailer: rcpt=%s\n", rcpt->q_paddr);
1303 SM_REQUIRE(rcpt->q_mailer->m_name != NULL);
1304 SM_REQUIRE(rcpt->q_mailer->m_name[0] != '\0');
1305 sm_strlcpy(mname, rcpt->q_mailer->m_name, sizeof(mname));
1306 mname[0] = dynmailerp;
1308 sm_dprintf("newmodmailer: name=%s\n", mname);
1309 s = stab(mname, ST_MAILER, ST_ENTER);
1310 if (s->s_mailer != NULL)
1312 idx = s->s_mailer->m_mno;
1314 sm_dprintf("newmodmailer: found idx=%d\n", idx);
1318 idx = rcpt->q_mailer->m_mno;
1321 sm_dprintf("newmodmailer: idx=%d\n", idx);
1322 if (idx > SM_ARRAY_SIZE(Mailer))
1328 m = (struct mailer *) xalloc(sizeof(*m));
1329 memset((char *) m, '\0', sizeof(*m));
1330 STRUCTCOPY(*rcpt->q_mailer, *m);
1333 /* "modify" the mailer */
1334 setbitn(bitidx(fl), m->m_flags);
1337 m->m_name = newstr(mname);
1339 sm_dprintf("newmodmailer: mailer[%d]=%s %p\n",
1340 idx, Mailer[idx]->m_name, Mailer[idx]);
1345 #endif /* _FFR_RCPTFLAGS */
1348 ** MAKEMAILER -- define a new mailer.
1351 ** line -- description of mailer. This is in labeled
1352 ** fields. The fields are:
1353 ** A -- the argv for this mailer
1354 ** C -- the character set for MIME conversions
1355 ** D -- the directory to run in
1356 ** E -- the eol string
1357 ** F -- the flags associated with the mailer
1358 ** L -- the maximum line length
1359 ** M -- the maximum message size
1360 ** N -- the niceness at which to run
1361 ** P -- the path to the mailer
1362 ** Q -- the queue group for the mailer
1363 ** R -- the recipient rewriting set
1364 ** S -- the sender rewriting set
1365 ** T -- the mailer type (for DSNs)
1366 ** U -- the uid to run as
1367 ** W -- the time to wait at the end
1368 ** m -- maximum messages per connection
1369 ** r -- maximum number of recipients per message
1370 ** / -- new root directory
1371 ** The first word is the canonical name of the mailer.
1377 ** enters the mailer into the mailer table.
1386 register struct mailer *m;
1391 static int nextmailer = 0; /* "free" index into Mailer struct */
1393 /* allocate a mailer and set up defaults */
1394 m = (struct mailer *) xalloc(sizeof(*m));
1395 memset((char *) m, '\0', sizeof(*m));
1396 errno = 0; /* avoid bogus error text */
1398 /* collect the mailer name */
1400 *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p));
1405 if (line[0] == '\0')
1407 syserr("name required for mailer");
1410 m->m_name = newstr(line);
1412 frst[nextmailer] = line[0];
1418 /* now scan through and assign info from the fields */
1421 auto char *delimptr;
1423 while (*p != '\0' &&
1424 (*p == ',' || (isascii(*p) && isspace(*p))))
1427 /* p now points to field code */
1429 while (*p != '\0' && *p != '=' && *p != ',')
1433 syserr("mailer %s: `=' expected", m->m_name);
1436 while (isascii(*p) && isspace(*p))
1439 /* p now points to the field body */
1440 p = munchstring(p, &delimptr, ',');
1442 /* install the field into the mailer struct */
1445 case 'P': /* pathname */
1446 if (*p != '\0') /* error is issued below */
1447 m->m_mailer = newstr(p);
1450 case 'F': /* flags */
1451 for (; *p != '\0'; p++)
1453 if (!(isascii(*p) && isspace(*p)))
1455 if (*p == M_INTERNAL)
1456 sm_syslog(LOG_WARNING, NOQID,
1457 "WARNING: mailer=%s, flag=%c deprecated",
1459 setbitn(bitidx(*p), m->m_flags);
1464 case 'S': /* sender rewriting ruleset */
1465 case 'R': /* recipient rewriting ruleset */
1466 i = strtorwset(p, &endp, ST_ENTER);
1470 m->m_sh_rwset = m->m_se_rwset = i;
1472 m->m_rh_rwset = m->m_re_rwset = i;
1477 i = strtorwset(p, NULL, ST_ENTER);
1487 case 'E': /* end of line string */
1489 syserr("mailer %s: null end-of-line string",
1492 m->m_eol = newstr(p);
1495 case 'A': /* argument vector */
1496 if (*p != '\0') /* error is issued below */
1497 m->m_argv = makeargv(p);
1500 case 'M': /* maximum message size */
1501 m->m_maxsize = atol(p);
1504 case 'm': /* maximum messages per connection */
1505 m->m_maxdeliveries = atoi(p);
1508 case 'r': /* max recipient per envelope */
1509 m->m_maxrcpt = atoi(p);
1512 case 'L': /* maximum line length */
1513 m->m_linelimit = atoi(p);
1514 if (m->m_linelimit < 0)
1518 case 'N': /* run niceness */
1519 m->m_nice = atoi(p);
1522 case 'D': /* working directory */
1524 syserr("mailer %s: null working directory",
1527 m->m_execdir = newstr(p);
1530 case 'C': /* default charset */
1532 syserr("mailer %s: null charset", m->m_name);
1534 m->m_defcharset = newstr(p);
1537 case 'Q': /* queue for this mailer */
1540 syserr("mailer %s: null queue", m->m_name);
1543 s = stab(p, ST_QUEUE, ST_FIND);
1545 syserr("mailer %s: unknown queue %s",
1548 m->m_qgrp = s->s_quegrp->qg_index;
1551 case 'T': /* MTA-Name/Address/Diagnostic types */
1552 /* extract MTA name type; default to "dns" */
1553 m->m_mtatype = newstr(p);
1554 p = strchr(m->m_mtatype, '/');
1561 if (*m->m_mtatype == '\0')
1562 m->m_mtatype = "dns";
1564 /* extract address type; default to "rfc822" */
1574 if (m->m_addrtype == NULL || *m->m_addrtype == '\0')
1575 m->m_addrtype = "rfc822";
1577 /* extract diagnostic type; default to "smtp" */
1579 if (m->m_diagtype == NULL || *m->m_diagtype == '\0')
1580 m->m_diagtype = "smtp";
1583 case 'U': /* user id */
1584 if (isascii(*p) && !isdigit(*p))
1589 while (*p != '\0' && isascii(*p) &&
1590 # if _FFR_DOTTED_USERNAMES
1591 (isalnum(*p) || strchr(SM_PWN_CHARS, *p) != NULL))
1592 # else /* _FFR_DOTTED_USERNAMES */
1593 (isalnum(*p) || strchr("-_", *p) != NULL))
1594 # endif /* _FFR_DOTTED_USERNAMES */
1596 while (isascii(*p) && isspace(*p))
1602 syserr("mailer %s: null user name",
1606 pw = sm_getpwnam(q);
1609 syserr("readcf: mailer U= flag: unknown user %s", q);
1614 m->m_uid = pw->pw_uid;
1615 m->m_gid = pw->pw_gid;
1622 m->m_uid = strtol(p, &q, 0);
1624 while (isascii(*p) && isspace(*p))
1629 while (isascii(*p) && isspace(*p))
1633 if (isascii(*p) && !isdigit(*p))
1638 while (isascii(*p) &&
1639 (isalnum(*p) || strchr(SM_PWN_CHARS, *p) != NULL))
1644 syserr("mailer %s: null group name",
1651 syserr("readcf: mailer U= flag: unknown group %s", q);
1655 m->m_gid = gr->gr_gid;
1659 m->m_gid = strtol(p, NULL, 0);
1663 case 'W': /* wait timeout */
1664 m->m_wait = convtime(p, 's');
1667 case '/': /* new root directory */
1669 syserr("mailer %s: null root directory",
1672 m->m_rootdir = newstr(p);
1676 syserr("M%s: unknown mailer equate %c=",
1685 if (bitnset(M_SECURE_PORT, m->m_flags))
1687 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1688 "M%s: Warning: F=%c set on system that doesn't support rresvport()\n",
1689 m->m_name, M_SECURE_PORT);
1691 #endif /* !HASRRESVPORT */
1696 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1697 "M%s: Warning: N= set on system that doesn't support nice()\n",
1700 #endif /* !HASNICE */
1702 /* do some rationality checking */
1703 if (m->m_argv == NULL)
1705 syserr("M%s: A= argument required", m->m_name);
1708 if (m->m_mailer == NULL)
1710 syserr("M%s: P= argument required", m->m_name);
1714 if (nextmailer >= MAXMAILERS)
1716 syserr("too many mailers defined (%d max)", MAXMAILERS);
1720 if (m->m_maxrcpt <= 0)
1721 m->m_maxrcpt = DEFAULT_MAX_RCPT;
1723 /* do some heuristic cleanup for back compatibility */
1724 if (bitnset(M_LIMITS, m->m_flags))
1726 if (m->m_linelimit == 0)
1727 m->m_linelimit = SMTPLINELIM;
1728 if (ConfigLevel < 2)
1729 setbitn(M_7BITS, m->m_flags);
1732 if (strcmp(m->m_mailer, "[TCP]") == 0)
1734 syserr("M%s: P=[TCP] must be replaced by P=[IPC]", m->m_name);
1738 if (strcmp(m->m_mailer, "[IPC]") == 0)
1740 /* Use the second argument for host or path to socket */
1741 if (m->m_argv[0] == NULL || m->m_argv[1] == NULL ||
1742 m->m_argv[1][0] == '\0')
1744 syserr("M%s: too few parameters for %s mailer",
1745 m->m_name, m->m_mailer);
1748 if (strcmp(m->m_argv[0], "TCP") != 0
1750 && strcmp(m->m_argv[0], "FILE") != 0
1751 #endif /* NETUNIX */
1754 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1755 "M%s: Warning: first argument in %s mailer must be %s\n",
1756 m->m_name, m->m_mailer,
1761 #endif /* NETUNIX */
1764 if (m->m_mtatype == NULL)
1765 m->m_mtatype = "dns";
1766 if (m->m_addrtype == NULL)
1767 m->m_addrtype = "rfc822";
1768 if (m->m_diagtype == NULL)
1770 if (m->m_argv[0] != NULL &&
1771 strcmp(m->m_argv[0], "FILE") == 0)
1772 m->m_diagtype = "x-unix";
1774 m->m_diagtype = "smtp";
1777 else if (strcmp(m->m_mailer, "[FILE]") == 0)
1779 /* Use the second argument for filename */
1780 if (m->m_argv[0] == NULL || m->m_argv[1] == NULL ||
1781 m->m_argv[2] != NULL)
1783 syserr("M%s: too %s parameters for [FILE] mailer",
1785 (m->m_argv[0] == NULL ||
1786 m->m_argv[1] == NULL) ? "few" : "many");
1789 else if (strcmp(m->m_argv[0], "FILE") != 0)
1791 syserr("M%s: first argument in [FILE] mailer must be FILE",
1797 if (m->m_eol == NULL)
1801 /* default for SMTP is \r\n; use \n for local delivery */
1802 for (pp = m->m_argv; *pp != NULL; pp++)
1804 for (p = *pp; *p != '\0'; )
1806 if ((*p++ & 0377) == MACROEXPAND && *p == 'u')
1818 /* enter the mailer into the symbol table */
1819 s = stab(m->m_name, ST_MAILER, ST_ENTER);
1820 if (s->s_mailer != NULL)
1822 i = s->s_mailer->m_mno;
1823 sm_free(s->s_mailer); /* XXX */
1829 Mailer[i] = s->s_mailer = m;
1833 ** MUNCHSTRING -- translate a string into internal form.
1836 ** p -- the string to munch.
1837 ** delimptr -- if non-NULL, set to the pointer of the
1838 ** field delimiter character.
1839 ** delim -- the delimiter for the field.
1842 ** the munched string.
1845 ** the munched string is a local static buffer.
1846 ** it must be copied before the function is called again.
1850 munchstring(p, delimptr, delim)
1856 bool backslash = false;
1857 bool quotemode = false;
1858 static char buf[MAXLINE];
1860 for (q = buf; *p != '\0' && q < &buf[sizeof(buf) - 1]; p++)
1864 /* everything is roughly literal */
1868 case 'r': /* carriage return */
1872 case 'n': /* newline */
1876 case 'f': /* form feed */
1880 case 'b': /* backspace */
1891 quotemode = !quotemode;
1892 else if (quotemode || *p != delim)
1899 if (delimptr != NULL)
1905 ** EXTRQUOTSTR -- extract a (quoted) string.
1907 ** This routine deals with quoted (") strings and escaped
1911 ** p -- source string.
1912 ** delimptr -- if non-NULL, set to the pointer of the
1913 ** field delimiter character.
1914 ** delimbuf -- delimiters for the field.
1915 ** st -- if non-NULL, store the return value (whether the
1916 ** string was correctly quoted) here.
1919 ** the extracted string.
1922 ** the returned string is a local static buffer.
1923 ** it must be copied before the function is called again.
1927 extrquotstr(p, delimptr, delimbuf, st)
1934 bool backslash = false;
1935 bool quotemode = false;
1936 static char buf[MAXLINE];
1938 for (q = buf; *p != '\0' && q < &buf[sizeof(buf) - 1]; p++)
1949 quotemode = !quotemode;
1950 else if (quotemode ||
1951 strchr(delimbuf, (int) *p) == NULL)
1957 if (delimptr != NULL)
1961 *st = !(quotemode || backslash);
1965 ** MAKEARGV -- break up a string into words
1968 ** p -- the string to break up.
1971 ** a char **argv (dynamically allocated)
1984 char *argv[MAXPV + 1];
1986 /* take apart the words */
1988 while (*p != '\0' && i < MAXPV)
1991 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
1993 while (isascii(*p) && isspace(*p))
1995 argv[i++] = newstr(q);
1999 /* now make a copy of the argv */
2000 avp = (char **) xalloc(sizeof(*avp) * i);
2001 memmove((char *) avp, (char *) argv, sizeof(*avp) * i);
2006 ** PRINTRULES -- print rewrite rules (for debugging)
2015 ** prints rewrite rules.
2021 register struct rewrite *rwp;
2022 register int ruleset;
2024 for (ruleset = 0; ruleset < 10; ruleset++)
2026 if (RewriteRules[ruleset] == NULL)
2028 sm_dprintf("\n----Rule Set %d:", ruleset);
2030 for (rwp = RewriteRules[ruleset]; rwp != NULL; rwp = rwp->r_next)
2032 sm_dprintf("\nLHS:");
2033 printav(sm_debug_file(), rwp->r_lhs);
2035 printav(sm_debug_file(), rwp->r_rhs);
2040 ** PRINTMAILER -- print mailer structure (for debugging)
2043 ** fp -- output file
2044 ** m -- the mailer to print
2057 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT,
2058 "mailer %d (%s): P=%s S=", m->m_mno, m->m_name,
2060 if (RuleSetNames[m->m_se_rwset] == NULL)
2061 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d/",
2064 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s/",
2065 RuleSetNames[m->m_se_rwset]);
2066 if (RuleSetNames[m->m_sh_rwset] == NULL)
2067 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d R=",
2070 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s R=",
2071 RuleSetNames[m->m_sh_rwset]);
2072 if (RuleSetNames[m->m_re_rwset] == NULL)
2073 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d/",
2076 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s/",
2077 RuleSetNames[m->m_re_rwset]);
2078 if (RuleSetNames[m->m_rh_rwset] == NULL)
2079 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%d ",
2082 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s ",
2083 RuleSetNames[m->m_rh_rwset]);
2084 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "M=%ld U=%d:%d F=",
2085 m->m_maxsize, (int) m->m_uid, (int) m->m_gid);
2086 for (j = '\0'; j <= '\177'; j++)
2087 if (bitnset(j, m->m_flags))
2088 (void) sm_io_putc(fp, SM_TIME_DEFAULT, j);
2089 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " L=%d E=",
2091 xputs(fp, m->m_eol);
2092 if (m->m_defcharset != NULL)
2093 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " C=%s",
2095 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " T=%s/%s/%s",
2096 m->m_mtatype == NULL
2097 ? "<undefined>" : m->m_mtatype,
2098 m->m_addrtype == NULL
2099 ? "<undefined>" : m->m_addrtype,
2100 m->m_diagtype == NULL
2101 ? "<undefined>" : m->m_diagtype);
2102 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " r=%d", m->m_maxrcpt);
2103 if (m->m_argv != NULL)
2105 char **a = m->m_argv;
2107 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " A=");
2111 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT,
2116 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "\n");
2120 static struct ssl_options
2122 const char *sslopt_name; /* name of the flag */
2123 long sslopt_bits; /* bits to set/clear */
2126 /* Workaround for bugs are turned on by default (as well as some others) */
2127 #ifdef SSL_OP_MICROSOFT_SESS_ID_BUG
2128 { "SSL_OP_MICROSOFT_SESS_ID_BUG", SSL_OP_MICROSOFT_SESS_ID_BUG },
2130 #ifdef SSL_OP_NETSCAPE_CHALLENGE_BUG
2131 { "SSL_OP_NETSCAPE_CHALLENGE_BUG", SSL_OP_NETSCAPE_CHALLENGE_BUG },
2133 #ifdef SSL_OP_LEGACY_SERVER_CONNECT
2134 { "SSL_OP_LEGACY_SERVER_CONNECT", SSL_OP_LEGACY_SERVER_CONNECT },
2136 #ifdef SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG
2137 { "SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG", SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG },
2139 #ifdef SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG
2140 { "SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG", SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG },
2142 #ifdef SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER
2143 { "SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER", SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER },
2145 #ifdef SSL_OP_MSIE_SSLV2_RSA_PADDING
2146 { "SSL_OP_MSIE_SSLV2_RSA_PADDING", SSL_OP_MSIE_SSLV2_RSA_PADDING },
2148 #ifdef SSL_OP_SSLEAY_080_CLIENT_DH_BUG
2149 { "SSL_OP_SSLEAY_080_CLIENT_DH_BUG", SSL_OP_SSLEAY_080_CLIENT_DH_BUG },
2151 #ifdef SSL_OP_TLS_D5_BUG
2152 { "SSL_OP_TLS_D5_BUG", SSL_OP_TLS_D5_BUG },
2154 #ifdef SSL_OP_TLS_BLOCK_PADDING_BUG
2155 { "SSL_OP_TLS_BLOCK_PADDING_BUG", SSL_OP_TLS_BLOCK_PADDING_BUG },
2157 #ifdef SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
2158 { "SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS", SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS },
2161 { "SSL_OP_ALL", SSL_OP_ALL },
2163 #ifdef SSL_OP_NO_QUERY_MTU
2164 { "SSL_OP_NO_QUERY_MTU", SSL_OP_NO_QUERY_MTU },
2166 #ifdef SSL_OP_COOKIE_EXCHANGE
2167 { "SSL_OP_COOKIE_EXCHANGE", SSL_OP_COOKIE_EXCHANGE },
2169 #ifdef SSL_OP_NO_TICKET
2170 { "SSL_OP_NO_TICKET", SSL_OP_NO_TICKET },
2172 #ifdef SSL_OP_CISCO_ANYCONNECT
2173 { "SSL_OP_CISCO_ANYCONNECT", SSL_OP_CISCO_ANYCONNECT },
2175 #ifdef SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
2176 { "SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION", SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION },
2178 #ifdef SSL_OP_NO_COMPRESSION
2179 { "SSL_OP_NO_COMPRESSION", SSL_OP_NO_COMPRESSION },
2181 #ifdef SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION
2182 { "SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION", SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION },
2184 #ifdef SSL_OP_SINGLE_ECDH_USE
2185 { "SSL_OP_SINGLE_ECDH_USE", SSL_OP_SINGLE_ECDH_USE },
2187 #ifdef SSL_OP_SINGLE_DH_USE
2188 { "SSL_OP_SINGLE_DH_USE", SSL_OP_SINGLE_DH_USE },
2190 #ifdef SSL_OP_EPHEMERAL_RSA
2191 { "SSL_OP_EPHEMERAL_RSA", SSL_OP_EPHEMERAL_RSA },
2193 #ifdef SSL_OP_CIPHER_SERVER_PREFERENCE
2194 { "SSL_OP_CIPHER_SERVER_PREFERENCE", SSL_OP_CIPHER_SERVER_PREFERENCE },
2196 #ifdef SSL_OP_TLS_ROLLBACK_BUG
2197 { "SSL_OP_TLS_ROLLBACK_BUG", SSL_OP_TLS_ROLLBACK_BUG },
2199 #ifdef SSL_OP_NO_SSLv2
2200 { "SSL_OP_NO_SSLv2", SSL_OP_NO_SSLv2 },
2202 #ifdef SSL_OP_NO_SSLv3
2203 { "SSL_OP_NO_SSLv3", SSL_OP_NO_SSLv3 },
2205 #ifdef SSL_OP_NO_TLSv1
2206 { "SSL_OP_NO_TLSv1", SSL_OP_NO_TLSv1 },
2208 #ifdef SSL_OP_NO_TLSv1_2
2209 { "SSL_OP_NO_TLSv1_2", SSL_OP_NO_TLSv1_2 },
2211 #ifdef SSL_OP_NO_TLSv1_1
2212 { "SSL_OP_NO_TLSv1_1", SSL_OP_NO_TLSv1_1 },
2214 #ifdef SSL_OP_PKCS1_CHECK_1
2215 { "SSL_OP_PKCS1_CHECK_1", SSL_OP_PKCS1_CHECK_1 },
2217 #ifdef SSL_OP_PKCS1_CHECK_2
2218 { "SSL_OP_PKCS1_CHECK_2", SSL_OP_PKCS1_CHECK_2 },
2220 #ifdef SSL_OP_NETSCAPE_CA_DN_BUG
2221 { "SSL_OP_NETSCAPE_CA_DN_BUG", SSL_OP_NETSCAPE_CA_DN_BUG },
2223 #ifdef SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG
2224 { "SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG", SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG },
2226 #ifdef SSL_OP_CRYPTOPRO_TLSEXT_BUG
2227 { "SSL_OP_CRYPTOPRO_TLSEXT_BUG", SSL_OP_CRYPTOPRO_TLSEXT_BUG },
2229 #ifdef SSL_OP_TLSEXT_PADDING
2230 { "SSL_OP_TLSEXT_PADDING", SSL_OP_TLSEXT_PADDING },
2236 ** READSSLOPTIONS -- read SSL_OP_* values
2239 ** opt -- name of option (can be NULL)
2240 ** val -- string with SSL_OP_* values or hex value
2241 ** delim -- end of string (e.g., '\0' or ';')
2242 ** pssloptions -- return value (output)
2248 #define SSLOPERR_NAN 1
2249 #define SSLOPERR_NOTFOUND 2
2250 #define SM_ISSPACE(c) (isascii(c) && isspace(c))
2253 readssloptions(opt, val, pssloptions, delim)
2256 unsigned long *pssloptions;
2263 for (p = val; *p != '\0' && *p != delim; )
2267 unsigned long sslopt_val;
2268 struct ssl_options *sslopts;
2275 if (*p == '-' || *p == '+')
2276 clearmode = *p++ == '-';
2278 while (*p != '\0' && !(SM_ISSPACE(*p)) && *p != ',')
2287 sslopt_val = strtoul(q, &end, 0);
2289 /* not a complete "syntax" check but good enough */
2295 syserr("readcf: %s option value %s not a number",
2302 for (sslopts = SSL_Option;
2303 sslopts->sslopt_name != NULL; sslopts++)
2305 if (sm_strcasecmp(q, sslopts->sslopt_name) == 0)
2307 sslopt_val = sslopts->sslopt_bits;
2311 if (sslopts->sslopt_name == NULL)
2314 ret = SSLOPERR_NOTFOUND;
2316 syserr("readcf: %s option value %s unrecognized",
2320 if (sslopt_val != 0)
2323 *pssloptions &= ~sslopt_val;
2325 *pssloptions |= sslopt_val;
2331 # if _FFR_TLS_SE_OPTS
2333 ** GET_TLS_SE_OPTIONS -- get TLS session options (from ruleset)
2337 ** ssl -- TLS session context
2345 get_tls_se_options(e, ssl, srv)
2350 bool saveQuickAbort, saveSuprErrs, ok;
2351 char *optionlist, *opt, *val;
2352 char *keyfile, *certfile;
2356 # define who (srv ? "server" : "client")
2357 # define NAME_C_S macvalue(macid(srv ? "{client_name}" : "{server_name}"), e)
2358 # define ADDR_C_S macvalue(macid(srv ? "{client_addr}" : "{server_addr}"), e)
2359 # define WHICH srv ? "srv" : "clt"
2362 keyfile = certfile = opt = val = NULL;
2363 saveQuickAbort = QuickAbort;
2364 saveSuprErrs = SuprErrs;
2369 ok = rscheck(srv ? "tls_srv_features" : "tls_clt_features",
2370 NAME_C_S, ADDR_C_S, e,
2371 RSF_RMCOMM|RSF_ADDR|RSF_STRING,
2372 5, NULL, NOQID, NULL, &optionlist) == EX_OK;
2373 if (!ok && LogLevel > 8)
2375 sm_syslog(LOG_NOTICE, NOQID,
2376 "rscheck(tls_%s_features)=failed, relay=%s [%s], errors=%d",
2377 WHICH, NAME_C_S, ADDR_C_S,
2380 QuickAbort = saveQuickAbort;
2381 SuprErrs = saveSuprErrs;
2382 if (ok && LogLevel > 9)
2384 sm_syslog(LOG_INFO, NOQID,
2385 "tls_%s_features=%s, relay=%s [%s]",
2386 WHICH, optionlist, NAME_C_S, ADDR_C_S);
2388 if (!ok || optionlist == NULL || (len = strlen(optionlist)) < 2)
2391 sm_syslog(LOG_INFO, NOQID,
2392 "tls_%s_features=empty, relay=%s [%s]",
2393 WHICH, NAME_C_S, ADDR_C_S);
2399 if (optionlist[0] == '"' && optionlist[len - 1] == '"')
2401 optionlist[0] = ' ';
2402 optionlist[--len] = '\0';
2405 if (LogLevel > 9 && len > 1)
2406 sm_syslog(LOG_INFO, NOQID,
2407 "tls_%s_features=too_short, relay=%s [%s]",
2408 WHICH, NAME_C_S, ADDR_C_S);
2410 /* this is not treated as error! */
2416 # define INVALIDSYNTAX \
2419 sm_syslog(LOG_INFO, NOQID, \
2420 "tls_%s_features=invalid_syntax, opt=%s, relay=%s [%s]", \
2421 WHICH, opt, NAME_C_S, ADDR_C_S); \
2433 while (i < len && SM_ISSPACE(optionlist[i])) \
2438 /* parse and handle opt=val; */
2443 opt = optionlist + i;
2445 while (i < len && optionlist[i] != sep
2446 && optionlist[i] != '\0' && !SM_ISSPACE(optionlist[i]))
2449 while (i < len && SM_ISSPACE(optionlist[i]))
2450 optionlist[i++] = '\0';
2452 if (optionlist[i] != sep)
2454 optionlist[i++] = '\0';
2457 val = optionlist + i;
2459 while (i < len && optionlist[i] != sep && optionlist[i] != '\0')
2461 if (optionlist[i] != '\0')
2464 optionlist[i++] = '\0';
2468 sm_syslog(LOG_DEBUG, NOQID,
2469 "tls_%s_features=parsed, %s=%s, relay=%s [%s]",
2470 WHICH, opt, val, NAME_C_S, ADDR_C_S);
2472 if (sm_strcasecmp(opt, "options") == 0)
2474 unsigned long ssloptions;
2477 ret = readssloptions(NULL, val, &ssloptions, ';');
2479 (void) SSL_set_options(ssl, (long) ssloptions);
2480 else if (LogLevel > 8)
2482 sm_syslog(LOG_WARNING, NOQID,
2483 "tls_%s_features=%s, error=%s, relay=%s [%s]",
2485 (ret == SSLOPERR_NAN) ? "not a number" :
2486 ((ret == SSLOPERR_NOTFOUND) ? "SSL_OP not found" :
2488 NAME_C_S, ADDR_C_S);
2491 else if (sm_strcasecmp(opt, "cipherlist") == 0)
2493 if (SSL_set_cipher_list(ssl, val) <= 0)
2498 sm_syslog(LOG_WARNING, NOQID,
2499 "STARTTLS=%s, error: SSL_set_cipher_list(%s) failed",
2503 tlslogerr(LOG_WARNING, who);
2507 else if (sm_strcasecmp(opt, "keyfile") == 0)
2509 else if (sm_strcasecmp(opt, "certfile") == 0)
2516 sm_syslog(LOG_INFO, NOQID,
2517 "tls_%s_features=unknown_option, opt=%s, relay=%s [%s]",
2518 WHICH, opt, NAME_C_S, ADDR_C_S);
2522 } while (optionlist[i] != '\0' && i < len);
2524 /* need cert and key before we can use the options */
2525 /* does not implement the "," hack for 2nd cert/key pair */
2526 if (keyfile != NULL && certfile != NULL)
2528 load_certkey(ssl, srv, certfile, keyfile);
2529 keyfile = certfile = NULL;
2531 else if (keyfile != NULL || certfile != NULL)
2536 sm_syslog(LOG_INFO, NOQID,
2537 "tls_%s_features=only_one_of_CertFile/KeyFile_specified, relay=%s [%s]",
2538 WHICH, NAME_C_S, ADDR_C_S);
2548 # endif /* _FFR_TLS_SE_OPTS */
2549 #endif /* STARTTLS */
2552 ** SETOPTION -- set global processing option
2555 ** opt -- option name.
2556 ** val -- option value (as a text string).
2557 ** safe -- set if this came from a configuration file.
2558 ** Some options (if set from the command line) will
2559 ** reset the user id to avoid security problems.
2560 ** sticky -- if set, don't let other setoptions override
2562 ** e -- the main envelope.
2568 ** Sets options as implied by the arguments.
2571 static BITMAP256 StickyOpt; /* set if option is stuck */
2575 static struct resolverflags
2577 char *rf_name; /* name of the flag */
2578 long rf_bits; /* bits to set/clear */
2581 { "debug", RES_DEBUG },
2582 { "aaonly", RES_AAONLY },
2583 { "usevc", RES_USEVC },
2584 { "primary", RES_PRIMARY },
2585 { "igntc", RES_IGNTC },
2586 { "recurse", RES_RECURSE },
2587 { "defnames", RES_DEFNAMES },
2588 { "stayopen", RES_STAYOPEN },
2589 { "dnsrch", RES_DNSRCH },
2590 # ifdef RES_USE_INET6
2591 { "use_inet6", RES_USE_INET6 },
2592 # endif /* RES_USE_INET6 */
2593 { "true", 0 }, /* avoid error on old syntax */
2597 #endif /* NAMED_BIND */
2599 #define OI_NONE 0 /* no special treatment */
2600 #define OI_SAFE 0x0001 /* safe for random people to use */
2601 #define OI_SUBOPT 0x0002 /* option has suboptions */
2603 static struct optioninfo
2605 char *o_name; /* long name of option */
2606 unsigned char o_code; /* short name of option */
2607 unsigned short o_flags; /* option flags */
2610 #if defined(SUN_EXTENSIONS) && defined(REMOTE_MODE)
2611 { "RemoteMode", '>', OI_NONE },
2612 #endif /* defined(SUN_EXTENSIONS) && defined(REMOTE_MODE) */
2613 { "SevenBitInput", '7', OI_SAFE },
2614 { "EightBitMode", '8', OI_SAFE },
2615 { "AliasFile", 'A', OI_NONE },
2616 { "AliasWait", 'a', OI_NONE },
2617 { "BlankSub", 'B', OI_NONE },
2618 { "MinFreeBlocks", 'b', OI_SAFE },
2619 { "CheckpointInterval", 'C', OI_SAFE },
2620 { "HoldExpensive", 'c', OI_NONE },
2621 { "DeliveryMode", 'd', OI_SAFE },
2622 { "ErrorHeader", 'E', OI_NONE },
2623 { "ErrorMode", 'e', OI_SAFE },
2624 { "TempFileMode", 'F', OI_NONE },
2625 { "SaveFromLine", 'f', OI_NONE },
2626 { "MatchGECOS", 'G', OI_NONE },
2628 /* no long name, just here to avoid problems in setoption */
2629 { "", 'g', OI_NONE },
2630 { "HelpFile", 'H', OI_NONE },
2631 { "MaxHopCount", 'h', OI_NONE },
2632 { "ResolverOptions", 'I', OI_NONE },
2633 { "IgnoreDots", 'i', OI_SAFE },
2634 { "ForwardPath", 'J', OI_NONE },
2635 { "SendMimeErrors", 'j', OI_SAFE },
2636 { "ConnectionCacheSize", 'k', OI_NONE },
2637 { "ConnectionCacheTimeout", 'K', OI_NONE },
2638 { "UseErrorsTo", 'l', OI_NONE },
2639 { "LogLevel", 'L', OI_SAFE },
2640 { "MeToo", 'm', OI_SAFE },
2642 /* no long name, just here to avoid problems in setoption */
2643 { "", 'M', OI_NONE },
2644 { "CheckAliases", 'n', OI_NONE },
2645 { "OldStyleHeaders", 'o', OI_SAFE },
2646 { "DaemonPortOptions", 'O', OI_NONE },
2647 { "PrivacyOptions", 'p', OI_SAFE },
2648 { "PostmasterCopy", 'P', OI_NONE },
2649 { "QueueFactor", 'q', OI_NONE },
2650 { "QueueDirectory", 'Q', OI_NONE },
2651 { "DontPruneRoutes", 'R', OI_NONE },
2652 { "Timeout", 'r', OI_SUBOPT },
2653 { "StatusFile", 'S', OI_NONE },
2654 { "SuperSafe", 's', OI_SAFE },
2655 { "QueueTimeout", 'T', OI_NONE },
2656 { "TimeZoneSpec", 't', OI_NONE },
2657 { "UserDatabaseSpec", 'U', OI_NONE },
2658 { "DefaultUser", 'u', OI_NONE },
2659 { "FallbackMXhost", 'V', OI_NONE },
2660 { "Verbose", 'v', OI_SAFE },
2661 { "TryNullMXList", 'w', OI_NONE },
2662 { "QueueLA", 'x', OI_NONE },
2663 { "RefuseLA", 'X', OI_NONE },
2664 { "RecipientFactor", 'y', OI_NONE },
2665 { "ForkEachJob", 'Y', OI_NONE },
2666 { "ClassFactor", 'z', OI_NONE },
2667 { "RetryFactor", 'Z', OI_NONE },
2668 #define O_QUEUESORTORD 0x81
2669 { "QueueSortOrder", O_QUEUESORTORD, OI_SAFE },
2670 #define O_HOSTSFILE 0x82
2671 { "HostsFile", O_HOSTSFILE, OI_NONE },
2673 { "MinQueueAge", O_MQA, OI_SAFE },
2674 #define O_DEFCHARSET 0x85
2675 { "DefaultCharSet", O_DEFCHARSET, OI_SAFE },
2676 #define O_SSFILE 0x86
2677 { "ServiceSwitchFile", O_SSFILE, OI_NONE },
2678 #define O_DIALDELAY 0x87
2679 { "DialDelay", O_DIALDELAY, OI_SAFE },
2680 #define O_NORCPTACTION 0x88
2681 { "NoRecipientAction", O_NORCPTACTION, OI_SAFE },
2682 #define O_SAFEFILEENV 0x89
2683 { "SafeFileEnvironment", O_SAFEFILEENV, OI_NONE },
2684 #define O_MAXMSGSIZE 0x8a
2685 { "MaxMessageSize", O_MAXMSGSIZE, OI_NONE },
2686 #define O_COLONOKINADDR 0x8b
2687 { "ColonOkInAddr", O_COLONOKINADDR, OI_SAFE },
2688 #define O_MAXQUEUERUN 0x8c
2689 { "MaxQueueRunSize", O_MAXQUEUERUN, OI_SAFE },
2690 #define O_MAXCHILDREN 0x8d
2691 { "MaxDaemonChildren", O_MAXCHILDREN, OI_NONE },
2692 #define O_KEEPCNAMES 0x8e
2693 { "DontExpandCnames", O_KEEPCNAMES, OI_NONE },
2694 #define O_MUSTQUOTE 0x8f
2695 { "MustQuoteChars", O_MUSTQUOTE, OI_NONE },
2696 #define O_SMTPGREETING 0x90
2697 { "SmtpGreetingMessage", O_SMTPGREETING, OI_NONE },
2698 #define O_UNIXFROM 0x91
2699 { "UnixFromLine", O_UNIXFROM, OI_NONE },
2700 #define O_OPCHARS 0x92
2701 { "OperatorChars", O_OPCHARS, OI_NONE },
2702 #define O_DONTINITGRPS 0x93
2703 { "DontInitGroups", O_DONTINITGRPS, OI_NONE },
2705 { "SingleLineFromHeader", O_SLFH, OI_SAFE },
2707 { "AllowBogusHELO", O_ABH, OI_SAFE },
2708 #define O_CONNTHROT 0x97
2709 { "ConnectionRateThrottle", O_CONNTHROT, OI_NONE },
2711 { "UnsafeGroupWrites", O_UGW, OI_NONE },
2712 #define O_DBLBOUNCE 0x9a
2713 { "DoubleBounceAddress", O_DBLBOUNCE, OI_NONE },
2714 #define O_HSDIR 0x9b
2715 { "HostStatusDirectory", O_HSDIR, OI_NONE },
2716 #define O_SINGTHREAD 0x9c
2717 { "SingleThreadDelivery", O_SINGTHREAD, OI_NONE },
2718 #define O_RUNASUSER 0x9d
2719 { "RunAsUser", O_RUNASUSER, OI_NONE },
2720 #define O_DSN_RRT 0x9e
2721 { "RrtImpliesDsn", O_DSN_RRT, OI_NONE },
2722 #define O_PIDFILE 0x9f
2723 { "PidFile", O_PIDFILE, OI_NONE },
2724 #define O_DONTBLAMESENDMAIL 0xa0
2725 { "DontBlameSendmail", O_DONTBLAMESENDMAIL, OI_NONE },
2727 { "DontProbeInterfaces", O_DPI, OI_NONE },
2728 #define O_MAXRCPT 0xa2
2729 { "MaxRecipientsPerMessage", O_MAXRCPT, OI_SAFE },
2730 #define O_DEADLETTER 0xa3
2731 { "DeadLetterDrop", O_DEADLETTER, OI_NONE },
2732 #if _FFR_DONTLOCKFILESFORREAD_OPTION
2733 # define O_DONTLOCK 0xa4
2734 { "DontLockFilesForRead", O_DONTLOCK, OI_NONE },
2735 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
2736 #define O_MAXALIASRCSN 0xa5
2737 { "MaxAliasRecursion", O_MAXALIASRCSN, OI_NONE },
2738 #define O_CNCTONLYTO 0xa6
2739 { "ConnectOnlyTo", O_CNCTONLYTO, OI_NONE },
2740 #define O_TRUSTUSER 0xa7
2741 { "TrustedUser", O_TRUSTUSER, OI_NONE },
2742 #define O_MAXMIMEHDRLEN 0xa8
2743 { "MaxMimeHeaderLength", O_MAXMIMEHDRLEN, OI_NONE },
2744 #define O_CONTROLSOCKET 0xa9
2745 { "ControlSocketName", O_CONTROLSOCKET, OI_NONE },
2746 #define O_MAXHDRSLEN 0xaa
2747 { "MaxHeadersLength", O_MAXHDRSLEN, OI_NONE },
2748 #if _FFR_MAX_FORWARD_ENTRIES
2749 # define O_MAXFORWARD 0xab
2750 { "MaxForwardEntries", O_MAXFORWARD, OI_NONE },
2751 #endif /* _FFR_MAX_FORWARD_ENTRIES */
2752 #define O_PROCTITLEPREFIX 0xac
2753 { "ProcessTitlePrefix", O_PROCTITLEPREFIX, OI_NONE },
2754 #define O_SASLINFO 0xad
2755 #if _FFR_ALLOW_SASLINFO
2756 { "DefaultAuthInfo", O_SASLINFO, OI_SAFE },
2757 #else /* _FFR_ALLOW_SASLINFO */
2758 { "DefaultAuthInfo", O_SASLINFO, OI_NONE },
2759 #endif /* _FFR_ALLOW_SASLINFO */
2760 #define O_SASLMECH 0xae
2761 { "AuthMechanisms", O_SASLMECH, OI_NONE },
2762 #define O_CLIENTPORT 0xaf
2763 { "ClientPortOptions", O_CLIENTPORT, OI_NONE },
2764 #define O_DF_BUFSIZE 0xb0
2765 { "DataFileBufferSize", O_DF_BUFSIZE, OI_NONE },
2766 #define O_XF_BUFSIZE 0xb1
2767 { "XscriptFileBufferSize", O_XF_BUFSIZE, OI_NONE },
2768 #define O_LDAPDEFAULTSPEC 0xb2
2769 { "LDAPDefaultSpec", O_LDAPDEFAULTSPEC, OI_NONE },
2770 #define O_SRVCERTFILE 0xb4
2771 { "ServerCertFile", O_SRVCERTFILE, OI_NONE },
2772 #define O_SRVKEYFILE 0xb5
2773 { "ServerKeyFile", O_SRVKEYFILE, OI_NONE },
2774 #define O_CLTCERTFILE 0xb6
2775 { "ClientCertFile", O_CLTCERTFILE, OI_NONE },
2776 #define O_CLTKEYFILE 0xb7
2777 { "ClientKeyFile", O_CLTKEYFILE, OI_NONE },
2778 #define O_CACERTFILE 0xb8
2779 { "CACertFile", O_CACERTFILE, OI_NONE },
2780 #define O_CACERTPATH 0xb9
2781 { "CACertPath", O_CACERTPATH, OI_NONE },
2782 #define O_DHPARAMS 0xba
2783 { "DHParameters", O_DHPARAMS, OI_NONE },
2784 #define O_INPUTMILTER 0xbb
2785 { "InputMailFilters", O_INPUTMILTER, OI_NONE },
2786 #define O_MILTER 0xbc
2787 { "Milter", O_MILTER, OI_SUBOPT },
2788 #define O_SASLOPTS 0xbd
2789 { "AuthOptions", O_SASLOPTS, OI_NONE },
2790 #define O_QUEUE_FILE_MODE 0xbe
2791 { "QueueFileMode", O_QUEUE_FILE_MODE, OI_NONE },
2792 #define O_DIG_ALG 0xbf
2793 { "CertFingerprintAlgorithm", O_DIG_ALG, OI_NONE },
2794 #define O_CIPHERLIST 0xc0
2795 { "CipherList", O_CIPHERLIST, OI_NONE },
2796 #define O_RANDFILE 0xc1
2797 { "RandFile", O_RANDFILE, OI_NONE },
2798 #define O_TLS_SRV_OPTS 0xc2
2799 { "TLSSrvOptions", O_TLS_SRV_OPTS, OI_NONE },
2800 #define O_RCPTTHROT 0xc3
2801 { "BadRcptThrottle", O_RCPTTHROT, OI_SAFE },
2802 #define O_DLVR_MIN 0xc4
2803 { "DeliverByMin", O_DLVR_MIN, OI_NONE },
2804 #define O_MAXQUEUECHILDREN 0xc5
2805 { "MaxQueueChildren", O_MAXQUEUECHILDREN, OI_NONE },
2806 #define O_MAXRUNNERSPERQUEUE 0xc6
2807 { "MaxRunnersPerQueue", O_MAXRUNNERSPERQUEUE, OI_NONE },
2808 #define O_DIRECTSUBMODIFIERS 0xc7
2809 { "DirectSubmissionModifiers", O_DIRECTSUBMODIFIERS, OI_NONE },
2810 #define O_NICEQUEUERUN 0xc8
2811 { "NiceQueueRun", O_NICEQUEUERUN, OI_NONE },
2812 #define O_SHMKEY 0xc9
2813 { "SharedMemoryKey", O_SHMKEY, OI_NONE },
2814 #define O_SASLBITS 0xca
2815 { "AuthMaxBits", O_SASLBITS, OI_NONE },
2817 { "MailboxDatabase", O_MBDB, OI_NONE },
2819 { "UseMSP", O_MSQ, OI_NONE },
2820 #define O_DELAY_LA 0xcd
2821 { "DelayLA", O_DELAY_LA, OI_NONE },
2822 #define O_FASTSPLIT 0xce
2823 { "FastSplit", O_FASTSPLIT, OI_NONE },
2824 #define O_SOFTBOUNCE 0xcf
2825 { "SoftBounce", O_SOFTBOUNCE, OI_NONE },
2826 #define O_SHMKEYFILE 0xd0
2827 { "SharedMemoryKeyFile", O_SHMKEYFILE, OI_NONE },
2828 #define O_REJECTLOGINTERVAL 0xd1
2829 { "RejectLogInterval", O_REJECTLOGINTERVAL, OI_NONE },
2830 #define O_REQUIRES_DIR_FSYNC 0xd2
2831 { "RequiresDirfsync", O_REQUIRES_DIR_FSYNC, OI_NONE },
2832 #define O_CONNECTION_RATE_WINDOW_SIZE 0xd3
2833 { "ConnectionRateWindowSize", O_CONNECTION_RATE_WINDOW_SIZE, OI_NONE },
2834 #define O_CRLFILE 0xd4
2835 { "CRLFile", O_CRLFILE, OI_NONE },
2836 #define O_FALLBACKSMARTHOST 0xd5
2837 { "FallbackSmartHost", O_FALLBACKSMARTHOST, OI_NONE },
2838 #define O_SASLREALM 0xd6
2839 { "AuthRealm", O_SASLREALM, OI_NONE },
2841 # define O_CRLPATH 0xd7
2842 { "CRLPath", O_CRLPATH, OI_NONE },
2843 #endif /* _FFR_CRLPATH */
2844 #define O_HELONAME 0xd8
2845 { "HeloName", O_HELONAME, OI_NONE },
2847 # define O_REFUSELOWMEM 0xd9
2848 { "RefuseLowMem", O_REFUSELOWMEM, OI_NONE },
2849 # define O_QUEUELOWMEM 0xda
2850 { "QueueLowMem", O_QUEUELOWMEM, OI_NONE },
2851 # define O_MEMRESOURCE 0xdb
2852 { "MemoryResource", O_MEMRESOURCE, OI_NONE },
2853 #endif /* _FFR_MEMSTAT */
2854 #define O_MAXNOOPCOMMANDS 0xdc
2855 { "MaxNOOPCommands", O_MAXNOOPCOMMANDS, OI_NONE },
2857 # define O_MSG_ACCEPT 0xdd
2858 { "MessageAccept", O_MSG_ACCEPT, OI_NONE },
2859 #endif /* _FFR_MSG_ACCEPT */
2860 #if _FFR_QUEUE_RUN_PARANOIA
2861 # define O_CHK_Q_RUNNERS 0xde
2862 { "CheckQueueRunners", O_CHK_Q_RUNNERS, OI_NONE },
2863 #endif /* _FFR_QUEUE_RUN_PARANOIA */
2864 #if _FFR_EIGHT_BIT_ADDR_OK
2866 # ERROR FFR_EIGHT_BIT_ADDR_OK requires _ALLOW_255
2867 # endif /* !ALLOW_255 */
2868 # define O_EIGHT_BIT_ADDR_OK 0xdf
2869 { "EightBitAddrOK", O_EIGHT_BIT_ADDR_OK, OI_NONE },
2870 #endif /* _FFR_EIGHT_BIT_ADDR_OK */
2871 #if _FFR_ADDR_TYPE_MODES
2872 # define O_ADDR_TYPE_MODES 0xe0
2873 { "AddrTypeModes", O_ADDR_TYPE_MODES, OI_NONE },
2874 #endif /* _FFR_ADDR_TYPE_MODES */
2875 #if _FFR_BADRCPT_SHUTDOWN
2876 # define O_RCPTSHUTD 0xe1
2877 { "BadRcptShutdown", O_RCPTSHUTD, OI_SAFE },
2878 # define O_RCPTSHUTDG 0xe2
2879 { "BadRcptShutdownGood", O_RCPTSHUTDG, OI_SAFE },
2880 #endif /* _FFR_BADRCPT_SHUTDOWN */
2881 #define O_SRV_SSL_OPTIONS 0xe3
2882 { "ServerSSLOptions", O_SRV_SSL_OPTIONS, OI_NONE },
2883 #define O_CLT_SSL_OPTIONS 0xe4
2884 { "ClientSSLOptions", O_CLT_SSL_OPTIONS, OI_NONE },
2885 #define O_MAX_QUEUE_AGE 0xe5
2886 { "MaxQueueAge", O_MAX_QUEUE_AGE, OI_NONE },
2887 #if _FFR_RCPTTHROTDELAY
2888 # define O_RCPTTHROTDELAY 0xe6
2889 { "BadRcptThrottleDelay", O_RCPTTHROTDELAY, OI_SAFE },
2890 #endif /* _FFR_RCPTTHROTDELAY */
2891 #if 0 && _FFR_QOS && defined(SOL_IP) && defined(IP_TOS)
2892 # define O_INETQOS 0xe7 /* reserved for FFR_QOS */
2893 { "InetQoS", O_INETQOS, OI_NONE },
2895 #if STARTTLS && _FFR_FIPSMODE
2896 # define O_FIPSMODE 0xe8
2897 { "FIPSMode", O_FIPSMODE, OI_NONE },
2898 #endif /* STARTTLS && _FFR_FIPSMODE */
2899 #if _FFR_REJECT_NUL_BYTE
2900 # define O_REJECTNUL 0xe9
2901 { "RejectNUL", O_REJECTNUL, OI_SAFE },
2902 #endif /* _FFR_REJECT_NUL_BYTE */
2903 #if _FFR_BOUNCE_QUEUE
2904 # define O_BOUNCEQUEUE 0xea
2905 { "BounceQueue", O_BOUNCEQUEUE, OI_NONE },
2906 #endif /* _FFR_BOUNCE_QUEUE */
2908 # define O_ADDBCC 0xeb
2909 { "AddBcc", O_ADDBCC, OI_NONE },
2911 #define O_USECOMPRESSEDIPV6ADDRESSES 0xec
2912 { "UseCompressedIPv6Addresses", O_USECOMPRESSEDIPV6ADDRESSES, OI_NONE },
2914 { NULL, '\0', OI_NONE }
2917 # define CANONIFY(val)
2919 # define SET_OPT_DEFAULT(opt, val) opt = val
2921 /* set a string option by expanding the value and assigning it */
2922 /* WARNING this belongs ONLY into a case statement! */
2923 #define SET_STRING_EXP(str) \
2924 expand(val, exbuf, sizeof(exbuf), e); \
2925 newval = sm_pstrdup_x(exbuf); \
2932 #define OPTNAME o->o_name == NULL ? "<unknown>" : o->o_name
2935 setoption(opt, val, safe, sticky, e)
2940 register ENVELOPE *e;
2943 register struct optioninfo *o;
2946 bool can_setuid = RunAsUid == 0;
2949 extern bool Warn_Q_option;
2950 #if _FFR_ALLOW_SASLINFO
2951 extern unsigned int SubmitMode;
2952 #endif /* _FFR_ALLOW_SASLINFO */
2953 #if STARTTLS || SM_CONF_SHM
2955 char exbuf[MAXLINE];
2956 #endif /* STARTTLS || SM_CONF_SHM */
2958 unsigned long *pssloptions = NULL;
2964 /* full word options */
2965 struct optioninfo *sel;
2967 p = strchr(val, '=');
2969 p = &val[strlen(val)];
2976 syserr("readcf: null option name");
2983 subopt = strchr(val, '.');
2987 for (o = OptionTab; o->o_name != NULL; o++)
2989 if (sm_strncasecmp(o->o_name, val, strlen(val)) != 0)
2991 if (strlen(o->o_name) == strlen(val))
2993 /* completely specified -- this must be it */
3001 if (sel != NULL && o->o_name == NULL)
3003 else if (o->o_name == NULL)
3005 syserr("readcf: unknown option name %s", val);
3008 else if (sel != NULL)
3010 syserr("readcf: ambiguous option name %s (matches %s and %s)",
3011 val, sel->o_name, o->o_name);
3014 if (strlen(val) != strlen(o->o_name))
3016 int oldVerbose = Verbose;
3019 message("Option %s used as abbreviation for %s",
3021 Verbose = oldVerbose;
3028 for (o = OptionTab; o->o_name != NULL; o++)
3030 if (o->o_code == opt)
3033 if (o->o_name == NULL)
3035 syserr("readcf: unknown option name 0x%x", opt & 0xff);
3041 if (subopt != NULL && !bitset(OI_SUBOPT, o->o_flags))
3044 sm_dprintf("setoption: %s does not support suboptions, ignoring .%s\n",
3051 sm_dprintf(isascii(opt) && isprint(opt) ?
3052 "setoption %s (%c)%s%s=" :
3053 "setoption %s (0x%x)%s%s=",
3054 OPTNAME, opt, subopt == NULL ? "" : ".",
3055 subopt == NULL ? "" : subopt);
3056 xputs(sm_debug_file(), val);
3060 ** See if this option is preset for us.
3063 if (!sticky && bitnset(opt, StickyOpt))
3066 sm_dprintf(" (ignored)\n");
3071 ** Check to see if this option can be specified by this user.
3074 if (!safe && RealUid == 0)
3076 if (!safe && !bitset(OI_SAFE, o->o_flags))
3078 if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
3083 sm_dprintf(" (unsafe)");
3084 dp = drop_privileges(true);
3093 case '7': /* force seven-bit input */
3094 SevenBitInput = atobool(val);
3097 case '8': /* handling of 8-bit input */
3101 case 'p': /* pass 8 bit, convert MIME */
3102 MimeMode = MM_CVTMIME|MM_PASS8BIT;
3105 case 'm': /* convert 8-bit, convert MIME */
3106 MimeMode = MM_CVTMIME|MM_MIME8BIT;
3109 case 's': /* strict adherence */
3110 MimeMode = MM_CVTMIME;
3114 case 'r': /* reject 8-bit, don't convert MIME */
3118 case 'j': /* "just send 8" */
3119 MimeMode = MM_PASS8BIT;
3122 case 'a': /* encode 8 bit if available */
3123 MimeMode = MM_MIME8BIT|MM_PASS8BIT|MM_CVTMIME;
3126 case 'c': /* convert 8 bit to MIME, never 7 bit */
3127 MimeMode = MM_MIME8BIT;
3132 syserr("Unknown 8-bit mode %c", *val);
3133 finis(false, true, EX_USAGE);
3135 #else /* MIME8TO7 */
3136 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3137 "Warning: Option: %s requires MIME8TO7 support\n",
3139 #endif /* MIME8TO7 */
3142 case 'A': /* set default alias file */
3147 SET_OPT_DEFAULT(al, "aliases");
3154 case 'a': /* look N minutes for "@:@" in alias file */
3156 SafeAlias = 5 MINUTES;
3158 SafeAlias = convtime(val, 'm');
3161 case 'B': /* substitution for blank character */
3163 if (SpaceSub == '\0')
3167 case 'b': /* min blocks free on queue fs/max msg size */
3168 p = strchr(val, '/');
3172 MaxMessageSize = atol(p);
3174 MinBlocksFree = atol(val);
3177 case 'c': /* don't connect to "expensive" mailers */
3178 NoConnect = atobool(val);
3181 case 'C': /* checkpoint every N addresses */
3182 if (safe || CheckpointInterval > atoi(val))
3183 CheckpointInterval = atoi(val);
3186 case 'd': /* delivery mode */
3190 set_delivery_mode(SM_DELIVER, e);
3193 case SM_QUEUE: /* queue only */
3194 case SM_DEFER: /* queue only and defer map lookups */
3195 case SM_DELIVER: /* do everything */
3196 case SM_FORK: /* fork after verification */
3198 /* deliver first TA in background, then queue */
3200 #endif /* _FFR_DM_ONE */
3201 set_delivery_mode(*val, e);
3206 set_delivery_mode(*val, e);
3208 #endif /* _FFR_PROXY */
3211 syserr("Unknown delivery mode %c", *val);
3212 finis(false, true, EX_USAGE);
3216 case 'E': /* error message header/header file */
3218 ErrMsgFile = newstr(val);
3221 case 'e': /* set error processing mode */
3224 case EM_QUIET: /* be silent about it */
3225 case EM_MAIL: /* mail back */
3226 case EM_BERKNET: /* do berknet error processing */
3227 case EM_WRITE: /* write back (or mail) */
3228 case EM_PRINT: /* print errors normally (default) */
3229 e->e_errormode = *val;
3234 case 'F': /* file mode */
3235 FileMode = atooct(val) & 0777;
3238 case 'f': /* save Unix-style From lines on front */
3239 SaveFrom = atobool(val);
3242 case 'G': /* match recipients against GECOS field */
3243 MatchGecos = atobool(val);
3246 case 'g': /* default gid */
3248 if (isascii(*val) && isdigit(*val))
3252 register struct group *gr;
3257 syserr("readcf: option %c: unknown group %s",
3260 DefGid = gr->gr_gid;
3264 case 'H': /* help file */
3267 SET_OPT_DEFAULT(HelpFile, "helpfile");
3272 HelpFile = newstr(val);
3276 case 'h': /* maximum hop count */
3277 MaxHopCount = atoi(val);
3280 case 'I': /* use internet domain name server */
3282 for (p = val; *p != 0; )
3286 struct resolverflags *rfp;
3299 while (*p != '\0' && !(isascii(*p) && isspace(*p)))
3303 if (sm_strcasecmp(q, "HasWildcardMX") == 0)
3305 HasWildcardMX = !clearmode;
3308 if (sm_strcasecmp(q, "WorkAroundBrokenAAAA") == 0)
3310 WorkAroundBrokenAAAA = !clearmode;
3313 for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
3315 if (sm_strcasecmp(q, rfp->rf_name) == 0)
3318 if (rfp->rf_name == NULL)
3319 syserr("readcf: I option value %s unrecognized", q);
3321 _res.options &= ~rfp->rf_bits;
3323 _res.options |= rfp->rf_bits;
3326 sm_dprintf("_res.options = %x, HasWildcardMX = %d\n",
3327 (unsigned int) _res.options, HasWildcardMX);
3328 #else /* NAMED_BIND */
3329 usrerr("name server (I option) specified but BIND not compiled in");
3330 #endif /* NAMED_BIND */
3333 case 'i': /* ignore dot lines in message */
3334 IgnrDot = atobool(val);
3337 case 'j': /* send errors in MIME (RFC 1341) format */
3338 SendMIMEErrors = atobool(val);
3341 case 'J': /* .forward search path */
3343 ForwardPath = newstr(val);
3346 case 'k': /* connection cache size */
3347 MaxMciCache = atoi(val);
3348 if (MaxMciCache < 0)
3352 case 'K': /* connection cache timeout */
3353 MciCacheTimeout = convtime(val, 'm');
3356 case 'l': /* use Errors-To: header */
3357 UseErrorsTo = atobool(val);
3360 case 'L': /* log level */
3361 if (safe || LogLevel < atoi(val))
3362 LogLevel = atoi(val);
3365 case 'M': /* define macro */
3367 mid = macid_parse(val, &ep);
3372 cleanstrcpy(p, p, strlen(p) + 1);
3373 macdefine(&CurEnv->e_macro, A_TEMP, mid, p);
3376 case 'm': /* send to me too */
3377 MeToo = atobool(val);
3380 case 'n': /* validate RHS in newaliases */
3381 CheckAliases = atobool(val);
3384 /* 'N' available -- was "net name" */
3386 case 'O': /* daemon options */
3387 if (!setdaemonoptions(val))
3388 syserr("too many daemons defined (%d max)", MAXDAEMONS);
3391 case 'o': /* assume old style headers */
3393 CurEnv->e_flags |= EF_OLDSTYLE;
3395 CurEnv->e_flags &= ~EF_OLDSTYLE;
3398 case 'p': /* select privacy level */
3402 register struct prival *pv;
3403 extern struct prival PrivacyValues[];
3405 while (isascii(*p) && (isspace(*p) || ispunct(*p)))
3410 while (isascii(*p) && isalnum(*p))
3415 for (pv = PrivacyValues; pv->pv_name != NULL; pv++)
3417 if (sm_strcasecmp(val, pv->pv_name) == 0)
3420 if (pv->pv_name == NULL)
3421 syserr("readcf: Op line: %s unrecognized", val);
3423 PrivacyFlags |= pv->pv_flag;
3428 case 'P': /* postmaster copy address for returned mail */
3429 PostMasterCopy = newstr(val);
3432 case 'q': /* slope of queue only function */
3433 QueueFactor = atoi(val);
3436 case 'Q': /* queue directory */
3439 QueueDir = "mqueue";
3443 QueueDir = newstr(val);
3445 if (RealUid != 0 && !safe)
3446 Warn_Q_option = true;
3449 case 'R': /* don't prune routes */
3450 DontPruneRoutes = atobool(val);
3453 case 'r': /* read timeout */
3455 inittimeouts(val, sticky);
3457 settimeout(subopt, val, sticky);
3460 case 'S': /* status file */
3463 SET_OPT_DEFAULT(StatFile, "statistics");
3468 StatFile = newstr(val);
3472 case 's': /* be super safe, even if expensive */
3473 if (tolower(*val) == 'i')
3474 SuperSafe = SAFE_INTERACTIVE;
3475 else if (tolower(*val) == 'p')
3477 SuperSafe = SAFE_REALLY_POSTMILTER;
3479 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3480 "Warning: SuperSafe=PostMilter requires Milter support (-DMILTER)\n");
3483 SuperSafe = atobool(val) ? SAFE_REALLY : SAFE_NO;
3486 case 'T': /* queue timeout */
3487 p = strchr(val, '/');
3491 settimeout("queuewarn", p, sticky);
3493 settimeout("queuereturn", val, sticky);
3496 case 't': /* time zone name */
3497 TimeZoneSpec = newstr(val);
3500 case 'U': /* location of user database */
3501 UdbSpec = newstr(val);
3504 case 'u': /* set default uid */
3505 for (p = val; *p != '\0'; p++)
3507 # if _FFR_DOTTED_USERNAMES
3508 if (*p == '/' || *p == ':')
3509 # else /* _FFR_DOTTED_USERNAMES */
3510 if (*p == '.' || *p == '/' || *p == ':')
3511 # endif /* _FFR_DOTTED_USERNAMES */
3517 if (isascii(*val) && isdigit(*val))
3524 register struct passwd *pw;
3527 pw = sm_getpwnam(val);
3530 syserr("readcf: option u: unknown user %s", val);
3535 DefUid = pw->pw_uid;
3536 DefGid = pw->pw_gid;
3537 DefUser = newstr(pw->pw_name);
3542 if (DefUid > UID_MAX)
3544 syserr("readcf: option u: uid value (%ld) > UID_MAX (%ld); ignored",
3545 (long)DefUid, (long)UID_MAX);
3548 # endif /* UID_MAX */
3550 /* handle the group if it is there */
3556 case 'V': /* fallback MX host */
3558 FallbackMX = newstr(val);
3561 case 'v': /* run in verbose mode */
3562 Verbose = atobool(val) ? 1 : 0;
3565 case 'w': /* if we are best MX, try host directly */
3566 TryNullMXList = atobool(val);
3569 /* 'W' available -- was wizard password */
3571 case 'x': /* load avg at which to auto-queue msgs */
3572 QueueLA = atoi(val);
3575 case 'X': /* load avg at which to auto-reject connections */
3576 RefuseLA = atoi(val);
3579 case O_DELAY_LA: /* load avg at which to delay connections */
3580 DelayLA = atoi(val);
3583 case 'y': /* work recipient factor */
3584 WkRecipFact = atoi(val);
3587 case 'Y': /* fork jobs during queue runs */
3588 ForkQueueRuns = atobool(val);
3591 case 'z': /* work message class factor */
3592 WkClassFact = atoi(val);
3595 case 'Z': /* work time factor */
3596 WkTimeFact = atoi(val);
3600 #if _FFR_QUEUE_GROUP_SORTORDER
3601 /* coordinate this with makequeue() */
3602 #endif /* _FFR_QUEUE_GROUP_SORTORDER */
3603 case O_QUEUESORTORD: /* queue sorting order */
3606 case 'f': /* File Name */
3608 QueueSortOrder = QSO_BYFILENAME;
3611 case 'h': /* Host first */
3613 QueueSortOrder = QSO_BYHOST;
3616 case 'm': /* Modification time */
3618 QueueSortOrder = QSO_BYMODTIME;
3621 case 'p': /* Priority order */
3623 QueueSortOrder = QSO_BYPRIORITY;
3626 case 't': /* Submission time */
3628 QueueSortOrder = QSO_BYTIME;
3631 case 'r': /* Random */
3633 QueueSortOrder = QSO_RANDOM;
3637 case 's': /* Shuffled host name */
3639 QueueSortOrder = QSO_BYSHUFFLE;
3641 #endif /* _FFR_RHS */
3643 case 'n': /* none */
3645 QueueSortOrder = QSO_NONE;
3649 syserr("Invalid queue sort order \"%s\"", val);
3653 case O_HOSTSFILE: /* pathname of /etc/hosts file */
3655 HostsFile = newstr(val);
3658 case O_MQA: /* minimum queue age between deliveries */
3659 MinQueueAge = convtime(val, 'm');
3662 case O_MAX_QUEUE_AGE:
3663 MaxQueueAge = convtime(val, 'm');
3666 case O_DEFCHARSET: /* default character set for mimefying */
3667 DefaultCharSet = newstr(denlstring(val, true, true));
3670 case O_SSFILE: /* service switch file */
3672 ServiceSwitchFile = newstr(val);
3675 case O_DIALDELAY: /* delay for dial-on-demand operation */
3676 DialDelay = convtime(val, 's');
3679 case O_NORCPTACTION: /* what to do if no recipient */
3680 if (sm_strcasecmp(val, "none") == 0)
3681 NoRecipientAction = NRA_NO_ACTION;
3682 else if (sm_strcasecmp(val, "add-to") == 0)
3683 NoRecipientAction = NRA_ADD_TO;
3684 else if (sm_strcasecmp(val, "add-apparently-to") == 0)
3685 NoRecipientAction = NRA_ADD_APPARENTLY_TO;
3686 else if (sm_strcasecmp(val, "add-bcc") == 0)
3687 NoRecipientAction = NRA_ADD_BCC;
3688 else if (sm_strcasecmp(val, "add-to-undisclosed") == 0)
3689 NoRecipientAction = NRA_ADD_TO_UNDISCLOSED;
3691 syserr("Invalid NoRecipientAction: %s", val);
3694 case O_SAFEFILEENV: /* chroot() environ for writing to files */
3698 /* strip trailing slashes */
3699 p = val + strlen(val) - 1;
3700 while (p >= val && *p == '/')
3706 SafeFileEnv = newstr(val);
3709 case O_MAXMSGSIZE: /* maximum message size */
3710 MaxMessageSize = atol(val);
3713 case O_COLONOKINADDR: /* old style handling of colon addresses */
3714 ColonOkInAddr = atobool(val);
3717 case O_MAXQUEUERUN: /* max # of jobs in a single queue run */
3718 MaxQueueRun = atoi(val);
3721 case O_MAXCHILDREN: /* max # of children of daemon */
3722 MaxChildren = atoi(val);
3725 case O_MAXQUEUECHILDREN: /* max # of children of daemon */
3726 MaxQueueChildren = atoi(val);
3729 case O_MAXRUNNERSPERQUEUE: /* max # runners in a queue group */
3730 MaxRunnersPerQueue = atoi(val);
3733 case O_NICEQUEUERUN: /* nice queue runs */
3735 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3736 "Warning: NiceQueueRun set on system that doesn't support nice()\n");
3737 #endif /* !HASNICE */
3739 /* XXX do we want to check the range? > 0 ? */
3740 NiceQueueRun = atoi(val);
3743 case O_SHMKEY: /* shared memory key */
3746 #else /* SM_CONF_SHM */
3747 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3748 "Warning: Option: %s requires shared memory support (-DSM_CONF_SHM)\n",
3750 #endif /* SM_CONF_SHM */
3753 case O_SHMKEYFILE: /* shared memory key file */
3755 SET_STRING_EXP(ShmKeyFile);
3756 #else /* SM_CONF_SHM */
3757 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3758 "Warning: Option: %s requires shared memory support (-DSM_CONF_SHM)\n",
3761 #endif /* SM_CONF_SHM */
3763 #if _FFR_MAX_FORWARD_ENTRIES
3764 case O_MAXFORWARD: /* max # of forward entries */
3765 MaxForwardEntries = atoi(val);
3767 #endif /* _FFR_MAX_FORWARD_ENTRIES */
3769 case O_KEEPCNAMES: /* don't expand CNAME records */
3770 DontExpandCnames = atobool(val);
3773 case O_MUSTQUOTE: /* must quote these characters in phrases */
3774 (void) sm_strlcpy(buf, "@,;:\\()[]", sizeof(buf));
3775 if (strlen(val) < sizeof(buf) - 10)
3776 (void) sm_strlcat(buf, val, sizeof(buf));
3778 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3779 "Warning: MustQuoteChars too long, ignored.\n");
3780 MustQuoteChars = newstr(buf);
3783 case O_SMTPGREETING: /* SMTP greeting message (old $e macro) */
3784 SmtpGreeting = newstr(munchstring(val, NULL, '\0'));
3787 case O_UNIXFROM: /* UNIX From_ line (old $l macro) */
3788 UnixFromLine = newstr(munchstring(val, NULL, '\0'));
3791 case O_OPCHARS: /* operator characters (old $o macro) */
3792 if (OperatorChars != NULL)
3793 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3794 "Warning: OperatorChars is being redefined.\n It should only be set before ruleset definitions.\n");
3795 OperatorChars = newstr(munchstring(val, NULL, '\0'));
3798 case O_DONTINITGRPS: /* don't call initgroups(3) */
3799 DontInitGroups = atobool(val);
3802 case O_SLFH: /* make sure from fits on one line */
3803 SingleLineFromHeader = atobool(val);
3806 case O_ABH: /* allow HELO commands with syntax errors */
3807 AllowBogusHELO = atobool(val);
3810 case O_CONNTHROT: /* connection rate throttle */
3811 ConnRateThrottle = atoi(val);
3814 case O_UGW: /* group writable files are unsafe */
3817 setbitn(DBS_GROUPWRITABLEFORWARDFILESAFE,
3819 setbitn(DBS_GROUPWRITABLEINCLUDEFILESAFE,
3824 case O_DBLBOUNCE: /* address to which to send double bounces */
3825 DoubleBounceAddr = newstr(val);
3828 case O_HSDIR: /* persistent host status directory */
3832 HostStatDir = newstr(val);
3836 case O_SINGTHREAD: /* single thread deliveries (requires hsdir) */
3837 SingleThreadDelivery = atobool(val);
3840 case O_RUNASUSER: /* run bulk of code as this user */
3841 for (p = val; *p != '\0'; p++)
3843 # if _FFR_DOTTED_USERNAMES
3844 if (*p == '/' || *p == ':')
3845 # else /* _FFR_DOTTED_USERNAMES */
3846 if (*p == '.' || *p == '/' || *p == ':')
3847 # endif /* _FFR_DOTTED_USERNAMES */
3853 if (isascii(*val) && isdigit(*val))
3856 RunAsUid = atoi(val);
3860 register struct passwd *pw;
3862 pw = sm_getpwnam(val);
3865 syserr("readcf: option RunAsUser: unknown user %s", val);
3868 else if (can_setuid)
3871 RunAsUserName = newstr(val);
3872 RunAsUid = pw->pw_uid;
3873 RunAsGid = pw->pw_gid;
3875 else if (EffGid == pw->pw_gid)
3876 RunAsGid = pw->pw_gid;
3877 else if (UseMSP && *p == '\0')
3878 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
3879 "WARNING: RunAsUser for MSP ignored, check group ids (egid=%ld, want=%ld)\n",
3884 if (RunAsUid > UID_MAX)
3886 syserr("readcf: option RunAsUser: uid value (%ld) > UID_MAX (%ld); ignored",
3887 (long) RunAsUid, (long) UID_MAX);
3890 # endif /* UID_MAX */
3893 if (isascii(*p) && isdigit(*p))
3897 runasgid = (gid_t) atoi(p);
3898 if (can_setuid || EffGid == runasgid)
3899 RunAsGid = runasgid;
3901 (void) sm_io_fprintf(smioout,
3903 "WARNING: RunAsUser for MSP ignored, check group ids (egid=%ld, want=%ld)\n",
3909 register struct group *gr;
3913 syserr("readcf: option RunAsUser: unknown group %s",
3915 else if (can_setuid || EffGid == gr->gr_gid)
3916 RunAsGid = gr->gr_gid;
3918 (void) sm_io_fprintf(smioout,
3920 "WARNING: RunAsUser for MSP ignored, check group ids (egid=%ld, want=%ld)\n",
3926 sm_dprintf("readcf: RunAsUser = %d:%d\n",
3927 (int) RunAsUid, (int) RunAsGid);
3931 RrtImpliesDsn = atobool(val);
3935 PSTRSET(PidFile, val);
3938 case O_DONTBLAMESENDMAIL:
3942 register struct dbsval *dbs;
3943 extern struct dbsval DontBlameSendmailValues[];
3945 while (isascii(*p) && (isspace(*p) || ispunct(*p)))
3950 while (isascii(*p) && isalnum(*p))
3955 for (dbs = DontBlameSendmailValues;
3956 dbs->dbs_name != NULL; dbs++)
3958 if (sm_strcasecmp(val, dbs->dbs_name) == 0)
3961 if (dbs->dbs_name == NULL)
3962 syserr("readcf: DontBlameSendmail option: %s unrecognized", val);
3963 else if (dbs->dbs_flag == DBS_SAFE)
3964 clrbitmap(DontBlameSendmail);
3966 setbitn(dbs->dbs_flag, DontBlameSendmail);
3972 if (sm_strcasecmp(val, "loopback") == 0)
3973 DontProbeInterfaces = DPI_SKIPLOOPBACK;
3974 else if (atobool(val))
3975 DontProbeInterfaces = DPI_PROBENONE;
3977 DontProbeInterfaces = DPI_PROBEALL;
3981 MaxRcptPerMsg = atoi(val);
3985 BadRcptThrottle = atoi(val);
3988 #if _FFR_RCPTTHROTDELAY
3989 case O_RCPTTHROTDELAY:
3990 BadRcptThrottleDelay = atoi(val);
3992 #endif /* _FFR_RCPTTHROTDELAY */
3996 PSTRSET(DeadLetterDrop, val);
3999 #if _FFR_DONTLOCKFILESFORREAD_OPTION
4001 DontLockReadFiles = atobool(val);
4003 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
4005 case O_MAXALIASRCSN:
4006 MaxAliasRecursion = atoi(val);
4010 /* XXX should probably use gethostbyname */
4011 #if NETINET || NETINET6
4012 ConnectOnlyTo.sa.sa_family = AF_UNSPEC;
4014 if (anynet_pton(AF_INET6, val,
4015 &ConnectOnlyTo.sin6.sin6_addr) == 1)
4016 ConnectOnlyTo.sa.sa_family = AF_INET6;
4018 # endif /* NETINET6 */
4021 ConnectOnlyTo.sin.sin_addr.s_addr = inet_addr(val);
4022 if (ConnectOnlyTo.sin.sin_addr.s_addr != INADDR_NONE)
4023 ConnectOnlyTo.sa.sa_family = AF_INET;
4026 # endif /* NETINET */
4027 if (ConnectOnlyTo.sa.sa_family == AF_UNSPEC)
4029 syserr("readcf: option ConnectOnlyTo: invalid IP address %s",
4033 #endif /* NETINET || NETINET6 */
4037 # if !HASFCHOWN && !defined(_FFR_DROP_TRUSTUSER_WARNING)
4039 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4040 "readcf: option TrustedUser may cause problems on systems\n which do not support fchown() if UseMSP is not set.\n");
4041 # endif /* !HASFCHOWN && !defined(_FFR_DROP_TRUSTUSER_WARNING) */
4042 if (isascii(*val) && isdigit(*val))
4043 TrustedUid = atoi(val);
4046 register struct passwd *pw;
4049 pw = sm_getpwnam(val);
4052 syserr("readcf: option TrustedUser: unknown user %s", val);
4056 TrustedUid = pw->pw_uid;
4060 if (TrustedUid > UID_MAX)
4062 syserr("readcf: option TrustedUser: uid value (%ld) > UID_MAX (%ld)",
4063 (long) TrustedUid, (long) UID_MAX);
4066 # endif /* UID_MAX */
4069 case O_MAXMIMEHDRLEN:
4070 p = strchr(val, '/');
4073 MaxMimeHeaderLength = atoi(val);
4074 if (p != NULL && *p != '\0')
4075 MaxMimeFieldLength = atoi(p);
4077 MaxMimeFieldLength = MaxMimeHeaderLength / 2;
4079 if (MaxMimeHeaderLength <= 0)
4080 MaxMimeHeaderLength = 0;
4081 else if (MaxMimeHeaderLength < 128)
4082 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4083 "Warning: MaxMimeHeaderLength: header length limit set lower than 128\n");
4085 if (MaxMimeFieldLength <= 0)
4086 MaxMimeFieldLength = 0;
4087 else if (MaxMimeFieldLength < 40)
4088 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4089 "Warning: MaxMimeHeaderLength: field length limit set lower than 40\n");
4092 ** Headers field values now include leading space, so let's
4093 ** adjust the values to be "backward compatible".
4096 if (MaxMimeHeaderLength > 0)
4097 MaxMimeHeaderLength++;
4098 if (MaxMimeFieldLength > 0)
4099 MaxMimeFieldLength++;
4102 case O_CONTROLSOCKET:
4103 PSTRSET(ControlSocketName, val);
4107 MaxHeadersLength = atoi(val);
4109 if (MaxHeadersLength > 0 &&
4110 MaxHeadersLength < (MAXHDRSLEN / 2))
4111 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4112 "Warning: MaxHeadersLength: headers length limit set lower than %d\n",
4116 case O_PROCTITLEPREFIX:
4117 PSTRSET(ProcTitlePrefix, val);
4122 # if _FFR_ALLOW_SASLINFO
4124 ** Allow users to select their own authinfo file
4125 ** under certain circumstances, otherwise just ignore
4126 ** the option. If the option isn't ignored, several
4127 ** commands don't work very well, e.g., mailq.
4128 ** However, this is not a "perfect" solution.
4129 ** If mail is queued, the authentication info
4130 ** will not be used in subsequent delivery attempts.
4131 ** If we really want to support this, then it has
4132 ** to be stored in the queue file.
4134 if (!bitset(SUBMIT_MSA, SubmitMode) && RealUid != 0 &&
4135 RunAsUid != RealUid)
4137 # endif /* _FFR_ALLOW_SASLINFO */
4138 PSTRSET(SASLInfo, val);
4142 if (AuthMechanisms != NULL)
4143 sm_free(AuthMechanisms); /* XXX */
4145 AuthMechanisms = newstr(val);
4147 AuthMechanisms = NULL;
4151 if (AuthRealm != NULL)
4154 AuthRealm = newstr(val);
4160 while (val != NULL && *val != '\0')
4165 SASLOpts |= SASL_AUTH_AUTH;
4169 SASLOpts |= SASL_SEC_NOACTIVE;
4173 SASLOpts |= SASL_SEC_PASS_CREDENTIALS;
4177 SASLOpts |= SASL_SEC_NODICTIONARY;
4181 SASLOpts |= SASL_SEC_FORWARD_SECRECY;
4186 SASLOpts |= SASL_SEC_MUTUAL_AUTH;
4188 # endif /* SASL >= 20101 */
4191 SASLOpts |= SASL_SEC_NOPLAINTEXT;
4195 SASLOpts |= SASL_SEC_NOANONYMOUS;
4198 case ' ': /* ignore */
4199 case '\t': /* ignore */
4200 case ',': /* ignore */
4204 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4205 "Warning: Option: %s unknown parameter '%c'\n",
4213 val = strpbrk(val, ", \t");
4220 MaxSLBits = atoi(val);
4229 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4230 "Warning: Option: %s requires SASL support (-DSASL)\n",
4237 SET_STRING_EXP(SrvCertFile);
4239 SET_STRING_EXP(SrvKeyFile);
4241 SET_STRING_EXP(CltCertFile);
4243 SET_STRING_EXP(CltKeyFile);
4245 SET_STRING_EXP(CACertFile);
4247 SET_STRING_EXP(CACertPath);
4249 SET_STRING_EXP(DHParams);
4251 SET_STRING_EXP(CipherList);
4253 SET_STRING_EXP(CertFingerprintAlgorithm);
4254 case O_SRV_SSL_OPTIONS:
4255 pssloptions = &Srv_SSL_Options;
4256 case O_CLT_SSL_OPTIONS:
4257 if (pssloptions == NULL)
4258 pssloptions = &Clt_SSL_Options;
4259 (void) readssloptions(o->o_name, val, pssloptions, '\0');
4261 sm_dprintf("ssloptions=%#lx\n", *pssloptions);
4267 # if OPENSSL_VERSION_NUMBER > 0x00907000L
4268 SET_STRING_EXP(CRLFile);
4269 # else /* OPENSSL_VERSION_NUMBER > 0x00907000L */
4270 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4271 "Warning: Option: %s requires at least OpenSSL 0.9.7\n",
4274 # endif /* OPENSSL_VERSION_NUMBER > 0x00907000L */
4278 # if OPENSSL_VERSION_NUMBER > 0x00907000L
4279 SET_STRING_EXP(CRLPath);
4280 # else /* OPENSSL_VERSION_NUMBER > 0x00907000L */
4281 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4282 "Warning: Option: %s requires at least OpenSSL 0.9.7\n",
4285 # endif /* OPENSSL_VERSION_NUMBER > 0x00907000L */
4286 # endif /* _FFR_CRLPATH */
4289 ** XXX How about options per daemon/client instead of globally?
4290 ** This doesn't work well for some options, e.g., no server cert,
4291 ** but fine for others.
4293 ** XXX Some people may want different certs per server.
4295 ** See also srvfeatures()
4298 case O_TLS_SRV_OPTS:
4299 while (val != NULL && *val != '\0')
4304 TLS_Srv_Opts |= TLS_I_NO_VRFY;
4307 ** Server without a cert? That works only if
4308 ** AnonDH is enabled as cipher, which is not in the
4309 ** default list. Hence the CipherList option must
4310 ** be available. Moreover: which clients support this
4311 ** besides sendmail with this setting?
4315 TLS_Srv_Opts &= ~TLS_I_SRV_CERT;
4317 case ' ': /* ignore */
4318 case '\t': /* ignore */
4319 case ',': /* ignore */
4322 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4323 "Warning: Option: %s unknown parameter '%c'\n",
4331 val = strpbrk(val, ", \t");
4338 PSTRSET(RandFile, val);
4341 #else /* STARTTLS */
4349 case O_SRV_SSL_OPTIONS:
4350 case O_CLT_SSL_OPTIONS:
4355 # endif /* _FFR_CRLPATH */
4357 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4358 "Warning: Option: %s requires TLS support\n",
4362 #endif /* STARTTLS */
4363 #if STARTTLS && _FFR_FIPSMODE
4365 FipsMode = atobool(val);
4367 #endif /* STARTTLS && _FFR_FIPSMODE */
4370 setclientoptions(val);
4374 DataFileBufferSize = atoi(val);
4378 XscriptFileBufferSize = atoi(val);
4381 case O_LDAPDEFAULTSPEC:
4383 ldapmap_set_defaults(val);
4385 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4386 "Warning: Option: %s requires LDAP support (-DLDAPMAP)\n",
4388 #endif /* LDAPMAP */
4393 InputFilterList = newstr(val);
4395 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4396 "Warning: Option: %s requires Milter support (-DMILTER)\n",
4403 milter_set_option(subopt, val, sticky);
4405 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
4406 "Warning: Option: %s requires Milter support (-DMILTER)\n",
4411 case O_QUEUE_FILE_MODE: /* queue file mode */
4412 QueueFileMode = atooct(val) & 0777;
4415 case O_DLVR_MIN: /* deliver by minimum time */
4416 DeliverByMin = convtime(val, 's');
4419 /* modifiers {daemon_flags} for direct submissions */
4420 case O_DIRECTSUBMODIFIERS:
4422 BITMAP256 m; /* ignored */
4423 extern ENVELOPE BlankEnvelope;
4425 macdefine(&BlankEnvelope.e_macro, A_PERM,
4426 macid("{daemon_flags}"),
4427 getmodifiers(val, m));
4432 FastSplit = atoi(val);
4440 UseMSP = atobool(val);
4444 SoftBounce = atobool(val);
4447 case O_REJECTLOGINTERVAL: /* time btwn log msgs while refusing */
4448 RejectLogInterval = convtime(val, 'h');
4451 case O_REQUIRES_DIR_FSYNC:
4452 #if REQUIRES_DIR_FSYNC
4453 RequiresDirfsync = atobool(val);
4454 #else /* REQUIRES_DIR_FSYNC */
4455 /* silently ignored... required for cf file option */
4456 #endif /* REQUIRES_DIR_FSYNC */
4459 case O_CONNECTION_RATE_WINDOW_SIZE:
4460 ConnectionRateWindowSize = convtime(val, 's');
4463 case O_FALLBACKSMARTHOST: /* fallback smart host */
4465 FallbackSmartHost = newstr(val);
4469 HeloName = newstr(val);
4473 case O_REFUSELOWMEM:
4474 RefuseLowMem = atoi(val);
4477 QueueLowMem = atoi(val);
4480 MemoryResource = newstr(val);
4482 #endif /* _FFR_MEMSTAT */
4484 case O_MAXNOOPCOMMANDS:
4485 MaxNOOPCommands = atoi(val);
4490 MessageAccept = newstr(val);
4492 #endif /* _FFR_MSG_ACCEPT */
4494 #if _FFR_QUEUE_RUN_PARANOIA
4495 case O_CHK_Q_RUNNERS:
4496 CheckQueueRunners = atoi(val);
4498 #endif /* _FFR_QUEUE_RUN_PARANOIA */
4500 #if _FFR_EIGHT_BIT_ADDR_OK
4501 case O_EIGHT_BIT_ADDR_OK:
4502 EightBitAddrOK = atobool(val);
4504 #endif /* _FFR_EIGHT_BIT_ADDR_OK */
4506 #if _FFR_ADDR_TYPE_MODES
4507 case O_ADDR_TYPE_MODES:
4508 AddrTypeModes = atobool(val);
4510 #endif /* _FFR_ADDR_TYPE_MODES */
4512 #if _FFR_BADRCPT_SHUTDOWN
4514 BadRcptShutdown = atoi(val);
4518 BadRcptShutdownGood = atoi(val);
4520 #endif /* _FFR_BADRCPT_SHUTDOWN */
4522 #if _FFR_REJECT_NUL_BYTE
4524 RejectNUL = atobool(val);
4526 #endif /* _FFR_REJECT_NUL_BYTE */
4528 #if _FFR_BOUNCE_QUEUE
4530 bouncequeue = newstr(val);
4532 #endif /* _FFR_BOUNCE_QUEUE */
4536 AddBcc = atobool(val);
4539 case O_USECOMPRESSEDIPV6ADDRESSES:
4540 UseCompressedIPv6Addresses = atobool(val);
4546 if (isascii(opt) && isprint(opt))
4547 sm_dprintf("Warning: option %c unknown\n", opt);
4549 sm_dprintf("Warning: option 0x%x unknown\n", opt);
4555 ** Options with suboptions are responsible for taking care
4556 ** of sticky-ness (e.g., that a command line setting is kept
4557 ** when reading in the sendmail.cf file). This has to be done
4558 ** when the suboptions are parsed since each suboption must be
4559 ** sticky, not the root option.
4562 if (sticky && !bitset(OI_SUBOPT, o->o_flags))
4563 setbitn(opt, StickyOpt);
4566 ** SETCLASS -- set a string into a class
4569 ** class -- the class to put the string in.
4570 ** str -- the string to enter
4576 ** puts the word into the symbol table.
4580 setclass(class, str)
4586 if ((str[0] & 0377) == MATCHCLASS)
4596 sm_dprintf("setclass(%s, $=%s)\n",
4597 macname(class), macname(mid));
4598 copy_class(mid, class);
4603 sm_dprintf("setclass(%s, %s)\n", macname(class), str);
4605 s = stab(str, ST_CLASS, ST_ENTER);
4606 setbitn(bitidx(class), s->s_class);
4610 ** MAKEMAPENTRY -- create a map entry
4613 ** line -- the config file line
4616 ** A pointer to the map that has been created.
4617 ** NULL if there was a syntax error.
4620 ** Enters the map into the dictionary.
4633 for (p = line; isascii(*p) && isspace(*p); p++)
4635 if (!(isascii(*p) && isalnum(*p)))
4637 syserr("readcf: config K line: no map name");
4642 while ((isascii(*++p) && isalnum(*p)) || *p == '_' || *p == '.')
4646 while (isascii(*p) && isspace(*p))
4648 if (!(isascii(*p) && isalnum(*p)))
4650 syserr("readcf: config K line, map %s: no map class", mapname);
4654 while (isascii(*++p) && isalnum(*p))
4658 while (isascii(*p) && isspace(*p))
4661 /* look up the class */
4662 class = stab(classname, ST_MAPCLASS, ST_FIND);
4665 syserr("readcf: map %s: class %s not available", mapname,
4671 s = stab(mapname, ST_MAP, ST_ENTER);
4672 s->s_map.map_class = &class->s_mapclass;
4673 s->s_map.map_mname = newstr(mapname);
4675 if (class->s_mapclass.map_parse(&s->s_map, p))
4676 s->s_map.map_mflags |= MF_VALID;
4680 sm_dprintf("map %s, class %s, flags %lx, file %s,\n",
4681 s->s_map.map_mname, s->s_map.map_class->map_cname,
4682 s->s_map.map_mflags, s->s_map.map_file);
4683 sm_dprintf("\tapp %s, domain %s, rebuild %s\n",
4684 s->s_map.map_app, s->s_map.map_domain,
4685 s->s_map.map_rebuild);
4690 ** STRTORWSET -- convert string to rewriting set number
4693 ** p -- the pointer to the string to decode.
4694 ** endp -- if set, store the trailing delimiter here.
4695 ** stabmode -- ST_ENTER to create this entry, ST_FIND if
4696 ** it must already exist.
4699 ** The appropriate ruleset number.
4700 ** -1 if it is not valid (error already printed)
4704 strtorwset(p, endp, stabmode)
4710 static int nextruleset = MAXRWSETS;
4712 while (isascii(*p) && isspace(*p))
4716 syserr("invalid ruleset name: \"%.20s\"", p);
4721 ruleset = strtol(p, endp, 10);
4722 if (ruleset >= MAXRWSETS / 2 || ruleset < 0)
4724 syserr("bad ruleset %d (%d max)",
4725 ruleset, MAXRWSETS / 2);
4736 while (*p != '\0' && isascii(*p) && (isalnum(*p) || *p == '_'))
4738 if (q == p || !(isascii(*q) && isalpha(*q)))
4740 /* no valid characters */
4741 syserr("invalid ruleset name: \"%.20s\"", q);
4744 while (isascii(*p) && isspace(*p))
4749 s = stab(q, ST_RULESET, stabmode);
4756 if (stabmode == ST_ENTER && delim == '=')
4758 while (isascii(*++p) && isspace(*p))
4760 if (!(isascii(*p) && isdigit(*p)))
4762 syserr("bad ruleset definition \"%s\" (number required after `=')", q);
4767 ruleset = strtol(p, endp, 10);
4768 if (ruleset >= MAXRWSETS / 2 || ruleset < 0)
4770 syserr("bad ruleset number %d in \"%s\" (%d max)",
4771 ruleset, q, MAXRWSETS / 2);
4780 if (s->s_ruleset >= 0)
4781 ruleset = s->s_ruleset;
4782 else if ((ruleset = --nextruleset) < MAXRWSETS / 2)
4784 syserr("%s: too many named rulesets (%d max)",
4789 if (s->s_ruleset >= 0 &&
4791 ruleset != s->s_ruleset)
4793 syserr("%s: ruleset changed value (old %d, new %d)",
4794 q, s->s_ruleset, ruleset);
4795 ruleset = s->s_ruleset;
4797 else if (ruleset >= 0)
4799 s->s_ruleset = ruleset;
4801 if (stabmode == ST_ENTER && ruleset >= 0)
4805 if (RuleSetNames[ruleset] != NULL)
4806 sm_free(RuleSetNames[ruleset]); /* XXX */
4807 if (delim != '\0' && (h = strchr(q, delim)) != NULL)
4809 RuleSetNames[ruleset] = newstr(q);
4810 if (delim == '/' && h != NULL)
4811 *h = delim; /* put back delim */
4817 ** SETTIMEOUT -- set an individual timeout
4820 ** name -- the name of the timeout.
4821 ** val -- the value of the timeout.
4822 ** sticky -- if set, don't let other setoptions override
4829 /* set if Timeout sub-option is stuck */
4830 static BITMAP256 StickyTimeoutOpt;
4832 static struct timeoutinfo
4834 char *to_name; /* long name of timeout */
4835 unsigned char to_code; /* code for option */
4838 #define TO_INITIAL 0x01
4839 { "initial", TO_INITIAL },
4840 #define TO_MAIL 0x02
4841 { "mail", TO_MAIL },
4842 #define TO_RCPT 0x03
4843 { "rcpt", TO_RCPT },
4844 #define TO_DATAINIT 0x04
4845 { "datainit", TO_DATAINIT },
4846 #define TO_DATABLOCK 0x05
4847 { "datablock", TO_DATABLOCK },
4848 #define TO_DATAFINAL 0x06
4849 { "datafinal", TO_DATAFINAL },
4850 #define TO_COMMAND 0x07
4851 { "command", TO_COMMAND },
4852 #define TO_RSET 0x08
4853 { "rset", TO_RSET },
4854 #define TO_HELO 0x09
4855 { "helo", TO_HELO },
4856 #define TO_QUIT 0x0A
4857 { "quit", TO_QUIT },
4858 #define TO_MISC 0x0B
4859 { "misc", TO_MISC },
4860 #define TO_IDENT 0x0C
4861 { "ident", TO_IDENT },
4862 #define TO_FILEOPEN 0x0D
4863 { "fileopen", TO_FILEOPEN },
4864 #define TO_CONNECT 0x0E
4865 { "connect", TO_CONNECT },
4866 #define TO_ICONNECT 0x0F
4867 { "iconnect", TO_ICONNECT },
4868 #define TO_QUEUEWARN 0x10
4869 { "queuewarn", TO_QUEUEWARN },
4870 { "queuewarn.*", TO_QUEUEWARN },
4871 #define TO_QUEUEWARN_NORMAL 0x11
4872 { "queuewarn.normal", TO_QUEUEWARN_NORMAL },
4873 #define TO_QUEUEWARN_URGENT 0x12
4874 { "queuewarn.urgent", TO_QUEUEWARN_URGENT },
4875 #define TO_QUEUEWARN_NON_URGENT 0x13
4876 { "queuewarn.non-urgent", TO_QUEUEWARN_NON_URGENT },
4877 #define TO_QUEUERETURN 0x14
4878 { "queuereturn", TO_QUEUERETURN },
4879 { "queuereturn.*", TO_QUEUERETURN },
4880 #define TO_QUEUERETURN_NORMAL 0x15
4881 { "queuereturn.normal", TO_QUEUERETURN_NORMAL },
4882 #define TO_QUEUERETURN_URGENT 0x16
4883 { "queuereturn.urgent", TO_QUEUERETURN_URGENT },
4884 #define TO_QUEUERETURN_NON_URGENT 0x17
4885 { "queuereturn.non-urgent", TO_QUEUERETURN_NON_URGENT },
4886 #define TO_HOSTSTATUS 0x18
4887 { "hoststatus", TO_HOSTSTATUS },
4888 #define TO_RESOLVER_RETRANS 0x19
4889 { "resolver.retrans", TO_RESOLVER_RETRANS },
4890 #define TO_RESOLVER_RETRANS_NORMAL 0x1A
4891 { "resolver.retrans.normal", TO_RESOLVER_RETRANS_NORMAL },
4892 #define TO_RESOLVER_RETRANS_FIRST 0x1B
4893 { "resolver.retrans.first", TO_RESOLVER_RETRANS_FIRST },
4894 #define TO_RESOLVER_RETRY 0x1C
4895 { "resolver.retry", TO_RESOLVER_RETRY },
4896 #define TO_RESOLVER_RETRY_NORMAL 0x1D
4897 { "resolver.retry.normal", TO_RESOLVER_RETRY_NORMAL },
4898 #define TO_RESOLVER_RETRY_FIRST 0x1E
4899 { "resolver.retry.first", TO_RESOLVER_RETRY_FIRST },
4900 #define TO_CONTROL 0x1F
4901 { "control", TO_CONTROL },
4902 #define TO_LHLO 0x20
4903 { "lhlo", TO_LHLO },
4904 #define TO_AUTH 0x21
4905 { "auth", TO_AUTH },
4906 #define TO_STARTTLS 0x22
4907 { "starttls", TO_STARTTLS },
4908 #define TO_ACONNECT 0x23
4909 { "aconnect", TO_ACONNECT },
4910 #define TO_QUEUEWARN_DSN 0x24
4911 { "queuewarn.dsn", TO_QUEUEWARN_DSN },
4912 #define TO_QUEUERETURN_DSN 0x25
4913 { "queuereturn.dsn", TO_QUEUERETURN_DSN },
4919 settimeout(name, val, sticky)
4924 register struct timeoutinfo *to;
4929 sm_dprintf("settimeout(%s = %s)", name, val);
4931 for (to = TimeOutTab; to->to_name != NULL; to++)
4933 if (sm_strcasecmp(to->to_name, name) == 0)
4937 if (to->to_name == NULL)
4939 errno = 0; /* avoid bogus error text */
4940 syserr("settimeout: invalid timeout %s", name);
4945 ** See if this option is preset for us.
4948 if (!sticky && bitnset(to->to_code, StickyTimeoutOpt))
4951 sm_dprintf(" (ignored)\n");
4958 toval = convtime(val, 'm');
4961 switch (to->to_code)
4964 TimeOuts.to_initial = toval;
4968 TimeOuts.to_mail = toval;
4972 TimeOuts.to_rcpt = toval;
4976 TimeOuts.to_datainit = toval;
4980 TimeOuts.to_datablock = toval;
4984 TimeOuts.to_datafinal = toval;
4988 TimeOuts.to_nextcommand = toval;
4992 TimeOuts.to_rset = toval;
4996 TimeOuts.to_helo = toval;
5000 TimeOuts.to_quit = toval;
5004 TimeOuts.to_miscshort = toval;
5008 TimeOuts.to_ident = toval;
5012 TimeOuts.to_fileopen = toval;
5016 TimeOuts.to_connect = toval;
5020 TimeOuts.to_iconnect = toval;
5024 TimeOuts.to_aconnect = toval;
5028 toval = convtime(val, 'h');
5029 TimeOuts.to_q_warning[TOC_NORMAL] = toval;
5030 TimeOuts.to_q_warning[TOC_URGENT] = toval;
5031 TimeOuts.to_q_warning[TOC_NONURGENT] = toval;
5032 TimeOuts.to_q_warning[TOC_DSN] = toval;
5036 case TO_QUEUEWARN_NORMAL:
5037 toval = convtime(val, 'h');
5038 TimeOuts.to_q_warning[TOC_NORMAL] = toval;
5041 case TO_QUEUEWARN_URGENT:
5042 toval = convtime(val, 'h');
5043 TimeOuts.to_q_warning[TOC_URGENT] = toval;
5046 case TO_QUEUEWARN_NON_URGENT:
5047 toval = convtime(val, 'h');
5048 TimeOuts.to_q_warning[TOC_NONURGENT] = toval;
5051 case TO_QUEUEWARN_DSN:
5052 toval = convtime(val, 'h');
5053 TimeOuts.to_q_warning[TOC_DSN] = toval;
5056 case TO_QUEUERETURN:
5057 toval = convtime(val, 'd');
5058 TimeOuts.to_q_return[TOC_NORMAL] = toval;
5059 TimeOuts.to_q_return[TOC_URGENT] = toval;
5060 TimeOuts.to_q_return[TOC_NONURGENT] = toval;
5061 TimeOuts.to_q_return[TOC_DSN] = toval;
5065 case TO_QUEUERETURN_NORMAL:
5066 toval = convtime(val, 'd');
5067 TimeOuts.to_q_return[TOC_NORMAL] = toval;
5070 case TO_QUEUERETURN_URGENT:
5071 toval = convtime(val, 'd');
5072 TimeOuts.to_q_return[TOC_URGENT] = toval;
5075 case TO_QUEUERETURN_NON_URGENT:
5076 toval = convtime(val, 'd');
5077 TimeOuts.to_q_return[TOC_NONURGENT] = toval;
5080 case TO_QUEUERETURN_DSN:
5081 toval = convtime(val, 'd');
5082 TimeOuts.to_q_return[TOC_DSN] = toval;
5086 MciInfoTimeout = toval;
5089 case TO_RESOLVER_RETRANS:
5090 toval = convtime(val, 's');
5091 TimeOuts.res_retrans[RES_TO_DEFAULT] = toval;
5092 TimeOuts.res_retrans[RES_TO_FIRST] = toval;
5093 TimeOuts.res_retrans[RES_TO_NORMAL] = toval;
5097 case TO_RESOLVER_RETRY:
5099 TimeOuts.res_retry[RES_TO_DEFAULT] = i;
5100 TimeOuts.res_retry[RES_TO_FIRST] = i;
5101 TimeOuts.res_retry[RES_TO_NORMAL] = i;
5105 case TO_RESOLVER_RETRANS_NORMAL:
5106 TimeOuts.res_retrans[RES_TO_NORMAL] = convtime(val, 's');
5109 case TO_RESOLVER_RETRY_NORMAL:
5110 TimeOuts.res_retry[RES_TO_NORMAL] = atoi(val);
5113 case TO_RESOLVER_RETRANS_FIRST:
5114 TimeOuts.res_retrans[RES_TO_FIRST] = convtime(val, 's');
5117 case TO_RESOLVER_RETRY_FIRST:
5118 TimeOuts.res_retry[RES_TO_FIRST] = atoi(val);
5122 TimeOuts.to_control = toval;
5126 TimeOuts.to_lhlo = toval;
5131 TimeOuts.to_auth = toval;
5137 TimeOuts.to_starttls = toval;
5139 #endif /* STARTTLS */
5142 syserr("settimeout: invalid timeout %s", name);
5148 for (i = 0; i <= addopts; i++)
5149 setbitn(to->to_code + i, StickyTimeoutOpt);
5153 ** INITTIMEOUTS -- parse and set timeout values
5156 ** val -- a pointer to the values. If NULL, do initial
5158 ** sticky -- if set, don't let other setoptions override
5159 ** this suboption value.
5165 ** Initializes the TimeOuts structure
5169 inittimeouts(val, sticky)
5176 sm_dprintf("inittimeouts(%s)\n", val == NULL ? "<NULL>" : val);
5179 TimeOuts.to_connect = (time_t) 0 SECONDS;
5180 TimeOuts.to_aconnect = (time_t) 0 SECONDS;
5181 TimeOuts.to_iconnect = (time_t) 0 SECONDS;
5182 TimeOuts.to_initial = (time_t) 5 MINUTES;
5183 TimeOuts.to_helo = (time_t) 5 MINUTES;
5184 TimeOuts.to_mail = (time_t) 10 MINUTES;
5185 TimeOuts.to_rcpt = (time_t) 1 HOUR;
5186 TimeOuts.to_datainit = (time_t) 5 MINUTES;
5187 TimeOuts.to_datablock = (time_t) 1 HOUR;
5188 TimeOuts.to_datafinal = (time_t) 1 HOUR;
5189 TimeOuts.to_rset = (time_t) 5 MINUTES;
5190 TimeOuts.to_quit = (time_t) 2 MINUTES;
5191 TimeOuts.to_nextcommand = (time_t) 1 HOUR;
5192 TimeOuts.to_miscshort = (time_t) 2 MINUTES;
5194 TimeOuts.to_ident = (time_t) 5 SECONDS;
5195 #else /* IDENTPROTO */
5196 TimeOuts.to_ident = (time_t) 0 SECONDS;
5197 #endif /* IDENTPROTO */
5198 TimeOuts.to_fileopen = (time_t) 60 SECONDS;
5199 TimeOuts.to_control = (time_t) 2 MINUTES;
5200 TimeOuts.to_lhlo = (time_t) 2 MINUTES;
5202 TimeOuts.to_auth = (time_t) 10 MINUTES;
5205 TimeOuts.to_starttls = (time_t) 1 HOUR;
5206 #endif /* STARTTLS */
5209 sm_dprintf("Timeouts:\n");
5210 sm_dprintf(" connect = %ld\n",
5211 (long) TimeOuts.to_connect);
5212 sm_dprintf(" aconnect = %ld\n",
5213 (long) TimeOuts.to_aconnect);
5214 sm_dprintf(" initial = %ld\n",
5215 (long) TimeOuts.to_initial);
5216 sm_dprintf(" helo = %ld\n", (long) TimeOuts.to_helo);
5217 sm_dprintf(" mail = %ld\n", (long) TimeOuts.to_mail);
5218 sm_dprintf(" rcpt = %ld\n", (long) TimeOuts.to_rcpt);
5219 sm_dprintf(" datainit = %ld\n",
5220 (long) TimeOuts.to_datainit);
5221 sm_dprintf(" datablock = %ld\n",
5222 (long) TimeOuts.to_datablock);
5223 sm_dprintf(" datafinal = %ld\n",
5224 (long) TimeOuts.to_datafinal);
5225 sm_dprintf(" rset = %ld\n", (long) TimeOuts.to_rset);
5226 sm_dprintf(" quit = %ld\n", (long) TimeOuts.to_quit);
5227 sm_dprintf(" nextcommand = %ld\n",
5228 (long) TimeOuts.to_nextcommand);
5229 sm_dprintf(" miscshort = %ld\n",
5230 (long) TimeOuts.to_miscshort);
5231 sm_dprintf(" ident = %ld\n", (long) TimeOuts.to_ident);
5232 sm_dprintf(" fileopen = %ld\n",
5233 (long) TimeOuts.to_fileopen);
5234 sm_dprintf(" lhlo = %ld\n",
5235 (long) TimeOuts.to_lhlo);
5236 sm_dprintf(" control = %ld\n",
5237 (long) TimeOuts.to_control);
5244 while (isascii(*val) && isspace(*val))
5248 for (p = val; *p != '\0' && *p != ','; p++)
5253 if (isascii(*val) && isdigit(*val))
5255 /* old syntax -- set everything */
5256 TimeOuts.to_mail = convtime(val, 'm');
5257 TimeOuts.to_rcpt = TimeOuts.to_mail;
5258 TimeOuts.to_datainit = TimeOuts.to_mail;
5259 TimeOuts.to_datablock = TimeOuts.to_mail;
5260 TimeOuts.to_datafinal = TimeOuts.to_mail;
5261 TimeOuts.to_nextcommand = TimeOuts.to_mail;
5264 setbitn(TO_MAIL, StickyTimeoutOpt);
5265 setbitn(TO_RCPT, StickyTimeoutOpt);
5266 setbitn(TO_DATAINIT, StickyTimeoutOpt);
5267 setbitn(TO_DATABLOCK, StickyTimeoutOpt);
5268 setbitn(TO_DATAFINAL, StickyTimeoutOpt);
5269 setbitn(TO_COMMAND, StickyTimeoutOpt);
5275 register char *q = strchr(val, ':');
5277 if (q == NULL && (q = strchr(val, '=')) == NULL)
5283 settimeout(val, q, sticky);