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"
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 **add_descs;
51 static AttributeDescription **add_descs_lastmod;
52 static AttributeDescription **del_descs;
53 static AttributeDescription **del_descs_lastmod;
55 struct runqueue_s syncrepl_rq;
60 add_descs = ch_malloc( 2 * sizeof( AttributeDescription * ));
61 add_descs[0] = slap_schema.si_ad_objectClass;
64 add_descs_lastmod = ch_malloc( 7 * sizeof( AttributeDescription * ));
65 add_descs_lastmod[0] = slap_schema.si_ad_objectClass;
66 add_descs_lastmod[1] = slap_schema.si_ad_creatorsName;
67 add_descs_lastmod[2] = slap_schema.si_ad_modifiersName;
68 add_descs_lastmod[3] = slap_schema.si_ad_createTimestamp;
69 add_descs_lastmod[4] = slap_schema.si_ad_modifyTimestamp;
70 add_descs_lastmod[5] = slap_schema.si_ad_entryCSN;
71 add_descs_lastmod[6] = NULL;
73 del_descs = ch_malloc( 9 * sizeof( AttributeDescription * ));
74 del_descs[0] = slap_schema.si_ad_structuralObjectClass;
75 del_descs[1] = slap_schema.si_ad_subschemaSubentry;
76 del_descs[2] = slap_schema.si_ad_hasSubordinates;
77 del_descs[3] = slap_schema.si_ad_creatorsName;
78 del_descs[4] = slap_schema.si_ad_modifiersName;
79 del_descs[5] = slap_schema.si_ad_createTimestamp;
80 del_descs[6] = slap_schema.si_ad_modifyTimestamp;
81 del_descs[7] = slap_schema.si_ad_entryCSN;
84 del_descs_lastmod = ch_malloc( 4 * sizeof( AttributeDescription * ));
85 del_descs_lastmod[0] = slap_schema.si_ad_structuralObjectClass;
86 del_descs_lastmod[1] = slap_schema.si_ad_subschemaSubentry;
87 del_descs_lastmod[2] = slap_schema.si_ad_hasSubordinates;
88 del_descs_lastmod[3] = NULL;
104 BerElement *sync_ber = NULL;
105 struct berval *sync_bvalp = NULL;
109 struct timeval timeout;
111 /* setup LDAP SYNC control */
112 sync_ber = ber_alloc_t( LBER_USE_DER );
113 ber_set_option( sync_ber, LBER_OPT_BER_MEMCTX, NULL );
115 if ( si->syncCookie ) {
116 ber_printf( sync_ber, "{eO}", abs(si->type), si->syncCookie );
118 ber_printf( sync_ber, "{e}", abs(si->type) );
121 if ( ber_flatten( sync_ber, &sync_bvalp ) == LBER_ERROR ) {
122 ber_free( sync_ber, 1 );
125 ber_free( sync_ber, 1 );
127 ctrls = (LDAPControl**) sl_calloc( 3, sizeof(LDAPControl*), NULL );
129 c[0].ldctl_oid = LDAP_CONTROL_SYNC;
130 c[0].ldctl_value = (*sync_bvalp);
131 c[0].ldctl_iscritical = si->type < 0;
135 c[1].ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
136 c[1].ldctl_value.bv_val = si->authzId;
137 c[1].ldctl_value.bv_len = strlen( si->authzId );
138 c[1].ldctl_iscritical = 1;
146 err = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, ctrls );
148 ber_bvfree( sync_bvalp );
151 if ( err != LDAP_OPT_SUCCESS )
152 fprintf( stderr, "Could not set controls : %d\n", err );
154 timeout.tv_sec = si->tlimit > 0 ? si->tlimit : 1;
156 rc = ldap_search_ext( ld, si->base, si->scope, si->filterstr,
157 si->attrs, si->attrsonly, sctrls, cctrls,
158 si->tlimit < 0 ? NULL : &timeout,
159 si->slimit, msgidp );
169 struct re_s* rtask = arg;
170 syncinfo_t *si = ( syncinfo_t * ) rtask->arg;
171 Backend *be = si->be;
173 SlapReply rs = {REP_RESULT};
176 LDAPControl **sctrls = NULL;
177 LDAPControl **rctrls = NULL;
178 LDAPControl *rctrlp = NULL;
179 BerElement *sync_ber = NULL;
180 struct berval *sync_bvalp = NULL;
182 BerElement *ctrl_ber = NULL;
183 BerElement *res_ber = NULL;
186 LDAPMessage *res = NULL;
187 LDAPMessage *msg = NULL;
191 int nresponses, nreferences, nextended, npartial;
192 int nresponses_psearch;
194 int cancel_msgid = -1;
196 struct berval *retdata = NULL;
198 int sync_info_arrived = 0;
202 struct berval syncUUID = { 0, NULL };
203 struct berval syncCookie = { 0, NULL };
204 struct berval syncCookie_req = { 0, NULL };
209 int syncinfo_arrived = 0;
210 int cancel_response = 0;
213 AttributeDescription** descs = NULL;
225 struct berval base_bv = { 0, NULL };
226 struct berval pbase = { 0, NULL };
227 struct berval nbase = { 0, NULL };
228 struct berval sub_bv = { 0, NULL };
229 struct berval psubrdn = { 0, NULL };
230 struct berval nsubrdn = { 0, NULL };
231 struct berval psub = { 0, NULL };
232 struct berval nsub = { 0, NULL };
234 Modifications *modlist = NULL;
235 Modifications *ml, *mlnext;
236 char *def_filter_str = NULL;
242 LDAP_LOG ( OPERATION, DETAIL1, "do_syncrepl\n", 0, 0, 0 );
244 Debug( LDAP_DEBUG_TRACE, "=>do_syncrepl\n", 0, 0, 0 );
250 if ( abs(si->type) != LDAP_SYNC_REFRESH_ONLY &&
251 abs(si->type) != LDAP_SYNC_REFRESH_AND_PERSIST ) {
255 si->sync_mode = LDAP_SYNC_STATE_MODE;
257 /* Init connection to master */
259 rc = ldap_initialize( &ld, si->provideruri );
260 if ( rc != LDAP_SUCCESS ) {
262 LDAP_LOG( OPERATION, ERR, "do_syncrepl: "
263 "ldap_initialize failed (%s)\n",
264 si->provideruri, 0, 0 );
266 Debug( LDAP_DEBUG_ANY, "do_syncrepl: "
267 "ldap_initialize failed (%s)\n",
268 si->provideruri, 0, 0 );
272 op.o_protocol = LDAP_VERSION3;
273 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &op.o_protocol );
278 rc = ldap_start_tls_s( ld, NULL, NULL );
279 if( rc != LDAP_SUCCESS ) {
281 LDAP_LOG ( OPERATION, ERR, "do_syncrepl: "
282 "%s: ldap_start_tls failed (%d)\n",
283 si->tls == TLS_CRITICAL ? "Error" : "Warning",
286 Debug( LDAP_DEBUG_ANY,
287 "%s: ldap_start_tls failed (%d)\n",
288 si->tls == TLS_CRITICAL ? "Error" : "Warning",
291 if( si->tls == TLS_CRITICAL )
296 if ( si->bindmethod == LDAP_AUTH_SASL ) {
297 #ifdef HAVE_CYRUS_SASL
300 if ( si->secprops != NULL ) {
301 int err = ldap_set_option( ld,
302 LDAP_OPT_X_SASL_SECPROPS, si->secprops);
304 if( err != LDAP_OPT_SUCCESS ) {
306 LDAP_LOG ( OPERATION, ERR, "do_bind: Error: "
307 "ldap_set_option(%s,SECPROPS,\"%s\") failed!\n",
308 si->provideruri, si->secprops, 0 );
310 Debug( LDAP_DEBUG_ANY, "Error: ldap_set_option "
311 "(%s,SECPROPS,\"%s\") failed!\n",
312 si->provideruri, si->secprops, NULL );
318 defaults = lutil_sasl_defaults( ld,
325 rc = ldap_sasl_interactive_bind_s( ld,
333 if ( rc != LDAP_SUCCESS ) {
335 LDAP_LOG ( OPERATION, ERR, "do_syncrepl: "
336 "ldap_sasl_interactive_bind_s failed (%d)\n",
339 Debug( LDAP_DEBUG_ANY, "do_syncrepl: "
340 "ldap_sasl_interactive_bind_s failed (%d)\n",
345 #else /* HAVE_CYRUS_SASL */
346 fprintf( stderr, "not compiled with SASL support\n" );
350 rc = ldap_bind_s( ld, si->binddn, si->passwd, si->bindmethod );
351 if ( rc != LDAP_SUCCESS ) {
353 LDAP_LOG ( OPERATION, ERR, "do_syncrepl: "
354 "ldap_bind_s failed (%d)\n", rc, 0, 0 );
356 Debug( LDAP_DEBUG_ANY, "do_syncrepl: "
357 "ldap_bind_s failed (%d)\n", rc, 0, 0 );
363 /* set thread context in syncinfo */
366 /* set memory context */
367 #define SLAB_SIZE 1048576
369 memctx = sl_mem_create( memsiz, ctx );
370 op.o_tmpmemctx = memctx;
371 op.o_tmpmfuncs = &sl_mfuncs;
374 op.o_tag = LDAP_REQ_SEARCH;
375 op.o_dn = si->updatedn;
376 op.o_ndn = si->updatedn;
378 op.o_time = slap_get_time();
379 op.o_managedsait = 1;
380 op.o_threadctx = si->ctx;
383 op.o_connid = op.o_conn->c_connid;
384 op.ors_scope = LDAP_SCOPE_BASE;
385 op.ors_deref = LDAP_DEREF_NEVER;
388 op.ors_attrsonly = 0;
390 op.ors_filter = str2filter( def_filter_str = "(objectClass=*)" );
391 ber_str2bv( def_filter_str, strlen( def_filter_str ), 1,
395 conn.c_send_ldap_result = slap_send_ldap_result;
396 conn.c_send_search_entry = slap_send_search_entry;
397 conn.c_send_search_reference = slap_send_search_reference;
399 /* get syncrepl cookie of shadow replica from subentry */
400 ber_str2bv( si->base, strlen(si->base), 1, &base_bv );
401 dnPrettyNormal( 0, &base_bv, &pbase, &nbase, op.o_tmpmemctx );
403 sprintf( substr, "cn=syncrepl%d", si->id );
404 ber_str2bv( substr, strlen(substr), 1, &sub_bv );
405 dnPrettyNormal( 0, &sub_bv, &psubrdn, &nsubrdn, op.o_tmpmemctx );
407 build_new_dn( &op.o_req_dn, &pbase, &psubrdn );
408 build_new_dn( &op.o_req_ndn, &nbase, &nsubrdn );
410 ch_free( base_bv.bv_val );
411 ch_free( pbase.bv_val );
412 ch_free( nbase.bv_val );
413 ch_free( sub_bv.bv_val );
414 ch_free( psubrdn.bv_val );
415 ch_free( nsubrdn.bv_val );
417 /* set callback function */
418 cb.sc_response = cookie_callback;
421 /* search subentry to retrieve cookie */
422 si->syncCookie = NULL;
423 be->be_search( &op, &rs );
425 ber_dupbv( &syncCookie_req, si->syncCookie );
427 ch_free( op.o_req_dn.bv_val );
428 ch_free( op.o_req_ndn.bv_val );
429 filter_free( op.ors_filter );
430 ch_free( op.ors_filterstr.bv_val );
432 psub = be->be_nsuffix[0];
434 /* Delete Attributes */
435 if ( si->lastmod == LASTMOD_REQ ) {
436 descs = del_descs_lastmod;
441 for ( i = 0; descs[i] != NULL; i++ ) {
442 for ( j = 0; si->attrs[j] != NULL; j++ ) {
443 if ( !strcmp( si->attrs[j], descs[i]->ad_cname.bv_val )) {
444 ch_free( si->attrs[j] );
445 for ( k = j; si->attrs[k] != NULL; k++ ) {
446 si->attrs[k] = si->attrs[k+1];
454 for ( n = 0; si->attrs[ n ] != NULL; n++ ) ;
456 if ( si->lastmod == LASTMOD_REQ ) {
457 descs = add_descs_lastmod;
462 for ( i = 0; descs[i] != NULL; i++ ) {
463 tmp = ( char ** ) ch_realloc( si->attrs,
464 ( n + 2 ) * sizeof( char * ));
467 LDAP_LOG( OPERATION, ERR, "out of memory\n", 0,0,0 );
469 Debug( LDAP_DEBUG_ANY, "out of memory\n", 0,0,0 );
473 si->attrs[ n++ ] = ch_strdup ( descs[i]->ad_cname.bv_val );
474 si->attrs[ n ] = NULL;
477 rc = ldap_sync_search( si, ld, NULL, NULL, &msgid );
478 if( rc != LDAP_SUCCESS ) {
479 fprintf( stderr, "syncrepl: ldap_search_ext: %s (%d)\n",
480 ldap_err2string( rc ), rc );
484 while (( rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ONE, NULL, &res )) > 0 ) {
486 for ( msg = ldap_first_message( ld, res );
488 msg = ldap_next_message( ld, msg ) )
490 syncCookie.bv_len = 0; syncCookie.bv_val = NULL;
491 switch( ldap_msgtype( msg ) ) {
492 case LDAP_RES_SEARCH_ENTRY:
493 entry = syncrepl_message_to_entry( si, ld, &op, msg,
494 &modlist, &syncstate, &syncUUID, &syncCookie );
495 rc_efree = syncrepl_entry( si, ld, &op, entry, modlist,
496 syncstate, &syncUUID, &syncCookie, !syncinfo_arrived );
497 if ( syncCookie.bv_len ) {
498 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie );
502 for ( ml = modlist; ml != NULL; ml = mlnext ) {
503 mlnext = ml->sml_next;
508 case LDAP_RES_SEARCH_REFERENCE:
510 LDAP_LOG( OPERATION, ERR,
511 "do_syncrepl : reference received\n", 0, 0, 0 );
513 Debug( LDAP_DEBUG_ANY,
514 "do_syncrepl : reference received\n", 0, 0, 0 );
518 case LDAP_RES_SEARCH_RESULT:
519 ldap_parse_result( ld, msg, &err, NULL, NULL, NULL, &rctrls, 0 );
522 ctrl_ber = ber_alloc_t( LBER_USE_DER );
523 ber_set_option( ctrl_ber, LBER_OPT_BER_MEMCTX, &op.o_tmpmemctx );
524 ber_write( ctrl_ber, rctrlp->ldctl_value.bv_val, rctrlp->ldctl_value.bv_len, 0 );
525 ber_reset( ctrl_ber, 1 );
527 ber_scanf( ctrl_ber, "{" /*"}"*/);
528 if ( ber_peek_tag( ctrl_ber, &len )
529 == LDAP_SYNC_TAG_COOKIE ) {
530 ber_scanf( ctrl_ber, "o", &syncCookie );
533 value_match( &match, slap_schema.si_ad_entryCSN,
534 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
535 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
536 &syncCookie_req, &syncCookie, &text );
537 if (si->type == LDAP_SYNC_REFRESH_AND_PERSIST) {
538 if ( cancel_response ) {
539 if ( syncCookie.bv_len && match < 0) {
540 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie );
543 ber_free( ctrl_ber, 1 );
548 ber_free( ctrl_ber, 1 );
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 );
652 LDAP_LOG( OPERATION, ERR,
653 "do_syncrepl : unknown result\n", 0, 0, 0 );
655 Debug( LDAP_DEBUG_ANY,
656 "do_syncrepl : unknown result\n", 0, 0, 0 );
661 if ( syncCookie.bv_val )
662 ch_free( syncCookie.bv_val );
663 if ( syncCookie_req.bv_val )
664 ch_free( syncCookie_req.bv_val );
665 if ( syncUUID.bv_val )
666 ch_free( syncUUID.bv_val );
672 ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
673 ldap_pvt_runqueue_stoptask( &syncrepl_rq, rtask );
674 if ( si->type == LDAP_SYNC_REFRESH_ONLY ) {
675 ldap_pvt_runqueue_resched( &syncrepl_rq, rtask );
677 ldap_pvt_runqueue_remove( &syncrepl_rq, rtask );
679 ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
685 syncrepl_message_to_entry(
690 Modifications **modlist,
692 struct berval *syncUUID,
693 struct berval *syncCookie
697 BerElement *ber = NULL;
699 struct berval bv = {0, NULL};
702 Modifications **modtail = modlist;
703 Backend *be = op->o_bd;
706 char txtbuf[SLAP_TEXT_BUFLEN];
707 size_t textlen = sizeof txtbuf;
709 struct berval **bvals = NULL;
711 struct berval bdn = {0, NULL};
713 struct berval empty_bv = { 0, NULL };
719 LDAPControl** rctrls = NULL;
720 BerElement* ctrl_ber;
724 Modifications *prevml = NULL;
725 Modifications *nextml = NULL;
726 Modifications *ml = NULL;
727 AttributeDescription** descs;
732 if ( ldap_msgtype( msg ) != LDAP_RES_SEARCH_ENTRY ) {
734 LDAP_LOG( OPERATION, ERR,
735 "Message type should be entry (%d)", ldap_msgtype( msg ), 0, 0 );
737 Debug( LDAP_DEBUG_ANY,
738 "Message type should be entry (%d)", ldap_msgtype( msg ), 0, 0 );
743 op->o_tag = LDAP_REQ_ADD;
745 rc = ldap_get_dn_ber( ld, msg, &ber, &bdn );
747 if ( rc != LDAP_SUCCESS ) {
749 LDAP_LOG( OPERATION, ERR,
750 "syncrepl_message_to_entry : dn get failed (%d)", rc, 0, 0 );
752 Debug( LDAP_DEBUG_ANY,
753 "syncrepl_message_to_entry : dn get failed (%d)", rc, 0, 0 );
758 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
759 dnPrettyNormal( NULL, &bdn, &e->e_name, &e->e_nname, NULL );
763 while ( ber_remaining( ber ) ) {
764 tag = ber_scanf( ber, "{mW}", &tmp.sml_type, &tmp.sml_values );
766 if ( tag == LBER_ERROR ) break;
767 if ( tmp.sml_type.bv_val == NULL ) break;
769 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
771 mod->sml_op = LDAP_MOD_REPLACE;
772 mod->sml_next = NULL;
773 mod->sml_desc = NULL;
774 mod->sml_type = tmp.sml_type;
775 mod->sml_bvalues = tmp.sml_bvalues;
776 mod->sml_nvalues = tmp.sml_bvalues;
779 modtail = &mod->sml_next;
782 if ( ber_scanf( ber, "}") == LBER_ERROR ) {
784 LDAP_LOG( OPERATION, ERR,
785 "syncrepl_message_to_entry: ber_scanf failed\n", 0, 0, 0 );
787 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: ber_scanf failed\n",
794 tmpber = ldap_get_message_ber( msg );
795 ber = ber_dup( tmpber );
797 ber_scanf( ber, "{xx" );
799 rc = ldap_int_get_controls( ber, &rctrls );
801 if ( rc != LDAP_SUCCESS ) {
803 LDAP_LOG( OPERATION, ERR,
804 "syncrepl_message_to_entry : control get failed (%d)", rc, 0, 0 );
806 Debug( LDAP_DEBUG_ANY,
807 "syncrepl_message_to_entry : control get failed (%d)", rc, 0, 0 );
814 ctrl_ber = ber_alloc_t( LBER_USE_DER );
815 ber_set_option( ctrl_ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
816 ber_write( ctrl_ber, rctrlp->ldctl_value.bv_val, rctrlp->ldctl_value.bv_len, 0 );
817 ber_reset( ctrl_ber, 1 );
818 ber_scanf( ctrl_ber, "{eo", syncstate, syncUUID );
819 if ( ber_peek_tag( ctrl_ber, &len ) == LDAP_SYNC_TAG_COOKIE ) {
820 ber_scanf( ctrl_ber, "o}", syncCookie );
822 ber_free( ctrl_ber, 1 );
825 LDAP_LOG( OPERATION, ERR,"syncrepl_message_to_entry : "
826 " rctrls absent\n", 0, 0, 0 );
828 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry :"
829 " rctrls absent\n", 0, 0, 0 );
833 if ( *syncstate == LDAP_SYNC_PRESENT ) {
836 } else if ( *syncstate == LDAP_SYNC_DELETE ) {
840 if ( *modlist == NULL ) {
842 LDAP_LOG( OPERATION, ERR,
843 "syncrepl_message_to_entry: no attributes\n", 0, 0, 0 );
845 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: no attributes\n",
851 while ( ml != NULL ) {
852 AttributeDescription *ad = NULL;
853 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, &text );
855 if( rc != LDAP_SUCCESS ) {
863 if ( si->lastmod == LASTMOD_REQ ) {
864 descs = del_descs_lastmod;
869 for ( i = 0; descs[i] != NULL; i++ ) {
870 if ( ad == descs[i] ) {
871 if ( prevml == NULL ) {
872 modlist = &ml->sml_next;
875 prevml->sml_next = ml->sml_next;
877 slap_mod_free( &ml->sml_mod, 0 );
878 nextml = ml->sml_next;
888 rc = slap_mods_check( *modlist, 1, &text, txtbuf, textlen, NULL );
890 if ( rc != LDAP_SUCCESS ) {
892 LDAP_LOG( OPERATION, ERR,
893 "syncrepl_message_to_entry: mods check (%s)\n", text, 0, 0 );
895 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods check (%s)\n",
901 rc = slap_mods_opattrs( op, *modlist, modtail,
902 &text,txtbuf, textlen );
904 if( rc != LDAP_SUCCESS ) {
906 LDAP_LOG( OPERATION, ERR,
907 "syncrepl_message_to_entry: mods opattrs (%s)\n", text, 0, 0 );
909 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods opattrs (%s)\n",
915 rc = slap_mods2entry( *modlist, &e, 1, 1, &text, txtbuf, textlen);
916 if( rc != LDAP_SUCCESS ) {
918 LDAP_LOG( OPERATION, ERR,
919 "syncrepl_message_to_entry: mods2entry (%s)\n", text, 0, 0 );
921 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods2entry (%s)\n",
934 syncuuid_cmp( const void* v_uuid1, const void* v_uuid2 )
936 const struct berval *uuid1 = v_uuid1;
937 const struct berval *uuid2 = v_uuid2;
938 int rc = uuid1->bv_len - uuid2->bv_len;
940 return ( strcmp( uuid1->bv_val, uuid2->bv_val ) );
949 Modifications* modlist,
951 struct berval* syncUUID,
952 struct berval* syncCookie,
956 Backend *be = op->o_bd;
958 struct berval csn_bv = {0, NULL};
959 struct berval *syncuuid_bv = NULL;
960 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
962 SlapReply rs = {REP_RESULT};
963 int rc = LDAP_SUCCESS;
965 struct berval base_bv = {0, NULL};
973 ( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD )) {
974 syncuuid_bv = ber_dupbv( NULL, syncUUID );
975 avl_insert( &si->presentlist, (caddr_t) syncuuid_bv,
976 syncuuid_cmp, avl_dup_error );
979 if ( syncstate == LDAP_SYNC_PRESENT ) {
986 filterstr = (char *) sl_malloc( strlen("entryUUID=") + syncUUID->bv_len + 1,
988 strcpy( filterstr, "entryUUID=" );
989 strcat( filterstr, syncUUID->bv_val );
992 si->syncUUID = syncUUID;
993 si->syncUUID_ndn = NULL;
995 filter = str2filter( filterstr );
996 ber_str2bv( filterstr, strlen(filterstr), 1, &op->ors_filterstr );
997 ch_free( filterstr );
998 op->ors_filter = filter;
999 op->ors_scope = LDAP_SCOPE_SUBTREE;
1001 /* get syncrepl cookie of shadow replica from subentry */
1002 ber_str2bv( si->base, strlen(si->base), 1, &base_bv );
1003 dnPrettyNormal( 0, &base_bv, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
1004 ch_free( base_bv.bv_val );
1006 /* set callback function */
1007 op->o_callback = &cb;
1008 cb.sc_response = dn_callback;
1011 rc = be->be_search( op, &rs );
1013 ch_free( op->o_req_dn.bv_val );
1014 ch_free( op->o_req_ndn.bv_val );
1015 filter_free( op->ors_filter );
1016 ch_free( op->ors_filterstr.bv_val );
1018 cb.sc_response = null_callback;
1021 if ( rc == LDAP_SUCCESS && si->syncUUID_ndn && si->sync_mode != LDAP_SYNC_LOG_MODE ) {
1022 op->o_req_dn = *si->syncUUID_ndn;
1023 op->o_req_ndn = *si->syncUUID_ndn;
1024 op->o_tag = LDAP_REQ_DELETE;
1025 rc = be->be_delete( op, &rs );
1028 if ( si->syncUUID_ndn ) {
1029 ber_bvfree( si->syncUUID_ndn );
1032 switch ( syncstate ) {
1033 case LDAP_SYNC_ADD :
1034 case LDAP_SYNC_MODIFY :
1036 if ( rc == LDAP_SUCCESS ||
1037 rc == LDAP_REFERRAL ||
1038 rc == LDAP_NO_SUCH_OBJECT ) {
1040 if ( !attr_find( e->e_attrs, slap_schema.si_ad_entryUUID )) {
1041 attr_merge_normalize_one( e, slap_schema.si_ad_entryUUID, syncUUID, op->o_tmpmemctx );
1044 op->o_tag = LDAP_REQ_ADD;
1046 op->o_req_dn = e->e_name;
1047 op->o_req_ndn = e->e_nname;
1048 rc = be->be_add( op, &rs );
1050 if ( rc != LDAP_SUCCESS ) {
1051 if ( rc == LDAP_ALREADY_EXISTS ) {
1052 op->o_tag = LDAP_REQ_MODIFY;
1053 op->orm_modlist = modlist;
1054 op->o_req_dn = e->e_name;
1055 op->o_req_ndn = e->e_nname;
1056 rc = be->be_modify( op, &rs );
1059 } else if ( rc == LDAP_REFERRAL ||
1060 rc == LDAP_NO_SUCH_OBJECT ) {
1061 syncrepl_add_glue( si, ld, op, e,
1063 syncUUID, syncCookie);
1068 LDAP_LOG( OPERATION, ERR,
1069 "be_modify failed (%d)\n",
1072 Debug( LDAP_DEBUG_ANY,
1073 "be_modify failed (%d)\n",
1081 be_entry_release_w( op, e );
1086 LDAP_LOG( OPERATION, ERR,
1087 "be_modify/be_delete failed (%d)\n", rc, 0, 0 );
1089 Debug( LDAP_DEBUG_ANY,
1090 "be_modify/be_delete failed (%d)\n", rc, 0, 0 );
1096 case LDAP_SYNC_DELETE :
1097 if ( si->sync_mode == LDAP_SYNC_LOG_MODE ) {
1098 op->o_req_dn = *si->syncUUID_ndn;
1099 op->o_req_ndn = *si->syncUUID_ndn;
1100 op->o_tag = LDAP_REQ_DELETE;
1101 rc = be->be_delete( op, &rs );
1103 /* Already deleted otherwise */
1108 LDAP_LOG( OPERATION, ERR,
1109 "unknown syncstate\n", 0, 0, 0 );
1111 Debug( LDAP_DEBUG_ANY,
1112 "unknown syncstate\n", 0, 0, 0 );
1119 syncrepl_del_nonpresent(
1124 Backend* be = op->o_bd;
1125 syncinfo_t *si = op->o_si;
1127 struct berval base_bv = {0, NULL};
1129 SlapReply rs = {REP_RESULT};
1130 struct berval filterstr_bv = {0, NULL};
1131 struct nonpresent_entry *np_list, *np_prev;
1133 ber_str2bv( si->base, strlen(si->base), 1, &base_bv );
1134 dnPrettyNormal(0, &base_bv, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
1135 ch_free( base_bv.bv_val );
1137 filter = str2filter( si->filterstr );
1139 cb.sc_response = nonpresent_callback;
1142 op->o_callback = &cb;
1143 op->o_tag = LDAP_REQ_SEARCH;
1144 op->ors_scope = si->scope;
1145 op->ors_deref = LDAP_DEREF_NEVER;
1148 op->ors_attrsonly = 0;
1149 op->ors_attrs = NULL;
1150 op->ors_filter = filter;
1151 ber_str2bv( si->filterstr, strlen( si->filterstr ), 1, &op->ors_filterstr );
1153 be->be_search( op, &rs );
1155 if ( !LDAP_LIST_EMPTY( &si->nonpresentlist ) ) {
1156 np_list = LDAP_LIST_FIRST( &si->nonpresentlist );
1157 while ( np_list != NULL ) {
1158 LDAP_LIST_REMOVE( np_list, np_link );
1160 np_list = LDAP_LIST_NEXT( np_list, np_link );
1161 op->o_tag = LDAP_REQ_DELETE;
1162 op->o_callback = &cb;
1163 cb.sc_response = null_callback;
1165 op->o_req_dn = *np_prev->dn;
1166 op->o_req_ndn = *np_prev->ndn;
1167 op->o_bd->be_delete( op, &rs );
1168 ber_bvfree( np_prev->dn );
1169 ber_bvfree( np_prev->ndn );
1170 op->o_req_dn.bv_val = NULL;
1171 op->o_req_ndn.bv_val = NULL;
1176 if ( op->o_req_dn.bv_val )
1177 ch_free( op->o_req_dn.bv_val );
1178 if ( op->o_req_ndn.bv_val )
1179 ch_free( op->o_req_ndn.bv_val );
1180 filter_free( op->ors_filter );
1181 ch_free( op->ors_filterstr.bv_val );
1193 Modifications* modlist,
1195 struct berval* syncUUID,
1196 struct berval* syncCookie
1199 Backend *be = op->o_bd;
1200 struct berval uuid_bv = {0, NULL};
1204 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
1207 struct berval dn = {0, NULL};
1208 struct berval pdn = {0, NULL};
1209 struct berval ndn = {0, NULL};
1210 struct berval rdn = {0, NULL};
1212 SlapReply rs = {REP_RESULT};
1213 Connection *conn = op->o_conn;
1216 op->o_tag = LDAP_REQ_ADD;
1217 op->o_callback = &cb;
1218 cb.sc_response = null_callback;
1221 ber_dupbv( &dn, &e->e_nname );
1222 ber_dupbv( &pdn, &e->e_nname );
1225 while ( !be_issuffix ( be, &pdn )) {
1226 dnParent( &dn, &pdn );
1227 dn.bv_val = pdn.bv_val;
1228 dn.bv_len = pdn.bv_len;
1233 for ( i = 0; i <= levels; i++ ) {
1234 glue = (Entry*) ch_calloc( 1, sizeof(Entry) );
1235 ber_dupbv( &dn, &e->e_nname );
1239 for ( k = 0; k < j; k++ ) {
1240 dnParent( &dn, &pdn );
1241 dn.bv_val = pdn.bv_val;
1242 dn.bv_len = pdn.bv_len;
1245 dnPrettyNormal( 0, &dn, &pdn, &ndn, op->o_tmpmemctx );
1246 ber_dupbv( &glue->e_name, &pdn );
1247 ber_dupbv( &glue->e_nname, &ndn );
1249 ch_free( pdn.bv_val );
1250 ch_free( ndn.bv_val );
1252 a = ch_calloc( 1, sizeof( Attribute ));
1253 a->a_desc = slap_schema.si_ad_objectClass;
1255 a->a_vals = ch_calloc( 3, sizeof( struct berval ));
1256 ber_str2bv( "top", strlen("top"), 1, &a->a_vals[0] );
1257 ber_str2bv( "glue", strlen("glue"), 1, &a->a_vals[1] );
1258 a->a_vals[2].bv_len = 0;
1259 a->a_vals[2].bv_val = NULL;
1261 a->a_nvals = ch_calloc( 3, sizeof( struct berval ));
1262 ber_str2bv( "top", strlen("top"), 1, &a->a_nvals[0] );
1263 ber_str2bv( "glue", strlen("glue"), 1, &a->a_nvals[1] );
1264 a->a_nvals[2].bv_len = 0;
1265 a->a_nvals[2].bv_val = NULL;
1267 a->a_next = glue->e_attrs;
1270 a = ch_calloc( 1, sizeof( Attribute ));
1271 a->a_desc = slap_schema.si_ad_structuralObjectClass;
1273 a->a_vals = ch_calloc( 2, sizeof( struct berval ));
1274 ber_str2bv( "glue", strlen("glue"), 1, &a->a_vals[0] );
1275 a->a_vals[1].bv_len = 0;
1276 a->a_vals[1].bv_val = NULL;
1278 a->a_nvals = ch_calloc( 2, sizeof( struct berval ));
1279 ber_str2bv( "glue", strlen("glue"), 1, &a->a_nvals[0] );
1280 a->a_nvals[1].bv_len = 0;
1281 a->a_nvals[1].bv_val = NULL;
1283 a->a_next = glue->e_attrs;
1286 if ( !strcmp( e->e_nname.bv_val, glue->e_nname.bv_val )) {
1287 op->o_req_dn = e->e_name;
1288 op->o_req_ndn = e->e_nname;
1290 rc = be->be_add ( op, &rs );
1291 if ( rc == LDAP_SUCCESS )
1292 be_entry_release_w( op, e );
1297 op->o_req_dn = glue->e_name;
1298 op->o_req_ndn = glue->e_nname;
1300 rc = be->be_add ( op, &rs );
1301 if ( rc == LDAP_SUCCESS ) {
1302 be_entry_release_w( op, glue );
1304 /* incl. ALREADY EXIST */
1314 syncrepl_updateCookie(
1319 struct berval *syncCookie
1322 Backend *be = op->o_bd;
1324 Modifications *mlnext;
1326 Modifications *modlist;
1327 Modifications **modtail = &modlist;
1329 struct berval* ocbva = NULL;
1330 struct berval* cnbva = NULL;
1331 struct berval* ssbva = NULL;
1332 struct berval* scbva = NULL;
1337 char txtbuf[SLAP_TEXT_BUFLEN];
1338 size_t textlen = sizeof txtbuf;
1343 struct berval sub_bv = { 0, NULL };
1344 struct berval psubrdn = { 0, NULL };
1347 SlapReply rs = {REP_RESULT};
1349 ocbva = ( struct berval * ) ch_calloc( 4, sizeof( struct berval ));
1350 cnbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval ));
1351 ssbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval ));
1352 scbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval ));
1354 /* update in memory cookie */
1355 if ( si->syncCookie != NULL ) {
1356 ber_bvfree( si->syncCookie );
1358 si->syncCookie = ber_dupbv( NULL, syncCookie );
1359 ber_str2bv( "top", strlen("top"), 1, &ocbva[0] );
1360 ber_str2bv( "subentry", strlen("subentry"), 1, &ocbva[1] );
1361 ber_str2bv( "syncConsumerSubentry",
1362 strlen("syncConsumerSubentry"), 1, &ocbva[2] );
1363 ocbva[3].bv_len = 0;
1364 ocbva[3].bv_val = NULL;
1366 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
1367 mod->sml_op = LDAP_MOD_REPLACE;
1368 mod->sml_next = NULL;
1369 mod->sml_desc = NULL;
1370 ber_str2bv( "objectClass", strlen("objectClass"), 1, &mod->sml_type );
1371 mod->sml_bvalues = ocbva;
1372 mod->sml_nvalues = ocbva;
1374 modtail = &mod->sml_next;
1376 sprintf( substr, "syncrepl%d", si->id );
1377 sprintf( rdnstr, "cn=%s", substr );
1378 ber_str2bv( substr, strlen( substr ), 1, &cnbva[0] );
1379 ber_str2bv( rdnstr, strlen( rdnstr ), 1, &psubrdn );
1380 cnbva[1].bv_len = 0;
1381 cnbva[1].bv_val = NULL;
1382 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
1383 mod->sml_op = LDAP_MOD_REPLACE;
1384 mod->sml_next = NULL;
1385 mod->sml_desc = NULL;
1386 ber_str2bv( "cn", strlen("cn"), 1, &mod->sml_type );
1387 mod->sml_bvalues = cnbva;
1388 mod->sml_nvalues = cnbva;
1390 modtail = &mod->sml_next;
1392 ber_dupbv( &scbva[0], si->syncCookie );
1393 scbva[1].bv_len = 0;
1394 scbva[1].bv_val = NULL;
1395 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
1396 mod->sml_op = LDAP_MOD_REPLACE;
1397 mod->sml_next = NULL;
1398 mod->sml_desc = NULL;
1399 ber_str2bv( "syncreplCookie", strlen("syncreplCookie"),
1400 1, &mod->sml_type );
1401 mod->sml_bvalues = scbva;
1402 mod->sml_nvalues = scbva;
1404 modtail = &mod->sml_next;
1406 ber_str2bv( "{}", strlen("{}"), 1, &ssbva[0] );
1407 ssbva[1].bv_len = 0;
1408 ssbva[1].bv_val = NULL;
1409 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
1410 mod->sml_op = LDAP_MOD_REPLACE;
1411 mod->sml_next = NULL;
1412 mod->sml_desc = NULL;
1413 ber_str2bv( "subtreeSpecification",
1414 strlen("subtreeSpecification"), 1, &mod->sml_type );
1415 mod->sml_bvalues = ssbva;
1416 mod->sml_nvalues = ssbva;
1418 modtail = &mod->sml_next;
1420 rc = slap_mods_check( modlist, 1, &text, txtbuf, textlen, NULL );
1422 if ( rc != LDAP_SUCCESS ) {
1424 LDAP_LOG( OPERATION, ERR,
1425 "syncrepl_updateCookie: mods check (%s)\n", text, 0, 0 );
1427 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods check (%s)\n",
1432 op->o_tag = LDAP_REQ_ADD;
1433 rc = slap_mods_opattrs( op, modlist, modtail,
1434 &text,txtbuf, textlen );
1436 for ( ml = modlist; ml != NULL; ml = mlnext ) {
1437 mlnext = ml->sml_next;
1438 if ( ml->sml_desc == slap_schema.si_ad_structuralObjectClass )
1439 ml->sml_op = LDAP_MOD_REPLACE;
1442 if( rc != LDAP_SUCCESS ) {
1444 LDAP_LOG( OPERATION, ERR,
1445 "syncrepl_updateCookie: mods opattrs (%s)\n", text, 0, 0 );
1447 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods opattrs (%s)\n",
1452 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
1454 build_new_dn( &sub_bv, pdn, &psubrdn );
1455 dnPrettyNormal( NULL, &sub_bv, &e->e_name, &e->e_nname, NULL );
1456 ch_free( sub_bv.bv_val );
1457 ch_free( psubrdn.bv_val );
1461 rc = slap_mods2entry( modlist, &e, 1, 1, &text, txtbuf, textlen );
1463 if( rc != LDAP_SUCCESS ) {
1465 LDAP_LOG( OPERATION, ERR,
1466 "syncrepl_updateCookie: mods2entry (%s)\n", text, 0, 0 );
1468 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods2entry (%s)\n",
1473 cb.sc_response = null_callback;
1476 op->o_callback = &cb;
1477 op->o_req_dn = e->e_name;
1478 op->o_req_ndn = e->e_nname;
1480 /* update persistent cookie */
1481 update_cookie_retry:
1482 op->o_tag = LDAP_REQ_MODIFY;
1483 op->orm_modlist = modlist;
1484 rc = be->be_modify( op, &rs );
1485 if ( rc != LDAP_SUCCESS ) {
1486 if ( rc == LDAP_REFERRAL ||
1487 rc == LDAP_NO_SUCH_OBJECT ) {
1488 op->o_tag = LDAP_REQ_ADD;
1490 rc = be->be_add( op, &rs );
1491 if ( rc != LDAP_SUCCESS ) {
1492 if ( rc == LDAP_ALREADY_EXISTS ) {
1493 goto update_cookie_retry;
1494 } else if ( rc == LDAP_REFERRAL ||
1495 rc == LDAP_NO_SUCH_OBJECT ) {
1497 LDAP_LOG( OPERATION, ERR,
1498 "cookie will be non-persistent\n",
1501 Debug( LDAP_DEBUG_ANY,
1502 "cookie will be non-persistent\n",
1507 LDAP_LOG( OPERATION, ERR,
1508 "be_add failed (%d)\n",
1511 Debug( LDAP_DEBUG_ANY,
1512 "be_add failed (%d)\n",
1517 be_entry_release_w( op, e );
1522 LDAP_LOG( OPERATION, ERR,
1523 "be_modify failed (%d)\n", rc, 0, 0 );
1525 Debug( LDAP_DEBUG_ANY,
1526 "be_modify failed (%d)\n", rc, 0, 0 );
1536 for ( ml = modlist; ml != NULL; ml = mlnext ) {
1537 mlnext = ml->sml_next;
1545 avl_ber_bvfree( void *bv )
1550 if ( ((struct berval *)bv)->bv_val != NULL ) {
1551 ber_memfree ( ((struct berval *)bv)->bv_val );
1553 ber_memfree ( (char *) bv );
1562 syncinfo_t *si = op->o_callback->sc_private;
1565 if ( rs->sr_type != REP_SEARCH ) return LDAP_SUCCESS;
1567 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_syncreplCookie );
1570 si->syncCookie = NULL;
1572 si->syncCookie = ber_dupbv( NULL, &a->a_vals[0] );
1574 return LDAP_SUCCESS;
1583 syncinfo_t *si = op->o_callback->sc_private;
1585 if ( rs->sr_type == REP_SEARCH ) {
1586 si->syncUUID_ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname );
1589 return LDAP_SUCCESS;
1593 nonpresent_callback(
1598 syncinfo_t *si = op->o_callback->sc_private;
1601 struct berval* present_uuid = NULL;
1603 SlapReply rs_cb = {REP_RESULT};
1604 struct nonpresent_entry *np_entry;
1606 if ( rs->sr_type == REP_RESULT ) {
1607 count = avl_free( si->presentlist, avl_ber_bvfree );
1608 si->presentlist = NULL;
1609 return LDAP_SUCCESS;
1610 } else if ( rs->sr_type == REP_SEARCH ) {
1611 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID );
1616 present_uuid = avl_find( si->presentlist, &a->a_vals[0], syncuuid_cmp );
1618 if ( present_uuid == NULL ) {
1619 np_entry = (struct nonpresent_entry *)
1620 ch_calloc( 1, sizeof( struct nonpresent_entry ));
1621 np_entry->dn = ber_dupbv( NULL, &rs->sr_entry->e_name );
1622 np_entry->ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname );
1623 LDAP_LIST_INSERT_HEAD( &si->nonpresentlist, np_entry, np_link );
1625 avl_delete( &si->presentlist,
1626 &a->a_vals[0], syncuuid_cmp );
1628 return LDAP_SUCCESS;
1630 return LDAP_SUCCESS;
1641 syncinfo_t *si = op->o_callback->sc_private;
1643 if ( rs->sr_err != LDAP_SUCCESS &&
1644 rs->sr_err != LDAP_REFERRAL &&
1645 rs->sr_err != LDAP_ALREADY_EXISTS &&
1646 rs->sr_err != LDAP_NO_SUCH_OBJECT ) {
1648 LDAP_LOG( OPERATION, ERR,
1649 "null_callback : error code 0x%x\n",
1652 Debug( LDAP_DEBUG_ANY,
1653 "null_callback : error code 0x%x\n",
1657 return LDAP_SUCCESS;
1662 str2clist( char ***out, char *in, const char *brkstr )
1671 /* find last element in list */
1672 for (i = 0; *out && *out[i]; i++);
1674 /* protect the input string from strtok */
1675 str = ch_strdup( in );
1677 /* Count words in string */
1679 for ( s = str; *s; s++ ) {
1680 if ( strchr( brkstr, *s ) != NULL ) {
1685 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
1687 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
1689 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
1691 *new = ch_strdup( s );