[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 |
|
---|
[19] | 22 | SERVER_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
|
---|
[1] | 23 |
|
---|
[30] | 24 | CLIENT_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
|
---|
[1] | 25 |
|
---|
[86] | 26 | MAXTEST=3; export MAXTEST
|
---|
| 27 |
|
---|
| 28 | testrun_threesockets () {
|
---|
| 29 |
|
---|
| 30 | GPG="$1"
|
---|
| 31 |
|
---|
| 32 | [ -z "$verbose" ] || {
|
---|
| 33 | echo;
|
---|
| 34 | echo Working directory: $PW_DIR; echo MAKE is $MAKE; echo GPG is $GPG;
|
---|
| 35 | echo;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | [ -z "$verbose" ] || { echo; echo "${S}Building client and server${E}"; echo; }
|
---|
| 39 |
|
---|
| 40 | if test -r "Makefile"; then
|
---|
| 41 | $MAKE distclean
|
---|
| 42 | fi
|
---|
| 43 |
|
---|
| 44 | ${TOP_SRCDIR}/configure --with-gpg=${GPG} --with-checksum=no ${SERVER_BUILDOPTS} >/dev/null 2>&1
|
---|
| 45 |
|
---|
| 46 | if test x$? = x0; then
|
---|
| 47 | [ -z "$verbose" ] || log_msg_ok "configure...";
|
---|
| 48 | $MAKE > /dev/null 2>>test_log
|
---|
| 49 | if test x$? = x0; then
|
---|
| 50 | [ -z "$verbose" ] || log_msg_ok "make...";
|
---|
| 51 | else
|
---|
| 52 | [ -z "$quiet" ] && log_msg_fail "make...";
|
---|
| 53 | return 1
|
---|
| 54 | fi
|
---|
| 55 | else
|
---|
| 56 | [ -z "$quiet" ] && log_msg_fail "configure...";
|
---|
| 57 | return 1
|
---|
| 58 | fi
|
---|
| 59 |
|
---|
| 60 | rm -f ./.samhain_file
|
---|
| 61 | rm -f ./.samhain_log
|
---|
| 62 | rm -f ./.samhain_lock
|
---|
| 63 | rm -f ./rc.${SH_LOCALHOST}
|
---|
| 64 | rm -f ./file.${SH_LOCALHOST}
|
---|
| 65 |
|
---|
| 66 | cp ${SCRIPTDIR}/testrc_2.in testrc_2
|
---|
| 67 |
|
---|
| 68 | ORIGINAL="DatabaseSeverity=none"
|
---|
| 69 | REPLACEMENT="DatabaseSeverity=warn"
|
---|
| 70 | ex -s $RCFILE <<EOF
|
---|
| 71 | %s/$ORIGINAL/$REPLACEMENT/g
|
---|
| 72 | wq
|
---|
| 73 | EOF
|
---|
| 74 |
|
---|
| 75 | ORIGINAL="MailSeverity=none"
|
---|
| 76 | REPLACEMENT="MailSeverity=crit"
|
---|
| 77 | ex -s $RCFILE <<EOF
|
---|
| 78 | %s/$ORIGINAL/$REPLACEMENT/g
|
---|
| 79 | wq
|
---|
| 80 | EOF
|
---|
| 81 | return 0
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[19] | 84 | check_mysql_log () {
|
---|
| 85 | DATE="$1"
|
---|
[1] | 86 |
|
---|
[19] | 87 | rm -f test_log_db
|
---|
[81] | 88 | #
|
---|
[19] | 89 | echo "SELECT * FROM log WHERE entry_status = 'NEW' and log_time > '"${DATE}"';" | mysql --password=samhain -u samhain samhain >test_log_db
|
---|
| 90 | #
|
---|
| 91 | egrep "START.*Yule" test_log_db >/dev/null 2>&1
|
---|
| 92 | if [ $? -ne 0 ]; then
|
---|
| 93 | [ -z "$verbose" ] || log_msg_fail "Server start";
|
---|
| 94 | return 1
|
---|
[1] | 95 | fi
|
---|
[19] | 96 | egrep "NEW CLIENT" test_log_db >/dev/null 2>&1
|
---|
| 97 | if [ $? -ne 0 ]; then
|
---|
| 98 | [ -z "$verbose" ] || log_msg_fail "Client connect";
|
---|
| 99 | return 1
|
---|
| 100 | fi
|
---|
| 101 | egrep "Checking.*/bin" test_log_db >/dev/null 2>&1
|
---|
| 102 | if [ $? -ne 0 ]; then
|
---|
| 103 | [ -z "$verbose" ] || log_msg_fail "Client file check";
|
---|
| 104 | return 1
|
---|
| 105 | fi
|
---|
| 106 | egrep "EXIT.*Samhain" test_log_db >/dev/null 2>&1
|
---|
| 107 | if [ $? -ne 0 ]; then
|
---|
| 108 | [ -z "$verbose" ] || log_msg_fail "Client exit";
|
---|
| 109 | return 1
|
---|
| 110 | fi
|
---|
| 111 | egrep "EXIT.*Yule.*SIGTERM" test_log_db >/dev/null 2>&1
|
---|
| 112 | if [ $? -ne 0 ]; then
|
---|
| 113 | [ -z "$verbose" ] || log_msg_fail "Server exit";
|
---|
| 114 | return 1
|
---|
| 115 | fi
|
---|
| 116 | return 0
|
---|
| 117 | }
|
---|
[1] | 118 |
|
---|
| 119 | testrun2c ()
|
---|
| 120 | {
|
---|
[19] | 121 | log_start "RUN FULL CLIENT/SERVER W/MYSQL"
|
---|
| 122 | #
|
---|
| 123 | if [ -z "$doall" ]; then
|
---|
| 124 | log_skip 1 $MAXTEST 'Client/server w/mysql (or use --really-all)'
|
---|
| 125 | return 0
|
---|
| 126 | fi
|
---|
| 127 | if [ x"$1" = x ]; then
|
---|
| 128 | [ -z "$quiet" ] && log_msg_fail "Missing hostname"
|
---|
| 129 | fi
|
---|
| 130 | MYSQL=`find_path mysql`
|
---|
| 131 | if [ -z "$MYSQL" ]; then
|
---|
| 132 | log_skip 1 $MAXTEST "mysql not found";
|
---|
| 133 | return 1
|
---|
| 134 | else
|
---|
| 135 | TEST=`echo "DESCRIBE log;" | mysql --password=samhain -u samhain samhain 2>/dev/null`
|
---|
| 136 | if [ $? -ne 0 -o -z "$TEST" ]; then
|
---|
| 137 | log_skip 1 $MAXTEST "mysql not default setup"
|
---|
| 138 | return 1
|
---|
[1] | 139 | fi
|
---|
[19] | 140 | fi
|
---|
| 141 | #
|
---|
| 142 | SH_LOCALHOST=$1; export SH_LOCALHOST
|
---|
| 143 | #
|
---|
| 144 | DATE=`date '+%Y-%m-%d %T'`
|
---|
| 145 | #
|
---|
| 146 | testrun2a_internal
|
---|
| 147 | #
|
---|
| 148 | ORIGINAL="DatabaseSeverity=none"
|
---|
| 149 | REPLACEMENT="DatabaseSeverity=info"
|
---|
[51] | 150 | ex -s $RCFILE <<EOF
|
---|
[30] | 151 | %s/$ORIGINAL/$REPLACEMENT/g
|
---|
| 152 | wq
|
---|
[19] | 153 | EOF
|
---|
| 154 | #
|
---|
| 155 | do_test_1_a
|
---|
| 156 | if [ $? -ne 0 ]; then
|
---|
| 157 | [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Client/server w/mysql";
|
---|
| 158 | else
|
---|
| 159 | #
|
---|
| 160 | check_mysql_log "${DATE}"
|
---|
| 161 | if [ $? -ne 0 ]; then
|
---|
| 162 | [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Client/server w/mysql";
|
---|
[1] | 163 | else
|
---|
[19] | 164 | [ -z "$quiet" ] && log_ok 1 ${MAXTEST} "Client/server w/mysql";
|
---|
[1] | 165 | fi
|
---|
[19] | 166 | fi
|
---|
| 167 | #
|
---|
[85] | 168 | if [ -f ./yule ]; then
|
---|
| 169 | ./yule -p info -l info --set-database-severity=info -D >/dev/null 2>>test_log
|
---|
| 170 | five_sec_sleep
|
---|
| 171 | netstat -pant 2>/dev/null | grep 49777 | grep yule >/dev/null 2>&1
|
---|
| 172 | if [ $? -ne 0 ]; then
|
---|
| 173 | [ -z "$quiet" ] && log_fail 2 ${MAXTEST} "Client/server w/mysql";
|
---|
| 174 | else
|
---|
| 175 | NSOCK=`netstat -pand 2>/dev/null | grep STREAM | grep yule | wc -l`
|
---|
| 176 | if [ $NSOCK -ne 2 ]; then
|
---|
| 177 | [ -z "$quiet" ] && log_fail 2 ${MAXTEST} "Three sockets open";
|
---|
| 178 | netstat -pand 2>/dev/null | grep yule
|
---|
| 179 | else
|
---|
| 180 | [ -z "$quiet" ] && log_ok 2 ${MAXTEST} "Three sockets open";
|
---|
| 181 | fi
|
---|
| 182 | fi
|
---|
| 183 | PID=`cat .samhain_lock`
|
---|
| 184 | kill $PID
|
---|
[86] | 185 | else
|
---|
| 186 | log_fail 2 ${MAXTEST} "Three sockets open";
|
---|
[85] | 187 | fi
|
---|
| 188 | #
|
---|
[86] | 189 | GPG=`find_path gpg`
|
---|
| 190 | if [ -z "$GPG" ]; then
|
---|
| 191 | log_skip 1 $MAXTEST 'gpg not found in $PATH'
|
---|
| 192 | else
|
---|
| 193 | eval "$GPG" --list-keys 0F571F6C >/dev/null 2>/dev/null
|
---|
| 194 | if [ $? -ne 0 ]; then
|
---|
| 195 | log_skip 1 $MAXTEST 'public PGP key 0x0F571F6C not present'
|
---|
| 196 | else
|
---|
| 197 | testrun_threesockets "$GPG"
|
---|
| 198 |
|
---|
| 199 | if [ -f ./yule ]; then
|
---|
| 200 | ./yule -D >/dev/null 2>>test_log
|
---|
| 201 | five_sec_sleep
|
---|
| 202 | netstat -pant 2>/dev/null | grep 49777 | grep yule >/dev/null 2>&1
|
---|
| 203 | if [ $? -ne 0 ]; then
|
---|
| 204 | [ -z "$quiet" ] && log_fail 3 ${MAXTEST} "Three sockets open (gpg)";
|
---|
| 205 | else
|
---|
| 206 | NSOCK=`netstat -pand 2>/dev/null | grep STREAM | grep yule | wc -l`
|
---|
| 207 | if [ $NSOCK -ne 2 ]; then
|
---|
| 208 | [ -z "$quiet" ] && log_fail 3 ${MAXTEST} "Three sockets open (gpg)";
|
---|
| 209 | netstat -pand 2>/dev/null | grep yule
|
---|
| 210 | else
|
---|
| 211 | [ -z "$quiet" ] && log_ok 3 ${MAXTEST} "Three sockets open (gpg)";
|
---|
| 212 | fi
|
---|
| 213 | fi
|
---|
| 214 | PID=`cat .samhain_lock`
|
---|
| 215 | kill $PID
|
---|
| 216 | else
|
---|
| 217 | log_fail 3 ${MAXTEST} "Three sockets open (gpg)";
|
---|
| 218 | fi
|
---|
| 219 | fi
|
---|
| 220 | fi
|
---|
| 221 | #
|
---|
[19] | 222 | if [ -n "$cleanup" ]; then
|
---|
[1] | 223 | rm -f ./rc.${SH_LOCALHOST}
|
---|
| 224 | rm -f ./file.${SH_LOCALHOST}
|
---|
[19] | 225 | ALTHOST=`find_hostname`
|
---|
| 226 | rm -f "./file.${ALTHOST}"
|
---|
| 227 | rm -f "./rc.${ALTHOST}"
|
---|
| 228 | fi
|
---|
| 229 | #
|
---|
| 230 | log_end "RUN FULL CLIENT/SERVER W/MYSQL"
|
---|
[1] | 231 | }
|
---|
| 232 |
|
---|