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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Sep 28 20:26:38 CEST 2011


Author: mattm
Date: 2011-09-28 20:26:33 +0200 (Wed, 28 Sep 2011)
New Revision: 11709

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

	* src/manage_sql.c (set_setting): New function.

	* src/manage.h: Add header accordingly.

	* src/omp.c (help_text, command_data_t, client_state_t): Add
	MODIFY_SETTING.
	(modify_setting_data_t): New type.
	(modify_setting_data_reset): New function.
	(modify_setting_data): New variable.
	(omp_xml_handle_start_element, omp_xml_handle_end_element)
	(omp_xml_handle_text): Add MODIFY_SETTING handling.

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog	2011-09-28 16:40:42 UTC (rev 11708)
+++ trunk/openvas-manager/ChangeLog	2011-09-28 18:26:33 UTC (rev 11709)
@@ -1,3 +1,19 @@
+2011-09-28  Matthew Mundell <matthew.mundell at greenbone.net>
+
+	Add OMP MODIFY_SETTING.
+
+	* src/manage_sql.c (set_setting): New function.
+
+	* src/manage.h: Add header accordingly.
+
+	* src/omp.c (help_text, command_data_t, client_state_t): Add
+	MODIFY_SETTING.
+	(modify_setting_data_t): New type.
+	(modify_setting_data_reset): New function.
+	(modify_setting_data): New variable.
+	(omp_xml_handle_start_element, omp_xml_handle_end_element)
+	(omp_xml_handle_text): Add MODIFY_SETTING handling.
+
 2011-09-27  Matthew Mundell <matthew.mundell at greenbone.net>
 
 	Add support for storing the user's timezone in the db.  Hence increase

Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h	2011-09-28 16:40:42 UTC (rev 11708)
+++ trunk/openvas-manager/src/manage.h	2011-09-28 18:26:33 UTC (rev 11709)
@@ -1939,7 +1939,7 @@
 manage_schema (gchar *, gchar **, gsize *, gchar **, gchar **);
 
 
-/* Schema. */
+/* Trashcan. */
 
 int
 manage_restore (const char *);
@@ -1954,9 +1954,15 @@
 parse_tags (const char *, gchar **, gchar **, gchar **);
 
 
-/* SCAP files parsing. */
+/* SCAP file parsing. */
 
 int
 manage_read_info (gchar *, gchar *, gchar **);
 
+
+/* SCAP file parsing. */
+
+int
+manage_set_setting (const gchar *, const gchar *);
+
 #endif /* not OPENVAS_MANAGER_MANAGE_H */

Modified: trunk/openvas-manager/src/manage_sql.c
===================================================================
--- trunk/openvas-manager/src/manage_sql.c	2011-09-28 16:40:42 UTC (rev 11708)
+++ trunk/openvas-manager/src/manage_sql.c	2011-09-28 18:26:33 UTC (rev 11709)
@@ -32384,4 +32384,41 @@
   return 0;
 }
 
+
+/* Settings. */
+
+/**
+ * @brief Set the value of a setting.
+ *
+ * @param[in]  name   Setting name.
+ * @param[in]  value  New setting value, base64 encoded.
+ *
+ * @return 0 success, 1 name must be Timezone.
+ */
+int
+manage_set_setting (const gchar *name, const gchar *value_64)
+{
+  assert (current_credentials.uuid);
+
+  if (strcmp (name, "Timezone") == 0)
+    {
+      gsize value_size;
+      gchar *quoted_timezone, *value;
+      if (value_64 && strlen (value_64))
+        value = (gchar*) g_base64_decode (value_64, &value_size);
+      else
+        {
+          value = g_strdup ("");
+          value_size = 0;
+        }
+      quoted_timezone = sql_quote (value);
+      sql ("UPDATE users SET timezone = '%s' WHERE uuid = '%s';",
+           quoted_timezone,
+           current_credentials.uuid);
+      g_free (quoted_timezone);
+      return 0;
+    }
+  return 1;
+}
+
 #undef DEF_ACCESS

Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c	2011-09-28 16:40:42 UTC (rev 11708)
+++ trunk/openvas-manager/src/omp.c	2011-09-28 18:26:33 UTC (rev 11709)
@@ -429,6 +429,7 @@
 "    MODIFY_OVERRIDE        Modify an existing override.\n"
 "    MODIFY_REPORT          Modify an existing report.\n"
 "    MODIFY_REPORT_FORMAT   Modify an existing report format.\n"
+"    MODIFY_SETTING         Modify an existing setting.\n"
 "    MODIFY_TASK            Update an existing task.\n"
 "    PAUSE_TASK             Pause a running task.\n"
 "    RESTORE                Restore a resource.\n"
@@ -2211,6 +2212,29 @@
 }
 
 /**
+ * @brief Command data for the modify_setting command.
+ */
+typedef struct
+{
+  char *name;           ///< Name.
+  char *value;          ///< Value.
+} modify_setting_data_t;
+
+/**
+ * @brief Reset command data.
+ *
+ * @param[in]  data  Command data.
+ */
+static void
+modify_setting_data_reset (modify_setting_data_t *data)
+{
+  free (data->name);
+  free (data->value);
+
+  memset (data, 0, sizeof (modify_setting_data_t));
+}
+
+/**
  * @brief Command data for the modify_task command.
  */
 typedef struct
