home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / cops_104.zip / cops_104 / cron.chk < prev    next >
Text File  |  1992-03-10  |  2KB  |  85 lines

  1. :
  2. #
  3. #  Usage: cron.chk
  4. #
  5. #  This checks pathnames and files inside the cron files /usr/lib/crontab
  6. # for writability.
  7. #
  8. #  Mechanism:  The commands inside the file /usr/lib/crontab are executed
  9. # by root.  This shell script greps for commands/paths that begins with
  10. # "/" and takes each potential problem-string and uses the program
  11. # "is_writable" to determine if it is world writable.  All results are
  12. # echoed to standard output.
  13. #  In addition, it throws away everything that has a /tmp, /dev/null, or
  14. # tty in the writable string, and everything after a ">"; e.g. if crontab
  15. # is writing to a file it doesn't care.
  16. #
  17. #  Cron.chk will try to find a file in /usr/lib/crontab first (bsd),
  18. # and then if it isn't there, it will look in the any alternate
  19. # possible locations next -- right now, /usr/spool/cron/crontab -- to
  20. # see if a directory exists, and, if it does, it checks all the cron
  21. # files in turn.
  22. #
  23. #  WARNING!
  24. #
  25. #  Spurious messages can occur; a more stringent method (if perhaps less
  26. # careful of a check) would be to test just the 6th field, instead of
  27. # all the fields after the fifth.  Also throwing away /tmp, etc. could
  28. # be a mistake.
  29. #
  30.  
  31. #  Location of stuff:
  32. AWK=/bin/awk
  33. SED=/bin/sed
  34. ECHO=/bin/echo
  35. EGREP=/usr/bin/egrep
  36. TEST=/bin/test
  37. CAT=/bin/cat
  38.  
  39. #  Possible location of crontab file:
  40. cron=/usr/lib/crontab
  41. #  alternate reality locations of crontab file:
  42. alt_cron="/usr/spool/cron/crontabs"
  43.  
  44. if $TEST ! -s $cron
  45.     then
  46.     cron=""
  47.     for i in "$alt_cron"
  48.         do
  49.         if $TEST -d $i
  50.             then
  51.             cron=`$ECHO $alt_cron/*`
  52.             fi
  53.         done
  54.  
  55.     if $TEST  -z "$cron"
  56.         then
  57.         exit
  58.         fi
  59.     fi
  60.  
  61. # finally, do the checking -- maybe for one, maybe for lots of
  62. # cron-ites:
  63.  
  64. for cron_kid in $cron
  65.     do
  66.     ./chk_strings $cron_kid
  67.     # A typical crontab entry might look something like this:
  68.     #
  69.     #   0,15,30,45 * * * * /bin/sh /usr/adm/newsyslog
  70.     #
  71.     risky_stuff=`$AWK '{for (i=6;i<NF;i++) printf("%s ", $i); \
  72.         if (NF!=6) printf("%s\n",$NF)}' $cron_kid |
  73.             $SED -e 's/>.*//' -e 's/;//g' |
  74.             $AWK '{ for (i=1; i<=NF; i++) 
  75.                     if (substr($i,1,1)=="/") print $i}'`
  76.     for i in $risky_stuff ; do
  77.         if $TEST `$ECHO $i | $EGREP "/tmp|/dev/null|tty"` ; then
  78.             continue
  79.             fi
  80.         if ./is_writable $i ; then
  81.             $ECHO "Warning!  $i (in $cron_kid) is World writable!"
  82.             fi
  83.         done
  84.     done    # for all the cron-kids
  85.