Greenbone Vulnerability Management Libraries  10.0.0
kb.h File Reference

Knowledge base management API - Redis backend. More...

#include "../base/nvti.h"
#include <assert.h>
#include <stddef.h>
#include <sys/types.h>
Include dependency graph for kb.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  kb_item
 Knowledge base item (defined by name, type (int/char*) and value). Implemented as a singly linked list. More...
 
struct  kb
 Top-level KB. This is to be inherited by KB implementations. More...
 
struct  kb_operations
 KB interface. Functions provided by an implementation. All functions have to be provided, there is no default/fallback. These functions should be called via the corresponding static inline wrappers below. See the wrappers for the documentation. More...
 

Macros

#define KB_PATH_DEFAULT   "/tmp/redis.sock"
 Default KB location. More...
 

Typedefs

typedef struct kbkb_t
 type abstraction to hide KB internals. More...
 

Enumerations

enum  kb_item_type { KB_TYPE_UNSPEC, KB_TYPE_INT, KB_TYPE_STR, KB_TYPE_CNT }
 Possible type of a kb_item. More...
 
enum  kb_nvt_pos {
  NVT_FILENAME_POS, NVT_REQUIRED_KEYS_POS, NVT_MANDATORY_KEYS_POS, NVT_EXCLUDED_KEYS_POS,
  NVT_REQUIRED_UDP_PORTS_POS, NVT_REQUIRED_PORTS_POS, NVT_DEPENDENCIES_POS, NVT_TAGS_POS,
  NVT_CVES_POS, NVT_BIDS_POS, NVT_XREFS_POS, NVT_CATEGORY_POS,
  NVT_TIMEOUT_POS, NVT_FAMILY_POS, NVT_NAME_POS, NVT_TIMESTAMP_POS,
  NVT_OID_POS
}
 Possible positions of nvt values in cache list. More...
 

Functions

void kb_item_free (struct kb_item *)
 Release a KB item (or a list). More...
 
static int kb_new (kb_t *kb, const char *kb_path)
 Initialize a new Knowledge Base object. More...
 
static kb_t kb_direct_conn (const char *kb_path, const int kb_index)
 Connect to a Knowledge Base object which has the given kb_index. More...
 
static kb_t kb_find (const char *kb_path, const char *key)
 Find an existing Knowledge Base object with key. More...
 
static int kb_delete (kb_t kb)
 Delete all entries and release ownership on the namespace. More...
 
static struct kb_itemkb_item_get_single (kb_t kb, const char *name, enum kb_item_type type)
 Get a single KB element. More...
 
static char * kb_item_get_str (kb_t kb, const char *name)
 Get a single KB string item. More...
 
static int kb_item_get_int (kb_t kb, const char *name)
 Get a single KB integer item. More...
 
static struct kb_itemkb_item_get_all (kb_t kb, const char *name)
 Get all items stored under a given name. More...
 
static struct kb_itemkb_item_get_pattern (kb_t kb, const char *pattern)
 Get all items stored under a given pattern. More...
 
static int kb_item_push_str (kb_t kb, const char *name, const char *value)
 Push a new value under a given key. More...
 
static char * kb_item_pop_str (kb_t kb, const char *name)
 Pop a single KB string item. More...
 
static size_t kb_item_count (kb_t kb, const char *pattern)
 Count all items stored under a given pattern. More...
 
static int kb_item_add_str (kb_t kb, const char *name, const char *str, size_t len)
 Insert (append) a new entry under a given name. More...
 
static int kb_item_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 kb_item_set_str (kb_t kb, const char *name, const char *str, size_t len)
 Set (replace) a new entry under a given name. More...
 
static int kb_item_add_int (kb_t kb, const char *name, int val)
 Insert (append) a new entry under a given name. More...
 
static int kb_item_add_int_unique (kb_t kb, const char *name, int val)
 Insert (append) a new unique entry under a given name. More...
 
static int kb_item_set_int (kb_t kb, const char *name, int val)
 Set (replace) a new entry under a given name. More...
 
static int kb_nvt_add (kb_t kb, const nvti_t *nvt, const char *filename)
 Insert a new nvt. More...
 
