/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2000-2005 The OpenLDAP Foundation.
+ * Copyright 2000-2006 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
struct berval *np_ndn = NULL; /* newSuperior ndn */
struct berval *new_parent_dn = NULL; /* np_dn, p_dn, or NULL */
- /* Used to interface with bdb_modify_internal() */
- Modifications *mod = NULL; /* Used to delete old rdn */
-
int manageDSAit = get_manageDSAit( op );
u_int32_t locker = 0;
op->o_req_dn.bv_val,op->oq_modrdn.rs_newrdn.bv_val,
op->oq_modrdn.rs_newSup ? op->oq_modrdn.rs_newSup->bv_val : "NULL" );
+ if ( !SLAP_SHADOW( op->o_bd ))
+ slap_mods_opattrs( op, &op->orr_modlist, 1 );
+
if( 0 ) {
retry: /* transaction retry */
if ( dummy.e_attrs ) {
}
}
- /* prepare modlist of modifications from old/new rdn */
- if (!mod) {
- rs->sr_err = slap_modrdn2mods( op, rs, e, old_rdn, new_rdn, &mod );
- if ( rs->sr_err != LDAP_SUCCESS ) {
- goto return_results;
- }
- }
+ assert( op->orr_modlist != NULL );
if( op->o_preread ) {
if( preread_ctrl == NULL ) {
dummy.e_attrs = e->e_attrs;
/* modify entry */
- rs->sr_err = bdb_modify_internal( op, lt2, &mod[0], &dummy,
+ rs->sr_err = bdb_modify_internal( op, lt2, op->orr_modlist, &dummy,
&rs->sr_text, textbuf, textlen );
if( rs->sr_err != LDAP_SUCCESS ) {
Debug(LDAP_DEBUG_TRACE,
ldap_rdnfree_x( old_rdn, op->o_tmpmemctx );
}
- if( mod != NULL ) {
- slap_modrdn2mods_free( mod );
- }
-
/* LDAP v3 Support */
if( np != NULL ) {
/* free new parent and reader lock */
struct berval *np_ndn = NULL; /* newSuperior ndn */
struct berval *new_parent_dn = NULL; /* np_dn, p_dn, or NULL */
/* Used to interface with ldbm_modify_internal() */
- Modifications *mod = NULL; /* Used to delete old/add new rdn */
int manageDSAit = get_manageDSAit( op );
Debug( LDAP_DEBUG_TRACE,
( op->oq_modrdn.rs_newSup && op->oq_modrdn.rs_newSup->bv_len )
? op->oq_modrdn.rs_newSup->bv_val : "NULL", 0 );
+ if ( !SLAP_SHADOW( op->o_bd ))
+ slap_mods_opattrs( op, &op->orr_modlist, 1 );
+
/* grab giant lock for writing */
ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: DN_X500\n",
0, 0, 0 );
- if ( slap_modrdn2mods( op, rs, e, old_rdn, new_rdn, &mod ) != LDAP_SUCCESS ) {
- send_ldap_result( op, rs );
- goto return_results;
- }
+ assert( op->orr_modlist != NULL );
/* check for abandon */
if ( op->o_abandon ) {
*/
/* modify memory copy of entry */
- rs->sr_err = ldbm_modify_internal( op, &mod[0], e,
+ rs->sr_err = ldbm_modify_internal( op, op->orr_modlist, e,
&rs->sr_text, textbuf, textlen );
switch ( rs->sr_err ) {
case LDAP_SUCCESS:
if ( old_rdn != NULL ) {
ldap_rdnfree( old_rdn );
}
- if ( mod != NULL ) {
- slap_modrdn2mods_free( mod );
- }
/* LDAP v3 Support */
if( np != NULL ) {
struct berval new_dn = BER_BVNULL, new_ndn = BER_BVNULL;
struct berval p_dn;
Entry * entry = NULL;
- LDAPRDN new_rdn = NULL;
- LDAPRDN old_rdn = NULL;
- Modifications * mods = NULL;
int res;
ldap_pvt_thread_mutex_lock( &ni->li_mutex );
/* build the mods to the entry */
if ( entry != NULL ) {
- if ( ldap_bv2rdn( &op->oq_modrdn.rs_newrdn, &new_rdn,
- (char **)&rs->sr_text, LDAP_DN_FORMAT_LDAP ) )
- {
- rs->sr_err = LDAP_INVALID_DN_SYNTAX;
- } else if ( op->oq_modrdn.rs_deleteoldrdn &&
- ldap_bv2rdn(&op->o_req_dn, &old_rdn, (char **)&rs->sr_text,
- LDAP_DN_FORMAT_LDAP ) )
- {
- rs->sr_err = LDAP_OTHER;
+ /* build new dn, and new ndn for the entry */
+ if ( op->oq_modrdn.rs_newSup != NULL ) {
+ /* new superior */
+ p_dn = *op->oq_modrdn.rs_newSup;
} else {
- /* got both rdns successfully, ready to build mods */
- if ( slap_modrdn2mods( op, rs, entry, old_rdn, new_rdn, &mods )
- != LDAP_SUCCESS )
- {
- rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
- } else {
- /* built mods successfully */
-
- /* build new dn, and new ndn for the entry */
- if ( op->oq_modrdn.rs_newSup != NULL ) {
- /* new superior */
- p_dn = *op->oq_modrdn.rs_newSup;
- } else {
- p_dn = slap_empty_bv;
- }
- dnParent( &entry->e_name, &p_dn );
- build_new_dn( &new_dn, &p_dn, &op->oq_modrdn.rs_newrdn, NULL );
- dnNormalize( 0, NULL, NULL, &new_dn, &new_ndn, NULL );
- ber_memfree_x( entry->e_name.bv_val, NULL );
- ber_memfree_x( entry->e_nname.bv_val, NULL );
- entry->e_name = new_dn;
- entry->e_nname = new_ndn;
-
- /* perform the modifications */
- res = apply_modify_to_entry( entry, mods, op, rs );
- slap_modrdn2mods_free( mods );
- if ( res == LDAP_SUCCESS ) {
- rs->sr_err = move_entry( entry, &op->o_req_ndn,
- &new_ndn,
- &op->o_bd->be_nsuffix[0],
- &ni->li_base_path );
- } else {
- rs->sr_err = res;
- }
- }
+ p_dn = slap_empty_bv;
}
-
- if ( new_rdn != NULL ) {
- ldap_rdnfree( new_rdn );
- }
-
- if ( old_rdn != NULL ) {
- ldap_rdnfree( old_rdn );
+ dnParent( &entry->e_name, &p_dn );
+ build_new_dn( &new_dn, &p_dn, &op->oq_modrdn.rs_newrdn, NULL );
+ dnNormalize( 0, NULL, NULL, &new_dn, &new_ndn, NULL );
+ ber_memfree_x( entry->e_name.bv_val, NULL );
+ ber_memfree_x( entry->e_nname.bv_val, NULL );
+ entry->e_name = new_dn;
+ entry->e_nname = new_ndn;
+
+ /* perform the modifications */
+ res = apply_modify_to_entry( entry, op->orr_modlist, op, rs );
+ if ( res == LDAP_SUCCESS ) {
+ rs->sr_err = move_entry( entry, &op->o_req_ndn,
+ &new_ndn,
+ &op->o_bd->be_nsuffix[0],
+ &ni->li_base_path );
+ } else {
+ rs->sr_err = res;
}
} else {
/* entry was null */
n = { 0 },
*e = NULL;
int manageDSAit = get_manageDSAit( op );
- Modifications *mod = NULL;
struct berval *newSuperior = op->oq_modrdn.rs_newSup;
char *next;
}
}
- rs->sr_err = slap_modrdn2mods( op, rs, &r, old_rdn, new_rdn, &mod );
- if ( rs->sr_err != LDAP_SUCCESS ) {
- e = &r;
- goto done;
- }
+ assert( op->orr_modlist != NULL );
oc = backsql_id2oc( bi, e_id.eid_oc_id );
- rs->sr_err = backsql_modify_internal( op, rs, dbh, oc, &e_id, mod );
+ rs->sr_err = backsql_modify_internal( op, rs, dbh, oc, &e_id, op->orr_modlist );
slap_graduate_commit_csn( op );
if ( rs->sr_err != LDAP_SUCCESS ) {
e = &r;
ldap_rdnfree( old_rdn );
}
- if ( mod != NULL ) {
- slap_modrdn2mods_free( mod );
- }
-
if ( !BER_BVISNULL( &e_id.eid_ndn ) ) {
(void)backsql_free_entryID( op, &e_id, 0 );
}
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1998-2005 The OpenLDAP Foundation.
+ * Copyright 1998-2006 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
/* FIXME: temporary? */
op->orr_deleteoldrdn = deloldrdn;
+ /* prepare modlist of modifications from old/new RDN */
+ rs->sr_err = slap_modrdn2mods( op, rs );
+ if ( rs->sr_err != LDAP_SUCCESS ) {
+ send_ldap_result( op, rs );
+ goto cleanup;
+ }
+
op->o_bd = frontendDB;
rs->sr_err = frontendDB->be_modrdn( op, rs );
op->o_tmpfree( op->orr_newrdn.bv_val, op->o_tmpmemctx );
op->o_tmpfree( op->orr_nnewrdn.bv_val, op->o_tmpmemctx );
+ if ( op->orr_modlist != NULL )
+ slap_mods_free( op->orr_modlist, 1 );
+
if ( !BER_BVISNULL( &pnewSuperior ) )
op->o_tmpfree( pnewSuperior.bv_val, op->o_tmpmemctx );
if ( !BER_BVISNULL( &nnewSuperior ) )
Backend *newSuperior_be = NULL;
int manageDSAit;
struct berval pdn = BER_BVNULL;
- BackendDB *op_be;
+ BackendDB *op_be;
if( op->o_req_ndn.bv_len == 0 ) {
Debug( LDAP_DEBUG_ANY, "do_modrdn: root dse!\n", 0, 0, 0 );
int
slap_modrdn2mods(
Operation *op,
- SlapReply *rs,
- Entry *e,
- LDAPRDN old_rdn,
- LDAPRDN new_rdn,
- Modifications **pmod )
+ SlapReply *rs )
{
- Modifications *mod = NULL;
int a_cnt, d_cnt;
- int repl_user;
-
- assert( new_rdn != NULL );
- assert( !op->orr_deleteoldrdn || old_rdn != NULL );
+ LDAPRDN old_rdn = NULL;
+ LDAPRDN new_rdn = NULL;
+
+ assert( !BER_BVISEMPTY( &op->oq_modrdn.rs_newrdn ) );
+ assert( !op->orr_deleteoldrdn || !BER_BVISEMPTY( &op->o_req_dn ) );
+
+ if ( ldap_bv2rdn_x( &op->oq_modrdn.rs_newrdn, &new_rdn,
+ (char **)&rs->sr_text, LDAP_DN_FORMAT_LDAP, op->o_tmpmemctx ) ) {
+ Debug( LDAP_DEBUG_TRACE,
+ LDAP_XSTRING(slap_modrdn2mods) ": can't figure out "
+ "type(s)/value(s) of newrdn\n", 0, 0, 0 );
+ rs->sr_err = LDAP_INVALID_DN_SYNTAX;
+ rs->sr_text = "unknown type(s) used in RDN";
+ goto done;
+ }
- repl_user = be_isupdate( op );
+ if ( op->oq_modrdn.rs_deleteoldrdn ) {
+ if ( ldap_bv2rdn_x( &op->o_req_dn, &old_rdn,
+ (char **)&rs->sr_text, LDAP_DN_FORMAT_LDAP, op->o_tmpmemctx ) ) {
+ Debug( LDAP_DEBUG_TRACE,
+ LDAP_XSTRING(slap_modrdn2mods) ": can't figure out "
+ "type(s)/value(s) of oldrdn\n", 0, 0, 0 );
+ rs->sr_err = LDAP_OTHER;
+ rs->sr_text = "cannot parse RDN from old DN";
+ goto done;
+ }
+ }
/* Add new attribute values to the entry */
for ( a_cnt = 0; new_rdn[a_cnt]; a_cnt++ ) {
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
- "slap_modrdn2modlist: %s: %s (new)\n",
+ "slap_modrdn2mods: %s: %s (new)\n",
rs->sr_text,
new_rdn[ a_cnt ]->la_attr.bv_val, 0 );
goto done;
}
- /* ACL check of newly added attrs */
- if ( op->o_bd && !access_allowed( op, e, desc,
- &new_rdn[a_cnt]->la_value, ACL_WADD, NULL ) ) {
- Debug( LDAP_DEBUG_TRACE,
- "slap_modrdn2modlist: access to attr \"%s\" "
- "(new) not allowed\n",
- new_rdn[ a_cnt ]->la_attr.bv_val, 0, 0 );
- rs->sr_text = "access to naming attributes (new) not allowed";
- rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
- goto done;
- }
-
/* Apply modification */
- mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications )
- + 4 * sizeof( struct berval ) );
+ mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications ) );
mod_tmp->sml_desc = desc;
- mod_tmp->sml_values = ( BerVarray )( mod_tmp + 1 );
- mod_tmp->sml_values[0] = new_rdn[a_cnt]->la_value;
+ mod_tmp->sml_values = ( BerVarray )ch_malloc( 2 * sizeof( struct berval ) );
+ ber_dupbv( &mod_tmp->sml_values[0], &new_rdn[a_cnt]->la_value );
mod_tmp->sml_values[1].bv_val = NULL;
if( desc->ad_type->sat_equality->smr_normalize) {
- mod_tmp->sml_nvalues = &mod_tmp->sml_values[2];
+ mod_tmp->sml_nvalues = ( BerVarray )ch_malloc( 2 * sizeof( struct berval ) );
(void) (*desc->ad_type->sat_equality->smr_normalize)(
SLAP_MR_EQUALITY|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
desc->ad_type->sat_syntax,
}
mod_tmp->sml_op = SLAP_MOD_SOFTADD;
mod_tmp->sml_flags = SLAP_MOD_INTERNAL;
- mod_tmp->sml_next = mod;
- mod = mod_tmp;
+ mod_tmp->sml_next = op->orr_modlist;
+ op->orr_modlist = mod_tmp;
}
/* Remove old rdn value if required */
rs->sr_err = slap_bv2ad( &old_rdn[d_cnt]->la_attr, &desc, &rs->sr_text );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
- "slap_modrdn2modlist: %s: %s (old)\n",
+ "slap_modrdn2mods: %s: %s (old)\n",
rs->sr_text,
old_rdn[d_cnt]->la_attr.bv_val,
0 );
goto done;
}
- /* ACL check of old rdn attrs removal */
- if ( op->o_bd && !access_allowed( op, e, desc,
- &old_rdn[d_cnt]->la_value, ACL_WDEL,
- NULL ) ) {
- Debug( LDAP_DEBUG_TRACE,
- "slap_modrdn2modlist: access "
- "to attr \"%s\" (old) not allowed\n",
- old_rdn[ d_cnt ]->la_attr.bv_val,
- 0, 0 );
- rs->sr_text = "access to naming attributes (old) not allowed";
- rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
- goto done;
- }
-
/* Apply modification */
- mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications )
- + 4 * sizeof ( struct berval ) );
+ mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications ) );
mod_tmp->sml_desc = desc;
- mod_tmp->sml_values = ( BerVarray )(mod_tmp+1);
- mod_tmp->sml_values[0] = old_rdn[d_cnt]->la_value;
+ mod_tmp->sml_values = ( BerVarray )ch_malloc( 2 * sizeof( struct berval ) );
+ ber_dupbv( &mod_tmp->sml_values[0], &old_rdn[d_cnt]->la_value );
mod_tmp->sml_values[1].bv_val = NULL;
if( desc->ad_type->sat_equality->smr_normalize) {
- mod_tmp->sml_nvalues = &mod_tmp->sml_values[2];
+ mod_tmp->sml_nvalues = ( BerVarray )ch_malloc( 2 * sizeof( struct berval ) );
(void) (*desc->ad_type->sat_equality->smr_normalize)(
SLAP_MR_EQUALITY|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
desc->ad_type->sat_syntax,
desc->ad_type->sat_equality,
&mod_tmp->sml_values[0],
- &mod_tmp->sml_nvalues[0], op->o_tmpmemctx );
+ &mod_tmp->sml_nvalues[0], NULL );
mod_tmp->sml_nvalues[1].bv_val = NULL;
} else {
mod_tmp->sml_nvalues = NULL;
}
mod_tmp->sml_op = LDAP_MOD_DELETE;
mod_tmp->sml_flags = SLAP_MOD_INTERNAL;
- mod_tmp->sml_next = mod;
- mod = mod_tmp;
+ mod_tmp->sml_next = op->orr_modlist;
+ op->orr_modlist = mod_tmp;
}
}
done:
+#if 0
+ /* should be done by backend */
if ( rs->sr_err == LDAP_SUCCESS && !repl_user ) {
- slap_mods_opattrs( op, &mod, 1 );
+ slap_mods_opattrs( op, &op->orr_modlist, 1 );
}
+#endif
/* LDAP v2 supporting correct attribute handling. */
- if ( rs->sr_err != LDAP_SUCCESS && mod != NULL ) {
+ if ( rs->sr_err != LDAP_SUCCESS && op->orr_modlist != NULL ) {
Modifications *tmp;
- for ( ; mod; mod = tmp ) {
- tmp = mod->sml_next;
- ch_free( mod );
- }
- }
-
- *pmod = mod;
-
- return rs->sr_err;
-}
-void
-slap_modrdn2mods_free( Modifications *mod )
-{
- Modifications *tmp;
-
- for ( ; mod; mod = tmp ) {
- tmp = mod->sml_next;
- /* slap_modrdn2mods does things one way,
- * slap_mods_opattrs does it differently
- */
- if ( mod->sml_op != SLAP_MOD_SOFTADD &&
- mod->sml_op != LDAP_MOD_DELETE )
- {
- break;
- }
-
- if ( mod->sml_nvalues ) {
- free( mod->sml_nvalues[0].bv_val );
+ for ( ; op->orr_modlist != NULL; op->orr_modlist = tmp ) {
+ tmp = op->orr_modlist->sml_next;
+ ch_free( op->orr_modlist );
}
+ }
- free( mod );
+ if ( new_rdn != NULL ) {
+ ldap_rdnfree_x( new_rdn, op->o_tmpmemctx );
+ }
+ if ( old_rdn != NULL ) {
+ ldap_rdnfree_x( old_rdn, op->o_tmpmemctx );
}
- slap_mods_free( mod, 1 );
+ return rs->sr_err;
}
*/
LDAP_SLAPD_F (int) slap_modrdn2mods LDAP_P((
Operation *op,
- SlapReply *rs,
- Entry *e,
- LDAPRDN oldrdn,
- LDAPRDN newrdn,
- Modifications **pmod ));
-
-LDAP_SLAPD_F (void) slap_modrdn2mods_free LDAP_P(( Modifications *mod ));
+ SlapReply *rs ));
/*
* modify.c
#define ATTR_CHAR(c) ( DESC_CHAR((c)) || OID_SEPARATOR(c) )
#define AD_LEADCHAR(c) ( ATTR_LEADCHAR(c) )
-#define AD_CHAR(c) ( ATTR_CHAR(c) || (c) == ';' )
+#define AD_CHAR(c) ( ATTR_CHAR(c) || (c) == ';' || (c) == '=' || (c) == '*' )
#define SLAP_NUMERIC(c) ( ASCII_DIGIT(c) || ASCII_SPACE(c) )
struct berval *rs_newSup;
struct berval *rs_nnewSup;
int rs_deleteoldrdn;
+ Modifications *rs_modlist;
} req_modrdn_s;
typedef struct req_add_s {
#define orr_newSup oq_modrdn.rs_newSup
#define orr_nnewSup oq_modrdn.rs_nnewSup
#define orr_deleteoldrdn oq_modrdn.rs_deleteoldrdn
+#define orr_modlist oq_modrdn.rs_modlist
#define orc_ava oq_compare.rs_ava
#define ora_e oq_add.rs_e
op->o_tmpfree( op->orr_nnewSup->bv_val, op->o_tmpmemctx );
op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx );
}
+ slap_mods_free( op->orr_modlist, 1 );
break;
case LDAP_REQ_ADD:
slap_mods_free( op->ora_modlist, 0 );
slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID, (void *)uniqueid );
slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS, (void *)&operation_flags );
+ slap_modrdn2mods( pb->pb_op, pb->pb_rs );
slapi_int_set_operation_dn( pb );
}
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2002-2005 The OpenLDAP Foundation.
+ * Copyright 2002-2006 The OpenLDAP Foundation.
* Portions Copyright 1997,2002-2003 IBM Corporation.
* All rights reserved.
*
break;
case SLAPI_MODIFY_MODS: {
LDAPMod **mods = NULL;
+ Modifications *ml;
pblock_get_default( pb, param, (void **)&mods );
if ( mods == NULL && pb->pb_intop == 0 ) {
- if ( pb->pb_op->o_tag != LDAP_REQ_MODIFY ) {
+ switch ( pb->pb_op->o_tag ) {
+ case LDAP_REQ_MODIFY:
+ ml = pb->pb_op->orm_modlist;
+ break;
+ case LDAP_REQ_MODRDN:
+ ml = pb->pb_op->orr_modlist;
+ break;
+ defaulat:
rc = PBLOCK_ERROR;
break;
}
- mods = slapi_int_modifications2ldapmods( pb->pb_op->orm_modlist );
+ mods = slapi_int_modifications2ldapmods( ml );
pblock_set_default( pb, param, (void *)mods );
}
*((LDAPMod ***)value) = mods;
mlp = &pb->pb_op->orm_modlist;
} else if ( pb->pb_op->o_tag == LDAP_REQ_ADD ) {
mlp = &pb->pb_op->ora_modlist;
+ } else if ( pb->pb_op->o_tag == LDAP_REQ_MODRDN ) {
+ mlp = &pb->pb_op->orr_modlist;
} else {
break;
}
op->orr_newrdn = prdn;
op->orr_nnewrdn = nrdn;
op->orr_deleteoldrdn = deleteOldRdn;
+ if ( slap_modrdn2mods( op, &rs ))
+ goto done;
rc = op->o_bd->be_modrdn( op, &rs );
+ slap_mods_free( op->orr_modlist, 1 );
break;
case LDAP_REQ_DELETE:
rc = op->o_bd->be_delete( op, &rs );