]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/id2entry.c
ITS#3226: Clear attribute flags after schema_check failed
[openldap] / servers / slapd / back-bdb / id2entry.c
index 21478685de03db4ad9d0337ec1603cea9451c1cf..d4eb26711119a21037a44c44bfb0832f1362fcf5 100644 (file)
@@ -1,8 +1,17 @@
 /* id2entry.c - routines to deal with the id2entry database */
 /* $OpenLDAP$ */
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 2000-2004 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
  */
 
 #include "portable.h"
@@ -11,8 +20,9 @@
 #include <ac/string.h>
 
 #include "back-bdb.h"
+#include "external.h"
 
-int bdb_id2entry_put(
+static int bdb_id2entry_put(
        BackendDB *be,
        DB_TXN *tid,
        Entry *e,
@@ -26,7 +36,7 @@ int bdb_id2entry_put(
 #ifdef BDB_HIER
        struct berval odn, ondn;
 
-       /* We only store rdns, and they go in the id2parent database. */
+       /* We only store rdns, and they go in the dn2id database. */
 
        odn = e->e_name; ondn = e->e_nname;
 
@@ -76,14 +86,11 @@ int bdb_id2entry_update(
        return bdb_id2entry_put(be, tid, e, 0);
 }
 
-int bdb_id2entry_rw(
+int bdb_id2entry(
        BackendDB *be,
        DB_TXN *tid,
        ID id,
-       Entry **e,
-       int rw,
-       u_int32_t locker,
-       DB_LOCK *lock )
+       Entry **e )
 {
        struct bdb_info *bdb = (struct bdb_info *) be->be_private;
        DB *db = bdb->bi_id2entry->bdi_db;
@@ -100,12 +107,8 @@ int bdb_id2entry_rw(
        DBTzero( &data );
        data.flags = DB_DBT_MALLOC;
 
-       if ((*e = bdb_cache_find_entry_id(bdb->bi_dbenv, &bdb->bi_cache, id, rw, locker, lock)) != NULL) {
-               return 0;
-       }
-
        /* fetch it */
-       rc = db->get( db, tid, &key, &data, bdb->bi_db_opflags | ( rw ? DB_RMW : 0 ));
+       rc = db->get( db, tid, &key, &data, bdb->bi_db_opflags );
 
        if( rc != 0 ) {
                return rc;
@@ -124,44 +127,6 @@ int bdb_id2entry_rw(
                ch_free( data.data );
        }
 
-       if ( rc == 0 ) {
-#ifdef BDB_HIER
-               bdb_fix_dn(be, id, *e);
-#endif
-               ret = bdb_cache_add_entry_rw( bdb->bi_dbenv,
-                               &bdb->bi_cache, *e, rw, locker, lock);
-               while ( ret == 1 || ret == -1 ) {
-                       Entry *ee;
-                       int add_loop_cnt = 0;
-                       if ( (*e)->e_private != NULL ) {
-                               free ((*e)->e_private);
-                       }
-                       (*e)->e_private = NULL;
-                       if ( (ee = bdb_cache_find_entry_id
-                                       (bdb->bi_dbenv, &bdb->bi_cache, id, rw, locker, lock) ) != NULL) {
-                               bdb_entry_return ( *e );
-                               *e = ee;
-                               return 0;
-                       }
-                       if ( ++add_loop_cnt == BDB_MAX_ADD_LOOP ) {
-                               bdb_entry_return ( *e );
-                               *e = NULL;
-                               return LDAP_BUSY;
-                       }
-               }
-               if ( ret != 0 ) {
-                       if ( (*e)->e_private != NULL )
-                               free ( (*e)->e_private );
-                       bdb_entry_return( *e );
-                       *e = NULL;
-               }
-               rc = ret;
-       }
-
-       if (rc == 0) {
-               bdb_cache_entry_commit(*e);
-       }
-
        return rc;
 }
 
@@ -175,8 +140,6 @@ int bdb_id2entry_delete(
        DBT key;
        int rc;
 
-       bdb_cache_delete_entry(&bdb->bi_cache, e);
-
        DBTzero( &key );
        key.data = (char *) &e->e_id;
        key.size = sizeof(ID);
@@ -206,7 +169,6 @@ int bdb_entry_return(
                attrs_free( e->e_attrs );
        }
 
-#ifndef BDB_HIER
        /* 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 ) {
@@ -215,17 +177,14 @@ int bdb_entry_return(
                e->e_name.bv_val = NULL;
                e->e_nname.bv_val = NULL;
        }
-#else
-       /* We had to construct the dn and ndn as well, in a single block */
-       if( e->e_name.bv_val ) {
-               free( e->e_name.bv_val );
-       }
-#endif
+#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 );
 
        return 0;
@@ -243,6 +202,10 @@ int bdb_entry_release(
                        SLAP_TRUNCATE_MODE, SLAP_UNDEFINED_MODE */
  
        if ( slapMode == SLAP_SERVER_MODE ) {
+               /* If not in our cache, just free it */
+               if ( !e->e_private ) {
+                       return bdb_entry_return( e );
+               }
                /* free entry and reader or writer lock */
                if ( o ) {
                        boi = (struct bdb_op_info *)o->o_private;
@@ -252,12 +215,12 @@ int bdb_entry_release(
                        bdb_unlocked_cache_return_entry_rw( &bdb->bi_cache, e, rw );
                } else {
                        bdb_cache_return_entry_rw( bdb->bi_dbenv, &bdb->bi_cache, e, rw, &boi->boi_lock );
-                       ch_free( boi );
+                       o->o_tmpfree( boi, o->o_tmpmemctx );
                        o->o_private = NULL;
                }
        } else {
                if (e->e_private != NULL)
-                       free (e->e_private);
+                       BEI(e)->bei_e = NULL;
                e->e_private = NULL;
                bdb_entry_return ( e );
        }
@@ -278,9 +241,10 @@ int bdb_entry_get(
        struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
        struct bdb_op_info *boi = NULL;
        DB_TXN *txn = NULL;
-       Entry *e;
+       Entry *e = NULL;
+       EntryInfo *ei;
        int     rc;
-       const char *at_name = at->ad_cname.bv_val;
+       const char *at_name = at ? at->ad_cname.bv_val : "(null)";
 
        u_int32_t       locker = 0;
        DB_LOCK         lock;
@@ -321,7 +285,7 @@ int bdb_entry_get(
 
 dn2entry_retry:
        /* can we find entry */
-       rc = bdb_dn2entry_rw( op->o_bd, txn, ndn, &e, NULL, 0, rw, locker, &lock );
+       rc = bdb_dn2entry( op, txn, ndn, &ei, 0, locker, &lock );
        switch( rc ) {
        case DB_NOTFOUND:
        case 0:
@@ -336,12 +300,13 @@ dn2entry_retry:
                ldap_pvt_thread_yield();
                goto dn2entry_retry;
        default:
-               boi->boi_err = rc;
+               if ( boi ) boi->boi_err = rc;
                if ( free_lock_id ) {
                        LOCK_ID_FREE( bdb->bi_dbenv, locker );
                }
                return (rc != LDAP_BUSY) ? LDAP_OTHER : LDAP_BUSY;
        }
+       if (ei) e = ei->bei_e;
        if (e == NULL) {
 #ifdef NEW_LOGGING
                LDAP_LOG( BACK_BDB, INFO, 
@@ -417,7 +382,7 @@ return_results:
                 * release it later??
                 */
                if ( op && !boi ) {
-                       boi = ch_calloc(1,sizeof(struct bdb_op_info));
+                       boi = op->o_tmpcalloc(1,sizeof(struct bdb_op_info),op->o_tmpmemctx);
                        boi->boi_lock = lock;
                        op->o_private = boi;
                }