3 # Copyright (C) 2008 CAI Qian <caiqian@cclom.cn>
4 # Copyright (c) International Business Machines Corp., 2003
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 # the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this pronram; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 # PURPOSE: Test that /etc/at.deny , does not allow those in the file
27 # 04/03 Jerone Young (jyoung5@us.ibm.com)
31 test_user1
="test_user_1"
32 test_user2
="test_user_2"
33 test_user2_home
="/home/${test_user2}"
34 test_user1_home
="/home/${test_user1}"
35 tmpfile
="/tmp/at_deny_test"
37 #-----------------------------------------------------------------------
39 #-----------------------------------------------------------------------
43 # Move any files that may get in the way.
44 rm "${tmpfile}" >/dev
/null
2>&1
45 mv "${deny}" "${deny}.old" >/dev
/null
2>&1
47 # if /etc/at.allow is there, /etc/at.deny will be ignored. So, we
48 # need to remove it first.
49 if [ -f "/etc/at.allow" ]; then
50 mv /etc
/at.allow
/etc
/at.allow.old
53 # Remove users for clean enviroment.
54 rm -rf "${test_user1_home}" "${test_user2_home}"
55 userdel
-r "${test_user1}" >/dev
/null
2>&1
56 userdel
-r "${test_user2}" >/dev
/null
2>&1
58 # Create the 1st user.
59 useradd
-g users
-d "${test_user1_home}" -m "${test_user1}"
61 echo "Could not add test user ${test_user1} to system."
65 # Create the 2nd user.
66 useradd
-g users
-d "${test_user2_home}" -m "${test_user2}"
68 echo "Could not add test user ${test_user2} to system."
72 # This is the workaround for a potential bug.
73 # [Bug 468337] At Refuse to Work with Non-login Shell
74 # https://bugzilla.redhat.com/show_bug.cgi?id=468337
75 # As we are running in non-login shell now, we cannot run the script
76 # by simply given it a relative path. Therefore, we copy it to test
77 # users' home directories, and run it from there.
78 cp "$0" "${test_user1_home}"
79 cp "$0" "${test_user2_home}"
82 /etc
/init.d
/atd restart
85 #-----------------------------------------------------------------------
86 # FUNCTION: do_cleanup
87 #-----------------------------------------------------------------------
90 # We forcefully remove those files anyway. Otherwise userdel may
91 # give us bad warnings.
92 rm -rf "${test_user1_home}" "${test_user2_home}"
93 userdel
-r "${test_user1}" >/dev
/null
2>&1
94 userdel
-r "${test_user2}" >/dev
/null
2>&1
96 mv "${deny}.old" "${deny}" >/dev
/null
2>&1
97 rm "${tmpfile}" >/dev
/null
2>&1
99 if [ -f /etc
/at.allow.old
]; then
100 mv /etc
/at.allow.old
/etc
/at.allow
104 #-----------------------------------------------------------------------
106 #-----------------------------------------------------------------------
109 if [ $
(whoami
) = "${test_user1}" ]; then
110 echo "TEST: ${deny} should deny only those who are not in the\
112 echo "(1) TEST THAT PERSON NOT IN ${deny} IS ABLE TO RUN JOB."
113 echo "echo 'TEST JOB RAN' >>\"${tmpfile}\" 2>&1" |
114 at -m now
+ 1 minutes
116 echo "Error while adding job using at for user ${test_user1}."
119 echo " Sleeping for 75 seconds...."
123 test -e "${tmpfile}" && exit_code
=0
124 if [ ${exit_code} -eq 1 ]; then
125 echo "At denyed user to execute test job, TEST FAILED."
127 echo "At did not deny user to execute job, TEST PASSED."
130 rm -f "${tmpfile}" >/dev
/null
2>&1
133 elif [ $
(whoami
) = "${test_user2}" ]; then
134 echo "(2) TEST THAT PERSON IN ${deny} IS NOT ABLE TO RUN JOB."
136 echo "echo 'TEST JOB RAN' >>\"${tmpfile}\" 2>&1" |
137 at -m now
+ 1 minutes
139 echo "Expected error while adding job user at for user\
142 echo "Sleeping for 75 seconds...."
146 test -e "${tmpfile}" || exit_code
=0
147 if [ ${exit_code} -eq 1 ]; then
148 echo "At did not deny user to execute job, TEST FAILED."
150 echo "At denyed user to execute test job, TEST PASSED."
153 rm -f "${tmpfile}" >/dev
/null
2>&1
158 #-----------------------------------------------------------------------
160 #-----------------------------------------------------------------------
161 if [ $
(whoami
) = "root" ]; then
163 echo "${test_user2}" >"${deny}"
166 su
"${test_user1}" -lc "${test_user1_home}/$(basename $0)"
171 su
"${test_user2}" -lc "${test_user2_home}/$(basename $0)"