#!/bin/sh
#
#     tiger - A UN*X security checking system
#     Copyright (C) 1993 Douglas Lee Schales, David K. Hess, David R. Safford
#
#     Please see the file `COPYING' for the complete copyright notice.
#
# check_root - 05/30/99
#
# 05/30/99  Added feature to check for no console root logins
# 09/14/01  Added test for root login for ssh.
#
#
#-----------------------------------------------------------------------------
#
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 AWK CAT GEN_PASSWD_SETS JOIN LS RM || exit 1
  haveallfiles BASEDIR WORKDIR || exit 1
  haveallvars TESTLINK HOSTNAME || exit 1
  
  echo "--CONFIG-- [init003c] $0: Configuration ok..."
  exit 0
}

#------------------------------------------------------------------------
echo
echo "# Performing check of /etc/default/login, /securetty, and /etc/ttytab..."
echo
haveallcmds AWK CAT GEN_PASSWD_SETS JOIN LS RM || exit 1
haveallfiles BASEDIR WORKDIR || exit 1
haveallvars TESTLINK HOSTNAME || exit 1
if [ -f /etc/default/login ]; then
  if [ ! "`grep '^CONSOLE' /etc/default/login`" ]; then
     message WARN root001w "" "Remote root login allowed in /etc/default/login."
     echo
  fi
fi
if [ -f /etc/securetty ]; then
  if [ "`grep '^ttyp' /etc/securetty`" ]; then
     message WARN root001w "" "Remote root login allowed in /etc/securetty"
     echo
  fi
fi   
if [ -f /etc/ttytab ]; then
  if [ "`grep ' secure' /etc/ttytab | grep -v console`" ]; then
     message WARN root001w "" "Remote root login allowed in /etc/ttytab"
     echo
  fi
fi   
if [ -f /etc/ftpusers ]; then
  if [ ! "`grep '^root' /etc/ftpusers`" ]; then
     message WARN root002w "" "Remote root access allowed in /etc/ftpusers"
     echo
  fi
fi
if [ -f /usr/local/etc/sshd_config ]; then
  prl=`grep PermitRootLogin /usr/local/etc/sshd_config`
elif [ -f /etc/sshd_config ]; then
  prl=`grep PermitRootLogin /etc/sshd_config`
  path="/etc/sshd_config"
elif [ -f /etc/ssh2/sshd2_config ]; then
  prl=`grep PermitRootLogin /etc/ssh2/sshd2_config`
  path="/etc/ssh2/sshd2_config"
elif [ -f /etc/ssh/sshd_config ]; then
  prl=`grep PermitRootLogin /etc/ssh/sshd_config`
  path="/etc/ssh/sshd_config"
fi
if [ "$prl" ]; then
  if [ ! "`echo $prl | grep \"^#\"`" ]; then
    if [ "`echo $prl | grep -i yes`" ]; then
      message WARN root001w "" "Remote root login allowed in $path"
    fi
    if [ "`echo $prl | grep -i nopwd`" ]; then
       message WARN root001w "" "root login without pwd allowed in $path"
    fi
  fi
fi
exit 0
