From: Marcin Siodelski Date: Fri, 25 Jan 2019 16:11:26 +0000 (+0100) Subject: [#396,!205] Return audit for the specified server. X-Git-Tag: 429-Updated-StampedValue-to-support-reals_base~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eeb089d4c28b4f3094541019192f98acc50e8f9e;p=thirdparty%2Fkea.git [#396,!205] Return audit for the specified server. --- diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc index 7c53bdd7f5..b89ff68932 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc @@ -2576,11 +2576,11 @@ getModifiedGlobalParameters4(const db::ServerSelector& server_selector, AuditEntryCollection MySqlConfigBackendDHCPv4:: -getRecentAuditEntries4(const db::ServerSelector&, +getRecentAuditEntries4(const db::ServerSelector& server_selector, const boost::posix_time::ptime& modification_time) const { AuditEntryCollection audit_entries; impl_->getRecentAuditEntries(MySqlConfigBackendDHCPv4Impl::GET_AUDIT_ENTRIES4_TIME, - modification_time, audit_entries); + server_selector, modification_time, audit_entries); return (audit_entries); } diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc index 67213e88ab..ff104bc5cb 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc @@ -112,6 +112,7 @@ MySqlConfigBackendImpl::clearAuditRevision() { void MySqlConfigBackendImpl::getRecentAuditEntries(const int index, + const db::ServerSelector& server_selector, const boost::posix_time::ptime& modification_time, AuditEntryCollection& audit_entries) { // Create the output bindings for receiving the data. @@ -124,27 +125,33 @@ MySqlConfigBackendImpl::getRecentAuditEntries(const int index, MySqlBinding::createString(AUDIT_ENTRY_LOG_MESSAGE_BUF_LENGTH) }; - // There is only one input binding, modification time. - MySqlBindingCollection in_bindings = { - MySqlBinding::createTimestamp(modification_time) - }; - - // Execute select. - conn_.selectQuery(index, in_bindings, out_bindings, - [&audit_entries] (MySqlBindingCollection& out_bindings) { - // Convert the numeric modification type into modification type enum. - AuditEntry::ModificationType mod_type = - static_cast(out_bindings[3]->getInteger()); - - // Create new audit entry and add it to the collection of received - // entries. - AuditEntryPtr audit_entry(new AuditEntry(out_bindings[1]->getString(), - out_bindings[2]->getInteger(), - mod_type, - out_bindings[4]->getTimestamp(), - out_bindings[5]->getStringOrDefault(""))); - audit_entries.insert(audit_entry); - }); + auto tags = getServerTags(server_selector); + + for (auto tag : tags) { + + // There is only one input binding, modification time. + MySqlBindingCollection in_bindings = { + MySqlBinding::createString(tag), + MySqlBinding::createTimestamp(modification_time) + }; + + // Execute select. + conn_.selectQuery(index, in_bindings, out_bindings, + [&audit_entries] (MySqlBindingCollection& out_bindings) { + // Convert the numeric modification type into modification type enum. + AuditEntry::ModificationType mod_type = + static_cast(out_bindings[3]->getInteger()); + + // Create new audit entry and add it to the collection of received + // entries. + AuditEntryPtr audit_entry(new AuditEntry(out_bindings[1]->getString(), + out_bindings[2]->getInteger(), + mod_type, + out_bindings[4]->getTimestamp(), + out_bindings[5]->getStringOrDefault(""))); + audit_entries.insert(audit_entry); + }); + } } uint64_t diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h index 251ed136e6..0955595302 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h @@ -190,11 +190,13 @@ public: /// @brief Sends query to the database to retrieve most recent audit entries. /// /// @param index Index of the query to be used. + /// @param server_selector Server selector. /// @param modification_time Timestamp being a lower limit for the returned /// result set, i.e. entries later than specified time are returned. /// @param [out] audit_entries Reference to the container where fetched audit /// entries will be inserted. void getRecentAuditEntries(const int index, + const db::ServerSelector& server_selector, const boost::posix_time::ptime& modification_time, db::AuditEntryCollection& audit_entries); diff --git a/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h b/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h index ef6c4b770f..7e5fa0c312 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h +++ b/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h @@ -204,9 +204,11 @@ namespace { " r.modification_ts," \ " r.log_message " \ "FROM " #table_prefix "_audit AS a " \ - "LEFT JOIN " #table_prefix "_audit_revision AS r " \ + "INNER JOIN " #table_prefix "_audit_revision AS r " \ " ON a.revision_id = r.id " \ - "WHERE (r.modification_ts > ?) " \ + "INNER JOIN " #table_prefix "_server AS s" \ + " ON r.server_id = s.id " \ + "WHERE (s.tag = ? OR s.id = 1) AND (r.modification_ts > ?) " \ "ORDER BY r.modification_ts" #endif