]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/modrdn.c
Berkeley DB 4.2 support (DB 4.2 required by default)
[openldap] / servers / slapd / modrdn.c
index 52e8b531dedfe917c44ab80a5815c45ddb4dc82b..f63aca9d5637d40e15694d493ac3a6c3991f7034 100644 (file)
@@ -60,10 +60,6 @@ do_modrdn(
        ber_len_t       length;
        int manageDSAit;
 
-#ifdef LDAP_SLAPI
-       Slapi_PBlock *pb = op->o_pb;
-#endif
-
 #ifdef NEW_LOGGING
        LDAP_LOG( OPERATION, ENTRY, "do_modrdn: begin\n", 0, 0, 0 );
 #else
@@ -173,7 +169,7 @@ do_modrdn(
                goto cleanup;
        } 
 
-       rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn );
+       rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
        if( rs->sr_err != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
                LDAP_LOG( OPERATION, INFO, 
@@ -216,7 +212,7 @@ do_modrdn(
 
        /* FIXME: should have/use rdnPretty / rdnNormalize routines */
 
-       rs->sr_err = dnPrettyNormal( NULL, &newrdn, &op->orr_newrdn, &op->orr_nnewrdn );
+       rs->sr_err = dnPrettyNormal( NULL, &newrdn, &op->orr_newrdn, &op->orr_nnewrdn, op->o_tmpmemctx );
        if( rs->sr_err != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
                LDAP_LOG( OPERATION, INFO, 
@@ -245,7 +241,7 @@ do_modrdn(
 
        if( op->orr_newSup ) {
                rs->sr_err = dnPrettyNormal( NULL, &newSuperior, &pnewSuperior,
-                       &nnewSuperior );
+                       &nnewSuperior, op->o_tmpmemctx );
                if( rs->sr_err != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
                        LDAP_LOG( OPERATION, INFO, 
@@ -276,10 +272,15 @@ do_modrdn(
                        NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
                if (!rs->sr_ref) rs->sr_ref = default_referral;
 
-               rs->sr_err = LDAP_REFERRAL;
-               send_ldap_result( op, rs );
+               if ( rs->sr_ref != NULL ) {
+                       rs->sr_err = LDAP_REFERRAL;
+                       send_ldap_result( op, rs );
 
-               if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
+                       if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
+               } else {
+                       send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
+                                       "referral missing" );
+               }
                goto cleanup;
        }
 
@@ -310,30 +311,35 @@ do_modrdn(
        }
 
 #if defined( LDAP_SLAPI )
-       slapi_x_pblock_set_operation( pb, op );
-       slapi_pblock_set( pb, SLAPI_MODRDN_TARGET, (void *)dn.bv_val );
-       slapi_pblock_set( pb, SLAPI_MODRDN_NEWRDN, (void *)newrdn.bv_val );
-       slapi_pblock_set( pb, SLAPI_MODRDN_NEWSUPERIOR,
-                       (void *)newSuperior.bv_val );
-       slapi_pblock_set( pb, SLAPI_MODRDN_DELOLDRDN, (void *)deloldrdn );
-       slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
-
-       rs->sr_err = doPluginFNs( op->o_bd, SLAPI_PLUGIN_PRE_MODRDN_FN, pb );
-       if ( rs->sr_err != 0 ) {
-               /*
-                * A preoperation plugin failure will abort the
-                * entire operation.
-                */
+#define        pb      op->o_pb
+       if ( pb ) {
+               slapi_x_pblock_set_operation( pb, op );
+               slapi_pblock_set( pb, SLAPI_MODRDN_TARGET, (void *)dn.bv_val );
+               slapi_pblock_set( pb, SLAPI_MODRDN_NEWRDN, (void *)newrdn.bv_val );
+               slapi_pblock_set( pb, SLAPI_MODRDN_NEWSUPERIOR,
+                               (void *)newSuperior.bv_val );
+               slapi_pblock_set( pb, SLAPI_MODRDN_DELOLDRDN, (void *)deloldrdn );
+               slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
+
+               rs->sr_err = doPluginFNs( op->o_bd, SLAPI_PLUGIN_PRE_MODRDN_FN, pb );
+               if ( rs->sr_err < 0 ) {
+                       /*
+                        * A preoperation plugin failure will abort the
+                        * entire operation.
+                        */
 #ifdef NEW_LOGGING
-               LDAP_LOG( OPERATION, INFO, "do_modrdn: modrdn preoperation plugin "
-                               "failed\n", 0, 0, 0 );
+                       LDAP_LOG( OPERATION, INFO, "do_modrdn: modrdn preoperation plugin "
+                                       "failed\n", 0, 0, 0 );
 #else
-               Debug(LDAP_DEBUG_TRACE, "do_modrdn: modrdn preoperation plugin "
-                               "failed.\n", 0, 0, 0);
+                       Debug(LDAP_DEBUG_TRACE, "do_modrdn: modrdn preoperation plugin "
+                                       "failed.\n", 0, 0, 0);
 #endif
-               if ( slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void *)&rs->sr_err ) != 0)
-                       rs->sr_err = LDAP_OTHER;
-               goto cleanup;
+                       if ( ( slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void *)&rs->sr_err ) != 0 ) ||
+                                rs->sr_err == LDAP_SUCCESS ) {
+                               rs->sr_err = LDAP_OTHER;
+                       }
+                       goto cleanup;
+               }
        }
 #endif /* defined( LDAP_SLAPI ) */
 
@@ -347,7 +353,10 @@ do_modrdn(
                /* do the update here */
                int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
 #ifndef SLAPD_MULTIMASTER
-               if ( !op->o_bd->be_update_ndn.bv_len || repl_user )
+               if ( !op->o_bd->be_syncinfo &&
+                       ( !op->o_bd->be_update_ndn.bv_len || repl_user ))
+#else
+               if ( !op->o_bd->be_syncinfo )
 #endif
                {
                        op->orr_deleteoldrdn = deloldrdn;
@@ -360,16 +369,27 @@ do_modrdn(
                        }
 #ifndef SLAPD_MULTIMASTER
                } else {
-                       BerVarray defref = op->o_bd->be_update_refs
-                               ? op->o_bd->be_update_refs : default_referral;
-                       rs->sr_ref = referral_rewrite( defref,
-                               NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
-                       if (!rs->sr_ref) rs->sr_ref = defref;
+                       BerVarray defref = NULL;
+                       if ( op->o_bd->be_syncinfo ) {
+                               defref = op->o_bd->be_syncinfo->si_provideruri_bv;
+                       } else {
+                               defref = op->o_bd->be_update_refs
+                                       ? op->o_bd->be_update_refs : default_referral;
+                       }
+                       if ( defref != NULL ) {
+                               rs->sr_ref = referral_rewrite( defref,
+                                       NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
+                               if (!rs->sr_ref) rs->sr_ref = defref;
 
-                       rs->sr_err = LDAP_REFERRAL;
-                       send_ldap_result( op, rs );
+                               rs->sr_err = LDAP_REFERRAL;
+                               send_ldap_result( op, rs );
 
-                       if (rs->sr_ref != defref) ber_bvarray_free( rs->sr_ref );
+                               if (rs->sr_ref != defref) ber_bvarray_free( rs->sr_ref );
+                       } else {
+                               send_ldap_error( op, rs,
+                                       LDAP_UNWILLING_TO_PERFORM,
+                                       "referral missing" );
+                       }
 #endif
                }
        } else {
@@ -378,7 +398,7 @@ do_modrdn(
        }
 
 #if defined( LDAP_SLAPI )
-       if ( doPluginFNs( op->o_bd, SLAPI_PLUGIN_POST_MODRDN_FN, pb ) != 0 ) {
+       if ( pb && doPluginFNs( op->o_bd, SLAPI_PLUGIN_POST_MODRDN_FN, pb ) < 0 ) {
 #ifdef NEW_LOGGING
                LDAP_LOG( OPERATION, INFO, "do_modrdn: modrdn postoperation plugins "
                                "failed\n", 0, 0, 0 );
@@ -390,14 +410,17 @@ do_modrdn(
 #endif /* defined( LDAP_SLAPI ) */
 
 cleanup:
-       free( op->o_req_dn.bv_val );
-       free( op->o_req_ndn.bv_val );
 
-       free( op->orr_newrdn.bv_val );  
-       free( op->orr_nnewrdn.bv_val ); 
+       slap_graduate_commit_csn( op );
+
+       op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
+       op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
 
-       if ( pnewSuperior.bv_val ) free( pnewSuperior.bv_val );
-       if ( nnewSuperior.bv_val ) free( nnewSuperior.bv_val );
+       op->o_tmpfree( op->orr_newrdn.bv_val, op->o_tmpmemctx );        
+       op->o_tmpfree( op->orr_nnewrdn.bv_val, op->o_tmpmemctx );       
+
+       if ( pnewSuperior.bv_val ) op->o_tmpfree( pnewSuperior.bv_val, op->o_tmpmemctx );
+       if ( nnewSuperior.bv_val ) op->o_tmpfree( nnewSuperior.bv_val, op->o_tmpmemctx );
 
        return rs->sr_err;
 }
@@ -407,82 +430,79 @@ slap_modrdn2mods(
        Operation       *op,
        SlapReply       *rs,
        Entry           *e,
-       LDAPRDN         *old_rdn,
-       LDAPRDN         *new_rdn,
+       LDAPRDN         old_rdn,
+       LDAPRDN         new_rdn,
        Modifications   **pmod )
 {
        Modifications   *mod = NULL;
+       Modifications   **modtail = &mod;
        int             a_cnt, d_cnt;
+       int repl_user;
 
        assert( new_rdn != NULL );
        assert( !op->orr_deleteoldrdn || old_rdn != NULL );
 
+       repl_user = be_isupdate( op->o_bd, &op->o_ndn );
+
        /* Add new attribute values to the entry */
-       for ( a_cnt = 0; new_rdn[0][a_cnt]; a_cnt++ ) {
+       for ( a_cnt = 0; new_rdn[a_cnt]; a_cnt++ ) {
                AttributeDescription    *desc = NULL;
                Modifications           *mod_tmp;
 
-               rs->sr_err = slap_bv2ad( &new_rdn[0][a_cnt]->la_attr, &desc, &rs->sr_text );
+               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[ 0 ][ a_cnt ]->la_attr.bv_val, 0 );
+                               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[ 0 ][ a_cnt ]->la_attr.bv_val, 0 );
+                               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[0][a_cnt]->la_value, ACL_WRITE, NULL ) ) {
+                       &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[0][a_cnt]->la_attr.bv_val, 0, 0 );
+                               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[0][ a_cnt ]->la_attr.bv_val, 0, 0 );
+                               new_rdn[ a_cnt ]->la_attr.bv_val, 0, 0 );
 #endif
                        rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
                        goto done;
                }
 
                /* Apply modification */
-#ifdef SLAP_NVALUES
                mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications )
                        + 4 * sizeof( struct berval ) );
-#else
-               mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications )
-                       + 2 * sizeof( struct berval ) );
-#endif
                mod_tmp->sml_desc = desc;
                mod_tmp->sml_values = ( BerVarray )( mod_tmp + 1 );
-               mod_tmp->sml_values[0] = new_rdn[0][a_cnt]->la_value;
+               mod_tmp->sml_values[0] = new_rdn[a_cnt]->la_value;
                mod_tmp->sml_values[1].bv_val = NULL;
-#ifdef SLAP_NVALUES
                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,
+                               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] );
+                               &mod_tmp->sml_nvalues[0], op->o_tmpmemctx );
                        mod_tmp->sml_nvalues[1].bv_val = NULL;
                } else {
                        mod_tmp->sml_nvalues = NULL;
                }
