Greenbone Vulnerability Management Libraries 22.18.1
|
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>
Go to the source code of this file.
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 "libgvm util" |
GLib logging domain. | |
#define | memdup g_memdup |
#define | GLOBAL_DBINDEX_NAME "GVM.__GlobalDBIndex" |
Name of the namespace usage bitmap in redis. | |
#define | redis_kb(__kb) |
Functions | |
static int | redis_delete_all (struct kb_redis *kbr) |
Delete all the KB's content. | |
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. | |
static int | redis_flush_all (kb_t kb, const char *except) |
Flush all the KB's content. Delete all namespaces. | |
static redisReply * | redis_cmd (struct kb_redis *kbr, const char *fmt,...) |
Execute a redis command and get a redis reply. | |
static int | try_database_index (struct kb_redis *kbr, int index) |
Attempt to atomically acquire ownership of a database. | |
static int | fetch_max_db_index (struct kb_redis *kbr) |
Set the number of databases have been configured into kbr struct. | |
static int | select_database (struct kb_redis *kbr) |
Select DB. | |
static int | redis_release_db (struct kb_redis *kbr) |
Release DB. | |
static char * | parse_port_of_addr (const char *addr, int tcp_indicator_len) |
static redisContext * | connect_redis (const char *addr, int len) |
static int | get_redis_ctx (struct kb_redis *kbr) |
Get redis context if it is already connected or do a a connection. | |
static int | redis_test_connection (struct kb_redis *kbr) |
Test redis connection. | |
static int | redis_delete (kb_t kb) |
Delete all entries and release ownership on the namespace. | |
static int | redis_get_kb_index (kb_t kb) |
Return the kb index. | |
static int | redis_memory_purge (kb_t kb) |
Attempt to purge dirty pages. | |
static int | redis_new (kb_t *kb, const char *kb_path) |
Initialize a new Knowledge Base object. | |
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. | |
static kb_t | redis_find (const char *kb_path, const char *key) |
Find an existing Knowledge Base object with key. | |
void | kb_item_free (struct kb_item *item) |
Release a KB item (or a list). | |
static struct kb_item * | redis2kbitem_single (const char *name, const redisReply *elt, int force_int) |
Give a single KB item. | |
static struct kb_item * | redis2kbitem (const char *name, const redisReply *rep) |
Fetch a KB item or list from a redis Reply. | |
static struct kb_item * | redis_get_single (kb_t kb, const char *name, enum kb_item_type type) |
Get a single KB element. | |
static char * | redis_get_str (kb_t kb, const char *name) |
Get a single KB string item. | |
static int | redis_push_str (kb_t kb, const char *name, const char *value) |
Push a new entry under a given key. | |
static char * | redis_pop_str (kb_t kb, const char *name) |
Pops a single KB string item. | |
static int | redis_get_int (kb_t kb, const char *name) |
Get a single KB integer item. | |
static char * | redis_get_nvt (kb_t kb, const char *oid, enum kb_nvt_pos position) |
Get field of a NVT. | |
static nvti_t * | redis_get_nvt_all (kb_t kb, const char *oid) |
Get a full NVT. | |
static struct kb_item * | redis_get_all (kb_t kb, const char *name) |
Get all items stored under a given name. | |
static struct kb_item * | redis_get_pattern (kb_t kb, const char *pattern) |
Get all items stored under a given pattern. | |
static GSList * | redis_get_oids (kb_t kb) |
Get all NVT OIDs. | |
static size_t | redis_count (kb_t kb, const char *pattern) |
Count all items stored under a given pattern. | |
static int | redis_del_items (kb_t kb, const char *name) |
Delete all entries under a given name. | |
static int | redis_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 | redis_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 | redis_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 | redis_set_str (kb_t kb, const char *name, const char *val, size_t len) |
Set (replace) a new entry under a given name. | |
static int | redis_add_int_unique_volatile (kb_t kb, const char *name, int val, int expire) |
Insert (append) a new unique entry under a given name. | |
static int | redis_add_int_unique (kb_t kb, const char *name, int val) |
Insert (append) a new unique entry under a given name. | |
static int | redis_add_int (kb_t kb, const char *name, int val) |
Insert (append) a new entry under a given name. | |
static int | redis_set_int (kb_t kb, const char *name, int val) |
Set (replace) a new entry under a given name. | |
static int | redis_add_nvt (kb_t kb, const nvti_t *nvt, const char *filename) |
Insert a new nvt. | |
static int | redis_save (kb_t kb) |
Save all the elements from the KB. | |
Variables | |
static const struct kb_operations | KBRedisOperations |
Default KB operations. | |
const struct kb_operations * | KBDefaultOperations = &KBRedisOperations |
Default KB operations. No selection mechanism is provided yet since there's only one implementation (redis-based). | |
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 "libgvm util" |
GLib logging domain.
#define GLOBAL_DBINDEX_NAME "GVM.__GlobalDBIndex" |
Name of the namespace usage bitmap in redis.
#define memdup g_memdup |
#define redis_kb | ( | __kb | ) |
|
static |
|
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 |
|
inlinestatic |
|
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. |
|
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. |
[in] | expire | Item expire. |
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. |
[in] | pos | Which position the value is appended to. 0 for right, 1 for left position in the list. |
|
static |
Insert (append) a new unique and volatile entry under a given name.
[in] | kb | KB handle where to store the item. |
[in] | name | Item name. |
[in] | str | Item value. |
[in] | expire | Item expire. |
[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. |
|
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 |
Attempt to purge dirty pages.
Attempt to purge dirty pages so these can be reclaimed by the allocator. This command only works when using jemalloc as an allocator, and evaluates to a benign NOOP for all others. Command is applied to complete redis instance and not only single db.
[in] | kb | KB handle where to run the command. |
|
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. |
|
static |
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).