Index: trunk/configure.ac
===================================================================
--- trunk/configure.ac	(revision 131)
+++ trunk/configure.ac	(revision 132)
@@ -274,5 +274,5 @@
 	ttyname fchmod \
 	getsid getpriority getpgid statvfs \
-	fpathconf dirfd \
+	strerror_r \
 	getgrgid_r getpwnam_r getpwuid_r gmtime_r localtime_r rand_r readdir_r strtok_r
 )
Index: trunk/docs/TODO
===================================================================
--- trunk/docs/TODO	(revision 131)
+++ trunk/docs/TODO	(revision 132)
@@ -1,12 +1,13 @@
 
-sh_unix_time: not thread_safe (static buffer)
-sh_error_message: not thread_safe (static buffer)
+not thread-safe: checksum function (returns static memory),
+                 sh_util_siggen
+                 sh_util_hash_tiger
+                 sh_util_hmac_tiger
 
 check thread_safe sh_entropy
+check thread_safe rng
 
-lock NEED_LOCK
+lock globber
 
-globber
+lock sh_alloc/sh_free
 
-sh_alloc/sh_free
-
Index: trunk/include/samhain.h
===================================================================
--- trunk/include/samhain.h	(revision 131)
+++ trunk/include/samhain.h	(revision 132)
@@ -45,4 +45,5 @@
 #define SH_GRBUF_SIZE  4096
 #define SH_PWBUF_SIZE  4096
+#define SH_ERRBUF_SIZE   64
 
 /* Sizes for arrays (user, group, timestamp).
Index: trunk/include/sh_error.h
===================================================================
--- trunk/include/sh_error.h	(revision 131)
+++ trunk/include/sh_error.h	(revision 132)
@@ -176,5 +176,5 @@
 /* error messages
  */
-/*@owned@*/char * sh_error_message (int tellme);
+/*@owned@*/char * sh_error_message (int tellme, char * str, size_t len);
 
 /* switch on/off log to file temporarily
Index: trunk/include/sh_pthread.h
===================================================================
--- trunk/include/sh_pthread.h	(revision 131)
+++ trunk/include/sh_pthread.h	(revision 132)
@@ -23,4 +23,6 @@
 	} while (0)
 
+#define SH_MUTEX_LOCK_UNSAFE(M) pthread_mutex_lock(&(M))
+#define SH_MUTEX_UNLOCK_UNSAFE(M) pthread_mutex_unlock(&(M))
 
 #else
@@ -32,4 +34,6 @@
 #define SH_MUTEX_LOCK(M)			((void)0)
 #define SH_MUTEX_UNLOCK(M)			((void)0)
+#define SH_MUTEX_LOCK_UNSAFE(M)			((void)0)
+#define SH_MUTEX_UNLOCK_UNSAFE(M)		((void)0)
 
 /* #ifdef HAVE_PTHREAD */
Index: trunk/include/sh_tools.h
===================================================================
--- trunk/include/sh_tools.h	(revision 131)
+++ trunk/include/sh_tools.h	(revision 132)
@@ -16,7 +16,11 @@
 
 #ifdef SH_ENCRYPT
-char * errorExplain (int err_num);
+/* returns pointer to errbuf
+ */
+char * errorExplain (int err_num, char * errbuf, size_t len);
 #endif
 
+/* returns allocated buffer
+ */
 char * sh_tools_safe_name(const char * str, int flag);
 int is_numeric (const char * address);
@@ -26,5 +30,8 @@
 		    char * ecall, int * errnum, char * errmsg, int errsiz);
 void delete_cache(void);
-char * sh_tools_errmessage (int tellme);
+
+/* returns pointer to errbuf
+ */
+char * sh_tools_errmessage (int tellme, char * errbuf, size_t len);
 
 
@@ -41,8 +48,15 @@
 int check_request_nerr (char * have, char * need);
 
+/* returns allocated buffer
+ */
 char * hash_me (char * key, char * buf,   int buflen);
 int sh_tools_hash_vfy(char * key, char * buf, int buflen);
 
+/* returns allocated buffer
+ */
 char * get_client_conf_file (char * peer, unsigned long * length);
+
+/* returns allocated buffer
+ */
 char * get_client_data_file (char * peer, unsigned long * length);
 
Index: trunk/include/sh_unix.h
===================================================================
--- trunk/include/sh_unix.h	(revision 131)
+++ trunk/include/sh_unix.h	(revision 132)
@@ -291,11 +291,11 @@
 int  sh_unix_init(int goDaemon);
 
-/* for local time use thetime = 0 
- */
-/*@owned@*/ char * sh_unix_time (time_t thetime);
-
-/* convert to GMT time
- */
-char * sh_unix_gmttime (time_t thetime);
+/* for local time use thetime = 0, returns pointer to buffer 
+ */
+char * sh_unix_time (time_t thetime, char * buffer, size_t len);
+
+/* convert to GMT time, returns pointer to buffer
+ */
+char * sh_unix_gmttime (time_t thetime, char * buffer, size_t len);
 
 /* effective user info
@@ -303,7 +303,7 @@
 int  sh_unix_getUser (void);
 
-/* get home directory
- */
-char *  sh_unix_getUIDdir (int level, uid_t uid);
+/* get home directory, , returns pointer to out
+ */
+char *  sh_unix_getUIDdir (int level, uid_t uid, char * out, size_t len);
 
 
Index: trunk/include/sh_utils.h
===================================================================
--- trunk/include/sh_utils.h	(revision 131)
+++ trunk/include/sh_utils.h	(revision 132)
@@ -43,4 +43,6 @@
 } st_format;
 
+/* returns allocated string
+ */
 char * sh_util_formatted (const char * fmt, st_format * ftab);
 
@@ -60,9 +62,17 @@
 int    taus_seed           (void);
 
+/* returns allocated memory
+ */
 char * sh_util_strdup (const char * str);
+
+/* returns allocated memory
+ */
 char * sh_util_strdup_l (const char * str, size_t len);
+
+/* returns pointer within str
+ */
 char * sh_util_strsep (char **str, const char *delim);
 
-/* compactify verbose acl text
+/* compactify verbose acl text, returns allocated memory
  */
 char * sh_util_acl_compact (char * buf, ssize_t len);
@@ -146,5 +156,5 @@
 
 /* returns freshly allocated memory, return value should be free'd.
- * Arhument list must be NULL terminated.
+ * Argument list must be NULL terminated.
  */
 char * sh_util_strconcat (const char * arg1, ...) SH_GNUC_NULL_TERMINATED;
Index: trunk/src/sh_calls.c
===================================================================
--- trunk/src/sh_calls.c	(revision 131)
+++ trunk/src/sh_calls.c	(revision 132)
@@ -115,4 +115,5 @@
   int error;
   long int val_retry = -1;
+  char errbuf[SH_ERRBUF_SIZE];
   errno              = 0;
 
@@ -126,5 +127,5 @@
   if (val_retry < 0) {
       sh_error_handle ((-1), file, line, error, MSG_ERR_SIGACT, 
-		       sh_error_message(error),
+		       sh_error_message(error, errbuf, sizeof(errbuf)),
 		       (long) signum );
   }
@@ -161,4 +162,5 @@
   long int val_retry = 0;
   static struct sockaddr_in new_addr;
+  char errbuf[SH_ERRBUF_SIZE];
 
   SL_ENTER(_("retry_connect"));
