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

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