BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.sbin / sendmail / src / readcf.c
index bc612c3..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    4.8             %G%);
+# include "sendmail.h"
 
 /*
 **  READCF -- read control file.
 
 /*
 **  READCF -- read control file.
@@ -24,19 +60,13 @@ SCCSID(@(#)readcf.c 4.8             %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   4.8             %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;
@@ -83,7 +112,7 @@ readcf(cfname, safe)
                        if (p[1] == '$')
                        {
                                /* actual dollar sign.... */
                        if (p[1] == '$')
                        {
                                /* actual dollar sign.... */
-                               strcpy(p, p + 1);
+                               (void) strcpy(p, p + 1);
                                continue;
                        }
 
                                continue;
                        }
 
@@ -199,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 */
@@ -295,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");
@@ -308,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);
@@ -331,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.
@@ -340,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;
@@ -399,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 */
@@ -564,8 +619,6 @@ makeargv(p)
 **             prints rewrite rules.
 */
 
 **             prints rewrite rules.
 */
 
-# ifdef DEBUG
-
 printrules()
 {
        register struct rewrite *rwp;
 printrules()
 {
        register struct rewrite *rwp;
@@ -587,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.
 **
@@ -606,7 +660,6 @@ printrules()
 */
 
 static BITMAP  StickyOpt;              /* set if option is stuck */
 */
 
 static BITMAP  StickyOpt;              /* set if option is stuck */
-extern char    *WizWord;               /* the stored wizard password */
 extern char    *NetName;               /* name of home (local) network */
 
 setoption(opt, val, safe, sticky)
 extern char    *NetName;               /* name of home (local) network */
 
 setoption(opt, val, safe, sticky)
@@ -619,11 +672,11 @@ setoption(opt, val, safe, sticky)
        extern time_t convtime();
        extern int QueueLA;
        extern int RefuseLA;
        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.
@@ -631,19 +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 (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)
        {
@@ -654,20 +721,27 @@ setoption(opt, val, safe, sticky)
                        AliasFile = newstr(val);
                break;
 
                        AliasFile = newstr(val);
                break;
 
+         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 'B':             /* substitution for blank character */
                SpaceSub = val[0];
                if (SpaceSub == '\0')
                        SpaceSub = ' ';
                break;
 
-         case 'a':             /* look for "@:@" in alias file */
-               SafeAlias = atobool(val);
-               break;
-
          case 'c':             /* don't connect to "expensive" mailers */
                NoConnect = atobool(val);
                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)
                {
@@ -713,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 */
@@ -721,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 */
@@ -732,10 +805,18 @@ 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 'L':             /* log level */
                LogLevel = atoi(val);
                break;
@@ -749,6 +830,10 @@ setoption(opt, val, safe, sticky)
                MeToo = atobool(val);
                break;
 
                MeToo = atobool(val);
                break;
 
+         case 'n':             /* validate RHS in newaliases */
+               CheckAliases = atobool(val);
+               break;
+
 # ifdef DAEMON
          case 'N':             /* home (local?) network name */
                NetName = newstr(val);
 # ifdef DAEMON
          case 'N':             /* home (local?) network name */
                NetName = newstr(val);
@@ -762,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";
@@ -786,35 +879,20 @@ 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);
-               break;
-# endif DEBUG
-
          case 'x':             /* load avg at which to auto-queue msgs */
                QueueLA = atoi(val);
                break;
          case 'x':             /* load avg at which to auto-queue msgs */
                QueueLA = atoi(val);
                break;
@@ -823,6 +901,22 @@ setoption(opt, val, safe, sticky)
                RefuseLA = atoi(val);
                break;
 
                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;
+
          default:
                break;
        }
          default:
                break;
        }