#!bin/sh
#
#     tiger - A UN*X security checking system
#     Copyright (C) 1993 Douglas Lee Schales, David K. Hess, David R. Safford
#     Copyright (C) 2003 Michael Sconzo
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 1, or (at your option)
#    any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#     Please see the file `COPYING' for the complete copyright notice.
#
#  check_xinetd - 02/11/03
#
#-----------------------------------------------------------------------------
#
TigerInstallDir='.'

#
# Set default base directory.
# Order or preference:
#      -B option
#      TIGERHOMEDIR environment variable
#      TigerInstallDir installed location
#
basedir=${TIGERHOMEDIR:=$TigerInstallDir}

for parm
do
   case $parm in
   -B) basedir=$2; break;;
   esac
done
#
# Verify that a config file exists there, and if it does
# source it.
#
[ ! -r $basedir/config ] && {
  echo "--ERROR-- [init002e] No 'config' file in \`$basedir'."
  exit 1
}
. $basedir/config

. $BASEDIR/initdefs
#
# If run in test mode (-t) this will verify that all required
# elements are set.
#
[ "$Tiger_TESTMODE" = 'Y' ] && {
  haveallcmds SED AWK CAT COMM GEN_INETD_SETS GEN_SERVICES_SETS GREP JOIN LS R
M SORT TAIL UNIQ || exit 1
  haveallfiles BASEDIR WORKDIR INETDFILE SERVICESFILE || exit 1
  
  echo "--CONFIG-- [init003c] $0: Configuration ok..."
  exit 0
}

#------------------------------------------------------------------------
echo
echo "# Performing check of 'xinetd' related services..."

check_config()
{

	xinetd_dir="$1"
	cd $xinetd_dir
	for FILE in `$LS`
	do
		if ["`$GREP -i 'disable' $FILE | $AWK '{print $NF}'`" = "no" ] ; 
		then
			BINARY=`$GREP -w 'server' $FILE | $GREP '=' | $AWK '{print $NF}'`
			echo "--WARN-- [xnet001w] $FILE service is enabledi using: $BINARY"
		fi
	done
}

if [ -r /etc/xinetd.conf ] ;
then
        echo "--INFO-- [xnet001i] using /etc/xinetd.conf as config file" 
	xinetd_directory=`$GREP 'includedir' /etc/xinetd.conf | $AWK '{print $NF}'`
	check_config $xinetd_directory
elif [ -r /usr/local/etc/xinetd.conf ] ;
then
        echo "--INFO-- [xnet001i] using /usr/local/etc/xinetd.conf as config file" 
	xinetd_directory=`$GREP 'includedir' /usr/local/etc/xinetd.conf | $AWK '{print $NF}'`
	check_config $xinetd_directory
else
	echo "--FAIL-- [xnet001f] It appears that xinetd is not installed"
fi