@@ -189,5 +191,5 @@
      */
     sh_error_handle ((-1), file, line, error, MSG_ERR_CONNECT, 
-		     sh_error_message(error),
+		     sh_error_message(error, errbuf, sizeof(errbuf)),
 		     (long) sockfd,
 		     /*@-unrecog -type@*/
@@ -212,4 +214,6 @@
   int  error;
   long int val_retry = -1;
+  char errbuf[SH_ERRBUF_SIZE];
+
   ACCEPT_TYPE_ARG3 my_addrlen = (ACCEPT_TYPE_ARG3) *addrlen;
 
@@ -225,5 +229,5 @@
   if (val_retry < 0) {
       sh_error_handle ((-1), file, line, error, MSG_ERR_ACCEPT, 
-		       sh_error_message(error),
+		       sh_error_message(error, errbuf, sizeof(errbuf)),
 		       (long) fd );
   }
@@ -237,4 +241,5 @@
   int error;
   long int val_retry = -1;
+  char errbuf[SH_ERRBUF_SIZE];
  
   SL_ENTER(_("retry_lstat"));
@@ -245,7 +250,7 @@
   error = errno;
   if (val_retry < 0) {
-      (void) sl_strlcpy(aud_err_message, sh_error_message(error), 64);
+      (void) sl_strlcpy(aud_err_message, sh_error_message(error, errbuf, sizeof(errbuf)), 64);
       sh_error_handle ((-1), file, line, error, MSG_ERR_LSTAT, 
-		       sh_error_message(error),
+		       sh_error_message(error, errbuf, sizeof(errbuf)),
 		       file_name );
   }
@@ -259,4 +264,5 @@
   int error;
   long int val_retry = -1;
+  char errbuf[SH_ERRBUF_SIZE];
  
   SL_ENTER(_("retry_stat"));
@@ -267,7 +273,7 @@
   error = errno;
   if (val_retry < 0) {
-      (void) sl_strlcpy(aud_err_message, sh_error_message(error), 64);
+      (void) sl_strlcpy(aud_err_message, sh_error_message(error, errbuf, sizeof(errbuf)), 64);
       sh_error_handle ((-1), file, line, error, MSG_ERR_STAT, 
-		       sh_error_message(error),
+		       sh_error_message(error, errbuf, sizeof(errbuf)),
 		       file_name );
   }
@@ -280,4 +286,5 @@
   int error;
   long int val_retry = -1;
+  char errbuf[SH_ERRBUF_SIZE];
  
   SL_ENTER(_("retry_fstat"));
@@ -289,5 +296,5 @@
   if (val_retry < 0) {
       sh_error_handle ((-1), file, line, error, MSG_ERR_FSTAT, 
-		       sh_error_message(error),
+		       sh_error_message(error, errbuf, sizeof(errbuf)),
 		       (long) filed );
   }
@@ -300,4 +307,5 @@
   int error;
   long int val_retry = -1;
+  char errbuf[SH_ERRBUF_SIZE];
   errno              = 0;
 
@@ -319,5 +327,5 @@
   if (val_retry < 0) {
       sh_error_handle ((-1), file, line, error, MSG_ERR_FCNTL, 
-		       sh_error_message(error),
+		       sh_error_message(error, errbuf, sizeof(errbuf)),
 		       (long) fd, (long) cmd, arg );
   }
@@ -389,4 +397,5 @@
   int   i;
   int   error;
+  char errbuf[SH_ERRBUF_SIZE];
 
   SL_ENTER(_("retry_aud_execve"));
@@ -401,5 +410,6 @@
   error = errno;
   if (i < 0) {
-      sh_error_handle ((-1), file, line, error, MSG_ERR_EXEC, sh_error_message(error),
+      sh_error_handle ((-1), file, line, error, MSG_ERR_EXEC, 
+		       sh_error_message(error, errbuf, sizeof(errbuf)),
 		       dateiname, (long) a, (long) b );
   }
@@ -414,4 +424,5 @@
   long int val_return;
   int  error;
+  char errbuf[SH_ERRBUF_SIZE];
   errno      = 0;
 
@@ -430,5 +441,5 @@
   if (val_return < 0) {
       sh_error_handle ((-1), file, line, error, MSG_ERR_UTIME, 
-		       sh_error_message(error),
+		       sh_error_message(error, errbuf, sizeof(errbuf)),
 		       path, 
 		       (unsigned long) buf->actime, 
@@ -444,4 +455,5 @@
   long int val_return;
   int error;
+  char errbuf[SH_ERRBUF_SIZE];
   errno      = 0;
 
@@ -457,5 +469,6 @@
 		     path);
   if (val_return < 0) {
-      sh_error_handle ((-1), file, line, error, MSG_ERR_UNLINK, sh_error_message(error),
+      sh_error_handle ((-1), file, line, error, MSG_ERR_UNLINK, 
+		       sh_error_message(error, errbuf, sizeof(errbuf)),
 		       path);
   }
@@ -469,4 +482,5 @@
   long int val_return;
   int error;
+  char errbuf[SH_ERRBUF_SIZE];
   errno      = 0;
 
@@ -483,5 +497,5 @@
   if (val_return < 0) {
       sh_error_handle ((-1), file, line, error, MSG_ERR_DUP, 
-		       sh_error_message(error),
+		       sh_error_message(error, errbuf, sizeof(errbuf)),
 		       (long) fd, val_return);
   }
@@ -495,4 +509,5 @@
   long int val_return;
   int error;
+  char errbuf[SH_ERRBUF_SIZE];
   errno      = 0;
 
@@ -508,5 +523,5 @@
   if (val_return < 0) {
       sh_error_handle ((-1), file, line, error, MSG_ERR_DUP, 
-		       sh_error_message(error),
+		       sh_error_message(error, errbuf, sizeof(errbuf)),
 		       (long) fd, val_return);
   }
@@ -522,4 +537,5 @@
   long int val_return;
   int      error      = 0;
+  char errbuf[SH_ERRBUF_SIZE];
   errno      = 0;
 
@@ -535,5 +551,6 @@
 		     path);
   if (val_return < 0) {
-      sh_error_handle ((-1), file, line, error, MSG_ERR_CHDIR, sh_error_message(error),
+      sh_error_handle ((-1), file, line, error, MSG_ERR_CHDIR, 
+		       sh_error_message(error, errbuf, sizeof(errbuf)),
 		       path);
   }
@@ -549,4 +566,5 @@
   long int val_return;
   int error;
+  char errbuf[SH_ERRBUF_SIZE];
 
   SL_ENTER(_("aud_open"));
@@ -566,5 +584,5 @@
   if (val_return < 0)
     {
-      (void) sl_strlcpy(aud_err_message, sh_error_message(error), 64);
+      (void) sl_strlcpy(aud_err_message, sh_error_message(error, errbuf, sizeof(errbuf)), 64);
     }
 
@@ -576,5 +594,5 @@
   if (val_return < 0) {
     sh_error_handle ((-1), file, line, error, MSG_ERR_OPEN, 
-		     sh_error_message(error),
+		     sh_error_message(error, errbuf, sizeof(errbuf)),
 		     pathname, (long) flags, (long) mode, val_return);
   }
@@ -588,4 +606,5 @@
   long int val_return;
   int error;
+  char errbuf[SH_ERRBUF_SIZE];
 
   SL_ENTER(_("aud_open"));
@@ -599,5 +618,5 @@
   if (val_return < 0)
     {
-      (void) sl_strlcpy(aud_err_message, sh_error_message(error), 64);
+      (void) sl_strlcpy(aud_err_message, sh_error_message(error, errbuf, sizeof(errbuf)), 64);
     }
 
@@ -609,5 +628,5 @@
   if (val_return < 0) {
     sh_error_handle ((-1), file, line, error, MSG_ERR_OPEN, 
-		     sh_error_message(error),
+		     sh_error_message(error, errbuf, sizeof(errbuf)),
 		     pathname, (long) flags, (long) mode, val_return);
   }
@@ -620,4 +639,5 @@
   int  myerror;
   long int val_return = kill (pid, sig);
+  char errbuf[SH_ERRBUF_SIZE];
   myerror = errno;
 
@@ -629,5 +649,5 @@
   if (val_return < 0) {
       sh_error_handle ((-1), file, line, myerror, MSG_ERR_KILL, 
-		       sh_error_message(myerror),
+		       sh_error_message(myerror, errbuf, sizeof(errbuf)),
 		       (long) pid, (long) sig);
   }
@@ -666,4 +686,5 @@
   int error;
   pid_t i = fork();
+  char errbuf[SH_ERRBUF_SIZE];
 
   error = errno;
@@ -675,5 +696,5 @@
   if (i == (pid_t) -1) {
     sh_error_handle ((-1), file, line, error, MSG_ERR_FORK, 
-		     sh_error_message(error),
+		     sh_error_message(error, errbuf, sizeof(errbuf)),
 		     (long) i);
   }
@@ -686,4 +707,5 @@
   int error = 0;
   int i = 0;
+  char errbuf[SH_ERRBUF_SIZE];
 
   SL_ENTER(_("aud_setuid"));
@@ -702,5 +724,5 @@
   if (i < 0) {
     sh_error_handle ((-1), file, line, error, MSG_ERR_SETUID, 
-		     sh_error_message(error),
+		     sh_error_message(error, errbuf, sizeof(errbuf)),
 		     (long) uid);
   }
@@ -713,4 +735,5 @@
   int error = 0;
   int i = 0;
+  char errbuf[SH_ERRBUF_SIZE];
 
   SL_ENTER(_("aud_setgid"));
@@ -730,5 +753,5 @@
   if (i < 0) {
     sh_error_handle ((-1), file, line, error, MSG_ERR_SETGID, 
-		     sh_error_message(error),
+		     sh_error_message(error, errbuf, sizeof(errbuf)),
 		     (long) gid);
   }
@@ -741,4 +764,5 @@
   int error;
   int i = pipe (modus);
+  char errbuf[SH_ERRBUF_SIZE];
 
   SL_ENTER(_("aud_pipe"));
@@ -761,5 +785,5 @@
     else
       sh_error_handle ((-1), file, line, error, MSG_ERR_PIPE, 
-		       sh_error_message(error),
+		       sh_error_message(error, errbuf, sizeof(errbuf)),
 		       (long) modus[0], (long) modus[1]);
   }
Index: trunk/src/sh_entropy.c
===================================================================
--- trunk/src/sh_entropy.c	(revision 131)
+++ trunk/src/sh_entropy.c	(revision 132)
@@ -645,4 +645,5 @@
     int retval;
     char msg[128];
+    char errbuf[SH_ERRBUF_SIZE];
 
     SL_ENTER(_("sh_pclose"));
@@ -653,5 +654,5 @@
 	sh_error_handle (SH_ERR_ALL, FIL__, __LINE__, retval, 
 			 MSG_E_SUBGEN,
-			 sh_error_message(retval),
+			 sh_error_message(retval, errbuf, sizeof(errbuf)),
                          _("sh_pclose"));
 	SL_RETURN((-1), _("sh_pclose"));
@@ -663,5 +664,5 @@
 	sh_error_handle (SH_ERR_ALL, FIL__, __LINE__, retval, 
 			 MSG_E_SUBGEN,
-			 sh_error_message(retval),
+			 sh_error_message(retval, errbuf, sizeof(errbuf)),
                          _("sh_pclose"));
 
@@ -707,5 +708,6 @@
   int    maxFD = 0;
   int    imax, selcount;
-
+  char errbuf[SH_ERRBUF_SIZE];
+  
   SL_ENTER(_("sh_entropy"));
 
@@ -738,5 +740,5 @@
     {
       sh_error_handle((-1), FIL__, __LINE__, caperr, MSG_E_SUBGEN,
-		      sh_error_message (caperr), 
+		      sh_error_message (caperr, errbuf, sizeof(errbuf)), 
 		      _("sl_get_cap_sub"));
     }
@@ -876,5 +878,5 @@
     {
       sh_error_handle((-1), FIL__, __LINE__, caperr, MSG_E_SUBGEN,
-		      sh_error_message (caperr), 
+		      sh_error_message (caperr, errbuf, sizeof(errbuf)), 
 		      _("sl_drop_cap_sub"));
     }
Index: trunk/src/sh_err_console.c
===================================================================
--- trunk/src/sh_err_console.c	(revision 131)
+++ trunk/src/sh_err_console.c	(revision 132)
@@ -70,4 +70,5 @@
   key_t            key;
   int              error;
+  char errbuf[SH_ERRBUF_SIZE];
 
   SL_ENTER(_("open_ipc"));
@@ -80,5 +81,5 @@
       error = errno;
       TPT(( 0, FIL__, __LINE__, _("msg=<ftok: %s> errno=<%d>\n"), 
-	    sh_error_message(error), error));
+	    sh_error_message(error, errbuf, sizeof(errbuf)), error));
       SL_RETURN(-1, _("open_ipc"));
     }
@@ -92,5 +93,5 @@
       error = errno;
       TPT(( 0, FIL__, __LINE__, _("msg=<msgget: %s> errno=<%d>\n"), 
-	    sh_error_message(error), error));
+	    sh_error_message(error, errbuf, sizeof(errbuf)), error));
       SL_RETURN(-1, _("open_ipc"));
     }
@@ -131,4 +132,5 @@
   int              error;
   int              count    = 0;
+  char errbuf[SH_ERRBUF_SIZE];
 
   SL_ENTER(_("push_message_queue"));
@@ -201,5 +203,5 @@
 	  error = errno;
 	  TPT(( 0, FIL__, __LINE__, _("msg=<msgsnd: %s> errno=<%d>\n"), 
-		sh_error_message(error), error));
+		sh_error_message(error, errbuf, sizeof(errbuf)), error));
 	  SH_FREE(recv_msg);
 	  SL_RETURN(-1, _("push_message_queue"));
Index: trunk/src/sh_err_log.c
===================================================================
--- trunk/src/sh_err_log.c	(revision 131)
+++ trunk/src/sh_err_log.c	(revision 132)
@@ -885,5 +885,5 @@
       /* Send out the key.
        */
-      (void) sl_strlcpy(log_msg.timestamp, sh_unix_time(0), KEY_LEN+1); 
+      (void) sh_unix_time(0, log_msg.timestamp, KEY_LEN+1); 
 
       store1               = errFlags.loglevel;
Index: trunk/src/sh_error.c
===================================================================
--- trunk/src/sh_error.c	(revision 131)
+++ trunk/src/sh_error.c	(revision 132)
@@ -20,8 +20,11 @@
 #include "config_xor.h"
 
+/* required on linux to get the correct strerror_r function
+ */
+#define _XOPEN_SOURCE 600
+#include <string.h>
 #include <stdio.h>     
 #include <stdlib.h>     
 #include <stdarg.h>
-#include <string.h>
 #include <ctype.h>
 #include <limits.h>
@@ -335,92 +338,99 @@
 
 
-/*@owned@*/char * sh_error_message (int tellme)
-{
-
-#if defined(HAVE_STRERROR)
-  /*@i@*/return strerror(tellme);
+char * sh_error_message (int tellme, char * str, size_t len)
+{
+
+#if defined(HAVE_STRERROR_R)
+  strerror_r(tellme, str, len);
+  return str;
+#elif defined(HAVE_STRERROR)
+  sl_strlcpy(str, strerror(tellme), len);
+  return str;
 #else
 
+  char *p = NULL;
 #ifdef EACCES
-    if (tellme == EACCES)  return _("Permission denied.");
+    if (tellme == EACCES)  p = _("Permission denied.");
 #endif
 #ifdef EAGAIN
-    if (tellme == EAGAIN)  return _("Try again.");
+    if (tellme == EAGAIN)  p = _("Try again.");
 #endif
 #ifdef EBADF
-    if (tellme == EBADF)   return _("File descriptor in bad state.");
+    if (tellme == EBADF)   p = _("File descriptor in bad state.");
 #endif
 #ifdef EEXIST
-    if (tellme == EEXIST)  return _("File exists.");
+    if (tellme == EEXIST)  p = _("File exists.");
 #endif
 #ifdef EFAULT
-    if (tellme == EFAULT)  return _("Bad address.");
+    if (tellme == EFAULT)  p = _("Bad address.");
 #endif
 #ifdef EINVAL
-    if (tellme == EINVAL)  return _("Invalid argument.");
+    if (tellme == EINVAL)  p = _("Invalid argument.");
 #endif
 #ifdef EISDIR
-    if (tellme == EISDIR)  return _("Is a directory.");
+    if (tellme == EISDIR)  p = _("Is a directory.");
 #endif
 #ifdef EINTR
-    if (tellme == EINTR)   return _("System call was interrupted.");
+    if (tellme == EINTR)   p = _("System call was interrupted.");
 #endif
 #ifdef EIO
-    if (tellme == EIO)     return _("Low-level I/O error.");
+    if (tellme == EIO)     p = _("Low-level I/O error.");
 #endif
 #ifdef ELOOP
-    if (tellme == ELOOP)   return _("Too many symbolic links encountered.");
+    if (tellme == ELOOP)   p = _("Too many symbolic links encountered.");
 #endif
 #ifdef EMFILE
-    if (tellme == EMFILE)  return _("Too many open files.");
+    if (tellme == EMFILE)  p = _("Too many open files.");
 #endif
 #ifdef EMLINK
-    if (tellme == EMLINK)  return _("Too many links.");
+    if (tellme == EMLINK)  p = _("Too many links.");
 #endif
 #ifdef ENAMETOOLONG
     if (tellme == ENAMETOOLONG) 
-                           return _("File name too long."); 
+                           p = _("File name too long."); 
 #endif
 #ifdef ENFILE
-    if (tellme == ENFILE)  return _("File table overflow.");
+    if (tellme == ENFILE)  p = _("File table overflow.");
 #endif
 #ifdef ENOENT
-    if (tellme == ENOENT)  return _("File does not exist.");
+    if (tellme == ENOENT)  p = _("File does not exist.");
 #endif
 #ifdef ENOMEM
-    if (tellme == ENOMEM)  return _("Out of memory.");
+    if (tellme == ENOMEM)  p = _("Out of memory.");
 #endif
 #ifdef ENOSPC
-    if (tellme == ENOSPC)  return _("No space on device.");
+    if (tellme == ENOSPC)  p = _("No space on device.");
 #endif
 #ifdef ENOTDIR
-    if (tellme == ENOTDIR) return _("Not a directory.");
+    if (tellme == ENOTDIR) p = _("Not a directory.");
 #endif
 #ifdef ENOTSOCK
-    if (tellme == ENOTSOCK) return _("Not a socket.");
+    if (tellme == ENOTSOCK) p = _("Not a socket.");
 #endif
 #ifdef EOPNOTSUPP
-    if (tellme == EOPNOTSUPP) return _("Socket is not of type SOCK_STREAM.");
+    if (tellme == EOPNOTSUPP) p = _("Socket is not of type SOCK_STREAM.");
 #endif
 #ifdef EPERM
-    if (tellme == EPERM)   return _("Permission denied.");
+    if (tellme == EPERM)   p = _("Permission denied.");
 #endif
 #ifdef EPIPE
-    if (tellme == EPIPE)   return _("No read on pipe.");
+    if (tellme == EPIPE)   p = _("No read on pipe.");
 #endif
 #ifdef EROFS
-    if (tellme == EROFS)    return _("Read-only file system.");
+    if (tellme == EROFS)    p = _("Read-only file system.");
 #endif
 #ifdef ETXTBSY
-    if (tellme == ETXTBSY) return _("Text file busy.");
+    if (tellme == ETXTBSY) p = _("Text file busy.");
 #endif
 #ifdef EWOULDBLOCK
     if (tellme == EWOULDBLOCK) 
-      return _("No connections on non-blocking socket.");
+      p = _("No connections on non-blocking socket.");
 #endif
 #ifdef EXDEV
-    if (tellme == EXDEV)    return _("Not on same file system.");
-#endif
-    return _("Unknown error");
+    if (tellme == EXDEV)    p = _("Not on same file system.");
+#endif
+    if (!p) p = _("Unknown error");
+    sl_strlcpy(str, p, len);
+    return str;
 #endif /* ifndef HAVE_STRERROR */
 }
@@ -1477,5 +1487,5 @@
   }
 
-  (void) sl_strlcpy (tst, sh_unix_time (0), 64);
+  (void) sh_unix_time (0, tst, 64);
   line = (unsigned long) lmsg->line;
   (void) sl_strlcpy (cla, _(class_cat[lmsg->class]), 11);
Index: trunk/src/sh_extern.c
===================================================================
--- trunk/src/sh_extern.c	(revision 131)
+++ trunk/src/sh_extern.c	(revision 132)
@@ -118,4 +118,5 @@
 
   char * errfile;
+  char errbuf[SH_ERRBUF_SIZE];
 
   static int some_error = 0;
@@ -213,5 +214,5 @@
       errnum = errno;
       sh_error_handle((-1), FIL__, __LINE__, errnum, MSG_E_SUBGEN, 
-		      sh_error_message(errnum), _("pipe"));
+		      sh_error_message(errnum, errbuf, sizeof(errbuf)), _("pipe"));
       SL_RETURN ((-1), _("sh_ext_popen"));
     }
@@ -235,5 +236,5 @@
       errnum = errno;
       sh_error_handle((-1), FIL__, __LINE__, errnum, MSG_E_SUBGEN, 
-		      sh_error_message(errnum), _("fork"));
+		      sh_error_message(errnum, errbuf, sizeof(errbuf)), _("fork"));
       SL_RETURN ((-1), _("sh_ext_popen"));
     }
@@ -1103,4 +1104,5 @@
   char * p = NULL;
   int    i;
+  char   dir[SH_PATHBUF];
 
   SL_ENTER(_("sh_ext_add_default"));
@@ -1110,5 +1112,6 @@
       SL_RETURN(0, _("sh_ext_add_default"));
     }
-  p = sh_unix_getUIDdir (SH_ERR_ERR, (uid_t) ext_coms->tas.run_user_uid);
+  p = sh_unix_getUIDdir (SH_ERR_ERR, (uid_t) ext_coms->tas.run_user_uid, 
+			 dir, sizeof(dir));
   if (p)
     (void) sh_ext_add_envv (_("HOME"), p);
@@ -1325,4 +1328,5 @@
   int        status = 0;
   char     * tmp;
+  char errbuf[SH_ERRBUF_SIZE];
 
   static  int some_error = 0;
@@ -1364,5 +1368,5 @@
 	    {
 	      sh_error_handle((-1), FIL__, __LINE__, caperr, MSG_E_SUBGEN,
-			      sh_error_message (caperr), 
+			      sh_error_message (caperr, errbuf, sizeof(errbuf)), 
 			      _("sl_get_cap_sub"));
 	    }
@@ -1443,5 +1447,5 @@
 	    {
 	      sh_error_handle((-1), FIL__, __LINE__, caperr, MSG_E_SUBGEN,
-			      sh_error_message (caperr), 
+			      sh_error_message (caperr, errbuf, sizeof(errbuf)), 
 			      _("sl_drop_cap_sub"));
 	    }
Index: trunk/src/sh_files.c
===================================================================
--- trunk/src/sh_files.c	(revision 131)
+++ trunk/src/sh_files.c	(revision 132)
@@ -721,4 +721,5 @@
 {
   char * p;
+  char errbuf[SH_ERRBUF_SIZE];
 
   SL_ENTER(_("sh_files_globerr"));
@@ -731,5 +732,5 @@
   p = sh_util_safe_name (epath);
   sh_error_handle (SH_ERR_ERR, FIL__, __LINE__, errnum, MSG_FI_GLOB,
-		   sh_error_message (errnum), p);
+		   sh_error_message (errnum, errbuf, sizeof(errbuf)), p);
   SH_FREE(p);
 
@@ -1491,4 +1492,5 @@
   char          * tmpname;
   char          * tmpcat;
+  char errbuf[SH_ERRBUF_SIZE];
 
   int             rdepth = 0;
@@ -1611,5 +1613,5 @@
       sh_error_handle (ShDFLevel[SH_ERR_T_DIR], FIL__, __LINE__, 0, 
 		       MSG_E_OPENDIR,
-		       sh_error_message (status), tmpname);
+		       sh_error_message (status, errbuf, sizeof(errbuf)), tmpname);
       SH_FREE(tmpname); 
 
Index: trunk/src/sh_forward.c
===================================================================
--- trunk/src/sh_forward.c	(revision 131)
+++ trunk/src/sh_forward.c	(revision 132)
@@ -386,4 +386,5 @@
   cipherInstance          cipherInst;
   int                     err_num;
+  char expbuf[SH_ERRBUF_SIZE];
 #else
   docrypt = SL_FALSE; /* dummy to fix compiler warning */
@@ -422,5 +423,5 @@
       if (err_num < 0)
 	sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-			errorExplain(err_num), 
+			errorExplain(err_num, expbuf, sizeof(expbuf)), 
 			_("sh_forward_send_intern: cipherInit"));
 
@@ -433,5 +434,5 @@
 	  if (err_num < 0)
 	    sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-			    errorExplain(err_num), 
+			    errorExplain(err_num, expbuf, sizeof(expbuf)), 
 			    _("sh_forward_send_intern: blockEncrypt"));
 	  memcpy(q, outBlock, B_SIZ);
@@ -447,5 +448,5 @@
 	  if (err_num < 0)
 	    sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-			    errorExplain(err_num), 
+			    errorExplain(err_num, expbuf, sizeof(expbuf)), 
 			    _("sh_forward_send_intern: blockEncrypt"));
 	  memcpy(q, outBlock, B_SIZ);
@@ -549,4 +550,5 @@
   cipherInstance          cipherInst;
   int                     err_num;
+  char expbuf[SH_ERRBUF_SIZE];
 #else
   docrypt = SL_FALSE; /* dummy to fix compiler warning */
@@ -655,5 +657,5 @@
       if (err_num < 0)
 	sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-			errorExplain(err_num), 
+			errorExplain(err_num, expbuf, sizeof(expbuf)), 
 			_("sh_forward_receive_intern: cipherInit"));
 
@@ -668,5 +670,5 @@
 	  if (err_num < 0)
 	    sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-			    errorExplain(err_num), 
+			    errorExplain(err_num, expbuf, sizeof(expbuf)), 
 			    _("sh_forward_receive_intern: blockDecrypt"));
 	  memcpy(q, outBlock, B_SIZ);
@@ -881,4 +883,5 @@
 #ifdef SH_ENCRYPT
   int err_num;
+  char expbuf[SH_ERRBUF_SIZE];
 #endif
 
@@ -1053,5 +1056,5 @@
 	  if (err_num < 0)
 	    sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-			    errorExplain(err_num), 
+			    errorExplain(err_num, expbuf, sizeof(expbuf)), 
 			    _("sh_forward_try_impl: makeKey"));
 
@@ -1060,5 +1063,5 @@
 	  if (err_num < 0)
 	    sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-			    errorExplain(err_num), 
+			    errorExplain(err_num, expbuf, sizeof(expbuf)), 
 			    _("sh_forward_try_impl: make_key"));
 #endif
@@ -1233,5 +1236,5 @@
 				sh_error_handle((-1), FIL__, __LINE__, -1, 
 						MSG_E_SUBGEN,
-						errorExplain(err_num), 
+						errorExplain(err_num, expbuf, sizeof(expbuf)), 
 						_("sh_forward_try_impl: makeKey"));
 			      err_num = makeKey(&(skey->keyInstD), 
@@ -1241,5 +1244,5 @@
 				sh_error_handle((-1), FIL__, __LINE__, -1, 
 						MSG_E_SUBGEN,
-						errorExplain(err_num), 
+						errorExplain(err_num, expbuf, sizeof(expbuf)), 
 						_("sh_forward_try_impl: makeKey"));
 #endif
@@ -1741,10 +1744,11 @@
   if (flag_err != 0)
     {
+      char errbuf[SH_ERRBUF_SIZE];
       conn_state = BAD;
       timeout_val *= 2;
-      if (flag_err < 0 || NULL == sh_error_message(flag_err))
+      if (flag_err < 0 || NULL == sh_error_message(flag_err, errbuf, sizeof(errbuf)))
 	flag_err = EIO;
       sh_error_handle((-1), FIL__, __LINE__, flag_err, MSG_TCP_ECONN,
-		      sh_error_message(flag_err));
+		      sh_error_message(flag_err, errbuf, sizeof(errbuf)));
       SL_RETURN( (-1), _("sh_forward_try_impl"));
     }
@@ -2053,5 +2057,5 @@
       for (i = 0; i < CLT_MAX; ++i) 
 	newclt->status_arr[i] = CLT_INACTIVE;
-      sl_strlcpy(newclt->timestamp[CLT_INACTIVE],   sh_unix_time(0), TIM_MAX);
+      (void) sh_unix_time(0, newclt->timestamp[CLT_INACTIVE], TIM_MAX);
       /* truncate */
       sl_strlcpy(newclt->hostname,  &str[0],        sep[0]+1);
@@ -2257,4 +2261,5 @@
   cipherInstance          cipherInst;
   int                     err_num;
+  char expbuf[SH_ERRBUF_SIZE];
 #else
   (void) docrypt;
@@ -2329,5 +2334,5 @@
       if (err_num < 0)
 	sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-			errorExplain(err_num), 
+			errorExplain(err_num, expbuf, sizeof(expbuf)), 
 			_("sh_forward_prep_send_int: cipherInit"));
 
@@ -2339,5 +2344,5 @@
 	  if (err_num < 0)
 	    sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-			    errorExplain(err_num), 
+			    errorExplain(err_num, expbuf, sizeof(expbuf)), 
 			    _("sh_forward_prep_send_int: blockEncrypt"));
 	  memcpy(q, outBlock, B_SIZ);
@@ -2355,5 +2360,5 @@
 	  if (err_num < 0)
 	    sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-			    errorExplain(err_num), 
+			    errorExplain(err_num, expbuf, sizeof(expbuf)), 
 			    _("sh_forward_prep_send_int: blockEncrypt"));
 	  memcpy(q, outBlock, B_SIZ);
@@ -2438,7 +2443,5 @@
   conn->status_now = status;
   conn->status_arr[status] = status;
-  sl_strlcpy(conn->timestamp[status],
-	     sh_unix_time(0), 
-	     TIM_MAX);
+  (void) sh_unix_time(0, conn->timestamp[status], TIM_MAX);
 
 #if defined(WITH_EXTERNAL)
@@ -2806,4 +2809,5 @@
   int        send_bytes;
   int        err_num;
+  char expbuf[SH_ERRBUF_SIZE];
 #endif
 
@@ -3880,5 +3884,5 @@
 	       if (err_num < 0)
 		 sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-				 errorExplain(err_num), 
+				 errorExplain(err_num, expbuf, sizeof(expbuf)), 
 				 _("check_protocol: makeKey"));
 	       err_num = makeKey(&(conn->client_entry->keyInstD), 
@@ -3887,5 +3891,5 @@
 	       if (err_num < 0)
 		 sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-				 errorExplain(err_num), 
+				 errorExplain(err_num, expbuf, sizeof(expbuf)), 
 				 _("check_protocol: makeKey"));
 #endif
@@ -4211,5 +4215,5 @@
 		  if (err_num < 0)
 		    sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-				    errorExplain(err_num), 
+				    errorExplain(err_num, expbuf, sizeof(expbuf)), 
 				    _("sh_forward_prep_send_int: makeKey"));
 		  err_num = makeKey(&(conn->client_entry->keyInstD), 
@@ -4218,5 +4222,5 @@
 		  if (err_num < 0)
 		    sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-				    errorExplain(err_num), 
+				    errorExplain(err_num, expbuf, sizeof(expbuf)), 
 				    _("sh_forward_prep_send_int: makeKey"));
 #endif
@@ -4312,4 +4316,5 @@
   cipherInstance          cipherInst;
   int                     err_num;
+  char expbuf[SH_ERRBUF_SIZE];
 #endif
 
@@ -4410,5 +4415,5 @@
 		  if (err_num < 0)
 		    sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-				    errorExplain(err_num), 
+				    errorExplain(err_num, expbuf, sizeof(expbuf)), 
 				    _("sh_forward_do_read: cipherInit"));
 
@@ -4422,5 +4427,5 @@
 			sh_error_handle((-1), FIL__, __LINE__, -1, 
 					MSG_E_SUBGEN,
-					errorExplain(err_num), 
+					errorExplain(err_num, expbuf, sizeof(expbuf)), 
 					_("sh_forward_do_read: blockDecrypt"));
 		      memcpy(q, outBlock, B_SIZ);
@@ -4650,7 +4655,8 @@
   else
     {
+      char err_buf[SH_ERRBUF_SIZE];
       errflag = errno;
       sh_error_handle((-1), FIL__, __LINE__, 0, MSG_E_SUBGEN,
-		      sh_error_message(errflag), _("accept"));
+		      sh_error_message(errflag,err_buf, sizeof(err_buf)), _("accept"));
       newconn->fd    = -1;
       newconn->state = CONN_FREE;
@@ -4732,4 +4738,6 @@
 int sh_forward_printerr_final(int slot)
 {
+  char errbuf[SH_ERRBUF_SIZE];
+
   SL_ENTER(_("sh_forward_printerr_final"));
   if (sock_err[slot].msg[0] != '\0')
@@ -4737,9 +4745,10 @@
       dlog(1, FIL__, __LINE__, 
 	   _("Could not set up the listening socket for the server because of the\nfollowing error: %s\nPossible reasons include:\n - insufficient privilege for UID %d, or\n - the port %d is already used by another program.\n"),
-	   sh_error_message(sock_err[slot].errnum), sock_err[slot].euid, 
+	   sh_error_message(sock_err[slot].errnum, errbuf, sizeof(errbuf)), 
+	   sock_err[slot].euid, 
 	   sock_err[slot].port);
       sh_error_handle((-1), FIL__, sock_err[slot].line, 
 		      sock_err[slot].errnum, MSG_EXIT_ABORTS,
-		      sh_error_message(sock_err[slot].errnum),
+		      sh_error_message(sock_err[slot].errnum, errbuf, sizeof(errbuf)),
 		      sh.prg_name,
 		      sock_err[slot].msg);
@@ -5180,4 +5189,6 @@
       if ( num_sel < 0 )        /* some error             */
 	{
+	  char errbuf[SH_ERRBUF_SIZE];
+
 	  if (sig_raised == 1)
 	    {
@@ -5207,5 +5218,5 @@
 
 	  sh_error_handle((-1), FIL__, __LINE__, errnum, MSG_EXIT_ABORTS,
-			  sh_error_message(errnum), 
+			  sh_error_message(errnum, errbuf, sizeof(errbuf)), 
 			  sh.prg_name,
 			  _("select"));
@@ -5535,4 +5546,5 @@
   char               buf[1048];
   struct sockaddr_in from;
+  char errbuf[SH_ERRBUF_SIZE];
 
   /* The 6th argument in recvfrom is *socklen_t in Linux and *BSD, 
@@ -5575,5 +5587,6 @@
 	  TPT(( 0, FIL__, __LINE__, _("msg=<UDP error: %d>\n"), res));
 	  sh_error_handle((-1), FIL__, __LINE__, res, MSG_ERR_SYSLOG,
-			  sh_error_message(res), my_inet_ntoa(from.sin_addr));
+			  sh_error_message(res, errbuf, sizeof(errbuf)), 
+			  my_inet_ntoa(from.sin_addr));
 	  SL_RETURN( (-1), _("recv_syslog_socket"));
 	}      
@@ -5634,5 +5647,6 @@
       TPT(( 0, FIL__, __LINE__, _("msg=<UDP error: %d>\n"), res));
       sh_error_handle((-1), FIL__, __LINE__, res, MSG_ERR_SYSLOG,
-		      sh_error_message(res), my_inet_ntoa(from.sin_addr));
+		      sh_error_message(res, errbuf, sizeof(errbuf)), 
+		      my_inet_ntoa(from.sin_addr));
 
       /* don't accept anything the next 2 seconds
Index: trunk/src/sh_gpg.c
===================================================================
--- trunk/src/sh_gpg.c	(revision 131)
+++ trunk/src/sh_gpg.c	(revision 132)
@@ -660,7 +660,9 @@
   if (0 != retry_lstat(FIL__, __LINE__, DEFAULT_GPG_PATH, &buf))
     {
+      char errbuf[SH_ERRBUF_SIZE];
+
       status = errno;
       sh_error_handle(SH_ERR_ERR, FIL__, __LINE__, status, MSG_ERR_LSTAT,
-		      sh_error_message(status), DEFAULT_GPG_PATH);
+		      sh_error_message(status, errbuf, sizeof(errbuf)), DEFAULT_GPG_PATH);
       SL_RETURN( SH_GPG_BAD, _("sh_gpg_check_file_sign"));
     }
@@ -690,7 +692,9 @@
   if (0 != retry_lstat(FIL__, __LINE__, DEFAULT_PGP_PATH, &buf))
     {
+      char errbuf[SH_ERRBUF_SIZE];
+
       status = errno;
       sh_error_handle(SH_ERR_ERR, FIL__, __LINE__, status, MSG_ERR_LSTAT,
-		      sh_error_message(status), DEFAULT_PGP_PATH);
+		      sh_error_message(status, errbuf, sizeof(errbuf)), DEFAULT_PGP_PATH);
       SL_RETURN( SH_GPG_BAD, _("sh_gpg_check_file_sign"));
     }
Index: trunk/src/sh_hash.c
===================================================================
--- trunk/src/sh_hash.c	(revision 131)
+++ trunk/src/sh_hash.c	(revision 132)
@@ -1404,5 +1404,4 @@
 
   char   timestring[81];
-  char * timep;
 
 #if !defined(__linux__) && !defined(HAVE_STAT_FLAGS)
@@ -1706,6 +1705,5 @@
 			    sl_strlen(sh_db_version_string));
 		  sl_write (pushdata_fd, _(" Date "), 6);
-		  timep = sh_unix_time(0);
-		  sl_strlcpy(timestring, timep, sizeof(timestring));
+		  (void) sh_unix_time(0, timestring, sizeof(timestring));
 		  sl_write (pushdata_fd, timestring, sl_strlen(timestring));
 		  sl_write (pushdata_fd,        "\n", 1);
@@ -1716,6 +1714,5 @@
 		  printf ("%s", sh_db_version_string);
 		  printf (_(" Date "));
-		  timep = sh_unix_time(0);
-		  sl_strlcpy(timestring, timep, sizeof(timestring));
+		  (void) sh_unix_time(0, timestring, sizeof(timestring));
 		  printf ("%s\n", timestring);
 		}
@@ -2343,5 +2340,5 @@
 
 
-  sl_strlcpy (timstr1c, sh_unix_gmttime (theFile->ctime),   32);
+  (void) sh_unix_gmttime (theFile->ctime, timstr1c,  sizeof(timstr1c));
   if (is_new)
     sl_snprintf(tmp, SH_BUFSIZE, _("ctime_new=\"%s\" "), timstr1c);
@@ -2350,5 +2347,5 @@
   sl_strlcat(msg, tmp, SH_BUFSIZE); 
 
-  sl_strlcpy (timstr1a, sh_unix_gmttime (theFile->atime),   32);
+  (void) sh_unix_gmttime (theFile->atime, timstr1a,  sizeof(timstr1a));
   if (is_new)
     sl_snprintf(tmp, SH_BUFSIZE, _("atime_new=\"%s\" "), timstr1a);
@@ -2357,5 +2354,5 @@
   sl_strlcat(msg, tmp, SH_BUFSIZE); 
 
-  sl_strlcpy (timstr1m, sh_unix_gmttime (theFile->mtime),   32);
+  (void) sh_unix_gmttime (theFile->mtime, timstr1m,  sizeof(timstr1m));
   if (is_new)
     sl_snprintf(tmp, SH_BUFSIZE, _("mtime_new=\"%s\" "), timstr1m);
@@ -2509,5 +2506,5 @@
 
 
-  sl_strlcpy (timstr1c, sh_unix_gmttime (theFile->ctime),   32);
+  (void) sh_unix_gmttime (theFile->ctime, timstr1c,  sizeof(timstr1c));
   if (is_new)
     sl_snprintf(tmp, SH_BUFSIZE, _("ctime_new=<%s>, "), timstr1c);
@@ -2516,5 +2513,5 @@
   sl_strlcat(msg, tmp, SH_BUFSIZE); 
 
-  sl_strlcpy (timstr1a, sh_unix_gmttime (theFile->atime),   32);
+  (void) sh_unix_gmttime (theFile->atime, timstr1a,  sizeof(timstr1a));
   if (is_new)
     sl_snprintf(tmp, SH_BUFSIZE, _("atime_new=<%s>, "), timstr1a);
@@ -2523,5 +2520,5 @@
   sl_strlcat(msg, tmp, SH_BUFSIZE); 
 
-  sl_strlcpy (timstr1m, sh_unix_gmttime (theFile->mtime),   32);
+  (void) sh_unix_gmttime (theFile->mtime, timstr1m,  sizeof(timstr1m));
   if (is_new)
     sl_snprintf(tmp, SH_BUFSIZE, _("mtime_new=<%s>, "), timstr1m);
@@ -3145,6 +3142,6 @@
       if ((modi_mask & MODI_CTM) != 0)
 	{
-	  sl_strlcpy (timstr1c, sh_unix_gmttime (p->theFile.ctime), 32);
-	  sl_strlcpy (timstr2c, sh_unix_gmttime (theFile->ctime),   32);
+	  (void) sh_unix_gmttime (p->theFile.ctime, timstr1c, sizeof(timstr1c));
+	  (void) sh_unix_gmttime (theFile->ctime,   timstr2c, sizeof(timstr2c));
 #ifdef SH_USE_XML
 	  sl_snprintf(tmp, SH_BUFSIZE, _("ctime_old=\"%s\" ctime_new=\"%s\" "),
@@ -3163,6 +3160,6 @@
       if ((modi_mask & MODI_ATM) != 0)
 	{
-	  sl_strlcpy (timstr1a, sh_unix_gmttime (p->theFile.atime), 32);
-	  sl_strlcpy (timstr2a, sh_unix_gmttime (theFile->atime),   32);
+	  (void) sh_unix_gmttime (p->theFile.atime, timstr1a, sizeof(timstr1a));
+	  (void) sh_unix_gmttime (theFile->atime,   timstr2a, sizeof(timstr2a));
 #ifdef SH_USE_XML
 	  sl_snprintf(tmp, SH_BUFSIZE, _("atime_old=\"%s\" atime_new=\"%s\" "),
@@ -3181,6 +3178,6 @@
       if ((modi_mask & MODI_MTM) != 0)
 	{
-	  sl_strlcpy (timstr1m, sh_unix_gmttime (p->theFile.mtime), 32);
-	  sl_strlcpy (timstr2m, sh_unix_gmttime (theFile->mtime),   32);
+	  (void) sh_unix_gmttime (p->theFile.mtime, timstr1m, sizeof(timstr1m));
+	  (void) sh_unix_gmttime (theFile->mtime,   timstr2m, sizeof(timstr2m));
 #ifdef SH_USE_XML
 	  sl_snprintf(tmp, SH_BUFSIZE, _("mtime_old=\"%s\" mtime_new=\"%s\" "),
@@ -3579,7 +3576,7 @@
 
   if ('c' == p->theFile.c_mode[0] || 'b' == p->theFile.c_mode[0])
-    sl_snprintf(str, 80, "%"PRIu64, p->theFile.rdev);
-  else
-    sl_snprintf(str, 80, "%"PRIu64, p->theFile.size);
+    sl_snprintf(str, sizeof(str), "%"PRIu64, p->theFile.rdev);
+  else
+    sl_snprintf(str, sizeof(str), "%"PRIu64, p->theFile.size);
 
   printf( _(" %8s"), str);
@@ -3587,11 +3584,11 @@
     putchar(',');
 
-  printf( _(" %s"), sh_unix_gmttime (p->theFile.ctime));
+  printf( _(" %s"), sh_unix_gmttime (p->theFile.ctime, str, sizeof(str)));
   if (ListWithDelimiter == S_TRUE)
     putchar(',');
-  printf( _(" %s"), sh_unix_gmttime (p->theFile.mtime));
+  printf( _(" %s"), sh_unix_gmttime (p->theFile.mtime, str, sizeof(str)));
   if (ListWithDelimiter == S_TRUE)
     putchar(',');
-  printf( _(" %s"), sh_unix_gmttime (p->theFile.atime));
+  printf( _(" %s"), sh_unix_gmttime (p->theFile.atime, str, sizeof(str)));
   if (ListWithDelimiter == S_TRUE)
     putchar(',');
Index: trunk/src/sh_kern.c
===================================================================
--- trunk/src/sh_kern.c	(revision 131)
+++ trunk/src/sh_kern.c	(revision 132)
@@ -1222,6 +1222,6 @@
 	      if (mod_syscall_code != 0)
 		{
-		  sl_strlcpy (timstr_o, sh_unix_gmttime (ctime_old), 32);
-		  sl_strlcpy (timstr_n, sh_unix_gmttime (ctime_new), 32);
+		  (void) sh_unix_gmttime (ctime_old, timstr_o, sizeof(timstr_o));
+		  (void) sh_unix_gmttime (ctime_new, timstr_n, sizeof(timstr_n));
 #ifdef SH_USE_XML
 		  sl_snprintf(tmp, 128, 
@@ -1234,6 +1234,6 @@
 #endif
 		  sl_strlcat(msg, tmp, SH_BUFSIZE); 
-		  sl_strlcpy (timstr_o, sh_unix_gmttime (mtime_old), 32);
-		  sl_strlcpy (timstr_n, sh_unix_gmttime (mtime_new), 32);
+		  (void) sh_unix_gmttime (mtime_old, timstr_o, sizeof(timstr_o));
+		  (void) sh_unix_gmttime (mtime_new, timstr_n, sizeof(timstr_n));
 #ifdef SH_USE_XML
 		  sl_snprintf(tmp, 128, 
@@ -1693,6 +1693,6 @@
 		  sl_strlcpy(msg, tmp, SH_BUFSIZE);
 
-		  sl_strlcpy (timstr_o, sh_unix_gmttime (ctime_old), 32);
-		  sl_strlcpy (timstr_n, sh_unix_gmttime (ctime_new), 32);
+		  (void) sh_unix_gmttime (ctime_old, timstr_o, sizeof(timstr_o));
+		  (void) sh_unix_gmttime (ctime_new, timstr_n, sizeof(timstr_n));
 #ifdef SH_USE_XML
 		  sl_snprintf(tmp, 128, 
@@ -1705,6 +1705,6 @@
 #endif
 		  sl_strlcat(msg, tmp, SH_BUFSIZE); 
-		  sl_strlcpy (timstr_o, sh_unix_gmttime (mtime_old), 32);
-		  sl_strlcpy (timstr_n, sh_unix_gmttime (mtime_new), 32);
+		  (void) sh_unix_gmttime (mtime_old, timstr_o, sizeof(timstr_o));
+		  (void) sh_unix_gmttime (mtime_new, timstr_n, sizeof(timstr_n));
 #ifdef SH_USE_XML
 		  sl_snprintf(tmp, 128, 
Index: trunk/src/sh_mail.c
===================================================================
--- trunk/src/sh_mail.c	(revision 131)
+++ trunk/src/sh_mail.c	(revision 132)
@@ -810,4 +810,5 @@
     size_t    msgbufsize = SH_MAILBUF;
     size_t    combufsize = SH_MAILBUF;
+    char      timebuf[81];
 
     SL_ENTER(_("sh_mail_msg"));
@@ -887,5 +888,6 @@
       {
 	(void) sl_strlcpy(mheader, _("Subject: "),       sizeof(mheader)-5);
-	(void) sl_strlcat(mheader, sh_unix_time (0),     sizeof(mheader)-5);
+	(void) sl_strlcat(mheader, sh_unix_time (0, timebuf, sizeof(timebuf)),
+			  sizeof(mheader)-5);
 	(void) sl_strlcat(mheader, " ",                  sizeof(mheader)-5);
 	(void) sl_strlcat(mheader, sh.host.name,         sizeof(mheader)-5);
@@ -909,5 +911,6 @@
 	  {
 	    (void) sl_strlcpy(mheader, _("Subject: "),     sizeof(mheader)-5);
-	    (void) sl_strlcat(mheader, sh_unix_time (0),   sizeof(mheader)-5);
+	    (void) sl_strlcat(mheader, sh_unix_time (0, timebuf, sizeof(timebuf)),
+			      sizeof(mheader)-5);
 	    (void) sl_strlcat(mheader, " ",                sizeof(mheader)-5);
 	    (void) sl_strlcat(mheader, sh.host.name,       sizeof(mheader)-5);
@@ -921,5 +924,6 @@
     /* ---------- Message  --------------------------------------- */
 
-    (void) sl_strlcpy(subject, sh_unix_time (0),          sizeof(subject));
+    (void) sl_strlcpy(subject, sh_unix_time (0, timebuf, sizeof(timebuf)),
+		      sizeof(subject));
     (void) sl_strlcat(subject, " ",                       sizeof(subject));
     (void) sl_strlcat(subject, sh.host.name,              sizeof(subject));
@@ -1885,4 +1889,6 @@
   if (length < 1)
     {
+      char errbuf[SH_ERRBUF_SIZE];
+
       /* error handling
        */
@@ -1897,12 +1903,12 @@
 	  sh_error_handle (SH_ERR_ALL, FIL__, __LINE__, status, MSG_E_SUBGEN,
 			   (errno == ECONNREFUSED) ? 
-			   sh_error_message (status) : 
-			   sh_tools_errmessage(status),
+			   sh_error_message (status, errbuf, sizeof(errbuf)) : 
+			   sh_tools_errmessage(status, errbuf, sizeof(errbuf)),
 			   _("res_query"));
 #else
 	  if (errno == ECONNREFUSED)
-	    fprintf(stderr, " ERROR: %s: \n", strerror(errno));
+	    fprintf(stderr, " ERROR: %s: \n", strerror(errno)); /* TESTONLY */
 	  else
-	    fprintf(stderr, "HERROR: %s\n", hstrerror(h_errno));
+	    fprintf(stderr, "HERROR: %s\n", hstrerror(h_errno));/* TESTONLY */
 #endif
 	}
Index: trunk/src/sh_portcheck.c
===================================================================
--- trunk/src/sh_portcheck.c	(revision 131)
+++ trunk/src/sh_portcheck.c	(revision 132)
@@ -608,4 +608,5 @@
   int                nerr;
 #endif
+  char errbuf[SH_ERRBUF_SIZE];
 
   /* inet_aton(interface, &haddr); */
@@ -627,5 +628,5 @@
       nerr = errno;
       sl_snprintf(errmsg, sizeof(errmsg), _("check port: %5d/udp on %15s: %s"),
-		  port, inet_ntoa(haddr), sh_error_message(errno));
+		  port, inet_ntoa(haddr), sh_error_message(errno, errbuf, sizeof(errbuf)));
       sh_error_handle((-1), FIL__, __LINE__, nerr, MSG_E_SUBGEN, 
 		      errmsg, _("connect"));
@@ -693,5 +694,5 @@
   int                nerr;
 #endif
-
+  char errbuf[SH_ERRBUF_SIZE];
 
   /* inet_aton(interface, &haddr); */
@@ -719,5 +720,5 @@
       nerr = errno;
       sl_snprintf(errmsg, sizeof(errmsg), _("check port: %5d/tcp on %15s: %s"),
-		  port, inet_ntoa(haddr), sh_error_message(errno));
+		  port, inet_ntoa(haddr), sh_error_message(errno, errbuf, sizeof(errbuf)));
       sh_error_handle((-1), FIL__, __LINE__, nerr, MSG_E_SUBGEN, 
 		      errmsg, _("connect"));
@@ -889,5 +890,6 @@
   int              flag =  1; /* non-zero to enable an option */
   struct in_addr   haddr;
- 
+  char errbuf[SH_ERRBUF_SIZE];
+
   /* Check all interfaces for this host
    */
@@ -901,5 +903,5 @@
 #else
 	  sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN, 
-			  sh_error_message(errno), _("socket"));
+			  sh_error_message(errno, errbuf, sizeof(errbuf)), _("socket"));
 #endif
 	}
@@ -912,5 +914,5 @@
 #else
 	  sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN, 
-			  sh_error_message(errno), _("setsockopt"));
+			  sh_error_message(errno, errbuf, sizeof(errbuf)),_("setsockopt"));
 #endif
 	}
@@ -957,4 +959,5 @@
   struct sockaddr_in addr;
   int addrlen      = sizeof(addr);
+  char errbuf[SH_ERRBUF_SIZE];
 
   if (min_port == -1)
@@ -973,5 +976,5 @@
 #else
 	  sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN, 
-			  sh_error_message(errno), _("socket"));
+			  sh_error_message(errno, errbuf, sizeof(errbuf)), _("socket"));
 #endif
 	}
@@ -984,5 +987,5 @@
 #else
 	  sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN, 
-			  sh_error_message(errno), _("setsockopt"));
+			  sh_error_message(errno, errbuf, sizeof(errbuf)),_("setsockopt"));
 #endif
 	}
@@ -1018,5 +1021,5 @@
 #else
 	      sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN, 
-			      sh_error_message(errno), _("bind"));
+			      sh_error_message(errno, errbuf, sizeof(errbuf)), _("bind"));
 #endif
 	    }
Index: trunk/src/sh_prelink.c
===================================================================
--- trunk/src/sh_prelink.c	(revision 131)
+++ trunk/src/sh_prelink.c	(revision 132)
@@ -179,6 +179,8 @@
   if (init == S_FALSE)
     {
+      char dir[SH_PATHBUF];
+
       sh_ext_tas_init(&task);
-      p = sh_unix_getUIDdir (SH_ERR_ERR, task.run_user_uid);
+      p = sh_unix_getUIDdir (SH_ERR_ERR, task.run_user_uid, dir, sizeof(dir));
       if (p)
 	{
Index: trunk/src/sh_processcheck.c
===================================================================
--- trunk/src/sh_processcheck.c	(revision 131)
+++ trunk/src/sh_processcheck.c	(revision 132)
@@ -185,5 +185,5 @@
 static char * get_user_and_path (pid_t pid, char * user, size_t usrlen)
 {
-  extern char *  sh_unix_getUIDname (int level, uid_t uid);
+  extern char *  sh_unix_getUIDname (int level, uid_t uid, char * out, size_t len);
 
   char        path[128];
@@ -232,9 +232,7 @@
     }
 
-  tmp = sh_unix_getUIDname (SH_ERR_ALL, sbuf.st_uid);
-
-  if (tmp)
-    sl_strlcpy(user, tmp, usrlen);
-  else
+  tmp = sh_unix_getUIDname (SH_ERR_ALL, sbuf.st_uid, user, usrlen);
+
+  if (!tmp)
     sl_snprintf (user, usrlen, "%ld", (unsigned long) sbuf.st_uid);
 
@@ -826,6 +824,8 @@
 	  else
 	    {
+	      char errbuf[SH_ERRBUF_SIZE];
+
 	      sh_error_handle(SH_ERR_ALL, FIL__, __LINE__, errno, MSG_E_SUBGEN,
-			      sh_error_message(errno),
+			      sh_error_message(errno, errbuf, sizeof(errbuf)),
 			      _("sh_processes_readps"));
 	      break;
@@ -951,9 +951,10 @@
   struct  sigaction  old_act;
   int retval = 0;
+  char  dir[SH_PATHBUF];
 
   SL_ENTER(_("sh_processes_runps"));
 
   sh_ext_tas_init(&task);
-  p = sh_unix_getUIDdir (SH_ERR_ERR, task.run_user_uid);
+  p = sh_unix_getUIDdir (SH_ERR_ERR, task.run_user_uid, dir, sizeof(dir));
   if (p)
     {
Index: trunk/src/sh_socket.c
===================================================================
--- trunk/src/sh_socket.c	(revision 131)
+++ trunk/src/sh_socket.c	(revision 132)
@@ -342,4 +342,5 @@
 #endif
   struct stat buf;
+  char errbuf[SH_ERRBUF_SIZE];
   
   SL_ENTER(_("sh_socket_open_int"));
@@ -364,5 +365,5 @@
     {
       sh_error_handle ((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		       sh_error_message (errno), 
+		       sh_error_message (errno, errbuf, sizeof(errbuf)), 
 		       _("sh_socket_open_int: socket"));
       SL_RETURN( (-1), _("sh_socket_open_int"));
@@ -405,5 +406,5 @@
       close(pf_unix_fd); pf_unix_fd = -1;
       sh_error_handle ((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		       sh_error_message (errno), 
+		       sh_error_message (errno, errbuf, sizeof(errbuf)), 
 		       _("sh_socket_open_int: bind"));
       SL_RETURN( (-1), _("sh_socket_open_int"));
@@ -416,5 +417,5 @@
       close(pf_unix_fd); pf_unix_fd = -1;
       sh_error_handle ((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		       sh_error_message (errno), 
+		       sh_error_message (errno, errbuf, sizeof(errbuf)), 
 		       _("sh_socket_open_int: setsockopt"));
       SL_RETURN( (-1), _("sh_socket_open_int"));
@@ -427,5 +428,5 @@
       close(pf_unix_fd); pf_unix_fd = -1;
       sh_error_handle ((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		       sh_error_message (errno), 
+		       sh_error_message (errno, errbuf, sizeof(errbuf)), 
 		       _("sh_socket_open_int: fcntl1"));
       SL_RETURN( (-1), _("sh_socket_open_int"));
@@ -437,5 +438,5 @@
       close(pf_unix_fd); pf_unix_fd = -1;
       sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		      sh_error_message (errno), 
+		      sh_error_message (errno, errbuf, sizeof(errbuf)), 
 		      _("sh_socket_open_int: fcntl2"));
       SL_RETURN( (-1), _("sh_socket_open_int"));
@@ -446,5 +447,5 @@
       close(pf_unix_fd); pf_unix_fd = -1;
       sh_error_handle ((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		       sh_error_message (errno), 
+		       sh_error_message (errno, errbuf, sizeof(errbuf)), 
 		       _("sh_socket_open_int: listen"));
       SL_RETURN( (-1), _("sh_socket_open_int"));
@@ -509,4 +510,5 @@
 
   int  client_uid = -1;
+  char errbuf[SH_ERRBUF_SIZE];
 
 
@@ -588,5 +590,5 @@
     {
       sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		      sh_error_message (errno), 
+		      sh_error_message (errno, errbuf, sizeof(errbuf)), 
 		      _("sh_socket_read: accept"));
       return -1;
@@ -602,5 +604,5 @@
       {
 	sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-			sh_error_message (errno), 
+			sh_error_message (errno, errbuf, sizeof(errbuf)), 
 			_("sh_socket_read: setsockopt"));
 	close(talkfd);
@@ -615,5 +617,5 @@
       {
 	sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-			sh_error_message (errno),
+			sh_error_message (errno, errbuf, sizeof(errbuf)),
 			_("sh_socket_read: recvmsg"));
 	close(talkfd);	
@@ -644,5 +646,5 @@
 	}
       sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		      sh_error_message (errno), 
+		      sh_error_message (errno, errbuf, sizeof(errbuf)), 
 		      _("sh_socket_read: recvfrom"));
       close(talkfd);
@@ -654,5 +656,5 @@
     {
       sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		      sh_error_message (errno), 
+		      sh_error_message (errno, errbuf, sizeof(errbuf)), 
 		      _("sh_socket_read: getpeereid"));
       close(talkfd);
@@ -665,5 +667,5 @@
     {
       sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		      sh_error_message (errno), 
+		      sh_error_message (errno, errbuf, sizeof(errbuf)), 
 		      _("sh_socket_read: getsockopt"));
       close(talkfd);
@@ -843,5 +845,5 @@
     {
       sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-		      sh_error_message (errno), 
+		      sh_error_message (errno, errbuf, sizeof(errbuf)), 
 		      _("sh_socket_read: send"));
       return -1;
@@ -876,5 +878,5 @@
 	    {
 	      sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-			      sh_error_message (errno), 
+			      sh_error_message (errno, errbuf, sizeof(errbuf)), 
 			      _("sh_socket_read: sendto"));
 	      close(talkfd);
@@ -907,5 +909,5 @@
 	{
 	  sh_error_handle((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
-			  sh_error_message (errno), 
+			  sh_error_message (errno, errbuf, sizeof(errbuf)), 
 			  _("sh_socket_read: sendto"));
 	  close(talkfd);
@@ -933,5 +935,5 @@
   sl_strlcpy (new->cmd, in->cmd, sizeof(new->cmd));
   sl_strlcpy (new->clt, in->clt, sizeof(new->clt));
-  sl_strlcpy (new->cti, sh_unix_time(0), sizeof(new->cti));
+  (void) sh_unix_time(0, new->cti, sizeof(new->cti));
   new->next = cmdlist;
   cmdlist   = new;
@@ -951,5 +953,5 @@
 	  sl_strlcpy (new->cmd, in->cmd, sizeof(new->cmd));
 	  sl_strlcpy (new->clt, in->clt, sizeof(new->clt));
-	  sl_strlcpy (new->cti, sh_unix_time(0), sizeof(new->cti));
+	  (void) sh_unix_time(0, new->cti, sizeof(new->cti));
 	  return;
 	}
@@ -960,5 +962,5 @@
   sl_strlcpy (new->cmd, in->cmd, sizeof(new->cmd));
   sl_strlcpy (new->clt, in->clt, sizeof(new->clt));
-  sl_strlcpy (new->cti, sh_unix_time(0), sizeof(new->cti));
+  (void) sh_unix_time(0, new->cti, sizeof(new->cti));
   new->next = runlist;
   runlist   = new;
Index: trunk/src/sh_suidchk.c
===================================================================
--- trunk/src/sh_suidchk.c	(revision 131)
+++ trunk/src/sh_suidchk.c	(revision 132)
@@ -173,4 +173,5 @@
   struct stat two;
   int         fd;
+  char errbuf[SH_ERRBUF_SIZE];
 
   if (depth > 99)
@@ -198,5 +199,5 @@
 	  sh_error_handle ((-1), FIL__, __LINE__, errno,
 			   MSG_SUID_ERROR,
-			   sh_error_message(errno));
+			   sh_error_message(errno, errbuf, sizeof(errbuf)));
 	  *q = '/'; 
 	  return -1; 
@@ -217,5 +218,5 @@
 	  sh_error_handle ((-1), FIL__, __LINE__, errno,
 			   MSG_SUID_ERROR,
-			   sh_error_message(errno));
+			   sh_error_message(errno, errbuf, sizeof(errbuf)));
 	  *q = '/';
 	  return -1;
@@ -226,5 +227,5 @@
 	  sh_error_handle ((-1), FIL__, __LINE__, errno,
 			   MSG_SUID_ERROR,
-			   sh_error_message(errno));
+			   sh_error_message(errno, errbuf, sizeof(errbuf)));
 	  return -1; 
 	}
@@ -252,5 +253,5 @@
 	  sh_error_handle ((-1), FIL__, __LINE__, errno,
 			   MSG_SUID_ERROR,
-			   sh_error_message(errno));
+			   sh_error_message(errno, errbuf, sizeof(errbuf)));
 	  return -1;
 	} 
@@ -260,5 +261,5 @@
 	  sh_error_handle ((-1), FIL__, __LINE__, errno,
 			   MSG_SUID_ERROR,
-			   sh_error_message(errno));
+			   sh_error_message(errno, errbuf, sizeof(errbuf)));
 	  return -1;
 	} 
