[Openvas-commits] r5659 - in trunk/openvas-administrator: . src src/tests

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Oct 21 11:59:08 CEST 2009


Author: mattm
Date: 2009-10-21 11:59:07 +0200 (Wed, 21 Oct 2009)
New Revision: 5659

Added:
   trunk/openvas-administrator/src/tests/oap_delete_user_1.c
Modified:
   trunk/openvas-administrator/ChangeLog
   trunk/openvas-administrator/src/oap.c
   trunk/openvas-administrator/src/tests/CMakeLists.txt
Log:
	* src/oad.c (oap_xml_handle_start_element): Correct command name in
	CLIENT_DELETE_USER response.
	(oap_xml_handle_end_element): Respond with failure if the requested user
	is the current user.
	(init_oap): Init current_credentials.

	* src/tests/oap_delete_user_1.c: New file.  Tests removing current user.

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

Modified: trunk/openvas-administrator/ChangeLog
===================================================================
--- trunk/openvas-administrator/ChangeLog	2009-10-21 08:12:07 UTC (rev 5658)
+++ trunk/openvas-administrator/ChangeLog	2009-10-21 09:59:07 UTC (rev 5659)
@@ -1,3 +1,15 @@
+2009-09-29  Matthew Mundell <matthew.mundell at intevation.de>
+
+	* src/oad.c (oap_xml_handle_start_element): Correct command name in
+	CLIENT_DELETE_USER response.
+	(oap_xml_handle_end_element): Respond with failure if the requested user
+	is the current user.
+	(init_oap): Init current_credentials.
+
+	* src/tests/oap_delete_user_1.c: New file.  Tests removing current user.
+
+	* src/tests/CMakeLists.txt: Add oap_delete_user_1.
+
 2009-10-19  Michael Wiegand <michael.wiegand at intevation.de>
 
 	Post release version bump.

Modified: trunk/openvas-administrator/src/oap.c
===================================================================
--- trunk/openvas-administrator/src/oap.c	2009-10-21 08:12:07 UTC (rev 5658)
+++ trunk/openvas-administrator/src/oap.c	2009-10-21 09:59:07 UTC (rev 5659)
@@ -777,7 +777,7 @@
         break;
 
       case CLIENT_DELETE_USER:
-        if (send_element_error_to_client ("delete_task", element_name))
+        if (send_element_error_to_client ("delete_user", element_name))
           {
             error_send_to_client (error);
             return;
@@ -950,21 +950,26 @@
         if (current_string_1)
           {
             assert (users_dir);
-            switch (openvas_admin_remove_user (current_string_1, users_dir))
-              {
-                case 0:
-                  SEND_TO_CLIENT_OR_FAIL (XML_OK ("delete_user"));
-                  break;
-                case -2:
-                  SEND_TO_CLIENT_OR_FAIL
-                   (XML_ERROR_SYNTAX ("delete_user",
-                                      "Failed to find user"));
-                  break;
-                default:
-                case -1:
-                  SEND_TO_CLIENT_OR_FAIL (XML_INTERNAL_ERROR ("delete_user"));
-                  break;
-              }
+            if (strcmp (current_credentials.username, current_string_1) == 0)
+              SEND_TO_CLIENT_OR_FAIL
+               (XML_ERROR_SYNTAX ("delete_user",
+                                  "Attempt to delete current user"));
+            else
+              switch (openvas_admin_remove_user (current_string_1, users_dir))
+                {
+                  case 0:
+                    SEND_TO_CLIENT_OR_FAIL (XML_OK ("delete_user"));
+                    break;
+                  case -2:
+                    SEND_TO_CLIENT_OR_FAIL
+                     (XML_ERROR_SYNTAX ("delete_user",
+                                        "Failed to find user"));
+                    break;
+                  default:
+                  case -1:
+                    SEND_TO_CLIENT_OR_FAIL (XML_INTERNAL_ERROR ("delete_user"));
+                    break;
+                }
             openvas_free_string_var (&current_string_1);
           }
         else
@@ -1152,6 +1157,8 @@
                      (GLogFunc) openvas_log_func,
                      log_config);
   users_dir = users_directory;