static char * kb_nvt_get (kb_t kb, const char *oid, enum kb_nvt_pos position)
 Get field of a NVT. More...
 
static nvti_tkb_nvt_get_all (kb_t kb, const char *oid)
 Get a full NVT. More...
 
static GSList * kb_nvt_get_oids (kb_t kb)
 Get list of NVT OIDs. More...
 
static int kb_del_items (kb_t kb, const char *name)
 Delete all entries under a given name. More...
 
static int kb_save (kb_t kb)
 Save all the KB's content. More...
 
static int kb_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 kb_flush (kb_t kb, const char *except)
 Flush all the KB's content. Delete all namespaces. More...
 
static int kb_get_kb_index (kb_t kb)
 Return the kb index. More...
 

Variables

const struct kb_operationsKBDefaultOperations
 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.

Definition in file kb.h.

Macro Definition Documentation

◆ KB_PATH_DEFAULT

#define KB_PATH_DEFAULT   "/tmp/redis.sock"

Default KB location.

Definition at line 37 of file kb.h.

Typedef Documentation

◆ kb_t

typedef struct kb* kb_t

type abstraction to hide KB internals.

Definition at line 109 of file kb.h.

Enumeration Type Documentation

◆ kb_item_type

Possible type of a kb_item.

Enumerator
KB_TYPE_UNSPEC 

Ignore the value (name/presence test).

KB_TYPE_INT 

The kb_items v should then be interpreted as int.

KB_TYPE_STR 

The kb_items v should then be interpreted as char*.

KB_TYPE_CNT 

Definition at line 42 of file kb.h.

43 {
45  KB_TYPE_INT,
46  KB_TYPE_STR,
47  /* -- */
49 };
Definition: kb.h:46
Definition: kb.h:48
Definition: kb.h:45

◆ kb_nvt_pos

enum kb_nvt_pos

Possible positions of nvt values in cache list.

Enumerator
NVT_FILENAME_POS 
NVT_REQUIRED_KEYS_POS 
NVT_MANDATORY_KEYS_POS 
NVT_EXCLUDED_KEYS_POS 
NVT_REQUIRED_UDP_PORTS_POS 
NVT_REQUIRED_PORTS_POS 
NVT_DEPENDENCIES_POS 
NVT_TAGS_POS 
NVT_CVES_POS 
NVT_BIDS_POS 
NVT_XREFS_POS 
NVT_CATEGORY_POS 
NVT_TIMEOUT_POS 
NVT_FAMILY_POS 
NVT_NAME_POS 
NVT_TIMESTAMP_POS 
NVT_OID_POS 

Definition at line 54 of file kb.h.

Function Documentation

◆ kb_del_items()

static int kb_del_items ( kb_t  kb,
const char *  name 
)
inlinestatic

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 612 of file kb.h.

613 {
614  assert (kb);
615  assert (kb->kb_ops);
616  assert (kb->kb_ops->kb_del_items);
617 
618  return kb->kb_ops->kb_del_items (kb, name);
619 }
int(* kb_del_items)(kb_t, const char *)
Definition: kb.h:212
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103

References kb_operations::kb_del_items, kb::kb_ops, and kb_item::name.

Referenced by nvticache_delete().

Here is the caller graph for this function:

◆ kb_delete()

static int kb_delete ( kb_t  kb)
inlinestatic

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 288 of file kb.h.

289 {
290  assert (kb);
291  assert (kb->kb_ops);
292  assert (kb->kb_ops->kb_delete);
293 
294  return kb->kb_ops->kb_delete (kb);
295 }
int(* kb_delete)(kb_t)
Definition: kb.h:121
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103

References kb_operations::kb_delete, and kb::kb_ops.

◆ kb_direct_conn()

static kb_t kb_direct_conn ( const char *  kb_path,
const int  kb_index 
)
inlinestatic

Connect to a Knowledge Base object which has the given kb_index.

Parameters
[in]kb_pathPath to KB.
[in]kb_indexDB index
Returns
Knowledge Base object, NULL otherwise.

Definition at line 259 of file kb.h.

