From feab869a99b0679688fefc79bf12afe8ccdab043 Mon Sep 17 00:00:00 2001 From: Thierry Bordaz Date: Fri, 20 Dec 2024 10:49:08 +0100 Subject: [PATCH] Issue 6417 - (2nd) If an entry RDN is identical to the suffix, then Entryrdn gets broken during a reindex Bug description: The primary fix has a flaw as it assumes that the suffix ID is '1'. If the RUV entry is the first entry of the database the server loops indefinitely Fix description: Read the suffix ID from the entryrdn index fixes: #6417 Reviewed by: Pierre Rogier (reviewed the first fix) --- ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c b/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c index b47d0f611..c749672b9 100644 --- a/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c +++ b/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c @@ -992,6 +992,7 @@ entryrdn_lookup_dn(backend *be, ID workid = id; /* starting from the given id */ rdn_elem *elem = NULL; int maybesuffix = 0; + ID suffix_id; slapi_log_err(SLAPI_LOG_TRACE, "entryrdn_lookup_dn", "--> entryrdn_lookup_dn\n"); @@ -1032,6 +1033,20 @@ entryrdn_lookup_dn(backend *be, dblayer_value_free(be, &data); dblayer_value_init(be, &data); + /* Just in case the suffix ID is not '1' retrieve it from the database */ + keybuf = slapi_ch_strdup(slapi_sdn_get_ndn(be->be_suffix)); + dblayer_value_set(be, &key, keybuf, strlen(keybuf) + 1); + rc = dblayer_cursor_op(&ctx.cursor, DBI_OP_MOVE_TO_KEY, &key, &data); + if (rc) { + slapi_log_err(SLAPI_LOG_WARNING, "entryrdn_lookup_dn", + "Fails to retrieve the ID of suffix %s - Assume it is '1'\n", slapi_sdn_get_ndn(be->be_suffix)); + suffix_id = 1; + } else { + elem = (rdn_elem *)data.data; + suffix_id = id_stored_to_internal(elem->rdn_elem_id); + dblayer_value_free(be, &data); + } + do { /* Setting up a key for the node to get its parent */ keybuf = slapi_ch_smprintf("%c%u", RDN_INDEX_PARENT, workid); @@ -1077,7 +1092,7 @@ entryrdn_lookup_dn(backend *be, _ENTRYRDN_DEBUG_GOTO_BAIL(); goto bail; } - if (workid == 1) { + if (workid == suffix_id) { /* The loop (workid) iterates from the starting 'id' * up to the suffix ID (i.e. '1'). * A corner case (#6417) is if an entry, on the path