version 1.56.2.39, 2006/12/16 00:26:41
|
version 1.135, 2005/12/07 11:09:00
|
Line 1
|
Line 1
|
/* $OpenLDAP: pkg/ldap/servers/slapd/overlays/syncprov.c,v 1.56.2.38 2006/10/31 18:32:36 hyc Exp $ */ |
/* $OpenLDAP: pkg/ldap/servers/slapd/overlays/syncprov.c,v 1.134 2005/12/07 08:51:12 ando 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-2006 The OpenLDAP Foundation. |
* Copyright 2004-2005 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 65 typedef struct syncops {
|
Line 65 typedef struct syncops {
|
#define PS_IS_DETACHED 0x02 |
#define PS_IS_DETACHED 0x02 |
#define PS_WROTE_BASE 0x04 |
#define PS_WROTE_BASE 0x04 |
#define PS_FIND_BASE 0x08 |
#define PS_FIND_BASE 0x08 |
#define PS_FIX_FILTER 0x10 |
|
|
|
int s_inuse; /* reference count */ |
int s_inuse; /* reference count */ |
struct syncres *s_res; |
struct syncres *s_res; |
Line 822 syncprov_qplay( Operation *op, slap_over
|
Line 821 syncprov_qplay( Operation *op, slap_over
|
syncres *sr; |
syncres *sr; |
Entry *e; |
Entry *e; |
opcookie opc; |
opcookie opc; |
int rc = 0; |
int rc; |
|
|
opc.son = on; |
opc.son = on; |
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
Line 898 syncprov_qtask( void *ctx, void *arg )
|
Line 897 syncprov_qtask( void *ctx, void *arg )
|
op->o_private = NULL; |
op->o_private = NULL; |
op->o_callback = NULL; |
op->o_callback = NULL; |
|
|
(void)syncprov_qplay( op, on, so ); |
syncprov_qplay( op, on, so ); |
|
|
/* decrement use count... */ |
/* decrement use count... */ |
syncprov_free_syncop( so ); |
syncprov_free_syncop( so ); |
Line 912 syncprov_qtask( void *ctx, void *arg )
|
Line 911 syncprov_qtask( void *ctx, void *arg )
|
return NULL; |
return NULL; |
} |
} |
|
|
/* Start the task to play back queued psearch responses */ |
|
static void |
|
syncprov_qstart( syncops *so ) |
|
{ |
|
int wake=0; |
|
ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); |
|
if ( !so->s_qtask ) { |
|
so->s_qtask = ldap_pvt_runqueue_insert( &slapd_rq, RUNQ_INTERVAL, |
|
syncprov_qtask, so, "syncprov_qtask", |
|
so->s_op->o_conn->c_peer_name.bv_val ); |
|
++so->s_inuse; |
|
wake = 1; |
|
} else { |
|
if (!ldap_pvt_runqueue_isrunning( &slapd_rq, so->s_qtask ) && |
|
!so->s_qtask->next_sched.tv_sec ) { |
|
so->s_qtask->interval.tv_sec = 0; |
|
ldap_pvt_runqueue_resched( &slapd_rq, so->s_qtask, 0 ); |
|
so->s_qtask->interval.tv_sec = RUNQ_INTERVAL; |
|
++so->s_inuse; |
|
wake = 1; |
|
} |
|
} |
|
ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); |
|
if ( wake ) |
|
slap_wake_listener(); |
|
} |
|
|
|
/* Queue a persistent search response */ |
/* Queue a persistent search response */ |
static int |
static int |
syncprov_qresp( opcookie *opc, syncops *so, int mode ) |
syncprov_qresp( opcookie *opc, syncops *so, int mode ) |
Line 977 syncprov_qresp( opcookie *opc, syncops *
|
Line 949 syncprov_qresp( opcookie *opc, syncops *
|
so->s_flags |= PS_FIND_BASE; |
so->s_flags |= PS_FIND_BASE; |
} |
} |
if ( so->s_flags & PS_IS_DETACHED ) { |
if ( so->s_flags & PS_IS_DETACHED ) { |
syncprov_qstart( so ); |
ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); |
|
if ( !so->s_qtask ) { |
|
so->s_qtask = ldap_pvt_runqueue_insert( &slapd_rq, RUNQ_INTERVAL, |
|
syncprov_qtask, so, "syncprov_qtask", |
|
so->s_op->o_conn->c_peer_name.bv_val ); |
|
++so->s_inuse; |
|
} else { |
|
if (!ldap_pvt_runqueue_isrunning( &slapd_rq, so->s_qtask ) && |
|
!so->s_qtask->next_sched.tv_sec ) { |
|
so->s_qtask->interval.tv_sec = 0; |
|
ldap_pvt_runqueue_resched( &slapd_rq, so->s_qtask, 0 ); |
|
so->s_qtask->interval.tv_sec = RUNQ_INTERVAL; |
|
++so->s_inuse; |
|
} |
|
} |
|
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 ); |
return LDAP_SUCCESS; |
return LDAP_SUCCESS; |
Line 1063 syncprov_matchops( Operation *op, opcook
|
Line 1050 syncprov_matchops( Operation *op, opcook
|
int rc; |
int rc; |
struct berval newdn; |
struct berval newdn; |
int freefdn = 0; |
int freefdn = 0; |
BackendDB *b0 = op->o_bd, db; |
|
|
|
fc.fdn = &op->o_req_ndn; |
fc.fdn = &op->o_req_ndn; |
/* compute new DN */ |
/* compute new DN */ |
Line 1076 syncprov_matchops( Operation *op, opcook
|
Line 1062 syncprov_matchops( Operation *op, opcook
|
freefdn = 1; |
freefdn = 1; |
} |
} |
if ( op->o_tag != LDAP_REQ_ADD ) { |
if ( op->o_tag != LDAP_REQ_ADD ) { |
if ( !SLAP_ISOVERLAY( op->o_bd )) { |
|
db = *op->o_bd; |
|
op->o_bd = &db; |
|
} |
|
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
rc = be_entry_get_rw( op, fc.fdn, NULL, NULL, 0, &e ); |
rc = be_entry_get_rw( op, fc.fdn, NULL, NULL, 0, &e ); |
/* If we're sending responses now, make a copy and unlock the DB */ |
/* If we're sending responses now, make a copy and unlock the DB */ |
Line 1089 syncprov_matchops( Operation *op, opcook
|
Line 1071 syncprov_matchops( Operation *op, opcook
|
e = e2; |
e = e2; |
} |
} |
op->o_bd->bd_info = (BackendInfo *)on; |
op->o_bd->bd_info = (BackendInfo *)on; |
if ( rc ) { |
if ( rc ) return; |
op->o_bd = b0; |
|
return; |
|
} |
|
} else { |
} else { |
e = op->ora_e; |
e = op->ora_e; |
} |
} |
Line 1190 syncprov_matchops( Operation *op, opcook
|
Line 1169 syncprov_matchops( Operation *op, opcook
|
if ( freefdn ) { |
if ( freefdn ) { |
op->o_tmpfree( fc.fdn->bv_val, op->o_tmpmemctx ); |
op->o_tmpfree( fc.fdn->bv_val, op->o_tmpmemctx ); |
} |
} |
op->o_bd = b0; |
|
} |
} |
|
|
static int |
static int |
Line 1243 syncprov_op_cleanup( Operation *op, Slap
|
Line 1221 syncprov_op_cleanup( Operation *op, Slap
|
} |
} |
|
|
static void |
static void |
syncprov_checkpoint( Operation *op, SlapReply *rs, slap_overinst *on, |
syncprov_checkpoint( Operation *op, SlapReply *rs, slap_overinst *on ) |
struct berval *csn ) |
|
{ |
{ |
|
syncprov_info_t *si = on->on_bi.bi_private; |
Modifications mod; |
Modifications mod; |
Operation opm; |
Operation opm; |
SlapReply rsm = { 0 }; |
SlapReply rsm = { 0 }; |
struct berval bv[2]; |
struct berval bv[2]; |
slap_callback cb = {0}; |
slap_callback cb = {0}; |
|
|
/* If ctxcsn is empty, delete it */ |
mod.sml_values = bv; |
if ( BER_BVISEMPTY( csn )) { |
bv[1].bv_val = NULL; |
mod.sml_values = NULL; |
bv[0] = si->si_ctxcsn; |
} else { |
|
mod.sml_values = bv; |
|
bv[1].bv_val = NULL; |
|
bv[0] = *csn; |
|
} |
|
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; |
Line 1284 syncprov_checkpoint( Operation *op, Slap
|
Line 1257 syncprov_checkpoint( Operation *op, Slap
|
} |
} |
|
|
static void |
static void |
syncprov_add_slog( Operation *op ) |
syncprov_add_slog( Operation *op, struct berval *csn ) |
{ |
{ |
opcookie *opc = op->o_callback->sc_private; |
opcookie *opc = op->o_callback->sc_private; |
slap_overinst *on = opc->son; |
slap_overinst *on = opc->son; |
Line 1296 syncprov_add_slog( Operation *op )
|
Line 1269 syncprov_add_slog( Operation *op )
|
{ |
{ |
/* Allocate a record. UUIDs are not NUL-terminated. */ |
/* Allocate a record. UUIDs are not NUL-terminated. */ |
se = ch_malloc( sizeof( slog_entry ) + opc->suuid.bv_len + |
se = ch_malloc( sizeof( slog_entry ) + opc->suuid.bv_len + |
op->o_csn.bv_len + 1 ); |
csn->bv_len + 1 ); |
se->se_next = NULL; |
se->se_next = NULL; |
se->se_tag = op->o_tag; |
se->se_tag = op->o_tag; |
|
|
se->se_uuid.bv_val = (char *)(&se[1]); |
se->se_uuid.bv_val = (char *)(se+1); |
AC_MEMCPY( se->se_uuid.bv_val, opc->suuid.bv_val, opc->suuid.bv_len ); |
AC_MEMCPY( se->se_uuid.bv_val, opc->suuid.bv_val, opc->suuid.bv_len ); |
se->se_uuid.bv_len = opc->suuid.bv_len; |
se->se_uuid.bv_len = opc->suuid.bv_len; |
|
|
se->se_csn.bv_val = se->se_uuid.bv_val + opc->suuid.bv_len; |
se->se_csn.bv_val = se->se_uuid.bv_val + opc->suuid.bv_len; |
AC_MEMCPY( se->se_csn.bv_val, op->o_csn.bv_val, op->o_csn.bv_len ); |
AC_MEMCPY( se->se_csn.bv_val, csn->bv_val, csn->bv_len ); |
se->se_csn.bv_val[op->o_csn.bv_len] = '\0'; |
se->se_csn.bv_val[csn->bv_len] = '\0'; |
se->se_csn.bv_len = op->o_csn.bv_len; |
se->se_csn.bv_len = csn->bv_len; |
|
|
ldap_pvt_thread_mutex_lock( &sl->sl_mutex ); |
ldap_pvt_thread_mutex_lock( &sl->sl_mutex ); |
if ( sl->sl_head ) { |
if ( sl->sl_head ) { |
Line 1324 syncprov_add_slog( Operation *op )
|
Line 1297 syncprov_add_slog( Operation *op )
|
sl->sl_mincsn.bv_len = se->se_csn.bv_len; |
sl->sl_mincsn.bv_len = se->se_csn.bv_len; |
ch_free( se ); |
ch_free( se ); |
sl->sl_num--; |
sl->sl_num--; |
|
if ( !sl->sl_head ) { |
|
sl->sl_tail = NULL; |
|
} |
} |
} |
ldap_pvt_thread_mutex_unlock( &sl->sl_mutex ); |
ldap_pvt_thread_mutex_unlock( &sl->sl_mutex ); |
} |
} |
Line 1342 playlog_cb( Operation *op, SlapReply *rs
|
Line 1318 playlog_cb( Operation *op, SlapReply *rs
|
/* enter with sl->sl_mutex locked, release before returning */ |
/* enter with sl->sl_mutex locked, release before returning */ |
static void |
static void |
syncprov_playlog( Operation *op, SlapReply *rs, sessionlog *sl, |
syncprov_playlog( Operation *op, SlapReply *rs, sessionlog *sl, |
sync_control *srs, struct berval *ctxcsn ) |
struct berval *oldcsn, struct berval *ctxcsn ) |
{ |
{ |
slap_overinst *on = (slap_overinst *)op->o_bd->bd_info; |
slap_overinst *on = (slap_overinst *)op->o_bd->bd_info; |
slog_entry *se; |
slog_entry *se; |
int i, j, ndel, num, nmods, mmods; |
int i, j, ndel, num, nmods, mmods; |
char cbuf[LDAP_LUTIL_CSNSTR_BUFSIZE]; |
|
BerVarray uuids; |
BerVarray uuids; |
struct berval delcsn; |
|
|
|
if ( !sl->sl_num ) { |
if ( !sl->sl_num ) { |
ldap_pvt_thread_mutex_unlock( &sl->sl_mutex ); |
ldap_pvt_thread_mutex_unlock( &sl->sl_mutex ); |
Line 1362 syncprov_playlog( Operation *op, SlapRep
|
Line 1336 syncprov_playlog( Operation *op, SlapRep
|
|
|
uuids = op->o_tmpalloc( (num+1) * sizeof( struct berval ) + |
uuids = op->o_tmpalloc( (num+1) * sizeof( struct berval ) + |
num * UUID_LEN, op->o_tmpmemctx ); |
num * UUID_LEN, op->o_tmpmemctx ); |
uuids[0].bv_val = (char *)(uuids + num + 1); |
|
|
|
delcsn.bv_len = 0; |
uuids[0].bv_val = (char *)(uuids + num + 1); |
delcsn.bv_val = cbuf; |
|
|
|
/* Make a copy of the relevant UUIDs. Put the Deletes up front |
/* Make a copy of the relevant UUIDs. Put the Deletes up front |
* and everything else at the end. Do this first so we can |
* and everything else at the end. Do this first so we can |
* unlock the list mutex. |
* unlock the list mutex. |
*/ |
*/ |
for ( se=sl->sl_head; se; se=se->se_next ) { |
for ( se=sl->sl_head; se; se=se->se_next ) { |
if ( ber_bvcmp( &se->se_csn, &srs->sr_state.ctxcsn ) <= 0 ) continue; |
if ( ber_bvcmp( &se->se_csn, oldcsn ) < 0 ) continue; |
if ( ber_bvcmp( &se->se_csn, ctxcsn ) > 0 ) break; |
if ( ber_bvcmp( &se->se_csn, ctxcsn ) > 0 ) break; |
if ( se->se_tag == LDAP_REQ_DELETE ) { |
if ( se->se_tag == LDAP_REQ_DELETE ) { |
j = i; |
j = i; |
i++; |
i++; |
AC_MEMCPY( cbuf, se->se_csn.bv_val, se->se_csn.bv_len ); |
|
delcsn.bv_len = se->se_csn.bv_len; |
|
delcsn.bv_val[delcsn.bv_len] = '\0'; |
|
} else { |
} else { |
nmods++; |
nmods++; |
j = num - nmods; |
j = num - nmods; |
Line 1460 syncprov_playlog( Operation *op, SlapRep
|
Line 1429 syncprov_playlog( Operation *op, SlapRep
|
mf.f_av_value = uuids[i]; |
mf.f_av_value = uuids[i]; |
cb.sc_private = NULL; |
cb.sc_private = NULL; |
fop.ors_slimit = 1; |
fop.ors_slimit = 1; |
frs.sr_nentries = 0; |
|
rc = fop.o_bd->be_search( &fop, &frs ); |
rc = fop.o_bd->be_search( &fop, &frs ); |
|
|
/* If entry was not found, add to delete list */ |
/* If entry was not found, add to delete list */ |
Line 1471 syncprov_playlog( Operation *op, SlapRep
|
Line 1439 syncprov_playlog( Operation *op, SlapRep
|
fop.o_bd->bd_info = (BackendInfo *)on; |
fop.o_bd->bd_info = (BackendInfo *)on; |
} |
} |
if ( ndel ) { |
if ( ndel ) { |
struct berval cookie; |
|
|
|
slap_compose_sync_cookie( op, &cookie, &delcsn, srs->sr_state.rid ); |
|
uuids[ndel].bv_val = NULL; |
uuids[ndel].bv_val = NULL; |
syncprov_sendinfo( op, rs, LDAP_TAG_SYNC_ID_SET, &cookie, 0, uuids, 1 ); |
syncprov_sendinfo( op, rs, LDAP_TAG_SYNC_ID_SET, NULL, 0, uuids, 1 ); |
op->o_tmpfree( cookie.bv_val, op->o_tmpmemctx ); |
|
} |
} |
op->o_tmpfree( uuids, op->o_tmpmemctx ); |
|
} |
} |
|
|
static int |
static int |
Line 1491 syncprov_op_response( Operation *op, Sla
|
Line 1454 syncprov_op_response( Operation *op, Sla
|
|
|
if ( rs->sr_err == LDAP_SUCCESS ) |
if ( rs->sr_err == LDAP_SUCCESS ) |
{ |
{ |
struct berval maxcsn = BER_BVNULL; |
struct berval maxcsn = BER_BVNULL, curcsn = BER_BVNULL; |
char cbuf[LDAP_LUTIL_CSNSTR_BUFSIZE]; |
char cbuf[LDAP_LUTIL_CSNSTR_BUFSIZE]; |
int do_check = 0; |
|
|
|
/* Update our context CSN */ |
/* Update our context CSN */ |
cbuf[0] = '\0'; |
cbuf[0] = '\0'; |
ldap_pvt_thread_mutex_lock( &si->si_csn_mutex ); |
ldap_pvt_thread_mutex_lock( &si->si_csn_mutex ); |
slap_get_commit_csn( op, &maxcsn ); |
slap_get_commit_csn( op, &maxcsn, &curcsn ); |
if ( !BER_BVISNULL( &maxcsn ) ) { |
if ( !BER_BVISNULL( &maxcsn ) ) { |
strcpy( cbuf, maxcsn.bv_val ); |
strcpy( cbuf, maxcsn.bv_val ); |
if ( ber_bvcmp( &maxcsn, &si->si_ctxcsn ) > 0 ) { |
if ( ber_bvcmp( &maxcsn, &si->si_ctxcsn ) > 0 ) { |
Line 1516 syncprov_op_response( Operation *op, Sla
|
Line 1478 syncprov_op_response( Operation *op, Sla
|
|
|
si->si_numops++; |
si->si_numops++; |
if ( si->si_chkops || si->si_chktime ) { |
if ( si->si_chkops || si->si_chktime ) { |
|
int do_check=0; |
if ( si->si_chkops && si->si_numops >= si->si_chkops ) { |
if ( si->si_chkops && si->si_numops >= si->si_chkops ) { |
do_check = 1; |
do_check = 1; |
si->si_numops = 0; |
si->si_numops = 0; |
Line 1525 syncprov_op_response( Operation *op, Sla
|
Line 1488 syncprov_op_response( Operation *op, Sla
|
do_check = 1; |
do_check = 1; |
si->si_chklast = op->o_time; |
si->si_chklast = op->o_time; |
} |
} |
|
if ( do_check ) { |
|
syncprov_checkpoint( op, rs, on ); |
|
} |
} |
} |
ldap_pvt_thread_mutex_unlock( &si->si_csn_mutex ); |
ldap_pvt_thread_mutex_unlock( &si->si_csn_mutex ); |
|
|
opc->sctxcsn.bv_len = maxcsn.bv_len; |
opc->sctxcsn.bv_len = maxcsn.bv_len; |
opc->sctxcsn.bv_val = cbuf; |
opc->sctxcsn.bv_val = cbuf; |
|
|
if ( do_check ) { |
|
syncprov_checkpoint( op, rs, on, &opc->sctxcsn ); |
|
} |
|
|
|
/* Handle any persistent searches */ |
/* Handle any persistent searches */ |
if ( si->si_ops ) { |
if ( si->si_ops ) { |
switch(op->o_tag) { |
switch(op->o_tag) { |
Line 1559 syncprov_op_response( Operation *op, Sla
|
Line 1521 syncprov_op_response( Operation *op, Sla
|
|
|
/* Add any log records */ |
/* Add any log records */ |
if ( si->si_logs && op->o_tag != LDAP_REQ_ADD ) { |
if ( si->si_logs && op->o_tag != LDAP_REQ_ADD ) { |
syncprov_add_slog( op ); |
syncprov_add_slog( op, &curcsn ); |
} |
} |
|
|
} |
} |
Line 1794 syncprov_detach_op( Operation *op, synco
|
Line 1756 syncprov_detach_op( Operation *op, synco
|
op2->ors_filterstr.bv_val = ptr; |
op2->ors_filterstr.bv_val = ptr; |
strcpy( ptr, so->s_filterstr.bv_val ); |
strcpy( ptr, so->s_filterstr.bv_val ); |
op2->ors_filterstr.bv_len = so->s_filterstr.bv_len; |
op2->ors_filterstr.bv_len = so->s_filterstr.bv_len; |
|
op2->ors_filter = str2filter( ptr ); |
/* Skip the AND/GE clause that we stuck on in front */ |
|
if ( so->s_flags & PS_FIX_FILTER ) { |
|
op2->ors_filter = op->ors_filter->f_and->f_next; |
|
so->s_flags ^= PS_FIX_FILTER; |
|
} else { |
|
op2->ors_filter = op->ors_filter; |
|
} |
|
op2->ors_filter = filter_dup( op2->ors_filter, NULL ); |
|
so->s_op = op2; |
so->s_op = op2; |
|
|
/* Copy any cached group ACLs individually */ |
/* Copy any cached group ACLs individually */ |
Line 1824 syncprov_detach_op( Operation *op, synco
|
Line 1778 syncprov_detach_op( Operation *op, synco
|
LDAP_STAILQ_INSERT_TAIL( &op->o_conn->c_ops, op2, o_next ); |
LDAP_STAILQ_INSERT_TAIL( &op->o_conn->c_ops, op2, o_next ); |
so->s_flags |= PS_IS_DETACHED; |
so->s_flags |= PS_IS_DETACHED; |
ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex ); |
ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex ); |
|
|
/* Prevent anyone else from trying to send a result for this op */ |
|
op->o_abandon = 1; |
|
} |
} |
|
|
static int |
static int |
Line 1853 syncprov_search_response( Operation *op,
|
Line 1804 syncprov_search_response( Operation *op,
|
a = attr_find( rs->sr_operational_attrs, slap_schema.si_ad_entryCSN ); |
a = attr_find( rs->sr_operational_attrs, slap_schema.si_ad_entryCSN ); |
} |
} |
if ( a ) { |
if ( a ) { |
/* Make sure entry is less than the snapshot'd contextCSN */ |
/* Make sure entry is less than the snaphot'd contextCSN */ |
if ( ber_bvcmp( &a->a_nvals[0], &ss->ss_ctxcsn ) > 0 ) { |
if ( ber_bvcmp( &a->a_nvals[0], &ss->ss_ctxcsn ) > 0 ) |
Debug( LDAP_DEBUG_SYNC, "Entry %s CSN %s greater than snapshot %s\n", |
|
rs->sr_entry->e_name.bv_val, |
|
a->a_nvals[0].bv_val, |
|
ss->ss_ctxcsn.bv_val ); |
|
return LDAP_SUCCESS; |
return LDAP_SUCCESS; |
} |
|
|
|
/* Don't send the ctx entry twice */ |
/* Don't send the ctx entry twice */ |
if ( !BER_BVISNULL( &srs->sr_state.ctxcsn ) && |
if ( !BER_BVISNULL( &srs->sr_state.ctxcsn ) && |
bvmatch( &a->a_nvals[0], &srs->sr_state.ctxcsn ) ) { |
bvmatch( &a->a_nvals[0], &srs->sr_state.ctxcsn ) ) |
Debug( LDAP_DEBUG_SYNC, "Entry %s CSN %s matches ctx %s\n", |
|
rs->sr_entry->e_name.bv_val, |
|
a->a_nvals[0].bv_val, |
|
srs->sr_state.ctxcsn.bv_val ); |
|
return LDAP_SUCCESS; |
return LDAP_SUCCESS; |
} |
|
} |
} |
rs->sr_ctrls = op->o_tmpalloc( sizeof(LDAPControl *)*2, |
rs->sr_ctrls = op->o_tmpalloc( sizeof(LDAPControl *)*2, |
op->o_tmpmemctx ); |
op->o_tmpmemctx ); |
Line 1894 syncprov_search_response( Operation *op,
|
Line 1835 syncprov_search_response( Operation *op,
|
op->o_tmpfree( cookie.bv_val, op->o_tmpmemctx ); |
op->o_tmpfree( cookie.bv_val, op->o_tmpmemctx ); |
} else { |
} else { |
/* It's RefreshAndPersist, transition to Persist phase */ |
/* It's RefreshAndPersist, transition to Persist phase */ |
syncprov_sendinfo( op, rs, ss->ss_present ? |
syncprov_sendinfo( op, rs, ( ss->ss_present && rs->sr_nentries ) ? |
LDAP_TAG_SYNC_REFRESH_PRESENT : LDAP_TAG_SYNC_REFRESH_DELETE, |
LDAP_TAG_SYNC_REFRESH_PRESENT : LDAP_TAG_SYNC_REFRESH_DELETE, |
&cookie, 1, NULL, 0 ); |
&cookie, 1, NULL, 0 ); |
op->o_tmpfree( cookie.bv_val, op->o_tmpmemctx ); |
op->o_tmpfree( cookie.bv_val, op->o_tmpmemctx ); |
Line 1906 syncprov_search_response( Operation *op,
|
Line 1847 syncprov_search_response( Operation *op,
|
ss->ss_so->s_flags ^= PS_IS_REFRESHING; |
ss->ss_so->s_flags ^= PS_IS_REFRESHING; |
|
|
syncprov_detach_op( op, ss->ss_so, on ); |
syncprov_detach_op( op, ss->ss_so, on ); |
|
|
/* If there are queued responses, fire them off */ |
|
if ( ss->ss_so->s_res ) |
|
syncprov_qstart( ss->ss_so ); |
|
ldap_pvt_thread_mutex_unlock( &ss->ss_so->s_mutex ); |
ldap_pvt_thread_mutex_unlock( &ss->ss_so->s_mutex ); |
|
|
return LDAP_SUCCESS; |
return LDAP_SUCCESS; |
Line 1959 syncprov_op_search( Operation *op, SlapR
|
Line 1896 syncprov_op_search( Operation *op, SlapR
|
/* syncprov_findbase expects to be called as a callback... */ |
/* syncprov_findbase expects to be called as a callback... */ |
sc.sc_private = &opc; |
sc.sc_private = &opc; |
opc.son = on; |
opc.son = on; |
ldap_pvt_thread_mutex_init( &so.s_mutex ); |
|
cb = op->o_callback; |
cb = op->o_callback; |
op->o_callback = ≻ |
op->o_callback = ≻ |
rs->sr_err = syncprov_findbase( op, &fc ); |
rs->sr_err = syncprov_findbase( op, &fc ); |
op->o_callback = cb; |
op->o_callback = cb; |
ldap_pvt_thread_mutex_destroy( &so.s_mutex ); |
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) { |
if ( rs->sr_err != LDAP_SUCCESS ) { |
send_ldap_result( op, rs ); |
send_ldap_result( op, rs ); |
Line 2017 syncprov_op_search( Operation *op, SlapR
|
Line 1952 syncprov_op_search( Operation *op, SlapR
|
sl=si->si_logs; |
sl=si->si_logs; |
if ( sl ) { |
if ( sl ) { |
ldap_pvt_thread_mutex_lock( &sl->sl_mutex ); |
ldap_pvt_thread_mutex_lock( &sl->sl_mutex ); |
/* Are there any log entries, and is the consumer state |
if ( ber_bvcmp( &srs->sr_state.ctxcsn, &sl->sl_mincsn ) >= 0 ) { |
* present in the session log? |
|
*/ |
|
if ( sl->sl_num > 0 && ber_bvcmp( &srs->sr_state.ctxcsn, &sl->sl_mincsn ) >= 0 ) { |
|
do_present = 0; |
do_present = 0; |
/* mutex is unlocked in playlog */ |
/* mutex is unlocked in playlog */ |
syncprov_playlog( op, rs, sl, srs, &ctxcsn ); |
syncprov_playlog( op, rs, sl, &srs->sr_state.ctxcsn, &ctxcsn ); |
} else { |
} else { |
ldap_pvt_thread_mutex_unlock( &sl->sl_mutex ); |
ldap_pvt_thread_mutex_unlock( &sl->sl_mutex ); |
} |
} |
Line 2074 shortcut:
|
Line 2006 shortcut:
|
fava->f_next = op->ors_filter; |
fava->f_next = op->ors_filter; |
op->ors_filter = fand; |
op->ors_filter = fand; |
filter2bv_x( op, op->ors_filter, &op->ors_filterstr ); |
filter2bv_x( op, op->ors_filter, &op->ors_filterstr ); |
if ( sop ) |
|
sop->s_flags |= PS_FIX_FILTER; |
|
} |
} |
|
|
/* Let our callback add needed info to returned entries */ |
/* Let our callback add needed info to returned entries */ |
Line 2349 syncprov_db_open(
|
Line 2279 syncprov_db_open(
|
slap_overinst *on = (slap_overinst *) be->bd_info; |
slap_overinst *on = (slap_overinst *) be->bd_info; |
syncprov_info_t *si = (syncprov_info_t *)on->on_bi.bi_private; |
syncprov_info_t *si = (syncprov_info_t *)on->on_bi.bi_private; |
|
|
Connection conn = { 0 }; |
Connection conn; |
OperationBuffer opbuf = { 0 }; |
OperationBuffer opbuf; |
char ctxcsnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE]; |
char ctxcsnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE]; |
Operation *op = (Operation *) &opbuf; |
Operation *op = (Operation *) &opbuf; |
Entry *e; |
Entry *e; |
Line 2358 syncprov_db_open(
|
Line 2288 syncprov_db_open(
|
int rc; |
int rc; |
void *thrctx = NULL; |
void *thrctx = NULL; |
|
|
if ( !SLAP_LASTMOD( be )) { |
|
Debug( LDAP_DEBUG_ANY, |
|
"syncprov_db_open: invalid config, lastmod must be enabled\n", 0, 0, 0 ); |
|
return -1; |
|
} |
|
|
|
if ( slapMode & SLAP_TOOL_MODE ) { |
if ( slapMode & SLAP_TOOL_MODE ) { |
return 0; |
return 0; |
} |
} |
Line 2407 syncprov_db_open(
|
Line 2331 syncprov_db_open(
|
ldap_pvt_thread_create( &tid, 0, syncprov_db_otask, op ); |
ldap_pvt_thread_create( &tid, 0, syncprov_db_otask, op ); |
ldap_pvt_thread_join( tid, NULL ); |
ldap_pvt_thread_join( tid, NULL ); |
} |
} |
} |
} else if ( SLAP_SYNC_SHADOW( op->o_bd )) { |
|
/* If we're also a consumer, and we didn't find the context entry, |
if ( BER_BVISEMPTY( &si->si_ctxcsn ) ) { |
|
if ( SLAP_SYNC_SHADOW( op->o_bd )) { |
|
/* If we're also a consumer, and we didn't get a contextCSN, |
|
* then don't generate anything, wait for our provider to send it |
* then don't generate anything, wait for our provider to send it |
* to us. |
* to us. |
*/ |
*/ |
goto out; |
goto out; |
} |
} |
|
|
|
if ( BER_BVISEMPTY( &si->si_ctxcsn ) ) { |
si->si_ctxcsn.bv_len = sizeof( si->si_ctxcsnbuf ); |
si->si_ctxcsn.bv_len = sizeof( si->si_ctxcsnbuf ); |
slap_get_csn( op, &si->si_ctxcsn, 0 ); |
slap_get_csn( op, &si->si_ctxcsn, 0 ); |
} |
} |
Line 2459 syncprov_db_close(
|
Line 2382 syncprov_db_close(
|
op->o_bd = be; |
op->o_bd = be; |
op->o_dn = be->be_rootdn; |
op->o_dn = be->be_rootdn; |
op->o_ndn = be->be_rootndn; |
op->o_ndn = be->be_rootndn; |
syncprov_checkpoint( op, &rs, on, &si->si_ctxcsn ); |
syncprov_checkpoint( op, &rs, on ); |
ldap_pvt_thread_pool_context_reset( thrctx ); |
ldap_pvt_thread_pool_context_reset( thrctx ); |
} |
} |
|
|
Line 2474 syncprov_db_init(
|
Line 2397 syncprov_db_init(
|
slap_overinst *on = (slap_overinst *)be->bd_info; |
slap_overinst *on = (slap_overinst *)be->bd_info; |
syncprov_info_t *si; |
syncprov_info_t *si; |
|
|
if ( SLAP_ISGLOBALOVERLAY( be ) ) { |
|
Debug( LDAP_DEBUG_ANY, |
|
"syncprov must be instantiated within a database.\n", |
|
0, 0, 0 ); |
|
return 1; |
|
} |
|
|
|
si = ch_calloc(1, sizeof(syncprov_info_t)); |
si = ch_calloc(1, sizeof(syncprov_info_t)); |
on->on_bi.bi_private = si; |
on->on_bi.bi_private = si; |
ldap_pvt_thread_mutex_init( &si->si_csn_mutex ); |
ldap_pvt_thread_mutex_init( &si->si_csn_mutex ); |
Line 2509 syncprov_db_destroy(
|
Line 2425 syncprov_db_destroy(
|
|
|
if ( si ) { |
if ( si ) { |
if ( si->si_logs ) { |
if ( si->si_logs ) { |
slog_entry *se = si->si_logs->sl_head; |
|
|
|
while ( se ) { |
|
slog_entry *se_next = se->se_next; |
|
ch_free( se ); |
|
se = se_next; |
|
} |
|
|
|
ch_free( si->si_logs ); |
ch_free( si->si_logs ); |
} |
} |
ldap_pvt_thread_mutex_destroy( &si->si_mods_mutex ); |
ldap_pvt_thread_mutex_destroy( &si->si_mods_mutex ); |
Line 2642 syncprov_initialize()
|
Line 2550 syncprov_initialize()
|
int rc; |
int rc; |
|
|
rc = register_supported_control( LDAP_CONTROL_SYNC, |
rc = register_supported_control( LDAP_CONTROL_SYNC, |
SLAP_CTRL_SEARCH, NULL, |
SLAP_CTRL_HIDE|SLAP_CTRL_SEARCH, NULL, |
syncprov_parseCtrl, &slap_cids.sc_LDAPsync ); |
syncprov_parseCtrl, &slap_cids.sc_LDAPsync ); |
if ( rc != LDAP_SUCCESS ) { |
if ( rc != LDAP_SUCCESS ) { |
Debug( LDAP_DEBUG_ANY, |
Debug( LDAP_DEBUG_ANY, |