|
Greenbone Vulnerability Management Libraries
20.8.0
|
Knowledge base management API - Redis backend. More...
#include "kb.h"#include <errno.h>#include <glib.h>#include <hiredis/hiredis.h>#include <stdbool.h>#include <stdio.h>#include <stdlib.h>#include <string.h>Data Structures | |
| struct | kb_redis |
| Subclass of struct kb, it contains the redis-specific fields, such as the redis context, current DB (namespace) id and the server socket path. More... | |
Macros | |
| #define | _GNU_SOURCE |
| #define | G_LOG_DOMAIN "lib kb" |
| #define | GLOBAL_DBINDEX_NAME "GVM.__GlobalDBIndex" |
| Name of the namespace usage bitmap in redis. More... | |
| #define | redis_kb(__kb) ((struct kb_redis *) (__kb)) |
Functions | |
| static int | redis_delete_all (struct kb_redis *kbr) |
| Delete all the KB's content. More... | |
| static int | redis_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 | redis_flush_all (kb_t kb, const char *except) |
| Flush all the KB's content. Delete all namespaces. More... | |
| static redisReply * | redis_cmd (struct kb_redis *kbr, const char *fmt,...) |
| Execute a redis command and get a redis reply. More... | |
| static int | try_database_index (struct kb_redis *kbr, int index) |
| Attempt to atomically acquire ownership of a database. More... | |
| static int | fetch_max_db_index (struct kb_redis *kbr) |
| Set the number of databases have been configured into kbr struct. More... | |
| static int | select_database (struct kb_redis *kbr) |
| Select DB. More... | |
| static int | redis_release_db (struct kb_redis *kbr) |
| Release DB. More... | |
| static int | get_redis_ctx (struct kb_redis *kbr) |
| Get redis context if it is already connected or do a a connection. More... | |
| static int | redis_test_connection (struct kb_redis *kbr) |
| Test redis connection. More... | |
| static int | redis_delete (kb_t kb) |
| Delete all entries and release ownership on the namespace. More... | |
| static int | redis_get_kb_index (kb_t kb) |
| Return the kb index. More... | |
| static int | redis_new (kb_t *kb, const char *kb_path) |
| Initialize a new Knowledge Base object. More... | |
| static kb_t | redis_direct_conn (const char *kb_path, const int kb_index) |
| Connect to a Knowledge Base object with the given kb_index. More... | |
| static kb_t | redis_find (const char *kb_path, const char *key) |
| Find an existing Knowledge Base object with key. More... | |
| void | kb_item_free (struct kb_item *item) |
| Release a KB item (or a list). More... | |
| static struct kb_item * | redis2kbitem_single (const char *name, const redisReply *elt, int force_int) |
| Give a single KB item. More... | |
| static struct kb_item * | redis2kbitem (const char *name, const redisReply *rep) |
| Fetch a KB item or list from a redis Reply. More... | |
| static struct kb_item * | redis_get_single (kb_t kb, const char *name, enum kb_item_type type) |
| Get a single KB element. More... | |
| static char * | redis_get_str (kb_t kb, const char *name) |
| Get a single KB string item. More... | |
| static int | redis_push_str (kb_t kb, const char *name, const char *value) |
| Push a new entry under a given key. More... | |
| static char * | redis_pop_str (kb_t kb, const char *name) |
| Pops a single KB string item. More... | |
| static int | redis_get_int (kb_t kb, const char *name) |
| Get a single KB integer item. More... | |
| static char * | redis_get_nvt (kb_t kb, const char *oid, enum kb_nvt_pos position) |
| Get field of a NVT. More... | |
| static nvti_t * | redis_get_nvt_all (kb_t kb, const char *oid) |
| Get a full NVT. More... | |
| static struct kb_item * | redis_get_all (kb_t kb, const char *name) |
| Get all items stored under a given name. More... | |
| static struct kb_item * | redis_get_pattern (kb_t kb, const char *pattern) |
| Get all items stored under a given pattern. More... | |
| static GSList * | redis_get_oids (kb_t kb) |
| Get all NVT OIDs. More... | |
| static size_t | redis_count (kb_t kb, const char *pattern) |
| Count all items stored under a given pattern. More... | |
| static int | redis_del_items (kb_t kb, const char *name) |
| Delete all entries under a given name. More... | |
| static int | redis_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 | redis_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 | redis_set_str (kb_t kb, const char *name, const char *val, size_t len) |
| Set (replace) a new entry under a given name. More... | |
| static int | redis_add_int_unique (kb_t kb, const char *name, int val) |
| Insert (append) a new unique entry under a given name. More... | |
| static int | redis_add_int (kb_t kb, const char *name, int val) |
| Insert (append) a new entry under a given name. More... | |
| static int | redis_set_int (kb_t kb, const char *name, int val) |
| Set (replace) a new entry under a given name. More... | |
| static int | redis_add_nvt (kb_t kb, const nvti_t *nvt, const char *filename) |
| Insert a new nvt. More... | |
| int | redis_save (kb_t kb) |
| Save all the elements from the KB. More... | |
Variables | |
| static const struct kb_operations | KBRedisOperations |
| Default KB operations. More... | |
| const struct kb_operations * | KBDefaultOperations = &KBRedisOperations |
| Default KB operations. No selection mechanism is provided yet since there's only one implementation (redis-based). More... | |
Knowledge base management API - Redis backend.
Contains specialized structures and functions to use redis as a KB server.
| #define _GNU_SOURCE |
| #define G_LOG_DOMAIN "lib kb" |
| #define GLOBAL_DBINDEX_NAME "GVM.__GlobalDBIndex" |
Name of the namespace usage bitmap in redis.
| #define redis_kb | ( | __kb | ) | ((struct kb_redis *) (__kb)) |
|
static |
Set the number of databases have been configured into kbr struct.
| [in] | kbr | Subclass of struct kb where to save the max db index founded. |
|
static |
Get redis context if it is already connected or do a a connection.
| [in] | kbr | Subclass of struct kb where to fetch the context. or where it is saved in case of a new connection. |
| void kb_item_free | ( | struct kb_item * | item | ) |
Release a KB item (or a list).
| [in] | item | Item or list to be release |
|
static |
Fetch a KB item or list from a redis Reply.
| [in] | name | Name of the item. |
| [in] | rep | A redisReply element where to fetch the item. |
|
static |
Give a single KB item.
| [in] | name | Name of the item. |
| [in] | elt | A redisReply element where to fetch the item. |
| [in] | force_int | To force string to integer conversion. |
|
static |
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. |
|
static |
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. |
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. |
|
static |
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. |
|
static |
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. |
|
static |
Execute a redis command and get a redis reply.
| [in] | kbr | Subclass of struct kb to connect to. |
| [in] | fmt | Formatted variable argument list with the cmd to be executed. |
|
static |
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. |
|
static |
Delete all entries under a given name.
| [in] | kb | KB handle where to store the item. |
| [in] | name | Item name. |
|
static |
Delete all entries and release ownership on the namespace.
| [in] | kb | KB handle to release. |
|
static |
Delete all the KB's content.
| [in] | kbr | Subclass of struct kb. |
|
static |
Connect to a Knowledge Base object with the given kb_index.
| [in] | kb_path | Path to KB. |
| [in] | kb_index | DB index |
|
static |
Find an existing Knowledge Base object with key.
| [in] | kb_path | Path to KB. |
| [in] | key | Marker key to search for in KB objects. |
|
static |
Flush all the KB's content. Delete all namespaces.
| [in] | kb | KB handle. |
| [in] | except | Don't flush DB with except key. |
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. |
|
static |
Get a single KB integer item.
| [in] | kb | KB handle where to fetch the item. |
| [in] | name | Name of the element to retrieve. |
|
static |
Return the kb index.
| [in] | kb | KB handle. |
|
static |
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. |
Get a full NVT.
| [in] | kb | KB handle where to store the nvt. |
| [in] | oid | OID of NVT to get. |
|
static |
Get all NVT OIDs.
| [in] | kb | KB handle where to fetch the items. |
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. |
|
static |
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. |
|
static |
Get a single KB string item.
| [in] | kb | KB handle where to fetch the item. |
| [in] | name | Name of the element to retrieve. |
|
static |
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. |
|
static |
Initialize a new Knowledge Base object.
| [in] | kb | Reference to a kb_t to initialize. |
| [in] | kb_path | Path to KB. |
|
static |
Pops a single KB string item.
| [in] | kb | KB handle where to fetch the item. |
| [in] | name | Name of the key from where to retrieve. |
|
static |
Push a new entry under a given key.
| [in] | kb | KB handle where to store the item. |
| [in] | name | Key to push to. |
| [in] | value | Value to push. |
|
static |
Release DB.
| [in] | kbr | Subclass of struct kb. |
| int redis_save | ( | kb_t | kb | ) |
Save all the elements from the KB.
| [in] | kb | KB handle. |
|
static |
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. |
|
static |
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. |
| [in] | len | Value length. Used for blobs. |
|
static |
Test redis connection.
| [in] | kbr | Subclass of struct kb to test. |
|
static |
Select DB.
WARNING: do not call redis_cmd in here, since our context is not fully acquired yet!
| [in] | kbr | Subclass of struct kb where to save the db index. |
|
static |
Attempt to atomically acquire ownership of a database.
| const struct kb_operations* KBDefaultOperations = &KBRedisOperations |
Default KB operations. No selection mechanism is provided yet since there's only one implementation (redis-based).
|
static |
Default KB operations.
No selection mechanism is provided yet since there's only one implementation (redis-based).