52b84b
From d8ae33a302f01601e9e98b4aca3516e93c634a54 Mon Sep 17 00:00:00 2001
52b84b
From: Andreas Henriksson <andreas@fatal.se>
52b84b
Date: Sun, 14 Oct 2018 14:53:09 +0200
52b84b
Subject: [PATCH] sulogin-shell: Use force if SYSTEMD_SULOGIN_FORCE set
52b84b
52b84b
When the root account is locked sulogin will either inform you of
52b84b
this and not allow you in or if --force is used it will hand
52b84b
you passwordless root (if using a recent enough version of util-linux).
52b84b
52b84b
Not being allowed a shell is ofcourse inconvenient, but at the same
52b84b
time handing out passwordless root unconditionally is probably not
52b84b
a good idea everywhere.
52b84b
52b84b
This patch thus allows to control which behaviour you want by
52b84b
setting the SYSTEMD_SULOGIN_FORCE environment variable to true
52b84b
or false to control the behaviour, eg. via adding this to
52b84b
'systemctl edit rescue.service' (or emergency.service):
52b84b
52b84b
[Service]
52b84b
Environment=SYSTEMD_SULOGIN_FORCE=1
52b84b
52b84b
Distributions who used locked root accounts and want the passwordless
52b84b
behaviour could thus simply drop in the override file in
52b84b
/etc/systemd/system/rescue.service.d/override.conf
52b84b
52b84b
Fixes: #7115
52b84b
Addresses: https://bugs.debian.org/802211
52b84b
(cherry picked from commit 33eb44fe4a8d7971b5614bc4c2d90f8d91cce66c)
52b84b
52b84b
Resolves: #1625929
52b84b
---
52b84b
 doc/ENVIRONMENT.md                |  6 ++++++
52b84b
 src/sulogin-shell/sulogin-shell.c | 11 ++++++++++-
52b84b
 2 files changed, 16 insertions(+), 1 deletion(-)
52b84b
52b84b
diff --git a/doc/ENVIRONMENT.md b/doc/ENVIRONMENT.md
52b84b
index 1e648be640..39a36a52cc 100644
52b84b
--- a/doc/ENVIRONMENT.md
52b84b
+++ b/doc/ENVIRONMENT.md
52b84b
@@ -101,3 +101,9 @@ systemd-timedated:
52b84b
   NTP client services. If set, `timedatectl set-ntp on` enables and starts the
52b84b
   first existing unit listed in the environment variable, and
52b84b
   `timedatectl set-ntp off` disables and stops all listed units.
52b84b
+
52b84b
+systemd-sulogin-shell:
52b84b
+
52b84b
+* `$SYSTEMD_SULOGIN_FORCE=1` — This skips asking for the root password if the
52b84b
+  root password is not available (such as when the root account is locked).
52b84b
+  See `sulogin(8)` for more details.
52b84b
diff --git a/src/sulogin-shell/sulogin-shell.c b/src/sulogin-shell/sulogin-shell.c
52b84b
index 5db3592d6f..a1ea2333de 100644
52b84b
--- a/src/sulogin-shell/sulogin-shell.c
52b84b
+++ b/src/sulogin-shell/sulogin-shell.c
52b84b
@@ -9,6 +9,7 @@
52b84b
 #include "bus-util.h"
52b84b
 #include "bus-error.h"
52b84b
 #include "def.h"
52b84b
+#include "env-util.h"
52b84b
 #include "log.h"
52b84b
 #include "process-util.h"
52b84b
 #include "sd-bus.h"
52b84b
@@ -89,7 +90,11 @@ static void print_mode(const char* mode) {
52b84b
 }
52b84b
 
52b84b
 int main(int argc, char *argv[]) {
52b84b
-        static const char* const sulogin_cmdline[] = {SULOGIN, NULL};
52b84b
+        const char* sulogin_cmdline[] = {
52b84b
+                SULOGIN,
52b84b
+                NULL,             /* --force */
52b84b
+                NULL
52b84b
+        };
52b84b
         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
52b84b
         int r;
52b84b
 
52b84b
@@ -99,6 +104,10 @@ int main(int argc, char *argv[]) {
52b84b
 
52b84b
         print_mode(argc > 1 ? argv[1] : "");
52b84b
 
52b84b
+        if (getenv_bool("SYSTEMD_SULOGIN_FORCE") > 0)
52b84b
+                /* allows passwordless logins if root account is locked. */
52b84b
+                sulogin_cmdline[1] = "--force";
52b84b
+
52b84b
         (void) fork_wait(sulogin_cmdline);
52b84b
 
52b84b
         r = bus_connect_system_systemd(&bus;;