• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3#   Copyright (c) International Business Machines  Corp., 2003, 2005
4#
5#   This program is free software;  you can redistribute it and/or modify
6#   it under the terms of the GNU General Public License as published by
7#   the Free Software Foundation; either version 2 of the License, or
8#   (at your option) any later version.
9#
10#   This program is distributed in the hope that it will be useful,
11#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13#   the GNU General Public License for more details.
14#
15#   You should have received a copy of the GNU General Public License
16#   along with this program;  if not, write to the Free Software
17#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18#
19#
20#
21#  FILE   : ftp
22#
23#  PURPOSE: Tests to see if ftp rejects a 'root' login attempt.
24#
25#  SETUP: The program `/usr/bin/expect' MUST be installed.
26#
27#  HISTORY:
28#   03/04/03 Jerone Young (jeroney@us.ibm.com)
29#   09/21/05 Kris Wilson (krisw@us.ibm.com) Check if vsftpd is on system.
30
31setup()
32{
33	TEST_USER=root
34
35	tvar=${MACHTYPE%-*}
36	tvar=${tvar#*-}
37
38	if [ $tvar = "redhat" -o $tvar = "redhat-linux" ]; then
39		ftpusers="/etc/vsftpd/ftpusers"
40	else
41		ftpusers="/etc/ftpusers"
42	fi
43	echo "Verifying test user $TEST_USER is in ${ftpusers} database..."
44	FTPUSERS=$(awk "/$TEST_USER/" ${ftpusers})
45	if [ -z "$FTPUSERS" ] ; then
46		tst_brkm TBROK "$TEST_USER not found in $ftpusers exiting 0 ..."
47	fi
48}
49
50do_test()
51{
52	FAIL_230="==> TEST : FAIL (ftp allowed login attempt)"
53	PASS_530="==> TEST : PASS (ftp rejected login attempt)"
54	echo "Ftp should reject $TEST_USER from loging in successfully"
55	expect -c "
56		spawn ftp $RHOST
57		sleep 1
58		expect -re \": \"
59		send \"$TEST_USER\r\"
60		expect -re \"Password:\"
61		send \"$TEST_USER_PASSWD\r\"
62		expect {
63			# 230 - Login successful
64			\"230\" {send_user \"$FAIL_230\n\";exit 1}
65			# 530 - Login failed
66			\"530\" {send_user \"$PASS_530\n\";exit 0}
67		}
68		expect \"ftp> \"
69		send \"quit\r\"
70	"
71}
72
73TCID="ftp04"
74TST_TOTAL=1
75
76. test.sh
77. ftp_setup
78
79setup
80do_setup
81
82do_test
83if [ $? -ne 0 ]; then
84	tst_resm TFAIL "Test $TCID FAIL"
85else
86	tst_resm TPASS "Test $TCID PASS"
87fi
88
89tst_exit
90