source: trunk/test/testrun_2f.sh@ 572

Last change on this file since 572 was 550, checked in by katerina, 5 years ago

Fix for ticket #442 (support for OpenBSD signify).

  • Property svn:executable set to *
File size: 10.0 KB
RevLine 
[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
22LOGFILE="$PW_DIR/.samhain_log"; export LOGFILE
23RCFILE="$PW_DIR/testrc_2"; export RCFILE
24
25SERVER_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"; export SERVER_BUILDOPTS
26
27CLIENT_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-debug"; export CLIENT_BUILDOPTS
28
29do_test_2_f () {
30
31 [ -z "$verbose" ] || {
32 echo;
33 echo "${S}Start Server${E}: ./yule -l info -p none &";
34 echo;
35 }
36 rm -f test_log_valgrind
37
38 # SetSocketAllowUid=$(id -u)
39 #
40 if test -f /usr/xpg4/bin/id; then
41 MY_ID=$(/usr/xpg4/bin/id -u)
42 else
43 MY_ID=$(id -u)
44 fi
45 #
46 sed -i -e "s/SetSocketAllowUid=0/SetSocketAllowUid=${MY_ID}/g" $RCFILE
47
48 # Start server
49 #
50 ${VALGRIND} ./yule -l info -p none >/dev/null 2>>test_log_valgrind &
51 PROC_Y=$!
52 five_sec_sleep
53
54
55 [ -z "$verbose" ] || {
56 echo;
57 echo "${S}Start Client${E}: ./samhain.new -t check --foreground --forever .. &";
58 echo;
59 }
60 ${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
61 if test x$? = x0; then
62 [ -z "$verbose" ] || log_msg_ok "starting samhain.new";
63 else
64 [ -z "$quiet" ] && log_msg_fail "starting samhain.new";
65 kill $PROC_Y
66 return 1
67 fi
68 five_sec_sleep
69 PROC_S=$( ps aux | grep samhain.new | grep -v grep | awk '{ print $2; }' )
70
71 for ff in 1 2; do
72 five_sec_sleep
73 done
74 egrep "File check completed" $LOGFILE >/dev/null 2>&1
75 if [ $? -ne 0 ]; then
76 [ -z "$verbose" ] || log_msg_fail "Client file check";
77 kill $PROC_S; kill $PROC_Y;
78 return 1
79 fi
80 NR=$( egrep "File check completed" $LOGFILE | wc -l )
81 if [ $NR -ne 1 ]; then
82 [ -z "$verbose" ] || log_msg_fail "Client file check (1)";
83 kill $PROC_S; kill $PROC_Y;
84 return 1
85 fi
86 #
87 # >>> (1) Send SIGTTOU to force a second scan,
88 # >>> and verify that it was done
89 #
90 kill -TTOU $PROC_S
91 if [ $? -ne 0 ]; then
92 [ -z "$verbose" ] || log_msg_fail "Kill -TTOU";
93 kill $PROC_S; kill $PROC_Y;
94 return 1
95 fi
96
97 for ff in 1 2; do
98 five_sec_sleep
99 done
100 NR=$( egrep "File check completed" $LOGFILE | wc -l )
101 if [ $NR -ne 2 ]; then
102 [ -z "$verbose" ] || log_msg_fail "Client file check (2)";
103 kill $PROC_S; kill $PROC_Y;
104 return 1
105 fi
106 [ -z "$verbose" ] || log_msg_ok "sigttou";
107
108 NR=$( egrep "POLICY" $LOGFILE | wc -l )
109 if [ $NR -ne 0 ]; then
110 [ -z "$verbose" ] || log_msg_fail "Client file check (3)";
111 kill $PROC_S; kill $PROC_Y;
112 return 1
113 fi
114
115 #
116 # >>> (2) Modify the file system
117 #
118
119 UUID=$(uuidgen)
120 mkdir /tmp/testrun_samhain/$UUID
121 if [ $? -ne 0 ]; then
122 [ -z "$verbose" ] || log_msg_fail "mkdir";
123 kill $PROC_S; kill $PROC_Y;
124 return 1
125 fi
126
127 kill -TTOU $PROC_S
128 if [ $? -ne 0 ]; then
129 [ -z "$verbose" ] || log_msg_fail "Kill -TTOU (2)";
130 kill $PROC_S; kill $PROC_Y;
131 return 1
132 fi
133
134 for ff in 1 2; do
135 five_sec_sleep
136 done
137 NR=$( egrep "POLICY" $LOGFILE | wc -l )
138 if [ $NR -ne 1 ]; then
139 [ -z "$verbose" ] || log_msg_fail "Client file check (4)";
140 kill $PROC_S; kill $PROC_Y;
141 return 1
142 fi
143 [ -z "$verbose" ] || log_msg_ok "/tmp/testrun_samhain modified";
144
145 kill $PROC_S;
146 five_sec_sleep
147
148 rm -f ./.samhain_file
149 rm -f ./file.${SH_LOCALHOST}
150 rm -f "./file.${ALTHOST}"
151
152 rm ./.samhain_log
153 rm -f ./.samhain_lock
154
155 #
156 # >>> (3) Re-init the database
157 #
158 ./samhain.new -t init -p none
159 if [ $? -ne 0 ]; then
160 [ -z "$verbose" ] || log_msg_fail "init (2) ..";
161 kill $PROC_Y;
162 return 1
163 fi
164 [ -z "$verbose" ] || log_msg_ok "init (2) ..";
165
166 #
167 # >>> (4) Re-start Samhain with delay
168 #
169
170 sed --in-place -e 's/SetUdpActive=no/StartupLoadDelay=10/g' ./rc.${SH_LOCALHOST}
171 if [ $? -ne 0 ]; then
172 [ -z "$verbose" ] || log_msg_fail "sed (1) ..";
173 kill $PROC_Y;
174 return 1
175 fi
176 sed --in-place -e 's/SetUdpActive=no/StartupLoadDelay=10/g' "./rc.${ALTHOST}"
177 if [ $? -ne 0 ]; then
178 [ -z "$verbose" ] || log_msg_fail "sed (2) ..";
179 kill $PROC_Y;
180 return 1
181 fi
182
183 ${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
184 if test x$? = x0; then
185 [ -z "$verbose" ] || log_msg_ok "starting samhain.new (2)";
186 else
187 [ -z "$quiet" ] && log_msg_fail "starting samhain.new (2)";
188 kill $PROC_Y
189 return 1
190 fi
191 five_sec_sleep
192 PROC_S=$( ps aux | grep samhain.new | grep -v grep | awk '{ print $2; }' )
193
194 #
195 # >>> (5) Copy database to server after Samhain startup
196 # >>> verifies that StartupLoadDelay works
197 #
198
199 if test -f ./.samhain_file; then
200 mv ./.samhain_file ./file.${SH_LOCALHOST}
201 chmod 644 ./file.${SH_LOCALHOST}
202
203 ALTHOST=`find_hostname`
204 cp ./file.${SH_LOCALHOST} "./file.${ALTHOST}" 2>/dev/null
205 chmod 644 ./file.${ALTHOST}
206 else
207 [ -z "$verbose" ] || log_msg_fail "baseline file ..";
208 kill $PROC_S; kill $PROC_Y;
209 return 1
210 fi
211
212 for ff in 1 2 3; do
213 five_sec_sleep
214 done
215 NR=$( egrep "File check completed" $LOGFILE | wc -l )
216 if [ $NR -ne 1 ]; then
217 [ -z "$verbose" ] || log_msg_fail "Client file check (5)";
218 kill $PROC_S; kill $PROC_Y;
219 return 1
220 fi
221 [ -z "$verbose" ] || log_msg_ok "file check after delay";
222
223 NR=$( egrep "POLICY" $LOGFILE | wc -l )
224 if [ $NR -ne 0 ]; then
225 [ -z "$verbose" ] || log_msg_fail "Client file check (6)";
226 kill $PROC_S; kill $PROC_Y;
227 return 1
228 fi
229
230 kill $PROC_S;
231 kill $PROC_Y
232 return 0
233}
234
235testrun2f_internal ()
236{
237 [ -z "$verbose" ] || {
238 echo;
239 echo Working directory: $PW_DIR; echo MAKE is $MAKE;
240 echo;
241 }
242 #
243 #
244 [ -z "$verbose" ] || { echo; echo "${S}Building client and server${E}"; echo; }
245 #
246 if test -r "Makefile"; then
247 $MAKE distclean
248 fi
249 #
250 ${TOP_SRCDIR}/configure ${CLIENT_BUILDOPTS}
251 #
252 if test x$? = x0; then
253 [ -z "$verbose" ] || log_msg_ok "configure...";
254 $MAKE > /dev/null 2>>test_log
255 if test x$? = x0; then
256 [ -z "$verbose" ] || log_msg_ok "make...";
257 else
258 [ -z "$quiet" ] && log_msg_fail "make...";
259 return 1
260 fi
261
262 else
263 [ -z "$quiet" ] && log_msg_fail "configure...";
264 return 1
265 fi
266
267 # save binary and build server
268 #
269 cp samhain samhain.build || return 1
270 $MAKE clean >/dev/null || return 1
271
272 ${TOP_SRCDIR}/configure ${SERVER_BUILDOPTS}
273 #
274 if test x$? = x0; then
275 [ -z "$verbose" ] || log_msg_ok "configure...";
276 $MAKE > /dev/null 2>>test_log
277 if test x$? = x0; then
278 [ -z "$verbose" ] || log_msg_ok "make...";
279 else
280 [ -z "$quiet" ] && log_msg_fail "make...";
281 return 1
282 fi
283
284 else
285 [ -z "$quiet" ] && log_msg_fail "configure...";
286 return 1
287 fi
288
289
290 #####################################################################
291 #
292 #
293 rm -f ./.samhain_file
294 rm -f ./.samhain_log
295 rm -f ./.samhain_lock
296 rm -f ./rc.${SH_LOCALHOST}
297 rm -f ./file.${SH_LOCALHOST}
298 rm -f "./rc.${ALTHOST}"
299 rm -f "./file.${ALTHOST}"
300
301 cp ${SCRIPTDIR}/testrc_2.in testrc_2
302
303 sed --in-place -e 's,file = /tmp,file = /tmp/testrun_samhain,g' testrc_2
304 mkdir /tmp/testrun_samhain 2>/dev/null
305
306 ./samhain.build -t init -p none
307
308 if test x$? = x0; then
309 [ -z "$verbose" ] || log_msg_ok "init...";
310 else
311 [ -z "$quiet" ] && log_msg_fail "init...";
312 return 1
313 fi
314
315 # Create a password
316
317 SHPW=`./yule -G`
318 if test x"$SHPW" = x; then
319 [ -z "$quiet" ] && log_msg_fail "password not generated -- aborting"
320 return 1
321 fi
322
323 # Set in client
324
325 ./samhain_setpwd samhain.build new $SHPW >/dev/null
326
327 if test x$? = x0; then
328 [ -z "$verbose" ] || log_msg_ok "./samhain_setpwd samhain.build new $SHPW";
329 else
330 [ -z "$quiet" ] && log_msg_fail "./samhain_setpwd samhain.build new $SHPW";
331 return 1
332 fi
333
334 mv samhain.build.new samhain.new || return 1
335
336 rm -f ./.samhain_log*
337 rm -f ./.samhain_lock
338
339 SHCLT=`./yule -P $SHPW`
340
341 if test x$? = x0; then
342 [ -z "$verbose" ] || log_msg_ok "yule -P $SHPW";
343 else
344 [ -z "$quiet" ] && log_msg_fail "yule -P $SHPW";
345 return 1
346 fi
347
348 SHCLT1=`echo "${SHCLT}" | sed s%HOSTNAME%${SH_LOCALHOST}%`
349 AHOST=`find_hostname`
350 SHCLT2=`echo "${SHCLT}" | sed s%HOSTNAME%${AHOST}%`
351
352 echo $SHCLT1 >> testrc_2
353 echo $SHCLT2 >> testrc_2
354
355 cp ./testrc_2 ./rc.${SH_LOCALHOST}
356 mv ./.samhain_file ./file.${SH_LOCALHOST}
357 chmod 644 ./rc.${SH_LOCALHOST}
358 chmod 644 ./file.${SH_LOCALHOST}
359
360 ALTHOST=`find_hostname`
361 cp ./testrc_2 "./rc.${ALTHOST}"
362 cp ./file.${SH_LOCALHOST} "./file.${ALTHOST}" 2>/dev/null
363 chmod 644 ./rc.${ALTHOST}
364 chmod 644 ./file.${ALTHOST}
365
366 echo $SHPW > ./testpw
367}
368
369MAXTEST=1; export MAXTEST
370
371testrun2f ()
372{
373 log_start "RUN CLIENT/SERVER CASE ONE";
374 #
375 if [ x"$1" = x ]; then
376 [ -z "$quiet" ] && log_msg_fail "Missing hostname"
377 fi
378 #
379 SH_LOCALHOST=$1; export SH_LOCALHOST
380 #
381 testrun2f_internal
382 do_test_2_f
383 if [ $? -eq 0 ]; then
384 [ -z "$quiet" ] && log_ok 1 ${MAXTEST} "Case One Change Management Integration";
385 else
386 [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Case One Change Management Integration";
387 fi
388 #
389 log_end "RUN CLIENT/SERVER CASE ONE"
390}
Note: See TracBrowser for help on using the repository browser.