Greenbone Vulnerability Manager  22.4.0~dev1
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 <errno.h>
#include <glib/gstdio.h>
#include <stdlib.h>
#include <string.h>
#include <gvm/util/uuidutils.h>

Macros

#define G_LOG_DOMAIN   "md manage"
 GLib log domain.
 

Functions

int sync_configs_with_feed (gboolean)
 Sync all configs with the feed. More...
 
static int switch_representation (config_t config, int constraining)
 Switch between constraining and generating representation. More...
 
static void update_config_caches (config_t config)
 Update the cached count and growing information in every config. 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...
 
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...
 
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...
 
static int nvt_selector_entire_and_growing (const char *selector, const char *family, int all)
 Get whether an NVT selector selects every NVT in a family. 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_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 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_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_modify_config_start (const char *config_id, config_t *config_out)
 Starts the SQL transaction for modify_config and finds the config. More...
 
void manage_modify_config_cancel ()
 Cancels a manage_config command and rolls back the changes.
 
void manage_modify_config_commit ()
 Commits the changes of a manage_config command.
 
int manage_set_config_families (config_t config, GPtrArray *growing_all_families, GPtrArray *static_all_families, GPtrArray *growing_families, int grow_families, gchar **rejected_family)
 Refresh NVT selection of a config from given families. More...
 
static int insert_nvt_selectors (const char *quoted_name, const array_t *selectors, int allow_errors)
 Insert NVT selectors. 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 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...
 
gboolean find_config_no_acl (const char *uuid, config_t *config)
 Find a config given a UUID. More...
 
gboolean find_trash_config_no_acl (const char *uuid, config_t *config)
 Find a trash config 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)
 Insert preferences into a config. More...
 
static int create_config_internal (int check_access, const char *config_id, const char *proposed_name, int make_name_unique, const char *comment, int all_selector, const array_t *selectors, const array_t *preferences, const char *usage_type, int allow_errors, int predefined, config_t *config, char **name)
 Create a config. More...
 
int create_config (const char *config_id, const char *proposed_name, int make_name_unique, const char *comment, int all_selector, const array_t *selectors, const array_t *preferences, const char *usage_type, config_t *config, char **name)
 Create a config. More...
 
int create_config_no_acl (const char *config_id, const char *proposed_name, int make_name_unique, const char *comment, int all_selector, const array_t *selectors, const array_t *preferences, const char *usage_type, config_t *config, char **name)
 Create a config. More...
 
gchar * configs_extra_where (const char *usage_type)
 Generate an extra WHERE clause for selecting configs. More...
 
char * config_uuid (config_t config)
 Return the UUID of a config. More...
 
int config_predefined (config_t config)
 Return whether a config is predefined. More...
 
int trash_config_predefined (config_t config)
 Return whether a trash config is predefined. 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_scanner_type (scanner_t scanner)
 Check if the scanner type is valid 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...
 
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_predefined (iterator_t *iterator)
 Get predefined status 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...
 
static int modify_config_preference (config_t config, const char *nvt, const char *name, const char *value_64)
 Update a preference of a config. More...
 
int manage_set_config_preference (config_t config, const char *nvt, const char *name, const char *value_64)
 Set a preference of a config. More...
 
int manage_set_config (config_t config, const char *name, const char *comment)
 Set the name and comment of a config. More...
 
int family_whole_only (const gchar *family)
 Check whether a family is "whole-only". More...
 
int config_family_entire_and_growing (config_t config, const char *family)
 Get whether a config selects every NVT in a given family. More...
 
