Greenbone Vulnerability Manager  22.4.0~dev1
Data Structures | Macros | Functions | Variables
gmp_configs.c File Reference

GVM GMP layer: Configs. More...

#include "gmp_configs.h"
#include "gmp_base.h"
#include "gmp_get.h"
#include "manage_acl.h"
#include "manage_configs.h"
#include <assert.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gvm/util/xmlutils.h>

Data Structures

struct  create_config_t
 The create_config command. More...
 
struct  modify_config_t
 The modify_config command. More...
 

Macros

#define G_LOG_DOMAIN   "md gmp"
 GLib log domain.
 

Functions

static gpointer nvt_selector_new (char *name, char *type, int include, char *family_or_nvt)
 Create a new NVT selector. More...
 
static void create_config_reset ()
 Reset command data.
 
void create_config_start (gmp_parser_t *gmp_parser, const gchar **attribute_names, const gchar **attribute_values)
 Start a command. More...
 
void create_config_element_start (gmp_parser_t *gmp_parser, const gchar *name, const gchar **attribute_names, const gchar **attribute_values)
 Start element. More...
 
static gchar * text_or_null (entity_t entity)
 Get the text of entity. More...
 
static gchar * attr_or_null (entity_t entity, const gchar *name)
 Get the attribute of entity. More...
 
int parse_config_entity (entity_t config, const char **config_id, char **name, char **comment, char **usage_type, int *all_selector, array_t **import_nvt_selectors, array_t **import_preferences)
 Get creation data from a config entity. More...
 
void create_config_run (gmp_parser_t *gmp_parser, GError **error)
 Execute command. More...
 
int create_config_element_end (gmp_parser_t *gmp_parser, GError **error, const gchar *name)
 End element. More...
 
void create_config_element_text (const gchar *text, gsize text_len)
 Add text to element. More...
 
static void modify_config_reset ()
 Reset command data.
 
void modify_config_start (gmp_parser_t *gmp_parser, const gchar **attribute_names, const gchar **attribute_values)
 Start a command. More...
 
void modify_config_element_start (gmp_parser_t *gmp_parser, const gchar *name, const gchar **attribute_names, const gchar **attribute_values)
 Start element. More...
 
static int modify_config_handle_basic_fields (config_t config, const char *name, const char *comment, gmp_parser_t *gmp_parser, GError **error)
 Handle basic, single-value fields of modify_config. More...
 
static int modify_config_collect_selection_families (entities_t entities, array_t **families_growing_all, array_t **families_growing_empty, array_t **families_static_all)
 Collect VT families from parsed modify_config XML into arrays. More...
 
static int modify_config_handle_family_selection (config_t config, array_t *families_growing_all, array_t *families_growing_empty, array_t *families_static_all, int family_selection_growing, gmp_parser_t *gmp_parser, GError **error)
 Handles a family selection inside a modify_config command. More...
 
static int modify_config_collect_selection_nvts (entities_t entities, array_t **nvt_oids)
 Collect a list of VT OIDs for a particular family in modify_config. More...
 
static int modify_config_handle_nvt_selection (config_t config, const char *nvt_selection_family, GPtrArray *nvt_selection, gmp_parser_t *gmp_parser, GError **error)
 Changes the VT selection of a given family in modify_config. More...
 
static int modify_config_handle_preference (config_t config, const char *nvt_oid, const char *name, const char *value, gmp_parser_t *gmp_parser, GError **error)
 Modifies a single preference inside a modify_config command. More...
 
static void modify_config_run (gmp_parser_t *gmp_parser, GError **error)
 Execute command. More...
 
int modify_config_element_end (gmp_parser_t *gmp_parser, GError **error, const gchar *name)
 End element. More...
 
void modify_config_element_text (const gchar *text, gsize text_len)
 Add text to element. More...
 

Variables

static create_config_t create_config_data
 Parser callback data. More...
 
static modify_config_t modify_config_data
 Parser callback data. More...
 

Detailed Description

GVM GMP layer: Configs.

GMP configs.

