/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2000-2008 The OpenLDAP Foundation.
+ * Copyright 2000-2011 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
BER_BVNULL
};
+static void
+bdb_modify_idxflags(
+ Operation *op,
+ AttributeDescription *desc,
+ int got_delete,
+ Attribute *newattrs,
+ Attribute *oldattrs )
+{
+ struct berval ix_at;
+ AttrInfo *ai;
+
+ /* check if modified attribute was indexed
+ * but not in case of NOOP... */
+ ai = bdb_index_mask( op->o_bd, desc, &ix_at );
+ if ( ai ) {
+ if ( got_delete ) {
+ Attribute *ap;
+ struct berval ix2;
+
+ ap = attr_find( oldattrs, desc );
+ if ( ap ) ap->a_flags |= SLAP_ATTR_IXDEL;
+
+ /* Find all other attrs that index to same slot */
+ for ( ap = newattrs; ap; ap = ap->a_next ) {
+ ai = bdb_index_mask( op->o_bd, ap->a_desc, &ix2 );
+ if ( ai && ix2.bv_val == ix_at.bv_val )
+ ap->a_flags |= SLAP_ATTR_IXADD;
+ }
+
+ } else {
+ Attribute *ap;
+
+ ap = attr_find( newattrs, desc );
+ if ( ap ) ap->a_flags |= SLAP_ATTR_IXADD;
+ }
+ }
+}
+
int bdb_modify_internal(
Operation *op,
DB_TXN *tid,
Attribute *ap;
int glue_attr_delete = 0;
int got_delete;
- AttrInfo *ai;
Debug( LDAP_DEBUG_TRACE, "bdb_modify_internal: 0x%08lx: %s\n",
e->e_id, e->e_dn, 0);
}
for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
- struct berval ix_at;
mod = &ml->sml_mod;
got_delete = 0;
mod->sm_desc->ad_cname.bv_val, 0, 0);
err = modify_delete_values( e, mod, get_permissiveModify(op),
text, textbuf, textlen );
- assert( err != LDAP_TYPE_OR_VALUE_EXISTS );
if( err != LDAP_SUCCESS ) {
Debug(LDAP_DEBUG_ARGS, "bdb_modify_internal: %d %s\n",
err, *text, 0);
}
break;
+ case SLAP_MOD_SOFTDEL:
+ Debug(LDAP_DEBUG_ARGS,
+ "bdb_modify_internal: softdel %s\n",
+ mod->sm_desc->ad_cname.bv_val, 0, 0);
+ /* Avoid problems in index_delete_mods()
+ * We need to add index if necessary.
+ */
+ mod->sm_op = LDAP_MOD_DELETE;
+
+ err = modify_delete_values( e, mod, get_permissiveModify(op),
+ text, textbuf, textlen );
+
+ mod->sm_op = SLAP_MOD_SOFTDEL;
+
+ if ( err == LDAP_NO_SUCH_ATTRIBUTE ) {
+ err = LDAP_SUCCESS;
+ }
+
+ if( err != LDAP_SUCCESS ) {
+ Debug(LDAP_DEBUG_ARGS, "bdb_modify_internal: %d %s\n",
+ err, *text, 0);
+ }
+ break;
+
+ case SLAP_MOD_ADD_IF_NOT_PRESENT:
+ if ( attr_find( e->e_attrs, mod->sm_desc ) != NULL ) {
+ /* skip */
+ err = LDAP_SUCCESS;
+ break;
+ }
+
+ Debug(LDAP_DEBUG_ARGS,
+ "bdb_modify_internal: add_if_not_present %s\n",
+ mod->sm_desc->ad_cname.bv_val, 0, 0);
+ /* Avoid problems in index_add_mods()
+ * We need to add index if necessary.
+ */
+ mod->sm_op = LDAP_MOD_ADD;
+
+ err = modify_add_values( e, mod, get_permissiveModify(op),
+ text, textbuf, textlen );
+
+ mod->sm_op = SLAP_MOD_ADD_IF_NOT_PRESENT;
+
+ if( err != LDAP_SUCCESS ) {
+ Debug(LDAP_DEBUG_ARGS, "bdb_modify_internal: %d %s\n",
+ err, *text, 0);
+ }
+ break;
+
default:
Debug(LDAP_DEBUG_ANY, "bdb_modify_internal: invalid op %d\n",
mod->sm_op, 0, 0);
if ( glue_attr_delete ) e->e_ocflags = 0;
+
/* check if modified attribute was indexed
* but not in case of NOOP... */
- ai = bdb_index_mask( op->o_bd, mod->sm_desc, &ix_at );
- if ( ai && !op->o_noop ) {
- if ( got_delete ) {
- struct berval ix2;
-
- ap = attr_find( save_attrs, mod->sm_desc );
- if ( ap ) ap->a_flags |= SLAP_ATTR_IXDEL;
-
- /* Find all other attrs that index to same slot */
- for ( ap = e->e_attrs; ap; ap=ap->a_next ) {
- ai = bdb_index_mask( op->o_bd, ap->a_desc, &ix2 );
- if ( ai && ix2.bv_val == ix_at.bv_val )
- ap->a_flags |= SLAP_ATTR_IXADD;
- }
- } else {
- ap = attr_find( e->e_attrs, mod->sm_desc );
- if ( ap ) ap->a_flags |= SLAP_ATTR_IXADD;
- }
+ if ( !op->o_noop ) {
+ bdb_modify_idxflags( op, mod->sm_desc, got_delete, e->e_attrs, save_attrs );
}
}
/* check that the entry still obeys the schema */
- rc = entry_schema_check( op, e, save_attrs, get_relax(op), 0,
+ ap = NULL;
+ rc = entry_schema_check( op, e, save_attrs, get_relax(op), 0, &ap,
text, textbuf, textlen );
if ( rc != LDAP_SUCCESS || op->o_noop ) {
attrs_free( e->e_attrs );
return rc;
}
+ /* structuralObjectClass modified! */
+ if ( ap ) {
+ assert( ap->a_desc == slap_schema.si_ad_structuralObjectClass );
+ if ( !op->o_noop ) {
+ bdb_modify_idxflags( op, slap_schema.si_ad_structuralObjectClass,
+ 1, e->e_attrs, save_attrs );
+ }
+ }
+
/* update the indices of the modified attributes */
/* start with deleting the old index entries */
if ( a2 ) {
/* need to detect which values were deleted */
int i, j;
- struct berval tmp;
- j = ap->a_numvals;
- for ( i=0; i<j; ) {
+ vals = op->o_tmpalloc( (ap->a_numvals + 1) *
+ sizeof(struct berval), op->o_tmpmemctx );
+ j = 0;
+ for ( i=0; i < ap->a_numvals; i++ ) {
rc = attr_valfind( a2, SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
&ap->a_nvals[i], NULL, op->o_tmpmemctx );
- /* Move deleted values to end of array */
- if ( rc == LDAP_NO_SUCH_ATTRIBUTE ) {
- j--;
- if ( i != j ) {
- tmp = ap->a_nvals[j];
- ap->a_nvals[j] = ap->a_nvals[i];
- ap->a_nvals[i] = tmp;
- tmp = ap->a_vals[j];
- ap->a_vals[j] = ap->a_vals[i];
- ap->a_vals[i] = tmp;
- }
- continue;
- }
- i++;
+ /* Save deleted values */
+ if ( rc == LDAP_NO_SUCH_ATTRIBUTE )
+ vals[j++] = ap->a_nvals[i];
}
- vals = &ap->a_nvals[j];
+ BER_BVZERO(vals+j);
} else {
/* attribute was completely deleted */
vals = ap->a_nvals;
}
+ rc = 0;
if ( !BER_BVISNULL( vals )) {
rc = bdb_index_values( op, tid, ap->a_desc,
vals, e->e_id, SLAP_INDEX_DELETE_OP );
op->o_log_prefix, ap->a_desc->ad_cname.bv_val, 0 );
attrs_free( e->e_attrs );
e->e_attrs = save_attrs;
- return rc;
}
}
+ if ( vals != ap->a_nvals )
+ op->o_tmpfree( vals, op->o_tmpmemctx );
+ if ( rc ) return rc;
}
}
DB_TXN *ltid = NULL, *lt2;
struct bdb_op_info opinfo = {{{ 0 }}};
Entry dummy = {0};
- int fakeroot = 0;
DB_LOCK lock;
ctrls[num_ctrls] = NULL;
- slap_mods_opattrs( op, &op->orm_modlist, 1 );
+ /* Don't touch the opattrs, if this is a contextCSN update
+ * initiated from updatedn */
+ if ( !be_isupdate(op) || !op->orm_modlist || op->orm_modlist->sml_next ||
+ op->orm_modlist->sml_desc != slap_schema.si_ad_contextCSN ) {
+
+ slap_mods_opattrs( op, &op->orm_modlist, 1 );
+ }
if( 0 ) {
retry: /* transaction retry */
case DB_LOCK_NOTGRANTED:
goto retry;
case DB_NOTFOUND:
- if ( BER_BVISEMPTY( &op->o_req_ndn )) {
- struct berval gluebv = BER_BVC("glue");
- e = ch_calloc( 1, sizeof(Entry));
- e->e_name.bv_val = ch_strdup( "" );
- ber_dupbv( &e->e_nname, &e->e_name );
- attr_merge_one( e, slap_schema.si_ad_objectClass,
- &gluebv, NULL );
- attr_merge_one( e, slap_schema.si_ad_structuralObjectClass,
- &gluebv, NULL );
- e->e_private = ei;
- fakeroot = 1;
- rs->sr_err = 0;
- }
break;
case LDAP_BUSY:
rs->sr_text = "ldap server busy";
}
}
- if ( !fakeroot ) {
- e = ei->bei_e;
- }
+ e = ei->bei_e;
/* acquire and lock entry */
/* FIXME: dn2entry() should return non-glue entry */
} else {
/* may have changed in bdb_modify_internal() */
e->e_ocflags = dummy.e_ocflags;
- if ( fakeroot ) {
- e->e_private = NULL;
- entry_free( e );
- e = NULL;
- attrs_free( dummy.e_attrs );
-
- } else {
- rc = bdb_cache_modify( bdb, e, dummy.e_attrs, ltid, &lock );
- switch( rc ) {
- case DB_LOCK_DEADLOCK:
- case DB_LOCK_NOTGRANTED:
- goto retry;
- }
+ rc = bdb_cache_modify( bdb, e, dummy.e_attrs, ltid, &lock );
+ switch( rc ) {
+ case DB_LOCK_DEADLOCK:
+ case DB_LOCK_NOTGRANTED:
+ goto retry;
}
dummy.e_attrs = NULL;