andykimpe / rpms / 389-ds-base

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

Blame SOURCES/0067-Ticket-49551-v3-correct-handling-of-numsubordinates-.patch

058656
From 233b64f26df76aa50f4b37aaf6b3804d208fdc1b Mon Sep 17 00:00:00 2001
058656
From: Ludwig Krispenz <lkrispen@redhat.com>
058656
Date: Mon, 12 Feb 2018 09:24:25 +0100
058656
Subject: [PATCH] Ticket 49551 - v3 - correct handling of numsubordinates for
058656
 cenotaphs and tombstone delete
058656
058656
        Bug: The ticket exposed several problems with tombstone handling.
058656
                - tombstone entries of conflicts were not purged in tombstone purging
058656
                - cenotaphs are tombstone, but the subordinate count was not managed properly
058656
                - direct delete of tombstones failed with err=1
058656
                - delete of entry with only conflict children failed correctly, but gave no hint why
058656
058656
        Fix: update the correct numsobordinates attribut for cenotaphs
058656
             set proper flag in directly deleting a tombstone
058656
             change search filter for tombstone purging to include ldapsubentries
058656
             check for conflict children if a delete is rejected and add a message to the response
058656
058656
        Reviewed by; Thierry, William - thanks
058656
---
058656
 ldap/servers/plugins/replication/repl5_replica.c | 14 +++++++++--
058656
 ldap/servers/plugins/replication/urp.c           |  8 +++---
058656
 ldap/servers/slapd/back-ldbm/ldbm_add.c          |  8 +++---
058656
 ldap/servers/slapd/back-ldbm/ldbm_delete.c       | 14 ++++++++---
058656
 ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c     |  3 ++-
058656
 ldap/servers/slapd/back-ldbm/parents.c           | 12 ++++++---
058656
 ldap/servers/slapd/entry.c                       | 31 ++++++++++++++++++++++++
058656
 ldap/servers/slapd/slapi-plugin.h                |  2 ++
058656
 ldap/servers/slapd/slapi-private.h               |  1 +
058656
 ldap/servers/slapd/task.c                        |  4 +--
058656
 10 files changed, 78 insertions(+), 19 deletions(-)
058656
058656
diff --git a/ldap/servers/plugins/replication/repl5_replica.c b/ldap/servers/plugins/replication/repl5_replica.c
058656
index bdb8a5167..628fb9ceb 100644
058656
--- a/ldap/servers/plugins/replication/repl5_replica.c
058656
+++ b/ldap/servers/plugins/replication/repl5_replica.c
058656
@@ -3017,6 +3017,16 @@ process_reap_entry(Slapi_Entry *entry, void *cb_data)
058656
        search in the future, see _replica_reap_tombstones below and add more to the
058656
        attrs array */
058656
     deletion_csn = entry_get_deletion_csn(entry);
058656
+    if (deletion_csn == NULL) {
058656
+        /* this might be a tombstone which was directly added, eg a cenotaph
058656
+         * check if a tombstonecsn exist and use it
058656
+         */
058656
+        char *tombstonecsn = slapi_entry_attr_get_charptr(entry, SLAPI_ATTR_TOMBSTONE_CSN);
058656
+        if (tombstonecsn) {
058656
+            deletion_csn = csn_new_by_string(tombstonecsn);
058656
+            slapi_ch_free_string(&tombstonecsn);
058656
+        }
058656
+    }
058656
 
058656
     if ((NULL == deletion_csn || csn_compare(deletion_csn, purge_csn) < 0) &&
058656
         (!is_ruv_tombstone_entry(entry))) {
058656
@@ -3116,11 +3126,11 @@ _replica_reap_tombstones(void *arg)
058656
              */
058656
             csn_as_string(purge_csn, PR_FALSE, deletion_csn_str);
058656
             PR_snprintf(tombstone_filter, 128,
058656
-                        "(&(%s<=%s)(objectclass=nsTombstone))", SLAPI_ATTR_TOMBSTONE_CSN,
058656
+                        "(&(%s<=%s)(objectclass=nsTombstone)(|(objectclass=*)(objectclass=ldapsubentry)))", SLAPI_ATTR_TOMBSTONE_CSN,
058656
                         csn_as_string(purge_csn, PR_FALSE, deletion_csn_str));
058656
         } else {
058656
             /* Use the old inefficient filter */
058656
-            PR_snprintf(tombstone_filter, 128, "(objectclass=nsTombstone)");
058656
+            PR_snprintf(tombstone_filter, 128, "(&(objectclass=nsTombstone)(|(objectclass=*)(objectclass=ldapsubentry)))");
058656
         }
