From 13a4dff7fe9c837ba16701a37069bf8a68afcc2c Mon Sep 17 00:00:00 2001 From: Michael Boelen Date: Sat, 14 Sep 2019 13:22:50 +0200 Subject: [PATCH] Improved logging of HasCorrectFilePermissions function and use correct value when data has a value of zero --- include/functions | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/include/functions b/include/functions index 73549ad9..ec5e44c9 100644 --- a/include/functions +++ b/include/functions @@ -239,7 +239,6 @@ # busybox does not support format if [ ${SHELL_IS_BUSYBOX} -eq 0 ]; then DATA=$(${STATBINARY} --format=%a ${CHECKFILE}) - LogText "Output: ${DATA}" fi fi @@ -266,15 +265,20 @@ else DATA=$(${LSBINARY} -l ${CHECKFILE} | cut -c 2-10) fi - # Convert permissions to octal - LogText "Converting ${DATA} to octal" - DATA=$(echo ${DATA} | ${AWKBINARY} '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o",k)}') - LogText "Output: ${DATA}" fi + # Convert permissions to octal when needed + case ${DATA} in + "r"|"w"|"x"|"-") + LogText "Converting value ${DATA} to octal" + DATA=$(echo ${DATA} | ${AWKBINARY} '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o",k)}') + if [ "${DATA}" = "0" ]; then DATA="000"; fi + ;; + esac + if [ -n "${DATA}" ]; then if [ "${DATA}" = "${CHECK_PERMISSION}" ]; then - LogText "Outcome: correct permissions" + LogText "Outcome: correct permissions (${DATA})" return 0 fi else @@ -282,7 +286,7 @@ fi done - LogText "Did not find the permissions of file ${CHECKFILE} matching any of the ${CHECKPERMISSION_FULL} values" + LogText "Outcome: permissions of file ${CHECKFILE} are not matching expected value (${DATA} != ${CHECKPERMISSION_FULL})" # No match, return exit code 1 return 1 fi