source: trunk/test/testrun_1b.sh@ 54

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

Fix stealth mode (regression in parser), add test for regression test suite

File size: 7.8 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
[52]22MAXTEST=3; 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 #
38 #
[19]39 ${TOP_SRCDIR}/configure ${BUILDOPTS} >/dev/null 2>/dev/null
[1]40 #
41 #
42 if test x$? = x0; then
[19]43 [ -z "$verbose" ] || log_msg_ok "configure...";
[22]44 $MAKE > /dev/null 2>&1
[1]45 if test x$? = x0; then
[19]46 [ -z "$verbose" ] || log_msg_ok "make...";
[1]47 else
[19]48 [ -z "$quiet" ] && log_msg_fail "make...";
49 return 1
[1]50 fi
51
52 else
[19]53 [ -z "$quiet" ] && log_msg_fail "configure...";
54 return 1
[1]55 fi
56
[19]57 SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' ${SCRIPTDIR}/test.sh`
[1]58
[19]59 tail -n "+$SKIP" ${SCRIPTDIR}/test.sh >/dev/null 2>&1
60 if [ $? -eq 0 ]; then
61 tail -n "+$SKIP" ${SCRIPTDIR}/test.sh | gunzip -c - | tar xf - && \
62 mv "./testrc.gpg.asc" "$RCFILE"
63 else
64 tail "+$SKIP" ${SCRIPTDIR}/test.sh | gunzip -c - | tar xf - && \
65 mv "./testrc.gpg.asc" "$RCFILE"
66 fi
67 if test x$? = x0; then
68 [ -z "$verbose" ] || log_msg_ok "extract gpg signed files...";
69 else
70 [ -z "$quiet" ] && log_msg_fail "extract gpg signed files...";
71 return 1
72 fi
73
[52]74 if test "x$2" = "x"; then
75 :
76 else
77 CONVERT="$2"
78 if test -f "${TOP_SRCDIR}/stealth_template.jpg"; then
79 [ -z "$verbose" ] || log_msg_ok "convert..."
80 "${CONVERT}" +compress "${TOP_SRCDIR}/stealth_template.jpg" stealth_template.ps >/dev/null
81 else
82 [ -z "$quiet" ] && log_msg_fail "cannot find file stealth_template.jpg"
83 return 1
84 fi
85 if [ $? -ne 0 ]; then
86 [ -z "$quiet" ] && log_msg_fail "${CONVERT} +compress ${TOP_SRCDIR}/stealth_template.jpg stealth_template.ps";
87 return 1
88 fi
89
90 [ -z "$verbose" ] || log_msg_ok "hide..."
91 ./samhain_stealth -s stealth_template.ps "$RCFILE" >/dev/null
92 if [ $? -ne 0 ]; then
93 [ -z "$quiet" ] && log_msg_fail "${CONVERT} +compress ${TOP_SRCDIR}/stealth_template.jpg stealth_template.ps";
94 return 1
95 fi
96
97 mv -f stealth_template.ps "$RCFILE"
98 if [ $? -ne 0 ]; then
99 [ -z "$quiet" ] && log_msg_fail "mv -f stealth_template.ps $RCFILE";
100 return 1
101 fi
102
103 fi
104
[1]105 rm -f ./.samhain_file
106 rm -f ./.samhain_log
107 rm -f ./.samhain_lock
108
[19]109 ./samhain -t init -p none -l info
[1]110
111 if test x$? = x0; then
[19]112 [ -z "$verbose" ] || log_msg_ok "init...";
113 else
114 [ -z "$quiet" ] && log_msg_fail "init...";
115 return 1
116 fi
[1]117
[19]118 mv $PW_DIR/.samhain_file.asc $PW_DIR/.samhain_file
119}
[1]120
[19]121do_test_1b () {
122
123 ./samhain -t check -p none -l info
124
125 if test x$? = x0; then
126 ./samhain -j -L $LOGFILE >"${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "${LOGFILE}"
127 if [ $? -ne 0 ]; then
128 [ -z "$quiet" ] && log_msg_fail "mv logfile...";
129 return 1
[1]130 fi
[19]131 [ -z "$verbose" ] || log_msg_ok "check...";
132 else
133 [ -z "$quiet" ] && log_msg_fail "check...";
134 return 1
135 fi
136 #
137 tmp=`egrep "Checking.*/etc(>|\")" $LOGFILE 2>/dev/null | wc -l`
138 if [ $tmp -ne 2 ]; then
139 [ -z "$verbose" ] || log_msg_fail "/etc";
140 fi
141 tmp=`egrep "Checking.*(>|\")" $LOGFILE 2>/dev/null | wc -l`
142 if [ $tmp -ne 2 ]; then
143 [ -z "$verbose" ] || log_msg_fail "checking";
144 fi
145 #
146 return 0
[1]147}
148
[19]149do_test_1b_2 () {
[1]150
[19]151 rm -f $PW_DIR/test_log_prelude
[1]152
[20]153 "$PM" --textmod -l $PW_DIR/test_log_prelude --listen 127.0.0.1:5500 >/dev/null 2>&1 &
[19]154 PID=$!
[1]155
[51]156 five_sec_sleep
[20]157
158 ./samhain -t check -p none -l info --set-prelude-severity=info --prelude --server-addr 127.0.0.1:5500 >/dev/null
[19]159
160 if test x$? = x0; then
161 ./samhain -j -L $LOGFILE >"${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "${LOGFILE}"
162 if [ $? -ne 0 ]; then
163 [ -z "$quiet" ] && log_msg_fail "mv logfile...";
164 kill $PID
165 return 1
166 fi
167 [ -z "$verbose" ] || log_msg_ok "check...";
168 else
169 [ -z "$quiet" ] && log_msg_fail "check...";
170 kill $PID
171 return 1
172 fi
173 #
174 tmp=`egrep 'File original:.*name=etc.*path=/etc' test_log_prelude 2>/dev/null | wc -l`
175 if [ $tmp -ne 1 ]; then
176 [ -z "$verbose" ] || log_msg_fail "/etc";
177 fi
178 tmp=`egrep 'Classification text: Checking' test_log_prelude 2>/dev/null | wc -l`
179 if [ $tmp -ne 1 ]; then
180 [ -z "$verbose" ] || log_msg_fail "checking";
181 fi
182 tmp=`egrep 'Classification text: Checking' test_log_prelude 2>/dev/null | wc -l`
183 if [ $tmp -ne 1 ]; then
184 [ -z "$verbose" ] || log_msg_fail "checking";
185 fi
186 #
187 kill $PID
188 return 0
189}
[1]190
[19]191testrun1b ()
192{
193 log_start "RUN STANDALONE W/STEALTH W/GPG"
194 GPG=`find_path gpg`
195 if [ -z "$GPG" ]; then
196 log_skip 1 $MAXTEST 'gpg not found in $PATH'
197 log_skip 2 $MAXTEST 'gpg not found in $PATH'
198 else
199 eval "$GPG" --list-keys 0F571F6C >/dev/null 2>/dev/null
200 if [ $? -ne 0 ]; then
201 log_skip 1 $MAXTEST 'public PGP key 0x0F571F6C not present'
202 log_skip 2 $MAXTEST 'public PGP key 0x0F571F6C not present'
203 else
[52]204 #
205 # ------------- first test -------------
206 #
[19]207 BUILDOPTS="--quiet $TRUST --enable-debug --with-gpg=${GPG} --with-checksum=no --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]208 testrun1b_internal "${BUILDOPTS}"
[19]209 do_test_1b
210 if [ $? -eq 0 ]; then
211 log_ok 1 $MAXTEST 'gpg signed config/database files'
212 else
213 log_fail 1 $MAXTEST 'gpg signed config/database files'
214 fi
[52]215
216
217 #
218 # ------------- second test -------------
219 #
220 PRECONV=`find_path convert`
221 "${PRECONV}" --help | grep ImageMagick >/dev/null 2>&1 && \
222 CONVERT="${PRECONV}"
223
224 if [ -z "$CONVERT" ]; then
225 log_skip 2 $MAXTEST 'ImageMagick convert not found in $PATH'
226 else
227 BUILDOPTS="--quiet $TRUST --enable-debug --with-gpg=${GPG} --with-checksum=no --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"
228 testrun1b_internal "${BUILDOPTS}" "$CONVERT"
229 do_test_1b
230 if [ $? -eq 0 ]; then
231 log_ok 2 $MAXTEST 'gpg signed config/database files'
232 else
233 log_fail 2 $MAXTEST 'gpg signed config/database files'
234 fi
235 fi
236
237
238 #
239 # ------------- third test -------------
240 #
[19]241 PM=`find_path prelude-manager`
242 if [ -z "$PM" ]; then
[52]243 log_skip 3 $MAXTEST 'prelude-manager not found in $PATH'
[19]244 elif [ -z "$doall" ]; then
[52]245 log_skip 3 $MAXTEST 'logging to prelude (or use --really-all)'
[19]246 else
247 BUILDOPTS="--quiet $TRUST --enable-debug --with-prelude --with-gpg=${GPG} --with-checksum=no --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]248 testrun1b_internal "${BUILDOPTS} CFLAGS=-DSH_NOFAILOVER=1"
[19]249 do_test_1b_2
250 if [ $? -eq 0 ]; then
[52]251 log_ok 3 $MAXTEST 'logging to prelude'
[19]252 else
[52]253 log_fail 3 $MAXTEST 'logging to prelude'
[19]254 fi
255 fi
256 fi
257 fi
258 log_end "RUN STANDALONE W/STEALTH W/GPG"
259 return 0
260}
[1]261
Note: See TracBrowser for help on using the repository browser.