source: trunk/test/testtimesrv.sh@ 27

Last change on this file since 27 was 27, checked in by rainer, 18 years ago

Support for server-to-server relay and more user policies

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