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>
33 #include "lutil_ldap.h"
37 static const struct berval slap_syncrepl_bvc = BER_BVC("syncreplxxx");
38 static const struct berval slap_syncrepl_cn_bvc = BER_BVC("cn=syncreplxxx");
41 syncrepl_del_nonpresent( LDAP *, Operation * );
43 /* callback functions */
44 static int cookie_callback( struct slap_op *, struct slap_rep * );
45 static int dn_callback( struct slap_op *, struct slap_rep * );
46 static int nonpresent_callback( struct slap_op *, struct slap_rep * );
47 static int null_callback( struct slap_op *, struct slap_rep * );
48 static int contextcsn_callback( Operation*, SlapReply* );
50 static AttributeDescription **sync_descs;
52 struct runqueue_s syncrepl_rq;
57 sync_descs = ch_malloc( 4 * sizeof( AttributeDescription * ));
58 sync_descs[0] = slap_schema.si_ad_objectClass;
59 sync_descs[1] = slap_schema.si_ad_structuralObjectClass;
60 sync_descs[2] = slap_schema.si_ad_entryCSN;
77 BerElement *sync_ber = NULL;
78 struct berval *sync_bvalp = NULL;
82 struct timeval timeout;
84 /* setup LDAP SYNC control */
85 sync_ber = ber_alloc_t( LBER_USE_DER );
86 ber_set_option( sync_ber, LBER_OPT_BER_MEMCTX, NULL );
88 if ( si->syncCookie ) {
89 ber_printf( sync_ber, "{eO}", abs(si->type), si->syncCookie );
91 ber_printf( sync_ber, "{e}", abs(si->type) );
94 if ( ber_flatten( sync_ber, &sync_bvalp ) == LBER_ERROR ) {
95 ber_free( sync_ber, 1 );
98 ber_free( sync_ber, 1 );
100 ctrls = (LDAPControl**) sl_calloc( 3, sizeof(LDAPControl*), NULL );
102 c[0].ldctl_oid = LDAP_CONTROL_SYNC;
103 c[0].ldctl_value = (*sync_bvalp);
104 c[0].ldctl_iscritical = si->type < 0;
108 c[1].ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
109 c[1].ldctl_value.bv_val = si->authzId;
110 c[1].ldctl_value.bv_len = strlen( si->authzId );
111 c[1].ldctl_iscritical = 1;
119 err = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, ctrls );
121 ber_bvfree( sync_bvalp );
124 if ( err != LDAP_OPT_SUCCESS )
125 fprintf( stderr, "Could not set controls : %d\n", err );
127 timeout.tv_sec = si->tlimit > 0 ? si->tlimit : 1;
129 rc = ldap_search_ext( ld, si->base, si->scope, si->filterstr,
130 si->attrs, si->attrsonly, sctrls, cctrls,
131 si->tlimit < 0 ? NULL : &timeout,
132 si->slimit, msgidp );
142 struct re_s* rtask = arg;
143 syncinfo_t *si = ( syncinfo_t * ) rtask->arg;
144 Backend *be = si->be;
146 SlapReply rs = {REP_RESULT};
149 LDAPControl **sctrls = NULL;
150 LDAPControl **rctrls = NULL;
151 LDAPControl *rctrlp = NULL;
152 BerElement *sync_ber = NULL;
153 struct berval *sync_bvalp = NULL;
155 BerElement *ctrl_ber = NULL;
156 BerElement *res_ber = NULL;
159 LDAPMessage *res = NULL;
160 LDAPMessage *msg = NULL;
164 int nresponses, nreferences, nextended, npartial;
165 int nresponses_psearch;
167 int cancel_msgid = -1;
169 struct berval *retdata = NULL;
171 int sync_info_arrived = 0;
175 struct berval syncUUID = { 0, NULL };
176 struct berval syncCookie = { 0, NULL };
177 struct berval syncCookie_req = { 0, NULL };
182 int syncinfo_arrived = 0;
185 AttributeDescription** descs = NULL;
197 struct berval base_bv = { 0, NULL };
198 struct berval pbase = { 0, NULL };
199 struct berval nbase = { 0, NULL };
200 struct berval psubrdn = { 0, NULL };
201 struct berval nsubrdn = { 0, NULL };
202 struct berval psub = { 0, NULL };
203 struct berval nsub = { 0, NULL };
204 Modifications *modlist = NULL;
205 Modifications *ml, *mlnext;
206 char *def_filter_str = NULL;
208 struct berval slap_syncrepl_cn_bv = BER_BVNULL;
213 struct timeval *tout_p = NULL;
214 struct timeval tout = { 10, 0 };
217 LDAP_LOG ( OPERATION, DETAIL1, "do_syncrepl\n", 0, 0, 0 );
219 Debug( LDAP_DEBUG_TRACE, "=>do_syncrepl\n", 0, 0, 0 );
225 if ( abs(si->type) != LDAP_SYNC_REFRESH_ONLY &&
226 abs(si->type) != LDAP_SYNC_REFRESH_AND_PERSIST ) {
230 si->sync_mode = LDAP_SYNC_STATE_MODE;
232 /* Init connection to master */
234 rc = ldap_initialize( &ld, si->provideruri );
235 if ( rc != LDAP_SUCCESS ) {
237 LDAP_LOG( OPERATION, ERR, "do_syncrepl: "
238 "ldap_initialize failed (%s)\n",
239 si->provideruri, 0, 0 );
241 Debug( LDAP_DEBUG_ANY, "do_syncrepl: "
242 "ldap_initialize failed (%s)\n",
243 si->provideruri, 0, 0 );
247 op.o_protocol = LDAP_VERSION3;
248 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &op.o_protocol );
253 rc = ldap_start_tls_s( ld, NULL, NULL );
254 if( rc != LDAP_SUCCESS ) {
256 LDAP_LOG ( OPERATION, ERR, "do_syncrepl: "
257 "%s: ldap_start_tls failed (%d)\n",
258 si->tls == TLS_CRITICAL ? "Error" : "Warning",
261 Debug( LDAP_DEBUG_ANY,
262 "%s: ldap_start_tls failed (%d)\n",
263 si->tls == TLS_CRITICAL ? "Error" : "Warning",
266 if( si->tls == TLS_CRITICAL )
271 if ( si->bindmethod == LDAP_AUTH_SASL ) {
272 #ifdef HAVE_CYRUS_SASL
275 if ( si->secprops != NULL ) {
276 int err = ldap_set_option( ld,
277 LDAP_OPT_X_SASL_SECPROPS, si->secprops);
279 if( err != LDAP_OPT_SUCCESS ) {
281 LDAP_LOG ( OPERATION, ERR, "do_bind: Error: "
282 "ldap_set_option(%s,SECPROPS,\"%s\") failed!\n",
283 si->provideruri, si->secprops, 0 );
285 Debug( LDAP_DEBUG_ANY, "Error: ldap_set_option "
286 "(%s,SECPROPS,\"%s\") failed!\n",
287 si->provideruri, si->secprops, NULL );
293 defaults = lutil_sasl_defaults( ld,
300 rc = ldap_sasl_interactive_bind_s( ld,
308 /* FIXME : different error behaviors according to
310 2) on err policy : exit, retry, backoff ...
312 if ( rc != LDAP_SUCCESS ) {
314 LDAP_LOG ( OPERATION, ERR, "do_syncrepl: "
315 "ldap_sasl_interactive_bind_s failed (%d)\n",
318 Debug( LDAP_DEBUG_ANY, "do_syncrepl: "
319 "ldap_sasl_interactive_bind_s failed (%d)\n",
324 #else /* HAVE_CYRUS_SASL */
325 fprintf( stderr, "not compiled with SASL support\n" );
329 rc = ldap_bind_s( ld, si->binddn, si->passwd, si->bindmethod );
330 if ( rc != LDAP_SUCCESS ) {
332 LDAP_LOG ( OPERATION, ERR, "do_syncrepl: "
333 "ldap_bind_s failed (%d)\n", rc, 0, 0 );
335 Debug( LDAP_DEBUG_ANY, "do_syncrepl: "
336 "ldap_bind_s failed (%d)\n", rc, 0, 0 );
342 /* set thread context in syncinfo */
345 /* set memory context */
346 #define SLAB_SIZE 1048576
348 memctx = sl_mem_create( memsiz, ctx );
349 op.o_tmpmemctx = memctx;
350 op.o_tmpmfuncs = &sl_mfuncs;
353 op.o_tag = LDAP_REQ_SEARCH;
354 op.o_dn = si->updatedn;
355 op.o_ndn = si->updatedn;
357 op.o_time = slap_get_time();
358 op.o_managedsait = 1;
359 op.o_threadctx = si->ctx;
362 op.o_connid = op.o_conn->c_connid;
363 op.ors_scope = LDAP_SCOPE_BASE;
364 op.ors_deref = LDAP_DEREF_NEVER;
367 op.ors_attrsonly = 0;
369 op.ors_filter = str2filter_x( &op, def_filter_str = "(objectClass=*)" );
370 ber_str2bv( def_filter_str, 0, 0, &op.ors_filterstr );
373 conn.c_send_ldap_result = slap_send_ldap_result;
374 conn.c_send_search_entry = slap_send_search_entry;
375 conn.c_send_search_reference = slap_send_search_reference;
377 /* get syncrepl cookie of shadow replica from subentry */
378 ber_str2bv( si->base, 0, 0, &base_bv );
379 dnPrettyNormal( 0, &base_bv, &pbase, &nbase, op.o_tmpmemctx );
381 ber_dupbv( &slap_syncrepl_cn_bv, (struct berval *) &slap_syncrepl_cn_bvc );
382 slap_syncrepl_cn_bv.bv_len = snprintf( slap_syncrepl_cn_bv.bv_val,
383 slap_syncrepl_cn_bvc.bv_len,
384 "cn=syncrepl%d", si->id );
385 build_new_dn( &op.o_req_dn, &pbase, &slap_syncrepl_cn_bv, op.o_tmpmemctx );
386 build_new_dn( &op.o_req_ndn, &nbase, &slap_syncrepl_cn_bv, op.o_tmpmemctx );
388 /* set callback function */
389 cb.sc_response = cookie_callback;
392 /* search subentry to retrieve cookie */
393 si->syncCookie = NULL;
394 be->be_search( &op, &rs );
396 if ( op.o_req_dn.bv_val )
397 ch_free( op.o_req_dn.bv_val );
398 if ( op.o_req_ndn.bv_val )
399 ch_free( op.o_req_ndn.bv_val );
401 filter_free( op.ors_filter );
402 if ( op.ors_filterstr.bv_val )
403 ch_free( op.ors_filterstr.bv_val );
404 if ( slap_syncrepl_cn_bv.bv_val )
405 ch_free( slap_syncrepl_cn_bv.bv_val );
407 ch_free( pbase.bv_val );
409 ch_free( nbase.bv_val );
411 ber_dupbv( &syncCookie_req, si->syncCookie );
413 psub = be->be_nsuffix[0];
415 for ( n = 0; si->attrs[ n ] != NULL; n++ ) ;
418 /* Delete Attributes */
420 for ( i = 0; descs[i] != NULL; i++ ) {
421 for ( j = 0; si->attrs[j] != NULL; j++ ) {
422 if ( !strcmp( si->attrs[j], descs[i]->ad_cname.bv_val )) {
423 ch_free( si->attrs[j] );
424 for ( k = j; si->attrs[k] != NULL; k++ ) {
425 si->attrs[k] = si->attrs[k+1];
430 for ( n = 0; si->attrs[ n ] != NULL; n++ );
431 tmp = ( char ** ) ch_realloc( si->attrs, ( n + 4 ) * sizeof( char * ));
434 LDAP_LOG( OPERATION, ERR, "out of memory\n", 0,0,0 );
436 Debug( LDAP_DEBUG_ANY, "out of memory\n", 0,0,0 );
440 tmp = ( char ** ) ch_realloc( si->attrs, 5 * sizeof( char * ));
443 LDAP_LOG( OPERATION, ERR, "out of memory\n", 0,0,0 );
445 Debug( LDAP_DEBUG_ANY, "out of memory\n", 0,0,0 );
448 tmp[ n++ ] = ch_strdup( "*" );
456 for ( i = 0; descs[ i ] != NULL; i++ ) {
457 si->attrs[ n++ ] = ch_strdup ( descs[i]->ad_cname.bv_val );
458 si->attrs[ n ] = NULL;
461 rc = ldap_sync_search( si, ld, NULL, NULL, &msgid );
462 if( rc != LDAP_SUCCESS ) {
463 fprintf( stderr, "syncrepl: ldap_search_ext: %s (%d)\n",
464 ldap_err2string( rc ), rc );
468 if ( abs(si->type) == LDAP_SYNC_REFRESH_AND_PERSIST ){
474 while (( rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ONE, tout_p, &res )) >= 0 ) {
477 if ( slapd_abrupt_shutdown ) {
484 for ( msg = ldap_first_message( ld, res );
486 msg = ldap_next_message( ld, msg ) )
488 syncCookie.bv_len = 0; syncCookie.bv_val = NULL;
489 switch( ldap_msgtype( msg ) ) {
490 case LDAP_RES_SEARCH_ENTRY:
491 entry = syncrepl_message_to_entry( si, ld, &op, msg,
492 &modlist, &syncstate, &syncUUID, &syncCookie );
493 rc_efree = syncrepl_entry( si, ld, &op, entry, modlist,
494 syncstate, &syncUUID, &syncCookie, !syncinfo_arrived );
495 if ( syncCookie.bv_len ) {
496 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie );
499 slap_mods_free( modlist );
506 case LDAP_RES_SEARCH_REFERENCE:
508 LDAP_LOG( OPERATION, ERR,
509 "do_syncrepl : reference received\n", 0, 0, 0 );
511 Debug( LDAP_DEBUG_ANY,
512 "do_syncrepl : reference received\n", 0, 0, 0 );
516 case LDAP_RES_SEARCH_RESULT:
517 ldap_parse_result( ld, msg, &err, NULL, NULL, NULL, &rctrls, 0 );
520 ctrl_ber = ber_alloc_t( LBER_USE_DER );
521 ber_set_option( ctrl_ber, LBER_OPT_BER_MEMCTX, &op.o_tmpmemctx );
522 ber_write( ctrl_ber, rctrlp->ldctl_value.bv_val, rctrlp->ldctl_value.bv_len, 0 );
523 ber_reset( ctrl_ber, 1 );
525 ber_scanf( ctrl_ber, "{" /*"}"*/);
526 if ( ber_peek_tag( ctrl_ber, &len )
527 == LDAP_SYNC_TAG_COOKIE ) {
528 ber_scanf( ctrl_ber, "o", &syncCookie );
531 value_match( &match, slap_schema.si_ad_entryCSN,
532 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
533 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
534 &syncCookie_req, &syncCookie, &text );
535 if (si->type == LDAP_SYNC_REFRESH_AND_PERSIST) {
536 /* FIXME : different error behaviors according to
537 1) err code : LDAP_BUSY ...
538 2) on err policy : stop service, stop sync, retry
540 if ( syncCookie.bv_len && match < 0) {
541 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie );
544 ber_free( ctrl_ber, 1 );
547 /* FIXME : different error behaviors according to
548 1) err code : LDAP_BUSY ...
549 2) on err policy : stop service, stop sync, retry
551 if ( syncCookie.bv_len && match < 0 ) {
552 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie);
554 if ( si->sync_mode == LDAP_SYNC_STATE_MODE && match < 0 ) {
555 syncrepl_del_nonpresent( ld, &op );
558 ber_free( ctrl_ber, 1 );
563 case LDAP_RES_INTERMEDIATE:
564 rc = ldap_parse_intermediate( ld, msg,
565 &retoid, &retdata, NULL, 0 );
566 if ( !rc && !strcmp( retoid, LDAP_SYNC_INFO ) ) {
567 sync_info_arrived = 1;
568 res_ber = ber_init( retdata );
569 ber_scanf( res_ber, "{e" /*"}"*/, &syncstate );
571 if ( ber_peek_tag( res_ber, &len )
572 == LDAP_SYNC_TAG_COOKIE ) {
573 ber_scanf( res_ber, /*"{"*/ "o}", &syncCookie );
575 if ( syncstate == LDAP_SYNC_NEW_COOKIE ) {
577 LDAP_LOG( OPERATION, ERR,
578 "do_syncrepl : cookie required\n", 0, 0, 0 );
580 Debug( LDAP_DEBUG_ANY,
581 "do_syncrepl : cookie required\n", 0, 0, 0 );
586 value_match( &match, slap_schema.si_ad_entryCSN,
587 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
588 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
589 &syncCookie_req, &syncCookie, &text );
591 if ( syncCookie.bv_len && match < 0 ) {
592 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie);
595 if ( syncstate == LDAP_SYNC_STATE_MODE_DONE ) {
597 syncrepl_del_nonpresent( ld, &op );
599 si->sync_mode = LDAP_SYNC_LOG_MODE;
600 } else if ( syncstate == LDAP_SYNC_LOG_MODE_DONE ) {
601 si->sync_mode = LDAP_SYNC_PERSIST_MODE;
602 } else if ( syncstate == LDAP_SYNC_REFRESH_DONE ) {
603 si->sync_mode = LDAP_SYNC_PERSIST_MODE;
604 } else if ( syncstate != LDAP_SYNC_NEW_COOKIE ||
605 syncstate != LDAP_SYNC_LOG_MODE_DONE ) {
607 LDAP_LOG( OPERATION, ERR,
608 "do_syncrepl : unknown sync info\n", 0, 0, 0 );
610 Debug( LDAP_DEBUG_ANY,
611 "do_syncrepl : unknown sync info\n", 0, 0, 0 );
615 ldap_memfree( retoid );
616 ber_bvfree( retdata );
617 ber_free( res_ber, 1 );
621 LDAP_LOG( OPERATION, ERR,"do_syncrepl :"
622 " unknown intermediate "
623 "response\n", 0, 0, 0 );
625 Debug( LDAP_DEBUG_ANY, "do_syncrepl : "
626 "unknown intermediate response (%d)\n",
629 ldap_memfree( retoid );
630 ber_bvfree( retdata );
636 LDAP_LOG( OPERATION, ERR, "do_syncrepl : "
637 "unknown message\n", 0, 0, 0 );
639 Debug( LDAP_DEBUG_ANY, "do_syncrepl : "
640 "unknown message\n", 0, 0, 0 );
645 if ( syncCookie.bv_val )
646 ch_free( syncCookie.bv_val );
647 if ( syncUUID.bv_val )
648 ch_free( syncUUID.bv_val );
657 ldap_get_option( ld, LDAP_OPT_ERROR_NUMBER, &errno );
658 errstr = ldap_err2string( errno );
661 LDAP_LOG( OPERATION, ERR,
662 "do_syncrepl : %s\n", errstr, 0, 0 );
664 Debug( LDAP_DEBUG_ANY,
665 "do_syncrepl : %s\n", errstr, 0, 0 );
670 if ( syncCookie.bv_val )
671 ch_free( syncCookie.bv_val );
672 if ( syncCookie_req.bv_val )
673 ch_free( syncCookie_req.bv_val );
674 if ( syncUUID.bv_val )
675 ch_free( syncUUID.bv_val );
682 ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
683 ldap_pvt_runqueue_stoptask( &syncrepl_rq, rtask );
684 if ( si->type == LDAP_SYNC_REFRESH_ONLY ) {
685 ldap_pvt_runqueue_resched( &syncrepl_rq, rtask );
687 ldap_pvt_runqueue_remove( &syncrepl_rq, rtask );
689 ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
695 syncrepl_message_to_entry(
700 Modifications **modlist,
702 struct berval *syncUUID,
703 struct berval *syncCookie
707 BerElement *ber = NULL;
709 struct berval bv = {0, NULL};
712 Modifications **modtail = modlist;
713 Backend *be = op->o_bd;
716 char txtbuf[SLAP_TEXT_BUFLEN];
717 size_t textlen = sizeof txtbuf;
719 struct berval **bvals = NULL;
721 struct berval bdn = {0, NULL};
723 struct berval empty_bv = { 0, NULL };
729 LDAPControl** rctrls = NULL;
730 BerElement* ctrl_ber;
734 Modifications *ml = NULL;
735 AttributeDescription** descs;
740 if ( ldap_msgtype( msg ) != LDAP_RES_SEARCH_ENTRY ) {
742 LDAP_LOG( OPERATION, ERR,
743 "Message type should be entry (%d)", ldap_msgtype( msg ), 0, 0 );
745 Debug( LDAP_DEBUG_ANY,
746 "Message type should be entry (%d)", ldap_msgtype( msg ), 0, 0 );
751 op->o_tag = LDAP_REQ_ADD;
753 rc = ldap_get_dn_ber( ld, msg, &ber, &bdn );
755 if ( rc != LDAP_SUCCESS ) {
757 LDAP_LOG( OPERATION, ERR,
758 "syncrepl_message_to_entry : dn get failed (%d)", rc, 0, 0 );
760 Debug( LDAP_DEBUG_ANY,
761 "syncrepl_message_to_entry : dn get failed (%d)", rc, 0, 0 );
766 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
767 dnPrettyNormal( NULL, &bdn, &e->e_name, &e->e_nname, NULL );
771 while ( ber_remaining( ber ) ) {
772 tag = ber_scanf( ber, "{mW}", &tmp.sml_type, &tmp.sml_values );
774 if ( tag == LBER_ERROR ) break;
775 if ( tmp.sml_type.bv_val == NULL ) break;
777 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
779 mod->sml_op = LDAP_MOD_REPLACE;
780 mod->sml_next = NULL;
781 mod->sml_desc = NULL;
782 mod->sml_type = tmp.sml_type;
783 mod->sml_bvalues = tmp.sml_bvalues;
784 mod->sml_nvalues = NULL;
787 modtail = &mod->sml_next;
790 if ( ber_scanf( ber, "}") == LBER_ERROR ) {
792 LDAP_LOG( OPERATION, ERR,
793 "syncrepl_message_to_entry: ber_scanf failed\n", 0, 0, 0 );
795 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: ber_scanf failed\n",
802 tmpber = ldap_get_message_ber( msg );
803 ber = ber_dup( tmpber );
805 ber_scanf( ber, "{xx" );
807 rc = ldap_pvt_get_controls( ber, &rctrls );
808 if ( rc != LDAP_SUCCESS ) {
810 LDAP_LOG( OPERATION, ERR,
811 "syncrepl_message_to_entry : control get failed (%d)", rc, 0, 0 );
813 Debug( LDAP_DEBUG_ANY,
814 "syncrepl_message_to_entry : control get failed (%d)", rc, 0, 0 );
821 ctrl_ber = ber_alloc_t( LBER_USE_DER );
822 ber_set_option( ctrl_ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
823 ber_write( ctrl_ber, rctrlp->ldctl_value.bv_val, rctrlp->ldctl_value.bv_len, 0 );
824 ber_reset( ctrl_ber, 1 );
825 ber_scanf( ctrl_ber, "{eo", syncstate, syncUUID );
826 if ( ber_peek_tag( ctrl_ber, &len ) == LDAP_SYNC_TAG_COOKIE ) {
827 ber_scanf( ctrl_ber, "o}", syncCookie );
829 ber_free( ctrl_ber, 1 );
830 ldap_controls_free( rctrls );
833 LDAP_LOG( OPERATION, ERR,"syncrepl_message_to_entry : "
834 " rctrls absent\n", 0, 0, 0 );
836 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry :"
837 " rctrls absent\n", 0, 0, 0 );
841 if ( *syncstate == LDAP_SYNC_PRESENT || *syncstate == LDAP_SYNC_DELETE ) {
845 if ( *modlist == NULL ) {
847 LDAP_LOG( OPERATION, ERR,
848 "syncrepl_message_to_entry: no attributes\n", 0, 0, 0 );
850 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: no attributes\n",
856 while ( ml != NULL ) {
857 AttributeDescription *ad = NULL;
858 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, &text );
860 if( rc != LDAP_SUCCESS ) {
870 rc = slap_mods_check( *modlist, 1, &text, txtbuf, textlen, NULL );
872 if ( rc != LDAP_SUCCESS ) {
874 LDAP_LOG( OPERATION, ERR,
875 "syncrepl_message_to_entry: mods check (%s)\n", text, 0, 0 );
877 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods check (%s)\n",
883 rc = slap_mods2entry( *modlist, &e, 1, 1, &text, txtbuf, textlen);
884 if( rc != LDAP_SUCCESS ) {
886 LDAP_LOG( OPERATION, ERR,
887 "syncrepl_message_to_entry: mods2entry (%s)\n", text, 0, 0 );
889 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods2entry (%s)\n",
902 syncuuid_cmp( const void* v_uuid1, const void* v_uuid2 )
904 const struct berval *uuid1 = v_uuid1;
905 const struct berval *uuid2 = v_uuid2;
906 int rc = uuid1->bv_len - uuid2->bv_len;
908 return ( strcmp( uuid1->bv_val, uuid2->bv_val ) );
917 Modifications* modlist,
919 struct berval* syncUUID,
920 struct berval* syncCookie,
924 Backend *be = op->o_bd;
926 struct berval csn_bv = {0, NULL};
927 struct berval *syncuuid_bv = NULL;
928 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
930 SlapReply rs = {REP_RESULT};
931 int rc = LDAP_SUCCESS;
933 struct berval base_bv = {0, NULL};
941 ( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD )) {
942 syncuuid_bv = ber_dupbv( NULL, syncUUID );
943 avl_insert( &si->presentlist, (caddr_t) syncuuid_bv,
944 syncuuid_cmp, avl_dup_error );
947 if ( syncstate == LDAP_SYNC_PRESENT ) {
955 filterstr = (char *) sl_malloc( strlen("entryUUID=") + syncUUID->bv_len + 1,
957 strcpy( filterstr, "entryUUID=" );
958 strcat( filterstr, syncUUID->bv_val );
961 si->syncUUID_ndn = NULL;
963 filter = str2filter( filterstr );
964 ber_str2bv( filterstr, strlen(filterstr), 1, &op->ors_filterstr );
965 ch_free( filterstr );
966 op->ors_filter = filter;
967 op->ors_scope = LDAP_SCOPE_SUBTREE;
969 /* get syncrepl cookie of shadow replica from subentry */
970 ber_str2bv( si->base, strlen(si->base), 1, &base_bv );
971 dnPrettyNormal( 0, &base_bv, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
972 ch_free( base_bv.bv_val );
974 /* set callback function */
975 op->o_callback = &cb;
976 cb.sc_response = dn_callback;
979 si->syncUUID_ndn = NULL;
981 rc = be->be_search( op, &rs );
983 if ( op->o_req_dn.bv_val )
984 ch_free( op->o_req_dn.bv_val );
985 if ( op->o_req_ndn.bv_val )
986 ch_free( op->o_req_ndn.bv_val );
987 if ( op->ors_filter )
988 filter_free( op->ors_filter );
989 if ( op->ors_filterstr.bv_val )
990 ch_free( op->ors_filterstr.bv_val );
992 cb.sc_response = null_callback;
995 if ( rc == LDAP_SUCCESS && si->syncUUID_ndn && si->sync_mode != LDAP_SYNC_LOG_MODE ) {
996 op->o_req_dn = *si->syncUUID_ndn;
997 op->o_req_ndn = *si->syncUUID_ndn;
998 op->o_tag = LDAP_REQ_DELETE;
999 rc = be->be_delete( op, &rs );
1002 if ( si->syncUUID_ndn ) {
1003 ber_bvfree( si->syncUUID_ndn );
1006 switch ( syncstate ) {
1007 case LDAP_SYNC_ADD :
1008 case LDAP_SYNC_MODIFY :
1010 if ( rc == LDAP_SUCCESS ||
1011 rc == LDAP_REFERRAL ||
1012 rc == LDAP_NO_SUCH_OBJECT ) {
1014 attr_delete( &e->e_attrs, slap_schema.si_ad_entryUUID );
1015 attr_merge_normalize_one( e, slap_schema.si_ad_entryUUID, syncUUID, op->o_tmpmemctx );
1017 op->o_tag = LDAP_REQ_ADD;
1019 op->o_req_dn = e->e_name;
1020 op->o_req_ndn = e->e_nname;
1021 rc = be->be_add( op, &rs );
1023 if ( rc != LDAP_SUCCESS ) {
1024 if ( rc == LDAP_ALREADY_EXISTS ) {
1025 op->o_tag = LDAP_REQ_MODIFY;
1026 op->orm_modlist = modlist;
1027 op->o_req_dn = e->e_name;
1028 op->o_req_ndn = e->e_nname;
1029 rc = be->be_modify( op, &rs );
1031 if ( rc != LDAP_SUCCESS ) {
1033 LDAP_LOG( OPERATION, ERR,
1034 "syncrepl_entry : be_modify failed (%d)\n",
1037 Debug( LDAP_DEBUG_ANY,
1038 "syncrepl_entry : be_modify failed (%d)\n",
1043 } else if ( rc == LDAP_REFERRAL ||
1044 rc == LDAP_NO_SUCH_OBJECT ) {
1045 syncrepl_add_glue( si, ld, op, e,
1047 syncUUID, syncCookie);
1052 LDAP_LOG( OPERATION, ERR,
1053 "syncrepl_entry : be_add failed (%d)\n",
1056 Debug( LDAP_DEBUG_ANY,
1057 "syncrepl_entry : be_add failed (%d)\n",
1065 be_entry_release_w( op, e );
1070 LDAP_LOG( OPERATION, ERR,
1071 "syncrepl_entry : be_search failed (%d)\n", rc, 0, 0 );
1073 Debug( LDAP_DEBUG_ANY,
1074 "syncrepl_entry : be_search failed (%d)\n", rc, 0, 0 );
1080 case LDAP_SYNC_DELETE :
1081 if ( si->sync_mode == LDAP_SYNC_LOG_MODE ) {
1082 op->o_req_dn = *si->syncUUID_ndn;
1083 op->o_req_ndn = *si->syncUUID_ndn;
1084 op->o_tag = LDAP_REQ_DELETE;
1085 rc = be->be_delete( op, &rs );
1087 /* Already deleted otherwise */
1092 LDAP_LOG( OPERATION, ERR,
1093 "syncrepl_entry : unknown syncstate\n", 0, 0, 0 );
1095 Debug( LDAP_DEBUG_ANY,
1096 "syncrepl_entry : unknown syncstate\n", 0, 0, 0 );
1103 syncrepl_del_nonpresent(
1108 Backend* be = op->o_bd;
1109 syncinfo_t *si = op->o_si;
1111 struct berval base_bv = {0, NULL};
1113 SlapReply rs = {REP_RESULT};
1114 struct berval filterstr_bv = {0, NULL};
1115 struct nonpresent_entry *np_list, *np_prev;
1117 ber_str2bv( si->base, strlen(si->base), 1, &base_bv );
1118 dnPrettyNormal(0, &base_bv, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
1119 ch_free( base_bv.bv_val );
1121 filter = str2filter( si->filterstr );
1123 cb.sc_response = nonpresent_callback;
1126 op->o_callback = &cb;
1127 op->o_tag = LDAP_REQ_SEARCH;
1128 op->ors_scope = si->scope;
1129 op->ors_deref = LDAP_DEREF_NEVER;
1132 op->ors_attrsonly = 0;
1133 op->ors_attrs = NULL;
1134 op->ors_filter = filter;
1135 ber_str2bv( si->filterstr, strlen( si->filterstr ), 1, &op->ors_filterstr );
1137 op->o_nocaching = 1;
1138 be->be_search( op, &rs );
1139 op->o_nocaching = 0;
1141 if ( op->o_req_dn.bv_val )
1142 ch_free( op->o_req_dn.bv_val );
1143 if ( op->o_req_ndn.bv_val )
1144 ch_free( op->o_req_ndn.bv_val );
1145 if ( op->ors_filter )
1146 filter_free( op->ors_filter );
1147 if ( op->ors_filterstr.bv_val )
1148 ch_free( op->ors_filterstr.bv_val );
1150 if ( !LDAP_LIST_EMPTY( &si->nonpresentlist ) ) {
1151 np_list = LDAP_LIST_FIRST( &si->nonpresentlist );
1152 while ( np_list != NULL ) {
1153 LDAP_LIST_REMOVE( np_list, np_link );
1155 np_list = LDAP_LIST_NEXT( np_list, np_link );
1156 op->o_tag = LDAP_REQ_DELETE;
1157 op->o_callback = &cb;
1158 cb.sc_response = null_callback;
1160 op->o_req_dn = *np_prev->dn;
1161 op->o_req_ndn = *np_prev->ndn;
1162 op->o_bd->be_delete( op, &rs );
1163 ber_bvfree( np_prev->dn );
1164 ber_bvfree( np_prev->ndn );
1165 op->o_req_dn.bv_val = NULL;
1166 op->o_req_ndn.bv_val = NULL;
1181 Modifications* modlist,
1183 struct berval* syncUUID,
1184 struct berval* syncCookie
1187 Backend *be = op->o_bd;
1188 struct berval uuid_bv = {0, NULL};
1192 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
1195 struct berval dn = {0, NULL};
1196 struct berval pdn = {0, NULL};
1197 struct berval ndn = {0, NULL};
1198 struct berval rdn = {0, NULL};
1200 SlapReply rs = {REP_RESULT};
1201 Connection *conn = op->o_conn;
1204 op->o_tag = LDAP_REQ_ADD;
1205 op->o_callback = &cb;
1206 cb.sc_response = null_callback;
1209 ber_dupbv( &dn, &e->e_nname );
1210 ber_dupbv( &pdn, &e->e_nname );
1213 while ( !be_issuffix ( be, &pdn )) {
1214 dnParent( &dn, &pdn );
1215 dn.bv_val = pdn.bv_val;
1216 dn.bv_len = pdn.bv_len;
1221 for ( i = 0; i <= levels; i++ ) {
1222 glue = (Entry*) ch_calloc( 1, sizeof(Entry) );
1223 ber_dupbv( &dn, &e->e_nname );
1227 for ( k = 0; k < j; k++ ) {
1228 dnParent( &dn, &pdn );
1229 dn.bv_val = pdn.bv_val;
1230 dn.bv_len = pdn.bv_len;
1233 dnPrettyNormal( 0, &dn, &pdn, &ndn, op->o_tmpmemctx );
1234 ber_dupbv( &glue->e_name, &pdn );
1235 ber_dupbv( &glue->e_nname, &ndn );
1237 ch_free( pdn.bv_val );
1238 ch_free( ndn.bv_val );
1240 a = ch_calloc( 1, sizeof( Attribute ));
1241 a->a_desc = slap_schema.si_ad_objectClass;
1243 a->a_vals = ch_calloc( 3, sizeof( struct berval ));
1244 ber_str2bv( "top", strlen("top"), 1, &a->a_vals[0] );
1245 ber_str2bv( "glue", strlen("glue"), 1, &a->a_vals[1] );
1246 a->a_vals[2].bv_len = 0;
1247 a->a_vals[2].bv_val = NULL;
1249 a->a_nvals = ch_calloc( 3, sizeof( struct berval ));
1250 ber_str2bv( "top", strlen("top"), 1, &a->a_nvals[0] );
1251 ber_str2bv( "glue", strlen("glue"), 1, &a->a_nvals[1] );
1252 a->a_nvals[2].bv_len = 0;
1253 a->a_nvals[2].bv_val = NULL;
1255 a->a_next = glue->e_attrs;
1258 a = ch_calloc( 1, sizeof( Attribute ));
1259 a->a_desc = slap_schema.si_ad_structuralObjectClass;
1261 a->a_vals = ch_calloc( 2, sizeof( struct berval ));
1262 ber_str2bv( "glue", strlen("glue"), 1, &a->a_vals[0] );
1263 a->a_vals[1].bv_len = 0;
1264 a->a_vals[1].bv_val = NULL;
1266 a->a_nvals = ch_calloc( 2, sizeof( struct berval ));
1267 ber_str2bv( "glue", strlen("glue"), 1, &a->a_nvals[0] );
1268 a->a_nvals[1].bv_len = 0;
1269 a->a_nvals[1].bv_val = NULL;
1271 a->a_next = glue->e_attrs;
1274 if ( !strcmp( e->e_nname.bv_val, glue->e_nname.bv_val )) {
1275 op->o_req_dn = e->e_name;
1276 op->o_req_ndn = e->e_nname;
1278 rc = be->be_add ( op, &rs );
1279 if ( rc == LDAP_SUCCESS )
1280 be_entry_release_w( op, e );
1285 op->o_req_dn = glue->e_name;
1286 op->o_req_ndn = glue->e_nname;
1288 rc = be->be_add ( op, &rs );
1289 if ( rc == LDAP_SUCCESS ) {
1290 be_entry_release_w( op, glue );
1292 /* incl. ALREADY EXIST */
1301 static struct berval ocbva[] = {
1303 BER_BVC("subentry"),
1304 BER_BVC("syncConsumerSubentry"),
1308 static struct berval cnbva[] = {
1313 static struct berval ssbva[] = {
1318 static struct berval scbva[] = {
1319 BER_BVC("subentry"),
1324 syncrepl_updateCookie(
1329 struct berval *syncCookie
1332 Backend *be = op->o_bd;
1334 Modifications *mlnext;
1336 Modifications *modlist = NULL;
1337 Modifications **modtail = &modlist;
1340 char txtbuf[SLAP_TEXT_BUFLEN];
1341 size_t textlen = sizeof txtbuf;
1346 struct berval slap_syncrepl_dn_bv = BER_BVNULL;
1347 struct berval slap_syncrepl_cn_bv = BER_BVNULL;
1350 SlapReply rs = {REP_RESULT};
1352 /* update in memory cookie */
1353 if ( si->syncCookie != NULL ) {
1354 ber_bvfree( si->syncCookie );
1356 si->syncCookie = ber_dupbv( NULL, syncCookie );
1357 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1358 mod->sml_op = LDAP_MOD_REPLACE;
1359 mod->sml_desc = slap_schema.si_ad_objectClass;
1360 mod->sml_type = mod->sml_desc->ad_cname;
1361 mod->sml_bvalues = ocbva;
1363 modtail = &mod->sml_next;
1365 ber_dupbv( &cnbva[0], (struct berval *) &slap_syncrepl_bvc );
1366 cnbva[0].bv_len = snprintf( cnbva[0].bv_val,
1367 slap_syncrepl_bvc.bv_len,
1368 "syncrepl%d", si->id );
1369 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1370 mod->sml_op = LDAP_MOD_REPLACE;
1371 mod->sml_desc = slap_schema.si_ad_cn;
1372 mod->sml_type = mod->sml_desc->ad_cname;
1373 mod->sml_bvalues = cnbva;
1375 modtail = &mod->sml_next;
1377 ber_dupbv( &scbva[0], si->syncCookie );
1378 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1379 mod->sml_op = LDAP_MOD_REPLACE;
1380 mod->sml_desc = slap_schema.si_ad_syncreplCookie;
1381 mod->sml_type = mod->sml_desc->ad_cname;
1382 mod->sml_bvalues = scbva;
1384 modtail = &mod->sml_next;
1386 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1387 mod->sml_op = LDAP_MOD_REPLACE;
1388 mod->sml_desc = slap_schema.si_ad_subtreeSpecification;
1389 mod->sml_type = mod->sml_desc->ad_cname;
1390 mod->sml_bvalues = ssbva;
1392 modtail = &mod->sml_next;
1395 rc = slap_mods_check( modlist, 1, &text, txtbuf, textlen, NULL );
1397 if ( rc != LDAP_SUCCESS ) {
1399 LDAP_LOG( OPERATION, ERR,
1400 "syncrepl_updateCookie: mods check (%s)\n", text, 0, 0 );
1402 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods check (%s)\n",
1408 op->o_tag = LDAP_REQ_ADD;
1409 rc = slap_mods_opattrs( op, modlist, modtail,
1410 &text,txtbuf, textlen );
1412 for ( ml = modlist; ml != NULL; ml = mlnext ) {
1413 mlnext = ml->sml_next;
1414 ml->sml_op = LDAP_MOD_REPLACE;
1417 if( rc != LDAP_SUCCESS ) {
1419 LDAP_LOG( OPERATION, ERR,
1420 "syncrepl_updateCookie: mods opattrs (%s)\n", text, 0, 0 );
1422 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods opattrs (%s)\n",
1427 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
1429 ber_dupbv( &slap_syncrepl_cn_bv, (struct berval *) &slap_syncrepl_cn_bvc );
1430 slap_syncrepl_cn_bv.bv_len = snprintf( slap_syncrepl_cn_bv.bv_val,
1431 slap_syncrepl_cn_bvc.bv_len,
1432 "cn=syncrepl%d", si->id );
1434 build_new_dn( &slap_syncrepl_dn_bv, pdn, &slap_syncrepl_cn_bv, NULL );
1435 dnPrettyNormal( NULL, &slap_syncrepl_dn_bv, &e->e_name, &e->e_nname, NULL );
1437 if ( slap_syncrepl_cn_bv.bv_val )
1438 ch_free( slap_syncrepl_cn_bv.bv_val );
1439 if ( slap_syncrepl_dn_bv.bv_val )
1440 ch_free( slap_syncrepl_dn_bv.bv_val );
1444 rc = slap_mods2entry( modlist, &e, 1, 1, &text, txtbuf, textlen );
1446 if( rc != LDAP_SUCCESS ) {
1448 LDAP_LOG( OPERATION, ERR,
1449 "syncrepl_updateCookie: mods2entry (%s)\n", text, 0, 0 );
1451 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods2entry (%s)\n",
1456 cb.sc_response = null_callback;
1459 op->o_callback = &cb;
1460 op->o_req_dn = e->e_name;
1461 op->o_req_ndn = e->e_nname;
1463 /* update persistent cookie */
1464 update_cookie_retry:
1465 op->o_tag = LDAP_REQ_MODIFY;
1466 op->orm_modlist = modlist;
1467 rc = be->be_modify( op, &rs );
1469 if ( rc != LDAP_SUCCESS ) {
1470 if ( rc == LDAP_REFERRAL ||
1471 rc == LDAP_NO_SUCH_OBJECT ) {
1472 op->o_tag = LDAP_REQ_ADD;
1474 rc = be->be_add( op, &rs );
1475 if ( rc != LDAP_SUCCESS ) {
1476 if ( rc == LDAP_ALREADY_EXISTS ) {
1477 goto update_cookie_retry;
1478 } else if ( rc == LDAP_REFERRAL ||
1479 rc == LDAP_NO_SUCH_OBJECT ) {
1481 LDAP_LOG( OPERATION, ERR,
1482 "cookie will be non-persistent\n",
1485 Debug( LDAP_DEBUG_ANY,
1486 "cookie will be non-persistent\n",
1491 LDAP_LOG( OPERATION, ERR,
1492 "be_add failed (%d)\n",
1495 Debug( LDAP_DEBUG_ANY,
1496 "be_add failed (%d)\n",
1501 be_entry_release_w( op, e );
1506 LDAP_LOG( OPERATION, ERR,
1507 "be_modify failed (%d)\n", rc, 0, 0 );
1509 Debug( LDAP_DEBUG_ANY,
1510 "be_modify failed (%d)\n", rc, 0, 0 );
1521 if ( cnbva[0].bv_val )
1522 ch_free( cnbva[0].bv_val );
1524 for ( ; ml != NULL; ml = mlnext ) {
1525 mlnext = ml->sml_next;
1533 avl_ber_bvfree( void *bv )
1538 if ( ((struct berval *)bv)->bv_val != NULL ) {
1539 ch_free ( ((struct berval *)bv)->bv_val );
1541 ch_free ( (char *) bv );
1550 syncinfo_t *si = op->o_callback->sc_private;
1553 if ( rs->sr_type != REP_SEARCH ) return LDAP_SUCCESS;
1555 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_syncreplCookie );
1558 si->syncCookie = NULL;
1560 si->syncCookie = ber_dupbv( NULL, &a->a_vals[0] );
1562 return LDAP_SUCCESS;
1571 syncinfo_t *si = op->o_callback->sc_private;
1573 if ( rs->sr_type == REP_SEARCH ) {
1574 if ( si->syncUUID_ndn != NULL ) {
1576 LDAP_LOG( OPERATION, ERR,
1577 "dn_callback : multiple entries match dn\n", 0, 0, 0 );
1579 Debug( LDAP_DEBUG_ANY,
1580 "dn_callback : multiple entries match dn\n", 0, 0, 0 );
1583 if ( rs->sr_entry == NULL ) {
1584 si->syncUUID_ndn = NULL;
1586 si->syncUUID_ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname );
1591 return LDAP_SUCCESS;
1595 nonpresent_callback(
1600 syncinfo_t *si = op->o_callback->sc_private;
1603 struct berval* present_uuid = NULL;
1605 SlapReply rs_cb = {REP_RESULT};
1606 struct nonpresent_entry *np_entry;
1608 if ( rs->sr_type == REP_RESULT ) {
1609 count = avl_free( si->presentlist, avl_ber_bvfree );
1610 si->presentlist = NULL;
1611 return LDAP_SUCCESS;
1612 } else if ( rs->sr_type == REP_SEARCH ) {
1613 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID );
1618 present_uuid = avl_find( si->presentlist, &a->a_vals[0], syncuuid_cmp );
1620 if ( present_uuid == NULL ) {
1621 np_entry = (struct nonpresent_entry *)
1622 ch_calloc( 1, sizeof( struct nonpresent_entry ));
1623 np_entry->dn = ber_dupbv( NULL, &rs->sr_entry->e_name );
1624 np_entry->ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname );
1625 LDAP_LIST_INSERT_HEAD( &si->nonpresentlist, np_entry, np_link );
1627 avl_delete( &si->presentlist,
1628 &a->a_vals[0], syncuuid_cmp );
1629 ch_free( present_uuid->bv_val );
1630 ch_free( present_uuid );
1632 return LDAP_SUCCESS;
1634 return LDAP_SUCCESS;
1645 syncinfo_t *si = op->o_callback->sc_private;
1647 if ( rs->sr_err != LDAP_SUCCESS &&
1648 rs->sr_err != LDAP_REFERRAL &&
1649 rs->sr_err != LDAP_ALREADY_EXISTS &&
1650 rs->sr_err != LDAP_NO_SUCH_OBJECT ) {
1652 LDAP_LOG( OPERATION, ERR,
1653 "null_callback : error code 0x%x\n",
1656 Debug( LDAP_DEBUG_ANY,
1657 "null_callback : error code 0x%x\n",
1661 return LDAP_SUCCESS;
1665 slap_create_syncrepl_entry(
1667 struct berval *context_csn,
1677 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
1679 attr_merge( e, slap_schema.si_ad_objectClass, ocbva, NULL );
1681 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &ocbva[1], NULL );
1683 attr_merge_one( e, slap_schema.si_ad_cn, cn, NULL );
1685 if ( context_csn ) {
1686 attr_merge_one( e, slap_schema.si_ad_syncreplCookie,
1687 context_csn, NULL );
1691 bv.bv_len = sizeof("{}")-1;
1692 attr_merge_one( e, slap_schema.si_ad_subtreeSpecification, &bv, NULL );
1694 build_new_dn( &e->e_name, &be->be_nsuffix[0], rdn, NULL );
1695 ber_dupbv( &e->e_nname, &e->e_name );