Greenbone Vulnerability Management Libraries  10.0.1
nvticache.h File Reference

Protos and data structures for NVT Information Cache. More...

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

Go to the source code of this file.

Macros

#define NVTICACHE_STR   "nvticache10"
 

Functions

int nvticache_init (const char *, const char *)
 Initializes the nvti cache. More...
 
void nvticache_reset ()
 Reset connection to KB. To be called after a fork(). More...
 
kb_t nvticache_get_kb ()
 Return the nvticache kb. More...
 
void nvticache_save ()
 Save the nvticache to disk. More...
 
int nvticache_initialized (void)
 Return whether the nvt cache is initialized. More...
 
int nvticache_check (const gchar *)
 Check if the nvt for the given filename exists in cache. More...
 
int nvticache_add (const nvti_t *, const char *)
 Add a NVT Information to the cache. More...
 
char * nvticache_get_src (const char *)
 Get the full source filename of an OID. More...
 
char * nvticache_get_oid (const char *)
 Get the OID from a plugin filename. More...
 
char * nvticache_get_name (const char *)
 Get the name from a plugin OID. More...
 
char * nvticache_get_tags (const char *)
 Get the tags from a plugin OID. More...
 
GSList * nvticache_get_prefs (const char *)
 Get the prefs from a plugin OID. More...
 
char * nvticache_get_cves (const char *)
 Get the cves from a plugin OID. More...
 
char * nvticache_get_bids (const char *)
 Get the bids from a plugin OID. More...
 
char * nvticache_get_xrefs (const char *)
 Get the xrefs from a plugin OID. More...
 
char * nvticache_get_family (const char *)
 Get the family from a plugin OID. More...
 
char * nvticache_get_filename (const char *)
 Get the filename from a plugin OID. More...
 
char * nvticache_get_required_keys (const char *)
 Get the Required Keys from a plugin OID. More...
 
char * nvticache_get_mandatory_keys (const char *)
 Get the Mandatory Keys from a plugin OID. More...
 
char * nvticache_get_excluded_keys (const char *)
 Get the Excluded Keys from a plugin OID. More...
 
char * nvticache_get_required_ports (const char *)
 Get the Required ports from a plugin OID. More...
 
char * nvticache_get_required_udp_ports (const char *)
 Get the Required udp ports from a plugin OID. More...
 
int nvticache_get_category (const char *)
 Get the Category from a plugin OID. More...
 
int nvticache_get_timeout (const char *)
 Get the Timeout from a plugin OID. More...
 
char * nvticache_get_dependencies (const char *)
 Get the Dependencies from a plugin OID. More...
 
nvti_t * nvticache_get_nvt (const char *)
 Get the nvti from a plugin OID. More...
 
GSList * nvticache_get_oids (void)
 Get the list of nvti OIDs. More...
 
size_t nvticache_count (void)
 Get the number of nvt's in the cache. More...
 
void nvticache_delete (const char *)
 Delete NVT from the cache. More...
 
char * nvticache_feed_version (void)
 Get the NVT feed version. More...
 
int nvticache_check_feed (void)
 Check if the plugins feed was newer than cached feed. More...
 

Detailed Description

Protos and data structures for NVT Information Cache.

This file contains the protos for nvticache.c

Definition in file nvticache.h.

Macro Definition Documentation

◆ NVTICACHE_STR

#define NVTICACHE_STR   "nvticache10"

Definition at line 36 of file nvticache.h.

Function Documentation

◆ nvticache_add()

int nvticache_add ( const nvti_t *  nvti,
const char *  filename 
)

Add a NVT Information to the cache.

Parameters
nvtiThe NVT Information to add
filenameThe name of the original NVT without the path to the base location of NVTs (e.g. "scriptname1.nasl" or even "subdir1/subdir2/scriptname2.nasl" )
Returns
0 in case of success, anything else indicates an error.

