Greenbone Vulnerability Management Libraries  11.0.0
kb.c File Reference

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>
Include dependency graph for kb.c:

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   "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_itemredis2kbitem_single (const char *name, const redisReply *elt, int force_int)
 Give a single KB item. More...
 
static struct kb_itemredis2kbitem (const char *name, const redisReply *rep)
 Fetch a KB item or list from a redis Reply. More...
 
static struct kb_itemredis_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_tredis_get_nvt_all (kb_t kb, const char *oid)
 Get a full NVT. More...
 
static struct kb_itemredis_get_all (kb_t kb, const char *name)
 Get all items stored under a given name. More...
 
static struct kb_itemredis_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. No selection mechanism is provided yet since there's only one implementation (redis-based). More...
 
const struct kb_operationsKBDefaultOperations = &KBRedisOperations
 Default KB operations. No selection mechanism is provided yet since there's only one implementation (redis-based). More...
 

Detailed Description

Knowledge base management API - Redis backend.

Contains specialized structures and functions to use redis as a KB server.

Definition in file kb.c.

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 25 of file kb.c.

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "lib kb"

Definition at line 38 of file kb.c.

◆ GLOBAL_DBINDEX_NAME

#define GLOBAL_DBINDEX_NAME   "GVM.__GlobalDBIndex"

Name of the namespace usage bitmap in redis.

Definition at line 50 of file kb.c.

◆ redis_kb

#define redis_kb (   __kb)    ((struct kb_redis *) (__kb))

Definition at line 67 of file kb.c.

Function Documentation

◆ 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]kbrSubclass of struct kb where to save the max db index founded.
Returns
0 on success, -1 on error.

Definition at line 111 of file kb.c.

112 {
113  int rc = 0;
114  redisContext *ctx = kbr->rctx;
115  redisReply *rep = NULL;
116 
117  rep = redisCommand (ctx, "CONFIG GET databases");
118  if (rep == NULL)
119  {
120  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
121  "%s: redis command failed with '%s'", __func__, ctx->errstr);
122  rc = -1;
123  goto err_cleanup;
124  }
125 
126  if (rep->type != REDIS_REPLY_ARRAY)
127  {
128  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
129  "%s: cannot retrieve max DB number: %s", __func__, rep->str);
130  rc = -1;
131  goto err_cleanup;
132  }
133 
134  if (rep->elements == 2)
135  {
136  kbr->max_db = (unsigned) atoi (rep->element[1]->str);
137  }
138  else
139  {
140  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
141  "%s: unexpected reply length (%zd)", __func__, rep->elements);
142  rc = -1;
143  goto err_cleanup;
144  }
145 
146  g_debug ("%s: maximum DB number: %u", __func__, kbr->max_db);
147 
148 err_cleanup:
149  if (rep != NULL)
150  freeReplyObject (rep);
151 
152  return rc;
153 }

References G_LOG_DOMAIN, kb_redis::max_db, and kb_redis::rctx.

Referenced by redis_find(), and select_database().

Here is the caller graph for this function:

◆ 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]kbrSubclass 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 256 of file kb.c.

257 {
258  int rc;
259 
260  if (kbr->rctx != NULL)
261  return 0;
262 
263  kbr->rctx = redisConnectUnix (kbr->path);
264  if (kbr->rctx == NULL || kbr->rctx->err)
265  {
266  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
267  "%s: redis connection error to %s: %s", __func__, kbr->path,
268  kbr->rctx ? kbr->rctx->errstr : strerror (ENOMEM));
269  redisFree (kbr->rctx);
270  kbr->rctx = NULL;
271  return -1;
272  }
273 
274  rc = select_database (kbr);
275  if (rc)
276  {
277  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "No redis DB available");
278  redisFree (kbr->rctx);
279  kbr->rctx = NULL;
280  return -2;
281  }
282 
283  g_debug ("%s: connected to redis://%s/%d", __func__, kbr->path, kbr->db);
284  return 0;
285 }

References kb_redis::db, G_LOG_DOMAIN, kb_redis::path, kb_redis::rctx, and select_database().

Referenced by redis_add_int_unique(), redis_add_str_unique(), redis_cmd(), redis_get_pattern(), redis_new(), redis_set_int(), and redis_set_str().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kb_item_free()

void kb_item_free ( struct kb_item item)

Release a KB item (or a list).

Parameters
[in]itemItem or list to be release

Definition at line 516 of file kb.c.

517 {
518  while (item != NULL)
519  {
520  struct kb_item *next;
521 
522  next = item->next;
523  if (item->type == KB_TYPE_STR && item->v_str != NULL)
524  g_free (item->v_str);
525  g_free (item);
526  item = next;
527  }
528 }

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().

Here is the caller graph for this function:

◆ 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]nameName of the item.
[in]repA redisReply element where to fetch the item.
Returns
kb_item or list on success, NULL otherwise.

Definition at line 580 of file kb.c.

581 {
582  struct kb_item *kbi;
583 
584  kbi = NULL;
585 
586  switch (rep->type)
587  {
588  unsigned int i;
589 
590  case REDIS_REPLY_STRING:
591  case REDIS_REPLY_INTEGER:
592  kbi = redis2kbitem_single (name, rep, 0);
593  break;
594 
595  case REDIS_REPLY_ARRAY:
596  for (i = 0; i < rep->elements; i++)
597  {
598  struct kb_item *tmpitem;
599 
600  tmpitem = redis2kbitem_single (name, rep->element[i], 0);
601  if (tmpitem == NULL)
602  break;
603 
604  if (kbi != NULL)
605  {
606  tmpitem->next = kbi;
607  kbi = tmpitem;
608  }
609  else
610  kbi = tmpitem;
611  }
612  break;
613 
614  case REDIS_REPLY_NIL:
615  case REDIS_REPLY_STATUS:
616  case REDIS_REPLY_ERROR:
617  default:
618  break;
619  }
620 
621  return kbi;
622 }

References kb_item::name, kb_item::next, and redis2kbitem_single().

Referenced by redis_get_all(), and redis_get_pattern().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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]nameName of the item.
[in]eltA redisReply element where to fetch the item.
[in]force_intTo force string to integer conversion.
Returns
Single retrieve kb_item on success, NULL otherwise.

Definition at line 538 of file kb.c.

539 {
540  struct kb_item *item;
541  size_t namelen;
542 
543  if (elt->type != REDIS_REPLY_STRING && elt->type != REDIS_REPLY_INTEGER)
544  return NULL;
545 
546  namelen = strlen (name) + 1;
547 
548  item = g_malloc0 (sizeof (struct kb_item) + namelen);
549  if (elt->type == REDIS_REPLY_INTEGER)
550  {
551  item->type = KB_TYPE_INT;
552  item->v_int = elt->integer;
553  }
554  else if (force_int)
555  {
556  item->type = KB_TYPE_INT;
557  item->v_int = atoi (elt->str);
558  }
559  else
560  {
561  item->type = KB_TYPE_STR;
562  item->v_str = g_memdup (elt->str, elt->len + 1);
563  item->len = elt->len;
564  }
565 
566  item->next = NULL;
567  item->namelen = namelen;
568  strncpy (item->name, name, namelen);
569 
570  return item;
571 }

References KB_TYPE_INT, KB_TYPE_STR, kb_item::len, 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().

Here is the caller graph for this function:

◆ 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]kbKB handle where to store the item.
[in]nameItem name.
[in]valItem value.
Returns
0 on success, non-null on error.

Definition at line 1228 of file kb.c.

1229 {
1230  redisReply *rep;
1231  int rc = 0;
1232 
1233  rep = redis_cmd (redis_kb (kb), "RPUSH %s %d", name, val);
1234  if (!rep || rep->type == REDIS_REPLY_ERROR)
1235  rc = -1;
1236  if (rep)
1237  freeReplyObject (rep);
1238 
1239  return rc;
1240 }

