]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/slapi/slapi_ops.c
Merge remote branch 'origin/mdb.master' into OPENLDAP_REL_ENG_2_4
[openldap] / servers / slapd / slapi / slapi_ops.c
index c224d7a667bbf7fabe94050cd6ed742a4ebddb5b..270f3577008e918c66bbccf2ab4382c562d9b5e3 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2002-2005 The OpenLDAP Foundation.
+ * Copyright 2002-2011 The OpenLDAP Foundation.
  * Portions Copyright 1997,2002-2003 IBM Corporation.
  * All rights reserved.
  *
@@ -33,7 +33,7 @@
 
 #ifdef LDAP_SLAPI
 
-static struct slap_listener slapi_listener = {
+static struct Listener slapi_listener = {
        BER_BVC("slapi://"),
        BER_BVC("slapi://")
 };
@@ -187,9 +187,9 @@ slapi_int_connection_init_pb( Slapi_PBlock *pb, ber_tag_t tag )
 
        LDAP_STAILQ_INIT( &conn->c_pending_ops );
 
-       op = (Operation *) slapi_ch_calloc( 1, OPERATION_BUFFER_SIZE );
-       op->o_hdr = (Opheader *)(op + 1);
-       op->o_controls = (void **)(op->o_hdr + 1);
+       op = (Operation *) slapi_ch_calloc( 1, sizeof(OperationBuffer) );
+       op->o_hdr = &((OperationBuffer *) op)->ob_hdr;
+       op->o_controls = ((OperationBuffer *) op)->ob_controls;
 
        op->o_callback = (slap_callback *) slapi_ch_calloc( 1, sizeof(slap_callback) );
        op->o_callback->sc_response = slapi_int_response;
@@ -224,8 +224,10 @@ slapi_int_connection_init_pb( Slapi_PBlock *pb, ber_tag_t tag )
 
        /* should check status of thread calls */
        ldap_pvt_thread_mutex_init( &conn->c_mutex );
-       ldap_pvt_thread_mutex_init( &conn->c_write_mutex );
-       ldap_pvt_thread_cond_init( &conn->c_write_cv );
+       ldap_pvt_thread_mutex_init( &conn->c_write1_mutex );
+       ldap_pvt_thread_mutex_init( &conn->c_write2_mutex );
+       ldap_pvt_thread_cond_init( &conn->c_write1_cv );
+       ldap_pvt_thread_cond_init( &conn->c_write2_cv );
 
        ldap_pvt_thread_mutex_lock( &conn->c_mutex );
 
@@ -253,7 +255,7 @@ slapi_int_connection_init_pb( Slapi_PBlock *pb, ber_tag_t tag )
        conn->c_conn_state  = 0x01;     /* SLAP_C_ACTIVE */
        conn->c_struct_state = 0x02;    /* SLAP_C_USED */
 
-       conn->c_ssf = conn->c_transport_ssf = 0;
+       conn->c_ssf = conn->c_transport_ssf = local_ssf;
        conn->c_tls_ssf = 0;
 
        backend_connection_init( conn );
@@ -296,7 +298,7 @@ slapi_int_set_operation_dn( Slapi_PBlock *pb )
 
        if ( BER_BVISNULL( &op->o_ndn ) ) {
                /* set to root DN */
-               be = select_backend( &op->o_req_ndn, 0, 0 );
+               be = select_backend( &op->o_req_ndn, 1 );
                if ( be != NULL ) {
                        ber_dupbv( &op->o_dn, &be->be_rootdn );
                        ber_dupbv( &op->o_ndn, &be->be_rootndn );
@@ -342,12 +344,13 @@ slapi_int_connection_done_pb( Slapi_PBlock *pb )
                        op->o_tmpfree( op->orr_nnewSup->bv_val, op->o_tmpmemctx );
                        op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx );
                }
+               slap_mods_free( op->orr_modlist, 1 );
                break;
        case LDAP_REQ_ADD:
-               slapi_int_mods_free( op->ora_modlist );
+               slap_mods_free( op->ora_modlist, 0 );
                break;
        case LDAP_REQ_MODIFY:
-               slapi_int_mods_free( op->orm_modlist );
+               slap_mods_free( op->orm_modlist, 1 );
                break;
        case LDAP_REQ_SEARCH:
                if ( op->ors_attrs != NULL ) {
@@ -362,6 +365,8 @@ slapi_int_connection_done_pb( Slapi_PBlock *pb )
        slapi_ch_free_string( &conn->c_authmech.bv_val );
        slapi_ch_free_string( &conn->c_dn.bv_val );
        slapi_ch_free_string( &conn->c_ndn.bv_val );
+       slapi_ch_free_string( &conn->c_peer_domain.bv_val );
+       slapi_ch_free_string( &conn->c_peer_name.bv_val );
 
        if ( conn->c_sb != NULL ) {
                ber_sockbuf_free( conn->c_sb );
@@ -407,7 +412,6 @@ slapi_delete_internal_pb( Slapi_PBlock *pb )
        PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_DELETE );
 
        slapi_int_func_internal_pb( pb, op_delete );
-       slap_graduate_commit_csn( pb->pb_op );
 
        return 0;
 }
@@ -417,6 +421,8 @@ slapi_add_internal_pb( Slapi_PBlock *pb )
 {
        SlapReply               *rs;
        Slapi_Entry             *entry_orig = NULL;
+       OpExtraDB oex;
+       int rc;
 
        if ( pb == NULL ) {
                return -1;
@@ -429,6 +435,10 @@ slapi_add_internal_pb( Slapi_PBlock *pb )
        entry_orig = pb->pb_op->ora_e;
        pb->pb_op->ora_e = NULL;
 
+       /*
+        * The caller can specify a new entry, or a target DN and set
+        * of modifications, but not both.
+        */
        if ( entry_orig != NULL ) {
                if ( pb->pb_op->ora_modlist != NULL || !BER_BVISNULL( &pb->pb_op->o_req_ndn )) {
                        rs->sr_err = LDAP_PARAM_ERROR;
@@ -443,10 +453,6 @@ slapi_add_internal_pb( Slapi_PBlock *pb )
                goto cleanup;
        }
 
-       /*
-        * The caller can specify a new entry, or a target DN and set
-        * of modifications, but not both.
-        */
        pb->pb_op->ora_e = (Entry *)slapi_ch_calloc( 1, sizeof(Entry) );
        ber_dupbv( &pb->pb_op->ora_e->e_name,  &pb->pb_op->o_req_dn );
        ber_dupbv( &pb->pb_op->ora_e->e_nname, &pb->pb_op->o_req_ndn );
@@ -463,28 +469,37 @@ slapi_add_internal_pb( Slapi_PBlock *pb )
                assert( pb->pb_op->ora_modlist != NULL );
        }
 
-       rs->sr_err = slap_mods_check( pb->pb_op->ora_modlist, &rs->sr_text,
+       rs->sr_err = slap_mods_check( pb->pb_op, pb->pb_op->ora_modlist, &rs->sr_text,
                pb->pb_textbuf, sizeof( pb->pb_textbuf ), NULL );
        if ( rs->sr_err != LDAP_SUCCESS ) {
                 goto cleanup;
         }
 
-       if ( slapi_int_func_internal_pb( pb, op_add ) == 0 ) {
-               if ( pb->pb_op->ora_e != NULL && pb->pb_op->o_private != NULL ) {
+       /* Duplicate the values, because we may call slapi_entry_free() */
+       rs->sr_err = slap_mods2entry( pb->pb_op->ora_modlist, &pb->pb_op->ora_e,
+               1, 0, &rs->sr_text, pb->pb_textbuf, sizeof( pb->pb_textbuf ) );
+       if ( rs->sr_err != LDAP_SUCCESS ) {
+               goto cleanup;
+       }
+
+       oex.oe.oe_key = (void *)do_add;
+       oex.oe_db = NULL;
+       LDAP_SLIST_INSERT_HEAD(&pb->pb_op->o_extra, &oex.oe, oe_next);
+       rc = slapi_int_func_internal_pb( pb, op_add );
+       LDAP_SLIST_REMOVE(&pb->pb_op->o_extra, &oex.oe, OpExtra, oe_next);
+
+       if ( !rc ) {
+               if ( pb->pb_op->ora_e != NULL && oex.oe_db != NULL ) {
                        BackendDB       *bd = pb->pb_op->o_bd;
 
-                       /* could we use SLAPI_BACKEND instead? */
-                       pb->pb_op->o_bd = (BackendDB *)pb->pb_op->o_private;
-                       pb->pb_op->o_private = NULL;
+                       pb->pb_op->o_bd = oex.oe_db;
                        be_entry_release_w( pb->pb_op, pb->pb_op->ora_e );
                        pb->pb_op->ora_e = NULL;
                        pb->pb_op->o_bd = bd;
-                       pb->pb_op->o_private = NULL;
                }
        }
 
 cleanup:
-       slap_graduate_commit_csn( pb->pb_op );
 
        if ( pb->pb_op->ora_e != NULL ) {
                slapi_entry_free( pb->pb_op->ora_e );
@@ -492,7 +507,7 @@ cleanup:
        }
        if ( entry_orig != NULL ) {
                pb->pb_op->ora_e = entry_orig;
-               slapi_int_mods_free( pb->pb_op->ora_modlist );
+               slap_mods_free( pb->pb_op->ora_modlist, 1 );
                pb->pb_op->ora_modlist = NULL;
        }
 
@@ -516,7 +531,6 @@ slapi_modrdn_internal_pb( Slapi_PBlock *pb )
        slapi_int_func_internal_pb( pb, op_modrdn );
 
 cleanup:
-       slap_graduate_commit_csn( pb->pb_op );
 
        return 0;
 }
@@ -544,7 +558,7 @@ slapi_modify_internal_pb( Slapi_PBlock *pb )
                goto cleanup;
        }
 
-       rs->sr_err = slap_mods_check( pb->pb_op->orm_modlist,
+       rs->sr_err = slap_mods_check( pb->pb_op, pb->pb_op->orm_modlist,
                &rs->sr_text, pb->pb_textbuf, sizeof( pb->pb_textbuf ), NULL );
        if ( rs->sr_err != LDAP_SUCCESS ) {
                 goto cleanup;
@@ -553,7 +567,6 @@ slapi_modify_internal_pb( Slapi_PBlock *pb )
        slapi_int_func_internal_pb( pb, op_modify );
 
 cleanup:
-       slap_graduate_commit_csn( pb->pb_op );
 
        return 0;
 }
@@ -859,6 +872,7 @@ slapi_rename_internal_set_pb( Slapi_PBlock *pb,
        slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID,    (void *)uniqueid );
        slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY,    (void *)plugin_identity );
        slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS,      (void *)&operation_flags );
+       slap_modrdn2mods( pb->pb_op, pb->pb_rs );
        slapi_int_set_operation_dn( pb );
 }