Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hosts count when reverse_lookup_only preferences is enabled. #715

Merged
merged 2 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix double free in nasl_cert_query. [#658](https://github.com/greenbone/openvas/pull/658)
- Fix message to the client if there is a iface problem. [#695](https://github.com/greenbone/openvas/pull/695)
- Fix SIGSEGV when no best route is found. [#702](https://github.com/greenbone/openvas/pull/702)
- Fix host count when reverse_lookup_only is enabled. [#715](https://github.com/greenbone/openvas/pull/715)

### Removed
- Remove code from the openvas daemon era. Do not flushall redis. [#689](https://github.com/greenbone/openvas/pull/689)
Expand Down
47 changes: 28 additions & 19 deletions src/attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,13 +731,27 @@ attack_start (struct attack_start_args *args)
}

static void
apply_hosts_preferences (gvm_hosts_t *hosts)
apply_hosts_excluded (gvm_hosts_t *hosts)
{
const char *ordering = prefs_get ("hosts_ordering"),
*exclude_hosts = prefs_get ("exclude_hosts");
const char *exclude_hosts = prefs_get ("exclude_hosts");

if (hosts == NULL)
return;
/* Exclude hosts ? */
if (exclude_hosts)
{
/* Exclude hosts, resolving hostnames. */
int 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.");
}
}

static void
apply_hosts_preferences_ordering (gvm_hosts_t *hosts)
{
const char *ordering = prefs_get ("hosts_ordering");

/* Hosts ordering strategy: sequential, random, reversed... */
if (ordering)
Expand All @@ -755,19 +769,11 @@ apply_hosts_preferences (gvm_hosts_t *hosts)
}
else
g_debug ("hosts_ordering: Sequential.");
}

/* Exclude hosts ? */
if (exclude_hosts)
{
/* Exclude hosts, resolving hostnames. */
int 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.");
}

static void
apply_hosts_reverse_lookup_preferences (gvm_hosts_t *hosts)
{
/* Reverse-lookup unify ? */
if (prefs_get_bool ("reverse_lookup_unify"))
g_debug ("reverse_lookup_unify: Skipped %d host(s).",
Expand Down Expand Up @@ -1118,15 +1124,18 @@ attack_network (struct scan_globals *globals)
}
g_slist_free_full (unresolved, g_free);

/* Apply Hosts preferences. */
apply_hosts_preferences_ordering (hosts);
apply_hosts_reverse_lookup_preferences (hosts);

/* Send the hosts count to the client, after removing duplicated and
* unresolved hosts.*/
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);

/* Apply Hosts preferences. */
apply_hosts_preferences (hosts);
apply_hosts_excluded (hosts);

/* Don't start if the provided interface is unauthorized. */
if (apply_source_iface_preference () != 0)
Expand Down