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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Dec 30 20:12:42 CET 2009


Author: mattm
Date: 2009-12-30 20:12:40 +0100 (Wed, 30 Dec 2009)
New Revision: 6284

Modified:
   trunk/openvas-administrator/ChangeLog
   trunk/openvas-administrator/src/admin.c
   trunk/openvas-administrator/src/admin.h
   trunk/openvas-administrator/src/oap.c
   trunk/openvas-administrator/src/oapd.c
   trunk/openvas-administrator/src/openvasad.c
   trunk/openvas-administrator/src/tests/oap_help_0.c
Log:
	* src/oapd.c (serve_omp): Just read and log a character on select
	exception, instead of failing.

	* src/admin.c (strcmp_desc): New function.
	(openvas_admin_list_users): Add ascending arg to control user sorting.

	* src/admin.h: Update header accordingly.

	* src/openvasad.c (is_parent): Format doc.
	(main): Update call to openvas_admin_list_users.

	* src/oap.c (help_text): Bring down to 80 chars wide.
	(oap_xml_handle_start_element): In CLIENT_GET_USERS store sort_order
	attribute.
	(oap_xml_handle_end_element): In CLIENT_GET_USERS pass sort_order
	to openvas_admin_list_users.

	* src/tests/oap_help_0.c (help_text): Match to current value.

	* ChangeLog: Cleanup some formatting.

Modified: trunk/openvas-administrator/ChangeLog
===================================================================
--- trunk/openvas-administrator/ChangeLog	2009-12-30 18:01:18 UTC (rev 6283)
+++ trunk/openvas-administrator/ChangeLog	2009-12-30 19:12:40 UTC (rev 6284)
@@ -1,3 +1,26 @@
+2009-12-30  Matthew Mundell <matthew.mundell at intevation.de>
+
+	* src/oapd.c (serve_omp): Just read and log a character on select
+	exception, instead of failing.
+
+	* src/admin.c (strcmp_desc): New function.
+	(openvas_admin_list_users): Add ascending arg to control user sorting.
+
+	* src/admin.h: Update header accordingly.
+
+	* src/openvasad.c (is_parent): Format doc.
+	(main): Update call to openvas_admin_list_users.
+
+	* src/oap.c (help_text): Bring down to 80 chars wide.
+	(oap_xml_handle_start_element): In CLIENT_GET_USERS store sort_order
+	attribute.
+	(oap_xml_handle_end_element): In CLIENT_GET_USERS pass sort_order
+	to openvas_admin_list_users.
+
+	* src/tests/oap_help_0.c (help_text): Match to current value.
+
+	* ChangeLog: Cleanup some formatting.
+
 2009-12-23  Felix Wolfsteller <felix.wolfsteller at intevation.de>
 
 	Applied patch from Vladimir Nadvornik. Compiled libraries do not need
@@ -135,8 +158,8 @@
 	synchronization script.
 
 	* src/admin.c: Added new functions for lockfile management.
-	(openvasad_create_lockfile, openvasad_remove_lockfile,
-	openvasad_currently_syncing): New.
+	(openvasad_create_lockfile, openvasad_remove_lockfile)
+	(openvasad_currently_syncing): New.
 
 	* src/admin.h: Updated header.
 
@@ -257,7 +280,7 @@
 	(g_key_file_free, g_slist_free, g_string_free, g_option_context_free): New
 	headers.
 
-	* src/oap.c: (oap_xml_handle_end_element): In CLIENT_GET_USERS use a temp
+	* src/oap.c (oap_xml_handle_end_element): In CLIENT_GET_USERS use a temp
 	var to iterate over the list and free the list data.
 
 	* src/openvasad.c: Include splint.h.  Move variable declarations to block

Modified: trunk/openvas-administrator/src/admin.c
===================================================================
--- trunk/openvas-administrator/src/admin.c	2009-12-30 18:01:18 UTC (rev 6283)
+++ trunk/openvas-administrator/src/admin.c	2009-12-30 19:12:40 UTC (rev 6284)
@@ -190,10 +190,25 @@
 }
 
 /**
+ * @brief Descending strcmp.
+ *
+ * @param  one  First string.
+ * @param  two  Second string.
+ *
+ * @return Negation of return from strcmp on args.
+ */
+static int
+strcmp_desc (const char *one, const char *two)
+{
+  return - strcmp (one, two);
+}
+
+/**
  * @brief Returns a list of user directories (= users) found in a given
  * directory.
  *
- * @param directory The complete name of the directory.
+ * @param  directory  The complete name of the directory.
+ * @param  ascending  Ascending order if true, descending order if 0.
  *
  * @return A pointer to a GSList containing the names of the users or NULL if
  * the directory could not be opened, did not exist or was not a directory.
@@ -201,7 +216,7 @@
  * element of the list should be freed with g_free.
  */
 GSList *
