source: branches/samhain-2_2-branch/c_random.sh@ 260

Last change on this file since 260 was 1, checked in by katerina, 19 years ago

Initial import

File size: 6.2 KB
Line 
1#! /bin/sh
2
3# this program collects some entropy from the system
4# into the file "my_random_file" and outputs the 16-bit
5# Unix 'sum' checksum (seems to be the only portable way
6# to get true entropy with a shell script).
7
8# Apparently, on FreeBSD /dev/random does not block (???), must make sure
9# we really got something rather than nothing.
10
11rnd_tst=no
12
13/bin/rm -f ./my_random_file 2>/dev/null
14
15if test -r "/dev/urandom"; then
16 if test -c "/dev/urandom"; then
17 dd if=/dev/urandom ibs=1 count=4 > my_random_file 2>/dev/null
18 nsum=`sum ./my_random_file | awk '{print $1 }' | sed 's%^0*%%g' 2>/dev/null`
19 if test x$nsum != x; then
20 rnd_tst=yes
21 fi
22 fi
23fi
24
25if test x$rnd_tst = xno; then
26 if test -r "/dev/srandom"; then
27 if test -c "/dev/srandom"; then
28 dd if=/dev/srandom ibs=1 count=4 > my_random_file 2>/dev/null
29 nsum=`sum ./my_random_file | awk '{print $1 }' | sed 's%^0*%%g' 2>/dev/null`
30 if test x$nsum != x; then
31 rnd_tst=yes
32 fi
33 fi
34 fi
35fi
36
37if test x$rnd_tst = xno; then
38#
39 touch ./my_random_file
40#
41 if test -r "/usr/ucb/vmstat"; then
42 /usr/ucb/vmstat >> my_random_file 2>/dev/null
43 fi
44 if test -r "/bin/vmstat"; then
45 /bin/vmstat >> my_random_file 2>/dev/null
46 fi
47 if test -r "/sbin/vmstat"; then
48 /sbin/vmstat >> my_random_file 2>/dev/null
49 fi
50 if test -r "/usr/bin/vmstat"; then
51 /usr/bin/vmstat >> my_random_file 2>/dev/null
52 fi
53 if test -r "/usr/sbin/vmstat"; then
54 /usr/sbin/vmstat >> my_random_file 2>/dev/null
55 fi
56 if test -r "/usr/local/bin/vmstat"; then
57 /usr/local/bin/vmstat >> my_random_file 2>/dev/null
58 fi
59#
60 if test -r "/usr/ucb/netstat"; then
61 /usr/ucb/netstat -n >> my_random_file 2>/dev/null
62 fi
63 if test -r "/bin/netstat"; then
64 /bin/netstat -n >> my_random_file 2>/dev/null
65 fi
66 if test -r "/sbin/netstat"; then
67 /sbin/netstat -n >> my_random_file 2>/dev/null
68 fi
69 if test -r "/usr/bin/netstat"; then
70 /usr/bin/netstat -n >> my_random_file 2>/dev/null
71 fi
72 if test -r "/usr/sbin/netstat"; then
73 /usr/sbin/netstat -n >> my_random_file 2>/dev/null
74 fi
75 if test -r "/usr/local/bin/netstat"; then
76 /usr/local/bin/netstat -n >> my_random_file 2>/dev/null
77 fi
78#
79#
80 if test -r "/usr/ucb/ps"; then
81 /usr/ucb/ps -ef >> my_random_file 2>/dev/null
82 fi
83 if test -r "/bin/ps"; then
84 /bin/ps -ef >> my_random_file 2>/dev/null
85 fi
86 if test -r "/sbin/ps"; then
87 /sbin/ps -ef >> my_random_file 2>/dev/null
88 fi
89 if test -r "/usr/bin/ps"; then
90 /usr/bin/ps -ef >> my_random_file 2>/dev/null
91 fi
92 if test -r "/usr/sbin/ps"; then
93 /usr/sbin/ps -ef >> my_random_file 2>/dev/null
94 fi
95 if test -r "/usr/local/bin/ps"; then
96 /usr/local/bin/ps -ef >> my_random_file 2>/dev/null
97 fi
98#
99#
100 if test -r "/usr/ucb/arp"; then
101 /usr/ucb/arp -a >> my_random_file 2>/dev/null
102 fi
103 if test -r "/bin/arp"; then
104 /bin/arp -a >> my_random_file 2>/dev/null
105 fi
106 if test -r "/sbin/arp"; then
107 /sbin/arp -a >> my_random_file 2>/dev/null
108 fi
109 if test -r "/usr/bin/arp"; then
110 /usr/bin/arp -a >> my_random_file 2>/dev/null
111 fi
112 if test -r "/usr/sbin/arp"; then
113 /usr/sbin/arp -a >> my_random_file 2>/dev/null
114 fi
115 if test -r "/usr/local/bin/arp"; then
116 /usr/local/bin/arp -a >> my_random_file 2>/dev/null
117 fi
118#
119#
120 if test -r "/usr/ucb/w"; then
121 /usr/ucb/w >> my_random_file 2>/dev/null
122 fi
123 if test -r "/bin/w"; then
124 /bin/w >> my_random_file 2>/dev/null
125 fi
126 if test -r "/sbin/w"; then
127 /sbin/w >> my_random_file 2>/dev/null
128 fi
129 if test -r "/usr/bin/w"; then
130 /usr/bin/w >> my_random_file 2>/dev/null
131 fi
132 if test -r "/usr/sbin/w"; then
133 /usr/sbin/w >> my_random_file 2>/dev/null
134 fi
135 if test -r "/usr/local/bin/w"; then
136 /usr/local/bin/w >> my_random_file 2>/dev/null
137 fi
138#
139# Don't use (NFS problems ahead)
140#
141# if test -r "/usr/ucb/df"; then
142# /usr/ucb/df >> my_random_file 2>/dev/null
143# fi
144# if test -r "/bin/df"; then
145# /bin/df >> my_random_file 2>/dev/null
146# fi
147# if test -r "/sbin/df"; then
148# /sbin/df >> my_random_file 2>/dev/null
149# fi
150# if test -r "/usr/bin/df"; then
151# /usr/bin/df >> my_random_file 2>/dev/null
152# fi
153# if test -r "/usr/sbin/df"; then
154# /usr/sbin/df >> my_random_file 2>/dev/null
155# fi
156# if test -r "/usr/local/bin/df"; then
157# /usr/local/bin/df >> my_random_file 2>/dev/null
158# fi
159#
160#
161 if test -r "/usr/ucb/free"; then
162 /usr/ucb/free >> my_random_file 2>/dev/null
163 fi
164 if test -r "/bin/free"; then
165 /bin/free >> my_random_file 2>/dev/null
166 fi
167 if test -r "/sbin/free"; then
168 /sbin/free >> my_random_file 2>/dev/null
169 fi
170 if test -r "/usr/bin/free"; then
171 /usr/bin/free >> my_random_file 2>/dev/null
172 fi
173 if test -r "/usr/sbin/free"; then
174 /usr/sbin/free >> my_random_file 2>/dev/null
175 fi
176 if test -r "/usr/local/bin/free"; then
177 /usr/local/bin/free >> my_random_file 2>/dev/null
178 fi
179#
180#
181 if test -r "/usr/ucb/uptime"; then
182 /usr/ucb/uptime >> my_random_file 2>/dev/null
183 fi
184 if test -r "/bin/uptime"; then
185 /bin/uptime >> my_random_file 2>/dev/null
186 fi
187 if test -r "/sbin/uptime"; then
188 /sbin/uptime >> my_random_file 2>/dev/null
189 fi
190 if test -r "/usr/bin/uptime"; then
191 /usr/bin/uptime >> my_random_file 2>/dev/null
192 fi
193 if test -r "/usr/sbin/uptime"; then
194 /usr/sbin/uptime >> my_random_file 2>/dev/null
195 fi
196 if test -r "/usr/local/bin/uptime"; then
197 /usr/local/bin/uptime >> my_random_file 2>/dev/null
198 fi
199#
200#
201 if test -r "/usr/ucb/procinfo"; then
202 /usr/ucb/procinfo -a >> my_random_file 2>/dev/null
203 fi
204 if test -r "/bin/procinfo"; then
205 /bin/procinfo -a >> my_random_file 2>/dev/null
206 fi
207 if test -r "/sbin/procinfo"; then
208 /sbin/procinfo -a >> my_random_file 2>/dev/null
209 fi
210 if test -r "/usr/bin/procinfo"; then
211 /usr/bin/procinfo -a >> my_random_file 2>/dev/null
212 fi
213 if test -r "/usr/sbin/procinfo"; then
214 /usr/sbin/procinfo -a >> my_random_file 2>/dev/null
215 fi
216 if test -r "/usr/local/bin/procinfo"; then
217 /usr/local/bin/procinfo -a >> my_random_file 2>/dev/null
218 fi
219#
220 nsum=`sum ./my_random_file | awk '{print $1 }' | sed 's%^0*%%g' 2>/dev/null`
221#
222fi
223
224#
225# 'sum' is portable, but only 16 bit
226#
227
228/bin/rm -f ./my_random_file 2>/dev/null
229
230echo $nsum
231
232
Note: See TracBrowser for help on using the repository browser.