Skip to content

Commit

Permalink
Get NVTICACHE_STR used by openvassd.
Browse files Browse the repository at this point in the history
This string is used to find the db in redis that stored the nvti cache.
  • Loading branch information
jjnicola committed Sep 25, 2018
1 parent 6e63d26 commit 947ecf3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
26 changes: 24 additions & 2 deletions ospd_openvas/nvticache.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,33 @@
from __future__ import absolute_import
from __future__ import print_function

import subprocess
from shutil import which
import xml.etree.ElementTree as ET
import ospd_openvas.openvas_db as openvas_db


NVTICACHE_STR = 'nvticache10'
NVTICACHE_STR = ""

def set_nvticache_str():
""" Get NVTICACHE_STR. """
global NVTICACHE_STR

try:
openvassd_bin = which('openvassd')
result = subprocess.check_output([openvassd_bin, '-V', '--scan-start=1'], shell=False,
stderr=subprocess.STDOUT)
result = result.decode('ascii')
except OSError:
# The command is not available
return 1

if result is None:
return 1
version = result.split('\n')
if 'NVTI Cache version' in version[1]:
NVTICACHE_STR = version[1].split()[-1]
else:
NVTICACHE_STR = version[2].split()[-1]

def get_feed_version():
""" Get feed version.
Expand Down
5 changes: 5 additions & 0 deletions ospd_openvas/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ def __init__(self, certfile, keyfile, cafile):
'to find db_connection.')
raise Exception

if nvti.set_nvticache_str():
logger.error('OpenVAS Error: Not possible '
'to set NVTICACHE_STR.')
raise Exception

ctx = openvas_db.db_find(nvti.NVTICACHE_STR)
if not ctx:
self.redis_nvticache_init()
Expand Down

0 comments on commit 947ecf3

Please sign in to comment.