source: trunk/test/testrun_1b.sh@ 169

Last change on this file since 169 was 169, checked in by katerina, 17 years ago

Fixes for tickes #93 to #104 (yes, big commit, bad, bad,...).

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