X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Flabel.c;h=82f10b21bd7142ed2adddd83a186afc67b28be0c;hp=eae66149692fd584418f925f241e52005f3b237c;hb=4968105790c65af58d4ab42bffa2a4bedc0be8ee;hpb=c80d766c8072dd0be311dcd31c17f9719775be44 diff --git a/src/shared/label.c b/src/shared/label.c index eae661496..82f10b21b 100644 --- a/src/shared/label.c +++ b/src/shared/label.c @@ -19,23 +19,62 @@ along with systemd; If not, see . ***/ -#include "label.h" +#include "selinux-util.h" +#include "smack-util.h" #include "util.h" +#include "label.h" int label_fix(const char *path, bool ignore_enoent, bool ignore_erofs) { - int r = 0; + int r, q; + + r = mac_selinux_fix(path, ignore_enoent, ignore_erofs); + q = mac_smack_fix(path, ignore_enoent, ignore_erofs); + + if (r < 0) + return r; + if (q < 0) + return q; + + return 0; +} + +int mkdir_label(const char *path, mode_t mode) { + int r; + + assert(path); + + r = mac_selinux_create_file_prepare(path, S_IFDIR); + if (r < 0) + return r; + + if (mkdir(path, mode) < 0) + r = -errno; + + mac_selinux_create_file_clear(); + + if (r < 0) + return r; + + return mac_smack_fix(path, false, false); +} + +int symlink_label(const char *old_path, const char *new_path) { + int r; + + assert(old_path); + assert(new_path); + + r = mac_selinux_create_file_prepare(new_path, S_IFLNK); + if (r < 0) + return r; + + if (symlink(old_path, new_path) < 0) + r = -errno; - if (mac_selinux_use()) { - r = mac_selinux_fix(path, ignore_enoent, ignore_erofs); - if (r < 0) - return r; - } + mac_selinux_create_file_clear(); - if (mac_smack_use()) { - r = mac_smack_fix(path); - if (r < 0) - return r; - } + if (r < 0) + return r; - return r; + return mac_smack_fix(new_path, false, false); }