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:
authormboelen <michael@cisofy.com>2016-04-26 22:20:37 +0300
committermboelen <michael@cisofy.com>2016-04-26 22:20:37 +0300
commitc98b37955c6089d5a7602337a3d9394496fe6055 (patch)
tree394f0a2455393c34635f3b7f50693024dab2b53f /include
parent098a2e3760b8cd4e97536cf9ea8960f5c08ec5b2 (diff)
Added IsOwnedByRoot function
Diffstat (limited to 'include')
-rw-r--r--include/functions39
1 files changed, 39 insertions, 0 deletions
diff --git a/include/functions b/include/functions
index 7f364410..2a97f51c 100644
--- a/include/functions
+++ b/include/functions
@@ -48,6 +48,7 @@
# IsRunning Check if a process is running
# InsertSection Insert a section block
# InsertPluginSection Insert a section block for plugins
+# IsOwnedByRoot Determine if file or directory is owned by root
# IsVerbose Check if --verbose is used
# IsVirtualMachine Check if this system is a virtual machine
# IsWorldExecutable Check if a file is world executable
@@ -935,6 +936,44 @@
################################################################################
+ # Name : IsOwnedByRoot
+ # Description : Check if file or directory is owned by root
+ # Returns : 0 (true), 1 (false), or 255 (unknown)
+ ################################################################################
+
+ IsOwnedByRoot() {
+ local PERMS=""
+ if [ $# -eq 1 ]; then
+ FILE="$1"
+ case $OS in
+ "AIX")
+ if [ ! "${ISTATBINARY}" = "" ]; then PERMS=`${ISTATBINARY} ${FILE} | sed "s/Owner: //" | sed "s/[a-zA-Z() ]//g"`; fi
+ ;;
+ "Linux")
+ if [ ! "${STATBINARY}" = "" ]; then PERMS=`${STATBINARY} -c "%u:%g" ${FILE}`; fi
+ ;;
+ "FreeBSD")
+ if [ ! "${STATBINARY}" = "" ]; then PERMS=`${STATBINARY} -f "%u:%g" ${FILE}`; fi
+ ;;
+ esac
+ # Fallback with ls (for other platforms, or when a test did not reveal any output)
+ if [ "${PERMS}" = "" ]; then
+ PERMS=`ls -n ${FILE} | ${AWKBINARY} '{ print $3":"$4 }'`
+ fi
+ else
+ ReportException "IsOwnedByRoot" "Functions needs 1 argument"
+ return 255
+ fi
+ if [ "${PERMS}" = "0:0" ]; then
+ if IsDeveloper; then LogText "Debug: found incorrect file permissions on ${FILE}"; fi
+ return 0
+ else
+ return 1
+ fi
+ }
+
+
+ ################################################################################
# Name : IsVerbose
# Description : Check if --verbose option is used to show more details on screen
# Returns : 0 (true) or 1 (false)