ftp04 revision aac0ece31ad729d33abbd7124ab538f0cd112e98
1#!/bin/sh
2#
3#   Copyright (c) International Business Machines  Corp., 2003
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 pronram;  if not, write to the Free Software
17#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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#
30
31
32RHOST=localhost
33TEST_USER=root
34
35if [ $PASSWD ]
36then
37	TEST_USER_PASSWORD=$PASSWD
38else	
39	echo "YOU MUST EXPORT PASSWD VARIABLE"
40	exit 1
41fi
42
43
44EXIT_CODE=0
45
46#-----------------------------------------------------------------------
47# FUNCTION:  verify_user_is_in_ftpusers_db
48#-----------------------------------------------------------------------
49                                                                               
50verify_user_is_in_ftpusers_db(){
51
52tvar=${MACHTYPE%-*}
53tvar=${tvar#*-}
54
55       if [ $tvar == "redhat" -o $tvar == "redhat-linux" ] 
56       then
57        echo "Verifying test user $TEST_USER is in /etc/vsftpd.ftpusers database..."
58        FTPUSERS=`grep $TEST_USER /etc/vsftpd.ftpusers`
59       else
60        echo "Verifying test user $TEST_USER is in /etc/ftpusers database..."
61        FTPUSERS=`grep $TEST_USER /etc/ftpusers`
62       fi
63        if [ "x$FTPUSERS" == "x" ]
64        then {
65            echo "Test user $TEST_USER not found in /etc/ftpusers unable to run TEST, exiting 0 ..."
66			exit 0
67         }
68		 fi
69	
70}
71
72#-----------------------------------------------------------------------
73# FUNCTION:  do_test
74#-----------------------------------------------------------------------
75do_test() {
76
77		echo "TEST: Ftp should reject $TEST_USER from loging in successfully"
78        expect -c "
79                   spawn ftp $RHOST
80                   sleep 1
81                   expect -re \": \"
82                   send \"$TEST_USER\r\"
83                   expect -re \"Password:\"
84                   send \"$TEST_USER_PASSWD\r\"
85                   expect {
86                     # 230 - Login successful
87                           \"230\" {send_user \"==> TEST \#$TEST : FAIL (ftp allowed login attempt)\n\";exit 1}
88                     # 530 - Login failed
89                           \"530\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
90                   }
91                   expect \"ftp> \"
92                   send \"quit\r\"
93        "
94
95    if [ $? != 0 ]
96        then {
97        EXIT_CODE=1
98        }
99    fi
100
101}
102
103#----------------------------------------------------------------------
104# FUNCTION: MAIN
105#----------------------------------------------------------------------
106verify_user_is_in_ftpusers_db
107do_test
108exit $EXIT_CODE
109
110
111
112
113
114
115