OpenVAS Scanner  5.1.3
nasl_plugins.c File Reference
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <glib.h>
#include <sys/types.h>
#include <utime.h>
#include <openvas/base/drop_privileges.h>
#include <openvas/base/nvticache.h>
#include <openvas/nasl/nasl.h>
#include <openvas/misc/network.h>
#include <openvas/misc/nvt_categories.h>
#include <openvas/misc/plugutils.h>
#include <openvas/misc/internal_com.h>
#include <openvas/misc/openvas_proctitle.h>
#include <openvas/misc/prefs.h>
#include "pluginload.h"
#include "pluginscheduler.h"
#include "pluginlaunch.h"
#include "processes.h"
#include "log.h"
Include dependency graph for nasl_plugins.c:

Go to the source code of this file.

Data Structures

struct  nasl_thread_args
 

Functions

int nasl_plugin_add (char *folder, char *filename)
 The nasl - plugin class. Loads or launches nasl- plugins. More...
 
int nasl_plugin_launch (struct arglist *globals, struct host_info *hostinfo, kb_t kb, char *name, const char *oid, int soc)
 Launch a NASL plugin. More...
 

Function Documentation

◆ 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.

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

References log_write().

Here is the call graph for this function:

◆ nasl_plugin_launch()

int nasl_plugin_launch ( struct arglist *  globals,
struct host_info *  hostinfo,
kb_t  kb,
char *  name,
const char *  oid,
int  soc 
)

Launch a NASL plugin.

Definition at line 145 of file nasl_plugins.c.

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

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

Here is the call graph for this function: