Greenbone Vulnerability Management Libraries  11.0.1
nvticache.c File Reference

Implementation of API to handle NVT Info Cache. More...

#include "nvticache.h"
#include "kb.h"
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
Include dependency graph for nvticache.c:

Go to the source code of this file.

Macros

#define G_LOG_DOMAIN   "lib nvticache"
 GLib log domain. More...
 

Functions

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

Variables

char * src_path = NULL
 
kb_t cache_kb = NULL
 
int cache_saved = 1
 

Detailed Description

Implementation of API to handle NVT Info Cache.

This file contains all methods to handle NVT Information Cache (nvticache_t).

The module consequently uses glib datatypes and api for memory management etc.

Definition in file nvticache.c.

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "lib nvticache"

GLib log domain.

Definition at line 47 of file nvticache.c.

Function Documentation

◆ nvt_feed_version()

static char* nvt_feed_version ( )
static

Determine the version of the NVT feed.

Returns
Feed version string if success, NULL otherwise.

Definition at line 148 of file nvticache.c.

149 {
150  char filename[2048], *fcontent = NULL, *plugin_set;
151  GError *error = NULL;
152  static int msg_shown = 0;
153 
154  g_snprintf (filename, sizeof (filename), "%s/plugin_feed_info.inc", src_path);
155  if (!g_file_get_contents (filename, &fcontent, NULL, &error))
156  {
157  if (error && msg_shown == 0)
158  {
159  g_warning ("nvt_feed_version: %s", error->message);
160  msg_shown = 1;
161  }
162  g_error_free (error);
163  return NULL;
164  }
165  plugin_set = g_strrstr (fcontent, "PLUGIN_SET = ");
166  if (!plugin_set)
167  {
168  g_warning ("nvt_feed_version: Erroneous %s format", filename);
169  g_free (fcontent);
170  return NULL;
171  }
172  msg_shown = 0;
173  plugin_set = g_strndup (plugin_set + 14, 12);
174  g_free (fcontent);
175  return plugin_set;
176 }

References src_path.

Referenced by nvticache_check_feed(), and nvticache_save().

Here is the caller graph for this function:

◆ 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 215 of file nvticache.c.

216 {
217  char *oid, *dummy;
218 
219  assert (cache_kb);
220  /* Check for duplicate OID. */
221  oid = nvti_oid (nvti);
222  dummy = nvticache_get_filename (oid);
223  if (dummy && strcmp (filename, dummy))
224  {
225  struct stat src_stat;
226  char *src_file = g_build_filename (src_path, dummy, NULL);
227 
228  /* If .nasl file was duplicated, not moved. */
229  if (src_file && stat (src_file, &src_stat) >= 0)
230  g_warning ("NVT %s with duplicate OID %s will be replaced with %s",
231  src_file, oid, filename);
232  g_free (src_file);
233  }
234  if (dummy)
235  nvticache_delete (oid);
236 
237  g_free (dummy);
238 
239  if (kb_nvt_add (cache_kb, nvti, filename))
240  goto kb_fail;
241  cache_saved = 0;
242 
243  return 0;
244 kb_fail:
245  return -1;
246 }

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 }

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 627 of file nvticache.c.

628 {
629  char *cached, *current;
630  int ret;
631 
632  if (!(current = nvt_feed_version ()))
633  return 0;
635  ret = strcmp (cached, current);
636  g_free (cached);
637  g_free (current);
638  return ret;
639 }

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 ( )

Get the number of nvt's in the cache.

Returns
Number of nvt's.

Definition at line 575 of file nvticache.c.

576 {
577  assert (cache_kb);
578 
579  return kb_item_count (cache_kb, "nvt:*");
580 }

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 588 of file nvticache.c.

589 {
590  char pattern[4096];
591  char *filename;
592 
593  assert (cache_kb);
594  assert (oid);
595 
596  filename = nvticache_get_filename (oid);
597  g_snprintf (pattern, sizeof (pattern), "oid:%s:prefs", oid);
598  kb_del_items (cache_kb, pattern);
599  g_snprintf (pattern, sizeof (pattern), "nvt:%s", oid);
600  kb_del_items (cache_kb, pattern);
601 
602  if (filename)
603  {
604  g_snprintf (pattern, sizeof (pattern), "filename:%s", filename);
605  kb_del_items (cache_kb, pattern);
606  }
607  g_free (filename);
608 }

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 616 of file nvticache.c.

617 {
619 }

References cache_kb, kb_item_get_str(), and NVTICACHE_STR.

Referenced by nvticache_save().

Here is the call graph for this function:
Here is the caller 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 459 of file nvticache.c.

460 {
461  assert (cache_kb);
462  return kb_nvt_get (cache_kb, oid, NVT_BIDS_POS);
463 }

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 391 of file nvticache.c.

