]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/fileio-label.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / basic / fileio-label.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
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 ***/
21
22 #include <sys/stat.h>
23
24 #include "fileio-label.h"
25 #include "fileio.h"
26 #include "selinux-util.h"
27
28 int write_string_file_atomic_label_ts(const char *fn, const char *line, struct timespec *ts) {
29 int r;
30
31 r = mac_selinux_create_file_prepare(fn, S_IFREG);
32 if (r < 0)
33 return r;
34
35 r = write_string_file_ts(fn, line, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC, ts);
36
37 mac_selinux_create_file_clear();
38
39 return r;
40 }
41
42 int write_env_file_label(const char *fname, char **l) {
43 int r;
44
45 r = mac_selinux_create_file_prepare(fname, S_IFREG);
46 if (r < 0)
47 return r;
48
49 r = write_env_file(fname, l);
50
51 mac_selinux_create_file_clear();
52
53 return r;
54 }
55
56 int fopen_temporary_label(const char *target,
57 const char *path, FILE **f, char **temp_path) {
58 int r;
59
60 r = mac_selinux_create_file_prepare(target, S_IFREG);
61 if (r < 0)
62 return r;
63
64 r = fopen_temporary(path, f, temp_path);
65
66 mac_selinux_create_file_clear();
67
68 return r;
69 }