]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/modrdn.c
- LDAP_SYNCREPL defined in include/ldap.h
[openldap] / servers / slapd / modrdn.c
index 52e8b531dedfe917c44ab80a5815c45ddb4dc82b..3f542adb4b81e1ed9a561a6fb8470bab5692fe7e 100644 (file)
@@ -173,7 +173,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 +216,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 +245,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 +276,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;
        }
 
@@ -319,7 +324,7 @@ do_modrdn(
        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 ) {
+       if ( rs->sr_err < 0 ) {
                /*
                 * A preoperation plugin failure will abort the
                 * entire operation.
@@ -331,8 +336,10 @@ do_modrdn(
                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)
+               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 ) */
@@ -346,7 +353,12 @@ do_modrdn(
        if ( op->o_bd->be_modrdn ) {
                /* do the update here */
                int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
-#ifndef SLAPD_MULTIMASTER
+#if defined(LDAP_SYNCREPL) && !defined(SLAPD_MULTIMASTER)
+               if ( !op->o_bd->syncinfo &&
+                                       ( !op->o_bd->be_update_ndn.bv_len || repl_user ))
+#elif defined(LDAP_SYNCREPL) && defined(SLAPD_MULTIMASTER)
+               if ( !op->o_bd->syncinfo )  /* LDAP_SYNCREPL overrides MM */
+#elif !defined(LDAP_SYNCREPL) && !defined(SLAPD_MULTIMASTER)
                if ( !op->o_bd->be_update_ndn.bv_len || repl_user )
 #endif
                {
@@ -358,18 +370,32 @@ do_modrdn(
                        ) {
                                replog( op );
                        }
-#ifndef SLAPD_MULTIMASTER
+#if defined(LDAP_SYNCREPL) || !defined(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;
+#ifdef LDAP_SYNCREPL
+                       if ( op->o_bd->syncinfo ) {
+                               defref = op->o_bd->syncinfo->master_bv;
+                       } else
+#endif
+                       {
+                               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 +404,7 @@ do_modrdn(
        }
 
 #if defined( LDAP_SLAPI )
-       if ( doPluginFNs( op->o_bd, SLAPI_PLUGIN_POST_MODRDN_FN, pb ) != 0 ) {
+       if ( 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 +416,14 @@ do_modrdn(
 #endif /* defined( LDAP_SLAPI ) */
 
 cleanup:
-       free( op->o_req_dn.bv_val );
-       free( op->o_req_ndn.bv_val );
+       op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
+       op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
 
-       free( op->orr_newrdn.bv_val );  
-       free( op->orr_nnewrdn.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 ) free( pnewSuperior.bv_val );
-       if ( nnewSuperior.bv_val ) free( nnewSuperior.bv_val );
+       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,8 +433,8 @@ 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;
@@ -418,58 +444,52 @@ slap_modrdn2mods(
        assert( !op->orr_deleteoldrdn || old_rdn != NULL );
 
        /* 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)(
@@ -477,12 +497,11 @@ slap_modrdn2mods(
                                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 +509,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 +533,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,18 +553,12 @@ 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)(
@@ -553,12 +566,11 @@ slap_modrdn2mods(
                                        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;