source: trunk/test/testrun_1b.sh@ 576

Last change on this file since 576 was 562, checked in by katerina, 3 years ago

Fix for ticket #450 (compiler warnings) and fixes for tests.

File size: 14.5 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
22MAXTEST=7; export MAXTEST
23LOGFILE="$PW_DIR/.samhain_log"; export LOGFILE
24RCFILE="$PW_DIR/testrc_1.dyn"; export RCFILE
25
26testrun1b_modrc ()
27{
28 ORIGINAL="\[EOF\]"
29 REPLACEMENT="\[PortCheck\]"
30 ex -s $RCFILE <<EOF
31%s/$ORIGINAL/$REPLACEMENT/g
32wq
33EOF
34
35 echo "PortCheckActive = yes" >>"$RCFILE"
36 echo "PortCheckInterface = 127.0.0.1" >>"$RCFILE"
37}
38
39testrun1b_internal ()
40{
41 BUILDOPTS="$1"
42 #
43 # test standalone compilation
44 #
45 [ -z "$verbose" ] || { echo; echo "${S}Building standalone agent${E}"; echo; }
46 #
47 if test -r "Makefile"; then
48 $MAKE distclean >/dev/null >&1
49 fi
50 #
51 # Bootstrapping
52 #
53 ${TOP_SRCDIR}/configure >/dev/null 2>/dev/null
54 if test x$? = x0; then
55 [ -z "$verbose" ] || log_msg_ok "configure (bootstrap)...";
56 $MAKE > /dev/null 2>&1
57 if test x$? = x0; then
58 [ -z "$verbose" ] || log_msg_ok "make (bootstrap)...";
59 else
60 [ -z "$quiet" ] && log_msg_fail "make (bootstrap)...";
61 return 1
62 fi
63
64 else
65 [ -z "$quiet" ] && log_msg_fail "configure (bootstrap)...";
66 return 1
67 fi
68 #
69 #
70 ${TOP_SRCDIR}/configure ${BUILDOPTS} 2>/dev/null
71 #
72 #
73 if test x$? = x0; then
74 [ -z "$verbose" ] || log_msg_ok "configure...";
75 $MAKE > /dev/null 2>&1
76 if test x$? = x0; then
77 [ -z "$verbose" ] || log_msg_ok "make...";
78 else
79 [ -z "$quiet" ] && log_msg_fail "make...";
80 return 1
81 fi
82
83 else
84 [ -z "$quiet" ] && log_msg_fail "configure...";
85 return 1
86 fi
87
88 SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' ${SCRIPTDIR}/test.sh`
89
90 tail -n "+$SKIP" ${SCRIPTDIR}/test.sh >/dev/null 2>&1
91 if [ $? -eq 0 ]; then
92 tail -n "+$SKIP" ${SCRIPTDIR}/test.sh | gunzip -c - 2>/dev/null | tar xf - && \
93 mv "./testrc.gpg.asc" "$RCFILE"
94 else
95 tail "+$SKIP" ${SCRIPTDIR}/test.sh | gunzip -c - 2>/dev/null | tar xf - && \
96 mv "./testrc.gpg.asc" "$RCFILE"
97 fi
98 if test x$? = x0; then
99 [ -z "$verbose" ] || log_msg_ok "extract gpg signed files...";
100 else
101 [ -z "$quiet" ] && log_msg_fail "extract gpg signed files...";
102 return 1
103 fi
104
105 if test "x$2" = "x"; then
106 :
107 else
108 CONVERT="$2"
109 if test -f "${TOP_SRCDIR}/stealth_template.jpg"; then
110 [ -z "$verbose" ] || log_msg_ok "convert..."
111 "${CONVERT}" +compress "${TOP_SRCDIR}/stealth_template.jpg" stealth_template.ps >/dev/null
112 else
113 [ -z "$quiet" ] && log_msg_fail "cannot find file stealth_template.jpg"
114 return 1
115 fi
116 if [ $? -ne 0 ]; then
117 [ -z "$quiet" ] && log_msg_fail "${CONVERT} +compress ${TOP_SRCDIR}/stealth_template.jpg stealth_template.ps";
118 return 1
119 fi
120
121 [ -z "$verbose" ] || log_msg_ok "hide..."
122 ./samhain_stealth -s stealth_template.ps "$RCFILE" >/dev/null
123 if [ $? -ne 0 ]; then
124 [ -z "$quiet" ] && log_msg_fail "${CONVERT} +compress ${TOP_SRCDIR}/stealth_template.jpg stealth_template.ps";
125 return 1
126 fi
127
128 mv -f stealth_template.ps "$RCFILE"
129 if [ $? -ne 0 ]; then
130 [ -z "$quiet" ] && log_msg_fail "mv -f stealth_template.ps $RCFILE";
131 return 1
132 fi
133
134 fi
135
136 rm -f ./.samhain_file
137 rm -f ./.samhain_log
138 rm -f ./.samhain_lock
139
140 ./samhain -t init -p none -l info
141
142 if test x$? = x0; then
143 [ -z "$verbose" ] || log_msg_ok "init...";
144 else
145 [ -z "$quiet" ] && log_msg_fail "init...";
146 return 1
147 fi
148
149 mv $PW_DIR/.samhain_file.asc $PW_DIR/.samhain_file
150}
151
152testrun1b_nogpg ()
153{
154 BUILDOPTS="$1"
155 #
156 # test standalone compilation
157 #
158 [ -z "$verbose" ] || { echo; echo "${S}Building standalone agent${E}"; echo; }
159 #
160 if test -r "Makefile"; then
161 $MAKE distclean >/dev/null >&1
162 fi
163
164 ${TOP_SRCDIR}/configure ${BUILDOPTS} 2>/dev/null
165 #
166 #
167 if test x$? = x0; then
168 [ -z "$verbose" ] || log_msg_ok "configure...";
169 $MAKE > /dev/null 2>&1
170 if test x$? = x0; then
171 [ -z "$verbose" ] || log_msg_ok "make...";
172 else
173 [ -z "$quiet" ] && log_msg_fail "make...";
174 return 1
175 fi
176
177 else
178 [ -z "$quiet" ] && log_msg_fail "configure...";
179 return 1
180 fi
181
182 rm -f ./.samhain_file
183 rm -f ./.samhain_log
184 rm -f ./.samhain_lock
185
186 cp "${SCRIPTDIR}/testrc_1" "${RCFILE}"
187
188 if test "x$2" = "xmodrc"; then
189 [ -z "$verbose" ] || log_msg_ok "mod rc...";
190 testrun1b_modrc
191 fi
192
193 ./samhain -t init -p none -l info
194
195 if test x$? = x0; then
196 [ -z "$verbose" ] || log_msg_ok "init...";
197 else
198 [ -z "$quiet" ] && log_msg_fail "init...";
199 return 1
200 fi
201
202}
203
204do_test_1b () {
205
206 ./samhain -t check -p none -l info
207
208 if test x$? = x0; then
209 ./samhain -j -L $LOGFILE >"${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "${LOGFILE}"
210 if [ $? -ne 0 ]; then
211 [ -z "$quiet" ] && log_msg_fail "mv logfile...";
212 return 1
213 fi
214 [ -z "$verbose" ] || log_msg_ok "check...";
215 else
216 [ -z "$quiet" ] && log_msg_fail "check...";
217 return 1
218 fi
219 #
220 tmp=`egrep "Checking.*/etc(>|\")" $LOGFILE 2>/dev/null | wc -l`
221 if [ $tmp -ne 2 ]; then
222 [ -z "$verbose" ] || log_msg_fail "/etc";
223 return 1
224 fi
225 tmp=`egrep "Checking.*(>|\")" $LOGFILE 2>/dev/null | wc -l`
226 if [ $tmp -ne 10 ]; then
227 [ -z "$verbose" ] || log_msg_fail "checking";
228 return 1
229 fi
230 egrep "ADDED" $LOGFILE >/dev/null 2>&1
231 if [ $? -eq 0 ]; then
232 [ -z "$verbose" ] || log_msg_fail "init was incomplete";
233 return 1
234 fi
235 #
236 return 0
237}
238
239do_test_1b_2 () {
240
241 #rm -f $PW_DIR/test_log_prelude
242 test_log_prelude="/var/log/prelude/prelude-text.log"
243 echo -n >"${test_log_prelude}"
244
245 #[ -z "$verbose" ] || { echo " starting prelude-manager.."; echo " ($PM --textmod -l $PW_DIR/test_log_prelude --listen 127.0.0.1:5500 >/dev/null 2>&1 &)"; }
246 #"$PM" --textmod -l $PW_DIR/test_log_prelude --listen 127.0.0.1:5500 >/dev/null 2>&1 &
247 #PID=$!
248
249 #five_sec_sleep
250
251 ./samhain -t check -p none -l info --set-prelude-severity=info --prelude --server-addr 127.0.0.1:5500 >/dev/null
252
253 if test x$? = x0; then
254 ./samhain -j -L $LOGFILE >"${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "${LOGFILE}"
255 if [ $? -ne 0 ]; then
256 [ -z "$quiet" ] && log_msg_fail "mv logfile...";
257 kill $PID
258 return 1
259 fi
260 [ -z "$verbose" ] || log_msg_ok "check...";
261 else
262 [ -z "$quiet" ] && log_msg_fail "check...";
263 #kill $PID
264 return 1
265 fi
266 #
267 tmp=`egrep 'File original:.*name=etc.*path=/etc' ${test_log_prelude} 2>/dev/null | wc -l`
268 if [ $tmp -lt 1 ]; then
269 [ -z "$verbose" ] || log_msg_fail "/etc";
270 #kill $PID
271 return 1
272 fi
273 tmp=`egrep 'Classification text: Checking' ${test_log_prelude} 2>/dev/null | wc -l`
274 if [ $tmp -lt 1 ]; then
275 [ -z "$verbose" ] || log_msg_fail "checking";
276 #kill $PID
277 return 1
278 fi
279 #
280 if test "x$2" = "xmodrc"; then
281 tmp=`egrep 'Classification text: Service opened' ${test_log_prelude} 2>/dev/null | wc -l`
282 if [ $tmp -lt 1 ]; then
283 [ -z "$verbose" ] || log_msg_fail "service";
284 #kill $PID
285 return 1
286 fi
287 tmp=`egrep 'Service: port=5500' ${test_log_prelude} 2>/dev/null | wc -l`
288 if [ $tmp -lt 1 ]; then
289 [ -z "$verbose" ] || log_msg_fail "port 5500";
290 #kill $PID
291 return 1
292 fi
293 fi
294 #
295 #kill $PID
296 return 0
297}
298
299testrun1b ()
300{
301 log_start "RUN STANDALONE W/STEALTH W/GPG"
302 GPG=`find_path gpg`
303 if [ -z "$GPG" ]; then
304 log_skip 1 $MAXTEST 'gpg not found in $PATH'
305 log_skip 2 $MAXTEST 'gpg not found in $PATH'
306 log_skip 3 $MAXTEST 'gpg not found in $PATH'
307 log_skip 4 $MAXTEST 'gpg not found in $PATH'
308 log_skip 5 $MAXTEST 'gpg not found in $PATH'
309 log_skip 6 $MAXTEST 'gpg not found in $PATH'
310 log_skip 7 $MAXTEST 'gpg not found in $PATH'
311 else
312 eval "$GPG" --list-keys 0F571F6C >/dev/null 2>/dev/null
313 if [ $? -ne 0 ]; then
314 log_skip 1 $MAXTEST 'public PGP key 0x0F571F6C not present'
315 log_skip 2 $MAXTEST 'public PGP key 0x0F571F6C not present'
316 log_skip 3 $MAXTEST 'public PGP key 0x0F571F6C not present'
317 log_skip 4 $MAXTEST 'public PGP key 0x0F571F6C not present'
318 log_skip 5 $MAXTEST 'public PGP key 0x0F571F6C not present'
319 log_skip 6 $MAXTEST 'public PGP key 0x0F571F6C not present'
320 log_skip 7 $MAXTEST 'public PGP key 0x0F571F6C not present'
321 else
322 #
323 # ------------- first test -------------
324 #
325 BUILDOPTS="--quiet $TRUST --enable-debug --with-gpg=${GPG} --enable-micro-stealth=137 --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
326 testrun1b_internal "${BUILDOPTS}"
327 do_test_1b
328 if [ $? -eq 0 ]; then
329 log_ok 1 $MAXTEST 'gpg signed config/database files'
330 else
331 log_fail 1 $MAXTEST 'gpg signed config/database files'
332 fi
333
334
335 #
336 # ------------- second test -------------
337 #
338 BUILDOPTS="--quiet $TRUST --enable-debug --with-gpg=${GPG} --with-checksum --enable-micro-stealth=137 --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
339 testrun1b_internal "${BUILDOPTS}"
340 do_test_1b
341 if [ $? -eq 0 ]; then
342 log_ok 2 $MAXTEST 'gpg signed config/database files'
343 else
344 log_fail 2 $MAXTEST 'gpg signed config/database files'
345 fi
346
347
348 #
349 # ------------- third test -------------
350 #
351 BUILDOPTS="--quiet $TRUST --enable-debug --with-gpg=${GPG} --with-checksum --with-fp=EF6CEF54701A0AFDB86AF4C31AAD26C80F571F6C --enable-micro-stealth=137 --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
352 testrun1b_internal "${BUILDOPTS}"
353 do_test_1b
354 if [ $? -eq 0 ]; then
355 log_ok 3 $MAXTEST 'gpg signed config/database files'
356 else
357 log_fail 3 $MAXTEST 'gpg signed config/database files'
358 fi
359
360
361 #
362 # ------------- fourth test -------------
363 #
364 PRECONV=`find_path convert`
365 "${PRECONV}" --help | grep ImageMagick >/dev/null 2>&1 && \
366 CONVERT="${PRECONV}"
367
368 if [ -z "$CONVERT" ]; then
369 log_skip 2 $MAXTEST 'ImageMagick convert not found in $PATH'
370 else
371 BUILDOPTS="--quiet $TRUST --enable-debug --with-gpg=${GPG} --with-checksum --enable-stealth=137 --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
372 testrun1b_internal "${BUILDOPTS}" "$CONVERT"
373 do_test_1b
374 if [ $? -eq 0 ]; then
375 log_ok 4 $MAXTEST 'gpg signed config/database files'
376 else
377 log_fail 4 $MAXTEST 'gpg signed config/database files'
378 fi
379 fi
380
381
382 #
383 # ------------- fifth test -------------
384 #
385 if ! test -d /var/run/prelude-manager
386 then
387 [ -z "$verbose" ] || log_msg_ok "create /var/run/prelude-manager...";
388 sudo mkdir /var/run/prelude-manager
389 sudo chown prelude:rainer /var/run/prelude-manager
390 sudo chmod 770 /var/run/prelude-manager
391 fi
392 #
393 PM=`find_path prelude-manager`
394 if [ -z "$PM" ]; then
395 log_skip 5 $MAXTEST 'prelude-manager not found in $PATH'
396 elif [ -z "$doall" ]; then
397 log_skip 5 $MAXTEST 'logging to prelude (or use --really-all)'
398 else
399 BUILDOPTS="--quiet $TRUST --enable-debug --with-prelude --with-gpg=${GPG} --with-checksum --enable-micro-stealth=137 --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
400 testrun1b_internal "${BUILDOPTS} CFLAGS=-DSH_NOFAILOVER=1"
401 do_test_1b_2
402 if [ $? -eq 0 ]; then
403 log_ok 5 $MAXTEST 'logging to prelude'
404 else
405 log_fail 5 $MAXTEST 'logging to prelude'
406 fi
407 fi
408
409 #
410 # ------------- sixth test -------------
411 #
412 if ! test -d /var/run/prelude-manager
413 then
414 [ -z "$verbose" ] || log_msg_ok "create /var/run/prelude-manager...";
415 sudo mkdir /var/run/prelude-manager
416 sudo chown prelude:rainer /var/run/prelude-manager
417 sudo chmod 770 /var/run/prelude-manager
418 fi
419 #
420 PM=`find_path prelude-manager`
421 if [ -z "$PM" ]; then
422 log_skip 6 $MAXTEST 'prelude-manager not found in $PATH'
423 elif [ -z "$doall" ]; then
424 log_skip 6 $MAXTEST 'logging to prelude (or use --really-all)'
425 else
426 BUILDOPTS="--quiet $TRUST --with-prelude --enable-login-watch --enable-mounts-check --enable-process-check --enable-port-check --enable-suidcheck --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
427 testrun1b_nogpg "${BUILDOPTS} CFLAGS=-DSH_NOFAILOVER=1"
428 do_test_1b_2
429 if [ $? -eq 0 ]; then
430 log_ok 6 $MAXTEST 'logging to prelude'
431 else
432 log_fail 6 $MAXTEST 'logging to prelude'
433 fi
434 fi
435
436 #
437 # ------------- seventh test -----------
438 #
439 if ! test -d /var/run/prelude-manager
440 then
441 [ -z "$verbose" ] || log_msg_ok "create /var/run/prelude-manager...";
442 sudo mkdir /var/run/prelude-manager
443 sudo chown prelude:rainer /var/run/prelude-manager
444 sudo chmod 770 /var/run/prelude-manager
445 fi
446 #
447 PM=`find_path prelude-manager`
448 if [ -z "$PM" ]; then
449 log_skip 7 $MAXTEST 'prelude-manager not found in $PATH'
450 elif [ -z "$doall" ]; then
451 log_skip 7 $MAXTEST 'logging to prelude (or use --really-all)'
452 else
453 BUILDOPTS="--quiet $TRUST --with-prelude --enable-login-watch --enable-mounts-check --enable-process-check --enable-port-check --enable-suidcheck --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
454 testrun1b_nogpg "${BUILDOPTS} CFLAGS=-DSH_NOFAILOVER=1" "modrc"
455 do_test_1b_2
456 if [ $? -eq 0 ]; then
457 log_ok 7 $MAXTEST 'logging to prelude'
458 else
459 log_fail 7 $MAXTEST 'logging to prelude'
460 fi
461 fi
462
463 fi
464 fi
465 log_end "RUN STANDALONE W/STEALTH W/GPG"
466 return 0
467}
468
Note: See TracBrowser for help on using the repository browser.