|
Greenbone Vulnerability Management Libraries
22.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>
Go to the source code of this file.
|
| 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...
|
| |
|
| 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 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. 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_memory_purge (kb_t kb) |
| | Attempt to purge dirty pages. 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_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. More...
|
| |
| 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. 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_volatile (kb_t kb, const char *name, int val, int expire) |
| | Insert (append) a new unique 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...
|
| |
| static int | redis_save (kb_t kb) |
| | Save all the elements from the KB. More...
|
| |
Knowledge base management API - Redis backend.
Contains specialized structures and functions to use redis as a KB server.
Definition in file kb.c.
◆ _GNU_SOURCE
Definition at line 11 of file kb.c.
◆ G_LOG_DOMAIN
| #define G_LOG_DOMAIN "libgvm util" |
GLib logging domain.
Definition at line 27 of file kb.c.
◆ GLOBAL_DBINDEX_NAME
| #define GLOBAL_DBINDEX_NAME "GVM.__GlobalDBIndex" |
Name of the namespace usage bitmap in redis.
Definition at line 45 of file kb.c.
◆ memdup
Definition at line 32 of file kb.c.
◆ redis_kb
| #define redis_kb |
( |
|
__kb | ) |
((struct kb_redis *) (__kb)) |
Definition at line 62 of file kb.c.
◆ connect_redis()
| static redisContext* connect_redis |
( |
const char * |
addr, |
|
|
int |
len |
|
) |
| |
|
static |
Definition at line 263 of file kb.c.
265 const char *tcp_indicator =
"tcp://";
266 const int tcp_indicator_len = strlen (tcp_indicator);
267 const int redis_default_port = 6379;
271 redisContext *result;
272 static int warn_flag = 0;
274 if (len < tcp_indicator_len + 1)
276 if (memcmp (addr, tcp_indicator, tcp_indicator_len) != 0)
278 host_len = len - tcp_indicator_len;
280 port = redis_default_port;
284 host_len -= strlen (tmp) + 1;
286 host = calloc (1, host_len);
287 memmove (host, addr + tcp_indicator_len, host_len);
288 result = redisConnect (host, port);
291 g_warning (
"A Redis TCP connection is being used. This feature is "
292 "experimental and insecure, since it is not an encrypted "
293 "channel. We discourage its usage in production environments");
299 return redisConnectUnix (addr);
References parse_port_of_addr().
Referenced by get_redis_ctx(), redis_direct_conn(), redis_find(), and redis_flush_all().
◆ fetch_max_db_index()
| static int fetch_max_db_index |
( |
struct kb_redis * |
kbr | ) |
|
|
static |
Set the number of databases have been configured into kbr struct.
- Parameters
-
| [in] | kbr | Subclass of struct kb where to save the max db index founded. |
- Returns
- 0 on success, -1 on error.
Definition at line 109 of file kb.c.
112 redisContext *ctx = kbr->
rctx;
113 redisReply *rep = NULL;
115 rep = redisCommand (ctx,
"CONFIG GET databases");
119 "%s: redis command failed with '%s'", __func__, ctx->errstr);
124 if (rep->type != REDIS_REPLY_ARRAY)
127 "%s: cannot retrieve max DB number: %s", __func__, rep->str);
132 if (rep->elements == 2)
134 kbr->
max_db = (unsigned) atoi (rep->element[1]->str);
139 "%s: unexpected reply length (%zd)", __func__, rep->elements);
144 g_debug (
"%s: maximum DB number: %u", __func__, kbr->
max_db);
148 freeReplyObject (rep);
References G_LOG_DOMAIN, kb_redis::max_db, and kb_redis::rctx.
Referenced by redis_find(), and select_database().
◆ get_redis_ctx()
| static int get_redis_ctx |
( |
struct kb_redis * |
kbr | ) |
|
|
static |
Get redis context if it is already connected or do a a connection.
- Parameters
-
| [in] | kbr | Subclass of struct kb where to fetch the context. or where it is saved in case of a new connection. |
- Returns
- 0 on success, -1 on connection error, -2 on unavailable DB slot.
Definition at line 312 of file kb.c.
316 if (kbr->
rctx != NULL)
320 if (kbr->
rctx == NULL || kbr->
rctx->err)
323 "%s: redis connection error to %s: %s", __func__, kbr->
path,
324 kbr->
rctx ? kbr->
rctx->errstr : strerror (ENOMEM));
325 redisFree (kbr->
rctx);
333 g_log (
G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
"No redis DB available");
334 redisFree (kbr->
rctx);
339 g_debug (
"%s: connected to redis://%s/%d", __func__, kbr->
path, kbr->
db);
References connect_redis(), kb_redis::db, G_LOG_DOMAIN, kb_redis::path, kb_redis::rctx, and select_database().
Referenced by redis_add_int_unique(), redis_add_int_unique_volatile(), redis_add_str_unique(), redis_add_str_unique_volatile(), redis_cmd(), redis_get_pattern(), redis_new(), redis_set_int(), and redis_set_str().
◆ kb_item_free()
| void kb_item_free |
( |
struct kb_item * |
item | ) |
|
◆ parse_port_of_addr()
| static char* parse_port_of_addr |
( |
const char * |
addr, |
|
|
int |
tcp_indicator_len |
|
) |
| |
|
inlinestatic |
Definition at line 250 of file kb.c.
254 if ((tmp = rindex (addr + tcp_indicator_len,
':')) == NULL)
256 is_ip_v6 = addr[tcp_indicator_len] ==
'[';
257 if (is_ip_v6 && (tmp - 1)[0] !=
']')
Referenced by connect_redis().
◆ redis2kbitem()
| static struct kb_item* redis2kbitem |
( |
const char * |
name, |
|
|
const redisReply * |
rep |
|
) |
| |
|
static |
Fetch a KB item or list from a redis Reply.
- Parameters
-
| [in] | name | Name of the item. |
| [in] | rep | A redisReply element where to fetch the item. |
- Returns
- kb_item or list on success, NULL otherwise.
Definition at line 708 of file kb.c.
718 case REDIS_REPLY_STRING:
719 case REDIS_REPLY_INTEGER:
723 case REDIS_REPLY_ARRAY:
724 for (i = 0; i < rep->elements; i++)
742 case REDIS_REPLY_NIL:
743 case REDIS_REPLY_STATUS:
744 case REDIS_REPLY_ERROR:
References kb_item::name, kb_item::next, and redis2kbitem_single().
Referenced by redis_get_all(), and redis_get_pattern().
◆ redis2kbitem_single()
| static struct kb_item* redis2kbitem_single |
( |
const char * |
name, |
|
|
const redisReply * |
elt, |
|
|
int |
force_int |
|
) |
| |
|
static |
Give a single KB item.
- Parameters
-
| [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. |
- Returns
- Single retrieve kb_item on success, NULL otherwise.
Definition at line 663 of file kb.c.
668 if (elt->type != REDIS_REPLY_STRING && elt->type != REDIS_REPLY_INTEGER)
674 if (elt->type == REDIS_REPLY_INTEGER)
677 item->
v_int = elt->integer;
682 item->
v_int = atoi (elt->str);
688 item->
len = elt->len;
References KB_TYPE_INT, KB_TYPE_STR, kb_item::len, memdup, kb_item::name, kb_item::namelen, kb_item::next, kb_item::type, kb_item::v_int, and kb_item::v_str.
Referenced by redis2kbitem(), and redis_get_single().
◆ redis_add_int()
| static int redis_add_int |
( |
kb_t |
kb, |
|
|
const char * |
name, |
|
|
int |
val |
|
) |
| |
|
static |
Insert (append) a new entry under a given name.
- Parameters
-
| [in] | kb | KB handle where to store the item. |
| [in] | name | Item name. |
| [in] | val | Item value. |
- Returns
- 0 on success, non-null on error.
Definition at line 1543 of file kb.c.
1549 if (!rep || rep->type == REDIS_REPLY_ERROR)
1552 freeReplyObject (rep);
References redis_cmd(), and redis_kb.
◆ redis_add_int_unique()
| static int redis_add_int_unique |
( |
kb_t |
kb, |
|
|
const char * |
name, |
|
|
int |
val |
|
) |
| |
|
static |
Insert (append) a new unique entry under a given name.
- Parameters
-
| [in] | kb | KB handle where to store the item. |
| [in] | name | Item name. |
| [in] | val | Item value. |
- Returns
- 0 on success, non-null on error.
Definition at line 1502 of file kb.c.
1513 redisAppendCommand (ctx,
"LREM %s 1 %d", name, val);
1514 redisAppendCommand (ctx,
"RPUSH %s %d", name, val);
1515 redisGetReply (ctx, (
void **) &rep);
1516 if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1517 g_debug (
"Key '%s' already contained integer '%d'", name, val);
1518 freeReplyObject (rep);
1519 redisGetReply (ctx, (
void **) &rep);
1520 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1528 freeReplyObject (rep);
References get_redis_ctx(), kb_redis::rctx, and redis_kb.
◆ redis_add_int_unique_volatile()
| static int redis_add_int_unique_volatile |
( |
kb_t |
kb, |
|
|
const char * |
name, |
|
|
int |
val, |
|
|
int |
expire |
|
) |
| |
|
static |
Insert (append) a new unique entry under a given name.
- Parameters
-
| [in] | kb | KB handle where to store the item. |
| [in] | name | Item name. |
| [in] | val | Item value. |
| [in] | expire | Item expire. |
- Returns
- 0 on success, non-null on error.
Definition at line 1449 of file kb.c.
1460 redisAppendCommand (ctx,
"LREM %s 1 %d", name, val);
1461 redisAppendCommand (ctx,
"RPUSH %s %d", name, val);
1462 redisAppendCommand (ctx,
"EXPIRE %s %d", name, expire);
1464 redisGetReply (ctx, (
void **) &rep);
1465 if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1466 g_debug (
"Key '%s' already contained integer '%d'", name, val);
1467 freeReplyObject (rep);
1469 redisGetReply (ctx, (
void **) &rep);
1470 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1476 redisGetReply (ctx, (
void **) &rep);
1477 if (rep == NULL || rep->type == REDIS_REPLY_ERROR
1478 || (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer != 1))
1480 g_warning (
"%s: Not able to set expire", __func__);
1487 freeReplyObject (rep);
References get_redis_ctx(), kb_redis::rctx, and redis_kb.
◆ redis_add_nvt()
| static int redis_add_nvt |
( |
kb_t |
kb, |
|
|
const nvti_t * |
nvt, |
|
|
const char * |
filename |
|
) |
| |
|
static |
Insert a new nvt.
- Parameters
-
| [in] | kb | KB handle where to store the nvt. |
| [in] | nvt | nvt to store. |
| [in] | filename | Path to nvt to store. |
- Returns
- 0 on success, non-null on error.
Definition at line 1604 of file kb.c.
1607 redisReply *rep = NULL;
1610 gchar *cves, *bids, *xrefs;
1612 if (!nvt || !filename)
1617 xrefs =
nvti_refs (nvt, NULL,
"cve,bid", 1);
1621 kbr,
"RPUSH nvt:%s %s %s %s %s %s %s %s %s %s %s %s %d %s %s",
1635 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1638 freeReplyObject (rep);
1646 rep =
redis_cmd (kbr,
"RPUSH oid:%s:prefs %d|||%s|||%s|||%s",
1649 if (!rep || rep->type == REDIS_REPLY_ERROR)
1652 freeReplyObject (rep);
1654 rep =
redis_cmd (kbr,
"RPUSH filename:%s %lu %s", filename, time (NULL),
1656 if (!rep || rep->type == REDIS_REPLY_ERROR)
1659 freeReplyObject (rep);
References nvti_category(), nvti_dependencies(), nvti_excluded_keys(), nvti_family(), nvti_mandatory_keys(), nvti_name(), nvti_oid(), nvti_pref(), nvti_pref_len(), nvti_refs(), nvti_required_keys(), nvti_required_ports(), nvti_required_udp_ports(), nvti_tag(), nvtpref_default(), nvtpref_id(), nvtpref_name(), nvtpref_type(), redis_cmd(), and redis_kb.
◆ redis_add_str()
| static int redis_add_str |
( |
kb_t |
kb, |
|
|
const char * |
name, |
|
|
const char * |
str, |
|
|
size_t |
len |
|
) |
| |
|
static |
Insert (append) a new entry under a given name.
- Parameters
-
| [in] | kb | KB handle where to store the item. |
| [in] | name | Item name. |
| [in] | str | Item value. |
| [in] | len | Value length. Used for blobs. |
- Returns
- 0 on success, non-null on error.
Definition at line 1378 of file kb.c.
1386 rep =
redis_cmd (kbr,
"RPUSH %s %s", name, str);
1388 rep =
redis_cmd (kbr,
"RPUSH %s %b", name, str, len);
1389 if (!rep || rep->type == REDIS_REPLY_ERROR)
1393 freeReplyObject (rep);
References redis_cmd(), and redis_kb.
◆ redis_add_str_unique()
| static int redis_add_str_unique |
( |
kb_t |
kb, |
|
|
const char * |
name, |
|
|
const char * |
str, |
|
|
size_t |
len, |
|
|
int |
pos |
|
) |
| |
|
static |
Insert (append) a new unique entry under a given name.
- Parameters
-
| [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. |
- Returns
- 0 on success, non-null on error.
Definition at line 1320 of file kb.c.
1324 redisReply *rep = NULL;
1339 redisAppendCommand (ctx,
"LREM %s 1 %s", name, str);
1340 redisAppendCommand (ctx,
"%s %s %s", pos ?
"LPUSH" :
"RPUSH", name, str);
1341 redisGetReply (ctx, (
void **) &rep);
1342 if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1343 g_debug (
"Key '%s' already contained value '%s'", name, str);
1344 freeReplyObject (rep);
1345 redisGetReply (ctx, (
void **) &rep);
1349 redisAppendCommand (ctx,
"LREM %s 1 %b", name, str, len);
1350 redisAppendCommand (ctx,
"%s %s %b", pos ?
"LPUSH" :
"RPUSH", name, str,
1352 redisGetReply (ctx, (
void **) &rep);
1353 if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1354 g_debug (
"Key '%s' already contained string '%s'", name, str);
1355 freeReplyObject (rep);
1356 redisGetReply (ctx, (
void **) &rep);
1358 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1362 freeReplyObject (rep);
References get_redis_ctx(), kb_redis::rctx, and redis_kb.
◆ redis_add_str_unique_volatile()
| static int redis_add_str_unique_volatile |
( |
kb_t |
kb, |
|
|
const char * |
name, |
|
|
const char * |
str, |
|
|
int |
expire, |
|
|
size_t |
len, |
|
|
int |
pos |
|
) |
| |
|
static |
Insert (append) a new unique and volatile entry under a given name.
- Parameters
-
| [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. |
- Returns
- 0 on success, -1 on error.
Definition at line 1227 of file kb.c.
1231 redisReply *rep = NULL;
1246 redisAppendCommand (ctx,
"LREM %s 1 %s", name, str);
1247 redisAppendCommand (ctx,
"%s %s %s", pos ?
"LPUSH" :
"RPUSH", name, str);
1248 redisAppendCommand (ctx,
"EXPIRE %s %d", name, expire);
1250 redisGetReply (ctx, (
void **) &rep);
1251 if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1252 g_debug (
"Key '%s' already contained value '%s'", name, str);
1253 freeReplyObject (rep);
1255 redisGetReply (ctx, (
void **) &rep);
1256 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1262 redisGetReply (ctx, (
void **) &rep);
1263 if (rep == NULL || rep->type == REDIS_REPLY_ERROR
1264 || (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer != 1))
1266 g_warning (
"%s: Not able to set expire", __func__);
1273 redisAppendCommand (ctx,
"LREM %s 1 %b", name, str, len);
1274 redisAppendCommand (ctx,
"%s %s %b", pos ?
"LPUSH" :
"RPUSH", name, str,
1276 redisAppendCommand (ctx,
"EXPIRE %s %d", name, expire);
1278 redisGetReply (ctx, (
void **) &rep);
1279 if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1280 g_debug (
"Key '%s' already contained string '%s'", name, str);
1281 freeReplyObject (rep);
1283 redisGetReply (ctx, (
void **) &rep);
1284 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1290 redisGetReply (ctx, (
void **) &rep);
1291 if (rep == NULL || rep->type == REDIS_REPLY_ERROR
1292 || (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer != 1))
1294 g_warning (
"%s: Not able to set expire", __func__);
1302 freeReplyObject (rep);
References get_redis_ctx(), kb_redis::rctx, and redis_kb.
◆ redis_cmd()
| static redisReply * redis_cmd |
( |
struct kb_redis * |
kbr, |
|
|
const char * |
fmt, |
|
|
|
... |
|
) |
| |
|
static |
Execute a redis command and get a redis reply.
- Parameters
-
| [in] | kbr | Subclass of struct kb to connect to. |
| [in] | fmt | Formatted variable argument list with the cmd to be executed. |
- Returns
- Redis reply on success, NULL otherwise.
Definition at line 761 of file kb.c.
777 rep = redisvCommand (kbr->
rctx, fmt, aq);
783 freeReplyObject (rep);
References get_redis_ctx(), kb_redis::rctx, and redis_lnk_reset().
Referenced by redis_add_int(), redis_add_nvt(), redis_add_str(), redis_count(), redis_del_items(), redis_delete_all(), redis_get_all(), redis_get_nvt(), redis_get_nvt_all(), redis_get_oids(), redis_get_pattern(), redis_get_single(), redis_memory_purge(), redis_pop_str(), redis_push_str(), redis_save(), and redis_test_connection().
◆ redis_count()
| static size_t redis_count |
( |
kb_t |
kb, |
|
|
const char * |
pattern |
|
) |
| |
|
static |
Count all items stored under a given pattern.
- Parameters
-
| [in] | kb | KB handle where to count the items. |
| [in] | pattern | '*' pattern of the elements to count. |
- Returns
- Count of items.
Definition at line 1163 of file kb.c.
1171 rep =
redis_cmd (kbr,
"KEYS %s", pattern);
1175 if (rep->type != REDIS_REPLY_ARRAY)
1177 freeReplyObject (rep);
1181 count = rep->elements;
1182 freeReplyObject (rep);
References redis_cmd(), and redis_kb.
◆ redis_del_items()
| static int redis_del_items |
( |
kb_t |
kb, |
|
|
const char * |
name |
|
) |
| |
|
static |
Delete all entries under a given name.
- Parameters
-
| [in] | kb | KB handle where to store the item. |
| [in] | name | Item name. |
- Returns
- 0 on success, non-null on error.
Definition at line 1195 of file kb.c.
1204 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1208 freeReplyObject (rep);
References redis_cmd(), and redis_kb.
◆ redis_delete()
| static int redis_delete |
( |
kb_t |
kb | ) |
|
|
static |
◆ redis_delete_all()
| int redis_delete_all |
( |
struct kb_redis * |
kbr | ) |
|
|
static |
Delete all the KB's content.
- Parameters
-
| [in] | kbr | Subclass of struct kb. |
- Returns
- 0 on success, non-null on error.
Definition at line 1806 of file kb.c.
1810 struct sigaction new_action, original_action;
1813 new_action.sa_flags = 0;
1814 if (sigemptyset (&new_action.sa_mask))
1816 new_action.sa_handler = SIG_IGN;
1817 if (sigaction (SIGPIPE, &new_action, &original_action))
1821 g_debug (
"%s: deleting all elements from KB #%u", __func__, kbr->
db);
1823 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
1832 if (sigaction (SIGPIPE, &original_action, NULL))
1835 freeReplyObject (rep);
References kb_redis::db, and redis_cmd().
Referenced by redis_delete(), redis_flush_all(), and redis_new().
◆ redis_direct_conn()
| static kb_t redis_direct_conn |
( |
const char * |
kb_path, |
|
|
const int |
kb_index |
|
) |
| |
|
static |
Connect to a Knowledge Base object with the given kb_index.
- Parameters
-
| [in] | kb_path | Path to KB. |
| [in] | kb_index | DB index |
- Returns
- Knowledge Base object, NULL otherwise.
Definition at line 513 of file kb.c.
521 kbr = g_malloc0 (
sizeof (
struct kb_redis));
523 kbr->
path = g_strdup (kb_path);
526 if (kbr->
rctx == NULL || kbr->
rctx->err)
529 "%s: redis connection error to %s: %s", __func__, kbr->
path,
530 kbr->
rctx ? kbr->
rctx->errstr : strerror (ENOMEM));
531 redisFree (kbr->
rctx);
537 rep = redisCommand (kbr->
rctx,
"SELECT %d", kb_index);
538 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
541 freeReplyObject (rep);
542 redisFree (kbr->
rctx);
548 freeReplyObject (rep);
References connect_redis(), kb_redis::db, G_LOG_DOMAIN, kb_redis::kb, kb::kb_ops, KBRedisOperations, kb_redis::path, and kb_redis::rctx.
◆ redis_find()
| static kb_t redis_find |
( |
const char * |
kb_path, |
|
|
const char * |
key |
|
) |
| |
|
static |
Find an existing Knowledge Base object with key.
- Parameters
-
| [in] | kb_path | Path to KB. |
| [in] | key | Marker key to search for in KB objects. |
- Returns
- Knowledge Base object, NULL otherwise.
Definition at line 561 of file kb.c.
569 kbr = g_malloc0 (
sizeof (
struct kb_redis));
571 kbr->
path = g_strdup (kb_path);
578 if (kbr->
rctx == NULL || kbr->
rctx->err)
581 "%s: redis connection error to %s: %s", __func__, kbr->
path,
582 kbr->
rctx ? kbr->
rctx->errstr : strerror (ENOMEM));
583 redisFree (kbr->
rctx);
594 if (rep == NULL || rep->type != REDIS_REPLY_INTEGER || rep->integer != 1)
597 freeReplyObject (rep);
599 redisFree (kbr->
rctx);
603 freeReplyObject (rep);
604 rep = redisCommand (kbr->
rctx,
"SELECT %u", i);
605 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
607 redisFree (kbr->
rctx);
612 freeReplyObject (rep);
622 redisFree (kbr->
rctx);
References connect_redis(), kb_redis::db, fetch_max_db_index(), G_LOG_DOMAIN, GLOBAL_DBINDEX_NAME, kb_redis::kb, kb_item_get_str(), kb::kb_ops, KBRedisOperations, kb_redis::max_db, kb_redis::path, and kb_redis::rctx.
◆ redis_flush_all()
| static int redis_flush_all |
( |
kb_t |
kb, |
|
|
const char * |
except |
|
) |
| |
|
static |
Flush all the KB's content. Delete all namespaces.
- Parameters
-
| [in] | kb | KB handle. |
| [in] | except | Don't flush DB with except key. |
- Returns
- 0 on success, non-null on error.
Definition at line 1696 of file kb.c.
1703 redisFree (kbr->
rctx);
1705 g_debug (
"%s: deleting all DBs at %s except %s", __func__, kbr->
path, except);
1711 if (kbr->
rctx == NULL || kbr->
rctx->err)
1714 "%s: redis connection error to %s: %s", __func__, kbr->
path,
1715 kbr->
rctx ? kbr->
rctx->errstr : strerror (ENOMEM));
1716 redisFree (kbr->
rctx);
1723 if (rep == NULL || rep->type != REDIS_REPLY_INTEGER || rep->integer != 1)
1725 freeReplyObject (rep);
1726 redisFree (kbr->
rctx);
1730 freeReplyObject (rep);
1731 rep = redisCommand (kbr->
rctx,
"SELECT %u", i);
1732 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
1734 freeReplyObject (rep);
1735 redisFree (kbr->
rctx);
1740 freeReplyObject (rep);
1749 redisFree (kbr->
rctx);
1755 redisFree (kbr->
rctx);
References connect_redis(), kb_redis::db, G_LOG_DOMAIN, GLOBAL_DBINDEX_NAME, kb_item_get_str(), kb_redis::max_db, kb_redis::path, kb_redis::rctx, redis_delete_all(), redis_kb, and redis_release_db().
◆ redis_get_all()
| static struct kb_item* redis_get_all |
( |
kb_t |
kb, |
|
|
const char * |
name |
|
) |
| |
|
static |
Get all items stored under a given name.
- Parameters
-
| [in] | kb | KB handle where to fetch the items. |
| [in] | name | Name of the elements to retrieve. |
- Returns
- Linked struct kb_item instances to be freed with kb_item_free() or NULL if no element was found or on error.
Definition at line 1035 of file kb.c.
1049 freeReplyObject (rep);
References kb_item::name, redis2kbitem(), redis_cmd(), and redis_kb.
◆ redis_get_int()
| static int redis_get_int |
( |
kb_t |
kb, |
|
|
const char * |
name |
|
) |
| |
|
static |
◆ redis_get_kb_index()
| static int redis_get_kb_index |
( |
kb_t |
kb | ) |
|
|
static |
Return the kb index.
- Parameters
-
- Returns
- kb_index on success, null on error.
Definition at line 420 of file kb.c.
◆ redis_get_nvt()
| static char* redis_get_nvt |
( |
kb_t |
kb, |
|
|
const char * |
oid, |
|
|
enum kb_nvt_pos |
position |
|
) |
| |
|
static |
Get field of a NVT.
- Parameters
-
| [in] | kb | KB handle where to store the nvt. |
| [in] | oid | OID of NVT to get from. |
| [in] | position | Position of field to get. |
- Returns
- Value of field, NULL otherwise.
Definition at line 953 of file kb.c.
961 rep =
redis_cmd (kbr,
"LINDEX filename:%s %d", oid,
964 rep =
redis_cmd (kbr,
"LINDEX nvt:%s %d", oid, position);
967 if (rep->type == REDIS_REPLY_INTEGER)
968 res = g_strdup_printf (
"%lld", rep->integer);
969 else if (rep->type == REDIS_REPLY_STRING)
970 res = g_strdup (rep->str);
971 freeReplyObject (rep);
References NVT_TIMESTAMP_POS, redis_cmd(), and redis_kb.
◆ redis_get_nvt_all()
| static nvti_t* redis_get_nvt_all |
( |
kb_t |
kb, |
|
|
const char * |
oid |
|
) |
| |
|
static |
Get a full NVT.
- Parameters
-
| [in] | kb | KB handle where to store the nvt. |
| [in] | oid | OID of NVT to get. |
- Returns
- nvti_t of NVT, NULL otherwise.
Definition at line 985 of file kb.c.
995 if (rep->type != REDIS_REPLY_ARRAY || rep->elements !=
NVT_NAME_POS + 1)
997 freeReplyObject (rep);
1020 freeReplyObject (rep);
References NVT_BIDS_POS, NVT_CATEGORY_POS, NVT_CVES_POS, NVT_DEPENDENCIES_POS, NVT_EXCLUDED_KEYS_POS, NVT_FAMILY_POS, NVT_FILENAME_POS, NVT_MANDATORY_KEYS_POS, NVT_NAME_POS, NVT_REQUIRED_KEYS_POS, NVT_REQUIRED_PORTS_POS, NVT_REQUIRED_UDP_PORTS_POS, NVT_TAGS_POS, NVT_XREFS_POS, nvti_add_refs(), nvti_new(), nvti_set_category(), nvti_set_dependencies(), nvti_set_excluded_keys(), nvti_set_family(), nvti_set_mandatory_keys(), nvti_set_name(), nvti_set_oid(), nvti_set_required_keys(), nvti_set_required_ports(), nvti_set_required_udp_ports(), nvti_set_tag(), redis_cmd(), and redis_kb.
◆ redis_get_oids()
| static GSList* redis_get_oids |
( |
kb_t |
kb | ) |
|
|
static |
Get all NVT OIDs.
- Parameters
-
| [in] | kb | KB handle where to fetch the items. |
- Returns
- Linked list of all OIDs or NULL.
Definition at line 1128 of file kb.c.
1132 GSList *list = NULL;
1140 if (rep->type != REDIS_REPLY_ARRAY)
1142 freeReplyObject (rep);
1147 for (i = 0; i < rep->elements; i++)
1148 list = g_slist_prepend (list, g_strdup (rep->element[i]->str + 4));
1149 freeReplyObject (rep);
References redis_cmd(), and redis_kb.
◆ redis_get_pattern()
| static struct kb_item* redis_get_pattern |
( |
kb_t |
kb, |
|
|
const char * |
pattern |
|
) |
| |
|
static |
Get all items stored under a given pattern.
- Parameters
-
| [in] | kb | KB handle where to fetch the items. |
| [in] | pattern | '*' pattern of the elements to retrieve. |
- Returns
- Linked struct kb_item instances to be freed with kb_item_free() or NULL if no element was found or on error.
Definition at line 1064 of file kb.c.
1072 rep =
redis_cmd (kbr,
"KEYS %s", pattern);
1075 if (rep->type != REDIS_REPLY_ARRAY)
1077 freeReplyObject (rep);
1083 for (i = 0; i < rep->elements; i++)
1084 redisAppendCommand (kbr->
rctx,
"LRANGE %s 0 -1", rep->element[i]->str);
1086 for (i = 0; i < rep->elements; i++)
1089 redisReply *rep_range;
1091 redisGetReply (kbr->
rctx, (
void **) &rep_range);
1097 freeReplyObject (rep_range);
1113 freeReplyObject (rep_range);
1116 freeReplyObject (rep);
References get_redis_ctx(), kb_item::next, kb_redis::rctx, redis2kbitem(), redis_cmd(), and redis_kb.
◆ redis_get_single()
◆ redis_get_str()
| static char* redis_get_str |
( |
kb_t |
kb, |
|
|
const char * |
name |
|
) |
| |
|
static |
◆ redis_lnk_reset()
| static int redis_lnk_reset |
( |
kb_t |
kb | ) |
|
|
static |
Reset connection to the KB. This is called after each fork() to make sure connections aren't shared between concurrent processes.
- Parameters
-
- Returns
- 0 on success, non-null on error.
Definition at line 1672 of file kb.c.
1678 if (kbr->
rctx != NULL)
1680 redisFree (kbr->
rctx);
References kb_redis::rctx, and redis_kb.
Referenced by redis_cmd().
◆ redis_memory_purge()
| static int redis_memory_purge |
( |
kb_t |
kb | ) |
|
|
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.
- Parameters
-
| [in] | kb | KB handle where to run the command. |
- Returns
- 0 on success, non-null on error.
Definition at line 442 of file kb.c.
448 if (!rep || rep->type == REDIS_REPLY_ERROR)
451 freeReplyObject (rep);
References redis_cmd(), and redis_kb.
Referenced by redis_new().
◆ redis_new()
| static int redis_new |
( |
kb_t * |
kb, |
|
|
const char * |
kb_path |
|
) |
| |
|
static |
Initialize a new Knowledge Base object.
- Parameters
-
| [in] | kb | Reference to a kb_t to initialize. |
| [in] | kb_path | Path to KB. |
- Returns
- 0 on success, -1 on connection error, -2 when no DB is available, -3 when given kb_path was NULL.
Definition at line 466 of file kb.c.
474 kbr = g_malloc0 (
sizeof (
struct kb_redis));
476 kbr->
path = g_strdup (kb_path);
486 "%s: cannot access redis at '%s'", __func__, kb_path);
499 g_warning (
"%s: Memory purge was not successful", __func__);
References G_LOG_DOMAIN, get_redis_ctx(), kb_redis::kb, kb::kb_ops, KBRedisOperations, kb_redis::path, redis_delete(), redis_delete_all(), redis_memory_purge(), and redis_test_connection().
◆ redis_pop_str()
| static char* redis_pop_str |
( |
kb_t |
kb, |
|
|
const char * |
name |
|
) |
| |
|
static |
Pops a single KB string item.
- Parameters
-
| [in] | kb | KB handle where to fetch the item. |
| [in] | name | Name of the key from where to retrieve. |
- Returns
- A string to be freed or NULL if list is empty or on error.
Definition at line 900 of file kb.c.
911 if (rep->type == REDIS_REPLY_STRING)
912 value = g_strdup (rep->str);
913 freeReplyObject (rep);
References redis_cmd(), and redis_kb.
◆ redis_push_str()
| static int redis_push_str |
( |
kb_t |
kb, |
|
|
const char * |
name, |
|
|
const char * |
value |
|
) |
| |
|
static |
Push a new entry under a given key.
- Parameters
-
| [in] | kb | KB handle where to store the item. |
| [in] | name | Key to push to. |
| [in] | value | Value to push. |
- Returns
- 0 on success, non-null on error.
Definition at line 871 of file kb.c.
874 redisReply *rep = NULL;
881 rep =
redis_cmd (kbr,
"LPUSH %s %s", name, value);
882 if (!rep || rep->type == REDIS_REPLY_ERROR)
886 freeReplyObject (rep);
References redis_cmd(), and redis_kb.
◆ redis_release_db()
| static int redis_release_db |
( |
struct kb_redis * |
kbr | ) |
|
|
static |
Release DB.
- Parameters
-
| [in] | kbr | Subclass of struct kb. |
- Returns
- 0 on success, -1 on error.
Definition at line 216 of file kb.c.
219 redisContext *ctx = kbr->
rctx;
225 rep = redisCommand (ctx,
"SELECT 0");
226 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
231 freeReplyObject (rep);
234 if (rep == NULL || rep->type != REDIS_REPLY_INTEGER)
244 freeReplyObject (rep);
References kb_redis::db, GLOBAL_DBINDEX_NAME, and kb_redis::rctx.
Referenced by redis_delete(), and redis_flush_all().
◆ redis_save()
| static int redis_save |
( |
kb_t |
kb | ) |
|
|
static |
Save all the elements from the KB.
- Parameters
-
- Returns
- 0 on success, -1 on error.
Definition at line 1774 of file kb.c.
1781 g_debug (
"%s: saving all elements from KB #%u", __func__, kbr->
db);
1783 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
1793 freeReplyObject (rep);
References kb_redis::db, redis_cmd(), and redis_kb.
◆ redis_set_int()
| static int redis_set_int |
( |
kb_t |
kb, |
|
|
const char * |
name, |
|
|
int |
val |
|
) |
| |
|
static |
Set (replace) a new entry under a given name.
- Parameters
-
| [in] | kb | KB handle where to store the item. |
| [in] | name | Item name. |
| [in] | val | Item value. |
- Returns
- 0 on success, non-null on error.
Definition at line 1567 of file kb.c.
1570 redisReply *rep = NULL;
1578 redisAppendCommand (ctx,
"MULTI");
1579 redisAppendCommand (ctx,
"DEL %s", name);
1580 redisAppendCommand (ctx,
"RPUSH %s %d", name, val);
1581 redisAppendCommand (ctx,
"EXEC");
1584 redisGetReply (ctx, (
void **) &rep);
1585 if (!rep || rep->type == REDIS_REPLY_ERROR)
1588 freeReplyObject (rep);
References get_redis_ctx(), kb_redis::rctx, and redis_kb.
◆ redis_set_str()
| static int redis_set_str |
( |
kb_t |
kb, |
|
|
const char * |
name, |
|
|
const char * |
val, |
|
|
size_t |
len |
|
) |
| |
|
static |
Set (replace) a new entry under a given name.
- Parameters
-
| [in] | kb | KB handle where to store the item. |
| [in] | name | Item name. |
| [in] | val | Item value. |
| [in] | len | Value length. Used for blobs. |
- Returns
- 0 on success, non-null on error.
Definition at line 1408 of file kb.c.
1411 redisReply *rep = NULL;
1419 redisAppendCommand (ctx,
"MULTI");
1420 redisAppendCommand (ctx,
"DEL %s", name);
1422 redisAppendCommand (ctx,
"RPUSH %s %s", name, val);
1424 redisAppendCommand (ctx,
"RPUSH %s %b", name, val, len);
1425 redisAppendCommand (ctx,
"EXEC");
1428 redisGetReply (ctx, (
void **) &rep);
1429 if (!rep || rep->type == REDIS_REPLY_ERROR)
1432 freeReplyObject (rep);
References get_redis_ctx(), kb_redis::rctx, and redis_kb.
◆ redis_test_connection()
| static int redis_test_connection |
( |
struct kb_redis * |
kbr | ) |
|
|
static |
Test redis connection.
- Parameters
-
| [in] | kbr | Subclass of struct kb to test. |
- Returns
- 0 on success, negative integer on error.
Definition at line 351 of file kb.c.
365 if (rep->type != REDIS_REPLY_STATUS)
371 if (g_ascii_strcasecmp (rep->str,
"PONG"))
379 freeReplyObject (rep);
References redis_cmd().
Referenced by redis_new().
◆ select_database()
| static int select_database |
( |
struct kb_redis * |
kbr | ) |
|
|
static |
Select DB.
WARNING: do not call redis_cmd in here, since our context is not fully acquired yet!
- Parameters
-
| [in] | kbr | Subclass of struct kb where to save the db index. |
- Returns
- 0 on success, -1 on error.
Definition at line 164 of file kb.c.
167 redisContext *ctx = kbr->
rctx;
168 redisReply *rep = NULL;
177 for (i = 1; i < kbr->
max_db; i++)
192 rep = redisCommand (ctx,
"SELECT %u", kbr->
db);
193 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
203 freeReplyObject (rep);
References kb_redis::db, fetch_max_db_index(), kb_redis::max_db, kb_redis::rctx, and try_database_index().
Referenced by get_redis_ctx().
◆ try_database_index()
| static int try_database_index |
( |
struct kb_redis * |
kbr, |
|
|
int |
index |
|
) |
| |
|
static |
Attempt to atomically acquire ownership of a database.
- Returns
- 0 on success, negative integer otherwise.
Definition at line 78 of file kb.c.
80 redisContext *ctx = kbr->
rctx;
88 if (rep->type != REDIS_REPLY_INTEGER)
90 else if (rep->integer == 0)
95 freeReplyObject (rep);
References kb_redis::db, GLOBAL_DBINDEX_NAME, and kb_redis::rctx.
Referenced by select_database().
◆ KBDefaultOperations
◆ KBRedisOperations
const nvtpref_t * nvti_pref(const nvti_t *n, guint p)
Get the n'th preferences of the NVT.
int nvti_set_required_udp_ports(nvti_t *n, const gchar *required_udp_ports)
Set the required udp ports of a NVT.
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 char * kb_item_get_str(kb_t kb, const char *name)
Get a single KB string item.
static struct kb_item * redis_get_all(kb_t kb, const char *name)
Get all items stored under a given name.
static redisReply * redis_cmd(struct kb_redis *kbr, const char *fmt,...)
Execute a redis command and get a redis reply.
int nvti_set_required_keys(nvti_t *n, const gchar *required_keys)
Set the required keys of a NVT.
gchar * nvti_family(const nvti_t *n)
Get the family name.
gchar * nvti_oid(const nvti_t *n)
Get the OID string.
static int redis_push_str(kb_t kb, const char *name, const char *value)
Push a new entry under a given key.
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 int redis_del_items(kb_t kb, const char *name)
Delete all entries under a given name.
static char * redis_get_str(kb_t kb, const char *name)
Get a single KB string item.
static GSList * redis_get_oids(kb_t kb)
Get all NVT OIDs.
static int redis_new(kb_t *kb, const char *kb_path)
Initialize a new Knowledge Base object.
static struct kb_item * redis_get_pattern(kb_t kb, const char *pattern)
Get all items stored under a given pattern.
static struct kb_item * redis2kbitem_single(const char *name, const redisReply *elt, int force_int)
Give a single KB item.
static int try_database_index(struct kb_redis *kbr, int index)
Attempt to atomically acquire ownership of a database.
static redisContext * connect_redis(const char *addr, int len)
int nvtpref_id(const nvtpref_t *np)
Get the ID of a NVT Preference.
static int redis_delete_all(struct kb_redis *)
Delete all the KB's content.
int nvti_set_name(nvti_t *n, const gchar *name)
Set the name of a NVT.
static int redis_lnk_reset(kb_t)
Reset connection to the KB. This is called after each fork() to make sure connections aren't shared b...
Knowledge base item (defined by name, type (int/char*) and value). Implemented as a singly linked lis...
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.
gchar * nvti_refs(const nvti_t *n, const gchar *type, const gchar *exclude_types, guint use_types)
Get references as string.
gchar * nvti_required_udp_ports(const nvti_t *n)
Get the required udp ports list.
The structure of a information record that corresponds to a NVT.
gchar * nvti_required_ports(const nvti_t *n)
Get the required ports list.
@ NVT_REQUIRED_UDP_PORTS_POS
gint nvti_category(const nvti_t *n)
Get the category for this NVT.
int nvti_set_excluded_keys(nvti_t *n, const gchar *excluded_keys)
Set the excluded keys of a NVT.
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.
void kb_item_free(struct kb_item *item)
Release a KB item (or a list).
static int redis_get_int(kb_t kb, const char *name)
Get a single KB integer item.
int nvti_add_refs(nvti_t *n, const gchar *type, const gchar *ref_ids, const gchar *ref_text)
Add many new vtref from a comma-separated list.
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.
The structure for a preference of a NVT.
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_set_str(kb_t kb, const char *name, const char *val, size_t len)
Set (replace) a new entry under a given name.
guint nvti_pref_len(const nvti_t *n)
Get the number of preferences of the NVT.
static int redis_release_db(struct kb_redis *kbr)
Release DB.
const struct kb_operations * kb_ops
int nvti_set_dependencies(nvti_t *n, const gchar *dependencies)
Set the dependencies of a NVT.
static int redis_add_nvt(kb_t kb, const nvti_t *nvt, const char *filename)
Insert a new nvt.
Subclass of struct kb, it contains the redis-specific fields, such as the redis context,...
static int redis_flush_all(kb_t, const char *)
Flush all the KB's content. Delete all namespaces.
static int redis_delete(kb_t kb)
Delete all entries and release ownership on the namespace.
gchar * nvti_tag(const nvti_t *n)
Get the tags.
int nvti_set_tag(nvti_t *n, const gchar *tag)
Set the tags of a NVT.
static char * redis_get_nvt(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
static char * redis_pop_str(kb_t kb, const char *name)
Pops a single KB string item.
Top-level KB. This is to be inherited by KB implementations.
gchar * nvtpref_name(const nvtpref_t *np)
Get the Name of a NVT Preference.
gchar * nvti_mandatory_keys(const nvti_t *n)
Get the mandatory keys list.
static int redis_save(kb_t kb)
Save all the elements from the KB.
static char * parse_port_of_addr(const char *addr, int tcp_indicator_len)
gchar * nvti_dependencies(const nvti_t *n)
Get the dependencies list.
static struct kb_item * redis2kbitem(const char *name, const redisReply *rep)
Fetch a KB item or list from a redis Reply.
gchar * nvti_name(const nvti_t *n)
Get the name.
static size_t redis_count(kb_t kb, const char *pattern)
Count all items stored under a given pattern.
static int select_database(struct kb_redis *kbr)
Select DB.
static const struct kb_operations KBRedisOperations
Default KB operations.
static struct kb_item * redis_get_single(kb_t kb, const char *name, enum kb_item_type type)
Get a single KB element.
gchar * nvti_excluded_keys(const nvti_t *n)
Get the excluded keys list.
static kb_t redis_find(const char *kb_path, const char *key)
Find an existing Knowledge Base object with key.
static int redis_add_int_unique(kb_t kb, const char *name, int val)
Insert (append) a new unique entry under a given name.
int nvti_set_required_ports(nvti_t *n, const gchar *required_ports)
Set the required ports of a NVT.
gchar * nvtpref_default(const nvtpref_t *np)
Get the Default of a NVT Preference.
#define GLOBAL_DBINDEX_NAME
Name of the namespace usage bitmap in redis.
nvti_t * nvti_new(void)
Create a new (empty) nvti structure.
gchar * nvtpref_type(const nvtpref_t *np)
Get the Type of a NVT Preference.
int nvti_set_family(nvti_t *n, const gchar *family)
Set the family of a NVT.
struct kb * kb_t
type abstraction to hide KB internals.
int nvti_set_category(nvti_t *n, const gint category)
Set the category type of a NVT Info.
#define G_LOG_DOMAIN
GLib logging domain.
static nvti_t * redis_get_nvt_all(kb_t kb, const char *oid)
Get a full NVT.
int nvti_set_oid(nvti_t *n, const gchar *oid)
Set the OID of a NVT Info.
static int redis_test_connection(struct kb_redis *kbr)
Test redis connection.
static int fetch_max_db_index(struct kb_redis *kbr)
Set the number of databases have been configured into kbr struct.
int nvti_set_mandatory_keys(nvti_t *n, const gchar *mandatory_keys)
Set the mandatory keys of a NVT.
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_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_set_int(kb_t kb, const char *name, int val)
Set (replace) a new entry under a given name.
gchar * nvti_required_keys(const nvti_t *n)
Get the required keys list.