int manage_set_config_nvts (config_t config, 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...
 
void migrate_predefined_configs ()
 Migrate old ownerless configs to the Feed Owner.
 
int config_updated_in_feed (config_t config, const gchar *path)
 Check if a config has been updated in the feed. More...
 
void update_config (config_t config, const gchar *name, const gchar *comment, const gchar *usage_type, int all_selector, const array_t *selectors, const array_t *preferences)
 Update a config from an XML file. More...
 
void check_db_configs ()
 Check configs, for startup.
 
void check_whole_only_in_configs ()
 Check whole-only families. More...
 
int cleanup_config_sequences ()
 Cleans up scan config related id sequences likely to run out. 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.

◆ check_whole_only_in_configs()

void check_whole_only_in_configs ( )

Check whole-only families.

Called after NVT sync.

◆ cleanup_config_sequences()

int cleanup_config_sequences ( )

Cleans up scan config related id sequences likely to run out.

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_family_entire_and_growing()

int config_family_entire_and_growing ( config_t  config,
const char *  family 
)

Get whether a config selects every NVT in a given family.

Parameters
[in]configConfig.
[in]familyFamily name.
Returns
0 no, 1 yes, -1 error.

◆ config_in_use()

int config_in_use ( config_t  config)

Return whether a config is referenced by a task.

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 
)
static

Insert preferences into a config.

Parameters
[in]configConfig.
[in]preferencesPreferences.
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_predefined()

int config_iterator_predefined ( iterator_t iterator)

Get predefined status from a config iterator.

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

◆ 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_predefined()

int config_predefined ( config_t  config)

Return whether a config is predefined.

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

◆ 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_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_updated_in_feed()

int config_updated_in_feed ( config_t  config,
const gchar *  path 
)

Check if a config has been updated in the feed.

Parameters
[in]pathFull path to config XML in feed.
[in]configConfig.
Returns
1 if updated in feed, else 0.

◆ 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
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 *  config_id,
const char *  proposed_name,
int  make_name_unique,
const char *  comment,
int  all_selector,
const array_t *  selectors,
const array_t *  preferences,
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]config_idID if one is required, else NULL.
[in]proposed_nameProposed name of config.
[in]make_name_uniqueWhether to make name unique.
[in]commentComment on config.
[in]all_selectorWhether to use "all" selector instead of selectors.
[in]selectorsNVT selectors.
[in]preferencesPreferences.
[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, -5 error in config_id.

◆ create_config_internal()

static int create_config_internal ( int  check_access,
const char *  config_id,
const char *  proposed_name,
int  make_name_unique,
const char *  comment,
int  all_selector,
const array_t *  selectors,
const array_t *  preferences,
const char *  usage_type,
int  allow_errors,
int  predefined,
config_t *  config,
char **  name 
)
static

Create a config.

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

Parameters
[in]check_accessWhether to check for create_config permission.
[in]config_idID if one is required, else NULL.
[in]proposed_nameProposed name of config.
[in]make_name_uniqueWhether to make name unique.
[in]commentComment on config.
[in]all_selectorWhether to use "all" selector instead of selectors.
[in]selectorsNVT selectors.
[in]preferencesPreferences.
[in]usage_typeThe usage type ("scan" or "policy")
[in]allow_errorsWhether certain errors are allowed.
[in]predefinedWhether config is predefined.
[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, -5 error in config_id.

◆ create_config_no_acl()

int create_config_no_acl ( const char *  config_id,
const char *  proposed_name,
int  make_name_unique,
const char *  comment,
int  all_selector,
const array_t *  selectors,
const array_t *  preferences,
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]config_idID if one is required, else NULL.
[in]proposed_nameProposed name of config.
[in]make_name_uniqueWhether to make name unique.
[in]commentComment on config.
[in]all_selectorWhether to use "all" selector instead of selectors.
[in]selectorsNVT selectors.
[in]preferencesPreferences.
[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, -5 error in config_id.

◆ create_task_check_scanner_type()

int create_task_check_scanner_type ( scanner_t  scanner)

Check if the scanner type is valid for a task.

Parameters
[in]scannerScanner.
Returns
1 if scanner type is valid, 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, 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.

◆ family_whole_only()

int family_whole_only ( const gchar *  family)

Check whether a family is "whole-only".

Parameters
[in]familyFamily name.
Returns
1 if whole-only, else 0.

◆ find_config_no_acl()

gboolean find_config_no_acl ( const char *  uuid,
config_t *  config 
)

Find a config given a UUID.

This does not do any permission checks.

Parameters
[in]uuidUUID of resource.
[out]configConfig return, 0 if no such config.
Returns
FALSE on success (including if no such config), TRUE on error.

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

◆ find_trash_config_no_acl()

gboolean find_trash_config_no_acl ( const char *  uuid,
config_t *  config 
)

Find a trash config given a UUID.

This does not do any permission checks.

Parameters
[in]uuidUUID of resource.
[out]configConfig return, 0 if no such config.
Returns
FALSE on success (including if no such 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).

◆ 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,
int  allow_errors 
)
static

Insert NVT selectors.

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

◆ manage_modify_config_start()

int manage_modify_config_start ( const char *  config_id,
config_t *  config_out 
)

Starts the SQL transaction for modify_config and finds the config.

Parameters
[in]config_idUUID of the config to find.
[out]config_outRow ID of the config or 0 if not found.
Returns
0 success, 1 config not found, -1 error.

◆ 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 ( config_t  config,
const char *  name,
const char *  comment 
)

Set the name and comment of a config.

Parameters
[in]configConfig to modify.
[in]nameNew name, not updated if NULL.
[in]commentNew comment, not updated if NULL.
Returns
0 success, 1 config with new name exists already.

◆ manage_set_config_families()

int manage_set_config_families ( config_t  config,
GPtrArray *  growing_all_families,
GPtrArray *  static_all_families,
GPtrArray *  growing_families,
int  grow_families,
gchar **  rejected_family 
)

Refresh NVT selection of a config from given families.

Parameters
[in]configConfig to modify.
[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.
[out]rejected_familyReturn of family if one was rejected.
Returns
0 success, 1 config in use, 2 whole-only families must be growing and include entire family, -1 error.

◆ manage_set_config_nvts()

int manage_set_config_nvts ( config_t  config,
const char *  family,
GPtrArray *  selected_nvts 
)

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

Parameters
[in]configConfig to modify.
[in]familyFamily name.
[in]selected_nvtsNVT's.
Returns
0 success, 1 config in use, 2 whole-only family, -1 error.

◆ manage_set_config_preference()

int manage_set_config_preference ( config_t  config,
const char *  nvt,
const char *  name,
const char *  value_64 
)

Set a preference of a config.

Parameters
[in]configConfig to modify.
[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, -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_config_preference()

static int modify_config_preference ( config_t  config,
const char *  nvt,
const char *  name,
const char *  value_64 
)
static

Update a preference of a config.

Parameters
[in]configConfig.
[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.

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

◆ nvt_selector_entire_and_growing()

static int nvt_selector_entire_and_growing ( const char *  selector,
const char *  family,
int  all 
)
static

Get whether an NVT selector selects every NVT in a family.

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

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

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

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

◆ 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_configs_with_feed()

int sync_configs_with_feed ( gboolean  rebuild)

Sync all configs with the feed.

Create configs that exists in the feed but not in the db. Update configs in the db that have changed on the feed. Do nothing to configs in db that have been removed from the feed.

Parameters
[in]rebuildWhether ignore timestamps to force a rebuild.
Returns
0 success, 1 no feed directory, 2 no feed owner, 3 NVTs missing, -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_predefined()

int trash_config_predefined ( config_t  config)

Return whether a trash config is predefined.

Parameters
[in]configConfig.
Returns
1 if predefined, 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()

void update_config ( config_t  config,
const gchar *  name,
const gchar *  comment,
const gchar *  usage_type,
int  all_selector,
const array_t *  selectors,
const array_t *  preferences 
)

Update a config from an XML file.

Parameters
[in]configExisting config.
[in]nameNew name.
[in]commentNew comment.
[in]usage_typeNew usage type.
[in]all_selectorWhether to use "all" selector instead of selectors.
[in]selectorsNew NVT selectors.
[in]preferencesNew preferences.

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