Change QueueLA and RefuseLA to 8 and 12 respectively
[unix-history] / usr / src / usr.sbin / sendmail / src / conf.c
index b4bc18b..b775fbd 100644 (file)
-# include <stdio.h>
 # include <pwd.h>
 # include <pwd.h>
-# include "dlvrmail.h"
+# include "sendmail.h"
 
 /*
 
 /*
-**  CONF.C -- Delivermail Configuration Tables.
+**  CONF.C -- Sendmail Configuration Tables.
 **
 **     Defines the configuration of this installation.
 **
 **     Compilation Flags:
 **
 **     Defines the configuration of this installation.
 **
 **     Compilation Flags:
-**             HASARPA -- set if this machine has a connection to
-**                     the Arpanet.
-**             HASUUCP -- set if this machine has a connection to
-**                     the UUCP network.
-**             NETV6MAIL -- set if you want to use "v6mail" that
-**                     comes with the Berkeley network.  Normally
-**                     /bin/mail will work fine, but around Berkeley
-**                     we use v6mail because it is a "fixed target".
 **             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.
 **             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:
 **
 **     Configuration Variables:
-**             ArpaHost -- the name of the host through which arpanet
-**                     mail will be sent.
-**             MyLocName -- the name of the host on a local network.
-**                     This is used to disambiguate the contents of
-**                     ArpaHost among many hosts who may be sharing
-**                     a gateway.
-**             Mailer -- a table of mailers known to the system.
-**                     The fields are:
-**                     - the pathname of the mailer.
-**                     - a list of flags describing the properties
-**                       of this mailer:
-**                        M_FOPT -- if set, the mailer has a picky "-f"
-**                             option.  In this mode, the mailer will
-**                             only accept the "-f" option if the
-**                             sender is actually "root", "network",
-**                             and possibly (but not necessarily) if
-**                             the -f argument matches the real sender.
-**                             The effect is that if the "-f" option
-**                             is given to delivermail then it will be
-**                             passed through (as arguments 1 & 2) to
-**                             the mailer.
-**                        M_ROPT -- identical to M_FOPT, except uses
-**                             -r instead.
-**                        M_QUIET -- if set, don't print a message if
-**                             the mailer returns bad status.
-**                        M_RESTR -- if set, this mailer is restricted
-**                             to use by "daemon"; otherwise, we do a
-**                             setuid(getuid()) before calling the
-**                             mailer.
-**                        M_HDR -- if set, the mailer wants us to
-**                             insert a UNIX "From" line before
-**                             outputing.
-**                        M_NOHOST -- if set, this mailer doesn't care
-**                             about the host part (e.g., the local
-**                             mailer).
-**                        M_STRIPQ -- if set, strip quote (`"')
-**                             characters out of parameters as you
-**                             transliterate them into the argument
-**                             vector.  For example, the local mailer
-**                             is called directly, so these should be
-**                             stripped, but the program-mailer (i.e.,
-**                             csh) should leave them in.
-**                     - an exit status to use as the code for the
-**                       error message print if the mailer returns
-**                       something we don't understand.
-**                     - A list of names that are to be considered
-**                       "local" (and hence are stripped off) for
-**                       this mailer.
-**                     - An argument vector to be passed to the
-**                       mailer with the following substitutions:
-**                        $f - the from person name.
-**                        $u - the target user name.
-**                        $h - the target user host.
-**                        $c - the hop count.
-**                     >>>>>>>>>> Entry zero must be for the local
-**                     >> NOTE >> mailer and entry one must be for
-**                     >>>>>>>>>> the shell.
-**             ParseTab -- a table driving the parsing process.  Each
-**                     entry contains:
-**                     - a character that will trigger this entry.
-**                     - an index into the Mailer table.
-**                     - a word of flags, described in dlvrmail.h.
-**                     - an argument.  If we have P_MAP, it is the
-**                       character to turn the trigger character into.
-**                       If we have P_MOVE, it is the site to send it
-**                       to, using the mailer specified above.
+**             HdrInfo -- a table describing well-known header fields.
+**                     Each entry has the field name and some flags,
+**                     which are described in sendmail.h.
+**
+**     Notes:
+**             I have tried to put almost all the reasonable
+**             configuration information into the configuration
+**             file read at runtime.  My intent is that anything
+**             here is a function of the version of UNIX you
+**             are running, or is really static -- for example
+**             the headers are a superset of widely used
+**             protocols.  If you find yourself playing with
+**             this file too much, you may be making a mistake!
 */
 
 
 
 
 */
 
 
 
 
