source: trunk/test/testrun_1d.sh@ 79

Last change on this file since 79 was 67, checked in by katerina, 18 years ago

Add/delete files for samhain 2.3

  • Property svn:executable set to *
File size: 5.5 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
157 run_check
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"'"'`
171 done
172
173 return 0
174}
175
176testrun1d ()
177{
178 log_start "RUN STANDALONE W/PROCESSCHECK"
179 testrun_internal_1d
180 log_end "RUN STANDALONE W/PROCESSCHECK"
181 return 0
182}
183
184proc_pspath ()
185{
186 PS=ps
187 for ff in /usr/ucb /bin /usr/bin; do
188 if test -x "$ff/ps"; then
189 PS="$ff/ps"
190 break
191 fi
192 done
193 echo "$PS"
194}
195
196proc_psarg ()
197{
198 OS=`uname -o`
199 case $OS in
200 *Linux*|*linux*)
201 PSARG="-eT";;
202 *)
203 PS=`proc_pspath`
204 $PS ax >/dev/null 2>&1
205 if test $? -eq 0; then
206 one=`$PS ax | wc -l`
207 else
208 one=0
209 fi
210 $PS -e >/dev/null 2>&1
211 if test $? -eq 0; then
212 two=`$PS -e | wc -l`
213 else
214 two=0
215 fi
216 if test $one -ge $two
217 then
218 PSARG="ax"
219 else
220 PSARG="-e"
221 fi
222 ;;
223 esac
224 echo "$PSARG"
225}
226
227proc_hide()
228{
229 PSPATH=`proc_pspath`
230 PSARG=`proc_psarg`
231
232 "${PSPATH}" "${PSARG}" | egrep -v '^[[:space:]]*[[:digit:]]{1}[[:space:]]+'
233}
234
235proc_fake()
236{
237 FAKE_PID=2
238 PSPATH=`proc_pspath`
239 PSARG=`proc_psarg`
240
241 "${PSPATH}" "${PSARG}"
242 if [ x"${PSARG}" = x-eT ]; then
243 echo "66666 66666 pts/2 S 0:14 THIS_IS_FAKE"
244 else
245 echo "66666 pts/2 S 0:14 THIS_IS_FAKE"
246 fi
247}
248
249if [ "x$1" = "x--hide" ]; then
250 proc_hide;
251 exit 0;
252fi
253
254if [ "x$1" = "x--fake" ]; then
255 proc_fake;
256 exit 0;
257fi
258
Note: See TracBrowser for help on using the repository browser.