/* modify.c - bdb backend modify routine */
/* $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"
#include "back-bdb.h"
#include "external.h"
-#define INDEXED 0x2000
-#define NULLIFIED 0x4000
+static struct berval scbva[] = {
+ BER_BVC("glue"),
+ BER_BVNULL
+};
int bdb_modify_internal(
Operation *op,
Modifications *ml;
Attribute *save_attrs;
Attribute *ap;
+ int glue_attr_delete = 0;
#ifdef NEW_LOGGING
LDAP_LOG ( OPERATION, ENTRY, "bdb_modify_internal: 0x%08lx: %s\n",
save_attrs = e->e_attrs;
e->e_attrs = attrs_dup( e->e_attrs );
+ for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
+ int match;
+ mod = &ml->sml_mod;
+ switch( mod->sm_op ) {
+ case LDAP_MOD_ADD:
+ case LDAP_MOD_REPLACE:
+ if ( mod->sm_desc == slap_schema.si_ad_structuralObjectClass ) {
+ value_match( &match, slap_schema.si_ad_structuralObjectClass,
+ slap_schema.si_ad_structuralObjectClass->ad_type->sat_equality,
+ SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
+ &mod->sm_values[0], &scbva[0], text );
+ if ( !match )
+ glue_attr_delete = 1;
+ }
+ }
+ if ( glue_attr_delete )
+ break;
+ }
+
+ if ( glue_attr_delete ) {
+ Attribute **app = &e->e_attrs;
+ while ( *app != NULL ) {
+ if ( !is_at_operational( (*app)->a_desc->ad_type )) {
+ Attribute *save = *app;
+ *app = (*app)->a_next;
+ attr_free( save );
+ continue;
+ }
+ app = &(*app)->a_next;
+ }
+ }
+
for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
mod = &ml->sml_mod;
break;
case LDAP_MOD_DELETE:
+ if ( glue_attr_delete )
+ break;
#ifdef NEW_LOGGING
LDAP_LOG ( OPERATION, DETAIL1,
"bdb_modify_internal: delete\n", 0, 0, 0 );
if ( mod->sm_desc == slap_schema.si_ad_objectClass ) {
e->e_ocflags = 0;
}
+
+ if ( glue_attr_delete ) {
+ e->e_ocflags = 0;
+ }
+
+ /* check if modified attribute was indexed
+ * but not in case of NOOP... */
+ err = bdb_index_is_indexed( op->o_bd, mod->sm_desc );
+ if ( err == LDAP_SUCCESS && !op->o_noop ) {
+ ap = attr_find( save_attrs, mod->sm_desc );
+ if ( ap ) ap->a_flags |= SLAP_ATTR_IXDEL;
+
+ ap = attr_find( e->e_attrs, mod->sm_desc );
+ if ( ap ) ap->a_flags |= SLAP_ATTR_IXADD;
+ }
}
/* check that the entry still obeys the schema */
}
/* update the indices of the modified attributes */
- if ( !op->o_noop ) {
- Modifications *m2;
-
- /* First look for any deletes that would nullify any adds
- * in this request. I.e., deleting an entire attribute after
- * assigning some values to it.
- */
- for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
- if (bdb_index_is_indexed( op->o_bd, ml->sml_desc ))
- continue;
- switch ( ml->sml_op ) {
- case LDAP_MOD_DELETE:
- /* If just deleting specific values, ignore */
- if ( ml->sml_bvalues ) break;
- case LDAP_MOD_REPLACE:
- for ( m2 = modlist; m2 != ml; m2 = m2->sml_next ) {
- if ( m2->sml_desc == ml->sml_desc &&
- m2->sml_op != LDAP_MOD_DELETE )
- m2->sml_op |= NULLIFIED;
- }
- break;
+
+ /* start with deleting the old index entries */
+ for ( ap = save_attrs; ap != NULL; ap = ap->a_next ) {
+ if ( ap->a_flags & SLAP_ATTR_IXDEL ) {
+ rc = bdb_index_values( op, tid, ap->a_desc,
+ ap->a_nvals,
+ e->e_id, SLAP_INDEX_DELETE_OP );
+ if ( rc != LDAP_SUCCESS ) {
+ attrs_free( e->e_attrs );
+ e->e_attrs = save_attrs;
+#ifdef NEW_LOGGING
+ LDAP_LOG ( OPERATION, ERR,
+ "bdb_modify_internal: attribute index delete failure\n",
+ 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "Attribute index delete failure",
+ 0, 0, 0 );
+#endif
+ return rc;
}
- ml->sml_op |= INDEXED;
+ ap->a_flags &= ~SLAP_ATTR_IXDEL;
}
- /* Now index the modifications */
- for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
- if ( ! (ml->sml_op & INDEXED) ) continue;
- ml->sml_op ^= INDEXED;
- switch ( ml->sml_op ) {
- case LDAP_MOD_DELETE:
- if ( ml->sml_bvalues ) {
- ap = attr_find( e->e_attrs, ml->sml_desc );
- rc = bdb_index_values( op, tid, ml->sml_desc,
- ml->sml_nvalues ? ml->sml_nvalues : ml->sml_bvalues,
- ap ? ap->a_nvals : NULL,
- e->e_id, SLAP_INDEX_DELETE_OP );
- break;
- }
- /* FALLTHRU */
- case LDAP_MOD_REPLACE:
- /* A nullified replace still does its delete action */
- case LDAP_MOD_REPLACE | NULLIFIED:
- ap = attr_find( save_attrs, ml->sml_desc );
- if ( ap != NULL ) {
- rc = bdb_index_values( op, tid, ap->a_desc,
- ap->a_nvals, NULL,
- e->e_id, SLAP_INDEX_DELETE_OP );
- } else {
- rc = LDAP_SUCCESS;
- }
- if ( rc || ml->sml_op == LDAP_MOD_DELETE ||
- (ml->sml_op & NULLIFIED))
- break;
- /* FALLTHRU */
- case LDAP_MOD_ADD:
- case SLAP_MOD_SOFTADD:
- rc = bdb_index_values( op, tid, ml->sml_desc,
- ml->sml_nvalues ? ml->sml_nvalues : ml->sml_bvalues,
- NULL, e->e_id, SLAP_INDEX_ADD_OP );
- break;
- }
- ml->sml_op &= ~NULLIFIED;
+ }
+
+ /* add the new index entries */
+ for ( ap = e->e_attrs; ap != NULL; ap = ap->a_next ) {
+ if (ap->a_flags & SLAP_ATTR_IXADD) {
+ rc = bdb_index_values( op, tid, ap->a_desc,
+ ap->a_nvals,
+ e->e_id, SLAP_INDEX_ADD_OP );
if ( rc != LDAP_SUCCESS ) {
attrs_free( e->e_attrs );
e->e_attrs = save_attrs;
#ifdef NEW_LOGGING
LDAP_LOG ( OPERATION, ERR,
- "bdb_modify_internal: attribute index update failure\n",
+ "bdb_modify_internal: attribute index add failure\n",
0, 0, 0 );
#else
Debug( LDAP_DEBUG_ANY,
- "Attribute index update failure",
+ "Attribute index add failure",
0, 0, 0 );
#endif
- /* reset our flags */
- for (; ml; ml=ml->sml_next ) {
- ml->sml_op &= ~(INDEXED | NULLIFIED);
- }
- break;
+ return rc;
}
+ ap->a_flags &= ~SLAP_ATTR_IXADD;
}
}
u_int32_t locker = 0;
DB_LOCK lock;
- int noop = 0;
-
int num_retries = 0;
LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
rs->sr_text = "internal error";
goto return_results;
}
- bdb_trans_backoff( ++num_retries );
ldap_pvt_thread_yield();
+ bdb_trans_backoff( ++num_retries );
}
/* begin transaction */
e = NULL;
} else {
- BerVarray deref = op->o_bd->syncinfo ?
- op->o_bd->syncinfo->provideruri_bv : default_referral;
- rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
+ BerVarray deref = NULL;
+ if ( !LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) {
+ syncinfo_t *si;
+ LDAP_STAILQ_FOREACH( si, &op->o_bd->be_syncinfo, si_next ) {
+ struct berval tmpbv;
+ ber_dupbv( &tmpbv, &si->si_provideruri_bv[0] );
+ ber_bvarray_add( &deref, &tmpbv );
+ }
+ } else {
+ deref = default_referral;
+ }
+ rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn,
+ LDAP_SCOPE_DEFAULT );
}
rs->sr_err = LDAP_REFERRAL;
send_ldap_result( op, rs );
- ber_bvarray_free( rs->sr_ref );
+ if ( rs->sr_ref != default_referral ) {
+ ber_bvarray_free( rs->sr_ref );
+ }
free( (char *)rs->sr_matched );
rs->sr_ref = NULL;
rs->sr_matched = NULL;
goto return_results;
}
- if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
+ if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop && !op->o_no_psearch ) {
+ ldap_pvt_thread_rdwr_rlock( &bdb->bi_pslist_rwlock );
LDAP_LIST_FOREACH ( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
bdb_psearch(op, rs, ps_list, e, LDAP_PSEARCH_BY_PREMODIFY );
}
+ ldap_pvt_thread_rdwr_runlock( &bdb->bi_pslist_rwlock );
}
if( op->o_preread ) {
goto return_results;
}
- if ( !op->o_bd->syncinfo ) {
+ if ( LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) {
rc = bdb_csn_commit( op, rs, ltid, ei, &suffix_ei,
&ctxcsn_e, &ctxcsn_added, locker );
switch ( rc ) {
if ( ( rs->sr_err = TXN_ABORT( ltid ) ) != 0 ) {
rs->sr_text = "txn_abort (no-op) failed";
} else {
- noop = 1;
- rs->sr_err = LDAP_SUCCESS;
+ rs->sr_err = LDAP_NO_OPERATION;
+ goto return_results;
}
} else {
- struct berval ctx_nrdn;
- EntryInfo *ctx_ei;
-
bdb_cache_modify( e, dummy.e_attrs, bdb->bi_dbenv, locker, &lock );
- if ( !op->o_bd->syncinfo ) {
+ if ( LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) {
if ( ctxcsn_added ) {
- ctx_nrdn.bv_val = "cn=ldapsync";
- ctx_nrdn.bv_len = strlen( ctx_nrdn.bv_val );
- bdb_cache_add( bdb, suffix_ei, ctxcsn_e, &ctx_nrdn, locker );
+ bdb_cache_add( bdb, suffix_ei, ctxcsn_e,
+ (struct berval *)&slap_ldapsync_cn_bv, locker );
+ }
+ }
+
+ if ( rs->sr_err == LDAP_SUCCESS ) {
+ /* Loop through in-scope entries for each psearch spec */
+ ldap_pvt_thread_rdwr_rlock( &bdb->bi_pslist_rwlock );
+ LDAP_LIST_FOREACH ( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
+ bdb_psearch( op, rs, ps_list, e, LDAP_PSEARCH_BY_MODIFY );
+ }
+ ldap_pvt_thread_rdwr_runlock( &bdb->bi_pslist_rwlock );
+ pm_list = LDAP_LIST_FIRST(&op->o_pm_list);
+ while ( pm_list != NULL ) {
+ bdb_psearch(op, rs, pm_list->ps_op,
+ e, LDAP_PSEARCH_BY_SCOPEOUT);
+ LDAP_LIST_REMOVE ( pm_list, ps_link );
+ pm_prev = pm_list;
+ pm_list = LDAP_LIST_NEXT ( pm_list, ps_link );
+ ch_free( pm_prev );
}
}
return_results:
send_ldap_result( op, rs );
- if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
- /* Loop through in-scope entries for each psearch spec */
- LDAP_LIST_FOREACH ( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
- bdb_psearch( op, rs, ps_list, e, LDAP_PSEARCH_BY_MODIFY );
- }
- pm_list = LDAP_LIST_FIRST(&op->o_pm_list);
- while ( pm_list != NULL ) {
- bdb_psearch(op, rs, pm_list->ps_op,
- e, LDAP_PSEARCH_BY_SCOPEOUT);
- LDAP_LIST_REMOVE ( pm_list, ps_link );
- pm_prev = pm_list;
- pm_list = LDAP_LIST_NEXT ( pm_list, ps_link );
- ch_free( pm_prev );
- }
- }
-
if( rs->sr_err == LDAP_SUCCESS && bdb->bi_txn_cp ) {
ldap_pvt_thread_yield();
TXN_CHECKPOINT( bdb->bi_dbenv,
if( e != NULL ) {
bdb_unlocked_cache_return_entry_w (&bdb->bi_cache, e);
}
- return ( ( rs->sr_err == LDAP_SUCCESS ) ? noop : rs->sr_err );
+ return rs->sr_err;
}