Greenbone Vulnerability Manager  9.0.1
Macros | Functions
manage_sql_configs.c File Reference

GVM management layer: Config SQL. More...

#include "manage_configs.h"
#include "manage_acl.h"
#include "manage_sql.h"
#include "manage_sql_configs.h"
#include "manage_sql_nvts.h"
#include "sql.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <gvm/util/uuidutils.h>

Macros

#define G_LOG_DOMAIN   "md manage"
 GLib log domain.
 

Functions

static int switch_representation (config_t config, int constraining)
 Switch between constraining and generating representation. More...
 
static void nvt_selector_add (const char *quoted_selector, const char *quoted_family_or_nvt, const char *quoted_family, int exclude)
 Add a selector to an NVT selector. More...
 
static void nvt_selector_remove_selector (const char *quoted_selector, const char *family_or_nvt, int type)
 Remove all selectors of a certain type from an NVT selector. More...
 
static void update_config_caches (config_t config)
 Update the cached count and growing information in every config. More...
 
static int nvt_selector_families_growing (const char *selector)
 Get the family growth status of an NVT selector. More...
 
static int nvt_selector_nvts_growing_2 (const char *quoted_selector, int families_growing)
 Get the NVT growth status of an NVT selector. More...
 
static int insert_nvt_selectors (const char *quoted_name, const array_t *selectors)
 Insert NVT selectors. More...
 
static int member (GPtrArray *array, const char *string)
 Test whether a string equal to a given string exists in an array. More...
 
int nvt_selector_family_count (const char *quoted_selector, int families_growing)
 Get the number of families selected by an NVT selector. More...
 
int config_nvts_growing (config_t config)
 Get the NVT growth status of a config. More...
 
int config_families_growing (config_t config)
 Get the family growth status of a config. More...
 
void init_nvt_selector_iterator (iterator_t *iterator, const char *selector, config_t config, int type)
 Initialise an NVT selector iterator. More...
 
int nvt_selector_iterator_include (iterator_t *iterator)
 Get whether the selector rule is an include rule. More...
 
int nvt_selector_iterator_type (iterator_t *iterator)
 Get the type from an NVT selector. More...
 
void init_family_iterator (iterator_t *iterator, int all, const char *selector, int ascending)
 Initialise an NVT selector family iterator. More...
 
int nvt_selector_family_growing (const char *selector, const char *family, int all)
 Get whether an NVT selector family is growing. More...
 
int nvt_selector_nvt_count (const char *selector, const char *family, int growing)
 Get the number of NVTs selected by an NVT selector. More...
 
static void nvt_selector_remove (const char *quoted_selector, const char *quoted_family, int type)
 Remove all selectors of a certain family from an NVT selector. More...
 
static void nvt_selector_set_family (const char *quoted_selector, const char *family_or_nvt, int type, const char *family)
 Set the family of an NVT selector. More...
 
static int family_is_selected (const char *quoted_selector, const char *quoted_family)
 Check whether a family is selected. More...
 
static int nvt_selector_has (const char *quoted_selector, const char *family_or_nvt, int type, int exclude)
 Check whether an NVT selector has a particular selector. More...
 
int manage_set_config_families (const gchar *config_id, GPtrArray *growing_all_families, GPtrArray *static_all_families, GPtrArray *growing_families, int grow_families)
 Refresh NVT selection of a config from given families. More...
 
static int config_update_nvt_family (resource_t config, const char *oid, const char *old_family, const char *new_family)
 Change the family of an NVT in a config. More...
 
static int update_nvt_family (const char *oid, const char *old_family, const char *new_family)
 Change the family of an NVT in all configs. More...
 
int check_config_families ()
 Ensure that all configs refer to the right NVT families. More...
 
void manage_nvt_preference_add (const char *name, const char *value)
 Add/replace an NVT preference. More...
 
void manage_nvt_preferences_enable ()
 Enable the NVT preferences.
 
void init_nvt_preference_iterator (iterator_t *iterator, const char *oid)
 Initialise an NVT preference iterator. More...
 
char * nvt_preference_iterator_real_name (iterator_t *iterator)
 Get the real name from an NVT preference iterator. More...
 
char * nvt_preference_iterator_type (iterator_t *iterator)
 Get the type from an NVT preference iterator. More...
 
char * nvt_preference_iterator_oid (iterator_t *iterator)
 Get the NVT from an NVT preference iterator. More...
 
char * nvt_preference_iterator_id (iterator_t *iterator)
 Get the ID from an NVT preference iterator. More...
 
char * nvt_preference_iterator_config_value (iterator_t *iterator, config_t config)
 Get the config value from an NVT preference iterator. More...
 
int nvt_preference_count (const char *oid)
 Get the number preferences available for an NVT. More...
 
char * task_preference_value (task_t task, const char *name)
 Get the value of a task preference. More...
 
int set_task_preferences (task_t task, array_t *preferences)
 Set the preferences of a task. More...
 
gboolean find_config_with_permission (const char *uuid, config_t *config, const char *permission)
 Find a config for a set of permissions, given a UUID. More...
 
preference_tget_nvt_preference_by_id (const char *nvt_oid, const char *find_id, const char *check_name, const char *check_type, const char *value)
 Gets an NVT preference by id or by name. More...
 
static int config_insert_preferences (config_t config, const array_t *preferences, const char *config_type)
 Insert preferences into a config. More...
 
int create_config (const char *proposed_name, const char *comment, const array_t *selectors, const array_t *preferences, const char *config_type, const char *usage_type, config_t *config, char **name)
 Create a config. More...
 
static GSList * get_scanner_params (scanner_t scanner)
 Get list of OSP Scanner parameters. More...
 
static int insert_osp_parameter (osp_param_t *param, config_t config)
 Insert an OSP parameter into a config if not already present. More...
 
gchar * configs_extra_where (const char *usage_type)
 Generate an extra WHERE clause for selecting configs. More...
 
int create_config_from_scanner (const char *scanner_id, const char *name, const char *comment, const char *usage_type, char **uuid)
 Create a config from an OSP scanner. More...
 
char * config_uuid (config_t config)
 Return the UUID of a config. More...
 
int config_type (config_t config)
 Return the type of a config. More...
 
static scanner_t config_scanner (config_t config)
 Return the scanner associated with a config, if any. More...
 
char * config_nvt_timeout (config_t config, const char *oid)
 Get the timeout value for an NVT in a config. More...
 
int create_task_check_config_scanner (config_t config, scanner_t scanner)
 Check scanner and config values match for a task. More...
 
int modify_task_check_config_scanner (task_t task, const char *config_id, const char *scanner_id)
 Check scanner and config values match for a task. More...
 
int copy_config (const char *name, const char *comment, const char *config_id, const char *usage_type, config_t *new_config)
 Create a config from an existing config. More...
 
int delete_config (const char *config_id, int ultimate)
 Delete a config. More...
 
static void update_config_params (config_t config, const char *config_id, GSList *params)
 Update a config with a list of parameters. More...
 
int sync_config (const char *config_id)
 Synchronize a config. More...
 
int config_count (const get_data_t *get)
 Count the number of scan configs. More...
 
void init_user_config_iterator (iterator_t *iterator, config_t config, int trash, int ascending, const char *sort_field)
 Initialise a config iterator, limited to user's configs. More...
 
int init_config_iterator (iterator_t *iterator, const get_data_t *get)
 Initialise a scan config iterator. More...
 
int config_iterator_family_count (iterator_t *iterator)
 Get the family count from a config iterator. More...
 
int config_iterator_nvt_count (iterator_t *iterator)
 Get the nvt count from a config iterator. More...
 
int config_iterator_families_growing (iterator_t *iterator)
 Get the families growing state from a config iterator. More...
 
int config_iterator_nvts_growing (iterator_t *iterator)
 Get the NVTs growing state from a config iterator. More...
 
int config_iterator_type (iterator_t *iterator)
 Get the type from a config iterator. More...
 
scanner_t config_iterator_scanner (iterator_t *iterator)
 Get the scanner from a config iterator. More...
 
int config_iterator_scanner_trash (iterator_t *iterator)
 Get whether scanner is in trash from a config iterator. More...
 
int config_in_use (config_t config)
 Return whether a config is referenced by a task. More...
 
int config_writable (config_t config)
 Return whether a config can be modified. More...
 
int trash_config_in_use (config_t config)
 Return whether a trashcan config is referenced by a task. More...
 
int trash_config_writable (config_t config)
 Return whether a trashcan config is writable. More...
 
int trash_config_readable_uuid (const gchar *config_id)
 Return whether a trashcan config is readable. More...
 
void init_config_preference_iterator (iterator_t *iterator, config_t config)
 Initialise a preference iterator. More...
 
void init_preference_iterator (iterator_t *iterator, config_t config, const char *section)
 Initialise a config preference iterator, with defaults. More...
 
char * config_nvt_selector (config_t config)
 Return the NVT selector associated with a config. More...
 
int manage_set_config_preference (const gchar *config_id, const char *nvt, const char *name, const char *value_64)
 Set a preference of a config. More...
 
int manage_set_config (const gchar *config_id, const char *name, const char *comment, const char *scanner_id)
 Set the name, comment and scanner of a config. More...
 
int manage_set_config_nvts (const gchar *config_id, const char *family, GPtrArray *selected_nvts)
 Set the NVT's selected for a single family of a config. More...
 
void init_config_task_iterator (iterator_t *iterator, config_t config, int ascending)
 Initialise a config task iterator. More...
 
int config_task_iterator_readable (iterator_t *iterator)
 Get the read permission status from a GET iterator. More...
 
void init_config_timeout_iterator (iterator_t *iterator, config_t config)
 Initialise a config timeout iterator. More...
 
void update_config_preference (const char *config_id, const char *type, const char *preference_name, const char *new_value, gboolean insert)
 Update or optionally insert a NVT preference. More...
 
static void update_config_cache (iterator_t *configs)
 Update the cached count and growing information in a config. More...
 
void update_all_config_caches ()
 Update count and growing info in every config across all users. More...
 
void update_config_cache_init (const char *uuid)
 Update count and growing info in config, without checking user. More...
 

Detailed Description

GVM management layer: Config SQL.

The Config SQL for the GVM management layer.

Function Documentation

◆ check_config_families()

int check_config_families ( )

Ensure that all configs refer to the right NVT families.

When the family of an NVT is changed in the feed, then the config refers to the wrong family.

Returns
0 success, -1 error.

◆ config_count()

int config_count ( const get_data_t get)

Count the number of scan configs.

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

◆ config_families_growing()

int config_families_growing ( config_t  config)

Get the family growth status of a config.

Parameters
[in]configConfig.
Returns
1 growing, 0 static.

◆ config_in_use()

int config_in_use ( config_t  config)

Return whether a config is referenced by a task.

The predefined configs are always in use.

Parameters
[in]configConfig.
Returns
1 if in use, else 0.

◆ config_insert_preferences()

static int config_insert_preferences ( config_t  config,
const array_t *  preferences,
const char *  config_type 
)
static

Insert preferences into a config.

Parameters
[in]configConfig.
[in]preferencesPreferences.
[in]config_typeConfig type.
Returns
0 success, -1 error, -4 input error.

◆ config_iterator_families_growing()

int config_iterator_families_growing ( iterator_t iterator)

Get the families growing state from a config iterator.

Parameters
[in]iteratorIterator.
Returns
Families growing flag.

◆ config_iterator_family_count()

int config_iterator_family_count ( iterator_t iterator)

Get the family count from a config iterator.

Parameters
[in]iteratorIterator.
Returns
Family count if known, -1 else.

◆ config_iterator_nvt_count()

int config_iterator_nvt_count ( iterator_t iterator)

Get the nvt count from a config iterator.

Parameters
[in]iteratorIterator.
Returns
Nvt count if known, -1 else.

◆ config_iterator_nvts_growing()

int config_iterator_nvts_growing ( iterator_t iterator)

Get the NVTs growing state from a config iterator.

Parameters
[in]iteratorIterator.
Returns
NVTs growing flag.

◆ config_iterator_scanner()

scanner_t config_iterator_scanner ( iterator_t iterator)

Get the scanner from a config iterator.

Parameters
[in]iteratorIterator.
Returns
Scanner.

◆ config_iterator_scanner_trash()

int config_iterator_scanner_trash ( iterator_t iterator)

Get whether scanner is in trash from a config iterator.

Parameters
[in]iteratorIterator.
Returns
Whether Scanner is in trash.

◆ config_iterator_type()

int config_iterator_type ( iterator_t iterator)

Get the type from a config iterator.

Parameters
[in]iteratorIterator.
Returns
Config type.

◆ config_nvt_selector()

char* config_nvt_selector ( config_t  config)

Return the NVT selector associated with a config.

Parameters
[in]configConfig.
Returns
Name of NVT selector if config exists and NVT selector is set, else NULL.

◆ config_nvt_timeout()

char* config_nvt_timeout ( config_t  config,
const char *  oid 
)

Get the timeout value for an NVT in a config.

Parameters
[in]configConfig.
[in]oidID of NVT.
Returns
Newly allocated timeout if set for the NVT, else NULL.

◆ config_nvts_growing()

int config_nvts_growing ( config_t  config)

Get the NVT growth status of a config.

Todo:
Move these config functions to the config section.
Parameters
[in]configConfig.
Returns
1 growing, 0 static.

◆ config_scanner()

static scanner_t config_scanner ( config_t  config)
static

Return the scanner associated with a config, if any.

Parameters
[in]configConfig.
Returns
Scanner ID if found, 0 otherwise.

◆ config_task_iterator_readable()

int config_task_iterator_readable ( iterator_t iterator)

Get the read permission status from a GET iterator.

Parameters
[in]iteratorIterator.
Returns
1 if may read, else 0.

◆ config_type()

int config_type ( config_t  config)

Return the type of a config.

Parameters
[in]configConfig.
Returns
Config type, -1 if not found.

◆ config_update_nvt_family()

static int config_update_nvt_family ( resource_t  config,
const char *  oid,
const char *  old_family,
const char *  new_family 
)
static

Change the family of an NVT in a config.

Parameters
[in]configConfig.
[in]oidNVT OID.
[in]old_familyName of old family.
[in]new_familyName of new family.
Returns
0 success, -1 error.

◆ config_uuid()

char* config_uuid ( config_t  config)

Return the UUID of a config.

Parameters
[in]configConfig.
Returns
Newly allocated config uuid pointer.

◆ config_writable()

int config_writable ( config_t  config)

Return whether a config can be modified.

Parameters
[in]configConfig.
Returns
0 if predefined config, else 1.

◆ configs_extra_where()

gchar* configs_extra_where ( const char *  usage_type)

Generate an extra WHERE clause for selecting configs.

Parameters
[in]usage_typeThe usage type to limit the selection to.
Returns
Newly allocated where clause string.

◆ copy_config()

int copy_config ( const char *  name,
const char *  comment,
const char *  config_id,
const char *  usage_type,
config_t *  new_config 
)

Create a config from an existing config.

Parameters
[in]nameName of new config and NVT selector.
[in]commentComment on new config.
[in]config_idUUID of existing config.
[in]usage_typeOptional new usage type for the new config.
[out]new_configNew config.
Returns
0 success, 1 config exists already, 2 failed to find existing config, 99 permission denied, -1 error.

◆ create_config()

int create_config ( const char *  proposed_name,
const char *  comment,
const array_t *  selectors,
const array_t *  preferences,
const char *  config_type,
const char *  usage_type,
config_t *  config,
char **  name 
)

Create a config.

If a config with the same name exists already then add a unique integer suffix onto the name.

Parameters
[in]proposed_nameProposed name of config.
[in]commentComment on config.
[in]selectorsNVT selectors.
[in]preferencesPreferences.
[in]config_typeConfig type.
[in]usage_typeThe usage type ("scan" or "policy")
[out]configOn success the config.
[out]nameOn success the name of the config.
Returns
0 success, 1 config exists already, 99 permission denied, -1 error, -2 name empty, -3 input error in selectors, -4 input error in preferences.

◆ create_config_from_scanner()

int create_config_from_scanner ( const char *  scanner_id,
const char *  name,
const char *  comment,
const char *  usage_type,
char **  uuid 
)

Create a config from an OSP scanner.

Parameters
[in]scanner_idUUID of scanner to create config from.
[in]nameName for config.
[in]commentComment for config.
[in]usage_typeThe usage type ("scan" or "policy")
[out]uuidConfig UUID, on success.
Returns
0 success, 1 couldn't find scanner, 2 scanner not of OSP type, 3 config name exists already, 4 couldn't get params from scanner, 99 permission denied, -1 error.

◆ create_task_check_config_scanner()

int create_task_check_config_scanner ( config_t  config,
scanner_t  scanner 
)

Check scanner and config values match for a task.

Parameters
[in]configScan Config.
[in]scannerScanner.
Returns
1 if config and scanner types match, 0 otherwise.

◆ delete_config()

int delete_config ( const char *  config_id,
int  ultimate 
)

Delete a config.

Parameters
[in]config_idUUID of config.
[in]ultimateWhether to remove entirely, or to trashcan.
Returns
0 success, 1 fail because a task refers to the config, 2 failed to find config, 3 config is predefined, 99 permission denied, -1 error.

◆ family_is_selected()

static int family_is_selected ( const char *  quoted_selector,
const char *  quoted_family 
)
static

