[1] | 1 | #! /bin/sh
|
---|
| 2 |
|
---|
[19] | 3 | MAXTEST=1; export MAXTEST
|
---|
[1] | 4 |
|
---|
[19] | 5 | testext0 ()
|
---|
| 6 | {
|
---|
| 7 | COMP=`which gcc`
|
---|
| 8 | if test "x$?" = x1 ; then
|
---|
| 9 | COMP="cc"
|
---|
[1] | 10 | else
|
---|
[19] | 11 | COMP=`which gcc | sed -e "s%\([a-z:]\) .*%\1%g"`
|
---|
| 12 | if test "x$COMP" = x; then
|
---|
[1] | 13 | COMP="cc"
|
---|
[19] | 14 | elif test "x$COMP" = xno; then
|
---|
| 15 | COMP="cc"
|
---|
| 16 | else
|
---|
| 17 | if test "x$COMP" = "xwhich:"; then
|
---|
| 18 | COMP="cc"
|
---|
| 19 | else
|
---|
[1] | 20 | COMP="gcc"
|
---|
| 21 | gcc -v >/dev/null 2>&1 || COMP="gcc"
|
---|
[19] | 22 | fi
|
---|
| 23 | fi
|
---|
[1] | 24 | fi
|
---|
[19] | 25 | log_start "EXTERNAL PROGRAM"
|
---|
| 26 | [ -z "$verbose" ] || echo MAKE is $MAKE
|
---|
| 27 | [ -z "$verbose" ] || { echo COMP is $COMP; echo; }
|
---|
[1] | 28 | #
|
---|
| 29 | # standalone compilation
|
---|
| 30 | #
|
---|
[19] | 31 | [ -z "$verbose" ] || { echo; echo "${S}Building standalone agent${E}"; echo; }
|
---|
[1] | 32 | #
|
---|
| 33 | if test -r "Makefile"; then
|
---|
[19] | 34 | ${MAKE} distclean >/dev/null
|
---|
[1] | 35 | fi
|
---|
| 36 | #
|
---|
[19] | 37 | ${TOP_SRCDIR}/configure --quiet --enable-debug --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] | 38 | #
|
---|
| 39 | if test x$? = x0; then
|
---|
[19] | 40 | [ -z "$verbose" ] || log_msg_ok "configure...";
|
---|
| 41 | $MAKE > /dev/null
|
---|
| 42 | if test x$? = x0; then
|
---|
| 43 | [ -z "$verbose" ] || log_msg_ok "make...";
|
---|
| 44 | else
|
---|
| 45 | [ -z "$quiet" ] && log_msg_fail "make...";
|
---|
| 46 | return 1
|
---|
| 47 | fi
|
---|
| 48 |
|
---|
[1] | 49 | else
|
---|
[19] | 50 | [ -z "$quiet" ] && log_msg_fail "configure...";
|
---|
| 51 | return 1
|
---|
[1] | 52 | fi
|
---|
[19] | 53 | #
|
---|
[1] | 54 | # prepare the program
|
---|
| 55 | #
|
---|
| 56 | cat test/test_ext.c.in | sed -e "s%MYPWDIR%$PW_DIR/test_ext.res%g" > test_ext.c
|
---|
[19] | 57 |
|
---|
[1] | 58 | ${COMP} -o test_ext test_ext.c
|
---|
| 59 | if test "x$?" != x0; then
|
---|
[19] | 60 | log_msg_fail "${COMP} -o test_ext test_ext.c"
|
---|
| 61 | return 1
|
---|
[1] | 62 | fi
|
---|
[19] | 63 | chmod +rx test_ext
|
---|
| 64 | if test "x$?" != x0; then
|
---|
| 65 | log_msg_fail "chmod +rx test_ext"
|
---|
| 66 | return 1
|
---|
| 67 | fi
|
---|
| 68 |
|
---|
[1] | 69 | # compute checksum and fix config file
|
---|
| 70 | #
|
---|
| 71 | cp test/testrc_1ext.in testrc_1ext
|
---|
| 72 | CHKSUM=`./samhain -H $PW_DIR/test_ext | awk '{ print $2$3$4$5$6$7}'`
|
---|
| 73 | echo "OpenCommand=$PW_DIR/test_ext" >> testrc_1ext
|
---|
| 74 | echo "SetType=log" >> testrc_1ext
|
---|
| 75 | echo "SetChecksum=$CHKSUM" >> testrc_1ext
|
---|
| 76 | echo "SetFilterOr=ALERT" >> testrc_1ext
|
---|
[19] | 77 |
|
---|
[1] | 78 | rm -f $PW_DIR/test_ext.res
|
---|
| 79 | rm -f $PW_DIR/pdbg.child
|
---|
| 80 | rm -f $PW_DIR/pdbg.main
|
---|
[19] | 81 | ./samhain -p none
|
---|
| 82 |
|
---|
[1] | 83 | # The shell is too fast ...
|
---|
[19] | 84 | sleep 1
|
---|
| 85 | [ -z "$verbose" ] || {
|
---|
| 86 | echo;
|
---|
| 87 | echo "${S}Logged by external C program test_ext (filtered: ALERT only):${E}";
|
---|
| 88 | echo;
|
---|
| 89 | cat $PW_DIR/test_ext.res
|
---|
| 90 | echo
|
---|
| 91 | }
|
---|
[1] | 92 |
|
---|
[19] | 93 | tmp=`cat $PW_DIR/test_ext.res | wc -l`
|
---|
| 94 | if [ $tmp -eq 4 ]; then
|
---|
| 95 | tmp=`egrep 'RECV: \[EOF\]' $PW_DIR/test_ext.res | wc -l`
|
---|
| 96 | if [ $tmp -eq 2 ]; then
|
---|
| 97 | tmp=`egrep 'RECV: ALERT' $PW_DIR/test_ext.res | wc -l`
|
---|
| 98 | if [ $tmp -eq 2 ]; then
|
---|
| 99 | log_ok 1 ${MAXTEST};
|
---|
| 100 | else
|
---|
| 101 | log_fail 1 ${MAXTEST};
|
---|
| 102 | fi
|
---|
| 103 | else
|
---|
| 104 | log_fail 1 ${MAXTEST};
|
---|
| 105 | fi
|
---|
| 106 | else
|
---|
| 107 | log_fail 1 ${MAXTEST};
|
---|
| 108 | fi
|
---|
| 109 |
|
---|
[1] | 110 | rm -f $PW_DIR/.samhain_file
|
---|
[19] | 111 | rm -f $LOGFILE
|
---|
[1] | 112 | rm -f $PW_DIR/.samhain_lock
|
---|
[19] | 113 |
|
---|
| 114 | log_end "EXTERNAL PROGRAM"
|
---|
[1] | 115 | }
|
---|
| 116 |
|
---|