chiark / gitweb /
nologin: extend the /run/nologin descriptions a bit (#8244)
authorLennart Poettering <lennart@poettering.net>
Thu, 22 Feb 2018 13:21:30 +0000 (14:21 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:59:03 +0000 (07:59 +0200)
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.

src/basic/fileio-label.c
src/basic/fileio-label.h
src/login/logind-dbus.c

index 6b942627a8eb797368a569b0a3cfa3079c9044d1..0baa6a2fd1b46c8c01d420759315db10920d583f 100644 (file)
@@ -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;
+}
index f6d33a678ca218e73df323a362fb5562da767b67..f77ea43303ebc7b7e518be33ac197d94e62f6f17 100644 (file)
@@ -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);
index 87734d8e562e5279c340942c24c02e77757cc214..ee3a1e919aa93f6cfbcfc3a95fbce11f3531b203 100644 (file)
@@ -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;
 }