#include <ac/string.h>
#include "lutil.h"
#include "slap.h"
+#include "config.h"
/* A modify request on a particular entry */
typedef struct modinst {
{
Attribute* a;
int ret;
- int res;
- const char *text = NULL;
BerElementBuffer berbuf;
BerElement *ber = (BerElement *)&berbuf;
{
opcookie *opc = op->o_callback->sc_private;
slap_overinst *on = opc->son;
- syncprov_info_t *si = on->on_bi.bi_private;
slap_callback cb = {0};
Operation fop;
SlapReply frs = { REP_RESULT };
char buf[LDAP_LUTIL_CSNSTR_BUFSIZE + STRLENOF("(entryCSN<=)")];
char cbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
- struct berval fbuf, maxcsn;
+ struct berval maxcsn;
Filter cf, af;
#ifdef LDAP_COMP_MATCH
AttributeAssertion eq = { NULL, BER_BVNULL, NULL };
/* We want pure entries, not referrals */
fop.o_managedsait = SLAP_CONTROL_CRITICAL;
- fbuf.bv_val = buf;
cf.f_ava = &eq;
cf.f_av_desc = slap_schema.si_ad_entryCSN;
cf.f_next = NULL;
fop.ors_limit = NULL;
fop.ors_tlimit = SLAP_NO_LIMIT;
fop.ors_filter = &cf;
- fop.ors_filterstr = fbuf;
+ fop.ors_filterstr.bv_val = buf;
switch( mode ) {
case FIND_MAXCSN:
cf.f_choice = LDAP_FILTER_GE;
cf.f_av_value = si->si_ctxcsn;
- fbuf.bv_len = sprintf( buf, "(entryCSN>=%s)",
+ fop.ors_filterstr.bv_len = sprintf( buf, "(entryCSN>=%s)",
cf.f_av_value.bv_val );
fop.ors_attrsonly = 0;
fop.ors_attrs = csn_anlist;
case FIND_CSN:
cf.f_choice = LDAP_FILTER_LE;
cf.f_av_value = srs->sr_state.ctxcsn;
- fbuf.bv_len = sprintf( buf, "(entryCSN<=%s)",
+ fop.ors_filterstr.bv_len = sprintf( buf, "(entryCSN<=%s)",
cf.f_av_value.bv_val );
fop.ors_attrsonly = 1;
fop.ors_attrs = slap_anlist_no_attrs;
opc.son = on;
op->o_bd->bd_info = (BackendInfo *)on->on_info;
for (sr = so->s_res; sr; sr=srnext) {
- int rc;
srnext = sr->s_next;
opc.sdn = sr->s_dn;
opc.sndn = sr->s_ndn;
syncprov_sendresp( Operation *op, opcookie *opc, syncops *so, Entry **e, int mode, int queue )
{
slap_overinst *on = opc->son;
- syncprov_info_t *si = on->on_bi.bi_private;
SlapReply rs = { REP_SEARCH };
LDAPControl *ctrls[2];
Operation sop = *so->s_op;
Opheader ohdr;
+ if ( so->s_op->o_abandon )
+ return SLAPD_ABANDON;
+
ohdr = *sop.o_hdr;
sop.o_hdr = &ohdr;
sop.o_tmpmemctx = op->o_tmpmemctx;
return syncprov_qresp( opc, so, mode );
}
ldap_pvt_thread_mutex_unlock( &so->s_mutex );
+
+ /* If syncprov_qplay returned any other error, bail out. */
+ if ( rs.sr_err ) {
+ return rs.sr_err;
+ }
} else {
/* Queueing not allowed and conn is busy, give up */
if ( sop.o_conn->c_writewaiter )
* recovered, there may be more to send now. But don't check if the
* original psearch has been abandoned.
*/
- if ( !so->s_op->o_abandon && rs.sr_err == LDAP_SUCCESS && queue
- && so->s_res ) {
+ if ( so->s_op->o_abandon )
+ return SLAPD_ABANDON;
+
+ if ( rs.sr_err == LDAP_SUCCESS && queue && so->s_res ) {
ldap_pvt_thread_mutex_lock( &so->s_mutex );
rs.sr_err = syncprov_qplay( &sop, on, so );
ldap_pvt_thread_mutex_unlock( &so->s_mutex );
}
}
ldap_pvt_thread_mutex_unlock( &si->si_ops_mutex );
-done:
+
if ( op->o_tag != LDAP_REQ_ADD && e ) {
op->o_bd->bd_info = (BackendInfo *)on->on_info;
be_entry_release_rw( op, e, 0 );
mod.sml_nvalues = NULL;
mod.sml_desc = slap_schema.si_ad_contextCSN;
mod.sml_op = LDAP_MOD_REPLACE;
+ mod.sml_flags = 0;
mod.sml_next = NULL;
cb.sc_response = slap_null_cb;
se->se_tag = op->o_tag;
se->se_uuid.bv_val = (char *)(se+1);
- se->se_csn.bv_val = se->se_uuid.bv_val + opc->suuid.bv_len + 1;
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_csn.bv_val = se->se_uuid.bv_val + opc->suuid.bv_len;
AC_MEMCPY( se->se_csn.bv_val, csn->bv_val, csn->bv_len );
se->se_csn.bv_val[csn->bv_len] = '\0';
se->se_csn.bv_len = csn->bv_len;
struct berval *oldcsn, struct berval *ctxcsn )
{
slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
- syncprov_info_t *si = on->on_bi.bi_private;
slog_entry *se;
int i, j, ndel, num, nmods, mmods;
BerVarray uuids;
{
searchstate *ss = op->o_callback->sc_private;
slap_overinst *on = ss->ss_on;
- syncprov_info_t *si = on->on_bi.bi_private;
sync_control *srs = op->o_controls[slap_cids.sc_LDAPsync];
if ( rs->sr_type == REP_SEARCH || rs->sr_type == REP_SEARCHREF ) {
- int i;
/* If we got a referral without a referral object, there's
* something missing that we cannot replicate. Just ignore it.
* The consumer will abort because we didn't send the expected
* control.
*/
if ( !rs->sr_entry ) {
- assert( rs->sr_entry );
+ assert( rs->sr_entry != NULL );
Debug( LDAP_DEBUG_ANY, "bogus referral in context\n",0,0,0 );
return SLAP_CB_CONTINUE;
}
return SLAP_CB_CONTINUE;
}
+enum {
+ SP_CHKPT = 1,
+ SP_SESSL
+};
+
+static ConfigDriver sp_cf_gen;
+
+static ConfigTable spcfg[] = {
+ { "syncprov-checkpoint", "ops> <minutes", 3, 3, 0, ARG_MAGIC|SP_CHKPT,
+ sp_cf_gen, "( OLcfgOvAt:1.1 NAME 'olcSpCheckpoint' "
+ "DESC 'ContextCSN checkpoint interval in ops and minutes' "
+ "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
+ { "syncprov-sessionlog", "size", 2, 2, 0, ARG_INT|ARG_MAGIC|SP_SESSL,
+ sp_cf_gen, "( OLcfgOvAt:1.2 NAME 'olcSpSessionlog' "
+ "DESC 'Session log size in ops' "
+ "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
+ { NULL, NULL, 0, 0, 0, ARG_IGNORED }
+};
+
+static ConfigOCs spocs[] = {
+ { "( OLcfgOvOc:1.1 "
+ "NAME 'olcSyncProvConfig' "
+ "DESC 'SyncRepl Provider configuration' "
+ "SUP olcOverlayConfig "
+ "MAY ( olcSpCheckpoint $ olcSpSessionlog ) )",
+ Cft_Overlay, spcfg },
+ { NULL, 0, NULL }
+};
+
static int
-syncprov_db_config(
- BackendDB *be,
- const char *fname,
- int lineno,
- int argc,
- char **argv
-)
+sp_cf_gen(ConfigArgs *c)
{
- slap_overinst *on = (slap_overinst *)be->bd_info;
+ slap_overinst *on = (slap_overinst *)c->bi;
syncprov_info_t *si = (syncprov_info_t *)on->on_bi.bi_private;
-
- if ( strcasecmp( argv[ 0 ], "syncprov-checkpoint" ) == 0 ) {
- if ( argc != 3 ) {
- fprintf( stderr, "%s: line %d: wrong number of arguments in "
- "\"syncprov-checkpoint <ops> <minutes>\"\n", fname, lineno );
- return -1;
+ int rc = 0;
+
+ if ( c->op == SLAP_CONFIG_EMIT ) {
+ switch ( c->type ) {
+ case SP_CHKPT:
+ if ( si->si_chkops || si->si_chktime ) {
+ struct berval bv;
+ bv.bv_len = sprintf( c->msg, "%d %d",
+ si->si_chkops, si->si_chktime );
+ bv.bv_val = c->msg;
+ value_add_one( &c->rvalue_vals, &bv );
+ } else {
+ rc = 1;
+ }
+ break;
+ case SP_SESSL:
+ if ( si->si_logs ) {
+ c->value_int = si->si_logs->sl_size;
+ } else {
+ rc = 1;
+ }
+ break;
}
- si->si_chkops = atoi( argv[1] );
- si->si_chktime = atoi( argv[2] ) * 60;
- return 0;
-
- } else if ( strcasecmp( argv[0], "syncprov-sessionlog" ) == 0 ) {
- sessionlog *sl;
- int size;
- if ( argc != 2 ) {
- fprintf( stderr, "%s: line %d: wrong number of arguments in "
- "\"syncprov-sessionlog <size>\"\n", fname, lineno );
- return -1;
+ return rc;
+ } else if ( c->op == LDAP_MOD_DELETE ) {
+ switch ( c->type ) {
+ case SP_CHKPT:
+ si->si_chkops = 0;
+ si->si_chktime = 0;
+ break;
+ case SP_SESSL:
+ if ( si->si_logs )
+ si->si_logs->sl_size = 0;
+ else
+ rc = LDAP_NO_SUCH_ATTRIBUTE;
+ break;
}
- size = atoi( argv[1] );
+ return rc;
+ }
+ switch ( c->type ) {
+ case SP_CHKPT:
+ si->si_chkops = atoi( c->argv[1] );
+ si->si_chktime = atoi( c->argv[2] ) * 60;
+ break;
+ case SP_SESSL: {
+ sessionlog *sl;
+ int size = c->value_int;
+
if ( size < 0 ) {
- fprintf( stderr,
- "%s: line %d: session log size %d is negative\n",
- fname, lineno, size );
- return -1;
+ sprintf( c->msg, "%s size %d is negative",
+ c->argv[0], size );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->msg, 0 );
+ return ARG_BAD_CONF;
}
sl = si->si_logs;
if ( !sl ) {
si->si_logs = sl;
}
sl->sl_size = size;
- return 0;
+ }
+ break;
}
-
- return SLAP_CONF_UNKNOWN;
+ return rc;
}
/* Cheating - we have no thread pool context for these functions,
/* A fake thread context */
static thread_keys thrctx[MAXKEYS];
+/* ITS#3456 we cannot run this search on the main thread, must use a
+ * child thread in order to insure we have a big enough stack.
+ */
+static void *
+syncprov_db_otask(
+ void *ptr
+)
+{
+ syncprov_findcsn( ptr, FIND_MAXCSN );
+ return NULL;
+}
+
/* Read any existing contextCSN from the underlying db.
* Then search for any entries newer than that. If no value exists,
* just generate it. Cache whatever result.
slap_schema.si_ad_contextCSN, 0, &e );
if ( e ) {
+ ldap_pvt_thread_t tid;
+
a = attr_find( e->e_attrs, slap_schema.si_ad_contextCSN );
if ( a ) {
si->si_ctxcsn.bv_len = a->a_nvals[0].bv_len;
op->o_req_dn = be->be_suffix[0];
op->o_req_ndn = be->be_nsuffix[0];
op->ors_scope = LDAP_SCOPE_SUBTREE;
- syncprov_findcsn( op, FIND_MAXCSN );
+ ldap_pvt_thread_create( &tid, 0, syncprov_db_otask, op );
+ 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,
* then don't generate anything, wait for our provider to send it
}
/* If our ctxcsn is different from what was read from the root
- * entry, write the new value out.
+ * entry, make sure we do a checkpoint on close
*/
if ( strcmp( si->si_ctxcsnbuf, ctxcsnbuf )) {
- SlapReply rs = {REP_RESULT};
- syncprov_checkpoint( op, &rs, on );
+ si->si_numops++;
}
out:
LDAPControl *ctrl )
{
ber_tag_t tag;
- BerElement *ber;
+ BerElementBuffer berbuf;
+ BerElement *ber = (BerElement *)&berbuf;
ber_int_t mode;
ber_len_t len;
struct berval cookie = BER_BVNULL;
* }
*/
- ber = ber_init( &ctrl->ldctl_value );
- if( ber == NULL ) {
- rs->sr_text = "internal error";
- return LDAP_OTHER;
- }
+ ber_init2( ber, &ctrl->ldctl_value, 0 );
if ( (tag = ber_scanf( ber, "{i" /*}*/, &mode )) == LBER_ERROR ) {
rs->sr_text = "Sync control : mode decoding error";
tag = ber_peek_tag( ber, &len );
if ( tag == LDAP_TAG_SYNC_COOKIE ) {
- if (( ber_scanf( ber, /*{*/ "o", &cookie )) == LBER_ERROR ) {
+ if (( ber_scanf( ber, /*{*/ "m", &cookie )) == LBER_ERROR ) {
rs->sr_text = "Sync control : cookie decoding error";
return LDAP_PROTOCOL_ERROR;
}
sr = op->o_tmpcalloc( 1, sizeof(struct sync_control), op->o_tmpmemctx );
sr->sr_rhint = rhint;
if (!BER_BVISNULL(&cookie)) {
- ber_dupbv( &sr->sr_state.octet_str, &cookie );
- slap_parse_sync_cookie( &sr->sr_state );
+ ber_dupbv_x( &sr->sr_state.octet_str, &cookie, op->o_tmpmemctx );
+ slap_parse_sync_cookie( &sr->sr_state, op->o_tmpmemctx );
+ if ( sr->sr_state.rid == -1 ) {
+ rs->sr_text = "Sync control : cookie parsing error";
+ return LDAP_PROTOCOL_ERROR;
+ }
}
op->o_controls[slap_cids.sc_LDAPsync] = sr;
- (void) ber_free( ber, 1 );
-
op->o_sync = ctrl->ldctl_iscritical
? SLAP_CONTROL_CRITICAL
: SLAP_CONTROL_NONCRITICAL;
SLAP_CTRL_HIDE|SLAP_CTRL_SEARCH, NULL,
syncprov_parseCtrl, &slap_cids.sc_LDAPsync );
if ( rc != LDAP_SUCCESS ) {
- fprintf( stderr, "Failed to register control %d\n", rc );
+ Debug( LDAP_DEBUG_ANY,
+ "syncprov_init: Failed to register control %d\n", rc, 0, 0 );
return rc;
}
syncprov.on_bi.bi_type = "syncprov";
syncprov.on_bi.bi_db_init = syncprov_db_init;
- syncprov.on_bi.bi_db_config = syncprov_db_config;
syncprov.on_bi.bi_db_destroy = syncprov_db_destroy;
syncprov.on_bi.bi_db_open = syncprov_db_open;
syncprov.on_bi.bi_db_close = syncprov_db_close;
syncprov.on_bi.bi_extended = syncprov_op_extended;
syncprov.on_bi.bi_operational = syncprov_operational;
+ syncprov.on_bi.bi_cf_ocs = spocs;
+
+ rc = config_register_schema( spcfg, spocs );
+ if ( rc ) return rc;
+
return overlay_register( &syncprov );
}