ftp04 revision 4548c6cf9bcdd96d8303caa4130ab638b61f8a30
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 31#----------------------------------------------------------------------- 32# FUNCTION: do_setup 33#----------------------------------------------------------------------- 34 35do_setup() 36{ 37 38 tvar=${MACHTYPE%-*} 39 tvar=${tvar#*-} 40 41 RHOST=localhost 42 TEST_USER=root 43 44 tst_setup 45 46 if [ -n "$PASSWD" ]; then 47 TEST_USER_PASSWORD=$PASSWD 48 else 49 end_testcase "You must set your password via the PASSWD variable." 50 exit 1 51 fi 52 53 exists awk expect ftp vsftpd 54 55 if [ $tvar = "redhat" -o $tvar = "redhat-linux" ]; then 56 echo "Verifying test user $TEST_USER is in /etc/vsftpd.ftpusers database..." 57 FTPUSERS=$(awk "/$TEST_USER/" /etc/vsftpd.ftpusers) 58 else 59 echo "Verifying test user $TEST_USER is in /etc/ftpusers database..." 60 FTPUSERS=$(awk "/$TEST_USER/" /etc/ftpusers) 61 fi 62 if [ -z "$FTPUSERS" ] ; then 63 end_testcase "Test user $TEST_USER not found in /etc/ftpusers unable to run TEST, exiting 0 ..." 64 fi 65 66} 67 68#----------------------------------------------------------------------- 69# FUNCTION: do_test 70#----------------------------------------------------------------------- 71do_test() 72{ 73 74 tst_resm TINFO "Ftp should reject $TEST_USER from loging in successfully" 75 expect -c " 76 spawn ftp $RHOST 77 sleep 1 78 expect -re \": \" 79 send \"$TEST_USER\r\" 80 expect -re \"Password:\" 81 send \"$TEST_USER_PASSWD\r\" 82 expect { 83 # 230 - Login successful 84 \"230\" {send_user \"==> TEST \#$TEST : FAIL (ftp allowed login attempt)\n\";exit 1} 85 # 530 - Login failed 86 \"530\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0} 87 } 88 expect \"ftp> \" 89 send \"quit\r\" 90 " 91 92 [ $? -eq 0 ] || end_testcase "Testcase failed." 93 94} 95 96#---------------------------------------------------------------------- 97# FUNCTION: MAIN 98#---------------------------------------------------------------------- 99. net_cmdlib.sh 100 101read_opts $* 102do_setup 103do_test 104end_testcase 105