From 130b602a6d107429b03a85c1467ceb353216b22d Mon Sep 17 00:00:00 2001 From: MilhouseVH Date: Tue, 12 Dec 2017 00:59:14 +0000 Subject: [PATCH] shadow: detect corrupt content --- packages/sysutils/systemd/scripts/usercache-setup | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/sysutils/systemd/scripts/usercache-setup b/packages/sysutils/systemd/scripts/usercache-setup index 1f57204283..a0c9e4f2e7 100755 --- a/packages/sysutils/systemd/scripts/usercache-setup +++ b/packages/sysutils/systemd/scripts/usercache-setup @@ -25,8 +25,13 @@ if [ -f /storage/.cache/shadow -a -f /usr/cache/shadow ]; then # Get existing root details (possibly user defined) userroot="$(grep "^root:" /storage/.cache/shadow)" - # Overwrite users shadow file with default details, but replacing root with any existing value - [ -n "${userroot}" ] && sed -e "s ^root:.* ${userroot} " /usr/cache/shadow >/storage/.cache/shadow + # Overwrite users shadow file with default details, replacing root with any existing value + # If current file is garbage (ie. missing root) then replace it + if [ -n "${userroot}" ]; then + sed -e "s ^root:.* ${userroot} " /usr/cache/shadow >/storage/.cache/shadow + else + cp -fp /usr/cache/shadow /storage/.cache/shadow + fi # Make sure we have the correct permission chmod 000 /storage/.cache/shadow