References redis_cmd(), and redis_kb.

Here is the call graph for this function:

◆ 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]kbKB handle where to store the item.
[in]nameItem name.
[in]valItem value.
Returns
0 on success, non-null on error.

Definition at line 1189 of file kb.c.

1190 {
1191  struct kb_redis *kbr;
1192  redisReply *rep;
1193  int rc = 0;
1194  redisContext *ctx;
1195 
1196  kbr = redis_kb (kb);
1197  if (get_redis_ctx (kbr) < 0)
1198  return -1;
1199  ctx = kbr->rctx;
1200  redisAppendCommand (ctx, "LREM %s 1 %d", name, val);
1201  redisAppendCommand (ctx, "RPUSH %s %d", name, val);
1202  redisGetReply (ctx, (void **) &rep);
1203  if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1204  g_debug ("Key '%s' already contained integer '%d'", name, val);
1205  freeReplyObject (rep);
1206  redisGetReply (ctx, (void **) &rep);
1207  if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1208  {
1209  rc = -1;
1210  goto out;
1211  }
1212 
1213 out:
1214  if (rep != NULL)
1215  freeReplyObject (rep);
1216 
1217  return rc;
1218 }

References get_redis_ctx(), kb_redis::rctx, and redis_kb.

Here is the call graph for this function:

◆ 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]kbKB handle where to store the nvt.
[in]nvtnvt to store.
[in]filenamePath to nvt to store.
Returns
0 on success, non-null on error.

Definition at line 1285 of file kb.c.

1286 {
1287  struct kb_redis *kbr;
1288  redisReply *rep = NULL;
1289  int rc = 0;
1290  unsigned int i;
1291  gchar *cves, *bids, *xrefs;
1292 
1293  if (!nvt || !filename)
1294  return -1;
1295 
1296  cves = nvti_refs (nvt, "cve", "", 0);
1297  bids = nvti_refs (nvt, "bid", "", 0);
1298  xrefs = nvti_refs (nvt, NULL, "cve,bid", 1);
1299 
1300  kbr = redis_kb (kb);
1301  rep = redis_cmd (
1302  kbr, "RPUSH nvt:%s %s %s %s %s %s %s %s %s %s %s %s %d %d %s %s",
1303  nvti_oid (nvt), filename, nvti_required_keys (nvt) ?: "",
1304  nvti_mandatory_keys (nvt) ?: "", nvti_excluded_keys (nvt) ?: "",
1305  nvti_required_udp_ports (nvt) ?: "", nvti_required_ports (nvt) ?: "",
1306  nvti_dependencies (nvt) ?: "", nvti_tag (nvt) ?: "", cves ?: "",
1307  bids ?: "", xrefs ?: "", nvti_category (nvt),
1308  nvti_timeout (nvt), nvti_family (nvt), nvti_name (nvt));
1309  g_free (cves);
1310  g_free (bids);
1311  g_free (xrefs);
1312  if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1313  rc = -1;
1314  if (rep != NULL)
1315  freeReplyObject (rep);
1316 
1317  if (nvti_pref_len (nvt))
1318  redis_cmd (kbr, "DEL oid:%s:prefs", nvti_oid (nvt));
1319  for (i = 0; i < nvti_pref_len (nvt); i++)
1320  {
1321  const nvtpref_t *pref = nvti_pref (nvt, i);
1322 
1323  rep = redis_cmd (kbr, "RPUSH oid:%s:prefs %d|||%s|||%s|||%s",
1324  nvti_oid (nvt), nvtpref_id (pref), nvtpref_name (pref),
1325  nvtpref_type (pref), nvtpref_default (pref));
1326  if (!rep || rep->type == REDIS_REPLY_ERROR)
1327  rc = -1;
1328  if (rep)
1329  freeReplyObject (rep);
1330  }
1331  rep = redis_cmd (kbr, "RPUSH filename:%s %lu %s", filename, time (NULL),
1332  nvti_oid (nvt));
1333  if (!rep || rep->type == REDIS_REPLY_ERROR)
1334  rc = -1;
1335  if (rep)
1336  freeReplyObject (rep);
1337  return rc;
1338 }

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(), nvti_timeout(), nvtpref_default(), nvtpref_id(), nvtpref_name(), nvtpref_type(), redis_cmd(), and redis_kb.

Here is the call graph for this function:

◆ 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]kbKB handle where to store the item.
[in]nameItem name.
[in]strItem value.
[in]lenValue length. Used for blobs.
Returns
0 on success, non-null on error.

Definition at line 1123 of file kb.c.

1124 {
1125  struct kb_redis *kbr;
1126  redisReply *rep;
1127  int rc = 0;
1128 
1129  kbr = redis_kb (kb);
1130  if (len == 0)
1131  rep = redis_cmd (kbr, "RPUSH %s %s", name, str);
1132  else
1133  rep = redis_cmd (kbr, "RPUSH %s %b", name, str, len);
1134  if (!rep || rep->type == REDIS_REPLY_ERROR)
1135  rc = -1;
1136 
1137  if (rep)
1138  freeReplyObject (rep);
1139  return rc;
1140 }

References redis_cmd(), and redis_kb.

Here is the call graph for this function:

◆ redis_add_str_unique()

static int redis_add_str_unique ( kb_t  kb,
const char *  name,
const char *  str,
size_t  len 
)
static

Insert (append) a new unique entry under a given name.

Parameters
[in]kbKB handle where to store the item.
[in]nameItem name.
[in]strItem value.
[in]lenValue length. Used for blobs.
Returns
0 on success, non-null on error.

Definition at line 1069 of file kb.c.

1070 {
1071  struct kb_redis *kbr;
1072  redisReply *rep = NULL;
1073  int rc = 0;
1074  redisContext *ctx;
1075 
1076  kbr = redis_kb (kb);
1077  if (get_redis_ctx (kbr) < 0)
1078  return -1;
1079  ctx = kbr->rctx;
1080 
1081  /* Some VTs still rely on values being unique (ie. a value inserted multiple
1082  * times, will only be present once.)
1083  * Once these are fixed, the LREM becomes redundant and should be removed.
1084  */
1085  if (len == 0)
1086  {
1087  redisAppendCommand (ctx, "LREM %s 1 %s", name, str);
1088  redisAppendCommand (ctx, "RPUSH %s %s", name, str);
1089  redisGetReply (ctx, (void **) &rep);
1090  if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1091  g_debug ("Key '%s' already contained value '%s'", name, str);
1092  freeReplyObject (rep);
1093  redisGetReply (ctx, (void **) &rep);
1094  }
1095  else
1096  {
1097  redisAppendCommand (ctx, "LREM %s 1 %b", name, str, len);
1098  redisAppendCommand (ctx, "RPUSH %s %b", name, str, len);
1099  redisGetReply (ctx, (void **) &rep);
1100  if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1101  g_debug ("Key '%s' already contained string '%s'", name, str);
1102  freeReplyObject (rep);
1103  redisGetReply (ctx, (void **) &rep);
1104  }
1105  if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1106  rc = -1;
1107 
1108  if (rep != NULL)
1109  freeReplyObject (rep);
1110 
1111  return rc;
1112 }

References get_redis_ctx(), kb_redis::rctx, and redis_kb.

Here is the call graph for this function:

◆ 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]kbrSubclass of struct kb to connect to.
[in]fmtFormatted variable argument list with the cmd to be executed.
Returns
Redis reply on success, NULL otherwise.

Definition at line 631 of file kb.c.

