17#include "base/networking.h"
21#include <gvm/base/prefs.h>
22#include <gvm/boreas/cli.h>
36#define G_LOG_DOMAIN "sd main"
58 trans = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
62 g_hash_table_insert (trans, g_strdup (file_hash), contents);
82 gchar *filesize_str = g_strdup_printf (
"%ld", filesize);
87 trans = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
91 g_hash_table_insert (trans, g_strdup (file_hash), g_strdup (filesize_str));
105 const char *file_hash)
108 gchar *contents = NULL;
112 if (!file_hash || *file_hash ==
'\0')
115 origname = g_strdup (file_hash);
117 contents = (gchar *) g_base64_decode (file, &bytes);
119 if (contents == NULL)
121 g_debug (
"store_file: Failed to allocate memory for uploaded file.");
140 if (prefs_get (
"max_hosts"))
142 max_hosts = atoi (prefs_get (
"max_hosts"));
145 g_debug (
"Error ! max_hosts = %d -- check %s", max_hosts,
146 (
char *) prefs_get (
"config_file"));
151 g_debug (
"Client tried to raise the maximum hosts number - %d."
152 " Using %d. Change 'max_hosts' in openvas.conf if you"
153 " believe this is incorrect",
171 if (prefs_get (
"max_checks"))
173 max_checks = atoi (prefs_get (
"max_checks"));
176 g_debug (
"Error ! max_hosts = %d -- check %s", max_checks,
177 (
char *) prefs_get (
"config_file"));
182 g_debug (
"Client tried to raise the maximum checks number - %d."
183 " Using %d. Change 'max_checks' in openvas.conf if you"
184 " believe this is incorrect",
204 for (i = 0, ret = 1; (i < 10) && (ret > 0); i++)
205 ret = waitpid (
pid, NULL, WNOHANG);
207 return kill (
pid, 0) == 0;
214 ioctl (soc, FIONREAD, &data);
225 e = waitpid (-1, NULL, WNOHANG);
228 while ((e > 0 || errno == EINTR) && n < 20);
242 if (!strcmp (pref,
"config_file") || !strcmp (pref,
"plugins_folder")
246 || !strcmp (pref,
"db_address") || !strcmp (pref,
"negot_timeout")
247 || !strcmp (pref,
"force_pubkey_auth")
248 || !strcmp (pref,
"log_whole_attack")
249 || !strcmp (pref,
"log_plugins_name_at_load")
250 || !strcmp (pref,
"nasl_no_signature_check")
251 || !strcmp (pref,
"vendor_version") || !strcmp (pref,
"drop_privileges")
252 || !strcmp (pref,
"nasl_drop_privileges_user")
253 || !strcmp (pref,
"debug_tls") || !strcmp (pref,
"min_free_mem")
254 || !strcmp (pref,
"max_sysload")
256 || !strncmp (pref,
"sys_", 4))
275 if (mode < 0 || mode > 2)
277 g_warning (
"%s: invalid mode %d", __func__, mode);
280 pd = fopen (path, mode == 0 ?
"a" : mode == 1 ?
"r+" :
"w");
283 g_warning (
"%s: Error opening FILE '%s' for script stats: %d - %s",
284 __func__, path, errno, strerror (errno));
291 while ((ch = fgetc (pd)) != EOF)
293 fseek (pd, -1, SEEK_CUR);
295 fprintf (pd,
"%s", buf);
310 GString *data = g_string_new (
"");
311 struct kb_item *stats = NULL, *stats_tmp = NULL;
315 if (!prefs_get (
"report_scripts"))
318 stats = kb_item_get_pattern (kb,
"general/script_stats*");
321 g_string_append_printf (data,
"\"%s\": [", ip);
324 char **spl = g_strsplit (stats_tmp->v_str,
"/", 0);
328 g_string_append_c (data,
',');
330 buf = g_strdup_printf (
"{\"%s\": {\"start\": %s, \"stop\": %s}}", spl[0],
333 g_string_append (data, buf);
337 stats_tmp = stats_tmp->next;
341 g_string_append (data,
"],");
344 g_strdup_printf (
"%s/%s-stats.json", prefs_get (
"report_scripts"),
scan_id);
346 kb_item_free (stats);
349 g_string_free (data, TRUE);
Header file for module plugutils.
Auxiliary structures for scanner.
GHashTable * files_size_translation
GHashTable * files_translation
int is_scanner_only_pref(const char *pref)
static void files_add_size_translation(struct scan_globals *globals, const char *file_hash, const long filesize)
Adds a 'content size' entry for a file sent by the client.
void write_script_stats(const char *buf, const char *path, int mode)
Writes scripts stats into a file.
void write_host_stats(kb_t kb, const char *scan_id, const char *ip)
Reads the script stats from the kb and generate a string in json format to be stored in the disk.
int store_file(struct scan_globals *globals, const char *file, const char *file_hash)
Stores a file type preference in a hash table.
int get_max_hosts_number(void)
int get_max_checks_number(void)
static void files_add_translation(struct scan_globals *globals, const char *file_hash, char *contents)
Adds a 'translation' entry for a file sent by the client.
void wait_for_children1(void)
int process_alive(pid_t pid)