OpenVAS Scanner  7.0.1~git
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 247 of file plugs_req.c.

References check_mandatory_keys().

Referenced by launch_plugin().

248 {
249  int ret;
250 
251  ret = check_mandatory_keys (kb, nvti_mandatory_keys (nvti));
252 
253  if (ret)
254  return 0;
255  return 1;
256 }
static int check_mandatory_keys(kb_t kb, char *keys)
Checks mandatory keys presence and value in the KB.
Definition: plugs_req.c:173
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 264 of file plugs_req.c.

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

Referenced by launch_plugin().

265 {
266  static char error[64];
267  char *errkey = NULL, *keys, *tcp, *udp;
268  const char *opti = prefs_get ("optimization_level");
269 
270  /*
271  * Check whether the good ports are open
272  */
273  error[sizeof (error) - 1] = '\0';
274  tcp = nvti_required_ports (nvti);
275  if (tcp && *tcp && (get_closed_ports (kb, tcp, "tcp")) == 0)
276  {
277  strncpy (error, "none of the required tcp ports are open",
278  sizeof (error) - 1);
279  return error;
280  }
281 
282  udp = nvti_required_udp_ports (nvti);
283  if (udp && *udp && (get_closed_ports (kb, udp, "udp")) == 0)
284  {
285  strncpy (error, "none of the required udp ports are open",
286  sizeof (error) - 1);
287  return error;
288  }
289 
290  if (opti != NULL && (strcmp (opti, "open_ports") == 0 || atoi (opti) == 1))
291  return NULL;
292 
293  /*
294  * Check whether a key we wanted is missing
295  */
296  keys = nvti_required_keys (nvti);
297  if (kb_missing_keyname_of_namelist (kb, keys, &errkey))
298  {
299  snprintf (error, sizeof (error), "because the key %s is missing", errkey);
300  g_free (errkey);
301  return error;
302  }
303 
304  if (opti != NULL && (strcmp (opti, "required_keys") == 0 || atoi (opti) == 2))
305  return NULL;
306 
307  /*
308  * Check whether a key we do not want is present
309  */
310  keys = nvti_excluded_keys (nvti);
311  if (kb_present_keyname_of_namelist (kb, keys, &errkey))
312  {
313  snprintf (error, sizeof (error), "because the key %s is present", errkey);
314  g_free (errkey);
315  return error;
316  }
317  return NULL;
318 }
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:96
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:135
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:52
Here is the call graph for this function:
Here is the caller graph for this function: