BSD 4_4_Lite1 release
[unix-history] / usr / src / usr.sbin / sendmail / src / main.c
index 7008fd2..e2af9df 100644 (file)
@@ -3,7 +3,33 @@
  * 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.
  *
- * %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
@@ -13,7 +39,7 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     8.52 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     8.55 (Berkeley) 4/15/94";
 #endif /* not lint */
 
 #define        _DEFINE
 #endif /* not lint */
 
 #define        _DEFINE
@@ -101,7 +127,6 @@ main(argc, argv, envp)
 {
        register char *p;
        char **av;
 {
        register char *p;
        char **av;
-       char *locname;
        extern int finis();
        extern char Version[];
        char *ep, *from;
        extern int finis();
        extern char Version[];
        char *ep, *from;
@@ -129,7 +154,7 @@ main(argc, argv, envp)
        extern char *getcfname();
        extern char *optarg;
        extern char **environ;
        extern char *getcfname();
        extern char *optarg;
        extern char **environ;
-       extern void dumpstate();
+       extern void sigusr1();
 
        /*
        **  Check to see if we reentered.
 
        /*
        **  Check to see if we reentered.
@@ -143,15 +168,13 @@ main(argc, argv, envp)
                abort();
        }
        reenter = TRUE;
                abort();
        }
        reenter = TRUE;
-       extern ADDRESS *recipient();
-       bool canrename;
 
        /* do machine-dependent initializations */
        init_md(argc, argv);
 
        /* arrange to dump state on signal */
 #ifdef SIGUSR1
 
        /* do machine-dependent initializations */
        init_md(argc, argv);
 
        /* arrange to dump state on signal */
 #ifdef SIGUSR1
-       setsignal(SIGUSR1, dumpstate);
+       setsignal(SIGUSR1, sigusr1);
 #endif
 
        /* in 4.4BSD, the table can be huge; impose a reasonable limit */
 #endif
 
        /* in 4.4BSD, the table can be huge; impose a reasonable limit */
@@ -164,7 +187,7 @@ main(argc, argv, envp)
        **      But also be sure that 0, 1, & 2 are open.
        */
 
        **      But also be sure that 0, 1, & 2 are open.
        */
 
-       i = open("/dev/null", O_RDWR);
+       i = open("/dev/null", O_RDWR, 0);
        if (fstat(STDIN_FILENO, &stb) < 0 && errno != EOPNOTSUPP)
                (void) dup2(i, STDIN_FILENO);
        if (fstat(STDOUT_FILENO, &stb) < 0 && errno != EOPNOTSUPP)
        if (fstat(STDIN_FILENO, &stb) < 0 && errno != EOPNOTSUPP)
                (void) dup2(i, STDIN_FILENO);
        if (fstat(STDOUT_FILENO, &stb) < 0 && errno != EOPNOTSUPP)
@@ -182,10 +205,12 @@ main(argc, argv, envp)
        }
        errno = 0;
 
        }
        errno = 0;
 
-#ifdef LOG_MAIL
+#ifdef LOG
+# ifdef LOG_MAIL
        openlog("sendmail", LOG_PID, LOG_MAIL);
        openlog("sendmail", LOG_PID, LOG_MAIL);
-#else 
+# else 
        openlog("sendmail", LOG_PID);
        openlog("sendmail", LOG_PID);
+# endif
 #endif 
 
        /* set up the blank envelope */
 #endif 
 
        /* set up the blank envelope */
@@ -193,8 +218,8 @@ main(argc, argv, envp)
        BlankEnvelope.e_putbody = putbody;
        BlankEnvelope.e_xfp = NULL;
        STRUCTCOPY(NullAddress, BlankEnvelope.e_from);
        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.
 
        /*
        **  Set default values for variables.
@@ -962,7 +987,9 @@ main(argc, argv, envp)
                if (tTd(0, 1))
                        strcat(dtype, "+debugging");
 
                if (tTd(0, 1))
                        strcat(dtype, "+debugging");
 
+#ifdef LOG
                syslog(LOG_INFO, "starting daemon (%s): %s", Version, dtype + 1);
                syslog(LOG_INFO, "starting daemon (%s): %s", Version, dtype + 1);
+#endif
 #ifdef XLA
                xla_create_file();
 #endif
 #ifdef XLA
                xla_create_file();
 #endif
@@ -1183,7 +1210,6 @@ 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,
@@ -1402,22 +1428,28 @@ auth_warning(e, msg, va_alist)
        }
 }
 \f/*
        }
 }
 \f/*
-**  DUMPSTATE -- dump state on user signal
+**  DUMPSTATE -- dump state
 **
 **     For debugging.
 */
 
 void
 **
 **     For debugging.
 */
 
 void
-dumpstate()
+dumpstate(when)
+       char *when;
 {
 #ifdef LOG
        register char *j = macvalue('j', CurEnv);
        register STAB *s;
 
 {
 #ifdef LOG
        register char *j = macvalue('j', CurEnv);
        register STAB *s;
 
-       syslog(LOG_DEBUG, "--- dumping state on user signal: $j = %s ---", j);
-       s = stab(j, ST_CLASS, ST_FIND);
-       if (s == NULL || !bitnset('w', s->s_class))
-               syslog(LOG_DEBUG, "*** $j not in $=w ***");
+       syslog(LOG_DEBUG, "--- dumping state on %s: $j = %s ---",
+               when,
+               j == NULL ? "<NULL>" : j);
+       if (j != NULL)
+       {
+               s = stab(j, ST_CLASS, ST_FIND);
+               if (s == NULL || !bitnset('w', s->s_class))
+                       syslog(LOG_DEBUG, "*** $j not in $=w ***");
+       }
        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: ---");
@@ -1438,3 +1470,10 @@ dumpstate()
        syslog(LOG_DEBUG, "--- end of state dump ---");
 #endif
 }
        syslog(LOG_DEBUG, "--- end of state dump ---");
 #endif
 }
+
+
+void
+sigusr1()
+{
+       dumpstate("user signal");
+}