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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed May 27 15:19:42 CEST 2009


Author: mattm
Date: 2009-05-27 15:19:40 +0200 (Wed, 27 May 2009)
New Revision: 3492

Added:
   trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_2.c
   trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_3.c
   trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_4.c
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/omp.h
   trunk/openvas-manager/src/tests/CMakeLists.txt
Log:
	Implement OMP GET_NVT_FEED_DETAILS when called to return a specific NVT.

	* src/manage.c (find_plugin): New function.
	* src/manage.h (find_plugin): New header.

	* src/omp.c (client_state_t): Add CLIENT_GET_NVT_FEED_DETAILS_OID.
	(omp_xml_handle_start_element, omp_xml_handle_end_element)
	(omp_xml_handle_text): Add GET_NVT_FEED_DETAILS ID handling.
	(send_plugin): Convert strings to UTF-8 for g_markup_escape_text.  Free
	the correct strings.  Correct XML tag.

    * src/omp.h (TO_CLIENT_BUFFER_SIZE): Increase.

	* src/tests/omp_get_nvt_feed_details_2.c,
	src/tests/omp_get_nvt_feed_details_3.c,
	src/tests/omp_get_nvt_feed_details_4.c: New files.

	* src/tests/CMakeLists.txt: Add new tests.

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog	2009-05-27 11:33:03 UTC (rev 3491)
+++ trunk/openvas-manager/ChangeLog	2009-05-27 13:19:40 UTC (rev 3492)
@@ -1,3 +1,24 @@
+2009-05-27  Matthew Mundell <mmundell at intevation.de>
+
+	Implement OMP GET_NVT_FEED_DETAILS when called to return a specific NVT.
+
+	* src/manage.c (find_plugin): New function.
+	* src/manage.h (find_plugin): New header.
+
+	* src/omp.c (client_state_t): Add CLIENT_GET_NVT_FEED_DETAILS_OID.
+	(omp_xml_handle_start_element, omp_xml_handle_end_element)
+	(omp_xml_handle_text): Add GET_NVT_FEED_DETAILS ID handling.
+	(send_plugin): Convert strings to UTF-8 for g_markup_escape_text.  Free
+	the correct strings.  Correct XML tag.
+
+    * src/omp.h (TO_CLIENT_BUFFER_SIZE): Increase.
+
+	* src/tests/omp_get_nvt_feed_details_2.c,
+	src/tests/omp_get_nvt_feed_details_3.c,
+	src/tests/omp_get_nvt_feed_details_4.c: New files.
+
+	* src/tests/CMakeLists.txt: Add new tests.
+
 2009-05-26  Matthew Mundell <mmundell at intevation.de>
 
 	Implement OMP GET_NVT_FEED_DETAILS when called to return all NVTs.

Modified: trunk/openvas-manager/src/manage.c
===================================================================
--- trunk/openvas-manager/src/manage.c	2009-05-27 11:33:03 UTC (rev 3491)
+++ trunk/openvas-manager/src/manage.c	2009-05-27 13:19:40 UTC (rev 3492)
@@ -1239,6 +1239,12 @@
     g_hash_table_insert (plugins, (gpointer) plugin->oid, (gpointer) plugin);
 }
 