058656
 
058656
         /* we just need the objectclass - for the deletion csn
058656
diff --git a/ldap/servers/plugins/replication/urp.c b/ldap/servers/plugins/replication/urp.c
058656
index d4556d7fd..11c5da7cf 100644
058656
--- a/ldap/servers/plugins/replication/urp.c
058656
+++ b/ldap/servers/plugins/replication/urp.c
058656
@@ -911,7 +911,7 @@ urp_fixup_add_cenotaph (Slapi_PBlock *pb, char *sessionid, CSN *opcsn)
058656
                                     cenotaph,
058656
                                     NULL,
058656
                                     repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION),
058656
-                                    OP_FLAG_REPL_FIXUP|OP_FLAG_NOOP);
058656
+                                    OP_FLAG_REPL_FIXUP|OP_FLAG_NOOP|OP_FLAG_CENOTAPH_ENTRY);
058656
     slapi_add_internal_pb(add_pb);
058656
     slapi_pblock_get(add_pb, SLAPI_PLUGIN_INTOP_RESULT, &ret;;
058656
 
058656
@@ -1922,7 +1922,7 @@ done:
058656
     newpb = NULL;
058656
 
058656
     slapi_log_err(SLAPI_LOG_REPL, sessionid,
058656
-                  "urp_get_min_naming_conflict_entry - Found %d entries\n", i);
058656
+                  "urp_get_min_naming_conflict_entry - Found %d entries\n", min_csn?1:0);
058656
 
058656
     return min_naming_conflict_entry;
058656
 }
058656
@@ -2172,8 +2172,8 @@ mod_objectclass_attr(const char *uniqueid, const Slapi_DN *entrysdn, const Slapi
058656
     char csnstr[CSN_STRSIZE+1] = {0};
058656
 
058656
     slapi_mods_init(&smods, 3);
058656
-    slapi_mods_add(&smods, LDAP_MOD_ADD, "objectclass", strlen("ldapsubentry"),"ldapsubentry");
058656
-    slapi_mods_add(&smods, LDAP_MOD_REPLACE, "conflictcsn", CSN_STRSIZE, csn_as_string(opcsn, PR_FALSE, csnstr));
058656
+    slapi_mods_add_string(&smods, LDAP_MOD_ADD, "objectclass", "ldapsubentry");
058656
+    slapi_mods_add_string(&smods, LDAP_MOD_REPLACE, "conflictcsn", csn_as_string(opcsn, PR_FALSE, csnstr));
058656
     op_result = urp_fixup_modify_entry(uniqueid, entrysdn, opcsn, &smods, 0);
058656
     slapi_mods_done(&smods);
058656
     if (op_result == LDAP_TYPE_OR_VALUE_EXISTS) {
058656
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_add.c b/ldap/servers/slapd/back-ldbm/ldbm_add.c
058656
index c93d44a65..f0a3262ec 100644
058656
--- a/ldap/servers/slapd/back-ldbm/ldbm_add.c
058656
+++ b/ldap/servers/slapd/back-ldbm/ldbm_add.c
058656
@@ -81,6 +81,7 @@ ldbm_back_add(Slapi_PBlock *pb)
058656
     Slapi_Operation *operation;
058656
     int is_replicated_operation = 0;
058656
     int is_resurect_operation = 0;
058656
+    int is_cenotaph_operation = 0;
058656
     int is_tombstone_operation = 0;
058656
     int is_fixup_operation = 0;
058656
     int is_remove_from_cache = 0;
058656
@@ -116,6 +117,7 @@ ldbm_back_add(Slapi_PBlock *pb)
058656
     }
058656
 
058656
     is_resurect_operation = operation_is_flag_set(operation, OP_FLAG_RESURECT_ENTRY);
058656
+    is_cenotaph_operation = operation_is_flag_set(operation, OP_FLAG_CENOTAPH_ENTRY);
058656
     is_tombstone_operation = operation_is_flag_set(operation, OP_FLAG_TOMBSTONE_ENTRY);
058656
     is_fixup_operation = operation_is_flag_set(operation, OP_FLAG_REPL_FIXUP);
058656
     is_ruv = operation_is_flag_set(operation, OP_FLAG_REPL_RUV);
058656
@@ -846,9 +848,9 @@ ldbm_back_add(Slapi_PBlock *pb)
058656
                the in-memory state of the parent to reflect the new child (update
058656
                subordinate count specifically */
