[550] | 1 | #! /bin/sh
|
---|
| 2 |
|
---|
| 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 |
|
---|
| 22 | RCFILE="$PW_DIR/testrc_1.dyn"; export RCFILE
|
---|
| 23 | LOGFILE="$PW_DIR/.samhain_log"; export LOGFILE
|
---|
| 24 |
|
---|
| 25 | # --enable-login-watch --enable-xml-log
|
---|
| 26 | # --enable-debug --enable-suidcheck --with-prelude
|
---|
| 27 |
|
---|
| 28 | BUILDOPTS="--quiet $TRUST --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-debug --with-gpg=/usr/bin/gpg --with-keyid=0x8A0B337A --with-fp=DCCBBB6625591ECE2B8F3AC94ED99E4E8A0B337A"
|
---|
| 29 | export BUILDOPTS
|
---|
| 30 |
|
---|
| 31 | BASE="${PW_DIR}/testrun_testdata"; export BASE
|
---|
| 32 | TDIRS="a b c a/a a/b a/c a/a/a a/a/b a/a/c a/a/a/a a/a/a/b a/a/a/c"; export TDIRS
|
---|
| 33 | TFILES="x y z"; export TFILES
|
---|
| 34 |
|
---|
| 35 | ###########################################################
|
---|
| 36 | #
|
---|
| 37 | # ---- [Define tests here] ----
|
---|
| 38 | #
|
---|
| 39 |
|
---|
| 40 | # 1 for testing new tests
|
---|
| 41 | testrun1_setup=0
|
---|
| 42 |
|
---|
| 43 | MAXTEST=17; export MAXTEST
|
---|
| 44 |
|
---|
| 45 | TESTPOLICY_17="
|
---|
| 46 | [ReadOnly]
|
---|
| 47 | dir=${BASE}
|
---|
| 48 | "
|
---|
| 49 | mod_testdata_17 () {
|
---|
| 50 | one_sec_sleep
|
---|
| 51 | rm "${BASE}/a/a/c/x" # delete
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | TESTPOLICY_16="
|
---|
| 55 | [ReadOnly]
|
---|
| 56 | dir=${BASE}
|
---|
| 57 | "
|
---|
| 58 | mod_testdata_16 () {
|
---|
| 59 | one_sec_sleep
|
---|
| 60 | echo "foobar" > "${BASE}/foo" # new
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | prep_sign_file ()
|
---|
| 64 | {
|
---|
| 65 | scripts/samhainadmin.pl -s ./test/gnupg/ -m R $1 >/dev/null
|
---|
| 66 | scripts/samhainadmin.pl -s ./test/gnupg/ -k 8A0B337A -m E $1 >/dev/null
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 | run_check_CLverify ()
|
---|
| 71 | {
|
---|
| 72 | if [ "x$1" = "x" ]; then
|
---|
| 73 | logsev=debug
|
---|
| 74 | else
|
---|
| 75 | logsev=$1
|
---|
| 76 | fi
|
---|
| 77 | if test -f ./.samhain_file; then
|
---|
| 78 | mv ./.samhain_file ./.samhain_file_clverify
|
---|
| 79 | if [ $? -ne 0 ]; then
|
---|
| 80 | [ -z "$quiet" ] && log_msg_fail "mv ./.samhain_file ...";
|
---|
| 81 | return 1
|
---|
| 82 | fi
|
---|
| 83 | else
|
---|
| 84 | [ -z "$quiet" ] && log_msg_fail "test -f ./.samhain_file ...";
|
---|
| 85 | return 1
|
---|
| 86 | fi
|
---|
| 87 |
|
---|
| 88 | rm -f test_log_valgrind
|
---|
| 89 |
|
---|
| 90 | ${VALGRIND} ./samhain -p =err --verify-database ./.samhain_file_clverify 2>>test_log_valgrind
|
---|
| 91 |
|
---|
| 92 | if test x$? = x0; then
|
---|
| 93 | if [ "x$2" != "xnullok" ]; then
|
---|
| 94 | [ -z "$quiet" ] && log_msg_fail "check (1)...";
|
---|
| 95 | return 1
|
---|
| 96 | fi
|
---|
| 97 | else
|
---|
| 98 | if [ "x$2" = "xnullok" ]; then
|
---|
| 99 | [ -z "$quiet" ] && log_msg_fail "check (1)...";
|
---|
| 100 | return 1
|
---|
| 101 | fi
|
---|
| 102 | fi
|
---|
| 103 |
|
---|
| 104 | LL=`wc -l test_log_valgrind | awk '{ print $1; }'`
|
---|
| 105 | if ! test x$LL = x0; then
|
---|
| 106 | [ -z "$quiet" ] && log_msg_fail "check (2)...";
|
---|
| 107 | [ -z "$quiet" ] && cat test_log_valgrind
|
---|
| 108 | return 1
|
---|
| 109 | fi
|
---|
| 110 |
|
---|
| 111 | [ -z "$verbose" ] || log_msg_ok "check...";
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | run_update_CLverify ()
|
---|
| 115 | {
|
---|
| 116 | if test -f ./.samhain_file_clverify; then
|
---|
| 117 | mv ./.samhain_file_clverify ./.samhain_file
|
---|
| 118 | if [ $? -ne 0 ]; then
|
---|
| 119 | [ -z "$quiet" ] && log_msg_fail "mv ./.samhain_file_clverify ...";
|
---|
| 120 | return 1
|
---|
| 121 | fi
|
---|
| 122 | else
|
---|
| 123 | [ -z "$quiet" ] && log_msg_fail "test -f ./.samhain_file_clverify ...";
|
---|
| 124 | return 1
|
---|
| 125 | fi
|
---|
| 126 |
|
---|
| 127 | ${VALGRIND} ./samhain -t update -p none -l debug 2>>test_log_valgrind
|
---|
| 128 |
|
---|
| 129 | if test x$? = x0; then
|
---|
| 130 | [ -z "$verbose" ] || log_msg_ok "update...";
|
---|
| 131 | else
|
---|
| 132 | [ -z "$quiet" ] && log_msg_fail "update...";
|
---|
| 133 | return 1
|
---|
| 134 | fi
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | run_check_after_update_CLverify ()
|
---|
| 138 | {
|
---|
| 139 | rm -rf $LOGFILE
|
---|
| 140 |
|
---|
| 141 | run_check_CLverify debug nullok
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | testrun_internal_CLverify ()
|
---|
| 145 | {
|
---|
| 146 | [ -z "$verbose" ] || echo Working directory: $PW_DIR
|
---|
| 147 | [ -z "$verbose" ] || { echo MAKE is $MAKE; echo; }
|
---|
| 148 |
|
---|
| 149 | #
|
---|
| 150 | # test standalone compilation
|
---|
| 151 | #
|
---|
| 152 | [ -z "$verbose" ] || { echo; echo "${S}Building standalone agent${E}"; echo; }
|
---|
| 153 |
|
---|
| 154 | if test -r "Makefile"; then
|
---|
| 155 | $MAKE distclean >/dev/null
|
---|
| 156 | fi
|
---|
| 157 |
|
---|
| 158 | ${TOP_SRCDIR}/configure ${BUILDOPTS}
|
---|
| 159 |
|
---|
| 160 | #
|
---|
| 161 | if test x$? = x0; then
|
---|
| 162 | [ -z "$verbose" ] || log_msg_ok "configure...";
|
---|
| 163 | $MAKE >/dev/null 2>>test_log
|
---|
| 164 | if test x$? = x0; then
|
---|
| 165 | [ -z "$verbose" ] || log_msg_ok "make...";
|
---|
| 166 | else
|
---|
| 167 | [ -z "$quiet" ] && log_msg_fail "make...";
|
---|
| 168 | return 1
|
---|
| 169 | fi
|
---|
| 170 |
|
---|
| 171 | else
|
---|
| 172 | [ -z "$quiet" ] && log_msg_fail "configure...";
|
---|
| 173 | return 1
|
---|
| 174 | fi
|
---|
| 175 |
|
---|
| 176 | [ -z "$verbose" ] || { echo; echo "${S}Running test suite${E}"; echo; }
|
---|
| 177 |
|
---|
| 178 | tcount=1
|
---|
| 179 | POLICY=`eval echo '"$'"TESTPOLICY_$tcount"'"'`
|
---|
| 180 |
|
---|
| 181 | until [ -z "$POLICY" ]
|
---|
| 182 | do
|
---|
| 183 | prep_init
|
---|
| 184 | check_err $? ${tcount}; errval=$?
|
---|
| 185 | if [ $errval -eq 0 ]; then
|
---|
| 186 | prep_testdata
|
---|
| 187 | check_err $? ${tcount}; errval=$?
|
---|
| 188 | fi
|
---|
| 189 | if [ $errval -eq 0 ]; then
|
---|
| 190 | prep_testpolicy ${tcount}
|
---|
| 191 | check_err $? ${tcount}; errval=$?
|
---|
| 192 | fi
|
---|
| 193 | if [ $errval -eq 0 ]; then
|
---|
| 194 | prep_sign_file "${RCFILE}"
|
---|
| 195 | check_err $? ${tcount}; errval=$?
|
---|
| 196 | fi
|
---|
| 197 | if [ $errval -eq 0 ]; then
|
---|
| 198 | run_init
|
---|
| 199 | check_err $? ${tcount}; errval=$?
|
---|
| 200 | fi
|
---|
| 201 | if [ $errval -eq 0 ]; then
|
---|
| 202 | prep_sign_file ./.samhain_file
|
---|
| 203 | check_err $? ${tcount}; errval=$?
|
---|
| 204 | fi
|
---|
| 205 | if [ $errval -eq 0 ]; then
|
---|
| 206 | eval mod_testdata_${tcount}
|
---|
| 207 | check_err $? ${tcount}; errval=$?
|
---|
| 208 | fi
|
---|
| 209 | if [ $errval -eq 0 ]; then
|
---|
| 210 | run_check_CLverify
|
---|
| 211 | check_err $? ${tcount}; errval=$?
|
---|
| 212 | fi
|
---|
| 213 | if [ $testrun1_setup -eq 0 ]; then
|
---|
| 214 | if [ $errval -eq 0 ]; then
|
---|
| 215 | prep_sign_file "${RCFILE}"
|
---|
| 216 | check_err $? ${tcount}; errval=$?
|
---|
| 217 | fi
|
---|
| 218 | if [ $errval -eq 0 ]; then
|
---|
| 219 | run_update_CLverify
|
---|
| 220 | check_err $? ${tcount}; errval=$?
|
---|
| 221 | fi
|
---|
| 222 | if [ $errval -eq 0 ]; then
|
---|
| 223 | prep_sign_file ./.samhain_file
|
---|
| 224 | check_err $? ${tcount}; errval=$?
|
---|
| 225 | fi
|
---|
| 226 | if [ $errval -eq 0 ]; then
|
---|
| 227 | run_check_after_update_CLverify
|
---|
| 228 | check_err $? ${tcount}; errval=$?
|
---|
| 229 | fi
|
---|
| 230 | fi
|
---|
| 231 | #
|
---|
| 232 | if [ $errval -eq 0 ]; then
|
---|
| 233 | [ -z "$quiet" ] && log_ok ${tcount} ${MAXTEST};
|
---|
| 234 | fi
|
---|
| 235 | #
|
---|
| 236 | let "tcount = tcount + 1" >/dev/null
|
---|
| 237 | #
|
---|
| 238 | if [ $tcount -eq 10 ]; then
|
---|
| 239 | if [ -z "$doall" ]; then
|
---|
| 240 | log_skip 10 $MAXTEST 'ACL/SELinux test (or use --really-all)'
|
---|
| 241 | log_skip 11 $MAXTEST 'ACL/SELinux test (or use --really-all)'
|
---|
| 242 | let "tcount = tcount + 2" >/dev/null
|
---|
| 243 | else
|
---|
| 244 | # 'id -u' is posix
|
---|
| 245 | #
|
---|
| 246 | if test -f /usr/xpg4/bin/id
|
---|
| 247 | then
|
---|
| 248 | my_uid=`/usr/xpg4/bin/id -u`
|
---|
| 249 | else
|
---|
| 250 | my_uid=`id -u`
|
---|
| 251 | fi
|
---|
| 252 | #
|
---|
| 253 | if [ ${my_uid} -ne 0 ]; then
|
---|
| 254 | log_skip 10 $MAXTEST 'ACL/SELinux test (you are not root)'
|
---|
| 255 | log_skip 11 $MAXTEST 'ACL/SELinux test (you are not root)'
|
---|
| 256 | let "tcount = tcount + 2" >/dev/null
|
---|
| 257 | else
|
---|
| 258 |
|
---|
| 259 | SETFATTR=`find_path setfattr`
|
---|
| 260 | if [ -z "$SETFATTR" ]; then
|
---|
| 261 | log_skip 10 $MAXTEST 'ACL/SELinux test (setfattr not in path)'
|
---|
| 262 | log_skip 11 $MAXTEST 'ACL/SELinux test (setfattr not in path)'
|
---|
| 263 | let "tcount = tcount + 2" >/dev/null
|
---|
| 264 | fi
|
---|
| 265 | fi
|
---|
| 266 | fi
|
---|
| 267 | fi
|
---|
| 268 | #
|
---|
| 269 | POLICY=`eval echo '"$'"TESTPOLICY_$tcount"'"'`
|
---|
| 270 | done
|
---|
| 271 |
|
---|
| 272 | return 0
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | testrun1f ()
|
---|
| 276 | {
|
---|
| 277 | log_start "RUN CL Verify"
|
---|
| 278 | gpg --list-keys | grep 8A0B337A >/dev/null 2>&1
|
---|
| 279 | if [ $? -ne 0 ]; then
|
---|
| 280 | echo "You need to do 'gpg --import test/gnupg/public-key.asc' first"
|
---|
| 281 | for ff in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17; do
|
---|
| 282 | log_skip $ff $MAXTEST 'CL verify'
|
---|
| 283 | done
|
---|
| 284 | else
|
---|
| 285 | testrun_internal_CLverify
|
---|
| 286 | fi
|
---|
| 287 | log_end "RUN CL Verify"
|
---|
| 288 | return 0
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 |
|
---|
| 292 |
|
---|