Index: trunk/src/sh_socket.c
===================================================================
--- trunk/src/sh_socket.c	(revision 583)
+++ trunk/src/sh_socket.c	(revision 1)
@@ -24,17 +24,8 @@
  */
 
-#if defined(SH_WITH_SERVER) && defined(__linux__)
-#define _GNU_SOURCE
-#endif
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
-
-#if HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-#include <time.h>
 
 #include "samhain.h"
@@ -43,7 +34,4 @@
 #include "sh_unix.h"
 #include "sh_calls.h"
-#include "sh_guid.h"
-#include "sh_fifo.h"
-#include "sh_utils.h"
 
 #undef  FIL__
@@ -54,145 +42,4 @@
 #include <signal.h>
 
-typedef struct delta_tofetch {
-  char            uuid[SH_UUID_BUF];
-  time_t          last_time;
-  unsigned int    count;
-} SH_DELTA_DB;
-
-static SH_DELTA_DB * parse_entry(SH_DELTA_DB * db, const char * str)
-{
-  long last_time;
-  unsigned int count;
-  char buf[SH_UUID_BUF];
-  int res = sscanf(str, _("%u:%ld:%36s"), &count, &last_time, buf);
-  if (res == 3)
-    {
-      db->count = count;
-      db->last_time  = (time_t) last_time;
-      sl_strlcpy(db->uuid, buf, SH_UUID_BUF);
-      return db;
-    }
-  return NULL;
-}
-
-static char * unparse_entry(const SH_DELTA_DB * db, char * str, size_t len)
-{
-  int nbytes = sl_snprintf(str, len, _("%u:%ld:%s"), 
-			   db->count, (long) db->last_time, db->uuid);
-  if (nbytes < 0 || nbytes >= (int) len)
-    return NULL;
-  return str;
-}
-
-static SH_FIFO xfifo = SH_FIFO_INITIALIZER;
-
-int sh_socket_store_uuid(const char * cmd)
-{
-  char * p = sh_util_strdup(cmd);
-  char * q = strchr(cmd, ':');
-  char   entry[SH_BUFSIZE];
-  SH_DELTA_DB db;
-
-  if (!q) { SH_FREE(p); return -1; }
-
-  ++q;
-
-  if (0 != sh_uuid_check(q)) { SH_FREE(p); return -1; }
-
-  db.count = 0;
-  db.last_time = (time_t) 0;
-  sl_strlcpy(db.uuid, q, SH_UUID_BUF);
-  SH_FREE(p);
-
-  if (NULL != unparse_entry(&db, entry, sizeof(entry)))
-    {
-      sh_fifo_push(&xfifo, entry);
-      return 0;
-    }
-  return -1;
-}
-
-static unsigned int try_interval = 60;
-static unsigned int try_max = 2;
-
-int set_delta_retry_interval(const char * str)
-{
-  long val = strtol (str, (char **)NULL, 10);
-
-  if (val < 0 || val > INT_MAX)
-    return -1;
-  try_interval = (unsigned int) val;
-  return 0;
-}
-int set_delta_retry_count(const char * str)
-{
-  long val = strtol (str, (char **)NULL, 10);
-
-  if (val < 0 || val > INT_MAX)
-    return -1;
-  try_max = (unsigned int) val;
-  return 0;
-}
-
-char * sh_socket_get_uuid(int * errflag, unsigned int * count, time_t * last)
-{
-  char * entry = sh_fifo_pop(&xfifo);
-  char * uuid = NULL;
-
-  if (entry)
-    {
-      SH_DELTA_DB db;
-      time_t      now;
-      
-      if (NULL == parse_entry(&db, entry))
-	{
-	  SH_FREE(entry);
-	  sh_error_handle(SH_ERR_WARN, FIL__, __LINE__, 0, MSG_E_SUBGEN,
-			  _("Bad entry in fifo"), 
-			  _("sh_socket_get_uuid"));
-	  *errflag = -1;
-	  return NULL;
-	}
-
-      now = time(NULL);
-
-      if ( (db.count > 0) && ((unsigned long)(now - db.last_time) < try_interval) )
-	{
-	  sh_fifo_push_tail(&xfifo, entry);
-	  SH_FREE(entry);
-	  *errflag = -1;
-	  return NULL;
-	}
-
-      SH_FREE(entry);
-      uuid   = sh_util_strdup(db.uuid);
-      *count = db.count;
-      *last  = db.last_time;
-    }
-
-  *errflag = 0;
-  return uuid;
-}
-
-int sh_socket_return_uuid (const char * uuid, unsigned int count, time_t last)
-{
-  (void) last;
-
-  if (count < try_max)
-    {
-      char   entry[SH_BUFSIZE];
-      SH_DELTA_DB db;
-      time_t now = time(NULL);
-
-      db.count     = count + 1;
-      db.last_time = now;
-      sl_strlcpy(db.uuid, uuid, SH_UUID_BUF);
-
-      if (NULL != unparse_entry(&db, entry, sizeof(entry)))
-	return sh_fifo_push_tail(&xfifo, entry); /* >0 for success */
-    }
-  return -1;
-}
-
 void sh_socket_server_cmd(const char * srvcmd)
 {
@@ -203,6 +50,6 @@
       SL_RET0(_("sh_socket_server_cmd"));
     }
-
-  if (0 == strncmp(srvcmd, _("STOP"), 4))
+  if ((srvcmd[0] == 'S') || (srvcmd[1] == 'T') || 
+      (srvcmd[2] == 'O') || (srvcmd[3] == 'P'))
     {
       TPT((0, FIL__, __LINE__, _("msg=<stop command from server>\n")));
@@ -210,10 +57,10 @@
       raise(SIGQUIT);
 #else
-      sig_terminate       = 1;
-      ++sig_raised;
+      TPT((0, FIL__, __LINE__, _("msg=<sigquit not defined>\n")));
 #endif
     } 
