Using return codes and minor cleanups of code

This commit is contained in:
mboelen 2015-03-25 17:31:17 +01:00
parent 30bc903c5a
commit 9978e5c824

View File

@ -5,8 +5,8 @@
# Lynis # Lynis
# ------------------ # ------------------
# #
# Copyright 2007-2015, Michael Boelen (michael@rootkit.nl), The Netherlands # Copyright 2007-2015, Michael Boelen, CISOfy (michael.boelen@cisofy.com)
# Web site: http://www.rootkit.nl # Web site: https://cisofy.com
# #
# Lynis comes with ABSOLUTELY NO WARRANTY. This is free software, and you are # Lynis comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
# welcome to redistribute it under the terms of the GNU General Public License. # welcome to redistribute it under the terms of the GNU General Public License.
@ -45,7 +45,7 @@
fi fi
if [ -f /etc/COPYRIGHT ]; then if [ -f /etc/COPYRIGHT ]; then
Display --indent 2 --text "- /etc/COPYRIGHT" --result FOUND --color GREEN Display --indent 2 --text "- /etc/COPYRIGHT" --result FOUND --color GREEN
if [ -s /etc/COPYRIGHT ]; then if [ -s /etc/COPYRIGHT ]; then
logtext "Result: /etc/COPYRIGHT available and contains text" logtext "Result: /etc/COPYRIGHT available and contains text"
else else
@ -65,24 +65,24 @@
if [ ${SKIPTEST} -eq 0 ]; then if [ ${SKIPTEST} -eq 0 ]; then
logtext "Test: Testing existence /etc/motd" logtext "Test: Testing existence /etc/motd"
if [ -f /etc/motd ]; then if [ -f /etc/motd ]; then
logtext "Result: file /etc/motd exists" logtext "Result: file /etc/motd exists"
Display --indent 2 --text "- /etc/motd" --result FOUND --color GREEN Display --indent 2 --text "- /etc/motd" --result FOUND --color GREEN
if [ ! -L /etc/motd ]; then if [ ! -L /etc/motd ]; then
IsWorldWritable /etc/motd IsWorldWritable /etc/motd
if [ "${FileIsWorldWritable}" = "TRUE" ]; then if [ $? -eq 1 ]; then
Display --indent 4 --text "- /etc/motd permissions" --result WARNING --color RED Display --indent 4 --text "- /etc/motd permissions" --result WARNING --color RED
logtext "Result: /etc/motd is world writable. Users can change this file!" logtext "Result: /etc/motd is world writable. Users can change this file!"
ReportWarning ${TEST_NO} "H" "/etc/motd is world writable" ReportWarning ${TEST_NO} "H" "/etc/motd is world writable"
else else
Display --indent 4 --text "- /etc/motd permissions" --result OK --color GREEN Display --indent 4 --text "- /etc/motd permissions" --result OK --color GREEN
logtext "Result: /etc/motd is not world writable." logtext "Result: /etc/motd is not world writable."
fi fi
else else
logtext "Result: file /etc/motd is symlink" logtext "Result: file /etc/motd is symlink"
fi fi
else else
logtext "Result: File /etc/motd not found" logtext "Result: File /etc/motd not found"
Display --indent 2 --text "- /etc/motd" --result "NOT FOUND" --color WHITE Display --indent 2 --text "- /etc/motd" --result "NOT FOUND" --color WHITE
fi fi
fi fi
# #
@ -97,23 +97,23 @@
N=0 N=0
logtext "Test: Checking file /etc/motd contents for legal key words" logtext "Test: Checking file /etc/motd contents for legal key words"
for I in ${LEGAL_BANNER_STRINGS}; do for I in ${LEGAL_BANNER_STRINGS}; do
FIND=`grep -i "${I}" /etc/motd` FIND=`grep -i "${I}" /etc/motd`
if [ ! "${FIND}" = "" ]; then if [ ! "${FIND}" = "" ]; then
logtext "Result: found string '${I}'" logtext "Result: found string '${I}'"
N=`expr ${N} + 1` N=`expr ${N} + 1`
fi fi
done done
# Check if we have 5 or more key words # Check if we have 5 or more key words
if [ ${N} -gt 4 ]; then if [ ${N} -gt 4 ]; then
logtext "Result: Found ${N} key words, to warn unauthorized users" logtext "Result: Found ${N} key words, to warn unauthorized users"
Display --indent 4 --text "- /etc/motd contents" --result OK --color GREEN Display --indent 4 --text "- /etc/motd contents" --result OK --color GREEN
AddHP 2 2 AddHP 2 2
else else
logtext "Result: Found only ${N} key words, to warn unauthorized users and could be increased" logtext "Result: Found only ${N} key words, to warn unauthorized users and could be increased"
Display --indent 4 --text "- /etc/motd contents" --result WEAK --color YELLOW Display --indent 4 --text "- /etc/motd contents" --result WEAK --color YELLOW
ReportSuggestion ${TEST_NO} "Add legal banner to /etc/motd, to warn unauthorized users" ReportSuggestion ${TEST_NO} "Add legal banner to /etc/motd, to warn unauthorized users"
AddHP 0 1 AddHP 0 1
fi fi
fi fi
# #
################################################################################# #################################################################################
@ -246,4 +246,4 @@ wait_for_keypress
# HPUX: /etc/copyright # HPUX: /etc/copyright
# #
#================================================================================ #================================================================================
# Lynis - Copyright 2007-2015, Michael Boelen - www.rootkit.nl - The Netherlands # Lynis - Copyright 2007-2015, Michael Boelen, CISOfy - https://cisofy.com