From 17d1f3ca5b3e6784cab57632ac5732002558713b Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Wed, 22 May 2019 11:44:55 +0200 Subject: [PATCH] Fetch OSP results while scan is running Without this OSP tasks had to wait until the end of the scan before fetching any results, which could take a long time for scanners like the OpenVAS one and tasks with many target hosts. --- src/manage.c | 39 ++++++++++++++++++++++----------------- src/manage_sql.c | 17 +++++++---------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/manage.c b/src/manage.c index 4c0e6079f..8d62952b4 100644 --- a/src/manage.c +++ b/src/manage.c @@ -3998,6 +3998,7 @@ delete_osp_scan (const char *report_id, const char *host, int port, * @param[in] key_pub Certificate. * @param[in] key_priv Private key. * @param[in] details 1 for detailed report, 0 otherwise. + * @param[in] pop_results 1 to pop results, 0 to leave results intact. * @param[out] report_xml Scan report. * * @return -1 on error, progress value between 0 and 100 on success. @@ -4005,7 +4006,8 @@ delete_osp_scan (const char *report_id, const char *host, int port, static int get_osp_scan_report (const char *scan_id, const char *host, int port, const char *ca_pub, const char *key_pub, const char - *key_priv, int details, char **report_xml) + *key_priv, int details, int pop_results, + char **report_xml) { osp_connection_t *connection; int progress; @@ -4017,7 +4019,8 @@ get_osp_scan_report (const char *scan_id, const char *host, int port, g_warning ("Couldn't connect to OSP scanner on %s:%d", host, port); return -1; } - progress = osp_get_scan (connection, scan_id, report_xml, details, &error); + progress = osp_get_scan_pop (connection, scan_id, report_xml, details, + pop_results, &error); if (progress > 100 || progress < 0) { g_warning ("OSP get_scan %s: %s", scan_id, error); @@ -4064,8 +4067,8 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id) break; } int progress = get_osp_scan_report (scan_id, host, port, ca_pub, key_pub, - key_priv, 0, NULL); - if (progress == -1) + key_priv, 0, 0, &report_xml); + if (progress < 0 || progress > 100) { result_t result = make_osp_result (task, "", "", threat_message_type ("Error"), @@ -4075,17 +4078,12 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id) rc = -1; break; } - else if (progress < 100) - { - set_report_slave_progress (report, progress); - gvm_sleep (10); - } - else if (progress == 100) + else { /* Get the full OSP report. */ progress = get_osp_scan_report (scan_id, host, port, ca_pub, key_pub, - key_priv, 1, &report_xml); - if (progress != 100) + key_priv, 1, 1, &report_xml); + if (progress < 0 || progress > 100) { result_t result = make_osp_result (task, "", "", threat_message_type ("Error"), @@ -4095,11 +4093,18 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id) rc = -1; break; } - parse_osp_report (task, report, report_xml); - g_free (report_xml); - delete_osp_scan (scan_id, host, port, ca_pub, key_pub, key_priv); - rc = 0; - break; + else + { + set_report_slave_progress (report, progress); + parse_osp_report (task, report, report_xml); + g_free (report_xml); + if (progress == 100) + { + delete_osp_scan (scan_id, host, port, ca_pub, key_pub, + key_priv); + break; + } + } } } diff --git a/src/manage_sql.c b/src/manage_sql.c index 2a480621a..8e6eabc30 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -32514,21 +32514,18 @@ parse_osp_report (task_t task, report_t report, const char *report_xml) sql_begin_immediate (); /* Set the report's start and end times. */ str = entity_attribute (entity, "start_time"); - if (!str) + if (str) { - g_warning ("Missing start_time in OSP report %s", report_xml); - goto end_parse_osp_report; + start_time = atoi (str); + set_scan_start_time_epoch (report, start_time); } - start_time = atoi (str); - set_scan_start_time_epoch (report, start_time); + str = entity_attribute (entity, "end_time"); - if (!str) + if (str) { - g_warning ("Missing end_time in OSP report %s", report_xml); - goto end_parse_osp_report; + end_time = atoi (str); + set_scan_end_time_epoch (report, end_time); } - end_time = atoi (str); - set_scan_end_time_epoch (report, end_time); /* Insert results. */ child = entity_child (entity, "results");