49 #define G_LOG_DOMAIN "lib nvticache" 82 cache_kb = kb_find (kb_path,
"nvticache");
86 if (kb_new (&
cache_kb, kb_path) || kb_item_set_int (
cache_kb,
"nvticache", 1))
117 char pattern[2048], *src_file;
119 struct stat src_stat;
121 src_file = g_build_filename (
src_path, filename, NULL);
122 g_snprintf (pattern,
sizeof (pattern),
"filename:%s:timestamp", filename);
123 timestamp = kb_item_get_int (
cache_kb, pattern);
124 if (timestamp && src_file && stat (src_file, &src_stat) >= 0
125 && timestamp > src_stat.st_mtime)
159 char *
oid, *dummy, pattern[4096];
167 if (dummy && strcmp (filename, dummy))
169 struct stat src_stat;
170 char *src_file = g_build_filename (
src_path, dummy, NULL);
173 if (src_file && stat (src_file, &src_stat) >= 0)
174 g_warning (
"NVT %s with duplicate OID %s will be replaced with %s",
175 src_file,
oid, filename);
190 g_snprintf (pattern,
sizeof (pattern),
"oid:%s:prefs",
oid);
191 g_snprintf (value,
sizeof (value),
"%s|||%s|||%s", pref->
name, pref->
type,
193 if (kb_item_add_str (
cache_kb, pattern, value))
195 element = element->next;
197 g_snprintf (pattern,
sizeof (pattern),
"filename:%s:timestamp", filename);
198 if (kb_item_set_int (
cache_kb, pattern, time (NULL)))
217 char *filename, *src;
224 src = g_build_filename (
src_path, filename, NULL);
239 char *ret, pattern[2048];
244 g_snprintf (pattern,
sizeof (pattern),
"filename:%s:oid", filename);
245 ret = kb_item_get_str (
cache_kb, pattern);
250 g_snprintf (pattern,
sizeof (pattern),
"filename:*/%s:oid", filename);
251 kbi = kb_item_get_pattern (
cache_kb, pattern);
255 ret = g_strdup (kbi->
v_str);
373 category = atoi (category_s);
393 timeout = atoi (timeout_s);
521 struct kb_item *prefs, *element;
526 g_snprintf (pattern,
sizeof (pattern),
"oid:%s:prefs",
oid);
527 prefs = element = kb_item_get_all (
cache_kb, pattern);
531 char **array = g_strsplit (element->
v_str,
"|||", -1);
540 element = element->
next;
560 kbi = item = kb_item_get_pattern (
cache_kb,
"filename:*:oid");
583 return kb_item_count (
cache_kb,
"nvt:*");
596 g_snprintf (pattern,
sizeof (pattern),
"oid:%s:prefs",
oid);
598 g_snprintf (pattern,
sizeof (pattern),
"nvt:%s",
oid);
603 g_snprintf (pattern,
sizeof (pattern),
"filename:%s:timestamp", filename);
605 g_snprintf (pattern,
sizeof (pattern),
"filename:%s:oid", filename);
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 *)
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.
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.
char * nvticache_get_version(const char *oid)
Get the version from a plugin OID.
char * nvticache_get_copyright(const char *oid)
Get the copyright from a plugin OID.
gchar * type
Preference type.
void nvticache_delete(const char *oid)
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.
int nvticache_initialized(void)
Return whether the nvt cache is initialized.
gchar * dflt
Default value of the preference.
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.
GSList * nvticache_get_prefs(const char *oid)
Get the prefs from a plugin OID.
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.
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.
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.
char * nvticache_get_tags(const char *oid)
Get the tags from a plugin OID.
char * nvticache_get_required_udp_ports(const char *oid)
Get the Required udp ports from a plugin OID.
GSList * prefs
Collection of NVT preferences.
Protos and data structures for NVT Information Cache.
int nvticache_get_category(const char *oid)
Get the Category from a plugin OID.