Greenbone Vulnerability Management Libraries  10.0.0
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_tnvticache_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 204 of file nvticache.c.

205 {
206  char *oid, *dummy;
207 
208  assert (cache_kb);
209  /* Check for duplicate OID. */
210  oid = nvti_oid (nvti);
211  dummy = nvticache_get_filename (oid);
212  if (dummy && strcmp (filename, dummy))
213  {
214  struct stat src_stat;
215  char *src_file = g_build_filename (src_path, dummy, NULL);
216 
217  /* If .nasl file was duplicated, not moved. */
218  if (src_file && stat (src_file, &src_stat) >= 0)
219  g_warning ("NVT %s with duplicate OID %s will be replaced with %s",
220  src_file, oid, filename);
221  g_free (src_file);
222  }
223  if (dummy)
224  nvticache_delete (oid);
225 
226  g_free (dummy);
227 
228  if (kb_nvt_add (cache_kb, nvti, filename))
229  goto kb_fail;
230  cache_saved = 0;
231 
232  return 0;
233 kb_fail:
234  return -1;
235 }
char * nvticache_get_filename(const char *oid)
Get the filename from a plugin OID.
Definition: nvticache.c:282
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:579
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 618 of file nvticache.c.

619 {
620  char *cached, *current;
621  int ret;
622 
623  if (!(current = nvt_feed_version ()))
624  return 0;
626  ret = strcmp (cached, current);
627  g_free (cached);
628  g_free (current);
629  return ret;
630 }
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 567 of file nvticache.c.

568 {
569  assert (cache_kb);
570 
571  return kb_item_count (cache_kb, "nvt:*");
572 }
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 579 of file nvticache.c.

580 {
581  char pattern[4096];
582  char *filename;
583 
584  assert (cache_kb);
585  assert (oid);
586 
587  filename = nvticache_get_filename (oid);
588  g_snprintf (pattern, sizeof (pattern), "prefs:%s", oid);
589  kb_del_items (cache_kb, pattern);
590  g_snprintf (pattern, sizeof (pattern), "nvt:%s", oid);
591  kb_del_items (cache_kb, pattern);
592 
593  if (filename)
594  {
595  g_snprintf (pattern, sizeof (pattern), "filename:%s", filename);
596  kb_del_items (cache_kb, pattern);
597  }
598  g_free (filename);
599 }
char * nvticache_get_filename(const char *oid)
Get the filename from a plugin OID.
Definition: nvticache.c:282
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 607 of file nvticache.c.

608 {
610 }
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 448 of file nvticache.c.

449 {
450  assert (cache_kb);
451  return kb_nvt_get (cache_kb, oid, NVT_BIDS_POS);
452 }
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 380 of file nvticache.c.

381 {
382  int category;
383  char *category_s;
384 
385  assert (cache_kb);
386  category_s = kb_nvt_get (cache_kb, oid, NVT_CATEGORY_POS);
387  category = atoi (category_s);
388  g_free (category_s);
389  return category;
390 }
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 434 of file nvticache.c.

435 {
436  assert (cache_kb);
437  return kb_nvt_get (cache_kb, oid, NVT_CVES_POS);
438 }
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 366 of file nvticache.c.

367 {
368  assert (cache_kb);
370 }
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 324 of file nvticache.c.

325 {
326  assert (cache_kb);
328 }
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 476 of file nvticache.c.

477 {
478  assert (cache_kb);
479  return kb_nvt_get (cache_kb, oid, NVT_FAMILY_POS);
480 }
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 282 of file nvticache.c.

283 {
284  assert (cache_kb);
285  return kb_nvt_get (cache_kb, oid, NVT_FILENAME_POS);
286 }
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 310 of file nvticache.c.

311 {
312  assert (cache_kb);
314 }
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 420 of file nvticache.c.

421 {
422  assert (cache_kb);
423  return kb_nvt_get (cache_kb, oid, NVT_NAME_POS);
424 }
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 504 of file nvticache.c.

505 {
506  assert (cache_kb);
507  return kb_nvt_get_all (cache_kb, oid);
508 }
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 267 of file nvticache.c.

268 {
269  assert (cache_kb);
270 
271  return kb_nvt_get (cache_kb, filename, NVT_OID_POS);
272 }
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 554 of file nvticache.c.

555 {
556  assert (cache_kb);
557 
558  return kb_nvt_get_oids (cache_kb);
559 }
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 518 of file nvticache.c.

519 {
520  char pattern[4096];
521  struct kb_item *prefs, *element;
522  GSList *list = NULL;
523 
524  assert (cache_kb);
525 
526  g_snprintf (pattern, sizeof (pattern), "oid:%s:prefs", oid);
527  prefs = element = kb_item_get_all (cache_kb, pattern);
528  while (element)
529  {
530  nvtpref_t *np;
531  char **array = g_strsplit (element->v_str, "|||", -1);
532 
533  assert (array[2]);
534  assert (!array[3]);
535  np = g_malloc0 (sizeof (nvtpref_t));
536  np->name = array[0];
537  np->type = array[1];
538  np->dflt = array[2];
539  g_free (array);
540  list = g_slist_append (list, np);
541  element = element->next;
542  }
543  kb_item_free (prefs);
544 
545  return list;
546 }
void kb_item_free(struct kb_item *item)
Release a KB item (or a list).
Definition: kb.c:608
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 296 of file nvticache.c.

297 {
298  assert (cache_kb);
300 }
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 352 of file nvticache.c.

353 {
354  assert (cache_kb);
356 }
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 338 of file nvticache.c.

339 {
340  assert (cache_kb);
342 }
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 245 of file nvticache.c.

246 {
247  char *filename, *src;
248 
249  assert (cache_kb);
250 
251  filename = kb_nvt_get (cache_kb, oid, NVT_FILENAME_POS);
252  if (!filename)
253  return NULL;
254  src = g_build_filename (src_path, filename, NULL);
255  g_free (filename);
256  return src;
257 }
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 490 of file nvticache.c.

491 {
492  assert (cache_kb);
493  return kb_nvt_get (cache_kb, oid, NVT_TAGS_POS);
494 }
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 400 of file nvticache.c.

401 {
402  int timeout;
403  char *timeout_s;
404 
405  assert (cache_kb);
406  timeout_s = kb_nvt_get (cache_kb, oid, NVT_TIMEOUT_POS);
407  timeout = atoi (timeout_s);
408  g_free (timeout_s);
409  return timeout;
410 }
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 462 of file nvticache.c.

463 {
464  assert (cache_kb);
465  return kb_nvt_get (cache_kb, oid, NVT_XREFS_POS);
466 }
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 178 of file nvticache.c.

179 {
180  char *feed_version;
181  if (cache_kb && !cache_saved)
182  {
183  kb_save (cache_kb);
184  cache_saved = 1;
185  }
186  if ((feed_version = nvt_feed_version ()))
187  kb_item_set_str (cache_kb, NVTICACHE_STR, feed_version, 0);
188  g_free (feed_version);
189 }
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: