[Openvas-commits] r5518 - in trunk/openvas-manager: . src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Oct 13 18:16:44 CEST 2009


Author: mattm
Date: 2009-10-13 18:16:42 +0200 (Tue, 13 Oct 2009)
New Revision: 5518

Modified:
   trunk/openvas-manager/ChangeLog
   trunk/openvas-manager/src/manage.h
   trunk/openvas-manager/src/omp.c
   trunk/openvas-manager/src/otp.c
   trunk/openvas-manager/src/tasks_sql.h
Log:
	Add parsing of NVT category from OTP.

	* src/otp.c: Include openvas/nvt_categories.h.
	(category_number): New function.
	(process_otp_scanner_input): In SCANNER_PLUGIN_LIST_CATEGORY set the
	category number according to the OTP field.

	* src/tasks_sql.h (DATABASE_VERSION): Increment, due to nvts category
	column type specification.
	(init_manage): Specify type for category column in table nvts.
	(make_nvt_from_nvti): Insert category as int.
	(nvt_iterator_category): Change return to int.

	* src/manage.h: Update header.

	* src/omp.c: Include openvas/nvt_categories.h.
	(category_name): New function.
	(send_nvt): Convert category number into name.

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog	2009-10-13 16:05:02 UTC (rev 5517)
+++ trunk/openvas-manager/ChangeLog	2009-10-13 16:16:42 UTC (rev 5518)
@@ -1,5 +1,26 @@
-2009-10-12  Matthew Mundell <matthew.mundell at intevation.de>
+2009-10-13  Matthew Mundell <matthew.mundell at intevation.de>
 
+	Add parsing of NVT category from OTP.
+
+	* src/otp.c: Include openvas/nvt_categories.h.
+	(category_number): New function.
+	(process_otp_scanner_input): In SCANNER_PLUGIN_LIST_CATEGORY set the
+	category number according to the OTP field.
+
+	* src/tasks_sql.h (DATABASE_VERSION): Increment, due to nvts category
+	column type specification.
+	(init_manage): Specify type for category column in table nvts.
+	(make_nvt_from_nvti): Insert category as int.
+	(nvt_iterator_category): Change return to int.
+
+	* src/manage.h: Update header.
+
+	* src/omp.c: Include openvas/nvt_categories.h.
+	(category_name): New function.
+	(send_nvt): Convert category number into name.
+
+2009-10-13  Matthew Mundell <matthew.mundell at intevation.de>
+
 	* src/omp.c (omp_xml_handle_end_element): Free modify_task_file.
 
 2009-10-12  Matthew Mundell <matthew.mundell at intevation.de>

Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h	2009-10-13 16:05:02 UTC (rev 5517)
+++ trunk/openvas-manager/src/manage.h	2009-10-13 16:16:42 UTC (rev 5518)
@@ -627,7 +627,7 @@
 const char*
 nvt_iterator_sign_key_ids (iterator_t*);
 
-const char*
+int
 nvt_iterator_category (iterator_t*);
 
 const char*

Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c	2009-10-13 16:05:02 UTC (rev 5517)
+++ trunk/openvas-manager/src/omp.c	2009-10-13 16:16:42 UTC (rev 5518)
@@ -56,6 +56,7 @@
 #include <openvas/base/certificate.h>
 #include <openvas/base/nvti.h>
 #include <openvas/base/openvas_string.h>
+#include <openvas/nvt_categories.h>
 #include <openvas/openvas_logging.h>
 
 #ifdef S_SPLINT_S
@@ -69,6 +70,26 @@
 #define G_LOG_DOMAIN "md    omp"
 
 
+/* Helper functions. */
+
+/** @brief Return the name of a category.
+ *
+ * @param  category  The number of the category.
+ *
+ * @return The name of the category.
+ */
+static const char*
+category_name (int category)
+{
+  static const char *categories[] = { ACT_STRING_LIST_ALL };
+  if (category >= ACT_FIRST && category <= ACT_END)
+    {
+      return categories[category];
+    }
+  return categories[ACT_UNKNOWN];
+}
+
+
 /* Help message. */
 
 static char* help_text = "\n"
@@ -1677,7 +1698,7 @@
                              "</nvt>",
                              oid,
                              name_text,
