Greenbone Vulnerability Management Libraries
11.0.1
|
Knowledge base management API - Redis backend. More...
Go to the source code of this file.
Data Structures | |
struct | kb_item |
Knowledge base item (defined by name, type (int/char*) and value). Implemented as a singly linked list. More... | |
struct | kb |
Top-level KB. This is to be inherited by KB implementations. More... | |
struct | kb_operations |
KB interface. Functions provided by an implementation. All functions have to be provided, there is no default/fallback. These functions should be called via the corresponding static inline wrappers below. See the wrappers for the documentation. More... | |
Macros | |
#define | KB_PATH_DEFAULT "/run/redis/redis.sock" |
Default KB location. More... | |
Typedefs | |
typedef struct kb * | kb_t |
type abstraction to hide KB internals. More... | |
Enumerations | |
enum | kb_item_type { KB_TYPE_UNSPEC, KB_TYPE_INT, KB_TYPE_STR, KB_TYPE_CNT } |
Possible type of a kb_item. More... | |
enum | kb_nvt_pos { NVT_FILENAME_POS, NVT_REQUIRED_KEYS_POS, NVT_MANDATORY_KEYS_POS, NVT_EXCLUDED_KEYS_POS, NVT_REQUIRED_UDP_PORTS_POS, NVT_REQUIRED_PORTS_POS, NVT_DEPENDENCIES_POS, NVT_TAGS_POS, NVT_CVES_POS, NVT_BIDS_POS, NVT_XREFS_POS, NVT_CATEGORY_POS, NVT_TIMEOUT_POS, NVT_FAMILY_POS, NVT_NAME_POS, NVT_TIMESTAMP_POS, NVT_OID_POS } |
Possible positions of nvt values in cache list. More... | |
Functions | |
void | kb_item_free (struct kb_item *) |
Release a KB item (or a list). More... | |
static int | kb_new (kb_t *kb, const char *kb_path) |
Initialize a new Knowledge Base object. More... | |
static kb_t | kb_direct_conn (const char *kb_path, const int kb_index) |
Connect to a Knowledge Base object which has the given kb_index. More... | |
static kb_t | kb_find (const char *kb_path, const char *key) |
Find an existing Knowledge Base object with key. More... | |
static int | kb_delete (kb_t kb) |
Delete all entries and release ownership on the namespace. More... | |
static struct kb_item * | kb_item_get_single (kb_t kb, const char *name, enum kb_item_type type) |
Get a single KB element. More... | |
static char * | kb_item_get_str (kb_t kb, const char *name) |
Get a single KB string item. More... | |
static int | kb_item_get_int (kb_t kb, const char *name) |
Get a single KB integer item. More... | |
static struct kb_item * | kb_item_get_all (kb_t kb, const char *name) |
Get all items stored under a given name. More... | |
static struct kb_item * | kb_item_get_pattern (kb_t kb, const char *pattern) |
Get all items stored under a given pattern. More... | |
static int | kb_item_push_str (kb_t kb, const char *name, const char *value) |
Push a new value under a given key. More... | |
static char * | kb_item_pop_str (kb_t kb, const char *name) |
Pop a single KB string item. More... | |
static size_t | kb_item_count (kb_t kb, const char *pattern) |
Count all items stored under a given pattern. More... | |
static int | kb_item_add_str (kb_t kb, const char *name, const char *str, size_t len) |
Insert (append) a new entry under a given name. More... | |
static int | kb_item_add_str_unique (kb_t kb, const char *name, const char *str, size_t len) |
Insert (append) a new unique entry under a given name. More... | |
static int | kb_item_set_str (kb_t kb, const char *name, const char *str, size_t len) |
Set (replace) a new entry under a given name. More... | |
static int | kb_item_add_int (kb_t kb, const char *name, int val) |
Insert (append) a new entry under a given name. More... | |
static int | kb_item_add_int_unique (kb_t kb, const char *name, int val) |
Insert (append) a new unique entry under a given name. More... | |
static int | kb_item_set_int (kb_t kb, const char *name, int val) |
Set (replace) a new entry under a given name. More... | |
static int | kb_nvt_add (kb_t kb, const nvti_t *nvt, const char *filename) |
Insert a new nvt. More... | |
static char * | kb_nvt_get (kb_t kb, const char *oid, enum kb_nvt_pos position) |
Get field of a NVT. More... | |
static nvti_t * | kb_nvt_get_all (kb_t kb, const char *oid) |
Get a full NVT. More... | |
static GSList * | kb_nvt_get_oids (kb_t kb) |
Get list of NVT OIDs. More... | |
static int | kb_del_items (kb_t kb, const char *name) |
Delete all entries under a given name. More... | |
static int | kb_save (kb_t kb) |
Save all the KB's content. More... | |
static int | kb_lnk_reset (kb_t kb) |
Reset connection to the KB. This is called after each fork() to make sure connections aren't shared between concurrent processes. More... | |
static int | kb_flush (kb_t kb, const char *except) |
Flush all the KB's content. Delete all namespaces. More... | |
static int | kb_get_kb_index (kb_t kb) |
Return the kb index. More... | |
Variables | |
const struct kb_operations * | KBDefaultOperations |
Default KB operations. No selection mechanism is provided yet since there's only one implementation (redis-based). More... | |
Knowledge base management API - Redis backend.
Definition in file kb.h.
#define KB_PATH_DEFAULT "/run/redis/redis.sock" |
enum kb_item_type |
Possible type of a kb_item.
enum kb_nvt_pos |
Possible positions of nvt values in cache list.
Definition at line 58 of file kb.h.
|
inlinestatic |
Delete all entries under a given name.
[in] | kb | KB handle where to store the item. |
[in] | name | Item name. |
Definition at line 616 of file kb.h.
References kb_operations::kb_del_items, kb::kb_ops, and kb_item::name.
Referenced by nvticache_delete().
|
inlinestatic |
Delete all entries and release ownership on the namespace.
[in] | kb | KB handle to release. |
Definition at line 292 of file kb.h.
References kb_operations::kb_delete, and kb::kb_ops.
|
inlinestatic |
Connect to a Knowledge Base object which has the given kb_index.
[in] | kb_path | Path to KB. |
[in] | kb_index | DB index |
Definition at line 263 of file kb.h.
References kb_operations::kb_direct_conn, and KBDefaultOperations.
|
inlinestatic |
Find an existing Knowledge Base object with key.
[in] | kb_path | Path to KB. |
[in] | key | Marker key to search for in KB objects. |
Definition at line 278 of file kb.h.
References kb_operations::kb_find, and KBDefaultOperations.
Referenced by nvticache_init().
|
inlinestatic |
Flush all the KB's content. Delete all namespaces.
[in] | kb | KB handle. |
[in] | except | Don't flush DB with except key. |
Definition at line 671 of file kb.h.
References kb_operations::kb_flush, and kb::kb_ops.
|
inlinestatic |
Return the kb index.
[in] | kb | KB handle. |
Definition at line 690 of file kb.h.
References kb_operations::kb_get_kb_index, and kb::kb_ops.
|
inlinestatic |
Insert (append) a new entry under a given name.
[in] | kb | KB handle where to store the item. |
[in] | name | Item name. |
[in] | val | Item value. |
Definition at line 501 of file kb.h.
References kb_operations::kb_add_int, kb::kb_ops, and kb_item::name.
|
inlinestatic |
Insert (append) a new unique entry under a given name.
[in] | kb | KB handle where to store the item. |
[in] | name | Item name. |
[in] | val | Item value. |
Definition at line 518 of file kb.h.
References kb_operations::kb_add_int_unique, kb::kb_ops, and kb_item::name.
|
inlinestatic |
Insert (append) a new entry under a given name.
[in] | kb | KB handle where to store the item. |
[in] | name | Item name. |
[in] | str | Item value. |
[in] | len | Value length. Used for blobs. |
Definition at line 448 of file kb.h.
References kb_operations::kb_add_str, kb::kb_ops, kb_item::len, and kb_item::name.
|
inlinestatic |
Insert (append) a new unique entry under a given name.
[in] | kb | KB handle where to store the item. |
[in] | name | Item name. |
[in] | str | Item value. |
[in] | len | Value length. Used for blobs. |
Definition at line 466 of file kb.h.
References kb_operations::kb_add_str_unique, kb::kb_ops, kb_item::len, and kb_item::name.
|
inlinestatic |
Count all items stored under a given pattern.
[in] | kb | KB handle where to count the items. |
[in] | pattern | '*' pattern of the elements to count. |
Definition at line 430 of file kb.h.
References kb_operations::kb_count, and kb::kb_ops.
Referenced by nvticache_count().
void kb_item_free | ( | struct kb_item * | item | ) |
Release a KB item (or a list).
[in] | item | Item or list to be release |
Definition at line 537 of file kb.c.
References KB_TYPE_STR, kb_item::next, kb_item::type, and kb_item::v_str.
Referenced by nvticache_get_prefs(), redis_get_int(), and redis_get_str().
Get all items stored under a given name.
[in] | kb | KB handle where to fetch the items. |
[in] | name | Name of the elements to retrieve. |
Definition at line 361 of file kb.h.
References kb_operations::kb_get_all, kb::kb_ops, and kb_item::name.
Referenced by nvticache_get_prefs().
|
inlinestatic |
Get a single KB integer item.
[in] | kb | KB handle where to fetch the item. |
[in] | name | Name of the element to retrieve. |
Definition at line 344 of file kb.h.
References kb_operations::kb_get_int, kb::kb_ops, and kb_item::name.
Get all items stored under a given pattern.
[in] | kb | KB handle where to fetch the items. |
[in] | pattern | '*' pattern of the elements to retrieve. |
Definition at line 378 of file kb.h.
References kb_operations::kb_get_pattern, and kb::kb_ops.
|
inlinestatic |
Get a single KB element.
[in] | kb | KB handle where to fetch the item. |
[in] | name | Name of the element to retrieve. |
[in] | type | Desired element type. |
Definition at line 310 of file kb.h.
References kb_operations::kb_get_single, kb::kb_ops, kb_item::name, and kb_item::type.
|
inlinestatic |
Get a single KB string item.
[in] | kb | KB handle where to fetch the item. |
[in] | name | Name of the element to retrieve. |
Definition at line 327 of file kb.h.
References kb_operations::kb_get_str, kb::kb_ops, and kb_item::name.
Referenced by nvticache_check_feed(), nvticache_feed_version(), redis_find(), and redis_flush_all().
|
inlinestatic |
Pop a single KB string item.
[in] | kb | KB handle where to fetch the item. |
[in] | name | Name of the element to retrieve. |
Definition at line 412 of file kb.h.
References kb::kb_ops, kb_operations::kb_pop_str, and kb_item::name.
|
inlinestatic |
Push a new value under a given key.
[in] | kb | KB handle where to store the item. |
[in] | name | Key to push to. |
[in] | value | Value to push. |
Definition at line 395 of file kb.h.
References kb::kb_ops, kb_operations::kb_push_str, and kb_item::name.
|
inlinestatic |
Set (replace) a new entry under a given name.
[in] | kb | KB handle where to store the item. |
[in] | name | Item name. |
[in] | val | Item value. |
Definition at line 535 of file kb.h.
References kb::kb_ops, kb_operations::kb_set_int, and kb_item::name.
|
inlinestatic |
Set (replace) a new entry under a given name.
[in] | kb | KB handle where to store the item. |
[in] | name | Item name. |
[in] | str | Item value. |
[in] | len | Value length. Used for blobs. |
Definition at line 484 of file kb.h.
References kb::kb_ops, kb_operations::kb_set_str, kb_item::len, and kb_item::name.
Referenced by nvticache_init(), and nvticache_save().
|
inlinestatic |
Reset connection to the KB. This is called after each fork() to make sure connections aren't shared between concurrent processes.
[in] | kb | KB handle. |
Definition at line 651 of file kb.h.
References kb_operations::kb_lnk_reset, and kb::kb_ops.
Referenced by nvticache_init(), and nvticache_reset().
|
inlinestatic |
Initialize a new Knowledge Base object.
[in] | kb | Reference to a kb_t to initialize. |
[in] | kb_path | Path to KB. |
Definition at line 245 of file kb.h.
References kb_operations::kb_new, and KBDefaultOperations.
Referenced by nvticache_init().
Insert a new nvt.
[in] | kb | KB handle where to store the nvt. |
[in] | nvt | nvt to store. |
[in] | filename | Path to nvt to store. |
Definition at line 552 of file kb.h.
References kb_operations::kb_add_nvt, and kb::kb_ops.
Referenced by nvticache_add().
|
inlinestatic |
Get field of a NVT.
[in] | kb | KB handle where to store the nvt. |
[in] | oid | OID of NVT to get from. |
[in] | position | Position of field to get. |
Definition at line 569 of file kb.h.
References kb_operations::kb_get_nvt, and kb::kb_ops.
Referenced by nvticache_check(), nvticache_get_bids(), nvticache_get_category(), nvticache_get_cves(), nvticache_get_dependencies(), nvticache_get_excluded_keys(), nvticache_get_family(), nvticache_get_filename(), nvticache_get_mandatory_keys(), nvticache_get_name(), nvticache_get_oid(), nvticache_get_required_keys(), nvticache_get_required_ports(), nvticache_get_required_udp_ports(), nvticache_get_src(), nvticache_get_tags(), nvticache_get_timeout(), and nvticache_get_xrefs().
Get a full NVT.
[in] | kb | KB handle where to store the nvt. |
[in] | oid | OID of NVT to get. |
Definition at line 585 of file kb.h.
References kb_operations::kb_get_nvt_all, and kb::kb_ops.
Referenced by nvticache_get_nvt().
|
inlinestatic |
Get list of NVT OIDs.
[in] | kb | KB handle where NVTs are stored. |
Definition at line 600 of file kb.h.
References kb_operations::kb_get_nvt_oids, and kb::kb_ops.
Referenced by nvticache_get_oids().
|
inlinestatic |
Save all the KB's content.
[in] | kb | KB handle. |
Definition at line 631 of file kb.h.
References kb::kb_ops, and kb_operations::kb_save.
Referenced by nvticache_save().
const struct kb_operations* KBDefaultOperations |
Default KB operations. No selection mechanism is provided yet since there's only one implementation (redis-based).
Definition at line 1614 of file kb.c.
Referenced by kb_direct_conn(), kb_find(), and kb_new().