[Openvas-commits] r5968 - in trunk/openvas-manager: . src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Nov 25 14:53:12 CET 2009
Author: mattm
Date: 2009-11-25 14:53:10 +0100 (Wed, 25 Nov 2009)
New Revision: 5968
Modified:
trunk/openvas-manager/ChangeLog
trunk/openvas-manager/src/omp.c
trunk/openvas-manager/src/tasks_sql.h
Log:
Add support for per-NVT timeout preferences.
* src/omp.c (send_nvt): Add timeout arg. Update callers.
(omp_xml_handle_end_element): In CLIENT_GET_NVT_DETAILS and
CLIENT_GET_NVT_DETAILS send TIMEOUT in PREFERENCES and NVT. In
CLIENT_MODIFY_CONFIG_PREFERENCE_VALUE initialise the string that will
hold the value, so that it is always some string when the OMP caller
sends a VALUE and only NULL if the caller leaves out VALUE entirely.
* src/tasks_sql.h (config_nvt_timeout): New function.
(manage_set_config_preference): Enable the preference removal section.
Remove type decoration in removal section for scanner preferences.
Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog 2009-11-25 12:02:13 UTC (rev 5967)
+++ trunk/openvas-manager/ChangeLog 2009-11-25 13:53:10 UTC (rev 5968)
@@ -1,3 +1,18 @@
+2009-11-25 Matthew Mundell <matthew.mundell at intevation.de>
+
+ Add support for per-NVT timeout preferences.
+
+ * src/omp.c (send_nvt): Add timeout arg. Update callers.
+ (omp_xml_handle_end_element): In CLIENT_GET_NVT_DETAILS and
+ CLIENT_GET_NVT_DETAILS send TIMEOUT in PREFERENCES and NVT. In
+ CLIENT_MODIFY_CONFIG_PREFERENCE_VALUE initialise the string that will
+ hold the value, so that it is always some string when the OMP caller
+ sends a VALUE and only NULL if the caller leaves out VALUE entirely.
+
+ * src/tasks_sql.h (config_nvt_timeout): New function.
+ (manage_set_config_preference): Enable the preference removal section.
+ Remove type decoration in removal section for scanner preferences.
+
2009-11-25 Felix Wolfsteller <felix.wolfsteller at intevation.de>
Added stubs for dependency checks during configure/build time.
Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c 2009-11-25 12:02:13 UTC (rev 5967)
+++ trunk/openvas-manager/src/omp.c 2009-11-25 13:53:10 UTC (rev 5968)
@@ -2117,11 +2117,12 @@
* @param[in] key The plugin OID.
* @param[in] details If true, detailed XML, else simple XML.
* @param[in] pref_count Preference count. Used if details is true.
+ * @param[in] timeout Timeout. Used if details is true.
*
* @return TRUE if out of space in to_client buffer, else FALSE.
*/
static gboolean
-send_nvt (iterator_t *nvts, int details, int pref_count)
+send_nvt (iterator_t *nvts, int details, int pref_count, const char *timeout)
{
const char* oid = nvt_iterator_oid (nvts);
const char* name = nvt_iterator_name (nvts);
@@ -2159,6 +2160,7 @@
"<fingerprints>%s</fingerprints>"
"<tags>%s</tags>"
"<preference_count>%i</preference_count>"
+ "<timeout>%s</timeout>"
"<checksum>"
"<algorithm>md5</algorithm>"
// FIX implement
@@ -2178,7 +2180,8 @@
nvt_iterator_xref (nvts),
nvt_iterator_sign_key_ids (nvts),
tag_text,
- pref_count);
+ pref_count,
+ timeout ? timeout : "");
g_free (copyright_text);
g_free (description_text);
g_free (summary_text);
@@ -3229,7 +3232,7 @@
init_nvt_iterator (&nvts, (nvt_t) 0, NULL, NULL, 1, NULL);
while (next (&nvts))
- if (send_nvt (&nvts, 0, -1))
+ if (send_nvt (&nvts, 0, -1, NULL))
{
error_send_to_client (error);
return;
@@ -3304,7 +3307,14 @@
init_nvt_iterator (&nvts, nvt, NULL, NULL, 1, NULL);
while (next (&nvts))
{
- if (send_nvt (&nvts, 1, -1))
+ char *timeout = NULL;
+
+ if (current_name) /* Attribute config. */
+ timeout = config_nvt_timeout (current_name,
+ nvt_iterator_oid
+ (&nvts));
+
+ if (send_nvt (&nvts, 1, -1, timeout))
{
error_send_to_client (error);
return;
@@ -3316,7 +3326,10 @@
/* Send the preferences for the NVT. */
- SEND_TO_CLIENT_OR_FAIL ("<preferences>");
+ SENDF_TO_CLIENT_OR_FAIL ("<preferences>"
+ "<timeout>%s</timeout>",
+ timeout ? timeout : "");
+ free (timeout);
init_nvt_preference_iterator (&prefs, nvt_name);
while (next (&prefs))
@@ -3375,7 +3388,7 @@
SEND_TO_CLIENT_OR_FAIL ("</preferences>");
}
- }
+ }
cleanup_iterator (&nvts);
SEND_TO_CLIENT_OR_FAIL ("</get_nvt_details_response>");
@@ -3408,13 +3421,20 @@
while (next (&nvts))
{
int pref_count = -1;
+ char *timeout = NULL;
+
+ if (current_name) /* Attribute config. */
+ timeout = config_nvt_timeout (current_name,
+ nvt_iterator_oid
+ (&nvts));
+
if (current_name /* Attribute config. */
|| current_format) /* Attribute family. */
{
const char *nvt_name = nvt_iterator_name (&nvts);
pref_count = nvt_preference_count (nvt_name);
}
- if (send_nvt (&nvts, 1, pref_count))
+ if (send_nvt (&nvts, 1, pref_count, timeout))
{
error_send_to_client (error);
return;
@@ -4717,6 +4737,8 @@
break;
case CLIENT_MODIFY_CONFIG_PREFERENCE_VALUE:
assert (strcasecmp ("VALUE", element_name) == 0);
+ /* Init, so it's the empty string when the value is empty. */
+ openvas_append_string (&modify_task_value, "");
set_client_state (CLIENT_MODIFY_CONFIG_PREFERENCE);
break;
Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h 2009-11-25 12:02:13 UTC (rev 5967)
+++ trunk/openvas-manager/src/tasks_sql.h 2009-11-25 13:53:10 UTC (rev 5968)
@@ -4942,6 +4942,31 @@
}
/**
+ * @brief Get the timeout value for an NVT in a config.
+ *
+ * @param[in] config Config name.
+ * @param[in] oid ID of NVT.
+ *
+ * @return Newly allocated timeout if set for the NVT, else NULL.
+ */
+char *
+config_nvt_timeout (const char *config, const char *oid)
+{
+ char *ret;
+ gchar *quoted_config = sql_quote (config);
+ ret = sql_string (0, 0,
+ "SELECT value FROM config_preferences"
+ " WHERE config ="
+ " (SELECT ROWID FROM configs where name = '%s')"
+ " AND type = 'SERVER_PREFS'"
+ " AND name = 'timeout.%s';",
+ quoted_config,
+ oid);
+ g_free (quoted_config);
+ return ret;
+}
+
+/**
* @brief Exclude or include an array of NVTs in a config.
*
* @param[in] config_name Config name.
@@ -5778,13 +5803,19 @@
quoted_config = sql_quote (config);
quoted_name = sql_quote (name);
-#if 0
- /**
- * @todo The OMP parsing keeps value_64 NULL when VALUE is empty, so do
- * this some other way. */
if (value_64 == NULL)
{
- if (nvt == NULL) return -1;
+ int end = -1;
+
+ /* scanner[scanner]:Timeout */
+ count = sscanf (name, "%*[^[][scanner]:%n", &end);
+ if (count == 0 && end > 0)
+ {
+ /* A scanner preference. Remove type decoration from name. */
+ g_free (quoted_name);
+ quoted_name = sql_quote (name + end);
+ }
+
sql ("DELETE FROM config_preferences"
" WHERE config = (SELECT ROWID FROM configs WHERE name = '%s')"
" AND name = '%s';",
@@ -5794,9 +5825,8 @@
g_free (quoted_name);
return 0;
}
-#endif
- if (value_64 && strlen (value_64))
+ if (strlen (value_64))
{
gsize value_len;
value = (gchar*) g_base64_decode (value_64, &value_len);
More information about the Openvas-commits
mailing list