Greenbone Vulnerability Management Libraries 22.8.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   "/run/redis/redis.sock"
 Default KB location.
 

Typedefs

typedef struct kbkb_t
 type abstraction to hide KB internals.
 

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_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).
 
static int kb_new (kb_t *kb, const char *kb_path)
 Initialize a new Knowledge Base object.
 
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.
 
static kb_t kb_find (const char *kb_path, const char *key)
 Find an existing Knowledge Base object with key.
 
static int kb_delete (kb_t kb)
 Delete all entries and release ownership on the namespace.
 
static struct kb_itemkb_item_get_single (kb_t kb, const char *name, enum kb_item_type type)
 Get a single KB element.
 
static char * kb_item_get_str (kb_t kb, const char *name)
 Get a single KB string item.
 
static int kb_item_get_int (kb_t kb, const char *name)
 Get a single KB integer item.
 
static struct kb_itemkb_item_get_all (kb_t kb, const char *name)
 Get all items stored under a given name.
 
static struct kb_itemkb_item_get_pattern (kb_t kb, const char *pattern)
 Get all items stored under a given pattern.
 
static int kb_item_push_str (kb_t kb, const char *name, const char *value)
 Push a new value under a given key.
 
static char * kb_item_pop_str (kb_t kb, const char *name)
 Pop a single KB string item.
 
static size_t kb_item_count (kb_t kb, const char *pattern)
 Count all items stored under a given pattern.
 
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.
 
static int kb_item_add_str_unique (kb_t kb, const char *name, const char *str, size_t len, int pos)
 Insert (append) a new unique entry under a given name.
 
static int kb_add_str_unique_volatile (kb_t kb, const char *name, const char *str, int expire, size_t len, int pos)
 Insert (append) a new unique and volatile entry under a given name.
 
static int 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.
 
static int kb_item_add_int (kb_t kb, const char *name, int val)
 Insert (append) a new entry under a given name.
 
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.
 
static int kb_add_int_unique_volatile (kb_t kb, const char *name, int val, int expire)
 Insert (append) a new unique and volatile entry under a given name.
 
static int kb_item_set_int (kb_t kb, const char *name, int val)
 Set (replace) a new entry under a given name.
 
static int kb_nvt_add (kb_t kb, const nvti_t *nvt, const char *filename)
 Insert a new nvt.
 
static char * kb_nvt_get (kb_t kb, const char *oid, enum kb_nvt_pos position)
 Get field of a NVT.
 
static nvti_tkb_nvt_get_all (kb_t kb, const char *oid)
 Get a full NVT.
 
static GSList * kb_nvt_get_oids (kb_t kb)
 Get list of NVT OIDs.
 
static int kb_del_items (kb_t kb, const char *name)
 Delete all entries under a given name.
 
static int kb_save (kb_t kb)
 Save all the KB's content.
 
static int kb_lnk_reset (kb_t kb)
 Reset connection to the KB. This is called after each fork() to make.
 
static int kb_flush (kb_t kb, const char *except)
 Flush all the KB's content. Delete all namespaces.
 
static int kb_get_kb_index (kb_t kb)
 Return the kb index.
 

Variables

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

Detailed Description

Knowledge base management API - Redis backend.

Definition in file kb.h.

Macro Definition Documentation

◆ KB_PATH_DEFAULT

#define KB_PATH_DEFAULT   "/run/redis/redis.sock"

Default KB location.

Definition at line 26 of file kb.h.

Typedef Documentation

◆ kb_t

typedef struct kb* kb_t

type abstraction to hide KB internals.

Definition at line 98 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 32 of file kb.h.

33{
37 /* -- */
39};
@ KB_TYPE_INT
Definition: kb.h:35
@ KB_TYPE_CNT
Definition: kb.h:38
@ KB_TYPE_UNSPEC
Definition: kb.h:34
@ KB_TYPE_STR
Definition: kb.h:36

◆ 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_FAMILY_POS 
NVT_NAME_POS 
NVT_TIMESTAMP_POS 
NVT_OID_POS 

Definition at line 44 of file kb.h.

45{
62};
@ NVT_FAMILY_POS
Definition: kb.h:58
@ NVT_CATEGORY_POS
Definition: kb.h:57
@ NVT_TIMESTAMP_POS
Definition: kb.h:60
@ NVT_NAME_POS
Definition: kb.h:59
@ NVT_TAGS_POS
Definition: kb.h:53
@ NVT_BIDS_POS
Definition: kb.h:55
@ NVT_EXCLUDED_KEYS_POS
Definition: kb.h:49
@ NVT_REQUIRED_PORTS_POS
Definition: kb.h:51
@ NVT_REQUIRED_UDP_PORTS_POS
Definition: kb.h:50
@ NVT_FILENAME_POS
Definition: kb.h:46
@ NVT_OID_POS
Definition: kb.h:61
@ NVT_DEPENDENCIES_POS
Definition: kb.h:52
@ NVT_CVES_POS
Definition: kb.h:54
@ NVT_REQUIRED_KEYS_POS
Definition: kb.h:47
@ NVT_XREFS_POS
Definition: kb.h:56
@ NVT_MANDATORY_KEYS_POS
Definition: kb.h:48

Function Documentation

◆ kb_add_int_unique_volatile()

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

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

Parameters
[in]kbReference to a kb_t to initialize.
[in]nameItem name.
[in]valItem value.
[in]expireItem expire.
Returns
0 on success, -1 on error.

Definition at line 597 of file kb.h.

598{
599 assert (kb);
600 assert (KBDefaultOperations);
602
604 expire);
605}
const struct kb_operations * KBDefaultOperations
Default KB operations. No selection mechanism is provided yet since there's only one implementation (...
Definition: kb.c:1877
int(* kb_add_int_unique_volatile)(kb_t, const char *, int, int)
Definition: kb.h:197
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:91

References kb_operations::kb_add_int_unique_volatile, KBDefaultOperations, and kb_item::name.

◆ kb_add_str_unique_volatile()

static int kb_add_str_unique_volatile ( kb_t  kb,
const char *  name,
const char *  str,
int  expire,
size_t  len,
int  pos 
)
inlinestatic

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

Parameters
[in]kbReference to a kb_t to initialize.
[in]nameItem name.
[in]strString to add.
[in]lenValue length. Used for blobs.
[in]expireItem expire.
[in]posWhich position the value is appended to. 0 for right, 1 for left position in the list.
Returns
0 on success, -1 on error.

Definition at line 516 of file kb.h.

518{
519 assert (kb);
520 assert (KBDefaultOperations);
522
523 return KBDefaultOperations->kb_add_str_unique_volatile (kb, name, str, expire,
524 len, pos);
525}
int(* kb_add_str_unique_volatile)(kb_t, const char *, const char *, int, size_t, int)
Definition: kb.h:176

References kb_operations::kb_add_str_unique_volatile, KBDefaultOperations, kb_item::len, and kb_item::name.

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

709{
710 assert (kb);
711 assert (kb->kb_ops);
712 assert (kb->kb_ops->kb_del_items);
713
714 return kb->kb_ops->kb_del_items (kb, name);
715}
int(* kb_del_items)(kb_t, const char *)
Definition: kb.h:212
const struct kb_operations * kb_ops
Definition: kb.h:92

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

297{
298 assert (kb);
299 assert (kb->kb_ops);
300 assert (kb->kb_ops->kb_delete);
301
302 return kb->kb_ops->kb_delete (kb);
303}
int(* kb_delete)(kb_t)
Definition: kb.h:110

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

264{
265 assert (KBDefaultOperations);
267
268 return KBDefaultOperations->kb_direct_conn (kb_path, kb_index);
269}
kb_t(* kb_direct_conn)(const char *, const int)
Definition: kb.h:112

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

281{
282 assert (KBDefaultOperations);
284
285 return KBDefaultOperations->kb_find (kb_path, key);
286}
kb_t(* kb_find)(const char *, const char *)
Definition: kb.h:111

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

