Performs various checks for requirements set in a given plugin.
More...
#include "plugs_req.h"
#include "pluginscheduler.h"
#include <gvm/base/prefs.h>
#include <gvm/util/nvticache.h>
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
|
int | kb_get_port_state_proto (kb_t, int, char *) |
|
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. More...
|
|
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 . More...
|
|
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 . More...
|
|
static int | check_mandatory_keys (kb_t kb, char *keys) |
| Checks mandatory keys presence and value in the KB. More...
|
|
int | mandatory_requirements_met (kb_t kb, nvti_t *nvti) |
| Check whether mandatory requirements for plugin are met. More...
|
|
char * | requirements_plugin (kb_t kb, nvti_t *nvti) |
| Determine if the plugin requirements are met. More...
|
|
Performs various checks for requirements set in a given plugin.
Definition in file plugs_req.c.
◆ check_mandatory_keys()
static int check_mandatory_keys |
( |
kb_t |
kb, |
|
|
char * |
keys |
|
) |
| |
|
static |
Checks mandatory keys presence and value in the KB.
- Parameters
-
[in] | kb | KB handle where to search for the keys. |
[in] | keys | Comma separated list of mandatory keys. |
- Returns
- 1 if a key is missing or not matching its value, 0 otherwise.
Definition at line 173 of file plugs_req.c.
Referenced by mandatory_requirements_met().
178 if (!kb || !keys || !*keys)
180 keynames = g_strsplit (keys,
", ", 0);
183 for (i = 0; keynames[i] != NULL; i++)
186 char *re_str = NULL, *pos;
189 if ((pos = strstr (keynames[i],
"=")))
195 kbi = kb_item_get_single (kb, keynames[i], KB_TYPE_UNSPEC);
198 g_strfreev (keynames);
207 if (kbi->type != KB_TYPE_STR || !kbi->v_str)
209 g_strfreev (keynames);
213 if (regcomp (&re, re_str, REG_EXTENDED | REG_NOSUB | REG_ICASE))
215 g_warning (
"Couldn't compile regex %s", re_str);
216 g_strfreev (keynames);
220 if (regexec (&re, kbi->v_str, 0, NULL, 0) == REG_NOMATCH)
222 g_strfreev (keynames);
232 g_strfreev (keynames);
◆ get_closed_ports()
static int get_closed_ports |
( |
kb_t |
kb, |
|
|
char * |
ports_list, |
|
|
char * |
proto |
|
) |
| |
|
static |
Returns whether a port in a port list is closed or not.
- Returns
- Whether a port in a port list is closed or not.
Definition at line 52 of file plugs_req.c.
References kb_get_port_state_proto().
Referenced by requirements_plugin().
59 ports = g_strsplit (ports_list,
", ", 0);
60 for (i = 0; ports[i] != NULL; i++)
62 int iport = atoi (ports[i]);
70 if (kb_item_get_int (kb, ports[i]) > 0)
int kb_get_port_state_proto(kb_t, int, char *)
◆ kb_get_port_state_proto()
int kb_get_port_state_proto |
( |
kb_t |
kb, |
|
|
int |
portnum, |
|
|
char * |
proto |
|
) |
| |
- Parameters
-
proto | Protocol (udp/tcp). If NULL, "tcp" will be used. |
Definition at line 110 of file plugutils.c.
References unscanned_ports_as_closed().
Referenced by get_closed_ports(), and host_get_port_state_proto().
112 char port_s[255], *kbstr;
113 const char *prange = prefs_get (
"port_range");
114 port_protocol_t port_type;
115 array_t *port_ranges;
119 if (!strcmp (proto,
"udp"))
121 port_type = PORT_PROTOCOL_UDP;
122 kbstr =
"Host/udp_scanned";
126 port_type = PORT_PROTOCOL_TCP;
127 kbstr =
"Host/scanned";
131 if (kb_item_get_int (kb, kbstr) <= 0)
134 port_ranges = port_range_ranges (prange);
135 if (!port_in_port_ranges (portnum, port_type, port_ranges))
137 array_free (port_ranges);
140 array_free (port_ranges);
143 snprintf (port_s,
sizeof (port_s),
"Ports/%s/%d", proto, portnum);
144 return kb_item_get_int (kb, port_s) > 0;
static int unscanned_ports_as_closed(port_protocol_t ptype)
Report state of preferences "unscanned_closed".
◆ kb_missing_keyname_of_namelist()
static int kb_missing_keyname_of_namelist |
( |
kb_t |
kb, |
|
|
char * |
keys, |
|
|
char ** |
keyname |
|
) |
| |
|
static |
Returns the name of the first key which is not present in the kb
.
- Parameters
-
[in] | kb | KB handle where to search for the keys. |
[in] | keys | Comma separated list of keys. |
[out] | keyname | Key that was missing. Free with g_free(). |
- Returns
- 1 if a key is missing in KB, 0 otherwise.
Definition at line 96 of file plugs_req.c.
Referenced by requirements_plugin().
100 if (!kb || !keys || !*keys)
103 keynames = g_strsplit (keys,
", ", 0);
106 for (i = 0; keynames[i] != NULL; i++)
108 struct kb_item *kbi =
109 kb_item_get_single (kb, keynames[i], KB_TYPE_UNSPEC);
114 *keyname = g_strdup (keynames[i]);
115 g_strfreev (keynames);
122 g_strfreev (keynames);
◆ kb_present_keyname_of_namelist()
static int kb_present_keyname_of_namelist |
( |
kb_t |
kb, |
|
|
char * |
keys, |
|
|
char ** |
keyname |
|
) |
| |
|
static |
Returns the name of the first key which is present in the kb
.
- Parameters
-
[in] | kb | KB handle where to search for the keys. |
[in] | keys | Comma separated list of keys. |
[out] | keyname | Key that was found. Free with g_free(). |
- Returns
- 1 if a key is present in KB, 0 otherwise.
Definition at line 135 of file plugs_req.c.
Referenced by requirements_plugin().
140 if (!kb || !keys || !*keys)
143 keynames = g_strsplit (keys,
", ", 0);
146 for (i = 0; keynames[i] != NULL; i++)
148 struct kb_item *kbi =
149 kb_item_get_single (kb, keynames[i], KB_TYPE_UNSPEC);
154 *keyname = g_strdup (keynames[i]);
156 g_strfreev (keynames);
161 g_strfreev (keynames);
◆ mandatory_requirements_met()
int mandatory_requirements_met |
( |
kb_t |
kb, |
|
|
nvti_t * |
nvti |
|
) |
| |
Check whether mandatory requirements for plugin are met.
- Parameters
-
kb | The knowledge base with all keys. |
plugin | The 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().
static int check_mandatory_keys(kb_t kb, char *keys)
Checks mandatory keys presence and value in the KB.
◆ 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().
266 static char error[64];
267 char *errkey = NULL, *keys, *tcp, *udp;
268 const char *opti = prefs_get (
"optimization_level");
273 error[
sizeof (error) - 1] =
'\0';
274 tcp = nvti_required_ports (nvti);
277 strncpy (error,
"none of the required tcp ports are open",
282 udp = nvti_required_udp_ports (nvti);
285 strncpy (error,
"none of the required udp ports are open",
290 if (opti != NULL && (strcmp (opti,
"open_ports") == 0 || atoi (opti) == 1))
296 keys = nvti_required_keys (nvti);
299 snprintf (error,
sizeof (error),
"because the key %s is missing", errkey);
304 if (opti != NULL && (strcmp (opti,
"required_keys") == 0 || atoi (opti) == 2))
310 keys = nvti_excluded_keys (nvti);
313 snprintf (error,
sizeof (error),
"because the key %s is present", errkey);
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 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.