]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/modify.c
fix previous commit (ITS#4861)
[openldap] / servers / slapd / back-meta / modify.c
index 62a041a17f5f6904cadd82482c8782d0a68a5fc0..3ca7cf821f8c8a183f63b72152107e265ddaee0a 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1999-2005 The OpenLDAP Foundation.
+ * Copyright 1999-2007 The OpenLDAP Foundation.
  * Portions Copyright 2001-2003 Pierangelo Masarati.
  * Portions Copyright 1999-2003 Howard Chu.
  * All rights reserved.
@@ -35,6 +35,7 @@ int
 meta_back_modify( Operation *op, SlapReply *rs )
 {
        metainfo_t      *mi = ( metainfo_t * )op->o_bd->be_private;
+       metatarget_t    *mt;
        metaconn_t      *mc;
        int             rc = 0;
        LDAPMod         **modv = NULL;
@@ -45,7 +46,9 @@ meta_back_modify( Operation *op, SlapReply *rs )
        struct berval   mdn = BER_BVNULL;
        struct berval   mapped;
        dncookie        dc;
+       int             msgid;
        int             do_retry = 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 ) ) {
@@ -57,13 +60,14 @@ meta_back_modify( Operation *op, SlapReply *rs )
        /*
         * Rewrite the modify dn, if needed
         */
-       dc.target = &mi->mi_targets[ candidate ];
+       mt = mi->mi_targets[ candidate ];
+       dc.target = mt;
        dc.conn = op->o_conn;
        dc.rs = rs;
        dc.ctx = "modifyDN";
 
        if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
-               rc = -1;
+               send_ldap_result( op, rs );
                goto cleanup;
        }
 
@@ -72,14 +76,14 @@ meta_back_modify( Operation *op, SlapReply *rs )
 
        mods = ch_malloc( sizeof( LDAPMod )*i );
        if ( mods == NULL ) {
-               rs->sr_err = LDAP_NO_MEMORY;
-               rc = -1;
+               rs->sr_err = LDAP_OTHER;
+               send_ldap_result( op, rs );
                goto cleanup;
        }
        modv = ( LDAPMod ** )ch_malloc( ( i + 1 )*sizeof( LDAPMod * ) );
        if ( modv == NULL ) {
-               rs->sr_err = LDAP_NO_MEMORY;
-               rc = -1;
+               rs->sr_err = LDAP_OTHER;
+               send_ldap_result( op, rs );
                goto cleanup;
        }
 
@@ -88,7 +92,8 @@ meta_back_modify( Operation *op, SlapReply *rs )
        for ( i = 0, ml = op->orm_modlist; ml; ml = ml->sml_next ) {
                int     j, is_oc = 0;
 
-               if ( !isupdate && ml->sml_desc->ad_type->sat_no_user_mod  ) {
+               if ( !isupdate && !get_manageDIT( op ) && ml->sml_desc->ad_type->sat_no_user_mod  )
+               {
                        continue;
                }
 
@@ -99,7 +104,7 @@ meta_back_modify( Operation *op, SlapReply *rs )
                        mapped = ml->sml_desc->ad_cname;
 
                } else {
-                       ldap_back_map( &mi->mi_targets[ candidate ].mt_rwmap.rwm_at,
+                       ldap_back_map( &mt->mt_rwmap.rwm_at,
                                        &ml->sml_desc->ad_cname, &mapped,
                                        BACKLDAP_MAP );
                        if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
@@ -126,11 +131,11 @@ meta_back_modify( Operation *op, SlapReply *rs )
                                for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); ) {
                                        struct ldapmapping      *mapping;
 
-                                       ldap_back_mapping( &mi->mi_targets[ candidate ].mt_rwmap.rwm_oc,
+                                       ldap_back_mapping( &mt->mt_rwmap.rwm_oc,
                                                        &ml->sml_values[ j ], &mapping, BACKLDAP_MAP );
 
                                        if ( mapping == NULL ) {
-                                               if ( mi->mi_targets[ candidate ].mt_rwmap.rwm_oc.drop_missing ) {
+                                               if ( mt->mt_rwmap.rwm_oc.drop_missing ) {
                                                        continue;
                                                }
                                                mods[ i ].mod_bvalues[ j ] = &ml->sml_values[ j ];
@@ -172,16 +177,30 @@ meta_back_modify( Operation *op, SlapReply *rs )
        modv[ i ] = 0;
 
 retry:;
-       rs->sr_err = ldap_modify_ext_s( mc->mc_conns[ candidate ].msc_ld, mdn.bv_val,
-                       modv, op->o_ctrls, NULL );
+       ctrls = op->o_ctrls;
+       rc = ldap_back_proxy_authz_ctrl( &mc->mc_conns[ candidate ].msc_bound_ndn,
+               mt->mt_version, &mt->mt_idassert, op, rs, &ctrls );
+       if ( rc != LDAP_SUCCESS ) {
+               send_ldap_result( op, rs );
+               goto cleanup;
+       }
+
+       rs->sr_err = ldap_modify_ext( mc->mc_conns[ candidate ].msc_ld, mdn.bv_val,
+                       modv, ctrls, NULL, &msgid );
+       rs->sr_err = meta_back_op_result( mc, op, rs, candidate, msgid,
+               mt->mt_timeout[ SLAP_OP_MODIFY ], 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 ( 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;
                }
        }
 
 cleanup:;
+       (void)ldap_back_proxy_authz_ctrl_free( op, &ctrls );
+
        if ( mdn.bv_val != op->o_req_dn.bv_val ) {
                free( mdn.bv_val );
                BER_BVZERO( &mdn );
@@ -194,11 +213,9 @@ cleanup:;
        free( mods );
        free( modv );
 
-       if ( rc != -1 ) {
-               return meta_back_op_result( mc, op, rs, candidate );
+       if ( mc ) {
+               meta_back_release_conn( mi, mc );
        }
-       
-       send_ldap_result( op, rs );
 
        return rs->sr_err;
 }