]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/netaudit
f043df9885129448c769c11f07953ee9633eb07b
[plan9front.git] / rc / bin / netaudit
1 #!/bin/rc
2 rfork e
3 fn checkhost {
4         if(~ $sysname ''){
5                 echo 'sysname= env var is not set'
6                 exit 'fail'
7         }
8         echo 'checking this host''s tuple:'
9         ip=`{ndb/query sys $sysname ip}
10         if(~ $ip '')
11                 echo '  no ip= entry'
12         if not
13                 echo '  ip='$ip 'looks ok'
14         dom=`{ndb/query sys $sysname dom}
15         if(~ $dom '')
16                 echo '  no dom= entry'
17         if not if(! ~ $dom *.*)
18                 echo '  dom='$dom 'does not have a dot'
19         if not if(! ~ $dom $sysname^.*)
20                 echo '  dom='$dom 'does not start with' $sysname^'; it''s supposed to be the FQDN, not the domain name!'
21         if not
22                 echo '  dom='$dom 'looks ok'
23         ether=`{ndb/query sys $sysname ether}
24         if(~ $ether '')
25                 echo '  no ether entry'
26         if not if(! ~ $ether [0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
27                 echo '  ether='$ether 'has wrong format'
28         if not if(! grep -s $ether /net/ether*/addr)
29                 echo '  ether='$ether 'does not belong to any network interface'
30         if not
31                 echo '  ether='$ether 'looks ok'
32 }
33 fn checknet {
34         echo 'checking the network tuple:'
35         ipnet=`{ndb/ipquery sys $sysname ipnet | sed 's/^ipnet=//'}
36         if(~ $ipnet ''){
37                 echo '  we are not in an ipnet, so looking for entries in host tuple only'
38         }
39         if not
40                 echo '  we are in ipnet='^$ipnet
41         ipgw=`{ndb/ipquery sys $sysname ipgw | sed 's/^ipgw=//'}
42         if(~ $ipgw '' '::'){
43                 echo '  we do not have an internet gateway, no ipgw= entry'
44         }
45         if not {
46                 if(! ~ $ipgw *.*.*.* *:*:*:*:*:*:*:* *::*)
47                         echo '  ipgw='$ipgw 'does not look like an ip address'
48                 if not
49                         echo '  ipgw='$ipgw 'looks ok'
50         }
51         dns=`{ndb/ipquery sys $sysname dns | sed 's/^dns=//'}
52         if(~ $dns '')
53                 echo '  no dns= entry'
54         if not if(! ip/ping -n 1 $dns >/dev/null >[2=1])
55                 echo '  dns='$dns 'does not reply to ping'
56         if not
57                 echo '  dns='$dns 'looks ok'
58         auth=`{ndb/ipquery sys $sysname auth | sed 's/^auth=//'}
59         if(~ $auth '')
60                 echo '  no auth= entry'
61         if not if(! ip/ping -n 1 $auth >/dev/null >[2=1])
62                 echo '  auth='$auth 'does not reply to ping'
63         if not {
64                 authok=1
65                 echo '  auth='$auth 'looks ok'
66         }
67 }
68 fn checkauth {
69         echo 'checking auth server configuration:'
70         if(~ $auth ''){
71                 echo '  no auth server'
72                 exit fail
73         }
74         if not if(~ $auth $sysname){
75                 echo '  we are the auth server'
76                 authisus=1
77         }
78         if not if(~ $auth $dom){
79                 echo '  we are the auth server'
80                 authisus=1
81         }
82         if not if(~ $auth $ip){
83                 echo '  we are the auth server'
84                 authisus=1
85         }
86         if not {
87                 echo '  we are not the auth server '^$auth
88                 echo '  if this is a mistake, set auth='$sysname' or auth='$dom
89                 if(~ $authok 1)
90                         echo '  run auth/debug to test the auth server'
91         }
92         if(~ $authisus 1){
93                 if(! grep -s keyfs <{ps})
94                         echo '  auth/keyfs is not running, try reboot'
95                 if not
96                         echo '  auth/keyfs is running'
97                 if(! grep -s 'Listen *567' <{netstat -n})
98                         echo '  no one listening on port 567, try reboot'
99                 if not {
100                         echo '  someone is listening on port 567'
101                         echo '  run auth/debug to test the auth server'
102                 }
103         }
104
105 }
106 fn checksec {
107         echo 'checking basic security:'
108         if(@{rfork n; mount -n /srv/boot /root >/dev/null >[2=1]})
109                 echo '  file server does not require auth for user '^`{cat '#c'/user}
110         if not
111                 echo '  file server seems to require auth'
112 }
113 checkhost
114 checknet
115 checkauth
116 checksec