]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
a5c32cff HH |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2010 Lennart Poettering | |
6 | Copyright 2010 Harald Hoyer | |
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 | ***/ | |
a5c32cff | 21 | |
11c3a366 TA |
22 | #include <sys/stat.h> |
23 | ||
d7b8eec7 | 24 | #include "fileio-label.h" |
11c3a366 | 25 | #include "fileio.h" |
93cc7779 | 26 | #include "selinux-util.h" |
a5c32cff | 27 | |
39c38d77 | 28 | int write_string_file_atomic_label_ts(const char *fn, const char *line, struct timespec *ts) { |
a5c32cff HH |
29 | int r; |
30 | ||
ecabcf8b | 31 | r = mac_selinux_create_file_prepare(fn, S_IFREG); |
f7f628b5 | 32 | if (r < 0) |
a5c32cff HH |
33 | return r; |
34 | ||
39c38d77 | 35 | r = write_string_file_ts(fn, line, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC, ts); |
a5c32cff | 36 | |
ecabcf8b | 37 | mac_selinux_create_file_clear(); |
a5c32cff HH |
38 | |
39 | return r; | |
40 | } | |
41 | ||
42 | int write_env_file_label(const char *fname, char **l) { | |
43 | int r; | |
44 | ||
ecabcf8b | 45 | r = mac_selinux_create_file_prepare(fname, S_IFREG); |
f7f628b5 | 46 | if (r < 0) |
a5c32cff HH |
47 | return r; |
48 | ||
754fc0c7 | 49 | r = write_env_file(fname, l); |
a5c32cff | 50 | |
ecabcf8b | 51 | mac_selinux_create_file_clear(); |
a5c32cff HH |
52 | |
53 | return r; | |
54 | } | |
f7f628b5 ZJS |
55 | |
56 | int fopen_temporary_label(const char *target, | |
57 | const char *path, FILE **f, char **temp_path) { | |
58 | int r; | |
59 | ||
ecabcf8b | 60 | r = mac_selinux_create_file_prepare(target, S_IFREG); |
f7f628b5 ZJS |
61 | if (r < 0) |
62 | return r; | |
63 | ||
64 | r = fopen_temporary(path, f, temp_path); | |
65 | ||
ecabcf8b | 66 | mac_selinux_create_file_clear(); |
f7f628b5 ZJS |
67 | |
68 | return r; | |
69 | } |