#! /usr/bin/expect -f
#*********************************************************************
#   Copyright (C) International Business Machines  Corp., 2000
#
#   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 2 of the License, 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.
#
#   You should have received a copy of the GNU General Public License
#   along with this pronram;  if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#  FILE   : ssh 
#
#  PURPOSE: Tests to see that ssh rejects a 'root' login attempt 
#
#  SETUP: The program `/usr/bin/expect' MUST be installed.
#
#  HISTORY:
#    03/03 Jerone Young (jeroney@us.ibm.com)
#    07/04 Daniel H. Jones (danjones@us.ibm.com)
#    07/04 Kimberly D. Simon (kdsimon@us.ibm.com)
#
#
set RHOST localhost

set RUSER root 

if [info exists env(PASSWD)] {
    set PASSWD $env(PASSWD)
} else {
    send_user "YOU NEED TO SET ENVIROMENT VARIABLE PASSWD. \n"
    exit 1
}

set timeout 90

#test root login
send_user "TEST: See if ssh rejects a root login \n"

spawn ssh -l $RUSER $RHOST whoami

while 1 {
    sleep 2
    expect {

        "assword:" {exp_send "$PASSWD\r"}
        "Permission" {
            send_user "\nSSH would not allow $RUSER to login, Test Passed \n"
            send_user "\nTEST PASS\n"
            break
        }
        "$RUSER" {send_user "\nSSH allowed $RUSER to login, Test FAIL \n" ;exit 1}
		"Connection to localhost closed by remote host." {
			send_user "\nSSH would not allow $RUSER to login, Test Passed \n"
			send_user "\nTEST PASS\n"
			break
		}    
}
    sleep 1
}

exit 0
