]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/label.c
treewide: use log_*_errno whenever %m is in the format string
[thirdparty/systemd.git] / src / shared / label.c
CommitLineData
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
e51bc1a2
LP
22#include "label.h"
23#include "util.h"
b9c1bc28
ŁS
24
25int label_fix(const char *path, bool ignore_enoent, bool ignore_erofs) {
5dfc5461 26 int r, q;
b9c1bc28 27
5dfc5461
LP
28 r = mac_selinux_fix(path, ignore_enoent, ignore_erofs);
29 q = mac_smack_fix(path, ignore_enoent, ignore_erofs);
b9c1bc28 30
5dfc5461
LP
31 if (r < 0)
32 return r;
33 if (q < 0)
34 return q;
e51bc1a2 35
5dfc5461 36 return 0;
e51bc1a2 37}
c34255bd
LP
38
39int 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
59int 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}