OpenVAS Libraries  9.0.1
Macros | Functions
nvti.c File Reference

Implementation of API to handle NVT Info datasets. More...

#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#include <utime.h>
#include "nvti.h"

Macros

#define G_LOG_DOMAIN   "lib nvti"
 

Functions

nvtpref_tnvtpref_new (gchar *name, gchar *type, gchar *dflt)
 Create a new nvtpref structure filled with the given values. More...
 
void nvtpref_free (nvtpref_t *np)
 Free memory of a nvtpref structure. More...
 
gchar * nvtpref_name (const nvtpref_t *np)
 Get the Name of a NVT Preference. More...
 
gchar * nvtpref_type (const nvtpref_t *np)
 Get the Type of a NVT Preference. More...
 
gchar * nvtpref_default (const nvtpref_t *np)
 Get the Default of a NVT Preference. More...
 
nvti_tnvti_new (void)
 Create a new (empty) nvti structure. More...
 
void nvti_free (nvti_t *n)
 Free memory of a nvti structure. More...
 
gchar * nvti_oid (const nvti_t *n)
 Get the OID string. More...
 
gchar * nvti_version (const nvti_t *n)
 Get the version. More...
 
gchar * nvti_name (const nvti_t *n)
 Get the name. More...
 
gchar * nvti_copyright (const nvti_t *n)
 Get the copyright notice. More...
 
gchar * nvti_cve (const nvti_t *n)
 Get the CVE references. More...
 
gchar * nvti_bid (const nvti_t *n)
 Get the bid references. More...
 
gchar * nvti_xref (const nvti_t *n)
 Get the xref's. More...
 
gchar * nvti_tag (const nvti_t *n)
 Get the tag. More...
 
gchar * nvti_cvss_base (const nvti_t *n)
 Get the CVSS base. More...
 
gchar * nvti_dependencies (const nvti_t *n)
 Get the dependencies list. More...
 
gchar * nvti_required_keys (const nvti_t *n)
 Get the required keys list. More...
 
gchar * nvti_mandatory_keys (const nvti_t *n)
 Get the mandatory keys list. More...
 
gchar * nvti_excluded_keys (const nvti_t *n)
 Get the excluded keys list. More...
 
gchar * nvti_required_ports (const nvti_t *n)
 Get the required ports list. More...
 
gchar * nvti_required_udp_ports (const nvti_t *n)
 Get the required udp ports list. More...
 
gchar * nvti_family (const nvti_t *n)
 Get the family name. More...
 
guint nvti_pref_len (const nvti_t *n)
 Get the number of preferences of the NVT. More...
 
const nvtpref_tnvti_pref (const nvti_t *n, guint p)
 Get the n'th preferences of the NVT. More...
 
gint nvti_timeout (const nvti_t *n)
 Get the timeout for this NVT. More...
 
gint nvti_category (const nvti_t *n)
 Get the category for this NVT. More...
 
int nvti_set_oid (nvti_t *n, const gchar *oid)
 Set the OID of a NVT Info. More...
 
int nvti_set_version (nvti_t *n, const gchar *version)
 Set the version of a NVT. More...
 
int nvti_set_name (nvti_t *n, const gchar *name)
 Set the name of a NVT. More...
 
int nvti_set_copyright (nvti_t *n, const gchar *copyright)
 Set the copyright of a NVT. More...
 
int nvti_set_cve (nvti_t *n, const gchar *cve)
 Set the CVE references of a NVT. More...
 
int nvti_set_bid (nvti_t *n, const gchar *bid)
 Set the bid references of a NVT. More...
 
int nvti_set_xref (nvti_t *n, const gchar *xref)
 Set the xrefs of a NVT. More...
 
int nvti_set_tag (nvti_t *n, const gchar *tag)
 Set the tags of a NVT. More...
 
int nvti_set_cvss_base (nvti_t *n, const gchar *cvss_base)
 Set the CVSS base of an NVT. More...
 
int nvti_set_dependencies (nvti_t *n, const gchar *dependencies)
 Set the dependencies of a NVT. More...
 
int nvti_set_required_keys (nvti_t *n, const gchar *required_keys)
 Set the required keys of a NVT. More...
 
int nvti_set_mandatory_keys (nvti_t *n, const gchar *mandatory_keys)
 Set the mandatory keys of a NVT. More...
 
int nvti_set_excluded_keys (nvti_t *n, const gchar *excluded_keys)
 Set the excluded keys of a NVT. More...
 
