[Openvas-commits] r3484 - in trunk/openvas-manager: . src src/tests
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue May 26 19:46:12 CEST 2009
Author: mattm
Date: 2009-05-26 19:46:12 +0200 (Tue, 26 May 2009)
New Revision: 3484
Modified:
trunk/openvas-manager/ChangeLog
trunk/openvas-manager/src/omp.c
trunk/openvas-manager/src/tests/omp_get_nvt_feed_all_1.c
trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_0.c
trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_1.c
Log:
Implement OMP GET_NVT_FEED_DETAILS when called to return all NVTs.
* src/omp.c (send_plugin): Add a details option.
(omp_xml_handle_end_element): Add real CLIENT_GET_NVT_FEED_DETAILS
handling.
* src/tests/omp_get_nvt_feed_details_0.c: Improve comments. Use new status
code.
* src/tests/omp_get_nvt_feed_details_1.c: Get feed initially. Check
response.
* src/tests/omp_get_nvt_feed_all_1.c: Also check for response status 503.
Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog 2009-05-26 16:43:12 UTC (rev 3483)
+++ trunk/openvas-manager/ChangeLog 2009-05-26 17:46:12 UTC (rev 3484)
@@ -1,5 +1,21 @@
2009-05-26 Matthew Mundell <mmundell at intevation.de>
+ Implement OMP GET_NVT_FEED_DETAILS when called to return all NVTs.
+
+ * src/omp.c (send_plugin): Add a details option.
+ (omp_xml_handle_end_element): Add real CLIENT_GET_NVT_FEED_DETAILS
+ handling.
+
+ * src/tests/omp_get_nvt_feed_details_0.c: Improve comments. Use new status
+ code.
+
+ * src/tests/omp_get_nvt_feed_details_1.c: Get feed initially. Check
+ response.
+
+ * src/tests/omp_get_nvt_feed_all_1.c: Also check for response status 503.
+
+2009-05-26 Matthew Mundell <mmundell at intevation.de>
+
Implement OMP GET_NVT_FEED_ALL.
* src/manage.c (plugin_t, plugins_t): New types.
Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c 2009-05-26 16:43:12 UTC (rev 3483)
+++ trunk/openvas-manager/src/omp.c 2009-05-26 17:46:12 UTC (rev 3484)
@@ -855,25 +855,87 @@
* @return TRUE if out of space in to_client buffer, else FALSE.
*/
static gboolean
-send_plugin (gpointer oid_gp, gpointer plugin_gp, /*@unused@*/ gpointer dummy)
+send_plugin (gpointer oid_gp, gpointer plugin_gp, gpointer details_gp)
{
plugin_t* plugin = (plugin_t*) plugin_gp;
char* oid = (char*) oid_gp;
char* name = plugin_name (plugin);
+ int details = (int) details_gp;
+ gchar* msg;
gchar* name_text = g_markup_escape_text (name, strlen (name));
- gchar* msg = g_strdup_printf ("<nvt>"
- "<oid>%s</oid>"
- "<name>%s</name>"
+ if (details)
+ {
+
+#define DEF(x) \
+ char* x = plugin_ ## x (plugin); \
+ gchar* x ## _text = g_markup_escape_text (x, \
+ strlen (x))
+
+ DEF (copyright);
+ DEF (description);
+ DEF (summary);
+ DEF (family);
+ DEF (version);
+ DEF (tags);
+
+ msg = g_strdup_printf ("<nvt>"
+ "<oid>%s</oid>"
+ "<name>%s</name>"
+ "<category>%s</category>"
+ "<copyright>%s</copyright>"
+ "<description>%s</description>"
+ "<summary>%s</summary>"
+ "<family>%s</family>"
+ "<version>%s</version>"
+ // FIX spec has multiple <cve_id>s
+ "<cve_id>%s</cvs_id>"
+ "<bugtraq_id>%s</bugtraq_id>"
+ "<xrefs>%s</xrefs>"
+ "<fingerprints>%s</fingerprints>"
+ "<tags>%s</tags>"
#if 0
- "<checksum>"
- "<algorithm>md5</algorithm>"
- "%s"
- "</checksum>"
+ // FIX implement
+ "<checksum>"
+ "<algorithm>md5</algorithm>"
+ "%s"
+ "</checksum>"
#endif
- "</nvt>",
- oid,
- name_text);
+ "</nvt>",
+ oid,
+ name_text,
+ plugin_category (plugin),
+ copyright_text,
+ description_text,
+ summary_text,
+ family_text,
+ version_text,
+ plugin_cve_id (plugin),
+ plugin_bugtraq_id (plugin),
+ 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);
+ }
+ else
+ msg = g_strdup_printf ("<nvt>"
+ "<oid>%s</oid>"
+ "<name>%s</name>"
+#if 0
+ // FIX implement
+ "<checksum>"
+ "<algorithm>md5</algorithm>"
+ "%s"
+ "</checksum>"
+#endif
+ "</nvt>",
+ oid,
+ name_text);
g_free (name_text);
if (send_to_client (msg))
{
@@ -1266,7 +1328,7 @@
SEND_TO_CLIENT_OR_FAIL (server.plugins_md5);
SEND_TO_CLIENT_OR_FAIL ("</feed_checksum>");
}
- if (plugins_find (server.plugins, send_plugin, NULL))
+ if (plugins_find (server.plugins, send_plugin, (gpointer) 0))
{
error_send_to_client (error);
return;
@@ -1307,25 +1369,40 @@
break;
case CLIENT_GET_NVT_FEED_DETAILS:
- SEND_TO_CLIENT_OR_FAIL ("<get_nvt_feed_details_response>"
- "<status>" STATUS_OK "</status>");
- // FIX
- SEND_TO_CLIENT_OR_FAIL ("<nvt>"
- "<oid>1.3.6.1.4.1.25623.1.7.13005</oid>"
- "<cve>CVE-2008-4877</cve>"
- "<cve>CVE-2008-4881</cve>"
- "<bugtraq_id>12345</bugtraq_id>"
- "<filename>foobar_15_detect.nasl</filename>"
- "<description>This script detects whether FooBar 1.5 is installed.</description>"
- "</nvt>");
- SEND_TO_CLIENT_OR_FAIL ("<nvt>"
- "<oid>1.3.6.1.4.1.25623.1.7.13006</oid>"
- "<cve>CVE-2008-5142</cve>"
- "<bugtraq_id>12478</bugtraq_id>"
- "<filename>foobar_21_xss.nasl</filename>"
- "<description>This script detects whether the FooBar 2.1 XSS vulnerability is present.</description>"
- "</nvt>");
- SEND_TO_CLIENT_OR_FAIL ("</get_nvt_feed_details_response>");
+ 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 ("<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>");
+ }
+ else
+ {
+ SEND_TO_CLIENT_OR_FAIL ("<get_nvt_feed_details_response>"
+ "<status>" STATUS_SERVICE_DOWN "</status>"
+ "</get_nvt_feed_details_response>");
+ /* \todo TODO Sort out a cache for this. */
+ if (request_plugin_list ())
+ {
+ /* to_server is full. */
+ // FIX ~ revert parsing for retry
+ // process_omp_client_input must return -2
+ abort ();
+ }
+ }
set_client_state (CLIENT_AUTHENTIC);
break;
Modified: trunk/openvas-manager/src/tests/omp_get_nvt_feed_all_1.c
===================================================================
--- trunk/openvas-manager/src/tests/omp_get_nvt_feed_all_1.c 2009-05-26 16:43:12 UTC (rev 3483)
+++ trunk/openvas-manager/src/tests/omp_get_nvt_feed_all_1.c 2009-05-26 17:46:12 UTC (rev 3484)
@@ -161,7 +161,9 @@
if (entity == NULL
|| strcmp (entity_name (entity), "get_nvt_feed_all_response")
|| (status = entity_child (entity, "status")) == NULL
- || strcmp (entity_text (status), "200"))
+ || (strcmp (entity_text (status), "200")
+
+ && strcmp (entity_text (status), "503")))
{
free_entity (entity);
delete_task (&session, id);
Modified: trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_0.c
===================================================================
--- trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_0.c 2009-05-26 16:43:12 UTC (rev 3483)
+++ trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_0.c 2009-05-26 17:46:12 UTC (rev 3484)
@@ -1,6 +1,6 @@
-/* Test 1 of OMP GET_NVT_FEED_DETAILS.
+/* Test 0 of OMP GET_NVT_FEED_DETAILS.
* $Id$
- * Description: Test the OMP GET_NVT_FEED_DETAILS command on a running task.
+ * Description: Test the OMP GET_NVT_FEED_DETAILS command before a task runs.
*
* Authors:
* Matthew Mundell <matt at mundell.ukfsn.org>
@@ -43,7 +43,7 @@
socket = connect_to_manager (&session);
if (socket == -1) return EXIT_FAILURE;
- /* Get the preferences. */
+ /* Request the feed details. */
if (env_authenticate (&session))
{
@@ -65,7 +65,7 @@
/* Compare to expected response. */
entity_t expected = add_entity (NULL, "get_nvt_feed_details_response", NULL);
- add_entity (&expected->entities, "status", "500");
+ add_entity (&expected->entities, "status", "503");
if (compare_entities (entity, expected))
{
Modified: trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_1.c
===================================================================
--- trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_1.c 2009-05-26 16:43:12 UTC (rev 3483)
+++ trunk/openvas-manager/src/tests/omp_get_nvt_feed_details_1.c 2009-05-26 17:46:12 UTC (rev 3484)
@@ -1,6 +1,6 @@
/* Test 1 of OMP GET_NVT_FEED_DETAILS.
* $Id$
- * Description: Test the OMP GET_NVT_FEED_DETAILS command on a running task.
+ * Description: Test the OMP GET_NVT_FEED_DETAILS command after a task runs.
*
* Authors:
* Matthew Mundell <matt at mundell.ukfsn.org>
@@ -40,18 +40,34 @@
int socket;
gnutls_session_t session;
char* id;
+ entity_t entity, status;
socket = connect_to_manager (&session);
if (socket == -1) return EXIT_FAILURE;
- /* Create a task. */
-
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",
@@ -95,7 +111,7 @@
#endif
if (sendf_to_manager (&session,
- "<status><task_id>%i</task_id></status>",
+ "<status><task_id>%s</task_id></status>",
id)
== -1)
{
@@ -105,7 +121,7 @@
return EXIT_FAILURE;
}
- entity_t entity = NULL;
+ entity = NULL;
if (read_entity (&session, &entity))
{
delete_task (&session, id);
@@ -115,7 +131,7 @@
}
free_entity (entity);
- /* Get the preferences. */
+ /* Get the feed details. */
#if 0
if (env_authenticate (&session))
@@ -141,23 +157,21 @@
read_entity (&session, &entity);
if (entity) print_entity (stdout, entity);
-#if 0
/* Compare to expected response. */
- entity_t expected = add_entity (NULL, "get_nvt_feed_details_response", FIX);
-
- if (compare_entities (entity, expected))
+ if (entity == NULL
+ || strcmp (entity_name (entity), "get_nvt_feed_details_response")
+ || (status = entity_child (entity, "status")) == NULL
+ || (strcmp (entity_text (status), "200")
+ && strcmp (entity_text (status), "503")))
{
free_entity (entity);
- free_entity (expected);
delete_task (&session, id);
close_manager_connection (socket, session);
free (id);
return EXIT_FAILURE;
}
- free_entity (expected);
-#endif
free_entity (entity);
delete_task (&session, id);
close_manager_connection (socket, session);
More information about the Openvas-commits
mailing list