unix_integration: also check running SELinux mode (#1704)

For kanidm_unixd_tasks, check the current SELinux mode in addition to
kernel support. If SELinux is disabled at runtime, any attempts to query
the policy will fail, so also disable SELinux features if this is the
case.

Signed-off-by: Kenton Groombridge <concord@gentoo.org>
This commit is contained in:
Kenton Groombridge 2023-06-13 18:58:26 -04:00 committed by GitHub
parent cc5f21eee5
commit 3c421c240d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,9 +1,19 @@
use std::ffi::CString;
use selinux::{kernel_support, label::back_end::File, label::Labeler, KernelSupport};
use selinux::{
current_mode, kernel_support, label::back_end::File, label::Labeler, KernelSupport, SELinuxMode,
};
pub fn supported() -> bool {
return !matches!(kernel_support(), KernelSupport::Unsupported);
// check if the running kernel has SELinux support
if matches!(kernel_support(), KernelSupport::Unsupported) {
return false;
}
// check if SELinux is actually running
match current_mode() {
SELinuxMode::Permissive | SELinuxMode::Enforcing => true,
_ => false,
}
}
pub fn get_labeler() -> Result<Labeler<File>, String> {