Blame SOURCES/aide-0.15.1-prelinkwarn.patch

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