]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#396,!205] Audit revision timestamp is set by Kea.
authorMarcin Siodelski <marcin@isc.org>
Mon, 28 Jan 2019 19:14:59 +0000 (20:14 +0100)
committerMarcin Siodelski <marcin@isc.org>
Wed, 30 Jan 2019 09:18:59 +0000 (10:18 +0100)
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc
src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc
src/hooks/dhcp/mysql_cb/mysql_cb_impl.h
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc
src/lib/dhcpsrv/cfg_option.h
src/share/database/scripts/mysql/dhcpdb_create.mysql
src/share/database/scripts/mysql/upgrade_7.0_to_8.0.sh.in

index b89ff6893273712e2a6644369dc6ae81e01f36d0..02bedf31efcf6e3e67f434346e0b70e7408b3a97 100644 (file)
@@ -755,8 +755,7 @@ public:
         // no new audit revisions are created in any subsequent calls.
         ScopedAuditRevision audit_revision(this,
                                            MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
-                                           server_selector,
-                                           "subnet set", true);
+                                           server_selector, "subnet set", true);
 
         try {
 
@@ -872,8 +871,7 @@ public:
         ScopedAuditRevision
             audit_revision(this,
                            MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
-                           server_selector,
-                           log_message, cascade_delete);
+                           server_selector, log_message, cascade_delete);
 
         auto count = deleteFromTable(index, server_selector, operation, keys...);
 
