From 5b74b57d1240cfd733955ec7305fa61cdc44c44a Mon Sep 17 00:00:00 2001 From: UltimateByte Date: Tue, 15 Mar 2016 13:40:30 +0100 Subject: [PATCH] Update check_permissions.sh --- lgsm/functions/check_permissions.sh | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/lgsm/functions/check_permissions.sh b/lgsm/functions/check_permissions.sh index f8056b5a4..fb73d5121 100644 --- a/lgsm/functions/check_permissions.sh +++ b/lgsm/functions/check_permissions.sh @@ -8,23 +8,41 @@ lgsm_version="150316" # Description: Checks script, files and folders ownership and permissions. # Useful variables -currentuser="$(whoami)" scriptfullpath="${rootdir}/${selfname}" conclusionpermissionerror="0" fn_check_ownership(){ # Check script ownership -if [ "${currentuser}" != "$(stat -c %U "${scriptfullpath}")" ] && [ "${currentuser}" != "$(stat -c %G "${scriptfullpath}")" ]; then +if [ ! -U "${scriptfullpath}" ] && [ ! -G "${scriptfullpath}" ]; then fn_print_fail_nl "Oops ! Permission denied on ${selfname}" echo " * To check allowed user and group run ls -l ${selfname}" exit 1 fi + # Check rootdir ownership -if [ "${currentuser}" != "$(stat -c %U "${rootdir}")" ] && [ "${currentuser}" != "$(stat -c %G "${rootdir}")" ]; then +if [ ! -U "${rootdir}" ] && [ ! -G "${rootdir}" ]; then fn_print_fail_nl "Oops ! Permission denied on ${rootdir}" echo " * To check allowed user and group run ls -l ${rootdir}" exit 1 fi + +# Check functions ownership +funownfail="0" +if [ -n "${functionsdir}" ]; then + while read -r filename + do + if [ ! -U "${filename}" ] && [ ! -G "${filename}" ]; then + funownfail="0" + conclusionpermissionerror="1" + fi + done <<< "$(find "${functionsdir}" -name "*.sh")" + + if [ "${funownfail}" == "1" ]; then + fn_print_fail_nl "Permission issues found in functions." + echo " * Neither the user or group has full control of some scripts in \"${functionsdir}\"" + echo " * You might wanna run : chmod -R 770 \"${functionsdir}\"" + fi +fi } fn_check_permissions(){ @@ -36,7 +54,7 @@ if [ -n "${rootdir}" ]; then if [ "${userrootdirperm}" != "7" ] && [ "${grouprootdirperm}" != "7" ]; then fn_print_fail_nl "Permission issues found in root directory" echo " * Neither the user or group has full control of \"${rootdir}\"" - echo " * You might wanna run : chmod -R 755 \"${rootdir}\"" + echo " * You might wanna run : chmod -R 770 \"${rootdir}\"" conclusionpermissionerror="1" fi fi @@ -58,7 +76,7 @@ if [ -n "${functionsdir}" ]; then if [ "${funcpermfail}" == "1" ]; then fn_print_fail_nl "Permission issues found in functions." echo " * Neither the user or group has full control of at least some scripts in \"${functionsdir}\"" - echo " * You might wanna run : chmod -R 755 \"${functionsdir}\"" + echo " * You might wanna run : chmod -R 770 \"${functionsdir}\"" fi fi }