file reorg, pathnames.h, paths.h
[unix-history] / usr / src / usr.sbin / sendmail / src / conf.c
index fd5ec6e..f9fca2f 100644 (file)
@@ -1,3 +1,27 @@
+/*
+ * 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 are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)conf.c     5.19 (Berkeley) %G%";
+#endif /* not lint */
+
+# include <sys/ioctl.h>
+# include <sys/param.h>
 # include <pwd.h>
 # include "sendmail.h"
 
 # include <pwd.h>
 # include "sendmail.h"
 
@@ -7,11 +31,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.
@@ -32,7 +52,6 @@
 
 
 
 
 
 
-SCCSID(@(#)conf.c      3.67            %G%);
 \f/*
 **  Header info table
 **     Final (null) entry contains the flags used for any other field.
 \f/*
 **  Header info table
 **     Final (null) entry contains the flags used for any other field.
@@ -46,23 +65,30 @@ SCCSID(@(#)conf.c   3.67            %G%);
 struct hdrinfo HdrInfo[] =
 {
                /* originator fields, most to least significant  */
 struct hdrinfo HdrInfo[] =
 {
                /* originator fields, most to least significant  */
-       "resent-sender",        H_FROM,
-       "resent-from",          H_FROM,
+       "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,
                /* destination fields */
        "to",                   H_RCPT,
        "full-name",            H_ACHECK,
        "return-receipt-to",    H_FROM,
        "errors-to",            H_FROM,
                /* destination fields */
        "to",                   H_RCPT,
-       "resent-to",            H_RCPT,
+       "resent-to",            H_RCPT|H_RESENT,
        "cc",                   H_RCPT,
        "cc",                   H_RCPT,
-       "resent-cc",            H_RCPT,
+       "resent-cc",            H_RCPT|H_RESENT,
        "bcc",                  H_RCPT|H_ACHECK,
        "bcc",                  H_RCPT|H_ACHECK,
-       "resent-bcc",           H_RCPT|H_ACHECK,
+       "resent-bcc",           H_RCPT|H_ACHECK|H_RESENT,
                /* message identification and control */
                /* message identification and control */
+       "message-id",           0,
+       "resent-message-id",    H_RESENT,
        "message",              H_EOH,
        "text",                 H_EOH,
        "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,
                /* trace fields */
        "received",             H_TRACE|H_FORCE,
        "via",                  H_TRACE|H_FORCE,
@@ -87,175 +113,47 @@ 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 =     "/etc/sendmail.cf";     /* runtime configuration */
+char   *FreezeFile =   "/etc/sendmail.fc";     /* frozen version of above */
 
 
 
 /*
 
 
 
 /*
-**  Some other configuration....
-*/
-
-char   SpaceSub =      '.';
-\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".
+**  Miscellaneous stuff.
 */
 
 */
 
-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);
-}
+int    DtableSize =    50;             /* max open files; reset in 4.2bsd */
 \f/*
 \f/*
-**  INDEX -- Return pointer to character in string
+**  SETDEFAULTS -- set default values
 **
 **
-**     For V7 compatibility.
+**     Because of the way freezing is done, these must be initialized
+**     using direct code.
 **
 **     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.
-**
-**     Side Effects:
 **             none.
 **             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);
-}
-
-
-/*
-**  GETEUID -- get effective user id.
-*/
-
-geteuid()
-{
-       return ((getuid() >> 8) & 0377);
-}
-
-
-/*
-**  GETEGID -- get effective group id.
+**     Side Effects:
+**             Initializes a bunch of global variables to their
+**             default values.
 */
 
 */
 
-getegid()
+setdefaults()
 {
 {
-       return ((getgid() >> 8) & 0377);
+       QueueLA = 8;
+       QueueFactor = 10000;
+       RefuseLA = 12;
+       SpaceSub = ' ';
+       WkRecipFact = 1000;
+       WkClassFact = 1800;
+       WkTimeFact = 9000;
+       FileMode = 0644;
+       DefUid = 1;
+       DefGid = 1;
 }
 
 }
 
-# endif V6
-\f
-# ifndef V6
-
 /*
 **  GETRUID -- get real user id (V7)
 */
 /*
 **  GETRUID -- get real user id (V7)
 */
@@ -281,8 +179,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:
@@ -301,9 +198,41 @@ getrgid()
 char *
 username()
 {
 char *
 username()
 {
+       static char *myname = NULL;
        extern char *getlogin();
        extern char *getlogin();
+       register struct passwd *pw;
+       extern struct passwd *getpwuid();
+
+       /* cache the result */
+       if (myname == NULL)
+       {
+               myname = getlogin();
+               if (myname == NULL || myname[0] == '\0')
+               {
+
+                       pw = getpwuid(getruid());
+                       if (pw != NULL)
+                               myname = pw->pw_name;
+               }
+               else
+               {
+
+                       pw = getpwnam(myname);
+                       if(getuid() != pw->pw_uid)
+                       {
+                               pw = getpwuid(getuid());
+                               if (pw != NULL)
+                                       myname = pw->pw_name;
+                       }
+               }
+               if (myname == NULL || myname[0] == '\0')
+               {
+                       syserr("Who are you?");
+                       myname = "postmaster";
+               }
+       }
 
 
-       return (getlogin());
+       return (myname);
 }
 \f/*
 **  TTYPATH -- Get the path of the user's tty
 }
 \f/*
 **  TTYPATH -- Get the path of the user's tty
@@ -391,25 +320,23 @@ bool
 checkcompat(to)
        register ADDRESS *to;
 {
 checkcompat(to)
        register ADDRESS *to;
 {
-# ifdef ING70
+# ifdef lint
+       if (to == NULL)
+               to++;
+# endif lint
+# ifdef EXAMPLE_CODE
+       /* this code is intended as an example only */
        register STAB *s;
        register STAB *s;
-# endif ING70
 
 
-       if (to->q_mailer != LocalMailer && CurEnv->e_msgsize > 100000)
-       {
-               usrerr("Message exceeds 100000 bytes");
-               NoReturn++;
-               return (FALSE);
-       }
-# ifdef ING70
        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");
        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);
        }
                return (FALSE);
        }
-# endif ING70
+# endif EXAMPLE_CODE
        return (TRUE);
 }
 \f/*
        return (TRUE);
 }
 \f/*
@@ -447,47 +374,172 @@ rlsesigs()
 {
 }
 \f/*
 {
 }
 \f/*
-**  MYHOSTNAME -- return the name of this host.
+**  GETLA -- get the current load average
+**
+**     This code stolen from la.c.
 **
 **     Parameters:
 **
 **     Parameters:
-**             hostbuf -- a place to return the name of this host.
+**             none.
 **
 **     Returns:
 **
 **     Returns:
-**             A list of aliases for this host.
+**             The current load average as an integer.
 **
 **     Side Effects:
 **             none.
 */
 
 #ifdef VMUNIX
 **
 **     Side Effects:
 **             none.
 */
 
 #ifdef VMUNIX
-#include <netdb.h>
+
+#include <nlist.h>
+
+struct nlist Nl[] =
+{
+       { "_avenrun" },
+#define        X_AVENRUN       0
+       { 0 },
+};
+
+getla()
+{
+       static int kmem = -1;
+# ifdef sun
+       long avenrun[3];
+# else
+       double avenrun[3];
+# endif
+       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);
+       }
+# ifdef sun
+       return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
+# else
+       return ((int) (avenrun[0] + 0.5));
+# endif
+}
+
+#else VMUNIX
+
+getla()
+{
+       return (0);
+}
+
 #endif VMUNIX
 #endif VMUNIX
+\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.
+*/
 
 
-char **
-myhostname(hostbuf)
-       char hostbuf[];
+bool
+shouldqueue(pri)
+       long pri;
 {
 {
-#ifdef VMUNIX
-       extern struct hostent *gethostbyname();
-       struct hostent *hent;
+       int la;
 
 
-       gethostname(hostbuf, sizeof hostbuf);
-       hent = gethostbyname(hostbuf);
-       if (hent != NULL)
-               return (hent->h_aliases);
-       else
-               return (NULL);
-# else VMUNIX
-       register FILE *f;
+       la = getla();
+       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];
 
 
-       hostbuf[0] = '\0';
-       f = fopen("/usr/include/whoami", "r");
-       if (f != NULL)
+       (void) sprintf(buf, fmt, a, b, c);
+
+       /* make ps print "(sendmail)" */
+       p = Argv[0];
+       *p++ = '-';
+
+       i = strlen(buf);
+       if (i > LastArgv - p - 2)
        {
        {
-               (void) fgets(hostbuf, sizeof hostbuf, f);
-               fixcrlf(hostbuf, TRUE);
-               (void) fclose(f);
+               i = LastArgv - p - 2;
+               buf[i] = '\0';
        }
        }
-       return (NULL);
-#endif VMUNIX
+       (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
+
+reapchild()
+{
+# ifdef WNOHANG
+       union wait status;
+
+       while (wait3(&status, WNOHANG, (struct rusage *) NULL) > 0)
+               continue;
+# else WNOHANG
+       auto int status;
+
+       while (wait(&status) > 0)
+               continue;
+# endif WNOHANG
 }
 }