-static char SccsId[] = "@(#)conf.c     1.8     %G%";
-
-
-char   *ArpaHost = "Berkeley"; /* host name of gateway on Arpanet */
-bool   UseMsgId = FALSE;       /* don't put message id's in anywhere */
-
-# include <whoami.h>           /* definitions of machine id's at berkeley */
-
-# ifdef ING70
-static char    *BerkLocal[] = { "i", "ingres", "ing70", NULL };
-# define ArpaLocal     NULL
-char           *MyLocName = "Ing70";
-# define HASARPA
-# define V6
-# endif ING70
-
-# ifdef INGVAX
-/* untested */
-static char    *BerkLocal[] = { "j", "ingvax", NULL };
-char           *MyLocName = "IngVax";
-# endif INGVAX
-
-# ifdef CSVAX
-/* untested */
-static char    *BerkLocal[] = { "v", "csvax", "vax", NULL };
-static char    *UucpLocal[] = { "ucbvax", "ernie", NULL };
-char           *MyLocName = "CSVAX";
-# define HASUUCP
-# define NETV6MAIL
-# endif CSVAX
-
-# ifdef CORY
-/* untested */
-static char    *BerkLocal[] = { "y", "cory", NULL };
-char           *MyLocName = "Cory";
-# endif CORY
-
-# ifdef IMAGE
-/* untested */
-static char    *BerkLocal[] = { "m", "image", NULL };
-char           *MyLocName = "Image";
-# define V6
-# endif IMAGE
+SCCSID(@(#)conf.c      4.3             %G%);
+\f/*
+**  Header info table
+**     Final (null) entry contains the flags used for any other field.
+**
+**     Not all of these are actually handled specially by sendmail
+**     at this time.  They are included as placeholders, to let
+**     you know that "someday" I intend to have sendmail do
+**     something with them.
+*/
 
 
-# ifdef ESVAX
-/* untested */
-static char    *BerkLocal[] = { "o", "esvax", NULL };
-char           *MyLocName = "ESVAX";
-# endif ESVAX
+struct hdrinfo HdrInfo[] =
+{
+               /* originator fields, most to least significant  */
+       "resent-sender",        H_FROM|H_RESENT,
+       "resent-from",          H_FROM|H_RESENT,
+       "sender",               H_FROM,
+       "from",                 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,
+};
 
 
-# ifdef EECS40
-/* untested */
-static char    *BerkLocal[] = { "z", "eecs40", NULL };
-char           *MyLocName = "EECS40";
-# define V6
-# endif EECS40
 
 
+/*
+**  ARPANET error message numbers.
+*/
 
 
-# ifndef HASARPA
-# define ArpaLocal     NULL
-# endif HASARPA
+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 */
 
 
-# ifndef HASUUCP
-# define UucpLocal     NULL
-# endif HASUUCP
 
 
 
 
-struct mailer Mailer[] =
-{
-       /* local mail -- must be #0 */
-       {
-# ifdef NETV6MAIL
-               "/usr/net/bin/v6mail",
-# else
-               "/bin/mail",
-# endif
-               M_ROPT|M_NOHOST|M_STRIPQ,       EX_NOUSER,      NULL,
-               { "...local%mail", "-d", "$u", NULL }
-       },
-       /* pipes through programs -- must be #1 */
-       {
-               "/bin/csh",
-               M_HDR|M_NOHOST,                 EX_UNAVAIL,     NULL,
-               { "...prog%mail", "-fc", "$u", NULL }
-       },
-       /* local berkeley mail */
-       {
-               "/usr/net/bin/sendberkmail",
-               M_FOPT|M_HDR|M_STRIPQ,          EX_UNAVAIL,     BerkLocal,
-               { "...berk%mail", "-m", "$h", "-t", "$u", "-h", "$c", NULL }
-       },
-       /* arpanet mail */
-       {
-               "/usr/lib/mailers/arpa",
-               M_STRIPQ,                       0,              ArpaLocal,
-               { "...arpa%mail", "$f", "$h", "$u", NULL }
-       },
-       /* uucp mail (cheat & use Bell's v7 mail) */
-       {
-               "/bin/mail",
-               M_ROPT|M_STRIPQ,                EX_NOUSER,      UucpLocal,
-# ifdef DUMBMAIL
-               { "...uucp%mail", "$h!$u", NULL }
-# else
-               { "...uucp%mail", "-d", "$h!$u", NULL }
-# endif DUMBMAIL
-       },
-};
+/*
+**  Location of system files/databases/etc.
+*/
 
 
-# define M_LOCAL       0
-# define M_BERK                2
-# define M_ARPA                3
-# define M_UUCP                4
+char   *ConfFile =     "/usr/lib/sendmail.cf"; /* runtime configuration */
+char   *FreezeFile =   "/usr/lib/sendmail.fc"; /* frozen version of above */
 
 
 
 
 
 
-struct parsetab ParseTab[] =
-{
-       ':',    M_BERK,         P_ONE,                          NULL,
-# ifdef HASARPA
-       '@',    M_ARPA,         P_HLAST|P_USR_UPPER,            NULL,
-# else
-       '@',    M_BERK,         P_HLAST|P_USR_UPPER|P_MOVE,     "ing70",
-# endif HASARPA
-       '^',    -1,             P_MAP,                          "!",
-# ifdef HASUUCP
-       '!',    M_UUCP,         0,                              NULL,
-# else
-       '!',    M_BERK,         P_MOVE,                         "csvax",
-# endif HASUUCP
-       '.',    -1,             P_MAP|P_ONE,                    ":",
-       '\0',   M_LOCAL,        P_MOVE,                         "",
-};
-\f/*
-**  GETNAME -- Get the current users login name.
-**
-**     This is in config.c because it is somewhat machine dependent.
-**     Examine it carefully for your installation.
-**
-**     Algorithm:
-**             See if the person is logged in.  If so, return
-**                     the name s/he is logged in as.
-**             Look up the user id in /etc/passwd.  If found,
-**                     return that name.
-**             Return NULL.
-**
-**     Parameters:
-**             none
-**
-**     Returns:
-**             The login name of this user.
-**             NULL if this person is noone.
-**
-**     Side Effects:
-**             none
-**
-**     Called By:
-**             main
+/*
+**  Some other configuration....
 */
 
 */
 
-char *
-getname()
-{
-       register char *p;
-       register struct passwd *w;
-       extern char *getlogin();
-       extern struct passwd *getpwuid();
-       static char namebuf[9];
-
-       p = getlogin();
-       if (p != NULL && p[0] != '\0')
-               return (p);
-# ifdef V6
-       w = getpwuid(getuid() & 0377);
-# else
-       w = getpwuid(getuid());
-# endif V6
-       if (w != NULL)
-       {
-               strcpy(namebuf, w->pw_name);
-               return (namebuf);
-       }
-       return (NULL);
-}
+char   SpaceSub =      '.';    /* character to replace <lwsp> in addrs */
+int    QueueLA =       8;      /* load avg > QueueLA -> just queue */
+int    RefuseLA =      12;     /* load avg > RefuseLA -> refuse connections */
 \f
 # ifdef V6
 /*
 \f
 # ifdef V6
 /*
-**  TTYPATH -- Get the path of the user's tty -- Version 6 version.
-**
-**     Returns the pathname of the user's tty.  Returns NULL if
-**     the user is not logged in or if s/he has write permission
-**     denied.
+**  TTYNAME -- return name of terminal.
 **
 **     Parameters:
 **
 **     Parameters:
-**             none
+**             fd -- file descriptor to check.
 **
 **     Returns:
 **
 **     Returns:
-**             pathname of the user's tty.
-**             NULL if not logged in or write permission denied.
+**             pointer to full path of tty.
+**             NULL if no tty.
 **
 **     Side Effects:
 **             none.
 **
 **     Side Effects:
 **             none.
-**
-**     WARNING:
-**             Return value is in a local buffer.
-**
-**     Called By:
-**             savemail
 */
 
 */
 
-# include <sys/types.h>
-# include <sys/stat.h>
-
 char *
 char *
-ttypath()
+ttyname(fd)
+       int fd;
 {
 {
-       struct stat stbuf;
-       register int i;
+       register char tn;
        static char pathn[] = "/dev/ttyx";
        static char pathn[] = "/dev/ttyx";
-       extern int errno;
 
        /* compute the pathname of the controlling tty */
 
        /* compute the pathname of the controlling tty */
-       if ((i = ttyn(2)) == 'x' && (i = ttyn(1)) == 'x' && (i = ttyn(0)) == 'x')
-       {
-               errno = 0;
-               return (NULL);
-       }
-       pathn[8] = i;
-
-       /* see if we have write permission */
-       if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode))
+       if ((tn = ttyn(fd)) == NULL)
        {
                errno = 0;
                return (NULL);
        }
        {
                errno = 0;
                return (NULL);
        }
-
-       /* see if the user is logged in */
-       if (getlogin() == NULL)
-               return (NULL);
-
-       /* looks good */
+       pathn[8] = tn;
        return (pathn);
 }
 \f/*
        return (pathn);
 }
 \f/*
@@ -373,7 +173,7 @@ fdopen(fd, type)
        register FILE *f;
 
        f = fopen("/dev/null", type);
        register FILE *f;
 
        f = fopen("/dev/null", type);
-       close(fileno(f));
+       (void) close(fileno(f));
        fileno(f) = fd;
        return (f);
 }
        fileno(f) = fd;
        return (f);
 }
@@ -395,6 +195,7 @@ fdopen(fd, type)
 **             none.
 */
 
 **             none.
 */
 
+char *
 index(s, c)
        register char *s;
        register char c;
 index(s, c)
        register char *s;
        register char c;
@@ -406,11 +207,114 @@ index(s, c)
        }
        return (NULL);
 }
        }
        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);
+}
+
+
+/*
+**  GETEUID -- get effective user id.
+*/
+
+geteuid()
+{
+       return ((getuid() >> 8) & 0377);
+}
+
+
+/*
+**  GETEGID -- get effective group id.
+*/
+
+getegid()
+{
+       return ((getgid() >> 8) & 0377);
+}
+
 # endif V6
 \f
 # ifndef V6
 # endif V6
 \f
 # ifndef V6
+
+/*
+**  GETRUID -- get real user id (V7)
+*/
+
+getruid()
+{
+       if (OpMode == MD_DAEMON)
+               return (RealUid);
+       else
+               return (getuid());
+}
+
+
 /*
 /*
-**  TTYPATH -- Get the path of the user's tty -- Version 7 version.
+**  GETRGID -- get real group id (V7).
+*/
+
+getrgid()
+{
+       if (OpMode == MD_DAEMON)
+               return (RealGid);
+       else
+               return (getgid());
+}
+
+# endif V6
+\f/*
+**  USERNAME -- return the user id of the logged in user.
+**
+**     Parameters:
+**             none.
+**
+**     Returns:
+**             The login name of the logged in user.
+**
+**     Side Effects:
+**             none.
+**
+**     Notes:
+**             The return value is statically allocated.
+*/
+
+char *
+username()
+{
+       extern char *getlogin();
+
+       return (getlogin());
+}
+\f/*
+**  TTYPATH -- Get the path of the user's tty
 **
 **     Returns the pathname of the user's tty.  Returns NULL if
 **     the user is not logged in or if s/he has write permission
 **
 **     Returns the pathname of the user's tty.  Returns NULL if
 **     the user is not logged in or if s/he has write permission
@@ -433,7 +337,6 @@ index(s, c)
 **             savemail
 */
 
 **             savemail
 */
 
-# include <sys/types.h>
 # include <sys/stat.h>
 
 char *
 # include <sys/stat.h>
 
 char *
@@ -441,18 +344,19 @@ ttypath()
 {
        struct stat stbuf;
        register char *pathn;
 {
        struct stat stbuf;
        register char *pathn;
-       extern int errno;
        extern char *ttyname();
        extern char *ttyname();
+       extern char *getlogin();
 
        /* compute the pathname of the controlling tty */
 
        /* 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);
        }
 
        /* see if we have write permission */
        {
                errno = 0;
                return (NULL);
        }
 
        /* see if we have write permission */
-       if (stat(pathn, &stbuf) < 0 || !flagset(02, stbuf.st_mode))
+       if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
        {
                errno = 0;
                return (NULL);
        {
                errno = 0;
                return (NULL);
@@ -465,4 +369,137 @@ ttypath()
        /* looks good */
        return (pathn);
 }
        /* looks good */
        return (pathn);
 }
-# endif V6
+\f/*
+**  CHECKCOMPAT -- check for From and To person compatible.
+**
+**     This routine can be supplied on a per-installation basis
+**     to determine whether a person is allowed to send a message.
+**     This allows restriction of certain types of internet
+**     forwarding or registration of users.
+**
+**     If the hosts are found to be incompatible, an error
+**     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.
+**
+**     Returns:
+**             TRUE -- ok to send.
+**             FALSE -- not ok.
+**
+**     Side Effects:
+**             none (unless you include the usrerr stuff)
+*/
+
+bool
+checkcompat(to)
+       register ADDRESS *to;
+{
+# ifdef lint
+       if (to == NULL)
+               to++;
+# 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);
+}
+\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
+**
+**     Parameters:
+**             none.
+**
+**     Returns:
+**             The current load average as an integer.
+**
+**     Side Effects:
+**             none.
+*/
+
+#ifdef VMUNIX
+
+#include <nlist.h>
+
+struct nlist Nl[] =
+{
+       { "_avenrun" },
+#define        X_AVENRUN       0
+       { 0 },
+};
+
+getla()
+{
+       static int kmem = -1;
+       double avenrun[3];
+
+       if (kmem < 0)
+       {
+               kmem = open("/dev/kmem", 0);
+               if (kmem < 0)
+                       return (-1);
+               nlist("/vmunix", Nl);
+               if (Nl[0].n_type == 0)
+                       return (-1);
+       }
+       (void) lseek(kmem, (long) Nl[X_AVENRUN].n_value, 0);
+       (void) read(kmem, avenrun, sizeof(avenrun));
+       return ((int) (avenrun[0] + 0.5));
+}
+
+#else VMUNIX
+
+getla()
+{
+       return (0);
+}
+
+#endif VMUNIX