]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/add.c
Drop unnecessary memset()s
[openldap] / servers / slapd / back-meta / add.c
index 31b0fcb59a108d8db161060223c44c7ea31b6fde..2d318bb1f04030d16459264cb230fe41419f92d5 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-2006 The OpenLDAP Foundation.
  * Portions Copyright 2001-2003 Pierangelo Masarati.
  * Portions Copyright 1999-2003 Howard Chu.
  * All rights reserved.
@@ -36,6 +36,7 @@ int
 meta_back_add( Operation *op, SlapReply *rs )
 {
        metainfo_t      *mi = ( metainfo_t * )op->o_bd->be_private;
+       metatarget_t    *mt;
        metaconn_t      *mc;
        int             i, candidate = -1;
        int             isupdate;
@@ -43,7 +44,9 @@ meta_back_add( Operation *op, SlapReply *rs )
        LDAPMod         **attrs;
        struct berval   mdn = BER_BVNULL, mapped;
        dncookie        dc;
+       int             msgid;
        int             do_retry = 1;
+       LDAPControl     **ctrls = NULL;
 
        Debug(LDAP_DEBUG_ARGS, "==> meta_back_add: %s\n",
                        op->o_req_dn.bv_val, 0, 0 );
@@ -61,7 +64,8 @@ meta_back_add( Operation *op, SlapReply *rs )
        /*
         * Rewrite the add 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 = "addDN";
@@ -82,7 +86,8 @@ meta_back_add( Operation *op, SlapReply *rs )
        for ( i = 0, a = op->ora_e->e_attrs; a; a = a->a_next ) {
                int                     j, is_oc = 0;
 
-               if ( !isupdate && a->a_desc->ad_type->sat_no_user_mod  ) {
+               if ( !isupdate && !get_relax( op ) && a->a_desc->ad_type->sat_no_user_mod  )
+               {
                        continue;
                }
 
@@ -93,7 +98,7 @@ meta_back_add( Operation *op, SlapReply *rs )
                        mapped = a->a_desc->ad_cname;
 
                } else {
-                       ldap_back_map( &mi->mi_targets[ candidate ].mt_rwmap.rwm_at,
+                       ldap_back_map( &mt->mt_rwmap.rwm_at,
                                        &a->a_desc->ad_cname, &mapped, BACKLDAP_MAP );
                        if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
                                continue;
@@ -118,11 +123,11 @@ meta_back_add( Operation *op, SlapReply *rs )
                        for ( j = 0; !BER_BVISNULL( &a->a_vals[ j ] ); ) {
                                struct ldapmapping      *mapping;
 
-                               ldap_back_mapping( &mi->mi_targets[ candidate ].mt_rwmap.rwm_oc,
+                               ldap_back_mapping( &mt->mt_rwmap.rwm_oc,
                                                &a->a_vals[ 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;
                                        }
                                        attrs[ i ]->mod_bvalues[ j ] = &a->a_vals[ j ];
@@ -163,20 +168,30 @@ meta_back_add( Operation *op, SlapReply *rs )
        attrs[ i ] = NULL;
 
 retry:;
-#if 0
+       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_add_ext( mc->mc_conns[ candidate ].msc_ld, mdn.bv_val,
-                             attrs, op->o_ctrls, NULL, &msgid );
-       rs->sr_err = meta_back_op_result( op, rs, &mc->mc_conns[ candidate ], msgid, LDAP_BACK_SENDERR );
-#endif
-       rs->sr_err = ldap_add_ext_s( mc->mc_conns[ candidate ].msc_ld, mdn.bv_val,
-                             attrs, op->o_ctrls, NULL );
+                             attrs, ctrls, NULL, &msgid );
+       rs->sr_err = meta_back_op_result( mc, op, rs, candidate, msgid,
+               mt->mt_timeout[ SLAP_OP_ADD ], 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 );
+
        for ( --i; i >= 0; --i ) {
                free( attrs[ i ]->mod_bvalues );
                free( attrs[ i ] );
@@ -187,10 +202,10 @@ retry:;
                BER_BVZERO( &mdn );
        }
 
-       (void)meta_back_op_result( mc, op, rs, candidate );
-
 done:;
-       meta_back_release_conn( op, mc );
+       if ( mc ) {
+               meta_back_release_conn( op, mc );
+       }
 
        return rs->sr_err;
 }