ftp04 revision b5bdd9a1d1e8e1377ef16201ce38677b68d4fabf
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 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#   09/21/05 Kris Wilson (krisw@us.ibm.com) Check if vsftpd is on system.
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         # Check if vsftpd is on system.
58         which vsftpd
59         if [ $? != 0 ]
60         then { 
61            echo "vsftpd not found.  Possible cause: does not exist on WS."
62            echo "Test ftp04 FAIL."
63            EXIT_CODE=1
64            exit 1
65       } 
66       fi
67        echo "Verifying test user $TEST_USER is in /etc/vsftpd.ftpusers database..."
68        FTPUSERS=`grep $TEST_USER /etc/vsftpd.ftpusers`
69       else
70        echo "Verifying test user $TEST_USER is in /etc/ftpusers database..."
71        FTPUSERS=`grep $TEST_USER /etc/ftpusers`
72       fi
73        if [ "x$FTPUSERS" == "x" ]
74        then {
75            echo "Test user $TEST_USER not found in /etc/ftpusers unable to run TEST, exiting 0 ..."
76			exit 0
77         }
78		 fi
79	
80}
81
82#-----------------------------------------------------------------------
83# FUNCTION:  do_test
84#-----------------------------------------------------------------------
85do_test() {
86
87		echo "TEST: Ftp should reject $TEST_USER from loging in successfully"
88        expect -c "
89                   spawn ftp $RHOST
90                   sleep 1
91                   expect -re \": \"
92                   send \"$TEST_USER\r\"
93                   expect -re \"Password:\"
94                   send \"$TEST_USER_PASSWD\r\"
95                   expect {
96                     # 230 - Login successful
97                           \"230\" {send_user \"==> TEST \#$TEST : FAIL (ftp allowed login attempt)\n\";exit 1}
98                     # 530 - Login failed
99                           \"530\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
100                   }
101                   expect \"ftp> \"
102                   send \"quit\r\"
103        "
104
105    if [ $? != 0 ]
106        then {
107        EXIT_CODE=1
108        }
109    fi
110
111}
112
113#----------------------------------------------------------------------
114# FUNCTION: MAIN
115#----------------------------------------------------------------------
116verify_user_is_in_ftpusers_db
117do_test
118exit $EXIT_CODE
119
120
121
122
123
124
125