BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.sbin / sendmail / src / conf.c
index 1b72887..48a978c 100644 (file)
@@ -1,5 +1,46 @@
+/*
+ * 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[] = "@(#)conf.c     5.28 (Berkeley) 3/12/91";
+#endif /* not lint */
+
+# include <sys/ioctl.h>
+# include <sys/param.h>
 # include <pwd.h>
 # include "sendmail.h"
 # include <pwd.h>
 # include "sendmail.h"
+# include "pathnames.h"
 
 /*
 **  CONF.C -- Sendmail Configuration Tables.
 
 /*
 **  CONF.C -- Sendmail Configuration Tables.
@@ -7,11 +48,7 @@
 **     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:
 **             HdrInfo -- a table describing well-known header fields.
 **
 **     Configuration Variables:
 **             HdrInfo -- a table describing well-known header fields.
 
 
 
 
 
 
-static char SccsId[] = "@(#)conf.c     3.21    %G%";
-
-
-# include <whoami.h>           /* definitions of machine id's at berkeley */
-
-
 /*
 **  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.
@@ -50,23 +81,37 @@ static char SccsId[] = "@(#)conf.c  3.21    %G%";
 
 struct hdrinfo HdrInfo[] =
 {
 
 struct hdrinfo HdrInfo[] =
 {
-       "date",                 H_CHECK,                M_NEEDDATE,
-       "from",                 H_CHECK,                M_NEEDFROM,
-       "sender",               0,                      0,
-       "full-name",            H_ACHECK,               M_FULLNAME,
-       "to",                   0,                      0,
-       "cc",                   0,                      0,
-       "bcc",                  0,                      0,
-       "message-id",           H_CHECK,                M_MSGID,
-       "message",              H_EOH,                  0,
-       "text",                 H_EOH,                  0,
-       "posted-date",          0,                      0,
-       "return-receipt-to",    0,                      0,
-       "received-date",        H_CHECK,                M_LOCAL,
-       "received-from",        H_CHECK,                M_LOCAL,
-       "precedence",           0,                      0,
-       "via",                  H_FORCE,                0,
-       NULL,                   0,                      0,
+               /* 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,
+       "reply-to",             H_FROM,
+       "full-name",            H_ACHECK,
+       "return-receipt-to",    H_FROM,
+       "errors-to",            H_FROM,
+               /* destination fields */
+       "to",                   H_RCPT,
+       "resent-to",            H_RCPT|H_RESENT,
+       "cc",                   H_RCPT,
+       "resent-cc",            H_RCPT|H_RESENT,
+       "bcc",                  H_RCPT|H_ACHECK,
+       "resent-bcc",           H_RCPT|H_ACHECK|H_RESENT,
+               /* message identification and control */
+       "message-id",           0,
+       "resent-message-id",    H_RESENT,
+       "message",              H_EOH,
+       "text",                 H_EOH,
+               /* date fields */
+       "date",                 0,
+       "resent-date",          H_RESENT,
+               /* trace fields */
+       "received",             H_TRACE|H_FORCE,
+       "via",                  H_TRACE|H_FORCE,
+       "mail-from",            H_TRACE|H_FORCE,
+
+       NULL,                   0,
 };
 
 
 };
 
 
@@ -74,124 +119,159 @@ struct hdrinfo   HdrInfo[] =
 **  ARPANET error message numbers.
 */
 
 **  ARPANET error message numbers.
 */
 
-# ifdef NEWFTP
-/* these are almost all unchecked */
-char   Arpa_Info[] =   "010";  /* arbitrary info: this is WRONG! */
-char   Arpa_Enter[] =  "354";  /* start mail input */
-char   Arpa_Mmsg[] =   "250";  /* mail successful (MAIL cmd) */
-char   Arpa_Fmsg[] =   "250";  /* mail successful (MLFL cmd) */
-char   Arpa_Syserr[] = "450";  /* some (transient) system error */
-char   Arpa_Usrerr[] = "550";  /* some (fatal) user error */
-# else NEWFTP
-char   Arpa_Info[] =   "050";  /* arbitrary info */
-char   Arpa_Enter[] =  "350";  /* start mail input */
-char   Arpa_Mmsg[] =   "256";  /* mail successful (MAIL cmd) */
-char   Arpa_Fmsg[] =   "250";  /* mail successful (MLFL cmd) */
-char   Arpa_Syserr[] = "455";  /* some (transient) system error */
-char   Arpa_Usrerr[] = "450";  /* some (fatal) user error */
-# endif NEWFTP
-\f
-# ifdef V6
+char   Arpa_Info[] =           "050";  /* arbitrary info */
+char   Arpa_TSyserr[] =        "451";  /* some (transient) system error */
+char   Arpa_PSyserr[] =        "554";  /* some (permanent) system error */
+char   Arpa_Usrerr[] =         "554";  /* some (fatal) user error */
+
+
+
 /*
 /*
-**  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.
+**  Location of system files/databases/etc.
 */
 
 */
 
