From e933f076ccd420824ba6dc3d0fb783b49094660a Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 25 Dec 2003 15:01:53 +0000 Subject: [PATCH] Better fix for ITS#2512. Use callback to invoke replog before sending result to client. --- servers/slapd/add.c | 13 +++++++------ servers/slapd/delete.c | 12 ++++++------ servers/slapd/modify.c | 11 ++++++----- servers/slapd/modrdn.c | 12 +++++++----- servers/slapd/passwd.c | 5 ++--- servers/slapd/result.c | 8 ++++++++ servers/slapd/slapi/slapi_ops.c | 33 +++++++++++---------------------- servers/slapd/tools/mimic.c | 13 ++++++++----- 8 files changed, 55 insertions(+), 52 deletions(-) diff --git a/servers/slapd/add.c b/servers/slapd/add.c index 0f87f21552..1b06371da8 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -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; } diff --git a/servers/slapd/delete.c b/servers/slapd/delete.c index e1f01cd601..e0a5c38fda 100644 --- a/servers/slapd/delete.c +++ b/servers/slapd/delete.c @@ -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; diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index 0b1101fd17..e390d0acf9 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -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 */ diff --git a/servers/slapd/modrdn.c b/servers/slapd/modrdn.c index 88b251156f..2a6acd386c 100644 --- a/servers/slapd/modrdn.c +++ b/servers/slapd/modrdn.c @@ -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; diff --git a/servers/slapd/passwd.c b/servers/slapd/passwd.c index 63750e6db0..113f13f5d8 100644 --- a/servers/slapd/passwd.c +++ b/servers/slapd/passwd.c @@ -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 ); diff --git a/servers/slapd/result.c b/servers/slapd/result.c index b3971d5284..23b45f0892 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -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; diff --git a/servers/slapd/slapi/slapi_ops.c b/servers/slapd/slapi/slapi_ops.c index 1b4a4cda7c..8a42e14eae 100644 --- a/servers/slapd/slapi/slapi_ops.c +++ b/servers/slapd/slapi/slapi_ops.c @@ -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 { diff --git a/servers/slapd/tools/mimic.c b/servers/slapd/tools/mimic.c index d8dde1d711..044d8c164e 100644 --- a/servers/slapd/tools/mimic.c +++ b/servers/slapd/tools/mimic.c @@ -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); -- 2.39.5