check syscall return values in a few questions; thanks go to Ian Darwin's
[unix-history] / usr / src / usr.sbin / sendmail / src / conf.c
index b8e0cfe..3bac230 100644 (file)
@@ -1,4 +1,5 @@
 # include <pwd.h>
 # include <pwd.h>
+# include <sys/ioctl.h>
 # include "sendmail.h"
 
 /*
 # include "sendmail.h"
 
 /*
 **                     the two systems.  If you are running a funny
 **                     system, e.g., V6 with long tty names, this
 **                     should be checked carefully.
 **                     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.
 **                     Each entry has the field name and some flags,
 **                     which are described in sendmail.h.
 **
 **     Configuration Variables:
 **             HdrInfo -- a table describing well-known header fields.
 **                     Each entry has the field name and some flags,
 **                     which are described in sendmail.h.
-**             StdTimezone -- name of local timezone in standard time
-**                     (V6 only).
-**             DstTimezone -- name of local timezone in daylight savings
-**                     time (V6 only).
 **
 **     Notes:
 **             I have tried to put almost all the reasonable
 **
 **     Notes:
 **             I have tried to put almost all the reasonable
@@ -36,7 +34,7 @@
 
 
 
 
 
 
-SCCSID(@(#)conf.c      3.50            %G%);
+SCCSID(@(#)conf.c      4.9             %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.
@@ -49,25 +47,35 @@ SCCSID(@(#)conf.c   3.50            %G%);
 
 struct hdrinfo HdrInfo[] =
 {
 
 struct hdrinfo HdrInfo[] =
 {
-       "date",                 H_CHECK,                M_NEEDDATE,
-       "from",                 H_ADDR|H_CHECK,         M_NEEDFROM,
-       "original-from",        0,                      0,
-       "sender",               H_ADDR,                 0,
-       "full-name",            H_ACHECK,               M_FULLNAME,
-       "to",                   H_ADDR|H_RCPT,          0,
-       "cc",                   H_ADDR|H_RCPT,          0,
-       "bcc",                  H_ADDR|H_RCPT,          0,
-       "message-id",           0,                      0,
-       "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,
-       "mail-from",            H_FORCE,                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,
+       "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,
 };
 
 
 };
 
 
@@ -75,11 +83,10 @@ struct hdrinfo      HdrInfo[] =
 **  ARPANET error message numbers.
 */
 
 **  ARPANET error message numbers.
 */
 
-char   Arpa_Info[] =   "050";  /* arbitrary info */
-char   Arpa_Syserr[] = "451";  /* some (transient) system error */
-char   Arpa_Usrerr[] = "554";  /* some (fatal) user error */
-
-
+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 */
 
 
 
 
 
 
@@ -87,39 +94,18 @@ char        Arpa_Usrerr[] = "554";  /* some (fatal) user error */
 **  Location of system files/databases/etc.
 */
 
 **  Location of system files/databases/etc.
 */
 
-char   *AliasFile =    "/usr/lib/aliases";     /* alias file */
 char   *ConfFile =     "/usr/lib/sendmail.cf"; /* runtime configuration */
 char   *ConfFile =     "/usr/lib/sendmail.cf"; /* runtime configuration */
-char   *StatFile =     "/usr/lib/sendmail.st"; /* statistics summary */
-char   *HelpFile =     "/usr/lib/sendmail.hf"; /* help file */
-# ifdef QUEUE
-char   *QueueDir =     "/usr/spool/mqueue";    /* queue of saved mail */
-# else QUEUE
-char   *QueueDir =     "/tmp";                 /* location of temp files */
-# endif QUEUE
-char   *XcriptFile =   "/tmp/mailxXXXXXX";     /* template for transcript */
-
-
-/*
-**  Other configuration.
-*/
-
-int    DefUid =        1;              /* the uid to execute mailers as */
-int    DefGid =        1;              /* ditto for gid */
-time_t TimeOut =       3*24*60*60L;    /* default timeout for queue files */
-char   *TextTimeOut =  "three days";   /* text of above for error messages */
-int    ReadTimeout =   10*60;          /* timeout on external reads */
-int    LogLevel =      2;              /* default logging level */
+char   *FreezeFile =   "/usr/lib/sendmail.fc"; /* frozen version of above */
 
 
 
 /*
 
 
 
 /*
-**  V6 system configuration.
+**  Some other configuration....
 */
 
 */
 
-# ifdef V6
-char   *StdTimezone =  "PST";          /* std time timezone */
-char   *DstTimezone =  "PDT";          /* daylight time timezone */
-# endif V6
+char   SpaceSub;               /* character to replace <lwsp> in addrs */
+int    QueueLA;                /* load avg > QueueLA -> just queue */
+int    RefuseLA;               /* load avg > RefuseLA -> refuse connections */
 \f
 # ifdef V6
 /*
 \f
 # ifdef V6
 /*
@@ -285,7 +271,7 @@ getegid()
 
 getruid()
 {
 
 getruid()
 {
-       if (Mode == MD_DAEMON)
+       if (OpMode == MD_DAEMON)
                return (RealUid);
        else
                return (getuid());
                return (RealUid);
        else
                return (getuid());
@@ -298,7 +284,7 @@ getruid()
 
 getrgid()
 {
 
 getrgid()
 {
-       if (Mode == MD_DAEMON)
+       if (OpMode == MD_DAEMON)
                return (RealGid);
        else
                return (getgid());
                return (RealGid);
        else
                return (getgid());
@@ -306,6 +292,60 @@ getrgid()
 
 # endif V6
 \f/*
 
 # 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()
+{
+       static char *myname = NULL;
+       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());
+                               myname = pw->pw_name;
+                       }
+               }
+               if (myname == NULL || myname[0] == '\0')
+               {
+                       syserr("Who are you?");
+                       myname = "postmaster";
+               }
+       }
+
+       return (myname);
+}
+\f/*
 **  TTYPATH -- Get the path of the user's tty
 **
 **     Returns the pathname of the user's tty.  Returns NULL if
 **  TTYPATH -- Get the path of the user's tty
 **
 **     Returns the pathname of the user's tty.  Returns NULL if
@@ -340,7 +380,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);
@@ -390,23 +431,138 @@ 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);
        s = stab("arpa", ST_MAILER, ST_FIND);
-       if (s != NULL && CurEnv->e_from.q_mailer != LocalMailer && to->q_mailer == s->s_mailer)
+       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");
        {
                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);
 }
        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.
+*/
+
+#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);
+               (void) ioctl(kmem, FIOCLEX, 0);
+               nlist("/vmunix", Nl);
+               if (Nl[0].n_type == 0)
+                       return (-1);
+       }
+       if (lseek(kmem, (long) Nl[X_AVENRUN].n_value, 0) < 0 ||
+           read(kmem, avenrun, sizeof(avenrun)) < sizeof(avenrun))
+       {
+               /* thank you Ian */
+               return (-1);
+       }
+       return ((int) (avenrun[0] + 0.5));
+}
+
+#else VMUNIX
+
+getla()
+{
+       return (0);
+}
+
+#endif VMUNIX
+\f/*
+**  DBMCLOSE -- close the DBM file
+**
+**     This depends on the implementation of the DBM library.  It
+**     seems to work for all versions that I have come across.
+**
+**     Parameters:
+**             none.
+**
+**     Returns:
+**             none.
+**
+**     Side Effects:
+**             Closes the current DBM file; dbminit must be
+**             called again to continue using the DBM routines.
+*/
+
+dbmclose()
+{
+       extern int pagf, dirf;  /* defined in the DBM package */
+
+       (void) close(pagf);
+       (void) close(dirf);
+}