17#include <gvm/base/prefs.h>
18#include <gvm/util/nvticache.h>
46 ports = g_strsplit (ports_list,
", ", 0);
47 for (i = 0; ports[i] != NULL; i++)
49 int iport = atoi (ports[i]);
57 if (kb_item_get_int (kb, ports[i]) > 0)
87 if (!kb || !keys || !*keys)
90 keynames = g_strsplit (keys,
", ", 0);
93 for (i = 0; keynames[i] != NULL; i++)
96 kb_item_get_single (kb, keynames[i], KB_TYPE_UNSPEC);
101 *keyname = g_strdup (keynames[i]);
102 g_strfreev (keynames);
109 g_strfreev (keynames);
127 if (!kb || !keys || !*keys)
130 keynames = g_strsplit (keys,
", ", 0);
133 for (i = 0; keynames[i] != NULL; i++)
135 struct kb_item *kbi =
136 kb_item_get_single (kb, keynames[i], KB_TYPE_UNSPEC);
141 *keyname = g_strdup (keynames[i]);
143 g_strfreev (keynames);
148 g_strfreev (keynames);
165 if (!kb || !keys || !*keys)
167 keynames = g_strsplit (keys,
", ", 0);
170 for (i = 0; keynames[i] != NULL; i++)
173 char *re_str = NULL, *pos;
176 if ((pos = strstr (keynames[i],
"=")))
182 kbi = kb_item_get_single (kb, keynames[i], KB_TYPE_UNSPEC);
185 g_strfreev (keynames);
194 if (kbi->type != KB_TYPE_STR || !kbi->v_str)
196 g_strfreev (keynames);
200 if (regcomp (&re, re_str, REG_EXTENDED | REG_NOSUB | REG_ICASE))
202 g_warning (
"Couldn't compile regex %s", re_str);
203 g_strfreev (keynames);
207 if (regexec (&re, kbi->v_str, 0, NULL, 0) == REG_NOMATCH)
209 g_strfreev (keynames);
219 g_strfreev (keynames);
253 static char error[64];
254 char *errkey = NULL, *keys, *tcp, *udp;
255 const char *opti = prefs_get (
"optimization_level");
260 error[
sizeof (error) - 1] =
'\0';
261 tcp = nvti_required_ports (nvti);
264 strncpy (error,
"none of the required tcp ports are open",
269 udp = nvti_required_udp_ports (nvti);
272 strncpy (error,
"none of the required udp ports are open",
277 if (opti != NULL && (strcmp (opti,
"open_ports") == 0 || atoi (opti) == 1))
283 keys = nvti_required_keys (nvti);
286 snprintf (error,
sizeof (error),
"because the key %s is missing", errkey);
291 if (opti != NULL && (strcmp (opti,
"required_keys") == 0 || atoi (opti) == 2))
297 keys = nvti_excluded_keys (nvti);
300 snprintf (error,
sizeof (error),
"because the key %s is present", errkey);
header for pluginscheduler.c
int kb_get_port_state_proto(kb_t, int, char *)
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.
static int check_mandatory_keys(kb_t kb, char *keys)
Checks mandatory keys presence and value in the KB.
char * requirements_plugin(kb_t kb, nvti_t *nvti)
Determine if the plugin requirements are met.
int mandatory_requirements_met(kb_t kb, nvti_t *nvti)
Check whether mandatory requirements for plugin are met.
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.
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.