BSD 4_4 release
[unix-history] / usr / src / usr.sbin / sendmail / src / main.c
index 603748e..5027aeb 100644 (file)
@@ -1,31 +1,57 @@
 /*
  * Copyright (c) 1983 Eric P. Allman
 /*
  * Copyright (c) 1983 Eric P. Allman
- * Copyright (c) 1988 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1988, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * %sccs.include.redist.c%
+ * 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
-char copyright[] =
-"@(#) Copyright (c) 1988 Regents of the University of California.\n\
- All rights reserved.\n";
+static char copyright[] =
+"@(#) Copyright (c) 1988, 1993\n\
      The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     6.40 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     8.1 (Berkeley) 6/7/93";
 #endif /* not lint */
 
 #define        _DEFINE
 
 #include "sendmail.h"
 #endif /* not lint */
 
 #define        _DEFINE
 
 #include "sendmail.h"
-#include <sys/stat.h>
 #include <signal.h>
 #include <sgtty.h>
 #ifdef NAMED_BIND
 #include <arpa/nameser.h>
 #include <resolv.h>
 #endif
 #include <signal.h>
 #include <sgtty.h>
 #ifdef NAMED_BIND
 #include <arpa/nameser.h>
 #include <resolv.h>
 #endif
+#include <pwd.h>
 
 # ifdef lint
 char   edata, end;
 
 # ifdef lint
 char   edata, end;
@@ -72,6 +98,7 @@ ADDRESS               NullAddress =   /* a null address */
                { "", "", NULL, "" };
 char           *UserEnviron[MAXUSERENVIRON + 1];
                                /* saved user environment */
                { "", "", NULL, "" };
 char           *UserEnviron[MAXUSERENVIRON + 1];
                                /* saved user environment */
+char           RealUserName[256];      /* the actual user id on this host */
 
 /*
 **  Pointers for setproctitle.
 
 /*
 **  Pointers for setproctitle.
@@ -103,7 +130,6 @@ main(argc, argv, envp)
        register char *p;
        register char *q;
        char **av;
        register char *p;
        register char *q;
        char **av;
-       char *locname;
        extern int finis();
        extern char Version[];
        char *ep, *from;
        extern int finis();
        extern char Version[];
        char *ep, *from;
@@ -117,17 +143,17 @@ main(argc, argv, envp)
        bool safecf = TRUE;
        static bool reenter = FALSE;
        char *argv0 = argv[0];
        bool safecf = TRUE;
        static bool reenter = FALSE;
        char *argv0 = argv[0];
+       struct passwd *pw;
        struct stat stb;
        char jbuf[MAXHOSTNAMELEN];      /* holds MyHostName */
        extern int DtableSize;
        extern int optind;
        extern time_t convtime();
        extern putheader(), putbody();
        struct stat stb;
        char jbuf[MAXHOSTNAMELEN];      /* holds MyHostName */
        extern int DtableSize;
        extern int optind;
        extern time_t convtime();
        extern putheader(), putbody();
-       extern ENVELOPE *newenvelope();
        extern void intsig();
        extern char **myhostname();
        extern char *arpadate();
        extern void intsig();
        extern char **myhostname();
        extern char *arpadate();
-       extern char *getrealhostname();
+       extern char *getauthinfo();
        extern char *optarg;
        extern char **environ;
 
        extern char *optarg;
        extern char **environ;
 
@@ -143,8 +169,6 @@ main(argc, argv, envp)
                abort();
        }
        reenter = TRUE;
                abort();
        }
        reenter = TRUE;
-       extern ADDRESS *recipient();
-       bool canrename;
 
 #ifndef SYS5TZ
        /* enforce use of kernel-supplied time zone information */
 
 #ifndef SYS5TZ
        /* enforce use of kernel-supplied time zone information */
@@ -184,24 +208,30 @@ main(argc, argv, envp)
        openlog("sendmail", LOG_PID);
 #endif 
 
        openlog("sendmail", LOG_PID);
 #endif 
 
