]> git.sur5r.net Git - openldap/commitdiff
ITS#5947
authorQuanah Gibson-Mount <quanah@openldap.org>
Tue, 17 Feb 2009 01:06:01 +0000 (01:06 +0000)
committerQuanah Gibson-Mount <quanah@openldap.org>
Tue, 17 Feb 2009 01:06:01 +0000 (01:06 +0000)
CHANGES
servers/slapd/ctxcsn.c
servers/slapd/overlays/syncprov.c
servers/slapd/syncrepl.c

diff --git a/CHANGES b/CHANGES
index 67deadd75e3df6465588a3ac4ed8a027d4c5129d..7229afe7eb06189d8f27a263739054e92a0279a4 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,7 @@
 OpenLDAP 2.4 Change Log
 
 OpenLDAP 2.4.15 Engineering
+       Fixed slapd corrupt contextCSN (ITS#5947)
 
 OpenLDAP 2.4.14 Release (2009/02/14)
        Added libldap option to disable SASL host canonicalization (ITS#5812)
index 1f8c0505c78672683206ee15781bc8a40b77038b..873721600fcf8963f559d9fd8a95a054a0594806 100644 (file)
@@ -30,6 +30,7 @@ const struct berval slap_ldapsync_bv = BER_BVC("ldapsync");
 const struct berval slap_ldapsync_cn_bv = BER_BVC("cn=ldapsync");
 int slap_serverID;
 
+/* maxcsn->bv_val must point to a char buf[LDAP_LUTIL_CSNSTR_BUFSIZE] */
 void
 slap_get_commit_csn(
        Operation *op,
@@ -41,7 +42,8 @@ slap_get_commit_csn(
        BackendDB *be = op->o_bd->bd_self;
 
        if ( maxcsn ) {
-               BER_BVZERO( maxcsn );
+               assert( maxcsn->bv_val != NULL );
+               assert( maxcsn->bv_len >= LDAP_LUTIL_CSNSTR_BUFSIZE );
        }
        if ( foundit ) {
                *foundit = 0;
@@ -62,7 +64,17 @@ slap_get_commit_csn(
                if ( csne->ce_state == SLAP_CSN_PENDING ) break;
        }
 
-       if ( committed_csne && maxcsn ) *maxcsn = committed_csne->ce_csn;
+       if ( maxcsn ) {
+               if ( committed_csne ) {
+                       if ( committed_csne->ce_csn.bv_len < maxcsn->bv_len )
+                               maxcsn->bv_len = committed_csne->ce_csn.bv_len;
+                       AC_MEMCPY( maxcsn->bv_val, committed_csne->ce_csn.bv_val,
+                               maxcsn->bv_len+1 );
+               } else {
+                       maxcsn->bv_len = 0;
+                       maxcsn->bv_val[0] = 0;
+               }
+       }
        ldap_pvt_thread_mutex_unlock( &be->be_pcl_mutex );
 }
 
index 2f8686acecde99fd327ea91623917de1bd3eeb7d..427c9a421d5defe712bc5405fff8542d5e37e2b2 100644 (file)
 #include "config.h"
 #include "ldap_rq.h"
 
+#ifdef LDAP_DEVEL
+#define        CHECK_CSN       1
+#endif
+
 /* A modify request on a particular entry */
 typedef struct modinst {
        struct modinst *mi_next;
@@ -704,6 +708,10 @@ again:
        switch( mode ) {
        case FIND_MAXCSN:
                if ( ber_bvcmp( &si->si_ctxcsn[maxid], &maxcsn )) {
+#ifdef CHECK_CSN
+                       Syntax *syn = slap_schema.si_ad_contextCSN->ad_type->sat_syntax;
+                       assert( !syn->ssyn_validate( syn, &maxcsn ));
+#endif
                        ber_bvreplace( &si->si_ctxcsn[maxid], &maxcsn );
                        si->si_numops++;        /* ensure a checkpoint */
                }
@@ -1339,7 +1347,14 @@ syncprov_checkpoint( Operation *op, SlapReply *rs, slap_overinst *on )
        SlapReply rsm = { 0 };
        slap_callback cb = {0};
        BackendDB be;
+#ifdef CHECK_CSN
+       Syntax *syn = slap_schema.si_ad_contextCSN->ad_type->sat_syntax;
 
+       int i;
+       for ( i=0; i<si->si_numcsns; i++ ) {
+               assert( !syn->ssyn_validate( syn, si->si_ctxcsn+i ));
+       }
+#endif
        mod.sml_numvals = si->si_numcsns;
        mod.sml_values = si->si_ctxcsn;
        mod.sml_nvalues = NULL;
@@ -1367,6 +1382,11 @@ syncprov_checkpoint( Operation *op, SlapReply *rs, slap_overinst *on )
        if ( mod.sml_next != NULL ) {
                slap_mods_free( mod.sml_next, 1 );
        }
+#ifdef CHECK_CSN
+       for ( i=0; i<si->si_numcsns; i++ ) {
+               assert( !syn->ssyn_validate( syn, si->si_ctxcsn+i ));
+       }
+#endif
 }
 
 static void
@@ -1608,15 +1628,17 @@ syncprov_op_response( Operation *op, SlapReply *rs )
 
        if ( rs->sr_err == LDAP_SUCCESS )
        {
-               struct berval maxcsn = BER_BVNULL;
+               struct berval maxcsn;
                char cbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
                int do_check = 0, have_psearches, foundit;
 
                /* Update our context CSN */
                cbuf[0] = '\0';
+               maxcsn.bv_val = cbuf;
+               maxcsn.bv_len = sizeof(cbuf);
                ldap_pvt_thread_rdwr_wlock( &si->si_csn_rwlock );
                slap_get_commit_csn( op, &maxcsn, &foundit );
-               if ( BER_BVISNULL( &maxcsn ) && SLAP_GLUE_SUBORDINATE( op->o_bd )) {
+               if ( BER_BVISEMPTY( &maxcsn ) && SLAP_GLUE_SUBORDINATE( op->o_bd )) {
                        /* syncrepl queues the CSN values in the db where
                         * it is configured , not where the changes are made.
                         * So look for a value in the glue db if we didn't
@@ -1624,12 +1646,17 @@ syncprov_op_response( Operation *op, SlapReply *rs )
                         */
                        BackendDB *be = op->o_bd;
                        op->o_bd = select_backend( &be->be_nsuffix[0], 1);
+                       maxcsn.bv_val = cbuf;
+                       maxcsn.bv_len = sizeof(cbuf);
                        slap_get_commit_csn( op, &maxcsn, &foundit );
                        op->o_bd = be;
                }
-               if ( !BER_BVISNULL( &maxcsn ) ) {
+               if ( !BER_BVISEMPTY( &maxcsn ) ) {
                        int i, sid;
-                       strcpy( cbuf, maxcsn.bv_val );
+#ifdef CHECK_CSN
+                       Syntax *syn = slap_schema.si_ad_contextCSN->ad_type->sat_syntax;
+                       assert( !syn->ssyn_validate( syn, &maxcsn ));
+#endif
                        sid = slap_parse_csn_sid( &maxcsn );
                        for ( i=0; i<si->si_numcsns; i++ ) {
                                if ( sid == si->si_sids[i] ) {
@@ -1685,8 +1712,7 @@ syncprov_op_response( Operation *op, SlapReply *rs )
 
                /* only update consumer ctx if this is the greatest csn */
                if ( bvmatch( &maxcsn, &op->o_csn )) {
-                       opc->sctxcsn.bv_len = maxcsn.bv_len;
-                       opc->sctxcsn.bv_val = cbuf;
+                       opc->sctxcsn = maxcsn;
                }
 
                /* Handle any persistent searches */
@@ -1750,6 +1776,7 @@ syncprov_op_compare( Operation *op, SlapReply *rs )
 
                a.a_vals = si->si_ctxcsn;
                a.a_nvals = a.a_vals;
+               a.a_numvals = si->si_numcsns;
 
                rs->sr_err = access_allowed( op, &e, op->oq_compare.rs_ava->aa_desc,
                        &op->oq_compare.rs_ava->aa_value, ACL_COMPARE, NULL );
index 1313b8ad429e1a99996f25ebc967f645fe0eaccd..d99af0ef2ef67b2ba2fc931ba9a8fa06278e4f17 100644 (file)
@@ -2876,6 +2876,9 @@ syncrepl_updateCookie(
        Backend *be = op->o_bd;
        Modifications mod;
        struct berval first = BER_BVNULL;
+#ifdef CHECK_CSN
+       Syntax *syn = slap_schema.si_ad_contextCSN->ad_type->sat_syntax;
+#endif
 
        int rc, i, j;
        ber_len_t len;
@@ -2892,6 +2895,15 @@ syncrepl_updateCookie(
 
        ldap_pvt_thread_mutex_lock( &si->si_cookieState->cs_mutex );
 
+#ifdef CHECK_CSN
+       for ( i=0; i<syncCookie->numcsns; i++ ) {
+               assert( !syn->ssyn_validate( syn, syncCookie->ctxcsn+i ));
+       }
+       for ( i=0; i<si->si_cookieState->cs_num; i++ ) {
+               assert( !syn->ssyn_validate( syn, si->si_cookieState->cs_vals+i ));
+       }
+#endif
+
        /* clone the cookieState CSNs so we can Replace the whole thing */
        mod.sml_numvals = si->si_cookieState->cs_num;
        mod.sml_values = op->o_tmpalloc(( mod.sml_numvals+1 )*sizeof(struct berval), op->o_tmpmemctx );
@@ -2994,6 +3006,12 @@ syncrepl_updateCookie(
        if ( mod.sml_next ) slap_mods_free( mod.sml_next, 1 );
        op->o_tmpfree( mod.sml_values, op->o_tmpmemctx );
 
+#ifdef CHECK_CSN
+       for ( i=0; i<si->si_cookieState->cs_num; i++ ) {
+               assert( !syn->ssyn_validate( syn, si->si_cookieState->cs_vals+i ));
+       }
+#endif
+
        return rc;
 }