~ttx/openldap/lucid-gssapi-495418

« back to all changes in this revision

Viewing changes to servers/slapd/overlays/syncprov.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2009-03-06 17:34:21 UTC
  • mto: (0.3.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: james.westby@ubuntu.com-20090306173421-n2o3ca73v9tmrdiy
Tags: upstream-2.4.15
ImportĀ upstreamĀ versionĀ 2.4.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $OpenLDAP: pkg/ldap/servers/slapd/overlays/syncprov.c,v 1.147.2.44 2009/01/30 18:49:57 quanah Exp $ */
 
1
/* $OpenLDAP: pkg/ldap/servers/slapd/overlays/syncprov.c,v 1.147.2.46 2009/02/23 02:15:32 quanah Exp $ */
2
2
/* syncprov.c - syncrepl provider */
3
3
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4
4
 *
28
28
#include "config.h"
29
29
#include "ldap_rq.h"
30
30
 
 
31
#ifdef LDAP_DEVEL
 
32
#define CHECK_CSN       1
 
33
#endif
 
34
 
31
35
/* A modify request on a particular entry */
32
36
typedef struct modinst {
33
37
        struct modinst *mi_next;
704
708
        switch( mode ) {
705
709
        case FIND_MAXCSN:
706
710
                if ( ber_bvcmp( &si->si_ctxcsn[maxid], &maxcsn )) {
 
711
#ifdef CHECK_CSN
 
712
                        Syntax *syn = slap_schema.si_ad_contextCSN->ad_type->sat_syntax;
 
713
                        assert( !syn->ssyn_validate( syn, &maxcsn ));
 
714
#endif
707
715
                        ber_bvreplace( &si->si_ctxcsn[maxid], &maxcsn );
708
716
                        si->si_numops++;        /* ensure a checkpoint */
709
717
                }
1339
1347
        SlapReply rsm = { 0 };
1340
1348
        slap_callback cb = {0};
1341
1349
        BackendDB be;
 
1350
#ifdef CHECK_CSN
 
1351
        Syntax *syn = slap_schema.si_ad_contextCSN->ad_type->sat_syntax;
1342
1352
 
 
1353
        int i;
 
1354
        for ( i=0; i<si->si_numcsns; i++ ) {
 
1355
                assert( !syn->ssyn_validate( syn, si->si_ctxcsn+i ));
 
1356
        }
 
1357
#endif
1343
1358
        mod.sml_numvals = si->si_numcsns;
1344
1359
        mod.sml_values = si->si_ctxcsn;
1345
1360
        mod.sml_nvalues = NULL;
1367
1382
        if ( mod.sml_next != NULL ) {
1368
1383
                slap_mods_free( mod.sml_next, 1 );
1369
1384
        }
 
1385
#ifdef CHECK_CSN
 
1386
        for ( i=0; i<si->si_numcsns; i++ ) {
 
1387
                assert( !syn->ssyn_validate( syn, si->si_ctxcsn+i ));
 
1388
        }
 
1389
#endif
1370
1390
}
1371
1391
 
1372
1392
static void
1608
1628
 
1609
1629
        if ( rs->sr_err == LDAP_SUCCESS )
1610
1630
        {
1611
 
                struct berval maxcsn = BER_BVNULL;
 
1631
                struct berval maxcsn;
1612
1632
                char cbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
1613
 
                int do_check = 0, have_psearches, foundit;
 
1633
                int do_check = 0, have_psearches, foundit, csn_changed = 0;
1614
1634
 
1615
1635
                /* Update our context CSN */
1616
1636
                cbuf[0] = '\0';
 
1637
                maxcsn.bv_val = cbuf;
 
1638
                maxcsn.bv_len = sizeof(cbuf);
1617
1639
                ldap_pvt_thread_rdwr_wlock( &si->si_csn_rwlock );
1618
1640
                slap_get_commit_csn( op, &maxcsn, &foundit );
1619
 
                if ( BER_BVISNULL( &maxcsn ) && SLAP_GLUE_SUBORDINATE( op->o_bd )) {
 
1641
                if ( BER_BVISEMPTY( &maxcsn ) && SLAP_GLUE_SUBORDINATE( op->o_bd )) {
1620
1642
                        /* syncrepl queues the CSN values in the db where
1621
1643
                         * it is configured , not where the changes are made.
1622
1644
                         * So look for a value in the glue db if we didn't
1624
1646
                         */
1625
1647
                        BackendDB *be = op->o_bd;
1626
1648
                        op->o_bd = select_backend( &be->be_nsuffix[0], 1);
 
1649
                        maxcsn.bv_val = cbuf;
 
1650
                        maxcsn.bv_len = sizeof(cbuf);
1627
1651
                        slap_get_commit_csn( op, &maxcsn, &foundit );
1628
1652
                        op->o_bd = be;
1629
1653
                }
1630
 
                if ( !BER_BVISNULL( &maxcsn ) ) {
 
1654
                if ( !BER_BVISEMPTY( &maxcsn ) ) {
1631
1655
                        int i, sid;
1632
 
                        strcpy( cbuf, maxcsn.bv_val );
 
1656
#ifdef CHECK_CSN
 
1657
                        Syntax *syn = slap_schema.si_ad_contextCSN->ad_type->sat_syntax;
 
1658
                        assert( !syn->ssyn_validate( syn, &maxcsn ));
 
1659
#endif
1633
1660
                        sid = slap_parse_csn_sid( &maxcsn );
1634
1661
                        for ( i=0; i<si->si_numcsns; i++ ) {
1635
1662
                                if ( sid == si->si_sids[i] ) {
1636
1663
                                        if ( ber_bvcmp( &maxcsn, &si->si_ctxcsn[i] ) > 0 ) {
1637
1664
                                                ber_bvreplace( &si->si_ctxcsn[i], &maxcsn );
 
1665
                                                csn_changed = 1;
1638
1666
                                        }
1639
1667
                                        break;
1640
1668
                                }
1642
1670
                        /* It's a new SID for us */
1643
1671
                        if ( i == si->si_numcsns ) {
1644
1672
                                value_add_one( &si->si_ctxcsn, &maxcsn );
 
1673
                                csn_changed = 1;
1645
1674
                                si->si_numcsns++;
1646
1675
                                si->si_sids = ch_realloc( si->si_sids, si->si_numcsns *
1647
1676
                                        sizeof(int));
1683
1712
                        ldap_pvt_thread_rdwr_runlock( &si->si_csn_rwlock );
1684
1713
                }
1685
1714
 
1686
 
                /* only update consumer ctx if this is the greatest csn */
1687
 
                if ( bvmatch( &maxcsn, &op->o_csn )) {
1688
 
                        opc->sctxcsn.bv_len = maxcsn.bv_len;
1689
 
                        opc->sctxcsn.bv_val = cbuf;
 
1715
                /* only update consumer ctx if this is a newer csn */
 
1716
                if ( csn_changed ) {
 
1717
                        opc->sctxcsn = maxcsn;
1690
1718
                }
1691
1719
 
1692
1720
                /* Handle any persistent searches */
1750
1778
 
1751
1779
                a.a_vals = si->si_ctxcsn;
1752
1780
                a.a_nvals = a.a_vals;
 
1781
                a.a_numvals = si->si_numcsns;
1753
1782
 
1754
1783
                rs->sr_err = access_allowed( op, &e, op->oq_compare.rs_ava->aa_desc,
1755
1784
                        &op->oq_compare.rs_ava->aa_value, ACL_COMPARE, NULL );