]> git.sur5r.net Git - openldap/commitdiff
Better fix for ITS#2512. Use callback to invoke replog before sending
authorHoward Chu <hyc@openldap.org>
Thu, 25 Dec 2003 15:01:53 +0000 (15:01 +0000)
committerHoward Chu <hyc@openldap.org>
Thu, 25 Dec 2003 15:01:53 +0000 (15:01 +0000)
result to client.

servers/slapd/add.c
servers/slapd/delete.c
servers/slapd/modify.c
servers/slapd/modrdn.c
servers/slapd/passwd.c
servers/slapd/result.c
servers/slapd/slapi/slapi_ops.c
servers/slapd/tools/mimic.c

index 0f87f2155299f0bd3f0ea28bd28bb212595ef3cf..1b06371da821674d3c5ce44ab404ad37d4635012 100644 (file)
@@ -261,6 +261,7 @@ do_add( Operation *op, SlapReply *rs )
                        int update = op->o_bd->be_update_ndn.bv_len;
                        char textbuf[SLAP_TEXT_BUFLEN];
                        size_t textlen = sizeof textbuf;
+                       slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
 
                        rs->sr_err = slap_mods_check( modlist, update, &rs->sr_text,
                                                                                  textbuf, textlen, NULL );
@@ -308,14 +309,14 @@ do_add( Operation *op, SlapReply *rs )
 #endif /* LDAP_SLAPI */
 
                        op->ora_e = e;
