2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2013-07-26 03:34:18 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2017-12-16 13:32:42 +01:00
|
|
|
#include <sys/stat.h>
|
2015-11-30 21:43:37 +01:00
|
|
|
#include <sys/types.h>
|
2015-11-16 22:09:36 +01:00
|
|
|
#include <unistd.h>
|
2013-07-26 03:34:18 +02:00
|
|
|
|
|
|
|
#include "label.h"
|
2017-12-16 13:32:42 +01:00
|
|
|
#include "macro.h"
|
2013-07-26 03:34:18 +02:00
|
|
|
#include "mkdir.h"
|
2017-12-16 13:32:42 +01:00
|
|
|
#include "selinux-util.h"
|
|
|
|
#include "smack-util.h"
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
r = mkdir_errno_wrapper(path, mode);
|
|
|
|
mac_selinux_create_file_clear();
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2018-03-27 07:38:26 +02:00
|
|
|
return mac_smack_fix(path, 0);
|
2017-12-16 13:32:42 +01:00
|
|
|
}
|
2013-07-26 03:34:18 +02:00
|
|
|
|
2018-04-27 12:55:56 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-03-22 12:38:01 +01:00
|
|
|
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);
|
2013-07-26 03:34:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int mkdir_parents_label(const char *path, mode_t mode) {
|
2014-10-23 19:58:45 +02:00
|
|
|
return mkdir_parents_internal(NULL, path, mode, mkdir_label);
|
2013-07-26 03:34:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int mkdir_p_label(const char *path, mode_t mode) {
|
2014-10-23 19:58:45 +02:00
|
|
|
return mkdir_p_internal(NULL, path, mode, mkdir_label);
|
2013-07-26 03:34:18 +02:00
|
|
|
}
|