OpenVAS Scanner  5.1.3
plugs_req.h File Reference
#include <openvas/base/kb.h>
#include <openvas/misc/arglists.h>
Include dependency graph for plugs_req.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

char * requirements_plugin (kb_t, struct scheduler_plugin *)
 Determine if the plugin requirements are met. More...
 
int mandatory_requirements_met (kb_t, struct scheduler_plugin *)
 Check whether mandatory requirements for plugin are met. More...
 
struct arglist * requirements_common_ports (struct scheduler_plugin *, struct scheduler_plugin *)
 Returns <port> if the lists of the required ports between. More...
 

Function Documentation

◆ mandatory_requirements_met()

int mandatory_requirements_met ( kb_t  kb,
struct scheduler_plugin plugin 
)

Check whether mandatory requirements for plugin are met.

Parameters
kbThe arglist knowledge base with all keys.
pluginThe arglist plugin.
Returns
1 if all mandatory requirements for the plugin are met. 0 if it is not the case.

Definition at line 299 of file plugs_req.c.

301 {
302  char *mandatory_keys;
303  int ret;
304 
305  mandatory_keys = nvticache_get_mandatory_keys (plugin->oid);
306  ret = check_mandatory_keys (kb, mandatory_keys);
307 
308  g_free (mandatory_keys);
309  if (ret)
310  return 0;
311  return 1;
312 }

References scheduler_plugin::oid.

◆ requirements_common_ports()

struct arglist* requirements_common_ports ( struct scheduler_plugin plugin1,
struct scheduler_plugin plugin2 
)

Returns <port> if the lists of the required ports between.

plugin 1 and plugin 2 have at least one port in common.

Definition at line 95 of file plugs_req.c.

97 {
98  struct arglist *ret = NULL;
99  int i, j;
100  char *ports1, *ports2, **array1, **array2;
101 
102  if (!plugin1 || !plugin2)
103  return 0;
104 
105  ports1 = nvticache_get_required_ports (plugin1->oid);
106  ports2 = nvticache_get_required_ports (plugin2->oid);
107  if (!ports1 || !ports2)
108  {
109  g_free (ports1);
110  g_free (ports2);
111  return 0;
112  }
113  array1 = g_strsplit (ports1, ", ", 0);
114  array2 = g_strsplit (ports2, ", ", 0);
115  g_free (ports1);
116  g_free (ports2);
117  if (!array1 || !array2)
118  {
119  g_strfreev (array1);
120  g_strfreev (array2);
121  return 0;
122  }
123 
124  for (i = 0; array1[i] != NULL; i ++)
125  {
126  for (j = 0; array2[j] != NULL; j ++)
127  {
128  if (!strcmp (array2[j], array1[i]))
129  {
130  if (!ret)
131  ret = g_malloc0 (sizeof (struct arglist));
132  arg_add_value (ret, array2[j], ARG_INT, (void *) 1);
133  }
134  }
135  }
136  g_strfreev (array1);
137  g_strfreev (array2);
138  return ret;
139 }

References scheduler_plugin::oid.

◆ requirements_plugin()

char* requirements_plugin ( kb_t  kb,
struct scheduler_plugin plugin 
)

Determine if the plugin requirements are met.

Returns
Returns NULL is everything is ok, else an error message.

Definition at line 320 of file plugs_req.c.

321 {
322  static char error[64];
323  char *errkey = NULL, *keys, *tcp, *udp;
324  const char *opti = prefs_get ("optimization_level");
325 
326  /*
327  * Check wether the good ports are open
328  */
329  error[sizeof (error) - 1] = '\0';
330  tcp = nvticache_get_required_ports (plugin->oid);
331  if (tcp && *tcp && (get_closed_ports (kb, tcp, "tcp")) == 0)
332  {
333  strncpy (error, "none of the required tcp ports are open",
334  sizeof (error) - 1);
335  g_free (tcp);
336  return error;
337  }
338  g_free (tcp);
339 
340  udp = nvticache_get_required_udp_ports (plugin->oid);
341  if (udp && *udp && (get_closed_ports (kb, udp, "udp")) == 0)
342  {
343  strncpy (error, "none of the required udp ports are open",
344  sizeof (error) - 1);
345  g_free (udp);
346  return error;
347  }
348  g_free (udp);
349 
350  if (opti != NULL && (strcmp (opti, "open_ports") == 0 || atoi (opti) == 1))
351  return NULL;
352 
353  /*
354  * Check wether a key we wanted is missing
355  */
356  keys = nvticache_get_required_keys (plugin->oid);
357  if (kb_missing_keyname_of_namelist (kb, keys, &errkey))
358  {
359  snprintf (error, sizeof (error), "because the key %s is missing", errkey);
360  g_free (errkey);
361  g_free (keys);
362  return error;
363  }
364  g_free (keys);
365 
366  if (opti != NULL && (strcmp (opti, "required_keys") == 0 || atoi (opti) == 2))
367  return NULL;
368 
369  /*
370  * Check wether a key we do not want is present
371  */
372  keys = nvticache_get_excluded_keys (plugin->oid);
373  if (kb_present_keyname_of_namelist (kb, keys, &errkey))
374  {
375  snprintf (error, sizeof (error), "because the key %s is present", errkey);
376  g_free (errkey);
377  g_free (keys);
378  return error;
379  }
380  g_free (keys);
381  return NULL;
382 }

References scheduler_plugin::oid.