[Openvas-commits] r6174 - in trunk/openvas-administrator: . src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Dec 17 15:47:39 CET 2009
Author: mwiegand
Date: 2009-12-17 15:47:38 +0100 (Thu, 17 Dec 2009)
New Revision: 6174
Modified:
trunk/openvas-administrator/ChangeLog
trunk/openvas-administrator/src/admin.c
trunk/openvas-administrator/src/admin.h
trunk/openvas-administrator/src/oap.c
trunk/openvas-administrator/src/oap.h
trunk/openvas-administrator/src/oapd.c
trunk/openvas-administrator/src/oapd.h
trunk/openvas-administrator/src/openvasad.c
Log:
Added support for retrieving settings from configuration files.
* src/openvas.c (main): Replaced list_all_prefs command with new
get_settings command. Make it clear that the file being handled
contains the scanner settings. Hand the name of the scanner
settings file to the daemon when initializing it.
* src/oapd.c (init_oapd): Updated to handle the additional
parameter.
* src/oapd.h: Updated.
* src/oap.c: Added new client state, fixed sorting of states.
(init_oap): Updated to handle the additional parameter.
(build_settings_xml): New. Function to construct the XML output
for a list of settings.
(oap_xml_handle_start_element): Handle new get_settings element.
(oap_xml_handle_end_element): Handle new get_settings element.
* src/oap.h: Updated.
* src/admin.c: Cleaned up, switched to text output for
settings.
(print_preference): Removed and replaced with print_setting.
(print_setting): New.
(print_preferences_xml): Removed and replaced with
print_settings.
(print_settings): New.
(openvas_admin_list_all_prefs): Removed since functionality has
been moved to openvas-libraries.
* src/admin.h: Updated.
Modified: trunk/openvas-administrator/ChangeLog
===================================================================
--- trunk/openvas-administrator/ChangeLog 2009-12-17 13:58:46 UTC (rev 6173)
+++ trunk/openvas-administrator/ChangeLog 2009-12-17 14:47:38 UTC (rev 6174)
@@ -1,3 +1,38 @@
+2009-12-17 Michael Wiegand <michael.wiegand at intevation.de>
+
+ Added support for retrieving settings from configuration files.
+
+ * src/openvas.c (main): Replaced list_all_prefs command with new
+ get_settings command. Make it clear that the file being handled
+ contains the scanner settings. Hand the name of the scanner
+ settings file to the daemon when initializing it.
+
+ * src/oapd.c (init_oapd): Updated to handle the additional
+ parameter.
+
+ * src/oapd.h: Updated.
+
+ * src/oap.c: Added new client state, fixed sorting of states.
+ (init_oap): Updated to handle the additional parameter.
+ (build_settings_xml): New. Function to construct the XML output
+ for a list of settings.
+ (oap_xml_handle_start_element): Handle new get_settings element.
+ (oap_xml_handle_end_element): Handle new get_settings element.
+
+ * src/oap.h: Updated.
+
+ * src/admin.c: Cleaned up, switched to text output for
+ settings.
+ (print_preference): Removed and replaced with print_setting.
+ (print_setting): New.
+ (print_preferences_xml): Removed and replaced with
+ print_settings.
+ (print_settings): New.
+ (openvas_admin_list_all_prefs): Removed since functionality has
+ been moved to openvas-libraries.
+
+ * src/admin.h: Updated.
+
2009-12-17 Felix Wolfsteller <felix.wolfsteller at intevation.de>
Second step of versioning mechanism change.
Modified: trunk/openvas-administrator/src/admin.c
===================================================================
--- trunk/openvas-administrator/src/admin.c 2009-12-17 13:58:46 UTC (rev 6173)
+++ trunk/openvas-administrator/src/admin.c 2009-12-17 14:47:38 UTC (rev 6174)
@@ -57,22 +57,21 @@
/** @todo Add contention handling at this level. */
/**
- * @brief Convenience function to produce XML output from key/value pairs of
- * preferences.
+ * @brief Convenience function to produce text output from key/value pairs of
+ * settings.
* This function is used by g_hash_table_foreach().
*
* @param key The key.
* @param value The value corresponding to the key.
- * @param user_data User data passed to g_hash_table_foreach().
+ * @param user_data A GString object to which the output should be appended.
*/
static void
-print_preference (void * key, void * value, void * user_data)
+print_setting (void * key, void * value, void * user_data)
{
- gchar *xml;
- xml = g_markup_printf_escaped ("<preference name=\"%s\">%s</preference>",
- (gchar *) key, (gchar *) value);
- g_string_append ((GString *) user_data, xml);
- g_free (xml);
+ gchar *text;
+ text = g_strdup_printf ("%s=%s\n", (gchar *) key, (gchar *) value);
+ g_string_append ((GString *) user_data, text);
+ g_free (text);
}
/**
@@ -255,76 +254,23 @@
}
}
-/**
- * @brief Returns a HashTable of preferences retrieved from a given openvasd
- * configuration file.
- *
- * @param config_file The complete name of the configuration file.
- *
- * @return A pointer to a GHashTable containing key/value pairs of all
- * preferences found in the file or NULL if the file contents could not be
- * accessed. The HashTable should be freed with g_hash_table_destroy() when no
- * longer needed.
- */
-GHashTable *
-openvas_admin_list_all_prefs (const gchar * config_file)
-{
- GError *error = NULL;
- GKeyFile *config_key_file = g_key_file_new ();
- gchar **config_keys = NULL;
-
- if (g_key_file_load_from_file (config_key_file, config_file, G_KEY_FILE_NONE, &error))
- {
- GHashTable *prefs = g_hash_table_new (NULL, NULL);
- gsize len;
- int i;
-
- config_keys = g_key_file_get_keys (config_key_file, "OpenVAS", &len, &error);
- for (i = 0; i < g_strv_length (config_keys); i++)
- {
- g_hash_table_insert (prefs,
- g_strdup (config_keys[i]),
- g_key_file_get_value (config_key_file, "OpenVAS",
- config_keys[i], &error));
- }
- g_strfreev (config_keys);
- g_key_file_free (config_key_file);
- g_error_free (error);
- return prefs;
- }
- else
- {
- g_warning ("%s", error->message);
- g_key_file_free (config_key_file);
- g_error_free (error);
- return NULL;
- }
-}
-
/** @todo Get the 200's in these commands from libs (STATUS_OK). */
/**
- * @brief Produces an ocp_response element for a list_all_prefs request from a
- * GHashTable of preferences.
+ * @brief Produces a newline separated list from a GHashTable of settings.
*
- * @param preferences A pointer to a GHashTable containing preferences.
+ * @param preferences A pointer to a GHashTable containing settings.
*
- * @return A pointer to a GString containig the ocp_response element.
+ * @return A pointer to a GString containing the settings list.
*/
GString *
-print_preferences_xml (GHashTable * preferences)
+print_settings (GHashTable * settings)
{
- GString *response = NULL;
- if (preferences)
+ GString *response = g_string_new ("");
+ if (settings)
{
- response = g_string_new ("<ocp_response command=\"list_all_prefs\" status=\"200\"><preferences>");
- g_hash_table_foreach (preferences, print_preference, response);
- response = g_string_append (response, "</preferences></ocp_response>");
+ g_hash_table_foreach (settings, print_setting, response);
}
- else
- {
- response = g_string_new ("<ocp_response command=\"list_all_prefs\" status=\"200\"><preferences/></ocp_response>");
- }
return response;
}
Modified: trunk/openvas-administrator/src/admin.h
===================================================================
--- trunk/openvas-administrator/src/admin.h 2009-12-17 13:58:46 UTC (rev 6173)
+++ trunk/openvas-administrator/src/admin.h 2009-12-17 14:47:38 UTC (rev 6174)
@@ -29,7 +29,6 @@
#include <glib.h>
GSList *openvas_admin_list_users (const gchar *);
-GHashTable *openvas_admin_list_all_prefs (const gchar *);
int openvas_admin_add_user (const gchar *, const gchar *, const gchar *,
const gchar *);
int openvas_admin_remove_user (const gchar *, const gchar *);
@@ -44,7 +43,7 @@
gboolean openvasad_remove_lockfile (void);
gboolean openvasad_currently_syncing (void);
-GString *print_preferences_xml (GHashTable *);
+GString *print_settings (GHashTable *);
GString *print_users_xml (GSList *);
GString *print_users_text (GSList *);
Modified: trunk/openvas-administrator/src/oap.c
===================================================================
--- trunk/openvas-administrator/src/oap.c 2009-12-17 13:58:46 UTC (rev 6173)
+++ trunk/openvas-administrator/src/oap.c 2009-12-17 14:47:38 UTC (rev 6174)
@@ -43,6 +43,7 @@
#include <string.h>
#include <openvas/base/openvas_string.h> /* for openvas_append_text */
+#include <openvas/base/settings.h>
#include <openvas/openvas_auth.h>
#include <openvas/openvas_logging.h>
@@ -66,6 +67,11 @@
*/
static const gchar *sync_script = NULL;
+/**
+ * @brief The scanner configuration file for this daemon.
+ */
+static const gchar *scanner_config_file = NULL;
+
/* Credentials. */
@@ -140,6 +146,28 @@
}
+/* Convenience functions. */
+
+/**
+ * @brief Convenience function to produce XML output from key/value pairs of
+ * settings.
+ * This function is used by g_hash_table_foreach().
+ *
+ * @param key The key.
+ * @param value The value corresponding to the key.
+ * @param xml_string GString where the resulting XML will be written.
+ */
+static void
+build_settings_xml (void * key, void * value, void * xml_string)
+{
+ gchar *xml;
+ xml = g_markup_printf_escaped ("<setting name=\"%s\">%s</setting>",
+ (gchar *) key, (gchar *) value);
+ g_string_append ((GString *) xml_string, xml);
+ g_free (xml);
+}
+
+
/* Authenticate. */
/**
@@ -374,11 +402,12 @@
CLIENT_CREDENTIALS_PASSWORD,
CLIENT_CREDENTIALS_USERNAME,
CLIENT_DELETE_USER,
+ CLIENT_DESCRIBE_FEED,
+ CLIENT_GET_SETTINGS,
CLIENT_GET_USERS,
CLIENT_HELP,
- CLIENT_VERSION,
- CLIENT_DESCRIBE_FEED,
- CLIENT_SYNC_FEED
+ CLIENT_SYNC_FEED,
+ CLIENT_VERSION
} client_state_t;
/**
@@ -746,6 +775,8 @@
set_client_state (CLIENT_DESCRIBE_FEED);
else if (strcasecmp ("SYNC_FEED", element_name) == 0)
set_client_state (CLIENT_SYNC_FEED);
+ else if (strcasecmp ("GET_SETTINGS", element_name) == 0)
+ set_client_state (CLIENT_GET_SETTINGS);
else
{
if (send_to_client (XML_ERROR_SYNTAX ("oap", "Bogus command name")))
@@ -1080,6 +1111,36 @@
break;
}
+ case CLIENT_GET_SETTINGS:
+ {
+ GHashTable *scanner_settings_hash_table = get_all_settings
+ (scanner_config_file, "Misc");
+
+ if (scanner_settings_hash_table != NULL)
+ {
+ GString *scanner_settings = g_string_new ("");
+ g_hash_table_foreach (scanner_settings_hash_table,
+ build_settings_xml, scanner_settings);
+ SEND_TO_CLIENT_OR_FAIL ("<get_settings_response"
+ " status=\"" STATUS_OK "\""
+ " status_text=\"" STATUS_OK_TEXT "\">");
+ SENDF_TO_CLIENT_OR_FAIL ("<scanner_settings sourcefile=\"%s\">",
+ scanner_config_file);
+ SEND_TO_CLIENT_OR_FAIL (scanner_settings->str);
+ SEND_TO_CLIENT_OR_FAIL ("</scanner_settings>");
+
+ SEND_TO_CLIENT_OR_FAIL ("</get_settings_response>");
+ g_string_free (scanner_settings, TRUE);
+ g_hash_table_destroy (scanner_settings_hash_table);
+ }
+ else
+ {
+ SEND_TO_CLIENT_OR_FAIL (XML_INTERNAL_ERROR ("get_settings"));
+ }
+ set_client_state (CLIENT_AUTHENTIC);
+ break;
+ }
+
case CLIENT_CREATE_USER:
{
assert (strcasecmp ("CREATE_USER", element_name) == 0);
@@ -1240,21 +1301,25 @@
* @param[in] users_directory Directory containing user info.
* @param[in] synchronization_script The script to use for feed
* synchronization.
+ * @param[in] configuration_file Scanner Configuration file.
*
* @return 0 success, -1 error.
*/
int
init_oap (GSList *log_config, const gchar *users_directory,
- const gchar *synchronization_script)
+ const gchar *synchronization_script,
+ const gchar *configuration_file)
{
if (users_directory == NULL) return -1;
if (synchronization_script == NULL) return -1;
+ if (configuration_file == NULL) return -1;
g_log_set_handler (G_LOG_DOMAIN,
ALL_LOG_LEVELS,
(GLogFunc) openvas_log_func,
log_config);
users_dir = users_directory;
sync_script = synchronization_script;
+ scanner_config_file = configuration_file;
current_credentials.username = NULL;
current_credentials.password = NULL;
return 0;
Modified: trunk/openvas-administrator/src/oap.h
===================================================================
--- trunk/openvas-administrator/src/oap.h 2009-12-17 13:58:46 UTC (rev 6173)
+++ trunk/openvas-administrator/src/oap.h 2009-12-17 14:47:38 UTC (rev 6174)
@@ -36,7 +36,7 @@
#define TO_CLIENT_BUFFER_SIZE 26214400
int
-init_oap (GSList*, const gchar*, const gchar*);
+init_oap (GSList*, const gchar*, const gchar*, const gchar*);
void
init_oap_process ();
Modified: trunk/openvas-administrator/src/oapd.c
===================================================================
--- trunk/openvas-administrator/src/oapd.c 2009-12-17 13:58:46 UTC (rev 6173)
+++ trunk/openvas-administrator/src/oapd.c 2009-12-17 14:47:38 UTC (rev 6174)
@@ -81,14 +81,17 @@
* @param[in] users_dir Directory containing user information.
* @param[in] synchronization_script The script to use for feed
* synchronization.
+ * @param[in] configuration_file Configuration file.
*
* @return 0 success, -1 error, -2 database is wrong version.
*/
int
init_oapd (GSList *log_config, const gchar *users_dir,
- const gchar *synchronization_script)
+ const gchar *synchronization_script,
+ const gchar *configuration_file)
{
- return init_oap (log_config, users_dir, synchronization_script);
+ return init_oap (log_config, users_dir, synchronization_script,
+ configuration_file);
}
/**
Modified: trunk/openvas-administrator/src/oapd.h
===================================================================
--- trunk/openvas-administrator/src/oapd.h 2009-12-17 13:58:46 UTC (rev 6173)
+++ trunk/openvas-administrator/src/oapd.h 2009-12-17 14:47:38 UTC (rev 6174)
@@ -30,7 +30,7 @@
#include <glib.h>
#include <gnutls/gnutls.h>
-int init_oapd (GSList*, const gchar*, const gchar*);
+int init_oapd (GSList*, const gchar*, const gchar*, const gchar*);
int serve_oap (gnutls_session_t*, int, gnutls_certificate_credentials_t*);
Modified: trunk/openvas-administrator/src/openvasad.c
===================================================================
--- trunk/openvas-administrator/src/openvasad.c 2009-12-17 13:58:46 UTC (rev 6173)
+++ trunk/openvas-administrator/src/openvasad.c 2009-12-17 14:47:38 UTC (rev 6174)
@@ -67,6 +67,7 @@
#include <openvas_server.h>
#include <openvas_auth.h>
#include <openvas/base/pidfile.h>
+#include <openvas/base/settings.h>
#ifdef S_SPLINT_S
#include "splint.h"
@@ -426,7 +427,7 @@
static gchar *administrator_port_string = NULL;
static gchar *command = NULL;
static const gchar *users_dir = NULL;
- static const gchar *config_file = NULL;
+ static const gchar *scanner_config_file = NULL;
static const gchar *name = NULL;
static const gchar *role = NULL;
static const gchar *password = NULL;
@@ -467,8 +468,8 @@
{ "users-dir", 0, 0, G_OPTION_ARG_FILENAME, &users_dir,
"Directory containing the OpenVAS user data (default: " OPENVAS_USERS_DIR ")",
"<users-dir>" },
- { "config-file", 0, 0, G_OPTION_ARG_FILENAME, &config_file,
- "File containing the OpenVAS configuration (default: " OPENVAS_CONFIG_FILE ")",
+ { "scanner-config-file", 0, 0, G_OPTION_ARG_FILENAME, &scanner_config_file,
+ "File containing the OpenVAS-Scanner configuration (default: " OPENVAS_CONFIG_FILE ")",
"<config-file>" },
#endif /* S_SPLINT_S */
{ "sync-script", 's', 0, G_OPTION_ARG_FILENAME, &sync_script,
@@ -517,13 +518,13 @@
tracef (" Using directory %s as the users directory\n", users_dir);
- if (config_file == NULL)
+ if (scanner_config_file == NULL)
{
- tracef (" config_file not set, setting to default\n");
- config_file = OPENVAS_CONFIG_FILE;
+ tracef (" scanner_config_file not set, setting to default\n");
+ scanner_config_file = OPENVAS_CONFIG_FILE;
}
- tracef (" Using %s as the config file\n", config_file);
+ tracef (" Using %s as the scanner config file\n", scanner_config_file);
/* account overrides name and password. If an account is specified, the
* username and password are extracted and copied into name and password
@@ -552,13 +553,6 @@
response = print_users_text (user_list);
g_slist_free (user_list);
}
- else if (g_strcasecmp (command, "list_all_prefs") == 0)
- {
- GHashTable *all_prefs = openvas_admin_list_all_prefs (config_file);
- g_string_free (response, TRUE);
- response = print_preferences_xml (all_prefs);
- g_hash_table_destroy (all_prefs);
- }
/** @todo For consistency with protocol, rename to "create_user". */
else if (g_strcasecmp (command, "add_user") == 0)
{
@@ -749,6 +743,13 @@
exit (EXIT_FAILURE);
}
}
+ else if (g_strcasecmp (command, "get_settings") == 0)
+ {
+ GHashTable *scanner_settings = get_all_settings (scanner_config_file, "Misc");
+ g_string_free (response, TRUE);
+ response = print_settings (scanner_settings);
+ g_hash_table_destroy (scanner_settings);
+ }
else
{
g_string_printf (response,
@@ -791,13 +792,13 @@
tracef (" Using %s as the synchronization script\n", sync_script);
- if (config_file == NULL)
+ if (scanner_config_file == NULL)
{
- tracef (" config_file not set, setting to default\n");
- config_file = OPENVAS_CONFIG_FILE;
+ tracef (" scanner_config_file not set, setting to default\n");
+ scanner_config_file = OPENVAS_CONFIG_FILE;
}
- tracef (" Using %s as the config file\n", config_file);
+ tracef (" Using %s as the scanner config file\n", scanner_config_file);
if (administrator_port_string)
{
@@ -848,7 +849,7 @@
/* Initialise OAP daemon. */
- switch (init_oapd (log_config, users_dir, sync_script))
+ switch (init_oapd (log_config, users_dir, sync_script, scanner_config_file))
{
case 0:
break;
More information about the Openvas-commits
mailing list