]>
Commit | Line | Data |
---|---|---|
a5c32cff HH |
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 | ***/ | |
a5c32cff | 22 | |
d7b8eec7 | 23 | #include "fileio-label.h" |
cf0fbc49 TA |
24 | #include "selinux-util.h" |
25 | #include "util.h" | |
a5c32cff | 26 | |
574d5f2d | 27 | int write_string_file_atomic_label(const char *fn, const char *line) { |
a5c32cff HH |
28 | int r; |
29 | ||
ecabcf8b | 30 | r = mac_selinux_create_file_prepare(fn, S_IFREG); |
f7f628b5 | 31 | if (r < 0) |
a5c32cff HH |
32 | return r; |
33 | ||
4c1fc3e4 | 34 | r = write_string_file(fn, line, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC); |
a5c32cff | 35 | |
ecabcf8b | 36 | mac_selinux_create_file_clear(); |
a5c32cff HH |
37 | |
38 | return r; | |
39 | } | |
40 | ||
41 | int write_env_file_label(const char *fname, char **l) { | |
42 | int r; | |
43 | ||
ecabcf8b | 44 | r = mac_selinux_create_file_prepare(fname, S_IFREG); |
f7f628b5 | 45 | if (r < 0) |
a5c32cff HH |
46 | return r; |
47 | ||
754fc0c7 | 48 | r = write_env_file(fname, l); |
a5c32cff | 49 | |
ecabcf8b | 50 | mac_selinux_create_file_clear(); |
a5c32cff HH |
51 | |
52 | return r; | |
53 | } | |
f7f628b5 ZJS |
54 | |
55 | int fopen_temporary_label(const char *target, | |
56 | const char *path, FILE **f, char **temp_path) { | |
57 | int r; | |
58 | ||
ecabcf8b | 59 | r = mac_selinux_create_file_prepare(target, S_IFREG); |
f7f628b5 ZJS |
60 | if (r < 0) |
61 | return r; | |
62 | ||
63 | r = fopen_temporary(path, f, temp_path); | |
64 | ||
ecabcf8b | 65 | mac_selinux_create_file_clear(); |
f7f628b5 ZJS |
66 | |
67 | return r; | |
68 | } |