33 #include <openvas/misc/prefs.h> 34 #include <openvas/base/nvticache.h> 53 get_closed_ports (kb_t kb,
char *ports_list,
char *proto)
60 ports = g_strsplit (ports_list,
", ", 0);
61 for (i = 0; ports[i] != NULL; i ++)
63 int iport = atoi (ports[i]);
71 if (kb_item_get_int (kb, ports[i]) > 0)
98 struct arglist *ret = NULL;
100 char *ports1, *ports2, **array1, **array2;
102 if (!plugin1 || !plugin2)
105 ports1 = nvticache_get_required_ports (plugin1->
oid);
106 ports2 = nvticache_get_required_ports (plugin2->
oid);
107 if (!ports1 || !ports2)
113 array1 = g_strsplit (ports1,
", ", 0);
114 array2 = g_strsplit (ports2,
", ", 0);
117 if (!array1 || !array2)
124 for (i = 0; array1[i] != NULL; i ++)
126 for (j = 0; array2[j] != NULL; j ++)
128 if (!strcmp (array2[j], array1[i]))
131 ret = g_malloc0 (
sizeof (
struct arglist));
132 arg_add_value (ret, array2[j], ARG_INT, (
void *) 1);
150 kb_missing_keyname_of_namelist (kb_t kb,
char *keys,
char **keyname)
154 if (!kb || !keys || !*keys)
157 keynames = g_strsplit (keys,
", ", 0);
160 for (i = 0; keynames[i] != NULL; i ++)
162 struct kb_item *kbi = kb_item_get_single (kb, keynames[i], KB_TYPE_UNSPEC);
167 *keyname = g_strdup (keynames[i]);
168 g_strfreev (keynames);
175 g_strfreev (keynames);
188 kb_present_keyname_of_namelist (kb_t kb,
char *keys,
char **keyname)
193 if (!kb || !keys || !*keys)
196 keynames = g_strsplit (keys,
", ", 0);
199 for (i = 0; keynames[i] != NULL; i ++)
201 struct kb_item *kbi = kb_item_get_single (kb, keynames[i], KB_TYPE_UNSPEC);
206 *keyname = g_strdup (keynames[i]);
208 g_strfreev (keynames);
213 g_strfreev (keynames);
225 check_mandatory_keys (kb_t kb,
char *keys)
230 if (!kb || !keys || !*keys)
232 keynames = g_strsplit (keys,
", ", 0);
235 for (i = 0; keynames[i] != NULL; i ++)
238 char *re_str = NULL, *pos;
241 if ((pos = strstr (keynames[i],
"=")))
247 kbi = kb_item_get_single (kb, keynames[i], KB_TYPE_UNSPEC);
250 g_strfreev (keynames);
259 if (kbi->type != KB_TYPE_STR || !kbi->v_str)
261 g_strfreev (keynames);
265 if (regcomp (&re, re_str, REG_EXTENDED | REG_NOSUB | REG_ICASE))
267 g_warning (
"Couldn't compile regex %s", re_str);
268 g_strfreev (keynames);
272 if (regexec (&re, kbi->v_str, 0, NULL, 0) == REG_NOMATCH)
274 g_strfreev (keynames);
284 g_strfreev (keynames);
302 char *mandatory_keys;
305 mandatory_keys = nvticache_get_mandatory_keys (plugin->
oid);
306 ret = check_mandatory_keys (kb, mandatory_keys);
308 g_free (mandatory_keys);
322 static char error[64];
323 char *errkey = NULL, *keys, *tcp, *udp;
324 const char *opti = prefs_get (
"optimization_level");
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)
333 strncpy (error,
"none of the required tcp ports are open",
340 udp = nvticache_get_required_udp_ports (plugin->
oid);
341 if (udp && *udp && (get_closed_ports (kb, udp,
"udp")) == 0)
343 strncpy (error,
"none of the required udp ports are open",
350 if (opti != NULL && (strcmp (opti,
"open_ports") == 0 || atoi (opti) == 1))
356 keys = nvticache_get_required_keys (plugin->
oid);
357 if (kb_missing_keyname_of_namelist (kb, keys, &errkey))
359 snprintf (error,
sizeof (error),
"because the key %s is missing", errkey);
366 if (opti != NULL && (strcmp (opti,
"required_keys") == 0 || atoi (opti) == 2))
372 keys = nvticache_get_excluded_keys (plugin->
oid);
373 if (kb_present_keyname_of_namelist (kb, keys, &errkey))
375 snprintf (error,
sizeof (error),
"because the key %s is present", errkey);
struct arglist * requirements_common_ports(struct scheduler_plugin *plugin1, struct scheduler_plugin *plugin2)
Returns <port> if the lists of the required ports between.
int mandatory_requirements_met(kb_t kb, struct scheduler_plugin *plugin)
Check whether mandatory requirements for plugin are met.
int kb_get_port_state_proto(kb_t, int, char *)
char * requirements_plugin(kb_t kb, struct scheduler_plugin *plugin)
Determine if the plugin requirements are met.