058656
             if (parententry) {
058656
-                retval = parent_update_on_childchange(&parent_modify_c,
058656
-                                                      is_resurect_operation ? PARENTUPDATE_RESURECT : PARENTUPDATE_ADD,
058656
-                                                      NULL);
058656
+                int op = is_resurect_operation ? PARENTUPDATE_RESURECT : PARENTUPDATE_ADD;
058656
+                if (is_cenotaph_operation ) op |= PARENTUPDATE_CREATE_TOMBSTONE;
058656
+                retval = parent_update_on_childchange(&parent_modify_c, op, NULL);
058656
                 slapi_log_err(SLAPI_LOG_BACKLDBM, "ldbm_back_add",
058656
                               "conn=%lu op=%d parent_update_on_childchange: old_entry=0x%p, new_entry=0x%p, rc=%d\n",
058656
                               conn_id, op_id, parent_modify_c.old_entry, parent_modify_c.new_entry, retval);
058656
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_delete.c b/ldap/servers/slapd/back-ldbm/ldbm_delete.c
058656
index be0db1bd0..bc0a3654e 100644
058656
--- a/ldap/servers/slapd/back-ldbm/ldbm_delete.c
058656
+++ b/ldap/servers/slapd/back-ldbm/ldbm_delete.c
058656
@@ -291,9 +291,16 @@ replace_entry:
058656
             retval = slapi_entry_has_children(e->ep_entry);
058656
             if (retval && !is_replicated_operation) {
058656
                 ldap_result_code= LDAP_NOT_ALLOWED_ON_NONLEAF;
058656
-                slapi_log_err(SLAPI_LOG_BACKLDBM, "ldbm_back_delete", 
058656
-                              "conn=%lu op=%d Deleting entry %s has %d children.\n", 
058656
-                               conn_id, op_id, slapi_entry_get_dn(e->ep_entry), retval);
058656
+                if (slapi_entry_has_conflict_children(e->ep_entry, (void *)li->li_identity) > 0) {
058656
+                    ldap_result_message = "Entry has replication conflicts as children";
058656
+                    slapi_log_err(SLAPI_LOG_ERR, "ldbm_back_delete",
058656
+                                  "conn=%lu op=%d Deleting entry %s has replication conflicts as children.\n",
058656
+                                   conn_id, op_id, slapi_entry_get_dn(e->ep_entry));
058656
+                } else {
058656
+                    slapi_log_err(SLAPI_LOG_BACKLDBM, "ldbm_back_delete",
058656
+                                  "conn=%lu op=%d Deleting entry %s has %d children.\n",
058656
+                                   conn_id, op_id, slapi_entry_get_dn(e->ep_entry), retval);
058656
+                }
058656
                 retval = -1;
058656
                 goto error_return;
058656
             }
058656
@@ -431,6 +438,7 @@ replace_entry:
058656
                     slapi_log_err(SLAPI_LOG_WARNING, "ldbm_back_delete",
058656
                             "Attempt to Tombstone again a tombstone entry %s\n", dn);
058656
                     delete_tombstone_entry = 1;
058656
+                    operation_set_flag(operation, OP_FLAG_TOMBSTONE_ENTRY);
058656
                 }
