warn of the sins of wildcard MX records
[unix-history] / usr / src / usr.sbin / sendmail / src / main.c
index 01fa387..e106c59 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 1983 Eric P. Allman
+ * Copyright (c) 1983, 1995 Eric P. Allman
  * Copyright (c) 1988, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
  * Copyright (c) 1988, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
@@ -13,7 +13,7 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     8.94 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     8.133 (Berkeley) %G%";
 #endif /* not lint */
 
 #define        _DEFINE
 #endif /* not lint */
 
 #define        _DEFINE
@@ -66,9 +66,6 @@ ENVELOPE      BlankEnvelope;  /* a "blank" envelope */
 ENVELOPE       MainEnvelope;   /* the envelope around the basic letter */
 ADDRESS                NullAddress =   /* a null address */
                { "", "", NULL, "" };
 ENVELOPE       MainEnvelope;   /* the envelope around the basic letter */
 ADDRESS                NullAddress =   /* a null address */
                { "", "", NULL, "" };
-char           *UserEnviron[MAXUSERENVIRON + 2];
-                               /* saved user environment */
-char           RealUserName[256];      /* the actual user id on this host */
 char           *CommandLineArgs;       /* command line args for pid file */
 bool           Warn_Q_option = FALSE;  /* warn about Q option use */
 char           **SaveArgv;     /* argument vector for re-execing */
 char           *CommandLineArgs;       /* command line args for pid file */
 bool           Warn_Q_option = FALSE;  /* warn about Q option use */
 char           **SaveArgv;     /* argument vector for re-execing */
@@ -91,6 +88,7 @@ ERROR %%%%   Cannot have daemon mode without SMTP   %%%% ERROR
 
 #define MAXCONFIGLEVEL 6       /* highest config version level known */
 
 
 #define MAXCONFIGLEVEL 6       /* highest config version level known */
 
+int
 main(argc, argv, envp)
        int argc;
        char **argv;
 main(argc, argv, envp)
        int argc;
        char **argv;
@@ -110,15 +108,14 @@ main(argc, argv, envp)
        bool warn_C_flag = FALSE;
        char warn_f_flag = '\0';
        static bool reenter = FALSE;
        bool warn_C_flag = FALSE;
        char warn_f_flag = '\0';
        static bool reenter = FALSE;
-       char *argv0 = argv[0];
        struct passwd *pw;
        struct stat stb;
        struct hostent *hp;
        char jbuf[MAXHOSTNAMELEN];      /* holds MyHostName */
        struct passwd *pw;
        struct stat stb;
        struct hostent *hp;
        char jbuf[MAXHOSTNAMELEN];      /* holds MyHostName */
+       static char rnamebuf[MAXNAME];  /* holds RealUserName */
        extern int DtableSize;
        extern int optind;
        extern time_t convtime();
        extern int DtableSize;
        extern int optind;
        extern time_t convtime();
-       extern putheader(), putbody();
        extern void intsig();
        extern struct hostent *myhostname();
        extern char *arpadate();
        extern void intsig();
        extern struct hostent *myhostname();
        extern char *arpadate();
@@ -128,6 +125,7 @@ main(argc, argv, envp)
        extern char **environ;
        extern void sigusr1();
        extern void sighup();
        extern char **environ;
        extern void sigusr1();
        extern void sighup();
+       extern void initmacros __P((ENVELOPE *));
 
        /*
        **  Check to see if we reentered.
 
        /*
        **  Check to see if we reentered.
@@ -210,9 +208,10 @@ main(argc, argv, envp)
 
        pw = sm_getpwuid(RealUid);
        if (pw != NULL)
 
        pw = sm_getpwuid(RealUid);
        if (pw != NULL)
-               (void) strcpy(RealUserName, pw->pw_name);
+               (void) strcpy(rnamebuf, pw->pw_name);
        else
        else
-               (void) sprintf(RealUserName, "Unknown UID %d", RealUid);
+               (void) sprintf(rnamebuf, "Unknown UID %d", RealUid);
+       RealUserName = rnamebuf;
 
        /* save command line arguments */
        i = 0;
 
        /* save command line arguments */
        i = 0;
@@ -244,6 +243,9 @@ main(argc, argv, envp)
 #if defined(ultrix)
 # define OPTIONS       "B:b:C:cd:e:F:f:h:IiM:mnO:o:p:q:r:sTtvX:"
 #endif
 #if defined(ultrix)
 # define OPTIONS       "B:b:C:cd:e:F:f:h:IiM:mnO:o:p:q:r:sTtvX:"
 #endif
