source: trunk/test/testtimesrv.sh@ 26

Last change on this file since 26 was 19, checked in by rainer, 19 years ago

Rewrite of test suite, checksum for growing logs, fix for minor bug with dead client detection.

File size: 8.0 KB
Line 
1#! /bin/sh
2
3RCFILE="$PW_DIR/testrc_1.dyn"; export RCFILE
4LOGFILE="$PW_DIR/.samhain_log"; export LOGFILE
5PIDFILE="$PW_DIR/.samhain_lock"; export PIDFILE
6
7BASE="${PW_DIR}/testrun_testdata"; export BASE
8TDIRS="a b c a/a a/b a/c a/a/a a/a/b a/a/c a/a/a/a a/a/a/b a/a/a/c"; export TDIRS
9TFILES="x y z"; export TFILES
10
11prep_testdata ()
12{
13 chmod -R 0700 "${BASE}" || {
14 [ -z "$quiet" ] && log_msg_fail "chmod -R 0700 ${BASE}";
15 return 1;
16 }
17
18 rm -rf "${BASE}" || {
19 [ -z "$quiet" ] && log_msg_fail "rm -rf ${BASE}";
20 return 1;
21 }
22
23 mkdir "${BASE}" || {
24 [ -z "$quiet" ] && log_msg_fail "mkdir ${BASE}";
25 return 1;
26 }
27
28 for ff in $TDIRS; do
29 mkdir "${BASE}/${ff}" || {
30 [ -z "$quiet" ] && log_msg_fail "mkdir ${BASE}/${ff}";
31 return 1;
32 }
33 chmod 0755 "${BASE}/${ff}"
34 for gg in $TFILES; do
35 echo "This is a test file" > "${BASE}/${ff}/${gg}"
36 chmod 0644 "${BASE}/${ff}/${gg}"
37 done
38 done
39}
40
41mkconfig_misc ()
42{
43 test -f "${RCFILE}" || touch "${RCFILE}"
44 cat >> "${RCFILE}" <<End-of-data
45[Misc]
46Daemon=no
47SetFilecheckTime=60
48TrustedUser=uucp,fax,fnet
49SetRecursionLevel=10
50SetLoopTime=30
51ReportFullDetail = no
52ChecksumTest=check
53
54End-of-data
55}
56
57mkconfig_log ()
58{
59 test -f "${RCFILE}" || touch "${RCFILE}"
60 cat >> "${RCFILE}" <<End-of-data
61[Log]
62MailSeverity=none
63LogSeverity=warn
64SyslogSeverity=none
65PrintSeverity=info
66MailSeverity=none
67#Restrict to certain classes of messages
68#LogClass=RUN
69#PreludeSeverity=err
70#ExportSeverity=none
71
72End-of-data
73}
74
75mkconfig_sev ()
76{
77 test -f "${RCFILE}" || touch "${RCFILE}"
78 cat >> "${RCFILE}" <<End-of-data
79[EventSeverity]
80SeverityUser0=crit
81SeverityUser1=crit
82SeverityReadOnly=crit
83SeverityLogFiles=crit
84SeverityGrowingLogs=crit
85SeverityIgnoreNone=crit
86SeverityAttributes=crit
87SeverityIgnoreAll=crit
88SeverityFiles=err
89SeverityDirs=err
90SeverityNames=warn
91
92End-of-data
93}
94
95prep_init ()
96{
97 rm -f ./.samhain_file
98 rm -f "${LOGFILE}"
99 rm -f ./.samhain_lock
100
101 rm -f "${RCFILE}"
102 mkconfig_sev
103 mkconfig_log
104 mkconfig_misc
105}
106
107TESTPOLICY="
108[ReadOnly]
109dir=${BASE}/c
110[Attributes]
111dir=${BASE}/a
112#dir=${BASE}/b
113"
114
115
116testtime0_int ()
117{
118 [ -z "$verbose" ] || echo Working directory: $PW_DIR
119 [ -z "$verbose" ] || { echo MAKE is $MAKE; echo; }
120 #
121 # standalone compilation
122 #
123 [ -z "$verbose" ] || { echo; echo "${S}Building standalone agent w/timeserver${E}"; echo; }
124 #
125 if test -r "Makefile"; then
126 $MAKE distclean >/dev/null
127 fi
128 #
129 ${TOP_SRCDIR}/configure --quiet --enable-debug --enable-xml-log --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$LOGFILE --with-pid-file=$PIDFILE --with-data-file=$PW_DIR/.samhain_file
130 #
131 if test x$? = x0; then
132 [ -z "$verbose" ] || log_msg_ok "configure...";
133 $MAKE > /dev/null
134 if test x$? = x0; then
135 [ -z "$verbose" ] || log_msg_ok "make...";
136 else
137 [ -z "$quiet" ] && log_msg_fail "make...";
138 return 1
139 fi
140 else
141 [ -z "$quiet" ] && log_msg_fail "configure...";
142 return 1
143 fi
144
145 prep_init && prep_testdata && echo "$TESTPOLICY" >>$RCFILE
146 if [ $? -ne 0 ]; then
147 [ -z "$quiet" ] && log_msg_fail "prepare...";
148 return 1
149 fi
150
151 ./samhain -t init -p none
152
153 if test x$? = x0; then
154 [ -z "$verbose" ] || log_msg_ok "init...";
155 else
156 [ -z "$quiet" ] && log_msg_fail "init...";
157 return 1
158 fi
159
160 chmod 0555 "${BASE}/a/x"
161 chmod 0555 "${BASE}/b/x"
162
163 ./samhain -t check -p none -l info -D
164
165 count=0
166 until [ -f $PIDFILE ]; do
167 sleep 1
168 let "count = count + 1" >/dev/null
169 if [ $count -gt 12 ]; then
170 break;
171 fi
172 done
173
174 if test x$? = x0; then
175 [ -z "$verbose" ] || log_msg_ok "start daemon...";
176 else
177 [ -z "$quiet" ] && log_msg_fail "start daemon...";
178 return 1
179 fi
180
181 return 0
182}
183
184MAXTEST=14; export MAXTEST
185
186die () {
187 test -z "$stoponerr" && return 0;
188 PID=`cat $PIDFILE`
189 kill -9 $PID
190}
191
192killdaemon () {
193 if [ -f $PIDFILE ]; then
194 PID=`cat $PIDFILE`
195 kill -9 $PID
196 fi
197}
198
199check_err () {
200 if [ ${2} -ne 0 ]; then
201 die;
202 [ -z "$quiet" ] && log_fail ${1} ${MAXTEST} "${3}";
203 return 1
204 else
205 [ -z "$quiet" ] && log_ok ${1} ${MAXTEST} "${3}";
206 fi
207}
208
209daemontest_started () {
210 PID=`cat $PIDFILE`
211
212 kill -0 $PID
213 check_err ${1} $? "started"
214}
215
216daemontest_sigterm () {
217 PID=`cat $PIDFILE`
218
219 kill -15 $PID
220 count=0
221 while [ `kill -0 $PID` ]; do
222 sleep 1
223 let "count = count + 1" >/dev/null
224 if [ $count -gt 12 ]; then
225 check_err ${1} 1 "sigterm"
226 return 1
227 fi
228 done
229 check_err ${1} 0 "sigterm"
230}
231
232daemontest_sigusr2 () {
233 PID=`cat $PIDFILE`
234
235 tmp=`grep 'File check completed' $LOGFILE | wc -l`
236 kill -USR2 $PID
237 kill -TTOU $PID
238
239 count=0
240 tmp2=`grep 'SUSPEND' $LOGFILE | wc -l`
241 while [ $tmp2 -ne $2 ]; do
242 sleep 1
243 let "count = count + 1" >/dev/null
244 if [ $count -gt 12 ]; then
245 check_err ${1} 1 "sigusr2: suspend"
246 return 1
247 fi
248 tmp2=`grep 'SUSPEND' $LOGFILE | wc -l`
249 done
250
251 kill -USR2 $PID
252
253 count=0
254 tmp2=$tmp
255 while [ $tmp2 -eq $tmp ]; do
256 sleep 1
257 let "count = count + 1" >/dev/null
258 if [ $count -gt 12 ]; then
259 check_err ${1} 1 "sigusr2: wakeup"
260 return 1
261 fi
262 tmp2=`grep 'File check completed' $LOGFILE | wc -l`
263 done
264 check_err ${1} 0 "sigusr2"
265}
266
267daemontest_sigttou () {
268 PID=`cat $PIDFILE`
269
270 tmp=`grep 'File check completed' $LOGFILE | wc -l`
271 kill -TTOU $PID
272 count=0
273 tmp2=$tmp
274 while [ $tmp2 -eq $tmp ]; do
275 sleep 1
276 let "count = count + 1" >/dev/null
277 if [ $count -gt 12 ]; then
278 check_err ${1} 1 "sigttou"
279 return 1
280 fi
281 tmp2=`grep 'File check completed' $LOGFILE | wc -l`
282 done
283 check_err ${1} 0 "sigttou"
284}
285
286daemontest_sighup () {
287
288 if [ $2 -eq 1 ]; then
289 echo "dir=${BASE}/b" >>$RCFILE
290 tmp=`grep CRIT $LOGFILE | grep -v Runtime | wc -l`
291 if [ $tmp -ne 1 ]; then
292 [ -z "$verbose" ] || log_msg_fail "policy count (before)";
293 return 1
294 fi
295 fi
296
297 PID=`cat $PIDFILE`
298 kill -HUP $PID
299
300 if [ $2 -eq 1 ]; then
301 kill -TTOU $PID
302 count=0
303 tmp=`grep CRIT $LOGFILE | grep -v Runtime | wc -l`
304 while [ $tmp -lt 2 ]; do
305 sleep 1
306 if [ $count -gt 12 ]; then
307 [ -z "$verbose" ] || log_msg_fail "policy count (after)";
308 return 1
309 fi
310 tmp=`grep CRIT $LOGFILE | grep -v Runtime | wc -l`
311 done
312 fi
313
314 count=0
315 tmp2=0
316 while [ $tmp2 -ne $2 ]; do
317 sleep 1
318 let "count = count + 1" >/dev/null
319 if [ $count -gt 12 ]; then
320 check_err ${1} 1 "sighup"
321 return 1
322 fi
323 tmp2=`grep 'Runtime configuration reloaded' $LOGFILE | wc -l`
324 done
325 check_err ${1} 0 "sighup"
326}
327
328daemontest_sigabrt () {
329 PID=`cat $PIDFILE`
330 kill -ABRT $PID
331
332 count=0
333 while [ -f $LOGFILE.lock ]; do
334 sleep 1
335 let "count = count + 1" >/dev/null
336 if [ $count -gt 12 ]; then
337 check_err ${1} 1 "sigabrt"
338 return 1
339 fi
340 done
341
342 kill -TTOU $PID
343
344 sleep 4
345
346 if [ -f $LOGFILE.lock ]; then
347 tmp=`grep '<trail>' $LOGFILE | wc -l`
348 tst=$2; let "tst = tst + 2" >/dev/null;
349 if [ $tmp -eq $tst ]; then
350 check_err ${1} 0 "sigabrt"
351 return 0
352 fi
353 fi
354 check_err ${1} 1 "sigabrt"
355}
356
357testtime0 () {
358 log_start "DAEMON CONTROL"
359
360 testtime0_int;
361
362 tcount=1
363
364 trap 'killdaemon' 1 3 15
365
366 daemontest_started $tcount;
367
368 let "tcount = tcount + 1" >/dev/null
369 daemontest_sigttou $tcount;
370 let "tcount = tcount + 1" >/dev/null
371 daemontest_sigttou $tcount;
372 let "tcount = tcount + 1" >/dev/null
373 daemontest_sigttou $tcount;
374
375 let "tcount = tcount + 1" >/dev/null
376 daemontest_sigusr2 $tcount 1;
377 let "tcount = tcount + 1" >/dev/null
378 daemontest_sigusr2 $tcount 2;
379 let "tcount = tcount + 1" >/dev/null
380 daemontest_sigusr2 $tcount 3;
381
382 let "tcount = tcount + 1" >/dev/null
383 daemontest_sigabrt $tcount 1;
384 let "tcount = tcount + 1" >/dev/null
385 daemontest_sigabrt $tcount 2;
386 let "tcount = tcount + 1" >/dev/null
387 daemontest_sigabrt $tcount 3;
388
389 let "tcount = tcount + 1" >/dev/null
390 daemontest_sighup $tcount 1;
391 let "tcount = tcount + 1" >/dev/null
392 daemontest_sighup $tcount 2;
393 let "tcount = tcount + 1" >/dev/null
394 daemontest_sighup $tcount 3;
395
396 let "tcount = tcount + 1" >/dev/null
397 daemontest_sigterm $tcount;
398
399 log_end "DAEMON CONTROL"
400}
401
402
Note: See TracBrowser for help on using the repository browser.