Index: trunk/src/CuTest.c
===================================================================
--- trunk/src/CuTest.c	(revision 136)
+++ trunk/src/CuTest.c	(revision 137)
@@ -32,4 +32,5 @@
 #include <string.h>
 #include <math.h>
+#include <unistd.h>
 
 #include "CuTest.h"
Index: trunk/src/cutest_sh_tiger0.c
===================================================================
--- trunk/src/cutest_sh_tiger0.c	(revision 136)
+++ trunk/src/cutest_sh_tiger0.c	(revision 137)
@@ -9,4 +9,9 @@
 #include "sh_tiger.h"
 
+#if defined(HAVE_PTHREAD) && defined(SH_STEALTH)
+extern void sh_g_init();
+#endif
+
+
 static void init() {
 
@@ -16,4 +21,7 @@
   int i;
 
+#if defined(HAVE_PTHREAD) && defined(SH_STEALTH)
+  sh_g_init();
+#endif
   skey = (sh_key_t *) malloc (sizeof(sh_key_t));
   if (skey != NULL) 
@@ -69,4 +77,8 @@
   char hashbuf[KEYBUF_SIZE];
 
+#if defined(HAVE_PTHREAD) && defined(SH_STEALTH)
+  sh_g_init();
+#endif
+
   input  = "";
   actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
Index: trunk/src/samhain.c
===================================================================
--- trunk/src/samhain.c	(revision 136)
+++ trunk/src/samhain.c	(revision 137)
@@ -139,5 +139,5 @@
 
 #ifdef HAVE_PTHREAD
-typedef struct gt {
+struct gt {
   size_t g_count;
   char * g_glob;
@@ -149,5 +149,5 @@
 {
   struct gt * ptr = malloc(sizeof(struct gt));
-  if (!gt)
+  if (!ptr)
     return -1;
   ptr->g_count    = 0;
@@ -166,5 +166,5 @@
 }
 
-static void sh_g_init()
+void sh_g_init()
 {
   if (0 != pthread_key_create(&g_key, sh_g_destroy))
@@ -176,5 +176,5 @@
   if (0 != sh_g_thread())
     {
-      perror("1");
+      perror("2");
       exit(EXIT_FAILURE);
     }
@@ -191,17 +191,24 @@
   size_t j;
 
-#ifdef HAVE_PTHREAD
-  struct gt * ptr = pthread_getspecific(g_key);
-  size_t count = ptr->g_count;
-  char *  glob = ptr->g_glob;
-#else
+#ifndef HAVE_PTHREAD
   static   size_t  count = 0;
   static   char glob[SH_MAX_GLOBS * (GLOB_LEN+1)];
-#
-
-  if (str == NULL)
+#else
+  struct gt * ptr = pthread_getspecific(g_key);
+  size_t count;
+  char *  glob;
+
+  if (ptr) {
+    count = ptr->g_count;
+    glob  = ptr->g_glob;
+  } else {
     return NULL;
+  }
+#endif
+
+  if (str != NULL)
+    j = strlen(str);
   else
-    j = strlen(str);
+    return NULL;
 
   ASSERT((j <= GLOB_LEN), _("j <= GLOB_LEN"))
@@ -228,5 +235,5 @@
   i     = count;
 #ifdef HAVE_PTHREAD
-  ptr->count = count + j + 1;
+  ptr->g_count = count + j + 1;
 #else
   count = count + j + 1;
@@ -248,4 +255,7 @@
 }
 
+#else
+/* not stealth */
+#define SH_G_INIT ((void)0)
 #endif
 
@@ -815,5 +825,5 @@
     }
 
-  SH_MUTEX_LOCK(readdir_lock);
+  SH_MUTEX_LOCK(mutex_readdir);
 
   while (NULL != (d = readdir(dp)) && i < 65535)
@@ -838,5 +848,5 @@
     }
 
-  SH_MUTEX_UNLOCK(readdir_lock);
+  SH_MUTEX_UNLOCK(mutex_readdir);
 
   closedir(dp);
Index: trunk/src/sh_calls.c
===================================================================
--- trunk/src/sh_calls.c	(revision 136)
+++ trunk/src/sh_calls.c	(revision 137)
@@ -781,5 +781,5 @@
     if (i < 0)
       sh_error_handle ((-1), file, line, error, MSG_ERR_PIPE, 
-		       sh_error_message(error),
+		       sh_error_message(error, errbuf, sizeof(errbuf)),
 		       (long) 0, (long) 0);
     else
Index: trunk/src/sh_err_console.c
===================================================================
--- trunk/src/sh_err_console.c	(revision 136)
+++ trunk/src/sh_err_console.c	(revision 137)
@@ -70,5 +70,7 @@
   key_t            key;
   int              error;
+#if defined(WITH_TPT) 
   char errbuf[SH_ERRBUF_SIZE];
+#endif
 
   SL_ENTER(_("open_ipc"));
@@ -132,5 +134,7 @@
   int              error;
   int              count    = 0;
+#if defined(WITH_TPT) 
   char errbuf[SH_ERRBUF_SIZE];
+#endif
 
   SL_ENTER(_("push_message_queue"));
Index: trunk/src/sh_err_log.c
===================================================================
--- trunk/src/sh_err_log.c	(revision 136)
+++ trunk/src/sh_err_log.c	(revision 137)
@@ -649,4 +649,5 @@
   char               * sigkey_old;
   char               * crypto;
+  char                 hashbuf[KEYBUF_SIZE];
 
   SL_ENTER(_("sh_log_file"));
@@ -865,6 +866,4 @@
   if (current->log_start == S_TRUE) 
     {
-      char hashbuf[KEYBUF_SIZE];
-
       if (sh.real.user[0] == '\0') 
 	(void) sh_unix_getUser();
@@ -948,5 +947,5 @@
       log_msg.timestamp[0] = '\0';
       (void) sl_strlcpy (sigkey_new, 
-			 sh_tiger_hash (sigkey_old, TIGER_DATA, KEY_LEN),
+			 sh_tiger_hash (sigkey_old, TIGER_DATA, KEY_LEN, hashbuf, sizeof(hashbuf)),
 			 KEY_LEN+1);
     }
@@ -954,10 +953,12 @@
   /* --- Sign the message with the signature key. ---
    */
+  sh_tiger_hash (log_msg.msg, -1, 10, hashbuf, 10);
+  sh_tiger_hash (log_msg.msg, TIGER_DATA,
+		 (unsigned long)(status + KEY_LEN), (char *) hashbuf, (size_t) sizeof(hashbuf));
 
   (void) sl_strlcat (log_msg.msg, sigkey_new, (size_t)(status + KEY_LEN + 2));
-  
   (void) sl_strlcpy (log_msg.signature,
-		     sh_tiger_hash (log_msg.msg, TIGER_DATA, 
-				    (unsigned long)(status + KEY_LEN)), 
+		     sh_tiger_hash (log_msg.msg, (TigerType) TIGER_DATA,
+				    (unsigned long)(status + KEY_LEN), hashbuf, sizeof(hashbuf)),
 		     KEY_LEN+1);
   (void) sl_strlcpy (sigkey_old, sigkey_new, KEY_LEN+1); 
Index: trunk/src/sh_files.c
===================================================================
--- trunk/src/sh_files.c	(revision 136)
+++ trunk/src/sh_files.c	(revision 137)
@@ -51,4 +51,5 @@
 #endif
 #endif
+#define NEED_ADD_DIRENT
 
 #ifdef HAVE_GLOB_H
@@ -1636,5 +1637,5 @@
   /* ---- read ----
    */
-  SH_MUTEX_LOCK(readdir_lock);
+  SH_MUTEX_LOCK(mutex_readdir);
 
   do {
@@ -1657,5 +1658,5 @@
   } while (thisEntry != NULL);
 
-  SH_MUTEX_UNLOCK(readdir_lock);
+  SH_MUTEX_UNLOCK(mutex_readdir);
 
   closedir (thisDir);
Index: trunk/src/sh_forward.c
===================================================================
--- trunk/src/sh_forward.c	(revision 136)
+++ trunk/src/sh_forward.c	(revision 137)
@@ -277,4 +277,5 @@
   register int i;
   unsigned char * dez = NULL;
+  char hashbuf[KEYBUF_SIZE];
 
   if (password == NULL)
@@ -297,5 +298,6 @@
 	}
       (void) sl_strlcpy (skey->vernam,
-			 sh_tiger_hash(skey->vernam, TIGER_DATA, PW_LEN), 
+			 sh_tiger_hash(skey->vernam, TIGER_DATA, PW_LEN,
+				       hashbuf, sizeof(hashbuf)), 
 			 KEY_LEN+1);
     }
