Line data Source code
1 : /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
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
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
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
16 : Lesser General Public License for more details.
17 :
18 : You should have received a copy of the GNU Lesser General Public License
19 : along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 : ***/
21 :
22 : #include "selinux-util.h"
23 : #include "smack-util.h"
24 : #include "util.h"
25 : #include "label.h"
26 :
27 0 : int label_fix(const char *path, bool ignore_enoent, bool ignore_erofs) {
28 : int r, q;
29 :
30 0 : r = mac_selinux_fix(path, ignore_enoent, ignore_erofs);
31 0 : q = mac_smack_fix(path, ignore_enoent, ignore_erofs);
32 :
33 0 : if (r < 0)
34 0 : return r;
35 0 : if (q < 0)
36 0 : return q;
37 :
38 0 : return 0;
39 : }
40 :
41 75 : int mkdir_label(const char *path, mode_t mode) {
42 : int r;
43 :
44 75 : assert(path);
45 :
46 75 : r = mac_selinux_create_file_prepare(path, S_IFDIR);
47 75 : if (r < 0)
48 0 : return r;
49 :
50 75 : if (mkdir(path, mode) < 0)
51 58 : r = -errno;
52 :
53 75 : mac_selinux_create_file_clear();
54 :
55 75 : if (r < 0)
56 58 : return r;
57 :
58 17 : return mac_smack_fix(path, false, false);
59 : }
60 :
61 0 : int symlink_label(const char *old_path, const char *new_path) {
62 : int r;
63 :
64 0 : assert(old_path);
65 0 : assert(new_path);
66 :
67 0 : r = mac_selinux_create_file_prepare(new_path, S_IFLNK);
68 0 : if (r < 0)
69 0 : return r;
70 :
71 0 : if (symlink(old_path, new_path) < 0)
72 0 : r = -errno;
73 :
74 0 : mac_selinux_create_file_clear();
75 :
76 0 : if (r < 0)
77 0 : return r;
78 :
79 0 : return mac_smack_fix(new_path, false, false);
80 : }
|