632 {
633  redisReply *rep;
634  va_list ap, aq;
635  int retry = 0;
636 
637  va_start (ap, fmt);
638  do
639  {
640  if (get_redis_ctx (kbr) < 0)
641  {
642  va_end (ap);
643  return NULL;
644  }
645 
646  va_copy (aq, ap);
647  rep = redisvCommand (kbr->rctx, fmt, aq);
648  va_end (aq);
649 
650  if (kbr->rctx->err)
651  {
652  if (rep != NULL)
653  freeReplyObject (rep);
654 
655  redis_lnk_reset ((kb_t) kbr);
656  retry = !retry;
657  }
658  else
659  retry = 0;
660  }
661  while (retry);
662 
663  va_end (ap);
664 
665  return rep;
666 }

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_pop_str(), redis_push_str(), redis_save(), and redis_test_connection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ redis_count()

static size_t redis_count ( kb_t  kb,
const char *  pattern 
)
static

Count all items stored under a given pattern.

Parameters
[in]kbKB handle where to count the items.
[in]pattern'*' pattern of the elements to count.
Returns
Count of items.

Definition at line 1012 of file kb.c.

1013 {
1014  struct kb_redis *kbr;
1015  redisReply *rep;
1016  size_t count;
1017 
1018  kbr = redis_kb (kb);
1019 
1020  rep = redis_cmd (kbr, "KEYS %s", pattern);
1021  if (rep == NULL)
1022  return 0;
1023 
1024  if (rep->type != REDIS_REPLY_ARRAY)
1025  {
1026  freeReplyObject (rep);
1027  return 0;
1028  }
1029 
1030  count = rep->elements;
1031  freeReplyObject (rep);
1032  return count;
1033 }

References redis_cmd(), and redis_kb.

Here is the call graph for this function:

◆ redis_del_items()

static int redis_del_items ( kb_t  kb,
const char *  name 
)
static

Delete all entries under a given name.

Parameters
[in]kbKB handle where to store the item.
[in]nameItem name.
Returns
0 on success, non-null on error.

Definition at line 1042 of file kb.c.

1043 {
1044  struct kb_redis *kbr;
1045  redisReply *rep;
1046  int rc = 0;
1047 
1048  kbr = redis_kb (kb);
1049 
1050  rep = redis_cmd (kbr, "DEL %s", name);
1051  if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1052  rc = -1;
1053 
1054  if (rep != NULL)
1055  freeReplyObject (rep);
1056 
1057  return rc;
1058 }

References redis_cmd(), and redis_kb.

Here is the call graph for this function:

◆ redis_delete()

static int redis_delete ( kb_t  kb)
static

Delete all entries and release ownership on the namespace.

Parameters
[in]kbKB handle to release.
Returns
0 on success, non-null on error.

Definition at line 332 of file kb.c.

333 {
334  struct kb_redis *kbr;
335 
336  kbr = redis_kb (kb);
337 
338  redis_delete_all (kbr);
339  redis_release_db (kbr);
340 
341  if (kbr->rctx != NULL)
342  {
343  redisFree (kbr->rctx);
344  kbr->rctx = NULL;
345  }
346 
347  g_free (kb);
348  return 0;
349 }

References kb_redis::rctx, redis_delete_all(), redis_kb, and redis_release_db().

Referenced by redis_new().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ redis_delete_all()

int redis_delete_all ( struct kb_redis kbr)
static

Delete all the KB's content.

Parameters
[in]kbrSubclass of struct kb.
Returns
0 on success, non-null on error.

Definition at line 1474 of file kb.c.

1475 {
1476  int rc;
1477  redisReply *rep;
1478  struct sigaction new_action, original_action;
1479 
1480  /* Ignore SIGPIPE, in case of a lost connection. */
1481  new_action.sa_flags = 0;
1482  if (sigemptyset (&new_action.sa_mask))
1483  return -1;
1484  new_action.sa_handler = SIG_IGN;
1485  if (sigaction (SIGPIPE, &new_action, &original_action))
1486  return -1;
1487 
1488  g_debug ("%s: deleting all elements from KB #%u", __func__, kbr->db);
1489  rep = redis_cmd (kbr, "FLUSHDB");
1490  if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
1491  {
1492  rc = -1;
1493  goto err_cleanup;
1494  }
1495 
1496  rc = 0;
1497 
1498 err_cleanup:
1499  if (sigaction (SIGPIPE, &original_action, NULL))
1500  return -1;
1501  if (rep != NULL)
1502  freeReplyObject (rep);
1503 
1504  return rc;
1505 }

References kb_redis::db, and redis_cmd().

Referenced by redis_delete(), and redis_flush_all().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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_pathPath to KB.
[in]kb_indexDB index
Returns
Knowledge Base object, NULL otherwise.

Definition at line 404 of file kb.c.

405 {
406  struct kb_redis *kbr;
407  redisReply *rep;
408 
409  kbr = g_malloc0 (sizeof (struct kb_redis) + strlen (kb_path) + 1);
410  kbr->kb.kb_ops = &KBRedisOperations;
411  strcpy (kbr->path, kb_path);
412 
413  kbr->rctx = redisConnectUnix (kbr->path);
414  if (kbr->rctx == NULL || kbr->rctx->err)
415  {
416  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
417  "%s: redis connection error to %s: %s", __func__, kbr->path,
418  kbr->rctx ? kbr->rctx->errstr : strerror (ENOMEM));
419  redisFree (kbr->rctx);
420  g_free (kbr);
421  return NULL;
422  }
423  kbr->db = kb_index;
424  rep = redisCommand (kbr->rctx, "SELECT %d", kb_index);
425  if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
426  {
427  if (rep != NULL)
428  freeReplyObject (rep);
429  redisFree (kbr->rctx);
430  kbr->rctx = NULL;
431  return NULL;
432  }
433  freeReplyObject (rep);
434  return (kb_t) kbr;
435 }

References 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_pathPath to KB.
[in]keyMarker key to search for in KB objects.
Returns
Knowledge Base object, NULL otherwise.

Definition at line 444 of file kb.c.

445 {
446  struct kb_redis *kbr;
447  unsigned int i = 1;
448 
449  kbr = g_malloc0 (sizeof (struct kb_redis) + strlen (kb_path) + 1);
450  kbr->kb.kb_ops = &KBRedisOperations;
451  strcpy (kbr->path, kb_path);
452 
453  do
454  {
455  redisReply *rep;
456 
457  kbr->rctx = redisConnectUnix (kbr->path);
458  if (kbr->rctx == NULL || kbr->rctx->err)
459  {
460  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
461  "%s: redis connection error to %s: %s", __func__, kbr->path,
462  kbr->rctx ? kbr->rctx->errstr : strerror (ENOMEM));
463  redisFree (kbr->rctx);
464  g_free (kbr);
465  return NULL;
466  }
467 
468  if (kbr->max_db == 0)
469  fetch_max_db_index (kbr);
470 
471  kbr->db = i;
472  rep = redisCommand (kbr->rctx, "HEXISTS %s %d", GLOBAL_DBINDEX_NAME, i);
473  if (rep == NULL || rep->type != REDIS_REPLY_INTEGER || rep->integer != 1)
474  {
475  if (rep != NULL)
476  freeReplyObject (rep);
477  i++;
478  redisFree (kbr->rctx);
479  kbr->rctx = NULL;
480  continue;
481  }
482  freeReplyObject (rep);
483  rep = redisCommand (kbr->rctx, "SELECT %u", i);
484  if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
485  {
486  redisFree (kbr->rctx);
487  kbr->rctx = NULL;
488  }
489  else
490  {
491  freeReplyObject (rep);
492  if (key)
493  {
494  char *tmp = kb_item_get_str (&kbr->kb, key);
495  if (tmp)
496  {
497  g_free (tmp);
498  return (kb_t) kbr;
499  }
500  }
501  redisFree (kbr->rctx);
502  }
503  i++;
504  }
505  while (i < kbr->max_db);
506 
507  g_free (kbr);
508  return NULL;
509 }

References 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.

Here is the call graph for this function:

◆ 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]kbKB handle.
[in]exceptDon't flush DB with except key.
Returns
0 on success, non-null on error.

Definition at line 1369 of file kb.c.

1370 {
1371  unsigned int i = 1;
1372  struct kb_redis *kbr;
1373 
1374  kbr = redis_kb (kb);
1375  if (kbr->rctx)
1376  redisFree (kbr->rctx);
1377 
1378  g_debug ("%s: deleting all DBs at %s except %s", __func__, kbr->path, except);
1379  do
1380  {
1381  redisReply *rep;
1382 
1383  kbr->rctx = redisConnectUnix (kbr->path);
1384  if (kbr->rctx == NULL || kbr->rctx->err)
1385  {
1386  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1387  "%s: redis connection error to %s: %s", __func__, kbr->path,
1388  kbr->rctx ? kbr->rctx->errstr : strerror (ENOMEM));
1389  redisFree (kbr->rctx);
1390  kbr->rctx = NULL;
1391  return -1;
1392  }
1393 
1394  kbr->db = i;
1395  rep = redisCommand (kbr->rctx, "HEXISTS %s %d", GLOBAL_DBINDEX_NAME, i);
1396  if (rep == NULL || rep->type != REDIS_REPLY_INTEGER || rep->integer != 1)
1397  {
1398  freeReplyObject (rep);
1399  redisFree (kbr->rctx);
1400  i++;
1401  continue;
1402  }
1403  freeReplyObject (rep);
1404  rep = redisCommand (kbr->rctx, "SELECT %u", i);
1405  if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
1406  {
1407  freeReplyObject (rep);
1408  redisFree (kbr->rctx);
1409  kbr->rctx = NULL;
1410  }
1411  else
1412  {
1413  freeReplyObject (rep);
1414  /* Don't remove DB if it has "except" key. */
1415  if (except)
1416  {
1417  char *tmp = kb_item_get_str (kb, except);
1418  if (tmp)
1419  {
1420  g_free (tmp);
1421  i++;
1422  redisFree (kbr->rctx);
1423  continue;
1424  }
1425  }
1426  redis_delete_all (kbr);
1427  redis_release_db (kbr);
1428  redisFree (kbr->rctx);
1429  }
1430  i++;
1431  }
1432  while (i < kbr->max_db);
1433 
1434  g_free (kb);
1435  return 0;
1436 }

References 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().

Here is the call graph for this function:

◆ 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]kbKB handle where to fetch the items.
[in]nameName 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 888 of file kb.c.

889 {
890  struct kb_redis *kbr;
891  struct kb_item *kbi;
892  redisReply *rep;
893 
894  kbr = redis_kb (kb);
895 
896  rep = redis_cmd (kbr, "LRANGE %s 0 -1", name);
897  if (rep == NULL)
898  return NULL;
899 
900  kbi = redis2kbitem (name, rep);
901 
902  freeReplyObject (rep);
903 
904  return kbi;
905 }

References kb_item::name, redis2kbitem(), redis_cmd(), and redis_kb.

Here is the call graph for this function:

◆ redis_get_int()

static int redis_get_int ( kb_t  kb,
const char *  name 
)
static

Get a single KB integer item.

Parameters
[in]kbKB handle where to fetch the item.
[in]nameName of the element to retrieve.
Returns
A struct kb_item to be freed with kb_item_free() or NULL if no element was found or on error.

Definition at line 785 of file kb.c.

786 {
787  struct kb_item *kbi;
788 
790  if (kbi != NULL)
791  {
792  int res;
793 
794  res = kbi->v_int;
795  kb_item_free (kbi);
796  return res;
797  }
798  return -1;
799 }

References kb_item_free(), KB_TYPE_INT, kb_item::name, redis_get_single(), and kb_item::v_int.

Here is the call graph for this function:

◆ redis_get_kb_index()

static int redis_get_kb_index ( kb_t  kb)
static

Return the kb index.

Parameters
[in]kbKB handle.
Returns
kb_index on success, null on error.

Definition at line 357 of file kb.c.

358 {
359  int i;
360  i = ((struct kb_redis *) kb)->db;
361  if (i > 0)
362  return i;
363  return -1;
364 }

◆ 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]kbKB handle where to store the nvt.
[in]oidOID of NVT to get from.
[in]positionPosition of field to get.
Returns
Value of field, NULL otherwise.

Definition at line 809 of file kb.c.

810 {
811  struct kb_redis *kbr;
812  redisReply *rep;
813  char *res = NULL;
814 
815  kbr = redis_kb (kb);
816  if (position >= NVT_TIMESTAMP_POS)
817  rep = redis_cmd (kbr, "LINDEX filename:%s %d", oid,
818  position - NVT_TIMESTAMP_POS);
819  else
820  rep = redis_cmd (kbr, "LINDEX nvt:%s %d", oid, position);
821  if (!rep)
822  return NULL;
823  if (rep->type == REDIS_REPLY_INTEGER)
824  res = g_strdup_printf ("%lld", rep->integer);
825  else if (rep->type == REDIS_REPLY_STRING)
826  res = g_strdup (rep->str);
827  freeReplyObject (rep);
828 
829  return res;
830 }

References NVT_TIMESTAMP_POS, redis_cmd(), and redis_kb.

Here is the call graph for this function:

◆ redis_get_nvt_all()

static nvti_t* redis_get_nvt_all ( kb_t  kb,
const char *  oid 
)
static

Get a full NVT.

Parameters
[in]kbKB handle where to store the nvt.
[in]oidOID of NVT to get.
Returns
nvti_t of NVT, NULL otherwise.

Definition at line 839 of file kb.c.

840 {
841  struct kb_redis *kbr;
842  redisReply *rep;
843 
844  kbr = redis_kb (kb);
845  rep =
846  redis_cmd (kbr, "LRANGE nvt:%s %d %d", oid, NVT_FILENAME_POS, NVT_NAME_POS);
847  if (!rep)
848  return NULL;
849  if (rep->type != REDIS_REPLY_ARRAY || rep->elements != NVT_NAME_POS + 1)
850  {
851  freeReplyObject (rep);
852  return NULL;
853  }
854  else
855  {
856  nvti_t *nvti = nvti_new ();
857 
858  nvti_set_oid (nvti, oid);
859  nvti_set_required_keys (nvti, rep->element[NVT_REQUIRED_KEYS_POS]->str);
861  nvti_set_excluded_keys (nvti, rep->element[NVT_EXCLUDED_KEYS_POS]->str);
863  nvti, rep->element[NVT_REQUIRED_UDP_PORTS_POS]->str);
865  nvti_set_dependencies (nvti, rep->element[NVT_DEPENDENCIES_POS]->str);
866  nvti_set_tag (nvti, rep->element[NVT_TAGS_POS]->str);
867  nvti_add_refs (nvti, "cve", rep->element[NVT_CVES_POS]->str, "");
868  nvti_add_refs (nvti, "bid", rep->element[NVT_BIDS_POS]->str, "");
869  nvti_add_refs (nvti, NULL, rep->element[NVT_XREFS_POS]->str, "");
870  nvti_set_category (nvti, atoi (rep->element[NVT_CATEGORY_POS]->str));
871  nvti_set_timeout (nvti, atoi (rep->element[NVT_TIMEOUT_POS]->str));
872  nvti_set_family (nvti, rep->element[NVT_FAMILY_POS]->str);
873  nvti_set_name (nvti, rep->element[NVT_NAME_POS]->str);
874 
875  freeReplyObject (rep);
876  return nvti;
877  }
878 }

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_TIMEOUT_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(), nvti_set_timeout(), redis_cmd(), and redis_kb.

Here is the call graph for this function:

◆ redis_get_oids()

static GSList* redis_get_oids ( kb_t  kb)
static

Get all NVT OIDs.

