]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/label.c
util: introduce memcmp_safe()
[thirdparty/systemd.git] / src / basic / label.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <errno.h>
4 #include <sys/stat.h>
5 #include <unistd.h>
6
7 #include "btrfs-util.h"
8 #include "label.h"
9 #include "macro.h"
10 #include "selinux-util.h"
11 #include "smack-util.h"
12
13 int label_fix(const char *path, LabelFixFlags flags) {
14 int r, q;
15
16 r = mac_selinux_fix(path, flags);
17 q = mac_smack_fix(path, flags);
18
19 if (r < 0)
20 return r;
21 if (q < 0)
22 return q;
23
24 return 0;
25 }
26
27 int symlink_label(const char *old_path, const char *new_path) {
28 int r;
29
30 assert(old_path);
31 assert(new_path);
32
33 r = mac_selinux_create_file_prepare(new_path, S_IFLNK);
34 if (r < 0)
35 return r;
36
37 if (symlink(old_path, new_path) < 0)
38 r = -errno;
39
40 mac_selinux_create_file_clear();
41
42 if (r < 0)
43 return r;
44
45 return mac_smack_fix(new_path, 0);
46 }
47
48 int btrfs_subvol_make_label(const char *path) {
49 int r;
50
51 assert(path);
52
53 r = mac_selinux_create_file_prepare(path, S_IFDIR);
54 if (r < 0)
55 return r;
56
57 r = btrfs_subvol_make(path);
58 mac_selinux_create_file_clear();
59
60 if (r < 0)
61 return r;
62
63 return mac_smack_fix(path, 0);
64 }