-openvas_admin_list_users (const gchar * directory)
+openvas_admin_list_users (const gchar * directory, int ascending)
 {
   GSList *users = NULL;
 
@@ -233,11 +248,17 @@
                                                       "auth", "dname", NULL);
               if (g_file_test (user_hash_filename, G_FILE_TEST_EXISTS))
                 {
-                  users = g_slist_append (users, g_strdup (entry_name));
+                  users = g_slist_insert_sorted
+                           (users,
+                            (gpointer) g_strdup (entry_name),
+                            (GCompareFunc) (ascending ? strcmp : strcmp_desc));
                 }
               else if (g_file_test (user_dname_filename, G_FILE_TEST_EXISTS))
                 {
-                  users = g_slist_append (users, g_strdup (entry_name));
+                  users = g_slist_insert_sorted
+                           (users,
+                            (gpointer) g_strdup (entry_name),
+                            (GCompareFunc) (ascending ? strcmp : strcmp_desc));
                 }
               g_free (user_hash_filename);
               g_free (user_dname_filename);

Modified: trunk/openvas-administrator/src/admin.h
===================================================================
--- trunk/openvas-administrator/src/admin.h	2009-12-30 18:01:18 UTC (rev 6283)
+++ trunk/openvas-administrator/src/admin.h	2009-12-30 19:12:40 UTC (rev 6284)
@@ -28,7 +28,7 @@
 
 #include <glib.h>
 
-GSList *openvas_admin_list_users (const gchar *);
+GSList *openvas_admin_list_users (const gchar *, int);
 int openvas_admin_add_user (const gchar *, const gchar *, const gchar *,
                             const gchar *);
 int openvas_admin_remove_user (const gchar *, const gchar *);

Modified: trunk/openvas-administrator/src/oap.c
===================================================================
--- trunk/openvas-administrator/src/oap.c	2009-12-30 18:01:18 UTC (rev 6283)
+++ trunk/openvas-administrator/src/oap.c	2009-12-30 19:12:40 UTC (rev 6284)
@@ -203,15 +203,15 @@
 /* Help message. */
 
 static char* help_text = "\n"
-"    AUTHENTICATE           Authenticate with the administrator.\n"
-"    COMMANDS               Run a list of commands.\n"
-"    CREATE_USER            Create a new user.\n"
-"    DELETE_USER            Delete an existing user.\n"
-"    GET_USERS              Get all users.\n"
-"    GET_VERSION            Get the OpenVAS Administrator Protocol version.\n"
-"    DESCRIBE_FEED          Get a description of the feed this administrator synchronizes with.\n"
-"    SYNC_FEED              Synchronize with an NVT feed.\n"
-"    HELP                   Get this help text.\n";
+"    AUTHENTICATE   Authenticate with the administrator.\n"
+"    COMMANDS       Run a list of commands.\n"
+"    CREATE_USER    Create a new user.\n"
+"    DELETE_USER    Delete an existing user.\n"
+"    GET_USERS      Get all users.\n"
+"    GET_VERSION    Get the OpenVAS Administrator Protocol version.\n"
+"    DESCRIBE_FEED  Get details of the feed this administrator synchronizes with.\n"
+"    SYNC_FEED      Synchronize with an NVT feed.\n"
+"    HELP           Get this help text.\n";
 
 
 /* Status codes. */
@@ -766,7 +766,15 @@
             set_client_state (CLIENT_DELETE_USER);
           }
         else if (strcasecmp ("GET_USERS", element_name) == 0)
-          set_client_state (CLIENT_GET_USERS);
+          {
+            const gchar* attribute;
+            if (find_attribute (attribute_names, attribute_values,
+                                "sort_order", &attribute))
+              current_int_2 = strcmp (attribute, "descending");
+            else
+              current_int_2 = 1;
+            set_client_state (CLIENT_GET_USERS);
+          }
         else if (strcasecmp ("HELP", element_name) == 0)
           set_client_state (CLIENT_HELP);
         else if (strcasecmp ("GET_VERSION", element_name) == 0)