-       /*
-       **  Set default values for variables.
-       **      These cannot be in initialized data space.
-       */
-
-       setdefaults();
-
        /* set up the blank envelope */
        BlankEnvelope.e_puthdr = putheader;
        BlankEnvelope.e_putbody = putbody;
        BlankEnvelope.e_xfp = NULL;
        STRUCTCOPY(NullAddress, BlankEnvelope.e_from);
        /* set up the blank envelope */
        BlankEnvelope.e_puthdr = putheader;
        BlankEnvelope.e_putbody = putbody;
        BlankEnvelope.e_xfp = NULL;
        STRUCTCOPY(NullAddress, BlankEnvelope.e_from);
-       STRUCTCOPY(BlankEnvelope, MainEnvelope);
-       CurEnv = &MainEnvelope;
+       CurEnv = &BlankEnvelope;
+       STRUCTCOPY(NullAddress, MainEnvelope.e_from);
+
+       /*
+       **  Set default values for variables.
+       **      These cannot be in initialized data space.
+       */
+
+       setdefaults(&BlankEnvelope);
 
        RealUid = getuid();
        RealGid = getgid();
 
 
        RealUid = getuid();
        RealGid = getgid();
 
+       pw = getpwuid(RealUid);
+       if (pw != NULL)
+               (void) strcpy(RealUserName, pw->pw_name);
+       else
+               (void) sprintf(RealUserName, "Unknown UID %d", RealUid);
+
        /* Handle any non-getoptable constructions. */
        obsolete(argv);
 
        /* Handle any non-getoptable constructions. */
        obsolete(argv);
 
@@ -213,7 +243,11 @@ main(argc, argv, envp)
        **      to the run that froze the configuration.
        */
        nothaw = FALSE;
        **      to the run that froze the configuration.
        */
        nothaw = FALSE;
-#define OPTIONS                "b:C:cd:e:F:f:h:Iimno:p:q:r:sTtv"
+#ifdef __osf__
+#define OPTIONS                "B:b:C:cd:e:F:f:h:Iimno:p:q:r:sTtvx"
+#else
+#define OPTIONS                "B:b:C:cd:e:F:f:h:Iimno:p:q:r:sTtv"
+#endif
        while ((j = getopt(argc, argv, OPTIONS)) != EOF)
        {
                switch (j)
        while ((j = getopt(argc, argv, OPTIONS)) != EOF)
        {
                switch (j)
@@ -286,6 +320,11 @@ main(argc, argv, envp)
        OpMode = MD_DELIVER;
        FullName = getenv("NAME");
 
        OpMode = MD_DELIVER;
        FullName = getenv("NAME");
 
+#ifdef NAMED_BIND
+       if (tTd(8, 8))
+               _res.options |= RES_DEBUG;
+#endif
+
        errno = 0;
        from = NULL;
 
        errno = 0;
        from = NULL;
 
@@ -294,54 +333,61 @@ main(argc, argv, envp)
                /* initialize some macros, etc. */
                initmacros();
 
                /* initialize some macros, etc. */
                initmacros();
 
-               /* hostname */
-               av = myhostname(jbuf, sizeof jbuf);
-               if (jbuf[0] != '\0')
-               {
-                       struct  utsname utsname;
-                       extern char *strchr();
+               /* version */
+               define('v', Version, CurEnv);
+       }
 
 
-                       if (tTd(0, 4))
-                               printf("canonical name: %s\n", jbuf);
-                       p = newstr(jbuf);
-                       define('w', p, CurEnv);
+       /* hostname */
+       av = myhostname(jbuf, sizeof jbuf);
+       if (jbuf[0] != '\0')
+       {
+               struct  utsname utsname;
 
 
-                       q = strchr(jbuf, '.');
-                       if (q != NULL)
-                       {
-                               *q++ = '\0';
-                               p = newstr(jbuf);
-                               define('m', q, CurEnv);
-                       }
-                       setclass('w', p);
+               if (tTd(0, 4))
+                       printf("canonical name: %s\n", jbuf);
+               p = newstr(jbuf);
+               define('w', p, CurEnv);
+               setclass('w', p);
 
 
-                       if (uname(&utsname) >= 0)
-                               p = utsname.nodename;
-                       else
-                       {
-                               makelower(jbuf);
-                               p = jbuf;
-                       }
-                       if (tTd(0, 4))
-                               printf("UUCP nodename: %s\n", p);
-                       p = newstr(p);
-                       define('k', p, CurEnv);
+               q = strchr(jbuf, '.');
+               if (q != NULL)
+               {
+                       *q++ = '\0';
+                       define('m', q, CurEnv);
+                       p = newstr(jbuf);
                        setclass('w', p);
                }
                        setclass('w', p);
                }
-               while (av != NULL && *av != NULL)
+
+               if (uname(&utsname) >= 0)
+                       p = utsname.nodename;
+               else
                {
                {
-                       if (tTd(0, 4))
-                               printf("\ta.k.a.: %s\n", *av);
-                       setclass('w', *av++);
+                       makelower(jbuf);
+                       p = jbuf;
                }
                }
-
-               /* version */
-               define('v', Version, CurEnv);
+               if (tTd(0, 4))
+                       printf("UUCP nodename: %s\n", p);
+               p = newstr(p);
+               define('k', p, CurEnv);
+               setclass('w', p);
+       }
+       while (av != NULL && *av != NULL)
+       {
+               if (tTd(0, 4))
+                       printf("\ta.k.a.: %s\n", *av);
+               setclass('w', *av++);
        }
 
        /* current time */
        define('b', arpadate((char *) NULL), CurEnv);
 
        }
 
        /* current time */
        define('b', arpadate((char *) NULL), CurEnv);
 
+       /*
+       **  Find our real host name for future logging.
+       */
+
+       p = getauthinfo(STDIN_FILENO);
+       define('_', p, CurEnv);
+
        /*
        ** Crack argv.
        */
        /*
        ** Crack argv.
        */
@@ -408,7 +454,15 @@ main(argc, argv, envp)
                        }
                        break;
 
                        }
                        break;
 
+                 case 'B':     /* body type */
+                       CurEnv->e_bodytype = newstr(optarg);
+                       break;
+
                  case 'C':     /* select configuration file (already done) */
                  case 'C':     /* select configuration file (already done) */
+                       if (getuid() != 0)
+                               auth_warning(CurEnv,
+                                       "Processed by %s with -C %s",
+                                       RealUserName, optarg);
                        break;
 
                  case 'd':     /* debugging -- redo in case frozen */
                        break;
 
                  case 'd':     /* debugging -- redo in case frozen */
@@ -426,6 +480,10 @@ main(argc, argv, envp)
                                break;
                        }
                        from = newstr(optarg);
                                break;
                        }
                        from = newstr(optarg);
+                       if (strcmp(RealUserName, from) != 0)
+                               auth_warning(CurEnv,
+                                       "%s set sender to %s using -%c",
+                                       RealUserName, from, j);
                        break;
 
                  case 'F':     /* set full name */
                        break;
 
                  case 'F':     /* set full name */
@@ -447,7 +505,7 @@ main(argc, argv, envp)
                        break;
 
                  case 'o':     /* set option */
                        break;
 
                  case 'o':     /* set option */
-                       setoption(*optarg, optarg + 1, FALSE, TRUE);
+                       setoption(*optarg, optarg + 1, FALSE, TRUE, CurEnv);
                        break;
 
                  case 'p':     /* set protocol */
                        break;
 
                  case 'p':     /* set protocol */
@@ -480,7 +538,7 @@ main(argc, argv, envp)
                                break;
 
                          default:
                                break;
 
                          default:
-                               QueueIntvl = convtime(optarg);
+                               QueueIntvl = convtime(optarg, 'm');
                                break;
                        }
 # else /* QUEUE */
                                break;
                        }
 # else /* QUEUE */
@@ -499,15 +557,15 @@ main(argc, argv, envp)
                  case 'm':     /* send to me too */
                  case 'T':     /* set timeout interval */
                  case 'v':     /* give blow-by-blow description */
                  case 'm':     /* send to me too */
                  case 'T':     /* set timeout interval */
                  case 'v':     /* give blow-by-blow description */
