Clean more files generated by configure
[ltp-debian.git] / testcases / commands / at / at_deny01
blob9c038455bf7bec23d3e75cf93aa1b98120a153ed
1 #!/bin/sh -u
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
19 # USA
21 # FILE: /etc/at.deny
23 # PURPOSE: Test that /etc/at.deny , does not allow those in the file
24 # to run cron jobs.
26 # HISTORY:
27 # 04/03 Jerone Young (jyoung5@us.ibm.com)
30 deny="/etc/at.deny"
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 #-----------------------------------------------------------------------
38 # FUNCTION: do_setup
39 #-----------------------------------------------------------------------
41 do_setup()
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}"
60 if [ $? != 0 ]; then
61 echo "Could not add test user ${test_user1} to system."
62 exit 1
65 # Create the 2nd user.
66 useradd -g users -d "${test_user2_home}" -m "${test_user2}"
67 if [ $? != 0 ]; then
68 echo "Could not add test user ${test_user2} to system."
69 exit 1
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}"
81 # Restart atd daemon.
82 /etc/init.d/atd restart
85 #-----------------------------------------------------------------------
86 # FUNCTION: do_cleanup
87 #-----------------------------------------------------------------------
88 do_cleanup()
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
95 rm "${deny}"
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 #-----------------------------------------------------------------------
105 # FUNCTION: run_test
106 #-----------------------------------------------------------------------
107 run_test()
109 if [ $(whoami) = "${test_user1}" ]; then
110 echo "TEST: ${deny} should deny only those who are not in the\
111 file to run jobs."
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
115 if [ $? != 0 ]; then
116 echo "Error while adding job using at for user ${test_user1}."
117 exit 1
119 echo " Sleeping for 75 seconds...."
120 sleep 75
122 exit_code=1
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."
126 else
127 echo "At did not deny user to execute job, TEST PASSED."
130 rm -f "${tmpfile}" >/dev/null 2>&1
131 exit ${exit_code}
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
138 if [ $? != 0 ]; then
139 echo "Expected error while adding job user at for user\
140 ${test_user2}"
142 echo "Sleeping for 75 seconds...."
143 sleep 75
145 exit_code=1
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."
149 else
150 echo "At denyed user to execute test job, TEST PASSED."
153 rm -f "${tmpfile}" >/dev/null 2>&1
154 exit ${exit_code}
158 #-----------------------------------------------------------------------
159 # FUNCTION: main
160 #-----------------------------------------------------------------------
161 if [ $(whoami) = "root" ]; then
162 do_setup
163 echo "${test_user2}" >"${deny}"
164 exit_code=0
166 su "${test_user1}" -lc "${test_user1_home}/$(basename $0)"
167 if [ $? != 0 ]; then
168 exit_code=1
171 su "${test_user2}" -lc "${test_user2_home}/$(basename $0)"
172 if [ $? != 0 ]; then
173 exit_code=1
175 do_cleanup
176 exit ${exit_code}
177 else
178 run_test
179 exit 0