[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 | #
|
---|
[1] | 21 |
|
---|
[52] | 22 | MAXTEST=3; export MAXTEST
|
---|
[19] | 23 | LOGFILE="$PW_DIR/.samhain_log"; export LOGFILE
|
---|
| 24 | RCFILE="$PW_DIR/testrc_1.dyn"; export RCFILE
|
---|
[1] | 25 |
|
---|
[19] | 26 | testrun1b_internal ()
|
---|
[1] | 27 | {
|
---|
[19] | 28 | BUILDOPTS="$1"
|
---|
[1] | 29 | #
|
---|
| 30 | # test standalone compilation
|
---|
| 31 | #
|
---|
[19] | 32 | [ -z "$verbose" ] || { echo; echo "${S}Building standalone agent${E}"; echo; }
|
---|
[1] | 33 | #
|
---|
| 34 | if test -r "Makefile"; then
|
---|
[22] | 35 | $MAKE distclean >/dev/null >&1
|
---|
[1] | 36 | fi
|
---|
| 37 | #
|
---|
[159] | 38 | # Bootstrapping
|
---|
[1] | 39 | #
|
---|
[159] | 40 | ${TOP_SRCDIR}/configure >/dev/null 2>/dev/null
|
---|
| 41 | if test x$? = x0; then
|
---|
| 42 | [ -z "$verbose" ] || log_msg_ok "configure (bootstrap)...";
|
---|
| 43 | $MAKE > /dev/null 2>&1
|
---|
| 44 | if test x$? = x0; then
|
---|
| 45 | [ -z "$verbose" ] || log_msg_ok "make (bootstrap)...";
|
---|
| 46 | else
|
---|
| 47 | [ -z "$quiet" ] && log_msg_fail "make (bootstrap)...";
|
---|
| 48 | return 1
|
---|
| 49 | fi
|
---|
| 50 |
|
---|
| 51 | else
|
---|
| 52 | [ -z "$quiet" ] && log_msg_fail "configure (bootstrap)...";
|
---|
| 53 | return 1
|
---|
| 54 | fi
|
---|
[1] | 55 | #
|
---|
| 56 | #
|
---|
[159] | 57 | ${TOP_SRCDIR}/configure ${BUILDOPTS} 2>/dev/null | \
|
---|
| 58 | egrep 'use existing [./[:alnum:]]+ for gpg checksum' >/dev/null
|
---|
| 59 | #
|
---|
| 60 | #
|
---|
[1] | 61 | if test x$? = x0; then
|
---|
[19] | 62 | [ -z "$verbose" ] || log_msg_ok "configure...";
|
---|
[22] | 63 | $MAKE > /dev/null 2>&1
|
---|
[1] | 64 | if test x$? = x0; then
|
---|
[19] | 65 | [ -z "$verbose" ] || log_msg_ok "make...";
|
---|
[1] | 66 | else
|
---|
[19] | 67 | [ -z "$quiet" ] && log_msg_fail "make...";
|
---|
| 68 | return 1
|
---|
[1] | 69 | fi
|
---|
| 70 |
|
---|
| 71 | else
|
---|
[19] | 72 | [ -z "$quiet" ] && log_msg_fail "configure...";
|
---|
| 73 | return 1
|
---|
[1] | 74 | fi
|
---|
| 75 |
|
---|
[19] | 76 | SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' ${SCRIPTDIR}/test.sh`
|
---|
[1] | 77 |
|
---|
[19] | 78 | tail -n "+$SKIP" ${SCRIPTDIR}/test.sh >/dev/null 2>&1
|
---|
| 79 | if [ $? -eq 0 ]; then
|
---|
[159] | 80 | tail -n "+$SKIP" ${SCRIPTDIR}/test.sh | gunzip -c - 2>/dev/null | tar xf - && \
|
---|
[19] | 81 | mv "./testrc.gpg.asc" "$RCFILE"
|
---|
| 82 | else
|
---|
[159] | 83 | tail "+$SKIP" ${SCRIPTDIR}/test.sh | gunzip -c - 2>/dev/null | tar xf - && \
|
---|
[19] | 84 | mv "./testrc.gpg.asc" "$RCFILE"
|
---|
| 85 | fi
|
---|
| 86 | if test x$? = x0; then
|
---|
| 87 | [ -z "$verbose" ] || log_msg_ok "extract gpg signed files...";
|
---|
| 88 | else
|
---|
| 89 | [ -z "$quiet" ] && log_msg_fail "extract gpg signed files...";
|
---|
| 90 | return 1
|
---|
| 91 | fi
|
---|
| 92 |
|
---|
[52] | 93 | if test "x$2" = "x"; then
|
---|
| 94 | :
|
---|
| 95 | else
|
---|
| 96 | CONVERT="$2"
|
---|
| 97 | if test -f "${TOP_SRCDIR}/stealth_template.jpg"; then
|
---|
| 98 | [ -z "$verbose" ] || log_msg_ok "convert..."
|
---|
| 99 | "${CONVERT}" +compress "${TOP_SRCDIR}/stealth_template.jpg" stealth_template.ps >/dev/null
|
---|
| 100 | else
|
---|
| 101 | [ -z "$quiet" ] && log_msg_fail "cannot find file stealth_template.jpg"
|
---|
| 102 | return 1
|
---|
| 103 | fi
|
---|
| 104 | if [ $? -ne 0 ]; then
|
---|
| 105 | [ -z "$quiet" ] && log_msg_fail "${CONVERT} +compress ${TOP_SRCDIR}/stealth_template.jpg stealth_template.ps";
|
---|
| 106 | return 1
|
---|
| 107 | fi
|
---|
| 108 |
|
---|
| 109 | [ -z "$verbose" ] || log_msg_ok "hide..."
|
---|
| 110 | ./samhain_stealth -s stealth_template.ps "$RCFILE" >/dev/null
|
---|
| 111 | if [ $? -ne 0 ]; then
|
---|
| 112 | [ -z "$quiet" ] && log_msg_fail "${CONVERT} +compress ${TOP_SRCDIR}/stealth_template.jpg stealth_template.ps";
|
---|
| 113 | return 1
|
---|
| 114 | fi
|
---|
| 115 |
|
---|
| 116 | mv -f stealth_template.ps "$RCFILE"
|
---|
| 117 | if [ $? -ne 0 ]; then
|
---|
| 118 | [ -z "$quiet" ] && log_msg_fail "mv -f stealth_template.ps $RCFILE";
|
---|
| 119 | return 1
|
---|
| 120 | fi
|
---|
| 121 |
|
---|
| 122 | fi
|
---|
| 123 |
|
---|
[1] | 124 | rm -f ./.samhain_file
|
---|
| 125 | rm -f ./.samhain_log
|
---|
| 126 | rm -f ./.samhain_lock
|
---|
| 127 |
|
---|
[19] | 128 | ./samhain -t init -p none -l info
|
---|
[1] | 129 |
|
---|
| 130 | if test x$? = x0; then
|
---|
[19] | 131 | [ -z "$verbose" ] || log_msg_ok "init...";
|
---|
| 132 | else
|
---|
| 133 | [ -z "$quiet" ] && log_msg_fail "init...";
|
---|
| 134 | return 1
|
---|
| 135 | fi
|
---|
[1] | 136 |
|
---|
[19] | 137 | mv $PW_DIR/.samhain_file.asc $PW_DIR/.samhain_file
|
---|
| 138 | }
|
---|
[1] | 139 |
|
---|
[19] | 140 | do_test_1b () {
|
---|
| 141 |
|
---|
| 142 | ./samhain -t check -p none -l info
|
---|
| 143 |
|
---|
| 144 | if test x$? = x0; then
|
---|
| 145 | ./samhain -j -L $LOGFILE >"${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "${LOGFILE}"
|
---|
| 146 | if [ $? -ne 0 ]; then
|
---|
| 147 | [ -z "$quiet" ] && log_msg_fail "mv logfile...";
|
---|
| 148 | return 1
|
---|
[1] | 149 | fi
|
---|
[19] | 150 | [ -z "$verbose" ] || log_msg_ok "check...";
|
---|
| 151 | else
|
---|
| 152 | [ -z "$quiet" ] && log_msg_fail "check...";
|
---|
| 153 | return 1
|
---|
| 154 | fi
|
---|
| 155 | #
|
---|
| 156 | tmp=`egrep "Checking.*/etc(>|\")" $LOGFILE 2>/dev/null | wc -l`
|
---|
| 157 | if [ $tmp -ne 2 ]; then
|
---|
| 158 | [ -z "$verbose" ] || log_msg_fail "/etc";
|
---|
[60] | 159 | return 1
|
---|
[19] | 160 | fi
|
---|
| 161 | tmp=`egrep "Checking.*(>|\")" $LOGFILE 2>/dev/null | wc -l`
|
---|
[60] | 162 | if [ $tmp -ne 8 ]; then
|
---|
[19] | 163 | [ -z "$verbose" ] || log_msg_fail "checking";
|
---|
[60] | 164 | return 1
|
---|
[19] | 165 | fi
|
---|
[60] | 166 | egrep "ADDED" $LOGFILE >/dev/null 2>&1
|
---|
| 167 | if [ $? -eq 0 ]; then
|
---|
| 168 | [ -z "$verbose" ] || log_msg_fail "init was incomplete";
|
---|
| 169 | return 1
|
---|
| 170 | fi
|
---|
[19] | 171 | #
|
---|
| 172 | return 0
|
---|
[1] | 173 | }
|
---|
| 174 |
|
---|
[19] | 175 | do_test_1b_2 () {
|
---|
[1] | 176 |
|
---|
[19] | 177 | rm -f $PW_DIR/test_log_prelude
|
---|
[1] | 178 |
|
---|
[20] | 179 | "$PM" --textmod -l $PW_DIR/test_log_prelude --listen 127.0.0.1:5500 >/dev/null 2>&1 &
|
---|
[19] | 180 | PID=$!
|
---|
[1] | 181 |
|
---|
[51] | 182 | five_sec_sleep
|
---|
[20] | 183 |
|
---|
| 184 | ./samhain -t check -p none -l info --set-prelude-severity=info --prelude --server-addr 127.0.0.1:5500 >/dev/null
|
---|
[19] | 185 |
|
---|
| 186 | if test x$? = x0; then
|
---|
| 187 | ./samhain -j -L $LOGFILE >"${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "${LOGFILE}"
|
---|
| 188 | if [ $? -ne 0 ]; then
|
---|
| 189 | [ -z "$quiet" ] && log_msg_fail "mv logfile...";
|
---|
| 190 | kill $PID
|
---|
| 191 | return 1
|
---|
| 192 | fi
|
---|
| 193 | [ -z "$verbose" ] || log_msg_ok "check...";
|
---|
| 194 | else
|
---|
| 195 | [ -z "$quiet" ] && log_msg_fail "check...";
|
---|
| 196 | kill $PID
|
---|
| 197 | return 1
|
---|
| 198 | fi
|
---|
| 199 | #
|
---|
| 200 | tmp=`egrep 'File original:.*name=etc.*path=/etc' test_log_prelude 2>/dev/null | wc -l`
|
---|
[81] | 201 | if [ $tmp -lt 1 ]; then
|
---|
[19] | 202 | [ -z "$verbose" ] || log_msg_fail "/etc";
|
---|
| 203 | fi
|
---|
| 204 | tmp=`egrep 'Classification text: Checking' test_log_prelude 2>/dev/null | wc -l`
|
---|
[81] | 205 | if [ $tmp -lt 1 ]; then
|
---|
[19] | 206 | [ -z "$verbose" ] || log_msg_fail "checking";
|
---|
| 207 | fi
|
---|
| 208 | tmp=`egrep 'Classification text: Checking' test_log_prelude 2>/dev/null | wc -l`
|
---|
[81] | 209 | if [ $tmp -lt 1 ]; then
|
---|
[19] | 210 | [ -z "$verbose" ] || log_msg_fail "checking";
|
---|
| 211 | fi
|
---|
| 212 | #
|
---|
| 213 | kill $PID
|
---|
| 214 | return 0
|
---|
| 215 | }
|
---|
[1] | 216 |
|
---|
[19] | 217 | testrun1b ()
|
---|
| 218 | {
|
---|
| 219 | log_start "RUN STANDALONE W/STEALTH W/GPG"
|
---|
| 220 | GPG=`find_path gpg`
|
---|
| 221 | if [ -z "$GPG" ]; then
|
---|
| 222 | log_skip 1 $MAXTEST 'gpg not found in $PATH'
|
---|
| 223 | log_skip 2 $MAXTEST 'gpg not found in $PATH'
|
---|
[100] | 224 | log_skip 3 $MAXTEST 'gpg not found in $PATH'
|
---|
[19] | 225 | else
|
---|
| 226 | eval "$GPG" --list-keys 0F571F6C >/dev/null 2>/dev/null
|
---|
| 227 | if [ $? -ne 0 ]; then
|
---|
| 228 | log_skip 1 $MAXTEST 'public PGP key 0x0F571F6C not present'
|
---|
| 229 | log_skip 2 $MAXTEST 'public PGP key 0x0F571F6C not present'
|
---|
[100] | 230 | log_skip 3 $MAXTEST 'public PGP key 0x0F571F6C not present'
|
---|
[19] | 231 | else
|
---|
[52] | 232 | #
|
---|
| 233 | # ------------- first test -------------
|
---|
| 234 | #
|
---|
[159] | 235 | BUILDOPTS="--quiet $TRUST --enable-debug --with-gpg=${GPG} --with-checksum --enable-micro-stealth=137 --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
|
---|
[52] | 236 | testrun1b_internal "${BUILDOPTS}"
|
---|
[19] | 237 | do_test_1b
|
---|
| 238 | if [ $? -eq 0 ]; then
|
---|
| 239 | log_ok 1 $MAXTEST 'gpg signed config/database files'
|
---|
| 240 | else
|
---|
| 241 | log_fail 1 $MAXTEST 'gpg signed config/database files'
|
---|
| 242 | fi
|
---|
[52] | 243 |
|
---|
| 244 |
|
---|
| 245 | #
|
---|
| 246 | # ------------- second test -------------
|
---|
| 247 | #
|
---|
| 248 | PRECONV=`find_path convert`
|
---|
| 249 | "${PRECONV}" --help | grep ImageMagick >/dev/null 2>&1 && \
|
---|
| 250 | CONVERT="${PRECONV}"
|
---|
| 251 |
|
---|
| 252 | if [ -z "$CONVERT" ]; then
|
---|
| 253 | log_skip 2 $MAXTEST 'ImageMagick convert not found in $PATH'
|
---|
| 254 | else
|
---|
[159] | 255 | BUILDOPTS="--quiet $TRUST --enable-debug --with-gpg=${GPG} --with-checksum --enable-stealth=137 --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
|
---|
[52] | 256 | testrun1b_internal "${BUILDOPTS}" "$CONVERT"
|
---|
| 257 | do_test_1b
|
---|
| 258 | if [ $? -eq 0 ]; then
|
---|
| 259 | log_ok 2 $MAXTEST 'gpg signed config/database files'
|
---|
| 260 | else
|
---|
| 261 | log_fail 2 $MAXTEST 'gpg signed config/database files'
|
---|
| 262 | fi
|
---|
| 263 | fi
|
---|
| 264 |
|
---|
| 265 |
|
---|
| 266 | #
|
---|
| 267 | # ------------- third test -------------
|
---|
| 268 | #
|
---|
[97] | 269 | if test -f /usr/local/lib/libprelude.so
|
---|
[96] | 270 | then
|
---|
| 271 | LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
|
---|
| 272 | export LD_LIBRARY_PATH
|
---|
| 273 | fi
|
---|
| 274 | #
|
---|
[19] | 275 | PM=`find_path prelude-manager`
|
---|
| 276 | if [ -z "$PM" ]; then
|
---|
[52] | 277 | log_skip 3 $MAXTEST 'prelude-manager not found in $PATH'
|
---|
[19] | 278 | elif [ -z "$doall" ]; then
|
---|
[52] | 279 | log_skip 3 $MAXTEST 'logging to prelude (or use --really-all)'
|
---|
[19] | 280 | else
|
---|
[159] | 281 | BUILDOPTS="--quiet $TRUST --enable-debug --with-prelude --with-gpg=${GPG} --with-checksum --enable-micro-stealth=137 --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
|
---|
[20] | 282 | testrun1b_internal "${BUILDOPTS} CFLAGS=-DSH_NOFAILOVER=1"
|
---|
[19] | 283 | do_test_1b_2
|
---|
| 284 | if [ $? -eq 0 ]; then
|
---|
[52] | 285 | log_ok 3 $MAXTEST 'logging to prelude'
|
---|
[19] | 286 | else
|
---|
[52] | 287 | log_fail 3 $MAXTEST 'logging to prelude'
|
---|
[19] | 288 | fi
|
---|
| 289 | fi
|
---|
| 290 | fi
|
---|
| 291 | fi
|
---|
| 292 | log_end "RUN STANDALONE W/STEALTH W/GPG"
|
---|
| 293 | return 0
|
---|
| 294 | }
|
---|
[1] | 295 |
|
---|