#!/bin/sh
#  This software was derived from SATAN 1.1.1 by Dan Farmer and Wietse Venema
#  (http://www.porcupine.org/satan).
#
#
#  Does host trust us?  What is in hosts.equiv (probably a "+", if
# this works...)  Should run as "root"
#
#  CHANGES TO BE DONE: do something with the output.
#
#
# version 2, Sat Apr  8 21:02:49 1995, last mod by wietse
# version 3, Mon Mar  8 23:30:00 1999, last mod by todd
#

. config/paths.sh

user=bin
tmp_file="./tmp_file.$$"
# arg stuff:
while $TEST $# != 0
        do      case "$1" in
        -u)     user=$2 ; shift ;;
        *)      target=$1
        esac
        shift
        done

if $TEST "X$target" = "X" ; then
        $ECHO Usage $0 [-u user] target
        exit 1
        fi

# used in final output
service="shell"
status="a"
service_output=""


# Check to see if we are who we should be -- bin or whatever:
whoami=`$WHOAMI`

if $TEST "$whoami" = "root" ; then
	$RCMD $target $user "file /bin/sh" > $tmp_file 2>&1 
else
	# $ECHO Must be run as root
	exit 2
	fi
if $GREP /bin/sh "$tmp_file" >/dev/null ; then
	# do we want to put the output into a data file?
	# $ECHO $target /etc/hosts.equiv file: `$CAT $tmp_file`
	trustee="USER@$target"
	service_output="remote service access"
	if $TEST $user = "bin" ; then
		trusted="ANY@ANY"
		text="user bin with passwd NONE can access service $service"

		# assume if you can get bin, a "+" in hosts.equiv, == root
        	severity="rs"
                $ECHO "$target|$service|$status|$severity|$trustee|$trusted|$service_output|$text"
	else
		trusted="$user@ANY"
		text="user $user with passwd NONE can access service $service"
        	severity="us"
                $ECHO "$target|$service|$status|$severity|$trustee|$trusted|$service_output|$text"
		fi
     elif $GREP -i Permission "$tmp_file" >/dev/null ; then
        severity="zwoi"
	trustee="ANY@$target"
	trusted="ANY@$target"
	service_output="Doubtful Internet service"
	text="confirm that rshd should be running"
        $ECHO "$target|$service|$status|$severity|$trustee|$trusted|$service_output|$text"
	fi

$RM -f $tmp_file

exit 0

# finis
