]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/fileio-label.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #include "fileio-label.h"
7 #include "selinux-util.h"
9 int write_string_file_atomic_label_ts(const char *fn
, const char *line
, struct timespec
*ts
) {
12 r
= mac_selinux_create_file_prepare(fn
, S_IFREG
);
16 r
= write_string_file_ts(fn
, line
, WRITE_STRING_FILE_CREATE
|WRITE_STRING_FILE_ATOMIC
, ts
);
18 mac_selinux_create_file_clear();
23 int write_env_file_label(const char *fname
, char **l
) {
26 r
= mac_selinux_create_file_prepare(fname
, S_IFREG
);
30 r
= write_env_file(fname
, l
);
32 mac_selinux_create_file_clear();
37 int fopen_temporary_label(const char *target
,
38 const char *path
, FILE **f
, char **temp_path
) {
41 r
= mac_selinux_create_file_prepare(target
, S_IFREG
);
45 r
= fopen_temporary(path
, f
, temp_path
);
47 mac_selinux_create_file_clear();
52 int create_shutdown_run_nologin_or_warn(void) {
55 /* This is used twice: once in systemd-user-sessions.service, in order to block logins when we actually go
56 * down, and once in systemd-logind.service when shutdowns are scheduled, and logins are to be turned off a bit
57 * in advance. We use the same wording of the message in both cases. */
59 r
= write_string_file_atomic_label("/run/nologin",
60 "System is going down. Unprivileged users are not permitted to log in anymore. "
61 "For technical details, see pam_nologin(8).");
63 return log_error_errno(r
, "Failed to create /run/nologin: %m");