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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Oct 6 11:38:05 CEST 2009


Author: mattm
Date: 2009-10-06 11:38:00 +0200 (Tue, 06 Oct 2009)
New Revision: 5391

Modified:
   trunk/openvas-manager/ChangeLog
   trunk/openvas-manager/src/manage.h
   trunk/openvas-manager/src/omp.c
   trunk/openvas-manager/src/omp.h
   trunk/openvas-manager/src/ompd.c
   trunk/openvas-manager/src/ompd.h
   trunk/openvas-manager/src/openvasmd.c
   trunk/openvas-manager/src/tasks_sql.h
Log:
	Complete database initialisation check started yesterday.

	* src/tasks_sql.h (init_manage): Add nvt_cache_mode arg.  Update caller.
	Enable and complete database initialisation check.
	* src/manage.h: Update header.

	* src/omp.c (init_omp): Add nvt_cache_mode arg.  Update caller.
	* src/omp.h: Update header.

	* src/ompd.c (init_ompd): Add nvt_cache_mode arg.  Update caller.
	* src/ompd.h: Update header.

	* src/openvasmd.c (main): Add "must init" failure to init_ompd return
	checks.

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog	2009-10-06 09:21:55 UTC (rev 5390)
+++ trunk/openvas-manager/ChangeLog	2009-10-06 09:38:00 UTC (rev 5391)
@@ -1,3 +1,20 @@
+2009-10-06  Matthew Mundell <matthew.mundell at intevation.de>
+
+	Complete database initialisation check started yesterday.
+
+	* src/tasks_sql.h (init_manage): Add nvt_cache_mode arg.  Update caller.
+	Enable and complete database initialisation check.
+	* src/manage.h: Update header.
+
+	* src/omp.c (init_omp): Add nvt_cache_mode arg.  Update caller.
+	* src/omp.h: Update header.
+
+	* src/ompd.c (init_ompd): Add nvt_cache_mode arg.  Update caller.
+	* src/ompd.h: Update header.
+
+	* src/openvasmd.c (main): Add "must init" failure to init_ompd return
+	checks.
+
 2009-10-05  Matthew Mundell <matthew.mundell at intevation.de>
 
 	Move caching of NVT preferences to the database.

Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h	2009-10-06 09:21:55 UTC (rev 5390)
+++ trunk/openvas-manager/src/manage.h	2009-10-06 09:38:00 UTC (rev 5391)
@@ -52,7 +52,7 @@
 extern scanner_t scanner;
 
 int
-init_manage (GSList*);
+init_manage (GSList*, int);
 
 void
 init_manage_process ();

Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c	2009-10-06 09:21:55 UTC (rev 5390)
+++ trunk/openvas-manager/src/omp.c	2009-10-06 09:38:00 UTC (rev 5391)
@@ -5174,18 +5174,19 @@
  * @brief Initialise OMP library.
  *
  * @param[in]  log_config  Logging configuration list.
+ * @param[in]  nvt_cache_mode  True when running in NVT caching mode.
  *
  * @return 0 success, -1 error, -2 database is wrong version, -3 database
  *         needs to be initialized from server.
  */
 int
-init_omp (GSList *log_config)
+init_omp (GSList *log_config, int nvt_cache_mode)
 {
   g_log_set_handler (G_LOG_DOMAIN,
                      ALL_LOG_LEVELS,
                      (GLogFunc) openvas_log_func,
                      log_config);
-  return init_manage (log_config);
+  return init_manage (log_config, nvt_cache_mode);
 }
 
 /**

Modified: trunk/openvas-manager/src/omp.h
===================================================================
--- trunk/openvas-manager/src/omp.h	2009-10-06 09:21:55 UTC (rev 5390)
+++ trunk/openvas-manager/src/omp.h	2009-10-06 09:38:00 UTC (rev 5391)
@@ -36,7 +36,7 @@
 #define TO_CLIENT_BUFFER_SIZE 26214400
 
 int
-init_omp (GSList*);
+init_omp (GSList*, int);
 
 void
 init_omp_process ();

Modified: trunk/openvas-manager/src/ompd.c
===================================================================
--- trunk/openvas-manager/src/ompd.c	2009-10-06 09:21:55 UTC (rev 5390)
+++ trunk/openvas-manager/src/ompd.c	2009-10-06 09:38:00 UTC (rev 5391)
@@ -93,15 +93,16 @@
 /**
  * @brief Initialise the OMP library for the OMP daemon.
  *
- * @param[in]  log_config  Log configuration
+ * @param[in]  log_config      Log configuration
+ * @param[in]  nvt_cache_mode  True when running in NVT caching mode.
  *
  * @return 0 success, -1 error, -2 database is wrong version, -3 database
  *         needs to be initialized from server.
  */
 int
