Optimize IsWorldWritable function, with additional debugging data for developers

This commit is contained in:
mboelen 2016-04-26 13:52:26 +02:00
parent 812a0ea270
commit 216611259e

View File

@ -1183,6 +1183,7 @@
fi fi
} }
################################################################################ ################################################################################
# Name : IsWorldWritable() # Name : IsWorldWritable()
# Description : Determines if a file is writable for all users # Description : Determines if a file is writable for all users
@ -1190,19 +1191,25 @@
# Usage : if IsWorldWritable /etc/motd; then echo "File is writable"; fi # Usage : if IsWorldWritable /etc/motd; then echo "File is writable"; fi
################################################################################ ################################################################################
IsWorldWritable() IsWorldWritable() {
{
sFILE=$1 sFILE=$1
FileIsWorldWritable="" FileIsWorldWritable=""
# Only check the file if it isn't a symlink (after previous check) # Only check if target is a file or directory
if [ -f ${sFILE} -a ! -L ${sFILE} ]; then if [ -f ${sFILE} -o -d ${sFILE} ]; then
FINDVAL=`ls -l ${sFILE} | cut -c 9` FINDVAL=`ls -ld ${sFILE} | cut -c 9`
if [ "${FINDVAL}" = "w" ]; then return 0; LogText "IsWorldWritable: file ${sFILE} is world-writable"; else return 1; fi if IsDeveloperMode; then Debug "File mode of ${sFILE} is ${FINDVAL}"; fi
if [ "${FINDVAL}" = "w" ]; then
if IsDeveloperMode; then LogText "IsWorldWritable: file ${sFILE} is world-writable"; fi
return 0
else
return 1
fi
else else
return 255 return 255
fi fi
} }
################################################################################ ################################################################################
# Name : LogText() # Name : LogText()