Index: /trunk/config.h.in
===================================================================
--- /trunk/config.h.in	(revision 563)
+++ /trunk/config.h.in	(revision 564)
@@ -770,4 +770,7 @@
 /* Define if you have SA_SIGINFO */
 #undef HAVE_SA_SIGINFO
+
+/* Define to 1 if you have the `scandir' function. */
+#undef HAVE_SCANDIR
 
 /* Define to 1 if you have the <sched.h> header file. */
Index: /trunk/configure.ac
===================================================================
--- /trunk/configure.ac	(revision 563)
+++ /trunk/configure.ac	(revision 564)
@@ -12,5 +12,5 @@
 dnl start
 dnl
-AM_INIT_AUTOMAKE(samhain, 4.4.3)
+AM_INIT_AUTOMAKE(samhain, 4.4.4)
 AC_DEFINE([SAMHAIN], 1, [Application is samhain])
 AC_CANONICAL_HOST
@@ -391,5 +391,5 @@
 	strerror_r getgrgid_r getpwnam_r getpwuid_r \
 	gmtime_r localtime_r rand_r readdir_r strtok_r \
-	mincore posix_fadvise inotify_init1
+	mincore posix_fadvise inotify_init1 scandir
 )
 AC_CHECK_FUNC(statfs, AC_DEFINE(HAVE_STATFS) statfs="yes",  statfs="no")
@@ -1140,5 +1140,5 @@
 # this is from the snort configure.in
 #
-AC_DEFUN(FAIL_MESSAGE,[
+AC_DEFUN([FAIL_MESSAGE],[
    echo 
    echo
Index: /trunk/docs/Changelog
===================================================================
--- /trunk/docs/Changelog	(revision 563)
+++ /trunk/docs/Changelog	(revision 564)
@@ -3,4 +3,6 @@
 	* fix bug with signify-openbsd in client/server setup (reported
 	by Sdoba)
+	* patch by K. Hacene for reproducible database generation
+	* fix recognition of invalid compiler options in configure.ac
 
 4.4.3:
Index: /trunk/src/sh_dbIO.c
===================================================================
--- /trunk/src/sh_dbIO.c	(revision 563)
+++ /trunk/src/sh_dbIO.c	(revision 564)
@@ -1512,8 +1512,7 @@
  	}
     }
-	 
-  if (!buf) {
-    memset(&p, 0, sizeof(sh_filestore_t));
-  }
+
+  /* unconditionally initialize the structure */
+  memset(&p, 0, sizeof(sh_filestore_t));
 
   if (buf != NULL) 
Index: /trunk/src/sh_files.c
===================================================================
--- /trunk/src/sh_files.c	(revision 563)
+++ /trunk/src/sh_files.c	(revision 564)
@@ -20,5 +20,35 @@
 #include "config_xor.h"
 
-#if defined(HAVE_PTHREAD_MUTEX_RECURSIVE)
+#if defined(HAVE_PTHREAD_MUTEX_RECURSIVE) && defined(HAVE_DIRENT_H) && defined(HAVE_SCANDIR)
+
+/* Linux */
+#if defined(__linux__)
+#define _XOPEN_SOURCE 700
+#define SH_USE_SCANDIR 1
+
+/* FreeBSD */
+#elif defined(__FreeBSD__)
+
+#if __FreeBSD__ >= 8
+#define __XSI_VISIBLE 700
+#define SH_USE_SCANDIR 1
+#endif
+
+/* OpenBSD */
+#elif defined(__OpenBSD__)
+#define __POSIX_VISIBLE 200809
+#define SH_USE_SCANDIR 1
+
+#elif defined(__NetBSD__)
+#define _NETBSD_SOURCE
+#define SH_USE_SCANDIR 1
+
+/* other os */
+#else
+#define _XOPEN_SOURCE 500
+
+#endif
+
+#elif defined(HAVE_PTHREAD_MUTEX_RECURSIVE)
 #define _XOPEN_SOURCE 500
 #endif
@@ -36,5 +66,4 @@
 #include <sys/types.h>
 #include <unistd.h>
-#include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -2081,4 +2110,8 @@
   DIR *           thisDir = NULL;
   struct dirent * thisEntry;
+#if defined(SH_USE_SCANDIR)
+  struct dirent **entryList;
+  int             entry;
+#endif
   int             status;
   int             dummy = S_FALSE;
@@ -2267,6 +2300,13 @@
   dirlist_orig = NULL;
 
+#if defined(SH_USE_SCANDIR)
+  entry = scandir(iname, &entryList, 0, alphasort);
+  while(entry > 0) { /* scandir() may return -1 on error! */
+      entry--;
+      thisEntry = entryList[entry];
+#else
   do {
       thisEntry = readdir (thisDir);
+#endif
       if (thisEntry != NULL) 
 	{
@@ -2284,6 +2324,9 @@
 	  dirlist = addto_sh_dirlist (thisEntry, dirlist);
 	}
-  } while (thisEntry != NULL);
-
+  }
+#if !defined(SH_USE_SCANDIR)  
+  while (thisEntry != NULL);
+#endif
+  
   SH_MUTEX_UNLOCK(mutex_readdir);
 