@@ -1166,8 +1164,7 @@ public:
         ScopedAuditRevision
             audit_revision(this,
                            MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
-                           server_selector,
-                           "shared network set", true);
+                           server_selector, "shared network set", true);
 
         try {
 
@@ -1281,8 +1278,7 @@ public:
         ScopedAuditRevision
             audit_revision(this,
                            MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
-                           server_selector,
-                           "global option set", false);
+                           server_selector, "global option set", false);
 
         if (existing_option) {
             in_bindings.push_back(MySqlBinding::createString(tag));
@@ -1352,8 +1348,8 @@ public:
         ScopedAuditRevision
             audit_revision(this,
                            MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
-                           server_selector,
-                           "subnet specific option set", cascade_update);
+                           server_selector, "subnet specific option set",
+                           cascade_update);
 
         if (existing_option) {
             in_bindings.push_back(MySqlBinding::createString(tag));
@@ -1441,8 +1437,8 @@ public:
         ScopedAuditRevision
             audit_revision(this,
                            MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
-                           server_selector,
-                           "pool specific option set", cascade_update);
+                           server_selector, "pool specific option set",
+                           cascade_update);
 
         if (existing_option) {
             in_bindings.push_back(MySqlBinding::createString(tag));
@@ -1512,8 +1508,7 @@ public:
         ScopedAuditRevision
             audit_revision(this,
                            MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
-                           server_selector,
-                           "shared network specific option set",
+                           server_selector, "shared network specific option set",
                            cascade_update);
 
         if (existing_option) {
@@ -1837,8 +1832,7 @@ public:
         ScopedAuditRevision
             audit_revision(this,
                            MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
-                           server_selector,
-                           "option definition set",
+                           server_selector, "option definition set",
                            true);
 
         if (existing_definition) {
@@ -2053,7 +2047,7 @@ TaggedStatementArray;
 /// retrieve data from the database.
 TaggedStatementArray tagged_statements = { {
     { MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
-      "CALL createAuditRevisionDHCP4(?, ?, ?)"
+      "CALL createAuditRevisionDHCP4(?, ?, ?, ?)"
     },
 
     // Select global parameter by name.
index ff104bc5cbd5ee530e1d7e0a003a6e2bde6eb581..29cc7774401a568f84c3dd698aa733f11d2d4220 100644 (file)
@@ -32,7 +32,9 @@ ScopedAuditRevision::ScopedAuditRevision(MySqlConfigBackendImpl* impl,
                                          const std::string& log_message,
                                          bool cascade_transaction)
     : impl_(impl) {
-    impl_->createAuditRevision(index, server_selector, log_message,
+    impl_->createAuditRevision(index, server_selector,
+                               boost::posix_time::microsec_clock::local_time(),
+                               log_message,
                                cascade_transaction);
 }
 
@@ -86,6 +88,7 @@ MySqlConfigBackendImpl::~MySqlConfigBackendImpl() {
 void
 MySqlConfigBackendImpl::createAuditRevision(const int index,
                                             const ServerSelector& server_selector,
+                                            const boost::posix_time::ptime& audit_ts,
                                             const std::string& log_message,
                                             const bool cascade_transaction) {
     // Do not touch existing audit revision in case of the cascade update.
@@ -97,6 +100,7 @@ MySqlConfigBackendImpl::createAuditRevision(const int index,
                             "audit revision");
 
     MySqlBindingCollection in_bindings = {
+        MySqlBinding::createTimestamp(audit_ts),
         MySqlBinding::createString(tag),
         MySqlBinding::createString(log_message),
         MySqlBinding::createInteger<uint8_t>(static_cast<uint8_t>(cascade_transaction))
index 0955595302fea2ce596082586f0663d547e9eed3..e9d891cc0dd194fae0d8ee7fb2e58a5343bf527f 100644 (file)
@@ -171,6 +171,8 @@ public:
     ///
     /// @param index query index.
     /// @param server_selector Server selector.
+    /// @param audit_ts Timestamp to be associated with the audit
+    /// revision.
     /// @param log_message log message to be used for the audit revision.
     /// @param cascade_transaction Boolean value indicating whether the
     /// configuration modification is performed as part of the ownining
@@ -179,6 +181,7 @@ public:
     /// audit entry for the owning element should be created.
     void createAuditRevision(const int index,
                              const db::ServerSelector& server_selector,
+                             const boost::posix_time::ptime& audit_ts,
                              const std::string& log_message,
                              const bool cascade_transaction);
 
index b434bb3d4a735657aae4904a04e0858e2581efa5..aa556d3815662c2063bd785e129fd26451858443 100644 (file)
@@ -296,6 +296,9 @@ public:
         timestamps_["tomorrow"] = timestamps_["today"] + boost::posix_time::hours(24);
     }
 
+    /// @brief Logs audit entries in the @c audit_entries_ member.
+    ///
+    /// This function is called in case of an error.
     std::string logExistingAuditEntries() {
         std::ostringstream s;
 
index 92a6c4ee92e0c9cbb650dd9da551a722c44ff177..600321f7a846d172cb93f2a8c3c052cdbf1397f5 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -80,7 +80,7 @@ public:
     OptionDescriptor(const OptionPtr& opt, bool persist,
                      const std::string& formatted_value = "",
                      data::ConstElementPtr user_context = data::ConstElementPtr())
-        : option_(opt), persistent_(persist),
+        : data::StampedElement(), option_(opt), persistent_(persist),
           formatted_value_(formatted_value),
           space_name_() {
         setContext(user_context);
@@ -90,14 +90,15 @@ public:
     ///
     /// @param persist if true option is always sent.
     OptionDescriptor(bool persist)
-        : option_(OptionPtr()), persistent_(persist),
+        : data::StampedElement(), option_(OptionPtr()), persistent_(persist),
           formatted_value_(), space_name_() {};
 
     /// @brief Constructor.
     ///
     /// @param desc descriptor
     OptionDescriptor(const OptionDescriptor& desc)
-        : option_(desc.option_), persistent_(desc.persistent_),
+        : data::StampedElement(), option_(desc.option_),
+          persistent_(desc.persistent_),
           formatted_value_(desc.formatted_value_),
           space_name_(desc.space_name_) {
         setContext(desc.getContext());
index b033ea873795cd2e60541afcd9190eb9bf7f3e34..22b06f4dc444d9717af25238f9c3d254d9646b87 100644 (file)
@@ -1459,6 +1459,8 @@ ALTER TABLE dhcp4_audit
 -- data in the database, e.g. when new subnet is added.
 --
 -- Parameters:
+-- - audit_ts timestamp to be associated with the audit
+--   revision.
 -- - server_tag is used to retrieve the server_id which
 --   associates the changes applied with the particular
 --   server or all servers.
@@ -1478,14 +1480,15 @@ ALTER TABLE dhcp4_audit
 -- -----------------------------------------------------
 DROP PROCEDURE IF EXISTS createAuditRevisionDHCP4;
 DELIMITER $$
-CREATE PROCEDURE createAuditRevisionDHCP4(IN server_tag VARCHAR(256),
+CREATE PROCEDURE createAuditRevisionDHCP4(IN audit_ts TIMESTAMP(6),
+                                          IN server_tag VARCHAR(256),
                                           IN audit_log_message TEXT,
                                           IN cascade_transaction TINYINT(1))
 BEGIN
     DECLARE srv_id BIGINT(20);
     SELECT id INTO srv_id FROM dhcp4_server WHERE tag = server_tag;
     INSERT INTO dhcp4_audit_revision (modification_ts, server_id, log_message)
-       VALUES (NOW(), srv_id, audit_log_message);
+       VALUES (audit_ts, srv_id, audit_log_message);
     SET @audit_revision_id = LAST_INSERT_ID();
     SET @cascade_transaction = cascade_transaction;
 END $$
index ad9c5e2c270bd85d801c97aa22f05e540cdac800..2680aecda8da73fc838b0ad1aab90925a3921152 100644 (file)
@@ -142,6 +142,8 @@ ALTER TABLE dhcp4_audit
 # data in the database, e.g. when new subnet is added.
 --
 # Parameters:
+# - audit_ts timestamp to be associated with the audit
+#   revision.
 # - server_tag is used to retrieve the server_id which
 #   associates the changes applied with the particular
 #   server or all servers.
@@ -161,14 +163,15 @@ ALTER TABLE dhcp4_audit
 # -----------------------------------------------------
 DROP PROCEDURE IF EXISTS createAuditRevisionDHCP4;
 DELIMITER $$
-CREATE PROCEDURE createAuditRevisionDHCP4(IN server_tag VARCHAR(256),
+CREATE PROCEDURE createAuditRevisionDHCP4(IN audit_ts TIMESTAMP(6),
+                                          IN server_tag VARCHAR(256),
                                           IN audit_log_message TEXT,
                                           IN cascade_transaction TINYINT(1))
 BEGIN
     DECLARE srv_id BIGINT(20);
     SELECT id INTO srv_id FROM dhcp4_server WHERE tag = server_tag;
     INSERT INTO dhcp4_audit_revision (modification_ts, server_id, log_message)
-       VALUES (NOW(), srv_id, audit_log_message);
+       VALUES (audit_ts, srv_id, audit_log_message);
     SET @audit_revision_id = LAST_INSERT_ID();
     SET @cascade_transaction = cascade_transaction;
 END $$