Check whether a family is selected.

Only works for "generating from empty" selection.

Parameters
[in]quoted_selectorSQL-quoted selector name.
[in]quoted_familySQL-quoted family name (NULL for families).
Returns
1 if selected, else 0.

◆ find_config_with_permission()

gboolean find_config_with_permission ( const char *  uuid,
config_t *  config,
const char *  permission 
)

Find a config for a set of permissions, given a UUID.

Parameters
[in]uuidUUID of config.
[out]configConfig return, 0 if successfully failed to find config.
[in]permissionPermission.
Returns
FALSE on success (including if failed to find config), TRUE on error.

◆ get_nvt_preference_by_id()

preference_t* get_nvt_preference_by_id ( const char *  nvt_oid,
const char *  find_id,
const char *  check_name,
const char *  check_type,
const char *  value 
)

Gets an NVT preference by id or by name.

Note: This currently only gets the fields needed by create_config.

Parameters
[in]nvt_oidOID of the NVT the preference belongs to.
[in]find_idPreference id to find, or NULL.
[in]check_namePreference name to check.
[in]check_typePreference name to check.
[in]valueValue to assign to the preference.
Returns
Newly allocated preference, freed with preference_free, or NULL (on error or if not found).

◆ get_scanner_params()

static GSList* get_scanner_params ( scanner_t  scanner)
static

Get list of OSP Scanner parameters.

Parameters
[in]scannerScanner.
Returns
List of scanner parameters, NULL if error.

◆ init_config_iterator()

int init_config_iterator ( iterator_t iterator,
const get_data_t get 
)

Initialise a scan config iterator.

Parameters
[in]iteratorIterator.
[in]getGET data.
Returns
0 success, 1 failed to find scan config, 2 failed to find filter, -1 error.

◆ init_config_preference_iterator()

void init_config_preference_iterator ( iterator_t iterator,
config_t  config 
)

Initialise a preference iterator.

Assume the caller has permission to access the config.

Parameters
[in]iteratorIterator.
[in]configConfig.

◆ init_config_task_iterator()

void init_config_task_iterator ( iterator_t iterator,
config_t  config,
int  ascending 
)

Initialise a config task iterator.

Iterate over all tasks that use the config.

Parameters
[in]iteratorIterator.
[in]configConfig.
[in]ascendingWhether to sort ascending or descending.

◆ init_config_timeout_iterator()

void init_config_timeout_iterator ( iterator_t iterator,
config_t  config 
)

Initialise a config timeout iterator.

Iterate over all timeout preferences of NVTs that have timeouts.

Parameters
[in]iteratorIterator.
[in]configConfig.

◆ init_family_iterator()

void init_family_iterator ( iterator_t iterator,
int  all,
const char *  selector,
int  ascending 
)

Initialise an NVT selector family iterator.

Parameters
[in]iteratorIterator.
[in]allTrue if families are growing in the selector, else 0. Only considered with a selector.
[in]selectorName of NVT selector. NULL for all families.
[in]ascendingWhether to sort ascending or descending.

◆ init_nvt_preference_iterator()

void init_nvt_preference_iterator ( iterator_t iterator,
const char *  oid 
)

Initialise an NVT preference iterator.

Parameters
[in]iteratorIterator.
[in]oidOID of NVT, NULL for all preferences.

◆ init_nvt_selector_iterator()

void init_nvt_selector_iterator ( iterator_t iterator,
const char *  selector,
config_t  config,
int  type 
)

Initialise an NVT selector iterator.

Parameters
[in]iteratorIterator.
[in]selectorName of single selector to iterate over, NULL for all.
[in]configConfig to limit iteration to, 0 for all.
[in]typeType of selector. All if config is given.

◆ init_preference_iterator()

void init_preference_iterator ( iterator_t iterator,
config_t  config,
const char *  section 
)

Initialise a config preference iterator, with defaults.

Assume the caller has permission to access the config.

This version substitutes the NVT preference when the config preference is missing.

Parameters
[in]iteratorIterator.
[in]configConfig containing preferences.
[in]sectionPreference section.

◆ init_user_config_iterator()

void init_user_config_iterator ( iterator_t iterator,
config_t  config,
int  trash,
int  ascending,
const char *  sort_field 
)

Initialise a config iterator, limited to user's configs.

Parameters
[in]iteratorIterator.
[in]configConfig. 0 for all.
[in]trashWhether to iterate over trashcan configs.
[in]ascendingWhether to sort ascending or descending.
[in]sort_fieldField to sort on, or NULL for "id".

