Blame SOURCES/aide-0.15.1-prelinkwarn.patch

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