Greenbone Vulnerability Management Libraries
11.0.0
|
Go to the documentation of this file.
58 #define G_LOG_DOMAIN "lib nvti"
89 vtref_new (
const gchar *type,
const gchar *ref_id,
const gchar *ref_text)
94 ref->
type = g_strdup (type);
96 ref->
ref_id = g_strdup (ref_id);
131 return (r ? r->
type : NULL);
145 return (r ? r->
ref_id : NULL);
179 if ((strcmp ((
char *) str_time,
"") == 0)
180 || (strcmp ((
char *) str_time,
"$Date: $") == 0)
181 || (strcmp ((
char *) str_time,
"$Date$") == 0)
182 || (strcmp ((
char *) str_time,
"$Date:$") == 0)
183 || (strcmp ((
char *) str_time,
"$Date") == 0)
184 || (strcmp ((
char *) str_time,
"$$") == 0))
194 memset (&tm, 0,
sizeof (
struct tm));
195 if (strptime ((
char *) str_time,
"%F %T %z", &tm) == NULL)
197 memset (&tm, 0,
sizeof (
struct tm));
198 if (strptime ((
char *) str_time,
"$Date: %F %T %z", &tm) == NULL)
200 memset (&tm, 0,
sizeof (
struct tm));
201 if (strptime ((
char *) str_time,
"%a %b %d %T %Y %z", &tm) == NULL)
203 memset (&tm, 0,
sizeof (
struct tm));
204 if (strptime ((
char *) str_time,
"$Date: %a, %d %b %Y %T %z", &tm)
207 memset (&tm, 0,
sizeof (
struct tm));
208 if (strptime ((
char *) str_time,
"$Date: %a %b %d %T %Y %z",
212 g_warning (
"%s: Failed to parse time: %s", __FUNCTION__,
220 epoch_time = mktime (&tm);
221 if (epoch_time == -1)
223 g_warning (
"%s: Failed to make time: %s", __FUNCTION__, str_time);
229 if ((sscanf ((
char *) str_time,
"%*u-%*u-%*u %*u:%*u:%*u %d%*[^]]", &offset)
231 && (sscanf ((
char *) str_time,
"$Date: %*u-%*u-%*u %*u:%*u:%*u %d%*[^]]",
234 && (sscanf ((
char *) str_time,
"%*s %*s %*s %*u:%*u:%*u %*u %d%*[^]]",
237 && (sscanf ((
char *) str_time,
238 "$Date: %*s %*s %*s %*u %*u:%*u:%*u %d%*[^]]", &offset)
240 && (sscanf ((
char *) str_time,
241 "$Date: %*s %*s %*s %*u:%*u:%*u %*u %d%*[^]]", &offset)
244 g_warning (
"%s: Failed to parse timezone offset: %s", __FUNCTION__,
253 epoch_time += ((-offset) / 100) * 60 * 60;
254 epoch_time += ((-offset) % 100) * 60;
258 epoch_time -= (offset / 100) * 60 * 60;
259 epoch_time -= (offset % 100) * 60;
324 vt->
refs = g_slist_append (vt->
refs, ref);
363 np->
name = g_strdup (name);
365 np->
type = g_strdup (type);
367 np->
dflt = g_strdup (dflt);
400 return np ? np->
id : -1;
414 return (np ? np->
name : NULL);
428 return (np ? np->
type : NULL);
442 return (np ? np->
dflt : NULL);
505 return (n ? n->
oid : NULL);
519 return (n ? n->
name : NULL);
533 return (n ? n->
summary : NULL);
547 return (n ? n->
insight : NULL);
575 return (n ? n->
impact : NULL);
616 return (n ? g_slist_length (n->
refs) : 0);
631 return (n ? g_slist_nth_data (n->
refs, p) : NULL);
661 gchar *refs, *refs2, **exclude_item;
664 gchar **exclude_split;
673 if (exclude_types && exclude_types[0])
674 exclude_split = g_strsplit (exclude_types,
",", 0);
676 exclude_split = NULL;
678 for (i = 0; i < g_slist_length (n->
refs); i++)
680 ref = g_slist_nth_data (n->
refs, i);
681 if (type && strcasecmp (ref->
type, type) != 0)
687 for (exclude_item = exclude_split; *exclude_item; exclude_item++)
689 if (strcasecmp (g_strstrip (*exclude_item), ref->
type) == 0)
703 g_strdup_printf (
"%s, %s:%s", refs, ref->
type, ref->
ref_id);
705 refs2 = g_strdup_printf (
"%s:%s", ref->
type, ref->
ref_id);
710 refs2 = g_strdup_printf (
"%s, %s", refs, ref->
ref_id);
712 refs2 = g_strdup_printf (
"%s", ref->
ref_id);
719 g_strfreev (exclude_split);
763 return (n ? n->
tag : NULL);
903 return (n ? n->
family : NULL);
916 return (n ? g_slist_length (n->
prefs) : 0);
931 return (n ? g_slist_nth_data (n->
prefs, p) : NULL);
978 n->
oid = g_strdup (oid);
999 n->
name = g_strdup (name);
1020 n->
summary = g_strdup (summary);
1041 n->
insight = g_strdup (insight);
1083 n->
impact = g_strdup (impact);
1187 gchar *newvalue = NULL;
1192 if (!name || !name[0])
1195 if (!value || !value[0])
1198 if (!strcmp (name,
"last_modification"))
1203 else if (!strcmp (name,
"creation_date"))
1208 else if (!strcmp (name,
"cvss_base"))
1225 g_strconcat (n->
tag,
"|", name,
"=", newvalue ? newvalue : value, NULL);
1230 n->
tag = g_strconcat (name,
"=", newvalue ? newvalue : value, NULL);
1256 n->
tag = g_strdup (tag);
1279 if (cvss_base && cvss_base[0])
1304 if (dependencies && dependencies[0])
1329 if (required_keys && required_keys[0])
1354 if (mandatory_keys && mandatory_keys[0])
1379 if (excluded_keys && excluded_keys[0])
1404 if (required_ports && required_ports[0])
1429 if (required_udp_ports && required_udp_ports[0])
1475 if (qod_type && qod_type[0])
1499 n->
family = g_strdup (family);
1558 const gchar *ref_text)
1560 gchar **split, **item;
1568 split = g_strsplit (ref_ids,
",", 0);
1570 for (item = split; *item; item++)
1577 if (strcmp (
id,
"") == 0)
1588 split2 = g_strsplit (
id,
":", 2);
1589 if (split2[0] && split2[1])
1591 g_strfreev (split2);
1799 return g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
1812 g_hash_table_destroy (nvtis);
1839 return g_hash_table_lookup (nvtis, oid);
gchar * nvti_solution_type(const nvti_t *n)
Get the solution type.
const gchar * vtref_text(const vtref_t *r)
Get the text of a reference.
const nvtpref_t * nvti_pref(const nvti_t *n, guint p)
Get the n'th preferences of the NVT.
int nvti_add_vtref(nvti_t *vt, vtref_t *ref)
Add a reference to the VT Info.
gchar * mandatory_keys
List of mandatory KB keys of this NVT.
gchar * insight
The insight.
int nvti_set_required_udp_ports(nvti_t *n, const gchar *required_udp_ports)
Set the required udp ports of a NVT.
gchar * ref_text
Optional additional text.
gchar * required_keys
List of required KB keys of this NVT.
void nvtis_free(nvtis_t *nvtis)
Free a collection of NVT Infos.
gchar * nvti_cvss_base(const nvti_t *n)
Get the CVSS base.
struct nvti nvti_t
The structure of a information record that corresponds to a NVT.
GHashTable nvtis_t
A collection of information records corresponding to NVTs.
gchar * solution_type
The solution type.
int nvti_set_creation_time(nvti_t *n, const time_t creation_time)
Set the creation time of a NVT.
int nvti_set_impact(nvti_t *n, const gchar *impact)
Set the impact text of a NVT.
guint nvti_vtref_len(const nvti_t *n)
Get the number of references of the NVT.
int nvti_set_required_keys(nvti_t *n, const gchar *required_keys)
Set the required keys of a NVT.
gchar * nvti_family(const nvti_t *n)
Get the family name.
struct nvtpref nvtpref_t
The structure for a preference of a NVT.
The structure for a cross reference of a VT.
gchar * nvti_insight(const nvti_t *n)
Get the text about insight.
int nvti_add_required_ports(nvti_t *n, const gchar *port)
Add a required port of a NVT.
gchar * detection
Detection description.
gchar * nvti_detection(const nvti_t *n)
Get the text about detection.
gchar * nvti_oid(const nvti_t *n)
Get the OID string.
int nvti_set_insight(nvti_t *n, const gchar *insight)
Set the insight text of a NVT.
int nvti_add_required_keys(nvti_t *n, const gchar *key)
Add a required key of a NVT.
int nvti_add_pref(nvti_t *n, nvtpref_t *np)
Add a preference to the NVT Info.
gchar * solution
The solution.
void nvtis_add(nvtis_t *nvtis, nvti_t *nvti)
Add an NVT Info to a collection of NVT Infos.
int nvti_set_cvss_base(nvti_t *n, const gchar *cvss_base)
Set the CVSS base of an NVT.
gchar * dflt
Default value of the preference.
gchar * type
Reference type ("cve", "bid", ...)
int nvtpref_id(const nvtpref_t *np)
Get the ID of a NVT Preference.
int nvti_set_name(nvti_t *n, const gchar *name)
Set the name of a NVT.
gint timeout
Default timeout time for this NVT.
time_t creation_time
Time of creation, seconds since epoch.
gchar * cvss_base
CVSS base score for this NVT.
int nvti_set_solution(nvti_t *n, const gchar *solution)
Set the solution of a NVT.
gchar * affected
Affected systems.
gchar * required_udp_ports
List of required UDP ports of this NVT.
gint category
The category, this NVT belongs to.
gchar * nvti_refs(const nvti_t *n, const gchar *type, const gchar *exclude_types, guint use_types)
Get references as string.
gchar * nvti_required_udp_ports(const nvti_t *n)
Get the required udp ports list.
The structure of a information record that corresponds to a NVT.
gchar * nvti_required_ports(const nvti_t *n)
Get the required ports list.
time_t nvti_modification_time(const nvti_t *n)
Get the modification time.
gint nvti_category(const nvti_t *n)
Get the category for this NVT.
void vtref_free(vtref_t *ref)
Free memory of a vtref structure.
int nvti_set_excluded_keys(nvti_t *n, const gchar *excluded_keys)
Set the excluded keys of a NVT.
gchar * name
Name of the preference.
int nvti_set_qod_type(nvti_t *n, const gchar *qod_type)
Set the QoD type of a NVT.
gchar * excluded_keys
List of excluded KB keys of this NVT.
int nvti_add_refs(nvti_t *n, const gchar *type, const gchar *ref_ids, const gchar *ref_text)
Add many new vtref from a comma-separated list.
gchar * nvti_solution(const nvti_t *n)
Get the solution.
void nvti_free(nvti_t *n)
Free memory of a nvti structure.
nvtis_t * nvtis_new(void)
Make a collection of NVT Infos.
gchar * nvti_impact(const nvti_t *n)
Get the text about impact.
int nvti_set_modification_time(nvti_t *n, const time_t modification_time)
Set the modification time of a NVT.
The structure for a preference of a NVT.
struct vtref vtref_t
The structure for a cross reference of a VT.
int nvti_set_timeout(nvti_t *n, const gint timeout)
Set the timeout of a NVT Info.
guint nvti_pref_len(const nvti_t *n)
Get the number of preferences of the NVT.
void nvtpref_free(nvtpref_t *np)
Free memory of a nvtpref structure.
int nvti_set_dependencies(nvti_t *n, const gchar *dependencies)
Set the dependencies of a NVT.
int nvti_add_tag(nvti_t *n, const gchar *name, const gchar *value)
Add a tag to the NVT tags. The tag names "last_modification" and "creation_date" are treated special:...
gchar * type
Preference type.
gchar * impact
Impact of vulnerability.
vtref_t * vtref_new(const gchar *type, const gchar *ref_id, const gchar *ref_text)
Create a new vtref structure filled with the given values.
nvti_t * nvtis_lookup(nvtis_t *nvtis, const char *oid)
Add an NVT Info to a collection of NVT Infos.
static void free_nvti_for_hash_table(gpointer nvti)
Free an NVT Info, for g_hash_table_destroy.
gchar * nvti_tag(const nvti_t *n)
Get the tags.
vtref_t * nvti_vtref(const nvti_t *n, guint p)
Get the n'th reference of the NVT.
gchar * summary
The summary.
int nvti_set_tag(nvti_t *n, const gchar *tag)
Set the tags of a NVT.
int nvti_add_required_udp_ports(nvti_t *n, const gchar *port)
Add a required udp port of a NVT.
nvtpref_t * nvtpref_new(int id, gchar *name, gchar *type, gchar *dflt)
Create a new nvtpref structure filled with the given values.
gchar * family
Family the NVT belongs to.
time_t modification_time
Time of last change, sec. since epoch.
gchar * nvti_affected(const nvti_t *n)
Get the text about affected systems.
gchar * nvtpref_name(const nvtpref_t *np)
Get the Name of a NVT Preference.
gchar * nvti_mandatory_keys(const nvti_t *n)
Get the mandatory keys list.
gint nvti_timeout(const nvti_t *n)
Get the timeout for this NVT.
gchar * nvti_dependencies(const nvti_t *n)
Get the dependencies list.
int nvti_add_mandatory_keys(nvti_t *n, const gchar *key)
Add a mandatory key of a NVT.
gchar * dependencies
List of dependencies of this NVT.
gchar * nvti_name(const nvti_t *n)
Get the name.
gchar * tag
List of tags attached to this NVT.
gchar * nvti_excluded_keys(const nvti_t *n)
Get the excluded keys list.
gchar * required_ports
List of required ports of this NVT.
int nvti_set_required_ports(nvti_t *n, const gchar *required_ports)
Set the required ports of a NVT.
gchar * nvti_qod_type(const nvti_t *n)
Get the QoD type.
int nvti_set_summary(nvti_t *n, const gchar *summary)
Set the summary of a NVT.
gchar * qod_type
Quality of detection type.
int nvti_set_solution_type(nvti_t *n, const gchar *solution_type)
Set the solution type of a NVT.
int nvti_set_detection(nvti_t *n, const gchar *detection)
Set the detection text of a NVT.
gchar * nvtpref_default(const nvtpref_t *np)
Get the Default of a NVT Preference.
time_t nvti_creation_time(const nvti_t *n)
Get the creation time.
nvti_t * nvti_new(void)
Create a new (empty) nvti structure.
int nvti_set_affected(nvti_t *n, const gchar *affected)
Set the affected text of a NVT.
gchar * nvtpref_type(const nvtpref_t *np)
Get the Type of a NVT Preference.
const gchar * vtref_type(const vtref_t *r)
Get the type of a reference.
int nvti_set_family(nvti_t *n, const gchar *family)
Set the family of a NVT.
int nvti_set_category(nvti_t *n, const gint category)
Set the category type of a NVT Info.
static time_t parse_nvt_timestamp(const gchar *str_time)
Try convert an NVT tag time string into epoch time or return 0 upon parse errors.
int nvti_set_oid(nvti_t *n, const gchar *oid)
Set the OID of a NVT Info.
int nvti_set_mandatory_keys(nvti_t *n, const gchar *mandatory_keys)
Set the mandatory keys of a NVT.
gchar * nvti_summary(const nvti_t *n)
Get the summary.
GSList * prefs
Collection of NVT preferences.
Protos and data structures for NVT Information data sets.
GSList * refs
Collection of VT references.
int nvti_add_excluded_keys(nvti_t *n, const gchar *key)
Add a excluded key of a NVT.
const gchar * vtref_id(const vtref_t *r)
Get the id of a reference.
gchar * ref_id
Actual reference ID ("CVE-2018-1234", etc)
gchar * nvti_required_keys(const nvti_t *n)
Get the required keys list.