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 / crc.chk < prev    next >
Text File  |  1992-03-10  |  2KB  |  99 lines

  1. :
  2. #
  3. #  Usage: crc.chk
  4. #
  5. #  A CRC generator, checker, slicer and dicer.  See the man page for
  6. # lots more verbage.
  7. #
  8.  
  9. # commands 'n stuff:
  10. AWK=/bin/awk
  11. SED=/bin/sed
  12. SORT=/usr/bin/sort
  13. MV=/bin/mv
  14. MAIL=/bin/mail
  15. CAT=/bin/cat
  16. TEST=/bin/test
  17. ECHO=/bin/echo
  18. RM=/bin/rm
  19. DATE=/bin/date
  20.  
  21. # files used:
  22. crc_list=./crc_list    # lists files used
  23. crc_seed=./crc_seed    # optional -- contains seed
  24. crc_old=./crc_old    # old crc values
  25. crc_tmp=./crc_tmp    # temp storage for the new crc's
  26. crc_res=./crc_res    # difference between new and old crc's
  27. bit_bucket=/dev/null    # junk goes here
  28. results=./crc_results    # results go here; deleted & mailed, or
  29.             # saved here, depending on the "MAIL" flag.
  30.  
  31. # Do you want it mailed?  If "YES", the results file gets deleted
  32. MMAIL=NO
  33. # who gets the report?
  34. INFORM="foo@bar.edu"
  35.  
  36. #   If you don't use an argument, and don't have a seed file, generate
  37. # a semi-random seed:
  38. if $TEST $# -eq 1 ; then
  39.     seed=$1
  40. else
  41.     if $TEST ! -s $crc_seed ; then
  42.         seed=$$
  43.         $ECHO $seed > $crc_seed
  44.     else
  45.         seed=`$CAT $crc_seed`
  46.         fi
  47.     fi
  48.  
  49. # AIX has a broken awk.
  50. # files=`$AWK '/^#/ {next} {print $1}' $crc_list | $SORT -u`
  51. files=`$SED '/^#.*$/d' $crc_list | $SORT -u`
  52.  
  53. # $ECHO crc\'ing, with seed $seed
  54. for i in $files
  55.     do
  56.     ./crc -v -i $seed $i >> $crc_tmp 2> $bit_bucket
  57.     done
  58.  
  59. # First time used, create the database:
  60. if $TEST ! -s $crc_old ; then
  61.     $MV $crc_tmp $crc_old
  62.     exit 0
  63.     fi
  64.  
  65. # any differences?
  66. ./crc_check $crc_old $crc_tmp > $crc_res
  67.  
  68. if $TEST -s $crc_res ; then
  69.  
  70.     # get the hostname:
  71.     if $TEST -s /bin/hostname ; then
  72.                 HOSTNAME=`/bin/hostname`
  73.         elif $TEST -s /bin/uname ; then
  74.                 HOSTNAME=`/bin/uname -n`
  75.         elif $TEST -s /usr/bin/uuname ; then
  76.                 HOSTNAME=`/usr/bin/uuname -l`
  77.                 fi
  78.         if $TEST -z "$HOSTNAME" ; then
  79.                 HOSTNAME="foobar"
  80.                 fi
  81.  
  82.     $ECHO >> $results
  83.     $ECHO ATTENTION:                        >> $results
  84.     $ECHO "CRC Security Report for "`$DATE` >> $results
  85.     $ECHO "from host $HOSTNAME"             >> $results
  86.     $ECHO >> $results
  87.     $CAT $crc_res >>$results
  88.  
  89.     if $TEST $MMAIL = "YES" ; then
  90.         $MAIL $INFORM < $results
  91.         $RM $results
  92.         fi
  93.     fi
  94.  
  95. $RM -f $crc_tmp $crc_res
  96.  
  97. #  end it all....
  98. exit 0
  99.