+ assert( new_rdn != NULL );
+ assert( !op->orr_deleteoldrdn || old_rdn != NULL );
+
+ /* Add new attribute values to the entry */
+ for ( a_cnt = 0; new_rdn[a_cnt]; a_cnt++ ) {
+ AttributeDescription *desc = NULL;
+ Modifications *mod_tmp;
+
+ rs->sr_err = slap_bv2ad( &new_rdn[a_cnt]->la_attr, &desc, &rs->sr_text );
+
+ if ( rs->sr_err != LDAP_SUCCESS ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG ( OPERATION, ERR,
+ "slap_modrdn2modlist: %s: %s (new)\n",
+ rs->sr_text,
+ new_rdn[ a_cnt ]->la_attr.bv_val, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "slap_modrdn2modlist: %s: %s (new)\n",
+ rs->sr_text,
+ new_rdn[ a_cnt ]->la_attr.bv_val, 0 );
+#endif
+ goto done;
+ }
+
+ /* ACL check of newly added attrs */
+ if ( op->o_bd && !access_allowed( op, e, desc,
+ &new_rdn[a_cnt]->la_value, ACL_WRITE, NULL ) ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG ( OPERATION, ERR,
+ "slap_modrdn2modlist: access to attr \"%s\" "
+ "(new) not allowed\n",
+ new_rdn[a_cnt]->la_attr.bv_val, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "slap_modrdn2modlist: access to attr \"%s\" "
+ "(new) not allowed\n",
+ new_rdn[ a_cnt ]->la_attr.bv_val, 0, 0 );
+#endif
+ rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
+ goto done;
+ }
+
+ /* Apply modification */
+ mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications )
+ + 4 * sizeof( struct berval ) );
+ 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[1].bv_val = NULL;
+ if( desc->ad_type->sat_equality->smr_normalize) {
+ mod_tmp->sml_nvalues = &mod_tmp->sml_values[2];
+ (void) (*desc->ad_type->sat_equality->smr_normalize)(
+ SLAP_MR_EQUALITY,
+ 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[1].bv_val = NULL;
+ } else {
+ mod_tmp->sml_nvalues = NULL;
+ }
+ mod_tmp->sml_op = SLAP_MOD_SOFTADD;
+ mod_tmp->sml_next = mod;
+ mod = mod_tmp;
+ }
+
+ /* Remove old rdn value if required */
+ if ( op->orr_deleteoldrdn ) {
+ for ( d_cnt = 0; old_rdn[d_cnt]; d_cnt++ ) {
+ AttributeDescription *desc = NULL;
+ Modifications *mod_tmp;
+
+ rs->sr_err = slap_bv2ad( &old_rdn[d_cnt]->la_attr, &desc, &rs->sr_text );
+ if ( rs->sr_err != LDAP_SUCCESS ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG ( OPERATION, ERR,
+ "slap_modrdn2modlist: %s: %s (old)\n",
+ rs->sr_text,
+ old_rdn[d_cnt]->la_attr.bv_val,
+ 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "slap_modrdn2modlist: %s: %s (old)\n",
+ rs->sr_text,
+ old_rdn[d_cnt]->la_attr.bv_val,
+ 0 );
+#endif
+ goto done;
+ }
+
+ /* ACL check of newly added attrs */
+ if ( op->o_bd && !access_allowed( op, e, desc,
+ &old_rdn[d_cnt]->la_value, ACL_WRITE,
+ NULL ) ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG ( OPERATION, ERR,
+ "slap_modrdn2modlist: access "
+ "to attr \"%s\" (old) not allowed\n",
+ old_rdn[ d_cnt ]->la_attr.bv_val,
+ 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "slap_modrdn2modlist: access "
+ "to attr \"%s\" (old) not allowed\n",
+ old_rdn[ d_cnt ]->la_attr.bv_val,
+ 0, 0 );
+#endif
+ rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
+ goto done;
+ }
+
+ /* Apply modification */
+ mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications )
+ + 4 * sizeof ( struct berval ) );
+ 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[1].bv_val = NULL;
+ if( desc->ad_type->sat_equality->smr_normalize) {
+ mod_tmp->sml_nvalues = &mod_tmp->sml_values[2];
+ (void) (*desc->ad_type->sat_equality->smr_normalize)(
+ SLAP_MR_EQUALITY,
+ 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[1].bv_val = NULL;
+ } else {
+ mod_tmp->sml_nvalues = NULL;
+ }
+ mod_tmp->sml_op = LDAP_MOD_DELETE;
+ mod_tmp->sml_next = mod;
+ mod = mod_tmp;
+ }
+ }
+
+done:
+ /* LDAP v2 supporting correct attribute handling. */
+ if ( rs->sr_err != LDAP_SUCCESS && mod != NULL ) {
+ Modifications *tmp;
+ for ( ; mod; mod = tmp ) {
+ tmp = mod->sml_next;
+ ch_free( mod );
+ }
+ }