+plugin_t*
+find_plugin (plugins_t* plugins, const char* oid)
+{
+  return g_hash_table_lookup (plugins, oid);
+}
+
 /**
  * @brief Request the list of plugins from the server.
  *

Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h	2009-05-27 11:33:03 UTC (rev 3491)
+++ trunk/openvas-manager/src/manage.h	2009-05-27 13:19:40 UTC (rev 3492)
@@ -389,6 +389,9 @@
 void
 add_plugin (plugins_t*, plugin_t*);
 
+plugin_t*
+find_plugin (plugins_t*, const char*);
+
 #define plugins_find g_hash_table_find
 
 char*

Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c	2009-05-27 11:33:03 UTC (rev 3491)
+++ trunk/openvas-manager/src/omp.c	2009-05-27 13:19:40 UTC (rev 3492)
@@ -69,7 +69,7 @@
 "    GET_DEPENDENCIES       Get dependencies for all available NVTs.\n"
 "    GET_NVT_FEED_ALL       Get IDs and names of all available NVTs.\n"
 "    GET_NVT_FEED_CHECKSUM  Get checksum for entire NVT collection.\n"
-"    GET_NVT_FEED_DETAILS   * Get all details for all available NVTs.\n"
+"    GET_NVT_FEED_DETAILS   Get all details for all available NVTs.\n"
 "    GET_PREFERENCES        Get preferences for all available NVTs.\n"
 "    GET_REPORT             Get a report identified by its unique ID.\n"
 "    GET_RULES              Get the rules for the authenticated user.\n"
@@ -188,6 +188,7 @@
   CLIENT_GET_NVT_FEED_ALL,
   CLIENT_GET_NVT_FEED_CHECKSUM,
   CLIENT_GET_NVT_FEED_DETAILS,
+  CLIENT_GET_NVT_FEED_DETAILS_OID,
   CLIENT_GET_PREFERENCES,
   CLIENT_GET_REPORT,
   CLIENT_GET_REPORT_ID,
@@ -548,6 +549,9 @@
         break;
 
       case CLIENT_GET_NVT_FEED_DETAILS:
+        if (strncasecmp ("OID", element_name, 3) == 0)
+          set_client_state (CLIENT_GET_NVT_FEED_DETAILS_OID);
+        else
           {
             if (send_to_client ("<get_nvt_feed_details>"
                                 "<status>" STATUS_ERROR_SYNTAX "</status>"
@@ -866,11 +870,19 @@
   gchar* name_text = g_markup_escape_text (name, strlen (name));
   if (details)
     {
+      gsize dummy;
 
-#define DEF(x)                                               \
-      char* x = plugin_ ## x (plugin);                       \
-      gchar* x ## _text = g_markup_escape_text (x,           \
-                                               strlen (x))
+#define DEF(x)                                                    \
+      char* x = plugin_ ## x (plugin);                            \
+      /* FIX Temp hack. */                                        \
+      gchar* x ## _utf8 = x ? g_convert (x, strlen (x),           \
+                                         "utf-8", "iso_8895-1",   \
+                                         NULL, &dummy, NULL)      \
+                            : NULL;                               \
+      gchar* x ## _text = x ## _utf8                              \
+                          ? g_markup_escape_text (x ## _utf8, -1) \
+                          : g_strdup ("");                        \
+      g_free (x ## _utf8);
 
       DEF (copyright);
       DEF (description);
@@ -889,7 +901,7 @@
                              "<family>%s</family>"
                              "<version>%s</version>"
                              // FIX spec has multiple <cve_id>s
-                             "<cve_id>%s</cvs_id>"
+                             "<cve_id>%s</cve_id>"
                              "<bugtraq_id>%s</bugtraq_id>"
                              "<xrefs>%s</xrefs>"
                              "<fingerprints>%s</fingerprints>"
@@ -915,12 +927,12 @@
                              plugin_xrefs (plugin),
                              plugin_fingerprints (plugin),
                              tags_text);
-      g_free (copyright);
-      g_free (description);
-      g_free (summary);
-      g_free (family);
-      g_free (version);
-      g_free (tags);
+      g_free (copyright_text);
+      g_free (description_text);
+      g_free (summary_text);
+      g_free (family_text);
+      g_free (version_text);
+      g_free (tags_text);
     }
   else
     msg = g_strdup_printf ("<nvt>"
@@ -1371,21 +1383,38 @@
       case CLIENT_GET_NVT_FEED_DETAILS:
         if (server.plugins)
           {
-            SEND_TO_CLIENT_OR_FAIL ("<get_nvt_feed_details_response>"
-                                    "<status>" STATUS_OK "</status>");
-            SENDF_TO_CLIENT_OR_FAIL ("<nvt_count>%u</nvt_count>",
-                                     plugins_size (server.plugins));
-            if (server.plugins_md5)
+            SEND_TO_CLIENT_OR_FAIL ("<get_nvt_feed_details_response>");
+            if (current_uuid)
               {
-                SEND_TO_CLIENT_OR_FAIL ("<feed_checksum>"
-                                        "<algorithm>md5</algorithm>");
-                SEND_TO_CLIENT_OR_FAIL (server.plugins_md5);
-                SEND_TO_CLIENT_OR_FAIL ("</feed_checksum>");
+                plugin_t* plugin = find_plugin (server.plugins, current_uuid);
+                if (plugin)
+                  {
+                    SEND_TO_CLIENT_OR_FAIL ("<status>" STATUS_OK "</status>");
+                    send_plugin (plugin->oid, plugin, (gpointer) 1);
+                  }
+                else
+                  {
+                    SEND_TO_CLIENT_OR_FAIL ("<status>"
+                                            STATUS_ERROR_MISSING
+                                            "</status>");
+                  }
               }
-            if (plugins_find (server.plugins, send_plugin, (gpointer) 1))
+            else
               {
-                error_send_to_client (error);
-                return;
+                SENDF_TO_CLIENT_OR_FAIL ("<nvt_count>%u</nvt_count>",
+                                         plugins_size (server.plugins));
+                if (server.plugins_md5)
+                  {
+                    SEND_TO_CLIENT_OR_FAIL ("<feed_checksum>"
+                                            "<algorithm>md5</algorithm>");
+                    SEND_TO_CLIENT_OR_FAIL (server.plugins_md5);
+                    SEND_TO_CLIENT_OR_FAIL ("</feed_checksum>");
+                  }
+                if (plugins_find (server.plugins, send_plugin, (gpointer) 1))
+                  {
+                    error_send_to_client (error);
+                    return;
+                  }
               }
             SEND_TO_CLIENT_OR_FAIL ("</get_nvt_feed_details_response>");
           }
@@ -1405,6 +1434,10 @@
           }
         set_client_state (CLIENT_AUTHENTIC);
         break;
