From 216611259edd429088d400ce918713704f0aa906 Mon Sep 17 00:00:00 2001 From: mboelen Date: Tue, 26 Apr 2016 13:52:26 +0200 Subject: Optimize IsWorldWritable function, with additional debugging data for developers --- include/functions | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'include/functions') diff --git a/include/functions b/include/functions index e7fdd97a..7f364410 100644 --- a/include/functions +++ b/include/functions @@ -1183,6 +1183,7 @@ fi } + ################################################################################ # Name : IsWorldWritable() # 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 ################################################################################ - IsWorldWritable() - { + IsWorldWritable() { sFILE=$1 FileIsWorldWritable="" - # Only check the file if it isn't a symlink (after previous check) - if [ -f ${sFILE} -a ! -L ${sFILE} ]; then - FINDVAL=`ls -l ${sFILE} | cut -c 9` - if [ "${FINDVAL}" = "w" ]; then return 0; LogText "IsWorldWritable: file ${sFILE} is world-writable"; else return 1; fi + # Only check if target is a file or directory + if [ -f ${sFILE} -o -d ${sFILE} ]; then + FINDVAL=`ls -ld ${sFILE} | cut -c 9` + 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 return 255 fi - } + } + ################################################################################ # Name : LogText() -- cgit v1.2.3