From 4662fa621b43ba2e2749d02bad3028e1737ec108 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Tue, 7 Mar 2023 14:05:57 +0200 Subject: [PATCH 1/2] Add hostname to CVE scan report --- src/manage.c | 10 ++++++++++ src/manage_sql.c | 19 +++++++++++++++++++ src/manage_sql.h | 2 ++ 3 files changed, 31 insertions(+) diff --git a/src/manage.c b/src/manage.c index db2b77a50..74a734fc6 100644 --- a/src/manage.c +++ b/src/manage.c @@ -2990,9 +2990,19 @@ cve_scan_host (task_t task, report_t report, gvm_host_t *gvm_host) if (prognosis_report_host) { + gchar *hostname; + /* Complete the report_host. */ report_host_set_end_time (prognosis_report_host, time (NULL)); + + hostname = report_host_hostname (report_host); + if (hostname) { + insert_report_host_detail (report, ip, "cve", "", + "CVE Scanner", "hostname", hostname); + g_free(hostname); + } + insert_report_host_detail (report, ip, "cve", "", "CVE Scanner", "CVE Scan", "1"); update_report_modification_time (report); diff --git a/src/manage_sql.c b/src/manage_sql.c index 5add27246..2479bc201 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -28860,6 +28860,25 @@ report_host_ip (const char *host) return ret; } +/** + * @brief Get the hostname of a report_host. + * + * The most recent host detail takes preference. + * + * @param[in] report_host Report host. + * + * @return Newly allocated UUID if available, else NULL. + */ +gchar* +report_host_hostname (report_host_t report_host) +{ + return sql_string ("SELECT value FROM report_host_details" + " WHERE report_host = %llu" + " AND name = 'hostname'" + " ORDER BY id DESC LIMIT 1;", + report_host); +} + /** * @brief Check if a report host is alive and has at least one result. * diff --git a/src/manage_sql.h b/src/manage_sql.h index f2360ccaa..44053ef7c 100644 --- a/src/manage_sql.h +++ b/src/manage_sql.h @@ -295,6 +295,8 @@ host_nthlast_report_host (const char *, report_host_t *, int); char* report_host_ip (const char *); +gchar *report_host_hostname (report_host_t); + void trim_report (report_t); int delete_report_internal (report_t); From cc71199a75fae350da0a4b720ac2cac32bd0c7f5 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Mon, 13 Mar 2023 14:40:46 +0200 Subject: [PATCH 2/2] Correct doc --- src/manage_sql.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manage_sql.c b/src/manage_sql.c index 2479bc201..823386c3d 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -28867,7 +28867,7 @@ report_host_ip (const char *host) * * @param[in] report_host Report host. * - * @return Newly allocated UUID if available, else NULL. + * @return Newly allocated hostname if available, else NULL. */ gchar* report_host_hostname (report_host_t report_host)