]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/label.c
Merge pull request #16145 from poettering/qrcode-dlopen
[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_container(const char *path, const char *inside_path, LabelFixFlags flags) {
14 int r, q;
15
16 r = mac_selinux_fix_container(path, inside_path, flags);
17 q = mac_smack_fix_container(path, inside_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 mknod_label(const char *pathname, mode_t mode, dev_t dev) {
49 int r;
50
51 assert(pathname);
52
53 r = mac_selinux_create_file_prepare(pathname, mode);
54 if (r < 0)
55 return r;
56
57 if (mknod(pathname, mode, dev) < 0)
58 r = -errno;
59
60 mac_selinux_create_file_clear();
61
62 if (r < 0)
63 return r;
64
65 return mac_smack_fix(pathname, 0);
66 }
67
68 int btrfs_subvol_make_label(const char *path) {
69 int r;
70
71 assert(path);
72
73 r = mac_selinux_create_file_prepare(path, S_IFDIR);
74 if (r < 0)
75 return r;
76
77 r = btrfs_subvol_make(path);
78 mac_selinux_create_file_clear();
79
80 if (r < 0)
81 return r;
82
83 return mac_smack_fix(path, 0);
84 }