Parameters
[in]kbKB handle where to fetch the items.
Returns
Linked list of all OIDs or NULL.

Definition at line 977 of file kb.c.

978 {
979  struct kb_redis *kbr;
980  redisReply *rep;
981  GSList *list = NULL;
982  size_t i;
983 
984  kbr = redis_kb (kb);
985  rep = redis_cmd (kbr, "KEYS nvt:*");
986  if (!rep)
987  return NULL;
988 
989  if (rep->type != REDIS_REPLY_ARRAY)
990  {
991  freeReplyObject (rep);
992  return NULL;
993  }
994 
995  /* Fetch OID values from key names nvt:OID. */
996  for (i = 0; i < rep->elements; i++)
997  list = g_slist_prepend (list, g_strdup (rep->element[i]->str + 4));
998  freeReplyObject (rep);
999 
1000  return list;
1001 }

References redis_cmd(), and redis_kb.

Here is the call graph for this function:

◆ 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]kbKB 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 915 of file kb.c.

916 {
917  struct kb_redis *kbr;
918  struct kb_item *kbi = NULL;
919  redisReply *rep;
920  unsigned int i;
921 
922  kbr = redis_kb (kb);
923  rep = redis_cmd (kbr, "KEYS %s", pattern);
924  if (!rep)
925  return NULL;
926  if (rep->type != REDIS_REPLY_ARRAY)
927  {
928  freeReplyObject (rep);
929  return NULL;
930  }
931 
932  if (get_redis_ctx (kbr) < 0)
933  return NULL;
934  for (i = 0; i < rep->elements; i++)
935  redisAppendCommand (kbr->rctx, "LRANGE %s 0 -1", rep->element[i]->str);
936 
937  for (i = 0; i < rep->elements; i++)
938  {
939  struct kb_item *tmp;
940  redisReply *rep_range;
941 
942  redisGetReply (kbr->rctx, (void **) &rep_range);
943  if (!rep)
944  continue;
945  tmp = redis2kbitem (rep->element[i]->str, rep_range);
946  if (!tmp)
947  {
948  freeReplyObject (rep_range);
949  continue;
950  }
951 
952  if (kbi)
953  {
954  struct kb_item *tmp2;
955 
956  tmp2 = tmp;
957  while (tmp->next)
958  tmp = tmp->next;
959  tmp->next = kbi;
960  kbi = tmp2;
961  }
962  else
963  kbi = tmp;
964  freeReplyObject (rep_range);
965  }
966 
967  freeReplyObject (rep);
968  return kbi;
969 }

References get_redis_ctx(), kb_item::next, kb_redis::rctx, redis2kbitem(), redis_cmd(), and redis_kb.

Here is the call graph for this function:

◆ redis_get_single()

static struct kb_item* redis_get_single ( kb_t  kb,
const char *  name,
enum kb_item_type  type 
)
static

Get a single KB element.

Parameters
[in]kbKB handle where to fetch the item.
[in]nameName of the element to retrieve.
[in]typeDesired element type.
Returns
A struct kb_item to be freed with kb_item_free() or NULL if no element was found or on error.

Definition at line 677 of file kb.c.

678 {
679  struct kb_item *kbi;
680  struct kb_redis *kbr;
681  redisReply *rep;
682 
683  kbr = redis_kb (kb);
684  kbi = NULL;
685 
686  rep = redis_cmd (kbr, "LINDEX %s -1", name);
687  if (rep == NULL || rep->type != REDIS_REPLY_STRING)
688  {
689  kbi = NULL;
690  goto out;
691  }
692 
693  kbi = redis2kbitem_single (name, rep, type == KB_TYPE_INT);
694 
695 out:
696  if (rep != NULL)
697  freeReplyObject (rep);
698 
699  return kbi;
700 }

References KB_TYPE_INT, redis2kbitem_single(), redis_cmd(), and redis_kb.

Referenced by redis_get_int(), and redis_get_str().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ redis_get_str()

static char* redis_get_str ( kb_t  kb,
const char *  name 
)
static

Get a single KB string item.

Parameters
[in]kbKB handle where to fetch the item.
[in]nameName of the element to retrieve.
Returns
A struct kb_item to be freed with kb_item_free() or NULL if no element was found or on error.

Definition at line 710 of file kb.c.

711 {
712  struct kb_item *kbi;
713 
715  if (kbi != NULL)
716  {
717  char *res;
718 
719  res = kbi->v_str;
720  kbi->v_str = NULL;
721  kb_item_free (kbi);
722  return res;
723  }
724  return NULL;
725 }

References kb_item_free(), KB_TYPE_STR, kb_item::name, redis_get_single(), and kb_item::v_str.

Here is the call graph for this function:

◆ 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
[in]kbKB handle.
Returns
0 on success, non-null on error.

Definition at line 1347 of file kb.c.

1348 {
1349  struct kb_redis *kbr;
1350 
1351  kbr = redis_kb (kb);
1352 
1353  if (kbr->rctx != NULL)
1354  {
1355  redisFree (kbr->rctx);
1356  kbr->rctx = NULL;
1357  }
1358 
1359  return 0;
1360 }

References kb_redis::rctx, and redis_kb.

Referenced by redis_cmd().

Here is the caller graph for this function:

◆ redis_new()

static int redis_new ( kb_t kb,
const char *  kb_path 
)
static

Initialize a new Knowledge Base object.

Parameters
[in]kbReference to a kb_t to initialize.
[in]kb_pathPath to KB.
Returns
0 on success, -1 on connection error, -2 when no DB is available.

Definition at line 373 of file kb.c.

374 {
375  struct kb_redis *kbr;
376  int rc = 0;
377 
378  kbr = g_malloc0 (sizeof (struct kb_redis) + strlen (kb_path) + 1);
379  kbr->kb.kb_ops = &KBRedisOperations;
380  strcpy (kbr->path, kb_path);
381 
382  if ((rc = get_redis_ctx (kbr)) < 0)
383  return rc;
384  if (redis_test_connection (kbr))
385  {
386  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
387  "%s: cannot access redis at '%s'", __func__, kb_path);
388  redis_delete ((kb_t) kbr);
389  kbr = NULL;
390  rc = -1;
391  }
392 
393  *kb = (kb_t) kbr;
394  return rc;
395 }

References G_LOG_DOMAIN, get_redis_ctx(), kb_redis::kb, kb::kb_ops, KBRedisOperations, kb_redis::path, redis_delete(), and redis_test_connection().

Here is the call graph for this function:

◆ redis_pop_str()

static char* redis_pop_str ( kb_t  kb,
const char *  name 
)
static

Pops a single KB string item.

Parameters
[in]kbKB handle where to fetch the item.
[in]nameName 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 759 of file kb.c.

760 {
761  struct kb_redis *kbr;
762  redisReply *rep;
763  char *value = NULL;
764 
765  kbr = redis_kb (kb);
766  rep = redis_cmd (kbr, "RPOP %s", name);
767  if (!rep)
768  return NULL;
769 
770  if (rep->type == REDIS_REPLY_STRING)
771  value = g_strdup (rep->str);
772  freeReplyObject (rep);
773 
774  return value;
775 }

References redis_cmd(), and redis_kb.

Here is the call graph for this function:

◆ 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]kbKB handle where to store the item.
[in]nameKey to push to.
[in]valueValue to push.
Returns
0 on success, non-null on error.

Definition at line 735 of file kb.c.

736 {
737  struct kb_redis *kbr;
738  redisReply *rep = NULL;
739  int rc = 0;
740 
741  kbr = redis_kb (kb);
742  rep = redis_cmd (kbr, "LPUSH %s %s", name, value);
743  if (!rep || rep->type == REDIS_REPLY_ERROR)
744  rc = -1;
745 
746  if (rep)
747  freeReplyObject (rep);
748 
749  return rc;
750 }

References redis_cmd(), and redis_kb.

Here is the call graph for this function:

◆ redis_release_db()

static int redis_release_db ( struct kb_redis kbr)
static

Release DB.

Parameters
[in]kbrSubclass of struct kb.
Returns
0 on success, -1 on error.

Definition at line 215 of file kb.c.

216 {
217  int rc;
218  redisContext *ctx = kbr->rctx;
219  redisReply *rep;
220 
221  if (ctx == NULL)
222  return -EINVAL;
223 
224  rep = redisCommand (ctx, "SELECT 0"); /* Management database*/
225  if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
226  {
227  rc = -1;
228  goto err_cleanup;
229  }
230  freeReplyObject (rep);
231 
232  rep = redisCommand (ctx, "HDEL %s %d", GLOBAL_DBINDEX_NAME, kbr->db);
233  if (rep == NULL || rep->type != REDIS_REPLY_INTEGER)
234  {
235  rc = -1;
236  goto err_cleanup;
237  }
238 
239  rc = 0;
240 
241 err_cleanup:
242  if (rep != NULL)
243  freeReplyObject (rep);
244 
245  return rc;
246 }

References kb_redis::db, GLOBAL_DBINDEX_NAME, and kb_redis::rctx.

Referenced by redis_delete(), and redis_flush_all().

Here is the caller graph for this function:

◆ redis_save()

int redis_save ( kb_t  kb)

Save all the elements from the KB.

Parameters
[in]kbKB handle.
Returns
0 on success, -1 on error.

Definition at line 1444 of file kb.c.

1445 {
1446  int rc;
1447  redisReply *rep;
1448  struct kb_redis *kbr;
1449 
1450  kbr = redis_kb (kb);
1451  g_debug ("%s: saving all elements from KB #%u", __func__, kbr->db);
1452  rep = redis_cmd (kbr, "SAVE");
1453  if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
1454  {
1455  rc = -1;
1456  goto err_cleanup;
1457  }
1458 
1459  rc = 0;
1460 
1461 err_cleanup:
1462  if (rep != NULL)
1463  freeReplyObject (rep);
1464 
1465  return rc;
1466 }

References kb_redis::db, redis_cmd(), and redis_kb.

Here is the call graph for this function:

◆ 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]kbKB handle where to store the item.
[in]nameItem name.
[in]valItem value.
Returns
0 on success, non-null on error.

Definition at line 1250 of file kb.c.

1251 {
1252  struct kb_redis *kbr;
1253  redisReply *rep = NULL;
1254  redisContext *ctx;
1255  int rc = 0, i = 4;
1256 
1257  kbr = redis_kb (kb);
1258  if (get_redis_ctx (redis_kb (kb)) < 0)
1259  return -1;
1260  ctx = kbr->rctx;
1261  redisAppendCommand (ctx, "MULTI");
1262  redisAppendCommand (ctx, "DEL %s", name);
1263  redisAppendCommand (ctx, "RPUSH %s %d", name, val);
1264  redisAppendCommand (ctx, "EXEC");
1265  while (i--)
1266  {
1267  redisGetReply (ctx, (void **) &rep);
1268  if (!rep || rep->type == REDIS_REPLY_ERROR)
1269  rc = -1;
1270  if (rep)
1271  freeReplyObject (rep);
1272  }
1273 
1274  return rc;
1275 }

References get_redis_ctx(), kb_redis::rctx, and redis_kb.

Here is the call graph for this function:

◆ 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]kbKB handle where to store the item.
[in]nameItem name.
[in]valItem value.
[in]lenValue length. Used for blobs.
Returns
0 on success, non-null on error.

Definition at line 1151 of file kb.c.

1152 {
1153  struct kb_redis *kbr;
1154  redisReply *rep = NULL;
1155  redisContext *ctx;
1156  int rc = 0, i = 4;
1157 
1158  kbr = redis_kb (kb);
1159  if (get_redis_ctx (kbr) < 0)
1160  return -1;
1161  ctx = kbr->rctx;
1162  redisAppendCommand (ctx, "MULTI");
1163  redisAppendCommand (ctx, "DEL %s", name);
1164  if (len == 0)
1165  redisAppendCommand (ctx, "RPUSH %s %s", name, val);
1166  else
1167  redisAppendCommand (ctx, "RPUSH %s %b", name, val, len);
1168  redisAppendCommand (ctx, "EXEC");
1169  while (i--)
1170  {
1171  redisGetReply (ctx, (void **) &rep);
1172  if (!rep || rep->type == REDIS_REPLY_ERROR)
1173  rc = -1;
1174  if (rep)
1175  freeReplyObject (rep);
1176  }
1177 
1178  return rc;
1179 }

References get_redis_ctx(), kb_redis::rctx, and redis_kb.

Here is the call graph for this function:

◆ redis_test_connection()

static int redis_test_connection ( struct kb_redis kbr)
static

Test redis connection.

Parameters
[in]kbrSubclass of struct kb to test.
Returns
0 on success, negative integer on error.

Definition at line 293 of file kb.c.

294 {
295  int rc = 0;
296  redisReply *rep;
297 
298  rep = redis_cmd (kbr, "PING");
299  if (rep == NULL)
300  {
301  /* not 100% relevant but hiredis doesn't provide us with proper error
302  * codes. */
303  rc = -ECONNREFUSED;
304  goto out;
305  }
306 
307  if (rep->type != REDIS_REPLY_STATUS)
308  {
309  rc = -EINVAL;
310  goto out;
311  }
312 
313  if (g_ascii_strcasecmp (rep->str, "PONG"))
314  {
315  rc = -EPROTO;
316  goto out;
317  }
318 
319 out:
320  if (rep != NULL)
321  freeReplyObject (rep);
322 
323  return rc;
324 }

References redis_cmd().

Referenced by redis_new().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ select_database()

static int select_database ( struct kb_redis kbr)
static

Select DB.

Parameters
[in]kbrSubclass of struct kb where to save the db index.
Returns
0 on success, -1 on error.

WARNING: do not call redis_cmd in here, since our context is not fully acquired yet!

Definition at line 164 of file kb.c.

165 {
166  int rc;
167  redisContext *ctx = kbr->rctx;
168  redisReply *rep = NULL;
169 
170  if (kbr->db == 0)
171  {
172  unsigned i;
173 
174  if (kbr->max_db == 0)
175  fetch_max_db_index (kbr);
176 
177  for (i = 1; i < kbr->max_db; i++)
178  {
179  rc = try_database_index (kbr, i);
180  if (rc == 0)
181  break;
182  }
183  }
184 
185  /* No DB available, give up. */
186  if (kbr->db == 0)
187  {
188  rc = -1;
189  goto err_cleanup;
190  }
191 
192  rep = redisCommand (ctx, "SELECT %u", kbr->db);
193  if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
194  {
195  rc = -1;
196  goto err_cleanup;
197  }
198 
199  rc = 0;
200 
201 err_cleanup:
202  if (rep != NULL)
203  freeReplyObject (rep);
204 
205  return rc;
206 }

References kb_redis::db, fetch_max_db_index(), kb_redis::max_db, kb_redis::rctx, and try_database_index().

Referenced by get_redis_ctx().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 82 of file kb.c.

83 {
84  redisContext *ctx = kbr->rctx;
85  redisReply *rep;
86  int rc = 0;
87 
88  rep = redisCommand (ctx, "HSETNX %s %d 1", GLOBAL_DBINDEX_NAME, index);
89  if (rep == NULL)
90  return -ENOMEM;
91 
92  if (rep->type != REDIS_REPLY_INTEGER)
93  rc = -EPROTO;
94  else if (rep->integer == 0)
95  rc = -EALREADY;
96  else
97  kbr->db = index;
98 
99  freeReplyObject (rep);
100 
101  return rc;
102 }

