[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openvas-cvs
Subject:    [Openvas-commits] r6270 - in trunk/openvas-manager: . src
From:       scm-commit () wald ! intevation ! org
Date:       2009-12-29 12:37:06
Message-ID: 20091229123706.9C5B28667D1D () pyrosoma ! intevation ! org
[Download RAW message or body]

Author: mattm
Date: 2009-12-29 13:37:04 +0100 (Tue, 29 Dec 2009)
New Revision: 6270

Modified:
   trunk/openvas-manager/ChangeLog
   trunk/openvas-manager/src/omp.c
   trunk/openvas-manager/src/tasks_sql.h
Log:
	* src/tasks_sql.h (manage_set_config_preference)
	(manage_set_config_nvts, manage_set_config_families): Return 1 if the
	config is in use.

	* src/omp.c (omp_xml_handle_end_element): In CLIENT_MODIFY_CONFIG respond
	with error if config is in use.

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog	2009-12-29 12:08:05 UTC (rev 6269)
+++ trunk/openvas-manager/ChangeLog	2009-12-29 12:37:04 UTC (rev 6270)
@@ -1,3 +1,12 @@
+2009-12-29  Matthew Mundell <matthew.mundell@intevation.de>
+
+	* src/tasks_sql.h (manage_set_config_preference)
+	(manage_set_config_nvts, manage_set_config_families): Return 1 if the
+	config is in use.
+
+	* src/omp.c (omp_xml_handle_end_element): In CLIENT_MODIFY_CONFIG respond
+	with error if config is in use.
+
 2009-12-28  Matthew Mundell <matthew.mundell@intevation.de>
 
 	* src/ovas-mngr-comm.c (sendn_to_server, write_string_to_server)

Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c	2009-12-29 12:08:05 UTC (rev 6269)
+++ trunk/openvas-manager/src/omp.c	2009-12-29 12:37:04 UTC (rev 6270)
@@ -5111,6 +5111,10 @@
                 case 0:
                   SEND_TO_CLIENT_OR_FAIL (XML_OK ("modify_config"));
                   break;
+                case 1:
+                  SEND_TO_CLIENT_OR_FAIL
+                   (XML_ERROR_SYNTAX ("modify_config", "Config is in use"));
+                  break;
 #if 0
                 case -1:
                   SEND_TO_CLIENT_OR_FAIL
@@ -5121,7 +5125,7 @@
 #endif
                 default:
                   SEND_TO_CLIENT_OR_FAIL
-                   (XML_INTERNAL_ERROR ("modify_report"));
+                   (XML_INTERNAL_ERROR ("modify_config"));
                   break;
               }
 
@@ -5145,6 +5149,10 @@
                 case 0:
                   SEND_TO_CLIENT_OR_FAIL (XML_OK ("modify_config"));
                   break;
+                case 1:
+                  SEND_TO_CLIENT_OR_FAIL
+                   (XML_ERROR_SYNTAX ("modify_config", "Config is in use"));
+                  break;
 #if 0
                 case -1:
                   SEND_TO_CLIENT_OR_FAIL
@@ -5179,6 +5187,10 @@
             case 0:
               SEND_TO_CLIENT_OR_FAIL (XML_OK ("modify_config"));
               break;
