Skip to content

Commit

Permalink
Fetch OSP results while scan is running
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
timopollmeier committed May 22, 2019
1 parent 6565f37 commit 17d1f3c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
39 changes: 22 additions & 17 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -3998,14 +3998,16 @@ 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.
*/
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;
Expand All @@ -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);
Expand Down Expand Up @@ -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"),
Expand All @@ -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"),
Expand All @@ -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;
}
}
}
}

Expand Down
17 changes: 7 additions & 10 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 17d1f3c

Please sign in to comment.