OpenVAS Scanner  22.7.9
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)
 main function for loading all the plugins More...
 
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 (const char *, char *)
 Add one .nasl plugin to the plugin list. More...
 
int nasl_file_check (const char *, const char *)
 Check a single .nasl/.inc file. 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 171 of file pluginload.c.

172 {
173  return loading_shm ? loading_shm[0] : 0;
174 }

References loading_shm.

◆ destroy_loading_shm()

void destroy_loading_shm ( void  )

Definition at line 153 of file pluginload.c.

154 {
155  if (loading_shm)
156  {
157  shmdt (loading_shm);
158  if (shmctl (loading_shmid, IPC_RMID, NULL))
159  perror ("shmctl");
160  loading_shm = NULL;
161  loading_shmid = 0;
162  }
163 }

References loading_shm, and loading_shmid.

◆ init_loading_shm()

void init_loading_shm ( void  )

Definition at line 120 of file pluginload.c.

121 {
122  int shm_key;
123 
124  if (loading_shm)
125  return;
126 
127  shm_key = rand () + 1;
128  /*
129  * Create shared memory segment if it doesn't exist.
130  * This will be used to communicate current plugins loading progress to other
131  * processes.
132  * loading_shm[0]: Number of loaded plugins.
133  * loading_shm[1]: Total number of plugins.
134  */
135  loading_shmid = shmget (shm_key, sizeof (int) * 2, IPC_CREAT | 0600);
136  if (loading_shmid < 0)
137  perror ("shmget");
138  loading_shm = shmat (loading_shmid, NULL, 0);
139  if (loading_shm == (void *) -1)
140  {
141  perror ("shmat");
142  loading_shm = NULL;
143  }
144  else
145  bzero (loading_shm, sizeof (int) * 2);
146 }

References loading_shm, and loading_shmid.

◆ nasl_file_check()

int nasl_file_check ( const char *  folder,
const char *  filename 
)

Check a single .nasl/.inc file.

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

Definition at line 83 of file nasl_plugins.c.

84 {
85  char fullname[PATH_MAX + 1];
86  int nasl_mode;
87  struct script_infos *args;
88 
89  snprintf (fullname, sizeof (fullname), "%s/%s", folder, filename);
90  nasl_mode = NASL_EXEC_DESCR;
91  if (prefs_get_bool ("nasl_no_signature_check"))
92  nasl_mode |= NASL_ALWAYS_SIGNED;
93 
94  args = g_malloc0 (sizeof (struct script_infos));
95  args->key = nvticache_get_kb ();
96  args->nvti = NULL;
97  args->name = fullname;
98  if (exec_nasl_script (args, nasl_mode) < 0)
99  {
100  g_debug ("%s: Checksum check failed", fullname);
101  g_free (args);
102  return -1;
103  }
104  g_free (args);
105 
106  return 0;
107 }

References exec_nasl_script(), script_infos::key, script_infos::name, NASL_ALWAYS_SIGNED, NASL_EXEC_DESCR, and script_infos::nvti.

Referenced by plugins_cache_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nasl_plugin_add()

int nasl_plugin_add ( const char *  folder,
char *  filename 
)

Add one .nasl plugin to the plugin list.

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 120 of file nasl_plugins.c.

121 {
122  char fullname[PATH_MAX + 1];
123  int nasl_mode;
124  nvti_t *new_nvti;
125  struct script_infos *args;
126  time_t now;
127  struct utimbuf updated_timestamp;
128 
129  snprintf (fullname, sizeof (fullname), "%s/%s", folder, filename);
130  nasl_mode = NASL_EXEC_DESCR;
131  if (prefs_get_bool ("nasl_no_signature_check"))
132  nasl_mode |= NASL_ALWAYS_SIGNED;
133 
134  args = g_malloc0 (sizeof (struct script_infos));
135  args->key = nvticache_get_kb ();
136  new_nvti = nvti_new ();
137  args->nvti = new_nvti;
138  args->name = fullname;
139  if (exec_nasl_script (args, nasl_mode) < 0)
140  {
141  g_debug ("%s: Could not be loaded", fullname);
142  g_free (args);
143  return -1;
144  }
145  g_free (args);
146 
147  now = time (NULL) - 1;
148  updated_timestamp.actime = now;
149  updated_timestamp.modtime = now;
150  utime (fullname, &updated_timestamp);
151 
152  if (!check_nvti (filename, new_nvti))
153  nvticache_add (new_nvti, filename);
154  nvti_free (new_nvti);
155 
156  return 0;
157 }