+            case 1:
+              SEND_TO_CLIENT_OR_FAIL
+               (XML_ERROR_SYNTAX ("modify_config", "Config is in use"));
+              break;
             case -1:
               SEND_TO_CLIENT_OR_FAIL
                (XML_ERROR_SYNTAX ("modify_config",

Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h	2009-12-29 12:08:05 UTC (rev 6269)
+++ trunk/openvas-manager/src/tasks_sql.h	2009-12-29 12:37:04 UTC (rev 6270)
@@ -6828,7 +6828,7 @@
  * @param[in]  value_64  Preference value in base64.  NULL for an NVT
  *                       preference removes the preference from the config.
  *
- * @return 0 success, -1 error.
+ * @return 0 success, 1 config in use, -1 error.
  */
 int
 manage_set_config_preference (const char* config, const char* nvt, const char* name,
@@ -6838,12 +6838,24 @@
   int type_start = -1, type_end = -1, count;
 
   quoted_config = sql_quote (config);
-  quoted_name = sql_quote (name);
 
   if (value_64 == NULL)
     {
       int end = -1;
 
+      sql ("BEGIN IMMEDIATE;");
+
+      if (sql_int (0, 0,
+                   "SELECT count(*) FROM tasks WHERE config = '%s'",
+                   quoted_config))
+        {
+          g_free (quoted_config);
+          sql ("END;");
+          return 1;
+        }
+
+      quoted_name = sql_quote (name);
+
       /* scanner[scanner]:Timeout */
       count = sscanf (name, "%*[^[][scanner]:%n", &end);
       if (count == 0 && end > 0)
@@ -6858,11 +6870,27 @@
            " AND name = '%s';",
            quoted_config,
            quoted_name);
+
+      sql ("COMMIT;");
+
       g_free (quoted_config);
       g_free (quoted_name);
       return 0;
     }
 
+  sql ("BEGIN IMMEDIATE;");
+
+  if (sql_int (0, 0,
+               "SELECT count(*) FROM tasks WHERE config = '%s'",
+               quoted_config))
+    {
+      g_free (quoted_config);
+      sql ("END;");
+      return 1;
+    }
+
+  quoted_name = sql_quote (name);
+
   if (strlen (value_64))
     {
       gsize value_len;
@@ -6929,7 +6957,6 @@
   quoted_value = sql_quote ((gchar*) value);
   g_free (value);
 
-  sql ("BEGIN IMMEDIATE;");
   sql ("DELETE FROM config_preferences"
        " WHERE config = (SELECT ROWID FROM configs WHERE name = '%s')"
        " AND type %s"
@@ -6960,7 +6987,7 @@
  * @param[in]  family         Family name.
  * @param[in]  selected_nvts  NVT's.
  *
- * @return 0 success, -1 error.
+ * @return 0 success, 1 config in use, -1 error.
  */
 int
 manage_set_config_nvts (const char* config, const char* family,
@@ -6971,10 +6998,20 @@
   int new_nvt_count, old_nvt_count;
 
   quoted_config = sql_quote (config);
-  quoted_family = sql_quote (family);
 
   sql ("BEGIN EXCLUSIVE;");
 
+  if (sql_int (0, 0,
+               "SELECT count(*) FROM tasks WHERE config = '%s'",
+               quoted_config))
+    {
+      g_free (quoted_config);
+      sql ("END;");
+      return 1;
+    }
+
+  quoted_family = sql_quote (family);
+
   selector = config_nvt_selector (config);
   if (selector == NULL)
     /* The config should always have a selector. */
@@ -8479,7 +8516,7 @@
  * @param[in]  growing_families      The rest of the growing families.
  * @param[in]  grow_families         1 if families should grow, else 0.
  *
- * @return 0 success, -1 error.
+ * @return 0 success, config in use, -1 error.
  */
 int
 manage_set_config_families (const char* config,
@@ -8493,14 +8530,26 @@
   int constraining;
   char *selector;
 
+  sql ("BEGIN EXCLUSIVE;");
+
+  quoted_config = sql_quote (config);
+
+  if (sql_int (0, 0,
+               "SELECT count(*) FROM tasks WHERE config = '%s'",
+               quoted_config))
+    {
+      g_free (quoted_config);
+      sql ("END;");
+      return 1;
+    }
+
   constraining = config_families_growing (config);
 
-  sql ("BEGIN EXCLUSIVE;");
-
   if (constraining + grow_families == 1)
     {
       if (switch_representation (config, constraining))
         {
+          g_free (quoted_config);
           sql ("END;");
           return -1;
         }
@@ -8511,14 +8560,13 @@
   if (selector == NULL)
     {
       /* The config should always have a selector. */
+      g_free (quoted_config);
       sql ("END;");
       return -1;
     }
   quoted_selector = sql_quote (selector);
   free (selector);
 
-  quoted_config = sql_quote (config);
-
   /* Loop through all the known families. */
 
   init_family_iterator (&families, 1, NULL, 1);

_______________________________________________
Openvas-commits mailing list
Openvas-commits@wald.intevation.org
http://lists.wald.intevation.org/mailman/listinfo/openvas-commits
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic