]> mj.ucw.cz Git - nwho.git/blobdiff - nwhod.c
Split ywho and nwho.
[nwho.git] / nwhod.c
diff --git a/nwhod.c b/nwhod.c
index e0f158e8d91d98e20f3932039571a3b96a038875..23accf6d3b61a78754708351ebd37363f8a04563 100644 (file)
--- a/nwhod.c
+++ b/nwhod.c
@@ -1,7 +1,7 @@
 /*
- *     The Remote User Information Daemon 1.8
+ *     The Remote User Information Daemon 1.9
  *
- *     (c) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
+ *     (c) 1997--2001 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU General Public License. See file COPYING in any of the GNU packages.
 #include <arpa/inet.h>
 #include <syslog.h>
 #include <sys/stat.h>
+#include <time.h>
 #include <utmp.h>
 #include <signal.h>
 #include <dirent.h>
+#include <asm/types.h>
+#include <errno.h>
 
 #include "net.h"
 
@@ -110,19 +113,7 @@ scan_utmp(struct rywho_pkt *p, time_t now)
        name[9] = 0;
        strcpy(h->name, name);
        h->login_time = htonl(now - u->ut_time);
-       if (u->ut_id[0])
-         {
-           h->con[0] = u->ut_id[0];
-           h->con[1] = u->ut_id[1];
-           h->con[2] = 0;
-         }
-       else
-         {
-           char *z = u->ut_line;
-           if (!strncmp(z, "tty", 3))
-             z += 3;
-           sprintf(h->con, "%.3s", z);
-         }
+       sprintf(h->con, "%.7s", u->ut_line);
        sprintf(device, "/dev/%s", u->ut_line);
        if (stat(device, &st) < 0)
          {
@@ -176,6 +167,7 @@ static void
 make_pkt(struct rywho_pkt *pkt)
 {
   bzero(pkt, sizeof(pkt));
+  pkt->magic = htonl(NWHO_MAGIC);
   pkt->local_time = htonl(now);
   scan_utmp(pkt, now);
   scan_load(pkt);
@@ -255,6 +247,12 @@ receive(void)
       return;
     }
 
+  if (pkt.magic != htonl(NWHO_MAGIC))
+    {
+      syslog(LOG_WARNING, "Received ancient nwho packet from %s", inet_ntoa(sa.sin_addr));
+      return;
+    }
+
   for(e=first_host; e; e=e->next)
     if (e->addr == sa.sin_addr.s_addr)
       break;
@@ -329,15 +327,17 @@ tick(int unused)
 {
 }
 
-static struct sigaction sigact = { tick, 0, 0, NULL };
-
 static void
 server(void)
 {
+  static struct sigaction sigact;
+
   net_init(NULL);
-  if (chdir(YWHO_SPOOL_DIR) < 0)
-    die("chdir(" YWHO_SPOOL_DIR "): %m");
+  if (chdir(NWHO_SPOOL_DIR) < 0)
+    die("chdir(" NWHO_SPOOL_DIR "): %m");
   cleanup();
+  bzero(&sigact, sizeof(sigact));
+  sigact.sa_handler = tick;
   sigaction(SIGALRM, &sigact, NULL);
   now = time(NULL);
   for(;;)