source: trunk/test/testtimesrv.sh@ 198

Last change on this file since 198 was 172, checked in by katerina, 16 years ago

Documentation update, more dnmalloc fixes.

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