-                       setoption(j, "T", FALSE, TRUE);
+                       setoption(j, "T", FALSE, TRUE, CurEnv);
                        break;
 
                  case 'e':     /* error message disposition */
                        break;
 
                  case 'e':     /* error message disposition */
-                       setoption(j, optarg, FALSE, TRUE);
+                       setoption(j, optarg, FALSE, TRUE, CurEnv);
                        break;
 
                  case 's':     /* save From lines in headers */
                        break;
 
                  case 's':     /* save From lines in headers */
-                       setoption('f', "T", FALSE, TRUE);
+                       setoption('f', "T", FALSE, TRUE, CurEnv);
                        break;
 
 # ifdef DBM
                        break;
 
 # ifdef DBM
@@ -516,6 +574,11 @@ main(argc, argv, envp)
                        break;
 # endif /* DBM */
 
                        break;
 # endif /* DBM */
 
+# ifdef __osf__
+                 case 'x':     /* random flag that DEC OSF/1 mailx passes */
+                       break;
+# endif
+
                  default:
                        ExitStat = EX_USAGE;
                        finis();
                  default:
                        ExitStat = EX_USAGE;
                        finis();
@@ -524,11 +587,6 @@ main(argc, argv, envp)
        }
        av += optind;
 
        }
        av += optind;
 
-#ifdef NAMED_BIND
-       if (tTd(8, 8))
-               _res.options |= RES_DEBUG;
-#endif
-
        /*
        **  Do basic initialization.
        **      Read system control file.
        /*
        **  Do basic initialization.
        **      Read system control file.
@@ -594,26 +652,23 @@ main(argc, argv, envp)
                /* remove things that don't make sense in daemon mode */
                FullName = NULL;
                break;
                /* remove things that don't make sense in daemon mode */
                FullName = NULL;
                break;
-       }
-
-       /*
-       **  Find our real host name for future logging.
-       */
 
 
-       p = getrealhostname(STDIN_FILENO);
-       if (p != NULL)
-               RealHostName = newstr(p);
-       else
-               RealHostName = "localhost";
+         case MD_SMTP:
+               if (RealUid != 0)
+                       auth_warning(CurEnv,
+                               "%s owned process doing -bs",
+                               RealUserName);
+               break;
+       }
 
        /* do heuristic mode adjustment */
        if (Verbose)
        {
                /* turn off noconnect option */
 
        /* do heuristic mode adjustment */
        if (Verbose)
        {
                /* turn off noconnect option */
-               setoption('c', "F", TRUE, FALSE);
+               setoption('c', "F", TRUE, FALSE, CurEnv);
 
                /* turn on interactive delivery */
 
                /* turn on interactive delivery */
-               setoption('d', "", TRUE, FALSE);
+               setoption('d', "", TRUE, FALSE, CurEnv);
        }
 
        /* our name for SMTP codes */
        }
 
        /* our name for SMTP codes */
@@ -676,7 +731,7 @@ main(argc, argv, envp)
 
          case MD_INITALIAS:
                /* initialize alias database */
 
          case MD_INITALIAS:
                /* initialize alias database */
-               initaliases(AliasFile, TRUE, CurEnv);
+               initmaps(TRUE, CurEnv);
                exit(EX_OK);
 
          case MD_DAEMON:
                exit(EX_OK);
 
          case MD_DAEMON:
@@ -685,7 +740,7 @@ main(argc, argv, envp)
 
          default:
                /* open the alias database */
 
          default:
                /* open the alias database */
-               initaliases(AliasFile, FALSE, CurEnv);
+               initmaps(FALSE, CurEnv);
                break;
        }
 
                break;
        }
 
