More consolidation for single consumer-context syncrepl

This commit is contained in:
Howard Chu 2005-01-14 04:26:59 +00:00
parent 23f2d44d61
commit 495c315672
9 changed files with 179 additions and 878 deletions

View file

@ -1665,8 +1665,6 @@ add_syncrepl(
si->si_retryinterval = NULL;
si->si_retrynum_init = NULL;
si->si_retrynum = NULL;
si->si_syncCookie.ctxcsn = NULL;
si->si_syncCookie.octet_str = NULL;
si->si_manageDSAit = 0;
si->si_tlimit = 0;
si->si_slimit = 0;

View file

@ -71,14 +71,14 @@ slap_sync_cookie_free(
if ( cookie == NULL )
return;
if ( cookie->ctxcsn ) {
ber_bvarray_free( cookie->ctxcsn );
cookie->ctxcsn = NULL;
if ( !BER_BVISNULL( &cookie->ctxcsn )) {
ch_free( cookie->ctxcsn.bv_val );
BER_BVZERO( &cookie->ctxcsn );
}
if ( cookie->octet_str ) {
ber_bvarray_free( cookie->octet_str );
cookie->octet_str = NULL;
if ( !BER_BVISNULL( &cookie->octet_str )) {
ch_free( cookie->octet_str.bv_val );
BER_BVZERO( &cookie->octet_str );
}
if ( free_cookie ) {
@ -100,12 +100,11 @@ slap_parse_sync_cookie(
char *rid_ptr;
char *rid_str;
char *cval;
struct berval ctxcsn;
if ( cookie == NULL )
return -1;
while (( csn_ptr = strstr( cookie->octet_str[0].bv_val, "csn=" )) != NULL ) {
while (( csn_ptr = strstr( cookie->octet_str.bv_val, "csn=" )) != NULL ) {
AttributeDescription *ad = slap_schema.si_ad_modifyTimestamp;
slap_syntax_validate_func *validate;
struct berval stamp;
@ -130,13 +129,12 @@ slap_parse_sync_cookie(
break;
}
if ( valid ) {
ber_str2bv( csn_str, csn_str_len, 1, &ctxcsn );
ber_bvarray_add( &cookie->ctxcsn, &ctxcsn );
ber_str2bv( csn_str, csn_str_len, 1, &cookie->ctxcsn );
} else {
cookie->ctxcsn = NULL;
BER_BVZERO( &cookie->ctxcsn );
}
if (( rid_ptr = strstr( cookie->octet_str->bv_val, "rid=" )) != NULL ) {
if (( rid_ptr = strstr( cookie->octet_str.bv_val, "rid=" )) != NULL ) {
rid_str = SLAP_STRNDUP( rid_ptr,
SLAP_SYNC_RID_SIZE + sizeof("rid=") - 1 );
if ( (cval = strchr( rid_str, ',' )) != NULL ) {
@ -158,8 +156,6 @@ slap_init_sync_cookie_ctxcsn(
char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE + 4 ];
struct berval octet_str = BER_BVNULL;
struct berval ctxcsn = BER_BVNULL;
struct berval ctxcsn_dup = BER_BVNULL;
struct berval slap_syncCookie;
if ( cookie == NULL )
return -1;
@ -168,15 +164,12 @@ slap_init_sync_cookie_ctxcsn(
"csn=%4d%02d%02d%02d%02d%02dZ#%06x#%02x#%06x",
1900, 1, 1, 0, 0, 0, 0, 0, 0 );
octet_str.bv_val = csnbuf;
build_new_dn( &slap_syncCookie, &cookie->octet_str[0], &octet_str, NULL );
ber_bvarray_free( cookie->octet_str );
cookie->octet_str = NULL;
ber_bvarray_add( &cookie->octet_str, &slap_syncCookie );
ch_free( cookie->octet_str.bv_val );
ber_dupbv( &cookie->octet_str, &octet_str );
ctxcsn.bv_val = octet_str.bv_val + 4;
ctxcsn.bv_len = octet_str.bv_len - 4;
ber_dupbv( &ctxcsn_dup, &ctxcsn );
ber_bvarray_add( &cookie->ctxcsn, &ctxcsn_dup );
ber_dupbv( &cookie->ctxcsn, &ctxcsn );
return 0;
}
@ -195,8 +188,10 @@ slap_dup_sync_cookie(
return NULL;
if ( dst ) {
ber_bvarray_free( dst->ctxcsn );
ber_bvarray_free( dst->octet_str );
ch_free( dst->ctxcsn.bv_val );
ch_free( dst->octet_str.bv_val );
BER_BVZERO( &dst->ctxcsn );
BER_BVZERO( &dst->octet_str );
new = dst;
} else {
new = ( struct sync_cookie * )
@ -205,18 +200,12 @@ slap_dup_sync_cookie(
new->rid = src->rid;
if ( src->ctxcsn ) {
for ( i=0; src->ctxcsn[i].bv_val; i++ ) {
ber_dupbv( &tmp_bv, &src->ctxcsn[i] );
ber_bvarray_add( &new->ctxcsn, &tmp_bv );
}
if ( !BER_BVISNULL( &src->ctxcsn )) {
ber_dupbv( &new->ctxcsn, &src->ctxcsn );
}
if ( src->octet_str ) {
for ( i=0; src->octet_str[i].bv_val; i++ ) {
ber_dupbv( &tmp_bv, &src->octet_str[i] );
ber_bvarray_add( &new->octet_str, &tmp_bv );
}
if ( !BER_BVISNULL( &src->octet_str )) {
ber_dupbv( &new->octet_str, &src->octet_str );
}
return new;

View file

@ -612,7 +612,7 @@ syncprov_findcsn( Operation *op, int mode )
if ( mode != FIND_MAXCSN ) {
srs = op->o_controls[slap_cids.sc_LDAPsync];
if ( srs->sr_state.ctxcsn->bv_len >= LDAP_LUTIL_CSNSTR_BUFSIZE ) {
if ( srs->sr_state.ctxcsn.bv_len >= LDAP_LUTIL_CSNSTR_BUFSIZE ) {
return LDAP_OTHER;
}
}
@ -648,7 +648,7 @@ syncprov_findcsn( Operation *op, int mode )
break;
case FIND_CSN:
cf.f_choice = LDAP_FILTER_LE;
cf.f_av_value = *srs->sr_state.ctxcsn;
cf.f_av_value = srs->sr_state.ctxcsn;
fbuf.bv_len = sprintf( buf, "(entryCSN<=%s)",
cf.f_av_value.bv_val );
fop.ors_attrsonly = 1;
@ -662,7 +662,7 @@ syncprov_findcsn( Operation *op, int mode )
af.f_next = NULL;
af.f_and = &cf;
cf.f_choice = LDAP_FILTER_LE;
cf.f_av_value = *srs->sr_state.ctxcsn;
cf.f_av_value = srs->sr_state.ctxcsn;
cf.f_next = op->ors_filter;
fop.ors_filter = &af;
filter2bv_x( &fop, fop.ors_filter, &fop.ors_filterstr );
@ -921,10 +921,6 @@ syncprov_matchops( Operation *op, opcookie *opc, int saveit )
e = op->ora_e;
}
/* Never replicate these */
if ( is_entry_syncConsumerSubentry( e )) {
goto done;
}
if ( saveit ) {
ber_dupbv_x( &opc->sdn, &e->e_name, op->o_tmpmemctx );
ber_dupbv_x( &opc->sndn, &e->e_nname, op->o_tmpmemctx );
@ -1294,6 +1290,13 @@ syncprov_op_response( Operation *op, SlapReply *rs )
}
}
/* Don't do any processing for consumer contextCSN updates */
if ( SLAP_SYNC_SHADOW( op->o_bd ) &&
op->o_msgid == SLAP_SYNC_UPDATE_MSGID ) {
ldap_pvt_thread_mutex_unlock( &si->si_csn_mutex );
return SLAP_CB_CONTINUE;
}
si->si_numops++;
if ( si->si_chkops || si->si_chktime ) {
int do_check=0;
@ -1605,12 +1608,12 @@ syncprov_search_response( Operation *op, SlapReply *rs )
Debug( LDAP_DEBUG_ANY, "bogus referral in context\n",0,0,0 );
return SLAP_CB_CONTINUE;
}
if ( srs->sr_state.ctxcsn ) {
if ( !BER_BVISNULL( &srs->sr_state.ctxcsn )) {
Attribute *a = attr_find( rs->sr_entry->e_attrs,
slap_schema.si_ad_entryCSN );
/* Don't send the ctx entry twice */
if ( a && bvmatch( &a->a_nvals[0], srs->sr_state.ctxcsn ) )
if ( a && bvmatch( &a->a_nvals[0], &srs->sr_state.ctxcsn ) )
return LDAP_SUCCESS;
}
rs->sr_ctrls = op->o_tmpalloc( sizeof(LDAPControl *)*2,
@ -1760,13 +1763,13 @@ syncprov_op_search( Operation *op, SlapReply *rs )
ctxcsn.bv_val = csnbuf;
/* If we have a cookie, handle the PRESENT lookups */
if ( srs->sr_state.ctxcsn ) {
if ( !BER_BVISNULL( &srs->sr_state.ctxcsn )) {
sessionlog *sl;
/* The cookie was validated when it was parsed, just use it */
/* If just Refreshing and nothing has changed, shortcut it */
if ( bvmatch( srs->sr_state.ctxcsn, &ctxcsn )) {
if ( bvmatch( &srs->sr_state.ctxcsn, &ctxcsn )) {
nochange = 1;
if ( !(op->o_sync_mode & SLAP_SYNC_PERSIST) ) {
LDAPControl *ctrls[2];
@ -1787,10 +1790,10 @@ syncprov_op_search( Operation *op, SlapReply *rs )
sl=si->si_logs;
if ( sl ) {
ldap_pvt_thread_mutex_lock( &sl->sl_mutex );
if ( ber_bvcmp( srs->sr_state.ctxcsn, &sl->sl_mincsn ) >= 0 ) {
if ( ber_bvcmp( &srs->sr_state.ctxcsn, &sl->sl_mincsn ) >= 0 ) {
do_present = 0;
/* mutex is unlocked in playlog */
syncprov_playlog( op, rs, sl, srs->sr_state.ctxcsn, &ctxcsn );
syncprov_playlog( op, rs, sl, &srs->sr_state.ctxcsn, &ctxcsn );
} else {
ldap_pvt_thread_mutex_unlock( &sl->sl_mutex );
}
@ -1838,7 +1841,7 @@ shortcut:
fava->f_choice = LDAP_FILTER_GE;
fava->f_ava = op->o_tmpalloc( sizeof(AttributeAssertion), op->o_tmpmemctx );
fava->f_ava->aa_desc = slap_schema.si_ad_entryCSN;
ber_dupbv_x( &fava->f_ava->aa_value, srs->sr_state.ctxcsn, op->o_tmpmemctx );
ber_dupbv_x( &fava->f_ava->aa_value, &srs->sr_state.ctxcsn, op->o_tmpmemctx );
}
fava->f_next = op->ors_filter;
op->ors_filter = fand;
@ -2210,7 +2213,7 @@ static int syncprov_parseCtrl (
sr = op->o_tmpcalloc( 1, sizeof(struct sync_control), op->o_tmpmemctx );
sr->sr_rhint = rhint;
if (!BER_BVISNULL(&cookie)) {
ber_bvarray_add( &sr->sr_state.octet_str, &cookie );
ber_dupbv( &sr->sr_state.octet_str, &cookie );
slap_parse_sync_cookie( &sr->sr_state );
}

View file

@ -1457,6 +1457,8 @@ typedef BackendDB Backend;
#define SLAP_SYNC_RID_SIZE 3
#define SLAP_SYNCUUID_SET_SIZE 256
#define SLAP_SYNC_UPDATE_MSGID 2
struct nonpresent_entry {
struct berval *npe_name;
struct berval *npe_nname;
@ -1464,8 +1466,8 @@ struct nonpresent_entry {
};
struct sync_cookie {
struct berval *ctxcsn;
struct berval *octet_str;
struct berval ctxcsn;
struct berval octet_str;
long rid;
LDAP_STAILQ_ENTRY(sync_cookie) sc_next;
};

View file

@ -39,18 +39,7 @@
#include "slapcommon.h"
static char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
static const struct berval slap_syncrepl_bvc = BER_BVC("syncreplxxx");
static const struct berval slap_syncrepl_cn_bvc = BER_BVC("cn=syncreplxxx");
static struct berval slap_syncrepl_bv = BER_BVNULL;
static struct berval slap_syncrepl_cn_bv = BER_BVNULL;
struct subentryinfo {
struct berval cn;
struct berval ndn;
struct berval rdn;
struct berval cookie;
LDAP_SLIST_ENTRY( subentryinfo ) sei_next;
};
static char maxcsnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
int
slapadd( int argc, char **argv )
@ -66,25 +55,17 @@ slapadd( int argc, char **argv )
const char *progname = "slapadd";
struct berval csn;
struct berval maxcsn = BER_BVNULL;
struct berval ldifcsn = BER_BVNULL;
struct berval maxcsn;
int match;
int provider_subentry = 0;
struct subentryinfo *sei;
LDAP_SLIST_HEAD( consumer_subentry_slist, subentryinfo ) consumer_subentry;
Attribute *attr;
Entry *ctxcsn_e;
ID ctxcsn_id;
struct berval ctxcsn_ndn = BER_BVNULL;
ID ctxcsn_id, id;
int ret;
struct berval bvtext;
int i;
struct berval mc;
struct sync_cookie sc;
slap_tool_init( progname, SLAPADD, argc, argv );
LDAP_SLIST_INIT( &consumer_subentry );
if( !be->be_entry_open ||
!be->be_entry_close ||
!be->be_entry_put )
@ -108,6 +89,11 @@ slapadd( int argc, char **argv )
exit( EXIT_FAILURE );
}
if ( update_ctxcsn ) {
maxcsn.bv_val = maxcsnbuf;
maxcsn.bv_len = 0;
}
while( ldif_read_record( ldiffp, &lineno, &buf, &lmax ) ) {
Entry *e = str2entry( buf );
@ -288,11 +274,10 @@ slapadd( int argc, char **argv )
attr_merge( e, slap_schema.si_ad_entryCSN, vals, NULL );
}
if ( !is_entry_syncProviderSubentry( e ) &&
!is_entry_syncConsumerSubentry( e ) &&
update_ctxcsn != SLAP_TOOL_CTXCSN_KEEP ) {
if ( update_ctxcsn ) {
attr = attr_find( e->e_attrs, slap_schema.si_ad_entryCSN );
if ( maxcsn.bv_len != 0 ) {
match = 0;
value_match( &match, slap_schema.si_ad_entryCSN,
slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
@ -301,142 +286,32 @@ slapadd( int argc, char **argv )
match = -1;
}
if ( match < 0 ) {
if ( maxcsn.bv_val )
ch_free( maxcsn.bv_val );
ber_dupbv( &maxcsn, &attr->a_nvals[0] );
strcpy( maxcsn.bv_val, attr->a_nvals[0].bv_val );
maxcsn.bv_len = attr->a_nvals[0].bv_len;
}
}
}
if ( dryrun ) {
if ( verbose ) {
fprintf( stderr, "(dry) added: \"%s\"\n", e->e_dn );
}
goto done;
}
if ( update_ctxcsn == SLAP_TOOL_CTXCSN_KEEP &&
( replica_promotion || replica_demotion )) {
if ( is_entry_syncProviderSubentry( e )) {
if ( !LDAP_SLIST_EMPTY( &consumer_subentry )) {
fprintf( stderr, "%s: consumer and provider subentries "
"are both present\n", progname );
rc = EXIT_FAILURE;
entry_free( e );
sei = LDAP_SLIST_FIRST( &consumer_subentry );
while ( sei ) {
ch_free( sei->cn.bv_val );
ch_free( sei->ndn.bv_val );
ch_free( sei->rdn.bv_val );
ch_free( sei->cookie.bv_val );
LDAP_SLIST_REMOVE_HEAD( &consumer_subentry, sei_next );
ch_free( sei );
sei = LDAP_SLIST_FIRST( &consumer_subentry );
}
break;
}
if ( provider_subentry ) {
fprintf( stderr, "%s: multiple provider subentries are "
"present : add -w flag to refresh\n", progname );
rc = EXIT_FAILURE;
entry_free( e );
break;
}
attr = attr_find( e->e_attrs, slap_schema.si_ad_contextCSN );
if ( attr == NULL ) {
entry_free( e );
continue;
}
provider_subentry = 1;
ber_dupbv( &maxcsn, &attr->a_nvals[0] );
} else if ( is_entry_syncConsumerSubentry( e )) {
if ( provider_subentry ) {
fprintf( stderr, "%s: consumer and provider subentries "
"are both present\n", progname );
rc = EXIT_FAILURE;
entry_free( e );
break;
}
attr = attr_find( e->e_attrs, slap_schema.si_ad_cn );
if ( attr == NULL ) {
entry_free( e );
continue;
}
if ( !LDAP_SLIST_EMPTY( &consumer_subentry )) {
LDAP_SLIST_FOREACH( sei, &consumer_subentry, sei_next ) {
value_match( &match, slap_schema.si_ad_cn,
slap_schema.si_ad_cn->ad_type->sat_equality,
SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
&sei->cn, &attr->a_nvals[0], &text );
}
if ( !match ) {
fprintf( stderr, "%s: multiple consumer subentries "
"have the same id : add -w flag to refresh\n",
progname );
rc = EXIT_FAILURE;
entry_free( e );
sei = LDAP_SLIST_FIRST( &consumer_subentry );
while ( sei ) {
ch_free( sei->cn.bv_val );
ch_free( sei->ndn.bv_val );
ch_free( sei->rdn.bv_val );
ch_free( sei->cookie.bv_val );
LDAP_SLIST_REMOVE_HEAD( &consumer_subentry, sei_next );
ch_free( sei );
sei = LDAP_SLIST_FIRST( &consumer_subentry );
}
break;
}
}
sei = ch_calloc( 1, sizeof( struct subentryinfo ));
ber_dupbv( &sei->cn, &attr->a_nvals[0] );
ber_dupbv( &sei->ndn, &e->e_nname );
dnExtractRdn( &sei->ndn, &sei->rdn, NULL );
attr = attr_find( e->e_attrs, slap_schema.si_ad_syncreplCookie );
if ( attr == NULL ) {
ch_free( sei->cn.bv_val );
ch_free( sei->ndn.bv_val );
ch_free( sei->rdn.bv_val );
ch_free( sei->cookie.bv_val );
ch_free( sei );
entry_free( e );
continue;
}
ber_dupbv( &sei->cookie, &attr->a_nvals[0] );
LDAP_SLIST_INSERT_HEAD( &consumer_subentry, sei, sei_next );
if ( !dryrun ) {
id = be->be_entry_put( be, e, &bvtext );
if( id == NOID ) {
fprintf( stderr, "%s: could not add entry dn=\"%s\" "
"(line=%d): %s\n", progname, e->e_dn,
lineno, bvtext.bv_val );
rc = EXIT_FAILURE;
entry_free( e );
if( continuemode ) continue;
break;
}
}
if (( !is_entry_syncProviderSubentry( e ) &&
!is_entry_syncConsumerSubentry( e )) ||
( !replica_promotion && !replica_demotion ))
{
/* dryrun moved earlier */
assert( !dryrun );
if (!dryrun) {
ID id = be->be_entry_put( be, e, &bvtext );
if( id == NOID ) {
fprintf( stderr, "%s: could not add entry dn=\"%s\" "
"(line=%d): %s\n", progname, e->e_dn,
lineno, bvtext.bv_val );
rc = EXIT_FAILURE;
entry_free( e );
if( continuemode ) continue;
break;
}
if ( verbose ) {
fprintf( stderr, "added: \"%s\" (%08lx)\n",
e->e_dn, (long) id );
}
if ( verbose ) {
if ( dryrun ) {
fprintf( stderr, "added: \"%s\"\n",
e->e_dn );
} else {
if ( verbose ) {
fprintf( stderr, "(dry) added: \"%s\"\n", e->e_dn );
}
fprintf( stderr, "added: \"%s\" (%08lx)\n",
e->e_dn, (long) id );
}
}
@ -448,279 +323,37 @@ done:;
bvtext.bv_val = textbuf;
bvtext.bv_val[0] = '\0';
if ( !LDAP_SLIST_EMPTY( &consumer_subentry )) {
maxcsn.bv_len = 0;
maxcsn.bv_val = NULL;
LDAP_SLIST_FOREACH( sei, &consumer_subentry, sei_next ) {
sc.octet_str = &sei->cookie;
slap_parse_sync_cookie( &sc );
if ( maxcsn.bv_len != 0 ) {
value_match( &match, slap_schema.si_ad_syncreplCookie,
slap_schema.si_ad_syncreplCookie->ad_type->sat_ordering,
if ( update_ctxcsn && !dryrun && maxcsn.bv_len ) {
ctxcsn_id = be->be_dn2id_get( be, be->be_nsuffix );
if ( ctxcsn_id == NOID ) {
fprintf( stderr, "%s: context entry is missing\n", progname );
rc = EXIT_FAILURE;
} else {
ret = be->be_id2entry_get( be, ctxcsn_id, &ctxcsn_e );
if ( ret == LDAP_SUCCESS ) {
attr = attr_find( ctxcsn_e->e_attrs,
slap_schema.si_ad_contextCSN );
value_match( &match, slap_schema.si_ad_entryCSN,
slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
&maxcsn, &sc.ctxcsn[0], &text );
} else {
match = -1;
}
if ( match < 0 ) {
if ( maxcsn.bv_val )
ch_free( maxcsn.bv_val );
ber_dupbv( &maxcsn, &sc.ctxcsn[0] );
}
sc.octet_str = NULL;
slap_sync_cookie_free( &sc, 0 );
}
}
slap_compose_sync_cookie( NULL, &mc, &maxcsn, -1 );
if ( SLAP_LASTMOD(be) && replica_promotion ) {
if ( provider_subentry || update_ctxcsn == SLAP_TOOL_CTXCSN_BATCH ||
!LDAP_SLIST_EMPTY( &consumer_subentry )) {
build_new_dn( &ctxcsn_ndn, &be->be_nsuffix[0],
(struct berval *)&slap_ldapsync_cn_bv, NULL );
ctxcsn_id = be->be_dn2id_get( be, &ctxcsn_ndn );
if ( ctxcsn_id == NOID ) {
ctxcsn_e = slap_create_context_csn_entry( be, &maxcsn );
/* dryrun moved earlier */
assert( !dryrun );
if ( !dryrun ) {
ctxcsn_id = be->be_entry_put( be, ctxcsn_e, &bvtext );
if( ctxcsn_id == NOID ) {
fprintf( stderr, "%s: could not add ctxcsn subentry\n",
progname);
rc = EXIT_FAILURE;
}
if ( verbose ) {
fprintf( stderr, "added: \"%s\" (%08lx)\n",
ctxcsn_e->e_dn, (long) ctxcsn_id );
}
} else {
if ( verbose ) {
fprintf( stderr, "(dry) added: \"%s\"\n", ctxcsn_e->e_dn );
}
}
entry_free( ctxcsn_e );
} else {
ret = be->be_id2entry_get( be, ctxcsn_id, &ctxcsn_e );
if ( ret == LDAP_SUCCESS ) {
attr = attr_find( ctxcsn_e->e_attrs,
slap_schema.si_ad_contextCSN );
&maxcsn, &attr->a_nvals[0], &text );
if ( match > 0 ) {
AC_MEMCPY( attr->a_vals[0].bv_val, maxcsn.bv_val, maxcsn.bv_len );
attr->a_vals[0].bv_val[maxcsn.bv_len] = '\0';
attr->a_vals[0].bv_len = maxcsn.bv_len;
/* dryrun moved earlier */
assert( !dryrun );
if ( !dryrun ) {
ctxcsn_id = be->be_entry_modify( be, ctxcsn_e, &bvtext );
if( ctxcsn_id == NOID ) {
fprintf( stderr, "%s: could not modify ctxcsn "
"subentry\n", progname);
rc = EXIT_FAILURE;
}
if ( verbose ) {
fprintf( stderr, "modified: \"%s\" (%08lx)\n",
ctxcsn_e->e_dn, (long) ctxcsn_id );
}
} else {
if ( verbose ) {
fprintf( stderr, "(dry) modified: \"%s\"\n",
ctxcsn_e->e_dn );
}
ctxcsn_id = be->be_entry_modify( be, ctxcsn_e, &bvtext );
if( ctxcsn_id == NOID ) {
fprintf( stderr, "%s: could not modify ctxcsn\n",
progname);
rc = EXIT_FAILURE;
} else if ( verbose ) {
fprintf( stderr, "modified: \"%s\" (%08lx)\n",
ctxcsn_e->e_dn, (long) ctxcsn_id );
}
} else {
fprintf( stderr, "%s: could not modify ctxcsn subentry\n",
progname);
rc = EXIT_FAILURE;
}
}
}
} else if ( SLAP_LASTMOD(be) && replica_demotion &&
( update_ctxcsn == SLAP_TOOL_CTXCSN_BATCH ||
provider_subentry )) {
ber_dupbv( &slap_syncrepl_bv, (struct berval *) &slap_syncrepl_bvc );
ber_dupbv( &slap_syncrepl_cn_bv,
(struct berval *) &slap_syncrepl_cn_bvc );
if ( replica_id_list == NULL ) {
replica_id_list = ch_calloc( 2, sizeof( int ));
replica_id_list[0] = 0;
replica_id_list[1] = -1;
}
for ( i = 0; replica_id_list[i] > -1 ; i++ ) {
slap_syncrepl_bv.bv_len = snprintf( slap_syncrepl_bv.bv_val,
slap_syncrepl_bvc.bv_len+1,
"syncrepl%d", replica_id_list[i] );
slap_syncrepl_cn_bv.bv_len = snprintf( slap_syncrepl_cn_bv.bv_val,
slap_syncrepl_cn_bvc.bv_len+1,
"cn=syncrepl%d", replica_id_list[i] );
build_new_dn( &ctxcsn_ndn, &be->be_nsuffix[0],
(struct berval *)&slap_syncrepl_cn_bv, NULL );
ctxcsn_id = be->be_dn2id_get( be, &ctxcsn_ndn );
if ( ctxcsn_id == NOID ) {
ctxcsn_e = slap_create_syncrepl_entry( be, &mc,
&slap_syncrepl_cn_bv,
&slap_syncrepl_bv );
/* dryrun moved earlier */
assert( !dryrun );
if ( !dryrun ) {
ctxcsn_id = be->be_entry_put( be, ctxcsn_e, &bvtext );
if( ctxcsn_id == NOID ) {
fprintf( stderr, "%s: could not add ctxcsn subentry\n",
progname);
rc = EXIT_FAILURE;
}
if ( verbose ) {
fprintf( stderr, "added: \"%s\" (%08lx)\n",
ctxcsn_e->e_dn, (long) ctxcsn_id );
}
} else {
if ( verbose ) {
fprintf( stderr, "(dry) added: \"%s\"\n",
ctxcsn_e->e_dn );
}
}
entry_free( ctxcsn_e );
} else {
ret = be->be_id2entry_get( be, ctxcsn_id, &ctxcsn_e );
if ( ret == LDAP_SUCCESS ) {
attr = attr_find( ctxcsn_e->e_attrs,
slap_schema.si_ad_syncreplCookie );
AC_MEMCPY( attr->a_vals[0].bv_val, mc.bv_val, mc.bv_len );
attr->a_vals[0].bv_val[maxcsn.bv_len] = '\0';
attr->a_vals[0].bv_len = maxcsn.bv_len;
/* dryrun moved earlier */
assert( !dryrun );
if ( !dryrun ) {
ctxcsn_id = be->be_entry_modify( be,
ctxcsn_e, &bvtext );
if( ctxcsn_id == NOID ) {
fprintf( stderr, "%s: could not modify ctxcsn "
"subentry\n", progname);
rc = EXIT_FAILURE;
}
if ( verbose ) {
fprintf( stderr, "modified: \"%s\" (%08lx)\n",
ctxcsn_e->e_dn, (long) ctxcsn_id );
}
} else {
if ( verbose ) {
fprintf( stderr, "(dry) modified: \"%s\"\n",
ctxcsn_e->e_dn );
}
}
} else {
fprintf( stderr, "%s: could not modify ctxcsn subentry\n",
progname);
rc = EXIT_FAILURE;
}
}
}
if ( slap_syncrepl_bv.bv_val ) {
ch_free( slap_syncrepl_bv.bv_val );
}
if ( slap_syncrepl_cn_bv.bv_val ) {
ch_free( slap_syncrepl_cn_bv.bv_val );
}
} else if ( SLAP_LASTMOD(be) && replica_demotion &&
!LDAP_SLIST_EMPTY( &consumer_subentry )) {
LDAP_SLIST_FOREACH( sei, &consumer_subentry, sei_next ) {
ctxcsn_id = be->be_dn2id_get( be, &sei->ndn );
if ( ctxcsn_id == NOID ) {
ctxcsn_e = slap_create_syncrepl_entry( be, &sei->cookie,
&sei->rdn, &sei->cn );
/* dryrun moved earlier */
assert( !dryrun );
if ( !dryrun ) {
ctxcsn_id = be->be_entry_put( be, ctxcsn_e, &bvtext );
if( ctxcsn_id == NOID ) {
fprintf( stderr, "%s: could not add ctxcsn subentry\n",
progname);
rc = EXIT_FAILURE;
}
if ( verbose ) {
fprintf( stderr, "added: \"%s\" (%08lx)\n",
ctxcsn_e->e_dn, (long) ctxcsn_id );
}
} else {
if ( verbose ) {
fprintf( stderr, "(dry) added: \"%s\"\n",
ctxcsn_e->e_dn );
}
}
entry_free( ctxcsn_e );
} else {
ret = be->be_id2entry_get( be, ctxcsn_id, &ctxcsn_e );
if ( ret == LDAP_SUCCESS ) {
attr = attr_find( ctxcsn_e->e_attrs,
slap_schema.si_ad_syncreplCookie );
AC_MEMCPY( attr->a_vals[0].bv_val, sei->cookie.bv_val, sei->cookie.bv_len );
attr->a_vals[0].bv_val[sei->cookie.bv_len] = '\0';
attr->a_vals[0].bv_len = sei->cookie.bv_len;
/* dryrun moved earlier */
assert( !dryrun );
if ( !dryrun ) {
ctxcsn_id = be->be_entry_modify( be,
ctxcsn_e, &bvtext );
if( ctxcsn_id == NOID ) {
fprintf( stderr, "%s: could not modify ctxcsn "
"subentry\n", progname);
rc = EXIT_FAILURE;
}
if ( verbose ) {
fprintf( stderr, "modified: \"%s\" (%08lx)\n",
ctxcsn_e->e_dn, (long) ctxcsn_id );
}
} else {
if ( verbose ) {
fprintf( stderr, "(dry) modified: \"%s\"\n",
ctxcsn_e->e_dn );
}
}
} else {
fprintf( stderr, "%s: could not modify ctxcsn subentry\n",
progname);
rc = EXIT_FAILURE;
}
}
}
if ( slap_syncrepl_bv.bv_val ) {
ch_free( slap_syncrepl_bv.bv_val );
}
if ( slap_syncrepl_cn_bv.bv_val ) {
ch_free( slap_syncrepl_cn_bv.bv_val );
}
}
sei = LDAP_SLIST_FIRST( &consumer_subentry );
while ( sei ) {
ch_free( sei->cn.bv_val );
ch_free( sei->ndn.bv_val );
ch_free( sei->rdn.bv_val );
ch_free( sei->cookie.bv_val );
LDAP_SLIST_REMOVE_HEAD( &consumer_subentry, sei_next );
ch_free( sei );
sei = LDAP_SLIST_FIRST( &consumer_subentry );
}
ch_free( buf );

View file

@ -87,20 +87,6 @@ slapcat( int argc, char **argv )
}
}
if ( retrieve_ctxcsn == 0 ) {
if ( is_entry_syncProviderSubentry( e ) ) {
be_entry_release_r( &op, e );
continue;
}
}
if ( retrieve_synccookie == 0 ) {
if ( is_entry_syncConsumerSubentry( e ) ) {
be_entry_release_r( &op, e );
continue;
}
}
if( verbose ) {
printf( "# id=%08lx\n", (long) id );
}

View file

@ -60,7 +60,7 @@ usage( int tool, const char *progname )
case SLAPADD:
options = "\n\t[-n databasenumber | -b suffix]\n"
"\t[-l ldiffile] [-u] [-p [-w] | -r [-i syncreplidlist] [-w]]\n";
"\t[-l ldiffile] [-u] [-w]\n";
break;
case SLAPAUTH:
@ -127,11 +127,11 @@ slap_tool_init(
switch( tool ) {
case SLAPADD:
options = "b:cd:f:i:l:n:prtuvWw";
options = "b:cd:f:l:n:tuvw";
break;
case SLAPCAT:
options = "a:b:cd:f:kl:mn:s:v";
options = "a:b:cd:f:l:n:s:v";
mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
break;
@ -192,39 +192,10 @@ slap_tool_init(
conffile = strdup( optarg );
break;
case 'i': /* specify syncrepl id list */
replica_id_string = strdup( optarg );
if ( !isdigit( (unsigned char) *replica_id_string )) {
usage( tool, progname );
exit( EXIT_FAILURE );
}
slap_str2clist( &replica_id_strlist, replica_id_string, "," );
for ( i = 0; replica_id_strlist && replica_id_strlist[i]; i++ ) ;
replica_id_list = ch_calloc( i + 1, sizeof( int ) );
for ( i = 0; replica_id_strlist && replica_id_strlist[i]; i++ ) {
replica_id_list[i] = atoi( replica_id_strlist[i] );
if ( replica_id_list[i] >= 1000 ) {
fprintf(stderr,
"%s: syncrepl id %d is out of range [0..999]\n",
progname, replica_id_list[i] );
exit( EXIT_FAILURE );
}
}
replica_id_list[i] = -1;
break;
case 'k': /* Retrieve sync cookie entry */
retrieve_synccookie = 1;
break;
case 'l': /* LDIF file */
ldiffile = strdup( optarg );
break;
case 'm': /* Retrieve ldapsync entry */
retrieve_ctxcsn = 1;
break;
case 'M':
ber_str2bv( optarg, 0, 0, &mech );
break;
@ -233,14 +204,6 @@ slap_tool_init(
dbnum = atoi( optarg ) - 1;
break;
case 'p': /* replica promotion */
replica_promotion = 1;
break;
case 'r': /* replica demotion */
replica_demotion = 1;
break;
case 'R':
realm = optarg;
break;
@ -266,13 +229,8 @@ slap_tool_init(
verbose++;
break;
case 'W': /* write context csn on every entry add */
update_ctxcsn = SLAP_TOOL_CTXCSN_BATCH;
/* FIXME : update_ctxcsn = SLAP_TOOL_CTXCSN_ENTRY; */
break;
case 'w': /* write context csn on at the end */
update_ctxcsn = SLAP_TOOL_CTXCSN_BATCH;
update_ctxcsn++;
break;
case 'X':
@ -293,14 +251,6 @@ slap_tool_init(
usage( tool, progname );
}
if ( replica_promotion && replica_demotion ) {
usage( tool, progname );
} else if ( !replica_promotion && !replica_demotion ) {
if ( update_ctxcsn != SLAP_TOOL_CTXCSN_KEEP ) {
usage( tool, progname );
}
}
break;
case SLAPDN:

View file

@ -32,21 +32,10 @@ enum slaptool {
SLAPLAST
};
#define SLAP_TOOL_CTXCSN_KEEP 0
#define SLAP_TOOL_CTXCSN_ENTRY 1
#define SLAP_TOOL_CTXCSN_BATCH 2
typedef struct tool_vars {
Backend *tv_be;
int tv_verbose;
int tv_update_ctxcsn;
int tv_retrieve_ctxcsn;
int tv_retrieve_synccookie;
int tv_replica_promotion;
int tv_replica_demotion;
char *tv_replica_id_string;
char **tv_replica_id_strlist;
int *tv_replica_id_list;
int tv_continuemode;
int tv_nosubordinates;
int tv_dryrun;
@ -66,13 +55,6 @@ extern tool_vars tool_globals;
#define be tool_globals.tv_be
#define verbose tool_globals.tv_verbose
#define update_ctxcsn tool_globals.tv_update_ctxcsn
#define retrieve_ctxcsn tool_globals.tv_retrieve_ctxcsn
#define retrieve_synccookie tool_globals.tv_retrieve_synccookie
#define replica_promotion tool_globals.tv_replica_promotion
#define replica_demotion tool_globals.tv_replica_demotion
#define replica_id_string tool_globals.tv_replica_id_string
#define replica_id_strlist tool_globals.tv_replica_id_strlist
#define replica_id_list tool_globals.tv_replica_id_list
#define continuemode tool_globals.tv_continuemode
#define nosubordinates tool_globals.tv_nosubordinates
#define dryrun tool_globals.tv_dryrun

View file

@ -33,12 +33,6 @@
#undef ldap_debug
#include "../../libraries/libldap/ldap-int.h"
#define SYNCREPL_STR "syncreplxxx"
#define CN_STR "cn="
static const struct berval slap_syncrepl_bvc = BER_BVC(SYNCREPL_STR);
static const struct berval slap_syncrepl_cn_bvc = BER_BVC(CN_STR SYNCREPL_STR);
static int syncuuid_cmp( const void *, const void * );
static void avl_ber_bvfree( void * );
static void syncrepl_del_nonpresent( Operation *, syncinfo_t *, BerVarray );
@ -231,12 +225,11 @@ ldap_sync_search(
ber_init2( ber, NULL, LBER_USE_DER );
ber_set_option( ber, LBER_OPT_BER_MEMCTX, &ctx );
if ( si->si_syncCookie.octet_str &&
!BER_BVISNULL( &si->si_syncCookie.octet_str[0] ) )
if ( !BER_BVISNULL( &si->si_syncCookie.octet_str ) )
{
ber_printf( ber, "{eO}",
abs(si->si_type),
&si->si_syncCookie.octet_str[0] );
&si->si_syncCookie.octet_str );
} else {
ber_printf( ber, "{e}",
abs(si->si_type) );
@ -280,8 +273,6 @@ do_syncrep1(
int rc;
int cmdline_cookie_found = 0;
char syncrepl_cbuf[sizeof(CN_STR SYNCREPL_STR)];
struct berval syncrepl_cn_bv;
struct sync_cookie *sc = NULL;
struct berval *psub;
#ifdef HAVE_TLS
@ -396,89 +387,52 @@ do_syncrep1(
op->o_ssf = ( op->o_sasl_ssf > op->o_tls_ssf )
? op->o_sasl_ssf : op->o_tls_ssf;
/* get syncrepl cookie of shadow replica from subentry */
assert( si->si_rid < 1000 );
syncrepl_cn_bv.bv_val = syncrepl_cbuf;
syncrepl_cn_bv.bv_len = snprintf( syncrepl_cbuf, sizeof(syncrepl_cbuf),
CN_STR "syncrepl%ld", si->si_rid );
build_new_dn( &op->o_req_ndn, psub, &syncrepl_cn_bv, op->o_tmpmemctx );
op->o_req_dn = op->o_req_ndn;
LDAP_STAILQ_FOREACH( sc, &slap_sync_cookie, sc_next ) {
if ( si->si_rid == sc->rid ) {
cmdline_cookie_found = 1;
break;
}
}
if ( BER_BVISNULL( &si->si_syncCookie.octet_str )) {
/* get contextCSN shadow replica from database */
BerVarray csn = NULL;
struct berval newcookie;
if ( cmdline_cookie_found ) {
/* cookie is supplied in the command line */
BerVarray cookie = NULL;
struct berval cookie_bv;
assert( si->si_rid < 1000 );
op->o_req_ndn = op->o_bd->be_nsuffix[0];
op->o_req_dn = op->o_req_ndn;
LDAP_STAILQ_REMOVE( &slap_sync_cookie, sc, sync_cookie, sc_next );
slap_sync_cookie_free( &si->si_syncCookie, 0 );
/* read stored cookie if it exists */
/* try to read stored contextCSN */
backend_attribute( op, NULL, &op->o_req_ndn,
slap_schema.si_ad_syncreplCookie, &cookie, ACL_READ );
slap_schema.si_ad_contextCSN, &csn, ACL_READ );
if ( csn ) {
ch_free( si->si_syncCookie.ctxcsn.bv_val );
ber_dupbv( &si->si_syncCookie.ctxcsn, csn );
ber_bvarray_free_x( csn, op->o_tmpmemctx );
}
if ( !cookie ) {
/* no stored cookie */
if ( sc->ctxcsn == NULL ||
BER_BVISNULL( sc->ctxcsn ) ) {
si->si_syncCookie.rid = si->si_rid;
LDAP_STAILQ_FOREACH( sc, &slap_sync_cookie, sc_next ) {
if ( si->si_rid == sc->rid ) {
cmdline_cookie_found = 1;
break;
}
}
if ( cmdline_cookie_found ) {
/* cookie is supplied in the command line */
LDAP_STAILQ_REMOVE( &slap_sync_cookie, sc, sync_cookie, sc_next );
if ( BER_BVISNULL( &sc->ctxcsn ) ) {
/* if cmdline cookie does not have ctxcsn */
/* component, set it to an initial value */
slap_init_sync_cookie_ctxcsn( sc );
}
slap_sync_cookie_free( &si->si_syncCookie, 0 );
slap_dup_sync_cookie( &si->si_syncCookie, sc );
slap_sync_cookie_free( sc, 1 );
sc = NULL;
} else {
/* stored cookie */
struct berval newcookie = BER_BVNULL;
ber_dupbv( &cookie_bv, &cookie[0] );
ber_bvarray_add( &si->si_syncCookie.octet_str, &cookie_bv );
slap_parse_sync_cookie( &si->si_syncCookie );
ber_bvarray_free( si->si_syncCookie.octet_str );
si->si_syncCookie.octet_str = NULL;
ber_bvarray_free_x( cookie, op->o_tmpmemctx );
if ( sc->ctxcsn != NULL ) {
/* command line cookie wins */
if ( si->si_syncCookie.ctxcsn ) {
ber_bvarray_free( si->si_syncCookie.ctxcsn );
si->si_syncCookie.ctxcsn = NULL;
}
ber_dupbv( &cookie_bv, &sc->ctxcsn[0] );
ber_bvarray_add( &si->si_syncCookie.ctxcsn, &cookie_bv );
}
if ( sc->rid != -1 ) {
/* command line cookie wins */
si->si_syncCookie.rid = sc->rid;
}
slap_sync_cookie_free( sc, 1 );
sc = NULL;
slap_compose_sync_cookie( NULL, &newcookie,
&si->si_syncCookie.ctxcsn[0],
si->si_syncCookie.rid );
ber_bvarray_add( &si->si_syncCookie.octet_str, &newcookie );
}
} else {
/* no command line cookie is specified */
if ( si->si_syncCookie.octet_str == NULL ) {
BerVarray cookie = NULL;
struct berval cookie_bv;
/* try to read stored cookie */
backend_attribute( op, NULL, &op->o_req_ndn,
slap_schema.si_ad_syncreplCookie, &cookie, ACL_READ );
if ( cookie ) {
ber_dupbv( &cookie_bv, &cookie[0] );
ber_bvarray_add( &si->si_syncCookie.octet_str, &cookie_bv );
slap_parse_sync_cookie( &si->si_syncCookie );
ber_bvarray_free_x( cookie, op->o_tmpmemctx );
}
if ( !BER_BVISNULL( &si->si_syncCookie.ctxcsn )) {
slap_compose_sync_cookie( NULL, &si->si_syncCookie.octet_str,
&si->si_syncCookie.ctxcsn, si->si_syncCookie.rid );
}
}
@ -497,8 +451,6 @@ done:
}
}
slap_sl_free( op->o_req_ndn.bv_val, op->o_tmpmemctx );
return rc;
}
@ -523,8 +475,8 @@ do_syncrep2(
int syncstate;
struct berval syncUUID = BER_BVNULL;
struct sync_cookie syncCookie = { NULL };
struct sync_cookie syncCookie_req = { NULL };
struct sync_cookie syncCookie = { 0 };
struct sync_cookie syncCookie_req = { 0 };
struct berval cookie = BER_BVNULL;
int rc, err, i;
@ -594,12 +546,10 @@ do_syncrep2(
if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
ber_scanf( ber, /*"{"*/ "m}", &cookie );
if ( !BER_BVISNULL( &cookie ) ) {
struct berval tmp_bv;
ber_dupbv( &tmp_bv, &cookie );
ber_bvarray_add( &syncCookie.octet_str, &tmp_bv );
ch_free( syncCookie.octet_str.bv_val );
ber_dupbv( &syncCookie.octet_str, &cookie );
}
if ( syncCookie.octet_str &&
!BER_BVISNULL( &syncCookie.octet_str[0] ) )
if ( !BER_BVISNULL( &syncCookie.octet_str ) )
{
slap_parse_sync_cookie( &syncCookie );
}
@ -607,9 +557,8 @@ do_syncrep2(
if ( syncrepl_message_to_entry( si, op, msg,
&modlist, &entry, syncstate ) == LDAP_SUCCESS ) {
rc_efree = syncrepl_entry( si, op, entry, &modlist,
syncstate, &syncUUID, &syncCookie_req, syncCookie.ctxcsn );
if ( syncCookie.octet_str &&
!BER_BVISNULL( &syncCookie.octet_str[0] ) )
syncstate, &syncUUID, &syncCookie_req, &syncCookie.ctxcsn );
if ( !BER_BVISNULL( &syncCookie.octet_str ) )
{
syncrepl_updateCookie( si, op, psub, &syncCookie );
}
@ -642,12 +591,10 @@ do_syncrep2(
if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
ber_scanf( ber, "m", &cookie );
if ( !BER_BVISNULL( &cookie ) ) {
struct berval tmp_bv;
ber_dupbv( &tmp_bv, &cookie );
ber_bvarray_add( &syncCookie.octet_str, &tmp_bv);
ch_free( syncCookie.octet_str.bv_val );
ber_dupbv( &syncCookie.octet_str, &cookie);
}
if ( syncCookie.octet_str &&
!BER_BVISNULL( &syncCookie.octet_str[0] ) )
if ( !BER_BVISNULL( &syncCookie.octet_str ) )
{
slap_parse_sync_cookie( &syncCookie );
}
@ -658,18 +605,18 @@ do_syncrep2(
}
ber_scanf( ber, /*"{"*/ "}" );
}
if ( syncCookie_req.ctxcsn == NULL ) {
if ( BER_BVISNULL( &syncCookie_req.ctxcsn )) {
match = -1;
} else if ( syncCookie.ctxcsn == NULL ) {
} else if ( BER_BVISNULL( &syncCookie.ctxcsn )) {
match = 1;
} else {
value_match( &match, slap_schema.si_ad_entryCSN,
slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
&syncCookie_req.ctxcsn[0], &syncCookie.ctxcsn[0],
&syncCookie_req.ctxcsn, &syncCookie.ctxcsn,
&text );
}
if ( syncCookie.octet_str && !BER_BVISNULL( syncCookie.octet_str ) &&
if ( !BER_BVISNULL( &syncCookie.octet_str ) &&
match < 0 && err == LDAP_SUCCESS )
{
syncrepl_updateCookie( si, op, psub, &syncCookie );
@ -728,13 +675,10 @@ do_syncrep2(
{
ber_scanf( ber, "m", &cookie );
if ( !BER_BVISNULL( &cookie ) ) {
struct berval tmp_bv;
ber_dupbv( &tmp_bv, &cookie );
ber_bvarray_add( &syncCookie.octet_str,
&tmp_bv);
ch_free( syncCookie.octet_str.bv_val );
ber_dupbv( &syncCookie.octet_str, &cookie );
}
if ( syncCookie.octet_str &&
!BER_BVISNULL( &syncCookie.octet_str[0] ) )
if ( !BER_BVISNULL( &syncCookie.octet_str ) )
{
slap_parse_sync_cookie( &syncCookie );
}
@ -758,13 +702,10 @@ do_syncrep2(
{
ber_scanf( ber, "m", &cookie );
if ( !BER_BVISNULL( &cookie ) ) {
struct berval tmp_bv;
ber_dupbv( &tmp_bv, &cookie );
ber_bvarray_add( &syncCookie.octet_str,
&tmp_bv );
ch_free( syncCookie.octet_str.bv_val );
ber_dupbv( &syncCookie.octet_str, &cookie );
}
if ( syncCookie.octet_str &&
!BER_BVISNULL( &syncCookie.octet_str[0] ) )
if ( !BER_BVISNULL( &syncCookie.octet_str ) )
{
slap_parse_sync_cookie( &syncCookie );
}
@ -800,19 +741,19 @@ do_syncrep2(
continue;
}
if ( syncCookie_req.ctxcsn == NULL ) {
if ( BER_BVISNULL( &syncCookie_req.ctxcsn )) {
match = -1;
} else if ( syncCookie.ctxcsn == NULL ) {
} else if ( BER_BVISNULL( &syncCookie.ctxcsn )) {
match = 1;
} else {
value_match( &match, slap_schema.si_ad_entryCSN,
slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
&syncCookie_req.ctxcsn[0],
&syncCookie.ctxcsn[0], &text );
&syncCookie_req.ctxcsn,
&syncCookie.ctxcsn, &text );
}
if ( syncCookie.ctxcsn && !BER_BVISNULL( &syncCookie.ctxcsn[0] ) &&
if ( !BER_BVISNULL( &syncCookie.ctxcsn ) &&
match < 0 )
{
syncrepl_updateCookie( si, op, psub, &syncCookie);
@ -844,7 +785,7 @@ do_syncrep2(
break;
}
if ( syncCookie.octet_str ) {
if ( !BER_BVISNULL( &syncCookie.octet_str )) {
slap_sync_cookie_free( &syncCookie_req, 0 );
slap_dup_sync_cookie( &syncCookie_req, &syncCookie );
slap_sync_cookie_free( &syncCookie, 0 );
@ -1848,28 +1789,6 @@ syncrepl_add_glue(
return;
}
static struct berval ocbva[] = {
BER_BVC("top"),
BER_BVC("subentry"),
BER_BVC("syncConsumerSubentry"),
BER_BVNULL
};
static struct berval cnbva[] = {
BER_BVNULL,
BER_BVNULL
};
static struct berval ssbva[] = {
BER_BVC("{}"),
BER_BVNULL
};
static struct berval scbva[] = {
BER_BVNULL,
BER_BVNULL
};
void
syncrepl_updateCookie(
syncinfo_t *si,
@ -1878,183 +1797,56 @@ syncrepl_updateCookie(
struct sync_cookie *syncCookie )
{
Backend *be = op->o_bd;
Modifications *ml;
Modifications *mlnext;
Modifications *mod;
Modifications *modlist = NULL;
Modifications **modtail = &modlist;
Modifications mod = {0};
struct berval vals[2];
const char *text;
char txtbuf[SLAP_TEXT_BUFLEN];
size_t textlen = sizeof txtbuf;
Entry* e = NULL;
int rc;
char syncrepl_cbuf[sizeof(CN_STR SYNCREPL_STR)];
struct berval slap_syncrepl_dn_bv = BER_BVNULL;
struct berval slap_syncrepl_cn_bv = BER_BVNULL;
slap_callback cb = { NULL };
SlapReply rs_add = {REP_RESULT};
SlapReply rs_modify = {REP_RESULT};
slap_sync_cookie_free( &si->si_syncCookie, 0 );
slap_dup_sync_cookie( &si->si_syncCookie, syncCookie );
mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
mod->sml_op = LDAP_MOD_REPLACE;
mod->sml_desc = slap_schema.si_ad_objectClass;
mod->sml_type = mod->sml_desc->ad_cname;
mod->sml_values = ocbva;
*modtail = mod;
modtail = &mod->sml_next;
mod.sml_op = LDAP_MOD_REPLACE;
mod.sml_desc = slap_schema.si_ad_contextCSN;
mod.sml_type = mod.sml_desc->ad_cname;
mod.sml_values = vals;
vals[0] = si->si_syncCookie.ctxcsn;
vals[1].bv_val = NULL;
vals[1].bv_len = 0;
slap_queue_csn( op, &si->si_syncCookie.ctxcsn );
op->o_tag = LDAP_REQ_MODIFY;
ber_dupbv( &cnbva[0], (struct berval *) &slap_syncrepl_bvc );
assert( si->si_rid < 1000 );
cnbva[0].bv_len = snprintf( cnbva[0].bv_val,
slap_syncrepl_bvc.bv_len + 1,
"syncrepl%ld", si->si_rid );
mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
mod->sml_op = LDAP_MOD_REPLACE;
mod->sml_desc = slap_schema.si_ad_cn;
mod->sml_type = mod->sml_desc->ad_cname;
mod->sml_values = cnbva;
*modtail = mod;
modtail = &mod->sml_next;
mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
mod->sml_op = LDAP_MOD_REPLACE;
mod->sml_desc = slap_schema.si_ad_subtreeSpecification;
mod->sml_type = mod->sml_desc->ad_cname;
mod->sml_values = ssbva;
*modtail = mod;
modtail = &mod->sml_next;
/* Keep this last, so we can avoid touching the previous
* attributes unnecessarily.
*/
if ( scbva[0].bv_val ) ch_free( scbva[0].bv_val );
ber_dupbv( &scbva[0], &si->si_syncCookie.octet_str[0] );
mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
mod->sml_op = LDAP_MOD_REPLACE;
mod->sml_desc = slap_schema.si_ad_syncreplCookie;
mod->sml_type = mod->sml_desc->ad_cname;
mod->sml_values = scbva;
*modtail = mod;
modtail = &mod->sml_next;
slap_queue_csn( op, si->si_syncCookie.ctxcsn );
mlnext = mod;
op->o_tag = LDAP_REQ_ADD;
rc = slap_mods_opattrs( op, modlist, modtail,
&text, txtbuf, textlen, 0 );
for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
ml->sml_op = LDAP_MOD_REPLACE;
}
if( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods opattrs (%s)\n",
text, 0, 0 );
}
e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
slap_syncrepl_cn_bv.bv_val = syncrepl_cbuf;
assert( si->si_rid < 1000 );
slap_syncrepl_cn_bv.bv_len = snprintf( slap_syncrepl_cn_bv.bv_val,
slap_syncrepl_cn_bvc.bv_len + 1,
"cn=syncrepl%ld", si->si_rid );
build_new_dn( &slap_syncrepl_dn_bv, pdn, &slap_syncrepl_cn_bv,
op->o_tmpmemctx );
ber_dupbv( &e->e_name, &slap_syncrepl_dn_bv );
ber_dupbv( &e->e_nname, &slap_syncrepl_dn_bv );
if ( !BER_BVISNULL( &slap_syncrepl_dn_bv ) ) {
slap_sl_free( slap_syncrepl_dn_bv.bv_val, op->o_tmpmemctx );
}
e->e_attrs = NULL;
rc = slap_mods2entry( modlist, &e, 1, 1, &text, txtbuf, textlen );
if( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods2entry (%s)\n",
text, 0, 0 );
}
cb.sc_response = null_callback;
cb.sc_private = si;
op->o_callback = &cb;
op->o_req_dn = e->e_name;
op->o_req_ndn = e->e_nname;
op->o_req_dn = op->o_bd->be_suffix[0];
op->o_req_ndn = op->o_bd->be_nsuffix[0];
/* update persistent cookie */
update_cookie_retry:
op->o_tag = LDAP_REQ_MODIFY;
/* Just modify the cookie value, not the entire entry */
op->orm_modlist = mod;
/* update contextCSN */
op->o_msgid = SLAP_SYNC_UPDATE_MSGID;
op->orm_modlist = &mod;
rc = be->be_modify( op, &rs_modify );
op->o_msgid = 0;
if ( rs_modify.sr_err != LDAP_SUCCESS ) {
if ( rs_modify.sr_err == LDAP_REFERRAL ||
rs_modify.sr_err == LDAP_NO_SUCH_OBJECT ) {
op->o_tag = LDAP_REQ_ADD;
op->ora_e = e;
rc = be->be_add( op, &rs_add );
if ( rs_add.sr_err != LDAP_SUCCESS ) {
if ( rs_add.sr_err == LDAP_ALREADY_EXISTS ) {
goto update_cookie_retry;
} else if ( rs_add.sr_err == LDAP_REFERRAL ||
rs_add.sr_err == LDAP_NO_SUCH_OBJECT ) {
Debug( LDAP_DEBUG_ANY,
"cookie will be non-persistent\n",
0, 0, 0 );
} else {
Debug( LDAP_DEBUG_ANY,
"be_add failed (%d)\n", rs_add.sr_err, 0, 0 );
}
} else {
be_entry_release_w( op, e );
goto done;
}
} else {
Debug( LDAP_DEBUG_ANY,
"be_modify failed (%d)\n", rs_modify.sr_err, 0, 0 );
}
}
if ( e != NULL ) {
entry_free( e );
Debug( LDAP_DEBUG_ANY,
"be_modify failed (%d)\n", rs_modify.sr_err, 0, 0 );
}
done :
slap_graduate_commit_csn( op );
if ( !BER_BVISNULL( &cnbva[0] ) ) {
ch_free( cnbva[0].bv_val );
BER_BVZERO( &cnbva[0] );
}
if ( !BER_BVISNULL( &scbva[0] ) ) {
ch_free( scbva[0].bv_val );
BER_BVZERO( &scbva[0] );
}
if ( mlnext->sml_next ) {
slap_mods_free( mlnext->sml_next );
mlnext->sml_next = NULL;
}
for (ml = modlist ; ml != NULL; ml = mlnext ) {
mlnext = ml->sml_next;
free( ml );
}
return;
}
@ -2216,40 +2008,6 @@ null_callback(
return LDAP_SUCCESS;
}
Entry *
slap_create_syncrepl_entry(
Backend *be,
struct berval *context_csn,
struct berval *rdn,
struct berval *cn )
{
Entry* e;
struct berval bv;
e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
attr_merge( e, slap_schema.si_ad_objectClass, ocbva, NULL );
attr_merge_one( e, slap_schema.si_ad_structuralObjectClass,
&ocbva[1], NULL );
attr_merge_one( e, slap_schema.si_ad_cn, cn, NULL );
if ( context_csn ) {
attr_merge_one( e, slap_schema.si_ad_syncreplCookie,
context_csn, NULL );
}
BER_BVSTR( &bv, "{}" );
attr_merge_one( e, slap_schema.si_ad_subtreeSpecification, &bv, NULL );
build_new_dn( &e->e_name, &be->be_nsuffix[0], rdn, NULL );
ber_dupbv( &e->e_nname, &e->e_name );
return e;
}
struct berval *
slap_uuidstr_from_normalized(
struct berval* uuidstr,