@@ -2607,6 +2631,7 @@
   modify_lsc_credential_data_t modify_lsc_credential; ///< modify_lsc_credential
   modify_report_data_t modify_report;                 ///< modify_report
   modify_report_format_data_t modify_report_format;   ///< modify_report_format
+  modify_setting_data_t modify_setting;               ///< modify_setting
   modify_task_data_t modify_task;                     ///< modify_task
   pause_task_data_t pause_task;                       ///< pause_task
   restore_data_t restore;                             ///< restore
@@ -2950,6 +2975,12 @@
  = &(command_data.modify_report_format);
 
 /**
+ * @brief Parser callback data for MODIFY_SETTING.
+ */
+modify_setting_data_t *modify_setting_data
+ = &(command_data.modify_setting);
+
+/**
  * @brief Parser callback data for MODIFY_TASK.
  */
 modify_task_data_t *modify_task_data
@@ -3332,6 +3363,9 @@
   CLIENT_MODIFY_OVERRIDE_TASK,
   CLIENT_MODIFY_OVERRIDE_TEXT,
   CLIENT_MODIFY_OVERRIDE_THREAT,
+  CLIENT_MODIFY_SETTING,
+  CLIENT_MODIFY_SETTING_NAME,
+  CLIENT_MODIFY_SETTING_VALUE,
   CLIENT_MODIFY_TASK,
   CLIENT_MODIFY_TASK_COMMENT,
   CLIENT_MODIFY_TASK_ESCALATOR,
@@ -4682,6 +4716,10 @@
                               &modify_report_format_data->report_format_id);
             set_client_state (CLIENT_MODIFY_REPORT_FORMAT);
           }
+        else if (strcasecmp ("MODIFY_SETTING", element_name) == 0)
+          {
+            set_client_state (CLIENT_MODIFY_SETTING);
+          }
         else if (strcasecmp ("MODIFY_TASK", element_name) == 0)
           {
             append_attribute (attribute_names, attribute_values, "task_id",
@@ -5793,6 +5831,29 @@
                      "Error");
         break;
 
+      case CLIENT_MODIFY_SETTING:
+        if (strcasecmp ("NAME", element_name) == 0)
+          set_client_state (CLIENT_MODIFY_SETTING_NAME);
+        else if (strcasecmp ("VALUE", element_name) == 0)
+          set_client_state (CLIENT_MODIFY_SETTING_VALUE);
+        else
+          {
+            if (send_element_error_to_client ("modify_setting",
+                                              element_name,
+                                              write_to_client,
+                                              write_to_client_data))
+              {
+                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_MODIFY_TASK:
         if (strcasecmp ("COMMENT", element_name) == 0)
           {
@@ -11623,6 +11684,47 @@
         set_client_state (CLIENT_MODIFY_REPORT_FORMAT_PARAM);
         break;
 
+      case CLIENT_MODIFY_SETTING:
+        {
+          if ((modify_setting_data->name == NULL)
+              || (modify_setting_data->value == NULL))
+            SEND_TO_CLIENT_OR_FAIL
+             (XML_ERROR_SYNTAX ("modify_setting",
+                                "MODIFY_SETTING requires a NAME and VALUE"));
+          else switch (manage_set_setting (modify_setting_data->name,
+                                           modify_setting_data->value))
+            {
+              case 0:
+                SEND_TO_CLIENT_OR_FAIL (XML_OK ("modify_setting"));
+                break;
+              case 1:
+                SEND_TO_CLIENT_OR_FAIL
+                 (XML_ERROR_SYNTAX ("modify_setting",
+                                    "NAME must be Timezone"));
+                break;
+              case 2:
+                SEND_TO_CLIENT_OR_FAIL
+                 (XML_ERROR_SYNTAX ("modify_setting",
+                                    "Value validation failed"));
+                break;
+              default:
+                SEND_TO_CLIENT_OR_FAIL
+                 (XML_INTERNAL_ERROR ("modify_setting"));
+                break;
+            }
+        }
+        modify_setting_data_reset (modify_setting_data);
+        set_client_state (CLIENT_AUTHENTIC);
+        break;
+      case CLIENT_MODIFY_SETTING_NAME:
+        assert (strcasecmp ("NAME", element_name) == 0);
+        set_client_state (CLIENT_MODIFY_SETTING);
+        break;
+      case CLIENT_MODIFY_SETTING_VALUE:
+        assert (strcasecmp ("VALUE", element_name) == 0);
+        set_client_state (CLIENT_MODIFY_SETTING);
+        break;
+
       case CLIENT_MODIFY_TASK:
         /** @todo Update to match "create_task (config, target)". */
         if (modify_task_data->task_id)
@@ -17729,6 +17831,17 @@
                              text_len);
         break;
 
+      case CLIENT_MODIFY_SETTING_NAME:
+        openvas_append_text (&modify_setting_data->name,
+                             text,
+                             text_len);
+        break;
+      case CLIENT_MODIFY_SETTING_VALUE:
+        openvas_append_text (&modify_setting_data->value,
+                             text,
+                             text_len);
+        break;
+
       case CLIENT_MODIFY_TASK_COMMENT:
         openvas_append_text (&modify_task_data->comment, text, text_len);
         break;



More information about the Openvas-commits mailing list