From cefbebc32b0153c353802f633fa7296b7e6db060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Nicola?= Date: Mon, 11 Mar 2024 07:37:01 +0100 Subject: [PATCH] Change: Send a message with excluded hosts count to ospd. (#1528) Also, the excluded hosts count is subtracted from the hosts count sent to ospd. With this change, openvas sends the information necessary for the progress calculation, and ospd doesn't have to calculate the excluded hosts and subtract from the total amount of hosts. --- src/attack.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/attack.c b/src/attack.c index 331a05c00..abc0d4c2a 100644 --- a/src/attack.c +++ b/src/attack.c @@ -912,22 +912,23 @@ attack_start (struct ipc_context *ipcc, struct attack_start_args *args) } } -static void +static int apply_hosts_excluded (gvm_hosts_t *hosts) { const char *exclude_hosts = prefs_get ("exclude_hosts"); - + int ret = 0; /* Exclude hosts ? */ if (exclude_hosts) { /* Exclude hosts, resolving hostnames. */ - int ret = gvm_hosts_exclude (hosts, exclude_hosts); + ret = gvm_hosts_exclude (hosts, exclude_hosts); if (ret > 0) g_message ("exclude_hosts: Skipped %d host(s).", ret); if (ret < 0) g_message ("exclude_hosts: Error."); } + return ret; } #ifdef FEATURE_HOSTS_ALLOWED_ONLY @@ -1279,16 +1280,23 @@ attack_network (struct scan_globals *globals) apply_hosts_allow_deny (hosts); #endif + // Remove the excluded hosts + int exc = apply_hosts_excluded (hosts); + + /* Send the excluded hosts count to the client, after removing duplicated and + * unresolved hosts.*/ + sprintf (buf, "%d", exc + already_excluded); + connect_main_kb (&main_kb); + message_to_client (main_kb, buf, NULL, NULL, "HOSTS_EXCLUDED"); + kb_lnk_reset (main_kb); + /* Send the hosts count to the client, after removing duplicated and * unresolved hosts.*/ - sprintf (buf, "%d", gvm_hosts_count (hosts) + already_excluded); + sprintf (buf, "%d", gvm_hosts_count (hosts)); connect_main_kb (&main_kb); message_to_client (main_kb, buf, NULL, NULL, "HOSTS_COUNT"); kb_lnk_reset (main_kb); - // Remove the excluded hosts - apply_hosts_excluded (hosts); - host = gvm_hosts_next (hosts); if (host == NULL) goto stop;