Function Documentation

◆ attr_or_null()

static gchar* attr_or_null ( entity_t  entity,
const gchar *  name 
)
static

Get the attribute of entity.

Parameters
[in]entityEntity. Can be NULL.
[in]nameName of attribute.
Returns
Entity attribute if there's an entity, else NULL.

◆ create_config_element_end()

int create_config_element_end ( gmp_parser_t gmp_parser,
GError **  error,
const gchar *  name 
)

End element.

Parameters
[in]gmp_parserGMP parser.
[in]errorError parameter.
[in]nameElement name.
Returns
0 success, 1 command finished.

◆ create_config_element_start()

void create_config_element_start ( gmp_parser_t gmp_parser,
const gchar *  name,
const gchar **  attribute_names,
const gchar **  attribute_values 
)

Start element.

Parameters
[in]gmp_parserGMP parser.
[in]nameElement name.
[in]attribute_namesAll attribute names.
[in]attribute_valuesAll attribute values.

◆ create_config_element_text()

void create_config_element_text ( const gchar *  text,
gsize  text_len 
)

Add text to element.

Parameters
[in]textText.
[in]text_lenText length.

◆ create_config_run()

void create_config_run ( gmp_parser_t gmp_parser,
GError **  error 
)

Execute command.

Parameters
[in]gmp_parserGMP parser.
[in]errorError parameter.

◆ create_config_start()

void create_config_start ( gmp_parser_t gmp_parser,
const gchar **  attribute_names,
const gchar **  attribute_values 
)

Start a command.

Parameters
[in]gmp_parserGMP parser.
[in]attribute_namesAll attribute names.
[in]attribute_valuesAll attribute values.

◆ modify_config_collect_selection_families()

static int modify_config_collect_selection_families ( entities_t  entities,
array_t **  families_growing_all,
array_t **  families_growing_empty,
array_t **  families_static_all 
)
static

Collect VT families from parsed modify_config XML into arrays.

Family name strings are to be freed with entity. VT families not collected are assumed to be static and empty.

Parameters
[in]entitiesThe entities struct with family elems as children.
[out]families_growing_allArray of growing families with all VTs.
[out]families_growing_emptyArray of growing, empty families.
[out]families_static_allArray of static families with all VTs.
Returns
0 on success, -1 on error.

◆ modify_config_collect_selection_nvts()

static int modify_config_collect_selection_nvts ( entities_t  entities,
array_t **  nvt_oids 
)
static

Collect a list of VT OIDs for a particular family in modify_config.

Parameters
[in]entitiesThe entities containing nvt elements as children.
[out]nvt_oidsThe list of VT OIDs to select.
Returns
0 on success, -1 on error.

◆ modify_config_element_end()

int modify_config_element_end ( gmp_parser_t gmp_parser,
GError **  error,
const gchar *  name 
)

End element.

Parameters
[in]gmp_parserGMP parser.
[in]errorError parameter.
[in]nameElement name.
Returns
0 success, 1 command finished.

◆ modify_config_element_start()

void modify_config_element_start ( gmp_parser_t gmp_parser,
const gchar *  name,
const gchar **  attribute_names,
const gchar **  attribute_values 
)

Start element.

Parameters
[in]gmp_parserGMP parser.
[in]nameElement name.
[in]attribute_namesAll attribute names.
[in]attribute_valuesAll attribute values.

◆ modify_config_element_text()

void modify_config_element_text ( const gchar *  text,
gsize  text_len 
)

Add text to element.

Parameters
[in]textText.
[in]text_lenText length.

◆ modify_config_handle_basic_fields()

static int modify_config_handle_basic_fields ( config_t  config,
const char *  name,
const char *  comment,
gmp_parser_t gmp_parser,
GError **  error 
)
static

Handle basic, single-value fields of modify_config.

Parameters
[in]configThe config to modify.
[in]nameThe name to set or NULL to keep old value.
[in]commentThe comment to set or NULL to keep old value.
[in]gmp_parserGMP parser.
[out]errorGError output.
Returns
0 on success, -1 on error.

