Fix the creation of the dumpdir directory in stress_floppy Makefile
[ltp-debian.git] / testcases / commands / su / su01
blob1228c013d6181a3b170c0a2f38ff0fab2269a489
1 #!/bin/sh
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
19 # FILE : su
21 # PURPOSE: Tests the basic functionality of `su`.
23 # SETUP: The program `/usr/bin/expect' MUST be installed.
25 # HISTORY:
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 #*********************************************************************
32 if [ -z ${TCbin} ]
33 then
34 export TCbin=$PWD
37 export TEST_USER1="su_usr1"
39 tvar=${MACHTYPE%-*}
40 tvar=${tvar#*-}
42 # need to export tvar for su01_s1
43 export tvar
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
48 then
49 export TEST_USER1_GROUP="wheel"
50 export TEST_USER2_GROUP="wheel"
51 else
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 #-----------------------------------------------------------------------
73 # FUNCTION: do_setup
74 #-----------------------------------------------------------------------
76 do_setup(){
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
84 #Create 1st test user
85 #erase user if he may exist , so we can have a clean en
86 rm -rf /home/$TEST_USER1
87 userdel $TEST_USER1
88 sleep 1
90 useradd -m -g users $TEST_USER1
91 if [ $? != 0 ]
92 then {
93 echo "Could not add test user $TEST_USER1."
94 exit 1
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" ]
103 then {
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
112 if [ $? != 0 ]
113 then {
114 echo "Could not set password for test user $TEST_USER1"
115 exit 1
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
122 userdel $TEST_USER2
123 sleep 1
125 useradd -m -g users $TEST_USER2
127 if [ $? != 0 ]
128 then {
129 echo "Could not add test user $TEST_USER2."
130 exit 1
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" ]
139 then {
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
148 if [ $? != 0 ]
149 then {
150 echo "Could not set password for test user $TEST_USER2"
151 exit 1
157 #-----------------------------------------------------------------------
158 # FUNCTION: do_cleanup
159 #-----------------------------------------------------------------------
161 do_cleanup() {
162 rm -rf /home/$TEST_USER1
163 rm -rf /home/$TEST_USER2
164 userdel $TEST_USER1
165 userdel $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 #-----------------------------------------------------------------------
173 # FUNCTION: MAIN
174 #-----------------------------------------------------------------------
175 do_setup
176 /bin/su $TEST_USER1 -c ${TCbin}/su01_s1
177 EXIT_CODE=$?
178 do_cleanup
179 exit $EXIT_CODE