#!/bin/sh

#################################################################################
#
#   Lynis
# ------------------
#
# Copyright 2007-2009, Michael Boelen (michael@rootkit.nl), The Netherlands
# Web site: http://www.rootkit.nl
#
# 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.
# See LICENSE file for usage of this software.
#
#################################################################################
#
# Banners and identification
#
#################################################################################
#
    InsertSection "Banners and identification"
    Display --indent 2 --text "- Checking banners..."
#
#################################################################################
#
    # Test        : BANN-7113
    # Description : Check FreeBSD COPYRIGHT banner file
    Register --test-no BANN-7113 --os FreeBSD --weight L --network NO --description "Check COPYRIGHT banner file"
    if [ ${SKIPTEST} -eq 0 ]; then
	logtext "Test: Testing existence /COPYRIGHT or /etc/COPYRIGHT"
        if [ -f /COPYRIGHT ]; then
	    Display --indent 2 --text "- /COPYRIGHT" --result FOUND --color GREEN
            if [ -e /COPYRIGHT ]; then
		logtext "Result: /COPYRIGHT available, but empty"
	     else
	        logtext "Result: /COPYRIGHT available and contains text"	
	    fi
	  else
    	    Display --indent 2 --text "- /COPYRIGHT" --result "NOT FOUND" --color WHITE
	    logtext "Result: /COPYRIGHT not found"
	fi

	if [ -f /etc/COPYRIGHT ]; then
	    Display --indent 2 --text "- /etc/COPYRIGHT" --result FOUND --color GREEN	
            if [ -e /etc/COPYRIGHT ]; then
	        logtext "Result: /etc/COPYRIGHT available, but empty"
	      else
	        logtext "Result: /etc/COPYRIGHT available and contains text"	
	    fi
	  else
    	    Display --indent 2 --text "- /etc/COPYRIGHT" --result "NOT FOUND" --color WHITE
	    logtext "Result: /etc/COPYRIGHT not found"
        fi

    fi    
#
#################################################################################
#
    # Test        : BANN-7119
    # Description : Check MOTD banner file
    Register --test-no BANN-7119 --weight L --network NO --description "Check MOTD banner file"
    if [ ${SKIPTEST} -eq 0 ]; then
        logtext "Test: Testing existence /etc/motd"
        if [ -f /etc/motd  ]; then
	    logtext "Result: file /etc/motd exists"
	    Display --indent 2 --text "- /etc/motd..." --result FOUND --color GREEN
	    if [ ! -L /etc/motd ]; then
	        IsWorldWritable /etc/motd
		if [ "${FileIsWorldWritable}" = "TRUE" ]; then
		    Display --indent 4 --text "- /etc/motd permissions..." --result WARNING --color RED
		    logtext "Result: /etc/motd is world writable. Users can change this file."
		    ReportWarning ${TEST_NO} "H" "/etc/motd is world writable"
	         else
		    Display --indent 4 --text "- /etc/motd permissions..." --result OK --color GREEN
		    logtext "Result: /etc/motd is not world writable."
		fi
	    fi
	  else
	    logtext "Result: Test skipped"
	    Display --indent 2 --text "- /etc/motd..." --result "NOT FOUND" --color WHITE
        fi
    fi
#
#################################################################################
#
    # Test        : BANN-7124
    # Description : Check issue banner file
    Register --test-no BANN-7124 --weight L --network NO --description "Check issue banner file"
    if [ ${SKIPTEST} -eq 0 ]; then
        logtext "Test: Checking file /etc/issue"
        if [ -f /etc/issue  ]; then
	    logtext "Result: file /etc/issue exists"
	    Display --indent 2 --text "- /etc/issue..." --result FOUND --color GREEN
	  else
	    logtext "Result: Test skipped"
	    Display --indent 2 --text "- /etc/issue..." --result "NOT FOUND" --color WHITE
	fi
    fi
#
#################################################################################
#
    # Test        : BANN-7126
    # Description : Check issue file to see if it contains some form of message
    #               to discourage unauthorized users to leave the system alone
    if [ -f /etc/issue ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
    Register --test-no BANN-7126 --preqs-met ${PREQS_MET} --weight L --network NO --description "Check issue banner file contents"
    if [ ${SKIPTEST} -eq 0 ]; then
        N=0
        logtext "Test: Checking file /etc/issue contents for legal key words"
	PREFERRED_STRINGS="access authorized legal monitor owner policy policies private prohibited this unauthorized"
        for I in ${PREFERRED_STRINGS}; do
	    FIND=`grep "${I}" /etc/issue`
	    if [ ! "${FIND}" = "" ]; then
	        logtext "Result: found string '${I}'"
	        N=`expr ${N} + 1`
	    fi
	done	    
	# Check if we have 5 or more key words
	if [ ${N} -gt 4 ]; then
	    logtext "Result: Found ${N} key words, to warn unauthorized users"
	    Display --indent 4 --text "- /etc/issue contents..." --result OK --color GREEN
	    AddHP 2 2
	  else
	    logtext "Result: Found only ${N} key words, to warn unauthorized users and could be increased"
	    Display --indent 4 --text "- /etc/issue contents..." --result WEAK --color YELLOW
	    AddHP 0 1
	fi
    fi
#
#################################################################################
#

wait_for_keypress

#
#################################################################################
#
# Notes:
# HPUX: /etc/copyright
#
#================================================================================
# Lynis - Copyright 2007-2009, Michael Boelen - www.rootkit.nl - The Netherlands
