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;
153 g_snprintf (filename,
sizeof (filename),
"%s/plugin_feed_info.inc",
src_path);
154 if (!g_file_get_contents (filename, &fcontent, NULL, &error))
157 g_warning (
"nvt_feed_version: %s", error->message);
158 g_error_free (error);
161 plugin_set = g_strrstr (fcontent,
"PLUGIN_SET = ");
164 g_warning (
"nvt_feed_version: Erroneous %s format", filename);
169 plugin_set = g_strndup (plugin_set + 14, 12);
188 g_free (feed_version);
212 if (dummy && strcmp (filename, dummy))
214 struct stat src_stat;
215 char *src_file = g_build_filename (
src_path, dummy, NULL);
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);
247 char *filename, *src;
254 src = g_build_filename (
src_path, filename, NULL);
387 category = atoi (category_s);
407 timeout = atoi (timeout_s);
521 struct kb_item *prefs, *element;
526 g_snprintf (pattern,
sizeof (pattern),
"oid:%s:prefs", oid);
531 char **array = g_strsplit (element->
v_str,
"|||", -1);
540 list = g_slist_append (list, np);
541 element = element->
next;
588 g_snprintf (pattern,
sizeof (pattern),
"prefs:%s", oid);
590 g_snprintf (pattern,
sizeof (pattern),
"nvt:%s", oid);
595 g_snprintf (pattern,
sizeof (pattern),
"filename:%s", filename);
620 char *cached, *current;
626 ret = strcmp (cached, current);
char * nvticache_get_excluded_keys(const char *oid)
Get the Excluded Keys from a plugin OID.
char * nvticache_get_oid(const char *filename)
Get the OID from a plugin filename.
int nvticache_check(const gchar *filename)
Check if the nvt for the given filename exists in cache.
void kb_item_free(struct kb_item *item)
Release a KB item (or a list).
void nvticache_reset()
Reset connection to KB. To be called after a fork().
char * nvticache_get_required_keys(const char *oid)
Get the Required Keys from a plugin OID.
char * nvticache_get_filename(const char *oid)
Get the filename from a plugin OID.
gchar * name
Name of the preference.
The structure of a information record that corresponds to a NVT.
Knowledge base item (defined by name, type (int/char*) and value). Implemented as a singly linked lis...
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.
static struct kb_item * kb_item_get_all(kb_t kb, const char *name)
Get all items stored under a given name.
static nvti_t * kb_nvt_get_all(kb_t kb, const char *oid)
Get a full NVT.
char * nvticache_get_src(const char *oid)
Get the full source filename of an OID.
char * nvticache_get_mandatory_keys(const char *oid)
Get the Mandatory Keys from a plugin OID.
int nvticache_get_timeout(const char *oid)
Get the Timeout from a plugin OID.
static int kb_new(kb_t *kb, const char *kb_path)
Initialize a new Knowledge Base object.
gchar * type
Preference type.
void nvticache_delete(const char *oid)
Delete NVT from the cache.
Top-level KB. This is to be inherited by KB implementations.
char * nvticache_get_cves(const char *oid)
Get the cves from a plugin OID.
static int kb_del_items(kb_t kb, const char *name)
Delete all entries under a given name.
static int kb_nvt_add(kb_t kb, const nvti_t *nvt, const char *filename)
Insert a new nvt.
Knowledge base management API - Redis backend.
void nvticache_save()
Save the nvticache to disk.
int nvticache_initialized(void)
Return whether the nvt cache is initialized.
gchar * dflt
Default value of the preference.
static GSList * kb_nvt_get_oids(kb_t kb)
Get list of NVT OIDs.
char * nvticache_get_required_ports(const char *oid)
Get the Required ports from a plugin OID.
kb_t nvticache_get_kb(void)
Return the nvticache kb.
static char * kb_item_get_str(kb_t kb, const char *name)
Get a single KB string item.
GSList * nvticache_get_prefs(const char *oid)
Get the prefs 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_feed_version(void)
Get the NVT feed version.
char * nvticache_get_xrefs(const char *oid)
Get the xrefs from a plugin OID.
The structure for a preference of a NVT.
GSList * nvticache_get_oids()
Get the list of nvti OIDs.
char * nvticache_get_name(const char *oid)
Get the name from a plugin OID.
char * nvticache_get_bids(const char *oid)
Get the bids 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.
int nvticache_init(const char *src, const char *kb_path)
Initializes the nvti cache.
char * nvticache_get_dependencies(const char *oid)
Get the Dependencies from a plugin OID.
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.
char * nvticache_get_family(const char *oid)
Get the family from a plugin OID.
static char * nvt_feed_version()
Determine the version of the NVT feed.
static kb_t kb_find(const char *kb_path, const char *key)
Find an existing Knowledge Base object with key.
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.
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.
char * nvticache_get_required_udp_ports(const char *oid)
Get the Required udp ports from a plugin OID.
Protos and data structures for NVT Information Cache.
int nvticache_get_category(const char *oid)
Get the Category from a plugin OID.