(Log entry for previous version is bogus.) Read netgroups database.
[become] / src / daemon.c
index eb36b39..56a9dab 100644 (file)
@@ -1,13 +1,13 @@
 /* -*-c-*-
  *
- * $Id: daemon.c,v 1.1 1997/07/21 13:47:50 mdw Exp $
+ * $Id: daemon.c,v 1.4 1997/08/07 10:00:37 mdw Exp $
  *
  * Running a `become' daemon
  *
  * (c) 1997 EBI
  */
 
-/*----- Licencing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of `become'
  *
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with `become'; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with `become'; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
 /*----- Revision history --------------------------------------------------*
  *
  * $Log: daemon.c,v $
- * Revision 1.1  1997/07/21 13:47:50  mdw
+ * Revision 1.4  1997/08/07 10:00:37  mdw
+ * (Log entry for previous version is bogus.)  Read netgroups database.
+ * Give up privileges permanently on startup.
+ *
+ * Revision 1.2  1997/08/04 10:24:21  mdw
+ * Sources placed under CVS control.
+ *
+ * Revision 1.1  1997/07/21  13:47:50  mdw
  * Initial revision
  *
  */
@@ -68,6 +75,7 @@
 #include "idea.h"
 #include "lexer.h"
 #include "name.h"
+#include "netg.h"
 #include "parser.h"
 #include "rule.h"
 #include "tx.h"
@@ -76,7 +84,7 @@
 
 /*----- Arbitrary constants -----------------------------------------------*/
 
-#define daemon__awakeEvery (5 * 60)    /* Awaken this often to rescan */
+#define daemon__awakeEvery (30 * 60)   /* Awaken this often to rescan */
 
 /*----- Static variables --------------------------------------------------*/
 
@@ -152,6 +160,7 @@ static int daemon__readConfig(const char *cf)
   if (!daemon__readKey)
     daemon_readKey(file_KEY);
   daemon__rescan = 0;
+  T( trace(TRACE_DAEMON, "daemon: read config file"); )
   return (0);
 }
 
@@ -210,6 +219,8 @@ void daemon__read(int fd)
 
     if (recvfrom(fd, (char *)buff, sizeof(buff), 0,
                 (struct sockaddr *)&sin, &slen) < 0) {
+      T( trace(TRACE_DAEMON, "daemon: error reading packet: %s",
+              strerror(errno)); )
       syslog(LOG_INFO, "duff packet received: %e");
       return;
     }
@@ -226,12 +237,14 @@ void daemon__read(int fd)
            he ? he->h_name : inet_ntoa(sin.sin_addr),
            sizeof(sender));
     syslog(LOG_DEBUG, "packet received from %s", sender);
+    T( trace(TRACE_DAEMON, "daemon: received request from %s", sender); )
   }
 
   /* --- Unpack the block --- */
 
   if (crypt_unpackRequest(&rq, buff, daemon__key, sk, rpl) == 0) {
     burn(buff);
+    T( trace(TRACE_DAEMON, "daemon: received corrupt or invalid request"); )
     syslog(LOG_INFO, "packet from %s rejected", sender);
     return;
   }
@@ -254,6 +267,7 @@ void daemon__read(int fd)
   /* --- Send the reply off --- */
 
   sendto(fd, (char *)rpl, crp_size, 0, (struct sockaddr *)&sin, sizeof(sin));
+  T( trace(TRACE_DAEMON, "daemon: reply sent"); )
   burn(rpl);
 }
 
@@ -277,7 +291,7 @@ void daemon_init(const char *cf, int port)
    * user wants me to start on a funny port.
    */
 
-  seteuid(getuid());
+  setuid(getuid());
 
   /* --- Initialise bits of the program --- */
 
@@ -286,6 +300,7 @@ void daemon_init(const char *cf, int port)
   userdb_init();
   userdb_local();
   userdb_yp();
+  netg_init();
   name_init();
   rule_init();
   openlog(quis(), 0, LOG_DAEMON);
@@ -345,26 +360,38 @@ void daemon_init(const char *cf, int port)
       fprintf(fp, "%lu\n", (unsigned long)getpid());
       fclose(fp);
     }
+    T( trace(TRACE_DAEMON, "daemon: forked to pid %li", (long)getpid()); )
   }
 #endif
 
   /* --- Program in daemon death mode --- */
 
   if (setjmp(daemon__dieBuf)) {
-    syslog(LOG_NOTICE, "killed by signal type %i", daemon__signum);
-    remove(file_PID);
-    exit(0);
-  }
+#ifdef TRACING
+    if (daemon__signum == SIGQUIT && tracing() & TRACE_RULE) {
+      T( rule_dump(); )
+      signal(SIGQUIT, daemon__die);
+    } else
+#endif
+    {
+      T( trace(TRACE_DAEMON, "daemon: killed by signal %i",
+              daemon__signum); )
+      syslog(LOG_NOTICE, "killed by signal type %i", daemon__signum);
+      remove(file_PID);
+      exit(0);
+    }
+  } else {
 
-  /* --- Set signal handlers --- */
+    /* --- Set signal handlers --- */
 
-  signal(SIGHUP, daemon__restart);
-  signal(SIGQUIT, daemon__restart);
-  signal(SIGINT, daemon__die);
-  signal(SIGTERM, daemon__die);
-  signal(SIGSEGV, daemon__die);
-  signal(SIGFPE, daemon__die);
-  signal(SIGBUS, daemon__die);
+    signal(SIGHUP, daemon__restart);
+    signal(SIGQUIT, daemon__die);
+    signal(SIGINT, daemon__die);
+    signal(SIGTERM, daemon__die);
+    signal(SIGSEGV, daemon__die);
+    signal(SIGFPE, daemon__die);
+    signal(SIGBUS, daemon__die);
+  }
 
   /* --- Now wait for something exciting to happen --- *
    *
@@ -391,6 +418,7 @@ void daemon_init(const char *cf, int port)
 
       /* --- Now wait for something interesting --- */
 
+      T( trace(TRACE_DAEMON, "daemon: waiting for requests"); )
       i = select(FD_SETSIZE, &fds, 0, 0, 0);
 
       /* --- Now, see if I need to rescan the config --- */
@@ -401,6 +429,7 @@ void daemon_init(const char *cf, int port)
        userdb_reinit();
        userdb_local();
        userdb_yp();
+       netg_reinit();
        rule_reinit();
        name_reinit();
        if (daemon__readConfig(cf))