summaryrefslogtreecommitdiffstats
path: root/test/testhash.sh
blob: c2e20f4ddaba012f570697f62c7c25d6f545785c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#! /bin/sh

#
# Copyright Rainer Wichmann (2006)
#
# License Information:
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

RCFILE="$PW_DIR/testrc_1.dyn";  export RCFILE
LOGFILE="$PW_DIR/.samhain_log"; export LOGFILE

MAXTEST=2; export MAXTEST

testhash ()
{
	log_start "HASH FUNCTION"

	C_LOGFILE=""

	ls /lib/libpcre* >/dev/null 2>&1
	if [ $? -eq 0 ]; then
	    C_LOGFILE=" --enable-logfile-monitor "
	else
	    ls /usr/lib/libpcre* >/dev/null 2>&1
	    if [ $? -eq 0 ]; then
		C_LOGFILE=" --enable-logfile-monitor "
	    else
                ls /usr/lib/*/libpcre* >/dev/null 2>&1
                if [ $? -eq 0 ]; then
                    C_LOGFILE=" --enable-logfile-monitor "
                else
                    ls /usr/local/lib/libpcre* >/dev/null 2>&1
                    if [ $? -eq 0 ]; then
                        C_LOGFILE=" --enable-logfile-monitor "
                    fi
                fi
	    fi
	fi
	if [ x"${C_LOGFILE}" = x ]; then
	    log_msg_ok  "Not testing  --enable-logfile-monitor";
	fi

	#
	# test standalone compilation
	#
	TEST="${S}standalone agent${E}"
	#
	if test -r "Makefile"; then
		$MAKE distclean
	fi
	#
	${TOP_SRCDIR}/configure --enable-debug=gdb --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-db-reload '--enable-login-watch' '--enable-mounts-check' ${C_LOGFILE} '--enable-port-check' '--enable-process-check' '--enable-message-queue' '--enable-suidcheck' '--disable-dnmalloc'
	#
	fail=0
	#
	if test x$? = x0; then
		[ -z "$verbose" ] || log_msg_ok  "configure...";
		$MAKE  > /dev/null 2>> test_log
		if test x$? = x0; then
		    [ -z "$verbose" ] || log_msg_ok "make...";
 		else
		    [ -z "$quiet" ] &&   log_msg_fail "make...";
		    fail=1
		fi
	else
		[ -z "$quiet" ] && log_msg_fail "configure...";
		fail=1
	fi
	#
	if [ $fail -eq 1 ]; then
	    [ -z "$quiet" ] && log_fail 1 ${MAXTEST};
	    return 1
	fi
	#
	echo "Test results of the TIGER hash algorithm" > testhash.tmp
	echo >> testhash.tmp
	echo "(use samhain -H string to test)" >> testhash.tmp
	echo >> testhash.tmp
	./samhain -H "" >> testhash.tmp
	./samhain -H "abc" >> testhash.tmp
	./samhain -H "Tiger" >> testhash.tmp
	./samhain -H "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-" >> testhash.tmp
	./samhain -H "ABCDEFGHIJKLMNOPQRSTUVWXYZ=abcdefghijklmnopqrstuvwxyz+0123456789" >> testhash.tmp
	./samhain -H "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham" >> testhash.tmp
	./samhain -H "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, proceedings of Fast Software Encryption 3, Cambridge." >> testhash.tmp
	./samhain -H "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, proceedings of Fast Software Encryption 3, Cambridge, 1996." >> testhash.tmp
	./samhain -H "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-" >> testhash.tmp
	#
	RESU=`diff testhash.tmp ${SCRIPTDIR}/testtiger.txt 2>/dev/null`
	if test "x${RESU}" = "x"; then
	    [ -z "$quiet" ] && log_ok   1 ${MAXTEST};
	else
	    [ -z "$quiet" ] && log_fail 1 ${MAXTEST};
	    return 1
	fi
        #
        #
        #
        TEST="${S}files${E}"
        #
        case $SCRIPTDIR in
            /*)
                testpath="${SCRIPTDIR}/testtiger.txt";;
            *)
                testpath="`pwd`/${SCRIPTDIR}/testtiger.txt";;
        esac
        #
        RESU=`./samhain -H ${testpath}`
        #
        if test x"$RESU" = x"${testpath}: 8125E439 4E7E20F9 24FD8E37  BC4D90C7 FC67F40C 1681F05D"; then
            [ -z "$quiet" ] && log_ok   2 ${MAXTEST};
        else
            [ -z "$quiet" ] && log_fail 2 ${MAXTEST};
            return 1
        fi
        #
	log_end "HASH FUNCTION"
	return 0
}