source: trunk/test/testext.sh@ 427

Last change on this file since 427 was 235, checked in by katerina, 15 years ago

Fix for potential deadlock when calling external programm (ticket #155).

File size: 4.3 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#
21
[235]22MAXTEST=2; export MAXTEST
[1]23
[19]24testext0 ()
25{
26 COMP=`which gcc`
27 if test "x$?" = x1 ; then
28 COMP="cc"
[1]29 else
[19]30 COMP=`which gcc | sed -e "s%\([a-z:]\) .*%\1%g"`
31 if test "x$COMP" = x; then
[1]32 COMP="cc"
[19]33 elif test "x$COMP" = xno; then
34 COMP="cc"
35 else
36 if test "x$COMP" = "xwhich:"; then
37 COMP="cc"
38 else
[1]39 COMP="gcc"
40 gcc -v >/dev/null 2>&1 || COMP="gcc"
[19]41 fi
42 fi
[1]43 fi
[19]44 log_start "EXTERNAL PROGRAM"
45 [ -z "$verbose" ] || echo MAKE is $MAKE
46 [ -z "$verbose" ] || { echo COMP is $COMP; echo; }
[1]47 #
48 # standalone compilation
49 #
[19]50 [ -z "$verbose" ] || { echo; echo "${S}Building standalone agent${E}"; echo; }
[1]51 #
52 if test -r "Makefile"; then
[19]53 ${MAKE} distclean >/dev/null
[1]54 fi
55 #
[235]56 ${TOP_SRCDIR}/configure --quiet --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$PW_DIR/testrc_1ext --with-log-file=$LOGFILE --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file
[1]57 #
58 if test x$? = x0; then
[19]59 [ -z "$verbose" ] || log_msg_ok "configure...";
[30]60 $MAKE >/dev/null 2>>test_log
[19]61 if test x$? = x0; then
62 [ -z "$verbose" ] || log_msg_ok "make...";
63 else
64 [ -z "$quiet" ] && log_msg_fail "make...";
65 return 1
66 fi
67
[1]68 else
[19]69 [ -z "$quiet" ] && log_msg_fail "configure...";
70 return 1
[1]71 fi
[19]72 #
[1]73 # prepare the program
74 #
75 cat test/test_ext.c.in | sed -e "s%MYPWDIR%$PW_DIR/test_ext.res%g" > test_ext.c
[19]76
[1]77 ${COMP} -o test_ext test_ext.c
78 if test "x$?" != x0; then
[19]79 log_msg_fail "${COMP} -o test_ext test_ext.c"
80 return 1
[1]81 fi
[19]82 chmod +rx test_ext
83 if test "x$?" != x0; then
84 log_msg_fail "chmod +rx test_ext"
85 return 1
86 fi
87
[1]88 # compute checksum and fix config file
89 #
90 cp test/testrc_1ext.in testrc_1ext
91 CHKSUM=`./samhain -H $PW_DIR/test_ext | awk '{ print $2$3$4$5$6$7}'`
92 echo "OpenCommand=$PW_DIR/test_ext" >> testrc_1ext
93 echo "SetType=log" >> testrc_1ext
94 echo "SetChecksum=$CHKSUM" >> testrc_1ext
[202]95 echo "SetEnviron=TZ=Europe/Berlin" >> testrc_1ext
[1]96 echo "SetFilterOr=ALERT" >> testrc_1ext
[164]97 echo "CloseCommand" >> testrc_1ext
98 echo "OpenCommand=$PW_DIR/test_ext" >> testrc_1ext
99 echo "SetType=log" >> testrc_1ext
100 echo "SetChecksum=$CHKSUM" >> testrc_1ext
101 echo "SetFilterOr=ALERT" >> testrc_1ext
[235]102 echo "CloseCommand" >> testrc_1ext
[19]103
[1]104 rm -f $PW_DIR/test_ext.res
105 rm -f $PW_DIR/pdbg.child
106 rm -f $PW_DIR/pdbg.main
[22]107 ./samhain -p none
[19]108
[1]109 # The shell is too fast ...
[51]110 one_sec_sleep
[19]111 [ -z "$verbose" ] || {
112 echo;
113 echo "${S}Logged by external C program test_ext (filtered: ALERT only):${E}";
114 echo;
115 cat $PW_DIR/test_ext.res
116 echo
117 }
[1]118
[19]119 tmp=`cat $PW_DIR/test_ext.res | wc -l`
[164]120 if [ $tmp -eq 8 ]; then
[19]121 tmp=`egrep 'RECV: \[EOF\]' $PW_DIR/test_ext.res | wc -l`
[164]122 if [ $tmp -eq 4 ]; then
[19]123 tmp=`egrep 'RECV: ALERT' $PW_DIR/test_ext.res | wc -l`
[164]124 if [ $tmp -eq 4 ]; then
[19]125 log_ok 1 ${MAXTEST};
126 else
127 log_fail 1 ${MAXTEST};
128 fi
129 else
130 log_fail 1 ${MAXTEST};
131 fi
132 else
133 log_fail 1 ${MAXTEST};
134 fi
135
[235]136 ORIGINAL="SetChecksum=${CHKSUM}"
137 REPLACEMENT="SetChecksum=DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF"
138
139 ex -s "$PW_DIR/testrc_1ext" <<EOF
140%s/$ORIGINAL/$REPLACEMENT/g
141wq
142EOF
143
144 rm -f $PW_DIR/test_ext.res
145 rm -f $PW_DIR/pdbg.child
146 rm -f $PW_DIR/pdbg.main
147 ./samhain -p none
148
149 one_sec_sleep
150
151 if [ -f $PW_DIR/test_ext.res ]; then
152 log_fail 2 ${MAXTEST};
153 else
154 log_ok 2 ${MAXTEST};
155 fi
156
[1]157 rm -f $PW_DIR/.samhain_file
[19]158 rm -f $LOGFILE
[1]159 rm -f $PW_DIR/.samhain_lock
[19]160
161 log_end "EXTERNAL PROGRAM"
[1]162}
163
Note: See TracBrowser for help on using the repository browser.