From 7482698b041e4882b4d0ca66d06dfd833657b6f3 Mon Sep 17 00:00:00 2001 From: Noriko Hosoi Date: Thu, 24 Jun 2010 16:34:01 -0700 Subject: 578296 - Attribute type entrydn needs to be added when subtree rename switch is on https://bugzilla.redhat.com/show_bug.cgi?id=578296 Change Description: 1) ldbm_back_next_search_entry_ext (ldbm_search.c) When getting an entry from ID using id2entry_ext, pass a flag ID2ENTRY_ADD_ENTRYDN to add entrydn to the entry. 2) id2entry_ext (id2entry.c) Added id2entry_ext to handle the flag ID2ENTRY_ADD_ENTRYDN. If ID2ENTRY_ADD_ENTRYDN is set in the flags variable and entryrdn switch is enabled, entrydn is added to the entry. 3) index_read_ext (index.c) If entryrdn switch is on and the attribute type is entrydn and the search type is equality, then call entryrdn_index_read to get the ID directly. --- ldap/servers/slapd/back-ldbm/back-ldbm.h | 3 +++ ldap/servers/slapd/back-ldbm/id2entry.c | 31 +++++++++++++++++++++++++- ldap/servers/slapd/back-ldbm/index.c | 31 +++++++++++++++++++++++++- ldap/servers/slapd/back-ldbm/ldbm_search.c | 3 ++- ldap/servers/slapd/back-ldbm/proto-back-ldbm.h | 2 ++ 5 files changed, 67 insertions(+), 3 deletions(-) diff --git a/ldap/servers/slapd/back-ldbm/back-ldbm.h b/ldap/servers/slapd/back-ldbm/back-ldbm.h index 9efcd160..8a944c81 100644 --- a/ldap/servers/slapd/back-ldbm/back-ldbm.h +++ b/ldap/servers/slapd/back-ldbm/back-ldbm.h @@ -826,4 +826,7 @@ typedef struct _back_search_result_set /* whether we call fat lock or not [608146] */ #define SERIALLOCK(li) (li->li_fat_lock) + +/* id2entry_ext flags */ +#define ID2ENTRY_ADD_ENTRYDN 0x1 #endif /* _back_ldbm_h_ */ diff --git a/ldap/servers/slapd/back-ldbm/id2entry.c b/ldap/servers/slapd/back-ldbm/id2entry.c index 21f21fc6..31d3b724 100644 --- a/ldap/servers/slapd/back-ldbm/id2entry.c +++ b/ldap/servers/slapd/back-ldbm/id2entry.c @@ -208,7 +208,7 @@ id2entry_delete( backend *be, struct backentry *e, back_txn *txn ) } struct backentry * -id2entry( backend *be, ID id, back_txn *txn, int *err ) +id2entry_ext( backend *be, ID id, back_txn *txn, int *err, int flags ) { ldbm_instance *inst = (ldbm_instance *) be->be_instance_info; DB *db = NULL; @@ -376,6 +376,29 @@ id2entry( backend *be, ID id, back_txn *txn, int *err ) } bail: + /* + * If return entry exists AND adding entrydn is requested AND + * entryrdn switch is on, add the entrydn value. + */ + if (e && e->ep_entry && (flags & ID2ENTRY_ADD_ENTRYDN) && + entryrdn_get_switch()) { + Slapi_Attr *eattr = NULL; + /* Check if entrydn is in the entry or not */ + if (slapi_entry_attr_find(e->ep_entry, "entrydn", &eattr)) { + /* entrydn does not exist in the entry */ + char *entrydn = NULL; + /* slapi_ch_strdup and slapi_dn_ignore_case never returns NULL */ + entrydn = slapi_ch_strdup(slapi_entry_get_dn_const(e->ep_entry)); + entrydn = slapi_dn_ignore_case(entrydn); + slapi_entry_attr_set_charptr (e->ep_entry, "entrydn", entrydn); + if (0 == slapi_entry_attr_find(e->ep_entry, "entrydn", &eattr)) { + /* now entrydn should exist in the entry */ + /* Set it to operational attribute */ + eattr->a_flags = SLAPI_ATTR_FLAG_OPATTR; + } + slapi_ch_free_string(&entrydn); + } + } slapi_ch_free( &(data.data) ); dblayer_release_id2entry( be, db ); @@ -385,3 +408,9 @@ bail: return( e ); } +struct backentry * +id2entry( backend *be, ID id, back_txn *txn, int *err ) +{ + return id2entry_ext(be, id, txn, err, 0); +} + diff --git a/ldap/servers/slapd/back-ldbm/index.c b/ldap/servers/slapd/back-ldbm/index.c index f26e3d37..da22648c 100644 --- a/ldap/servers/slapd/back-ldbm/index.c +++ b/ldap/servers/slapd/back-ldbm/index.c @@ -817,7 +817,7 @@ index_read_ext( DB *db = NULL; DB_TXN *db_txn = NULL; DBT key = {0}; - IDList *idl; + IDList *idl = NULL; char *prefix; char *tmpbuf = NULL; char buf[BUFSIZ]; @@ -850,6 +850,35 @@ index_read_ext( LDAPDebug( LDAP_DEBUG_ARGS, " indextype: \"%s\" indexmask: 0x%x\n", indextype, ai->ai_indexmask, 0 ); + /* If entryrdn switch is on AND the type is entrydn AND the prefix is '=', + * use the entryrdn index directly */ + if (entryrdn_get_switch() && (*prefix == '=') && + (0 == PL_strcasecmp(basetype, LDBM_ENTRYDN_STR))) { + int rc = 0; + ID id = 0; + Slapi_DN sdn = {0}; + + /* We don't need these values... */ + index_free_prefix( prefix ); + slapi_ch_free_string( &basetmp ); + if (NULL == val || NULL == val->bv_val) { + /* entrydn value was not given */ + return NULL; + } + slapi_sdn_init_dn_byval(&sdn, val->bv_val); + rc = entryrdn_index_read(be, &sdn, &id, txn); + slapi_sdn_done(&sdn); + if (rc) { /* failure */ + return NULL; + } else { /* success */ + rc = idl_append_extend(&idl, id); + if (rc) { /* failure */ + return NULL; + } + return idl; + } + } + if ( !is_indexed( indextype, ai->ai_indexmask, ai->ai_index_rules ) ) { idl = idl_allids( be ); if (unindexed != NULL) *unindexed = 1; diff --git a/ldap/servers/slapd/back-ldbm/ldbm_search.c b/ldap/servers/slapd/back-ldbm/ldbm_search.c index db1bd926..9a4925f6 100644 --- a/ldap/servers/slapd/back-ldbm/ldbm_search.c +++ b/ldap/servers/slapd/back-ldbm/ldbm_search.c @@ -1241,7 +1241,8 @@ ldbm_back_next_search_entry_ext( Slapi_PBlock *pb, int use_extension ) ++sr->sr_lookthroughcount; /* checked above */ /* get the entry */ - if ( (e = id2entry( be, id, NULL, &err )) == NULL ) + e = id2entry_ext( be, id, NULL, &err, ID2ENTRY_ADD_ENTRYDN ); + if ( e == NULL ) { if ( err != 0 && err != DB_NOTFOUND ) { diff --git a/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h b/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h index 12361f42..5b776847 100644 --- a/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h +++ b/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h @@ -214,6 +214,8 @@ int id2entry_add( backend *be, struct backentry *e, back_txn *txn ); int id2entry_add_ext( backend *be, struct backentry *e, back_txn *txn, int encrypt ); int id2entry_delete( backend *be, struct backentry *e, back_txn *txn ); struct backentry * id2entry( backend *be, ID id, back_txn *txn, int *err ); +struct backentry * id2entry_ext( backend *be, ID id, back_txn *txn, int *err, int flags ); + /* * idl.c -- cgit