Skip to content

Commit

Permalink
Add "error" argument to plugins_scheduler_init().
Browse files Browse the repository at this point in the history
This allows to detect errors in attack.c and send a message to client.
  • Loading branch information
jjnicola committed Dec 3, 2019
1 parent 47226be commit 3d64dfc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
18 changes: 17 additions & 1 deletion src/attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1074,15 +1074,31 @@ 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 will not be launch.", 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
12 changes: 8 additions & 4 deletions src/pluginscheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +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 void
static int
plugins_scheduler_enable (plugins_scheduler_t sched, const char *oid_list,
int autoload)
{
char *oids, *oid, *saveptr;
GHashTable *oids_table, *names_table;
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 @@ -237,6 +239,8 @@ plugins_scheduler_enable (plugins_scheduler_t sched, const char *oid_list,
g_hash_table_destroy (oids_table);
g_hash_table_destroy (names_table);
g_free (oids);

return error_counter;
}

int
Expand Down Expand Up @@ -307,14 +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;

/* Fill our lists */
ret = g_malloc0 (sizeof (*ret));
plugins_scheduler_enable (ret, plugins_list, autoload);
*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 3d64dfc

Please sign in to comment.