Greenbone Vulnerability Management Libraries  11.0.1
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. 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   "/run/redis/redis.sock"

Default KB location.

Definition at line 40 of file kb.h.

Typedef Documentation

◆ kb_t

typedef struct kb* kb_t

type abstraction to hide KB internals.

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

47 {
49  KB_TYPE_INT,
50  KB_TYPE_STR,
51  /* -- */
53 };

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

617 {
618  assert (kb);
619  assert (kb->kb_ops);
620  assert (kb->kb_ops->kb_del_items);
621 
622  return kb->kb_ops->kb_del_items (kb, name);
623 }

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

293 {
294  assert (kb);
295  assert (kb->kb_ops);
296  assert (kb->kb_ops->kb_delete);
297 
298  return kb->kb_ops->kb_delete (kb);
299 }

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 }

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

279 {
280  assert (KBDefaultOperations);
281  assert (KBDefaultOperations->kb_find);
282 
283  return KBDefaultOperations->kb_find (kb_path, key);
284 }

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

672 {
673  int rc = 0;
674 
675  assert (kb);
676  assert (kb->kb_ops);
677 
678  if (kb->kb_ops->kb_flush != NULL)
679  rc = kb->kb_ops->kb_flush (kb, except);
680 
681  return rc;
682 }

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

691 {
692  assert (kb);
693  assert (kb->kb_ops);
694  assert (kb->kb_ops->kb_get_kb_index);
695 
696  return kb->kb_ops->kb_get_kb_index (kb);
697 }

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

502 {
503  assert (kb);
504  assert (kb->kb_ops);
505  assert (kb->kb_ops->kb_add_int);
506 
507  return kb->kb_ops->kb_add_int (kb, name, val);
508 }

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

519 {
520  assert (kb);
521  assert (kb->kb_ops);
522  assert (kb->kb_ops->kb_add_int_unique);
523 
524  return kb->kb_ops->kb_add_int_unique (kb, name, val);
525 }

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

449 {
450  assert (kb);
451  assert (kb->kb_ops);
452  assert (kb->kb_ops->kb_add_str);
453 
454  return kb->kb_ops->kb_add_str (kb, name, str, len);
455 }

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

467 {
468  assert (kb);
469  assert (kb->kb_ops);
470  assert (kb->kb_ops->kb_add_str_unique);
471 
472  return kb->kb_ops->kb_add_str_unique (kb, name, str, len);
473 }

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

431 {
432  assert (kb);
433  assert (kb->kb_ops);
434  assert (kb->kb_ops->kb_count);
435 
436  return kb->kb_ops->kb_count (kb, pattern);
437 }

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

538 {
539  while (item != NULL)
540  {
541  struct kb_item *next;
542 
543  next = item->next;
544  if (item->type == KB_TYPE_STR && item->v_str != NULL)
545  g_free (item->v_str);
546  g_free (item);
547  item = next;
548  }
549 }

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

362 {
363  assert (kb);
364  assert (kb->kb_ops);
365  assert (kb->kb_ops->kb_get_all);
366 
367  return kb->kb_ops->kb_get_all (kb, name);
368 }

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

345 {
346  assert (kb);
347  assert (kb->kb_ops);
348  assert (kb->kb_ops->kb_get_int);
349 
350  return kb->kb_ops->kb_get_int (kb, name);
351 }

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

379 {
380  assert (kb);
381  assert (kb->kb_ops);
382  assert (kb->kb_ops->kb_get_pattern);
383 
384  return kb->kb_ops->kb_get_pattern (kb, pattern);
385 }

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

311 {
312  assert (kb);
313  assert (kb->kb_ops);
314  assert (kb->kb_ops->kb_get_single);
315 
316  return kb->kb_ops->kb_get_single (kb, name, type);
317 }

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

328 {
329  assert (kb);
330  assert (kb->kb_ops);
331  assert (kb->kb_ops->kb_get_str);
332 
333  return kb->kb_ops->kb_get_str (kb, name);
334 }

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

413 {
414  assert (kb);
415  assert (kb->kb_ops);
416  assert (kb->kb_ops->kb_pop_str);
417 
418  return kb->kb_ops->kb_pop_str (kb, name);
419 }

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

