summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2014-11-06 16:48:11 +0100
committerAnthony G. Basile <blueness@gentoo.org>2014-11-14 14:24:11 -0500
commit5ce04ca64c9cab96901f3eb6f6000aabf5d17e43 (patch)
treefc84f77e5cc2304757c10c92ff33194c72a2391a /src
parentafd5b52fcf667b771d90223992ca0454afdde866 (diff)
shared: create files even if the SELinux policy has no context for them
The SELinux policy defines no context for some files. E.g.: $ matchpathcon /run/lock/subsys /dev/mqueue /run/lock/subsys <<none>> /dev/mqueue <<none>> We still need to be able to create them. In this case selabel_lookup_raw() returns ENOENT. We should then skip setfscreatecon(), but still return success. It was broken since c34255bdb2 ("label: unify code to make directories, symlinks"). Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src')
-rw-r--r--src/shared/selinux-util.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/shared/selinux-util.c b/src/shared/selinux-util.c
index e2ccef2865..a374c277a8 100644
--- a/src/shared/selinux-util.c
+++ b/src/shared/selinux-util.c
@@ -330,9 +330,13 @@ int mac_selinux_create_file_prepare(const char *path, mode_t mode) {
r = selabel_lookup_raw(label_hnd, &filecon, newpath, mode);
}
- if (r < 0 && errno != ENOENT)
+ /* No context specified by the policy? Proceed without setting it. */
+ if (r < 0 && errno == ENOENT)
+ return 0;
+
+ if (r < 0)
r = -errno;
- else if (r == 0) {
+ else {
r = setfscreatecon(filecon);
if (r < 0) {
log_enforcing("Failed to set SELinux security context %s for %s: %m", filecon, path);