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