From 691019f9ae13ea4fdcbf9891a7005ff3f976324d Mon Sep 17 00:00:00 2001 From: mboelen Date: Mon, 8 Sep 2014 21:30:54 +0200 Subject: Added FileIsReadable function --- include/functions | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/include/functions b/include/functions index 86d2fefb..97c8e452 100644 --- a/include/functions +++ b/include/functions @@ -29,6 +29,7 @@ # ExitClean Stop the program (cleanly) # ExitFatal Stop the program (cleanly), with fatal # FileExists Check if a file exists on the disk +# FileIsReadable Check if a file is readable or directory accessible # GetHostID Retrieve an unique ID for this host # InsertSection Insert a section block # InsertPluginSection Insert a section block for plugins @@ -75,6 +76,8 @@ fi } + + ################################################################################ # Name : CheckItem() # Description : Check if a specific item exists in the report @@ -242,6 +245,33 @@ fi } + + ################################################################################ + # Name : FileIsReadable + # Description : Check if a file readable or directory is accessible + # Returns : CANREAD (0 or 1) + ################################################################################ + + FileIsReadable() + { + CHECKFILE=$1 + CANREAD=0 + if [ -d ${CHECKFILE} ]; then + OTHERPERMS=`ls -d -l ${CHECKFILE} | cut -c 8` + elif [ -f ${CHECKFILE} ]; then + OTHERPERMS=`ls -d -l ${CHECKFILE} | cut -c 8` + else + OTHERPERMS="-" + fi + # Check if we have the read bit + if [ "${OTHERPERMS}" = "r" ]; then + CANREAD=1 + fi + } + + + + # Get Host ID GetHostID() { -- cgit v1.2.3