source: branches/samhain-2_2-branch/test/testrun_1.sh@ 286

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

Fix problems with linux kernel 2.6.17

File size: 26.4 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
24
25# --enable-login-watch --enable-xml-log
26# --enable-debug --enable-suidcheck --with-prelude
27
28BUILDOPTS="--quiet $TRUST --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$LOGFILE --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file --enable-debug"
29export BUILDOPTS
30
31BASE="${PW_DIR}/testrun_testdata"; export BASE
32TDIRS="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
33TFILES="x y z"; export TFILES
34
35###########################################################
36#
37# ---- [Define tests here] ----
38#
39
40# 1 for testing new tests
41testrun1_setup=0
42
43MAXTEST=11; export MAXTEST
44
45test_dirs () {
46 for ff in $CDIRS; do
47 #
48 egrep "Checking.*${BASE}/${ff}(>|\")" $LOGFILE >/dev/null 2>&1
49 if [ $? -ne 0 ]; then
50 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff} (checking)";
51 return 1
52 fi
53 tmp=`egrep "Checking.*${BASE}/${ff}(>|\")" $LOGFILE 2>/dev/null | wc -l`
54 if [ $tmp -ne 1 ]; then
55 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff} (multiple)";
56 fi
57 #
58 done
59 for ff in $NDIRS; do
60 #
61 egrep "Checking.*${BASE}/${ff}(>|\")" $LOGFILE >/dev/null 2>&1
62 if [ $? -eq 0 ]; then
63 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff} (checking)";
64 return 1
65 fi
66 done
67}
68
69#
70# combine file check schedule with one-shot mode
71#
72TESTPOLICY_11="
73[ReadOnly]
74dir=99${BASE}
75"
76
77mod_testdata_11 () {
78 one_sec_sleep
79 echo "foobar" >"${BASE}/c/x"; # bad
80 chmod 0555 "${BASE}/a/y"; # bad
81 ORIGINAL='SetFilecheckTime=60'
82 REPLACEMENT='FileCheckScheduleOne = 6 12 * * *'
83 ex -s $RCFILE <<EOF
84%s/${ORIGINAL}/${REPLACEMENT}/g
85wq
86EOF
87}
88
89chk_testdata_11 () {
90 # CDIRS="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";
91 tmp=`grep CRIT $LOGFILE | wc -l`
92 if [ $tmp -ne 2 ]; then
93 [ -z "$verbose" ] || log_msg_fail "policy count";
94 return 1
95 fi
96 egrep "CRIT.*POLICY \[ReadOnly\] C-------TS.*${BASE}/c/x" $LOGFILE >/dev/null 2>&1
97 if [ $? -ne 0 ]; then
98 [ -z "$verbose" ] || log_msg_fail "${BASE}/c/x";
99 return 1
100 fi
101 egrep "CRIT.*POLICY \[ReadOnly\] -----M--T-.*${BASE}/a/y" $LOGFILE >/dev/null 2>&1
102 if [ $? -ne 0 ]; then
103 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/y";
104 return 1
105 fi
106 CDIRS="a a/a a/b a/c c b a/a/a a/a/b a/a/c a/a/a/a a/a/a/b a/a/a/c";
107 NDIRS="";
108 test_dirs;
109 return $?
110}
111
112TESTPOLICY_10="
113[ReadOnly]
114dir=99${BASE}
115[IgnoreAll]
116dir=-1${BASE}/b
117[Attributes]
118dir=1${BASE}/a
119"
120
121mod_testdata_10 () {
122 one_sec_sleep
123 echo "foobar" >"${BASE}/b/x"; # ok
124 echo "foobar" >"${BASE}/c/x"; # bad
125 echo "foobar" >"${BASE}/a/x"; # ok
126 chmod 0555 "${BASE}/a/a/x"; # bad
127 chmod 0555 "${BASE}/a/a/a/x";# ok
128 chmod 0555 "${BASE}/a/y"; # bad
129}
130
131chk_testdata_10 () {
132 # CDIRS="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";
133 tmp=`grep CRIT $LOGFILE | wc -l`
134 if [ $tmp -ne 3 ]; then
135 [ -z "$verbose" ] || log_msg_fail "policy count";
136 return 1
137 fi
138 egrep "CRIT.*POLICY \[ReadOnly\] C-------TS.*${BASE}/c/x" $LOGFILE >/dev/null 2>&1
139 if [ $? -ne 0 ]; then
140 [ -z "$verbose" ] || log_msg_fail "${BASE}/c/x";
141 return 1
142 fi
143 egrep "CRIT.*POLICY \[Attributes\] -----M----.*${BASE}/a/a/x" $LOGFILE >/dev/null 2>&1
144 if [ $? -ne 0 ]; then
145 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/x";
146 return 1
147 fi
148 egrep "CRIT.*POLICY \[Attributes\] -----M----.*${BASE}/a/y" $LOGFILE >/dev/null 2>&1
149 if [ $? -ne 0 ]; then
150 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/y";
151 return 1
152 fi
153 CDIRS="a a/a a/b a/c c";
154 NDIRS="b a/a/a a/a/b a/a/c a/a/a/a a/a/a/b a/a/a/c";
155 test_dirs;
156 return $?
157}
158
159TESTPOLICY_9="
160[ReadOnly]
161dir=0${BASE}/b
162[Attributes]
163dir=2${BASE}/a/a
164"
165
166mod_testdata_9 () {
167 echo "foobar" >"${BASE}/b/x";
168 echo "foobar" >"${BASE}/a/x";
169 echo "foobar" >"${BASE}/x";
170}
171
172chk_testdata_9 () {
173 # CDIRS="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";
174 tmp=`grep CRIT $LOGFILE | wc -l`
175 if [ $tmp -ne 1 ]; then
176 [ -z "$verbose" ] || log_msg_fail "policy count";
177 return 1
178 fi
179 CDIRS="b a/a a/a/a a/a/b a/a/c a/a/a/a a/a/a/b a/a/a/c";
180 NDIRS="a c a/b a/c";
181 test_dirs;
182 return $?
183}
184
185TESTPOLICY_8="
186[ReadOnly]
187dir=1${BASE}
188[Attributes]
189dir=1${BASE}/a/a
190"
191
192mod_testdata_8 () {
193 echo "foobar" >"${BASE}/a/x";
194 chmod 0555 "${BASE}/a/a/a/b/x";
195}
196
197chk_testdata_8 () {
198 # CDIRS="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";
199 tmp=`grep CRIT $LOGFILE | wc -l`
200 if [ $tmp -ne 1 ]; then
201 [ -z "$verbose" ] || log_msg_fail "policy count";
202 return 1
203 fi
204 CDIRS="a b c a/a a/a/a a/a/b a/a/c";
205 NDIRS="a/b a/c a/a/a/a a/a/a/b a/a/a/c";
206 test_dirs;
207 return $?
208}
209
210
211TESTPOLICY_7="
212[ReadOnly]
213dir=${BASE}
214[Attributes]
215dir=${BASE}/a/a
216[GrowingLogFiles]
217dir=${BASE}/a/a/a
218[IgnoreAll]
219file=${BASE}/a/a/a/z
220dir=${BASE}/b
221"
222
223mod_testdata_7 () {
224 one_sec_sleep
225 echo "foobar" >"${BASE}/a/a/a/z" # ok
226 echo "foobar" >"${BASE}/a/a/a/x" # bad
227 echo "foobar" >"${BASE}/a/a/x" # ok
228 echo "foobar" >"${BASE}/a/x" # bad
229 chmod 0555 "${BASE}/a" # bad
230 chmod 0555 "${BASE}/b" # ok
231}
232
233
234chk_testdata_7 () {
235 tmp=`grep CRIT $LOGFILE | wc -l`
236 if [ $tmp -ne 3 ]; then
237 [ -z "$verbose" ] || log_msg_fail "policy count";
238 return 1
239 fi
240 egrep "CRIT.*POLICY \[GrowingLogs\] C--------S.*${BASE}/a/a/a/x" $LOGFILE >/dev/null 2>&1
241 if [ $? -ne 0 ]; then
242 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/a/x";
243 return 1
244 fi
245 egrep "CRIT.*POLICY \[ReadOnly\] -----M--T-.*${BASE}/a" $LOGFILE >/dev/null 2>&1
246 if [ $? -ne 0 ]; then
247 [ -z "$verbose" ] || log_msg_fail "${BASE}/a";
248 return 1
249 fi
250 egrep "CRIT.*POLICY \[ReadOnly\] C-------TS.*${BASE}/a/x" $LOGFILE >/dev/null 2>&1
251 if [ $? -ne 0 ]; then
252 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/x";
253 return 1
254 fi
255}
256
257
258TESTPOLICY_6="
259[ReadOnly]
260dir=${BASE}
261[Attributes]
262file=${BASE}/a/y
263file=${BASE}/b/y
264file=${BASE}/c/y
265file=${BASE}/a/a/y
266file=${BASE}/a/b/y
267file=${BASE}/a/c/y
268file=${BASE}/a/a/a/y
269file=${BASE}/a/a/b/y
270file=${BASE}/a/a/c/y
271file=${BASE}/a/a/a/a/y
272file=${BASE}/a/a/a/b/y
273file=${BASE}/a/a/a/c/y
274"
275
276mod_testdata_6 () {
277 one_sec_sleep
278 for ff in $TDIRS; do
279 echo "foobar" >"${BASE}/${ff}/x"
280 chmod 0555 "${BASE}/${ff}/y"
281 echo "foobar" >"${BASE}/${ff}/z"
282 done
283}
284
285chk_testdata_6 () {
286 count6=0
287 for ff in $TDIRS; do
288 #
289 egrep "Checking.*${BASE}/${ff}(>|\")" $LOGFILE >/dev/null 2>&1
290 if [ $? -ne 0 ]; then
291 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff} (checking)";
292 return 1
293 fi
294 tmp=`egrep "Checking.*${BASE}/${ff}(>|\")" $LOGFILE 2>/dev/null | wc -l`
295 if [ $tmp -ne 1 ]; then
296 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff} (multiple)";
297 fi
298 #
299 for gg in $TFILES; do
300 egrep "Checksum.*${BASE}/${ff}/${gg}" $LOGFILE >/dev/null 2>&1
301 if [ $? -ne 0 ]; then
302 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff}/${gg} (checking)";
303 fi
304 tmp=`egrep "Checksum.*${BASE}/${ff}/${gg}" $LOGFILE 2>/dev/null | wc -l`
305 if [ $tmp -ne 1 ]; then
306 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff}/${gg} (multiple)";
307 fi
308 done
309 egrep "CRIT.*POLICY \[ReadOnly\] C-------TS.*${BASE}/${ff}/x" $LOGFILE >/dev/null 2>&1
310 if [ $? -ne 0 ]; then
311 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff}/x";
312 return 1
313 fi
314 let "count6 = count6 + 1" >/dev/null
315 egrep "CRIT.*POLICY \[ReadOnly\] C-------TS.*${BASE}/${ff}/z" $LOGFILE >/dev/null 2>&1
316 if [ $? -ne 0 ]; then
317 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff}/z";
318 return 1
319 fi
320 let "count6 = count6 + 1" >/dev/null
321 egrep "CRIT.*POLICY \[Attributes\] -----M----.*${BASE}/${ff}/y" $LOGFILE >/dev/null 2>&1
322 if [ $? -ne 0 ]; then
323 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff}/y";
324 return 1
325 fi
326 let "count6 = count6 + 1" >/dev/null
327 done
328 tmp=`grep CRIT $LOGFILE | wc -l`
329 if [ $tmp -ne $count6 ]; then
330 [ -z "$verbose" ] || log_msg_fail "policy count";
331 return 1
332 fi
333}
334
335TESTPOLICY_5="
336[Attributes]
337dir=${BASE}
338file=${BASE}/a/a/c/x
339[ReadOnly]
340file=${BASE}/a/a/c/y
341[GrowingLogFiles]
342dir=${BASE}/a/a/c
343dir=${BASE}/a/a/b
344dir=${BASE}/a/b
345"
346
347mod_testdata_5 () {
348 mod_testdata_4
349 echo "This is a xxxx file" > "${BASE}/a/a/b/x" # GrowingLogFiles
350 echo "This is a test file" > "${BASE}/a/a/b/y" # GrowingLogFiles
351 echo "This is a xxxx file bad" > "${BASE}/a/a/b/z" # GrowingLogFiles
352}
353
354chk_testdata_5 () {
355 for ff in $TDIRS; do
356 #
357 egrep "Checking.*${BASE}/${ff}(>|\")" $LOGFILE >/dev/null 2>&1
358 if [ $? -ne 0 ]; then
359 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff} (checking)";
360 return 1
361 fi
362 tmp=`egrep "Checking.*${BASE}/${ff}(>|\")" $LOGFILE 2>/dev/null | wc -l`
363 if [ $tmp -ne 1 ]; then
364 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff} (multiple)";
365 fi
366 #
367 for gg in $TFILES; do
368 egrep "Checksum.*${BASE}/${ff}/${gg}" $LOGFILE >/dev/null 2>&1
369 if [ $? -ne 0 ]; then
370 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff}/${gg} (checking)";
371 fi
372 tmp=`egrep "Checksum.*${BASE}/${ff}/${gg}" $LOGFILE 2>/dev/null | wc -l`
373 if [ $tmp -ne 1 ]; then
374 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff}/${gg} (multiple)";
375 fi
376 done
377 done
378 egrep "CRIT.*POLICY \[GrowingLogs\] C---------.*${BASE}/a/a/b/x" $LOGFILE >/dev/null 2>&1
379 if [ $? -ne 0 ]; then
380 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/b/x";
381 return 1
382 fi
383 egrep "CRIT.*POLICY \[GrowingLogs\] C---------.*${BASE}/a/a/b/z" $LOGFILE >/dev/null 2>&1
384 if [ $? -ne 0 ]; then
385 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/b/z";
386 return 1
387 fi
388 egrep "CRIT.*POLICY \[GrowingLogs\] -----M----.*${BASE}/a/b/z" $LOGFILE >/dev/null 2>&1
389 if [ $? -ne 0 ]; then
390 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/b/z";
391 return 1
392 fi
393 egrep "CRIT.*POLICY \[GrowingLogs\] -----M----.*${BASE}/a/a/c/z" $LOGFILE >/dev/null 2>&1
394 if [ $? -ne 0 ]; then
395 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/c/z";
396 return 1
397 fi
398 egrep "CRIT.*POLICY \[GrowingLogs\] C--------S.*${BASE}/a/b/y" $LOGFILE >/dev/null 2>&1
399 if [ $? -ne 0 ]; then
400 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/b/y";
401 return 1
402 fi
403 egrep "CRIT.*POLICY \[Attributes\] -----M----.*${BASE}/a/a/c/x" $LOGFILE >/dev/null 2>&1
404 if [ $? -ne 0 ]; then
405 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/c/x";
406 return 1
407 fi
408 egrep "CRIT.*POLICY ADDED.*${BASE}/a/a/c/foo" $LOGFILE >/dev/null 2>&1
409 if [ $? -ne 0 ]; then
410 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/c/foo";
411 return 1
412 fi
413 egrep "CRIT.*POLICY ADDED.*033\[1;30m" $LOGFILE >/dev/null 2>&1
414 if [ $? -ne 0 ]; then
415 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/\033[1;30m";
416 return 1
417 fi
418 egrep "WARN.*Weird filename.*033\[1;30m" $LOGFILE >/dev/null 2>&1
419 if [ $? -ne 0 ]; then
420 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/\033[1;30m";
421 return 1
422 fi
423 egrep "CRIT.*POLICY \[ReadOnly\] C-------TS.*${BASE}/a/a/c/y" $LOGFILE >/dev/null 2>&1
424 if [ $? -ne 0 ]; then
425 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/c/y";
426 return 1
427 fi
428 tmp=`grep CRIT $LOGFILE | wc -l`
429 if [ $tmp -ne 9 ]; then
430 [ -z "$verbose" ] || log_msg_fail "policy count";
431 return 1
432 fi
433}
434
435
436TESTPOLICY_4="
437[Attributes]
438dir=${BASE}
439file=${BASE}/a/a/c/x
440[ReadOnly]
441file=${BASE}/a/a/c/y
442[LogFiles]
443dir=${BASE}/a/a/c
444dir=${BASE}/a/b
445"
446
447mod_testdata_4 () {
448 one_sec_sleep
449 echo "foobar" >> "${BASE}/a/a/x" # Attributes
450 echo "foobar" > "${BASE}/a/a/c/foo" # new within LogFiles
451 echo "foobar" >> "${BASE}/a/a/c/y" # ReadOnly
452 echo "foobar" >> "${BASE}/a/a/c/x" # Attributes
453 chmod 0555 "${BASE}/a/a/c/x" # Attributes
454 chmod 0555 "${BASE}/a/a/c/z" # LogFiles
455 echo "foobar" >> "${BASE}/a/b/x" # LogFiles
456 echo "" > "${BASE}/a/b/y" # LogFiles
457 chmod 0555 "${BASE}/a/b/z" # LogFiles
458 touch "${BASE}/a/a/[1;30m" # non-printable character in filename
459}
460
461chk_testdata_4 () {
462 for ff in $TDIRS; do
463 #
464 egrep "Checking.*${BASE}/${ff}(>|\")" $LOGFILE >/dev/null 2>&1
465 if [ $? -ne 0 ]; then
466 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff} (checking)";
467 return 1
468 fi
469 tmp=`egrep "Checking.*${BASE}/${ff}(>|\")" $LOGFILE 2>/dev/null | wc -l`
470 if [ $tmp -ne 1 ]; then
471 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff} (multiple)";
472 fi
473 #
474 for gg in $TFILES; do
475 egrep "Checksum.*${BASE}/${ff}/${gg}" $LOGFILE >/dev/null 2>&1
476 if [ $? -ne 0 ]; then
477 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff}/${gg} (checking)";
478 fi
479 tmp=`egrep "Checksum.*${BASE}/${ff}/${gg}" $LOGFILE 2>/dev/null | wc -l`
480 if [ $tmp -ne 1 ]; then
481 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff}/${gg} (multiple)";
482 fi
483 done
484 done
485 egrep "CRIT.*POLICY \[Attributes\] -----M----.*${BASE}/a/a/c/x" $LOGFILE >/dev/null 2>&1
486 if [ $? -ne 0 ]; then
487 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/c/x";
488 return 1
489 fi
490 egrep "CRIT.*POLICY \[LogFiles\] -----M----.*${BASE}/a/b/z" $LOGFILE >/dev/null 2>&1
491 if [ $? -ne 0 ]; then
492 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/b/z";
493 return 1
494 fi
495 egrep "CRIT.*POLICY \[LogFiles\] -----M----.*${BASE}/a/a/c/z" $LOGFILE >/dev/null 2>&1
496 if [ $? -ne 0 ]; then
497 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/c/z";
498 return 1
499 fi
500 egrep "CRIT.*POLICY ADDED.*${BASE}/a/a/c/foo" $LOGFILE >/dev/null 2>&1
501 if [ $? -ne 0 ]; then
502 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/c/foo";
503 return 1
504 fi
505 egrep "CRIT.*POLICY ADDED.*033\[1;30m" $LOGFILE >/dev/null 2>&1
506 if [ $? -ne 0 ]; then
507 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/\033[1;30m";
508 return 1
509 fi
510 egrep "WARN.*Weird filename.*033\[1;30m" $LOGFILE >/dev/null 2>&1
511 if [ $? -ne 0 ]; then
512 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/\033[1;30m";
513 return 1
514 fi
515 egrep "CRIT.*POLICY \[ReadOnly\] C-------TS.*${BASE}/a/a/c/y" $LOGFILE >/dev/null 2>&1
516 if [ $? -ne 0 ]; then
517 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/c/y";
518 return 1
519 fi
520 tmp=`grep CRIT $LOGFILE | wc -l`
521 if [ $tmp -ne 6 ]; then
522 [ -z "$verbose" ] || log_msg_fail "policy count";
523 return 1
524 fi
525}
526
527TESTPOLICY_3="
528[Attributes]
529dir=${BASE}
530file=${BASE}/a/a/c/x
531[ReadOnly]
532file=${BASE}/a/a/c/y
533[IgnoreAll]
534dir=${BASE}/a/a/c
535"
536mod_testdata_3 () {
537 one_sec_sleep
538 echo "foobar" > "${BASE}/a/b/foo" # new within Attributes
539 chmod 0555 "${BASE}/a/b"
540 echo "foobar" > "${BASE}/a/a/c/foo" # new within IgnoreAll
541 echo "foobar" > "${BASE}/a/a/c/y" # ReadOnly
542 chmod 0555 "${BASE}/a/a/c/x" # Attributes
543 chmod 0555 "${BASE}/a/a/c/z" # IgnoreAll
544}
545
546chk_testdata_3 () {
547 for ff in $TDIRS; do
548 #
549 egrep "Checking.*${BASE}/${ff}(>|\")" $LOGFILE >/dev/null 2>&1
550 if [ $? -ne 0 ]; then
551 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff} (checking)";
552 return 1
553 fi
554 tmp=`egrep "Checking.*${BASE}/${ff}(>|\")" $LOGFILE 2>/dev/null | wc -l`
555 if [ $tmp -ne 1 ]; then
556 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff} (multiple)";
557 fi
558 #
559 for gg in $TFILES; do
560 egrep "Checksum.*${BASE}/${ff}/${gg}" $LOGFILE >/dev/null 2>&1
561 if [ $? -ne 0 ]; then
562 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff}/${gg} (checking)";
563 fi
564 tmp=`egrep "Checksum.*${BASE}/${ff}/${gg}" $LOGFILE 2>/dev/null | wc -l`
565 if [ $tmp -ne 1 ]; then
566 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff}/${gg} (multiple)";
567 fi
568 done
569 done
570 egrep "CRIT.*POLICY ADDED.*${BASE}/a/b/foo" $LOGFILE >/dev/null 2>&1
571 if [ $? -ne 0 ]; then
572 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/b/foo";
573 return 1
574 fi
575 egrep "CRIT.*POLICY ADDED.*${BASE}/a/a/c/foo" $LOGFILE >/dev/null 2>&1
576 if [ $? -ne 0 ]; then
577 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/c/foo";
578 return 1
579 fi
580 egrep "CRIT.*POLICY \[Attributes\] -----M----.*${BASE}/a/b" $LOGFILE >/dev/null 2>&1
581 if [ $? -ne 0 ]; then
582 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/b";
583 return 1
584 fi
585 egrep "CRIT.*POLICY \[Attributes\] -----M----.*${BASE}/a/a/c/x" $LOGFILE >/dev/null 2>&1
586 if [ $? -ne 0 ]; then
587 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/c/x";
588 return 1
589 fi
590 egrep "CRIT.*POLICY \[ReadOnly\] C-------TS.*${BASE}/a/a/c/y" $LOGFILE >/dev/null 2>&1
591 if [ $? -ne 0 ]; then
592 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/c/y";
593 return 1
594 fi
595 tmp=`grep CRIT $LOGFILE | wc -l`
596 if [ $tmp -ne 5 ]; then
597 [ -z "$verbose" ] || log_msg_fail "policy count";
598 return 1
599 fi
600}
601
602TESTPOLICY_2="
603[ReadOnly]
604dir=${BASE}
605file=${BASE}/a/a/c/x
606[IgnoreAll]
607dir=${BASE}/a/a/c
608"
609mod_testdata_2 () {
610 mod_testdata_1;
611 rm "${BASE}/a/a/c/y"
612 echo "foobar" > "${BASE}/a/a/c/foo"
613 chmod 0555 "${BASE}/a/a/c/x"
614 chmod 0555 "${BASE}/a/a/c/z"
615}
616
617chk_testdata_2 () {
618 for ff in $TDIRS; do
619 #
620 egrep "Checking.*${BASE}/${ff}(>|\")" $LOGFILE >/dev/null 2>&1
621 if [ $? -ne 0 ]; then
622 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff} (checking)";
623 return 1
624 fi
625 tmp=`egrep "Checking.*${BASE}/${ff}(>|\")" $LOGFILE 2>/dev/null | wc -l`
626 if [ $tmp -ne 1 ]; then
627 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff} (multiple)";
628 fi
629 #
630 for gg in $TFILES; do
631 egrep "Checksum.*${BASE}/${ff}/${gg}" $LOGFILE >/dev/null 2>&1
632 if [ $? -ne 0 ]; then
633 if [ x"${ff}/${gg}" = x"a/a/c/y" ]; then :; else
634 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff}/${gg} (checking)";
635 return 1
636 fi
637 fi
638 done
639 done
640 egrep "CRIT.*POLICY ADDED.*${BASE}/a/a/c/foo" $LOGFILE >/dev/null 2>&1
641 if [ $? -ne 0 ]; then
642 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/c/foo";
643 return 1
644 fi
645 egrep "CRIT.*POLICY MISSING.*${BASE}/a/a/c/y" $LOGFILE >/dev/null 2>&1
646 if [ $? -ne 0 ]; then
647 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/c/y";
648 return 1
649 fi
650 egrep "CRIT.*POLICY \[ReadOnly\] -----M--T-.*${BASE}/a/a/c/x" $LOGFILE >/dev/null 2>&1
651 if [ $? -ne 0 ]; then
652 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/c/x";
653 return 1
654 fi
655 tmp=`grep CRIT $LOGFILE | wc -l`
656 if [ $tmp -ne 8 ]; then
657 [ -z "$verbose" ] || log_msg_fail "policy count";
658 return 1
659 fi
660}
661
662TESTPOLICY_1="
663[ReadOnly]
664dir=${BASE}
665"
666
667mod_testdata_1 () {
668 one_sec_sleep
669 touch "${BASE}/a/a/x"
670 chmod 0555 "${BASE}/a/a/y"
671 mv "${BASE}/a/b/y" "${BASE}/a/b/yy"; echo "This is a test file" > "${BASE}/a/b/y"; rm "${BASE}/a/b/yy"
672 echo "foobar" > "${BASE}/a/c/y"
673}
674
675chk_testdata_1 () {
676 for ff in $TDIRS; do
677 #
678 egrep "Checking.*${BASE}/${ff}(>|\")" $LOGFILE >/dev/null 2>&1
679 if [ $? -ne 0 ]; then
680 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff} (checking)";
681 return 1
682 fi
683 tmp=`egrep "Checking.*${BASE}/${ff}(>|\")" $LOGFILE 2>/dev/null | wc -l`
684 if [ $tmp -ne 1 ]; then
685 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff} (multiple)";
686 fi
687 #
688 for gg in $TFILES; do
689 egrep "Checksum.*${BASE}/${ff}/${gg}" $LOGFILE >/dev/null 2>&1
690 if [ $? -ne 0 ]; then
691 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff}/${gg} (checking)";
692 return 1
693 fi
694 tmp=`egrep "Checksum.*${BASE}/${ff}/${gg}" $LOGFILE 2>/dev/null | wc -l`
695 if [ $tmp -ne 1 ]; then
696 [ -z "$verbose" ] || log_msg_fail "${BASE}/${ff}/${gg} (multiple)";
697 fi
698 done
699 done
700 egrep "CRIT.*POLICY \[ReadOnly\] --------T-.*${BASE}/a/a/x" $LOGFILE >/dev/null 2>&1
701 if [ $? -ne 0 ]; then
702 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/x";
703 return 1
704 fi
705 egrep "CRIT.*POLICY \[ReadOnly\] -----M--T-.*${BASE}/a/a/y" $LOGFILE >/dev/null 2>&1
706 if [ $? -ne 0 ]; then
707 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/y";
708 return 1
709 fi
710 egrep "CRIT.*POLICY \[ReadOnly\] ---I----T-.*${BASE}/a/b/y" $LOGFILE >/dev/null 2>&1
711 if [ $? -ne 0 ]; then
712 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/b/y";
713 return 1
714 fi
715 egrep "CRIT.*POLICY \[ReadOnly\] --------T-.*${BASE}/a/b" $LOGFILE >/dev/null 2>&1
716 if [ $? -ne 0 ]; then
717 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/b";
718 return 1
719 fi
720 egrep "CRIT.*POLICY \[ReadOnly\] C-------TS.*${BASE}/a/c/y" $LOGFILE >/dev/null 2>&1
721 if [ $? -ne 0 ]; then
722 [ -z "$verbose" ] || log_msg_fail "${BASE}/a/c/y";
723 return 1
724 fi
725 tmp=`grep CRIT $LOGFILE | wc -l`
726 if [ $tmp -ne 5 ]; then
727 [ -z "$verbose" ] || log_msg_fail "policy count";
728 return 1
729 fi
730 return 0
731}
732
733
734##############################################################
735#
736# Common subroutines
737#
738
739mkconfig_misc ()
740{
741 test -f "${RCFILE}" || touch "${RCFILE}"
742 cat >> "${RCFILE}" <<End-of-data
743[Misc]
744Daemon=no
745SetFilecheckTime=60
746TrustedUser=uucp,fax,fnet
747SetRecursionLevel=10
748SetLoopTime=30
749ReportFullDetail = no
750ChecksumTest=check
751
752End-of-data
753}
754
755mkconfig_log ()
756{
757 test -f "${RCFILE}" || touch "${RCFILE}"
758 cat >> "${RCFILE}" <<End-of-data
759[Log]
760MailSeverity=none
761LogSeverity=warn
762SyslogSeverity=none
763PrintSeverity=info
764MailSeverity=none
765#Restrict to certain classes of messages
766#LogClass=RUN
767#PreludeSeverity=err
768#ExportSeverity=none
769
770End-of-data
771}
772
773mkconfig_sev ()
774{
775 test -f "${RCFILE}" || touch "${RCFILE}"
776 cat >> "${RCFILE}" <<End-of-data
777[EventSeverity]
778SeverityUser0=crit
779SeverityUser1=crit
780SeverityReadOnly=crit
781SeverityLogFiles=crit
782SeverityGrowingLogs=crit
783SeverityIgnoreNone=crit
784SeverityAttributes=crit
785SeverityIgnoreAll=crit
786SeverityFiles=err
787SeverityDirs=err
788SeverityNames=warn
789
790End-of-data
791}
792
793prep_testpolicy ()
794{
795 test -f "${RCFILE}" || touch "${RCFILE}"
796 eval echo '"$'"TESTPOLICY_$1"'"' >>"${RCFILE}"
797}
798
799prep_init ()
800{
801 rm -f ./.samhain_file
802 rm -f "${LOGFILE}"
803 rm -f ./.samhain_lock
804
805 rm -f "${RCFILE}"
806 mkconfig_sev
807 mkconfig_log
808 mkconfig_misc
809}
810
811run_init ()
812{
813 rm -f test_log_valgrind
814
815 ${VALGRIND} ./samhain -t init -p none 2>>test_log_valgrind
816
817 if test x$? = x0; then
818 [ -z "$verbose" ] || log_msg_ok "init...";
819 else
820 [ -z "$quiet" ] && log_msg_fail "init...";
821 return 1
822 fi
823}
824
825run_check ()
826{
827 ${VALGRIND} ./samhain -t check -p none -l debug 2>>test_log_valgrind
828
829 if test x$? = x0; then
830 ./samhain -j -L $LOGFILE >"${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "${LOGFILE}"
831 if [ $? -ne 0 ]; then
832 [ -z "$quiet" ] && log_msg_fail "mv logfile...";
833 return 1
834 fi
835 [ -z "$verbose" ] || log_msg_ok "check...";
836 else
837 [ -z "$quiet" ] && log_msg_fail "check...";
838 return 1
839 fi
840}
841
842run_update ()
843{
844 ${VALGRIND} ./samhain -t update -p none -l debug 2>>test_log_valgrind
845
846 if test x$? = x0; then
847 [ -z "$verbose" ] || log_msg_ok "update...";
848 else
849 [ -z "$quiet" ] && log_msg_fail "update...";
850 return 1
851 fi
852}
853
854run_check_after_update ()
855{
856 rm -rf $LOGFILE
857
858 ${VALGRIND} ./samhain -t check -p none -l debug 2>>test_log_valgrind
859
860 if test x$? = x0; then
861 #
862 tmp=`./samhain -j -L $LOGFILE | grep CRIT | wc -l`
863 if [ $tmp -ne 0 ]; then
864 [ -z "$verbose" ] || log_msg_fail "update not successful(?)";
865 return 1
866 fi
867 #
868 # wtmp may not be readable
869 #
870 tmp=`./samhain -j -L $LOGFILE | grep ERR | grep -v wtmp | wc -l`
871 if [ $tmp -ne 0 ]; then
872 [ -z "$verbose" ] || log_msg_fail "errors during check";
873 return 1
874 fi
875 #
876 [ -z "$VALGRIND" ] || {
877 tmp=`cat test_log_valgrind 2>/dev/null | wc -l`;
878 if [ $tmp -ne 0 ]; then
879 [ -z "$verbose" ] || log_msg_fail "valgrind reports errors";
880 cat test_log_valgrind
881 return 1;
882 fi;
883 }
884 #
885 [ -z "$verbose" ] || log_msg_ok "check(2)...";
886 else
887 [ -z "$quiet" ] && log_msg_fail "check(2)...";
888 return 1
889 fi
890}
891
892prep_testdata ()
893{
894 if test -d "$BASE"; then
895 if [ -d "${BASE}" ]; then
896 chmod -R 0700 "${BASE}" || {
897 [ -z "$quiet" ] && log_msg_fail "chmod -R 0700 ${BASE}";
898 return 1;
899 }
900 fi
901 fi
902
903 rm -rf "${BASE}" || {
904 [ -z "$quiet" ] && log_msg_fail "rm -rf ${BASE}";
905 return 1;
906 }
907
908 mkdir "${BASE}" || {
909 [ -z "$quiet" ] && log_msg_fail "mkdir ${BASE}";
910 return 1;
911 }
912
913 for ff in $TDIRS; do
914 mkdir "${BASE}/${ff}" || {
915 [ -z "$quiet" ] && log_msg_fail "mkdir ${BASE}/${ff}";
916 return 1;
917 }
918 chmod 0755 "${BASE}/${ff}"
919 for gg in $TFILES; do
920 echo "This is a test file" > "${BASE}/${ff}/${gg}"
921 chmod 0644 "${BASE}/${ff}/${gg}"
922 done
923 done
924}
925
926check_err ()
927{
928 if [ $1 -ne 0 ]; then
929 [ -z "$quiet" ] && log_fail ${2} ${MAXTEST};
930 return 1
931 fi
932 return 0
933}
934
935testrun_internal ()
936{
937 [ -z "$verbose" ] || echo Working directory: $PW_DIR
938 [ -z "$verbose" ] || { echo MAKE is $MAKE; echo; }
939
940 #
941 # test standalone compilation
942 #
943 [ -z "$verbose" ] || { echo; echo "${S}Building standalone agent${E}"; echo; }
944
945 if test -r "Makefile"; then
946 $MAKE distclean >/dev/null
947 fi
948
949 ${TOP_SRCDIR}/configure ${BUILDOPTS}
950
951 #
952 if test x$? = x0; then
953 [ -z "$verbose" ] || log_msg_ok "configure...";
954 $MAKE >/dev/null 2>>test_log
955 if test x$? = x0; then
956 [ -z "$verbose" ] || log_msg_ok "make...";
957 else
958 [ -z "$quiet" ] && log_msg_fail "make...";
959 return 1
960 fi
961
962 else
963 [ -z "$quiet" ] && log_msg_fail "configure...";
964 return 1
965 fi
966
967 [ -z "$verbose" ] || { echo; echo "${S}Running test suite${E}"; echo; }
968
969 tcount=1
970 POLICY=`eval echo '"$'"TESTPOLICY_$tcount"'"'`
971
972 until [ -z "$POLICY" ]
973 do
974 prep_init
975 check_err $? ${tcount}; errval=$?
976 if [ $errval -eq 0 ]; then
977 prep_testdata
978 check_err $? ${tcount}; errval=$?
979 fi
980 if [ $errval -eq 0 ]; then
981 prep_testpolicy ${tcount}
982 check_err $? ${tcount}; errval=$?
983 fi
984 if [ $errval -eq 0 ]; then
985 run_init
986 check_err $? ${tcount}; errval=$?
987 fi
988 if [ $errval -eq 0 ]; then
989 eval mod_testdata_${tcount}
990 check_err $? ${tcount}; errval=$?
991 fi
992 if [ $errval -eq 0 ]; then
993 run_check
994 check_err $? ${tcount}; errval=$?
995 fi
996 if [ $errval -eq 0 ]; then
997 eval chk_testdata_${tcount}
998 check_err $? ${tcount}; errval=$?
999 fi
1000 if [ $testrun1_setup -eq 0 ]; then
1001 if [ $errval -eq 0 ]; then
1002 run_update
1003 check_err $? ${tcount}; errval=$?
1004 fi
1005 if [ $errval -eq 0 ]; then
1006 run_check_after_update
1007 check_err $? ${tcount}; errval=$?
1008 fi
1009 fi
1010 #
1011 if [ $errval -eq 0 ]; then
1012 [ -z "$quiet" ] && log_ok ${tcount} ${MAXTEST};
1013 fi
1014 let "tcount = tcount + 1" >/dev/null
1015 POLICY=`eval echo '"$'"TESTPOLICY_$tcount"'"'`
1016 done
1017
1018 return 0
1019}
1020
1021testrun1 ()
1022{
1023 log_start "RUN STANDALONE"
1024 testrun_internal
1025 log_end "RUN STANDALONE"
1026 return 0
1027}
1028
1029
1030
Note: See TracBrowser for help on using the repository browser.