chiark / gitweb /
tree-wide: drop license boilerplate
[elogind.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
9 #include <sys/stat.h>
10
11 #include "fileio-label.h"
12 //#include "fileio.h"
13 #include "selinux-util.h"
14
15 int write_string_file_atomic_label_ts(const char *fn, const char *line, struct timespec *ts) {
16         int r;
17
18         r = mac_selinux_create_file_prepare(fn, S_IFREG);
19         if (r < 0)
20                 return r;
21
22         r = write_string_file_ts(fn, line, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC, ts);
23
24         mac_selinux_create_file_clear();
25
26         return r;
27 }
28
29 #if 0 /// UNNEEDED by elogind
30 int write_env_file_label(const char *fname, char **l) {
31         int r;
32
33         r = mac_selinux_create_file_prepare(fname, S_IFREG);
34         if (r < 0)
35                 return r;
36
37         r = write_env_file(fname, l);
38
39         mac_selinux_create_file_clear();
40
41         return r;
42 }
43
44 int fopen_temporary_label(const char *target,
45                           const char *path, FILE **f, char **temp_path) {
46         int r;
47
48         r = mac_selinux_create_file_prepare(target, S_IFREG);
49         if (r < 0)
50                 return r;
51
52         r = fopen_temporary(path, f, temp_path);
53
54         mac_selinux_create_file_clear();
55
56         return r;
57 }
58 #endif // 0
59
60 int create_shutdown_run_nologin_or_warn(void) {
61         int r;
62
63         /* This is used twice: once in systemd-user-sessions.service, in order to block logins when we actually go
64          * down, and once in systemd-logind.service when shutdowns are scheduled, and logins are to be turned off a bit
65          * in advance. We use the same wording of the message in both cases. */
66
67         r = write_string_file_atomic_label("/run/nologin",
68                                            "System is going down. Unprivileged users are not permitted to log in anymore. "
69                                            "For technical details, see pam_nologin(8).");
70         if (r < 0)
71                 return log_error_errno(r, "Failed to create /run/nologin: %m");
72
73         return 0;
74 }