daandemeyer / rpms / systemd

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