3 # checkhier 2.7 - check the directory hierarchy Author: Kees J. Bot
8 *) echo "$0: must be run by root" >&2
12 # List of all interesting top level files and directories, with mode,
13 # owner and group. Only the key files are listed, the rest is owned
14 # by bin, has mode 755 or 644, and is not critical to the operation of
18 drwxr-xr-x root operator /
19 drwxr-xr-x bin operator /bin
20 drwxr-xr-x root operator /dev
21 drwxr-xr-x root operator /etc
22 -rw-r--r-- root operator /etc/fstab
23 -rw-r--r-- root operator /etc/group
24 -rw-r--r-- root operator /etc/hostname.file
25 -rw-r--r-- root operator /etc/inet.conf
26 -rw-r--r-- root operator /etc/motd
27 -rw-r--r-- root operator /etc/mtab
28 -rw-r--r-- root operator /etc/passwd
29 -rw-r--r-- root operator /etc/profile
30 -rw-r--r-- root operator /etc/protocols
31 -rw-r--r-- root operator /etc/rc
32 -rw-r--r-- root operator /etc/services
33 -rw------- root operator /etc/shadow
34 -rw-r--r-- root operator /etc/termcap
35 -rw-r--r-- root operator /etc/ttytab
36 -rw-r--r-- root operator /etc/utmp
37 dr-xr-xr-x root operator /mnt
38 dr-xr-xr-x root operator /root
39 drwxrwxrwx root operator /tmp
40 drwxr-xr-x root operator /usr
41 drwxr-xr-x root operator /usr/adm
42 -rw-r--r-- root operator /usr/adm/lastlog
43 -rw-r--r-- root operator /usr/adm/wtmp
44 drwxr-xr-x ast other /usr/ast
45 drwxr-xr-x bin operator /usr/bin
46 drwxr-xr-x root operator /usr/etc
47 drwxr-xr-x bin operator /usr/include
48 drwxr-xr-x bin operator /usr/lib
49 drwxrwxr-x root operator /usr/local
50 drwxrwxr-x bin operator /usr/local/bin
51 drwxrwxr-x bin operator /usr/local/include
52 drwxrwxr-x bin operator /usr/local/lib
53 drwxrwxr-x bin operator /usr/local/man
54 drwxrwxr-x bin operator /usr/local/src
55 drwxr-xr-x bin operator /usr/man
56 drwxr-xr-x bin operator /usr/mdec
57 drwx------ root operator /usr/preserve
58 drwxr-xr-x root operator /usr/run
59 drwxr-xr-x root operator /usr/spool
60 drwx--x--x root operator /usr/spool/at
61 drwx--x--x root operator /usr/spool/at/past
62 drwx------ root operator /usr/spool/crontabs
63 drwxrwxr-x root uucp /usr/spool/locks
64 drwx------ daemon daemon /usr/spool/lpd
65 drwxr-xr-x bin operator /usr/src
66 drwxrwxrwx root operator /usr/tmp
67 -rwsr-xr-x root ? /usr/bin/at
68 -rwsr-xr-x root ? /usr/bin/chfn
69 -rwsr-xr-x root ? /usr/bin/chsh
70 -rwsr-xr-x root ? /usr/bin/df
71 -rwsr-xr-x root ? /usr/bin/elvprsv
72 -rwsr-xr-x root ? /usr/bin/elvrec
73 -rwsr-xr-x root ? /usr/bin/format
74 -rwsr-xr-x root ? /usr/bin/hostaddr
75 -rwsr-xr-x root ? /usr/bin/install
76 -rwsr-xr-x daemon ? /usr/bin/lpd
77 -rwsr-xr-x root ? /usr/bin/mail
78 -rwsr-xr-x root ? /usr/bin/mount
79 -rwsr-xr-x root ? /usr/bin/passwd
80 -rwsr-xr-x root ? /usr/bin/ping
81 -rwxr-sr-x ? kmem /usr/bin/ps
82 -rwsr-xr-- root ? /usr/bin/shutdown
83 -rwsr-xr-x root ? /usr/bin/su
84 -rwxr-sr-x ? uucp /usr/bin/term
85 -rwsr-xr-x root ? /usr/bin/umount
86 -rwxr-sr-x ? tty /usr/bin/write
90 # Check if each file has the proper attributes. Offer a correction
93 # List of commands to fix the top level hierarchy. Do not apply these
94 # commands blindly, but check and repair by hand.
97 while read mode owner group
file
99 ( # "fix" a memory leak in set...
101 set -$
- `ls -ld $file 2>/dev/null` '' '' '' ''
102 curmode
=$1 curowner
=$3 curgroup
=$4
103 test $owner = '?' && curowner
=$owner
104 test $group = '?' && curgroup
=$group
107 if [ x
`expr "$mode" : '\\(.\\)'` != \
108 x
`expr "$curmode" : '\\(.\\)'` ]
111 ?
*) echo "${banner}rm -r $file"
114 curmode
= curowner
= curgroup
=
116 d
*) echo "${banner}mkdir $file"
118 -*) echo "${banner}> $file"
120 *) echo "$0: $mode $file: unknown filetype" >&2
127 if [ x
$mode != x
$curmode ]
143 octmode
=$octmode`expr $r + $w + $x`
144 m
=`expr $m : '...\\(.*\\)'`
158 *) octmode
=`expr $r + $w + $x`$octmode
161 echo "${banner}chmod $octmode $file"
166 if [ x
$owner != x
$curowner -o x
$group != x
$curgroup ]
168 echo "${banner}chown $owner:$group $file"
172 # The Minix shell forgets processes, so wait explicitly.
175 case "$banner" in '') exit 1;; *) exit 0;; esac) ||
banner=