]>
Commit | Line | Data |
---|---|---|
e51bc1a2 LP |
1 | /*** |
2 | This file is part of systemd. | |
3 | ||
4 | Copyright 2010 Lennart Poettering | |
5 | ||
6 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
7 | under the terms of the GNU Lesser General Public License as published by |
8 | the Free Software Foundation; either version 2.1 of the License, or | |
e51bc1a2 LP |
9 | (at your option) any later version. |
10 | ||
11 | systemd is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 14 | Lesser General Public License for more details. |
e51bc1a2 | 15 | |
5430f7f2 | 16 | You should have received a copy of the GNU Lesser General Public License |
e51bc1a2 LP |
17 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
18 | ***/ | |
19 | ||
11c3a366 TA |
20 | #include <errno.h> |
21 | #include <sys/stat.h> | |
22 | #include <unistd.h> | |
23 | ||
cf0fbc49 | 24 | #include "label.h" |
93cc7779 | 25 | #include "macro.h" |
d7b8eec7 LP |
26 | #include "selinux-util.h" |
27 | #include "smack-util.h" | |
b9c1bc28 ŁS |
28 | |
29 | int label_fix(const char *path, bool ignore_enoent, bool ignore_erofs) { | |
5dfc5461 | 30 | int r, q; |
b9c1bc28 | 31 | |
5dfc5461 LP |
32 | r = mac_selinux_fix(path, ignore_enoent, ignore_erofs); |
33 | q = mac_smack_fix(path, ignore_enoent, ignore_erofs); | |
b9c1bc28 | 34 | |
5dfc5461 LP |
35 | if (r < 0) |
36 | return r; | |
37 | if (q < 0) | |
38 | return q; | |
e51bc1a2 | 39 | |
5dfc5461 | 40 | return 0; |
e51bc1a2 | 41 | } |
c34255bd LP |
42 | |
43 | int mkdir_label(const char *path, mode_t mode) { | |
44 | int r; | |
45 | ||
46 | assert(path); | |
47 | ||
48 | r = mac_selinux_create_file_prepare(path, S_IFDIR); | |
49 | if (r < 0) | |
50 | return r; | |
51 | ||
52 | if (mkdir(path, mode) < 0) | |
53 | r = -errno; | |
54 | ||
55 | mac_selinux_create_file_clear(); | |
56 | ||
57 | if (r < 0) | |
58 | return r; | |
59 | ||
60 | return mac_smack_fix(path, false, false); | |
61 | } | |
62 | ||
63 | int symlink_label(const char *old_path, const char *new_path) { | |
64 | int r; | |
65 | ||
66 | assert(old_path); | |
67 | assert(new_path); | |
68 | ||
69 | r = mac_selinux_create_file_prepare(new_path, S_IFLNK); | |
70 | if (r < 0) | |
71 | return r; | |
72 | ||
73 | if (symlink(old_path, new_path) < 0) | |
74 | r = -errno; | |
75 | ||
76 | mac_selinux_create_file_clear(); | |
77 | ||
78 | if (r < 0) | |
79 | return r; | |
80 | ||
81 | return mac_smack_fix(new_path, false, false); | |
82 | } |