]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/modrdn.c
Drop unnecessary memset()s
[openldap] / servers / slapd / back-meta / modrdn.c
index fb739fa1c0811d197849417caf496991e07fce9c..f6e27c64902f3d622e1c7363e982eb50825dd366 100644 (file)
@@ -35,6 +35,7 @@ int
 meta_back_modrdn( Operation *op, SlapReply *rs )
 {
        metainfo_t      *mi = ( metainfo_t * )op->o_bd->be_private;
+       metatarget_t    *mt;
        metaconn_t      *mc;
        int             candidate = -1;
        struct berval   mdn = BER_BVNULL,
@@ -42,7 +43,7 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
        dncookie        dc;
        int             msgid;
        int             do_retry = 1;
-       int             maperr = 1;
+       LDAPControl     **ctrls = NULL;
 
        mc = meta_back_getconn( op, rs, &candidate, LDAP_BACK_SENDERR );
        if ( !mc || !meta_back_dobind( op, rs, mc, LDAP_BACK_SENDERR ) ) {
@@ -51,6 +52,8 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
 
        assert( mc->mc_conns[ candidate ].msc_ld != NULL );
 
+       mt = mi->mi_targets[ candidate ];
+       dc.target = mt;
        dc.conn = op->o_conn;
        dc.rs = rs;
 
@@ -76,7 +79,7 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
                 */
 
                /* needs LDAPv3 */
-               switch ( mi->mi_targets[ candidate ]->mt_version ) {
+               switch ( mt->mt_version ) {
                case LDAP_VERSION3:
                        break;
 
@@ -90,18 +93,17 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
                        /* op->o_protocol cannot be anything but LDAPv3,
                         * otherwise wouldn't be here */
                        rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
-                       maperr = 0;
+                       send_ldap_result( op, rs );
                        goto cleanup;
                }
                
                /*
                 * Rewrite the new superior, if defined and required
                 */
-               dc.target = mi->mi_targets[ candidate ];
                dc.ctx = "newSuperiorDN";
                if ( ldap_back_dn_massage( &dc, op->orr_newSup, &mnewSuperior ) ) {
                        rs->sr_err = LDAP_OTHER;
-                       maperr = 0;
+                       send_ldap_result( op, rs );
                        goto cleanup;
                }
        }
@@ -109,79 +111,40 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
        /*
         * Rewrite the modrdn dn, if required
         */
-       dc.target = mi->mi_targets[ candidate ];
        dc.ctx = "modrDN";
        if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
                rs->sr_err = LDAP_OTHER;
-               maperr = 0;
+               send_ldap_result( op, rs );
                goto cleanup;
        }
 
 retry:;
+       ctrls = op->o_ctrls;
+       if ( ldap_back_proxy_authz_ctrl( &mc->mc_conns[ candidate ].msc_bound_ndn,
+               mt->mt_version, &mt->mt_idassert, op, rs, &ctrls ) != LDAP_SUCCESS )
+       {
+               send_ldap_result( op, rs );
+               goto cleanup;
+       }
+
        rs->sr_err = ldap_rename( mc->mc_conns[ candidate ].msc_ld,
                        mdn.bv_val, op->orr_newrdn.bv_val,
                        mnewSuperior.bv_val, op->orr_deleteoldrdn,
-                       op->o_ctrls, NULL, &msgid );
+                       ctrls, NULL, &msgid );
+       rs->sr_err = meta_back_op_result( mc, op, rs, candidate, msgid,
+               mt->mt_timeout[ SLAP_OP_MODRDN ], LDAP_BACK_SENDRESULT );
        if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) {
                do_retry = 0;
                if ( meta_back_retry( op, rs, &mc, candidate, LDAP_BACK_SENDERR ) ) {
+                       /* if the identity changed, there might be need to re-authz */
+                       (void)ldap_back_proxy_authz_ctrl_free( op, &ctrls );
                        goto retry;
                }
-               goto done;
-
-       } else if ( rs->sr_err == LDAP_SUCCESS ) {
-               struct timeval  tv, *tvp = NULL;
-               LDAPMessage     *res = NULL;
-               int             rc;
-
-               if ( mi->mi_targets[ candidate ]->mt_timeout[ LDAP_BACK_OP_MODRDN ] != 0 ) {
-                       tv.tv_sec = mi->mi_targets[ candidate ]->mt_timeout[ LDAP_BACK_OP_MODRDN ];
-                       tv.tv_usec = 0;
-                       tvp = &tv;
-               }
-
-               rs->sr_err = LDAP_OTHER;
-               rc = ldap_result( mc->mc_conns[ candidate ].msc_ld,
-                       msgid, LDAP_MSG_ALL, tvp, &res );
-               maperr = 0;
-               switch ( rc ) {
-               case -1:
-                       break;
-
-               case 0:
-                       (void)meta_back_cancel( mc, op, rs, msgid, candidate, LDAP_BACK_DONTSEND );
-                       rs->sr_err = op->o_protocol >= LDAP_VERSION3 ?
-                               LDAP_ADMINLIMIT_EXCEEDED : LDAP_OPERATIONS_ERROR;
-                       break;
-
-               case LDAP_RES_RENAME:
-                       rc = ldap_parse_result( mc->mc_conns[ candidate ].msc_ld,
-                               res, &rs->sr_err, NULL, NULL, NULL, NULL, 1 );
-                       if ( rc != LDAP_SUCCESS ) {
-                               rs->sr_err = rc;
-                       }
-                       maperr = 1;
-                       break;
-
-               default:
-                       ldap_msgfree( res );
-                       break;
-               }
        }
 
 cleanup:;
-       if ( maperr ) {
-               meta_back_op_result( mc, op, rs, candidate );
-
-       } else {
-               send_ldap_result( op, rs );
-
-               if ( META_BACK_QUARANTINE( mi ) ) {
-                       meta_back_quarantine( op, rs, candidate, 1 );
-               }
-       }
+       (void)ldap_back_proxy_authz_ctrl_free( op, &ctrls );
 
-done:;
        if ( mdn.bv_val != op->o_req_dn.bv_val ) {
                free( mdn.bv_val );
                BER_BVZERO( &mdn );