- 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,
- 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, -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 );
- 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 );
- }
- }
- } 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,
- "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,
- "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 );
- }