46 GHashTable *names_table,
int autoload,
char *
oid)
54 if (g_hash_table_lookup (oids_table,
oid))
58 nvti = nvticache_get_nvt (
oid);
61 g_warning (
"The NVT with oid %s was not found in the nvticache.",
oid);
65 tag_value = nvti_get_tag (nvti,
"deprecated");
66 if (tag_value && !strcmp (tag_value,
"1"))
68 if (prefs_get_bool (
"log_whole_attack"))
70 char *
name = nvticache_get_filename (
oid);
71 g_message (
"Plugin %s is deprecated. "
72 "It will neither be loaded nor launched.",
81 category = nvti_category (nvti);
84 g_warning (
"The NVT with oid %s has no category assigned. This is "
85 "considered a fatal error, since the NVTI Cache "
86 "structure stored in Redis is out dated or corrupted.",
93 plugin->
oid = g_strdup (
oid);
94 g_hash_table_insert (oids_table, plugin->
oid, plugin);
96 sched->
list[category] = g_slist_prepend (sched->
list[category], plugin);
101 char *saveptr, *dep_name = NULL, *
deps = nvti_dependencies (nvti);
104 dep_name = strtok_r (
deps,
", ", &saveptr);
110 dep_oid = g_hash_table_lookup (names_table, dep_name);
113 dep_oid = nvticache_get_oid (dep_name);
114 g_hash_table_insert (names_table, g_strdup (dep_name), dep_oid);
119 plugin_add (sched, oids_table, names_table, autoload, dep_oid);
122 dep_plugin = g_hash_table_lookup (oids_table, dep_oid);
127 plugin->
deps = g_slist_prepend (plugin->
deps, dep_plugin);
129 g_warning (
"There was a problem loading %s (%s), a "
130 "dependency of %s. This can happen e.g. when "
131 "depending on a deprecated NVT.",
132 dep_name, dep_oid,
oid);
136 char *
name = nvticache_get_name (
oid);
138 "There was a problem trying to load %s, a dependency "
139 "of %s. This may be due to a parse error, or it failed "
140 "to find the dependency. Please check the path to the "
145 dep_name = strtok_r (NULL,
", ", &saveptr);
159 GSList *element = sched->
list[category];
166 assert (plugin->
deps == NULL);
167 deps = nvticache_get_dependencies (plugin->
oid);
171 char **array = g_strsplit (
deps,
", ", 0);
173 for (i = 0; array[i]; i++)
176 char *dep_oid = nvticache_get_oid (array[i]);
177 dep_plugin = g_hash_table_lookup (oids_table, dep_oid);
179 plugin->
deps = g_slist_prepend (plugin->
deps, dep_plugin);
185 element = element->next;
203 char *oids, *
oid, *saveptr;
204 GHashTable *oids_table, *names_table;
205 int error_counter = 0;
207 oids_table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
208 names_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
211 oids = g_strdup (oid_list);
212 oid = strtok_r (oids,
";", &saveptr);
217 oid = strtok_r (NULL,
";", &saveptr);
224 if (error_counter > 0)
225 g_warning (
"%s: %d errors were found during the plugin scheduling.",
226 __func__, error_counter);
228 g_hash_table_destroy (oids_table);
229 g_hash_table_destroy (names_table);
232 return error_counter;
239 GSList *element = array[pos]->
deps;
242 for (i = 0; i < pos; i++)
243 if (array[i] == array[pos])
246 if (g_hash_table_lookup (checked, array[pos]))
252 array[pos + 1] = element->data;
256 element = element->next;
258 g_hash_table_insert (checked, array[pos], array[pos]);
268 checked = g_hash_table_new_full (g_str_hash, g_direct_equal, NULL, NULL);
271 GSList *element = sched->
list[i];
278 array[0] = element->data;
282 g_warning (
"Dependency cycle:");
283 for (j = 0; j <= pos; j++)
285 char *
name = nvticache_get_filename (array[j]->
oid);
287 g_message (
" %s (%s)",
name, array[j]->
oid);
291 g_hash_table_destroy (checked);
294 element = element->next;
297 g_hash_table_destroy (checked);