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_int_get_controls( ber, &rctrls );
810 if ( rc != LDAP_SUCCESS ) {
812 LDAP_LOG( OPERATION, ERR,
813 "syncrepl_message_to_entry : control get failed (%d)", rc, 0, 0 );
815 Debug( LDAP_DEBUG_ANY,
816 "syncrepl_message_to_entry : control get failed (%d)", rc, 0, 0 );
823 ctrl_ber = ber_alloc_t( LBER_USE_DER );
824 ber_set_option( ctrl_ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
825 ber_write( ctrl_ber, rctrlp->ldctl_value.bv_val, rctrlp->ldctl_value.bv_len, 0 );
826 ber_reset( ctrl_ber, 1 );
827 ber_scanf( ctrl_ber, "{eo", syncstate, syncUUID );
828 if ( ber_peek_tag( ctrl_ber, &len ) == LDAP_SYNC_TAG_COOKIE ) {
829 ber_scanf( ctrl_ber, "o}", syncCookie );
831 ber_free( ctrl_ber, 1 );
832 ldap_controls_free( rctrls );
835 LDAP_LOG( OPERATION, ERR,"syncrepl_message_to_entry : "
836 " rctrls absent\n", 0, 0, 0 );
838 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry :"
839 " rctrls absent\n", 0, 0, 0 );
843 if ( *syncstate == LDAP_SYNC_PRESENT || *syncstate == LDAP_SYNC_DELETE ) {
847 if ( *modlist == NULL ) {
849 LDAP_LOG( OPERATION, ERR,
850 "syncrepl_message_to_entry: no attributes\n", 0, 0, 0 );
852 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: no attributes\n",
858 while ( ml != NULL ) {
859 AttributeDescription *ad = NULL;
860 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, &text );
862 if( rc != LDAP_SUCCESS ) {
872 rc = slap_mods_check( *modlist, 1, &text, txtbuf, textlen, NULL );
874 if ( rc != LDAP_SUCCESS ) {
876 LDAP_LOG( OPERATION, ERR,
877 "syncrepl_message_to_entry: mods check (%s)\n", text, 0, 0 );
879 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods check (%s)\n",
885 rc = slap_mods2entry( *modlist, &e, 1, 1, &text, txtbuf, textlen);
886 if( rc != LDAP_SUCCESS ) {
888 LDAP_LOG( OPERATION, ERR,
889 "syncrepl_message_to_entry: mods2entry (%s)\n", text, 0, 0 );
891 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods2entry (%s)\n",
904 syncuuid_cmp( const void* v_uuid1, const void* v_uuid2 )
906 const struct berval *uuid1 = v_uuid1;
907 const struct berval *uuid2 = v_uuid2;
908 int rc = uuid1->bv_len - uuid2->bv_len;
910 return ( strcmp( uuid1->bv_val, uuid2->bv_val ) );
919 Modifications* modlist,
921 struct berval* syncUUID,
922 struct berval* syncCookie,
926 Backend *be = op->o_bd;
928 struct berval csn_bv = {0, NULL};
929 struct berval *syncuuid_bv = NULL;
930 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
932 SlapReply rs = {REP_RESULT};
933 int rc = LDAP_SUCCESS;
935 struct berval base_bv = {0, NULL};
943 ( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD )) {
944 syncuuid_bv = ber_dupbv( NULL, syncUUID );
945 avl_insert( &si->presentlist, (caddr_t) syncuuid_bv,
946 syncuuid_cmp, avl_dup_error );
949 if ( syncstate == LDAP_SYNC_PRESENT ) {
957 filterstr = (char *) sl_malloc( strlen("entryUUID=") + syncUUID->bv_len + 1,
959 strcpy( filterstr, "entryUUID=" );
960 strcat( filterstr, syncUUID->bv_val );
963 si->syncUUID_ndn = NULL;
965 filter = str2filter( filterstr );
966 ber_str2bv( filterstr, strlen(filterstr), 1, &op->ors_filterstr );
967 ch_free( filterstr );
968 op->ors_filter = filter;
969 op->ors_scope = LDAP_SCOPE_SUBTREE;
971 /* get syncrepl cookie of shadow replica from subentry */
972 ber_str2bv( si->base, strlen(si->base), 1, &base_bv );
973 dnPrettyNormal( 0, &base_bv, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
974 ch_free( base_bv.bv_val );
976 /* set callback function */
977 op->o_callback = &cb;
978 cb.sc_response = dn_callback;
981 si->syncUUID_ndn = NULL;
983 rc = be->be_search( op, &rs );
985 if ( op->o_req_dn.bv_val )
986 ch_free( op->o_req_dn.bv_val );
987 if ( op->o_req_ndn.bv_val )
988 ch_free( op->o_req_ndn.bv_val );
989 if ( op->ors_filter )
990 filter_free( op->ors_filter );
991 if ( op->ors_filterstr.bv_val )
992 ch_free( op->ors_filterstr.bv_val );
994 cb.sc_response = null_callback;
997 if ( rc == LDAP_SUCCESS && si->syncUUID_ndn && si->sync_mode != LDAP_SYNC_LOG_MODE ) {
998 op->o_req_dn = *si->syncUUID_ndn;
999 op->o_req_ndn = *si->syncUUID_ndn;
1000 op->o_tag = LDAP_REQ_DELETE;
1001 rc = be->be_delete( op, &rs );
1004 if ( si->syncUUID_ndn ) {
1005 ber_bvfree( si->syncUUID_ndn );
1008 switch ( syncstate ) {
1009 case LDAP_SYNC_ADD :
1010 case LDAP_SYNC_MODIFY :
1012 if ( rc == LDAP_SUCCESS ||
1013 rc == LDAP_REFERRAL ||
1014 rc == LDAP_NO_SUCH_OBJECT ) {
1016 attr_delete( &e->e_attrs, slap_schema.si_ad_entryUUID );
1017 attr_merge_normalize_one( e, slap_schema.si_ad_entryUUID, syncUUID, op->o_tmpmemctx );
1019 op->o_tag = LDAP_REQ_ADD;
1021 op->o_req_dn = e->e_name;
1022 op->o_req_ndn = e->e_nname;
1023 rc = be->be_add( op, &rs );
1025 if ( rc != LDAP_SUCCESS ) {
1026 if ( rc == LDAP_ALREADY_EXISTS ) {
1027 op->o_tag = LDAP_REQ_MODIFY;
1028 op->orm_modlist = modlist;
1029 op->o_req_dn = e->e_name;
1030 op->o_req_ndn = e->e_nname;
1031 rc = be->be_modify( op, &rs );
1033 if ( rc != LDAP_SUCCESS ) {
1035 LDAP_LOG( OPERATION, ERR,
1036 "syncrepl_entry : be_modify failed (%d)\n",
1039 Debug( LDAP_DEBUG_ANY,
1040 "syncrepl_entry : be_modify failed (%d)\n",
1045 } else if ( rc == LDAP_REFERRAL ||
1046 rc == LDAP_NO_SUCH_OBJECT ) {
1047 syncrepl_add_glue( si, ld, op, e,
1049 syncUUID, syncCookie);
1054 LDAP_LOG( OPERATION, ERR,
1055 "syncrepl_entry : be_add failed (%d)\n",
1058 Debug( LDAP_DEBUG_ANY,
1059 "syncrepl_entry : be_add failed (%d)\n",
1067 be_entry_release_w( op, e );
1072 LDAP_LOG( OPERATION, ERR,
1073 "syncrepl_entry : be_search failed (%d)\n", rc, 0, 0 );
1075 Debug( LDAP_DEBUG_ANY,
1076 "syncrepl_entry : be_search failed (%d)\n", rc, 0, 0 );
1082 case LDAP_SYNC_DELETE :
1083 if ( si->sync_mode == LDAP_SYNC_LOG_MODE ) {
1084 op->o_req_dn = *si->syncUUID_ndn;
1085 op->o_req_ndn = *si->syncUUID_ndn;
1086 op->o_tag = LDAP_REQ_DELETE;
1087 rc = be->be_delete( op, &rs );
1089 /* Already deleted otherwise */
1094 LDAP_LOG( OPERATION, ERR,
1095 "syncrepl_entry : unknown syncstate\n", 0, 0, 0 );
1097 Debug( LDAP_DEBUG_ANY,
1098 "syncrepl_entry : unknown syncstate\n", 0, 0, 0 );
1105 syncrepl_del_nonpresent(
1110 Backend* be = op->o_bd;
1111 syncinfo_t *si = op->o_si;
1113 struct berval base_bv = {0, NULL};
1115 SlapReply rs = {REP_RESULT};
1116 struct berval filterstr_bv = {0, NULL};
1117 struct nonpresent_entry *np_list, *np_prev;
1119 ber_str2bv( si->base, strlen(si->base), 1, &base_bv );
1120 dnPrettyNormal(0, &base_bv, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
1121 ch_free( base_bv.bv_val );
1123 filter = str2filter( si->filterstr );
1125 cb.sc_response = nonpresent_callback;
1128 op->o_callback = &cb;
1129 op->o_tag = LDAP_REQ_SEARCH;
1130 op->ors_scope = si->scope;
1131 op->ors_deref = LDAP_DEREF_NEVER;
1134 op->ors_attrsonly = 0;
1135 op->ors_attrs = NULL;
1136 op->ors_filter = filter;
1137 ber_str2bv( si->filterstr, strlen( si->filterstr ), 1, &op->ors_filterstr );
1139 op->o_nocaching = 1;
1140 be->be_search( op, &rs );
1141 op->o_nocaching = 0;
1143 if ( op->o_req_dn.bv_val )
1144 ch_free( op->o_req_dn.bv_val );
1145 if ( op->o_req_ndn.bv_val )
1146 ch_free( op->o_req_ndn.bv_val );
1147 if ( op->ors_filter )
1148 filter_free( op->ors_filter );
1149 if ( op->ors_filterstr.bv_val )
1150 ch_free( op->ors_filterstr.bv_val );
1152 if ( !LDAP_LIST_EMPTY( &si->nonpresentlist ) ) {
1153 np_list = LDAP_LIST_FIRST( &si->nonpresentlist );
1154 while ( np_list != NULL ) {
1155 LDAP_LIST_REMOVE( np_list, np_link );
1157 np_list = LDAP_LIST_NEXT( np_list, np_link );
1158 op->o_tag = LDAP_REQ_DELETE;
1159 op->o_callback = &cb;
1160 cb.sc_response = null_callback;
1162 op->o_req_dn = *np_prev->dn;
1163 op->o_req_ndn = *np_prev->ndn;
1164 op->o_bd->be_delete( op, &rs );
1165 ber_bvfree( np_prev->dn );
1166 ber_bvfree( np_prev->ndn );
1167 op->o_req_dn.bv_val = NULL;
1168 op->o_req_ndn.bv_val = NULL;
1183 Modifications* modlist,
1185 struct berval* syncUUID,
1186 struct berval* syncCookie
1189 Backend *be = op->o_bd;
1190 struct berval uuid_bv = {0, NULL};
1194 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
1197 struct berval dn = {0, NULL};
1198 struct berval pdn = {0, NULL};
1199 struct berval ndn = {0, NULL};
1200 struct berval rdn = {0, NULL};
1202 SlapReply rs = {REP_RESULT};
1203 Connection *conn = op->o_conn;
1206 op->o_tag = LDAP_REQ_ADD;
1207 op->o_callback = &cb;
1208 cb.sc_response = null_callback;
1211 ber_dupbv( &dn, &e->e_nname );
1212 ber_dupbv( &pdn, &e->e_nname );
1215 while ( !be_issuffix ( be, &pdn )) {
1216 dnParent( &dn, &pdn );
1217 dn.bv_val = pdn.bv_val;
1218 dn.bv_len = pdn.bv_len;
1223 for ( i = 0; i <= levels; i++ ) {
1224 glue = (Entry*) ch_calloc( 1, sizeof(Entry) );
1225 ber_dupbv( &dn, &e->e_nname );
1229 for ( k = 0; k < j; k++ ) {
1230 dnParent( &dn, &pdn );
1231 dn.bv_val = pdn.bv_val;
1232 dn.bv_len = pdn.bv_len;
1235 dnPrettyNormal( 0, &dn, &pdn, &ndn, op->o_tmpmemctx );
1236 ber_dupbv( &glue->e_name, &pdn );
1237 ber_dupbv( &glue->e_nname, &ndn );
1239 ch_free( pdn.bv_val );
1240 ch_free( ndn.bv_val );
1242 a = ch_calloc( 1, sizeof( Attribute ));
1243 a->a_desc = slap_schema.si_ad_objectClass;
1245 a->a_vals = ch_calloc( 3, sizeof( struct berval ));
1246 ber_str2bv( "top", strlen("top"), 1, &a->a_vals[0] );
1247 ber_str2bv( "glue", strlen("glue"), 1, &a->a_vals[1] );
1248 a->a_vals[2].bv_len = 0;
1249 a->a_vals[2].bv_val = NULL;
1251 a->a_nvals = ch_calloc( 3, sizeof( struct berval ));
1252 ber_str2bv( "top", strlen("top"), 1, &a->a_nvals[0] );
1253 ber_str2bv( "glue", strlen("glue"), 1, &a->a_nvals[1] );
1254 a->a_nvals[2].bv_len = 0;
1255 a->a_nvals[2].bv_val = NULL;
1257 a->a_next = glue->e_attrs;
1260 a = ch_calloc( 1, sizeof( Attribute ));
1261 a->a_desc = slap_schema.si_ad_structuralObjectClass;
1263 a->a_vals = ch_calloc( 2, sizeof( struct berval ));
1264 ber_str2bv( "glue", strlen("glue"), 1, &a->a_vals[0] );
1265 a->a_vals[1].bv_len = 0;
1266 a->a_vals[1].bv_val = NULL;
1268 a->a_nvals = ch_calloc( 2, sizeof( struct berval ));
1269 ber_str2bv( "glue", strlen("glue"), 1, &a->a_nvals[0] );
1270 a->a_nvals[1].bv_len = 0;
1271 a->a_nvals[1].bv_val = NULL;
1273 a->a_next = glue->e_attrs;
1276 if ( !strcmp( e->e_nname.bv_val, glue->e_nname.bv_val )) {
1277 op->o_req_dn = e->e_name;
1278 op->o_req_ndn = e->e_nname;
1280 rc = be->be_add ( op, &rs );
1281 if ( rc == LDAP_SUCCESS )
1282 be_entry_release_w( op, e );
1287 op->o_req_dn = glue->e_name;
1288 op->o_req_ndn = glue->e_nname;
1290 rc = be->be_add ( op, &rs );
1291 if ( rc == LDAP_SUCCESS ) {
1292 be_entry_release_w( op, glue );
1294 /* incl. ALREADY EXIST */
1303 static struct berval ocbva[] = {
1305 BER_BVC("subentry"),
1306 BER_BVC("syncConsumerSubentry"),
1310 static struct berval cnbva[] = {
1315 static struct berval ssbva[] = {
1320 static struct berval scbva[] = {
1321 BER_BVC("subentry"),
1326 syncrepl_updateCookie(
1331 struct berval *syncCookie
1334 Backend *be = op->o_bd;
1336 Modifications *mlnext;
1338 Modifications *modlist = NULL;
1339 Modifications **modtail = &modlist;
1342 char txtbuf[SLAP_TEXT_BUFLEN];
1343 size_t textlen = sizeof txtbuf;
1348 struct berval slap_syncrepl_dn_bv = BER_BVNULL;
1349 struct berval slap_syncrepl_cn_bv = BER_BVNULL;
1352 SlapReply rs = {REP_RESULT};
1354 /* update in memory cookie */
1355 if ( si->syncCookie != NULL ) {
1356 ber_bvfree( si->syncCookie );
1358 si->syncCookie = ber_dupbv( NULL, syncCookie );
1359 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1360 mod->sml_op = LDAP_MOD_REPLACE;
1361 mod->sml_desc = slap_schema.si_ad_objectClass;
1362 mod->sml_type = mod->sml_desc->ad_cname;
1363 mod->sml_bvalues = ocbva;
1365 modtail = &mod->sml_next;
1367 ber_dupbv( &cnbva[0], (struct berval *) &slap_syncrepl_bvc );
1368 cnbva[0].bv_len = snprintf( cnbva[0].bv_val,
1369 slap_syncrepl_bvc.bv_len,
1370 "syncrepl%d", si->id );
1371 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1372 mod->sml_op = LDAP_MOD_REPLACE;
1373 mod->sml_desc = slap_schema.si_ad_cn;
1374 mod->sml_type = mod->sml_desc->ad_cname;
1375 mod->sml_bvalues = cnbva;
1377 modtail = &mod->sml_next;
1379 ber_dupbv( &scbva[0], si->syncCookie );
1380 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1381 mod->sml_op = LDAP_MOD_REPLACE;
1382 mod->sml_desc = slap_schema.si_ad_syncreplCookie;
1383 mod->sml_type = mod->sml_desc->ad_cname;
1384 mod->sml_bvalues = scbva;
1386 modtail = &mod->sml_next;
1388 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1389 mod->sml_op = LDAP_MOD_REPLACE;
1390 mod->sml_desc = slap_schema.si_ad_subtreeSpecification;
1391 mod->sml_type = mod->sml_desc->ad_cname;
1392 mod->sml_bvalues = ssbva;
1394 modtail = &mod->sml_next;
1397 rc = slap_mods_check( modlist, 1, &text, txtbuf, textlen, NULL );
1399 if ( rc != LDAP_SUCCESS ) {
1401 LDAP_LOG( OPERATION, ERR,
1402 "syncrepl_updateCookie: mods check (%s)\n", text, 0, 0 );
1404 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods check (%s)\n",
1410 op->o_tag = LDAP_REQ_ADD;
1411 rc = slap_mods_opattrs( op, modlist, modtail,
1412 &text,txtbuf, textlen );
1414 for ( ml = modlist; ml != NULL; ml = mlnext ) {
1415 mlnext = ml->sml_next;
1416 ml->sml_op = LDAP_MOD_REPLACE;
1419 if( rc != LDAP_SUCCESS ) {
1421 LDAP_LOG( OPERATION, ERR,
1422 "syncrepl_updateCookie: mods opattrs (%s)\n", text, 0, 0 );
1424 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods opattrs (%s)\n",
1429 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
1431 ber_dupbv( &slap_syncrepl_cn_bv, (struct berval *) &slap_syncrepl_cn_bvc );
1432 slap_syncrepl_cn_bv.bv_len = snprintf( slap_syncrepl_cn_bv.bv_val,
1433 slap_syncrepl_cn_bvc.bv_len,
1434 "cn=syncrepl%d", si->id );
1436 build_new_dn( &slap_syncrepl_dn_bv, pdn, &slap_syncrepl_cn_bv, NULL );
1437 dnPrettyNormal( NULL, &slap_syncrepl_dn_bv, &e->e_name, &e->e_nname, NULL );
1439 if ( slap_syncrepl_cn_bv.bv_val )
1440 ch_free( slap_syncrepl_cn_bv.bv_val );
1441 if ( slap_syncrepl_dn_bv.bv_val )
1442 ch_free( slap_syncrepl_dn_bv.bv_val );
1446 rc = slap_mods2entry( modlist, &e, 1, 1, &text, txtbuf, textlen );
1448 if( rc != LDAP_SUCCESS ) {
1450 LDAP_LOG( OPERATION, ERR,
1451 "syncrepl_updateCookie: mods2entry (%s)\n", text, 0, 0 );
1453 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods2entry (%s)\n",
1458 cb.sc_response = null_callback;
1461 op->o_callback = &cb;
1462 op->o_req_dn = e->e_name;
1463 op->o_req_ndn = e->e_nname;
1465 /* update persistent cookie */
1466 update_cookie_retry:
1467 op->o_tag = LDAP_REQ_MODIFY;
1468 op->orm_modlist = modlist;
1469 rc = be->be_modify( op, &rs );
1471 if ( rc != LDAP_SUCCESS ) {
1472 if ( rc == LDAP_REFERRAL ||
1473 rc == LDAP_NO_SUCH_OBJECT ) {
1474 op->o_tag = LDAP_REQ_ADD;
1476 rc = be->be_add( op, &rs );
1477 if ( rc != LDAP_SUCCESS ) {
1478 if ( rc == LDAP_ALREADY_EXISTS ) {
1479 goto update_cookie_retry;
1480 } else if ( rc == LDAP_REFERRAL ||
1481 rc == LDAP_NO_SUCH_OBJECT ) {
1483 LDAP_LOG( OPERATION, ERR,
1484 "cookie will be non-persistent\n",
1487 Debug( LDAP_DEBUG_ANY,
1488 "cookie will be non-persistent\n",
1493 LDAP_LOG( OPERATION, ERR,
1494 "be_add failed (%d)\n",
1497 Debug( LDAP_DEBUG_ANY,
1498 "be_add failed (%d)\n",
1503 be_entry_release_w( op, e );
1508 LDAP_LOG( OPERATION, ERR,
1509 "be_modify failed (%d)\n", rc, 0, 0 );
1511 Debug( LDAP_DEBUG_ANY,
1512 "be_modify failed (%d)\n", rc, 0, 0 );
1523 if ( cnbva[0].bv_val )
1524 ch_free( cnbva[0].bv_val );
1526 for ( ; ml != NULL; ml = mlnext ) {
1527 mlnext = ml->sml_next;
1535 avl_ber_bvfree( void *bv )
1540 if ( ((struct berval *)bv)->bv_val != NULL ) {
1541 ch_free ( ((struct berval *)bv)->bv_val );
1543 ch_free ( (char *) bv );
1552 syncinfo_t *si = op->o_callback->sc_private;
1555 if ( rs->sr_type != REP_SEARCH ) return LDAP_SUCCESS;
1557 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_syncreplCookie );
1560 si->syncCookie = NULL;
1562 si->syncCookie = ber_dupbv( NULL, &a->a_vals[0] );
1564 return LDAP_SUCCESS;
1573 syncinfo_t *si = op->o_callback->sc_private;
1575 if ( rs->sr_type == REP_SEARCH ) {
1576 if ( si->syncUUID_ndn != NULL ) {
1578 LDAP_LOG( OPERATION, ERR,
1579 "dn_callback : multiple entries match dn\n", 0, 0, 0 );
1581 Debug( LDAP_DEBUG_ANY,
1582 "dn_callback : multiple entries match dn\n", 0, 0, 0 );
1585 if ( rs->sr_entry == NULL ) {
1586 si->syncUUID_ndn = NULL;
1588 si->syncUUID_ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname );
1593 return LDAP_SUCCESS;
1597 nonpresent_callback(
1602 syncinfo_t *si = op->o_callback->sc_private;
1605 struct berval* present_uuid = NULL;
1607 SlapReply rs_cb = {REP_RESULT};
1608 struct nonpresent_entry *np_entry;
1610 if ( rs->sr_type == REP_RESULT ) {
1611 count = avl_free( si->presentlist, avl_ber_bvfree );
1612 si->presentlist = NULL;
1613 return LDAP_SUCCESS;
1614 } else if ( rs->sr_type == REP_SEARCH ) {
1615 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID );
1620 present_uuid = avl_find( si->presentlist, &a->a_vals[0], syncuuid_cmp );
1622 if ( present_uuid == NULL ) {
1623 np_entry = (struct nonpresent_entry *)
1624 ch_calloc( 1, sizeof( struct nonpresent_entry ));
1625 np_entry->dn = ber_dupbv( NULL, &rs->sr_entry->e_name );
1626 np_entry->ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname );
1627 LDAP_LIST_INSERT_HEAD( &si->nonpresentlist, np_entry, np_link );
1629 avl_delete( &si->presentlist,
1630 &a->a_vals[0], syncuuid_cmp );
1631 ch_free( present_uuid->bv_val );
1632 ch_free( present_uuid );
1634 return LDAP_SUCCESS;
1636 return LDAP_SUCCESS;
1647 syncinfo_t *si = op->o_callback->sc_private;
1649 if ( rs->sr_err != LDAP_SUCCESS &&
1650 rs->sr_err != LDAP_REFERRAL &&
1651 rs->sr_err != LDAP_ALREADY_EXISTS &&
1652 rs->sr_err != LDAP_NO_SUCH_OBJECT ) {
1654 LDAP_LOG( OPERATION, ERR,
1655 "null_callback : error code 0x%x\n",
1658 Debug( LDAP_DEBUG_ANY,
1659 "null_callback : error code 0x%x\n",
1663 return LDAP_SUCCESS;
1667 slap_create_syncrepl_entry(
1669 struct berval *context_csn,
1679 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
1681 attr_merge( e, slap_schema.si_ad_objectClass, ocbva, NULL );
1683 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &ocbva[1], NULL );
1685 attr_merge_one( e, slap_schema.si_ad_cn, cn, NULL );
1687 if ( context_csn ) {
1688 attr_merge_one( e, slap_schema.si_ad_syncreplCookie,
1689 context_csn, NULL );
1693 bv.bv_len = sizeof("{}")-1;
1694 attr_merge_one( e, slap_schema.si_ad_subtreeSpecification, &bv, NULL );
1696 build_new_dn( &e->e_name, &be->be_nsuffix[0], rdn, NULL );
1697 ber_dupbv( &e->e_nname, &e->e_name );