From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id F17661392EF for ; Wed, 16 Jul 2014 23:01:31 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8A994E09FE; Wed, 16 Jul 2014 23:01:31 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 0EAC1E09FE for ; Wed, 16 Jul 2014 23:01:30 +0000 (UTC) Received: from spoonbill.gentoo.org (spoonbill.gentoo.org [81.93.255.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 11A513400F3 for ; Wed, 16 Jul 2014 23:01:30 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by spoonbill.gentoo.org (Postfix) with ESMTP id 1EE44193E5 for ; Wed, 16 Jul 2014 23:01:28 +0000 (UTC) From: "William Hubbs" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "William Hubbs" Message-ID: <1405551565.89907b60bac51db2cda1afe4555676577ef498a8.williamh@OpenRC> Subject: [gentoo-commits] proj/openrc:master commit in: src/rc/ X-VCS-Repository: proj/openrc X-VCS-Files: src/rc/rc-selinux.c src/rc/rc-selinux.h src/rc/runscript.c X-VCS-Directories: src/rc/ X-VCS-Committer: williamh X-VCS-Committer-Name: William Hubbs X-VCS-Revision: 89907b60bac51db2cda1afe4555676577ef498a8 X-VCS-Branch: master Date: Wed, 16 Jul 2014 23:01:28 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 46bf7d5e-234b-4408-9b65-2fb41b969e65 X-Archives-Hash: 3e09cc428e8f42372fefd1f093bca790 commit: 89907b60bac51db2cda1afe4555676577ef498a8 Author: Jason Zaman perfinion com> AuthorDate: Wed Jul 16 20:46:25 2014 +0000 Commit: William Hubbs gentoo org> CommitDate: Wed Jul 16 22:59:25 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=89907b60 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 --- src/rc/rc-selinux.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/rc/rc-selinux.h | 2 ++ src/rc/runscript.c | 45 +++++---------------------------------------- 3 files changed, 48 insertions(+), 40 deletions(-) diff --git a/src/rc/rc-selinux.c b/src/rc/rc-selinux.c index 7c1ee80..eae030d 100644 --- a/src/rc/rc-selinux.c +++ b/src/rc/rc-selinux.c @@ -30,14 +30,24 @@ #include #include +#include #include #include #include +#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); +} diff --git a/src/rc/rc-selinux.h b/src/rc/rc-selinux.h index 69624b3..8cf73b0 100644 --- a/src/rc/rc-selinux.h +++ b/src/rc/rc-selinux.h @@ -30,4 +30,6 @@ int selinux_util_open(void); int selinux_util_label(const char *path); int selinux_util_close(void); +void selinux_setup(int argc, char **argv); + #endif diff --git a/src/rc/runscript.c b/src/rc/runscript.c index 981e606..03d851e 100644 --- a/src/rc/runscript.c +++ b/src/rc/runscript.c @@ -36,7 +36,6 @@ #include #include -#include #include #include #include @@ -66,7 +65,9 @@ #include "rc-misc.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" @@ -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_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 handle_signal(int sig) { @@ -1224,9 +1189,9 @@ openrc_run(int argc, char **argv) eprefix(prefix); } -#ifdef __linux__ +#ifdef HAVE_SELINUX /* Ok, we are ready to go, so setup selinux if applicable */ - setup_selinux(argc, argv); + selinux_setup(argc, argv); #endif deps = true;