-                             nvt_iterator_category (nvts),
+                             category_name (nvt_iterator_category (nvts)),
                              copyright_text,
                              description_text,
                              summary_text,

Modified: trunk/openvas-manager/src/otp.c
===================================================================
--- trunk/openvas-manager/src/otp.c	2009-10-13 16:05:02 UTC (rev 5517)
+++ trunk/openvas-manager/src/otp.c	2009-10-13 16:16:42 UTC (rev 5518)
@@ -55,6 +55,7 @@
 #include <unistd.h>
 
 #include <openvas/base/openvas_string.h>
+#include <openvas/nvt_categories.h>
 
 #ifdef S_SPLINT_S
 #include "splint.h"
@@ -85,6 +86,23 @@
   g_slist_free ((GSList*) list);
 }
 
+/** @brief Return the number associated with a category name.
+ *
+ * @param  category  The category name.
+ *
+ * @return The number of the category.
+ */
+static int
+category_number (const char *category)
+{
+  static const char *categories[] = { ACT_STRING_LIST_ALL };
+  int index;
+  for (index = ACT_FIRST; index <= ACT_END; index++)
+    if (strcmp (category, categories[index]) == 0)
+      return index;
+  return ACT_UNKNOWN;
+}
+
 
 /* Ports. */
 
@@ -1959,8 +1977,7 @@
                 }
               case SCANNER_PLUGIN_LIST_CATEGORY:
                 {
-                  // FIX parse category number from field
-                  nvti_set_category (current_plugin, 0);
+                  nvti_set_category (current_plugin, category_number (field));
                   set_scanner_state (SCANNER_PLUGIN_LIST_COPYRIGHT);
                   break;
                 }

Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h	2009-10-13 16:05:02 UTC (rev 5517)
+++ trunk/openvas-manager/src/tasks_sql.h	2009-10-13 16:16:42 UTC (rev 5518)
@@ -30,7 +30,7 @@
 /**
  * @brief Version of the database schema.
  */
-#define DATABASE_VERSION 1
+#define DATABASE_VERSION 2
 
 /**
  * @brief NVT selector type for "all" rule.
@@ -983,7 +983,7 @@
   sql ("CREATE TABLE IF NOT EXISTS reports (uuid, hidden INTEGER, task INTEGER, date INTEGER, start_time, end_time, nbefile, comment, scan_run_status INTEGER);");
   sql ("CREATE TABLE IF NOT EXISTS report_hosts (report INTEGER, host, start_time, end_time, attack_state, current_port, max_port);");
   sql ("CREATE TABLE IF NOT EXISTS report_results (report INTEGER, result INTEGER);");
-  sql ("CREATE TABLE IF NOT EXISTS nvts (oid, version, name, summary, description, copyright, cve, bid, xref, tag, sign_key_ids, category, family);");
+  sql ("CREATE TABLE IF NOT EXISTS nvts (oid, version, name, summary, description, copyright, cve, bid, xref, tag, sign_key_ids, category INTEGER, family);");
   sql ("CREATE TABLE IF NOT EXISTS nvt_preferences (name, value);");
   sql ("CREATE TABLE IF NOT EXISTS lsc_credentials (name, comment, rpm, deb, dog);");
 
@@ -4289,7 +4289,7 @@
   sql ("INSERT into nvts (oid, version, name, summary, description, copyright,"
        " cve, bid, xref, tag, sign_key_ids, category, family)"
        " VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s',"
-       " '%s', '%i', '%s');",
+       " '%s', %i, '%s');",
        nvti_oid (nvti),
        quoted_version,
        quoted_name,
@@ -4382,9 +4382,17 @@
 DEF_ACCESS (nvt_iterator_xref, 8);
 DEF_ACCESS (nvt_iterator_tag, 9);
 DEF_ACCESS (nvt_iterator_sign_key_ids, 10);
-DEF_ACCESS (nvt_iterator_category, 11);
 DEF_ACCESS (nvt_iterator_family, 12);
 
+int
+nvt_iterator_category (iterator_t* iterator)
+{
+  int ret;
+  if (iterator->done) return -1;
+  ret = (int) sqlite3_column_int (iterator->stmt, 11);
+  return ret;
+}
+
 
 /* NVT selectors. */
 



More information about the Openvas-commits mailing list