[Openvas-commits] r5772 - in trunk/openvas-manager: . src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sat Oct 31 22:44:18 CET 2009
Author: mattm
Date: 2009-10-31 22:44:16 +0100 (Sat, 31 Oct 2009)
New Revision: 5772
Modified:
trunk/openvas-manager/ChangeLog
trunk/openvas-manager/src/manage.c
trunk/openvas-manager/src/manage.h
trunk/openvas-manager/src/omp.c
trunk/openvas-manager/src/tasks_sql.h
Log:
Add config and family attributes to OMP GET_NVT_DETAILS, for getting
NVT's in one family for a config.
* src/tasks_sql.h (select_config_nvts): New function.
(init_nvt_iterator): Add args for requesting from a family in a config
only. Update all callers.
* src/manage.h: Update header.
* src/manage.c: Update call to init_nvt_iterator.
* src/omp.c (omp_xml_handle_start_element, omp_xml_handle_end_element):
Add config and family attributes to GET_NVT_DETAILS, to limit the list of
NVT's.
Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog 2009-10-31 19:02:01 UTC (rev 5771)
+++ trunk/openvas-manager/ChangeLog 2009-10-31 21:44:16 UTC (rev 5772)
@@ -1,5 +1,22 @@
2009-10-31 Matthew Mundell <matthew.mundell at intevation.de>
+ Add config and family attributes to OMP GET_NVT_DETAILS, for getting
+ NVT's in one family for a config.
+
+ * src/tasks_sql.h (select_config_nvts): New function.
+ (init_nvt_iterator): Add args for requesting from a family in a config
+ only. Update all callers.
+
+ * src/manage.h: Update header.
+
+ * src/manage.c: Update call to init_nvt_iterator.
+
+ * src/omp.c (omp_xml_handle_start_element, omp_xml_handle_end_element):
+ Add config and family attributes to GET_NVT_DETAILS, to limit the list of
+ NVT's.
+
+2009-10-31 Matthew Mundell <matthew.mundell at intevation.de>
+
* src/tasks_sql.h: Correct revision number in comment.
2009-10-31 Matthew Mundell <matthew.mundell at intevation.de>
Modified: trunk/openvas-manager/src/manage.c
===================================================================
--- trunk/openvas-manager/src/manage.c 2009-10-31 19:02:01 UTC (rev 5771)
+++ trunk/openvas-manager/src/manage.c 2009-10-31 21:44:16 UTC (rev 5772)
@@ -477,7 +477,7 @@
gboolean first = TRUE;
plugins = g_string_new ("");
- init_nvt_iterator (&nvts, (nvt_t) 0);
+ init_nvt_iterator (&nvts, (nvt_t) 0, NULL, NULL);
while (next (&nvts))
{
if (first)
Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h 2009-10-31 19:02:01 UTC (rev 5771)
+++ trunk/openvas-manager/src/manage.h 2009-10-31 21:44:16 UTC (rev 5772)
@@ -606,7 +606,7 @@
find_nvt (const char*, nvt_t*);
void
-init_nvt_iterator (iterator_t*, nvt_t);
+init_nvt_iterator (iterator_t*, nvt_t, const char*, const char*);
const char*
nvt_iterator_oid (iterator_t*);
Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c 2009-10-31 19:02:01 UTC (rev 5771)
+++ trunk/openvas-manager/src/omp.c 2009-10-31 21:44:16 UTC (rev 5772)
@@ -928,6 +928,12 @@
if (find_attribute (attribute_names, attribute_values,
"oid", &attribute))
openvas_append_string (¤t_uuid, attribute);
+ if (find_attribute (attribute_names, attribute_values,
+ "config", &attribute))
+ openvas_append_string (¤t_name, attribute);
+ if (find_attribute (attribute_names, attribute_values,
+ "family", &attribute))
+ openvas_append_string (¤t_format, attribute);
set_client_state (CLIENT_GET_NVT_DETAILS);
}
else if (strcasecmp ("GET_PREFERENCES", element_name) == 0)
@@ -2729,7 +2735,7 @@
free (md5sum);
SEND_TO_CLIENT_OR_FAIL ("</feed_checksum>");
- init_nvt_iterator (&nvts, (nvt_t) 0);
+ init_nvt_iterator (&nvts, (nvt_t) 0, NULL, NULL);
while (next (&nvts))
if (send_nvt (&nvts, 0))
{
@@ -2803,7 +2809,7 @@
" status=\"" STATUS_OK "\""
" status_text=\"" STATUS_OK_TEXT "\">");
- init_nvt_iterator (&nvts, nvt);
+ init_nvt_iterator (&nvts, nvt, NULL, NULL);
while (next (&nvts))
if (send_nvt (&nvts, 1))
{
@@ -2831,7 +2837,10 @@
free (md5sum);
SEND_TO_CLIENT_OR_FAIL ("</feed_checksum>");
- init_nvt_iterator (&nvts, (nvt_t) 0);
+ init_nvt_iterator (&nvts,
+ (nvt_t) 0,
+ current_name, /* Attribute config. */
+ current_format); /* Attribute family. */
while (next (&nvts))
if (send_nvt (&nvts, 1))
{
Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h 2009-10-31 19:02:01 UTC (rev 5771)
+++ trunk/openvas-manager/src/tasks_sql.h 2009-10-31 21:44:16 UTC (rev 5772)
@@ -91,6 +91,9 @@
static void
set_target_hosts (const char *, const char *);
+static gchar*
+select_config_nvts (const char*, const char*);
+
/* Variables. */
@@ -433,6 +436,8 @@
const char* tail;
sqlite3_stmt* stmt;
+ tracef (" sql: %s\n", sql);
+
iterator->done = FALSE;
while (1)
{
@@ -677,7 +682,7 @@
* may be a redundant conversion, as SQLite may have converted these
* values automatically in each query anyway. */
- init_nvt_iterator (&nvts, (nvt_t) 0);
+ init_nvt_iterator (&nvts, (nvt_t) 0, NULL, NULL);
while (next (&nvts))
{
int category;
@@ -2105,7 +2110,7 @@
nvti_cache = nvtis_new ();
- init_nvt_iterator (&nvts, (nvt_t) 0);
+ init_nvt_iterator (&nvts, (nvt_t) 0, NULL, NULL);
while (next (&nvts))
{
nvti_t *nvti = nvti_new ();
@@ -2628,7 +2633,7 @@
{
iterator_t nvts;
- init_nvt_iterator (&nvts, (nvt_t) 0);
+ init_nvt_iterator (&nvts, (nvt_t) 0, NULL, NULL);
while (next (&nvts))
g_string_append_printf (buffer,
" %s = yes\n",
@@ -5131,9 +5136,13 @@
*
* @param[in] iterator Iterator.
* @param[in] nvt NVT to iterate over, all if 0.
+ * @param[in] config Config to limit selection to. NULL for all NVTs.
+ * Overridden by \arg nvt.
+ * @param[in] family Family to limit selection to, if config given.
*/
void
-init_nvt_iterator (iterator_t* iterator, nvt_t nvt)
+init_nvt_iterator (iterator_t* iterator, nvt_t nvt, const char* config,
+ const char* family)
{
if (nvt)
{
@@ -5146,6 +5155,23 @@
init_iterator (iterator, sql);
g_free (sql);
}
+ else if (config)
+ {
+ gchar* sql;
+ if (family == NULL) abort ();
+ sql = select_config_nvts (config, family);
+ if (sql)
+ {
+ init_iterator (iterator, sql);
+ g_free (sql);
+ }
+ else
+ init_iterator (iterator,
+ "SELECT oid, version, name, summary, description,"
+ " copyright, cve, bid, xref, tag, sign_key_ids,"
+ " category, family"
+ " FROM nvts LIMIT 0;");
+ }
else
init_iterator (iterator, "SELECT oid, version, name, summary, description,"
" copyright, cve, bid, xref, tag, sign_key_ids,"
@@ -5618,6 +5644,77 @@
return ret;
}
+/**
+ * @brief Return a statement for selecting the NVT's of a config.
+ *
+ * @param[in] config Config.
+ * @param[in] family Family to limit selection to.
+ *
+ * @return Freshly allocated SELECT statement if possibly, else NULL.
+ */
+static gchar*
+select_config_nvts (const char* config, const char* family)
+{
+ /** @todo sql_quote. */
+ char *selector = config_nvt_selector (config);
+ if (selector == NULL)
+ /* The config should always have a selector. */
+ return NULL;
+ if (config_nvts_growing (config))
+ {
+ /* The number of NVT's can increase. */
+
+ int alls = sql_int (0, 0,
+ "SELECT COUNT(*) FROM nvt_selectors"
+ " WHERE name = '%s'"
+ " AND type = " G_STRINGIFY (NVT_SELECTOR_TYPE_ALL)
+ ";",
+ selector);
+ if (sql_int (0, 0,
+ "SELECT COUNT(*) FROM nvt_selectors WHERE name = '%s';",
+ selector)
+ == 1)
+ {
+ /* There is one selector. */
+ if (alls == 1)
+ /* It is the all selector. */
+ return g_strdup_printf
+ ("SELECT oid, version, name, summary, description,"
+ " copyright, cve, bid, xref, tag, sign_key_ids,"
+ " category, family"
+ " FROM nvts WHERE family = '%s';",
+ family);
+ /* An error somewhere. */
+ return NULL;
+ }
+ else
+ {
+#if 0
+ int excludes, includes;
+
+ /* There are multiple selectors. */
+
+ excludes = sql_int (0, 0,
+ "SELECT COUNT(*) FROM nvt_selectors"
+ " WHERE name = '%s' AND exclude = 1"
+ " AND type = "
+ G_STRINGIFY (NVT_SELECTOR_TYPE_NVT)
+ ";",
+ selector);
+ includes = sql_int (0, 0,
+ "SELECT COUNT(*) FROM nvt_selectors"
+ " WHERE name = '%s' AND exclude = 0"
+ " AND type = "
+ G_STRINGIFY (NVT_SELECTOR_TYPE_NVT)
+ ";",
+ selector);
+#endif
+ return NULL;
+ }
+ }
+ return NULL;
+}
+
/* NVT preferences. */
More information about the Openvas-commits
mailing list