]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/syncprov.c
ITS#6872
[openldap] / servers / slapd / overlays / syncprov.c
index 14aed8cbd7a6e0a209f53756b15262706eae1413..a058e194237cad7a34b146c8c3b0836991066208 100644 (file)
@@ -225,10 +225,10 @@ syncprov_state_ctrl(
 
        if ( ret < 0 ) {
                Debug( LDAP_DEBUG_TRACE,
-                       "slap_build_sync_ctrl: ber_flatten2 failed\n",
-                       0, 0, 0 );
+                       "slap_build_sync_ctrl: ber_flatten2 failed (%d)\n",
+                       ret, 0, 0 );
                send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
-               return ret;
+               return LDAP_OTHER;
        }
 
        return LDAP_SUCCESS;
@@ -271,10 +271,10 @@ syncprov_done_ctrl(
 
        if ( ret < 0 ) {
                Debug( LDAP_DEBUG_TRACE,
-                       "syncprov_done_ctrl: ber_flatten2 failed\n",
-                       0, 0, 0 );
+                       "syncprov_done_ctrl: ber_flatten2 failed (%d)\n",
+                       ret, 0, 0 );
                send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
-               return ret;
+               return LDAP_OTHER;
        }
 
        return LDAP_SUCCESS;
@@ -338,10 +338,10 @@ syncprov_sendinfo(
 
        if ( ret < 0 ) {
                Debug( LDAP_DEBUG_TRACE,
-                       "syncprov_sendinfo: ber_flatten2 failed\n",
-                       0, 0, 0 );
+                       "syncprov_sendinfo: ber_flatten2 failed (%d)\n",
+                       ret, 0, 0 );
                send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
-               return ret;
+               return LDAP_OTHER;
        }
 
        rs->sr_rspoid = LDAP_SYNC_INFO;
@@ -586,7 +586,7 @@ findpres_cb( Operation *op, SlapReply *rs )
 }
 
 static int
-syncprov_findcsn( Operation *op, find_csn_t mode )
+syncprov_findcsn( Operation *op, find_csn_t mode, struct berval *csn )
 {
        slap_overinst           *on = (slap_overinst *)op->o_bd->bd_info;
        syncprov_info_t         *si = on->on_bi.bi_private;
@@ -659,15 +659,12 @@ again:
                break;
        case FIND_CSN:
                if ( BER_BVISEMPTY( &cf.f_av_value )) {
-                       cf.f_av_value = srs->sr_state.ctxcsn[0];
-                       /* If there are multiple CSNs, use the smallest */
-                       for ( i=1; i<srs->sr_state.numcsns; i++ ) {
-                               if ( ber_bvcmp( &cf.f_av_value, &srs->sr_state.ctxcsn[i] )
-                                       > 0 ) {
-                                       cf.f_av_value = srs->sr_state.ctxcsn[i];
-                               }
-                       }
+                       cf.f_av_value = *csn;
                }
+               fop.o_dn = op->o_bd->be_rootdn;
+               fop.o_ndn = op->o_bd->be_rootndn;
+               fop.o_req_dn = op->o_bd->be_suffix[0];
+               fop.o_req_ndn = op->o_bd->be_nsuffix[0];
                /* Look for exact match the first time */
                if ( findcsn_retry ) {
                        cf.f_choice = LDAP_FILTER_EQUALITY;
@@ -2330,6 +2327,7 @@ syncprov_search_response( Operation *op, SlapReply *rs )
                rs->sr_ctrls = op->o_tmpalloc( sizeof(LDAPControl *)*2,
                        op->o_tmpmemctx );
                rs->sr_ctrls[1] = NULL;
+               rs->sr_flags |= REP_CTRLS_MUSTBEFREED;
                /* If we're in delta-sync mode, always send a cookie */
                if ( si->si_nopres && si->si_usehint && a ) {
                        struct berval cookie;
@@ -2623,7 +2621,7 @@ no_change:                if ( !(op->o_sync_mode & SLAP_SYNC_PERSIST) ) {
                        }
                }
                /* Is the CSN still present in the database? */
-               if ( syncprov_findcsn( op, FIND_CSN ) != LDAP_SUCCESS ) {
+               if ( syncprov_findcsn( op, FIND_CSN, &mincsn ) != LDAP_SUCCESS ) {
                        /* No, so a reload is required */
                        /* the 2.2 consumer doesn't send this hint */
                        if ( si->si_usehint && srs->sr_rhint == 0 ) {
@@ -2647,7 +2645,7 @@ no_change:                if ( !(op->o_sync_mode & SLAP_SYNC_PERSIST) ) {
                } else {
                        gotstate = 1;
                        /* If changed and doing Present lookup, send Present UUIDs */
-                       if ( do_present && syncprov_findcsn( op, FIND_PRESENT ) !=
+                       if ( do_present && syncprov_findcsn( op, FIND_PRESENT, 0 ) !=
                                LDAP_SUCCESS ) {
                                if ( ctxcsn )
                                        ber_bvarray_free_x( ctxcsn, op->o_tmpmemctx );
@@ -2761,7 +2759,7 @@ syncprov_operational(
                                }
 
                                if ( !ap ) {
-                                       if ( rs_ensure_entry_modifiable( op, rs, on )) {
+                                       if ( rs_entry2modifiable( op, rs, on )) {
                                                a = attr_find( rs->sr_entry->e_attrs,
                                                        slap_schema.si_ad_contextCSN );
                                        }
@@ -2975,7 +2973,7 @@ syncprov_db_otask(
        void *ptr
 )
 {
-       syncprov_findcsn( ptr, FIND_MAXCSN );
+       syncprov_findcsn( ptr, FIND_MAXCSN, 0 );
        return NULL;
 }