Index: trunk/src/slib.c
===================================================================
--- trunk/src/slib.c	(revision 76)
+++ trunk/src/slib.c	(revision 131)
@@ -1425,6 +1425,4 @@
 int sl_policy_get_real(char * user)
 {
-  struct passwd * tempres;
-
   SL_ENTER(_("sl_policy_get_real"));
   SL_REQUIRE(uids_are_stored == SL_FALSE, _("uids_are_stored == SL_FALSE"));
@@ -1433,5 +1431,12 @@
   if (euid == 0 || ruid == 0)
     {
-      tempres = sh_getpwnam(user);
+#if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R)
+      struct passwd    pwd;
+      char             buffer[SH_PWBUF_SIZE];
+      struct passwd *  tempres;
+      sh_getpwnam_r(user, &pwd, buffer, sizeof(buffer), &tempres);
+#else
+      struct passwd * tempres = sh_getpwnam(user);
+#endif
 
       SL_REQUIRE (NULL != tempres, _("tempres != NULL"));
@@ -1471,14 +1476,15 @@
   if (euid != ruid || egid != rgid)
     {
-      tempres = sh_getpwnam(user);
+#if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R)
+      struct passwd    pwd;
+      char             buffer[SH_PWBUF_SIZE];
+      struct passwd *  tempres;
+      sh_getpwnam_r(user, &pwd, buffer, sizeof(buffer), &tempres);
+#else
+      struct passwd * tempres = sh_getpwnam(user);
+#endif
 
       SL_REQUIRE (NULL != tempres, _("tempres != NULL"));
 
-#if 0
-      rgid = tempres->pw_gid;
-      ruid = tempres->pw_uid;
-      SL_REQUIRE(sl_unset_suid() == SL_ENONE, 
-		 _("sl_unset_suid() == SL_ENONE"));
-#endif
       SL_REQUIRE (sl_drop_privileges() == SL_ENONE,
 		  _("sl_drop_privileges() == SL_ENONE"));
@@ -2115,9 +2121,10 @@
   SL_IRETURN(SL_ENONE, _("sl_read_timeout_prep"));
 }
-  
-
-int sl_read_timeout (SL_TICKET ticket, void * buf_in, size_t count, 
-		     int timeout)
-{
+
+
+int sl_read_timeout_fd (int fd, void * buf_in, size_t count, 
+			int timeout, int is_nonblocking)
+{
+  int sflags;
   fd_set readfds;
   struct timeval tv;
@@ -2135,16 +2142,10 @@
   extern volatile int sig_termfast;
  
-  if (buf_in == NULL || SL_ISERROR(fd = get_the_fd(ticket)))
-    {
-      if (buf_in == NULL)
-	{
-	  TPT(( 0, FIL__, __LINE__, _("msg=<null buffer>")));
-	  return (SL_ENULL);
-	}
-      if (SL_ISERROR(fd = get_the_fd(ticket)))
-	{
-	  TPT(( 0, FIL__, __LINE__, _("msg=<ticket error> errno=<%d>"), fd));
-	  return (fd);
-	}
+  if (is_nonblocking == SL_FALSE)
+    {
+      /* set to non-blocking mode 
+       */
+      sflags = retry_fcntl(FIL__, __LINE__, fd, F_GETFL, 0);
+      retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags | O_NONBLOCK);
     }
 
@@ -2190,4 +2191,6 @@
 	      else
 		{
+		  if (is_nonblocking == SL_FALSE)
+		      retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags);
 		  return (SL_EREAD);
 		}
@@ -2203,8 +2206,12 @@
       else if (retval == 0)
 	{
+	  if (is_nonblocking == SL_FALSE)
+	      retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags);
 	  return (SL_TIMEOUT);
 	}
       else
 	{
+	  if (is_nonblocking == SL_FALSE)
+	      retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags);
 	  return (SL_EREAD);
 	}
@@ -2212,4 +2219,6 @@
       if (sig_termfast == 1) 
 	{
+	  if (is_nonblocking == SL_FALSE)
+	      retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags);
 	  return (SL_EREAD);
 	}
@@ -2220,9 +2229,35 @@
       if (tdiff > timeout)
 	{
+	  if (is_nonblocking == SL_FALSE)
+	      retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags);
 	  return (SL_TIMEOUT);
 	}
     }
 
+  if (is_nonblocking == SL_FALSE)
+    retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags);
   return ((int) bytes);
+}
+
+int sl_read_timeout (SL_TICKET ticket, void * buf_in, size_t count, 
+		     int timeout, int is_nonblocking)
+{
+  int    fd;
+ 
+  if (buf_in == NULL || SL_ISERROR(fd = get_the_fd(ticket)))
+    {
+      if (buf_in == NULL)
+	{
+	  TPT(( 0, FIL__, __LINE__, _("msg=<null buffer>")));
+	  return (SL_ENULL);
+	}
+      if (SL_ISERROR(fd = get_the_fd(ticket)))
+	{
+	  TPT(( 0, FIL__, __LINE__, _("msg=<ticket error> errno=<%d>"), fd));
+	  return (fd);
+	}
+    }
+
+  return sl_read_timeout_fd (fd, buf_in, count, timeout, is_nonblocking);
 }
 
