summaryrefslogtreecommitdiffstats
path: root/test/testrun_1i.sh
blob: 2eb3bd54675d3ab59fdf898862b0ff6107a80dba (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#! /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.
#

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

testrun1b_modrc ()
{
        ORIGINAL="\[EOF\]"
        REPLACEMENT="\[PortCheck\]"
        ex -s $RCFILE <<EOF
%s/$ORIGINAL/$REPLACEMENT/g
wq
EOF

        echo "PortCheckActive = yes" >>"$RCFILE"
        echo "PortCheckInterface = 127.0.0.1" >>"$RCFILE"
}

testrun1b_internal ()
{
	BUILDOPTS="$1"
	#
	# test standalone compilation
	#
	[ -z "$verbose" ] || { echo; echo "${S}Building standalone agent${E}"; echo; }
	#
	if test -r "Makefile"; then
		$MAKE distclean >/dev/null >&1
	fi
	#
	# Bootstrapping
	#
	${TOP_SRCDIR}/configure >/dev/null 2>/dev/null
	if test x$? = x0; then
		[ -z "$verbose" ] ||     log_msg_ok "configure (bootstrap)..."; 
		$MAKE  > /dev/null 2>&1
		if test x$? = x0; then
		    [ -z "$verbose" ] || log_msg_ok "make (bootstrap)..."; 
		else
		    [ -z "$quiet" ] &&   log_msg_fail "make (bootstrap)..."; 
		    return 1
		fi

	else
		[ -z "$quiet" ] &&       log_msg_fail "configure (bootstrap)...";
		return 1
	fi
	#
	#
	${TOP_SRCDIR}/configure ${BUILDOPTS} 2>/dev/null
	#
	#
	if test x$? = x0; then
		[ -z "$verbose" ] ||     log_msg_ok "configure..."; 
		$MAKE  > /dev/null 2>&1
		if test x$? = x0; then
		    [ -z "$verbose" ] || log_msg_ok "make..."; 
		else
		    [ -z "$quiet" ] &&   log_msg_fail "make..."; 
		    return 1
		fi

	else
		[ -z "$quiet" ] &&       log_msg_fail "configure...";
		return 1
	fi

	cp ${SCRIPTDIR}/testrc_1i.dyn "$RCFILE"
	

	if test x$? = x0; then
	    [ -z "$verbose" ] || log_msg_ok    "copy signed config file...";
	else
	    [ -z "$quiet" ]   && log_msg_fail  "copy signed config file...";
	    return 1
	fi

	if test "x$2" = "x"; then
	    :
	else
	    CONVERT="$2"
	    if test -f "${TOP_SRCDIR}/stealth_template.jpg"; then
		[ -z "$verbose" ] || log_msg_ok "convert..."
		"${CONVERT}" +compress "${TOP_SRCDIR}/stealth_template.jpg" stealth_template.ps >/dev/null
	    else
		[ -z "$quiet" ]   && log_msg_fail  "cannot find file stealth_template.jpg"
		return 1
	    fi
	    if [ $? -ne 0 ]; then
		[ -z "$quiet" ]   && log_msg_fail  "${CONVERT} +compress ${TOP_SRCDIR}/stealth_template.jpg stealth_template.ps";
		return 1
	    fi

	    [ -z "$verbose" ] || log_msg_ok "hide..."
	    ./samhain_stealth -s stealth_template.ps "$RCFILE" >/dev/null
	    if [ $? -ne 0 ]; then
		[ -z "$quiet" ]   && log_msg_fail  "${CONVERT} +compress ${TOP_SRCDIR}/stealth_template.jpg stealth_template.ps";
		return 1
	    fi

	    mv -f stealth_template.ps "$RCFILE"
	    if [ $? -ne 0 ]; then
		[ -z "$quiet" ]   && log_msg_fail  "mv -f stealth_template.ps $RCFILE";
		return 1
	    fi

	fi

	rm -f ./.samhain_file
	rm -f ./.samhain_log
	rm -f ./.samhain_lock

	./samhain -t init -p none -l info

	if test x$? = x0; then
	    [ -z "$verbose" ] || log_msg_ok    "init...";
	else
	    [ -z "$quiet" ]   && log_msg_fail  "init...";
	    return 1
	fi

	cp ${SCRIPTDIR}/test1i_file.sig $PW_DIR/.samhain_file
	if test x$? = x0; then
	    [ -z "$verbose" ] || log_msg_ok    "copy signed database file...";
	else
	    [ -z "$quiet" ]   && log_msg_fail  "copy signed database file...";
	    return 1
	fi
}

testrun1b_nogpg ()
{
	BUILDOPTS="$1"
	#
	# test standalone compilation
	#
	[ -z "$verbose" ] || { echo; echo "${S}Building standalone agent${E}"; echo; }
	#
	if test -r "Makefile"; then
		$MAKE distclean >/dev/null >&1
	fi

	${TOP_SRCDIR}/configure ${BUILDOPTS} 2>/dev/null 
        #
	#
	if test x$? = x0; then
		[ -z "$verbose" ] ||     log_msg_ok "configure..."; 
		$MAKE  > /dev/null 2>&1
		if test x$? = x0; then
		    [ -z "$verbose" ] || log_msg_ok "make..."; 
		else
		    [ -z "$quiet" ] &&   log_msg_fail "make..."; 
		    return 1
		fi

	else
		[ -z "$quiet" ] &&       log_msg_fail "configure...";
		return 1
	fi

	rm -f ./.samhain_file
	rm -f ./.samhain_log
	rm -f ./.samhain_lock

	cp "${SCRIPTDIR}/testrc_1" "${RCFILE}"

	if test "x$2" = "xmodrc"; then
	    [ -z "$verbose" ] || log_msg_ok    "mod rc...";
	    testrun1b_modrc
	fi

	./samhain -t init -p none -l info

	if test x$? = x0; then
	    [ -z "$verbose" ] || log_msg_ok    "init...";
	else
	    [ -z "$quiet" ]   && log_msg_fail  "init...";
	    return 1
	fi

}

do_test_1b () {

    ./samhain -t check -p none -l info
    
    if test x$? = x0; then
	./samhain -j -L $LOGFILE >"${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "${LOGFILE}"
	if [ $? -ne 0 ]; then
	    [ -z "$quiet" ]   && log_msg_fail  "mv logfile...";
	    return 1
	fi
	[ -z "$verbose" ] || log_msg_ok    "check...";
    else
	[ -z "$quiet" ]   && log_msg_fail  "check...";
	return 1
    fi
    #
    tmp=`egrep "Checking.*/etc(>|\")" $LOGFILE 2>/dev/null | wc -l`
    if [ $tmp -ne 2 ]; then
	[ -z "$verbose" ] || log_msg_fail "/etc";
	return 1
    fi
    tmp=`egrep "Checking.*(>|\")" $LOGFILE 2>/dev/null | wc -l`
    if [ $tmp -ne 10 ]; then
	[ -z "$verbose" ] || log_msg_fail "checking";
	return 1
    fi
    egrep "ADDED" $LOGFILE >/dev/null 2>&1
    if [ $? -eq 0 ]; then
	[ -z "$verbose" ] || log_msg_fail "init was incomplete";
	return 1
    fi
    #
    return 0
}

testrun1i ()
{
    log_start "RUN STANDALONE W/STEALTH W/SIGNIFY"
    SIGNIFY=`find_path signify-openbsd`
    if [ -z "$SIGNIFY" ]; then
	SIGNIFY=`find_path signify`
    fi
    if [ -z "$SIGNIFY" ]; then
	log_skip 1 $MAXTEST 'signify not found in $PATH'
	log_skip 2 $MAXTEST 'signify not found in $PATH'
	log_skip 3 $MAXTEST 'signify not found in $PATH'
	log_skip 4 $MAXTEST 'signify not found in $PATH'
    else
	eval "ls ~/.signify/samhain.pub >/dev/null 2>/dev/null"
	if [ $? -ne 0 ]; then
	    log_skip 1 $MAXTEST 'public key ~/.signify/samhain.pub not present'
	    log_skip 2 $MAXTEST 'public key ~/.signify/samhain.pub not present'
	    log_skip 3 $MAXTEST 'public key ~/.signify/samhain.pub not present'
	    log_skip 4 $MAXTEST 'public key ~/.signify/samhain.pub not present'
	else
	    #
	    # -------------  first test -------------
	    #
	    BUILDOPTS="--quiet $TRUST --enable-debug --with-signify=${SIGNIFY} --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"
	    testrun1b_internal "${BUILDOPTS}" 
	    do_test_1b
	    if [ $? -eq 0 ]; then
		log_ok   1 $MAXTEST 'signify signed config/database files'
	    else
		log_fail 1 $MAXTEST 'signify signed config/database files'
	    fi


	    #
	    # -------------  second test -------------
	    #
	    BUILDOPTS="--quiet $TRUST --enable-debug --with-signify=${SIGNIFY} --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"
	    testrun1b_internal "${BUILDOPTS}" 
	    do_test_1b
	    if [ $? -eq 0 ]; then
		log_ok   2 $MAXTEST 'signify signed config/database files'
	    else
		log_fail 2 $MAXTEST 'signify signed config/database files'
	    fi


	    #
	    # -------------  third test -------------
	    #
	    BUILDOPTS="--quiet $TRUST --enable-debug --with-signify=${SIGNIFY} --with-checksum --with-pubkey-checksum=62F3EAE3CD9BA8849015060750908790B6326015A20AC0DA --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"
	    testrun1b_internal "${BUILDOPTS}" 
	    do_test_1b
	    if [ $? -eq 0 ]; then
		log_ok   3 $MAXTEST 'signify signed config/database files'
	    else
		log_fail 3 $MAXTEST 'signify signed config/database files'
	    fi


	    #
	    # -------------  fourth test -------------
	    #
	    PRECONV=`find_path convert`
	    "${PRECONV}" --help | grep  ImageMagick >/dev/null 2>&1 && \
 		CONVERT="${PRECONV}"

	    if [ -z "$CONVERT" ]; then
		log_skip 2 $MAXTEST 'ImageMagick convert not found in $PATH'
	    else
		BUILDOPTS="--quiet $TRUST --enable-debug --with-signify=${SIGNIFY} --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"
		testrun1b_internal "${BUILDOPTS}" "$CONVERT"
		do_test_1b
		if [ $? -eq 0 ]; then
		    log_ok   4 $MAXTEST 'signify signed config/database files'
		else
		    log_fail 4 $MAXTEST 'signify signed config/database files'
		fi
	    fi

	fi
    fi
    log_end "RUN STANDALONE W/STEALTH W/SIGNIFY"
    return 0
}