OpenVAS Scanner  22.7.9
plugs_req.h File Reference

plugs_req.c header. More...

#include <gvm/util/kb.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, nvti_t *)
 Determine if the plugin requirements are met. More...
 
int mandatory_requirements_met (kb_t, nvti_t *)
 Check whether mandatory requirements for plugin are met. More...
 

Detailed Description

plugs_req.c header.

Definition in file plugs_req.h.

Function Documentation

◆ mandatory_requirements_met()

int mandatory_requirements_met ( kb_t  kb,
nvti_t *  nvti 
)

Check whether mandatory requirements for plugin are met.

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

Definition at line 234 of file plugs_req.c.

235 {
236  int ret;
237 
238  ret = check_mandatory_keys (kb, nvti_mandatory_keys (nvti));
239 
240  if (ret)
241  return 0;
242  return 1;
243 }

References check_mandatory_keys().

Referenced by launch_plugin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ requirements_plugin()

char* requirements_plugin ( kb_t  kb,
nvti_t *  nvti 
)

Determine if the plugin requirements are met.

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

Definition at line 251 of file plugs_req.c.

252 {
253  static char error[64];
254  char *errkey = NULL, *keys, *tcp, *udp;
255  const char *opti = prefs_get ("optimization_level");
256 
257  /*
258  * Check whether the good ports are open
259  */
260  error[sizeof (error) - 1] = '\0';
261  tcp = nvti_required_ports (nvti);
262  if (tcp && *tcp && (get_closed_ports (kb, tcp, "tcp")) == 0)
263  {
264  strncpy (error, "none of the required tcp ports are open",
265  sizeof (error) - 1);
266  return error;
267  }
268 
269  udp = nvti_required_udp_ports (nvti);
270  if (udp && *udp && (get_closed_ports (kb, udp, "udp")) == 0)
271  {
272  strncpy (error, "none of the required udp ports are open",
273  sizeof (error) - 1);
274  return error;
275  }
276 
277  if (opti != NULL && (strcmp (opti, "open_ports") == 0 || atoi (opti) == 1))
278  return NULL;
279 
280  /*
281  * Check whether a key we wanted is missing
282  */
283  keys = nvti_required_keys (nvti);
284  if (kb_missing_keyname_of_namelist (kb, keys, &errkey))
285  {
286  snprintf (error, sizeof (error), "because the key %s is missing", errkey);
287  g_free (errkey);
288  return error;
289  }
290 
291  if (opti != NULL && (strcmp (opti, "required_keys") == 0 || atoi (opti) == 2))
292  return NULL;
293 
294  /*
295  * Check whether a key we do not want is present
296  */
297  keys = nvti_excluded_keys (nvti);
298  if (kb_present_keyname_of_namelist (kb, keys, &errkey))
299  {
300  snprintf (error, sizeof (error), "because the key %s is present", errkey);
301  g_free (errkey);
302  return error;
303  }
304  return NULL;
305 }

References get_closed_ports(), kb_missing_keyname_of_namelist(), and kb_present_keyname_of_namelist().

Referenced by launch_plugin().

Here is the call graph for this function:
Here is the caller graph for this function:
get_closed_ports
static int get_closed_ports(kb_t kb, char *ports_list, char *proto)
Returns whether a port in a port list is closed or not.
Definition: plugs_req.c:39
check_mandatory_keys
static int check_mandatory_keys(kb_t kb, char *keys)
Checks mandatory keys presence and value in the KB.
Definition: plugs_req.c:160
kb_missing_keyname_of_namelist
static int kb_missing_keyname_of_namelist(kb_t kb, char *keys, char **keyname)
Returns the name of the first key which is not present in the kb.
Definition: plugs_req.c:83
kb_present_keyname_of_namelist
static int kb_present_keyname_of_namelist(kb_t kb, char *keys, char **keyname)
Returns the name of the first key which is present in the kb.
Definition: plugs_req.c:122