]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/label.c
license: LGPL-2.1+ -> LGPL-2.1-or-later
[thirdparty/systemd.git] / src / basic / label.c
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
e51bc1a2 2
11c3a366
TA
3#include <errno.h>
4#include <sys/stat.h>
5#include <unistd.h>
6
de2e28d8 7#include "btrfs-util.h"
a3f5fd96 8#include "fs-util.h"
cf0fbc49 9#include "label.h"
93cc7779 10#include "macro.h"
d7b8eec7
LP
11#include "selinux-util.h"
12#include "smack-util.h"
b9c1bc28 13
c3151977 14int label_fix_container(const char *path, const char *inside_path, LabelFixFlags flags) {
5dfc5461 15 int r, q;
b9c1bc28 16
c3151977
TM
17 r = mac_selinux_fix_container(path, inside_path, flags);
18 q = mac_smack_fix_container(path, inside_path, flags);
b9c1bc28 19
5dfc5461
LP
20 if (r < 0)
21 return r;
22 if (q < 0)
23 return q;
e51bc1a2 24
5dfc5461 25 return 0;
e51bc1a2 26}
c34255bd 27
c34255bd
LP
28int symlink_label(const char *old_path, const char *new_path) {
29 int r;
30
31 assert(old_path);
32 assert(new_path);
33
34 r = mac_selinux_create_file_prepare(new_path, S_IFLNK);
35 if (r < 0)
36 return r;
37
38 if (symlink(old_path, new_path) < 0)
39 r = -errno;
40
41 mac_selinux_create_file_clear();
42
43 if (r < 0)
44 return r;
45
08c84981 46 return mac_smack_fix(new_path, 0);
c34255bd 47}
de2e28d8 48
a3f5fd96
CG
49int symlink_atomic_label(const char *from, const char *to) {
50 int r;
51
52 assert(from);
53 assert(to);
54
55 r = mac_selinux_create_file_prepare(to, S_IFLNK);
56 if (r < 0)
57 return r;
58
59 if (symlink_atomic(from, to) < 0)
60 r = -errno;
61
62 mac_selinux_create_file_clear();
63
64 if (r < 0)
65 return r;
66
67 return mac_smack_fix(to, 0);
68}
69
7a3e4dc3
CG
70int mknod_label(const char *pathname, mode_t mode, dev_t dev) {
71 int r;
72
73 assert(pathname);
74
75 r = mac_selinux_create_file_prepare(pathname, mode);
76 if (r < 0)
77 return r;
78
79 if (mknod(pathname, mode, dev) < 0)
80 r = -errno;
81
82 mac_selinux_create_file_clear();
83
84 if (r < 0)
85 return r;
86
87 return mac_smack_fix(pathname, 0);
88}
89
de2e28d8
ZJS
90int btrfs_subvol_make_label(const char *path) {
91 int r;
92
93 assert(path);
94
95 r = mac_selinux_create_file_prepare(path, S_IFDIR);
96 if (r < 0)
97 return r;
98
99 r = btrfs_subvol_make(path);
100 mac_selinux_create_file_clear();
101
102 if (r < 0)
103 return r;
104
08c84981 105 return mac_smack_fix(path, 0);
de2e28d8 106}