3 * Replication Engine which uses the LDAP Sync protocol
6 * Copyright 2003 The OpenLDAP Foundation, All Rights Reserved.
7 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
9 /* Copyright (c) 2003 by International Business Machines, Inc.
11 * International Business Machines, Inc. (hereinafter called IBM) grants
12 * permission under its copyrights to use, copy, modify, and distribute this
13 * Software with or without fee, provided that the above copyright notice and
14 * all paragraphs of this notice appear in all copies, and that the name of IBM
15 * not be used in connection with the marketing of any product incorporating
16 * the Software or modifications thereof, without specific, written prior
19 * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
20 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21 * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
22 * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
23 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
24 * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
26 /* Modified by Howard Chu
28 * Copyright (c) 2003 by Howard Chu, Symas Corporation
30 * Modifications provided under the terms of the OpenLDAP public license.
37 #include <ac/string.h>
38 #include <ac/socket.h>
43 #include "lutil_ldap.h"
47 #define SYNCREPL_STR "syncreplxxx"
50 static const struct berval slap_syncrepl_bvc = BER_BVC(SYNCREPL_STR);
51 static const struct berval slap_syncrepl_cn_bvc = BER_BVC(CN_STR SYNCREPL_STR);
53 static void avl_ber_bvfree( void * );
56 syncrepl_del_nonpresent( Operation *, syncinfo_t * );
58 /* callback functions */
59 static int dn_callback( struct slap_op *, struct slap_rep * );
60 static int nonpresent_callback( struct slap_op *, struct slap_rep * );
61 static int null_callback( struct slap_op *, struct slap_rep * );
63 static AttributeDescription *sync_descs[4];
65 struct runqueue_s syncrepl_rq;
68 init_syncrepl(syncinfo_t *si)
73 if ( !sync_descs[0] ) {
74 sync_descs[0] = slap_schema.si_ad_objectClass;
75 sync_descs[1] = slap_schema.si_ad_structuralObjectClass;
76 sync_descs[2] = slap_schema.si_ad_entryCSN;
80 for ( n = 0; si->si_attrs[ n ] != NULL; n++ ) /* empty */;
83 /* Delete Attributes */
84 for ( i = 0; sync_descs[i] != NULL; i++ ) {
85 for ( j = 0; si->si_attrs[j] != NULL; j++ ) {
86 if ( strcmp( si->si_attrs[j], sync_descs[i]->ad_cname.bv_val )
89 ch_free( si->si_attrs[j] );
90 for ( k = j; si->si_attrs[k] != NULL; k++ ) {
91 si->si_attrs[k] = si->si_attrs[k+1];
96 for ( n = 0; si->si_attrs[ n ] != NULL; n++ ) /* empty */;
97 tmp = ( char ** ) ch_realloc( si->si_attrs, (n + 4)*sizeof( char * ));
100 LDAP_LOG( OPERATION, ERR, "out of memory\n", 0,0,0 );
102 Debug( LDAP_DEBUG_ANY, "out of memory\n", 0,0,0 );
106 tmp = ( char ** ) ch_realloc( si->si_attrs, 5 * sizeof( char * ));
109 LDAP_LOG( OPERATION, ERR, "out of memory\n", 0,0,0 );
111 Debug( LDAP_DEBUG_ANY, "out of memory\n", 0,0,0 );
114 tmp[ n++ ] = ch_strdup( "*" );
121 for ( i = 0; sync_descs[ i ] != NULL; i++ ) {
122 si->si_attrs[ n++ ] = ch_strdup ( sync_descs[i]->ad_cname.bv_val );
123 si->si_attrs[ n ] = NULL;
133 BerElementBuffer berbuf;
134 BerElement *ber = (BerElement *)&berbuf;
135 LDAPControl c[2], *ctrls[3];
136 struct timeval timeout;
140 /* setup LDAP SYNC control */
141 ber_init2( ber, NULL, LBER_USE_DER );
142 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &ctx );
144 if ( si->si_syncCookie.octet_str &&
145 si->si_syncCookie.octet_str[0].bv_val ) {
146 ber_printf( ber, "{eO}", abs(si->si_type),
147 &si->si_syncCookie.octet_str[0] );
149 ber_printf( ber, "{e}", abs(si->si_type) );
152 if ( (rc = ber_flatten2( ber, &c[0].ldctl_value, 0 )) == LBER_ERROR ) {
157 c[0].ldctl_oid = LDAP_CONTROL_SYNC;
158 c[0].ldctl_iscritical = si->si_type < 0;
161 if ( si->si_authzId ) {
162 c[1].ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
163 ber_str2bv( si->si_authzId, 0, 0, &c[1].ldctl_value );
164 c[1].ldctl_iscritical = 1;
171 timeout.tv_sec = si->si_tlimit > 0 ? si->si_tlimit : 1;
174 rc = ldap_search_ext( si->si_ld, si->si_base.bv_val, si->si_scope,
175 si->si_filterstr.bv_val, si->si_attrs, si->si_attrsonly,
176 ctrls, NULL, si->si_tlimit < 0 ? NULL : &timeout,
177 si->si_slimit, &msgid );
183 static const Listener dummy_list = { {0, ""}, {0, ""} };
192 char syncrepl_cbuf[sizeof(CN_STR SYNCREPL_STR)];
193 struct berval syncrepl_cn_bv;
194 struct sync_cookie syncCookie = { NULL, -1, NULL };
196 /* Init connection to master */
198 rc = ldap_initialize( &si->si_ld, si->si_provideruri );
199 if ( rc != LDAP_SUCCESS ) {
201 LDAP_LOG( OPERATION, ERR,
202 "do_syncrep1: ldap_initialize failed (%s)\n",
203 si->si_provideruri, 0, 0 );
205 Debug( LDAP_DEBUG_ANY,
206 "do_syncrep1: ldap_initialize failed (%s)\n",
207 si->si_provideruri, 0, 0 );
212 op->o_protocol = LDAP_VERSION3;
213 ldap_set_option( si->si_ld, LDAP_OPT_PROTOCOL_VERSION, &op->o_protocol );
218 rc = ldap_start_tls_s( si->si_ld, NULL, NULL );
219 if( rc != LDAP_SUCCESS ) {
221 LDAP_LOG ( OPERATION, ERR, "do_syncrep1: "
222 "%s: ldap_start_tls failed (%d)\n",
223 si->si_tls == SYNCINFO_TLS_CRITICAL ? "Error" : "Warning",
226 Debug( LDAP_DEBUG_ANY,
227 "%s: ldap_start_tls failed (%d)\n",
228 si->si_tls == SYNCINFO_TLS_CRITICAL ? "Error" : "Warning",
231 if( si->si_tls == SYNCINFO_TLS_CRITICAL ) goto done;
235 if ( si->si_bindmethod == LDAP_AUTH_SASL ) {
236 #ifdef HAVE_CYRUS_SASL
239 if ( si->si_secprops != NULL ) {
240 rc = ldap_set_option( si->si_ld,
241 LDAP_OPT_X_SASL_SECPROPS, si->si_secprops);
243 if( rc != LDAP_OPT_SUCCESS ) {
245 LDAP_LOG ( OPERATION, ERR, "do_bind: Error: "
246 "ldap_set_option(%s,SECPROPS,\"%s\") failed!\n",
247 si->si_provideruri, si->si_secprops, 0 );
249 Debug( LDAP_DEBUG_ANY, "Error: ldap_set_option "
250 "(%s,SECPROPS,\"%s\") failed!\n",
251 si->si_provideruri, si->si_secprops, 0 );
257 defaults = lutil_sasl_defaults( si->si_ld,
258 si->si_saslmech, si->si_realm,
259 si->si_authcId, si->si_passwd, si->si_authzId );
261 rc = ldap_sasl_interactive_bind_s( si->si_ld,
269 lutil_sasl_freedefs( defaults );
271 /* FIXME : different error behaviors according to
273 * 2) on err policy : exit, retry, backoff ...
275 if ( rc != LDAP_SUCCESS ) {
277 LDAP_LOG ( OPERATION, ERR, "do_syncrep1: "
278 "ldap_sasl_interactive_bind_s failed (%d)\n",
281 Debug( LDAP_DEBUG_ANY, "do_syncrep1: "
282 "ldap_sasl_interactive_bind_s failed (%d)\n",
287 #else /* HAVE_CYRUS_SASL */
288 /* Should never get here, we trapped this at config time */
289 fprintf( stderr, "not compiled with SASL support\n" );
294 rc = ldap_bind_s( si->si_ld, si->si_binddn, si->si_passwd, si->si_bindmethod );
295 if ( rc != LDAP_SUCCESS ) {
297 LDAP_LOG ( OPERATION, ERR, "do_syncrep1: "
298 "ldap_bind_s failed (%d)\n", rc, 0, 0 );
300 Debug( LDAP_DEBUG_ANY, "do_syncrep1: "
301 "ldap_bind_s failed (%d)\n", rc, 0, 0 );
307 /* get syncrepl cookie of shadow replica from subentry */
309 assert( si->si_id < 1000 );
310 syncrepl_cn_bv.bv_val = syncrepl_cbuf;
311 syncrepl_cn_bv.bv_len = snprintf(syncrepl_cbuf, sizeof(syncrepl_cbuf),
312 CN_STR "syncrepl%d", si->si_id );
313 build_new_dn( &op->o_req_ndn, &si->si_base, &syncrepl_cn_bv,
315 op->o_req_dn = op->o_req_ndn;
317 if ( slap_sync_cookie != NULL ) {
318 slap_sync_cookie_free( &si->si_syncCookie, 0 );
319 slap_parse_sync_cookie( slap_sync_cookie );
320 if ( slap_sync_cookie->ctxcsn == NULL ||
321 slap_sync_cookie->ctxcsn->bv_val == NULL ) {
322 slap_init_sync_cookie_ctxcsn( slap_sync_cookie );
324 slap_dup_sync_cookie( &si->si_syncCookie, slap_sync_cookie );
325 slap_sync_cookie_free( slap_sync_cookie, 1 );
326 slap_sync_cookie = NULL;
329 /* use in-memory version if it exists */
330 if ( si->si_syncCookie.octet_str == NULL ) {
331 BerVarray cookie = NULL;
332 struct berval cookie_bv;
333 backend_attribute( op, NULL, &op->o_req_ndn,
334 slap_schema.si_ad_syncreplCookie, &cookie );
336 ber_dupbv( &cookie_bv, &cookie[0] );
337 ber_bvarray_add( &si->si_syncCookie.octet_str, &cookie_bv );
338 slap_parse_sync_cookie( &si->si_syncCookie );
339 ber_bvarray_free_x( cookie, op->o_tmpmemctx );
343 rc = ldap_sync_search( si, op->o_tmpmemctx );
345 if( rc != LDAP_SUCCESS ) {
347 LDAP_LOG ( OPERATION, ERR, "do_syncrep1: "
348 "ldap_search_ext: %s (%d)\n", ldap_err2string( rc ), rc, 0 );
350 Debug( LDAP_DEBUG_ANY, "do_syncrep1: "
351 "ldap_search_ext: %s (%d)\n", ldap_err2string( rc ), rc, 0 );
358 ldap_unbind( si->si_ld );
371 LDAPControl **rctrls = NULL;
374 BerElementBuffer berbuf;
375 BerElement *ber = (BerElement *)&berbuf;
377 LDAPMessage *res = NULL;
378 LDAPMessage *msg = NULL;
381 struct berval *retdata = NULL;
386 struct berval syncUUID = { 0, NULL };
387 struct sync_cookie syncCookie = { NULL, -1, NULL };
388 struct sync_cookie syncCookie_req = { NULL, -1, NULL };
389 struct berval cookie = { 0, NULL };
400 Modifications *modlist = NULL;
405 struct timeval *tout_p = NULL;
406 struct timeval tout = { 0, 0 };
408 int refreshDeletes = 0;
413 if ( slapd_abrupt_shutdown ) {
419 LDAP_LOG ( OPERATION, DETAIL1, "do_syncrep2\n", 0, 0, 0 );
421 Debug( LDAP_DEBUG_TRACE, "=>do_syncrep2\n", 0, 0, 0 );
424 op->o_callback = &cb;
426 psub = &si->si_be->be_nsuffix[0];
428 slap_dup_sync_cookie( &syncCookie_req, &si->si_syncCookie );
430 if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST ){
436 while (( rc = ldap_result( si->si_ld, LDAP_RES_ANY, LDAP_MSG_ONE, tout_p, &res ))
439 if ( slapd_abrupt_shutdown ) {
443 for( msg = ldap_first_message( si->si_ld, res );
445 msg = ldap_next_message( si->si_ld, msg ) )
447 switch( ldap_msgtype( msg ) ) {
448 case LDAP_RES_SEARCH_ENTRY:
449 ldap_get_entry_controls( si->si_ld, msg, &rctrls );
450 /* we can't work without the control */
456 ber_init2( ber, &rctrlp->ldctl_value, LBER_USE_DER );
457 ber_scanf( ber, "{em", &syncstate, &syncUUID );
458 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
459 ber_scanf( ber, "m}", &cookie );
460 if ( cookie.bv_val ) {
461 struct berval tmp_bv;
462 ber_dupbv( &tmp_bv, &cookie );
463 ber_bvarray_add( &syncCookie.octet_str, &tmp_bv );
465 if ( syncCookie.octet_str &&
466 syncCookie.octet_str[0].bv_val )
467 slap_parse_sync_cookie( &syncCookie );
469 entry = syncrepl_message_to_entry( si, op, msg,
470 &modlist, syncstate );
471 rc_efree = syncrepl_entry( si, op, entry, modlist, syncstate,
472 &syncUUID, &syncCookie_req );
473 if ( syncCookie.octet_str && syncCookie.octet_str[0].bv_val ) {
474 syncrepl_updateCookie( si, op, psub, &syncCookie );
476 ldap_controls_free( rctrls );
478 slap_mods_free( modlist );
480 if ( rc_efree && entry ) {
485 case LDAP_RES_SEARCH_REFERENCE:
487 LDAP_LOG( OPERATION, ERR,
488 "do_syncrep2 : reference received\n", 0, 0, 0 );
490 Debug( LDAP_DEBUG_ANY,
491 "do_syncrep2 : reference received\n", 0, 0, 0 );
495 case LDAP_RES_SEARCH_RESULT:
496 ldap_parse_result( si->si_ld, msg, &err, NULL, NULL, NULL,
500 ber_init2( ber, &rctrlp->ldctl_value, LBER_USE_DER );
502 ber_scanf( ber, "{" /*"}"*/);
503 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE )
505 ber_scanf( ber, "m", &cookie );
506 if ( cookie.bv_val ) {
507 struct berval tmp_bv;
508 ber_dupbv( &tmp_bv, &cookie );
509 ber_bvarray_add( &syncCookie.octet_str, &tmp_bv);
511 if ( syncCookie.octet_str &&
512 syncCookie.octet_str[0].bv_val )
513 slap_parse_sync_cookie( &syncCookie );
515 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_REFRESHDELETES )
517 ber_scanf( ber, "b", &refreshDeletes );
519 ber_scanf( ber, "}" );
521 if ( syncCookie_req.ctxcsn == NULL ) {
523 } else if ( syncCookie.ctxcsn == NULL ) {
526 value_match( &match, slap_schema.si_ad_entryCSN,
527 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
528 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
529 &syncCookie_req.ctxcsn[0], &syncCookie.ctxcsn[0], &text );
531 if ( syncCookie.octet_str && syncCookie.octet_str->bv_val
533 syncrepl_updateCookie( si, op, psub, &syncCookie );
536 ldap_controls_free( rctrls );
538 if (si->si_type != LDAP_SYNC_REFRESH_AND_PERSIST) {
539 /* FIXME : different error behaviors according to
540 * 1) err code : LDAP_BUSY ...
541 * 2) on err policy : stop service, stop sync, retry
543 if ( refreshDeletes == 0 && match < 0 ) {
544 syncrepl_del_nonpresent( op, si );
546 avl_free( si->si_presentlist, avl_ber_bvfree );
547 si->si_presentlist = NULL;
554 case LDAP_RES_INTERMEDIATE:
555 rc = ldap_parse_intermediate( si->si_ld, msg,
556 &retoid, &retdata, NULL, 0 );
557 if ( !rc && !strcmp( retoid, LDAP_SYNC_INFO ) ) {
558 int si_refreshDelete = 0;
559 int si_refreshPresent = 0;
560 ber_init2( ber, retdata, LBER_USE_DER );
562 switch ( si_tag = ber_peek_tag( ber, &len )) {
564 case LDAP_TAG_SYNC_NEW_COOKIE:
565 ber_scanf( ber, "tm", &tag, &cookie );
567 case LDAP_TAG_SYNC_REFRESH_DELETE:
568 si_refreshDelete = 1;
569 case LDAP_TAG_SYNC_REFRESH_PRESENT:
570 si_refreshPresent = 1;
571 ber_scanf( ber, "t{", &tag );
572 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE )
574 ber_scanf( ber, "m", &tag, &cookie );
576 if ( ber_peek_tag( ber, &len ) ==
577 LDAP_TAG_REFRESHDONE )
579 ber_scanf( ber, "b", &refreshDone );
581 ber_scanf( ber, "}" );
583 case LDAP_TAG_SYNC_ID_SET:
584 /* FIXME : to be supported */
585 ber_scanf( ber, "t{", &tag );
586 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE )
588 ber_scanf( ber, "m", &tag, &cookie );
590 if ( ber_peek_tag( ber, &len ) ==
591 LDAP_TAG_REFRESHDELETES )
593 ber_scanf( ber, "b", &refreshDeletes );
595 ber_scanf( ber, "[W]", &syncUUIDs );
596 ber_scanf( ber, "}" );
600 LDAP_LOG( OPERATION, ERR,
601 "do_syncrep2 : unknown syncinfo tag (%d)\n",
604 Debug( LDAP_DEBUG_ANY,
605 "do_syncrep2 : unknown syncinfo tag (%d)\n",
608 ldap_memfree( retoid );
609 ber_bvfree( retdata );
613 if ( syncCookie_req.ctxcsn == NULL ) {
615 } else if ( syncCookie.ctxcsn == NULL ) {
618 value_match( &match, slap_schema.si_ad_entryCSN,
619 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
620 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
621 &syncCookie_req.ctxcsn[0],
622 &syncCookie.ctxcsn[0], &text );
625 if ( syncCookie.ctxcsn && syncCookie.ctxcsn[0].bv_val
627 syncrepl_updateCookie( si, op, psub, &syncCookie);
630 if ( si_refreshPresent == 1 ) {
632 syncrepl_del_nonpresent( op, si );
636 ldap_memfree( retoid );
637 ber_bvfree( retdata );
641 LDAP_LOG( OPERATION, ERR,"do_syncrep2 :"
642 " unknown intermediate "
643 "response\n", 0, 0, 0 );
645 Debug( LDAP_DEBUG_ANY, "do_syncrep2 : "
646 "unknown intermediate response (%d)\n",
649 ldap_memfree( retoid );
650 ber_bvfree( retdata );
656 LDAP_LOG( OPERATION, ERR, "do_syncrep2 : "
657 "unknown message\n", 0, 0, 0 );
659 Debug( LDAP_DEBUG_ANY, "do_syncrep2 : "
660 "unknown message\n", 0, 0, 0 );
665 if ( syncCookie.octet_str ) {
666 slap_sync_cookie_free( &syncCookie_req, 0 );
667 slap_dup_sync_cookie( &syncCookie_req, &syncCookie );
668 slap_sync_cookie_free( &syncCookie, 0 );
678 ldap_get_option( si->si_ld, LDAP_OPT_ERROR_NUMBER, &rc );
679 errstr = ldap_err2string( rc );
682 LDAP_LOG( OPERATION, ERR,
683 "do_syncrep2 : %s\n", errstr, 0, 0 );
685 Debug( LDAP_DEBUG_ANY,
686 "do_syncrep2 : %s\n", errstr, 0, 0 );
691 slap_sync_cookie_free( &syncCookie, 0 );
692 slap_sync_cookie_free( &syncCookie_req, 0 );
694 if ( res ) ldap_msgfree( res );
696 if ( rc && si->si_ld ) {
697 ldap_unbind( si->si_ld );
709 struct re_s* rtask = arg;
710 syncinfo_t *si = ( syncinfo_t * ) rtask->arg;
711 Connection conn = {0};
713 int rc = LDAP_SUCCESS;
719 LDAP_LOG ( OPERATION, DETAIL1, "do_syncrepl\n", 0, 0, 0 );
721 Debug( LDAP_DEBUG_TRACE, "=>do_syncrepl\n", 0, 0, 0 );
727 switch( abs( si->si_type )) {
728 case LDAP_SYNC_REFRESH_ONLY:
729 case LDAP_SYNC_REFRESH_AND_PERSIST:
735 if ( slapd_abrupt_shutdown && si->si_ld ) {
736 ldap_get_option( si->si_ld, LDAP_OPT_DESC, &s );
737 connection_client_stop( s );
738 ldap_unbind( si->si_ld );
744 conn.c_send_ldap_result = slap_send_ldap_result;
745 conn.c_send_search_entry = slap_send_search_entry;
746 conn.c_send_search_reference = slap_send_search_reference;
747 conn.c_listener = (Listener *)&dummy_list;
748 conn.c_peer_name = slap_empty_bv;
750 /* set memory context */
751 #define SLAB_SIZE 1048576
752 op.o_tmpmemctx = sl_mem_create( SLAB_SIZE, ctx );
753 op.o_tmpmfuncs = &sl_mfuncs;
755 op.o_dn = si->si_updatedn;
756 op.o_ndn = si->si_updatedn;
757 op.o_time = slap_get_time();
758 op.o_threadctx = ctx;
759 op.o_managedsait = 1;
762 op.o_connid = op.o_conn->c_connid;
764 op.o_sync_state.ctxcsn = NULL;
765 op.o_sync_state.sid = -1;
766 op.o_sync_state.octet_str = NULL;
767 op.o_sync_slog_size = -1;
768 LDAP_STAILQ_FIRST( &op.o_sync_slog_list ) = NULL;
769 op.o_sync_slog_list.stqh_last = &LDAP_STAILQ_FIRST(&op.o_sync_slog_list);
771 /* Establish session, do search */
774 rc = do_syncrep1( &op, si );
777 /* Process results */
778 if ( rc == LDAP_SUCCESS ) {
779 ldap_get_option( si->si_ld, LDAP_OPT_DESC, &s );
781 rc = do_syncrep2( &op, si );
783 if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST ) {
784 /* If we succeeded, enable the connection for further listening.
785 * If we failed, tear down the connection and reschedule.
787 if ( rc == LDAP_SUCCESS ) {
789 rc = connection_client_setup( s, (Listener *)&dummy_list, do_syncrepl,
792 connection_client_enable( s );
794 } else if ( !first ) {
798 if ( rc == -2 ) rc = 0;
802 /* At this point, we have 4 cases:
803 * 1) for any hard failure, give up and remove this task
804 * 2) for ServerDown, reschedule this task to run
805 * 3) for Refresh and Success, reschedule to run
806 * 4) for Persist and Success, reschedule to defer
808 ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
809 if ( ldap_pvt_runqueue_isrunning( &syncrepl_rq, rtask )) {
810 ldap_pvt_runqueue_stoptask( &syncrepl_rq, rtask );
814 connection_client_stop( s );
817 if ( rc && rc != LDAP_SERVER_DOWN ) {
818 ldap_pvt_runqueue_remove( &syncrepl_rq, rtask );
820 if ( rc == LDAP_SERVER_DOWN ||
821 si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
826 ldap_pvt_runqueue_resched( &syncrepl_rq, rtask, rc );
828 ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
834 syncrepl_message_to_entry(
838 Modifications **modlist,
843 BerElement *ber = NULL;
846 Modifications **modtail = modlist;
849 char txtbuf[SLAP_TEXT_BUFLEN];
850 size_t textlen = sizeof txtbuf;
852 struct berval bdn = {0, NULL}, dn, ndn;
857 if ( ldap_msgtype( msg ) != LDAP_RES_SEARCH_ENTRY ) {
859 LDAP_LOG( OPERATION, ERR,
860 "Message type should be entry (%d)", ldap_msgtype( msg ), 0, 0 );
862 Debug( LDAP_DEBUG_ANY,
863 "Message type should be entry (%d)", ldap_msgtype( msg ), 0, 0 );
868 op->o_tag = LDAP_REQ_ADD;
870 rc = ldap_get_dn_ber( si->si_ld, msg, &ber, &bdn );
872 if ( rc != LDAP_SUCCESS ) {
874 LDAP_LOG( OPERATION, ERR,
875 "syncrepl_message_to_entry : dn get failed (%d)", rc, 0, 0 );
877 Debug( LDAP_DEBUG_ANY,
878 "syncrepl_message_to_entry : dn get failed (%d)", rc, 0, 0 );
883 dnPrettyNormal( NULL, &bdn, &dn, &ndn, op->o_tmpmemctx );
884 ber_dupbv( &op->o_req_dn, &dn );
885 ber_dupbv( &op->o_req_ndn, &ndn );
886 sl_free( ndn.bv_val, op->o_tmpmemctx );
887 sl_free( dn.bv_val, op->o_tmpmemctx );
889 if ( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_DELETE ) {
893 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ) );
894 e->e_name = op->o_req_dn;
895 e->e_nname = op->o_req_ndn;
897 while ( ber_remaining( ber ) ) {
898 if ( (ber_scanf( ber, "{mW}", &tmp.sml_type, &tmp.sml_values ) ==
899 LBER_ERROR ) || ( tmp.sml_type.bv_val == NULL ))
904 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
906 mod->sml_op = LDAP_MOD_REPLACE;
907 mod->sml_next = NULL;
908 mod->sml_desc = NULL;
909 mod->sml_type = tmp.sml_type;
910 mod->sml_bvalues = tmp.sml_bvalues;
911 mod->sml_nvalues = NULL;
914 modtail = &mod->sml_next;
917 if ( *modlist == NULL ) {
919 LDAP_LOG( OPERATION, ERR,
920 "syncrepl_message_to_entry: no attributes\n", 0, 0, 0 );
922 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: no attributes\n",
927 rc = slap_mods_check( *modlist, 1, &text, txtbuf, textlen, NULL );
929 if ( rc != LDAP_SUCCESS ) {
931 LDAP_LOG( OPERATION, ERR,
932 "syncrepl_message_to_entry: mods check (%s)\n", text, 0, 0 );
934 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods check (%s)\n",
940 rc = slap_mods2entry( *modlist, &e, 1, 1, &text, txtbuf, textlen);
941 if( rc != LDAP_SUCCESS ) {
943 LDAP_LOG( OPERATION, ERR,
944 "syncrepl_message_to_entry: mods2entry (%s)\n", text, 0, 0 );
946 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods2entry (%s)\n",
953 if ( rc != LDAP_SUCCESS ) {
962 syncuuid_cmp( const void* v_uuid1, const void* v_uuid2 )
964 const struct berval *uuid1 = v_uuid1;
965 const struct berval *uuid2 = v_uuid2;
966 int rc = uuid1->bv_len - uuid2->bv_len;
968 return ( strcmp( uuid1->bv_val, uuid2->bv_val ) );
976 Modifications* modlist,
978 struct berval* syncUUID,
979 struct sync_cookie* syncCookie_req
982 Backend *be = op->o_bd;
984 struct berval *syncuuid_bv = NULL;
986 SlapReply rs = {REP_RESULT};
988 AttributeAssertion ava = {0};
989 int rc = LDAP_SUCCESS;
990 int ret = LDAP_SUCCESS;
993 if (( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD ))
995 syncuuid_bv = ber_dupbv( NULL, syncUUID );
996 avl_insert( &si->si_presentlist, (caddr_t) syncuuid_bv,
997 syncuuid_cmp, avl_dup_error );
1000 if ( syncstate == LDAP_SYNC_PRESENT ) {
1004 f.f_choice = LDAP_FILTER_EQUALITY;
1006 ava.aa_desc = slap_schema.si_ad_entryUUID;
1007 rc = asserted_value_validate_normalize(
1008 ava.aa_desc, ad_mr(ava.aa_desc, SLAP_MR_EQUALITY),
1009 SLAP_MR_EQUALITY, syncUUID, &ava.aa_value, &text, op->o_tmpmemctx );
1010 if ( rc != LDAP_SUCCESS ) {
1013 op->ors_filter = &f;
1015 op->ors_filterstr.bv_len = (sizeof("entryUUID=")-1) + syncUUID->bv_len;
1016 op->ors_filterstr.bv_val = (char *) sl_malloc(
1017 op->ors_filterstr.bv_len + 1, op->o_tmpmemctx );
1018 AC_MEMCPY( op->ors_filterstr.bv_val, "entryUUID=", sizeof("entryUUID=")-1 );
1019 AC_MEMCPY( &op->ors_filterstr.bv_val[sizeof("entryUUID=")-1],
1020 syncUUID->bv_val, syncUUID->bv_len );
1021 op->ors_filterstr.bv_val[op->ors_filterstr.bv_len] = '\0';
1023 op->ors_scope = LDAP_SCOPE_SUBTREE;
1025 /* get syncrepl cookie of shadow replica from subentry */
1026 op->o_req_dn = si->si_base;
1027 op->o_req_ndn = si->si_base;
1029 /* set callback function */
1030 op->o_callback = &cb;
1031 cb.sc_response = dn_callback;
1034 si->si_syncUUID_ndn.bv_val = NULL;
1036 rc = be->be_search( op, &rs );
1038 if ( op->ors_filterstr.bv_val ) {
1039 sl_free( op->ors_filterstr.bv_val, op->o_tmpmemctx );
1042 cb.sc_response = null_callback;
1045 if ( rc == LDAP_SUCCESS && si->si_syncUUID_ndn.bv_val )
1049 if ( syncstate != LDAP_SYNC_DELETE ) {
1050 op->o_no_psearch = 1;
1053 ber_dupbv( &op->o_sync_csn, syncCookie_req->ctxcsn );
1054 if ( op->o_sync_csn.bv_val ) {
1055 subseq_ptr = strstr( op->o_sync_csn.bv_val, "#0000" );
1060 op->o_req_dn = si->si_syncUUID_ndn;
1061 op->o_req_ndn = si->si_syncUUID_ndn;
1062 op->o_tag = LDAP_REQ_DELETE;
1063 rc = be->be_delete( op, &rs );
1064 op->o_no_psearch = 0;
1067 switch ( syncstate ) {
1069 case LDAP_SYNC_MODIFY:
1070 if ( rc == LDAP_SUCCESS ||
1071 rc == LDAP_REFERRAL ||
1072 rc == LDAP_NO_SUCH_OBJECT )
1074 attr_delete( &e->e_attrs, slap_schema.si_ad_entryUUID );
1075 attr_merge_one( e, slap_schema.si_ad_entryUUID,
1076 syncUUID, &ava.aa_value );
1078 op->o_tag = LDAP_REQ_ADD;
1080 op->o_req_dn = e->e_name;
1081 op->o_req_ndn = e->e_nname;
1082 rc = be->be_add( op, &rs );
1084 if ( rc != LDAP_SUCCESS ) {
1085 if ( rc == LDAP_ALREADY_EXISTS ) {
1086 op->o_tag = LDAP_REQ_MODIFY;
1087 op->orm_modlist = modlist;
1088 op->o_req_dn = e->e_name;
1089 op->o_req_ndn = e->e_nname;
1090 rc = be->be_modify( op, &rs );
1091 if ( rc != LDAP_SUCCESS ) {
1093 LDAP_LOG( OPERATION, ERR,
1094 "syncrepl_entry : be_modify failed (%d)\n",
1097 Debug( LDAP_DEBUG_ANY,
1098 "syncrepl_entry : be_modify failed (%d)\n",
1104 } else if ( rc == LDAP_REFERRAL || rc == LDAP_NO_SUCH_OBJECT ) {
1105 syncrepl_add_glue( op, e );
1110 LDAP_LOG( OPERATION, ERR,
1111 "syncrepl_entry : be_add failed (%d)\n",
1114 Debug( LDAP_DEBUG_ANY,
1115 "syncrepl_entry : be_add failed (%d)\n",
1122 be_entry_release_w( op, e );
1128 LDAP_LOG( OPERATION, ERR,
1129 "syncrepl_entry : be_search failed (%d)\n", rc, 0, 0 );
1131 Debug( LDAP_DEBUG_ANY,
1132 "syncrepl_entry : be_search failed (%d)\n", rc, 0, 0 );
1138 case LDAP_SYNC_DELETE :
1139 /* Already deleted */
1145 LDAP_LOG( OPERATION, ERR,
1146 "syncrepl_entry : unknown syncstate\n", 0, 0, 0 );
1148 Debug( LDAP_DEBUG_ANY,
1149 "syncrepl_entry : unknown syncstate\n", 0, 0, 0 );
1157 if ( ava.aa_value.bv_val ) {
1158 ber_memfree_x( ava.aa_value.bv_val, op->o_tmpmemctx );
1160 if ( si->si_syncUUID_ndn.bv_val ) {
1161 ber_memfree_x( si->si_syncUUID_ndn.bv_val, op->o_tmpmemctx );
1167 syncrepl_del_nonpresent(
1172 Backend* be = op->o_bd;
1174 SlapReply rs = {REP_RESULT};
1175 struct nonpresent_entry *np_list, *np_prev;
1177 op->o_req_dn = si->si_base;
1178 op->o_req_ndn = si->si_base;
1180 cb.sc_response = nonpresent_callback;
1183 op->o_callback = &cb;
1184 op->o_tag = LDAP_REQ_SEARCH;
1185 op->ors_scope = si->si_scope;
1186 op->ors_deref = LDAP_DEREF_NEVER;
1189 op->ors_attrsonly = 0;
1190 op->ors_attrs = NULL;
1191 op->ors_filter = str2filter_x( op, si->si_filterstr.bv_val );
1192 op->ors_filterstr = si->si_filterstr;
1194 op->o_nocaching = 1;
1195 be->be_search( op, &rs );
1196 op->o_nocaching = 0;
1198 if ( op->ors_filter ) filter_free_x( op, op->ors_filter );
1200 if ( !LDAP_LIST_EMPTY( &si->si_nonpresentlist ) ) {
1201 np_list = LDAP_LIST_FIRST( &si->si_nonpresentlist );
1202 while ( np_list != NULL ) {
1203 LDAP_LIST_REMOVE( np_list, npe_link );
1205 np_list = LDAP_LIST_NEXT( np_list, npe_link );
1206 op->o_tag = LDAP_REQ_DELETE;
1207 op->o_callback = &cb;
1208 cb.sc_response = null_callback;
1210 op->o_req_dn = *np_prev->npe_name;
1211 op->o_req_ndn = *np_prev->npe_nname;
1212 op->o_bd->be_delete( op, &rs );
1213 ber_bvfree( np_prev->npe_name );
1214 ber_bvfree( np_prev->npe_nname );
1215 op->o_req_dn.bv_val = NULL;
1216 op->o_req_ndn.bv_val = NULL;
1225 static struct berval gcbva[] = {
1236 Backend *be = op->o_bd;
1242 struct berval dn = {0, NULL};
1243 struct berval ndn = {0, NULL};
1245 SlapReply rs = {REP_RESULT};
1248 op->o_tag = LDAP_REQ_ADD;
1249 op->o_callback = &cb;
1250 cb.sc_response = null_callback;
1251 cb.sc_private = NULL;
1256 /* count RDNs in suffix */
1257 if ( be->be_nsuffix[0].bv_len ) {
1258 for (i=0, ptr=be->be_nsuffix[0].bv_val; ptr; ptr=strchr( ptr, ',' )) {
1268 /* Start with BE suffix */
1269 for ( i = 0, ptr = NULL; i < suffrdns; i++ ) {
1270 comma = strrchr(dn.bv_val, ',');
1271 if ( ptr ) *ptr = ',';
1272 if ( comma ) *comma = '\0';
1277 dn.bv_len -= ptr - dn.bv_val;
1280 /* the normalizedDNs are always the same length, no counting
1283 if ( ndn.bv_len > be->be_nsuffix[0].bv_len ) {
1284 ndn.bv_val += ndn.bv_len - be->be_nsuffix[0].bv_len;
1285 ndn.bv_len = be->be_nsuffix[0].bv_len;
1288 while ( ndn.bv_val > e->e_nname.bv_val ) {
1289 glue = (Entry *) ch_calloc( 1, sizeof(Entry) );
1290 ber_dupbv( &glue->e_name, &dn );
1291 ber_dupbv( &glue->e_nname, &ndn );
1293 a = ch_calloc( 1, sizeof( Attribute ));
1294 a->a_desc = slap_schema.si_ad_objectClass;
1296 a->a_vals = ch_calloc( 3, sizeof( struct berval ));
1297 ber_dupbv( &a->a_vals[0], &gcbva[0] );
1298 ber_dupbv( &a->a_vals[1], &gcbva[1] );
1299 a->a_vals[2].bv_len = 0;
1300 a->a_vals[2].bv_val = NULL;
1302 a->a_nvals = a->a_vals;
1304 a->a_next = glue->e_attrs;
1307 a = ch_calloc( 1, sizeof( Attribute ));
1308 a->a_desc = slap_schema.si_ad_structuralObjectClass;
1310 a->a_vals = ch_calloc( 2, sizeof( struct berval ));
1311 ber_dupbv( &a->a_vals[0], &gcbva[1] );
1312 a->a_vals[1].bv_len = 0;
1313 a->a_vals[1].bv_val = NULL;
1315 a->a_nvals = a->a_vals;
1317 a->a_next = glue->e_attrs;
1320 op->o_req_dn = glue->e_name;
1321 op->o_req_ndn = glue->e_nname;
1323 rc = be->be_add ( op, &rs );
1324 if ( rc == LDAP_SUCCESS ) {
1325 be_entry_release_w( op, glue );
1327 /* incl. ALREADY EXIST */
1331 /* Move to next child */
1332 for (ptr = dn.bv_val-2; ptr > e->e_name.bv_val && *ptr != ','; ptr--) {
1335 if ( ptr == e->e_name.bv_val ) break;
1337 dn.bv_len = e->e_name.bv_len - (ptr-e->e_name.bv_val);
1338 for( ptr = ndn.bv_val-2;
1339 ptr > e->e_nname.bv_val && *ptr != ',';
1345 ndn.bv_len = e->e_nname.bv_len - (ptr-e->e_nname.bv_val);
1348 op->o_req_dn = e->e_name;
1349 op->o_req_ndn = e->e_nname;
1351 rc = be->be_add ( op, &rs );
1352 if ( rc == LDAP_SUCCESS ) {
1353 be_entry_release_w( op, e );
1361 static struct berval ocbva[] = {
1363 BER_BVC("subentry"),
1364 BER_BVC("syncConsumerSubentry"),
1368 static struct berval cnbva[] = {
1373 static struct berval ssbva[] = {
1378 static struct berval scbva[] = {
1384 syncrepl_updateCookie(
1388 struct sync_cookie *syncCookie
1391 Backend *be = op->o_bd;
1393 Modifications *mlnext;
1395 Modifications *modlist = NULL;
1396 Modifications **modtail = &modlist;
1399 char txtbuf[SLAP_TEXT_BUFLEN];
1400 size_t textlen = sizeof txtbuf;
1405 char syncrepl_cbuf[sizeof(CN_STR SYNCREPL_STR)];
1406 struct berval slap_syncrepl_dn_bv = BER_BVNULL;
1407 struct berval slap_syncrepl_cn_bv = BER_BVNULL;
1410 SlapReply rs = {REP_RESULT};
1412 slap_sync_cookie_free( &si->si_syncCookie, 0 );
1413 slap_dup_sync_cookie( &si->si_syncCookie, syncCookie );
1415 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1416 mod->sml_op = LDAP_MOD_REPLACE;
1417 mod->sml_desc = slap_schema.si_ad_objectClass;
1418 mod->sml_type = mod->sml_desc->ad_cname;
1419 mod->sml_bvalues = ocbva;
1421 modtail = &mod->sml_next;
1423 ber_dupbv( &cnbva[0], (struct berval *) &slap_syncrepl_bvc );
1424 assert( si->si_id < 1000 );
1425 cnbva[0].bv_len = snprintf( cnbva[0].bv_val,
1426 slap_syncrepl_bvc.bv_len,
1427 "syncrepl%d", si->si_id );
1428 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1429 mod->sml_op = LDAP_MOD_REPLACE;
1430 mod->sml_desc = slap_schema.si_ad_cn;
1431 mod->sml_type = mod->sml_desc->ad_cname;
1432 mod->sml_bvalues = cnbva;
1434 modtail = &mod->sml_next;
1436 if ( scbva[0].bv_val ) ch_free( scbva[0].bv_val );
1437 ber_dupbv( &scbva[0], &si->si_syncCookie.octet_str[0] );
1438 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1439 mod->sml_op = LDAP_MOD_REPLACE;
1440 mod->sml_desc = slap_schema.si_ad_syncreplCookie;
1441 mod->sml_type = mod->sml_desc->ad_cname;
1442 mod->sml_bvalues = scbva;
1444 modtail = &mod->sml_next;
1446 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1447 mod->sml_op = LDAP_MOD_REPLACE;
1448 mod->sml_desc = slap_schema.si_ad_subtreeSpecification;
1449 mod->sml_type = mod->sml_desc->ad_cname;
1450 mod->sml_bvalues = ssbva;
1452 modtail = &mod->sml_next;
1456 op->o_tag = LDAP_REQ_ADD;
1457 rc = slap_mods_opattrs( op, modlist, modtail,
1458 &text,txtbuf, textlen );
1460 for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
1461 ml->sml_op = LDAP_MOD_REPLACE;
1464 if( rc != LDAP_SUCCESS ) {
1466 LDAP_LOG( OPERATION, ERR,
1467 "syncrepl_updateCookie: mods opattrs (%s)\n", text, 0, 0 );
1469 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods opattrs (%s)\n",
1474 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
1476 slap_syncrepl_cn_bv.bv_val = syncrepl_cbuf;
1477 assert( si->si_id < 1000 );
1478 slap_syncrepl_cn_bv.bv_len = snprintf( slap_syncrepl_cn_bv.bv_val,
1479 slap_syncrepl_cn_bvc.bv_len,
1480 "cn=syncrepl%d", si->si_id );
1482 build_new_dn( &slap_syncrepl_dn_bv, pdn, &slap_syncrepl_cn_bv,
1484 ber_dupbv( &e->e_name, &slap_syncrepl_dn_bv );
1485 ber_dupbv( &e->e_nname, &slap_syncrepl_dn_bv );
1487 if ( slap_syncrepl_dn_bv.bv_val ) {
1488 sl_free( slap_syncrepl_dn_bv.bv_val, op->o_tmpmemctx );
1493 rc = slap_mods2entry( modlist, &e, 1, 1, &text, txtbuf, textlen );
1495 if( rc != LDAP_SUCCESS ) {
1497 LDAP_LOG( OPERATION, ERR,
1498 "syncrepl_updateCookie: mods2entry (%s)\n", text, 0, 0 );
1500 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods2entry (%s)\n",
1505 cb.sc_response = null_callback;
1508 op->o_callback = &cb;
1509 op->o_req_dn = e->e_name;
1510 op->o_req_ndn = e->e_nname;
1512 /* update persistent cookie */
1513 update_cookie_retry:
1514 op->o_tag = LDAP_REQ_MODIFY;
1515 op->orm_modlist = modlist;
1516 rc = be->be_modify( op, &rs );
1518 if ( rc != LDAP_SUCCESS ) {
1519 if ( rc == LDAP_REFERRAL ||
1520 rc == LDAP_NO_SUCH_OBJECT ) {
1521 op->o_tag = LDAP_REQ_ADD;
1523 rc = be->be_add( op, &rs );
1524 if ( rc != LDAP_SUCCESS ) {
1525 if ( rc == LDAP_ALREADY_EXISTS ) {
1526 goto update_cookie_retry;
1527 } else if ( rc == LDAP_REFERRAL ||
1528 rc == LDAP_NO_SUCH_OBJECT ) {
1530 LDAP_LOG( OPERATION, ERR,
1531 "cookie will be non-persistent\n",
1534 Debug( LDAP_DEBUG_ANY,
1535 "cookie will be non-persistent\n",
1540 LDAP_LOG( OPERATION, ERR,
1541 "be_add failed (%d)\n",
1544 Debug( LDAP_DEBUG_ANY,
1545 "be_add failed (%d)\n",
1550 be_entry_release_w( op, e );
1555 LDAP_LOG( OPERATION, ERR,
1556 "be_modify failed (%d)\n", rc, 0, 0 );
1558 Debug( LDAP_DEBUG_ANY,
1559 "be_modify failed (%d)\n", rc, 0, 0 );
1570 if ( cnbva[0].bv_val ) {
1571 ch_free( cnbva[0].bv_val );
1572 cnbva[0].bv_val = NULL;
1574 if ( scbva[0].bv_val ) {
1575 ch_free( scbva[0].bv_val );
1576 scbva[0].bv_val = NULL;
1579 if ( mlnext->sml_next ) {
1580 slap_mods_free( mlnext->sml_next );
1581 mlnext->sml_next = NULL;
1584 for (ml = modlist ; ml != NULL; ml = mlnext ) {
1585 mlnext = ml->sml_next;
1598 syncinfo_t *si = op->o_callback->sc_private;
1600 if ( rs->sr_type == REP_SEARCH ) {
1601 if ( si->si_syncUUID_ndn.bv_val != NULL ) {
1603 LDAP_LOG( OPERATION, ERR,
1604 "dn_callback : multiple entries match dn\n", 0, 0, 0 );
1606 Debug( LDAP_DEBUG_ANY,
1607 "dn_callback : multiple entries match dn\n", 0, 0, 0 );
1610 ber_dupbv_x( &si->si_syncUUID_ndn, &rs->sr_entry->e_nname, op->o_tmpmemctx );
1614 return LDAP_SUCCESS;
1618 nonpresent_callback(
1623 syncinfo_t *si = op->o_callback->sc_private;
1626 struct berval* present_uuid = NULL;
1627 struct nonpresent_entry *np_entry;
1629 if ( rs->sr_type == REP_RESULT ) {
1630 count = avl_free( si->si_presentlist, avl_ber_bvfree );
1631 si->si_presentlist = NULL;
1633 } else if ( rs->sr_type == REP_SEARCH ) {
1634 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID );
1636 if ( a == NULL ) return 0;
1638 present_uuid = avl_find( si->si_presentlist, &a->a_vals[0],
1641 if ( present_uuid == NULL ) {
1642 np_entry = (struct nonpresent_entry *)
1643 ch_calloc( 1, sizeof( struct nonpresent_entry ));
1644 np_entry->npe_name = ber_dupbv( NULL, &rs->sr_entry->e_name );
1645 np_entry->npe_nname = ber_dupbv( NULL, &rs->sr_entry->e_nname );
1646 LDAP_LIST_INSERT_HEAD( &si->si_nonpresentlist, np_entry, npe_link );
1649 avl_delete( &si->si_presentlist,
1650 &a->a_vals[0], syncuuid_cmp );
1651 ch_free( present_uuid->bv_val );
1652 ch_free( present_uuid );
1655 return LDAP_SUCCESS;
1664 if ( rs->sr_err != LDAP_SUCCESS &&
1665 rs->sr_err != LDAP_REFERRAL &&
1666 rs->sr_err != LDAP_ALREADY_EXISTS &&
1667 rs->sr_err != LDAP_NO_SUCH_OBJECT )
1670 LDAP_LOG( OPERATION, ERR,
1671 "null_callback : error code 0x%x\n",
1674 Debug( LDAP_DEBUG_ANY,
1675 "null_callback : error code 0x%x\n",
1679 return LDAP_SUCCESS;
1683 slap_create_syncrepl_entry(
1685 struct berval *context_csn,
1694 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
1696 attr_merge( e, slap_schema.si_ad_objectClass, ocbva, NULL );
1698 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass,
1701 attr_merge_one( e, slap_schema.si_ad_cn, cn, NULL );
1703 if ( context_csn ) {
1704 attr_merge_one( e, slap_schema.si_ad_syncreplCookie,
1705 context_csn, NULL );
1709 bv.bv_len = sizeof("{}")-1;
1710 attr_merge_one( e, slap_schema.si_ad_subtreeSpecification, &bv, NULL );
1712 build_new_dn( &e->e_name, &be->be_nsuffix[0], rdn, NULL );
1713 ber_dupbv( &e->e_nname, &e->e_name );
1719 avl_ber_bvfree( void *bv )
1724 if ( ((struct berval *)bv)->bv_val != NULL ) {
1725 ch_free ( ((struct berval *)bv)->bv_val );
1727 ch_free ( (char *) bv );