bc4ae4
diff -up aide-0.15.1/src/do_md.c.prelinkwarn aide-0.15.1/src/do_md.c
bc4ae4
--- aide-0.15.1/src/do_md.c.prelinkwarn	2010-08-08 19:39:31.000000000 +0200
bc4ae4
+++ aide-0.15.1/src/do_md.c	2013-11-08 13:13:54.634961991 +0100
bc4ae4
@@ -70,6 +70,40 @@
bc4ae4
 #ifdef WITH_PRELINK
bc4ae4
 #include <sys/wait.h>
bc4ae4
 #include <gelf.h>
bc4ae4
+#include <stdbool.h>
bc4ae4
+
bc4ae4
+bool g_prelink_present = false;
bc4ae4
+bool g_prelink_detect = true;
bc4ae4
+bool g_noprelink_warn = true;
bc4ae4
+
bc4ae4
+bool prelink_present(void)
bc4ae4
+{
bc4ae4
+	/* don't perform the check if we already did it */
bc4ae4
+	if (!g_prelink_detect)
bc4ae4
+		return g_prelink_present;
bc4ae4
+
bc4ae4
+	/* check whether the prelink binary is present and executable */
bc4ae4
+	if (access(PRELINK_PATH, X_OK) == 0)
bc4ae4
+		g_prelink_present = true;
bc4ae4
+	else
bc4ae4
+		g_prelink_present = false;
bc4ae4
+
bc4ae4
+	g_prelink_detect = false;
bc4ae4
+	return g_prelink_present;
bc4ae4
+}
bc4ae4
+
bc4ae4
+void noprelink_warn(void)
bc4ae4
+{
bc4ae4
+	if (g_noprelink_warn) {
bc4ae4
+		error(0,
bc4ae4
+		      "WARNING: AIDE detected prelinked binary objects on your"
bc4ae4
+		      " system but the prelink tool (%s) is missing!\n", PRELINK_PATH);
bc4ae4
+		error(0,
bc4ae4
+		      "WARNING: prelinked files will be processed without a prelink undo operation!"
bc4ae4
+		      " Please install prelink to fix this.\n");
bc4ae4
+		g_noprelink_warn = false;
bc4ae4
+	}
bc4ae4
+}
bc4ae4
 
bc4ae4
 /*
bc4ae4
  *  Is file descriptor prelinked binary/library?
bc4ae4
@@ -265,12 +299,19 @@ void calc_md(struct AIDE_STAT_TYPE* old_
bc4ae4
      */
bc4ae4
     pid=0;
bc4ae4
     if ( is_prelinked(filedes) ) {
bc4ae4
-      close(filedes);
bc4ae4
-      pid = open_prelinked(line->filename, &filedes);
bc4ae4
-      if (pid == 0) {
bc4ae4
-        error(0, "Error on starting prelink undo\n");
bc4ae4
-	return;
bc4ae4
-      }
bc4ae4
+	    /* first detect whether the prelink binary is available */
bc4ae4
+	    if (prelink_present()) {
bc4ae4
+		    close(filedes);
bc4ae4
+		    pid = open_prelinked(line->filename, &filedes);
bc4ae4
+		    if (pid == 0) {
bc4ae4
+			    error(0, "Error on starting prelink undo\n");
bc4ae4
+			    return;
bc4ae4
+		    }
bc4ae4
+	    } else {
bc4ae4
+		    /* we've detected a prelinked file but the prelink binary is not available */
bc4ae4
+		    /* warn the user about this situation (once) and process the file as is */
bc4ae4
+		    noprelink_warn();
bc4ae4
+	    }
bc4ae4
     }
bc4ae4
 #endif
bc4ae4
 
bc4ae4
@@ -296,6 +337,7 @@ void calc_md(struct AIDE_STAT_TYPE* old_
bc4ae4
 #ifdef __hpux
bc4ae4
            buf = mmap(0,r_size,PROT_READ,MAP_PRIVATE,filedes,curpos);
bc4ae4
 #else
bc4ae4
+
bc4ae4
            buf = mmap(0,r_size,PROT_READ,MAP_SHARED,filedes,curpos);
bc4ae4
 #endif
bc4ae4
            curpos+=r_size;