prefs.c
Go to the documentation of this file.
/* SPDX-FileCopyrightText: 2014-2023 Greenbone AG
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "prefs.h"
#include "settings.h" /* for init_settings_iterator_from_file */
#include <glib.h> /* for gchar */
#include <stdio.h> /* for printf() */
#include <stdlib.h> /* for atoi() */
#include <string.h> /* for strlen() */
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "libgvm base"
static GHashTable *global_prefs = NULL;
void
prefs_set (const gchar *, const gchar *);
static void
prefs_init (void)
{
if (global_prefs)
g_hash_table_destroy (global_prefs);
global_prefs =
g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
prefs_set ("cgi_path", "/cgi-bin:/scripts");
prefs_set ("checks_read_timeout", "5");
prefs_set ("unscanned_closed", "yes");
prefs_set ("unscanned_closed_udp", "yes");
prefs_set ("timeout_retry", "3");
prefs_set ("expand_vhosts", "yes");
prefs_set ("test_empty_vhost", "no");
prefs_set ("open_sock_max_attempts", "5");
prefs_set ("time_between_request", "0");
prefs_set ("nasl_no_signature_check", "yes");
prefs_set ("max_hosts", "30");
prefs_set ("max_checks", "10");
prefs_set ("log_whole_attack", "no");
prefs_set ("log_plugins_name_at_load", "no");
prefs_set ("optimize_test", "yes");
prefs_set ("non_simult_ports", "139, 445, 3389, Services/irc");
prefs_set ("safe_checks", "yes");
prefs_set ("auto_enable_dependencies", "yes");
prefs_set ("drop_privileges", "no");
prefs_set ("report_host_details", "yes");
prefs_set ("vendor_version", "\0");
prefs_set ("test_alive_hosts_only", "yes");
prefs_set ("test_alive_wait_timeout", "3");
prefs_set ("debug_tls", "0");
prefs_set ("allow_simultaneous_ips", "yes");
}
GHashTable *
preferences_get (void)
{
if (!global_prefs)
prefs_init ();
return global_prefs;
}
const gchar *
prefs_get (const gchar *key)
{
if (!global_prefs)
prefs_init ();
return g_hash_table_lookup (global_prefs, key);
}
int
prefs_get_bool (const gchar *key)
{
gchar *str;
if (!global_prefs)
prefs_init ();
str = g_hash_table_lookup (global_prefs, key);
if (str && !strcmp (str, "yes"))
return 1;
return 0;
}
void
prefs_set (const gchar *key, const gchar *value)
{
if (!global_prefs)
prefs_init ();
g_hash_table_insert (global_prefs, g_strdup (key), g_strdup (value));
}
void
prefs_config (const char *config)
{
settings_iterator_t settings;
if (!global_prefs)
prefs_init ();
if (!init_settings_iterator_from_file (&settings, config, "Misc"))
{
while (settings_iterator_next (&settings))
{
gchar *value;
value = settings_iterator_value (&settings);
prefs_set (settings_iterator_name (&settings), value);
g_free (value);
}
cleanup_settings_iterator (&settings);
}
prefs_set ("config_file", config);
}
void
prefs_dump (void)
{
void *name, *value;
GHashTableIter iter;
if (global_prefs)
{
g_hash_table_iter_init (&iter, global_prefs);
while (g_hash_table_iter_next (&iter, &name, &value))
{
printf ("%s = %s\n", (char *) name, (char *) value);
}
}
}
prefs_config
void prefs_config(const char *config)
Apply the configs from given file as preferences.
Definition prefs.c:156
prefs_get_bool
int prefs_get_bool(const gchar *key)
Get a boolean expression of a preference value via a key.
Definition prefs.c:119
prefs_init
static void prefs_init(void)
Initializes the preferences structure. If it was already initialized, remove old settings and start f...
Definition prefs.c:40
prefs_get
const gchar * prefs_get(const gchar *key)
Get a string preference value via a key.
Definition prefs.c:99
global_prefs
static GHashTable * global_prefs
Definition prefs.c:29
preferences_get
GHashTable * preferences_get(void)
Get the pointer to the global preferences structure. Eventually this function should not be used anyw...
Definition prefs.c:81
prefs_set
void prefs_set(const gchar *, const gchar *)
Set a string preference value via a key.
Definition prefs.c:142
prefs_dump
void prefs_dump(void)
Dump the preferences to stdout.
Definition prefs.c:184
prefs.h
Protos and data structures for NVT Information data sets.
settings_iterator_next
gboolean settings_iterator_next(settings_iterator_t *iterator)
Increment an iterator.
Definition settings.c:150
cleanup_settings_iterator
void cleanup_settings_iterator(settings_iterator_t *iterator)
Cleanup a settings iterator.
Definition settings.c:136
init_settings_iterator_from_file
int init_settings_iterator_from_file(settings_iterator_t *iterator, const gchar *filename, const gchar *group)
Initialise a settings iterator from a file.
Definition settings.c:98
settings_iterator_value
gchar * settings_iterator_value(settings_iterator_t *iterator)
Get the value from a settings iterator.
Definition settings.c:179
settings_iterator_name
const gchar * settings_iterator_name(settings_iterator_t *iterator)
Get the name from a settings iterator.
Definition settings.c:166
settings.h
Protos and data structures for configuration file management.
settings_iterator_t
Struct holding options to iterate over a GKeyFile.
Definition settings.h:36