From: Lennart Poettering Date: Thu, 22 Feb 2018 13:21:30 +0000 (+0100) Subject: nologin: extend the /run/nologin descriptions a bit (#8244) X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=5e7eb6fbbd4a55cb4b26929482478ca7b2eef6aa;p=elogind.git nologin: extend the /run/nologin descriptions a bit (#8244) This is an attempt to improve #8228 a bit, by extending the /run/nologin a bit, but still keeping it somewhat brief. On purpose I used the vague wording "unprivileged user" rather than "non-root user" so that pam_nologin can be updated to disable its behaviour for members of the "wheel" group one day, and our messages would still make sense. See #8228. --- diff --git a/src/basic/fileio-label.c b/src/basic/fileio-label.c index 6b942627a..0baa6a2fd 100644 --- a/src/basic/fileio-label.c +++ b/src/basic/fileio-label.c @@ -69,3 +69,19 @@ int fopen_temporary_label(const char *target, return r; } #endif // 0 + +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; +} diff --git a/src/basic/fileio-label.h b/src/basic/fileio-label.h index f6d33a678..f77ea4330 100644 --- a/src/basic/fileio-label.h +++ b/src/basic/fileio-label.h @@ -35,6 +35,7 @@ static inline int write_string_file_atomic_label(const char *fn, const char *lin } #if 0 /// UNNEEDED by elogind int write_env_file_label(const char *fname, char **l); -int fopen_temporary_label(const char *target, - const char *path, FILE **f, char **temp_path); #endif // 0 +int fopen_temporary_label(const char *target, const char *path, FILE **f, char **temp_path); + +int create_shutdown_run_nologin_or_warn(void); diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 87734d8e5..ee3a1e919 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1969,15 +1969,11 @@ static int nologin_timeout_handler( void *userdata) { Manager *m = userdata; - int r; log_info("Creating /run/nologin, blocking further logins..."); - r = write_string_file_atomic_label("/run/nologin", "System is going down."); - if (r < 0) - log_error_errno(r, "Failed to create /run/nologin: %m"); - else - m->unlink_nologin = true; + m->unlink_nologin = + create_shutdown_run_nologin_or_warn() >= 0; return 0; }