source: trunk/test/testrun_1e.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.

  • Property svn:executable set to *
File size: 8.8 KB
RevLine 
[67]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
[295]22BUILDOPTS="--quiet $TRUST --enable-debug=gdb --enable-xml-log --enable-port-check --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$LOGFILE --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
[67]23export BUILDOPTS
24
[206]25MAXTEST=5; export MAXTEST
[67]26
[562]27test_log_prelude="/var/log/prelude/prelude-text.log"; export test_log_prelude
28
[206]29PORTPOLICY_5="
30[ReadOnly]
31file=${BASE}
32[PortCheck]
33PortCheckActive = yes
34PortCheckUDP = no
35PortCheckInterface = 127.0.0.1
36"
37
38chk_portdata_5 () {
39 one_sec_sleep
40
41 if [ -z "$PM" ]; then
42 log_skip 5 $MAXTEST 'prelude-manager not found in $PATH'
43 elif [ -z "$doall" ]; then
44 log_skip 5 $MAXTEST 'logging to prelude (or use --really-all)'
45 else
[562]46 tmp=`egrep 'Service: port=5500 .unknown. protocol=tcp' ${test_log_prelude} 2>/dev/null | wc -l`
[206]47 if [ $tmp -lt 1 ]; then
48 [ -z "$verbose" ] || log_msg_fail "port 5500";
49 [ -z "$quiet" ] && log_fail 5 ${MAXTEST};
50 return 1
51 fi
52 #
53 [ -z "$quiet" ] && log_ok 5 ${MAXTEST};
54 fi
55 return 0
56}
57
58refine_portpolicy_5 ()
59{
60 echo "PortCheckIgnore=2026/tcp" >>"${RCFILE}"
61 echo "PortCheckIgnore=2027/udp" >>"${RCFILE}"
62 echo "PortCheckIgnore=2028/tcp" >>"${RCFILE}"
63 echo "PortCheckIgnore=2029/udp" >>"${RCFILE}"
64}
65
[149]66PORTPOLICY_4="
67[ReadOnly]
68file=${BASE}
69[PortCheck]
70PortCheckActive = yes
71PortCheckUDP = no
72"
73
74chk_portdata_4 () {
75 one_sec_sleep
76
77 egrep 'CRIT.*POLICY \[ServiceNew\]' $LOGFILE >/dev/null 2>&1
78 if [ $? -eq 0 ]; then
[468]79 [ -z "$verbose" ] || egrep 'CRIT.*POLICY \[ServiceNew\]' $LOGFILE
[149]80 [ -z "$verbose" ] || log_msg_fail "Open ports";
81 return 1
82 fi
83}
84
85refine_portpolicy_4 ()
86{
[179]87 cat "$LOGFILE" | grep ServiceNew | sed 's/.*port: //' | awk '{ print $1 }' | \
[149]88 while read line; do
89 echo "PortCheckSkip=$line" >>"${RCFILE}"
90 done
91 echo "PortCheckIgnore=2026/tcp" >>"${RCFILE}"
92 echo "PortCheckIgnore=2027/udp" >>"${RCFILE}"
93 echo "PortCheckIgnore=2028/tcp" >>"${RCFILE}"
94 echo "PortCheckIgnore=2029/udp" >>"${RCFILE}"
95}
96
[128]97PORTPOLICY_3="
98[ReadOnly]
99file=${BASE}
100[PortCheck]
101PortCheckActive = yes
102PortCheckUDP = no
103"
104
105chk_portdata_3 () {
106 one_sec_sleep
107
108 egrep 'CRIT.*POLICY \[ServiceNew\]' $LOGFILE >/dev/null 2>&1
109 if [ $? -eq 0 ]; then
110
111 [ -z "$verbose" ] || log_msg_fail "Open ports";
112 return 1
113 fi
114}
115
116refine_portpolicy_3 ()
117{
[179]118 cat "$LOGFILE" | grep ServiceNew | sed 's/.*port: //' | awk '{ print $1 }' | \
[128]119 while read line; do
120 echo "PortCheckIgnore=$line" >>"${RCFILE}"
121 done
[149]122 echo "PortCheckIgnore=2026/tcp" >>"${RCFILE}"
123 echo "PortCheckIgnore=2027/udp" >>"${RCFILE}"
124 echo "PortCheckIgnore=2028/tcp" >>"${RCFILE}"
125 echo "PortCheckIgnore=2029/udp" >>"${RCFILE}"
[128]126}
127
128
[67]129PORTPOLICY_2="
130[ReadOnly]
131file=${BASE}
132[PortCheck]
133PortCheckActive = yes
134PortCheckUDP = no
135"
136
137chk_portdata_2 () {
138 one_sec_sleep
139
140 egrep 'CRIT.*POLICY \[ServiceNew\]' $LOGFILE >/dev/null 2>&1
141 if [ $? -eq 0 ]; then
142
143 [ -z "$verbose" ] || log_msg_fail "Open ports";
144 return 1
145 fi
146}
147
148refine_portpolicy_2 ()
149{
[179]150 cat "$LOGFILE" | grep ServiceNew | sed 's/.*port: //' | awk '{ print $1 }' | \
[67]151 while read line; do
152 echo "PortCheckOptional=$line" >>"${RCFILE}"
153 done
154}
155
156PORTPOLICY_1="
157[ReadOnly]
158file=${BASE}
159[PortCheck]
160PortCheckActive = yes
161PortCheckUDP = no
162"
163
164chk_portdata_1 () {
165 one_sec_sleep
166
167 egrep 'CRIT.*POLICY \[ServiceNew\]' $LOGFILE >/dev/null 2>&1
168 if [ $? -eq 0 ]; then
169
170 [ -z "$verbose" ] || log_msg_fail "Open ports";
171 return 1
172 fi
173}
174
175refine_portpolicy_1 ()
176{
[179]177 cat "$LOGFILE" | grep ServiceNew | sed 's/.*port: //' | awk '{ print $1 }' | \
[67]178 while read line; do
179 echo "PortCheckRequired=$line" >>"${RCFILE}"
180 done
181}
182
183prep_portpolicy ()
184{
185 test -f "${RCFILE}" || touch "${RCFILE}"
186 eval echo '"$'"PORTPOLICY_$1"'"' >>"${RCFILE}"
187}
188
[206]189run_check_prelude()
190{
[562]191 echo -n >"${test_log_prelude}"
192
[206]193 ./samhain -t check -p none -l info --set-prelude-severity=info --prelude --server-addr 127.0.0.1:5500 >/dev/null
194
195 if test x$? = x0; then
196
197 ./samhain -j -L $LOGFILE >"${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "${LOGFILE}"
198
199 if [ $? -ne 0 ]; then
200 [ -z "$quiet" ] && log_msg_fail "mv logfile...";
201 return 1
202 fi
203 [ -z "$verbose" ] || log_msg_ok "check...";
204 else
205 [ -z "$quiet" ] && log_msg_fail "check...";
206 return 1
207 fi
208}
209
210
[67]211testrun_internal_1e ()
212{
213 [ -z "$verbose" ] || echo Working directory: $PW_DIR
214 [ -z "$verbose" ] || { echo MAKE is $MAKE; echo; }
215
216 #
217 # test standalone compilation
218 #
219 [ -z "$verbose" ] || { echo; echo "${S}Building standalone agent${E}"; echo; }
220
221 if test -r "Makefile"; then
222 $MAKE distclean >/dev/null
223 fi
224
225 tcount=1
226 ${TOP_SRCDIR}/configure ${BUILDOPTS}
227
228 #
229 if test x$? = x0; then
230 [ -z "$verbose" ] || log_msg_ok "configure...";
231 $MAKE >/dev/null 2>&1
232 if test x$? = x0; then
233 [ -z "$verbose" ] || log_msg_ok "make...";
234 else
235 [ -z "$quiet" ] && log_msg_fail "make...";
236 return 1
237 fi
238
239 else
240 [ -z "$quiet" ] && log_msg_fail "configure...";
241 return 1
242 fi
243
244 [ -z "$verbose" ] || { echo; echo "${S}Running test suite${E}"; echo; }
245
246 POLICY=`eval echo '"$'"PORTPOLICY_$tcount"'"'`
247
248 until [ -z "$POLICY" ]
249 do
250 prep_init
251 check_err $? ${tcount}; errval=$?
252 if [ $errval -eq 0 ]; then
253 prep_testdata
254 check_err $? ${tcount}; errval=$?
255 fi
256 if [ $errval -eq 0 ]; then
257 prep_portpolicy ${tcount}
258 check_err $? ${tcount}; errval=$?
259 fi
260 if [ $errval -eq 0 ]; then
261 run_init
262 check_err $? ${tcount}; errval=$?
263 fi
264 #
265 if [ $errval -eq 0 ]; then
266 eval refine_portpolicy_${tcount}
267 check_err $? ${tcount}; errval=$?
268 fi
269 #
270 rm -f "$LOGFILE"
271 #
[206]272 PRELUDEPID=0
273 #
274 if test ${tcount} -eq 5;
275 then
276
277 PM=`find_path prelude-manager`
278
279 if [ -z "$PM" ]; then
280 if [ $errval -eq 0 ]; then
281 run_check
282 check_err $? ${tcount}; errval=$?
283 fi
284 elif [ -z "$doall" ]; then
285 if [ $errval -eq 0 ]; then
286 run_check
287 check_err $? ${tcount}; errval=$?
288 fi
289 else
290 #
291 #
292 ${TOP_SRCDIR}/configure ${BUILDOPTS} --with-prelude
293 #
294 #
295 if test x$? = x0; then
296 [ -z "$verbose" ] || log_msg_ok "configure...";
297 $MAKE >/dev/null 2>&1
298 if test x$? = x0; then
299 [ -z "$verbose" ] || log_msg_ok "make...";
300 else
301 [ -z "$quiet" ] && log_msg_fail "make...";
302 return 1
303 fi
304
305 else
306 [ -z "$quiet" ] && log_msg_fail "configure...";
307 return 1
308 fi
309 #
310 #
311 if ! test -d /var/run/prelude-manager
312 then
313 [ -z "$verbose" ] || log_msg_ok "create /var/run/prelude-manager...";
314 sudo mkdir /var/run/prelude-manager
315 sudo chown prelude:rainer /var/run/prelude-manager
316 sudo chmod 770 /var/run/prelude-manager
317 fi
318 if ! test -d /var/spool/prelude/samhain/global
319 then
320 [ -z "$verbose" ] || log_msg_ok "create /var/spool/prelude/samhain/global...";
321 sudo mkdir -p /var/spool/prelude/samhain/global
322 sudo chown prelude:rainer /var/spool/prelude/samhain/global
323 sudo chmod 770 /var/spool/prelude/samhain/global
324 fi
325
326 #
327 #
[562]328 #[ -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 &)"; }
329 #"$PM" --textmod -l $PW_DIR/test_log_prelude --listen 127.0.0.1:5500 >/dev/null 2>&1 &
330 #PRELUDEPID=$!
[206]331 #
332 #
333 five_sec_sleep
334 #
335 #
336 if [ $errval -eq 0 ]; then
337 run_check_prelude
338 check_err $? ${tcount}; errval=$?
339 fi
340 fi
341
342 else
343 if [ $errval -eq 0 ]; then
344 run_check
345 check_err $? ${tcount}; errval=$?
346 fi
[67]347 fi
[206]348 #
[67]349 if [ $errval -eq 0 ]; then
350 eval chk_portdata_${tcount}
351 check_err $? ${tcount}; errval=$?
352 fi
353 #
354 if [ $errval -eq 0 ]; then
[206]355 if test ${tcount} -ne 5; then
356 [ -z "$quiet" ] && log_ok ${tcount} ${MAXTEST};
357 fi
[67]358 fi
359 let "tcount = tcount + 1" >/dev/null
360 POLICY=`eval echo '"$'"PORTPOLICY_$tcount"'"'`
[206]361
362 if test $PRELUDEPID -ne 0;
363 then
364 kill $PRELUDEPID
365 fi
366
[67]367 done
368
369 return 0
370}
371
372testrun1e ()
373{
374 log_start "RUN STANDALONE W/PORTCHECK"
375 testrun_internal_1e
376 log_end "RUN STANDALONE W/PORTCHECK"
377 return 0
378}
379
380
Note: See TracBrowser for help on using the repository browser.