summaryrefslogtreecommitdiffstats
path: root/ldap
diff options
context:
space:
mode:
authorNoriko Hosoi <nhosoi@redhat.com>2010-08-31 10:09:39 -0700
committerNoriko Hosoi <nhosoi@redhat.com>2010-08-31 10:35:35 -0700
commit7cd57ad2fc78c90a2405128df1e5414161e1ff9d (patch)
tree30b8bc0c338615bfea3dc19bd298e143d39ede79 /ldap
parenta2bcd8130c0b4b2db68045d3ecd433f7a0744b33 (diff)
downloadds-7cd57ad2fc78c90a2405128df1e5414161e1ff9d.tar.gz
ds-7cd57ad2fc78c90a2405128df1e5414161e1ff9d.tar.xz
ds-7cd57ad2fc78c90a2405128df1e5414161e1ff9d.zip
Bug 628300 - DN is not normalized in dn/entry cache when an entry is added, entrydn is not present in search results
https://bugzilla.redhat.com/show_bug.cgi?id=628300 Resolves: 628300 Description: Code for supporting entrydn (added for Bug 578296) contained a bug. If an entry was found in the entry cache, id2entry_ext returned it without adding the entrydn attribute value. This patch fixes the problem. In addition, if the parent DN in the to-be-added entry is not identical to the real parent DN (e.g., dc=eXAmple vs. dc=example), replace the string with the real parent DN. This check & replace is done only when the parent entry is in the entry cache not to sacrifice the performance.
Diffstat (limited to 'ldap')
-rw-r--r--ldap/servers/slapd/back-ldbm/id2entry.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/ldap/servers/slapd/back-ldbm/id2entry.c b/ldap/servers/slapd/back-ldbm/id2entry.c
index 235fd68b..977e0b44 100644
--- a/ldap/servers/slapd/back-ldbm/id2entry.c
+++ b/ldap/servers/slapd/back-ldbm/id2entry.c
@@ -131,10 +131,35 @@ id2entry_add_ext( backend *be, struct backentry *e, back_txn *txn, int encrypt
if (0 == rc)
{
- /* DBDB the fact that we don't check the return code here is
- * indicitive that there may be a latent race condition lurking
- * ---what happens if the entry is already in the cache by this point?
- */
+ if (entryrdn_get_switch()) {
+ struct backentry *parententry = NULL;
+ ID parentid = slapi_entry_attr_get_ulong(e->ep_entry, "parentid");
+ const char *myrdn = slapi_entry_get_rdn_const(e->ep_entry);
+ const char *parentdn = NULL;
+ char *myparentdn = NULL;
+ /* If the parent is in the cache, check the parent's DN and
+ * adjust to it if they don't match. (bz628300) */
+ if (parentid && myrdn) {
+ parententry = cache_find_id(&inst->inst_cache, parentid);
+ if (parententry) {
+ parentdn = slapi_entry_get_dn_const(parententry->ep_entry);
+ if (parentdn) {
+ myparentdn =
+ slapi_dn_parent(slapi_entry_get_dn_const(e->ep_entry));
+ if (myparentdn && PL_strcmp(parentdn, myparentdn)) {
+ Slapi_DN *sdn = slapi_entry_get_sdn(e->ep_entry);
+ char *newdn = NULL;
+ slapi_sdn_done(sdn);
+ newdn = slapi_ch_smprintf("%s,%s", myrdn, parentdn);
+ slapi_sdn_init_dn_passin(sdn, newdn);
+ slapi_sdn_get_ndn(sdn); /* to set ndn */
+ }
+ slapi_ch_free_string(&myparentdn);
+ }
+ CACHE_RETURN(&inst->inst_cache, &parententry);
+ }
+ }
+ }
/*
* For ldbm_back_add and ldbm_back_modify, this entry had been already
* reserved as a tentative entry. So, it should be safe.
@@ -158,7 +183,7 @@ done:
int
id2entry_add( backend *be, struct backentry *e, back_txn *txn )
{
- return id2entry_add_ext(be,e,txn,1);
+ return id2entry_add_ext(be,e,txn,1);
}
/*
@@ -229,8 +254,8 @@ id2entry_ext( backend *be, ID id, back_txn *txn, int *err, int flags )
if ( (e = cache_find_id( &inst->inst_cache, id )) != NULL ) {
slapi_log_error(SLAPI_LOG_TRACE, ID2ENTRY,
"<= id2entry %p, dn \"%s\" (cache)\n",
- e, backentry_get_ndn(e));
- return( e );
+ e, backentry_get_ndn(e));
+ goto bail;
}
if ( (*err = dblayer_get_id2entry( be, &db )) != 0 ) {
@@ -344,7 +369,7 @@ id2entry_ext( backend *be, ID id, back_txn *txn, int *err, int flags )
e->ep_id = id;
slapi_log_error(SLAPI_LOG_TRACE, ID2ENTRY,
"id2entry id: %d, dn \"%s\" -- adding it to cache\n",
- id, backentry_get_ndn(e));
+ id, backentry_get_ndn(e));
/* Decrypt any encrypted attributes in this entry,
* before adding it to the cache */