392 {
393  int category;
394  char *category_s;
395 
396  assert (cache_kb);
397  category_s = kb_nvt_get (cache_kb, oid, NVT_CATEGORY_POS);
398  category = atoi (category_s);
399  g_free (category_s);
400  return category;
401 }

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 445 of file nvticache.c.

446 {
447  assert (cache_kb);
448  return kb_nvt_get (cache_kb, oid, NVT_CVES_POS);
449 }

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 377 of file nvticache.c.

378 {
379  assert (cache_kb);
381 }

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 335 of file nvticache.c.

336 {
337  assert (cache_kb);
339 }

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 487 of file nvticache.c.

488 {
489  assert (cache_kb);
490  return kb_nvt_get (cache_kb, oid, NVT_FAMILY_POS);
491 }

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 293 of file nvticache.c.

294 {
295  assert (cache_kb);
296  return kb_nvt_get (cache_kb, oid, NVT_FILENAME_POS);
297 }

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 }

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 321 of file nvticache.c.

322 {
323  assert (cache_kb);
325 }

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 431 of file nvticache.c.

432 {
433  assert (cache_kb);
434  return kb_nvt_get (cache_kb, oid, NVT_NAME_POS);
435 }

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 515 of file nvticache.c.

516 {
517  assert (cache_kb);
518  return kb_nvt_get_all (cache_kb, oid);
519 }

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 278 of file nvticache.c.

279 {
280  assert (cache_kb);
281 
282  return kb_nvt_get (cache_kb, filename, NVT_OID_POS);
283 }

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 ( )

Get the list of nvti OIDs.

Returns
OIDs list.

Definition at line 562 of file nvticache.c.

563 {
564  assert (cache_kb);
565 
566  return kb_nvt_get_oids (cache_kb);
567 }

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 529 of file nvticache.c.

530 {
531  char pattern[4096];
532  struct kb_item *prefs, *element;
533  GSList *list = NULL;
534 
535  assert (cache_kb);
536 
537  g_snprintf (pattern, sizeof (pattern), "oid:%s:prefs", oid);
538  prefs = element = kb_item_get_all (cache_kb, pattern);
539  while (element)
540  {
541  nvtpref_t *np;
542  char **array = g_strsplit (element->v_str, "|||", -1);
543 
544  assert (array[3]);
545  assert (!array[4]);
546  np = nvtpref_new (atoi (array[0]), array[1], array[2], array[3]);
547  g_strfreev (array);
548  list = g_slist_append (list, np);
549  element = element->next;
550  }
551  kb_item_free (prefs);
552 
553  return list;
554 }

References cache_kb, kb_item_free(), kb_item_get_all(), kb_item::next, nvtpref_new(), 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 307 of file nvticache.c.

308 {
309  assert (cache_kb);
311 }

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 363 of file nvticache.c.

364 {
365  assert (cache_kb);
367 }

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 349 of file nvticache.c.

350 {
351  assert (cache_kb);
353 }

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 256 of file nvticache.c.

257 {
258  char *filename, *src;
259 
260  assert (cache_kb);
261 
262  filename = kb_nvt_get (cache_kb, oid, NVT_FILENAME_POS);
263  if (!filename)
264  return NULL;
265  src = g_build_filename (src_path, filename, NULL);
266  g_free (filename);
267  return src;
268 }

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 501 of file nvticache.c.

502 {
503  assert (cache_kb);
504  return kb_nvt_get (cache_kb, oid, NVT_TAGS_POS);
505 }

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 411 of file nvticache.c.

412 {
413  int timeout;
414  char *timeout_s;
415 
416  assert (cache_kb);
417  timeout_s = kb_nvt_get (cache_kb, oid, NVT_TIMEOUT_POS);
418  timeout = atoi (timeout_s);
419  g_free (timeout_s);
420  return timeout;
421 }

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 473 of file nvticache.c.

474 {
475  assert (cache_kb);
476  return kb_nvt_get (cache_kb, oid, NVT_XREFS_POS);
477 }

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 }

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 }

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 }

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, *old_version;
185  if (cache_kb && !cache_saved)
186  {
187  kb_save (cache_kb);
188  cache_saved = 1;
189  }
190  old_version = nvticache_feed_version ();
191  feed_version = nvt_feed_version ();
192  if (feed_version && g_strcmp0 (old_version, feed_version))
193  {
194  kb_item_set_str (cache_kb, NVTICACHE_STR, feed_version, 0);
195  g_message ("Updated NVT cache from version %s to %s", old_version,
196  feed_version);
197  }
198  g_free (old_version);
199  g_free (feed_version);
200 }

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

Here is the call graph for this function:

Variable Documentation

◆ cache_kb

◆ cache_saved

int cache_saved = 1

If cache was saved.

Definition at line 51 of file nvticache.c.

Referenced by nvticache_add(), and nvticache_save().

◆ src_path

char* src_path = NULL

The directory of the source files.

Definition at line 49 of file nvticache.c.

Referenced by nvt_feed_version(), nvticache_add(), nvticache_check(), nvticache_get_src(), and nvticache_init().

NVT_EXCLUDED_KEYS_POS
@ NVT_EXCLUDED_KEYS_POS
Definition: kb.h:63
NVT_BIDS_POS
@ NVT_BIDS_POS
Definition: kb.h:69
nvticache_feed_version
char * nvticache_feed_version(void)
Get the NVT feed version.
Definition: nvticache.c:616
kb_find
static kb_t kb_find(const char *kb_path, const char *key)
Find an existing Knowledge Base object with key.
Definition: kb.h:278
kb_item_get_str
static char * kb_item_get_str(kb_t kb, const char *name)
Get a single KB string item.
Definition: kb.h:327
nvticache_delete
void nvticache_delete(const char *oid)
Delete NVT from the cache.
Definition: nvticache.c:588
NVT_NAME_POS
@ NVT_NAME_POS
Definition: kb.h:74
kb_lnk_reset
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:651
nvti_oid
gchar * nvti_oid(const nvti_t *n)
Get the OID string.
Definition: nvti.c:503
kb_save
static int kb_save(kb_t kb)
Save all the KB's content.
Definition: kb.h:631
nvt_feed_version
static char * nvt_feed_version()
Determine the version of the NVT feed.
Definition: nvticache.c:148
kb_nvt_get_all
static nvti_t * kb_nvt_get_all(kb_t kb, const char *oid)
Get a full NVT.
Definition: kb.h:585
NVT_FILENAME_POS
@ NVT_FILENAME_POS
Definition: kb.h:60
NVT_TIMEOUT_POS
@ NVT_TIMEOUT_POS
Definition: kb.h:72
kb_nvt_get_oids
static GSList * kb_nvt_get_oids(kb_t kb)
Get list of NVT OIDs.
Definition: kb.h:600
kb_item
Knowledge base item (defined by name, type (int/char*) and value). Implemented as a singly linked lis...
Definition: kb.h:83
nvti
The structure of a information record that corresponds to a NVT.
Definition: nvti.c:270
NVT_REQUIRED_UDP_PORTS_POS
@ NVT_REQUIRED_UDP_PORTS_POS
Definition: kb.h:64
kb_item_set_str
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:484
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
NVT_XREFS_POS
@ NVT_XREFS_POS
Definition: kb.h:70
kb_item_free
void kb_item_free(struct kb_item *item)
Release a KB item (or a list).
Definition: kb.c:537
nvticache_get_filename
char * nvticache_get_filename(const char *oid)
Get the filename from a plugin OID.
Definition: nvticache.c:293
cache_kb
kb_t cache_kb
Definition: nvticache.c:50
nvtpref
The structure for a preference of a NVT.
Definition: nvti.c:333
NVT_CATEGORY_POS
@ NVT_CATEGORY_POS
Definition: kb.h:71
NVT_DEPENDENCIES_POS
@ NVT_DEPENDENCIES_POS
Definition: kb.h:66
kb_item::next
struct kb_item * next
Definition: kb.h:94
src_path
char * src_path
Definition: nvticache.c:49
NVT_FAMILY_POS
@ NVT_FAMILY_POS
Definition: kb.h:73
NVTICACHE_STR
#define NVTICACHE_STR
Definition: nvticache.h:36
nvtpref_new
nvtpref_t * nvtpref_new(int id, gchar *name, gchar *type, gchar *dflt)
Create a new nvtpref structure filled with the given values.
Definition: nvti.c:357
kb_del_items
static int kb_del_items(kb_t kb, const char *name)
Delete all entries under a given name.
Definition: kb.h:616
kb_item_get_all
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:361
NVT_CVES_POS
@ NVT_CVES_POS
Definition: kb.h:68
NVT_MANDATORY_KEYS_POS
@ NVT_MANDATORY_KEYS_POS
Definition: kb.h:62
cache_saved
int cache_saved
Definition: nvticache.c:51
kb_nvt_add
static int kb_nvt_add(kb_t kb, const nvti_t *nvt, const char *filename)
Insert a new nvt.
Definition: kb.h:552
kb_item_count
static size_t kb_item_count(kb_t kb, const char *pattern)
Count all items stored under a given pattern.
Definition: kb.h:430
NVT_REQUIRED_KEYS_POS
@ NVT_REQUIRED_KEYS_POS
Definition: kb.h:61
kb_new
static int kb_new(kb_t *kb, const char *kb_path)
Initialize a new Knowledge Base object.
Definition: kb.h:245
NVT_TAGS_POS
@ NVT_TAGS_POS
Definition: kb.h:67
kb_nvt_get
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition: kb.h:569
NVT_REQUIRED_PORTS_POS
@ NVT_REQUIRED_PORTS_POS
Definition: kb.h:65