3 # Copyright (c) International Business Machines Corp., 2003
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: /var/spool/cron/allow
21 # PURPOSE: Test that /var/spool/cron/deny , does not allow those in the file to run cron jobs.
24 # 04/03 Jerone Young (jyoung5@us.ibm.com)
32 if [ "$tvar" = "redhat" -o "$tvar" = "redhat-linux" ]
34 CRON_DENY
="/etc/cron.deny"
35 CRON_ALLOW
="/etc/cron.allow"
37 CRON_DENY
="/var/spool/cron/deny"
38 CRON_ALLOW
="/var/spool/cron/allow"
42 TEST_USER1_HOME
="/home/$TEST_USER1"
44 TEST_USER2_HOME
="/home/$TEST_USER2"
46 #-----------------------------------------------------------------------
48 #-----------------------------------------------------------------------
51 #move any files that may get in the way
52 rm /tmp
/cron_deny_test
> /dev
/null
2>&1
53 rm /tmp
/cron_deny_test1
> /dev
/null
2>&1
55 mv $CRON_DENY $CRON_DENY.old
> /dev
/null
2>&1
56 mv $CRON_ALLOW $CRON_ALLOW.old
> /dev
/null
2>&1
58 #remove users for clean enviroment
59 su
$TEST_USER1 -c "crontab -r"
60 su
$TEST_USER2 -c "crontab -r"
61 rm -rf /home
/$TEST_USER1
62 rm -rf /home
/$TEST_USER2
68 useradd
-m -g users
$TEST_USER1
71 echo "Could not add test user $TEST_USER1 to system."
77 useradd
-m -g users
$TEST_USER2
80 echo "Could not add test user $TEST_USER2 to system."
86 #-----------------------------------------------------------------------
87 # FUNCTION: do_cleanup
88 #-----------------------------------------------------------------------
90 su
$TEST_USER1 -c "crontab -r"
91 su
$TEST_USER2 -c "crontab -r"
92 rm -rf /home
/$TEST_USER1
93 rm -rf /home
/$TEST_USER2
97 mv $CRON_DENY.old
$CRON_DENY > /dev
/null
2>&1
98 mv $CRON_ALLOW.old
$CRON_ALLOW > /dev
/null
2>&1
99 rm /tmp
/cron_allow_test
>/dev
/null
2>&1
102 #-----------------------------------------------------------------------
104 #-----------------------------------------------------------------------
107 if [ $iam = $TEST_USER1 ]
109 echo "TEST: $CRON_DENY should allow only allow those who are not in the file to
112 echo "(1) TEST THAT PERSON NOT IN $CRON_DENY IS ABLE TO RUN JOB."
115 `date '+%M %H' | awk '{ORS=""; print ($1+2)%60" "$2" * * * "}'` echo "TEST JOB RAN" >> /tmp/cron_deny_test 2>&1
118 echo Error
while adding crontab
for user
$TEST_USER1
122 echo "sleeping for 130 seconds...."
126 test -e /tmp
/cron_deny_test
&& EXIT_CODE
=0
128 if [ $EXIT_CODE = 1 ]; then
129 echo "Cron did not allow user to execute job , TEST FAILED"
131 echo "Cron allowed user to execute test job, TEST PASSED"
134 rm -f /tmp
/cron_deny_test
139 if [ $iam = $TEST_USER2 ]
141 echo "(2) TEST THAT PERSON IN $CRON_DENY IS NOT ABLE TO RUN JOB."
144 `date '+%M' | awk '{ORS=""; print ($1+2)%60 " * * * * "}'` echo "TEST JOB RAN" >> /tmp/cron_deny_test 2>&1
147 echo Error
while adding crontab
for user
$TEST_USER2
150 echo "sleeping for 130 seconds...."
154 test -e /tmp
/cron_deny_test1
&& EXIT_CODE
=1
156 if [ $EXIT_CODE = 0 ]; then
157 echo "Cron did not allow user to execute job , TEST PASSED"
159 echo "Cron allowed user to execute test job, TEST FAILED"
162 rm -f /tmp
/cron_deny_test1
169 #-----------------------------------------------------------------------
171 #-----------------------------------------------------------------------
175 echo $TEST_USER2 > $CRON_DENY
177 su
$TEST_USER1 -c "$0"
182 su
$TEST_USER2 -c "$0"