X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Futil.c;h=ee7749be5ef9c4751acdb4bc3ffcf8de64890dd7;hp=39dca0d4587ffdea104964a078be4e133506b017;hb=95978cf8a66b0d03271f7da2399a3b588db0c71d;hpb=5b1fe56a8b5543df614091d3cbcdb6b87e294dc0 diff --git a/src/util.c b/src/util.c index 39dca0d45..ee7749be5 100644 --- a/src/util.c +++ b/src/util.c @@ -62,11 +62,11 @@ static struct selabel_handle *label_hnd = NULL; -static inline int use_selinux(void) { +static inline bool use_selinux(void) { static int use_selinux_ind = -1; - if (use_selinux_ind == -1) - use_selinux_ind = (is_selinux_enabled() == 1); + if (use_selinux_ind < 0) + use_selinux_ind = is_selinux_enabled() > 0; return use_selinux_ind; } @@ -84,6 +84,8 @@ static int label_get_file_label_from_path( r = getfilecon(path, &dir_con); if (r >= 0) { r = -1; + errno = EINVAL; + if ((sclass = string_to_security_class(class)) != 0) r = security_compute_create((security_context_t) label, dir_con, sclass, fcon); } @@ -122,7 +124,7 @@ int label_fix(const char *path) { struct stat st; security_context_t fcon; - if (!use_selinux()) + if (!use_selinux() || !label_hnd) return 0; r = lstat(path, &st); @@ -147,7 +149,7 @@ int label_fix(const char *path) { void label_finish(void) { #ifdef HAVE_SELINUX - if (use_selinux()) + if (use_selinux() && label_hnd) selabel_close(label_hnd); #endif } @@ -270,7 +272,7 @@ static int label_mkdir( int r; security_context_t fcon = NULL; - if (use_selinux()) { + if (use_selinux() && label_hnd) { if (path[0] == '/') { r = selabel_lookup_raw(label_hnd, &fcon, path, mode); } @@ -300,7 +302,7 @@ static int label_mkdir( r = mkdir(path, mode); finish: - if (use_selinux()) { + if (use_selinux() && label_hnd) { setfscreatecon(NULL); freecon(fcon); }