version 1.239, 2008/05/29 14:58:32
|
version 1.255, 2009/01/24 06:04:42
|
Line 1
|
Line 1
|
/* $OpenLDAP: pkg/ldap/servers/slapd/overlays/syncprov.c,v 1.238 2008/05/28 00:46:35 hyc Exp $ */ |
/* $OpenLDAP: pkg/ldap/servers/slapd/overlays/syncprov.c,v 1.254 2009/01/21 23:40:40 kurt Exp $ */ |
/* syncprov.c - syncrepl provider */ |
/* syncprov.c - syncrepl provider */ |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
* |
* |
* Copyright 2004-2008 The OpenLDAP Foundation. |
* Copyright 2004-2009 The OpenLDAP Foundation. |
* All rights reserved. |
* All rights reserved. |
* |
* |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
Line 393 static struct berval generic_filterstr =
|
Line 393 static struct berval generic_filterstr =
|
static int |
static int |
syncprov_findbase( Operation *op, fbase_cookie *fc ) |
syncprov_findbase( Operation *op, fbase_cookie *fc ) |
{ |
{ |
opcookie *opc = op->o_callback->sc_private; |
|
slap_overinst *on = opc->son; |
|
|
|
/* Use basic parameters from syncrepl search, but use |
/* Use basic parameters from syncrepl search, but use |
* current op's threadctx / tmpmemctx |
* current op's threadctx / tmpmemctx |
*/ |
*/ |
Line 497 findmax_cb( Operation *op, SlapReply *rs
|
Line 494 findmax_cb( Operation *op, SlapReply *rs
|
Attribute *a = attr_find( rs->sr_entry->e_attrs, |
Attribute *a = attr_find( rs->sr_entry->e_attrs, |
slap_schema.si_ad_entryCSN ); |
slap_schema.si_ad_entryCSN ); |
|
|
if ( a && ber_bvcmp( &a->a_vals[0], maxcsn ) > 0 ) { |
if ( a && ber_bvcmp( &a->a_vals[0], maxcsn ) > 0 && |
|
slap_parse_csn_sid( &a->a_vals[0] ) == slap_serverID ) { |
maxcsn->bv_len = a->a_vals[0].bv_len; |
maxcsn->bv_len = a->a_vals[0].bv_len; |
strcpy( maxcsn->bv_val, a->a_vals[0].bv_val ); |
strcpy( maxcsn->bv_val, a->a_vals[0].bv_val ); |
} |
} |
Line 587 syncprov_findcsn( Operation *op, find_cs
|
Line 585 syncprov_findcsn( Operation *op, find_cs
|
sync_control *srs = NULL; |
sync_control *srs = NULL; |
struct slap_limits_set fc_limits; |
struct slap_limits_set fc_limits; |
int i, rc = LDAP_SUCCESS, findcsn_retry = 1; |
int i, rc = LDAP_SUCCESS, findcsn_retry = 1; |
int maxid = 0; |
int maxid; |
|
|
if ( mode != FIND_MAXCSN ) { |
if ( mode != FIND_MAXCSN ) { |
srs = op->o_controls[slap_cids.sc_LDAPsync]; |
srs = op->o_controls[slap_cids.sc_LDAPsync]; |
Line 613 again:
|
Line 611 again:
|
switch( mode ) { |
switch( mode ) { |
case FIND_MAXCSN: |
case FIND_MAXCSN: |
cf.f_choice = LDAP_FILTER_GE; |
cf.f_choice = LDAP_FILTER_GE; |
cf.f_av_value = si->si_ctxcsn[0]; |
/* If there are multiple CSNs, use the one with our serverID */ |
/* If there are multiple CSNs, use the largest */ |
for ( i=0; i<si->si_numcsns; i++) { |
for ( i=1; i<si->si_numcsns; i++) { |
if ( slap_serverID == si->si_sids[i] ) { |
if ( ber_bvcmp( &cf.f_av_value, &si->si_ctxcsn[i] ) < 0 ) { |
|
cf.f_av_value = si->si_ctxcsn[i]; |
|
maxid = i; |
maxid = i; |
|
break; |
} |
} |
} |
} |
|
if ( i == si->si_numcsns ) { |
|
/* No match: this is multimaster, and none of the content in the DB |
|
* originated locally. Treat like no CSN. |
|
*/ |
|
return LDAP_NO_SUCH_OBJECT; |
|
} |
|
cf.f_av_value = si->si_ctxcsn[maxid]; |
fop.ors_filterstr.bv_len = snprintf( buf, sizeof( buf ), |
fop.ors_filterstr.bv_len = snprintf( buf, sizeof( buf ), |
"(entryCSN>=%s)", cf.f_av_value.bv_val ); |
"(entryCSN>=%s)", cf.f_av_value.bv_val ); |
if ( fop.ors_filterstr.bv_len < 0 || fop.ors_filterstr.bv_len >= sizeof( buf ) ) { |
if ( fop.ors_filterstr.bv_len >= sizeof( buf ) ) { |
return LDAP_OTHER; |
return LDAP_OTHER; |
} |
} |
fop.ors_attrsonly = 0; |
fop.ors_attrsonly = 0; |
Line 660 again:
|
Line 664 again:
|
fop.ors_filterstr.bv_len = snprintf( buf, sizeof( buf ), |
fop.ors_filterstr.bv_len = snprintf( buf, sizeof( buf ), |
"(entryCSN<=%s)", cf.f_av_value.bv_val ); |
"(entryCSN<=%s)", cf.f_av_value.bv_val ); |
} |
} |
if ( fop.ors_filterstr.bv_len < 0 || fop.ors_filterstr.bv_len >= sizeof( buf ) ) { |
if ( fop.ors_filterstr.bv_len >= sizeof( buf ) ) { |
return LDAP_OTHER; |
return LDAP_OTHER; |
} |
} |
fop.ors_attrsonly = 1; |
fop.ors_attrsonly = 1; |
Line 796 syncprov_sendresp( Operation *op, opcook
|
Line 800 syncprov_sendresp( Operation *op, opcook
|
rs.sr_entry = *e; |
rs.sr_entry = *e; |
if ( rs.sr_entry->e_private ) |
if ( rs.sr_entry->e_private ) |
rs.sr_flags = REP_ENTRY_MUSTRELEASE; |
rs.sr_flags = REP_ENTRY_MUSTRELEASE; |
if ( opc->sreference ) { |
if ( opc->sreference && so->s_op->o_managedsait <= SLAP_CONTROL_IGNORED ) { |
rs.sr_ref = get_entry_referrals( op, rs.sr_entry ); |
rs.sr_ref = get_entry_referrals( op, rs.sr_entry ); |
rs.sr_err = send_search_reference( op, &rs ); |
rs.sr_err = send_search_reference( op, &rs ); |
ber_bvarray_free( rs.sr_ref ); |
ber_bvarray_free( rs.sr_ref ); |
Line 819 syncprov_sendresp( Operation *op, opcook
|
Line 823 syncprov_sendresp( Operation *op, opcook
|
e_uuid.e_name = opc->sdn; |
e_uuid.e_name = opc->sdn; |
e_uuid.e_nname = opc->sndn; |
e_uuid.e_nname = opc->sndn; |
rs.sr_entry = &e_uuid; |
rs.sr_entry = &e_uuid; |
if ( opc->sreference ) { |
if ( opc->sreference && so->s_op->o_managedsait <= SLAP_CONTROL_IGNORED ) { |
struct berval bv = BER_BVNULL; |
struct berval bv = BER_BVNULL; |
rs.sr_ref = &bv; |
rs.sr_ref = &bv; |
rs.sr_err = send_search_reference( op, &rs ); |
rs.sr_err = send_search_reference( op, &rs ); |
Line 904 syncprov_qplay( Operation *op, struct re
|
Line 908 syncprov_qplay( Operation *op, struct re
|
} else { |
} else { |
/* bail out on any error */ |
/* bail out on any error */ |
ldap_pvt_runqueue_remove( &slapd_rq, rtask ); |
ldap_pvt_runqueue_remove( &slapd_rq, rtask ); |
|
|
|
/* Prevent duplicate remove */ |
|
if ( so->s_qtask == rtask ) |
|
so->s_qtask = NULL; |
} |
} |
ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); |
ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); |
ldap_pvt_thread_mutex_unlock( &so->s_mutex ); |
ldap_pvt_thread_mutex_unlock( &so->s_mutex ); |
Line 1174 syncprov_matchops( Operation *op, opcook
|
Line 1182 syncprov_matchops( Operation *op, opcook
|
sprev = ss, ss=snext) |
sprev = ss, ss=snext) |
{ |
{ |
Operation op2; |
Operation op2; |
|
Opheader oh; |
syncmatches *sm; |
syncmatches *sm; |
int found = 0; |
int found = 0; |
|
|
Line 1223 syncprov_matchops( Operation *op, opcook
|
Line 1232 syncprov_matchops( Operation *op, opcook
|
|
|
if ( fc.fscope ) { |
if ( fc.fscope ) { |
op2 = *ss->s_op; |
op2 = *ss->s_op; |
op2.o_hdr = op->o_hdr; |
oh = *op->o_hdr; |
|
oh.oh_conn = ss->s_op->o_conn; |
|
oh.oh_connid = ss->s_op->o_connid; |
|
op2.o_hdr = &oh; |
op2.o_extra = op->o_extra; |
op2.o_extra = op->o_extra; |
} |
} |
|
|
Line 1247 syncprov_matchops( Operation *op, opcook
|
Line 1259 syncprov_matchops( Operation *op, opcook
|
/* send DELETE */ |
/* send DELETE */ |
syncprov_qresp( opc, ss, LDAP_SYNC_DELETE ); |
syncprov_qresp( opc, ss, LDAP_SYNC_DELETE ); |
} |
} |
|
if ( !saveit && found ) { |
|
/* Decrement s_inuse, was incremented when called |
|
* with saveit == TRUE |
|
*/ |
|
syncprov_free_syncop( ss ); |
|
} |
} |
} |
ldap_pvt_thread_mutex_unlock( &si->si_ops_mutex ); |
ldap_pvt_thread_mutex_unlock( &si->si_ops_mutex ); |
|
|
Line 1327 syncprov_checkpoint( Operation *op, Slap
|
Line 1345 syncprov_checkpoint( Operation *op, Slap
|
mod.sml_nvalues = NULL; |
mod.sml_nvalues = NULL; |
mod.sml_desc = slap_schema.si_ad_contextCSN; |
mod.sml_desc = slap_schema.si_ad_contextCSN; |
mod.sml_op = LDAP_MOD_REPLACE; |
mod.sml_op = LDAP_MOD_REPLACE; |
mod.sml_flags = 0; |
mod.sml_flags = SLAP_MOD_INTERNAL; |
mod.sml_next = NULL; |
mod.sml_next = NULL; |
|
|
cb.sc_response = slap_null_cb; |
cb.sc_response = slap_null_cb; |
Line 1566 syncprov_playlog( Operation *op, SlapRep
|
Line 1584 syncprov_playlog( Operation *op, SlapRep
|
if ( delcsn[0].bv_len ) { |
if ( delcsn[0].bv_len ) { |
slap_compose_sync_cookie( op, &cookie, delcsn, srs->sr_state.rid, |
slap_compose_sync_cookie( op, &cookie, delcsn, srs->sr_state.rid, |
srs->sr_state.sid ); |
srs->sr_state.sid ); |
} |
|
|
|
Debug( LDAP_DEBUG_SYNC, "syncprov_playlog: cookie=%s\n", cookie.bv_val, 0, 0 ); |
Debug( LDAP_DEBUG_SYNC, "syncprov_playlog: cookie=%s\n", cookie.bv_val, 0, 0 ); |
|
} |
|
|
uuids[ndel].bv_val = NULL; |
uuids[ndel].bv_val = NULL; |
syncprov_sendinfo( op, rs, LDAP_TAG_SYNC_ID_SET, |
syncprov_sendinfo( op, rs, LDAP_TAG_SYNC_ID_SET, |
delcsn[0].bv_len ? &cookie : NULL, 0, uuids, 1 ); |
delcsn[0].bv_len ? &cookie : NULL, 0, uuids, 1 ); |
op->o_tmpfree( cookie.bv_val, op->o_tmpmemctx ); |
if ( delcsn[0].bv_len ) { |
|
op->o_tmpfree( cookie.bv_val, op->o_tmpmemctx ); |
|
} |
} |
} |
op->o_tmpfree( uuids, op->o_tmpmemctx ); |
op->o_tmpfree( uuids, op->o_tmpmemctx ); |
} |
} |
Line 1590 syncprov_op_response( Operation *op, Sla
|
Line 1610 syncprov_op_response( Operation *op, Sla
|
{ |
{ |
struct berval maxcsn = BER_BVNULL; |
struct berval maxcsn = BER_BVNULL; |
char cbuf[LDAP_LUTIL_CSNSTR_BUFSIZE]; |
char cbuf[LDAP_LUTIL_CSNSTR_BUFSIZE]; |
int do_check = 0, have_psearches; |
int do_check = 0, have_psearches, foundit; |
|
|
/* Update our context CSN */ |
/* Update our context CSN */ |
cbuf[0] = '\0'; |
cbuf[0] = '\0'; |
ldap_pvt_thread_rdwr_wlock( &si->si_csn_rwlock ); |
ldap_pvt_thread_rdwr_wlock( &si->si_csn_rwlock ); |
slap_get_commit_csn( op, &maxcsn ); |
slap_get_commit_csn( op, &maxcsn, &foundit ); |
if ( BER_BVISNULL( &maxcsn ) && SLAP_GLUE_SUBORDINATE( op->o_bd )) { |
if ( BER_BVISNULL( &maxcsn ) && SLAP_GLUE_SUBORDINATE( op->o_bd )) { |
/* syncrepl queues the CSN values in the db where |
/* syncrepl queues the CSN values in the db where |
* it is configured , not where the changes are made. |
* it is configured , not where the changes are made. |
Line 1604 syncprov_op_response( Operation *op, Sla
|
Line 1624 syncprov_op_response( Operation *op, Sla
|
*/ |
*/ |
BackendDB *be = op->o_bd; |
BackendDB *be = op->o_bd; |
op->o_bd = select_backend( &be->be_nsuffix[0], 1); |
op->o_bd = select_backend( &be->be_nsuffix[0], 1); |
slap_get_commit_csn( op, &maxcsn ); |
slap_get_commit_csn( op, &maxcsn, &foundit ); |
op->o_bd = be; |
op->o_bd = be; |
} |
} |
if ( !BER_BVISNULL( &maxcsn ) ) { |
if ( !BER_BVISNULL( &maxcsn ) ) { |
Line 1627 syncprov_op_response( Operation *op, Sla
|
Line 1647 syncprov_op_response( Operation *op, Sla
|
sizeof(int)); |
sizeof(int)); |
si->si_sids[i] = sid; |
si->si_sids[i] = sid; |
} |
} |
} else { |
} else if ( !foundit ) { |
/* internal ops that aren't meant to be replicated */ |
/* internal ops that aren't meant to be replicated */ |
ldap_pvt_thread_rdwr_wunlock( &si->si_csn_rwlock ); |
ldap_pvt_thread_rdwr_wunlock( &si->si_csn_rwlock ); |
return SLAP_CB_CONTINUE; |
return SLAP_CB_CONTINUE; |
} |
} |
|
|
/* Don't do any processing for consumer contextCSN updates */ |
/* Don't do any processing for consumer contextCSN updates */ |
if ( SLAP_SYNC_SHADOW( op->o_bd ) && |
if ( op->o_dont_replicate ) { |
op->o_msgid == SLAP_SYNC_UPDATE_MSGID ) { |
|
ldap_pvt_thread_rdwr_wunlock( &si->si_csn_rwlock ); |
ldap_pvt_thread_rdwr_wunlock( &si->si_csn_rwlock ); |
return SLAP_CB_CONTINUE; |
return SLAP_CB_CONTINUE; |
} |
} |
Line 1664 syncprov_op_response( Operation *op, Sla
|
Line 1683 syncprov_op_response( Operation *op, Sla
|
ldap_pvt_thread_rdwr_runlock( &si->si_csn_rwlock ); |
ldap_pvt_thread_rdwr_runlock( &si->si_csn_rwlock ); |
} |
} |
|
|
opc->sctxcsn.bv_len = maxcsn.bv_len; |
/* only update consumer ctx if this is the greatest csn */ |
opc->sctxcsn.bv_val = cbuf; |
if ( bvmatch( &maxcsn, &op->o_csn )) { |
|
opc->sctxcsn.bv_len = maxcsn.bv_len; |
|
opc->sctxcsn.bv_val = cbuf; |
|
} |
|
|
/* Handle any persistent searches */ |
/* Handle any persistent searches */ |
ldap_pvt_thread_mutex_lock( &si->si_ops_mutex ); |
ldap_pvt_thread_mutex_lock( &si->si_ops_mutex ); |
Line 1927 syncprov_detach_op( Operation *op, synco
|
Line 1949 syncprov_detach_op( Operation *op, synco
|
op2->o_time = op->o_time; |
op2->o_time = op->o_time; |
op2->o_bd = on->on_info->oi_origdb; |
op2->o_bd = on->on_info->oi_origdb; |
op2->o_request = op->o_request; |
op2->o_request = op->o_request; |
|
op2->o_managedsait = op->o_managedsait; |
LDAP_SLIST_FIRST(&op2->o_extra)->oe_key = on; |
LDAP_SLIST_FIRST(&op2->o_extra)->oe_key = on; |
LDAP_SLIST_NEXT(LDAP_SLIST_FIRST(&op2->o_extra), oe_next) = NULL; |
LDAP_SLIST_NEXT(LDAP_SLIST_FIRST(&op2->o_extra), oe_next) = NULL; |
|
|
Line 2153 syncprov_op_search( Operation *op, SlapR
|
Line 2176 syncprov_op_search( Operation *op, SlapR
|
} |
} |
|
|
srs = op->o_controls[slap_cids.sc_LDAPsync]; |
srs = op->o_controls[slap_cids.sc_LDAPsync]; |
op->o_managedsait = SLAP_CONTROL_NONCRITICAL; |
|
|
|
/* If this is a persistent search, set it up right away */ |
/* If this is a persistent search, set it up right away */ |
if ( op->o_sync_mode & SLAP_SYNC_PERSIST ) { |
if ( op->o_sync_mode & SLAP_SYNC_PERSIST ) { |
Line 2312 no_change: if ( !(op->o_sync_mode & SLA
|
Line 2334 no_change: if ( !(op->o_sync_mode & SLA
|
send_ldap_error( op, rs, LDAP_SYNC_REFRESH_REQUIRED, "sync cookie is stale" ); |
send_ldap_error( op, rs, LDAP_SYNC_REFRESH_REQUIRED, "sync cookie is stale" ); |
return rs->sr_err; |
return rs->sr_err; |
} |
} |
|
if ( srs->sr_state.ctxcsn ) { |
|
ber_bvarray_free_x( srs->sr_state.ctxcsn, op->o_tmpmemctx ); |
|
srs->sr_state.ctxcsn = NULL; |
|
} |
|
if ( srs->sr_state.sids ) { |
|
slap_sl_free( srs->sr_state.sids, op->o_tmpmemctx ); |
|
srs->sr_state.sids = NULL; |
|
} |
|
srs->sr_state.numcsns = 0; |
} else { |
} else { |
gotstate = 1; |
gotstate = 1; |
/* If changed and doing Present lookup, send Present UUIDs */ |
/* If changed and doing Present lookup, send Present UUIDs */ |
Line 2490 static ConfigOCs spocs[] = {
|
Line 2521 static ConfigOCs spocs[] = {
|
"NAME 'olcSyncProvConfig' " |
"NAME 'olcSyncProvConfig' " |
"DESC 'SyncRepl Provider configuration' " |
"DESC 'SyncRepl Provider configuration' " |
"SUP olcOverlayConfig " |
"SUP olcOverlayConfig " |
"MAY ( olcSpCheckpoint $ olcSpSessionlog $ olcSpNoPresent ) )", |
"MAY ( olcSpCheckpoint " |
|
"$ olcSpSessionlog " |
|
"$ olcSpNoPresent " |
|
"$ olcSpReloadHint " |
|
") )", |
Cft_Overlay, spcfg }, |
Cft_Overlay, spcfg }, |
{ NULL, 0, NULL } |
{ NULL, 0, NULL } |
}; |
}; |
Line 2509 sp_cf_gen(ConfigArgs *c)
|
Line 2544 sp_cf_gen(ConfigArgs *c)
|
struct berval bv; |
struct berval bv; |
bv.bv_len = snprintf( c->cr_msg, sizeof( c->cr_msg ), |
bv.bv_len = snprintf( c->cr_msg, sizeof( c->cr_msg ), |
"%d %d", si->si_chkops, si->si_chktime ); |
"%d %d", si->si_chkops, si->si_chktime ); |
if ( bv.bv_len < 0 || bv.bv_len >= sizeof( c->cr_msg ) ) { |
if ( bv.bv_len >= sizeof( c->cr_msg ) ) { |
rc = 1; |
rc = 1; |
} else { |
} else { |
bv.bv_val = c->cr_msg; |
bv.bv_val = c->cr_msg; |
Line 2703 syncprov_db_open(
|
Line 2738 syncprov_db_open(
|
si->si_sids = slap_parse_csn_sids( si->si_ctxcsn, a->a_numvals, NULL ); |
si->si_sids = slap_parse_csn_sids( si->si_ctxcsn, a->a_numvals, NULL ); |
} |
} |
overlay_entry_release_ov( op, e, 0, on ); |
overlay_entry_release_ov( op, e, 0, on ); |
if ( si->si_ctxcsn ) { |
if ( si->si_ctxcsn && !SLAP_DBCLEAN( be )) { |
op->o_req_dn = be->be_suffix[0]; |
op->o_req_dn = be->be_suffix[0]; |
op->o_req_ndn = be->be_nsuffix[0]; |
op->o_req_ndn = be->be_nsuffix[0]; |
op->ors_scope = LDAP_SCOPE_SUBTREE; |
op->ors_scope = LDAP_SCOPE_SUBTREE; |