#!/bin/sh
#
#   Copyright (c) International Business Machines  Corp., 2003
#
#   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 program;  if not, write to the Free Software
#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
#
#
#  FILE   : ftp
#
#  PURPOSE: Test to see if ftp rejects a user with an invalid password
#
#  HISTORY:
#     03/03  Jerone Young (jeroney@us.ibm.com)
#
#  NOTE:
#       This version is intended for EAL certification, it will need modification
#       to conform with LTP standards in the offical LTP tree.
#
# DESCRIPTION:
#	Create Test User
#	Make sure test user cannont log in with invalid password
#	Cleanup Test User from system
#	Exit with exit code of script called upon
#

setup()
{
	export TEST_USER="ftpuser2"
}

do_test()
{
	CONNECTION_FAILED="Connection failed; test FAILED"
	EXPECTED="Login failed as expected; test PASSED"
	UNEXPECTED="Login succeeded unexpectedly; test FAILED"

	set PASSWD "invaild_password?!!"
	set timeout 90

	expect -c "
		#ftp to host
		spawn ftp $RHOST
		sleep 1
		# Check if connection succeeded.
		expect {
			\"Name\" {}
			timeout {send_user \"\n$CONNECTION_FAILED\n\";exit 1}
		}

		send \"$RUSER\r\"
		sleep 1
		expect -re \"Password:\"
		send \"$PASSWD\r\"
		sleep 1

		expect {
			# 530 - Login failed
			\"530\" {send_user \"$EXPECTED\n\";exit 0}
			# 230 - Login successful
			\"230\" {send_user \"$UNEXPECTED\n\"; exit 1}
		}

		expect \"ftp>\"
		send \"exit\r\"
	"
}

TCID="ftp02"
TST_TOTAL=1

. test.sh
. ftp_setup

setup
do_setup
TST_CLEANUP=do_cleanup

do_test
if [ $? -ne 0 ]; then
	tst_resm TFAIL "Test $TCID FAIL"
else
	tst_resm TPASS "Test $TCID PASS"
fi

tst_exit