Definition at line 208 of file nvticache.c.

209 {
210  char *oid, *dummy;
211 
212  assert (cache_kb);
213  /* Check for duplicate OID. */
214  oid = nvti_oid (nvti);
215  dummy = nvticache_get_filename (oid);
216  if (dummy && strcmp (filename, dummy))
217  {
218  struct stat src_stat;
219  char *src_file = g_build_filename (src_path, dummy, NULL);
220 
221  /* If .nasl file was duplicated, not moved. */
222  if (src_file && stat (src_file, &src_stat) >= 0)
223  g_warning ("NVT %s with duplicate OID %s will be replaced with %s",
224  src_file, oid, filename);
225  g_free (src_file);
226  }
227  if (dummy)
228  nvticache_delete (oid);
229 
230  g_free (dummy);
231 
232  if (kb_nvt_add (cache_kb, nvti, filename))
233  goto kb_fail;
234  cache_saved = 0;
235 
236  return 0;
237 kb_fail:
238  return -1;
239 }
char * nvticache_get_filename(const char *oid)
Get the filename from a plugin OID.
Definition: nvticache.c:286
The structure of a information record that corresponds to a NVT.
Definition: nvti.h:62
int cache_saved
Definition: nvticache.c:51
void nvticache_delete(const char *oid)
Delete NVT from the cache.
Definition: nvticache.c:583
static int kb_nvt_add(kb_t kb, const nvti_t *nvt, const char *filename)
Insert a new nvt.
Definition: kb.h:548
kb_t cache_kb
Definition: nvticache.c:50
char * src_path
Definition: nvticache.c:49
gchar * nvti_oid(const nvti_t *n)
Get the OID string.
Definition: nvti.c:219

References cache_kb, cache_saved, kb_nvt_add(), nvti_oid(), nvticache_delete(), nvticache_get_filename(), and src_path.

Here is the call graph for this function:

◆ nvticache_check()

int nvticache_check ( const gchar *  filename)

Check if the nvt for the given filename exists in cache.

Parameters
filenameThe name of the original NVT without the path to the base location of NVTs (e.g. "scriptname1.nasl" or even "subdir1/subdir2/scriptname2.nasl" )
Returns
1 if nvt is in cache and up to date, 0 otherwise.

Definition at line 115 of file nvticache.c.

116 {
117  assert (cache_kb);
118  char *src_file, *time_s;
119  struct stat src_stat;
120  int ret = 0;
121 
122  src_file = g_build_filename (src_path, filename, NULL);
123  time_s = kb_nvt_get (cache_kb, filename, NVT_TIMESTAMP_POS);
124  if (time_s && src_file && stat (src_file, &src_stat) >= 0
125  && atoi (time_s) > src_stat.st_mtime)
126  ret = 1;
127  g_free (time_s);
128  g_free (src_file);
129  return ret;
130 }
kb_t cache_kb
Definition: nvticache.c:50
char * src_path
Definition: nvticache.c:49
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:565

References cache_kb, kb_nvt_get(), NVT_TIMESTAMP_POS, and src_path.

Here is the call graph for this function:

◆ nvticache_check_feed()

int nvticache_check_feed ( void  )

Check if the plugins feed was newer than cached feed.

Returns
1 if new feed, 0 if matching feeds or error.

Definition at line 622 of file nvticache.c.

623 {
624  char *cached, *current;
625  int ret;
626 
627  if (!(current = nvt_feed_version ()))
628  return 0;
630  ret = strcmp (cached, current);
631  g_free (cached);
632  g_free (current);
633  return ret;
634 }
kb_t cache_kb
Definition: nvticache.c:50
static char * kb_item_get_str(kb_t kb, const char *name)
Get a single KB string item.
Definition: kb.h:323
#define NVTICACHE_STR
Definition: nvticache.h:36
static char * nvt_feed_version()
Determine the version of the NVT feed.
Definition: nvticache.c:148

