move the selinux_setup function into rc-selinux

X-Gentoo-Bug: 516956
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=516956
This commit is contained in:
Jason Zaman 2014-07-17 00:46:25 +04:00 committed by William Hubbs
parent a94a9740d5
commit 89907b60ba
3 changed files with 48 additions and 40 deletions

View File

@ -30,14 +30,24 @@
#include <stddef.h> #include <stddef.h>
#include <errno.h> #include <errno.h>
#include <dlfcn.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <selinux/selinux.h> #include <selinux/selinux.h>
#include <selinux/label.h> #include <selinux/label.h>
#include "einfo.h"
#include "rc.h"
#include "rc-misc.h"
#include "rc-plugin.h"
#include "rc-selinux.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; static struct selabel_handle *hnd = NULL;
int selinux_util_label(const char *path) int selinux_util_label(const char *path)
@ -121,3 +131,34 @@ int selinux_util_close(void)
return 0; 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);
}

View File

@ -30,4 +30,6 @@ int selinux_util_open(void);
int selinux_util_label(const char *path); int selinux_util_label(const char *path);
int selinux_util_close(void); int selinux_util_close(void);
void selinux_setup(int argc, char **argv);
#endif #endif

View File

@ -36,7 +36,6 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <ctype.h> #include <ctype.h>
#include <dlfcn.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <fnmatch.h> #include <fnmatch.h>
@ -66,7 +65,9 @@
#include "rc-misc.h" #include "rc-misc.h"
#include "rc-plugin.h" #include "rc-plugin.h"
#define SELINUX_LIB RC_LIBDIR "/runscript_selinux.so" #ifdef HAVE_SELINUX
#include "rc-selinux.h"
#endif
#define PREFIX_LOCK RC_SVCDIR "/prefix.lock" #define PREFIX_LOCK RC_SVCDIR "/prefix.lock"
@ -88,42 +89,6 @@ static int signal_pipe[2] = { -1, -1 };
static RC_STRINGLIST *types_b, *types_n, *types_nu, *types_nua, *types_m; static RC_STRINGLIST *types_b, *types_n, *types_nu, *types_nua, *types_m;
static RC_STRINGLIST *types_mua = NULL; static RC_STRINGLIST *types_mua = NULL;
#ifdef __linux__
static void (*selinux_run_init_old)(void);
static void (*selinux_run_init_new)(int argc, char **argv);
static void
setup_selinux(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);
}
#endif
static void static void
handle_signal(int sig) handle_signal(int sig)
{ {
@ -1224,9 +1189,9 @@ openrc_run(int argc, char **argv)
eprefix(prefix); eprefix(prefix);
} }
#ifdef __linux__ #ifdef HAVE_SELINUX
/* Ok, we are ready to go, so setup selinux if applicable */ /* Ok, we are ready to go, so setup selinux if applicable */
setup_selinux(argc, argv); selinux_setup(argc, argv);
#endif #endif
deps = true; deps = true;