Permalink
Browse files

basic/label: introduce mkdirat_label()/mkdirat_errno_wrapper() helpers

  • Loading branch information...
fbuihuu committed Apr 27, 2018
1 parent 7e531a5 commit 1e9126316fa10f8f1e2d40b90c77fb63fe10f781
Showing with 25 additions and 0 deletions.
  1. +1 −0 src/basic/label.h
  2. +17 −0 src/basic/mkdir-label.c
  3. +6 −0 src/basic/mkdir.c
  4. +1 −0 src/basic/mkdir.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);
@@ -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);
}
@@ -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);
}
@@ -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);

0 comments on commit 1e91263

Please sign in to comment.