@@ -778,7 +833,6 @@ main(argc, argv, envp)
                                continue;
                        do
                        {
                                continue;
                        do
                        {
-                               extern char **prescan();
                                char pvpbuf[PSBUFSIZE];
 
                                pvp = prescan(++p, ',', pvpbuf, &delimptr);
                                char pvpbuf[PSBUFSIZE];
 
                                pvp = prescan(++p, ',', pvpbuf, &delimptr);
@@ -787,7 +841,12 @@ main(argc, argv, envp)
                                p = q;
                                while (*p != '\0')
                                {
                                p = q;
                                while (*p != '\0')
                                {
-                                       rewrite(pvp, atoi(p));
+                                       int stat;
+
+                                       stat = rewrite(pvp, atoi(p), CurEnv);
+                                       if (stat != EX_OK)
+                                               printf("== Ruleset %s status %d\n",
+                                                       p, stat);
                                        while (*p != '\0' && *p++ != ',')
                                                continue;
                                }
                                        while (*p != '\0' && *p++ != ',')
                                                continue;
                                }
@@ -838,15 +897,16 @@ main(argc, argv, envp)
                        strcat(dtype, "+SMTP");
                if (QueueIntvl != 0)
                {
                        strcat(dtype, "+SMTP");
                if (QueueIntvl != 0)
                {
-                       extern char *pintvl();
-
                        strcat(dtype, "+queueing@");
                        strcat(dtype, pintvl(QueueIntvl, TRUE));
                }
                if (tTd(0, 1))
                        strcat(dtype, "+debugging");
 
                        strcat(dtype, "+queueing@");
                        strcat(dtype, pintvl(QueueIntvl, TRUE));
                }
                if (tTd(0, 1))
                        strcat(dtype, "+debugging");
 
-               syslog(LOG_INFO, "starting daemon: %s", dtype + 1);
+               syslog(LOG_INFO, "starting daemon (%s): %s", Version, dtype + 1);
+#ifdef XLA
+               xla_create_file();
+#endif
 
 # ifdef QUEUE
                if (queuemode)
 
 # ifdef QUEUE
                if (queuemode)
@@ -863,9 +923,15 @@ main(argc, argv, envp)
                getrequests();
 
                /* at this point we are in a child: reset state */
                getrequests();
 
                /* at this point we are in a child: reset state */
-               OpMode = MD_SMTP;
                (void) newenvelope(CurEnv, CurEnv);
                (void) newenvelope(CurEnv, CurEnv);
-               openxscript(CurEnv);
+
+               /*
+               **  Get authentication data
+               */
+
+               p = getauthinfo(fileno(InChannel));
+               define('_', p, CurEnv);
+
 #endif /* DAEMON */
        }
        
 #endif /* DAEMON */
        }
        
@@ -883,13 +949,19 @@ main(argc, argv, envp)
        **  Do basic system initialization and set the sender
        */
 
        **  Do basic system initialization and set the sender
        */
 
-# ifndef SYSTEM5
        /* make sendmail immune from process group signals */
        /* make sendmail immune from process group signals */
+# ifdef _POSIX_JOB_CONTROL
+       (void) setpgid(0, getpid());
+# else
+# ifndef SYSTEM5
        (void) setpgrp(0, getpid());
        (void) setpgrp(0, getpid());
+# endif
 # endif
 
        initsys(CurEnv);
        setsender(from, CurEnv, NULL, FALSE);
 # endif
 
        initsys(CurEnv);
        setsender(from, CurEnv, NULL, FALSE);
+       if (macvalue('s', CurEnv) == NULL)
+               define('s', RealHostName, CurEnv);
 
        if (*av == NULL && !GrabTo)
        {
 
        if (*av == NULL && !GrabTo)
        {
@@ -897,11 +969,14 @@ main(argc, argv, envp)
 
                /* collect body for UUCP return */
                if (OpMode != MD_VERIFY)
 
                /* collect body for UUCP return */
                if (OpMode != MD_VERIFY)
-                       collect(FALSE, CurEnv);
+                       collect(FALSE, FALSE, CurEnv);
                finis();
        }
        if (OpMode == MD_VERIFY)
                finis();
        }
        if (OpMode == MD_VERIFY)
