]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/fileio-label.c
util-lib: split out all temporary file related calls into tmpfiles-util.c
[thirdparty/systemd.git] / src / shared / fileio-label.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <sys/stat.h>
4
5 #include "fileio-label.h"
6 #include "fileio.h"
7 #include "selinux-util.h"
8
9 int write_string_file_atomic_label_ts(const char *fn, const char *line, struct timespec *ts) {
10 int r;
11
12 r = mac_selinux_create_file_prepare(fn, S_IFREG);
13 if (r < 0)
14 return r;
15
16 r = write_string_file_ts(fn, line, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC, ts);
17
18 mac_selinux_create_file_clear();
19
20 return r;
21 }
22
23 int write_env_file_label(const char *fname, char **l) {
24 int r;
25
26 r = mac_selinux_create_file_prepare(fname, S_IFREG);
27 if (r < 0)
28 return r;
29
30 r = write_env_file(fname, l);
31
32 mac_selinux_create_file_clear();
33
34 return r;
35 }
36
37 int create_shutdown_run_nologin_or_warn(void) {
38 int r;
39
40 /* This is used twice: once in systemd-user-sessions.service, in order to block logins when we actually go
41 * down, and once in systemd-logind.service when shutdowns are scheduled, and logins are to be turned off a bit
42 * in advance. We use the same wording of the message in both cases. */
43
44 r = write_string_file_atomic_label("/run/nologin",
45 "System is going down. Unprivileged users are not permitted to log in anymore. "
46 "For technical details, see pam_nologin(8).");
47 if (r < 0)
48 return log_error_errno(r, "Failed to create /run/nologin: %m");
49
50 return 0;
51 }