source: trunk/dsys/funcDB@ 270

Last change on this file since 270 was 27, checked in by rainer, 19 years ago

Support for server-to-server relay and more user policies

File size: 7.3 KB
RevLine 
[1]1#########################################################################
2#
3# More subroutines for client DB
4#
5#########################################################################
[27]6#
7# Copyright Rainer Wichmann (2005)
8#
9# License Information:
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
[1]24
25DBFTEST=0
26
27dbSETFLAG() {
28 case "$line" in
29 *\</client\>*)
30 DBFTEST=0;
31 return 0;
32 ;;
33
34 *\<client_host\>${DB_host}\</client_host\>*)
35 DBFTEST=1;
36 return 1;
37 ;;
38
39 *)
40 return ${DBFTEST};
41 ;;
42 esac
43}
44
45
46DB_arch=""; export DB_arch;
47DB_status=""; export DB_status;
48DB_version=""; export DB_version;
49DB_date=""; export DB_date;
50DB_name=""; export DB_name;
51
52dbINFO() {
53
54 if test "x$1" = x
55 then
56 printFATAL "No host specified, aborting"
57 else
58 DB_host="$1"
59 fi
60
61 DB_arch=""; export DB_arch;
62 DB_status=""; export DB_status;
63 DB_version=""; export DB_version;
64 DB_date=""; export DB_date;
65 DB_name=""; export DB_name;
66
67 if test x"$DATABASE" = x
68 then
69 DATABASE="${basedir}/${defdatabase}"
70 fi
71
72 if test -f "${DATABASE}"
73 then
74 SStr1=`grep '<yule_db>' "${DATABASE}"`
75 if test "x${SStr1}" != "x"
76 then
77
78 SStr2=`grep "<client_host>${DB_host}</client_host>" "${DATABASE}"`
79
80 SStr3=
81
82 if test "x${SStr2}" != "x"
83 then
84 exec 3<&0 <"${DATABASE}"
85 while
86 read line
87 do
88 # for some reason, var=xx only works in a function call (why?)
89 #
90 # here we test if we are still in the same client block
91 # (set_flag will return 0 for </client> and following)
92 dbSETFLAG "$line"
93
94 if test "x$?" = "x1"
95 then
96 case "$line" in
97 *\<client_os_machine\>*\</client_os_machine\>)
98 DB_arch=`echo "$line" | sed '/^\(.*\)<client_os_machine>\([0-9a-zA-Z_-]*\)<\/client_os_machine>\(.*\)$/{ s//\2/; q; }'`
99 export DB_arch
100 ;;
101
102 *\<client_install_status\>*\</client_install_status\>)
103 DB_status=`echo "$line" | sed '/^\(.*\)<client_install_status>\([0-9a-zA-Z_-]*\)<\/client_install_status>\(.*\)$/{ s//\2/; q; }'`
104 export DB_status
105 ;;
106
107 *\<client_install_date\>*\</client_install_date\>)
108 DB_date=`echo "$line" | sed '/^\(.*\)<client_install_date>\([ 0-9a-zA-Z_.:,-]*\)<\/client_install_date>\(.*\)$/{ s//\2/; q; }'`
109 export DB_date
110 ;;
111
112 *\<client_install_name\>*\</client_install_name\>)
113 DB_name=`echo "$line" | sed '/^\(.*\)<client_install_name>\([0-9a-zA-Z_-]*\)<\/client_install_name>\(.*\)$/{ s//\2/; q; }'`
114 export DB_name
115 ;;
116
117 *\<client_install_prefix\>*\</client_install_prefix\>)
118 ;;
119
120 *\<client_install_version\>*\</client_install_version\>)
121 DB_version=`echo "$line" | sed '/^\(.*\)<client_install_version>\([0-9a-zA-Z_.-]*\)<\/client_install_version>\(.*\)$/{ s//\2/; q; }'`
122 export DB_version
123 ;;
124
125 *)
126 ;;
127
128 esac
129 else
130 :
131 fi
132 done
133 exec 0<&3 3<&-
134 return 0
135 else
136 printINFO "Host ${DB_host} not found in client database"
137 return 1
138 fi
139 else
140 printINFO "Client database ${DATABASE} in bad shape"
141 return 1
142 fi
143 else
144 printINFO "Client database ${DATABASE} not available"
145 return 1
146 fi
147}
148
149DB_hostlist=""; export DB_hostlist
150
151dbHOSTLIST() {
152
153 DB_hostlist=""; export DB_hostlist
154
155 if test x"$DATABASE" = x
156 then
157 DATABASE="${basedir}/${defdatabase}"
158 fi
159
160 if test -f "${DATABASE}"
161 then
162 DB_hostlist=`cat "${DATABASE}" | grep 'client_host' | sed '/^\(.*\)<client_host>\([0-9a-zA-Z.-]*\)<\/client_host>\(.*\)$/{ s//\2/; }' | sort`
163 export DB_hostlist
164 return 0
165 else
166 printINFO "Client database ${DATABASE} not available"
167 return 1
168 fi
169}
170
171dbSHOWHOSTS() {
172
173 if test "x$1" = x
174 then
175 dbHOSTLIST
176 else
177 DB_hostlist="$1"
178 fi
179
180 if test "x$?" = x1
181 then
182 printLOG "No known hosts - database unavailable"
183 fi
184 if test "x${DB_hostlist}" = x
185 then
186 printLOG "No known hosts - database unavailable, empty, or corrupt"
187 fi
188
189 for ff in ${DB_hostlist}
190 do
191 dbINFO "$ff"
192
193
194 if test "x$?" = x1
195 then
196 :
197 else
198 test -z "${DB_date}" && DB_date="INDEF"
199 test -z "${DB_arch}" && DB_arch="INDEF"
200 test -z "${DB_version}" && DB_version="INDEF"
201
202 tmp_status="-"
203 if test "x$DB_status" = xinstalled
204 then
205 tmp_status="o"
206 elif test "x$DB_status" = xD2_installed
207 then
208 tmp_status="i"
209 elif test "x$DB_status" = xD2_removed
210 then
211 tmp_status="u"
212 fi
213 out=`echo | awk '{ printf "%1s %14s %-11s %19s %s\n", "'"${tmp_status}"'", "'"${DB_arch}"'", "'"${DB_version}"'", "'"${DB_date}"'", "'"${ff}"'" }'`
214 printINFO "${out}"
215 fi
216 done
217}
218
219
220dbSHOWPKG() {
221
222 delete=no
223 show=no
224
225 if test x"$1" = xshow
226 then
227 show=yes
228 fi
229 if test x"$2" = xdelete
230 then
231 delete=yes
232 fi
233
234 cd "${basedir}/archpkg" || printFATAL "Cannot cd to ${basedir}/archpkg"
235
236 dbHOSTLIST
237
238 if test x"$DATABASE" = x
239 then
240 DATABASE="${basedir}/${defdatabase}"
241 fi
242
243 LIST=`ls`
244 this_dir=`pwd`
245
246 for dd in $LIST
247 do
248 if test -d "$dd"
249 then
250 cd "$dd"
251
252 PKGLIST=`ls samhain-* 2>/dev/null`
253
254 for ff in $PKGLIST
255 do
256 if test -f "$ff"
257 then
258 version=`echo "$ff" | sed -e 's%samhain-%%'`
259
260 tmp_status="-"
261
262 grep "$version" "${DATABASE}" >/dev/null 2>&1
263 if test "x$?" = x0
264 then
265 for hh in ${DB_hostlist}
266 do
267 dbINFO "$hh"
268 if test x"${DB_arch}" = x"${dd}" && \
269 test x"${DB_version}" = x"${version}"
270 then
271 tmp_status="-"
272 if test "x$DB_status" = xinstalled
273 then
274 tmp_status="o"
275 elif test "x$DB_status" = xD2_installed
276 then
277 tmp_status="i"
278 fi
279 break
280 fi
281 done
282 else
283 tmp_status="-"
284 fi
285
286 if test x"${show}" = xyes
287 then
288 printINFO "${tmp_status} ${dd}/${version}"
289 fi
290
291 if test x"${delete}" = xyes && test x"${tmp_status}" = "x-"
292 then
293 printLOG "REMOVE ${dd}/${version}"
294
295 if test x"$simulate" = x0
296 then
297 rm -f "samhain-${version}"
298 rm -f "install-${version}"
299 rm -f "configure-${version}"
300 else
301 printINFO "rm -f ${dd}/samhain-${version}"
302 printINFO "rm -f ${dd}/install-${version}"
303 printINFO "rm -f ${dd}/configure-${version}"
304 fi
305 fi
306 fi
307 done
308 cd "${this_dir}"
309 fi
310 done
311}
Note: See TracBrowser for help on using the repository browser.