OpenVAS Scanner  5.1.3
pluginscheduler.c File Reference
#include <string.h>
#include <openvas/base/nvti.h>
#include <openvas/misc/nvt_categories.h>
#include <openvas/misc/plugutils.h>
#include <openvas/base/nvticache.h>
#include <glib.h>
#include "pluginscheduler.h"
#include "pluginload.h"
#include "pluginlaunch.h"
#include "log.h"
Include dependency graph for pluginscheduler.c:

Go to the source code of this file.

Data Structures

struct  hash
 
struct  list
 
struct  plist
 
struct  plugins_scheduler
 

Macros

#define HASH_MAX   2713
 

Functions

struct plistpl_get (struct plist *list, char *name)
 
void scheduler_mark_running_ports (plugins_scheduler_t sched, struct scheduler_plugin *plugin)
 
void scheduler_rm_running_ports (plugins_scheduler_t sched, struct scheduler_plugin *plugin)
 
struct scheduler_pluginplugin_next_unrun_dependency (plugins_scheduler_t sched, struct hash **dependencies_ptr, int calls)
 
plugins_scheduler_t plugins_scheduler_init (const char *plugins_list, int autoload, int only_network)
 
int plugins_scheduler_count_active (plugins_scheduler_t sched)
 
struct scheduler_pluginplugins_scheduler_next (plugins_scheduler_t h)
 
void list_destroy (struct list *list)
 
void plugins_scheduler_free (plugins_scheduler_t sched)
 

Macro Definition Documentation

◆ HASH_MAX

#define HASH_MAX   2713
Todo:
This important module needs documentation and comments.

Definition at line 50 of file pluginscheduler.c.

Function Documentation

◆ list_destroy()

void list_destroy ( struct list list)

Definition at line 719 of file pluginscheduler.c.

References list::next.

720 {
721  while (list != NULL)
722  {
723  struct list *next = list->next;
724  g_free (list);
725  list = next;
726  }
727 }
struct list * next

◆ pl_get()

struct plist* pl_get ( struct plist list,
char *  name 
)

Definition at line 220 of file pluginscheduler.c.

References plist::name, and list::next.

Referenced by scheduler_mark_running_ports(), and scheduler_rm_running_ports().

221 {
222  while (list != NULL)
223  {
224  if (strcmp (list->name, name) == 0)
225  return list;
226  else
227  list = list->next;
228  }
229  return NULL;
230 }
struct list * next
Here is the caller graph for this function:

◆ plugin_next_unrun_dependency()

struct scheduler_plugin* plugin_next_unrun_dependency ( plugins_scheduler_t  sched,
struct hash **  dependencies_ptr,
int  calls 
)

Definition at line 322 of file pluginscheduler.c.

References hash::dependencies_ptr, log_write(), scheduler_plugin::oid, PLUG_RUNNING, hash::plugin, PLUGIN_STATUS_DONE, PLUGIN_STATUS_DONE_AND_CLEANED, PLUGIN_STATUS_RUNNING, PLUGIN_STATUS_UNRUN, pluginlaunch_wait_for_free_process(), scheduler_plugin::running_state, and scheduler_rm_running_ports().

324 {
325  int flag = 0;
326  int i;
327 
328  if (dependencies_ptr == NULL)
329  return NULL;
330 
331  if (calls > 100)
332  {
333  log_write ("Possible dependency cycle detected %s",
334  dependencies_ptr[0]->plugin->oid);
335  return NULL;
336  }
337  if (calls && calls % 15 == 0)
339 
340  for (i = 0; dependencies_ptr[i] != NULL; i++)
341  {
342  struct scheduler_plugin *plugin;
343 
344  plugin = dependencies_ptr[i]->plugin;
345  if (plugin == NULL)
346  continue;
347 
348  switch (plugin->running_state)
349  {
350  case PLUGIN_STATUS_UNRUN:
351  {
352  struct hash **deps_ptr;
353  struct scheduler_plugin *ret;
354 
355  deps_ptr = dependencies_ptr[i]->dependencies_ptr;
356  if (deps_ptr == NULL)
357  return plugin;
358 
359  ret = plugin_next_unrun_dependency (sched, deps_ptr, calls + 1);
360  if (ret == NULL)
361  return plugin;
362 
363  if (ret == PLUG_RUNNING)
364  flag = 1;
365  else
366  return ret;
367  }
368  break;
370  flag = 1;
371  break;
372  case PLUGIN_STATUS_DONE:
373  scheduler_rm_running_ports (sched, plugin);
375  break;
377  break;
378  }
379  }
380 
381  if (!flag)
382  return NULL;
383 
384  return PLUG_RUNNING;
385 }
struct scheduler_plugin * plugin_next_unrun_dependency(plugins_scheduler_t sched, struct hash **dependencies_ptr, int calls)
void log_write(const char *str,...)
Write into the logfile / syslog.
Definition: log.c:140
void scheduler_rm_running_ports(plugins_scheduler_t sched, struct scheduler_plugin *plugin)
void pluginlaunch_wait_for_free_process(void)
Waits and &#39;pushes&#39; processes until the number of running processes has changed.
Definition: pluginlaunch.c:499
struct scheduler_plugin * plugin
#define PLUGIN_STATUS_DONE
#define PLUGIN_STATUS_RUNNING
struct hash ** dependencies_ptr
#define PLUG_RUNNING
#define PLUGIN_STATUS_UNRUN
struct scheduler_plugin * plugin
#define PLUGIN_STATUS_DONE_AND_CLEANED
Here is the call graph for this function:

◆ plugins_scheduler_count_active()

int plugins_scheduler_count_active ( plugins_scheduler_t  sched)

Definition at line 585 of file pluginscheduler.c.

References scheduler_plugin::enabled, plugins_scheduler::list, list::next, and list::plugin.

586 {
587  int ret = 0, i;
588  assert (sched);
589 
590  for (i = ACT_FIRST; i <= ACT_LAST; i++)
591  {
592  struct list *element = sched->list[i];
593 
594  while (element)
595  {
596  if (element->plugin->enabled)
597  ret++;
598  element = element->next;
599  }
600  }
601  return ret;
602 }
struct list * list[ACT_LAST+1]
struct scheduler_plugin * plugin
struct list * next

◆ plugins_scheduler_free()

void plugins_scheduler_free ( plugins_scheduler_t  sched)

Definition at line 730 of file pluginscheduler.c.

731 {
732  int i;
733  hash_destroy (sched->hash);
734  for (i = ACT_FIRST; i <= ACT_LAST; i++)
735  list_destroy (sched->list[i]);
736  g_free (sched);
737 }
struct list * list[ACT_LAST+1]
struct hash * hash
void list_destroy(struct list *list)

◆ plugins_scheduler_init()

plugins_scheduler_t plugins_scheduler_init ( const char *  plugins_list,
int  autoload,
int  only_network 
)

Definition at line 535 of file pluginscheduler.c.

References plugins_scheduler::hash.

536 {
538  int i;
539 
540  /* Fill our lists */
541  ret = g_malloc0 (sizeof (*ret));
542  ret->hash = hash_init ();
543  plugins_scheduler_fill (ret);
544 
545  plugins_scheduler_enable (ret, plugins_list, autoload);
546 
547  /* Now, remove the plugins that won't be launched */
548  for (i = ACT_FIRST; i <= ACT_LAST; i++)
549  {
550  struct list *plist = ret->list[i];
551 
552  while (plist != NULL)
553  {
554  if (!plist->plugin->enabled)
555  {
556  struct list *old = plist->next;
557 
558  if (plist->prev != NULL)
559  plist->prev->next = plist->next;
560  else
561  ret->list[i] = plist->next;
562 
563  if (plist->next != NULL)
564  plist->next->prev = plist->prev;
565 
566  g_free (plist);
567  plist = old;
568  continue;
569  }
570  plist = plist->next;
571  }
572  }
573 
574  if (only_network)
575  {
576  for (i = ACT_GATHER_INFO; i <= ACT_LAST; i++)
577  {
578  ret->list[i] = NULL;
579  }
580  }
581  return ret;
582 }
struct list * list[ACT_LAST+1]
struct hash * hash
struct plist * next
struct plist * prev