int nvti_set_required_ports (nvti_t *n, const gchar *required_ports)
 Set the required ports of a NVT. More...
 
int nvti_set_required_udp_ports (nvti_t *n, const gchar *required_udp_ports)
 Set the required udp ports of a NVT. More...
 
int nvti_set_family (nvti_t *n, const gchar *family)
 Set the family of a NVT. More...
 
int nvti_set_timeout (nvti_t *n, const gint timeout)
 Set the timout of a NVT Info. More...
 
int nvti_set_category (nvti_t *n, const gint category)
 Set the category type of a NVT Info. More...
 
int nvti_add_cve (nvti_t *n, const gchar *cve_id)
 Add a single CVE ID of a NVT. More...
 
int nvti_add_bid (nvti_t *n, const gchar *bid_id)
 Add a single BID ID of a NVT. More...
 
int nvti_add_required_keys (nvti_t *n, const gchar *key)
 Add a required key of a NVT. More...
 
int nvti_add_mandatory_keys (nvti_t *n, const gchar *key)
 Add a mandatory key of a NVT. More...
 
int nvti_add_excluded_keys (nvti_t *n, const gchar *key)
 Add a excluded key of a NVT. More...
 
int nvti_add_required_ports (nvti_t *n, const gchar *port)
 Add a required port of a NVT. More...
 
int nvti_add_required_udp_ports (nvti_t *n, const gchar *port)
 Add a required udp port of a NVT. More...
 
int nvti_add_pref (nvti_t *n, nvtpref_t *np)
 Add a preference to the NVT Info. More...
 
nvti_tnvti_from_keyfile (const gchar *fn)
 Read NVT Info from a keyfile. More...
 
int nvti_to_keyfile (const nvti_t *n, const char *src, const gchar *fn)
 Store NVT Info into a keyfile. More...
 
nvtis_tnvtis_new (void)
 Make a collection of NVT Infos. More...
 
void nvtis_free (nvtis_t *nvtis)
 Free a collection of NVT Infos. More...
 
void nvtis_add (nvtis_t *nvtis, nvti_t *nvti)
 Add an NVT Info to a collection of NVT Infos. More...
 
nvti_tnvtis_lookup (nvtis_t *nvtis, const char *oid)
 Add an NVT Info to a collection of NVT Infos. More...
 

Detailed Description

Implementation of API to handle NVT Info datasets.

This file contains all methods to handle NVT Information datasets (nvti_t).

The module consequently uses glib datatypes and api for memory management etc.

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "lib nvti"

Function Documentation

◆ nvti_add_bid()

int nvti_add_bid ( nvti_t n,
const gchar *  bid_id 
)

Add a single BID ID of a NVT.

Parameters
nThe NVT Info structure.
bid_idThe BID ID to add. A copy will be created from this.
Returns
0 for success. 1 if n was NULL. 2 if bid_id was NULL.

◆ nvti_add_cve()

int nvti_add_cve ( nvti_t n,
const gchar *  cve_id 
)

Add a single CVE ID of a NVT.

Parameters
nThe NVT Info structure.
cve_idThe CVE ID to add. A copy will be created from this.
Returns
0 for success. 1 if n was NULL, 2 if cve_id was NULL.

◆ nvti_add_excluded_keys()

int nvti_add_excluded_keys ( nvti_t n,
const gchar *  key 
)

Add a excluded key of a NVT.

Parameters
nThe NVT Info structure.
keyThe excluded key to add. A copy will be created from this.
Returns
0 for success. 1 if n was NULL. 2 if key was NULL.

◆ nvti_add_mandatory_keys()

int nvti_add_mandatory_keys ( nvti_t n,
const gchar *  key 
)

Add a mandatory key of a NVT.

Parameters
nThe NVT Info structure.
keyThe mandatory key to add. A copy will be created from this.
Returns
0 for success. 1 if n was NULL. 2 if key was NULL.

◆ nvti_add_pref()

int nvti_add_pref ( nvti_t n,
nvtpref_t np 
)

Add a preference to the NVT Info.

Parameters
nThe NVT Info structure.
npThe NVT preference to add.
Returns
0 for success. Anything else indicates an error.

◆ nvti_add_required_keys()

int nvti_add_required_keys ( nvti_t n,
const gchar *  key 
)

Add a required key of a NVT.

Parameters
nThe NVT Info structure.
keyThe required key to add. A copy will be created from this.
Returns
0 for success. 1 if n was NULL. 2 if key was NULL.

◆ nvti_add_required_ports()

int nvti_add_required_ports ( nvti_t n,
const gchar *  port 
)

Add a required port of a NVT.

Parameters
nThe NVT Info structure.
portThe required port to add. A copy will be created from this.
Returns
0 for success. 1 if n was NULL. 2 if port was NULL.

◆ 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.

Parameters
nThe NVT Info structure.
portThe required udp port to add. A copy will be created from this.
Returns
0 for success. 1 if n was NULL. 2 if port was NULL.

◆ nvti_bid()

gchar* nvti_bid ( const nvti_t n)

Get the bid references.

Parameters
nThe NVT Info structure of which the name should be returned.
Returns
The bid list as string. Don't free this.

◆ nvti_category()

gint nvti_category ( const nvti_t n)

Get the category for this NVT.

Parameters
nThe NVT Info structure of which the category should be returned.
Returns
The category integer code. A value <= 0 indicates it is not set.

◆ nvti_copyright()

gchar* nvti_copyright ( const nvti_t n)

Get the copyright notice.

Parameters
nThe NVT Info structure of which the name should be returned.
Returns
The copyright string. Don't free this.

◆ nvti_cve()

gchar* nvti_cve ( const nvti_t n)

Get the CVE references.

Parameters
nThe NVT Info structure of which the name should be returned.
Returns
The CVE list as string. Don't free this.

◆ nvti_cvss_base()

gchar* nvti_cvss_base ( const nvti_t n)

Get the CVSS base.

Parameters
nThe NVT Info structure of which the CVSS base should be returned.
Returns
The cvss_base string. Don't free this.

◆ nvti_dependencies()

gchar* nvti_dependencies ( const nvti_t n)

Get the dependencies list.

Parameters
nThe NVT Info structure of which the name should be returned.
Returns
The dependencies string. Don't free this.

◆ nvti_excluded_keys()

gchar* nvti_excluded_keys ( const nvti_t n)

Get the excluded keys list.

Parameters
nThe NVT Info structure of which the name should be returned.
Returns
The excluded keys string. Don't free this.

◆ nvti_family()

gchar* nvti_family ( const nvti_t n)

Get the family name.

Parameters
nThe NVT Info structure of which the name should be returned.
Returns
The family name string. Don't free this.

◆ nvti_free()

void nvti_free ( nvti_t n)

Free memory of a nvti structure.

Parameters
nThe structure to be freed.

◆ nvti_from_keyfile()

nvti_t* nvti_from_keyfile ( const gchar *  fn)

Read NVT Info from a keyfile.

Parameters
fnThe filename to read from.
Returns
A newly allocated nvti_t object. The nvti_t needs to be freed with nvti_free().

◆ nvti_mandatory_keys()

gchar* nvti_mandatory_keys ( const nvti_t n)

Get the mandatory keys list.

Parameters
nThe NVT Info structure of which the name should be returned.
Returns
The mandatory keys string. Don't free this.

◆ nvti_name()

gchar* nvti_name ( const nvti_t n)

Get the name.

Parameters
nThe NVT Info structure of which the name should be returned.
Returns
The name string. Don't free this.

◆ nvti_new()

nvti_t* nvti_new ( void  )

Create a new (empty) nvti structure.

Returns
NULL in case the memory could not be allocated. Else an empty nvti structure which needs to be released using nvti_free . The whole struct is initalized with 0's.

◆ nvti_oid()

gchar* nvti_oid ( const nvti_t n)

Get the OID string.

Parameters
nThe NVT Info structure of which the OID should be returned.
Returns
The OID string. Don't free this.

◆ nvti_pref()

const nvtpref_t* nvti_pref ( const nvti_t n,
guint  p 
)

Get the n'th preferences of the NVT.

Parameters
nThe NVT Info structure.
pThe position of the preference to return.
Returns
The number of preferences. NULL if

◆ nvti_pref_len()

guint nvti_pref_len ( const nvti_t n)

Get the number of preferences of the NVT.

Parameters
nThe NVT Info structure.
Returns
The number of preferences.

◆ nvti_required_keys()

gchar* nvti_required_keys ( const nvti_t n)

Get the required keys list.

Parameters
nThe NVT Info structure of which the name should be returned.
Returns
The required keys string. Don't free this.

◆ nvti_required_ports()

gchar* nvti_required_ports ( const nvti_t n)

Get the required ports list.

Parameters
nThe NVT Info structure of which the name should be returned.
Returns
The required ports string. Don't free this.

◆ nvti_required_udp_ports()

gchar* nvti_required_udp_ports ( const nvti_t n)

Get the required udp ports list.

Parameters
nThe NVT Info structure of which the name should be returned.
Returns
The required udp ports string. Don't free this.

◆ nvti_set_bid()

int nvti_set_bid ( nvti_t n,
const gchar *  bid 
)

Set the bid references of a NVT.

Parameters
nThe NVT Info structure.
bidThe bid to set. A copy will be created from this.
Returns
0 for success. Anything else indicates an error.

◆ nvti_set_category()

int nvti_set_category ( nvti_t n,
const gint  category 
)

Set the category type of a NVT Info.

Parameters
nThe NVT Info structure.
categoryThe category to set. Values <= 0 will indicate it is not set.
Returns
0 for success. Anything else indicates an error.

◆ nvti_set_copyright()

int nvti_set_copyright ( nvti_t n,
const gchar *  copyright 
)

Set the copyright of a NVT.

Parameters
nThe NVT Info structure.
copyrightThe copyright to set. A copy will be created from this.
Returns
0 for success. Anything else indicates an error.

◆ nvti_set_cve()

int nvti_set_cve ( nvti_t n,
const gchar *  cve 
)

Set the CVE references of a NVT.

Parameters
nThe NVT Info structure.
cveThe cve list to set. A copy will be created from this.
Returns
0 for success. Anything else indicates an error.

◆ nvti_set_cvss_base()

int nvti_set_cvss_base ( nvti_t n,
const gchar *  cvss_base 
)

Set the CVSS base of an NVT.

Parameters
nThe NVT Info structure.
cvss_baseThe CVSS base to set. A copy will be created from this.
Returns
0 for success. Anything else indicates an error.

◆ nvti_set_dependencies()

int nvti_set_dependencies ( nvti_t n,
const gchar *  dependencies 
)

Set the dependencies of a NVT.

Parameters
nThe NVT Info structure.
dependenciesThe dependencies to set. A copy will be created from this.
Returns
0 for success. Anything else indicates an error.

◆ nvti_set_excluded_keys()

int nvti_set_excluded_keys ( nvti_t n,
const gchar *  excluded_keys 
)

Set the excluded keys of a NVT.

Parameters
nThe NVT Info structure.
excluded_keysThe excluded keys to set. A copy will be created from this.
Returns
0 for success. Anything else indicates an error.

◆ nvti_set_family()

int nvti_set_family ( nvti_t n,
const gchar *  family 
)

Set the family of a NVT.

Parameters
nThe NVT Info structure.
familyThe family to set. A copy will be created from this.
Returns
0 for success. Anything else indicates an error.

◆ nvti_set_mandatory_keys()

int nvti_set_mandatory_keys ( nvti_t n,
const gchar *  mandatory_keys 
)

Set the mandatory keys of a NVT.

Parameters
nThe NVT Info structure.
mandatory_keysThe mandatory keys to set. A copy will be created from this.
Returns
0 for success. Anything else indicates an error.

◆ nvti_set_name()

int nvti_set_name ( nvti_t n,
const gchar *  name 
)

Set the name of a NVT.

Parameters
nThe NVT Info structure.
nameThe name to set. A copy will be created from this.
Returns
0 for success. Anything else indicates an error.

◆ nvti_set_oid()

int nvti_set_oid ( nvti_t n,
const gchar *  oid 
)

Set the OID of a NVT Info.

Parameters
nThe NVT Info structure.
oidThe OID to set. A copy will be created from this.
Returns
0 for success. Anything else indicates an error.

◆ nvti_set_required_keys()

int nvti_set_required_keys ( nvti_t n,
const gchar *  required_keys 
)

Set the required keys of a NVT.

Parameters
nThe NVT Info structure.
required_keysThe required keys to set. A copy will be created from this.
Returns
0 for success. Anything else indicates an error.

◆ nvti_set_required_ports()

int nvti_set_required_ports ( nvti_t n,
const gchar *  required_ports 
)

Set the required ports of a NVT.

Parameters
nThe NVT Info structure.
required_portsThe required ports to set. A copy will be created from this.
Returns
0 for success. Anything else indicates an error.

◆ 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.

Parameters
nThe NVT Info structure.
required_udp_portsThe required udp ports to set. A copy will be created from this.
Returns
0 for success. Anything else indicates an error.

◆ nvti_set_tag()