-               SendMode = SM_VERIFY;
+       {
+               CurEnv->e_sendmode = SM_VERIFY;
+               CurEnv->e_errormode = EM_QUIET;
+       }
 
        /*
        **  Scan argv and deliver the message to everyone.
 
        /*
        **  Scan argv and deliver the message to everyone.
@@ -919,7 +994,7 @@ main(argc, argv, envp)
 
        CurEnv->e_to = NULL;
        if (OpMode != MD_VERIFY || GrabTo)
 
        CurEnv->e_to = NULL;
        if (OpMode != MD_VERIFY || GrabTo)
-               collect(FALSE, CurEnv);
+               collect(FALSE, FALSE, CurEnv);
        errno = 0;
 
        /* collect statistics */
        errno = 0;
 
        /* collect statistics */
@@ -944,7 +1019,8 @@ main(argc, argv, envp)
        sendall(CurEnv, SM_DEFAULT);
 
        /*
        sendall(CurEnv, SM_DEFAULT);
 
        /*
-       ** All done.
+       **  All done.
+       **      Don't send return error message if in VERIFY mode.
        */
 
        finis();
        */
 
        finis();
@@ -977,6 +1053,11 @@ finis()
        /* post statistics */
        poststats(StatFile);
 
        /* post statistics */
        poststats(StatFile);
 
+# ifdef XLA
+       /* clean up extended load average stuff */
+       xla_all_end();
+# endif
+
        /* and exit */
 # ifdef LOG
        if (LogLevel > 78)
        /* and exit */
 # ifdef LOG
        if (LogLevel > 78)
@@ -1007,6 +1088,9 @@ intsig()
 {
        FileName = NULL;
        unlockqueue(CurEnv);
 {
        FileName = NULL;
        unlockqueue(CurEnv);
+#ifdef XLA
+       xla_all_end();
+#endif
        exit(EX_OK);
 }
 \f/*
        exit(EX_OK);
 }
 \f/*
@@ -1034,15 +1118,17 @@ struct metamac  MetaMacros[] =
        /* these are RHS metasymbols */
        '#', CANONNET,          '@', CANONHOST,         ':', CANONUSER,
        '>', CALLSUBR,
        /* these are RHS metasymbols */
        '#', CANONNET,          '@', CANONHOST,         ':', CANONUSER,
        '>', CALLSUBR,
-       '{', MATCHLOOKUP,               '}', MATCHELOOKUP,
 
        /* the conditional operations */
        '?', CONDIF,            '|', CONDELSE,          '.', CONDFI,
 
 
        /* the conditional operations */
        '?', CONDIF,            '|', CONDELSE,          '.', CONDFI,
 
-       /* and finally the hostname lookup characters */
+       /* the hostname lookup characters */
        '[', HOSTBEGIN,         ']', HOSTEND,
        '(', LOOKUPBEGIN,       ')', LOOKUPEND,
 
        '[', HOSTBEGIN,         ']', HOSTEND,
        '(', LOOKUPBEGIN,       ')', LOOKUPEND,
 
+       /* miscellaneous control characters */
+       '&', MACRODEXPAND,
+
        '\0'
 };
 
        '\0'
 };
 
@@ -1096,7 +1182,7 @@ union frz
        } frzinfo;
 };
 
        } frzinfo;
 };
 
-#ifdef __hpux
+#if defined(__hpux) || defined(__alpha)
 #define BRK_TYPE        int
 #define SBRK_TYPE       void *
 #else
 #define BRK_TYPE        int
 #define SBRK_TYPE       void *
 #else
@@ -1170,7 +1256,6 @@ thaw(freezefile, binfile)
        extern char edata, end;
        extern char Version[];
        extern char **myhostname();
        extern char edata, end;
        extern char Version[];
        extern char **myhostname();
-       extern char *macvalue();
        extern BRK_TYPE brk();
 
        if (freezefile == NULL)
        extern BRK_TYPE brk();
 
        if (freezefile == NULL)
@@ -1211,13 +1296,14 @@ thaw(freezefile, binfile)
            fhdr.frzinfo.frzend != &end ||
            strcmp(fhdr.frzinfo.frzver, Version) != 0)
        {
            fhdr.frzinfo.frzend != &end ||
            strcmp(fhdr.frzinfo.frzver, Version) != 0)
        {
+               fprintf(stderr, "Wrong version of frozen config file\n");
                syslog(LOG_WARNING, "Wrong version of frozen config file");
                (void) close(f);
                return (FALSE);
        }
 
        /* arrange to have enough space */
                syslog(LOG_WARNING, "Wrong version of frozen config file");
                (void) close(f);
                return (FALSE);
        }
 
        /* arrange to have enough space */
