1
0
forked from jengelh/openldap2
openldap2/0008-syncrepl-fixes-post-2.4.29.dif

228 lines
7.8 KiB
Plaintext

From 27f5cf4d4ebcef32c4102bbcc900b0d72383ddb9 Mon Sep 17 00:00:00 2001
From: Howard Chu <hyc@openldap.org>
Date: Sun, 12 Feb 2012 15:54:11 -0800
Subject: syncrepl fixes post 2.4.29
ITS#6024 patch breaks MMR loop detection
diff --git a/servers/slapd/overlays/syncprov.c b/servers/slapd/overlays/syncprov.c
index 8c6c296..e44c239 100644
--- a/servers/slapd/overlays/syncprov.c
+++ b/servers/slapd/overlays/syncprov.c
@@ -822,7 +822,7 @@ syncprov_sendresp( Operation *op, opcookie *opc, syncops *so, int mode )
{
SlapReply rs = { REP_SEARCH };
LDAPControl *ctrls[2];
- struct berval cookie = BER_BVNULL, csns[2];
+ struct berval cookie, csns[2];
Entry e_uuid = {0};
Attribute a_uuid = {0};
@@ -830,19 +830,17 @@ syncprov_sendresp( Operation *op, opcookie *opc, syncops *so, int mode )
return SLAPD_ABANDON;
ctrls[1] = NULL;
- if ( !BER_BVISNULL( &opc->sctxcsn )) {
- csns[0] = opc->sctxcsn;
- BER_BVZERO( &csns[1] );
- slap_compose_sync_cookie( op, &cookie, csns, so->s_rid, slap_serverID ? slap_serverID : -1 );
- }
+ csns[0] = opc->sctxcsn;
+ BER_BVZERO( &csns[1] );
+ slap_compose_sync_cookie( op, &cookie, csns, so->s_rid, slap_serverID ? slap_serverID : -1 );
#ifdef LDAP_DEBUG
if ( so->s_sid > 0 ) {
Debug( LDAP_DEBUG_SYNC, "syncprov_sendresp: to=%03x, cookie=%s\n",
- so->s_sid, cookie.bv_val ? cookie.bv_val : "", 0 );
+ so->s_sid, cookie.bv_val, 0 );
} else {
Debug( LDAP_DEBUG_SYNC, "syncprov_sendresp: cookie=%s\n",
- cookie.bv_val ? cookie.bv_val : "", 0, 0 );
+ cookie.bv_val, 0, 0 );
}
#endif
@@ -851,9 +849,7 @@ syncprov_sendresp( Operation *op, opcookie *opc, syncops *so, int mode )
a_uuid.a_nvals = &opc->suuid;
rs.sr_err = syncprov_state_ctrl( op, &rs, &e_uuid,
mode, ctrls, 0, 1, &cookie );
- if ( !BER_BVISNULL( &cookie )) {
- op->o_tmpfree( cookie.bv_val, op->o_tmpmemctx );
- }
+ op->o_tmpfree( cookie.bv_val, op->o_tmpmemctx );
rs.sr_ctrls = ctrls;
rs.sr_entry = &e_uuid;
diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c
index 3938288..ff13ff9 100644
--- a/servers/slapd/syncrepl.c
+++ b/servers/slapd/syncrepl.c
@@ -131,7 +131,7 @@ static int syncrepl_message_to_op(
syncinfo_t *, Operation *, LDAPMessage * );
static int syncrepl_message_to_entry(
syncinfo_t *, Operation *, LDAPMessage *,
- Modifications **, Entry **, int );
+ Modifications **, Entry **, int, struct berval* );
static int syncrepl_entry(
syncinfo_t *, Operation*, Entry*,
Modifications**,int, struct berval*,
@@ -833,7 +833,7 @@ do_syncrep2(
tout_p, &msg ) ) > 0 )
{
int match, punlock, syncstate;
- struct berval *retdata, syncUUID, cookie = BER_BVNULL;
+ struct berval *retdata, syncUUID[2], cookie = BER_BVNULL;
char *retoid;
LDAPControl **rctrls = NULL, *rctrlp = NULL;
BerVarray syncUUIDs;
@@ -885,7 +885,7 @@ do_syncrep2(
goto done;
}
ber_init2( ber, &rctrlp->ldctl_value, LBER_USE_DER );
- if ( ber_scanf( ber, "{em" /*"}"*/, &syncstate, &syncUUID )
+ if ( ber_scanf( ber, "{em" /*"}"*/, &syncstate, &syncUUID[0] )
== LBER_ERROR ) {
bdn.bv_val[bdn.bv_len] = '\0';
Debug( LDAP_DEBUG_ANY, "do_syncrep2: %s malformed message (%s)\n",
@@ -896,7 +896,7 @@ do_syncrep2(
}
/* FIXME: what if syncUUID is NULL or empty?
* (happens with back-sql...) */
- if ( BER_BVISEMPTY( &syncUUID ) ) {
+ if ( BER_BVISEMPTY( &syncUUID[0] ) ) {
bdn.bv_val[bdn.bv_len] = '\0';
Debug( LDAP_DEBUG_ANY, "do_syncrep2: %s "
"got empty syncUUID with LDAP_SYNC_%s (%s)\n",
@@ -1007,10 +1007,10 @@ do_syncrep2(
break;
}
} else if ( ( rc = syncrepl_message_to_entry( si, op, msg,
- &modlist, &entry, syncstate ) ) == LDAP_SUCCESS )
+ &modlist, &entry, syncstate, syncUUID ) ) == LDAP_SUCCESS )
{
if ( ( rc = syncrepl_entry( si, op, entry, &modlist,
- syncstate, &syncUUID, syncCookie.ctxcsn ) ) == LDAP_SUCCESS &&
+ syncstate, syncUUID, syncCookie.ctxcsn ) ) == LDAP_SUCCESS &&
syncCookie.ctxcsn )
{
rc = syncrepl_updateCookie( si, op, &syncCookie );
@@ -2415,7 +2415,8 @@ syncrepl_message_to_entry(
LDAPMessage *msg,
Modifications **modlist,
Entry **entry,
- int syncstate
+ int syncstate,
+ struct berval *syncUUID
)
{
Entry *e = NULL;
@@ -2457,6 +2458,14 @@ syncrepl_message_to_entry(
return LDAP_OTHER;
}
+ /* syncUUID[0] is normalized UUID received over the wire
+ * syncUUID[1] is denormalized UUID, generated here
+ */
+ (void)slap_uuidstr_from_normalized( &syncUUID[1], &syncUUID[0], op->o_tmpmemctx );
+ Debug( LDAP_DEBUG_SYNC,
+ "syncrepl_message_to_entry: %s DN: %s, UUID: %s\n",
+ si->si_ridtxt, bdn.bv_val, syncUUID[1].bv_val );
+
if ( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_DELETE ) {
/* NOTE: this could be done even before decoding the DN,
* although encoding errors wouldn't be detected */
@@ -2677,7 +2686,6 @@ syncrepl_entry(
Backend *be = op->o_bd;
slap_callback cb = { NULL, NULL, NULL, NULL };
int syncuuid_inserted = 0;
- struct berval syncUUID_strrep = BER_BVNULL;
SlapReply rs_search = {REP_RESULT};
Filter f = {0};
@@ -2707,14 +2715,13 @@ syncrepl_entry(
}
}
- (void)slap_uuidstr_from_normalized( &syncUUID_strrep, syncUUID, op->o_tmpmemctx );
if ( syncstate != LDAP_SYNC_DELETE ) {
Attribute *a = attr_find( entry->e_attrs, slap_schema.si_ad_entryUUID );
if ( a == NULL ) {
/* add if missing */
attr_merge_one( entry, slap_schema.si_ad_entryUUID,
- &syncUUID_strrep, syncUUID );
+ &syncUUID[1], syncUUID );
} else if ( !bvmatch( &a->a_nvals[0], syncUUID ) ) {
/* replace only if necessary */
@@ -2723,7 +2730,7 @@ syncrepl_entry(
ber_dupbv( &a->a_nvals[0], syncUUID );
}
ber_memfree( a->a_vals[0].bv_val );
- ber_dupbv( &a->a_vals[0], &syncUUID_strrep );
+ ber_dupbv( &a->a_vals[0], &syncUUID[1] );
}
}
@@ -2734,16 +2741,16 @@ syncrepl_entry(
if ( syncuuid_inserted ) {
Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: %s inserted UUID %s\n",
- si->si_ridtxt, syncUUID_strrep.bv_val, 0 );
+ si->si_ridtxt, syncUUID[1].bv_val, 0 );
}
op->ors_filter = &f;
- op->ors_filterstr.bv_len = STRLENOF( "(entryUUID=)" ) + syncUUID_strrep.bv_len;
+ op->ors_filterstr.bv_len = STRLENOF( "(entryUUID=)" ) + syncUUID[1].bv_len;
op->ors_filterstr.bv_val = (char *) slap_sl_malloc(
op->ors_filterstr.bv_len + 1, op->o_tmpmemctx );
AC_MEMCPY( op->ors_filterstr.bv_val, "(entryUUID=", STRLENOF( "(entryUUID=" ) );
AC_MEMCPY( &op->ors_filterstr.bv_val[STRLENOF( "(entryUUID=" )],
- syncUUID_strrep.bv_val, syncUUID_strrep.bv_len );
+ syncUUID[1].bv_val, syncUUID[1].bv_len );
op->ors_filterstr.bv_val[op->ors_filterstr.bv_len - 1] = ')';
op->ors_filterstr.bv_val[op->ors_filterstr.bv_len] = '\0';
@@ -2820,23 +2827,6 @@ syncrepl_entry(
*/
op->o_csn = a->a_vals[0];
freecsn = 0;
- /* There was no cookie CSN attached to this op,
- * make sure it's new enough
- */
- if ( !syncCSN ) {
- int i, sid = slap_parse_csn_sid( &a->a_vals[0] );
- for ( i = 0; i<si->si_cookieState->cs_num; i++ ) {
- if ( sid < si->si_cookieState->cs_sids[i] )
- break;
- if ( sid == si->si_cookieState->cs_sids[i] ) {
- if ( ber_bvcmp( &a->a_vals[0], &si->si_cookieState->cs_vals[i] ) <= 0 ) {
- Debug( LDAP_DEBUG_SYNC, "do_syncrep2: %s entryCSN too old, ignoring %s (%s)\n",
- si->si_ridtxt, a->a_vals[0].bv_val, entry->e_name.bv_val );
- goto done;
- }
- }
- }
- }
}
}
retry_add:;
@@ -3229,10 +3219,8 @@ retry_modrdn:;
}
done:
- if ( !BER_BVISNULL( &syncUUID_strrep ) ) {
- slap_sl_free( syncUUID_strrep.bv_val, op->o_tmpmemctx );
- BER_BVZERO( &syncUUID_strrep );
- }
+ slap_sl_free( syncUUID[1].bv_val, op->o_tmpmemctx );
+ BER_BVZERO( &syncUUID[1] );
if ( !BER_BVISNULL( &dni.ndn ) ) {
op->o_tmpfree( dni.ndn.bv_val, op->o_tmpmemctx );
}
--
1.7.7