ssh01 revision 77ce60052b21f40ca2c75e40d08fe3cd375c0bc8
1#!/bin/sh
2#*********************************************************************
3#   Copyright (c) International Business Machines  Corp., 2000
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#  FILE   : ssh
20#
21#  PURPOSE: Tests to see that ssh rejects an invalid password
22#
23#  SETUP: The program `/usr/bin/expect' MUST be installed.
24#
25#  HISTORY:
26#    03/03 Jerone Young (jeroney@us.ibm.com)
27#
28
29#-----------------------------------------------------------------------
30# FUNCTION:  do_setup
31#-----------------------------------------------------------------------
32
33do_setup()
34{
35    export RHOST="localhost"
36    export TEST_USER="ssh_usr1"
37    export TEST_USER_PASSWD="now_this_is_a_good_ltp_test_password"
38    export TEST_USER_ENCRYPTED_PASSWD="42VmxaOByKwlA"
39    export TEST_USER_HOMEDIR="/home/$TEST_USER"
40
41    exists expect ssh ssh01_s1 useradd userdel
42
43    trap do_cleanup EXIT
44
45    # erase user if he/she already exists, so we can have a clean env
46    userdel -r $TEST_USER
47    [ -d "$TEST_USER_HOMEDIR" ] && rm -rf "$TEST_USER_HOMEDIR"
48    sleep 1
49
50    tst_setup
51
52    if ! useradd -m -p $TEST_USER_ENCRYPTED_PASSWD $TEST_USER \
53    -d "$TEST_USER_HOMEDIR"; then
54        end_testcase "Could not add test user $TEST_USER to system $RHOST."
55    fi
56
57    # create users home diretory (SLES 8 does not do this, even when specified
58    # in adduser)
59    if [ ! -d "$TEST_USER_HOMEDIR" ]; then
60        USER_UID=$(id -u $TEST_USER)
61        USER_GID=$(id -g $TEST_USER)
62        if ! mkdir -p "$TEST_USER_HOMEDIR"; then
63            end_testcase "Failed to create $TEST_USER_HOMEDIR"
64        fi
65        chown -Rf $USER_UID.$USER_GID "$TEST_USER_HOMEDIR"
66    fi
67}
68
69#-----------------------------------------------------------------------
70# FUNCTION:  do_cleanup
71#-----------------------------------------------------------------------
72
73do_cleanup()
74{
75    userdel -r $TEST_USER
76    [ -d "$TEST_USER_HOMEDIR" ] && rm -rf "$TEST_USER_HOMEDIR"
77    tst_cleanup
78}
79
80#-----------------------------------------------------------------------
81# FUNCTION:  MAIN
82#
83# DESCRIPTION: Create Test User
84#          Call upon script to make sure test user cannont log in with invalid password
85#          Cleanup Test User from system
86#          Exit with exit code of script called upon
87#-----------------------------------------------------------------------
88. net_cmdlib.sh
89
90read_opts $*
91do_setup
92ssh01_s1 || end_testcase "Testcase failed"
93do_cleanup
94