coverity appeasement
[minix.git] / commands / checkhier / checkhier.sh
blob8cc593a151b77c68f502608da4f4ad014d19f6f4
1 #!/bin/sh
3 # checkhier 2.7 - check the directory hierarchy Author: Kees J. Bot
4 # 7 May 1995
6 case "`id`" in
7 'uid=0('*) ;;
8 *) echo "$0: must be run by root" >&2
9 exit 1
10 esac
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
15 # the system.
17 cat <<'EOF'
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
87 EOF
89 } | {
90 # Check if each file has the proper attributes. Offer a correction
91 # if not.
92 banner="\
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
106 # File types?
107 if [ x`expr "$mode" : '\\(.\\)'` != \
108 x`expr "$curmode" : '\\(.\\)'` ]
109 then
110 case $curmode in
111 ?*) echo "${banner}rm -r $file"
112 banner=
113 esac
114 curmode= curowner= curgroup=
115 case $mode in
116 d*) echo "${banner}mkdir $file"
118 -*) echo "${banner}> $file"
120 *) echo "$0: $mode $file: unknown filetype" >&2
121 exit 1
122 esac
123 banner=
126 # Mode?
127 if [ x$mode != x$curmode ]
128 then
129 octmode=
130 m=$mode
131 for i in u g o
133 r=0 w=0 x=0
134 case $m in
135 ?r??*) r=4
136 esac
137 case $m in
138 ??w?*) w=2
139 esac
140 case $m in
141 ???[xst]*) x=1
142 esac
143 octmode=$octmode`expr $r + $w + $x`
144 m=`expr $m : '...\\(.*\\)'`
145 done
146 r=0 w=0 x=0
147 case $mode in
148 ???[sS=]??????) r=4
149 esac
150 case $mode in
151 ??????[sS=]???) w=2
152 esac
153 case $mode in
154 ?????????[tT=]) x=1
155 esac
156 case $r$w$x in
157 000) ;;
158 *) octmode=`expr $r + $w + $x`$octmode
159 esac
161 echo "${banner}chmod $octmode $file"
162 banner=
165 # Ownership?
166 if [ x$owner != x$curowner -o x$group != x$curgroup ]
167 then
168 echo "${banner}chown $owner:$group $file"
169 banner=
172 # The Minix shell forgets processes, so wait explicitly.
173 wait
175 case "$banner" in '') exit 1;; *) exit 0;; esac) || banner=
176 done
177 case "$banner" in
178 '') exit 1
179 esac
180 exit 0