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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Feb 11 19:02:46 CET 2010


Author: mattm
Date: 2010-02-11 19:02:38 +0100 (Thu, 11 Feb 2010)
New Revision: 6719

Modified:
   trunk/openvas-manager/ChangeLog
   trunk/openvas-manager/src/manage.h
   trunk/openvas-manager/src/omp.c
   trunk/openvas-manager/src/tasks_sql.h
Log:
	Add OMP GET_NOTES.

	* src/tasks_sql.h (init_note_iterator, note_iterator_uuid)
	(note_iterator_nvt_oid, note_iterator_nvt_name): New functions.

	* src/manage.h: Add headers accordingly.

	* src/omp.c (help_text): Add GET_NOTES.
	(get_notes_data_t): New type.
	(get_notes_data_reset): New function.
	(command_data_t): Add get_notes.
	(get_notes_data): New variable.
	(client_state_t): Add CLIENT_GET_NOTES.
	(omp_xml_handle_start_element, omp_xml_handle_end_element): Add
	GET_NOTES handling.

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog	2010-02-11 16:58:53 UTC (rev 6718)
+++ trunk/openvas-manager/ChangeLog	2010-02-11 18:02:38 UTC (rev 6719)
@@ -1,5 +1,23 @@
 2010-02-11  Matthew Mundell <matthew.mundell at intevation.de>
 
+	Add OMP GET_NOTES.
+
+	* src/tasks_sql.h (init_note_iterator, note_iterator_uuid)
+	(note_iterator_nvt_oid, note_iterator_nvt_name): New functions.
+
+	* src/manage.h: Add headers accordingly.
+
+	* src/omp.c (help_text): Add GET_NOTES.
+	(get_notes_data_t): New type.
+	(get_notes_data_reset): New function.
+	(command_data_t): Add get_notes.
+	(get_notes_data): New variable.
+	(client_state_t): Add CLIENT_GET_NOTES.
+	(omp_xml_handle_start_element, omp_xml_handle_end_element): Add
+	GET_NOTES handling.
+
+2010-02-11  Matthew Mundell <matthew.mundell at intevation.de>
+
 	* src/openvasmd.c (main): Include --rebuild in error message.
 
 2010-02-11  Matthew Mundell <matthew.mundell at intevation.de>

Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h	2010-02-11 16:58:53 UTC (rev 6718)
+++ trunk/openvas-manager/src/manage.h	2010-02-11 18:02:38 UTC (rev 6719)
@@ -1093,6 +1093,18 @@
 int
 delete_note (note_t);
 
+void
+init_note_iterator (iterator_t*, note_t, int, const char*);
+
+const char*
+note_iterator_uuid (iterator_t*);
+
+const char*
+note_iterator_nvt_oid (iterator_t*);
+
+const char*
+note_iterator_nvt_name (iterator_t *);
+
 
 /* Scanner messaging. */
 

Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c	2010-02-11 16:58:53 UTC (rev 6718)
+++ trunk/openvas-manager/src/omp.c	2010-02-11 18:02:38 UTC (rev 6719)
@@ -272,6 +272,7 @@
 "    GET_DEPENDENCIES       Get dependencies for all available NVTs.\n"
 "    GET_ESCALATORS         Get all escalators.\n"
 "    GET_LSC_CREDENTIALS    Get all local security check credentials.\n"
+"    GET_NOTES              Get all notes.\n"
 "    GET_NVT_ALL            Get IDs and names of all available NVTs.\n"
 "    GET_NVT_DETAILS        Get all details for all available NVTs.\n"
 "    GET_NVT_FAMILIES       Get a list of all NVT families.\n"
@@ -554,6 +555,20 @@
 
 typedef struct
 {
+  char *note_id;
+  char *sort_field;
+  int sort_order;
+} get_notes_data_t;
+
+static void
+get_notes_data_reset (get_notes_data_t *data)
+{
+  free (data->note_id);
+  memset (data, 0, sizeof (get_notes_data_t));
+}
+
+typedef struct
+{
   char *format;
   char *report_id;
   int first_result;
@@ -594,6 +609,7 @@
   create_config_data_t create_config;
   create_note_data_t create_note;
   delete_note_data_t delete_note;
+  get_notes_data_t get_notes;
   get_report_data_t get_report;
   get_system_reports_data_t get_system_reports;
   name_command_data_t name_command;
@@ -635,6 +651,12 @@
  = (delete_note_data_t*) &(command_data.delete_note);
 
 /**
+ * @brief Parser callback data for GET_NOTES.
+ */
+get_notes_data_t *get_notes_data
+ = &(command_data.get_notes);
+
+/**
  * @brief Parser callback data for GET_REPORT.
  */
 get_report_data_t *get_report_data
@@ -891,6 +913,7 @@
   CLIENT_GET_DEPENDENCIES,
   CLIENT_GET_ESCALATORS,
   CLIENT_GET_LSC_CREDENTIALS,
+  CLIENT_GET_NOTES,
   CLIENT_GET_NVT_ALL,
   CLIENT_GET_NVT_DETAILS,
   CLIENT_GET_NVT_FAMILIES,
@@ -1511,6 +1534,26 @@
               current_int_2 = 1;
             set_client_state (CLIENT_GET_LSC_CREDENTIALS);
           }
