chiark / gitweb /
mac: also rename use_{smack,selinux,apparmor}() calls so that they share the new...
[elogind.git] / src / shared / fileio-label.c
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   Copyright 2010 Harald Hoyer
8
9   systemd is free software; you can redistribute it and/or modify it
10   under the terms of the GNU Lesser General Public License as published by
11   the Free Software Foundation; either version 2.1 of the License, or
12   (at your option) any later version.
13
14   systemd is distributed in the hope that it will be useful, but
15   WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   Lesser General Public License for more details.
18
19   You should have received a copy of the GNU Lesser General Public License
20   along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 ***/
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <unistd.h>
25
26 #include "fileio-label.h"
27 #include "label.h"
28 #include "util.h"
29
30 int write_string_file_atomic_label(const char *fn, const char *line) {
31         int r;
32
33         r = mac_selinux_context_set(fn, S_IFREG);
34         if (r < 0)
35                 return r;
36
37         r = write_string_file_atomic(fn, line);
38
39         mac_selinux_context_clear();
40
41         return r;
42 }
43
44 int write_env_file_label(const char *fname, char **l) {
45         int r;
46
47         r = mac_selinux_context_set(fname, S_IFREG);
48         if (r < 0)
49                 return r;
50
51         r = write_env_file(fname, l);
52
53         mac_selinux_context_clear();
54
55         return r;
56 }
57
58 int fopen_temporary_label(const char *target,
59                           const char *path, FILE **f, char **temp_path) {
60         int r;
61
62         r = mac_selinux_context_set(target, S_IFREG);
63         if (r < 0)
64                 return r;
65
66         r = fopen_temporary(path, f, temp_path);
67
68         mac_selinux_context_clear();
69
70         return r;
71 }