@@ -267,5 +268,5 @@
 	  sh_error_handle ((-1), FIL__, __LINE__, errno,
 			   MSG_SUID_ERROR,
-			   sh_error_message(errno));
+			   sh_error_message(errno, errbuf, sizeof(errbuf)));
 	  (void) close(fd);
 	  return -1; 
@@ -307,5 +308,5 @@
 	      sh_error_handle ((-1), FIL__, __LINE__, errno,
 			       MSG_SUID_ERROR,
-			       sh_error_message(errno));
+			       sh_error_message(errno, errbuf, sizeof(errbuf)));
 	      (void) close(fd); 
 	      return -1;
@@ -332,5 +333,5 @@
 	      sh_error_handle ((-1), FIL__, __LINE__, errno,
 			       MSG_SUID_ERROR,
-			       sh_error_message(errno));
+			       sh_error_message(errno, errbuf, sizeof(errbuf)));
 	      (void) close(fd); 
 	      return -1;
@@ -343,5 +344,5 @@
 	      sh_error_handle ((-1), FIL__, __LINE__, errno,
 			       MSG_SUID_ERROR,
-			       sh_error_message(errno));
+			       sh_error_message(errno, errbuf, sizeof(errbuf)));
 	      (void) close(fd); 
 	      return -1;
@@ -358,4 +359,5 @@
   int    result;
   char * path;
+  char errbuf[SH_ERRBUF_SIZE];
 
   if (0 != chdir("/"))
@@ -363,5 +365,5 @@
       sh_error_handle ((-1), FIL__, __LINE__, errno,
 		       MSG_SUID_ERROR,
-		       sh_error_message(errno));
+		       sh_error_message(errno, errbuf, sizeof(errbuf)));
     }
 
@@ -369,5 +371,5 @@
     {
       sh_error_handle((-1), FIL__, __LINE__, caperr, MSG_E_SUBGEN,
-		      sh_error_message (caperr), 
+		      sh_error_message (caperr, errbuf, sizeof(errbuf)), 
 		      _("sl_get_cap_qdel"));
     }
@@ -380,5 +382,5 @@
     {
       sh_error_handle((-1), FIL__, __LINE__, caperr, MSG_E_SUBGEN,
-		      sh_error_message (caperr), 
+		      sh_error_message (caperr, errbuf, sizeof(errbuf)), 
 		      _("sl_drop_cap_qdel"));
     }
@@ -388,5 +390,5 @@
       sh_error_handle ((-1), FIL__, __LINE__, errno,
 		       MSG_SUID_ERROR,
-		       sh_error_message(errno));
+		       sh_error_message(errno, errbuf, sizeof(errbuf)));
     }
   return result;
@@ -616,4 +618,5 @@
   int             cperm_status = 0;
   int             file_d       = -1;
+  char errbuf[SH_ERRBUF_SIZE];
 
   if (retry_lstat(FIL__, __LINE__, fullpath, &fileInfo) == -1)
@@ -640,5 +643,5 @@
 	  sh_error_handle((-1), FIL__, __LINE__, 
 			  caperr, MSG_E_SUBGEN,
-			  sh_error_message (caperr), 
+			  sh_error_message (caperr, errbuf, sizeof(errbuf)), 
 			  _("sl_get_cap_qdel"));
 	  cperm_status = -1;
@@ -753,5 +756,5 @@
       sh_error_handle((-1), FIL__, __LINE__, 
 		      caperr, MSG_E_SUBGEN,
-		      sh_error_message (caperr), 
+		      sh_error_message (caperr, errbuf, sizeof(errbuf)), 
 		      _("sl_drop_cap_qdel"));
     }
@@ -792,13 +795,5 @@
   msg[0] = '\0';
   /*@-usedef@*/
-  (void) sl_strlcpy (timestrc, 
-		     sh_unix_gmttime (theFile->ctime), 
-		     32);
-  (void) sl_strlcpy (timestra, 
-		     sh_unix_gmttime (theFile->atime), 
-		     32);
-  (void) sl_strlcpy (timestrm, 
-		     sh_unix_gmttime (theFile->mtime), 
-		     32);
+
 #ifdef SH_USE_XML
   (void) sl_snprintf(msg, SH_BUFSIZE, _("owner_new=\"%s\" iowner_new=\"%ld\" group_new=\"%s\" igroup_new=\"%ld\" size_new=\"%lu\" ctime_new=\"%s\" atime_new=\"%s\" mtime_new=\"%s\""), 
@@ -845,4 +840,5 @@
   struct sh_dirent * dirlist = NULL;
   struct sh_dirent * dirlist_orig = NULL;
+  char errbuf[SH_ERRBUF_SIZE];
 
   SL_ENTER(_("sh_suidchk_check_internal"));
@@ -866,5 +862,5 @@
       sh_error_handle (ShDFLevel[SH_ERR_T_DIR], FIL__, __LINE__, status, 
 		       MSG_E_OPENDIR,
-		       sh_error_message (status), tmp);
+		       sh_error_message (status, errbuf, sizeof(errbuf)), tmp);
       SH_FREE(tmp);
       SL_RETURN( (-1), _("sh_suidchk_check_internal"));
@@ -961,5 +957,5 @@
 	tmp = sh_util_safe_name(tmpcat);
 	sh_error_handle (SH_ERR_ERR, FIL__, __LINE__, status, MSG_ERR_LSTAT,
-			 sh_error_message(status),
+			 sh_error_message(status, errbuf, sizeof(errbuf)),
 			 tmpcat );
 	SH_FREE(tmp);
@@ -1083,6 +1079,11 @@
 		      {
 			if (-1 == fflags)
-			  report_file(tmpcat, &theFile, timestrc, timestra, 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);
+			  }
 			/* Quarantine file according to configured method
 			 */
Index: trunk/src/sh_tools.c
===================================================================
--- trunk/src/sh_tools.c	(revision 131)
+++ trunk/src/sh_tools.c	(revision 132)
@@ -94,24 +94,28 @@
 #ifdef SH_ENCRYPT
 #include "rijndael-api-fst.h"
-char * errorExplain (int err_num)
-{
+char * errorExplain (int err_num, char * buffer, size_t len)
+{
+  char * p;
+
   if      (err_num == BAD_KEY_DIR)
-    return (_("Key direction is invalid"));
+    p = (_("Key direction is invalid"));
   else if (err_num == BAD_KEY_MAT) 
-    return (_("Key material not of correct length"));
+    p = (_("Key material not of correct length"));
   else if (err_num == BAD_KEY_INSTANCE) 
-    return (_("Key passed is not valid"));
+    p = (_("Key passed is not valid"));
   else if (err_num == BAD_CIPHER_MODE) 
-    return (_("Params struct passed to cipherInit invalid"));
+    p = (_("Params struct passed to cipherInit invalid"));
   else if (err_num == BAD_CIPHER_STATE) 
-    return (_("Cipher in wrong state"));
+    p = (_("Cipher in wrong state"));
   else if (err_num == BAD_BLOCK_LENGTH) 
-    return (_("Bad block length"));
+    p = (_("Bad block length"));
   else if (err_num == BAD_CIPHER_INSTANCE) 
-    return (_("Bad cipher instance"));
+    p = (_("Bad cipher instance"));
   else if (err_num == BAD_DATA) 
-    return (_("Data contents are invalid"));
+    p = (_("Data contents are invalid"));
   else  
-    return (_("Unknown error"));
+    p = (_("Unknown error"));
+  sl_strlcpy (buffer, p, len);
+  return buffer;
 }
 
@@ -361,24 +365,26 @@
 /* extern int h_errno; */ 
 
-char * sh_tools_errmessage (int tellme)
-{
-
+char * sh_tools_errmessage (int tellme, char * errbuf, size_t len)
+{
+  char * p = NULL;
 #ifdef HOST_NOT_FOUND
     if (tellme == HOST_NOT_FOUND)  
-      return _("The specified host is unknown: ");
+      p = _("The specified host is unknown: ");
 #endif
 #ifdef NO_ADDRESS
     if (tellme == NO_ADDRESS)  
-      return _("The requested name is valid but does not have an IP address: ");
+      p = _("The requested name is valid but does not have an IP address: ");
 #endif
 #ifdef NO_RECOVERY
     if (tellme == NO_RECOVERY)  
-      return _("A non-recoverable name server error occurred: ");
+      p = _("A non-recoverable name server error occurred: ");
 #endif
 #ifdef TRY_AGAIN
     if (tellme == TRY_AGAIN)  
-      return _("A temporary error occurred on an authoritative name server. The specified host is unknown: ");
-#endif
-    return _("Unknown error");
+      p = _("A temporary error occurred on an authoritative name server. The specified host is unknown: ");
+#endif
+    if (!p) p =  _("Unknown error");
+    sl_strlcpy(errbuf, p, len);
+    return errbuf;
 }
 
@@ -474,4 +480,5 @@
 
   int    retval;
+  char   errbuf[SH_ERRBUF_SIZE];
 
   sin_cache * check_cache = conn_cache;
@@ -525,5 +532,5 @@
 	      *errnum = 666;
 #endif
-	      sl_strlcpy(errmsg, sh_tools_errmessage (*errnum), errsiz);
+	      (void) sh_tools_errmessage (*errnum, errmsg, errsiz);
 	      sl_strlcat(errmsg, address, errsiz); 
 	      fail = (-1);
@@ -561,6 +568,5 @@
 		      *errnum = 666;
 #endif
-		      sl_strlcpy(errmsg, 
-				 sh_tools_errmessage (*errnum), errsiz);
+		      (void) sh_tools_errmessage (*errnum, errmsg, errsiz);
 		      sl_strlcat(errmsg, 
 				 inet_ntoa (*(struct in_addr *) &(sinr.sin_addr)),
@@ -637,5 +643,5 @@
 	sl_strlcpy(ecall, _("socket"), SH_MINIBUF);
 	*errnum = status;
-	sl_strlcpy(errmsg, sh_error_message (status), errsiz);
+	sl_strlcpy(errmsg, sh_error_message (status, errbuf, sizeof(errbuf)), errsiz);
 	sl_strlcat(errmsg, _(", address "), errsiz);
 	sl_strlcat(errmsg, address, errsiz);
@@ -651,5 +657,5 @@
 	sl_strlcpy(ecall, _("connect"), SH_MINIBUF);
 	*errnum = status;
-	sl_strlcpy(errmsg, sh_error_message (status), errsiz);
+	sl_strlcpy(errmsg, sh_error_message (status, errbuf, sizeof(errbuf)), errsiz);
 	sl_strlcat(errmsg, _(", address "), errsiz);
 	sl_strlcat(errmsg, address, errsiz);
@@ -715,4 +721,5 @@
   struct  sigaction  new_act;
   struct  sigaction  old_act;
+  char    errbuf[SH_ERRBUF_SIZE];
 
   SL_ENTER(_("sh_write_select"));
@@ -753,5 +760,5 @@
 	    *w_error = errno;
 	    TPT(( 0, FIL__, __LINE__, _("msg=<select: %s>\n"), 
-		  sh_error_message(*w_error)));
+		  sh_error_message(*w_error, errbuf, sizeof(errbuf))));
 	    sigaction (SIGPIPE, &old_act, NULL);
 	    SL_RETURN( countbytes, _("sh_write_select"));
@@ -771,5 +778,5 @@
 	    *w_error = errno;
 	    TPT(( 0, FIL__, __LINE__, _("msg=<select: %s>\n"), 
-		  sh_error_message(*w_error)));
+		  sh_error_message(*w_error, errbuf, sizeof(errbuf))));
 	    sigaction (SIGPIPE, &old_act, NULL);
 	    SL_RETURN( countbytes, _("sh_write_select"));
