diff options
-rw-r--r-- | src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc | 28 | ||||
-rw-r--r-- | src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc | 6 | ||||
-rw-r--r-- | src/hooks/dhcp/mysql_cb/mysql_cb_impl.h | 3 | ||||
-rw-r--r-- | src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc | 3 | ||||
-rw-r--r-- | src/lib/dhcpsrv/cfg_option.h | 9 | ||||
-rw-r--r-- | src/share/database/scripts/mysql/dhcpdb_create.mysql | 7 | ||||
-rw-r--r-- | src/share/database/scripts/mysql/upgrade_7.0_to_8.0.sh.in | 7 |
7 files changed, 37 insertions, 26 deletions
diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc index b89ff68932..02bedf31ef 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc @@ -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. diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc index ff104bc5cb..29cc777440 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc @@ -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)) diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h index 0955595302..e9d891cc0d 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h @@ -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); diff --git a/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc b/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc index b434bb3d4a..aa556d3815 100644 --- a/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc +++ b/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc @@ -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; diff --git a/src/lib/dhcpsrv/cfg_option.h b/src/lib/dhcpsrv/cfg_option.h index 92a6c4ee92..600321f7a8 100644 --- a/src/lib/dhcpsrv/cfg_option.h +++ b/src/lib/dhcpsrv/cfg_option.h @@ -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()); diff --git a/src/share/database/scripts/mysql/dhcpdb_create.mysql b/src/share/database/scripts/mysql/dhcpdb_create.mysql index b033ea8737..22b06f4dc4 100644 --- a/src/share/database/scripts/mysql/dhcpdb_create.mysql +++ b/src/share/database/scripts/mysql/dhcpdb_create.mysql @@ -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 $$ diff --git a/src/share/database/scripts/mysql/upgrade_7.0_to_8.0.sh.in b/src/share/database/scripts/mysql/upgrade_7.0_to_8.0.sh.in index ad9c5e2c27..2680aecda8 100644 --- a/src/share/database/scripts/mysql/upgrade_7.0_to_8.0.sh.in +++ b/src/share/database/scripts/mysql/upgrade_7.0_to_8.0.sh.in @@ -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 $$ |