[Openvas-commits] r5782 - in trunk/openvas-manager: . src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Nov 3 14:54:19 CET 2009
Author: mattm
Date: 2009-11-03 14:54:18 +0100 (Tue, 03 Nov 2009)
New Revision: 5782
Modified:
trunk/openvas-manager/ChangeLog
trunk/openvas-manager/src/manage.h
trunk/openvas-manager/src/omp.c
trunk/openvas-manager/src/tasks_sql.h
Log:
Send preference counts with OMP GET_NVT_DETAILS and preferences with
OMP GET_CONFIGS.
* src/tasks_sql.h (nvt_preference_iterator_real_name): Return name anyway
if sscanf fails to match.
(nvt_preference_iterator_nvt, nvt_preference_count): New functions.
* src/manage.h: Update headers.
* src/omp.c (current_int_3): New variable.
(omp_xml_handle_start_element): Add "preferences" attribute to
GET_CONFIGS.
(send_nvt): Send preference count from new arg pref_count.
(omp_xml_handle_end_element): In CLIENT_GET_NVT_DETAILS check type exists
before strcmp and send preference count with each NVT. In
CLIENT_GET_CONFIGS send preferences according to "preferences" attribute.
Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog 2009-11-03 11:50:27 UTC (rev 5781)
+++ trunk/openvas-manager/ChangeLog 2009-11-03 13:54:18 UTC (rev 5782)
@@ -1,3 +1,22 @@
+2009-11-03 Matthew Mundell <matthew.mundell at intevation.de>
+
+ Send preference counts with OMP GET_NVT_DETAILS and preferences with
+ OMP GET_CONFIGS.
+
+ * src/tasks_sql.h (nvt_preference_iterator_real_name): Return name anyway
+ if sscanf fails to match.
+ (nvt_preference_iterator_nvt, nvt_preference_count): New functions.
+
+ * src/manage.h: Update headers.
+
+ * src/omp.c (current_int_3): New variable.
+ (omp_xml_handle_start_element): Add "preferences" attribute to
+ GET_CONFIGS.
+ (send_nvt): Send preference count from new arg pref_count.
+ (omp_xml_handle_end_element): In CLIENT_GET_NVT_DETAILS check type exists
+ before strcmp and send preference count with each NVT. In
+ CLIENT_GET_CONFIGS send preferences according to "preferences" attribute.
+
2009-11-02 Matthew Mundell <matthew.mundell at intevation.de>
Send NVT preferences with OMP GET_NVT_DETAILS.
Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h 2009-11-03 11:50:27 UTC (rev 5781)
+++ trunk/openvas-manager/src/manage.h 2009-11-03 13:54:18 UTC (rev 5782)
@@ -705,6 +705,9 @@
char*
nvt_preference_iterator_type (iterator_t*);
+char*
+nvt_preference_iterator_nvt (iterator_t*);
+
void
init_config_pref_iterator (iterator_t*, const char*, const char*);
@@ -714,6 +717,9 @@
const char*
config_pref_iterator_value (iterator_t*);
+int
+nvt_preference_count (const char *);
+
/* LSC credentials. */
Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c 2009-11-03 11:50:27 UTC (rev 5781)
+++ trunk/openvas-manager/src/omp.c 2009-11-03 13:54:18 UTC (rev 5782)
@@ -253,6 +253,11 @@
int current_int_2;
/**
+ * @brief Generic integer variable for communicating between the callbacks.
+ */
+int current_int_3;
+
+/**
* @brief Buffer of output to the client.
*/
char to_client[TO_CLIENT_BUFFER_SIZE];
@@ -905,6 +910,11 @@
current_int_2 = strcmp (attribute, "descending");
else
current_int_2 = 1;
+ if (find_attribute (attribute_names, attribute_values,
+ "preferences", &attribute))
+ current_int_3 = atoi (attribute);
+ else
+ current_int_3 = 0;
set_client_state (CLIENT_GET_CONFIGS);
}
else if (strcasecmp ("GET_DEPENDENCIES", element_name) == 0)
@@ -1754,13 +1764,14 @@
/**
* @brief Send XML for an NVT.
*
- * @param[in] key The plugin OID.
- * @param[in] details If true, detailed XML, else simple XML.
+ * @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.
*
* @return TRUE if out of space in to_client buffer, else FALSE.
*/
static gboolean
-send_nvt (iterator_t *nvts, int details)
+send_nvt (iterator_t *nvts, int details, int pref_count)
{
const char* oid = nvt_iterator_oid (nvts);
const char* name = nvt_iterator_name (nvts);
@@ -1797,6 +1808,7 @@
"<xrefs>%s</xrefs>"
"<fingerprints>%s</fingerprints>"
"<tags>%s</tags>"
+ "<preference_count>%i</preference_count>"
"<checksum>"
"<algorithm>md5</algorithm>"
// FIX implement
@@ -1815,7 +1827,8 @@
nvt_iterator_bid (nvts),
nvt_iterator_xref (nvts),
nvt_iterator_sign_key_ids (nvts),
- tag_text);
+ tag_text,
+ pref_count);
g_free (copyright_text);
g_free (description_text);
g_free (summary_text);
@@ -2780,7 +2793,7 @@
init_nvt_iterator (&nvts, (nvt_t) 0, NULL, NULL, 1, NULL);
while (next (&nvts))
- if (send_nvt (&nvts, 0))
+ if (send_nvt (&nvts, 0, -1))
{
error_send_to_client (error);
return;
@@ -2855,7 +2868,7 @@
init_nvt_iterator (&nvts, nvt, NULL, NULL, 1, NULL);
while (next (&nvts))
{
- if (send_nvt (&nvts, 1))
+ if (send_nvt (&nvts, 1, -1))
{
error_send_to_client (error);
return;
@@ -2878,7 +2891,7 @@
type = nvt_preference_iterator_type (&prefs);
value = nvt_preference_iterator_config_value
(&prefs, current_name);
- if (strcmp (type, "radio") == 0)
+ if (type && strcmp (type, "radio") == 0)
{
/* Clip off the alternative values. */
char *pos = strchr (value, ';');
@@ -2933,11 +2946,19 @@
/* Attribute sort_field. */
modify_task_value);
while (next (&nvts))
- if (send_nvt (&nvts, 1))
- {
- error_send_to_client (error);
- return;
- }
+ {
+ int pref_count = -1;
+ if (current_name) /* Attribute config. */
+ {
+ const char *nvt_name = nvt_iterator_name (&nvts);
+ pref_count = nvt_preference_count (nvt_name);
+ }
+ if (send_nvt (&nvts, 1, pref_count))
+ {
+ error_send_to_client (error);
+ return;
+ }
+ }
cleanup_iterator (&nvts);
SEND_TO_CLIENT_OR_FAIL ("</get_nvt_details_response>");
@@ -5371,13 +5392,59 @@
* NVT's. */
"<known_nvt_count>"
"%i"
- "</known_nvt_count>"
- "</config>",
+ "</known_nvt_count>",
max_nvt_count,
known_nvt_count);
}
- else
- SENDF_TO_CLIENT_OR_FAIL ("</config>");
+
+ if (current_int_3)
+ {
+ iterator_t prefs;
+
+ /** @todo Similar to block in CLIENT_GET_NVT_DETAILS. */
+
+ /* The "preferences" attribute was true. */
+
+ SEND_TO_CLIENT_OR_FAIL ("<preferences>");
+
+ init_nvt_preference_iterator (&prefs, NULL);
+ while (next (&prefs))
+ {
+ char *real_name, *type, *value, *nvt;
+ real_name
+ = nvt_preference_iterator_real_name (&prefs);
+ type = nvt_preference_iterator_type (&prefs);
+ value = nvt_preference_iterator_config_value
+ (&prefs, config_name);
+ nvt = nvt_preference_iterator_nvt (&prefs);
+ if (type && strcmp (type, "radio") == 0)
+ {
+ /* Clip off the alternative values. */
+ char *pos = strchr (value, ';');
+ if (pos) *pos = '\0';
+ }
+ SENDF_TO_CLIENT_OR_FAIL
+ ("<preference>"
+ "<nvt>%s</nvt>"
+ "<name>%s</name>"
+ "<type>%s</type>"
+ "<value>%s</value>"
+ "</preference>",
+ nvt ? nvt : "",
+ real_name,
+ type,
+ value);
+ free (real_name);
+ free (type);
+ free (value);
+ free (nvt);
+ }
+ cleanup_iterator (&prefs);
+
+ SEND_TO_CLIENT_OR_FAIL ("</preferences>");
+ }
+
+ SENDF_TO_CLIENT_OR_FAIL ("</config>");
}
openvas_free_string_var (¤t_name);
cleanup_iterator (&configs);
Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h 2009-11-03 11:50:27 UTC (rev 5781)
+++ trunk/openvas-manager/src/tasks_sql.h 2009-11-03 13:54:18 UTC (rev 5782)
@@ -5875,7 +5875,7 @@
ret += value_start;
return g_strndup (ret, value_end - value_start);
}
- return NULL;
+ return g_strdup (ret);
}
return NULL;
}
@@ -5901,6 +5901,25 @@
}
char*
+nvt_preference_iterator_nvt (iterator_t* iterator)
+{
+ const char *ret;
+ if (iterator->done) return NULL;
+ ret = (const char*) sqlite3_column_text (iterator->stmt, 0);
+ if (ret)
+ {
+ int type_start = -1, count;
+ count = sscanf (ret, "%*[^[]%n[%*[^]]]:", &type_start);
+ if (count == 0 && type_start > 0)
+ {
+ return g_strndup (ret, type_start);
+ }
+ return NULL;
+ }
+ return NULL;
+}
+
+char*
nvt_preference_iterator_config_value (iterator_t* iterator, const char* config)
{
gchar *quoted_config, *quoted_name, *value;
@@ -5926,6 +5945,25 @@
return NULL;
}
+/**
+ * @brief Get the number preferences available for an NVT.
+ *
+ * @param[in] name Name of NVT.
+ *
+ * @return Number of possible preferences on NVT.
+ */
+int
+nvt_preference_count (const char *name)
+{
+ gchar *quoted_name = sql_quote (name);
+ int ret = sql_int (0, 0,
+ "SELECT COUNT(*) FROM nvt_preferences"
+ " WHERE name LIKE '%s[%%';",
+ quoted_name);
+ g_free (quoted_name);
+ return ret;
+}
+
/* LSC Credentials. */
More information about the Openvas-commits
mailing list