chiark / gitweb /
1641a6918954293aca7158ea6bea81038b36055f
[elogind.git] / src / basic / label.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3   This file is part of systemd.
4
5   Copyright 2010 Lennart Poettering
6 ***/
7
8 #include <errno.h>
9 #include <sys/stat.h>
10 #include <unistd.h>
11
12 //#include "btrfs-util.h"
13 #include "label.h"
14 #include "macro.h"
15 #include "selinux-util.h"
16 #include "smack-util.h"
17
18 int label_fix(const char *path, LabelFixFlags flags) {
19         int r, q;
20
21         r = mac_selinux_fix(path, flags);
22         q = mac_smack_fix(path, flags);
23
24         if (r < 0)
25                 return r;
26         if (q < 0)
27                 return q;
28
29         return 0;
30 }
31
32
33 #if 0 /// UNNEEDED by elogind
34 int symlink_label(const char *old_path, const char *new_path) {
35         int r;
36
37         assert(old_path);
38         assert(new_path);
39
40         r = mac_selinux_create_file_prepare(new_path, S_IFLNK);
41         if (r < 0)
42                 return r;
43
44         if (symlink(old_path, new_path) < 0)
45                 r = -errno;
46
47         mac_selinux_create_file_clear();
48
49         if (r < 0)
50                 return r;
51
52         return mac_smack_fix(new_path, 0);
53 }
54
55 int btrfs_subvol_make_label(const char *path) {
56         int r;
57
58         assert(path);
59
60         r = mac_selinux_create_file_prepare(path, S_IFDIR);
61         if (r < 0)
62                 return r;
63
64         r = btrfs_subvol_make(path);
65         mac_selinux_create_file_clear();
66
67         if (r < 0)
68                 return r;
69
70         return mac_smack_fix(path, 0);
71 }
72 #endif // 0