+      case CLIENT_GET_NVT_FEED_DETAILS_OID:
+        assert (strncasecmp ("OID", element_name, 3) == 0);
+        set_client_state (CLIENT_GET_NVT_FEED_DETAILS);
+        break;
 
       case CLIENT_DELETE_REPORT:
         assert (strncasecmp ("DELETE_REPORT", element_name, 13) == 0);
@@ -2023,6 +2056,7 @@
       case CLIENT_DELETE_REPORT_ID:
       case CLIENT_DELETE_TASK_TASK_ID:
       case CLIENT_GET_REPORT_ID:
+      case CLIENT_GET_NVT_FEED_DETAILS_OID:
       case CLIENT_MODIFY_REPORT_REPORT_ID:
       case CLIENT_MODIFY_TASK_TASK_ID:
       case CLIENT_START_TASK_TASK_ID:

Modified: trunk/openvas-manager/src/omp.h
===================================================================
--- trunk/openvas-manager/src/omp.h	2009-05-27 11:33:03 UTC (rev 3491)
+++ trunk/openvas-manager/src/omp.h	2009-05-27 13:19:40 UTC (rev 3492)
@@ -32,7 +32,7 @@
 /**
  * @brief The size of the \ref to_client data buffer, in bytes.
  */
-#define TO_CLIENT_BUFFER_SIZE 1048576
+#define TO_CLIENT_BUFFER_SIZE 5242880
 
 int
 init_omp ();

Modified: trunk/openvas-manager/src/tests/CMakeLists.txt
===================================================================
--- trunk/openvas-manager/src/tests/CMakeLists.txt	2009-05-27 11:33:03 UTC (rev 3491)
+++ trunk/openvas-manager/src/tests/CMakeLists.txt	2009-05-27 13:19:40 UTC (rev 3492)
@@ -214,6 +214,27 @@
 target_link_libraries (omp_get_nvt_feed_details_1 common)
 ADD_TEST (omp_get_nvt_feed_details_1 omp_get_nvt_feed_details_1)
 
+add_executable (omp_get_nvt_feed_details_2 omp_get_nvt_feed_details_2.c)
+target_link_libraries (omp_get_nvt_feed_details_2 string)
+set_target_properties (omp_get_nvt_feed_details_2 PROPERTIES COMPILE_FLAGS "-I .. ${GLIB_CFLAGS}")
+set_target_properties (omp_get_nvt_feed_details_2 PROPERTIES LINK_FLAGS "${OVAS_LDFLAG} ${GLIB_LDFLAGS}")
+target_link_libraries (omp_get_nvt_feed_details_2 common)
+ADD_TEST (omp_get_nvt_feed_details_2 omp_get_nvt_feed_details_2)
+
+add_executable (omp_get_nvt_feed_details_3 omp_get_nvt_feed_details_3.c)
+target_link_libraries (omp_get_nvt_feed_details_3 string)
+set_target_properties (omp_get_nvt_feed_details_3 PROPERTIES COMPILE_FLAGS "-I .. ${GLIB_CFLAGS}")
+set_target_properties (omp_get_nvt_feed_details_3 PROPERTIES LINK_FLAGS "${OVAS_LDFLAG} ${GLIB_LDFLAGS}")
+target_link_libraries (omp_get_nvt_feed_details_3 common)
+ADD_TEST (omp_get_nvt_feed_details_3 omp_get_nvt_feed_details_3)
+
+add_executable (omp_get_nvt_feed_details_4 omp_get_nvt_feed_details_4.c)
+target_link_libraries (omp_get_nvt_feed_details_4 string)
+set_target_properties (omp_get_nvt_feed_details_4 PROPERTIES COMPILE_FLAGS "-I .. ${GLIB_CFLAGS}")
+set_target_properties (omp_get_nvt_feed_details_4 PROPERTIES LINK_FLAGS "${OVAS_LDFLAG} ${GLIB_LDFLAGS}")
+target_link_libraries (omp_get_nvt_feed_details_4 common)
+ADD_TEST (omp_get_nvt_feed_details_4 omp_get_nvt_feed_details_4)
+
 add_executable (omp_get_preferences_0 omp_get_preferences_0.c)
 target_link_libraries (omp_get_preferences_0 string)
 set_target_properties (omp_get_preferences_0 PROPERTIES COMPILE_FLAGS "-I .. ${GLIB_CFLAGS}")