-                       repstamp( op );
-                       if ( (op->o_bd->be_add)( op, rs ) == 0 ) {
 #ifdef SLAPD_MULTIMASTER
-                               if ( !repl_user )
+                       if ( !repl_user )
 #endif
-                               {
-                                       replog( op );
-                               }
+                       {
+                               cb.sc_next = op->o_callback;
+                               op->o_callback = &cb;
+                       }
+                       if ( (op->o_bd->be_add)( op, rs ) == 0 ) {
                                be_entry_release_w( op, e );
                                e = NULL;
                        }
index e1f01cd601102361b0c1ccc8606f6ef246cd1aee..e0a5c38fda7f6119645ac538f6486be96b36b491 100644 (file)
@@ -206,6 +206,7 @@ do_delete(
                if ( LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo ))
 #endif
                {
+                       slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
 
                        if ( !repl_user ) {
                                struct berval csn = { 0 , NULL };
@@ -213,15 +214,14 @@ do_delete(
                                slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, 1 );
                        }
 
-                       repstamp( op );
-                       if ( (op->o_bd->be_delete)( op, rs ) == 0 ) {
 #ifdef SLAPD_MULTIMASTER
-                               if ( !op->o_bd->be_update_ndn.bv_len || !repl_user )
+                       if ( !op->o_bd->be_update_ndn.bv_len || !repl_user )
 #endif
-                               {
-                                       replog( op );
-                               }
+                       {
+                               cb.sc_next = op->o_callback;
+                               op->o_callback = &cb;
                        }
+                       op->o_bd->be_delete( op, rs );
 #ifndef SLAPD_MULTIMASTER
                } else {
                        BerVarray defref = NULL;
index 0b1101fd17a92663192fdae845d8eadc556f6e96..e390d0acf91be0bc6588dc7e3c8c8417361efa84 100644 (file)
@@ -472,6 +472,7 @@ do_modify(
                        int update = op->o_bd->be_update_ndn.bv_len;
                        char textbuf[SLAP_TEXT_BUFLEN];
                        size_t textlen = sizeof textbuf;
+                       slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
 
                        rs->sr_err = slap_mods_check( modlist, update, &rs->sr_text,
                                textbuf, textlen, NULL );
@@ -498,15 +499,15 @@ do_modify(
                        }
 
                        op->orm_modlist = modlist;
-                       repstamp( op );
-                       if ( (op->o_bd->be_modify)( op, rs ) == 0
 #ifdef SLAPD_MULTIMASTER
-                               && !repl_user
+                       if ( !repl_user )
 #endif
-                       {
+                       {
                                /* but we log only the ones not from a replicator user */
-                               replog( op );
+                               cb.sc_next = op->o_callback;
+                               op->o_callback = &cb;
                        }
+                       op->o_bd->be_modify( op, rs );
 
 #ifndef SLAPD_MULTIMASTER
                /* send a referral */
index 88b251156ff130697a82a27352f7968e16e80953..2a6acd386cceaa921c1dac5b2bd74d55aef2ee61 100644 (file)
@@ -362,15 +362,17 @@ do_modrdn(
                if ( LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo ))
 #endif
                {
+                       slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
                        op->orr_deleteoldrdn = deloldrdn;
-                       repstamp( op );
-                       if ( (op->o_bd->be_modrdn)( op, rs ) == 0
 #ifdef SLAPD_MULTIMASTER
-                               && ( !op->o_bd->be_update_ndn.bv_len || !repl_user )
+                       if ( !op->o_bd->be_update_ndn.bv_len || !repl_user )
 #endif
-                       ) {
-                               replog( op );
+                       {
+                               cb.sc_next = op->o_callback;
+                               op->o_callback = &cb;
                        }
+                       op->o_bd->be_modrdn( op, rs );
+
 #ifndef SLAPD_MULTIMASTER
                } else {
                        BerVarray defref = NULL;
index 63750e6db05d4d38d4be0d980ac7bd164e176d10..113f13f5d8f32b5907ec5a28abc48eabf9ffb9ce 100644 (file)
@@ -37,6 +37,7 @@ int passwd_extop(
        Modifications ml, **modtail;
        Operation op2;
        slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
+       slap_callback cb2 = { &cb, slap_replog_cb, NULL, NULL };
 
        assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->ore_reqoid ) == 0 );
 
@@ -156,7 +157,7 @@ int passwd_extop(
 
        op2 = *op;
        op2.o_tag = LDAP_REQ_MODIFY;
-       op2.o_callback = &cb;
+       op2.o_callback = &cb2;
        op2.o_req_dn = dn;
        op2.o_req_ndn = ndn;
        op2.orm_modlist = &ml;
@@ -166,11 +167,9 @@ int passwd_extop(
                NULL, 0 );
        
        if ( rs->sr_err == LDAP_SUCCESS ) {
-               repstamp( &op2 );
                rs->sr_err = op2.o_bd->be_modify( &op2, rs );
        }
        if ( rs->sr_err == LDAP_SUCCESS ) {
-               replog( &op2 );
                rs->sr_rspdata = rsp;
        } else if ( rsp ) {
                ber_bvfree( rsp );
index b3971d5284a3e8f5c136a657ca8aa217aa0bb235..23b45f0892303ac13f8dfa15a2678bcab0ad43e0 100644 (file)
@@ -46,6 +46,14 @@ int slap_null_cb( Operation *op, SlapReply *rs )
        return 0;
 }
 
+int slap_replog_cb( Operation *op, SlapReply *rs )
+{
+       if ( rs->sr_err == LDAP_SUCCESS ) {
+               replog( op );
+       }
+       return SLAP_CB_CONTINUE;
+}
+
 static char *v2ref( BerVarray ref, const char *text )
 {
        size_t len = 0, i = 0;
index 1b4a4cda7c991acc74ece5264a45207c943976e8..8a42e14eae19b2242fc7915f5859c27fb22bfff7 100644 (file)
@@ -559,12 +559,9 @@ slapi_delete_internal(
        if ( op->o_bd->be_delete ) {
                int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
                if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
-                       if ( log_change ) repstamp( op );
-                       if ( (*op->o_bd->be_delete)( op, &rs ) == 0 ) {
-                               if ( log_change ) {
-                                       replog( op );
-                               }
-                       } else {
+                       slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
+                       if ( log_change ) op->o_callback = &cb;
+                       if ( (*op->o_bd->be_delete)( op, &rs ) ) {
                                rs.sr_err = LDAP_OTHER;
                        }
                } else {
@@ -641,11 +638,9 @@ slapi_add_entry_internal_locked(
        if ( op->o_bd->be_add ) {
                int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
                if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
-                       if ( log_changes ) repstamp( op );
+                       slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
+                       if ( log_changes ) op->o_callback = &cb;
                        if ( (*op->o_bd->be_add)( op, &rs ) == 0 ) {
-                               if ( log_changes ) {
-                                       replog( op );
-                               }
                                be_entry_release_w( op, *e );
                                *e = NULL;
                        }
@@ -834,12 +829,9 @@ slapi_modrdn_internal(
        if ( op->o_bd->be_modrdn ) {
                int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
                if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
-                       if ( log_change ) repstamp( op );
-                       if ( (*op->o_bd->be_modrdn)( op, &rs ) == 0 ) {
-                               if ( log_change ) {
-                                       replog( op );
-                               }
-                       } else {
+                       slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
+                       if ( log_change ) op->o_callback = &cb;
+                       if ( (*op->o_bd->be_modrdn)( op, &rs ) ) {
                                rs.sr_err = LDAP_OTHER;
                        }
                } else {
@@ -1032,6 +1024,7 @@ slapi_modify_internal(
                        const char *text = NULL;
                        char textbuf[SLAP_TEXT_BUFLEN];
                        size_t textlen = sizeof( textbuf );
+                       slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
 
                        rs.sr_err = slap_mods_check( modlist, update,
                                        &text, textbuf, textlen, NULL );
@@ -1047,12 +1040,8 @@ slapi_modify_internal(
                                        goto cleanup;
                                }
                        }
-                       if ( log_change ) repstamp( op );
-                       if ( (*op->o_bd->be_modify)( op, &rs ) == 0 ) {
-                               if ( log_change ) {
-                                       replog( op );
-                               }
-                       } else {
+                       if ( log_change ) op->o_callback = &cb;
+                       if ( (*op->o_bd->be_modify)( op, &rs ) ) {
                                rs.sr_err = LDAP_OTHER;
                        }
                } else {
index d8dde1d711483ea618904f943f329f88db284e15..044d8c164ebe7888a56f55a3ec774822d42d266f 100644 (file)
@@ -62,6 +62,14 @@ slap_null_cb(
        assert(0);
 }
 
+int
+slap_replog_cb(
+    Operation  *op, SlapReply *rs
+)
+{
+       assert(0);
+}
+
 void
 slap_send_ldap_extended(
     Operation  *op, SlapReply *rs
@@ -194,11 +202,6 @@ const char * connection_state2str( int state )
        return NULL;
 }
 
-void repstamp( Operation *op )
-{
-       assert(0);
-}
-
 void replog( Operation *op )
 {
        assert(0);