Fix the creation of the dumpdir directory in stress_floppy Makefile
[ltp-debian.git] / testcases / commands / cron / cron_neg_tests.sh
blob769ca3486a9a8030f093ee93191931371ed5fa47
1 #!/bin/bash
2 ########################################################
4 # CHANGE ACTIVITY
6 # 10/01/04 Kris Wilson RHEL4 only allows super user
7 # to use crontab.
8 # to use crontab.
9 # 12/03/04 Marty Ridgeway Pull RHEl4 tests out from script
10 ########################################################
12 iam=`whoami`
14 if [ $iam = "root" ]; then
15 if [ $# -lt 1 ] ; then
16 echo Either do not run this script as root or start it like
17 echo " $0 <user>"
18 exit 1
21 su $1 -c "$0 $*"
22 exit $?
26 # 1. root einen cronjob unterjubeln
29 finalrc=0
32 crontab -u root - << EOF
33 0 * * * * true
34 EOF
36 rc=$?
38 if [ $rc = "0" ]; then
39 echo root has now an interesting cron job
40 echo "crontab has a severe security breach (FAIL)"
41 echo
42 finalrc=1
43 else
44 echo "Editing a crontab of another user failed successfully (PASS)"
45 echo
50 # 2. write some illegal crontabs
53 # Save crontab
55 #crontab -l > /dev/null 2> /dev/null
56 #if [ $? = "0" ]; then
57 # echo Saving current crontab...
58 # echo
59 # crontab -l > /tmp/save-crontab-`whoami`
60 # savedcrontab=1
61 # crontab -r
62 #fi
64 #for line in `cat cron_illegal_cron_lines | grep '^[^#]' | sed -e 's/[ \t][ \t]*/_/g'` ; do
65 # line=`echo $line | sed -e 's/_/ /g'`
66 # echo Line: "$line"
67 # cronconf=`echo "$line" | cut -f 1 -d '|'`
68 # desc=`echo "$line" | cut -f 2 -d '|'`
70 # echo "Test: $desc"
71 # echo "$cronconf true" | crontab -
72 # echo "$cronconf"
73 # if [ $? = "0" ]; then
74 # echo 'Test FAILED (or crontab returned wrong exit code)'
75 # echo 'crontab -l:'
76 # crontab -l
77 # finalrc=1
78 # fi
79 # echo
80 #done
83 # Test whether cron uses setuid correctly
85 echo
86 echo setuid test
87 echo
89 tmpscript=cron_neg01_test
90 rm -rf $tmpscript.out &> /dev/null
93 cat > /tmp/$tmpscript << EOF
94 touch /root/halloichwarhier
95 sleep 1
96 cat /root/halloichwarhier ; echo "res:$?"
97 rm /root/halloichwarhier
98 EOF
100 chmod 755 /tmp/$tmpscript
103 cronline=`date '+%M' | awk '{print ($1+2)%60 " * * * * "}'`
104 (echo "$cronline /tmp/$tmpscript >> /tmp/$tmpscript.out 2>> /tmp/$tmpscript.out" ; \
105 echo "$cronline /tmp/$tmpscript >> /$tmpscript.out 2>> /$tmpscript.out") \
106 | crontab -
108 echo "sleeping 130 secs..."
109 sleep 130
111 echo
112 echo "Results:"
113 if [ "1" = `cat /tmp/$tmpscript.out | grep "res:0" | wc -l` ]; then
114 echo "setuid test part 1 successfully failed (PASS)"
115 else
116 echo "cron executed scripts have root privileges! (FAIL)"
117 finalrc=1
120 CODE=0
121 test -e /tmp/$tmpscript.out && CODE=1
122 if [ $CODE = "1" ]; then
123 echo "setuid test part 2 successfully failed (PASS)"
124 else
125 echo "cron writes script output with root privileges! (FAIL)"
126 finalrc=1
128 echo
130 rm /tmp/$tmpscript* &> /dev/null
131 crontab -r
133 # Restore crontab
135 if [ "$savedcrontab" = "1" ]; then
136 echo "Restoring crontab..."
137 cat /tmp/save-crontab-`whoami` | grep '^[^#]' | crontab -
138 # rm -r /tmp/save-crontab-`whoami`
141 exit $finalrc