source: trunk/minix/commands/scripts/checkhier.sh@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 4.5 KB
Line 
1#!/bin/sh
2#
3# checkhier 2.7 - check the directory hierarchy Author: Kees J. Bot
4# 7 May 1995
5
6case "`id`" in
7'uid=0('*) ;;
8*) echo "$0: must be run by root" >&2
9 exit 1
10esac
11
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.
16{
17 cat <<'EOF'
18drwxr-xr-x root operator /
19drwxr-xr-x bin operator /bin
20drwxr-xr-x root operator /dev
21drwxr-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
37dr-xr-xr-x root operator /mnt
38dr-xr-xr-x root operator /root
39drwxrwxrwx root operator /tmp
40drwxr-xr-x root operator /usr
41drwxr-xr-x root operator /usr/adm
42-rw-r--r-- root operator /usr/adm/lastlog
43-rw-r--r-- root operator /usr/adm/wtmp
44drwxr-xr-x ast other /usr/ast
45drwxr-xr-x bin operator /usr/bin
46drwxr-xr-x root operator /usr/etc
47drwxr-xr-x bin operator /usr/include
48drwxr-xr-x bin operator /usr/lib
49drwxrwxr-x root operator /usr/local
50drwxrwxr-x bin operator /usr/local/bin
51drwxrwxr-x bin operator /usr/local/include
52drwxrwxr-x bin operator /usr/local/lib
53drwxrwxr-x bin operator /usr/local/man
54drwxrwxr-x bin operator /usr/local/src
55drwxr-xr-x bin operator /usr/man
56drwxr-xr-x bin operator /usr/mdec
57drwx------ root operator /usr/preserve
58drwxr-xr-x root operator /usr/run
59drwxr-xr-x root operator /usr/spool
60drwx--x--x root operator /usr/spool/at
61drwx--x--x root operator /usr/spool/at/past
62drwx------ root operator /usr/spool/crontabs
63drwxrwxr-x root uucp /usr/spool/locks
64drwx------ daemon daemon /usr/spool/lpd
65drwxr-xr-x bin operator /usr/src
66drwxrwxrwx 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
87EOF
88
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.
95"
96
97 while read mode owner group file
98 do
99 ( # "fix" a memory leak in set...
100
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
105
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"
117 ;;
118 -*) echo "${banner}> $file"
119 ;;
120 *) echo "$0: $mode $file: unknown filetype" >&2
121 exit 1
122 esac
123 banner=
124 fi
125
126 # Mode?
127 if [ x$mode != x$curmode ]
128 then
129 octmode=
130 m=$mode
131 for i in u g o
132 do
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
160
161 echo "${banner}chmod $octmode $file"
162 banner=
163 fi
164
165 # Ownership?
166 if [ x$owner != x$curowner -o x$group != x$curgroup ]
167 then
168 echo "${banner}chown $owner:$group $file"
169 banner=
170 fi
171
172 # The Minix shell forgets processes, so wait explicitly.
173 wait
174
175 case "$banner" in '') exit 1;; *) exit 0;; esac) || banner=
176 done
177 case "$banner" in
178 '') exit 1
179 esac
180 exit 0
181}
Note: See TracBrowser for help on using the repository browser.