OpenVAS Scanner  5.1.3
pluginload.h File Reference
#include <openvas/misc/arglists.h>
#include <openvas/base/kb.h>
#include <openvas/misc/network.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)
 
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 *)
 The nasl - plugin class. Loads or launches nasl- plugins. More...
 
int nasl_plugin_launch (struct arglist *, struct host_info *, kb_t, char *, const char *, int)
 Launch a NASL plugin. More...
 

Function Documentation

◆ current_loading_plugins()

int current_loading_plugins ( void  )

Definition at line 183 of file pluginload.c.

Referenced by comm_loading().

184 {
185  return loading_shm ? loading_shm[0] : 0;
186 }
Here is the caller graph for this function:

◆ destroy_loading_shm()

void destroy_loading_shm ( void  )

Definition at line 165 of file pluginload.c.

Referenced by loading_handler_stop().

166 {
167  if (loading_shm)
168  {
169  shmdt (loading_shm);
170  if (shmctl (loading_shmid, IPC_RMID, NULL))
171  perror ("shmctl");
172  loading_shm = NULL;
173  loading_shmid = 0;
174  }
175 }
Here is the caller graph for this function:

◆ init_loading_shm()

void init_loading_shm ( void  )

Definition at line 132 of file pluginload.c.

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

◆ nasl_plugin_add()

int nasl_plugin_add ( char *  folder,
char *  filename 
)

The nasl - plugin class. Loads or launches nasl- plugins.

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. If a plugin with the same (file)name is already present in the plugins arglist, it will be replaced.

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

Definition at line 73 of file nasl_plugins.c.

References log_write().

74 {
75  char fullname[PATH_MAX + 1];
76  int nasl_mode;
77  nasl_mode = NASL_EXEC_DESCR;
78 
79  snprintf (fullname, sizeof (fullname), "%s/%s", folder, filename);
80 
81  if (prefs_get_bool ("nasl_no_signature_check"))
82  {
83  nasl_mode |= NASL_ALWAYS_SIGNED;
84  }
85 
86  if (!nvticache_check (filename))
87  {
88  nvti_t *new_nvti;
89  struct arglist *plugin_args;
90 
91  plugin_args = g_malloc0 (sizeof (struct arglist));
92  arg_add_value (plugin_args, "key", ARG_PTR, nvticache_get_kb ());
93  new_nvti = nvti_new ();
94  arg_add_value (plugin_args, "NVTI", ARG_PTR, new_nvti);
95 
96  if (exec_nasl_script (plugin_args, fullname, NULL, nasl_mode) < 0)
97  {
98  log_write ("%s: Could not be loaded", fullname);
99  arg_free_all (plugin_args);
100  return -1;
101  }
102  arg_free_all (plugin_args);
103 
104  // Check mtime of plugin before caching it
105  // Set to now if mtime is in the future
106  struct stat plug_stat;
107  time_t now = time (NULL) - 1;
108  stat (fullname, &plug_stat);
109  if (plug_stat.st_mtime > now)
110  {
111  struct utimbuf fixed_timestamp;
112  fixed_timestamp.actime = now;
113  fixed_timestamp.modtime = now;
114  if (utime (fullname, &fixed_timestamp) == 0)
115  log_write ("The timestamp for %s was from the future. This has been fixed.", fullname);
116  else
117  log_write ("The timestamp for %s is from the future and could not be fixed.", fullname);
118  }
119 
120  if (nvti_oid (new_nvti))
121  nvticache_add (new_nvti, filename);
122  else
123  // Most likely an exit was hit before the description could be parsed.
124  log_write ("\r%s could not be added to the cache and is likely to stay"
125  " invisible to the client.", filename);
126  nvti_free (new_nvti);
127  }
128  return 0;
129 }
void log_write(const char *str,...)
Write into the logfile / syslog.
Definition: log.c:140
Here is the call graph for this function:

◆ nasl_plugin_launch()

int nasl_plugin_launch ( struct arglist *  ,
struct host_info *  ,
kb_t  ,
char *  ,
const char *  ,
int   
)

Launch a NASL plugin.

Definition at line 145 of file nasl_plugins.c.

References nasl_thread_args::args, create_process(), nasl_thread_args::name, nasl_thread_args::oid, and nasl_thread_args::soc.

147 {
148  int module;
149  struct nasl_thread_args nargs;
150  struct arglist *plugin;
151 
152  plugin = g_malloc0 (sizeof (struct arglist));
153  arg_add_value (plugin, "HOSTNAME", ARG_PTR, hostinfo);
154  arg_add_value (plugin, "globals", ARG_ARGLIST, globals);
155  arg_add_value (plugin, "key", ARG_PTR, kb);
156 
157  nargs.args = plugin;
158  nargs.name = name;
159  nargs.oid = oid;
160  nargs.soc = soc;
161 
162  module = create_process ((process_func_t) nasl_thread, &nargs);
163  arg_free (plugin);
164  return module;
165 }
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:77
Here is the call graph for this function:

◆ plugins_init()

int plugins_init ( void  )

Definition at line 358 of file pluginload.c.

References log_write().

359 {
360  int ret = 0;
361  pid_t child_pid;
362  const char *plugins_folder = prefs_get ("plugins_folder");
363 
364  if (nvticache_init (plugins_folder, prefs_get ("kb_location")))
365  {
366  log_write ("Failed to initialize nvti cache.");
367  return -1;
368  }
369  include_dirs ();
370 
371  child_pid = create_process (plugins_reload_from_dir, (void *) plugins_folder);
372  waitpid (child_pid, &ret, 0);
373  return ret;
374 }
void log_write(const char *str,...)
Write into the logfile / syslog.
Definition: log.c:140
pid_t create_process(process_func_t function, void *argument)
Create a new process (fork).
Definition: processes.c:77
Here is the call graph for this function:

◆ total_loading_plugins()

int total_loading_plugins ( void  )

Definition at line 194 of file pluginload.c.

Referenced by comm_loading().

195 {
196  return loading_shm ? loading_shm[1] : 0;
197 }
Here is the caller graph for this function: