Greenbone Vulnerability Manager  8.0.1~git
Macros | Functions | Variables
manage_sql_nvts.c File Reference

GVM management layer: NVTs. More...

#include "manage_sql_nvts.h"
#include "manage_sql.h"
#include "sql.h"
#include "utils.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>

Macros

#define _GNU_SOURCE
 Enable extra GNU functions.
 
#define G_LOG_DOMAIN   "md manage"
 GLib log domain.
 
#define CHUNK_SIZE   100
 Size of chunk for insert_nvts_list.
 

Functions

static void refresh_nvt_cves ()
 Refresh nvt_cves table. More...
 
void check_db_nvts ()
 Ensures the sanity of nvts cache in DB.
 
char * manage_nvt_name (nvt_t nvt)
 Get the name of an NVT. More...
 
char * nvt_oid (const char *name)
 Guess the OID of an NVT given a name. More...
 
char * nvts_feed_version ()
 Return feed version of the plugins in the plugin cache. More...
 
void set_nvts_feed_version (const char *feed_version)
 Set the feed version of the plugins in the plugin cache. More...
 
gboolean find_nvt (const char *oid, nvt_t *nvt)
 Find an NVT given an identifier. More...
 
static nvt_t make_nvt_from_nvti (const nvti_t *nvti)
 Make an nvt from an nvti. More...
 
int init_nvt_info_iterator (iterator_t *iterator, get_data_t *get, const char *name)
 Initialise an NVT iterator. More...
 
static gchar * nvt_iterator_columns ()
 Get NVT iterator SELECT columns. More...
 
static gchar * nvt_iterator_columns_nvts ()
 Get NVT iterator SELECT columns. More...
 
int nvt_info_count (const get_data_t *get)
 Count number of nvt. More...
 
static gchar * select_config_nvts (const config_t config, const char *family, int ascending, const char *sort_field)
 Return SQL for selecting NVT's of a config from one family. More...
 
void init_nvt_iterator (iterator_t *iterator, nvt_t nvt, config_t config, const char *family, const char *category, int ascending, const char *sort_field)
 Initialise an NVT iterator. More...
 
void init_cve_nvt_iterator (iterator_t *iterator, const char *cve, int ascending, const char *sort_field)
 Initialise an NVT iterator, for NVTs of a certain CVE. More...
 
int nvt_iterator_category (iterator_t *iterator)
 Get the category from an NVT iterator. More...
 
char * nvt_default_timeout (const char *oid)
 Get the default timeout of an NVT. More...
 
int family_nvt_count (const char *family)
 Get the number of NVTs in one or all families. More...
 
int family_count ()
 Get the number of families. More...
 
static void insert_nvt_from_nvti (gpointer nvti, gpointer dummy)
 Insert an NVT from an nvti structure. More...
 
static void insert_nvt_preference (gpointer nvt_preference, gpointer dummy)
 Insert a NVT preferences. More...
 
static void insert_nvts_list (GList *nvts_list)
 Inserts NVTs in DB from a list of nvti_t structures. More...
 
static void insert_nvt_preferences_list (GList *nvt_preferences_list)
 Inserts NVT preferences in DB from a list of nvt_preference_t structures. More...
 
static void check_for_new_nvts ()
 Check for new NVTs after an update.
 
static void check_for_updated_nvts ()
 Check for updated NVTS after an update.
 
void manage_complete_nvt_cache_update (GList *nvts_list, GList *nvt_preferences_list)
 Complete an update of the NVT cache. More...
 
void manage_sync_nvts (int(*fork_update_nvt_cache)())
 Sync NVTs if newer NVTs are available. More...
 

Variables

static int chunk_count = 0
 Counter for chunking in insert_nvts_list.
 

Detailed Description

GVM management layer: NVTs.

The NVT parts of the GVM management layer.

Function Documentation

◆ family_count()

int family_count ( )

Get the number of families.

Returns
Total number of families.

◆ family_nvt_count()

int family_nvt_count ( const char *  family)

Get the number of NVTs in one or all families.

Parameters
[in]familyFamily name. NULL for all families.
Returns
Number of NVTs in family, or total number of nvts.

◆ find_nvt()

gboolean find_nvt ( const char *  oid,
nvt_t *  nvt 
)

Find an NVT given an identifier.

Parameters
[in]oidAn NVT identifier.
[out]nvtNVT return, 0 if successfully failed to find task.
Returns
FALSE on success (including if failed to find NVT), TRUE on error.

◆ init_cve_nvt_iterator()

void init_cve_nvt_iterator ( iterator_t iterator,
const char *  cve,
int  ascending,
const char *  sort_field 
)

Initialise an NVT iterator, for NVTs of a certain CVE.

Parameters
[in]iteratorIterator.
[in]cveCVE name.
[in]ascendingWhether to sort ascending or descending.
[in]sort_fieldField to sort on, or NULL for "id".

◆ init_nvt_info_iterator()

int init_nvt_info_iterator ( iterator_t iterator,
get_data_t get,
const char *  name 
)

Initialise an NVT iterator.

