BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.sbin / sendmail / src / conf.c
index 8acab99..48a978c 100644 (file)
@@ -1,23 +1,46 @@
 /*
 /*
-**  Sendmail
-**  Copyright (c) 1983  Eric P. Allman
-**  Berkeley, California
-**
-**  Copyright (c) 1983 Regents of the University of California.
-**  All rights reserved.  The Berkeley software License Agreement
-**  specifies the terms and conditions for redistribution.
-*/
+ * 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
 
 #ifndef lint
-static char    SccsId[] = "@(#)conf.c  5.10 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)conf.c     5.28 (Berkeley) 3/12/91";
+#endif /* not lint */
 
 
-# include <pwd.h>
 # include <sys/ioctl.h>
 # include <sys/ioctl.h>
-# ifdef sun
 # include <sys/param.h>
 # include <sys/param.h>
-# endif sun
+# include <pwd.h>
 # include "sendmail.h"
 # include "sendmail.h"
+# include "pathnames.h"
 
 /*
 **  CONF.C -- Sendmail Configuration Tables.
 
 /*
 **  CONF.C -- Sendmail Configuration Tables.
@@ -25,11 +48,6 @@ static char  SccsId[] = "@(#)conf.c  5.10 (Berkeley) %G%";
 **     Defines the configuration of this installation.
 **
 **     Compilation Flags:
 **     Defines the configuration of this installation.
 **
 **     Compilation Flags:
-**             V6 -- running on a version 6 system.  This determines
-**                     whether to define certain routines between
-**                     the two systems.  If you are running a funny
-**                     system, e.g., V6 with long tty names, this
-**                     should be checked carefully.
 **             VMUNIX -- running on a Berkeley UNIX system.
 **
 **     Configuration Variables:
 **             VMUNIX -- running on a Berkeley UNIX system.
 **
 **     Configuration Variables:
@@ -51,7 +69,7 @@ static char   SccsId[] = "@(#)conf.c  5.10 (Berkeley) %G%";
 
 
 
 
 
 
-\f/*
+/*
 **  Header info table
 **     Final (null) entry contains the flags used for any other field.
 **
 **  Header info table
 **     Final (null) entry contains the flags used for any other field.
 **
@@ -66,8 +84,10 @@ struct hdrinfo       HdrInfo[] =
                /* originator fields, most to least significant  */
        "resent-sender",        H_FROM|H_RESENT,
        "resent-from",          H_FROM|H_RESENT,
                /* originator fields, most to least significant  */
        "resent-sender",        H_FROM|H_RESENT,
        "resent-from",          H_FROM|H_RESENT,
+       "resent-reply-to",      H_FROM|H_RESENT,
        "sender",               H_FROM,
        "from",                 H_FROM,
        "sender",               H_FROM,
        "from",                 H_FROM,
+       "reply-to",             H_FROM,
        "full-name",            H_ACHECK,
        "return-receipt-to",    H_FROM,
        "errors-to",            H_FROM,
        "full-name",            H_ACHECK,
        "return-receipt-to",    H_FROM,
        "errors-to",            H_FROM,
@@ -110,8 +130,8 @@ char        Arpa_Usrerr[] =         "554";  /* some (fatal) user error */
 **  Location of system files/databases/etc.
 */
 
 **  Location of system files/databases/etc.
 */
 
-char   *ConfFile =     "/usr/lib/sendmail.cf"; /* runtime configuration */
-char   *FreezeFile =   "/usr/lib/sendmail.fc"; /* frozen version of above */
+char   *ConfFile =     _PATH_SENDMAILCF;       /* runtime configuration */
+char   *FreezeFile =   _PATH_SENDMAILFC;       /* frozen version of above */
 
 
 
 
 
 
@@ -120,6 +140,7 @@ char        *FreezeFile =   "/usr/lib/sendmail.fc"; /* frozen version of above */
 */
 
 int    DtableSize =    50;             /* max open files; reset in 4.2bsd */
 */
 
 int    DtableSize =    50;             /* max open files; reset in 4.2bsd */
