Blame SOURCES/aide-0.15.1-prelinkwarn.patch

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