ports/security/openvas9-manager/files/patch-tools+greenbone-scapdata-sync.in
Jose Alonso Cardenas Marquez ec093cec9b - Fix rc scripts of OpenVAS 9 ports
- Change some entries of openvas8/files/pkg-message
- Change some entries of openvas9/files/pkg-message. It reflects socket use of
  OpenVAS 9 ports.
- Fix problems into OpenVAS 9 greenbone*-sync scripts
- Add missing dependency (ftp/wget)
- Fix socket connection from openvas9-manager to openvas9-scanner
- Bump PORTREVISION
2017-08-07 03:48:23 +00:00

136 lines
5.4 KiB
Text

--- tools/greenbone-scapdata-sync.in 2016-11-10 04:58:06.000000000 -0500
+++ tools/greenbone-scapdata-sync.in 2017-08-06 13:50:52.849680000 -0500
@@ -89,7 +89,7 @@
# Split CVE data files into parts of this size in kB. 0 = no splitting
# The default is 1/30 of the system memory.
-SPLIT_PART_SIZE=$(awk '/MemTotal/ { print int( $2/60) }' /proc/meminfo)
+SPLIT_PART_SIZE=$((($(sysctl hw.physmem | cut -d " " -f2)/1024)/60))
# SQLITE3 defines the name of the sqlite binary to call, along with additional
# parameters.
@@ -109,7 +109,7 @@
# Delay between retries
if [ -z "$SQL_RETRY_DELAY" ]; then
- SQL_RETRY_DELAY="10m" # allowed unit suffixes: see sleep command
+ SQL_RETRY_DELAY="600" # allowed unit suffixes: see sleep command
fi
# SCRIPT_NAME is the name the scripts will use to identify itself and to mark
@@ -234,11 +234,6 @@
if [ -z "$TMPDIR" ]; then
SYNC_TMP_DIR=/tmp
- # If we have mktemp, create a temporary dir (safer)
- if [ -n "`which mktemp`" ]; then
- SYNC_TMP_DIR=`mktemp -t -d greenbone-scap-data-sync.XXXXXXXXXX` || { log_err "Cannot create temporary directory for file download" ; exit 1 ; }
- trap "rm -rf $SYNC_TMP_DIR" EXIT HUP INT TRAP TERM
- fi
else
SYNC_TMP_DIR="$TMPDIR"
fi
@@ -1080,11 +1075,11 @@
then
for ovalfile in $oval_files_sorted_private
do
- filedate=`stat -c "%Y" "$ovalfile" | cut -d " " -f 1 | tr -d "-"`
+ filedate=`stat -f "%m" "$ovalfile" | cut -d " " -f 1 | tr -d "-"`
filedate=$(( $filedate - ( $filedate % 60 ) ))
if [ $filedate -gt $DB_LASTUPDATE ] || [ 1 = "$REBUILD_OVAL" ]
then
- oval_timestamp=`xsltproc "$SCAP_RES_DIR/oval_timestamp.xsl" "$ovalfile" | date "+%s" -f -`
+ oval_timestamp=`date -j -f "%Y-%m-%dT%H:%M:%S" $(xsltproc "$SCAP_RES_DIR/oval_timestamp.xsl" "$ovalfile" | cut -d "." -f1) +%s`
if [ 1 = "$REBUILD_OVAL" ]
then
@@ -1153,7 +1148,7 @@
DIR_STR_LENGTH=$((`echo "$SCAP_DIR" | wc -c` + 1))
oval_files_shortened=""
- if [ 0 != "$xmlcount" ]
+ if [ "$xmlcount" -ne 0 ]
then
for ovalfile in $oval_files_sorted_private
do
@@ -1163,7 +1158,7 @@
fi
oval_files_clause=""
- if [ ! -z "$oval_files_shortened" ]
+ if [ "$oval_files_shortened" =! "" ]
then
oval_files_clause="AND (xml_file NOT IN ($oval_files_shortened))"
fi
@@ -1186,7 +1181,7 @@
fi
# TODO: This is not quite accurate as it uses the timestamp of the non-private data.
- LAST_UPDATE_TIMESTAMP=`sed 's/^\(.\{8\}\)/\1 /' $TIMESTAMP | date +%s -f -`
+ LAST_UPDATE_TIMESTAMP=`date -j -f '%Y%m%d%H%M%S' $(sed 's/$/00/g' $TIMESTAMP) +%s`
reset_sql_tries
until [ "$try_sql" -eq 0 ]
@@ -1208,12 +1203,12 @@
CPEBASE="$SCAP_DIR/official-cpe-dictionary_v2.2.xml"
if [ -e $CPEBASE ]
then
- filedate=`stat -c "%Y" "$CPEBASE" | cut -d " " -f 1 | tr -d "-"`
+ filedate=`stat -f "%m" "$CPEBASE" | cut -d " " -f 1 | tr -d "-"`
filedate=$(( $filedate - ( $filedate % 60 ) ))
if [ $filedate -gt $DB_LASTUPDATE ]
then
log_info "Updating CPEs"
- filesize=`stat -c "%s" "$CPEBASE"`
+ filesize=`stat -f "%z" "$CPEBASE"`
if [ "0" -ne "$SPLIT_PART_SIZE" ] && [ "$filesize" -gt $(($SPLIT_PART_SIZE * 1024)) ]
then
log_info "File is larger than ${SPLIT_PART_SIZE}k. Splitting into multiple parts"
@@ -1271,13 +1266,13 @@
for cvefile in $SCAP_DIR/nvdcve-2.0-*.xml
do
[ -e "$cvefile" ] || break # no file found
- filedate=`stat -c "%Y" "$cvefile" | cut -d " " -f 1 | tr -d "-"`
+ filedate=`stat -f "%m" "$cvefile" | cut -d " " -f 1 | tr -d "-"`
filedate=$(( $filedate - ( $filedate % 60 ) ))
if [ $filedate -gt $DB_LASTUPDATE ]
then
log_info "Updating $cvefile"
- filesize=`stat -c "%s" "$cvefile"`
+ filesize=`stat -f "%z" "$cvefile"`
if [ "0" -ne "$SPLIT_PART_SIZE" ] && [ "$filesize" -gt $(($SPLIT_PART_SIZE * 1024)) ]
then
log_info "File is larger than ${SPLIT_PART_SIZE}k. Splitting into multiple parts"
@@ -1347,11 +1342,11 @@
for ovalfile in $oval_files_sorted
do
- filedate=`stat -c "%Y" "$ovalfile" | cut -d " " -f 1 | tr -d "-"`
+ filedate=`stat -f "%m" "$ovalfile" | cut -d " " -f 1 | tr -d "-"`
filedate=$(( $filedate - ( $filedate % 60 ) ))
if [ $filedate -gt $DB_LASTUPDATE ] || [ 1 = "$REBUILD_OVAL" ]
then
- oval_timestamp=`xsltproc "$SCAP_RES_DIR/oval_timestamp.xsl" "$ovalfile" | date "+%s" -f -`
+ oval_timestamp=`date -j -f '%Y-%m-%dT%H:%M:%S' $(xsltproc "$SCAP_RES_DIR/oval_timestamp.xsl" "$ovalfile" | cut -d "." -f1) +%s`
if [ 1 = "$REBUILD_OVAL" ]
then
@@ -1403,7 +1398,7 @@
update_cvss
update_placeholders
- LAST_UPDATE_TIMESTAMP=`sed 's/^\(.\{8\}\)/\1 /' $TIMESTAMP | env TZ="UTC" date +%s -f -`
+ LAST_UPDATE_TIMESTAMP=`date -j -f '%Y%m%d%H%M%S' $(sed 's/$/00/g' $TIMESTAMP) +%s`
reset_sql_tries
until [ "$try_sql" -eq 0 ]
@@ -1635,7 +1630,7 @@
then
if [ -f "$SCAP_DB" ]
then
- if [ "$(id -u)" -ne "$(stat -c %u $SCAP_DB)" ]
+ if [ "$(id -u)" -ne "$(stat -f %u $SCAP_DB)" ]
then
log_err "Not synchronizing or updating the database since the current user is not the owner of the database."
echo "Not synchronizing or updating the database since the current user is not the owner of the database."