3 * Replication Engine which uses the LDAP Sync protocol
5 /* Copyright (c) 2003 by International Business Machines, Inc.
7 * International Business Machines, Inc. (hereinafter called IBM) grants
8 * permission under its copyrights to use, copy, modify, and distribute this
9 * Software with or without fee, provided that the above copyright notice and
10 * all paragraphs of this notice appear in all copies, and that the name of IBM
11 * not be used in connection with the marketing of any product incorporating
12 * the Software or modifications thereof, without specific, written prior
15 * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17 * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
18 * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
19 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
20 * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
27 #include <ac/string.h>
28 #include <ac/socket.h>
34 #include "lutil_ldap.h"
38 static const struct berval slap_syncrepl_bvc = BER_BVC("syncreplxxx");
39 static const struct berval slap_syncrepl_cn_bvc = BER_BVC("cn=syncreplxxx");
42 syncrepl_del_nonpresent( LDAP *, Operation * );
44 /* callback functions */
45 static int cookie_callback( struct slap_op *, struct slap_rep * );
46 static int dn_callback( struct slap_op *, struct slap_rep * );
47 static int nonpresent_callback( struct slap_op *, struct slap_rep * );
48 static int null_callback( struct slap_op *, struct slap_rep * );
49 static int contextcsn_callback( Operation*, SlapReply* );
51 static AttributeDescription **sync_descs;
53 struct runqueue_s syncrepl_rq;
58 sync_descs = ch_malloc( 4 * sizeof( AttributeDescription * ));
59 sync_descs[0] = slap_schema.si_ad_objectClass;
60 sync_descs[1] = slap_schema.si_ad_structuralObjectClass;
61 sync_descs[2] = slap_schema.si_ad_entryCSN;
78 BerElement *sync_ber = NULL;
79 struct berval *sync_bvalp = NULL;
83 struct timeval timeout;
85 /* setup LDAP SYNC control */
86 sync_ber = ber_alloc_t( LBER_USE_DER );
87 ber_set_option( sync_ber, LBER_OPT_BER_MEMCTX, NULL );
89 if ( si->syncCookie ) {
90 ber_printf( sync_ber, "{eO}", abs(si->type), si->syncCookie );
92 ber_printf( sync_ber, "{e}", abs(si->type) );
95 if ( ber_flatten( sync_ber, &sync_bvalp ) == LBER_ERROR ) {
96 ber_free( sync_ber, 1 );
99 ber_free( sync_ber, 1 );
101 ctrls = (LDAPControl**) sl_calloc( 3, sizeof(LDAPControl*), NULL );
103 c[0].ldctl_oid = LDAP_CONTROL_SYNC;
104 c[0].ldctl_value = (*sync_bvalp);
105 c[0].ldctl_iscritical = si->type < 0;
109 c[1].ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
110 c[1].ldctl_value.bv_val = si->authzId;
111 c[1].ldctl_value.bv_len = strlen( si->authzId );
112 c[1].ldctl_iscritical = 1;
120 err = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, ctrls );
122 ber_bvfree( sync_bvalp );
125 if ( err != LDAP_OPT_SUCCESS )
126 fprintf( stderr, "Could not set controls : %d\n", err );
128 timeout.tv_sec = si->tlimit > 0 ? si->tlimit : 1;
130 rc = ldap_search_ext( ld, si->base, si->scope, si->filterstr,
131 si->attrs, si->attrsonly, sctrls, cctrls,
132 si->tlimit < 0 ? NULL : &timeout,
133 si->slimit, msgidp );
143 struct re_s* rtask = arg;
144 syncinfo_t *si = ( syncinfo_t * ) rtask->arg;
145 Backend *be = si->be;
147 SlapReply rs = {REP_RESULT};
150 LDAPControl **sctrls = NULL;
151 LDAPControl **rctrls = NULL;
152 LDAPControl *rctrlp = NULL;
153 BerElement *sync_ber = NULL;
154 struct berval *sync_bvalp = NULL;
156 BerElement *ctrl_ber = NULL;
157 BerElement *res_ber = NULL;
160 LDAPMessage *res = NULL;
161 LDAPMessage *msg = NULL;
165 int nresponses, nreferences, nextended, npartial;
166 int nresponses_psearch;
168 int cancel_msgid = -1;
170 struct berval *retdata = NULL;
172 int sync_info_arrived = 0;
176 struct berval syncUUID = { 0, NULL };
177 struct berval syncCookie = { 0, NULL };
178 struct berval syncCookie_req = { 0, NULL };
183 int syncinfo_arrived = 0;
186 AttributeDescription** descs = NULL;
198 struct berval base_bv = { 0, NULL };
199 struct berval pbase = { 0, NULL };
200 struct berval nbase = { 0, NULL };
201 struct berval psubrdn = { 0, NULL };
202 struct berval nsubrdn = { 0, NULL };
203 struct berval psub = { 0, NULL };
204 struct berval nsub = { 0, NULL };
205 Modifications *modlist = NULL;
206 Modifications *ml, *mlnext;
207 char *def_filter_str = NULL;
209 struct berval slap_syncrepl_bv = BER_BVNULL;
214 struct timeval *tout_p = NULL;
215 struct timeval tout = { 10, 0 };
218 LDAP_LOG ( OPERATION, DETAIL1, "do_syncrepl\n", 0, 0, 0 );
220 Debug( LDAP_DEBUG_TRACE, "=>do_syncrepl\n", 0, 0, 0 );
226 if ( abs(si->type) != LDAP_SYNC_REFRESH_ONLY &&
227 abs(si->type) != LDAP_SYNC_REFRESH_AND_PERSIST ) {
231 si->sync_mode = LDAP_SYNC_STATE_MODE;
233 /* Init connection to master */
235 rc = ldap_initialize( &ld, si->provideruri );
236 if ( rc != LDAP_SUCCESS ) {
238 LDAP_LOG( OPERATION, ERR, "do_syncrepl: "
239 "ldap_initialize failed (%s)\n",
240 si->provideruri, 0, 0 );
242 Debug( LDAP_DEBUG_ANY, "do_syncrepl: "
243 "ldap_initialize failed (%s)\n",
244 si->provideruri, 0, 0 );
248 op.o_protocol = LDAP_VERSION3;
249 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &op.o_protocol );
254 rc = ldap_start_tls_s( ld, NULL, NULL );
255 if( rc != LDAP_SUCCESS ) {
257 LDAP_LOG ( OPERATION, ERR, "do_syncrepl: "
258 "%s: ldap_start_tls failed (%d)\n",
259 si->tls == TLS_CRITICAL ? "Error" : "Warning",
262 Debug( LDAP_DEBUG_ANY,
263 "%s: ldap_start_tls failed (%d)\n",
264 si->tls == TLS_CRITICAL ? "Error" : "Warning",
267 if( si->tls == TLS_CRITICAL )
272 if ( si->bindmethod == LDAP_AUTH_SASL ) {
273 #ifdef HAVE_CYRUS_SASL
276 if ( si->secprops != NULL ) {
277 int err = ldap_set_option( ld,
278 LDAP_OPT_X_SASL_SECPROPS, si->secprops);
280 if( err != LDAP_OPT_SUCCESS ) {
282 LDAP_LOG ( OPERATION, ERR, "do_bind: Error: "
283 "ldap_set_option(%s,SECPROPS,\"%s\") failed!\n",
284 si->provideruri, si->secprops, 0 );
286 Debug( LDAP_DEBUG_ANY, "Error: ldap_set_option "
287 "(%s,SECPROPS,\"%s\") failed!\n",
288 si->provideruri, si->secprops, NULL );
294 defaults = lutil_sasl_defaults( ld,
301 rc = ldap_sasl_interactive_bind_s( ld,
309 /* FIXME : different error behaviors according to
311 2) on err policy : exit, retry, backoff ...
313 if ( rc != LDAP_SUCCESS ) {
315 LDAP_LOG ( OPERATION, ERR, "do_syncrepl: "
316 "ldap_sasl_interactive_bind_s failed (%d)\n",
319 Debug( LDAP_DEBUG_ANY, "do_syncrepl: "
320 "ldap_sasl_interactive_bind_s failed (%d)\n",
325 #else /* HAVE_CYRUS_SASL */
326 fprintf( stderr, "not compiled with SASL support\n" );
330 rc = ldap_bind_s( ld, si->binddn, si->passwd, si->bindmethod );
331 if ( rc != LDAP_SUCCESS ) {
333 LDAP_LOG ( OPERATION, ERR, "do_syncrepl: "
334 "ldap_bind_s failed (%d)\n", rc, 0, 0 );
336 Debug( LDAP_DEBUG_ANY, "do_syncrepl: "
337 "ldap_bind_s failed (%d)\n", rc, 0, 0 );
343 /* set thread context in syncinfo */
346 /* set memory context */
347 #define SLAB_SIZE 1048576
349 memctx = sl_mem_create( memsiz, ctx );
350 op.o_tmpmemctx = memctx;
351 op.o_tmpmfuncs = &sl_mfuncs;
354 op.o_tag = LDAP_REQ_SEARCH;
355 op.o_dn = si->updatedn;
356 op.o_ndn = si->updatedn;
358 op.o_time = slap_get_time();
359 op.o_managedsait = 1;
360 op.o_threadctx = si->ctx;
363 op.o_connid = op.o_conn->c_connid;
364 op.ors_scope = LDAP_SCOPE_BASE;
365 op.ors_deref = LDAP_DEREF_NEVER;
368 op.ors_attrsonly = 0;
370 op.ors_filter = str2filter_x( &op, def_filter_str = "(objectClass=*)" );
371 ber_str2bv( def_filter_str, 0, 0, &op.ors_filterstr );
374 conn.c_send_ldap_result = slap_send_ldap_result;
375 conn.c_send_search_entry = slap_send_search_entry;
376 conn.c_send_search_reference = slap_send_search_reference;
378 /* get syncrepl cookie of shadow replica from subentry */
379 ber_str2bv( si->base, 0, 0, &base_bv );
380 dnPrettyNormal( 0, &base_bv, &pbase, &nbase, op.o_tmpmemctx );
382 ber_dupbv( &slap_syncrepl_bv, (struct berval *) &slap_syncrepl_bvc );
383 slap_syncrepl_bv.bv_len = snprintf( slap_syncrepl_bv.bv_val,
384 slap_syncrepl_bvc.bv_len,
385 "syncrepl%d", si->id );
386 build_new_dn( &op.o_req_dn, &pbase, &slap_syncrepl_bv, op.o_tmpmemctx );
387 build_new_dn( &op.o_req_ndn, &nbase, &slap_syncrepl_bv, op.o_tmpmemctx );
389 /* set callback function */
390 cb.sc_response = cookie_callback;
393 /* search subentry to retrieve cookie */
394 si->syncCookie = NULL;
395 be->be_search( &op, &rs );
397 if ( op.o_req_dn.bv_val )
398 ch_free( op.o_req_dn.bv_val );
399 if ( op.o_req_ndn.bv_val )
400 ch_free( op.o_req_ndn.bv_val );
402 filter_free( op.ors_filter );
403 if ( op.ors_filterstr.bv_val )
404 ch_free( op.ors_filterstr.bv_val );
405 if ( slap_syncrepl_bv.bv_val )
406 ch_free( slap_syncrepl_bv.bv_val );
408 ch_free( pbase.bv_val );
410 ch_free( nbase.bv_val );
412 ber_dupbv( &syncCookie_req, si->syncCookie );
414 psub = be->be_nsuffix[0];
416 for ( n = 0; si->attrs[ n ] != NULL; n++ ) ;
419 /* Delete Attributes */
421 for ( i = 0; descs[i] != NULL; i++ ) {
422 for ( j = 0; si->attrs[j] != NULL; j++ ) {
423 if ( !strcmp( si->attrs[j], descs[i]->ad_cname.bv_val )) {
424 ch_free( si->attrs[j] );
425 for ( k = j; si->attrs[k] != NULL; k++ ) {
426 si->attrs[k] = si->attrs[k+1];
431 for ( n = 0; si->attrs[ n ] != NULL; n++ );
432 tmp = ( char ** ) ch_realloc( si->attrs, ( n + 4 ) * sizeof( char * ));
435 LDAP_LOG( OPERATION, ERR, "out of memory\n", 0,0,0 );
437 Debug( LDAP_DEBUG_ANY, "out of memory\n", 0,0,0 );
441 tmp = ( char ** ) ch_realloc( si->attrs, 5 * sizeof( char * ));
444 LDAP_LOG( OPERATION, ERR, "out of memory\n", 0,0,0 );
446 Debug( LDAP_DEBUG_ANY, "out of memory\n", 0,0,0 );
449 tmp[ n++ ] = ch_strdup( "*" );
457 for ( i = 0; descs[ i ] != NULL; i++ ) {
458 si->attrs[ n++ ] = ch_strdup ( descs[i]->ad_cname.bv_val );
459 si->attrs[ n ] = NULL;
462 rc = ldap_sync_search( si, ld, NULL, NULL, &msgid );
463 if( rc != LDAP_SUCCESS ) {
464 fprintf( stderr, "syncrepl: ldap_search_ext: %s (%d)\n",
465 ldap_err2string( rc ), rc );
469 if ( abs(si->type) == LDAP_SYNC_REFRESH_AND_PERSIST ){
475 while (( rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ONE, tout_p, &res )) >= 0 ) {
478 if ( slapd_abrupt_shutdown ) {
485 for ( msg = ldap_first_message( ld, res );
487 msg = ldap_next_message( ld, msg ) )
489 syncCookie.bv_len = 0; syncCookie.bv_val = NULL;
490 switch( ldap_msgtype( msg ) ) {
491 case LDAP_RES_SEARCH_ENTRY:
492 entry = syncrepl_message_to_entry( si, ld, &op, msg,
493 &modlist, &syncstate, &syncUUID, &syncCookie );
494 rc_efree = syncrepl_entry( si, ld, &op, entry, modlist,
495 syncstate, &syncUUID, &syncCookie, !syncinfo_arrived );
496 if ( syncCookie.bv_len ) {
497 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie );
500 slap_mods_free( modlist );
507 case LDAP_RES_SEARCH_REFERENCE:
509 LDAP_LOG( OPERATION, ERR,
510 "do_syncrepl : reference received\n", 0, 0, 0 );
512 Debug( LDAP_DEBUG_ANY,
513 "do_syncrepl : reference received\n", 0, 0, 0 );
517 case LDAP_RES_SEARCH_RESULT:
518 ldap_parse_result( ld, msg, &err, NULL, NULL, NULL, &rctrls, 0 );
521 ctrl_ber = ber_alloc_t( LBER_USE_DER );
522 ber_set_option( ctrl_ber, LBER_OPT_BER_MEMCTX, &op.o_tmpmemctx );
523 ber_write( ctrl_ber, rctrlp->ldctl_value.bv_val, rctrlp->ldctl_value.bv_len, 0 );
524 ber_reset( ctrl_ber, 1 );
526 ber_scanf( ctrl_ber, "{" /*"}"*/);
527 if ( ber_peek_tag( ctrl_ber, &len )
528 == LDAP_SYNC_TAG_COOKIE ) {
529 ber_scanf( ctrl_ber, "o", &syncCookie );
532 value_match( &match, slap_schema.si_ad_entryCSN,
533 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
534 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
535 &syncCookie_req, &syncCookie, &text );
536 if (si->type == LDAP_SYNC_REFRESH_AND_PERSIST) {
537 /* FIXME : different error behaviors according to
538 1) err code : LDAP_BUSY ...
539 2) on err policy : stop service, stop sync, retry
541 if ( syncCookie.bv_len && match < 0) {
542 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie );
545 ber_free( ctrl_ber, 1 );
548 /* FIXME : different error behaviors according to
549 1) err code : LDAP_BUSY ...
550 2) on err policy : stop service, stop sync, retry
552 if ( syncCookie.bv_len && match < 0 ) {
553 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie);
555 if ( si->sync_mode == LDAP_SYNC_STATE_MODE && match < 0 ) {
556 syncrepl_del_nonpresent( ld, &op );
559 ber_free( ctrl_ber, 1 );
564 case LDAP_RES_INTERMEDIATE:
565 rc = ldap_parse_intermediate( ld, msg,
566 &retoid, &retdata, NULL, 0 );
567 if ( !rc && !strcmp( retoid, LDAP_SYNC_INFO ) ) {
568 sync_info_arrived = 1;
569 res_ber = ber_init( retdata );
570 ber_scanf( res_ber, "{e" /*"}"*/, &syncstate );
572 if ( ber_peek_tag( res_ber, &len )
573 == LDAP_SYNC_TAG_COOKIE ) {
574 ber_scanf( res_ber, /*"{"*/ "o}", &syncCookie );
576 if ( syncstate == LDAP_SYNC_NEW_COOKIE ) {
578 LDAP_LOG( OPERATION, ERR,
579 "do_syncrepl : cookie required\n", 0, 0, 0 );
581 Debug( LDAP_DEBUG_ANY,
582 "do_syncrepl : cookie required\n", 0, 0, 0 );
587 value_match( &match, slap_schema.si_ad_entryCSN,
588 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
589 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
590 &syncCookie_req, &syncCookie, &text );
592 if ( syncCookie.bv_len && match < 0 ) {
593 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie);
596 if ( syncstate == LDAP_SYNC_STATE_MODE_DONE ) {
598 syncrepl_del_nonpresent( ld, &op );
600 si->sync_mode = LDAP_SYNC_LOG_MODE;
601 } else if ( syncstate == LDAP_SYNC_LOG_MODE_DONE ) {
602 si->sync_mode = LDAP_SYNC_PERSIST_MODE;
603 } else if ( syncstate == LDAP_SYNC_REFRESH_DONE ) {
604 si->sync_mode = LDAP_SYNC_PERSIST_MODE;
605 } else if ( syncstate != LDAP_SYNC_NEW_COOKIE ||
606 syncstate != LDAP_SYNC_LOG_MODE_DONE ) {
608 LDAP_LOG( OPERATION, ERR,
609 "do_syncrepl : unknown sync info\n", 0, 0, 0 );
611 Debug( LDAP_DEBUG_ANY,
612 "do_syncrepl : unknown sync info\n", 0, 0, 0 );
616 ldap_memfree( retoid );
617 ber_bvfree( retdata );
618 ber_free( res_ber, 1 );
622 LDAP_LOG( OPERATION, ERR,"do_syncrepl :"
623 " unknown intermediate "
624 "response\n", 0, 0, 0 );
626 Debug( LDAP_DEBUG_ANY, "do_syncrepl : "
627 "unknown intermediate response (%d)\n",
630 ldap_memfree( retoid );
631 ber_bvfree( retdata );
637 LDAP_LOG( OPERATION, ERR, "do_syncrepl : "
638 "unknown message\n", 0, 0, 0 );
640 Debug( LDAP_DEBUG_ANY, "do_syncrepl : "
641 "unknown message\n", 0, 0, 0 );
646 if ( syncCookie.bv_val )
647 ch_free( syncCookie.bv_val );
648 if ( syncUUID.bv_val )
649 ch_free( syncUUID.bv_val );
658 ldap_get_option( ld, LDAP_OPT_ERROR_NUMBER, &errno );
659 errstr = ldap_err2string( errno );
662 LDAP_LOG( OPERATION, ERR,
663 "do_syncrepl : %s\n", errstr, 0, 0 );
665 Debug( LDAP_DEBUG_ANY,
666 "do_syncrepl : %s\n", errstr, 0, 0 );
671 if ( syncCookie.bv_val )
672 ch_free( syncCookie.bv_val );
673 if ( syncCookie_req.bv_val )
674 ch_free( syncCookie_req.bv_val );
675 if ( syncUUID.bv_val )
676 ch_free( syncUUID.bv_val );
683 ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
684 ldap_pvt_runqueue_stoptask( &syncrepl_rq, rtask );
685 if ( si->type == LDAP_SYNC_REFRESH_ONLY ) {
686 ldap_pvt_runqueue_resched( &syncrepl_rq, rtask );
688 ldap_pvt_runqueue_remove( &syncrepl_rq, rtask );
690 ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
696 syncrepl_message_to_entry(
701 Modifications **modlist,
703 struct berval *syncUUID,
704 struct berval *syncCookie
708 BerElement *ber = NULL;
710 struct berval bv = {0, NULL};
713 Modifications **modtail = modlist;
714 Backend *be = op->o_bd;
717 char txtbuf[SLAP_TEXT_BUFLEN];
718 size_t textlen = sizeof txtbuf;
720 struct berval **bvals = NULL;
722 struct berval bdn = {0, NULL};
724 struct berval empty_bv = { 0, NULL };
730 LDAPControl** rctrls = NULL;
731 BerElement* ctrl_ber;
735 Modifications *ml = NULL;
736 AttributeDescription** descs;
741 if ( ldap_msgtype( msg ) != LDAP_RES_SEARCH_ENTRY ) {
743 LDAP_LOG( OPERATION, ERR,
744 "Message type should be entry (%d)", ldap_msgtype( msg ), 0, 0 );
746 Debug( LDAP_DEBUG_ANY,
747 "Message type should be entry (%d)", ldap_msgtype( msg ), 0, 0 );
752 op->o_tag = LDAP_REQ_ADD;
754 rc = ldap_get_dn_ber( ld, msg, &ber, &bdn );
756 if ( rc != LDAP_SUCCESS ) {
758 LDAP_LOG( OPERATION, ERR,
759 "syncrepl_message_to_entry : dn get failed (%d)", rc, 0, 0 );
761 Debug( LDAP_DEBUG_ANY,
762 "syncrepl_message_to_entry : dn get failed (%d)", rc, 0, 0 );
767 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
768 dnPrettyNormal( NULL, &bdn, &e->e_name, &e->e_nname, NULL );
772 while ( ber_remaining( ber ) ) {
773 tag = ber_scanf( ber, "{mW}", &tmp.sml_type, &tmp.sml_values );
775 if ( tag == LBER_ERROR ) break;
776 if ( tmp.sml_type.bv_val == NULL ) break;
778 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
780 mod->sml_op = LDAP_MOD_REPLACE;
781 mod->sml_next = NULL;
782 mod->sml_desc = NULL;
783 mod->sml_type = tmp.sml_type;
784 mod->sml_bvalues = tmp.sml_bvalues;
785 mod->sml_nvalues = NULL;
788 modtail = &mod->sml_next;
791 if ( ber_scanf( ber, "}") == LBER_ERROR ) {
793 LDAP_LOG( OPERATION, ERR,
794 "syncrepl_message_to_entry: ber_scanf failed\n", 0, 0, 0 );
796 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: ber_scanf failed\n",
803 tmpber = ldap_get_message_ber( msg );
804 ber = ber_dup( tmpber );
806 ber_scanf( ber, "{xx" );
808 rc = ldap_pvt_get_controls( ber, &rctrls );
809 if ( rc != LDAP_SUCCESS ) {
811 LDAP_LOG( OPERATION, ERR,
812 "syncrepl_message_to_entry : control get failed (%d)", rc, 0, 0 );
814 Debug( LDAP_DEBUG_ANY,
815 "syncrepl_message_to_entry : control get failed (%d)", rc, 0, 0 );
822 ctrl_ber = ber_alloc_t( LBER_USE_DER );
823 ber_set_option( ctrl_ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
824 ber_write( ctrl_ber, rctrlp->ldctl_value.bv_val, rctrlp->ldctl_value.bv_len, 0 );
825 ber_reset( ctrl_ber, 1 );
826 ber_scanf( ctrl_ber, "{eo", syncstate, syncUUID );
827 if ( ber_peek_tag( ctrl_ber, &len ) == LDAP_SYNC_TAG_COOKIE ) {
828 ber_scanf( ctrl_ber, "o}", syncCookie );
830 ber_free( ctrl_ber, 1 );
831 ldap_controls_free( rctrls );
834 LDAP_LOG( OPERATION, ERR,"syncrepl_message_to_entry : "
835 " rctrls absent\n", 0, 0, 0 );
837 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry :"
838 " rctrls absent\n", 0, 0, 0 );
842 if ( *syncstate == LDAP_SYNC_PRESENT || *syncstate == LDAP_SYNC_DELETE ) {
846 if ( *modlist == NULL ) {
848 LDAP_LOG( OPERATION, ERR,
849 "syncrepl_message_to_entry: no attributes\n", 0, 0, 0 );
851 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: no attributes\n",
857 while ( ml != NULL ) {
858 AttributeDescription *ad = NULL;
859 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, &text );
861 if( rc != LDAP_SUCCESS ) {
871 rc = slap_mods_check( *modlist, 1, &text, txtbuf, textlen, NULL );
873 if ( rc != LDAP_SUCCESS ) {
875 LDAP_LOG( OPERATION, ERR,
876 "syncrepl_message_to_entry: mods check (%s)\n", text, 0, 0 );
878 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods check (%s)\n",
884 rc = slap_mods2entry( *modlist, &e, 1, 1, &text, txtbuf, textlen);
885 if( rc != LDAP_SUCCESS ) {
887 LDAP_LOG( OPERATION, ERR,
888 "syncrepl_message_to_entry: mods2entry (%s)\n", text, 0, 0 );
890 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods2entry (%s)\n",
903 syncuuid_cmp( const void* v_uuid1, const void* v_uuid2 )
905 const struct berval *uuid1 = v_uuid1;
906 const struct berval *uuid2 = v_uuid2;
907 int rc = uuid1->bv_len - uuid2->bv_len;
909 return ( strcmp( uuid1->bv_val, uuid2->bv_val ) );
918 Modifications* modlist,
920 struct berval* syncUUID,
921 struct berval* syncCookie,
925 Backend *be = op->o_bd;
927 struct berval csn_bv = {0, NULL};
928 struct berval *syncuuid_bv = NULL;
929 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
931 SlapReply rs = {REP_RESULT};
932 int rc = LDAP_SUCCESS;
934 struct berval base_bv = {0, NULL};
942 ( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD )) {
943 syncuuid_bv = ber_dupbv( NULL, syncUUID );
944 avl_insert( &si->presentlist, (caddr_t) syncuuid_bv,
945 syncuuid_cmp, avl_dup_error );
948 if ( syncstate == LDAP_SYNC_PRESENT ) {
956 filterstr = (char *) sl_malloc( strlen("entryUUID=") + syncUUID->bv_len + 1,
958 strcpy( filterstr, "entryUUID=" );
959 strcat( filterstr, syncUUID->bv_val );
962 si->syncUUID_ndn = NULL;
964 filter = str2filter( filterstr );
965 ber_str2bv( filterstr, strlen(filterstr), 1, &op->ors_filterstr );
966 ch_free( filterstr );
967 op->ors_filter = filter;
968 op->ors_scope = LDAP_SCOPE_SUBTREE;
970 /* get syncrepl cookie of shadow replica from subentry */
971 ber_str2bv( si->base, strlen(si->base), 1, &base_bv );
972 dnPrettyNormal( 0, &base_bv, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
973 ch_free( base_bv.bv_val );
975 /* set callback function */
976 op->o_callback = &cb;
977 cb.sc_response = dn_callback;
980 si->syncUUID_ndn = NULL;
982 rc = be->be_search( op, &rs );
984 if ( op->o_req_dn.bv_val )
985 ch_free( op->o_req_dn.bv_val );
986 if ( op->o_req_ndn.bv_val )
987 ch_free( op->o_req_ndn.bv_val );
988 if ( op->ors_filter )
989 filter_free( op->ors_filter );
990 if ( op->ors_filterstr.bv_val )
991 ch_free( op->ors_filterstr.bv_val );
993 cb.sc_response = null_callback;
996 if ( rc == LDAP_SUCCESS && si->syncUUID_ndn && si->sync_mode != LDAP_SYNC_LOG_MODE ) {
997 op->o_req_dn = *si->syncUUID_ndn;
998 op->o_req_ndn = *si->syncUUID_ndn;
999 op->o_tag = LDAP_REQ_DELETE;
1000 rc = be->be_delete( op, &rs );
1003 if ( si->syncUUID_ndn ) {
1004 ber_bvfree( si->syncUUID_ndn );
1007 switch ( syncstate ) {
1008 case LDAP_SYNC_ADD :
1009 case LDAP_SYNC_MODIFY :
1011 if ( rc == LDAP_SUCCESS ||
1012 rc == LDAP_REFERRAL ||
1013 rc == LDAP_NO_SUCH_OBJECT ) {
1015 attr_delete( &e->e_attrs, slap_schema.si_ad_entryUUID );
1016 attr_merge_normalize_one( e, slap_schema.si_ad_entryUUID, syncUUID, op->o_tmpmemctx );
1018 op->o_tag = LDAP_REQ_ADD;
1020 op->o_req_dn = e->e_name;
1021 op->o_req_ndn = e->e_nname;
1022 rc = be->be_add( op, &rs );
1024 if ( rc != LDAP_SUCCESS ) {
1025 if ( rc == LDAP_ALREADY_EXISTS ) {
1026 op->o_tag = LDAP_REQ_MODIFY;
1027 op->orm_modlist = modlist;
1028 op->o_req_dn = e->e_name;
1029 op->o_req_ndn = e->e_nname;
1030 rc = be->be_modify( op, &rs );
1032 if ( rc != LDAP_SUCCESS ) {
1034 LDAP_LOG( OPERATION, ERR,
1035 "syncrepl_entry : be_modify failed (%d)\n",
1038 Debug( LDAP_DEBUG_ANY,
1039 "syncrepl_entry : be_modify failed (%d)\n",
1044 } else if ( rc == LDAP_REFERRAL ||
1045 rc == LDAP_NO_SUCH_OBJECT ) {
1046 syncrepl_add_glue( si, ld, op, e,
1048 syncUUID, syncCookie);
1053 LDAP_LOG( OPERATION, ERR,
1054 "syncrepl_entry : be_add failed (%d)\n",
1057 Debug( LDAP_DEBUG_ANY,
1058 "syncrepl_entry : be_add failed (%d)\n",
1066 be_entry_release_w( op, e );
1071 LDAP_LOG( OPERATION, ERR,
1072 "syncrepl_entry : be_search failed (%d)\n", rc, 0, 0 );
1074 Debug( LDAP_DEBUG_ANY,
1075 "syncrepl_entry : be_search failed (%d)\n", rc, 0, 0 );
1081 case LDAP_SYNC_DELETE :
1082 if ( si->sync_mode == LDAP_SYNC_LOG_MODE ) {
1083 op->o_req_dn = *si->syncUUID_ndn;
1084 op->o_req_ndn = *si->syncUUID_ndn;
1085 op->o_tag = LDAP_REQ_DELETE;
1086 rc = be->be_delete( op, &rs );
1088 /* Already deleted otherwise */
1093 LDAP_LOG( OPERATION, ERR,
1094 "syncrepl_entry : unknown syncstate\n", 0, 0, 0 );
1096 Debug( LDAP_DEBUG_ANY,
1097 "syncrepl_entry : unknown syncstate\n", 0, 0, 0 );
1104 syncrepl_del_nonpresent(
1109 Backend* be = op->o_bd;
1110 syncinfo_t *si = op->o_si;
1112 struct berval base_bv = {0, NULL};
1114 SlapReply rs = {REP_RESULT};
1115 struct berval filterstr_bv = {0, NULL};
1116 struct nonpresent_entry *np_list, *np_prev;
1118 ber_str2bv( si->base, strlen(si->base), 1, &base_bv );
1119 dnPrettyNormal(0, &base_bv, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
1120 ch_free( base_bv.bv_val );
1122 filter = str2filter( si->filterstr );
1124 cb.sc_response = nonpresent_callback;
1127 op->o_callback = &cb;
1128 op->o_tag = LDAP_REQ_SEARCH;
1129 op->ors_scope = si->scope;
1130 op->ors_deref = LDAP_DEREF_NEVER;
1133 op->ors_attrsonly = 0;
1134 op->ors_attrs = NULL;
1135 op->ors_filter = filter;
1136 ber_str2bv( si->filterstr, strlen( si->filterstr ), 1, &op->ors_filterstr );
1138 op->o_nocaching = 1;
1139 be->be_search( op, &rs );
1140 op->o_nocaching = 0;
1142 if ( op->o_req_dn.bv_val )
1143 ch_free( op->o_req_dn.bv_val );
1144 if ( op->o_req_ndn.bv_val )
1145 ch_free( op->o_req_ndn.bv_val );
1146 if ( op->ors_filter )
1147 filter_free( op->ors_filter );
1148 if ( op->ors_filterstr.bv_val )
1149 ch_free( op->ors_filterstr.bv_val );
1151 if ( !LDAP_LIST_EMPTY( &si->nonpresentlist ) ) {
1152 np_list = LDAP_LIST_FIRST( &si->nonpresentlist );
1153 while ( np_list != NULL ) {
1154 LDAP_LIST_REMOVE( np_list, np_link );
1156 np_list = LDAP_LIST_NEXT( np_list, np_link );
1157 op->o_tag = LDAP_REQ_DELETE;
1158 op->o_callback = &cb;
1159 cb.sc_response = null_callback;
1161 op->o_req_dn = *np_prev->dn;
1162 op->o_req_ndn = *np_prev->ndn;
1163 op->o_bd->be_delete( op, &rs );
1164 ber_bvfree( np_prev->dn );
1165 ber_bvfree( np_prev->ndn );
1166 op->o_req_dn.bv_val = NULL;
1167 op->o_req_ndn.bv_val = NULL;
1182 Modifications* modlist,
1184 struct berval* syncUUID,
1185 struct berval* syncCookie
1188 Backend *be = op->o_bd;
1189 struct berval uuid_bv = {0, NULL};
1193 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
1196 struct berval dn = {0, NULL};
1197 struct berval pdn = {0, NULL};
1198 struct berval ndn = {0, NULL};
1199 struct berval rdn = {0, NULL};
1201 SlapReply rs = {REP_RESULT};
1202 Connection *conn = op->o_conn;
1205 op->o_tag = LDAP_REQ_ADD;
1206 op->o_callback = &cb;
1207 cb.sc_response = null_callback;
1210 ber_dupbv( &dn, &e->e_nname );
1211 ber_dupbv( &pdn, &e->e_nname );
1214 while ( !be_issuffix ( be, &pdn )) {
1215 dnParent( &dn, &pdn );
1216 dn.bv_val = pdn.bv_val;
1217 dn.bv_len = pdn.bv_len;
1222 for ( i = 0; i <= levels; i++ ) {
1223 glue = (Entry*) ch_calloc( 1, sizeof(Entry) );
1224 ber_dupbv( &dn, &e->e_nname );
1228 for ( k = 0; k < j; k++ ) {
1229 dnParent( &dn, &pdn );
1230 dn.bv_val = pdn.bv_val;
1231 dn.bv_len = pdn.bv_len;
1234 dnPrettyNormal( 0, &dn, &pdn, &ndn, op->o_tmpmemctx );
1235 ber_dupbv( &glue->e_name, &pdn );
1236 ber_dupbv( &glue->e_nname, &ndn );
1238 ch_free( pdn.bv_val );
1239 ch_free( ndn.bv_val );
1241 a = ch_calloc( 1, sizeof( Attribute ));
1242 a->a_desc = slap_schema.si_ad_objectClass;
1244 a->a_vals = ch_calloc( 3, sizeof( struct berval ));
1245 ber_str2bv( "top", strlen("top"), 1, &a->a_vals[0] );
1246 ber_str2bv( "glue", strlen("glue"), 1, &a->a_vals[1] );
1247 a->a_vals[2].bv_len = 0;
1248 a->a_vals[2].bv_val = NULL;
1250 a->a_nvals = ch_calloc( 3, sizeof( struct berval ));
1251 ber_str2bv( "top", strlen("top"), 1, &a->a_nvals[0] );
1252 ber_str2bv( "glue", strlen("glue"), 1, &a->a_nvals[1] );
1253 a->a_nvals[2].bv_len = 0;
1254 a->a_nvals[2].bv_val = NULL;
1256 a->a_next = glue->e_attrs;
1259 a = ch_calloc( 1, sizeof( Attribute ));
1260 a->a_desc = slap_schema.si_ad_structuralObjectClass;
1262 a->a_vals = ch_calloc( 2, sizeof( struct berval ));
1263 ber_str2bv( "glue", strlen("glue"), 1, &a->a_vals[0] );
1264 a->a_vals[1].bv_len = 0;
1265 a->a_vals[1].bv_val = NULL;
1267 a->a_nvals = ch_calloc( 2, sizeof( struct berval ));
1268 ber_str2bv( "glue", strlen("glue"), 1, &a->a_nvals[0] );
1269 a->a_nvals[1].bv_len = 0;
1270 a->a_nvals[1].bv_val = NULL;
1272 a->a_next = glue->e_attrs;
1275 if ( !strcmp( e->e_nname.bv_val, glue->e_nname.bv_val )) {
1276 op->o_req_dn = e->e_name;
1277 op->o_req_ndn = e->e_nname;
1279 rc = be->be_add ( op, &rs );
1280 if ( rc == LDAP_SUCCESS )
1281 be_entry_release_w( op, e );
1286 op->o_req_dn = glue->e_name;
1287 op->o_req_ndn = glue->e_nname;
1289 rc = be->be_add ( op, &rs );
1290 if ( rc == LDAP_SUCCESS ) {
1291 be_entry_release_w( op, glue );
1293 /* incl. ALREADY EXIST */
1302 static struct berval ocbva[] = {
1304 BER_BVC("subentry"),
1305 BER_BVC("syncConsumerSubentry"),
1309 static struct berval cnbva[] = {
1314 static struct berval ssbva[] = {
1319 static struct berval scbva[] = {
1320 BER_BVC("subentry"),
1325 syncrepl_updateCookie(
1330 struct berval *syncCookie
1333 Backend *be = op->o_bd;
1335 Modifications *mlnext;
1337 Modifications *modlist = NULL;
1338 Modifications **modtail = &modlist;
1341 char txtbuf[SLAP_TEXT_BUFLEN];
1342 size_t textlen = sizeof txtbuf;
1347 struct berval slap_syncrepl_dn_bv = BER_BVNULL;
1348 struct berval slap_syncrepl_cn_bv = BER_BVNULL;
1351 SlapReply rs = {REP_RESULT};
1353 /* update in memory cookie */
1354 if ( si->syncCookie != NULL ) {
1355 ber_bvfree( si->syncCookie );
1357 si->syncCookie = ber_dupbv( NULL, syncCookie );
1358 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1359 mod->sml_op = LDAP_MOD_REPLACE;
1360 mod->sml_desc = slap_schema.si_ad_objectClass;
1361 mod->sml_type = mod->sml_desc->ad_cname;
1362 mod->sml_bvalues = ocbva;
1364 modtail = &mod->sml_next;
1366 ber_dupbv( &cnbva[0], (struct berval *) &slap_syncrepl_bvc );
1367 cnbva[0].bv_len = snprintf( cnbva[0].bv_val,
1368 slap_syncrepl_bvc.bv_len,
1369 "syncrepl%d", si->id );
1370 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1371 mod->sml_op = LDAP_MOD_REPLACE;
1372 mod->sml_desc = slap_schema.si_ad_cn;
1373 mod->sml_type = mod->sml_desc->ad_cname;
1374 mod->sml_bvalues = cnbva;
1376 modtail = &mod->sml_next;
1378 ber_dupbv( &scbva[0], si->syncCookie );
1379 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1380 mod->sml_op = LDAP_MOD_REPLACE;
1381 mod->sml_desc = slap_schema.si_ad_syncreplCookie;
1382 mod->sml_type = mod->sml_desc->ad_cname;
1383 mod->sml_bvalues = scbva;
1385 modtail = &mod->sml_next;
1387 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1388 mod->sml_op = LDAP_MOD_REPLACE;
1389 mod->sml_desc = slap_schema.si_ad_subtreeSpecification;
1390 mod->sml_type = mod->sml_desc->ad_cname;
1391 mod->sml_bvalues = ssbva;
1393 modtail = &mod->sml_next;
1396 rc = slap_mods_check( modlist, 1, &text, txtbuf, textlen, NULL );
1398 if ( rc != LDAP_SUCCESS ) {
1400 LDAP_LOG( OPERATION, ERR,
1401 "syncrepl_updateCookie: mods check (%s)\n", text, 0, 0 );
1403 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods check (%s)\n",
1409 op->o_tag = LDAP_REQ_ADD;
1410 rc = slap_mods_opattrs( op, modlist, modtail,
1411 &text,txtbuf, textlen );
1413 for ( ml = modlist; ml != NULL; ml = mlnext ) {
1414 mlnext = ml->sml_next;
1415 ml->sml_op = LDAP_MOD_REPLACE;
1418 if( rc != LDAP_SUCCESS ) {
1420 LDAP_LOG( OPERATION, ERR,
1421 "syncrepl_updateCookie: mods opattrs (%s)\n", text, 0, 0 );
1423 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods opattrs (%s)\n",
1428 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
1430 ber_dupbv( &slap_syncrepl_cn_bv, (struct berval *) &slap_syncrepl_cn_bvc );
1431 slap_syncrepl_cn_bv.bv_len = snprintf( slap_syncrepl_cn_bv.bv_val,
1432 slap_syncrepl_cn_bvc.bv_len,
1433 "cn=syncrepl%d", si->id );
1435 build_new_dn( &slap_syncrepl_dn_bv, pdn, &slap_syncrepl_cn_bv, NULL );
1436 dnPrettyNormal( NULL, &slap_syncrepl_dn_bv, &e->e_name, &e->e_nname, NULL );
1438 if ( slap_syncrepl_cn_bv.bv_val )
1439 ch_free( slap_syncrepl_cn_bv.bv_val );
1440 if ( slap_syncrepl_dn_bv.bv_val )
1441 ch_free( slap_syncrepl_dn_bv.bv_val );
1445 rc = slap_mods2entry( modlist, &e, 1, 1, &text, txtbuf, textlen );
1447 if( rc != LDAP_SUCCESS ) {
1449 LDAP_LOG( OPERATION, ERR,
1450 "syncrepl_updateCookie: mods2entry (%s)\n", text, 0, 0 );
1452 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods2entry (%s)\n",
1457 cb.sc_response = null_callback;
1460 op->o_callback = &cb;
1461 op->o_req_dn = e->e_name;
1462 op->o_req_ndn = e->e_nname;
1464 /* update persistent cookie */
1465 update_cookie_retry:
1466 op->o_tag = LDAP_REQ_MODIFY;
1467 op->orm_modlist = modlist;
1468 rc = be->be_modify( op, &rs );
1470 if ( rc != LDAP_SUCCESS ) {
1471 if ( rc == LDAP_REFERRAL ||
1472 rc == LDAP_NO_SUCH_OBJECT ) {
1473 op->o_tag = LDAP_REQ_ADD;
1475 rc = be->be_add( op, &rs );
1476 if ( rc != LDAP_SUCCESS ) {
1477 if ( rc == LDAP_ALREADY_EXISTS ) {
1478 goto update_cookie_retry;
1479 } else if ( rc == LDAP_REFERRAL ||
1480 rc == LDAP_NO_SUCH_OBJECT ) {
1482 LDAP_LOG( OPERATION, ERR,
1483 "cookie will be non-persistent\n",
1486 Debug( LDAP_DEBUG_ANY,
1487 "cookie will be non-persistent\n",
1492 LDAP_LOG( OPERATION, ERR,
1493 "be_add failed (%d)\n",
1496 Debug( LDAP_DEBUG_ANY,
1497 "be_add failed (%d)\n",
1502 be_entry_release_w( op, e );
1507 LDAP_LOG( OPERATION, ERR,
1508 "be_modify failed (%d)\n", rc, 0, 0 );
1510 Debug( LDAP_DEBUG_ANY,
1511 "be_modify failed (%d)\n", rc, 0, 0 );
1522 if ( cnbva[0].bv_val )
1523 ch_free( cnbva[0].bv_val );
1525 for ( ; ml != NULL; ml = mlnext ) {
1526 mlnext = ml->sml_next;
1534 avl_ber_bvfree( void *bv )
1539 if ( ((struct berval *)bv)->bv_val != NULL ) {
1540 ch_free ( ((struct berval *)bv)->bv_val );
1542 ch_free ( (char *) bv );
1551 syncinfo_t *si = op->o_callback->sc_private;
1554 if ( rs->sr_type != REP_SEARCH ) return LDAP_SUCCESS;
1556 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_syncreplCookie );
1559 si->syncCookie = NULL;
1561 si->syncCookie = ber_dupbv( NULL, &a->a_vals[0] );
1563 return LDAP_SUCCESS;
1572 syncinfo_t *si = op->o_callback->sc_private;
1574 if ( rs->sr_type == REP_SEARCH ) {
1575 if ( si->syncUUID_ndn != NULL ) {
1577 LDAP_LOG( OPERATION, ERR,
1578 "dn_callback : multiple entries match dn\n", 0, 0, 0 );
1580 Debug( LDAP_DEBUG_ANY,
1581 "dn_callback : multiple entries match dn\n", 0, 0, 0 );
1584 if ( rs->sr_entry == NULL ) {
1585 si->syncUUID_ndn = NULL;
1587 si->syncUUID_ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname );
1592 return LDAP_SUCCESS;
1596 nonpresent_callback(
1601 syncinfo_t *si = op->o_callback->sc_private;
1604 struct berval* present_uuid = NULL;
1606 SlapReply rs_cb = {REP_RESULT};
1607 struct nonpresent_entry *np_entry;
1609 if ( rs->sr_type == REP_RESULT ) {
1610 count = avl_free( si->presentlist, avl_ber_bvfree );
1611 si->presentlist = NULL;
1612 return LDAP_SUCCESS;
1613 } else if ( rs->sr_type == REP_SEARCH ) {
1614 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID );
1619 present_uuid = avl_find( si->presentlist, &a->a_vals[0], syncuuid_cmp );
1621 if ( present_uuid == NULL ) {
1622 np_entry = (struct nonpresent_entry *)
1623 ch_calloc( 1, sizeof( struct nonpresent_entry ));
1624 np_entry->dn = ber_dupbv( NULL, &rs->sr_entry->e_name );
1625 np_entry->ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname );
1626 LDAP_LIST_INSERT_HEAD( &si->nonpresentlist, np_entry, np_link );
1628 avl_delete( &si->presentlist,
1629 &a->a_vals[0], syncuuid_cmp );
1630 ch_free( present_uuid->bv_val );
1631 ch_free( present_uuid );
1633 return LDAP_SUCCESS;
1635 return LDAP_SUCCESS;
1646 syncinfo_t *si = op->o_callback->sc_private;
1648 if ( rs->sr_err != LDAP_SUCCESS &&
1649 rs->sr_err != LDAP_REFERRAL &&
1650 rs->sr_err != LDAP_ALREADY_EXISTS &&
1651 rs->sr_err != LDAP_NO_SUCH_OBJECT ) {
1653 LDAP_LOG( OPERATION, ERR,
1654 "null_callback : error code 0x%x\n",
1657 Debug( LDAP_DEBUG_ANY,
1658 "null_callback : error code 0x%x\n",
1662 return LDAP_SUCCESS;
1666 slap_create_syncrepl_entry(
1668 struct berval *context_csn,
1678 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
1680 attr_merge( e, slap_schema.si_ad_objectClass, ocbva, NULL );
1682 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &ocbva[1], NULL );
1684 attr_merge_one( e, slap_schema.si_ad_cn, cn, NULL );
1686 if ( context_csn ) {
1687 attr_merge_one( e, slap_schema.si_ad_syncreplCookie,
1688 context_csn, NULL );
1692 bv.bv_len = sizeof("{}")-1;
1693 attr_merge_one( e, slap_schema.si_ad_subtreeSpecification, &bv, NULL );
1695 build_new_dn( &e->e_name, &be->be_nsuffix[0], rdn, NULL );
1696 ber_dupbv( &e->e_nname, &e->e_name );