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;
337 /* Use the log parameters if we're in log mode */
338 if ( si->si_syncdata && si->si_logstate == SYNCLOG_LOGGING ) {
340 if ( si->si_syncdata == SYNCDATA_ACCESSLOG )
344 lattrs[0] = ls->ls_dn.bv_val;
345 lattrs[1] = ls->ls_req.bv_val;
346 lattrs[2] = ls->ls_mod.bv_val;
347 lattrs[3] = ls->ls_newRdn.bv_val;
348 lattrs[4] = ls->ls_delRdn.bv_val;
349 lattrs[5] = ls->ls_newSup.bv_val;
350 lattrs[6] = slap_schema.si_ad_entryCSN->ad_cname.bv_val;
354 base = si->si_logbase.bv_val;
355 filter = si->si_logfilterstr.bv_val;
358 scope = LDAP_SCOPE_SUBTREE;
361 base = si->si_base.bv_val;
362 filter = si->si_filterstr.bv_val;
363 attrs = si->si_attrs;
364 attrsonly = si->si_attrsonly;
365 scope = si->si_scope;
367 if ( si->si_syncdata && si->si_logstate == SYNCLOG_FALLBACK ) {
368 si->si_type = LDAP_SYNC_REFRESH_ONLY;
370 si->si_type = si->si_ctype;
373 if ( !BER_BVISNULL( &si->si_syncCookie.octet_str ) )
375 ber_printf( ber, "{eOb}",
376 abs(si->si_type), &si->si_syncCookie.octet_str, rhint );
378 ber_printf( ber, "{eb}",
379 abs(si->si_type), rhint );
382 if ( (rc = ber_flatten2( ber, &c[0].ldctl_value, 0 ) ) == LBER_ERROR ) {
387 c[0].ldctl_oid = LDAP_CONTROL_SYNC;
388 c[0].ldctl_iscritical = si->si_type < 0;
391 if ( !BER_BVISNULL( &si->si_bindconf.sb_authzId ) ) {
392 c[1].ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
393 c[1].ldctl_value = si->si_bindconf.sb_authzId;
394 c[1].ldctl_iscritical = 1;
401 timeout.tv_sec = si->si_tlimit;
404 rc = ldap_search_ext( si->si_ld, base, scope, filter, attrs, attrsonly,
405 ctrls, NULL, si->si_tlimit > 0 ? &timeout : NULL,
406 si->si_slimit, &msgid );
417 int cmdline_cookie_found = 0;
419 struct sync_cookie *sc = NULL;
425 psub = &si->si_be->be_nsuffix[0];
427 rc = slap_client_connect( &si->si_ld, &si->si_bindconf );
428 if ( rc != LDAP_SUCCESS ) {
431 op->o_protocol = LDAP_VERSION3;
433 /* Set SSF to strongest of TLS, SASL SSFs */
436 op->o_transport_ssf = 0;
438 if ( ldap_get_option( si->si_ld, LDAP_OPT_X_TLS_SSL_CTX, &ssl )
439 == LDAP_SUCCESS && ssl != NULL )
441 op->o_tls_ssf = ldap_pvt_tls_get_strength( ssl );
443 #endif /* HAVE_TLS */
444 ldap_get_option( si->si_ld, LDAP_OPT_X_SASL_SSF, &op->o_sasl_ssf );
445 op->o_ssf = ( op->o_sasl_ssf > op->o_tls_ssf )
446 ? op->o_sasl_ssf : op->o_tls_ssf;
449 if ( BER_BVISNULL( &si->si_syncCookie.octet_str ) ) {
450 /* get contextCSN shadow replica from database */
451 BerVarray csn = NULL;
453 assert( si->si_rid < 1000 );
454 op->o_req_ndn = op->o_bd->be_nsuffix[0];
455 op->o_req_dn = op->o_req_ndn;
457 /* try to read stored contextCSN */
458 backend_attribute( op, NULL, &op->o_req_ndn,
459 slap_schema.si_ad_contextCSN, &csn, ACL_READ );
461 ch_free( si->si_syncCookie.ctxcsn.bv_val );
462 ber_dupbv( &si->si_syncCookie.ctxcsn, csn );
463 ber_bvarray_free_x( csn, op->o_tmpmemctx );
466 si->si_syncCookie.rid = si->si_rid;
468 LDAP_STAILQ_FOREACH( sc, &slap_sync_cookie, sc_next ) {
469 if ( si->si_rid == sc->rid ) {
470 cmdline_cookie_found = 1;
475 if ( cmdline_cookie_found ) {
476 /* cookie is supplied in the command line */
478 LDAP_STAILQ_REMOVE( &slap_sync_cookie, sc, sync_cookie, sc_next );
480 /* ctxcsn wasn't parsed yet, do it now */
481 slap_parse_sync_cookie( sc, op->o_tmpmemctx );
482 if ( BER_BVISNULL( &sc->ctxcsn ) ) {
483 /* if cmdline cookie does not have ctxcsn */
484 /* component, set it to an initial value */
485 slap_init_sync_cookie_ctxcsn( sc );
487 slap_sync_cookie_free( &si->si_syncCookie, 0 );
488 slap_dup_sync_cookie( &si->si_syncCookie, sc );
489 slap_sync_cookie_free( sc, 1 );
492 slap_compose_sync_cookie( NULL, &si->si_syncCookie.octet_str,
493 &si->si_syncCookie.ctxcsn, si->si_syncCookie.rid );
496 rc = ldap_sync_search( si, op->o_tmpmemctx );
498 if( rc != LDAP_SUCCESS ) {
499 Debug( LDAP_DEBUG_ANY, "do_syncrep1: rid %03ld "
500 "ldap_search_ext: %s (%d)\n",
501 si->si_rid, ldap_err2string( rc ), rc );
507 ldap_unbind_ext( si->si_ld, NULL, NULL );
520 LDAPControl **rctrls = NULL;
523 BerElementBuffer berbuf;
524 BerElement *ber = (BerElement *)&berbuf;
526 LDAPMessage *res = NULL;
527 LDAPMessage *msg = NULL;
530 struct berval *retdata = NULL;
535 struct berval syncUUID = BER_BVNULL;
536 struct sync_cookie syncCookie = { BER_BVNULL };
537 struct sync_cookie syncCookie_req = { BER_BVNULL };
538 struct berval cookie = BER_BVNULL;
544 Modifications *modlist = NULL;
549 struct timeval *tout_p = NULL;
550 struct timeval tout = { 0, 0 };
552 int refreshDeletes = 0;
554 BerVarray syncUUIDs = NULL;
557 if ( slapd_shutdown ) {
562 ber_init2( ber, NULL, LBER_USE_DER );
563 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
565 Debug( LDAP_DEBUG_TRACE, "=>do_syncrep2 rid %03ld\n", si->si_rid, 0, 0 );
567 psub = &si->si_be->be_nsuffix[0];
569 slap_dup_sync_cookie( &syncCookie_req, &si->si_syncCookie );
571 if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST ) {
577 while ( ( rc = ldap_result( si->si_ld, LDAP_RES_ANY, LDAP_MSG_ONE,
578 tout_p, &res ) ) > 0 )
580 if ( slapd_shutdown ) {
584 for( msg = ldap_first_message( si->si_ld, res );
586 msg = ldap_next_message( si->si_ld, msg ) )
588 if ( slapd_shutdown ) {
592 switch( ldap_msgtype( msg ) ) {
593 case LDAP_RES_SEARCH_ENTRY:
594 ldap_get_entry_controls( si->si_ld, msg, &rctrls );
595 /* we can't work without the control */
598 /* NOTE: make sure we use the right one;
599 * a better approach would be to run thru
600 * the whole list and take care of all */
601 rctrlp = ldap_find_control( LDAP_CONTROL_SYNC_STATE, rctrls );
603 if ( rctrlp == NULL ) {
604 Debug( LDAP_DEBUG_ANY, "do_syncrep2: rid %03ld "
605 "got search entry without "
606 "Sync State control\n", si->si_rid, 0, 0 );
610 ber_init2( ber, &rctrlp->ldctl_value, LBER_USE_DER );
611 ber_scanf( ber, "{em" /*"}"*/, &syncstate, &syncUUID );
612 /* FIXME: what if syncUUID is NULL or empty?
613 * (happens with back-sql...) */
614 if ( BER_BVISEMPTY( &syncUUID ) ) {
615 Debug( LDAP_DEBUG_ANY, "do_syncrep2: rid %03ld "
616 "got empty syncUUID\n", si->si_rid, 0, 0 );
617 ldap_controls_free( rctrls );
621 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
622 ber_scanf( ber, /*"{"*/ "m}", &cookie );
623 if ( !BER_BVISNULL( &cookie ) ) {
624 ch_free( syncCookie.octet_str.bv_val );
625 ber_dupbv( &syncCookie.octet_str, &cookie );
627 if ( !BER_BVISNULL( &syncCookie.octet_str ) )
629 slap_parse_sync_cookie( &syncCookie, NULL );
633 if ( si->si_syncdata && si->si_logstate == SYNCLOG_LOGGING ) {
635 if ( ( rc = syncrepl_message_to_op( si, op, msg ) ) == LDAP_SUCCESS &&
636 !BER_BVISNULL( &syncCookie.ctxcsn ) )
638 rc = syncrepl_updateCookie( si, op, psub, &syncCookie );
640 } else if ( ( rc = syncrepl_message_to_entry( si, op, msg,
641 &modlist, &entry, syncstate ) ) == LDAP_SUCCESS )
643 if ( ( rc = syncrepl_entry( si, op, entry, &modlist,
644 syncstate, &syncUUID, &syncCookie_req,
645 &syncCookie.ctxcsn ) ) == LDAP_SUCCESS &&
646 !BER_BVISNULL( &syncCookie.ctxcsn ) )
648 rc = syncrepl_updateCookie( si, op, psub, &syncCookie );
651 ldap_controls_free( rctrls );
653 slap_mods_free( modlist, 1 );
659 case LDAP_RES_SEARCH_REFERENCE:
660 Debug( LDAP_DEBUG_ANY,
661 "do_syncrep2: rid %03ld reference received error\n",
665 case LDAP_RES_SEARCH_RESULT:
666 Debug( LDAP_DEBUG_SYNC,
667 "do_syncrep2: rid %03ld LDAP_RES_SEARCH_RESULT\n",
669 ldap_parse_result( si->si_ld, msg, &err, NULL, NULL, NULL,
671 #ifdef LDAP_X_SYNC_REFRESH_REQUIRED
672 if ( err == LDAP_X_SYNC_REFRESH_REQUIRED ) {
673 /* map old result code to registered code */
674 err = LDAP_SYNC_REFRESH_REQUIRED;
677 if ( err == LDAP_SYNC_REFRESH_REQUIRED ) {
678 if ( si->si_logstate == SYNCLOG_LOGGING ) {
679 si->si_logstate = SYNCLOG_FALLBACK;
686 ber_init2( ber, &rctrlp->ldctl_value, LBER_USE_DER );
688 ber_scanf( ber, "{" /*"}"*/);
689 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
690 ber_scanf( ber, "m", &cookie );
691 if ( !BER_BVISNULL( &cookie ) ) {
692 ch_free( syncCookie.octet_str.bv_val );
693 ber_dupbv( &syncCookie.octet_str, &cookie);
695 if ( !BER_BVISNULL( &syncCookie.octet_str ) )
697 slap_parse_sync_cookie( &syncCookie, NULL );
700 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_REFRESHDELETES )
702 ber_scanf( ber, "b", &refreshDeletes );
704 ber_scanf( ber, /*"{"*/ "}" );
706 if ( BER_BVISNULL( &syncCookie_req.ctxcsn ) ) {
708 } else if ( BER_BVISNULL( &syncCookie.ctxcsn ) ) {
711 value_match( &match, slap_schema.si_ad_entryCSN,
712 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
713 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
714 &syncCookie_req.ctxcsn, &syncCookie.ctxcsn,
718 ldap_controls_free( rctrls );
720 if (si->si_type != LDAP_SYNC_REFRESH_AND_PERSIST) {
721 /* FIXME : different error behaviors according to
722 * 1) err code : LDAP_BUSY ...
723 * 2) on err policy : stop service, stop sync, retry
725 if ( refreshDeletes == 0 && match < 0 &&
726 err == LDAP_SUCCESS )
728 syncrepl_del_nonpresent( op, si, NULL, &syncCookie.ctxcsn );
730 avl_free( si->si_presentlist, avl_ber_bvfree );
731 si->si_presentlist = NULL;
734 if ( !BER_BVISNULL( &syncCookie.ctxcsn ) &&
735 match < 0 && err == LDAP_SUCCESS )
737 rc = syncrepl_updateCookie( si, op, psub, &syncCookie );
739 if ( err == LDAP_SUCCESS
740 && si->si_logstate == SYNCLOG_FALLBACK ) {
741 si->si_logstate = SYNCLOG_LOGGING;
742 rc = LDAP_SYNC_REFRESH_REQUIRED;
749 case LDAP_RES_INTERMEDIATE:
750 rc = ldap_parse_intermediate( si->si_ld, msg,
751 &retoid, &retdata, NULL, 0 );
752 if ( !rc && !strcmp( retoid, LDAP_SYNC_INFO ) ) {
753 ber_init2( ber, retdata, LBER_USE_DER );
755 switch ( si_tag = ber_peek_tag( ber, &len ) ) {
757 case LDAP_TAG_SYNC_NEW_COOKIE:
758 Debug( LDAP_DEBUG_SYNC,
759 "do_syncrep2: rid %03ld %s - %s\n",
761 "LDAP_RES_INTERMEDIATE",
763 ber_scanf( ber, "tm", &tag, &cookie );
765 case LDAP_TAG_SYNC_REFRESH_DELETE:
766 case LDAP_TAG_SYNC_REFRESH_PRESENT:
767 Debug( LDAP_DEBUG_SYNC,
768 "do_syncrep2: rid %03ld %s - %s\n",
770 "LDAP_RES_INTERMEDIATE",
771 si_tag == LDAP_TAG_SYNC_REFRESH_PRESENT ?
772 "REFRESH_PRESENT" : "REFRESH_DELETE" );
773 if ( si_tag == LDAP_TAG_SYNC_REFRESH_DELETE ) {
774 si->si_refreshDelete = 1;
776 si->si_refreshPresent = 1;
778 ber_scanf( ber, "t{" /*"}"*/, &tag );
779 if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE )
781 ber_scanf( ber, "m", &cookie );
782 if ( !BER_BVISNULL( &cookie ) ) {
783 ch_free( syncCookie.octet_str.bv_val );
784 ber_dupbv( &syncCookie.octet_str, &cookie );
786 if ( !BER_BVISNULL( &syncCookie.octet_str ) )
788 slap_parse_sync_cookie( &syncCookie, NULL );
791 if ( ber_peek_tag( ber, &len ) ==
792 LDAP_TAG_REFRESHDONE )
794 ber_scanf( ber, "b", &refreshDone );
796 ber_scanf( ber, /*"{"*/ "}" );
798 case LDAP_TAG_SYNC_ID_SET:
799 Debug( LDAP_DEBUG_SYNC,
800 "do_syncrep2: rid %03ld %s - %s\n",
802 "LDAP_RES_INTERMEDIATE",
804 ber_scanf( ber, "t{" /*"}"*/, &tag );
805 if ( ber_peek_tag( ber, &len ) ==
806 LDAP_TAG_SYNC_COOKIE )
808 ber_scanf( ber, "m", &cookie );
809 if ( !BER_BVISNULL( &cookie ) ) {
810 ch_free( syncCookie.octet_str.bv_val );
811 ber_dupbv( &syncCookie.octet_str, &cookie );
813 if ( !BER_BVISNULL( &syncCookie.octet_str ) )
815 slap_parse_sync_cookie( &syncCookie, NULL );
818 if ( ber_peek_tag( ber, &len ) ==
819 LDAP_TAG_REFRESHDELETES )
821 ber_scanf( ber, "b", &refreshDeletes );
823 ber_scanf( ber, "[W]", &syncUUIDs );
824 ber_scanf( ber, /*"{"*/ "}" );
825 if ( refreshDeletes ) {
826 syncrepl_del_nonpresent( op, si, syncUUIDs,
827 &syncCookie.ctxcsn );
828 ber_bvarray_free_x( syncUUIDs, op->o_tmpmemctx );
831 for ( i = 0; !BER_BVISNULL( &syncUUIDs[i] ); i++ ) {
832 struct berval *syncuuid_bv;
833 syncuuid_bv = ber_dupbv( NULL, &syncUUIDs[i] );
834 slap_sl_free( syncUUIDs[i].bv_val,op->o_tmpmemctx );
835 if ( avl_insert( &si->si_presentlist,
836 (caddr_t) syncuuid_bv,
837 syncuuid_cmp, avl_dup_error ) )
839 ber_bvfree( syncuuid_bv );
842 slap_sl_free( syncUUIDs, op->o_tmpmemctx );
844 slap_sync_cookie_free( &syncCookie, 0 );
847 Debug( LDAP_DEBUG_ANY,
848 "do_syncrep2: rid %03ld unknown syncinfo tag (%ld)\n",
849 si->si_rid, (long) si_tag, 0 );
850 ldap_memfree( retoid );
851 ber_bvfree( retdata );
855 if ( BER_BVISNULL( &syncCookie_req.ctxcsn ) ) {
857 } else if ( BER_BVISNULL( &syncCookie.ctxcsn ) ) {
860 value_match( &match, slap_schema.si_ad_entryCSN,
861 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
862 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
863 &syncCookie_req.ctxcsn,
864 &syncCookie.ctxcsn, &text );
868 if ( si->si_refreshPresent == 1 ) {
869 syncrepl_del_nonpresent( op, si, NULL, &syncCookie.ctxcsn );
872 if ( !BER_BVISNULL( &syncCookie.ctxcsn ) )
874 rc = syncrepl_updateCookie( si, op, psub, &syncCookie);
878 ldap_memfree( retoid );
879 ber_bvfree( retdata );
883 Debug( LDAP_DEBUG_ANY, "do_syncrep2: rid %03ld "
884 "unknown intermediate response (%d)\n",
886 ldap_memfree( retoid );
887 ber_bvfree( retdata );
893 Debug( LDAP_DEBUG_ANY, "do_syncrep2: rid %03ld "
894 "unknown message\n", si->si_rid, 0, 0 );
898 if ( !BER_BVISNULL( &syncCookie.octet_str ) ) {
899 slap_sync_cookie_free( &syncCookie_req, 0 );
900 slap_dup_sync_cookie( &syncCookie_req, &syncCookie );
901 slap_sync_cookie_free( &syncCookie, 0 );
911 ldap_get_option( si->si_ld, LDAP_OPT_ERROR_NUMBER, &rc );
912 errstr = ldap_err2string( rc );
914 Debug( LDAP_DEBUG_ANY,
915 "do_syncrep2: rid %03ld %s\n", si->si_rid, errstr, 0 );
919 slap_sync_cookie_free( &syncCookie, 0 );
920 slap_sync_cookie_free( &syncCookie_req, 0 );
922 if ( res ) ldap_msgfree( res );
924 if ( rc && rc != LDAP_SYNC_REFRESH_REQUIRED && si->si_ld ) {
925 if ( si->si_conn_setup ) {
927 ldap_get_option( si->si_ld, LDAP_OPT_DESC, &s );
928 connection_client_stop( s );
929 si->si_conn_setup = 0;
931 ldap_unbind_ext( si->si_ld, NULL, NULL );
943 struct re_s* rtask = arg;
944 syncinfo_t *si = ( syncinfo_t * ) rtask->arg;
945 Connection conn = {0};
946 OperationBuffer opbuf;
948 int rc = LDAP_SUCCESS;
954 Debug( LDAP_DEBUG_TRACE, "=>do_syncrepl rid %03ld\n", si->si_rid, 0, 0 );
959 ldap_pvt_thread_mutex_lock( &si->si_mutex );
961 switch( abs( si->si_type ) ) {
962 case LDAP_SYNC_REFRESH_ONLY:
963 case LDAP_SYNC_REFRESH_AND_PERSIST:
966 ldap_pvt_thread_mutex_unlock( &si->si_mutex );
970 if ( slapd_shutdown ) {
972 if ( si->si_conn_setup ) {
973 ldap_get_option( si->si_ld, LDAP_OPT_DESC, &s );
974 connection_client_stop( s );
975 si->si_conn_setup = 0;
977 ldap_unbind_ext( si->si_ld, NULL, NULL );
980 ldap_pvt_thread_mutex_unlock( &si->si_mutex );
984 op = (Operation *) &opbuf;
985 connection_fake_init( &conn, op, ctx );
987 /* use global malloc for now */
988 op->o_tmpmemctx = NULL;
989 op->o_tmpmfuncs = &ch_mfuncs;
991 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
992 op->o_bd = be = si->si_be;
993 op->o_dn = op->o_bd->be_rootdn;
994 op->o_ndn = op->o_bd->be_rootndn;
995 if ( !si->si_schemachecking )
996 op->o_no_schema_check = 1;
998 /* Establish session, do search */
1000 si->si_refreshDelete = 0;
1001 si->si_refreshPresent = 0;
1002 rc = do_syncrep1( op, si );
1006 /* Process results */
1007 if ( rc == LDAP_SUCCESS ) {
1008 ldap_get_option( si->si_ld, LDAP_OPT_DESC, &s );
1010 rc = do_syncrep2( op, si );
1011 if ( rc == LDAP_SYNC_REFRESH_REQUIRED ) {
1012 rc = ldap_sync_search( si, op->o_tmpmemctx );
1016 if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST ) {
1017 /* If we succeeded, enable the connection for further listening.
1018 * If we failed, tear down the connection and reschedule.
1020 if ( rc == LDAP_SUCCESS ) {
1021 if ( si->si_conn_setup ) {
1022 connection_client_enable( s );
1024 rc = connection_client_setup( s, do_syncrepl, arg );
1026 si->si_conn_setup = 1;
1028 } else if ( si->si_conn_setup ) {
1032 if ( rc == -2 ) rc = 0;
1036 /* At this point, we have 4 cases:
1037 * 1) for any hard failure, give up and remove this task
1038 * 2) for ServerDown, reschedule this task to run
1039 * 3) for Refresh and Success, reschedule to run
1040 * 4) for Persist and Success, reschedule to defer
1042 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
1044 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, rtask ) ) {
1045 ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
1049 connection_client_stop( s );
1052 if ( rc == LDAP_SUCCESS ) {
1053 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
1056 rtask->interval.tv_sec = si->si_interval;
1057 ldap_pvt_runqueue_resched( &slapd_rq, rtask, defer );
1058 if ( si->si_retrynum ) {
1059 for ( i = 0; si->si_retrynum_init[i] != RETRYNUM_TAIL; i++ ) {
1060 si->si_retrynum[i] = si->si_retrynum_init[i];
1062 si->si_retrynum[i] = RETRYNUM_TAIL;
1065 for ( i = 0; si->si_retrynum && si->si_retrynum[i] <= 0; i++ ) {
1066 if ( si->si_retrynum[i] == RETRYNUM_FOREVER || si->si_retrynum[i] == RETRYNUM_TAIL )
1070 if ( !si->si_retrynum || si->si_retrynum[i] == RETRYNUM_TAIL ) {
1071 ldap_pvt_runqueue_remove( &slapd_rq, rtask );
1072 } else if ( RETRYNUM_VALID( si->si_retrynum[i] ) ) {
1073 if ( si->si_retrynum[i] > 0 )
1074 si->si_retrynum[i]--;
1075 rtask->interval.tv_sec = si->si_retryinterval[i];
1076 ldap_pvt_runqueue_resched( &slapd_rq, rtask, 0 );
1077 slap_wake_listener();
1081 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
1082 ldap_pvt_thread_mutex_unlock( &si->si_mutex );
1087 static slap_verbmasks modops[] = {
1088 { BER_BVC("add"), LDAP_REQ_ADD },
1089 { BER_BVC("delete"), LDAP_REQ_DELETE },
1090 { BER_BVC("modify"), LDAP_REQ_MODIFY },
1091 { BER_BVC("modrdn"), LDAP_REQ_MODRDN},
1095 static Modifications *
1096 syncrepl_accesslog_mods(
1103 AttributeDescription *ad;
1104 struct berval bv, bv2;
1106 Modifications *mod = NULL, *modlist = NULL, **modtail;
1111 for (i=0; !BER_BVISNULL( &vals[i] ); i++) {
1115 colon = ber_bvchr( &bv, ':' );
1121 bv.bv_len = colon - bv.bv_val;
1122 if ( slap_bv2ad( &bv, &ad, &text ) ) {
1127 /* Ignore dynamically generated attrs */
1128 if ( ad->ad_type->sat_flags & SLAP_AT_DYNAMIC ) {
1132 /* Ignore excluded attrs */
1133 if ( ldap_charray_inlist( si->si_exattrs,
1134 ad->ad_type->sat_cname.bv_val ) )
1140 case '+': op = LDAP_MOD_ADD; break;
1141 case '-': op = LDAP_MOD_DELETE; break;
1142 case '=': op = LDAP_MOD_REPLACE; break;
1143 case '#': op = LDAP_MOD_INCREMENT; break;
1147 if ( !mod || ad != mod->sml_desc || op != mod->sml_op ) {
1148 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
1151 mod->sml_next = NULL;
1153 mod->sml_type = ad->ad_cname;
1154 mod->sml_values = NULL;
1155 mod->sml_nvalues = NULL;
1158 modtail = &mod->sml_next;
1160 if ( colon[2] == ' ' ) {
1161 bv.bv_val = colon + 3;
1162 bv.bv_len = vals[i].bv_len - ( bv.bv_val - vals[i].bv_val );
1163 ber_dupbv( &bv2, &bv );
1164 ber_bvarray_add( &mod->sml_values, &bv2 );
1170 static Modifications *
1171 syncrepl_changelog_mods(
1176 return NULL; /* FIXME */
1180 syncrepl_message_to_op(
1186 BerElement *ber = NULL;
1187 Modifications *modlist = NULL;
1189 SlapReply rs = { REP_RESULT };
1190 slap_callback cb = { NULL, null_callback, NULL, NULL };
1193 char txtbuf[SLAP_TEXT_BUFLEN];
1194 size_t textlen = sizeof txtbuf;
1196 struct berval bdn, dn = BER_BVNULL, ndn;
1197 struct berval bv, *bvals = NULL;
1198 struct berval rdn = BER_BVNULL, sup = BER_BVNULL,
1199 prdn = BER_BVNULL, nrdn = BER_BVNULL,
1200 psup = BER_BVNULL, nsup = BER_BVNULL;
1201 int rc, deleteOldRdn = 0, freeReqDn = 0;
1203 if ( ldap_msgtype( msg ) != LDAP_RES_SEARCH_ENTRY ) {
1204 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_op: rid %03ld "
1205 "Message type should be entry (%d)",
1206 si->si_rid, ldap_msgtype( msg ), 0 );
1210 if ( si->si_syncdata == SYNCDATA_ACCESSLOG )
1215 rc = ldap_get_dn_ber( si->si_ld, msg, &ber, &bdn );
1217 if ( rc != LDAP_SUCCESS ) {
1218 Debug( LDAP_DEBUG_ANY,
1219 "syncrepl_message_to_op: rid %03ld dn get failed (%d)",
1220 si->si_rid, rc, 0 );
1224 op->o_tag = LBER_DEFAULT;
1226 while (( rc = ldap_get_attribute_ber( si->si_ld, msg, ber, &bv, &bvals ) )
1228 if ( bv.bv_val == NULL )
1231 if ( !ber_bvstrcasecmp( &bv, &ls->ls_dn ) ) {
1233 dnPrettyNormal( NULL, &bdn, &dn, &ndn, op->o_tmpmemctx );
1234 ber_dupbv( &op->o_req_dn, &dn );
1235 ber_dupbv( &op->o_req_ndn, &ndn );
1236 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1237 slap_sl_free( dn.bv_val, op->o_tmpmemctx );
1239 } else if ( !ber_bvstrcasecmp( &bv, &ls->ls_req ) ) {
1240 int i = verb_to_mask( bvals[0].bv_val, modops );
1242 Debug( LDAP_DEBUG_ANY,
1243 "syncrepl_message_to_op: rid %03ld unknown op %s",
1244 si->si_rid, bvals[0].bv_val, 0 );
1249 op->o_tag = modops[i].mask;
1250 } else if ( !ber_bvstrcasecmp( &bv, &ls->ls_mod ) ) {
1251 /* Parse attribute into modlist */
1252 if ( si->si_syncdata == SYNCDATA_ACCESSLOG ) {
1253 modlist = syncrepl_accesslog_mods( si, bvals );
1255 modlist = syncrepl_changelog_mods( si, bvals );
1257 } else if ( !ber_bvstrcasecmp( &bv, &ls->ls_newRdn ) ) {
1259 } else if ( !ber_bvstrcasecmp( &bv, &ls->ls_delRdn ) ) {
1260 if ( !ber_bvstrcasecmp( &slap_true_bv, bvals ) ) {
1263 } else if ( !ber_bvstrcasecmp( &bv, &ls->ls_newSup ) ) {
1265 } else if ( !ber_bvstrcasecmp( &bv,
1266 &slap_schema.si_ad_entryCSN->ad_cname ) )
1268 slap_queue_csn( op, bvals );
1273 /* If we didn't get a mod type or a target DN, bail out */
1274 if ( op->o_tag == LBER_DEFAULT || BER_BVISNULL( &dn ) ) {
1279 op->o_callback = &cb;
1280 slap_op_time( &op->o_time, &op->o_tincr );
1282 switch( op->o_tag ) {
1284 case LDAP_REQ_MODIFY:
1285 /* If we didn't get required data, bail */
1286 if ( !modlist ) goto done;
1288 rc = slap_mods_check( op, modlist, &text, txtbuf, textlen, NULL );
1290 if ( rc != LDAP_SUCCESS ) {
1291 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_op: rid %03ld "
1292 "mods check (%s)\n",
1293 si->si_rid, text, 0 );
1297 if ( op->o_tag == LDAP_REQ_ADD ) {
1298 Entry *e = entry_alloc();
1300 op->ora_e->e_name = op->o_req_dn;
1301 op->ora_e->e_nname = op->o_req_ndn;
1303 rc = slap_mods2entry( modlist, &op->ora_e, 1, 0, &text, txtbuf, textlen);
1304 if( rc != LDAP_SUCCESS ) {
1305 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_op: rid %03ld "
1306 "mods2entry (%s)\n",
1307 si->si_rid, text, 0 );
1309 rc = op->o_bd->be_add( op, &rs );
1310 Debug( LDAP_DEBUG_SYNC,
1311 "syncrepl_message_to_op: rid %03ld be_add %s (%d)\n",
1312 si->si_rid, op->o_req_dn.bv_val, rc );
1314 if ( e == op->ora_e )
1315 be_entry_release_w( op, op->ora_e );
1317 op->orm_modlist = modlist;
1318 rc = op->o_bd->be_modify( op, &rs );
1319 Debug( rc ? LDAP_DEBUG_ANY : LDAP_DEBUG_SYNC,
1320 "syncrepl_message_to_op: rid %03ld be_modify %s (%d)\n",
1321 si->si_rid, op->o_req_dn.bv_val, rc );
1324 case LDAP_REQ_MODRDN:
1325 if ( BER_BVISNULL( &rdn ) ) goto done;
1327 if ( rdnPretty( NULL, &rdn, &prdn, NULL ) ) {
1330 if ( rdnNormalize( 0, NULL, NULL, &rdn, &nrdn, NULL ) ) {
1333 if ( !BER_BVISNULL( &sup ) ) {
1334 if ( dnPrettyNormal( NULL, &sup, &psup, &nsup, NULL ) ) {
1337 op->orr_newSup = &psup;
1338 op->orr_nnewSup = ⊅
1340 op->orr_newSup = NULL;
1341 op->orr_nnewSup = NULL;
1343 op->orr_newrdn = prdn;
1344 op->orr_nnewrdn = nrdn;
1345 op->orr_deleteoldrdn = deleteOldRdn;
1346 op->orr_modlist = NULL;
1347 if ( slap_modrdn2mods( op, &rs ) ) {
1351 /* Append modlist for operational attrs */
1355 for ( m = op->orr_modlist; m->sml_next; m = m->sml_next )
1357 m->sml_next = modlist;
1360 rc = op->o_bd->be_modrdn( op, &rs );
1361 slap_mods_free( op->orr_modlist, 1 );
1362 Debug( rc ? LDAP_DEBUG_ANY : LDAP_DEBUG_SYNC,
1363 "syncrepl_message_to_op: rid %03ld be_modrdn %s (%d)\n",
1364 si->si_rid, op->o_req_dn.bv_val, rc );
1366 case LDAP_REQ_DELETE:
1367 rc = op->o_bd->be_delete( op, &rs );
1368 Debug( rc ? LDAP_DEBUG_ANY : LDAP_DEBUG_SYNC,
1369 "syncrepl_message_to_op: rid %03ld be_delete %s (%d)\n",
1370 si->si_rid, op->o_req_dn.bv_val, rc );
1374 slap_graduate_commit_csn( op );
1375 op->o_tmpfree( op->o_csn.bv_val, op->o_tmpmemctx );
1376 BER_BVZERO( &op->o_csn );
1378 slap_mods_free( modlist, op->o_tag != LDAP_REQ_ADD );
1380 if ( !BER_BVISNULL( &rdn ) ) {
1381 if ( !BER_BVISNULL( &nsup ) ) {
1382 ch_free( nsup.bv_val );
1384 if ( !BER_BVISNULL( &psup ) ) {
1385 ch_free( psup.bv_val );
1387 if ( !BER_BVISNULL( &nrdn ) ) {
1388 ch_free( nrdn.bv_val );
1390 if ( !BER_BVISNULL( &prdn ) ) {
1391 ch_free( prdn.bv_val );
1395 ch_free( op->o_req_ndn.bv_val );
1396 ch_free( op->o_req_dn.bv_val );
1403 syncrepl_message_to_entry(
1407 Modifications **modlist,
1413 BerElement *ber = NULL;
1416 Modifications **modtail = modlist;
1419 char txtbuf[SLAP_TEXT_BUFLEN];
1420 size_t textlen = sizeof txtbuf;
1422 struct berval bdn = BER_BVNULL, dn, ndn;
1427 if ( ldap_msgtype( msg ) != LDAP_RES_SEARCH_ENTRY ) {
1428 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: rid %03ld "
1429 "Message type should be entry (%d)",
1430 si->si_rid, ldap_msgtype( msg ), 0 );
1434 op->o_tag = LDAP_REQ_ADD;
1436 rc = ldap_get_dn_ber( si->si_ld, msg, &ber, &bdn );
1437 if ( rc != LDAP_SUCCESS ) {
1438 Debug( LDAP_DEBUG_ANY,
1439 "syncrepl_message_to_entry: rid %03ld dn get failed (%d)",
1440 si->si_rid, rc, 0 );
1444 if ( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_DELETE ) {
1445 /* NOTE: this could be done even before decoding the DN,
1446 * although encoding errors wouldn't be detected */
1451 if ( entry == NULL ) {
1456 dnPrettyNormal( NULL, &bdn, &dn, &ndn, op->o_tmpmemctx );
1457 ber_dupbv( &op->o_req_dn, &dn );
1458 ber_dupbv( &op->o_req_ndn, &ndn );
1459 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1460 slap_sl_free( dn.bv_val, op->o_tmpmemctx );
1463 e->e_name = op->o_req_dn;
1464 e->e_nname = op->o_req_ndn;
1466 while ( ber_remaining( ber ) ) {
1467 if ( (ber_scanf( ber, "{mW}", &tmp.sml_type, &tmp.sml_values ) ==
1468 LBER_ERROR ) || BER_BVISNULL( &tmp.sml_type ) )
1473 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
1475 mod->sml_op = LDAP_MOD_REPLACE;
1477 mod->sml_next = NULL;
1478 mod->sml_desc = NULL;
1479 mod->sml_type = tmp.sml_type;
1480 mod->sml_values = tmp.sml_values;
1481 mod->sml_nvalues = NULL;
1484 modtail = &mod->sml_next;
1487 if ( *modlist == NULL ) {
1488 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: rid %03ld no attributes\n",
1494 rc = slap_mods_check( op, *modlist, &text, txtbuf, textlen, NULL );
1496 if ( rc != LDAP_SUCCESS ) {
1497 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: rid %03ld mods check (%s)\n",
1498 si->si_rid, text, 0 );
1502 /* Strip out dynamically generated attrs */
1503 for ( modtail = modlist; *modtail ; ) {
1505 if ( mod->sml_desc->ad_type->sat_flags & SLAP_AT_DYNAMIC ) {
1506 *modtail = mod->sml_next;
1507 slap_mod_free( &mod->sml_mod, 0 );
1510 modtail = &mod->sml_next;
1514 /* Strip out attrs in exattrs list */
1515 for ( modtail = modlist; *modtail ; ) {
1517 if ( ldap_charray_inlist( si->si_exattrs,
1518 mod->sml_desc->ad_type->sat_cname.bv_val ) )
1520 *modtail = mod->sml_next;
1521 slap_mod_free( &mod->sml_mod, 0 );
1524 modtail = &mod->sml_next;
1528 rc = slap_mods2entry( *modlist, &e, 1, 1, &text, txtbuf, textlen);
1529 if( rc != LDAP_SUCCESS ) {
1530 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: rid %03ld mods2entry (%s)\n",
1531 si->si_rid, text, 0 );
1536 if ( rc != LDAP_SUCCESS ) {
1547 static struct berval generic_filterstr = BER_BVC("(objectclass=*)");
1549 /* During a refresh, we may get an LDAP_SYNC_ADD for an already existing
1550 * entry if a previous refresh was interrupted before sending us a new
1551 * context state. We try to compare the new entry to the existing entry
1552 * and ignore the new entry if they are the same.
1554 * Also, we may get an update where the entryDN has changed, due to
1555 * a ModDn on the provider. We detect this as well, so we can issue
1556 * the corresponding operation locally.
1558 * In the case of a modify, we get a list of all the attributes
1559 * in the original entry. Rather than deleting the entry and re-adding it,
1560 * we issue a Modify request that deletes all the attributes and adds all
1561 * the new ones. This avoids the issue of trying to delete/add a non-leaf
1564 * We otherwise distinguish ModDN from Modify; in the case of
1565 * a ModDN we just use the CSN, modifyTimestamp and modifiersName
1566 * operational attributes from the entry, and do a regular ModDN.
1568 typedef struct dninfo {
1572 int renamed; /* Was an existing entry renamed? */
1573 int delOldRDN; /* Was old RDN deleted? */
1574 Modifications **modlist; /* the modlist we received */
1575 Modifications *mods; /* the modlist we compared */
1583 Modifications** modlist,
1585 struct berval* syncUUID,
1586 struct sync_cookie* syncCookie_req,
1587 struct berval* syncCSN )
1589 Backend *be = op->o_bd;
1590 slap_callback cb = { NULL, NULL, NULL, NULL };
1591 struct berval *syncuuid_bv = NULL;
1592 struct berval syncUUID_strrep = BER_BVNULL;
1593 struct berval uuid_bv = BER_BVNULL;
1595 SlapReply rs_search = {REP_RESULT};
1596 SlapReply rs_delete = {REP_RESULT};
1597 SlapReply rs_add = {REP_RESULT};
1598 SlapReply rs_modify = {REP_RESULT};
1600 #ifdef LDAP_COMP_MATCH
1601 AttributeAssertion ava = { NULL, BER_BVNULL, NULL };
1603 AttributeAssertion ava = { NULL, BER_BVNULL };
1605 int rc = LDAP_SUCCESS;
1607 struct berval pdn = BER_BVNULL;
1611 switch( syncstate ) {
1612 case LDAP_SYNC_PRESENT:
1613 Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03ld %s\n",
1615 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_PRESENT)", 0 );
1618 Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03ld %s\n",
1620 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_ADD)", 0 );
1622 case LDAP_SYNC_DELETE:
1623 Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03ld %s\n",
1625 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_DELETE)", 0 );
1627 case LDAP_SYNC_MODIFY:
1628 Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03ld %s\n",
1630 "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_MODIFY)", 0 );
1633 Debug( LDAP_DEBUG_ANY, "syncrepl_entry: rid %03ld %s\n",
1635 "LDAP_RES_SEARCH_ENTRY(UNKNOWN syncstate)", 0 );
1638 if (( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD ) ) {
1639 if ( !si->si_refreshPresent ) {
1640 syncuuid_bv = ber_dupbv( NULL, syncUUID );
1641 if ( avl_insert( &si->si_presentlist, (caddr_t) syncuuid_bv,
1642 syncuuid_cmp, avl_dup_error ) )
1644 ber_bvfree( syncuuid_bv );
1650 if ( syncstate == LDAP_SYNC_PRESENT ) {
1652 } else if ( syncstate != LDAP_SYNC_DELETE ) {
1653 if ( entry == NULL ) {
1658 (void)slap_uuidstr_from_normalized( &syncUUID_strrep, syncUUID, op->o_tmpmemctx );
1659 if ( syncstate != LDAP_SYNC_DELETE ) {
1660 Attribute *a = attr_find( entry->e_attrs, slap_schema.si_ad_entryUUID );
1663 /* add if missing */
1664 attr_merge_one( entry, slap_schema.si_ad_entryUUID,
1665 &syncUUID_strrep, syncUUID );
1667 } else if ( !bvmatch( &a->a_nvals[0], syncUUID ) ) {
1668 /* replace only if necessary */
1669 if ( a->a_nvals != a->a_vals ) {
1670 ber_memfree( a->a_nvals[0].bv_val );
1671 ber_dupbv( &a->a_nvals[0], syncUUID );
1673 ber_memfree( a->a_vals[0].bv_val );
1674 ber_dupbv( &a->a_vals[0], &syncUUID_strrep );
1678 f.f_choice = LDAP_FILTER_EQUALITY;
1680 ava.aa_desc = slap_schema.si_ad_entryUUID;
1681 ava.aa_value = *syncUUID;
1683 if ( syncuuid_bv ) {
1684 Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03ld inserted UUID %s\n",
1685 si->si_rid, syncUUID_strrep.bv_val, 0 );
1687 op->ors_filter = &f;
1689 op->ors_filterstr.bv_len = STRLENOF( "(entryUUID=)" ) + syncUUID_strrep.bv_len;
1690 op->ors_filterstr.bv_val = (char *) slap_sl_malloc(
1691 op->ors_filterstr.bv_len + 1, op->o_tmpmemctx );
1692 AC_MEMCPY( op->ors_filterstr.bv_val, "(entryUUID=", STRLENOF( "(entryUUID=" ) );
1693 AC_MEMCPY( &op->ors_filterstr.bv_val[STRLENOF( "(entryUUID=" )],
1694 syncUUID_strrep.bv_val, syncUUID_strrep.bv_len );
1695 op->ors_filterstr.bv_val[op->ors_filterstr.bv_len - 1] = ')';
1696 op->ors_filterstr.bv_val[op->ors_filterstr.bv_len] = '\0';
1698 op->o_tag = LDAP_REQ_SEARCH;
1699 op->ors_scope = LDAP_SCOPE_SUBTREE;
1700 op->ors_deref = LDAP_DEREF_NEVER;
1702 /* get the entry for this UUID */
1703 op->o_req_dn = si->si_base;
1704 op->o_req_ndn = si->si_base;
1706 op->o_time = slap_get_time();
1707 op->ors_tlimit = SLAP_NO_LIMIT;
1710 op->ors_attrs = slap_anlist_all_attributes;
1711 op->ors_attrsonly = 0;
1713 /* set callback function */
1714 op->o_callback = &cb;
1715 cb.sc_response = dn_callback;
1716 cb.sc_private = &dni;
1717 dni.new_entry = entry;
1718 dni.modlist = modlist;
1720 if ( limits_check( op, &rs_search ) == 0 ) {
1721 rc = be->be_search( op, &rs_search );
1722 Debug( LDAP_DEBUG_SYNC,
1723 "syncrepl_entry: rid %03ld be_search (%d)\n",
1724 si->si_rid, rc, 0 );
1727 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
1728 slap_sl_free( op->ors_filterstr.bv_val, op->o_tmpmemctx );
1731 cb.sc_response = null_callback;
1734 if ( entry && !BER_BVISNULL( &entry->e_name ) ) {
1735 Debug( LDAP_DEBUG_SYNC,
1736 "syncrepl_entry: rid %03ld %s\n",
1737 si->si_rid, entry->e_name.bv_val, 0 );
1739 Debug( LDAP_DEBUG_SYNC,
1740 "syncrepl_entry: rid %03ld %s\n",
1741 si->si_rid, dni.dn.bv_val ? dni.dn.bv_val : "(null)", 0 );
1744 /* Don't save the contextCSN on the inooming context entry,
1745 * we'll write it when syncrepl_updateCookie eventually
1746 * gets called. (ITS#4622)
1748 if ( syncstate == LDAP_SYNC_ADD && dn_match( &entry->e_nname,
1749 &be->be_nsuffix[0] ) )
1752 for ( ap = &entry->e_attrs; *ap; ap=&(*ap)->a_next ) {
1754 if ( a->a_desc == slap_schema.si_ad_contextCSN ) {
1762 slap_op_time( &op->o_time, &op->o_tincr );
1763 switch ( syncstate ) {
1765 case LDAP_SYNC_MODIFY:
1767 Attribute *a = attr_find( entry->e_attrs, slap_schema.si_ad_entryCSN );
1769 /* FIXME: op->o_csn is assumed to be
1770 * on the thread's slab; this needs
1771 * to be cleared ASAP.
1772 * What happens if already present?
1774 assert( BER_BVISNULL( &op->o_csn ) );
1775 op->o_csn = a->a_vals[0];
1779 if ( BER_BVISNULL( &dni.dn ) ) {
1781 op->o_req_dn = entry->e_name;
1782 op->o_req_ndn = entry->e_nname;
1783 op->o_tag = LDAP_REQ_ADD;
1786 rc = be->be_add( op, &rs_add );
1787 Debug( LDAP_DEBUG_SYNC,
1788 "syncrepl_entry: rid %03ld be_add (%d)\n",
1789 si->si_rid, rc, 0 );
1790 switch ( rs_add.sr_err ) {
1792 if ( op->ora_e == entry ) {
1793 be_entry_release_w( op, entry );
1799 /* we assume that LDAP_NO_SUCH_OBJECT is returned
1800 * only if the suffix entry is not present */
1801 case LDAP_NO_SUCH_OBJECT:
1802 rc = syncrepl_add_glue( op, entry );
1806 /* if an entry was added via syncrepl_add_glue(),
1807 * it likely has no entryUUID, so the previous
1808 * be_search() doesn't find it. In this case,
1809 * give syncrepl a chance to modify it. Also
1810 * allow for entries that were recreated with the
1811 * same DN but a different entryUUID.
1813 case LDAP_ALREADY_EXISTS:
1815 Operation op2 = *op;
1816 SlapReply rs2 = { 0 };
1817 slap_callback cb2 = { 0 };
1819 op2.o_tag = LDAP_REQ_SEARCH;
1820 op2.o_req_dn = entry->e_name;
1821 op2.o_req_ndn = entry->e_nname;
1822 op2.ors_scope = LDAP_SCOPE_BASE;
1823 op2.ors_deref = LDAP_DEREF_NEVER;
1824 op2.ors_attrs = slap_anlist_all_attributes;
1825 op2.ors_attrsonly = 0;
1826 op2.ors_limit = NULL;
1828 op2.ors_tlimit = SLAP_NO_LIMIT;
1830 f.f_choice = LDAP_FILTER_PRESENT;
1831 f.f_desc = slap_schema.si_ad_objectClass;
1832 op2.ors_filter = &f;
1833 op2.ors_filterstr = generic_filterstr;
1835 op2.o_callback = &cb2;
1836 cb2.sc_response = dn_callback;
1837 cb2.sc_private = &dni;
1839 rc = be->be_search( &op2, &rs2 );
1840 if ( rc ) goto done;
1843 slap_op_time( &op->o_time, &op->o_tincr );
1849 Debug( LDAP_DEBUG_ANY,
1850 "syncrepl_entry: rid %03ld be_add failed (%d)\n",
1851 si->si_rid, rs_add.sr_err, 0 );
1857 op->o_req_dn = dni.dn;
1858 op->o_req_ndn = dni.ndn;
1859 if ( dni.renamed ) {
1860 struct berval noldp, newp, nnewp;
1862 op->o_tag = LDAP_REQ_MODRDN;
1863 dnRdn( &entry->e_name, &op->orr_newrdn );
1864 dnRdn( &entry->e_nname, &op->orr_nnewrdn );
1866 dnParent( &dni.ndn, &noldp );
1867 dnParent( &entry->e_nname, &nnewp );
1868 if ( !dn_match( &noldp, &nnewp ) ) {
1869 dnParent( &entry->e_name, &newp );
1870 op->orr_newSup = &newp;
1871 op->orr_nnewSup = &nnewp;
1873 op->orr_newSup = NULL;
1874 op->orr_nnewSup = NULL;
1876 op->orr_deleteoldrdn = dni.delOldRDN;
1877 op->orr_modlist = NULL;
1878 if ( ( rc = slap_modrdn2mods( op, &rs_modify ) ) ) {
1882 /* RDNs must be NUL-terminated for back-ldap */
1883 noldp = op->orr_newrdn;
1884 ber_dupbv_x( &op->orr_newrdn, &noldp, op->o_tmpmemctx );
1885 noldp = op->orr_nnewrdn;
1886 ber_dupbv_x( &op->orr_nnewrdn, &noldp, op->o_tmpmemctx );
1888 /* Setup opattrs too */
1890 AttributeDescription *opattrs[] = {
1891 slap_schema.si_ad_entryCSN,
1892 slap_schema.si_ad_modifiersName,
1893 slap_schema.si_ad_modifyTimestamp,
1896 Modifications *mod, **modtail, **ml;
1899 for ( mod = op->orr_modlist;
1901 mod = mod->sml_next )
1903 modtail = &mod->sml_next;
1905 /* pull mod off incoming modlist, append to orr_modlist */
1906 for ( i = 0; opattrs[i]; i++ ) {
1907 for ( ml = modlist; *ml; ml = &(*ml)->sml_next )
1909 if ( (*ml)->sml_desc == opattrs[i] ) {
1911 *ml = mod->sml_next;
1912 mod->sml_next = NULL;
1914 modtail = &mod->sml_next;
1920 rc = be->be_modrdn( op, &rs_modify );
1921 op->o_tmpfree( op->orr_nnewrdn.bv_val, op->o_tmpmemctx );
1922 op->o_tmpfree( op->orr_newrdn.bv_val, op->o_tmpmemctx );
1924 slap_mods_free( op->orr_modlist, 1 );
1925 Debug( LDAP_DEBUG_SYNC,
1926 "syncrepl_entry: rid %03ld be_modrdn (%d)\n",
1927 si->si_rid, rc, 0 );
1931 op->o_tag = LDAP_REQ_MODIFY;
1932 op->orm_modlist = dni.mods;
1933 op->orm_no_opattrs = 1;
1935 rc = be->be_modify( op, &rs_modify );
1936 slap_mods_free( op->orm_modlist, 1 );
1937 Debug( LDAP_DEBUG_SYNC,
1938 "syncrepl_entry: rid %03ld be_modify (%d)\n",
1939 si->si_rid, rc, 0 );
1940 if ( rs_modify.sr_err != LDAP_SUCCESS ) {
1941 Debug( LDAP_DEBUG_ANY,
1942 "syncrepl_entry: rid %03ld be_modify failed (%d)\n",
1943 si->si_rid, rs_modify.sr_err, 0 );
1947 case LDAP_SYNC_DELETE :
1948 if ( !BER_BVISNULL( &dni.dn ) ) {
1949 op->o_req_dn = dni.dn;
1950 op->o_req_ndn = dni.ndn;
1951 op->o_tag = LDAP_REQ_DELETE;
1952 rc = be->be_delete( op, &rs_delete );
1953 Debug( LDAP_DEBUG_SYNC,
1954 "syncrepl_entry: rid %03ld be_delete (%d)\n",
1955 si->si_rid, rc, 0 );
1957 while ( rs_delete.sr_err == LDAP_SUCCESS
1958 && op->o_delete_glue_parent ) {
1959 op->o_delete_glue_parent = 0;
1960 if ( !be_issuffix( op->o_bd, &op->o_req_ndn ) ) {
1961 slap_callback cb = { NULL };
1962 cb.sc_response = slap_null_cb;
1963 dnParent( &op->o_req_ndn, &pdn );
1965 op->o_req_ndn = pdn;
1966 op->o_callback = &cb;
1967 op->o_bd->be_delete( op, &rs_delete );
1976 Debug( LDAP_DEBUG_ANY,
1977 "syncrepl_entry: rid %03ld unknown syncstate\n", si->si_rid, 0, 0 );
1982 if ( !BER_BVISNULL( &syncUUID_strrep ) ) {
1983 slap_sl_free( syncUUID_strrep.bv_val, op->o_tmpmemctx );
1984 BER_BVZERO( &syncUUID_strrep );
1986 if ( !BER_BVISNULL( &dni.ndn ) ) {
1987 op->o_tmpfree( dni.ndn.bv_val, op->o_tmpmemctx );
1989 if ( !BER_BVISNULL( &dni.dn ) ) {
1990 op->o_tmpfree( dni.dn.bv_val, op->o_tmpmemctx );
1993 entry_free( entry );
1994 BER_BVZERO( &op->o_csn );
1998 static struct berval gcbva[] = {
2004 #define NP_DELETE_ONE 2
2007 syncrepl_del_nonpresent(
2011 struct berval *cookiecsn )
2013 Backend* be = op->o_bd;
2014 slap_callback cb = { NULL };
2015 SlapReply rs_search = {REP_RESULT};
2016 SlapReply rs_delete = {REP_RESULT};
2017 SlapReply rs_modify = {REP_RESULT};
2018 struct nonpresent_entry *np_list, *np_prev;
2020 AttributeName an[2];
2022 struct berval pdn = BER_BVNULL;
2025 op->o_req_dn = si->si_base;
2026 op->o_req_ndn = si->si_base;
2028 cb.sc_response = nonpresent_callback;
2031 op->o_callback = &cb;
2032 op->o_tag = LDAP_REQ_SEARCH;
2033 op->ors_scope = si->si_scope;
2034 op->ors_deref = LDAP_DEREF_NEVER;
2035 op->o_time = slap_get_time();
2036 op->ors_tlimit = SLAP_NO_LIMIT;
2041 #ifdef LDAP_COMP_MATCH
2042 AttributeAssertion eq = { NULL, BER_BVNULL, NULL };
2044 AttributeAssertion eq = { NULL, BER_BVNULL };
2048 op->ors_attrsonly = 1;
2049 op->ors_attrs = slap_anlist_no_attrs;
2050 op->ors_limit = NULL;
2051 op->ors_filter = &uf;
2054 uf.f_av_desc = slap_schema.si_ad_entryUUID;
2056 uf.f_choice = LDAP_FILTER_EQUALITY;
2057 si->si_refreshDelete |= NP_DELETE_ONE;
2059 for (i=0; uuids[i].bv_val; i++) {
2061 slap_uuidstr_from_normalized( &uf.f_av_value, &uuids[i],
2063 filter2bv_x( op, op->ors_filter, &op->ors_filterstr );
2064 op->o_tmpfree( uf.f_av_value.bv_val, op->o_tmpmemctx );
2065 uf.f_av_value = uuids[i];
2066 rc = be->be_search( op, &rs_search );
2067 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
2069 si->si_refreshDelete ^= NP_DELETE_ONE;
2071 memset( &an[0], 0, 2 * sizeof( AttributeName ) );
2072 an[0].an_name = slap_schema.si_ad_entryUUID->ad_cname;
2073 an[0].an_desc = slap_schema.si_ad_entryUUID;
2075 op->ors_slimit = SLAP_NO_LIMIT;
2076 op->ors_attrsonly = 0;
2077 op->ors_filter = str2filter_x( op, si->si_filterstr.bv_val );
2078 op->ors_filterstr = si->si_filterstr;
2079 op->o_nocaching = 1;
2081 if ( limits_check( op, &rs_search ) == 0 ) {
2082 rc = be->be_search( op, &rs_search );
2084 if ( op->ors_filter ) filter_free_x( op, op->ors_filter );
2087 op->o_nocaching = 0;
2089 if ( !LDAP_LIST_EMPTY( &si->si_nonpresentlist ) ) {
2091 if ( cookiecsn && !BER_BVISNULL( cookiecsn ) ) {
2094 csn = si->si_syncCookie.ctxcsn;
2097 slap_queue_csn( op, &csn );
2099 np_list = LDAP_LIST_FIRST( &si->si_nonpresentlist );
2100 while ( np_list != NULL ) {
2101 LDAP_LIST_REMOVE( np_list, npe_link );
2103 np_list = LDAP_LIST_NEXT( np_list, npe_link );
2104 op->o_tag = LDAP_REQ_DELETE;
2105 op->o_callback = &cb;
2106 cb.sc_response = null_callback;
2108 op->o_req_dn = *np_prev->npe_name;
2109 op->o_req_ndn = *np_prev->npe_nname;
2110 rc = op->o_bd->be_delete( op, &rs_delete );
2111 Debug( LDAP_DEBUG_SYNC,
2112 "syncrepl_del_nonpresent: rid %03ld be_delete %s (%d)\n",
2113 si->si_rid, op->o_req_dn.bv_val, rc );
2115 if ( rs_delete.sr_err == LDAP_NOT_ALLOWED_ON_NONLEAF ) {
2116 Modifications mod1, mod2;
2117 mod1.sml_op = LDAP_MOD_REPLACE;
2119 mod1.sml_desc = slap_schema.si_ad_objectClass;
2120 mod1.sml_type = mod1.sml_desc->ad_cname;
2121 mod1.sml_values = &gcbva[0];
2122 mod1.sml_nvalues = NULL;
2123 mod1.sml_next = &mod2;
2125 mod2.sml_op = LDAP_MOD_REPLACE;
2127 mod2.sml_desc = slap_schema.si_ad_structuralObjectClass;
2128 mod2.sml_type = mod2.sml_desc->ad_cname;
2129 mod2.sml_values = &gcbva[1];
2130 mod2.sml_nvalues = NULL;
2131 mod2.sml_next = NULL;
2133 op->o_tag = LDAP_REQ_MODIFY;
2134 op->orm_modlist = &mod1;
2136 rc = be->be_modify( op, &rs_modify );
2137 if ( mod2.sml_next ) slap_mods_free( mod2.sml_next, 1 );
2140 while ( rs_delete.sr_err == LDAP_SUCCESS &&
2141 op->o_delete_glue_parent ) {
2142 op->o_delete_glue_parent = 0;
2143 if ( !be_issuffix( op->o_bd, &op->o_req_ndn ) ) {
2144 slap_callback cb = { NULL };
2145 cb.sc_response = slap_null_cb;
2146 dnParent( &op->o_req_ndn, &pdn );
2148 op->o_req_ndn = pdn;
2149 op->o_callback = &cb;
2150 /* give it a root privil ? */
2151 op->o_bd->be_delete( op, &rs_delete );
2157 op->o_delete_glue_parent = 0;
2159 ber_bvfree( np_prev->npe_name );
2160 ber_bvfree( np_prev->npe_nname );
2164 slap_graduate_commit_csn( op );
2166 op->o_tmpfree( op->o_csn.bv_val, op->o_tmpmemctx );
2167 BER_BVZERO( &op->o_csn );
2178 Backend *be = op->o_bd;
2179 slap_callback cb = { NULL };
2184 struct berval dn = BER_BVNULL;
2185 struct berval ndn = BER_BVNULL;
2187 SlapReply rs_add = {REP_RESULT};
2188 struct berval ptr, nptr;
2191 op->o_tag = LDAP_REQ_ADD;
2192 op->o_callback = &cb;
2193 cb.sc_response = null_callback;
2194 cb.sc_private = NULL;
2199 /* count RDNs in suffix */
2200 if ( !BER_BVISEMPTY( &be->be_nsuffix[0] ) ) {
2201 for ( i = 0, ptr = be->be_nsuffix[0], comma = ptr.bv_val; comma != NULL; comma = ber_bvchr( &ptr, ',' ) ) {
2203 ptr.bv_len -= comma - ptr.bv_val;
2213 /* Start with BE suffix */
2215 for ( i = 0; i < suffrdns; i++ ) {
2216 comma = ber_bvrchr( &ptr, ',' );
2217 if ( comma != NULL ) {
2218 ptr.bv_len = comma - ptr.bv_val;
2225 if ( !BER_BVISEMPTY( &ptr ) ) {
2226 dn.bv_len -= ptr.bv_len + 1;
2227 dn.bv_val += ptr.bv_len + 1;
2230 /* the normalizedDNs are always the same length, no counting
2234 if ( ndn.bv_len > be->be_nsuffix[0].bv_len ) {
2235 ndn.bv_val += ndn.bv_len - be->be_nsuffix[0].bv_len;
2236 ndn.bv_len = be->be_nsuffix[0].bv_len;
2238 nptr.bv_len = ndn.bv_val - nptr.bv_val - 1;
2244 while ( ndn.bv_val > e->e_nname.bv_val ) {
2245 glue = entry_alloc();
2246 ber_dupbv( &glue->e_name, &dn );
2247 ber_dupbv( &glue->e_nname, &ndn );
2249 a = attr_alloc( slap_schema.si_ad_objectClass );
2251 a->a_vals = ch_calloc( 3, sizeof( struct berval ) );
2252 ber_dupbv( &a->a_vals[0], &gcbva[0] );
2253 ber_dupbv( &a->a_vals[1], &gcbva[1] );
2254 ber_dupbv( &a->a_vals[2], &gcbva[2] );
2256 a->a_nvals = a->a_vals;
2258 a->a_next = glue->e_attrs;
2261 a = attr_alloc( slap_schema.si_ad_structuralObjectClass );
2263 a->a_vals = ch_calloc( 2, sizeof( struct berval ) );
2264 ber_dupbv( &a->a_vals[0], &gcbva[1] );
2265 ber_dupbv( &a->a_vals[1], &gcbva[2] );
2267 a->a_nvals = a->a_vals;
2269 a->a_next = glue->e_attrs;
2272 op->o_req_dn = glue->e_name;
2273 op->o_req_ndn = glue->e_nname;
2275 rc = be->be_add ( op, &rs_add );
2276 if ( rs_add.sr_err == LDAP_SUCCESS ) {
2277 if ( op->ora_e == glue )
2278 be_entry_release_w( op, glue );
2280 /* incl. ALREADY EXIST */
2282 if ( rs_add.sr_err != LDAP_ALREADY_EXISTS ) {
2288 /* Move to next child */
2289 comma = ber_bvrchr( &ptr, ',' );
2290 if ( comma == NULL ) {
2293 ptr.bv_len = comma - ptr.bv_val;
2295 dn.bv_val = ++comma;
2296 dn.bv_len = e->e_name.bv_len - (dn.bv_val - e->e_name.bv_val);
2298 comma = ber_bvrchr( &nptr, ',' );
2299 assert( comma != NULL );
2300 nptr.bv_len = comma - nptr.bv_val;
2302 ndn.bv_val = ++comma;
2303 ndn.bv_len = e->e_nname.bv_len - (ndn.bv_val - e->e_nname.bv_val);
2306 op->o_req_dn = e->e_name;
2307 op->o_req_ndn = e->e_nname;
2309 rc = be->be_add ( op, &rs_add );
2310 if ( rs_add.sr_err == LDAP_SUCCESS ) {
2311 if ( op->ora_e == e )
2312 be_entry_release_w( op, e );
2321 syncrepl_updateCookie(
2325 struct sync_cookie *syncCookie )
2327 Backend *be = op->o_bd;
2328 Modifications mod = { { 0 } };
2329 struct berval vals[ 2 ];
2333 slap_callback cb = { NULL };
2334 SlapReply rs_modify = {REP_RESULT};
2336 mod.sml_op = LDAP_MOD_REPLACE;
2337 mod.sml_desc = slap_schema.si_ad_contextCSN;
2338 mod.sml_type = mod.sml_desc->ad_cname;
2339 mod.sml_values = vals;
2340 vals[0] = syncCookie->ctxcsn;
2341 BER_BVZERO( &vals[1] );
2343 slap_queue_csn( op, &syncCookie->ctxcsn );
2345 op->o_tag = LDAP_REQ_MODIFY;
2347 assert( si->si_rid < 1000 );
2349 cb.sc_response = null_callback;
2352 op->o_callback = &cb;
2353 op->o_req_dn = op->o_bd->be_suffix[0];
2354 op->o_req_ndn = op->o_bd->be_nsuffix[0];
2356 /* update contextCSN */
2357 op->o_msgid = SLAP_SYNC_UPDATE_MSGID;
2358 op->orm_modlist = &mod;
2359 flags = SLAP_DBFLAGS( op->o_bd );
2360 SLAP_DBFLAGS( op->o_bd ) |= SLAP_DBFLAG_NOLASTMOD;
2361 rc = be->be_modify( op, &rs_modify );
2362 SLAP_DBFLAGS( op->o_bd ) = flags;
2365 if ( rs_modify.sr_err == LDAP_SUCCESS ) {
2366 slap_sync_cookie_free( &si->si_syncCookie, 0 );
2367 slap_dup_sync_cookie( &si->si_syncCookie, syncCookie );
2369 Debug( LDAP_DEBUG_ANY,
2370 "syncrepl_updateCookie: rid %03ld be_modify failed (%d)\n",
2371 si->si_rid, rs_modify.sr_err, 0 );
2374 slap_graduate_commit_csn( op );
2375 op->o_tmpfree( op->o_csn.bv_val, op->o_tmpmemctx );
2376 BER_BVZERO( &op->o_csn );
2377 if ( mod.sml_next ) slap_mods_free( mod.sml_next, 1 );
2383 attr_cmp( Operation *op, Attribute *old, Attribute *new,
2384 Modifications ***mret, Modifications ***mcur )
2386 int i, j, doadd = 0;
2387 Modifications *mod, **modtail;
2392 int n, o, d, a, *adds, *dels;
2393 /* count old and new */
2394 for ( o=0; old->a_vals[o].bv_val; o++ ) ;
2395 for ( n=0; new->a_vals[n].bv_val; n++ ) ;
2397 adds = op->o_tmpalloc( sizeof(int) * n, op->o_tmpmemctx );
2398 dels = op->o_tmpalloc( sizeof(int) * o, op->o_tmpmemctx );
2404 while ( i < o && j < n ) {
2406 if ( bvmatch( &old->a_vals[i], &new->a_vals[j] ) ) {
2411 for ( k = j + 1; k<n; k++ ) {
2412 if ( bvmatch( &old->a_vals[i], &new->a_vals[k] ) ) {
2416 /* an old value was deleted */
2421 for ( k = i + 1; k < o; k++ ) {
2422 if ( bvmatch( &old->a_vals[k], &new->a_vals[j] ) ) {
2435 /* all old values were deleted, just use the replace op */
2439 /* delete some values */
2440 mod = ch_malloc( sizeof( Modifications ) );
2441 mod->sml_op = LDAP_MOD_DELETE;
2443 mod->sml_desc = old->a_desc;
2444 mod->sml_type = mod->sml_desc->ad_cname;
2445 mod->sml_values = ch_malloc( ( d + 1 ) * sizeof(struct berval) );
2446 if ( old->a_vals != old->a_nvals ) {
2447 mod->sml_nvalues = ch_malloc( ( d + 1 ) * sizeof(struct berval) );
2449 mod->sml_nvalues = NULL;
2451 for ( i = 0; i < d; i++ ) {
2452 ber_dupbv( &mod->sml_values[i], &old->a_vals[dels[i]] );
2453 if ( mod->sml_nvalues ) {
2454 ber_dupbv( &mod->sml_nvalues[i], &old->a_nvals[dels[i]] );
2457 BER_BVZERO( &mod->sml_values[i] );
2458 if ( mod->sml_nvalues ) {
2459 BER_BVZERO( &mod->sml_nvalues[i] );
2462 modtail = &mod->sml_next;
2465 op->o_tmpfree( dels, op->o_tmpmemctx );
2466 /* some values were added */
2468 mod = ch_malloc( sizeof( Modifications ) );
2469 mod->sml_op = LDAP_MOD_ADD;
2471 mod->sml_desc = old->a_desc;
2472 mod->sml_type = mod->sml_desc->ad_cname;
2473 mod->sml_values = ch_malloc( ( a + 1 ) * sizeof(struct berval) );
2474 if ( old->a_vals != old->a_nvals ) {
2475 mod->sml_nvalues = ch_malloc( ( a + 1 ) * sizeof(struct berval) );
2477 mod->sml_nvalues = NULL;
2479 for ( i = 0; i < a; i++ ) {
2480 ber_dupbv( &mod->sml_values[i], &new->a_vals[adds[i]] );
2481 if ( mod->sml_nvalues ) {
2482 ber_dupbv( &mod->sml_nvalues[i], &new->a_nvals[adds[i]] );
2485 BER_BVZERO( &mod->sml_values[i] );
2486 if ( mod->sml_nvalues ) {
2487 BER_BVZERO( &mod->sml_nvalues[i] );
2490 modtail = &mod->sml_next;
2493 op->o_tmpfree( adds, op->o_tmpmemctx );
2495 /* new attr, just use the new mod */
2499 /* advance to next element */
2502 **mcur = mod->sml_next;
2504 modtail = &mod->sml_next;
2507 *mcur = &mod->sml_next;
2517 dninfo *dni = op->o_callback->sc_private;
2519 if ( rs->sr_type == REP_SEARCH ) {
2520 if ( !BER_BVISNULL( &dni->dn ) ) {
2521 Debug( LDAP_DEBUG_ANY,
2522 "dn_callback : consistency error - "
2523 "entryUUID is not unique\n", 0, 0, 0 );
2525 ber_dupbv_x( &dni->dn, &rs->sr_entry->e_name, op->o_tmpmemctx );
2526 ber_dupbv_x( &dni->ndn, &rs->sr_entry->e_nname, op->o_tmpmemctx );
2527 /* If there is a new entry, see if it differs from the old.
2528 * We compare the non-normalized values so that cosmetic changes
2529 * in the provider are always propagated.
2531 if ( dni->new_entry ) {
2532 Modifications **modtail, **ml;
2533 Attribute *old, *new;
2536 /* Did the DN change?
2538 if ( !dn_match( &rs->sr_entry->e_name,
2539 &dni->new_entry->e_name ) )
2541 struct berval oldRDN, oldVal;
2542 AttributeDescription *ad = NULL;
2546 /* See if the oldRDN was deleted */
2547 dnRdn( &rs->sr_entry->e_nname, &oldRDN );
2548 oldVal.bv_val = strchr(oldRDN.bv_val, '=') + 1;
2549 oldVal.bv_len = oldRDN.bv_len - ( oldVal.bv_val -
2551 oldRDN.bv_len -= oldVal.bv_len + 2;
2552 slap_bv2ad( &oldRDN, &ad, &rs->sr_text );
2553 a = attr_find( dni->new_entry->e_attrs, ad );
2554 if ( !a || value_find_ex( ad,
2555 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH |
2556 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
2557 SLAP_MR_VALUE_OF_SYNTAX, a->a_nvals,
2558 &oldVal, op->o_tmpmemctx ) != LDAP_SUCCESS )
2562 /* OK, this was just a modDN, we're done */
2563 return LDAP_SUCCESS;
2566 modtail = &dni->mods;
2569 /* We assume that attributes are saved in the same order
2570 * in the remote and local databases. So if we walk through
2571 * the attributeDescriptions one by one they should match in
2572 * lock step. If not, look for an add or delete.
2574 for ( old = rs->sr_entry->e_attrs, new = dni->new_entry->e_attrs;
2578 if ( new->a_flags & SLAP_ATTR_IXADD ) {
2583 if ( old->a_desc != new->a_desc ) {
2587 /* If it's just been re-added later,
2588 * remember that we've seen it.
2590 tmp = attr_find( new, old->a_desc );
2592 tmp->a_flags |= SLAP_ATTR_IXADD;
2594 /* If it's a new attribute, pull it in.
2596 tmp = attr_find( old, new->a_desc );
2598 attr_cmp( op, NULL, new, &modtail, &ml );
2602 /* Delete old attr */
2603 mod = ch_malloc( sizeof( Modifications ) );
2604 mod->sml_op = LDAP_MOD_DELETE;
2606 mod->sml_desc = old->a_desc;
2607 mod->sml_type = mod->sml_desc->ad_cname;
2608 mod->sml_values = NULL;
2609 mod->sml_nvalues = NULL;
2611 modtail = &mod->sml_next;
2616 attr_cmp( op, old, new, &modtail, &ml );
2624 } else if ( rs->sr_type == REP_RESULT ) {
2625 if ( rs->sr_err == LDAP_SIZELIMIT_EXCEEDED ) {
2626 Debug( LDAP_DEBUG_ANY,
2627 "dn_callback : consistency error - "
2628 "entryUUID is not unique\n", 0, 0, 0 );
2632 return LDAP_SUCCESS;
2636 nonpresent_callback(
2640 syncinfo_t *si = op->o_callback->sc_private;
2643 struct berval* present_uuid = NULL;
2644 struct nonpresent_entry *np_entry;
2646 if ( rs->sr_type == REP_RESULT ) {
2647 count = avl_free( si->si_presentlist, avl_ber_bvfree );
2648 si->si_presentlist = NULL;
2650 } else if ( rs->sr_type == REP_SEARCH ) {
2651 if ( !( si->si_refreshDelete & NP_DELETE_ONE ) ) {
2652 char buf[sizeof("000 not")];
2654 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID );
2657 present_uuid = avl_find( si->si_presentlist, &a->a_nvals[0],
2661 if ( slap_debug & LDAP_DEBUG_SYNC ) {
2662 sprintf( buf, "%03ld %s", si->si_rid,
2663 present_uuid ? "got" : "not" );
2666 Debug( LDAP_DEBUG_SYNC, "nonpresent_callback: rid %s UUID %s, dn %s\n",
2667 buf, a ? a->a_vals[0].bv_val : "<missing>", rs->sr_entry->e_name.bv_val );
2669 if ( a == NULL ) return 0;
2672 if ( present_uuid == NULL ) {
2673 np_entry = (struct nonpresent_entry *)
2674 ch_calloc( 1, sizeof( struct nonpresent_entry ) );
2675 np_entry->npe_name = ber_dupbv( NULL, &rs->sr_entry->e_name );
2676 np_entry->npe_nname = ber_dupbv( NULL, &rs->sr_entry->e_nname );
2677 LDAP_LIST_INSERT_HEAD( &si->si_nonpresentlist, np_entry, npe_link );
2680 avl_delete( &si->si_presentlist,
2681 &a->a_nvals[0], syncuuid_cmp );
2682 ch_free( present_uuid->bv_val );
2683 ch_free( present_uuid );
2686 return LDAP_SUCCESS;
2694 if ( rs->sr_err != LDAP_SUCCESS &&
2695 rs->sr_err != LDAP_REFERRAL &&
2696 rs->sr_err != LDAP_ALREADY_EXISTS &&
2697 rs->sr_err != LDAP_NO_SUCH_OBJECT &&
2698 rs->sr_err != LDAP_NOT_ALLOWED_ON_NONLEAF )
2700 Debug( LDAP_DEBUG_ANY,
2701 "null_callback : error code 0x%x\n",
2704 return LDAP_SUCCESS;
2707 static struct berval *
2708 slap_uuidstr_from_normalized(
2709 struct berval* uuidstr,
2710 struct berval* normalized,
2714 unsigned char nibble;
2717 if ( normalized == NULL ) return NULL;
2718 if ( normalized->bv_len != 16 ) return NULL;
2723 new = (struct berval *)slap_sl_malloc( sizeof(struct berval), ctx );
2724 if ( new == NULL ) {
2731 if ( ( new->bv_val = slap_sl_malloc( new->bv_len + 1, ctx ) ) == NULL ) {
2732 if ( new != uuidstr ) {
2733 slap_sl_free( new, ctx );
2738 for ( i = 0; i < 16; i++ ) {
2739 if ( i == 4 || i == 6 || i == 8 || i == 10 ) {
2740 new->bv_val[(i<<1)+d] = '-';
2744 nibble = (normalized->bv_val[i] >> 4) & 0xF;
2745 if ( nibble < 10 ) {
2746 new->bv_val[(i<<1)+d] = nibble + '0';
2748 new->bv_val[(i<<1)+d] = nibble - 10 + 'a';
2751 nibble = (normalized->bv_val[i]) & 0xF;
2752 if ( nibble < 10 ) {
2753 new->bv_val[(i<<1)+d+1] = nibble + '0';
2755 new->bv_val[(i<<1)+d+1] = nibble - 10 + 'a';
2759 new->bv_val[new->bv_len] = '\0';
2764 syncuuid_cmp( const void* v_uuid1, const void* v_uuid2 )
2766 const struct berval *uuid1 = v_uuid1;
2767 const struct berval *uuid2 = v_uuid2;
2768 int rc = uuid1->bv_len - uuid2->bv_len;
2769 if ( rc ) return rc;
2770 return ( memcmp( uuid1->bv_val, uuid2->bv_val, uuid1->bv_len ) );
2774 avl_ber_bvfree( void *v_bv )
2776 struct berval *bv = (struct berval *)v_bv;
2778 if( v_bv == NULL ) return;
2779 if ( !BER_BVISNULL( bv ) ) {
2780 ch_free( bv->bv_val );
2782 ch_free( (char *) bv );
2786 syncinfo_free( syncinfo_t *sie )
2789 if ( sie->si_conn_setup ) {
2791 ldap_get_option( sie->si_ld, LDAP_OPT_DESC, &s );
2792 connection_client_stop( s );
2793 sie->si_conn_setup = 0;
2795 ldap_unbind_ext( sie->si_ld, NULL, NULL );
2798 /* re-fetch it, in case it was already removed */
2799 sie->si_re = ldap_pvt_runqueue_find( &slapd_rq, do_syncrepl, sie );
2801 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, sie->si_re ) )
2802 ldap_pvt_runqueue_stoptask( &slapd_rq, sie->si_re );
2803 ldap_pvt_runqueue_remove( &slapd_rq, sie->si_re );
2806 ldap_pvt_thread_mutex_destroy( &sie->si_mutex );
2808 bindconf_free( &sie->si_bindconf );
2810 if ( sie->si_filterstr.bv_val ) {
2811 ch_free( sie->si_filterstr.bv_val );
2813 if ( sie->si_logfilterstr.bv_val ) {
2814 ch_free( sie->si_logfilterstr.bv_val );
2816 if ( sie->si_base.bv_val ) {
2817 ch_free( sie->si_base.bv_val );
2819 if ( sie->si_logbase.bv_val ) {
2820 ch_free( sie->si_logbase.bv_val );
2822 if ( sie->si_attrs ) {
2824 while ( sie->si_attrs[i] != NULL ) {
2825 ch_free( sie->si_attrs[i] );
2828 ch_free( sie->si_attrs );
2830 if ( sie->si_exattrs ) {
2832 while ( sie->si_exattrs[i] != NULL ) {
2833 ch_free( sie->si_exattrs[i] );
2836 ch_free( sie->si_exattrs );
2838 if ( sie->si_anlist ) {
2840 while ( sie->si_anlist[i].an_name.bv_val != NULL ) {
2841 ch_free( sie->si_anlist[i].an_name.bv_val );
2844 ch_free( sie->si_anlist );
2846 if ( sie->si_exanlist ) {
2848 while ( sie->si_exanlist[i].an_name.bv_val != NULL ) {
2849 ch_free( sie->si_exanlist[i].an_name.bv_val );
2852 ch_free( sie->si_exanlist );
2854 if ( sie->si_retryinterval ) {
2855 ch_free( sie->si_retryinterval );
2857 if ( sie->si_retrynum ) {
2858 ch_free( sie->si_retrynum );
2860 if ( sie->si_retrynum_init ) {
2861 ch_free( sie->si_retrynum_init );
2863 slap_sync_cookie_free( &sie->si_syncCookie, 0 );
2864 if ( sie->si_presentlist ) {
2865 avl_free( sie->si_presentlist, avl_ber_bvfree );
2867 while ( !LDAP_LIST_EMPTY( &sie->si_nonpresentlist ) ) {
2868 struct nonpresent_entry* npe;
2869 npe = LDAP_LIST_FIRST( &sie->si_nonpresentlist );
2870 LDAP_LIST_REMOVE( npe, npe_link );
2871 if ( npe->npe_name ) {
2872 if ( npe->npe_name->bv_val ) {
2873 ch_free( npe->npe_name->bv_val );
2875 ch_free( npe->npe_name );
2877 if ( npe->npe_nname ) {
2878 if ( npe->npe_nname->bv_val ) {
2879 ch_free( npe->npe_nname->bv_val );
2881 ch_free( npe->npe_nname );
2890 /* NOTE: used & documented in slapd.conf(5) */
2892 #define PROVIDERSTR "provider"
2893 #define SCHEMASTR "schemachecking"
2894 #define FILTERSTR "filter"
2895 #define SEARCHBASESTR "searchbase"
2896 #define SCOPESTR "scope"
2897 #define ATTRSONLYSTR "attrsonly"
2898 #define ATTRSSTR "attrs"
2899 #define TYPESTR "type"
2900 #define INTERVALSTR "interval"
2901 #define RETRYSTR "retry"
2902 #define SLIMITSTR "sizelimit"
2903 #define TLIMITSTR "timelimit"
2904 #define SYNCDATASTR "syncdata"
2906 /* FIXME: undocumented */
2907 #define LOGBASESTR "logbase"
2908 #define LOGFILTERSTR "logfilter"
2909 #define OLDAUTHCSTR "bindprincipal"
2910 #define EXATTRSSTR "exattrs"
2911 #define MANAGEDSAITSTR "manageDSAit"
2914 #define LASTMODSTR "lastmod"
2915 #define LMGENSTR "gen"
2916 #define LMNOSTR "no"
2917 #define LMREQSTR "req"
2918 #define SRVTABSTR "srvtab"
2919 #define SUFFIXSTR "suffix"
2922 #define GOT_ID 0x0001
2923 #define GOT_PROVIDER 0x0002
2924 #define GOT_BASE 0x0004
2927 #define GOT_ALL (GOT_ID|GOT_PROVIDER|GOT_BASE)
2933 { BER_BVC("base"), LDAP_SCOPE_BASE },
2934 { BER_BVC("one"), LDAP_SCOPE_ONELEVEL },
2935 { BER_BVC("onelevel"), LDAP_SCOPE_ONELEVEL }, /* OpenLDAP extension */
2936 { BER_BVC("children"), LDAP_SCOPE_SUBORDINATE },
2937 { BER_BVC("subord"), LDAP_SCOPE_SUBORDINATE },
2938 { BER_BVC("subordinate"), LDAP_SCOPE_SUBORDINATE },
2939 { BER_BVC("sub"), LDAP_SCOPE_SUBTREE },
2940 { BER_BVC("subtree"), LDAP_SCOPE_SUBTREE }, /* OpenLDAP extension */
2944 static slap_verbmasks datamodes[] = {
2945 { BER_BVC("default"), SYNCDATA_DEFAULT },
2946 { BER_BVC("accesslog"), SYNCDATA_ACCESSLOG },
2947 { BER_BVC("changelog"), SYNCDATA_CHANGELOG },
2952 parse_syncrepl_line(
2960 for ( i = 1; i < c->argc; i++ ) {
2961 if ( !strncasecmp( c->argv[ i ], IDSTR "=",
2962 STRLENOF( IDSTR "=" ) ) )
2965 /* '\0' string terminator accounts for '=' */
2966 val = c->argv[ i ] + STRLENOF( IDSTR "=" );
2967 if ( lutil_atoi( &tmp, val ) != 0 ) {
2968 snprintf( c->msg, sizeof( c->msg ),
2969 "Error: parse_syncrepl_line: "
2970 "unable to parse syncrepl id \"%s\"", val );
2971 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
2974 if ( tmp >= 1000 || tmp < 0 ) {
2975 snprintf( c->msg, sizeof( c->msg ),
2976 "Error: parse_syncrepl_line: "
2977 "syncrepl id %d is out of range [0..999]", tmp );
2978 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
2983 } else if ( !strncasecmp( c->argv[ i ], PROVIDERSTR "=",
2984 STRLENOF( PROVIDERSTR "=" ) ) )
2986 val = c->argv[ i ] + STRLENOF( PROVIDERSTR "=" );
2987 ber_str2bv( val, 0, 1, &si->si_bindconf.sb_uri );
2988 gots |= GOT_PROVIDER;
2989 } else if ( !strncasecmp( c->argv[ i ], SCHEMASTR "=",
2990 STRLENOF( SCHEMASTR "=" ) ) )
2992 val = c->argv[ i ] + STRLENOF( SCHEMASTR "=" );
2993 if ( !strncasecmp( val, "on", STRLENOF( "on" ) ) ) {
2994 si->si_schemachecking = 1;
2995 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2996 si->si_schemachecking = 0;
2998 si->si_schemachecking = 1;
3000 } else if ( !strncasecmp( c->argv[ i ], FILTERSTR "=",
3001 STRLENOF( FILTERSTR "=" ) ) )
3003 val = c->argv[ i ] + STRLENOF( FILTERSTR "=" );
3004 if ( si->si_filterstr.bv_val )
3005 ch_free( si->si_filterstr.bv_val );
3006 ber_str2bv( val, 0, 1, &si->si_filterstr );
3007 } else if ( !strncasecmp( c->argv[ i ], LOGFILTERSTR "=",
3008 STRLENOF( LOGFILTERSTR "=" ) ) )
3010 val = c->argv[ i ] + STRLENOF( LOGFILTERSTR "=" );
3011 if ( si->si_logfilterstr.bv_val )
3012 ch_free( si->si_logfilterstr.bv_val );
3013 ber_str2bv( val, 0, 1, &si->si_logfilterstr );
3014 } else if ( !strncasecmp( c->argv[ i ], SEARCHBASESTR "=",
3015 STRLENOF( SEARCHBASESTR "=" ) ) )
3020 val = c->argv[ i ] + STRLENOF( SEARCHBASESTR "=" );
3021 if ( si->si_base.bv_val ) {
3022 ch_free( si->si_base.bv_val );
3024 ber_str2bv( val, 0, 0, &bv );
3025 rc = dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL );
3026 if ( rc != LDAP_SUCCESS ) {
3027 snprintf( c->msg, sizeof( c->msg ),
3028 "Invalid base DN \"%s\": %d (%s)",
3029 val, rc, ldap_err2string( rc ) );
3030 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3034 } else if ( !strncasecmp( c->argv[ i ], LOGBASESTR "=",
3035 STRLENOF( LOGBASESTR "=" ) ) )
3040 val = c->argv[ i ] + STRLENOF( LOGBASESTR "=" );
3041 if ( si->si_logbase.bv_val ) {
3042 ch_free( si->si_logbase.bv_val );
3044 ber_str2bv( val, 0, 0, &bv );
3045 rc = dnNormalize( 0, NULL, NULL, &bv, &si->si_logbase, NULL );
3046 if ( rc != LDAP_SUCCESS ) {
3047 snprintf( c->msg, sizeof( c->msg ),
3048 "Invalid logbase DN \"%s\": %d (%s)",
3049 val, rc, ldap_err2string( rc ) );
3050 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3053 } else if ( !strncasecmp( c->argv[ i ], SCOPESTR "=",
3054 STRLENOF( SCOPESTR "=" ) ) )
3057 val = c->argv[ i ] + STRLENOF( SCOPESTR "=" );
3058 for ( j = 0; !BER_BVISNULL(&scopes[j].key); j++ ) {
3059 if (!strcasecmp( val, scopes[j].key.bv_val ) ) {
3060 si->si_scope = scopes[j].val;
3064 if ( BER_BVISNULL(&scopes[j].key) ) {
3065 snprintf( c->msg, sizeof( c->msg ),
3066 "Error: parse_syncrepl_line: "
3067 "unknown scope \"%s\"", val);
3068 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3071 } else if ( !strncasecmp( c->argv[ i ], ATTRSONLYSTR,
3072 STRLENOF( ATTRSONLYSTR ) ) )
3074 si->si_attrsonly = 1;
3075 } else if ( !strncasecmp( c->argv[ i ], ATTRSSTR "=",
3076 STRLENOF( ATTRSSTR "=" ) ) )
3078 val = c->argv[ i ] + STRLENOF( ATTRSSTR "=" );
3079 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") ) ) {
3081 attr_fname = ch_strdup( val + STRLENOF(":include:") );
3082 si->si_anlist = file2anlist( si->si_anlist, attr_fname, " ,\t" );
3083 if ( si->si_anlist == NULL ) {
3084 ch_free( attr_fname );
3087 si->si_anfile = attr_fname;
3089 char *str, *s, *next;
3090 char delimstr[] = " ,\t";
3091 str = ch_strdup( val );
3092 for ( s = ldap_pvt_strtok( str, delimstr, &next );
3094 s = ldap_pvt_strtok( NULL, delimstr, &next ) )
3096 if ( strlen(s) == 1 && *s == '*' ) {
3097 si->si_allattrs = 1;
3098 val[ s - str ] = delimstr[0];
3100 if ( strlen(s) == 1 && *s == '+' ) {
3101 si->si_allopattrs = 1;
3102 val [ s - str ] = delimstr[0];
3106 si->si_anlist = str2anlist( si->si_anlist, val, " ,\t" );
3107 if ( si->si_anlist == NULL ) {
3111 } else if ( !strncasecmp( c->argv[ i ], EXATTRSSTR "=",
3112 STRLENOF( EXATTRSSTR "=" ) ) )
3114 val = c->argv[ i ] + STRLENOF( EXATTRSSTR "=" );
3115 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") ) ) {
3117 attr_fname = ch_strdup( val + STRLENOF(":include:") );
3118 si->si_exanlist = file2anlist(
3119 si->si_exanlist, attr_fname, " ,\t" );
3120 if ( si->si_exanlist == NULL ) {
3121 ch_free( attr_fname );
3124 ch_free( attr_fname );
3126 si->si_exanlist = str2anlist( si->si_exanlist, val, " ,\t" );
3127 if ( si->si_exanlist == NULL ) {
3131 } else if ( !strncasecmp( c->argv[ i ], TYPESTR "=",
3132 STRLENOF( TYPESTR "=" ) ) )
3134 val = c->argv[ i ] + STRLENOF( TYPESTR "=" );
3135 if ( !strncasecmp( val, "refreshOnly",
3136 STRLENOF("refreshOnly") ) )
3138 si->si_type = si->si_ctype = LDAP_SYNC_REFRESH_ONLY;
3139 } else if ( !strncasecmp( val, "refreshAndPersist",
3140 STRLENOF("refreshAndPersist") ) )
3142 si->si_type = si->si_ctype = LDAP_SYNC_REFRESH_AND_PERSIST;
3143 si->si_interval = 60;
3145 snprintf( c->msg, sizeof( c->msg ),
3146 "Error: parse_syncrepl_line: "
3147 "unknown sync type \"%s\"", val);
3148 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3151 } else if ( !strncasecmp( c->argv[ i ], INTERVALSTR "=",
3152 STRLENOF( INTERVALSTR "=" ) ) )
3154 val = c->argv[ i ] + STRLENOF( INTERVALSTR "=" );
3155 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
3156 si->si_interval = 0;
3157 } else if ( strchr( val, ':' ) != NULL ) {
3158 char *next, *ptr = val;
3159 unsigned dd, hh, mm, ss;
3161 /* NOTE: the test for ptr[ 0 ] == '-'
3162 * should go before the call to strtoul() */
3163 dd = strtoul( ptr, &next, 10 );
3164 if ( ptr[ 0 ] == '-' || next == ptr || next[0] != ':' ) {
3165 snprintf( c->msg, sizeof( c->msg ),
3166 "Error: parse_syncrepl_line: "
3167 "invalid interval \"%s\", unable to parse days", val );
3168 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3172 hh = strtoul( ptr, &next, 10 );
3173 if ( ptr[ 0 ] == '-' || next == ptr || next[0] != ':' || hh > 24 ) {
3174 snprintf( c->msg, sizeof( c->msg ),
3175 "Error: parse_syncrepl_line: "
3176 "invalid interval \"%s\", unable to parse hours", val );
3177 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3181 mm = strtoul( ptr, &next, 10 );
3182 if ( ptr[ 0 ] == '-' || next == ptr || next[0] != ':' || mm > 60 ) {
3183 snprintf( c->msg, sizeof( c->msg ),
3184 "Error: parse_syncrepl_line: "
3185 "invalid interval \"%s\", unable to parse minutes", val );
3186 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3190 ss = strtoul( ptr, &next, 10 );
3191 if ( ptr[ 0 ] == '-' || next == ptr || next[0] != '\0' || ss > 60 ) {
3192 snprintf( c->msg, sizeof( c->msg ),
3193 "Error: parse_syncrepl_line: "
3194 "invalid interval \"%s\", unable to parse seconds", val );
3195 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3198 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
3202 if ( lutil_parse_time( val, &t ) != 0 ) {
3203 snprintf( c->msg, sizeof( c->msg ),
3204 "Error: parse_syncrepl_line: "
3205 "invalid interval \"%s\"", val );
3206 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3209 si->si_interval = (time_t)t;
3211 if ( si->si_interval < 0 ) {
3212 snprintf( c->msg, sizeof( c->msg ),
3213 "Error: parse_syncrepl_line: "
3214 "invalid interval \"%ld\"",
3215 (long) si->si_interval);
3216 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3219 } else if ( !strncasecmp( c->argv[ i ], RETRYSTR "=",
3220 STRLENOF( RETRYSTR "=" ) ) )
3225 val = c->argv[ i ] + STRLENOF( RETRYSTR "=" );
3226 retry_list = (char **) ch_calloc( 1, sizeof( char * ) );
3227 retry_list[0] = NULL;
3229 slap_str2clist( &retry_list, val, " ,\t" );
3231 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
3234 snprintf( c->msg, sizeof( c->msg ),
3235 "Error: incomplete syncrepl retry list" );
3236 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3237 for ( k = 0; retry_list && retry_list[k]; k++ ) {
3238 ch_free( retry_list[k] );
3240 ch_free( retry_list );
3243 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ) );
3244 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ) );
3245 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ) );
3246 for ( j = 0; j < n; j++ ) {
3248 if ( lutil_atoul( &t, retry_list[j*2] ) != 0 ) {
3249 snprintf( c->msg, sizeof( c->msg ),
3250 "Error: invalid retry interval \"%s\" (#%d)",
3251 retry_list[j*2], j );
3252 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3253 /* do some cleanup */
3256 si->si_retryinterval[j] = (time_t)t;
3257 if ( *retry_list[j*2+1] == '+' ) {
3258 si->si_retrynum_init[j] = RETRYNUM_FOREVER;
3259 si->si_retrynum[j] = RETRYNUM_FOREVER;
3263 if ( lutil_atoi( &si->si_retrynum_init[j], retry_list[j*2+1] ) != 0
3264 || si->si_retrynum_init[j] <= 0 )
3266 snprintf( c->msg, sizeof( c->msg ),
3267 "Error: invalid initial retry number \"%s\" (#%d)",
3268 retry_list[j*2+1], j );
3269 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3270 /* do some cleanup */
3273 if ( lutil_atoi( &si->si_retrynum[j], retry_list[j*2+1] ) != 0
3274 || si->si_retrynum[j] <= 0 )
3276 snprintf( c->msg, sizeof( c->msg ),
3277 "Error: invalid retry number \"%s\" (#%d)",
3278 retry_list[j*2+1], j );
3279 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3280 /* do some cleanup */
3285 si->si_retrynum_init[j] = RETRYNUM_TAIL;
3286 si->si_retrynum[j] = RETRYNUM_TAIL;
3287 si->si_retryinterval[j] = 0;
3289 for ( k = 0; retry_list && retry_list[k]; k++ ) {
3290 ch_free( retry_list[k] );
3292 ch_free( retry_list );
3293 } else if ( !strncasecmp( c->argv[ i ], MANAGEDSAITSTR "=",
3294 STRLENOF( MANAGEDSAITSTR "=" ) ) )
3296 val = c->argv[ i ] + STRLENOF( MANAGEDSAITSTR "=" );
3297 if ( lutil_atoi( &si->si_manageDSAit, val ) != 0
3298 || si->si_manageDSAit < 0 || si->si_manageDSAit > 1 )
3300 snprintf( c->msg, sizeof( c->msg ),
3301 "invalid manageDSAit value \"%s\".\n",
3303 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3306 } else if ( !strncasecmp( c->argv[ i ], SLIMITSTR "=",
3307 STRLENOF( SLIMITSTR "=") ) )
3309 val = c->argv[ i ] + STRLENOF( SLIMITSTR "=" );
3310 if ( strcasecmp( val, "unlimited" ) == 0 ) {
3313 } else if ( lutil_atoi( &si->si_slimit, val ) != 0 || si->si_slimit < 0 ) {
3314 snprintf( c->msg, sizeof( c->msg ),
3315 "invalid size limit value \"%s\".\n",
3317 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3320 } else if ( !strncasecmp( c->argv[ i ], TLIMITSTR "=",
3321 STRLENOF( TLIMITSTR "=" ) ) )
3323 val = c->argv[ i ] + STRLENOF( TLIMITSTR "=" );
3324 if ( strcasecmp( val, "unlimited" ) == 0 ) {
3327 } else if ( lutil_atoi( &si->si_tlimit, val ) != 0 || si->si_tlimit < 0 ) {
3328 snprintf( c->msg, sizeof( c->msg ),
3329 "invalid time limit value \"%s\".\n",
3331 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3334 } else if ( !strncasecmp( c->argv[ i ], SYNCDATASTR "=",
3335 STRLENOF( SYNCDATASTR "=" ) ) )
3337 val = c->argv[ i ] + STRLENOF( SYNCDATASTR "=" );
3338 si->si_syncdata = verb_to_mask( val, datamodes );
3339 } else if ( bindconf_parse( c->argv[i], &si->si_bindconf ) ) {
3340 snprintf( c->msg, sizeof( c->msg ),
3341 "Error: parse_syncrepl_line: "
3342 "unable to parse \"%s\"\n", c->argv[ i ] );
3343 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3348 if ( gots != GOT_ALL ) {
3349 snprintf( c->msg, sizeof( c->msg ),
3350 "Error: Malformed \"syncrepl\" line in slapd config file, missing%s%s%s",
3351 gots & GOT_ID ? "" : " "IDSTR,
3352 gots & GOT_PROVIDER ? "" : " "PROVIDERSTR,
3353 gots & GOT_BASE ? "" : " "SEARCHBASESTR );
3354 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
3368 if ( !( c->be->be_search && c->be->be_add && c->be->be_modify && c->be->be_delete ) ) {
3369 snprintf( c->msg, sizeof(c->msg), "database %s does not support "
3370 "operations required for syncrepl", c->be->be_type );
3371 Debug( LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
3374 if ( BER_BVISEMPTY( &c->be->be_rootdn ) ) {
3375 strcpy( c->msg, "rootDN must be defined before syncrepl may be used" );
3376 Debug( LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
3379 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
3382 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
3386 si->si_bindconf.sb_tls = SB_TLS_OFF;
3387 si->si_bindconf.sb_method = LDAP_AUTH_SIMPLE;
3388 si->si_schemachecking = 0;
3389 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
3390 &si->si_filterstr );
3391 si->si_base.bv_val = NULL;
3392 si->si_scope = LDAP_SCOPE_SUBTREE;
3393 si->si_attrsonly = 0;
3394 si->si_anlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ) );
3395 si->si_exanlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ) );
3396 si->si_attrs = NULL;
3397 si->si_allattrs = 0;
3398 si->si_allopattrs = 0;
3399 si->si_exattrs = NULL;
3400 si->si_type = si->si_ctype = LDAP_SYNC_REFRESH_ONLY;
3401 si->si_interval = 86400;
3402 si->si_retryinterval = NULL;
3403 si->si_retrynum_init = NULL;
3404 si->si_retrynum = NULL;
3405 si->si_manageDSAit = 0;
3408 si->si_conn_setup = 0;
3410 si->si_presentlist = NULL;
3411 LDAP_LIST_INIT( &si->si_nonpresentlist );
3412 ldap_pvt_thread_mutex_init( &si->si_mutex );
3414 rc = parse_syncrepl_line( c, si );
3417 /* Must be LDAPv3 because we need controls */
3418 switch ( si->si_bindconf.sb_version ) {
3420 /* not explicitly set */
3421 si->si_bindconf.sb_version = LDAP_VERSION3;
3424 /* explicitly set */
3427 Debug( LDAP_DEBUG_ANY,
3428 "version %d incompatible with syncrepl\n",
3429 si->si_bindconf.sb_version, 0, 0 );
3430 syncinfo_free( si );
3435 if ( slapMode & SLAP_SERVER_MODE ) {
3436 Listener **l = slapd_get_listeners();
3439 /* check if URL points to current server. If so, ignore
3440 * this configuration. We require an exact match. Just
3441 * in case they really want to do this, they can vary
3442 * the case of the URL to allow it.
3444 if ( l && !SLAP_DBHIDDEN( c->be ) ) {
3446 for ( i=0; l[i]; i++ ) {
3447 if ( bvmatch( &l[i]->sl_url, &si->si_bindconf.sb_uri ) ) {
3455 init_syncrepl( si );
3456 si->si_re = ldap_pvt_runqueue_insert( &slapd_rq,
3457 si->si_interval, do_syncrepl, si, "do_syncrepl",
3458 c->be->be_suffix[0].bv_val );
3460 rc = config_sync_shadow( c ) ? -1 : 0;
3468 /* Use main slapd defaults */
3469 bindconf_tls_defaults( &si->si_bindconf );
3472 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
3473 syncinfo_free( si );
3476 Debug( LDAP_DEBUG_CONFIG,
3477 "Config: ** successfully added syncrepl \"%s\"\n",
3478 BER_BVISNULL( &si->si_bindconf.sb_uri ) ?
3479 "(null)" : si->si_bindconf.sb_uri.bv_val, 0, 0 );
3480 if ( !si->si_schemachecking ) {
3481 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
3483 c->be->be_syncinfo = si;
3489 syncrepl_unparse( syncinfo_t *si, struct berval *bv )
3491 struct berval bc, uri;
3492 char buf[BUFSIZ*2], *ptr;
3495 #define WHATSLEFT ( sizeof( buf ) - ( ptr - buf ) )
3499 /* temporarily inhibit bindconf from printing URI */
3500 uri = si->si_bindconf.sb_uri;
3501 BER_BVZERO( &si->si_bindconf.sb_uri );
3502 si->si_bindconf.sb_version = 0;
3503 bindconf_unparse( &si->si_bindconf, &bc );
3504 si->si_bindconf.sb_uri = uri;
3505 si->si_bindconf.sb_version = LDAP_VERSION3;
3508 ptr += snprintf( ptr, WHATSLEFT, IDSTR "=%03ld " PROVIDERSTR "=%s",
3509 si->si_rid, si->si_bindconf.sb_uri.bv_val );
3510 if ( ptr - buf >= sizeof( buf ) ) return;
3511 if ( !BER_BVISNULL( &bc ) ) {
3512 if ( WHATSLEFT <= bc.bv_len ) {
3516 ptr = lutil_strcopy( ptr, bc.bv_val );
3519 if ( !BER_BVISEMPTY( &si->si_filterstr ) ) {
3520 if ( WHATSLEFT <= STRLENOF( " " FILTERSTR "=\"" "\"" ) + si->si_filterstr.bv_len ) return;
3521 ptr = lutil_strcopy( ptr, " " FILTERSTR "=\"" );
3522 ptr = lutil_strcopy( ptr, si->si_filterstr.bv_val );
3525 if ( !BER_BVISNULL( &si->si_base ) ) {
3526 if ( WHATSLEFT <= STRLENOF( " " SEARCHBASESTR "=\"" "\"" ) + si->si_base.bv_len ) return;
3527 ptr = lutil_strcopy( ptr, " " SEARCHBASESTR "=\"" );
3528 ptr = lutil_strcopy( ptr, si->si_base.bv_val );
3531 if ( !BER_BVISEMPTY( &si->si_logfilterstr ) ) {
3532 if ( WHATSLEFT <= STRLENOF( " " LOGFILTERSTR "=\"" "\"" ) + si->si_logfilterstr.bv_len ) return;
3533 ptr = lutil_strcopy( ptr, " " LOGFILTERSTR "=\"" );
3534 ptr = lutil_strcopy( ptr, si->si_logfilterstr.bv_val );
3537 if ( !BER_BVISNULL( &si->si_logbase ) ) {
3538 if ( WHATSLEFT <= STRLENOF( " " LOGBASESTR "=\"" "\"" ) + si->si_logbase.bv_len ) return;
3539 ptr = lutil_strcopy( ptr, " " LOGBASESTR "=\"" );
3540 ptr = lutil_strcopy( ptr, si->si_logbase.bv_val );
3543 for (i=0; !BER_BVISNULL(&scopes[i].key);i++) {
3544 if ( si->si_scope == scopes[i].val ) {
3545 if ( WHATSLEFT <= STRLENOF( " " SCOPESTR "=" ) + scopes[i].key.bv_len ) return;
3546 ptr = lutil_strcopy( ptr, " " SCOPESTR "=" );
3547 ptr = lutil_strcopy( ptr, scopes[i].key.bv_val );
3551 if ( si->si_attrsonly ) {
3552 if ( WHATSLEFT <= STRLENOF( " " ATTRSONLYSTR "=\"" "\"" ) ) return;
3553 ptr = lutil_strcopy( ptr, " " ATTRSONLYSTR );
3555 if ( si->si_anfile ) {
3556 if ( WHATSLEFT <= STRLENOF( " " ATTRSSTR "=\":include:" "\"" ) + strlen( si->si_anfile ) ) return;
3557 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=:include:\"" );
3558 ptr = lutil_strcopy( ptr, si->si_anfile );
3560 } else if ( si->si_allattrs || si->si_allopattrs ||
3561 ( si->si_anlist && !BER_BVISNULL(&si->si_anlist[0].an_name) ) )
3565 if ( WHATSLEFT <= STRLENOF( " " ATTRSONLYSTR "=\"" "\"" ) ) return;
3566 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=\"" );
3568 /* FIXME: add check for overflow */
3569 ptr = anlist_unparse( si->si_anlist, ptr, WHATSLEFT );
3570 if ( si->si_allattrs ) {
3571 if ( WHATSLEFT <= STRLENOF( ",*\"" ) ) return;
3572 if ( old != ptr ) *ptr++ = ',';
3575 if ( si->si_allopattrs ) {
3576 if ( WHATSLEFT <= STRLENOF( ",+\"" ) ) return;
3577 if ( old != ptr ) *ptr++ = ',';
3582 if ( si->si_exanlist && !BER_BVISNULL(&si->si_exanlist[0].an_name) ) {
3583 if ( WHATSLEFT <= STRLENOF( " " EXATTRSSTR "=" ) ) return;
3584 ptr = lutil_strcopy( ptr, " " EXATTRSSTR "=" );
3585 /* FIXME: add check for overflow */
3586 ptr = anlist_unparse( si->si_exanlist, ptr, WHATSLEFT );
3588 if ( WHATSLEFT <= STRLENOF( " " SCHEMASTR "=" ) + STRLENOF( "off" ) ) return;
3589 ptr = lutil_strcopy( ptr, " " SCHEMASTR "=" );
3590 ptr = lutil_strcopy( ptr, si->si_schemachecking ? "on" : "off" );
3592 if ( WHATSLEFT <= STRLENOF( " " TYPESTR "=" ) + STRLENOF( "refreshAndPersist" ) ) return;
3593 ptr = lutil_strcopy( ptr, " " TYPESTR "=" );
3594 ptr = lutil_strcopy( ptr, si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ?
3595 "refreshAndPersist" : "refreshOnly" );
3597 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
3600 dd = si->si_interval;
3607 ptr = lutil_strcopy( ptr, " " INTERVALSTR "=" );
3608 ptr += snprintf( ptr, WHATSLEFT, "%02d:%02d:%02d:%02d", dd, hh, mm, ss );
3609 if ( ptr - buf >= sizeof( buf ) ) return;
3610 } else if ( si->si_retryinterval ) {
3612 if ( WHATSLEFT <= STRLENOF( " " RETRYSTR "=\"" "\"" ) ) return;
3613 ptr = lutil_strcopy( ptr, " " RETRYSTR "=\"" );
3614 for (i=0; si->si_retryinterval[i]; i++) {
3615 if ( space ) *ptr++ = ' ';
3617 ptr += snprintf( ptr, WHATSLEFT, "%ld ", (long) si->si_retryinterval[i] );
3618 if ( si->si_retrynum_init[i] == RETRYNUM_FOREVER )
3621 ptr += snprintf( ptr, WHATSLEFT, "%d", si->si_retrynum_init[i] );
3623 if ( WHATSLEFT <= STRLENOF( "\"" ) ) return;
3627 if ( si->si_slimit ) {
3628 if ( WHATSLEFT <= STRLENOF( " " SLIMITSTR "=" ) ) return;
3629 ptr = lutil_strcopy( ptr, " " SLIMITSTR "=" );
3630 ptr += snprintf( ptr, WHATSLEFT, "%d", si->si_slimit );
3633 if ( si->si_tlimit ) {
3634 if ( WHATSLEFT <= STRLENOF( " " TLIMITSTR "=" ) ) return;
3635 ptr = lutil_strcopy( ptr, " " TLIMITSTR "=" );
3636 ptr += snprintf( ptr, WHATSLEFT, "%d", si->si_tlimit );
3639 if ( si->si_syncdata ) {
3640 if ( enum_to_verb( datamodes, si->si_syncdata, &bc ) >= 0 ) {
3641 if ( WHATSLEFT <= STRLENOF( " " SYNCDATASTR "=" ) + bc.bv_len ) return;
3642 ptr = lutil_strcopy( ptr, " " SYNCDATASTR "=" );
3643 ptr = lutil_strcopy( ptr, bc.bv_val );
3646 bc.bv_len = ptr - buf;
3648 ber_dupbv( bv, &bc );
3652 syncrepl_config( ConfigArgs *c )
3654 if (c->op == SLAP_CONFIG_EMIT) {
3655 if ( c->be->be_syncinfo ) {
3657 syncrepl_unparse( c->be->be_syncinfo, &bv );
3658 ber_bvarray_add( &c->rvalue_vals, &bv );
3662 } else if ( c->op == LDAP_MOD_DELETE ) {
3663 if ( c->be->be_syncinfo ) {
3664 syncinfo_free( c->be->be_syncinfo );
3665 c->be->be_syncinfo = NULL;
3667 SLAP_DBFLAGS( c->be ) &= ~(SLAP_DBFLAG_SHADOW|SLAP_DBFLAG_SYNC_SHADOW);
3670 if ( SLAP_SHADOW( c->be ) ) {
3671 Debug(LDAP_DEBUG_ANY, "%s: "
3672 "syncrepl: database already shadowed.\n",
3676 return add_syncrepl( c );