@@ -853,5 +860,4 @@
 {
   unsigned long bytes;
-  char errmsg[256];
 
   SL_ENTER(_("write_port"));
@@ -860,7 +866,8 @@
   if (*w_error != 0)
     {
-      sl_strlcpy(errmsg, sh_error_message (*w_error), sizeof(errmsg));
+      char errbuf[SH_ERRBUF_SIZE];
       sh_error_handle((-1), FIL__, __LINE__, *w_error, MSG_TCP_NETRP, 
-		      errmsg, (long) sockfd, _("write_port"));
+		      sh_error_message (*w_error, errbuf, sizeof(errbuf)),
+		      (long) sockfd, _("write_port"));
     }
   SL_RETURN( bytes, _("write_port"));
@@ -874,5 +881,4 @@
 {
   unsigned long bytes;
-  char errmsg[256];
 
   SL_ENTER(_("read_port"));
@@ -881,7 +887,8 @@
   if (*w_error != 0)
     {
-      sl_strlcpy(errmsg, sh_error_message (*w_error), sizeof(errmsg));
+      char errbuf[SH_ERRBUF_SIZE];
       sh_error_handle((-1), FIL__, __LINE__, *w_error, MSG_TCP_NETRP, 
-		      errmsg, (long) sockfd, _("read_port"));
+		      sh_error_message (*w_error, errbuf, sizeof(errbuf)),
+		      (long) sockfd, _("read_port"));
     }
   SL_RETURN( bytes, _("read_port"));
@@ -1216,6 +1223,7 @@
   if (err_num < 0) 
     {
+      char expbuf[SH_ERRBUF_SIZE];
       sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-		      errorExplain(err_num), 
+		      errorExplain(err_num, expbuf, sizeof(expbuf)), 
 		      _("sh_tools_makePack: cipherInit"));
     }
@@ -1227,6 +1235,7 @@
       if (err_num < 0)
 	{
+	  char expbuf[SH_ERRBUF_SIZE];
 	  sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-			  errorExplain(err_num), 
+			  errorExplain(err_num, expbuf, sizeof(expbuf)), 
 			  _("sh_tools_makePack: blockEncrypt"));
 	}
@@ -1255,4 +1264,5 @@
   int                     err_num;
   int                     blkfac;
+  char expbuf[SH_ERRBUF_SIZE];
 
   msg_size = (256 * (unsigned int)header[1] + (unsigned int)header[2]);
@@ -1274,5 +1284,5 @@
     {
       sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-		      errorExplain(err_num), 
+		      errorExplain(err_num, expbuf, sizeof(expbuf)), 
 		      _("sh_tools_revertPack: cipherInit"));
     }
@@ -1285,5 +1295,5 @@
 	{
 	  sh_error_handle((-1), FIL__, __LINE__, -1, MSG_E_SUBGEN,
-			  errorExplain(err_num), 
+			  errorExplain(err_num, expbuf, sizeof(expbuf)), 
 			  _("sh_tools_revertPack: blockDecrypt"));
 	}
Index: trunk/src/sh_unix.c
===================================================================
--- trunk/src/sh_unix.c	(revision 131)
+++ trunk/src/sh_unix.c	(revision 132)
@@ -797,5 +797,9 @@
 #endif
 #ifdef SIGPIPE
+#ifdef HAVE_PTHREAD
+  retry_sigaction(FIL__, __LINE__, SIGPIPE,   &ignact, &oldact);
+#else
   retry_sigaction(FIL__, __LINE__, SIGPIPE,      &act, &oldact);
+#endif
 #endif
 #ifdef SIGALRM
@@ -1181,14 +1185,13 @@
 
 #ifdef HAVE_INITGROUPS
-char *  sh_unix_getUIDname (int level, uid_t uid);
+char *  sh_unix_getUIDname (int level, uid_t uid, char * out, size_t len);
 int  sh_unix_initgroups2 (uid_t in_pid, gid_t in_gid)
 {
   int status  = -1;
-  char * user = NULL;
+  char user[SH_MINIBUF];
 
   SL_ENTER(_("sh_unix_initgroups2"));
 
-  user = sh_unix_getUIDname (SH_ERR_ERR, in_pid);
-  if (user == NULL)
+  if (NULL == sh_unix_getUIDname (SH_ERR_ERR, in_pid, user, sizeof(user)))
     SL_RETURN((-1), _("sh_unix_initgroups2"));
   status = sh_initgroups (user, in_gid);
@@ -1481,7 +1484,8 @@
       if ((test == -1) && (errno != EINVAL)) 
 	{
+	  char errbuf[SH_ERRBUF_SIZE];
 	  status = errno;
 	  sh_error_handle ((-1), FIL__, __LINE__, status, MSG_W_SIG,
-			   sh_error_message (status), sig_num);
+			   sh_error_message (status, errbuf, sizeof(errbuf)), sig_num);
 	}
     }
@@ -1734,7 +1738,8 @@
       if ( (-1) == status ) 
 	{
+	  char errbuf[SH_ERRBUF_SIZE];
 	  status = errno;
 	  sh_error_handle ((-1), FIL__, __LINE__, status, MSG_W_CHDIR,
-			   sh_error_message (status), chroot_dir);
+			   sh_error_message (status, errbuf, sizeof(errbuf)), chroot_dir);
 	  aud_exit(FIL__, __LINE__, EXIT_FAILURE);
 	}
@@ -1779,5 +1784,5 @@
 {
   int    res = 0;
-
+  
   SL_ENTER(_("sh_unix_setnodeamon"));
 
@@ -1804,4 +1809,5 @@
   extern int sh_socket_open_int ();
 #endif
+  char errbuf[SH_ERRBUF_SIZE];
 
   SL_ENTER(_("sh_unix_init"));
@@ -1849,5 +1855,5 @@
       status = errno;
       sh_error_handle ((-1), FIL__, __LINE__, status, MSG_W_CHDIR,
-		       sh_error_message (status), "/");
+		       sh_error_message (status, errbuf, sizeof(errbuf)), "/");
       aud_exit(FIL__, __LINE__, EXIT_FAILURE);
     }
@@ -1897,5 +1903,5 @@
 	  status = errno;
 	  sh_error_handle((-1), FIL__, __LINE__, status, MSG_E_SUBGEN, 
-			  sh_error_message(status), _("open"));
+			  sh_error_message(status, errbuf, sizeof(errbuf)), _("open"));
 	  aud_exit(FIL__, __LINE__, EXIT_FAILURE);
 	}
@@ -1909,5 +1915,5 @@
 	  status = errno;
 	  sh_error_handle((-1), FIL__, __LINE__, status, MSG_E_SUBGEN, 
-			  sh_error_message(status), _("dup"));
+			  sh_error_message(status, errbuf, sizeof(errbuf)), _("dup"));
 	  aud_exit(FIL__, __LINE__, EXIT_FAILURE);
 	}
@@ -1962,5 +1968,5 @@
       status = errno;
       sh_error_handle((-1), FIL__, __LINE__, status, MSG_E_SUBGEN, 
-			  sh_error_message(status), _("chroot"));
+			  sh_error_message(status, errbuf, sizeof(errbuf)), _("chroot"));
       aud_exit(FIL__, __LINE__, EXIT_FAILURE);
     }
@@ -2095,9 +2101,9 @@
 #endif
 
-char * sh_unix_time (time_t thetime)
+char * sh_unix_time (time_t thetime, char * buffer, size_t len)
 {
 
   int           status;
-
+  char          AsciiTime[81];                       /* local time   */
   time_t        time_now;
   struct tm   * time_ptr;
@@ -2105,6 +2111,4 @@
   struct tm     time_tm;
 #endif
-  static char   AsciiTime[81];                       /* local time   */
-  static char   RetTime[81];                         /* local time   */
 #ifdef SH_USE_XML
   static char   deftime[] = N_("0000-00-00T00:00:00"); /* default time */
@@ -2202,6 +2206,9 @@
 #endif
 
-  if (time_now == (-1) ) 
-    SL_RETURN( _(deftime), _("sh_unix_time"));
+  if (time_now == (-1) )
+    {
+      sl_strlcpy(buffer, _(deftime), len);
+      SL_RETURN(buffer, _("sh_unix_time"));
+    }
   else
     {
@@ -2214,5 +2221,5 @@
   if (time_ptr != NULL) 
     {
-      status = strftime (AsciiTime, 80,
+      status = strftime (AsciiTime, sizeof(AsciiTime),
 #ifdef SH_USE_XML
 			 _("%Y-%m-%dT%H:%M:%S%%s"),
@@ -2222,15 +2229,21 @@
 			 time_ptr);
 
-      sl_snprintf(RetTime, 80, AsciiTime, t_zone(&time_now));
-
-      if ( (status == 0) || (status == 80) ) 
-	SL_RETURN( _(deftime), _("sh_unix_time"));
+      sl_snprintf(buffer, len, AsciiTime, t_zone(&time_now));
+
+      if ( (status == 0) || (status == sizeof(AsciiTime)) )
+	{
+	  sl_strlcpy(buffer, _(deftime), len);
+	  SL_RETURN( buffer, _("sh_unix_time"));
+	}
       else
-	SL_RETURN( &RetTime[0], _("sh_unix_time"));
+	{
+	  SL_RETURN(buffer, _("sh_unix_time"));
+	}
     }
 
   /* last resort
    */
-  SL_RETURN( _(deftime), _("sh_unix_time"));
+  sl_strlcpy(buffer, _(deftime), len);
+  SL_RETURN( buffer, _("sh_unix_time"));
 }
 
@@ -2248,5 +2261,5 @@
 }
     
-char * sh_unix_gmttime (time_t thetime)
+char * sh_unix_gmttime (time_t thetime, char * buffer, size_t len)
 {
 
@@ -2257,5 +2270,5 @@
   struct tm     time_tm;
 #endif
-  static char   AsciiTime[81];                       /* GMT time   */
+  char   AsciiTime[81];                       /* GMT time   */
 #ifdef SH_USE_XML
   static char   deftime[] = N_("0000-00-00T00:00:00"); /* default time */
@@ -2292,18 +2305,19 @@
 			 time_ptr);
 
-      if ( (status == 0) || (status == 80) ) 
-	SL_RETURN( _(deftime), _("sh_unix_gmttime"));
+      if ( (status == 0) || (status == 80) )
+	sl_strlcpy(buffer, _(deftime), len);
       else
-	SL_RETURN( &AsciiTime[0], _("sh_unix_gmttime"));
+	sl_strlcpy(buffer, AsciiTime, len);
+      SL_RETURN( buffer, _("sh_unix_gmttime"));
     }
 
   /* last resort
    */