References cache_kb, kb_item_get_str(), nvt_feed_version(), and NVTICACHE_STR.

Here is the call graph for this function:

◆ nvticache_count()

size_t nvticache_count ( void  )

Get the number of nvt's in the cache.

Returns
Number of nvt's.

Definition at line 571 of file nvticache.c.

572 {
573  assert (cache_kb);
574 
575  return kb_item_count (cache_kb, "nvt:*");
576 }
kb_t cache_kb
Definition: nvticache.c:50
static size_t kb_item_count(kb_t kb, const char *pattern)
Count all items stored under a given pattern.
Definition: kb.h:426

References cache_kb, and kb_item_count().

Here is the call graph for this function:

◆ nvticache_delete()

void nvticache_delete ( const char *  oid)

Delete NVT from the cache.

Parameters
[in]oidOID to match.

Definition at line 583 of file nvticache.c.

584 {
585  char pattern[4096];
586  char *filename;
587 
588  assert (cache_kb);
589  assert (oid);
590 
591  filename = nvticache_get_filename (oid);
592  g_snprintf (pattern, sizeof (pattern), "oid:%s:prefs", oid);
593  kb_del_items (cache_kb, pattern);
594  g_snprintf (pattern, sizeof (pattern), "nvt:%s", oid);
595  kb_del_items (cache_kb, pattern);
596 
597  if (filename)
598  {
599  g_snprintf (pattern, sizeof (pattern), "filename:%s", filename);
600  kb_del_items (cache_kb, pattern);
601  }
602  g_free (filename);
603 }
char * nvticache_get_filename(const char *oid)
Get the filename from a plugin OID.
Definition: nvticache.c:286
static int kb_del_items(kb_t kb, const char *name)
Delete all entries under a given name.
Definition: kb.h:612
kb_t cache_kb
Definition: nvticache.c:50

References cache_kb, kb_del_items(), and nvticache_get_filename().

Referenced by nvticache_add().

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

◆ nvticache_feed_version()

char* nvticache_feed_version ( void  )

Get the NVT feed version.

Returns
Feed version.

Definition at line 611 of file nvticache.c.

612 {
614 }
kb_t cache_kb
Definition: nvticache.c:50
static char * kb_item_get_str(kb_t kb, const char *name)
Get a single KB string item.
Definition: kb.h:323
#define NVTICACHE_STR
Definition: nvticache.h:36

References cache_kb, kb_item_get_str(), and NVTICACHE_STR.

Here is the call graph for this function:

◆ nvticache_get_bids()

char* nvticache_get_bids ( const char *  oid)

Get the bids from a plugin OID.

Parameters
[in]oidOID to match.
Returns
BIDs matching OID, NULL otherwise.

Definition at line 452 of file nvticache.c.

453 {
454  assert (cache_kb);
455  return kb_nvt_get (cache_kb, oid, NVT_BIDS_POS);
456 }
kb_t cache_kb
Definition: nvticache.c:50
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:565

References cache_kb, kb_nvt_get(), and NVT_BIDS_POS.

Here is the call graph for this function:

◆ nvticache_get_category()

int nvticache_get_category ( const char *  oid)

Get the Category from a plugin OID.

Parameters
[in]oidOID to match.
Returns
Category matching OID, -1 otherwise.

Definition at line 384 of file nvticache.c.

385 {
386  int category;
387  char *category_s;
388 
389  assert (cache_kb);
390  category_s = kb_nvt_get (cache_kb, oid, NVT_CATEGORY_POS);
391  category = atoi (category_s);
392  g_free (category_s);
393  return category;
394 }
kb_t cache_kb
Definition: nvticache.c:50
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:565

References cache_kb, kb_nvt_get(), and NVT_CATEGORY_POS.

Here is the call graph for this function:

◆ nvticache_get_cves()

char* nvticache_get_cves ( const char *  oid)

Get the cves from a plugin OID.

Parameters
[in]oidOID to match.
Returns
CVEs matching OID, NULL otherwise.

Definition at line 438 of file nvticache.c.

439 {
440  assert (cache_kb);
441  return kb_nvt_get (cache_kb, oid, NVT_CVES_POS);
442 }
kb_t cache_kb
Definition: nvticache.c:50
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:565

References cache_kb, kb_nvt_get(), and NVT_CVES_POS.

Here is the call graph for this function:

◆ nvticache_get_dependencies()

char* nvticache_get_dependencies ( const char *  oid)

Get the Dependencies from a plugin OID.

Parameters
[in]oidOID to match.
Returns
Dependencies matching OID, NULL otherwise.

Definition at line 370 of file nvticache.c.

371 {
372  assert (cache_kb);
374 }
kb_t cache_kb
Definition: nvticache.c:50
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:565

References cache_kb, kb_nvt_get(), and NVT_DEPENDENCIES_POS.

Here is the call graph for this function:

◆ nvticache_get_excluded_keys()

char* nvticache_get_excluded_keys ( const char *  oid)

Get the Excluded Keys from a plugin OID.

Parameters
[in]oidOID to match.
Returns
Excluded Keys matching OID, NULL otherwise.

Definition at line 328 of file nvticache.c.

329 {
330  assert (cache_kb);
332 }
kb_t cache_kb
Definition: nvticache.c:50
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:565

References cache_kb, kb_nvt_get(), and NVT_EXCLUDED_KEYS_POS.

Here is the call graph for this function:

◆ nvticache_get_family()

char* nvticache_get_family ( const char *  oid)

Get the family from a plugin OID.

Parameters
[in]oidOID to match.
Returns
Family matching OID, NULL otherwise.

Definition at line 480 of file nvticache.c.

481 {
482  assert (cache_kb);
483  return kb_nvt_get (cache_kb, oid, NVT_FAMILY_POS);
484 }
kb_t cache_kb
Definition: nvticache.c:50
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:565

References cache_kb, kb_nvt_get(), and NVT_FAMILY_POS.

Here is the call graph for this function:

◆ nvticache_get_filename()

char* nvticache_get_filename ( const char *  oid)

Get the filename from a plugin OID.

Parameters
[in]oidOID to match.
Returns
Filanem matching OID, NULL otherwise.

Definition at line 286 of file nvticache.c.

287 {
288  assert (cache_kb);
289  return kb_nvt_get (cache_kb, oid, NVT_FILENAME_POS);
290 }
kb_t cache_kb
Definition: nvticache.c:50
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:565

References cache_kb, kb_nvt_get(), and NVT_FILENAME_POS.

Referenced by nvticache_add(), and nvticache_delete().

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

◆ nvticache_get_kb()

kb_t nvticache_get_kb ( void  )

Return the nvticache kb.

Returns
Cache kb.

Definition at line 98 of file nvticache.c.

99 {
100  assert (cache_kb);
101  return cache_kb;
102 }
kb_t cache_kb
Definition: nvticache.c:50

References cache_kb.

◆ nvticache_get_mandatory_keys()

char* nvticache_get_mandatory_keys ( const char *  oid)

Get the Mandatory Keys from a plugin OID.

Parameters
[in]oidOID to match.
Returns
Mandatory Keys matching OID, NULL otherwise.

Definition at line 314 of file nvticache.c.

315 {
316  assert (cache_kb);
318 }
kb_t cache_kb
Definition: nvticache.c:50
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:565

References cache_kb, kb_nvt_get(), and NVT_MANDATORY_KEYS_POS.

Here is the call graph for this function:

◆ nvticache_get_name()

char* nvticache_get_name ( const char *  oid)

Get the name from a plugin OID.

Parameters
[in]oidOID to match.
Returns
Name matching OID, NULL otherwise.

Definition at line 424 of file nvticache.c.

425 {
426  assert (cache_kb);
427  return kb_nvt_get (cache_kb, oid, NVT_NAME_POS);
428 }
kb_t cache_kb
Definition: nvticache.c:50
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:565

References cache_kb, kb_nvt_get(), and NVT_NAME_POS.

Here is the call graph for this function:

◆ nvticache_get_nvt()

nvti_t* nvticache_get_nvt ( const char *  oid)

Get the nvti from a plugin OID.

Parameters
[in]oidOID to match.
Returns
Full nvti matching OID, NULL otherwise.

Definition at line 508 of file nvticache.c.

509 {
510  assert (cache_kb);
511  return kb_nvt_get_all (cache_kb, oid);
512 }
static nvti_t * kb_nvt_get_all(kb_t kb, const char *oid)
Get a full NVT.
Definition: kb.h:581
kb_t cache_kb
Definition: nvticache.c:50

References cache_kb, and kb_nvt_get_all().

Here is the call graph for this function:

◆ nvticache_get_oid()

char* nvticache_get_oid ( const char *  filename)

Get the OID from a plugin filename.

Parameters
filenameFilename to lookup.
Returns
OID matching filename if found, NULL otherwise.

Definition at line 271 of file nvticache.c.

272 {
273  assert (cache_kb);
274 
275  return kb_nvt_get (cache_kb, filename, NVT_OID_POS);
276 }
kb_t cache_kb
Definition: nvticache.c:50
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:565
Definition: kb.h:72

References cache_kb, kb_nvt_get(), and NVT_OID_POS.

Here is the call graph for this function:

◆ nvticache_get_oids()

GSList* nvticache_get_oids ( void  )

Get the list of nvti OIDs.

Returns
OIDs list.

Definition at line 558 of file nvticache.c.

559 {
560  assert (cache_kb);
561 
562  return kb_nvt_get_oids (cache_kb);
563 }
kb_t cache_kb
Definition: nvticache.c:50
static GSList * kb_nvt_get_oids(kb_t kb)
Get list of NVT OIDs.
Definition: kb.h:596

References cache_kb, and kb_nvt_get_oids().

Here is the call graph for this function:

◆ nvticache_get_prefs()

GSList* nvticache_get_prefs ( const char *  oid)

Get the prefs from a plugin OID.

Parameters
[in]oidOID to match.
Returns
Prefs matching OID, NULL otherwise.

Definition at line 522 of file nvticache.c.

523 {
524  char pattern[4096];
525  struct kb_item *prefs, *element;
526  GSList *list = NULL;
527 
528  assert (cache_kb);
529 
530  g_snprintf (pattern, sizeof (pattern), "oid:%s:prefs", oid);
531  prefs = element = kb_item_get_all (cache_kb, pattern);
532  while (element)
533  {
534  nvtpref_t *np;
535  char **array = g_strsplit (element->v_str, "|||", -1);
536 
537  assert (array[2]);
538  assert (!array[3]);
539  np = g_malloc0 (sizeof (nvtpref_t));
540  np->name = array[0];
541  np->type = array[1];
542  np->dflt = array[2];
543  g_free (array);
544  list = g_slist_append (list, np);
545  element = element->next;
546  }
547  kb_item_free (prefs);
548 
549  return list;
550 }
void kb_item_free(struct kb_item *item)
Release a KB item (or a list).
Definition: kb.c:599
gchar * name
Name of the preference.
Definition: nvti.h:41
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
static struct kb_item * kb_item_get_all(kb_t kb, const char *name)
Get all items stored under a given name.
Definition: kb.h:357
gchar * type
Preference type.
Definition: nvti.h:40
kb_t cache_kb
Definition: nvticache.c:50
gchar * dflt
Default value of the preference.
Definition: nvti.h:42
The structure for a preference of a NVT.
Definition: nvti.h:38
char * v_str
Definition: kb.h:85

References cache_kb, nvtpref::dflt, kb_item_free(), kb_item_get_all(), nvtpref::name, kb_item::next, nvtpref::type, and kb_item::v_str.

Here is the call graph for this function:

◆ nvticache_get_required_keys()

char* nvticache_get_required_keys ( const char *  oid)

Get the Required Keys from a plugin OID.

Parameters
[in]oidOID to match.
Returns
Required Keys matching OID, NULL otherwise.

Definition at line 300 of file nvticache.c.

301 {
302  assert (cache_kb);
304 }
kb_t cache_kb
Definition: nvticache.c:50
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:565

References cache_kb, kb_nvt_get(), and NVT_REQUIRED_KEYS_POS.

Here is the call graph for this function:

◆ nvticache_get_required_ports()

char* nvticache_get_required_ports ( const char *  oid)

Get the Required ports from a plugin OID.

Parameters
[in]oidOID to match.
Returns
Required ports matching OID, NULL otherwise.

Definition at line 356 of file nvticache.c.

357 {
358  assert (cache_kb);
360 }
kb_t cache_kb
Definition: nvticache.c:50
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:565

References cache_kb, kb_nvt_get(), and NVT_REQUIRED_PORTS_POS.

Here is the call graph for this function:

◆ nvticache_get_required_udp_ports()

char* nvticache_get_required_udp_ports ( const char *  oid)

Get the Required udp ports from a plugin OID.

Parameters
[in]oidOID to match.
Returns
Required udp ports matching OID, NULL otherwise.

Definition at line 342 of file nvticache.c.

343 {
344  assert (cache_kb);
346 }
kb_t cache_kb
Definition: nvticache.c:50
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:565

References cache_kb, kb_nvt_get(), and NVT_REQUIRED_UDP_PORTS_POS.

Here is the call graph for this function:

◆ nvticache_get_src()

char* nvticache_get_src ( const char *  oid)

Get the full source filename of an OID.

Parameters
oidThe OID to look up.
Returns
Filename with full path matching OID if found, NULL otherwise.

Definition at line 249 of file nvticache.c.

250 {
251  char *filename, *src;
252 
253  assert (cache_kb);
254 
255  filename = kb_nvt_get (cache_kb, oid, NVT_FILENAME_POS);
256  if (!filename)
257  return NULL;
258  src = g_build_filename (src_path, filename, NULL);
259  g_free (filename);
260  return src;
261 }
kb_t cache_kb
Definition: nvticache.c:50
char * src_path
Definition: nvticache.c:49
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:565

References cache_kb, kb_nvt_get(), NVT_FILENAME_POS, and src_path.

Here is the call graph for this function:

◆ nvticache_get_tags()

char* nvticache_get_tags ( const char *  oid)

Get the tags from a plugin OID.

Parameters
[in]oidOID to match.
Returns
Tags matching OID, NULL otherwise.

Definition at line 494 of file nvticache.c.

495 {
496  assert (cache_kb);
497  return kb_nvt_get (cache_kb, oid, NVT_TAGS_POS);
498 }
kb_t cache_kb
Definition: nvticache.c:50
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:565

References cache_kb, kb_nvt_get(), and NVT_TAGS_POS.

Here is the call graph for this function:

◆ nvticache_get_timeout()

int nvticache_get_timeout ( const char *  oid)

Get the Timeout from a plugin OID.

Parameters
[in]oidOID to match.
Returns
Timeout matching OID, -1 otherwise.

Definition at line 404 of file nvticache.c.

405 {
406  int timeout;
407  char *timeout_s;
408 
409  assert (cache_kb);
410  timeout_s = kb_nvt_get (cache_kb, oid, NVT_TIMEOUT_POS);
411  timeout = atoi (timeout_s);
412  g_free (timeout_s);
413  return timeout;
414 }
kb_t cache_kb
Definition: nvticache.c:50
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:565

