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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Sep 9 14:45:06 CEST 2008


Author: jan
Date: 2008-09-09 14:45:05 +0200 (Tue, 09 Sep 2008)
New Revision: 1308

Modified:
   trunk/openvas-client/ChangeLog
   trunk/openvas-client/nessus/comm.c
   trunk/openvas-client/nessus/data_mining.c
   trunk/openvas-client/nessus/nessus_plugin.c
   trunk/openvas-client/nessus/nessus_plugin.h
   trunk/openvas-client/nessus/pdf_output.c
   trunk/openvas-client/nessus/prefs_dialog/prefs_report.c
Log:
Migrate PLUGIN_INFO request based on OIDs.
Assume OIDs for receiving standard plugin information.

* nessus/comm.c (parse_plugin): Now parsing for a OID string
instead of the old integer ID.
(fetch_new_plugins): Apply PLUGIN_INFO with OID instead of
old ID.
(struct mising_plugin): replaced element "int id" by "char * oid".
(missing_plugins_list_add): Apply OID instead of ID.
(update_existing_plugin): Apply OID instead of ID.
(comm_get_plugins_md5): Migrated from ID to OID.
(add_md5sum_to_plugin): Adapted parameter type.

* nessus/nessus_plugin.c (nessus_plugin_new): Now takes
and sets OID instead of old ID.
(nessus_plugin_get_by_id): Renamed to nessus_plugin_get_by_oid()
and switched to using OIDs.

* nessus/nessus_plugin.h: Updated protos.

* nessus/prefs_dialog/prefs_report.c (row_activated): Migrated from
id to oid.

* nessus/pdf_output.c (print_plugin_information): Migrated from
id to oid.

* nessus/data_mining.c: rename "plugin_id" to "plugin_oid" for query types.



Modified: trunk/openvas-client/ChangeLog
===================================================================
--- trunk/openvas-client/ChangeLog	2008-09-09 12:32:02 UTC (rev 1307)
+++ trunk/openvas-client/ChangeLog	2008-09-09 12:45:05 UTC (rev 1308)
@@ -1,3 +1,33 @@
+2008-09-09  Jan-Oliver Wagner <jan-oliver.wagner at intevation.de>
+
+	Migrate PLUGIN_INFO request based on OIDs.
+	Assume OIDs for receiving standard plugin information.
+
+	* nessus/comm.c (parse_plugin): Now parsing for a OID string
+	instead of the old integer ID.
+	(fetch_new_plugins): Apply PLUGIN_INFO with OID instead of
+	old ID.
+	(struct mising_plugin): replaced element "int id" by "char * oid".
+	(missing_plugins_list_add): Apply OID instead of ID.
+	(update_existing_plugin): Apply OID instead of ID.
+	(comm_get_plugins_md5): Migrated from ID to OID.
+	(add_md5sum_to_plugin): Adapted parameter type.
+
+	* nessus/nessus_plugin.c (nessus_plugin_new): Now takes
+	and sets OID instead of old ID.
+	(nessus_plugin_get_by_id): Renamed to nessus_plugin_get_by_oid()
+	and switched to using OIDs.
+
+	* nessus/nessus_plugin.h: Updated protos.
+
+	* nessus/prefs_dialog/prefs_report.c (row_activated): Migrated from
+	id to oid.
+
+	* nessus/pdf_output.c (print_plugin_information): Migrated from
+	id to oid.
+
+	* nessus/data_mining.c: rename "plugin_id" to "plugin_oid" for query types.
+
 2008-09-05  Jan-Oliver Wagner <jan-oliver.wagner at intevation.de>
 
 	Renaming element "asc_id" of struct "nessus_plugin" into

Modified: trunk/openvas-client/nessus/comm.c
===================================================================
--- trunk/openvas-client/nessus/comm.c	2008-09-09 12:32:02 UTC (rev 1307)
+++ trunk/openvas-client/nessus/comm.c	2008-09-09 12:45:05 UTC (rev 1308)
@@ -136,8 +136,7 @@
   char *t;
   size_t l;
 
-  int    i_id;
-  char id[32];
+  char * oid = NULL;
   char * name = NULL;
   char * category = NULL;
   char * copyright = NULL;
@@ -148,23 +147,17 @@
   char * cve = NULL;
   char * bid = NULL;
   char * xref = NULL;
-  struct nessus_plugin * ret;
 
-  sscanf(buf, "%d", &i_id);
-
-  
-  snprintf(id, sizeof(id), "%d", i_id);
-  l = strlen(id);
-
   str = parse_separator(buf);
-  if(!str)
-    return NULL;
+  if(!str) return NULL;
+  oid = str;
 
+  l = strlen(str) + 5;
+  str = parse_separator(buf + l);
+  if(!str) return NULL;
   name = str;
 
-
   l += strlen(str) + 5;
-
   str = parse_separator(buf + l);
   if(!str) return NULL;
   category = str;
@@ -175,23 +168,19 @@
   copyright = str;
 
   l += strlen(str) + 5;
-
-
   str = parse_separator(buf + l);
   if(!str) return NULL;
   t = str;
   while((t = strchr(t, ';')))
     t[0] = '\n';
-
   description = str;
-  l += strlen(str) + 5;
 
+  l += strlen(str) + 5;
   str = parse_separator(buf + l);
   if(!str) return NULL;
   summary = str;
 
   l += strlen(str) + 5;
-
   str = parse_separator(buf + l);
   if(!str) return NULL;
   family = str;
@@ -222,8 +211,8 @@
     }
   }
 
-  ret = nessus_plugin_new(id, name, category, copyright, description, summary, family, version, cve, bid, xref);   
-  return ret;
+  return nessus_plugin_new(oid, name, category, copyright, description,
+                           summary, family, version, cve, bid, xref);
 }
 
 
@@ -891,8 +880,10 @@
  */
 static int
 comm_get_plugins_md5(struct context *context, char * buf, int bufsz,
-    int (callback)(struct context *context, int id, const char * md5sum,
-	struct nessus_plugin * plugin, void * data), void * data)
+    int (callback)(struct context *context, const char * oid,
+                   const char * md5sum, struct nessus_plugin * plugin,
+                   void * data),
+    void * data)
 {
   network_printf(context->socket, "CLIENT <|> SEND_PLUGINS_MD5 <|> CLIENT\n");
   network_gets(context->socket, buf, 23);
@@ -911,8 +902,9 @@
 	break;
       else
       {
-	char * rest;
-	int id = strtol(buf, &rest, 10);
+	char * oid = parse_separator(buf);
+	char * rest = buf + strlen(oid) + 5;
+
 	if (strncmp(rest, " <|> ", 5) == 0)
 	{
 	  struct nessus_plugin * plugin = NULL;
@@ -924,10 +916,10 @@
 	  if (md5sum[md5len - 1] == '\n')
 	    md5sum[md5len - 1] = '\0';
 
-	  plugin = nessus_plugin_get_by_id(context->plugins, id);
+	  plugin = nessus_plugin_get_by_oid(context->plugins, oid);
 	  if (plugin == NULL)
-	    plugin = nessus_plugin_get_by_id(context->scanners, id);
-	  if (callback(context, id, md5sum, plugin, data))
+	    plugin = nessus_plugin_get_by_oid(context->scanners, oid);
+	  if (callback(context, oid, md5sum, plugin, data))
 	  {
 	    show_error(_("Error processing plugin information from the server"));
 	    return -1;
@@ -950,7 +942,7 @@
  * plugins.  The list contains the ids and md5sums of the plugins */
 
 struct missing_plugin {
-  int id;
+  char * oid;
   char * md5sum;
 };
 
@@ -971,7 +963,7 @@
 /* Add an entry to the list of missing/outdated plugins */
 static void
 missing_plugins_list_add(struct missing_plugins_list * missing,
-    int id, const char * md5sum)
+    const char * oid, const char * md5sum)
 {
   if (missing->length == missing->allocated)
   {
@@ -984,7 +976,7 @@
     missing->allocated = new_length;
   }
 
-  missing->plugins[missing->length].id = id;
+  missing->plugins[missing->length].oid = estrdup(oid);
   missing->plugins[missing->length].md5sum = estrdup(md5sum);
   missing->length += 1;
 }
@@ -1014,7 +1006,8 @@
  * the data parameter.
  */
 static int
-update_existing_plugin(struct context *context, int id, const char * md5sum,
+update_existing_plugin(struct context *context,
+    const char * oid, const char * md5sum,
     struct nessus_plugin * plugin, void * data)
 {
   if (plugin && strcmp(plugin->md5sum, md5sum) == 0)
@@ -1023,7 +1016,7 @@
   }
   else
   {
-    missing_plugins_list_add((struct missing_plugins_list*)data, id, md5sum);
+    missing_plugins_list_add((struct missing_plugins_list*)data, oid, md5sum);
   }
 
   return 0;
@@ -1083,7 +1076,7 @@
   for (i = 0; i < missing->length; i++)
   {
     network_printf(context->socket,
-	"CLIENT <|> PLUGIN_INFO <|> %d <|> CLIENT\n", missing->plugins[i].id);
+	"CLIENT <|> PLUGIN_INFO <|> %s <|> CLIENT\n", missing->plugins[i].oid);
     network_gets(context->socket, buf, bufsz);
 
     plugin = parse_plugin(buf);
@@ -1137,8 +1130,8 @@
 /* callback for comm_get_plugins_md5 that simply adds the md5sum to a plugin
  */
 static int
-add_md5sum_to_plugin(struct context *context, int id, const char * md5sum,
-    struct nessus_plugin * plugin, void * data)
+add_md5sum_to_plugin(struct context *context, const char * oid,
+    const char * md5sum, struct nessus_plugin * plugin, void * data)
 {
   if (plugin != NULL)
   {
@@ -1149,7 +1142,7 @@
      * immediately after the full list of plugins has been fetched from
      * the server, all plugins should be known, so we should never get
      * here */
-    fprintf(stderr, "add_md5sum_to_plugin: Unknown plugin %d\n", id);
+    fprintf(stderr, "add_md5sum_to_plugin: Unknown plugin %s\n", oid);
 
   return 0;
 }

Modified: trunk/openvas-client/nessus/data_mining.c
===================================================================
--- trunk/openvas-client/nessus/data_mining.c	2008-09-09 12:32:02 UTC (rev 1307)
+++ trunk/openvas-client/nessus/data_mining.c	2008-09-09 12:45:05 UTC (rev 1308)
@@ -801,7 +801,7 @@
 #define QUERY_TYPE_SUBNET_ASC 		"subnet"
 #define QUERY_TYPE_HOST_ASC   		"host"
 #define QUERY_TYPE_PORT_ASC   		"port"
-#define QUERY_TYPE_PLUGIN_ID_ASC 	"plugin_id"
+#define QUERY_TYPE_PLUGIN_ID_ASC 	"plugin_oid"
 #define QUERY_TYPE_SEVERITY_ASC		"severity"
 #define QUERY_TYPE_REPORT_ASC   	"report"
 #define QUERY_TYPE_TYPE_ASC		"type"

Modified: trunk/openvas-client/nessus/nessus_plugin.c
===================================================================
--- trunk/openvas-client/nessus/nessus_plugin.c	2008-09-09 12:32:02 UTC (rev 1307)
+++ trunk/openvas-client/nessus/nessus_plugin.c	2008-09-09 12:45:05 UTC (rev 1308)
@@ -25,14 +25,24 @@
 }
 
 
-struct nessus_plugin * nessus_plugin_new(char * id, char * name, char * category, char * copyright, char * description, char * summary, char * family, char * version, char * cve, char * bid, char * xrefs)
+struct nessus_plugin *
+nessus_plugin_new(char * oid,
+                  char * name,
+                  char * category,
+                  char * copyright,
+                  char * description,
+                  char * summary,
+                  char * family,
+                  char * version,
+                  char * cve,
+                  char * bid,
+                  char * xrefs)
 {
  struct nessus_plugin * np = malloc(sizeof(*np));
 
  if ( np == NULL ) abort();
  bzero(np, sizeof(*np));
- np->id = atoi(id);
- np->oid = cache_inc(id);
+ np->oid = cache_inc(oid);
  np->md5sum = NULL;
 
  np->name = cache_inc(name); 
@@ -76,11 +86,12 @@
 }
 
 
-struct nessus_plugin * nessus_plugin_get_by_id(struct nessus_plugin * plugins, int id )
+struct nessus_plugin *
+nessus_plugin_get_by_oid(struct nessus_plugin * plugins, const char * oid)
 {
  while ( plugins != NULL )
  	{
-	if ( plugins->id == id ) return plugins;
+	if (!strcmp(plugins->oid, oid)) return plugins;
 	plugins = plugins->next;
 	}
 

Modified: trunk/openvas-client/nessus/nessus_plugin.h
===================================================================
--- trunk/openvas-client/nessus/nessus_plugin.h	2008-09-09 12:32:02 UTC (rev 1307)
+++ trunk/openvas-client/nessus/nessus_plugin.h	2008-09-09 12:45:05 UTC (rev 1308)
@@ -31,7 +31,7 @@
 struct nessus_plugin * nessus_plugin_new(char * id, char * name, char * category, char * copyright, char * description, char * summary, char * family, char * version, char * cve, char * bid, char * xrefs);
 
 struct nessus_plugin * nessus_plugin_get_by_name( struct nessus_plugin * plugins, char * name);
-struct nessus_plugin * nessus_plugin_get_by_id( struct nessus_plugin * plugins, int id);
+struct nessus_plugin * nessus_plugin_get_by_oid( struct nessus_plugin * plugins, const char * id);
 
 void nessus_plugin_set_md5sum(struct nessus_plugin * plugin, const char * md5sum);
 

Modified: trunk/openvas-client/nessus/pdf_output.c
===================================================================
--- trunk/openvas-client/nessus/pdf_output.c	2008-09-09 12:32:02 UTC (rev 1307)
+++ trunk/openvas-client/nessus/pdf_output.c	2008-09-09 12:45:05 UTC (rev 1308)
@@ -917,25 +917,24 @@
 {
   struct context *context = value;
   FILE *file = userdata;
-  char *plugin_id_str = key;
-  int plugin_id = atoi(plugin_id_str);
+  char *plugin_oid = key;
   struct nessus_plugin *plugin;
   char *description;
   char *html_description;
 
-  plugin = nessus_plugin_get_by_id(context->plugins, plugin_id);
+  plugin = nessus_plugin_get_by_oid(context->plugins, plugin_oid);
   if (plugin == NULL)
-    plugin = nessus_plugin_get_by_id(context->scanners, plugin_id);
+    plugin = nessus_plugin_get_by_oid(context->scanners, plugin_oid);
 
   if (plugin == NULL)
   {
-    fprintf(stderr, "print_plugin_information: no plugin with id %d\n",
-	plugin_id);
+    fprintf(stderr, "print_plugin_information: no plugin with oid %s\n",
+	plugin_oid);
     return;
   }
 
-  fprintf(file, "<H3><a name=\"nvt1.3.6.1.4.1.25623.1.0.%s\">NVT 1.3.6.1.4.1.25623.1.0.%d: %s</a></H3>\n\n",
-      plugin_id_str, plugin_id, plugin->name);
+  fprintf(file, "<H3><a name=\"nvt%s\">NVT %s: %s</a></H3>\n\n",
+      plugin_oid, plugin_oid, plugin->name);
 
   fprintf(file, "<table>\n");
   print_plugin_table_row(file, _("Summary"), plugin->summary);

Modified: trunk/openvas-client/nessus/prefs_dialog/prefs_report.c
===================================================================
--- trunk/openvas-client/nessus/prefs_dialog/prefs_report.c	2008-09-09 12:32:02 UTC (rev 1307)
+++ trunk/openvas-client/nessus/prefs_dialog/prefs_report.c	2008-09-09 12:45:05 UTC (rev 1308)
@@ -300,7 +300,7 @@
   int depth = 0;
   int has_parent;
   struct context *context = arg_get_value((struct arglist*)user_data, "REPORT_CONTEXT");
-  int plugin_id = 0;
+  char * plugin_oid = NULL;
   struct nessus_plugin *plugin;
 
 
@@ -343,7 +343,7 @@
     clear_report_text(user_data);
 
     subset = sort_uniq(query_backend(be,
-	    "SELECT report,severity,plugin_id FROM results"
+	    "SELECT report,severity,plugin_oid FROM results"
 	    " WHERE %s = '%s' AND %s = '%s' AND %s = '%s'",
 	    keys[0], values[0],
 	    keys[1], values[1],
@@ -355,21 +355,21 @@
       if (((prefs_get_int(Global, "show_nvt_name_and_oid")) == 1) &&
             ((prefs_get_int(Global, "reports_use_plugin_cache")) == 1))
       {
-        plugin_id = atoi(subset_nth_value(walk, 2));
-        plugin = nessus_plugin_get_by_id(context->plugins, plugin_id);
+        plugin_oid = subset_nth_value(walk, 2);
+        plugin = nessus_plugin_get_by_oid(context->plugins, plugin_oid);
         if (plugin == NULL)
-          plugin = nessus_plugin_get_by_id(context->scanners, plugin_id);
+          plugin = nessus_plugin_get_by_oid(context->scanners, plugin_oid);
         if (plugin == NULL)
         {
-          fprintf(stderr, "prefs_report.row_activated: no plugin with id %d in cache!\n",
-              plugin_id);
+          fprintf(stderr, "prefs_report.row_activated: no plugin with id %s in cache!\n",
+              plugin_oid);
         }
         else
         {
           gtk_text_buffer_get_end_iter(buffer, &iter);
           gtk_text_buffer_insert(buffer, &iter,
-            g_strdup_printf(_("Reported by NVT \"%s\" (1.3.6.1.4.1.25623.1.0.%d):\n\n"),
-                            plugin->name, plugin->id), -1);
+            g_strdup_printf(_("Reported by NVT \"%s\" (%s):\n\n"),
+                            plugin->name, plugin->oid), -1);
         }
       }
 



More information about the Openvas-commits mailing list