260 {
261  assert (KBDefaultOperations);
263 
264  return KBDefaultOperations->kb_direct_conn (kb_path, kb_index);
265 }
const struct kb_operations * KBDefaultOperations
Default KB operations. No selection mechanism is provided yet since there's only one implementation (...
Definition: kb.c:1623
kb_t(* kb_direct_conn)(const char *, const int)
Definition: kb.h:123

References kb_operations::kb_direct_conn, and KBDefaultOperations.

◆ kb_find()

static kb_t kb_find ( const char *  kb_path,
const char *  key 
)
inlinestatic

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 274 of file kb.h.

275 {
276  assert (KBDefaultOperations);
277  assert (KBDefaultOperations->kb_find);
278 
279  return KBDefaultOperations->kb_find (kb_path, key);
280 }
const struct kb_operations * KBDefaultOperations
Default KB operations. No selection mechanism is provided yet since there's only one implementation (...
Definition: kb.c:1623
kb_t(* kb_find)(const char *, const char *)
Definition: kb.h:122

References kb_operations::kb_find, and KBDefaultOperations.

Referenced by nvticache_init().

Here is the caller graph for this function:

◆ kb_flush()

static int kb_flush ( kb_t  kb,
const char *  except 
)
inlinestatic

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 667 of file kb.h.

668 {
669  int rc = 0;
670 
671  assert (kb);
672  assert (kb->kb_ops);
673 
674  if (kb->kb_ops->kb_flush != NULL)
675  rc = kb->kb_ops->kb_flush (kb, except);
676 
677  return rc;
678 }
int(* kb_flush)(kb_t, const char *)
Definition: kb.h:217
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103

References kb_operations::kb_flush, and kb::kb_ops.

◆ kb_get_kb_index()

static int kb_get_kb_index ( kb_t  kb)
inlinestatic

Return the kb index.

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

Definition at line 686 of file kb.h.

687 {
688  assert (kb);
689  assert (kb->kb_ops);
690  assert (kb->kb_ops->kb_get_kb_index);
691 
692  return kb->kb_ops->kb_get_kb_index (kb);
693 }
int(* kb_get_kb_index)(kb_t)
Definition: kb.h:218
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103

References kb_operations::kb_get_kb_index, and kb::kb_ops.

◆ kb_item_add_int()

static int kb_item_add_int ( kb_t  kb,
const char *  name,
int  val 
)
inlinestatic

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 497 of file kb.h.

498 {
499  assert (kb);
500  assert (kb->kb_ops);
501  assert (kb->kb_ops->kb_add_int);
502 
503  return kb->kb_ops->kb_add_int (kb, name, val);
504 }
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103
int(* kb_add_int)(kb_t, const char *, int)
Definition: kb.h:192

References kb_operations::kb_add_int, kb::kb_ops, and kb_item::name.

◆ kb_item_add_int_unique()

static int kb_item_add_int_unique ( kb_t  kb,
const char *  name,
int  val 
)
inlinestatic

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 514 of file kb.h.

515 {
516  assert (kb);
517  assert (kb->kb_ops);
518  assert (kb->kb_ops->kb_add_int_unique);
519 
520  return kb->kb_ops->kb_add_int_unique (kb, name, val);
521 }
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103
int(* kb_add_int_unique)(kb_t, const char *, int)
Definition: kb.h:197

References kb_operations::kb_add_int_unique, kb::kb_ops, and kb_item::name.

◆ kb_item_add_str()

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

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 444 of file kb.h.

445 {
446  assert (kb);
447  assert (kb->kb_ops);
448  assert (kb->kb_ops->kb_add_str);
449 
450  return kb->kb_ops->kb_add_str (kb, name, str, len);
451 }
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103
int(* kb_add_str)(kb_t, const char *, const char *, size_t)
Definition: kb.h:177

References kb_operations::kb_add_str, kb::kb_ops, kb_item::len, and kb_item::name.

◆ kb_item_add_str_unique()

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

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 462 of file kb.h.

463 {
464  assert (kb);
465  assert (kb->kb_ops);
466  assert (kb->kb_ops->kb_add_str_unique);
467 
468  return kb->kb_ops->kb_add_str_unique (kb, name, str, len);
469 }
int(* kb_add_str_unique)(kb_t, const char *, const char *, size_t)
Definition: kb.h:182
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103

References kb_operations::kb_add_str_unique, kb::kb_ops, kb_item::len, and kb_item::name.

