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"
39 syncrepl_del_nonpresent( LDAP *, Operation * );
41 /* callback functions */
42 static int cookie_callback( struct slap_op *, struct slap_rep * );
43 static int dn_callback( struct slap_op *, struct slap_rep * );
44 static int nonpresent_callback( struct slap_op *, struct slap_rep * );
45 static int null_callback( struct slap_op *, struct slap_rep * );
46 static int contextcsn_callback( Operation*, SlapReply* );
48 static AttributeDescription **add_descs;
49 static AttributeDescription **add_descs_lastmod;
50 static AttributeDescription **del_descs;
51 static AttributeDescription **del_descs_lastmod;
53 struct runqueue_s syncrepl_rq;
58 add_descs = ch_malloc( 2 * sizeof( AttributeDescription * ));
59 add_descs[0] = slap_schema.si_ad_objectClass;
62 add_descs_lastmod = ch_malloc( 7 * sizeof( AttributeDescription * ));
63 add_descs_lastmod[0] = slap_schema.si_ad_objectClass;
64 add_descs_lastmod[1] = slap_schema.si_ad_creatorsName;
65 add_descs_lastmod[2] = slap_schema.si_ad_modifiersName;
66 add_descs_lastmod[3] = slap_schema.si_ad_createTimestamp;
67 add_descs_lastmod[4] = slap_schema.si_ad_modifyTimestamp;
68 add_descs_lastmod[5] = slap_schema.si_ad_entryCSN;
69 add_descs_lastmod[6] = NULL;
71 del_descs = ch_malloc( 9 * sizeof( AttributeDescription * ));
72 del_descs[0] = slap_schema.si_ad_structuralObjectClass;
73 del_descs[1] = slap_schema.si_ad_subschemaSubentry;
74 del_descs[2] = slap_schema.si_ad_hasSubordinates;
75 del_descs[3] = slap_schema.si_ad_creatorsName;
76 del_descs[4] = slap_schema.si_ad_modifiersName;
77 del_descs[5] = slap_schema.si_ad_createTimestamp;
78 del_descs[6] = slap_schema.si_ad_modifyTimestamp;
79 del_descs[7] = slap_schema.si_ad_entryCSN;
82 del_descs_lastmod = ch_malloc( 4 * sizeof( AttributeDescription * ));
83 del_descs_lastmod[0] = slap_schema.si_ad_structuralObjectClass;
84 del_descs_lastmod[1] = slap_schema.si_ad_subschemaSubentry;
85 del_descs_lastmod[2] = slap_schema.si_ad_hasSubordinates;
86 del_descs_lastmod[3] = NULL;
102 BerElement *sync_ber = NULL;
103 struct berval *sync_bvalp = NULL;
107 struct timeval timeout;
109 /* setup LDAP SYNC control */
110 sync_ber = ber_alloc_t( LBER_USE_DER );
111 ber_set_option( sync_ber, LBER_OPT_BER_MEMCTX, NULL );
113 if ( si->syncCookie ) {
114 ber_printf( sync_ber, "{eO}", abs(si->type), si->syncCookie );
116 ber_printf( sync_ber, "{e}", abs(si->type) );
119 if ( ber_flatten( sync_ber, &sync_bvalp ) == LBER_ERROR ) {
120 ber_free( sync_ber, 1 );
123 ber_free( sync_ber, 1 );
125 ctrls = (LDAPControl**) sl_calloc( 3, sizeof(LDAPControl*), NULL );
127 c[0].ldctl_oid = LDAP_CONTROL_SYNC;
128 c[0].ldctl_value = (*sync_bvalp);
129 c[0].ldctl_iscritical = si->type < 0;
133 c[1].ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
134 c[1].ldctl_value.bv_val = si->authzId;
135 c[1].ldctl_value.bv_len = strlen( si->authzId );
136 c[1].ldctl_iscritical = 1;
144 err = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, ctrls );
146 ber_bvfree( sync_bvalp );
149 if ( err != LDAP_OPT_SUCCESS )
150 fprintf( stderr, "Could not set controls : %d\n", err );
152 timeout.tv_sec = si->tlimit > 0 ? si->tlimit : 1;
154 rc = ldap_search_ext( ld, si->base, si->scope, si->filterstr,
155 si->attrs, si->attrsonly, sctrls, cctrls,
156 si->tlimit < 0 ? NULL : &timeout,
157 si->slimit, msgidp );
167 struct re_s* rtask = arg;
168 syncinfo_t *si = ( syncinfo_t * ) rtask->arg;
169 Backend *be = si->be;
171 SlapReply rs = {REP_RESULT};
174 LDAPControl **sctrls = NULL;
175 LDAPControl **rctrls = NULL;
176 LDAPControl *rctrlp = NULL;
177 BerElement *sync_ber = NULL;
178 struct berval *sync_bvalp = NULL;
180 BerElement *ctrl_ber = NULL;
181 BerElement *res_ber = NULL;
184 LDAPMessage *res = NULL;
185 LDAPMessage *msg = NULL;
189 int nresponses, nreferences, nextended, npartial;
190 int nresponses_psearch;
192 int cancel_msgid = -1;
194 struct berval *retdata = NULL;
196 int sync_info_arrived = 0;
200 struct berval syncUUID = { 0, NULL };
201 struct berval syncCookie = { 0, NULL };
202 struct berval syncCookie_req = { 0, NULL };
207 int syncinfo_arrived = 0;
208 int cancel_response = 0;
211 AttributeDescription** descs = NULL;
223 struct berval base_bv = { 0, NULL };
224 struct berval pbase = { 0, NULL };
225 struct berval nbase = { 0, NULL };
226 struct berval sub_bv = { 0, NULL };
227 struct berval psubrdn = { 0, NULL };
228 struct berval nsubrdn = { 0, NULL };
229 struct berval psub = { 0, NULL };
230 struct berval nsub = { 0, NULL };
232 Modifications *modlist = NULL;
233 Modifications *ml, *mlnext;
234 char *def_filter_str = NULL;
240 LDAP_LOG ( OPERATION, DETAIL1, "do_syncrepl\n", 0, 0, 0 );
242 Debug( LDAP_DEBUG_TRACE, "=>do_syncrepl\n", 0, 0, 0 );
248 if ( abs(si->type) != LDAP_SYNC_REFRESH_ONLY &&
249 abs(si->type) != LDAP_SYNC_REFRESH_AND_PERSIST ) {
253 si->sync_mode = LDAP_SYNC_STATE_MODE;
255 /* Init connection to master */
257 rc = ldap_initialize( &ld, si->provideruri );
258 if ( rc != LDAP_SUCCESS ) {
260 LDAP_LOG( OPERATION, ERR, "do_syncrepl: "
261 "ldap_initialize failed (%s)\n",
262 si->provideruri, 0, 0 );
264 Debug( LDAP_DEBUG_ANY, "do_syncrepl: "
265 "ldap_initialize failed (%s)\n",
266 si->provideruri, 0, 0 );
270 op.o_protocol = LDAP_VERSION3;
271 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &op.o_protocol );
276 rc = ldap_start_tls_s( ld, NULL, NULL );
277 if( rc != LDAP_SUCCESS ) {
279 LDAP_LOG ( OPERATION, ERR, "do_syncrepl: "
280 "%s: ldap_start_tls failed (%d)\n",
281 si->tls == TLS_CRITICAL ? "Error" : "Warning",
284 Debug( LDAP_DEBUG_ANY,
285 "%s: ldap_start_tls failed (%d)\n",
286 si->tls == TLS_CRITICAL ? "Error" : "Warning",
289 if( si->tls == TLS_CRITICAL )
294 if ( si->bindmethod == LDAP_AUTH_SASL ) {
295 #ifdef HAVE_CYRUS_SASL
298 if ( si->secprops != NULL ) {
299 int err = ldap_set_option( ld,
300 LDAP_OPT_X_SASL_SECPROPS, si->secprops);
302 if( err != LDAP_OPT_SUCCESS ) {
304 LDAP_LOG ( OPERATION, ERR, "do_bind: Error: "
305 "ldap_set_option(%s,SECPROPS,\"%s\") failed!\n",
306 si->provideruri, si->secprops, 0 );
308 Debug( LDAP_DEBUG_ANY, "Error: ldap_set_option "
309 "(%s,SECPROPS,\"%s\") failed!\n",
310 si->provideruri, si->secprops, NULL );
316 defaults = lutil_sasl_defaults( ld,
323 rc = ldap_sasl_interactive_bind_s( ld,
331 if ( rc != LDAP_SUCCESS ) {
333 LDAP_LOG ( OPERATION, ERR, "do_syncrepl: "
334 "ldap_sasl_interactive_bind_s failed (%d)\n",
337 Debug( LDAP_DEBUG_ANY, "do_syncrepl: "
338 "ldap_sasl_interactive_bind_s failed (%d)\n",
343 #else /* HAVE_CYRUS_SASL */
344 fprintf( stderr, "not compiled with SASL support\n" );
348 rc = ldap_bind_s( ld, si->binddn, si->passwd, si->bindmethod );
349 if ( rc != LDAP_SUCCESS ) {
351 LDAP_LOG ( OPERATION, ERR, "do_syncrepl: "
352 "ldap_bind_s failed (%d)\n", rc, 0, 0 );
354 Debug( LDAP_DEBUG_ANY, "do_syncrepl: "
355 "ldap_bind_s failed (%d)\n", rc, 0, 0 );
361 /* set thread context in syncinfo */
364 /* set memory context */
365 #define SLAB_SIZE 1048576
367 memctx = sl_mem_create( memsiz, ctx );
368 op.o_tmpmemctx = memctx;
369 op.o_tmpmfuncs = &sl_mfuncs;
372 op.o_tag = LDAP_REQ_SEARCH;
373 op.o_dn = si->updatedn;
374 op.o_ndn = si->updatedn;
376 op.o_time = slap_get_time();
377 op.o_managedsait = 1;
378 op.o_threadctx = si->ctx;
381 op.o_connid = op.o_conn->c_connid;
382 op.ors_scope = LDAP_SCOPE_BASE;
383 op.ors_deref = LDAP_DEREF_NEVER;
386 op.ors_attrsonly = 0;
388 op.ors_filter = str2filter( def_filter_str = "(objectClass=*)" );
389 ber_str2bv( def_filter_str, strlen( def_filter_str ), 1,
393 conn.c_send_ldap_result = slap_send_ldap_result;
394 conn.c_send_search_entry = slap_send_search_entry;
395 conn.c_send_search_reference = slap_send_search_reference;
397 /* get syncrepl cookie of shadow replica from subentry */
398 ber_str2bv( si->base, strlen(si->base), 1, &base_bv );
399 dnPrettyNormal( 0, &base_bv, &pbase, &nbase, op.o_tmpmemctx );
401 sprintf( substr, "cn=syncrepl%d", si->id );
402 ber_str2bv( substr, strlen(substr), 1, &sub_bv );
403 dnPrettyNormal( 0, &sub_bv, &psubrdn, &nsubrdn, op.o_tmpmemctx );
405 build_new_dn( &op.o_req_dn, &pbase, &psubrdn );
406 build_new_dn( &op.o_req_ndn, &nbase, &nsubrdn );
408 ch_free( base_bv.bv_val );
409 ch_free( pbase.bv_val );
410 ch_free( nbase.bv_val );
411 ch_free( sub_bv.bv_val );
412 ch_free( psubrdn.bv_val );
413 ch_free( nsubrdn.bv_val );
415 /* set callback function */
416 cb.sc_response = cookie_callback;
419 /* search subentry to retrieve cookie */
420 si->syncCookie = NULL;
421 be->be_search( &op, &rs );
423 ber_dupbv( &syncCookie_req, si->syncCookie );
425 ch_free( op.o_req_dn.bv_val );
426 ch_free( op.o_req_ndn.bv_val );
427 filter_free( op.ors_filter );
428 ch_free( op.ors_filterstr.bv_val );
430 psub = be->be_nsuffix[0];
432 /* Delete Attributes */
433 if ( si->lastmod == LASTMOD_REQ ) {
434 descs = del_descs_lastmod;
439 for ( i = 0; descs[i] != NULL; i++ ) {
440 for ( j = 0; si->attrs[j] != NULL; j++ ) {
441 if ( !strcmp( si->attrs[j], descs[i]->ad_cname.bv_val )) {
442 ch_free( si->attrs[j] );
443 for ( k = j; si->attrs[k] != NULL; k++ ) {
444 si->attrs[k] = si->attrs[k+1];
452 for ( n = 0; si->attrs[ n ] != NULL; n++ ) ;
454 if ( si->lastmod == LASTMOD_REQ ) {
455 descs = add_descs_lastmod;
460 for ( i = 0; descs[i] != NULL; i++ ) {
461 tmp = ( char ** ) ch_realloc( si->attrs,
462 ( n + 2 ) * sizeof( char * ));
465 LDAP_LOG( OPERATION, ERR, "out of memory\n", 0,0,0 );
467 Debug( LDAP_DEBUG_ANY, "out of memory\n", 0,0,0 );
471 si->attrs[ n++ ] = ch_strdup ( descs[i]->ad_cname.bv_val );
472 si->attrs[ n ] = NULL;
475 rc = ldap_sync_search( si, ld, NULL, NULL, &msgid );
476 if( rc != LDAP_SUCCESS ) {
477 fprintf( stderr, "syncrepl: ldap_search_ext: %s (%d)\n",
478 ldap_err2string( rc ), rc );
482 while (( rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ONE, NULL, &res )) > 0 ) {
484 for ( msg = ldap_first_message( ld, res );
486 msg = ldap_next_message( ld, msg ) )
488 syncCookie.bv_len = 0; syncCookie.bv_val = NULL;
489 switch( ldap_msgtype( msg ) ) {
490 case LDAP_RES_SEARCH_ENTRY:
491 entry = syncrepl_message_to_entry( si, ld, &op, msg,
492 &modlist, &syncstate, &syncUUID, &syncCookie );
493 rc_efree = syncrepl_entry( si, ld, &op, entry, modlist,
494 syncstate, &syncUUID, &syncCookie, !syncinfo_arrived );
495 if ( syncCookie.bv_len ) {
496 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie );
500 for ( ml = modlist; ml != NULL; ml = mlnext ) {
501 mlnext = ml->sml_next;
506 case LDAP_RES_SEARCH_REFERENCE:
508 LDAP_LOG( OPERATION, ERR,
509 "do_syncrepl : reference received\n", 0, 0, 0 );
511 Debug( LDAP_DEBUG_ANY,
512 "do_syncrepl : reference received\n", 0, 0, 0 );
516 case LDAP_RES_SEARCH_RESULT:
517 ldap_parse_result( ld, msg, &err, NULL, NULL, NULL, &rctrls, 0 );
520 ctrl_ber = ber_alloc_t( LBER_USE_DER );
521 ber_set_option( ctrl_ber, LBER_OPT_BER_MEMCTX, &op.o_tmpmemctx );
522 ber_write( ctrl_ber, rctrlp->ldctl_value.bv_val, rctrlp->ldctl_value.bv_len, 0 );
523 ber_reset( ctrl_ber, 1 );
525 ber_scanf( ctrl_ber, "{" /*"}"*/);
526 if ( ber_peek_tag( ctrl_ber, &len )
527 == LDAP_SYNC_TAG_COOKIE ) {
528 ber_scanf( ctrl_ber, "o", &syncCookie );
531 value_match( &match, slap_schema.si_ad_entryCSN,
532 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
533 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
534 &syncCookie_req, &syncCookie, &text );
535 if (si->type == LDAP_SYNC_REFRESH_AND_PERSIST) {
536 if ( cancel_response ) {
537 if ( syncCookie.bv_len && match < 0) {
538 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie );
541 ber_free( ctrl_ber, 1 );
546 ber_free( ctrl_ber, 1 );
550 if ( syncCookie.bv_len && match < 0 ) {
551 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie);
553 if ( si->sync_mode == LDAP_SYNC_STATE_MODE && match < 0 ) {
554 syncrepl_del_nonpresent( ld, &op );
557 ber_free( ctrl_ber, 1 );
562 case LDAP_RES_INTERMEDIATE:
563 rc = ldap_parse_intermediate( ld, msg,
564 &retoid, &retdata, NULL, 0 );
565 if ( !rc && !strcmp( retoid, LDAP_SYNC_INFO ) ) {
566 sync_info_arrived = 1;
567 res_ber = ber_init( retdata );
568 ber_scanf( res_ber, "{e" /*"}"*/, &syncstate );
570 if ( ber_peek_tag( res_ber, &len )
571 == LDAP_SYNC_TAG_COOKIE ) {
572 ber_scanf( res_ber, /*"{"*/ "o}", &syncCookie );
574 if ( syncstate == LDAP_SYNC_NEW_COOKIE ) {
576 LDAP_LOG( OPERATION, ERR,
577 "do_syncrepl : cookie required\n", 0, 0, 0 );
579 Debug( LDAP_DEBUG_ANY,
580 "do_syncrepl : cookie required\n", 0, 0, 0 );
585 value_match( &match, slap_schema.si_ad_entryCSN,
586 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
587 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
588 &syncCookie_req, &syncCookie, &text );
590 if ( syncCookie.bv_len && match < 0 ) {
591 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie);
594 if ( syncstate == LDAP_SYNC_STATE_MODE_DONE ) {
596 syncrepl_del_nonpresent( ld, &op );
598 si->sync_mode = LDAP_SYNC_LOG_MODE;
599 } else if ( syncstate == LDAP_SYNC_LOG_MODE_DONE ) {
600 si->sync_mode = LDAP_SYNC_PERSIST_MODE;
601 } else if ( syncstate == LDAP_SYNC_REFRESH_DONE ) {
602 si->sync_mode = LDAP_SYNC_PERSIST_MODE;
603 } else if ( syncstate != LDAP_SYNC_NEW_COOKIE ||
604 syncstate != LDAP_SYNC_LOG_MODE_DONE ) {
606 LDAP_LOG( OPERATION, ERR,
607 "do_syncrepl : unknown sync info\n", 0, 0, 0 );
609 Debug( LDAP_DEBUG_ANY,
610 "do_syncrepl : unknown sync info\n", 0, 0, 0 );
614 ldap_memfree( retoid );
615 ber_bvfree( retdata );
616 ber_free( res_ber, 1 );
620 LDAP_LOG( OPERATION, ERR,"do_syncrepl :"
621 " unknown intermediate "
622 "response\n", 0, 0, 0 );
624 Debug( LDAP_DEBUG_ANY, "do_syncrepl : "
625 "unknown intermediate response (%d)\n",
628 ldap_memfree( retoid );
629 ber_bvfree( retdata );
635 LDAP_LOG( OPERATION, ERR, "do_syncrepl : "
636 "unknown message\n", 0, 0, 0 );
638 Debug( LDAP_DEBUG_ANY, "do_syncrepl : "
639 "unknown message\n", 0, 0, 0 );
650 LDAP_LOG( OPERATION, ERR,
651 "do_syncrepl : unknown result\n", 0, 0, 0 );
653 Debug( LDAP_DEBUG_ANY,
654 "do_syncrepl : unknown result\n", 0, 0, 0 );
659 if ( syncCookie.bv_val )
660 ch_free( syncCookie.bv_val );
661 if ( syncCookie_req.bv_val )
662 ch_free( syncCookie_req.bv_val );
663 if ( syncUUID.bv_val )
664 ch_free( syncUUID.bv_val );
670 ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
671 ldap_pvt_runqueue_stoptask( &syncrepl_rq, rtask );
672 if ( si->type == LDAP_SYNC_REFRESH_ONLY ) {
673 ldap_pvt_runqueue_resched( &syncrepl_rq, rtask );
675 ldap_pvt_runqueue_remove( &syncrepl_rq, rtask );
677 ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
683 syncrepl_message_to_entry(
688 Modifications **modlist,
690 struct berval *syncUUID,
691 struct berval *syncCookie
695 BerElement *ber = NULL;
697 struct berval bv = {0, NULL};
700 Modifications **modtail = modlist;
701 Backend *be = op->o_bd;
704 char txtbuf[SLAP_TEXT_BUFLEN];
705 size_t textlen = sizeof txtbuf;
707 struct berval **bvals = NULL;
709 struct berval bdn = {0, NULL};
711 struct berval empty_bv = { 0, NULL };
717 LDAPControl** rctrls = NULL;
718 BerElement* ctrl_ber;
722 Modifications *prevml = NULL;
723 Modifications *nextml = NULL;
724 Modifications *ml = NULL;
725 AttributeDescription** descs;
730 if ( ldap_msgtype( msg ) != LDAP_RES_SEARCH_ENTRY ) {
732 LDAP_LOG( OPERATION, ERR,
733 "Message type should be entry (%d)", ldap_msgtype( msg ), 0, 0 );
735 Debug( LDAP_DEBUG_ANY,
736 "Message type should be entry (%d)", ldap_msgtype( msg ), 0, 0 );
741 op->o_tag = LDAP_REQ_ADD;
743 rc = ldap_get_dn_ber( ld, msg, &ber, &bdn );
745 if ( rc != LDAP_SUCCESS ) {
747 LDAP_LOG( OPERATION, ERR,
748 "syncrepl_message_to_entry : dn get failed (%d)", rc, 0, 0 );
750 Debug( LDAP_DEBUG_ANY,
751 "syncrepl_message_to_entry : dn get failed (%d)", rc, 0, 0 );
756 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
757 dnPrettyNormal( NULL, &bdn, &e->e_name, &e->e_nname, NULL );
761 while ( ber_remaining( ber ) ) {
762 tag = ber_scanf( ber, "{mW}", &tmp.sml_type, &tmp.sml_values );
764 if ( tag == LBER_ERROR ) break;
765 if ( tmp.sml_type.bv_val == NULL ) break;
767 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
769 mod->sml_op = LDAP_MOD_REPLACE;
770 mod->sml_next = NULL;
771 mod->sml_desc = NULL;
772 mod->sml_type = tmp.sml_type;
773 mod->sml_bvalues = tmp.sml_bvalues;
774 mod->sml_nvalues = tmp.sml_bvalues;
777 modtail = &mod->sml_next;
780 if ( ber_scanf( ber, "}") == LBER_ERROR ) {
782 LDAP_LOG( OPERATION, ERR,
783 "syncrepl_message_to_entry: ber_scanf failed\n", 0, 0, 0 );
785 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: ber_scanf failed\n",
792 tmpber = ldap_get_message_ber( msg );
793 ber = ber_dup( tmpber );
795 ber_scanf( ber, "{xx" );
797 rc = ldap_int_get_controls( ber, &rctrls );
799 if ( rc != LDAP_SUCCESS ) {
801 LDAP_LOG( OPERATION, ERR,
802 "syncrepl_message_to_entry : control get failed (%d)", rc, 0, 0 );
804 Debug( LDAP_DEBUG_ANY,
805 "syncrepl_message_to_entry : control get failed (%d)", rc, 0, 0 );
812 ctrl_ber = ber_alloc_t( LBER_USE_DER );
813 ber_set_option( ctrl_ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
814 ber_write( ctrl_ber, rctrlp->ldctl_value.bv_val, rctrlp->ldctl_value.bv_len, 0 );
815 ber_reset( ctrl_ber, 1 );
816 ber_scanf( ctrl_ber, "{eo", syncstate, syncUUID );
817 if ( ber_peek_tag( ctrl_ber, &len ) == LDAP_SYNC_TAG_COOKIE ) {
818 ber_scanf( ctrl_ber, "o}", syncCookie );
820 ber_free( ctrl_ber, 1 );
823 LDAP_LOG( OPERATION, ERR,"syncrepl_message_to_entry : "
824 " rctrls absent\n", 0, 0, 0 );
826 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry :"
827 " rctrls absent\n", 0, 0, 0 );
831 if ( *syncstate == LDAP_SYNC_PRESENT ) {
834 } else if ( *syncstate == LDAP_SYNC_DELETE ) {
838 if ( *modlist == NULL ) {
840 LDAP_LOG( OPERATION, ERR,
841 "syncrepl_message_to_entry: no attributes\n", 0, 0, 0 );
843 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: no attributes\n",
849 while ( ml != NULL ) {
850 AttributeDescription *ad = NULL;
851 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, &text );
853 if( rc != LDAP_SUCCESS ) {
861 if ( si->lastmod == LASTMOD_REQ ) {
862 descs = del_descs_lastmod;
867 for ( i = 0; descs[i] != NULL; i++ ) {
868 if ( ad == descs[i] ) {
869 if ( prevml == NULL ) {
870 modlist = &ml->sml_next;
873 prevml->sml_next = ml->sml_next;
875 slap_mod_free( &ml->sml_mod, 0 );
876 nextml = ml->sml_next;
886 rc = slap_mods_check( *modlist, 1, &text, txtbuf, textlen, NULL );
888 if ( rc != LDAP_SUCCESS ) {
890 LDAP_LOG( OPERATION, ERR,
891 "syncrepl_message_to_entry: mods check (%s)\n", text, 0, 0 );
893 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods check (%s)\n",
899 rc = slap_mods_opattrs( op, *modlist, modtail,
900 &text,txtbuf, textlen );
902 if( rc != LDAP_SUCCESS ) {
904 LDAP_LOG( OPERATION, ERR,
905 "syncrepl_message_to_entry: mods opattrs (%s)\n", text, 0, 0 );
907 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods opattrs (%s)\n",
913 rc = slap_mods2entry( *modlist, &e, 1, 1, &text, txtbuf, textlen);
914 if( rc != LDAP_SUCCESS ) {
916 LDAP_LOG( OPERATION, ERR,
917 "syncrepl_message_to_entry: mods2entry (%s)\n", text, 0, 0 );
919 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods2entry (%s)\n",
932 syncuuid_cmp( const void* v_uuid1, const void* v_uuid2 )
934 const struct berval *uuid1 = v_uuid1;
935 const struct berval *uuid2 = v_uuid2;
936 int rc = uuid1->bv_len - uuid2->bv_len;
938 return ( strcmp( uuid1->bv_val, uuid2->bv_val ) );
947 Modifications* modlist,
949 struct berval* syncUUID,
950 struct berval* syncCookie,
954 Backend *be = op->o_bd;
956 struct berval csn_bv = {0, NULL};
957 struct berval *syncuuid_bv = NULL;
958 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
960 SlapReply rs = {REP_RESULT};
961 int rc = LDAP_SUCCESS;
963 struct berval base_bv = {0, NULL};
971 ( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD )) {
972 syncuuid_bv = ber_dupbv( NULL, syncUUID );
973 avl_insert( &si->presentlist, (caddr_t) syncuuid_bv,
974 syncuuid_cmp, avl_dup_error );
977 if ( syncstate == LDAP_SYNC_PRESENT ) {
984 filterstr = (char *) sl_malloc( strlen("entryUUID=") + syncUUID->bv_len + 1,
986 strcpy( filterstr, "entryUUID=" );
987 strcat( filterstr, syncUUID->bv_val );
990 si->syncUUID = syncUUID;
991 si->syncUUID_ndn = NULL;
993 filter = str2filter( filterstr );
994 ber_str2bv( filterstr, strlen(filterstr), 1, &op->ors_filterstr );
995 ch_free( filterstr );
996 op->ors_filter = filter;
997 op->ors_scope = LDAP_SCOPE_SUBTREE;
999 /* get syncrepl cookie of shadow replica from subentry */
1000 ber_str2bv( si->base, strlen(si->base), 1, &base_bv );
1001 dnPrettyNormal( 0, &base_bv, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
1002 ch_free( base_bv.bv_val );
1004 /* set callback function */
1005 op->o_callback = &cb;
1006 cb.sc_response = dn_callback;
1009 si->syncUUID_ndn = NULL;
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 );
1058 if ( rc != LDAP_SUCCESS ) {
1060 LDAP_LOG( OPERATION, ERR,
1061 "syncrepl_entry : be_modify failed (%d)\n",
1064 Debug( LDAP_DEBUG_ANY,
1065 "syncrepl_entry : be_modify failed (%d)\n",
1071 } else if ( rc == LDAP_REFERRAL ||
1072 rc == LDAP_NO_SUCH_OBJECT ) {
1073 syncrepl_add_glue( si, ld, op, e,
1075 syncUUID, syncCookie);
1080 LDAP_LOG( OPERATION, ERR,
1081 "syncrepl_entry : be_add failed (%d)\n",
1084 Debug( LDAP_DEBUG_ANY,
1085 "syncrepl_entry : be_add failed (%d)\n",
1093 be_entry_release_w( op, e );
1098 LDAP_LOG( OPERATION, ERR,
1099 "syncrepl_entry : be_search failed (%d)\n", rc, 0, 0 );
1101 Debug( LDAP_DEBUG_ANY,
1102 "syncrepl_entry : be_search failed (%d)\n", rc, 0, 0 );
1108 case LDAP_SYNC_DELETE :
1109 if ( si->sync_mode == LDAP_SYNC_LOG_MODE ) {
1110 op->o_req_dn = *si->syncUUID_ndn;
1111 op->o_req_ndn = *si->syncUUID_ndn;
1112 op->o_tag = LDAP_REQ_DELETE;
1113 rc = be->be_delete( op, &rs );
1115 /* Already deleted otherwise */
1120 LDAP_LOG( OPERATION, ERR,
1121 "syncrepl_entry : unknown syncstate\n", 0, 0, 0 );
1123 Debug( LDAP_DEBUG_ANY,
1124 "syncrepl_entry : unknown syncstate\n", 0, 0, 0 );
1131 syncrepl_del_nonpresent(
1136 Backend* be = op->o_bd;
1137 syncinfo_t *si = op->o_si;
1139 struct berval base_bv = {0, NULL};
1141 SlapReply rs = {REP_RESULT};
1142 struct berval filterstr_bv = {0, NULL};
1143 struct nonpresent_entry *np_list, *np_prev;
1145 ber_str2bv( si->base, strlen(si->base), 1, &base_bv );
1146 dnPrettyNormal(0, &base_bv, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
1147 ch_free( base_bv.bv_val );
1149 filter = str2filter( si->filterstr );
1151 cb.sc_response = nonpresent_callback;
1154 op->o_callback = &cb;
1155 op->o_tag = LDAP_REQ_SEARCH;
1156 op->ors_scope = si->scope;
1157 op->ors_deref = LDAP_DEREF_NEVER;
1160 op->ors_attrsonly = 0;
1161 op->ors_attrs = NULL;
1162 op->ors_filter = filter;
1163 ber_str2bv( si->filterstr, strlen( si->filterstr ), 1, &op->ors_filterstr );
1165 be->be_search( op, &rs );
1167 if ( !LDAP_LIST_EMPTY( &si->nonpresentlist ) ) {
1168 np_list = LDAP_LIST_FIRST( &si->nonpresentlist );
1169 while ( np_list != NULL ) {
1170 LDAP_LIST_REMOVE( np_list, np_link );
1172 np_list = LDAP_LIST_NEXT( np_list, np_link );
1173 op->o_tag = LDAP_REQ_DELETE;
1174 op->o_callback = &cb;
1175 cb.sc_response = null_callback;
1177 op->o_req_dn = *np_prev->dn;
1178 op->o_req_ndn = *np_prev->ndn;
1179 op->o_bd->be_delete( op, &rs );
1180 ber_bvfree( np_prev->dn );
1181 ber_bvfree( np_prev->ndn );
1182 op->o_req_dn.bv_val = NULL;
1183 op->o_req_ndn.bv_val = NULL;
1188 if ( op->o_req_dn.bv_val )
1189 ch_free( op->o_req_dn.bv_val );
1190 if ( op->o_req_ndn.bv_val )
1191 ch_free( op->o_req_ndn.bv_val );
1192 filter_free( op->ors_filter );
1193 ch_free( op->ors_filterstr.bv_val );
1205 Modifications* modlist,
1207 struct berval* syncUUID,
1208 struct berval* syncCookie
1211 Backend *be = op->o_bd;
1212 struct berval uuid_bv = {0, NULL};
1216 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
1219 struct berval dn = {0, NULL};
1220 struct berval pdn = {0, NULL};
1221 struct berval ndn = {0, NULL};
1222 struct berval rdn = {0, NULL};
1224 SlapReply rs = {REP_RESULT};
1225 Connection *conn = op->o_conn;
1228 op->o_tag = LDAP_REQ_ADD;
1229 op->o_callback = &cb;
1230 cb.sc_response = null_callback;
1233 ber_dupbv( &dn, &e->e_nname );
1234 ber_dupbv( &pdn, &e->e_nname );
1237 while ( !be_issuffix ( be, &pdn )) {
1238 dnParent( &dn, &pdn );
1239 dn.bv_val = pdn.bv_val;
1240 dn.bv_len = pdn.bv_len;
1245 for ( i = 0; i <= levels; i++ ) {
1246 glue = (Entry*) ch_calloc( 1, sizeof(Entry) );
1247 ber_dupbv( &dn, &e->e_nname );
1251 for ( k = 0; k < j; k++ ) {
1252 dnParent( &dn, &pdn );
1253 dn.bv_val = pdn.bv_val;
1254 dn.bv_len = pdn.bv_len;
1257 dnPrettyNormal( 0, &dn, &pdn, &ndn, op->o_tmpmemctx );
1258 ber_dupbv( &glue->e_name, &pdn );
1259 ber_dupbv( &glue->e_nname, &ndn );
1261 ch_free( pdn.bv_val );
1262 ch_free( ndn.bv_val );
1264 a = ch_calloc( 1, sizeof( Attribute ));
1265 a->a_desc = slap_schema.si_ad_objectClass;
1267 a->a_vals = ch_calloc( 3, sizeof( struct berval ));
1268 ber_str2bv( "top", strlen("top"), 1, &a->a_vals[0] );
1269 ber_str2bv( "glue", strlen("glue"), 1, &a->a_vals[1] );
1270 a->a_vals[2].bv_len = 0;
1271 a->a_vals[2].bv_val = NULL;
1273 a->a_nvals = ch_calloc( 3, sizeof( struct berval ));
1274 ber_str2bv( "top", strlen("top"), 1, &a->a_nvals[0] );
1275 ber_str2bv( "glue", strlen("glue"), 1, &a->a_nvals[1] );
1276 a->a_nvals[2].bv_len = 0;
1277 a->a_nvals[2].bv_val = NULL;
1279 a->a_next = glue->e_attrs;
1282 a = ch_calloc( 1, sizeof( Attribute ));
1283 a->a_desc = slap_schema.si_ad_structuralObjectClass;
1285 a->a_vals = ch_calloc( 2, sizeof( struct berval ));
1286 ber_str2bv( "glue", strlen("glue"), 1, &a->a_vals[0] );
1287 a->a_vals[1].bv_len = 0;
1288 a->a_vals[1].bv_val = NULL;
1290 a->a_nvals = ch_calloc( 2, sizeof( struct berval ));
1291 ber_str2bv( "glue", strlen("glue"), 1, &a->a_nvals[0] );
1292 a->a_nvals[1].bv_len = 0;
1293 a->a_nvals[1].bv_val = NULL;
1295 a->a_next = glue->e_attrs;
1298 if ( !strcmp( e->e_nname.bv_val, glue->e_nname.bv_val )) {
1299 op->o_req_dn = e->e_name;
1300 op->o_req_ndn = e->e_nname;
1302 rc = be->be_add ( op, &rs );
1303 if ( rc == LDAP_SUCCESS )
1304 be_entry_release_w( op, e );
1309 op->o_req_dn = glue->e_name;
1310 op->o_req_ndn = glue->e_nname;
1312 rc = be->be_add ( op, &rs );
1313 if ( rc == LDAP_SUCCESS ) {
1314 be_entry_release_w( op, glue );
1316 /* incl. ALREADY EXIST */
1326 syncrepl_updateCookie(
1331 struct berval *syncCookie
1334 Backend *be = op->o_bd;
1336 Modifications *mlnext;
1338 Modifications *modlist;
1339 Modifications **modtail = &modlist;
1341 struct berval* ocbva = NULL;
1342 struct berval* cnbva = NULL;
1343 struct berval* ssbva = NULL;
1344 struct berval* scbva = NULL;
1349 char txtbuf[SLAP_TEXT_BUFLEN];
1350 size_t textlen = sizeof txtbuf;
1355 struct berval sub_bv = { 0, NULL };
1356 struct berval psubrdn = { 0, NULL };
1359 SlapReply rs = {REP_RESULT};
1361 ocbva = ( struct berval * ) ch_calloc( 4, sizeof( struct berval ));
1362 cnbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval ));
1363 ssbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval ));
1364 scbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval ));
1366 /* update in memory cookie */
1367 if ( si->syncCookie != NULL ) {
1368 ber_bvfree( si->syncCookie );
1370 si->syncCookie = ber_dupbv( NULL, syncCookie );
1371 ber_str2bv( "top", strlen("top"), 1, &ocbva[0] );
1372 ber_str2bv( "subentry", strlen("subentry"), 1, &ocbva[1] );
1373 ber_str2bv( "syncConsumerSubentry",
1374 strlen("syncConsumerSubentry"), 1, &ocbva[2] );
1375 ocbva[3].bv_len = 0;
1376 ocbva[3].bv_val = NULL;
1378 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
1379 mod->sml_op = LDAP_MOD_REPLACE;
1380 mod->sml_next = NULL;
1381 mod->sml_desc = NULL;
1382 ber_str2bv( "objectClass", strlen("objectClass"), 1, &mod->sml_type );
1383 mod->sml_bvalues = ocbva;
1384 mod->sml_nvalues = ocbva;
1386 modtail = &mod->sml_next;
1388 sprintf( substr, "syncrepl%d", si->id );
1389 sprintf( rdnstr, "cn=%s", substr );
1390 ber_str2bv( substr, strlen( substr ), 1, &cnbva[0] );
1391 ber_str2bv( rdnstr, strlen( rdnstr ), 1, &psubrdn );
1392 cnbva[1].bv_len = 0;
1393 cnbva[1].bv_val = NULL;
1394 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
1395 mod->sml_op = LDAP_MOD_REPLACE;
1396 mod->sml_next = NULL;
1397 mod->sml_desc = NULL;
1398 ber_str2bv( "cn", strlen("cn"), 1, &mod->sml_type );
1399 mod->sml_bvalues = cnbva;
1400 mod->sml_nvalues = cnbva;
1402 modtail = &mod->sml_next;
1404 ber_dupbv( &scbva[0], si->syncCookie );
1405 scbva[1].bv_len = 0;
1406 scbva[1].bv_val = NULL;
1407 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
1408 mod->sml_op = LDAP_MOD_REPLACE;
1409 mod->sml_next = NULL;
1410 mod->sml_desc = NULL;
1411 ber_str2bv( "syncreplCookie", strlen("syncreplCookie"),
1412 1, &mod->sml_type );
1413 mod->sml_bvalues = scbva;
1414 mod->sml_nvalues = scbva;
1416 modtail = &mod->sml_next;
1418 ber_str2bv( "{}", strlen("{}"), 1, &ssbva[0] );
1419 ssbva[1].bv_len = 0;
1420 ssbva[1].bv_val = NULL;
1421 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
1422 mod->sml_op = LDAP_MOD_REPLACE;
1423 mod->sml_next = NULL;
1424 mod->sml_desc = NULL;
1425 ber_str2bv( "subtreeSpecification",
1426 strlen("subtreeSpecification"), 1, &mod->sml_type );
1427 mod->sml_bvalues = ssbva;
1428 mod->sml_nvalues = ssbva;
1430 modtail = &mod->sml_next;
1432 rc = slap_mods_check( modlist, 1, &text, txtbuf, textlen, NULL );
1434 if ( rc != LDAP_SUCCESS ) {
1436 LDAP_LOG( OPERATION, ERR,
1437 "syncrepl_updateCookie: mods check (%s)\n", text, 0, 0 );
1439 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods check (%s)\n",
1444 op->o_tag = LDAP_REQ_ADD;
1445 rc = slap_mods_opattrs( op, modlist, modtail,
1446 &text,txtbuf, textlen );
1448 for ( ml = modlist; ml != NULL; ml = mlnext ) {
1449 mlnext = ml->sml_next;
1450 if ( ml->sml_desc == slap_schema.si_ad_structuralObjectClass )
1451 ml->sml_op = LDAP_MOD_REPLACE;
1454 if( rc != LDAP_SUCCESS ) {
1456 LDAP_LOG( OPERATION, ERR,
1457 "syncrepl_updateCookie: mods opattrs (%s)\n", text, 0, 0 );
1459 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods opattrs (%s)\n",
1464 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
1466 build_new_dn( &sub_bv, pdn, &psubrdn );
1467 dnPrettyNormal( NULL, &sub_bv, &e->e_name, &e->e_nname, NULL );
1468 ch_free( sub_bv.bv_val );
1469 ch_free( psubrdn.bv_val );
1473 rc = slap_mods2entry( modlist, &e, 1, 1, &text, txtbuf, textlen );
1475 if( rc != LDAP_SUCCESS ) {
1477 LDAP_LOG( OPERATION, ERR,
1478 "syncrepl_updateCookie: mods2entry (%s)\n", text, 0, 0 );
1480 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods2entry (%s)\n",
1485 cb.sc_response = null_callback;
1488 op->o_callback = &cb;
1489 op->o_req_dn = e->e_name;
1490 op->o_req_ndn = e->e_nname;
1492 /* update persistent cookie */
1493 update_cookie_retry:
1494 op->o_tag = LDAP_REQ_MODIFY;
1495 op->orm_modlist = modlist;
1496 rc = be->be_modify( op, &rs );
1497 if ( rc != LDAP_SUCCESS ) {
1498 if ( rc == LDAP_REFERRAL ||
1499 rc == LDAP_NO_SUCH_OBJECT ) {
1500 op->o_tag = LDAP_REQ_ADD;
1502 rc = be->be_add( op, &rs );
1503 if ( rc != LDAP_SUCCESS ) {
1504 if ( rc == LDAP_ALREADY_EXISTS ) {
1505 goto update_cookie_retry;
1506 } else if ( rc == LDAP_REFERRAL ||
1507 rc == LDAP_NO_SUCH_OBJECT ) {
1509 LDAP_LOG( OPERATION, ERR,
1510 "cookie will be non-persistent\n",
1513 Debug( LDAP_DEBUG_ANY,
1514 "cookie will be non-persistent\n",
1519 LDAP_LOG( OPERATION, ERR,
1520 "be_add failed (%d)\n",
1523 Debug( LDAP_DEBUG_ANY,
1524 "be_add failed (%d)\n",
1529 be_entry_release_w( op, e );
1534 LDAP_LOG( OPERATION, ERR,
1535 "be_modify failed (%d)\n", rc, 0, 0 );
1537 Debug( LDAP_DEBUG_ANY,
1538 "be_modify failed (%d)\n", rc, 0, 0 );
1548 for ( ml = modlist; ml != NULL; ml = mlnext ) {
1549 mlnext = ml->sml_next;
1557 avl_ber_bvfree( void *bv )
1562 if ( ((struct berval *)bv)->bv_val != NULL ) {
1563 ber_memfree ( ((struct berval *)bv)->bv_val );
1565 ber_memfree ( (char *) bv );
1574 syncinfo_t *si = op->o_callback->sc_private;
1577 if ( rs->sr_type != REP_SEARCH ) return LDAP_SUCCESS;
1579 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_syncreplCookie );
1582 si->syncCookie = NULL;
1584 si->syncCookie = ber_dupbv( NULL, &a->a_vals[0] );
1586 return LDAP_SUCCESS;
1595 syncinfo_t *si = op->o_callback->sc_private;
1597 if ( rs->sr_type == REP_SEARCH ) {
1598 if ( si->syncUUID_ndn != NULL ) {
1600 LDAP_LOG( OPERATION, ERR,
1601 "dn_callback : multiple entries match dn\n", 0, 0, 0 );
1603 Debug( LDAP_DEBUG_ANY,
1604 "dn_callback : multiple entries match dn\n", 0, 0, 0 );
1607 if ( rs->sr_entry == NULL ) {
1608 si->syncUUID_ndn = NULL;
1610 si->syncUUID_ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname );
1615 return LDAP_SUCCESS;
1619 nonpresent_callback(
1624 syncinfo_t *si = op->o_callback->sc_private;
1627 struct berval* present_uuid = NULL;
1629 SlapReply rs_cb = {REP_RESULT};
1630 struct nonpresent_entry *np_entry;
1632 if ( rs->sr_type == REP_RESULT ) {
1633 count = avl_free( si->presentlist, avl_ber_bvfree );
1634 si->presentlist = NULL;
1635 return LDAP_SUCCESS;
1636 } else if ( rs->sr_type == REP_SEARCH ) {
1637 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID );
1642 present_uuid = avl_find( si->presentlist, &a->a_vals[0], syncuuid_cmp );
1644 if ( present_uuid == NULL ) {
1645 np_entry = (struct nonpresent_entry *)
1646 ch_calloc( 1, sizeof( struct nonpresent_entry ));
1647 np_entry->dn = ber_dupbv( NULL, &rs->sr_entry->e_name );
1648 np_entry->ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname );
1649 LDAP_LIST_INSERT_HEAD( &si->nonpresentlist, np_entry, np_link );
1651 avl_delete( &si->presentlist,
1652 &a->a_vals[0], syncuuid_cmp );
1654 return LDAP_SUCCESS;
1656 return LDAP_SUCCESS;
1667 syncinfo_t *si = op->o_callback->sc_private;
1669 if ( rs->sr_err != LDAP_SUCCESS &&
1670 rs->sr_err != LDAP_REFERRAL &&
1671 rs->sr_err != LDAP_ALREADY_EXISTS &&
1672 rs->sr_err != LDAP_NO_SUCH_OBJECT ) {
1674 LDAP_LOG( OPERATION, ERR,
1675 "null_callback : error code 0x%x\n",
1678 Debug( LDAP_DEBUG_ANY,
1679 "null_callback : error code 0x%x\n",
1683 return LDAP_SUCCESS;
1688 str2clist( char ***out, char *in, const char *brkstr )
1697 /* find last element in list */
1698 for (i = 0; *out && *out[i]; i++);
1700 /* protect the input string from strtok */
1701 str = ch_strdup( in );
1703 /* Count words in string */
1705 for ( s = str; *s; s++ ) {
1706 if ( strchr( brkstr, *s ) != NULL ) {
1711 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
1713 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
1715 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
1717 *new = ch_strdup( s );