-char *
-ttyname(fd)
-       int fd;
-{
-       register char tn;
-       static char pathn[] = "/dev/ttyx";
+char   *ConfFile =     _PATH_SENDMAILCF;       /* runtime configuration */
+char   *FreezeFile =   _PATH_SENDMAILFC;       /* frozen version of above */
 
 
-       /* compute the pathname of the controlling tty */
-       if ((tn = ttyn(fd)) == NULL)
-       {
-               errno = 0;
-               return (NULL);
-       }
-       pathn[8] = tn;
-       return (pathn);
-}
+
+
+/*
+**  Miscellaneous stuff.
+*/
+
+int    DtableSize =    50;             /* max open files; reset in 4.2bsd */
+extern int la;                         /* load average */
 \f/*
 \f/*
-**  FDOPEN -- Open a stdio file given an open file descriptor.
+**  SETDEFAULTS -- set default values
 **
 **
-**     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.
+**     Because of the way freezing is done, these must be initialized
+**     using direct code.
 **
 **     Parameters:
 **
 **     Parameters:
-**             fd -- the open file descriptor.
-**             type -- "r", "w", or whatever.
+**             none.
 **
 **     Returns:
 **
 **     Returns:
-**             The file descriptor it creates.
+**             none.
 **
 **     Side Effects:
 **
 **     Side Effects:
-**             none
-**
-**     Called By:
-**             deliver
-**
-**     Notes:
-**             The mode of fd must match "type".
+**             Initializes a bunch of global variables to their
+**             default values.
+*/
+
+setdefaults()
+{
+       QueueLA = 8;
+       QueueFactor = 10000;
+       RefuseLA = 12;
+       SpaceSub = ' ';
+       WkRecipFact = 1000;
+       WkClassFact = 1800;
+       WkTimeFact = 9000;
+       FileMode = 0644;
+       DefUid = 1;
+       DefGid = 1;
+       CheckpointInterval = 10;
+       setdefuser();
+}
+
+
+/*
+**  SETDEFUSER -- set/reset DefUser using DefUid (for initgroups())
 */
 
 */
 
-FILE *
-fdopen(fd, type)
-       int fd;
-       char *type;
+setdefuser()
 {
 {
-       register FILE *f;
+       struct passwd *defpwent;
 
 
-       f = fopen("/dev/null", type);
-       (void) close(fileno(f));
-       fileno(f) = fd;
-       return (f);
+       if (DefUser != NULL)
+               free(DefUser);
+       if ((defpwent = getpwuid(DefUid)) != NULL)
+               DefUser = newstr(defpwent->pw_name);
+       else
+               DefUser = newstr("nobody");
 }
 }
-\f/*
-**  INDEX -- Return pointer to character in string
-**
-**     For V7 compatibility.
+
+
+/*
+**  GETRUID -- get real user id (V7)
+*/
+
+getruid()
+{
+       if (OpMode == MD_DAEMON)
+               return (RealUid);
+       else
+               return (getuid());
+}
+
+
+/*
+**  GETRGID -- get real group id (V7).
+*/
+
+getrgid()
+{
+       if (OpMode == MD_DAEMON)
+               return (RealGid);
+       else
+               return (getgid());
+}
+
+/*
+**  USERNAME -- return the user id of the logged in user.
 **
 **     Parameters:
 **
 **     Parameters:
-**             s -- a string to scan.
-**             c -- a character to look for.
+**             none.
 **
 **     Returns:
 **
 **     Returns:
-**             If c is in s, returns the address of the first
-**                     instance of c in s.
-**             NULL if c is not in s.
+**             The login name of the logged in user.
 **
 **     Side Effects:
 **             none.
 **
 **     Side Effects:
 **             none.
+**
+**     Notes:
+**             The return value is statically allocated.
 */
 
 */
 
-index(s, c)
-       register char *s;
-       register char c;
+char *
+username()
 {
 {
-       while (*s != '\0')
+       static char *myname = NULL;
+       extern char *getlogin();
+       register struct passwd *pw;
+
+       /* cache the result */
+       if (myname == NULL)
        {
        {
-               if (*s++ == c)
-                       return (--s);
+               myname = getlogin();
+               if (myname == NULL || myname[0] == '\0')
+               {
+
+                       pw = getpwuid(getruid());
+                       if (pw != NULL)
+                               myname = newstr(pw->pw_name);
+               }
+               else
+               {
+
+                       myname = newstr(myname);
+                       if ((pw = getpwnam(myname)) == NULL ||
+                             getuid() != pw->pw_uid)
+                       {
+                               pw = getpwuid(getuid());
+                               if (pw != NULL)
+                                       myname = newstr(pw->pw_name);
+                       }
+               }
+               if (myname == NULL || myname[0] == '\0')
+               {
+                       syserr("Who are you?");
+                       myname = "postmaster";
+               }
        }
        }
-       return (NULL);
+
+       return (myname);
 }
 }
-# endif V6
 \f/*
 **  TTYPATH -- Get the path of the user's tty
 **
 \f/*
 **  TTYPATH -- Get the path of the user's tty
 **
@@ -227,7 +307,8 @@ ttypath()
        extern char *getlogin();
 
        /* compute the pathname of the controlling tty */
        extern char *getlogin();
 
        /* compute the pathname of the controlling tty */
