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 *, BerVarray );
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];
54 init_syncrepl(syncinfo_t *si)
57 char **attrs, **exattrs;
59 if ( !sync_descs[0] ) {
60 sync_descs[0] = slap_schema.si_ad_objectClass;
61 sync_descs[1] = slap_schema.si_ad_structuralObjectClass;
62 sync_descs[2] = slap_schema.si_ad_entryCSN;
66 if ( si->si_allattrs && si->si_allopattrs )
69 attrs = anlist2attrs( si->si_anlist );
72 if ( si->si_allattrs ) {
75 if ( !is_at_operational( at_find( attrs[i] ))) {
76 for ( j = i; attrs[j] != NULL; j++ ) {
79 attrs[j] = attrs[j+1];
85 attrs = ( char ** ) ch_realloc( attrs, (i + 2)*sizeof( char * ) );
86 attrs[i] = ch_strdup("*");
89 } else if ( si->si_allopattrs ) {
92 if ( is_at_operational( at_find( attrs[i] ))) {
93 for ( j = i; attrs[j] != NULL; j++ ) {
96 attrs[j] = attrs[j+1];
102 attrs = ( char ** ) ch_realloc( attrs, (i + 2)*sizeof( char * ) );
103 attrs[i] = ch_strdup("+");
107 for ( i = 0; sync_descs[i] != NULL; i++ ) {
110 if ( !strcmp( attrs[j], sync_descs[i]->ad_cname.bv_val )) {
111 for ( k = j; attrs[k] != NULL; k++ ) {
114 attrs[k] = attrs[k+1];
122 for ( n = 0; attrs[ n ] != NULL; n++ ) /* empty */;
124 if ( si->si_allopattrs ) {
125 attrs = ( char ** ) ch_realloc( attrs, (n + 2)*sizeof( char * ));
127 attrs = ( char ** ) ch_realloc( attrs, (n + 4)*sizeof( char * ));
130 if ( attrs == NULL ) {
131 Debug( LDAP_DEBUG_ANY, "out of memory\n", 0,0,0 );
135 if ( si->si_allopattrs ) {
136 attrs[n++] = ch_strdup( sync_descs[0]->ad_cname.bv_val );
138 for ( i = 0; sync_descs[ i ] != NULL; i++ ) {
139 attrs[ n++ ] = ch_strdup ( sync_descs[i]->ad_cname.bv_val );
147 if ( si->si_allattrs == si->si_allopattrs ) {
148 attrs = (char**) ch_malloc( 3 * sizeof(char*) );
149 attrs[i++] = ch_strdup( "*" );
150 attrs[i++] = ch_strdup( "+" );
151 } else if ( si->si_allattrs && !si->si_allopattrs ) {
152 for ( n = 0; sync_descs[ n ] != NULL; n++ ) ;
153 attrs = (char**) ch_malloc( (n+1)* sizeof(char*) );
154 attrs[i++] = ch_strdup( "*" );
155 for ( j = 1; sync_descs[ j ] != NULL; j++ ) {
156 attrs[i++] = ch_strdup ( sync_descs[j]->ad_cname.bv_val );
158 } else if ( !si->si_allattrs && si->si_allopattrs ) {
159 attrs = (char**) ch_malloc( 3 * sizeof(char*) );
160 attrs[i++] = ch_strdup( "+" );
161 attrs[i++] = ch_strdup( sync_descs[0]->ad_cname.bv_val );
166 si->si_attrs = attrs;
168 exattrs = anlist2attrs( si->si_exanlist );
171 for ( n = 0; exattrs[n] != NULL; n++ ) ;
173 for ( i = 0; sync_descs[i] != NULL; i++ ) {
175 while ( exattrs[j] != NULL ) {
176 if ( !strcmp( exattrs[j], sync_descs[i]->ad_cname.bv_val )) {
177 for ( k = j; exattrs[k] != NULL; k++ ) {
179 ch_free( exattrs[k] );
180 exattrs[k] = exattrs[k+1];
188 for ( i = 0; exattrs[i] != NULL; i++ ) {
189 for ( j = 0; si->si_anlist[j].an_name.bv_val; j++ ) {
191 if ( ( oc = si->si_anlist[j].an_oc ) ) {
193 while ( oc->soc_required[k] ) {
194 if ( !strcmp( exattrs[i],
195 oc->soc_required[k]->sat_cname.bv_val )) {
196 for ( l = i; exattrs[l]; l++ ) {
198 ch_free( exattrs[i] );
199 exattrs[l] = exattrs[l+1];
209 for ( i = 0; exattrs[i] != NULL; i++ ) ;
212 exattrs = (char **) ch_realloc( exattrs, (i + 1)*sizeof(char *));
215 si->si_exattrs = exattrs;
223 BerElementBuffer berbuf;
224 BerElement *ber = (BerElement *)&berbuf;
225 LDAPControl c[2], *ctrls[3];
226 struct timeval timeout;
230 /* setup LDAP SYNC control */
231 ber_init2( ber, NULL, LBER_USE_DER );
232 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &ctx );
234 if ( si->si_syncCookie.octet_str &&
235 !BER_BVISNULL( &si->si_syncCookie.octet_str[0] ) )
237 ber_printf( ber, "{eO}",
239 &si->si_syncCookie.octet_str[0] );
241 ber_printf( ber, "{e}",
245 if ( (rc = ber_flatten2( ber, &c[0].ldctl_value, 0 )) == LBER_ERROR ) {
250 c[0].ldctl_oid = LDAP_CONTROL_SYNC;
251 c[0].ldctl_iscritical = si->si_type < 0;
254 if ( si->si_authzId ) {
255 c[1].ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
256 ber_str2bv( si->si_authzId, 0, 0, &c[1].ldctl_value );
257 c[1].ldctl_iscritical = 1;
264 timeout.tv_sec = si->si_tlimit;
267 rc = ldap_search_ext( si->si_ld, si->si_base.bv_val, si->si_scope,
268 si->si_filterstr.bv_val, si->si_attrs, si->si_attrsonly,
269 ctrls, NULL, si->si_tlimit > 0 ? &timeout : NULL,
270 si->si_slimit, &msgid );
281 int cmdline_cookie_found = 0;
283 char syncrepl_cbuf[sizeof(CN_STR SYNCREPL_STR)];
284 struct berval syncrepl_cn_bv;
285 struct sync_cookie *sc = NULL;
291 psub = &si->si_be->be_nsuffix[0];
293 /* Init connection to master */
294 rc = ldap_initialize( &si->si_ld, si->si_provideruri );
295 if ( rc != LDAP_SUCCESS ) {
296 Debug( LDAP_DEBUG_ANY,
297 "do_syncrep1: ldap_initialize failed (%s)\n",
298 si->si_provideruri, 0, 0 );
302 op->o_protocol = LDAP_VERSION3;
303 ldap_set_option( si->si_ld, LDAP_OPT_PROTOCOL_VERSION, &op->o_protocol );
308 rc = ldap_start_tls_s( si->si_ld, NULL, NULL );
309 if( rc != LDAP_SUCCESS ) {
310 Debug( LDAP_DEBUG_ANY,
311 "%s: ldap_start_tls failed (%d)\n",
312 si->si_tls == SYNCINFO_TLS_CRITICAL ? "Error" : "Warning",
314 if( si->si_tls == SYNCINFO_TLS_CRITICAL ) goto done;
318 if ( si->si_bindmethod == LDAP_AUTH_SASL ) {
319 #ifdef HAVE_CYRUS_SASL
322 if ( si->si_secprops != NULL ) {
323 rc = ldap_set_option( si->si_ld,
324 LDAP_OPT_X_SASL_SECPROPS, si->si_secprops);
326 if( rc != LDAP_OPT_SUCCESS ) {
327 Debug( LDAP_DEBUG_ANY, "Error: ldap_set_option "
328 "(%s,SECPROPS,\"%s\") failed!\n",
329 si->si_provideruri, si->si_secprops, 0 );
334 defaults = lutil_sasl_defaults( si->si_ld, si->si_saslmech,
335 si->si_realm, si->si_authcId, si->si_passwd, si->si_authzId );
337 rc = ldap_sasl_interactive_bind_s( si->si_ld,
345 lutil_sasl_freedefs( defaults );
347 /* FIXME: different error behaviors according to
349 * 2) on err policy : exit, retry, backoff ...
351 if ( rc != LDAP_SUCCESS ) {
352 Debug( LDAP_DEBUG_ANY, "do_syncrep1: "
353 "ldap_sasl_interactive_bind_s failed (%d)\n",
356 /* FIXME (see above comment) */
357 /* if Kerberos credentials cache is not active, retry */
358 if ( strcmp( si->si_saslmech, "GSSAPI" ) == 0 &&
359 rc == LDAP_LOCAL_ERROR )
361 rc = LDAP_SERVER_DOWN;
366 #else /* HAVE_CYRUS_SASL */
367 /* Should never get here, we trapped this at config time */
369 fprintf( stderr, "not compiled with SASL support\n" );
375 rc = ldap_bind_s( si->si_ld,
376 si->si_binddn, si->si_passwd, si->si_bindmethod );
377 if ( rc != LDAP_SUCCESS ) {
378 Debug( LDAP_DEBUG_ANY, "do_syncrep1: "
379 "ldap_bind_s failed (%d)\n", rc, 0, 0 );
384 /* Set SSF to strongest of TLS, SASL SSFs */
387 op->o_transport_ssf = 0;
389 if ( ldap_get_option( si->si_ld, LDAP_OPT_X_TLS_SSL_CTX, &ssl )
390 == LDAP_SUCCESS && ssl != NULL )
392 op->o_tls_ssf = ldap_pvt_tls_get_strength( ssl );
394 #endif /* HAVE_TLS */
395 ldap_get_option( si->si_ld, LDAP_OPT_X_SASL_SSF, &op->o_sasl_ssf );
396 op->o_ssf = ( op->o_sasl_ssf > op->o_tls_ssf )
397 ? op->o_sasl_ssf : op->o_tls_ssf;
399 /* get syncrepl cookie of shadow replica from subentry */
400 assert( si->si_rid < 1000 );
401 syncrepl_cn_bv.bv_val = syncrepl_cbuf;
402 syncrepl_cn_bv.bv_len = snprintf( syncrepl_cbuf, sizeof(syncrepl_cbuf),
403 CN_STR "syncrepl%ld", si->si_rid );
404 build_new_dn( &op->o_req_ndn, psub, &syncrepl_cn_bv, op->o_tmpmemctx );
405 op->o_req_dn = op->o_req_ndn;
407 LDAP_STAILQ_FOREACH( sc, &slap_sync_cookie, sc_next ) {
408 if ( si->si_rid == sc->rid ) {
409 cmdline_cookie_found = 1;
414 if ( cmdline_cookie_found ) {
415 /* cookie is supplied in the command line */
416 BerVarray cookie = NULL;
417 struct berval cookie_bv;
419 LDAP_STAILQ_REMOVE( &slap_sync_cookie, sc, sync_cookie, sc_next );
420 slap_sync_cookie_free( &si->si_syncCookie, 0 );
422 /* read stored cookie if it exists */
423 backend_attribute( op, NULL, &op->o_req_ndn,
424 slap_schema.si_ad_syncreplCookie, &cookie, ACL_READ );
427 /* no stored cookie */
428 if ( sc->ctxcsn == NULL ||
429 BER_BVISNULL( sc->ctxcsn ) ) {
430 /* if cmdline cookie does not have ctxcsn */
431 /* component, set it to an initial value */
432 slap_init_sync_cookie_ctxcsn( sc );
434 slap_dup_sync_cookie( &si->si_syncCookie, sc );
435 slap_sync_cookie_free( sc, 1 );
440 struct berval newcookie = BER_BVNULL;
441 ber_dupbv( &cookie_bv, &cookie[0] );
442 ber_bvarray_add( &si->si_syncCookie.octet_str, &cookie_bv );
443 slap_parse_sync_cookie( &si->si_syncCookie );
444 ber_bvarray_free( si->si_syncCookie.octet_str );
445 si->si_syncCookie.octet_str = NULL;
446 ber_bvarray_free_x( cookie, op->o_tmpmemctx );
447 if ( sc->sid != -1 ) {
448 /* command line cookie wins */
449 si->si_syncCookie.sid = sc->sid;
451 if ( sc->ctxcsn != NULL ) {
452 /* command line cookie wins */
453 if ( si->si_syncCookie.ctxcsn ) {
454 ber_bvarray_free( si->si_syncCookie.ctxcsn );
455 si->si_syncCookie.ctxcsn = NULL;
457 ber_dupbv( &cookie_bv, &sc->ctxcsn[0] );
458 ber_bvarray_add( &si->si_syncCookie.ctxcsn, &cookie_bv );
460 if ( sc->rid != -1 ) {
461 /* command line cookie wins */
462 si->si_syncCookie.rid = sc->rid;
464 slap_sync_cookie_free( sc, 1 );
466 slap_compose_sync_cookie( NULL, &newcookie,
467 &si->si_syncCookie.ctxcsn[0],
468 si->si_syncCookie.sid, si->si_syncCookie.rid );
469 ber_bvarray_add( &si->si_syncCookie.octet_str, &newcookie );
473 /* no command line cookie is specified */
474 if ( si->si_syncCookie.octet_str == NULL ) {
475 BerVarray cookie = NULL;
476 struct berval cookie_bv;
477 /* try to read stored cookie */
478 backend_attribute( op, NULL, &op->o_req_ndn,
479 slap_schema.si_ad_syncreplCookie, &cookie, ACL_READ );
481 ber_dupbv( &cookie_bv, &cookie[0] );
482 ber_bvarray_add( &si->si_syncCookie.octet_str, &cookie_bv );
483 slap_parse_sync_cookie( &si->si_syncCookie );
484 ber_bvarray_free_x( cookie, op->o_tmpmemctx );
489 rc = ldap_sync_search( si, op->o_tmpmemctx );
491 if( rc != LDAP_SUCCESS ) {
492 Debug( LDAP_DEBUG_ANY, "do_syncrep1: "
493 "ldap_search_ext: %s (%d)\n", ldap_err2string( rc ), rc, 0 );
499 ldap_unbind( si->si_ld );
504 slap_sl_free( op->o_req_ndn.bv_val, op->o_tmpmemctx );
514 LDAPControl **rctrls = NULL;
517 BerElementBuffer berbuf;
518 BerElement *ber = (BerElement *)&berbuf;
520 LDAPMessage *res = NULL;
521 LDAPMessage *msg = NULL;
524 struct berval *retdata = NULL;
529 struct berval syncUUID = BER_BVNULL;
530 struct sync_cookie syncCookie = { NULL, -1, NULL };
531 struct sync_cookie syncCookie_req = { NULL, -1, NULL };
532 struct berval cookie = BER_BVNULL;
540 Modifications *modlist = NULL;
545 struct timeval *tout_p = NULL;
546 struct timeval tout = { 0, 0 };
548 int refreshDeletes = 0;
550 BerVarray syncUUIDs = NULL;
553 if ( slapd_shutdown ) {
558 ber_init2( ber, NULL, LBER_USE_DER );
559 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
561 Debug( LDAP_DEBUG_TRACE, "=>do_syncrep2\n", 0, 0, 0 );
563 psub = &si->si_be->be_nsuffix[0];
565 slap_dup_sync_cookie( &syncCookie_req, &si->si_syncCookie );
567 if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST ) {
573 while (( rc = ldap_result( si->si_ld, LDAP_RES_ANY, LDAP_MSG_ONE,
574 tout_p, &res )) > 0 )
576 if ( slapd_shutdown ) {
580 for( msg = ldap_first_message( si->si_ld, res );
582 msg = ldap_next_message( si->si_ld, msg ) )
584 switch( ldap_msgtype( msg ) ) {
585 case LDAP_RES_SEARCH_ENTRY:
586 ldap_get_entry_controls( si->si_ld, msg, &rctrls );
587 /* we can't work without the control */
589 Debug( LDAP_DEBUG_ANY, "do_syncrep2: "
590 "got search entry without "
591 "control\n", 0, 0, 0 );
596 ber_init2( ber, &rctrlp->ldctl_value, LBER_USE_DER );
597 ber_scanf( ber, "{em" /*"}"*/, &syncstate, &syncUUID );
598 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
599 ber_scanf( ber, /*"{"*/ "m}", &cookie );
600 if ( !BER_BVISNULL( &cookie ) ) {
601 struct berval tmp_bv;
602 ber_dupbv( &tmp_bv, &cookie );
603 ber_bvarray_add( &syncCookie.octet_str, &tmp_bv );
605 if ( syncCookie.octet_str &&
606 !BER_BVISNULL( &syncCookie.octet_str[0] ) )
608 slap_parse_sync_cookie( &syncCookie );
611 if ( syncrepl_message_to_entry( si, op, msg,
612 &modlist, &entry, syncstate ) == LDAP_SUCCESS ) {
613 rc_efree = syncrepl_entry( si, op, entry, &modlist,
614 syncstate, &syncUUID, &syncCookie_req, syncCookie.ctxcsn );
615 if ( syncCookie.octet_str &&
616 !BER_BVISNULL( &syncCookie.octet_str[0] ) )
618 syncrepl_updateCookie( si, op, psub, &syncCookie );
621 ldap_controls_free( rctrls );
623 slap_mods_free( modlist );
625 if ( rc_efree && entry ) {
631 case LDAP_RES_SEARCH_REFERENCE:
632 Debug( LDAP_DEBUG_ANY,
633 "do_syncrep2: reference received error\n", 0, 0, 0 );
636 case LDAP_RES_SEARCH_RESULT:
637 Debug( LDAP_DEBUG_SYNC,
638 "do_syncrep2: LDAP_RES_SEARCH_RESULT\n", 0, 0, 0 );
639 ldap_parse_result( si->si_ld, msg, &err, NULL, NULL, NULL,
643 ber_init2( ber, &rctrlp->ldctl_value, LBER_USE_DER );
645 ber_scanf( ber, "{" /*"}"*/);
646 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
647 ber_scanf( ber, "m", &cookie );
648 if ( !BER_BVISNULL( &cookie ) ) {
649 struct berval tmp_bv;
650 ber_dupbv( &tmp_bv, &cookie );
651 ber_bvarray_add( &syncCookie.octet_str, &tmp_bv);
653 if ( syncCookie.octet_str &&
654 !BER_BVISNULL( &syncCookie.octet_str[0] ) )
656 slap_parse_sync_cookie( &syncCookie );
659 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_REFRESHDELETES )
661 ber_scanf( ber, "b", &refreshDeletes );
663 ber_scanf( ber, /*"{"*/ "}" );
665 if ( syncCookie_req.ctxcsn == NULL ) {
667 } else if ( syncCookie.ctxcsn == NULL ) {
670 value_match( &match, slap_schema.si_ad_entryCSN,
671 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
672 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
673 &syncCookie_req.ctxcsn[0], &syncCookie.ctxcsn[0],
676 if ( syncCookie.octet_str && !BER_BVISNULL( syncCookie.octet_str ) &&
677 match < 0 && err == LDAP_SUCCESS )
679 syncrepl_updateCookie( si, op, psub, &syncCookie );
682 ldap_controls_free( rctrls );
684 if (si->si_type != LDAP_SYNC_REFRESH_AND_PERSIST) {
685 /* FIXME : different error behaviors according to
686 * 1) err code : LDAP_BUSY ...
687 * 2) on err policy : stop service, stop sync, retry
689 if ( refreshDeletes == 0 && match < 0 &&
690 err == LDAP_SUCCESS )
692 syncrepl_del_nonpresent( op, si, NULL );
694 avl_free( si->si_presentlist, avl_ber_bvfree );
695 si->si_presentlist = NULL;
702 case LDAP_RES_INTERMEDIATE:
703 rc = ldap_parse_intermediate( si->si_ld, msg,
704 &retoid, &retdata, NULL, 0 );
705 if ( !rc && !strcmp( retoid, LDAP_SYNC_INFO ) ) {
706 ber_init2( ber, retdata, LBER_USE_DER );
708 switch ( si_tag = ber_peek_tag( ber, &len )) {
710 case LDAP_TAG_SYNC_NEW_COOKIE:
711 Debug( LDAP_DEBUG_SYNC,
712 "do_syncrep2: %s - %s%s\n",
713 "LDAP_RES_INTERMEDIATE",
714 "NEW_COOKIE", "\n" );
715 ber_scanf( ber, "tm", &tag, &cookie );
717 case LDAP_TAG_SYNC_REFRESH_DELETE:
718 case LDAP_TAG_SYNC_REFRESH_PRESENT:
719 Debug( LDAP_DEBUG_SYNC,
720 "do_syncrep2: %s - %s%s\n",
721 "LDAP_RES_INTERMEDIATE",
722 si_tag == LDAP_TAG_SYNC_REFRESH_PRESENT ?
723 "REFRESH_PRESENT" : "REFRESH_DELETE",
725 if ( si_tag == LDAP_TAG_SYNC_REFRESH_DELETE ) {
726 si->si_refreshDelete = 1;
728 si->si_refreshPresent = 1;
730 ber_scanf( ber, "t{" /*"}"*/, &tag );
731 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE )
733 ber_scanf( ber, "m", &cookie );
734 if ( !BER_BVISNULL( &cookie ) ) {
735 struct berval tmp_bv;
736 ber_dupbv( &tmp_bv, &cookie );
737 ber_bvarray_add( &syncCookie.octet_str,
740 if ( syncCookie.octet_str &&
741 !BER_BVISNULL( &syncCookie.octet_str[0] ) )
743 slap_parse_sync_cookie( &syncCookie );
746 if ( ber_peek_tag( ber, &len ) ==
747 LDAP_TAG_REFRESHDONE )
749 ber_scanf( ber, "b", &refreshDone );
751 ber_scanf( ber, /*"{"*/ "}" );
753 case LDAP_TAG_SYNC_ID_SET:
754 Debug( LDAP_DEBUG_SYNC,
755 "do_syncrep2: %s - %s%s\n",
756 "LDAP_RES_INTERMEDIATE",
759 ber_scanf( ber, "t{" /*"}"*/, &tag );
760 if ( ber_peek_tag( ber, &len ) ==
761 LDAP_TAG_SYNC_COOKIE )
763 ber_scanf( ber, "m", &cookie );
764 if ( !BER_BVISNULL( &cookie ) ) {
765 struct berval tmp_bv;
766 ber_dupbv( &tmp_bv, &cookie );
767 ber_bvarray_add( &syncCookie.octet_str,
770 if ( syncCookie.octet_str &&
771 !BER_BVISNULL( &syncCookie.octet_str[0] ) )
773 slap_parse_sync_cookie( &syncCookie );
776 if ( ber_peek_tag( ber, &len ) ==
777 LDAP_TAG_REFRESHDELETES )
779 ber_scanf( ber, "b", &refreshDeletes );
781 ber_scanf( ber, "[W]", &syncUUIDs );
782 ber_scanf( ber, /*"{"*/ "}" );
783 if ( refreshDeletes ) {
784 syncrepl_del_nonpresent( op, si, syncUUIDs );
785 ber_bvarray_free_x( syncUUIDs, op->o_tmpmemctx );
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 );
799 Debug( LDAP_DEBUG_ANY,
800 "do_syncrep2 : unknown syncinfo tag (%ld)\n",
801 (long) si_tag, 0, 0 );
802 ldap_memfree( retoid );
803 ber_bvfree( retdata );
807 if ( syncCookie_req.ctxcsn == NULL ) {
809 } else if ( syncCookie.ctxcsn == NULL ) {
812 value_match( &match, slap_schema.si_ad_entryCSN,
813 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
814 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
815 &syncCookie_req.ctxcsn[0],
816 &syncCookie.ctxcsn[0], &text );
819 if ( syncCookie.ctxcsn && !BER_BVISNULL( &syncCookie.ctxcsn[0] ) &&
822 syncrepl_updateCookie( si, op, psub, &syncCookie);
825 if ( si->si_refreshPresent == 1 ) {
827 syncrepl_del_nonpresent( op, si, NULL );
831 ldap_memfree( retoid );
832 ber_bvfree( retdata );
836 Debug( LDAP_DEBUG_ANY, "do_syncrep2 : "
837 "unknown intermediate response (%d)\n",
839 ldap_memfree( retoid );
840 ber_bvfree( retdata );
846 Debug( LDAP_DEBUG_ANY, "do_syncrep2 : "
847 "unknown message\n", 0, 0, 0 );
851 if ( syncCookie.octet_str ) {
852 slap_sync_cookie_free( &syncCookie_req, 0 );
853 slap_dup_sync_cookie( &syncCookie_req, &syncCookie );
854 slap_sync_cookie_free( &syncCookie, 0 );
864 ldap_get_option( si->si_ld, LDAP_OPT_ERROR_NUMBER, &rc );
865 errstr = ldap_err2string( rc );
867 Debug( LDAP_DEBUG_ANY,
868 "do_syncrep2 : %s\n", errstr, 0, 0 );
872 slap_sync_cookie_free( &syncCookie, 0 );
873 slap_sync_cookie_free( &syncCookie_req, 0 );
875 if ( res ) ldap_msgfree( res );
877 if ( rc && si->si_ld ) {
878 ldap_unbind( si->si_ld );
890 struct re_s* rtask = arg;
891 syncinfo_t *si = ( syncinfo_t * ) rtask->arg;
892 Connection conn = {0};
893 char opbuf[OPERATION_BUFFER_SIZE];
895 int rc = LDAP_SUCCESS;
902 Debug( LDAP_DEBUG_TRACE, "=>do_syncrepl\n", 0, 0, 0 );
907 switch( abs( si->si_type )) {
908 case LDAP_SYNC_REFRESH_ONLY:
909 case LDAP_SYNC_REFRESH_AND_PERSIST:
915 if ( slapd_shutdown && si->si_ld ) {
916 ldap_get_option( si->si_ld, LDAP_OPT_DESC, &s );
917 connection_client_stop( s );
918 ldap_unbind( si->si_ld );
923 op = (Operation *)opbuf;
924 connection_fake_init( &conn, op, ctx );
926 /* use global malloc for now */
927 op->o_tmpmemctx = NULL;
928 op->o_tmpmfuncs = &ch_mfuncs;
930 op->o_dn = si->si_updatedn;
931 op->o_ndn = si->si_updatedn;
932 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
933 op->o_bd = be = si->si_be;
935 /* Establish session, do search */
938 si->si_refreshDelete = 0;
939 si->si_refreshPresent = 0;
940 rc = do_syncrep1( op, si );
943 /* Process results */
944 if ( rc == LDAP_SUCCESS ) {
945 ldap_get_option( si->si_ld, LDAP_OPT_DESC, &s );
947 rc = do_syncrep2( op, si );
949 if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST ) {
950 /* If we succeeded, enable the connection for further listening.
951 * If we failed, tear down the connection and reschedule.
953 if ( rc == LDAP_SUCCESS ) {
955 rc = connection_client_setup( s, do_syncrepl, arg );
957 connection_client_enable( s );
959 } else if ( !first ) {
963 if ( rc == -2 ) rc = 0;
967 /* At this point, we have 4 cases:
968 * 1) for any hard failure, give up and remove this task
969 * 2) for ServerDown, reschedule this task to run
970 * 3) for Refresh and Success, reschedule to run
971 * 4) for Persist and Success, reschedule to defer
973 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
975 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, rtask )) {
976 ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
980 connection_client_stop( s );
983 if ( rc == LDAP_SUCCESS ) {
984 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
987 rtask->interval.tv_sec = si->si_interval;
988 ldap_pvt_runqueue_resched( &slapd_rq, rtask, defer );
989 if ( si->si_retrynum ) {
990 for ( i = 0; si->si_retrynum_init[i] != -2; i++ ) {
991 si->si_retrynum[i] = si->si_retrynum_init[i];
993 si->si_retrynum[i] = -2;
996 for ( i = 0; si->si_retrynum && si->si_retrynum[i] <= 0; i++ ) {
997 if ( si->si_retrynum[i] == -1 || si->si_retrynum[i] == -2 )
1001 if ( !si->si_retrynum || si->si_retrynum[i] == -2 ) {
1002 ldap_pvt_runqueue_remove( &slapd_rq, rtask );
1003 LDAP_STAILQ_REMOVE( &be->be_syncinfo, si, syncinfo_s, si_next );
1004 syncinfo_free( si );
1005 } else if ( si->si_retrynum[i] >= -1 ) {
1006 if ( si->si_retrynum[i] > 0 )
1007 si->si_retrynum[i]--;
1008 rtask->interval.tv_sec = si->si_retryinterval[i];
1009 ldap_pvt_runqueue_resched( &slapd_rq, rtask, 0 );
1010 slap_wake_listener();
1014 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
1020 syncrepl_message_to_entry(
1024 Modifications **modlist,
1030 BerElement *ber = NULL;
1033 Modifications **modtail = modlist;
1036 char txtbuf[SLAP_TEXT_BUFLEN];
1037 size_t textlen = sizeof txtbuf;
1039 struct berval bdn = {0, NULL}, dn, ndn;
1044 if ( ldap_msgtype( msg ) != LDAP_RES_SEARCH_ENTRY ) {
1045 Debug( LDAP_DEBUG_ANY,
1046 "Message type should be entry (%d)", ldap_msgtype( msg ), 0, 0 );
1050 op->o_tag = LDAP_REQ_ADD;
1052 rc = ldap_get_dn_ber( si->si_ld, msg, &ber, &bdn );
1054 if ( rc != LDAP_SUCCESS ) {
1055 Debug( LDAP_DEBUG_ANY,
1056 "syncrepl_message_to_entry : dn get failed (%d)", rc, 0, 0 );
1060 dnPrettyNormal( NULL, &bdn, &dn, &ndn, op->o_tmpmemctx );
1061 ber_dupbv( &op->o_req_dn, &dn );
1062 ber_dupbv( &op->o_req_ndn, &ndn );
1063 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1064 slap_sl_free( dn.bv_val, op->o_tmpmemctx );
1066 if ( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_DELETE ) {
1069 return LDAP_SUCCESS;
1072 if ( entry == NULL ) {
1076 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ) );
1078 e->e_name = op->o_req_dn;
1079 e->e_nname = op->o_req_ndn;
1081 while ( ber_remaining( ber ) ) {
1082 if ( (ber_scanf( ber, "{mW}", &tmp.sml_type, &tmp.sml_values ) ==
1083 LBER_ERROR ) || BER_BVISNULL( &tmp.sml_type ) )
1088 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
1090 mod->sml_op = LDAP_MOD_REPLACE;
1091 mod->sml_next = NULL;
1092 mod->sml_desc = NULL;
1093 mod->sml_type = tmp.sml_type;
1094 mod->sml_values = tmp.sml_values;
1095 mod->sml_nvalues = NULL;
1098 modtail = &mod->sml_next;
1101 if ( *modlist == NULL ) {
1102 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: no attributes\n",
1108 rc = slap_mods_check( *modlist, 1, &text, txtbuf, textlen, NULL );
1110 if ( rc != LDAP_SUCCESS ) {
1111 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods check (%s)\n",
1116 /* Strip out dynamically generated attrs */
1117 for ( modtail = modlist; *modtail ; ) {
1119 if ( mod->sml_desc->ad_type->sat_flags & SLAP_AT_DYNAMIC ) {
1120 *modtail = mod->sml_next;
1121 slap_mod_free( &mod->sml_mod, 0 );
1124 modtail = &mod->sml_next;
1128 /* Strip out attrs in exattrs list */
1129 for ( modtail = modlist; *modtail ; ) {
1131 if ( ldap_charray_inlist( si->si_exattrs,
1132 mod->sml_desc->ad_type->sat_cname.bv_val )) {
1133 *modtail = mod->sml_next;
1134 slap_mod_free( &mod->sml_mod, 0 );
1137 modtail = &mod->sml_next;
1141 rc = slap_mods2entry( *modlist, &e, 1, 1, &text, txtbuf, textlen);
1142 if( rc != LDAP_SUCCESS ) {
1143 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods2entry (%s)\n",
1148 ber_free ( ber, 0 );
1149 if ( rc != LDAP_SUCCESS ) {
1159 /* During a refresh, we may get an LDAP_SYNC_ADD for an already existing
1160 * entry if a previous refresh was interrupted before sending us a new
1161 * context state. We try to compare the new entry to the existing entry
1162 * and ignore the new entry if they are the same.
1164 * Also, we may get an update where the entryDN has changed, due to
1165 * a ModDn on the provider. We detect this as well, so we can issue
1166 * the corresponding operation locally.
1168 * In the case of a modify, we get a list of all the attributes
1169 * in the original entry. Rather than deleting the entry and re-adding it,
1170 * we issue a Modify request that deletes all the attributes and adds all
1171 * the new ones. This avoids the issue of trying to delete/add a non-leaf
1174 * We don't try to otherwise distinguish ModDN from Modify; in the case of
1175 * a ModDN we will issue both operations on the local database.
1177 typedef struct dninfo {
1181 int renamed; /* Was an existing entry renamed? */
1182 int wasChanged; /* are the attributes changed? */
1183 int attrs; /* how many attribute types are in the ads list */
1184 AttributeDescription **ads;
1192 Modifications** modlist,
1194 struct berval* syncUUID,
1195 struct sync_cookie* syncCookie_req,
1196 struct berval* syncCSN )
1198 Backend *be = op->o_bd;
1199 slap_callback cb = { NULL };
1200 struct berval *syncuuid_bv = NULL;
1201 struct berval syncUUID_strrep = BER_BVNULL;
1202 struct berval uuid_bv = BER_BVNULL;
1204 SlapReply rs_search = {REP_RESULT};
1205 SlapReply rs_delete = {REP_RESULT};
1206 SlapReply rs_add = {REP_RESULT};
1207 SlapReply rs_modify = {REP_RESULT};
1209 AttributeAssertion ava = {0};
1210 int rc = LDAP_SUCCESS;
1211 int ret = LDAP_SUCCESS;
1213 struct berval pdn = BER_BVNULL;
1214 struct berval org_req_dn = BER_BVNULL;
1215 struct berval org_req_ndn = BER_BVNULL;
1216 struct berval org_dn = BER_BVNULL;
1217 struct berval org_ndn = BER_BVNULL;
1218 int org_managedsait;
1222 switch( syncstate ) {
1223 case LDAP_SYNC_PRESENT:
1224 Debug( LDAP_DEBUG_SYNC, "%s: %s\n",
1226 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_PRESENT)", 0 );
1229 Debug( LDAP_DEBUG_SYNC, "%s: %s\n",
1231 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_ADD)", 0 );
1233 case LDAP_SYNC_DELETE:
1234 Debug( LDAP_DEBUG_SYNC, "%s: %s\n",
1236 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_DELETE)", 0 );
1238 case LDAP_SYNC_MODIFY:
1239 Debug( LDAP_DEBUG_SYNC, "%s: %s\n",
1241 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_MODIFY)", 0 );
1244 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
1246 "LDAP_RES_SEARCH_ENTRY(UNKNOWN syncstate)", 0 );
1249 if (( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD )) {
1250 if ( !si->si_refreshPresent ) {
1251 syncuuid_bv = ber_dupbv( NULL, syncUUID );
1252 avl_insert( &si->si_presentlist, (caddr_t) syncuuid_bv,
1253 syncuuid_cmp, avl_dup_error );
1257 if ( syncstate == LDAP_SYNC_PRESENT ) {
1259 } else if ( syncstate != LDAP_SYNC_DELETE ) {
1260 if ( entry == NULL ) {
1265 f.f_choice = LDAP_FILTER_EQUALITY;
1267 ava.aa_desc = slap_schema.si_ad_entryUUID;
1268 (void)slap_uuidstr_from_normalized( &syncUUID_strrep, syncUUID, op->o_tmpmemctx );
1269 ava.aa_value = *syncUUID;
1270 op->ors_filter = &f;
1272 op->ors_filterstr.bv_len = STRLENOF( "entryUUID=" ) + syncUUID->bv_len;
1273 op->ors_filterstr.bv_val = (char *) slap_sl_malloc(
1274 op->ors_filterstr.bv_len + 1, op->o_tmpmemctx );
1275 AC_MEMCPY( op->ors_filterstr.bv_val, "entryUUID=", STRLENOF( "entryUUID=" ) );
1276 AC_MEMCPY( &op->ors_filterstr.bv_val[STRLENOF( "entryUUID=" )],
1277 syncUUID->bv_val, syncUUID->bv_len );
1278 op->ors_filterstr.bv_val[op->ors_filterstr.bv_len] = '\0';
1280 op->o_tag = LDAP_REQ_SEARCH;
1281 op->ors_scope = LDAP_SCOPE_SUBTREE;
1283 /* get the entry for this UUID */
1284 op->o_req_dn = si->si_base;
1285 op->o_req_ndn = si->si_base;
1287 op->o_time = slap_get_time();
1288 op->ors_tlimit = SLAP_NO_LIMIT;
1291 op->ors_attrs = slap_anlist_all_attributes;
1292 op->ors_attrsonly = 0;
1294 /* set callback function */
1295 op->o_callback = &cb;
1296 cb.sc_response = dn_callback;
1297 cb.sc_private = &dni;
1298 dni.new_entry = entry;
1300 if ( limits_check( op, &rs_search ) == 0 ) {
1301 rc = be->be_search( op, &rs_search );
1302 Debug( LDAP_DEBUG_SYNC,
1303 "syncrepl_entry: %s (%d)\n",
1304 "be_search", rc, 0 );
1307 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
1308 slap_sl_free( op->ors_filterstr.bv_val, op->o_tmpmemctx );
1311 cb.sc_response = null_callback;
1314 if ( entry && entry->e_name.bv_val ) {
1315 Debug( LDAP_DEBUG_SYNC,
1316 "syncrepl_entry: %s\n",
1317 entry->e_name.bv_val, 0, 0 );
1319 Debug( LDAP_DEBUG_SYNC,
1320 "syncrepl_entry: %s\n",
1321 dni.dn.bv_val ? dni.dn.bv_val : "(null)", 0, 0 );
1324 org_req_dn = op->o_req_dn;
1325 org_req_ndn = op->o_req_ndn;
1327 org_ndn = op->o_ndn;
1328 org_managedsait = get_manageDSAit( op );
1329 op->o_dn = op->o_bd->be_rootdn;
1330 op->o_ndn = op->o_bd->be_rootndn;
1331 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
1333 if ( syncstate != LDAP_SYNC_DELETE ) {
1334 attr_delete( &entry->e_attrs, slap_schema.si_ad_entryUUID );
1335 attr_merge_one( entry, slap_schema.si_ad_entryUUID,
1336 &syncUUID_strrep, syncUUID );
1339 switch ( syncstate ) {
1341 case LDAP_SYNC_MODIFY:
1343 if ( BER_BVISNULL( &dni.dn )) {
1345 op->o_req_dn = entry->e_name;
1346 op->o_req_ndn = entry->e_nname;
1347 op->o_tag = LDAP_REQ_ADD;
1350 rc = be->be_add( op, &rs_add );
1351 Debug( LDAP_DEBUG_SYNC,
1352 "syncrepl_entry: %s (%d)\n",
1354 switch ( rs_add.sr_err ) {
1356 be_entry_release_w( op, entry );
1361 /* we assume that LDAP_NO_SUCH_OBJECT is returned
1362 * only if the suffix entry is not present */
1363 case LDAP_NO_SUCH_OBJECT:
1364 syncrepl_add_glue( op, entry );
1368 /* if an entry was added via syncrepl_add_glue(),
1369 * it likely has no entryUUID, so the previous
1370 * be_search() doesn't find it. In this case,
1371 * give syncrepl a chance to modify it. */
1372 case LDAP_ALREADY_EXISTS:
1374 Operation op2 = *op;
1375 SlapReply rs2 = { 0 };
1376 slap_callback cb2 = { 0 };
1378 op2.o_tag = LDAP_REQ_SEARCH;
1379 ber_dupbv_x( &op2.o_req_dn,
1382 ber_dupbv_x( &op2.o_req_ndn,
1385 op2.ors_scope = LDAP_SCOPE_BASE;
1386 op2.ors_attrs = slap_anlist_all_attributes;
1387 op2.ors_attrsonly = 0;
1388 op2.ors_limit = NULL;
1390 op2.ors_tlimit = SLAP_NO_LIMIT;
1392 f.f_choice = LDAP_FILTER_EQUALITY;
1394 ava.aa_desc = slap_schema.si_ad_objectClass;
1395 ber_dupbv_x( &ava.aa_value,
1396 &slap_schema.si_oc_glue->soc_cname,
1398 op2.ors_filter = &f;
1399 filter2bv_x( &op2, op2.ors_filter,
1400 &op2.ors_filterstr );
1402 op2.o_callback = &cb2;
1403 cb2.sc_response = dn_callback;
1404 cb2.sc_private = &dni;
1406 be->be_search( &op2, &rs2 );
1408 op2.o_tmpfree( op2.o_req_dn.bv_val,
1410 op2.o_tmpfree( op2.o_req_ndn.bv_val,
1412 op2.o_tmpfree( ava.aa_value.bv_val,
1414 op2.o_tmpfree( op2.ors_filterstr.bv_val,
1423 Debug( LDAP_DEBUG_ANY,
1424 "syncrepl_entry : be_add failed (%d)\n",
1425 rs_add.sr_err, 0, 0 );
1432 op->o_req_dn = dni.dn;
1433 op->o_req_ndn = dni.ndn;
1434 if ( dni.renamed ) {
1435 struct berval noldp, newp, nnewp;
1437 op->o_tag = LDAP_REQ_MODRDN;
1438 dnRdn( &entry->e_name, &op->orr_newrdn );
1439 dnRdn( &entry->e_nname, &op->orr_nnewrdn );
1441 dnParent( &dni.ndn, &noldp );
1442 dnParent( &entry->e_nname, &nnewp );
1443 if ( !dn_match( &noldp, &newp )) {
1444 dnParent( &entry->e_name, &newp );
1445 op->orr_newSup = &newp;
1446 op->orr_nnewSup = &nnewp;
1448 op->orr_deleteoldrdn = 0;
1449 rc = be->be_modrdn( op, &rs_modify );
1450 Debug( LDAP_DEBUG_SYNC,
1451 "syncrepl_entry: %s (%d)\n",
1452 "be_modrdn", rc, 0 );
1453 if ( rs_modify.sr_err == LDAP_SUCCESS ) {
1454 op->o_req_dn = entry->e_name;
1455 op->o_req_ndn = entry->e_nname;
1461 if ( dni.wasChanged ) {
1462 Modifications *mod, *modhead = NULL;
1463 Modifications *modtail = NULL;
1466 op->o_tag = LDAP_REQ_MODIFY;
1470 /* Delete all the old attrs */
1471 for ( i=0; i<dni.attrs; i++) {
1472 mod = ch_malloc( sizeof(Modifications));
1473 mod->sml_op = LDAP_MOD_DELETE;
1474 mod->sml_desc = dni.ads[i];
1475 mod->sml_type =mod->sml_desc->ad_cname;
1476 mod->sml_values = NULL;
1477 mod->sml_nvalues = NULL;
1478 if ( !modhead ) modhead = mod;
1480 modtail->sml_next = mod;
1485 /* Append passed in list to ours */
1487 modtail->sml_next = *modlist;
1493 /* Find end of this list */
1494 for ( ; mod != NULL; mod = mod->sml_next ) {
1498 mod = (Modifications *)ch_calloc(1, sizeof(Modifications));
1499 mod->sml_op = LDAP_MOD_REPLACE;
1500 mod->sml_desc = slap_schema.si_ad_entryUUID;
1501 mod->sml_type = mod->sml_desc->ad_cname;
1502 ber_dupbv( &uuid_bv, &syncUUID_strrep );
1503 ber_bvarray_add( &mod->sml_values, &uuid_bv );
1504 ber_dupbv( &uuid_bv, syncUUID );
1505 ber_bvarray_add( &mod->sml_nvalues, &uuid_bv );
1506 modtail->sml_next = mod;
1508 op->o_tag = LDAP_REQ_MODIFY;
1509 op->orm_modlist = *modlist;
1511 rc = be->be_modify( op, &rs_modify );
1512 Debug( LDAP_DEBUG_SYNC,
1513 "syncrepl_entry: %s (%d)\n",
1514 "be_modify", rc, 0 );
1515 if ( rs_modify.sr_err != LDAP_SUCCESS ) {
1516 Debug( LDAP_DEBUG_ANY,
1517 "syncrepl_entry : be_modify failed (%d)\n",
1518 rs_modify.sr_err, 0, 0 );
1523 case LDAP_SYNC_DELETE :
1524 if ( !BER_BVISNULL( &dni.dn )) {
1525 op->o_req_dn = dni.dn;
1526 op->o_req_ndn = dni.ndn;
1527 op->o_tag = LDAP_REQ_DELETE;
1528 rc = be->be_delete( op, &rs_delete );
1529 Debug( LDAP_DEBUG_SYNC,
1530 "syncrepl_entry: %s (%d)\n",
1531 "be_delete", rc, 0 );
1533 while ( rs_delete.sr_err == LDAP_SUCCESS
1534 && op->o_delete_glue_parent ) {
1535 op->o_delete_glue_parent = 0;
1536 if ( !be_issuffix( op->o_bd, &op->o_req_ndn )) {
1537 slap_callback cb = { NULL };
1538 cb.sc_response = slap_null_cb;
1539 dnParent( &op->o_req_ndn, &pdn );
1541 op->o_req_ndn = pdn;
1542 op->o_callback = &cb;
1543 op->o_bd->be_delete( op, &rs_delete );
1553 Debug( LDAP_DEBUG_ANY,
1554 "syncrepl_entry : unknown syncstate\n", 0, 0, 0 );
1560 if ( !BER_BVISNULL( &syncUUID_strrep ) ) {
1561 slap_sl_free( syncUUID_strrep.bv_val, op->o_tmpmemctx );
1562 BER_BVZERO( &syncUUID_strrep );
1565 op->o_tmpfree( dni.ads, op->o_tmpmemctx );
1567 if ( !BER_BVISNULL( &dni.ndn ) ) {
1568 op->o_tmpfree( dni.ndn.bv_val, op->o_tmpmemctx );
1570 if ( !BER_BVISNULL( &dni.dn ) ) {
1571 op->o_tmpfree( dni.dn.bv_val, op->o_tmpmemctx );
1576 static struct berval gcbva[] = {
1582 #define NP_DELETE_ONE 2
1585 syncrepl_del_nonpresent(
1590 Backend* be = op->o_bd;
1591 slap_callback cb = { NULL };
1592 SlapReply rs_search = {REP_RESULT};
1593 SlapReply rs_delete = {REP_RESULT};
1594 SlapReply rs_modify = {REP_RESULT};
1595 struct nonpresent_entry *np_list, *np_prev;
1598 Modifications *mlnext;
1600 Modifications *modlist = NULL;
1601 Modifications **modtail;
1602 AttributeName an[2];
1604 struct berval pdn = BER_BVNULL;
1605 struct berval org_req_dn = BER_BVNULL;
1606 struct berval org_req_ndn = BER_BVNULL;
1607 struct berval org_dn = BER_BVNULL;
1608 struct berval org_ndn = BER_BVNULL;
1609 int org_managedsait;
1611 op->o_req_dn = si->si_base;
1612 op->o_req_ndn = si->si_base;
1614 cb.sc_response = nonpresent_callback;
1617 op->o_callback = &cb;
1618 op->o_tag = LDAP_REQ_SEARCH;
1619 op->ors_scope = si->si_scope;
1620 op->ors_deref = LDAP_DEREF_NEVER;
1621 op->o_time = slap_get_time();
1622 op->ors_tlimit = SLAP_NO_LIMIT;
1627 AttributeAssertion eq;
1630 op->ors_attrsonly = 1;
1631 op->ors_attrs = slap_anlist_no_attrs;
1632 op->ors_limit = NULL;
1633 op->ors_filter = &uf;
1634 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
1637 uf.f_av_desc = slap_schema.si_ad_entryUUID;
1639 uf.f_choice = LDAP_FILTER_EQUALITY;
1640 si->si_refreshDelete |= NP_DELETE_ONE;
1642 for (i=0; uuids[i].bv_val; i++) {
1644 uf.f_av_value = uuids[i];
1645 rc = be->be_search( op, &rs_search );
1647 si->si_refreshDelete ^= NP_DELETE_ONE;
1649 memset( &an[0], 0, 2 * sizeof( AttributeName ) );
1650 an[0].an_name = slap_schema.si_ad_entryUUID->ad_cname;
1651 an[0].an_desc = slap_schema.si_ad_entryUUID;
1653 op->ors_slimit = SLAP_NO_LIMIT;
1654 op->ors_attrsonly = 0;
1655 op->ors_filter = str2filter_x( op, si->si_filterstr.bv_val );
1656 op->ors_filterstr = si->si_filterstr;
1657 op->o_nocaching = 1;
1658 op->o_managedsait = SLAP_CONTROL_NONE;
1660 if ( limits_check( op, &rs_search ) == 0 ) {
1661 rc = be->be_search( op, &rs_search );
1663 if ( op->ors_filter ) filter_free_x( op, op->ors_filter );
1666 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
1667 op->o_nocaching = 0;
1669 if ( !LDAP_LIST_EMPTY( &si->si_nonpresentlist ) ) {
1670 np_list = LDAP_LIST_FIRST( &si->si_nonpresentlist );
1671 while ( np_list != NULL ) {
1672 LDAP_LIST_REMOVE( np_list, npe_link );
1674 np_list = LDAP_LIST_NEXT( np_list, npe_link );
1675 op->o_tag = LDAP_REQ_DELETE;
1676 op->o_callback = &cb;
1677 cb.sc_response = null_callback;
1679 op->o_req_dn = *np_prev->npe_name;
1680 op->o_req_ndn = *np_prev->npe_nname;
1681 rc = op->o_bd->be_delete( op, &rs_delete );
1683 if ( rs_delete.sr_err == LDAP_NOT_ALLOWED_ON_NONLEAF ) {
1685 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1686 mod->sml_op = LDAP_MOD_REPLACE;
1687 mod->sml_desc = slap_schema.si_ad_objectClass;
1688 mod->sml_type = mod->sml_desc->ad_cname;
1689 mod->sml_values = &gcbva[0];
1691 modtail = &mod->sml_next;
1693 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1694 mod->sml_op = LDAP_MOD_REPLACE;
1695 mod->sml_desc = slap_schema.si_ad_structuralObjectClass;
1696 mod->sml_type = mod->sml_desc->ad_cname;
1697 mod->sml_values = &gcbva[1];
1699 modtail = &mod->sml_next;
1701 op->o_tag = LDAP_REQ_MODIFY;
1702 op->orm_modlist = modlist;
1704 rc = be->be_modify( op, &rs_modify );
1706 for ( ml = modlist; ml != NULL; ml = mlnext ) {
1707 mlnext = ml->sml_next;
1712 org_req_dn = op->o_req_dn;
1713 org_req_ndn = op->o_req_ndn;
1715 org_ndn = op->o_ndn;
1716 org_managedsait = get_manageDSAit( op );
1717 op->o_dn = op->o_bd->be_rootdn;
1718 op->o_ndn = op->o_bd->be_rootndn;
1719 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
1721 while ( rs_delete.sr_err == LDAP_SUCCESS &&
1722 op->o_delete_glue_parent ) {
1723 op->o_delete_glue_parent = 0;
1724 if ( !be_issuffix( op->o_bd, &op->o_req_ndn )) {
1725 slap_callback cb = { NULL };
1726 cb.sc_response = slap_null_cb;
1727 dnParent( &op->o_req_ndn, &pdn );
1729 op->o_req_ndn = pdn;
1730 op->o_callback = &cb;
1731 /* give it a root privil ? */
1732 op->o_bd->be_delete( op, &rs_delete );
1738 op->o_managedsait = org_managedsait;
1740 op->o_ndn = org_ndn;
1741 op->o_req_dn = org_req_dn;
1742 op->o_req_ndn = org_req_ndn;
1743 op->o_delete_glue_parent = 0;
1745 ber_bvfree( np_prev->npe_name );
1746 ber_bvfree( np_prev->npe_nname );
1747 BER_BVZERO( &op->o_req_dn );
1748 BER_BVZERO( &op->o_req_ndn );
1761 Backend *be = op->o_bd;
1762 slap_callback cb = { NULL };
1767 struct berval dn = {0, NULL};
1768 struct berval ndn = {0, NULL};
1770 SlapReply rs_add = {REP_RESULT};
1773 op->o_tag = LDAP_REQ_ADD;
1774 op->o_callback = &cb;
1775 cb.sc_response = null_callback;
1776 cb.sc_private = NULL;
1781 /* count RDNs in suffix */
1782 if ( !BER_BVISEMPTY( &be->be_nsuffix[0] ) ) {
1783 for ( i = 0, ptr = be->be_nsuffix[0].bv_val; ptr; ptr = strchr( ptr, ',' ) ) {
1793 /* Start with BE suffix */
1794 for ( i = 0, ptr = NULL; i < suffrdns; i++ ) {
1795 comma = strrchr( dn.bv_val, ',' );
1796 if ( ptr ) *ptr = ',';
1797 if ( comma ) *comma = '\0';
1802 dn.bv_len -= ptr - dn.bv_val;
1805 /* the normalizedDNs are always the same length, no counting
1808 if ( ndn.bv_len > be->be_nsuffix[0].bv_len ) {
1809 ndn.bv_val += ndn.bv_len - be->be_nsuffix[0].bv_len;
1810 ndn.bv_len = be->be_nsuffix[0].bv_len;
1813 while ( ndn.bv_val > e->e_nname.bv_val ) {
1814 glue = (Entry *) ch_calloc( 1, sizeof(Entry) );
1815 ber_dupbv( &glue->e_name, &dn );
1816 ber_dupbv( &glue->e_nname, &ndn );
1818 a = ch_calloc( 1, sizeof( Attribute ));
1819 a->a_desc = slap_schema.si_ad_objectClass;
1821 a->a_vals = ch_calloc( 3, sizeof( struct berval ));
1822 ber_dupbv( &a->a_vals[0], &gcbva[0] );
1823 ber_dupbv( &a->a_vals[1], &gcbva[1] );
1824 ber_dupbv( &a->a_vals[2], &gcbva[2] );
1826 a->a_nvals = a->a_vals;
1828 a->a_next = glue->e_attrs;
1831 a = ch_calloc( 1, sizeof( Attribute ));
1832 a->a_desc = slap_schema.si_ad_structuralObjectClass;
1834 a->a_vals = ch_calloc( 2, sizeof( struct berval ));
1835 ber_dupbv( &a->a_vals[0], &gcbva[1] );
1836 ber_dupbv( &a->a_vals[1], &gcbva[2] );
1838 a->a_nvals = a->a_vals;
1840 a->a_next = glue->e_attrs;
1843 op->o_req_dn = glue->e_name;
1844 op->o_req_ndn = glue->e_nname;
1846 rc = be->be_add ( op, &rs_add );
1847 if ( rs_add.sr_err == LDAP_SUCCESS ) {
1848 be_entry_release_w( op, glue );
1850 /* incl. ALREADY EXIST */
1854 /* Move to next child */
1855 for (ptr = dn.bv_val-2; ptr > e->e_name.bv_val && *ptr != ','; ptr--) {
1858 if ( ptr == e->e_name.bv_val ) break;
1860 dn.bv_len = e->e_name.bv_len - (ptr-e->e_name.bv_val);
1861 for( ptr = ndn.bv_val-2;
1862 ptr > e->e_nname.bv_val && *ptr != ',';
1868 ndn.bv_len = e->e_nname.bv_len - (ptr-e->e_nname.bv_val);
1871 op->o_req_dn = e->e_name;
1872 op->o_req_ndn = e->e_nname;
1874 rc = be->be_add ( op, &rs_add );
1875 if ( rs_add.sr_err == LDAP_SUCCESS ) {
1876 be_entry_release_w( op, e );
1884 static struct berval ocbva[] = {
1886 BER_BVC("subentry"),
1887 BER_BVC("syncConsumerSubentry"),
1891 static struct berval cnbva[] = {
1896 static struct berval ssbva[] = {
1901 static struct berval scbva[] = {
1907 syncrepl_updateCookie(
1911 struct sync_cookie *syncCookie )
1913 Backend *be = op->o_bd;
1915 Modifications *mlnext;
1917 Modifications *modlist = NULL;
1918 Modifications **modtail = &modlist;
1921 char txtbuf[SLAP_TEXT_BUFLEN];
1922 size_t textlen = sizeof txtbuf;
1927 char syncrepl_cbuf[sizeof(CN_STR SYNCREPL_STR)];
1928 struct berval slap_syncrepl_dn_bv = BER_BVNULL;
1929 struct berval slap_syncrepl_cn_bv = BER_BVNULL;
1931 slap_callback cb = { NULL };
1932 SlapReply rs_add = {REP_RESULT};
1933 SlapReply rs_modify = {REP_RESULT};
1935 slap_sync_cookie_free( &si->si_syncCookie, 0 );
1936 slap_dup_sync_cookie( &si->si_syncCookie, syncCookie );
1938 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1939 mod->sml_op = LDAP_MOD_REPLACE;
1940 mod->sml_desc = slap_schema.si_ad_objectClass;
1941 mod->sml_type = mod->sml_desc->ad_cname;
1942 mod->sml_values = ocbva;
1944 modtail = &mod->sml_next;
1946 ber_dupbv( &cnbva[0], (struct berval *) &slap_syncrepl_bvc );
1947 assert( si->si_rid < 1000 );
1948 cnbva[0].bv_len = snprintf( cnbva[0].bv_val,
1949 slap_syncrepl_bvc.bv_len + 1,
1950 "syncrepl%ld", si->si_rid );
1951 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1952 mod->sml_op = LDAP_MOD_REPLACE;
1953 mod->sml_desc = slap_schema.si_ad_cn;
1954 mod->sml_type = mod->sml_desc->ad_cname;
1955 mod->sml_values = cnbva;
1957 modtail = &mod->sml_next;
1959 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1960 mod->sml_op = LDAP_MOD_REPLACE;
1961 mod->sml_desc = slap_schema.si_ad_subtreeSpecification;
1962 mod->sml_type = mod->sml_desc->ad_cname;
1963 mod->sml_values = ssbva;
1965 modtail = &mod->sml_next;
1967 /* Keep this last, so we can avoid touching the previous
1968 * attributes unnecessarily.
1970 if ( scbva[0].bv_val ) ch_free( scbva[0].bv_val );
1971 ber_dupbv( &scbva[0], &si->si_syncCookie.octet_str[0] );
1972 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1973 mod->sml_op = LDAP_MOD_REPLACE;
1974 mod->sml_desc = slap_schema.si_ad_syncreplCookie;
1975 mod->sml_type = mod->sml_desc->ad_cname;
1976 mod->sml_values = scbva;
1978 modtail = &mod->sml_next;
1980 slap_queue_csn( op, si->si_syncCookie.ctxcsn );
1984 op->o_tag = LDAP_REQ_ADD;
1985 rc = slap_mods_opattrs( op, modlist, modtail,
1986 &text, txtbuf, textlen, 0 );
1988 for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
1989 ml->sml_op = LDAP_MOD_REPLACE;
1992 if( rc != LDAP_SUCCESS ) {
1993 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods opattrs (%s)\n",
1997 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
1999 slap_syncrepl_cn_bv.bv_val = syncrepl_cbuf;
2000 assert( si->si_rid < 1000 );
2001 slap_syncrepl_cn_bv.bv_len = snprintf( slap_syncrepl_cn_bv.bv_val,
2002 slap_syncrepl_cn_bvc.bv_len + 1,
2003 "cn=syncrepl%ld", si->si_rid );
2005 build_new_dn( &slap_syncrepl_dn_bv, pdn, &slap_syncrepl_cn_bv,
2007 ber_dupbv( &e->e_name, &slap_syncrepl_dn_bv );
2008 ber_dupbv( &e->e_nname, &slap_syncrepl_dn_bv );
2010 if ( !BER_BVISNULL( &slap_syncrepl_dn_bv ) ) {
2011 slap_sl_free( slap_syncrepl_dn_bv.bv_val, op->o_tmpmemctx );
2016 rc = slap_mods2entry( modlist, &e, 1, 1, &text, txtbuf, textlen );
2018 if( rc != LDAP_SUCCESS ) {
2019 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods2entry (%s)\n",
2023 cb.sc_response = null_callback;
2026 op->o_callback = &cb;
2027 op->o_req_dn = e->e_name;
2028 op->o_req_ndn = e->e_nname;
2030 /* update persistent cookie */
2031 update_cookie_retry:
2032 op->o_tag = LDAP_REQ_MODIFY;
2033 /* Just modify the cookie value, not the entire entry */
2034 op->orm_modlist = mod;
2035 rc = be->be_modify( op, &rs_modify );
2037 if ( rs_modify.sr_err != LDAP_SUCCESS ) {
2038 if ( rs_modify.sr_err == LDAP_REFERRAL ||
2039 rs_modify.sr_err == LDAP_NO_SUCH_OBJECT ) {
2040 op->o_tag = LDAP_REQ_ADD;
2042 rc = be->be_add( op, &rs_add );
2043 if ( rs_add.sr_err != LDAP_SUCCESS ) {
2044 if ( rs_add.sr_err == LDAP_ALREADY_EXISTS ) {
2045 goto update_cookie_retry;
2046 } else if ( rs_add.sr_err == LDAP_REFERRAL ||
2047 rs_add.sr_err == LDAP_NO_SUCH_OBJECT ) {
2048 Debug( LDAP_DEBUG_ANY,
2049 "cookie will be non-persistent\n",
2052 Debug( LDAP_DEBUG_ANY,
2053 "be_add failed (%d)\n", rs_add.sr_err, 0, 0 );
2056 be_entry_release_w( op, e );
2060 Debug( LDAP_DEBUG_ANY,
2061 "be_modify failed (%d)\n", rs_modify.sr_err, 0, 0 );
2069 slap_graduate_commit_csn( op );
2072 if ( !BER_BVISNULL( &cnbva[0] ) ) {
2073 ch_free( cnbva[0].bv_val );
2074 BER_BVZERO( &cnbva[0] );
2076 if ( !BER_BVISNULL( &scbva[0] ) ) {
2077 ch_free( scbva[0].bv_val );
2078 BER_BVZERO( &scbva[0] );
2081 if ( mlnext->sml_next ) {
2082 slap_mods_free( mlnext->sml_next );
2083 mlnext->sml_next = NULL;
2086 for (ml = modlist ; ml != NULL; ml = mlnext ) {
2087 mlnext = ml->sml_next;
2095 syncrepl_isupdate( Operation *op )
2097 return ( syncrepl_isupdate_dn( op->o_bd, &op->o_ndn ));
2101 syncrepl_isupdate_dn(
2103 struct berval* ndn )
2108 if ( !LDAP_STAILQ_EMPTY( &be->be_syncinfo )) {
2109 LDAP_STAILQ_FOREACH( si, &be->be_syncinfo, si_next ) {
2110 if ( ( ret = dn_match( &si->si_updatedn, ndn ) ) ) {
2123 dninfo *dni = op->o_callback->sc_private;
2125 if ( rs->sr_type == REP_SEARCH ) {
2126 if ( !BER_BVISNULL( &dni->dn ) ) {
2127 Debug( LDAP_DEBUG_ANY,
2128 "dn_callback : consistency error - "
2129 "entryUUID is not unique\n", 0, 0, 0 );
2131 ber_dupbv_x( &dni->dn, &rs->sr_entry->e_name, op->o_tmpmemctx );
2132 ber_dupbv_x( &dni->ndn, &rs->sr_entry->e_nname, op->o_tmpmemctx );
2133 /* If there is a new entry, see if it differs from the old.
2134 * We compare the non-normalized values so that cosmetic changes
2135 * in the provider are always propagated.
2137 if ( dni->new_entry ) {
2138 Attribute *old, *new;
2141 /* Did the DN change? Note that we don't explicitly try to
2142 * discover if the deleteOldRdn argument applies here. It
2143 * would save an unnecessary Modify if we detected it, but
2144 * that's a fair amount of trouble to compare the two attr
2147 if ( !dn_match( &rs->sr_entry->e_name,
2148 &dni->new_entry->e_name ) )
2153 for ( i = 0, old = rs->sr_entry->e_attrs;
2155 i++, old = old->a_next )
2160 /* We assume that attributes are saved in the same order
2161 * in the remote and local databases. So if we walk through
2162 * the attributeDescriptions one by one they should match in
2163 * lock step. If not, we signal a change. Otherwise we test
2166 for ( old = rs->sr_entry->e_attrs, new = dni->new_entry->e_attrs;
2168 old = old->a_next, new = new->a_next )
2170 if ( old->a_desc != new->a_desc ) {
2171 dni->wasChanged = 1;
2174 for ( i = 0; ; i++ ) {
2176 nold = BER_BVISNULL( &old->a_vals[i] );
2177 nnew = BER_BVISNULL( &new->a_vals[i] );
2178 /* If both are empty, stop looking */
2179 if ( nold && nnew ) {
2182 /* If they are different, stop looking */
2183 if ( nold != nnew ) {
2184 dni->wasChanged = 1;
2187 if ( ber_bvcmp( &old->a_vals[i], &new->a_vals[i] )) {
2188 dni->wasChanged = 1;
2192 if ( dni->wasChanged ) break;
2194 if ( dni->wasChanged ) {
2195 dni->ads = op->o_tmpalloc( dni->attrs *
2196 sizeof(AttributeDescription *), op->o_tmpmemctx );
2198 for ( old = rs->sr_entry->e_attrs; old; old = old->a_next ) {
2199 dni->ads[i] = old->a_desc;
2205 } else if ( rs->sr_type == REP_RESULT ) {
2206 if ( rs->sr_err == LDAP_SIZELIMIT_EXCEEDED ) {
2207 Debug( LDAP_DEBUG_ANY,
2208 "dn_callback : consistency error - "
2209 "entryUUID is not unique\n", 0, 0, 0 );
2213 return LDAP_SUCCESS;
2217 nonpresent_callback(
2221 syncinfo_t *si = op->o_callback->sc_private;
2224 struct berval* present_uuid = NULL;
2225 struct nonpresent_entry *np_entry;
2227 if ( rs->sr_type == REP_RESULT ) {
2228 count = avl_free( si->si_presentlist, avl_ber_bvfree );
2229 si->si_presentlist = NULL;
2231 } else if ( rs->sr_type == REP_SEARCH ) {
2232 if ( !(si->si_refreshDelete & NP_DELETE_ONE )) {
2233 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID );
2235 if ( a == NULL ) return 0;
2237 present_uuid = avl_find( si->si_presentlist, &a->a_nvals[0],
2241 if ( present_uuid == NULL ) {
2242 np_entry = (struct nonpresent_entry *)
2243 ch_calloc( 1, sizeof( struct nonpresent_entry ));
2244 np_entry->npe_name = ber_dupbv( NULL, &rs->sr_entry->e_name );
2245 np_entry->npe_nname = ber_dupbv( NULL, &rs->sr_entry->e_nname );
2246 LDAP_LIST_INSERT_HEAD( &si->si_nonpresentlist, np_entry, npe_link );
2249 avl_delete( &si->si_presentlist,
2250 &a->a_nvals[0], syncuuid_cmp );
2251 ch_free( present_uuid->bv_val );
2252 ch_free( present_uuid );
2255 return LDAP_SUCCESS;
2263 if ( rs->sr_err != LDAP_SUCCESS &&
2264 rs->sr_err != LDAP_REFERRAL &&
2265 rs->sr_err != LDAP_ALREADY_EXISTS &&
2266 rs->sr_err != LDAP_NO_SUCH_OBJECT &&
2267 rs->sr_err != LDAP_NOT_ALLOWED_ON_NONLEAF )
2269 Debug( LDAP_DEBUG_ANY,
2270 "null_callback : error code 0x%x\n",
2273 return LDAP_SUCCESS;
2277 slap_create_syncrepl_entry(
2279 struct berval *context_csn,
2287 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
2289 attr_merge( e, slap_schema.si_ad_objectClass, ocbva, NULL );
2291 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass,
2294 attr_merge_one( e, slap_schema.si_ad_cn, cn, NULL );
2296 if ( context_csn ) {
2297 attr_merge_one( e, slap_schema.si_ad_syncreplCookie,
2298 context_csn, NULL );
2301 BER_BVSTR( &bv, "{}" );
2302 attr_merge_one( e, slap_schema.si_ad_subtreeSpecification, &bv, NULL );
2304 build_new_dn( &e->e_name, &be->be_nsuffix[0], rdn, NULL );
2305 ber_dupbv( &e->e_nname, &e->e_name );
2311 slap_uuidstr_from_normalized(
2312 struct berval* uuidstr,
2313 struct berval* normalized,
2317 unsigned char nibble;
2320 if ( normalized == NULL ) return NULL;
2321 if ( normalized->bv_len != 16 ) return NULL;
2326 new = (struct berval *)slap_sl_malloc( sizeof(struct berval), ctx );
2327 if ( new == NULL ) {
2334 if ( ( new->bv_val = slap_sl_malloc( new->bv_len + 1, ctx ) ) == NULL ) {
2335 if ( new != uuidstr ) {
2336 slap_sl_free( new, ctx );
2341 for ( i = 0; i < 16; i++ ) {
2342 if ( i == 4 || i == 6 || i == 8 || i == 10 ) {
2343 new->bv_val[(i<<1)+d] = '-';
2347 nibble = (normalized->bv_val[i] >> 4) & 0xF;
2348 if ( nibble < 10 ) {
2349 new->bv_val[(i<<1)+d] = nibble + '0';
2351 new->bv_val[(i<<1)+d] = nibble - 10 + 'a';
2354 nibble = (normalized->bv_val[i]) & 0xF;
2355 if ( nibble < 10 ) {
2356 new->bv_val[(i<<1)+d+1] = nibble + '0';
2358 new->bv_val[(i<<1)+d+1] = nibble - 10 + 'a';
2362 new->bv_val[new->bv_len] = '\0';
2367 syncuuid_cmp( const void* v_uuid1, const void* v_uuid2 )
2369 const struct berval *uuid1 = v_uuid1;
2370 const struct berval *uuid2 = v_uuid2;
2371 int rc = uuid1->bv_len - uuid2->bv_len;
2372 if ( rc ) return rc;
2373 return ( memcmp( uuid1->bv_val, uuid2->bv_val, uuid1->bv_len ) );
2377 avl_ber_bvfree( void *v_bv )
2379 struct berval *bv = (struct berval *)v_bv;
2381 if( v_bv == NULL ) return;
2382 if ( !BER_BVISNULL( bv ) ) {
2383 ch_free( bv->bv_val );
2385 ch_free( (char *) bv );
2389 syncinfo_free( syncinfo_t *sie )
2391 if ( sie->si_provideruri ) {
2392 ch_free( sie->si_provideruri );
2394 if ( sie->si_provideruri_bv ) {
2395 ber_bvarray_free( sie->si_provideruri_bv );
2397 if ( sie->si_updatedn.bv_val ) {
2398 ch_free( sie->si_updatedn.bv_val );
2400 if ( sie->si_binddn ) {
2401 ch_free( sie->si_binddn );
2403 if ( sie->si_passwd ) {
2404 ch_free( sie->si_passwd );
2406 if ( sie->si_saslmech ) {
2407 ch_free( sie->si_saslmech );
2409 if ( sie->si_secprops ) {
2410 ch_free( sie->si_secprops );
2412 if ( sie->si_realm ) {
2413 ch_free( sie->si_realm );
2415 if ( sie->si_authcId ) {
2416 ch_free( sie->si_authcId );
2418 if ( sie->si_authzId ) {
2419 ch_free( sie->si_authzId );
2421 if ( sie->si_filterstr.bv_val ) {
2422 ch_free( sie->si_filterstr.bv_val );
2424 if ( sie->si_base.bv_val ) {
2425 ch_free( sie->si_base.bv_val );
2427 if ( sie->si_attrs ) {
2429 while ( sie->si_attrs[i] != NULL ) {
2430 ch_free( sie->si_attrs[i] );
2433 ch_free( sie->si_attrs );
2435 if ( sie->si_exattrs ) {
2437 while ( sie->si_exattrs[i] != NULL ) {
2438 ch_free( sie->si_exattrs[i] );
2441 ch_free( sie->si_exattrs );
2443 if ( sie->si_anlist ) {
2445 while ( sie->si_anlist[i].an_name.bv_val != NULL ) {
2446 ch_free( sie->si_anlist[i].an_name.bv_val );
2449 ch_free( sie->si_anlist );
2451 if ( sie->si_exanlist ) {
2453 while ( sie->si_exanlist[i].an_name.bv_val != NULL ) {
2454 ch_free( sie->si_exanlist[i].an_name.bv_val );
2457 ch_free( sie->si_exanlist );
2459 if ( sie->si_retryinterval ) {
2460 ch_free( sie->si_retryinterval );
2462 if ( sie->si_retrynum ) {
2463 ch_free( sie->si_retrynum );
2465 if ( sie->si_retrynum_init ) {
2466 ch_free( sie->si_retrynum_init );
2468 slap_sync_cookie_free( &sie->si_syncCookie, 0 );
2469 if ( sie->si_presentlist ) {
2470 avl_free( sie->si_presentlist, avl_ber_bvfree );
2473 ldap_ld_free( sie->si_ld, 1, NULL, NULL );
2475 while ( !LDAP_LIST_EMPTY( &sie->si_nonpresentlist )) {
2476 struct nonpresent_entry* npe;
2477 npe = LDAP_LIST_FIRST( &sie->si_nonpresentlist );
2478 LDAP_LIST_REMOVE( npe, npe_link );
2479 if ( npe->npe_name ) {
2480 if ( npe->npe_name->bv_val ) {
2481 ch_free( npe->npe_name->bv_val );
2483 ch_free( npe->npe_name );
2485 if ( npe->npe_nname ) {
2486 if ( npe->npe_nname->bv_val ) {
2487 ch_free( npe->npe_nname->bv_val );
2489 ch_free( npe->npe_nname );