28 #include "../misc/nvt_categories.h"
29 #include "../misc/plugutils.h"
34 #include <gvm/base/prefs.h>
35 #include <gvm/util/nvticache.h>
43 #define G_LOG_DOMAIN "sd main"
59 GHashTable *names_table,
int autoload,
char *
oid)
65 if (g_hash_table_lookup (oids_table,
oid))
69 nvti = nvticache_get_nvt (
oid);
72 g_warning (
"The NVT with oid %s was not found in the nvticache.",
oid);
77 && (g_str_has_prefix (nvti_tag (nvti),
"deprecated=1")
78 || strstr (nvti_tag (nvti),
"|deprecated=1")))
80 if (prefs_get_bool (
"log_whole_attack"))
82 char *
name = nvticache_get_filename (
oid);
83 g_message (
"Plugin %s is deprecated. "
84 "It will neither be loaded nor launched.",
92 category = nvti_category (nvti);
95 g_warning (
"The NVT with oid %s has no category assigned. This is "
96 "considered a fatal error, since the NVTI Cache "
97 "structure stored in Redis is out dated or corrupted.",
104 plugin->
oid = g_strdup (
oid);
105 g_hash_table_insert (oids_table, plugin->
oid, plugin);
107 sched->
list[category] = g_slist_prepend (sched->
list[category], plugin);
112 char *saveptr, *dep_name = NULL, *
deps = nvti_dependencies (nvti);
115 dep_name = strtok_r (
deps,
", ", &saveptr);
121 dep_oid = g_hash_table_lookup (names_table, dep_name);
124 dep_oid = nvticache_get_oid (dep_name);
125 g_hash_table_insert (names_table, g_strdup (dep_name), dep_oid);
130 plugin_add (sched, oids_table, names_table, autoload, dep_oid);
133 dep_plugin = g_hash_table_lookup (oids_table, dep_oid);
138 plugin->
deps = g_slist_prepend (plugin->
deps, dep_plugin);
140 g_warning (
"There was a problem loading %s (%s), a "
141 "dependency of %s. This can happen e.g. when "
142 "depending on a deprecated NVT.",
143 dep_name, dep_oid,
oid);
147 char *
name = nvticache_get_name (
oid);
149 "There was a problem trying to load %s, a dependency "
150 "of %s. This may be due to a parse error, or it failed "
151 "to find the dependency. Please check the path to the "
156 dep_name = strtok_r (NULL,
", ", &saveptr);
170 GSList *element = sched->
list[category];
177 assert (plugin->
deps == NULL);
178 deps = nvticache_get_dependencies (plugin->
oid);
182 char **array = g_strsplit (
deps,
", ", 0);
184 for (i = 0; array[i]; i++)
187 char *dep_oid = nvticache_get_oid (array[i]);
188 dep_plugin = g_hash_table_lookup (oids_table, dep_oid);
190 plugin->
deps = g_slist_prepend (plugin->
deps, dep_plugin);
196 element = element->next;
214 char *oids, *
oid, *saveptr;
215 GHashTable *oids_table, *names_table;
216 int error_counter = 0;
218 oids_table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
219 names_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
222 oids = g_strdup (oid_list);
223 oid = strtok_r (oids,
";", &saveptr);
228 oid = strtok_r (NULL,
";", &saveptr);
235 if (error_counter > 0)
236 g_warning (
"%s: %d errors were found during the plugin scheduling.",
237 __func__, error_counter);
239 g_hash_table_destroy (oids_table);
240 g_hash_table_destroy (names_table);
243 return error_counter;
250 GSList *element = array[pos]->
deps;
253 for (i = 0; i < pos; i++)
254 if (array[i] == array[pos])
257 if (g_hash_table_lookup (checked, array[pos]))
263 array[pos + 1] = element->data;
267 element = element->next;
269 g_hash_table_insert (checked, array[pos], array[pos]);
279 checked = g_hash_table_new_full (g_str_hash, g_direct_equal, NULL, NULL);
282 GSList *element = sched->
list[i];
289 array[0] = element->data;
293 g_warning (
"Dependency cycle:");
294 for (j = 0; j <= pos; j++)
296 char *
name = nvticache_get_filename (array[j]->
oid);
298 g_message (
" %s (%s)",
name, array[j]->
oid);
302 g_hash_table_destroy (checked);
305 element = element->next;
308 g_hash_table_destroy (checked);
314 int only_network,
int *error)
320 ret = g_malloc0 (
sizeof (*ret));
347 ret += g_slist_length (sched->
list[i]);
354 int still_running = 0;
364 GSList *deps_list = plugin->
deps;
388 plugins = plugins->next;
398 int still_running = 0;
400 for (category = start; category <= end; category++)
403 element = h->
list[category];
424 for (category = start; category <= end; category++)
426 GSList *element = sched->
list[category];
431 g_free (plugin->
oid);
432 g_slist_free (plugin->
deps);
435 element = element->next;
445 static int scheduler_phase = 0;
450 if (scheduler_phase == 0)
458 if (scheduler_phase <= 1)
466 if (scheduler_phase <= 2)
474 if (scheduler_phase <= 3)
482 if (scheduler_phase <= 4)
507 GSList *element = sched->
list[category];
514 element = element->next;
528 g_free (plugin->
oid);
529 g_slist_free (plugin->
deps);