summaryrefslogtreecommitdiffstats
path: root/usr.sbin/sendmail/src/readcf.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/sendmail/src/readcf.c')
-rw-r--r--usr.sbin/sendmail/src/readcf.c1301
1 files changed, 1085 insertions, 216 deletions
diff --git a/usr.sbin/sendmail/src/readcf.c b/usr.sbin/sendmail/src/readcf.c
index ad7da2a..c98d82c 100644
--- a/usr.sbin/sendmail/src/readcf.c
+++ b/usr.sbin/sendmail/src/readcf.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1983 Eric P. Allman
+ * Copyright (c) 1983, 1995 Eric P. Allman
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
@@ -33,14 +33,12 @@
*/
#ifndef lint
-static char sccsid[] = "@(#)readcf.c 8.23.1.3 (Berkeley) 3/5/95";
+static char sccsid[] = "@(#)readcf.c 8.138 (Berkeley) 11/20/95";
#endif /* not lint */
# include "sendmail.h"
-# include <pwd.h>
# include <grp.h>
#if NAMED_BIND
-# include <arpa/nameser.h>
# include <resolv.h>
#endif
@@ -76,6 +74,7 @@ static char sccsid[] = "@(#)readcf.c 8.23.1.3 (Berkeley) 3/5/95";
** Kmapname mapclass arguments....
** Define keyed lookup of a given class.
** Arguments are class dependent.
+** Eenvar=value Set the environment value to the given value.
**
** Parameters:
** cfname -- control file name.
@@ -90,6 +89,7 @@ static char sccsid[] = "@(#)readcf.c 8.23.1.3 (Berkeley) 3/5/95";
** Builds several internal tables.
*/
+void
readcf(cfname, safe, e)
char *cfname;
bool safe;
@@ -104,14 +104,18 @@ readcf(cfname, safe, e)
int nfuzzy;
char *file;
bool optional;
+ int mid;
char buf[MAXLINE];
register char *p;
extern char **copyplist();
struct stat statb;
char exbuf[MAXLINE];
char pvpbuf[MAXLINE + MAXATOM];
- extern char *munchstring();
- extern void makemapentry();
+ static char *null_list[1] = { NULL };
+ extern char *munchstring __P((char *, char **));
+ extern void fileclass __P((int, char *, char *, bool, bool));
+ extern void toomany __P((int, int));
+ extern void translate_dollars __P((char *));
FileName = cfname;
LineNumber = 0;
@@ -137,7 +141,7 @@ readcf(cfname, safe, e)
if (OpMode != MD_TEST && bitset(S_IWGRP|S_IWOTH, statb.st_mode))
{
- if (OpMode == MD_DAEMON || OpMode == MD_FREEZE)
+ if (OpMode == MD_DAEMON || OpMode == MD_INITALIAS)
fprintf(stderr, "%s: WARNING: dangerous write permissions\n",
FileName);
#ifdef LOG
@@ -160,52 +164,8 @@ readcf(cfname, safe, e)
continue;
}
- /* map $ into \201 for macro expansion */
- for (p = bp; *p != '\0'; p++)
- {
- if (*p == '#' && p > bp && ConfigLevel >= 3)
- {
- /* this is an on-line comment */
- register char *e;
-
- switch (*--p & 0377)
- {
- case MACROEXPAND:
- /* it's from $# -- let it go through */
- p++;
- break;
-
- case '\\':
- /* it's backslash escaped */
- (void) strcpy(p, p + 1);
- break;
-
- default:
- /* delete preceeding white space */
- while (isascii(*p) && isspace(*p) && p > bp)
- p--;
- if ((e = strchr(++p, '\n')) != NULL)
- (void) strcpy(p, e);
- else
- p[0] = p[1] = '\0';
- break;
- }
- continue;
- }
-
- if (*p != '$')
- continue;
-
- if (p[1] == '$')
- {
- /* actual dollar sign.... */
- (void) strcpy(p, p + 1);
- continue;
- }
-
- /* convert to macro expansion character */
- *p = MACROEXPAND;
- }
+ /* do macro expansion mappings */
+ translate_dollars(bp);
/* interpret this line */
errno = 0;
@@ -240,9 +200,9 @@ readcf(cfname, safe, e)
/* expand and save the LHS */
*p = '\0';
- expand(&bp[1], exbuf, &exbuf[sizeof exbuf], e);
+ expand(&bp[1], exbuf, sizeof exbuf, e);
rwp->r_lhs = prescan(exbuf, '\t', pvpbuf,
- sizeof pvpbuf, NULL);
+ sizeof pvpbuf, NULL, NULL);
nfuzzy = 0;
if (rwp->r_lhs != NULL)
{
@@ -316,7 +276,10 @@ readcf(cfname, safe, e)
}
}
else
+ {
syserr("R line: null LHS");
+ rwp->r_lhs = null_list;
+ }
/* expand and save the RHS */
while (*++p == '\t')
@@ -325,9 +288,9 @@ readcf(cfname, safe, e)
while (*p != '\0' && *p != '\t')
p++;
*p = '\0';
- expand(q, exbuf, &exbuf[sizeof exbuf], e);
+ expand(q, exbuf, sizeof exbuf, e);
rwp->r_rhs = prescan(exbuf, '\t', pvpbuf,
- sizeof pvpbuf, NULL);
+ sizeof pvpbuf, NULL, NULL);
if (rwp->r_rhs != NULL)
{
register char **ap;
@@ -377,40 +340,51 @@ readcf(cfname, safe, e)
}
}
else
+ {
syserr("R line: null RHS");
+ rwp->r_rhs = null_list;
+ }
break;
case 'S': /* select rewriting set */
- for (p = &bp[1]; isascii(*p) && isspace(*p); p++)
- continue;
- if (!isascii(*p) || !isdigit(*p))
- {
- syserr("invalid argument to S line: \"%.20s\"",
- &bp[1]);
+ expand(&bp[1], exbuf, sizeof exbuf, e);
+ ruleset = strtorwset(exbuf, NULL, ST_ENTER);
+ if (ruleset < 0)
break;
- }
- ruleset = atoi(p);
- if (ruleset >= MAXRWSETS || ruleset < 0)
+ rwp = RewriteRules[ruleset];
+ if (rwp != NULL)
{
- syserr("bad ruleset %d (%d max)", ruleset, MAXRWSETS);
- ruleset = 0;
+ while (rwp->r_next != NULL)
+ rwp = rwp->r_next;
+ fprintf(stderr, "WARNING: Ruleset %s redefined\n",
+ &bp[1]);
}
- rwp = NULL;
break;
case 'D': /* macro definition */
- p = munchstring(&bp[2], NULL);
- define(bp[1], newstr(p), e);
+ mid = macid(&bp[1], &ep);
+ p = munchstring(ep, NULL);
+ define(mid, newstr(p), e);
break;
case 'H': /* required header line */
- (void) chompheader(&bp[1], TRUE, e);
+ (void) chompheader(&bp[1], TRUE, NULL, e);
break;
case 'C': /* word class */
- /* scan the list of words and set class for all */
- expand(&bp[2], exbuf, &exbuf[sizeof exbuf], e);
- for (p = exbuf; *p != '\0'; )
+ case 'T': /* trusted user (set class `t') */
+ if (bp[0] == 'C')
+ {
+ mid = macid(&bp[1], &ep);
+ expand(ep, exbuf, sizeof exbuf, e);
+ p = exbuf;
+ }
+ else
+ {
+ mid = 't';
+ p = &bp[1];
+ }
+ while (*p != '\0')
{
register char *wd;
char delim;
@@ -423,13 +397,14 @@ readcf(cfname, safe, e)
delim = *p;
*p = '\0';
if (wd[0] != '\0')
- setclass(bp[1], wd);
+ setclass(mid, wd);
*p = delim;
}
break;
case 'F': /* word class from file */
- for (p = &bp[2]; isascii(*p) && isspace(*p); )
+ mid = macid(&bp[1], &ep);
+ for (p = ep; isascii(*p) && isspace(*p); )
p++;
if (p[0] == '-' && p[1] == 'o')
{
@@ -437,22 +412,27 @@ readcf(cfname, safe, e)
while (*p != '\0' && !(isascii(*p) && isspace(*p)))
p++;
while (isascii(*p) && isspace(*p))
- *p++;
+ p++;
}
else
optional = FALSE;
file = p;
- while (*p != '\0' && !(isascii(*p) && isspace(*p)))
- p++;
- if (*p == '\0')
+ if (*file == '|')
p = "%s";
else
{
- *p = '\0';
- while (isascii(*++p) && isspace(*p))
- continue;
+ while (*p != '\0' && !(isascii(*p) && isspace(*p)))
+ p++;
+ if (*p == '\0')
+ p = "%s";
+ else
+ {
+ *p = '\0';
+ while (isascii(*++p) && isspace(*p))
+ continue;
+ }
}
- fileclass(bp[1], file, p, safe, optional);
+ fileclass(mid, file, p, safe, optional);
break;
#ifdef XLA
@@ -475,7 +455,7 @@ readcf(cfname, safe, e)
toomany('P', MAXPRIORITIES);
break;
}
- for (p = &bp[1]; *p != '\0' && *p != '=' && *p != '\t'; p++)
+ for (p = &bp[1]; *p != '\0' && *p != '='; p++)
continue;
if (*p == '\0')
goto badline;
@@ -485,10 +465,6 @@ readcf(cfname, safe, e)
NumPriorities++;
break;
- case 'T': /* trusted user(s) */
- /* this option is obsolete, but will be ignored */
- break;
-
case 'V': /* configuration syntax version */
for (p = &bp[1]; isascii(*p) && isspace(*p); p++)
continue;
@@ -499,13 +475,28 @@ readcf(cfname, safe, e)
break;
}
ConfigLevel = strtol(p, &ep, 10);
+
+ /*
+ ** Do heuristic tweaking for back compatibility.
+ */
+
if (ConfigLevel >= 5)
{
/* level 5 configs have short name in $w */
p = macvalue('w', e);
if (p != NULL && (p = strchr(p, '.')) != NULL)
*p = '\0';
+ define('w', macvalue('w', e), e);
}
+ if (ConfigLevel >= 6)
+ {
+ ColonOkInAddr = FALSE;
+ }
+
+ /*
+ ** Look for vendor code.
+ */
+
if (*ep++ == '/')
{
/* extract vendor code */
@@ -520,7 +511,15 @@ readcf(cfname, safe, e)
break;
case 'K':
- makemapentry(&bp[1]);
+ expand(&bp[1], exbuf, sizeof exbuf, e);
+ (void) makemapentry(exbuf);
+ break;
+
+ case 'E':
+ p = strchr(bp, '=');
+ if (p != NULL)
+ *p++ = '\0';
+ setuserenv(&bp[1], p);
break;
default:
@@ -532,24 +531,133 @@ readcf(cfname, safe, e)
}
if (ferror(cf))
{
- syserr("I/O read error", cfname);
+ syserr("I/O read error");
exit(EX_OSFILE);
}
fclose(cf);
FileName = NULL;
- if (stab("host", ST_MAP, ST_FIND) == NULL)
+ /* initialize host maps from local service tables */
+ inithostmaps();
+
+ /* determine if we need to do special name-server frotz */
{
- /* user didn't initialize: set up host map */
- strcpy(buf, "host host");
-#if NAMED_BIND
- if (ConfigLevel >= 2)
- strcat(buf, " -a.");
+ int nmaps;
+ char *maptype[MAXMAPSTACK];
+ short mapreturn[MAXMAPACTIONS];
+
+ nmaps = switch_map_find("hosts", maptype, mapreturn);
+ UseNameServer = FALSE;
+ if (nmaps > 0 && nmaps <= MAXMAPSTACK)
+ {
+ register int mapno;
+
+ for (mapno = 0; mapno < nmaps && !UseNameServer; mapno++)
+ {
+ if (strcmp(maptype[mapno], "dns") == 0)
+ UseNameServer = TRUE;
+ }
+ }
+
+#ifdef HESIOD
+ nmaps = switch_map_find("passwd", maptype, mapreturn);
+ UseHesiod = FALSE;
+ if (nmaps > 0 && nmaps <= MAXMAPSTACK)
+ {
+ register int mapno;
+
+ for (mapno = 0; mapno < nmaps && !UseHesiod; mapno++)
+ {
+ if (strcmp(maptype[mapno], "hesiod") == 0)
+ UseHesiod = TRUE;
+ }
+ }
#endif
- makemapentry(buf);
}
}
/*
+** TRANSLATE_DOLLARS -- convert $x into internal form
+**
+** Actually does all appropriate pre-processing of a config line
+** to turn it into internal form.
+**
+** Parameters:
+** bp -- the buffer to translate.
+**
+** Returns:
+** None. The buffer is translated in place. Since the
+** translations always make the buffer shorter, this is
+** safe without a size parameter.
+*/
+
+void
+translate_dollars(bp)
+ char *bp;
+{
+ register char *p;
+ auto char *ep;
+
+ for (p = bp; *p != '\0'; p++)
+ {
+ if (*p == '#' && p > bp && ConfigLevel >= 3)
+ {
+ /* this is an on-line comment */
+ register char *e;
+
+ switch (*--p & 0377)
+ {
+ case MACROEXPAND:
+ /* it's from $# -- let it go through */
+ p++;
+ break;
+
+ case '\\':
+ /* it's backslash escaped */
+ (void) strcpy(p, p + 1);
+ break;
+
+ default:
+ /* delete preceeding white space */
+ while (isascii(*p) && isspace(*p) &&
+ *p != '\n' && p > bp)
+ p--;
+ if ((e = strchr(++p, '\n')) != NULL)
+ (void) strcpy(p, e);
+ else
+ *p-- = '\0';
+ break;
+ }
+ continue;
+ }
+
+ if (*p != '$' || p[1] == '\0')
+ continue;
+
+ if (p[1] == '$')
+ {
+ /* actual dollar sign.... */
+ (void) strcpy(p, p + 1);
+ continue;
+ }
+
+ /* convert to macro expansion character */
+ *p++ = MACROEXPAND;
+
+ /* special handling for $=, $~, $&, and $? */
+ if (*p == '=' || *p == '~' || *p == '&' || *p == '?')
+ p++;
+
+ /* convert macro name to code */
+ *p = macid(p, &ep);
+ if (ep != p)
+ strcpy(p + 1, ep);
+ }
+
+ /* strip trailing white space from the line */
+ while (--p > bp && isascii(*p) && isspace(*p))
+ *p = '\0';
+}
+ /*
** TOOMANY -- signal too many of some option
**
** Parameters:
@@ -563,8 +671,9 @@ readcf(cfname, safe, e)
** gives a syserr.
*/
+void
toomany(id, maxcnt)
- char id;
+ int id;
int maxcnt;
{
syserr("too many %c lines, %d max", id, maxcnt);
@@ -589,6 +698,7 @@ toomany(id, maxcnt)
** the named class.
*/
+void
fileclass(class, filename, fmt, safe, optional)
int class;
char *filename;
@@ -597,7 +707,9 @@ fileclass(class, filename, fmt, safe, optional)
bool optional;
{
FILE *f;
- struct stat stbuf;
+ int sff;
+ int pid;
+ register char *p;
char buf[MAXLINE];
if (tTd(37, 2))
@@ -605,42 +717,49 @@ fileclass(class, filename, fmt, safe, optional)
if (filename[0] == '|')
{
- syserr("fileclass: pipes (F%c%s) not supported due to security problems",
- class, filename);
- return;
- }
- if (stat(filename, &stbuf) < 0)
- {
- if (tTd(37, 2))
- printf(" cannot stat (%s)\n", errstring(errno));
- if (!optional)
- syserr("fileclass: cannot stat %s", filename);
- return;
- }
- if (!S_ISREG(stbuf.st_mode))
- {
- syserr("fileclass: %s not a regular file", filename);
- return;
+ auto int fd;
+ int i;
+ char *argv[MAXPV + 1];
+
+ i = 0;
+ for (p = strtok(&filename[1], " \t"); p != NULL; p = strtok(NULL, " \t"))
+ {
+ if (i >= MAXPV)
+ break;
+ argv[i++] = p;
+ }
+ argv[i] = NULL;
+ pid = prog_open(argv, &fd, CurEnv);
+ if (pid < 0)
+ f = NULL;
+ else
+ f = fdopen(fd, "r");
}
- if (!safe && access(filename, R_OK) < 0)
+ else
{
- syserr("fileclass: access denied on %s", filename);
- return;
+ pid = -1;
+ sff = SFF_REGONLY;
+ if (safe)
+ sff |= SFF_OPENASROOT;
+ f = safefopen(filename, O_RDONLY, 0, sff);
}
- f = fopen(filename, "r");
if (f == NULL)
{
- syserr("fileclass: cannot open %s", filename);
+ if (!optional)
+ syserr("fileclass: cannot open %s", filename);
return;
}
while (fgets(buf, sizeof buf, f) != NULL)
{
- register STAB *s;
register char *p;
-# ifdef SCANF
+# if SCANF
char wordbuf[MAXNAME+1];
+# endif
+ if (buf[0] == '#')
+ continue;
+# if SCANF
if (sscanf(buf, fmt, wordbuf) != 1)
continue;
p = wordbuf;
@@ -675,6 +794,8 @@ fileclass(class, filename, fmt, safe, optional)
}
(void) fclose(f);
+ if (pid > 0)
+ (void) waitfor(pid);
}
/*
** MAKEMAILER -- define a new mailer.
@@ -682,12 +803,19 @@ fileclass(class, filename, fmt, safe, optional)
** Parameters:
** line -- description of mailer. This is in labeled
** fields. The fields are:
-** P -- the path to the mailer
-** F -- the flags associated with the mailer
** A -- the argv for this mailer
-** S -- the sender rewriting set
-** R -- the recipient rewriting set
+** C -- the character set for MIME conversions
+** D -- the directory to run in
** E -- the eol string
+** F -- the flags associated with the mailer
+** L -- the maximum line length
+** M -- the maximum message size
+** N -- the niceness at which to run
+** P -- the path to the mailer
+** R -- the recipient rewriting set
+** S -- the sender rewriting set
+** T -- the mailer type (for DSNs)
+** U -- the uid to run as
** The first word is the canonical name of the mailer.
**
** Returns:
@@ -697,6 +825,7 @@ fileclass(class, filename, fmt, safe, optional)
** enters the mailer into the mailer table.
*/
+void
makemailer(line)
char *line;
{
@@ -709,18 +838,20 @@ makemailer(line)
extern int NextMailer;
extern char **makeargv();
extern char *munchstring();
- extern long atol();
/* allocate a mailer and set up defaults */
m = (struct mailer *) xalloc(sizeof *m);
bzero((char *) m, sizeof *m);
m->m_eol = "\n";
+ m->m_uid = m->m_gid = 0;
/* collect the mailer name */
for (p = line; *p != '\0' && *p != ',' && !(isascii(*p) && isspace(*p)); p++)
continue;
if (*p != '\0')
*p++ = '\0';
+ if (line[0] == '\0')
+ syserr("name required for mailer");
m->m_name = newstr(line);
/* now scan through and assign info from the fields */
@@ -750,6 +881,8 @@ makemailer(line)
switch (fcode)
{
case 'P': /* pathname */
+ if (*p == '\0')
+ syserr("mailer %s: empty path name", m->m_name);
m->m_mailer = newstr(p);
break;
@@ -761,12 +894,9 @@ makemailer(line)
case 'S': /* sender rewriting ruleset */
case 'R': /* recipient rewriting ruleset */
- i = strtol(p, &endp, 10);
- if (i < 0 || i >= MAXRWSETS)
- {
- syserr("invalid rewrite set, %d max", MAXRWSETS);
+ i = strtorwset(p, &endp, ST_ENTER);
+ if (i < 0)
return;
- }
if (fcode == 'S')
m->m_sh_rwset = m->m_se_rwset = i;
else
@@ -775,13 +905,9 @@ makemailer(line)
p = endp;
if (*p++ == '/')
{
- i = strtol(p, NULL, 10);
- if (i < 0 || i >= MAXRWSETS)
- {
- syserr("invalid rewrite set, %d max",
- MAXRWSETS);
+ i = strtorwset(p, NULL, ST_ENTER);
+ if (i < 0)
return;
- }
if (fcode == 'S')
m->m_sh_rwset = i;
else
@@ -790,10 +916,16 @@ makemailer(line)
break;
case 'E': /* end of line string */
+ if (*p == '\0')
+ syserr("mailer %s: null end-of-line string",
+ m->m_name);
m->m_eol = newstr(p);
break;
case 'A': /* argument vector */
+ if (*p == '\0')
+ syserr("mailer %s: null argument vector",
+ m->m_name);
m->m_argv = makeargv(p);
break;
@@ -805,23 +937,118 @@ makemailer(line)
m->m_linelimit = atoi(p);
break;
+ case 'N': /* run niceness */
+ m->m_nice = atoi(p);
+ break;
+
case 'D': /* working directory */
+ if (*p == '\0')
+ syserr("mailer %s: null working directory",
+ m->m_name);
m->m_execdir = newstr(p);
break;
+
+ case 'C': /* default charset */
+ if (*p == '\0')
+ syserr("mailer %s: null charset", m->m_name);
+ m->m_defcharset = newstr(p);
+ break;
+
+ case 'T': /* MTA-Name/Address/Diagnostic types */
+ /* extract MTA name type; default to "dns" */
+ m->m_mtatype = newstr(p);
+ p = strchr(m->m_mtatype, '/');
+ if (p != NULL)
+ {
+ *p++ = '\0';
+ if (*p == '\0')
+ p = NULL;
+ }
+ if (*m->m_mtatype == '\0')
+ m->m_mtatype = "dns";
+
+ /* extract address type; default to "rfc822" */
+ m->m_addrtype = p;
+ if (p != NULL)
+ p = strchr(p, '/');
+ if (p != NULL)
+ {
+ *p++ = '\0';
+ if (*p == '\0')
+ p = NULL;
+ }
+ if (m->m_addrtype == NULL || *m->m_addrtype == '\0')
+ m->m_addrtype = "rfc822";
+
+ /* extract diagnostic type; default to "smtp" */
+ m->m_diagtype = p;
+ if (m->m_diagtype == NULL || *m->m_diagtype == '\0')
+ m->m_diagtype = "smtp";
+ break;
+
+ case 'U': /* user id */
+ if (isascii(*p) && !isdigit(*p))
+ {
+ char *q = p;
+ struct passwd *pw;
+
+ while (*p != '\0' && isascii(*p) &&
+ (isalnum(*p) || strchr("-_", *p) != NULL))
+ p++;
+ while (isascii(*p) && isspace(*p))
+ *p++ = '\0';
+ if (*p != '\0')
+ *p++ = '\0';
+ if (*q == '\0')
+ syserr("mailer %s: null user name",
+ m->m_name);
+ pw = sm_getpwnam(q);
+ if (pw == NULL)
+ syserr("readcf: mailer U= flag: unknown user %s", q);
+ else
+ {
+ m->m_uid = pw->pw_uid;
+ m->m_gid = pw->pw_gid;
+ }
+ }
+ else
+ {
+ auto char *q;
+
+ m->m_uid = strtol(p, &q, 0);
+ p = q;
+ }
+ while (isascii(*p) && isspace(*p))
+ p++;
+ if (*p == '\0')
+ break;
+ if (isascii(*p) && !isdigit(*p))
+ {
+ char *q = p;
+ struct group *gr;
+
+ while (isascii(*p) && isalnum(*p))
+ p++;
+ *p++ = '\0';
+ if (*q == '\0')
+ syserr("mailer %s: null group name",
+ m->m_name);
+ gr = getgrnam(q);
+ if (gr == NULL)
+ syserr("readcf: mailer U= flag: unknown group %s", q);
+ else
+ m->m_gid = gr->gr_gid;
+ }
+ else
+ {
+ m->m_gid = strtol(p, NULL, 0);
+ }
+ break;
}
p = delimptr;
}
- /* do some heuristic cleanup for back compatibility */
- if (bitnset(M_LIMITS, m->m_flags))
- {
- if (m->m_linelimit == 0)
- m->m_linelimit = SMTPLINELIM;
- if (ConfigLevel < 2)
- setbitn(M_7BITS, m->m_flags);
- }
-
/* do some rationality checking */
if (m->m_argv == NULL)
{
@@ -840,6 +1067,27 @@ makemailer(line)
return;
}
+ /* do some heuristic cleanup for back compatibility */
+ if (bitnset(M_LIMITS, m->m_flags))
+ {
+ if (m->m_linelimit == 0)
+ m->m_linelimit = SMTPLINELIM;
+ if (ConfigLevel < 2)
+ setbitn(M_7BITS, m->m_flags);
+ }
+
+ if (strcmp(m->m_mailer, "[IPC]") == 0 ||
+ strcmp(m->m_mailer, "[TCP]") == 0)
+ {
+ if (m->m_mtatype == NULL)
+ m->m_mtatype = "dns";
+ if (m->m_addrtype == NULL)
+ m->m_addrtype = "rfc822";
+ if (m->m_diagtype == NULL)
+ m->m_diagtype = "smtp";
+ }
+
+ /* enter the mailer into the symbol table */
s = stab(m->m_name, ST_MAILER, ST_ENTER);
if (s->s_mailer != NULL)
{
@@ -875,7 +1123,7 @@ munchstring(p, delimptr)
bool quotemode = FALSE;
static char buf[MAXLINE];
- for (q = buf; *p != '\0'; p++)
+ for (q = buf; *p != '\0' && q < &buf[sizeof buf - 1]; p++)
{
if (backslash)
{
@@ -973,6 +1221,7 @@ makeargv(p)
** prints rewrite rules.
*/
+void
printrules()
{
register struct rewrite *rwp;
@@ -993,7 +1242,52 @@ printrules()
}
}
}
+ /*
+** PRINTMAILER -- print mailer structure (for debugging)
+**
+** Parameters:
+** m -- the mailer to print
+**
+** Returns:
+** none.
+*/
+
+void
+printmailer(m)
+ register MAILER *m;
+{
+ int j;
+
+ printf("mailer %d (%s): P=%s S=%d/%d R=%d/%d M=%ld U=%d:%d F=",
+ m->m_mno, m->m_name,
+ m->m_mailer, m->m_se_rwset, m->m_sh_rwset,
+ m->m_re_rwset, m->m_rh_rwset, m->m_maxsize,
+ m->m_uid, m->m_gid);
+ for (j = '\0'; j <= '\177'; j++)
+ if (bitnset(j, m->m_flags))
+ (void) putchar(j);
+ printf(" L=%d E=", m->m_linelimit);
+ xputs(m->m_eol);
+ if (m->m_defcharset != NULL)
+ printf(" C=%s", m->m_defcharset);
+ printf(" T=%s/%s/%s",
+ m->m_mtatype == NULL ? "<undefined>" : m->m_mtatype,
+ m->m_addrtype == NULL ? "<undefined>" : m->m_addrtype,
+ m->m_diagtype == NULL ? "<undefined>" : m->m_diagtype);
+ if (m->m_argv != NULL)
+ {
+ char **a = m->m_argv;
+ printf(" A=");
+ while (*a != NULL)
+ {
+ if (a != m->m_argv)
+ printf(" ");
+ xputs(*a++);
+ }
+ }
+ printf("\n");
+}
/*
** SETOPTION -- set global processing option
**
@@ -1015,6 +1309,7 @@ printrules()
*/
static BITMAP StickyOpt; /* set if option is stuck */
+extern void settimeout __P((char *, char *));
#if NAMED_BIND
@@ -1040,23 +1335,222 @@ struct resolverflags
#endif
+struct optioninfo
+{
+ char *o_name; /* long name of option */
+ u_char o_code; /* short name of option */
+ bool o_safe; /* safe for random people to use */
+} OptionTab[] =
+{
+ "SevenBitInput", '7', TRUE,
+#if MIME8TO7
+ "EightBitMode", '8', TRUE,
+#endif
+ "AliasFile", 'A', FALSE,
+ "AliasWait", 'a', FALSE,
+ "BlankSub", 'B', FALSE,
+ "MinFreeBlocks", 'b', TRUE,
+ "CheckpointInterval", 'C', TRUE,
+ "HoldExpensive", 'c', FALSE,
+ "AutoRebuildAliases", 'D', FALSE,
+ "DeliveryMode", 'd', TRUE,
+ "ErrorHeader", 'E', FALSE,
+ "ErrorMode", 'e', TRUE,
+ "TempFileMode", 'F', FALSE,
+ "SaveFromLine", 'f', FALSE,
+ "MatchGECOS", 'G', FALSE,
+ "HelpFile", 'H', FALSE,
+ "MaxHopCount", 'h', FALSE,
+ "ResolverOptions", 'I', FALSE,
+ "IgnoreDots", 'i', TRUE,
+ "ForwardPath", 'J', FALSE,
+ "SendMimeErrors", 'j', TRUE,
+ "ConnectionCacheSize", 'k', FALSE,
+ "ConnectionCacheTimeout", 'K', FALSE,
+ "UseErrorsTo", 'l', FALSE,
+ "LogLevel", 'L', FALSE,
+ "MeToo", 'm', TRUE,
+ "CheckAliases", 'n', FALSE,
+ "OldStyleHeaders", 'o', TRUE,
+ "DaemonPortOptions", 'O', FALSE,
+ "PrivacyOptions", 'p', TRUE,
+ "PostmasterCopy", 'P', FALSE,
+ "QueueFactor", 'q', FALSE,
+ "QueueDirectory", 'Q', FALSE,
+ "DontPruneRoutes", 'R', FALSE,
+ "Timeout", 'r', TRUE,
+ "StatusFile", 'S', FALSE,
+ "SuperSafe", 's', TRUE,
+ "QueueTimeout", 'T', FALSE,
+ "TimeZoneSpec", 't', FALSE,
+ "UserDatabaseSpec", 'U', FALSE,
+ "DefaultUser", 'u', FALSE,
+ "FallbackMXhost", 'V', FALSE,
+ "Verbose", 'v', TRUE,
+ "TryNullMXList", 'w', TRUE,
+ "QueueLA", 'x', FALSE,
+ "RefuseLA", 'X', FALSE,
+ "RecipientFactor", 'y', FALSE,
+ "ForkEachJob", 'Y', FALSE,
+ "ClassFactor", 'z', FALSE,
+ "RetryFactor", 'Z', FALSE,
+#define O_QUEUESORTORD 0x81
+ "QueueSortOrder", O_QUEUESORTORD, TRUE,
+#define O_HOSTSFILE 0x82
+ "HostsFile", O_HOSTSFILE, FALSE,
+#define O_MQA 0x83
+ "MinQueueAge", O_MQA, TRUE,
+#define O_MHSA 0x84
+/*
+ "MaxHostStatAge", O_MHSA, TRUE,
+*/
+#define O_DEFCHARSET 0x85
+ "DefaultCharSet", O_DEFCHARSET, TRUE,
+#define O_SSFILE 0x86
+ "ServiceSwitchFile", O_SSFILE, FALSE,
+#define O_DIALDELAY 0x87
+ "DialDelay", O_DIALDELAY, TRUE,
+#define O_NORCPTACTION 0x88
+ "NoRecipientAction", O_NORCPTACTION, TRUE,
+#define O_SAFEFILEENV 0x89
+ "SafeFileEnvironment", O_SAFEFILEENV, FALSE,
+#define O_MAXMSGSIZE 0x8a
+ "MaxMessageSize", O_MAXMSGSIZE, FALSE,
+#define O_COLONOKINADDR 0x8b
+ "ColonOkInAddr", O_COLONOKINADDR, TRUE,
+#define O_MAXQUEUERUN 0x8c
+ "MaxQueueRunSize", O_MAXQUEUERUN, TRUE,
+#define O_MAXCHILDREN 0x8d
+/*
+ "MaxDaemonChildren", O_MAXCHILDREN, FALSE,
+*/
+#define O_KEEPCNAMES 0x8e
+ "DontExpandCnames", O_KEEPCNAMES, FALSE,
+#define O_MUSTQUOTE 0x8f
+/*
+ "MustQuoteChars", O_MUSTQUOTE, FALSE,
+*/
+#define O_SMTPGREETING 0x90
+ "SmtpGreetingMessage", O_SMTPGREETING, FALSE,
+#define O_UNIXFROM 0x91
+ "UnixFromLine", O_UNIXFROM, FALSE,
+#define O_OPCHARS 0x92
+ "OperatorChars", O_OPCHARS, FALSE,
+#define O_DONTINITGRPS 0x93
+ "DontInitGroups", O_DONTINITGRPS, TRUE,
+#define O_SLFH 0x94
+#ifdef LOTUS_NOTES_HACK
+ "SingleLineFromHeader", O_SLFH, TRUE,
+#endif
+
+ NULL, '\0', FALSE,
+};
+
+
+
+void
setoption(opt, val, safe, sticky, e)
- char opt;
+ int opt;
char *val;
bool safe;
bool sticky;
register ENVELOPE *e;
{
register char *p;
+ register struct optioninfo *o;
+ char *subopt;
+ char buf[50];
extern bool atobool();
extern time_t convtime();
extern int QueueLA;
extern int RefuseLA;
extern bool Warn_Q_option;
- extern bool trusteduser();
+
+ errno = 0;
+ if (opt == ' ')
+ {
+ /* full word options */
+ struct optioninfo *sel;
+
+ p = strchr(val, '=');
+ if (p == NULL)
+ p = &val[strlen(val)];
+ while (*--p == ' ')
+ continue;
+ while (*++p == ' ')
+ *p = '\0';
+ if (p == val)
+ {
+ syserr("readcf: null option name");
+ return;
+ }
+ if (*p == '=')
+ *p++ = '\0';
+ while (*p == ' ')
+ p++;
+ subopt = strchr(val, '.');
+ if (subopt != NULL)
+ *subopt++ = '\0';
+ sel = NULL;
+ for (o = OptionTab; o->o_name != NULL; o++)
+ {
+ if (strncasecmp(o->o_name, val, strlen(val)) != 0)
+ continue;
+ if (strlen(o->o_name) == strlen(val))
+ {
+ /* completely specified -- this must be it */
+ sel = NULL;
+ break;
+ }
+ if (sel != NULL)
+ break;
+ sel = o;
+ }
+ if (sel != NULL && o->o_name == NULL)
+ o = sel;
+ else if (o->o_name == NULL)
+ {
+ syserr("readcf: unknown option name %s", val);
+ return;
+ }
+ else if (sel != NULL)
+ {
+ syserr("readcf: ambiguous option name %s (matches %s and %s)",
+ val, sel->o_name, o->o_name);
+ return;
+ }
+ if (strlen(val) != strlen(o->o_name))
+ {
+ bool oldVerbose = Verbose;
+
+ Verbose = TRUE;
+ message("Option %s used as abbreviation for %s",
+ val, o->o_name);
+ Verbose = oldVerbose;
+ }
+ opt = o->o_code;
+ val = p;
+ }
+ else
+ {
+ for (o = OptionTab; o->o_name != NULL; o++)
+ {
+ if (o->o_code == opt)
+ break;
+ }
+ subopt = NULL;
+ }
if (tTd(37, 1))
- printf("setoption %c=%s", opt, val);
+ {
+ printf(isascii(opt) && isprint(opt) ?
+ "setoption %s (%c).%s=" :
+ "setoption %s (0x%x).%s=",
+ o->o_name == NULL ? "<unknown>" : o->o_name,
+ opt,
+ subopt == NULL ? "" : subopt);
+ xputs(val);
+ }
/*
** See if this option is preset for us.
@@ -1075,7 +1569,7 @@ setoption(opt, val, safe, sticky, e)
if (!safe && RealUid == 0)
safe = TRUE;
- if (!safe && strchr("bCdeijLmoprsvw7", opt) == NULL)
+ if (!safe && !o->o_safe)
{
if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
{
@@ -1085,6 +1579,7 @@ setoption(opt, val, safe, sticky, e)
{
if (tTd(37, 1))
printf("(Resetting uid)");
+ endpwent();
(void) setgid(RealGid);
(void) setuid(RealUid);
}
@@ -1093,12 +1588,53 @@ setoption(opt, val, safe, sticky, e)
if (tTd(37, 1))
printf("\n");
- switch (opt)
+ switch (opt & 0xff)
{
case '7': /* force seven-bit input */
- SevenBit = atobool(val);
+ SevenBitInput = atobool(val);
break;
+#if MIME8TO7
+ case '8': /* handling of 8-bit input */
+ switch (*val)
+ {
+ case 'm': /* convert 8-bit, convert MIME */
+ MimeMode = MM_CVTMIME|MM_MIME8BIT;
+ break;
+
+ case 'p': /* pass 8 bit, convert MIME */
+ MimeMode = MM_CVTMIME|MM_PASS8BIT;
+ break;
+
+ case 's': /* strict adherence */
+ MimeMode = MM_CVTMIME;
+ break;
+
+#if 0
+ case 'r': /* reject 8-bit, don't convert MIME */
+ MimeMode = 0;
+ break;
+
+ case 'j': /* "just send 8" */
+ MimeMode = MM_PASS8BIT;
+ break;
+
+ case 'a': /* encode 8 bit if available */
+ MimeMode = MM_MIME8BIT|MM_PASS8BIT|MM_CVTMIME;
+ break;
+
+ case 'c': /* convert 8 bit to MIME, never 7 bit */
+ MimeMode = MM_MIME8BIT;
+ break;
+#endif
+
+ default:
+ syserr("Unknown 8-bit mode %c", *val);
+ exit(EX_USAGE);
+ }
+ break;
+#endif
+
case 'A': /* set default alias file */
if (val[0] == '\0')
setalias("aliases");
@@ -1145,8 +1681,9 @@ setoption(opt, val, safe, sticky, e)
break;
case SM_QUEUE: /* queue only */
+ case SM_DEFER: /* queue only and defer map lookups */
#ifndef QUEUE
- syserr("need QUEUE to set -odqueue");
+ syserr("need QUEUE to set -odqueue or -oddefer");
#endif /* QUEUE */
/* fall through..... */
@@ -1177,9 +1714,6 @@ setoption(opt, val, safe, sticky, e)
case EM_MAIL: /* mail back */
case EM_BERKNET: /* do berknet error processing */
case EM_WRITE: /* write back (or mail) */
- HoldErrs = TRUE;
- /* fall through... */
-
case EM_PRINT: /* print errors normally (default) */
e->e_errormode = *val;
break;
@@ -1199,6 +1733,7 @@ setoption(opt, val, safe, sticky, e)
break;
case 'g': /* default gid */
+ g_opt:
if (isascii(*val) && isdigit(*val))
DefGid = atoi(val);
else
@@ -1208,7 +1743,8 @@ setoption(opt, val, safe, sticky, e)
DefGid = -1;
gr = getgrnam(val);
if (gr == NULL)
- syserr("readcf: option g: unknown group %s", val);
+ syserr("readcf: option %c: unknown group %s",
+ opt, val);
else
DefGid = gr->gr_gid;
}
@@ -1227,7 +1763,6 @@ setoption(opt, val, safe, sticky, e)
case 'I': /* use internet domain name server */
#if NAMED_BIND
- UseNameServer = TRUE;
for (p = val; *p != 0; )
{
bool clearmode;
@@ -1249,6 +1784,11 @@ setoption(opt, val, safe, sticky, e)
p++;
if (*p != '\0')
*p++ = '\0';
+ if (strcasecmp(q, "HasWildcardMX") == 0)
+ {
+ HasWildcardMX = !clearmode;
+ continue;
+ }
for (rfp = ResolverFlags; rfp->rf_name != NULL; rfp++)
{
if (strcasecmp(q, rfp->rf_name) == 0)
@@ -1262,7 +1802,8 @@ setoption(opt, val, safe, sticky, e)
_res.options |= rfp->rf_bits;
}
if (tTd(8, 2))
- printf("_res.options = %x\n", _res.options);
+ printf("_res.options = %x, HasWildcardMX = %d\n",
+ _res.options, HasWildcardMX);
#else
usrerr("name server (I option) specified but BIND not compiled in");
#endif
@@ -1318,7 +1859,11 @@ setoption(opt, val, safe, sticky, e)
/* 'N' available -- was "net name" */
case 'O': /* daemon options */
+#ifdef DAEMON
setdaemonoptions(val);
+#else
+ syserr("DaemonPortOptions (O option) set but DAEMON not compiled in");
+#endif
break;
case 'o': /* assume old style headers */
@@ -1379,7 +1924,10 @@ setoption(opt, val, safe, sticky, e)
break;
case 'r': /* read timeout */
- settimeouts(val);
+ if (subopt == NULL)
+ inittimeouts(val);
+ else
+ settimeout(subopt, val);
break;
case 'S': /* status file */
@@ -1398,9 +1946,9 @@ setoption(opt, val, safe, sticky, e)
if (p != NULL)
{
*p++ = '\0';
- TimeOuts.to_q_warning = convtime(p, 'd');
+ settimeout("queuewarn", p);
}
- TimeOuts.to_q_return = convtime(val, 'h');
+ settimeout("queuereturn", val);
break;
case 't': /* time zone name */
@@ -1412,6 +1960,14 @@ setoption(opt, val, safe, sticky, e)
break;
case 'u': /* set default uid */
+ for (p = val; *p != '\0'; p++)
+ {
+ if (*p == '.' || *p == '/' || *p == ':')
+ {
+ *p++ = '\0';
+ break;
+ }
+ }
if (isascii(*val) && isdigit(*val))
DefUid = atoi(val);
else
@@ -1419,14 +1975,22 @@ setoption(opt, val, safe, sticky, e)
register struct passwd *pw;
DefUid = -1;
- pw = getpwnam(val);
+ pw = sm_getpwnam(val);
if (pw == NULL)
syserr("readcf: option u: unknown user %s", val);
else
+ {
DefUid = pw->pw_uid;
+ DefGid = pw->pw_gid;
+ }
}
setdefuser();
- break;
+
+ /* handle the group if it is there */
+ if (*p == '\0')
+ break;
+ val = p;
+ goto g_opt;
case 'V': /* fallback MX host */
FallBackMX = newstr(val);
@@ -1466,19 +2030,133 @@ setoption(opt, val, safe, sticky, e)
WkTimeFact = atoi(val);
break;
+ case O_QUEUESORTORD: /* queue sorting order */
+ switch (*val)
+ {
+ case 'h': /* Host first */
+ case 'H':
+ QueueSortOrder = QS_BYHOST;
+ break;
+
+ case 'p': /* Priority order */
+ case 'P':
+ QueueSortOrder = QS_BYPRIORITY;
+ break;
+
+ default:
+ syserr("Invalid queue sort order \"%s\"", val);
+ }
+ break;
+
+ case O_HOSTSFILE: /* pathname of /etc/hosts file */
+ HostsFile = newstr(val);
+ break;
+
+ case O_MQA: /* minimum queue age between deliveries */
+ MinQueueAge = convtime(val, 'm');
+ break;
+
+ case O_MHSA: /* maximum age of cached host status */
+ MaxHostStatAge = convtime(val, 'm');
+ break;
+
+ case O_DEFCHARSET: /* default character set for mimefying */
+ DefaultCharSet = newstr(denlstring(val, TRUE, TRUE));
+ break;
+
+ case O_SSFILE: /* service switch file */
+ ServiceSwitchFile = newstr(val);
+ break;
+
+ case O_DIALDELAY: /* delay for dial-on-demand operation */
+ DialDelay = convtime(val, 's');
+ break;
+
+ case O_NORCPTACTION: /* what to do if no recipient */
+ if (strcasecmp(val, "none") == 0)
+ NoRecipientAction = NRA_NO_ACTION;
+ else if (strcasecmp(val, "add-to") == 0)
+ NoRecipientAction = NRA_ADD_TO;
+ else if (strcasecmp(val, "add-apparently-to") == 0)
+ NoRecipientAction = NRA_ADD_APPARENTLY_TO;
+ else if (strcasecmp(val, "add-bcc") == 0)
+ NoRecipientAction = NRA_ADD_BCC;
+ else if (strcasecmp(val, "add-to-undisclosed") == 0)
+ NoRecipientAction = NRA_ADD_TO_UNDISCLOSED;
+ else
+ syserr("Invalid NoRecipientAction: %s", val);
+ break;
+
+ case O_SAFEFILEENV: /* chroot() environ for writing to files */
+ SafeFileEnv = newstr(val);
+ break;
+
+ case O_MAXMSGSIZE: /* maximum message size */
+ MaxMessageSize = atol(val);
+ break;
+
+ case O_COLONOKINADDR: /* old style handling of colon addresses */
+ ColonOkInAddr = atobool(val);
+ break;
+
+ case O_MAXQUEUERUN: /* max # of jobs in a single queue run */
+ MaxQueueRun = atol(val);
+ break;
+
+ case O_MAXCHILDREN: /* max # of children of daemon */
+ MaxChildren = atoi(val);
+ break;
+
+ case O_KEEPCNAMES: /* don't expand CNAME records */
+ DontExpandCnames = atobool(val);
+ break;
+
+ case O_MUSTQUOTE: /* must quote these characters in phrases */
+ strcpy(buf, "@,;:\\()[]");
+ if (strlen(val) < sizeof buf - 10)
+ strcat(buf, val);
+ MustQuoteChars = newstr(buf);
+ break;
+
+ case O_SMTPGREETING: /* SMTP greeting message (old $e macro) */
+ SmtpGreeting = newstr(munchstring(val, NULL));
+ break;
+
+ case O_UNIXFROM: /* UNIX From_ line (old $l macro) */
+ UnixFromLine = newstr(munchstring(val, NULL));
+ break;
+
+ case O_OPCHARS: /* operator characters (old $o macro) */
+ OperatorChars = newstr(munchstring(val, NULL));
+ break;
+
+ case O_DONTINITGRPS: /* don't call initgroups(3) */
+ DontInitGroups = atobool(val);
+ break;
+
+ case O_SLFH: /* make sure from fits on one line */
+ SingleLineFromHeader = atobool(val);
+ break;
+
default:
+ if (tTd(37, 1))
+ {
+ if (isascii(opt) && isprint(opt))
+ printf("Warning: option %c unknown\n", opt);
+ else
+ printf("Warning: option 0x%x unknown\n", opt);
+ }
break;
}
if (sticky)
setbitn(opt, StickyOpt);
- return;
}
/*
-** SETCLASS -- set a word into a class
+** SETCLASS -- set a string into a class
**
** Parameters:
-** class -- the class to put the word in.
-** word -- the word to enter
+** class -- the class to put the string in.
+** str -- the string to enter
**
** Returns:
** none.
@@ -1487,15 +2165,16 @@ setoption(opt, val, safe, sticky, e)
** puts the word into the symbol table.
*/
-setclass(class, word)
+void
+setclass(class, str)
int class;
- char *word;
+ char *str;
{
register STAB *s;
if (tTd(37, 8))
- printf("setclass(%c, %s)\n", class, word);
- s = stab(word, ST_CLASS, ST_ENTER);
+ printf("setclass(%s, %s)\n", macname(class), str);
+ s = stab(str, ST_CLASS, ST_ENTER);
setbitn(class, s->s_class);
}
/*
@@ -1505,14 +2184,14 @@ setclass(class, word)
** line -- the config file line
**
** Returns:
-** TRUE if it successfully entered the map entry.
-** FALSE otherwise (usually syntax error).
+** A pointer to the map that has been created.
+** NULL if there was a syntax error.
**
** Side Effects:
** Enters the map into the dictionary.
*/
-void
+MAP *
makemapentry(line)
char *line;
{
@@ -1527,11 +2206,11 @@ makemapentry(line)
if (!(isascii(*p) && isalnum(*p)))
{
syserr("readcf: config K line: no map name");
- return;
+ return NULL;
}
mapname = p;
- while (isascii(*++p) && isalnum(*p))
+ while ((isascii(*++p) && isalnum(*p)) || *p == '_' || *p == '.')
continue;
if (*p != '\0')
*p++ = '\0';
@@ -1540,7 +2219,7 @@ makemapentry(line)
if (!(isascii(*p) && isalnum(*p)))
{
syserr("readcf: config K line, map %s: no map class", mapname);
- return;
+ return NULL;
}
classname = p;
while (isascii(*++p) && isalnum(*p))
@@ -1555,7 +2234,7 @@ makemapentry(line)
if (class == NULL)
{
syserr("readcf: map %s: class %s not available", mapname, classname);
- return;
+ return NULL;
}
/* enter the map */
@@ -1577,9 +2256,128 @@ makemapentry(line)
s->s_map.map_domain == NULL ? "(null)" : s->s_map.map_domain,
s->s_map.map_rebuild == NULL ? "(null)" : s->s_map.map_rebuild);
}
+
+ return &s->s_map;
}
/*
-** SETTIMEOUTS -- parse and set timeout values
+** STRTORWSET -- convert string to rewriting set number
+**
+** Parameters:
+** p -- the pointer to the string to decode.
+** endp -- if set, store the trailing delimiter here.
+** stabmode -- ST_ENTER to create this entry, ST_FIND if
+** it must already exist.
+**
+** Returns:
+** The appropriate ruleset number.
+** -1 if it is not valid (error already printed)
+*/
+
+int
+strtorwset(p, endp, stabmode)
+ char *p;
+ char **endp;
+ int stabmode;
+{
+ int ruleset;
+ static int nextruleset = MAXRWSETS;
+
+ while (isascii(*p) && isspace(*p))
+ p++;
+ if (!isascii(*p))
+ {
+ syserr("invalid ruleset name: \"%.20s\"", p);
+ return -1;
+ }
+ if (isdigit(*p))
+ {
+ ruleset = strtol(p, endp, 10);
+ if (ruleset >= MAXRWSETS / 2 || ruleset < 0)
+ {
+ syserr("bad ruleset %d (%d max)",
+ ruleset, MAXRWSETS / 2);
+ ruleset = -1;
+ }
+ }
+ else
+ {
+ STAB *s;
+ char delim;
+ char *q;
+
+ q = p;
+ while (*p != '\0' && isascii(*p) &&
+ (isalnum(*p) || *p == '_'))
+ p++;
+ if (q == p || !isalpha(*q))
+ {
+ /* no valid characters */
+ syserr("invalid ruleset name: \"%.20s\"", q);
+ return -1;
+ }
+ while (isascii(*p) && isspace(*p))
+ *p++ = '\0';
+ delim = *p;
+ if (delim != '\0')
+ *p = '\0';
+ s = stab(q, ST_RULESET, stabmode);
+ if (delim != '\0')
+ *p = delim;
+
+ if (s == NULL)
+ {
+ syserr("unknown ruleset %s", q);
+ return -1;
+ }
+
+ if (stabmode == ST_ENTER && delim == '=')
+ {
+ while (isascii(*++p) && isspace(*p))
+ continue;
+ if (!isdigit(*p))
+ {
+ syserr("bad ruleset definition \"%s\" (number required after `=')", q);
+ ruleset = -1;
+ }
+ else
+ {
+ ruleset = strtol(p, endp, 10);
+ if (ruleset >= MAXRWSETS / 2 || ruleset < 0)
+ {
+ syserr("bad ruleset number %d in \"%s\" (%d max)",
+ ruleset, q, MAXRWSETS / 2);
+ ruleset = -1;
+ }
+ }
+ }
+ else
+ {
+ if (endp != NULL)
+ *endp = p;
+ if (s->s_ruleset > 0)
+ ruleset = s->s_ruleset;
+ else if ((ruleset = --nextruleset) < MAXRWSETS / 2)
+ {
+ syserr("%s: too many named rulesets (%d max)",
+ q, MAXRWSETS / 2);
+ ruleset = -1;
+ }
+ }
+ if (s->s_ruleset > 0 && ruleset >= 0 && ruleset != s->s_ruleset)
+ {
+ syserr("%s: ruleset changed value (old %d, new %d)",
+ q, ruleset, s->s_ruleset);
+ ruleset = s->s_ruleset;
+ }
+ else if (ruleset > 0)
+ {
+ s->s_ruleset = ruleset;
+ }
+ }
+ return ruleset;
+}
+ /*
+** INITTIMEOUTS -- parse and set timeout values
**
** Parameters:
** val -- a pointer to the values. If NULL, do initial
@@ -1596,7 +2394,8 @@ makemapentry(line)
#define MINUTES * 60
#define HOUR * 3600
-settimeouts(val)
+void
+inittimeouts(val)
register char *val;
{
register char *p;
@@ -1604,6 +2403,7 @@ settimeouts(val)
if (val == NULL)
{
+ TimeOuts.to_connect = (time_t) 0 SECONDS;
TimeOuts.to_initial = (time_t) 5 MINUTES;
TimeOuts.to_helo = (time_t) 5 MINUTES;
TimeOuts.to_mail = (time_t) 10 MINUTES;
@@ -1615,7 +2415,12 @@ settimeouts(val)
TimeOuts.to_quit = (time_t) 2 MINUTES;
TimeOuts.to_nextcommand = (time_t) 1 HOUR;
TimeOuts.to_miscshort = (time_t) 2 MINUTES;
+#if IDENTPROTO
TimeOuts.to_ident = (time_t) 30 SECONDS;
+#else
+ TimeOuts.to_ident = (time_t) 0 SECONDS;
+#endif
+ TimeOuts.to_fileopen = (time_t) 60 SECONDS;
return;
}
@@ -1643,43 +2448,107 @@ settimeouts(val)
}
else
{
- register char *q = strchr(val, '=');
- time_t to;
+ register char *q = strchr(val, ':');
- if (q == NULL)
+ if (q == NULL && (q = strchr(val, '=')) == NULL)
{
/* syntax error */
continue;
}
*q++ = '\0';
- to = convtime(q, 'm');
-
- if (strcasecmp(val, "initial") == 0)
- TimeOuts.to_initial = to;
- else if (strcasecmp(val, "mail") == 0)
- TimeOuts.to_mail = to;
- else if (strcasecmp(val, "rcpt") == 0)
- TimeOuts.to_rcpt = to;
- else if (strcasecmp(val, "datainit") == 0)
- TimeOuts.to_datainit = to;
- else if (strcasecmp(val, "datablock") == 0)
- TimeOuts.to_datablock = to;
- else if (strcasecmp(val, "datafinal") == 0)
- TimeOuts.to_datafinal = to;
- else if (strcasecmp(val, "command") == 0)
- TimeOuts.to_nextcommand = to;
- else if (strcasecmp(val, "rset") == 0)
- TimeOuts.to_rset = to;
- else if (strcasecmp(val, "helo") == 0)
- TimeOuts.to_helo = to;
- else if (strcasecmp(val, "quit") == 0)
- TimeOuts.to_quit = to;
- else if (strcasecmp(val, "misc") == 0)
- TimeOuts.to_miscshort = to;
- else if (strcasecmp(val, "ident") == 0)
- TimeOuts.to_ident = to;
- else
- syserr("settimeouts: invalid timeout %s", val);
+ settimeout(val, q);
}
}
}
+ /*
+** SETTIMEOUT -- set an individual timeout
+**
+** Parameters:
+** name -- the name of the timeout.
+** val -- the value of the timeout.
+**
+** Returns:
+** none.
+*/
+
+void
+settimeout(name, val)
+ char *name;
+ char *val;
+{
+ register char *p;
+ time_t to;
+ extern time_t convtime();
+
+ to = convtime(val, 'm');
+ p = strchr(name, '.');
+ if (p != NULL)
+ *p++ = '\0';
+
+ if (strcasecmp(name, "initial") == 0)
+ TimeOuts.to_initial = to;
+ else if (strcasecmp(name, "mail") == 0)
+ TimeOuts.to_mail = to;
+ else if (strcasecmp(name, "rcpt") == 0)
+ TimeOuts.to_rcpt = to;
+ else if (strcasecmp(name, "datainit") == 0)
+ TimeOuts.to_datainit = to;
+ else if (strcasecmp(name, "datablock") == 0)
+ TimeOuts.to_datablock = to;
+ else if (strcasecmp(name, "datafinal") == 0)
+ TimeOuts.to_datafinal = to;
+ else if (strcasecmp(name, "command") == 0)
+ TimeOuts.to_nextcommand = to;
+ else if (strcasecmp(name, "rset") == 0)
+ TimeOuts.to_rset = to;
+ else if (strcasecmp(name, "helo") == 0)
+ TimeOuts.to_helo = to;
+ else if (strcasecmp(name, "quit") == 0)
+ TimeOuts.to_quit = to;
+ else if (strcasecmp(name, "misc") == 0)
+ TimeOuts.to_miscshort = to;
+ else if (strcasecmp(name, "ident") == 0)
+ TimeOuts.to_ident = to;
+ else if (strcasecmp(name, "fileopen") == 0)
+ TimeOuts.to_fileopen = to;
+ else if (strcasecmp(name, "connect") == 0)
+ TimeOuts.to_connect = to;
+ else if (strcasecmp(name, "queuewarn") == 0)
+ {
+ to = convtime(val, 'h');
+ if (p == NULL || strcmp(p, "*") == 0)
+ {
+ TimeOuts.to_q_warning[TOC_NORMAL] = to;
+ TimeOuts.to_q_warning[TOC_URGENT] = to;
+ TimeOuts.to_q_warning[TOC_NONURGENT] = to;
+ }
+ else if (strcasecmp(p, "normal") == 0)
+ TimeOuts.to_q_warning[TOC_NORMAL] = to;
+ else if (strcasecmp(p, "urgent") == 0)
+ TimeOuts.to_q_warning[TOC_URGENT] = to;
+ else if (strcasecmp(p, "non-urgent") == 0)
+ TimeOuts.to_q_warning[TOC_NONURGENT] = to;
+ else
+ syserr("settimeout: invalid queuewarn subtimeout %s", p);
+ }
+ else if (strcasecmp(name, "queuereturn") == 0)
+ {
+ to = convtime(val, 'd');
+ if (p == NULL || strcmp(p, "*") == 0)
+ {
+ TimeOuts.to_q_return[TOC_NORMAL] = to;
+ TimeOuts.to_q_return[TOC_URGENT] = to;
+ TimeOuts.to_q_return[TOC_NONURGENT] = to;
+ }
+ else if (strcasecmp(p, "normal") == 0)
+ TimeOuts.to_q_return[TOC_NORMAL] = to;
+ else if (strcasecmp(p, "urgent") == 0)
+ TimeOuts.to_q_return[TOC_URGENT] = to;
+ else if (strcasecmp(p, "non-urgent") == 0)
+ TimeOuts.to_q_return[TOC_NONURGENT] = to;
+ else
+ syserr("settimeout: invalid queuereturn subtimeout %s", p);
+ }
+ else
+ syserr("settimeout: invalid timeout %s", name);
+}
OpenPOWER on IntegriCloud