@@ -320,5 +322,6 @@
   (void) sl_strlcpy (hash, 
 		     sh_tiger_hash(combi, TIGER_DATA, 
-				   (unsigned long) sl_strlen(combi)),
+				   (unsigned long) sl_strlen(combi),
+				   hashbuf, sizeof(hashbuf)),
 		     KEY_LEN+1);
 
@@ -1012,7 +1015,6 @@
       /* --- Create own nonce. ---
        */
-      ticks = (UINT32) taus_get (&(skey->rng0[0]), 
-				 &(skey->rng1[0]),
-				 &(skey->rng2[0]));
+      ticks = (UINT32) taus_get ();
+
       (void) sl_strlcpy(nonce_u, 
 			sh_tiger_hash((char *) &ticks, 
@@ -1591,7 +1593,5 @@
 	      /* --- Generate a nonce. ---
 	       */
-	      ticks = (UINT32) taus_get (&(skey->rng0[0]), 
-					 &(skey->rng1[0]),
-					 &(skey->rng2[0]));
+	      ticks = (UINT32) taus_get ();
               
 	      (void) sl_strlcpy(nclt, 
@@ -1897,6 +1897,6 @@
   char hashbuf[KEYBUF_SIZE];
 
-  val[0] = taus_get (&(skey->rng0[0]), &(skey->rng0[1]), &(skey->rng0[2]));
-  val[1] = taus_get (&(skey->rng0[0]), &(skey->rng0[1]), &(skey->rng0[2]));
+  val[0] = taus_get ();
+  val[1] = taus_get ();
 
   sl_strlcpy (output, 
@@ -2970,7 +2970,6 @@
 	      sl_strlcpy (conn->peer, &(conn->buf[KEY_LEN]), SH_MINIBUF+1);
 
-	      ticks = (UINT32) taus_get (&(skey->rng0[0]), 
-					 &(skey->rng1[0]),
-					 &(skey->rng2[0]));
+	      ticks = (UINT32) taus_get ();
+
 	      if (conn->K != NULL) 
 		{
@@ -3430,7 +3429,6 @@
 	      sl_strlcpy (conn->peer, &(conn->buf[KEY_LEN]), SH_MINIBUF+1);
 
-	      ticks = (UINT32) taus_get (&(skey->rng0[0]), 
-					 &(skey->rng1[0]),
-					 &(skey->rng2[0]));
+	      ticks = (UINT32) taus_get ();
+
 	      test = (char *) &ticks;
 	      sh_util_cpylong (conn->challenge, test, 4);
@@ -3790,7 +3788,5 @@
 	      /* -- create server nounce v --
 	       */
-	      ticks = (UINT32) taus_get (&(skey->rng0[0]), 
-					 &(skey->rng1[0]),
-					 &(skey->rng2[0]));
+	      ticks = (UINT32) taus_get ();
 	      
 	      if (conn->A != NULL)
@@ -4116,7 +4112,6 @@
 		   * create nonce u 
 		   */
-		  ticks = (UINT32) taus_get (&(skey->rng0[0]), 
-					     &(skey->rng1[0]),
-					     &(skey->rng2[0])); 
+		  ticks = (UINT32) taus_get ();
+
 		  test = (char *) &ticks;
 		  sh_util_cpylong (u, test, 4);  /* u        nounce        */
Index: trunk/src/sh_gpg.c
===================================================================
--- trunk/src/sh_gpg.c	(revision 136)
+++ trunk/src/sh_gpg.c	(revision 137)
@@ -554,6 +554,6 @@
        * between the integrity check and the execve
        */
-      myrand = (int) taus_get (&(skey->rng0[0]), &(skey->rng1[0]), 
-			       &(skey->rng2[0]));
+      myrand = (int) taus_get ();
+
       myrand = (myrand < 0) ? (-myrand) : myrand;
       myrand = (myrand % 32) + 2;
Index: trunk/src/sh_hash.c
===================================================================
--- trunk/src/sh_hash.c	(revision 136)
+++ trunk/src/sh_hash.c	(revision 137)
@@ -2010,4 +2010,5 @@
   int         i = 0;
   char      * p;
+  char        i2h[2];
 
   tmpFile.attr_string = NULL;
@@ -2035,5 +2036,5 @@
       for (i = 0; i < size; ++i)
 	{
-	  p = sh_util_charhex (str[i]);
+	  p = sh_util_charhex (str[i],i2h);
 	  tmpFile.linkpath[2*i]   = p[0];
 	  tmpFile.linkpath[2*i+1] = p[1];
Index: trunk/src/sh_kern.c
===================================================================
--- trunk/src/sh_kern.c	(revision 136)
+++ trunk/src/sh_kern.c	(revision 137)
@@ -202,4 +202,5 @@
   char  *linkpath_old;
   char  *linkpath_new;
+  char   i2h[2];
 
 #ifdef SH_USE_XML
@@ -226,5 +227,5 @@
   for (k = 0; k < old_len; ++k)
     {
-      p = sh_util_charhex (old[k]);
+      p = sh_util_charhex (old[k], i2h);
       linkpath_old[2*k]   = p[0];
       linkpath_old[2*k+1] = p[1];
@@ -234,5 +235,5 @@
   for (k = 0; k < new_len; ++k)
     {
-      p = sh_util_charhex (new[k]);
+      p = sh_util_charhex (new[k], i2h);
       linkpath_new[2*k]   = p[0];
       linkpath_new[2*k+1] = p[1];
@@ -967,5 +968,5 @@
   if (df)
     {
-      SH_MUTEX_LOCK(readdir_lock);
+      SH_MUTEX_LOCK(mutex_readdir);
 
       while (NULL != (entry = readdir(df)))
@@ -981,5 +982,5 @@
 	}
 
-      SH_MUTEX_UNLOCK(readdir_lock);
+      SH_MUTEX_UNLOCK(mutex_readdir);
 
       closedir(df);
Index: trunk/src/sh_mail.c
===================================================================
--- trunk/src/sh_mail.c	(revision 136)
+++ trunk/src/sh_mail.c	(revision 137)
@@ -58,4 +58,5 @@
 #include "sh_fifo.h"
 #include "sh_tools.h"
+#include "sh_pthread.h"
 
 #undef  FIL__
@@ -1246,5 +1247,5 @@
 #endif
 
-static int sh_mail_wait(int code, FILE * m_socket);
+static int sh_mail_wait(int code, int ma_socket);
 
 static char * relay_host = NULL;
@@ -1680,9 +1681,11 @@
     g = (int) c;
 
-    if ( (g=fgetc(ma_socket)) == EOF)
+    /*
+    if (g == EOF)
       {
 	TPT((0, FIL__, __LINE__, _("msg=<mail_wait: EOF>\n"))); 
 	SL_RETURN( 0, _("mail_wait")); 
       }
+    */
 
     switch(state) {
@@ -2101,5 +2104,5 @@
   dnsrep * answers = NULL;
   mx     * result;
-  dnsrep * retval;
+  dnsrep * retval  = NULL;
   char     errmsg[128];
   size_t   len;
Index: trunk/src/sh_mem.c
===================================================================
--- trunk/src/sh_mem.c	(revision 136)
+++ trunk/src/sh_mem.c	(revision 137)
@@ -20,4 +20,10 @@
 #include "config_xor.h"
 
+/* With glibc, _XOPEN_SOURCE 500 is required for 
+ * pthread_mutexattr_settype/PTHREAD_MUTEX_RECURSIVE
+ */
+#if defined(HAVE_PTHREAD) && defined(MEM_DEBUG)
+#define _XOPEN_SOURCE 500
+#endif
 
 #include <stdio.h>
@@ -108,5 +114,5 @@
 static pthread_mutex_t mutex_mem;
 
-static int initialize_mem(void)
+static void initialize_mem(void)
 {
   pthread_mutexattr_t   mta;
@@ -114,5 +120,5 @@
   pthread_mutex_init(&mutex_mem, &mta);
   pthread_mutexattr_destroy(&mta);
-  return 0;
+  return;
 }
 #define MEM_MUTEX_INIT  (void) pthread_once(&mem_is_initialized, initialize_mem)
Index: trunk/src/sh_portcheck.c
===================================================================
--- trunk/src/sh_portcheck.c	(revision 136)
+++ trunk/src/sh_portcheck.c	(revision 137)
@@ -115,4 +115,5 @@
 #include "sh_utils.h"
 #include "sh_modules.h"
+#include "sh_pthread.h"
 
 static int sh_portchk_severity  = SH_ERR_SEVERE;
Index: trunk/src/sh_srp.c
===================================================================
--- trunk/src/sh_srp.c	(revision 136)
+++ trunk/src/sh_srp.c	(revision 137)
@@ -341,7 +341,6 @@
 
   for (i = 0; i < 6; ++i)
-    randl[i] = (UINT32) taus_get (&(skey->rng0[0]), 
-				  &(skey->rng1[0]),
-				  &(skey->rng2[0]));
+    randl[i] = (UINT32) taus_get ();
+
   (void) sl_strlcpy (hash, 
 		     sh_tiger_hash((char *)&randl[0], TIGER_DATA, 
Index: trunk/src/sh_suidchk.c
===================================================================
--- trunk/src/sh_suidchk.c	(revision 136)
+++ trunk/src/sh_suidchk.c	(revision 137)
@@ -69,4 +69,5 @@
 #endif
 #endif
+#define NEED_ADD_DIRENT
 
 #include "samhain.h"
@@ -869,5 +870,5 @@
   /* Loop over directory entries
    */
-  SH_MUTEX_LOCK(readdir_lock);
+  SH_MUTEX_LOCK(mutex_readdir);
 
   do {
@@ -892,5 +893,5 @@
   } while (thisEntry != NULL);
 
-  SH_MUTEX_UNLOCK(readdir_lock);
+  SH_MUTEX_UNLOCK(mutex_readdir);
 
   closedir(thisDir);
@@ -1080,7 +1081,7 @@
 			if (-1 == fflags)
 			  {
-			    (void) sh_unix_gmttime (theFile->ctime, timestrc, sizeof(timestrc)); 
-			    (void) sh_unix_gmttime (theFile->atime, timestra, sizeof(timestra)); 
-			    (void) sh_unix_gmttime (theFile->mtime, timestrm, sizeof(timestrm));
+			    (void) sh_unix_gmttime (theFile.ctime, timestrc, sizeof(timestrc)); 
+			    (void) sh_unix_gmttime (theFile.atime, timestra, sizeof(timestra)); 
+			    (void) sh_unix_gmttime (theFile.mtime, timestrm, sizeof(timestrm));
 
 			    report_file(tmpcat, &theFile, timestrc, timestra, timestrm);
Index: trunk/src/sh_tiger0.c
===================================================================
--- trunk/src/sh_tiger0.c	(revision 136)
+++ trunk/src/sh_tiger0.c	(revision 137)
@@ -24,4 +24,5 @@
 #include "sh_error.h"
 #include "sh_utils.h"
+#include "sh_pthread.h"
 
 #define PRIV_MAX  32768
@@ -121,5 +122,5 @@
   UINT64    bcount = 0;
 
-  char * buffer = SH_ALLOC(PRIV_MAX + 72);
+  sh_byte * buffer = SH_ALLOC(PRIV_MAX + 72);
 
   unsigned long pages_read;
@@ -156,5 +157,5 @@
   if (what >= TIGER_FILE) 
     {
-      if (what > TIGER_FD)
+      if (what > TIGER_FILE)
 	{
 	  fd = what;
@@ -829,5 +830,4 @@
   size_t sum;
 
-  SL_TICKET  fd;
   char * tmp;
   uid_t   euid;
@@ -869,5 +869,5 @@
 
       n = (off_t) sl_read_timeout (fd, buffer + sum, 
-				   (size_t) BLOCKSIZE - sum, timeout);
+				   (size_t) BLOCKSIZE - sum, timeout, SL_FALSE);
 
       if (SL_ISERROR (n))
@@ -1339,5 +1339,4 @@
   char buffer[4168]; /* BLOCKSIZE + 72 AIX compiler chokes */
   off_t sum = 0;
-  SL_TICKET  fd;
   char * tmp;
   uid_t  euid;
@@ -1379,5 +1378,5 @@
     do {
       n = (off_t) sl_read_timeout(fd, buffer + sum, 
-				  (size_t) BLOCKSIZE - sum, timeout);
+				  (size_t) BLOCKSIZE - sum, timeout, SL_FALSE);
 
       if (SL_ISERROR (n))
Index: trunk/src/sh_tools.c
===================================================================
--- trunk/src/sh_tools.c	(revision 136)
+++ trunk/src/sh_tools.c	(revision 137)
@@ -88,4 +88,5 @@
 #define SH_NEED_GETHOSTBYXXX
 #include "sh_static.h"
+#include "sh_pthread.h"
 
 #undef  FIL__
@@ -723,5 +724,7 @@
   struct  sigaction  new_act;
   struct  sigaction  old_act;
+#if defined(WITH_TPT) 
   char    errbuf[SH_ERRBUF_SIZE];
+#endif
 
   SL_ENTER(_("sh_write_select"));
@@ -1144,9 +1147,9 @@
   /* random_pad
    */
-  rpad[1] = taus_get (&(skey->rng0[0]), &(skey->rng1[0]), &(skey->rng2[0]));
+  rpad[1] = taus_get ();
   memcpy (head,      &rpad[1],    4);
-  rpad[0] = taus_get (&(skey->rng0[0]), &(skey->rng1[0]), &(skey->rng2[0]));
+  rpad[0] = taus_get ();
   memcpy (&head[4],  &rpad[0],    4);
-  rpad[2] = taus_get (&(skey->rng0[0]), &(skey->rng1[0]), &(skey->rng2[0]));
+  rpad[2] = taus_get ();
   memcpy (&head[8],  &rpad[2],    4);
 
@@ -1634,5 +1637,5 @@
     /* create random filename in effective users home directory
      */
-    ticks = taus_get (&(skey->rng0[0]), &(skey->rng1[0]), &(skey->rng2[0]));
+    ticks = taus_get ();
     if (my_tmp_dir[0] == '/' && my_tmp_dir[1] == '\0')
       file = sh_util_strconcat (my_tmp_dir, 
Index: trunk/src/sh_unix.c
===================================================================
--- trunk/src/sh_unix.c	(revision 136)
+++ trunk/src/sh_unix.c	(revision 137)
@@ -94,4 +94,5 @@
 #include "sh_tiger.h"
 #include "sh_prelink.h"
+#include "sh_pthread.h"
 
 /* moved here from far below
@@ -956,5 +957,5 @@
 static int tf_add_trusted_user_int(const char * c)
 {
-  register struct passwd *          w;
+  struct passwd *          w;
   int                           count;
   uid_t                     pwid  = (uid_t)-1;
@@ -970,5 +971,5 @@
    */
 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R)
-  status = sh_getpwnam_r(c, &pwd, buffer, sizeof(buffer), &w);
+  sh_getpwnam_r(c, &pwd, buffer, sizeof(buffer), &w);
 #else
   w = sh_getpwnam(c);
@@ -3243,5 +3244,4 @@
   ShFileType    type;
   unsigned int  mode;
-  char        * name;
   char        * tmp;
   char        * tmp2;
@@ -3545,5 +3545,5 @@
 
   
-  if (NULL == sh_unix_getUIDname(SH_ERR_ALL, buf.st_uid, theFile->c_owner, USER_MAX+)) {
+  if (NULL == sh_unix_getUIDname(SH_ERR_ALL, buf.st_uid, theFile->c_owner, USER_MAX+1)) {
 
     tmp2 = sh_util_safe_name (theFile->fullpath);
@@ -3571,5 +3571,5 @@
       tmp2 = sh_util_safe_name ((filename == NULL) ? 
 				theFile->fullpath : filename);
-      (void) sh_unix_time(theFile->mtime, timestr, sizeof(timestring));
+      (void) sh_unix_time(theFile->mtime, timestr, sizeof(timestr));
       sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_LIST,
 		       theFile->c_mode,
Index: trunk/src/sh_userfiles.c
===================================================================
--- trunk/src/sh_userfiles.c	(revision 136)
+++ trunk/src/sh_userfiles.c	(revision 137)
@@ -30,5 +30,4 @@
 #include <pwd.h>
 
-
 #include "samhain.h"
 #include "sh_modules.h"
@@ -41,4 +40,5 @@
 #define SH_NEED_PWD_GRP 1
 #include "sh_static.h"
+#include "sh_pthread.h"
 
 #ifdef SH_USE_USERFILES
Index: trunk/src/sh_utils.c
===================================================================
--- trunk/src/sh_utils.c	(revision 136)
+++ trunk/src/sh_utils.c	(revision 137)
@@ -45,4 +45,5 @@
 #include "sh_tiger.h"
 #include "sh_entropy.h"
+#include "sh_pthread.h"
 
 #undef  FIL__
@@ -570,7 +571,6 @@
 }
 
-char * sh_util_charhex( unsigned char i )
-{
-  static char i2h[2];
+char * sh_util_charhex( unsigned char i , char * i2h)
+{
   int j, k;
 
@@ -669,5 +669,4 @@
   UINT32    * h2;
   UINT32      cc[KEY_LEN/4];
-  char      * res;
   UINT32      kbuf[KEY_BYT/sizeof(UINT32)];
   char hashbuf[KEYBUF_SIZE];
@@ -681,5 +680,6 @@
   if (KEY_BLOCK > (KEY_LEN/2))
     {
-      res = sh_tiger_hash (NULL, TIGER_DATA, 0, hashbuf, sizeof(hashbuf));
+      (void) sh_tiger_hash (NULL, TIGER_DATA, 0, hashbuf, sizeof(hashbuf));
+      sl_strlcpy(res, hashbuf, len);
       SL_RETURN(res, _("sh_util_hmac_tiger"));
     }
@@ -689,5 +689,6 @@
   if (sh_util_hextobinary (K, hexkey, KEY_LEN) < 0)
     {
-      res = sh_tiger_hash (NULL, TIGER_DATA, 0, hashbuf, sizeof(hashbuf));
+      (void) sh_tiger_hash (NULL, TIGER_DATA, 0, hashbuf, sizeof(hashbuf));
+      sl_strlcpy(res, hashbuf, len);
       SL_RETURN(res, _("sh_util_hmac_tiger"));
     }
@@ -712,5 +713,6 @@
 		      _("integer overflow"), 
 		      _("sh_util_hmac_tiger"));
-      res = sh_tiger_hash (NULL, TIGER_DATA, 0, hashbuf, sizeof(hashbuf));
+      (void) sh_tiger_hash (NULL, TIGER_DATA, 0, hashbuf, sizeof(hashbuf));
+      sl_strlcpy(res, hashbuf, len);
       SL_RETURN(res, _("sh_util_hmac_tiger"));
     }
@@ -749,8 +751,10 @@
 
 static char * sh_util_hash_tiger ( char * hexkey,  
-				   char * text, size_t textlen
+				   char * text, size_t textlen,
 				   char * res, size_t len)
 {
   char           h2[2*KEY_LEN+1];
+  char hashbuf[KEYBUF_SIZE];
+
   SL_ENTER(_("sh_util_hash_tiger"));
 
@@ -760,5 +764,5 @@
 				  (unsigned long) textlen,
 				  hashbuf, sizeof(hashbuf)), 
-		    2*KEY_LEN+1,
+		    2*KEY_LEN+1
 		    );
 
@@ -917,6 +921,8 @@
   UINT32 * state = (UINT32 *) vstate;
 
+  /*
   if (skey->rngI == BAD)
     (void)taus_seed();
+  */
 
 #define TAUSWORTHE(s,a,b,c,d) ((s &c) <<d) ^ (((s <<a) ^s) >>b)
@@ -932,8 +938,8 @@
  * input for a one-way hash function.
  */
-UINT32   taus_svec[6];
-
-UINT32 taus_get (void *state1, void *state2, void *state3)
-{
+
+UINT32 taus_get ()
+{
+  UINT32   taus_svec[6];
   UINT32   retval;
   UINT32 * res;
@@ -943,17 +949,24 @@
   UINT32       kbuf[KEY_BYT/sizeof(UINT32)];
 
+  SH_MUTEX_LOCK_UNSAFE(mutex_skey);
   if (res_num > 0)
     {
       retval  = res_vec[res_num];
       res_num = (res_num == 5) ? 0 : (res_num + 1);
+      SH_MUTEX_UNLOCK_UNSAFE(mutex_skey); /* alternative path */
       return  retval;
     }
-
-  taus_svec[0] = taus_get_long (state1);
-  taus_svec[1] = taus_get_long (state2);
-  taus_svec[2] = taus_get_long (state3);
-  taus_svec[3] = taus_get_long (state1);
-  taus_svec[4] = taus_get_long (state2);
-  taus_svec[5] = taus_get_long (state3);
+  SH_MUTEX_UNLOCK_UNSAFE(mutex_skey);
+
+  (void)taus_seed();
+
+  SH_MUTEX_LOCK_UNSAFE(mutex_skey);
+  taus_svec[0] = taus_get_long (&(skey->rng0[0]));
+  taus_svec[1] = taus_get_long (&(skey->rng1[0]));
+  taus_svec[2] = taus_get_long (&(skey->rng2[2]));
+  taus_svec[3] = taus_get_long (&(skey->rng0[0]));
+  taus_svec[4] = taus_get_long (&(skey->rng1[0]));
+  taus_svec[5] = taus_get_long (&(skey->rng2[0]));
+  SH_MUTEX_UNLOCK_UNSAFE(mutex_skey);
 
   res     = sh_tiger_hash_uint32 ( (char *) &taus_svec[0], 
@@ -962,4 +975,5 @@
 				   kbuf, KEY_BYT/sizeof(UINT32));
 
+  SH_MUTEX_LOCK_UNSAFE(mutex_skey);
   for (i = 1; i < 6; ++i)
     { 
@@ -968,4 +982,5 @@
   retval  = taus_svec[0];
   res_num = 1;
+  SH_MUTEX_UNLOCK_UNSAFE(mutex_skey);
 
   taus_svec[0] = 0; taus_svec[1] = 0; taus_svec[2] = 0; 
@@ -1027,4 +1042,5 @@
   int                  status;
   static unsigned long seed_time = 0;
+  unsigned long        gtime;
 
   SL_ENTER(_("taus_seed"));
@@ -1032,5 +1048,5 @@
   if (skey->rngI == GOOD)
     {
-      if ( (sh_unix_longtime () - seed_time) < 3600)
+      if ( (sh_unix_longtime () - seed_time) < 7200)
 	SL_RETURN( (0), _("taus_seed"));
     }
@@ -1042,5 +1058,5 @@
   if (!SL_ISERROR(status))
     {
-      skey->rngI = GOOD;
+      SH_MUTEX_LOCK_UNSAFE(mutex_skey);
       memcpy (&skey->rng0[0], &bufx[0],                  2*sizeof(UINT32));
       memcpy (&skey->rng1[0], &bufx[2*sizeof(UINT32)],   2*sizeof(UINT32));
@@ -1056,4 +1072,6 @@
       taus_set_from_state( &(skey->rng2[0]), &(skey->rng2[0]));
 
+      skey->rngI = GOOD;
+      SH_MUTEX_UNLOCK_UNSAFE(mutex_skey);
       SL_RETURN( (0), _("taus_seed"));
     }
@@ -1064,13 +1082,16 @@
   /* emergency backup - unsafe !
    */
-  skey->rngI = GOOD;
 #ifdef HAVE_GETTIMEOFDAY
-  taus_set_from_ulong ( &(skey->rng0[0]), LCG (sh_unix_notime())      );
+  gtime = sh_unix_notime();
 #else
-  taus_set_from_ulong ( &(skey->rng0[0]), LCG (seed_time)      );
+  gtime = seed_time;
 #endif
+
+  SH_MUTEX_LOCK_UNSAFE(mutex_skey);
+  taus_set_from_ulong ( &(skey->rng0[0]), LCG (gtime)          );
   taus_set_from_ulong ( &(skey->rng1[0]), LCG (skey->rng0[0])  );
   taus_set_from_ulong ( &(skey->rng2[0]), LCG (skey->rng1[0])  );
   skey->rngI = BAD;
+  SH_MUTEX_UNLOCK_UNSAFE(mutex_skey);
 
   SL_RETURN( (-1), _("taus_seed"));
Index: trunk/src/slib.c
===================================================================
--- trunk/src/slib.c	(revision 136)
+++ trunk/src/slib.c	(revision 137)
@@ -1466,6 +1466,4 @@
 int sl_policy_get_user(char * user)
 {
-  struct passwd * tempres;
-
   SL_ENTER(_("sl_policy_get_user"));
 
@@ -2126,5 +2124,5 @@
 			int timeout, int is_nonblocking)
 {
-  int sflags;
+  int sflags = 0;
   fd_set readfds;
   struct timeval tv;
@@ -2132,5 +2130,4 @@
   int retval;
 
-  int    fd;
   int    byteread = 0;
   int    bytes    = 0;
Index: trunk/src/trustfile.c
===================================================================
--- trunk/src/trustfile.c	(revision 136)
+++ trunk/src/trustfile.c	(revision 137)
@@ -103,6 +103,5 @@
 #define SH_NEED_PWD_GRP 1
 #include "sh_static.h"
-#define SH_GRBUF_SIZE 4096
-#define SH_PWBUF_SIZE 4096
+#include "sh_pthread.h"
 
 #else
@@ -411,8 +410,8 @@
 int isingrp(gid_t grp, uid_t *ulist)
 {
-  register struct passwd *w;	/* info about group member */
+  struct passwd *w;	        /* info about group member */
   register uid_t *u;		/* points to current ulist member */
   register char **p;		/* points to current group member */
-  register struct group *g;	/* pointer to group information */
+  struct group *g;	        /* pointer to group information */
   
 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R)
@@ -494,8 +493,8 @@
 int onlytrustedingrp(gid_t grp, uid_t *ulist)
 {
-  register struct passwd *w;	/* info about group member */
+  struct passwd *w;	        /* info about group member */
   register uid_t *u;		/* points to current ulist member */
   register char **p;		/* points to current group member */
-  register struct group *g;	/* pointer to group information */
+  struct group *g;	        /* pointer to group information */
   register int flag = -1;       /* group member found */
 
@@ -503,5 +502,5 @@
   struct group    gr;
   char            buffer[SH_GRBUF_SIZE];
-  struct group    pw;
+  struct passwd   pw;
   char            pbuffer[SH_PWBUF_SIZE];
 #endif
