chiark / gitweb /
test: do not use last cap from kernel in test-cap-list
[elogind.git] / src / shared / label.c
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 "label.h"
23 #include "util.h"
24
25 int label_fix(const char *path, bool ignore_enoent, bool ignore_erofs) {
26         int r, q;
27
28         r = mac_selinux_fix(path, ignore_enoent, ignore_erofs);
29         q = mac_smack_fix(path, ignore_enoent, ignore_erofs);
30
31         if (r < 0)
32                 return r;
33         if (q < 0)
34                 return q;
35
36         return 0;
37 }
38
39 int mkdir_label(const char *path, mode_t mode) {
40         int r;
41
42         assert(path);
43
44         r = mac_selinux_create_file_prepare(path, S_IFDIR);
45         if (r < 0)
46                 return r;
47
48         if (mkdir(path, mode) < 0)
49                 r = -errno;
50
51         mac_selinux_create_file_clear();
52
53         if (r < 0)
54                 return r;
55
56         return mac_smack_fix(path, false, false);
57 }
58
59 int symlink_label(const char *old_path, const char *new_path) {
60         int r;
61
62         assert(old_path);
63         assert(new_path);
64
65         r = mac_selinux_create_file_prepare(new_path, S_IFLNK);
66         if (r < 0)
67                 return r;
68
69         if (symlink(old_path, new_path) < 0)
70                 r = -errno;
71
72         mac_selinux_create_file_clear();
73
74         if (r < 0)
75                 return r;
76
77         return mac_smack_fix(new_path, false, false);
78 }