3 * Context CSN Management Routines
5 /* Copyright (c) 2003 by International Business Machines, Inc.
7 * International Business Machines, Inc. (hereinafter called IBM) grants
8 * permission under its copyrights to use, copy, modify, and distribute this
9 * Software with or without fee, provided that the above copyright notice and
10 * all paragraphs of this notice appear in all copies, and that the name of IBM
11 * not be used in connection with the marketing of any product incorporating
12 * the Software or modifications thereof, without specific, written prior
15 * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17 * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
18 * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
19 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
20 * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
27 #include <ac/string.h>
28 #include <ac/socket.h>
34 #include "lutil_ldap.h"
36 const struct berval slap_ldapsync_bv = BER_BVC("ldapsync");
37 const struct berval slap_ldapsync_cn_bv = BER_BVC("cn=ldapsync");
40 slap_get_commit_csn( Operation *op, struct berval *csn )
42 struct slap_csn_entry *csne = NULL, *committed_csne = NULL;
48 ldap_pvt_thread_mutex_lock( &op->o_bd->be_pcl_mutex );
50 LDAP_TAILQ_FOREACH( csne, &op->o_bd->be_pending_csn_list, csn_link ) {
51 if ( csne->opid == op->o_opid && csne->connid == op->o_connid )
56 csne->state = SLAP_CSN_COMMIT;
59 LDAP_TAILQ_FOREACH( csne, &op->o_bd->be_pending_csn_list, csn_link ) {
60 if ( csne->state == SLAP_CSN_COMMIT )
61 committed_csne = csne;
62 if ( csne->state == SLAP_CSN_PENDING )
66 ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex );
68 if ( committed_csne ) {
69 ber_dupbv( csn, committed_csne->csn );
74 slap_rewind_commit_csn( Operation *op )
76 struct slap_csn_entry *csne = NULL;
78 ldap_pvt_thread_mutex_lock( &op->o_bd->be_pcl_mutex );
80 LDAP_TAILQ_FOREACH( csne, &op->o_bd->be_pending_csn_list, csn_link ) {
81 if ( csne->opid == op->o_opid && csne->connid == op->o_connid )
86 csne->state = SLAP_CSN_PENDING;
89 ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex );
93 slap_graduate_commit_csn( Operation *op )
95 struct slap_csn_entry *csne = NULL;
97 ldap_pvt_thread_mutex_lock( &op->o_bd->be_pcl_mutex );
99 LDAP_TAILQ_FOREACH( csne, &op->o_bd->be_pending_csn_list, csn_link ) {
100 if ( csne->opid == op->o_opid && csne->connid == op->o_connid )
105 LDAP_TAILQ_REMOVE( &op->o_bd->be_pending_csn_list, csne, csn_link );
106 ch_free( csne->csn->bv_val );
107 ch_free( csne->csn );
111 ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex );
116 static struct berval ocbva[] = {
119 BER_BVC("syncProviderSubentry"),
124 slap_create_context_csn_entry(
126 struct berval *context_csn
134 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
136 attr_merge( e, slap_schema.si_ad_objectClass, ocbva, NULL );
138 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &ocbva[1], NULL );
140 attr_merge_one( e, slap_schema.si_ad_cn, (struct berval *)&slap_ldapsync_bv, NULL );
143 attr_merge_one( e, slap_schema.si_ad_contextCSN,
148 bv.bv_len = sizeof("{}")-1;
149 attr_merge_one( e, slap_schema.si_ad_subtreeSpecification, &bv, NULL );
151 build_new_dn( &e->e_name, &be->be_nsuffix[0], (struct berval *)&slap_ldapsync_cn_bv, NULL );
152 ber_dupbv( &e->e_nname, &e->e_name );
158 slap_contextcsn_callback(
163 if ( rs->sr_type != REP_SEARCH ) {
164 *((int*)op->o_callback->sc_private) = 0;
166 *((int*)op->o_callback->sc_private) = 1;
180 struct slap_csn_entry *pending;
182 if ( manage_ctxcsn ) {
183 pending = (struct slap_csn_entry *) ch_calloc( 1, sizeof( struct slap_csn_entry ));
189 csn->bv_len = lutil_csnstr( csnbuf, len, 0, 0 );
190 csn->bv_val = csnbuf;
192 if ( manage_ctxcsn ) {
193 ldap_pvt_thread_mutex_lock( &op->o_bd->be_pcl_mutex );
194 pending->csn = ber_dupbv( NULL, csn );
195 pending->connid = op->o_connid;
196 pending->opid = op->o_opid;
197 pending->state = SLAP_CSN_PENDING;
198 LDAP_TAILQ_INSERT_TAIL( &op->o_bd->be_pending_csn_list, pending, csn_link );
199 ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex );