Greenbone Vulnerability Management Libraries
11.0.1
|
Go to the documentation of this file.
47 #define G_LOG_DOMAIN "lib nvticache"
118 char *src_file, *time_s;
119 struct stat src_stat;
122 src_file = g_build_filename (
src_path, filename, NULL);
124 if (time_s && src_file && stat (src_file, &src_stat) >= 0
125 && atoi (time_s) > src_stat.st_mtime)
150 char filename[2048], *fcontent = NULL, *plugin_set;
151 GError *error = NULL;
152 static int msg_shown = 0;
154 g_snprintf (filename,
sizeof (filename),
"%s/plugin_feed_info.inc",
src_path);
155 if (!g_file_get_contents (filename, &fcontent, NULL, &error))
157 if (error && msg_shown == 0)
159 g_warning (
"nvt_feed_version: %s", error->message);
162 g_error_free (error);
165 plugin_set = g_strrstr (fcontent,
"PLUGIN_SET = ");
168 g_warning (
"nvt_feed_version: Erroneous %s format", filename);
173 plugin_set = g_strndup (plugin_set + 14, 12);
184 char *feed_version, *old_version;
192 if (feed_version && g_strcmp0 (old_version, feed_version))
195 g_message (
"Updated NVT cache from version %s to %s", old_version,
198 g_free (old_version);
199 g_free (feed_version);
223 if (dummy && strcmp (filename, dummy))
225 struct stat src_stat;
226 char *src_file = g_build_filename (
src_path, dummy, NULL);
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);
258 char *filename, *src;
265 src = g_build_filename (
src_path, filename, NULL);
398 category = atoi (category_s);
418 timeout = atoi (timeout_s);
532 struct kb_item *prefs, *element;
537 g_snprintf (pattern,
sizeof (pattern),
"oid:%s:prefs", oid);
542 char **array = g_strsplit (element->
v_str,
"|||", -1);
546 np =
nvtpref_new (atoi (array[0]), array[1], array[2], array[3]);
548 list = g_slist_append (list, np);
549 element = element->
next;
597 g_snprintf (pattern,
sizeof (pattern),
"oid:%s:prefs", oid);
599 g_snprintf (pattern,
sizeof (pattern),
"nvt:%s", oid);
604 g_snprintf (pattern,
sizeof (pattern),
"filename:%s", filename);
629 char *cached, *current;
635 ret = strcmp (cached, current);
Knowledge base management API - Redis backend.
char * nvticache_feed_version(void)
Get the NVT feed version.
static kb_t kb_find(const char *kb_path, const char *key)
Find an existing Knowledge Base object with key.
static char * kb_item_get_str(kb_t kb, const char *name)
Get a single KB string item.
Protos and data structures for NVT Information Cache.
char * nvticache_get_src(const char *oid)
Get the full source filename of an OID.
void nvticache_delete(const char *oid)
Delete NVT from the cache.
char * nvticache_get_mandatory_keys(const char *oid)
Get the Mandatory Keys from a plugin OID.
char * nvticache_get_oid(const char *filename)
Get the OID from a plugin filename.
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...
gchar * nvti_oid(const nvti_t *n)
Get the OID string.
int nvticache_get_timeout(const char *oid)
Get the Timeout from a plugin OID.
static int kb_save(kb_t kb)
Save all the KB's content.
size_t nvticache_count()
Get the number of nvt's in the cache.
void nvticache_reset()
Reset connection to KB. To be called after a fork().
static char * nvt_feed_version()
Determine the version of the NVT feed.
char * nvticache_get_family(const char *oid)
Get the family from a plugin OID.
static nvti_t * kb_nvt_get_all(kb_t kb, const char *oid)
Get a full NVT.
char * nvticache_get_cves(const char *oid)
Get the cves from a plugin OID.
void nvticache_save()
Save the nvticache to disk.
char * nvticache_get_xrefs(const char *oid)
Get the xrefs from a plugin OID.
static GSList * kb_nvt_get_oids(kb_t kb)
Get list of NVT OIDs.
int nvticache_get_category(const char *oid)
Get the Category from a plugin OID.
char * nvticache_get_required_udp_ports(const char *oid)
Get the Required udp ports from a plugin OID.
int nvticache_initialized(void)
Return whether the nvt cache is initialized.
Knowledge base item (defined by name, type (int/char*) and value). Implemented as a singly linked lis...
char * nvticache_get_name(const char *oid)
Get the name from a plugin OID.
GSList * nvticache_get_oids()
Get the list of nvti OIDs.
The structure of a information record that corresponds to a NVT.
@ NVT_REQUIRED_UDP_PORTS_POS
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.
GSList * nvticache_get_prefs(const char *oid)
Get the prefs from a plugin OID.
int nvticache_check(const gchar *filename)
Check if the nvt for the given filename exists in cache.
int nvticache_init(const char *src, const char *kb_path)
Initializes the nvti cache.
void kb_item_free(struct kb_item *item)
Release a KB item (or a list).
char * nvticache_get_filename(const char *oid)
Get the filename from a plugin OID.
char * nvticache_get_required_keys(const char *oid)
Get the Required Keys from a plugin OID.
The structure for a preference of a NVT.
int nvticache_add(const nvti_t *nvti, const char *filename)
Add a NVT Information to the cache.
int nvticache_check_feed(void)
Check if the plugins feed was newer than cached feed.
nvtpref_t * nvtpref_new(int id, gchar *name, gchar *type, gchar *dflt)
Create a new nvtpref structure filled with the given values.
Top-level KB. This is to be inherited by KB implementations.
static int kb_del_items(kb_t kb, const char *name)
Delete all entries under a given name.
static struct kb_item * kb_item_get_all(kb_t kb, const char *name)
Get all items stored under a given name.
static int kb_nvt_add(kb_t kb, const nvti_t *nvt, const char *filename)
Insert a new nvt.
char * nvticache_get_bids(const char *oid)
Get the bids from a plugin OID.
static size_t kb_item_count(kb_t kb, const char *pattern)
Count all items stored under a given pattern.
char * nvticache_get_dependencies(const char *oid)
Get the Dependencies from a plugin OID.
static int kb_new(kb_t *kb, const char *kb_path)
Initialize a new Knowledge Base object.
nvti_t * nvticache_get_nvt(const char *oid)
Get the nvti from a plugin OID.
static char * kb_nvt_get(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
char * nvticache_get_tags(const char *oid)
Get the tags from a plugin OID.
char * nvticache_get_excluded_keys(const char *oid)
Get the Excluded Keys from a plugin OID.
kb_t nvticache_get_kb(void)
Return the nvticache kb.
char * nvticache_get_required_ports(const char *oid)
Get the Required ports from a plugin OID.