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