References cache_kb, kb_nvt_get(), and NVT_TIMEOUT_POS.

Here is the call graph for this function:

◆ nvticache_get_xrefs()

char* nvticache_get_xrefs ( const char *  oid)

Get the xrefs from a plugin OID.

Parameters
[in]oidOID to match.
Returns
XREFs matching OID, NULL otherwise.

Definition at line 466 of file nvticache.c.

467 {
468  assert (cache_kb);
469  return kb_nvt_get (cache_kb, oid, NVT_XREFS_POS);
470 }
kb_t cache_kb
Definition: nvticache.c:50
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:565

References cache_kb, kb_nvt_get(), and NVT_XREFS_POS.

Here is the call graph for this function:

◆ nvticache_init()

int nvticache_init ( const char *  src,
const char *  kb_path 
)

Initializes the nvti cache.

Parameters
srcThe directory that contains the nvt files.
kb_pathPath to kb socket.
Returns
0 in case of success, anything else indicates an error.

Definition at line 73 of file nvticache.c.

74 {
75  assert (src);
76 
77  if (src_path)
78  g_free (src_path);
79  src_path = g_strdup (src);
80  if (cache_kb)
82  cache_kb = kb_find (kb_path, NVTICACHE_STR);
83  if (cache_kb)
84  return 0;
85 
86  if (kb_new (&cache_kb, kb_path)
88  return -1;
89  return 0;
90 }
static int kb_new(kb_t *kb, const char *kb_path)
Initialize a new Knowledge Base object.
Definition: kb.h:241
kb_t cache_kb
Definition: nvticache.c:50
#define NVTICACHE_STR
Definition: nvticache.h:36
char * src_path
Definition: nvticache.c:49
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 b...
Definition: kb.h:647
static kb_t kb_find(const char *kb_path, const char *key)
Find an existing Knowledge Base object with key.
Definition: kb.h:274
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.
Definition: kb.h:480

References cache_kb, kb_find(), kb_item_set_str(), kb_lnk_reset(), kb_new(), NVTICACHE_STR, and src_path.

Here is the call graph for this function:

◆ nvticache_initialized()

int nvticache_initialized ( void  )

Return whether the nvt cache is initialized.

Returns
1 if cache is initialized, 0 otherwise.

Definition at line 59 of file nvticache.c.

60 {
61  return !!cache_kb;
62 }
kb_t cache_kb
Definition: nvticache.c:50

References cache_kb.

◆ nvticache_reset()

void nvticache_reset ( )

Reset connection to KB. To be called after a fork().

Definition at line 136 of file nvticache.c.

137 {
138  if (cache_kb)
140 }
kb_t cache_kb
Definition: nvticache.c:50
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 b...
Definition: kb.h:647

References cache_kb, and kb_lnk_reset().

Here is the call graph for this function:

◆ nvticache_save()

void nvticache_save ( )

Save the nvticache to disk.

Definition at line 182 of file nvticache.c.

183 {
184  char *feed_version;
185  if (cache_kb && !cache_saved)
186  {
187  kb_save (cache_kb);
188  cache_saved = 1;
189  }
190  if ((feed_version = nvt_feed_version ()))
191  kb_item_set_str (cache_kb, NVTICACHE_STR, feed_version, 0);
192  g_free (feed_version);
193 }
int cache_saved
Definition: nvticache.c:51
kb_t cache_kb
Definition: nvticache.c:50
#define NVTICACHE_STR
Definition: nvticache.h:36
static int kb_save(kb_t kb)
Save all the KB's content.
Definition: kb.h:627
static char * nvt_feed_version()
Determine the version of the NVT feed.
Definition: nvticache.c:148
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.
Definition: kb.h:480

References cache_kb, cache_saved, kb_item_set_str(), kb_save(), nvt_feed_version(), and NVTICACHE_STR.

Here is the call graph for this function: