source: trunk/test/testrun_1b.sh@ 163

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

Add gpg fingerprint test to testsuite.

File size: 10.1 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=5; 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 log_skip 4 $MAXTEST 'public PGP key 0x0F571F6C not present'
232 log_skip 5 $MAXTEST 'public PGP key 0x0F571F6C not present'
233 else
234 #
235 # ------------- first test -------------
236 #
237 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"
238 testrun1b_internal "${BUILDOPTS}"
239 do_test_1b
240 if [ $? -eq 0 ]; then
241 log_ok 1 $MAXTEST 'gpg signed config/database files'
242 else
243 log_fail 1 $MAXTEST 'gpg signed config/database files'
244 fi
245
246
247 #
248 # ------------- second test -------------
249 #
250 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"
251 testrun1b_internal "${BUILDOPTS}"
252 do_test_1b
253 if [ $? -eq 0 ]; then
254 log_ok 2 $MAXTEST 'gpg signed config/database files'
255 else
256 log_fail 2 $MAXTEST 'gpg signed config/database files'
257 fi
258
259
260 #
261 # ------------- third test -------------
262 #
263 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"
264 testrun1b_internal "${BUILDOPTS}"
265 do_test_1b
266 if [ $? -eq 0 ]; then
267 log_ok 3 $MAXTEST 'gpg signed config/database files'
268 else
269 log_fail 3 $MAXTEST 'gpg signed config/database files'
270 fi
271
272
273 #
274 # ------------- fourth test -------------
275 #
276 PRECONV=`find_path convert`
277 "${PRECONV}" --help | grep ImageMagick >/dev/null 2>&1 && \
278 CONVERT="${PRECONV}"
279
280 if [ -z "$CONVERT" ]; then
281 log_skip 2 $MAXTEST 'ImageMagick convert not found in $PATH'
282 else
283 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"
284 testrun1b_internal "${BUILDOPTS}" "$CONVERT"
285 do_test_1b
286 if [ $? -eq 0 ]; then
287 log_ok 4 $MAXTEST 'gpg signed config/database files'
288 else
289 log_fail 4 $MAXTEST 'gpg signed config/database files'
290 fi
291 fi
292
293
294 #
295 # ------------- fifth test -------------
296 #
297 if test -f /usr/local/lib/libprelude.so
298 then
299 LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
300 export LD_LIBRARY_PATH
301 fi
302 #
303 PM=`find_path prelude-manager`
304 if [ -z "$PM" ]; then
305 log_skip 5 $MAXTEST 'prelude-manager not found in $PATH'
306 elif [ -z "$doall" ]; then
307 log_skip 5 $MAXTEST 'logging to prelude (or use --really-all)'
308 else
309 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"
310 testrun1b_internal "${BUILDOPTS} CFLAGS=-DSH_NOFAILOVER=1"
311 do_test_1b_2
312 if [ $? -eq 0 ]; then
313 log_ok 5 $MAXTEST 'logging to prelude'
314 else
315 log_fail 5 $MAXTEST 'logging to prelude'
316 fi
317 fi
318 fi
319 fi
320 log_end "RUN STANDALONE W/STEALTH W/GPG"
321 return 0
322}
323
Note: See TracBrowser for help on using the repository browser.