-#endif
                mod_tmp->sml_op = SLAP_MOD_SOFTADD;
                mod_tmp->sml_next = mod;
                mod = mod_tmp;
@@ -490,23 +510,23 @@ slap_modrdn2mods(
 
        /* Remove old rdn value if required */
        if ( op->orr_deleteoldrdn ) {
-               for ( d_cnt = 0; old_rdn[0][d_cnt]; d_cnt++ ) {
+               for ( d_cnt = 0; old_rdn[d_cnt]; d_cnt++ ) {
                        AttributeDescription    *desc = NULL;
                        Modifications           *mod_tmp;
 
-                       rs->sr_err = slap_bv2ad( &old_rdn[0][d_cnt]->la_attr, &desc, &rs->sr_text );
+                       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[0][d_cnt]->la_attr.bv_val, 
+                                       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[0][d_cnt]->la_attr.bv_val, 
+                                       old_rdn[d_cnt]->la_attr.bv_val, 
                                        0 );
 #endif
                                goto done;              
@@ -514,19 +534,19 @@ slap_modrdn2mods(
 
                        /* ACL check of newly added attrs */
                        if ( op->o_bd && !access_allowed( op, e, desc,
-                               &old_rdn[0][d_cnt]->la_value, ACL_WRITE, 
+                               &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[ 0 ][ d_cnt ]->la_attr.bv_val, 
+                                       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[ 0 ][ d_cnt ]->la_attr.bv_val,
+                                       old_rdn[ d_cnt ]->la_attr.bv_val,
                                        0, 0 );
 #endif
                                rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
@@ -534,31 +554,24 @@ slap_modrdn2mods(
                        }
 
                        /* Apply modification */
-#ifdef SLAP_NVALUES
                        mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications )
                                + 4 * sizeof ( struct berval ) );
-#else
-                       mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications )
-                               + 2 * sizeof ( struct berval ) );
-#endif
                        mod_tmp->sml_desc = desc;
                        mod_tmp->sml_values = ( BerVarray )(mod_tmp+1);
-                       mod_tmp->sml_values[0] = old_rdn[0][d_cnt]->la_value;
+                       mod_tmp->sml_values[0] = old_rdn[d_cnt]->la_value;
                        mod_tmp->sml_values[1].bv_val = NULL;
-#ifdef SLAP_NVALUES
                        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,
+                                       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] );
+                                       &mod_tmp->sml_nvalues[0], op->o_tmpmemctx );
                                mod_tmp->sml_nvalues[1].bv_val = NULL;
                        } else {
                                mod_tmp->sml_nvalues = NULL;
                        }
-#endif
                        mod_tmp->sml_op = LDAP_MOD_DELETE;
                        mod_tmp->sml_next = mod;
                        mod = mod_tmp;
@@ -566,6 +579,21 @@ slap_modrdn2mods(
        }
        
 done:
+
+       if ( !repl_user ) {
+               char textbuf[ SLAP_TEXT_BUFLEN ];
+               size_t textlen = sizeof textbuf;
+
+               for( modtail = &mod;
+                       *modtail != NULL;
+                       modtail = &(*modtail)->sml_next )
+               {
+                       /* empty */
+               }
+
+               rs->sr_err = slap_mods_opattrs( op, mod, modtail, &rs->sr_text, textbuf, textlen );
+       }
+
        /* LDAP v2 supporting correct attribute handling. */
        if ( rs->sr_err != LDAP_SUCCESS && mod != NULL ) {
                Modifications *tmp;