From 406f33eb128c4e85ddd542d63467a8cfee9837bc Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Thu, 26 Aug 1999 00:48:24 +0000 Subject: [PATCH] This fixes dn2id delete bug... but breaks modrdn. --- libraries/libldbm/ldbm.c | 10 +++++--- servers/slapd/back-ldbm/add.c | 2 +- servers/slapd/back-ldbm/delete.c | 2 +- servers/slapd/back-ldbm/dn2id.c | 44 +++++++++++++++++++++++++++++--- servers/slapd/back-ldbm/modrdn.c | 2 +- 5 files changed, 51 insertions(+), 9 deletions(-) diff --git a/libraries/libldbm/ldbm.c b/libraries/libldbm/ldbm.c index e9091a9a10..7d2cfc831b 100644 --- a/libraries/libldbm/ldbm.c +++ b/libraries/libldbm/ldbm.c @@ -441,12 +441,16 @@ ldbm_open( char *name, int rw, int mode, int dbcachesize ) #ifdef HAVE_ST_BLKSIZE if ( dbcachesize > 0 && stat( name, &st ) == 0 ) { - dbcachesize = (dbcachesize / st.st_blksize); + dbcachesize /= st.st_blksize; + if( dbcachesize == 0 ) dbcachesize = 1; gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) ); } #else - dbcachesize = (dbcachesize / 4096); - gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) ); + if ( dbcachesize > 0 ) { + dbcachesize /= 4096; + if( dbcachesize == 0 ) dbcachesize = 1; + gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) ); + } #endif LDBM_UNLOCK; diff --git a/servers/slapd/back-ldbm/add.c b/servers/slapd/back-ldbm/add.c index 8775e29514..5f8f9052f5 100644 --- a/servers/slapd/back-ldbm/add.c +++ b/servers/slapd/back-ldbm/add.c @@ -252,7 +252,7 @@ ldbm_back_add( if ( id2entry_add( be, e ) != 0 ) { Debug( LDAP_DEBUG_TRACE, "id2entry_add failed\n", 0, 0, 0 ); - (void) dn2id_delete( be, e->e_ndn ); + (void) 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-ldbm/delete.c b/servers/slapd/back-ldbm/delete.c index 7db49948bb..ae5c513c26 100644 --- a/servers/slapd/back-ldbm/delete.c +++ b/servers/slapd/back-ldbm/delete.c @@ -141,7 +141,7 @@ ldbm_back_delete( } /* delete from dn2id mapping */ - if ( dn2id_delete( be, e->e_ndn ) != 0 ) { + if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) { Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: operations error %s\n", dn, 0, 0); diff --git a/servers/slapd/back-ldbm/dn2id.c b/servers/slapd/back-ldbm/dn2id.c index 26f75476aa..0501dd014d 100644 --- a/servers/slapd/back-ldbm/dn2id.c +++ b/servers/slapd/back-ldbm/dn2id.c @@ -87,7 +87,6 @@ dn2id_add( charray_free( subtree ); } - } ldbm_cache_close( be, db ); @@ -187,14 +186,15 @@ dn2idl( int dn2id_delete( Backend *be, - const char *dn + const char *dn, + ID id ) { DBCache *db; Datum key; int rc; - Debug( LDAP_DEBUG_TRACE, "=> dn2id_delete( \"%s\" )\n", dn, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "=> dn2id_delete( \"%s\", %ld )\n", dn, id, 0 ); if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_WRCREAT )) == NULL ) { @@ -204,6 +204,44 @@ 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) idl_delete_key( be, db, key, id ); + free( key.dptr ); + free( pdn ); + } + } + + { + 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) idl_delete_key( be, db, key, id ); + + free( key.dptr ); + + if(rc == -1) break; + } + + charray_free( subtree ); + } + } + ldbm_datum_init( key ); key.dsize = strlen( dn ) + 2; diff --git a/servers/slapd/back-ldbm/modrdn.c b/servers/slapd/back-ldbm/modrdn.c index fae002cec0..9ada4b1bc0 100644 --- a/servers/slapd/back-ldbm/modrdn.c +++ b/servers/slapd/back-ldbm/modrdn.c @@ -280,7 +280,7 @@ ldbm_back_modrdn( ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex ); /* delete old one */ - if ( dn2id_delete( be, e->e_ndn ) != 0 ) { + if ( 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; -- 2.39.5