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