diff options
author | David Herrmann <dh.herrmann@googlemail.com> | 2015-11-30 19:30:03 +0100 |
---|---|---|
committer | David Herrmann <dh.herrmann@googlemail.com> | 2015-11-30 19:30:03 +0100 |
commit | de418eb91cfa07f2d67f0eeaf0e787da4fa4feac (patch) | |
tree | ebae7c02386b958d754de33bddc6ec36fdc20fe3 /src/basic | |
parent | a00405285e5ee25d7532f66f470b0bb7fb8df7de (diff) | |
parent | 20ba6c2ebe083a6a5021b68622637c710ea12115 (diff) |
Merge pull request #2053 from poettering/selinux-fix
Two unrelated fixes
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/selinux-util.c | 20 | ||||
-rw-r--r-- | src/basic/selinux-util.h | 1 |
2 files changed, 16 insertions, 5 deletions
diff --git a/src/basic/selinux-util.c b/src/basic/selinux-util.c index e8ce5cfd96..7e4ae33efe 100644 --- a/src/basic/selinux-util.c +++ b/src/basic/selinux-util.c @@ -47,7 +47,7 @@ static struct selabel_handle *label_hnd = NULL; #define log_enforcing(...) log_full(security_getenforce() == 1 ? LOG_ERR : LOG_DEBUG, __VA_ARGS__) #endif -bool mac_selinux_use(void) { +bool mac_selinux_have(void) { #ifdef HAVE_SELINUX if (cached_use < 0) cached_use = is_selinux_enabled() > 0; @@ -58,6 +58,16 @@ bool mac_selinux_use(void) { #endif } +bool mac_selinux_use(void) { + if (!mac_selinux_have()) + return false; + + /* Never try to configure SELinux features if we aren't + * root */ + + return getuid() == 0; +} + void mac_selinux_retest(void) { #ifdef HAVE_SELINUX cached_use = -1; @@ -197,7 +207,7 @@ int mac_selinux_get_create_label_from_exe(const char *exe, char **label) { assert(exe); assert(label); - if (!mac_selinux_use()) + if (!mac_selinux_have()) return -EOPNOTSUPP; r = getcon_raw(&mycon); @@ -223,7 +233,7 @@ int mac_selinux_get_our_label(char **label) { assert(label); #ifdef HAVE_SELINUX - if (!mac_selinux_use()) + if (!mac_selinux_have()) return -EOPNOTSUPP; r = getcon_raw(label); @@ -247,7 +257,7 @@ int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, const char * assert(exe); assert(label); - if (!mac_selinux_use()) + if (!mac_selinux_have()) return -EOPNOTSUPP; r = getcon_raw(&mycon); @@ -302,7 +312,7 @@ char* mac_selinux_free(char *label) { if (!label) return NULL; - if (!mac_selinux_use()) + if (!mac_selinux_have()) return NULL; diff --git a/src/basic/selinux-util.h b/src/basic/selinux-util.h index d19984c5fe..95a2fcdbca 100644 --- a/src/basic/selinux-util.h +++ b/src/basic/selinux-util.h @@ -27,6 +27,7 @@ #include "macro.h" bool mac_selinux_use(void); +bool mac_selinux_have(void); void mac_selinux_retest(void); int mac_selinux_init(const char *prefix); |