-
-  else if (0 == strncmp(srvcmd, _("RELOAD"), 6))
+  else if ((srvcmd[0] == 'R') || (srvcmd[1] == 'E') || 
+	   (srvcmd[2] == 'L') || (srvcmd[3] == 'O') ||
+	   (srvcmd[4] == 'A') || (srvcmd[5] == 'D'))
     {
       TPT((0, FIL__, __LINE__, _("msg=<reload command from server>\n")));
@@ -221,44 +68,10 @@
       raise(SIGHUP);
 #else
-      sig_config_read_again = 1;
-      ++sig_raised;
-#endif
-    }
-
-  else if (0 == strncmp(srvcmd, _("DELTA:"), 6))
-    {
-      TPT((0, FIL__, __LINE__, _("msg=<delta load command from server>\n")));
-
-      if (sh_socket_store_uuid(srvcmd) == 0)
-	{
-	  ++sh_load_delta_flag;
-	  ++sig_raised;
-	}
-    }
-
-  else if (0 == strncmp(srvcmd, _("SCAN"), 4))
-    {
-      TPT((0, FIL__, __LINE__, _("msg=<scan command from server>\n")));
-      if (sh.flag.isdaemon == S_TRUE) 
-	{ 
-#ifdef SIGTTOU
-	  raise(SIGTTOU);
-#else
-	  sig_force_check = 1;
-	  ++sig_raised;
-#endif
-	} 
-      else 
-	{
-	  sig_force_check = 1;
-	  ++sig_raised;
-	}
-    }
-
-  /* Unknown command 
-   */
+      TPT((0, FIL__, __LINE__, _("msg=<sighup not defined>\n")));
+#endif
+    }
   else
     {
-      sh_error_handle(SH_ERR_WARN, FIL__, __LINE__, 0, MSG_E_SUBGEN,
+      sh_error_handle(SH_ERR_INFO, FIL__, __LINE__, 0, MSG_E_SUBGEN,
 		      srvcmd, 
 		      _("sh_socket_server_cmd"));
@@ -266,5 +79,7 @@
   SL_RET0(_("sh_socket_server_cmd"));
 }
-#endif  /* #if defined (SH_WITH_CLIENT) */
+/* #if defined (SH_WITH_CLIENT)
+ */
+#endif
 
 #if defined(SH_WITH_SERVER)
@@ -296,5 +111,6 @@
 int    pf_unix_fd  = -1;
 static char * sh_sockname = NULL;
-static char   sh_sockpass_real[SOCKPASS_MAX+1];
+/* static char   sh_sockpass[29]; */
+static char   sh_sockpass_real[15];
 
 struct socket_cmd {
@@ -325,8 +141,5 @@
 #include "sh_utils.h"
 
-/* The reload list stores information about
- * reloads confirmed by clients (startup and/or
- * runtime cinfiguration reloaded).
- */
+
 struct reload_cmd {
   char          clt[SH_MAXMSGLEN];
@@ -344,7 +157,4 @@
       if (0 == sl_strcmp(new->clt, clt))
 	{
-#ifdef SH_DEBUG_SOCKET
-	  fprintf(stderr, "add2reload: time reset for %s\n", clt);
-#endif
 	  sl_strlcpy (new->clt, clt, SH_MAXMSGLEN);
 	  new->cti = time(NULL);
@@ -355,7 +165,4 @@
 
   new = SH_ALLOC(sizeof(struct reload_cmd));
-#ifdef SH_DEBUG_SOCKET
-  fprintf(stderr, "add2reload: time set for %s\n", clt);
-#endif
   sl_strlcpy (new->clt, clt, SH_MAXMSGLEN);
   new->cti = time(NULL);
@@ -372,5 +179,5 @@
 static void sh_socket_add2list (struct socket_cmd * in);
 
-static void sh_socket_probe4reload (void)
+static void sh_socket_probe4reload ()
 {
   struct reload_cmd  * new;
@@ -390,6 +197,4 @@
       if (item->status_now != CLT_INACTIVE)
 	{
-	  int flag = 0;
-
 	  file = get_client_conf_file (item->hostname, &dummy);
 
@@ -401,6 +206,4 @@
 		  if (0 == sl_strcmp(new->clt, item->hostname))
 		    {
-		      flag = 1; /* Client is in list already */
-
 		      if (buf.st_mtime > new->cti)
 			{
@@ -414,39 +217,14 @@
 		  new = new->next;
 		}
-
-	      if (flag == 0)
-		{
-		  /* client is active, but start message has been missed; reload 
-		   */
-		  sl_strlcpy(cmd.cmd, _("RELOAD"),    SH_MAXMSGLEN);
-		  sl_strlcpy(cmd.clt, item->hostname, SH_MAXMSGLEN);
-		  sh_socket_add2list (&cmd);
-
-		  /* Add the client to the reload list and set
-		   * time to 0, since we don't know the startup time.
-		   */
-		  sh_socket_add2reload (item->hostname);
-		  new = reloadlist;
-		  while (new)
-		    {
-		      if (0 == sl_strcmp(new->clt, item->hostname))
-			{
-			  new->cti = 0;
-			  break;
-			}
-		      new = new->next;
-		    }
-		}
-	    } /* if stat(file).. */
-	} /* if !CLT_INACTIVE */
-    } /* loop over clients */
+	    }
+	}
+    }
   return;
 }
 