@@ -1199,7 +1207,7 @@
           SEND_TO_CLIENT_OR_FAIL ("<get_users_response"
                                   " status=\"" STATUS_OK "\""
                                   " status_text=\"" STATUS_OK_TEXT "\">");
-          user = users = openvas_admin_list_users (users_dir);
+          user = users = openvas_admin_list_users (users_dir, current_int_2);
           while (user)
             {
               SENDF_TO_CLIENT_OR_FAIL ("<user>"

Modified: trunk/openvas-administrator/src/oapd.c
===================================================================
--- trunk/openvas-administrator/src/oapd.c	2009-12-30 18:01:18 UTC (rev 6283)
+++ trunk/openvas-administrator/src/oapd.c	2009-12-30 19:12:40 UTC (rev 6284)
@@ -362,12 +362,21 @@
 
       if (FD_ISSET (client_socket, &exceptfds))
         {
-          g_warning ("%s: exception on client in child select\n",
-                     __FUNCTION__);
-          openvas_server_free (client_socket,
-                               *client_session,
-                               *client_credentials);
-          return -1;
+          char ch;
+          if (recv (client_socket, &ch, 1, MSG_OOB) < 1)
+            {
+              g_warning ("%s: after exception on client in child select:"
+                         " recv failed\n",
+                         __FUNCTION__);
+              openvas_server_free (client_socket,
+                                   *client_session,
+                                   *client_credentials);
+              return -1;
+            }
+          g_warning ("%s: after exception on client in child select:"
+                     " recv: %c\n",
+                     __FUNCTION__,
+                     ch);
         }
 
       if ((fds & FD_CLIENT_READ) == FD_CLIENT_READ

Modified: trunk/openvas-administrator/src/openvasad.c
===================================================================
--- trunk/openvas-administrator/src/openvasad.c	2009-12-30 18:01:18 UTC (rev 6283)
+++ trunk/openvas-administrator/src/openvasad.c	2009-12-30 19:12:40 UTC (rev 6284)
@@ -169,8 +169,8 @@
 gnutls_certificate_credentials_t client_credentials;
 
 /**
- *  * @brief Is this process parent or child?
- *   */
+ * @brief Is this process parent or child?
+ */
 int is_parent = 1;
 
 
@@ -548,7 +548,7 @@
       g_strstrip (command);
       if (g_strcasecmp (command, "list_users") == 0)
         {
-          GSList *user_list = openvas_admin_list_users (users_dir);
+          GSList *user_list = openvas_admin_list_users (users_dir, 1);
           g_string_free (response, TRUE);
           response = print_users_text (user_list);
           g_slist_free (user_list);

Modified: trunk/openvas-administrator/src/tests/oap_help_0.c
===================================================================
--- trunk/openvas-administrator/src/tests/oap_help_0.c	2009-12-30 18:01:18 UTC (rev 6283)
+++ trunk/openvas-administrator/src/tests/oap_help_0.c	2009-12-30 19:12:40 UTC (rev 6284)
@@ -33,13 +33,15 @@
 #include "../tracef.h"
 
 static char* help_text = "\n"
-"    AUTHENTICATE           Authenticate with the administrator.\n"
-"    COMMANDS               Run a list of commands.\n"
-"    CREATE_USER            Create a new user.\n"
-"    DELETE_USER            Delete an existing user.\n"
-"    GET_USERS              Get all users.\n"
-"    GET_VERSION            Get the OpenVAS Administrator Protocol version.\n"
-"    HELP                   Get this help text.\n";
+"    AUTHENTICATE   Authenticate with the administrator.\n"
+"    COMMANDS       Run a list of commands.\n"
+"    CREATE_USER    Create a new user.\n"
+"    DELETE_USER    Delete an existing user.\n"
+"    GET_USERS      Get all users.\n"
+"    GET_VERSION    Get the OpenVAS Administrator Protocol version.\n"
+"    DESCRIBE_FEED  Get details of the feed this administrator synchronizes with.\n"
+"    SYNC_FEED      Synchronize with an NVT feed.\n"
+"    HELP           Get this help text.\n";
 
 int
 main ()



More information about the Openvas-commits mailing list