058656
             }
058656
 
058656
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c b/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
058656
index b41a2d241..5797dd779 100644
058656
--- a/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
058656
+++ b/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
058656
@@ -2824,7 +2824,8 @@ _entryrdn_delete_key(backend *be,
058656
                     break;
058656
                 }
058656
                 childelem = (rdn_elem *)dataret.data;
058656
-                if (!slapi_is_special_rdn(childelem->rdn_elem_nrdn_rdn, RDN_IS_TOMBSTONE)) {
058656
+                if (!slapi_is_special_rdn(childelem->rdn_elem_nrdn_rdn, RDN_IS_TOMBSTONE) &&
058656
+                    !strcasestr(childelem->rdn_elem_nrdn_rdn, "cenotaphid")) {
058656
                     /* there's at least one live child */
058656
                     slapi_log_err(SLAPI_LOG_ERR, "_entryrdn_delete_key",
058656
                                   "Failed to remove %s; has a child %s\n", nrdn,
058656
diff --git a/ldap/servers/slapd/back-ldbm/parents.c b/ldap/servers/slapd/back-ldbm/parents.c
058656
index 79e66451e..1afc795c0 100644
058656
--- a/ldap/servers/slapd/back-ldbm/parents.c
058656
+++ b/ldap/servers/slapd/back-ldbm/parents.c
058656
@@ -89,7 +89,11 @@ parent_update_on_childchange(modify_context *mc, int op, size_t *new_sub_count)
058656
         }
058656
     }
058656
 
058656
-    if (PARENTUPDATE_DELETE_TOMBSTONE != repl_op) {
058656
+    if ((PARENTUPDATE_ADD == op) && (PARENTUPDATE_CREATE_TOMBSTONE == repl_op)) {
058656
+        /* we are directly adding a tombstone entry, only need to
058656
+         * update the tombstone subordinates
058656
+         */
058656
+    } else if (PARENTUPDATE_DELETE_TOMBSTONE != repl_op) {
058656
         /* are we adding ? */
058656
         if (((PARENTUPDATE_ADD == op) || (PARENTUPDATE_RESURECT == op)) && !already_present) {
058656
             /* If so, and the parent entry does not already have a subcount
058656
@@ -136,10 +140,10 @@ parent_update_on_childchange(modify_context *mc, int op, size_t *new_sub_count)
058656
         }
058656
     }
058656
 
058656
-    /* tombstoneNumSubordinates is needed only when this is repl op
058656
-     * and a child is being deleted */
058656
+    /* tombstoneNumSubordinates has to be updated if a tombstone child has been
058656
+     * deleted or a tombstone has been directly added (cenotaph) */
058656
     current_sub_count = LDAP_MAXINT;
058656
-    if ((repl_op && (PARENTUPDATE_DEL == op)) || (PARENTUPDATE_RESURECT == op)) {
058656
+    if (repl_op) {
058656
         ret = slapi_entry_attr_find(mc->old_entry->ep_entry,
058656
                                     tombstone_numsubordinates, &read_attr);
058656
         if (0 == ret) {
058656
diff --git a/ldap/servers/slapd/entry.c b/ldap/servers/slapd/entry.c
058656
index 32828b4e2..b85e9f5b0 100644
058656
--- a/ldap/servers/slapd/entry.c
058656
+++ b/ldap/servers/slapd/entry.c
058656
@@ -3238,6 +3238,37 @@ slapi_entry_has_children(const Slapi_Entry *entry)
058656
     return slapi_entry_has_children_ext(entry, 0);
058656
 }
058656
 
058656
+int
058656
+slapi_entry_has_conflict_children(const Slapi_Entry *entry, void *plg_id)
058656
+{
058656
+    Slapi_PBlock *search_pb = NULL;
058656
+    Slapi_Entry **entries;
058656
+    int rc = 0;
058656
+
058656
+    search_pb = slapi_pblock_new();
058656
+    slapi_search_internal_set_pb(search_pb, slapi_entry_get_dn_const(entry),
058656
+                                 LDAP_SCOPE_ONELEVEL,
058656
+                                 "(&(objectclass=ldapsubentry)(nsds5ReplConflict=namingConflict*))",
058656
+                                 NULL, 0, NULL, NULL, plg_id, 0);
058656
+    slapi_search_internal_pb(search_pb);
058656
+    slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
058656
+    if (rc) {
058656
+        rc = -1;
058656
+    } else {
058656
+        slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
058656
+        if (entries && entries[0]) {
058656
+            /* we found at least one conflict entry */
058656
+            rc = 1;
058656
+        } else {
058656
+            rc = 0;
058656
+        }
058656
+        slapi_free_search_results_internal(search_pb);
058656
+    }
058656
+    slapi_pblock_destroy(search_pb);
058656
+
058656
+    return rc;
058656
+}
058656
+
058656
 /*
058656
  * Renames an entry to simulate a MODRDN operation
058656
  */
058656
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
058656
index 95cdcc0da..6978e258f 100644
058656
--- a/ldap/servers/slapd/slapi-plugin.h
058656
+++ b/ldap/servers/slapd/slapi-plugin.h
058656
@@ -2000,6 +2000,8 @@ int slapi_entry_has_children(const Slapi_Entry *e);
058656
  */
058656
 int slapi_entry_has_children_ext(const Slapi_Entry *e, int include_tombstone);
058656
 
058656
+int slapi_entry_has_conflict_children(const Slapi_Entry *e, void *plg_id);
058656
+
058656
 /**
058656
  * This function determines if an entry is the root DSE.
058656
  *
058656
diff --git a/ldap/servers/slapd/slapi-private.h b/ldap/servers/slapd/slapi-private.h
058656
index 548d5cabb..b08c0d7ce 100644
058656
--- a/ldap/servers/slapd/slapi-private.h
058656
+++ b/ldap/servers/slapd/slapi-private.h
058656
@@ -403,6 +403,7 @@ char *slapi_filter_to_string_internal(const struct slapi_filter *f, char *buf, s
058656
 #define OP_FLAG_NEVER_CHAIN SLAPI_OP_FLAG_NEVER_CHAIN         /* 0x000800 */
058656
 #define OP_FLAG_TOMBSTONE_ENTRY SLAPI_OP_FLAG_TOMBSTONE_ENTRY /* 0x001000 */
058656
 #define OP_FLAG_RESURECT_ENTRY 0x002000
058656
+#define OP_FLAG_CENOTAPH_ENTRY 0x004000
058656
 #define OP_FLAG_ACTION_NOLOG 0x008000            /* Do not log the entry in \
058656
                                                   * audit log or change log  \
058656
                                                   */
058656
diff --git a/ldap/servers/slapd/task.c b/ldap/servers/slapd/task.c
058656
index 4bd8895ff..3f9d5d995 100644
058656
--- a/ldap/servers/slapd/task.c
058656
+++ b/ldap/servers/slapd/task.c
058656
@@ -2352,10 +2352,10 @@ task_fixup_tombstone_thread(void *arg)
058656
 
058656
     if (task_data->stripcsn) {
058656
         /* find tombstones with nsTombstoneCSN */
058656
-        filter = "(&(nstombstonecsn=*)(objectclass=nsTombstone))";
058656
+        filter = "(&(nstombstonecsn=*)(objectclass=nsTombstone)(|(objectclass=*)(objectclass=ldapsubentry)))";
058656
     } else {
058656
         /* find tombstones missing nsTombstoneCSN */
058656
-        filter = "(&(!(nstombstonecsn=*))(objectclass=nsTombstone))";
058656
+        filter = "(&(!(nstombstonecsn=*))(objectclass=nsTombstone)(|(objectclass=*)(objectclass=ldapsubentry)))";
058656
     }
058656
 
058656
     /* Okay check the specified backends only */
058656
-- 
058656
2.13.6
058656