1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 
3 #include <sys/stat.h>
4 
5 #include "mkdir-label.h"
6 #include "selinux-util.h"
7 #include "smack-util.h"
8 #include "user-util.h"
9 
mkdirat_label(int dirfd,const char * path,mode_t mode)10 int mkdirat_label(int dirfd, const char *path, mode_t mode) {
11         int r;
12 
13         assert(path);
14 
15         r = mac_selinux_create_file_prepare_at(dirfd, path, S_IFDIR);
16         if (r < 0)
17                 return r;
18 
19         r = mkdirat_errno_wrapper(dirfd, path, mode);
20         mac_selinux_create_file_clear();
21         if (r < 0)
22                 return r;
23 
24         return mac_smack_fix_at(dirfd, path, 0);
25 }
26 
mkdir_safe_label(const char * path,mode_t mode,uid_t uid,gid_t gid,MkdirFlags flags)27 int mkdir_safe_label(const char *path, mode_t mode, uid_t uid, gid_t gid, MkdirFlags flags) {
28         return mkdir_safe_internal(path, mode, uid, gid, flags, mkdirat_label);
29 }
30 
mkdir_parents_label(const char * path,mode_t mode)31 int mkdir_parents_label(const char *path, mode_t mode) {
32         return mkdir_parents_internal(NULL, path, mode, UID_INVALID, UID_INVALID, 0, mkdirat_label);
33 }
34 
mkdir_p_label(const char * path,mode_t mode)35 int mkdir_p_label(const char *path, mode_t mode) {
36         return mkdir_p_internal(NULL, path, mode, UID_INVALID, UID_INVALID, 0, mkdirat_label);
37 }
38