diff options
author | Franck Bui <fbui@suse.com> | 2018-04-27 12:55:56 +0200 |
---|---|---|
committer | Franck Bui <fbui@suse.com> | 2018-07-30 15:54:03 +0200 |
commit | 1e9126316fa10f8f1e2d40b90c77fb63fe10f781 (patch) | |
tree | c879154ba97f1e023d0908b3e98da1431ae4670c /src | |
parent | 7e531a5265687aef5177b070c36ca4ceab42e768 (diff) | |
download | systemd-1e9126316fa10f8f1e2d40b90c77fb63fe10f781.tar.gz systemd-1e9126316fa10f8f1e2d40b90c77fb63fe10f781.tar.bz2 systemd-1e9126316fa10f8f1e2d40b90c77fb63fe10f781.zip |
basic/label: introduce mkdirat_label()/mkdirat_errno_wrapper() helpers
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/label.h | 1 | ||||
-rw-r--r-- | src/basic/mkdir-label.c | 17 | ||||
-rw-r--r-- | src/basic/mkdir.c | 6 | ||||
-rw-r--r-- | src/basic/mkdir.h | 1 |
4 files changed, 25 insertions, 0 deletions
diff --git a/src/basic/label.h b/src/basic/label.h index 08fd109bcf..594fd65974 100644 --- a/src/basic/label.h +++ b/src/basic/label.h @@ -12,6 +12,7 @@ typedef enum LabelFixFlags { int label_fix(const char *path, LabelFixFlags flags); int mkdir_label(const char *path, mode_t mode); +int mkdirat_label(int dirfd, const char *path, mode_t mode); int symlink_label(const char *old_path, const char *new_path); int btrfs_subvol_make_label(const char *path); diff --git a/src/basic/mkdir-label.c b/src/basic/mkdir-label.c index 1d51e92e9a..0eba7fc514 100644 --- a/src/basic/mkdir-label.c +++ b/src/basic/mkdir-label.c @@ -28,6 +28,23 @@ int mkdir_label(const char *path, mode_t mode) { return mac_smack_fix(path, 0); } +int mkdirat_label(int dirfd, const char *path, mode_t mode) { + int r; + + assert(path); + + r = mac_selinux_create_file_prepare_at(dirfd, path, S_IFDIR); + if (r < 0) + return r; + + r = mkdirat_errno_wrapper(dirfd, path, mode); + mac_selinux_create_file_clear(); + if (r < 0) + return r; + + return mac_smack_fix_at(dirfd, path, 0); +} + int mkdir_safe_label(const char *path, mode_t mode, uid_t uid, gid_t gid, MkdirFlags flags) { return mkdir_safe_internal(path, mode, uid, gid, flags, mkdir_label); } diff --git a/src/basic/mkdir.c b/src/basic/mkdir.c index 6ab1b4422b..4bb65d5838 100644 --- a/src/basic/mkdir.c +++ b/src/basic/mkdir.c @@ -80,6 +80,12 @@ int mkdir_errno_wrapper(const char *pathname, mode_t mode) { return 0; } +int mkdirat_errno_wrapper(int dirfd, const char *pathname, mode_t mode) { + if (mkdirat(dirfd, pathname, mode) < 0) + return -errno; + return 0; +} + int mkdir_safe(const char *path, mode_t mode, uid_t uid, gid_t gid, MkdirFlags flags) { return mkdir_safe_internal(path, mode, uid, gid, flags, mkdir_errno_wrapper); } diff --git a/src/basic/mkdir.h b/src/basic/mkdir.h index bdca15460e..eb54853ea7 100644 --- a/src/basic/mkdir.h +++ b/src/basic/mkdir.h @@ -9,6 +9,7 @@ typedef enum MkdirFlags { } MkdirFlags; int mkdir_errno_wrapper(const char *pathname, mode_t mode); +int mkdirat_errno_wrapper(int dirfd, const char *pathname, mode_t mode); int mkdir_safe(const char *path, mode_t mode, uid_t uid, gid_t gid, MkdirFlags flags); int mkdir_parents(const char *path, mode_t mode); int mkdir_p(const char *path, mode_t mode); |