X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fselinux-util.c;h=7c58985cd26ae29975e4e7fc5458a5e5dd6b12d6;hb=ce5792dac67c5ae5656f1f9665b777d44af4cb35;hp=1eddd17d2797ff797254aab1faf43c34f58affb4;hpb=a07e9cfb790f3f5f492f2ff895a9de65e2b00a09;p=elogind.git diff --git a/src/shared/selinux-util.c b/src/shared/selinux-util.c index 1eddd17d2..7c58985cd 100644 --- a/src/shared/selinux-util.c +++ b/src/shared/selinux-util.c @@ -20,7 +20,6 @@ ***/ #include -#include #include #include @@ -117,6 +116,7 @@ void mac_selinux_finish(void) { return; selabel_close(label_hnd); + label_hnd = NULL; #endif } @@ -146,7 +146,7 @@ int mac_selinux_fix(const char *path, bool ignore_enoent, bool ignore_erofs) { r = lsetfilecon(path, fcon); /* If the FS doesn't support labels, then exit without warning */ - if (r < 0 && errno == ENOTSUP) + if (r < 0 && errno == EOPNOTSUPP) return 0; } } @@ -233,7 +233,7 @@ int mac_selinux_get_our_label(char **label) { return r; } -int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, char **label) { +int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, const char *exec_label, char **label) { int r = -EOPNOTSUPP; #ifdef HAVE_SELINUX @@ -257,11 +257,7 @@ int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, char **label if (r < 0) return -errno; - r = getexeccon(&fcon); - if (r < 0) - return -errno; - - if (!fcon) { + if (!exec_label) { /* If there is no context set for next exec let's use context of target executable */ r = getfilecon(exe, &fcon); @@ -332,9 +328,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);