chiark / gitweb /
nspawn: support ephemeral boots from images
[elogind.git] / src / basic / label.c
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
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
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
14   Lesser General Public License for more details.
15
16   You should have received a copy of the GNU Lesser General Public License
17   along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #include <errno.h>
21 #include <sys/stat.h>
22 #include <unistd.h>
23
24 #include "label.h"
25 #include "macro.h"
26 #include "selinux-util.h"
27 #include "smack-util.h"
28
29 int label_fix(const char *path, bool ignore_enoent, bool ignore_erofs) {
30         int r, q;
31
32         r = mac_selinux_fix(path, ignore_enoent, ignore_erofs);
33         q = mac_smack_fix(path, ignore_enoent, ignore_erofs);
34
35         if (r < 0)
36                 return r;
37         if (q < 0)
38                 return q;
39
40         return 0;
41 }
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 #if 0 /// UNNEEDED by elogind
64 int symlink_label(const char *old_path, const char *new_path) {
65         int r;
66
67         assert(old_path);
68         assert(new_path);
69
70         r = mac_selinux_create_file_prepare(new_path, S_IFLNK);
71         if (r < 0)
72                 return r;
73
74         if (symlink(old_path, new_path) < 0)
75                 r = -errno;
76
77         mac_selinux_create_file_clear();
78
79         if (r < 0)
80                 return r;
81
82         return mac_smack_fix(new_path, false, false);
83 }
84 #endif // 0