]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#396,!205] Return audit for the specified server.
authorMarcin Siodelski <marcin@isc.org>
Fri, 25 Jan 2019 16:11:26 +0000 (17:11 +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/mysql_query_macros_dhcp.h

index 7c53bdd7f51801bfd961d8612a96327c662d7487..b89ff6893273712e2a6644369dc6ae81e01f36d0 100644 (file)
@@ -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);
 }
index 67213e88ab5b6eac27e51250bdde1a26755bcb5a..ff104bc5cbd5ee530e1d7e0a003a6e2bde6eb581 100644 (file)
@@ -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<AuditEntry::ModificationType>(out_bindings[3]->getInteger<uint8_t>());
-
-        // 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<uint64_t>(),
-                                                 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<AuditEntry::ModificationType>(out_bindings[3]->getInteger<uint8_t>());
+
+            // 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<uint64_t>(),
+                                                     mod_type,
+                                                     out_bindings[4]->getTimestamp(),
+                                                     out_bindings[5]->getStringOrDefault("")));
+            audit_entries.insert(audit_entry);
+        });
+    }
 }
 
 uint64_t
index 251ed136e6eed7e4d22642c0e6546e660e8f0c82..0955595302fea2ce596082586f0663d547e9eed3 100644 (file)
@@ -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);
 
index ef6c4b770f4c83518336d09347d2b30d4005c761..7e5fa0c312d41e01be51cc7f9336e78a032391ed 100644 (file)
@@ -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