32 #include <openvas/base/nvti.h> 34 #include <openvas/misc/nvt_categories.h> 35 #include <openvas/misc/plugutils.h> 37 #include <openvas/base/nvticache.h> 103 hash_link_destroy (
struct hash *h)
109 hash_link_destroy (h->
next);
117 hash_destroy (
struct hash *h)
123 hash_link_destroy (h[i].
next);
132 struct hash *l = g_malloc0 (
sizeof (
struct hash));
145 _hash_get (
struct hash *h,
char *name)
147 unsigned int idx = mkhash (name);
160 static struct hash **
161 hash_get_deps_ptr (
struct hash *h,
char *name)
163 struct hash *l = _hash_get (h, name);
172 hash_fill_deps (
struct hash *h,
struct hash *l)
174 int i, j = 0, num_deps;
175 char *dependencies, **array;
179 dependencies = nvticache_get_dependencies (l->
plugin->
oid);
182 array = g_strsplit (dependencies,
", ", 0);
183 g_free (dependencies);
187 for (num_deps = 0; array[num_deps]; num_deps++)
193 for (i = 0; array[i]; i++)
198 oid = nvticache_get_oid (array[i]);
201 log_write (
"scheduler: %s depends on %s which could not be found",
205 d = _hash_get (h, oid);
209 log_write (
"scheduler: %s depends on %s which could not be found",
245 char *ports, **array;
248 ports = nvticache_get_required_ports (plugin->
oid);
252 array = g_strsplit (ports,
", ", 0);
256 for (i = 0; array[i] != NULL; i++)
264 pl = g_malloc0 (
sizeof (
struct plist));
265 pl->
name = g_strdup (array[i]);
268 if (sched->
plist != NULL)
281 char *ports, **array;
284 ports = nvticache_get_required_ports (plugin->
oid);
288 array = g_strsplit (ports,
", ", 0);
292 for (i = 0; array[i] != NULL; i++)
301 if (pl->
next != NULL)
304 if (pl->
prev != NULL)
314 log_write (
"Warning: scheduler_rm_running_ports failed ?! (%s)\n",
323 struct hash **dependencies_ptr,
int calls)
328 if (dependencies_ptr == NULL)
333 log_write (
"Possible dependency cycle detected %s",
334 dependencies_ptr[0]->plugin->
oid);
337 if (calls && calls % 15 == 0)
340 for (i = 0; dependencies_ptr[i] != NULL; i++)
344 plugin = dependencies_ptr[i]->
plugin;
352 struct hash **deps_ptr;
356 if (deps_ptr == NULL)
395 GHashTable *deps_table)
397 struct hash **deps_ptr;
403 if (g_hash_table_lookup (deps_table,
plugin->
oid))
410 if (deps_ptr == NULL)
412 for (i = 0; deps_ptr[i] != NULL; i++)
417 enable_plugin_and_dependencies (shed, p, deps_table);
436 GHashTable *oids_table;
438 oids_table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
441 oids = g_strdup (oid_list);
442 oid = strtok (oids,
";");
445 g_hash_table_insert (oids_table,
oid,
oid);
446 oid = strtok (NULL,
";");
450 for (i = ACT_FIRST; i <= ACT_LAST; i++)
452 struct list *element = sched->
list[i];
456 if (g_hash_table_lookup (oids_table, element->
plugin->
oid))
459 element = element->
next;
462 g_hash_table_destroy (oids_table);
467 for (i = ACT_FIRST; i <= ACT_LAST; i++)
469 struct list *element = sched->
list[i];
474 GHashTable *deps_table;
476 deps_table = g_hash_table_new_full
477 (g_str_hash, g_str_equal, g_free, NULL);
479 enable_plugin_and_dependencies (sched, element->
plugin,
482 g_hash_table_destroy (deps_table);
483 element = element->
next;
493 GSList *
list, *element;
495 list = element = nvticache_get_oids ();
502 category = nvticache_get_category (element->data);
508 assert (category <= ACT_LAST);
509 dup = g_malloc0 (
sizeof (
struct list));
513 if (sched->
list[category] != NULL)
515 sched->
list[category] = dup;
518 element = element->next;
520 g_slist_free_full (
list, g_free);
527 hash_fill_deps (sched->
hash, l);
541 ret = g_malloc0 (
sizeof (*ret));
542 ret->
hash = hash_init ();
543 plugins_scheduler_fill (ret);
545 plugins_scheduler_enable (ret, plugins_list, autoload);
548 for (i = ACT_FIRST; i <= ACT_LAST; i++)
552 while (
plist != NULL)
554 if (!
plist->plugin->enabled)
576 for (i = ACT_GATHER_INFO; i <= ACT_LAST; i++)
590 for (i = ACT_FIRST; i <= ACT_LAST; i++)
592 struct list *element = sched->
list[i];
598 element = element->
next;
621 switch (GPOINTER_TO_SIZE (p))
623 case GPOINTER_TO_SIZE (NULL):
669 struct list *element;
670 int still_running = 0;
672 for (category = start; category <= end; category++)
674 element = h->
list[category];
675 if (category == ACT_SCANNER || category == ACT_KILL_HOST
676 || category == ACT_FLOOD || category == ACT_DENIAL)
684 element = element->
next;
700 ret = get_next_in_range (h, ACT_INIT, ACT_INIT);
703 ret = get_next_in_range (h, ACT_SCANNER, ACT_SCANNER);
706 ret = get_next_in_range (h, ACT_SETTINGS, ACT_GATHER_INFO);
709 ret = get_next_in_range (h, ACT_ATTACK, ACT_FLOOD);
712 ret = get_next_in_range (h, ACT_END, ACT_END);
733 hash_destroy (sched->
hash);
734 for (i = ACT_FIRST; i <= ACT_LAST; i++)
struct list * list[ACT_LAST+1]
struct scheduler_plugin * plugin_next_unrun_dependency(plugins_scheduler_t sched, struct hash **dependencies_ptr, int calls)
void pluginlaunch_enable_parrallel_checks(void)
void log_write(const char *str,...)
Write into the logfile / syslog.
plugins_scheduler_t plugins_scheduler_init(const char *plugins_list, int autoload, int only_network)
struct scheduler_plugin * plugins_scheduler_next(plugins_scheduler_t h)
void scheduler_rm_running_ports(plugins_scheduler_t sched, struct scheduler_plugin *plugin)
void plugins_scheduler_free(plugins_scheduler_t sched)
int plugins_scheduler_count_active(plugins_scheduler_t sched)
void pluginlaunch_wait_for_free_process(void)
Waits and 'pushes' processes until the number of running processes has changed.
struct scheduler_plugin * plugin
void scheduler_mark_running_ports(plugins_scheduler_t sched, struct scheduler_plugin *plugin)
#define PLUGIN_STATUS_DONE
#define PLUGIN_STATUS_RUNNING
struct hash ** dependencies_ptr
void pluginlaunch_disable_parrallel_checks(void)
#define PLUGIN_STATUS_UNRUN
void list_destroy(struct list *list)
struct scheduler_plugin * plugin
#define PLUGIN_STATUS_DONE_AND_CLEANED
struct plist * pl_get(struct plist *list, char *name)
struct hash * parent_hash