aboutsummaryrefslogtreecommitdiff
path: root/src/rc/rc-selinux.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rc/rc-selinux.c')
-rw-r--r--src/rc/rc-selinux.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/rc/rc-selinux.c b/src/rc/rc-selinux.c
index 7c1ee80d..eae030d0 100644
--- a/src/rc/rc-selinux.c
+++ b/src/rc/rc-selinux.c
@@ -30,14 +30,24 @@
#include <stddef.h>
#include <errno.h>
+#include <dlfcn.h>
#include <sys/stat.h>
#include <selinux/selinux.h>
#include <selinux/label.h>
+#include "einfo.h"
+#include "rc.h"
+#include "rc-misc.h"
+#include "rc-plugin.h"
#include "rc-selinux.h"
+#define SELINUX_LIB RC_LIBDIR "/runscript_selinux.so"
+
+static void (*selinux_run_init_old) (void);
+static void (*selinux_run_init_new) (int argc, char **argv);
+
static struct selabel_handle *hnd = NULL;
int selinux_util_label(const char *path)
@@ -121,3 +131,34 @@ int selinux_util_close(void)
return 0;
}
+
+void selinux_setup(int argc, char **argv)
+{
+ void *lib_handle = NULL;
+
+ if (!exists(SELINUX_LIB))
+ return;
+
+ lib_handle = dlopen(SELINUX_LIB, RTLD_NOW | RTLD_GLOBAL);
+ if (!lib_handle) {
+ eerror("dlopen: %s", dlerror());
+ return;
+ }
+
+ selinux_run_init_old = (void (*)(void))
+ dlfunc(lib_handle, "selinux_runscript");
+ selinux_run_init_new = (void (*)(int, char **))
+ dlfunc(lib_handle, "selinux_runscript2");
+
+ /* Use new run_init if it exists, else fall back to old */
+ if (selinux_run_init_new)
+ selinux_run_init_new(argc, argv);
+ else if (selinux_run_init_old)
+ selinux_run_init_old();
+ else
+ /* This shouldnt happen... probably corrupt lib */
+ eerrorx
+ ("run_init is missing from runscript_selinux.so!");
+
+ dlclose(lib_handle);
+}