From 03ea068193ec1ed564a33251e933e5a3869e7bed Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Thu, 26 Aug 1999 22:43:08 +0000 Subject: [PATCH] Disable removal of subtree indices upon delete. This allows modrdn to run, but masks the underlying subtree index bug (which I haven't found yet). Apply modrdn/dn2id changes to BDB2. --- servers/slapd/back-bdb2/add.c | 2 +- servers/slapd/back-bdb2/delete.c | 2 +- servers/slapd/back-bdb2/dn2id.c | 42 +++++++++++++++- servers/slapd/back-bdb2/modrdn.c | 60 +++++++++++++---------- servers/slapd/back-bdb2/proto-back-bdb2.h | 2 +- servers/slapd/back-bdb2/tools.c | 2 +- servers/slapd/back-ldbm/dn2id.c | 2 + 7 files changed, 80 insertions(+), 32 deletions(-) diff --git a/servers/slapd/back-bdb2/add.c b/servers/slapd/back-bdb2/add.c index 7324cc2e13..3bca6e99c5 100644 --- a/servers/slapd/back-bdb2/add.c +++ b/servers/slapd/back-bdb2/add.c @@ -243,7 +243,7 @@ bdb2i_back_add_internal( if ( bdb2i_id2entry_add( be, e ) != 0 ) { Debug( LDAP_DEBUG_TRACE, "bdb2i_id2entry_add failed\n", 0, 0, 0 ); - (void) bdb2i_dn2id_delete( be, e->e_ndn ); + (void) bdb2i_dn2id_delete( be, e->e_ndn, e->e_id ); send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL, NULL, NULL ); diff --git a/servers/slapd/back-bdb2/delete.c b/servers/slapd/back-bdb2/delete.c index d80d2dceb2..898c36b617 100644 --- a/servers/slapd/back-bdb2/delete.c +++ b/servers/slapd/back-bdb2/delete.c @@ -126,7 +126,7 @@ bdb2i_back_delete_internal( } /* delete from dn2id mapping */ - if ( bdb2i_dn2id_delete( be, e->e_ndn ) != 0 ) { + if ( bdb2i_dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) { Debug(LDAP_DEBUG_ARGS, "<=- bdb2i_back_delete: operations error %s\n", dn, 0, 0); diff --git a/servers/slapd/back-bdb2/dn2id.c b/servers/slapd/back-bdb2/dn2id.c index 0d49a099dd..c4cb4e8458 100644 --- a/servers/slapd/back-bdb2/dn2id.c +++ b/servers/slapd/back-bdb2/dn2id.c @@ -178,14 +178,16 @@ bdb2i_dn2idl( int bdb2i_dn2id_delete( BackendDB *be, - const char *dn + const char *dn, + ID id ) { struct dbcache *db; Datum key; int rc; - Debug( LDAP_DEBUG_TRACE, "=> bdb2i_dn2id_delete( \"%s\" )\n", dn, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "=> bdb2i_dn2id_delete( \"%s\", %ld )\n", + dn, id, 0 ); if ( (db = bdb2i_cache_open( be, "dn2id", BDB2_SUFFIX, LDBM_WRCREAT )) == NULL ) { @@ -195,6 +197,42 @@ bdb2i_dn2id_delete( return( -1 ); } + { + char *pdn = dn_parent( NULL, dn ); + + if( pdn != NULL ) { + ldbm_datum_init( key ); + key.dsize = strlen( pdn ) + 2; + key.dptr = ch_malloc( key.dsize ); + sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, pdn ); + (void) bdb2i_idl_delete_key( be, db, key, id ); + free( key.dptr ); + free( pdn ); + } + } + +#if 0 + { + char **subtree = dn_subtree( NULL, dn ); + + if( subtree != NULL ) { + int i; + for( i=0; subtree[i] != NULL; i++ ) { + ldbm_datum_init( key ); + key.dsize = strlen( subtree[i] ) + 2; + key.dptr = ch_malloc( key.dsize ); + sprintf( key.dptr, "%c%s", DN_SUBTREE_PREFIX, subtree[i] ); + + (void) bdb2i_idl_delete_key( be, db, key, id ); + + free( key.dptr ); + } + + charray_free( subtree ); + } + } +#endif + ldbm_datum_init( key ); key.dsize = strlen( dn ) + 2; diff --git a/servers/slapd/back-bdb2/modrdn.c b/servers/slapd/back-bdb2/modrdn.c index 4460c06cdd..e6e003b793 100644 --- a/servers/slapd/back-bdb2/modrdn.c +++ b/servers/slapd/back-bdb2/modrdn.c @@ -225,12 +225,6 @@ bdb2i_back_modrdn_internal( Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: new ndn=%s\n", new_ndn, 0, 0 ); - if ( (bdb2i_dn2id ( be, new_ndn ) ) != NOID ) { - send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, - NULL, NULL, NULL, NULL ); - goto return_results; - } - /* check for abandon */ ldap_pvt_thread_mutex_lock( &op->o_abandonmutex ); if ( op->o_abandon ) { @@ -239,23 +233,8 @@ bdb2i_back_modrdn_internal( } ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex ); - /* delete old one */ - if ( bdb2i_dn2id_delete( be, e->e_ndn ) != 0 ) { - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, - NULL, NULL, NULL, NULL ); - goto return_results; - } - - (void) bdb2i_cache_delete_entry( &li->li_cache, e ); - free( e->e_dn ); - free( e->e_ndn ); - e->e_dn = new_dn; - e->e_ndn = new_ndn; - - - /* add new one */ - if ( bdb2i_dn2id_add( be, e->e_ndn, e->e_id ) != 0 ) { - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, + if ( (bdb2i_dn2id ( be, new_ndn ) ) != NOID ) { + send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, NULL, NULL, NULL, NULL ); goto return_results; } @@ -401,6 +380,37 @@ bdb2i_back_modrdn_internal( } #endif + /* check for abandon */ + ldap_pvt_thread_mutex_lock( &op->o_abandonmutex ); + if ( op->o_abandon ) { + ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex ); + goto return_results; + } + ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex ); + + /* delete old one */ + if ( bdb2i_dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) { + send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, + NULL, NULL, NULL, NULL ); + goto return_results; + } + + (void) bdb2i_cache_delete_entry( &li->li_cache, e ); + + free( e->e_dn ); + free( e->e_ndn ); + e->e_dn = new_dn; + e->e_ndn = new_ndn; + new_dn = NULL; + new_ndn = NULL; + + /* add new one */ + if ( bdb2i_dn2id_add( be, e->e_ndn, e->e_id ) != 0 ) { + send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, + NULL, NULL, NULL, NULL ); + goto return_results; + } + /* modify memory copy of entry */ if ( bdb2i_back_modify_internal( be, conn, op, dn, &mod[0], e ) != 0 ) { @@ -420,19 +430,17 @@ bdb2i_back_modrdn_internal( entry_free( e ); send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL, NULL, NULL ); - goto return_results_after; + goto return_results; } send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, NULL ); rc = 0; - goto return_results_after; return_results: if( new_dn != NULL ) free( new_dn ); if( new_ndn != NULL ) free( new_ndn ); -return_results_after: /* NOTE: * new_dn and new_ndn are not deallocated because they are used by * the cache entry. diff --git a/servers/slapd/back-bdb2/proto-back-bdb2.h b/servers/slapd/back-bdb2/proto-back-bdb2.h index d2c18a6454..4b7d6e8674 100644 --- a/servers/slapd/back-bdb2/proto-back-bdb2.h +++ b/servers/slapd/back-bdb2/proto-back-bdb2.h @@ -76,7 +76,7 @@ int bdb2i_cache_delete LDAP_P(( struct dbcache *db, Datum key )); int bdb2i_dn2id_add LDAP_P(( BackendDB *be, const char *dn, ID id )); ID bdb2i_dn2id LDAP_P(( BackendDB *be, const char *dn )); -int bdb2i_dn2id_delete LDAP_P(( BackendDB *be, const char *dn )); +int bdb2i_dn2id_delete LDAP_P(( BackendDB *be, const char *dn, ID id )); ID_BLOCK * bdb2i_dn2idl LDAP_P(( diff --git a/servers/slapd/back-bdb2/tools.c b/servers/slapd/back-bdb2/tools.c index 66b018a03a..ba9c939ee4 100644 --- a/servers/slapd/back-bdb2/tools.c +++ b/servers/slapd/back-bdb2/tools.c @@ -184,7 +184,7 @@ ID bdb2_tool_entry_put( rc = bdb2i_cache_store( id2entry, key, data, LDBM_REPLACE ); if( rc != 0 ) { - (void) bdb2i_dn2id_delete( be, e->e_ndn ); + (void) bdb2i_dn2id_delete( be, e->e_ndn, e->e_id ); return NOID; } diff --git a/servers/slapd/back-ldbm/dn2id.c b/servers/slapd/back-ldbm/dn2id.c index ca3a2803dc..9a1d4f2ccc 100644 --- a/servers/slapd/back-ldbm/dn2id.c +++ b/servers/slapd/back-ldbm/dn2id.c @@ -226,6 +226,7 @@ dn2id_delete( } } +#if 0 { char **subtree = dn_subtree( NULL, dn ); @@ -246,6 +247,7 @@ dn2id_delete( charray_free( subtree ); } } +#endif ldbm_datum_init( key ); -- 2.39.5