source: trunk/test/testrun_2c.sh@ 298

Last change on this file since 298 was 286, checked in by katerina, 15 years ago

Fix for ticket #211 (samhain_kmem compile problems) and ticket #210 (line length, filename quoting in config file).

File size: 11.9 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#
21LOGFILE="$PW_DIR/.samhain_log"; export LOGFILE
22RCFILE="$PW_DIR/testrc_2"; export RCFILE
23HTML="$PW_DIR/yule.html"; export HTML
24
25SERVER_BUILDOPTS="--quiet $TRUST --enable-xml-log --enable-debug --enable-network=server --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=REQ_FROM_SERVER$PW_DIR/testrc_2 --with-data-file=REQ_FROM_SERVER$PW_DIR/.samhain_file --with-logserver=${SH_LOCALHOST} --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-database=mysql"; export SERVER_BUILDOPTS
26
27CLIENT_BUILDOPTS="--quiet $TRUST --prefix=$PW_DIR --with-tmp-dir=$PW_DIR --localstatedir=$PW_DIR --enable-network=client --disable-mail --disable-external-scripts --enable-login-watch --enable-xml-log --enable-db-reload --with-logserver=localhost --with-config-file=REQ_FROM_SERVER$PW_DIR/testrc_2 --with-data-file=REQ_FROM_SERVER$PW_DIR/.samhain_file --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock"; export CLIENT_BUILDOPTS
28
29MAXTEST=4; export MAXTEST
30
31do_test_1_c () {
32
33 [ -z "$verbose" ] || {
34 echo;
35 echo "${S}Start Server${E}: ./yule -l info -p none &";
36 echo;
37 }
38
39 rm -f test_log_valgrind
40
41 ${VALGRIND} ./yule.2 -q -l info -p none >/dev/null 2>>test_log_valgrind &
42 PROC_Y2=$!
43 five_sec_sleep
44
45 [ -z "$verbose" ] || {
46 echo;
47 echo "${S}Start Server #2${E}: ./yule.2 -l info -p none &";
48 echo;
49 }
50
51 ${VALGRIND} ./yule -l info -p none -e info --bind-address=127.0.0.1 \
52 --server-port=49778 >/dev/null 2>>test_log_valgrind &
53 PROC_Y=$!
54 five_sec_sleep
55
56 [ -z "$verbose" ] || {
57 echo;
58 echo "${S}Start Client${E}: ./samhain.new -l none -p none -e info -t check";
59 echo;
60 }
61
62 ${VALGRIND} ./samhain.new -t check -p none -l none -e info --bind-address=127.0.0.1 >/dev/null 2>>test_log_valgrind
63 if test x$? = x0; then
64 [ -z "$verbose" ] || log_msg_ok "samhain.new -t check";
65 else
66 [ -z "$quiet" ] && log_msg_fail "samhain.new -t check";
67 kill $PROC_Y
68 kill $PROC_Y2
69 return 1
70 fi
71
72 kill $PROC_Y
73 kill $PROC_Y2
74 five_sec_sleep
75
76 # cp ${LOGFILE} triple_test
77 # cp ${LOGFILE}2 triple_test_2
78
79 egrep "START(>|\").*Yule(>|\")" ${LOGFILE}2 >/dev/null 2>&1
80 if [ $? -ne 0 ]; then
81 [ -z "$verbose" ] || log_msg_fail "Server #2 start";
82 return 1
83 fi
84 egrep "remote_host.*Checking.*/bin" ${LOGFILE}2 >/dev/null 2>&1
85 if [ $? -ne 0 ]; then
86 [ -z "$verbose" ] || log_msg_fail "Client file check (relayed)";
87 return 1
88 fi
89 egrep "remote_host.*EXIT.*Samhain" ${LOGFILE}2 >/dev/null 2>&1
90 if [ $? -ne 0 ]; then
91 [ -z "$verbose" ] || log_msg_fail "Client exit (relayed)";
92 return 1
93 fi
94 egrep "EXIT.*Yule.*SIGTERM" ${LOGFILE}2 >/dev/null 2>&1
95 if [ $? -ne 0 ]; then
96 [ -z "$verbose" ] || log_msg_fail "Server #2 exit";
97 return 1
98 fi
99
100
101 egrep "START(>|\").*Yule(>|\")" $LOGFILE >/dev/null 2>&1
102 if [ $? -ne 0 ]; then
103 [ -z "$verbose" ] || log_msg_fail "Server start";
104 return 1
105 fi
106 egrep "NEW CLIENT" $LOGFILE >/dev/null 2>&1
107 if [ $? -ne 0 ]; then
108 [ -z "$verbose" ] || log_msg_fail "Client connect";
109 return 1
110 fi
111 egrep "remote_host.*Checking.*/bin" $LOGFILE >/dev/null 2>&1
112 if [ $? -ne 0 ]; then
113 [ -z "$verbose" ] || log_msg_fail "Client file check";
114 return 1
115 fi
116 egrep "remote_host.*EXIT.*Samhain" $LOGFILE >/dev/null 2>&1
117 if [ $? -ne 0 ]; then
118 [ -z "$verbose" ] || log_msg_fail "Client exit";
119 return 1
120 fi
121 egrep "EXIT.*Yule.*SIGTERM" $LOGFILE >/dev/null 2>&1
122 if [ $? -ne 0 ]; then
123 [ -z "$verbose" ] || log_msg_fail "Server exit";
124 return 1
125 fi
126
127 [ -z "$VALGRIND" ] || {
128 tmp=`cat test_log_valgrind 2>/dev/null | wc -l`;
129 if [ $tmp -ne 0 ]; then
130 [ -z "$verbose" ] || log_msg_fail "valgrind reports errors";
131 cat test_log_valgrind
132 return 1;
133 fi;
134 }
135
136 return 0
137}
138
139testrun_threesockets () {
140
141 GPG="$1"
142
143 [ -z "$verbose" ] || {
144 echo;
145 echo Working directory: $PW_DIR; echo MAKE is $MAKE; echo GPG is $GPG;
146 echo;
147 }
148
149 [ -z "$verbose" ] || { echo; echo "${S}Building client and server${E}"; echo; }
150
151 if test -r "Makefile"; then
152 $MAKE distclean
153 fi
154
155 ${TOP_SRCDIR}/configure --with-gpg=${GPG} --with-fp=EF6CEF54701A0AFDB86AF4C31AAD26C80F571F6C --with-checksum=no ${SERVER_BUILDOPTS} >/dev/null 2>&1
156
157 if test x$? = x0; then
158 [ -z "$verbose" ] || log_msg_ok "configure...";
159 $MAKE > /dev/null 2>>test_log
160 if test x$? = x0; then
161 [ -z "$verbose" ] || log_msg_ok "make...";
162 else
163 [ -z "$quiet" ] && log_msg_fail "make...";
164 return 1
165 fi
166 else
167 [ -z "$quiet" ] && log_msg_fail "configure...";
168 return 1
169 fi
170
171 rm -f ./.samhain_file
172 rm -f ./.samhain_log
173 rm -f ./.samhain_lock
174 rm -f ./rc.${SH_LOCALHOST}
175 rm -f ./file.${SH_LOCALHOST}
176
177 cp ${SCRIPTDIR}/testrc_2.in testrc_2
178
179 ORIGINAL="DatabaseSeverity=none"
180 REPLACEMENT="DatabaseSeverity=warn"
181 ex -s $RCFILE <<EOF
182%s/$ORIGINAL/$REPLACEMENT/g
183wq
184EOF
185
186 ORIGINAL="MailSeverity=none"
187 REPLACEMENT="MailSeverity=crit"
188 ex -s $RCFILE <<EOF
189%s/$ORIGINAL/$REPLACEMENT/g
190wq
191EOF
192 return 0
193 }
194
195check_mysql_log () {
196 DATE="$1"
197
198 rm -f test_log_db
199 #
200 echo "SELECT * FROM log WHERE entry_status = 'NEW' and log_time > '"${DATE}"';" | mysql --password=samhain -u samhain samhain >test_log_db
201 #
202 egrep "START.*Yule" test_log_db >/dev/null 2>&1
203 if [ $? -ne 0 ]; then
204 [ -z "$verbose" ] || log_msg_fail "Server start";
205 return 1
206 fi
207 egrep "NEW CLIENT" test_log_db >/dev/null 2>&1
208 if [ $? -ne 0 ]; then
209 [ -z "$verbose" ] || log_msg_fail "Client connect";
210 return 1
211 fi
212 egrep "Checking.*/bin" test_log_db >/dev/null 2>&1
213 if [ $? -ne 0 ]; then
214 [ -z "$verbose" ] || log_msg_fail "Client file check";
215 return 1
216 fi
217 egrep "EXIT.*Samhain" test_log_db >/dev/null 2>&1
218 if [ $? -ne 0 ]; then
219 [ -z "$verbose" ] || log_msg_fail "Client exit";
220 return 1
221 fi
222 egrep "EXIT.*Yule.*SIGTERM" test_log_db >/dev/null 2>&1
223 if [ $? -ne 0 ]; then
224 [ -z "$verbose" ] || log_msg_fail "Server exit";
225 return 1
226 fi
227 return 0
228}
229
230testrun2c ()
231{
232 log_start "RUN FULL CLIENT/SERVER W/MYSQL"
233 #
234 if [ -z "$doall" ]; then
235 log_skip 1 $MAXTEST 'Client/server w/mysql (or use --really-all)'
236 log_skip 2 $MAXTEST 'Client/server w/mysql (or use --really-all)'
237 log_skip 3 $MAXTEST 'Client/server w/mysql (or use --really-all)'
238 return 0
239 fi
240 if [ x"$1" = x ]; then
241 [ -z "$quiet" ] && log_msg_fail "Missing hostname"
242 fi
243 MYSQL=`find_path mysql`
244 if [ -z "$MYSQL" ]; then
245 log_skip 1 $MAXTEST "mysql not found";
246 log_skip 2 $MAXTEST "mysql not found";
247 log_skip 3 $MAXTEST "mysql not found";
248 return 1
249 else
250 TEST=`echo "DESCRIBE log;" | mysql --password=samhain -u samhain samhain 2>/dev/null`
251 if [ $? -ne 0 -o -z "$TEST" ]; then
252 log_skip 1 $MAXTEST "mysql not default setup"
253 log_skip 2 $MAXTEST "mysql not default setup"
254 log_skip 3 $MAXTEST "mysql not default setup"
255 return 1
256 fi
257 fi
258 #
259 SH_LOCALHOST=$1; export SH_LOCALHOST
260 #
261 DATE=`date '+%Y-%m-%d %T'`
262 #
263 testrun2a_internal
264 #
265 # BUILD Server 2
266 #
267 cp ./yule ./yule.orig
268
269 ${TOP_SRCDIR}/configure --quiet $TRUST --enable-debug --enable-network=server --enable-xml-log --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=${RCFILE}2 --with-log-file=${LOGFILE}2 --with-pid-file=$PW_DIR/.samhain_lock2 --with-html-file=${HTML}2 --with-state-dir=$PW_DIR --with-port=49778 --with-database=mysql
270 #
271 if test x$? = x0; then
272 [ -z "$verbose" ] || log_msg_ok "configure...";
273 $MAKE > /dev/null 2>>test_log
274 if test x$? = x0; then
275 [ -z "$verbose" ] || log_msg_ok "make...";
276 else
277 [ -z "$quiet" ] && log_msg_fail "make...";
278 return 1
279 fi
280
281 else
282 [ -z "$quiet" ] && log_msg_fail "configure...";
283 return 1
284 fi
285
286 cp yule yule.2 || return 1
287 #
288 cp ./yule.orig ./yule
289 #
290 SHPW=`cat ./testpw`
291
292 if test x"$SHPW" = x; then
293 [ -z "$quiet" ] && log_msg_fail "password not generated -- aborting"
294 return 1
295 fi
296
297 rm -f ./testpw
298
299 ./samhain_setpwd yule new $SHPW >/dev/null
300
301 if test x$? = x0; then
302 [ -z "$verbose" ] || log_msg_ok "./samhain_setpwd yule new $SHPW";
303 else
304 [ -z "$quiet" ] && log_msg_fail "./samhain_setpwd yule new $SHPW";
305 return 1
306 fi
307
308
309 $MAKE clean >/dev/null || return 1
310 mv yule.new yule || return 1
311 #
312 ORIGINAL="DatabaseSeverity=none"
313 REPLACEMENT="DatabaseSeverity=info"
314 ex -s $RCFILE <<EOF
315%s/$ORIGINAL/$REPLACEMENT/g
316wq
317EOF
318 #
319 do_test_1_a
320 #
321 if [ $? -ne 0 ]; then
322 [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Client/server w/mysql";
323 else
324 #
325 check_mysql_log "${DATE}"
326 if [ $? -ne 0 ]; then
327 [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Client/server w/mysql";
328 else
329 [ -z "$quiet" ] && log_ok 1 ${MAXTEST} "Client/server w/mysql";
330 fi
331 fi
332 #
333 cp testrc_2 testrc_22
334 ORIGINAL="DatabaseSeverity=none"
335 REPLACEMENT="DatabaseSeverity=info"
336 ex -s $RCFILE <<EOF
337%s/$REPLACEMENT/$ORIGINAL/g
338wq
339EOF
340 #
341 do_test_1_c
342 #
343 if [ $? -ne 0 ]; then
344 [ -z "$quiet" ] && log_fail 2 ${MAXTEST} "Client/server (relay) w/mysql";
345 else
346 #
347 check_mysql_log "${DATE}"
348 if [ $? -ne 0 ]; then
349 [ -z "$quiet" ] && log_fail 2 ${MAXTEST} "Client/server (relay) w/mysql";
350 else
351 [ -z "$quiet" ] && log_ok 2 ${MAXTEST} "Client/server (relay) w/mysql";
352 fi
353 fi
354 #
355 #
356 if [ -f ./yule ]; then
357 ./yule -p info -l info --set-database-severity=info -D >/dev/null 2>>test_log
358 five_sec_sleep
359 netstat -pant 2>/dev/null | grep 49777 | grep yule >/dev/null 2>&1
360 if [ $? -ne 0 ]; then
361 [ -z "$quiet" ] && log_fail 3 ${MAXTEST} "Client/server w/mysql";
362 else
363 NSOCK=`netstat -pand 2>/dev/null | grep STREAM | grep yule | wc -l`
364 if [ $NSOCK -ne 2 ]; then
365 [ -z "$quiet" ] && log_fail 3 ${MAXTEST} "Three sockets open";
366 netstat -pand 2>/dev/null | grep yule
367 else
368 [ -z "$quiet" ] && log_ok 3 ${MAXTEST} "Three sockets open";
369 fi
370 fi
371 PID=`cat .samhain_lock`
372 kill $PID
373 else
374 log_fail 3 ${MAXTEST} "Three sockets open";
375 fi
376 #
377 GPG=`find_path gpg`
378 if [ -z "$GPG" ]; then
379 log_skip 4 $MAXTEST 'gpg not found in $PATH'
380 else
381 eval "$GPG" --list-keys 0F571F6C >/dev/null 2>/dev/null
382 if [ $? -ne 0 ]; then
383 log_skip 4 $MAXTEST 'public PGP key 0x0F571F6C not present'
384 else
385 testrun_threesockets "$GPG"
386
387 if [ -f ./yule ]; then
388 ./yule -D >/dev/null 2>>test_log
389 five_sec_sleep
390 netstat -pant 2>/dev/null | grep 49777 | grep yule >/dev/null 2>&1
391 if [ $? -ne 0 ]; then
392 [ -z "$quiet" ] && log_fail 4 ${MAXTEST} "Three sockets open (gpg)";
393 else
394 NSOCK=`netstat -pand 2>/dev/null | grep STREAM | grep yule | wc -l`
395 if [ $NSOCK -ne 2 ]; then
396 [ -z "$quiet" ] && log_fail 4 ${MAXTEST} "Three sockets open (gpg)";
397 netstat -pand 2>/dev/null | grep yule
398 else
399 [ -z "$quiet" ] && log_ok 4 ${MAXTEST} "Three sockets open (gpg)";
400 fi
401 fi
402 PID=`cat .samhain_lock`
403 kill $PID
404 else
405 log_fail 4 ${MAXTEST} "Three sockets open (gpg)";
406 fi
407 fi
408 fi
409 #
410 if [ -n "$cleanup" ]; then
411 rm -f ./rc.${SH_LOCALHOST}
412 rm -f ./file.${SH_LOCALHOST}
413 ALTHOST=`find_hostname`
414 rm -f "./file.${ALTHOST}"
415 rm -f "./rc.${ALTHOST}"
416 fi
417 #
418 log_end "RUN FULL CLIENT/SERVER W/MYSQL"
419}
420
Note: See TracBrowser for help on using the repository browser.