[1] | 1 | #! /bin/sh
|
---|
| 2 |
|
---|
[19] | 3 | LOGFILE="$PW_DIR/.samhain_log"; export LOGFILE
|
---|
| 4 | RCFILE="$PW_DIR/testrc_2"; export RCFILE
|
---|
[1] | 5 |
|
---|
| 6 |
|
---|
[19] | 7 | do_test_1 () {
|
---|
[1] | 8 |
|
---|
[19] | 9 | [ -z "$verbose" ] || {
|
---|
| 10 | echo;
|
---|
| 11 | echo "${S}Start Server${E}: ./yule -l info -p none &";
|
---|
| 12 | echo;
|
---|
| 13 | }
|
---|
| 14 | ./yule -l info -p none >/dev/null 2>&1 &
|
---|
| 15 | PROC_Y=$!
|
---|
| 16 | sleep 5
|
---|
[1] | 17 |
|
---|
[19] | 18 | [ -z "$verbose" ] || {
|
---|
| 19 | echo;
|
---|
| 20 | echo "${S}Start Client${E}: ./samhain.new -l none -p none -e info -t check";
|
---|
| 21 | echo;
|
---|
| 22 | }
|
---|
[1] | 23 |
|
---|
[19] | 24 | ./samhain.new -t check -p none -l none -e info --bind-address=127.0.0.1 >/dev/null 2>&1
|
---|
| 25 | if test x$? = x0; then
|
---|
| 26 | [ -z "$verbose" ] || log_msg_ok "samhain.new -t check";
|
---|
[1] | 27 | else
|
---|
[19] | 28 | [ -z "$quiet" ] && log_msg_fail "samhain.new -t check";
|
---|
| 29 | kill $PROC_Y
|
---|
| 30 | return 1
|
---|
[1] | 31 | fi
|
---|
| 32 |
|
---|
[19] | 33 | kill $PROC_Y
|
---|
| 34 | sleep 5
|
---|
[1] | 35 |
|
---|
[19] | 36 | egrep "START(>|\").*Yule(>|\")" $LOGFILE >/dev/null 2>&1
|
---|
| 37 | if [ $? -ne 0 ]; then
|
---|
| 38 | [ -z "$verbose" ] || log_msg_fail "Server start";
|
---|
| 39 | return 1
|
---|
| 40 | fi
|
---|
| 41 | egrep "NEW CLIENT" $LOGFILE >/dev/null 2>&1
|
---|
| 42 | if [ $? -ne 0 ]; then
|
---|
| 43 | [ -z "$verbose" ] || log_msg_fail "Client connect";
|
---|
| 44 | return 1
|
---|
| 45 | fi
|
---|
| 46 | egrep "remote_host.*Checking.*/bin" $LOGFILE >/dev/null 2>&1
|
---|
| 47 | if [ $? -ne 0 ]; then
|
---|
| 48 | [ -z "$verbose" ] || log_msg_fail "Client file check";
|
---|
| 49 | return 1
|
---|
| 50 | fi
|
---|
| 51 | egrep "remote_host.*EXIT.*Samhain" $LOGFILE >/dev/null 2>&1
|
---|
| 52 | if [ $? -ne 0 ]; then
|
---|
| 53 | [ -z "$verbose" ] || log_msg_fail "Client exit";
|
---|
| 54 | return 1
|
---|
| 55 | fi
|
---|
| 56 | egrep "EXIT.*Yule.*SIGTERM" $LOGFILE >/dev/null 2>&1
|
---|
| 57 | if [ $? -ne 0 ]; then
|
---|
| 58 | [ -z "$verbose" ] || log_msg_fail "Server exit";
|
---|
| 59 | return 1
|
---|
| 60 | fi
|
---|
| 61 |
|
---|
[1] | 62 |
|
---|
[19] | 63 | return 0
|
---|
| 64 | }
|
---|
[1] | 65 |
|
---|
[19] | 66 | do_test_2 () {
|
---|
| 67 |
|
---|
| 68 | ORIGINAL="UseSeparateLogs=no"
|
---|
| 69 | REPLACEMENT="UseSeparateLogs=yes"
|
---|
| 70 | ex $RCFILE <<EOF
|
---|
| 71 | :%s/$ORIGINAL/$REPLACEMENT/g
|
---|
| 72 | :wq
|
---|
| 73 | EOF
|
---|
| 74 | # :%s is the "ex" substitution command.
|
---|
| 75 | # :wq is write-and-quit.
|
---|
| 76 | [ -z "$verbose" ] || {
|
---|
| 77 | echo;
|
---|
| 78 | echo "${S}Start Server${E}: ./yule -l info -p none &";
|
---|
| 79 | echo;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | rm -f $LOGFILE
|
---|
| 83 |
|
---|
| 84 | ./yule -l info -p none >/dev/null 2>&1 &
|
---|
| 85 | PROC_Y=$!
|
---|
| 86 | sleep 5
|
---|
| 87 |
|
---|
| 88 | [ -z "$verbose" ] || {
|
---|
| 89 | echo;
|
---|
| 90 | echo "${S}Start Client${E}: ./samhain.new -l none -p none -e info -t check";
|
---|
| 91 | echo;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | ./samhain.new -t check -p none -l none -e info --bind-address=127.0.0.1 >/dev/null 2>&1
|
---|
| 95 | if test x$? = x0; then
|
---|
| 96 | [ -z "$verbose" ] || log_msg_ok "samhain.new -t check";
|
---|
| 97 | else
|
---|
| 98 | [ -z "$quiet" ] && log_msg_fail "samhain.new -t check";
|
---|
| 99 | kill $PROC_Y
|
---|
| 100 | return 1
|
---|
| 101 | fi
|
---|
| 102 |
|
---|
| 103 | kill $PROC_Y
|
---|
| 104 | sleep 5
|
---|
| 105 |
|
---|
| 106 | if [ -f ${LOGFILE}.${SH_LOCALHOST} ]; then
|
---|
| 107 | remhost=${SH_LOCALHOST}
|
---|
| 108 | else
|
---|
| 109 | remhost=`echo $SH_LOCALHOST | sed 's,\..*,,'`
|
---|
| 110 | fi
|
---|
| 111 | if [ -f ${LOGFILE}.${remhost} ]; then
|
---|
| 112 | CLIENTLOG="${LOGFILE}.${remhost}"
|
---|
| 113 | else
|
---|
| 114 | CLIENTLOG=`ls -1 ${LOGFILE}.* | tail -n 1`
|
---|
| 115 | fi
|
---|
| 116 |
|
---|
| 117 | egrep "START(>|\").*Yule(>|\")" $LOGFILE >/dev/null 2>&1
|
---|
| 118 | if [ $? -ne 0 ]; then
|
---|
| 119 | [ -z "$verbose" ] || log_msg_fail "Server start";
|
---|
| 120 | return 1
|
---|
| 121 | fi
|
---|
| 122 | egrep "NEW CLIENT" $LOGFILE >/dev/null 2>&1
|
---|
| 123 | if [ $? -ne 0 ]; then
|
---|
| 124 | [ -z "$verbose" ] || log_msg_fail "Client connect";
|
---|
| 125 | return 1
|
---|
| 126 | fi
|
---|
| 127 | egrep "remote_host.*Checking.*/bin" ${CLIENTLOG} >/dev/null 2>&1
|
---|
| 128 | if [ $? -ne 0 ]; then
|
---|
| 129 | [ -z "$verbose" ] || log_msg_fail "Client file check";
|
---|
| 130 | return 1
|
---|
| 131 | fi
|
---|
| 132 | egrep "remote_host.*EXIT.*Samhain" ${CLIENTLOG} >/dev/null 2>&1
|
---|
| 133 | if [ $? -ne 0 ]; then
|
---|
| 134 | [ -z "$verbose" ] || log_msg_fail "Client exit";
|
---|
| 135 | return 1
|
---|
| 136 | fi
|
---|
| 137 | egrep "EXIT.*Yule.*SIGTERM" $LOGFILE >/dev/null 2>&1
|
---|
| 138 | if [ $? -ne 0 ]; then
|
---|
| 139 | [ -z "$verbose" ] || log_msg_fail "Server exit";
|
---|
| 140 | return 1
|
---|
| 141 | fi
|
---|
| 142 |
|
---|
| 143 | rm -f ${LOGFILE}.${remhost}
|
---|
| 144 | return 0
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | do_test_3 () {
|
---|
| 148 |
|
---|
| 149 | ORIGINAL_1="ExportSeverity=none"
|
---|
| 150 | REPLACEMENT_1="ExportSeverity=mark"
|
---|
| 151 | ORIGINAL_2="UseSeparateLogs=yes"
|
---|
| 152 | REPLACEMENT_2="UseSeparateLogs=no"
|
---|
| 153 | ORIGINAL_3="LogSeverity=none"
|
---|
| 154 | REPLACEMENT_3="LogSeverity=debug"
|
---|
| 155 | ORIGINAL_4="# SetClientTimeLimit=1800"
|
---|
| 156 | REPLACEMENT_4="SetClientTimeLimit=20"
|
---|
| 157 | ex $RCFILE <<EOF
|
---|
| 158 | :%s/${ORIGINAL_1}/${REPLACEMENT_1}/g
|
---|
| 159 | :%s/${ORIGINAL_2}/${REPLACEMENT_2}/g
|
---|
| 160 | :%s/${ORIGINAL_3}/${REPLACEMENT_3}/g
|
---|
| 161 | :%s/${ORIGINAL_4}/${REPLACEMENT_4}/g
|
---|
| 162 | :wq
|
---|
| 163 | EOF
|
---|
| 164 | # :%s is the "ex" substitution command.
|
---|
| 165 | # :wq is write-and-quit.
|
---|
| 166 | [ -z "$verbose" ] || {
|
---|
| 167 | echo;
|
---|
| 168 | echo "${S}Start Server${E}: ./yule -p none &";
|
---|
| 169 | echo;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | rm -f $LOGFILE
|
---|
| 173 |
|
---|
| 174 | ./yule -p none >/dev/null 2>&1 &
|
---|
| 175 | PROC_Y=$!
|
---|
| 176 | sleep 5
|
---|
| 177 |
|
---|
| 178 | [ -z "$verbose" ] || {
|
---|
| 179 | echo;
|
---|
| 180 | echo "${S}Start Client${E}: ./samhain.new -l none -p none -t check";
|
---|
| 181 | echo;
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | ./samhain.new -t check -p none -l none --forever --bind-address=127.0.0.1 >/dev/null 2>&1 &
|
---|
| 185 | if test x$? = x0; then
|
---|
| 186 | PROC_S=$!
|
---|
| 187 | # echo "PID is ${PROC_S}"
|
---|
| 188 | [ -z "$verbose" ] || log_msg_ok "samhain.new -t check";
|
---|
| 189 | sleep 5
|
---|
| 190 | # Redirect the shells (un-)helpful job monitoring messages.
|
---|
| 191 | # The 'disown' buildin is not portable.
|
---|
| 192 | { kill -9 ${PROC_S}; sleep 40; } >/dev/null 2>&1
|
---|
| 193 | else
|
---|
| 194 | [ -z "$quiet" ] && log_msg_fail "samhain.new -t check";
|
---|
| 195 | kill $PROC_Y
|
---|
| 196 | return 1
|
---|
| 197 | fi
|
---|
| 198 |
|
---|
| 199 | if [ -t 0 ]; then
|
---|
| 200 | # enable monitor mode again if interactive
|
---|
| 201 | set -m
|
---|
| 202 | fi
|
---|
| 203 |
|
---|
| 204 |
|
---|
| 205 | kill $PROC_Y
|
---|
| 206 | sleep 5
|
---|
| 207 |
|
---|
| 208 | egrep "START(>|\").*Yule(>|\")" $LOGFILE >/dev/null 2>&1
|
---|
| 209 | if [ $? -ne 0 ]; then
|
---|
| 210 | [ -z "$verbose" ] || log_msg_fail "Server start";
|
---|
| 211 | return 1
|
---|
| 212 | fi
|
---|
| 213 | egrep "NEW CLIENT" $LOGFILE >/dev/null 2>&1
|
---|
| 214 | if [ $? -ne 0 ]; then
|
---|
| 215 | [ -z "$verbose" ] || log_msg_fail "Client connect";
|
---|
| 216 | return 1
|
---|
| 217 | fi
|
---|
| 218 | egrep "remote_host.*File check completed.*" ${LOGFILE} >/dev/null 2>&1
|
---|
| 219 | if [ $? -ne 0 ]; then
|
---|
| 220 | [ -z "$verbose" ] || log_msg_fail "Client file check";
|
---|
| 221 | return 1
|
---|
| 222 | fi
|
---|
| 223 | egrep "Time limit exceeded" ${LOGFILE} >/dev/null 2>&1
|
---|
| 224 | if [ $? -ne 0 ]; then
|
---|
| 225 | [ -z "$verbose" ] || log_msg_fail "Client dead detection";
|
---|
| 226 | return 1
|
---|
| 227 | fi
|
---|
| 228 | egrep "EXIT.*Yule.*SIGTERM" $LOGFILE >/dev/null 2>&1
|
---|
| 229 | if [ $? -ne 0 ]; then
|
---|
| 230 | [ -z "$verbose" ] || log_msg_fail "Server exit";
|
---|
| 231 | return 1
|
---|
| 232 | fi
|
---|
| 233 |
|
---|
| 234 | rm -f ${LOGFILE}.${remhost}
|
---|
| 235 | return 0
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | testrun2_internal ()
|
---|
[1] | 239 | {
|
---|
[19] | 240 | [ -z "$verbose" ] || {
|
---|
| 241 | echo;
|
---|
| 242 | echo Working directory: $PW_DIR; echo MAKE is $MAKE;
|
---|
| 243 | echo;
|
---|
| 244 | }
|
---|
[1] | 245 | #
|
---|
| 246 | #
|
---|
[19] | 247 | [ -z "$verbose" ] || { echo; echo "${S}Building client and server${E}"; echo; }
|
---|
[1] | 248 | #
|
---|
| 249 | if test -r "Makefile"; then
|
---|
| 250 | $MAKE distclean
|
---|
| 251 | fi
|
---|
| 252 | #
|
---|
[19] | 253 | ${TOP_SRCDIR}/configure --quiet $TRUST --enable-debug --enable-network=client --enable-xml-log --enable-login-watch --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 --enable-encrypt=2
|
---|
[1] | 254 | #
|
---|
| 255 | if test x$? = x0; then
|
---|
[19] | 256 | [ -z "$verbose" ] || log_msg_ok "configure...";
|
---|
| 257 | $MAKE > /dev/null 2>>test_log
|
---|
[1] | 258 | if test x$? = x0; then
|
---|
[19] | 259 | [ -z "$verbose" ] || log_msg_ok "make...";
|
---|
[1] | 260 | else
|
---|
[19] | 261 | [ -z "$quiet" ] && log_msg_fail "make...";
|
---|
| 262 | return 1
|
---|
[1] | 263 | fi
|
---|
| 264 |
|
---|
| 265 | else
|
---|
[19] | 266 | [ -z "$quiet" ] && log_msg_fail "configure...";
|
---|
| 267 | return 1
|
---|
[1] | 268 | fi
|
---|
| 269 |
|
---|
| 270 | # save binary and build server
|
---|
| 271 | #
|
---|
[19] | 272 | cp samhain samhain.build || return 1
|
---|
| 273 | make clean >/dev/null || return 1
|
---|
[1] | 274 |
|
---|
[19] | 275 | ${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 --with-log-file=$LOGFILE --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file --enable-identity=rainer --enable-encrypt=2
|
---|
[1] | 276 | #
|
---|
| 277 | if test x$? = x0; then
|
---|
[19] | 278 | [ -z "$verbose" ] || log_msg_ok "configure...";
|
---|
| 279 | $MAKE > /dev/null 2>>test_log
|
---|
[1] | 280 | if test x$? = x0; then
|
---|
[19] | 281 | [ -z "$verbose" ] || log_msg_ok "make...";
|
---|
[1] | 282 | else
|
---|
[19] | 283 | [ -z "$quiet" ] && log_msg_fail "make...";
|
---|
| 284 | return 1
|
---|
[1] | 285 | fi
|
---|
| 286 |
|
---|
| 287 | else
|
---|
[19] | 288 | [ -z "$quiet" ] && log_msg_fail "configure...";
|
---|
| 289 | return 1
|
---|
[1] | 290 | fi
|
---|
| 291 |
|
---|
[19] | 292 |
|
---|
[1] | 293 | #####################################################################
|
---|
| 294 | #
|
---|
| 295 | #
|
---|
| 296 | rm -f ./.samhain_file
|
---|
| 297 | rm -f ./.samhain_log
|
---|
| 298 | rm -f ./.samhain_lock
|
---|
| 299 |
|
---|
| 300 | cp ${SCRIPTDIR}/testrc_2.in testrc_2
|
---|
| 301 |
|
---|
[19] | 302 | ./samhain.build -t init -p none
|
---|
[1] | 303 |
|
---|
[19] | 304 | if test x$? = x0; then
|
---|
| 305 | [ -z "$verbose" ] || log_msg_ok "init...";
|
---|
| 306 | else
|
---|
| 307 | [ -z "$quiet" ] && log_msg_fail "init...";
|
---|
| 308 | return 1
|
---|
| 309 | fi
|
---|
[1] | 310 |
|
---|
| 311 | # Create a password
|
---|
| 312 |
|
---|
| 313 | SHPW=`./yule -G`
|
---|
| 314 | if test x"$SHPW" = x; then
|
---|
[19] | 315 | [ -z "$quiet" ] && log_msg_fail "password not generated -- aborting"
|
---|
| 316 | return 1
|
---|
[1] | 317 | fi
|
---|
| 318 |
|
---|
| 319 | # Set in client
|
---|
| 320 |
|
---|
[19] | 321 | ./samhain_setpwd samhain.build new $SHPW >/dev/null
|
---|
[1] | 322 |
|
---|
[19] | 323 | if test x$? = x0; then
|
---|
| 324 | [ -z "$verbose" ] || log_msg_ok "./samhain_setpwd samhain.build new $SHPW";
|
---|
| 325 | else
|
---|
| 326 | [ -z "$quiet" ] && log_msg_fail "./samhain_setpwd samhain.build new $SHPW";
|
---|
| 327 | return 1
|
---|
| 328 | fi
|
---|
[1] | 329 |
|
---|
[19] | 330 | mv samhain.build.new samhain.new || return 1
|
---|
| 331 |
|
---|
[1] | 332 | rm -f ./.samhain_log.*
|
---|
| 333 | rm -f ./.samhain_lock
|
---|
| 334 |
|
---|
| 335 | SHCLT=`./yule -P $SHPW | sed s%HOSTNAME%${SH_LOCALHOST}%`
|
---|
| 336 |
|
---|
[19] | 337 | if test x$? = x0; then
|
---|
| 338 | [ -z "$verbose" ] || log_msg_ok "yule -P $SHPW";
|
---|
| 339 | else
|
---|
| 340 | [ -z "$quiet" ] && log_msg_fail "yule -P $SHPW";
|
---|
| 341 | return 1
|
---|
| 342 | fi
|
---|
| 343 |
|
---|
[1] | 344 | echo $SHCLT >> testrc_2
|
---|
| 345 |
|
---|
[19] | 346 | do_test_1
|
---|
| 347 | if [ $? -eq 0 ]; then
|
---|
| 348 | [ -z "$quiet" ] && log_ok 1 ${MAXTEST} "Client logging";
|
---|
| 349 | else
|
---|
| 350 | [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Client logging";
|
---|
| 351 | fi
|
---|
[1] | 352 |
|
---|
[19] | 353 | do_test_2
|
---|
| 354 | if [ $? -eq 0 ]; then
|
---|
| 355 | [ -z "$quiet" ] && log_ok 2 ${MAXTEST} "Client logging, seperate logfiles";
|
---|
| 356 | else
|
---|
| 357 | [ -z "$quiet" ] && log_fail 2 ${MAXTEST} "Client logging, seperate logfiles";
|
---|
| 358 | fi
|
---|
[1] | 359 |
|
---|
[19] | 360 | do_test_3
|
---|
| 361 | if [ $? -eq 0 ]; then
|
---|
| 362 | [ -z "$quiet" ] && log_ok 3 ${MAXTEST} "Dead client detection";
|
---|
[1] | 363 | else
|
---|
[19] | 364 | [ -z "$quiet" ] && log_fail 3 ${MAXTEST} "Dead client detection";
|
---|
[1] | 365 | fi
|
---|
[19] | 366 |
|
---|
| 367 | return $?
|
---|
[1] | 368 | }
|
---|
| 369 |
|
---|
[19] | 370 | MAXTEST=3; export MAXTEST
|
---|
| 371 |
|
---|
| 372 | testrun2 ()
|
---|
| 373 | {
|
---|
| 374 | log_start "RUN CLIENT/SERVER"
|
---|
| 375 |
|
---|
| 376 | if [ x"$1" = x ]; then
|
---|
| 377 | [ -z "$quiet" ] && log_msg_fail "Missing hostname"
|
---|
[1] | 378 | fi
|
---|
[19] | 379 | #
|
---|
[1] | 380 | SH_LOCALHOST=$1; export SH_LOCALHOST
|
---|
[19] | 381 | #
|
---|
| 382 | testrun2_internal
|
---|
| 383 | #
|
---|
| 384 | log_end "RUN CLIENT/SERVER"
|
---|
[1] | 385 |
|
---|
[19] | 386 | return 0
|
---|
| 387 | }
|
---|
[1] | 388 |
|
---|