[Openvas-commits] r5359 - in trunk/openvas-manager: . src src/tests
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sat Oct 3 12:15:29 CEST 2009
Author: mattm
Date: 2009-10-03 12:15:27 +0200 (Sat, 03 Oct 2009)
New Revision: 5359
Added:
trunk/openvas-manager/src/tests/omp_get_preferences_2.c
Modified:
trunk/openvas-manager/ChangeLog
trunk/openvas-manager/src/otp.c
trunk/openvas-manager/src/tests/CMakeLists.txt
Log:
When parsing the OTP PREFERENCES, read in all the preferences before
enabling them, otherwise OMP GET_PREFERENCES might return a partial
set of preferences.
* src/otp.c (current_scanner_preferences): New variable.
(make_scanner_preferences): Return preferences instead of setting scanner.
(add_scanner_preference): Set preference on a given preference table
instead of on scanner.preferences. Update caller.
(process_otp_scanner_input): Initialise current_scanner_preferences
with the make_scanner_preferences return. In SCANNER_PREFERENCE_NAME set
scanner.preferences to current_scanner_preferences.
* src/tests/omp_get_preferences_2.c: New file. Tests that first two
successful returns from GET_PREFERENCES are identical.
* src/tests/CMakeLists.txt: Add omp_get_preferences_2.
Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog 2009-10-02 17:48:14 UTC (rev 5358)
+++ trunk/openvas-manager/ChangeLog 2009-10-03 10:15:27 UTC (rev 5359)
@@ -1,3 +1,22 @@
+2009-09-30 Matthew Mundell <matthew.mundell at intevation.de>
+
+ When parsing the OTP PREFERENCES, read in all the preferences before
+ enabling them, otherwise OMP GET_PREFERENCES might return a partial
+ set of preferences.
+
+ * src/otp.c (current_scanner_preferences): New variable.
+ (make_scanner_preferences): Return preferences instead of setting scanner.
+ (add_scanner_preference): Set preference on a given preference table
+ instead of on scanner.preferences. Update caller.
+ (process_otp_scanner_input): Initialise current_scanner_preferences
+ with the make_scanner_preferences return. In SCANNER_PREFERENCE_NAME set
+ scanner.preferences to current_scanner_preferences.
+
+ * src/tests/omp_get_preferences_2.c: New file. Tests that first two
+ successful returns from GET_PREFERENCES are identical.
+
+ * src/tests/CMakeLists.txt: Add omp_get_preferences_2.
+
2009-09-30 Jan-Oliver Wagner <jan-oliver.wagner at greenbone.net>
Post-release version bump.
Modified: trunk/openvas-manager/src/otp.c
===================================================================
--- trunk/openvas-manager/src/otp.c 2009-10-02 17:48:14 UTC (rev 5358)
+++ trunk/openvas-manager/src/otp.c 2009-10-03 10:15:27 UTC (rev 5359)
@@ -35,6 +35,13 @@
* task records according to the OTP messages in the string.
*/
+/**
+ * @todo
+ * Ensure that the globals used to store information across the XML
+ * parser callbacks (for example, current_scanner_preferences) are freed in
+ * the failure cases.
+ */
+
#include "otp.h"
#include "manage.h"
#include "tracef.h"
@@ -411,16 +418,20 @@
static char* current_scanner_preference = NULL;
/**
+ * @brief The current scanner preferences, during reading of scanner preferences.
+ */
+static GHashTable* current_scanner_preferences = NULL;
+
+/**
* @brief Create the scanner preferences.
*/
-static void
+static GHashTable*
make_scanner_preferences ()
{
- if (scanner.preferences) g_hash_table_destroy (scanner.preferences);
- scanner.preferences = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- g_free);
+ return g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ g_free);
}
/**
@@ -433,9 +444,11 @@
* @param[in] value The value of the preference.
*/
static void
-add_scanner_preference (/*@keep@*/ char* preference, /*@keep@*/ char* value)
+add_scanner_preference (GHashTable* preferences,
+ /*@keep@*/ char* preference,
+ /*@keep@*/ char* value)
{
- g_hash_table_insert (scanner.preferences, preference, value);
+ g_hash_table_insert (preferences, preference, value);
}
@@ -1003,7 +1016,9 @@
{
match[0] = '\0';
value = g_strdup (*messages);
- add_scanner_preference (current_scanner_preference, value);
+ add_scanner_preference (current_scanner_preferences,
+ current_scanner_preference,
+ value);
set_scanner_state (SCANNER_PREFERENCE_NAME);
from_scanner_start += match + 1 - *messages;
*messages = match + 1;
@@ -2127,6 +2142,10 @@
if (sync_buffer ()) return -1;
return 0;
}
+ if (scanner.preferences)
+ g_hash_table_destroy (scanner.preferences);
+ scanner.preferences = current_scanner_preferences;
+ current_scanner_preferences = NULL;
break;
}
{
@@ -2196,7 +2215,8 @@
set_scanner_state (SCANNER_PORT_HOST);
else if (strcasecmp ("PREFERENCES", field) == 0)
{
- make_scanner_preferences ();
+ assert (current_scanner_preference == NULL);
+ current_scanner_preferences = make_scanner_preferences ();
set_scanner_state (SCANNER_PREFERENCE_NAME);
}
else if (strcasecmp ("RULES", field) == 0)
Modified: trunk/openvas-manager/src/tests/CMakeLists.txt
===================================================================
--- trunk/openvas-manager/src/tests/CMakeLists.txt 2009-10-02 17:48:14 UTC (rev 5358)
+++ trunk/openvas-manager/src/tests/CMakeLists.txt 2009-10-03 10:15:27 UTC (rev 5359)
@@ -410,6 +410,12 @@
target_link_libraries (omp_get_preferences_1 common)
ADD_TEST (omp_get_preferences_1 omp_get_preferences_1)
+add_executable (omp_get_preferences_2 omp_get_preferences_2.c)
+set_target_properties (omp_get_preferences_2 PROPERTIES COMPILE_FLAGS "${GLIB_CFLAGS} ${OVAS_CFLAGS}")
+set_target_properties (omp_get_preferences_2 PROPERTIES LINK_FLAGS "${OVAS_LDFLAG} ${GLIB_LDFLAGS}")
+target_link_libraries (omp_get_preferences_2 common)
+ADD_TEST (omp_get_preferences_2 omp_get_preferences_2)
+
add_executable (omp_get_report_0 omp_get_report_0.c)
set_target_properties (omp_get_report_0 PROPERTIES COMPILE_FLAGS "${GLIB_CFLAGS} ${OVAS_CFLAGS}")
set_target_properties (omp_get_report_0 PROPERTIES LINK_FLAGS "${OVAS_LDFLAG} ${GLIB_LDFLAGS}")
Added: trunk/openvas-manager/src/tests/omp_get_preferences_2.c
===================================================================
--- trunk/openvas-manager/src/tests/omp_get_preferences_2.c 2009-10-02 17:48:14 UTC (rev 5358)
+++ trunk/openvas-manager/src/tests/omp_get_preferences_2.c 2009-10-03 10:15:27 UTC (rev 5359)
@@ -0,0 +1,96 @@
+/* Test 1 of OMP GET_PREFERENCES.
+ * $Id$
+ * Description: Test the OMP GET_PREFERENCES command.
+ *
+ * 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;
+ entity_t preferences_1, preferences_2;
+
+ setup_test ();
+
+ socket = connect_to_manager (&session);
+ if (socket == -1) return EXIT_FAILURE;
+
+ if (omp_authenticate_env (&session))
+ {
+ close_manager_connection (socket, session);
+ return EXIT_FAILURE;
+ }
+
+ if (omp_get_preferences_503 (&session, &preferences_1))
+ {
+ close_manager_connection (socket, session);
+ return EXIT_FAILURE;
+ }
+
+ /* Get the preferences. */
+
+ if (openvas_server_send (&session, "<get_preferences />") == -1)
+ {
+ free_entity (preferences_1);
+ close_manager_connection (socket, session);
+ return EXIT_FAILURE;
+ }
+
+ /* Read the response. */
+
+ preferences_2 = NULL;
+ read_entity (&session, &preferences_2);
+ if (preferences_2) print_entity (stdout, preferences_2);
+
+ /* Compare to expected response. */
+
+ if (preferences_2
+ && entity_attribute (preferences_2, "status")
+ && (strcmp (entity_attribute (preferences_2, "status"), "200") == 0)
+ && (strcmp (entity_attribute (preferences_2, "status_text"), "OK") == 0))
+ {
+ if (compare_entities (preferences_1, preferences_2) == 0)
+ {
+ free_entity (preferences_1);
+ free_entity (preferences_2);
+ close_manager_connection (socket, session);
+ return EXIT_SUCCESS;
+ }
+ free_entity (preferences_1);
+ }
+
+ if (preferences_2) free_entity (preferences_2);
+ close_manager_connection (socket, session);
+ return EXIT_FAILURE;
+}
More information about the Openvas-commits
mailing list