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 / dev.chk < prev    next >
Text File  |  1992-03-10  |  3KB  |  129 lines

  1. :
  2. #
  3. #  dev.chk [-g]
  4. #
  5. #   This shell script checks the permissions of all devs listed in the
  6. # file /etc/fstab (the "mount" command would be a preferable way of
  7. # getting the file system name, but the syntax of the output is variable
  8. # from machine to machine), and flags them if they are readable by using
  9. # the "is_able" command.  It also checks for unrestricted NFS
  10. # mountings.  By default, dev_check will flag devs only if world readable
  11. # or writable.  The -g option tells it to print out devs that are also
  12. # group readable/writable.
  13. #   As an aside, the fact that NFS mounted dirs are world readable isn't
  14. # a big deal, but they shouldn't be world writable.  So do two checks here,
  15. # instead of one.
  16. #
  17. # (p.s. /dev/?mem and some misc files used to be checked here, but they
  18. # are now checked in is_able.chk)
  19. #
  20. #  Two types of /etc/fstab formats I've seen so far:
  21. #
  22. #  spec:file:type:freq:passno:name:options
  23. #      NFS are indicated by an "@"
  24. #
  25. #  fsname dir type opts freq passno
  26. #      NFS are indicated by an ":"
  27. #
  28. #  I check for the second; comment that code out (lines 83-84), and
  29. # uncomment the other style (lines 79-80), if you have the first type.
  30. #
  31. AWK=/bin/awk
  32. SED=/bin/sed
  33. LS=/bin/ls
  34. ECHO=/bin/echo
  35. TEST=/bin/test
  36.  
  37. # locations of vital stuff...
  38. mtab=/etc/fstab
  39. exports=/etc/exports
  40.  
  41. group=no
  42.  
  43. if $TEST $# -gt 1 ; then
  44.     $ECHO "Usage: $0 [-g]"
  45.     exit 2
  46. fi
  47.  
  48. if $TEST $# -eq 1 ; then
  49.     if $TEST "X$1" = "X-g" ; then
  50.         group=yes
  51.     else
  52.         $ECHO "Usage: $0 [-g]"
  53.         exit 2
  54.     fi
  55. fi
  56.  
  57. #  Testing filesystems and devices for improper read/write permissions...
  58.  
  59. # grab devices from "/etc/fstab"....
  60. #  Format of /etc/fstab:
  61. #
  62. #  spec:file:type:freq:passno:name:options
  63. #     NFS mounted:
  64. #  uther@foobar.edu:/usr/spaf:ect....
  65. #
  66. #  Or, the default means of checking:
  67. #
  68. #  filesystem   directory   type   options   freq   pass
  69. #     NFS mounted:
  70. #  uther:foobar.edu /usr/spaf....
  71. #
  72. #   kill comments, then get the device/filesystem in question.
  73. #
  74. # First style:
  75. # nfs_devs=`$SED 's/^#.*//' $mtab | $AWK -F: '/@/ {print $2}'`
  76. # local_devs=`$SED -e 's/^#.*$//' -e 's/^.*@.*$//' $mtab|$AWK -F: {print $1}'`
  77.  
  78. # Default style:
  79. nfs_devs=`$SED -e 's/^#.*$//' $mtab | $AWK '/:/ {print $1}'`
  80. local_devs=`$SED -e 's/^#.*$//' -e 's/^.*:.*$//' $mtab | $AWK '{print $1}'`
  81.  
  82. all_devs=$nfs_devs" "$local_devs
  83.  
  84. # Alternate way; grab devices from "mount [-p]"....
  85. #   Format of output from mount (some machines use -p option, some
  86. # don't.  Check your local man page... you might have to add a "-F:" or
  87. # something, depending on your output:
  88. # crit_devs=`/etc/mount -p|$AWK 'index($1, "/")==1
  89. #                    {print $1} \
  90. #                }'`
  91. # On an IBM/AIX box, you can try something like:
  92. # all_devs=`$GREP 'dev.*=' /etc/filesystems | $AWK '{print $NF}'`
  93.  
  94. #
  95. # However, do check for single line entries in /etc/exports:
  96. if $TEST -s $exports
  97.     then
  98.     $SED -e 's/^#.*$//' $exports | $AWK '!/access=/ {
  99.         print "Warning!  NFS file system " $1 " exported with no restrictions!"}'
  100.     fi
  101.  
  102. #
  103. #  Have to get them in the format that "is_able" likes:
  104. #
  105. #  filename {world|group} {writeable|readable|both}
  106. #
  107. # all things check world/group writability
  108. for i in $all_devs
  109.     do
  110.     ./is_able $i w w
  111.     if $TEST "$group" = "yes"
  112.         then
  113.         ./is_able $i g w
  114.         fi
  115.     done
  116.  
  117. #  For local devices, we want to make sure that no one can bypass
  118. # security by reading straight from the device:
  119. for i in $local_devs
  120.     do
  121.     ./is_able $i w r
  122.     if $TEST "$group" = "yes"
  123.         then
  124.         ./is_able $i g r
  125.         fi
  126.     done
  127.  
  128. # end of script
  129.