From 3d836e7a5ec9d24e4c123573701b184fee175a32 Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Tue, 3 Dec 2019 11:35:00 +0100 Subject: [PATCH] Send messages generated by the scanner main process. Also remove trailing whitespaces from the host and OID strings. --- CHANGELOG.md | 1 + ospd_openvas/daemon.py | 7 ++++--- tests/test_daemon.py | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 143a2884..a5fa6973 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added - Check the vt's preference value for type 'file'. [#130](https://github.com/greenbone/ospd-openvas/pull/130). - Check for malformed credentials. [#160](https://github.com/greenbone/ospd-openvas/pull/160). +- Send messages generated by the scannner main process. [#171](https://github.com/greenbone/ospd-openvas/pull/171). ### Changed - Less strict checks for the nvti cache version. diff --git a/ospd_openvas/daemon.py b/ospd_openvas/daemon.py index 77320545..9510e340 100644 --- a/ospd_openvas/daemon.py +++ b/ospd_openvas/daemon.py @@ -925,13 +925,13 @@ def get_openvas_result(self, scan_id, current_host): res = self.openvas_db.get_result() while res: msg = res.split('|||') - roid = msg[3] + roid = msg[3].strip() rqod = '' rname = '' - rhostname = msg[1] if msg[1] else '' + rhostname = msg[1].strip() if msg[1] else '' host_is_dead = "Host dead" in msg[4] - if not host_is_dead: + if roid and not host_is_dead: if self.vts[roid].get('qod_type'): qod_t = self.vts[roid].get('qod_type') rqod = self.nvti.QOD_TYPES[qod_t] @@ -1507,6 +1507,7 @@ def exec_scan(self, scan_id, target): ctx = self.openvas_db.kb_connect(self.main_kbindex) self.openvas_db.set_redisctx(ctx) + self.get_openvas_result(scan_id, "") dbs = self.openvas_db.get_list_item('internal/dbindex') for i in list(dbs): if i == self.main_kbindex: diff --git a/tests/test_daemon.py b/tests/test_daemon.py index 14ae0d73..075681a7 100644 --- a/tests/test_daemon.py +++ b/tests/test_daemon.py @@ -698,11 +698,11 @@ def test_get_openvas_result(self, mock_ospd, mock_nvti, mock_db): mock_ospd.assert_called_with( '123-456', host='localhost', - hostname=' ', + hostname='', name='', port='general/Host_Details', qod='', - test_id=' ', + test_id='', value='Host dead', )