int nvti_set_tag ( nvti_t n,
const gchar *  tag 
)

Set the tags of a NVT.

Parameters
nThe NVT Info structure.
tagThe tags to set. A copy will be created from this.
Returns
0 for success. Anything else indicates an error.

◆ nvti_set_timeout()

int nvti_set_timeout ( nvti_t n,
const gint  timeout 
)

Set the timout of a NVT Info.

Parameters
nThe NVT Info structure.
timeoutThe timeout to set. Values <= 0 will indicate it is not set.
Returns
0 for success. Anything else indicates an error.

◆ nvti_set_version()

int nvti_set_version ( nvti_t n,
const gchar *  version 
)

Set the version of a NVT.

Parameters
nThe NVT Info structure.
versionThe version to set. A copy will be created from this.
Returns
0 for success. Anything else indicates an error.

◆ nvti_set_xref()

int nvti_set_xref ( nvti_t n,
const gchar *  xref 
)

Set the xrefs of a NVT.

Parameters
nThe NVT Info structure.
xrefThe xrefs to set. A copy will be created from this.
Returns
0 for success. Anything else indicates an error.

◆ nvti_tag()

gchar* nvti_tag ( const nvti_t n)

Get the tag.

Parameters
nThe NVT Info structure of which the name should be returned.
Returns
The tags string. Don't free this.

◆ nvti_timeout()

gint nvti_timeout ( const nvti_t n)

Get the timeout for this NVT.

Parameters
nThe NVT Info structure of which the timeout should be returned.
Returns
The timeout integer number. A value <= 0 indicates it is not set.

◆ nvti_to_keyfile()

int nvti_to_keyfile ( const nvti_t n,
const char *  src,
const gchar *  fn 
)

Store NVT Info into a keyfile.

Parameters
nThe NVT Info object to store.
fnThe filename to write to.
Returns
0 on success.
Todo:
Anything else indicates an error.

◆ nvti_version()

gchar* nvti_version ( const nvti_t n)

Get the version.

Parameters
nThe NVT Info structure of which the OID should be returned.
Returns
The version string. Don't free this.

◆ nvti_xref()

gchar* nvti_xref ( const nvti_t n)

Get the xref's.

Parameters
nThe NVT Info structure of which the name should be returned.
Returns
The xref string. Don't free this.

◆ nvtis_add()

void nvtis_add ( nvtis_t nvtis,
nvti_t nvti 
)

Add an NVT Info to a collection of NVT Infos.

Parameters
nvtisThe collection of NVT Infos.
nvtiThe NVT Info to add.

◆ nvtis_free()

void nvtis_free ( nvtis_t nvtis)

Free a collection of NVT Infos.

Parameters
nvtisThe collection of NVT Infos.

◆ nvtis_lookup()

nvti_t* nvtis_lookup ( nvtis_t nvtis,
const char *  oid 
)

Add an NVT Info to a collection of NVT Infos.

Parameters
nvtisThe collection of NVT Infos.
oidThe OID of the NVT.
Returns
The NVT Info, if found, else NULL.

◆ nvtis_new()

nvtis_t* nvtis_new ( void  )

Make a collection of NVT Infos.

◆ nvtpref_default()

gchar* nvtpref_default ( const nvtpref_t np)

Get the Default of a NVT Preference.

Parameters
npThe NVT Pref structure of which the Default should be returned.
Returns
The default string. Don't free this.

◆ nvtpref_free()

void nvtpref_free ( nvtpref_t np)

Free memory of a nvtpref structure.

Parameters
npThe structure to be freed.

◆ nvtpref_name()

gchar* nvtpref_name ( const nvtpref_t np)

Get the Name of a NVT Preference.

Parameters
npThe NVT Pref structure of which the Name should be returned.
Returns
The name string. Don't free this.

◆ nvtpref_new()

nvtpref_t* nvtpref_new ( gchar *  name,
gchar *  type,
gchar *  dflt 
)

Create a new nvtpref structure filled with the given values.

Parameters
nameThe name to be set. A copy will created of this.
typeThe type to be set. A copy will created of this.
dfltThe default to be set. A copy will created of this.
Returns
NULL in case the memory could not be allocated. Else a nvtpref structure which needs to be released using nvtpref_free .

◆ nvtpref_type()

gchar* nvtpref_type ( const nvtpref_t np)

Get the Type of a NVT Preference.

Parameters
npThe NVT Pref structure of which the Type should be returned.
Returns
The type string. Don't free this.