Parameters
[in]iteratorIterator.
[in]getGET data.
[in]nameName of the info
Returns
0 success, 1 failed to find NVT, 2 failed to find filter, -1 error.

◆ init_nvt_iterator()

void init_nvt_iterator ( iterator_t iterator,
nvt_t  nvt,
config_t  config,
const char *  family,
const char *  category,
int  ascending,
const char *  sort_field 
)

Initialise an NVT iterator.

Parameters
[in]iteratorIterator.
[in]nvtNVT to iterate over, all if 0.
[in]configConfig to limit selection to. NULL for all NVTs. Overridden by
  • nvt.
[in]familyFamily to limit selection to. NULL for all NVTs. Overridden by
  • config.
[in]categoryCategory to limit selection to. NULL for all.
[in]ascendingWhether to sort ascending or descending.
[in]sort_fieldField to sort on, or NULL for "id".

◆ insert_nvt_from_nvti()

static void insert_nvt_from_nvti ( gpointer  nvti,
gpointer  dummy 
)
static

Insert an NVT from an nvti structure.

Parameters
[in]nvtinvti_t to insert in nvts table.
[in]dummyDummy arg for g_list_foreach.

◆ insert_nvt_preference()

static void insert_nvt_preference ( gpointer  nvt_preference,
gpointer  dummy 
)
static

Insert a NVT preferences.

Parameters
[in]nvt_preferencePreference.
[in]dummyDummy arg for g_list_foreach.

◆ insert_nvt_preferences_list()

static void insert_nvt_preferences_list ( GList *  nvt_preferences_list)
static

Inserts NVT preferences in DB from a list of nvt_preference_t structures.

Parameters
[in]nvt_preferences_listList of nvts to be inserted.

◆ insert_nvts_list()

static void insert_nvts_list ( GList *  nvts_list)
static

Inserts NVTs in DB from a list of nvti_t structures.

Parameters
[in]nvts_listList of nvts to be inserted.

◆ make_nvt_from_nvti()

static nvt_t make_nvt_from_nvti ( const nvti_t *  nvti)
static

Make an nvt from an nvti.

Parameters
[in]nvtiNVTI.
Returns
An NVT.

◆ manage_complete_nvt_cache_update()

void manage_complete_nvt_cache_update ( GList *  nvts_list,
GList *  nvt_preferences_list 
)

Complete an update of the NVT cache.

Parameters
[in]nvts_listList of nvti_t to insert.
[in]nvt_preferences_listList of preference_t to insert.

◆ manage_nvt_name()

char* manage_nvt_name ( nvt_t  nvt)

Get the name of an NVT.

Parameters
[in]nvtNVT.
Returns
Freshly allocated name of NVT if possible, else NULL.

◆ manage_sync_nvts()

void manage_sync_nvts ( int(*)()  fork_update_nvt_cache)

Sync NVTs if newer NVTs are available.

Parameters
[in]fork_update_nvt_cacheFunction to do the update.

◆ nvt_default_timeout()

char* nvt_default_timeout ( const char *  oid)

Get the default timeout of an NVT.

Parameters
[in]oidThe OID of the NVT to get the timeout of.
Returns
Newly allocated string of the timeout in seconds or NULL.

◆ nvt_info_count()

int nvt_info_count ( const get_data_t get)

Count number of nvt.

Parameters
[in]getGET params.
Returns
Total number of cpes in filtered set.

◆ nvt_iterator_category()

int nvt_iterator_category ( iterator_t iterator)

Get the category from an NVT iterator.

Parameters
[in]iteratorIterator.
Returns
Category.

◆ nvt_iterator_columns()

static gchar* nvt_iterator_columns ( )
static

Get NVT iterator SELECT columns.

Returns
SELECT columns

◆ nvt_iterator_columns_nvts()

static gchar* nvt_iterator_columns_nvts ( )
static

Get NVT iterator SELECT columns.

Returns
SELECT columns

◆ nvt_oid()

char* nvt_oid ( const char *  name)

Guess the OID of an NVT given a name.

Parameters
[in]nameName of NVT.
Returns
OID of NVT if possible, else NULL.

◆ nvts_feed_version()

char* nvts_feed_version ( )

Return feed version of the plugins in the plugin cache.

Returns
Feed version of plugins if the plugins are cached, else NULL.

◆ refresh_nvt_cves()

static void refresh_nvt_cves ( )
static

Refresh nvt_cves table.

Caller must organise transaction.

◆ select_config_nvts()

static gchar* select_config_nvts ( const config_t  config,
const char *  family,
int  ascending,
const char *  sort_field 
)
static

Return SQL for selecting NVT's of a config from one family.

Parameters
[in]configConfig.
[in]familyFamily to limit selection to.
[in]ascendingWhether to sort ascending or descending.
[in]sort_fieldField to sort on, or NULL for "nvts.id".
Returns
Freshly allocated SELECT statement on success, or NULL on error.

◆ set_nvts_feed_version()

void set_nvts_feed_version ( const char *  feed_version)

Set the feed version of the plugins in the plugin cache.

Parameters
[in]feed_versionNew feed version.

Also queue an update to the nvti cache.