Imported Upstream version 20091031
[ltp-debian.git] / testcases / network / tcp_cmds / ssh / ssh02
blob84c36374062d8891e7d690a5aa1d86e6d6cae202
1 #!/bin/sh
2 #*********************************************************************
3 # Copyright (c) International Business Machines Corp., 2000
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.
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.
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
19 # FILE : ssh
21 # PURPOSE: Tests to see that ssh rejects an invalid username
23 # SETUP: The program `/usr/bin/expect' MUST be installed.
25 # HISTORY:
26 # 03/03 Jerone Young (jeroney@us.ibm.com)
29 #-----------------------------------------------------------------------
30 # FUNCTION: do_setup
31 #-----------------------------------------------------------------------
33 do_setup()
36 export RHOST="localhost"
37 export TEST_USER="ssh_usr2"
38 export TEST_USER_PASSWD="now_this_is_a_good_ltp_test_password"
39 export TEST_USER_ENCRYPTED_PASSWD="42VmxaOByKwlA"
40 export TEST_USER_HOMEDIR="/home/$TEST_USER"
42 # erase user if he/she already exists, so we can have a clean env
43 TCtmp=/home/$TEST_USER
45 rm -Rf $TCtmp
47 tst_setup
49 exists expect ssh ssh02_s1 useradd userdel
51 userdel $TEST_USER
52 sleep 1
54 if ! useradd -m -p $TEST_USER_ENCRYPTED_PASSWD $TEST_USER; then
55 end_testcase "Could not add test user $TEST_USER to system $RHOST."
58 # create users home diretory (SLES 8 does not do this, even when specified
59 # in adduser)
60 USER_UID=$(id -u $TEST_USER)
61 USER_GID=$(id -g $TEST_USER)
62 if ! mkdir "$TEST_USER_HOMEDIR"; then
63 end_testcase "Failed to create $TEST_USER_HOMEDIR"
65 chown -R $USER_UID.$USER_GID "$TEST_USER_HOMEDIR"
67 trap do_cleanup EXIT
71 #-----------------------------------------------------------------------
72 # FUNCTION: do_cleanup
73 #-----------------------------------------------------------------------
75 do_cleanup()
77 userdel $TEST_USER
78 tst_cleanup
81 #-----------------------------------------------------------------------
82 # FUNCTION: MAIN
84 # DESCRIPTION: Create Test User
85 # Call upon script to make sure an invalid user can not have access
86 # Cleanup Test User from system
87 # Exit with exit code of script called upon
88 #-----------------------------------------------------------------------
89 . net_cmdlib.sh
91 read_opts $*
92 do_setup
93 ssh02_s1 || end_testcase "Testcase failed"
94 do_cleanup