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-2007 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 struct nonpresent_entry {
35 struct berval *npe_name;
36 struct berval *npe_nname;
37 LDAP_LIST_ENTRY(nonpresent_entry) npe_link;
40 #define SYNCDATA_DEFAULT 0 /* entries are plain LDAP entries */
41 #define SYNCDATA_ACCESSLOG 1 /* entries are accesslog format */
42 #define SYNCDATA_CHANGELOG 2 /* entries are changelog format */
44 #define SYNCLOG_LOGGING 0 /* doing a log-based update */
45 #define SYNCLOG_FALLBACK 1 /* doing a full refresh */
47 #define RETRYNUM_FOREVER (-1) /* retry forever */
48 #define RETRYNUM_TAIL (-2) /* end of retrynum array */
49 #define RETRYNUM_VALID(n) ((n) >= RETRYNUM_FOREVER) /* valid retrynum */
50 #define RETRYNUM_FINITE(n) ((n) > RETRYNUM_FOREVER) /* not forever */
52 typedef struct syncinfo_s {
53 struct slap_backend_db *si_be;
56 slap_bindconf si_bindconf;
57 struct berval si_base;
58 struct berval si_logbase;
59 struct berval si_filterstr;
60 struct berval si_logfilterstr;
64 AttributeName *si_anlist;
65 AttributeName *si_exanlist;
70 int si_schemachecking;
71 int si_type; /* the active type */
72 int si_ctype; /* the configured type */
74 time_t *si_retryinterval;
75 int *si_retrynum_init;
77 struct sync_cookie si_syncCookie;
82 int si_refreshPresent;
86 Avlnode *si_presentlist;
88 LDAP_LIST_HEAD(np, nonpresent_entry) si_nonpresentlist;
89 ldap_pvt_thread_mutex_t si_mutex;
92 static int syncuuid_cmp( const void *, const void * );
93 static void avl_ber_bvfree( void * );
94 static void syncrepl_del_nonpresent( Operation *, syncinfo_t *, BerVarray, struct berval * );
95 static int syncrepl_message_to_op(
96 syncinfo_t *, Operation *, LDAPMessage * );
97 static int syncrepl_message_to_entry(
98 syncinfo_t *, Operation *, LDAPMessage *,
99 Modifications **, Entry **, int );
100 static int syncrepl_entry(
101 syncinfo_t *, Operation*, Entry*,
102 Modifications**,int, struct berval*,
103 struct sync_cookie *,
105 static int syncrepl_updateCookie(
106 syncinfo_t *, Operation *, struct berval *,
107 struct sync_cookie * );
108 static struct berval * slap_uuidstr_from_normalized(
109 struct berval *, struct berval *, void * );
111 /* callback functions */
112 static int dn_callback( struct slap_op *, struct slap_rep * );
113 static int nonpresent_callback( struct slap_op *, struct slap_rep * );
114 static int null_callback( struct slap_op *, struct slap_rep * );
116 static AttributeDescription *sync_descs[4];
119 init_syncrepl(syncinfo_t *si)
122 char **attrs, **exattrs;
124 if ( !sync_descs[0] ) {
125 sync_descs[0] = slap_schema.si_ad_objectClass;
126 sync_descs[1] = slap_schema.si_ad_structuralObjectClass;
127 sync_descs[2] = slap_schema.si_ad_entryCSN;
128 sync_descs[3] = NULL;
131 if ( si->si_allattrs && si->si_allopattrs )
134 attrs = anlist2attrs( si->si_anlist );
137 if ( si->si_allattrs ) {
140 if ( !is_at_operational( at_find( attrs[i] ))) {
141 for ( j = i; attrs[j] != NULL; j++ ) {
144 attrs[j] = attrs[j+1];
150 attrs = ( char ** ) ch_realloc( attrs, (i + 2)*sizeof( char * ) );
151 attrs[i] = ch_strdup("*");
154 } else if ( si->si_allopattrs ) {
157 if ( is_at_operational( at_find( attrs[i] ))) {
158 for ( j = i; attrs[j] != NULL; j++ ) {
161 attrs[j] = attrs[j+1];
167 attrs = ( char ** ) ch_realloc( attrs, (i + 2)*sizeof( char * ) );
168 attrs[i] = ch_strdup("+");
172 for ( i = 0; sync_descs[i] != NULL; i++ ) {
175 if ( !strcmp( attrs[j], sync_descs[i]->ad_cname.bv_val )) {
176 for ( k = j; attrs[k] != NULL; k++ ) {
179 attrs[k] = attrs[k+1];
187 for ( n = 0; attrs[ n ] != NULL; n++ ) /* empty */;
189 if ( si->si_allopattrs ) {
190 attrs = ( char ** ) ch_realloc( attrs, (n + 2)*sizeof( char * ));
192 attrs = ( char ** ) ch_realloc( attrs, (n + 4)*sizeof( char * ));
195 if ( attrs == NULL ) {
196 Debug( LDAP_DEBUG_ANY, "out of memory\n", 0, 0, 0 );
200 if ( si->si_allopattrs ) {
201 attrs[n++] = ch_strdup( sync_descs[0]->ad_cname.bv_val );
203 for ( i = 0; sync_descs[ i ] != NULL; i++ ) {
204 attrs[ n++ ] = ch_strdup ( sync_descs[i]->ad_cname.bv_val );
212 if ( si->si_allattrs == si->si_allopattrs ) {
213 attrs = (char**) ch_malloc( 3 * sizeof(char*) );
214 attrs[i++] = ch_strdup( "*" );
215 attrs[i++] = ch_strdup( "+" );
216 } else if ( si->si_allattrs && !si->si_allopattrs ) {
217 for ( n = 0; sync_descs[ n ] != NULL; n++ ) ;
218 attrs = (char**) ch_malloc( (n+1)* sizeof(char*) );
219 attrs[i++] = ch_strdup( "*" );
220 for ( j = 1; sync_descs[ j ] != NULL; j++ ) {
221 attrs[i++] = ch_strdup ( sync_descs[j]->ad_cname.bv_val );
223 } else if ( !si->si_allattrs && si->si_allopattrs ) {
224 attrs = (char**) ch_malloc( 3 * sizeof(char*) );
225 attrs[i++] = ch_strdup( "+" );
226 attrs[i++] = ch_strdup( sync_descs[0]->ad_cname.bv_val );
231 si->si_attrs = attrs;
233 exattrs = anlist2attrs( si->si_exanlist );
236 for ( n = 0; exattrs[n] != NULL; n++ ) ;
238 for ( i = 0; sync_descs[i] != NULL; i++ ) {
240 while ( exattrs[j] != NULL ) {
241 if ( !strcmp( exattrs[j], sync_descs[i]->ad_cname.bv_val )) {
242 ch_free( exattrs[j] );
243 for ( k = j; exattrs[k] != NULL; k++ ) {
244 exattrs[k] = exattrs[k+1];
252 for ( i = 0; exattrs[i] != NULL; i++ ) {
253 for ( j = 0; si->si_anlist[j].an_name.bv_val; j++ ) {
255 if ( ( oc = si->si_anlist[j].an_oc ) ) {
257 while ( oc->soc_required[k] ) {
258 if ( !strcmp( exattrs[i],
259 oc->soc_required[k]->sat_cname.bv_val )) {
260 ch_free( exattrs[i] );
261 for ( l = i; exattrs[l]; l++ ) {
262 exattrs[l] = exattrs[l+1];
272 for ( i = 0; exattrs[i] != NULL; i++ ) ;
275 exattrs = (char **) ch_realloc( exattrs, (i + 1)*sizeof(char *));
278 si->si_exattrs = exattrs;
281 typedef struct logschema {
283 struct berval ls_req;
284 struct berval ls_mod;
285 struct berval ls_newRdn;
286 struct berval ls_delRdn;
287 struct berval ls_newSup;
290 static logschema changelog_sc = {
292 BER_BVC("changeType"),
295 BER_BVC("deleteOldRDN"),
296 BER_BVC("newSuperior")
299 static logschema accesslog_sc = {
303 BER_BVC("reqNewRDN"),
304 BER_BVC("reqDeleteOldRDN"),
305 BER_BVC("reqNewSuperior")
313 BerElementBuffer berbuf;
314 BerElement *ber = (BerElement *)&berbuf;
315 LDAPControl c[2], *ctrls[3];
316 struct timeval timeout;
321 char **attrs, *lattrs[8];
326 /* setup LDAP SYNC control */
327 ber_init2( ber, NULL, LBER_USE_DER );
328 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &ctx );
330 /* If we're using a log but we have no state, then fallback to
331 * normal mode for a full refresh.
333 if ( si->si_syncdata && BER_BVISEMPTY( &si->si_syncCookie.ctxcsn ))
334 si->si_logstate = SYNCLOG_FALLBACK;
336 /* Use the log parameters if we're in log mode */
337 if ( si->si_syncdata && si->si_logstate == SYNCLOG_LOGGING ) {
339 if ( si->si_syncdata == SYNCDATA_ACCESSLOG )
343 lattrs[0] = ls->ls_dn.bv_val;
344 lattrs[1] = ls->ls_req.bv_val;
345 lattrs[2] = ls->ls_mod.bv_val;
346 lattrs[3] = ls->ls_newRdn.bv_val;
347 lattrs[4] = ls->ls_delRdn.bv_val;
348 lattrs[5] = ls->ls_newSup.bv_val;
349 lattrs[6] = slap_schema.si_ad_entryCSN->ad_cname.bv_val;
353 base = si->si_logbase.bv_val;
354 filter = si->si_logfilterstr.bv_val;
357 scope = LDAP_SCOPE_SUBTREE;
360 base = si->si_base.bv_val;
361 filter = si->si_filterstr.bv_val;
362 attrs = si->si_attrs;
363 attrsonly = si->si_attrsonly;
364 scope = si->si_scope;
366 if ( si->si_syncdata && si->si_logstate == SYNCLOG_FALLBACK ) {
367 si->si_type = LDAP_SYNC_REFRESH_ONLY;
369 si->si_type = si->si_ctype;
372 if ( !BER_BVISNULL( &si->si_syncCookie.octet_str ) )
374 ber_printf( ber, "{eOb}",
375 abs(si->si_type), &si->si_syncCookie.octet_str, rhint );
377 ber_printf( ber, "{eb}",
378 abs(si->si_type), rhint );
381 if ( (rc = ber_flatten2( ber, &c[0].ldctl_value, 0 )) == LBER_ERROR ) {
386 c[0].ldctl_oid = LDAP_CONTROL_SYNC;
387 c[0].ldctl_iscritical = si->si_type < 0;
390 if ( !BER_BVISNULL( &si->si_bindconf.sb_authzId ) ) {
391 c[1].ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
392 c[1].ldctl_value = si->si_bindconf.sb_authzId;
393 c[1].ldctl_iscritical = 1;
400 timeout.tv_sec = si->si_tlimit;
403 rc = ldap_search_ext( si->si_ld, base, scope, filter, attrs, attrsonly,
404 ctrls, NULL, si->si_tlimit > 0 ? &timeout : NULL,
405 si->si_slimit, &msgid );
416 int cmdline_cookie_found = 0;
418 struct sync_cookie *sc = NULL;
424 psub = &si->si_be->be_nsuffix[0];
426 rc = slap_client_connect( &si->si_ld, &si->si_bindconf );
427 if ( rc != LDAP_SUCCESS ) {
430 op->o_protocol = LDAP_VERSION3;
432 /* Set SSF to strongest of TLS, SASL SSFs */
435 op->o_transport_ssf = 0;
437 if ( ldap_get_option( si->si_ld, LDAP_OPT_X_TLS_SSL_CTX, &ssl )
438 == LDAP_SUCCESS && ssl != NULL )
440 op->o_tls_ssf = ldap_pvt_tls_get_strength( ssl );
442 #endif /* HAVE_TLS */
443 ldap_get_option( si->si_ld, LDAP_OPT_X_SASL_SSF, &op->o_sasl_ssf );
444 op->o_ssf = ( op->o_sasl_ssf > op->o_tls_ssf )
445 ? op->o_sasl_ssf : op->o_tls_ssf;
448 if ( BER_BVISNULL( &si->si_syncCookie.octet_str )) {
449 /* get contextCSN shadow replica from database */
450 BerVarray csn = NULL;
452 assert( si->si_rid < 1000 );
453 op->o_req_ndn = op->o_bd->be_nsuffix[0];
454 op->o_req_dn = op->o_req_ndn;
456 /* try to read stored contextCSN */
457 backend_attribute( op, NULL, &op->o_req_ndn,
458 slap_schema.si_ad_contextCSN, &csn, ACL_READ );
460 ch_free( si->si_syncCookie.ctxcsn.bv_val );
461 ber_dupbv( &si->si_syncCookie.ctxcsn, csn );
462 ber_bvarray_free_x( csn, op->o_tmpmemctx );
465 si->si_syncCookie.rid = si->si_rid;
467 LDAP_STAILQ_FOREACH( sc, &slap_sync_cookie, sc_next ) {
468 if ( si->si_rid == sc->rid ) {
469 cmdline_cookie_found = 1;
474 if ( cmdline_cookie_found ) {
475 /* cookie is supplied in the command line */
477 LDAP_STAILQ_REMOVE( &slap_sync_cookie, sc, sync_cookie, sc_next );
479 /* ctxcsn wasn't parsed yet, do it now */
480 slap_parse_sync_cookie( sc, op->o_tmpmemctx );
481 if ( BER_BVISNULL( &sc->ctxcsn ) ) {
482 /* if cmdline cookie does not have ctxcsn */
483 /* component, set it to an initial value */
484 slap_init_sync_cookie_ctxcsn( sc );
486 slap_sync_cookie_free( &si->si_syncCookie, 0 );
487 slap_dup_sync_cookie( &si->si_syncCookie, sc );
488 slap_sync_cookie_free( sc, 1 );
491 slap_compose_sync_cookie( NULL, &si->si_syncCookie.octet_str,
492 &si->si_syncCookie.ctxcsn, si->si_syncCookie.rid );
495 rc = ldap_sync_search( si, op->o_tmpmemctx );
497 if( rc != LDAP_SUCCESS ) {
498 Debug( LDAP_DEBUG_ANY, "do_syncrep1: rid %03ld "
499 "ldap_search_ext: %s (%d)\n",
500 si->si_rid, ldap_err2string( rc ), rc );
506 ldap_unbind_ext( si->si_ld, NULL, NULL );
519 LDAPControl **rctrls = NULL;
522 BerElementBuffer berbuf;
523 BerElement *ber = (BerElement *)&berbuf;
525 LDAPMessage *res = NULL;
526 LDAPMessage *msg = NULL;
529 struct berval *retdata = NULL;
534 struct berval syncUUID = BER_BVNULL;
535 struct sync_cookie syncCookie = { BER_BVNULL };
536 struct sync_cookie syncCookie_req = { BER_BVNULL };
537 struct berval cookie = BER_BVNULL;
543 Modifications *modlist = NULL;
548 struct timeval *tout_p = NULL;
549 struct timeval tout = { 0, 0 };
551 int refreshDeletes = 0;
553 BerVarray syncUUIDs = NULL;
556 if ( slapd_shutdown ) {
561 ber_init2( ber, NULL, LBER_USE_DER );
562 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
564 Debug( LDAP_DEBUG_TRACE, "=>do_syncrep2 rid %03ld\n", si->si_rid, 0, 0 );
566 psub = &si->si_be->be_nsuffix[0];
568 slap_dup_sync_cookie( &syncCookie_req, &si->si_syncCookie );
570 if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST ) {
576 while (( rc = ldap_result( si->si_ld, LDAP_RES_ANY, LDAP_MSG_ONE,
577 tout_p, &res )) > 0 )
579 if ( slapd_shutdown ) {
583 for( msg = ldap_first_message( si->si_ld, res );
585 msg = ldap_next_message( si->si_ld, msg ) )
587 if ( slapd_shutdown ) {
591 switch( ldap_msgtype( msg ) ) {
592 case LDAP_RES_SEARCH_ENTRY:
593 ldap_get_entry_controls( si->si_ld, msg, &rctrls );
594 /* we can't work without the control */
597 /* NOTE: make sure we use the right one;
598 * a better approach would be to run thru
599 * the whole list and take care of all */
600 rctrlp = ldap_find_control( LDAP_CONTROL_SYNC_STATE, rctrls );
602 if ( rctrlp == NULL ) {
603 Debug( LDAP_DEBUG_ANY, "do_syncrep2: rid %03ld "
604 "got search entry without "
605 "Sync State control\n", si->si_rid, 0, 0 );
609 ber_init2( ber, &rctrlp->ldctl_value, LBER_USE_DER );
610 ber_scanf( ber, "{em" /*"}"*/, &syncstate, &syncUUID );
611 /* FIXME: what if syncUUID is NULL or empty?
612 * (happens with back-sql...) */
613 if ( BER_BVISEMPTY( &syncUUID ) ) {
614 Debug( LDAP_DEBUG_ANY, "do_syncrep2: rid %03ld "
615 "got empty syncUUID\n", si->si_rid, 0, 0 );
616 ldap_controls_free( rctrls );
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 );
632 if ( si->si_syncdata && si->si_logstate == SYNCLOG_LOGGING ) {
634 if (( rc = syncrepl_message_to_op( si, op, msg )) == LDAP_SUCCESS &&
635 !BER_BVISNULL( &syncCookie.ctxcsn ) ) {
636 rc = syncrepl_updateCookie( si, op, psub, &syncCookie );
638 } else if (( rc = syncrepl_message_to_entry( si, op, msg,
639 &modlist, &entry, syncstate )) == LDAP_SUCCESS ) {
640 if (( rc = syncrepl_entry( si, op, entry, &modlist,
641 syncstate, &syncUUID, &syncCookie_req,
642 &syncCookie.ctxcsn )) == LDAP_SUCCESS &&
643 !BER_BVISNULL( &syncCookie.ctxcsn ) ) {
644 rc = syncrepl_updateCookie( si, op, psub, &syncCookie );
647 ldap_controls_free( rctrls );
649 slap_mods_free( modlist, 1 );
655 case LDAP_RES_SEARCH_REFERENCE:
656 Debug( LDAP_DEBUG_ANY,
657 "do_syncrep2: rid %03ld reference received error\n",
661 case LDAP_RES_SEARCH_RESULT:
662 Debug( LDAP_DEBUG_SYNC,
663 "do_syncrep2: rid %03ld LDAP_RES_SEARCH_RESULT\n",
665 ldap_parse_result( si->si_ld, msg, &err, NULL, NULL, NULL,
667 #ifdef LDAP_X_SYNC_REFRESH_REQUIRED
668 if ( err == LDAP_X_SYNC_REFRESH_REQUIRED ) {
669 /* map old result code to registered code */
670 err = LDAP_SYNC_REFRESH_REQUIRED;
673 if ( err == LDAP_SYNC_REFRESH_REQUIRED ) {
674 if ( si->si_logstate == SYNCLOG_LOGGING ) {
675 si->si_logstate = SYNCLOG_FALLBACK;
682 ber_init2( ber, &rctrlp->ldctl_value, LBER_USE_DER );
684 ber_scanf( ber, "{" /*"}"*/);
685 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
686 ber_scanf( ber, "m", &cookie );
687 if ( !BER_BVISNULL( &cookie ) ) {
688 ch_free( syncCookie.octet_str.bv_val );
689 ber_dupbv( &syncCookie.octet_str, &cookie);
691 if ( !BER_BVISNULL( &syncCookie.octet_str ) )
693 slap_parse_sync_cookie( &syncCookie, NULL );
696 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_REFRESHDELETES )
698 ber_scanf( ber, "b", &refreshDeletes );
700 ber_scanf( ber, /*"{"*/ "}" );
702 if ( BER_BVISNULL( &syncCookie_req.ctxcsn )) {
704 } else if ( BER_BVISNULL( &syncCookie.ctxcsn )) {
707 value_match( &match, slap_schema.si_ad_entryCSN,
708 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
709 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
710 &syncCookie_req.ctxcsn, &syncCookie.ctxcsn,
714 ldap_controls_free( rctrls );
716 if (si->si_type != LDAP_SYNC_REFRESH_AND_PERSIST) {
717 /* FIXME : different error behaviors according to
718 * 1) err code : LDAP_BUSY ...
719 * 2) on err policy : stop service, stop sync, retry
721 if ( refreshDeletes == 0 && match < 0 &&
722 err == LDAP_SUCCESS )
724 syncrepl_del_nonpresent( op, si, NULL, &syncCookie.ctxcsn );
726 avl_free( si->si_presentlist, avl_ber_bvfree );
727 si->si_presentlist = NULL;
730 if ( !BER_BVISNULL( &syncCookie.ctxcsn ) &&
731 match < 0 && err == LDAP_SUCCESS )
733 rc = syncrepl_updateCookie( si, op, psub, &syncCookie );
735 if ( err == LDAP_SUCCESS
736 && si->si_logstate == SYNCLOG_FALLBACK ) {
737 si->si_logstate = SYNCLOG_LOGGING;
738 rc = LDAP_SYNC_REFRESH_REQUIRED;
745 case LDAP_RES_INTERMEDIATE:
746 rc = ldap_parse_intermediate( si->si_ld, msg,
747 &retoid, &retdata, NULL, 0 );
748 if ( !rc && !strcmp( retoid, LDAP_SYNC_INFO ) ) {
749 ber_init2( ber, retdata, LBER_USE_DER );
751 switch ( si_tag = ber_peek_tag( ber, &len )) {
753 case LDAP_TAG_SYNC_NEW_COOKIE:
754 Debug( LDAP_DEBUG_SYNC,
755 "do_syncrep2: rid %03ld %s - %s\n",
757 "LDAP_RES_INTERMEDIATE",
759 ber_scanf( ber, "tm", &tag, &cookie );
761 case LDAP_TAG_SYNC_REFRESH_DELETE:
762 case LDAP_TAG_SYNC_REFRESH_PRESENT:
763 Debug( LDAP_DEBUG_SYNC,
764 "do_syncrep2: rid %03ld %s - %s\n",
766 "LDAP_RES_INTERMEDIATE",
767 si_tag == LDAP_TAG_SYNC_REFRESH_PRESENT ?
768 "REFRESH_PRESENT" : "REFRESH_DELETE" );
769 if ( si_tag == LDAP_TAG_SYNC_REFRESH_DELETE ) {
770 si->si_refreshDelete = 1;
772 si->si_refreshPresent = 1;
774 ber_scanf( ber, "t{" /*"}"*/, &tag );
775 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE )
777 ber_scanf( ber, "m", &cookie );
778 if ( !BER_BVISNULL( &cookie ) ) {
779 ch_free( syncCookie.octet_str.bv_val );
780 ber_dupbv( &syncCookie.octet_str, &cookie );
782 if ( !BER_BVISNULL( &syncCookie.octet_str ) )
784 slap_parse_sync_cookie( &syncCookie, NULL );
787 if ( ber_peek_tag( ber, &len ) ==
788 LDAP_TAG_REFRESHDONE )
790 ber_scanf( ber, "b", &refreshDone );
792 ber_scanf( ber, /*"{"*/ "}" );
794 case LDAP_TAG_SYNC_ID_SET:
795 Debug( LDAP_DEBUG_SYNC,
796 "do_syncrep2: rid %03ld %s - %s\n",
798 "LDAP_RES_INTERMEDIATE",
800 ber_scanf( ber, "t{" /*"}"*/, &tag );
801 if ( ber_peek_tag( ber, &len ) ==
802 LDAP_TAG_SYNC_COOKIE )
804 ber_scanf( ber, "m", &cookie );
805 if ( !BER_BVISNULL( &cookie ) ) {
806 ch_free( syncCookie.octet_str.bv_val );
807 ber_dupbv( &syncCookie.octet_str, &cookie );
809 if ( !BER_BVISNULL( &syncCookie.octet_str ) )
811 slap_parse_sync_cookie( &syncCookie, NULL );
814 if ( ber_peek_tag( ber, &len ) ==
815 LDAP_TAG_REFRESHDELETES )
817 ber_scanf( ber, "b", &refreshDeletes );
819 ber_scanf( ber, "[W]", &syncUUIDs );
820 ber_scanf( ber, /*"{"*/ "}" );
821 if ( refreshDeletes ) {
822 syncrepl_del_nonpresent( op, si, syncUUIDs,
823 &syncCookie.ctxcsn );
824 ber_bvarray_free_x( syncUUIDs, op->o_tmpmemctx );
827 for ( i = 0; !BER_BVISNULL( &syncUUIDs[i] ); i++ ) {
828 struct berval *syncuuid_bv;
829 syncuuid_bv = ber_dupbv( NULL, &syncUUIDs[i] );
830 slap_sl_free( syncUUIDs[i].bv_val,op->o_tmpmemctx );
831 avl_insert( &si->si_presentlist,
832 (caddr_t) syncuuid_bv,
833 syncuuid_cmp, avl_dup_error );
835 slap_sl_free( syncUUIDs, op->o_tmpmemctx );
837 slap_sync_cookie_free( &syncCookie, 0 );
840 Debug( LDAP_DEBUG_ANY,
841 "do_syncrep2: rid %03ld unknown syncinfo tag (%ld)\n",
842 si->si_rid, (long) si_tag, 0 );
843 ldap_memfree( retoid );
844 ber_bvfree( retdata );
848 if ( BER_BVISNULL( &syncCookie_req.ctxcsn )) {
850 } else if ( BER_BVISNULL( &syncCookie.ctxcsn )) {
853 value_match( &match, slap_schema.si_ad_entryCSN,
854 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
855 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
856 &syncCookie_req.ctxcsn,
857 &syncCookie.ctxcsn, &text );
861 if ( si->si_refreshPresent == 1 ) {
862 syncrepl_del_nonpresent( op, si, NULL, &syncCookie.ctxcsn );
865 if ( !BER_BVISNULL( &syncCookie.ctxcsn ))
867 rc = syncrepl_updateCookie( si, op, psub, &syncCookie);
871 ldap_memfree( retoid );
872 ber_bvfree( retdata );
876 Debug( LDAP_DEBUG_ANY, "do_syncrep2: rid %03ld "
877 "unknown intermediate response (%d)\n",
879 ldap_memfree( retoid );
880 ber_bvfree( retdata );
886 Debug( LDAP_DEBUG_ANY, "do_syncrep2: rid %03ld "
887 "unknown message\n", si->si_rid, 0, 0 );
891 if ( !BER_BVISNULL( &syncCookie.octet_str )) {
892 slap_sync_cookie_free( &syncCookie_req, 0 );
893 slap_dup_sync_cookie( &syncCookie_req, &syncCookie );
894 slap_sync_cookie_free( &syncCookie, 0 );
904 ldap_get_option( si->si_ld, LDAP_OPT_ERROR_NUMBER, &rc );
905 errstr = ldap_err2string( rc );
907 Debug( LDAP_DEBUG_ANY,
908 "do_syncrep2: rid %03ld %s\n", si->si_rid, errstr, 0 );
912 slap_sync_cookie_free( &syncCookie, 0 );
913 slap_sync_cookie_free( &syncCookie_req, 0 );
915 if ( res ) ldap_msgfree( res );
917 if ( rc && rc != LDAP_SYNC_REFRESH_REQUIRED && si->si_ld ) {
918 if ( si->si_conn_setup ) {
920 ldap_get_option( si->si_ld, LDAP_OPT_DESC, &s );
921 connection_client_stop( s );
922 si->si_conn_setup = 0;
924 ldap_unbind_ext( si->si_ld, NULL, NULL );
936 struct re_s* rtask = arg;
937 syncinfo_t *si = ( syncinfo_t * ) rtask->arg;
938 Connection conn = {0};
939 OperationBuffer opbuf;
941 int rc = LDAP_SUCCESS;
947 Debug( LDAP_DEBUG_TRACE, "=>do_syncrepl rid %03ld\n", si->si_rid, 0, 0 );
952 ldap_pvt_thread_mutex_lock( &si->si_mutex );
954 switch( abs( si->si_type )) {
955 case LDAP_SYNC_REFRESH_ONLY:
956 case LDAP_SYNC_REFRESH_AND_PERSIST:
959 ldap_pvt_thread_mutex_unlock( &si->si_mutex );
963 if ( slapd_shutdown ) {
965 if ( si->si_conn_setup ) {
966 ldap_get_option( si->si_ld, LDAP_OPT_DESC, &s );
967 connection_client_stop( s );
968 si->si_conn_setup = 0;
970 ldap_unbind_ext( si->si_ld, NULL, NULL );
973 ldap_pvt_thread_mutex_unlock( &si->si_mutex );
977 op = (Operation *) &opbuf;
978 connection_fake_init( &conn, op, ctx );
980 /* use global malloc for now */
981 op->o_tmpmemctx = NULL;
982 op->o_tmpmfuncs = &ch_mfuncs;
984 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
985 op->o_bd = be = si->si_be;
986 op->o_dn = op->o_bd->be_rootdn;
987 op->o_ndn = op->o_bd->be_rootndn;
988 if ( !si->si_schemachecking )
989 op->o_no_schema_check = 1;
991 /* Establish session, do search */
993 si->si_refreshDelete = 0;
994 si->si_refreshPresent = 0;
995 rc = do_syncrep1( op, si );
999 /* Process results */
1000 if ( rc == LDAP_SUCCESS ) {
1001 ldap_get_option( si->si_ld, LDAP_OPT_DESC, &s );
1003 rc = do_syncrep2( op, si );
1004 if ( rc == LDAP_SYNC_REFRESH_REQUIRED ) {
1005 rc = ldap_sync_search( si, op->o_tmpmemctx );
1009 if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST ) {
1010 /* If we succeeded, enable the connection for further listening.
1011 * If we failed, tear down the connection and reschedule.
1013 if ( rc == LDAP_SUCCESS ) {
1014 if ( si->si_conn_setup ) {
1015 connection_client_enable( s );
1017 rc = connection_client_setup( s, do_syncrepl, arg );
1019 si->si_conn_setup = 1;
1021 } else if ( si->si_conn_setup ) {
1025 if ( rc == -2 ) rc = 0;
1029 /* At this point, we have 4 cases:
1030 * 1) for any hard failure, give up and remove this task
1031 * 2) for ServerDown, reschedule this task to run
1032 * 3) for Refresh and Success, reschedule to run
1033 * 4) for Persist and Success, reschedule to defer
1035 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
1037 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, rtask )) {
1038 ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
1042 connection_client_stop( s );
1045 if ( rc == LDAP_SUCCESS ) {
1046 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
1049 rtask->interval.tv_sec = si->si_interval;
1050 ldap_pvt_runqueue_resched( &slapd_rq, rtask, defer );
1051 if ( si->si_retrynum ) {
1052 for ( i = 0; si->si_retrynum_init[i] != RETRYNUM_TAIL; i++ ) {
1053 si->si_retrynum[i] = si->si_retrynum_init[i];
1055 si->si_retrynum[i] = RETRYNUM_TAIL;
1058 for ( i = 0; si->si_retrynum && si->si_retrynum[i] <= 0; i++ ) {
1059 if ( si->si_retrynum[i] == RETRYNUM_FOREVER || si->si_retrynum[i] == RETRYNUM_TAIL )
1063 if ( !si->si_retrynum || si->si_retrynum[i] == RETRYNUM_TAIL ) {
1064 ldap_pvt_runqueue_remove( &slapd_rq, rtask );
1065 } else if ( RETRYNUM_VALID( si->si_retrynum[i] ) ) {
1066 if ( si->si_retrynum[i] > 0 )
1067 si->si_retrynum[i]--;
1068 rtask->interval.tv_sec = si->si_retryinterval[i];
1069 ldap_pvt_runqueue_resched( &slapd_rq, rtask, 0 );
1070 slap_wake_listener();
1074 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
1075 ldap_pvt_thread_mutex_unlock( &si->si_mutex );
1080 static slap_verbmasks modops[] = {
1081 { BER_BVC("add"), LDAP_REQ_ADD },
1082 { BER_BVC("delete"), LDAP_REQ_DELETE },
1083 { BER_BVC("modify"), LDAP_REQ_MODIFY },
1084 { BER_BVC("modrdn"), LDAP_REQ_MODRDN},
1088 static Modifications *
1089 syncrepl_accesslog_mods(
1096 AttributeDescription *ad;
1097 struct berval bv, bv2;
1099 Modifications *mod = NULL, *modlist = NULL, **modtail;
1104 for (i=0; !BER_BVISNULL( &vals[i] ); i++) {
1108 colon = ber_bvchr( &bv, ':' );
1110 continue; /* invalid */
1111 bv.bv_len = colon - bv.bv_val;
1112 if ( slap_bv2ad( &bv, &ad, &text )) {
1116 /* Ignore dynamically generated attrs */
1117 if ( ad->ad_type->sat_flags & SLAP_AT_DYNAMIC )
1119 /* Ignore excluded attrs */
1120 if ( ldap_charray_inlist( si->si_exattrs,
1121 ad->ad_type->sat_cname.bv_val ))
1125 case '+': op = LDAP_MOD_ADD; break;
1126 case '-': op = LDAP_MOD_DELETE; break;
1127 case '=': op = LDAP_MOD_REPLACE; break;
1128 case '#': op = LDAP_MOD_INCREMENT; break;
1132 if ( !mod || ad != mod->sml_desc || op != mod->sml_op ) {
1133 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
1136 mod->sml_next = NULL;
1138 mod->sml_type = ad->ad_cname;
1139 mod->sml_values = NULL;
1140 mod->sml_nvalues = NULL;
1143 modtail = &mod->sml_next;
1145 if ( colon[2] == ' ' ) {
1146 bv.bv_val = colon + 3;
1147 bv.bv_len = vals[i].bv_len - ( bv.bv_val - vals[i].bv_val );
1148 ber_dupbv( &bv2, &bv );
1149 ber_bvarray_add( &mod->sml_values, &bv2 );
1155 static Modifications *
1156 syncrepl_changelog_mods(
1161 return NULL; /* FIXME */
1165 syncrepl_message_to_op(
1171 BerElement *ber = NULL;
1172 Modifications *modlist = NULL;
1174 SlapReply rs = { REP_RESULT };
1175 slap_callback cb = { NULL, null_callback, NULL, NULL };
1178 char txtbuf[SLAP_TEXT_BUFLEN];
1179 size_t textlen = sizeof txtbuf;
1181 struct berval bdn, dn = BER_BVNULL, ndn;
1182 struct berval bv, *bvals = NULL;
1183 struct berval rdn = BER_BVNULL, sup = BER_BVNULL,
1184 prdn = BER_BVNULL, nrdn = BER_BVNULL,
1185 psup = BER_BVNULL, nsup = BER_BVNULL;
1186 int rc, deleteOldRdn = 0, freeReqDn = 0;
1188 if ( ldap_msgtype( msg ) != LDAP_RES_SEARCH_ENTRY ) {
1189 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_op: rid %03ld "
1190 "Message type should be entry (%d)",
1191 si->si_rid, ldap_msgtype( msg ), 0 );
1195 if ( si->si_syncdata == SYNCDATA_ACCESSLOG )
1200 rc = ldap_get_dn_ber( si->si_ld, msg, &ber, &bdn );
1202 if ( rc != LDAP_SUCCESS ) {
1203 Debug( LDAP_DEBUG_ANY,
1204 "syncrepl_message_to_op: rid %03ld dn get failed (%d)",
1205 si->si_rid, rc, 0 );
1209 op->o_tag = LBER_DEFAULT;
1211 while (( rc = ldap_get_attribute_ber( si->si_ld, msg, ber, &bv, &bvals ))
1213 if ( bv.bv_val == NULL )
1216 if ( !ber_bvstrcasecmp( &bv, &ls->ls_dn )) {
1218 dnPrettyNormal( NULL, &bdn, &dn, &ndn, op->o_tmpmemctx );
1219 ber_dupbv( &op->o_req_dn, &dn );
1220 ber_dupbv( &op->o_req_ndn, &ndn );
1221 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1222 slap_sl_free( dn.bv_val, op->o_tmpmemctx );
1224 } else if ( !ber_bvstrcasecmp( &bv, &ls->ls_req )) {
1225 int i = verb_to_mask( bvals[0].bv_val, modops );
1227 Debug( LDAP_DEBUG_ANY,
1228 "syncrepl_message_to_op: rid %03ld unknown op %s",
1229 si->si_rid, bvals[0].bv_val, 0 );
1234 op->o_tag = modops[i].mask;
1235 } else if ( !ber_bvstrcasecmp( &bv, &ls->ls_mod )) {
1236 /* Parse attribute into modlist */
1237 if ( si->si_syncdata == SYNCDATA_ACCESSLOG )
1238 modlist = syncrepl_accesslog_mods( si, bvals );
1240 modlist = syncrepl_changelog_mods( si, bvals );
1241 } else if ( !ber_bvstrcasecmp( &bv, &ls->ls_newRdn )) {
1243 } else if ( !ber_bvstrcasecmp( &bv, &ls->ls_delRdn )) {
1244 if ( !ber_bvstrcasecmp( &slap_true_bv, bvals ))
1246 } else if ( !ber_bvstrcasecmp( &bv, &ls->ls_newSup )) {
1248 } else if ( !ber_bvstrcasecmp( &bv,
1249 &slap_schema.si_ad_entryCSN->ad_cname )) {
1250 slap_queue_csn( op, bvals );
1255 /* If we didn't get a mod type or a target DN, bail out */
1256 if ( op->o_tag == LBER_DEFAULT || BER_BVISNULL( &dn )) {
1261 op->o_callback = &cb;
1262 slap_op_time( &op->o_time, &op->o_tincr );
1264 switch( op->o_tag ) {
1266 case LDAP_REQ_MODIFY:
1267 /* If we didn't get required data, bail */
1268 if ( !modlist ) goto done;
1270 rc = slap_mods_check( op, modlist, &text, txtbuf, textlen, NULL );
1272 if ( rc != LDAP_SUCCESS ) {
1273 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_op: rid %03ld "
1274 "mods check (%s)\n",
1275 si->si_rid, text, 0 );
1279 if ( op->o_tag == LDAP_REQ_ADD ) {
1280 Entry *e = entry_alloc();
1282 op->ora_e->e_name = op->o_req_dn;
1283 op->ora_e->e_nname = op->o_req_ndn;
1285 rc = slap_mods2entry( modlist, &op->ora_e, 1, 0, &text, txtbuf, textlen);
1286 if( rc != LDAP_SUCCESS ) {
1287 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_op: rid %03ld "
1288 "mods2entry (%s)\n",
1289 si->si_rid, text, 0 );
1291 rc = op->o_bd->be_add( op, &rs );
1292 Debug( LDAP_DEBUG_SYNC,
1293 "syncrepl_message_to_op: rid %03ld be_add %s (%d)\n",
1294 si->si_rid, op->o_req_dn.bv_val, rc );
1296 if ( e == op->ora_e )
1297 be_entry_release_w( op, op->ora_e );
1299 op->orm_modlist = modlist;
1300 rc = op->o_bd->be_modify( op, &rs );
1301 Debug( rc ? LDAP_DEBUG_ANY : LDAP_DEBUG_SYNC,
1302 "syncrepl_message_to_op: rid %03ld be_modify %s (%d)\n",
1303 si->si_rid, op->o_req_dn.bv_val, rc );
1306 case LDAP_REQ_MODRDN:
1307 if ( BER_BVISNULL( &rdn )) goto done;
1309 if ( rdnPretty( NULL, &rdn, &prdn, NULL ))
1311 if ( rdnNormalize( 0, NULL, NULL, &rdn, &nrdn, NULL ))
1313 if ( !BER_BVISNULL( &sup )) {
1314 if ( dnPrettyNormal( NULL, &sup, &psup, &nsup, NULL ))
1316 op->orr_newSup = &psup;
1317 op->orr_nnewSup = ⊅
1319 op->orr_newSup = NULL;
1320 op->orr_nnewSup = NULL;
1322 op->orr_newrdn = prdn;
1323 op->orr_nnewrdn = nrdn;
1324 op->orr_deleteoldrdn = deleteOldRdn;
1325 op->orr_modlist = NULL;
1326 if ( slap_modrdn2mods( op, &rs ))
1328 /* FIXME: append entryCSN, modifiersName, modifyTimestamp to
1329 * modlist here. Should accesslog give these to us in a reqMod?
1331 rc = op->o_bd->be_modrdn( op, &rs );
1332 slap_mods_free( op->orr_modlist, 1 );
1333 Debug( rc ? LDAP_DEBUG_ANY : LDAP_DEBUG_SYNC,
1334 "syncrepl_message_to_op: rid %03ld be_modrdn %s (%d)\n",
1335 si->si_rid, op->o_req_dn.bv_val, rc );
1337 case LDAP_REQ_DELETE:
1338 rc = op->o_bd->be_delete( op, &rs );
1339 Debug( rc ? LDAP_DEBUG_ANY : LDAP_DEBUG_SYNC,
1340 "syncrepl_message_to_op: rid %03ld be_delete %s (%d)\n",
1341 si->si_rid, op->o_req_dn.bv_val, rc );
1345 slap_graduate_commit_csn( op );
1346 op->o_tmpfree( op->o_csn.bv_val, op->o_tmpmemctx );
1347 BER_BVZERO( &op->o_csn );
1349 slap_mods_free( modlist, op->o_tag != LDAP_REQ_ADD );
1350 if ( !BER_BVISNULL( &rdn )) {
1351 if ( !BER_BVISNULL( &nsup ))
1352 ch_free( nsup.bv_val );
1353 if ( !BER_BVISNULL( &psup ))
1354 ch_free( psup.bv_val );
1355 if ( !BER_BVISNULL( &nrdn ))
1356 ch_free( nrdn.bv_val );
1357 if ( !BER_BVISNULL( &prdn ))
1358 ch_free( prdn.bv_val );
1361 ch_free( op->o_req_ndn.bv_val );
1362 ch_free( op->o_req_dn.bv_val );
1364 ber_free ( ber, 0 );
1369 syncrepl_message_to_entry(
1373 Modifications **modlist,
1379 BerElement *ber = NULL;
1382 Modifications **modtail = modlist;
1385 char txtbuf[SLAP_TEXT_BUFLEN];
1386 size_t textlen = sizeof txtbuf;
1388 struct berval bdn = BER_BVNULL, dn, ndn;
1393 if ( ldap_msgtype( msg ) != LDAP_RES_SEARCH_ENTRY ) {
1394 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: rid %03ld "
1395 "Message type should be entry (%d)",
1396 si->si_rid, ldap_msgtype( msg ), 0 );
1400 op->o_tag = LDAP_REQ_ADD;
1402 rc = ldap_get_dn_ber( si->si_ld, msg, &ber, &bdn );
1403 if ( rc != LDAP_SUCCESS ) {
1404 Debug( LDAP_DEBUG_ANY,
1405 "syncrepl_message_to_entry: rid %03ld dn get failed (%d)",
1406 si->si_rid, rc, 0 );
1410 dnPrettyNormal( NULL, &bdn, &dn, &ndn, op->o_tmpmemctx );
1411 ber_dupbv( &op->o_req_dn, &dn );
1412 ber_dupbv( &op->o_req_ndn, &ndn );
1413 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1414 slap_sl_free( dn.bv_val, op->o_tmpmemctx );
1416 if ( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_DELETE ) {
1417 /* NOTE: this could be done even before decoding the DN,
1418 * although encoding errors wouldn't be detected */
1423 if ( entry == NULL ) {
1429 e->e_name = op->o_req_dn;
1430 e->e_nname = op->o_req_ndn;
1432 while ( ber_remaining( ber ) ) {
1433 if ( (ber_scanf( ber, "{mW}", &tmp.sml_type, &tmp.sml_values ) ==
1434 LBER_ERROR ) || BER_BVISNULL( &tmp.sml_type ) )
1439 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
1441 mod->sml_op = LDAP_MOD_REPLACE;
1443 mod->sml_next = NULL;
1444 mod->sml_desc = NULL;
1445 mod->sml_type = tmp.sml_type;
1446 mod->sml_values = tmp.sml_values;
1447 mod->sml_nvalues = NULL;
1450 modtail = &mod->sml_next;
1453 if ( *modlist == NULL ) {
1454 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: rid %03ld no attributes\n",
1460 rc = slap_mods_check( op, *modlist, &text, txtbuf, textlen, NULL );
1462 if ( rc != LDAP_SUCCESS ) {
1463 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: rid %03ld mods check (%s)\n",
1464 si->si_rid, text, 0 );
1468 /* Strip out dynamically generated attrs */
1469 for ( modtail = modlist; *modtail ; ) {
1471 if ( mod->sml_desc->ad_type->sat_flags & SLAP_AT_DYNAMIC ) {
1472 *modtail = mod->sml_next;
1473 slap_mod_free( &mod->sml_mod, 0 );
1476 modtail = &mod->sml_next;
1480 /* Strip out attrs in exattrs list */
1481 for ( modtail = modlist; *modtail ; ) {
1483 if ( ldap_charray_inlist( si->si_exattrs,
1484 mod->sml_desc->ad_type->sat_cname.bv_val )) {
1485 *modtail = mod->sml_next;
1486 slap_mod_free( &mod->sml_mod, 0 );
1489 modtail = &mod->sml_next;
1493 rc = slap_mods2entry( *modlist, &e, 1, 1, &text, txtbuf, textlen);
1494 if( rc != LDAP_SUCCESS ) {
1495 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: rid %03ld mods2entry (%s)\n",
1496 si->si_rid, text, 0 );
1501 if ( rc != LDAP_SUCCESS ) {
1512 static struct berval generic_filterstr = BER_BVC("(objectclass=*)");
1514 /* During a refresh, we may get an LDAP_SYNC_ADD for an already existing
1515 * entry if a previous refresh was interrupted before sending us a new
1516 * context state. We try to compare the new entry to the existing entry
1517 * and ignore the new entry if they are the same.
1519 * Also, we may get an update where the entryDN has changed, due to
1520 * a ModDn on the provider. We detect this as well, so we can issue
1521 * the corresponding operation locally.
1523 * In the case of a modify, we get a list of all the attributes
1524 * in the original entry. Rather than deleting the entry and re-adding it,
1525 * we issue a Modify request that deletes all the attributes and adds all
1526 * the new ones. This avoids the issue of trying to delete/add a non-leaf
1529 * We otherwise distinguish ModDN from Modify; in the case of
1530 * a ModDN we just use the CSN, modifyTimestamp and modifiersName
1531 * operational attributes from the entry, and do a regular ModDN.
1533 typedef struct dninfo {
1537 int renamed; /* Was an existing entry renamed? */
1538 int delOldRDN; /* Was old RDN deleted? */
1539 Modifications **modlist; /* the modlist we received */
1540 Modifications *mods; /* the modlist we compared */
1548 Modifications** modlist,
1550 struct berval* syncUUID,
1551 struct sync_cookie* syncCookie_req,
1552 struct berval* syncCSN )
1554 Backend *be = op->o_bd;
1555 slap_callback cb = { NULL, NULL, NULL, NULL };
1556 struct berval *syncuuid_bv = NULL;
1557 struct berval syncUUID_strrep = BER_BVNULL;
1558 struct berval uuid_bv = BER_BVNULL;
1560 SlapReply rs_search = {REP_RESULT};
1561 SlapReply rs_delete = {REP_RESULT};
1562 SlapReply rs_add = {REP_RESULT};
1563 SlapReply rs_modify = {REP_RESULT};
1565 #ifdef LDAP_COMP_MATCH
1566 AttributeAssertion ava = { NULL, BER_BVNULL, NULL };
1568 AttributeAssertion ava = { NULL, BER_BVNULL };
1570 int rc = LDAP_SUCCESS;
1572 struct berval pdn = BER_BVNULL;
1576 switch( syncstate ) {
1577 case LDAP_SYNC_PRESENT:
1578 Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03ld %s\n",
1580 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_PRESENT)", 0 );
1583 Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03ld %s\n",
1585 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_ADD)", 0 );
1587 case LDAP_SYNC_DELETE:
1588 Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03ld %s\n",
1590 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_DELETE)", 0 );
1592 case LDAP_SYNC_MODIFY:
1593 Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03ld %s\n",
1595 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_MODIFY)", 0 );
1598 Debug( LDAP_DEBUG_ANY, "syncrepl_entry: rid %03ld %s\n",
1600 "LDAP_RES_SEARCH_ENTRY(UNKNOWN syncstate)", 0 );
1603 if (( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD )) {
1604 if ( !si->si_refreshPresent ) {
1605 syncuuid_bv = ber_dupbv( NULL, syncUUID );
1606 avl_insert( &si->si_presentlist, (caddr_t) syncuuid_bv,
1607 syncuuid_cmp, avl_dup_error );
1611 if ( syncstate == LDAP_SYNC_PRESENT ) {
1613 } else if ( syncstate != LDAP_SYNC_DELETE ) {
1614 if ( entry == NULL ) {
1619 (void)slap_uuidstr_from_normalized( &syncUUID_strrep, syncUUID, op->o_tmpmemctx );
1620 if ( syncstate != LDAP_SYNC_DELETE ) {
1621 Attribute *a = attr_find( entry->e_attrs, slap_schema.si_ad_entryUUID );
1624 /* add if missing */
1625 attr_merge_one( entry, slap_schema.si_ad_entryUUID,
1626 &syncUUID_strrep, syncUUID );
1628 } else if ( !bvmatch( &a->a_nvals[0], syncUUID ) ) {
1629 /* replace only if necessary */
1630 if ( a->a_nvals != a->a_vals ) {
1631 ber_memfree( a->a_nvals[0].bv_val );
1632 ber_dupbv( &a->a_nvals[0], syncUUID );
1634 ber_memfree( a->a_vals[0].bv_val );
1635 ber_dupbv( &a->a_vals[0], &syncUUID_strrep );
1639 f.f_choice = LDAP_FILTER_EQUALITY;
1641 ava.aa_desc = slap_schema.si_ad_entryUUID;
1642 ava.aa_value = *syncUUID;
1644 if ( syncuuid_bv ) {
1645 Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03ld inserted UUID %s\n",
1646 si->si_rid, syncUUID_strrep.bv_val, 0 );
1648 op->ors_filter = &f;
1650 op->ors_filterstr.bv_len = STRLENOF( "(entryUUID=)" ) + syncUUID_strrep.bv_len;
1651 op->ors_filterstr.bv_val = (char *) slap_sl_malloc(
1652 op->ors_filterstr.bv_len + 1, op->o_tmpmemctx );
1653 AC_MEMCPY( op->ors_filterstr.bv_val, "(entryUUID=", STRLENOF( "(entryUUID=" ) );
1654 AC_MEMCPY( &op->ors_filterstr.bv_val[STRLENOF( "(entryUUID=" )],
1655 syncUUID_strrep.bv_val, syncUUID_strrep.bv_len );
1656 op->ors_filterstr.bv_val[op->ors_filterstr.bv_len - 1] = ')';
1657 op->ors_filterstr.bv_val[op->ors_filterstr.bv_len] = '\0';
1659 op->o_tag = LDAP_REQ_SEARCH;
1660 op->ors_scope = LDAP_SCOPE_SUBTREE;
1661 op->ors_deref = LDAP_DEREF_NEVER;
1663 /* get the entry for this UUID */
1664 op->o_req_dn = si->si_base;
1665 op->o_req_ndn = si->si_base;
1667 op->o_time = slap_get_time();
1668 op->ors_tlimit = SLAP_NO_LIMIT;
1671 op->ors_attrs = slap_anlist_all_attributes;
1672 op->ors_attrsonly = 0;
1674 /* set callback function */
1675 op->o_callback = &cb;
1676 cb.sc_response = dn_callback;
1677 cb.sc_private = &dni;
1678 dni.new_entry = entry;
1679 dni.modlist = modlist;
1681 if ( limits_check( op, &rs_search ) == 0 ) {
1682 rc = be->be_search( op, &rs_search );
1683 Debug( LDAP_DEBUG_SYNC,
1684 "syncrepl_entry: rid %03ld be_search (%d)\n",
1685 si->si_rid, rc, 0 );
1688 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
1689 slap_sl_free( op->ors_filterstr.bv_val, op->o_tmpmemctx );
1692 cb.sc_response = null_callback;
1695 if ( entry && !BER_BVISNULL( &entry->e_name ) ) {
1696 Debug( LDAP_DEBUG_SYNC,
1697 "syncrepl_entry: rid %03ld %s\n",
1698 si->si_rid, entry->e_name.bv_val, 0 );
1700 Debug( LDAP_DEBUG_SYNC,
1701 "syncrepl_entry: rid %03ld %s\n",
1702 si->si_rid, dni.dn.bv_val ? dni.dn.bv_val : "(null)", 0 );
1705 /* Don't save the contextCSN on the inooming context entry,
1706 * we'll write it when syncrepl_updateCookie eventually
1707 * gets called. (ITS#4622)
1709 if ( syncstate == LDAP_SYNC_ADD && dn_match( &entry->e_nname,
1710 &be->be_nsuffix[0] )) {
1712 for ( ap = &entry->e_attrs; *ap; ap=&(*ap)->a_next ) {
1714 if ( a->a_desc == slap_schema.si_ad_contextCSN ) {
1722 slap_op_time( &op->o_time, &op->o_tincr );
1723 switch ( syncstate ) {
1725 case LDAP_SYNC_MODIFY:
1727 Attribute *a = attr_find( entry->e_attrs, slap_schema.si_ad_entryCSN );
1729 /* FIXME: op->o_csn is assumed to be
1730 * on the thread's slab; this needs
1731 * to be cleared ASAP.
1732 * What happens if already present?
1734 assert( BER_BVISNULL( &op->o_csn ) );
1735 op->o_csn = a->a_vals[0];
1739 if ( BER_BVISNULL( &dni.dn )) {
1741 op->o_req_dn = entry->e_name;
1742 op->o_req_ndn = entry->e_nname;
1743 op->o_tag = LDAP_REQ_ADD;
1746 rc = be->be_add( op, &rs_add );
1747 Debug( LDAP_DEBUG_SYNC,
1748 "syncrepl_entry: rid %03ld be_add (%d)\n",
1749 si->si_rid, rc, 0 );
1750 switch ( rs_add.sr_err ) {
1752 if ( op->ora_e == entry )
1753 be_entry_release_w( op, entry );
1758 /* we assume that LDAP_NO_SUCH_OBJECT is returned
1759 * only if the suffix entry is not present */
1760 case LDAP_NO_SUCH_OBJECT:
1761 rc = syncrepl_add_glue( op, entry );
1765 /* if an entry was added via syncrepl_add_glue(),
1766 * it likely has no entryUUID, so the previous
1767 * be_search() doesn't find it. In this case,
1768 * give syncrepl a chance to modify it. Also
1769 * allow for entries that were recreated with the
1770 * same DN but a different entryUUID.
1772 case LDAP_ALREADY_EXISTS:
1774 Operation op2 = *op;
1775 SlapReply rs2 = { 0 };
1776 slap_callback cb2 = { 0 };
1778 op2.o_tag = LDAP_REQ_SEARCH;
1779 op2.o_req_dn = entry->e_name;
1780 op2.o_req_ndn = entry->e_nname;
1781 op2.ors_scope = LDAP_SCOPE_BASE;
1782 op2.ors_deref = LDAP_DEREF_NEVER;
1783 op2.ors_attrs = slap_anlist_all_attributes;
1784 op2.ors_attrsonly = 0;
1785 op2.ors_limit = NULL;
1787 op2.ors_tlimit = SLAP_NO_LIMIT;
1789 f.f_choice = LDAP_FILTER_PRESENT;
1790 f.f_desc = slap_schema.si_ad_objectClass;
1791 op2.ors_filter = &f;
1792 op2.ors_filterstr = generic_filterstr;
1794 op2.o_callback = &cb2;
1795 cb2.sc_response = dn_callback;
1796 cb2.sc_private = &dni;
1798 rc = be->be_search( &op2, &rs2 );
1799 if ( rc ) goto done;
1802 slap_op_time( &op->o_time, &op->o_tincr );
1808 Debug( LDAP_DEBUG_ANY,
1809 "syncrepl_entry: rid %03ld be_add failed (%d)\n",
1810 si->si_rid, rs_add.sr_err, 0 );
1816 op->o_req_dn = dni.dn;
1817 op->o_req_ndn = dni.ndn;
1818 if ( dni.renamed ) {
1819 struct berval noldp, newp, nnewp;
1821 op->o_tag = LDAP_REQ_MODRDN;
1822 dnRdn( &entry->e_name, &op->orr_newrdn );
1823 dnRdn( &entry->e_nname, &op->orr_nnewrdn );
1825 dnParent( &dni.ndn, &noldp );
1826 dnParent( &entry->e_nname, &nnewp );
1827 if ( !dn_match( &noldp, &nnewp )) {
1828 dnParent( &entry->e_name, &newp );
1829 op->orr_newSup = &newp;
1830 op->orr_nnewSup = &nnewp;
1832 op->orr_newSup = NULL;
1833 op->orr_nnewSup = NULL;
1835 op->orr_deleteoldrdn = dni.delOldRDN;
1836 op->orr_modlist = NULL;
1837 if (( rc = slap_modrdn2mods( op, &rs_modify ))) {
1841 /* RDNs must be NUL-terminated for back-ldap */
1842 noldp = op->orr_newrdn;
1843 ber_dupbv_x( &op->orr_newrdn, &noldp, op->o_tmpmemctx );
1844 noldp = op->orr_nnewrdn;
1845 ber_dupbv_x( &op->orr_nnewrdn, &noldp, op->o_tmpmemctx );
1847 /* Setup opattrs too */
1849 AttributeDescription *opattrs[] = {
1850 slap_schema.si_ad_entryCSN,
1851 slap_schema.si_ad_modifiersName,
1852 slap_schema.si_ad_modifyTimestamp,
1855 Modifications *mod, **modtail, **ml;
1858 for (mod=op->orr_modlist; mod->sml_next; mod=mod->sml_next)
1860 modtail = &mod->sml_next;
1862 /* pull mod off incoming modlist, append to orr_modlist */
1863 for (i=0; opattrs[i]; i++) {
1864 for (ml = modlist; *ml; ml = &(*ml)->sml_next)
1865 if ( (*ml)->sml_desc == opattrs[i] ) {
1867 *ml = mod->sml_next;
1868 mod->sml_next = NULL;
1870 modtail = &mod->sml_next;
1875 rc = be->be_modrdn( op, &rs_modify );
1876 op->o_tmpfree( op->orr_nnewrdn.bv_val, op->o_tmpmemctx );
1877 op->o_tmpfree( op->orr_newrdn.bv_val, op->o_tmpmemctx );
1879 slap_mods_free( op->orr_modlist, 1 );
1880 Debug( LDAP_DEBUG_SYNC,
1881 "syncrepl_entry: rid %03ld be_modrdn (%d)\n",
1882 si->si_rid, rc, 0 );
1886 op->o_tag = LDAP_REQ_MODIFY;
1887 op->orm_modlist = dni.mods;
1889 rc = be->be_modify( op, &rs_modify );
1890 slap_mods_free( op->orm_modlist, 1 );
1891 Debug( LDAP_DEBUG_SYNC,
1892 "syncrepl_entry: rid %03ld be_modify (%d)\n",
1893 si->si_rid, rc, 0 );
1894 if ( rs_modify.sr_err != LDAP_SUCCESS ) {
1895 Debug( LDAP_DEBUG_ANY,
1896 "syncrepl_entry: rid %03ld be_modify failed (%d)\n",
1897 si->si_rid, rs_modify.sr_err, 0 );
1901 case LDAP_SYNC_DELETE :
1902 if ( !BER_BVISNULL( &dni.dn )) {
1903 op->o_req_dn = dni.dn;
1904 op->o_req_ndn = dni.ndn;
1905 op->o_tag = LDAP_REQ_DELETE;
1906 rc = be->be_delete( op, &rs_delete );
1907 Debug( LDAP_DEBUG_SYNC,
1908 "syncrepl_entry: rid %03ld be_delete (%d)\n",
1909 si->si_rid, rc, 0 );
1911 while ( rs_delete.sr_err == LDAP_SUCCESS
1912 && op->o_delete_glue_parent ) {
1913 op->o_delete_glue_parent = 0;
1914 if ( !be_issuffix( op->o_bd, &op->o_req_ndn )) {
1915 slap_callback cb = { NULL };
1916 cb.sc_response = slap_null_cb;
1917 dnParent( &op->o_req_ndn, &pdn );
1919 op->o_req_ndn = pdn;
1920 op->o_callback = &cb;
1921 op->o_bd->be_delete( op, &rs_delete );
1930 Debug( LDAP_DEBUG_ANY,
1931 "syncrepl_entry: rid %03ld unknown syncstate\n", si->si_rid, 0, 0 );
1936 if ( !BER_BVISNULL( &syncUUID_strrep ) ) {
1937 slap_sl_free( syncUUID_strrep.bv_val, op->o_tmpmemctx );
1938 BER_BVZERO( &syncUUID_strrep );
1940 if ( !BER_BVISNULL( &dni.ndn ) ) {
1941 op->o_tmpfree( dni.ndn.bv_val, op->o_tmpmemctx );
1943 if ( !BER_BVISNULL( &dni.dn ) ) {
1944 op->o_tmpfree( dni.dn.bv_val, op->o_tmpmemctx );
1947 entry_free( entry );
1948 BER_BVZERO( &op->o_csn );
1952 static struct berval gcbva[] = {
1958 #define NP_DELETE_ONE 2
1961 syncrepl_del_nonpresent(
1965 struct berval *cookiecsn )
1967 Backend* be = op->o_bd;
1968 slap_callback cb = { NULL };
1969 SlapReply rs_search = {REP_RESULT};
1970 SlapReply rs_delete = {REP_RESULT};
1971 SlapReply rs_modify = {REP_RESULT};
1972 struct nonpresent_entry *np_list, *np_prev;
1974 AttributeName an[2];
1976 struct berval pdn = BER_BVNULL;
1979 op->o_req_dn = si->si_base;
1980 op->o_req_ndn = si->si_base;
1982 cb.sc_response = nonpresent_callback;
1985 op->o_callback = &cb;
1986 op->o_tag = LDAP_REQ_SEARCH;
1987 op->ors_scope = si->si_scope;
1988 op->ors_deref = LDAP_DEREF_NEVER;
1989 op->o_time = slap_get_time();
1990 op->ors_tlimit = SLAP_NO_LIMIT;
1995 #ifdef LDAP_COMP_MATCH
1996 AttributeAssertion eq = { NULL, BER_BVNULL, NULL };
1998 AttributeAssertion eq = { NULL, BER_BVNULL };
2002 op->ors_attrsonly = 1;
2003 op->ors_attrs = slap_anlist_no_attrs;
2004 op->ors_limit = NULL;
2005 op->ors_filter = &uf;
2008 uf.f_av_desc = slap_schema.si_ad_entryUUID;
2010 uf.f_choice = LDAP_FILTER_EQUALITY;
2011 si->si_refreshDelete |= NP_DELETE_ONE;
2013 for (i=0; uuids[i].bv_val; i++) {
2015 slap_uuidstr_from_normalized( &uf.f_av_value, &uuids[i],
2017 filter2bv_x( op, op->ors_filter, &op->ors_filterstr );
2018 op->o_tmpfree( uf.f_av_value.bv_val, op->o_tmpmemctx );
2019 uf.f_av_value = uuids[i];
2020 rc = be->be_search( op, &rs_search );
2021 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
2023 si->si_refreshDelete ^= NP_DELETE_ONE;
2025 memset( &an[0], 0, 2 * sizeof( AttributeName ) );
2026 an[0].an_name = slap_schema.si_ad_entryUUID->ad_cname;
2027 an[0].an_desc = slap_schema.si_ad_entryUUID;
2029 op->ors_slimit = SLAP_NO_LIMIT;
2030 op->ors_attrsonly = 0;
2031 op->ors_filter = str2filter_x( op, si->si_filterstr.bv_val );
2032 op->ors_filterstr = si->si_filterstr;
2033 op->o_nocaching = 1;
2035 if ( limits_check( op, &rs_search ) == 0 ) {
2036 rc = be->be_search( op, &rs_search );
2038 if ( op->ors_filter ) filter_free_x( op, op->ors_filter );
2041 op->o_nocaching = 0;
2043 if ( !LDAP_LIST_EMPTY( &si->si_nonpresentlist ) ) {
2045 if ( cookiecsn && !BER_BVISNULL( cookiecsn ))
2048 csn = si->si_syncCookie.ctxcsn;
2050 slap_queue_csn( op, &csn );
2052 np_list = LDAP_LIST_FIRST( &si->si_nonpresentlist );
2053 while ( np_list != NULL ) {
2054 LDAP_LIST_REMOVE( np_list, npe_link );
2056 np_list = LDAP_LIST_NEXT( np_list, npe_link );
2057 op->o_tag = LDAP_REQ_DELETE;
2058 op->o_callback = &cb;
2059 cb.sc_response = null_callback;
2061 op->o_req_dn = *np_prev->npe_name;
2062 op->o_req_ndn = *np_prev->npe_nname;
2063 rc = op->o_bd->be_delete( op, &rs_delete );
2064 Debug( LDAP_DEBUG_SYNC,
2065 "syncrepl_del_nonpresent: rid %03ld be_delete %s (%d)\n",
2066 si->si_rid, op->o_req_dn.bv_val, rc );
2068 if ( rs_delete.sr_err == LDAP_NOT_ALLOWED_ON_NONLEAF ) {
2069 Modifications mod1, mod2;
2070 mod1.sml_op = LDAP_MOD_REPLACE;
2072 mod1.sml_desc = slap_schema.si_ad_objectClass;
2073 mod1.sml_type = mod1.sml_desc->ad_cname;
2074 mod1.sml_values = &gcbva[0];
2075 mod1.sml_nvalues = NULL;
2076 mod1.sml_next = &mod2;
2078 mod2.sml_op = LDAP_MOD_REPLACE;
2080 mod2.sml_desc = slap_schema.si_ad_structuralObjectClass;
2081 mod2.sml_type = mod2.sml_desc->ad_cname;
2082 mod2.sml_values = &gcbva[1];
2083 mod2.sml_nvalues = NULL;
2084 mod2.sml_next = NULL;
2086 op->o_tag = LDAP_REQ_MODIFY;
2087 op->orm_modlist = &mod1;
2089 rc = be->be_modify( op, &rs_modify );
2090 if ( mod2.sml_next ) slap_mods_free( mod2.sml_next, 1 );
2093 while ( rs_delete.sr_err == LDAP_SUCCESS &&
2094 op->o_delete_glue_parent ) {
2095 op->o_delete_glue_parent = 0;
2096 if ( !be_issuffix( op->o_bd, &op->o_req_ndn )) {
2097 slap_callback cb = { NULL };
2098 cb.sc_response = slap_null_cb;
2099 dnParent( &op->o_req_ndn, &pdn );
2101 op->o_req_ndn = pdn;
2102 op->o_callback = &cb;
2103 /* give it a root privil ? */
2104 op->o_bd->be_delete( op, &rs_delete );
2110 op->o_delete_glue_parent = 0;
2112 ber_bvfree( np_prev->npe_name );
2113 ber_bvfree( np_prev->npe_nname );
2117 slap_graduate_commit_csn( op );
2119 op->o_tmpfree( op->o_csn.bv_val, op->o_tmpmemctx );
2120 BER_BVZERO( &op->o_csn );
2131 Backend *be = op->o_bd;
2132 slap_callback cb = { NULL };
2137 struct berval dn = BER_BVNULL;
2138 struct berval ndn = BER_BVNULL;
2140 SlapReply rs_add = {REP_RESULT};
2141 struct berval ptr, nptr;
2144 op->o_tag = LDAP_REQ_ADD;
2145 op->o_callback = &cb;
2146 cb.sc_response = null_callback;
2147 cb.sc_private = NULL;
2152 /* count RDNs in suffix */
2153 if ( !BER_BVISEMPTY( &be->be_nsuffix[0] ) ) {
2154 for ( i = 0, ptr = be->be_nsuffix[0], comma = ptr.bv_val; comma != NULL; comma = ber_bvchr( &ptr, ',' ) ) {
2156 ptr.bv_len -= comma - ptr.bv_val;
2166 /* Start with BE suffix */
2168 for ( i = 0; i < suffrdns; i++ ) {
2169 comma = ber_bvrchr( &ptr, ',' );
2170 if ( comma != NULL ) {
2171 ptr.bv_len = comma - ptr.bv_val;
2178 if ( !BER_BVISEMPTY( &ptr ) ) {
2179 dn.bv_len -= ptr.bv_len + 1;
2180 dn.bv_val += ptr.bv_len + 1;
2183 /* the normalizedDNs are always the same length, no counting
2187 if ( ndn.bv_len > be->be_nsuffix[0].bv_len ) {
2188 ndn.bv_val += ndn.bv_len - be->be_nsuffix[0].bv_len;
2189 ndn.bv_len = be->be_nsuffix[0].bv_len;
2191 nptr.bv_len = ndn.bv_val - nptr.bv_val - 1;
2197 while ( ndn.bv_val > e->e_nname.bv_val ) {
2198 glue = entry_alloc();
2199 ber_dupbv( &glue->e_name, &dn );
2200 ber_dupbv( &glue->e_nname, &ndn );
2202 a = attr_alloc( slap_schema.si_ad_objectClass );
2204 a->a_vals = ch_calloc( 3, sizeof( struct berval ));
2205 ber_dupbv( &a->a_vals[0], &gcbva[0] );
2206 ber_dupbv( &a->a_vals[1], &gcbva[1] );
2207 ber_dupbv( &a->a_vals[2], &gcbva[2] );
2209 a->a_nvals = a->a_vals;
2211 a->a_next = glue->e_attrs;
2214 a = attr_alloc( slap_schema.si_ad_structuralObjectClass );
2216 a->a_vals = ch_calloc( 2, sizeof( struct berval ));
2217 ber_dupbv( &a->a_vals[0], &gcbva[1] );
2218 ber_dupbv( &a->a_vals[1], &gcbva[2] );
2220 a->a_nvals = a->a_vals;
2222 a->a_next = glue->e_attrs;
2225 op->o_req_dn = glue->e_name;
2226 op->o_req_ndn = glue->e_nname;
2228 rc = be->be_add ( op, &rs_add );
2229 if ( rs_add.sr_err == LDAP_SUCCESS ) {
2230 if ( op->ora_e == glue )
2231 be_entry_release_w( op, glue );
2233 /* incl. ALREADY EXIST */
2235 if ( rs_add.sr_err != LDAP_ALREADY_EXISTS ) {
2241 /* Move to next child */
2242 comma = ber_bvrchr( &ptr, ',' );
2243 if ( comma == NULL ) {
2246 ptr.bv_len = comma - ptr.bv_val;
2248 dn.bv_val = ++comma;
2249 dn.bv_len = e->e_name.bv_len - (dn.bv_val - e->e_name.bv_val);
2251 comma = ber_bvrchr( &nptr, ',' );
2252 assert( comma != NULL );
2253 nptr.bv_len = comma - nptr.bv_val;
2255 ndn.bv_val = ++comma;
2256 ndn.bv_len = e->e_nname.bv_len - (ndn.bv_val - e->e_nname.bv_val);
2259 op->o_req_dn = e->e_name;
2260 op->o_req_ndn = e->e_nname;
2262 rc = be->be_add ( op, &rs_add );
2263 if ( rs_add.sr_err == LDAP_SUCCESS ) {
2264 if ( op->ora_e == e )
2265 be_entry_release_w( op, e );
2274 syncrepl_updateCookie(
2278 struct sync_cookie *syncCookie )
2280 Backend *be = op->o_bd;
2281 Modifications mod = { { 0 } };
2282 struct berval vals[ 2 ];
2286 slap_callback cb = { NULL };
2287 SlapReply rs_modify = {REP_RESULT};
2289 mod.sml_op = LDAP_MOD_REPLACE;
2290 mod.sml_desc = slap_schema.si_ad_contextCSN;
2291 mod.sml_type = mod.sml_desc->ad_cname;
2292 mod.sml_values = vals;
2293 vals[0] = syncCookie->ctxcsn;
2294 BER_BVZERO( &vals[1] );
2296 slap_queue_csn( op, &syncCookie->ctxcsn );
2298 op->o_tag = LDAP_REQ_MODIFY;
2300 assert( si->si_rid < 1000 );
2302 cb.sc_response = null_callback;
2305 op->o_callback = &cb;
2306 op->o_req_dn = op->o_bd->be_suffix[0];
2307 op->o_req_ndn = op->o_bd->be_nsuffix[0];
2309 /* update contextCSN */
2310 op->o_msgid = SLAP_SYNC_UPDATE_MSGID;
2311 op->orm_modlist = &mod;
2312 rc = be->be_modify( op, &rs_modify );
2315 if ( rs_modify.sr_err == LDAP_SUCCESS ) {
2316 slap_sync_cookie_free( &si->si_syncCookie, 0 );
2317 slap_dup_sync_cookie( &si->si_syncCookie, syncCookie );
2319 Debug( LDAP_DEBUG_ANY,
2320 "syncrepl_updateCookie: rid %03ld be_modify failed (%d)\n",
2321 si->si_rid, rs_modify.sr_err, 0 );
2324 slap_graduate_commit_csn( op );
2325 op->o_tmpfree( op->o_csn.bv_val, op->o_tmpmemctx );
2326 BER_BVZERO( &op->o_csn );
2327 if ( mod.sml_next ) slap_mods_free( mod.sml_next, 1 );
2333 attr_cmp( Operation *op, Attribute *old, Attribute *new,
2334 Modifications ***mret, Modifications ***mcur )
2336 int i, j, doadd = 0;
2337 Modifications *mod, **modtail;
2342 int n, o, d, a, *adds, *dels;
2343 /* count old and new */
2344 for ( o=0; old->a_vals[o].bv_val; o++ ) ;
2345 for ( n=0; new->a_vals[n].bv_val; n++ ) ;
2347 adds = op->o_tmpalloc( sizeof(int) * n, op->o_tmpmemctx );
2348 dels = op->o_tmpalloc( sizeof(int) * o, op->o_tmpmemctx );
2354 while ( i < o && j < n ) {
2356 if ( bvmatch( &old->a_vals[i], &new->a_vals[j] )) {
2361 for ( k=j+1; k<n; k++ ) {
2362 if ( bvmatch( &old->a_vals[i], &new->a_vals[k] )) {
2366 /* an old value was deleted */
2371 for ( k=i+1; k<o; k++ ) {
2372 if ( bvmatch( &old->a_vals[k], &new->a_vals[j] )) {
2385 /* all old values were deleted, just use the replace op */
2389 /* delete some values */
2390 mod = ch_malloc( sizeof( Modifications ) );
2391 mod->sml_op = LDAP_MOD_DELETE;
2393 mod->sml_desc = old->a_desc;
2394 mod->sml_type = mod->sml_desc->ad_cname;
2395 mod->sml_values = ch_malloc(( d+1) * sizeof(struct berval));
2396 if ( old->a_vals != old->a_nvals )
2397 mod->sml_nvalues = ch_malloc(( d+1) * sizeof(struct berval));
2399 mod->sml_nvalues = NULL;
2400 for ( i=0; i<d; i++ ) {
2401 ber_dupbv( &mod->sml_values[i], &old->a_vals[dels[i]] );
2402 if ( mod->sml_nvalues )
2403 ber_dupbv( &mod->sml_nvalues[i], &old->a_nvals[dels[i]] );
2405 BER_BVZERO( &mod->sml_values[i] );
2406 if ( mod->sml_nvalues )
2407 BER_BVZERO( &mod->sml_nvalues[i] );
2409 modtail = &mod->sml_next;
2412 op->o_tmpfree( dels, op->o_tmpmemctx );
2413 /* some values were added */
2415 mod = ch_malloc( sizeof( Modifications ) );
2416 mod->sml_op = LDAP_MOD_ADD;
2418 mod->sml_desc = old->a_desc;
2419 mod->sml_type = mod->sml_desc->ad_cname;
2420 mod->sml_values = ch_malloc(( a+1) * sizeof(struct berval));
2421 if ( old->a_vals != old->a_nvals )
2422 mod->sml_nvalues = ch_malloc(( a+1) * sizeof(struct berval));
2424 mod->sml_nvalues = NULL;
2425 for ( i=0; i<a; i++ ) {
2426 ber_dupbv( &mod->sml_values[i], &new->a_vals[adds[i]] );
2427 if ( mod->sml_nvalues )
2428 ber_dupbv( &mod->sml_nvalues[i], &new->a_nvals[adds[i]] );
2430 BER_BVZERO( &mod->sml_values[i] );
2431 if ( mod->sml_nvalues )
2432 BER_BVZERO( &mod->sml_nvalues[i] );
2434 modtail = &mod->sml_next;
2437 op->o_tmpfree( adds, op->o_tmpmemctx );
2439 /* new attr, just use the new mod */
2443 /* advance to next element */
2446 **mcur = mod->sml_next;
2448 modtail = &mod->sml_next;
2451 *mcur = &mod->sml_next;
2461 dninfo *dni = op->o_callback->sc_private;
2463 if ( rs->sr_type == REP_SEARCH ) {
2464 if ( !BER_BVISNULL( &dni->dn ) ) {
2465 Debug( LDAP_DEBUG_ANY,
2466 "dn_callback : consistency error - "
2467 "entryUUID is not unique\n", 0, 0, 0 );
2469 ber_dupbv_x( &dni->dn, &rs->sr_entry->e_name, op->o_tmpmemctx );
2470 ber_dupbv_x( &dni->ndn, &rs->sr_entry->e_nname, op->o_tmpmemctx );
2471 /* If there is a new entry, see if it differs from the old.
2472 * We compare the non-normalized values so that cosmetic changes
2473 * in the provider are always propagated.
2475 if ( dni->new_entry ) {
2476 Modifications **modtail, **ml;
2477 Attribute *old, *new;
2480 /* Did the DN change?
2482 if ( !dn_match( &rs->sr_entry->e_name,
2483 &dni->new_entry->e_name ) )
2485 struct berval oldRDN, oldVal;
2486 AttributeDescription *ad = NULL;
2490 /* See if the oldRDN was deleted */
2491 dnRdn( &rs->sr_entry->e_nname, &oldRDN );
2492 oldVal.bv_val = strchr(oldRDN.bv_val, '=') + 1;
2493 oldVal.bv_len = oldRDN.bv_len - ( oldVal.bv_val -
2495 oldRDN.bv_len -= oldVal.bv_len + 2;
2496 slap_bv2ad( &oldRDN, &ad, &rs->sr_text );
2497 a = attr_find( dni->new_entry->e_attrs, ad );
2498 if ( !a || value_find_ex( ad,
2499 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH |
2500 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
2501 SLAP_MR_VALUE_OF_SYNTAX, a->a_nvals,
2502 &oldVal, op->o_tmpmemctx ) != LDAP_SUCCESS )
2506 /* OK, this was just a modDN, we're done */
2507 return LDAP_SUCCESS;
2510 modtail = &dni->mods;
2513 /* We assume that attributes are saved in the same order
2514 * in the remote and local databases. So if we walk through
2515 * the attributeDescriptions one by one they should match in
2516 * lock step. If not, look for an add or delete.
2518 for ( old = rs->sr_entry->e_attrs, new = dni->new_entry->e_attrs;
2522 if ( new->a_flags & SLAP_ATTR_IXADD ) {
2527 if ( old->a_desc != new->a_desc ) {
2531 /* If it's just been re-added later,
2532 * remember that we've seen it.
2534 tmp = attr_find( new, old->a_desc );
2536 tmp->a_flags |= SLAP_ATTR_IXADD;
2538 /* If it's a new attribute, pull it in.
2540 tmp = attr_find( old, new->a_desc );
2542 attr_cmp( op, NULL, new, &modtail, &ml );
2546 /* Delete old attr */
2547 mod = ch_malloc( sizeof( Modifications ) );
2548 mod->sml_op = LDAP_MOD_DELETE;
2550 mod->sml_desc = old->a_desc;
2551 mod->sml_type = mod->sml_desc->ad_cname;
2552 mod->sml_values = NULL;
2553 mod->sml_nvalues = NULL;
2555 modtail = &mod->sml_next;
2560 attr_cmp( op, old, new, &modtail, &ml );
2568 } else if ( rs->sr_type == REP_RESULT ) {
2569 if ( rs->sr_err == LDAP_SIZELIMIT_EXCEEDED ) {
2570 Debug( LDAP_DEBUG_ANY,
2571 "dn_callback : consistency error - "
2572 "entryUUID is not unique\n", 0, 0, 0 );
2576 return LDAP_SUCCESS;
2580 nonpresent_callback(
2584 syncinfo_t *si = op->o_callback->sc_private;
2587 struct berval* present_uuid = NULL;
2588 struct nonpresent_entry *np_entry;
2590 if ( rs->sr_type == REP_RESULT ) {
2591 count = avl_free( si->si_presentlist, avl_ber_bvfree );
2592 si->si_presentlist = NULL;
2594 } else if ( rs->sr_type == REP_SEARCH ) {
2595 if ( !(si->si_refreshDelete & NP_DELETE_ONE )) {
2596 char buf[sizeof("000 not")];
2598 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID );
2601 present_uuid = avl_find( si->si_presentlist, &a->a_nvals[0],
2604 if ( slap_debug & LDAP_DEBUG_SYNC )
2605 sprintf( buf, "%03ld %s", si->si_rid,
2606 present_uuid ? "got" : "not" );
2608 Debug( LDAP_DEBUG_SYNC, "nonpresent_callback: rid %s UUID %s, dn %s\n",
2609 buf, a ? a->a_vals[0].bv_val : "<missing>", rs->sr_entry->e_name.bv_val );
2611 if ( a == NULL ) return 0;
2614 if ( present_uuid == NULL ) {
2615 np_entry = (struct nonpresent_entry *)
2616 ch_calloc( 1, sizeof( struct nonpresent_entry ));
2617 np_entry->npe_name = ber_dupbv( NULL, &rs->sr_entry->e_name );
2618 np_entry->npe_nname = ber_dupbv( NULL, &rs->sr_entry->e_nname );
2619 LDAP_LIST_INSERT_HEAD( &si->si_nonpresentlist, np_entry, npe_link );
2622 avl_delete( &si->si_presentlist,
2623 &a->a_nvals[0], syncuuid_cmp );
2624 ch_free( present_uuid->bv_val );
2625 ch_free( present_uuid );
2628 return LDAP_SUCCESS;
2636 if ( rs->sr_err != LDAP_SUCCESS &&
2637 rs->sr_err != LDAP_REFERRAL &&
2638 rs->sr_err != LDAP_ALREADY_EXISTS &&
2639 rs->sr_err != LDAP_NO_SUCH_OBJECT &&
2640 rs->sr_err != LDAP_NOT_ALLOWED_ON_NONLEAF )
2642 Debug( LDAP_DEBUG_ANY,
2643 "null_callback : error code 0x%x\n",
2646 return LDAP_SUCCESS;
2649 static struct berval *
2650 slap_uuidstr_from_normalized(
2651 struct berval* uuidstr,
2652 struct berval* normalized,
2656 unsigned char nibble;
2659 if ( normalized == NULL ) return NULL;
2660 if ( normalized->bv_len != 16 ) return NULL;
2665 new = (struct berval *)slap_sl_malloc( sizeof(struct berval), ctx );
2666 if ( new == NULL ) {
2673 if ( ( new->bv_val = slap_sl_malloc( new->bv_len + 1, ctx ) ) == NULL ) {
2674 if ( new != uuidstr ) {
2675 slap_sl_free( new, ctx );
2680 for ( i = 0; i < 16; i++ ) {
2681 if ( i == 4 || i == 6 || i == 8 || i == 10 ) {
2682 new->bv_val[(i<<1)+d] = '-';
2686 nibble = (normalized->bv_val[i] >> 4) & 0xF;
2687 if ( nibble < 10 ) {
2688 new->bv_val[(i<<1)+d] = nibble + '0';
2690 new->bv_val[(i<<1)+d] = nibble - 10 + 'a';
2693 nibble = (normalized->bv_val[i]) & 0xF;
2694 if ( nibble < 10 ) {
2695 new->bv_val[(i<<1)+d+1] = nibble + '0';
2697 new->bv_val[(i<<1)+d+1] = nibble - 10 + 'a';
2701 new->bv_val[new->bv_len] = '\0';
2706 syncuuid_cmp( const void* v_uuid1, const void* v_uuid2 )
2708 const struct berval *uuid1 = v_uuid1;
2709 const struct berval *uuid2 = v_uuid2;
2710 int rc = uuid1->bv_len - uuid2->bv_len;
2711 if ( rc ) return rc;
2712 return ( memcmp( uuid1->bv_val, uuid2->bv_val, uuid1->bv_len ) );
2716 avl_ber_bvfree( void *v_bv )
2718 struct berval *bv = (struct berval *)v_bv;
2720 if( v_bv == NULL ) return;
2721 if ( !BER_BVISNULL( bv ) ) {
2722 ch_free( bv->bv_val );
2724 ch_free( (char *) bv );
2728 syncinfo_free( syncinfo_t *sie )
2731 if ( sie->si_conn_setup ) {
2733 ldap_get_option( sie->si_ld, LDAP_OPT_DESC, &s );
2734 connection_client_stop( s );
2735 sie->si_conn_setup = 0;
2737 ldap_unbind_ext( sie->si_ld, NULL, NULL );
2740 /* re-fetch it, in case it was already removed */
2741 sie->si_re = ldap_pvt_runqueue_find( &slapd_rq, do_syncrepl, sie );
2743 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, sie->si_re ) )
2744 ldap_pvt_runqueue_stoptask( &slapd_rq, sie->si_re );
2745 ldap_pvt_runqueue_remove( &slapd_rq, sie->si_re );
2748 ldap_pvt_thread_mutex_destroy( &sie->si_mutex );
2750 bindconf_free( &sie->si_bindconf );
2752 if ( sie->si_filterstr.bv_val ) {
2753 ch_free( sie->si_filterstr.bv_val );
2755 if ( sie->si_base.bv_val ) {
2756 ch_free( sie->si_base.bv_val );
2758 if ( sie->si_attrs ) {
2760 while ( sie->si_attrs[i] != NULL ) {
2761 ch_free( sie->si_attrs[i] );
2764 ch_free( sie->si_attrs );
2766 if ( sie->si_exattrs ) {
2768 while ( sie->si_exattrs[i] != NULL ) {
2769 ch_free( sie->si_exattrs[i] );
2772 ch_free( sie->si_exattrs );
2774 if ( sie->si_anlist ) {
2776 while ( sie->si_anlist[i].an_name.bv_val != NULL ) {
2777 ch_free( sie->si_anlist[i].an_name.bv_val );
2780 ch_free( sie->si_anlist );
2782 if ( sie->si_exanlist ) {
2784 while ( sie->si_exanlist[i].an_name.bv_val != NULL ) {
2785 ch_free( sie->si_exanlist[i].an_name.bv_val );
2788 ch_free( sie->si_exanlist );
2790 if ( sie->si_retryinterval ) {
2791 ch_free( sie->si_retryinterval );
2793 if ( sie->si_retrynum ) {
2794 ch_free( sie->si_retrynum );
2796 if ( sie->si_retrynum_init ) {
2797 ch_free( sie->si_retrynum_init );
2799 slap_sync_cookie_free( &sie->si_syncCookie, 0 );
2800 if ( sie->si_presentlist ) {
2801 avl_free( sie->si_presentlist, avl_ber_bvfree );
2803 while ( !LDAP_LIST_EMPTY( &sie->si_nonpresentlist )) {
2804 struct nonpresent_entry* npe;
2805 npe = LDAP_LIST_FIRST( &sie->si_nonpresentlist );
2806 LDAP_LIST_REMOVE( npe, npe_link );
2807 if ( npe->npe_name ) {
2808 if ( npe->npe_name->bv_val ) {
2809 ch_free( npe->npe_name->bv_val );
2811 ch_free( npe->npe_name );
2813 if ( npe->npe_nname ) {
2814 if ( npe->npe_nname->bv_val ) {
2815 ch_free( npe->npe_nname->bv_val );
2817 ch_free( npe->npe_nname );
2826 /* NOTE: used & documented in slapd.conf(5) */
2828 #define PROVIDERSTR "provider"
2829 #define SCHEMASTR "schemachecking"
2830 #define FILTERSTR "filter"
2831 #define SEARCHBASESTR "searchbase"
2832 #define SCOPESTR "scope"
2833 #define ATTRSONLYSTR "attrsonly"
2834 #define ATTRSSTR "attrs"
2835 #define TYPESTR "type"
2836 #define INTERVALSTR "interval"
2837 #define RETRYSTR "retry"
2838 #define SLIMITSTR "sizelimit"
2839 #define TLIMITSTR "timelimit"
2840 #define SYNCDATASTR "syncdata"
2842 /* FIXME: undocumented */
2843 #define LOGBASESTR "logbase"
2844 #define LOGFILTERSTR "logfilter"
2845 #define OLDAUTHCSTR "bindprincipal"
2846 #define EXATTRSSTR "exattrs"
2847 #define MANAGEDSAITSTR "manageDSAit"
2850 #define LASTMODSTR "lastmod"
2851 #define LMGENSTR "gen"
2852 #define LMNOSTR "no"
2853 #define LMREQSTR "req"
2854 #define SRVTABSTR "srvtab"
2855 #define SUFFIXSTR "suffix"
2858 #define GOT_ID 0x0001
2859 #define GOT_PROVIDER 0x0002
2860 #define GOT_BASE 0x0004
2863 #define GOT_ALL (GOT_ID|GOT_PROVIDER|GOT_BASE)
2869 { BER_BVC("base"), LDAP_SCOPE_BASE },
2870 { BER_BVC("one"), LDAP_SCOPE_ONELEVEL },
2871 { BER_BVC("onelevel"), LDAP_SCOPE_ONELEVEL }, /* OpenLDAP extension */
2872 { BER_BVC("children"), LDAP_SCOPE_SUBORDINATE },
2873 { BER_BVC("subord"), LDAP_SCOPE_SUBORDINATE },
2874 { BER_BVC("subordinate"), LDAP_SCOPE_SUBORDINATE },
2875 { BER_BVC("sub"), LDAP_SCOPE_SUBTREE },
2876 { BER_BVC("subtree"), LDAP_SCOPE_SUBTREE }, /* OpenLDAP extension */
2880 static slap_verbmasks datamodes[] = {
2881 { BER_BVC("default"), SYNCDATA_DEFAULT },
2882 { BER_BVC("accesslog"), SYNCDATA_ACCESSLOG },
2883 { BER_BVC("changelog"), SYNCDATA_CHANGELOG },
2888 parse_syncrepl_line(
2896 for ( i = 1; i < c->argc; i++ ) {
2897 if ( !strncasecmp( c->argv[ i ], IDSTR "=",
2898 STRLENOF( IDSTR "=" ) ) )
2901 /* '\0' string terminator accounts for '=' */
2902 val = c->argv[ i ] + STRLENOF( IDSTR "=" );
2903 if ( lutil_atoi( &tmp, val ) != 0 ) {
2904 snprintf( c->msg, sizeof( c->msg ),
2905 "Error: parse_syncrepl_line: "
2906 "unable to parse syncrepl id \"%s\"", val );
2907 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
2910 if ( tmp >= 1000 || tmp < 0 ) {
2911 snprintf( c->msg, sizeof( c->msg ),
2912 "Error: parse_syncrepl_line: "
2913 "syncrepl id %d is out of range [0..999]", tmp );
2914 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
2919 } else if ( !strncasecmp( c->argv[ i ], PROVIDERSTR "=",
2920 STRLENOF( PROVIDERSTR "=" ) ) )
2922 val = c->argv[ i ] + STRLENOF( PROVIDERSTR "=" );
2923 ber_str2bv( val, 0, 1, &si->si_bindconf.sb_uri );
2924 gots |= GOT_PROVIDER;
2925 } else if ( !strncasecmp( c->argv[ i ], SCHEMASTR "=",
2926 STRLENOF( SCHEMASTR "=" ) ) )
2928 val = c->argv[ i ] + STRLENOF( SCHEMASTR "=" );
2929 if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
2930 si->si_schemachecking = 1;
2931 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2932 si->si_schemachecking = 0;
2934 si->si_schemachecking = 1;
2936 } else if ( !strncasecmp( c->argv[ i ], FILTERSTR "=",
2937 STRLENOF( FILTERSTR "=" ) ) )
2939 val = c->argv[ i ] + STRLENOF( FILTERSTR "=" );
2940 if ( si->si_filterstr.bv_val )
2941 ch_free( si->si_filterstr.bv_val );
2942 ber_str2bv( val, 0, 1, &si->si_filterstr );
2943 } else if ( !strncasecmp( c->argv[ i ], LOGFILTERSTR "=",
2944 STRLENOF( LOGFILTERSTR "=" ) ) )
2946 val = c->argv[ i ] + STRLENOF( LOGFILTERSTR "=" );
2947 if ( si->si_logfilterstr.bv_val )
2948 ch_free( si->si_logfilterstr.bv_val );
2949 ber_str2bv( val, 0, 1, &si->si_logfilterstr );
2950 } else if ( !strncasecmp( c->argv[ i ], SEARCHBASESTR "=",
2951 STRLENOF( SEARCHBASESTR "=" ) ) )
2956 val = c->argv[ i ] + STRLENOF( SEARCHBASESTR "=" );
2957 if ( si->si_base.bv_val ) {
2958 ch_free( si->si_base.bv_val );
2960 ber_str2bv( val, 0, 0, &bv );
2961 rc = dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL );
2962 if ( rc != LDAP_SUCCESS ) {
2963 snprintf( c->msg, sizeof( c->msg ),
2964 "Invalid base DN \"%s\": %d (%s)",
2965 val, rc, ldap_err2string( rc ) );
2966 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
2970 } else if ( !strncasecmp( c->argv[ i ], LOGBASESTR "=",
2971 STRLENOF( LOGBASESTR "=" ) ) )
2976 val = c->argv[ i ] + STRLENOF( LOGBASESTR "=" );
2977 if ( si->si_logbase.bv_val ) {
2978 ch_free( si->si_logbase.bv_val );
2980 ber_str2bv( val, 0, 0, &bv );
2981 rc = dnNormalize( 0, NULL, NULL, &bv, &si->si_logbase, NULL );
2982 if ( rc != LDAP_SUCCESS ) {
2983 snprintf( c->msg, sizeof( c->msg ),
2984 "Invalid logbase DN \"%s\": %d (%s)",
2985 val, rc, ldap_err2string( rc ) );
2986 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
2989 } else if ( !strncasecmp( c->argv[ i ], SCOPESTR "=",
2990 STRLENOF( SCOPESTR "=" ) ) )
2993 val = c->argv[ i ] + STRLENOF( SCOPESTR "=" );
2994 for ( j=0; !BER_BVISNULL(&scopes[j].key); j++ ) {
2995 if (!strcasecmp( val, scopes[j].key.bv_val )) {
2996 si->si_scope = scopes[j].val;
3000 if ( BER_BVISNULL(&scopes[j].key) ) {
3001 snprintf( c->msg, sizeof( c->msg ),
3002 "Error: parse_syncrepl_line: "
3003 "unknown scope \"%s\"", val);
3004 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3007 } else if ( !strncasecmp( c->argv[ i ], ATTRSONLYSTR,
3008 STRLENOF( ATTRSONLYSTR ) ) )
3010 si->si_attrsonly = 1;
3011 } else if ( !strncasecmp( c->argv[ i ], ATTRSSTR "=",
3012 STRLENOF( ATTRSSTR "=" ) ) )
3014 val = c->argv[ i ] + STRLENOF( ATTRSSTR "=" );
3015 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") ) ) {
3017 attr_fname = ch_strdup( val + STRLENOF(":include:") );
3018 si->si_anlist = file2anlist( si->si_anlist, attr_fname, " ,\t" );
3019 if ( si->si_anlist == NULL ) {
3020 ch_free( attr_fname );
3023 si->si_anfile = attr_fname;
3025 char *str, *s, *next;
3026 char delimstr[] = " ,\t";
3027 str = ch_strdup( val );
3028 for ( s = ldap_pvt_strtok( str, delimstr, &next );
3030 s = ldap_pvt_strtok( NULL, delimstr, &next ) )
3032 if ( strlen(s) == 1 && *s == '*' ) {
3033 si->si_allattrs = 1;
3034 *(val + ( s - str )) = delimstr[0];
3036 if ( strlen(s) == 1 && *s == '+' ) {
3037 si->si_allopattrs = 1;
3038 *(val + ( s - str )) = delimstr[0];
3042 si->si_anlist = str2anlist( si->si_anlist, val, " ,\t" );
3043 if ( si->si_anlist == NULL ) {
3047 } else if ( !strncasecmp( c->argv[ i ], EXATTRSSTR "=",
3048 STRLENOF( EXATTRSSTR "=" ) ) )
3050 val = c->argv[ i ] + STRLENOF( EXATTRSSTR "=" );
3051 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") )) {
3053 attr_fname = ch_strdup( val + STRLENOF(":include:") );
3054 si->si_exanlist = file2anlist(
3055 si->si_exanlist, attr_fname, " ,\t" );
3056 if ( si->si_exanlist == NULL ) {
3057 ch_free( attr_fname );
3060 ch_free( attr_fname );
3062 si->si_exanlist = str2anlist( si->si_exanlist, val, " ,\t" );
3063 if ( si->si_exanlist == NULL ) {
3067 } else if ( !strncasecmp( c->argv[ i ], TYPESTR "=",
3068 STRLENOF( TYPESTR "=" ) ) )
3070 val = c->argv[ i ] + STRLENOF( TYPESTR "=" );
3071 if ( !strncasecmp( val, "refreshOnly",
3072 STRLENOF("refreshOnly") ) )
3074 si->si_type = si->si_ctype = LDAP_SYNC_REFRESH_ONLY;
3075 } else if ( !strncasecmp( val, "refreshAndPersist",
3076 STRLENOF("refreshAndPersist") ) )
3078 si->si_type = si->si_ctype = LDAP_SYNC_REFRESH_AND_PERSIST;
3079 si->si_interval = 60;
3081 snprintf( c->msg, sizeof( c->msg ),
3082 "Error: parse_syncrepl_line: "
3083 "unknown sync type \"%s\"", val);
3084 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3087 } else if ( !strncasecmp( c->argv[ i ], INTERVALSTR "=",
3088 STRLENOF( INTERVALSTR "=" ) ) )
3090 val = c->argv[ i ] + STRLENOF( INTERVALSTR "=" );
3091 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
3092 si->si_interval = 0;
3093 } else if ( strchr( val, ':' ) != NULL ) {
3094 char *next, *ptr = val;
3095 unsigned dd, hh, mm, ss;
3097 /* NOTE: the test for ptr[ 0 ] == '-'
3098 * should go before the call to strtoul() */
3099 dd = strtoul( ptr, &next, 10 );
3100 if ( ptr[ 0 ] == '-' || next == ptr || next[0] != ':' ) {
3101 snprintf( c->msg, sizeof( c->msg ),
3102 "Error: parse_syncrepl_line: "
3103 "invalid interval \"%s\", unable to parse days", val );
3104 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3108 hh = strtoul( ptr, &next, 10 );
3109 if ( ptr[ 0 ] == '-' || next == ptr || next[0] != ':' || hh > 24 ) {
3110 snprintf( c->msg, sizeof( c->msg ),
3111 "Error: parse_syncrepl_line: "
3112 "invalid interval \"%s\", unable to parse hours", val );
3113 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3117 mm = strtoul( ptr, &next, 10 );
3118 if ( ptr[ 0 ] == '-' || next == ptr || next[0] != ':' || mm > 60 ) {
3119 snprintf( c->msg, sizeof( c->msg ),
3120 "Error: parse_syncrepl_line: "
3121 "invalid interval \"%s\", unable to parse minutes", val );
3122 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3126 ss = strtoul( ptr, &next, 10 );
3127 if ( ptr[ 0 ] == '-' || next == ptr || next[0] != '\0' || ss > 60 ) {
3128 snprintf( c->msg, sizeof( c->msg ),
3129 "Error: parse_syncrepl_line: "
3130 "invalid interval \"%s\", unable to parse seconds", val );
3131 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3134 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
3138 if ( lutil_parse_time( val, &t ) != 0 ) {
3139 snprintf( c->msg, sizeof( c->msg ),
3140 "Error: parse_syncrepl_line: "
3141 "invalid interval \"%s\"", val );
3142 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3145 si->si_interval = (time_t)t;
3147 if ( si->si_interval < 0 ) {
3148 snprintf( c->msg, sizeof( c->msg ),
3149 "Error: parse_syncrepl_line: "
3150 "invalid interval \"%ld\"",
3151 (long) si->si_interval);
3152 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3155 } else if ( !strncasecmp( c->argv[ i ], RETRYSTR "=",
3156 STRLENOF( RETRYSTR "=" ) ) )
3161 val = c->argv[ i ] + STRLENOF( RETRYSTR "=" );
3162 retry_list = (char **) ch_calloc( 1, sizeof( char * ));
3163 retry_list[0] = NULL;
3165 slap_str2clist( &retry_list, val, " ,\t" );
3167 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
3170 snprintf( c->msg, sizeof( c->msg ),
3171 "Error: incomplete syncrepl retry list" );
3172 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3173 for ( k = 0; retry_list && retry_list[k]; k++ ) {
3174 ch_free( retry_list[k] );
3176 ch_free( retry_list );
3179 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
3180 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
3181 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
3182 for ( j = 0; j < n; j++ ) {
3184 if ( lutil_atoul( &t, retry_list[j*2] ) != 0 ) {
3185 snprintf( c->msg, sizeof( c->msg ),
3186 "Error: invalid retry interval \"%s\" (#%d)",
3187 retry_list[j*2], j );
3188 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3189 /* do some cleanup */
3192 si->si_retryinterval[j] = (time_t)t;
3193 if ( *retry_list[j*2+1] == '+' ) {
3194 si->si_retrynum_init[j] = RETRYNUM_FOREVER;
3195 si->si_retrynum[j] = RETRYNUM_FOREVER;
3199 if ( lutil_atoi( &si->si_retrynum_init[j], retry_list[j*2+1] ) != 0
3200 || si->si_retrynum_init[j] <= 0 )
3202 snprintf( c->msg, sizeof( c->msg ),
3203 "Error: invalid initial retry number \"%s\" (#%d)",
3204 retry_list[j*2+1], j );
3205 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3206 /* do some cleanup */
3209 if ( lutil_atoi( &si->si_retrynum[j], retry_list[j*2+1] ) != 0
3210 || si->si_retrynum[j] <= 0 )
3212 snprintf( c->msg, sizeof( c->msg ),
3213 "Error: invalid retry number \"%s\" (#%d)",
3214 retry_list[j*2+1], j );
3215 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3216 /* do some cleanup */
3221 si->si_retrynum_init[j] = RETRYNUM_TAIL;
3222 si->si_retrynum[j] = RETRYNUM_TAIL;
3223 si->si_retryinterval[j] = 0;
3225 for ( k = 0; retry_list && retry_list[k]; k++ ) {
3226 ch_free( retry_list[k] );
3228 ch_free( retry_list );
3229 } else if ( !strncasecmp( c->argv[ i ], MANAGEDSAITSTR "=",
3230 STRLENOF( MANAGEDSAITSTR "=" ) ) )
3232 val = c->argv[ i ] + STRLENOF( MANAGEDSAITSTR "=" );
3233 if ( lutil_atoi( &si->si_manageDSAit, val ) != 0
3234 || si->si_manageDSAit < 0 || si->si_manageDSAit > 1 )
3236 snprintf( c->msg, sizeof( c->msg ),
3237 "invalid manageDSAit value \"%s\".\n",
3239 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3242 } else if ( !strncasecmp( c->argv[ i ], SLIMITSTR "=",
3243 STRLENOF( SLIMITSTR "=") ) )
3245 val = c->argv[ i ] + STRLENOF( SLIMITSTR "=" );
3246 if ( strcasecmp( val, "unlimited" ) == 0 ) {
3249 } else if ( lutil_atoi( &si->si_slimit, val ) != 0 || si->si_slimit < 0 ) {
3250 snprintf( c->msg, sizeof( c->msg ),
3251 "invalid size limit value \"%s\".\n",
3253 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3256 } else if ( !strncasecmp( c->argv[ i ], TLIMITSTR "=",
3257 STRLENOF( TLIMITSTR "=" ) ) )
3259 val = c->argv[ i ] + STRLENOF( TLIMITSTR "=" );
3260 if ( strcasecmp( val, "unlimited" ) == 0 ) {
3263 } else if ( lutil_atoi( &si->si_tlimit, val ) != 0 || si->si_tlimit < 0 ) {
3264 snprintf( c->msg, sizeof( c->msg ),
3265 "invalid time limit value \"%s\".\n",
3267 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3270 } else if ( !strncasecmp( c->argv[ i ], SYNCDATASTR "=",
3271 STRLENOF( SYNCDATASTR "=" ) ) )
3273 val = c->argv[ i ] + STRLENOF( SYNCDATASTR "=" );
3274 si->si_syncdata = verb_to_mask( val, datamodes );
3275 } else if ( bindconf_parse( c->argv[i], &si->si_bindconf ) ) {
3276 snprintf( c->msg, sizeof( c->msg ),
3277 "Error: parse_syncrepl_line: "
3278 "unable to parse \"%s\"\n", c->argv[ i ] );
3279 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3284 if ( gots != GOT_ALL ) {
3285 snprintf( c->msg, sizeof( c->msg ),
3286 "Error: Malformed \"syncrepl\" line in slapd config file, missing%s%s%s",
3287 gots & GOT_ID ? "" : " "IDSTR,
3288 gots & GOT_PROVIDER ? "" : " "PROVIDERSTR,
3289 gots & GOT_BASE ? "" : " "SEARCHBASESTR );
3290 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3304 if ( !( c->be->be_search && c->be->be_add && c->be->be_modify && c->be->be_delete ) ) {
3305 snprintf( c->msg, sizeof(c->msg), "database %s does not support "
3306 "operations required for syncrepl", c->be->be_type );
3307 Debug( LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
3310 if ( BER_BVISEMPTY( &c->be->be_rootdn )) {
3311 strcpy( c->msg, "rootDN must be defined before syncrepl may be used" );
3312 Debug( LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
3315 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
3318 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
3322 si->si_bindconf.sb_tls = SB_TLS_OFF;
3323 si->si_bindconf.sb_method = LDAP_AUTH_SIMPLE;
3324 si->si_schemachecking = 0;
3325 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
3326 &si->si_filterstr );
3327 si->si_base.bv_val = NULL;
3328 si->si_scope = LDAP_SCOPE_SUBTREE;
3329 si->si_attrsonly = 0;
3330 si->si_anlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
3331 si->si_exanlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
3332 si->si_attrs = NULL;
3333 si->si_allattrs = 0;
3334 si->si_allopattrs = 0;
3335 si->si_exattrs = NULL;
3336 si->si_type = si->si_ctype = LDAP_SYNC_REFRESH_ONLY;
3337 si->si_interval = 86400;
3338 si->si_retryinterval = NULL;
3339 si->si_retrynum_init = NULL;
3340 si->si_retrynum = NULL;
3341 si->si_manageDSAit = 0;
3344 si->si_conn_setup = 0;
3346 si->si_presentlist = NULL;
3347 LDAP_LIST_INIT( &si->si_nonpresentlist );
3348 ldap_pvt_thread_mutex_init( &si->si_mutex );
3350 rc = parse_syncrepl_line( c, si );
3353 /* Must be LDAPv3 because we need controls */
3354 switch ( si->si_bindconf.sb_version ) {
3356 /* not explicitly set */
3357 si->si_bindconf.sb_version = LDAP_VERSION3;
3360 /* explicitly set */
3363 Debug( LDAP_DEBUG_ANY,
3364 "version %d incompatible with syncrepl\n",
3365 si->si_bindconf.sb_version, 0, 0 );
3366 syncinfo_free( si );
3371 if ( slapMode & SLAP_SERVER_MODE ) {
3372 Listener **l = slapd_get_listeners();
3375 /* check if URL points to current server. If so, ignore
3376 * this configuration. We require an exact match. Just
3377 * in case they really want to do this, they can vary
3378 * the case of the URL to allow it.
3382 for ( i=0; l[i]; i++ ) {
3383 if ( bvmatch( &l[i]->sl_url, &si->si_bindconf.sb_uri )) {
3391 init_syncrepl( si );
3392 si->si_re = ldap_pvt_runqueue_insert( &slapd_rq,
3393 si->si_interval, do_syncrepl, si, "do_syncrepl",
3394 c->be->be_suffix[0].bv_val );
3396 rc = config_sync_shadow( c ) ? -1 : 0;
3404 /* Use main slapd defaults */
3405 bindconf_tls_defaults( &si->si_bindconf );
3408 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
3409 syncinfo_free( si );
3412 Debug( LDAP_DEBUG_CONFIG,
3413 "Config: ** successfully added syncrepl \"%s\"\n",
3414 BER_BVISNULL( &si->si_bindconf.sb_uri ) ?
3415 "(null)" : si->si_bindconf.sb_uri.bv_val, 0, 0 );
3416 if ( !si->si_schemachecking ) {
3417 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
3419 c->be->be_syncinfo = si;
3425 syncrepl_unparse( syncinfo_t *si, struct berval *bv )
3427 struct berval bc, uri;
3428 char buf[BUFSIZ*2], *ptr;
3431 #define WHATSLEFT ( sizeof( buf ) - ( ptr - buf ) )
3435 /* temporarily inhibit bindconf from printing URI */
3436 uri = si->si_bindconf.sb_uri;
3437 BER_BVZERO( &si->si_bindconf.sb_uri );
3438 si->si_bindconf.sb_version = 0;
3439 bindconf_unparse( &si->si_bindconf, &bc );
3440 si->si_bindconf.sb_uri = uri;
3441 si->si_bindconf.sb_version = LDAP_VERSION3;
3444 ptr += snprintf( ptr, WHATSLEFT, IDSTR "=%03ld " PROVIDERSTR "=%s",
3445 si->si_rid, si->si_bindconf.sb_uri.bv_val );
3446 if ( ptr - buf >= sizeof( buf ) ) return;
3447 if ( !BER_BVISNULL( &bc )) {
3448 if ( WHATSLEFT <= bc.bv_len ) {
3452 ptr = lutil_strcopy( ptr, bc.bv_val );
3455 if ( !BER_BVISEMPTY( &si->si_filterstr )) {
3456 if ( WHATSLEFT <= STRLENOF( " " FILTERSTR "=\"" "\"" ) + si->si_filterstr.bv_len ) return;
3457 ptr = lutil_strcopy( ptr, " " FILTERSTR "=\"" );
3458 ptr = lutil_strcopy( ptr, si->si_filterstr.bv_val );
3461 if ( !BER_BVISNULL( &si->si_base )) {
3462 if ( WHATSLEFT <= STRLENOF( " " SEARCHBASESTR "=\"" "\"" ) + si->si_base.bv_len ) return;
3463 ptr = lutil_strcopy( ptr, " " SEARCHBASESTR "=\"" );
3464 ptr = lutil_strcopy( ptr, si->si_base.bv_val );
3467 if ( !BER_BVISEMPTY( &si->si_logfilterstr )) {
3468 if ( WHATSLEFT <= STRLENOF( " " LOGFILTERSTR "=\"" "\"" ) + si->si_logfilterstr.bv_len ) return;
3469 ptr = lutil_strcopy( ptr, " " LOGFILTERSTR "=\"" );
3470 ptr = lutil_strcopy( ptr, si->si_logfilterstr.bv_val );
3473 if ( !BER_BVISNULL( &si->si_logbase )) {
3474 if ( WHATSLEFT <= STRLENOF( " " LOGBASESTR "=\"" "\"" ) + si->si_logbase.bv_len ) return;
3475 ptr = lutil_strcopy( ptr, " " LOGBASESTR "=\"" );
3476 ptr = lutil_strcopy( ptr, si->si_logbase.bv_val );
3479 for (i=0; !BER_BVISNULL(&scopes[i].key);i++) {
3480 if ( si->si_scope == scopes[i].val ) {
3481 if ( WHATSLEFT <= STRLENOF( " " SCOPESTR "=" ) + scopes[i].key.bv_len ) return;
3482 ptr = lutil_strcopy( ptr, " " SCOPESTR "=" );
3483 ptr = lutil_strcopy( ptr, scopes[i].key.bv_val );
3487 if ( si->si_attrsonly ) {
3488 if ( WHATSLEFT <= STRLENOF( " " ATTRSONLYSTR "=\"" "\"" ) ) return;
3489 ptr = lutil_strcopy( ptr, " " ATTRSONLYSTR );
3491 if ( si->si_anfile ) {
3492 if ( WHATSLEFT <= STRLENOF( " " ATTRSSTR "=\":include:" "\"" ) + strlen( si->si_anfile ) ) return;
3493 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=:include:\"" );
3494 ptr = lutil_strcopy( ptr, si->si_anfile );
3496 } else if ( si->si_allattrs || si->si_allopattrs ||
3497 ( si->si_anlist && !BER_BVISNULL(&si->si_anlist[0].an_name) ))
3501 if ( WHATSLEFT <= STRLENOF( " " ATTRSONLYSTR "=\"" "\"" ) ) return;
3502 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=\"" );
3504 /* FIXME: add check for overflow */
3505 ptr = anlist_unparse( si->si_anlist, ptr, WHATSLEFT );
3506 if ( si->si_allattrs ) {
3507 if ( WHATSLEFT <= STRLENOF( ",*\"" ) ) return;
3508 if ( old != ptr ) *ptr++ = ',';
3511 if ( si->si_allopattrs ) {
3512 if ( WHATSLEFT <= STRLENOF( ",+\"" ) ) return;
3513 if ( old != ptr ) *ptr++ = ',';
3518 if ( si->si_exanlist && !BER_BVISNULL(&si->si_exanlist[0].an_name) ) {
3519 if ( WHATSLEFT <= STRLENOF( " " EXATTRSSTR "=" ) ) return;
3520 ptr = lutil_strcopy( ptr, " " EXATTRSSTR "=" );
3521 /* FIXME: add check for overflow */
3522 ptr = anlist_unparse( si->si_exanlist, ptr, WHATSLEFT );
3524 if ( WHATSLEFT <= STRLENOF( " " SCHEMASTR "=" ) + STRLENOF( "off" ) ) return;
3525 ptr = lutil_strcopy( ptr, " " SCHEMASTR "=" );
3526 ptr = lutil_strcopy( ptr, si->si_schemachecking ? "on" : "off" );
3528 if ( WHATSLEFT <= STRLENOF( " " TYPESTR "=" ) + STRLENOF( "refreshAndPersist" ) ) return;
3529 ptr = lutil_strcopy( ptr, " " TYPESTR "=" );
3530 ptr = lutil_strcopy( ptr, si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ?
3531 "refreshAndPersist" : "refreshOnly" );
3533 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
3536 dd = si->si_interval;
3543 ptr = lutil_strcopy( ptr, " " INTERVALSTR "=" );
3544 ptr += snprintf( ptr, WHATSLEFT, "%02d:%02d:%02d:%02d", dd, hh, mm, ss );
3545 if ( ptr - buf >= sizeof( buf ) ) return;
3546 } else if ( si->si_retryinterval ) {
3548 if ( WHATSLEFT <= STRLENOF( " " RETRYSTR "=\"" "\"" ) ) return;
3549 ptr = lutil_strcopy( ptr, " " RETRYSTR "=\"" );
3550 for (i=0; si->si_retryinterval[i]; i++) {
3551 if ( space ) *ptr++ = ' ';
3553 ptr += snprintf( ptr, WHATSLEFT, "%ld ", (long) si->si_retryinterval[i] );
3554 if ( si->si_retrynum_init[i] == RETRYNUM_FOREVER )
3557 ptr += snprintf( ptr, WHATSLEFT, "%d", si->si_retrynum_init[i] );
3559 if ( WHATSLEFT <= STRLENOF( "\"" ) ) return;
3563 if ( si->si_slimit ) {
3564 if ( WHATSLEFT <= STRLENOF( " " SLIMITSTR "=" ) ) return;
3565 ptr = lutil_strcopy( ptr, " " SLIMITSTR "=" );
3566 ptr += snprintf( ptr, WHATSLEFT, "%d", si->si_slimit );
3569 if ( si->si_tlimit ) {
3570 if ( WHATSLEFT <= STRLENOF( " " TLIMITSTR "=" ) ) return;
3571 ptr = lutil_strcopy( ptr, " " TLIMITSTR "=" );
3572 ptr += snprintf( ptr, WHATSLEFT, "%d", si->si_tlimit );
3575 if ( si->si_syncdata ) {
3576 if ( enum_to_verb( datamodes, si->si_syncdata, &bc ) >= 0 ) {
3577 if ( WHATSLEFT <= STRLENOF( " " SYNCDATASTR "=" ) + bc.bv_len ) return;
3578 ptr = lutil_strcopy( ptr, " " SYNCDATASTR "=" );
3579 ptr = lutil_strcopy( ptr, bc.bv_val );
3582 bc.bv_len = ptr - buf;
3584 ber_dupbv( bv, &bc );
3588 syncrepl_config( ConfigArgs *c )
3590 if (c->op == SLAP_CONFIG_EMIT) {
3591 if ( c->be->be_syncinfo ) {
3593 syncrepl_unparse( c->be->be_syncinfo, &bv );
3594 ber_bvarray_add( &c->rvalue_vals, &bv );
3598 } else if ( c->op == LDAP_MOD_DELETE ) {
3599 if ( c->be->be_syncinfo ) {
3600 syncinfo_free( c->be->be_syncinfo );
3601 c->be->be_syncinfo = NULL;
3603 SLAP_DBFLAGS( c->be ) &= ~(SLAP_DBFLAG_SHADOW|SLAP_DBFLAG_SYNC_SHADOW);
3606 if ( SLAP_SHADOW( c->be ) ) {
3607 Debug(LDAP_DEBUG_ANY, "%s: "
3608 "syncrepl: database already shadowed.\n",
3612 return add_syncrepl( c );