39 #include <sys/types.h> 42 #include <openvas/base/drop_privileges.h> 43 #include <openvas/base/nvticache.h> 44 #include <openvas/nasl/nasl.h> 45 #include <openvas/misc/network.h> 46 #include <openvas/misc/nvt_categories.h> 47 #include <openvas/misc/plugutils.h> 48 #include <openvas/misc/internal_com.h> 49 #include <openvas/misc/openvas_proctitle.h> 50 #include <openvas/misc/prefs.h> 75 char fullname[PATH_MAX + 1];
77 nasl_mode = NASL_EXEC_DESCR;
79 snprintf (fullname,
sizeof (fullname),
"%s/%s", folder, filename);
81 if (prefs_get_bool (
"nasl_no_signature_check"))
83 nasl_mode |= NASL_ALWAYS_SIGNED;
86 if (!nvticache_check (filename))
89 struct arglist *plugin_args;
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);
96 if (exec_nasl_script (plugin_args, fullname, NULL, nasl_mode) < 0)
98 log_write (
"%s: Could not be loaded", fullname);
99 arg_free_all (plugin_args);
102 arg_free_all (plugin_args);
106 struct stat plug_stat;
107 time_t now = time (NULL) - 1;
108 stat (fullname, &plug_stat);
109 if (plug_stat.st_mtime > now)
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);
117 log_write (
"The timestamp for %s is from the future and could not be fixed.", fullname);
120 if (nvti_oid (new_nvti))
121 nvticache_add (new_nvti, filename);
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);
146 kb_t kb,
char *name,
const char *oid,
int soc)
150 struct arglist *plugin;
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);
170 struct arglist *args = nargs->
args;
171 struct arglist *globals = arg_get_value (args,
"globals");
172 struct host_info *hostinfo = arg_get_value (args,
"HOSTNAME");
173 char *name = nargs->
name;
176 GError *error = NULL;
179 if (prefs_get_bool (
"be_nice"))
183 nice_retval = nice (-5);
184 if (nice_retval == -1 && errno != 0)
186 log_write (
"Unable to renice process: %d", errno);
191 kb = arg_get_value (args,
"key");
193 arg_set_value (globals,
"global_socket", GSIZE_TO_POINTER (nargs->
soc));
194 proctitle_set (
"openvassd: testing %s (%s)", hostinfo->name, name);
196 if (prefs_get_bool (
"nasl_no_signature_check"))
197 nasl_mode |= NASL_ALWAYS_SIGNED;
199 if (prefs_get_bool (
"drop_privileges"))
201 int drop_priv_res = drop_privileges (NULL, &error);
202 if (drop_priv_res != OPENVAS_DROP_PRIVILEGES_OK)
204 if (drop_priv_res != OPENVAS_DROP_PRIVILEGES_FAIL_NOT_ROOT)
205 log_write (
"Failed to drop privileges for %s", name);
206 g_error_free (error);
210 exec_nasl_script (args, name, nargs->
oid, nasl_mode);
211 internal_send (nargs->
soc, NULL,
212 INTERNAL_COMM_MSG_TYPE_CTRL | INTERNAL_COMM_CTRL_FINISHED);
void log_write(const char *str,...)
Write into the logfile / syslog.
int nasl_plugin_add(char *folder, char *filename)
The nasl - plugin class. Loads or launches nasl- plugins.
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.
void pluginlaunch_child_cleanup(void)
Cleanup file descriptors used by the processes array. To be called by the child process running the p...
void(* process_func_t)(void *)
pid_t create_process(process_func_t function, void *argument)
Create a new process (fork).