switch( rs->sr_err ) {
case 0:
rs->sr_err = LDAP_ALREADY_EXISTS;
- mdb_entry_return( p );
+ mdb_entry_return( op, p );
p = NULL;
goto return_results;
case MDB_NOTFOUND:
rs->sr_ref = NULL;
}
if ( p != (Entry *)&slap_entry_root )
- mdb_entry_return( p );
+ mdb_entry_return( op, p );
p = NULL;
Debug( LDAP_DEBUG_TRACE,
LDAP_XSTRING(mdb_add) ": parent "
if ( ! rs->sr_err ) {
if ( p != (Entry *)&slap_entry_root )
- mdb_entry_return( p );
+ mdb_entry_return( op, p );
p = NULL;
Debug( LDAP_DEBUG_TRACE,
if ( p != (Entry *)&slap_entry_root ) {
if ( is_entry_subentry( p ) ) {
- mdb_entry_return( p );
+ mdb_entry_return( op, p );
p = NULL;
/* parent is a subentry, don't allow add */
Debug( LDAP_DEBUG_TRACE,
}
if ( is_entry_alias( p ) ) {
- mdb_entry_return( p );
+ mdb_entry_return( op, p );
p = NULL;
/* parent is an alias, don't allow add */
Debug( LDAP_DEBUG_TRACE,
rs->sr_ref = referral_rewrite( ref, &p->e_name,
&op->o_req_dn, LDAP_SCOPE_DEFAULT );
ber_bvarray_free( ref );
- mdb_entry_return( p );
+ mdb_entry_return( op, p );
p = NULL;
Debug( LDAP_DEBUG_TRACE,
LDAP_XSTRING(mdb_add) ": parent is referral\n",
}
}
- mdb_entry_return( p );
+ mdb_entry_return( op, p );
}
p = NULL;
}
/* free entry and reader lock */
if( e != NULL ) {
- mdb_entry_return( e );
+ mdb_entry_return( op, e );
}
if ( rs->sr_err ) {
}
rs->sr_err = LDAP_REFERRAL;
}
- mdb_entry_return( e );
+ mdb_entry_return( op, e );
e = NULL;
} else {
}
/* free entry */
if ( e != NULL ) {
- mdb_entry_return( e );
+ mdb_entry_return( op, e );
}
return rs->sr_err;
&op->o_req_dn, LDAP_SCOPE_DEFAULT );
}
if ( p ) {
- mdb_entry_return( p );
+ mdb_entry_return( op, p );
p = NULL;
}
} else {
rs->sr_ref = NULL;
}
- mdb_entry_return( e );
+ mdb_entry_return( op, e );
e = NULL;
rs->sr_err = LDAP_REFERRAL;
}
parent_is_leaf = 1;
}
- mdb_entry_return( p );
+ mdb_entry_return( op, p );
p = NULL;
}
}
if ( p != NULL ) {
- mdb_entry_return( p );
+ mdb_entry_return( op, p );
}
/* free entry */
if( e != NULL ) {
- mdb_entry_return( e );
+ mdb_entry_return( op, e );
}
if( moi == &opinfo ) {
#include "back-mdb.h"
static int mdb_entry_encode(Operation *op, MDB_txn *txn, Entry *e, MDB_val *data);
+static Entry *mdb_entry_alloc( Operation *op, int nattrs, int nvals );
static int mdb_id2entry_put(
Operation *op,
/* Looking for root entry on an empty-dn suffix? */
if ( !id && BER_BVISEMPTY( &op->o_bd->be_nsuffix[0] )) {
struct berval gluebv = BER_BVC("glue");
- Entry *r = entry_alloc();
+ Entry *r = mdb_entry_alloc(op, 2, 4);
+ Attribute *a = r->e_attrs;
+ struct berval *bptr;
r->e_id = 0;
- attr_merge_one( r, slap_schema.si_ad_objectClass, &gluebv, NULL );
- attr_merge_one( r, slap_schema.si_ad_structuralObjectClass, &gluebv, NULL );
r->e_ocflags = SLAP_OC_GLUE|SLAP_OC__END;
+ bptr = a->a_vals;
+ a->a_flags = SLAP_ATTR_DONT_FREE_DATA | SLAP_ATTR_DONT_FREE_VALS;
+ a->a_desc = slap_schema.si_ad_objectClass;
+ a->a_nvals = a->a_vals;
+ a->a_numvals = 1;
+ *bptr++ = gluebv;
+ BER_BVZERO(bptr);
+ bptr++;
+ a = a->a_next;
+ a->a_flags = SLAP_ATTR_DONT_FREE_DATA | SLAP_ATTR_DONT_FREE_VALS;
+ a->a_desc = slap_schema.si_ad_structuralObjectClass;
+ a->a_vals = bptr;
+ a->a_nvals = a->a_vals;
+ a->a_numvals = 1;
+ *bptr++ = gluebv;
+ BER_BVZERO(bptr);
*e = r;
return MDB_SUCCESS;
}
return rc;
}
+static Attribute * mdb_attrs_alloc(
+ Operation *op,
+ int nattrs,
+ int nvals )
+{
+ Attribute *a, *s;
+
+ if (!nattrs || !nvals) return NULL;
+
+ s = op->o_tmpalloc( nattrs * sizeof(Attribute) +
+ nvals * sizeof(struct berval), op->o_tmpmemctx );
+
+ for (a=s; nattrs>1; nattrs--) {
+ a->a_next = a+1;
+ a++;
+ }
+ a->a_next = NULL;
+ s->a_vals = (struct berval *)(a+1);
+ return s;
+}
+
+static Entry * mdb_entry_alloc(
+ Operation *op,
+ int nattrs,
+ int nvals )
+{
+ Entry *e = op->o_tmpalloc( sizeof(Entry), op->o_tmpmemctx );
+ BER_BVZERO(&e->e_bv);
+ e->e_attrs = mdb_attrs_alloc( op, nattrs, nvals );
+ e->e_private = e;
+ return e;
+}
+
int mdb_entry_return(
+ Operation *op,
Entry *e
)
{
- entry_free( e );
+ if ( e->e_private ) {
+ op->o_tmpfree( e->e_nname.bv_val, op->o_tmpmemctx );
+ op->o_tmpfree( e->e_name.bv_val, op->o_tmpmemctx );
+ op->o_tmpfree( e->e_attrs, op->o_tmpmemctx );
+ op->o_tmpfree( e, op->o_tmpmemctx );
+ } else {
+ entry_free( e );
+ }
return 0;
}
/* slapMode : SLAP_SERVER_MODE, SLAP_TOOL_MODE,
SLAP_TRUNCATE_MODE, SLAP_UNDEFINED_MODE */
- mdb_entry_return ( e );
+ mdb_entry_return( op, e );
if ( slapMode == SLAP_SERVER_MODE ) {
OpExtra *oex;
LDAP_SLIST_FOREACH( oex, &op->o_extra, oe_next ) {
if( rc != LDAP_SUCCESS ) {
/* free entry */
if ( e )
- mdb_entry_return( e );
+ mdb_entry_return( op, e );
if (moi->moi_ref == 1) {
LDAP_SLIST_REMOVE( &op->o_extra, &moi->moi_oe, OpExtra, oe_next );
nattrs = mdb_entry_getlen(&ptr);
nvals = mdb_entry_getlen(&ptr);
- x = entry_alloc();
+ x = mdb_entry_alloc(op, nattrs, nvals);
x->e_ocflags = mdb_entry_getlen(&ptr);
- x->e_attrs = attrs_alloc( nattrs );
- x->e_bv.bv_len = nvals * sizeof(struct berval);
- x->e_bv.bv_val = op->o_tmpalloc(x->e_bv.bv_len, op->o_tmpmemctx);
- bptr = (BerVarray) x->e_bv.bv_val;
-
+ if (!nvals) {
+ goto done;
+ }
a = x->e_attrs;
+ bptr = a->a_vals;
while ((i = mdb_entry_getlen(&ptr))) {
a->a_desc = mdb->mi_ads[i];
if ( !nattrs )
break;
}
+done:
Debug(LDAP_DEBUG_TRACE, "<= mdb_entry_decode\n",
0, 0, 0 );
return LDAP_INSUFFICIENT_ACCESS;
}
- /* save_attrs will be disposed of by mdb_cache_modify */
+ /* save_attrs will be disposed of by caller */
save_attrs = e->e_attrs;
e->e_attrs = attrs_dup( e->e_attrs );
} else {
rs->sr_ref = NULL;
}
- mdb_entry_return( e );
+ mdb_entry_return( op, e );
e = NULL;
} else {
}
if( e != NULL ) {
- mdb_entry_return( e );
+ mdb_entry_return( op, e );
}
if( preread_ctrl != NULL && (*preread_ctrl) != NULL ) {
} else {
rs->sr_ref = NULL;
}
- mdb_entry_return( e );
+ mdb_entry_return( op, e );
e = NULL;
} else {
}
parent_is_leaf = 1;
}
- mdb_entry_return( p );
+ mdb_entry_return( op, p );
p = NULL;
}
/* LDAP v3 Support */
if( np != NULL ) {
/* free new parent */
- mdb_entry_return( np );
+ mdb_entry_return( op, np );
}
if( p != NULL ) {
/* free parent */
- mdb_entry_return( p );
+ mdb_entry_return( op, p );
}
/* free entry */
if( e != NULL ) {
- mdb_entry_return( e );
+ mdb_entry_return( op, e );
}
if( moi == &opinfo ) {
ID id,
Entry **e);
-void mdb_entry_free ( Entry *e );
-int mdb_entry_return( Entry *e );
+int mdb_entry_return( Operation *op, Entry *e );
BI_entry_release_rw mdb_entry_release;
BI_entry_get_rw mdb_entry_get;
}
}
- mdb_entry_return( e );
+ mdb_entry_return( op, e );
e = NULL;
}
LDAP_SLIST_REMOVE( &op->o_extra, &moi->moi_oe, OpExtra, oe_next );
}
if ( e )
- mdb_entry_return( e );
+ mdb_entry_return( op, e );
return rc;
}
/* Free the previous entry, continue to work with the
* one we just retrieved.
*/
- mdb_entry_return( *matched );
+ mdb_entry_return( op, *matched );
/* We found a regular entry. Return this to the caller.
*/
if (first) {
first = 0;
} else {
- mdb_entry_return( e );
+ mdb_entry_return( op, e );
}
/* Dereference all of the aliases in the current scope. */
* turned into a range that spans IDs indiscriminately
*/
if (!is_entry_alias(a)) {
- mdb_entry_return (a);
+ mdb_entry_return(op, a);
continue;
}
if (mdb_idl_insert(scopes, a->e_id) == 0) {
mdb_idl_insert(newsubs, a->e_id);
}
- mdb_entry_return( a );
+ mdb_entry_return( op, a );
} else if (matched) {
/* Alias could not be dereferenced, or it deref'd to
* an ID we've already seen. Ignore it.
*/
- mdb_entry_return( matched );
+ mdb_entry_return( op, matched );
rs->sr_text = NULL;
}
}
if ( e ) {
build_new_dn( &op->o_req_ndn, &e->e_nname, &stub,
op->o_tmpmemctx );
- mdb_entry_return (e);
+ mdb_entry_return(op, e);
matched = NULL;
goto dn2entry_retry;
}
rs->sr_matched = matched_dn.bv_val;
}
- mdb_entry_return (matched);
+ mdb_entry_return(op, matched);
matched = NULL;
if ( erefs ) {
rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
}
- mdb_entry_return(e);
+ mdb_entry_return( op,e);
send_ldap_result( op, rs );
goto done;
}
rs->sr_err = LDAP_REFERRAL;
- mdb_entry_return( e );
+ mdb_entry_return( op, e );
e = NULL;
if ( erefs ) {
( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
{
rs->sr_err = LDAP_ASSERTION_FAILED;
- mdb_entry_return(e);
+ mdb_entry_return( op,e);
send_ldap_result( op, rs );
goto done;
}
send_search_reference( op, rs );
- mdb_entry_return( e );
+ mdb_entry_return( op, e );
rs->sr_entry = NULL;
e = NULL;
/* check size limit */
if ( get_pagedresults(op) > SLAP_CONTROL_IGNORED ) {
if ( rs->sr_nentries >= ((PagedResultsState *)op->o_pagedresults_state)->ps_size ) {
- mdb_entry_return( e );
+ mdb_entry_return( op, e );
e = NULL;
send_paged_response( op, rs, &lastid, tentries );
goto done;
rs->sr_attrs = NULL;
rs->sr_entry = NULL;
if (e != base)
- mdb_entry_return( e );
+ mdb_entry_return( op, e );
e = NULL;
switch ( rs->sr_err ) {
loop_continue:
if( e != NULL ) {
if ( e != base )
- mdb_entry_return( e );
+ mdb_entry_return( op, e );
RS_ASSERT( rs->sr_entry == NULL );
e = NULL;
rs->sr_entry = NULL;
rs->sr_v2ref = NULL;
}
if (base)
- mdb_entry_return(base);
+ mdb_entry_return( op,base);
return rs->sr_err;
}
rc = mdb_id2name( &op, txn, &idcursor, id, &dn, &ndn );
if ( rc ) {
rc = LDAP_OTHER;
- mdb_entry_return( e );
+ mdb_entry_return( &op, e );
e = NULL;
goto done;
}