◆ insert_nvt_selectors()

static int insert_nvt_selectors ( const char *  quoted_name,
const array_t *  selectors 
)
static

Insert NVT selectors.

Parameters
[in]quoted_nameName of NVT selector.
[in]selectorsNVT selectors.
Returns
0 success, -1 error, -3 input error.
Todo:
Check that selector->type is actually an integer.

◆ insert_osp_parameter()

static int insert_osp_parameter ( osp_param_t *  param,
config_t  config 
)
static

Insert an OSP parameter into a config if not already present.

Parameters
[in]paramOSP parameter to insert.
[in]configConfig to insert parameter into.
Returns
1 if added, 0 otherwise.

◆ manage_nvt_preference_add()

void manage_nvt_preference_add ( const char *  name,
const char *  value 
)

Add/replace an NVT preference.

Parameters
[in]nameThe name of the preference.
[in]valueThe value of the preference.

◆ manage_set_config()

int manage_set_config ( const gchar *  config_id,
const char *  name,
const char *  comment,
const char *  scanner_id 
)

Set the name, comment and scanner of a config.

Parameters
[in]config_idConfig.
[in]nameNew name, not updated if NULL.
[in]commentNew comment, not updated if NULL.
[in]scanner_idUUID of new scanner, not updated if NULL.
Returns
0 success, 1 config with new name exists already, 2 scanner doesn't exist, 3 modification not allowed while config is in use, 4 failed to find config, -1 error.

◆ manage_set_config_families()

int manage_set_config_families ( const gchar *  config_id,
GPtrArray *  growing_all_families,
GPtrArray *  static_all_families,
GPtrArray *  growing_families,
int  grow_families 
)

Refresh NVT selection of a config from given families.

Parameters
[in]config_idConfig.
[in]growing_all_familiesGrowing families with all selection.
[in]static_all_familiesStatic families with all selection.
[in]growing_familiesThe rest of the growing families.
[in]grow_families1 if families should grow, else 0.
Returns
0 success, 1 config in use, 2 failed to find config, -1 error.

◆ manage_set_config_nvts()

int manage_set_config_nvts ( const gchar *  config_id,
const char *  family,
GPtrArray *  selected_nvts 
)

Set the NVT's selected for a single family of a config.

Parameters
[in]config_idConfig.
[in]familyFamily name.
[in]selected_nvtsNVT's.
Returns
0 success, 1 config in use, 2 failed to find config, -1 error.

◆ manage_set_config_preference()

int manage_set_config_preference ( const gchar *  config_id,
const char *  nvt,
const char *  name,
const char *  value_64 
)

Set a preference of a config.

Parameters
[in]config_idConfig.
[in]nvtUUID of NVT. NULL for scanner preference.
[in]namePreference name, including NVT name and preference type.
[in]value_64Preference value in base64. NULL for an NVT preference removes the preference from the config.
Returns
0 success, 1 config in use, 2 empty radio value, 3 failed to find config, -1 error.

◆ member()

static int member ( GPtrArray *  array,
const char *  string 
)
static

Test whether a string equal to a given string exists in an array.

Parameters
[in]arrayArray of gchar* pointers.
[in]stringString.
Returns
1 if a string equal to
  • string exists in
  • array, else 0.

◆ modify_task_check_config_scanner()

int modify_task_check_config_scanner ( task_t  task,
const char *  config_id,
const char *  scanner_id 
)

Check scanner and config values match for a task.

Parameters
[in]taskTask.
[in]config_idID of config. "0" to use task's config.
[in]scanner_idID of scanner.
Returns
0 if config and scanner types match, 1 do not match, 2 failed to find config, 3 failed to find scanner, -1 error.

◆ nvt_preference_count()

int nvt_preference_count ( const char *  oid)

Get the number preferences available for an NVT.

Parameters
[in]oidOID of NVT.
Returns
Number of possible preferences on NVT.

◆ nvt_preference_iterator_config_value()

char* nvt_preference_iterator_config_value ( iterator_t iterator,
config_t  config 
)

Get the config value from an NVT preference iterator.

Parameters
[in]iteratorIterator.
[in]configConfig.
Returns
Freshly allocated config value.

◆ nvt_preference_iterator_id()

char* nvt_preference_iterator_id ( iterator_t iterator)

Get the ID from an NVT preference iterator.

Parameters
[in]iteratorIterator.
Returns
NVT.

◆ nvt_preference_iterator_oid()

char* nvt_preference_iterator_oid ( iterator_t iterator)

Get the NVT from an NVT preference iterator.

Parameters
[in]iteratorIterator.
Returns
NVT.

◆ nvt_preference_iterator_real_name()

char* nvt_preference_iterator_real_name ( iterator_t iterator)

Get the real name from an NVT preference iterator.

Parameters
[in]iteratorIterator.
Returns
Real name.

◆ nvt_preference_iterator_type()

char* nvt_preference_iterator_type ( iterator_t iterator)

Get the type from an NVT preference iterator.

Parameters
[in]iteratorIterator.
Returns
Type.

◆ nvt_selector_add()

static void nvt_selector_add ( const char *  quoted_selector,
const char *  quoted_family_or_nvt,
const char *  quoted_family,
int  exclude 
)
static

Add a selector to an NVT selector.

Parameters
[in]quoted_selectorSQL-quoted selector name.
[in]quoted_family_or_nvtSQL-quoted family or NVT name.
[in]quoted_familySQL-quoted family name (NULL for families).
[in]exclude1 exclude selector, 0 include selector.
Returns
0 success, -1 error.

◆ nvt_selector_families_growing()

static int nvt_selector_families_growing ( const char *  selector)
static

Get the family growth status of an NVT selector.

Parameters
[in]selectorNVT selector.
Returns
1 growing, 0 static.

◆ nvt_selector_family_count()

int nvt_selector_family_count ( const char *  quoted_selector,
int  families_growing 
)

Get the number of families selected by an NVT selector.

A growing family which has all current NVT's excluded is still considered as selected by the NVT selector.

Parameters
[in]quoted_selectorSQL-quoted selector name.
[in]families_growing1 if families are growing, else 0.
Returns
The number of families selected by an NVT selector.

◆ nvt_selector_family_growing()

int nvt_selector_family_growing ( const char *  selector,
const char *  family,
int  all 
)

Get whether an NVT selector family is growing.

Parameters
[in]selectorNVT selector.
[in]familyFamily name.
[in]allTrue if selector is an "all" selector, else 0.
Returns
1 growing, 0 static.

◆ nvt_selector_has()

static int nvt_selector_has ( const char *  quoted_selector,
const char *  family_or_nvt,
int  type,
int  exclude 
)
static

Check whether an NVT selector has a particular selector.

Parameters
[in]quoted_selectorSQL-quoted selector name.
[in]family_or_nvtSQL-quoted UUID of NVT, or family name.
[in]typeSelector type.
[in]exclude1 exclude, 0 include.
Returns
1 if contains include/exclude, else 0.

◆ nvt_selector_iterator_include()

int nvt_selector_iterator_include ( iterator_t iterator)

Get whether the selector rule is an include rule.

Parameters
[in]iteratorIterator.
Returns
-1 if iteration is complete, 1 if include, else 0.

◆ nvt_selector_iterator_type()

int nvt_selector_iterator_type ( iterator_t iterator)

Get the type from an NVT selector.

Parameters
[in]iteratorIterator.
Returns
-1 if iteration is complete, 1 if include, else 0.

◆ nvt_selector_nvt_count()

int nvt_selector_nvt_count ( const char *  selector,
const char *  family,
int  growing 
)

Get the number of NVTs selected by an NVT selector.

Parameters
[in]selectorNVT selector.
[in]familyFamily name. NULL for all.
[in]growingTrue if the given family is growing, else 0. If
familyis NULL, true if the the families are growing, else 0.
Returns
Number of NVTs selected in one or all families.

◆ nvt_selector_nvts_growing_2()

static int nvt_selector_nvts_growing_2 ( const char *  quoted_selector,
int  families_growing 
)
static

Get the NVT growth status of an NVT selector.

Parameters
[in]quoted_selectorSQL-quoted selector name.
[in]families_growing1 if families are growing, else 0.
Returns
1 growing, 0 static.

◆ nvt_selector_remove()

static void nvt_selector_remove ( const char *  quoted_selector,
const char *  quoted_family,
int  type 
)
static

Remove all selectors of a certain family from an NVT selector.

Parameters
[in]quoted_selectorSQL-quoted selector name.
[in]quoted_familySQL-quoted family name.
[in]typeSelector type to remove.
Returns
0 success, -1 error.

◆ nvt_selector_remove_selector()

static void nvt_selector_remove_selector ( const char *  quoted_selector,
const char *  family_or_nvt,
int  type 
)
static

