[Openvas-commits] r2876 - in trunk/openvas-client: . nessus

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Mar 23 13:04:30 CET 2009


Author: felix
Date: 2009-03-23 13:04:27 +0100 (Mon, 23 Mar 2009)
New Revision: 2876

Modified:
   trunk/openvas-client/ChangeLog
   trunk/openvas-client/nessus/data_mining.c
Log:
Outline of function to query certain records of the results "table" in
nbe backend file (specified by line numbers as unique "ID"/ primary key).

* nessus/data_mining.c (report_query_all_by_line): New. Method stub to
access certain rows of the backends results "table".


Modified: trunk/openvas-client/ChangeLog
===================================================================
--- trunk/openvas-client/ChangeLog	2009-03-23 11:59:46 UTC (rev 2875)
+++ trunk/openvas-client/ChangeLog	2009-03-23 12:04:27 UTC (rev 2876)
@@ -1,5 +1,13 @@
 2009-03-23  Felix Wolfsteller <felix.wolfsteller at intevation.de>
 
+	Outline of function to query certain records of the results "table" in
+	nbe backend file (specified by line numbers as unique "ID"/ primary key).
+	
+	* nessus/data_mining.c (report_query_all_by_line): New. Method stub to
+	access certain rows of the backends results "table".
+
+2009-03-23  Felix Wolfsteller <felix.wolfsteller at intevation.de>
+
 	Cosmetics, docs, added comment about GLib 2.8 functionality.
 	
 	* nessus/data_mining.c (query_backend): Removed accidentially pasted

Modified: trunk/openvas-client/nessus/data_mining.c
===================================================================
--- trunk/openvas-client/nessus/data_mining.c	2009-03-23 11:59:46 UTC (rev 2875)
+++ trunk/openvas-client/nessus/data_mining.c	2009-03-23 12:04:27 UTC (rev 2876)
@@ -1435,7 +1435,121 @@
   return ret;
 }
 
+/**
+ * @brief Gets a subset with some values set, defined by line numbers.
+ * 
+ * Queries the results "table" only.
+ * Subset will contain: host port oid severity data (in this order).
+ * 
+ * @param be           Backend- index to query.
+ * @param line_nr_list List of line numbers in the nbe backend file (serve as a
+ *                     workaround for primary keys).
+ * 
+ * @return Subset (list) with rows specified in the line_nr_list parameter, if
+ *         accessible.
+ */
+static struct subset*
+report_query_all_by_line (int be, GList* line_nr_list)
+{
+  struct subset* ret = NULL;
+  static char* buf = NULL;
+  static int   buf_sz = 0;
 
+  if (buf == NULL)
+    {
+      buf_sz = 1024*1024;
+      buf = emalloc(buf_sz);
+    }
+
+#ifdef HAVE_MMAP
+  if (backends[be].mmap) backends[be].cur_line = 0;
+  else
+#endif
+  if (lseek(backends[be].fd, 0, SEEK_SET) < 0)
+    {
+      perror("lseek ");
+    }
+
+#ifdef HAVE_MMAP
+  if(backends[be].fields)
+    {
+      char * requests[BE_NUM_FIELDS];
+      u_short * lines;
+      //struct condition * conditions = query->conditions;
+      int i;
+      bzero (requests, sizeof(*requests)*BE_NUM_FIELDS);
+      requests[0] = "results";
+      lines = requests2lines(be, requests);
+      for (i=0; i<backends[be].num_lines; i++)
+        {
+          // if lines[i] in list
+          if(lines[i])
+            {
+              int j;
+              char * val = NULL;
+              char * table;
+              char * subnet;
+              char * hostname;
+              char * port;
+              char * plugin_id;
+              char * severity;
+              char * data;
+              buf[0] = '\0';
+              mmap_read_line_n (be, buf, buf_sz, i);
+              __split_line (buf, &table, &subnet, &hostname, &port, &plugin_id, &severity, &data);
+              //if (!strcmp (table, "results"))
+              //ret = subset_add (ret, val);
+              ret = subset_add (ret, hostname);
+              ret->id_line = i;
+              //ret = subset_add_again (ret, host);
+              ret = subset_add_again (ret, port);
+              ret = subset_add_again (ret, plugin_id);
+              ret = subset_add_again (ret, severity);
+              ret = subset_add_again (ret, data);
+            }
+        }
+
+      efree(&lines);
+      return ret;
+    }
+#endif /* HAVE_MMAP */
+  int curr_id_line = -1;
+  while (read_line (be, buf, buf_sz ) > 0)
+    {
+      ++curr_id_line;
+#ifdef DEBUG
+      printf ("Query Backend, Line (%d): %s \n", curr_id_line, buf);
+#endif
+      char * table;
+      char * subnet;
+      char * hostname;
+      char * port;
+      char * plugin_id;
+      char * severity;
+      char * data;
+      int selected = 0;
+      __split_line(buf, &table, &subnet, &hostname, &port, &plugin_id, &severity, &data);
+
+      if (strcmp(table, "results"))
+      continue;
+
+      // If curr_id_line in list
+      // Fill the resulting subset
+      char * val = NULL;
+
+      ret = subset_add (ret, hostname);
+      ret->id_line = curr_id_line;
+      //ret = subset_add_again (ret, host);
+      ret = subset_add_again (ret, port);
+      ret = subset_add_again (ret, plugin_id);
+      ret = subset_add_again (ret, severity);
+      ret = subset_add_again (ret, data);
+    }
+
+  return ret;
+}
+
+
 /**
  * @brief Builds a query struct str (printf-like) and executes it against a flat
  * @brief file.



More information about the Openvas-commits mailing list