OpenVAS Scanner  7.0.1~git
pluginload.h File Reference

pluginload.c header. More...

#include "../misc/network.h"
#include "../misc/scanneraux.h"
#include <gvm/util/kb.h>
Include dependency graph for pluginload.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int plugins_init (void)
 
int plugins_cache_init (void)
 Main function for nvticache initialization without loading the plugins. More...
 
void init_loading_shm (void)
 
void destroy_loading_shm (void)
 
int current_loading_plugins (void)
 
int total_loading_plugins (void)
 
int nasl_plugin_add (char *, char *)
 Add one .nasl plugin to the plugin list. More...
 
int nasl_plugin_launch (struct scan_globals *, struct in6_addr *, GSList *, kb_t, const char *)
 Launch a NASL plugin. More...
 

Detailed Description

pluginload.c header.

Definition in file pluginload.h.

Function Documentation

◆ current_loading_plugins()

int current_loading_plugins ( void  )

Definition at line 184 of file pluginload.c.

References loading_shm.

185 {
186  return loading_shm ? loading_shm[0] : 0;
187 }
static int * loading_shm
Definition: pluginload.c:125

◆ destroy_loading_shm()

void destroy_loading_shm ( void  )

Definition at line 166 of file pluginload.c.

References loading_shm, and loading_shmid.

167 {
168  if (loading_shm)
169  {
170  shmdt (loading_shm);
171  if (shmctl (loading_shmid, IPC_RMID, NULL))
172  perror ("shmctl");
173  loading_shm = NULL;
174  loading_shmid = 0;
175  }
176 }
static int loading_shmid
Definition: pluginload.c:126
static int * loading_shm
Definition: pluginload.c:125

◆ init_loading_shm()

void init_loading_shm ( void  )

Definition at line 133 of file pluginload.c.

References loading_shm, and loading_shmid.

134 {
135  int shm_key;
136 
137  if (loading_shm)
138  return;
139 
140  shm_key = rand () + 1;
141  /*
142  * Create shared memory segment if it doesn't exist.
143  * This will be used to communicate current plugins loading progress to other
144  * processes.
145  * loading_shm[0]: Number of loaded plugins.
146  * loading_shm[1]: Total number of plugins.
147  */
148  loading_shmid = shmget (shm_key, sizeof (int) * 2, IPC_CREAT | 0600);
149  if (loading_shmid < 0)
150  perror ("shmget");
151  loading_shm = shmat (loading_shmid, NULL, 0);
152  if (loading_shm == (void *) -1)
153  {
154  perror ("shmat");
155  loading_shm = NULL;
156  }
157  else
158  bzero (loading_shm, sizeof (int) * 2);
159 }
static int loading_shmid
Definition: pluginload.c:126
static int * loading_shm
Definition: pluginload.c:125

◆ nasl_plugin_add()

int nasl_plugin_add ( char *  folder,
char *  filename 
)

Add one .nasl plugin to the plugin list.

The plugin is first attempted to be loaded from the cache. If that fails, it is parsed (via exec_nasl_script) and added to the cache.

Parameters
folderPath to the plugin folder.
filenameFile-name of the plugin
Returns
0 on success, -1 on error.

Definition at line 99 of file nasl_plugins.c.

References check_nvti(), exec_nasl_script(), NASL_ALWAYS_SIGNED, and NASL_EXEC_DESCR.

Referenced by plugins_reload_from_dir().

100 {
101  char fullname[PATH_MAX + 1];
102  int nasl_mode;
103  nasl_mode = NASL_EXEC_DESCR;
104 
105  snprintf (fullname, sizeof (fullname), "%s/%s", folder, filename);
106 
107  if (prefs_get_bool ("nasl_no_signature_check"))
108  {
109  nasl_mode |= NASL_ALWAYS_SIGNED;
110  }
111 
112  if (!nvticache_check (filename))
113  {
114  nvti_t *new_nvti;
115  struct script_infos *args;
116  time_t now;
117  struct utimbuf updated_timestamp;
118 
119  args = g_malloc0 (sizeof (struct script_infos));
120  args->key = nvticache_get_kb ();
121  new_nvti = nvti_new ();
122  args->nvti = new_nvti;
123  args->name = fullname;
124  if (exec_nasl_script (args, nasl_mode) < 0)
125  {
126  g_debug ("%s: Could not be loaded", fullname);
127  g_free (args);
128  return -1;
129  }
130  g_free (args);
131 
132  now = time (NULL) - 1;
133  updated_timestamp.actime = now;
134  updated_timestamp.modtime = now;
135  utime (fullname, &updated_timestamp);
136 
137  if (!check_nvti (filename, new_nvti))
138  nvticache_add (new_nvti, filename);
139  nvti_free (new_nvti);
140  }
141  return 0;
142 }
int exec_nasl_script(struct script_infos *script_infos, int mode)
Execute a NASL script.
Definition: exec.c:1624
#define NASL_EXEC_DESCR
Definition: nasl.h:57
#define NASL_ALWAYS_SIGNED
Definition: nasl.h:59
static int check_nvti(const char *filename, nvti_t *nvt)
Check that the nvt&#39;s data is valid.
Definition: nasl_plugins.c:63
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nasl_plugin_launch()

int nasl_plugin_launch ( struct scan_globals ,
struct in6_addr *  ,
GSList *  ,
kb_t  ,
const char *   
)

Launch a NASL plugin.

Definition at line 151 of file nasl_plugins.c.

References create_process(), script_infos::globals, script_infos::ip, script_infos::key, script_infos::name, nasl_thread(), script_infos::oid, oid, and script_infos::vhosts.

Referenced by plugin_launch().

153 {
154  int module;
155  struct script_infos infos;
156 
157  memset (&infos, '\0', sizeof (infos));
158  infos.ip = ip;
159  infos.vhosts = vhosts;
160  infos.globals = globals;
161  infos.key = kb;
162  infos.oid = (char *) oid;
163  infos.name = nvticache_get_src (oid);
164 
165  module = create_process ((process_func_t) nasl_thread, &infos);
166  g_free (infos.name);
167  return module;
168 }
struct scan_globals * globals
Definition: scanneraux.h:45
const char * oid
struct in6_addr * ip
Definition: scanneraux.h:51
static void nasl_thread(struct script_infos *)
Definition: nasl_plugins.c:171
void(* process_func_t)(void *)
Definition: processes.h:31
pid_t create_process(process_func_t function, void *argument)
Create a new process (fork).
Definition: processes.c:97
GSList * vhosts
Definition: scanneraux.h:52
Here is the call graph for this function:
Here is the caller graph for this function:

◆ plugins_cache_init()

int plugins_cache_init ( void  )

Main function for nvticache initialization without loading the plugins.

Definition at line 359 of file pluginload.c.

References include_dirs().

Referenced by plugins_init(), and start_single_task_scan().

360 {
361  const char *plugins_folder = prefs_get ("plugins_folder");
362 
363  if (nvticache_init (plugins_folder, prefs_get ("db_address")))
364  {
365  g_debug ("Failed to initialize nvti cache.");
366  return -1;
367  }
368  include_dirs ();
369  return 0;
370 }
static void include_dirs(void)
Definition: pluginload.c:331
Here is the call graph for this function:
Here is the caller graph for this function:

◆ plugins_init()

int plugins_init ( void  )

Definition at line 376 of file pluginload.c.

References create_process(), plugins_cache_init(), and plugins_reload_from_dir().

Referenced by openvas(), and reload_openvas().

377 {
378  int ret = 0;
379  pid_t child_pid;
380  const char *plugins_folder = prefs_get ("plugins_folder");
381 
382  ret = plugins_cache_init ();
383  if (ret)
384  return ret;
385 
386  child_pid = create_process (plugins_reload_from_dir, (void *) plugins_folder);
387  waitpid (child_pid, &ret, 0);
388  nvticache_save ();
389  return ret;
390 }
static void plugins_reload_from_dir(void *folder)
Definition: pluginload.c:255
pid_t create_process(process_func_t function, void *argument)
Create a new process (fork).
Definition: processes.c:97
int plugins_cache_init(void)
Main function for nvticache initialization without loading the plugins.
Definition: pluginload.c:359
Here is the call graph for this function:
Here is the caller graph for this function:

◆ total_loading_plugins()

int total_loading_plugins ( void  )

Definition at line 195 of file pluginload.c.

References loading_shm.

196 {
197  return loading_shm ? loading_shm[1] : 0;
198 }
static int * loading_shm
Definition: pluginload.c:125