]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/fileio-label.c
tree-wide: drop 'This file is part of systemd' blurb
[thirdparty/systemd.git] / src / basic / fileio-label.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 Copyright 2010 Lennart Poettering
4 Copyright 2010 Harald Hoyer
5 ***/
6
7 #include <sys/stat.h>
8
9 #include "fileio-label.h"
10 #include "fileio.h"
11 #include "selinux-util.h"
12
13 int write_string_file_atomic_label_ts(const char *fn, const char *line, struct timespec *ts) {
14 int r;
15
16 r = mac_selinux_create_file_prepare(fn, S_IFREG);
17 if (r < 0)
18 return r;
19
20 r = write_string_file_ts(fn, line, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC, ts);
21
22 mac_selinux_create_file_clear();
23
24 return r;
25 }
26
27 int write_env_file_label(const char *fname, char **l) {
28 int r;
29
30 r = mac_selinux_create_file_prepare(fname, S_IFREG);
31 if (r < 0)
32 return r;
33
34 r = write_env_file(fname, l);
35
36 mac_selinux_create_file_clear();
37
38 return r;
39 }
40
41 int fopen_temporary_label(const char *target,
42 const char *path, FILE **f, char **temp_path) {
43 int r;
44
45 r = mac_selinux_create_file_prepare(target, S_IFREG);
46 if (r < 0)
47 return r;
48
49 r = fopen_temporary(path, f, temp_path);
50
51 mac_selinux_create_file_clear();
52
53 return r;
54 }
55
56 int create_shutdown_run_nologin_or_warn(void) {
57 int r;
58
59 /* This is used twice: once in systemd-user-sessions.service, in order to block logins when we actually go
60 * down, and once in systemd-logind.service when shutdowns are scheduled, and logins are to be turned off a bit
61 * in advance. We use the same wording of the message in both cases. */
62
63 r = write_string_file_atomic_label("/run/nologin",
64 "System is going down. Unprivileged users are not permitted to log in anymore. "
65 "For technical details, see pam_nologin(8).");
66 if (r < 0)
67 return log_error_errno(r, "Failed to create /run/nologin: %m");
68
69 return 0;
70 }