[Openvas-commits] r5683 - in trunk/openvas-manager: . src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Oct 23 12:46:37 CEST 2009
Author: mattm
Date: 2009-10-23 12:46:36 +0200 (Fri, 23 Oct 2009)
New Revision: 5683
Modified:
trunk/openvas-manager/ChangeLog
trunk/openvas-manager/src/tasks_sql.h
Log:
Add families to NVT selectors in database when creating selectors from
RC file.
* src/tasks_sql.h (clude): Add a families arg. Insert the NVT family in
families and the database.
(insert_rc_into_config): Let clude do the families inserting.
(nvt_selector_family_growing): Correct column name in SQL.
Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog 2009-10-23 08:42:28 UTC (rev 5682)
+++ trunk/openvas-manager/ChangeLog 2009-10-23 10:46:36 UTC (rev 5683)
@@ -1,5 +1,15 @@
2009-10-23 Matthew Mundell <matthew.mundell at intevation.de>
+ Add families to NVT selectors in database when creating selectors from
+ RC file.
+
+ * src/tasks_sql.h (clude): Add a families arg. Insert the NVT family in
+ families and the database.
+ (insert_rc_into_config): Let clude do the families inserting.
+ (nvt_selector_family_growing): Correct column name in SQL.
+
+2009-10-23 Matthew Mundell <matthew.mundell at intevation.de>
+
Extend OMP GET_CONFIGS for retrieving a single config with a summary
of the selected families.
Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h 2009-10-23 08:42:28 UTC (rev 5682)
+++ trunk/openvas-manager/src/tasks_sql.h 2009-10-23 10:46:36 UTC (rev 5683)
@@ -3675,7 +3675,8 @@
* @param[in] exclude If true exclude, else include.
*/
static void
-clude (const char *config_name, GArray *array, int array_size, int exclude)
+clude (const char *config_name, GArray *array, int array_size, int exclude,
+ GHashTable *families)
{
gint index;
const char* tail;
@@ -3683,11 +3684,18 @@
sqlite3_stmt* stmt;
gchar* formatted;
- formatted = g_strdup_printf ("INSERT INTO nvt_selectors"
- " (name, exclude, type, family_or_nvt)"
- " VALUES ('%s', %i, 2, $value);",
- config_name,
- exclude);
+ if (families)
+ formatted = g_strdup_printf ("INSERT INTO nvt_selectors"
+ " (name, exclude, type, family_or_nvt, family)"
+ " VALUES ('%s', %i, 2, $value, $family);",
+ config_name,
+ exclude);
+ else
+ formatted = g_strdup_printf ("INSERT INTO nvt_selectors"
+ " (name, exclude, type, family_or_nvt, family)"
+ " VALUES ('%s', %i, 2, $value, NULL);",
+ config_name,
+ exclude);
tracef (" sql: %s\n", formatted);
@@ -3733,6 +3741,37 @@
abort ();
}
+ /* Bind the family name to the "$family" in the SQL statement. */
+
+ if (families)
+ {
+ char *family = NULL;
+ nvti_t *nvti = nvtis_lookup (nvti_cache, id);
+
+ if (nvti)
+ {
+ family = nvti_family (nvti);
+
+ if (family)
+ g_hash_table_insert (families, family, (gpointer) 1);
+ }
+
+ while (1)
+ {
+ if (family)
+ ret = sqlite3_bind_text (stmt, 2, family, -1,
+ SQLITE_TRANSIENT);
+ else
+ ret = sqlite3_bind_null (stmt, 2);
+ if (ret == SQLITE_BUSY) continue;
+ if (ret == SQLITE_OK) break;
+ g_warning ("%s: sqlite3_prepare failed: %s\n",
+ __FUNCTION__,
+ sqlite3_errmsg (task_db));
+ abort ();
+ }
+ }
+
/* Run the statement. */
while (1)
@@ -3873,16 +3912,8 @@
if ((value_len == 3)
&& strncasecmp (eq2 + 2, "yes", 3) == 0)
{
- nvti_t * nvti;
-
+ yes_size++;
g_array_append_val (yes, rc);
- yes_size++;
-
- nvti = nvtis_lookup (nvti_cache, rc);
- if (nvti)
- g_hash_table_insert (families,
- nvti_family (nvti),
- (gpointer) 1);
}
else
{
@@ -3965,7 +3996,7 @@
/* Explicitly exclude any nos. */
- clude (config_name, no, no_size, 1);
+ clude (config_name, no, no_size, 1, NULL);
/* Cache the growth types. */
@@ -3979,8 +4010,8 @@
/* Explictly include the yeses and exclude the nos. Keep the nos
* because the config may change to auto enable new plugins. */
- clude (config_name, yes, yes_size, 0);
- clude (config_name, no, no_size, 1);
+ clude (config_name, yes, yes_size, 0, families);
+ clude (config_name, no, no_size, 1, NULL);
/* Cache the family and NVT count and selector types. */
@@ -4892,7 +4923,7 @@
ret = sql_int (0, 0,
"SELECT COUNT(*) FROM nvt_selectors"
- " WHERE name = '%s' AND type = 1 AND nvt_or_family = '%s'"
+ " WHERE name = '%s' AND type = 1 AND family_or_nvt = '%s'"
" LIMIT 1;",
quoted_selector, quoted_family);
More information about the Openvas-commits
mailing list