|
Greenbone Vulnerability Management Libraries 22.32.0
|
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. | |
Typedefs | |
| typedef struct kb * | kb_t |
| type abstraction to hide KB internals. | |
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_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). | |
| static int | kb_new (kb_t *kb, const char *kb_path) |
| Initialize a new Knowledge Base object. | |
| 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. | |
| static kb_t | kb_find (const char *kb_path, const char *key) |
| Find an existing Knowledge Base object with key. | |
| static int | kb_delete (kb_t kb) |
| Delete all entries and release ownership on the namespace. | |
| static struct kb_item * | kb_item_get_single (kb_t kb, const char *name, enum kb_item_type type) |
| Get a single KB element. | |
| static char * | kb_item_get_str (kb_t kb, const char *name) |
| Get a single KB string item. | |
| static int | kb_item_get_int (kb_t kb, const char *name) |
| Get a single KB integer item. | |
| static struct kb_item * | kb_item_get_all (kb_t kb, const char *name) |
| Get all items stored under a given name. | |
| static struct kb_item * | kb_item_get_pattern (kb_t kb, const char *pattern) |
| Get all items stored under a given pattern. | |
| static int | kb_item_push_str (kb_t kb, const char *name, const char *value) |
| Push a new value under a given key. | |
| static char * | kb_item_pop_str (kb_t kb, const char *name) |
| Pop a single KB string item. | |
| static size_t | kb_item_count (kb_t kb, const char *pattern) |
| Count all items stored under a given pattern. | |
| 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. | |
| static int | kb_item_add_str_unique (kb_t kb, const char *name, const char *str, size_t len, int pos) |
| Insert (append) a new unique entry under a given name. | |
| static int | kb_add_str_unique_volatile (kb_t kb, const char *name, const char *str, int expire, size_t len, int pos) |
| Insert (append) a new unique and volatile entry under a given name. | |
| 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. | |
| static int | kb_item_add_int (kb_t kb, const char *name, int val) |
| Insert (append) a new entry under a given name. | |
| 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. | |
| static int | kb_add_int_unique_volatile (kb_t kb, const char *name, int val, int expire) |
| Insert (append) a new unique and volatile entry under a given name. | |
| static int | kb_item_set_int (kb_t kb, const char *name, int val) |
| Set (replace) a new entry under a given name. | |
| static int | kb_nvt_add (kb_t kb, const nvti_t *nvt, const char *filename) |
| Insert a new nvt. | |
| static char * | kb_nvt_get (kb_t kb, const char *oid, enum kb_nvt_pos position) |
| Get field of a NVT. | |
| static nvti_t * | kb_nvt_get_all (kb_t kb, const char *oid) |
| Get a full NVT. | |
| static GSList * | kb_nvt_get_oids (kb_t kb) |
| Get list of NVT OIDs. | |
| static int | kb_del_items (kb_t kb, const char *name) |
| Delete all entries under a given name. | |
| static int | kb_save (kb_t kb) |
| Save all the KB's content. | |
| static int | kb_lnk_reset (kb_t kb) |
| Reset connection to the KB. This is called after each fork() to make. | |
| static int | kb_flush (kb_t kb, const char *except) |
| Flush all the KB's content. Delete all namespaces. | |
| static int | kb_get_kb_index (kb_t kb) |
| Return the kb index. | |
Variables | |
| const struct kb_operations * | KBDefaultOperations |
| Default KB operations. No selection mechanism is provided yet since there's only one implementation (redis-based). | |
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 44 of file kb.h.
|
inlinestatic |
Insert (append) a new unique and volatile entry under a given name.
| [in] | kb | Reference to a kb_t to initialize. |
| [in] | name | Item name. |
| [in] | val | Item value. |
| [in] | expire | Item expire. |
Definition at line 597 of file kb.h.
References KBDefaultOperations, and kb_item::name.
|
inlinestatic |
Insert (append) a new unique and volatile entry under a given name.
| [in] | kb | Reference to a kb_t to initialize. |
| [in] | name | Item name. |
| [in] | str | String to add. |
| [in] | len | Value length. Used for blobs. |
| [in] | expire | Item expire. |
| [in] | pos | Which position the value is appended to. 0 for right, 1 for left position in the list. |
Definition at line 516 of file kb.h.
References KBDefaultOperations, kb_item::len, and kb_item::name.
|
inlinestatic |
Delete all entries under a given name.
| [in] | kb | KB handle where to store the item. |
| [in] | name | Item name. |
Definition at line 708 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 296 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 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 280 of file kb.h.
References 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 769 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 790 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 557 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 576 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 468 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. |
| [in] | pos | Which position the value is appended to. 0 for right, 1 for left position in the list. |
Definition at line 490 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 448 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 642 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 371 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 352 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 390 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 316 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 334 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 428 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 409 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 617 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 538 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 747 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 243 of file kb.h.
References 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 636 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 655 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(), 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 673 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 690 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 725 of file kb.h.
References kb::kb_ops, and kb_operations::kb_save.
|
extern |
Default KB operations. No selection mechanism is provided yet since there's only one implementation (redis-based).
Definition at line 1880 of file kb.c.
Referenced by kb_add_int_unique_volatile(), kb_add_str_unique_volatile(), kb_direct_conn(), kb_find(), and kb_new().