References kb_redis::db, GLOBAL_DBINDEX_NAME, and kb_redis::rctx.

Referenced by select_database().

Here is the caller graph for this function:

Variable Documentation

◆ KBDefaultOperations

const struct kb_operations* KBDefaultOperations = &KBRedisOperations

Default KB operations. No selection mechanism is provided yet since there's only one implementation (redis-based).

Definition at line 1542 of file kb.c.

Referenced by kb_direct_conn(), kb_find(), and kb_new().

◆ KBRedisOperations

static const struct kb_operations KBRedisOperations
static
Initial value:
= {
.kb_new = redis_new,
.kb_find = redis_find,
.kb_delete = redis_delete,
.kb_get_single = redis_get_single,
.kb_get_str = redis_get_str,
.kb_get_int = redis_get_int,
.kb_get_nvt = redis_get_nvt,
.kb_get_nvt_all = redis_get_nvt_all,
.kb_get_nvt_oids = redis_get_oids,
.kb_push_str = redis_push_str,
.kb_pop_str = redis_pop_str,
.kb_get_all = redis_get_all,
.kb_get_pattern = redis_get_pattern,
.kb_count = redis_count,
.kb_add_str = redis_add_str,
.kb_add_str_unique = redis_add_str_unique,
.kb_set_str = redis_set_str,
.kb_add_int = redis_add_int,
.kb_add_int_unique = redis_add_int_unique,
.kb_set_int = redis_set_int,
.kb_add_nvt = redis_add_nvt,
.kb_del_items = redis_del_items,
.kb_lnk_reset = redis_lnk_reset,
.kb_save = redis_save,
.kb_flush = redis_flush_all,
.kb_direct_conn = redis_direct_conn,
.kb_get_kb_index = redis_get_kb_index,
}

Default KB operations. No selection mechanism is provided yet since there's only one implementation (redis-based).

Definition at line 52 of file kb.c.

Referenced by redis_direct_conn(), redis_find(), and redis_new().

