chiark / gitweb /
tree-wide: beautify remaining copyright statements
[elogind.git] / src / basic / fileio-label.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3   Copyright © 2010 Harald Hoyer
4 ***/
5
6 #include <sys/stat.h>
7
8 #include "fileio-label.h"
9 //#include "fileio.h"
10 #include "selinux-util.h"
11
12 int write_string_file_atomic_label_ts(const char *fn, const char *line, struct timespec *ts) {
13         int r;
14
15         r = mac_selinux_create_file_prepare(fn, S_IFREG);
16         if (r < 0)
17                 return r;
18
19         r = write_string_file_ts(fn, line, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC, ts);
20
21         mac_selinux_create_file_clear();
22
23         return r;
24 }
25
26 #if 0 /// UNNEEDED by elogind
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 #endif // 0
56
57 int create_shutdown_run_nologin_or_warn(void) {
58         int r;
59
60         /* This is used twice: once in systemd-user-sessions.service, in order to block logins when we actually go
61          * down, and once in systemd-logind.service when shutdowns are scheduled, and logins are to be turned off a bit
62          * in advance. We use the same wording of the message in both cases. */
63
64         r = write_string_file_atomic_label("/run/nologin",
65                                            "System is going down. Unprivileged users are not permitted to log in anymore. "
66                                            "For technical details, see pam_nologin(8).");
67         if (r < 0)
68                 return log_error_errno(r, "Failed to create /run/nologin: %m");
69
70         return 0;
71 }