Blame SOURCES/0002-Issue-4877-RFE-EntryUUID-to-validate-UUIDs-on-fixup-.patch

a77461
From 6c8906559cd049b14b08e4d3158338f6611f04e4 Mon Sep 17 00:00:00 2001
a77461
From: Firstyear <william@blackhats.net.au>
a77461
Date: Fri, 20 Aug 2021 09:18:50 +1000
a77461
Subject: [PATCH] Issue 4877 - RFE - EntryUUID to validate UUIDs on fixup
a77461
 (#4878)
a77461
a77461
Bug Description: Due to changing the syntax of EntryUUID's
a77461
to string, we may have invalid EntryUUID's imported into
a77461
the database.
a77461
a77461
Fix Description: To resolve this during a fixup we validate
a77461
that Uuid's have a valid syntax. If they do not, we regenerate
a77461
them.
a77461
a77461
fixes: https://github.com/389ds/389-ds-base/issues/4877
a77461
a77461
Author: William Brown <william@blackhats.net.au>
a77461
a77461
Review by: @mreynolds389
a77461
---
a77461
 src/plugins/entryuuid/src/lib.rs | 28 ++++++++++++++++++++--------
a77461
 1 file changed, 20 insertions(+), 8 deletions(-)
a77461
a77461
diff --git a/src/plugins/entryuuid/src/lib.rs b/src/plugins/entryuuid/src/lib.rs
a77461
index 29a9f1258..ad3faef4b 100644
a77461
--- a/src/plugins/entryuuid/src/lib.rs
a77461
+++ b/src/plugins/entryuuid/src/lib.rs
a77461
@@ -144,11 +144,17 @@ impl SlapiPlugin3 for EntryUuid {
a77461
         // Error if the first filter is empty?
a77461
 
a77461
         // Now, to make things faster, we wrap the filter in a exclude term.
a77461
+
a77461
+        // 2021 - #4877 because we allow entryuuid to be strings, on import these may
a77461
+        // be invalid. As a result, we DO need to allow the fixup to check the entryuuid
a77461
+        // value is correct, so we can not exclude these during the search.
a77461
+        /*
a77461
         let raw_filter = if !raw_filter.starts_with('(') && !raw_filter.ends_with('(') {
a77461
             format!("(&({})(!(entryuuid=*)))", raw_filter)
a77461
         } else {
a77461
             format!("(&{}(!(entryuuid=*)))", raw_filter)
a77461
         };
a77461
+        */
a77461
 
a77461
         Ok(FixupData { basedn, raw_filter })
a77461
     }
a77461
@@ -213,14 +219,20 @@ pub fn entryuuid_fixup_mapfn(e: &EntryRef, _data: &()) -> Result<(), PluginError
a77461
     /* Supply a modification to the entry. */
a77461
     let sdn = e.get_sdnref();
a77461
 
a77461
-    /* Sanity check that entryuuid doesn't already exist */
a77461
-    if e.contains_attr("entryUUID") {
a77461
-        log_error!(
a77461
-            ErrorLevel::Plugin,
a77461
-            "skipping fixup for -> {}",
a77461
-            sdn.to_dn_string()
a77461
-        );
a77461
-        return Ok(());
a77461
+    /* Check that entryuuid doesn't already exist, and is valid */
a77461
+    if let Some(valueset) = e.get_attr("entryUUID") {
a77461
+        if valueset.iter().all(|v| {
a77461
+            let u: Result<Uuid, _> = (&v).try_into();
a77461
+            u.is_ok()
a77461
+        }) {
a77461
+            // All values were valid uuid, move on!
a77461
+            log_error!(
a77461
+                ErrorLevel::Plugin,
a77461
+                "skipping fixup for -> {}",
a77461
+                sdn.to_dn_string()
a77461
+            );
a77461
+            return Ok(());
a77461
+        }
a77461
     }
a77461
 
a77461
     // Setup the modifications
a77461
-- 
a77461
2.31.1
a77461