3 * Replication Engine which uses the LDAP Sync protocol
5 /* Copyright (c) 2003 by International Business Machines, Inc.
7 * International Business Machines, Inc. (hereinafter called IBM) grants
8 * permission under its copyrights to use, copy, modify, and distribute this
9 * Software with or without fee, provided that the above copyright notice and
10 * all paragraphs of this notice appear in all copies, and that the name of IBM
11 * not be used in connection with the marketing of any product incorporating
12 * the Software or modifications thereof, without specific, written prior
15 * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17 * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
18 * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
19 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
20 * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
27 #include <ac/string.h>
28 #include <ac/socket.h>
34 #include "lutil_ldap.h"
39 syncrepl_del_nonpresent( LDAP *, Operation * );
41 /* callback functions */
42 static int cookie_callback( struct slap_op *, struct slap_rep * );
43 static int dn_callback( struct slap_op *, struct slap_rep * );
44 static int nonpresent_callback( struct slap_op *, struct slap_rep * );
45 static int null_callback( struct slap_op *, struct slap_rep * );
46 static int contextcsn_callback( Operation*, SlapReply* );
48 static AttributeDescription **sync_descs;
50 struct runqueue_s syncrepl_rq;
55 sync_descs = ch_malloc( 4 * sizeof( AttributeDescription * ));
56 sync_descs[0] = slap_schema.si_ad_objectClass;
57 sync_descs[1] = slap_schema.si_ad_structuralObjectClass;
58 sync_descs[2] = slap_schema.si_ad_entryCSN;
75 BerElement *sync_ber = NULL;
76 struct berval *sync_bvalp = NULL;
80 struct timeval timeout;
82 /* setup LDAP SYNC control */
83 sync_ber = ber_alloc_t( LBER_USE_DER );
84 ber_set_option( sync_ber, LBER_OPT_BER_MEMCTX, NULL );
86 if ( si->syncCookie ) {
87 ber_printf( sync_ber, "{eO}", abs(si->type), si->syncCookie );
89 ber_printf( sync_ber, "{e}", abs(si->type) );
92 if ( ber_flatten( sync_ber, &sync_bvalp ) == LBER_ERROR ) {
93 ber_free( sync_ber, 1 );
96 ber_free( sync_ber, 1 );
98 ctrls = (LDAPControl**) sl_calloc( 3, sizeof(LDAPControl*), NULL );
100 c[0].ldctl_oid = LDAP_CONTROL_SYNC;
101 c[0].ldctl_value = (*sync_bvalp);
102 c[0].ldctl_iscritical = si->type < 0;
106 c[1].ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
107 c[1].ldctl_value.bv_val = si->authzId;
108 c[1].ldctl_value.bv_len = strlen( si->authzId );
109 c[1].ldctl_iscritical = 1;
117 err = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, ctrls );
119 ber_bvfree( sync_bvalp );
122 if ( err != LDAP_OPT_SUCCESS )
123 fprintf( stderr, "Could not set controls : %d\n", err );
125 timeout.tv_sec = si->tlimit > 0 ? si->tlimit : 1;
127 rc = ldap_search_ext( ld, si->base, si->scope, si->filterstr,
128 si->attrs, si->attrsonly, sctrls, cctrls,
129 si->tlimit < 0 ? NULL : &timeout,
130 si->slimit, msgidp );
140 struct re_s* rtask = arg;
141 syncinfo_t *si = ( syncinfo_t * ) rtask->arg;
142 Backend *be = si->be;
144 SlapReply rs = {REP_RESULT};
147 LDAPControl **sctrls = NULL;
148 LDAPControl **rctrls = NULL;
149 LDAPControl *rctrlp = NULL;
150 BerElement *sync_ber = NULL;
151 struct berval *sync_bvalp = NULL;
153 BerElement *ctrl_ber = NULL;
154 BerElement *res_ber = NULL;
157 LDAPMessage *res = NULL;
158 LDAPMessage *msg = NULL;
162 int nresponses, nreferences, nextended, npartial;
163 int nresponses_psearch;
165 int cancel_msgid = -1;
167 struct berval *retdata = NULL;
169 int sync_info_arrived = 0;
173 struct berval syncUUID = { 0, NULL };
174 struct berval syncCookie = { 0, NULL };
175 struct berval syncCookie_req = { 0, NULL };
180 int syncinfo_arrived = 0;
183 AttributeDescription** descs = NULL;
195 struct berval base_bv = { 0, NULL };
196 struct berval pbase = { 0, NULL };
197 struct berval nbase = { 0, NULL };
198 struct berval sub_bv = { 0, NULL };
199 struct berval psubrdn = { 0, NULL };
200 struct berval nsubrdn = { 0, NULL };
201 struct berval psub = { 0, NULL };
202 struct berval nsub = { 0, NULL };
204 Modifications *modlist = NULL;
205 Modifications *ml, *mlnext;
206 char *def_filter_str = NULL;
211 struct timeval *tout_p = NULL;
212 struct timeval tout = { 10, 0 };
215 LDAP_LOG ( OPERATION, DETAIL1, "do_syncrepl\n", 0, 0, 0 );
217 Debug( LDAP_DEBUG_TRACE, "=>do_syncrepl\n", 0, 0, 0 );
223 if ( abs(si->type) != LDAP_SYNC_REFRESH_ONLY &&
224 abs(si->type) != LDAP_SYNC_REFRESH_AND_PERSIST ) {
228 si->sync_mode = LDAP_SYNC_STATE_MODE;
230 /* Init connection to master */
232 rc = ldap_initialize( &ld, si->provideruri );
233 if ( rc != LDAP_SUCCESS ) {
235 LDAP_LOG( OPERATION, ERR, "do_syncrepl: "
236 "ldap_initialize failed (%s)\n",
237 si->provideruri, 0, 0 );
239 Debug( LDAP_DEBUG_ANY, "do_syncrepl: "
240 "ldap_initialize failed (%s)\n",
241 si->provideruri, 0, 0 );
245 op.o_protocol = LDAP_VERSION3;
246 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &op.o_protocol );
251 rc = ldap_start_tls_s( ld, NULL, NULL );
252 if( rc != LDAP_SUCCESS ) {
254 LDAP_LOG ( OPERATION, ERR, "do_syncrepl: "
255 "%s: ldap_start_tls failed (%d)\n",
256 si->tls == TLS_CRITICAL ? "Error" : "Warning",
259 Debug( LDAP_DEBUG_ANY,
260 "%s: ldap_start_tls failed (%d)\n",
261 si->tls == TLS_CRITICAL ? "Error" : "Warning",
264 if( si->tls == TLS_CRITICAL )
269 if ( si->bindmethod == LDAP_AUTH_SASL ) {
270 #ifdef HAVE_CYRUS_SASL
273 if ( si->secprops != NULL ) {
274 int err = ldap_set_option( ld,
275 LDAP_OPT_X_SASL_SECPROPS, si->secprops);
277 if( err != LDAP_OPT_SUCCESS ) {
279 LDAP_LOG ( OPERATION, ERR, "do_bind: Error: "
280 "ldap_set_option(%s,SECPROPS,\"%s\") failed!\n",
281 si->provideruri, si->secprops, 0 );
283 Debug( LDAP_DEBUG_ANY, "Error: ldap_set_option "
284 "(%s,SECPROPS,\"%s\") failed!\n",
285 si->provideruri, si->secprops, NULL );
291 defaults = lutil_sasl_defaults( ld,
298 rc = ldap_sasl_interactive_bind_s( ld,
306 /* FIXME : different error behaviors according to
308 2) on err policy : exit, retry, backoff ...
310 if ( rc != LDAP_SUCCESS ) {
312 LDAP_LOG ( OPERATION, ERR, "do_syncrepl: "
313 "ldap_sasl_interactive_bind_s failed (%d)\n",
316 Debug( LDAP_DEBUG_ANY, "do_syncrepl: "
317 "ldap_sasl_interactive_bind_s failed (%d)\n",
322 #else /* HAVE_CYRUS_SASL */
323 fprintf( stderr, "not compiled with SASL support\n" );
327 rc = ldap_bind_s( ld, si->binddn, si->passwd, si->bindmethod );
328 if ( rc != LDAP_SUCCESS ) {
330 LDAP_LOG ( OPERATION, ERR, "do_syncrepl: "
331 "ldap_bind_s failed (%d)\n", rc, 0, 0 );
333 Debug( LDAP_DEBUG_ANY, "do_syncrepl: "
334 "ldap_bind_s failed (%d)\n", rc, 0, 0 );
340 /* set thread context in syncinfo */
343 /* set memory context */
344 #define SLAB_SIZE 1048576
346 memctx = sl_mem_create( memsiz, ctx );
347 op.o_tmpmemctx = memctx;
348 op.o_tmpmfuncs = &sl_mfuncs;
351 op.o_tag = LDAP_REQ_SEARCH;
352 op.o_dn = si->updatedn;
353 op.o_ndn = si->updatedn;
355 op.o_time = slap_get_time();
356 op.o_managedsait = 1;
357 op.o_threadctx = si->ctx;
360 op.o_connid = op.o_conn->c_connid;
361 op.ors_scope = LDAP_SCOPE_BASE;
362 op.ors_deref = LDAP_DEREF_NEVER;
365 op.ors_attrsonly = 0;
367 op.ors_filter = str2filter( def_filter_str = "(objectClass=*)" );
368 ber_str2bv( def_filter_str, strlen( def_filter_str ), 1,
372 conn.c_send_ldap_result = slap_send_ldap_result;
373 conn.c_send_search_entry = slap_send_search_entry;
374 conn.c_send_search_reference = slap_send_search_reference;
376 /* get syncrepl cookie of shadow replica from subentry */
377 ber_str2bv( si->base, strlen(si->base), 1, &base_bv );
378 dnPrettyNormal( 0, &base_bv, &pbase, &nbase, op.o_tmpmemctx );
380 sprintf( substr, "cn=syncrepl%d", si->id );
381 ber_str2bv( substr, strlen(substr), 1, &sub_bv );
382 dnPrettyNormal( 0, &sub_bv, &psubrdn, &nsubrdn, op.o_tmpmemctx );
384 build_new_dn( &op.o_req_dn, &pbase, &psubrdn );
385 build_new_dn( &op.o_req_ndn, &nbase, &nsubrdn );
387 ch_free( base_bv.bv_val );
388 ch_free( pbase.bv_val );
389 ch_free( nbase.bv_val );
390 ch_free( sub_bv.bv_val );
391 ch_free( psubrdn.bv_val );
392 ch_free( nsubrdn.bv_val );
394 /* set callback function */
395 cb.sc_response = cookie_callback;
398 /* search subentry to retrieve cookie */
399 si->syncCookie = NULL;
400 be->be_search( &op, &rs );
402 ber_dupbv( &syncCookie_req, si->syncCookie );
404 ch_free( op.o_req_dn.bv_val );
405 ch_free( op.o_req_ndn.bv_val );
406 filter_free( op.ors_filter );
407 ch_free( op.ors_filterstr.bv_val );
409 psub = be->be_nsuffix[0];
411 for ( n = 0; si->attrs[ n ] != NULL; n++ ) ;
414 /* Delete Attributes */
416 for ( i = 0; descs[i] != NULL; i++ ) {
417 for ( j = 0; si->attrs[j] != NULL; j++ ) {
418 if ( !strcmp( si->attrs[j], descs[i]->ad_cname.bv_val )) {
419 ch_free( si->attrs[j] );
420 for ( k = j; si->attrs[k] != NULL; k++ ) {
421 si->attrs[k] = si->attrs[k+1];
426 for ( n = 0; si->attrs[ n ] != NULL; n++ );
427 tmp = ( char ** ) ch_realloc( si->attrs, ( n + 4 ) * sizeof( char * ));
430 LDAP_LOG( OPERATION, ERR, "out of memory\n", 0,0,0 );
432 Debug( LDAP_DEBUG_ANY, "out of memory\n", 0,0,0 );
436 tmp = ( char ** ) ch_realloc( si->attrs, 5 * sizeof( char * ));
439 LDAP_LOG( OPERATION, ERR, "out of memory\n", 0,0,0 );
441 Debug( LDAP_DEBUG_ANY, "out of memory\n", 0,0,0 );
444 tmp[ n++ ] = ch_strdup( "*" );
452 for ( i = 0; descs[ i ] != NULL; i++ ) {
453 si->attrs[ n++ ] = ch_strdup ( descs[i]->ad_cname.bv_val );
454 si->attrs[ n ] = NULL;
457 rc = ldap_sync_search( si, ld, NULL, NULL, &msgid );
458 if( rc != LDAP_SUCCESS ) {
459 fprintf( stderr, "syncrepl: ldap_search_ext: %s (%d)\n",
460 ldap_err2string( rc ), rc );
464 if ( abs(si->type) == LDAP_SYNC_REFRESH_AND_PERSIST ){
470 while (( rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ONE, tout_p, &res )) >= 0 ) {
473 if ( slapd_abrupt_shutdown ) {
480 for ( msg = ldap_first_message( ld, res );
482 msg = ldap_next_message( ld, msg ) )
484 syncCookie.bv_len = 0; syncCookie.bv_val = NULL;
485 switch( ldap_msgtype( msg ) ) {
486 case LDAP_RES_SEARCH_ENTRY:
487 entry = syncrepl_message_to_entry( si, ld, &op, msg,
488 &modlist, &syncstate, &syncUUID, &syncCookie );
489 rc_efree = syncrepl_entry( si, ld, &op, entry, modlist,
490 syncstate, &syncUUID, &syncCookie, !syncinfo_arrived );
491 if ( syncCookie.bv_len ) {
492 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie );
496 for ( ml = modlist; ml != NULL; ml = mlnext ) {
497 mlnext = ml->sml_next;
502 case LDAP_RES_SEARCH_REFERENCE:
504 LDAP_LOG( OPERATION, ERR,
505 "do_syncrepl : reference received\n", 0, 0, 0 );
507 Debug( LDAP_DEBUG_ANY,
508 "do_syncrepl : reference received\n", 0, 0, 0 );
512 case LDAP_RES_SEARCH_RESULT:
513 ldap_parse_result( ld, msg, &err, NULL, NULL, NULL, &rctrls, 0 );
516 ctrl_ber = ber_alloc_t( LBER_USE_DER );
517 ber_set_option( ctrl_ber, LBER_OPT_BER_MEMCTX, &op.o_tmpmemctx );
518 ber_write( ctrl_ber, rctrlp->ldctl_value.bv_val, rctrlp->ldctl_value.bv_len, 0 );
519 ber_reset( ctrl_ber, 1 );
521 ber_scanf( ctrl_ber, "{" /*"}"*/);
522 if ( ber_peek_tag( ctrl_ber, &len )
523 == LDAP_SYNC_TAG_COOKIE ) {
524 ber_scanf( ctrl_ber, "o", &syncCookie );
527 value_match( &match, slap_schema.si_ad_entryCSN,
528 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
529 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
530 &syncCookie_req, &syncCookie, &text );
531 if (si->type == LDAP_SYNC_REFRESH_AND_PERSIST) {
532 /* FIXME : different error behaviors according to
533 1) err code : LDAP_BUSY ...
534 2) on err policy : stop service, stop sync, retry
536 if ( syncCookie.bv_len && match < 0) {
537 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie );
540 ber_free( ctrl_ber, 1 );
543 /* FIXME : different error behaviors according to
544 1) err code : LDAP_BUSY ...
545 2) on err policy : stop service, stop sync, retry
547 if ( syncCookie.bv_len && match < 0 ) {
548 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie);
550 if ( si->sync_mode == LDAP_SYNC_STATE_MODE && match < 0 ) {
551 syncrepl_del_nonpresent( ld, &op );
554 ber_free( ctrl_ber, 1 );
559 case LDAP_RES_INTERMEDIATE:
560 rc = ldap_parse_intermediate( ld, msg,
561 &retoid, &retdata, NULL, 0 );
562 if ( !rc && !strcmp( retoid, LDAP_SYNC_INFO ) ) {
563 sync_info_arrived = 1;
564 res_ber = ber_init( retdata );
565 ber_scanf( res_ber, "{e" /*"}"*/, &syncstate );
567 if ( ber_peek_tag( res_ber, &len )
568 == LDAP_SYNC_TAG_COOKIE ) {
569 ber_scanf( res_ber, /*"{"*/ "o}", &syncCookie );
571 if ( syncstate == LDAP_SYNC_NEW_COOKIE ) {
573 LDAP_LOG( OPERATION, ERR,
574 "do_syncrepl : cookie required\n", 0, 0, 0 );
576 Debug( LDAP_DEBUG_ANY,
577 "do_syncrepl : cookie required\n", 0, 0, 0 );
582 value_match( &match, slap_schema.si_ad_entryCSN,
583 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
584 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
585 &syncCookie_req, &syncCookie, &text );
587 if ( syncCookie.bv_len && match < 0 ) {
588 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie);
591 if ( syncstate == LDAP_SYNC_STATE_MODE_DONE ) {
593 syncrepl_del_nonpresent( ld, &op );
595 si->sync_mode = LDAP_SYNC_LOG_MODE;
596 } else if ( syncstate == LDAP_SYNC_LOG_MODE_DONE ) {
597 si->sync_mode = LDAP_SYNC_PERSIST_MODE;
598 } else if ( syncstate == LDAP_SYNC_REFRESH_DONE ) {
599 si->sync_mode = LDAP_SYNC_PERSIST_MODE;
600 } else if ( syncstate != LDAP_SYNC_NEW_COOKIE ||
601 syncstate != LDAP_SYNC_LOG_MODE_DONE ) {
603 LDAP_LOG( OPERATION, ERR,
604 "do_syncrepl : unknown sync info\n", 0, 0, 0 );
606 Debug( LDAP_DEBUG_ANY,
607 "do_syncrepl : unknown sync info\n", 0, 0, 0 );
611 ldap_memfree( retoid );
612 ber_bvfree( retdata );
613 ber_free( res_ber, 1 );
617 LDAP_LOG( OPERATION, ERR,"do_syncrepl :"
618 " unknown intermediate "
619 "response\n", 0, 0, 0 );
621 Debug( LDAP_DEBUG_ANY, "do_syncrepl : "
622 "unknown intermediate response (%d)\n",
625 ldap_memfree( retoid );
626 ber_bvfree( retdata );
632 LDAP_LOG( OPERATION, ERR, "do_syncrepl : "
633 "unknown message\n", 0, 0, 0 );
635 Debug( LDAP_DEBUG_ANY, "do_syncrepl : "
636 "unknown message\n", 0, 0, 0 );
647 LDAP_LOG( OPERATION, ERR,
648 "do_syncrepl : unknown result\n", 0, 0, 0 );
650 Debug( LDAP_DEBUG_ANY,
651 "do_syncrepl : unknown result\n", 0, 0, 0 );
656 if ( syncCookie.bv_val )
657 ch_free( syncCookie.bv_val );
658 if ( syncCookie_req.bv_val )
659 ch_free( syncCookie_req.bv_val );
660 if ( syncUUID.bv_val )
661 ch_free( syncUUID.bv_val );
668 ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
669 ldap_pvt_runqueue_stoptask( &syncrepl_rq, rtask );
670 if ( si->type == LDAP_SYNC_REFRESH_ONLY ) {
671 ldap_pvt_runqueue_resched( &syncrepl_rq, rtask );
673 ldap_pvt_runqueue_remove( &syncrepl_rq, rtask );
675 ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
681 syncrepl_message_to_entry(
686 Modifications **modlist,
688 struct berval *syncUUID,
689 struct berval *syncCookie
693 BerElement *ber = NULL;
695 struct berval bv = {0, NULL};
698 Modifications **modtail = modlist;
699 Backend *be = op->o_bd;
702 char txtbuf[SLAP_TEXT_BUFLEN];
703 size_t textlen = sizeof txtbuf;
705 struct berval **bvals = NULL;
707 struct berval bdn = {0, NULL};
709 struct berval empty_bv = { 0, NULL };
715 LDAPControl** rctrls = NULL;
716 BerElement* ctrl_ber;
720 Modifications *ml = NULL;
721 AttributeDescription** descs;
726 if ( ldap_msgtype( msg ) != LDAP_RES_SEARCH_ENTRY ) {
728 LDAP_LOG( OPERATION, ERR,
729 "Message type should be entry (%d)", ldap_msgtype( msg ), 0, 0 );
731 Debug( LDAP_DEBUG_ANY,
732 "Message type should be entry (%d)", ldap_msgtype( msg ), 0, 0 );
737 op->o_tag = LDAP_REQ_ADD;
739 rc = ldap_get_dn_ber( ld, msg, &ber, &bdn );
741 if ( rc != LDAP_SUCCESS ) {
743 LDAP_LOG( OPERATION, ERR,
744 "syncrepl_message_to_entry : dn get failed (%d)", rc, 0, 0 );
746 Debug( LDAP_DEBUG_ANY,
747 "syncrepl_message_to_entry : dn get failed (%d)", rc, 0, 0 );
752 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
753 dnPrettyNormal( NULL, &bdn, &e->e_name, &e->e_nname, NULL );
757 while ( ber_remaining( ber ) ) {
758 tag = ber_scanf( ber, "{mW}", &tmp.sml_type, &tmp.sml_values );
760 if ( tag == LBER_ERROR ) break;
761 if ( tmp.sml_type.bv_val == NULL ) break;
763 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
765 mod->sml_op = LDAP_MOD_REPLACE;
766 mod->sml_next = NULL;
767 mod->sml_desc = NULL;
768 mod->sml_type = tmp.sml_type;
769 mod->sml_bvalues = tmp.sml_bvalues;
770 mod->sml_nvalues = NULL;
773 modtail = &mod->sml_next;
776 if ( ber_scanf( ber, "}") == LBER_ERROR ) {
778 LDAP_LOG( OPERATION, ERR,
779 "syncrepl_message_to_entry: ber_scanf failed\n", 0, 0, 0 );
781 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: ber_scanf failed\n",
788 tmpber = ldap_get_message_ber( msg );
789 ber = ber_dup( tmpber );
791 ber_scanf( ber, "{xx" );
793 rc = ldap_int_get_controls( ber, &rctrls );
795 if ( rc != LDAP_SUCCESS ) {
797 LDAP_LOG( OPERATION, ERR,
798 "syncrepl_message_to_entry : control get failed (%d)", rc, 0, 0 );
800 Debug( LDAP_DEBUG_ANY,
801 "syncrepl_message_to_entry : control get failed (%d)", rc, 0, 0 );
808 ctrl_ber = ber_alloc_t( LBER_USE_DER );
809 ber_set_option( ctrl_ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
810 ber_write( ctrl_ber, rctrlp->ldctl_value.bv_val, rctrlp->ldctl_value.bv_len, 0 );
811 ber_reset( ctrl_ber, 1 );
812 ber_scanf( ctrl_ber, "{eo", syncstate, syncUUID );
813 if ( ber_peek_tag( ctrl_ber, &len ) == LDAP_SYNC_TAG_COOKIE ) {
814 ber_scanf( ctrl_ber, "o}", syncCookie );
816 ber_free( ctrl_ber, 1 );
819 LDAP_LOG( OPERATION, ERR,"syncrepl_message_to_entry : "
820 " rctrls absent\n", 0, 0, 0 );
822 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry :"
823 " rctrls absent\n", 0, 0, 0 );
827 if ( *syncstate == LDAP_SYNC_PRESENT ) {
830 } else if ( *syncstate == LDAP_SYNC_DELETE ) {
834 if ( *modlist == NULL ) {
836 LDAP_LOG( OPERATION, ERR,
837 "syncrepl_message_to_entry: no attributes\n", 0, 0, 0 );
839 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: no attributes\n",
845 while ( ml != NULL ) {
846 AttributeDescription *ad = NULL;
847 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, &text );
849 if( rc != LDAP_SUCCESS ) {
859 rc = slap_mods_check( *modlist, 1, &text, txtbuf, textlen, NULL );
861 if ( rc != LDAP_SUCCESS ) {
863 LDAP_LOG( OPERATION, ERR,
864 "syncrepl_message_to_entry: mods check (%s)\n", text, 0, 0 );
866 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods check (%s)\n",
872 rc = slap_mods2entry( *modlist, &e, 1, 1, &text, txtbuf, textlen);
873 if( rc != LDAP_SUCCESS ) {
875 LDAP_LOG( OPERATION, ERR,
876 "syncrepl_message_to_entry: mods2entry (%s)\n", text, 0, 0 );
878 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods2entry (%s)\n",
891 syncuuid_cmp( const void* v_uuid1, const void* v_uuid2 )
893 const struct berval *uuid1 = v_uuid1;
894 const struct berval *uuid2 = v_uuid2;
895 int rc = uuid1->bv_len - uuid2->bv_len;
897 return ( strcmp( uuid1->bv_val, uuid2->bv_val ) );
906 Modifications* modlist,
908 struct berval* syncUUID,
909 struct berval* syncCookie,
913 Backend *be = op->o_bd;
915 struct berval csn_bv = {0, NULL};
916 struct berval *syncuuid_bv = NULL;
917 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
919 SlapReply rs = {REP_RESULT};
920 int rc = LDAP_SUCCESS;
922 struct berval base_bv = {0, NULL};
930 ( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD )) {
931 syncuuid_bv = ber_dupbv( NULL, syncUUID );
932 avl_insert( &si->presentlist, (caddr_t) syncuuid_bv,
933 syncuuid_cmp, avl_dup_error );
936 if ( syncstate == LDAP_SYNC_PRESENT ) {
943 filterstr = (char *) sl_malloc( strlen("entryUUID=") + syncUUID->bv_len + 1,
945 strcpy( filterstr, "entryUUID=" );
946 strcat( filterstr, syncUUID->bv_val );
949 si->syncUUID = syncUUID;
950 si->syncUUID_ndn = NULL;
952 filter = str2filter( filterstr );
953 ber_str2bv( filterstr, strlen(filterstr), 1, &op->ors_filterstr );
954 ch_free( filterstr );
955 op->ors_filter = filter;
956 op->ors_scope = LDAP_SCOPE_SUBTREE;
958 /* get syncrepl cookie of shadow replica from subentry */
959 ber_str2bv( si->base, strlen(si->base), 1, &base_bv );
960 dnPrettyNormal( 0, &base_bv, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
961 ch_free( base_bv.bv_val );
963 /* set callback function */
964 op->o_callback = &cb;
965 cb.sc_response = dn_callback;
968 si->syncUUID_ndn = NULL;
970 rc = be->be_search( op, &rs );
972 ch_free( op->o_req_dn.bv_val );
973 ch_free( op->o_req_ndn.bv_val );
974 filter_free( op->ors_filter );
975 ch_free( op->ors_filterstr.bv_val );
977 cb.sc_response = null_callback;
980 if ( rc == LDAP_SUCCESS && si->syncUUID_ndn && si->sync_mode != LDAP_SYNC_LOG_MODE ) {
981 op->o_req_dn = *si->syncUUID_ndn;
982 op->o_req_ndn = *si->syncUUID_ndn;
983 op->o_tag = LDAP_REQ_DELETE;
984 rc = be->be_delete( op, &rs );
987 if ( si->syncUUID_ndn ) {
988 ber_bvfree( si->syncUUID_ndn );
991 switch ( syncstate ) {
993 case LDAP_SYNC_MODIFY :
995 if ( rc == LDAP_SUCCESS ||
996 rc == LDAP_REFERRAL ||
997 rc == LDAP_NO_SUCH_OBJECT ) {
999 attr_delete( &e->e_attrs, slap_schema.si_ad_entryUUID );
1000 attr_merge_normalize_one( e, slap_schema.si_ad_entryUUID, syncUUID, op->o_tmpmemctx );
1002 op->o_tag = LDAP_REQ_ADD;
1004 op->o_req_dn = e->e_name;
1005 op->o_req_ndn = e->e_nname;
1006 rc = be->be_add( op, &rs );
1008 if ( rc != LDAP_SUCCESS ) {
1009 if ( rc == LDAP_ALREADY_EXISTS ) {
1010 op->o_tag = LDAP_REQ_MODIFY;
1011 op->orm_modlist = modlist;
1012 op->o_req_dn = e->e_name;
1013 op->o_req_ndn = e->e_nname;
1014 rc = be->be_modify( op, &rs );
1016 if ( rc != LDAP_SUCCESS ) {
1018 LDAP_LOG( OPERATION, ERR,
1019 "syncrepl_entry : be_modify failed (%d)\n",
1022 Debug( LDAP_DEBUG_ANY,
1023 "syncrepl_entry : be_modify failed (%d)\n",
1029 } else if ( rc == LDAP_REFERRAL ||
1030 rc == LDAP_NO_SUCH_OBJECT ) {
1031 syncrepl_add_glue( si, ld, op, e,
1033 syncUUID, syncCookie);
1038 LDAP_LOG( OPERATION, ERR,
1039 "syncrepl_entry : be_add failed (%d)\n",
1042 Debug( LDAP_DEBUG_ANY,
1043 "syncrepl_entry : be_add failed (%d)\n",
1051 be_entry_release_w( op, e );
1056 LDAP_LOG( OPERATION, ERR,
1057 "syncrepl_entry : be_search failed (%d)\n", rc, 0, 0 );
1059 Debug( LDAP_DEBUG_ANY,
1060 "syncrepl_entry : be_search failed (%d)\n", rc, 0, 0 );
1066 case LDAP_SYNC_DELETE :
1067 if ( si->sync_mode == LDAP_SYNC_LOG_MODE ) {
1068 op->o_req_dn = *si->syncUUID_ndn;
1069 op->o_req_ndn = *si->syncUUID_ndn;
1070 op->o_tag = LDAP_REQ_DELETE;
1071 rc = be->be_delete( op, &rs );
1073 /* Already deleted otherwise */
1078 LDAP_LOG( OPERATION, ERR,
1079 "syncrepl_entry : unknown syncstate\n", 0, 0, 0 );
1081 Debug( LDAP_DEBUG_ANY,
1082 "syncrepl_entry : unknown syncstate\n", 0, 0, 0 );
1089 syncrepl_del_nonpresent(
1094 Backend* be = op->o_bd;
1095 syncinfo_t *si = op->o_si;
1097 struct berval base_bv = {0, NULL};
1099 SlapReply rs = {REP_RESULT};
1100 struct berval filterstr_bv = {0, NULL};
1101 struct nonpresent_entry *np_list, *np_prev;
1103 ber_str2bv( si->base, strlen(si->base), 1, &base_bv );
1104 dnPrettyNormal(0, &base_bv, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
1105 ch_free( base_bv.bv_val );
1107 filter = str2filter( si->filterstr );
1109 cb.sc_response = nonpresent_callback;
1112 op->o_callback = &cb;
1113 op->o_tag = LDAP_REQ_SEARCH;
1114 op->ors_scope = si->scope;
1115 op->ors_deref = LDAP_DEREF_NEVER;
1118 op->ors_attrsonly = 0;
1119 op->ors_attrs = NULL;
1120 op->ors_filter = filter;
1121 ber_str2bv( si->filterstr, strlen( si->filterstr ), 1, &op->ors_filterstr );
1123 be->be_search( op, &rs );
1125 if ( !LDAP_LIST_EMPTY( &si->nonpresentlist ) ) {
1126 np_list = LDAP_LIST_FIRST( &si->nonpresentlist );
1127 while ( np_list != NULL ) {
1128 LDAP_LIST_REMOVE( np_list, np_link );
1130 np_list = LDAP_LIST_NEXT( np_list, np_link );
1131 op->o_tag = LDAP_REQ_DELETE;
1132 op->o_callback = &cb;
1133 cb.sc_response = null_callback;
1135 op->o_req_dn = *np_prev->dn;
1136 op->o_req_ndn = *np_prev->ndn;
1137 op->o_bd->be_delete( op, &rs );
1138 ber_bvfree( np_prev->dn );
1139 ber_bvfree( np_prev->ndn );
1140 op->o_req_dn.bv_val = NULL;
1141 op->o_req_ndn.bv_val = NULL;
1146 if ( op->o_req_dn.bv_val )
1147 ch_free( op->o_req_dn.bv_val );
1148 if ( op->o_req_ndn.bv_val )
1149 ch_free( op->o_req_ndn.bv_val );
1150 filter_free( op->ors_filter );
1151 ch_free( op->ors_filterstr.bv_val );
1163 Modifications* modlist,
1165 struct berval* syncUUID,
1166 struct berval* syncCookie
1169 Backend *be = op->o_bd;
1170 struct berval uuid_bv = {0, NULL};
1174 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
1177 struct berval dn = {0, NULL};
1178 struct berval pdn = {0, NULL};
1179 struct berval ndn = {0, NULL};
1180 struct berval rdn = {0, NULL};
1182 SlapReply rs = {REP_RESULT};
1183 Connection *conn = op->o_conn;
1186 op->o_tag = LDAP_REQ_ADD;
1187 op->o_callback = &cb;
1188 cb.sc_response = null_callback;
1191 ber_dupbv( &dn, &e->e_nname );
1192 ber_dupbv( &pdn, &e->e_nname );
1195 while ( !be_issuffix ( be, &pdn )) {
1196 dnParent( &dn, &pdn );
1197 dn.bv_val = pdn.bv_val;
1198 dn.bv_len = pdn.bv_len;
1203 for ( i = 0; i <= levels; i++ ) {
1204 glue = (Entry*) ch_calloc( 1, sizeof(Entry) );
1205 ber_dupbv( &dn, &e->e_nname );
1209 for ( k = 0; k < j; k++ ) {
1210 dnParent( &dn, &pdn );
1211 dn.bv_val = pdn.bv_val;
1212 dn.bv_len = pdn.bv_len;
1215 dnPrettyNormal( 0, &dn, &pdn, &ndn, op->o_tmpmemctx );
1216 ber_dupbv( &glue->e_name, &pdn );
1217 ber_dupbv( &glue->e_nname, &ndn );
1219 ch_free( pdn.bv_val );
1220 ch_free( ndn.bv_val );
1222 a = ch_calloc( 1, sizeof( Attribute ));
1223 a->a_desc = slap_schema.si_ad_objectClass;
1225 a->a_vals = ch_calloc( 3, sizeof( struct berval ));
1226 ber_str2bv( "top", strlen("top"), 1, &a->a_vals[0] );
1227 ber_str2bv( "glue", strlen("glue"), 1, &a->a_vals[1] );
1228 a->a_vals[2].bv_len = 0;
1229 a->a_vals[2].bv_val = NULL;
1231 a->a_nvals = ch_calloc( 3, sizeof( struct berval ));
1232 ber_str2bv( "top", strlen("top"), 1, &a->a_nvals[0] );
1233 ber_str2bv( "glue", strlen("glue"), 1, &a->a_nvals[1] );
1234 a->a_nvals[2].bv_len = 0;
1235 a->a_nvals[2].bv_val = NULL;
1237 a->a_next = glue->e_attrs;
1240 a = ch_calloc( 1, sizeof( Attribute ));
1241 a->a_desc = slap_schema.si_ad_structuralObjectClass;
1243 a->a_vals = ch_calloc( 2, sizeof( struct berval ));
1244 ber_str2bv( "glue", strlen("glue"), 1, &a->a_vals[0] );
1245 a->a_vals[1].bv_len = 0;
1246 a->a_vals[1].bv_val = NULL;
1248 a->a_nvals = ch_calloc( 2, sizeof( struct berval ));
1249 ber_str2bv( "glue", strlen("glue"), 1, &a->a_nvals[0] );
1250 a->a_nvals[1].bv_len = 0;
1251 a->a_nvals[1].bv_val = NULL;
1253 a->a_next = glue->e_attrs;
1256 if ( !strcmp( e->e_nname.bv_val, glue->e_nname.bv_val )) {
1257 op->o_req_dn = e->e_name;
1258 op->o_req_ndn = e->e_nname;
1260 rc = be->be_add ( op, &rs );
1261 if ( rc == LDAP_SUCCESS )
1262 be_entry_release_w( op, e );
1267 op->o_req_dn = glue->e_name;
1268 op->o_req_ndn = glue->e_nname;
1270 rc = be->be_add ( op, &rs );
1271 if ( rc == LDAP_SUCCESS ) {
1272 be_entry_release_w( op, glue );
1274 /* incl. ALREADY EXIST */
1284 syncrepl_updateCookie(
1289 struct berval *syncCookie
1292 Backend *be = op->o_bd;
1294 Modifications *mlnext;
1296 Modifications *modlist;
1297 Modifications **modtail = &modlist;
1299 struct berval* ocbva = NULL;
1300 struct berval* cnbva = NULL;
1301 struct berval* ssbva = NULL;
1302 struct berval* scbva = NULL;
1307 char txtbuf[SLAP_TEXT_BUFLEN];
1308 size_t textlen = sizeof txtbuf;
1313 struct berval sub_bv = { 0, NULL };
1314 struct berval psubrdn = { 0, NULL };
1317 SlapReply rs = {REP_RESULT};
1319 ocbva = ( struct berval * ) ch_calloc( 4, sizeof( struct berval ));
1320 cnbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval ));
1321 ssbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval ));
1322 scbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval ));
1324 /* update in memory cookie */
1325 if ( si->syncCookie != NULL ) {
1326 ber_bvfree( si->syncCookie );
1328 si->syncCookie = ber_dupbv( NULL, syncCookie );
1329 ber_str2bv( "top", strlen("top"), 1, &ocbva[0] );
1330 ber_str2bv( "subentry", strlen("subentry"), 1, &ocbva[1] );
1331 ber_str2bv( "syncConsumerSubentry",
1332 strlen("syncConsumerSubentry"), 1, &ocbva[2] );
1333 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1334 mod->sml_op = LDAP_MOD_REPLACE;
1335 ber_str2bv( "objectClass", strlen("objectClass"), 1, &mod->sml_type );
1336 mod->sml_bvalues = ocbva;
1338 modtail = &mod->sml_next;
1340 sprintf( substr, "syncrepl%d", si->id );
1341 sprintf( rdnstr, "cn=%s", substr );
1342 ber_str2bv( substr, strlen( substr ), 1, &cnbva[0] );
1343 ber_str2bv( rdnstr, strlen( rdnstr ), 1, &psubrdn );
1344 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1345 mod->sml_op = LDAP_MOD_REPLACE;
1346 ber_str2bv( "cn", strlen("cn"), 1, &mod->sml_type );
1347 mod->sml_bvalues = cnbva;
1349 modtail = &mod->sml_next;
1351 ber_dupbv( &scbva[0], si->syncCookie );
1352 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1353 mod->sml_op = LDAP_MOD_REPLACE;
1354 ber_str2bv( "syncreplCookie", strlen("syncreplCookie"),
1355 1, &mod->sml_type );
1356 mod->sml_bvalues = scbva;
1358 modtail = &mod->sml_next;
1360 ber_str2bv( "{}", strlen("{}"), 1, &ssbva[0] );
1361 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1362 mod->sml_op = LDAP_MOD_REPLACE;
1363 ber_str2bv( "subtreeSpecification",
1364 strlen("subtreeSpecification"), 1, &mod->sml_type );
1365 mod->sml_bvalues = ssbva;
1367 modtail = &mod->sml_next;
1369 rc = slap_mods_check( modlist, 1, &text, txtbuf, textlen, NULL );
1371 if ( rc != LDAP_SUCCESS ) {
1373 LDAP_LOG( OPERATION, ERR,
1374 "syncrepl_updateCookie: mods check (%s)\n", text, 0, 0 );
1376 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods check (%s)\n",
1381 op->o_tag = LDAP_REQ_ADD;
1382 rc = slap_mods_opattrs( op, modlist, modtail,
1383 &text,txtbuf, textlen );
1385 for ( ml = modlist; ml != NULL; ml = mlnext ) {
1386 mlnext = ml->sml_next;
1387 ml->sml_op = LDAP_MOD_REPLACE;
1390 if( rc != LDAP_SUCCESS ) {
1392 LDAP_LOG( OPERATION, ERR,
1393 "syncrepl_updateCookie: mods opattrs (%s)\n", text, 0, 0 );
1395 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods opattrs (%s)\n",
1400 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
1402 build_new_dn( &sub_bv, pdn, &psubrdn );
1403 dnPrettyNormal( NULL, &sub_bv, &e->e_name, &e->e_nname, NULL );
1404 ch_free( sub_bv.bv_val );
1405 ch_free( psubrdn.bv_val );
1409 rc = slap_mods2entry( modlist, &e, 1, 1, &text, txtbuf, textlen );
1411 if( rc != LDAP_SUCCESS ) {
1413 LDAP_LOG( OPERATION, ERR,
1414 "syncrepl_updateCookie: mods2entry (%s)\n", text, 0, 0 );
1416 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods2entry (%s)\n",
1421 cb.sc_response = null_callback;
1424 op->o_callback = &cb;
1425 op->o_req_dn = e->e_name;
1426 op->o_req_ndn = e->e_nname;
1428 /* update persistent cookie */
1429 update_cookie_retry:
1430 op->o_tag = LDAP_REQ_MODIFY;
1431 op->orm_modlist = modlist;
1432 rc = be->be_modify( op, &rs );
1434 if ( rc != LDAP_SUCCESS ) {
1435 if ( rc == LDAP_REFERRAL ||
1436 rc == LDAP_NO_SUCH_OBJECT ) {
1437 op->o_tag = LDAP_REQ_ADD;
1439 rc = be->be_add( op, &rs );
1440 if ( rc != LDAP_SUCCESS ) {
1441 if ( rc == LDAP_ALREADY_EXISTS ) {
1442 goto update_cookie_retry;
1443 } else if ( rc == LDAP_REFERRAL ||
1444 rc == LDAP_NO_SUCH_OBJECT ) {
1446 LDAP_LOG( OPERATION, ERR,
1447 "cookie will be non-persistent\n",
1450 Debug( LDAP_DEBUG_ANY,
1451 "cookie will be non-persistent\n",
1456 LDAP_LOG( OPERATION, ERR,
1457 "be_add failed (%d)\n",
1460 Debug( LDAP_DEBUG_ANY,
1461 "be_add failed (%d)\n",
1466 be_entry_release_w( op, e );
1471 LDAP_LOG( OPERATION, ERR,
1472 "be_modify failed (%d)\n", rc, 0, 0 );
1474 Debug( LDAP_DEBUG_ANY,
1475 "be_modify failed (%d)\n", rc, 0, 0 );
1485 for ( ml = modlist; ml != NULL; ml = mlnext ) {
1486 mlnext = ml->sml_next;
1494 avl_ber_bvfree( void *bv )
1499 if ( ((struct berval *)bv)->bv_val != NULL ) {
1500 ber_memfree ( ((struct berval *)bv)->bv_val );
1502 ber_memfree ( (char *) bv );
1511 syncinfo_t *si = op->o_callback->sc_private;
1514 if ( rs->sr_type != REP_SEARCH ) return LDAP_SUCCESS;
1516 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_syncreplCookie );
1519 si->syncCookie = NULL;
1521 si->syncCookie = ber_dupbv( NULL, &a->a_vals[0] );
1523 return LDAP_SUCCESS;
1532 syncinfo_t *si = op->o_callback->sc_private;
1534 if ( rs->sr_type == REP_SEARCH ) {
1535 if ( si->syncUUID_ndn != NULL ) {
1537 LDAP_LOG( OPERATION, ERR,
1538 "dn_callback : multiple entries match dn\n", 0, 0, 0 );
1540 Debug( LDAP_DEBUG_ANY,
1541 "dn_callback : multiple entries match dn\n", 0, 0, 0 );
1544 if ( rs->sr_entry == NULL ) {
1545 si->syncUUID_ndn = NULL;
1547 si->syncUUID_ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname );
1552 return LDAP_SUCCESS;
1556 nonpresent_callback(
1561 syncinfo_t *si = op->o_callback->sc_private;
1564 struct berval* present_uuid = NULL;
1566 SlapReply rs_cb = {REP_RESULT};
1567 struct nonpresent_entry *np_entry;
1569 if ( rs->sr_type == REP_RESULT ) {
1570 count = avl_free( si->presentlist, avl_ber_bvfree );
1571 si->presentlist = NULL;
1572 return LDAP_SUCCESS;
1573 } else if ( rs->sr_type == REP_SEARCH ) {
1574 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID );
1579 present_uuid = avl_find( si->presentlist, &a->a_vals[0], syncuuid_cmp );
1581 if ( present_uuid == NULL ) {
1582 np_entry = (struct nonpresent_entry *)
1583 ch_calloc( 1, sizeof( struct nonpresent_entry ));
1584 np_entry->dn = ber_dupbv( NULL, &rs->sr_entry->e_name );
1585 np_entry->ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname );
1586 LDAP_LIST_INSERT_HEAD( &si->nonpresentlist, np_entry, np_link );
1588 avl_delete( &si->presentlist,
1589 &a->a_vals[0], syncuuid_cmp );
1591 return LDAP_SUCCESS;
1593 return LDAP_SUCCESS;
1604 syncinfo_t *si = op->o_callback->sc_private;
1606 if ( rs->sr_err != LDAP_SUCCESS &&
1607 rs->sr_err != LDAP_REFERRAL &&
1608 rs->sr_err != LDAP_ALREADY_EXISTS &&
1609 rs->sr_err != LDAP_NO_SUCH_OBJECT ) {
1611 LDAP_LOG( OPERATION, ERR,
1612 "null_callback : error code 0x%x\n",
1615 Debug( LDAP_DEBUG_ANY,
1616 "null_callback : error code 0x%x\n",
1620 return LDAP_SUCCESS;
1625 str2clist( char ***out, char *in, const char *brkstr )
1634 /* find last element in list */
1635 for (i = 0; *out && *out[i]; i++);
1637 /* protect the input string from strtok */
1638 str = ch_strdup( in );
1640 if ( *str == '\0' ) {
1645 /* Count words in string */
1647 for ( s = str; *s; s++ ) {
1648 if ( strchr( brkstr, *s ) != NULL ) {
1653 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
1655 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
1657 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
1659 *new = ch_strdup( s );