770{
771 int rc = 0;
772
773 assert (kb);
774 assert (kb->kb_ops);
775
776 if (kb->kb_ops->kb_flush != NULL)
777 rc = kb->kb_ops->kb_flush (kb, except);
778
779 return rc;
780}
int(* kb_flush)(kb_t, const char *)
Definition: kb.h:217

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

791{
792 assert (kb);
793 assert (kb->kb_ops);
794 assert (kb->kb_ops->kb_get_kb_index);
795
796 return kb->kb_ops->kb_get_kb_index (kb);
797}
int(* kb_get_kb_index)(kb_t)
Definition: kb.h:218

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

558{
559 assert (kb);
560 assert (kb->kb_ops);
561 assert (kb->kb_ops->kb_add_int);
562
563 return kb->kb_ops->kb_add_int (kb, name, val);
564}
int(* kb_add_int)(kb_t, const char *, int)
Definition: kb.h:187

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

577{
578 assert (kb);
579 assert (kb->kb_ops);
580 assert (kb->kb_ops->kb_add_int_unique);
581
582 return kb->kb_ops->kb_add_int_unique (kb, name, val);
583}
int(* kb_add_int_unique)(kb_t, const char *, int)
Definition: kb.h:192

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

469{
470 assert (kb);
471 assert (kb->kb_ops);
472 assert (kb->kb_ops->kb_add_str);
473
474 return kb->kb_ops->kb_add_str (kb, name, str, len);
475}
int(* kb_add_str)(kb_t, const char *, const char *, size_t)
Definition: kb.h:166

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,
int  pos 
)
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.
[in]posWhich position the value is appended to. 0 for right, 1 for left position in the list.
Returns
0 on success, non-null on error.

Definition at line 490 of file kb.h.

492{
493 assert (kb);
494 assert (kb->kb_ops);
495 assert (kb->kb_ops->kb_add_str_unique);
496
497 return kb->kb_ops->kb_add_str_unique (kb, name, str, len, pos);
498}
int(* kb_add_str_unique)(kb_t, const char *, const char *, size_t, int)
Definition: kb.h:171

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

449{
450 assert (kb);
451 assert (kb->kb_ops);
452 assert (kb->kb_ops->kb_count);
453
454 return kb->kb_ops->kb_count (kb, pattern);
455}
size_t(* kb_count)(kb_t, const char *)
Definition: kb.h:161

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

640{
641 while (item != NULL)
642 {
643 struct kb_item *next;
644
645 next = item->next;
646 if (item->type == KB_TYPE_STR && item->v_str != NULL)
647 g_free (item->v_str);
648 g_free (item);
649 item = next;
650 }
651}
Knowledge base item (defined by name, type (int/char*) and value). Implemented as a singly linked lis...
Definition: kb.h:69
enum kb_item_type type
Definition: kb.h:70
char * v_str
Definition: kb.h:74
struct kb_item * next
Definition: kb.h:79

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

372{
373 assert (kb);
374 assert (kb->kb_ops);
375 assert (kb->kb_ops->kb_get_all);
376
377 return kb->kb_ops->kb_get_all (kb, name);
378}
struct kb_item *(* kb_get_all)(kb_t, const char *)
Definition: kb.h:151

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
An integer.

Definition at line 352 of file kb.h.

353{
354 assert (kb);
355 assert (kb->kb_ops);
356 assert (kb->kb_ops->kb_get_int);
357
358 return kb->kb_ops->kb_get_int (kb, name);
359}
int(* kb_get_int)(kb_t, const char *)
Definition: kb.h:126

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

391{
392 assert (kb);
393 assert (kb->kb_ops);
394 assert (kb->kb_ops->kb_get_pattern);
395
396 return kb->kb_ops->kb_get_pattern (kb, pattern);
397}
struct kb_item *(* kb_get_pattern)(kb_t, const char *)
Definition: kb.h:156

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

317{
318 assert (kb);
319 assert (kb->kb_ops);
320 assert (kb->kb_ops->kb_get_single);
321
322 return kb->kb_ops->kb_get_single (kb, name, type);
323}
struct kb_item *(* kb_get_single)(kb_t, const char *, enum kb_item_type)
Definition: kb.h:118

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 string to be freed or NULL if list is empty or on error.