◆ kb_item_count()

static size_t kb_item_count ( kb_t  kb,
const char *  pattern 
)
inlinestatic

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 426 of file kb.h.

427 {
428  assert (kb);
429  assert (kb->kb_ops);
430  assert (kb->kb_ops->kb_count);
431 
432  return kb->kb_ops->kb_count (kb, pattern);
433 }
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103
size_t(* kb_count)(kb_t, const char *)
Definition: kb.h:172

References kb_operations::kb_count, and kb::kb_ops.

Referenced by nvticache_count().

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

609 {
610  while (item != NULL)
611  {
612  struct kb_item *next;
613 
614  next = item->next;
615  if (item->type == KB_TYPE_STR && item->v_str != NULL)
616  g_free (item->v_str);
617  g_free (item);
618  item = next;
619  }
620 }
Definition: kb.h:46
Knowledge base item (defined by name, type (int/char*) and value). Implemented as a singly linked lis...
Definition: kb.h:79
struct kb_item * next
Definition: kb.h:90
enum kb_item_type type
Definition: kb.h:81
char * v_str
Definition: kb.h:85

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:

◆ kb_item_get_all()

static struct kb_item* kb_item_get_all ( kb_t  kb,
const char *  name 
)
inlinestatic

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 357 of file kb.h.

358 {
359  assert (kb);
360  assert (kb->kb_ops);
361  assert (kb->kb_ops->kb_get_all);
362 
363  return kb->kb_ops->kb_get_all (kb, name);
364 }
struct kb_item *(* kb_get_all)(kb_t, const char *)
Definition: kb.h:162
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103
char name[0]
Definition: kb.h:93

References kb_operations::kb_get_all, kb::kb_ops, and kb_item::name.

Referenced by nvticache_get_prefs().

Here is the caller graph for this function:

◆ kb_item_get_int()

static int kb_item_get_int ( kb_t  kb,
const char *  name 
)
inlinestatic

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 340 of file kb.h.

341 {
342  assert (kb);
343  assert (kb->kb_ops);
344  assert (kb->kb_ops->kb_get_int);
345 
346  return kb->kb_ops->kb_get_int (kb, name);
347 }
int(* kb_get_int)(kb_t, const char *)
Definition: kb.h:137
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103
char name[0]
Definition: kb.h:93

References kb_operations::kb_get_int, kb::kb_ops, and kb_item::name.

◆ kb_item_get_pattern()

static struct kb_item* kb_item_get_pattern ( kb_t  kb,
const char *  pattern 
)
inlinestatic

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 374 of file kb.h.

375 {
376  assert (kb);
377  assert (kb->kb_ops);
378  assert (kb->kb_ops->kb_get_pattern);
379 
380  return kb->kb_ops->kb_get_pattern (kb, pattern);
381 }
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103
struct kb_item *(* kb_get_pattern)(kb_t, const char *)
Definition: kb.h:167

References kb_operations::kb_get_pattern, and kb::kb_ops.

◆ kb_item_get_single()

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

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 306 of file kb.h.

307 {
308  assert (kb);
309  assert (kb->kb_ops);
310  assert (kb->kb_ops->kb_get_single);
311 
312  return kb->kb_ops->kb_get_single (kb, name, type);
313 }
enum kb_item_type type
Definition: kb.h:81
struct kb_item *(* kb_get_single)(kb_t, const char *, enum kb_item_type)
Definition: kb.h:129
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103
char name[0]
Definition: kb.h:93

References kb_operations::kb_get_single, kb::kb_ops, kb_item::name, and kb_item::type.

◆ kb_item_get_str()

static char* kb_item_get_str ( kb_t  kb,
const char *  name 
)
inlinestatic

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 323 of file kb.h.

324 {
325  assert (kb);
326  assert (kb->kb_ops);
327  assert (kb->kb_ops->kb_get_str);
328 
329  return kb->kb_ops->kb_get_str (kb, name);
330 }
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103
char name[0]
Definition: kb.h:93
char *(* kb_get_str)(kb_t, const char *)
Definition: kb.h:133

References kb_operations::kb_get_str, kb::kb_ops, and kb_item::name.

Referenced by nvticache_check_feed(), nvticache_feed_version(), redis_find(), and redis_flush_all().

Here is the caller graph for this function:

◆ kb_item_pop_str()

static char* kb_item_pop_str ( kb_t  kb,
const char *  name 
)
inlinestatic

Pop 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 408 of file kb.h.

409 {
410  assert (kb);
411  assert (kb->kb_ops);
412  assert (kb->kb_ops->kb_pop_str);
413 
414  return kb->kb_ops->kb_pop_str (kb, name);
415 }
char *(* kb_pop_str)(kb_t, const char *)
Definition: kb.h:157
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103
char name[0]
Definition: kb.h:93

References kb::kb_ops, kb_operations::kb_pop_str, and kb_item::name.

◆ kb_item_push_str()

static int kb_item_push_str ( kb_t  kb,
const char *  name,
const char *  value 
)
inlinestatic

Push a new value 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 391 of file kb.h.

392 {
393  assert (kb);
394  assert (kb->kb_ops);
395  assert (kb->kb_ops->kb_push_str);
396 
397  return kb->kb_ops->kb_push_str (kb, name, value);
398 }
int(* kb_push_str)(kb_t, const char *, const char *)
Definition: kb.h:153
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103
char name[0]
Definition: kb.h:93

References kb::kb_ops, kb_operations::kb_push_str, and kb_item::name.

◆ kb_item_set_int()

static int kb_item_set_int ( kb_t  kb,
const char *  name,
int  val 
)
inlinestatic

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 531 of file kb.h.

532 {
533  assert (kb);
534  assert (kb->kb_ops);
535  assert (kb->kb_ops->kb_set_int);
536 
537  return kb->kb_ops->kb_set_int (kb, name, val);
538 }
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103
int(* kb_set_int)(kb_t, const char *, int)
Definition: kb.h:202
char name[0]
Definition: kb.h:93

References kb::kb_ops, kb_operations::kb_set_int, and kb_item::name.

◆ kb_item_set_str()

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

Set (replace) 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 480 of file kb.h.

481 {
482  assert (kb);
483  assert (kb->kb_ops);
484  assert (kb->kb_ops->kb_set_str);
485 
486  return kb->kb_ops->kb_set_str (kb, name, str, len);
487 }
int(* kb_set_str)(kb_t, const char *, const char *, size_t)
Definition: kb.h:187
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103
size_t len
Definition: kb.h:89
char name[0]
Definition: kb.h:93

References kb::kb_ops, kb_operations::kb_set_str, kb_item::len, and kb_item::name.

Referenced by nvticache_init(), and nvticache_save().

Here is the caller graph for this function:

◆ kb_lnk_reset()

static int kb_lnk_reset ( kb_t  kb)
inlinestatic

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 647 of file kb.h.

648 {
649  int rc = 0;
650 
651  assert (kb);
652  assert (kb->kb_ops);
653 
654  if (kb->kb_ops->kb_lnk_reset != NULL)
655  rc = kb->kb_ops->kb_lnk_reset (kb);
656 
657  return rc;
658 }
int(* kb_lnk_reset)(kb_t)
Definition: kb.h:216
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103

References kb_operations::kb_lnk_reset, and kb::kb_ops.

Referenced by nvticache_init(), and nvticache_reset().

Here is the caller graph for this function:

◆ kb_new()

static int kb_new ( kb_t kb,
const char *  kb_path 
)
inlinestatic

Initialize a new Knowledge Base object.

Parameters
[in]kbReference to a kb_t to initialize.
[in]kb_pathPath to KB.
Returns
0 on success, non-null on error.

Definition at line 241 of file kb.h.

242 {
243  assert (kb);
244  assert (KBDefaultOperations);
245  assert (KBDefaultOperations->kb_new);
246 
247  *kb = NULL;
248 
249  return KBDefaultOperations->kb_new (kb, kb_path);
250 }
const struct kb_operations * KBDefaultOperations
Default KB operations. No selection mechanism is provided yet since there's only one implementation (...
Definition: kb.c:1623
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
int(* kb_new)(kb_t *, const char *)
Definition: kb.h:120

References kb_operations::kb_new, and KBDefaultOperations.

Referenced by nvticache_init().