-  SL_RETURN( _(deftime), _("sh_unix_gmttime"));
-}
-
-
-
-char *  sh_unix_getUIDdir (int level, uid_t uid)
+  sl_strlcpy(buffer, _(deftime), len);
+  SL_RETURN( buffer, _("sh_unix_gmttime"));
+}
+
+
+char *  sh_unix_getUIDdir (int level, uid_t uid, char * out, size_t len)
 {
   struct passwd * tempres;
@@ -2313,4 +2327,5 @@
   char   buffer[SH_PWBUF_SIZE];
 #endif
+  char errbuf[SH_ERRBUF_SIZE];
 
   SL_ENTER(_("sh_unix_getUIDdir"));
@@ -2326,5 +2341,5 @@
   if (tempres == NULL) {
     sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_PWNULL,
-		     sh_error_message(status),
+		     sh_error_message(status, errbuf, sizeof(errbuf)),
 		     _("getpwuid"), (long) uid, _("completely missing"));
     SL_RETURN( NULL, _("sh_unix_getUIDdir"));
@@ -2332,8 +2347,9 @@
 
   if (tempres->pw_dir != NULL) {
-    SL_RETURN( tempres->pw_dir, _("sh_unix_getUIDdir"));
+    sl_strlcpy(out, tempres->pw_dir, len);
+    SL_RETURN( out, _("sh_unix_getUIDdir"));
   } else {
     sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_PWNULL,
-		     sh_error_message(status),
+		     sh_error_message(status, errbuf, sizeof(errbuf)),
 		     _("getpwuid"), (long) uid, _("pw_dir"));
     SL_RETURN( NULL, _("sh_unix_getUIDdir"));
@@ -2341,5 +2357,7 @@
 }
 
-char *  sh_unix_getUIDname (int level, uid_t uid)
+SH_MUTEX_STATIC(getUIDname, PTHREAD_MUTEX_INITIALIZER);
+
+char *  sh_unix_getUIDname (int level, uid_t uid, char * out, size_t len)
 {
   struct passwd * tempres;
@@ -2351,9 +2369,17 @@
   static uid_t    old_uid;
   static char     name[32] = { '\0' };
+  char errbuf[SH_ERRBUF_SIZE];
 
   SL_ENTER(_("sh_unix_getUIDname"));
 
   if ((uid == old_uid) && (name[0] != '\0')) {
-    SL_RETURN( name, _("sh_unix_getUIDname"));
+    out[0] = '\0';
+    SH_MUTEX_LOCK_UNSAFE(getUIDname);
+    if ((uid == old_uid) && (name[0] != '\0')) {
+      sl_strlcpy(out, name, len);
+    }
+    SH_MUTEX_UNLOCK_UNSAFE(getUIDname);
+    if (out[0] != '\0')
+      SL_RETURN( out, _("sh_unix_getUIDname"));
   }
 
@@ -2368,5 +2394,5 @@
   if (tempres == NULL) {
     sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_PWNULL,
-		     sh_error_message(status),
+		     sh_error_message(status, errbuf, sizeof(errbuf)),
 		     _("getpwuid"), (long) uid, _("completely missing"));
     SL_RETURN( NULL, _("sh_unix_getUIDname"));
@@ -2375,12 +2401,13 @@
 
   if (tempres->pw_name != NULL) {
-    /* NEED_LOCK */
+    SH_MUTEX_LOCK_UNSAFE(getUIDname);
     sl_strlcpy(name, tempres->pw_name, sizeof(name));
     old_uid = uid;
-    /* END_LOCK  */
-    SL_RETURN( name, _("sh_unix_getUIDname"));
+    sl_strlcpy(out, name, len);
+    SH_MUTEX_UNLOCK_UNSAFE(getUIDname);
+    SL_RETURN( out, _("sh_unix_getUIDname"));
   } else {
     sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_PWNULL,
-		     sh_error_message(status),
+		     sh_error_message(status, errbuf, sizeof(errbuf)),
 		     _("getpwuid"), (long) uid, _("pw_user"));
     SL_RETURN( NULL, _("sh_unix_getUIDname"));
@@ -2388,5 +2415,7 @@
 }
 
-char *  sh_unix_getGIDname (int level, gid_t gid)
+SH_MUTEX_STATIC(getGIDname, PTHREAD_MUTEX_INITIALIZER);
+
+char *  sh_unix_getGIDname (int level, gid_t gid, char * out, size_t len)
 {
   struct group  * tempres;
@@ -2398,4 +2427,5 @@
   char            buffer[SH_GRBUF_SIZE];
 #endif
+  char errbuf[SH_ERRBUF_SIZE];
   
 
@@ -2403,7 +2433,14 @@
 
   if ((gid == old_gid) && (name[0] != '\0')) {
-    SL_RETURN( name, _("sh_unix_getUIDname"));
+    out[0] = '\0';
+    SH_MUTEX_LOCK_UNSAFE(getGIDname);
+    if ((gid == old_gid) && (name[0] != '\0')) {
+      sl_strlcpy(out, name, len);
+    }
+    SH_MUTEX_UNLOCK_UNSAFE(getGIDname);
+    if (out[0] != '\0')
+      SL_RETURN( out, _("sh_unix_getGIDname"));
   }
-  
+
 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R)
   status = sh_getgrgid_r(gid, &grp, buffer, sizeof(buffer), &tempres);
@@ -2416,5 +2453,5 @@
   if (tempres == NULL) {
     sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_GRNULL,
-		     sh_error_message(status),
+		     sh_error_message(status, errbuf, sizeof(errbuf)),
 		     _("getgrgid"), (long) gid, _("completely missing"));
       
@@ -2422,13 +2459,15 @@
   }
 
+  /* FIXME: need to return caller-supplied buffer */
   if (tempres->gr_name != NULL) {
-    /* NEED_LOCK */
+    SH_MUTEX_LOCK_UNSAFE(getGIDname);
     sl_strlcpy(name, tempres->gr_name, sizeof(name));
     old_gid = gid;
-    /* END_LOCK  */
-    SL_RETURN( name, _("sh_unix_getGIDname"));
+    sl_strlcpy(out, name, len);
+    SH_MUTEX_UNLOCK_UNSAFE(getGIDname);
+    SL_RETURN( out, _("sh_unix_getGIDname"));
   } else {
     sh_error_handle (level, FIL__, __LINE__, EINVAL, MSG_E_GRNULL,
-		     sh_error_message(status),
+		     sh_error_message(status, errbuf, sizeof(errbuf)),
 		     _("getgrgid"), (long) gid, _("gr_name"));
     SL_RETURN( NULL, _("sh_unix_getGIDname"));
@@ -2440,4 +2479,6 @@
   char          * p;
   uid_t  seuid, sruid;
+  char   user[USER_MAX];
+  char   dir[SH_PATHBUF];
 
   SL_ENTER(_("sh_unix_getUser"));
@@ -2447,5 +2488,5 @@
   sh.effective.uid = seuid;
 
-  p = sh_unix_getUIDdir (SH_ERR_ERR, seuid);
+  p = sh_unix_getUIDdir (SH_ERR_ERR, seuid, dir, sizeof(dir));
 
   if (p == NULL)
@@ -2466,5 +2507,5 @@
   sh.real.uid = sruid;
 
-  p = sh_unix_getUIDname (SH_ERR_ERR, sruid);
+  p = sh_unix_getUIDname (SH_ERR_ERR, sruid, user, sizeof(user));
   if (p == NULL)
     SL_RETURN((-1), _("sh_unix_getUser"));
@@ -2480,5 +2521,5 @@
     }
 
-  p = sh_unix_getUIDdir (SH_ERR_ERR, sruid);
+  p = sh_unix_getUIDdir (SH_ERR_ERR, sruid, dir, sizeof(dir));
 
   if (p == NULL)
@@ -3270,7 +3311,9 @@
 	{
 	  if (S_FALSE == sh_ignore_chk_del(theFile->fullpath)) {
+	    char errbuf[SH_ERRBUF_SIZE];
 	    tmp2 = sh_util_safe_name (theFile->fullpath);
 	    sh_error_handle (level, FIL__, __LINE__, stat_return, MSG_FI_LSTAT,
-			     sh_error_message (stat_return), tmp2);
+			     sh_error_message (stat_return, errbuf, sizeof(errbuf)), 
+			     tmp2);
 	    SH_FREE(tmp2);
 	  }
@@ -3465,8 +3508,5 @@
    */
 
-  if ( (name = sh_unix_getGIDname(SH_ERR_ALL,
-				  buf.st_gid)) != NULL) {
-    sl_strlcpy (theFile->c_group, name, GROUP_MAX+1);
-  } else {
+  if (NULL == sh_unix_getGIDname(SH_ERR_ALL, buf.st_gid, theFile->c_group, GROUP_MAX+1)) {
 
     tmp2 = sh_util_safe_name (theFile->fullpath);
@@ -3489,8 +3529,5 @@
 
   
-  if ( (name = sh_unix_getUIDname(SH_ERR_ALL,
-				  buf.st_uid)) != NULL) {
-    sl_strlcpy (theFile->c_owner, name, USER_MAX+1);
-  } else {
+  if (NULL == sh_unix_getUIDname(SH_ERR_ALL, buf.st_uid, theFile->c_owner, USER_MAX+)) {
 
     tmp2 = sh_util_safe_name (theFile->fullpath);
@@ -3518,5 +3555,5 @@
       tmp2 = sh_util_safe_name ((filename == NULL) ? 
 				theFile->fullpath : filename);
-      sl_strlcpy(timestr, sh_unix_time(theFile->mtime), 81);
+      (void) sh_unix_time(theFile->mtime, timestr, sizeof(timestring));
       sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_LIST,
 		       theFile->c_mode,
@@ -3547,8 +3584,9 @@
       if (linksize < 0) 
 	{
+	  char errbuf[SH_ERRBUF_SIZE];
 	  linksize = errno;
 	  tmp2 = sh_util_safe_name (theFile->fullpath);
 	  sh_error_handle (level, FIL__, __LINE__, linksize, MSG_FI_RDLNK,
-			   sh_error_message (linksize), tmp2);
+			   sh_error_message (linksize, errbuf, sizeof(errbuf)), tmp2);
 	  SH_FREE(tmp2);
 	  SH_FREE(linknamebuf);
@@ -3598,7 +3636,9 @@
 	if (stat_return != ENOENT)
 	  { 
+	    char errbuf[SH_ERRBUF_SIZE];
 	    sh_error_handle (level, FIL__, __LINE__, stat_return, 
 			     MSG_FI_LSTAT,
-			     sh_error_message (stat_return), tmp2);
+			     sh_error_message (stat_return,errbuf, sizeof(errbuf)), 
+			     tmp2);
 	  }
 	else 
@@ -3873,7 +3913,9 @@
   else if (flag != NULL)
     {
+      char errbuf[SH_ERRBUF_SIZE];
       error = errno;
       sh_error_handle ((-1), FIL__, __LINE__, error, MSG_E_UNLNK,
-		       sh_error_message(error), lockfile);
+		       sh_error_message(error, errbuf, sizeof(errbuf)), 
+		       lockfile);
       SL_RETURN((-1),_("sh_unix_unlock"));
     }
@@ -4211,5 +4253,7 @@
 	{
 #ifdef TEST_MLOCK
-	  fprintf(stderr, "mlock: error: %s\n", sh_error_message(errno));
+	  char errbuf[SH_ERRBUF_SIZE];
+	  fprintf(stderr, "mlock: error: %s\n", 
+		  sh_error_message(errno, errbuf, sizeof(errbuf)));
 #endif
 	  SH_FREE(page_list);
Index: trunk/src/sh_utmp.c
===================================================================
--- trunk/src/sh_utmp.c	(revision 131)
+++ trunk/src/sh_utmp.c	(revision 132)
@@ -799,5 +799,5 @@
 	  ) {
 	status = sh_utmp_login_a(user->name);
-	(void) sl_strlcpy(ttt, sh_unix_time (user->time), TIM_MAX);
+	(void) sh_unix_time (user->time, ttt, TIM_MAX);
 	sh_error_handle( ShUtmpLoginSolo, FIL__, __LINE__, 0,
 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR)
@@ -823,5 +823,5 @@
 	  {       
 	    status = sh_utmp_login_a(user->name);
-	    (void) sl_strlcpy(ttt, sh_unix_time (user->time), TIM_MAX);
+	    (void) sh_unix_time (user->time, ttt, TIM_MAX);
 	    sh_error_handle( ShUtmpLoginMulti, FIL__, __LINE__, 0,
 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR)
@@ -858,6 +858,5 @@
 	{
 	  status = sh_utmp_login_r(user->name);
-	  /* sl_strlcpy(ttt, sh_unix_time (user->time), TIM_MAX); */
-	  (void) sl_strlcpy(ttt, sh_unix_time (ut->ut_time), TIM_MAX);
+	  (void) sh_unix_time (ut->ut_time, ttt, TIM_MAX);
 	  sh_error_handle( ShUtmpLogout, FIL__, __LINE__, 0,
 #if defined(HAVE_UTHOST) && defined(HAVE_UTADDR)
@@ -889,5 +888,5 @@
 	{
 	  (void) sl_strlcpy(terminated_line, ut->ut_line, UT_HOSTSIZE);
-	  (void) sl_strlcpy(ttt, sh_unix_time (ut->ut_time), TIM_MAX);
+	  (void) sh_unix_time (ut->ut_time, ttt, TIM_MAX);
 	  sh_error_handle( ShUtmpLogout, FIL__, __LINE__, 0,
 			   MSG_UT_LG3C,
@@ -920,5 +919,5 @@
       userlist         = user;
 
-      sl_strlcpy(ttt, sh_unix_time (user->time), TIM_MAX);
+      (void) sh_unix_time (user->time, ttt, TIM_MAX);
 
 
@@ -946,6 +945,5 @@
   else  /* probably a logout */
     {
-      sl_strlcpy(ttt, sh_unix_time (ut->ut_time), TIM_MAX);
-      /* sl_strlcpy(ttt, sh_unix_time (user->time), TIM_MAX); */
+      (void) sh_unix_time (ut->ut_time, ttt, TIM_MAX);
 
       sh_error_handle( ShUtmpLogout, FIL__, __LINE__, 0,
