OpenVAS Libraries  4.0+rc3.SVN
Functions
misc/store.c File Reference
#include <string.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <time.h>
#include <sys/param.h>
#include <glib.h>
#include "share_fd.h"
#include "system.h"
#include "plugutils.h"
#include "nvti.h"
#include "nvticache.h"

Functions

void _add_plugin_preference (struct arglist *prefs, const char *p_name, const char *name, const char *type, const char *defaul)
int store_init (const char *dir, const char *src)
 Initializes the global NVTI Cache.
struct argliststore_load_plugin (const char *file, struct arglist *prefs)
 Returns a (plugin) arglist assembled from the cached description file.
void store_plugin (struct arglist *plugin, char *file)
 Creates an entry in the store for data of "plugin" into cache file.

Detailed Description

OpenVAS-Scanner employs a plugin cache to avoid parsing all known nvts at start-up.

The cache consists of a .desc file for each script (e.g. cache file of nvts/xyz.nasl is nvts/xyz.nas.desc), which contains a memory dump of the corresponding plugin struct.

The cache is used as followed:

  1. Init the store with store_init.
  1. Add nvts by calling store_plugin or
  1. Give the store a file path (store_load_plugin) and receive the plugin as arglist. Under nice conditions the information contained in the cache file can be used. Under not so nice conditions, the store returns NULL (cache is either outdated, contains error or an error occurred).

The store is updated at each openvassd start up. There the plugin loader iterates over plugin files and tries to retrieve the cached version. If there is no cached version (or store_load_plugin returns Null for another reason, e.g.because the script file seems to have been modified in between) the plugin is added to the store (store_plugin).


Function Documentation

int store_init ( const char *  dir,
const char *  src 
)

Initializes the global NVTI Cache.

Parameters:
dirPath to the cache-directory. It must exist.
srcPath to the plugin-directory. It must exist.
Returns:
0 in case of success (nvti_cache is set now) -1 if the given path exeeds the buffer size -2 if the directory does not exist -3 if the given path was NULL In any other case than 0 nvti_cache is not set and a error is printed to stderr
struct arglist* store_load_plugin ( const char *  file,
struct arglist prefs 
) [read]

Returns a (plugin) arglist assembled from the cached description file.

Parameters:
fileFilename of the plugin (e.g. "scriptname1.nasl" or "subdir1/subdir2/scriptname2.nasl" ).
prefsPlugin preference arglist.

NULL is returned in either of these cases: 1) The .NVT definition or .desc file does not exist. 2) NVT definition file (e.g. xyz.nasl) or nvt signature (xyz.asc) file is newer than the .desc file. 3) The NVT definition files (e.g. xyz.nasl) or nvt signature (xyz.asc) files timestamp is in the future. 4) The magic number test failed (other file format expected). 5) An internal error occured.

Point 4) is necessary because the cache will not create .desc files with timestamps in the future. Thus, when creating a new cache file for the given NVT, it would not be able to become loaded from the cache (point 2)).

Returns:
Pointer to plugin as arglist or NULL.
void store_plugin ( struct arglist plugin,
char *  file 
)

Creates an entry in the store for data of "plugin" into cache file.

"file" which is placed in the cache directory.

Parameters:
pluginData structure that contains a plugin description
fileName of corresponding plugin file (e.g. "x.nasl", "x.nes" or "x.oval". It can also be something like "subdir1/subdir2/scriptname.nasl").