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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Sep 7 08:52:57 CEST 2011


Author: mattm
Date: 2011-09-07 08:52:55 +0200 (Wed, 07 Sep 2011)
New Revision: 11578

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:
	* src/manage_sql.c (manage_set_config_name, manage_set_config_comment)
	(manage_set_config_name_comment): New functions.

	* src/manage.h: Add headers accordingly.

	* src/omp.c (modify_config_data_t, modify_config_data_reset)
	(client_state_t): Add comment and name.
	(omp_xml_handle_start_element, omp_xml_handle_end_element)
	(omp_xml_handle_text): Add NAME and COMMENT to MODIFY_CONFIG.

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog	2011-09-07 06:36:57 UTC (rev 11577)
+++ trunk/openvas-manager/ChangeLog	2011-09-07 06:52:55 UTC (rev 11578)
@@ -1,3 +1,15 @@
+2011-09-07  Matthew Mundell <matthew.mundell at greenbone.net>
+
+	* src/manage_sql.c (manage_set_config_name, manage_set_config_comment)
+	(manage_set_config_name_comment): New functions.
+
+	* src/manage.h: Add headers accordingly.
+
+	* src/omp.c (modify_config_data_t, modify_config_data_reset)
+	(client_state_t): Add comment and name.
+	(omp_xml_handle_start_element, omp_xml_handle_end_element)
+	(omp_xml_handle_text): Add NAME and COMMENT to MODIFY_CONFIG.
+
 2011-09-06  Matthew Mundell <matthew.mundell at greenbone.net>
 
 	* src/manage_sql.c (host_report_count): Count only visible finished

Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h	2011-09-07 06:36:57 UTC (rev 11577)
+++ trunk/openvas-manager/src/manage.h	2011-09-07 06:52:55 UTC (rev 11578)
@@ -1024,6 +1024,15 @@
                               const char*);
 
 int
+manage_set_config_comment (config_t, const char*);
+
+int
+manage_set_config_name (config_t, const char*);
+
+int
+manage_set_config_name_comment (config_t, const char*, const char*);
+
+int
 manage_set_config_nvts (config_t, const char*, GPtrArray*);
 
 int

