Skip to content

Commit

Permalink
Ticket #47523 - Set up replcation/agreement before initializing the s…
Browse files Browse the repository at this point in the history
…ub suffix, the sub suffix is not found by ldapsearch

Bug description: If a replication is configured against a backend
before initializing the backend with a suffix entry, an RUV entry
is inserted first with the entryid 1. The RUV entry's entryrdn is
added to the entryrdn index with a suffix entry which is a parent
entry of the RUV entry having a temporary entryid 0, which was to
be replaced with the real entryid when the real suffix entry is
added.  But the replacement code was not executed.

Fix description: When a real suffix is added to the entryrdn index,
it returns DB_KEYEXIST, which used to be ignored by resetting 0
(== SUCCESS).  This patch returns DB_KEYEXIST to the caller and let
_entryrdn_insert_key use the info to replace the temporary entryid
with the real one.  The error code is ignored by the other callers.

https://fedorahosted.org/389/ticket/47523

Reviewed by nkinder (Thanks!).
(cherry picked from commit e6eab21)
  • Loading branch information
nhosoi committed Sep 26, 2013
1 parent f7156e0 commit 6b35dc7
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
Expand Up @@ -748,7 +748,7 @@ entryrdn_rename_subtree(backend *be,
renamedata.data = (void *)newelem;
renamedata.flags = DB_DBT_USERMEM;
rc = _entryrdn_put_data(cursor, &key, &renamedata, RDN_INDEX_SELF, db_txn);
if (rc) {
if (rc && (DB_KEYEXIST != rc)) { /* failed && ignore already exists */
slapi_log_error(ENTRYRDN_LOGLEVEL(rc), ENTRYRDN_TAG,
"entryrdn_rename_subtree: Adding %s failed; "
"%s(%d)\n", keybuf, dblayer_strerror(rc), rc);
Expand All @@ -769,7 +769,7 @@ entryrdn_rename_subtree(backend *be,
renamedata.flags = DB_DBT_USERMEM;
rc = _entryrdn_put_data(cursor, &key,
&renamedata, RDN_INDEX_CHILD, db_txn);
if (rc) {
if (rc && (DB_KEYEXIST != rc)) { /* failed && ignore already exists */
goto bail;
}
}
Expand Down Expand Up @@ -814,7 +814,7 @@ entryrdn_rename_subtree(backend *be,
renamedata.data = (void *)newsupelem;
}
rc = _entryrdn_put_data(cursor, &key, &renamedata, RDN_INDEX_PARENT, db_txn);
if (rc) {
if (rc && (DB_KEYEXIST != rc)) { /* failed && ignore already exists */
slapi_log_error(ENTRYRDN_LOGLEVEL(rc), ENTRYRDN_TAG,
"entryrdn_rename_subtree: Adding "
"%s failed; %s(%d)\n",
Expand Down Expand Up @@ -849,7 +849,7 @@ entryrdn_rename_subtree(backend *be,
renamedata.data = (void *)newelem;
renamedata.flags = DB_DBT_USERMEM;
rc = _entryrdn_put_data(cursor, &key, &renamedata, RDN_INDEX_SELF, db_txn);
if (rc) {
if (rc && (DB_KEYEXIST != rc)) { /* failed && ignore already exists */
slapi_log_error(ENTRYRDN_LOGLEVEL(rc), ENTRYRDN_TAG,
"entryrdn_rename_subtree: Adding %s failed; "
"%s(%d)\n", keybuf, dblayer_strerror(rc), rc);
Expand Down Expand Up @@ -902,7 +902,7 @@ entryrdn_rename_subtree(backend *be,
renamedata.flags = DB_DBT_USERMEM;
}
rc = _entryrdn_put_data(cursor, &key, &renamedata, RDN_INDEX_CHILD, db_txn);
if (rc) {
if (rc && (DB_KEYEXIST != rc)) { /* failed && ignore already exists */
goto bail;
}
}
Expand Down Expand Up @@ -1955,12 +1955,11 @@ _entryrdn_put_data(DBC *cursor, DBT *key, DBT *data, char type, DB_TXN *db_txn)
rc = cursor->c_put(cursor, key, data, DB_NODUPDATA);
if (rc) {
if (DB_KEYEXIST == rc) {
/* this is okay */
/* this is okay, but need to return DB_KEYEXIST to caller */
slapi_log_error(SLAPI_LOG_BACKLDBM, ENTRYRDN_TAG,
"_entryrdn_put_data: The same key (%s) and the "
"data exists in index\n",
(char *)key->data);
rc = 0;
break;
} else {
char *keyword = NULL;
Expand Down Expand Up @@ -2109,7 +2108,7 @@ _entryrdn_insert_key_elems(backend *be,
/* adding RDN to the child key */
rc = _entryrdn_put_data(cursor, key, &adddata, RDN_INDEX_CHILD, db_txn);
keybuf = key->data;
if (rc) { /* failed */
if (rc && (DB_KEYEXIST != rc)) { /* failed && ignore already exists */
goto bail;
}

Expand All @@ -2125,7 +2124,7 @@ _entryrdn_insert_key_elems(backend *be,
key->flags = DB_DBT_USERMEM;

rc = _entryrdn_put_data(cursor, key, &adddata, RDN_INDEX_SELF, db_txn);
if (rc) { /* failed */
if (rc && (DB_KEYEXIST != rc)) { /* failed && ignore already exists */
goto bail;
}

Expand All @@ -2145,6 +2144,9 @@ _entryrdn_insert_key_elems(backend *be,
adddata.flags = DB_DBT_USERMEM;
/* adding RDN to the self key */
rc = _entryrdn_put_data(cursor, key, &adddata, RDN_INDEX_PARENT, db_txn);
if (DB_KEYEXIST == rc) { /* failed && ignore already exists */
rc = 0;
}
/* Succeeded or failed, it's done. */
bail:
slapi_ch_free_string(&keybuf);
Expand Down Expand Up @@ -2268,7 +2270,7 @@ _entryrdn_replace_suffix_id(DBC *cursor, DBT *key, DBT *adddata,
/* Add it back */
rc = _entryrdn_put_data(cursor, &realkey, &moddata,
RDN_INDEX_CHILD, db_txn);
if (rc) {
if (rc && (DB_KEYEXIST != rc)) { /* failed && ignore already exists */
goto bail0;
}
if (curr_childnum + 1 == childnum) {
Expand Down Expand Up @@ -2531,7 +2533,7 @@ _entryrdn_insert_key(backend *be,
slapi_ch_free_string(&dn);
goto bail;
}
elem = _entryrdn_new_rdn_elem(be, 0 /*fake id*/, tmpsrdn, &len);
elem = _entryrdn_new_rdn_elem(be, TMPID, tmpsrdn, &len);
if (NULL == elem) {
char *dn = NULL;
slapi_rdn_get_dn(tmpsrdn, &dn);
Expand All @@ -2551,12 +2553,13 @@ _entryrdn_insert_key(backend *be,
rc = _entryrdn_get_elem(cursor, &key, &data, nrdn, &elem);
if (rc) {
const char *myrdn = slapi_rdn_get_nrdn(srdn);
const char *ep = NULL;
const char **ep = NULL;
int isexception = 0;
/* Check the RDN is in the exception list */
for (ep = *rdn_exceptions; ep && *ep; ep++) {
if (!strcmp(ep, myrdn)) {
for (ep = rdn_exceptions; ep && *ep; ep++) {
if (!strcmp(*ep, myrdn)) {
isexception = 1;
break;
}
}

Expand Down Expand Up @@ -2636,7 +2639,7 @@ _entryrdn_insert_key(backend *be,
goto bail;
}
}
elem = _entryrdn_new_rdn_elem(be, 0 /*fake id*/, tmpsrdn, &len);
elem = _entryrdn_new_rdn_elem(be, TMPID, tmpsrdn, &len);
if (NULL == elem) {
char *dn = NULL;
slapi_rdn_get_dn(tmpsrdn, &dn);
Expand Down Expand Up @@ -2891,7 +2894,7 @@ _entryrdn_delete_key(backend *be,
slapi_ch_free_string(&dn);
goto bail;
}
elem = _entryrdn_new_rdn_elem(be, 0 /*fake id*/, tmpsrdn, &len);
elem = _entryrdn_new_rdn_elem(be, TMPID, tmpsrdn, &len);
if (NULL == elem) {
char *dn = NULL;
slapi_rdn_get_dn(tmpsrdn, &dn);
Expand Down Expand Up @@ -3134,7 +3137,7 @@ _entryrdn_index_read(backend *be,
slapi_ch_free_string(&dn);
goto bail;
}
*elem = _entryrdn_new_rdn_elem(be, 0 /*fake id*/, tmpsrdn, &len);
*elem = _entryrdn_new_rdn_elem(be, TMPID, tmpsrdn, &len);
if (NULL == *elem) {
char *dn = NULL;
slapi_rdn_get_dn(tmpsrdn, &dn);
Expand Down Expand Up @@ -3212,7 +3215,7 @@ _entryrdn_index_read(backend *be,
goto bail;
}
}
tmpelem = _entryrdn_new_rdn_elem(be, 0 /*fake id*/, tmpsrdn, &len);
tmpelem = _entryrdn_new_rdn_elem(be, TMPID, tmpsrdn, &len);
if (NULL == tmpelem) {
char *dn = NULL;
slapi_rdn_get_dn(tmpsrdn, &dn);
Expand Down

0 comments on commit 6b35dc7

Please sign in to comment.