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 | if test -f scripts/samhainadmin.pl
|
---|
512 | then
|
---|
513 | cp scripts/samhainadmin.pl scripts/xxx_samhainadmin.pl
|
---|
514 | fi
|
---|
515 | $MAKE clean >/dev/null || return 1
|
---|
516 |
|
---|
517 | ${TOP_SRCDIR}/configure ${SERVER_BUILDOPTS}
|
---|
518 | #
|
---|
519 | if test x$? = x0; then
|
---|
520 | [ -z "$verbose" ] || log_msg_ok "configure...";
|
---|
521 | $MAKE > /dev/null 2>>test_log
|
---|
522 | if test x$? = x0; then
|
---|
523 | [ -z "$verbose" ] || log_msg_ok "make...";
|
---|
524 | else
|
---|
525 | [ -z "$quiet" ] && log_msg_fail "make...";
|
---|
526 | return 1
|
---|
527 | fi
|
---|
528 |
|
---|
529 | else
|
---|
530 | [ -z "$quiet" ] && log_msg_fail "configure...";
|
---|
531 | return 1
|
---|
532 | fi
|
---|
533 |
|
---|
534 | # Create a password
|
---|
535 |
|
---|
536 | SHPW=`./yule -G`
|
---|
537 | if test x"$SHPW" = x; then
|
---|
538 | [ -z "$quiet" ] && log_msg_fail "password not generated -- aborting"
|
---|
539 | return 1
|
---|
540 | fi
|
---|
541 |
|
---|
542 | # Set in client
|
---|
543 |
|
---|
544 | ./samhain_setpwd samhain.build new $SHPW >/dev/null
|
---|
545 |
|
---|
546 | if test x$? = x0; then
|
---|
547 | [ -z "$verbose" ] || log_msg_ok "./samhain_setpwd samhain.build new $SHPW";
|
---|
548 | else
|
---|
549 | [ -z "$quiet" ] && log_msg_fail "./samhain_setpwd samhain.build new $SHPW";
|
---|
550 | return 1
|
---|
551 | fi
|
---|
552 |
|
---|
553 | mv samhain.build.new samhain.new || return 1
|
---|
554 | if test -f scripts/xxx_samhainadmin.pl
|
---|
555 | then
|
---|
556 | cp scripts/xxx_samhainadmin.pl scripts/samhainadmin.pl
|
---|
557 | fi
|
---|
558 |
|
---|
559 | rm -f ./.samhain_log*
|
---|
560 | rm -f ./.samhain_lock
|
---|
561 |
|
---|
562 | SHCLT=`./yule -P $SHPW`
|
---|
563 |
|
---|
564 | if test x$? = x0; then
|
---|
565 | [ -z "$verbose" ] || log_msg_ok "yule -P $SHPW";
|
---|
566 | else
|
---|
567 | [ -z "$quiet" ] && log_msg_fail "yule -P $SHPW";
|
---|
568 | return 1
|
---|
569 | fi
|
---|
570 |
|
---|
571 | SHCLT1=`echo "${SHCLT}" | sed s%HOSTNAME%${SH_LOCALHOST}%`
|
---|
572 | AHOST=`find_hostname`
|
---|
573 | SHCLT2=`echo "${SHCLT}" | sed s%HOSTNAME%${AHOST}%`
|
---|
574 |
|
---|
575 | cp ${SCRIPTDIR}/testrc_2.in testrc_2
|
---|
576 | #
|
---|
577 | sed --in-place -e 's,file = /tmp,dir = 99/tmp/testrun_samhain,g' testrc_2
|
---|
578 | #
|
---|
579 | sed --in-place -e 's,SetUdpActive=no,ReportCheckflags=yes,g' testrc_2
|
---|
580 | #
|
---|
581 | echo $SHCLT1 >> testrc_2
|
---|
582 | echo $SHCLT2 >> testrc_2
|
---|
583 |
|
---|
584 | echo $SHPW > ./testpw
|
---|
585 | }
|
---|
586 |
|
---|
587 | testrun2g_signrc ()
|
---|
588 | {
|
---|
589 | scripts/samhainadmin.pl -s ./test/gnupg/ -m R $1 >/dev/null
|
---|
590 | scripts/samhainadmin.pl -s ./test/gnupg/ -k 8A0B337A -m E $1 >/dev/null
|
---|
591 | }
|
---|
592 |
|
---|
593 | testrun2g_signdb ()
|
---|
594 | {
|
---|
595 | scripts/samhainadmin.pl -s ./test/gnupg/ -k 8A0B337A -m E ./.samhain_file >/dev/null
|
---|
596 | }
|
---|
597 |
|
---|
598 | copy_rc_db_files ()
|
---|
599 | {
|
---|
600 | cp ./testrc_2 ./rc.${SH_LOCALHOST}
|
---|
601 | mv ./.samhain_file ./file.${SH_LOCALHOST}
|
---|
602 | if [ $? -ne 0 ]; then
|
---|
603 | [ -z "$verbose" ] || log_msg_fail "No .samhain_file";
|
---|
604 | return 1
|
---|
605 | fi
|
---|
606 | chmod 644 ./rc.${SH_LOCALHOST}
|
---|
607 | chmod 644 ./file.${SH_LOCALHOST}
|
---|
608 |
|
---|
609 | cp ./testrc_2 "./rc.${ALTHOST}"
|
---|
610 | cp ./file.${SH_LOCALHOST} "./file.${ALTHOST}" 2>/dev/null
|
---|
611 | chmod 644 ./rc.${ALTHOST}
|
---|
612 | chmod 644 ./file.${ALTHOST}
|
---|
613 | }
|
---|
614 |
|
---|
615 | MAXTEST=6; export MAXTEST
|
---|
616 |
|
---|
617 | testrun2g ()
|
---|
618 | {
|
---|
619 | log_start "RUN CLIENT/SERVER CASE TWO";
|
---|
620 | #
|
---|
621 | if [ x"$1" = x ]; then
|
---|
622 | [ -z "$quiet" ] && log_msg_fail "Missing hostname"
|
---|
623 | fi
|
---|
624 | #
|
---|
625 | SH_LOCALHOST=$1; export SH_LOCALHOST
|
---|
626 | #
|
---|
627 |
|
---|
628 |
|
---|
629 | # Test with missing delta
|
---|
630 | #
|
---|
631 | gpg --list-keys | grep 8A0B337A >/dev/null 2>&1
|
---|
632 | if [ $? -ne 0 ]; then
|
---|
633 | echo "You need to do 'gpg --import test/gnupg/public-key.asc' first"
|
---|
634 | log_skip 1 $MAXTEST 'Case Two w/signed files'
|
---|
635 | else
|
---|
636 | testrun2g_build "--with-gpg=/usr/bin/gpg" "--with-keyid=0x8A0B337A"
|
---|
637 | if [ $? -eq 0 ]; then
|
---|
638 | [ -z "$verbose" ] || log_msg_ok "build..";
|
---|
639 | testrun2g_signrc ./testrc_2
|
---|
640 | fi
|
---|
641 | if [ $? -eq 0 ]; then
|
---|
642 | [ -z "$verbose" ] || log_msg_ok "sign rc..";
|
---|
643 | testrun2g_prepare
|
---|
644 | fi
|
---|
645 | if [ $? -eq 0 ]; then
|
---|
646 | [ -z "$verbose" ] || log_msg_ok "prepare..";
|
---|
647 | testrun2g_signdb
|
---|
648 | fi
|
---|
649 | if [ $? -eq 0 ]; then
|
---|
650 | [ -z "$verbose" ] || log_msg_ok "sign db..";
|
---|
651 | copy_rc_db_files
|
---|
652 | fi
|
---|
653 | if [ $? -eq 0 ]; then
|
---|
654 | [ -z "$verbose" ] || log_msg_ok "copy..";
|
---|
655 | do_test_2_g_yule_start
|
---|
656 | fi
|
---|
657 | if [ $? -eq 0 ]; then
|
---|
658 | [ -z "$verbose" ] || log_msg_ok "start yule..";
|
---|
659 | do_test_2_g_three nodelta
|
---|
660 | fi
|
---|
661 | if [ $? -eq 0 ]; then
|
---|
662 | [ -z "$quiet" ] && log_ok 1 ${MAXTEST} "Case Two w/missing delta";
|
---|
663 | else
|
---|
664 | [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Case Two w/missing delta";
|
---|
665 | fi
|
---|
666 | fi
|
---|
667 |
|
---|
668 | # Test with unsigned delta
|
---|
669 | #
|
---|
670 | gpg --list-keys | grep 8A0B337A >/dev/null 2>&1
|
---|
671 | if [ $? -ne 0 ]; then
|
---|
672 | echo "You need to do 'gpg --import test/gnupg/public-key.asc' first"
|
---|
673 | log_skip 1 $MAXTEST 'Case Two w/signed files'
|
---|
674 | else
|
---|
675 | testrun2g_build "--with-gpg=/usr/bin/gpg" "--with-keyid=0x8A0B337A"
|
---|
676 | if [ $? -eq 0 ]; then
|
---|
677 | [ -z "$verbose" ] || log_msg_ok "build..";
|
---|
678 | testrun2g_signrc ./testrc_2
|
---|
679 | fi
|
---|
680 | if [ $? -eq 0 ]; then
|
---|
681 | [ -z "$verbose" ] || log_msg_ok "sign rc..";
|
---|
682 | testrun2g_prepare
|
---|
683 | fi
|
---|
684 | if [ $? -eq 0 ]; then
|
---|
685 | [ -z "$verbose" ] || log_msg_ok "prepare..";
|
---|
686 | testrun2g_signdb
|
---|
687 | fi
|
---|
688 | if [ $? -eq 0 ]; then
|
---|
689 | [ -z "$verbose" ] || log_msg_ok "sign db..";
|
---|
690 | copy_rc_db_files
|
---|
691 | fi
|
---|
692 | if [ $? -eq 0 ]; then
|
---|
693 | [ -z "$verbose" ] || log_msg_ok "copy..";
|
---|
694 | do_test_2_g_yule_start
|
---|
695 | fi
|
---|
696 | if [ $? -eq 0 ]; then
|
---|
697 | [ -z "$verbose" ] || log_msg_ok "start yule..";
|
---|
698 | do_test_2_g_three nosig
|
---|
699 | fi
|
---|
700 | if [ $? -eq 0 ]; then
|
---|
701 | [ -z "$quiet" ] && log_ok 1 ${MAXTEST} "Case Two w/unsigned delta";
|
---|
702 | else
|
---|
703 | [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Case Two w/unsigned delta";
|
---|
704 | fi
|
---|
705 | fi
|
---|
706 |
|
---|
707 | # Test with signed files, no sig client
|
---|
708 | #
|
---|
709 | gpg --list-keys | grep 8A0B337A >/dev/null 2>&1
|
---|
710 | if [ $? -ne 0 ]; then
|
---|
711 | echo "You need to do 'gpg --import test/gnupg/public-key.asc' first"
|
---|
712 | log_skip 1 $MAXTEST 'Case Two w/signed files'
|
---|
713 | else
|
---|
714 | testrun2g_build
|
---|
715 | if [ $? -eq 0 ]; then
|
---|
716 | [ -z "$verbose" ] || log_msg_ok "build..";
|
---|
717 | testrun2g_signrc ./testrc_2
|
---|
718 | fi
|
---|
719 | if [ $? -eq 0 ]; then
|
---|
720 | [ -z "$verbose" ] || log_msg_ok "sign rc..";
|
---|
721 | testrun2g_prepare
|
---|
722 | fi
|
---|
723 | if [ $? -eq 0 ]; then
|
---|
724 | [ -z "$verbose" ] || log_msg_ok "prepare..";
|
---|
725 | testrun2g_signdb
|
---|
726 | fi
|
---|
727 | if [ $? -eq 0 ]; then
|
---|
728 | [ -z "$verbose" ] || log_msg_ok "sign db..";
|
---|
729 | copy_rc_db_files
|
---|
730 | fi
|
---|
731 | if [ $? -eq 0 ]; then
|
---|
732 | [ -z "$verbose" ] || log_msg_ok "copy..";
|
---|
733 | do_test_2_g_yule_start
|
---|
734 | fi
|
---|
735 | if [ $? -eq 0 ]; then
|
---|
736 | [ -z "$verbose" ] || log_msg_ok "start yule..";
|
---|
737 | do_test_2_g_three
|
---|
738 | fi
|
---|
739 | if [ $? -eq 0 ]; then
|
---|
740 | [ -z "$quiet" ] && log_ok 1 ${MAXTEST} "Case Two w/signed files+nosig client";
|
---|
741 | else
|
---|
742 | [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Case Two w/signed files+nosig client";
|
---|
743 | fi
|
---|
744 | fi
|
---|
745 |
|
---|
746 | # Test with signed files
|
---|
747 | #
|
---|
748 | gpg --list-keys | grep 8A0B337A >/dev/null 2>&1
|
---|
749 | if [ $? -ne 0 ]; then
|
---|
750 | echo "You need to do 'gpg --import test/gnupg/public-key.asc' first"
|
---|
751 | log_skip 1 $MAXTEST 'Case Two w/signed files'
|
---|
752 | else
|
---|
753 | testrun2g_build "--with-gpg=/usr/bin/gpg" "--with-keyid=0x8A0B337A"
|
---|
754 | if [ $? -eq 0 ]; then
|
---|
755 | [ -z "$verbose" ] || log_msg_ok "build..";
|
---|
756 | testrun2g_signrc ./testrc_2
|
---|
757 | fi
|
---|
758 | if [ $? -eq 0 ]; then
|
---|
759 | [ -z "$verbose" ] || log_msg_ok "sign rc..";
|
---|
760 | testrun2g_prepare
|
---|
761 | fi
|
---|
762 | if [ $? -eq 0 ]; then
|
---|
763 | [ -z "$verbose" ] || log_msg_ok "prepare..";
|
---|
764 | testrun2g_signdb
|
---|
765 | fi
|
---|
766 | if [ $? -eq 0 ]; then
|
---|
767 | [ -z "$verbose" ] || log_msg_ok "sign db..";
|
---|
768 | copy_rc_db_files
|
---|
769 | fi
|
---|
770 | if [ $? -eq 0 ]; then
|
---|
771 | [ -z "$verbose" ] || log_msg_ok "copy..";
|
---|
772 | do_test_2_g_yule_start
|
---|
773 | fi
|
---|
774 | if [ $? -eq 0 ]; then
|
---|
775 | [ -z "$verbose" ] || log_msg_ok "start yule..";
|
---|
776 | do_test_2_g_three
|
---|
777 | fi
|
---|
778 | if [ $? -eq 0 ]; then
|
---|
779 | [ -z "$quiet" ] && log_ok 1 ${MAXTEST} "Case Two w/signed files";
|
---|
780 | else
|
---|
781 | [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Case Two w/signed files";
|
---|
782 | fi
|
---|
783 | fi
|
---|
784 |
|
---|
785 | # Test with non-signed files
|
---|
786 | #
|
---|
787 | testrun2g_build
|
---|
788 | if [ $? -eq 0 ]; then
|
---|
789 | [ -z "$verbose" ] || log_msg_ok "build..";
|
---|
790 | testrun2g_prepare
|
---|
791 | fi
|
---|
792 | if [ $? -eq 0 ]; then
|
---|
793 | [ -z "$verbose" ] || log_msg_ok "prepare..";
|
---|
794 | copy_rc_db_files
|
---|
795 | fi
|
---|
796 | if [ $? -eq 0 ]; then
|
---|
797 | [ -z "$verbose" ] || log_msg_ok "copy..";
|
---|
798 | do_test_2_g_yule_start
|
---|
799 | fi
|
---|
800 | if [ $? -eq 0 ]; then
|
---|
801 | [ -z "$verbose" ] || log_msg_ok "start yule..";
|
---|
802 | do_test_2_g_one
|
---|
803 | fi
|
---|
804 | if [ $? -eq 0 ]; then
|
---|
805 | [ -z "$quiet" ] && log_ok 2 ${MAXTEST} "Case Two w/unsigned files";
|
---|
806 | else
|
---|
807 | [ -z "$quiet" ] && log_fail 2 ${MAXTEST} "Case Two w/unsigned files";
|
---|
808 | fi
|
---|
809 |
|
---|
810 |
|
---|
811 |
|
---|
812 | #
|
---|
813 | testrun2g_prepare
|
---|
814 | if [ $? -eq 0 ]; then
|
---|
815 | [ -z "$verbose" ] || log_msg_ok "prepare..";
|
---|
816 | copy_rc_db_files
|
---|
817 | fi
|
---|
818 | if [ $? -eq 0 ]; then
|
---|
819 | [ -z "$verbose" ] || log_msg_ok "copy..";
|
---|
820 | do_test_2_g_yule_start
|
---|
821 | fi
|
---|
822 | if [ $? -eq 0 ]; then
|
---|
823 | [ -z "$verbose" ] || log_msg_ok "start yule..";
|
---|
824 | do_test_2_g_two
|
---|
825 | fi
|
---|
826 | if [ $? -eq 0 ]; then
|
---|
827 | [ -z "$quiet" ] && log_ok 3 ${MAXTEST} "Case Two w/o delta";
|
---|
828 | else
|
---|
829 | [ -z "$quiet" ] && log_fail 3 ${MAXTEST} "Case Two w/o delta";
|
---|
830 | fi
|
---|
831 |
|
---|
832 | if test -f scripts/xxx_samhainadmin.pl
|
---|
833 | then
|
---|
834 | rm -f scripts/xxx_samhainadmin.pl
|
---|
835 | fi
|
---|
836 |
|
---|
837 |
|
---|
838 | log_end "RUN CLIENT/SERVER CASE TWO"
|
---|
839 | }
|
---|