Modified: trunk/openvas-manager/src/manage_sql.c
===================================================================
--- trunk/openvas-manager/src/manage_sql.c	2011-09-07 06:36:57 UTC (rev 11577)
+++ trunk/openvas-manager/src/manage_sql.c	2011-09-07 06:52:55 UTC (rev 11578)
@@ -20941,6 +20941,89 @@
 }
 
 /**
+ * @brief Set the comment of a config.
+ *
+ * @param[in]  config   Config.
+ * @param[in]  comment  New comment.
+ *
+ * @return 0 success, -1 error.
+ */
+int
+manage_set_config_comment (config_t config, const char* comment)
+{
+  gchar *quoted_comment;
+  quoted_comment = sql_quote (comment);
+  sql ("UPDATE configs SET comment = '%s' WHERE ROWID = %llu;",
+       quoted_comment, config);
+  g_free (quoted_comment);
+  return 0;
+}
+
+/**
+ * @brief Set the name of a config.
+ *
+ * @param[in]  config  Config.
+ * @param[in]  name    New name.
+ *
+ * @return 0 success, 1 config with new name exists already, -1 error.
+ */
+int
+manage_set_config_name (config_t config, const char* name)
+{
+  gchar *quoted_name;
+  sql ("BEGIN IMMEDIATE;");
+  quoted_name = sql_quote (name);
+  if (sql_int (0, 0,
+               "SELECT count(*) FROM configs"
+               " WHERE name = '%s' AND ROWID != %llu;",
+               quoted_name,
+               config))
+    {
+      sql ("ROLLBACK;");
+      return 1;
+    }
+  sql ("UPDATE configs SET name = '%s' WHERE ROWID = %llu;",
+       quoted_name, config);
+  g_free (quoted_name);
+  sql ("COMMIT;");
+  return 0;
+}
+
+/**
+ * @brief Set the name of a config.
+ *
+ * @param[in]  config   Config.
+ * @param[in]  name     New name.
+ * @param[in]  comment  New comment.
+ *
+ * @return 0 success, 1 config with new name exists already, -1 error.
+ */
+int
+manage_set_config_name_comment (config_t config, const char* name,
+                                const char* comment)
+{
+  gchar *quoted_name, *quoted_comment;
+  sql ("BEGIN IMMEDIATE;");
+  quoted_name = sql_quote (name);
+  quoted_comment = sql_quote (comment);
+  if (sql_int (0, 0,
+               "SELECT count(*) FROM configs"
+               " WHERE name = '%s' AND ROWID != %llu;",
+               quoted_name,
+               config))
+    {
+      sql ("ROLLBACK;");
+      return 1;
+    }
+  sql ("UPDATE configs SET name = '%s', comment = '%s' WHERE ROWID = %llu;",
+       quoted_name, quoted_comment, config);
+  g_free (quoted_name);
+  g_free (quoted_comment);
+  sql ("COMMIT;");
+  return 0;
+}
+
+/**
  * @brief Set the NVT's selected for a single family of a config.
  *
  * @param[in]  config         Config.

Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c	2011-09-07 06:36:57 UTC (rev 11577)
+++ trunk/openvas-manager/src/omp.c	2011-09-07 06:52:55 UTC (rev 11578)
@@ -1986,6 +1986,7 @@
  */
 typedef struct
 {
+  char *comment;                       ///< New comment for config.
   char *config_id;                     ///< ID of config to modify.
   array_t *families_growing_empty; ///< New family selection: growing, empty.
   array_t *families_growing_all;   ///< New family selection: growing, all NVTs.
@@ -1997,6 +1998,7 @@
   char *family_selection_family_name;  ///< FAMILY_SELECTION/FAMILY family name.
   int family_selection_growing;        ///< Whether families in selection grow.
   char *family_selection_growing_text; ///< Text version of above.
+  char *name;                          ///< New name for config.
   array_t *nvt_selection;              ///< OID array. New NVT set for config.
   char *nvt_selection_family;          ///< Family of NVT selection.
   char *nvt_selection_nvt_oid;         ///< OID during NVT_selection/NVT.
@@ -2062,6 +2064,7 @@
 static void
 modify_config_data_reset (modify_config_data_t *data)
 {
+  free (data->comment);
   free (data->config_id);
   array_free (data->families_growing_empty);
   array_free (data->families_growing_all);
@@ -2070,6 +2073,7 @@
   free (data->family_selection_family_growing_text);
   free (data->family_selection_family_name);
   free (data->family_selection_growing_text);
+  free (data->name);
   array_free (data->nvt_selection);
   free (data->nvt_selection_family);
   free (data->nvt_selection_nvt_oid);
@@ -3244,6 +3248,8 @@
   CLIENT_MODIFY_REPORT_FORMAT_PARAM_NAME,
   CLIENT_MODIFY_REPORT_FORMAT_PARAM_VALUE,
   CLIENT_MODIFY_CONFIG,
+  CLIENT_MODIFY_CONFIG_COMMENT,
+  CLIENT_MODIFY_CONFIG_NAME,
   CLIENT_MODIFY_CONFIG_PREFERENCE,
   CLIENT_MODIFY_CONFIG_PREFERENCE_NAME,
   CLIENT_MODIFY_CONFIG_PREFERENCE_NVT,
@@ -5385,8 +5391,14 @@
         break;
 
       case CLIENT_MODIFY_CONFIG:
-        if (strcasecmp ("FAMILY_SELECTION", element_name) == 0)
+        if (strcasecmp ("COMMENT", element_name) == 0)
           {
+            openvas_free_string_var (&modify_config_data->comment);
+            openvas_append_string (&modify_config_data->comment, "");
+            set_client_state (CLIENT_MODIFY_CONFIG_COMMENT);
+          }
+        else if (strcasecmp ("FAMILY_SELECTION", element_name) == 0)
+          {
             modify_config_data->families_growing_all = make_array ();
             modify_config_data->families_static_all = make_array ();
             modify_config_data->families_growing_empty = make_array ();
@@ -5394,6 +5406,8 @@
             modify_config_data->family_selection_growing = 0;
             set_client_state (CLIENT_MODIFY_CONFIG_FAMILY_SELECTION);
           }
+        else if (strcasecmp ("NAME", element_name) == 0)
+          set_client_state (CLIENT_MODIFY_CONFIG_NAME);
         else if (strcasecmp ("NVT_SELECTION", element_name) == 0)
           {
             modify_config_data->nvt_selection = make_array ();
@@ -10942,6 +10956,61 @@
                     break;
                 }
             }
+          else if (modify_config_data->name && modify_config_data->comment)
+            switch (manage_set_config_name_comment (config,
+                                                    modify_config_data->name,
+                                                    modify_config_data->comment))
+              {
+                case 0:
+                  SEND_TO_CLIENT_OR_FAIL (XML_OK ("modify_config"));
+                  break;
+                case 1:
+                  SEND_TO_CLIENT_OR_FAIL
+                   (XML_ERROR_SYNTAX ("modify_config",
+                                      "MODIFY_CONFIG name must be unique"));
+                  break;
+                case -1:
+                  SEND_TO_CLIENT_OR_FAIL (XML_INTERNAL_ERROR ("modify_config"));
+                  break;
+                default:
+                  SEND_TO_CLIENT_OR_FAIL
+                   (XML_INTERNAL_ERROR ("modify_config"));
+                  break;
+              }
+          else if (modify_config_data->name)
+            switch (manage_set_config_name (config, modify_config_data->name))
+              {
+                case 0:
+                  SEND_TO_CLIENT_OR_FAIL (XML_OK ("modify_config"));
+                  break;
+                case 1:
+                  SEND_TO_CLIENT_OR_FAIL
+                   (XML_ERROR_SYNTAX ("modify_config",
+                                      "MODIFY_CONFIG name must be unique"));
+                  break;
+                case -1:
+                  SEND_TO_CLIENT_OR_FAIL (XML_INTERNAL_ERROR ("modify_config"));
+                  break;
+                default:
+                  SEND_TO_CLIENT_OR_FAIL
+                   (XML_INTERNAL_ERROR ("modify_config"));
+                  break;
+              }
+          else if (modify_config_data->comment)
+            switch (manage_set_config_comment (config,
+                                               modify_config_data->comment))
+              {
+                case 0:
+                  SEND_TO_CLIENT_OR_FAIL (XML_OK ("modify_config"));
+                  break;
+                case -1:
+                  SEND_TO_CLIENT_OR_FAIL (XML_INTERNAL_ERROR ("modify_config"));
+                  break;
+                default:
+                  SEND_TO_CLIENT_OR_FAIL
+                   (XML_INTERNAL_ERROR ("modify_config"));
+                  break;
+              }
           else if (modify_config_data->preference_name == NULL
                    || strlen (modify_config_data->preference_name) == 0)
             SEND_TO_CLIENT_OR_FAIL
@@ -10977,6 +11046,10 @@
         modify_config_data_reset (modify_config_data);
         set_client_state (CLIENT_AUTHENTIC);
         break;
+      case CLIENT_MODIFY_CONFIG_COMMENT:
+        assert (strcasecmp ("COMMENT", element_name) == 0);
+        set_client_state (CLIENT_MODIFY_CONFIG);
+        break;
       case CLIENT_MODIFY_CONFIG_FAMILY_SELECTION:
         assert (strcasecmp ("FAMILY_SELECTION", element_name) == 0);
         assert (modify_config_data->families_growing_all);
@@ -10987,6 +11060,10 @@
         array_terminate (modify_config_data->families_growing_empty);
         set_client_state (CLIENT_MODIFY_CONFIG);
         break;
+      case CLIENT_MODIFY_CONFIG_NAME:
+        assert (strcasecmp ("NAME", element_name) == 0);
+        set_client_state (CLIENT_MODIFY_CONFIG);
+        break;
       case CLIENT_MODIFY_CONFIG_NVT_SELECTION:
         assert (strcasecmp ("NVT_SELECTION", element_name) == 0);
         assert (modify_config_data->nvt_selection);
@@ -17178,6 +17255,16 @@
                              text_len);
         break;
 
+      case CLIENT_MODIFY_CONFIG_COMMENT:
+        openvas_append_text (&modify_config_data->comment,
+                             text,
+                             text_len);
+        break;
+      case CLIENT_MODIFY_CONFIG_NAME:
+        openvas_append_text (&modify_config_data->name,
+                             text,
+                             text_len);
+        break;
       case CLIENT_MODIFY_CONFIG_PREFERENCE_NAME:
         openvas_append_text (&modify_config_data->preference_name,
                              text,



More information about the Openvas-commits mailing list