Index: trunk/src/slib.c
===================================================================
--- trunk/src/slib.c	(revision 34)
+++ trunk/src/slib.c	(revision 76)
@@ -48,4 +48,6 @@
 #define FD_ZERO(p)      memset((char *)(p), '\0', sizeof(*(p)))
 #endif
+
+#define SH_REAL_SET
 
 #include "slib.h"
@@ -566,16 +568,10 @@
   
 /*
- * A memset that does not get optimized away
+ * Have memset in a different translation unit (i.e. this) to prevent 
+ * it to get optimized away
  */
 void *sl_memset(void *s, int c, size_t n)
 {
-  volatile char *p = (char *) s;
-
-  if (s != NULL)
-    {
-      while (n--)
-	*p++ = c;
-    }
-  return s;
+  return memset(s, c,n);
 }
 
@@ -870,33 +866,33 @@
   register const char * q;
 
-  if (dst == NULL)
-    return SL_ENONE;
-  if (src == NULL || *src == '\0') 
-    return SL_ENONE;
-
-  if (siz > 0) {
-
-    /* How much free space do we have ?
-     */
-    dst_end  = strlen(dst);
-    dst_free = siz - dst_end - 1;
-
-    p = &dst[dst_end];
-    q = src;
-
-    while (dst_free > 0 && *q != '\0')
-      {
-	*p++ = *q++;
-	--dst_free;
-      }
-
-    /* NULL terminate dst.
-     */
-    *p = '\0';
-
-    if (*q != '\0') 
-      return SL_ETRUNC;
-  }
-
+  if (!(dst == NULL || src == NULL || *src == '\0'))
+    {
+      if (siz > 0) 
+	{
+
+	  /* How much free space do we have ?
+	   */
+	  dst_end  = strlen(dst);
+	  dst_free = siz - dst_end - 1;
+	  
+	  p = &dst[dst_end];
+	  q = src;
+	  
+	  while (dst_free > 0 && *q != '\0')
+	    {
+	      *p++ = *q++;
+	      --dst_free;
+	    }
+	
+	  /* NULL terminate dst.
+	   */
+	  *p = '\0';
+	
+	  if (*q == '\0')
+	    return SL_ENONE;
+	  else
+	    return SL_ETRUNC;
+	}
+    }
   return SL_ENONE;
 }
@@ -917,24 +913,27 @@
   /* SL_ENTER(_("sl_strlcpy")); */
 
-  if (dst == NULL)
-    return SL_ENULL;
-  if (src == NULL)
-    { 
+  if (!((dst == NULL) || (src == NULL))) 
+    {
+      if (siz > 0) {
+	/* copy siz-1 characters 
+	 */
+	(void) strncpy(dst, src, siz-1);
+
+	/* NULL terminate
+	 */
+	dst[siz-1] = '\0';
+      }
+      return SL_ENONE;
+    }
+  else if (src == NULL)
+    {
       if (siz > 0) 
 	dst[0] = '\0';
       return SL_ENONE;
     }
-
-
-  if (siz > 0) {
-    /* copy siz-1 characters 
-     */
-    (void) strncpy(dst, src, siz-1);
-
-    /* NULL terminate
-     */
-    dst[siz-1] = '\0';
-  }
-  return SL_ENONE;
+  else
+    {
+      return SL_ENULL;
+    } 
 }
 
@@ -1574,5 +1573,5 @@
 }
 
-SL_TICKET sl_make_ticket (int fd, char * filename)
+SL_TICKET sl_make_ticket (int fd, const char * filename)
 {
   size_t    len;
@@ -2376,4 +2375,21 @@
 }
 
+int sl_write_line_fast (SL_TICKET ticket, void * msg, long nbytes)
+{
+  int  status;
+  char * p = (char *) msg;
+
+  SL_ENTER(_("sl_write_line_fast"));
+
+  /* Here nbytes is strlen(msg), so p[nbytes] is the terminating '\0'
+   * Overwrite the terminator, write out, then write back the terminator.
+   */
+  p[nbytes] = '\n';
+  status = sl_write(ticket,  msg, nbytes+1);
+  p[nbytes] = '\0';
+
+  SL_IRETURN(status, _("sl_write_line_fast"));
+}
+
 
 /* ---------------------------------------------------------------- 
@@ -2389,5 +2405,4 @@
 extern char  tf_path[MAXFILENAME];	/* Error path for trust function. */
 extern uid_t tf_euid;	                /* Space for EUID of process.     */
-
 
 char * sl_error_string(int errorcode)
@@ -2490,7 +2505,59 @@
 }
 
+#include "sh_mem.h"
+extern char * sh_util_strdup (const char * str);
+
+struct sl_trustfile_store {
+  char * filename;
+  uid_t  teuid;
+  struct sl_trustfile_store * next;
+};
+
+static struct sl_trustfile_store * sl_trusted_files = NULL;
+
+void sl_add_trusted_file(char * filename, uid_t teuid)
+{
+  struct sl_trustfile_store *new = SH_ALLOC(sizeof(struct sl_trustfile_store));
+
+  new->filename = sh_util_strdup (filename);
+  new->teuid    = teuid;
+  new->next     = sl_trusted_files;
+
+  sl_trusted_files = new;
+  return;
+}
+
+char * sl_check_trusted_file(char * filename, uid_t teuid)
+{
+  struct sl_trustfile_store *new = sl_trusted_files;
+
+  while (new)
+    {
+      if ((new->teuid == teuid) && (0 == strcmp(new->filename, filename)))
+	return filename;
+      new = new->next;
+    }
+
+  return NULL;
+}
+
+void sl_clear_trusted_file(struct sl_trustfile_store * file)
+{
+  if (file)
+    {
+      if (file->next != NULL)
+	sl_clear_trusted_file(file->next);
+      SH_FREE(file->filename);
+      SH_FREE(file);
+    }
+  return;
+}
+
 int sl_trustfile_euid(char * filename, uid_t teuid)
 {
-  long status;
+  long          status;
+  static time_t old = 0;
+  static time_t now;
+
   SL_ENTER(_("sl_trustfile_euid"));
 
@@ -2499,6 +2566,24 @@
     SL_IRETURN(SL_EBADNAME, _("sl_trustfile_euid"));
 
+  now = time(NULL);
+  if (now < (old + 300))
+    {
+      if (NULL != sl_check_trusted_file(filename, teuid))
+	{
+	  sl_strlcpy(tf_path, filename, sizeof(tf_path));
+	  SL_IRETURN(SL_ENONE, _("sl_trustfile_euid"));
+	}
+    }
+  else
+    {
+      sl_clear_trusted_file(sl_trusted_files);
+      sl_trusted_files = NULL;
+      old = now;
+    }
+
   tf_euid = teuid;
   status = sl_trustfile(filename, NULL, NULL);
+  if (status == SL_ENONE)
+    sl_add_trusted_file(filename, teuid);
   SL_IRETURN(status, _("sl_trustfile_euid"));
 }