Here is the caller graph for this function:

◆ kb_nvt_add()

static int kb_nvt_add ( kb_t  kb,
const nvti_t nvt,
const char *  filename 
)
inlinestatic

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 548 of file kb.h.

549 {
550  assert (kb);
551  assert (kb->kb_ops);
552  assert (kb->kb_ops->kb_add_nvt);
553 
554  return kb->kb_ops->kb_add_nvt (kb, nvt, filename);
555 }
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103
int(* kb_add_nvt)(kb_t, const nvti_t *, const char *)
Definition: kb.h:207

References kb_operations::kb_add_nvt, and kb::kb_ops.

Referenced by nvticache_add().

Here is the caller graph for this function:

◆ kb_nvt_get()

static char* kb_nvt_get ( kb_t  kb,
const char *  oid,
enum kb_nvt_pos  position 
)
inlinestatic

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 565 of file kb.h.

566 {
567  assert (kb);
568  assert (kb->kb_ops);
569  assert (kb->kb_ops->kb_get_nvt);
570 
571  return kb->kb_ops->kb_get_nvt (kb, oid, position);
572 }
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103
char *(* kb_get_nvt)(kb_t, const char *, enum kb_nvt_pos)
Definition: kb.h:141

References kb_operations::kb_get_nvt, and kb::kb_ops.

Referenced by nvticache_check(), nvticache_get_bids(), nvticache_get_category(), nvticache_get_cves(), nvticache_get_dependencies(), nvticache_get_excluded_keys(), nvticache_get_family(), nvticache_get_filename(), nvticache_get_mandatory_keys(), nvticache_get_name(), nvticache_get_oid(), nvticache_get_required_keys(), nvticache_get_required_ports(), nvticache_get_required_udp_ports(), nvticache_get_src(), nvticache_get_tags(), nvticache_get_timeout(), and nvticache_get_xrefs().

Here is the caller graph for this function:

◆ kb_nvt_get_all()

static nvti_t* kb_nvt_get_all ( kb_t  kb,
const char *  oid 
)
inlinestatic

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 581 of file kb.h.

582 {
583  assert (kb);
584  assert (kb->kb_ops);
585  assert (kb->kb_ops->kb_get_nvt_all);
586 
587  return kb->kb_ops->kb_get_nvt_all (kb, oid);
588 }
nvti_t *(* kb_get_nvt_all)(kb_t, const char *)
Definition: kb.h:145
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103

References kb_operations::kb_get_nvt_all, and kb::kb_ops.

Referenced by nvticache_get_nvt().

Here is the caller graph for this function:

◆ kb_nvt_get_oids()

static GSList* kb_nvt_get_oids ( kb_t  kb)
inlinestatic

Get list of NVT OIDs.

Parameters
[in]kbKB handle where NVTs are stored.
Returns
Linked-list of OIDs, NULL otherwise.

Definition at line 596 of file kb.h.

597 {
598  assert (kb);
599  assert (kb->kb_ops);
600  assert (kb->kb_ops->kb_get_nvt_oids);
601 
602  return kb->kb_ops->kb_get_nvt_oids (kb);
603 }
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103
GSList *(* kb_get_nvt_oids)(kb_t)
Definition: kb.h:149

References kb_operations::kb_get_nvt_oids, and kb::kb_ops.

Referenced by nvticache_get_oids().

Here is the caller graph for this function:

◆ kb_save()

static int kb_save ( kb_t  kb)
inlinestatic

Save all the KB's content.

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

Definition at line 627 of file kb.h.

628 {
629  int rc = 0;
630 
631  assert (kb);
632  assert (kb->kb_ops);
633 
634  if (kb->kb_ops->kb_save != NULL)
635  rc = kb->kb_ops->kb_save (kb);
636 
637  return rc;
638 }
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:101
const struct kb_operations * kb_ops
Definition: kb.h:103
int(* kb_save)(kb_t)
Definition: kb.h:215

References kb::kb_ops, and kb_operations::kb_save.

Referenced by nvticache_save().

Here is the caller graph for this function:

Variable Documentation

◆ KBDefaultOperations

const struct kb_operations* KBDefaultOperations

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

Definition at line 1623 of file kb.c.

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