]> git.proxmox.com Git - systemd.git/blame - src/shared/label.c
Imported Upstream version 217
[systemd.git] / src / shared / label.c
CommitLineData
663996b3
MS
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
663996b3 22#include "label.h"
663996b3 23#include "util.h"
663996b3 24
60f067b4 25int label_fix(const char *path, bool ignore_enoent, bool ignore_erofs) {
5eef597e 26 int r, q;
663996b3 27
5eef597e
MP
28 r = mac_selinux_fix(path, ignore_enoent, ignore_erofs);
29 q = mac_smack_fix(path, ignore_enoent, ignore_erofs);
663996b3 30
663996b3 31 if (r < 0)
5eef597e
MP
32 return r;
33 if (q < 0)
34 return q;
663996b3
MS
35
36 return 0;
37}
38
5eef597e
MP
39int mkdir_label(const char *path, mode_t mode) {
40 int r;
663996b3 41
5eef597e 42 assert(path);
663996b3 43
5eef597e 44 r = mac_selinux_create_file_prepare(path, S_IFDIR);
663996b3 45 if (r < 0)
5eef597e 46 return r;
663996b3 47
5eef597e
MP
48 if (mkdir(path, mode) < 0)
49 r = -errno;
60f067b4 50
5eef597e 51 mac_selinux_create_file_clear();
60f067b4 52
5eef597e
MP
53 if (r < 0)
54 return r;
60f067b4 55
5eef597e 56 return mac_smack_fix(path, false, false);
663996b3
MS
57}
58
5eef597e 59int symlink_label(const char *old_path, const char *new_path) {
60f067b4 60 int r;
663996b3 61
5eef597e
MP
62 assert(old_path);
63 assert(new_path);
663996b3 64
5eef597e 65 r = mac_selinux_create_file_prepare(new_path, S_IFLNK);
663996b3 66 if (r < 0)
5eef597e 67 return r;
663996b3 68
5eef597e
MP
69 if (symlink(old_path, new_path) < 0)
70 r = -errno;
60f067b4 71
5eef597e 72 mac_selinux_create_file_clear();
60f067b4 73
5eef597e
MP
74 if (r < 0)
75 return r;
60f067b4 76
5eef597e 77 return mac_smack_fix(new_path, false, false);
60f067b4 78}