ftp03 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: 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.conf was found.
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
34#-----------------------------------------------------------------------
35# FUNCTION:  do_setup
36#-----------------------------------------------------------------------
37
38do_setup()
39{
40
41    RHOST="localhost"
42    TEST_USER="ftpuser1"
43    TCtmp=/home/$TEST_USER
44    TEST_USER_PASSWD="eal"
45    TEST_USER_ENCRYPTED_PASSWD="42VmxaOByKwlA"
46    TEST_USER_HOMEDIR="/home/$TEST_USER"
47    VSFTP_CONF=
48
49    tst_setup
50
51    exists ftp useradd userdel vftpd
52
53    for vsftp_conf in /etc/vsftpd /etc; do
54
55        if [ -r "$vsftp_confdir/vsftp.conf" ]; then
56            VSFTP_CONF="$vsftp_confdir/vsftp.conf"
57            break
58        fi
59
60    done
61    if [ ! -r "$VSFTP_CONF" ] ; then
62        end_testcase "vsftpd.conf not found."
63    fi
64    LOCAL_ENABLE=$(awk -F= '/^local_enable=/ {print $2}' "$VSFTP_CONF")
65
66    [ "$LOCAL_ENABLE" != "YES" ] && LOCAL_ENABLE="NO"
67
68    userdel $TEST_USER
69    sleep 1
70
71    if ! useradd -m -p $TEST_USER_ENCRYPTED_PASSWD $TEST_USER; then
72        end_testcase "Could not add test user $TEST_USER on system $RHOST."
73    fi
74
75    trap do_cleanup QUIT
76
77    # create users home diretory (SLES 8 does not do this, even when specified
78    # in adduser)
79    USER_UID=$(id -u $TEST_USER)
80    USER_GID=$(id -g $TEST_USER)
81    mkdir -p "$TEST_USER_HOMEDIR"
82    chown -R $USER_UID:$USER_GID $TEST_USER_HOMEDIR
83
84}
85
86#-----------------------------------------------------------------------
87# FUNCTION:  do_cleanup
88#-----------------------------------------------------------------------
89
90do_cleanup()
91{
92    userdel $TEST_USER
93    tst_cleanup
94}
95
96#-----------------------------------------------------------------------
97# FUNCTION:  do_test
98#
99# DESCRIPTION: The test user will ftp in and create a directory in his home directory on the remote host.
100#              The directory is then checked on the remote hosts to see if it is owned
101#	       by the test user.
102#-----------------------------------------------------------------------
103
104do_test(){
105    tst_resm TINFO "TEST: Ftp into a remote host as a local user (other than root), LOCAL_ENABLE=$LOCAL_ENABLE"
106
107    if [ "$LOCAL_ENABLE" = "YES" ]; then
108	expect -c "
109            spawn ftp $RHOST
110            sleep 1
111            expect -re \": \"
112            send \"$TEST_USER\r\"
113            expect -re \"Password:\"
114            send \"$TEST_USER_PASSWD\r\"
115            expect {
116                # 530 - Login failed
117                \"530\" {send_user \"==> TEST \#$TEST : FAIL (ftp rejected login attempt)\n\";exit 1}
118                # 230 - Login successful
119                \"230\" {send_user \"==> TEST \#$TEST : PASS (ftp allowed login attempt)\n\";exit 0}
120            }
121            expect \"ftp> \"
122            send \"quit\r\"
123	"
124    else
125        expect -c "
126            spawn ftp $RHOST
127            sleep 1
128            expect -re \": \"
129            send \"$TEST_USER\r\"
130            expect -re \"Password:\"
131            send \"$TEST_USER_PASSWD\r\"
132            expect {
133                # 230 - Login successful
134                \"230\" {send_user \"==> TEST \#$TEST : FAIL (ftp allowed login attempt)\n\";exit 1}
135                # 500 - Login failed
136                \"500\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
137                # 530 - Login failed
138                \"530\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
139            }
140            expect \"ftp> \"
141            send \"quit\r\"
142        "
143    fi
144
145    if [ $? != 0 ]; then
146        end_testcase "Testcase failed"
147    fi
148}
149
150#----------------------------------------------------------------------
151# FUNCTION: MAIN
152# PURPOSE:  To invoke the functions to perform the tasks described in
153#           the prologue.
154#----------------------------------------------------------------------
155. net_cmdlib.sh
156
157read_opts $*
158do_setup
159do_test
160end_testcase
161