Definition at line 334 of file kb.h.

335{
336 assert (kb);
337 assert (kb->kb_ops);
338 assert (kb->kb_ops->kb_get_str);
339
340 return kb->kb_ops->kb_get_str (kb, name);
341}
char *(* kb_get_str)(kb_t, const char *)
Definition: kb.h:122

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

429{
430 assert (kb);
431 assert (kb->kb_ops);
432 assert (kb->kb_ops->kb_pop_str);
433
434 return kb->kb_ops->kb_pop_str (kb, name);
435}
char *(* kb_pop_str)(kb_t, const char *)
Definition: kb.h:146

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

410{
411 assert (kb);
412 assert (kb->kb_ops);
413 assert (kb->kb_ops->kb_push_str);
414
415 return kb->kb_ops->kb_push_str (kb, name, value);
416}
int(* kb_push_str)(kb_t, const char *, const char *)
Definition: kb.h:142

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

618{
619 assert (kb);
620 assert (kb->kb_ops);
621 assert (kb->kb_ops->kb_set_int);
622
623 return kb->kb_ops->kb_set_int (kb, name, val);
624}
int(* kb_set_int)(kb_t, const char *, int)
Definition: kb.h:202

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

539{
540 assert (kb);
541 assert (kb->kb_ops);
542 assert (kb->kb_ops->kb_set_str);
543
544 return kb->kb_ops->kb_set_str (kb, name, str, len);
545}
int(* kb_set_str)(kb_t, const char *, const char *, size_t)
Definition: kb.h:182

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

748{
749 int rc = 0;
750
751 assert (kb);
752 assert (kb->kb_ops);
753
754 if (kb->kb_ops->kb_lnk_reset != NULL)
755 rc = kb->kb_ops->kb_lnk_reset (kb);
756
757 return rc;
758}
int(* kb_lnk_reset)(kb_t)
Definition: kb.h:216

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, -1 on connection error, -2 on unavailable DB spot.

Definition at line 243 of file kb.h.

244{
245 assert (kb);
246 assert (KBDefaultOperations);
247 assert (KBDefaultOperations->kb_new);
248
249 *kb = NULL;
250
251 return KBDefaultOperations->kb_new (kb, kb_path);
252}
int(* kb_new)(kb_t *, const char *)
Definition: kb.h:109

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

637{
638 assert (kb);
639 assert (kb->kb_ops);
640 assert (kb->kb_ops->kb_add_nvt);
641
642 return kb->kb_ops->kb_add_nvt (kb, nvt, filename);
643}
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 655 of file kb.h.

656{
657 assert (kb);
658 assert (kb->kb_ops);
659 assert (kb->kb_ops->kb_get_nvt);
660
661 return kb->kb_ops->kb_get_nvt (kb, oid, position);
662}
char *(* kb_get_nvt)(kb_t, const char *, enum kb_nvt_pos)
Definition: kb.h:130

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(), 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 673 of file kb.h.

674{
675 assert (kb);
676 assert (kb->kb_ops);
677 assert (kb->kb_ops->kb_get_nvt_all);
678
679 return kb->kb_ops->kb_get_nvt_all (kb, oid);
680}
nvti_t *(* kb_get_nvt_all)(kb_t, const char *)
Definition: kb.h:134

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

691{
692 assert (kb);
693 assert (kb->kb_ops);
694 assert (kb->kb_ops->kb_get_nvt_oids);
695
696 return kb->kb_ops->kb_get_nvt_oids (kb);
697}
GSList *(* kb_get_nvt_oids)(kb_t)
Definition: kb.h:138

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

726{
727 int rc = 0;
728
729 assert (kb);
730 assert (kb->kb_ops);
731
732 if (kb->kb_ops->kb_save != NULL)
733 rc = kb->kb_ops->kb_save (kb);
734
735 return rc;
736}
int(* kb_save)(kb_t)
Definition: kb.h:215

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

Variable Documentation

◆ KBDefaultOperations

const struct kb_operations* KBDefaultOperations
extern

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

Definition at line 1877 of file kb.c.

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