[550] | 1 | #! /bin/sh
|
---|
| 2 |
|
---|
| 3 | #
|
---|
| 4 | # Copyright Rainer Wichmann (2015)
|
---|
| 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 |
|
---|
| 22 | LOGFILE="$PW_DIR/.samhain_log"; export LOGFILE
|
---|
| 23 | RCFILE="$PW_DIR/testrc_2"; export RCFILE
|
---|
| 24 |
|
---|
| 25 | SERVER_BUILDOPTS="--quiet $TRUST --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 --enable-debug=gdb --enable-static"; export SERVER_BUILDOPTS
|
---|
| 26 |
|
---|
| 27 | CLIENT_BUILDOPTS="--quiet $TRUST --enable-network=client --enable-srp --prefix=$PW_DIR --with-tmp-dir=$PW_DIR --localstatedir=$PW_DIR --with-config-file=REQ_FROM_SERVER$RCFILE --with-data-file=REQ_FROM_SERVER$PW_DIR/.samhain_file --with-log-file=$LOGFILE --with-pid-file=$PW_DIR/.samhain_lock --enable-static"; export CLIENT_BUILDOPTS
|
---|
| 28 |
|
---|
| 29 | TEST_DIRS="one two three four"
|
---|
| 30 | TEST_FILES="change leave rmthis"
|
---|
| 31 | BASE="/tmp/testrun_samhain"
|
---|
| 32 |
|
---|
| 33 | TEST_LIST="./tmp_list_file"
|
---|
| 34 |
|
---|
| 35 | ALTHOST=`find_hostname`
|
---|
| 36 |
|
---|
| 37 | PROC_S=0; export PROC_S
|
---|
| 38 | PROC_Y=0; export PROC_Y
|
---|
| 39 |
|
---|
| 40 | mod_files ()
|
---|
| 41 | {
|
---|
| 42 | rm -f "${TEST_LIST}"
|
---|
| 43 | touch "${TEST_LIST}"
|
---|
| 44 | #
|
---|
| 45 | for dd in ${TEST_DIRS}; do
|
---|
| 46 | echo "changed" > "${BASE}/$dd/change"
|
---|
| 47 | rm -f "${BASE}/$dd/rmthis"
|
---|
| 48 | echo "added" > "${BASE}/$dd/addedthis"
|
---|
| 49 | echo "${BASE}/$dd" >> "${TEST_LIST}"
|
---|
| 50 | echo "${BASE}/$dd/change" >> "${TEST_LIST}"
|
---|
| 51 | echo "${BASE}/$dd/rmthis" >> "${TEST_LIST}"
|
---|
| 52 | echo "${BASE}/$dd/addedthis" >> "${TEST_LIST}"
|
---|
| 53 | done
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | do_test_2_g_yule_start () {
|
---|
| 57 |
|
---|
| 58 | [ -z "$verbose" ] || {
|
---|
| 59 | echo;
|
---|
| 60 | echo "${S}Start Server${E}: ./yule -l info -p none &";
|
---|
| 61 | echo;
|
---|
| 62 | }
|
---|
| 63 | rm -f test_log_valgrind
|
---|
| 64 |
|
---|
| 65 | # SetSocketAllowUid=$(id -u)
|
---|
| 66 | #
|
---|
| 67 | if test -f /usr/xpg4/bin/id; then
|
---|
| 68 | MY_ID=$(/usr/xpg4/bin/id -u)
|
---|
| 69 | else
|
---|
| 70 | MY_ID=$(id -u)
|
---|
| 71 | fi
|
---|
| 72 | #
|
---|
| 73 | sed -i -e "s/SetSocketAllowUid=0/SetSocketAllowUid=${MY_ID}/g" $RCFILE
|
---|
| 74 |
|
---|
| 75 | # Start server
|
---|
| 76 | #
|
---|
| 77 | ${VALGRIND} ./yule -l info -p none >/dev/null 2>>test_log_valgrind &
|
---|
| 78 | PROC_Y=$!
|
---|
| 79 | five_sec_sleep
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 | [ -z "$verbose" ] || {
|
---|
| 83 | echo;
|
---|
| 84 | echo "${S}Start Client${E}: ./samhain.new -t check -D .. &";
|
---|
| 85 | echo;
|
---|
| 86 | }
|
---|
| 87 | ${VALGRIND} ./samhain.new -t check -D -p none -l none -e info --bind-address=127.0.0.1 --server-host=localhost >/dev/null 2>>test_log_valgrind
|
---|
| 88 | if test x$? = x0; then
|
---|
| 89 | [ -z "$verbose" ] || log_msg_ok "starting samhain.new";
|
---|
| 90 | else
|
---|
| 91 | [ -z "$quiet" ] && log_msg_fail "starting samhain.new";
|
---|
| 92 | kill $PROC_Y
|
---|
| 93 | return 1
|
---|
| 94 | fi
|
---|
| 95 | five_sec_sleep
|
---|
| 96 | PROC_S=$( ps aux | grep samhain.new | grep -v grep | awk '{ print $2; }' | sort | head -n 1 )
|
---|
| 97 |
|
---|
| 98 | for ff in 1 2; do
|
---|
| 99 | five_sec_sleep
|
---|
| 100 | done
|
---|
| 101 | egrep "File check completed" $LOGFILE >/dev/null 2>&1
|
---|
| 102 | if [ $? -ne 0 ]; then
|
---|
| 103 | [ -z "$verbose" ] || log_msg_fail "Client file check";
|
---|
| 104 | kill $PROC_S; kill $PROC_Y;
|
---|
| 105 | return 1
|
---|
| 106 | fi
|
---|
| 107 | NR=$( egrep "File check completed" $LOGFILE | wc -l )
|
---|
| 108 | if [ $NR -ne 1 ]; then
|
---|
| 109 | [ -z "$verbose" ] || log_msg_fail "Client file check (1)";
|
---|
| 110 | kill $PROC_S; kill $PROC_Y;
|
---|
| 111 | return 1
|
---|
| 112 | fi
|
---|
| 113 |
|
---|
| 114 | return 0
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | do_test_2_g_two () {
|
---|
| 118 |
|
---|
| 119 | #
|
---|
| 120 | # >>> Modify files
|
---|
| 121 | #
|
---|
| 122 | mod_files
|
---|
| 123 | #
|
---|
| 124 | if ! test -f ${TEST_LIST}; then
|
---|
| 125 | [ -z "$verbose" ] || log_msg_fail "No file list created";
|
---|
| 126 | kill $PROC_S; kill $PROC_Y;
|
---|
| 127 | return 1
|
---|
| 128 | fi
|
---|
| 129 | #
|
---|
| 130 | #
|
---|
| 131 | # >>> Trigger a scan
|
---|
| 132 | #
|
---|
| 133 | kill -TTOU $PROC_S
|
---|
| 134 | if [ $? -ne 0 ]; then
|
---|
| 135 | [ -z "$verbose" ] || log_msg_fail "Kill -TTOU";
|
---|
| 136 | kill $PROC_S; kill $PROC_Y;
|
---|
| 137 | return 1
|
---|
| 138 | fi
|
---|
| 139 |
|
---|
| 140 | for ff in 1 2 3; do
|
---|
| 141 | five_sec_sleep
|
---|
| 142 | done
|
---|
| 143 | NR=$( egrep "File check completed" $LOGFILE | wc -l )
|
---|
| 144 | if [ $NR -ne 2 ]; then
|
---|
| 145 | [ -z "$verbose" ] || log_msg_fail "Client file check (2)";
|
---|
| 146 | kill $PROC_S; kill $PROC_Y;
|
---|
| 147 | return 1
|
---|
| 148 | fi
|
---|
| 149 | [ -z "$verbose" ] || log_msg_ok "sigttou";
|
---|
| 150 |
|
---|
| 151 | NR=$( egrep "POLICY" $LOGFILE | grep ReadOnly | wc -l )
|
---|
| 152 | if [ $NR -ne 8 ]; then
|
---|
| 153 | [ -z "$verbose" ] || log_msg_fail "Client file check (ReadOnly)";
|
---|
| 154 | kill $PROC_S; kill $PROC_Y;
|
---|
| 155 | return 1
|
---|
| 156 | fi
|
---|
| 157 | NR=$( egrep "POLICY" $LOGFILE | grep ADDED | wc -l )
|
---|
| 158 | if [ $NR -ne 4 ]; then
|
---|
| 159 | [ -z "$verbose" ] || log_msg_fail "Client file check (added)";
|
---|
| 160 | kill $PROC_S; kill $PROC_Y;
|
---|
| 161 | return 1
|
---|
| 162 | fi
|
---|
| 163 | NR=$( egrep "POLICY" $LOGFILE | grep MISSING | wc -l )
|
---|
| 164 | if [ $NR -ne 4 ]; then
|
---|
| 165 | [ -z "$verbose" ] || log_msg_fail "Client file check (removed)";
|
---|
| 166 | kill $PROC_S; kill $PROC_Y;
|
---|
| 167 | return 1
|
---|
| 168 | fi
|
---|
| 169 |
|
---|
| 170 | kill $PROC_S;
|
---|
| 171 | kill $PROC_Y;
|
---|
| 172 | return 0
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | do_test_2_g_one () {
|
---|
| 176 |
|
---|
| 177 | #
|
---|
| 178 | # >>> (1) Modify files, create DeltaDB from file list in ${TEST_LIST}
|
---|
| 179 | #
|
---|
| 180 | mod_files
|
---|
| 181 | #
|
---|
| 182 | if ! test -f ${TEST_LIST}; then
|
---|
| 183 | [ -z "$verbose" ] || log_msg_fail "No file list created";
|
---|
| 184 | kill $PROC_S; kill $PROC_Y;
|
---|
| 185 | return 1
|
---|
| 186 | fi
|
---|
| 187 | #
|
---|
| 188 | ./samhain.new --outfile ./file.delta --create-database "${TEST_LIST}"
|
---|
| 189 | #
|
---|
| 190 | if [ $? -ne 0 ]; then
|
---|
| 191 | [ -z "$verbose" ] || log_msg_fail "Create DeltaDB";
|
---|
| 192 | kill $PROC_S; kill $PROC_Y;
|
---|
| 193 | return 1
|
---|
| 194 | fi
|
---|
| 195 | if ! test -f ./file.delta; then
|
---|
| 196 | [ -z "$verbose" ] || log_msg_fail "No DeltaDB created";
|
---|
| 197 | kill $PROC_S; kill $PROC_Y;
|
---|
| 198 | return 1
|
---|
| 199 | fi
|
---|
| 200 |
|
---|
| 201 | #
|
---|
| 202 | # >>> (2) Copy to server and tag with a UUID
|
---|
| 203 | #
|
---|
| 204 | UUID=$(uuidgen)
|
---|
| 205 | mv ./file.delta file.${SH_LOCALHOST}.${UUID}
|
---|
| 206 | cp file.${SH_LOCALHOST}.${UUID} "./file.${ALTHOST}.${UUID}"
|
---|
| 207 |
|
---|
| 208 | #
|
---|
| 209 | # >>> (3) Tell client to load delta database.
|
---|
| 210 | # >>> testrc_2: timestamps every 10 sec
|
---|
| 211 | #
|
---|
| 212 | grep '^SetLoopTime=10$' rc.${SH_LOCALHOST} >/dev/null 2>&1
|
---|
| 213 | if [ $? -ne 0 ]; then
|
---|
| 214 | [ -z "$verbose" ] || log_msg_fail "SetLoopTime != 10 in rc.${SH_LOCALHOST}";
|
---|
| 215 | kill $PROC_S; kill $PROC_Y;
|
---|
| 216 | return 1
|
---|
| 217 | fi
|
---|
| 218 | grep '^SetLoopTime=10$' rc.${ALTHOST} >/dev/null 2>&1
|
---|
| 219 | if [ $? -ne 0 ]; then
|
---|
| 220 | [ -z "$verbose" ] || log_msg_fail "SetLoopTime != 10 in rc.${ALTHOST}";
|
---|
| 221 | kill $PROC_S; kill $PROC_Y;
|
---|
| 222 | return 1
|
---|
| 223 | fi
|
---|
| 224 |
|
---|
| 225 | ./yulectl -c "DELTA:${UUID}" ${SH_LOCALHOST}
|
---|
| 226 | if [ $? -ne 0 ]; then
|
---|
| 227 | [ -z "$verbose" ] || log_msg_fail "yulectl (1)";
|
---|
| 228 | kill $PROC_S; kill $PROC_Y;
|
---|
| 229 | return 1
|
---|
| 230 | fi
|
---|
| 231 | ./yulectl -c "DELTA:${UUID}" ${ALTHOST}
|
---|
| 232 | if [ $? -ne 0 ]; then
|
---|
| 233 | [ -z "$verbose" ] || log_msg_fail "yulectl (2)";
|
---|
| 234 | kill $PROC_S; kill $PROC_Y;
|
---|
| 235 | return 1
|
---|
| 236 | fi
|
---|
| 237 | NR=$( ./yulectl -c LIST | grep ${UUID} | grep -v grep | wc -l )
|
---|
| 238 | if [ $NR -ne 2 ]; then
|
---|
| 239 | [ -z "$verbose" ] || log_msg_fail "yulectl (3)";
|
---|
| 240 | [ -z "$verbose" ] || ./yulectl -c LIST
|
---|
| 241 | kill $PROC_S; kill $PROC_Y;
|
---|
| 242 | return 1
|
---|
| 243 | fi
|
---|
| 244 |
|
---|
| 245 | # Wait and verify that command has been sent
|
---|
| 246 | #
|
---|
| 247 | for tt in 1 2 3 4; do
|
---|
| 248 | five_sec_sleep
|
---|
| 249 | done
|
---|
| 250 | #
|
---|
| 251 | NR=$( ./yulectl -c LIST | grep ${UUID} | grep -v grep | wc -l )
|
---|
| 252 | if [ $NR -ne 1 ]; then
|
---|
| 253 | [ -z "$verbose" ] || log_msg_fail "yulectl (4)";
|
---|
| 254 | [ -z "$verbose" ] || ./yulectl -c LISTALL
|
---|
| 255 | kill $PROC_S; kill $PROC_Y;
|
---|
| 256 | return 1
|
---|
| 257 | fi
|
---|
| 258 |
|
---|
| 259 | #
|
---|
| 260 | # >>> (4) Trigger a scan
|
---|
| 261 | #
|
---|
| 262 | kill -TTOU $PROC_S
|
---|
| 263 | if [ $? -ne 0 ]; then
|
---|
| 264 | [ -z "$verbose" ] || log_msg_fail "Kill -TTOU";
|
---|
| 265 | kill $PROC_S; kill $PROC_Y;
|
---|
| 266 | return 1
|
---|
| 267 | fi
|
---|
| 268 |
|
---|
| 269 | for ff in 1 2; do
|
---|
| 270 | five_sec_sleep
|
---|
| 271 | done
|
---|
| 272 | NR=$( egrep "File check completed" $LOGFILE | wc -l )
|
---|
| 273 | if [ $NR -ne 2 ]; then
|
---|
| 274 | [ -z "$verbose" ] || log_msg_fail "Client file check (2)";
|
---|
| 275 | kill $PROC_S; kill $PROC_Y;
|
---|
| 276 | return 1
|
---|
| 277 | fi
|
---|
| 278 | [ -z "$verbose" ] || log_msg_ok "sigttou";
|
---|
| 279 |
|
---|
| 280 | NR=$( egrep "POLICY" $LOGFILE | wc -l )
|
---|
| 281 | if [ $NR -ne 0 ]; then
|
---|
| 282 | [ -z "$verbose" ] || log_msg_fail "Client file check (3)";
|
---|
| 283 | kill $PROC_S; kill $PROC_Y;
|
---|
| 284 | return 1
|
---|
| 285 | fi
|
---|
| 286 |
|
---|
| 287 | # --- The End ---
|
---|
| 288 |
|
---|
| 289 | kill $PROC_S;
|
---|
| 290 | kill $PROC_Y
|
---|
| 291 | return 0
|
---|
| 292 | }
|
---|
| 293 |
|
---|
| 294 | do_test_2_g_three () {
|
---|
| 295 |
|
---|
| 296 | #
|
---|
| 297 | # >>> (1) Modify files, create DeltaDB from file list in ${TEST_LIST}
|
---|
| 298 | #
|
---|
| 299 | mod_files
|
---|
| 300 | #
|
---|
| 301 | if ! test -f ${TEST_LIST}; then
|
---|
| 302 | [ -z "$verbose" ] || log_msg_fail "No file list created";
|
---|
| 303 | kill $PROC_S; kill $PROC_Y;
|
---|
| 304 | return 1
|
---|
| 305 | fi
|
---|
| 306 | #
|
---|
| 307 | ./samhain.new --outfile ./file.delta --create-database "${TEST_LIST}"
|
---|
| 308 | #
|
---|
| 309 | if [ $? -ne 0 ]; then
|
---|
| 310 | [ -z "$verbose" ] || log_msg_fail "Create DeltaDB";
|
---|
| 311 | kill $PROC_S; kill $PROC_Y;
|
---|
| 312 | return 1
|
---|
| 313 | fi
|
---|
| 314 | if ! test -f ./file.delta; then
|
---|
| 315 | [ -z "$verbose" ] || log_msg_fail "No DeltaDB created";
|
---|
| 316 | kill $PROC_S; kill $PROC_Y;
|
---|
| 317 | return 1
|
---|
| 318 | fi
|
---|
| 319 | [ -z "$verbose" ] || log_msg_ok "... DeltaDB created ...";
|
---|
| 320 |
|
---|
| 321 | #
|
---|
| 322 | # >>> (2) Copy to server and tag with a UUID
|
---|
| 323 | #
|
---|
| 324 | UUID=$(uuidgen)
|
---|
| 325 | if [ x"$1" != "xnosig" ]; then
|
---|
| 326 | scripts/samhainadmin.pl -s ./test/gnupg/ -k 8A0B337A -m E ./file.delta >/dev/null
|
---|
| 327 | fi
|
---|
| 328 | if [ x"$1" == "xnodelta" ]; then
|
---|
| 329 | rm -f ./file.*
|
---|
| 330 | else
|
---|
| 331 | mv ./file.delta file.${SH_LOCALHOST}.${UUID}
|
---|
| 332 | cp file.${SH_LOCALHOST}.${UUID} "./file.${ALTHOST}.${UUID}"
|
---|
| 333 | fi
|
---|
| 334 | [ -z "$verbose" ] || log_msg_ok "... DeltaDB copied as file.${SH_LOCALHOST}.${UUID} ...";
|
---|
| 335 |
|
---|
| 336 | #
|
---|
| 337 | # >>> (3) Tell client to load delta database.
|
---|
| 338 | # >>> testrc_2: timestamps every 10 sec
|
---|
| 339 | #
|
---|
| 340 | grep '^SetLoopTime=10$' rc.${SH_LOCALHOST} >/dev/null 2>&1
|
---|
| 341 | if [ $? -ne 0 ]; then
|
---|
| 342 | [ -z "$verbose" ] || log_msg_fail "SetLoopTime != 10 in rc.${SH_LOCALHOST}";
|
---|
| 343 | kill $PROC_S; kill $PROC_Y;
|
---|
| 344 | return 1
|
---|
| 345 | fi
|
---|
| 346 | grep '^SetLoopTime=10$' rc.${ALTHOST} >/dev/null 2>&1
|
---|
| 347 | if [ $? -ne 0 ]; then
|
---|
| 348 | [ -z "$verbose" ] || log_msg_fail "SetLoopTime != 10 in rc.${ALTHOST}";
|
---|
| 349 | kill $PROC_S; kill $PROC_Y;
|
---|
| 350 | return 1
|
---|
| 351 | fi
|
---|
| 352 |
|
---|
| 353 | ./yulectl -c "DELTA:${UUID}" ${SH_LOCALHOST}
|
---|
| 354 | if [ $? -ne 0 ]; then
|
---|
| 355 | [ -z "$verbose" ] || log_msg_fail "yulectl (1)";
|
---|
| 356 | kill $PROC_S; kill $PROC_Y;
|
---|
| 357 | return 1
|
---|
| 358 | fi
|
---|
| 359 | ./yulectl -c "DELTA:${UUID}" ${ALTHOST}
|
---|
| 360 | if [ $? -ne 0 ]; then
|
---|
| 361 | [ -z "$verbose" ] || log_msg_fail "yulectl (2)";
|
---|
| 362 | kill $PROC_S; kill $PROC_Y;
|
---|
| 363 | return 1
|
---|
| 364 | fi
|
---|
| 365 | NR=$( ./yulectl -c LIST | grep ${UUID} | grep -v grep | wc -l )
|
---|
| 366 | if [ $NR -ne 2 ]; then
|
---|
| 367 | [ -z "$verbose" ] || log_msg_fail "yulectl (3)";
|
---|
| 368 | [ -z "$verbose" ] || ./yulectl -c LIST
|
---|
| 369 | kill $PROC_S; kill $PROC_Y;
|
---|
| 370 | return 1
|
---|
| 371 | fi
|
---|
| 372 | [ -z "$verbose" ] || log_msg_ok "... command sent to client ...";
|
---|
| 373 |
|
---|
| 374 | # Wait and verify that command has been sent
|
---|
| 375 | #
|
---|
| 376 | for tt in 1 2 3 4; do
|
---|
| 377 | five_sec_sleep
|
---|
| 378 | done
|
---|
| 379 | #
|
---|
| 380 | NR=$( ./yulectl -c LIST | grep ${UUID} | grep -v grep | wc -l )
|
---|
| 381 | if [ $NR -ne 1 ]; then
|
---|
| 382 | [ -z "$verbose" ] || log_msg_fail "yulectl (4)";
|
---|
| 383 | [ -z "$verbose" ] || ./yulectl -c LISTALL
|
---|
| 384 | kill $PROC_S; kill $PROC_Y;
|
---|
| 385 | return 1
|
---|
| 386 | fi
|
---|
| 387 | [ -z "$verbose" ] || OLINE=$( ./yulectl -c LIST | grep ${UUID} )
|
---|
| 388 | [ -z "$verbose" ] || echo "${OLINE}"
|
---|
| 389 |
|
---|
| 390 | #
|
---|
| 391 | # >>> (4) Trigger a scan
|
---|
| 392 | #
|
---|
| 393 | kill -TTOU $PROC_S
|
---|
| 394 | if [ $? -ne 0 ]; then
|
---|
| 395 | [ -z "$verbose" ] || log_msg_fail "Kill -TTOU";
|
---|
| 396 | kill $PROC_S; kill $PROC_Y;
|
---|
| 397 | return 1
|
---|
| 398 | fi
|
---|
| 399 | [ -z "$verbose" ] || echo " ... TTOU sent to /${PROC_S}/ ...";
|
---|
| 400 |
|
---|
| 401 | for ff in 1 2; do
|
---|
| 402 | five_sec_sleep
|
---|
| 403 | done
|
---|
| 404 | if [ x"$1" != x ]; then
|
---|
| 405 | if [ x"$1" = xnodelta ]; then
|
---|
| 406 | NR=$( egrep "File download failed" $LOGFILE | wc -l )
|
---|
| 407 | else
|
---|
| 408 | NR=$( egrep "No good signature" $LOGFILE | wc -l )
|
---|
| 409 | fi
|
---|
| 410 | if [ $NR -ne 1 ]; then
|
---|
| 411 | [ -z "$verbose" ] || log_msg_fail "Client file check (expected fail)";
|
---|
| 412 | kill $PROC_S; kill $PROC_Y;
|
---|
| 413 | return 1
|
---|
| 414 | else
|
---|
| 415 | [ -z "$verbose" ] || log_msg_ok "Client file check (expected fail)";
|
---|
| 416 | kill $PROC_S; kill $PROC_Y;
|
---|
| 417 | return 0
|
---|
| 418 | fi
|
---|
| 419 | fi
|
---|
| 420 |
|
---|
| 421 | NR=$( egrep "File check completed" $LOGFILE | wc -l )
|
---|
| 422 | if [ $NR -ne 2 ]; then
|
---|
| 423 | [ -z "$verbose" ] || log_msg_fail "Client file check (2)";
|
---|
| 424 | kill $PROC_S; kill $PROC_Y;
|
---|
| 425 | return 1
|
---|
| 426 | fi
|
---|
| 427 | [ -z "$verbose" ] || log_msg_ok "sigttou";
|
---|
| 428 |
|
---|
| 429 | NR=$( egrep "POLICY" $LOGFILE | wc -l )
|
---|
| 430 | if [ $NR -ne 0 ]; then
|
---|
| 431 | [ -z "$verbose" ] || log_msg_fail "Client file check (3)";
|
---|
| 432 | kill $PROC_S; kill $PROC_Y;
|
---|
| 433 | return 1
|
---|
| 434 | fi
|
---|
| 435 |
|
---|
| 436 | # --- The End ---
|
---|
| 437 |
|
---|
| 438 | kill $PROC_S;
|
---|
| 439 | kill $PROC_Y
|
---|
| 440 | return 0
|
---|
| 441 | }
|
---|
| 442 |
|
---|
| 443 | testrun2g_prepare ()
|
---|
| 444 | {
|
---|
| 445 | #####################################################################
|
---|
| 446 | #
|
---|
| 447 | # Create test area and initialize database
|
---|
| 448 | #
|
---|
| 449 | rm -f ./.samhain_file
|
---|
| 450 | rm -f ./.samhain_log
|
---|
| 451 | rm -f ./.samhain_lock
|
---|
| 452 | rm -f ./rc.${SH_LOCALHOST}
|
---|
| 453 | rm -f ./rc.${ALTHOST}
|
---|
| 454 | rm -f ./file.*
|
---|
| 455 | #
|
---|
| 456 | rm -rf ${BASE}
|
---|
| 457 | #
|
---|
| 458 | mkdir ${BASE} 2>/dev/null
|
---|
| 459 | for dd in ${TEST_DIRS}; do
|
---|
| 460 | mkdir ${BASE}/$dd
|
---|
| 461 | for ff in ${TEST_FILES}; do
|
---|
| 462 | echo "foobar" > ${BASE}/$dd/$ff
|
---|
| 463 | done
|
---|
| 464 | done
|
---|
| 465 | #
|
---|
| 466 | ./samhain.build -t init -p none
|
---|
| 467 |
|
---|
| 468 | if test x$? = x0; then
|
---|
| 469 | [ -z "$verbose" ] || log_msg_ok "init...";
|
---|
| 470 | else
|
---|
| 471 | [ -z "$quiet" ] && log_msg_fail "init...";
|
---|
| 472 | return 1
|
---|
| 473 | fi
|
---|
| 474 | }
|
---|
| 475 |
|
---|
| 476 | testrun2g_build ()
|
---|
| 477 | {
|
---|
| 478 | [ -z "$verbose" ] || {
|
---|
| 479 | echo;
|
---|
| 480 | echo Working directory: $PW_DIR; echo MAKE is $MAKE;
|
---|
| 481 | echo;
|
---|
| 482 | }
|
---|
| 483 | #
|
---|
| 484 | #
|
---|
| 485 | [ -z "$verbose" ] || { echo; echo "${S}Building client and server${E}"; echo; }
|
---|
| 486 | #
|
---|
| 487 | if test -r "Makefile"; then
|
---|
| 488 | $MAKE distclean
|
---|
| 489 | fi
|
---|
| 490 | #
|
---|
| 491 | ${TOP_SRCDIR}/configure ${CLIENT_BUILDOPTS} $1 $2 >/dev/null 2>&1
|
---|
| 492 | #
|
---|
| 493 | if test x$? = x0; then
|
---|
| 494 | [ -z "$verbose" ] || log_msg_ok "configure...";
|
---|
| 495 | $MAKE > /dev/null 2>>test_log
|
---|
| 496 | if test x$? = x0; then
|
---|
| 497 | [ -z "$verbose" ] || log_msg_ok "make...";
|
---|
| 498 | else
|
---|
| 499 | [ -z "$quiet" ] && log_msg_fail "make...";
|
---|
| 500 | return 1
|
---|
| 501 | fi
|
---|
| 502 |
|
---|
| 503 | else
|
---|
| 504 | [ -z "$quiet" ] && log_msg_fail "configure...";
|
---|
| 505 | return 1
|
---|
| 506 | fi
|
---|
| 507 |
|
---|
| 508 | # save binary and build server
|
---|
| 509 | #
|
---|
| 510 | cp samhain samhain.build || return 1
|
---|
| 511 | $MAKE clean >/dev/null || return 1
|
---|
| 512 |
|
---|
| 513 | ${TOP_SRCDIR}/configure ${SERVER_BUILDOPTS}
|
---|
| 514 | #
|
---|
| 515 | if test x$? = x0; then
|
---|
| 516 | [ -z "$verbose" ] || log_msg_ok "configure...";
|
---|
| 517 | $MAKE > /dev/null 2>>test_log
|
---|
| 518 | if test x$? = x0; then
|
---|
| 519 | [ -z "$verbose" ] || log_msg_ok "make...";
|
---|
| 520 | else
|
---|
| 521 | [ -z "$quiet" ] && log_msg_fail "make...";
|
---|
| 522 | return 1
|
---|
| 523 | fi
|
---|
| 524 |
|
---|
| 525 | else
|
---|
| 526 | [ -z "$quiet" ] && log_msg_fail "configure...";
|
---|
| 527 | return 1
|
---|
| 528 | fi
|
---|
| 529 |
|
---|
| 530 | # Create a password
|
---|
| 531 |
|
---|
| 532 | SHPW=`./yule -G`
|
---|
| 533 | if test x"$SHPW" = x; then
|
---|
| 534 | [ -z "$quiet" ] && log_msg_fail "password not generated -- aborting"
|
---|
| 535 | return 1
|
---|
| 536 | fi
|
---|
| 537 |
|
---|
| 538 | # Set in client
|
---|
| 539 |
|
---|
| 540 | ./samhain_setpwd samhain.build new $SHPW >/dev/null
|
---|
| 541 |
|
---|
| 542 | if test x$? = x0; then
|
---|
| 543 | [ -z "$verbose" ] || log_msg_ok "./samhain_setpwd samhain.build new $SHPW";
|
---|
| 544 | else
|
---|
| 545 | [ -z "$quiet" ] && log_msg_fail "./samhain_setpwd samhain.build new $SHPW";
|
---|
| 546 | return 1
|
---|
| 547 | fi
|
---|
| 548 |
|
---|
| 549 | mv samhain.build.new samhain.new || return 1
|
---|
| 550 |
|
---|
| 551 | rm -f ./.samhain_log*
|
---|
| 552 | rm -f ./.samhain_lock
|
---|
| 553 |
|
---|
| 554 | SHCLT=`./yule -P $SHPW`
|
---|
| 555 |
|
---|
| 556 | if test x$? = x0; then
|
---|
| 557 | [ -z "$verbose" ] || log_msg_ok "yule -P $SHPW";
|
---|
| 558 | else
|
---|
| 559 | [ -z "$quiet" ] && log_msg_fail "yule -P $SHPW";
|
---|
| 560 | return 1
|
---|
| 561 | fi
|
---|
| 562 |
|
---|
| 563 | SHCLT1=`echo "${SHCLT}" | sed s%HOSTNAME%${SH_LOCALHOST}%`
|
---|
| 564 | AHOST=`find_hostname`
|
---|
| 565 | SHCLT2=`echo "${SHCLT}" | sed s%HOSTNAME%${AHOST}%`
|
---|
| 566 |
|
---|
| 567 | cp ${SCRIPTDIR}/testrc_2.in testrc_2
|
---|
| 568 | #
|
---|
| 569 | sed --in-place -e 's,file = /tmp,dir = 99/tmp/testrun_samhain,g' testrc_2
|
---|
| 570 | #
|
---|
| 571 | sed --in-place -e 's,SetUdpActive=no,ReportCheckflags=yes,g' testrc_2
|
---|
| 572 | #
|
---|
| 573 | echo $SHCLT1 >> testrc_2
|
---|
| 574 | echo $SHCLT2 >> testrc_2
|
---|
| 575 |
|
---|
| 576 | echo $SHPW > ./testpw
|
---|
| 577 | }
|
---|
| 578 |
|
---|
| 579 | testrun2g_signrc ()
|
---|
| 580 | {
|
---|
| 581 | scripts/samhainadmin.pl -s ./test/gnupg/ -m R $1 >/dev/null
|
---|
| 582 | scripts/samhainadmin.pl -s ./test/gnupg/ -k 8A0B337A -m E $1 >/dev/null
|
---|
| 583 | }
|
---|
| 584 |
|
---|
| 585 | testrun2g_signdb ()
|
---|
| 586 | {
|
---|
| 587 | scripts/samhainadmin.pl -s ./test/gnupg/ -k 8A0B337A -m E ./.samhain_file >/dev/null
|
---|
| 588 | }
|
---|
| 589 |
|
---|
| 590 | copy_rc_db_files ()
|
---|
| 591 | {
|
---|
| 592 | cp ./testrc_2 ./rc.${SH_LOCALHOST}
|
---|
| 593 | mv ./.samhain_file ./file.${SH_LOCALHOST}
|
---|
| 594 | if [ $? -ne 0 ]; then
|
---|
| 595 | [ -z "$verbose" ] || log_msg_fail "No .samhain_file";
|
---|
| 596 | return 1
|
---|
| 597 | fi
|
---|
| 598 | chmod 644 ./rc.${SH_LOCALHOST}
|
---|
| 599 | chmod 644 ./file.${SH_LOCALHOST}
|
---|
| 600 |
|
---|
| 601 | cp ./testrc_2 "./rc.${ALTHOST}"
|
---|
| 602 | cp ./file.${SH_LOCALHOST} "./file.${ALTHOST}" 2>/dev/null
|
---|
| 603 | chmod 644 ./rc.${ALTHOST}
|
---|
| 604 | chmod 644 ./file.${ALTHOST}
|
---|
| 605 | }
|
---|
| 606 |
|
---|
| 607 | MAXTEST=6; export MAXTEST
|
---|
| 608 |
|
---|
| 609 | testrun2g ()
|
---|
| 610 | {
|
---|
| 611 | log_start "RUN CLIENT/SERVER CASE TWO";
|
---|
| 612 | #
|
---|
| 613 | if [ x"$1" = x ]; then
|
---|
| 614 | [ -z "$quiet" ] && log_msg_fail "Missing hostname"
|
---|
| 615 | fi
|
---|
| 616 | #
|
---|
| 617 | SH_LOCALHOST=$1; export SH_LOCALHOST
|
---|
| 618 | #
|
---|
| 619 |
|
---|
| 620 |
|
---|
| 621 | # Test with missing delta
|
---|
| 622 | #
|
---|
| 623 | gpg --list-keys | grep 8A0B337A >/dev/null 2>&1
|
---|
| 624 | if [ $? -ne 0 ]; then
|
---|
| 625 | echo "You need to do 'gpg --import test/gnupg/public-key.asc' first"
|
---|
| 626 | log_skip 1 $MAXTEST 'Case Two w/signed files'
|
---|
| 627 | else
|
---|
| 628 | testrun2g_build "--with-gpg=/usr/bin/gpg" "--with-keyid=0x8A0B337A"
|
---|
| 629 | if [ $? -eq 0 ]; then
|
---|
| 630 | [ -z "$verbose" ] || log_msg_ok "build..";
|
---|
| 631 | testrun2g_signrc ./testrc_2
|
---|
| 632 | fi
|
---|
| 633 | if [ $? -eq 0 ]; then
|
---|
| 634 | [ -z "$verbose" ] || log_msg_ok "sign rc..";
|
---|
| 635 | testrun2g_prepare
|
---|
| 636 | fi
|
---|
| 637 | if [ $? -eq 0 ]; then
|
---|
| 638 | [ -z "$verbose" ] || log_msg_ok "prepare..";
|
---|
| 639 | testrun2g_signdb
|
---|
| 640 | fi
|
---|
| 641 | if [ $? -eq 0 ]; then
|
---|
| 642 | [ -z "$verbose" ] || log_msg_ok "sign db..";
|
---|
| 643 | copy_rc_db_files
|
---|
| 644 | fi
|
---|
| 645 | if [ $? -eq 0 ]; then
|
---|
| 646 | [ -z "$verbose" ] || log_msg_ok "copy..";
|
---|
| 647 | do_test_2_g_yule_start
|
---|
| 648 | fi
|
---|
| 649 | if [ $? -eq 0 ]; then
|
---|
| 650 | [ -z "$verbose" ] || log_msg_ok "start yule..";
|
---|
| 651 | do_test_2_g_three nodelta
|
---|
| 652 | fi
|
---|
| 653 | if [ $? -eq 0 ]; then
|
---|
| 654 | [ -z "$quiet" ] && log_ok 1 ${MAXTEST} "Case Two w/missing delta";
|
---|
| 655 | else
|
---|
| 656 | [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Case Two w/missing delta";
|
---|
| 657 | fi
|
---|
| 658 | fi
|
---|
| 659 |
|
---|
| 660 | # Test with unsigned delta
|
---|
| 661 | #
|
---|
| 662 | gpg --list-keys | grep 8A0B337A >/dev/null 2>&1
|
---|
| 663 | if [ $? -ne 0 ]; then
|
---|
| 664 | echo "You need to do 'gpg --import test/gnupg/public-key.asc' first"
|
---|
| 665 | log_skip 1 $MAXTEST 'Case Two w/signed files'
|
---|
| 666 | else
|
---|
| 667 | testrun2g_build "--with-gpg=/usr/bin/gpg" "--with-keyid=0x8A0B337A"
|
---|
| 668 | if [ $? -eq 0 ]; then
|
---|
| 669 | [ -z "$verbose" ] || log_msg_ok "build..";
|
---|
| 670 | testrun2g_signrc ./testrc_2
|
---|
| 671 | fi
|
---|
| 672 | if [ $? -eq 0 ]; then
|
---|
| 673 | [ -z "$verbose" ] || log_msg_ok "sign rc..";
|
---|
| 674 | testrun2g_prepare
|
---|
| 675 | fi
|
---|
| 676 | if [ $? -eq 0 ]; then
|
---|
| 677 | [ -z "$verbose" ] || log_msg_ok "prepare..";
|
---|
| 678 | testrun2g_signdb
|
---|
| 679 | fi
|
---|
| 680 | if [ $? -eq 0 ]; then
|
---|
| 681 | [ -z "$verbose" ] || log_msg_ok "sign db..";
|
---|
| 682 | copy_rc_db_files
|
---|
| 683 | fi
|
---|
| 684 | if [ $? -eq 0 ]; then
|
---|
| 685 | [ -z "$verbose" ] || log_msg_ok "copy..";
|
---|
| 686 | do_test_2_g_yule_start
|
---|
| 687 | fi
|
---|
| 688 | if [ $? -eq 0 ]; then
|
---|
| 689 | [ -z "$verbose" ] || log_msg_ok "start yule..";
|
---|
| 690 | do_test_2_g_three nosig
|
---|
| 691 | fi
|
---|
| 692 | if [ $? -eq 0 ]; then
|
---|
| 693 | [ -z "$quiet" ] && log_ok 1 ${MAXTEST} "Case Two w/unsigned delta";
|
---|
| 694 | else
|
---|
| 695 | [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Case Two w/unsigned delta";
|
---|
| 696 | fi
|
---|
| 697 | fi
|
---|
| 698 |
|
---|
| 699 | # Test with signed files, no sig client
|
---|
| 700 | #
|
---|
| 701 | gpg --list-keys | grep 8A0B337A >/dev/null 2>&1
|
---|
| 702 | if [ $? -ne 0 ]; then
|
---|
| 703 | echo "You need to do 'gpg --import test/gnupg/public-key.asc' first"
|
---|
| 704 | log_skip 1 $MAXTEST 'Case Two w/signed files'
|
---|
| 705 | else
|
---|
| 706 | testrun2g_build
|
---|
| 707 | if [ $? -eq 0 ]; then
|
---|
| 708 | [ -z "$verbose" ] || log_msg_ok "build..";
|
---|
| 709 | testrun2g_signrc ./testrc_2
|
---|
| 710 | fi
|
---|
| 711 | if [ $? -eq 0 ]; then
|
---|
| 712 | [ -z "$verbose" ] || log_msg_ok "sign rc..";
|
---|
| 713 | testrun2g_prepare
|
---|
| 714 | fi
|
---|
| 715 | if [ $? -eq 0 ]; then
|
---|
| 716 | [ -z "$verbose" ] || log_msg_ok "prepare..";
|
---|
| 717 | testrun2g_signdb
|
---|
| 718 | fi
|
---|
| 719 | if [ $? -eq 0 ]; then
|
---|
| 720 | [ -z "$verbose" ] || log_msg_ok "sign db..";
|
---|
| 721 | copy_rc_db_files
|
---|
| 722 | fi
|
---|
| 723 | if [ $? -eq 0 ]; then
|
---|
| 724 | [ -z "$verbose" ] || log_msg_ok "copy..";
|
---|
| 725 | do_test_2_g_yule_start
|
---|
| 726 | fi
|
---|
| 727 | if [ $? -eq 0 ]; then
|
---|
| 728 | [ -z "$verbose" ] || log_msg_ok "start yule..";
|
---|
| 729 | do_test_2_g_three
|
---|
| 730 | fi
|
---|
| 731 | if [ $? -eq 0 ]; then
|
---|
| 732 | [ -z "$quiet" ] && log_ok 1 ${MAXTEST} "Case Two w/signed files+nosig client";
|
---|
| 733 | else
|
---|
| 734 | [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Case Two w/signed files+nosig client";
|
---|
| 735 | fi
|
---|
| 736 | fi
|
---|
| 737 |
|
---|
| 738 | # Test with signed files
|
---|
| 739 | #
|
---|
| 740 | gpg --list-keys | grep 8A0B337A >/dev/null 2>&1
|
---|
| 741 | if [ $? -ne 0 ]; then
|
---|
| 742 | echo "You need to do 'gpg --import test/gnupg/public-key.asc' first"
|
---|
| 743 | log_skip 1 $MAXTEST 'Case Two w/signed files'
|
---|
| 744 | else
|
---|
| 745 | testrun2g_build "--with-gpg=/usr/bin/gpg" "--with-keyid=0x8A0B337A"
|
---|
| 746 | if [ $? -eq 0 ]; then
|
---|
| 747 | [ -z "$verbose" ] || log_msg_ok "build..";
|
---|
| 748 | testrun2g_signrc ./testrc_2
|
---|
| 749 | fi
|
---|
| 750 | if [ $? -eq 0 ]; then
|
---|
| 751 | [ -z "$verbose" ] || log_msg_ok "sign rc..";
|
---|
| 752 | testrun2g_prepare
|
---|
| 753 | fi
|
---|
| 754 | if [ $? -eq 0 ]; then
|
---|
| 755 | [ -z "$verbose" ] || log_msg_ok "prepare..";
|
---|
| 756 | testrun2g_signdb
|
---|
| 757 | fi
|
---|
| 758 | if [ $? -eq 0 ]; then
|
---|
| 759 | [ -z "$verbose" ] || log_msg_ok "sign db..";
|
---|
| 760 | copy_rc_db_files
|
---|
| 761 | fi
|
---|
| 762 | if [ $? -eq 0 ]; then
|
---|
| 763 | [ -z "$verbose" ] || log_msg_ok "copy..";
|
---|
| 764 | do_test_2_g_yule_start
|
---|
| 765 | fi
|
---|
| 766 | if [ $? -eq 0 ]; then
|
---|
| 767 | [ -z "$verbose" ] || log_msg_ok "start yule..";
|
---|
| 768 | do_test_2_g_three
|
---|
| 769 | fi
|
---|
| 770 | if [ $? -eq 0 ]; then
|
---|
| 771 | [ -z "$quiet" ] && log_ok 1 ${MAXTEST} "Case Two w/signed files";
|
---|
| 772 | else
|
---|
| 773 | [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Case Two w/signed files";
|
---|
| 774 | fi
|
---|
| 775 | fi
|
---|
| 776 |
|
---|
| 777 | # Test with non-signed files
|
---|
| 778 | #
|
---|
| 779 | testrun2g_build
|
---|
| 780 | if [ $? -eq 0 ]; then
|
---|
| 781 | [ -z "$verbose" ] || log_msg_ok "build..";
|
---|
| 782 | testrun2g_prepare
|
---|
| 783 | fi
|
---|
| 784 | if [ $? -eq 0 ]; then
|
---|
| 785 | [ -z "$verbose" ] || log_msg_ok "prepare..";
|
---|
| 786 | copy_rc_db_files
|
---|
| 787 | fi
|
---|
| 788 | if [ $? -eq 0 ]; then
|
---|
| 789 | [ -z "$verbose" ] || log_msg_ok "copy..";
|
---|
| 790 | do_test_2_g_yule_start
|
---|
| 791 | fi
|
---|
| 792 | if [ $? -eq 0 ]; then
|
---|
| 793 | [ -z "$verbose" ] || log_msg_ok "start yule..";
|
---|
| 794 | do_test_2_g_one
|
---|
| 795 | fi
|
---|
| 796 | if [ $? -eq 0 ]; then
|
---|
| 797 | [ -z "$quiet" ] && log_ok 2 ${MAXTEST} "Case Two w/unsigned files";
|
---|
| 798 | else
|
---|
| 799 | [ -z "$quiet" ] && log_fail 2 ${MAXTEST} "Case Two w/unsigned files";
|
---|
| 800 | fi
|
---|
| 801 |
|
---|
| 802 |
|
---|
| 803 |
|
---|
| 804 | #
|
---|
| 805 | testrun2g_prepare
|
---|
| 806 | if [ $? -eq 0 ]; then
|
---|
| 807 | [ -z "$verbose" ] || log_msg_ok "prepare..";
|
---|
| 808 | copy_rc_db_files
|
---|
| 809 | fi
|
---|
| 810 | if [ $? -eq 0 ]; then
|
---|
| 811 | [ -z "$verbose" ] || log_msg_ok "copy..";
|
---|
| 812 | do_test_2_g_yule_start
|
---|
| 813 | fi
|
---|
| 814 | if [ $? -eq 0 ]; then
|
---|
| 815 | [ -z "$verbose" ] || log_msg_ok "start yule..";
|
---|
| 816 | do_test_2_g_two
|
---|
| 817 | fi
|
---|
| 818 | if [ $? -eq 0 ]; then
|
---|
| 819 | [ -z "$quiet" ] && log_ok 3 ${MAXTEST} "Case Two w/o delta";
|
---|
| 820 | else
|
---|
| 821 | [ -z "$quiet" ] && log_fail 3 ${MAXTEST} "Case Two w/o delta";
|
---|
| 822 | fi
|
---|
| 823 |
|
---|
| 824 |
|
---|
| 825 | log_end "RUN CLIENT/SERVER CASE TWO"
|
---|
| 826 | }
|
---|