summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-07-10 21:37:44 +0200
committerChristian Göttsche <cgzones@googlemail.com>2020-07-10 21:55:13 +0200
commit7a3e4dc38b3e3ef60d4886aa2c1cb871f49bfee9 (patch)
tree84abf75a514c4a5992f3b346541d32369d423535 /src
parent5149990e1f6d3c456e3664011778d09734faacfd (diff)
downloadsystemd-7a3e4dc38b3e3ef60d4886aa2c1cb871f49bfee9.tar.gz
basic: add helper function mknod_label()
Diffstat (limited to 'src')
-rw-r--r--src/basic/label.c20
-rw-r--r--src/basic/label.h1
2 files changed, 21 insertions, 0 deletions
diff --git a/src/basic/label.c b/src/basic/label.c
index 1fce7718d4..741c43c2b9 100644
--- a/src/basic/label.c
+++ b/src/basic/label.c
@@ -45,6 +45,26 @@ int symlink_label(const char *old_path, const char *new_path) {
return mac_smack_fix(new_path, 0);
}
+int mknod_label(const char *pathname, mode_t mode, dev_t dev) {
+ int r;
+
+ assert(pathname);
+
+ r = mac_selinux_create_file_prepare(pathname, mode);
+ if (r < 0)
+ return r;
+
+ if (mknod(pathname, mode, dev) < 0)
+ r = -errno;
+
+ mac_selinux_create_file_clear();
+
+ if (r < 0)
+ return r;
+
+ return mac_smack_fix(pathname, 0);
+}
+
int btrfs_subvol_make_label(const char *path) {
int r;
diff --git a/src/basic/label.h b/src/basic/label.h
index a6f9074b28..6dc0f710ef 100644
--- a/src/basic/label.h
+++ b/src/basic/label.h
@@ -17,5 +17,6 @@ static inline 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 mknod_label(const char *pathname, mode_t mode, dev_t dev);
int btrfs_subvol_make_label(const char *path);