source: trunk/test/testtimesrv.sh@ 384

Last change on this file since 384 was 310, checked in by katerina, 14 years ago

Add option to skip checksum for certain files (ticket #232). Also fix for #231 (missing warning on invalid recursion depth).

File size: 8.9 KB
RevLine 
[1]1#! /bin/sh
2
[27]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
[19]22RCFILE="$PW_DIR/testrc_1.dyn"; export RCFILE
23LOGFILE="$PW_DIR/.samhain_log"; export LOGFILE
24PIDFILE="$PW_DIR/.samhain_lock"; export PIDFILE
[1]25
[19]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
[1]29
[19]30prep_testdata ()
31{
[30]32 if test -d "$BASE"; then
[172]33 chmod -f -R 0700 "${BASE}" || {
34 [ -z "$quiet" ] && log_msg_fail "chmod -f -R 0700 ${BASE}";
[30]35 return 1;
36 }
37 fi
[1]38
[19]39 rm -rf "${BASE}" || {
40 [ -z "$quiet" ] && log_msg_fail "rm -rf ${BASE}";
41 return 1;
42 }
[1]43
[19]44 mkdir "${BASE}" || {
45 [ -z "$quiet" ] && log_msg_fail "mkdir ${BASE}";
46 return 1;
47 }
[1]48
[19]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}
[1]61
[19]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
[1]74
[19]75End-of-data
76}
[1]77
[19]78mkconfig_log ()
[1]79{
[19]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; }
[1]141 #
142 # standalone compilation
143 #
[30]144 [ -z "$verbose" ] || { echo; echo "${S}Building standalone agent${E}"; echo; }
[1]145 #
146 if test -r "Makefile"; then
[19]147 $MAKE distclean >/dev/null
[1]148 fi
149 #
[19]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
[1]151 #
152 if test x$? = x0; then
[19]153 [ -z "$verbose" ] || log_msg_ok "configure...";
[30]154 $MAKE > /dev/null 2>>test_log
[19]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
[1]161 else
[19]162 [ -z "$quiet" ] && log_msg_fail "configure...";
163 return 1
[1]164 fi
165
[19]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
[1]171
[19]172 ./samhain -t init -p none
[1]173
174 if test x$? = x0; then
[19]175 [ -z "$verbose" ] || log_msg_ok "init...";
[1]176 else
[19]177 [ -z "$quiet" ] && log_msg_fail "init...";
178 return 1
[1]179 fi
180
[19]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
[51]188 one_sec_sleep
[19]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
[1]203}
204
[19]205MAXTEST=14; export MAXTEST
[1]206
[19]207die () {
208 test -z "$stoponerr" && return 0;
209 PID=`cat $PIDFILE`
210 kill -9 $PID
211}
[1]212
[19]213killdaemon () {
214 if [ -f $PIDFILE ]; then
215 PID=`cat $PIDFILE`
216 kill -9 $PID
217 fi
218}
[1]219
[19]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}
[1]229
[19]230daemontest_started () {
231 PID=`cat $PIDFILE`
[1]232
[19]233 kill -0 $PID
234 check_err ${1} $? "started"
235}
[1]236
[19]237daemontest_sigterm () {
238 PID=`cat $PIDFILE`
239
240 kill -15 $PID
241 count=0
242 while [ `kill -0 $PID` ]; do
[51]243 one_sec_sleep
[19]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
[51]263 one_sec_sleep
[19]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
[51]277 one_sec_sleep
[19]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
[51]296 one_sec_sleep
[19]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
[51]326 one_sec_sleep
[310]327 let "count = count + 1" >/dev/null
[19]328 if [ $count -gt 12 ]; then
329 [ -z "$verbose" ] || log_msg_fail "policy count (after)";
330 return 1
331 fi
332 tmp=`grep CRIT $LOGFILE | grep -v Runtime | wc -l`
333 done
334 fi
335
336 count=0
337 tmp2=0
338 while [ $tmp2 -ne $2 ]; do
[51]339 one_sec_sleep
[19]340 let "count = count + 1" >/dev/null
341 if [ $count -gt 12 ]; then
342 check_err ${1} 1 "sighup"
343 return 1
344 fi
345 tmp2=`grep 'Runtime configuration reloaded' $LOGFILE | wc -l`
346 done
347 check_err ${1} 0 "sighup"
348}
349
350daemontest_sigabrt () {
351 PID=`cat $PIDFILE`
[281]352 kill -${3} $PID
[19]353
354 count=0
355 while [ -f $LOGFILE.lock ]; do
[51]356 one_sec_sleep
[19]357 let "count = count + 1" >/dev/null
358 if [ $count -gt 12 ]; then
359 check_err ${1} 1 "sigabrt"
360 return 1
361 fi
362 done
363
364 kill -TTOU $PID
365
[51]366 five_sec_sleep
[19]367
368 if [ -f $LOGFILE.lock ]; then
369 tmp=`grep '<trail>' $LOGFILE | wc -l`
370 tst=$2; let "tst = tst + 2" >/dev/null;
371 if [ $tmp -eq $tst ]; then
372 check_err ${1} 0 "sigabrt"
373 return 0
374 fi
375 fi
376 check_err ${1} 1 "sigabrt"
377}
378
379testtime0 () {
380 log_start "DAEMON CONTROL"
381
382 testtime0_int;
383
384 tcount=1
385
386 trap 'killdaemon' 1 3 15
387
388 daemontest_started $tcount;
389
390 let "tcount = tcount + 1" >/dev/null
391 daemontest_sigttou $tcount;
392 let "tcount = tcount + 1" >/dev/null
393 daemontest_sigttou $tcount;
394 let "tcount = tcount + 1" >/dev/null
395 daemontest_sigttou $tcount;
396
397 let "tcount = tcount + 1" >/dev/null
398 daemontest_sigusr2 $tcount 1;
399 let "tcount = tcount + 1" >/dev/null
400 daemontest_sigusr2 $tcount 2;
401 let "tcount = tcount + 1" >/dev/null
402 daemontest_sigusr2 $tcount 3;
403
404 let "tcount = tcount + 1" >/dev/null
[281]405 daemontest_sigabrt $tcount 1 ABRT;
[19]406 let "tcount = tcount + 1" >/dev/null
[281]407 daemontest_sigabrt $tcount 2 TTIN;
[19]408 let "tcount = tcount + 1" >/dev/null
[281]409 daemontest_sigabrt $tcount 3 ABRT;
[19]410
411 let "tcount = tcount + 1" >/dev/null
412 daemontest_sighup $tcount 1;
413 let "tcount = tcount + 1" >/dev/null
414 daemontest_sighup $tcount 2;
415 let "tcount = tcount + 1" >/dev/null
416 daemontest_sighup $tcount 3;
417
418 let "tcount = tcount + 1" >/dev/null
419 daemontest_sigterm $tcount;
420
421 log_end "DAEMON CONTROL"
422}
423
424
Note: See TracBrowser for help on using the repository browser.