nvti_pref
const nvtpref_t * nvti_pref(const nvti_t *n, guint p)
Get the n'th preferences of the NVT.
Definition: nvti.c:929
NVT_EXCLUDED_KEYS_POS
@ NVT_EXCLUDED_KEYS_POS
Definition: kb.h:63
redis_kb
#define redis_kb(__kb)
Definition: kb.c:67
nvti_set_required_udp_ports
int nvti_set_required_udp_ports(nvti_t *n, const gchar *required_udp_ports)
Set the required udp ports of a NVT.
Definition: nvti.c:1422
NVT_BIDS_POS
@ NVT_BIDS_POS
Definition: kb.h:69
kb_item_get_str
static char * kb_item_get_str(kb_t kb, const char *name)
Get a single KB string item.
Definition: kb.h:327
redis_get_all
static struct kb_item * redis_get_all(kb_t kb, const char *name)
Get all items stored under a given name.
Definition: kb.c:888
redis_cmd
static redisReply * redis_cmd(struct kb_redis *kbr, const char *fmt,...)
Execute a redis command and get a redis reply.
Definition: kb.c:631
nvti_set_required_keys
int nvti_set_required_keys(nvti_t *n, const gchar *required_keys)
Set the required keys of a NVT.
Definition: nvti.c:1322
nvti_family
gchar * nvti_family(const nvti_t *n)
Get the family name.
Definition: nvti.c:901
redis_save
int redis_save(kb_t kb)
Save all the elements from the KB.
Definition: kb.c:1444
NVT_NAME_POS
@ NVT_NAME_POS
Definition: kb.h:74
nvti_oid
gchar * nvti_oid(const nvti_t *n)
Get the OID string.
Definition: nvti.c:503
redis_push_str
static int redis_push_str(kb_t kb, const char *name, const char *value)
Push a new entry under a given key.
Definition: kb.c:735
kb_item::name
char name[0]
Definition: kb.h:97
redis_direct_conn
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.
Definition: kb.c:404
redis_del_items
static int redis_del_items(kb_t kb, const char *name)
Delete all entries under a given name.
Definition: kb.c:1042
redis_get_str
static char * redis_get_str(kb_t kb, const char *name)
Get a single KB string item.
Definition: kb.c:710
kb_item::len
size_t len
Definition: kb.h:93
redis_get_oids
static GSList * redis_get_oids(kb_t kb)
Get all NVT OIDs.
Definition: kb.c:977
redis_new
static int redis_new(kb_t *kb, const char *kb_path)
Initialize a new Knowledge Base object.
Definition: kb.c:373
redis_get_pattern
static struct kb_item * redis_get_pattern(kb_t kb, const char *pattern)
Get all items stored under a given pattern.
Definition: kb.c:915
redis2kbitem_single
static struct kb_item * redis2kbitem_single(const char *name, const redisReply *elt, int force_int)
Give a single KB item.
Definition: kb.c:538
try_database_index
static int try_database_index(struct kb_redis *kbr, int index)
Attempt to atomically acquire ownership of a database.
Definition: kb.c:82
redis_add_str_unique
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.
Definition: kb.c:1069
kb_redis::kb
struct kb kb
Definition: kb.c:61
NVT_FILENAME_POS
@ NVT_FILENAME_POS
Definition: kb.h:60
NVT_TIMEOUT_POS
@ NVT_TIMEOUT_POS
Definition: kb.h:72
nvtpref_id
int nvtpref_id(const nvtpref_t *np)
Get the ID of a NVT Preference.
Definition: nvti.c:398
redis_delete_all
static int redis_delete_all(struct kb_redis *)
Delete all the KB's content.
Definition: kb.c:1474
nvti_set_name
int nvti_set_name(nvti_t *n, const gchar *name)
Set the name of a NVT.
Definition: nvti.c:992
redis_lnk_reset
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...
Definition: kb.c:1347
kb_item
Knowledge base item (defined by name, type (int/char*) and value). Implemented as a singly linked lis...
Definition: kb.h:83
nvti_refs
gchar * nvti_refs(const nvti_t *n, const gchar *type, const gchar *exclude_types, guint use_types)
Get references as string.
Definition: nvti.c:658
nvti_required_udp_ports
gchar * nvti_required_udp_ports(const nvti_t *n)
Get the required udp ports list.
Definition: nvti.c:859
nvti
The structure of a information record that corresponds to a NVT.
Definition: nvti.c:270
nvti_required_ports
gchar * nvti_required_ports(const nvti_t *n)
Get the required ports list.
Definition: nvti.c:845
NVT_REQUIRED_UDP_PORTS_POS
@ NVT_REQUIRED_UDP_PORTS_POS
Definition: kb.h:64
nvti_category
gint nvti_category(const nvti_t *n)
Get the category for this NVT.
Definition: nvti.c:956
NVT_TIMESTAMP_POS
@ NVT_TIMESTAMP_POS
Definition: kb.h:75
nvti_set_excluded_keys
int nvti_set_excluded_keys(nvti_t *n, const gchar *excluded_keys)
Set the excluded keys of a NVT.
Definition: nvti.c:1372
redis_get_kb_index
static int redis_get_kb_index(kb_t kb)
Return the kb index.
Definition: kb.c:357
kb_item::v_int
int v_int
Definition: kb.h:90
kb_item::v_str
char * v_str
Definition: kb.h:89
NVT_XREFS_POS
@ NVT_XREFS_POS
Definition: kb.h:70
kb_item_free
void kb_item_free(struct kb_item *item)
Release a KB item (or a list).
Definition: kb.c:516
redis_get_int
static int redis_get_int(kb_t kb, const char *name)
Get a single KB integer item.
Definition: kb.c:785
nvti_add_refs
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.
Definition: nvti.c:1557
redis_add_str
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.
Definition: kb.c:1123
nvtpref
The structure for a preference of a NVT.
Definition: nvti.c:333
get_redis_ctx
static int get_redis_ctx(struct kb_redis *kbr)
Get redis context if it is already connected or do a a connection.
Definition: kb.c:256
nvti_set_timeout
int nvti_set_timeout(nvti_t *n, const gint timeout)
Set the timeout of a NVT Info.
Definition: nvti.c:1513
redis_set_str
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.
Definition: kb.c:1151
nvti_pref_len
guint nvti_pref_len(const nvti_t *n)
Get the number of preferences of the NVT.
Definition: nvti.c:914
NVT_CATEGORY_POS
@ NVT_CATEGORY_POS
Definition: kb.h:71
redis_release_db
static int redis_release_db(struct kb_redis *kbr)
Release DB.
Definition: kb.c:215
kb_redis::max_db
unsigned int max_db
Definition: kb.c:62
NVT_DEPENDENCIES_POS
@ NVT_DEPENDENCIES_POS
Definition: kb.h:66
kb::kb_ops
const struct kb_operations * kb_ops
Definition: kb.h:107
nvti_set_dependencies
int nvti_set_dependencies(nvti_t *n, const gchar *dependencies)
Set the dependencies of a NVT.
Definition: nvti.c:1297
redis_add_nvt
static int redis_add_nvt(kb_t kb, const nvti_t *nvt, const char *filename)
Insert a new nvt.
Definition: kb.c:1285
KB_TYPE_STR
@ KB_TYPE_STR
Definition: kb.h:50
kb_item::next
struct kb_item * next
Definition: kb.h:94
kb_redis::db
unsigned int db
Definition: kb.c:63
kb_redis
Subclass of struct kb, it contains the redis-specific fields, such as the redis context,...
Definition: kb.c:59
redis_flush_all
static int redis_flush_all(kb_t, const char *)
Flush all the KB's content. Delete all namespaces.
Definition: kb.c:1369
NVT_FAMILY_POS
@ NVT_FAMILY_POS
Definition: kb.h:73
redis_delete
static int redis_delete(kb_t kb)
Delete all entries and release ownership on the namespace.
Definition: kb.c:332
nvti_tag
gchar * nvti_tag(const nvti_t *n)
Get the tags.
Definition: nvti.c:761
nvti_set_tag
int nvti_set_tag(nvti_t *n, const gchar *tag)
Set the tags of a NVT.
Definition: nvti.c:1248
redis_get_nvt
static char * redis_get_nvt(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.c:809
redis_pop_str
static char * redis_pop_str(kb_t kb, const char *name)
Pops a single KB string item.
Definition: kb.c:759
kb
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:105
nvtpref_name
gchar * nvtpref_name(const nvtpref_t *np)
Get the Name of a NVT Preference.
Definition: nvti.c:412
nvti_mandatory_keys
gchar * nvti_mandatory_keys(const nvti_t *n)
Get the mandatory keys list.
Definition: nvti.c:817
nvti_timeout
gint nvti_timeout(const nvti_t *n)
Get the timeout for this NVT.
Definition: nvti.c:943
nvti_dependencies
gchar * nvti_dependencies(const nvti_t *n)
Get the dependencies list.
Definition: nvti.c:789
redis2kbitem
static struct kb_item * redis2kbitem(const char *name, const redisReply *rep)
Fetch a KB item or list from a redis Reply.
Definition: kb.c:580
NVT_CVES_POS
@ NVT_CVES_POS
Definition: kb.h:68
NVT_MANDATORY_KEYS_POS
@ NVT_MANDATORY_KEYS_POS
Definition: kb.h:62
nvti_name
gchar * nvti_name(const nvti_t *n)
Get the name.
Definition: nvti.c:517
redis_count
static size_t redis_count(kb_t kb, const char *pattern)
Count all items stored under a given pattern.
Definition: kb.c:1012
select_database
static int select_database(struct kb_redis *kbr)
Select DB.
Definition: kb.c:164
KBRedisOperations
static const struct kb_operations KBRedisOperations
Default KB operations. No selection mechanism is provided yet since there's only one implementation (...
Definition: kb.c:52
kb_redis::rctx
redisContext * rctx
Definition: kb.c:64
redis_get_single
static struct kb_item * redis_get_single(kb_t kb, const char *name, enum kb_item_type type)
Get a single KB element.
Definition: kb.c:677
nvti_excluded_keys
gchar * nvti_excluded_keys(const nvti_t *n)
Get the excluded keys list.
Definition: nvti.c:831
redis_find
static kb_t redis_find(const char *kb_path, const char *key)
Find an existing Knowledge Base object with key.
Definition: kb.c:444
redis_add_int_unique
static int redis_add_int_unique(kb_t kb, const char *name, int val)
Insert (append) a new unique entry under a given name.
Definition: kb.c:1189
nvti_set_required_ports
int nvti_set_required_ports(nvti_t *n, const gchar *required_ports)
Set the required ports of a NVT.
Definition: nvti.c:1397
kb_item::namelen
size_t namelen
Definition: kb.h:96
NVT_REQUIRED_KEYS_POS
@ NVT_REQUIRED_KEYS_POS
Definition: kb.h:61
nvtpref_default
gchar * nvtpref_default(const nvtpref_t *np)
Get the Default of a NVT Preference.
Definition: nvti.c:440
kb_redis::path
char path[0]
Definition: kb.c:65
GLOBAL_DBINDEX_NAME
#define GLOBAL_DBINDEX_NAME
Name of the namespace usage bitmap in redis.
Definition: kb.c:50
nvti_new
nvti_t * nvti_new(void)
Create a new (empty) nvti structure.
Definition: nvti.c:454
NVT_TAGS_POS
@ NVT_TAGS_POS
Definition: kb.h:67
nvtpref_type
gchar * nvtpref_type(const nvtpref_t *np)
Get the Type of a NVT Preference.
Definition: nvti.c:426
KB_TYPE_INT
@ KB_TYPE_INT
Definition: kb.h:49
nvti_set_family
int nvti_set_family(nvti_t *n, const gchar *family)
Set the family of a NVT.
Definition: nvti.c:1492
kb_t
struct kb * kb_t
type abstraction to hide KB internals.
Definition: kb.h:113
nvti_set_category
int nvti_set_category(nvti_t *n, const gint category)
Set the category type of a NVT Info.
Definition: nvti.c:1532
G_LOG_DOMAIN
#define G_LOG_DOMAIN
Definition: kb.c:38
NVT_REQUIRED_PORTS_POS
@ NVT_REQUIRED_PORTS_POS
Definition: kb.h:65
redis_get_nvt_all
static nvti_t * redis_get_nvt_all(kb_t kb, const char *oid)
Get a full NVT.
Definition: kb.c:839
nvti_set_oid
int nvti_set_oid(nvti_t *n, const gchar *oid)
Set the OID of a NVT Info.
Definition: nvti.c:971
redis_test_connection
static int redis_test_connection(struct kb_redis *kbr)
Test redis connection.
Definition: kb.c:293
fetch_max_db_index
static int fetch_max_db_index(struct kb_redis *kbr)
Set the number of databases have been configured into kbr struct.
Definition: kb.c:111
nvti_set_mandatory_keys
int nvti_set_mandatory_keys(nvti_t *n, const gchar *mandatory_keys)
Set the mandatory keys of a NVT.
Definition: nvti.c:1347
redis_add_int
static int redis_add_int(kb_t kb, const char *name, int val)
Insert (append) a new entry under a given name.
Definition: kb.c:1228
kb_item::type
enum kb_item_type type
Definition: kb.h:85
redis_set_int
static int redis_set_int(kb_t kb, const char *name, int val)
Set (replace) a new entry under a given name.
Definition: kb.c:1250
nvti_required_keys
gchar * nvti_required_keys(const nvti_t *n)
Get the required keys list.
Definition: nvti.c:803