Remove all selectors of a certain type from an NVT selector.

Parameters
[in]quoted_selectorSQL-quoted selector name.
[in]family_or_nvtSQL-quoted family name or NVT UUID.
[in]typeSelector type to remove.
Returns
0 success, -1 error.

◆ nvt_selector_set_family()

static void nvt_selector_set_family ( const char *  quoted_selector,
const char *  family_or_nvt,
int  type,
const char *  family 
)
static

Set the family of an NVT selector.

Parameters
[in]quoted_selectorSQL-quoted selector name.
[in]family_or_nvtFamily name or NVT OID of selector.
[in]typeSelector type to remove.
[in]familyNew family.
Returns
0 success, -1 error.

◆ set_task_preferences()

int set_task_preferences ( task_t  task,
array_t *  preferences 
)

Set the preferences of a task.

Only the given preferences are affected. A NULL value means to remove the preference (reverts to using scanner value).

Parameters
[in]taskTask.
[in]preferencesPreferences.
Returns
0 success, 1 invalid auto_delete value, 2 auto_delete_data out of range.

◆ switch_representation()

static int switch_representation ( config_t  config,
int  constraining 
)
static

Switch between constraining and generating representation.

It's up to the caller to start and end a transaction.

Parameters
[in]configConfig name.
[in]constraining1 families currently growing, 0 families currently static.
Returns
0 success, -1 error.

◆ sync_config()

int sync_config ( const char *  config_id)

Synchronize a config.

Parameters
[in]config_idUUID of config.
Returns
0 success, 1 failed to find config, 2 config not of OSP type, 3 config has no scanner, 4 couldn't get params from scanner, 99 permission denied, -1 error.

◆ task_preference_value()

char* task_preference_value ( task_t  task,
const char *  name 
)

Get the value of a task preference.

Parameters
[in]taskTask.
[in]namePreference name.
Returns
Freshly allocated task preference value or NULL if pref missing.

◆ trash_config_in_use()

int trash_config_in_use ( config_t  config)

Return whether a trashcan config is referenced by a task.

Parameters
[in]configConfig.
Returns
1 if in use, else 0.

◆ trash_config_readable_uuid()

int trash_config_readable_uuid ( const gchar *  config_id)

Return whether a trashcan config is readable.

Parameters
[in]config_idConfig UUID.
Returns
1 if readable, else 0.

◆ trash_config_writable()

int trash_config_writable ( config_t  config)

Return whether a trashcan config is writable.

Parameters
[in]configConfig.
Returns
1 if in use, else 0.

◆ update_all_config_caches()

void update_all_config_caches ( )

Update count and growing info in every config across all users.

It's up to the caller to organise a transaction.

◆ update_config_cache()

static void update_config_cache ( iterator_t configs)
static

Update the cached count and growing information in a config.

It's up to the caller to organise a transaction.

Parameters
[in]configsConfig to update.

◆ update_config_cache_init()

void update_config_cache_init ( const char *  uuid)

Update count and growing info in config, without checking user.

For use during initialisation.

Parameters
[in]uuidConfig UUID.

It's up to the caller to organise a transaction.

◆ update_config_caches()

static void update_config_caches ( config_t  config)
static

Update the cached count and growing information in every config.

Only consider configs for the current user.

It's up to the caller to organise a transaction.

Parameters
[in]configConfig to update. 0 for all.

◆ update_config_params()

static void update_config_params ( config_t  config,
const char *  config_id,
GSList *  params 
)
static

Update a config with a list of parameters.

Parameters
[in]configConfig ID.
[in]config_idConfig UUID.
[in]paramsList of new config parameters.

◆ update_config_preference()

void update_config_preference ( const char *  config_id,
const char *  type,
const char *  preference_name,
const char *  new_value,
gboolean  insert 
)

Update or optionally insert a NVT preference.

Parameters
[in]config_idUUID of the config to set the preference in
[in]typeType of the preference, e.g. "PLUGINS_PREFS"
[in]preference_nameFull name of the preference
[in]new_valueThe new value to set
[in]insertWhether to insert the preference if missing

◆ update_nvt_family()

static int update_nvt_family ( const char *  oid,
const char *  old_family,
const char *  new_family 
)
static

Change the family of an NVT in all configs.

Parameters
[in]oidNVT OID.
[in]old_familyName of old family.
[in]new_familyName of new family.
Returns
0 success, -1 error.