]> git.sur5r.net Git - openldap/commitdiff
Fix ITS#1774, BDB keys need ulen and flags to be initialized because BDB
authorHoward Chu <hyc@openldap.org>
Thu, 25 Apr 2002 05:16:15 +0000 (05:16 +0000)
committerHoward Chu <hyc@openldap.org>
Thu, 25 Apr 2002 05:16:15 +0000 (05:16 +0000)
tries to retrieve both the key and the data.

servers/slapd/back-bdb/dn2id.c
servers/slapd/back-bdb/idl.c
servers/slapd/back-bdb/key.c

index 6511e6706bbb08cf17a29c3d3f294c65d5ba2614..91a989095c9ab8a05b68691b023a0d8af23efc48 100644 (file)
@@ -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 );
index ec193efeece06c9cc48c22d26d2b7e4364785819..175faa0bbdc742db7766b81ceebd02d4016c5670 100644 (file)
@@ -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 ) {
index ea6433fa6eebf38301a286322ef24ab24c3ff452..a6b490f101cac5f2d2dcdc9f9e50987a9020face 100644 (file)
@@ -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 */