Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/CISOfy/lynis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Vehrs <dvehrs@gmail.com>2019-10-23 21:31:20 +0300
committerDave Vehrs <dvehrs@gmail.com>2019-10-23 21:31:20 +0300
commit6dad2f476e3ab5386cf573b962f9af58a20fb60f (patch)
treea45c723e5fd35b04862638ee67204fcb9c6eeffa /include/functions
parent0fe16a286e5671802582b10d33016a3cf9cdfdbb (diff)
Updated permissions checks
Diffstat (limited to 'include/functions')
-rw-r--r--include/functions18
1 files changed, 14 insertions, 4 deletions
diff --git a/include/functions b/include/functions
index b96bb070..ea5a2bd3 100644
--- a/include/functions
+++ b/include/functions
@@ -1281,6 +1281,9 @@
CHECK_PERMISSION=$(echo "-${CHECK_PERMISSION}" | ${AWKBINARY} '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o",k)}')
fi
+ # Add leading zeros if necessary
+ CHECK_PERMISSION=$(echo "${CHECK_PERMISSION}" | ${AWKBINARY} '{printf "%03d",$1}')
+
# First try stat command
LogText "Test: checking if file ${CHECKFILE} is ${CHECK_PERMISSION}"
if [ -n "${STATBINARY}" ]; then
@@ -1299,7 +1302,11 @@
*)
# Only use find when OS is NOT AIX and binaries are NOT busybox
if [ ${SHELL_IS_BUSYBOX} -eq 0 ]; then
- DATA=$(${FINDBINARY} ${CHECKFILE} -printf "%m")
+ if [ -d ${CHECKFILE} ]; then
+ DATA=$(${FINDBINARY} ${CHECKFILE} -maxdepth 0 -printf "%m")
+ else
+ DATA=$(${FINDBINARY} ${CHECKFILE} -printf "%m")
+ fi
fi
;;
esac
@@ -1317,13 +1324,16 @@
# Convert permissions to octal when needed
case ${DATA} in
- "r"|"w"|"x"|"-")
+ [-r][-w][-x][-r][-w][-x][-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
+ # add a dummy character as first character so it looks like output is a normal file
+ 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)}')
;;
esac
+ # Add leading zeros if necessary
+ DATA=$(echo "${DATA}" | ${AWKBINARY} '{printf "%03d",$1}')
+
if [ -n "${DATA}" ]; then
if [ "${DATA}" = "${CHECK_PERMISSION}" ]; then
LogText "Outcome: correct permissions (${DATA})"