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-2005 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->ctxcsn != NULL ) {
448 /* command line cookie wins */
449 if ( si->si_syncCookie.ctxcsn ) {
450 ber_bvarray_free( si->si_syncCookie.ctxcsn );
451 si->si_syncCookie.ctxcsn = NULL;
453 ber_dupbv( &cookie_bv, &sc->ctxcsn[0] );
454 ber_bvarray_add( &si->si_syncCookie.ctxcsn, &cookie_bv );
456 if ( sc->rid != -1 ) {
457 /* command line cookie wins */
458 si->si_syncCookie.rid = sc->rid;
460 slap_sync_cookie_free( sc, 1 );
462 slap_compose_sync_cookie( NULL, &newcookie,
463 &si->si_syncCookie.ctxcsn[0],
464 si->si_syncCookie.rid );
465 ber_bvarray_add( &si->si_syncCookie.octet_str, &newcookie );
469 /* no command line cookie is specified */
470 if ( si->si_syncCookie.octet_str == NULL ) {
471 BerVarray cookie = NULL;
472 struct berval cookie_bv;
473 /* try to read stored cookie */
474 backend_attribute( op, NULL, &op->o_req_ndn,
475 slap_schema.si_ad_syncreplCookie, &cookie, ACL_READ );
477 ber_dupbv( &cookie_bv, &cookie[0] );
478 ber_bvarray_add( &si->si_syncCookie.octet_str, &cookie_bv );
479 slap_parse_sync_cookie( &si->si_syncCookie );
480 ber_bvarray_free_x( cookie, op->o_tmpmemctx );
485 rc = ldap_sync_search( si, op->o_tmpmemctx );
487 if( rc != LDAP_SUCCESS ) {
488 Debug( LDAP_DEBUG_ANY, "do_syncrep1: "
489 "ldap_search_ext: %s (%d)\n", ldap_err2string( rc ), rc, 0 );
495 ldap_unbind( si->si_ld );
500 slap_sl_free( op->o_req_ndn.bv_val, op->o_tmpmemctx );
510 LDAPControl **rctrls = NULL;
513 BerElementBuffer berbuf;
514 BerElement *ber = (BerElement *)&berbuf;
516 LDAPMessage *res = NULL;
517 LDAPMessage *msg = NULL;
520 struct berval *retdata = NULL;
525 struct berval syncUUID = BER_BVNULL;
526 struct sync_cookie syncCookie = { NULL };
527 struct sync_cookie syncCookie_req = { NULL };
528 struct berval cookie = BER_BVNULL;
536 Modifications *modlist = NULL;
541 struct timeval *tout_p = NULL;
542 struct timeval tout = { 0, 0 };
544 int refreshDeletes = 0;
546 BerVarray syncUUIDs = NULL;
549 if ( slapd_shutdown ) {
554 ber_init2( ber, NULL, LBER_USE_DER );
555 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
557 Debug( LDAP_DEBUG_TRACE, "=>do_syncrep2\n", 0, 0, 0 );
559 psub = &si->si_be->be_nsuffix[0];
561 slap_dup_sync_cookie( &syncCookie_req, &si->si_syncCookie );
563 if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST ) {
569 while (( rc = ldap_result( si->si_ld, LDAP_RES_ANY, LDAP_MSG_ONE,
570 tout_p, &res )) > 0 )
572 if ( slapd_shutdown ) {
576 for( msg = ldap_first_message( si->si_ld, res );
578 msg = ldap_next_message( si->si_ld, msg ) )
580 switch( ldap_msgtype( msg ) ) {
581 case LDAP_RES_SEARCH_ENTRY:
582 ldap_get_entry_controls( si->si_ld, msg, &rctrls );
583 /* we can't work without the control */
585 Debug( LDAP_DEBUG_ANY, "do_syncrep2: "
586 "got search entry without "
587 "control\n", 0, 0, 0 );
592 ber_init2( ber, &rctrlp->ldctl_value, LBER_USE_DER );
593 ber_scanf( ber, "{em" /*"}"*/, &syncstate, &syncUUID );
594 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
595 ber_scanf( ber, /*"{"*/ "m}", &cookie );
596 if ( !BER_BVISNULL( &cookie ) ) {
597 struct berval tmp_bv;
598 ber_dupbv( &tmp_bv, &cookie );
599 ber_bvarray_add( &syncCookie.octet_str, &tmp_bv );
601 if ( syncCookie.octet_str &&
602 !BER_BVISNULL( &syncCookie.octet_str[0] ) )
604 slap_parse_sync_cookie( &syncCookie );
607 if ( syncrepl_message_to_entry( si, op, msg,
608 &modlist, &entry, syncstate ) == LDAP_SUCCESS ) {
609 rc_efree = syncrepl_entry( si, op, entry, &modlist,
610 syncstate, &syncUUID, &syncCookie_req, syncCookie.ctxcsn );
611 if ( syncCookie.octet_str &&
612 !BER_BVISNULL( &syncCookie.octet_str[0] ) )
614 syncrepl_updateCookie( si, op, psub, &syncCookie );
617 ldap_controls_free( rctrls );
619 slap_mods_free( modlist );
621 if ( rc_efree && entry ) {
627 case LDAP_RES_SEARCH_REFERENCE:
628 Debug( LDAP_DEBUG_ANY,
629 "do_syncrep2: reference received error\n", 0, 0, 0 );
632 case LDAP_RES_SEARCH_RESULT:
633 Debug( LDAP_DEBUG_SYNC,
634 "do_syncrep2: LDAP_RES_SEARCH_RESULT\n", 0, 0, 0 );
635 ldap_parse_result( si->si_ld, msg, &err, NULL, NULL, NULL,
639 ber_init2( ber, &rctrlp->ldctl_value, LBER_USE_DER );
641 ber_scanf( ber, "{" /*"}"*/);
642 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
643 ber_scanf( ber, "m", &cookie );
644 if ( !BER_BVISNULL( &cookie ) ) {
645 struct berval tmp_bv;
646 ber_dupbv( &tmp_bv, &cookie );
647 ber_bvarray_add( &syncCookie.octet_str, &tmp_bv);
649 if ( syncCookie.octet_str &&
650 !BER_BVISNULL( &syncCookie.octet_str[0] ) )
652 slap_parse_sync_cookie( &syncCookie );
655 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_REFRESHDELETES )
657 ber_scanf( ber, "b", &refreshDeletes );
659 ber_scanf( ber, /*"{"*/ "}" );
661 if ( syncCookie_req.ctxcsn == NULL ) {
663 } else if ( syncCookie.ctxcsn == NULL ) {
666 value_match( &match, slap_schema.si_ad_entryCSN,
667 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
668 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
669 &syncCookie_req.ctxcsn[0], &syncCookie.ctxcsn[0],
672 if ( syncCookie.octet_str && !BER_BVISNULL( syncCookie.octet_str ) &&
673 match < 0 && err == LDAP_SUCCESS )
675 syncrepl_updateCookie( si, op, psub, &syncCookie );
678 ldap_controls_free( rctrls );
680 if (si->si_type != LDAP_SYNC_REFRESH_AND_PERSIST) {
681 /* FIXME : different error behaviors according to
682 * 1) err code : LDAP_BUSY ...
683 * 2) on err policy : stop service, stop sync, retry
685 if ( refreshDeletes == 0 && match < 0 &&
686 err == LDAP_SUCCESS )
688 syncrepl_del_nonpresent( op, si, NULL );
690 avl_free( si->si_presentlist, avl_ber_bvfree );
691 si->si_presentlist = NULL;
698 case LDAP_RES_INTERMEDIATE:
699 rc = ldap_parse_intermediate( si->si_ld, msg,
700 &retoid, &retdata, NULL, 0 );
701 if ( !rc && !strcmp( retoid, LDAP_SYNC_INFO ) ) {
702 ber_init2( ber, retdata, LBER_USE_DER );
704 switch ( si_tag = ber_peek_tag( ber, &len )) {
706 case LDAP_TAG_SYNC_NEW_COOKIE:
707 Debug( LDAP_DEBUG_SYNC,
708 "do_syncrep2: %s - %s%s\n",
709 "LDAP_RES_INTERMEDIATE",
710 "NEW_COOKIE", "\n" );
711 ber_scanf( ber, "tm", &tag, &cookie );
713 case LDAP_TAG_SYNC_REFRESH_DELETE:
714 case LDAP_TAG_SYNC_REFRESH_PRESENT:
715 Debug( LDAP_DEBUG_SYNC,
716 "do_syncrep2: %s - %s%s\n",
717 "LDAP_RES_INTERMEDIATE",
718 si_tag == LDAP_TAG_SYNC_REFRESH_PRESENT ?
719 "REFRESH_PRESENT" : "REFRESH_DELETE",
721 if ( si_tag == LDAP_TAG_SYNC_REFRESH_DELETE ) {
722 si->si_refreshDelete = 1;
724 si->si_refreshPresent = 1;
726 ber_scanf( ber, "t{" /*"}"*/, &tag );
727 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE )
729 ber_scanf( ber, "m", &cookie );
730 if ( !BER_BVISNULL( &cookie ) ) {
731 struct berval tmp_bv;
732 ber_dupbv( &tmp_bv, &cookie );
733 ber_bvarray_add( &syncCookie.octet_str,
736 if ( syncCookie.octet_str &&
737 !BER_BVISNULL( &syncCookie.octet_str[0] ) )
739 slap_parse_sync_cookie( &syncCookie );
742 if ( ber_peek_tag( ber, &len ) ==
743 LDAP_TAG_REFRESHDONE )
745 ber_scanf( ber, "b", &refreshDone );
747 ber_scanf( ber, /*"{"*/ "}" );
749 case LDAP_TAG_SYNC_ID_SET:
750 Debug( LDAP_DEBUG_SYNC,
751 "do_syncrep2: %s - %s%s\n",
752 "LDAP_RES_INTERMEDIATE",
755 ber_scanf( ber, "t{" /*"}"*/, &tag );
756 if ( ber_peek_tag( ber, &len ) ==
757 LDAP_TAG_SYNC_COOKIE )
759 ber_scanf( ber, "m", &cookie );
760 if ( !BER_BVISNULL( &cookie ) ) {
761 struct berval tmp_bv;
762 ber_dupbv( &tmp_bv, &cookie );
763 ber_bvarray_add( &syncCookie.octet_str,
766 if ( syncCookie.octet_str &&
767 !BER_BVISNULL( &syncCookie.octet_str[0] ) )
769 slap_parse_sync_cookie( &syncCookie );
772 if ( ber_peek_tag( ber, &len ) ==
773 LDAP_TAG_REFRESHDELETES )
775 ber_scanf( ber, "b", &refreshDeletes );
777 ber_scanf( ber, "[W]", &syncUUIDs );
778 ber_scanf( ber, /*"{"*/ "}" );
779 if ( refreshDeletes ) {
780 syncrepl_del_nonpresent( op, si, syncUUIDs );
781 ber_bvarray_free_x( syncUUIDs, op->o_tmpmemctx );
783 for ( i = 0; !BER_BVISNULL( &syncUUIDs[i] ); i++ ) {
784 struct berval *syncuuid_bv;
785 syncuuid_bv = ber_dupbv( NULL, &syncUUIDs[i] );
786 slap_sl_free( syncUUIDs[i].bv_val,op->o_tmpmemctx );
787 avl_insert( &si->si_presentlist,
788 (caddr_t) syncuuid_bv,
789 syncuuid_cmp, avl_dup_error );
791 slap_sl_free( syncUUIDs, op->o_tmpmemctx );
795 Debug( LDAP_DEBUG_ANY,
796 "do_syncrep2 : unknown syncinfo tag (%ld)\n",
797 (long) si_tag, 0, 0 );
798 ldap_memfree( retoid );
799 ber_bvfree( retdata );
803 if ( syncCookie_req.ctxcsn == NULL ) {
805 } else if ( syncCookie.ctxcsn == NULL ) {
808 value_match( &match, slap_schema.si_ad_entryCSN,
809 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
810 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
811 &syncCookie_req.ctxcsn[0],
812 &syncCookie.ctxcsn[0], &text );
815 if ( syncCookie.ctxcsn && !BER_BVISNULL( &syncCookie.ctxcsn[0] ) &&
818 syncrepl_updateCookie( si, op, psub, &syncCookie);
821 if ( si->si_refreshPresent == 1 ) {
823 syncrepl_del_nonpresent( op, si, NULL );
827 ldap_memfree( retoid );
828 ber_bvfree( retdata );
832 Debug( LDAP_DEBUG_ANY, "do_syncrep2 : "
833 "unknown intermediate response (%d)\n",
835 ldap_memfree( retoid );
836 ber_bvfree( retdata );
842 Debug( LDAP_DEBUG_ANY, "do_syncrep2 : "
843 "unknown message\n", 0, 0, 0 );
847 if ( syncCookie.octet_str ) {
848 slap_sync_cookie_free( &syncCookie_req, 0 );
849 slap_dup_sync_cookie( &syncCookie_req, &syncCookie );
850 slap_sync_cookie_free( &syncCookie, 0 );
860 ldap_get_option( si->si_ld, LDAP_OPT_ERROR_NUMBER, &rc );
861 errstr = ldap_err2string( rc );
863 Debug( LDAP_DEBUG_ANY,
864 "do_syncrep2 : %s\n", errstr, 0, 0 );
868 slap_sync_cookie_free( &syncCookie, 0 );
869 slap_sync_cookie_free( &syncCookie_req, 0 );
871 if ( res ) ldap_msgfree( res );
873 if ( rc && si->si_ld ) {
874 ldap_unbind( si->si_ld );
886 struct re_s* rtask = arg;
887 syncinfo_t *si = ( syncinfo_t * ) rtask->arg;
888 Connection conn = {0};
889 char opbuf[OPERATION_BUFFER_SIZE];
891 int rc = LDAP_SUCCESS;
898 Debug( LDAP_DEBUG_TRACE, "=>do_syncrepl\n", 0, 0, 0 );
903 switch( abs( si->si_type )) {
904 case LDAP_SYNC_REFRESH_ONLY:
905 case LDAP_SYNC_REFRESH_AND_PERSIST:
911 if ( slapd_shutdown ) {
913 ldap_get_option( si->si_ld, LDAP_OPT_DESC, &s );
914 connection_client_stop( s );
915 ldap_unbind( si->si_ld );
921 op = (Operation *)opbuf;
922 connection_fake_init( &conn, op, ctx );
924 /* use global malloc for now */
925 op->o_tmpmemctx = NULL;
926 op->o_tmpmfuncs = &ch_mfuncs;
928 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
929 op->o_bd = be = si->si_be;
930 op->o_dn = op->o_bd->be_rootdn;
931 op->o_ndn = op->o_bd->be_rootndn;
933 /* Establish session, do search */
936 si->si_refreshDelete = 0;
937 si->si_refreshPresent = 0;
938 rc = do_syncrep1( op, si );
941 /* Process results */
942 if ( rc == LDAP_SUCCESS ) {
943 ldap_get_option( si->si_ld, LDAP_OPT_DESC, &s );
945 rc = do_syncrep2( op, si );
947 if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST ) {
948 /* If we succeeded, enable the connection for further listening.
949 * If we failed, tear down the connection and reschedule.
951 if ( rc == LDAP_SUCCESS ) {
953 rc = connection_client_setup( s, do_syncrepl, arg );
955 connection_client_enable( s );
957 } else if ( !first ) {
961 if ( rc == -2 ) rc = 0;
965 /* At this point, we have 4 cases:
966 * 1) for any hard failure, give up and remove this task
967 * 2) for ServerDown, reschedule this task to run
968 * 3) for Refresh and Success, reschedule to run
969 * 4) for Persist and Success, reschedule to defer
971 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
973 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, rtask )) {
974 ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
978 connection_client_stop( s );
981 if ( rc == LDAP_SUCCESS ) {
982 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
985 rtask->interval.tv_sec = si->si_interval;
986 ldap_pvt_runqueue_resched( &slapd_rq, rtask, defer );
987 if ( si->si_retrynum ) {
988 for ( i = 0; si->si_retrynum_init[i] != -2; i++ ) {
989 si->si_retrynum[i] = si->si_retrynum_init[i];
991 si->si_retrynum[i] = -2;
994 for ( i = 0; si->si_retrynum && si->si_retrynum[i] <= 0; i++ ) {
995 if ( si->si_retrynum[i] == -1 || si->si_retrynum[i] == -2 )
999 if ( !si->si_retrynum || si->si_retrynum[i] == -2 ) {
1000 ldap_pvt_runqueue_remove( &slapd_rq, rtask );
1001 } else if ( si->si_retrynum[i] >= -1 ) {
1002 if ( si->si_retrynum[i] > 0 )
1003 si->si_retrynum[i]--;
1004 rtask->interval.tv_sec = si->si_retryinterval[i];
1005 ldap_pvt_runqueue_resched( &slapd_rq, rtask, 0 );
1006 slap_wake_listener();
1010 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
1016 syncrepl_message_to_entry(
1020 Modifications **modlist,
1026 BerElement *ber = NULL;
1029 Modifications **modtail = modlist;
1032 char txtbuf[SLAP_TEXT_BUFLEN];
1033 size_t textlen = sizeof txtbuf;
1035 struct berval bdn = {0, NULL}, dn, ndn;
1040 if ( ldap_msgtype( msg ) != LDAP_RES_SEARCH_ENTRY ) {
1041 Debug( LDAP_DEBUG_ANY,
1042 "Message type should be entry (%d)", ldap_msgtype( msg ), 0, 0 );
1046 op->o_tag = LDAP_REQ_ADD;
1048 rc = ldap_get_dn_ber( si->si_ld, msg, &ber, &bdn );
1050 if ( rc != LDAP_SUCCESS ) {
1051 Debug( LDAP_DEBUG_ANY,
1052 "syncrepl_message_to_entry : dn get failed (%d)", rc, 0, 0 );
1056 dnPrettyNormal( NULL, &bdn, &dn, &ndn, op->o_tmpmemctx );
1057 ber_dupbv( &op->o_req_dn, &dn );
1058 ber_dupbv( &op->o_req_ndn, &ndn );
1059 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1060 slap_sl_free( dn.bv_val, op->o_tmpmemctx );
1062 if ( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_DELETE ) {
1065 return LDAP_SUCCESS;
1068 if ( entry == NULL ) {
1072 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ) );
1074 e->e_name = op->o_req_dn;
1075 e->e_nname = op->o_req_ndn;
1077 while ( ber_remaining( ber ) ) {
1078 if ( (ber_scanf( ber, "{mW}", &tmp.sml_type, &tmp.sml_values ) ==
1079 LBER_ERROR ) || BER_BVISNULL( &tmp.sml_type ) )
1084 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
1086 mod->sml_op = LDAP_MOD_REPLACE;
1087 mod->sml_next = NULL;
1088 mod->sml_desc = NULL;
1089 mod->sml_type = tmp.sml_type;
1090 mod->sml_values = tmp.sml_values;
1091 mod->sml_nvalues = NULL;
1094 modtail = &mod->sml_next;
1097 if ( *modlist == NULL ) {
1098 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: no attributes\n",
1104 rc = slap_mods_check( *modlist, &text, txtbuf, textlen, NULL );
1106 if ( rc != LDAP_SUCCESS ) {
1107 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods check (%s)\n",
1112 /* Strip out dynamically generated attrs */
1113 for ( modtail = modlist; *modtail ; ) {
1115 if ( mod->sml_desc->ad_type->sat_flags & SLAP_AT_DYNAMIC ) {
1116 *modtail = mod->sml_next;
1117 slap_mod_free( &mod->sml_mod, 0 );
1120 modtail = &mod->sml_next;
1124 /* Strip out attrs in exattrs list */
1125 for ( modtail = modlist; *modtail ; ) {
1127 if ( ldap_charray_inlist( si->si_exattrs,
1128 mod->sml_desc->ad_type->sat_cname.bv_val )) {
1129 *modtail = mod->sml_next;
1130 slap_mod_free( &mod->sml_mod, 0 );
1133 modtail = &mod->sml_next;
1137 rc = slap_mods2entry( *modlist, &e, 1, 1, &text, txtbuf, textlen);
1138 if( rc != LDAP_SUCCESS ) {
1139 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods2entry (%s)\n",
1144 ber_free ( ber, 0 );
1145 if ( rc != LDAP_SUCCESS ) {
1155 static struct berval generic_filterstr = BER_BVC("(objectclass=*)");
1157 /* During a refresh, we may get an LDAP_SYNC_ADD for an already existing
1158 * entry if a previous refresh was interrupted before sending us a new
1159 * context state. We try to compare the new entry to the existing entry
1160 * and ignore the new entry if they are the same.
1162 * Also, we may get an update where the entryDN has changed, due to
1163 * a ModDn on the provider. We detect this as well, so we can issue
1164 * the corresponding operation locally.
1166 * In the case of a modify, we get a list of all the attributes
1167 * in the original entry. Rather than deleting the entry and re-adding it,
1168 * we issue a Modify request that deletes all the attributes and adds all
1169 * the new ones. This avoids the issue of trying to delete/add a non-leaf
1172 * We don't try to otherwise distinguish ModDN from Modify; in the case of
1173 * a ModDN we will issue both operations on the local database.
1175 typedef struct dninfo {
1179 int renamed; /* Was an existing entry renamed? */
1180 int wasChanged; /* are the attributes changed? */
1181 int attrs; /* how many attribute types are in the ads list */
1182 AttributeDescription **ads;
1190 Modifications** modlist,
1192 struct berval* syncUUID,
1193 struct sync_cookie* syncCookie_req,
1194 struct berval* syncCSN )
1196 Backend *be = op->o_bd;
1197 slap_callback cb = { NULL };
1198 struct berval *syncuuid_bv = NULL;
1199 struct berval syncUUID_strrep = BER_BVNULL;
1200 struct berval uuid_bv = BER_BVNULL;
1202 SlapReply rs_search = {REP_RESULT};
1203 SlapReply rs_delete = {REP_RESULT};
1204 SlapReply rs_add = {REP_RESULT};
1205 SlapReply rs_modify = {REP_RESULT};
1207 AttributeAssertion ava = {0};
1208 int rc = LDAP_SUCCESS;
1209 int ret = LDAP_SUCCESS;
1211 struct berval pdn = BER_BVNULL;
1212 struct berval org_req_dn = BER_BVNULL;
1213 struct berval org_req_ndn = BER_BVNULL;
1214 int org_managedsait;
1218 switch( syncstate ) {
1219 case LDAP_SYNC_PRESENT:
1220 Debug( LDAP_DEBUG_SYNC, "%s: %s\n",
1222 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_PRESENT)", 0 );
1225 Debug( LDAP_DEBUG_SYNC, "%s: %s\n",
1227 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_ADD)", 0 );
1229 case LDAP_SYNC_DELETE:
1230 Debug( LDAP_DEBUG_SYNC, "%s: %s\n",
1232 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_DELETE)", 0 );
1234 case LDAP_SYNC_MODIFY:
1235 Debug( LDAP_DEBUG_SYNC, "%s: %s\n",
1237 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_MODIFY)", 0 );
1240 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
1242 "LDAP_RES_SEARCH_ENTRY(UNKNOWN syncstate)", 0 );
1245 if (( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD )) {
1246 if ( !si->si_refreshPresent ) {
1247 syncuuid_bv = ber_dupbv( NULL, syncUUID );
1248 avl_insert( &si->si_presentlist, (caddr_t) syncuuid_bv,
1249 syncuuid_cmp, avl_dup_error );
1253 if ( syncstate == LDAP_SYNC_PRESENT ) {
1255 } else if ( syncstate != LDAP_SYNC_DELETE ) {
1256 if ( entry == NULL ) {
1261 f.f_choice = LDAP_FILTER_EQUALITY;
1263 ava.aa_desc = slap_schema.si_ad_entryUUID;
1264 (void)slap_uuidstr_from_normalized( &syncUUID_strrep, syncUUID, op->o_tmpmemctx );
1265 ava.aa_value = *syncUUID;
1266 op->ors_filter = &f;
1268 op->ors_filterstr.bv_len = STRLENOF( "entryUUID=" ) + syncUUID->bv_len;
1269 op->ors_filterstr.bv_val = (char *) slap_sl_malloc(
1270 op->ors_filterstr.bv_len + 1, op->o_tmpmemctx );
1271 AC_MEMCPY( op->ors_filterstr.bv_val, "entryUUID=", STRLENOF( "entryUUID=" ) );
1272 AC_MEMCPY( &op->ors_filterstr.bv_val[STRLENOF( "entryUUID=" )],
1273 syncUUID->bv_val, syncUUID->bv_len );
1274 op->ors_filterstr.bv_val[op->ors_filterstr.bv_len] = '\0';
1276 op->o_tag = LDAP_REQ_SEARCH;
1277 op->ors_scope = LDAP_SCOPE_SUBTREE;
1279 /* get the entry for this UUID */
1280 op->o_req_dn = si->si_base;
1281 op->o_req_ndn = si->si_base;
1283 op->o_time = slap_get_time();
1284 op->ors_tlimit = SLAP_NO_LIMIT;
1287 op->ors_attrs = slap_anlist_all_attributes;
1288 op->ors_attrsonly = 0;
1290 /* set callback function */
1291 op->o_callback = &cb;
1292 cb.sc_response = dn_callback;
1293 cb.sc_private = &dni;
1294 dni.new_entry = entry;
1296 if ( limits_check( op, &rs_search ) == 0 ) {
1297 rc = be->be_search( op, &rs_search );
1298 Debug( LDAP_DEBUG_SYNC,
1299 "syncrepl_entry: %s (%d)\n",
1300 "be_search", rc, 0 );
1303 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
1304 slap_sl_free( op->ors_filterstr.bv_val, op->o_tmpmemctx );
1307 cb.sc_response = null_callback;
1310 if ( entry && entry->e_name.bv_val ) {
1311 Debug( LDAP_DEBUG_SYNC,
1312 "syncrepl_entry: %s\n",
1313 entry->e_name.bv_val, 0, 0 );
1315 Debug( LDAP_DEBUG_SYNC,
1316 "syncrepl_entry: %s\n",
1317 dni.dn.bv_val ? dni.dn.bv_val : "(null)", 0, 0 );
1320 org_req_dn = op->o_req_dn;
1321 org_req_ndn = op->o_req_ndn;
1322 org_managedsait = get_manageDSAit( op );
1323 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
1325 if ( syncstate != LDAP_SYNC_DELETE ) {
1326 attr_delete( &entry->e_attrs, slap_schema.si_ad_entryUUID );
1327 attr_merge_one( entry, slap_schema.si_ad_entryUUID,
1328 &syncUUID_strrep, syncUUID );
1331 switch ( syncstate ) {
1333 case LDAP_SYNC_MODIFY:
1335 if ( BER_BVISNULL( &dni.dn )) {
1337 op->o_req_dn = entry->e_name;
1338 op->o_req_ndn = entry->e_nname;
1339 op->o_tag = LDAP_REQ_ADD;
1342 rc = be->be_add( op, &rs_add );
1343 Debug( LDAP_DEBUG_SYNC,
1344 "syncrepl_entry: %s (%d)\n",
1346 switch ( rs_add.sr_err ) {
1348 be_entry_release_w( op, entry );
1353 /* we assume that LDAP_NO_SUCH_OBJECT is returned
1354 * only if the suffix entry is not present */
1355 case LDAP_NO_SUCH_OBJECT:
1356 syncrepl_add_glue( op, entry );
1360 /* if an entry was added via syncrepl_add_glue(),
1361 * it likely has no entryUUID, so the previous
1362 * be_search() doesn't find it. In this case,
1363 * give syncrepl a chance to modify it. Also
1364 * allow for entries that were recreated with the
1365 * same DN but a different entryUUID.
1367 case LDAP_ALREADY_EXISTS:
1369 Operation op2 = *op;
1370 SlapReply rs2 = { 0 };
1371 slap_callback cb2 = { 0 };
1373 op2.o_tag = LDAP_REQ_SEARCH;
1374 op2.o_req_dn = entry->e_name;
1375 op2.o_req_ndn = entry->e_nname;
1376 op2.ors_scope = LDAP_SCOPE_BASE;
1377 op2.ors_attrs = slap_anlist_all_attributes;
1378 op2.ors_attrsonly = 0;
1379 op2.ors_limit = NULL;
1381 op2.ors_tlimit = SLAP_NO_LIMIT;
1383 f.f_choice = LDAP_FILTER_PRESENT;
1384 f.f_desc = slap_schema.si_ad_objectClass;
1385 op2.ors_filter = &f;
1386 op2.ors_filterstr = generic_filterstr;
1388 op2.o_callback = &cb2;
1389 cb2.sc_response = dn_callback;
1390 cb2.sc_private = &dni;
1392 be->be_search( &op2, &rs2 );
1400 Debug( LDAP_DEBUG_ANY,
1401 "syncrepl_entry : be_add failed (%d)\n",
1402 rs_add.sr_err, 0, 0 );
1409 op->o_req_dn = dni.dn;
1410 op->o_req_ndn = dni.ndn;
1411 if ( dni.renamed ) {
1412 struct berval noldp, newp, nnewp;
1414 op->o_tag = LDAP_REQ_MODRDN;
1415 dnRdn( &entry->e_name, &op->orr_newrdn );
1416 dnRdn( &entry->e_nname, &op->orr_nnewrdn );
1418 dnParent( &dni.ndn, &noldp );
1419 dnParent( &entry->e_nname, &nnewp );
1420 if ( !dn_match( &noldp, &newp )) {
1421 dnParent( &entry->e_name, &newp );
1422 op->orr_newSup = &newp;
1423 op->orr_nnewSup = &nnewp;
1425 op->orr_deleteoldrdn = 0;
1426 rc = be->be_modrdn( op, &rs_modify );
1427 Debug( LDAP_DEBUG_SYNC,
1428 "syncrepl_entry: %s (%d)\n",
1429 "be_modrdn", rc, 0 );
1430 if ( rs_modify.sr_err == LDAP_SUCCESS ) {
1431 op->o_req_dn = entry->e_name;
1432 op->o_req_ndn = entry->e_nname;
1438 if ( dni.wasChanged ) {
1439 Modifications *mod, *modhead = NULL;
1440 Modifications *modtail = NULL;
1443 op->o_tag = LDAP_REQ_MODIFY;
1447 /* Delete all the old attrs */
1448 for ( i = 0; i < dni.attrs; i++ ) {
1449 mod = ch_malloc( sizeof( Modifications ) );
1450 mod->sml_op = LDAP_MOD_DELETE;
1451 mod->sml_desc = dni.ads[i];
1452 mod->sml_type = mod->sml_desc->ad_cname;
1453 mod->sml_values = NULL;
1454 mod->sml_nvalues = NULL;
1455 if ( !modhead ) modhead = mod;
1457 modtail->sml_next = mod;
1462 /* Append passed in list to ours */
1464 modtail->sml_next = *modlist;
1470 /* Find end of this list */
1471 for ( ; mod != NULL; mod = mod->sml_next ) {
1475 mod = (Modifications *)ch_calloc(1, sizeof(Modifications));
1476 mod->sml_op = LDAP_MOD_REPLACE;
1477 mod->sml_desc = slap_schema.si_ad_entryUUID;
1478 mod->sml_type = mod->sml_desc->ad_cname;
1479 ber_dupbv( &uuid_bv, &syncUUID_strrep );
1480 ber_bvarray_add( &mod->sml_values, &uuid_bv );
1481 ber_dupbv( &uuid_bv, syncUUID );
1482 ber_bvarray_add( &mod->sml_nvalues, &uuid_bv );
1483 modtail->sml_next = mod;
1485 op->o_tag = LDAP_REQ_MODIFY;
1486 op->orm_modlist = *modlist;
1488 rc = be->be_modify( op, &rs_modify );
1489 Debug( LDAP_DEBUG_SYNC,
1490 "syncrepl_entry: %s (%d)\n",
1491 "be_modify", rc, 0 );
1492 if ( rs_modify.sr_err != LDAP_SUCCESS ) {
1493 Debug( LDAP_DEBUG_ANY,
1494 "syncrepl_entry : be_modify failed (%d)\n",
1495 rs_modify.sr_err, 0, 0 );
1500 case LDAP_SYNC_DELETE :
1501 if ( !BER_BVISNULL( &dni.dn )) {
1502 op->o_req_dn = dni.dn;
1503 op->o_req_ndn = dni.ndn;
1504 op->o_tag = LDAP_REQ_DELETE;
1505 rc = be->be_delete( op, &rs_delete );
1506 Debug( LDAP_DEBUG_SYNC,
1507 "syncrepl_entry: %s (%d)\n",
1508 "be_delete", rc, 0 );
1510 while ( rs_delete.sr_err == LDAP_SUCCESS
1511 && op->o_delete_glue_parent ) {
1512 op->o_delete_glue_parent = 0;
1513 if ( !be_issuffix( op->o_bd, &op->o_req_ndn )) {
1514 slap_callback cb = { NULL };
1515 cb.sc_response = slap_null_cb;
1516 dnParent( &op->o_req_ndn, &pdn );
1518 op->o_req_ndn = pdn;
1519 op->o_callback = &cb;
1520 op->o_bd->be_delete( op, &rs_delete );
1530 Debug( LDAP_DEBUG_ANY,
1531 "syncrepl_entry : unknown syncstate\n", 0, 0, 0 );
1537 if ( !BER_BVISNULL( &syncUUID_strrep ) ) {
1538 slap_sl_free( syncUUID_strrep.bv_val, op->o_tmpmemctx );
1539 BER_BVZERO( &syncUUID_strrep );
1542 op->o_tmpfree( dni.ads, op->o_tmpmemctx );
1544 if ( !BER_BVISNULL( &dni.ndn ) ) {
1545 op->o_tmpfree( dni.ndn.bv_val, op->o_tmpmemctx );
1547 if ( !BER_BVISNULL( &dni.dn ) ) {
1548 op->o_tmpfree( dni.dn.bv_val, op->o_tmpmemctx );
1553 static struct berval gcbva[] = {
1559 #define NP_DELETE_ONE 2
1562 syncrepl_del_nonpresent(
1567 Backend* be = op->o_bd;
1568 slap_callback cb = { NULL };
1569 SlapReply rs_search = {REP_RESULT};
1570 SlapReply rs_delete = {REP_RESULT};
1571 SlapReply rs_modify = {REP_RESULT};
1572 struct nonpresent_entry *np_list, *np_prev;
1575 Modifications *mlnext;
1577 Modifications *modlist = NULL;
1578 Modifications **modtail;
1579 AttributeName an[2];
1581 struct berval pdn = BER_BVNULL;
1582 struct berval org_req_dn = BER_BVNULL;
1583 struct berval org_req_ndn = BER_BVNULL;
1584 int org_managedsait;
1586 op->o_req_dn = si->si_base;
1587 op->o_req_ndn = si->si_base;
1589 cb.sc_response = nonpresent_callback;
1592 op->o_callback = &cb;
1593 op->o_tag = LDAP_REQ_SEARCH;
1594 op->ors_scope = si->si_scope;
1595 op->ors_deref = LDAP_DEREF_NEVER;
1596 op->o_time = slap_get_time();
1597 op->ors_tlimit = SLAP_NO_LIMIT;
1602 AttributeAssertion eq;
1605 op->ors_attrsonly = 1;
1606 op->ors_attrs = slap_anlist_no_attrs;
1607 op->ors_limit = NULL;
1608 op->ors_filter = &uf;
1609 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
1612 uf.f_av_desc = slap_schema.si_ad_entryUUID;
1614 uf.f_choice = LDAP_FILTER_EQUALITY;
1615 si->si_refreshDelete |= NP_DELETE_ONE;
1617 for (i=0; uuids[i].bv_val; i++) {
1619 uf.f_av_value = uuids[i];
1620 rc = be->be_search( op, &rs_search );
1622 si->si_refreshDelete ^= NP_DELETE_ONE;
1624 memset( &an[0], 0, 2 * sizeof( AttributeName ) );
1625 an[0].an_name = slap_schema.si_ad_entryUUID->ad_cname;
1626 an[0].an_desc = slap_schema.si_ad_entryUUID;
1628 op->ors_slimit = SLAP_NO_LIMIT;
1629 op->ors_attrsonly = 0;
1630 op->ors_filter = str2filter_x( op, si->si_filterstr.bv_val );
1631 op->ors_filterstr = si->si_filterstr;
1632 op->o_nocaching = 1;
1633 op->o_managedsait = SLAP_CONTROL_NONE;
1635 if ( limits_check( op, &rs_search ) == 0 ) {
1636 rc = be->be_search( op, &rs_search );
1638 if ( op->ors_filter ) filter_free_x( op, op->ors_filter );
1641 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
1642 op->o_nocaching = 0;
1644 if ( !LDAP_LIST_EMPTY( &si->si_nonpresentlist ) ) {
1645 np_list = LDAP_LIST_FIRST( &si->si_nonpresentlist );
1646 while ( np_list != NULL ) {
1647 LDAP_LIST_REMOVE( np_list, npe_link );
1649 np_list = LDAP_LIST_NEXT( np_list, npe_link );
1650 op->o_tag = LDAP_REQ_DELETE;
1651 op->o_callback = &cb;
1652 cb.sc_response = null_callback;
1654 op->o_req_dn = *np_prev->npe_name;
1655 op->o_req_ndn = *np_prev->npe_nname;
1656 rc = op->o_bd->be_delete( op, &rs_delete );
1658 if ( rs_delete.sr_err == LDAP_NOT_ALLOWED_ON_NONLEAF ) {
1660 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1661 mod->sml_op = LDAP_MOD_REPLACE;
1662 mod->sml_desc = slap_schema.si_ad_objectClass;
1663 mod->sml_type = mod->sml_desc->ad_cname;
1664 mod->sml_values = &gcbva[0];
1666 modtail = &mod->sml_next;
1668 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1669 mod->sml_op = LDAP_MOD_REPLACE;
1670 mod->sml_desc = slap_schema.si_ad_structuralObjectClass;
1671 mod->sml_type = mod->sml_desc->ad_cname;
1672 mod->sml_values = &gcbva[1];
1674 modtail = &mod->sml_next;
1676 op->o_tag = LDAP_REQ_MODIFY;
1677 op->orm_modlist = modlist;
1679 rc = be->be_modify( op, &rs_modify );
1681 for ( ml = modlist; ml != NULL; ml = mlnext ) {
1682 mlnext = ml->sml_next;
1687 org_managedsait = get_manageDSAit( op );
1688 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
1690 while ( rs_delete.sr_err == LDAP_SUCCESS &&
1691 op->o_delete_glue_parent ) {
1692 op->o_delete_glue_parent = 0;
1693 if ( !be_issuffix( op->o_bd, &op->o_req_ndn )) {
1694 slap_callback cb = { NULL };
1695 cb.sc_response = slap_null_cb;
1696 dnParent( &op->o_req_ndn, &pdn );
1698 op->o_req_ndn = pdn;
1699 op->o_callback = &cb;
1700 /* give it a root privil ? */
1701 op->o_bd->be_delete( op, &rs_delete );
1707 op->o_managedsait = org_managedsait;
1708 op->o_req_dn = org_req_dn;
1709 op->o_req_ndn = org_req_ndn;
1710 op->o_delete_glue_parent = 0;
1712 ber_bvfree( np_prev->npe_name );
1713 ber_bvfree( np_prev->npe_nname );
1714 BER_BVZERO( &op->o_req_dn );
1715 BER_BVZERO( &op->o_req_ndn );
1728 Backend *be = op->o_bd;
1729 slap_callback cb = { NULL };
1734 struct berval dn = {0, NULL};
1735 struct berval ndn = {0, NULL};
1737 SlapReply rs_add = {REP_RESULT};
1740 op->o_tag = LDAP_REQ_ADD;
1741 op->o_callback = &cb;
1742 cb.sc_response = null_callback;
1743 cb.sc_private = NULL;
1748 /* count RDNs in suffix */
1749 if ( !BER_BVISEMPTY( &be->be_nsuffix[0] ) ) {
1750 for ( i = 0, ptr = be->be_nsuffix[0].bv_val; ptr; ptr = strchr( ptr, ',' ) ) {
1760 /* Start with BE suffix */
1761 for ( i = 0, ptr = NULL; i < suffrdns; i++ ) {
1762 comma = strrchr( dn.bv_val, ',' );
1763 if ( ptr ) *ptr = ',';
1764 if ( comma ) *comma = '\0';
1769 dn.bv_len -= ptr - dn.bv_val;
1772 /* the normalizedDNs are always the same length, no counting
1775 if ( ndn.bv_len > be->be_nsuffix[0].bv_len ) {
1776 ndn.bv_val += ndn.bv_len - be->be_nsuffix[0].bv_len;
1777 ndn.bv_len = be->be_nsuffix[0].bv_len;
1780 while ( ndn.bv_val > e->e_nname.bv_val ) {
1781 glue = (Entry *) ch_calloc( 1, sizeof(Entry) );
1782 ber_dupbv( &glue->e_name, &dn );
1783 ber_dupbv( &glue->e_nname, &ndn );
1785 a = ch_calloc( 1, sizeof( Attribute ));
1786 a->a_desc = slap_schema.si_ad_objectClass;
1788 a->a_vals = ch_calloc( 3, sizeof( struct berval ));
1789 ber_dupbv( &a->a_vals[0], &gcbva[0] );
1790 ber_dupbv( &a->a_vals[1], &gcbva[1] );
1791 ber_dupbv( &a->a_vals[2], &gcbva[2] );
1793 a->a_nvals = a->a_vals;
1795 a->a_next = glue->e_attrs;
1798 a = ch_calloc( 1, sizeof( Attribute ));
1799 a->a_desc = slap_schema.si_ad_structuralObjectClass;
1801 a->a_vals = ch_calloc( 2, sizeof( struct berval ));
1802 ber_dupbv( &a->a_vals[0], &gcbva[1] );
1803 ber_dupbv( &a->a_vals[1], &gcbva[2] );
1805 a->a_nvals = a->a_vals;
1807 a->a_next = glue->e_attrs;
1810 op->o_req_dn = glue->e_name;
1811 op->o_req_ndn = glue->e_nname;
1813 rc = be->be_add ( op, &rs_add );
1814 if ( rs_add.sr_err == LDAP_SUCCESS ) {
1815 be_entry_release_w( op, glue );
1817 /* incl. ALREADY EXIST */
1821 /* Move to next child */
1822 for (ptr = dn.bv_val-2; ptr > e->e_name.bv_val && *ptr != ','; ptr--) {
1825 if ( ptr == e->e_name.bv_val ) break;
1827 dn.bv_len = e->e_name.bv_len - (ptr-e->e_name.bv_val);
1828 for( ptr = ndn.bv_val-2;
1829 ptr > e->e_nname.bv_val && *ptr != ',';
1835 ndn.bv_len = e->e_nname.bv_len - (ptr-e->e_nname.bv_val);
1838 op->o_req_dn = e->e_name;
1839 op->o_req_ndn = e->e_nname;
1841 rc = be->be_add ( op, &rs_add );
1842 if ( rs_add.sr_err == LDAP_SUCCESS ) {
1843 be_entry_release_w( op, e );
1851 static struct berval ocbva[] = {
1853 BER_BVC("subentry"),
1854 BER_BVC("syncConsumerSubentry"),
1858 static struct berval cnbva[] = {
1863 static struct berval ssbva[] = {
1868 static struct berval scbva[] = {
1874 syncrepl_updateCookie(
1878 struct sync_cookie *syncCookie )
1880 Backend *be = op->o_bd;
1882 Modifications *mlnext;
1884 Modifications *modlist = NULL;
1885 Modifications **modtail = &modlist;
1888 char txtbuf[SLAP_TEXT_BUFLEN];
1889 size_t textlen = sizeof txtbuf;
1894 char syncrepl_cbuf[sizeof(CN_STR SYNCREPL_STR)];
1895 struct berval slap_syncrepl_dn_bv = BER_BVNULL;
1896 struct berval slap_syncrepl_cn_bv = BER_BVNULL;
1898 slap_callback cb = { NULL };
1899 SlapReply rs_add = {REP_RESULT};
1900 SlapReply rs_modify = {REP_RESULT};
1902 slap_sync_cookie_free( &si->si_syncCookie, 0 );
1903 slap_dup_sync_cookie( &si->si_syncCookie, syncCookie );
1905 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1906 mod->sml_op = LDAP_MOD_REPLACE;
1907 mod->sml_desc = slap_schema.si_ad_objectClass;
1908 mod->sml_type = mod->sml_desc->ad_cname;
1909 mod->sml_values = ocbva;
1911 modtail = &mod->sml_next;
1913 ber_dupbv( &cnbva[0], (struct berval *) &slap_syncrepl_bvc );
1914 assert( si->si_rid < 1000 );
1915 cnbva[0].bv_len = snprintf( cnbva[0].bv_val,
1916 slap_syncrepl_bvc.bv_len + 1,
1917 "syncrepl%ld", si->si_rid );
1918 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1919 mod->sml_op = LDAP_MOD_REPLACE;
1920 mod->sml_desc = slap_schema.si_ad_cn;
1921 mod->sml_type = mod->sml_desc->ad_cname;
1922 mod->sml_values = cnbva;
1924 modtail = &mod->sml_next;
1926 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1927 mod->sml_op = LDAP_MOD_REPLACE;
1928 mod->sml_desc = slap_schema.si_ad_subtreeSpecification;
1929 mod->sml_type = mod->sml_desc->ad_cname;
1930 mod->sml_values = ssbva;
1932 modtail = &mod->sml_next;
1934 /* Keep this last, so we can avoid touching the previous
1935 * attributes unnecessarily.
1937 if ( scbva[0].bv_val ) ch_free( scbva[0].bv_val );
1938 ber_dupbv( &scbva[0], &si->si_syncCookie.octet_str[0] );
1939 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1940 mod->sml_op = LDAP_MOD_REPLACE;
1941 mod->sml_desc = slap_schema.si_ad_syncreplCookie;
1942 mod->sml_type = mod->sml_desc->ad_cname;
1943 mod->sml_values = scbva;
1945 modtail = &mod->sml_next;
1947 slap_queue_csn( op, si->si_syncCookie.ctxcsn );
1951 op->o_tag = LDAP_REQ_ADD;
1952 rc = slap_mods_opattrs( op, modlist, modtail,
1953 &text, txtbuf, textlen, 0 );
1955 for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
1956 ml->sml_op = LDAP_MOD_REPLACE;
1959 if( rc != LDAP_SUCCESS ) {
1960 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods opattrs (%s)\n",
1964 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
1966 slap_syncrepl_cn_bv.bv_val = syncrepl_cbuf;
1967 assert( si->si_rid < 1000 );
1968 slap_syncrepl_cn_bv.bv_len = snprintf( slap_syncrepl_cn_bv.bv_val,
1969 slap_syncrepl_cn_bvc.bv_len + 1,
1970 "cn=syncrepl%ld", si->si_rid );
1972 build_new_dn( &slap_syncrepl_dn_bv, pdn, &slap_syncrepl_cn_bv,
1974 ber_dupbv( &e->e_name, &slap_syncrepl_dn_bv );
1975 ber_dupbv( &e->e_nname, &slap_syncrepl_dn_bv );
1977 if ( !BER_BVISNULL( &slap_syncrepl_dn_bv ) ) {
1978 slap_sl_free( slap_syncrepl_dn_bv.bv_val, op->o_tmpmemctx );
1983 rc = slap_mods2entry( modlist, &e, 1, 1, &text, txtbuf, textlen );
1985 if( rc != LDAP_SUCCESS ) {
1986 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods2entry (%s)\n",
1990 cb.sc_response = null_callback;
1993 op->o_callback = &cb;
1994 op->o_req_dn = e->e_name;
1995 op->o_req_ndn = e->e_nname;
1997 /* update persistent cookie */
1998 update_cookie_retry:
1999 op->o_tag = LDAP_REQ_MODIFY;
2000 /* Just modify the cookie value, not the entire entry */
2001 op->orm_modlist = mod;
2002 rc = be->be_modify( op, &rs_modify );
2004 if ( rs_modify.sr_err != LDAP_SUCCESS ) {
2005 if ( rs_modify.sr_err == LDAP_REFERRAL ||
2006 rs_modify.sr_err == LDAP_NO_SUCH_OBJECT ) {
2007 op->o_tag = LDAP_REQ_ADD;
2009 rc = be->be_add( op, &rs_add );
2010 if ( rs_add.sr_err != LDAP_SUCCESS ) {
2011 if ( rs_add.sr_err == LDAP_ALREADY_EXISTS ) {
2012 goto update_cookie_retry;
2013 } else if ( rs_add.sr_err == LDAP_REFERRAL ||
2014 rs_add.sr_err == LDAP_NO_SUCH_OBJECT ) {
2015 Debug( LDAP_DEBUG_ANY,
2016 "cookie will be non-persistent\n",
2019 Debug( LDAP_DEBUG_ANY,
2020 "be_add failed (%d)\n", rs_add.sr_err, 0, 0 );
2023 be_entry_release_w( op, e );
2027 Debug( LDAP_DEBUG_ANY,
2028 "be_modify failed (%d)\n", rs_modify.sr_err, 0, 0 );
2036 slap_graduate_commit_csn( op );
2039 if ( !BER_BVISNULL( &cnbva[0] ) ) {
2040 ch_free( cnbva[0].bv_val );
2041 BER_BVZERO( &cnbva[0] );
2043 if ( !BER_BVISNULL( &scbva[0] ) ) {
2044 ch_free( scbva[0].bv_val );
2045 BER_BVZERO( &scbva[0] );
2048 if ( mlnext->sml_next ) {
2049 slap_mods_free( mlnext->sml_next );
2050 mlnext->sml_next = NULL;
2053 for (ml = modlist ; ml != NULL; ml = mlnext ) {
2054 mlnext = ml->sml_next;
2066 dninfo *dni = op->o_callback->sc_private;
2068 if ( rs->sr_type == REP_SEARCH ) {
2069 if ( !BER_BVISNULL( &dni->dn ) ) {
2070 Debug( LDAP_DEBUG_ANY,
2071 "dn_callback : consistency error - "
2072 "entryUUID is not unique\n", 0, 0, 0 );
2074 ber_dupbv_x( &dni->dn, &rs->sr_entry->e_name, op->o_tmpmemctx );
2075 ber_dupbv_x( &dni->ndn, &rs->sr_entry->e_nname, op->o_tmpmemctx );
2076 /* If there is a new entry, see if it differs from the old.
2077 * We compare the non-normalized values so that cosmetic changes
2078 * in the provider are always propagated.
2080 if ( dni->new_entry ) {
2081 Attribute *old, *new;
2084 /* Did the DN change? Note that we don't explicitly try to
2085 * discover if the deleteOldRdn argument applies here. It
2086 * would save an unnecessary Modify if we detected it, but
2087 * that's a fair amount of trouble to compare the two attr
2090 if ( !dn_match( &rs->sr_entry->e_name,
2091 &dni->new_entry->e_name ) )
2096 for ( i = 0, old = rs->sr_entry->e_attrs;
2098 i++, old = old->a_next )
2103 /* We assume that attributes are saved in the same order
2104 * in the remote and local databases. So if we walk through
2105 * the attributeDescriptions one by one they should match in
2106 * lock step. If not, we signal a change. Otherwise we test
2109 for ( old = rs->sr_entry->e_attrs, new = dni->new_entry->e_attrs;
2111 old = old->a_next, new = new->a_next )
2113 if ( old->a_desc != new->a_desc ) {
2114 dni->wasChanged = 1;
2117 for ( i = 0; ; i++ ) {
2119 nold = BER_BVISNULL( &old->a_vals[i] );
2120 nnew = BER_BVISNULL( &new->a_vals[i] );
2121 /* If both are empty, stop looking */
2122 if ( nold && nnew ) {
2125 /* If they are different, stop looking */
2126 if ( nold != nnew ) {
2127 dni->wasChanged = 1;
2130 if ( ber_bvcmp( &old->a_vals[i], &new->a_vals[i] )) {
2131 dni->wasChanged = 1;
2135 if ( dni->wasChanged ) break;
2137 if ( dni->wasChanged ) {
2138 dni->ads = op->o_tmpalloc( dni->attrs *
2139 sizeof(AttributeDescription *), op->o_tmpmemctx );
2141 for ( old = rs->sr_entry->e_attrs; old; old = old->a_next ) {
2142 dni->ads[i] = old->a_desc;
2148 } else if ( rs->sr_type == REP_RESULT ) {
2149 if ( rs->sr_err == LDAP_SIZELIMIT_EXCEEDED ) {
2150 Debug( LDAP_DEBUG_ANY,
2151 "dn_callback : consistency error - "
2152 "entryUUID is not unique\n", 0, 0, 0 );
2156 return LDAP_SUCCESS;
2160 nonpresent_callback(
2164 syncinfo_t *si = op->o_callback->sc_private;
2167 struct berval* present_uuid = NULL;
2168 struct nonpresent_entry *np_entry;
2170 if ( rs->sr_type == REP_RESULT ) {
2171 count = avl_free( si->si_presentlist, avl_ber_bvfree );
2172 si->si_presentlist = NULL;
2174 } else if ( rs->sr_type == REP_SEARCH ) {
2175 if ( !(si->si_refreshDelete & NP_DELETE_ONE )) {
2176 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID );
2178 if ( a == NULL ) return 0;
2180 present_uuid = avl_find( si->si_presentlist, &a->a_nvals[0],
2184 if ( present_uuid == NULL ) {
2185 np_entry = (struct nonpresent_entry *)
2186 ch_calloc( 1, sizeof( struct nonpresent_entry ));
2187 np_entry->npe_name = ber_dupbv( NULL, &rs->sr_entry->e_name );
2188 np_entry->npe_nname = ber_dupbv( NULL, &rs->sr_entry->e_nname );
2189 LDAP_LIST_INSERT_HEAD( &si->si_nonpresentlist, np_entry, npe_link );
2192 avl_delete( &si->si_presentlist,
2193 &a->a_nvals[0], syncuuid_cmp );
2194 ch_free( present_uuid->bv_val );
2195 ch_free( present_uuid );
2198 return LDAP_SUCCESS;
2206 if ( rs->sr_err != LDAP_SUCCESS &&
2207 rs->sr_err != LDAP_REFERRAL &&
2208 rs->sr_err != LDAP_ALREADY_EXISTS &&
2209 rs->sr_err != LDAP_NO_SUCH_OBJECT &&
2210 rs->sr_err != LDAP_NOT_ALLOWED_ON_NONLEAF )
2212 Debug( LDAP_DEBUG_ANY,
2213 "null_callback : error code 0x%x\n",
2216 return LDAP_SUCCESS;
2220 slap_create_syncrepl_entry(
2222 struct berval *context_csn,
2230 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
2232 attr_merge( e, slap_schema.si_ad_objectClass, ocbva, NULL );
2234 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass,
2237 attr_merge_one( e, slap_schema.si_ad_cn, cn, NULL );
2239 if ( context_csn ) {
2240 attr_merge_one( e, slap_schema.si_ad_syncreplCookie,
2241 context_csn, NULL );
2244 BER_BVSTR( &bv, "{}" );
2245 attr_merge_one( e, slap_schema.si_ad_subtreeSpecification, &bv, NULL );
2247 build_new_dn( &e->e_name, &be->be_nsuffix[0], rdn, NULL );
2248 ber_dupbv( &e->e_nname, &e->e_name );
2254 slap_uuidstr_from_normalized(
2255 struct berval* uuidstr,
2256 struct berval* normalized,
2260 unsigned char nibble;
2263 if ( normalized == NULL ) return NULL;
2264 if ( normalized->bv_len != 16 ) return NULL;
2269 new = (struct berval *)slap_sl_malloc( sizeof(struct berval), ctx );
2270 if ( new == NULL ) {
2277 if ( ( new->bv_val = slap_sl_malloc( new->bv_len + 1, ctx ) ) == NULL ) {
2278 if ( new != uuidstr ) {
2279 slap_sl_free( new, ctx );
2284 for ( i = 0; i < 16; i++ ) {
2285 if ( i == 4 || i == 6 || i == 8 || i == 10 ) {
2286 new->bv_val[(i<<1)+d] = '-';
2290 nibble = (normalized->bv_val[i] >> 4) & 0xF;
2291 if ( nibble < 10 ) {
2292 new->bv_val[(i<<1)+d] = nibble + '0';
2294 new->bv_val[(i<<1)+d] = nibble - 10 + 'a';
2297 nibble = (normalized->bv_val[i]) & 0xF;
2298 if ( nibble < 10 ) {
2299 new->bv_val[(i<<1)+d+1] = nibble + '0';
2301 new->bv_val[(i<<1)+d+1] = nibble - 10 + 'a';
2305 new->bv_val[new->bv_len] = '\0';
2310 syncuuid_cmp( const void* v_uuid1, const void* v_uuid2 )
2312 const struct berval *uuid1 = v_uuid1;
2313 const struct berval *uuid2 = v_uuid2;
2314 int rc = uuid1->bv_len - uuid2->bv_len;
2315 if ( rc ) return rc;
2316 return ( memcmp( uuid1->bv_val, uuid2->bv_val, uuid1->bv_len ) );
2320 avl_ber_bvfree( void *v_bv )
2322 struct berval *bv = (struct berval *)v_bv;
2324 if( v_bv == NULL ) return;
2325 if ( !BER_BVISNULL( bv ) ) {
2326 ch_free( bv->bv_val );
2328 ch_free( (char *) bv );
2332 syncinfo_free( syncinfo_t *sie )
2334 if ( sie->si_provideruri ) {
2335 ch_free( sie->si_provideruri );
2337 if ( sie->si_provideruri_bv ) {
2338 ber_bvarray_free( sie->si_provideruri_bv );
2340 if ( sie->si_binddn ) {
2341 ch_free( sie->si_binddn );
2343 if ( sie->si_passwd ) {
2344 ch_free( sie->si_passwd );
2346 if ( sie->si_saslmech ) {
2347 ch_free( sie->si_saslmech );
2349 if ( sie->si_secprops ) {
2350 ch_free( sie->si_secprops );
2352 if ( sie->si_realm ) {
2353 ch_free( sie->si_realm );
2355 if ( sie->si_authcId ) {
2356 ch_free( sie->si_authcId );
2358 if ( sie->si_authzId ) {
2359 ch_free( sie->si_authzId );
2361 if ( sie->si_filterstr.bv_val ) {
2362 ch_free( sie->si_filterstr.bv_val );
2364 if ( sie->si_base.bv_val ) {
2365 ch_free( sie->si_base.bv_val );
2367 if ( sie->si_attrs ) {
2369 while ( sie->si_attrs[i] != NULL ) {
2370 ch_free( sie->si_attrs[i] );
2373 ch_free( sie->si_attrs );
2375 if ( sie->si_exattrs ) {
2377 while ( sie->si_exattrs[i] != NULL ) {
2378 ch_free( sie->si_exattrs[i] );
2381 ch_free( sie->si_exattrs );
2383 if ( sie->si_anlist ) {
2385 while ( sie->si_anlist[i].an_name.bv_val != NULL ) {
2386 ch_free( sie->si_anlist[i].an_name.bv_val );
2389 ch_free( sie->si_anlist );
2391 if ( sie->si_exanlist ) {
2393 while ( sie->si_exanlist[i].an_name.bv_val != NULL ) {
2394 ch_free( sie->si_exanlist[i].an_name.bv_val );
2397 ch_free( sie->si_exanlist );
2399 if ( sie->si_retryinterval ) {
2400 ch_free( sie->si_retryinterval );
2402 if ( sie->si_retrynum ) {
2403 ch_free( sie->si_retrynum );
2405 if ( sie->si_retrynum_init ) {
2406 ch_free( sie->si_retrynum_init );
2408 slap_sync_cookie_free( &sie->si_syncCookie, 0 );
2409 if ( sie->si_presentlist ) {
2410 avl_free( sie->si_presentlist, avl_ber_bvfree );
2413 ldap_ld_free( sie->si_ld, 1, NULL, NULL );
2415 while ( !LDAP_LIST_EMPTY( &sie->si_nonpresentlist )) {
2416 struct nonpresent_entry* npe;
2417 npe = LDAP_LIST_FIRST( &sie->si_nonpresentlist );
2418 LDAP_LIST_REMOVE( npe, npe_link );
2419 if ( npe->npe_name ) {
2420 if ( npe->npe_name->bv_val ) {
2421 ch_free( npe->npe_name->bv_val );
2423 ch_free( npe->npe_name );
2425 if ( npe->npe_nname ) {
2426 if ( npe->npe_nname->bv_val ) {
2427 ch_free( npe->npe_nname->bv_val );
2429 ch_free( npe->npe_nname );