BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.sbin / sendmail / src / readcf.c
index 8056c4e..bd2bad7 100644 (file)
@@ -1,6 +1,42 @@
-# include "sendmail.h"
+/*
+ * Copyright (c) 1983 Eric P. Allman
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)readcf.c   5.22 (Berkeley) 3/12/91";
+#endif /* not lint */
 
 
-SCCSID(@(#)readcf.c    3.53            %G%);
+# include "sendmail.h"
 
 /*
 **  READCF -- read control file.
 
 /*
 **  READCF -- read control file.
@@ -24,19 +60,13 @@ SCCSID(@(#)readcf.c 3.53            %G%);
 **             Sn              Use rewriting set n.
 **             Rlhs rhs        Rewrite addresses that match lhs to
 **                             be rhs.
 **             Sn              Use rewriting set n.
 **             Rlhs rhs        Rewrite addresses that match lhs to
 **                             be rhs.
-**             Mn p f s r a    Define mailer.  n - internal name,
-**                             p - pathname, f - flags, s - rewriting
-**                             ruleset for sender, s - rewriting ruleset
-**                             for recipients, a - argument vector.
+**             Mn arg=val...   Define mailer.  n is the internal name.
+**                             Args specify mailer parameters.
 **             Oxvalue         Set option x to value.
 **             Pname=value     Set precedence name to value.
 **
 **     Parameters:
 **             cfname -- control file name.
 **             Oxvalue         Set option x to value.
 **             Pname=value     Set precedence name to value.
 **
 **     Parameters:
 **             cfname -- control file name.
-**             safe -- set if this is a system configuration file.
-**                     Non-system configuration files can not do
-**                     certain things (e.g., leave the SUID bit on
-**                     when executing mailers).
 **
 **     Returns:
 **             none.
 **
 **     Returns:
 **             none.
@@ -45,9 +75,8 @@ SCCSID(@(#)readcf.c   3.53            %G%);
 **             Builds several internal tables.
 */
 
 **             Builds several internal tables.
 */
 
-readcf(cfname, safe)
+readcf(cfname)
        char *cfname;
        char *cfname;
-       bool safe;
 {
        FILE *cf;
        int ruleset = 0;
 {
        FILE *cf;
        int ruleset = 0;
@@ -59,7 +88,9 @@ readcf(cfname, safe)
        extern char **prescan();
        extern char **copyplist();
        char exbuf[MAXLINE];
        extern char **prescan();
        extern char **copyplist();
        char exbuf[MAXLINE];
+       char pvpbuf[PSBUFSIZE];
        extern char *fgetfolded();
        extern char *fgetfolded();
+       extern char *munchstring();
 
        cf = fopen(cfname, "r");
        if (cf == NULL)
 
        cf = fopen(cfname, "r");
        if (cf == NULL)
@@ -72,6 +103,24 @@ readcf(cfname, safe)
        LineNumber = 0;
        while (fgetfolded(buf, sizeof buf, cf) != NULL)
        {
        LineNumber = 0;
        while (fgetfolded(buf, sizeof buf, cf) != NULL)
        {
+               /* map $ into \001 (ASCII SOH) for macro expansion */
+               for (p = buf; *p != '\0'; p++)
+               {
+                       if (*p != '$')
+                               continue;
+
+                       if (p[1] == '$')
+                       {
+                               /* actual dollar sign.... */
+                               (void) strcpy(p, p + 1);
+                               continue;
+                       }
+
+                       /* convert to macro expansion character */
+                       *p = '\001';
+               }
+
+               /* interpret this line */
                switch (buf[0])
                {
                  case '\0':
                switch (buf[0])
                {
                  case '\0':
@@ -104,7 +153,7 @@ readcf(cfname, safe)
                        /* expand and save the LHS */
                        *p = '\0';
                        expand(&buf[1], exbuf, &exbuf[sizeof exbuf], CurEnv);
                        /* expand and save the LHS */
                        *p = '\0';
                        expand(&buf[1], exbuf, &exbuf[sizeof exbuf], CurEnv);
-                       rwp->r_lhs = prescan(exbuf, '\t');
+                       rwp->r_lhs = prescan(exbuf, '\t', pvpbuf);
                        if (rwp->r_lhs != NULL)
                                rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
 
                        if (rwp->r_lhs != NULL)
                                rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
 
@@ -116,7 +165,7 @@ readcf(cfname, safe)
                                p++;
                        *p = '\0';
                        expand(q, exbuf, &exbuf[sizeof exbuf], CurEnv);
                                p++;
                        *p = '\0';
                        expand(q, exbuf, &exbuf[sizeof exbuf], CurEnv);
-                       rwp->r_rhs = prescan(exbuf, '\t');
+                       rwp->r_rhs = prescan(exbuf, '\t', pvpbuf);
                        if (rwp->r_rhs != NULL)
                                rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
                        break;
                        if (rwp->r_rhs != NULL)
                                rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
                        break;
@@ -132,7 +181,7 @@ readcf(cfname, safe)
                        break;
 
                  case 'D':             /* macro definition */
                        break;
 
                  case 'D':             /* macro definition */
-                       define(buf[1], newstr(&buf[2]), CurEnv);
+                       define(buf[1], newstr(munchstring(&buf[2])), CurEnv);
                        break;
 
                  case 'H':             /* required header line */
                        break;
 
                  case 'H':             /* required header line */
@@ -164,7 +213,6 @@ readcf(cfname, safe)
                        {
                                register char *wd;
                                char delim;
                        {
                                register char *wd;
                                char delim;
-                               register STAB *s;
 
                                while (*p != '\0' && isspace(*p))
                                        p++;
 
                                while (*p != '\0' && isspace(*p))
                                        p++;
@@ -180,11 +228,11 @@ readcf(cfname, safe)
                        break;
 
                  case 'M':             /* define mailer */
                        break;
 
                  case 'M':             /* define mailer */
-                       makemailer(&buf[1], safe);
+                       makemailer(&buf[1]);
                        break;
 
                  case 'O':             /* set option */
                        break;
 
                  case 'O':             /* set option */
-                       setoption(buf[1], &buf[2], safe, FALSE);
+                       setoption(buf[1], &buf[2], TRUE, FALSE);
                        break;
 
                  case 'P':             /* set precedence */
                        break;
 
                  case 'P':             /* set precedence */
@@ -276,7 +324,7 @@ fileclass(class, filename, fmt)
        char *filename;
        char *fmt;
 {
        char *filename;
        char *fmt;
 {
-       register FILE *f;
+       FILE *f;
        char buf[MAXLINE];
 
        f = fopen(filename, "r");
        char buf[MAXLINE];
 
        f = fopen(filename, "r");
@@ -289,12 +337,42 @@ fileclass(class, filename, fmt)
        while (fgets(buf, sizeof buf, f) != NULL)
        {
                register STAB *s;
        while (fgets(buf, sizeof buf, f) != NULL)
        {
                register STAB *s;
+               register char *p;
+# ifdef SCANF
                char wordbuf[MAXNAME+1];
 
                if (sscanf(buf, fmt, wordbuf) != 1)
                        continue;
                char wordbuf[MAXNAME+1];
 
                if (sscanf(buf, fmt, wordbuf) != 1)
                        continue;
-               s = stab(wordbuf, ST_CLASS, ST_ENTER);
-               setbitn(class, s->s_class);
+               p = wordbuf;
+# else SCANF
+               p = buf;
+# endif SCANF
+
+               /*
+               **  Break up the match into words.
+               */
+
+               while (*p != '\0')
+               {
+                       register char *q;
+
+                       /* strip leading spaces */
+                       while (isspace(*p))
+                               p++;
+                       if (*p == '\0')
+                               break;
+
+                       /* find the end of the word */
+                       q = p;
+                       while (*p != '\0' && !isspace(*p))
+                               p++;
+                       if (*p != '\0')
+                               *p++ = '\0';
+
+                       /* enter the word in the symbol table */
+                       s = stab(q, ST_CLASS, ST_ENTER);
+                       setbitn(class, s->s_class);
+               }
        }
 
        (void) fclose(f);
        }
 
        (void) fclose(f);
@@ -312,7 +390,6 @@ fileclass(class, filename, fmt)
 **                        R -- the recipient rewriting set
 **                        E -- the eol string
 **                     The first word is the canonical name of the mailer.
 **                        R -- the recipient rewriting set
 **                        E -- the eol string
 **                     The first word is the canonical name of the mailer.
-**             safe -- set if this is a safe configuration file.
 **
 **     Returns:
 **             none.
 **
 **     Returns:
 **             none.
@@ -321,9 +398,8 @@ fileclass(class, filename, fmt)
 **             enters the mailer into the mailer table.
 */
 
 **             enters the mailer into the mailer table.
 */
 
-makemailer(line, safe)
+makemailer(line)
        char *line;
        char *line;
-       bool safe;
 {
        register char *p;
        register struct mailer *m;
 {
        register char *p;
        register struct mailer *m;
@@ -334,6 +410,7 @@ makemailer(line, safe)
        extern char **makeargv();
        extern char *munchstring();
        extern char *DelimChar;
        extern char **makeargv();
        extern char *munchstring();
        extern char *DelimChar;
+       extern long atol();
 
        /* allocate a mailer and set up defaults */
        m = (struct mailer *) xalloc(sizeof *m);
 
        /* allocate a mailer and set up defaults */
        m = (struct mailer *) xalloc(sizeof *m);
@@ -379,8 +456,6 @@ makemailer(line, safe)
                  case 'F':             /* flags */
                        for (; *p != '\0'; p++)
                                setbitn(*p, m->m_flags);
                  case 'F':             /* flags */
                        for (; *p != '\0'; p++)
                                setbitn(*p, m->m_flags);
-                       if (!safe)
-                               clrbitn(M_RESTR, m->m_flags);
                        break;
 
                  case 'S':             /* sender rewriting ruleset */
                        break;
 
                  case 'S':             /* sender rewriting ruleset */
@@ -404,6 +479,10 @@ makemailer(line, safe)
                  case 'A':             /* argument vector */
                        m->m_argv = makeargv(p);
                        break;
                  case 'A':             /* argument vector */
                        m->m_argv = makeargv(p);
                        break;
+
+                 case 'M':             /* maximum message size */
+                       m->m_maxsize = atol(p);
+                       break;
                }
 
                p = DelimChar;
                }
 
                p = DelimChar;
@@ -523,7 +602,7 @@ makeargv(p)
 
        /* now make a copy of the argv */
        avp = (char **) xalloc(sizeof *avp * i);
 
        /* now make a copy of the argv */
        avp = (char **) xalloc(sizeof *avp * i);
-       bmove((char *) argv, (char *) avp, sizeof *avp * i);
+       bcopy((char *) argv, (char *) avp, sizeof *avp * i);
 
        return (avp);
 }
 
        return (avp);
 }
@@ -540,8 +619,6 @@ makeargv(p)
 **             prints rewrite rules.
 */
 
 **             prints rewrite rules.
 */
 
-# ifdef DEBUG
-
 printrules()
 {
        register struct rewrite *rwp;
 printrules()
 {
        register struct rewrite *rwp;
@@ -563,14 +640,15 @@ printrules()
        }
 }
 
        }
 }
 
-# endif DEBUG
 \f/*
 **  SETOPTION -- set global processing option
 **
 **     Parameters:
 **             opt -- option name.
 **             val -- option value (as a text string).
 \f/*
 **  SETOPTION -- set global processing option
 **
 **     Parameters:
 **             opt -- option name.
 **             val -- option value (as a text string).
-**             safe -- if set, this came from a system configuration file.
+**             safe -- set if this came from a configuration file.
+**                     Some options (if set from the command line) will
+**                     reset the user id to avoid security problems.
 **             sticky -- if set, don't let other setoptions override
 **                     this value.
 **
 **             sticky -- if set, don't let other setoptions override
 **                     this value.
 **
@@ -582,10 +660,7 @@ printrules()
 */
 
 static BITMAP  StickyOpt;              /* set if option is stuck */
 */
 
 static BITMAP  StickyOpt;              /* set if option is stuck */
-extern char    *WizWord;               /* the stored wizard password */
-#ifdef DAEMON
-extern int     MaxConnections;         /* max simult. SMTP conns */
-#endif DAEMON
+extern char    *NetName;               /* name of home (local) network */
 
 setoption(opt, val, safe, sticky)
        char opt;
 
 setoption(opt, val, safe, sticky)
        char opt;
@@ -594,11 +669,14 @@ setoption(opt, val, safe, sticky)
        bool sticky;
 {
        extern bool atobool();
        bool sticky;
 {
        extern bool atobool();
+       extern time_t convtime();
+       extern int QueueLA;
+       extern int RefuseLA;
+       extern bool trusteduser();
+       extern char *username();
 
 
-# ifdef DEBUG
        if (tTd(37, 1))
                printf("setoption %c=%s", opt, val);
        if (tTd(37, 1))
                printf("setoption %c=%s", opt, val);
-# endif DEBUG
 
        /*
        **  See if this option is preset for us.
 
        /*
        **  See if this option is preset for us.
@@ -606,21 +684,33 @@ setoption(opt, val, safe, sticky)
 
        if (bitnset(opt, StickyOpt))
        {
 
        if (bitnset(opt, StickyOpt))
        {
-# ifdef DEBUG
                if (tTd(37, 1))
                        printf(" (ignored)\n");
                if (tTd(37, 1))
                        printf(" (ignored)\n");
-# endif DEBUG
                return;
        }
                return;
        }
-#ifdef DEBUG
-       else if (tTd(37, 1))
-               printf("\n");
-#endif DEBUG
-       if (sticky)
-               setbitn(opt, StickyOpt);
 
 
-       if (getruid() == 0)
+       /*
+       **  Check to see if this option can be specified by this user.
+       */
+
+       if (!safe && getuid() == 0)
                safe = TRUE;
                safe = TRUE;
+       if (!safe && index("deiLmorsv", opt) == NULL)
+       {
+               if (opt != 'M' || (val[0] != 'r' && val[0] != 's'))
+               {
+                       if (tTd(37, 1))
+                               printf(" (unsafe)");
+                       if (getuid() != geteuid())
+                       {
+                               printf("(Resetting uid)\n");
+                               (void) setgid(getgid());
+                               (void) setuid(getuid());
+                       }
+               }
+       }
+       else if (tTd(37, 1))
+               printf("\n");
 
        switch (opt)
        {
 
        switch (opt)
        {
@@ -631,14 +721,27 @@ setoption(opt, val, safe, sticky)
                        AliasFile = newstr(val);
                break;
 
                        AliasFile = newstr(val);
                break;
 
-         case 'a':             /* look for "@:@" in alias file */
-               SafeAlias = atobool(val);
+         case 'a':             /* look N minutes for "@:@" in alias file */
+               if (val[0] == '\0')
+                       SafeAlias = 5;
+               else
+                       SafeAlias = atoi(val);
+               break;
+
+         case 'B':             /* substitution for blank character */
+               SpaceSub = val[0];
+               if (SpaceSub == '\0')
+                       SpaceSub = ' ';
                break;
 
          case 'c':             /* don't connect to "expensive" mailers */
                NoConnect = atobool(val);
                break;
 
                break;
 
          case 'c':             /* don't connect to "expensive" mailers */
                NoConnect = atobool(val);
                break;
 
+         case 'C':             /* checkpoint after N connections */
+               CheckPointLimit = atoi(val);
+               break;
+
          case 'd':             /* delivery mode */
                switch (*val)
                {
          case 'd':             /* delivery mode */
                switch (*val)
                {
@@ -646,9 +749,14 @@ setoption(opt, val, safe, sticky)
                        SendMode = SM_DELIVER;
                        break;
 
                        SendMode = SM_DELIVER;
                        break;
 
+                 case SM_QUEUE:        /* queue only */
+#ifndef QUEUE
+                       syserr("need QUEUE to set -odqueue");
+#endif QUEUE
+                       /* fall through..... */
+
                  case SM_DELIVER:      /* do everything */
                  case SM_FORK:         /* fork after verification */
                  case SM_DELIVER:      /* do everything */
                  case SM_FORK:         /* fork after verification */
-                 case SM_QUEUE:        /* queue only */
                        SendMode = *val;
                        break;
 
                        SendMode = *val;
                        break;
 
@@ -666,9 +774,6 @@ setoption(opt, val, safe, sticky)
                switch (*val)
                {
                  case EM_QUIET:        /* be silent about it */
                switch (*val)
                {
                  case EM_QUIET:        /* be silent about it */
-                       (void) freopen("/dev/null", "w", stdout);
-                       /* fall through... */
-
                  case EM_MAIL:         /* mail back */
                  case EM_BERKNET:      /* do berknet error processing */
                  case EM_WRITE:        /* write back (or mail) */
                  case EM_MAIL:         /* mail back */
                  case EM_BERKNET:      /* do berknet error processing */
                  case EM_WRITE:        /* write back (or mail) */
@@ -682,7 +787,7 @@ setoption(opt, val, safe, sticky)
                break;
 
          case 'F':             /* file mode */
                break;
 
          case 'F':             /* file mode */
-               FileMode = atooct(val);
+               FileMode = atooct(val) & 0777;
                break;
 
          case 'f':             /* save Unix-style From lines on front */
                break;
 
          case 'f':             /* save Unix-style From lines on front */
@@ -690,8 +795,7 @@ setoption(opt, val, safe, sticky)
                break;
 
          case 'g':             /* default gid */
                break;
 
          case 'g':             /* default gid */
-               if (safe)
-                       DefGid = atoi(val);
+               DefGid = atoi(val);
                break;
 
          case 'H':             /* help file */
                break;
 
          case 'H':             /* help file */
@@ -701,27 +805,40 @@ setoption(opt, val, safe, sticky)
                        HelpFile = newstr(val);
                break;
 
                        HelpFile = newstr(val);
                break;
 
+         case 'I':             /* use internet domain name server */
+               UseNameServer = atobool(val);
+               break;
+
          case 'i':             /* ignore dot lines in message */
                IgnrDot = atobool(val);
                break;
 
          case 'i':             /* ignore dot lines in message */
                IgnrDot = atobool(val);
                break;
 
+         case 'k':             /* checkpoint every N addresses */
+               CheckpointInterval = atoi(val);
+               break;
+
          case 'L':             /* log level */
                LogLevel = atoi(val);
                break;
 
          case 'M':             /* define macro */
                define(val[0], newstr(&val[1]), CurEnv);
          case 'L':             /* log level */
                LogLevel = atoi(val);
                break;
 
          case 'M':             /* define macro */
                define(val[0], newstr(&val[1]), CurEnv);
+               sticky = FALSE;
                break;
 
          case 'm':             /* send to me too */
                MeToo = atobool(val);
                break;
 
                break;
 
          case 'm':             /* send to me too */
                MeToo = atobool(val);
                break;
 
-#ifdef DAEMON
-         case 'N':             /* maximum simultaneous SMTP connections */
-               MaxConnections = atoi(val);
+         case 'n':             /* validate RHS in newaliases */
+               CheckAliases = atobool(val);
                break;
                break;
-#endif DAEMON
+
+# ifdef DAEMON
+         case 'N':             /* home (local?) network name */
+               NetName = newstr(val);
+               break;
+# endif DAEMON
 
          case 'o':             /* assume old style headers */
                if (atobool(val))
 
          case 'o':             /* assume old style headers */
                if (atobool(val))
@@ -730,6 +847,14 @@ setoption(opt, val, safe, sticky)
                        CurEnv->e_flags &= ~EF_OLDSTYLE;
                break;
 
                        CurEnv->e_flags &= ~EF_OLDSTYLE;
                break;
 
+         case 'P':             /* postmaster copy address for returned mail */
+               PostMasterCopy = newstr(val);
+               break;
+
+         case 'q':             /* slope of queue only function */
+               QueueFactor = atoi(val);
+               break;
+
          case 'Q':             /* queue directory */
                if (val[0] == '\0')
                        QueueDir = "mqueue";
          case 'Q':             /* queue directory */
                if (val[0] == '\0')
                        QueueDir = "mqueue";
@@ -754,38 +879,49 @@ setoption(opt, val, safe, sticky)
 
          case 'T':             /* queue timeout */
                TimeOut = convtime(val);
 
          case 'T':             /* queue timeout */
                TimeOut = convtime(val);
-               break;
+               /*FALLTHROUGH*/
 
          case 't':             /* time zone name */
 
          case 't':             /* time zone name */
-# ifdef V6
-               StdTimezone = newstr(val);
-               DstTimezone = index(StdTimeZone, ',');
-               if (DstTimezone == NULL)
-                       syserr("bad time zone spec");
-               else
-                       *DstTimezone++ = '\0';
-# endif V6
                break;
 
          case 'u':             /* set default uid */
                break;
 
          case 'u':             /* set default uid */
-               if (safe)
-                       DefUid = atoi(val);
+               DefUid = atoi(val);
+               setdefuser();
                break;
 
          case 'v':             /* run in verbose mode */
                Verbose = atobool(val);
                break;
 
                break;
 
          case 'v':             /* run in verbose mode */
                Verbose = atobool(val);
                break;
 
-# ifdef DEBUG
-         case 'W':             /* set the wizards password */
-               if (safe)
-                       WizWord = newstr(val);
+         case 'x':             /* load avg at which to auto-queue msgs */
+               QueueLA = atoi(val);
+               break;
+
+         case 'X':             /* load avg at which to auto-reject connections */
+               RefuseLA = atoi(val);
+               break;
+
+         case 'y':             /* work recipient factor */
+               WkRecipFact = atoi(val);
+               break;
+
+         case 'Y':             /* fork jobs during queue runs */
+               ForkQueueRuns = atobool(val);
+               break;
+
+         case 'z':             /* work message class factor */
+               WkClassFact = atoi(val);
+               break;
+
+         case 'Z':             /* work time factor */
+               WkTimeFact = atoi(val);
                break;
                break;
-# endif DEBUG
 
          default:
                break;
        }
 
          default:
                break;
        }
+       if (sticky)
+               setbitn(opt, StickyOpt);
        return;
 }
 \f/*
        return;
 }
 \f/*