+extern int la;                         /* load average */
 \f/*
 **  SETDEFAULTS -- set default values
 **
 \f/*
 **  SETDEFAULTS -- set default values
 **
@@ -145,169 +166,31 @@ setdefaults()
        SpaceSub = ' ';
        WkRecipFact = 1000;
        WkClassFact = 1800;
        SpaceSub = ' ';
        WkRecipFact = 1000;
        WkClassFact = 1800;
-       WkTimeFact = 600;
+       WkTimeFact = 9000;
        FileMode = 0644;
        DefUid = 1;
        DefGid = 1;
        FileMode = 0644;
        DefUid = 1;
        DefGid = 1;
-}
-\f
-# ifdef V6
-/*
-**  TTYNAME -- return name of terminal.
-**
-**     Parameters:
-**             fd -- file descriptor to check.
-**
-**     Returns:
-**             pointer to full path of tty.
-**             NULL if no tty.
-**
-**     Side Effects:
-**             none.
-*/
-
-char *
-ttyname(fd)
-       int fd;
-{
-       register char tn;
-       static char pathn[] = "/dev/ttyx";
-
-       /* compute the pathname of the controlling tty */
-       if ((tn = ttyn(fd)) == NULL)
-       {
-               errno = 0;
-               return (NULL);
-       }
-       pathn[8] = tn;
-       return (pathn);
-}
-\f/*
-**  FDOPEN -- Open a stdio file given an open file descriptor.
-**
-**     This is included here because it is standard in v7, but we
-**     need it in v6.
-**
-**     Algorithm:
-**             Open /dev/null to create a descriptor.
-**             Close that descriptor.
-**             Copy the existing fd into the descriptor.
-**
-**     Parameters:
-**             fd -- the open file descriptor.
-**             type -- "r", "w", or whatever.
-**
-**     Returns:
-**             The file descriptor it creates.
-**
-**     Side Effects:
-**             none
-**
-**     Called By:
-**             deliver
-**
-**     Notes:
-**             The mode of fd must match "type".
-*/
-
-FILE *
-fdopen(fd, type)
-       int fd;
-       char *type;
-{
-       register FILE *f;
-
-       f = fopen("/dev/null", type);
-       (void) close(fileno(f));
-       fileno(f) = fd;
-       return (f);
-}
-\f/*
-**  INDEX -- Return pointer to character in string
-**
-**     For V7 compatibility.
-**
-**     Parameters:
-**             s -- a string to scan.
-**             c -- a character to look for.
-**
-**     Returns:
-**             If c is in s, returns the address of the first
-**                     instance of c in s.
-**             NULL if c is not in s.
-**
-**     Side Effects:
-**             none.
-*/
-
-char *
-index(s, c)
-       register char *s;
-       register char c;
-{
-       while (*s != '\0')
-       {
-               if (*s++ == c)
-                       return (--s);
-       }
-       return (NULL);
-}
-\f/*
-**  UMASK -- fake the umask system call.
-**
-**     Since V6 always acts like the umask is zero, we will just
-**     assume the same thing.
-*/
-
-/*ARGSUSED*/
-umask(nmask)
-{
-       return (0);
-}
-
-
-/*
-**  GETRUID -- get real user id.
-*/
-
-getruid()
-{
-       return (getuid() & 0377);
-}
-
-
-/*
-**  GETRGID -- get real group id.
-*/
-
-getrgid()
-{
-       return (getgid() & 0377);
+       CheckpointInterval = 10;
+       setdefuser();
 }
 
 
 /*
 }
 
 
 /*
-**  GETEUID -- get effective user id.
+**  SETDEFUSER -- set/reset DefUser using DefUid (for initgroups())
 */
 
 */
 
-geteuid()
+setdefuser()
 {
 {
-       return ((getuid() >> 8) & 0377);
-}
-
-
-/*
-**  GETEGID -- get effective group id.
-*/
+       struct passwd *defpwent;
 
 
-getegid()
-{
-       return ((getgid() >> 8) & 0377);
+       if (DefUser != NULL)
+               free(DefUser);
+       if ((defpwent = getpwuid(DefUid)) != NULL)
+               DefUser = newstr(defpwent->pw_name);
+       else
+               DefUser = newstr("nobody");
 }
 
 }
 
-# endif V6
-\f
-# ifndef V6
 
 /*
 **  GETRUID -- get real user id (V7)
 
 /*
 **  GETRUID -- get real user id (V7)
@@ -334,8 +217,7 @@ getrgid()
                return (getgid());
 }
 
                return (getgid());
 }
 
-# endif V6
-\f/*
+/*
 **  USERNAME -- return the user id of the logged in user.
 **
 **     Parameters:
 **  USERNAME -- return the user id of the logged in user.
 **
 **     Parameters:
@@ -357,7 +239,6 @@ username()
        static char *myname = NULL;
        extern char *getlogin();
        register struct passwd *pw;
        static char *myname = NULL;
        extern char *getlogin();
        register struct passwd *pw;
-       extern struct passwd *getpwuid();
 
        /* cache the result */
        if (myname == NULL)
 
        /* cache the result */
        if (myname == NULL)
@@ -368,17 +249,18 @@ username()
 
                        pw = getpwuid(getruid());
                        if (pw != NULL)
 
                        pw = getpwuid(getruid());
                        if (pw != NULL)
-                               myname = pw->pw_name;
+                               myname = newstr(pw->pw_name);
                }
                else
                {
 
                }
                else
                {
 
-                       pw = getpwnam(myname);
-                       if(getuid() != pw->pw_uid)
+                       myname = newstr(myname);
+                       if ((pw = getpwnam(myname)) == NULL ||
+                             getuid() != pw->pw_uid)
                        {
                                pw = getpwuid(getuid());
                                if (pw != NULL)
                        {
                                pw = getpwuid(getuid());
                                if (pw != NULL)
-                                       myname = pw->pw_name;
+                                       myname = newstr(pw->pw_name);
                        }
                }
                if (myname == NULL || myname[0] == '\0')
                        }
                }
                if (myname == NULL || myname[0] == '\0')
@@ -544,7 +426,18 @@ rlsesigs()
 **             none.
 */
 
 **             none.
 */
 
-#ifdef VMUNIX
+#ifndef sun
+
+getla()
+{
+       double avenrun[3];
+
+       if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0)
+               return (0);
+       return ((int) (avenrun[0] + 0.5));
+}
+
+#else /* sun */
 
 #include <nlist.h>
 
 
 #include <nlist.h>
 
@@ -555,14 +448,14 @@ struct    nlist Nl[] =
        { 0 },
 };
 
        { 0 },
 };
 
+
+extern int la;
+
 getla()
 {
        static int kmem = -1;
 getla()
 {
        static int kmem = -1;
-# ifdef sun
        long avenrun[3];
        long avenrun[3];
-# else
-       double avenrun[3];
-# endif
+       extern off_t lseek();
 
        if (kmem < 0)
        {
 
        if (kmem < 0)
        {
@@ -580,21 +473,10 @@ getla()
                /* thank you Ian */
                return (-1);
        }
                /* thank you Ian */
                return (-1);
        }
-# ifdef sun
        return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
        return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
-# else
-       return ((int) (avenrun[0] + 0.5));
-# endif
-}
-
-#else VMUNIX
-
-getla()
-{
-       return (0);
 }
 
 }
 
-#endif VMUNIX
+#endif /* sun */
 \f/*
 **  SHOULDQUEUE -- should this message be queued or sent?
 **
 \f/*
 **  SHOULDQUEUE -- should this message be queued or sent?
 **
@@ -616,9 +498,6 @@ bool
 shouldqueue(pri)
        long pri;
 {
 shouldqueue(pri)
        long pri;
 {
-       int la;
-
-       la = getla();
        if (la < QueueLA)
                return (FALSE);
        return (pri > (QueueFactor / (la - QueueLA + 1)));
        if (la < QueueLA)
                return (FALSE);
        return (pri > (QueueFactor / (la - QueueLA + 1)));
@@ -667,3 +546,35 @@ setproctitle(fmt, a, b, c)
                *p++ = ' ';
 # endif SETPROCTITLE
 }
                *p++ = ' ';
 # endif SETPROCTITLE
 }
+\f/*
+**  REAPCHILD -- pick up the body of my child, lest it become a zombie
+**
+**     Parameters:
+**             none.
+**
+**     Returns:
+**             none.
+**
+**     Side Effects:
+**             Picks up extant zombies.
+*/
+
+# ifdef VMUNIX
+# include <sys/wait.h>
+# endif VMUNIX
+
+void
+reapchild()
+{
+# ifdef WNOHANG
+       union wait status;
+
+       while (wait3((int *)&status, WNOHANG, (struct rusage *) NULL) > 0)
+               continue;
+# else WNOHANG
+       auto int status;
+
+       while (wait((int *)&status) > 0)
+               continue;
+# endif WNOHANG
+}