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 rc = be->be_search( op, &rs );
1011 ch_free( op->o_req_dn.bv_val );
1012 ch_free( op->o_req_ndn.bv_val );
1013 filter_free( op->ors_filter );
1014 ch_free( op->ors_filterstr.bv_val );
1016 cb.sc_response = null_callback;
1019 if ( rc == LDAP_SUCCESS && si->syncUUID_ndn && si->sync_mode != LDAP_SYNC_LOG_MODE ) {
1020 op->o_req_dn = *si->syncUUID_ndn;
1021 op->o_req_ndn = *si->syncUUID_ndn;
1022 op->o_tag = LDAP_REQ_DELETE;
1023 rc = be->be_delete( op, &rs );
1026 if ( si->syncUUID_ndn ) {
1027 ber_bvfree( si->syncUUID_ndn );
1030 switch ( syncstate ) {
1031 case LDAP_SYNC_ADD :
1032 case LDAP_SYNC_MODIFY :
1034 if ( rc == LDAP_SUCCESS ||
1035 rc == LDAP_REFERRAL ||
1036 rc == LDAP_NO_SUCH_OBJECT ) {
1038 if ( !attr_find( e->e_attrs, slap_schema.si_ad_entryUUID )) {
1039 attr_merge_normalize_one( e, slap_schema.si_ad_entryUUID, syncUUID, op->o_tmpmemctx );
1042 op->o_tag = LDAP_REQ_ADD;
1044 op->o_req_dn = e->e_name;
1045 op->o_req_ndn = e->e_nname;
1046 rc = be->be_add( op, &rs );
1048 if ( rc != LDAP_SUCCESS ) {
1049 if ( rc == LDAP_ALREADY_EXISTS ) {
1050 op->o_tag = LDAP_REQ_MODIFY;
1051 op->orm_modlist = modlist;
1052 op->o_req_dn = e->e_name;
1053 op->o_req_ndn = e->e_nname;
1054 rc = be->be_modify( op, &rs );
1057 } else if ( rc == LDAP_REFERRAL ||
1058 rc == LDAP_NO_SUCH_OBJECT ) {
1059 syncrepl_add_glue( si, ld, op, e,
1061 syncUUID, syncCookie);
1066 LDAP_LOG( OPERATION, ERR,
1067 "be_modify failed (%d)\n",
1070 Debug( LDAP_DEBUG_ANY,
1071 "be_modify failed (%d)\n",
1079 be_entry_release_w( op, e );
1084 LDAP_LOG( OPERATION, ERR,
1085 "be_modify/be_delete failed (%d)\n", rc, 0, 0 );
1087 Debug( LDAP_DEBUG_ANY,
1088 "be_modify/be_delete failed (%d)\n", rc, 0, 0 );
1094 case LDAP_SYNC_DELETE :
1095 if ( si->sync_mode == LDAP_SYNC_LOG_MODE ) {
1096 op->o_req_dn = *si->syncUUID_ndn;
1097 op->o_req_ndn = *si->syncUUID_ndn;
1098 op->o_tag = LDAP_REQ_DELETE;
1099 rc = be->be_delete( op, &rs );
1101 /* Already deleted otherwise */
1106 LDAP_LOG( OPERATION, ERR,
1107 "unknown syncstate\n", 0, 0, 0 );
1109 Debug( LDAP_DEBUG_ANY,
1110 "unknown syncstate\n", 0, 0, 0 );
1117 syncrepl_del_nonpresent(
1122 Backend* be = op->o_bd;
1123 syncinfo_t *si = op->o_si;
1125 struct berval base_bv = {0, NULL};
1127 SlapReply rs = {REP_RESULT};
1128 struct berval filterstr_bv = {0, NULL};
1129 struct nonpresent_entry *np_list, *np_prev;
1131 ber_str2bv( si->base, strlen(si->base), 1, &base_bv );
1132 dnPrettyNormal(0, &base_bv, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
1133 ch_free( base_bv.bv_val );
1135 filter = str2filter( si->filterstr );
1137 cb.sc_response = nonpresent_callback;
1140 op->o_callback = &cb;
1141 op->o_tag = LDAP_REQ_SEARCH;
1142 op->ors_scope = si->scope;
1143 op->ors_deref = LDAP_DEREF_NEVER;
1146 op->ors_attrsonly = 0;
1147 op->ors_attrs = NULL;
1148 op->ors_filter = filter;
1149 ber_str2bv( si->filterstr, strlen( si->filterstr ), 1, &op->ors_filterstr );
1151 be->be_search( op, &rs );
1153 if ( !LDAP_LIST_EMPTY( &si->nonpresentlist ) ) {
1154 np_list = LDAP_LIST_FIRST( &si->nonpresentlist );
1155 while ( np_list != NULL ) {
1156 LDAP_LIST_REMOVE( np_list, np_link );
1158 np_list = LDAP_LIST_NEXT( np_list, np_link );
1159 op->o_tag = LDAP_REQ_DELETE;
1160 op->o_callback = &cb;
1161 cb.sc_response = null_callback;
1163 op->o_req_dn = *np_prev->dn;
1164 op->o_req_ndn = *np_prev->ndn;
1165 op->o_bd->be_delete( op, &rs );
1166 ber_bvfree( np_prev->dn );
1167 ber_bvfree( np_prev->ndn );
1168 op->o_req_dn.bv_val = NULL;
1169 op->o_req_ndn.bv_val = NULL;
1174 if ( op->o_req_dn.bv_val )
1175 ch_free( op->o_req_dn.bv_val );
1176 if ( op->o_req_ndn.bv_val )
1177 ch_free( op->o_req_ndn.bv_val );
1178 filter_free( op->ors_filter );
1179 ch_free( op->ors_filterstr.bv_val );
1191 Modifications* modlist,
1193 struct berval* syncUUID,
1194 struct berval* syncCookie
1197 Backend *be = op->o_bd;
1198 struct berval uuid_bv = {0, NULL};
1202 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
1205 struct berval dn = {0, NULL};
1206 struct berval pdn = {0, NULL};
1207 struct berval ndn = {0, NULL};
1208 struct berval rdn = {0, NULL};
1210 SlapReply rs = {REP_RESULT};
1211 Connection *conn = op->o_conn;
1214 op->o_tag = LDAP_REQ_ADD;
1215 op->o_callback = &cb;
1216 cb.sc_response = null_callback;
1219 ber_dupbv( &dn, &e->e_nname );
1220 ber_dupbv( &pdn, &e->e_nname );
1223 while ( !be_issuffix ( be, &pdn )) {
1224 dnParent( &dn, &pdn );
1225 dn.bv_val = pdn.bv_val;
1226 dn.bv_len = pdn.bv_len;
1231 for ( i = 0; i <= levels; i++ ) {
1232 glue = (Entry*) ch_calloc( 1, sizeof(Entry) );
1233 ber_dupbv( &dn, &e->e_nname );
1237 for ( k = 0; k < j; k++ ) {
1238 dnParent( &dn, &pdn );
1239 dn.bv_val = pdn.bv_val;
1240 dn.bv_len = pdn.bv_len;
1243 dnPrettyNormal( 0, &dn, &pdn, &ndn, op->o_tmpmemctx );
1244 ber_dupbv( &glue->e_name, &pdn );
1245 ber_dupbv( &glue->e_nname, &ndn );
1247 ch_free( pdn.bv_val );
1248 ch_free( ndn.bv_val );
1250 a = ch_calloc( 1, sizeof( Attribute ));
1251 a->a_desc = slap_schema.si_ad_objectClass;
1253 a->a_vals = ch_calloc( 3, sizeof( struct berval ));
1254 ber_str2bv( "top", strlen("top"), 1, &a->a_vals[0] );
1255 ber_str2bv( "glue", strlen("glue"), 1, &a->a_vals[1] );
1256 a->a_vals[2].bv_len = 0;
1257 a->a_vals[2].bv_val = NULL;
1259 a->a_nvals = ch_calloc( 3, sizeof( struct berval ));
1260 ber_str2bv( "top", strlen("top"), 1, &a->a_nvals[0] );
1261 ber_str2bv( "glue", strlen("glue"), 1, &a->a_nvals[1] );
1262 a->a_nvals[2].bv_len = 0;
1263 a->a_nvals[2].bv_val = NULL;
1265 a->a_next = glue->e_attrs;
1268 a = ch_calloc( 1, sizeof( Attribute ));
1269 a->a_desc = slap_schema.si_ad_structuralObjectClass;
1271 a->a_vals = ch_calloc( 2, sizeof( struct berval ));
1272 ber_str2bv( "glue", strlen("glue"), 1, &a->a_vals[0] );
1273 a->a_vals[1].bv_len = 0;
1274 a->a_vals[1].bv_val = NULL;
1276 a->a_nvals = ch_calloc( 2, sizeof( struct berval ));
1277 ber_str2bv( "glue", strlen("glue"), 1, &a->a_nvals[0] );
1278 a->a_nvals[1].bv_len = 0;
1279 a->a_nvals[1].bv_val = NULL;
1281 a->a_next = glue->e_attrs;
1284 if ( !strcmp( e->e_nname.bv_val, glue->e_nname.bv_val )) {
1285 op->o_req_dn = e->e_name;
1286 op->o_req_ndn = e->e_nname;
1288 rc = be->be_add ( op, &rs );
1289 if ( rc == LDAP_SUCCESS )
1290 be_entry_release_w( op, e );
1295 op->o_req_dn = glue->e_name;
1296 op->o_req_ndn = glue->e_nname;
1298 rc = be->be_add ( op, &rs );
1299 if ( rc == LDAP_SUCCESS ) {
1300 be_entry_release_w( op, glue );
1302 /* incl. ALREADY EXIST */
1312 syncrepl_updateCookie(
1317 struct berval *syncCookie
1320 Backend *be = op->o_bd;
1322 Modifications *mlnext;
1324 Modifications *modlist;
1325 Modifications **modtail = &modlist;
1327 struct berval* ocbva = NULL;
1328 struct berval* cnbva = NULL;
1329 struct berval* ssbva = NULL;
1330 struct berval* scbva = NULL;
1335 char txtbuf[SLAP_TEXT_BUFLEN];
1336 size_t textlen = sizeof txtbuf;
1341 struct berval sub_bv = { 0, NULL };
1342 struct berval psubrdn = { 0, NULL };
1345 SlapReply rs = {REP_RESULT};
1347 ocbva = ( struct berval * ) ch_calloc( 4, sizeof( struct berval ));
1348 cnbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval ));
1349 ssbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval ));
1350 scbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval ));
1352 /* update in memory cookie */
1353 if ( si->syncCookie != NULL ) {
1354 ber_bvfree( si->syncCookie );
1356 si->syncCookie = ber_dupbv( NULL, syncCookie );
1357 ber_str2bv( "top", strlen("top"), 1, &ocbva[0] );
1358 ber_str2bv( "subentry", strlen("subentry"), 1, &ocbva[1] );
1359 ber_str2bv( "syncConsumerSubentry",
1360 strlen("syncConsumerSubentry"), 1, &ocbva[2] );
1361 ocbva[3].bv_len = 0;
1362 ocbva[3].bv_val = NULL;
1364 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
1365 mod->sml_op = LDAP_MOD_REPLACE;
1366 mod->sml_next = NULL;
1367 mod->sml_desc = NULL;
1368 ber_str2bv( "objectClass", strlen("objectClass"), 1, &mod->sml_type );
1369 mod->sml_bvalues = ocbva;
1370 mod->sml_nvalues = ocbva;
1372 modtail = &mod->sml_next;
1374 sprintf( substr, "syncrepl%d", si->id );
1375 sprintf( rdnstr, "cn=%s", substr );
1376 ber_str2bv( substr, strlen( substr ), 1, &cnbva[0] );
1377 ber_str2bv( rdnstr, strlen( rdnstr ), 1, &psubrdn );
1378 cnbva[1].bv_len = 0;
1379 cnbva[1].bv_val = NULL;
1380 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
1381 mod->sml_op = LDAP_MOD_REPLACE;
1382 mod->sml_next = NULL;
1383 mod->sml_desc = NULL;
1384 ber_str2bv( "cn", strlen("cn"), 1, &mod->sml_type );
1385 mod->sml_bvalues = cnbva;
1386 mod->sml_nvalues = cnbva;
1388 modtail = &mod->sml_next;
1390 ber_dupbv( &scbva[0], si->syncCookie );
1391 scbva[1].bv_len = 0;
1392 scbva[1].bv_val = NULL;
1393 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
1394 mod->sml_op = LDAP_MOD_REPLACE;
1395 mod->sml_next = NULL;
1396 mod->sml_desc = NULL;
1397 ber_str2bv( "syncreplCookie", strlen("syncreplCookie"),
1398 1, &mod->sml_type );
1399 mod->sml_bvalues = scbva;
1400 mod->sml_nvalues = scbva;
1402 modtail = &mod->sml_next;
1404 ber_str2bv( "{}", strlen("{}"), 1, &ssbva[0] );
1405 ssbva[1].bv_len = 0;
1406 ssbva[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( "subtreeSpecification",
1412 strlen("subtreeSpecification"), 1, &mod->sml_type );
1413 mod->sml_bvalues = ssbva;
1414 mod->sml_nvalues = ssbva;
1416 modtail = &mod->sml_next;
1418 rc = slap_mods_check( modlist, 1, &text, txtbuf, textlen, NULL );
1420 if ( rc != LDAP_SUCCESS ) {
1422 LDAP_LOG( OPERATION, ERR,
1423 "syncrepl_updateCookie: mods check (%s)\n", text, 0, 0 );
1425 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods check (%s)\n",
1430 op->o_tag = LDAP_REQ_ADD;
1431 rc = slap_mods_opattrs( op, modlist, modtail,
1432 &text,txtbuf, textlen );
1434 for ( ml = modlist; ml != NULL; ml = mlnext ) {
1435 mlnext = ml->sml_next;
1436 if ( ml->sml_desc == slap_schema.si_ad_structuralObjectClass )
1437 ml->sml_op = LDAP_MOD_REPLACE;
1440 if( rc != LDAP_SUCCESS ) {
1442 LDAP_LOG( OPERATION, ERR,
1443 "syncrepl_updateCookie: mods opattrs (%s)\n", text, 0, 0 );
1445 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods opattrs (%s)\n",
1450 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
1452 build_new_dn( &sub_bv, pdn, &psubrdn );
1453 dnPrettyNormal( NULL, &sub_bv, &e->e_name, &e->e_nname, NULL );
1454 ch_free( sub_bv.bv_val );
1455 ch_free( psubrdn.bv_val );
1459 rc = slap_mods2entry( modlist, &e, 1, 1, &text, txtbuf, textlen );
1461 if( rc != LDAP_SUCCESS ) {
1463 LDAP_LOG( OPERATION, ERR,
1464 "syncrepl_updateCookie: mods2entry (%s)\n", text, 0, 0 );
1466 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods2entry (%s)\n",
1471 cb.sc_response = null_callback;
1474 op->o_callback = &cb;
1475 op->o_req_dn = e->e_name;
1476 op->o_req_ndn = e->e_nname;
1478 /* update persistent cookie */
1479 update_cookie_retry:
1480 op->o_tag = LDAP_REQ_MODIFY;
1481 op->orm_modlist = modlist;
1482 rc = be->be_modify( op, &rs );
1483 if ( rc != LDAP_SUCCESS ) {
1484 if ( rc == LDAP_REFERRAL ||
1485 rc == LDAP_NO_SUCH_OBJECT ) {
1486 op->o_tag = LDAP_REQ_ADD;
1488 rc = be->be_add( op, &rs );
1489 if ( rc != LDAP_SUCCESS ) {
1490 if ( rc == LDAP_ALREADY_EXISTS ) {
1491 goto update_cookie_retry;
1492 } else if ( rc == LDAP_REFERRAL ||
1493 rc == LDAP_NO_SUCH_OBJECT ) {
1495 LDAP_LOG( OPERATION, ERR,
1496 "cookie will be non-persistent\n",
1499 Debug( LDAP_DEBUG_ANY,
1500 "cookie will be non-persistent\n",
1505 LDAP_LOG( OPERATION, ERR,
1506 "be_add failed (%d)\n",
1509 Debug( LDAP_DEBUG_ANY,
1510 "be_add failed (%d)\n",
1515 be_entry_release_w( op, e );
1520 LDAP_LOG( OPERATION, ERR,
1521 "be_modify failed (%d)\n", rc, 0, 0 );
1523 Debug( LDAP_DEBUG_ANY,
1524 "be_modify failed (%d)\n", rc, 0, 0 );
1534 for ( ml = modlist; ml != NULL; ml = mlnext ) {
1535 mlnext = ml->sml_next;
1543 avl_ber_bvfree( void *bv )
1548 if ( ((struct berval *)bv)->bv_val != NULL ) {
1549 ber_memfree ( ((struct berval *)bv)->bv_val );
1551 ber_memfree ( (char *) bv );
1560 syncinfo_t *si = op->o_callback->sc_private;
1563 if ( rs->sr_type != REP_SEARCH ) return LDAP_SUCCESS;
1565 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_syncreplCookie );
1568 si->syncCookie = NULL;
1570 si->syncCookie = ber_dupbv( NULL, &a->a_vals[0] );
1572 return LDAP_SUCCESS;
1581 syncinfo_t *si = op->o_callback->sc_private;
1583 if ( rs->sr_type == REP_SEARCH ) {
1584 si->syncUUID_ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname );
1587 return LDAP_SUCCESS;
1591 nonpresent_callback(
1596 syncinfo_t *si = op->o_callback->sc_private;
1599 struct berval* present_uuid = NULL;
1601 SlapReply rs_cb = {REP_RESULT};
1602 struct nonpresent_entry *np_entry;
1604 if ( rs->sr_type == REP_RESULT ) {
1605 count = avl_free( si->presentlist, avl_ber_bvfree );
1606 si->presentlist = NULL;
1607 return LDAP_SUCCESS;
1608 } else if ( rs->sr_type == REP_SEARCH ) {
1609 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID );
1614 present_uuid = avl_find( si->presentlist, &a->a_vals[0], syncuuid_cmp );
1616 if ( present_uuid == NULL ) {
1617 np_entry = (struct nonpresent_entry *)
1618 ch_calloc( 1, sizeof( struct nonpresent_entry ));
1619 np_entry->dn = ber_dupbv( NULL, &rs->sr_entry->e_name );
1620 np_entry->ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname );
1621 LDAP_LIST_INSERT_HEAD( &si->nonpresentlist, np_entry, np_link );
1623 avl_delete( &si->presentlist,
1624 &a->a_vals[0], syncuuid_cmp );
1626 return LDAP_SUCCESS;
1628 return LDAP_SUCCESS;
1639 syncinfo_t *si = op->o_callback->sc_private;
1641 if ( rs->sr_err != LDAP_SUCCESS &&
1642 rs->sr_err != LDAP_REFERRAL &&
1643 rs->sr_err != LDAP_ALREADY_EXISTS &&
1644 rs->sr_err != LDAP_NO_SUCH_OBJECT ) {
1646 LDAP_LOG( OPERATION, ERR,
1647 "null_callback : error code 0x%x\n",
1650 Debug( LDAP_DEBUG_ANY,
1651 "null_callback : error code 0x%x\n",
1655 return LDAP_SUCCESS;
1660 str2clist( char ***out, char *in, const char *brkstr )
1669 /* find last element in list */
1670 for (i = 0; *out && *out[i]; i++);
1672 /* protect the input string from strtok */
1673 str = ch_strdup( in );
1675 /* Count words in string */
1677 for ( s = str; *s; s++ ) {
1678 if ( strchr( brkstr, *s ) != NULL ) {
1683 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
1685 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
1687 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
1689 *new = ch_strdup( s );