2000-09-22 14:46:32 +08:00
|
|
|
/* id2entry.c - routines to deal with the id2entry database */
|
|
|
|
/* $OpenLDAP$ */
|
2003-11-29 05:08:20 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2013-01-03 02:20:30 +08:00
|
|
|
* Copyright 2000-2013 The OpenLDAP Foundation.
|
2003-11-29 05:08:20 +08:00
|
|
|
* 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>.
|
2000-09-22 14:46:32 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ac/string.h>
|
2006-09-20 10:43:47 +08:00
|
|
|
#include <ac/errno.h>
|
2000-09-22 14:46:32 +08:00
|
|
|
|
|
|
|
#include "back-bdb.h"
|
|
|
|
|
2003-04-23 14:34:55 +08:00
|
|
|
static int bdb_id2entry_put(
|
2000-09-26 07:41:16 +08:00
|
|
|
BackendDB *be,
|
2000-09-22 14:46:32 +08:00
|
|
|
DB_TXN *tid,
|
2001-12-06 11:26:37 +08:00
|
|
|
Entry *e,
|
|
|
|
int flag )
|
2000-09-22 14:46:32 +08:00
|
|
|
{
|
|
|
|
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
|
2000-09-25 06:48:13 +08:00
|
|
|
DB *db = bdb->bi_id2entry->bdi_db;
|
2000-09-22 14:46:32 +08:00
|
|
|
DBT key, data;
|
2001-12-03 22:00:19 +08:00
|
|
|
struct berval bv;
|
2004-03-07 03:15:39 +08:00
|
|
|
int rc;
|
2004-12-06 15:28:47 +08:00
|
|
|
ID nid;
|
2001-12-07 20:38:25 +08:00
|
|
|
#ifdef BDB_HIER
|
2003-03-23 23:27:43 +08:00
|
|
|
struct berval odn, ondn;
|
2000-09-22 14:46:32 +08:00
|
|
|
|
2003-04-22 21:14:06 +08:00
|
|
|
/* We only store rdns, and they go in the dn2id database. */
|
2001-12-07 20:38:25 +08:00
|
|
|
|
2003-03-23 23:27:43 +08:00
|
|
|
odn = e->e_name; ondn = e->e_nname;
|
2001-12-07 20:38:25 +08:00
|
|
|
|
2003-03-23 23:27:43 +08:00
|
|
|
e->e_name = slap_empty_bv;
|
|
|
|
e->e_nname = slap_empty_bv;
|
2001-12-07 20:38:25 +08:00
|
|
|
#endif
|
2000-09-22 14:46:32 +08:00
|
|
|
DBTzero( &key );
|
2004-12-06 15:28:47 +08:00
|
|
|
|
|
|
|
/* Store ID in BigEndian format */
|
|
|
|
key.data = &nid;
|
2000-09-22 14:46:32 +08:00
|
|
|
key.size = sizeof(ID);
|
2004-12-06 15:28:47 +08:00
|
|
|
BDB_ID2DISK( e->e_id, &nid );
|
2000-09-22 14:46:32 +08:00
|
|
|
|
|
|
|
rc = entry_encode( e, &bv );
|
2001-12-07 20:38:25 +08:00
|
|
|
#ifdef BDB_HIER
|
2003-03-23 23:27:43 +08:00
|
|
|
e->e_name = odn; e->e_nname = ondn;
|
2001-12-07 20:38:25 +08:00
|
|
|
#endif
|
2000-09-22 14:46:32 +08:00
|
|
|
if( rc != LDAP_SUCCESS ) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBTzero( &data );
|
2001-12-03 22:00:19 +08:00
|
|
|
bv2DBT( &bv, &data );
|
2000-09-22 14:46:32 +08:00
|
|
|
|
2001-12-06 11:26:37 +08:00
|
|
|
rc = db->put( db, tid, &key, &data, flag );
|
2000-09-22 14:46:32 +08:00
|
|
|
|
2001-12-03 22:00:19 +08:00
|
|
|
free( bv.bv_val );
|
2000-09-28 06:28:59 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2002-01-25 15:19:01 +08:00
|
|
|
/*
|
|
|
|
* This routine adds (or updates) an entry on disk.
|
|
|
|
* The cache should be already be updated.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2001-12-06 11:26:37 +08:00
|
|
|
int bdb_id2entry_add(
|
2000-09-28 06:28:59 +08:00
|
|
|
BackendDB *be,
|
|
|
|
DB_TXN *tid,
|
|
|
|
Entry *e )
|
|
|
|
{
|
2001-12-07 20:38:25 +08:00
|
|
|
return bdb_id2entry_put(be, tid, e, DB_NOOVERWRITE);
|
2001-12-06 11:26:37 +08:00
|
|
|
}
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2001-12-06 11:26:37 +08:00
|
|
|
int bdb_id2entry_update(
|
|
|
|
BackendDB *be,
|
|
|
|
DB_TXN *tid,
|
|
|
|
Entry *e )
|
|
|
|
{
|
2001-12-07 20:38:25 +08:00
|
|
|
return bdb_id2entry_put(be, tid, e, 0);
|
2000-09-22 14:46:32 +08:00
|
|
|
}
|
2000-09-25 06:48:13 +08:00
|
|
|
|
2003-04-17 00:23:36 +08:00
|
|
|
int bdb_id2entry(
|
2000-09-26 07:41:16 +08:00
|
|
|
BackendDB *be,
|
2000-09-25 06:48:13 +08:00
|
|
|
DB_TXN *tid,
|
|
|
|
ID id,
|
2003-04-17 00:23:36 +08:00
|
|
|
Entry **e )
|
2000-09-25 06:48:13 +08:00
|
|
|
{
|
|
|
|
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
|
|
|
|
DB *db = bdb->bi_id2entry->bdi_db;
|
|
|
|
DBT key, data;
|
2005-10-19 05:35:07 +08:00
|
|
|
DBC *cursor;
|
2006-09-20 10:43:47 +08:00
|
|
|
EntryHeader eh;
|
|
|
|
char buf[16];
|
|
|
|
int rc = 0, off;
|
2004-12-06 15:28:47 +08:00
|
|
|
ID nid;
|
2000-09-25 06:48:13 +08:00
|
|
|
|
2000-09-26 02:59:15 +08:00
|
|
|
*e = NULL;
|
|
|
|
|
2000-09-25 06:48:13 +08:00
|
|
|
DBTzero( &key );
|
2004-12-06 15:28:47 +08:00
|
|
|
key.data = &nid;
|
2000-09-25 06:48:13 +08:00
|
|
|
key.size = sizeof(ID);
|
2004-12-06 15:28:47 +08:00
|
|
|
BDB_ID2DISK( id, &nid );
|
2000-09-25 06:48:13 +08:00
|
|
|
|
|
|
|
DBTzero( &data );
|
2006-09-20 10:43:47 +08:00
|
|
|
data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
|
2000-09-25 06:48:13 +08:00
|
|
|
|
|
|
|
/* fetch it */
|
2005-10-19 05:35:07 +08:00
|
|
|
rc = db->cursor( db, tid, &cursor, bdb->bi_db_opflags );
|
|
|
|
if ( rc ) return rc;
|
|
|
|
|
2006-09-20 10:43:47 +08:00
|
|
|
/* Get the nattrs / nvals counts first */
|
|
|
|
data.ulen = data.dlen = sizeof(buf);
|
|
|
|
data.data = buf;
|
2005-10-19 05:35:07 +08:00
|
|
|
rc = cursor->c_get( cursor, &key, &data, DB_SET );
|
2007-06-10 07:45:23 +08:00
|
|
|
if ( rc ) goto finish;
|
2006-09-20 10:43:47 +08:00
|
|
|
|
2006-09-27 18:51:06 +08:00
|
|
|
|
2006-09-20 10:43:47 +08:00
|
|
|
eh.bv.bv_val = buf;
|
|
|
|
eh.bv.bv_len = data.size;
|
|
|
|
rc = entry_header( &eh );
|
2007-06-10 07:45:23 +08:00
|
|
|
if ( rc ) goto finish;
|
2006-09-20 10:43:47 +08:00
|
|
|
|
2011-08-28 05:35:31 +08:00
|
|
|
if ( eh.nvals ) {
|
|
|
|
/* Get the size */
|
|
|
|
data.flags ^= DB_DBT_PARTIAL;
|
|
|
|
data.ulen = 0;
|
|
|
|
rc = cursor->c_get( cursor, &key, &data, DB_CURRENT );
|
|
|
|
if ( rc != DB_BUFFER_SMALL ) goto finish;
|
|
|
|
|
|
|
|
/* Allocate a block and retrieve the data */
|
|
|
|
off = eh.data - eh.bv.bv_val;
|
|
|
|
eh.bv.bv_len = eh.nvals * sizeof( struct berval ) + data.size;
|
|
|
|
eh.bv.bv_val = ch_malloc( eh.bv.bv_len );
|
|
|
|
eh.data = eh.bv.bv_val + eh.nvals * sizeof( struct berval );
|
|
|
|
data.data = eh.data;
|
|
|
|
data.ulen = data.size;
|
|
|
|
|
|
|
|
/* skip past already parsed nattr/nvals */
|
|
|
|
eh.data += off;
|
|
|
|
|
|
|
|
rc = cursor->c_get( cursor, &key, &data, DB_CURRENT );
|
|
|
|
}
|
2006-09-20 10:43:47 +08:00
|
|
|
|
2007-06-10 07:45:23 +08:00
|
|
|
finish:
|
2005-10-19 05:35:07 +08:00
|
|
|
cursor->c_close( cursor );
|
2000-09-25 06:48:13 +08:00
|
|
|
|
|
|
|
if( rc != 0 ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2011-08-28 05:35:31 +08:00
|
|
|
if ( eh.nvals ) {
|
2004-12-15 01:22:22 +08:00
|
|
|
#ifdef SLAP_ZONE_ALLOC
|
2011-08-28 05:35:31 +08:00
|
|
|
rc = entry_decode(&eh, e, bdb->bi_cache.c_zctx);
|
2004-12-15 01:22:22 +08:00
|
|
|
#else
|
2011-08-28 05:35:31 +08:00
|
|
|
rc = entry_decode(&eh, e);
|
2004-12-15 01:22:22 +08:00
|
|
|
#endif
|
2011-08-28 05:35:31 +08:00
|
|
|
} else {
|
|
|
|
*e = entry_alloc();
|
|
|
|
}
|
2000-09-25 06:48:13 +08:00
|
|
|
|
2000-09-27 03:26:08 +08:00
|
|
|
if( rc == 0 ) {
|
|
|
|
(*e)->e_id = id;
|
2001-10-22 22:07:42 +08:00
|
|
|
} else {
|
|
|
|
/* only free on error. On success, the entry was
|
|
|
|
* decoded in place.
|
|
|
|
*/
|
2004-12-15 01:22:22 +08:00
|
|
|
#ifndef SLAP_ZONE_ALLOC
|
2006-09-20 10:43:47 +08:00
|
|
|
ch_free(eh.bv.bv_val);
|
2004-12-15 01:22:22 +08:00
|
|
|
#endif
|
2000-09-27 03:26:08 +08:00
|
|
|
}
|
2004-12-15 01:22:22 +08:00
|
|
|
#ifdef SLAP_ZONE_ALLOC
|
2006-09-20 10:43:47 +08:00
|
|
|
ch_free(eh.bv.bv_val);
|
2004-12-15 01:22:22 +08:00
|
|
|
#endif
|
2002-01-25 15:19:01 +08:00
|
|
|
|
2000-09-25 06:48:13 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int bdb_id2entry_delete(
|
2000-09-26 07:41:16 +08:00
|
|
|
BackendDB *be,
|
2000-09-25 06:48:13 +08:00
|
|
|
DB_TXN *tid,
|
2002-01-25 15:19:01 +08:00
|
|
|
Entry *e )
|
2000-09-25 06:48:13 +08:00
|
|
|
{
|
|
|
|
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
|
|
|
|
DB *db = bdb->bi_id2entry->bdi_db;
|
|
|
|
DBT key;
|
2004-03-07 03:15:39 +08:00
|
|
|
int rc;
|
2004-12-06 15:28:47 +08:00
|
|
|
ID nid;
|
2000-09-25 06:48:13 +08:00
|
|
|
|
|
|
|
DBTzero( &key );
|
2004-12-06 15:28:47 +08:00
|
|
|
key.data = &nid;
|
2000-09-25 06:48:13 +08:00
|
|
|
key.size = sizeof(ID);
|
2004-12-06 15:28:47 +08:00
|
|
|
BDB_ID2DISK( e->e_id, &nid );
|
2000-09-25 06:48:13 +08:00
|
|
|
|
2002-01-25 15:19:01 +08:00
|
|
|
/* delete from database */
|
2000-09-25 06:48:13 +08:00
|
|
|
rc = db->del( db, tid, &key, 0 );
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2004-12-15 01:22:22 +08:00
|
|
|
int bdb_entry_return(
|
|
|
|
Entry *e
|
|
|
|
)
|
2000-09-25 06:48:13 +08:00
|
|
|
{
|
2001-12-05 08:24:13 +08:00
|
|
|
/* 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
|
2006-08-29 09:43:23 +08:00
|
|
|
* in e_bv.
|
2001-10-22 22:07:42 +08:00
|
|
|
*/
|
2006-08-29 09:43:23 +08:00
|
|
|
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);
|
|
|
|
}
|
2002-01-25 15:19:01 +08:00
|
|
|
e->e_name.bv_val = NULL;
|
|
|
|
e->e_nname.bv_val = NULL;
|
2006-08-29 09:43:23 +08:00
|
|
|
/* 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 );
|
2002-01-25 15:19:01 +08:00
|
|
|
}
|
2006-08-29 09:43:23 +08:00
|
|
|
entry_free( e );
|
2000-09-25 06:48:13 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2001-12-07 20:38:25 +08:00
|
|
|
|
2001-11-27 17:34:53 +08:00
|
|
|
int bdb_entry_release(
|
2004-12-15 01:22:22 +08:00
|
|
|
Operation *op,
|
2001-11-27 17:34:53 +08:00
|
|
|
Entry *e,
|
|
|
|
int rw )
|
|
|
|
{
|
2004-12-15 01:22:22 +08:00
|
|
|
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
|
2008-05-01 20:49:35 +08:00
|
|
|
struct bdb_op_info *boi;
|
|
|
|
OpExtra *oex;
|
2002-01-25 15:19:01 +08:00
|
|
|
|
|
|
|
/* slapMode : SLAP_SERVER_MODE, SLAP_TOOL_MODE,
|
|
|
|
SLAP_TRUNCATE_MODE, SLAP_UNDEFINED_MODE */
|
|
|
|
|
|
|
|
if ( slapMode == SLAP_SERVER_MODE ) {
|
2004-07-04 12:56:36 +08:00
|
|
|
/* If not in our cache, just free it */
|
|
|
|
if ( !e->e_private ) {
|
2004-12-15 01:22:22 +08:00
|
|
|
#ifdef SLAP_ZONE_ALLOC
|
|
|
|
return bdb_entry_return( bdb, e, -1 );
|
|
|
|
#else
|
2004-07-04 12:56:36 +08:00
|
|
|
return bdb_entry_return( e );
|
2004-12-15 01:22:22 +08:00
|
|
|
#endif
|
2004-07-04 12:56:36 +08:00
|
|
|
}
|
2002-01-25 15:19:01 +08:00
|
|
|
/* free entry and reader or writer lock */
|
2008-05-01 20:49:35 +08:00
|
|
|
LDAP_SLIST_FOREACH( oex, &op->o_extra, oe_next ) {
|
2008-05-01 21:25:15 +08:00
|
|
|
if ( oex->oe_key == bdb ) break;
|
2008-05-01 20:49:35 +08:00
|
|
|
}
|
|
|
|
boi = (struct bdb_op_info *)oex;
|
2006-03-31 20:53:32 +08:00
|
|
|
|
2003-03-26 21:33:51 +08:00
|
|
|
/* lock is freed with txn */
|
2003-03-27 11:27:48 +08:00
|
|
|
if ( !boi || boi->boi_txn ) {
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_unlocked_cache_return_entry_rw( bdb, e, rw );
|
2003-03-26 21:33:51 +08:00
|
|
|
} else {
|
2004-12-05 10:00:19 +08:00
|
|
|
struct bdb_lock_info *bli, *prev;
|
|
|
|
for ( prev=(struct bdb_lock_info *)&boi->boi_locks,
|
|
|
|
bli = boi->boi_locks; bli; prev=bli, bli=bli->bli_next ) {
|
|
|
|
if ( bli->bli_id == e->e_id ) {
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_rw( bdb, e, rw, &bli->bli_lock );
|
2004-12-05 10:00:19 +08:00
|
|
|
prev->bli_next = bli->bli_next;
|
2008-10-07 08:29:54 +08:00
|
|
|
/* Cleanup, or let caller know we unlocked */
|
|
|
|
if ( bli->bli_flag & BLI_DONTFREE )
|
|
|
|
bli->bli_flag = 0;
|
|
|
|
else
|
|
|
|
op->o_tmpfree( bli, op->o_tmpmemctx );
|
2004-12-05 10:00:19 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !boi->boi_locks ) {
|
2008-05-01 20:49:35 +08:00
|
|
|
LDAP_SLIST_REMOVE( &op->o_extra, &boi->boi_oe, OpExtra, oe_next );
|
2008-10-07 08:29:54 +08:00
|
|
|
if ( !(boi->boi_flag & BOI_DONTFREE))
|
|
|
|
op->o_tmpfree( boi, op->o_tmpmemctx );
|
2004-12-05 10:00:19 +08:00
|
|
|
}
|
2003-03-26 21:33:51 +08:00
|
|
|
}
|
2002-01-25 15:19:01 +08:00
|
|
|
} else {
|
2004-12-15 01:22:22 +08:00
|
|
|
#ifdef SLAP_ZONE_ALLOC
|
|
|
|
int zseq = -1;
|
|
|
|
if (e->e_private != NULL) {
|
|
|
|
BEI(e)->bei_e = NULL;
|
|
|
|
zseq = BEI(e)->bei_zseq;
|
|
|
|
}
|
|
|
|
#else
|
2002-01-25 15:19:01 +08:00
|
|
|
if (e->e_private != NULL)
|
2003-04-22 21:14:06 +08:00
|
|
|
BEI(e)->bei_e = NULL;
|
2004-12-15 01:22:22 +08:00
|
|
|
#endif
|
2002-01-25 15:19:01 +08:00
|
|
|
e->e_private = NULL;
|
2004-12-15 01:22:22 +08:00
|
|
|
#ifdef SLAP_ZONE_ALLOC
|
|
|
|
bdb_entry_return ( bdb, e, zseq );
|
|
|
|
#else
|
2002-01-25 15:19:01 +08:00
|
|
|
bdb_entry_return ( e );
|
2004-12-15 01:22:22 +08:00
|
|
|
#endif
|
2002-01-25 15:19:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2001-11-27 17:34:53 +08:00
|
|
|
}
|
2003-03-26 19:50:03 +08:00
|
|
|
|
|
|
|
/* return LDAP_SUCCESS IFF we can retrieve the specified entry.
|
|
|
|
*/
|
|
|
|
int bdb_entry_get(
|
|
|
|
Operation *op,
|
|
|
|
struct berval *ndn,
|
|
|
|
ObjectClass *oc,
|
|
|
|
AttributeDescription *at,
|
|
|
|
int rw,
|
|
|
|
Entry **ent )
|
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
|
2003-03-26 19:50:03 +08:00
|
|
|
struct bdb_op_info *boi = NULL;
|
|
|
|
DB_TXN *txn = NULL;
|
2003-05-02 21:38:16 +08:00
|
|
|
Entry *e = NULL;
|
2003-04-17 00:23:36 +08:00
|
|
|
EntryInfo *ei;
|
2003-03-26 19:50:03 +08:00
|
|
|
int rc;
|
2003-09-20 15:48:57 +08:00
|
|
|
const char *at_name = at ? at->ad_cname.bv_val : "(null)";
|
2003-03-26 19:50:03 +08:00
|
|
|
|
|
|
|
DB_LOCK lock;
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_ARGS,
|
|
|
|
"=> bdb_entry_get: ndn: \"%s\"\n", ndn->bv_val, 0, 0 );
|
|
|
|
Debug( LDAP_DEBUG_ARGS,
|
|
|
|
"=> bdb_entry_get: oc: \"%s\", at: \"%s\"\n",
|
|
|
|
oc ? oc->soc_cname.bv_val : "(null)", at_name, 0);
|
|
|
|
|
2008-05-01 20:49:35 +08:00
|
|
|
if( op ) {
|
|
|
|
OpExtra *oex;
|
|
|
|
LDAP_SLIST_FOREACH( oex, &op->o_extra, oe_next ) {
|
2008-05-01 21:25:15 +08:00
|
|
|
if ( oex->oe_key == bdb ) break;
|
2008-05-01 20:49:35 +08:00
|
|
|
}
|
|
|
|
boi = (struct bdb_op_info *)oex;
|
|
|
|
if ( boi )
|
|
|
|
txn = boi->boi_txn;
|
2003-03-26 19:50:03 +08:00
|
|
|
}
|
|
|
|
|
2008-08-27 09:45:35 +08:00
|
|
|
if ( !txn ) {
|
|
|
|
rc = bdb_reader_get( op, bdb->bi_dbenv, &txn );
|
2003-03-26 19:50:03 +08:00
|
|
|
switch(rc) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return LDAP_OTHER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dn2entry_retry:
|
|
|
|
/* can we find entry */
|
2008-08-27 09:45:35 +08:00
|
|
|
rc = bdb_dn2entry( op, txn, ndn, &ei, 0, &lock );
|
2003-03-26 19:50:03 +08:00
|
|
|
switch( rc ) {
|
|
|
|
case DB_NOTFOUND:
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
/* the txn must abort and retry */
|
|
|
|
if ( txn ) {
|
2008-09-03 04:58:34 +08:00
|
|
|
if ( boi ) boi->boi_err = rc;
|
2003-03-26 19:50:03 +08:00
|
|
|
return LDAP_BUSY;
|
|
|
|
}
|
|
|
|
ldap_pvt_thread_yield();
|
|
|
|
goto dn2entry_retry;
|
|
|
|
default:
|
2003-04-25 18:27:55 +08:00
|
|
|
if ( boi ) boi->boi_err = rc;
|
2003-03-26 19:50:03 +08:00
|
|
|
return (rc != LDAP_BUSY) ? LDAP_OTHER : LDAP_BUSY;
|
|
|
|
}
|
2003-04-17 00:23:36 +08:00
|
|
|
if (ei) e = ei->bei_e;
|
2003-03-26 19:50:03 +08:00
|
|
|
if (e == NULL) {
|
|
|
|
Debug( LDAP_DEBUG_ACL,
|
|
|
|
"=> bdb_entry_get: cannot find entry: \"%s\"\n",
|
|
|
|
ndn->bv_val, 0, 0 );
|
|
|
|
return LDAP_NO_SUCH_OBJECT;
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_ACL,
|
|
|
|
"=> bdb_entry_get: found entry: \"%s\"\n",
|
|
|
|
ndn->bv_val, 0, 0 );
|
|
|
|
|
|
|
|
if ( oc && !is_entry_objectclass( e, oc, 0 )) {
|
|
|
|
Debug( LDAP_DEBUG_ACL,
|
2005-04-07 08:54:06 +08:00
|
|
|
"<= bdb_entry_get: failed to find objectClass %s\n",
|
2005-07-04 14:05:04 +08:00
|
|
|
oc->soc_cname.bv_val, 0, 0 );
|
2003-03-26 19:50:03 +08:00
|
|
|
rc = LDAP_NO_SUCH_ATTRIBUTE;
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2008-08-10 00:04:55 +08:00
|
|
|
/* NOTE: attr_find() or attrs_find()? */
|
|
|
|
if ( at && attr_find( e->e_attrs, at ) == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_ACL,
|
|
|
|
"<= bdb_entry_get: failed to find attribute %s\n",
|
|
|
|
at->ad_cname.bv_val, 0, 0 );
|
|
|
|
rc = LDAP_NO_SUCH_ATTRIBUTE;
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2003-03-26 19:50:03 +08:00
|
|
|
return_results:
|
|
|
|
if( rc != LDAP_SUCCESS ) {
|
|
|
|
/* free entry */
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_rw(bdb, e, rw, &lock);
|
2004-07-17 22:45:07 +08:00
|
|
|
|
2003-03-26 19:50:03 +08:00
|
|
|
} else {
|
2004-07-17 22:45:07 +08:00
|
|
|
if ( slapMode == SLAP_SERVER_MODE ) {
|
|
|
|
*ent = e;
|
|
|
|
/* big drag. we need a place to store a read lock so we can
|
2004-12-05 10:00:19 +08:00
|
|
|
* release it later?? If we're in a txn, nothing is needed
|
|
|
|
* here because the locks will go away with the txn.
|
2004-07-17 22:45:07 +08:00
|
|
|
*/
|
2004-12-05 10:00:19 +08:00
|
|
|
if ( op ) {
|
|
|
|
if ( !boi ) {
|
|
|
|
boi = op->o_tmpcalloc(1,sizeof(struct bdb_op_info),op->o_tmpmemctx);
|
2008-05-01 21:25:15 +08:00
|
|
|
boi->boi_oe.oe_key = bdb;
|
2008-05-01 20:49:35 +08:00
|
|
|
LDAP_SLIST_INSERT_HEAD( &op->o_extra, &boi->boi_oe, oe_next );
|
2004-12-05 10:00:19 +08:00
|
|
|
}
|
|
|
|
if ( !boi->boi_txn ) {
|
|
|
|
struct bdb_lock_info *bli;
|
|
|
|
bli = op->o_tmpalloc( sizeof(struct bdb_lock_info),
|
|
|
|
op->o_tmpmemctx );
|
|
|
|
bli->bli_next = boi->boi_locks;
|
|
|
|
bli->bli_id = e->e_id;
|
2008-11-23 06:41:11 +08:00
|
|
|
bli->bli_flag = 0;
|
2004-12-05 10:00:19 +08:00
|
|
|
bli->bli_lock = lock;
|
|
|
|
boi->boi_locks = bli;
|
|
|
|
}
|
2004-07-17 22:45:07 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*ent = entry_dup( e );
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_rw(bdb, e, rw, &lock);
|
2003-03-26 21:33:51 +08:00
|
|
|
}
|
2003-03-26 19:50:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"bdb_entry_get: rc=%d\n",
|
|
|
|
rc, 0, 0 );
|
|
|
|
return(rc);
|
|
|
|
}
|