+  current_credentials.username = NULL;
+  current_credentials.password = NULL;
   return 0;
 }
 

Modified: trunk/openvas-administrator/src/tests/CMakeLists.txt
===================================================================
--- trunk/openvas-administrator/src/tests/CMakeLists.txt	2009-10-21 08:12:07 UTC (rev 5658)
+++ trunk/openvas-administrator/src/tests/CMakeLists.txt	2009-10-21 09:59:07 UTC (rev 5659)
@@ -98,6 +98,12 @@
 target_link_libraries (oap_delete_user_0 common)
 ADD_TEST (oap_delete_user_0 oap_delete_user_0)
 
+add_executable (oap_delete_user_1 oap_delete_user_1.c)
+set_target_properties (oap_delete_user_1 PROPERTIES COMPILE_FLAGS "${GLIB_CFLAGS} ${OVAS_CFLAGS}")
+set_target_properties (oap_delete_user_1 PROPERTIES LINK_FLAGS "${OVAS_LDFLAG} ${GLIB_LDFLAGS}")
+target_link_libraries (oap_delete_user_1 common)
+ADD_TEST (oap_delete_user_1 oap_delete_user_1)
+
 add_executable (oap_get_users_0 oap_get_users_0.c)
 set_target_properties (oap_get_users_0 PROPERTIES COMPILE_FLAGS "${GLIB_CFLAGS} ${OVAS_CFLAGS}")
 set_target_properties (oap_get_users_0 PROPERTIES LINK_FLAGS "${OVAS_LDFLAG} ${GLIB_LDFLAGS}")

Added: trunk/openvas-administrator/src/tests/oap_delete_user_1.c
===================================================================
--- trunk/openvas-administrator/src/tests/oap_delete_user_1.c	2009-10-21 08:12:07 UTC (rev 5658)
+++ trunk/openvas-administrator/src/tests/oap_delete_user_1.c	2009-10-21 09:59:07 UTC (rev 5659)
@@ -0,0 +1,98 @@
+/* Test 1 of removing a user.
+ * $Id$
+ * Description: Test OAP DELETE_USER on current user.
+ *
+ * Authors:
+ * Matthew Mundell <matthew.mundell at intevation.de>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "common.h"
+#include "../tracef.h"
+#include "../string.h"
+
+int
+main ()
+{
+  int socket;
+  gnutls_session_t session;
+  entity_t entity;
+  char *name;
+
+  setup_test ();
+
+  /* Get the user name. */
+
+  name = getenv ("OPENVAS_TEST_USER");
+  if (name == NULL)
+    {
+      name = getenv ("USER");
+      if (name == NULL) return EXIT_FAILURE;
+    }
+
+  /* Connect and auth as that user. */
+
+  socket = connect_to_manager (&session);
+  if (socket == -1) return EXIT_FAILURE;
+
+  if (omp_authenticate_env (&session))
+    {
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+
+  /* Try delete the user. */
+
+  if (openvas_server_sendf (&session,
+                            "<delete_user name=\"%s\"/>",
+                            name)
+      == -1)
+    {
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+
+  entity = NULL;
+  if (read_entity (&session, &entity))
+    {
+      close_manager_connection (socket, session);
+      return EXIT_FAILURE;
+    }
+
+  /* Check the response. */
+
+  if (entity_attribute (entity, "status")
+      && (strcmp (entity_attribute (entity, "status"), "400") == 0))
+    {
+      free_entity (entity);
+      close_manager_connection (socket, session);
+      return EXIT_SUCCESS;
+    }
+
+  free_entity (entity);
+  close_manager_connection (socket, session);
+  return EXIT_FAILURE;
+}



More information about the Openvas-commits mailing list