The following patch against servers/slapd/overlays/syncprov.c
version 1.320 appears to fix the issue detailed in ITS#6717,
and does not appear to break any of the basic sync functionality.

--- syncprov.c.1.320    2010-12-15 19:55:32.000000000 +0000
+++ syncprov.c  2010-12-15 22:13:48.000000000 +0000
@@ -2409,7 +2409,7 @@
        sync_control *srs;
        BerVarray ctxcsn;
        int i, *sids, numcsns;
-       struct berval mincsn;
+       struct berval mincsn, maxcsn;
        int dirty = 0;
 
        if ( !(op->o_sync_mode & SLAP_SYNC_REFRESH) ) return SLAP_CB_CONTINUE;
@@ -2524,12 +2524,25 @@
                        i++;
                }
 
-               /* Find the smallest CSN */
-               mincsn = srs->sr_state.ctxcsn[0];
-               for ( i=1; i<srs->sr_state.numcsns; i++ ) {
-                       if ( ber_bvcmp( &mincsn, &srs->sr_state.ctxcsn[i] ) > 0 
)
-                               mincsn = srs->sr_state.ctxcsn[i];
+               /* Find the smallest CSN which differs between cookie
+                * and contextCSN.
+                */
+               mincsn.bv_len = 0;
+               maxcsn.bv_len = 0;
+               for ( i=0; i<srs->sr_state.numcsns; i++) {
+                       for (j=0; j<numcsns; j++) {
+                               if ( srs->sr_state.sids[i] != sids[j] ) 
continue;
+                               if (BER_BVISNULL(&maxcsn) || ber_bvcmp( 
&maxcsn, &srs->sr_state.ctxcsn[i] ) < 0 ) {
+                                       maxcsn = srs->sr_state.ctxcsn[i];
+                               }
+                               if (ber_bvcmp( &srs->sr_state.ctxcsn[i], 
&ctxcsn[j] ) < 0) {
+                                       if (BER_BVISNULL(&mincsn) || ber_bvcmp( 
&mincsn, &srs->sr_state.ctxcsn[i] ) > 0 ) {
+                                               mincsn = 
srs->sr_state.ctxcsn[i];
+                                       }
+                               }
+                       }
                }
+               if (BER_BVISNULL(&mincsn)) mincsn = maxcsn;
 
                /* If nothing has changed, shortcut it */
                if ( srs->sr_state.numcsns == numcsns ) {


Reply via email to