]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/id2entry.c
return structuralObjectClass errors
[openldap] / servers / slapd / back-bdb / id2entry.c
index 0bb1ced380fd8300800f23ccd1605dce625f57d5..58fafd1cc9ba834a88123dd2eced5c078eded935 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2000-2004 The OpenLDAP Foundation.
+ * Copyright 2000-2006 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -92,14 +92,16 @@ int bdb_id2entry_update(
 int bdb_id2entry(
        BackendDB *be,
        DB_TXN *tid,
+       u_int32_t locker,
        ID id,
        Entry **e )
 {
        struct bdb_info *bdb = (struct bdb_info *) be->be_private;
        DB *db = bdb->bi_id2entry->bdi_db;
        DBT key, data;
+       DBC *cursor;
        struct berval bv;
-       int rc = 0, ret = 0;
+       int rc = 0;
        ID nid;
 
        *e = NULL;
@@ -113,7 +115,15 @@ int bdb_id2entry(
        data.flags = DB_DBT_MALLOC;
 
        /* fetch it */
-       rc = db->get( db, tid, &key, &data, bdb->bi_db_opflags );
+       rc = db->cursor( db, tid, &cursor, bdb->bi_db_opflags );
+       if ( rc ) return rc;
+
+       /* Use our own locker if needed */
+       if ( !tid && locker )
+               cursor->locker = locker;
+
+       rc = cursor->c_get( cursor, &key, &data, DB_SET );
+       cursor->c_close( cursor );
 
        if( rc != 0 ) {
                return rc;
@@ -121,7 +131,11 @@ int bdb_id2entry(
 
        DBT2bv( &data, &bv );
 
-       rc = entry_decode( &bv, e );
+#ifdef SLAP_ZONE_ALLOC
+       rc = entry_decode(&bv, e, bdb->bi_cache.c_zctx);
+#else
+       rc = entry_decode(&bv, e);
+#endif
 
        if( rc == 0 ) {
                (*e)->e_id = id;
@@ -129,8 +143,13 @@ int bdb_id2entry(
                /* only free on error. On success, the entry was
                 * decoded in place.
                 */
-               ch_free( data.data );
+#ifndef SLAP_ZONE_ALLOC
+               ch_free(data.data);
+#endif
        }
+#ifdef SLAP_ZONE_ALLOC
+       ch_free(data.data);
+#endif
 
        return rc;
 }
@@ -158,51 +177,39 @@ int bdb_id2entry_delete(
 }
 
 int bdb_entry_return(
-       Entry *e )
+       Entry *e
+)
 {
        /* Our entries are allocated in two blocks; the data comes from
         * the db itself and the Entry structure and associated pointers
         * are allocated in entry_decode. The db data pointer is saved
-        * in e_bv. Since the Entry structure is allocated as a single
-        * block, e_attrs is always a fixed offset from e. The exception
-        * is when an entry has been modified, in which case we also need
-        * to free e_attrs.
+        * in e_bv.
         */
-       if( !e->e_bv.bv_val ) { /* A regular entry, from do_add */
-               entry_free( e );
-               return 0;
-       }
-       if( (void *) e->e_attrs != (void *) (e+1)) {
-               attrs_free( e->e_attrs );
-       }
-
-       /* See if the DNs were changed by modrdn */
-       if( e->e_nname.bv_val < e->e_bv.bv_val || e->e_nname.bv_val >
-               e->e_bv.bv_val + e->e_bv.bv_len ) {
-               ch_free(e->e_name.bv_val);
-               ch_free(e->e_nname.bv_val);
+       if ( e->e_bv.bv_val ) {
+               /* See if the DNs were changed by modrdn */
+               if( e->e_nname.bv_val < e->e_bv.bv_val || e->e_nname.bv_val >
+                       e->e_bv.bv_val + e->e_bv.bv_len ) {
+                       ch_free(e->e_name.bv_val);
+                       ch_free(e->e_nname.bv_val);
+               }
                e->e_name.bv_val = NULL;
                e->e_nname.bv_val = NULL;
+               /* In tool mode the e_bv buffer is realloc'd, leave it alone */
+               if( !(slapMode & SLAP_TOOL_MODE) ) {
+                       free( e->e_bv.bv_val );
+               }
+               BER_BVZERO( &e->e_bv );
        }
-#ifndef BDB_HIER
-       /* In tool mode the e_bv buffer is realloc'd, leave it alone */
-       if( !(slapMode & SLAP_TOOL_MODE) ) {
-               free( e->e_bv.bv_val );
-       }
-#else
-       free( e->e_bv.bv_val );
-#endif
-       free( e );
-
+       entry_free( e );
        return 0;
 }
 
 int bdb_entry_release(
-       Operation *o,
+       Operation *op,
        Entry *e,
        int rw )
 {
-       struct bdb_info *bdb = (struct bdb_info *) o->o_bd->be_private;
+       struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
        struct bdb_op_info *boi = NULL;
  
        /* slapMode : SLAP_SERVER_MODE, SLAP_TOOL_MODE,
@@ -211,12 +218,15 @@ int bdb_entry_release(
        if ( slapMode == SLAP_SERVER_MODE ) {
                /* If not in our cache, just free it */
                if ( !e->e_private ) {
+#ifdef SLAP_ZONE_ALLOC
+                       return bdb_entry_return( bdb, e, -1 );
+#else
                        return bdb_entry_return( e );
+#endif
                }
                /* free entry and reader or writer lock */
-               if ( o ) {
-                       boi = (struct bdb_op_info *)o->o_private;
-               }
+               boi = (struct bdb_op_info *)op->o_private;
+
                /* lock is freed with txn */
                if ( !boi || boi->boi_txn ) {
                        bdb_unlocked_cache_return_entry_rw( &bdb->bi_cache, e, rw );
@@ -228,20 +238,32 @@ int bdb_entry_release(
                                        bdb_cache_return_entry_rw( bdb->bi_dbenv, &bdb->bi_cache,
                                                e, rw, &bli->bli_lock );
                                        prev->bli_next = bli->bli_next;
-                                       o->o_tmpfree( bli, o->o_tmpmemctx );
+                                       op->o_tmpfree( bli, op->o_tmpmemctx );
                                        break;
                                }
                        }
                        if ( !boi->boi_locks ) {
-                               o->o_tmpfree( boi, o->o_tmpmemctx );
-                               o->o_private = NULL;
+                               op->o_tmpfree( boi, op->o_tmpmemctx );
+                               op->o_private = NULL;
                        }
                }
        } else {
+#ifdef SLAP_ZONE_ALLOC
+               int zseq = -1;
+               if (e->e_private != NULL) {
+                       BEI(e)->bei_e = NULL;
+                       zseq = BEI(e)->bei_zseq;
+               }
+#else
                if (e->e_private != NULL)
                        BEI(e)->bei_e = NULL;
+#endif
                e->e_private = NULL;
+#ifdef SLAP_ZONE_ALLOC
+               bdb_entry_return ( bdb, e, zseq );
+#else
                bdb_entry_return ( e );
+#endif
        }
  
        return 0;
@@ -349,8 +371,8 @@ dn2entry_retry:
 
        if ( oc && !is_entry_objectclass( e, oc, 0 )) {
                Debug( LDAP_DEBUG_ACL,
-                       "<= bdb_entry_get: failed to find objectClass\n",
-                       0, 0, 0 ); 
+                       "<= bdb_entry_get: failed to find objectClass %s\n",
+                       oc->soc_cname.bv_val, 0, 0 ); 
                rc = LDAP_NO_SUCH_ATTRIBUTE;
                goto return_results;
        }