-char * sh_get_sockpass (void)
-{
-  size_t j = 0;
-
-  while (skey->sh_sockpass[2*j] != '\0' && j < sizeof(sh_sockpass_real))
+char * sh_get_sockpass ()
+{
+  int j = 0;
+  while (skey->sh_sockpass[2*j] != '\0')
     {
       sh_sockpass_real[j] = skey->sh_sockpass[2*j];
@@ -454,9 +232,8 @@
     }
   sh_sockpass_real[j] = '\0';
-
   return sh_sockpass_real;
 }
 
-void sh_set_sockpass (void)
+void sh_set_sockpass ()
 {
   int j;
@@ -467,5 +244,5 @@
 }
 
-int sh_socket_use (const char * c)
+int sh_socket_use (char * c)
 {
   return sh_util_flagval(c, &sh_socket_flaguse);
@@ -509,7 +286,8 @@
 
 #define NEED_PASSWORD_AUTH
-#endif
-
-int sh_socket_uid (const char * c)
+
+#endif
+
+int sh_socket_uid (char * c)
 {
   uid_t val = (uid_t) strtol (c, (char **)NULL, 10);
@@ -523,5 +301,5 @@
 }
 
-int sh_socket_password (const char * c)
+int sh_socket_password (char * c)
 {
 #if defined(NEED_PASSWORD_AUTH)
@@ -531,8 +309,8 @@
 
   i = sl_strlen(c);
-  if (i > SOCKPASS_MAX) {
+  if (i > 14) {
     return -1;
   }
-  for (j = 0; j < (2*SOCKPASS_MAX+1); ++j)
+  for (j = 0; j < 29; ++j)
     {
       skey->sh_sockpass[j] = '\0';
@@ -563,5 +341,4 @@
 #endif
   struct stat buf;
-  char errbuf[SH_ERRBUF_SIZE];
   
   SL_ENTER(_("sh_socket_open_int"));
@@ -575,5 +352,5 @@
     {
       size = sl_strlen(DEFAULT_PIDDIR) + 1 + sl_strlen(SH_INSTALL_NAME) + 6;
-      sh_sockname = SH_ALLOC(size); /* compile-time constant */
+      sh_sockname = SH_ALLOC(size);
       sl_strlcpy(sh_sockname, DEFAULT_PIDDIR, size);
       sl_strlcat(sh_sockname, "/", size);
@@ -582,15 +359,9 @@
     }
 
-  if (0 != sh_unix_check_piddir (sh_sockname))
-    {
-      SH_FREE(sh_sockname);
-      SL_RETURN((-1),_("sh_socket_open_int"));
-    }
-
   pf_unix_fd = socket (PF_UNIX, SOCK_STREAM, 0);
   if ((pf_unix_fd) < 0)
     {
       sh_error_handle ((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		       sh_error_message (errno, errbuf, sizeof(errbuf)), 
+		       sh_error_message (errno), 
 		       _("sh_socket_open_int: socket"));
       SL_RETURN( (-1), _("sh_socket_open_int"));
@@ -599,5 +370,5 @@
   if (sizeof(name.sun_path) < (1 + sl_strlen(sh_sockname)))
     {
-      sl_close_fd(FIL__, __LINE__, pf_unix_fd); pf_unix_fd = -1;
+      close(pf_unix_fd); pf_unix_fd = -1;
       sh_error_handle ((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
 		       _("PID dir path too long"), 
@@ -607,5 +378,5 @@
 
   name.sun_family = AF_FILE;
-  sl_strlcpy (name.sun_path, sh_sockname, sizeof(name.sun_path));
+  strcpy (name.sun_path, sh_sockname);
 
   size = (offsetof (struct sockaddr_un, sun_path)
@@ -621,5 +392,5 @@
       if (sh_socket_remove() < 0) 
 	{
-	  sl_close_fd(FIL__, __LINE__, pf_unix_fd); pf_unix_fd = -1;
+	  close(pf_unix_fd); pf_unix_fd = -1;
 	  sh_error_handle ((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
 			   _("Unlink of socket failed, maybe path not trusted"), 
@@ -631,7 +402,7 @@
   if (bind ((pf_unix_fd), (struct sockaddr *) &name, size) < 0)
     {
-      sl_close_fd(FIL__, __LINE__, pf_unix_fd); pf_unix_fd = -1;
+      close(pf_unix_fd); pf_unix_fd = -1;
       sh_error_handle ((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		       sh_error_message (errno, errbuf, sizeof(errbuf)), 
+		       sh_error_message (errno), 
 		       _("sh_socket_open_int: bind"));
       SL_RETURN( (-1), _("sh_socket_open_int"));
@@ -642,7 +413,7 @@
 		      &optval, sizeof(optval)))
     {
-      sl_close_fd(FIL__, __LINE__, pf_unix_fd); pf_unix_fd = -1;
+      close(pf_unix_fd); pf_unix_fd = -1;
       sh_error_handle ((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		       sh_error_message (errno, errbuf, sizeof(errbuf)), 
+		       sh_error_message (errno), 
 		       _("sh_socket_open_int: setsockopt"));
       SL_RETURN( (-1), _("sh_socket_open_int"));
@@ -653,7 +424,7 @@
   if (flags < 0)
     {
-      sl_close_fd(FIL__, __LINE__, pf_unix_fd); pf_unix_fd = -1;
+      close(pf_unix_fd); pf_unix_fd = -1;
       sh_error_handle ((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		       sh_error_message (errno, errbuf, sizeof(errbuf)), 
+		       sh_error_message (errno), 
 		       _("sh_socket_open_int: fcntl1"));
       SL_RETURN( (-1), _("sh_socket_open_int"));
@@ -663,7 +434,7 @@
   if (flags < 0)
     {
-      sl_close_fd(FIL__, __LINE__, pf_unix_fd); pf_unix_fd = -1;
+      close(pf_unix_fd); pf_unix_fd = -1;
       sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		      sh_error_message (errno, errbuf, sizeof(errbuf)), 
+		      sh_error_message (errno), 
 		      _("sh_socket_open_int: fcntl2"));
       SL_RETURN( (-1), _("sh_socket_open_int"));
@@ -672,7 +443,7 @@
   if (0 != listen(pf_unix_fd, 5))
     {
-      sl_close_fd(FIL__, __LINE__, pf_unix_fd); pf_unix_fd = -1;
+      close(pf_unix_fd); pf_unix_fd = -1;
       sh_error_handle ((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		       sh_error_message (errno, errbuf, sizeof(errbuf)), 
+		       sh_error_message (errno), 
 		       _("sh_socket_open_int: listen"));
       SL_RETURN( (-1), _("sh_socket_open_int"));
@@ -680,5 +451,18 @@
   SL_RETURN( (0), _("sh_socket_open_int"));
 }
-
+/* #if !defined(HAVE_CMSGCRED) || !defined(SO_PEERCRED) */
+/* #endif */
+
+/*
+#if !defined(HAVE_GETPEEREID) && !defined(SO_PEERCRED) && !defined(HAVE_STRUCT_CMSGCRED) && !defined(HAVE_STRUCT_FCRED) && !(defined(HAVE_STRUCT_SOCKCRED) && defined(LOCAL_CREDS))
+static 
+int sh_socket_read (struct socket_cmd * srvcmd)
+{
+  srvcmd->cmd[0] = '\0';
+  srvcmd->clt[0] = '\0';
+  return 0;
+}
+#else
+*/
 
 /*
@@ -709,20 +493,124 @@
  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  */
-
-static int receive_message(int talkfd, struct msghdr * msg, size_t message_size)
-{
-  unsigned int retry = 0;
+static 
+int sh_socket_read (struct socket_cmd * srvcmd)
+{
+  struct socket_cmd * list_cmd;
+  char message[SH_MAXMSG];
+  struct sockaddr_un name;
+  int size;
   int nbytes;
-  char * message = msg->msg_iov->iov_base;
-  char errbuf[SH_ERRBUF_SIZE];
+  int talkfd;
+  int retry = 0;
+
+  char * cmd = NULL;
+  char * clt = NULL;
+
+  int  client_uid = -1;
+
+
+  struct msghdr msg;
+  struct iovec iov;
+
+#if defined(NEED_PASSWORD_AUTH)
+  char * eopw = NULL;
+  char * goodpassword = NULL;
+#endif
+
+#if defined(HAVE_GETPEEREID)
+  uid_t peer_uid;
+  gid_t peer_gid;
+#elif defined(SO_PEERCRED) 
+  struct ucred cr;
+  int          cl = sizeof(cr);
+
+#elif defined(HAVE_STRUCT_CMSGCRED) || defined(HAVE_STRUCT_FCRED) || (defined(HAVE_STRUCT_SOCKCRED) && defined(LOCAL_CREDS))
+
+#ifdef HAVE_STRUCT_CMSGCRED
+  typedef struct cmsgcred Cred;
+#define CRED_UID cmcred_uid 
+
+#elif HAVE_STRUCT_FCRED
+  typedef struct fcred Cred;
+#define CRED_UID fc_uid 
+
+#elif HAVE_STRUCT_SOCKCRED
+  typedef struct sockcred Cred;
+#define CRED_UID sc_uid 
+
+#endif
+  Cred       *cred;
+
+  /* Compute size without padding */
+  char   cmsgmem[ALIGN(sizeof(struct cmsghdr)) + ALIGN(sizeof(Cred))];   
+  /* for NetBSD */
+
+  /* Point to start of first structure */
+  struct cmsghdr *cmsg = (struct cmsghdr *) cmsgmem;
+#endif
+
+  if (pf_unix_fd  < 0)
+    {
+      return 0;
+    }
+
+  iov.iov_base = (char *) &message;
+  iov.iov_len  = SH_MAXMSG;
+
+  memset (&msg, 0, sizeof (msg));
+  msg.msg_iov = &iov;
+  msg.msg_iovlen = 1;
+
+#if !defined(SO_PEERCRED) && !defined(HAVE_GETPEEREID)
+#if defined(HAVE_STRUCT_CMSGCRED) || defined(HAVE_STRUCT_FCRED) || (defined(HAVE_STRUCT_SOCKCRED) && defined(LOCAL_CREDS))
+  msg.msg_control = (char *) cmsg;
+  msg.msg_controllen = sizeof (cmsgmem);
+  memset (cmsg, 0, sizeof (cmsgmem));
+#endif
+#endif
+
+  /* the socket is non-blocking 
+   * 'name' is the address of the sender socket
+   */
+  size = sizeof (name);
+  talkfd = retry_accept(FIL__, __LINE__, 
+			pf_unix_fd, (struct sockaddr *) & name, &size);
+  if ((talkfd < 0) && (errno == EAGAIN))
+    {
+      return 0;
+    }
+  else if (talkfd < 0)
+    {
+      sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
+		      sh_error_message (errno), 
+		      _("sh_socket_read: accept"));
+      return -1;
+    }
+
+
+#if defined(LOCAL_CREDS) && !defined(SO_PEERCRED) && !defined(HAVE_GETPEEREID)
+  /* Set the socket to receive credentials on the next message 
+   */
+  {
+    int on = 1;
+    if (setsockopt (talkfd, 0, LOCAL_CREDS, &on, sizeof (on)) < 0)
+      {
+	sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
+			sh_error_message (errno), 
+			_("sh_socket_read: setsockopt"));
+	close(talkfd);
+	return -1;
+      }
+  }
+#endif
 
   do {
-    nbytes = recvmsg (talkfd, msg, 0);
+    nbytes = recvmsg (talkfd, &msg, 0);
     if ((nbytes < 0) && (errno != EAGAIN))
       {
 	sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-			sh_error_message (errno, errbuf, sizeof(errbuf)),
+			sh_error_message (errno),
 			_("sh_socket_read: recvmsg"));
-	sl_close_fd(FIL__, __LINE__, talkfd);	
+	close(talkfd);	
 	return -1;
       }
@@ -730,11 +618,15 @@
       {
 	++retry;
-	retry_msleep(0, 10);
+	retry_msleep(0, 1);
       }
   } while ((nbytes < 0) && (retry < 3));
 
-  /* msg.msg_iov.iov_base, filled by recvmsg
-   */
-  message[message_size-1] = '\0';
+#ifdef SH_DEBUG_SOCKET
+  fprintf(stderr, "%d bytes received\n", nbytes);
+#endif
+
+  /* nbytes = recv (talkfd, message, SH_MAXMSG, 0); */
+
+  message[SH_MAXMSG-1] = '\0';
 
   if (nbytes < 0)
@@ -743,81 +635,56 @@
 	{
 	  /* no data */
-	  sh_error_handle(SH_ERR_ALL, FIL__, __LINE__, errno, MSG_E_SUBGEN,
-			  sh_error_message (errno, errbuf, sizeof(errbuf)), 
-			  _("sh_socket_read: recvfrom"));
-	  sl_close_fd(FIL__, __LINE__, talkfd);
+	  close(talkfd);
 	  return 0;
 	}
       sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		      sh_error_message (errno, errbuf, sizeof(errbuf)), 
+		      sh_error_message (errno), 
 		      _("sh_socket_read: recvfrom"));
-      sl_close_fd(FIL__, __LINE__, talkfd);
+      close(talkfd);
       return -1;
     }
-  return 0;
-}
 
 #if defined(HAVE_GETPEEREID)
-
-static int get_peer_uid(int talkfd)
-{
-  uid_t peer_uid;
-  gid_t peer_gid;
-  char errbuf[SH_ERRBUF_SIZE];
-
   if (0 != getpeereid(talkfd, &peer_uid, &peer_gid))
     {
       sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		      sh_error_message (errno, errbuf, sizeof(errbuf)), 
+		      sh_error_message (errno), 
 		      _("sh_socket_read: getpeereid"));
-      sl_close_fd(FIL__, __LINE__, talkfd);
+      close(talkfd);
       return -1;
     }
-  return peer_uid;
-}
-
-#elif defined(SO_PEERCRED) 
-
-static int get_peer_uid(int talkfd)
-{
-  char errbuf[SH_ERRBUF_SIZE];
-  struct ucred cr;
-#ifdef HAVE_SOCKLEN_T
-  socklen_t cl = sizeof(cr);
-#else
-  int       cl = sizeof(cr);
-#endif 
-
+  client_uid = peer_uid;
+  cmd = message;
+#elif defined(SO_PEERCRED)
   if (0 != getsockopt(talkfd, SOL_SOCKET, SO_PEERCRED, &cr, &cl))
     {
       sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		      sh_error_message (errno, errbuf, sizeof(errbuf)), 
+		      sh_error_message (errno), 
 		      _("sh_socket_read: getsockopt"));
-      sl_close_fd(FIL__, __LINE__, talkfd);
+      close(talkfd);
       return -1;
     }
-  return cr.uid;
-}
-
-#endif
-
-#if defined(NEED_PASSWORD_AUTH)
-char * check_password(char * message, size_t msglen, int * client_uid, int talkfd)
-{
-  char * cmd = NULL;
-  char * eopw = NULL;
-  char * goodpassword = NULL;
-
+  client_uid = cr.uid;
+  cmd = message;
+#elif defined(HAVE_STRUCT_CMSGCRED) || defined(HAVE_STRUCT_FCRED) || (defined(HAVE_STRUCT_SOCKCRED) && defined(LOCAL_CREDS))
+  if (cmsg->cmsg_len < sizeof (cmsgmem) || cmsg->cmsg_type != SCM_CREDS)
+    {
+      sh_error_handle((-1), FIL__, __LINE__, 0, MSG_E_SUBGEN,
+		      _("Message from recvmsg() was not SCM_CREDS"), 
+		      _("sh_socket_read"));
+      close(talkfd);
+      return -1;
+    }
+  cred = (Cred *) CMSG_DATA (cmsg);
+  client_uid = cred->CRED_UID;
+  cmd = message;
+#elif defined(NEED_PASSWORD_AUTH)
   goodpassword = sh_get_sockpass();
   eopw = strchr(message, '@');
   if (eopw) 
     *eopw = '\0';
-  /*
-   * message is null-terminated and >> goodpassword
-   */
-  if (0 == strcmp(goodpassword, message) &&
-      strlen(goodpassword) < (msglen/2))
-    {
-      *client_uid = sh_socket_flaguid;
+  if (0 == strcmp(goodpassword, message))
+    {
+      client_uid = sh_socket_flaguid;
       cmd = &message[strlen(goodpassword)+1];
       sh_set_sockpass();
@@ -829,79 +696,18 @@
 		      _("sh_socket_read"));
       sh_set_sockpass();
-      sl_close_fd(FIL__, __LINE__, talkfd);
-      return NULL;
-    }
-  return cmd;
-}
-#endif
-
-static int list_all (int talkfd, char * cmd);
-static int process_message(int talkfd, char * cmd, struct socket_cmd * srvcmd);
-
-static 
-int sh_socket_read (struct socket_cmd * srvcmd)
-{
-  char message[SH_MAXMSG];
-  struct sockaddr_un name;
-  ACCEPT_TYPE_ARG3 size = sizeof(name);
-  int talkfd;
-  char * cmd = NULL;
-  int  client_uid = -1;
-  char errbuf[SH_ERRBUF_SIZE];
-  struct msghdr msg;
-  struct iovec iov;
-  int status;
-
-  if (pf_unix_fd  < 0)
-    return 0;
-
-  iov.iov_base = (char *) &message;
-  iov.iov_len  = sizeof(message);
-
-  memset (&msg, 0, sizeof (msg));
-  msg.msg_iov = &iov;
-  msg.msg_iovlen = 1;
-
-  /* the socket is non-blocking 
-   * 'name' is the address of the sender socket
-   */
-  do {
-    talkfd = accept(pf_unix_fd, (struct sockaddr *) &name, &size);
-  } while (talkfd < 0 && errno == EINTR);
-
-  if ((talkfd < 0) && (errno == EAGAIN))
-    {
-      return 0;
-    }
-  else if (talkfd < 0)
-    {
-      sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		      sh_error_message (errno, errbuf, sizeof(errbuf)), 
-		      _("sh_socket_read: accept"));
+      close(talkfd);
       return -1;
     }
-
-  if (receive_message(talkfd, &msg, sizeof(message)) < 0)
-    return -1;
-
-  /* Authenticate request by peer uid or password.
-   */
-#if defined(HAVE_GETPEEREID)
-  client_uid = get_peer_uid(talkfd);
-  cmd = message;
-
-#elif defined(SO_PEERCRED)
-  client_uid = get_peer_uid(talkfd);
-  cmd = message;
-
-#elif defined(NEED_PASSWORD_AUTH)
-  cmd = check_password(message, sizeof(message), &client_uid, talkfd);
-
 #else
   sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
 		  _("Socket credentials not supported on this OS"), 
 		  _("sh_socket_read"));
-  sl_close_fd(FIL__, __LINE__, talkfd);
+  close(talkfd);
   return -1;
+#endif
+
+#ifdef SH_DEBUG_SOCKET
+  fprintf(stderr, "Peer uid=%d, required=%d\n",
+	  client_uid, sh_socket_flaguid);
 #endif
 
@@ -911,85 +717,19 @@
 		      _("client does not have required uid"), 
 		      _("sh_socket_read: getsockopt"));
-      sl_close_fd(FIL__, __LINE__, talkfd);
+      close(talkfd);
       return -1;
     }
 
-  status = process_message(talkfd, cmd, srvcmd);
-
-  sl_close_fd(FIL__, __LINE__, talkfd);
-  return status;
-}
-
-static int check_valid_command(const char * str)
-{
-  unsigned int i = 0;
-  char * commands[] = { N_("DELTA"),  N_("RELOAD"),  N_("STOP"), N_("SCAN"),
-			N_("CANCEL"), N_("LISTALL"), N_("LIST"), N_("PROBE"), NULL };
-
-  while (commands[i])
-    {
-      if (0 == strcmp(_(commands[i]), str))
-	{
-	  return 0;
-	}
-      ++i;
-    }
-  return -1;
-}
-
-static int send_reply (int fd, char * msg)
-{
-  int nbytes = send (fd, msg, strlen(msg) + 1, 0);
-
-  if (nbytes < 0)
-    {
-      char errbuf[SH_ERRBUF_SIZE];
-      sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		      sh_error_message (errno, errbuf, sizeof(errbuf)), 
-		      _("send_reply"));
-      return -1;
-    }
-
-  return nbytes;
-}
-
-static int process_message(int talkfd, char * cmd, struct socket_cmd * srvcmd)
-{
-  int nbytes;
-  char error_type[SH_ERRBUF_SIZE] = { '\0' };
-  char * clt  = (cmd) ? strchr(cmd, ':') : NULL;
-
-  if (clt && 0 == strncmp(cmd, _("DELTA:"), 6))
-    {
-      /* DELTA:uuid:hostname 
-       */
-      char * uuid = clt;
-      
-      *uuid = '\0'; ++uuid;
-      clt = strchr(uuid, ':');
-      if (clt) { *clt = '\0'; ++clt; }
-      
-      if (sh_uuid_check(uuid) < 0)
-	{
-	  sl_strlcpy(error_type, _("!E:uuid-format:"), sizeof(error_type));
-	  sl_strlcat(error_type, uuid, sizeof(error_type));
-	  clt = NULL;
-	}
-      
-      --uuid; *uuid = ':';
-    }
-  else if (clt && *clt == ':')
-    { 
-      *clt = '\0'; ++clt; 
-      if (check_valid_command(cmd) < 0)
-	{
-	  sl_strlcpy(error_type, _("!E:cmd-invalid:"), sizeof(error_type));
-	  sl_strlcat(error_type, cmd, sizeof(error_type));
-	  clt = NULL;
-	}
-    }
-    
+
+  /* Give a diagnostic message. 
+   */
+#ifdef SH_DEBUG_SOCKET
+  fprintf (stderr, "Server: got message: %s\n", cmd);
+#endif
+
+  clt = strchr(cmd, ':');
   if (clt != NULL) 
     {
+      *clt = '\0'; ++clt;
       if (sl_strlen(cmd) >= SH_MAXMSGLEN)
 	{
@@ -997,6 +737,5 @@
 			  _("Bad message format: command too long"), 
 			  _("sh_socket_read"));
-	  sl_strlcpy(error_type, _("!E:cmd-toolong"), sizeof(error_type));
-	  send_reply(talkfd, error_type);
+	  close(talkfd);
 	  return -1;
 	}
@@ -1006,18 +745,19 @@
 			  _("Bad message format: hostname too long"), 
 			  _("sh_socket_read"));
-	  sl_strlcpy(error_type, _("!E:hostname-toolong"), sizeof(error_type));
-	  send_reply(talkfd, error_type);
+	  close(talkfd);
 	  return -1;
 	}
-
-      if (0 == strncmp(cmd, _("LIST"), 4))
-	return list_all(talkfd, cmd);
-      else if (0 == strncmp(cmd, _("PROBE"), 4))
+      if (cmd[0] == 'L' && cmd[1] == 'I' &&
+	  cmd[2] == 'S' && cmd[3] == 'T')
+	{
+	  goto list_all;
+	}
+      else if (cmd[0] == 'P' && cmd[1] == 'R' &&
+	  cmd[2] == 'O' && cmd[3] == 'B' && cmd[4] == 'E')
 	{
 	  sh_socket_probe4reload();
-	  sl_strlcpy(cmd, _("LIST"), 5);
-	  return list_all(talkfd, cmd);
-	}
-
+	  cmd[0] = 'L'; cmd[1] = 'I'; cmd[2] = 'S'; cmd[3] = 'T';cmd[4] = '\0';
+	  goto list_all;
+	}
       sl_strlcpy (srvcmd->cmd, cmd, SH_MAXMSGLEN);
       sl_strlcpy (srvcmd->clt, clt, SH_MAXMSGLEN);
@@ -1029,38 +769,61 @@
 		      _("Bad message format"), 
 		      _("sh_socket_read"));
-      if (error_type[0] == '\0')
-	sl_strlcpy(error_type, _("!E:message-format"), sizeof(error_type));
-      send_reply(talkfd, error_type);
+      close(talkfd);
       return -1;
     }
 
   /* Bounce the message back to the sender. 
+   * 'name' is the receiver address; it has been been filled
+   *        with the sender address in the recvfrom call 
    */
-  nbytes = send_reply(talkfd, cmd);
-
+#ifdef SH_DEBUG_SOCKET
+  fprintf (stderr, "Server: send message: %s to %s\n", 
+	   cmd, name.sun_path);
+#endif
+  /*
+  nbytes = sendto (pf_unix_fd, message, nbytes, 0,
+                       (struct sockaddr *) & name, size);
+  */
+  nbytes = send (talkfd, cmd, strlen(cmd) + 1, 0);
+  close(talkfd);
+  if (nbytes < 0)
+    {
+      sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
+		      sh_error_message (errno), 
+		      _("sh_socket_read: send"));
+      return -1;
+    }
+#ifdef SH_DEBUG_SOCKET
+  fprintf (stderr, "Server: message is out\n");
+#endif
   return nbytes;
-}
-
-static int list_all (int talkfd, char * cmd)
-{
-  int nbytes;
-  struct socket_cmd * list_cmd;
-  char message[SH_MAXMSG];
-  char errbuf[SH_ERRBUF_SIZE];
-
-  if (0 == strncmp(cmd, _("LISTALL"), 7))
+
+ list_all:
+#ifdef SH_DEBUG_SOCKET
+  fprintf (stderr, "Server: list all\n");
+#endif
+  if (cmd[4] == 'A' && cmd[5] == 'L' && cmd[6] == 'L')
     {
       list_cmd = runlist;
       while (list_cmd)
 	{
-	  sl_snprintf(message, sizeof(message), _("SENT  %42s  %32s  %s"),
+	  sl_snprintf(message, SH_MAXMSG, _("SENT  %8s  %32s  %s"),
 		      list_cmd->cmd, list_cmd->clt, list_cmd->cti);
-
+	  /*
+	  sl_strlcpy(message,     _("DONE"), SH_MAXMSG);
+	  sl_strlcat(message,          "  ", SH_MAXMSG);
+	  sl_strlcat(message, list_cmd->cmd, SH_MAXMSG);
+	  sl_strlcat(message,          "  ", SH_MAXMSG);
+	  sl_strlcat(message, list_cmd->clt, SH_MAXMSG);
+	  sl_strlcat(message,          "  ", SH_MAXMSG);
+	  sl_strlcat(message, list_cmd->cti, SH_MAXMSG);
+	  */
 	  nbytes = send (talkfd, message, sl_strlen(message) + 1, 0);
 	  if (nbytes < 0)
 	    {
 	      sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-			      sh_error_message (errno, errbuf, sizeof(errbuf)), 
+			      sh_error_message (errno), 
 			      _("sh_socket_read: sendto"));
+	      close(talkfd);
 	      return -1;
 	    }
@@ -1072,13 +835,26 @@
   while (list_cmd)
     {
-      sl_snprintf(message, sizeof(message), _(">>>>  %42s  %32s  %s"),
+      sl_snprintf(message, SH_MAXMSG, _(">>>>  %8s  %32s  %s"),
 		  list_cmd->cmd, list_cmd->clt, list_cmd->cti);
-
+      /*
+      sl_strlcpy(message,     _(">>>>"), SH_MAXMSG);
+      sl_strlcat(message,          "  ", SH_MAXMSG);
+      sl_strlcat(message, list_cmd->cmd, SH_MAXMSG);
+      sl_strlcat(message,          "  ", SH_MAXMSG);
+      sl_strlcat(message, list_cmd->clt, SH_MAXMSG);
+      sl_strlcat(message,          "  ", SH_MAXMSG);
+      sl_strlcat(message, list_cmd->cti, SH_MAXMSG);
+      */
+      /*
+      nbytes = sendto (pf_unix_fd, message, sl_strlen(message) + 1, 0,
+                       (struct sockaddr *) & name, size);
+      */
       nbytes = send (talkfd, message, sl_strlen(message) + 1, 0);
       if (nbytes < 0)
 	{
 	  sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-			  sh_error_message (errno, errbuf, sizeof(errbuf)), 
+			  sh_error_message (errno), 
 			  _("sh_socket_read: sendto"));
+	  close(talkfd);
 	  return -1;
 	}
@@ -1086,21 +862,41 @@
     }
 
-  send (talkfd, _("END"), 4, 0);
+  /*
+  nbytes = sendto (pf_unix_fd, _("END"), 4, 0,
+		   (struct sockaddr *) & name, size);
+  */
+  nbytes = send (talkfd, _("END"), 4, 0);
+  close(talkfd);
   return 0;
 }
+/* #if !defined(HAVE_CMSGCRED) || !defined(SO_PEERCRED) */
+/* #endif */
 
 static void sh_socket_add2list (struct socket_cmd * in)
 {
-  struct socket_cmd  * new  = cmdlist;
-  struct socket_cmd  * last = cmdlist;
+  struct socket_cmd  * new;
+
+  new = SH_ALLOC(sizeof(struct socket_cmd));
+  strcpy (new->cmd, in->cmd);
+  strcpy (new->clt, in->clt);
+  strcpy (new->cti, sh_unix_time(0));
+  new->next = cmdlist;
+  cmdlist   = new;
+
+  return;
+}
+
+static void sh_socket_add2run (struct socket_cmd * in)
+{
+  struct socket_cmd  * new = runlist;
+  char * client_name       = in->clt;
 
   while (new)
     {
-      /* Only skip identical commands.
-       */
-      if (0 == sl_strcmp(new->clt,  in->clt) &&
-	  0 == sl_strcmp(new->cmd,  in->cmd))
-	{
-	  (void) sh_unix_time(0, new->cti, sizeof(new->cti));
+      if (0 == sl_strcmp(new->clt, client_name))
+	{
+	  strcpy (new->cmd, in->cmd);
+	  strcpy (new->clt, in->clt);
+	  strcpy (new->cti, sh_unix_time(0));
 	  return;
 	}
@@ -1109,65 +905,16 @@
 
   new = SH_ALLOC(sizeof(struct socket_cmd));
-  sl_strlcpy (new->cmd,  in->cmd,  sizeof(new->cmd));
-  sl_strlcpy (new->clt,  in->clt,  sizeof(new->clt));
-  (void) sh_unix_time(0, new->cti, sizeof(new->cti));
-  new->next  = NULL;
-
-  if (last)
-    {
-      while (last->next) { last = last->next; }
-      last->next = new;
-    }
-  else
-    {
-      cmdlist = new;
-    }
+  strcpy (new->cmd, in->cmd);
+  strcpy (new->clt, in->clt);
+  strcpy (new->cti, sh_unix_time(0));
+  new->next = runlist;
+  runlist   = new;
+
   return;
 }
 
-static void sh_socket_add2run (struct socket_cmd * in)
-{
-  struct socket_cmd  * new  = runlist;
-  struct socket_cmd  * last = runlist;
-
-  while (new)
-    {
-      /* Only skip identical commands. First 5 will
-       * make all 'DELTA' identical.
-       */
-      if (0 == sl_strcmp(new->clt,  in->clt) &&
-	  0 == sl_strncmp(new->cmd,  in->cmd, 5))
-	{
-	  sl_strlcpy (new->cmd,  in->cmd,  sizeof(new->cmd));
-	  (void) sh_unix_time(0, new->cti, sizeof(new->cti));
-	  return;
-	}
-      new = new->next;
-    }
-
-  new = SH_ALLOC(sizeof(struct socket_cmd));
-  sl_strlcpy (new->cmd,  in->cmd,  sizeof(new->cmd));
-  sl_strlcpy (new->clt,  in->clt,  sizeof(new->clt));
-#ifdef SH_DEBUG_SOCKET
-  fprintf(stderr, "add2run: time set for %s\n", new->clt);
-#endif
-  (void) sh_unix_time(0, new->cti, sizeof(new->cti));
-  new->next  = NULL;
-
-  if (last)
-    {
-      while (last->next) { last = last->next; }
-      last->next = new;
-    }
-  else
-    {
-      runlist = new;
-    }
-  return;
-}
-
-
-
-static void sh_socket_rm2list (const char * client_name, int remove_all)
+
+
+static void sh_socket_rm2list (const char * client_name)
 {
   struct socket_cmd * old = cmdlist;
@@ -1180,5 +927,4 @@
 	  if ((new == cmdlist) && (new->next == NULL))
 	    {
-	      /* There is only one entry */
 	      cmdlist = NULL;
 	      SH_FREE(new);
@@ -1187,12 +933,7 @@
 	  else if (new == cmdlist)
 	    {
-	      /* first entry: new = old = cmdlist */
 	      cmdlist = new->next;
 	      SH_FREE(new);
-	      if (remove_all == S_FALSE)
-		return;
-	      old = cmdlist;
-	      new = cmdlist;
-	      continue;
+	      return;
 	    }
 	  else
@@ -1200,7 +941,5 @@
 	      old->next = new->next;
 	      SH_FREE(new);
-	      if (remove_all == S_FALSE)
-		return;
-	      new = old;
+	      return;
 	    }
 	}
@@ -1221,14 +960,21 @@
 
   if (pf_unix_fd  < 0)
-    return 0;
-
-  sl_strlcpy(cancel_cmd, _("CANCEL"), sizeof(cancel_cmd)); 
+    {
+      return 0;
+    }
+
+  sl_strlcpy(cancel_cmd, _("CANCEL"), SH_MAXMSGLEN); 
 
   while (sh_socket_read (&cmd) > 0)
     {
       if (0 == sl_strcmp(cmd.cmd, cancel_cmd))
-	sh_socket_rm2list  (cmd.clt, S_TRUE);
+	{
+	  sh_socket_rm2list  (cmd.clt);
+	}
       else
-	sh_socket_add2list (&cmd);
+	{
+	  sh_socket_rm2list  (cmd.clt);
+	  sh_socket_add2list (&cmd);
+	}
     }
   return 0;
@@ -1240,4 +986,5 @@
 char * sh_socket_check(const char * client_name)
 {
+  struct socket_cmd * old = cmdlist;
   struct socket_cmd * new = cmdlist;
   static char         out[SH_MAXMSGLEN];
@@ -1247,149 +994,17 @@
       if (0 == sl_strcmp(new->clt, client_name))
 	{
-	  sl_strlcpy(out,  new->cmd,  sizeof(out));
+	  sl_strlcpy(out, new->cmd, SH_MAXMSGLEN);
 	  sh_socket_add2run (new);
-	  sh_socket_rm2list (client_name, S_FALSE);
+	  sh_socket_rm2list  (client_name);
 	  return out;
 	}
+      old = new;
       new = new->next;
     }
   return NULL;
 }
+
 /* #if defined (SH_WITH_SERVER)
  */
 #endif
 
-
-#ifdef SH_CUTEST
-#include "CuTest.h"
-
-void Test_cmdlist (CuTest *tc) {
-
-#if defined (SH_WITH_SERVER)
-  struct socket_cmd cmd;
-  char * p;
-
-  sl_strlcpy(cmd.clt, "one", sizeof(cmd.clt));
-  sl_strlcpy(cmd.cmd, "RELOAD", sizeof(cmd.cmd));
-
-  sh_socket_add2list (&cmd);
-  p = sh_socket_check("one");
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc, "RELOAD", p);
-
-  p = sh_socket_check("one");
-  CuAssertPtrEquals(tc, NULL, p);
-
-  sh_socket_add2list (&cmd);
-  sl_strlcpy(cmd.cmd, "STOP",   sizeof(cmd.cmd));
-  sh_socket_add2list (&cmd);
-
-  sl_strlcpy(cmd.clt, "two", sizeof(cmd.clt));
-  sl_strlcpy(cmd.cmd, "STOP", sizeof(cmd.cmd));
-  sh_socket_add2list (&cmd);
-  sl_strlcpy(cmd.clt, "three", sizeof(cmd.clt));
-  sl_strlcpy(cmd.cmd, "STOP", sizeof(cmd.cmd));
-  sh_socket_add2list (&cmd);
-
-  sl_strlcpy(cmd.clt, "one", sizeof(cmd.clt));
-  sl_strlcpy(cmd.cmd, "DELTA",   sizeof(cmd.cmd));
-  sh_socket_add2list (&cmd);
-
-  p = sh_socket_check("one");
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc, "RELOAD", p);
-
-  sl_strlcpy(cmd.clt, "two", sizeof(cmd.clt));
-  sl_strlcpy(cmd.cmd, "RELOAD", sizeof(cmd.cmd));
-  sh_socket_add2list (&cmd);
-  sl_strlcpy(cmd.clt, "three", sizeof(cmd.clt));
-  sl_strlcpy(cmd.cmd, "RELOAD", sizeof(cmd.cmd));
-  sh_socket_add2list (&cmd);
-
-  p = sh_socket_check("one");
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc, "STOP", p);
-  p = sh_socket_check("one");
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc, "DELTA", p);
-  p = sh_socket_check("one");
-  CuAssertPtrEquals(tc, NULL, p);
-
-  /* Test removal in correct order */
-  sl_strlcpy(cmd.clt, "one", sizeof(cmd.clt));
-  sl_strlcpy(cmd.cmd, "RELOAD", sizeof(cmd.cmd));
-  sh_socket_add2list (&cmd);
-  sl_strlcpy(cmd.cmd, "STOP",   sizeof(cmd.cmd));
-  sh_socket_add2list (&cmd);
-  sl_strlcpy(cmd.cmd, "DELTA",  sizeof(cmd.cmd));
-  sh_socket_add2list (&cmd);
-  sl_strlcpy(cmd.cmd, "FOOBAR", sizeof(cmd.cmd));
-  sh_socket_add2list (&cmd);
-  
-  sh_socket_rm2list ("one", S_FALSE);
-
-  p = sh_socket_check("one");
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc, "STOP", p);
-
-  sh_socket_rm2list ("one", S_FALSE);
-  
-  p = sh_socket_check("one");
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc, "FOOBAR", p);
-
-  p = sh_socket_check("one");
-  CuAssertPtrEquals(tc, NULL, p);
-
-  sl_strlcpy(cmd.clt, "one", sizeof(cmd.clt));
-  sl_strlcpy(cmd.cmd, "RELOAD", sizeof(cmd.cmd));
-  sh_socket_add2list (&cmd);
-  sl_strlcpy(cmd.cmd, "STOP",   sizeof(cmd.cmd));
-  sh_socket_add2list (&cmd);
-
-  sl_strlcpy(cmd.clt, "two", sizeof(cmd.clt));
-  sl_strlcpy(cmd.cmd, "RELOAD", sizeof(cmd.cmd));
-  sh_socket_add2list (&cmd);
-  sl_strlcpy(cmd.clt, "three", sizeof(cmd.clt));
-  sl_strlcpy(cmd.cmd, "RELOAD", sizeof(cmd.cmd));
-  sh_socket_add2list (&cmd);
-
-  sl_strlcpy(cmd.clt, "one", sizeof(cmd.clt));
-  sl_strlcpy(cmd.cmd, "DELTA",  sizeof(cmd.cmd));
-  sh_socket_add2list (&cmd);
-  sl_strlcpy(cmd.cmd, "FOOBAR", sizeof(cmd.cmd));
-  sh_socket_add2list (&cmd);
-
-  sh_socket_rm2list ("one", S_TRUE);
-  p = sh_socket_check("one");
-  CuAssertPtrEquals(tc, NULL, p);
-
-  p = sh_socket_check("two");
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc, "STOP", p);
-  p = sh_socket_check("two");
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc, "RELOAD", p);
-  p = sh_socket_check("two");
-  CuAssertPtrEquals(tc, NULL, p);
-
-  p = sh_socket_check("three");
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc, "STOP", p);
-  p = sh_socket_check("three");
-  CuAssertPtrNotNull(tc, p);
-  CuAssertStrEquals(tc, "RELOAD", p);
-  p = sh_socket_check("three");
-  CuAssertPtrEquals(tc, NULL, p);
-
-  p = sh_socket_check("four");
-  CuAssertPtrEquals(tc, NULL, p);
-#else
-  (void) tc;
-#endif
-}
-
-#endif  /* #ifdef SH_CUTEST */
-
-
-
