]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/syncprov.c
ITS#5322 don't try to free a NULL locker
[openldap] / servers / slapd / overlays / syncprov.c
index bf678f5b4600c201c6282aad80626b51857c2282..ad8b9bb329e0b507e54f8dbaf4833156c4058aeb 100644 (file)
@@ -2,7 +2,7 @@
 /* syncprov.c - syncrepl provider */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2004-2007 The OpenLDAP Foundation.
+ * Copyright 2004-2008 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -1607,8 +1607,12 @@ syncprov_op_response( Operation *op, SlapReply *rs )
                        }
                        if ( si->si_chktime &&
                                (op->o_time - si->si_chklast >= si->si_chktime )) {
-                               do_check = 1;
-                               si->si_chklast = op->o_time;
+                               if ( si->si_chklast ) {
+                                       do_check = 1;
+                                       si->si_chklast = op->o_time;
+                               } else {
+                                       si->si_chklast = 1;
+                               }
                        }
                }
                ldap_pvt_thread_rdwr_wunlock( &si->si_csn_rwlock );
@@ -2064,7 +2068,7 @@ syncprov_op_search( Operation *op, SlapReply *rs )
        slap_overinst           *on = (slap_overinst *)op->o_bd->bd_info;
        syncprov_info_t         *si = (syncprov_info_t *)on->on_bi.bi_private;
        slap_callback   *cb;
-       int gotstate = 0, changed = 0, do_present;
+       int gotstate = 0, changed = 0, do_present = 0;
        syncops *sop = NULL;
        searchstate *ss;
        sync_control *srs;
@@ -2079,8 +2083,6 @@ syncprov_op_search( Operation *op, SlapReply *rs )
                return rs->sr_err;
        }
 
-       do_present = si->si_nopres ? 0 : SS_PRESENT;
-
        srs = op->o_controls[slap_cids.sc_LDAPsync];
        op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
 
@@ -2148,6 +2150,9 @@ syncprov_op_search( Operation *op, SlapReply *rs )
                if ( !numcsns )
                        goto no_change;
 
+               if ( !si->si_nopres )
+                       do_present = SS_PRESENT;
+
                /* If there are SIDs we don't recognize in the cookie, drop them */
                for (i=0; i<srs->sr_state.numcsns; ) {
                        for (j=0; j<numcsns; j++) {
@@ -2191,6 +2196,7 @@ syncprov_op_search( Operation *op, SlapReply *rs )
                                        break;
                        }
                        if ( !changed ) {
+                               do_present = 0;
 no_change:             if ( !(op->o_sync_mode & SLAP_SYNC_PERSIST) ) {
                                        LDAPControl     *ctrls[2];
 
@@ -2319,6 +2325,12 @@ syncprov_operational(
        slap_overinst           *on = (slap_overinst *)op->o_bd->bd_info;
        syncprov_info_t         *si = (syncprov_info_t *)on->on_bi.bi_private;
 
+       /* This prevents generating unnecessarily; frontend will strip
+        * any statically stored copy.
+        */
+       if ( op->o_sync != SLAP_CONTROL_NONE )
+               return SLAP_CB_CONTINUE;
+
        if ( rs->sr_entry &&
                dn_match( &rs->sr_entry->e_nname, op->o_bd->be_nsuffix )) {
 
@@ -2838,10 +2850,14 @@ static int syncprov_parseCtrl (
        sr->sr_rhint = rhint;
        if (!BER_BVISNULL(&cookie)) {
                ber_dupbv_x( &sr->sr_state.octet_str, &cookie, op->o_tmpmemctx );
+               /* If parse fails, pretend no cookie was sent */
                if ( slap_parse_sync_cookie( &sr->sr_state, op->o_tmpmemctx ) ||
                        sr->sr_state.rid == -1 ) {
-                       rs->sr_text = "Sync control : cookie parsing error";
-                       return LDAP_PROTOCOL_ERROR;
+                       if ( sr->sr_state.ctxcsn ) {
+                               ber_bvarray_free_x( sr->sr_state.ctxcsn, op->o_tmpmemctx );
+                               sr->sr_state.ctxcsn = NULL;
+                       }
+                       sr->sr_state.numcsns = 0;
                }
        }