-       if (brk(fhdr.frzinfo.frzbrk) == (caddr_t) -1)
+       if (brk(fhdr.frzinfo.frzbrk) == (BRK_TYPE) -1)
        {
                syserr("Cannot break to %x", fhdr.frzinfo.frzbrk);
                (void) close(f);
        {
                syserr("Cannot break to %x", fhdr.frzinfo.frzbrk);
                (void) close(f);
@@ -1289,7 +1375,7 @@ disconnect(fulldrop, e)
 
        /* we can't communicate with our caller, so.... */
        HoldErrs = TRUE;
 
        /* we can't communicate with our caller, so.... */
        HoldErrs = TRUE;
-       ErrorMode = EM_MAIL;
+       CurEnv->e_errormode = EM_MAIL;
        Verbose = FALSE;
 
        /* all input from /dev/null */
        Verbose = FALSE;
 
        /* all input from /dev/null */
@@ -1319,11 +1405,7 @@ disconnect(fulldrop, e)
        /* drop our controlling TTY completely if possible */
        if (fulldrop)
        {
        /* drop our controlling TTY completely if possible */
        if (fulldrop)
        {
-#ifdef SYSTEM5
-               (void) setpgrp();
-#else
                (void) setsid();
                (void) setsid();
-#endif
 #ifdef TIOCNOTTY
                fd = open("/dev/tty", 2);
                if (fd >= 0)
 #ifdef TIOCNOTTY
                fd = open("/dev/tty", 2);
                if (fd >= 0)
@@ -1350,7 +1432,7 @@ obsolete(argv)
 {
        char *ap;
 
 {
        char *ap;
 
-       while (ap = *++argv)
+       while ((ap = *++argv) != NULL)
        {
                /* Return if "--" or not an option of any form. */
                if (ap[0] != '-' || ap[1] == '-')
        {
                /* Return if "--" or not an option of any form. */
                if (ap[0] != '-' || ap[1] == '-')
@@ -1374,7 +1456,49 @@ obsolete(argv)
 
                /* if -d doesn't have an argument, use 0-99.1 */
                if (ap[1] == 'd' && ap[2] == '\0' &&
 
                /* if -d doesn't have an argument, use 0-99.1 */
                if (ap[1] == 'd' && ap[2] == '\0' &&
-                   (argv[1] == NULL || argv[1][0] == '-'))
+                   (argv[1] == NULL || !isdigit(argv[1][0])))
                        *argv = "-d0-99.1";
        }
 }
                        *argv = "-d0-99.1";
        }
 }
+\f/*
+**  AUTH_WARNING -- specify authorization warning
+**
+**     Parameters:
+**             e -- the current envelope.
+**             msg -- the text of the message.
+**             args -- arguments to the message.
+**
+**     Returns:
+**             none.
+*/
+
+void
+#ifdef __STDC__
+auth_warning(register ENVELOPE *e, const char *msg, ...)
+#else
+auth_warning(e, msg, va_alist)
+       register ENVELOPE *e;
+       const char *msg;
+       va_dcl
+#endif
+{
+       char buf[MAXLINE];
+       VA_LOCAL_DECL
+
+       if (bitset(PRIV_AUTHWARNINGS, PrivacyFlags))
+       {
+               register char *p;
+               static char hostbuf[48];
+               extern char **myhostname();
+
+               if (hostbuf[0] == '\0')
+                       (void) myhostname(hostbuf, sizeof hostbuf);
+
+               (void) sprintf(buf, "%s: ", hostbuf);
+               p = &buf[strlen(buf)];
+               VA_START(msg);
+               vsprintf(p, msg, ap);
+               VA_END;
+               addheader("X-Authentication-Warning", buf, e);
+       }
+}