◆ plugins_scheduler_next()

struct scheduler_plugin* plugins_scheduler_next ( plugins_scheduler_t  h)

Definition at line 694 of file pluginscheduler.c.

695 {
696  struct scheduler_plugin *ret;
697 
698  if (h == NULL)
699  return NULL;
700  ret = get_next_in_range (h, ACT_INIT, ACT_INIT);
701  if (ret)
702  return ret;
703  ret = get_next_in_range (h, ACT_SCANNER, ACT_SCANNER);
704  if (ret)
705  return ret;
706  ret = get_next_in_range (h, ACT_SETTINGS, ACT_GATHER_INFO);
707  if (ret)
708  return ret;
709  ret = get_next_in_range (h, ACT_ATTACK, ACT_FLOOD);
710  if (ret)
711  return ret;
712  ret = get_next_in_range (h, ACT_END, ACT_END);
713  if (ret)
714  return ret;
715  return NULL;
716 }

◆ scheduler_mark_running_ports()

void scheduler_mark_running_ports ( plugins_scheduler_t  sched,
struct scheduler_plugin plugin 
)

Definition at line 242 of file pluginscheduler.c.

References plist::name, plist::next, plist::occurences, scheduler_plugin::oid, pl_get(), plugins_scheduler::plist, and plist::prev.

244 {
245  char *ports, **array;
246  int i;
247 
248  ports = nvticache_get_required_ports (plugin->oid);
249  if (!ports)
250  return;
251 
252  array = g_strsplit (ports, ", ", 0);
253  g_free (ports);
254  if (!array)
255  return;
256  for (i = 0; array[i] != NULL; i++)
257  {
258  struct plist *pl = pl_get (sched->plist, array[i]);
259 
260  if (pl != NULL)
261  pl->occurences++;
262  else
263  {
264  pl = g_malloc0 (sizeof (struct plist));
265  pl->name = g_strdup (array[i]);
266  pl->occurences = 1;
267  pl->next = sched->plist;
268  if (sched->plist != NULL)
269  sched->plist->prev = pl;
270  pl->prev = NULL;
271  sched->plist = pl;
272  }
273  }
274  g_strfreev (array);
275 }
gchar * name
struct plist * next
int occurences
struct plist * plist
struct plist * pl_get(struct plist *list, char *name)
struct plist * prev
Here is the call graph for this function:

◆ scheduler_rm_running_ports()

void scheduler_rm_running_ports ( plugins_scheduler_t  sched,
struct scheduler_plugin plugin 
)

Definition at line 278 of file pluginscheduler.c.

References log_write(), plist::name, plist::next, plist::occurences, scheduler_plugin::oid, pl_get(), plugins_scheduler::plist, and plist::prev.

Referenced by plugin_next_unrun_dependency().

280 {
281  char *ports, **array;
282  int i;
283 
284  ports = nvticache_get_required_ports (plugin->oid);
285  if (!ports)
286  return;
287 
288  array = g_strsplit (ports, ", ", 0);
289  g_free (ports);
290  if (!array)
291  return;
292  for (i = 0; array[i] != NULL; i++)
293  {
294  struct plist *pl = pl_get (sched->plist, array[i]);
295 
296  if (pl != NULL)
297  {
298  pl->occurences--;
299  if (pl->occurences == 0)
300  {
301  if (pl->next != NULL)
302  pl->next->prev = pl->prev;
303 
304  if (pl->prev != NULL)
305  pl->prev->next = pl->next;
306  else
307  sched->plist = pl->next;
308 
309  g_free (pl->name);
310  g_free (pl);
311  }
312  }
313  else
314  log_write ("Warning: scheduler_rm_running_ports failed ?! (%s)\n",
315  array[i]);
316  }
317  g_strfreev (array);
318 }
void log_write(const char *str,...)
Write into the logfile / syslog.
Definition: log.c:140
gchar * name
struct plist * next
int occurences
struct plist * plist
struct plist * pl_get(struct plist *list, char *name)
struct plist * prev
Here is the call graph for this function:
Here is the caller graph for this function: