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"
34 /* FIXME: for ldap_ld_free() */
36 #include "../../libraries/libldap/ldap-int.h"
38 struct nonpresent_entry {
39 struct berval *npe_name;
40 struct berval *npe_nname;
41 LDAP_LIST_ENTRY(nonpresent_entry) npe_link;
44 #define SYNCDATA_DEFAULT 0 /* entries are plain LDAP entries */
45 #define SYNCDATA_ACCESSLOG 1 /* entries are accesslog format */
46 #define SYNCDATA_CHANGELOG 2 /* entries are changelog format */
48 typedef struct syncinfo_s {
49 struct slap_backend_db *si_be;
52 struct berval si_provideruri;
53 slap_bindconf si_bindconf;
54 struct berval si_filterstr;
55 struct berval si_base;
59 AttributeName *si_anlist;
60 AttributeName *si_exanlist;
65 int si_schemachecking;
68 time_t *si_retryinterval;
69 int *si_retrynum_init;
71 struct sync_cookie si_syncCookie;
76 int si_refreshPresent;
78 Avlnode *si_presentlist;
80 LDAP_LIST_HEAD(np, nonpresent_entry) si_nonpresentlist;
81 ldap_pvt_thread_mutex_t si_mutex;
84 static int syncuuid_cmp( const void *, const void * );
85 static void avl_ber_bvfree( void * );
86 static void syncrepl_del_nonpresent( Operation *, syncinfo_t *, BerVarray );
87 static int syncrepl_message_to_op(
88 syncinfo_t *, Operation *, LDAPMessage * );
89 static int syncrepl_message_to_entry(
90 syncinfo_t *, Operation *, LDAPMessage *,
91 Modifications **, Entry **, int );
92 static int syncrepl_entry(
93 syncinfo_t *, Operation*, Entry*,
94 Modifications**,int, struct berval*,
97 static void syncrepl_updateCookie(
98 syncinfo_t *, Operation *, struct berval *,
99 struct sync_cookie * );
100 static struct berval * slap_uuidstr_from_normalized(
101 struct berval *, struct berval *, void * );
103 /* callback functions */
104 static int dn_callback( struct slap_op *, struct slap_rep * );
105 static int nonpresent_callback( struct slap_op *, struct slap_rep * );
106 static int null_callback( struct slap_op *, struct slap_rep * );
108 static AttributeDescription *sync_descs[4];
111 init_syncrepl(syncinfo_t *si)
114 char **attrs, **exattrs;
116 if ( !sync_descs[0] ) {
117 sync_descs[0] = slap_schema.si_ad_objectClass;
118 sync_descs[1] = slap_schema.si_ad_structuralObjectClass;
119 sync_descs[2] = slap_schema.si_ad_entryCSN;
120 sync_descs[3] = NULL;
123 if ( si->si_allattrs && si->si_allopattrs )
126 attrs = anlist2attrs( si->si_anlist );
129 if ( si->si_allattrs ) {
132 if ( !is_at_operational( at_find( attrs[i] ))) {
133 for ( j = i; attrs[j] != NULL; j++ ) {
136 attrs[j] = attrs[j+1];
142 attrs = ( char ** ) ch_realloc( attrs, (i + 2)*sizeof( char * ) );
143 attrs[i] = ch_strdup("*");
146 } else if ( si->si_allopattrs ) {
149 if ( is_at_operational( at_find( attrs[i] ))) {
150 for ( j = i; attrs[j] != NULL; j++ ) {
153 attrs[j] = attrs[j+1];
159 attrs = ( char ** ) ch_realloc( attrs, (i + 2)*sizeof( char * ) );
160 attrs[i] = ch_strdup("+");
164 for ( i = 0; sync_descs[i] != NULL; i++ ) {
167 if ( !strcmp( attrs[j], sync_descs[i]->ad_cname.bv_val )) {
168 for ( k = j; attrs[k] != NULL; k++ ) {
171 attrs[k] = attrs[k+1];
179 for ( n = 0; attrs[ n ] != NULL; n++ ) /* empty */;
181 if ( si->si_allopattrs ) {
182 attrs = ( char ** ) ch_realloc( attrs, (n + 2)*sizeof( char * ));
184 attrs = ( char ** ) ch_realloc( attrs, (n + 4)*sizeof( char * ));
187 if ( attrs == NULL ) {
188 Debug( LDAP_DEBUG_ANY, "out of memory\n", 0,0,0 );
192 if ( si->si_allopattrs ) {
193 attrs[n++] = ch_strdup( sync_descs[0]->ad_cname.bv_val );
195 for ( i = 0; sync_descs[ i ] != NULL; i++ ) {
196 attrs[ n++ ] = ch_strdup ( sync_descs[i]->ad_cname.bv_val );
204 if ( si->si_allattrs == si->si_allopattrs ) {
205 attrs = (char**) ch_malloc( 3 * sizeof(char*) );
206 attrs[i++] = ch_strdup( "*" );
207 attrs[i++] = ch_strdup( "+" );
208 } else if ( si->si_allattrs && !si->si_allopattrs ) {
209 for ( n = 0; sync_descs[ n ] != NULL; n++ ) ;
210 attrs = (char**) ch_malloc( (n+1)* sizeof(char*) );
211 attrs[i++] = ch_strdup( "*" );
212 for ( j = 1; sync_descs[ j ] != NULL; j++ ) {
213 attrs[i++] = ch_strdup ( sync_descs[j]->ad_cname.bv_val );
215 } else if ( !si->si_allattrs && si->si_allopattrs ) {
216 attrs = (char**) ch_malloc( 3 * sizeof(char*) );
217 attrs[i++] = ch_strdup( "+" );
218 attrs[i++] = ch_strdup( sync_descs[0]->ad_cname.bv_val );
223 si->si_attrs = attrs;
225 exattrs = anlist2attrs( si->si_exanlist );
228 for ( n = 0; exattrs[n] != NULL; n++ ) ;
230 for ( i = 0; sync_descs[i] != NULL; i++ ) {
232 while ( exattrs[j] != NULL ) {
233 if ( !strcmp( exattrs[j], sync_descs[i]->ad_cname.bv_val )) {
234 for ( k = j; exattrs[k] != NULL; k++ ) {
236 ch_free( exattrs[k] );
237 exattrs[k] = exattrs[k+1];
245 for ( i = 0; exattrs[i] != NULL; i++ ) {
246 for ( j = 0; si->si_anlist[j].an_name.bv_val; j++ ) {
248 if ( ( oc = si->si_anlist[j].an_oc ) ) {
250 while ( oc->soc_required[k] ) {
251 if ( !strcmp( exattrs[i],
252 oc->soc_required[k]->sat_cname.bv_val )) {
253 for ( l = i; exattrs[l]; l++ ) {
255 ch_free( exattrs[i] );
256 exattrs[l] = exattrs[l+1];
266 for ( i = 0; exattrs[i] != NULL; i++ ) ;
269 exattrs = (char **) ch_realloc( exattrs, (i + 1)*sizeof(char *));
272 si->si_exattrs = exattrs;
280 BerElementBuffer berbuf;
281 BerElement *ber = (BerElement *)&berbuf;
282 LDAPControl c[2], *ctrls[3];
283 struct timeval timeout;
287 /* setup LDAP SYNC control */
288 ber_init2( ber, NULL, LBER_USE_DER );
289 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &ctx );
291 if ( !BER_BVISNULL( &si->si_syncCookie.octet_str ) )
293 ber_printf( ber, "{eO}",
295 &si->si_syncCookie.octet_str );
297 ber_printf( ber, "{e}",
301 if ( (rc = ber_flatten2( ber, &c[0].ldctl_value, 0 )) == LBER_ERROR ) {
306 c[0].ldctl_oid = LDAP_CONTROL_SYNC;
307 c[0].ldctl_iscritical = si->si_type < 0;
310 if ( !BER_BVISNULL( &si->si_bindconf.sb_authzId ) ) {
311 c[1].ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
312 c[1].ldctl_value = si->si_bindconf.sb_authzId;
313 c[1].ldctl_iscritical = 1;
320 timeout.tv_sec = si->si_tlimit;
323 rc = ldap_search_ext( si->si_ld, si->si_base.bv_val, si->si_scope,
324 si->si_filterstr.bv_val, si->si_attrs, si->si_attrsonly,
325 ctrls, NULL, si->si_tlimit > 0 ? &timeout : NULL,
326 si->si_slimit, &msgid );
337 int cmdline_cookie_found = 0;
339 struct sync_cookie *sc = NULL;
345 psub = &si->si_be->be_nsuffix[0];
347 /* Init connection to master */
348 rc = ldap_initialize( &si->si_ld, si->si_provideruri.bv_val );
349 if ( rc != LDAP_SUCCESS ) {
350 Debug( LDAP_DEBUG_ANY,
351 "do_syncrep1: ldap_initialize failed (%s)\n",
352 si->si_provideruri.bv_val, 0, 0 );
356 op->o_protocol = LDAP_VERSION3;
357 ldap_set_option( si->si_ld, LDAP_OPT_PROTOCOL_VERSION, &op->o_protocol );
361 if ( si->si_bindconf.sb_tls ) {
362 rc = ldap_start_tls_s( si->si_ld, NULL, NULL );
363 if( rc != LDAP_SUCCESS ) {
364 Debug( LDAP_DEBUG_ANY,
365 "%s: ldap_start_tls failed (%d)\n",
366 si->si_bindconf.sb_tls == SB_TLS_CRITICAL ? "Error" : "Warning",
368 if( si->si_bindconf.sb_tls == SB_TLS_CRITICAL ) goto done;
372 if ( si->si_bindconf.sb_method == LDAP_AUTH_SASL ) {
373 #ifdef HAVE_CYRUS_SASL
376 if ( si->si_bindconf.sb_secprops != NULL ) {
377 rc = ldap_set_option( si->si_ld,
378 LDAP_OPT_X_SASL_SECPROPS, si->si_bindconf.sb_secprops);
380 if( rc != LDAP_OPT_SUCCESS ) {
381 Debug( LDAP_DEBUG_ANY, "Error: ldap_set_option "
382 "(%s,SECPROPS,\"%s\") failed!\n",
383 si->si_provideruri.bv_val, si->si_bindconf.sb_secprops, 0 );
388 defaults = lutil_sasl_defaults( si->si_ld,
389 si->si_bindconf.sb_saslmech.bv_val,
390 si->si_bindconf.sb_realm.bv_val,
391 si->si_bindconf.sb_authcId.bv_val,
392 si->si_bindconf.sb_cred.bv_val,
393 si->si_bindconf.sb_authzId.bv_val );
395 rc = ldap_sasl_interactive_bind_s( si->si_ld,
396 si->si_bindconf.sb_binddn.bv_val,
397 si->si_bindconf.sb_saslmech.bv_val,
403 lutil_sasl_freedefs( defaults );
405 /* FIXME: different error behaviors according to
407 * 2) on err policy : exit, retry, backoff ...
409 if ( rc != LDAP_SUCCESS ) {
410 static struct berval bv_GSSAPI = BER_BVC( "GSSAPI" );
412 Debug( LDAP_DEBUG_ANY, "do_syncrep1: "
413 "ldap_sasl_interactive_bind_s failed (%d)\n",
416 /* FIXME (see above comment) */
417 /* if Kerberos credentials cache is not active, retry */
418 if ( ber_bvcmp( &si->si_bindconf.sb_saslmech, &bv_GSSAPI ) == 0 &&
419 rc == LDAP_LOCAL_ERROR )
421 rc = LDAP_SERVER_DOWN;
426 #else /* HAVE_CYRUS_SASL */
427 /* Should never get here, we trapped this at config time */
429 fprintf( stderr, "not compiled with SASL support\n" );
434 } else if ( si->si_bindconf.sb_method == LDAP_AUTH_SIMPLE ) {
435 rc = ldap_sasl_bind_s( si->si_ld,
436 si->si_bindconf.sb_binddn.bv_val, LDAP_SASL_SIMPLE,
437 &si->si_bindconf.sb_cred, NULL, NULL, NULL );
438 if ( rc != LDAP_SUCCESS ) {
439 Debug( LDAP_DEBUG_ANY, "do_syncrep1: "
440 "ldap_sasl_bind_s failed (%d)\n", rc, 0, 0 );
445 /* Set SSF to strongest of TLS, SASL SSFs */
448 op->o_transport_ssf = 0;
450 if ( ldap_get_option( si->si_ld, LDAP_OPT_X_TLS_SSL_CTX, &ssl )
451 == LDAP_SUCCESS && ssl != NULL )
453 op->o_tls_ssf = ldap_pvt_tls_get_strength( ssl );
455 #endif /* HAVE_TLS */
456 ldap_get_option( si->si_ld, LDAP_OPT_X_SASL_SSF, &op->o_sasl_ssf );
457 op->o_ssf = ( op->o_sasl_ssf > op->o_tls_ssf )
458 ? op->o_sasl_ssf : op->o_tls_ssf;
461 if ( BER_BVISNULL( &si->si_syncCookie.octet_str )) {
462 /* get contextCSN shadow replica from database */
463 BerVarray csn = NULL;
465 assert( si->si_rid < 1000 );
466 op->o_req_ndn = op->o_bd->be_nsuffix[0];
467 op->o_req_dn = op->o_req_ndn;
469 /* try to read stored contextCSN */
470 backend_attribute( op, NULL, &op->o_req_ndn,
471 slap_schema.si_ad_contextCSN, &csn, ACL_READ );
473 ch_free( si->si_syncCookie.ctxcsn.bv_val );
474 ber_dupbv( &si->si_syncCookie.ctxcsn, csn );
475 ber_bvarray_free_x( csn, op->o_tmpmemctx );
478 si->si_syncCookie.rid = si->si_rid;
480 LDAP_STAILQ_FOREACH( sc, &slap_sync_cookie, sc_next ) {
481 if ( si->si_rid == sc->rid ) {
482 cmdline_cookie_found = 1;
487 if ( cmdline_cookie_found ) {
488 /* cookie is supplied in the command line */
490 LDAP_STAILQ_REMOVE( &slap_sync_cookie, sc, sync_cookie, sc_next );
492 /* ctxcsn wasn't parsed yet, do it now */
493 slap_parse_sync_cookie( sc, op->o_tmpmemctx );
494 if ( BER_BVISNULL( &sc->ctxcsn ) ) {
495 /* if cmdline cookie does not have ctxcsn */
496 /* component, set it to an initial value */
497 slap_init_sync_cookie_ctxcsn( sc );
499 slap_sync_cookie_free( &si->si_syncCookie, 0 );
500 slap_dup_sync_cookie( &si->si_syncCookie, sc );
501 slap_sync_cookie_free( sc, 1 );
504 slap_compose_sync_cookie( NULL, &si->si_syncCookie.octet_str,
505 &si->si_syncCookie.ctxcsn, si->si_syncCookie.rid );
508 rc = ldap_sync_search( si, op->o_tmpmemctx );
510 if( rc != LDAP_SUCCESS ) {
511 Debug( LDAP_DEBUG_ANY, "do_syncrep1: "
512 "ldap_search_ext: %s (%d)\n", ldap_err2string( rc ), rc, 0 );
518 ldap_unbind_ext( si->si_ld, NULL, NULL );
531 LDAPControl **rctrls = NULL;
534 BerElementBuffer berbuf;
535 BerElement *ber = (BerElement *)&berbuf;
537 LDAPMessage *res = NULL;
538 LDAPMessage *msg = NULL;
541 struct berval *retdata = NULL;
546 struct berval syncUUID = BER_BVNULL;
547 struct sync_cookie syncCookie = { BER_BVNULL };
548 struct sync_cookie syncCookie_req = { BER_BVNULL };
549 struct berval cookie = BER_BVNULL;
557 Modifications *modlist = NULL;
562 struct timeval *tout_p = NULL;
563 struct timeval tout = { 0, 0 };
565 int refreshDeletes = 0;
567 BerVarray syncUUIDs = NULL;
570 if ( slapd_shutdown ) {
575 ber_init2( ber, NULL, LBER_USE_DER );
576 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
578 Debug( LDAP_DEBUG_TRACE, "=>do_syncrep2\n", 0, 0, 0 );
580 psub = &si->si_be->be_nsuffix[0];
582 slap_dup_sync_cookie( &syncCookie_req, &si->si_syncCookie );
584 if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST ) {
590 while (( rc = ldap_result( si->si_ld, LDAP_RES_ANY, LDAP_MSG_ONE,
591 tout_p, &res )) > 0 )
593 if ( slapd_shutdown ) {
597 for( msg = ldap_first_message( si->si_ld, res );
599 msg = ldap_next_message( si->si_ld, msg ) )
601 if ( slapd_shutdown ) {
605 switch( ldap_msgtype( msg ) ) {
606 case LDAP_RES_SEARCH_ENTRY:
607 ldap_get_entry_controls( si->si_ld, msg, &rctrls );
608 /* we can't work without the control */
610 Debug( LDAP_DEBUG_ANY, "do_syncrep2: "
611 "got search entry without "
612 "control\n", 0, 0, 0 );
617 ber_init2( ber, &rctrlp->ldctl_value, LBER_USE_DER );
618 ber_scanf( ber, "{em" /*"}"*/, &syncstate, &syncUUID );
619 /* FIXME: what if syncUUID is NULL or empty? */
620 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
621 ber_scanf( ber, /*"{"*/ "m}", &cookie );
622 if ( !BER_BVISNULL( &cookie ) ) {
623 ch_free( syncCookie.octet_str.bv_val );
624 ber_dupbv( &syncCookie.octet_str, &cookie );
626 if ( !BER_BVISNULL( &syncCookie.octet_str ) )
628 slap_parse_sync_cookie( &syncCookie, NULL );
631 if ( si->si_syncdata ) {
634 if ( syncrepl_message_to_op( si, op, msg ) == LDAP_SUCCESS &&
635 !BER_BVISNULL( &syncCookie.octet_str ) ) {
636 syncrepl_updateCookie( si, op, psub, &syncCookie );
638 } else if ( syncrepl_message_to_entry( si, op, msg,
639 &modlist, &entry, syncstate ) == LDAP_SUCCESS ) {
640 rc_efree = syncrepl_entry( si, op, entry, &modlist,
641 syncstate, &syncUUID, &syncCookie_req, &syncCookie.ctxcsn );
642 if ( !BER_BVISNULL( &syncCookie.octet_str ) )
644 syncrepl_updateCookie( si, op, psub, &syncCookie );
647 ldap_controls_free( rctrls );
649 slap_mods_free( modlist, 1 );
651 if ( rc_efree && entry ) {
657 case LDAP_RES_SEARCH_REFERENCE:
658 Debug( LDAP_DEBUG_ANY,
659 "do_syncrep2: reference received error\n", 0, 0, 0 );
662 case LDAP_RES_SEARCH_RESULT:
663 Debug( LDAP_DEBUG_SYNC,
664 "do_syncrep2: LDAP_RES_SEARCH_RESULT\n", 0, 0, 0 );
665 ldap_parse_result( si->si_ld, msg, &err, NULL, NULL, NULL,
669 ber_init2( ber, &rctrlp->ldctl_value, LBER_USE_DER );
671 ber_scanf( ber, "{" /*"}"*/);
672 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
673 ber_scanf( ber, "m", &cookie );
674 if ( !BER_BVISNULL( &cookie ) ) {
675 ch_free( syncCookie.octet_str.bv_val );
676 ber_dupbv( &syncCookie.octet_str, &cookie);
678 if ( !BER_BVISNULL( &syncCookie.octet_str ) )
680 slap_parse_sync_cookie( &syncCookie, NULL );
683 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_REFRESHDELETES )
685 ber_scanf( ber, "b", &refreshDeletes );
687 ber_scanf( ber, /*"{"*/ "}" );
689 if ( BER_BVISNULL( &syncCookie_req.ctxcsn )) {
691 } else if ( BER_BVISNULL( &syncCookie.ctxcsn )) {
694 value_match( &match, slap_schema.si_ad_entryCSN,
695 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
696 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
697 &syncCookie_req.ctxcsn, &syncCookie.ctxcsn,
700 if ( !BER_BVISNULL( &syncCookie.octet_str ) &&
701 match < 0 && err == LDAP_SUCCESS )
703 syncrepl_updateCookie( si, op, psub, &syncCookie );
706 ldap_controls_free( rctrls );
708 if (si->si_type != LDAP_SYNC_REFRESH_AND_PERSIST) {
709 /* FIXME : different error behaviors according to
710 * 1) err code : LDAP_BUSY ...
711 * 2) on err policy : stop service, stop sync, retry
713 if ( refreshDeletes == 0 && match < 0 &&
714 err == LDAP_SUCCESS )
716 syncrepl_del_nonpresent( op, si, NULL );
718 avl_free( si->si_presentlist, avl_ber_bvfree );
719 si->si_presentlist = NULL;
726 case LDAP_RES_INTERMEDIATE:
727 rc = ldap_parse_intermediate( si->si_ld, msg,
728 &retoid, &retdata, NULL, 0 );
729 if ( !rc && !strcmp( retoid, LDAP_SYNC_INFO ) ) {
730 ber_init2( ber, retdata, LBER_USE_DER );
732 switch ( si_tag = ber_peek_tag( ber, &len )) {
734 case LDAP_TAG_SYNC_NEW_COOKIE:
735 Debug( LDAP_DEBUG_SYNC,
736 "do_syncrep2: %s - %s%s\n",
737 "LDAP_RES_INTERMEDIATE",
738 "NEW_COOKIE", "\n" );
739 ber_scanf( ber, "tm", &tag, &cookie );
741 case LDAP_TAG_SYNC_REFRESH_DELETE:
742 case LDAP_TAG_SYNC_REFRESH_PRESENT:
743 Debug( LDAP_DEBUG_SYNC,
744 "do_syncrep2: %s - %s%s\n",
745 "LDAP_RES_INTERMEDIATE",
746 si_tag == LDAP_TAG_SYNC_REFRESH_PRESENT ?
747 "REFRESH_PRESENT" : "REFRESH_DELETE",
749 if ( si_tag == LDAP_TAG_SYNC_REFRESH_DELETE ) {
750 si->si_refreshDelete = 1;
752 si->si_refreshPresent = 1;
754 ber_scanf( ber, "t{" /*"}"*/, &tag );
755 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE )
757 ber_scanf( ber, "m", &cookie );
758 if ( !BER_BVISNULL( &cookie ) ) {
759 ch_free( syncCookie.octet_str.bv_val );
760 ber_dupbv( &syncCookie.octet_str, &cookie );
762 if ( !BER_BVISNULL( &syncCookie.octet_str ) )
764 slap_parse_sync_cookie( &syncCookie, NULL );
767 if ( ber_peek_tag( ber, &len ) ==
768 LDAP_TAG_REFRESHDONE )
770 ber_scanf( ber, "b", &refreshDone );
772 ber_scanf( ber, /*"{"*/ "}" );
774 case LDAP_TAG_SYNC_ID_SET:
775 Debug( LDAP_DEBUG_SYNC,
776 "do_syncrep2: %s - %s%s\n",
777 "LDAP_RES_INTERMEDIATE",
780 ber_scanf( ber, "t{" /*"}"*/, &tag );
781 if ( ber_peek_tag( ber, &len ) ==
782 LDAP_TAG_SYNC_COOKIE )
784 ber_scanf( ber, "m", &cookie );
785 if ( !BER_BVISNULL( &cookie ) ) {
786 ch_free( syncCookie.octet_str.bv_val );
787 ber_dupbv( &syncCookie.octet_str, &cookie );
789 if ( !BER_BVISNULL( &syncCookie.octet_str ) )
791 slap_parse_sync_cookie( &syncCookie, NULL );
794 if ( ber_peek_tag( ber, &len ) ==
795 LDAP_TAG_REFRESHDELETES )
797 ber_scanf( ber, "b", &refreshDeletes );
799 ber_scanf( ber, "[W]", &syncUUIDs );
800 ber_scanf( ber, /*"{"*/ "}" );
801 if ( refreshDeletes ) {
802 syncrepl_del_nonpresent( op, si, syncUUIDs );
803 ber_bvarray_free_x( syncUUIDs, op->o_tmpmemctx );
805 for ( i = 0; !BER_BVISNULL( &syncUUIDs[i] ); i++ ) {
806 struct berval *syncuuid_bv;
807 syncuuid_bv = ber_dupbv( NULL, &syncUUIDs[i] );
808 slap_sl_free( syncUUIDs[i].bv_val,op->o_tmpmemctx );
809 avl_insert( &si->si_presentlist,
810 (caddr_t) syncuuid_bv,
811 syncuuid_cmp, avl_dup_error );
813 slap_sl_free( syncUUIDs, op->o_tmpmemctx );
817 Debug( LDAP_DEBUG_ANY,
818 "do_syncrep2 : unknown syncinfo tag (%ld)\n",
819 (long) si_tag, 0, 0 );
820 ldap_memfree( retoid );
821 ber_bvfree( retdata );
825 if ( BER_BVISNULL( &syncCookie_req.ctxcsn )) {
827 } else if ( BER_BVISNULL( &syncCookie.ctxcsn )) {
830 value_match( &match, slap_schema.si_ad_entryCSN,
831 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
832 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
833 &syncCookie_req.ctxcsn,
834 &syncCookie.ctxcsn, &text );
837 if ( !BER_BVISNULL( &syncCookie.ctxcsn ) &&
840 syncrepl_updateCookie( si, op, psub, &syncCookie);
843 if ( si->si_refreshPresent == 1 ) {
845 syncrepl_del_nonpresent( op, si, NULL );
849 ldap_memfree( retoid );
850 ber_bvfree( retdata );
854 Debug( LDAP_DEBUG_ANY, "do_syncrep2 : "
855 "unknown intermediate response (%d)\n",
857 ldap_memfree( retoid );
858 ber_bvfree( retdata );
864 Debug( LDAP_DEBUG_ANY, "do_syncrep2 : "
865 "unknown message\n", 0, 0, 0 );
869 if ( !BER_BVISNULL( &syncCookie.octet_str )) {
870 slap_sync_cookie_free( &syncCookie_req, 0 );
871 slap_dup_sync_cookie( &syncCookie_req, &syncCookie );
872 slap_sync_cookie_free( &syncCookie, 0 );
882 ldap_get_option( si->si_ld, LDAP_OPT_ERROR_NUMBER, &rc );
883 errstr = ldap_err2string( rc );
885 Debug( LDAP_DEBUG_ANY,
886 "do_syncrep2 : %s\n", errstr, 0, 0 );
890 slap_sync_cookie_free( &syncCookie, 0 );
891 slap_sync_cookie_free( &syncCookie_req, 0 );
893 if ( res ) ldap_msgfree( res );
895 if ( rc && si->si_ld ) {
896 ldap_unbind_ext( si->si_ld, NULL, NULL );
908 struct re_s* rtask = arg;
909 syncinfo_t *si = ( syncinfo_t * ) rtask->arg;
910 Connection conn = {0};
911 char opbuf[OPERATION_BUFFER_SIZE];
913 int rc = LDAP_SUCCESS;
920 Debug( LDAP_DEBUG_TRACE, "=>do_syncrepl\n", 0, 0, 0 );
925 ldap_pvt_thread_mutex_lock( &si->si_mutex );
927 switch( abs( si->si_type )) {
928 case LDAP_SYNC_REFRESH_ONLY:
929 case LDAP_SYNC_REFRESH_AND_PERSIST:
932 ldap_pvt_thread_mutex_unlock( &si->si_mutex );
936 if ( slapd_shutdown ) {
938 ldap_get_option( si->si_ld, LDAP_OPT_DESC, &s );
939 connection_client_stop( s );
940 ldap_unbind_ext( si->si_ld, NULL, NULL );
943 ldap_pvt_thread_mutex_unlock( &si->si_mutex );
947 op = (Operation *)opbuf;
948 connection_fake_init( &conn, op, ctx );
950 /* use global malloc for now */
951 op->o_tmpmemctx = NULL;
952 op->o_tmpmfuncs = &ch_mfuncs;
954 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
955 op->o_bd = be = si->si_be;
956 op->o_dn = op->o_bd->be_rootdn;
957 op->o_ndn = op->o_bd->be_rootndn;
959 /* Establish session, do search */
962 si->si_refreshDelete = 0;
963 si->si_refreshPresent = 0;
964 rc = do_syncrep1( op, si );
967 /* Process results */
968 if ( rc == LDAP_SUCCESS ) {
969 ldap_get_option( si->si_ld, LDAP_OPT_DESC, &s );
971 rc = do_syncrep2( op, si );
973 if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST ) {
974 /* If we succeeded, enable the connection for further listening.
975 * If we failed, tear down the connection and reschedule.
977 if ( rc == LDAP_SUCCESS ) {
979 rc = connection_client_setup( s, do_syncrepl, arg );
981 connection_client_enable( s );
983 } else if ( !first ) {
987 if ( rc == -2 ) rc = 0;
991 /* At this point, we have 4 cases:
992 * 1) for any hard failure, give up and remove this task
993 * 2) for ServerDown, reschedule this task to run
994 * 3) for Refresh and Success, reschedule to run
995 * 4) for Persist and Success, reschedule to defer
997 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
999 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, rtask )) {
1000 ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
1004 connection_client_stop( s );
1007 if ( rc == LDAP_SUCCESS ) {
1008 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
1011 rtask->interval.tv_sec = si->si_interval;
1012 ldap_pvt_runqueue_resched( &slapd_rq, rtask, defer );
1013 if ( si->si_retrynum ) {
1014 for ( i = 0; si->si_retrynum_init[i] != -2; i++ ) {
1015 si->si_retrynum[i] = si->si_retrynum_init[i];
1017 si->si_retrynum[i] = -2;
1020 for ( i = 0; si->si_retrynum && si->si_retrynum[i] <= 0; i++ ) {
1021 if ( si->si_retrynum[i] == -1 || si->si_retrynum[i] == -2 )
1025 if ( !si->si_retrynum || si->si_retrynum[i] == -2 ) {
1026 ldap_pvt_runqueue_remove( &slapd_rq, rtask );
1027 } else if ( si->si_retrynum[i] >= -1 ) {
1028 if ( si->si_retrynum[i] > 0 )
1029 si->si_retrynum[i]--;
1030 rtask->interval.tv_sec = si->si_retryinterval[i];
1031 ldap_pvt_runqueue_resched( &slapd_rq, rtask, 0 );
1032 slap_wake_listener();
1036 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
1037 ldap_pvt_thread_mutex_unlock( &si->si_mutex );
1042 typedef struct logschema {
1043 struct berval ls_dn;
1044 struct berval ls_req;
1045 struct berval ls_mod;
1046 struct berval ls_newRdn;
1047 struct berval ls_delRdn;
1048 struct berval ls_newSup;
1051 static logschema changelog_sc = {
1052 BER_BVC("targetDN"),
1053 BER_BVC("changeType"),
1056 BER_BVC("deleteOldRDN"),
1057 BER_BVC("newSuperior")
1060 static logschema accesslog_sc = {
1064 BER_BVC("reqNewRDN"),
1065 BER_BVC("reqDeleteOldRDN"),
1066 BER_BVC("reqNewSuperior")
1069 static slap_verbmasks modops[] = {
1070 { BER_BVC("add"), LDAP_REQ_ADD },
1071 { BER_BVC("delete"), LDAP_REQ_DELETE },
1072 { BER_BVC("modify"), LDAP_REQ_MODIFY },
1073 { BER_BVC("modrdn"), LDAP_REQ_MODRDN},
1077 static Modifications *
1078 syncrepl_accesslog_mods(
1085 AttributeDescription *ad;
1086 struct berval bv, bv2;
1088 Modifications *mod = NULL, *modlist = NULL, **modtail;
1093 for (i=0; !BER_BVISNULL( &vals[i] ); i++) {
1097 colon = strchr( bv.bv_val, ':' );
1099 continue; /* invalid */
1100 bv.bv_len = colon - bv.bv_val;
1101 if ( slap_bv2ad( &bv, &ad, &text )) {
1105 /* Ignore dynamically generated attrs */
1106 if ( ad->ad_type->sat_flags & SLAP_AT_DYNAMIC )
1108 /* Ignore excluded attrs */
1109 if ( ldap_charray_inlist( si->si_exattrs,
1110 ad->ad_type->sat_cname.bv_val ))
1114 case '+': op = LDAP_MOD_ADD; break;
1115 case '-': op = LDAP_MOD_DELETE; break;
1116 case '=': op = LDAP_MOD_REPLACE; break;
1117 case '#': op = LDAP_MOD_INCREMENT; break;
1121 if ( !mod || ad != mod->sml_desc || op != mod->sml_op ) {
1122 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
1125 mod->sml_next = NULL;
1127 mod->sml_type = ad->ad_cname;
1128 mod->sml_values = NULL;
1129 mod->sml_nvalues = NULL;
1132 modtail = &mod->sml_next;
1134 bv.bv_val = colon + 3;
1135 bv.bv_len = vals[i].bv_len - ( bv.bv_val - vals[i].bv_val );
1136 ber_dupbv( &bv2, &bv );
1137 ber_bvarray_add( &mod->sml_values, &bv2 );
1142 static Modifications *
1143 syncrepl_changelog_mods(
1151 syncrepl_message_to_op(
1157 BerElement *ber = NULL;
1158 Modifications *modlist = NULL;
1160 SlapReply rs = { REP_RESULT };
1161 slap_callback cb = { NULL, null_callback, NULL, NULL };
1164 char txtbuf[SLAP_TEXT_BUFLEN];
1165 size_t textlen = sizeof txtbuf;
1167 struct berval bdn, dn = BER_BVNULL, ndn;
1168 struct berval bv, *bvals = NULL;
1169 struct berval rdn = BER_BVNULL, sup = BER_BVNULL,
1170 prdn = BER_BVNULL, nrdn = BER_BVNULL,
1171 psup = BER_BVNULL, nsup = BER_BVNULL;
1172 int rc, deleteOldRdn = 0;
1174 if ( ldap_msgtype( msg ) != LDAP_RES_SEARCH_ENTRY ) {
1175 Debug( LDAP_DEBUG_ANY,
1176 "Message type should be entry (%d)", ldap_msgtype( msg ), 0, 0 );
1180 if ( si->si_syncdata == SYNCDATA_ACCESSLOG )
1185 rc = ldap_get_dn_ber( si->si_ld, msg, &ber, &bdn );
1187 if ( rc != LDAP_SUCCESS ) {
1188 Debug( LDAP_DEBUG_ANY,
1189 "syncrepl_message_to_op : dn get failed (%d)", rc, 0, 0 );
1193 op->o_tag = LBER_DEFAULT;
1195 while (( rc = ldap_get_attribute_ber( si->si_ld, msg, ber, &bv, &bvals ))
1197 if ( bv.bv_val == NULL )
1200 if ( !ber_bvstrcasecmp( &bv, &ls->ls_dn )) {
1202 dnPrettyNormal( NULL, &bdn, &dn, &ndn, op->o_tmpmemctx );
1203 ber_dupbv( &op->o_req_dn, &dn );
1204 ber_dupbv( &op->o_req_ndn, &ndn );
1205 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1206 slap_sl_free( dn.bv_val, op->o_tmpmemctx );
1207 } else if ( !ber_bvstrcasecmp( &bv, &ls->ls_req )) {
1208 int i = verb_to_mask( bvals[0].bv_val, modops );
1210 Debug( LDAP_DEBUG_ANY,
1211 "syncrepl_message_to_op : unknown op %s",
1212 bvals[0].bv_val, 0, 0 );
1216 op->o_tag = modops[i].mask;
1217 } else if ( !ber_bvstrcasecmp( &bv, &ls->ls_mod )) {
1218 /* Parse attribute into modlist */
1219 if ( si->si_syncdata == SYNCDATA_ACCESSLOG )
1220 modlist = syncrepl_accesslog_mods( si, bvals );
1222 modlist = syncrepl_changelog_mods( si, bvals );
1223 } else if ( !ber_bvstrcasecmp( &bv, &ls->ls_newRdn )) {
1225 } else if ( !ber_bvstrcasecmp( &bv, &ls->ls_delRdn )) {
1226 if ( !ber_bvstrcasecmp( &slap_true_bv, bvals ))
1228 } else if ( !ber_bvstrcasecmp( &bv, &ls->ls_newSup )) {
1234 /* If we didn't get a mod type or a target DN, bail out */
1235 if ( op->o_tag == LBER_DEFAULT || BER_BVISNULL( &dn ))
1238 op->o_callback = &cb;
1240 switch( op->o_tag ) {
1242 case LDAP_REQ_MODIFY:
1243 /* If we didn't get required data, bail */
1244 if ( !modlist ) goto done;
1246 rc = slap_mods_check( modlist, &text, txtbuf, textlen, NULL );
1248 if ( rc != LDAP_SUCCESS ) {
1249 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_op: mods check (%s)\n",
1254 if ( op->o_tag == LDAP_REQ_ADD ) {
1255 op->ora_e = ( Entry * ) ch_calloc( 1, sizeof( Entry ) );
1256 op->ora_e->e_name = op->o_req_dn;
1257 op->ora_e->e_nname = op->o_req_ndn;
1258 rc = slap_mods2entry( modlist, &op->ora_e, 1, 0, &text, txtbuf, textlen);
1259 if( rc != LDAP_SUCCESS ) {
1260 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_op: mods2entry (%s)\n",
1263 rc = op->o_bd->be_add( op, &rs );
1265 be_entry_release_w( op, op->ora_e );
1267 op->orm_modlist = modlist;
1268 rc = op->o_bd->be_modify( op, &rs );
1271 case LDAP_REQ_MODRDN:
1272 if ( BER_BVISNULL( &rdn )) goto done;
1274 if ( rdnPretty( NULL, &rdn, &prdn, NULL ))
1276 if ( rdnNormalize( 0, NULL, NULL, &rdn, &nrdn, NULL ))
1278 if ( !BER_BVISNULL( &sup )) {
1279 if ( dnPrettyNormal( NULL, &sup, &psup, &nsup, NULL ))
1281 op->orr_newSup = &psup;
1282 op->orr_nnewSup = ⊅
1284 op->orr_newrdn = prdn;
1285 op->orr_nnewrdn = nrdn;
1286 op->orr_deleteoldrdn = deleteOldRdn;
1287 rc = op->o_bd->be_modrdn( op, &rs );
1292 slap_mods_free( modlist, op->o_tag != LDAP_REQ_ADD );
1293 if ( !BER_BVISNULL( &rdn )) {
1294 if ( !BER_BVISNULL( &nsup ))
1295 ch_free( nsup.bv_val );
1296 if ( !BER_BVISNULL( &psup ))
1297 ch_free( psup.bv_val );
1298 if ( !BER_BVISNULL( &nrdn ))
1299 ch_free( nrdn.bv_val );
1300 if ( !BER_BVISNULL( &prdn ))
1301 ch_free( prdn.bv_val );
1303 ber_free ( ber, 0 );
1307 syncrepl_message_to_entry(
1311 Modifications **modlist,
1317 BerElement *ber = NULL;
1320 Modifications **modtail = modlist;
1323 char txtbuf[SLAP_TEXT_BUFLEN];
1324 size_t textlen = sizeof txtbuf;
1326 struct berval bdn = {0, NULL}, dn, ndn;
1331 if ( ldap_msgtype( msg ) != LDAP_RES_SEARCH_ENTRY ) {
1332 Debug( LDAP_DEBUG_ANY,
1333 "Message type should be entry (%d)", ldap_msgtype( msg ), 0, 0 );
1337 op->o_tag = LDAP_REQ_ADD;
1339 rc = ldap_get_dn_ber( si->si_ld, msg, &ber, &bdn );
1341 if ( rc != LDAP_SUCCESS ) {
1342 Debug( LDAP_DEBUG_ANY,
1343 "syncrepl_message_to_entry : dn get failed (%d)", rc, 0, 0 );
1347 dnPrettyNormal( NULL, &bdn, &dn, &ndn, op->o_tmpmemctx );
1348 ber_dupbv( &op->o_req_dn, &dn );
1349 ber_dupbv( &op->o_req_ndn, &ndn );
1350 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1351 slap_sl_free( dn.bv_val, op->o_tmpmemctx );
1353 if ( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_DELETE ) {
1356 return LDAP_SUCCESS;
1359 if ( entry == NULL ) {
1363 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ) );
1365 e->e_name = op->o_req_dn;
1366 e->e_nname = op->o_req_ndn;
1368 while ( ber_remaining( ber ) ) {
1369 if ( (ber_scanf( ber, "{mW}", &tmp.sml_type, &tmp.sml_values ) ==
1370 LBER_ERROR ) || BER_BVISNULL( &tmp.sml_type ) )
1375 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
1377 mod->sml_op = LDAP_MOD_REPLACE;
1379 mod->sml_next = NULL;
1380 mod->sml_desc = NULL;
1381 mod->sml_type = tmp.sml_type;
1382 mod->sml_values = tmp.sml_values;
1383 mod->sml_nvalues = NULL;
1386 modtail = &mod->sml_next;
1389 if ( *modlist == NULL ) {
1390 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: no attributes\n",
1396 rc = slap_mods_check( *modlist, &text, txtbuf, textlen, NULL );
1398 if ( rc != LDAP_SUCCESS ) {
1399 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods check (%s)\n",
1404 /* Strip out dynamically generated attrs */
1405 for ( modtail = modlist; *modtail ; ) {
1407 if ( mod->sml_desc->ad_type->sat_flags & SLAP_AT_DYNAMIC ) {
1408 *modtail = mod->sml_next;
1409 slap_mod_free( &mod->sml_mod, 0 );
1412 modtail = &mod->sml_next;
1416 /* Strip out attrs in exattrs list */
1417 for ( modtail = modlist; *modtail ; ) {
1419 if ( ldap_charray_inlist( si->si_exattrs,
1420 mod->sml_desc->ad_type->sat_cname.bv_val )) {
1421 *modtail = mod->sml_next;
1422 slap_mod_free( &mod->sml_mod, 0 );
1425 modtail = &mod->sml_next;
1429 rc = slap_mods2entry( *modlist, &e, 1, 1, &text, txtbuf, textlen);
1430 if( rc != LDAP_SUCCESS ) {
1431 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods2entry (%s)\n",
1436 ber_free ( ber, 0 );
1437 if ( rc != LDAP_SUCCESS ) {
1447 static struct berval generic_filterstr = BER_BVC("(objectclass=*)");
1449 /* During a refresh, we may get an LDAP_SYNC_ADD for an already existing
1450 * entry if a previous refresh was interrupted before sending us a new
1451 * context state. We try to compare the new entry to the existing entry
1452 * and ignore the new entry if they are the same.
1454 * Also, we may get an update where the entryDN has changed, due to
1455 * a ModDn on the provider. We detect this as well, so we can issue
1456 * the corresponding operation locally.
1458 * In the case of a modify, we get a list of all the attributes
1459 * in the original entry. Rather than deleting the entry and re-adding it,
1460 * we issue a Modify request that deletes all the attributes and adds all
1461 * the new ones. This avoids the issue of trying to delete/add a non-leaf
1464 * We don't try to otherwise distinguish ModDN from Modify; in the case of
1465 * a ModDN we will issue both operations on the local database.
1467 typedef struct dninfo {
1471 int renamed; /* Was an existing entry renamed? */
1472 int wasChanged; /* are the attributes changed? */
1473 int attrs; /* how many attribute types are in the ads list */
1474 AttributeDescription **ads;
1482 Modifications** modlist,
1484 struct berval* syncUUID,
1485 struct sync_cookie* syncCookie_req,
1486 struct berval* syncCSN )
1488 Backend *be = op->o_bd;
1489 slap_callback cb = { NULL, NULL, NULL, NULL };
1490 struct berval *syncuuid_bv = NULL;
1491 struct berval syncUUID_strrep = BER_BVNULL;
1492 struct berval uuid_bv = BER_BVNULL;
1494 SlapReply rs_search = {REP_RESULT};
1495 SlapReply rs_delete = {REP_RESULT};
1496 SlapReply rs_add = {REP_RESULT};
1497 SlapReply rs_modify = {REP_RESULT};
1499 #ifdef LDAP_COMP_MATCH
1500 AttributeAssertion ava = { NULL, BER_BVNULL, NULL };
1502 AttributeAssertion ava = { NULL, BER_BVNULL };
1504 int rc = LDAP_SUCCESS;
1505 int ret = LDAP_SUCCESS;
1507 struct berval pdn = BER_BVNULL;
1511 switch( syncstate ) {
1512 case LDAP_SYNC_PRESENT:
1513 Debug( LDAP_DEBUG_SYNC, "%s: %s\n",
1515 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_PRESENT)", 0 );
1518 Debug( LDAP_DEBUG_SYNC, "%s: %s\n",
1520 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_ADD)", 0 );
1522 case LDAP_SYNC_DELETE:
1523 Debug( LDAP_DEBUG_SYNC, "%s: %s\n",
1525 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_DELETE)", 0 );
1527 case LDAP_SYNC_MODIFY:
1528 Debug( LDAP_DEBUG_SYNC, "%s: %s\n",
1530 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_MODIFY)", 0 );
1533 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
1535 "LDAP_RES_SEARCH_ENTRY(UNKNOWN syncstate)", 0 );
1538 if (( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD )) {
1539 if ( !si->si_refreshPresent ) {
1540 syncuuid_bv = ber_dupbv( NULL, syncUUID );
1541 avl_insert( &si->si_presentlist, (caddr_t) syncuuid_bv,
1542 syncuuid_cmp, avl_dup_error );
1546 if ( syncstate == LDAP_SYNC_PRESENT ) {
1548 } else if ( syncstate != LDAP_SYNC_DELETE ) {
1549 if ( entry == NULL ) {
1554 f.f_choice = LDAP_FILTER_EQUALITY;
1556 ava.aa_desc = slap_schema.si_ad_entryUUID;
1557 (void)slap_uuidstr_from_normalized( &syncUUID_strrep, syncUUID, op->o_tmpmemctx );
1558 ava.aa_value = *syncUUID;
1559 op->ors_filter = &f;
1561 op->ors_filterstr.bv_len = STRLENOF( "(entryUUID=)" ) + syncUUID->bv_len;
1562 op->ors_filterstr.bv_val = (char *) slap_sl_malloc(
1563 op->ors_filterstr.bv_len + 1, op->o_tmpmemctx );
1564 AC_MEMCPY( op->ors_filterstr.bv_val, "(entryUUID=", STRLENOF( "(entryUUID=" ) );
1565 AC_MEMCPY( &op->ors_filterstr.bv_val[STRLENOF( "(entryUUID=" )],
1566 syncUUID->bv_val, syncUUID->bv_len );
1567 op->ors_filterstr.bv_val[op->ors_filterstr.bv_len - 1] = ')';
1568 op->ors_filterstr.bv_val[op->ors_filterstr.bv_len] = '\0';
1570 op->o_tag = LDAP_REQ_SEARCH;
1571 op->ors_scope = LDAP_SCOPE_SUBTREE;
1572 op->ors_deref = LDAP_DEREF_NEVER;
1574 /* get the entry for this UUID */
1575 op->o_req_dn = si->si_base;
1576 op->o_req_ndn = si->si_base;
1578 op->o_time = slap_get_time();
1579 op->ors_tlimit = SLAP_NO_LIMIT;
1582 op->ors_attrs = slap_anlist_all_attributes;
1583 op->ors_attrsonly = 0;
1585 /* set callback function */
1586 op->o_callback = &cb;
1587 cb.sc_response = dn_callback;
1588 cb.sc_private = &dni;
1589 dni.new_entry = entry;
1591 if ( limits_check( op, &rs_search ) == 0 ) {
1592 rc = be->be_search( op, &rs_search );
1593 Debug( LDAP_DEBUG_SYNC,
1594 "syncrepl_entry: %s (%d)\n",
1595 "be_search", rc, 0 );
1598 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
1599 slap_sl_free( op->ors_filterstr.bv_val, op->o_tmpmemctx );
1602 cb.sc_response = null_callback;
1605 if ( entry && !BER_BVISNULL( &entry->e_name ) ) {
1606 Debug( LDAP_DEBUG_SYNC,
1607 "syncrepl_entry: %s\n",
1608 entry->e_name.bv_val, 0, 0 );
1610 Debug( LDAP_DEBUG_SYNC,
1611 "syncrepl_entry: %s\n",
1612 dni.dn.bv_val ? dni.dn.bv_val : "(null)", 0, 0 );
1615 if ( syncstate != LDAP_SYNC_DELETE ) {
1616 Attribute *a = attr_find( entry->e_attrs, slap_schema.si_ad_entryUUID );
1619 /* add if missing */
1620 attr_merge_one( entry, slap_schema.si_ad_entryUUID,
1621 &syncUUID_strrep, syncUUID );
1623 } else if ( !bvmatch( &a->a_nvals[0], syncUUID ) ) {
1624 /* replace only if necessary */
1625 if ( a->a_nvals != a->a_vals ) {
1626 ber_memfree( a->a_nvals[0].bv_val );
1627 ber_dupbv( &a->a_nvals[0], syncUUID );
1629 ber_memfree( a->a_vals[0].bv_val );
1630 ber_dupbv( &a->a_vals[0], &syncUUID_strrep );
1634 switch ( syncstate ) {
1636 case LDAP_SYNC_MODIFY:
1638 if ( BER_BVISNULL( &dni.dn )) {
1640 op->o_req_dn = entry->e_name;
1641 op->o_req_ndn = entry->e_nname;
1642 op->o_tag = LDAP_REQ_ADD;
1645 rc = be->be_add( op, &rs_add );
1646 Debug( LDAP_DEBUG_SYNC,
1647 "syncrepl_entry: %s (%d)\n",
1649 switch ( rs_add.sr_err ) {
1651 be_entry_release_w( op, entry );
1656 /* we assume that LDAP_NO_SUCH_OBJECT is returned
1657 * only if the suffix entry is not present */
1658 case LDAP_NO_SUCH_OBJECT:
1659 syncrepl_add_glue( op, entry );
1663 /* if an entry was added via syncrepl_add_glue(),
1664 * it likely has no entryUUID, so the previous
1665 * be_search() doesn't find it. In this case,
1666 * give syncrepl a chance to modify it. Also
1667 * allow for entries that were recreated with the
1668 * same DN but a different entryUUID.
1670 case LDAP_ALREADY_EXISTS:
1672 Operation op2 = *op;
1673 SlapReply rs2 = { 0 };
1674 slap_callback cb2 = { 0 };
1676 op2.o_tag = LDAP_REQ_SEARCH;
1677 op2.o_req_dn = entry->e_name;
1678 op2.o_req_ndn = entry->e_nname;
1679 op2.ors_scope = LDAP_SCOPE_BASE;
1680 op2.ors_deref = LDAP_DEREF_NEVER;
1681 op2.ors_attrs = slap_anlist_all_attributes;
1682 op2.ors_attrsonly = 0;
1683 op2.ors_limit = NULL;
1685 op2.ors_tlimit = SLAP_NO_LIMIT;
1687 f.f_choice = LDAP_FILTER_PRESENT;
1688 f.f_desc = slap_schema.si_ad_objectClass;
1689 op2.ors_filter = &f;
1690 op2.ors_filterstr = generic_filterstr;
1692 op2.o_callback = &cb2;
1693 cb2.sc_response = dn_callback;
1694 cb2.sc_private = &dni;
1696 be->be_search( &op2, &rs2 );
1704 Debug( LDAP_DEBUG_ANY,
1705 "syncrepl_entry : be_add failed (%d)\n",
1706 rs_add.sr_err, 0, 0 );
1713 op->o_req_dn = dni.dn;
1714 op->o_req_ndn = dni.ndn;
1715 if ( dni.renamed ) {
1716 struct berval noldp, newp, nnewp;
1718 op->o_tag = LDAP_REQ_MODRDN;
1719 dnRdn( &entry->e_name, &op->orr_newrdn );
1720 dnRdn( &entry->e_nname, &op->orr_nnewrdn );
1722 dnParent( &dni.ndn, &noldp );
1723 dnParent( &entry->e_nname, &nnewp );
1724 if ( !dn_match( &noldp, &newp )) {
1725 dnParent( &entry->e_name, &newp );
1726 op->orr_newSup = &newp;
1727 op->orr_nnewSup = &nnewp;
1729 op->orr_deleteoldrdn = 0;
1730 rc = be->be_modrdn( op, &rs_modify );
1731 Debug( LDAP_DEBUG_SYNC,
1732 "syncrepl_entry: %s (%d)\n",
1733 "be_modrdn", rc, 0 );
1734 if ( rs_modify.sr_err == LDAP_SUCCESS ) {
1735 op->o_req_dn = entry->e_name;
1736 op->o_req_ndn = entry->e_nname;
1742 if ( dni.wasChanged ) {
1743 Modifications *mod, *modhead = NULL;
1744 Modifications *modtail = NULL;
1747 op->o_tag = LDAP_REQ_MODIFY;
1749 assert( *modlist != NULL );
1751 /* Delete all the old attrs */
1752 for ( i = 0; i < dni.attrs; i++ ) {
1753 mod = ch_malloc( sizeof( Modifications ) );
1754 mod->sml_op = LDAP_MOD_DELETE;
1756 mod->sml_desc = dni.ads[i];
1757 mod->sml_type = mod->sml_desc->ad_cname;
1758 mod->sml_values = NULL;
1759 mod->sml_nvalues = NULL;
1760 if ( !modhead ) modhead = mod;
1762 modtail->sml_next = mod;
1767 /* Append passed in list to ours */
1769 modtail->sml_next = *modlist;
1775 /* Find end of this list */
1776 for ( ; mod != NULL; mod = mod->sml_next ) {
1780 mod = (Modifications *)ch_calloc(1, sizeof(Modifications));
1781 mod->sml_op = LDAP_MOD_REPLACE;
1783 mod->sml_desc = slap_schema.si_ad_entryUUID;
1784 mod->sml_type = mod->sml_desc->ad_cname;
1785 ber_dupbv( &uuid_bv, &syncUUID_strrep );
1786 ber_bvarray_add( &mod->sml_values, &uuid_bv );
1787 ber_dupbv( &uuid_bv, syncUUID );
1788 ber_bvarray_add( &mod->sml_nvalues, &uuid_bv );
1789 modtail->sml_next = mod;
1791 op->o_tag = LDAP_REQ_MODIFY;
1792 op->orm_modlist = *modlist;
1794 rc = be->be_modify( op, &rs_modify );
1795 Debug( LDAP_DEBUG_SYNC,
1796 "syncrepl_entry: %s (%d)\n",
1797 "be_modify", rc, 0 );
1798 if ( rs_modify.sr_err != LDAP_SUCCESS ) {
1799 Debug( LDAP_DEBUG_ANY,
1800 "syncrepl_entry : be_modify failed (%d)\n",
1801 rs_modify.sr_err, 0, 0 );
1806 case LDAP_SYNC_DELETE :
1807 if ( !BER_BVISNULL( &dni.dn )) {
1808 op->o_req_dn = dni.dn;
1809 op->o_req_ndn = dni.ndn;
1810 op->o_tag = LDAP_REQ_DELETE;
1811 rc = be->be_delete( op, &rs_delete );
1812 Debug( LDAP_DEBUG_SYNC,
1813 "syncrepl_entry: %s (%d)\n",
1814 "be_delete", rc, 0 );
1816 while ( rs_delete.sr_err == LDAP_SUCCESS
1817 && op->o_delete_glue_parent ) {
1818 op->o_delete_glue_parent = 0;
1819 if ( !be_issuffix( op->o_bd, &op->o_req_ndn )) {
1820 slap_callback cb = { NULL };
1821 cb.sc_response = slap_null_cb;
1822 dnParent( &op->o_req_ndn, &pdn );
1824 op->o_req_ndn = pdn;
1825 op->o_callback = &cb;
1826 op->o_bd->be_delete( op, &rs_delete );
1836 Debug( LDAP_DEBUG_ANY,
1837 "syncrepl_entry : unknown syncstate\n", 0, 0, 0 );
1843 if ( !BER_BVISNULL( &syncUUID_strrep ) ) {
1844 slap_sl_free( syncUUID_strrep.bv_val, op->o_tmpmemctx );
1845 BER_BVZERO( &syncUUID_strrep );
1848 op->o_tmpfree( dni.ads, op->o_tmpmemctx );
1850 if ( !BER_BVISNULL( &dni.ndn ) ) {
1851 op->o_tmpfree( dni.ndn.bv_val, op->o_tmpmemctx );
1853 if ( !BER_BVISNULL( &dni.dn ) ) {
1854 op->o_tmpfree( dni.dn.bv_val, op->o_tmpmemctx );
1859 static struct berval gcbva[] = {
1865 #define NP_DELETE_ONE 2
1868 syncrepl_del_nonpresent(
1873 Backend* be = op->o_bd;
1874 slap_callback cb = { NULL };
1875 SlapReply rs_search = {REP_RESULT};
1876 SlapReply rs_delete = {REP_RESULT};
1877 SlapReply rs_modify = {REP_RESULT};
1878 struct nonpresent_entry *np_list, *np_prev;
1880 AttributeName an[2];
1882 struct berval pdn = BER_BVNULL;
1884 op->o_req_dn = si->si_base;
1885 op->o_req_ndn = si->si_base;
1887 cb.sc_response = nonpresent_callback;
1890 op->o_callback = &cb;
1891 op->o_tag = LDAP_REQ_SEARCH;
1892 op->ors_scope = si->si_scope;
1893 op->ors_deref = LDAP_DEREF_NEVER;
1894 op->o_time = slap_get_time();
1895 op->ors_tlimit = SLAP_NO_LIMIT;
1900 #ifdef LDAP_COMP_MATCH
1901 AttributeAssertion eq = { NULL, BER_BVNULL, NULL };
1903 AttributeAssertion eq = { NULL, BER_BVNULL };
1907 op->ors_attrsonly = 1;
1908 op->ors_attrs = slap_anlist_no_attrs;
1909 op->ors_limit = NULL;
1910 op->ors_filter = &uf;
1913 uf.f_av_desc = slap_schema.si_ad_entryUUID;
1915 uf.f_choice = LDAP_FILTER_EQUALITY;
1916 si->si_refreshDelete |= NP_DELETE_ONE;
1918 for (i=0; uuids[i].bv_val; i++) {
1920 uf.f_av_value = uuids[i];
1921 rc = be->be_search( op, &rs_search );
1923 si->si_refreshDelete ^= NP_DELETE_ONE;
1925 memset( &an[0], 0, 2 * sizeof( AttributeName ) );
1926 an[0].an_name = slap_schema.si_ad_entryUUID->ad_cname;
1927 an[0].an_desc = slap_schema.si_ad_entryUUID;
1929 op->ors_slimit = SLAP_NO_LIMIT;
1930 op->ors_attrsonly = 0;
1931 op->ors_filter = str2filter_x( op, si->si_filterstr.bv_val );
1932 op->ors_filterstr = si->si_filterstr;
1933 op->o_nocaching = 1;
1935 if ( limits_check( op, &rs_search ) == 0 ) {
1936 rc = be->be_search( op, &rs_search );
1938 if ( op->ors_filter ) filter_free_x( op, op->ors_filter );
1941 op->o_nocaching = 0;
1943 if ( !LDAP_LIST_EMPTY( &si->si_nonpresentlist ) ) {
1945 slap_queue_csn( op, &si->si_syncCookie.ctxcsn );
1947 np_list = LDAP_LIST_FIRST( &si->si_nonpresentlist );
1948 while ( np_list != NULL ) {
1949 LDAP_LIST_REMOVE( np_list, npe_link );
1951 np_list = LDAP_LIST_NEXT( np_list, npe_link );
1952 op->o_tag = LDAP_REQ_DELETE;
1953 op->o_callback = &cb;
1954 cb.sc_response = null_callback;
1956 op->o_req_dn = *np_prev->npe_name;
1957 op->o_req_ndn = *np_prev->npe_nname;
1958 rc = op->o_bd->be_delete( op, &rs_delete );
1960 if ( rs_delete.sr_err == LDAP_NOT_ALLOWED_ON_NONLEAF ) {
1961 Modifications mod1, mod2;
1962 mod1.sml_op = LDAP_MOD_REPLACE;
1964 mod1.sml_desc = slap_schema.si_ad_objectClass;
1965 mod1.sml_type = mod1.sml_desc->ad_cname;
1966 mod1.sml_values = &gcbva[0];
1967 mod1.sml_nvalues = NULL;
1968 mod1.sml_next = &mod2;
1970 mod2.sml_op = LDAP_MOD_REPLACE;
1972 mod2.sml_desc = slap_schema.si_ad_structuralObjectClass;
1973 mod2.sml_type = mod2.sml_desc->ad_cname;
1974 mod2.sml_values = &gcbva[1];
1975 mod2.sml_nvalues = NULL;
1976 mod2.sml_next = NULL;
1978 op->o_tag = LDAP_REQ_MODIFY;
1979 op->orm_modlist = &mod1;
1981 rc = be->be_modify( op, &rs_modify );
1984 while ( rs_delete.sr_err == LDAP_SUCCESS &&
1985 op->o_delete_glue_parent ) {
1986 op->o_delete_glue_parent = 0;
1987 if ( !be_issuffix( op->o_bd, &op->o_req_ndn )) {
1988 slap_callback cb = { NULL };
1989 cb.sc_response = slap_null_cb;
1990 dnParent( &op->o_req_ndn, &pdn );
1992 op->o_req_ndn = pdn;
1993 op->o_callback = &cb;
1994 /* give it a root privil ? */
1995 op->o_bd->be_delete( op, &rs_delete );
2001 op->o_delete_glue_parent = 0;
2003 ber_bvfree( np_prev->npe_name );
2004 ber_bvfree( np_prev->npe_nname );
2008 slap_graduate_commit_csn( op );
2019 Backend *be = op->o_bd;
2020 slap_callback cb = { NULL };
2025 struct berval dn = {0, NULL};
2026 struct berval ndn = {0, NULL};
2028 SlapReply rs_add = {REP_RESULT};
2031 op->o_tag = LDAP_REQ_ADD;
2032 op->o_callback = &cb;
2033 cb.sc_response = null_callback;
2034 cb.sc_private = NULL;
2039 /* count RDNs in suffix */
2040 if ( !BER_BVISEMPTY( &be->be_nsuffix[0] ) ) {
2041 for ( i = 0, ptr = be->be_nsuffix[0].bv_val; ptr; ptr = strchr( ptr, ',' ) ) {
2051 /* Start with BE suffix */
2052 for ( i = 0, ptr = NULL; i < suffrdns; i++ ) {
2053 comma = strrchr( dn.bv_val, ',' );
2054 if ( ptr ) *ptr = ',';
2055 if ( comma ) *comma = '\0';
2060 dn.bv_len -= ptr - dn.bv_val;
2063 /* the normalizedDNs are always the same length, no counting
2066 if ( ndn.bv_len > be->be_nsuffix[0].bv_len ) {
2067 ndn.bv_val += ndn.bv_len - be->be_nsuffix[0].bv_len;
2068 ndn.bv_len = be->be_nsuffix[0].bv_len;
2071 while ( ndn.bv_val > e->e_nname.bv_val ) {
2072 glue = (Entry *) ch_calloc( 1, sizeof(Entry) );
2073 ber_dupbv( &glue->e_name, &dn );
2074 ber_dupbv( &glue->e_nname, &ndn );
2076 a = ch_calloc( 1, sizeof( Attribute ));
2077 a->a_desc = slap_schema.si_ad_objectClass;
2079 a->a_vals = ch_calloc( 3, sizeof( struct berval ));
2080 ber_dupbv( &a->a_vals[0], &gcbva[0] );
2081 ber_dupbv( &a->a_vals[1], &gcbva[1] );
2082 ber_dupbv( &a->a_vals[2], &gcbva[2] );
2084 a->a_nvals = a->a_vals;
2086 a->a_next = glue->e_attrs;
2089 a = ch_calloc( 1, sizeof( Attribute ));
2090 a->a_desc = slap_schema.si_ad_structuralObjectClass;
2092 a->a_vals = ch_calloc( 2, sizeof( struct berval ));
2093 ber_dupbv( &a->a_vals[0], &gcbva[1] );
2094 ber_dupbv( &a->a_vals[1], &gcbva[2] );
2096 a->a_nvals = a->a_vals;
2098 a->a_next = glue->e_attrs;
2101 op->o_req_dn = glue->e_name;
2102 op->o_req_ndn = glue->e_nname;
2104 rc = be->be_add ( op, &rs_add );
2105 if ( rs_add.sr_err == LDAP_SUCCESS ) {
2106 be_entry_release_w( op, glue );
2108 /* incl. ALREADY EXIST */
2112 /* Move to next child */
2113 for (ptr = dn.bv_val-2; ptr > e->e_name.bv_val && *ptr != ','; ptr--) {
2116 if ( ptr == e->e_name.bv_val ) break;
2118 dn.bv_len = e->e_name.bv_len - (ptr-e->e_name.bv_val);
2119 for( ptr = ndn.bv_val-2;
2120 ptr > e->e_nname.bv_val && *ptr != ',';
2126 ndn.bv_len = e->e_nname.bv_len - (ptr-e->e_nname.bv_val);
2129 op->o_req_dn = e->e_name;
2130 op->o_req_ndn = e->e_nname;
2132 rc = be->be_add ( op, &rs_add );
2133 if ( rs_add.sr_err == LDAP_SUCCESS ) {
2134 be_entry_release_w( op, e );
2143 syncrepl_updateCookie(
2147 struct sync_cookie *syncCookie )
2149 Backend *be = op->o_bd;
2150 Modifications mod = { { 0 } };
2151 struct berval vals[ 2 ];
2155 slap_callback cb = { NULL };
2156 SlapReply rs_modify = {REP_RESULT};
2158 slap_sync_cookie_free( &si->si_syncCookie, 0 );
2159 slap_dup_sync_cookie( &si->si_syncCookie, syncCookie );
2161 mod.sml_op = LDAP_MOD_REPLACE;
2162 mod.sml_desc = slap_schema.si_ad_contextCSN;
2163 mod.sml_type = mod.sml_desc->ad_cname;
2164 mod.sml_values = vals;
2165 vals[0] = si->si_syncCookie.ctxcsn;
2166 vals[1].bv_val = NULL;
2169 slap_queue_csn( op, &si->si_syncCookie.ctxcsn );
2171 op->o_tag = LDAP_REQ_MODIFY;
2173 assert( si->si_rid < 1000 );
2175 cb.sc_response = null_callback;
2178 op->o_callback = &cb;
2179 op->o_req_dn = op->o_bd->be_suffix[0];
2180 op->o_req_ndn = op->o_bd->be_nsuffix[0];
2182 /* update contextCSN */
2183 op->o_msgid = SLAP_SYNC_UPDATE_MSGID;
2184 op->orm_modlist = &mod;
2185 rc = be->be_modify( op, &rs_modify );
2188 if ( rs_modify.sr_err != LDAP_SUCCESS ) {
2189 Debug( LDAP_DEBUG_ANY,
2190 "be_modify failed (%d)\n", rs_modify.sr_err, 0, 0 );
2193 slap_graduate_commit_csn( op );
2203 dninfo *dni = op->o_callback->sc_private;
2205 if ( rs->sr_type == REP_SEARCH ) {
2206 if ( !BER_BVISNULL( &dni->dn ) ) {
2207 Debug( LDAP_DEBUG_ANY,
2208 "dn_callback : consistency error - "
2209 "entryUUID is not unique\n", 0, 0, 0 );
2211 ber_dupbv_x( &dni->dn, &rs->sr_entry->e_name, op->o_tmpmemctx );
2212 ber_dupbv_x( &dni->ndn, &rs->sr_entry->e_nname, op->o_tmpmemctx );
2213 /* If there is a new entry, see if it differs from the old.
2214 * We compare the non-normalized values so that cosmetic changes
2215 * in the provider are always propagated.
2217 if ( dni->new_entry ) {
2218 Attribute *old, *new;
2221 /* Did the DN change? Note that we don't explicitly try to
2222 * discover if the deleteOldRdn argument applies here. It
2223 * would save an unnecessary Modify if we detected it, but
2224 * that's a fair amount of trouble to compare the two attr
2227 if ( !dn_match( &rs->sr_entry->e_name,
2228 &dni->new_entry->e_name ) )
2233 for ( i = 0, old = rs->sr_entry->e_attrs;
2235 i++, old = old->a_next )
2240 /* We assume that attributes are saved in the same order
2241 * in the remote and local databases. So if we walk through
2242 * the attributeDescriptions one by one they should match in
2243 * lock step. If not, we signal a change. Otherwise we test
2246 for ( old = rs->sr_entry->e_attrs, new = dni->new_entry->e_attrs;
2248 old = old->a_next, new = new->a_next )
2250 if ( old->a_desc != new->a_desc ) {
2251 dni->wasChanged = 1;
2254 for ( i = 0; ; i++ ) {
2256 nold = BER_BVISNULL( &old->a_vals[i] );
2257 nnew = BER_BVISNULL( &new->a_vals[i] );
2258 /* If both are empty, stop looking */
2259 if ( nold && nnew ) {
2262 /* If they are different, stop looking */
2263 if ( nold != nnew ) {
2264 dni->wasChanged = 1;
2267 if ( ber_bvcmp( &old->a_vals[i], &new->a_vals[i] )) {
2268 dni->wasChanged = 1;
2272 if ( dni->wasChanged ) break;
2274 if ( dni->wasChanged ) {
2275 dni->ads = op->o_tmpalloc( dni->attrs *
2276 sizeof(AttributeDescription *), op->o_tmpmemctx );
2278 for ( old = rs->sr_entry->e_attrs; old; old = old->a_next ) {
2279 dni->ads[i] = old->a_desc;
2285 } else if ( rs->sr_type == REP_RESULT ) {
2286 if ( rs->sr_err == LDAP_SIZELIMIT_EXCEEDED ) {
2287 Debug( LDAP_DEBUG_ANY,
2288 "dn_callback : consistency error - "
2289 "entryUUID is not unique\n", 0, 0, 0 );
2293 return LDAP_SUCCESS;
2297 nonpresent_callback(
2301 syncinfo_t *si = op->o_callback->sc_private;
2304 struct berval* present_uuid = NULL;
2305 struct nonpresent_entry *np_entry;
2307 if ( rs->sr_type == REP_RESULT ) {
2308 count = avl_free( si->si_presentlist, avl_ber_bvfree );
2309 si->si_presentlist = NULL;
2311 } else if ( rs->sr_type == REP_SEARCH ) {
2312 if ( !(si->si_refreshDelete & NP_DELETE_ONE )) {
2313 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID );
2315 if ( a == NULL ) return 0;
2317 present_uuid = avl_find( si->si_presentlist, &a->a_nvals[0],
2321 if ( present_uuid == NULL ) {
2322 np_entry = (struct nonpresent_entry *)
2323 ch_calloc( 1, sizeof( struct nonpresent_entry ));
2324 np_entry->npe_name = ber_dupbv( NULL, &rs->sr_entry->e_name );
2325 np_entry->npe_nname = ber_dupbv( NULL, &rs->sr_entry->e_nname );
2326 LDAP_LIST_INSERT_HEAD( &si->si_nonpresentlist, np_entry, npe_link );
2329 avl_delete( &si->si_presentlist,
2330 &a->a_nvals[0], syncuuid_cmp );
2331 ch_free( present_uuid->bv_val );
2332 ch_free( present_uuid );
2335 return LDAP_SUCCESS;
2343 if ( rs->sr_err != LDAP_SUCCESS &&
2344 rs->sr_err != LDAP_REFERRAL &&
2345 rs->sr_err != LDAP_ALREADY_EXISTS &&
2346 rs->sr_err != LDAP_NO_SUCH_OBJECT &&
2347 rs->sr_err != LDAP_NOT_ALLOWED_ON_NONLEAF )
2349 Debug( LDAP_DEBUG_ANY,
2350 "null_callback : error code 0x%x\n",
2353 return LDAP_SUCCESS;
2356 static struct berval *
2357 slap_uuidstr_from_normalized(
2358 struct berval* uuidstr,
2359 struct berval* normalized,
2363 unsigned char nibble;
2366 if ( normalized == NULL ) return NULL;
2367 if ( normalized->bv_len != 16 ) return NULL;
2372 new = (struct berval *)slap_sl_malloc( sizeof(struct berval), ctx );
2373 if ( new == NULL ) {
2380 if ( ( new->bv_val = slap_sl_malloc( new->bv_len + 1, ctx ) ) == NULL ) {
2381 if ( new != uuidstr ) {
2382 slap_sl_free( new, ctx );
2387 for ( i = 0; i < 16; i++ ) {
2388 if ( i == 4 || i == 6 || i == 8 || i == 10 ) {
2389 new->bv_val[(i<<1)+d] = '-';
2393 nibble = (normalized->bv_val[i] >> 4) & 0xF;
2394 if ( nibble < 10 ) {
2395 new->bv_val[(i<<1)+d] = nibble + '0';
2397 new->bv_val[(i<<1)+d] = nibble - 10 + 'a';
2400 nibble = (normalized->bv_val[i]) & 0xF;
2401 if ( nibble < 10 ) {
2402 new->bv_val[(i<<1)+d+1] = nibble + '0';
2404 new->bv_val[(i<<1)+d+1] = nibble - 10 + 'a';
2408 new->bv_val[new->bv_len] = '\0';
2413 syncuuid_cmp( const void* v_uuid1, const void* v_uuid2 )
2415 const struct berval *uuid1 = v_uuid1;
2416 const struct berval *uuid2 = v_uuid2;
2417 int rc = uuid1->bv_len - uuid2->bv_len;
2418 if ( rc ) return rc;
2419 return ( memcmp( uuid1->bv_val, uuid2->bv_val, uuid1->bv_len ) );
2423 avl_ber_bvfree( void *v_bv )
2425 struct berval *bv = (struct berval *)v_bv;
2427 if( v_bv == NULL ) return;
2428 if ( !BER_BVISNULL( bv ) ) {
2429 ch_free( bv->bv_val );
2431 ch_free( (char *) bv );
2435 syncinfo_free( syncinfo_t *sie )
2437 ldap_pvt_thread_mutex_destroy( &sie->si_mutex );
2438 if ( !BER_BVISNULL( &sie->si_provideruri ) ) {
2439 ch_free( sie->si_provideruri.bv_val );
2442 bindconf_free( &sie->si_bindconf );
2444 if ( sie->si_filterstr.bv_val ) {
2445 ch_free( sie->si_filterstr.bv_val );
2447 if ( sie->si_base.bv_val ) {
2448 ch_free( sie->si_base.bv_val );
2450 if ( sie->si_attrs ) {
2452 while ( sie->si_attrs[i] != NULL ) {
2453 ch_free( sie->si_attrs[i] );
2456 ch_free( sie->si_attrs );
2458 if ( sie->si_exattrs ) {
2460 while ( sie->si_exattrs[i] != NULL ) {
2461 ch_free( sie->si_exattrs[i] );
2464 ch_free( sie->si_exattrs );
2466 if ( sie->si_anlist ) {
2468 while ( sie->si_anlist[i].an_name.bv_val != NULL ) {
2469 ch_free( sie->si_anlist[i].an_name.bv_val );
2472 ch_free( sie->si_anlist );
2474 if ( sie->si_exanlist ) {
2476 while ( sie->si_exanlist[i].an_name.bv_val != NULL ) {
2477 ch_free( sie->si_exanlist[i].an_name.bv_val );
2480 ch_free( sie->si_exanlist );
2482 if ( sie->si_retryinterval ) {
2483 ch_free( sie->si_retryinterval );
2485 if ( sie->si_retrynum ) {
2486 ch_free( sie->si_retrynum );
2488 if ( sie->si_retrynum_init ) {
2489 ch_free( sie->si_retrynum_init );
2491 slap_sync_cookie_free( &sie->si_syncCookie, 0 );
2492 if ( sie->si_presentlist ) {
2493 avl_free( sie->si_presentlist, avl_ber_bvfree );
2496 ldap_ld_free( sie->si_ld, 1, NULL, NULL );
2498 while ( !LDAP_LIST_EMPTY( &sie->si_nonpresentlist )) {
2499 struct nonpresent_entry* npe;
2500 npe = LDAP_LIST_FIRST( &sie->si_nonpresentlist );
2501 LDAP_LIST_REMOVE( npe, npe_link );
2502 if ( npe->npe_name ) {
2503 if ( npe->npe_name->bv_val ) {
2504 ch_free( npe->npe_name->bv_val );
2506 ch_free( npe->npe_name );
2508 if ( npe->npe_nname ) {
2509 if ( npe->npe_nname->bv_val ) {
2510 ch_free( npe->npe_nname->bv_val );
2512 ch_free( npe->npe_nname );
2521 /* NOTE: used & documented in slapd.conf(5) */
2523 #define PROVIDERSTR "provider"
2524 #define SCHEMASTR "schemachecking"
2525 #define FILTERSTR "filter"
2526 #define SEARCHBASESTR "searchbase"
2527 #define SCOPESTR "scope"
2528 #define ATTRSONLYSTR "attrsonly"
2529 #define ATTRSSTR "attrs"
2530 #define TYPESTR "type"
2531 #define INTERVALSTR "interval"
2532 #define RETRYSTR "retry"
2533 #define SLIMITSTR "sizelimit"
2534 #define TLIMITSTR "timelimit"
2535 #define SYNCDATASTR "syncdata"
2537 /* FIXME: undocumented */
2538 #define OLDAUTHCSTR "bindprincipal"
2539 #define EXATTRSSTR "exattrs"
2540 #define MANAGEDSAITSTR "manageDSAit"
2543 #define LASTMODSTR "lastmod"
2544 #define LMGENSTR "gen"
2545 #define LMNOSTR "no"
2546 #define LMREQSTR "req"
2547 #define SRVTABSTR "srvtab"
2548 #define SUFFIXSTR "suffix"
2551 #define GOT_ID 0x0001
2552 #define GOT_PROVIDER 0x0002
2555 #define GOT_ALL (GOT_ID|GOT_PROVIDER)
2561 { BER_BVC("base"), LDAP_SCOPE_BASE },
2562 { BER_BVC("one"), LDAP_SCOPE_ONELEVEL },
2563 { BER_BVC("onelevel"), LDAP_SCOPE_ONELEVEL }, /* OpenLDAP extension */
2564 #ifdef LDAP_SCOPE_SUBORDINATE
2565 { BER_BVC("children"), LDAP_SCOPE_SUBORDINATE },
2566 { BER_BVC("subordinate"), LDAP_SCOPE_SUBORDINATE },
2568 { BER_BVC("sub"), LDAP_SCOPE_SUBTREE },
2569 { BER_BVC("subtree"), LDAP_SCOPE_SUBTREE }, /* OpenLDAP extension */
2573 static slap_verbmasks datamodes[] = {
2574 { BER_BVC("default"), SYNCDATA_DEFAULT },
2575 { BER_BVC("accesslog"), SYNCDATA_ACCESSLOG },
2576 { BER_BVC("changelog"), SYNCDATA_CHANGELOG },
2581 parse_syncrepl_line(
2591 for ( i = 1; i < cargc; i++ ) {
2592 if ( !strncasecmp( cargv[ i ], IDSTR "=",
2593 STRLENOF( IDSTR "=" ) ) )
2596 /* '\0' string terminator accounts for '=' */
2597 val = cargv[ i ] + STRLENOF( IDSTR "=" );
2599 if ( tmp >= 1000 || tmp < 0 ) {
2600 fprintf( stderr, "Error: parse_syncrepl_line: "
2601 "syncrepl id %d is out of range [0..999]\n", tmp );
2606 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR "=",
2607 STRLENOF( PROVIDERSTR "=" ) ) )
2609 val = cargv[ i ] + STRLENOF( PROVIDERSTR "=" );
2610 ber_str2bv( val, 0, 1, &si->si_provideruri );
2611 gots |= GOT_PROVIDER;
2612 } else if ( !strncasecmp( cargv[ i ], SCHEMASTR "=",
2613 STRLENOF( SCHEMASTR "=" ) ) )
2615 val = cargv[ i ] + STRLENOF( SCHEMASTR "=" );
2616 if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
2617 si->si_schemachecking = 1;
2618 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2619 si->si_schemachecking = 0;
2621 si->si_schemachecking = 1;
2623 } else if ( !strncasecmp( cargv[ i ], FILTERSTR "=",
2624 STRLENOF( FILTERSTR "=" ) ) )
2626 val = cargv[ i ] + STRLENOF( FILTERSTR "=" );
2627 if ( si->si_filterstr.bv_val )
2628 ch_free( si->si_filterstr.bv_val );
2629 ber_str2bv( val, 0, 1, &si->si_filterstr );
2630 } else if ( !strncasecmp( cargv[ i ], SEARCHBASESTR "=",
2631 STRLENOF( SEARCHBASESTR "=" ) ) )
2636 val = cargv[ i ] + STRLENOF( SEARCHBASESTR "=" );
2637 if ( si->si_base.bv_val ) {
2638 ch_free( si->si_base.bv_val );
2640 ber_str2bv( val, 0, 0, &bv );
2641 rc = dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL );
2642 if ( rc != LDAP_SUCCESS ) {
2643 fprintf( stderr, "Invalid base DN \"%s\": %d (%s)\n",
2644 val, rc, ldap_err2string( rc ) );
2647 } else if ( !strncasecmp( cargv[ i ], SCOPESTR "=",
2648 STRLENOF( SCOPESTR "=" ) ) )
2651 val = cargv[ i ] + STRLENOF( SCOPESTR "=" );
2652 for ( j=0; !BER_BVISNULL(&scopes[j].key); j++ ) {
2653 if (!strcasecmp( val, scopes[j].key.bv_val )) {
2654 si->si_scope = scopes[j].val;
2658 if ( BER_BVISNULL(&scopes[j].key) ) {
2659 fprintf( stderr, "Error: parse_syncrepl_line: "
2660 "unknown scope \"%s\"\n", val);
2663 } else if ( !strncasecmp( cargv[ i ], ATTRSONLYSTR "=",
2664 STRLENOF( ATTRSONLYSTR "=" ) ) )
2666 si->si_attrsonly = 1;
2667 } else if ( !strncasecmp( cargv[ i ], ATTRSSTR "=",
2668 STRLENOF( ATTRSSTR "=" ) ) )
2670 val = cargv[ i ] + STRLENOF( ATTRSSTR "=" );
2671 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") ) ) {
2673 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2674 si->si_anlist = file2anlist( si->si_anlist, attr_fname, " ,\t" );
2675 if ( si->si_anlist == NULL ) {
2676 ch_free( attr_fname );
2679 si->si_anfile = attr_fname;
2681 char *str, *s, *next;
2682 char delimstr[] = " ,\t";
2683 str = ch_strdup( val );
2684 for ( s = ldap_pvt_strtok( str, delimstr, &next );
2686 s = ldap_pvt_strtok( NULL, delimstr, &next ) )
2688 if ( strlen(s) == 1 && *s == '*' ) {
2689 si->si_allattrs = 1;
2690 *(val + ( s - str )) = delimstr[0];
2692 if ( strlen(s) == 1 && *s == '+' ) {
2693 si->si_allopattrs = 1;
2694 *(val + ( s - str )) = delimstr[0];
2698 si->si_anlist = str2anlist( si->si_anlist, val, " ,\t" );
2699 if ( si->si_anlist == NULL ) {
2703 } else if ( !strncasecmp( cargv[ i ], EXATTRSSTR "=",
2704 STRLENOF( EXATTRSSTR "=" ) ) )
2706 val = cargv[ i ] + STRLENOF( EXATTRSSTR "=" );
2707 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") )) {
2709 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2710 si->si_exanlist = file2anlist(
2711 si->si_exanlist, attr_fname, " ,\t" );
2712 if ( si->si_exanlist == NULL ) {
2713 ch_free( attr_fname );
2716 ch_free( attr_fname );
2718 si->si_exanlist = str2anlist( si->si_exanlist, val, " ,\t" );
2719 if ( si->si_exanlist == NULL ) {
2723 } else if ( !strncasecmp( cargv[ i ], TYPESTR "=",
2724 STRLENOF( TYPESTR "=" ) ) )
2726 val = cargv[ i ] + STRLENOF( TYPESTR "=" );
2727 if ( !strncasecmp( val, "refreshOnly",
2728 STRLENOF("refreshOnly") ))
2730 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2731 } else if ( !strncasecmp( val, "refreshAndPersist",
2732 STRLENOF("refreshAndPersist") ))
2734 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
2735 si->si_interval = 60;
2737 fprintf( stderr, "Error: parse_syncrepl_line: "
2738 "unknown sync type \"%s\"\n", val);
2741 } else if ( !strncasecmp( cargv[ i ], INTERVALSTR "=",
2742 STRLENOF( INTERVALSTR "=" ) ) )
2744 val = cargv[ i ] + STRLENOF( INTERVALSTR "=" );
2745 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
2746 si->si_interval = 0;
2754 hstr = strchr( dstr, ':' );
2755 if ( hstr == NULL ) {
2756 fprintf( stderr, "Error: parse_syncrepl_line: "
2757 "invalid interval \"%s\"\n", val );
2761 mstr = strchr( hstr, ':' );
2762 if ( mstr == NULL ) {
2763 fprintf( stderr, "Error: parse_syncrepl_line: "
2764 "invalid interval \"%s\"\n", val );
2768 sstr = strchr( mstr, ':' );
2769 if ( sstr == NULL ) {
2770 fprintf( stderr, "Error: parse_syncrepl_line: "
2771 "invalid interval \"%s\"\n", val );
2780 if (( hh > 24 ) || ( hh < 0 ) ||
2781 ( mm > 60 ) || ( mm < 0 ) ||
2782 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
2783 fprintf( stderr, "Error: parse_syncrepl_line: "
2784 "invalid interval \"%s\"\n", val );
2787 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
2789 if ( si->si_interval < 0 ) {
2790 fprintf( stderr, "Error: parse_syncrepl_line: "
2791 "invalid interval \"%ld\"\n",
2792 (long) si->si_interval);
2795 } else if ( !strncasecmp( cargv[ i ], RETRYSTR "=",
2796 STRLENOF( RETRYSTR "=" ) ) )
2801 val = cargv[ i ] + STRLENOF( RETRYSTR "=" );
2802 retry_list = (char **) ch_calloc( 1, sizeof( char * ));
2803 retry_list[0] = NULL;
2805 slap_str2clist( &retry_list, val, " ,\t" );
2807 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
2811 "Error: incomplete syncrepl retry list\n" );
2812 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2813 ch_free( retry_list[k] );
2815 ch_free( retry_list );
2816 exit( EXIT_FAILURE );
2818 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
2819 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
2820 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
2821 for ( j = 0; j < n; j++ ) {
2822 si->si_retryinterval[j] = atoi( retry_list[j*2] );
2823 if ( *retry_list[j*2+1] == '+' ) {
2824 si->si_retrynum_init[j] = -1;
2825 si->si_retrynum[j] = -1;
2829 si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
2830 si->si_retrynum[j] = atoi( retry_list[j*2+1] );
2833 si->si_retrynum_init[j] = -2;
2834 si->si_retrynum[j] = -2;
2835 si->si_retryinterval[j] = 0;
2837 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2838 ch_free( retry_list[k] );
2840 ch_free( retry_list );
2841 } else if ( !strncasecmp( cargv[ i ], MANAGEDSAITSTR "=",
2842 STRLENOF( MANAGEDSAITSTR "=" ) ) )
2844 val = cargv[ i ] + STRLENOF( MANAGEDSAITSTR "=" );
2845 si->si_manageDSAit = atoi( val );
2846 } else if ( !strncasecmp( cargv[ i ], SLIMITSTR "=",
2847 STRLENOF( SLIMITSTR "=") ) )
2849 val = cargv[ i ] + STRLENOF( SLIMITSTR "=" );
2850 si->si_slimit = atoi( val );
2851 } else if ( !strncasecmp( cargv[ i ], TLIMITSTR "=",
2852 STRLENOF( TLIMITSTR "=" ) ) )
2854 val = cargv[ i ] + STRLENOF( TLIMITSTR "=" );
2855 si->si_tlimit = atoi( val );
2856 } else if ( !strncasecmp( cargv[ i ], SYNCDATASTR "=",
2857 STRLENOF( SYNCDATASTR "=" ) ) )
2859 val = cargv[ i ] + STRLENOF( SYNCDATASTR "=" );
2860 si->si_syncdata = verb_to_mask( val, datamodes );
2861 } else if ( bindconf_parse( cargv[i], &si->si_bindconf )) {
2862 fprintf( stderr, "Error: parse_syncrepl_line: "
2863 "unknown keyword \"%s\"\n", cargv[ i ] );
2868 if ( gots != GOT_ALL ) {
2870 "Error: Malformed \"syncrepl\" line in slapd config file" );
2887 if ( !( be->be_search && be->be_add && be->be_modify && be->be_delete )) {
2888 Debug( LDAP_DEBUG_ANY, "database %s does not support operations "
2889 "required for syncrepl\n", be->be_type, 0, 0 );
2892 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2895 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2899 si->si_bindconf.sb_tls = SB_TLS_OFF;
2900 si->si_bindconf.sb_method = LDAP_AUTH_SIMPLE;
2901 si->si_schemachecking = 0;
2902 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
2903 &si->si_filterstr );
2904 si->si_base.bv_val = NULL;
2905 si->si_scope = LDAP_SCOPE_SUBTREE;
2906 si->si_attrsonly = 0;
2907 si->si_anlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2908 si->si_exanlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2909 si->si_attrs = NULL;
2910 si->si_allattrs = 0;
2911 si->si_allopattrs = 0;
2912 si->si_exattrs = NULL;
2913 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2914 si->si_interval = 86400;
2915 si->si_retryinterval = NULL;
2916 si->si_retrynum_init = NULL;
2917 si->si_retrynum = NULL;
2918 si->si_manageDSAit = 0;
2922 si->si_presentlist = NULL;
2923 LDAP_LIST_INIT( &si->si_nonpresentlist );
2924 ldap_pvt_thread_mutex_init( &si->si_mutex );
2926 rc = parse_syncrepl_line( cargv, cargc, si );
2930 init_syncrepl( si );
2931 si->si_re = ldap_pvt_runqueue_insert( &slapd_rq, si->si_interval,
2932 do_syncrepl, si, "do_syncrepl", be->be_suffix[0].bv_val );
2937 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2938 syncinfo_free( si );
2941 Debug( LDAP_DEBUG_CONFIG,
2942 "Config: ** successfully added syncrepl \"%s\"\n",
2943 BER_BVISNULL( &si->si_provideruri ) ?
2944 "(null)" : si->si_provideruri.bv_val, 0, 0 );
2945 if ( !si->si_schemachecking ) {
2946 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2948 be->be_syncinfo = si;
2954 syncrepl_unparse( syncinfo_t *si, struct berval *bv )
2957 char buf[BUFSIZ*2], *ptr;
2960 bindconf_unparse( &si->si_bindconf, &bc );
2962 ptr += sprintf( ptr, IDSTR "=%03ld " PROVIDERSTR "=%s",
2963 si->si_rid, si->si_provideruri.bv_val );
2964 if ( !BER_BVISNULL( &bc )) {
2965 ptr = lutil_strcopy( ptr, bc.bv_val );
2968 if ( !BER_BVISEMPTY( &si->si_filterstr )) {
2969 ptr = lutil_strcopy( ptr, " " FILTERSTR "=\"" );
2970 ptr = lutil_strcopy( ptr, si->si_filterstr.bv_val );
2973 if ( !BER_BVISNULL( &si->si_base )) {
2974 ptr = lutil_strcopy( ptr, " " SEARCHBASESTR "=\"" );
2975 ptr = lutil_strcopy( ptr, si->si_base.bv_val );
2978 for (i=0; !BER_BVISNULL(&scopes[i].key);i++) {
2979 if ( si->si_scope == scopes[i].val ) {
2980 ptr = lutil_strcopy( ptr, " " SCOPESTR "=" );
2981 ptr = lutil_strcopy( ptr, scopes[i].key.bv_val );
2985 if ( si->si_attrsonly ) {
2986 ptr = lutil_strcopy( ptr, " " ATTRSONLYSTR "=yes" );
2988 if ( si->si_anfile ) {
2989 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=:include:" );
2990 ptr = lutil_strcopy( ptr, si->si_anfile );
2991 } else if ( si->si_allattrs || si->si_allopattrs ||
2992 ( si->si_anlist && !BER_BVISNULL(&si->si_anlist[0].an_name) )) {
2994 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=\"" );
2996 ptr = anlist_unparse( si->si_anlist, ptr );
2997 if ( si->si_allattrs ) {
2998 if ( old != ptr ) *ptr++ = ',';
3001 if ( si->si_allopattrs ) {
3002 if ( old != ptr ) *ptr++ = ',';
3007 if ( si->si_exanlist && !BER_BVISNULL(&si->si_exanlist[0].an_name) ) {
3008 ptr = lutil_strcopy( ptr, " " EXATTRSSTR "=" );
3009 ptr = anlist_unparse( si->si_exanlist, ptr );
3011 ptr = lutil_strcopy( ptr, " " SCHEMASTR "=" );
3012 ptr = lutil_strcopy( ptr, si->si_schemachecking ? "on" : "off" );
3014 ptr = lutil_strcopy( ptr, " " TYPESTR "=" );
3015 ptr = lutil_strcopy( ptr, si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ?
3016 "refreshAndPersist" : "refreshOnly" );
3018 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
3021 dd = si->si_interval;
3028 ptr = lutil_strcopy( ptr, " " INTERVALSTR "=" );
3029 ptr += sprintf( ptr, "%02d:%02d:%02d:%02d", dd, hh, mm, ss );
3030 } else if ( si->si_retryinterval ) {
3032 ptr = lutil_strcopy( ptr, " " RETRYSTR "=\"" );
3033 for (i=0; si->si_retryinterval[i]; i++) {
3034 if ( space ) *ptr++ = ' ';
3036 ptr += sprintf( ptr, "%ld ", (long) si->si_retryinterval[i] );
3037 if ( si->si_retrynum_init[i] == -1 )
3040 ptr += sprintf( ptr, "%d", si->si_retrynum_init[i] );
3045 if ( si->si_slimit ) {
3046 ptr = lutil_strcopy( ptr, " " SLIMITSTR "=" );
3047 ptr += sprintf( ptr, "%d", si->si_slimit );
3050 if ( si->si_tlimit ) {
3051 ptr = lutil_strcopy( ptr, " " TLIMITSTR "=" );
3052 ptr += sprintf( ptr, "%d", si->si_tlimit );
3055 if ( si->si_syncdata ) {
3056 if ( enum_to_verb( datamodes, si->si_syncdata, &bc ) >= 0 ) {
3057 ptr = lutil_strcopy( ptr, " " SYNCDATASTR "=" );
3058 ptr = lutil_strcopy( ptr, bc.bv_val );
3061 bc.bv_len = ptr - buf;
3063 ber_dupbv( bv, &bc );
3067 syncrepl_config(ConfigArgs *c) {
3068 if (c->op == SLAP_CONFIG_EMIT) {
3069 if ( c->be->be_syncinfo ) {
3071 syncrepl_unparse( c->be->be_syncinfo, &bv );
3072 ber_bvarray_add( &c->rvalue_vals, &bv );
3076 } else if ( c->op == LDAP_MOD_DELETE ) {
3079 if ( c->be->be_syncinfo ) {
3080 re = c->be->be_syncinfo->si_re;
3082 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ))
3083 ldap_pvt_runqueue_stoptask( &slapd_rq, re );
3084 ldap_pvt_runqueue_remove( &slapd_rq, re );
3086 syncinfo_free( c->be->be_syncinfo );
3087 c->be->be_syncinfo = NULL;
3089 SLAP_DBFLAGS(c->be) &= ~(SLAP_DBFLAG_SHADOW|SLAP_DBFLAG_SYNC_SHADOW);
3092 if(SLAP_SHADOW(c->be)) {
3093 Debug(LDAP_DEBUG_ANY, "%s: "
3094 "syncrepl: database already shadowed.\n",
3097 } else if(add_syncrepl(c->be, c->argv, c->argc)) {
3100 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW);