#!/bin/sh

#################################################################################
#
#   Lynis
# ------------------
#
# Copyright 2007-2008, 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.
#
#################################################################################
#
# Home directories
#
#################################################################################
#
    InsertSection "Home directories"

    # Test        : HOME-9302
    # Description : Create list with home directories
    Register --test-no HOME-9302 --weight L --network NO --description "Create list with home directories"
    if [ ${SKIPTEST} -eq 0 ]; then
	# Read sixth field of /etc/passwd
	logtext "Test: query /etc/passwd to obtain home directories"
        FIND=`awk -F: '{ if ($1 !~ "#") print $6 }' /etc/passwd | sort | uniq`
	for I in ${FIND}; do
	    logtext "Home directory: ${I}"
	    #YYY test if home directory exists
	done
    fi	
#
#################################################################################
#
    # Test        : HOME-9310
    # Description : Check for suspicious shell history files
    Register --test-no HOME-9310 --weight L --network NO --description "Checking for suspicious shell history files"
    if [ ${SKIPTEST} -eq 0 ]; then
	if [ ! "${HOMEDIRS}" = "" ]; then
	    if [ ${OS} = "SunOS" ]; then
	        # Solaris doesn't support -maxdepth
	        FIND=`find ${HOMEDIRS} -name ".*history" -not -type f -print`
	      else
	        FIND=`find ${HOMEDIRS} -maxdepth 1 -name ".*history" -not -type f -print`
	    fi
	    if [ "${FIND}" = "" ]; then
		Display --indent 2 --text "- Checking shell history files... " --result OK --color GREEN
	        logtext "Result: Ok, history files are type 'file'."
	      else
		Display --indent 2 --text "- Checking shell history files... " --result WARNING --color RED
	        logtext "Result: the following files seem to be of the wrong file type:"
	        logtext "Output: ${FIND}"
		logtext "Info: above files could be redirected files to avoid logging and should be investigated"
		report "warning[]=Found incorrect file type while checking shell history files"
		ReportWarning ${TEST_NO} "M" "Incorrect file type found for shell history file"
	        fi
	    logtext "Remarks: ${HOME_HISTORY_LOG_TEXT}"
          else
	    Display --indent 2 --text "- Checking shell history files... " --result SKIPPED --color WHITE
	    logtext "Result: Homedirs is empty, test will be skipped"
	fi
    fi

#
#################################################################################
#
    #YYY
    #echo -n "      - Checking PATH variable vulnerabilities... "
    #
    #FIND=`find ${HOMEDIRS} -name * | grep -r 'PATH=' | egrep '=.:|:.:|:.;' | grep -v 'CDPATH'`
    #if [ "${FIND}" = "" ]
    #  then
    #    logtext "Result: Ok, no special things found in the PATH variable"
    #  else
    #    echo "[ ${WARNING}WARNING${NORMAL} ]"
    #    logtext "Warning: Probably found \".\" in the PATH. Details: ${FIND}"
    #fi
    #
#
#################################################################################
#

wait_for_keypress

#
#================================================================================
# Lynis - Copyright 2007-2008, Michael Boelen - www.rootkit.nl - The Netherlands