+#if defined(sony_news)
+# define OPTIONS       "B:b:C:cd:E:e:F:f:h:IiJ:mnO:o:p:q:r:sTtvX:"
+#endif
 #ifndef OPTIONS
 # define OPTIONS       "B:b:C:cd:e:F:f:h:IimnO:o:p:q:r:sTtvX:"
 #endif
 #ifndef OPTIONS
 # define OPTIONS       "B:b:C:cd:e:F:f:h:IimnO:o:p:q:r:sTtvX:"
 #endif
@@ -254,11 +256,70 @@ main(argc, argv, envp)
                  case 'd':
                        tTflag(optarg);
                        setbuf(stdout, (char *) NULL);
                  case 'd':
                        tTflag(optarg);
                        setbuf(stdout, (char *) NULL);
-                       printf("Version %s\n", Version);
                        break;
                }
        }
 
                        break;
                }
        }
 
+       if (tTd(0, 1))
+       {
+               int ll;
+               extern char *CompileOptions[];
+
+               printf("Version %s\n Compiled with:", Version);
+               av = CompileOptions;
+               ll = 7;
+               while (*av != NULL)
+               {
+                       if (ll + strlen(*av) > 63)
+                       {
+                               putchar('\n');
+                               ll = 0;
+                       }
+                       if (ll == 0)
+                       {
+                               putchar('\t');
+                               putchar('\t');
+                       }
+                       else
+                               putchar(' ');
+                       printf("%s", *av);
+                       ll += strlen(*av++) + 1;
+               }
+               putchar('\n');
+       }
+       if (tTd(0, 10))
+       {
+               int ll;
+               extern char *OsCompileOptions[];
+
+               printf("    OS Defines:", Version);
+               av = OsCompileOptions;
+               ll = 7;
+               while (*av != NULL)
+               {
+                       if (ll + strlen(*av) > 63)
+                       {
+                               putchar('\n');
+                               ll = 0;
+                       }
+                       if (ll == 0)
+                       {
+                               putchar('\t');
+                               putchar('\t');
+                       }
+                       else
+                               putchar(' ');
+                       printf("%s", *av);
+                       ll += strlen(*av++) + 1;
+               }
+               putchar('\n');
+#ifdef _PATH_UNIX
+               printf("Kernel symbols:\t%s\n", _PATH_UNIX);
+#endif
+               printf("   Config file:\t%s\n", getcfname());
+               printf("      Pid file:\t%s\n", PidFile);
+       }
+
        InChannel = stdin;
        OutChannel = stdout;
 
        InChannel = stdin;
        OutChannel = stdout;
 
@@ -267,14 +328,15 @@ main(argc, argv, envp)
        **  the top of memory.
        */
 
        **  the top of memory.
        */
 
-       for (i = j = 0; j < MAXUSERENVIRON && (p = envp[i]) != NULL; i++)
-       {
-               if (strncmp(p, "IFS=", 4) == 0 || strncmp(p, "LD_", 3) == 0)
-                       continue;
-               UserEnviron[j++] = newstr(p);
-       }
-       UserEnviron[j] = NULL;
-       environ = UserEnviron;
+       for (i = 0; envp[i] != NULL; i++)
+               continue;
+       environ = (char **) xalloc(sizeof (char *) * (i + 1));
+       for (i = 0; envp[i] != NULL; i++)
+               environ[i] = newstr(envp[i]);
+       environ[i] = NULL;
+
+       /* and prime the child environment */
+       setuserenv("AGENT", "sendmail");
 
        /*
        **  Save start and extent of argv for setproctitle.
 
        /*
        **  Save start and extent of argv for setproctitle.
@@ -333,7 +395,6 @@ main(argc, argv, envp)
                        if (p[1] != '\0')
                        {
                                define('m', newstr(&p[1]), CurEnv);
                        if (p[1] != '\0')
                        {
                                define('m', newstr(&p[1]), CurEnv);
-                               setclass('m', &p[1]);
                        }
                        while (p != NULL && strchr(&p[1], '.') != NULL)
                        {
                        }
                        while (p != NULL && strchr(&p[1], '.') != NULL)
                        {
@@ -385,6 +446,9 @@ main(argc, argv, envp)
                }
        }
 
                }
        }
 
+       /* probe interfaces and locate any additional names */
+       load_if_names();
+
        /* current time */
        define('b', arpadate((char *) NULL), CurEnv);
 
        /* current time */
        define('b', arpadate((char *) NULL), CurEnv);
 
@@ -613,6 +677,12 @@ main(argc, argv, envp)
                  case 'x':     /* random flag that OSF/1 & AIX mailx passes */
                        break;
 # endif
                  case 'x':     /* random flag that OSF/1 & AIX mailx passes */
                        break;
 # endif
+# if defined(sony_news)
+                 case 'E':
+                 case 'J':     /* ignore flags for Japanese code conversion
+                                  impremented on Sony NEWS */
+                       break;
+# endif
 
                  default:
                        ExitStat = EX_USAGE;
 
                  default:
                        ExitStat = EX_USAGE;
@@ -628,23 +698,29 @@ main(argc, argv, envp)
        **      Extract special fields for local use.
        */
 
        **      Extract special fields for local use.
        */
 
-#ifdef XDEBUG
+#if XDEBUG
        checkfd012("before readcf");
 #endif
        checkfd012("before readcf");
 #endif
+       vendor_pre_defaults(CurEnv);
        readcf(getcfname(), safecf, CurEnv);
        readcf(getcfname(), safecf, CurEnv);
+       vendor_post_defaults(CurEnv);
+
+       /* set up the $=m class now, after .cf has a chance to redefine $m */
+       expand("\201m", jbuf, sizeof jbuf, CurEnv);
+       setclass('m', jbuf);
 
        if (tTd(0, 1))
        {
 
        if (tTd(0, 1))
        {
-               printf("SYSTEM IDENTITY (after readcf):");
-               printf("\n\t    (short domain name) $w = ");
+               printf("\n============ SYSTEM IDENTITY (after readcf) ============");
+               printf("\n      (short domain name) $w = ");
                xputs(macvalue('w', CurEnv));
                xputs(macvalue('w', CurEnv));
-               printf("\n\t(canonical domain name) $j = ");
+               printf("\n  (canonical domain name) $j = ");
                xputs(macvalue('j', CurEnv));
                xputs(macvalue('j', CurEnv));
-               printf("\n\t       (subdomain name) $m = ");
+               printf("\n         (subdomain name) $m = ");
                xputs(macvalue('m', CurEnv));
                xputs(macvalue('m', CurEnv));
-               printf("\n\t            (node name) $k = ");
+               printf("\n              (node name) $k = ");
                xputs(macvalue('k', CurEnv));
                xputs(macvalue('k', CurEnv));
-               printf("\n");
+               printf("\n========================================================\n\n");
        }
 
        /*
        }
 
        /*
@@ -672,9 +748,7 @@ main(argc, argv, envp)
        if (warn_C_flag)
                auth_warning(CurEnv, "Processed by %s with -C %s",
                        RealUserName, ConfFile);
        if (warn_C_flag)
                auth_warning(CurEnv, "Processed by %s with -C %s",
                        RealUserName, ConfFile);
-       if (warn_f_flag != '\0' &&
-           ((st = stab(RealUserName, ST_CLASS, ST_FIND)) == NULL ||
-            !bitnset('t', st->s_class)))
+       if (warn_f_flag != '\0' && !wordinclass(RealUserName, 't'))
                auth_warning(CurEnv, "%s set sender to %s using -%c",
                        RealUserName, from, warn_f_flag);
        if (Warn_Q_option)
                auth_warning(CurEnv, "%s set sender to %s using -%c",
                        RealUserName, from, warn_f_flag);
        if (Warn_Q_option)
@@ -688,23 +762,8 @@ main(argc, argv, envp)
        if (TimeZoneSpec == NULL)
                unsetenv("TZ");
        else if (TimeZoneSpec[0] != '\0')
        if (TimeZoneSpec == NULL)
                unsetenv("TZ");
        else if (TimeZoneSpec[0] != '\0')
-       {
-               char **evp = UserEnviron;
-               char tzbuf[100];
-
-               strcpy(tzbuf, "TZ=");
-               strcpy(&tzbuf[3], TimeZoneSpec);
-
-               while (*evp != NULL && strncmp(*evp, "TZ=", 3) != 0)
-                       evp++;
-               if (*evp == NULL)
-               {
-                       *evp++ = newstr(tzbuf);
-                       *evp = NULL;
-               }
-               else
-                       *evp++ = newstr(tzbuf);
-       }
+               setuserenv("TZ", TimeZoneSpec);
+       tzset();
 
        if (ConfigLevel > MAXCONFIGLEVEL)
        {
 
        if (ConfigLevel > MAXCONFIGLEVEL)
        {
@@ -720,6 +779,7 @@ main(argc, argv, envp)
          case MD_DAEMON:
                /* remove things that don't make sense in daemon mode */
                FullName = NULL;
          case MD_DAEMON:
                /* remove things that don't make sense in daemon mode */
                FullName = NULL;
+               GrabTo = FALSE;
 
                /* arrange to restart on hangup signal */
                setsignal(SIGHUP, sighup);
 
                /* arrange to restart on hangup signal */
                setsignal(SIGHUP, sighup);
@@ -775,13 +835,19 @@ main(argc, argv, envp)
        if (st == NULL)
                syserr("No prog mailer defined");
        else
        if (st == NULL)
                syserr("No prog mailer defined");
        else
+       {
                ProgMailer = st->s_mailer;
                ProgMailer = st->s_mailer;
+               clrbitn(M_MUSER, ProgMailer->m_flags);
+       }
 
        st = stab("*file*", ST_MAILER, ST_FIND);
        if (st == NULL)
                syserr("No *file* mailer defined");
        else
 
        st = stab("*file*", ST_MAILER, ST_FIND);
        if (st == NULL)
                syserr("No *file* mailer defined");
        else
+       {
                FileMailer = st->s_mailer;
                FileMailer = st->s_mailer;
+               clrbitn(M_MUSER, FileMailer->m_flags);
+       }
 
        st = stab("*include*", ST_MAILER, ST_FIND);
        if (st == NULL)
 
        st = stab("*include*", ST_MAILER, ST_FIND);
        if (st == NULL)
@@ -789,9 +855,9 @@ main(argc, argv, envp)
        else
                InclMailer = st->s_mailer;
 
        else
                InclMailer = st->s_mailer;
 
-       /* heuristic tweaking of local mailer for back compat */
        if (ConfigLevel < 6)
        {
        if (ConfigLevel < 6)
        {
+               /* heuristic tweaking of local mailer for back compat */
                if (LocalMailer != NULL)
                {
                        setbitn(M_ALIASABLE, LocalMailer->m_flags);
                if (LocalMailer != NULL)
                {
                        setbitn(M_ALIASABLE, LocalMailer->m_flags);
@@ -806,14 +872,23 @@ main(argc, argv, envp)
                        setbitn(M_RUNASRCPT, ProgMailer->m_flags);
                if (FileMailer != NULL)
                        setbitn(M_RUNASRCPT, FileMailer->m_flags);
                        setbitn(M_RUNASRCPT, ProgMailer->m_flags);
                if (FileMailer != NULL)
                        setbitn(M_RUNASRCPT, FileMailer->m_flags);
+
+               /* propogate some envariables into children */
+               setuserenv("ISP", NULL);
+               setuserenv("SYSTYPE", NULL);
        }
 
        }
 
-       /* initialize standard MIME classes */
-       setclass('n', "message/rfc822");
-       setclass('n', "message/partial");
-       setclass('n', "message/external-body");
+       /* MIME Content-Types that cannot be transfer encoded */
        setclass('n', "multipart/signed");
 
        setclass('n', "multipart/signed");
 
+       /* MIME message/* subtypes that can be treated as messages */
+       setclass('m', "rfc822");
+
+       /* MIME Content-Transfer-Encodings that can be encoded */
+       setclass('e', "7bit");
+       setclass('e', "8bit");
+       setclass('e', "binary");
+
        /* operate in queue directory */
        if (OpMode != MD_TEST && chdir(QueueDir) < 0)
        {
        /* operate in queue directory */
        if (OpMode != MD_TEST && chdir(QueueDir) < 0)
        {
@@ -845,7 +920,7 @@ main(argc, argv, envp)
                exit(ExitStat);
        }
 
                exit(ExitStat);
        }
 
-#ifdef XDEBUG
+#if XDEBUG
        checkfd012("before main() initmaps");
 #endif
 
        checkfd012("before main() initmaps");
 #endif
 
@@ -874,6 +949,7 @@ main(argc, argv, envp)
                exit(EX_OK);
 
          case MD_DAEMON:
                exit(EX_OK);
 
          case MD_DAEMON:
+         case MD_SMTP:
                /* don't open alias database -- done in srvrsmtp */
                break;
 
                /* don't open alias database -- done in srvrsmtp */
                break;
 
@@ -920,145 +996,19 @@ main(argc, argv, envp)
                }
                for (;;)
                {
                }
                for (;;)
                {
-                       register char **pvp;
-                       char *q;
-                       auto char *delimptr;
-                       extern bool invalidaddr();
-                       extern char *crackaddr();
+                       extern void testmodeline __P((char *, ENVELOPE *));
 
                        if (Verbose)
                                printf("> ");
                        (void) fflush(stdout);
                        if (fgets(buf, sizeof buf, stdin) == NULL)
                                finis();
 
                        if (Verbose)
                                printf("> ");
                        (void) fflush(stdout);
                        if (fgets(buf, sizeof buf, stdin) == NULL)
                                finis();
+                       p = strchr(buf, '\n');
+                       if (p != NULL)
+                               *p = '\0';
                        if (!Verbose)
                        if (!Verbose)
-                               printf("> %s", buf);
-                       switch (buf[0])
-                       {
-                         case '#':
-                               continue;
-
-                         case '?':             /* try crackaddr */
-                               q = crackaddr(&buf[1]);
-                               xputs(q);
-                               printf("\n");
-                               continue;
-
-                         case '.':             /* config-style settings */
-                               switch (buf[1])
-                               {
-                                 case 'D':
-                                       define(buf[2], newstr(&buf[3]), CurEnv);
-                                       break;
-
-                                 case 'C':
-                                       setclass(buf[2], &buf[3]);
-                                       break;
-
-                                 case 'S':             /* dump rule set */
-                                       {
-                                               int rs;
-                                               struct rewrite *rw;
-                                               char *cp;
-                                               STAB *s;
-
-                                               if ((cp = strchr(buf, '\n')) != NULL)
-                                                       *cp = '\0';
-                                               if (cp == buf+2)
-                                                       continue;
-                                               s = stab(buf+2, ST_RULESET, ST_FIND);
-                                               if (s == NULL)
-                                               {
-                                                       if (!isdigit(buf[2]))
-                                                               continue;
-                                                       rs = atoi(buf+2);
-                                               }
-                                               else
-                                                       rs = s->s_ruleset;
-                                               if (rs < 0 || rs > MAXRWSETS)
-                                                       continue;
-                                               if ((rw = RewriteRules[rs]) == NULL)
-                                                       continue;
-                                               do
-                                               {
-                                                       char **s;
-                                                       putchar('R');
-                                                       s = rw->r_lhs;
-                                                       while (*s != NULL)
-                                                       {
-                                                               xputs(*s++);
-                                                               putchar(' ');
-                                                       }
-                                                       putchar('\t');
-                                                       putchar('\t');
-                                                       s = rw->r_rhs;
-                                                       while (*s != NULL)
-                                                       {
-                                                               xputs(*s++);
-                                                               putchar(' ');
-                                                       }
-                                                       putchar('\n');
-                                               } while (rw = rw->r_next);
-                                       }
-                                       break;
-
-                                 default:
-                                       printf("Unknown config command %s", buf);
-                                       break;
-                               }
-                               continue;
-
-                         case '-':             /* set command-line-like opts */
-                               switch (buf[1])
-                               {
-                                 case 'd':
-                                       if (buf[2] == '\n')
-                                               tTflag("");
-                                       else
-                                               tTflag(&buf[2]);
-                                       break;
-
-                                 default:
-                                       printf("Unknown \"-\" command %s", buf);
-                                       break;
-                               }
-                               continue;
-                       }
-
-                       for (p = buf; isascii(*p) && isspace(*p); p++)
-                               continue;
-                       q = p;
-                       while (*p != '\0' && !(isascii(*p) && isspace(*p)))
-                               p++;
-                       if (*p == '\0')
-                       {
-                               printf("No address!\n");
-                               continue;
-                       }
-                       *p = '\0';
-                       if (invalidaddr(p + 1, NULL))
-                               continue;
-                       do
-                       {
-                               char pvpbuf[PSBUFSIZE];
-
-                               pvp = prescan(++p, ',', pvpbuf, sizeof pvpbuf,
-                                             &delimptr);
-                               if (pvp == NULL)
-                                       continue;
-                               p = q;
-                               while (*p != '\0')
-                               {
-                                       int stat;
-
-                                       stat = rewrite(pvp, atoi(p), 0, CurEnv);
-                                       if (stat != EX_OK)
-                                               printf("== Ruleset %s status %d\n",
-                                                       p, stat);
-                                       while (*p != '\0' && *p++ != ',')
-                                               continue;
-                               }
-                       } while (*(p = delimptr) != '\0');
+                               printf("> %s\n", buf);
+                       testmodeline(buf, CurEnv);
                }
        }
 
                }
        }
 
@@ -1087,7 +1037,7 @@ main(argc, argv, envp)
        {
                char dtype[200];
 
        {
                char dtype[200];
 
-               if (!tTd(0, 1))
+               if (!tTd(99, 100))
                {
                        /* put us in background */
                        i = fork();
                {
                        /* put us in background */
                        i = fork();
@@ -1159,6 +1109,7 @@ main(argc, argv, envp)
        {
                CurEnv->e_sendmode = SM_VERIFY;
                CurEnv->e_errormode = EM_QUIET;
        {
                CurEnv->e_sendmode = SM_VERIFY;
                CurEnv->e_errormode = EM_QUIET;
+               PostMasterCopy = NULL;
        }
        else
        {
        }
        else
        {
@@ -1277,7 +1228,7 @@ finis()
        if (LogLevel > 78)
                syslog(LOG_DEBUG, "finis, pid=%d", getpid());
 # endif /* LOG */
        if (LogLevel > 78)
                syslog(LOG_DEBUG, "finis, pid=%d", getpid());
 # endif /* LOG */
-       if (ExitStat == EX_TEMPFAIL)
+       if (ExitStat == EX_TEMPFAIL || CurEnv->e_errormode == EM_BERKNET)
                ExitStat = EX_OK;
 
        /* reset uid for process accounting */
                ExitStat = EX_OK;
 
        /* reset uid for process accounting */
@@ -1355,6 +1306,7 @@ struct metamac    MetaMacros[] =
        '\0'
 };
 
        '\0'
 };
 
+void
 initmacros(e)
        register ENVELOPE *e;
 {
 initmacros(e)
        register ENVELOPE *e;
 {
@@ -1403,6 +1355,7 @@ initmacros(e)
 **             the controlling tty.
 */
 
 **             the controlling tty.
 */
 
+void
 disconnect(droplev, e)
        int droplev;
        register ENVELOPE *e;
 disconnect(droplev, e)
        int droplev;
        register ENVELOPE *e;
@@ -1412,7 +1365,7 @@ disconnect(droplev, e)
        if (tTd(52, 1))
                printf("disconnect: In %d Out %d, e=%x\n",
                        fileno(InChannel), fileno(OutChannel), e);
        if (tTd(52, 1))
                printf("disconnect: In %d Out %d, e=%x\n",
                        fileno(InChannel), fileno(OutChannel), e);
-       if (tTd(52, 5))
+       if (tTd(52, 100))
        {
                printf("don't\n");
                return;
        {
                printf("don't\n");
                return;
@@ -1462,7 +1415,7 @@ disconnect(droplev, e)
                errno = 0;
        }
 
                errno = 0;
        }
 
-#ifdef XDEBUG
+#if XDEBUG
        checkfd012("disconnect");
 #endif
 
        checkfd012("disconnect");
 #endif
 
@@ -1490,7 +1443,11 @@ obsolete(argv)
                /* skip over options that do have a value */
                op = strchr(OPTIONS, ap[1]);
                if (op != NULL && *++op == ':' && ap[2] == '\0' &&
                /* skip over options that do have a value */
                op = strchr(OPTIONS, ap[1]);
                if (op != NULL && *++op == ':' && ap[2] == '\0' &&
-                   ap[1] != 'd' && argv[1] != NULL && argv[1][0] != '-')
+                   ap[1] != 'd' &&
+#if defined(sony_news)
+                   ap[1] != 'E' && ap[1] != 'J' &&
+#endif
+                   argv[1] != NULL && argv[1][0] != '-')
                {
                        argv++;
                        continue;
                {
                        argv++;
                        continue;
@@ -1513,6 +1470,16 @@ obsolete(argv)
                /* if -d doesn't have an argument, use 0-99.1 */
                if (ap[1] == 'd' && ap[2] == '\0')
                        *argv = "-d0-99.1";
                /* if -d doesn't have an argument, use 0-99.1 */
                if (ap[1] == 'd' && ap[2] == '\0')
                        *argv = "-d0-99.1";
+
+# if defined(sony_news)
+               /* if -E doesn't have an argument, use -EC */
+               if (ap[1] == 'E' && ap[2] == '\0')
+                       *argv = "-EC";
+
+               /* if -J doesn't have an argument, use -JJ */
+               if (ap[1] == 'J' && ap[2] == '\0')
+                       *argv = "-JJ";
+# endif
        }
 }
 \f/*
        }
 }
 \f/*
@@ -1555,9 +1522,66 @@ auth_warning(e, msg, va_alist)
                vsprintf(p, msg, ap);
                VA_END;
                addheader("X-Authentication-Warning", buf, &e->e_header);
                vsprintf(p, msg, ap);
                VA_END;
                addheader("X-Authentication-Warning", buf, &e->e_header);
+#ifdef LOG
+               if (LogLevel > 3)
+                       syslog(LOG_INFO, "%s: Authentication-Warning: %s",
+                               e->e_id == NULL ? "[NOQUEUE]" : e->e_id, buf);
+#endif
        }
 }
 \f/*
        }
 }
 \f/*
+**  SETUSERENV -- set an environment in the propogated environment
+**
+**     Parameters:
+**             envar -- the name of the environment variable.
+**             value -- the value to which it should be set.  If
+**                     null, this is extracted from the incoming
+**                     environment.  If that is not set, the call
+**                     to setuserenv is ignored.
+**
+**     Returns:
+**             none.
+*/
+
+void
+setuserenv(envar, value)
+       const char *envar;
+       const char *value;
+{
+       int i;
+       char **evp = UserEnviron;
+       char *p;
+
+       if (value == NULL)
+       {
+               value = getenv(envar);
+               if (value == NULL)
+                       return;
+       }
+
+       i = strlen(envar);
+       p = (char *) xalloc(strlen(value) + i + 2);
+       strcpy(p, envar);
+       p[i++] = '=';
+       strcpy(&p[i], value);
+
+       while (*evp != NULL && strncmp(*evp, p, i) != 0)
+               evp++;
+       if (*evp != NULL)
+       {
+               *evp++ = p;
+       }
+       else if (evp < &UserEnviron[MAXUSERENVIRON])
+       {
+               *evp++ = p;
+               *evp = NULL;
+       }
+
+       /* make sure it is in our environment as well */
+       if (putenv(p) < 0)
+               syserr("setuserenv: putenv(%s) failed", p);
+}
+\f/*
 **  DUMPSTATE -- dump state
 **
 **     For debugging.
 **  DUMPSTATE -- dump state
 **
 **     For debugging.
@@ -1578,6 +1602,7 @@ dumpstate(when)
                if (!wordinclass(j, 'w'))
                        syslog(LOG_DEBUG, "*** $j not in $=w ***");
        }
                if (!wordinclass(j, 'w'))
                        syslog(LOG_DEBUG, "*** $j not in $=w ***");
        }
+       syslog(LOG_DEBUG, "CurChildren = %d", CurChildren);
        syslog(LOG_DEBUG, "--- open file descriptors: ---");
        printopenfds(TRUE);
        syslog(LOG_DEBUG, "--- connection cache: ---");
        syslog(LOG_DEBUG, "--- open file descriptors: ---");
        printopenfds(TRUE);
        syslog(LOG_DEBUG, "--- connection cache: ---");
@@ -1614,10 +1639,245 @@ sighup()
        if (LogLevel > 3)
                syslog(LOG_INFO, "restarting %s on signal", SaveArgv[0]);
 #endif
        if (LogLevel > 3)
                syslog(LOG_INFO, "restarting %s on signal", SaveArgv[0]);
 #endif
-       execv(SaveArgv[0], SaveArgv);
+       releasesignal(SIGHUP);
+       execv(SaveArgv[0], (ARGV_T) SaveArgv);
 #ifdef LOG
        if (LogLevel > 0)
                syslog(LOG_ALERT, "could not exec %s: %m", SaveArgv[0]);
 #endif
        exit(EX_OSFILE);
 }
 #ifdef LOG
        if (LogLevel > 0)
                syslog(LOG_ALERT, "could not exec %s: %m", SaveArgv[0]);
 #endif
        exit(EX_OSFILE);
 }
+\f/*
+**  TESTMODELINE -- process a test mode input line
+**
+**     Parameters:
+**             line -- the input line.
+**             e -- the current environment.
+*/
+
+void
+testmodeline(line, e)
+       char *line;
+       ENVELOPE *e;
+{
+       register char *p;
+       char *q;
+       auto char *delimptr;
+       int mid;
+       ADDRESS a;
+       static int tryflags = RF_COPYNONE;
+       extern bool invalidaddr();
+       extern char *crackaddr();
+
+       switch (line[0])
+       {
+         case '#':
+               return;
+
+         case '.':             /* config-style settings */
+               switch (line[1])
+               {
+                 case 'D':
+                       mid = macid(&line[2], &delimptr);
+                       if (mid != '\0')
+                               define(mid, newstr(delimptr), e);
+                       break;
+
+                 case 'C':
+                       setclass(line[2], &line[3]);
+                       break;
+
+                 case 'S':             /* dump rule set */
+                       {
+                               int rs;
+                               struct rewrite *rw;
+                               STAB *s;
+
+                               if (line[2] == '\0')
+                                       return;
+                               s = stab(&line[2], ST_RULESET, ST_FIND);
+                               if (s == NULL)
+                               {
+                                       if (!isdigit(line[2]))
+                                               return;
+                                       rs = atoi(line+2);
+                               }
+                               else
+                                       rs = s->s_ruleset;
+                               if (rs < 0 || rs > MAXRWSETS)
+                                       return;
+                               if ((rw = RewriteRules[rs]) == NULL)
+                                       return;
+                               do
+                               {
+                                       char **s;
+                                       putchar('R');
+                                       s = rw->r_lhs;
+                                       while (*s != NULL)
+                                       {
+                                               xputs(*s++);
+                                               putchar(' ');
+                                       }
+                                       putchar('\t');
+                                       putchar('\t');
+                                       s = rw->r_rhs;
+                                       while (*s != NULL)
+                                       {
+                                               xputs(*s++);
+                                               putchar(' ');
+                                       }
+                                       putchar('\n');
+                               } while (rw = rw->r_next);
+                       }
+                       break;
+
+                 default:
+                       printf("Unknown config command %s", line);
+                       break;
+               }
+               return;
+
+         case '-':             /* set command-line-like opts */
+               switch (line[1])
+               {
+                 case 'd':
+                       tTflag(&line[2]);
+                       break;
+
+                 default:
+                       printf("Unknown \"-\" command %s", line);
+                       break;
+               }
+               return;
+
+         case '$':
+               mid = macid(&line[1], NULL);
+               if (mid == '\0')
+                       return;
+               p = macvalue(mid, e);
+               if (p == NULL)
+                       printf("Undefined\n");
+               else
+               {
+                       xputs(p);
+                       printf("\n");
+               }
+               return;
+
+         case '/':             /* miscellaneous commands */
+               p = &line[strlen(line)];
+               while (--p >= line && isascii(*p) && isspace(*p))
+                       *p = '\0';
+               p = strpbrk(line, " \t");
+               if (p != NULL)
+               {
+                       while (isascii(*p) && isspace(*p))
+                               *p++ = '\0';
+               }
+               else
+                       p = "";
+               if (strcasecmp(&line[1], "mx") == 0)
+               {
+#if NAMED_BIND
+                       /* look up MX records */
+                       int nmx;
+                       int i;
+                       auto int rcode;
+                       char *mxhosts[MAXMXHOSTS + 1];
+
+                       nmx = getmxrr(p, mxhosts, FALSE, &rcode);
+                       printf("getmxrr(%s) returns %d value(s):\n", p, nmx);
+                       for (i = 0; i < nmx; i++)
+                               printf("\t%s\n", mxhosts[i]);
+#else
+                       printf("No MX code compiled in\n");
+#endif
+               }
+               else if (strcasecmp(&line[1], "try") == 0)
+               {
+                       q = crackaddr(p);
+                       printf("Cracked address = ");
+                       xputs(q);
+                       printf("\nParsing %s %s address\n",
+                               bitset(RF_HEADERADDR, tryflags) ? "header" : "envelope",
+                               bitset(RF_SENDERADDR, tryflags) ? "sender" : "recipient");
+                       if (parseaddr(p, &a, tryflags, '\0', NULL, e) == NULL)
+                               printf("Cannot parse\n");
+                       else if (a.q_host != NULL && a.q_host[0] != '\0')
+                               printf("mailer %s, host %s, user %s\n",
+                                       a.q_mailer->m_name, a.q_host, a.q_user);
+                       else
+                               printf("mailer %s, user %s\n",
+                                       a.q_mailer->m_name, a.q_user);
+               }
+               else if (strcasecmp(&line[1], "tryflags") == 0)
+               {
+                       while (*p != '\n')
+                       {
+                               switch (*p)
+                               {
+                                 case 'H':
+                                 case 'h':
+                                       tryflags |= RF_HEADERADDR;
+                                       break;
+
+                                 case 'E':
+                                 case 'e':
+                                       tryflags &= ~RF_HEADERADDR;
+                                       break;
+
+                                 case 'S':
+                                 case 's':
+                                       tryflags |= RF_SENDERADDR;
+                                       break;
+
+                                 case 'R':
+                                 case 'r':
+                                       tryflags &= ~RF_SENDERADDR;
+                                       break;
+                               }
+                       }
+               }
+               else
+               {
+                       printf("Unknown test command %s\n", line);
+               }
+               return;
+       }
+
+       for (p = line; isascii(*p) && isspace(*p); p++)
+               continue;
+       q = p;
+       while (*p != '\0' && !(isascii(*p) && isspace(*p)))
+               p++;
+       if (*p == '\0')
+       {
+               printf("No address!\n");
+               return;
+       }
+       *p = '\0';
+       if (invalidaddr(p + 1, NULL))
+               return;
+       do
+       {
+               register char **pvp;
+               char pvpbuf[PSBUFSIZE];
+
+               pvp = prescan(++p, ',', pvpbuf, sizeof pvpbuf,
+                             &delimptr, NULL);
+               if (pvp == NULL)
+                       continue;
+               p = q;
+               while (*p != '\0')
+               {
+                       int stat;
+
+                       stat = rewrite(pvp, atoi(p), 0, e);
+                       if (stat != EX_OK)
+                               printf("== Ruleset %s status %d\n",
+                                       p, stat);
+                       while (*p != '\0' && *p++ != ',')
+                               continue;
+               }
+       } while (*(p = delimptr) != '\0');
+}