From 373eb302ad5b641059bd8830a85d824b1b55c46c Mon Sep 17 00:00:00 2001 From: outphase Date: Sun, 13 Aug 2023 10:04:13 -0500 Subject: [PATCH] init: change rootful detection condition (#909) * Change rootful detection condition `cat /run/host/etc/shadow > /dev/null` appears to always return true even when rootless. Check to see if `/etc/shadow` is writable to determine access. The earlier commit for checking readability also always returned true. * Update distrobox-init --- distrobox-init | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/distrobox-init b/distrobox-init index 1f490911dc..3026defae7 100755 --- a/distrobox-init +++ b/distrobox-init @@ -187,7 +187,9 @@ fi # # if /run/.nopasswd is present, let's treat the init as rootless, this is not # a good thing, users behold! -if cat /run/host/etc/shadow > /dev/null && [ ! -e /run/.nopasswd ]; then +if stat /run/host/etc/shadow && + [ "$(stat -c "%u" /run/host/etc/shadow)" = "0" ] && + [ ! -e /run/.nopasswd ]; then rootful=1 fi