andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

Blame SOURCES/0005-Issue-4498-BUG-entryuuid-replication-may-not-work-45.patch

6d0b66
From b2e0a1d405d15383064e547fd15008bc136d3efe Mon Sep 17 00:00:00 2001
6d0b66
From: Firstyear <william@blackhats.net.au>
6d0b66
Date: Thu, 17 Dec 2020 08:22:23 +1000
6d0b66
Subject: [PATCH 05/12] Issue 4498 - BUG - entryuuid replication may not work
6d0b66
 (#4503)
6d0b66
6d0b66
Bug Description: EntryUUID can be duplicated in replication,
6d0b66
due to a missing check in assign_uuid
6d0b66
6d0b66
Fix Description: Add a test case to determine how this occurs,
6d0b66
and add the correct check for existing entryUUID.
6d0b66
6d0b66
fixes: https://github.com/389ds/389-ds-base/issues/4498
6d0b66
6d0b66
Author: William Brown <william@blackhats.net.au>
6d0b66
6d0b66
Review by: @mreynolds389
6d0b66
---
6d0b66
 .../tests/suites/entryuuid/replicated_test.py | 77 +++++++++++++++++++
6d0b66
 rpm.mk                                        |  2 +-
6d0b66
 src/plugins/entryuuid/src/lib.rs              | 20 ++++-
6d0b66
 src/slapi_r_plugin/src/constants.rs           |  2 +
6d0b66
 src/slapi_r_plugin/src/pblock.rs              |  7 ++
6d0b66
 5 files changed, 106 insertions(+), 2 deletions(-)
6d0b66
 create mode 100644 dirsrvtests/tests/suites/entryuuid/replicated_test.py
6d0b66
6d0b66
diff --git a/dirsrvtests/tests/suites/entryuuid/replicated_test.py b/dirsrvtests/tests/suites/entryuuid/replicated_test.py
6d0b66
new file mode 100644
6d0b66
index 000000000..a2ebc8ff7
6d0b66
--- /dev/null
6d0b66
+++ b/dirsrvtests/tests/suites/entryuuid/replicated_test.py
6d0b66
@@ -0,0 +1,77 @@
6d0b66
+# --- BEGIN COPYRIGHT BLOCK ---
6d0b66
+# Copyright (C) 2020 William Brown <william@blackhats.net.au>
6d0b66
+# All rights reserved.
6d0b66
+#
6d0b66
+# License: GPL (version 3 or any later version).
6d0b66
+# See LICENSE for details.
6d0b66
+# --- END COPYRIGHT BLOCK ---
6d0b66
+
6d0b66
+import ldap
6d0b66
+import pytest
6d0b66
+import logging
6d0b66
+from lib389.topologies import topology_m2 as topo_m2
6d0b66
+from lib389.idm.user import nsUserAccounts
6d0b66
+from lib389.paths import Paths
6d0b66
+from lib389.utils import ds_is_older
6d0b66
+from lib389._constants import *
6d0b66
+from lib389.replica import ReplicationManager
6d0b66
+
6d0b66
+default_paths = Paths()
6d0b66
+
6d0b66
+pytestmark = pytest.mark.tier1
6d0b66
+
6d0b66
+@pytest.mark.skipif(not default_paths.rust_enabled or ds_is_older('1.4.2.0'), reason="Entryuuid is not available in older versions")
6d0b66
+
6d0b66
+def test_entryuuid_with_replication(topo_m2):
6d0b66
+    """ Check that entryuuid works with replication
6d0b66
+
6d0b66
+    :id: a5f15bf9-7f63-473a-840c-b9037b787024
6d0b66
+
6d0b66
+    :setup: two node mmr
6d0b66
+
6d0b66
+    :steps:
6d0b66
+        1. Create an entry on one server
6d0b66
+        2. Wait for replication
6d0b66
+        3. Assert it is on the second
6d0b66
+
6d0b66
+    :expectedresults:
6d0b66
+        1. Success
6d0b66
+        1. Success
6d0b66
+        1. Success
6d0b66
+    """
6d0b66
+
6d0b66
+    server_a = topo_m2.ms["supplier1"]
6d0b66
+    server_b = topo_m2.ms["supplier2"]
6d0b66
+    server_a.config.loglevel(vals=(ErrorLog.DEFAULT,ErrorLog.TRACE))
6d0b66
+    server_b.config.loglevel(vals=(ErrorLog.DEFAULT,ErrorLog.TRACE))
6d0b66
+
6d0b66
+    repl = ReplicationManager(DEFAULT_SUFFIX)
6d0b66
+
6d0b66
+    account_a = nsUserAccounts(server_a, DEFAULT_SUFFIX).create_test_user(uid=2000)
6d0b66
+    euuid_a = account_a.get_attr_vals_utf8('entryUUID')
6d0b66
+    print("🧩 %s" % euuid_a)
6d0b66
+    assert(euuid_a is not None)
6d0b66
+    assert(len(euuid_a) == 1)
6d0b66
+
6d0b66
+    repl.wait_for_replication(server_a, server_b)
6d0b66
+
6d0b66
+    account_b = nsUserAccounts(server_b, DEFAULT_SUFFIX).get("test_user_2000")
6d0b66
+    euuid_b = account_b.get_attr_vals_utf8('entryUUID')
6d0b66
+    print("🧩 %s" % euuid_b)
6d0b66
+
6d0b66
+    server_a.config.loglevel(vals=(ErrorLog.DEFAULT,))
6d0b66
+    server_b.config.loglevel(vals=(ErrorLog.DEFAULT,))
6d0b66
+
6d0b66
+    assert(euuid_b is not None)
6d0b66
+    assert(len(euuid_b) == 1)
6d0b66
+    assert(euuid_b == euuid_a)
6d0b66
+
6d0b66
+    account_b.set("description", "update")
6d0b66
+    repl.wait_for_replication(server_b, server_a)
6d0b66
+
6d0b66
+    euuid_c = account_a.get_attr_vals_utf8('entryUUID')
6d0b66
+    print("🧩 %s" % euuid_c)
6d0b66
+    assert(euuid_c is not None)
6d0b66
+    assert(len(euuid_c) == 1)
6d0b66
+    assert(euuid_c == euuid_a)
6d0b66
+
6d0b66
diff --git a/rpm.mk b/rpm.mk
6d0b66
index 02f5bba37..d1cdff7df 100644
6d0b66
--- a/rpm.mk
6d0b66
+++ b/rpm.mk
6d0b66
@@ -25,7 +25,7 @@ TSAN_ON = 0
6d0b66
 # Undefined Behaviour Sanitizer
6d0b66
 UBSAN_ON = 0
6d0b66
 
6d0b66
-RUST_ON = 0
6d0b66
+RUST_ON = 1
6d0b66
 
6d0b66
 # PERL_ON is deprecated and turns on the LEGACY_ON, this for not breaking people's workflows.
6d0b66
 PERL_ON = 1
6d0b66
diff --git a/src/plugins/entryuuid/src/lib.rs b/src/plugins/entryuuid/src/lib.rs
6d0b66
index 92977db05..0197c5e83 100644
6d0b66
--- a/src/plugins/entryuuid/src/lib.rs
6d0b66
+++ b/src/plugins/entryuuid/src/lib.rs
6d0b66
@@ -30,6 +30,16 @@ slapi_r_search_callback_mapfn!(entryuuid, entryuuid_fixup_cb, entryuuid_fixup_ma
6d0b66
 fn assign_uuid(e: &mut EntryRef) {
6d0b66
     let sdn = e.get_sdnref();
6d0b66
 
6d0b66
+    // 🚧 safety barrier 🚧
6d0b66
+    if e.contains_attr("entryUUID") {
6d0b66
+        log_error!(
6d0b66
+            ErrorLevel::Trace,
6d0b66
+            "assign_uuid -> entryUUID exists, skipping dn {}",
6d0b66
+            sdn.to_dn_string()
6d0b66
+        );
6d0b66
+        return;
6d0b66
+    }
6d0b66
+
6d0b66
     // We could consider making these lazy static.
6d0b66
     let config_sdn = Sdn::try_from("cn=config").expect("Invalid static dn");
6d0b66
     let schema_sdn = Sdn::try_from("cn=schema").expect("Invalid static dn");
6d0b66
@@ -66,7 +76,15 @@ impl SlapiPlugin3 for EntryUuid {
6d0b66
     }
6d0b66
 
6d0b66
     fn betxn_pre_add(pb: &mut PblockRef) -> Result<(), PluginError> {
6d0b66
-        log_error!(ErrorLevel::Trace, "betxn_pre_add");
6d0b66
+        if pb.get_is_replicated_operation() {
6d0b66
+            log_error!(
6d0b66
+                ErrorLevel::Trace,
6d0b66
+                "betxn_pre_add -> replicated operation, will not change"
6d0b66
+            );
6d0b66
+            return Ok(());
6d0b66
+        }
6d0b66
+
6d0b66
+        log_error!(ErrorLevel::Trace, "betxn_pre_add -> start");
6d0b66
 
6d0b66
         let mut e = pb.get_op_add_entryref().map_err(|_| PluginError::Pblock)?;
6d0b66
         assign_uuid(&mut e);
6d0b66
diff --git a/src/slapi_r_plugin/src/constants.rs b/src/slapi_r_plugin/src/constants.rs
6d0b66
index 34845c2f4..aa0691acc 100644
6d0b66
--- a/src/slapi_r_plugin/src/constants.rs
6d0b66
+++ b/src/slapi_r_plugin/src/constants.rs
6d0b66
@@ -164,6 +164,8 @@ pub(crate) enum PblockType {
6d0b66
     AddEntry = 60,
6d0b66
     /// SLAPI_BACKEND
6d0b66
     Backend = 130,
6d0b66
+    /// SLAPI_IS_REPLICATED_OPERATION
6d0b66
+    IsReplicationOperation = 142,
6d0b66
     /// SLAPI_PLUGIN_MR_NAMES
6d0b66
     MRNames = 624,
6d0b66
     /// SLAPI_PLUGIN_SYNTAX_NAMES
6d0b66
diff --git a/src/slapi_r_plugin/src/pblock.rs b/src/slapi_r_plugin/src/pblock.rs
6d0b66
index 0f83914f3..718ff2ca7 100644
6d0b66
--- a/src/slapi_r_plugin/src/pblock.rs
6d0b66
+++ b/src/slapi_r_plugin/src/pblock.rs
6d0b66
@@ -279,4 +279,11 @@ impl PblockRef {
6d0b66
     pub fn get_op_result(&mut self) -> i32 {
6d0b66
         self.get_value_i32(PblockType::OpResult).unwrap_or(-1)
6d0b66
     }
6d0b66
+
6d0b66
+    pub fn get_is_replicated_operation(&mut self) -> bool {
6d0b66
+        let i = self.get_value_i32(PblockType::IsReplicationOperation).unwrap_or(0);
6d0b66
+        // Because rust returns the result of the last evaluation, we can
6d0b66
+        // just return if not equal 0.
6d0b66
+        i != 0
6d0b66
+    }
6d0b66
 }
6d0b66
-- 
6d0b66
2.26.3
6d0b66