-       if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && (pathn = ttyname(0)) == NULL)
+       if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL &&
+           (pathn = ttyname(0)) == NULL)
        {
                errno = 0;
                return (NULL);
        {
                errno = 0;
                return (NULL);
@@ -259,6 +340,9 @@ ttypath()
 **     message should be given using "usrerr" and FALSE should
 **     be returned.
 **
 **     message should be given using "usrerr" and FALSE should
 **     be returned.
 **
+**     'NoReturn' can be set to suppress the return-to-sender
+**     function; this should be done on huge messages.
+**
 **     Parameters:
 **             to -- the person being sent to.
 **
 **     Parameters:
 **             to -- the person being sent to.
 **
@@ -275,10 +359,222 @@ checkcompat(to)
        register ADDRESS *to;
 {
 # ifdef lint
        register ADDRESS *to;
 {
 # ifdef lint
-       ADDRESS *x = to;
-
-       to = x;
+       if (to == NULL)
+               to++;
 # endif lint
 # endif lint
+# ifdef EXAMPLE_CODE
+       /* this code is intended as an example only */
+       register STAB *s;
 
 
+       s = stab("arpa", ST_MAILER, ST_FIND);
+       if (s != NULL && CurEnv->e_from.q_mailer != LocalMailer &&
+           to->q_mailer == s->s_mailer)
+       {
+               usrerr("No ARPA mail through this machine: see your system administration");
+               /* NoReturn = TRUE; to supress return copy */
+               return (FALSE);
+       }
+# endif EXAMPLE_CODE
        return (TRUE);
 }
        return (TRUE);
 }
+\f/*
+**  HOLDSIGS -- arrange to hold all signals
+**
+**     Parameters:
+**             none.
+**
+**     Returns:
+**             none.
+**
+**     Side Effects:
+**             Arranges that signals are held.
+*/
+
+holdsigs()
+{
+}
+\f/*
+**  RLSESIGS -- arrange to release all signals
+**
+**     This undoes the effect of holdsigs.
+**
+**     Parameters:
+**             none.
+**
+**     Returns:
+**             none.
+**
+**     Side Effects:
+**             Arranges that signals are released.
+*/
+
+rlsesigs()
+{
+}
+\f/*
+**  GETLA -- get the current load average
+**
+**     This code stolen from la.c.
+**
+**     Parameters:
+**             none.
+**
+**     Returns:
+**             The current load average as an integer.
+**
+**     Side Effects:
+**             none.
+*/
+
+#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>
+
+struct nlist Nl[] =
+{
+       { "_avenrun" },
+#define        X_AVENRUN       0
+       { 0 },
+};
+
+
+extern int la;
+
+getla()
+{
+       static int kmem = -1;
+       long avenrun[3];
+       extern off_t lseek();
+
+       if (kmem < 0)
+       {
+               kmem = open("/dev/kmem", 0, 0);
+               if (kmem < 0)
+                       return (-1);
+               (void) ioctl(kmem, (int) FIOCLEX, (char *) 0);
+               nlist("/vmunix", Nl);
+               if (Nl[0].n_type == 0)
+                       return (-1);
+       }
+       if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, 0) == -1 ||
+           read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun))
+       {
+               /* thank you Ian */
+               return (-1);
+       }
+       return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
+}
+
+#endif /* sun */
+\f/*
+**  SHOULDQUEUE -- should this message be queued or sent?
+**
+**     Compares the message cost to the load average to decide.
+**
+**     Parameters:
+**             pri -- the priority of the message in question.
+**
+**     Returns:
+**             TRUE -- if this message should be queued up for the
+**                     time being.
+**             FALSE -- if the load is low enough to send this message.
+**
+**     Side Effects:
+**             none.
+*/
+
+bool
+shouldqueue(pri)
+       long pri;
+{
+       if (la < QueueLA)
+               return (FALSE);
+       return (pri > (QueueFactor / (la - QueueLA + 1)));
+}
+\f/*
+**  SETPROCTITLE -- set process title for ps
+**
+**     Parameters:
+**             fmt -- a printf style format string.
+**             a, b, c -- possible parameters to fmt.
+**
+**     Returns:
+**             none.
+**
+**     Side Effects:
+**             Clobbers argv of our main procedure so ps(1) will
+**             display the title.
+*/
+
+/*VARARGS1*/
+setproctitle(fmt, a, b, c)
+       char *fmt;
+{
+# ifdef SETPROCTITLE
+       register char *p;
+       register int i;
+       extern char **Argv;
+       extern char *LastArgv;
+       char buf[MAXLINE];
+
+       (void) sprintf(buf, fmt, a, b, c);
+
+       /* make ps print "(sendmail)" */
+       p = Argv[0];
+       *p++ = '-';
+
+       i = strlen(buf);
+       if (i > LastArgv - p - 2)
+       {
+               i = LastArgv - p - 2;
+               buf[i] = '\0';
+       }
+       (void) strcpy(p, buf);
+       p += i;
+       while (p < LastArgv)
+               *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
+}