396 {
397  assert (kb);
398  assert (kb->kb_ops);
399  assert (kb->kb_ops->kb_push_str);
400 
401  return kb->kb_ops->kb_push_str (kb, name, value);
402 }

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

536 {
537  assert (kb);
538  assert (kb->kb_ops);
539  assert (kb->kb_ops->kb_set_int);
540 
541  return kb->kb_ops->kb_set_int (kb, name, val);
542 }

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

485 {
486  assert (kb);
487  assert (kb->kb_ops);
488  assert (kb->kb_ops->kb_set_str);
489 
490  return kb->kb_ops->kb_set_str (kb, name, str, len);
491 }

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

652 {
653  int rc = 0;
654 
655  assert (kb);
656  assert (kb->kb_ops);
657 
658  if (kb->kb_ops->kb_lnk_reset != NULL)
659  rc = kb->kb_ops->kb_lnk_reset (kb);
660 
661  return rc;
662 }

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

246 {
247  assert (kb);
248  assert (KBDefaultOperations);
249  assert (KBDefaultOperations->kb_new);
250 
251  *kb = NULL;
252 
253  return KBDefaultOperations->kb_new (kb, kb_path);
254 }

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

553 {
554  assert (kb);
555  assert (kb->kb_ops);
556  assert (kb->kb_ops->kb_add_nvt);
557 
558  return kb->kb_ops->kb_add_nvt (kb, nvt, filename);
559 }

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

570 {
571  assert (kb);
572  assert (kb->kb_ops);
573  assert (kb->kb_ops->kb_get_nvt);
574 
575  return kb->kb_ops->kb_get_nvt (kb, oid, position);
576 }

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

586 {
587  assert (kb);
588  assert (kb->kb_ops);
589  assert (kb->kb_ops->kb_get_nvt_all);
590 
591  return kb->kb_ops->kb_get_nvt_all (kb, oid);
592 }

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

601 {
602  assert (kb);
603  assert (kb->kb_ops);
604  assert (kb->kb_ops->kb_get_nvt_oids);
605 
606  return kb->kb_ops->kb_get_nvt_oids (kb);
607 }

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

632 {
633  int rc = 0;
634 
635  assert (kb);
636  assert (kb->kb_ops);
637 
638  if (kb->kb_ops->kb_save != NULL)
639  rc = kb->kb_ops->kb_save (kb);
640 
641  return rc;
642 }

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

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

