source: trunk/test/testrun_1b.sh@ 160

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

Fix for ticket #87 (option --with-checksum broken).

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
22MAXTEST=3; export MAXTEST
23LOGFILE="$PW_DIR/.samhain_log"; export LOGFILE
24RCFILE="$PW_DIR/testrc_1.dyn"; export RCFILE
25
26testrun1b_internal ()
27{
28 BUILDOPTS="$1"
29 #
30 # test standalone compilation
31 #
32 [ -z "$verbose" ] || { echo; echo "${S}Building standalone agent${E}"; echo; }
33 #
34 if test -r "Makefile"; then
35 $MAKE distclean >/dev/null >&1
36 fi
37 #
38 # Bootstrapping
39 #
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
55 #
56 #
57 ${TOP_SRCDIR}/configure ${BUILDOPTS} 2>/dev/null | \
58 egrep 'use existing [./[:alnum:]]+ for gpg checksum' >/dev/null
59 #
60 #
61 if test x$? = x0; then
62 [ -z "$verbose" ] || log_msg_ok "configure...";
63 $MAKE > /dev/null 2>&1
64 if test x$? = x0; then
65 [ -z "$verbose" ] || log_msg_ok "make...";
66 else
67 [ -z "$quiet" ] && log_msg_fail "make...";
68 return 1
69 fi
70
71 else
72 [ -z "$quiet" ] && log_msg_fail "configure...";
73 return 1
74 fi
75
76 SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' ${SCRIPTDIR}/test.sh`
77
78 tail -n "+$SKIP" ${SCRIPTDIR}/test.sh >/dev/null 2>&1
79 if [ $? -eq 0 ]; then
80 tail -n "+$SKIP" ${SCRIPTDIR}/test.sh | gunzip -c - 2>/dev/null | tar xf - && \
81 mv "./testrc.gpg.asc" "$RCFILE"
82 else
83 tail "+$SKIP" ${SCRIPTDIR}/test.sh | gunzip -c - 2>/dev/null | tar xf - && \
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
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
124 rm -f ./.samhain_file
125 rm -f ./.samhain_log
126 rm -f ./.samhain_lock
127
128 ./samhain -t init -p none -l info
129
130 if test x$? = x0; then
131 [ -z "$verbose" ] || log_msg_ok "init...";
132 else
133 [ -z "$quiet" ] && log_msg_fail "init...";
134 return 1
135 fi
136
137 mv $PW_DIR/.samhain_file.asc $PW_DIR/.samhain_file
138}
139
140do_test_1b () {
141
142 ./samhain -t check -p none -l info
143
144 if test x$? = x0; then
145 ./samhain -j -L $LOGFILE >"${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "${LOGFILE}"
146 if [ $? -ne 0 ]; then
147 [ -z "$quiet" ] && log_msg_fail "mv logfile...";
148 return 1
149 fi
150 [ -z "$verbose" ] || log_msg_ok "check...";
151 else
152 [ -z "$quiet" ] && log_msg_fail "check...";
153 return 1
154 fi
155 #
156 tmp=`egrep "Checking.*/etc(>|\")" $LOGFILE 2>/dev/null | wc -l`
157 if [ $tmp -ne 2 ]; then
158 [ -z "$verbose" ] || log_msg_fail "/etc";
159 return 1
160 fi
161 tmp=`egrep "Checking.*(>|\")" $LOGFILE 2>/dev/null | wc -l`
162 if [ $tmp -ne 8 ]; then
163 [ -z "$verbose" ] || log_msg_fail "checking";
164 return 1
165 fi
166 egrep "ADDED" $LOGFILE >/dev/null 2>&1
167 if [ $? -eq 0 ]; then
168 [ -z "$verbose" ] || log_msg_fail "init was incomplete";
169 return 1
170 fi
171 #
172 return 0
173}
174
175do_test_1b_2 () {
176
177 rm -f $PW_DIR/test_log_prelude
178
179 "$PM" --textmod -l $PW_DIR/test_log_prelude --listen 127.0.0.1:5500 >/dev/null 2>&1 &
180 PID=$!
181
182 five_sec_sleep
183
184 ./samhain -t check -p none -l info --set-prelude-severity=info --prelude --server-addr 127.0.0.1:5500 >/dev/null
185
186 if test x$? = x0; then
187 ./samhain -j -L $LOGFILE >"${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "${LOGFILE}"
188 if [ $? -ne 0 ]; then
189 [ -z "$quiet" ] && log_msg_fail "mv logfile...";
190 kill $PID
191 return 1
192 fi
193 [ -z "$verbose" ] || log_msg_ok "check...";
194 else
195 [ -z "$quiet" ] && log_msg_fail "check...";
196 kill $PID
197 return 1
198 fi
199 #
200 tmp=`egrep 'File original:.*name=etc.*path=/etc' test_log_prelude 2>/dev/null | wc -l`
201 if [ $tmp -lt 1 ]; then
202 [ -z "$verbose" ] || log_msg_fail "/etc";
203 fi
204 tmp=`egrep 'Classification text: Checking' test_log_prelude 2>/dev/null | wc -l`
205 if [ $tmp -lt 1 ]; then
206 [ -z "$verbose" ] || log_msg_fail "checking";
207 fi
208 tmp=`egrep 'Classification text: Checking' test_log_prelude 2>/dev/null | wc -l`
209 if [ $tmp -lt 1 ]; then
210 [ -z "$verbose" ] || log_msg_fail "checking";
211 fi
212 #
213 kill $PID
214 return 0
215}
216
217testrun1b ()
218{
219 log_start "RUN STANDALONE W/STEALTH W/GPG"
220 GPG=`find_path gpg`
221 if [ -z "$GPG" ]; then
222 log_skip 1 $MAXTEST 'gpg not found in $PATH'
223 log_skip 2 $MAXTEST 'gpg not found in $PATH'
224 log_skip 3 $MAXTEST 'gpg not found in $PATH'
225 else
226 eval "$GPG" --list-keys 0F571F6C >/dev/null 2>/dev/null
227 if [ $? -ne 0 ]; then
228 log_skip 1 $MAXTEST 'public PGP key 0x0F571F6C not present'
229 log_skip 2 $MAXTEST 'public PGP key 0x0F571F6C not present'
230 log_skip 3 $MAXTEST 'public PGP key 0x0F571F6C not present'
231 else
232 #
233 # ------------- first test -------------
234 #
235 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"
236 testrun1b_internal "${BUILDOPTS}"
237 do_test_1b
238 if [ $? -eq 0 ]; then
239 log_ok 1 $MAXTEST 'gpg signed config/database files'
240 else
241 log_fail 1 $MAXTEST 'gpg signed config/database files'
242 fi
243
244
245 #
246 # ------------- second test -------------
247 #
248 PRECONV=`find_path convert`
249 "${PRECONV}" --help | grep ImageMagick >/dev/null 2>&1 && \
250 CONVERT="${PRECONV}"
251
252 if [ -z "$CONVERT" ]; then
253 log_skip 2 $MAXTEST 'ImageMagick convert not found in $PATH'
254 else
255 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"
256 testrun1b_internal "${BUILDOPTS}" "$CONVERT"
257 do_test_1b
258 if [ $? -eq 0 ]; then
259 log_ok 2 $MAXTEST 'gpg signed config/database files'
260 else
261 log_fail 2 $MAXTEST 'gpg signed config/database files'
262 fi
263 fi
264
265
266 #
267 # ------------- third test -------------
268 #
269 if test -f /usr/local/lib/libprelude.so
270 then
271 LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
272 export LD_LIBRARY_PATH
273 fi
274 #
275 PM=`find_path prelude-manager`
276 if [ -z "$PM" ]; then
277 log_skip 3 $MAXTEST 'prelude-manager not found in $PATH'
278 elif [ -z "$doall" ]; then
279 log_skip 3 $MAXTEST 'logging to prelude (or use --really-all)'
280 else
281 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"
282 testrun1b_internal "${BUILDOPTS} CFLAGS=-DSH_NOFAILOVER=1"
283 do_test_1b_2
284 if [ $? -eq 0 ]; then
285 log_ok 3 $MAXTEST 'logging to prelude'
286 else
287 log_fail 3 $MAXTEST 'logging to prelude'
288 fi
289 fi
290 fi
291 fi
292 log_end "RUN STANDALONE W/STEALTH W/GPG"
293 return 0
294}
295
Note: See TracBrowser for help on using the repository browser.