Added: trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_2.c
===================================================================
--- trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_2.c	2009-05-27 11:33:03 UTC (rev 3491)
+++ trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_2.c	2009-05-27 13:19:40 UTC (rev 3492)
@@ -0,0 +1,88 @@
+/* Test 2 of OMP GET_NVT_FEED_DETAILS.
+ * $Id$
+ * Description: Test OMP GET_NVT_FEED_DETAILS with a missing ID.
+ *
+ * Authors:
+ * Matthew Mundell <matt at mundell.ukfsn.org>
+ *
+ * Copyright:
+ * Copyright (C) 2009 Greenbone Networks GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * or, at your option, any later version as published by the Free
+ * Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#define TRACE 1
+
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "common.h"
+#include "../tracef.h"
+
+int
+main ()
+{
+  int socket;
+  gnutls_session_t session;
+
+  verbose = 1;
+
+  socket = connect_to_manager (&session);
+  if (socket == -1) return EXIT_FAILURE;
+
+  /* Request the feed details. */
+
+  if (env_authenticate (&session))
+    {
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+
+  if (send_to_manager (&session,
+                       "<get_nvt_feed_details>"
+                       "<oid>0.0.0.0.0.0.0.0.0.0</oid>"
+                       "</get_nvt_feed_details>")
+      == -1)
+    {
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+
+  /* Read the response. */
+
+  entity_t entity = NULL;
+  read_entity (&session, &entity);
+
+  /* Compare to expected response. */
+
+  entity_t expected = add_entity (NULL, "get_nvt_feed_details_response", NULL);
+  add_entity (&expected->entities, "status", "404");
+
+  if (compare_entities (entity, expected))
+    {
+      free_entity (entity);
+      free_entity (expected);
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+
+  free_entity (expected);
+  free_entity (entity);
+  close_manager_connection (socket, session);
+  return EXIT_SUCCESS;
+}

Added: trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_3.c
===================================================================
--- trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_3.c	2009-05-27 11:33:03 UTC (rev 3491)
+++ trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_3.c	2009-05-27 13:19:40 UTC (rev 3492)
@@ -0,0 +1,86 @@
+/* Test 3 of OMP GET_NVT_FEED_DETAILS.
+ * $Id$
+ * Description: Test OMP GET_NVT_FEED_DETAILS with a bogus ID.
+ *
+ * Authors:
+ * Matthew Mundell <matt at mundell.ukfsn.org>
+ *
+ * Copyright:
+ * Copyright (C) 2009 Greenbone Networks GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * or, at your option, any later version as published by the Free
+ * Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#define TRACE 1
+
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "common.h"
+#include "../tracef.h"
+
+int
+main ()
+{
+  int socket;
+  gnutls_session_t session;
+
+  socket = connect_to_manager (&session);
+  if (socket == -1) return EXIT_FAILURE;
+
+  /* Request the feed details. */
+
+  if (env_authenticate (&session))
+    {
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+
+  if (send_to_manager (&session,
+                       "<get_nvt_feed_details>"
+                       "<oid>-*_*-</oid>"
+                       "</get_nvt_feed_details>")
+      == -1)
+    {
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+
+  /* Read the response. */
+
+  entity_t entity = NULL;
+  read_entity (&session, &entity);
+
+  /* Compare to expected response. */
+
+  entity_t expected = add_entity (NULL, "get_nvt_feed_details_response", NULL);
+  add_entity (&expected->entities, "status", "404");
+
+  if (compare_entities (entity, expected))
+    {
+      free_entity (entity);
+      free_entity (expected);
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+
+  free_entity (expected);
+  free_entity (entity);
+  close_manager_connection (socket, session);
+  return EXIT_SUCCESS;
+}

Added: trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_4.c
===================================================================
--- trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_4.c	2009-05-27 11:33:03 UTC (rev 3491)
+++ trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_4.c	2009-05-27 13:19:40 UTC (rev 3492)
@@ -0,0 +1,201 @@
+/* Test 4 of OMP GET_NVT_FEED_DETAILS.
+ * $Id$
+ * Description: Test the OMP GET_NVT_FEED_DETAILS with a known ID.
+ *
+ * Authors:
+ * Matthew Mundell <matt at mundell.ukfsn.org>
+ *
+ * Copyright:
+ * Copyright (C) 2009 Greenbone Networks GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * or, at your option, any later version as published by the Free
+ * Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#define TRACE 1
+
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "common.h"
+#include "../tracef.h"
+
+int
+main ()
+{
+  int socket;
+  gnutls_session_t session;
+  char* id;
+  entity_t entity, entity2, status, nvt, nvt_id;
+
+  verbose = 1;
+
+  socket = connect_to_manager (&session);
+  if (socket == -1) return EXIT_FAILURE;
+
+  if (env_authenticate (&session))
+    {
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+
+  /* Request feed information once, so manager requests it from server. */
+
+  if (send_to_manager (&session, "<get_nvt_feed_all/>") == -1)
+    {
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+  entity = NULL;
+  if (read_entity (&session, &entity))
+    {
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+  free_entity (entity);
+
+  /* Create a task. */
+
+  if (create_task_from_rc_file (&session,
+                                "new_task_small_rc",
+                                "Task for omp_get_nvt_feed_details_1",
+                                "Test omp_get_nvt_feed_details_1 task.",
+                                &id))
+    {
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+
+  /* Start the task. */
+
+  if (start_task (&session, id))
+    {
+      delete_task (&session, id);
+      close_manager_connection (socket, session);
+      free (id);
+      return EXIT_FAILURE;
+    }
+
+  /* Wait for the task to start on the server. */
+
+  if (wait_for_task_start (&session, id))
+    {
+      delete_task (&session, id);
+      close_manager_connection (socket, session);
+      free (id);
+      return EXIT_FAILURE;
+    }
+
+  /* Request the task status. */
+
+#if 0
+  if (env_authenticate (&session))
+    {
+      delete_task (&session, id);
+      close_manager_connection (socket, session);
+      free (id);
+      return EXIT_FAILURE;
+    }
+#endif
+
+  if (sendf_to_manager (&session,
+                        "<status><task_id>%s</task_id></status>",
+                        id)
+      == -1)
+    {
+      delete_task (&session, id);
+      close_manager_connection (socket, session);
+      free (id);
+      return EXIT_FAILURE;
+    }
+
+  entity = NULL;
+  if (read_entity (&session, &entity))
+    {
+      delete_task (&session, id);
+      close_manager_connection (socket, session);
+      free (id);
+      return EXIT_FAILURE;
+    }
+  free_entity (entity);
+
+  delete_task (&session, id);
+  free (id);
+
+  /* Get all feed details, to get details of one NVT. */
+
+  if (send_to_manager (&session, "<get_nvt_feed_details/>") == -1)
+    {
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+  entity = NULL;
+  if (read_entity (&session, &entity))
+    {
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+  nvt = entity_child (entity, "nvt");
+  if (nvt == NULL
+      || (nvt_id = entity_child (nvt, "oid")) == NULL)
+    {
+      free_entity (entity);
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+
+  /* Request details of the NVT. */
+
+  if (sendf_to_manager (&session,
+                        "<get_nvt_feed_details>"
+                        "<oid>%s</oid>"
+                        "</get_nvt_feed_details>",
+                        entity_text (nvt_id))
+      == -1)
+    {
+      free_entity (entity);
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+
+  /* Read the response. */
+
+  entity2 = NULL;
+  if (read_entity (&session, &entity2))
+    {
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+  if (entity) print_entity (stdout, entity);
+
+  /* Compare to expected response. */
+
+  if (entity2 == NULL
+      || strcmp (entity_name (entity2), "get_nvt_feed_details_response")
+      || (status = entity_child (entity2, "status")) == NULL
+      || strcmp (entity_text (status), "200")
+      || compare_entities (entity_child (entity, "nvt"), nvt))
+    {
+      free_entity (entity);
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+
+  free_entity (entity);
+  close_manager_connection (socket, session);
+  return EXIT_SUCCESS;
+}



More information about the Openvas-commits mailing list