References check_nvti(), exec_nasl_script(), script_infos::key, script_infos::name, NASL_ALWAYS_SIGNED, NASL_EXEC_DESCR, and script_infos::nvti.

Referenced by plugins_reload_from_dir().

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 166 of file nasl_plugins.c.

168 {
169  int module;
170  struct script_infos infos;
171 
172  memset (&infos, '\0', sizeof (infos));
173  // extend here, maybe create struct to simplify calls
174  infos.ip = ip;
175  infos.vhosts = vhosts;
176  infos.globals = globals;
177  infos.key = kb;
178  infos.oid = (char *) oid;
179  infos.name = nvticache_get_src (oid);
180  infos.ipc_context = NULL;
181 
182  module = create_ipc_process ((ipc_process_func) nasl_thread, &infos);
183  g_free (infos.name);
184  return module;
185 }

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

Referenced by plugin_launch().

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.

Returns
0 on success, -1 on failure.

Definition at line 348 of file pluginload.c.

349 {
350  int ret;
351  const char *plugins_folder = prefs_get ("plugins_folder");
352 
353  if (nvticache_init (plugins_folder, prefs_get ("db_address")))
354  {
355  g_debug ("Failed to initialize nvti cache.");
356  return -1;
357  }
358  include_dirs ();
359  ret = nasl_file_check (plugins_folder, "plugin_feed_info.inc");
360  if (ret)
361  return -1;
362 
363  return 0;
364 }

References include_dirs(), and nasl_file_check().

Referenced by attack_network_init(), openvas(), and plugins_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ plugins_init()

int plugins_init ( void  )

main function for loading all the plugins

Returns
0 on success, !=0 on failure.

Definition at line 372 of file pluginload.c.

373 {
374  int ret = 0;
375  const char *plugins_folder = prefs_get ("plugins_folder");
376 
377  ret = plugins_cache_init ();
378  if (ret)
379  return ret;
380 
381  ret = plugins_reload_from_dir (plugins_folder);
382  nvticache_save ();
383  return ret;
384 }

References plugins_cache_init(), and plugins_reload_from_dir().

Referenced by openvas().

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 182 of file pluginload.c.

183 {
184  return loading_shm ? loading_shm[1] : 0;
185 }

References loading_shm.

script_infos::ip
struct in6_addr * ip
Definition: scanneraux.h:37
script_infos
Definition: scanneraux.h:29
script_infos::key
kb_t key
Definition: scanneraux.h:32
plugins_reload_from_dir
static int plugins_reload_from_dir(const char *folder)
Definition: pluginload.c:242
script_infos::name
char * name
Definition: scanneraux.h:35
script_infos::nvti
nvti_t * nvti
Definition: scanneraux.h:33
include_dirs
static void include_dirs(void)
Definition: pluginload.c:318
loading_shmid
static int loading_shmid
Definition: pluginload.c:113
nasl_file_check
int nasl_file_check(const char *folder, const char *filename)
Check a single .nasl/.inc file.
Definition: nasl_plugins.c:83
NASL_EXEC_DESCR
#define NASL_EXEC_DESCR
Definition: nasl.h:45
oid
const char * oid
Definition: nasl_builtin_find_service.c:51
create_ipc_process
pid_t create_ipc_process(ipc_process_func func, void *args)
initializes a communication channels and calls a function with a new process
Definition: processes.c:195
loading_shm
static int * loading_shm
Definition: pluginload.c:112
script_infos::globals
struct scan_globals * globals
Definition: scanneraux.h:30
ipc_process_func
void(* ipc_process_func)(struct ipc_context *, void *)
Definition: ipc.h:47
script_infos::vhosts
GSList * vhosts
Definition: scanneraux.h:38
NASL_ALWAYS_SIGNED
#define NASL_ALWAYS_SIGNED
Definition: nasl.h:47
nasl_thread
static void nasl_thread(struct ipc_context *, struct script_infos *)
Definition: nasl_plugins.c:188
exec_nasl_script
int exec_nasl_script(struct script_infos *script_infos, int mode)
Execute a NASL script.
Definition: exec.c:1614
check_nvti
static int check_nvti(const char *filename, nvti_t *nvt)
Check that the nvt's data is valid.
Definition: nasl_plugins.c:51
plugins_cache_init
int plugins_cache_init(void)
Main function for nvticache initialization without loading the plugins.
Definition: pluginload.c:348