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);
71 && (g_str_has_prefix (nvti_tag (nvti),
"deprecated=1")
72 || strstr (nvti_tag (nvti),
"|deprecated=1")))
74 if (prefs_get_bool (
"log_whole_attack"))
76 char *
name = nvticache_get_filename (
oid);
77 g_message (
"Plugin %s is deprecated. "
78 "It will neither be loaded nor launched.",
86 category = nvti_category (nvti);
89 g_message (
"The NVT with oid %s has no category assigned. This is "
90 "considered a fatal error, since the NVTI Cache "
91 "structure stored in Redis is out dated or corrupted.",
98 plugin->
oid = g_strdup (
oid);
99 g_hash_table_insert (oids_table, plugin->
oid, plugin);
101 sched->
list[category] = g_slist_prepend (sched->
list[category], plugin);
106 char *saveptr, *dep_name = NULL, *
deps = nvti_dependencies (nvti);
109 dep_name = strtok_r (
deps,
", ", &saveptr);
115 dep_oid = g_hash_table_lookup (names_table, dep_name);
118 dep_oid = nvticache_get_oid (dep_name);
119 g_hash_table_insert (names_table, g_strdup (dep_name), dep_oid);
124 plugin_add (sched, oids_table, names_table, autoload, dep_oid);
127 dep_plugin = g_hash_table_lookup (oids_table, dep_oid);
132 plugin->
deps = g_slist_prepend (plugin->
deps, dep_plugin);
134 g_warning (
"There was a problem loading %s (%s), a "
135 "dependency of %s. This can happen e.g. when "
136 "depending on a deprecated NVT.",
137 dep_name, dep_oid,
oid);
141 char *
name = nvticache_get_name (
oid);
143 "There was a problem trying to load %s, a dependency "
144 "of %s. This may be due to a parse error, or it failed "
145 "to find the dependency. Please check the path to the "
150 dep_name = strtok_r (NULL,
", ", &saveptr);
164 GSList *element = sched->
list[category];
171 assert (plugin->
deps == NULL);
172 deps = nvticache_get_dependencies (plugin->
oid);
176 char **array = g_strsplit (
deps,
", ", 0);
178 for (i = 0; array[i]; i++)
181 char *dep_oid = nvticache_get_oid (array[i]);
182 dep_plugin = g_hash_table_lookup (oids_table, dep_oid);
184 plugin->
deps = g_slist_prepend (plugin->
deps, dep_plugin);
190 element = element->next;
206 char *oids, *
oid, *saveptr;
207 GHashTable *oids_table, *names_table;
209 static int error_counter = 0;
211 oids_table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
212 names_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
215 oids = g_strdup (oid_list);
216 oid = strtok_r (oids,
";", &saveptr);
219 ret =
plugin_add (sched, oids_table, names_table, autoload,
oid);
223 if (error_counter >= 5)
225 g_message (
"Stopped plugin scheduler: High number of errors.");
229 oid = strtok_r (NULL,
";", &saveptr);
237 g_hash_table_destroy (oids_table);
238 g_hash_table_destroy (names_table);
247 GSList *element = array[pos]->
deps;
250 for (i = 0; i < pos; i++)
251 if (array[i] == array[pos])
254 if (g_hash_table_lookup (checked, array[pos]))
260 array[pos + 1] = element->data;
264 element = element->next;
266 g_hash_table_insert (checked, array[pos], array[pos]);
276 checked = g_hash_table_new_full (g_str_hash, g_direct_equal, NULL, NULL);
279 GSList *element = sched->
list[i];
286 array[0] = element->data;
290 g_warning (
"Dependency cycle:");
291 for (j = 0; j <= pos; j++)
293 char *
name = nvticache_get_filename (array[j]->
oid);
295 g_message (
" %s (%s)",
name, array[j]->
oid);
299 g_hash_table_destroy (checked);
302 element = element->next;
305 g_hash_table_destroy (checked);
317 ret = g_malloc0 (
sizeof (*ret));
349 ret += g_slist_length (sched->
list[i]);
356 int still_running = 0;
366 GSList *deps_list = plugin->
deps;
390 plugins = plugins->next;
400 int still_running = 0;
402 for (category = start; category <= end; category++)
405 element = h->
list[category];
426 for (category = start; category <= end; category++)
428 GSList *element = sched->
list[category];
433 g_free (plugin->
oid);
434 g_slist_free (plugin->
deps);
437 element = element->next;
447 static int scheduler_phase = 0;
452 if (scheduler_phase == 0)
460 if (scheduler_phase <= 1)
468 if (scheduler_phase <= 2)
476 if (scheduler_phase <= 3)
484 if (scheduler_phase <= 4)
509 GSList *element = sched->
list[category];
516 element = element->next;
530 g_free (plugin->
oid);
531 g_slist_free (plugin->
deps);