NVT_EXCLUDED_KEYS_POS
@ NVT_EXCLUDED_KEYS_POS
Definition: kb.h:63
NVT_BIDS_POS
@ NVT_BIDS_POS
Definition: kb.h:69
kb_operations::kb_get_single
struct kb_item *(* kb_get_single)(kb_t, const char *, enum kb_item_type)
Definition: kb.h:133
kb_operations::kb_lnk_reset
int(* kb_lnk_reset)(kb_t)
Definition: kb.h:220
kb_operations::kb_direct_conn
kb_t(* kb_direct_conn)(const char *, const int)
Definition: kb.h:127
NVT_NAME_POS
@ NVT_NAME_POS
Definition: kb.h:74
kb_operations::kb_save
int(* kb_save)(kb_t)
Definition: kb.h:219
kb_operations::kb_get_kb_index
int(* kb_get_kb_index)(kb_t)
Definition: kb.h:222
kb_item::name
char name[0]
Definition: kb.h:97
kb_item::len
size_t len
Definition: kb.h:93
kb_operations::kb_add_int_unique
int(* kb_add_int_unique)(kb_t, const char *, int)
Definition: kb.h:201
kb_operations::kb_find
kb_t(* kb_find)(const char *, const char *)
Definition: kb.h:126
NVT_FILENAME_POS
@ NVT_FILENAME_POS
Definition: kb.h:60
kb_operations::kb_set_int
int(* kb_set_int)(kb_t, const char *, int)
Definition: kb.h:206
kb_operations::kb_flush
int(* kb_flush)(kb_t, const char *)
Definition: kb.h:221
NVT_TIMEOUT_POS
@ NVT_TIMEOUT_POS
Definition: kb.h:72
kb_operations::kb_del_items
int(* kb_del_items)(kb_t, const char *)
Definition: kb.h:216
kb_item
Knowledge base item (defined by name, type (int/char*) and value). Implemented as a singly linked lis...
Definition: kb.h:83
kb_operations::kb_get_nvt_all
nvti_t *(* kb_get_nvt_all)(kb_t, const char *)
Definition: kb.h:149
kb_operations::kb_add_int
int(* kb_add_int)(kb_t, const char *, int)
Definition: kb.h:196
NVT_REQUIRED_UDP_PORTS_POS
@ NVT_REQUIRED_UDP_PORTS_POS
Definition: kb.h:64
kb_operations::kb_get_str
char *(* kb_get_str)(kb_t, const char *)
Definition: kb.h:137
NVT_TIMESTAMP_POS
@ NVT_TIMESTAMP_POS
Definition: kb.h:75
kb_item::v_str
char * v_str
Definition: kb.h:89
NVT_OID_POS
@ NVT_OID_POS
Definition: kb.h:76
KB_TYPE_CNT
@ KB_TYPE_CNT
Definition: kb.h:52
kb_operations::kb_get_int
int(* kb_get_int)(kb_t, const char *)
Definition: kb.h:141
NVT_XREFS_POS
@ NVT_XREFS_POS
Definition: kb.h:70
kb_operations::kb_add_nvt
int(* kb_add_nvt)(kb_t, const nvti_t *, const char *)
Definition: kb.h:211
NVT_CATEGORY_POS
@ NVT_CATEGORY_POS
Definition: kb.h:71
NVT_DEPENDENCIES_POS
@ NVT_DEPENDENCIES_POS
Definition: kb.h:66
kb_operations::kb_pop_str
char *(* kb_pop_str)(kb_t, const char *)
Definition: kb.h:161
kb::kb_ops
const struct kb_operations * kb_ops
Definition: kb.h:107
KB_TYPE_STR
@ KB_TYPE_STR
Definition: kb.h:50
kb_item::next
struct kb_item * next
Definition: kb.h:94
kb_operations::kb_delete
int(* kb_delete)(kb_t)
Definition: kb.h:125
NVT_FAMILY_POS
@ NVT_FAMILY_POS
Definition: kb.h:73
kb_operations::kb_get_all
struct kb_item *(* kb_get_all)(kb_t, const char *)
Definition: kb.h:166
kb_operations::kb_get_nvt_oids
GSList *(* kb_get_nvt_oids)(kb_t)
Definition: kb.h:153
kb
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:105
kb_operations::kb_set_str
int(* kb_set_str)(kb_t, const char *, const char *, size_t)
Definition: kb.h:191
KBDefaultOperations
const struct kb_operations * KBDefaultOperations
Default KB operations. No selection mechanism is provided yet since there's only one implementation (...
Definition: kb.c:1614
NVT_CVES_POS
@ NVT_CVES_POS
Definition: kb.h:68
NVT_MANDATORY_KEYS_POS
@ NVT_MANDATORY_KEYS_POS
Definition: kb.h:62
kb_operations::kb_push_str
int(* kb_push_str)(kb_t, const char *, const char *)
Definition: kb.h:157
kb_operations::kb_add_str_unique
int(* kb_add_str_unique)(kb_t, const char *, const char *, size_t)
Definition: kb.h:186
kb_operations::kb_new
int(* kb_new)(kb_t *, const char *)
Definition: kb.h:124
NVT_REQUIRED_KEYS_POS
@ NVT_REQUIRED_KEYS_POS
Definition: kb.h:61
kb_operations::kb_get_pattern
struct kb_item *(* kb_get_pattern)(kb_t, const char *)
Definition: kb.h:171
kb_operations::kb_get_nvt
char *(* kb_get_nvt)(kb_t, const char *, enum kb_nvt_pos)
Definition: kb.h:145
NVT_TAGS_POS
@ NVT_TAGS_POS
Definition: kb.h:67
KB_TYPE_UNSPEC
@ KB_TYPE_UNSPEC
Definition: kb.h:48
KB_TYPE_INT
@ KB_TYPE_INT
Definition: kb.h:49
NVT_REQUIRED_PORTS_POS
@ NVT_REQUIRED_PORTS_POS
Definition: kb.h:65
kb_operations::kb_add_str
int(* kb_add_str)(kb_t, const char *, const char *, size_t)
Definition: kb.h:181
kb_item::type
enum kb_item_type type
Definition: kb.h:85
kb_operations::kb_count
size_t(* kb_count)(kb_t, const char *)
Definition: kb.h:176