blob: 1228c013d6181a3b170c0a2f38ff0fab2269a489 [file] [log] [blame]
robbiewe6928cf2004-04-21 17:33:35 +00001#!/bin/sh
2#*********************************************************************
mridgeb641f412004-10-04 20:50:53 +00003# Copyright (c) International Business Machines Corp., 2003, 2004
robbiewe6928cf2004-04-21 17:33:35 +00004#
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 pronram; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18#
robbiewe6928cf2004-04-21 17:33:35 +000019# FILE : su
20#
21# PURPOSE: Tests the basic functionality of `su`.
22#
23# SETUP: The program `/usr/bin/expect' MUST be installed.
24#
25# HISTORY:
mridgeb641f412004-10-04 20:50:53 +000026# 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
robbiewe6928cf2004-04-21 17:33:35 +000029#
30#*********************************************************************
31
32if [ -z ${TCbin} ]
33then
34 export TCbin=$PWD
35fi
36
37export TEST_USER1="su_usr1"
mridge4e88baa2004-07-28 18:58:30 +000038
39tvar=${MACHTYPE%-*}
40tvar=${tvar#*-}
41
mridgeb641f412004-10-04 20:50:53 +000042# need to export tvar for su01_s1
43export tvar
subrata_modak6d561072009-07-08 17:53:47 +000044printf "Machine type is: $tvar\n\n"
mridgeb641f412004-10-04 20:50:53 +000045
subrata_modak97544a12009-10-26 15:07:57 +000046if [ "$tvar" = "redhat" -o "$tvar" = "redhat-linux" ]
mridgeb641f412004-10-04 20:50:53 +000047# Need to also set group for TEST_USER2
mridge4e88baa2004-07-28 18:58:30 +000048then
49export TEST_USER1_GROUP="wheel"
mridgeb641f412004-10-04 20:50:53 +000050export TEST_USER2_GROUP="wheel"
mridge4e88baa2004-07-28 18:58:30 +000051else
robbiewe6928cf2004-04-21 17:33:35 +000052export TEST_USER1_GROUP="trusted"
mridgeb641f412004-10-04 20:50:53 +000053export TEST_USER2_GROUP="trusted"
mridge4e88baa2004-07-28 18:58:30 +000054fi
robbiewe6928cf2004-04-21 17:33:35 +000055export TEST_USER1_PASSWD="eal"
56export TEST_USER1_ENCRYPTED_PASSWD="42VmxaOByKwlA"
57export TEST_USER1_NEW_PASSWD="a_very_good_and_long_password"
58export TEST_USER1_HOMEDIR="/home/$TEST_USER1"
59
60export TEST_USER2="su_usr2"
mridgeb641f412004-10-04 20:50:53 +000061# Group needs to be trusted for Red Hat.
62#export TEST_USER2_GROUP="trusted"
robbiewe6928cf2004-04-21 17:33:35 +000063export TEST_USER2_PASSWD="eal"
64export TEST_USER2_ENCRYPTED_PASSWD="42VmxaOByKwlA"
65export TEST_USER2_HOMEDIR="/home/$TEST_USER2"
66
67#This is for enviroment test
68export TEST_LINE="YOU_HAVE_THE_VARIABLE"
69export TEST_ENV_FILE="/tmp/TEST_ENV_FILE_ROOT"
70export TEST_ENV_FILE_USER="/tmp/TEST_ENV_FILE_USER"
71export TEST_ENV_FILE2="/tmp/TEST_ENV_FILE_ROOT2"
72#-----------------------------------------------------------------------
73# FUNCTION: do_setup
74#-----------------------------------------------------------------------
75
76do_setup(){
77
78#REMOVE ANY TEMPOARY FILES THAT MAY STILL BE AROUND
subrata_modak6d561072009-07-08 17:53:47 +000079rm -f $TEST_ENV_FILE_USER > /dev/null 2>&1
80rm -f $TEST_ENV_FILE2 > /dev/null 2>&1
81rm -f $TEST_ENV_FILE > /dev/null 2>&1
robbiewe6928cf2004-04-21 17:33:35 +000082
83
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
89
90 useradd -m -g users $TEST_USER1
91 if [ $? != 0 ]
92 then {
93 echo "Could not add test user $TEST_USER1."
94 exit 1
95 }
96 fi
97
98 usermod -G users,$TEST_USER1_GROUP $TEST_USER1
99
mridgeb641f412004-10-04 20:50:53 +0000100 #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.
subrata_modak97544a12009-10-26 15:07:57 +0000102 if [ "$tvar" != "redhat" -a "$tvar" != "redhat-linux" ]
mridgeb641f412004-10-04 20:50:53 +0000103 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
108 }
109 fi
robbiewe6928cf2004-04-21 17:33:35 +0000110
subrata_modak6d561072009-07-08 17:53:47 +0000111 usermod -p $TEST_USER1_ENCRYPTED_PASSWD $TEST_USER1 > /dev/null 2>&1
robbiewe6928cf2004-04-21 17:33:35 +0000112 if [ $? != 0 ]
113 then {
114 echo "Could not set password for test user $TEST_USER1"
115 exit 1
116 }
117 fi
118
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
124
125 useradd -m -g users $TEST_USER2
126
127 if [ $? != 0 ]
128 then {
129 echo "Could not add test user $TEST_USER2."
130 exit 1
131 }
132 fi
133
134 usermod -G users,$TEST_USER2_GROUP $TEST_USER2
135
136 #create users home diretory (SLES 8 does not do this, even when specified in adduser)
mridgeb641f412004-10-04 20:50:53 +0000137# Only do this if not RH; RH creates the directory.
subrata_modak97544a12009-10-26 15:07:57 +0000138 if [ "$tvar" != "redhat" -a "$tvar" != "redhat-linux" ]
mridgeb641f412004-10-04 20:50:53 +0000139 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
144 }
145 fi
robbiewe6928cf2004-04-21 17:33:35 +0000146
subrata_modak6d561072009-07-08 17:53:47 +0000147 usermod -p $TEST_USER2_ENCRYPTED_PASSWD $TEST_USER2 > /dev/null 2>&1
robbiewe6928cf2004-04-21 17:33:35 +0000148 if [ $? != 0 ]
149 then {
150 echo "Could not set password for test user $TEST_USER2"
151 exit 1
152 }
153 fi
154}
155
156
157#-----------------------------------------------------------------------
158# FUNCTION: do_cleanup
159#-----------------------------------------------------------------------
160
161do_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
subrata_modak6d561072009-07-08 17:53:47 +0000167 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
robbiewe6928cf2004-04-21 17:33:35 +0000170}
171
172#-----------------------------------------------------------------------
173# FUNCTION: MAIN
174#-----------------------------------------------------------------------
175do_setup
176/bin/su $TEST_USER1 -c ${TCbin}/su01_s1
177EXIT_CODE=$?
178do_cleanup
179exit $EXIT_CODE