From 43167d0fa65ea3c81368b6ce85fee48a7c703055 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 25 Apr 2002 05:16:15 +0000 Subject: [PATCH] Fix ITS#1774, BDB keys need ulen and flags to be initialized because BDB tries to retrieve both the key and the data. --- servers/slapd/back-bdb/dn2id.c | 10 +++++++++- servers/slapd/back-bdb/idl.c | 9 ++++++--- servers/slapd/back-bdb/key.c | 4 ++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/servers/slapd/back-bdb/dn2id.c b/servers/slapd/back-bdb/dn2id.c index 6511e6706b..91a989095c 100644 --- a/servers/slapd/back-bdb/dn2id.c +++ b/servers/slapd/back-bdb/dn2id.c @@ -39,6 +39,8 @@ bdb_dn2id_add( DBTzero( &key ); key.size = e->e_nname.bv_len + 2; + key.ulen = key.size; + key.flags = DB_DBT_USERMEM; buf = ch_malloc( key.size ); key.data = buf; buf[0] = DN_BASE_PREFIX; @@ -84,6 +86,7 @@ bdb_dn2id_add( dnParent( &ptr, &pdn ); key.size = pdn.bv_len + 2; + key.ulen = key.size; pdn.bv_val[-1] = DN_ONE_PREFIX; key.data = pdn.bv_val-1; ptr = pdn; @@ -124,6 +127,7 @@ bdb_dn2id_add( dnParent( &ptr, &pdn ); key.size = pdn.bv_len + 2; + key.ulen = key.size; key.data = pdn.bv_val - 1; ptr = pdn; } @@ -189,7 +193,7 @@ bdb_dn2id_delete( if( !be_issuffix( be, &ptr )) { buf[0] = DN_SUBTREE_PREFIX; - rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id ); + rc = db->del( db, txn, &key, 0 ); if( rc != 0 ) { #ifdef NEW_LOGGING LDAP_LOG (( "db2id", LDAP_LEVEL_ERR, @@ -206,6 +210,7 @@ bdb_dn2id_delete( dnParent( &ptr, &pdn ); key.size = pdn.bv_len + 2; + key.ulen = key.size; pdn.bv_val[-1] = DN_ONE_PREFIX; key.data = pdn.bv_val - 1; ptr = pdn; @@ -245,6 +250,7 @@ bdb_dn2id_delete( dnParent( &ptr, &pdn ); key.size = pdn.bv_len + 2; + key.ulen = key.size; key.data = pdn.bv_val - 1; ptr = pdn; } @@ -528,6 +534,8 @@ bdb_dn2idl( DBTzero( &key ); key.size = dn->bv_len + 2; + key.ulen = key.size; + key.flags = DB_DBT_USERMEM; key.data = ch_malloc( key.size ); ((char *)key.data)[0] = prefix; AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 ); diff --git a/servers/slapd/back-bdb/idl.c b/servers/slapd/back-bdb/idl.c index ec193efeec..175faa0bbd 100644 --- a/servers/slapd/back-bdb/idl.c +++ b/servers/slapd/back-bdb/idl.c @@ -684,9 +684,12 @@ bdb_idl_delete_key( if ( rc == 0 ) { if ( tmp != 0 ) { /* Not a range, just delete it */ - data.data = &id; - rc = cursor->c_get( cursor, key, &data, - DB_GET_BOTH | DB_RMW ); + if (tmp != id) { + /* position to correct item */ + tmp = id; + rc = cursor->c_get( cursor, key, &data, + DB_GET_BOTH | DB_RMW ); + } if ( rc == 0 ) { rc = cursor->c_del( cursor, 0 ); if ( rc != 0 ) { diff --git a/servers/slapd/back-bdb/key.c b/servers/slapd/back-bdb/key.c index ea6433fa6e..a6b490f101 100644 --- a/servers/slapd/back-bdb/key.c +++ b/servers/slapd/back-bdb/key.c @@ -38,6 +38,8 @@ bdb_key_read( DBTzero( &key ); bv2DBT(k,&key); + key.ulen = key.size; + key.flags = DB_DBT_USERMEM; rc = bdb_idl_fetch_key( be, db, txn, &key, ids ); @@ -88,6 +90,8 @@ bdb_key_change( DBTzero( &key ); bv2DBT(k,&key); + key.ulen = key.size; + key.flags = DB_DBT_USERMEM; if (op == SLAP_INDEX_ADD_OP) { /* Add values */ -- 2.39.5