1 /* syncrepl.c -- Replication Engine which uses the LDAP Sync protocol */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2004 The OpenLDAP Foundation.
6 * Portions Copyright 2003 by IBM Corporation.
7 * Portions Copyright 2003 by Howard Chu, Symas Corporation.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
23 #include <ac/string.h>
24 #include <ac/socket.h>
28 #include "lutil_ldap.h"
32 /* FIXME: for ldap_ld_free() */
34 #include "../../libraries/libldap/ldap-int.h"
36 #define SYNCREPL_STR "syncreplxxx"
39 static const struct berval slap_syncrepl_bvc = BER_BVC(SYNCREPL_STR);
40 static const struct berval slap_syncrepl_cn_bvc = BER_BVC(CN_STR SYNCREPL_STR);
42 static int syncuuid_cmp( const void *, const void * );
43 static void avl_ber_bvfree( void * );
44 static void syncrepl_del_nonpresent( Operation *, syncinfo_t * );
46 /* callback functions */
47 static int dn_callback( struct slap_op *, struct slap_rep * );
48 static int nonpresent_callback( struct slap_op *, struct slap_rep * );
49 static int null_callback( struct slap_op *, struct slap_rep * );
51 static AttributeDescription *sync_descs[4];
53 struct runqueue_s syncrepl_rq;
56 init_syncrepl(syncinfo_t *si)
59 char **attrs, **exattrs;
61 if ( !sync_descs[0] ) {
62 sync_descs[0] = slap_schema.si_ad_objectClass;
63 sync_descs[1] = slap_schema.si_ad_structuralObjectClass;
64 sync_descs[2] = slap_schema.si_ad_entryCSN;
68 if ( si->si_allattrs && si->si_allopattrs )
71 attrs = anlist2attrs( si->si_anlist );
74 if ( si->si_allattrs ) {
77 if ( !is_at_operational( at_find( attrs[i] ))) {
78 for ( j = i; attrs[j] != NULL; j++ ) {
81 attrs[j] = attrs[j+1];
87 attrs = ( char ** ) ch_realloc( attrs, (i + 2)*sizeof( char * ) );
88 attrs[i] = ch_strdup("*");
91 } else if ( si->si_allopattrs ) {
94 if ( is_at_operational( at_find( attrs[i] ))) {
95 for ( j = i; attrs[j] != NULL; j++ ) {
98 attrs[j] = attrs[j+1];
104 attrs = ( char ** ) ch_realloc( attrs, (i + 2)*sizeof( char * ) );
105 attrs[i] = ch_strdup("+");
109 for ( i = 0; sync_descs[i] != NULL; i++ ) {
112 if ( !strcmp( attrs[j], sync_descs[i]->ad_cname.bv_val )) {
113 for ( k = j; attrs[k] != NULL; k++ ) {
116 attrs[k] = attrs[k+1];
124 for ( n = 0; attrs[ n ] != NULL; n++ ) /* empty */;
126 if ( si->si_allopattrs ) {
127 attrs = ( char ** ) ch_realloc( attrs, (n + 2)*sizeof( char * ));
129 attrs = ( char ** ) ch_realloc( attrs, (n + 4)*sizeof( char * ));
132 if ( attrs == NULL ) {
133 Debug( LDAP_DEBUG_ANY, "out of memory\n", 0,0,0 );
137 if ( si->si_allopattrs ) {
138 attrs[n++] = ch_strdup( sync_descs[0]->ad_cname.bv_val );
140 for ( i = 0; sync_descs[ i ] != NULL; i++ ) {
141 attrs[ n++ ] = ch_strdup ( sync_descs[i]->ad_cname.bv_val );
149 if ( si->si_allattrs == si->si_allopattrs ) {
150 attrs = (char**) ch_malloc( 3 * sizeof(char*) );
151 attrs[i++] = ch_strdup( "*" );
152 attrs[i++] = ch_strdup( "+" );
153 } else if ( si->si_allattrs && !si->si_allopattrs ) {
154 for ( n = 0; sync_descs[ n ] != NULL; n++ ) ;
155 attrs = (char**) ch_malloc( (n+1)* sizeof(char*) );
156 attrs[i++] = ch_strdup( "*" );
157 for ( j = 1; sync_descs[ j ] != NULL; j++ ) {
158 attrs[i++] = ch_strdup ( sync_descs[j]->ad_cname.bv_val );
160 } else if ( !si->si_allattrs && si->si_allopattrs ) {
161 attrs = (char**) ch_malloc( 3 * sizeof(char*) );
162 attrs[i++] = ch_strdup( "+" );
163 attrs[i++] = ch_strdup( sync_descs[0]->ad_cname.bv_val );
168 si->si_attrs = attrs;
170 exattrs = anlist2attrs( si->si_exanlist );
173 for ( n = 0; exattrs[n] != NULL; n++ ) ;
175 for ( i = 0; sync_descs[i] != NULL; i++ ) {
177 while ( exattrs[j] != NULL ) {
178 if ( !strcmp( exattrs[j], sync_descs[i]->ad_cname.bv_val )) {
179 for ( k = j; exattrs[k] != NULL; k++ ) {
181 ch_free( exattrs[k] );
182 exattrs[k] = exattrs[k+1];
190 for ( i = 0; exattrs[i] != NULL; i++ ) {
191 for ( j = 0; si->si_anlist[j].an_name.bv_val; j++ ) {
193 if ( ( oc = si->si_anlist[j].an_oc ) ) {
195 while ( oc->soc_required[k] ) {
196 if ( !strcmp( exattrs[i],
197 oc->soc_required[k]->sat_cname.bv_val )) {
198 for ( l = i; exattrs[l]; l++ ) {
200 ch_free( exattrs[i] );
201 exattrs[l] = exattrs[l+1];
211 for ( i = 0; exattrs[i] != NULL; i++ ) ;
214 exattrs = (char **) ch_realloc( exattrs, (i + 1)*sizeof(char *));
217 si->si_exattrs = exattrs;
225 BerElementBuffer berbuf;
226 BerElement *ber = (BerElement *)&berbuf;
227 LDAPControl c[2], *ctrls[3];
228 struct timeval timeout;
232 /* setup LDAP SYNC control */
233 ber_init2( ber, NULL, LBER_USE_DER );
234 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &ctx );
236 if ( si->si_syncCookie.octet_str &&
237 !BER_BVISNULL( &si->si_syncCookie.octet_str[0] ) )
239 ber_printf( ber, "{eO}",
241 &si->si_syncCookie.octet_str[0] );
243 ber_printf( ber, "{e}",
247 if ( (rc = ber_flatten2( ber, &c[0].ldctl_value, 0 )) == LBER_ERROR ) {
252 c[0].ldctl_oid = LDAP_CONTROL_SYNC;
253 c[0].ldctl_iscritical = si->si_type < 0;
256 if ( si->si_authzId ) {
257 c[1].ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
258 ber_str2bv( si->si_authzId, 0, 0, &c[1].ldctl_value );
259 c[1].ldctl_iscritical = 1;
266 timeout.tv_sec = si->si_tlimit;
269 rc = ldap_search_ext( si->si_ld, si->si_base.bv_val, si->si_scope,
270 si->si_filterstr.bv_val, si->si_attrs, si->si_attrsonly,
271 ctrls, NULL, si->si_tlimit > 0 ? &timeout : NULL,
272 si->si_slimit, &msgid );
283 int cmdline_cookie_found = 0;
285 char syncrepl_cbuf[sizeof(CN_STR SYNCREPL_STR)];
286 struct berval syncrepl_cn_bv;
287 struct sync_cookie *sc = NULL;
293 psub = &si->si_be->be_nsuffix[0];
295 /* Init connection to master */
296 rc = ldap_initialize( &si->si_ld, si->si_provideruri );
297 if ( rc != LDAP_SUCCESS ) {
298 Debug( LDAP_DEBUG_ANY,
299 "do_syncrep1: ldap_initialize failed (%s)\n",
300 si->si_provideruri, 0, 0 );
304 op->o_protocol = LDAP_VERSION3;
305 ldap_set_option( si->si_ld, LDAP_OPT_PROTOCOL_VERSION, &op->o_protocol );
310 rc = ldap_start_tls_s( si->si_ld, NULL, NULL );
311 if( rc != LDAP_SUCCESS ) {
312 Debug( LDAP_DEBUG_ANY,
313 "%s: ldap_start_tls failed (%d)\n",
314 si->si_tls == SYNCINFO_TLS_CRITICAL ? "Error" : "Warning",
316 if( si->si_tls == SYNCINFO_TLS_CRITICAL ) goto done;
320 if ( si->si_bindmethod == LDAP_AUTH_SASL ) {
321 #ifdef HAVE_CYRUS_SASL
324 if ( si->si_secprops != NULL ) {
325 rc = ldap_set_option( si->si_ld,
326 LDAP_OPT_X_SASL_SECPROPS, si->si_secprops);
328 if( rc != LDAP_OPT_SUCCESS ) {
329 Debug( LDAP_DEBUG_ANY, "Error: ldap_set_option "
330 "(%s,SECPROPS,\"%s\") failed!\n",
331 si->si_provideruri, si->si_secprops, 0 );
336 defaults = lutil_sasl_defaults( si->si_ld, si->si_saslmech,
337 si->si_realm, si->si_authcId, si->si_passwd, si->si_authzId );
339 rc = ldap_sasl_interactive_bind_s( si->si_ld,
347 lutil_sasl_freedefs( defaults );
349 /* FIXME: different error behaviors according to
351 * 2) on err policy : exit, retry, backoff ...
353 if ( rc != LDAP_SUCCESS ) {
354 Debug( LDAP_DEBUG_ANY, "do_syncrep1: "
355 "ldap_sasl_interactive_bind_s failed (%d)\n",
358 /* FIXME (see above comment) */
359 /* if Kerberos credentials cache is not active, retry */
360 if ( strcmp( si->si_saslmech, "GSSAPI" ) == 0 &&
361 rc == LDAP_LOCAL_ERROR )
363 rc = LDAP_SERVER_DOWN;
368 #else /* HAVE_CYRUS_SASL */
369 /* Should never get here, we trapped this at config time */
371 fprintf( stderr, "not compiled with SASL support\n" );
377 rc = ldap_bind_s( si->si_ld,
378 si->si_binddn, si->si_passwd, si->si_bindmethod );
379 if ( rc != LDAP_SUCCESS ) {
380 Debug( LDAP_DEBUG_ANY, "do_syncrep1: "
381 "ldap_bind_s failed (%d)\n", rc, 0, 0 );
386 /* Set SSF to strongest of TLS, SASL SSFs */
389 op->o_transport_ssf = 0;
391 if ( ldap_get_option( si->si_ld, LDAP_OPT_X_TLS_SSL_CTX, &ssl )
392 == LDAP_SUCCESS && ssl != NULL )
394 op->o_tls_ssf = ldap_pvt_tls_get_strength( ssl );
396 #endif /* HAVE_TLS */
397 ldap_get_option( si->si_ld, LDAP_OPT_X_SASL_SSF, &op->o_sasl_ssf );
398 op->o_ssf = ( op->o_sasl_ssf > op->o_tls_ssf )
399 ? op->o_sasl_ssf : op->o_tls_ssf;
401 /* get syncrepl cookie of shadow replica from subentry */
402 assert( si->si_rid < 1000 );
403 syncrepl_cn_bv.bv_val = syncrepl_cbuf;
404 syncrepl_cn_bv.bv_len = snprintf( syncrepl_cbuf, sizeof(syncrepl_cbuf),
405 CN_STR "syncrepl%ld", si->si_rid );
406 build_new_dn( &op->o_req_ndn, psub, &syncrepl_cn_bv, op->o_tmpmemctx );
407 op->o_req_dn = op->o_req_ndn;
409 LDAP_STAILQ_FOREACH( sc, &slap_sync_cookie, sc_next ) {
410 if ( si->si_rid == sc->rid ) {
411 cmdline_cookie_found = 1;
416 if ( cmdline_cookie_found ) {
417 /* cookie is supplied in the command line */
418 BerVarray cookie = NULL;
419 struct berval cookie_bv;
421 LDAP_STAILQ_REMOVE( &slap_sync_cookie, sc, sync_cookie, sc_next );
422 slap_sync_cookie_free( &si->si_syncCookie, 0 );
424 /* read stored cookie if it exists */
425 backend_attribute( op, NULL, &op->o_req_ndn,
426 slap_schema.si_ad_syncreplCookie, &cookie, ACL_READ );
429 /* no stored cookie */
430 if ( sc->ctxcsn == NULL ||
431 BER_BVISNULL( sc->ctxcsn ) ) {
432 /* if cmdline cookie does not have ctxcsn */
433 /* component, set it to an initial value */
434 slap_init_sync_cookie_ctxcsn( sc );
436 slap_dup_sync_cookie( &si->si_syncCookie, sc );
437 slap_sync_cookie_free( sc, 1 );
442 struct berval newcookie = BER_BVNULL;
443 ber_dupbv( &cookie_bv, &cookie[0] );
444 ber_bvarray_add( &si->si_syncCookie.octet_str, &cookie_bv );
445 slap_parse_sync_cookie( &si->si_syncCookie );
446 ber_bvarray_free( si->si_syncCookie.octet_str );
447 si->si_syncCookie.octet_str = NULL;
448 ber_bvarray_free_x( cookie, op->o_tmpmemctx );
449 if ( sc->sid != -1 ) {
450 /* command line cookie wins */
451 si->si_syncCookie.sid = sc->sid;
453 if ( sc->ctxcsn != NULL ) {
454 /* command line cookie wins */
455 if ( si->si_syncCookie.ctxcsn ) {
456 ber_bvarray_free( si->si_syncCookie.ctxcsn );
457 si->si_syncCookie.ctxcsn = NULL;
459 ber_dupbv( &cookie_bv, &sc->ctxcsn[0] );
460 ber_bvarray_add( &si->si_syncCookie.ctxcsn, &cookie_bv );
462 if ( sc->rid != -1 ) {
463 /* command line cookie wins */
464 si->si_syncCookie.rid = sc->rid;
466 slap_sync_cookie_free( sc, 1 );
468 slap_compose_sync_cookie( NULL, &newcookie,
469 &si->si_syncCookie.ctxcsn[0],
470 si->si_syncCookie.sid, si->si_syncCookie.rid );
471 ber_bvarray_add( &si->si_syncCookie.octet_str, &newcookie );
475 /* no command line cookie is specified */
476 if ( si->si_syncCookie.octet_str == NULL ) {
477 BerVarray cookie = NULL;
478 struct berval cookie_bv;
479 /* try to read stored cookie */
480 backend_attribute( op, NULL, &op->o_req_ndn,
481 slap_schema.si_ad_syncreplCookie, &cookie, ACL_READ );
483 ber_dupbv( &cookie_bv, &cookie[0] );
484 ber_bvarray_add( &si->si_syncCookie.octet_str, &cookie_bv );
485 slap_parse_sync_cookie( &si->si_syncCookie );
486 ber_bvarray_free_x( cookie, op->o_tmpmemctx );
491 rc = ldap_sync_search( si, op->o_tmpmemctx );
493 if( rc != LDAP_SUCCESS ) {
494 Debug( LDAP_DEBUG_ANY, "do_syncrep1: "
495 "ldap_search_ext: %s (%d)\n", ldap_err2string( rc ), rc, 0 );
501 ldap_unbind( si->si_ld );
506 slap_sl_free( op->o_req_ndn.bv_val, op->o_tmpmemctx );
516 LDAPControl **rctrls = NULL;
519 BerElementBuffer berbuf;
520 BerElement *ber = (BerElement *)&berbuf;
522 LDAPMessage *res = NULL;
523 LDAPMessage *msg = NULL;
526 struct berval *retdata = NULL;
531 struct berval syncUUID = BER_BVNULL;
532 struct sync_cookie syncCookie = { NULL, -1, NULL };
533 struct sync_cookie syncCookie_req = { NULL, -1, NULL };
534 struct berval cookie = BER_BVNULL;
542 Modifications *modlist = NULL;
547 struct timeval *tout_p = NULL;
548 struct timeval tout = { 0, 0 };
550 int refreshDeletes = 0;
552 BerVarray syncUUIDs = NULL;
555 if ( slapd_shutdown ) {
560 ber_init2( ber, NULL, LBER_USE_DER );
561 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
563 Debug( LDAP_DEBUG_TRACE, "=>do_syncrep2\n", 0, 0, 0 );
565 psub = &si->si_be->be_nsuffix[0];
567 slap_dup_sync_cookie( &syncCookie_req, &si->si_syncCookie );
569 if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST ) {
575 while (( rc = ldap_result( si->si_ld, LDAP_RES_ANY, LDAP_MSG_ONE,
576 tout_p, &res )) > 0 )
578 if ( slapd_shutdown ) {
582 for( msg = ldap_first_message( si->si_ld, res );
584 msg = ldap_next_message( si->si_ld, msg ) )
586 switch( ldap_msgtype( msg ) ) {
587 case LDAP_RES_SEARCH_ENTRY:
588 ldap_get_entry_controls( si->si_ld, msg, &rctrls );
589 /* we can't work without the control */
591 Debug( LDAP_DEBUG_ANY, "do_syncrep2: "
592 "got search entry without "
593 "control\n", 0, 0, 0 );
598 ber_init2( ber, &rctrlp->ldctl_value, LBER_USE_DER );
599 ber_scanf( ber, "{em" /*"}"*/, &syncstate, &syncUUID );
600 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
601 ber_scanf( ber, /*"{"*/ "m}", &cookie );
602 if ( !BER_BVISNULL( &cookie ) ) {
603 struct berval tmp_bv;
604 ber_dupbv( &tmp_bv, &cookie );
605 ber_bvarray_add( &syncCookie.octet_str, &tmp_bv );
607 if ( syncCookie.octet_str &&
608 !BER_BVISNULL( &syncCookie.octet_str[0] ) )
610 slap_parse_sync_cookie( &syncCookie );
613 if ( syncrepl_message_to_entry( si, op, msg,
614 &modlist, &entry, syncstate ) == LDAP_SUCCESS ) {
615 rc_efree = syncrepl_entry( si, op, entry, &modlist,
616 syncstate, &syncUUID, &syncCookie_req, syncCookie.ctxcsn );
617 if ( syncCookie.octet_str &&
618 !BER_BVISNULL( &syncCookie.octet_str[0] ) )
620 syncrepl_updateCookie( si, op, psub, &syncCookie );
623 ldap_controls_free( rctrls );
625 slap_mods_free( modlist );
627 if ( rc_efree && entry ) {
633 case LDAP_RES_SEARCH_REFERENCE:
634 Debug( LDAP_DEBUG_ANY,
635 "do_syncrep2: reference received error\n", 0, 0, 0 );
638 case LDAP_RES_SEARCH_RESULT:
639 Debug( LDAP_DEBUG_SYNC,
640 "do_syncrep2: LDAP_RES_SEARCH_RESULT\n", 0, 0, 0 );
641 ldap_parse_result( si->si_ld, msg, &err, NULL, NULL, NULL,
645 ber_init2( ber, &rctrlp->ldctl_value, LBER_USE_DER );
647 ber_scanf( ber, "{" /*"}"*/);
648 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
649 ber_scanf( ber, "m", &cookie );
650 if ( !BER_BVISNULL( &cookie ) ) {
651 struct berval tmp_bv;
652 ber_dupbv( &tmp_bv, &cookie );
653 ber_bvarray_add( &syncCookie.octet_str, &tmp_bv);
655 if ( syncCookie.octet_str &&
656 !BER_BVISNULL( &syncCookie.octet_str[0] ) )
658 slap_parse_sync_cookie( &syncCookie );
661 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_REFRESHDELETES )
663 ber_scanf( ber, "b", &refreshDeletes );
665 ber_scanf( ber, /*"{"*/ "}" );
667 if ( syncCookie_req.ctxcsn == NULL ) {
669 } else if ( syncCookie.ctxcsn == NULL ) {
672 value_match( &match, slap_schema.si_ad_entryCSN,
673 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
674 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
675 &syncCookie_req.ctxcsn[0], &syncCookie.ctxcsn[0],
678 if ( syncCookie.octet_str && !BER_BVISNULL( syncCookie.octet_str ) &&
679 match < 0 && err == LDAP_SUCCESS )
681 syncrepl_updateCookie( si, op, psub, &syncCookie );
684 ldap_controls_free( rctrls );
686 if (si->si_type != LDAP_SYNC_REFRESH_AND_PERSIST) {
687 /* FIXME : different error behaviors according to
688 * 1) err code : LDAP_BUSY ...
689 * 2) on err policy : stop service, stop sync, retry
691 if ( refreshDeletes == 0 && match < 0 &&
692 err == LDAP_SUCCESS )
694 syncrepl_del_nonpresent( op, si );
696 avl_free( si->si_presentlist, avl_ber_bvfree );
697 si->si_presentlist = NULL;
704 case LDAP_RES_INTERMEDIATE:
705 rc = ldap_parse_intermediate( si->si_ld, msg,
706 &retoid, &retdata, NULL, 0 );
707 if ( !rc && !strcmp( retoid, LDAP_SYNC_INFO ) ) {
708 ber_init2( ber, retdata, LBER_USE_DER );
710 switch ( si_tag = ber_peek_tag( ber, &len )) {
712 case LDAP_TAG_SYNC_NEW_COOKIE:
713 Debug( LDAP_DEBUG_SYNC,
714 "do_syncrep2: %s - %s%s\n",
715 "LDAP_RES_INTERMEDIATE",
716 "NEW_COOKIE", "\n" );
717 ber_scanf( ber, "tm", &tag, &cookie );
719 case LDAP_TAG_SYNC_REFRESH_DELETE:
720 Debug( LDAP_DEBUG_SYNC,
721 "do_syncrep2: %s - %s%s\n",
722 "LDAP_RES_INTERMEDIATE",
723 "REFRESH_DELETE\n", "\n" );
724 si->si_refreshDelete = 1;
725 case LDAP_TAG_SYNC_REFRESH_PRESENT:
726 Debug( LDAP_DEBUG_SYNC,
727 "do_syncrep2: %s - %s%s\n",
728 "LDAP_RES_INTERMEDIATE",
729 si_tag == LDAP_TAG_SYNC_REFRESH_PRESENT ?
730 "REFRESH_PRESENT" : "REFRESH_DELETE",
732 si->si_refreshDelete = 1;
733 si->si_refreshPresent = 1;
734 ber_scanf( ber, "t{" /*"}"*/, &tag );
735 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE )
737 ber_scanf( ber, "m", &cookie );
738 if ( !BER_BVISNULL( &cookie ) ) {
739 struct berval tmp_bv;
740 ber_dupbv( &tmp_bv, &cookie );
741 ber_bvarray_add( &syncCookie.octet_str,
744 if ( syncCookie.octet_str &&
745 !BER_BVISNULL( &syncCookie.octet_str[0] ) )
747 slap_parse_sync_cookie( &syncCookie );
750 if ( ber_peek_tag( ber, &len ) ==
751 LDAP_TAG_REFRESHDONE )
753 ber_scanf( ber, "b", &refreshDone );
755 ber_scanf( ber, /*"{"*/ "}" );
757 case LDAP_TAG_SYNC_ID_SET:
758 Debug( LDAP_DEBUG_SYNC,
759 "do_syncrep2: %s - %s%s\n",
760 "LDAP_RES_INTERMEDIATE",
763 ber_scanf( ber, "t{" /*"}"*/, &tag );
764 if ( ber_peek_tag( ber, &len ) ==
765 LDAP_TAG_SYNC_COOKIE )
767 ber_scanf( ber, "m", &cookie );
768 if ( !BER_BVISNULL( &cookie ) ) {
769 struct berval tmp_bv;
770 ber_dupbv( &tmp_bv, &cookie );
771 ber_bvarray_add( &syncCookie.octet_str,
774 if ( syncCookie.octet_str &&
775 !BER_BVISNULL( &syncCookie.octet_str[0] ) )
777 slap_parse_sync_cookie( &syncCookie );
780 if ( ber_peek_tag( ber, &len ) ==
781 LDAP_TAG_REFRESHDELETES )
783 ber_scanf( ber, "b", &refreshDeletes );
785 ber_scanf( ber, "[W]", &syncUUIDs );
786 ber_scanf( ber, /*"{"*/ "}" );
787 for ( i = 0; !BER_BVISNULL( &syncUUIDs[i] ); i++ ) {
788 struct berval *syncuuid_bv;
789 syncuuid_bv = ber_dupbv( NULL, &syncUUIDs[i] );
790 slap_sl_free( syncUUIDs[i].bv_val,op->o_tmpmemctx );
791 avl_insert( &si->si_presentlist,
792 (caddr_t) syncuuid_bv,
793 syncuuid_cmp, avl_dup_error );
795 slap_sl_free( syncUUIDs, op->o_tmpmemctx );
798 Debug( LDAP_DEBUG_ANY,
799 "do_syncrep2 : unknown syncinfo tag (%ld)\n",
800 (long) si_tag, 0, 0 );
801 ldap_memfree( retoid );
802 ber_bvfree( retdata );
806 if ( syncCookie_req.ctxcsn == NULL ) {
808 } else if ( syncCookie.ctxcsn == NULL ) {
811 value_match( &match, slap_schema.si_ad_entryCSN,
812 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
813 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
814 &syncCookie_req.ctxcsn[0],
815 &syncCookie.ctxcsn[0], &text );
818 if ( syncCookie.ctxcsn && !BER_BVISNULL( &syncCookie.ctxcsn[0] ) &&
821 syncrepl_updateCookie( si, op, psub, &syncCookie);
824 if ( si->si_refreshPresent == 1 ) {
826 syncrepl_del_nonpresent( op, si );
830 ldap_memfree( retoid );
831 ber_bvfree( retdata );
835 Debug( LDAP_DEBUG_ANY, "do_syncrep2 : "
836 "unknown intermediate response (%d)\n",
838 ldap_memfree( retoid );
839 ber_bvfree( retdata );
845 Debug( LDAP_DEBUG_ANY, "do_syncrep2 : "
846 "unknown message\n", 0, 0, 0 );
850 if ( syncCookie.octet_str ) {
851 slap_sync_cookie_free( &syncCookie_req, 0 );
852 slap_dup_sync_cookie( &syncCookie_req, &syncCookie );
853 slap_sync_cookie_free( &syncCookie, 0 );
863 ldap_get_option( si->si_ld, LDAP_OPT_ERROR_NUMBER, &rc );
864 errstr = ldap_err2string( rc );
866 Debug( LDAP_DEBUG_ANY,
867 "do_syncrep2 : %s\n", errstr, 0, 0 );
871 slap_sync_cookie_free( &syncCookie, 0 );
872 slap_sync_cookie_free( &syncCookie_req, 0 );
874 if ( res ) ldap_msgfree( res );
876 if ( rc && si->si_ld ) {
877 ldap_unbind( si->si_ld );
889 struct re_s* rtask = arg;
890 syncinfo_t *si = ( syncinfo_t * ) rtask->arg;
891 Connection conn = {0};
892 char opbuf[OPERATION_BUFFER_SIZE];
894 int rc = LDAP_SUCCESS;
901 Debug( LDAP_DEBUG_TRACE, "=>do_syncrepl\n", 0, 0, 0 );
906 switch( abs( si->si_type )) {
907 case LDAP_SYNC_REFRESH_ONLY:
908 case LDAP_SYNC_REFRESH_AND_PERSIST:
914 if ( slapd_shutdown && si->si_ld ) {
915 ldap_get_option( si->si_ld, LDAP_OPT_DESC, &s );
916 connection_client_stop( s );
917 ldap_unbind( si->si_ld );
922 op = (Operation *)opbuf;
923 connection_fake_init( &conn, op, ctx );
925 /* use global malloc for now */
926 op->o_tmpmemctx = NULL;
927 op->o_tmpmfuncs = &ch_mfuncs;
929 op->o_dn = si->si_updatedn;
930 op->o_ndn = si->si_updatedn;
931 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
932 op->o_bd = be = si->si_be;
934 /* Establish session, do search */
937 si->si_refreshDelete = 0;
938 si->si_refreshPresent = 0;
939 rc = do_syncrep1( op, si );
942 /* Process results */
943 if ( rc == LDAP_SUCCESS ) {
944 ldap_get_option( si->si_ld, LDAP_OPT_DESC, &s );
946 rc = do_syncrep2( op, si );
948 if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST ) {
949 /* If we succeeded, enable the connection for further listening.
950 * If we failed, tear down the connection and reschedule.
952 if ( rc == LDAP_SUCCESS ) {
954 rc = connection_client_setup( s, do_syncrepl, arg );
956 connection_client_enable( s );
958 } else if ( !first ) {
962 if ( rc == -2 ) rc = 0;
966 /* At this point, we have 4 cases:
967 * 1) for any hard failure, give up and remove this task
968 * 2) for ServerDown, reschedule this task to run
969 * 3) for Refresh and Success, reschedule to run
970 * 4) for Persist and Success, reschedule to defer
972 ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
974 if ( ldap_pvt_runqueue_isrunning( &syncrepl_rq, rtask )) {
975 ldap_pvt_runqueue_stoptask( &syncrepl_rq, rtask );
979 connection_client_stop( s );
982 if ( rc == LDAP_SUCCESS ) {
983 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
986 rtask->interval.tv_sec = si->si_interval;
987 ldap_pvt_runqueue_resched( &syncrepl_rq, rtask, defer );
988 if ( si->si_retrynum ) {
989 for ( i = 0; si->si_retrynum_init[i] != -2; i++ ) {
990 si->si_retrynum[i] = si->si_retrynum_init[i];
992 si->si_retrynum[i] = -2;
995 for ( i = 0; si->si_retrynum && si->si_retrynum[i] <= 0; i++ ) {
996 if ( si->si_retrynum[i] == -1 || si->si_retrynum[i] == -2 )
1000 if ( !si->si_retrynum || si->si_retrynum[i] == -2 ) {
1001 ldap_pvt_runqueue_remove( &syncrepl_rq, rtask );
1002 LDAP_STAILQ_REMOVE( &be->be_syncinfo, si, syncinfo_s, si_next );
1003 syncinfo_free( si );
1004 } else if ( si->si_retrynum[i] >= -1 ) {
1005 if ( si->si_retrynum[i] > 0 )
1006 si->si_retrynum[i]--;
1007 rtask->interval.tv_sec = si->si_retryinterval[i];
1008 ldap_pvt_runqueue_resched( &syncrepl_rq, rtask, 0 );
1009 slap_wake_listener();
1013 ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
1019 syncrepl_message_to_entry(
1023 Modifications **modlist,
1029 BerElement *ber = NULL;
1032 Modifications **modtail = modlist;
1035 char txtbuf[SLAP_TEXT_BUFLEN];
1036 size_t textlen = sizeof txtbuf;
1038 struct berval bdn = {0, NULL}, dn, ndn;
1043 if ( ldap_msgtype( msg ) != LDAP_RES_SEARCH_ENTRY ) {
1044 Debug( LDAP_DEBUG_ANY,
1045 "Message type should be entry (%d)", ldap_msgtype( msg ), 0, 0 );
1049 op->o_tag = LDAP_REQ_ADD;
1051 rc = ldap_get_dn_ber( si->si_ld, msg, &ber, &bdn );
1053 if ( rc != LDAP_SUCCESS ) {
1054 Debug( LDAP_DEBUG_ANY,
1055 "syncrepl_message_to_entry : dn get failed (%d)", rc, 0, 0 );
1059 dnPrettyNormal( NULL, &bdn, &dn, &ndn, op->o_tmpmemctx );
1060 ber_dupbv( &op->o_req_dn, &dn );
1061 ber_dupbv( &op->o_req_ndn, &ndn );
1062 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1063 slap_sl_free( dn.bv_val, op->o_tmpmemctx );
1065 if ( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_DELETE ) {
1068 return LDAP_SUCCESS;
1071 if ( entry == NULL ) {
1075 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ) );
1077 e->e_name = op->o_req_dn;
1078 e->e_nname = op->o_req_ndn;
1080 while ( ber_remaining( ber ) ) {
1081 if ( (ber_scanf( ber, "{mW}", &tmp.sml_type, &tmp.sml_values ) ==
1082 LBER_ERROR ) || BER_BVISNULL( &tmp.sml_type ) )
1087 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
1089 mod->sml_op = LDAP_MOD_REPLACE;
1090 mod->sml_next = NULL;
1091 mod->sml_desc = NULL;
1092 mod->sml_type = tmp.sml_type;
1093 mod->sml_values = tmp.sml_values;
1094 mod->sml_nvalues = NULL;
1097 modtail = &mod->sml_next;
1100 if ( *modlist == NULL ) {
1101 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: no attributes\n",
1107 rc = slap_mods_check( *modlist, 1, &text, txtbuf, textlen, NULL );
1109 if ( rc != LDAP_SUCCESS ) {
1110 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods check (%s)\n",
1115 /* Strip out dynamically generated attrs */
1116 for ( modtail = modlist; *modtail ; ) {
1118 if ( mod->sml_desc->ad_type->sat_flags & SLAP_AT_DYNAMIC ) {
1119 *modtail = mod->sml_next;
1120 slap_mod_free( &mod->sml_mod, 0 );
1123 modtail = &mod->sml_next;
1127 /* Strip out attrs in exattrs list */
1128 for ( modtail = modlist; *modtail ; ) {
1130 if ( ldap_charray_inlist( si->si_exattrs,
1131 mod->sml_desc->ad_type->sat_cname.bv_val )) {
1132 *modtail = mod->sml_next;
1133 slap_mod_free( &mod->sml_mod, 0 );
1136 modtail = &mod->sml_next;
1140 rc = slap_mods2entry( *modlist, &e, 1, 1, &text, txtbuf, textlen);
1141 if( rc != LDAP_SUCCESS ) {
1142 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods2entry (%s)\n",
1147 ber_free ( ber, 0 );
1148 if ( rc != LDAP_SUCCESS ) {
1158 /* During a refresh, we may get an LDAP_SYNC_ADD for an already existing
1159 * entry if a previous refresh was interrupted before sending us a new
1160 * context state. We try to compare the new entry to the existing entry
1161 * and ignore the new entry if they are the same.
1163 * Also, we may get an update where the entryDN has changed, due to
1164 * a ModDn on the provider. We detect this as well, so we can issue
1165 * the corresponding operation locally.
1167 * In the case of a modify, we get a list of all the attributes
1168 * in the original entry. Rather than deleting the entry and re-adding it,
1169 * we issue a Modify request that deletes all the attributes and adds all
1170 * the new ones. This avoids the issue of trying to delete/add a non-leaf
1173 * We don't try to otherwise distinguish ModDN from Modify; in the case of
1174 * a ModDN we will issue both operations on the local database.
1176 typedef struct dninfo {
1180 int renamed; /* Was an existing entry renamed? */
1181 int wasChanged; /* are the attributes changed? */
1182 int attrs; /* how many attribute types are in the ads list */
1183 AttributeDescription **ads;
1191 Modifications** modlist,
1193 struct berval* syncUUID,
1194 struct sync_cookie* syncCookie_req,
1195 struct berval* syncCSN )
1197 Backend *be = op->o_bd;
1198 slap_callback cb = { NULL };
1199 struct berval *syncuuid_bv = NULL;
1200 struct berval syncUUID_strrep = BER_BVNULL;
1201 struct berval uuid_bv = BER_BVNULL;
1203 SlapReply rs_search = {REP_RESULT};
1204 SlapReply rs_delete = {REP_RESULT};
1205 SlapReply rs_add = {REP_RESULT};
1206 SlapReply rs_modify = {REP_RESULT};
1208 AttributeAssertion ava = {0};
1209 int rc = LDAP_SUCCESS;
1210 int ret = LDAP_SUCCESS;
1212 struct berval pdn = BER_BVNULL;
1213 struct berval org_req_dn = BER_BVNULL;
1214 struct berval org_req_ndn = BER_BVNULL;
1215 struct berval org_dn = BER_BVNULL;
1216 struct berval org_ndn = BER_BVNULL;
1217 int org_managedsait;
1221 switch( syncstate ) {
1222 case LDAP_SYNC_PRESENT:
1223 Debug( LDAP_DEBUG_SYNC, "%s: %s\n",
1225 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_PRESENT)", 0 );
1228 Debug( LDAP_DEBUG_SYNC, "%s: %s\n",
1230 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_ADD)", 0 );
1232 case LDAP_SYNC_DELETE:
1233 Debug( LDAP_DEBUG_SYNC, "%s: %s\n",
1235 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_DELETE)", 0 );
1237 case LDAP_SYNC_MODIFY:
1238 Debug( LDAP_DEBUG_SYNC, "%s: %s\n",
1240 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_MODIFY)", 0 );
1243 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
1245 "LDAP_RES_SEARCH_ENTRY(UNKNOWN syncstate)", 0 );
1248 if (( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD )) {
1249 if ( !si->si_refreshPresent ) {
1250 syncuuid_bv = ber_dupbv( NULL, syncUUID );
1251 avl_insert( &si->si_presentlist, (caddr_t) syncuuid_bv,
1252 syncuuid_cmp, avl_dup_error );
1256 if ( syncstate == LDAP_SYNC_PRESENT ) {
1258 } else if ( syncstate != LDAP_SYNC_DELETE ) {
1259 if ( entry == NULL ) {
1264 f.f_choice = LDAP_FILTER_EQUALITY;
1266 ava.aa_desc = slap_schema.si_ad_entryUUID;
1267 (void)slap_uuidstr_from_normalized( &syncUUID_strrep, syncUUID, op->o_tmpmemctx );
1268 ava.aa_value = *syncUUID;
1269 op->ors_filter = &f;
1271 op->ors_filterstr.bv_len = STRLENOF( "entryUUID=" ) + syncUUID->bv_len;
1272 op->ors_filterstr.bv_val = (char *) slap_sl_malloc(
1273 op->ors_filterstr.bv_len + 1, op->o_tmpmemctx );
1274 AC_MEMCPY( op->ors_filterstr.bv_val, "entryUUID=", STRLENOF( "entryUUID=" ) );
1275 AC_MEMCPY( &op->ors_filterstr.bv_val[STRLENOF( "entryUUID=" )],
1276 syncUUID->bv_val, syncUUID->bv_len );
1277 op->ors_filterstr.bv_val[op->ors_filterstr.bv_len] = '\0';
1279 op->o_tag = LDAP_REQ_SEARCH;
1280 op->ors_scope = LDAP_SCOPE_SUBTREE;
1282 /* get syncrepl cookie of shadow replica from subentry */
1283 op->o_req_dn = si->si_base;
1284 op->o_req_ndn = si->si_base;
1286 op->o_time = slap_get_time();
1287 op->ors_tlimit = SLAP_NO_LIMIT;
1290 op->ors_attrs = slap_anlist_no_attrs;
1291 op->ors_attrsonly = 1;
1293 /* set callback function */
1294 op->o_callback = &cb;
1295 cb.sc_response = dn_callback;
1296 cb.sc_private = &dni;
1297 dni.new_entry = entry;
1299 if ( limits_check( op, &rs_search ) == 0 ) {
1300 rc = be->be_search( op, &rs_search );
1301 Debug( LDAP_DEBUG_SYNC,
1302 "syncrepl_entry: %s (%d)\n",
1303 "be_search", rc, 0 );
1306 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
1307 slap_sl_free( op->ors_filterstr.bv_val, op->o_tmpmemctx );
1310 cb.sc_response = null_callback;
1313 if ( entry && entry->e_name.bv_val ) {
1314 Debug( LDAP_DEBUG_SYNC,
1315 "syncrepl_entry: %s\n",
1316 entry->e_name.bv_val, 0, 0 );
1318 Debug( LDAP_DEBUG_SYNC,
1319 "syncrepl_entry: %s\n",
1320 dni.dn.bv_val ? dni.dn.bv_val : "(null)", 0, 0 );
1323 org_req_dn = op->o_req_dn;
1324 org_req_ndn = op->o_req_ndn;
1326 org_ndn = op->o_ndn;
1327 org_managedsait = get_manageDSAit( op );
1328 op->o_dn = op->o_bd->be_rootdn;
1329 op->o_ndn = op->o_bd->be_rootndn;
1330 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
1332 if ( syncstate != LDAP_SYNC_DELETE ) {
1333 attr_delete( &entry->e_attrs, slap_schema.si_ad_entryUUID );
1334 attr_merge_one( entry, slap_schema.si_ad_entryUUID,
1335 &syncUUID_strrep, syncUUID );
1338 switch ( syncstate ) {
1340 case LDAP_SYNC_MODIFY:
1342 if ( BER_BVISNULL( &dni.dn )) {
1344 op->o_req_dn = entry->e_name;
1345 op->o_req_ndn = entry->e_nname;
1346 op->o_tag = LDAP_REQ_ADD;
1349 rc = be->be_add( op, &rs_add );
1350 Debug( LDAP_DEBUG_SYNC,
1351 "syncrepl_entry: %s (%d)\n",
1353 switch ( rs_add.sr_err ) {
1355 be_entry_release_w( op, entry );
1360 /* we assume that LDAP_NO_SUCH_OBJECT is returned
1361 * only if the suffix entry is not present */
1362 case LDAP_NO_SUCH_OBJECT:
1363 syncrepl_add_glue( op, entry );
1367 /* if an entry was added via syncrepl_add_glue(),
1368 * it likely has no entryUUID, so the previous
1369 * be_search() doesn't find it. In this case,
1370 * give syncrepl a chance to modify it. */
1371 case LDAP_ALREADY_EXISTS:
1373 Operation op2 = *op;
1374 SlapReply rs2 = { 0 };
1375 slap_callback cb2 = { 0 };
1377 op2.o_tag = LDAP_REQ_SEARCH;
1378 ber_dupbv_x( &op2.o_req_dn,
1381 ber_dupbv_x( &op2.o_req_ndn,
1384 op2.ors_scope = LDAP_SCOPE_BASE;
1385 op2.ors_attrs = slap_anlist_all_attributes;
1386 op2.ors_attrsonly = 0;
1387 op2.ors_limit = NULL;
1389 op2.ors_tlimit = SLAP_NO_LIMIT;
1391 f.f_choice = LDAP_FILTER_EQUALITY;
1393 ava.aa_desc = slap_schema.si_ad_objectClass;
1394 ber_dupbv_x( &ava.aa_value,
1395 &slap_schema.si_oc_glue->soc_cname,
1397 op2.ors_filter = &f;
1398 filter2bv_x( &op2, op2.ors_filter,
1399 &op2.ors_filterstr );
1401 op2.o_callback = &cb2;
1402 cb2.sc_response = dn_callback;
1403 cb2.sc_private = &dni;
1405 be->be_search( &op2, &rs2 );
1407 op2.o_tmpfree( op2.o_req_dn.bv_val,
1409 op2.o_tmpfree( op2.o_req_ndn.bv_val,
1411 op2.o_tmpfree( ava.aa_value.bv_val,
1413 op2.o_tmpfree( op2.ors_filterstr.bv_val,
1422 Debug( LDAP_DEBUG_ANY,
1423 "syncrepl_entry : be_add failed (%d)\n",
1424 rs_add.sr_err, 0, 0 );
1431 op->o_req_dn = dni.dn;
1432 op->o_req_ndn = dni.ndn;
1433 if ( dni.renamed ) {
1434 struct berval noldp, newp, nnewp;
1436 op->o_tag = LDAP_REQ_MODRDN;
1437 dnRdn( &entry->e_name, &op->orr_newrdn );
1438 dnRdn( &entry->e_nname, &op->orr_nnewrdn );
1440 dnParent( &dni.ndn, &noldp );
1441 dnParent( &entry->e_nname, &nnewp );
1442 if ( !dn_match( &noldp, &newp )) {
1443 dnParent( &entry->e_name, &newp );
1444 op->orr_newSup = &newp;
1445 op->orr_nnewSup = &nnewp;
1447 op->orr_deleteoldrdn = 0;
1448 rc = be->be_modrdn( op, &rs_modify );
1449 Debug( LDAP_DEBUG_SYNC,
1450 "syncrepl_entry: %s (%d)\n",
1451 "be_modrdn", rc, 0 );
1452 if ( rs_modify.sr_err == LDAP_SUCCESS ) {
1453 op->o_req_dn = entry->e_name;
1454 op->o_req_ndn = entry->e_nname;
1460 if ( dni.wasChanged ) {
1461 Modifications *mod, *modhead = NULL;
1462 Modifications *modtail = NULL;
1465 op->o_tag = LDAP_REQ_MODIFY;
1469 /* Delete all the old attrs */
1470 for ( i=0; i<dni.attrs; i++) {
1471 mod = ch_malloc( sizeof(Modifications));
1472 mod->sml_op = LDAP_MOD_DELETE;
1473 mod->sml_desc = dni.ads[i];
1474 mod->sml_type =mod->sml_desc->ad_cname;
1475 mod->sml_values = NULL;
1476 mod->sml_nvalues = NULL;
1477 if ( !modhead ) modhead = mod;
1479 modtail->sml_next = mod;
1484 /* Append passed in list to ours */
1486 modtail->sml_next = *modlist;
1492 /* Find end of this list */
1493 for ( ; mod != NULL; mod = mod->sml_next ) {
1497 mod = (Modifications *)ch_calloc(1, sizeof(Modifications));
1498 mod->sml_op = LDAP_MOD_REPLACE;
1499 mod->sml_desc = slap_schema.si_ad_entryUUID;
1500 mod->sml_type = mod->sml_desc->ad_cname;
1501 ber_dupbv( &uuid_bv, &syncUUID_strrep );
1502 ber_bvarray_add( &mod->sml_values, &uuid_bv );
1503 ber_dupbv( &uuid_bv, syncUUID );
1504 ber_bvarray_add( &mod->sml_nvalues, &uuid_bv );
1505 modtail->sml_next = mod;
1507 op->o_tag = LDAP_REQ_MODIFY;
1508 op->orm_modlist = *modlist;
1510 rc = be->be_modify( op, &rs_modify );
1511 Debug( LDAP_DEBUG_SYNC,
1512 "syncrepl_entry: %s (%d)\n",
1513 "be_modify", rc, 0 );
1514 if ( rs_modify.sr_err != LDAP_SUCCESS ) {
1515 Debug( LDAP_DEBUG_ANY,
1516 "syncrepl_entry : be_modify failed (%d)\n",
1517 rs_modify.sr_err, 0, 0 );
1522 case LDAP_SYNC_DELETE :
1523 if ( !BER_BVISNULL( &dni.dn )) {
1524 op->o_req_dn = dni.dn;
1525 op->o_req_ndn = dni.ndn;
1526 op->o_tag = LDAP_REQ_DELETE;
1527 rc = be->be_delete( op, &rs_delete );
1528 Debug( LDAP_DEBUG_SYNC,
1529 "syncrepl_entry: %s (%d)\n",
1530 "be_delete", rc, 0 );
1532 while ( rs_delete.sr_err == LDAP_SUCCESS
1533 && op->o_delete_glue_parent ) {
1534 op->o_delete_glue_parent = 0;
1535 if ( !be_issuffix( op->o_bd, &op->o_req_ndn )) {
1536 slap_callback cb = { NULL };
1537 cb.sc_response = slap_null_cb;
1538 dnParent( &op->o_req_ndn, &pdn );
1540 op->o_req_ndn = pdn;
1541 op->o_callback = &cb;
1542 op->o_bd->be_delete( op, &rs_delete );
1552 Debug( LDAP_DEBUG_ANY,
1553 "syncrepl_entry : unknown syncstate\n", 0, 0, 0 );
1559 if ( !BER_BVISNULL( &syncUUID_strrep ) ) {
1560 slap_sl_free( syncUUID_strrep.bv_val, op->o_tmpmemctx );
1561 BER_BVZERO( &syncUUID_strrep );
1564 op->o_tmpfree( dni.ads, op->o_tmpmemctx );
1566 if ( !BER_BVISNULL( &dni.ndn ) ) {
1567 op->o_tmpfree( dni.ndn.bv_val, op->o_tmpmemctx );
1569 if ( !BER_BVISNULL( &dni.dn ) ) {
1570 op->o_tmpfree( dni.dn.bv_val, op->o_tmpmemctx );
1575 static struct berval gcbva[] = {
1582 syncrepl_del_nonpresent(
1586 Backend* be = op->o_bd;
1587 slap_callback cb = { NULL };
1588 SlapReply rs_search = {REP_RESULT};
1589 SlapReply rs_delete = {REP_RESULT};
1590 SlapReply rs_modify = {REP_RESULT};
1591 struct nonpresent_entry *np_list, *np_prev;
1594 Modifications *mlnext;
1596 Modifications *modlist = NULL;
1597 Modifications **modtail;
1598 AttributeName an[2];
1600 struct berval pdn = BER_BVNULL;
1601 struct berval org_req_dn = BER_BVNULL;
1602 struct berval org_req_ndn = BER_BVNULL;
1603 struct berval org_dn = BER_BVNULL;
1604 struct berval org_ndn = BER_BVNULL;
1605 int org_managedsait;
1607 op->o_req_dn = si->si_base;
1608 op->o_req_ndn = si->si_base;
1610 cb.sc_response = nonpresent_callback;
1613 op->o_callback = &cb;
1614 op->o_tag = LDAP_REQ_SEARCH;
1615 op->ors_scope = si->si_scope;
1616 op->ors_deref = LDAP_DEREF_NEVER;
1617 op->o_time = slap_get_time();
1618 op->ors_tlimit = SLAP_NO_LIMIT;
1619 op->ors_slimit = SLAP_NO_LIMIT;
1621 memset( &an[0], 0, 2 * sizeof( AttributeName ) );
1622 an[0].an_name = slap_schema.si_ad_entryUUID->ad_cname;
1623 an[0].an_desc = slap_schema.si_ad_entryUUID;
1626 op->ors_attrsonly = 0;
1627 op->ors_filter = str2filter_x( op, si->si_filterstr.bv_val );
1628 op->ors_filterstr = si->si_filterstr;
1630 op->o_nocaching = 1;
1631 op->o_managedsait = SLAP_CONTROL_NONE;
1633 if ( limits_check( op, &rs_search ) == 0 ) {
1634 rc = be->be_search( op, &rs_search );
1637 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
1638 op->o_nocaching = 0;
1640 if ( op->ors_filter ) filter_free_x( op, op->ors_filter );
1642 if ( !LDAP_LIST_EMPTY( &si->si_nonpresentlist ) ) {
1643 np_list = LDAP_LIST_FIRST( &si->si_nonpresentlist );
1644 while ( np_list != NULL ) {
1645 LDAP_LIST_REMOVE( np_list, npe_link );
1647 np_list = LDAP_LIST_NEXT( np_list, npe_link );
1648 op->o_tag = LDAP_REQ_DELETE;
1649 op->o_callback = &cb;
1650 cb.sc_response = null_callback;
1652 op->o_req_dn = *np_prev->npe_name;
1653 op->o_req_ndn = *np_prev->npe_nname;
1654 rc = op->o_bd->be_delete( op, &rs_delete );
1656 if ( rs_delete.sr_err == LDAP_NOT_ALLOWED_ON_NONLEAF ) {
1658 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1659 mod->sml_op = LDAP_MOD_REPLACE;
1660 mod->sml_desc = slap_schema.si_ad_objectClass;
1661 mod->sml_type = mod->sml_desc->ad_cname;
1662 mod->sml_values = &gcbva[0];
1664 modtail = &mod->sml_next;
1666 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1667 mod->sml_op = LDAP_MOD_REPLACE;
1668 mod->sml_desc = slap_schema.si_ad_structuralObjectClass;
1669 mod->sml_type = mod->sml_desc->ad_cname;
1670 mod->sml_values = &gcbva[1];
1672 modtail = &mod->sml_next;
1674 op->o_tag = LDAP_REQ_MODIFY;
1675 op->orm_modlist = modlist;
1677 rc = be->be_modify( op, &rs_modify );
1679 for ( ml = modlist; ml != NULL; ml = mlnext ) {
1680 mlnext = ml->sml_next;
1685 org_req_dn = op->o_req_dn;
1686 org_req_ndn = op->o_req_ndn;
1688 org_ndn = op->o_ndn;
1689 org_managedsait = get_manageDSAit( op );
1690 op->o_dn = op->o_bd->be_rootdn;
1691 op->o_ndn = op->o_bd->be_rootndn;
1692 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
1694 while ( rs_delete.sr_err == LDAP_SUCCESS &&
1695 op->o_delete_glue_parent ) {
1696 op->o_delete_glue_parent = 0;
1697 if ( !be_issuffix( op->o_bd, &op->o_req_ndn )) {
1698 slap_callback cb = { NULL };
1699 cb.sc_response = slap_null_cb;
1700 dnParent( &op->o_req_ndn, &pdn );
1702 op->o_req_ndn = pdn;
1703 op->o_callback = &cb;
1704 /* give it a root privil ? */
1705 op->o_bd->be_delete( op, &rs_delete );
1711 op->o_managedsait = org_managedsait;
1713 op->o_ndn = org_ndn;
1714 op->o_req_dn = org_req_dn;
1715 op->o_req_ndn = org_req_ndn;
1716 op->o_delete_glue_parent = 0;
1718 ber_bvfree( np_prev->npe_name );
1719 ber_bvfree( np_prev->npe_nname );
1720 BER_BVZERO( &op->o_req_dn );
1721 BER_BVZERO( &op->o_req_ndn );
1734 Backend *be = op->o_bd;
1735 slap_callback cb = { NULL };
1740 struct berval dn = {0, NULL};
1741 struct berval ndn = {0, NULL};
1743 SlapReply rs_add = {REP_RESULT};
1746 op->o_tag = LDAP_REQ_ADD;
1747 op->o_callback = &cb;
1748 cb.sc_response = null_callback;
1749 cb.sc_private = NULL;
1754 /* count RDNs in suffix */
1755 if ( !BER_BVISEMPTY( &be->be_nsuffix[0] ) ) {
1756 for ( i = 0, ptr = be->be_nsuffix[0].bv_val; ptr; ptr = strchr( ptr, ',' ) ) {
1766 /* Start with BE suffix */
1767 for ( i = 0, ptr = NULL; i < suffrdns; i++ ) {
1768 comma = strrchr( dn.bv_val, ',' );
1769 if ( ptr ) *ptr = ',';
1770 if ( comma ) *comma = '\0';
1775 dn.bv_len -= ptr - dn.bv_val;
1778 /* the normalizedDNs are always the same length, no counting
1781 if ( ndn.bv_len > be->be_nsuffix[0].bv_len ) {
1782 ndn.bv_val += ndn.bv_len - be->be_nsuffix[0].bv_len;
1783 ndn.bv_len = be->be_nsuffix[0].bv_len;
1786 while ( ndn.bv_val > e->e_nname.bv_val ) {
1787 glue = (Entry *) ch_calloc( 1, sizeof(Entry) );
1788 ber_dupbv( &glue->e_name, &dn );
1789 ber_dupbv( &glue->e_nname, &ndn );
1791 a = ch_calloc( 1, sizeof( Attribute ));
1792 a->a_desc = slap_schema.si_ad_objectClass;
1794 a->a_vals = ch_calloc( 3, sizeof( struct berval ));
1795 ber_dupbv( &a->a_vals[0], &gcbva[0] );
1796 ber_dupbv( &a->a_vals[1], &gcbva[1] );
1797 ber_dupbv( &a->a_vals[2], &gcbva[2] );
1799 a->a_nvals = a->a_vals;
1801 a->a_next = glue->e_attrs;
1804 a = ch_calloc( 1, sizeof( Attribute ));
1805 a->a_desc = slap_schema.si_ad_structuralObjectClass;
1807 a->a_vals = ch_calloc( 2, sizeof( struct berval ));
1808 ber_dupbv( &a->a_vals[0], &gcbva[1] );
1809 ber_dupbv( &a->a_vals[1], &gcbva[2] );
1811 a->a_nvals = a->a_vals;
1813 a->a_next = glue->e_attrs;
1816 op->o_req_dn = glue->e_name;
1817 op->o_req_ndn = glue->e_nname;
1819 rc = be->be_add ( op, &rs_add );
1820 if ( rs_add.sr_err == LDAP_SUCCESS ) {
1821 be_entry_release_w( op, glue );
1823 /* incl. ALREADY EXIST */
1827 /* Move to next child */
1828 for (ptr = dn.bv_val-2; ptr > e->e_name.bv_val && *ptr != ','; ptr--) {
1831 if ( ptr == e->e_name.bv_val ) break;
1833 dn.bv_len = e->e_name.bv_len - (ptr-e->e_name.bv_val);
1834 for( ptr = ndn.bv_val-2;
1835 ptr > e->e_nname.bv_val && *ptr != ',';
1841 ndn.bv_len = e->e_nname.bv_len - (ptr-e->e_nname.bv_val);
1844 op->o_req_dn = e->e_name;
1845 op->o_req_ndn = e->e_nname;
1847 rc = be->be_add ( op, &rs_add );
1848 if ( rs_add.sr_err == LDAP_SUCCESS ) {
1849 be_entry_release_w( op, e );
1857 static struct berval ocbva[] = {
1859 BER_BVC("subentry"),
1860 BER_BVC("syncConsumerSubentry"),
1864 static struct berval cnbva[] = {
1869 static struct berval ssbva[] = {
1874 static struct berval scbva[] = {
1880 syncrepl_updateCookie(
1884 struct sync_cookie *syncCookie )
1886 Backend *be = op->o_bd;
1888 Modifications *mlnext;
1890 Modifications *modlist = NULL;
1891 Modifications **modtail = &modlist;
1894 char txtbuf[SLAP_TEXT_BUFLEN];
1895 size_t textlen = sizeof txtbuf;
1900 char syncrepl_cbuf[sizeof(CN_STR SYNCREPL_STR)];
1901 struct berval slap_syncrepl_dn_bv = BER_BVNULL;
1902 struct berval slap_syncrepl_cn_bv = BER_BVNULL;
1904 slap_callback cb = { NULL };
1905 SlapReply rs_add = {REP_RESULT};
1906 SlapReply rs_modify = {REP_RESULT};
1908 slap_sync_cookie_free( &si->si_syncCookie, 0 );
1909 slap_dup_sync_cookie( &si->si_syncCookie, syncCookie );
1911 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1912 mod->sml_op = LDAP_MOD_REPLACE;
1913 mod->sml_desc = slap_schema.si_ad_objectClass;
1914 mod->sml_type = mod->sml_desc->ad_cname;
1915 mod->sml_values = ocbva;
1917 modtail = &mod->sml_next;
1919 ber_dupbv( &cnbva[0], (struct berval *) &slap_syncrepl_bvc );
1920 assert( si->si_rid < 1000 );
1921 cnbva[0].bv_len = snprintf( cnbva[0].bv_val,
1922 slap_syncrepl_bvc.bv_len + 1,
1923 "syncrepl%ld", si->si_rid );
1924 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1925 mod->sml_op = LDAP_MOD_REPLACE;
1926 mod->sml_desc = slap_schema.si_ad_cn;
1927 mod->sml_type = mod->sml_desc->ad_cname;
1928 mod->sml_values = cnbva;
1930 modtail = &mod->sml_next;
1932 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1933 mod->sml_op = LDAP_MOD_REPLACE;
1934 mod->sml_desc = slap_schema.si_ad_subtreeSpecification;
1935 mod->sml_type = mod->sml_desc->ad_cname;
1936 mod->sml_values = ssbva;
1938 modtail = &mod->sml_next;
1940 /* Keep this last, so we can avoid touching the previous
1941 * attributes unnecessarily.
1943 if ( scbva[0].bv_val ) ch_free( scbva[0].bv_val );
1944 ber_dupbv( &scbva[0], &si->si_syncCookie.octet_str[0] );
1945 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1946 mod->sml_op = LDAP_MOD_REPLACE;
1947 mod->sml_desc = slap_schema.si_ad_syncreplCookie;
1948 mod->sml_type = mod->sml_desc->ad_cname;
1949 mod->sml_values = scbva;
1951 modtail = &mod->sml_next;
1953 slap_queue_csn( op, si->si_syncCookie.ctxcsn );
1957 op->o_tag = LDAP_REQ_ADD;
1958 rc = slap_mods_opattrs( op, modlist, modtail,
1959 &text, txtbuf, textlen, 0 );
1961 for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
1962 ml->sml_op = LDAP_MOD_REPLACE;
1965 if( rc != LDAP_SUCCESS ) {
1966 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods opattrs (%s)\n",
1970 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
1972 slap_syncrepl_cn_bv.bv_val = syncrepl_cbuf;
1973 assert( si->si_rid < 1000 );
1974 slap_syncrepl_cn_bv.bv_len = snprintf( slap_syncrepl_cn_bv.bv_val,
1975 slap_syncrepl_cn_bvc.bv_len + 1,
1976 "cn=syncrepl%ld", si->si_rid );
1978 build_new_dn( &slap_syncrepl_dn_bv, pdn, &slap_syncrepl_cn_bv,
1980 ber_dupbv( &e->e_name, &slap_syncrepl_dn_bv );
1981 ber_dupbv( &e->e_nname, &slap_syncrepl_dn_bv );
1983 if ( !BER_BVISNULL( &slap_syncrepl_dn_bv ) ) {
1984 slap_sl_free( slap_syncrepl_dn_bv.bv_val, op->o_tmpmemctx );
1989 rc = slap_mods2entry( modlist, &e, 1, 1, &text, txtbuf, textlen );
1991 if( rc != LDAP_SUCCESS ) {
1992 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods2entry (%s)\n",
1996 cb.sc_response = null_callback;
1999 op->o_callback = &cb;
2000 op->o_req_dn = e->e_name;
2001 op->o_req_ndn = e->e_nname;
2003 /* update persistent cookie */
2004 update_cookie_retry:
2005 op->o_tag = LDAP_REQ_MODIFY;
2006 /* Just modify the cookie value, not the entire entry */
2007 op->orm_modlist = mod;
2008 rc = be->be_modify( op, &rs_modify );
2010 if ( rs_modify.sr_err != LDAP_SUCCESS ) {
2011 if ( rs_modify.sr_err == LDAP_REFERRAL ||
2012 rs_modify.sr_err == LDAP_NO_SUCH_OBJECT ) {
2013 op->o_tag = LDAP_REQ_ADD;
2015 rc = be->be_add( op, &rs_add );
2016 if ( rs_add.sr_err != LDAP_SUCCESS ) {
2017 if ( rs_add.sr_err == LDAP_ALREADY_EXISTS ) {
2018 goto update_cookie_retry;
2019 } else if ( rs_add.sr_err == LDAP_REFERRAL ||
2020 rs_add.sr_err == LDAP_NO_SUCH_OBJECT ) {
2021 Debug( LDAP_DEBUG_ANY,
2022 "cookie will be non-persistent\n",
2025 Debug( LDAP_DEBUG_ANY,
2026 "be_add failed (%d)\n", rs_add.sr_err, 0, 0 );
2029 be_entry_release_w( op, e );
2033 Debug( LDAP_DEBUG_ANY,
2034 "be_modify failed (%d)\n", rs_modify.sr_err, 0, 0 );
2042 slap_graduate_commit_csn( op );
2045 if ( !BER_BVISNULL( &cnbva[0] ) ) {
2046 ch_free( cnbva[0].bv_val );
2047 BER_BVZERO( &cnbva[0] );
2049 if ( !BER_BVISNULL( &scbva[0] ) ) {
2050 ch_free( scbva[0].bv_val );
2051 BER_BVZERO( &scbva[0] );
2054 if ( mlnext->sml_next ) {
2055 slap_mods_free( mlnext->sml_next );
2056 mlnext->sml_next = NULL;
2059 for (ml = modlist ; ml != NULL; ml = mlnext ) {
2060 mlnext = ml->sml_next;
2068 syncrepl_isupdate( Operation *op )
2070 return ( syncrepl_isupdate_dn( op->o_bd, &op->o_ndn ));
2074 syncrepl_isupdate_dn(
2076 struct berval* ndn )
2081 if ( !LDAP_STAILQ_EMPTY( &be->be_syncinfo )) {
2082 LDAP_STAILQ_FOREACH( si, &be->be_syncinfo, si_next ) {
2083 if ( ( ret = dn_match( &si->si_updatedn, ndn ) ) ) {
2096 dninfo *dni = op->o_callback->sc_private;
2098 if ( rs->sr_type == REP_SEARCH ) {
2099 if ( !BER_BVISNULL( &dni->dn ) ) {
2100 Debug( LDAP_DEBUG_ANY,
2101 "dn_callback : consistency error - "
2102 "entryUUID is not unique\n", 0, 0, 0 );
2104 ber_dupbv_x( &dni->dn, &rs->sr_entry->e_name, op->o_tmpmemctx );
2105 ber_dupbv_x( &dni->ndn, &rs->sr_entry->e_nname, op->o_tmpmemctx );
2106 /* If there is a new entry, see if it differs from the old.
2107 * We compare the non-normalized values so that cosmetic changes
2108 * in the provider are always propagated.
2110 if ( dni->new_entry ) {
2111 Attribute *old, *new;
2114 /* Did the DN change? */
2115 if ( !dn_match( &rs->sr_entry->e_name,
2116 &dni->new_entry->e_name ) )
2121 for ( i = 0, old = rs->sr_entry->e_attrs;
2123 i++, old = old->a_next )
2128 for ( old = rs->sr_entry->e_attrs, new = dni->new_entry->e_attrs;
2130 old = old->a_next, new = new->a_next )
2132 if ( old->a_desc != new->a_desc ) {
2133 dni->wasChanged = 1;
2136 for ( i = 0; ; i++ ) {
2138 nold = BER_BVISNULL( &old->a_vals[i] );
2139 nnew = BER_BVISNULL( &new->a_vals[i] );
2140 /* If both are empty, stop looking */
2141 if ( nold && nnew ) {
2144 /* If they are different, stop looking */
2145 if ( nold != nnew ) {
2146 dni->wasChanged = 1;
2149 if ( ber_bvcmp( &old->a_vals[i], &new->a_vals[i] )) {
2150 dni->wasChanged = 1;
2154 if ( dni->wasChanged ) break;
2156 if ( dni->wasChanged ) {
2157 dni->ads = op->o_tmpalloc( dni->attrs *
2158 sizeof(AttributeDescription *), op->o_tmpmemctx );
2160 for ( old = rs->sr_entry->e_attrs; old; old = old->a_next ) {
2161 dni->ads[i] = old->a_desc;
2167 } else if ( rs->sr_type == REP_RESULT ) {
2168 if ( rs->sr_err == LDAP_SIZELIMIT_EXCEEDED ) {
2169 Debug( LDAP_DEBUG_ANY,
2170 "dn_callback : consistency error - "
2171 "entryUUID is not unique\n", 0, 0, 0 );
2175 return LDAP_SUCCESS;
2179 nonpresent_callback(
2183 syncinfo_t *si = op->o_callback->sc_private;
2186 struct berval* present_uuid = NULL;
2187 struct nonpresent_entry *np_entry;
2189 if ( rs->sr_type == REP_RESULT ) {
2190 count = avl_free( si->si_presentlist, avl_ber_bvfree );
2191 si->si_presentlist = NULL;
2193 } else if ( rs->sr_type == REP_SEARCH ) {
2194 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID );
2196 if ( a == NULL ) return 0;
2198 present_uuid = avl_find( si->si_presentlist, &a->a_nvals[0],
2201 if ( present_uuid == NULL ) {
2202 np_entry = (struct nonpresent_entry *)
2203 ch_calloc( 1, sizeof( struct nonpresent_entry ));
2204 np_entry->npe_name = ber_dupbv( NULL, &rs->sr_entry->e_name );
2205 np_entry->npe_nname = ber_dupbv( NULL, &rs->sr_entry->e_nname );
2206 LDAP_LIST_INSERT_HEAD( &si->si_nonpresentlist, np_entry, npe_link );
2209 avl_delete( &si->si_presentlist,
2210 &a->a_nvals[0], syncuuid_cmp );
2211 ch_free( present_uuid->bv_val );
2212 ch_free( present_uuid );
2215 return LDAP_SUCCESS;
2223 if ( rs->sr_err != LDAP_SUCCESS &&
2224 rs->sr_err != LDAP_REFERRAL &&
2225 rs->sr_err != LDAP_ALREADY_EXISTS &&
2226 rs->sr_err != LDAP_NO_SUCH_OBJECT &&
2227 rs->sr_err != LDAP_NOT_ALLOWED_ON_NONLEAF )
2229 Debug( LDAP_DEBUG_ANY,
2230 "null_callback : error code 0x%x\n",
2233 return LDAP_SUCCESS;
2237 slap_create_syncrepl_entry(
2239 struct berval *context_csn,
2247 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
2249 attr_merge( e, slap_schema.si_ad_objectClass, ocbva, NULL );
2251 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass,
2254 attr_merge_one( e, slap_schema.si_ad_cn, cn, NULL );
2256 if ( context_csn ) {
2257 attr_merge_one( e, slap_schema.si_ad_syncreplCookie,
2258 context_csn, NULL );
2261 BER_BVSTR( &bv, "{}" );
2262 attr_merge_one( e, slap_schema.si_ad_subtreeSpecification, &bv, NULL );
2264 build_new_dn( &e->e_name, &be->be_nsuffix[0], rdn, NULL );
2265 ber_dupbv( &e->e_nname, &e->e_name );
2271 slap_uuidstr_from_normalized(
2272 struct berval* uuidstr,
2273 struct berval* normalized,
2277 unsigned char nibble;
2280 if ( normalized == NULL ) return NULL;
2281 if ( normalized->bv_len != 16 ) return NULL;
2286 new = (struct berval *)slap_sl_malloc( sizeof(struct berval), ctx );
2287 if ( new == NULL ) {
2294 if ( ( new->bv_val = slap_sl_malloc( new->bv_len + 1, ctx ) ) == NULL ) {
2295 if ( new != uuidstr ) {
2296 slap_sl_free( new, ctx );
2301 for ( i = 0; i < 16; i++ ) {
2302 if ( i == 4 || i == 6 || i == 8 || i == 10 ) {
2303 new->bv_val[(i<<1)+d] = '-';
2307 nibble = (normalized->bv_val[i] >> 4) & 0xF;
2308 if ( nibble < 10 ) {
2309 new->bv_val[(i<<1)+d] = nibble + '0';
2311 new->bv_val[(i<<1)+d] = nibble - 10 + 'a';
2314 nibble = (normalized->bv_val[i]) & 0xF;
2315 if ( nibble < 10 ) {
2316 new->bv_val[(i<<1)+d+1] = nibble + '0';
2318 new->bv_val[(i<<1)+d+1] = nibble - 10 + 'a';
2322 new->bv_val[new->bv_len] = '\0';
2327 syncuuid_cmp( const void* v_uuid1, const void* v_uuid2 )
2329 const struct berval *uuid1 = v_uuid1;
2330 const struct berval *uuid2 = v_uuid2;
2331 int rc = uuid1->bv_len - uuid2->bv_len;
2332 if ( rc ) return rc;
2333 return ( memcmp( uuid1->bv_val, uuid2->bv_val, uuid1->bv_len ) );
2337 avl_ber_bvfree( void *v_bv )
2339 struct berval *bv = (struct berval *)v_bv;
2341 if( v_bv == NULL ) return;
2342 if ( !BER_BVISNULL( bv ) ) {
2343 ch_free( bv->bv_val );
2345 ch_free( (char *) bv );
2349 syncinfo_free( syncinfo_t *sie )
2351 if ( sie->si_provideruri ) {
2352 ch_free( sie->si_provideruri );
2354 if ( sie->si_provideruri_bv ) {
2355 ber_bvarray_free( sie->si_provideruri_bv );
2357 if ( sie->si_updatedn.bv_val ) {
2358 ch_free( sie->si_updatedn.bv_val );
2360 if ( sie->si_binddn ) {
2361 ch_free( sie->si_binddn );
2363 if ( sie->si_passwd ) {
2364 ch_free( sie->si_passwd );
2366 if ( sie->si_saslmech ) {
2367 ch_free( sie->si_saslmech );
2369 if ( sie->si_secprops ) {
2370 ch_free( sie->si_secprops );
2372 if ( sie->si_realm ) {
2373 ch_free( sie->si_realm );
2375 if ( sie->si_authcId ) {
2376 ch_free( sie->si_authcId );
2378 if ( sie->si_authzId ) {
2379 ch_free( sie->si_authzId );
2381 if ( sie->si_filterstr.bv_val ) {
2382 ch_free( sie->si_filterstr.bv_val );
2384 if ( sie->si_base.bv_val ) {
2385 ch_free( sie->si_base.bv_val );
2387 if ( sie->si_attrs ) {
2389 while ( sie->si_attrs[i] != NULL ) {
2390 ch_free( sie->si_attrs[i] );
2393 ch_free( sie->si_attrs );
2395 if ( sie->si_exattrs ) {
2397 while ( sie->si_exattrs[i] != NULL ) {
2398 ch_free( sie->si_exattrs[i] );
2401 ch_free( sie->si_exattrs );
2403 if ( sie->si_anlist ) {
2405 while ( sie->si_anlist[i].an_name.bv_val != NULL ) {
2406 ch_free( sie->si_anlist[i].an_name.bv_val );
2409 ch_free( sie->si_anlist );
2411 if ( sie->si_exanlist ) {
2413 while ( sie->si_exanlist[i].an_name.bv_val != NULL ) {
2414 ch_free( sie->si_exanlist[i].an_name.bv_val );
2417 ch_free( sie->si_exanlist );
2419 if ( sie->si_retryinterval ) {
2420 ch_free( sie->si_retryinterval );
2422 if ( sie->si_retrynum ) {
2423 ch_free( sie->si_retrynum );
2425 if ( sie->si_retrynum_init ) {
2426 ch_free( sie->si_retrynum_init );
2428 slap_sync_cookie_free( &sie->si_syncCookie, 0 );
2429 if ( sie->si_presentlist ) {
2430 avl_free( sie->si_presentlist, avl_ber_bvfree );
2433 ldap_ld_free( sie->si_ld, 1, NULL, NULL );
2435 while ( !LDAP_LIST_EMPTY( &sie->si_nonpresentlist )) {
2436 struct nonpresent_entry* npe;
2437 npe = LDAP_LIST_FIRST( &sie->si_nonpresentlist );
2438 LDAP_LIST_REMOVE( npe, npe_link );
2439 if ( npe->npe_name ) {
2440 if ( npe->npe_name->bv_val ) {
2441 ch_free( npe->npe_name->bv_val );
2443 ch_free( npe->npe_name );
2445 if ( npe->npe_nname ) {
2446 if ( npe->npe_nname->bv_val ) {
2447 ch_free( npe->npe_nname->bv_val );
2449 ch_free( npe->npe_nname );