• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#*********************************************************************
3#   Copyright (c) International Business Machines  Corp., 2003, 2004
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   : su
20#
21#  PURPOSE: Tests the basic functionality of `su`.
22#
23#  SETUP: The program `/usr/bin/expect' MUST be installed.
24#
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
29#
30#*********************************************************************
31
32echo "This script contains bashism that needs to be fixed!"
33
34if [ -z ${TCbin} ]
35then
36   export TCbin=$PWD
37fi
38
39export TEST_USER1="su_usr1"
40
41tvar=${MACHTYPE%-*}
42tvar=${tvar#*-}
43
44# need to export tvar for su01_s1
45export tvar
46printf "Machine type is: $tvar\n\n"
47
48if [ "$tvar" = "redhat" -o "$tvar" = "redhat-linux" ]
49# Need to also set group for TEST_USER2
50then
51export TEST_USER1_GROUP="wheel"
52export TEST_USER2_GROUP="wheel"
53else
54export TEST_USER1_GROUP="trusted"
55export TEST_USER2_GROUP="trusted"
56fi
57export TEST_USER1_PASSWD="eal"
58export TEST_USER1_ENCRYPTED_PASSWD="42VmxaOByKwlA"
59export TEST_USER1_NEW_PASSWD="a_very_good_and_long_password"
60export TEST_USER1_HOMEDIR="/home/$TEST_USER1"
61
62export TEST_USER2="su_usr2"
63# Group needs to be trusted for Red Hat.
64#export TEST_USER2_GROUP="trusted"
65export TEST_USER2_PASSWD="eal"
66export TEST_USER2_ENCRYPTED_PASSWD="42VmxaOByKwlA"
67export TEST_USER2_HOMEDIR="/home/$TEST_USER2"
68
69#This is for enviroment test
70export TEST_LINE="YOU_HAVE_THE_VARIABLE"
71export TEST_ENV_FILE="/tmp/TEST_ENV_FILE_ROOT"
72export TEST_ENV_FILE_USER="/tmp/TEST_ENV_FILE_USER"
73export TEST_ENV_FILE2="/tmp/TEST_ENV_FILE_ROOT2"
74#-----------------------------------------------------------------------
75# FUNCTION:  do_setup
76#-----------------------------------------------------------------------
77
78do_setup(){
79
80#REMOVE ANY TEMPOARY FILES THAT MAY STILL BE AROUND
81rm -f $TEST_ENV_FILE_USER > /dev/null 2>&1
82rm -f $TEST_ENV_FILE2 > /dev/null 2>&1
83rm -f $TEST_ENV_FILE > /dev/null 2>&1
84
85
86#Create 1st test user
87    #erase user if he may exist , so we can have a clean en
88        rm -rf /home/$TEST_USER1
89        userdel $TEST_USER1
90	sleep 1
91
92        useradd -m -g users $TEST_USER1
93        if [ $? != 0 ]
94        then {
95                echo "Could not add test user $TEST_USER1."
96                exit 1
97        }
98        fi
99
100		usermod -G users,$TEST_USER1_GROUP $TEST_USER1
101
102	#create users home directory (SLES 8 does not do this, even when specified in adduser)
103# Only do this if not RH; RH creates the directory.
104	if [ "$tvar" != "redhat" -a "$tvar" != "redhat-linux" ]
105	then {
106          USER_UID=`id -u $TEST_USER1`
107          USER_GID=`id -g $TEST_USER1`
108          mkdir $TEST_USER1_HOMEDIR
109          chown -R $USER_UID.$USER_GID $TEST_USER1_HOMEDIR
110	}
111	fi
112
113        usermod -p $TEST_USER1_ENCRYPTED_PASSWD $TEST_USER1 > /dev/null 2>&1
114        if [ $? != 0 ]
115        then {
116                echo "Could not set password for test user $TEST_USER1"
117                exit 1
118        }
119        fi
120
121#Create 2nd test user
122	#erase user if he may exist , so we can have a clean en
123        rm -rf /home/$TEST_USER2
124        userdel $TEST_USER2
125	sleep 1
126
127        useradd -m -g users $TEST_USER2
128
129        if [ $? != 0 ]
130        then {
131                echo "Could not add test user $TEST_USER2."
132                exit 1
133        }
134        fi
135
136		usermod -G users,$TEST_USER2_GROUP $TEST_USER2
137
138	#create users home diretory (SLES 8 does not do this, even when specified in adduser)
139# Only do this if not RH; RH creates the directory.
140        if [ "$tvar" != "redhat" -a "$tvar" != "redhat-linux" ]
141        then {
142          USER_UID=`id -u $TEST_USER2`
143          USER_GID=`id -g $TEST_USER2`
144          mkdir $TEST_USER2_HOMEDIR
145          chown -R $USER_UID.$USER_GID $TEST_USER2_HOMEDIR
146	}
147	fi
148
149        usermod -p $TEST_USER2_ENCRYPTED_PASSWD $TEST_USER2 > /dev/null 2>&1
150        if [ $? != 0 ]
151        then {
152                echo "Could not set password for test user $TEST_USER2"
153                exit 1
154        }
155        fi
156}
157
158
159#-----------------------------------------------------------------------
160# FUNCTION:  do_cleanup
161#-----------------------------------------------------------------------
162
163do_cleanup() {
164        rm -rf /home/$TEST_USER1
165        rm -rf /home/$TEST_USER2
166	userdel $TEST_USER1
167	userdel $TEST_USER2
168	#REMOVE ANY TEMPOARY FILES THAT MAY STILL BE AROUND
169	rm -f $TEST_ENV_FILE_USER > /dev/null 2>&1
170	rm -f $TEST_ENV_FILE2 > /dev/null 2>&1
171	rm -f $TEST_ENV_FILE > /dev/null 2>&1
172}
173
174#-----------------------------------------------------------------------
175# FUNCTION:  MAIN
176#-----------------------------------------------------------------------
177do_setup
178/bin/su $TEST_USER1 -c ${TCbin}/su01_s1
179EXIT_CODE=$?
180do_cleanup
181exit $EXIT_CODE
182