Skip to content

Commit

Permalink
libselinux: is_selinux_enabled: Add /etc/selinux/config test.
Browse files Browse the repository at this point in the history
To avoid regressions such as the one reported in:
https://bugzilla.redhat.com/show_bug.cgi?id=1219045
add a test for /etc/selinux/config to is_selinux_enabled().

This ensures that systems that do not install selinux-policy
will continue to return 0 from is_selinux_enabled().

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
  • Loading branch information
stephensmalley committed May 11, 2015
1 parent 26e05da commit c08c4ea
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions libselinux/src/enabled.c
Expand Up @@ -14,7 +14,11 @@ int is_selinux_enabled(void)
/* init_selinuxmnt() gets called before this function. We
* will assume that if a selinux file system is mounted, then
* selinux is enabled. */
#ifdef ANDROID
return (selinux_mnt ? 1 : 0);
#else
return (selinux_mnt && has_selinux_config);
#endif
}

hidden_def(is_selinux_enabled)
Expand Down
5 changes: 5 additions & 0 deletions libselinux/src/init.c
Expand Up @@ -22,6 +22,8 @@ char *selinux_mnt = NULL;
int selinux_page_size = 0;
int obj_class_compat = 1;

int has_selinux_config = 0;

/* Verify the mount point for selinux file system has a selinuxfs.
If the file system:
* Exist,
Expand Down Expand Up @@ -165,6 +167,9 @@ static void init_lib(void)
{
selinux_page_size = sysconf(_SC_PAGE_SIZE);
init_selinuxmnt();
#ifndef ANDROID
has_selinux_config = (access(SELINUXCONFIG, F_OK) == 0);
#endif
}

static void fini_lib(void) __attribute__ ((destructor));
Expand Down
2 changes: 0 additions & 2 deletions libselinux/src/selinux_config.c
Expand Up @@ -13,8 +13,6 @@
#include "selinux_internal.h"
#include "get_default_type_internal.h"

#define SELINUXDIR "/etc/selinux/"
#define SELINUXCONFIG SELINUXDIR "config"
#define SELINUXDEFAULT "targeted"
#define SELINUXTYPETAG "SELINUXTYPE="
#define SELINUXTAG "SELINUX="
Expand Down
5 changes: 5 additions & 0 deletions libselinux/src/selinux_internal.h
Expand Up @@ -137,3 +137,8 @@ extern int selinux_page_size hidden;
if (pthread_setspecific != NULL) \
pthread_setspecific(KEY, VALUE); \
} while (0)

#define SELINUXDIR "/etc/selinux/"
#define SELINUXCONFIG SELINUXDIR "config"

extern int has_selinux_config hidden;

0 comments on commit c08c4ea

Please sign in to comment.