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