From d9013b13acf25199690a4c65f9fa337e6b9c8f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20M=C3=A1rkus?= Date: Wed, 16 Oct 2019 16:14:44 +0200 Subject: [PATCH] Fixes CISOfy/lynis#773 --- include/tests_homedirs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/include/tests_homedirs b/include/tests_homedirs index 9b8c9c64..e1cdc9b0 100644 --- a/include/tests_homedirs +++ b/include/tests_homedirs @@ -57,7 +57,8 @@ if [ ${SKIPTEST} -eq 0 ]; then # Check if users' home directories permissions are 750 or more restrictive FOUND=0 - for LINE in $(${EGREPBINARY} -v '^(daemon|git|halt|root|shutdown|sync)' ${ROOTDIR}etc/passwd | ${AWKBINARY} -F: '($7 !~ "/(false|nologin)$") { print }'); do + USERDATA=$(${EGREPBINARY} -v '^(daemon|git|halt|root|shutdown|sync)' ${ROOTDIR}etc/passwd | ${AWKBINARY} -F: '($7 !~ "/(false|nologin)$") { print }') + while read -r LINE; do USER=$(echo ${LINE} | ${CUTBINARY} -d: -f1) DIR=$(echo ${LINE} | ${CUTBINARY} -d: -f6) if [ -d "${DIR}" ]; then @@ -70,7 +71,9 @@ LogText "Result: permissions of home directory ${DIR} of user ${USER} are fine" fi fi - done + done << EOF +$USERDATA +EOF if [ ${FOUND} -eq 1 ]; then Display --indent 2 --text "- Permissions of home directories" --result "${STATUS_WARNING}" --color RED @@ -89,7 +92,8 @@ if [ ${SKIPTEST} -eq 0 ]; then # Check if users own their home directories FOUND=0 - for LINE in $(${EGREPBINARY} -v '^(daemon|git|halt|root|shutdown|sync)' ${ROOTDIR}etc/passwd | ${AWKBINARY} -F: '($7 !~ "/(false|nologin)$") { print }'); do + USERDATA=$(${EGREPBINARY} -v '^(daemon|git|halt|root|shutdown|sync)' ${ROOTDIR}etc/passwd | ${AWKBINARY} -F: '($7 !~ "/(false|nologin)$") { print }') + while read -r LINE; do USER=$(echo ${LINE} | ${CUTBINARY} -d: -f1) DIR=$(echo ${LINE} | ${CUTBINARY} -d: -f6) if [ -d ${DIR} ]; then @@ -101,7 +105,9 @@ LogText "Result: ownership of home directory ${DIR} for user ${USER} looks to be correct" fi fi - done + done << EOF +$USERDATA +EOF if [ ${FOUND} -eq 1 ]; then Display --indent 2 --text "- Ownership of home directories" --result "${STATUS_WARNING}" --color RED