◆ modify_config_handle_family_selection()

static int modify_config_handle_family_selection ( config_t  config,
array_t *  families_growing_all,
array_t *  families_growing_empty,
array_t *  families_static_all,
int  family_selection_growing,
gmp_parser_t gmp_parser,
GError **  error 
)
static

Handles a family selection inside a modify_config command.

Parameters
[in]configThe config to modify.
[in]families_growing_allArray of growing families with all VTs.
[in]families_growing_emptyArray of growing, empty families.
[in]families_static_allArray of static families with all VTs.
[in]family_selection_growing1 if families should grow, else 0.
[in]gmp_parserThe GMP parser.
[out]errorGError output.
Returns
0 on success, -1 on error.

◆ modify_config_handle_nvt_selection()

static int modify_config_handle_nvt_selection ( config_t  config,
const char *  nvt_selection_family,
GPtrArray *  nvt_selection,
gmp_parser_t gmp_parser,
GError **  error 
)
static

Changes the VT selection of a given family in modify_config.

Parameters
[in]configThe config to modify.
[in]nvt_selection_familyThe family to set the VT selection of.
[in]nvt_selectionArray of VT OIDs to select of the family.
[in]gmp_parserThe GMP parser.
[out]errorGError output.
Returns
0 on success, -1 on error.

◆ modify_config_handle_preference()

static int modify_config_handle_preference ( config_t  config,
const char *  nvt_oid,
const char *  name,
const char *  value,
gmp_parser_t gmp_parser,
GError **  error 
)
static

Modifies a single preference inside a modify_config command.

Parameters
[in]configThe config to modify.
[in]nvt_oidVT OID of the preference or NULL for scanner pref.
[in]nameName of the preference to change.
[in]valueValue to set for the preference.
[in]gmp_parserThe GMP parser.
[out]errorGError output.
Returns
0 on success, -1 on error.

◆ modify_config_run()

static void modify_config_run ( gmp_parser_t gmp_parser,
GError **  error 
)
static

Execute command.

Parameters
[in]gmp_parserGMP parser.
[out]errorError parameter.

◆ modify_config_start()

void modify_config_start ( gmp_parser_t gmp_parser,
const gchar **  attribute_names,
const gchar **  attribute_values 
)

Start a command.

Parameters
[in]gmp_parserGMP parser.
[in]attribute_namesAll attribute names.
[in]attribute_valuesAll attribute values.

◆ nvt_selector_new()

static gpointer nvt_selector_new ( char *  name,
char *  type,
int  include,
char *  family_or_nvt 
)
static

Create a new NVT selector.

Parameters
[in]nameName of NVT selector.
[in]typeType of NVT selector.
[in]includeInclude/exclude flag.
[in]family_or_nvtFamily or NVT.
Returns
Newly allocated NVT selector.

◆ parse_config_entity()

int parse_config_entity ( entity_t  config,
const char **  config_id,
char **  name,
char **  comment,
char **  usage_type,
int *  all_selector,
array_t **  import_nvt_selectors,
array_t **  import_preferences 
)

Get creation data from a config entity.

Parameters
[in]configConfig entity.
[out]config_idAddress for config ID, or NULL.
[out]nameAddress for name.
[out]commentAddress for comment.
[out]usage_typeAddress for usage type.
[out]all_selectorTrue if ALL_SELECTOR was present.
[out]import_nvt_selectorsAddress for selectors.
[out]import_preferencesAddress for preferences.
Returns
0 success, 1 preference did no exist, -1 preference without ID.

◆ text_or_null()

static gchar* text_or_null ( entity_t  entity)
static

Get the text of entity.

Parameters
[in]entityEntity. Can be NULL.
Returns
Entity text if there's an entity, else NULL.

Variable Documentation

◆ create_config_data

create_config_t create_config_data
static

Parser callback data.

This is initially 0 because it's a global variable.

◆ modify_config_data

modify_config_t modify_config_data
static

Parser callback data.

This is initially 0 because it's a global variable.