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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Sep 27 18:26:59 CEST 2011


Author: mattm
Date: 2011-09-27 18:26:55 +0200 (Tue, 27 Sep 2011)
New Revision: 11704

Modified:
   trunk/openvas-manager/CMakeLists.txt
   trunk/openvas-manager/ChangeLog
   trunk/openvas-manager/doc/db.png
   trunk/openvas-manager/doc/db_postgres.sql
   trunk/openvas-manager/src/manage_sql.c
   trunk/openvas-manager/src/omp.c
Log:
	Add support for storing the user's timezone in the db.  Hence increase
	database version to 51.  Add database migration from version 50 to 51.
	Include user timezone and role in the AUTHENTICATE response.

	* CMakeLists.txt (OPENVASMD_DATABASE_VERSION): Increase to 51.

	* src/manage_sql.c (create_tables): Add timezone to users.
	(migrate_50_to_51): New function.
	(database_migrators): Add migrate_50_to_51.
	(authenticate): Set credentials role and timezone.

	* src/omp.c (omp_xml_handle_end_element): Add ROLE and TIMEZONE to
	AUTHENTICATE response.

	* doc/db_postgres.sql (users): Add timezone.

	* doc/db.png: Update from SQL.

Modified: trunk/openvas-manager/CMakeLists.txt
===================================================================
--- trunk/openvas-manager/CMakeLists.txt	2011-09-27 16:16:23 UTC (rev 11703)
+++ trunk/openvas-manager/CMakeLists.txt	2011-09-27 16:26:55 UTC (rev 11704)
@@ -105,7 +105,7 @@
 
 ## Variables
 
-set (OPENVASMD_DATABASE_VERSION 50)
+set (OPENVASMD_DATABASE_VERSION 51)
 
 if (SYSCONF_INSTALL_DIR)
   set (SYSCONFDIR "${SYSCONF_INSTALL_DIR}")

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog	2011-09-27 16:16:23 UTC (rev 11703)
+++ trunk/openvas-manager/ChangeLog	2011-09-27 16:26:55 UTC (rev 11704)
@@ -1,5 +1,25 @@
 2011-09-27  Matthew Mundell <matthew.mundell at greenbone.net>
 
+	Add support for storing the user's timezone in the db.  Hence increase
+	database version to 51.  Add database migration from version 50 to 51.
+	Include user timezone and role in the AUTHENTICATE response.
+
+	* CMakeLists.txt (OPENVASMD_DATABASE_VERSION): Increase to 51.
+
+	* src/manage_sql.c (create_tables): Add timezone to users.
+	(migrate_50_to_51): New function.
+	(database_migrators): Add migrate_50_to_51.
+	(authenticate): Set credentials role and timezone.
+
+	* src/omp.c (omp_xml_handle_end_element): Add ROLE and TIMEZONE to
+	AUTHENTICATE response.
+
+	* doc/db_postgres.sql (users): Add timezone.
+
+	* doc/db.png: Update from SQL.
+
+2011-09-27  Matthew Mundell <matthew.mundell at greenbone.net>
+
 	* src/manage_sql.c (cvss_threat, prognosis_where_levels): Use the CVSS
 	threat mapping from CR 42.
 

Modified: trunk/openvas-manager/doc/db.png
===================================================================
(Binary files differ)

Modified: trunk/openvas-manager/doc/db_postgres.sql
===================================================================
--- trunk/openvas-manager/doc/db_postgres.sql	2011-09-27 16:16:23 UTC (rev 11703)
+++ trunk/openvas-manager/doc/db_postgres.sql	2011-09-27 16:26:55 UTC (rev 11704)
@@ -93,7 +93,8 @@
 	id integer PRIMARY KEY,
     uuid text UNIQUE NOT NULL,
     name text NOT NULL,
-	password text);
+	password text,
+	timezone text);
 
 CREATE TABLE nvt_selectors (
 	id integer PRIMARY KEY,

Modified: trunk/openvas-manager/src/manage_sql.c
===================================================================
--- trunk/openvas-manager/src/manage_sql.c	2011-09-27 16:16:23 UTC (rev 11703)
+++ trunk/openvas-manager/src/manage_sql.c	2011-09-27 16:26:55 UTC (rev 11704)
@@ -1259,7 +1259,7 @@
   sql ("CREATE TABLE IF NOT EXISTS task_preferences (id INTEGER PRIMARY KEY, task INTEGER, name, value);");
   sql ("CREATE TABLE IF NOT EXISTS tasks   (id INTEGER PRIMARY KEY, uuid, owner INTEGER, name, hidden INTEGER, time, comment, description, run_status INTEGER, start_time, end_time, config INTEGER, target INTEGER, schedule INTEGER, schedule_next_time, slave INTEGER, config_location INTEGER, target_location INTEGER, schedule_location INTEGER, slave_location INTEGER, upload_result_count INTEGER);");
   sql ("CREATE TABLE IF NOT EXISTS task_users (id INTEGER PRIMARY KEY, task INTEGER, user INTEGER, actions INTEGER);");
-  sql ("CREATE TABLE IF NOT EXISTS users   (id INTEGER PRIMARY KEY, uuid UNIQUE, name, password);");
+  sql ("CREATE TABLE IF NOT EXISTS users   (id INTEGER PRIMARY KEY, uuid UNIQUE, name, password, timezone);");
 
   sql ("ANALYZE;");
 }
@@ -5130,6 +5130,40 @@
 }
 
 /**
+ * @brief Migrate the database from version 50 to version 51.
+ *
+ * @return 0 success, -1 error.
+ */
+static int
+migrate_50_to_51 ()
+{
+  sql ("BEGIN EXCLUSIVE;");
+
+  /* Ensure that the database is currently version 50. */
+
+  if (manage_db_version () != 50)
+    {
+      sql ("ROLLBACK;");
+      return -1;
+    }
+
+  /* Update the database. */
+
+  /* The user table got a timezone column. */
+
+  sql ("ALTER TABLE users ADD column timezone;");
+  sql ("UPDATE users SET timezone = NULL;");
+
+  /* Set the database version to 51. */
+
+  set_db_version (51);
+
+  sql ("COMMIT;");
+
+  return 0;
+}
+
+/**
  * @brief Array of database version migrators.
  */
 static migrator_t database_migrators[]
@@ -5184,6 +5218,7 @@
     {48, migrate_47_to_48},
     {49, migrate_48_to_49},
     {50, migrate_49_to_50},
+    {51, migrate_50_to_51},
     /* End marker. */
     {-1, NULL}};
 
@@ -8836,6 +8871,13 @@
         {
           gchar* quoted_name;
 
+          credentials->role
+            = g_strdup (openvas_is_user_admin (credentials->username)
+                         ? "Admin"
+                         : (openvas_is_user_observer (credentials->username)
+                             ? "Observer"
+                             : "User"));
+
           /* Ensure the user exists in the database.  SELECT then INSERT
            * instead of using "INSERT OR REPLACE", so that the ROWID stays
            * the same. */
@@ -8843,13 +8885,21 @@
           if (sql_int (0, 0,
                        "SELECT count(*) FROM users WHERE uuid = '%s';",
                        credentials->uuid))
-            return 0;
+            {
+              credentials->timezone = sql_string (0, 0,
+                                                  "SELECT timezone FROM users"
+                                                  " WHERE uuid = '%s';",
+                                                  credentials->uuid);
+              return 0;
+            }
 
           quoted_name = sql_quote (credentials->username);
-          sql ("INSERT INTO users (uuid, name) VALUES ('%s', '%s');",
+          sql ("INSERT INTO users (uuid, name, timezone)"
+               " VALUES ('%s', '%s', NULL);",
                credentials->uuid,
                quoted_name);
           g_free (quoted_name);
+          credentials->timezone = NULL;
           return 0;
         }
       return fail;

Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c	2011-09-27 16:16:23 UTC (rev 11703)
+++ trunk/openvas-manager/src/omp.c	2011-09-27 16:26:55 UTC (rev 11704)
@@ -8948,7 +8948,18 @@
                 }
               else
                 {
-                  SEND_TO_CLIENT_OR_FAIL (XML_OK ("authenticate"));
+                  SENDF_TO_CLIENT_OR_FAIL ("<authenticate_response"
+                                           " status=\"" STATUS_OK "\""
+                                           " status_text=\"" STATUS_OK_TEXT "\">"
+                                           "<role>%s</role>"
+                                           "<timezone>%s</timezone>"
+                                           "</authenticate_response>",
+                                           current_credentials.role
+                                             ? current_credentials.role
+                                             : "",
+                                           current_credentials.timezone
+                                             ? current_credentials.timezone
+                                             : "");
                   set_client_state (CLIENT_AUTHENTIC);
                 }
               break;



More information about the Openvas-commits mailing list