nvti.c
Go to the documentation of this file.
/* SPDX-FileCopyrightText: 2009-2023 Greenbone AG
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
// One of the files of gvm-libs needs to specify the meta data
// for the doxygen documentation.
/* For strptime in time.h. */
#undef _XOPEN_SOURCE
#define _XOPEN_SOURCE
#include "nvti.h"
#include <stdio.h> // for sscanf
#include <string.h> // for strcmp
#include <strings.h> // for strcasecmp
#include <time.h> // for strptime
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "libgvm base"
/* VT references */
typedef struct vtref
{
gchar *type;
gchar *ref_id;
gchar *ref_text;
} vtref_t;
vtref_t *
vtref_new (const gchar *type, const gchar *ref_id, const gchar *ref_text)
{
vtref_t *ref = g_malloc0 (sizeof (vtref_t));
if (type)
ref->type = g_strdup (type);
if (ref_id)
ref->ref_id = g_strdup (ref_id);
if (ref_text)
ref->ref_text = g_strdup (ref_text);
return ref;
}
void
vtref_free (vtref_t *ref)
{
if (!ref)
return;
g_free (ref->type);
g_free (ref->ref_id);
g_free (ref->ref_text);
g_free (ref);
}
const gchar *
vtref_type (const vtref_t *r)
{
return r ? r->type : NULL;
}
const gchar *
vtref_id (const vtref_t *r)
{
return r ? r->ref_id : NULL;
}
const gchar *
vtref_text (const vtref_t *r)
{
return r ? r->ref_text : NULL;
}
/* VT severities */
typedef struct vtseverity
{
gchar *type;
gchar *origin;
int date;
double score;
gchar *value;
} vtseverity_t;
vtseverity_t *
vtseverity_new (const gchar *type, const gchar *origin, int date, double score,
const gchar *value)
{
vtseverity_t *s = g_malloc0 (sizeof (vtseverity_t));
if (type)
s->type = g_strdup (type);
if (origin)
s->origin = g_strdup (origin);
s->date = date;
s->score = score;
if (value)
s->value = g_strdup (value);
return s;
}
void
vtseverity_free (vtseverity_t *s)
{
if (!s)
return;
g_free (s->type);
g_free (s->origin);
g_free (s->value);
g_free (s);
}
const gchar *
vtseverity_type (const vtseverity_t *s)
{
return s ? s->type : NULL;
}
const gchar *
vtseverity_origin (const vtseverity_t *s)
{
return s ? s->origin : NULL;
}
const gchar *
vtseverity_value (const vtseverity_t *s)
{
return s ? s->value : NULL;
}
int
vtseverity_date (const vtseverity_t *s)
{
return s->date;
}
double
vtseverity_score (const vtseverity_t *s)
{
return s->score;
}
/* Support function for timestamps */
static time_t
parse_nvt_timestamp (const gchar *str_time)
{
time_t epoch_time;
int offset;
struct tm tm;
if (strcmp ((char *) str_time, "") == 0)
return 0;
/* Parse the time. */
/* 2011-08-09 08:20:34 +0200 (Tue, 09 Aug 2011) */
memset (&tm, 0, sizeof (struct tm));
if (strptime ((char *) str_time, "%F %T %z", &tm) == NULL)
{
memset (&tm, 0, sizeof (struct tm));
if (strptime ((char *) str_time, "%a %b %d %T %Y %z", &tm) == NULL)
{
g_warning ("%s: Failed to parse time: %s", __func__, str_time);
return 0;
}
}
epoch_time = mktime (&tm);
if (epoch_time == -1)
{
g_warning ("%s: Failed to make time: %s", __func__, str_time);
return 0;
}
/* Get the timezone offset from the str_time. */
if ((sscanf ((char *) str_time, "%*u-%*u-%*u %*u:%*u:%*u %d%*[^]]", &offset)
!= 1)
&& (sscanf ((char *) str_time, "%*s %*s %*s %*u:%*u:%*u %*u %d%*[^]]",
&offset)
!= 1))
{
g_warning ("%s: Failed to parse timezone offset: %s", __func__, str_time);
return 0;
}
/* Use the offset to convert to UTC. */
if (offset < 0)
{
epoch_time += ((-offset) / 100) * 60 * 60;
epoch_time += ((-offset) % 100) * 60;
}
else if (offset > 0)
{
epoch_time -= (offset / 100) * 60 * 60;
epoch_time -= (offset % 100) * 60;
}
return epoch_time;
}
/* VT Information */
typedef struct nvti
{
gchar *oid;
gchar *name;
gchar *summary;
gchar *insight;
gchar *affected;
gchar *impact;
time_t creation_time;
time_t modification_time;
gchar *solution;
gchar *solution_type;
gchar *solution_method;
gchar *tag;
gchar *cvss_base;
gchar *dependencies;
gchar *required_keys;
gchar *mandatory_keys;
gchar *excluded_keys;
gchar *required_ports;
gchar
*required_udp_ports;
gchar *detection;
gchar *qod_type;
gchar *qod;
GSList *refs;
GSList *severities;
GSList *prefs;
// The following are not settled yet.
gint category;
gchar *family;
} nvti_t;
int
nvti_add_vtref (nvti_t *vt, vtref_t *ref)
{
if (!vt)
return -1;
vt->refs = g_slist_append (vt->refs, ref);
return 0;
}
int
nvti_add_vtseverity (nvti_t *vt, vtseverity_t *s)
{
if (!vt)
return -1;
vt->severities = g_slist_append (vt->severities, s);
return 0;
}
/* VT preferences */
typedef struct nvtpref
{
int id;
gchar *type;
gchar *name;
gchar *dflt;
} nvtpref_t;
nvtpref_t *
nvtpref_new (int id, const gchar *name, const gchar *type, const gchar *dflt)
{
nvtpref_t *np = g_malloc0 (sizeof (nvtpref_t));
np->id = id;
if (name)
np->name = g_strdup (name);
if (type)
np->type = g_strdup (type);
if (dflt)
np->dflt = g_strdup (dflt);
return np;
}
void
nvtpref_free (nvtpref_t *np)
{
if (!np)
return;
g_free (np->name);
g_free (np->type);
g_free (np->dflt);
g_free (np);
}
int
nvtpref_id (const nvtpref_t *np)
{
return np ? np->id : -1;
}
gchar *
nvtpref_name (const nvtpref_t *np)
{
return np ? np->name : NULL;
}
gchar *
nvtpref_type (const nvtpref_t *np)
{
return np ? np->type : NULL;
}
gchar *
nvtpref_default (const nvtpref_t *np)
{
return np ? np->dflt : NULL;
}
nvti_t *
nvti_new (void)
{
return (nvti_t *) g_malloc0 (sizeof (nvti_t));
}
void
nvti_free (nvti_t *n)
{
if (!n)
return;
g_free (n->oid);
g_free (n->name);
g_free (n->summary);
g_free (n->insight);
g_free (n->affected);
g_free (n->impact);
g_free (n->solution);
g_free (n->solution_type);
g_free (n->solution_method);
g_free (n->tag);
g_free (n->cvss_base);
g_free (n->dependencies);
g_free (n->required_keys);
g_free (n->mandatory_keys);
g_free (n->excluded_keys);
g_free (n->required_ports);
g_free (n->required_udp_ports);
g_free (n->detection);
g_free (n->qod_type);
g_free (n->qod);
g_free (n->family);
g_slist_free_full (n->refs, (void (*) (void *)) vtref_free);
g_slist_free_full (n->severities, (void (*) (void *)) vtseverity_free);
g_slist_free_full (n->prefs, (void (*) (void *)) nvtpref_free);
g_free (n);
}
gchar *
nvti_oid (const nvti_t *n)
{
return n ? n->oid : NULL;
}
gchar *
nvti_name (const nvti_t *n)
{
return n ? n->name : NULL;
}
gchar *
nvti_summary (const nvti_t *n)
{
return n ? n->summary : NULL;
}
gchar *
nvti_insight (const nvti_t *n)
{
return n ? n->insight : NULL;
}
gchar *
nvti_affected (const nvti_t *n)
{
return n ? n->affected : NULL;
}
gchar *
nvti_impact (const nvti_t *n)
{
return n ? n->impact : NULL;
}
time_t
nvti_creation_time (const nvti_t *n)
{
return n ? n->creation_time : 0;
}
time_t
nvti_modification_time (const nvti_t *n)
{
return n ? n->modification_time : 0;
}
guint
nvti_vtref_len (const nvti_t *n)
{
return n ? g_slist_length (n->refs) : 0;
}
vtref_t *
nvti_vtref (const nvti_t *n, guint p)
{
return n ? g_slist_nth_data (n->refs, p) : NULL;
}
gchar *
nvti_refs (const nvti_t *n, const gchar *type, const gchar *exclude_types,
guint use_types)
{
gchar *refs, *refs2, **exclude_item;
vtref_t *ref;
guint i, exclude;
gchar **exclude_split;
if (!n)
return NULL;
refs = NULL;
refs2 = NULL;
exclude = 0;
if (exclude_types && exclude_types[0])
exclude_split = g_strsplit (exclude_types, ",", 0);
else
exclude_split = NULL;
for (i = 0; i < g_slist_length (n->refs); i++)
{
ref = g_slist_nth_data (n->refs, i);
if (type && strcasecmp (ref->type, type) != 0)
continue;
if (exclude_split)
{
exclude = 0;
for (exclude_item = exclude_split; *exclude_item; exclude_item++)
{
if (strcasecmp (g_strstrip (*exclude_item), ref->type) == 0)
{
exclude = 1;
break;
}
}
}
if (!exclude)
{
if (use_types)
{
if (refs)
refs2 =
g_strdup_printf ("%s, %s:%s", refs, ref->type, ref->ref_id);
else
refs2 = g_strdup_printf ("%s:%s", ref->type, ref->ref_id);
}
else
{
if (refs)
refs2 = g_strdup_printf ("%s, %s", refs, ref->ref_id);
else
refs2 = g_strdup_printf ("%s", ref->ref_id);
}
g_free (refs);
refs = refs2;
}
}
g_strfreev (exclude_split);
return refs;
}
guint
nvti_vtseverities_len (const nvti_t *n)
{
return n ? g_slist_length (n->severities) : 0;
}
vtseverity_t *
nvti_vtseverity (const nvti_t *n, guint p)
{
return n ? g_slist_nth_data (n->severities, p) : NULL;
}
double
nvti_severity_score (const nvti_t *n)
{
unsigned int i;
double score = -1.0;
for (i = 0; i < nvti_vtseverities_len (n); i++)
{
vtseverity_t *severity;
severity = nvti_vtseverity (n, i);
if (vtseverity_score (severity) > score)
score = vtseverity_score (severity);
}
return score;
}
gchar *
nvti_severity_vector_from_tag (const nvti_t *n)
{
gchar *vector;
/* Currently, only one severity_vector can be stored as tag.
* Therfore we just check this one. */
vector = nvti_get_tag (n, "severity_vector");
if (vector)
return vector;
vector = nvti_get_tag (n, "cvss_base_vector");
return vector;
}
gchar *
nvti_solution (const nvti_t *n)
{
return n ? n->solution : NULL;
}
gchar *
nvti_solution_type (const nvti_t *n)
{
return n ? n->solution_type : NULL;
}
gchar *
nvti_solution_method (const nvti_t *n)
{
return n ? n->solution_method : NULL;
}
gchar *
nvti_tag (const nvti_t *n)
{
return n ? n->tag : NULL;
}
gchar *
nvti_get_tag (const nvti_t *n, const gchar *name)
{
gchar **split, **point;
if (!n || n->tag == NULL || !name)
return NULL;
split = g_strsplit (n->tag, "|", 0);
point = split;
while (*point)
{
if ((strlen (*point) > strlen (name))
&& (strncmp (*point, name, strlen (name)) == 0)
&& ((*point)[strlen (name)] == '='))
{
gchar *ret;
ret = g_strdup (*point + strlen (name) + 1);
g_strfreev (split);
return ret;
}
point++;
}
g_strfreev (split);
return NULL;
}
gchar *
nvti_cvss_base (const nvti_t *n)
{
return n ? n->cvss_base : NULL;
}
gchar *
nvti_dependencies (const nvti_t *n)
{
return n ? n->dependencies : NULL;
}
gchar *
nvti_required_keys (const nvti_t *n)
{
return n ? n->required_keys : NULL;
}
gchar *
nvti_mandatory_keys (const nvti_t *n)
{
return n ? n->mandatory_keys : NULL;
}
gchar *
nvti_excluded_keys (const nvti_t *n)
{
return n ? n->excluded_keys : NULL;
}
gchar *
nvti_required_ports (const nvti_t *n)
{
return n ? n->required_ports : NULL;
}
gchar *
nvti_required_udp_ports (const nvti_t *n)
{
return n ? n->required_udp_ports : NULL;
}
gchar *
nvti_detection (const nvti_t *n)
{
return n ? n->detection : NULL;
}
gchar *
nvti_qod_type (const nvti_t *n)
{
return n ? n->qod_type : NULL;
}
gchar *
nvti_qod (const nvti_t *n)
{
return n ? n->qod : NULL;
}
gchar *
nvti_family (const nvti_t *n)
{
return n ? n->family : NULL;
}
guint
nvti_pref_len (const nvti_t *n)
{
return n ? g_slist_length (n->prefs) : 0;
}
const nvtpref_t *
nvti_pref (const nvti_t *n, guint p)
{
return n ? g_slist_nth_data (n->prefs, p) : NULL;
}
gint
nvti_category (const nvti_t *n)
{
return n ? n->category : -1;
}
int
nvti_set_oid (nvti_t *n, const gchar *oid)
{
if (!n)
return -1;
g_free (n->oid);
n->oid = g_strdup (oid);
return 0;
}
int
nvti_set_name (nvti_t *n, const gchar *name)
{
if (!n)
return -1;
g_free (n->name);
n->name = g_strdup (name);
return 0;
}
int
nvti_put_name (nvti_t *n, gchar *name)
{
if (!n)
return -1;
g_free (n->name);
n->name = name;
return 0;
}
int
nvti_set_summary (nvti_t *n, const gchar *summary)
{
if (!n)
return -1;
g_free (n->summary);
n->summary = g_strdup (summary);
return 0;
}
int
nvti_put_summary (nvti_t *n, gchar *summary)
{
if (!n)
return -1;
g_free (n->summary);
n->summary = summary;
return 0;
}
int
nvti_set_insight (nvti_t *n, const gchar *insight)
{
if (!n)
return -1;
g_free (n->insight);
n->insight = g_strdup (insight);
return 0;
}
int
nvti_put_insight (nvti_t *n, gchar *insight)
{
if (!n)
return -1;
g_free (n->insight);
n->insight = insight;
return 0;
}
int
nvti_set_affected (nvti_t *n, const gchar *affected)
{
if (!n)
return -1;
g_free (n->affected);
n->affected = g_strdup (affected);
return 0;
}
int
nvti_put_affected (nvti_t *n, gchar *affected)
{
if (!n)
return -1;
g_free (n->affected);
n->affected = affected;
return 0;
}
int
nvti_set_impact (nvti_t *n, const gchar *impact)
{
if (!n)
return -1;
g_free (n->impact);
n->impact = g_strdup (impact);
return 0;
}
int
nvti_put_impact (nvti_t *n, gchar *impact)
{
if (!n)
return -1;
g_free (n->impact);
n->impact = impact;
return 0;
}
int
nvti_set_creation_time (nvti_t *n, const time_t creation_time)
{
if (!n)
return -1;
n->creation_time = creation_time;
return 0;
}
int
nvti_set_modification_time (nvti_t *n, const time_t modification_time)
{
if (!n)
return -1;
n->modification_time = modification_time;
return 0;
}
int
nvti_set_solution (nvti_t *n, const gchar *solution)
{
if (!n)
return -1;
g_free (n->solution);
n->solution = g_strdup (solution);
return 0;
}
int
nvti_put_solution (nvti_t *n, gchar *solution)
{
if (!n)
return -1;
g_free (n->solution);
n->solution = solution;
return 0;
}
int
nvti_set_solution_type (nvti_t *n, const gchar *solution_type)
{
if (!n)
return -1;
g_free (n->solution_type);
n->solution_type = g_strdup (solution_type);
return 0;
}
int
nvti_set_solution_method (nvti_t *n, const gchar *solution_method)
{
if (!n)
return -1;
g_free (n->solution_method);
n->solution_method = g_strdup (solution_method);
return 0;
}
int
nvti_add_tag (nvti_t *n, const gchar *name, const gchar *value)
{
gchar *newvalue = NULL;
if (!n)
return -1;
if (!name || !name[0])
return -2;
if (!value || !value[0])
return -3;
if (!strcmp (name, "last_modification"))
{
nvti_set_modification_time (n, parse_nvt_timestamp (value));
newvalue = g_strdup_printf ("%i", (int) nvti_modification_time (n));
}
else if (!strcmp (name, "creation_date"))
{
nvti_set_creation_time (n, parse_nvt_timestamp (value));
newvalue = g_strdup_printf ("%i", (int) nvti_creation_time (n));
}
else if (!strcmp (name, "severity_date"))
newvalue = g_strdup_printf ("%i", (int) parse_nvt_timestamp (value));
else if (!strcmp (name, "cvss_base"))
{
/* Ignore this tag because it is not being used.
* It is redundant with the tag cvss_base_vector from which
* it is computed.
* Once GOS 6 and GVM 11 are retired, all set_tag commands
* in the NASL scripts can be removed that set "cvss_base".
* Once this happened this exception can be removed from the code.
*/
return 0;
}
if (n->tag)
{
gchar *newtag;
newtag =
g_strconcat (n->tag, "|", name, "=", newvalue ? newvalue : value, NULL);
g_free (n->tag);
n->tag = newtag;
}
else
n->tag = g_strconcat (name, "=", newvalue ? newvalue : value, NULL);
g_free (newvalue);
return 0;
}
int
nvti_set_tag (nvti_t *n, const gchar *tag)
{
if (!n)
return -1;
g_free (n->tag);
if (tag && tag[0])
n->tag = g_strdup (tag);
else
n->tag = NULL;
return 0;
}
int
nvti_set_cvss_base (nvti_t *n, const gchar *cvss_base)
{
if (!n)
return -1;
g_free (n->cvss_base);
if (cvss_base && cvss_base[0])
n->cvss_base = g_strdup (cvss_base);
else
n->cvss_base = NULL;
return 0;
}
int
nvti_set_dependencies (nvti_t *n, const gchar *dependencies)
{
if (!n)
return -1;
g_free (n->dependencies);
if (dependencies && dependencies[0])
n->dependencies = g_strdup (dependencies);
else
n->dependencies = NULL;
return 0;
}
int
nvti_set_required_keys (nvti_t *n, const gchar *required_keys)
{
if (!n)
return -1;
g_free (n->required_keys);
if (required_keys && required_keys[0])
n->required_keys = g_strdup (required_keys);
else
n->required_keys = NULL;
return 0;
}
int
nvti_set_mandatory_keys (nvti_t *n, const gchar *mandatory_keys)
{
if (!n)
return -1;
g_free (n->mandatory_keys);
if (mandatory_keys && mandatory_keys[0])
n->mandatory_keys = g_strdup (mandatory_keys);
else
n->mandatory_keys = NULL;
return 0;
}
int
nvti_set_excluded_keys (nvti_t *n, const gchar *excluded_keys)
{
if (!n)
return -1;
g_free (n->excluded_keys);
if (excluded_keys && excluded_keys[0])
n->excluded_keys = g_strdup (excluded_keys);
else
n->excluded_keys = NULL;
return 0;
}
int
nvti_set_required_ports (nvti_t *n, const gchar *required_ports)
{
if (!n)
return -1;
g_free (n->required_ports);
if (required_ports && required_ports[0])
n->required_ports = g_strdup (required_ports);
else
n->required_ports = NULL;
return 0;
}
int
nvti_set_required_udp_ports (nvti_t *n, const gchar *required_udp_ports)
{
if (!n)
return -1;
g_free (n->required_udp_ports);
if (required_udp_ports && required_udp_ports[0])
n->required_udp_ports = g_strdup (required_udp_ports);
else
n->required_udp_ports = NULL;
return 0;
}
int
nvti_set_detection (nvti_t *n, const gchar *detection)
{
if (!n)
return -1;
g_free (n->detection);
n->detection = g_strdup (detection);
return 0;
}
int
nvti_put_detection (nvti_t *n, gchar *detection)
{
if (!n)
return -1;
g_free (n->detection);
n->detection = detection;
return 0;
}
int
nvti_set_qod_type (nvti_t *n, const gchar *qod_type)
{
if (!n)
return -1;
g_free (n->qod_type);
if (qod_type && qod_type[0])
n->qod_type = g_strdup (qod_type);
else
n->qod_type = NULL;
return 0;
}
int
nvti_set_qod (nvti_t *n, const gchar *qod)
{
if (!n)
return -1;
g_free (n->qod);
if (qod && qod[0])
n->qod = g_strdup (qod);
else
n->qod = NULL;
return 0;
}
int
nvti_set_family (nvti_t *n, const gchar *family)
{
if (!n)
return -1;
g_free (n->family);
n->family = g_strdup (family);
return 0;
}
int
nvti_put_family (nvti_t *n, gchar *family)
{
if (!n)
return -1;
g_free (n->family);
n->family = family;
return 0;
}
int
nvti_set_category (nvti_t *n, const gint category)
{
if (!n)
return -1;
n->category = category;
return 0;
}
int
nvti_add_refs (nvti_t *n, const gchar *type, const gchar *ref_ids,
const gchar *ref_text)
{
gchar **split, **item;
if (!n)
return 1;
if (!ref_ids)
return 2;
split = g_strsplit (ref_ids, ",", 0);
for (item = split; *item; item++)
{
gchar *id;
id = *item;
g_strstrip (id);
if (strcmp (id, "") == 0)
continue;
if (type)
{
nvti_add_vtref (n, vtref_new (type, id, ref_text));
}
else
{
gchar **split2;
split2 = g_strsplit (id, ":", 2);
if (split2[0] && split2[1])
nvti_add_vtref (n, vtref_new (split2[0], split2[1], ""));
g_strfreev (split2);
}
}
g_strfreev (split);
return 0;
}
int
nvti_add_required_keys (nvti_t *n, const gchar *key)
{
gchar *old;
if (!n)
return 1;
if (!key)
return 2;
old = n->required_keys;
if (old)
{
n->required_keys = g_strdup_printf ("%s, %s", old, key);
g_free (old);
}
else
n->required_keys = g_strdup (key);
return 0;
}
int
nvti_add_mandatory_keys (nvti_t *n, const gchar *key)
{
gchar *old;
if (!n)
return 1;
if (!key)
return 2;
old = n->mandatory_keys;
if (old)
{
n->mandatory_keys = g_strdup_printf ("%s, %s", old, key);
g_free (old);
}
else
n->mandatory_keys = g_strdup (key);
return 0;
}
int
nvti_add_excluded_keys (nvti_t *n, const gchar *key)
{
gchar *old;
if (!n)
return 1;
if (!key)
return 2;
old = n->excluded_keys;
if (old)
{
n->excluded_keys = g_strdup_printf ("%s, %s", old, key);
g_free (old);
}
else
n->excluded_keys = g_strdup (key);
return 0;
}
int
nvti_add_required_ports (nvti_t *n, const gchar *port)
{
gchar *old;
if (!n)
return 1;
if (!port)
return 2;
old = n->required_ports;
if (old)
{
n->required_ports = g_strdup_printf ("%s, %s", old, port);
g_free (old);
}
else
n->required_ports = g_strdup (port);
return 0;
}
int
nvti_add_required_udp_ports (nvti_t *n, const gchar *port)
{
gchar *old;
if (!n)
return 1;
if (!port)
return 2;
old = n->required_udp_ports;
if (old)
{
n->required_udp_ports = g_strdup_printf ("%s, %s", old, port);
g_free (old);
}
else
n->required_udp_ports = g_strdup (port);
return 0;
}
int
nvti_add_pref (nvti_t *n, nvtpref_t *np)
{
if (!n)
return -1;
n->prefs = g_slist_append (n->prefs, np);
return 0;
}
/* Collections of nvtis. */
static void
free_nvti_for_hash_table (gpointer nvti)
{
nvti_free ((nvti_t *) nvti);
}
nvtis_t *
nvtis_new (void)
{
return g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
free_nvti_for_hash_table);
}
void
nvtis_free (nvtis_t *nvtis)
{
if (nvtis)
g_hash_table_destroy (nvtis);
}
void
nvtis_add (nvtis_t *nvtis, nvti_t *nvti)
{
if (nvti)
g_hash_table_insert (
nvtis, (gpointer) (nvti_oid (nvti) ? g_strdup (nvti_oid (nvti)) : NULL),
(gpointer) nvti);
}
nvti_t *
nvtis_lookup (nvtis_t *nvtis, const char *oid)
{
return g_hash_table_lookup (nvtis, oid);
}
nvti_vtref
vtref_t * nvti_vtref(const nvti_t *n, guint p)
Get the n'th reference of the NVT.
Definition nvti.c:737
vtseverity_t
struct vtseverity vtseverity_t
The structure for a severity of a VT.
nvti_new
nvti_t * nvti_new(void)
Create a new (empty) nvti structure.
Definition nvti.c:559
nvti_put_impact
int nvti_put_impact(nvti_t *n, gchar *impact)
Set the impact text of a NVT, using the given memory.
Definition nvti.c:1414
vtseverity_free
void vtseverity_free(vtseverity_t *s)
Free memory of a vtseverity structure.
Definition nvti.c:203
nvti_dependencies
gchar * nvti_dependencies(const nvti_t *n)
Get the dependencies list.
Definition nvti.c:1032
nvti_add_required_keys
int nvti_add_required_keys(nvti_t *n, const gchar *key)
Add a required key of a NVT.
Definition nvti.c:2020
nvti_pref_len
guint nvti_pref_len(const nvti_t *n)
Get the number of preferences of the NVT.
Definition nvti.c:1171
nvti_set_qod
int nvti_set_qod(nvti_t *n, const gchar *qod)
Set the QoD of a NVT.
Definition nvti.c:1880
nvti_detection
gchar * nvti_detection(const nvti_t *n)
Get the text about detection.
Definition nvti.c:1116
nvti_required_udp_ports
gchar * nvti_required_udp_ports(const nvti_t *n)
Get the required udp ports list.
Definition nvti.c:1102
nvti_set_solution
int nvti_set_solution(nvti_t *n, const gchar *solution)
Set the solution of a NVT.
Definition nvti.c:1472
nvti_get_tag
gchar * nvti_get_tag(const nvti_t *n, const gchar *name)
Get a tag value by a tag name.
Definition nvti.c:982
nvti_summary
gchar * nvti_summary(const nvti_t *n)
Get the summary.
Definition nvti.c:639
nvti_set_solution_type
int nvti_set_solution_type(nvti_t *n, const gchar *solution_type)
Set the solution type of a NVT.
Definition nvti.c:1513
nvti_required_ports
gchar * nvti_required_ports(const nvti_t *n)
Get the required ports list.
Definition nvti.c:1088
nvti_put_insight
int nvti_put_insight(nvti_t *n, gchar *insight)
Set the insight text of a NVT, using the given memory.
Definition nvti.c:1334
nvti_refs
gchar * nvti_refs(const nvti_t *n, const gchar *type, const gchar *exclude_types, guint use_types)
Get references as string.
Definition nvti.c:766
nvti_severity_score
double nvti_severity_score(const nvti_t *n)
Get the maximum severity score.
Definition nvti.c:868
nvtpref_type
gchar * nvtpref_type(const nvtpref_t *np)
Get the Type of a NVT Preference.
Definition nvti.c:532
nvti_set_excluded_keys
int nvti_set_excluded_keys(nvti_t *n, const gchar *excluded_keys)
Set the excluded keys of a NVT.
Definition nvti.c:1744
nvti_t
struct nvti nvti_t
The structure of a information record that corresponds to a NVT.
nvti_set_qod_type
int nvti_set_qod_type(nvti_t *n, const gchar *qod_type)
Set the QoD type of a NVT.
Definition nvti.c:1856
nvti_add_excluded_keys
int nvti_add_excluded_keys(nvti_t *n, const gchar *key)
Add a excluded key of a NVT.
Definition nvti.c:2084
nvti_put_detection
int nvti_put_detection(nvti_t *n, gchar *detection)
Set the detection text of a NVT, using the given memory.
Definition nvti.c:1835
nvtis_new
nvtis_t * nvtis_new(void)
Make a collection of NVT Infos.
Definition nvti.c:2208
nvti_set_dependencies
int nvti_set_dependencies(nvti_t *n, const gchar *dependencies)
Set the dependencies of a NVT.
Definition nvti.c:1672
nvti_set_required_ports
int nvti_set_required_ports(nvti_t *n, const gchar *required_ports)
Set the required ports of a NVT.
Definition nvti.c:1768
nvti_set_oid
int nvti_set_oid(nvti_t *n, const gchar *oid)
Set the OID of a NVT Info.
Definition nvti.c:1214
nvti_add_required_udp_ports
int nvti_add_required_udp_ports(nvti_t *n, const gchar *port)
Add a required udp port of a NVT.
Definition nvti.c:2148
nvti_set_tag
int nvti_set_tag(nvti_t *n, const gchar *tag)
Set the tags of a NVT.
Definition nvti.c:1625
nvti_set_cvss_base
int nvti_set_cvss_base(nvti_t *n, const gchar *cvss_base)
Set the CVSS base of an NVT.
Definition nvti.c:1648
nvti_set_mandatory_keys
int nvti_set_mandatory_keys(nvti_t *n, const gchar *mandatory_keys)
Set the mandatory keys of a NVT.
Definition nvti.c:1720
nvti_put_name
int nvti_put_name(nvti_t *n, gchar *name)
Set the name of a NVT, using the given memory.
Definition nvti.c:1254
nvti_put_family
int nvti_put_family(nvti_t *n, gchar *family)
Set the family of a NVT, using the given memory.
Definition nvti.c:1923
nvti_category
gint nvti_category(const nvti_t *n)
Get the category for this NVT.
Definition nvti.c:1199
nvti_set_impact
int nvti_set_impact(nvti_t *n, const gchar *impact)
Set the impact text of a NVT.
Definition nvti.c:1394
vtseverity_type
const gchar * vtseverity_type(const vtseverity_t *s)
Get the type of a severity.
Definition nvti.c:223
nvti_add_required_ports
int nvti_add_required_ports(nvti_t *n, const gchar *port)
Add a required port of a NVT.
Definition nvti.c:2116
nvtpref_t
struct nvtpref nvtpref_t
The structure for a preference of a NVT.
nvti_family
gchar * nvti_family(const nvti_t *n)
Get the family name.
Definition nvti.c:1158
nvti_severity_vector_from_tag
gchar * nvti_severity_vector_from_tag(const nvti_t *n)
Get the severity score.
Definition nvti.c:900
vtref_t
struct vtref vtref_t
The structure for a cross reference of a VT.
free_nvti_for_hash_table
static void free_nvti_for_hash_table(gpointer nvti)
Free an NVT Info, for g_hash_table_destroy.
Definition nvti.c:2197
nvti_solution_method
gchar * nvti_solution_method(const nvti_t *n)
Get the solution method.
Definition nvti.c:952
nvti_vtseverities_len
guint nvti_vtseverities_len(const nvti_t *n)
Get the number of severities of the NVT.
Definition nvti.c:840
nvti_pref
const nvtpref_t * nvti_pref(const nvti_t *n, guint p)
Get the n'th preferences of the NVT.
Definition nvti.c:1186
nvti_qod
gchar * nvti_qod(const nvti_t *n)
Get the QoD.
Definition nvti.c:1144
nvti_excluded_keys
gchar * nvti_excluded_keys(const nvti_t *n)
Get the excluded keys list.
Definition nvti.c:1074
nvti_set_summary
int nvti_set_summary(nvti_t *n, const gchar *summary)
Set the summary of a NVT.
Definition nvti.c:1274
nvti_name
gchar * nvti_name(const nvti_t *n)
Get the name.
Definition nvti.c:625
nvti_oid
gchar * nvti_oid(const nvti_t *n)
Get the OID string.
Definition nvti.c:611
nvtpref_new
nvtpref_t * nvtpref_new(int id, const gchar *name, const gchar *type, const gchar *dflt)
Create a new nvtpref structure filled with the given values.
Definition nvti.c:463
nvti_put_affected
int nvti_put_affected(nvti_t *n, gchar *affected)
Set the affected text of a NVT, using the given memory.
Definition nvti.c:1374
nvti_put_solution
int nvti_put_solution(nvti_t *n, gchar *solution)
Set the solution of a NVT, using the given memory.
Definition nvti.c:1492
vtseverity_score
double vtseverity_score(const vtseverity_t *s)
Get the score of a severity.
Definition nvti.c:279
vtref_type
const gchar * vtref_type(const vtref_t *r)
Get the type of a reference.
Definition nvti.c:117
nvti_add_pref
int nvti_add_pref(nvti_t *n, nvtpref_t *np)
Add a preference to the NVT Info.
Definition nvti.c:2180
nvti_put_summary
int nvti_put_summary(nvti_t *n, gchar *summary)
Set the summary of a NVT, using the given memory.
Definition nvti.c:1294
vtseverity_value
const gchar * vtseverity_value(const vtseverity_t *s)
Get the value of a severity.
Definition nvti.c:251
nvti_set_insight
int nvti_set_insight(nvti_t *n, const gchar *insight)
Set the insight text of a NVT.
Definition nvti.c:1314
vtref_new
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.
Definition nvti.c:77
nvti_cvss_base
gchar * nvti_cvss_base(const nvti_t *n)
Get the CVSS base.
Definition nvti.c:1018
nvti_set_required_keys
int nvti_set_required_keys(nvti_t *n, const gchar *required_keys)
Set the required keys of a NVT.
Definition nvti.c:1696
nvti_add_vtseverity
int nvti_add_vtseverity(nvti_t *vt, vtseverity_t *s)
Add a severity to the VT Info.
Definition nvti.c:426
nvtpref_free
void nvtpref_free(nvtpref_t *np)
Free memory of a nvtpref structure.
Definition nvti.c:484
nvti_set_solution_method
int nvti_set_solution_method(nvti_t *n, const gchar *solution_method)
Set the solution method of a NVT.
Definition nvti.c:1534
nvtpref_id
int nvtpref_id(const nvtpref_t *np)
Get the ID of a NVT Preference.
Definition nvti.c:504
nvti_set_name
int nvti_set_name(nvti_t *n, const gchar *name)
Set the name of a NVT.
Definition nvti.c:1234
nvtis_lookup
nvti_t * nvtis_lookup(nvtis_t *nvtis, const char *oid)
Add an NVT Info to a collection of NVT Infos.
Definition nvti.c:2250
nvti_qod_type
gchar * nvti_qod_type(const nvti_t *n)
Get the QoD type.
Definition nvti.c:1130
nvti_add_mandatory_keys
int nvti_add_mandatory_keys(nvti_t *n, const gchar *key)
Add a mandatory key of a NVT.
Definition nvti.c:2052
nvti_creation_time
time_t nvti_creation_time(const nvti_t *n)
Get the creation time.
Definition nvti.c:695
nvti_affected
gchar * nvti_affected(const nvti_t *n)
Get the text about affected systems.
Definition nvti.c:667
nvti_vtseverity
vtseverity_t * nvti_vtseverity(const nvti_t *n, guint p)
Get the n'th reference of the NVT.
Definition nvti.c:855
vtseverity_new
vtseverity_t * vtseverity_new(const gchar *type, const gchar *origin, int date, double score, const gchar *value)
Create a new vtseverity structure filled with the given values.
Definition nvti.c:180
nvti_solution
gchar * nvti_solution(const nvti_t *n)
Get the solution.
Definition nvti.c:924
nvti_set_modification_time
int nvti_set_modification_time(nvti_t *n, const time_t modification_time)
Set the modification time of a NVT.
Definition nvti.c:1453
nvti_set_creation_time
int nvti_set_creation_time(nvti_t *n, const time_t creation_time)
Set the creation time of a NVT.
Definition nvti.c:1434
nvti_required_keys
gchar * nvti_required_keys(const nvti_t *n)
Get the required keys list.
Definition nvti.c:1046
nvti_insight
gchar * nvti_insight(const nvti_t *n)
Get the text about insight.
Definition nvti.c:653
nvti_add_refs
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.
Definition nvti.c:1968
nvti_modification_time
time_t nvti_modification_time(const nvti_t *n)
Get the modification time.
Definition nvti.c:709
vtref_free
void vtref_free(vtref_t *ref)
Free memory of a vtref structure.
Definition nvti.c:97
vtseverity_origin
const gchar * vtseverity_origin(const vtseverity_t *s)
Get the origin of a severity.
Definition nvti.c:237
nvti_vtref_len
guint nvti_vtref_len(const nvti_t *n)
Get the number of references of the NVT.
Definition nvti.c:722
nvti_set_required_udp_ports
int nvti_set_required_udp_ports(nvti_t *n, const gchar *required_udp_ports)
Set the required udp ports of a NVT.
Definition nvti.c:1792
nvti_mandatory_keys
gchar * nvti_mandatory_keys(const nvti_t *n)
Get the mandatory keys list.
Definition nvti.c:1060
nvtpref_default
gchar * nvtpref_default(const nvtpref_t *np)
Get the Default of a NVT Preference.
Definition nvti.c:546
nvti_set_family
int nvti_set_family(nvti_t *n, const gchar *family)
Set the family of a NVT.
Definition nvti.c:1903
nvtpref_name
gchar * nvtpref_name(const nvtpref_t *np)
Get the Name of a NVT Preference.
Definition nvti.c:518
parse_nvt_timestamp
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.
Definition nvti.c:295
nvti_set_affected
int nvti_set_affected(nvti_t *n, const gchar *affected)
Set the affected text of a NVT.
Definition nvti.c:1354
vtseverity_date
int vtseverity_date(const vtseverity_t *s)
Get the date of a severity.
Definition nvti.c:265
nvti_solution_type
gchar * nvti_solution_type(const nvti_t *n)
Get the solution type.
Definition nvti.c:938
vtref_id
const gchar * vtref_id(const vtref_t *r)
Get the id of a reference.
Definition nvti.c:131
nvti_add_tag
int nvti_add_tag(nvti_t *n, const gchar *name, const gchar *value)
Add a tag to the NVT tags. The tag names "severity_date", "last_modification" and "creation_date" are...
Definition nvti.c:1561
nvtis_add
void nvtis_add(nvtis_t *nvtis, nvti_t *nvti)
Add an NVT Info to a collection of NVT Infos.
Definition nvti.c:2233
nvti_impact
gchar * nvti_impact(const nvti_t *n)
Get the text about impact.
Definition nvti.c:681
vtref_text
const gchar * vtref_text(const vtref_t *r)
Get the text of a reference.
Definition nvti.c:145
nvtis_free
void nvtis_free(nvtis_t *nvtis)
Free a collection of NVT Infos.
Definition nvti.c:2220
nvti_set_detection
int nvti_set_detection(nvti_t *n, const gchar *detection)
Set the detection text of a NVT.
Definition nvti.c:1815
nvti_tag
gchar * nvti_tag(const nvti_t *n)
Get the tags.
Definition nvti.c:966
nvti_set_category
int nvti_set_category(nvti_t *n, const gint category)
Set the category type of a NVT Info.
Definition nvti.c:1943
nvti_free
void nvti_free(nvti_t *n)
Free memory of a nvti structure.
Definition nvti.c:570
nvti_add_vtref
int nvti_add_vtref(nvti_t *vt, vtref_t *ref)
Add a reference to the VT Info.
Definition nvti.c:408
nvti.h
Protos and data structures for NVT Information data sets.
nvtis_t
GHashTable nvtis_t
A collection of information records corresponding to NVTs.
Definition nvti.h:252
strings.h
String utilities.
nvti
The structure of a information record that corresponds to a NVT.
Definition nvti.c:358
nvti::solution_method
gchar * solution_method
The solution method.
Definition nvti.c:372
nvti::insight
gchar * insight
The insight.
Definition nvti.c:363
nvti::affected
gchar * affected
Affected systems.
Definition nvti.c:364
nvti::cvss_base
gchar * cvss_base
CVSS base score for this NVT.
Definition nvti.c:375
nvti::required_keys
gchar * required_keys
List of required KB keys of this NVT.
Definition nvti.c:378
nvti::creation_time
time_t creation_time
Time of creation, seconds since epoch.
Definition nvti.c:367
nvti::solution
gchar * solution
The solution.
Definition nvti.c:370
nvti::impact
gchar * impact
Impact of vulnerability.
Definition nvti.c:365
nvti::family
gchar * family
Family the NVT belongs to.
Definition nvti.c:395
nvti::excluded_keys
gchar * excluded_keys
List of excluded KB keys of this NVT.
Definition nvti.c:380
nvti::required_udp_ports
gchar * required_udp_ports
List of required UDP ports of this NVT.
Definition nvti.c:383
nvti::refs
GSList * refs
Collection of VT references.
Definition nvti.c:389
nvti::tag
gchar * tag
List of tags attached to this NVT.
Definition nvti.c:374
nvti::oid
gchar * oid
Object ID.
Definition nvti.c:359
nvti::name
gchar * name
The name.
Definition nvti.c:360
nvti::category
gint category
The category, this NVT belongs to.
Definition nvti.c:394
nvti::qod_type
gchar * qod_type
Quality of detection type.
Definition nvti.c:386
nvti::severities
GSList * severities
Collection of VT severities.
Definition nvti.c:390
nvti::mandatory_keys
gchar * mandatory_keys
List of mandatory KB keys of this NVT.
Definition nvti.c:379
nvti::detection
gchar * detection
Detection description.
Definition nvti.c:385
nvti::solution_type
gchar * solution_type
The solution type.
Definition nvti.c:371
nvti::dependencies
gchar * dependencies
List of dependencies of this NVT.
Definition nvti.c:377
nvti::qod
gchar * qod
Quality of detection.
Definition nvti.c:387
nvti::modification_time
time_t modification_time
Time of last change, sec. since epoch.
Definition nvti.c:368
nvti::required_ports
gchar * required_ports
List of required ports of this NVT.
Definition nvti.c:381
nvti::summary
gchar * summary
The summary.
Definition nvti.c:362
nvti::prefs
GSList * prefs
Collection of NVT preferences.
Definition nvti.c:391
nvtpref
The structure for a preference of a NVT.
Definition nvti.c:441
nvtpref::type
gchar * type
Preference type.
Definition nvti.c:443
nvtpref::dflt
gchar * dflt
Default value of the preference.
Definition nvti.c:445
nvtpref::id
int id
Preference ID.
Definition nvti.c:442
nvtpref::name
gchar * name
Name of the preference.
Definition nvti.c:444
vtref
The structure for a cross reference of a VT.
Definition nvti.c:58
vtref::type
gchar * type
Reference type ("cve", "bid", ...).
Definition nvti.c:59
vtref::ref_id
gchar * ref_id
Actual reference ID ("CVE-2018-1234", etc).
Definition nvti.c:60
vtref::ref_text
gchar * ref_text
Optional additional text.
Definition nvti.c:61
vtseverity
The structure for a severity of a VT.
Definition nvti.c:158
vtseverity::origin
gchar * origin
Definition nvti.c:160
vtseverity::date
int date
Timestamp in seconds since epoch, defaults to VT creation date.
Definition nvti.c:162
vtseverity::score
double score
The score derived from the value in range [0.0-10.0].
Definition nvti.c:163
vtseverity::value
gchar * value
The value which corresponds to the type.
Definition nvti.c:164
vtseverity::type
gchar * type
Severity type ("cvss_base_v2", ...).
Definition nvti.c:159