2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2013-02-14 12:26:13 +01:00
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright 2010 Lennart Poettering
|
|
|
|
Copyright 2010 Harald Hoyer
|
|
|
|
***/
|
|
|
|
|
2015-11-30 21:43:37 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2014-12-27 18:46:36 +01:00
|
|
|
#include "fileio-label.h"
|
2015-11-30 21:43:37 +01:00
|
|
|
#include "fileio.h"
|
2015-12-01 23:22:03 +01:00
|
|
|
#include "selinux-util.h"
|
2013-02-14 12:26:13 +01:00
|
|
|
|
2017-05-11 16:23:36 +02:00
|
|
|
int write_string_file_atomic_label_ts(const char *fn, const char *line, struct timespec *ts) {
|
2013-02-14 12:26:13 +01:00
|
|
|
int r;
|
|
|
|
|
2014-10-23 19:41:27 +02:00
|
|
|
r = mac_selinux_create_file_prepare(fn, S_IFREG);
|
2014-07-14 03:10:38 +02:00
|
|
|
if (r < 0)
|
2013-02-14 12:26:13 +01:00
|
|
|
return r;
|
|
|
|
|
2017-05-11 16:23:36 +02:00
|
|
|
r = write_string_file_ts(fn, line, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC, ts);
|
2013-02-14 12:26:13 +01:00
|
|
|
|
2014-10-23 19:41:27 +02:00
|
|
|
mac_selinux_create_file_clear();
|
2013-02-14 12:26:13 +01:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
int write_env_file_label(const char *fname, char **l) {
|
|
|
|
int r;
|
|
|
|
|
2014-10-23 19:41:27 +02:00
|
|
|
r = mac_selinux_create_file_prepare(fname, S_IFREG);
|
2014-07-14 03:10:38 +02:00
|
|
|
if (r < 0)
|
2013-02-14 12:26:13 +01:00
|
|
|
return r;
|
|
|
|
|
2014-10-03 14:58:40 +02:00
|
|
|
r = write_env_file(fname, l);
|
2013-02-14 12:26:13 +01:00
|
|
|
|
2014-10-23 19:41:27 +02:00
|
|
|
mac_selinux_create_file_clear();
|
2013-02-14 12:26:13 +01:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2014-07-14 03:10:38 +02:00
|
|
|
|
|
|
|
int fopen_temporary_label(const char *target,
|
|
|
|
const char *path, FILE **f, char **temp_path) {
|
|
|
|
int r;
|
|
|
|
|
2014-10-23 19:41:27 +02:00
|
|
|
r = mac_selinux_create_file_prepare(target, S_IFREG);
|
2014-07-14 03:10:38 +02:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = fopen_temporary(path, f, temp_path);
|
|
|
|
|
2014-10-23 19:41:27 +02:00
|
|
|
mac_selinux_create_file_clear();
|
2014-07-14 03:10:38 +02:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2018-02-22 14:21:30 +01:00
|
|
|
|
|
|
|
int create_shutdown_run_nologin_or_warn(void) {
|
|
|
|
int r;
|
|
|
|
|
|
|
|
/* This is used twice: once in systemd-user-sessions.service, in order to block logins when we actually go
|
|
|
|
* down, and once in systemd-logind.service when shutdowns are scheduled, and logins are to be turned off a bit
|
|
|
|
* in advance. We use the same wording of the message in both cases. */
|
|
|
|
|
|
|
|
r = write_string_file_atomic_label("/run/nologin",
|
|
|
|
"System is going down. Unprivileged users are not permitted to log in anymore. "
|
|
|
|
"For technical details, see pam_nologin(8).");
|
|
|
|
if (r < 0)
|
|
|
|
return log_error_errno(r, "Failed to create /run/nologin: %m");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|