Author: mattm
Date: 2016-10-14 14:32:02 +0200 (Fri, 14 Oct 2016)
New Revision: 26409

Modified:
   trunk/openvas-manager/ChangeLog
   trunk/openvas-manager/src/manage_config_discovery.c
   trunk/openvas-manager/src/manage_sql.c
Log:
        * src/manage_sql.c (check_db_configs): Recover lost Service Detection
        NVTs.

        * src/manage_config_discovery.c
        (make_config_discovery_service_detection): New function.
        (make_config_discovery): Use new function.

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog     2016-10-14 11:43:12 UTC (rev 26408)
+++ trunk/openvas-manager/ChangeLog     2016-10-14 12:32:02 UTC (rev 26409)
@@ -1,5 +1,14 @@
 2016-10-14  Matthew Mundell <matthew.mund...@greenbone.net>
 
+       * src/manage_sql.c (check_db_configs): Recover lost Service Detection
+       NVTs.
+
+       * src/manage_config_discovery.c
+       (make_config_discovery_service_detection): New function.
+       (make_config_discovery): Use new function.
+
+2016-10-14  Matthew Mundell <matthew.mund...@greenbone.net>
+
        * src/manage_sql.c (check_db_configs): Only check for removed Service
        Detection NVTs when there are NVTs in the nvts table.
 

Modified: trunk/openvas-manager/src/manage_config_discovery.c
===================================================================
--- trunk/openvas-manager/src/manage_config_discovery.c 2016-10-14 11:43:12 UTC 
(rev 26408)
+++ trunk/openvas-manager/src/manage_config_discovery.c 2016-10-14 12:32:02 UTC 
(rev 26409)
@@ -51,19 +51,8 @@
  * @param[in]  selector_name  Name of NVT selector to use.
  */
 void
-make_config_discovery (char *const uuid, char *const selector_name)
+make_config_discovery_service_detection (char *const selector_name)
 {
-  /* First, create the Discovery config. */
-  sql ("INSERT into configs (uuid, name, owner, nvt_selector, comment,"
-       " family_count, nvt_count, nvts_growing, families_growing,"
-       " type, creation_time, modification_time)"
-       " VALUES ('%s', 'Discovery', NULL,"
-       "         '%s', 'Network Discovery scan configuration.',"
-       "         0, 0, 0, 0, 0, m_now (), m_now ());",
-       uuid,
-       selector_name);
-
-  /* Setup the appropriate NVTs for the config. */
   NVT_SELECTOR (selector_name, "1.3.6.1.4.1.25623.1.0.11929", "Service 
detection");
   NVT_SELECTOR (selector_name, "1.3.6.1.4.1.25623.1.0.900534", "Service 
detection");
   NVT_SELECTOR (selector_name, "1.3.6.1.4.1.25623.1.0.902019", "Service 
detection");
@@ -580,6 +569,31 @@
   NVT_SELECTOR (selector_name, "1.3.6.1.4.1.25623.1.0.900371", "Service 
detection");
   NVT_SELECTOR (selector_name, "1.3.6.1.4.1.25623.1.0.900374", "Service 
detection");
   NVT_SELECTOR (selector_name, "1.3.6.1.4.1.25623.1.0.900376", "Service 
detection");
+}
+
+/**
+ * @brief Make Discovery Scan Config.
+ *
+ * Caller must lock the db.
+ *
+ * @param[in]  uuid           UUID for new scan config.
+ * @param[in]  selector_name  Name of NVT selector to use.
+ */
+void
+make_config_discovery (char *const uuid, char *const selector_name)
+{
+  /* First, create the Discovery config. */
+  sql ("INSERT into configs (uuid, name, owner, nvt_selector, comment,"
+       " family_count, nvt_count, nvts_growing, families_growing,"
+       " type, creation_time, modification_time)"
+       " VALUES ('%s', 'Discovery', NULL,"
+       "         '%s', 'Network Discovery scan configuration.',"
+       "         0, 0, 0, 0, 0, m_now (), m_now ());",
+       uuid,
+       selector_name);
+
+  /* Setup the appropriate NVTs for the config. */
+  make_config_discovery_service_detection (selector_name);
   NVT_SELECTOR (selector_name, "1.3.6.1.4.1.25623.1.0.17586", "Brute force 
attacks");
   NVT_SELECTOR (selector_name, "1.3.6.1.4.1.25623.1.0.17584", "Brute force 
attacks");
   NVT_SELECTOR (selector_name, "1.3.6.1.4.1.25623.1.0.17368", "Brute force 
attacks");

Modified: trunk/openvas-manager/src/manage_sql.c
===================================================================
--- trunk/openvas-manager/src/manage_sql.c      2016-10-14 11:43:12 UTC (rev 
26408)
+++ trunk/openvas-manager/src/manage_sql.c      2016-10-14 12:32:02 UTC (rev 
26409)
@@ -166,6 +166,9 @@
 make_config_discovery (char *const, const char * const);
 
 void
+make_config_discovery_service_detection (char * const);
+
+void
 make_config_host_discovery (char *const, const char * const);
 
 void
@@ -14747,6 +14750,16 @@
     make_config_discovery (CONFIG_UUID_DISCOVERY,
                            MANAGE_NVT_SELECTOR_UUID_DISCOVERY);
 
+  /* Service Detection NVTs were all being accidentally removed by the
+   * checks below.  Recover them. */
+
+  if (sql_int ("SELECT count (*) FROM nvt_selectors"
+               " WHERE name = '" MANAGE_NVT_SELECTOR_UUID_DISCOVERY "'"
+               " AND family = 'Service detection'")
+      == 0)
+    make_config_discovery_service_detection
+     (MANAGE_NVT_SELECTOR_UUID_DISCOVERY);
+
   /* In the Service Detection family, NVTs sometimes move to Product
    * Detection, and once an NVT was removed.  So remove those NVTs
    * from Service Detection in the NVT selector. */

_______________________________________________
Openvas-commits mailing list
Openvas-commits@wald.intevation.org
https://lists.wald.intevation.org/cgi-bin/mailman/listinfo/openvas-commits

Reply via email to