2 #*********************************************************************
3 # Copyright (c) International Business Machines Corp., 2003, 2004
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
21 # PURPOSE: Tests the basic functionality of `su`.
23 # SETUP: The program `/usr/bin/expect' MUST be installed.
26 # 03/03 Dustin Kirkland (dkirklan@us.ibm.com)
27 # 03/03 Jerone Young (jeroney@us.ibm.com)
28 # 10/01/04 Kris Wilson Port to Red Hat
30 #*********************************************************************
37 export TEST_USER1
="su_usr1"
42 # need to export tvar for su01_s1
44 printf "Machine type is: $tvar\n\n"
46 if [ "$tvar" = "redhat" -o "$tvar" = "redhat-linux" ]
47 # Need to also set group for TEST_USER2
49 export TEST_USER1_GROUP
="wheel"
50 export TEST_USER2_GROUP
="wheel"
52 export TEST_USER1_GROUP
="trusted"
53 export TEST_USER2_GROUP
="trusted"
55 export TEST_USER1_PASSWD
="eal"
56 export TEST_USER1_ENCRYPTED_PASSWD
="42VmxaOByKwlA"
57 export TEST_USER1_NEW_PASSWD
="a_very_good_and_long_password"
58 export TEST_USER1_HOMEDIR
="/home/$TEST_USER1"
60 export TEST_USER2
="su_usr2"
61 # Group needs to be trusted for Red Hat.
62 #export TEST_USER2_GROUP="trusted"
63 export TEST_USER2_PASSWD
="eal"
64 export TEST_USER2_ENCRYPTED_PASSWD
="42VmxaOByKwlA"
65 export TEST_USER2_HOMEDIR
="/home/$TEST_USER2"
67 #This is for enviroment test
68 export TEST_LINE
="YOU_HAVE_THE_VARIABLE"
69 export TEST_ENV_FILE
="/tmp/TEST_ENV_FILE_ROOT"
70 export TEST_ENV_FILE_USER
="/tmp/TEST_ENV_FILE_USER"
71 export TEST_ENV_FILE2
="/tmp/TEST_ENV_FILE_ROOT2"
72 #-----------------------------------------------------------------------
74 #-----------------------------------------------------------------------
78 #REMOVE ANY TEMPOARY FILES THAT MAY STILL BE AROUND
79 rm -f $TEST_ENV_FILE_USER > /dev
/null
2>&1
80 rm -f $TEST_ENV_FILE2 > /dev
/null
2>&1
81 rm -f $TEST_ENV_FILE > /dev
/null
2>&1
85 #erase user if he may exist , so we can have a clean en
86 rm -rf /home
/$TEST_USER1
90 useradd
-m -g users
$TEST_USER1
93 echo "Could not add test user $TEST_USER1."
98 usermod
-G users
,$TEST_USER1_GROUP $TEST_USER1
100 #create users home directory (SLES 8 does not do this, even when specified in adduser)
101 # Only do this if not RH; RH creates the directory.
102 if [ "$tvar" != "redhat" -a "$tvar" != "redhat-linux" ]
104 USER_UID
=`id -u $TEST_USER1`
105 USER_GID
=`id -g $TEST_USER1`
106 mkdir
$TEST_USER1_HOMEDIR
107 chown
-R $USER_UID.
$USER_GID $TEST_USER1_HOMEDIR
111 usermod
-p $TEST_USER1_ENCRYPTED_PASSWD $TEST_USER1 > /dev
/null
2>&1
114 echo "Could not set password for test user $TEST_USER1"
119 #Create 2nd test user
120 #erase user if he may exist , so we can have a clean en
121 rm -rf /home
/$TEST_USER2
125 useradd
-m -g users
$TEST_USER2
129 echo "Could not add test user $TEST_USER2."
134 usermod
-G users
,$TEST_USER2_GROUP $TEST_USER2
136 #create users home diretory (SLES 8 does not do this, even when specified in adduser)
137 # Only do this if not RH; RH creates the directory.
138 if [ "$tvar" != "redhat" -a "$tvar" != "redhat-linux" ]
140 USER_UID
=`id -u $TEST_USER2`
141 USER_GID
=`id -g $TEST_USER2`
142 mkdir
$TEST_USER2_HOMEDIR
143 chown
-R $USER_UID.
$USER_GID $TEST_USER2_HOMEDIR
147 usermod
-p $TEST_USER2_ENCRYPTED_PASSWD $TEST_USER2 > /dev
/null
2>&1
150 echo "Could not set password for test user $TEST_USER2"
157 #-----------------------------------------------------------------------
158 # FUNCTION: do_cleanup
159 #-----------------------------------------------------------------------
162 rm -rf /home
/$TEST_USER1
163 rm -rf /home
/$TEST_USER2
166 #REMOVE ANY TEMPOARY FILES THAT MAY STILL BE AROUND
167 rm -f $TEST_ENV_FILE_USER > /dev
/null
2>&1
168 rm -f $TEST_ENV_FILE2 > /dev
/null
2>&1
169 rm -f $TEST_ENV_FILE > /dev
/null
2>&1
172 #-----------------------------------------------------------------------
174 #-----------------------------------------------------------------------
176 /bin
/su
$TEST_USER1 -c ${TCbin}/su01_s1