ftp05 revision ef77253961f909f87e82e6d2b620e87af33e9665
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: Ftp into a remote hosts successfully as a vaild user (other than root) 24# 25# HISTORY: 26# 03/03 Jerone Young (jeroney@us.ibm.com) 27# 04/03 Dustin Kirkland (k1rkland@us.ibm.com) 28# 09/05 Kris Wilson (krisw@us.ibm.com) Check if vsftpd is on system. 29# 30# NOTE: 31# This version is intended for EAL certification, it will need modification 32# to conform with LTP standards in the offical LTP tree. 33 34do_setup() 35{ 36 RHOST="localhost" 37 TEST_USER="anonymous" 38 TEST_USER_PASSWD="noone@nowhere.com" 39 VSFTP_CONF= 40 41 tst_setup 42 43 exists expect ftp vsftpd 44 45 for vsftp_conf in /etc/vsftpd /etc; do 46 47 if [ -r "$vsftp_confdir/vsftp.conf" ]; then 48 VSFTP_CONF="$vsftp_confdir/vsftp.conf" 49 break 50 fi 51 52 done 53 if [ ! -r "$VSFTP_CONF" ] ; then 54 end_testcase "vsftpd.conf not found." 55 fi 56 ANONYMOUS_ENABLE=$(awk -F= '/^anonymous_enable=/ {print $2}' "$VSFTP_CONF") 57 if [ "$ANONYMOUS_ENABLE" != "NO" ]; then 58 ANONYMOUS_ENABLE="YES" 59 fi 60} 61 62#----------------------------------------------------------------------- 63# FUNCTION : do_test 64# 65# DESCRIPTION: The anonymous user will ftp in and create a directory in his/her 66# home directory on the remote host. 67#----------------------------------------------------------------------- 68 69do_test() 70{ 71 tst_resm TINFO "Ftp into a remote host as anonymous user; ANONYMOUS_ENABLE=$ANONYMOUS_ENABLE" 72 73 if [ "$ANONYMOUS_ENABLE" = "YES" ]; then 74 expect -c " 75 spawn ftp $RHOST 76 sleep 1 77 expect -re \": \" 78 send \"$TEST_USER\r\" 79 expect -re \"Password:\" 80 send \"$TEST_USER_PASSWD\r\" 81 expect { 82 # 530 - Login failed 83 \"530\" {send_user \"==> TEST \#$TEST : FAIL (ftp rejected login attempt)\n\";exit 1} 84 # 230 - Login successful 85 \"230\" {send_user \"==> TEST \#$TEST : PASS (ftp allowed login attempt)\n\";exit 0} 86 } 87 expect \"ftp> \" 88 send \"quit\r\" 89 " 90 else 91 expect -c " 92 spawn ftp $RHOST 93 sleep 1 94 expect -re \": \" 95 send \"$TEST_USER\r\" 96 expect -re \"Password:\" 97 send \"$TEST_USER_PASSWD\r\" 98 expect { 99 # 230 - Login successful 100 \"230\" {send_user \"==> TEST \#$TEST : FAIL (ftp allowed login attempt)\n\";exit 1} 101 # 500 - Login failed 102 \"500\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0} 103 # 530 - Login failed 104 \"530\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0} 105 } 106 expect \"ftp> \" 107 send \"quit\r\" 108 " 109 fi 110 111 [ $? -eq 0 ] || end_testcase "Testcase failed." 112 113} 114 115#---------------------------------------------------------------------- 116# FUNCTION: MAIN 117# PURPOSE: To invoke the functions to perform the tasks described in 118# the prologue. 119#---------------------------------------------------------------------- 120. net_cmdlib.sh 121 122read_opts $* 123do_setup 124do_test 125end_testcase 126