+        else if (strcasecmp ("GET_NOTES", element_name) == 0)
+          {
+            const gchar* attribute;
+
+            if (find_attribute (attribute_names, attribute_values,
+                                "note_id", &attribute))
+              openvas_append_string (&get_notes_data->note_id, attribute);
+
+            if (find_attribute (attribute_names, attribute_values,
+                                "sort_field", &attribute))
+              openvas_append_string (&get_notes_data->sort_field, attribute);
+
+            if (find_attribute (attribute_names, attribute_values,
+                                "sort_order", &attribute))
+              get_notes_data->sort_order = strcmp (attribute, "descending");
+            else
+              get_notes_data->sort_order = 1;
+
+            set_client_state (CLIENT_GET_NOTES);
+          }
         else if (strcasecmp ("GET_NVT_ALL", element_name) == 0)
           set_client_state (CLIENT_GET_NVT_ALL);
         else if (strcasecmp ("GET_NVT_FEED_CHECKSUM", element_name) == 0)
@@ -2052,6 +2095,19 @@
           }
         break;
 
+      case CLIENT_GET_NOTES:
+        if (send_element_error_to_client ("get_notes", element_name))
+          {
+            error_send_to_client (error);
+            return;
+          }
+        set_client_state (CLIENT_AUTHENTIC);
+        g_set_error (error,
+                     G_MARKUP_ERROR,
+                     G_MARKUP_ERROR_UNKNOWN_ELEMENT,
+                     "Error");
+        break;
+
       case CLIENT_GET_NVT_ALL:
           {
             if (send_element_error_to_client ("get_nvt_all", element_name))
@@ -4473,6 +4529,54 @@
         set_client_state (CLIENT_AUTHENTIC);
         break;
 
+      case CLIENT_GET_NOTES:
+        {
+          note_t note = 0;
+
+          assert (strcasecmp ("GET_NOTES", element_name) == 0);
+
+          if (get_notes_data->note_id
+              && find_note (get_notes_data->note_id, &note))
+            SEND_TO_CLIENT_OR_FAIL (XML_INTERNAL_ERROR ("get_notes"));
+          else if (get_notes_data->note_id && note == 0)
+            {
+              if (send_find_error_to_client ("get_notes",
+                                             "note",
+                                             get_notes_data->note_id))
+                {
+                  error_send_to_client (error);
+                  return;
+                }
+            }
+          else
+            {
+              iterator_t notes;
+
+              SENDF_TO_CLIENT_OR_FAIL ("<get_notes_response"
+                                       " status=\"" STATUS_OK "\""
+                                       " status_text=\"" STATUS_OK_TEXT "\">");
+
+              init_note_iterator (&notes,
+                                  note,
+                                  get_notes_data->sort_order,
+                                  get_notes_data->sort_field);
+              while (next (&notes))
+                SENDF_TO_CLIENT_OR_FAIL ("<note id=\"%s\">"
+                                         "<nvt oid=\"%s\"><name>%s</name></nvt>"
+                                         "</note>",
+                                         note_iterator_uuid (&notes),
+                                         note_iterator_nvt_oid (&notes),
+                                         note_iterator_nvt_name (&notes));
+              cleanup_iterator (&notes);
+
+              SEND_TO_CLIENT_OR_FAIL ("</get_notes_response>");
+            }
+
+          get_notes_data_reset (get_notes_data);
+          set_client_state (CLIENT_AUTHENTIC);
+          break;
+        }
+
       case CLIENT_GET_NVT_FEED_CHECKSUM:
         {
           char *md5sum;

Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h	2010-02-11 16:58:53 UTC (rev 6718)
+++ trunk/openvas-manager/src/tasks_sql.h	2010-02-11 18:02:38 UTC (rev 6719)
@@ -11476,4 +11476,65 @@
   return 0;
 }
 
+/**
+ * @brief Initialise a note iterator.
+ *
+ * @param[in]  iterator    Iterator.
+ * @param[in]  note        Single note to iterate, 0 for all.
+ * @param[in]  ascending   Whether to sort ascending or descending.
+ * @param[in]  sort_field  Field to sort on, or NULL for "ROWID".
+ */
+void
+init_note_iterator (iterator_t* iterator, note_t note,
+                    int ascending, const char* sort_field)
+{
+  assert (current_credentials.uuid);
+
+  if (note)
+    init_iterator (iterator,
+                   "SELECT ROWID, uuid, nvt, creation_time, modification_time,"
+                   " text, hosts, port, threat, task, report"
+                   " FROM notes"
+                   " WHERE ROWID = %llu"
+                   " AND ((owner IS NULL) OR (owner ="
+                   " (SELECT ROWID FROM users WHERE users.uuid = '%s')))"
+                   " ORDER BY %s %s;",
+                   note,
+                   current_credentials.uuid,
+                   sort_field ? sort_field : "ROWID",
+                   ascending ? "ASC" : "DESC");
+  else
+    init_iterator (iterator,
+                   "SELECT ROWID, uuid, nvt, creation_time, modification_time,"
+                   " text, hosts, port, threat, task, report"
+                   " FROM notes"
+                   " WHERE ((owner IS NULL) OR (owner ="
+                   " (SELECT ROWID FROM users WHERE users.uuid = '%s')))"
+                   " ORDER BY %s %s;",
+                   current_credentials.uuid,
+                   sort_field ? sort_field : "ROWID",
+                   ascending ? "ASC" : "DESC");
+}
+
+DEF_ACCESS (note_iterator_uuid, 1);
+DEF_ACCESS (note_iterator_nvt_oid, 2);
+
+/**
+ * @brief Get the NVT name from a nots iterator.
+ *
+ * @param[in]  iterator  Iterator.
+ *
+ * @return The name of the NVT associated with the note, or NULL on error.
+ */
+const char*
+note_iterator_nvt_name (iterator_t *iterator)
+{
+  nvti_t *nvti;
+  if (iterator->done) return NULL;
+  nvti = nvtis_lookup (nvti_cache, note_iterator_nvt_oid (iterator));
+  if (nvti)
+    return nvti_name (nvti);
+  return NULL;
+}
+
 #undef DEF_ACCESS



More information about the Openvas-commits mailing list