source: trunk/test/testrun_1d.sh@ 526

Last change on this file since 526 was 371, checked in by katerina, 13 years ago

Patch for ticket #265 (inotify support).

  • Property svn:executable set to *
File size: 5.6 KB
RevLine 
[67]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
22BUILDOPTS="--quiet $TRUST --enable-xml-log --enable-process-check --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"
23export BUILDOPTS
24
25MAXTEST=3; export MAXTEST
26
27PROCPOLICY_3="
28[ReadOnly]
29file=${BASE}
30[ProcessCheck]
31ProcessCheckActive = yes
32ProcessCheckPsPath = ${PW_DIR}/${SCRIPTDIR}/testrun_1d.sh
33ProcessCheckPsArg = --fake
34ProcessCheckMaxPid = 67000
35"
36
37chk_procdata_3 () {
38 one_sec_sleep
39
40 egrep 'CRIT.*POLICY \[Process\] Fake pid: 66666[[:space:]]' $LOGFILE >/dev/null 2>&1
41 if [ $? -ne 0 ]; then
42 [ -z "$verbose" ] || log_msg_fail "Fake pid";
43 return 1
44 fi
45 egrep 'CRIT.*POLICY \[Process\] Fake pid: [012345789]+[[:space:]]' $LOGFILE >/dev/null 2>&1
46 if [ $? -eq 0 ]; then
47 [ -z "$verbose" ] || log_msg_fail "Fake pids incorrect";
48 return 1
49 fi
50}
51
52PROCPOLICY_2="
53[ReadOnly]
54file=${BASE}
55[ProcessCheck]
56ProcessCheckActive = yes
57"
58
59chk_procdata_2 () {
60 one_sec_sleep
61
62 egrep 'CRIT.*POLICY \[Process\] Hidden pid' $LOGFILE >/dev/null 2>&1
63 if [ $? -eq 0 ]; then
64 [ -z "$verbose" ] || log_msg_fail "Hidden pids (ps)";
65 return 1
66 fi
67}
68
69
70PROCPOLICY_1="
71[ReadOnly]
72file=${BASE}
73[ProcessCheck]
74ProcessCheckActive = yes
75ProcessCheckPsPath = ${PW_DIR}/${SCRIPTDIR}/testrun_1d.sh
76ProcessCheckPsArg = --hide
77"
78
79
80chk_procdata_1 () {
81 one_sec_sleep
82
83 egrep 'CRIT.*POLICY \[Process\] Hidden pid: [[:digit:]][[:space:]]' $LOGFILE >/dev/null 2>&1
84 if [ $? -ne 0 ]; then
85 [ -z "$verbose" ] || log_msg_fail "Hidden pids";
86 return 1
87 fi
88 egrep 'CRIT.*POLICY \[Process\] Hidden pid: [[:digit:]][[:digit:]]+[[:space:]]' $LOGFILE >/dev/null 2>&1
89 if [ $? -eq 0 ]; then
90 [ -z "$verbose" ] || log_msg_fail "Hidden pids incorrect";
91 return 1
92 fi
93}
94
95prep_procpolicy ()
96{
97 test -f "${RCFILE}" || touch "${RCFILE}"
98 eval echo '"$'"PROCPOLICY_$1"'"' >>"${RCFILE}"
99}
100
101testrun_internal_1d ()
102{
103 [ -z "$verbose" ] || echo Working directory: $PW_DIR
104 [ -z "$verbose" ] || { echo MAKE is $MAKE; echo; }
105
106 #
107 # test standalone compilation
108 #
109 [ -z "$verbose" ] || { echo; echo "${S}Building standalone agent${E}"; echo; }
110
111 if test -r "Makefile"; then
112 $MAKE distclean >/dev/null
113 fi
114
115 tcount=1
116 ${TOP_SRCDIR}/configure ${BUILDOPTS}
117
118 #
119 if test x$? = x0; then
120 [ -z "$verbose" ] || log_msg_ok "configure...";
121 $MAKE >/dev/null 2>&1
122 if test x$? = x0; then
123 [ -z "$verbose" ] || log_msg_ok "make...";
124 else
125 [ -z "$quiet" ] && log_msg_fail "make...";
126 return 1
127 fi
128
129 else
130 [ -z "$quiet" ] && log_msg_fail "configure...";
131 return 1
132 fi
133
134 [ -z "$verbose" ] || { echo; echo "${S}Running test suite${E}"; echo; }
135
136 POLICY=`eval echo '"$'"PROCPOLICY_$tcount"'"'`
137
138 until [ -z "$POLICY" ]
139 do
140 prep_init
141 check_err $? ${tcount}; errval=$?
142 if [ $errval -eq 0 ]; then
143 prep_testdata
144 check_err $? ${tcount}; errval=$?
145 fi
146 if [ $errval -eq 0 ]; then
147 prep_procpolicy ${tcount}
148 check_err $? ${tcount}; errval=$?
149 fi
150 if [ $errval -eq 0 ]; then
151 run_init
152 check_err $? ${tcount}; errval=$?
153 fi
154 for iseq in 0 1 2 3 4 5 6 7 8 9; do
155 rm -f "$LOGFILE"
156 if [ $errval -eq 0 ]; then
[371]157 run_check info
[67]158 check_err $? ${tcount}; errval=$?
159 fi
160 if [ $errval -eq 0 ]; then
161 eval chk_procdata_${tcount}
162 check_err $? ${tcount}; errval=$?
163 fi
164 done
165 #
166 if [ $errval -eq 0 ]; then
167 [ -z "$quiet" ] && log_ok ${tcount} ${MAXTEST};
168 fi
169 let "tcount = tcount + 1" >/dev/null
170 POLICY=`eval echo '"$'"PROCPOLICY_$tcount"'"'`
[85]171
[67]172 done
173
174 return 0
175}
176
177testrun1d ()
178{
179 log_start "RUN STANDALONE W/PROCESSCHECK"
180 testrun_internal_1d
181 log_end "RUN STANDALONE W/PROCESSCHECK"
182 return 0
183}
184
185proc_pspath ()
186{
187 PS=ps
188 for ff in /usr/ucb /bin /usr/bin; do
189 if test -x "$ff/ps"; then
190 PS="$ff/ps"
191 break
192 fi
193 done
194 echo "$PS"
195}
196
197proc_psarg ()
198{
[169]199 OS=`uname -s`
[67]200 case $OS in
201 *Linux*|*linux*)
202 PSARG="-eT";;
[169]203 *OpenBSD*)
204 PSARG="akx";;
[67]205 *)
206 PS=`proc_pspath`
207 $PS ax >/dev/null 2>&1
208 if test $? -eq 0; then
209 one=`$PS ax | wc -l`
210 else
211 one=0
212 fi
213 $PS -e >/dev/null 2>&1
214 if test $? -eq 0; then
215 two=`$PS -e | wc -l`
216 else
217 two=0
218 fi
219 if test $one -ge $two
220 then
221 PSARG="ax"
222 else
223 PSARG="-e"
224 fi
225 ;;
226 esac
227 echo "$PSARG"
228}
229
230proc_hide()
231{
232 PSPATH=`proc_pspath`
233 PSARG=`proc_psarg`
234
235 "${PSPATH}" "${PSARG}" | egrep -v '^[[:space:]]*[[:digit:]]{1}[[:space:]]+'
236}
237
238proc_fake()
239{
240 FAKE_PID=2
241 PSPATH=`proc_pspath`
242 PSARG=`proc_psarg`
243
244 "${PSPATH}" "${PSARG}"
245 if [ x"${PSARG}" = x-eT ]; then
246 echo "66666 66666 pts/2 S 0:14 THIS_IS_FAKE"
247 else
248 echo "66666 pts/2 S 0:14 THIS_IS_FAKE"
249 fi
250}
251
252if [ "x$1" = "x--hide" ]; then
253 proc_hide;
254 exit 0;
255fi
256
257if [ "x$1" = "x--fake" ]; then
258 proc_fake;
259 exit 0;
260fi
261
Note: See TracBrowser for help on using the repository browser.