-init_ompd (GSList *log_config)
+init_ompd (GSList *log_config, int nvt_cache_mode)
 {
-  return init_omp (log_config);
+  return init_omp (log_config, nvt_cache_mode);
 }
 
 /**

Modified: trunk/openvas-manager/src/ompd.h
===================================================================
--- trunk/openvas-manager/src/ompd.h	2009-10-06 09:21:55 UTC (rev 5390)
+++ trunk/openvas-manager/src/ompd.h	2009-10-06 09:38:00 UTC (rev 5391)
@@ -31,7 +31,7 @@
 #include <gnutls/gnutls.h>
 
 int
-init_ompd (GSList*);
+init_ompd (GSList*, int);
 
 int
 serve_omp (gnutls_session_t*, gnutls_session_t*,

Modified: trunk/openvas-manager/src/openvasmd.c
===================================================================
--- trunk/openvas-manager/src/openvasmd.c	2009-10-06 09:21:55 UTC (rev 5390)
+++ trunk/openvas-manager/src/openvasmd.c	2009-10-06 09:38:00 UTC (rev 5391)
@@ -627,7 +627,7 @@
 
       /* Initialise OMP daemon. */
 
-      switch (init_ompd (log_config))
+      switch (init_ompd (log_config, 1))
         {
           case 0:
             break;
@@ -636,6 +636,8 @@
             free_log_configuration (log_config);
             exit (EXIT_FAILURE);
             break;
+          case -3:
+            assert (0);
           case -1:
           default:
             g_critical ("%s: failed to initialise OMP daemon\n", __FUNCTION__);
@@ -792,7 +794,7 @@
 
   /* Initialise OMP daemon. */
 
-  switch (init_ompd (log_config))
+  switch (init_ompd (log_config, 0))
     {
       case 0:
         break;
@@ -801,6 +803,13 @@
         free_log_configuration (log_config);
         exit (EXIT_FAILURE);
         break;
+      case -3:
+        g_critical ("%s: database must be initialised"
+                    " (with the --update command line option)\n",
+                    __FUNCTION__);
+        free_log_configuration (log_config);
+        exit (EXIT_FAILURE);
+        break;
       case -1:
       default:
         g_critical ("%s: failed to initialise OMP daemon\n", __FUNCTION__);

Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h	2009-10-06 09:21:55 UTC (rev 5390)
+++ trunk/openvas-manager/src/tasks_sql.h	2009-10-06 09:38:00 UTC (rev 5391)
@@ -889,11 +889,14 @@
  * Beware that calling this function while tasks are running may lead to
  * problems.
  *
+ * @param[in]  log_config      Log configuration.
+ * @param[in]  nvt_cache_mode  True when running in NVT caching mode.
+ *
  * @return 0 success, -1 error, -2 database is wrong version, -3 database needs
  *         to be initialised from server.
  */
 int
-init_manage (GSList *log_config)
+init_manage (GSList *log_config, int nvt_cache_mode)
 {
   const char *database_version;
   task_t index;
@@ -911,25 +914,36 @@
   database_version = sql_string (0, 0,
                                  "SELECT value FROM meta"
                                  " WHERE name = 'database_version';");
-  if (database_version
-      && strcmp (database_version, G_STRINGIFY (DATABASE_VERSION)))
-    return -2;
+  if (nvt_cache_mode)
+    {
+      if (database_version
+          && strcmp (database_version, G_STRINGIFY (DATABASE_VERSION)))
+        return -2;
 
-#if 0
-  /** @todo Skip this when in NVT caching mode. */
+      /* If database_version was NULL then meta was missing, so assume
+       * that the database is missing, which is OK. */
+    }
+  else
+    {
+      if (database_version)
+        {
+          if (strcmp (database_version, G_STRINGIFY (DATABASE_VERSION)))
+            return -2;
+        }
+      else
+        /* Assume database is missing. */
+        return -3;
 
-  /* Check that the database was initialised from the scanner. */
+      /* Check that the database was initialised from the scanner. */
 
-  {
-    long long int count;
-    if (sql_int64 (&count, 0, 0,
-                   "SELECT count(*) FROM meta"
-                   " WHERE name = 'nvt_md5sum'"
-                   " OR name = 'nvt_preferences_enabled';")
-        || count < 2)
-      return -3;
-  }
-#endif
+      long long int count;
+      if (sql_int64 (&count, 0, 0,
+                     "SELECT count(*) FROM meta"
+                     " WHERE name = 'nvts_md5sum'"
+                     " OR name = 'nvt_preferences_enabled';")
+          || count < 2)
+        return -3;
+    }
 
   /* Ensure the tables exist. */
 



More information about the Openvas-commits mailing list