Skip to content

Commit

Permalink
Merge pull request #439 from jjnicola/nvti-failure-7
Browse files Browse the repository at this point in the history
Perform a scan even if there are missing plugins.
  • Loading branch information
jjnicola authored Dec 3, 2019
2 parents 7895ed8 + e282e42 commit 71f4b5e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Changed
- Improve handling of invalid or existent ids of nvt's preference id. [#416](https://github.com/greenbone/openvas/pull/416)
- Perform a scan even if there are missing plugins. [#439](https://github.com/greenbone/openvas/pull/439)

### Fixed
- Do not store in memory an empty file received as nvt preference. [#409](https://github.com/greenbone/openvas/pull/409)
Expand Down
19 changes: 18 additions & 1 deletion src/attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1074,15 +1074,32 @@ attack_network (struct scan_globals *globals, kb_t *network_kb)
}

/* Initialize the attack. */
int plugins_init_error = 0;
sched = plugins_scheduler_init (prefs_get ("plugin_set"),
prefs_get_bool ("auto_enable_dependencies"),
network_phase);
network_phase, &plugins_init_error);
if (!sched)
{
g_message ("Couldn't initialize the plugin scheduler");
return;
}

if (plugins_init_error > 0)
{
char buf[96];
int i = atoi (prefs_get ("ov_maindbid"));
kb_t main_kb = NULL;

sprintf (buf,
"%d errors were found during the plugin scheduling. "
"Some plugins have not been launched.",
plugins_init_error);

main_kb = kb_direct_conn (prefs_get ("db_address"), i);
error_message_to_client2 (main_kb, buf, NULL);
kb_lnk_reset (main_kb);
}

max_hosts = get_max_hosts_number ();
max_checks = get_max_checks_number ();

Expand Down
44 changes: 21 additions & 23 deletions src/pluginscheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ plugin_add (plugins_scheduler_t sched, GHashTable *oids_table,

/* Check if the plugin is deprecated */
nvti = nvticache_get_nvt (oid);
if (nvti == NULL)
{
g_warning ("The NVT with oid %s was not found in the nvticache.", oid);
return 1;
}

if (nvti_tag (nvti)
&& (g_str_has_prefix (nvti_tag (nvti), "deprecated=1")
|| strstr (nvti_tag (nvti), "|deprecated=1")))
Expand All @@ -86,7 +92,7 @@ plugin_add (plugins_scheduler_t sched, GHashTable *oids_table,
category = nvti_category (nvti);
if (!(category >= ACT_INIT && category <= ACT_END))
{
g_message ("The NVT with oid %s has no category assigned. This is "
g_warning ("The NVT with oid %s has no category assigned. This is "
"considered a fatal error, since the NVTI Cache "
"structure stored in Redis is out dated or corrupted.",
oid);
Expand Down Expand Up @@ -198,15 +204,16 @@ plugins_scheduler_fill_deps (plugins_scheduler_t sched, GHashTable *oids_table)
* param[in] sched Plugins scheduler.
* param[in] oid_list List of plugins to enable.
* param[in] autoload Whether to autoload dependencies.
*
* return error_counter Number of errors found during the schecuduling.
*/
static int
plugins_scheduler_enable (plugins_scheduler_t sched, const char *oid_list,
int autoload)
{
char *oids, *oid, *saveptr;
GHashTable *oids_table, *names_table;
int ret = 0;
static int error_counter = 0;
int error_counter = 0;

oids_table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
names_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
Expand All @@ -216,28 +223,24 @@ plugins_scheduler_enable (plugins_scheduler_t sched, const char *oid_list,
oid = strtok_r (oids, ";", &saveptr);
while (oid)
{
ret = plugin_add (sched, oids_table, names_table, autoload, oid);
if (ret)
{
error_counter++;
if (error_counter >= 5)
{
g_message ("Stopped plugin scheduler: High number of errors.");
goto error;
}
}
error_counter +=
plugin_add (sched, oids_table, names_table, autoload, oid);
oid = strtok_r (NULL, ";", &saveptr);
}

/* When autoload is disabled, each plugin's deps list is still empty. */
if (!autoload)
plugins_scheduler_fill_deps (sched, oids_table);

error:
if (error_counter > 0)
g_warning ("%s: %d errors were found during the plugin scheduling.",
__func__, error_counter);

g_hash_table_destroy (oids_table);
g_hash_table_destroy (names_table);
g_free (oids);
return ret;

return error_counter;
}

int
Expand Down Expand Up @@ -308,19 +311,14 @@ check_dependency_cycles (plugins_scheduler_t sched)

plugins_scheduler_t
plugins_scheduler_init (const char *plugins_list, int autoload,
int only_network)
int only_network, int *error)
{
plugins_scheduler_t ret;
int i, err = 0;
int i;

/* Fill our lists */
ret = g_malloc0 (sizeof (*ret));
err = plugins_scheduler_enable (ret, plugins_list, autoload);
if (err)
{
plugins_scheduler_free (ret);
return NULL;
}
*error = plugins_scheduler_enable (ret, plugins_list, autoload);

if (only_network)
{
Expand Down
2 changes: 1 addition & 1 deletion src/pluginscheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ typedef struct plugins_scheduler *plugins_scheduler_t;
#define PLUG_RUNNING ((struct scheduler_plugin *) 0x02)

plugins_scheduler_t
plugins_scheduler_init (const char *, int, int);
plugins_scheduler_init (const char *, int, int, int *);

struct scheduler_plugin *plugins_scheduler_next (plugins_scheduler_t);

Expand Down

0 comments on commit 71f4b5e

Please sign in to comment.