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"
38 const struct berval slap_syncrepl_bvc = BER_BVC("syncreplxxx");
39 const struct berval slap_syncrepl_cn_bvc = BER_BVC("cn=syncreplxxx");
42 syncrepl_del_nonpresent( LDAP *, Operation * );
44 /* callback functions */
45 static int cookie_callback( struct slap_op *, struct slap_rep * );
46 static int dn_callback( struct slap_op *, struct slap_rep * );
47 static int nonpresent_callback( struct slap_op *, struct slap_rep * );
48 static int null_callback( struct slap_op *, struct slap_rep * );
49 static int contextcsn_callback( Operation*, SlapReply* );
51 static AttributeDescription **sync_descs;
53 struct runqueue_s syncrepl_rq;
58 sync_descs = ch_malloc( 4 * sizeof( AttributeDescription * ));
59 sync_descs[0] = slap_schema.si_ad_objectClass;
60 sync_descs[1] = slap_schema.si_ad_structuralObjectClass;
61 sync_descs[2] = slap_schema.si_ad_entryCSN;
78 BerElement *sync_ber = NULL;
79 struct berval *sync_bvalp = NULL;
83 struct timeval timeout;
85 /* setup LDAP SYNC control */
86 sync_ber = ber_alloc_t( LBER_USE_DER );
87 ber_set_option( sync_ber, LBER_OPT_BER_MEMCTX, NULL );
89 if ( si->syncCookie ) {
90 ber_printf( sync_ber, "{eO}", abs(si->type), si->syncCookie );
92 ber_printf( sync_ber, "{e}", abs(si->type) );
95 if ( ber_flatten( sync_ber, &sync_bvalp ) == LBER_ERROR ) {
96 ber_free( sync_ber, 1 );
99 ber_free( sync_ber, 1 );
101 ctrls = (LDAPControl**) sl_calloc( 3, sizeof(LDAPControl*), NULL );
103 c[0].ldctl_oid = LDAP_CONTROL_SYNC;
104 c[0].ldctl_value = (*sync_bvalp);
105 c[0].ldctl_iscritical = si->type < 0;
109 c[1].ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
110 c[1].ldctl_value.bv_val = si->authzId;
111 c[1].ldctl_value.bv_len = strlen( si->authzId );
112 c[1].ldctl_iscritical = 1;
120 err = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, ctrls );
122 ber_bvfree( sync_bvalp );
125 if ( err != LDAP_OPT_SUCCESS )
126 fprintf( stderr, "Could not set controls : %d\n", err );
128 timeout.tv_sec = si->tlimit > 0 ? si->tlimit : 1;
130 rc = ldap_search_ext( ld, si->base, si->scope, si->filterstr,
131 si->attrs, si->attrsonly, sctrls, cctrls,
132 si->tlimit < 0 ? NULL : &timeout,
133 si->slimit, msgidp );
143 struct re_s* rtask = arg;
144 syncinfo_t *si = ( syncinfo_t * ) rtask->arg;
145 Backend *be = si->be;
147 SlapReply rs = {REP_RESULT};
150 LDAPControl **sctrls = NULL;
151 LDAPControl **rctrls = NULL;
152 LDAPControl *rctrlp = NULL;
153 BerElement *sync_ber = NULL;
154 struct berval *sync_bvalp = NULL;
156 BerElement *ctrl_ber = NULL;
157 BerElement *res_ber = NULL;
160 LDAPMessage *res = NULL;
161 LDAPMessage *msg = NULL;
165 int nresponses, nreferences, nextended, npartial;
166 int nresponses_psearch;
168 int cancel_msgid = -1;
170 struct berval *retdata = NULL;
172 int sync_info_arrived = 0;
176 struct berval syncUUID = { 0, NULL };
177 struct berval syncCookie = { 0, NULL };
178 struct berval syncCookie_req = { 0, NULL };
183 int syncinfo_arrived = 0;
186 AttributeDescription** descs = NULL;
198 struct berval base_bv = { 0, NULL };
199 struct berval pbase = { 0, NULL };
200 struct berval nbase = { 0, NULL };
201 struct berval sub_bv = { 0, NULL };
202 struct berval psubrdn = { 0, NULL };
203 struct berval nsubrdn = { 0, NULL };
204 struct berval psub = { 0, NULL };
205 struct berval nsub = { 0, NULL };
207 Modifications *modlist = NULL;
208 Modifications *ml, *mlnext;
209 char *def_filter_str = NULL;
214 struct timeval *tout_p = NULL;
215 struct timeval tout = { 10, 0 };
218 LDAP_LOG ( OPERATION, DETAIL1, "do_syncrepl\n", 0, 0, 0 );
220 Debug( LDAP_DEBUG_TRACE, "=>do_syncrepl\n", 0, 0, 0 );
226 if ( abs(si->type) != LDAP_SYNC_REFRESH_ONLY &&
227 abs(si->type) != LDAP_SYNC_REFRESH_AND_PERSIST ) {
231 si->sync_mode = LDAP_SYNC_STATE_MODE;
233 /* Init connection to master */
235 rc = ldap_initialize( &ld, si->provideruri );
236 if ( rc != LDAP_SUCCESS ) {
238 LDAP_LOG( OPERATION, ERR, "do_syncrepl: "
239 "ldap_initialize failed (%s)\n",
240 si->provideruri, 0, 0 );
242 Debug( LDAP_DEBUG_ANY, "do_syncrepl: "
243 "ldap_initialize failed (%s)\n",
244 si->provideruri, 0, 0 );
248 op.o_protocol = LDAP_VERSION3;
249 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &op.o_protocol );
254 rc = ldap_start_tls_s( ld, NULL, NULL );
255 if( rc != LDAP_SUCCESS ) {
257 LDAP_LOG ( OPERATION, ERR, "do_syncrepl: "
258 "%s: ldap_start_tls failed (%d)\n",
259 si->tls == TLS_CRITICAL ? "Error" : "Warning",
262 Debug( LDAP_DEBUG_ANY,
263 "%s: ldap_start_tls failed (%d)\n",
264 si->tls == TLS_CRITICAL ? "Error" : "Warning",
267 if( si->tls == TLS_CRITICAL )
272 if ( si->bindmethod == LDAP_AUTH_SASL ) {
273 #ifdef HAVE_CYRUS_SASL
276 if ( si->secprops != NULL ) {
277 int err = ldap_set_option( ld,
278 LDAP_OPT_X_SASL_SECPROPS, si->secprops);
280 if( err != LDAP_OPT_SUCCESS ) {
282 LDAP_LOG ( OPERATION, ERR, "do_bind: Error: "
283 "ldap_set_option(%s,SECPROPS,\"%s\") failed!\n",
284 si->provideruri, si->secprops, 0 );
286 Debug( LDAP_DEBUG_ANY, "Error: ldap_set_option "
287 "(%s,SECPROPS,\"%s\") failed!\n",
288 si->provideruri, si->secprops, NULL );
294 defaults = lutil_sasl_defaults( ld,
301 rc = ldap_sasl_interactive_bind_s( ld,
309 /* FIXME : different error behaviors according to
311 2) on err policy : exit, retry, backoff ...
313 if ( rc != LDAP_SUCCESS ) {
315 LDAP_LOG ( OPERATION, ERR, "do_syncrepl: "
316 "ldap_sasl_interactive_bind_s failed (%d)\n",
319 Debug( LDAP_DEBUG_ANY, "do_syncrepl: "
320 "ldap_sasl_interactive_bind_s failed (%d)\n",
325 #else /* HAVE_CYRUS_SASL */
326 fprintf( stderr, "not compiled with SASL support\n" );
330 rc = ldap_bind_s( ld, si->binddn, si->passwd, si->bindmethod );
331 if ( rc != LDAP_SUCCESS ) {
333 LDAP_LOG ( OPERATION, ERR, "do_syncrepl: "
334 "ldap_bind_s failed (%d)\n", rc, 0, 0 );
336 Debug( LDAP_DEBUG_ANY, "do_syncrepl: "
337 "ldap_bind_s failed (%d)\n", rc, 0, 0 );
343 /* set thread context in syncinfo */
346 /* set memory context */
347 #define SLAB_SIZE 1048576
349 memctx = sl_mem_create( memsiz, ctx );
350 op.o_tmpmemctx = memctx;
351 op.o_tmpmfuncs = &sl_mfuncs;
354 op.o_tag = LDAP_REQ_SEARCH;
355 op.o_dn = si->updatedn;
356 op.o_ndn = si->updatedn;
358 op.o_time = slap_get_time();
359 op.o_managedsait = 1;
360 op.o_threadctx = si->ctx;
363 op.o_connid = op.o_conn->c_connid;
364 op.ors_scope = LDAP_SCOPE_BASE;
365 op.ors_deref = LDAP_DEREF_NEVER;
368 op.ors_attrsonly = 0;
370 op.ors_filter = str2filter_x( &op, def_filter_str = "(objectClass=*)" );
371 ber_str2bv( def_filter_str, 0, 0, &op.ors_filterstr );
374 conn.c_send_ldap_result = slap_send_ldap_result;
375 conn.c_send_search_entry = slap_send_search_entry;
376 conn.c_send_search_reference = slap_send_search_reference;
378 /* get syncrepl cookie of shadow replica from subentry */
379 ber_str2bv( si->base, 0, 0, &base_bv );
380 dnPrettyNormal( 0, &base_bv, &pbase, &nbase, op.o_tmpmemctx );
382 sprintf( substr, "cn=syncrepl%d", si->id );
383 ber_str2bv( substr, 0, 0, &sub_bv );
384 dnPrettyNormal( 0, &sub_bv, &psubrdn, &nsubrdn, op.o_tmpmemctx );
386 build_new_dn( &op.o_req_dn, &pbase, &psubrdn, op.o_tmpmemctx );
387 build_new_dn( &op.o_req_ndn, &nbase, &nsubrdn, op.o_tmpmemctx );
389 /* set callback function */
390 cb.sc_response = cookie_callback;
393 /* search subentry to retrieve cookie */
394 si->syncCookie = NULL;
395 be->be_search( &op, &rs );
397 ber_dupbv( &syncCookie_req, si->syncCookie );
399 psub = be->be_nsuffix[0];
401 for ( n = 0; si->attrs[ n ] != NULL; n++ ) ;
404 /* Delete Attributes */
406 for ( i = 0; descs[i] != NULL; i++ ) {
407 for ( j = 0; si->attrs[j] != NULL; j++ ) {
408 if ( !strcmp( si->attrs[j], descs[i]->ad_cname.bv_val )) {
409 ch_free( si->attrs[j] );
410 for ( k = j; si->attrs[k] != NULL; k++ ) {
411 si->attrs[k] = si->attrs[k+1];
416 for ( n = 0; si->attrs[ n ] != NULL; n++ );
417 tmp = ( char ** ) ch_realloc( si->attrs, ( n + 4 ) * sizeof( char * ));
420 LDAP_LOG( OPERATION, ERR, "out of memory\n", 0,0,0 );
422 Debug( LDAP_DEBUG_ANY, "out of memory\n", 0,0,0 );
426 tmp = ( char ** ) ch_realloc( si->attrs, 5 * sizeof( char * ));
429 LDAP_LOG( OPERATION, ERR, "out of memory\n", 0,0,0 );
431 Debug( LDAP_DEBUG_ANY, "out of memory\n", 0,0,0 );
434 tmp[ n++ ] = ch_strdup( "*" );
442 for ( i = 0; descs[ i ] != NULL; i++ ) {
443 si->attrs[ n++ ] = ch_strdup ( descs[i]->ad_cname.bv_val );
444 si->attrs[ n ] = NULL;
447 rc = ldap_sync_search( si, ld, NULL, NULL, &msgid );
448 if( rc != LDAP_SUCCESS ) {
449 fprintf( stderr, "syncrepl: ldap_search_ext: %s (%d)\n",
450 ldap_err2string( rc ), rc );
454 if ( abs(si->type) == LDAP_SYNC_REFRESH_AND_PERSIST ){
460 while (( rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ONE, tout_p, &res )) >= 0 ) {
463 if ( slapd_abrupt_shutdown ) {
470 for ( msg = ldap_first_message( ld, res );
472 msg = ldap_next_message( ld, msg ) )
474 syncCookie.bv_len = 0; syncCookie.bv_val = NULL;
475 switch( ldap_msgtype( msg ) ) {
476 case LDAP_RES_SEARCH_ENTRY:
477 entry = syncrepl_message_to_entry( si, ld, &op, msg,
478 &modlist, &syncstate, &syncUUID, &syncCookie );
479 rc_efree = syncrepl_entry( si, ld, &op, entry, modlist,
480 syncstate, &syncUUID, &syncCookie, !syncinfo_arrived );
481 if ( syncCookie.bv_len ) {
482 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie );
485 slap_mods_free( modlist );
492 case LDAP_RES_SEARCH_REFERENCE:
494 LDAP_LOG( OPERATION, ERR,
495 "do_syncrepl : reference received\n", 0, 0, 0 );
497 Debug( LDAP_DEBUG_ANY,
498 "do_syncrepl : reference received\n", 0, 0, 0 );
502 case LDAP_RES_SEARCH_RESULT:
503 ldap_parse_result( ld, msg, &err, NULL, NULL, NULL, &rctrls, 0 );
506 ctrl_ber = ber_alloc_t( LBER_USE_DER );
507 ber_set_option( ctrl_ber, LBER_OPT_BER_MEMCTX, &op.o_tmpmemctx );
508 ber_write( ctrl_ber, rctrlp->ldctl_value.bv_val, rctrlp->ldctl_value.bv_len, 0 );
509 ber_reset( ctrl_ber, 1 );
511 ber_scanf( ctrl_ber, "{" /*"}"*/);
512 if ( ber_peek_tag( ctrl_ber, &len )
513 == LDAP_SYNC_TAG_COOKIE ) {
514 ber_scanf( ctrl_ber, "o", &syncCookie );
517 value_match( &match, slap_schema.si_ad_entryCSN,
518 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
519 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
520 &syncCookie_req, &syncCookie, &text );
521 if (si->type == LDAP_SYNC_REFRESH_AND_PERSIST) {
522 /* FIXME : different error behaviors according to
523 1) err code : LDAP_BUSY ...
524 2) on err policy : stop service, stop sync, retry
526 if ( syncCookie.bv_len && match < 0) {
527 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie );
530 ber_free( ctrl_ber, 1 );
533 /* FIXME : different error behaviors according to
534 1) err code : LDAP_BUSY ...
535 2) on err policy : stop service, stop sync, retry
537 if ( syncCookie.bv_len && match < 0 ) {
538 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie);
540 if ( si->sync_mode == LDAP_SYNC_STATE_MODE && match < 0 ) {
541 syncrepl_del_nonpresent( ld, &op );
544 ber_free( ctrl_ber, 1 );
549 case LDAP_RES_INTERMEDIATE:
550 rc = ldap_parse_intermediate( ld, msg,
551 &retoid, &retdata, NULL, 0 );
552 if ( !rc && !strcmp( retoid, LDAP_SYNC_INFO ) ) {
553 sync_info_arrived = 1;
554 res_ber = ber_init( retdata );
555 ber_scanf( res_ber, "{e" /*"}"*/, &syncstate );
557 if ( ber_peek_tag( res_ber, &len )
558 == LDAP_SYNC_TAG_COOKIE ) {
559 ber_scanf( res_ber, /*"{"*/ "o}", &syncCookie );
561 if ( syncstate == LDAP_SYNC_NEW_COOKIE ) {
563 LDAP_LOG( OPERATION, ERR,
564 "do_syncrepl : cookie required\n", 0, 0, 0 );
566 Debug( LDAP_DEBUG_ANY,
567 "do_syncrepl : cookie required\n", 0, 0, 0 );
572 value_match( &match, slap_schema.si_ad_entryCSN,
573 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
574 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
575 &syncCookie_req, &syncCookie, &text );
577 if ( syncCookie.bv_len && match < 0 ) {
578 syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie);
581 if ( syncstate == LDAP_SYNC_STATE_MODE_DONE ) {
583 syncrepl_del_nonpresent( ld, &op );
585 si->sync_mode = LDAP_SYNC_LOG_MODE;
586 } else if ( syncstate == LDAP_SYNC_LOG_MODE_DONE ) {
587 si->sync_mode = LDAP_SYNC_PERSIST_MODE;
588 } else if ( syncstate == LDAP_SYNC_REFRESH_DONE ) {
589 si->sync_mode = LDAP_SYNC_PERSIST_MODE;
590 } else if ( syncstate != LDAP_SYNC_NEW_COOKIE ||
591 syncstate != LDAP_SYNC_LOG_MODE_DONE ) {
593 LDAP_LOG( OPERATION, ERR,
594 "do_syncrepl : unknown sync info\n", 0, 0, 0 );
596 Debug( LDAP_DEBUG_ANY,
597 "do_syncrepl : unknown sync info\n", 0, 0, 0 );
601 ldap_memfree( retoid );
602 ber_bvfree( retdata );
603 ber_free( res_ber, 1 );
607 LDAP_LOG( OPERATION, ERR,"do_syncrepl :"
608 " unknown intermediate "
609 "response\n", 0, 0, 0 );
611 Debug( LDAP_DEBUG_ANY, "do_syncrepl : "
612 "unknown intermediate response (%d)\n",
615 ldap_memfree( retoid );
616 ber_bvfree( retdata );
622 LDAP_LOG( OPERATION, ERR, "do_syncrepl : "
623 "unknown message\n", 0, 0, 0 );
625 Debug( LDAP_DEBUG_ANY, "do_syncrepl : "
626 "unknown message\n", 0, 0, 0 );
631 if ( syncCookie.bv_val )
632 ch_free( syncCookie.bv_val );
633 if ( syncUUID.bv_val )
634 ch_free( syncUUID.bv_val );
643 ldap_get_option( ld, LDAP_OPT_ERROR_NUMBER, &errno );
644 errstr = ldap_err2string( errno );
647 LDAP_LOG( OPERATION, ERR,
648 "do_syncrepl : %s\n", errstr, 0, 0 );
650 Debug( LDAP_DEBUG_ANY,
651 "do_syncrepl : %s\n", errstr, 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 );
817 ldap_controls_free( rctrls );
820 LDAP_LOG( OPERATION, ERR,"syncrepl_message_to_entry : "
821 " rctrls absent\n", 0, 0, 0 );
823 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry :"
824 " rctrls absent\n", 0, 0, 0 );
828 if ( *syncstate == LDAP_SYNC_PRESENT || *syncstate == LDAP_SYNC_DELETE ) {
832 if ( *modlist == NULL ) {
834 LDAP_LOG( OPERATION, ERR,
835 "syncrepl_message_to_entry: no attributes\n", 0, 0, 0 );
837 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: no attributes\n",
843 while ( ml != NULL ) {
844 AttributeDescription *ad = NULL;
845 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, &text );
847 if( rc != LDAP_SUCCESS ) {
857 rc = slap_mods_check( *modlist, 1, &text, txtbuf, textlen, NULL );
859 if ( rc != LDAP_SUCCESS ) {
861 LDAP_LOG( OPERATION, ERR,
862 "syncrepl_message_to_entry: mods check (%s)\n", text, 0, 0 );
864 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods check (%s)\n",
870 rc = slap_mods2entry( *modlist, &e, 1, 1, &text, txtbuf, textlen);
871 if( rc != LDAP_SUCCESS ) {
873 LDAP_LOG( OPERATION, ERR,
874 "syncrepl_message_to_entry: mods2entry (%s)\n", text, 0, 0 );
876 Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods2entry (%s)\n",
889 syncuuid_cmp( const void* v_uuid1, const void* v_uuid2 )
891 const struct berval *uuid1 = v_uuid1;
892 const struct berval *uuid2 = v_uuid2;
893 int rc = uuid1->bv_len - uuid2->bv_len;
895 return ( strcmp( uuid1->bv_val, uuid2->bv_val ) );
904 Modifications* modlist,
906 struct berval* syncUUID,
907 struct berval* syncCookie,
911 Backend *be = op->o_bd;
913 struct berval csn_bv = {0, NULL};
914 struct berval *syncuuid_bv = NULL;
915 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
917 SlapReply rs = {REP_RESULT};
918 int rc = LDAP_SUCCESS;
920 struct berval base_bv = {0, NULL};
928 ( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD )) {
929 syncuuid_bv = ber_dupbv( NULL, syncUUID );
930 avl_insert( &si->presentlist, (caddr_t) syncuuid_bv,
931 syncuuid_cmp, avl_dup_error );
934 if ( syncstate == LDAP_SYNC_PRESENT ) {
942 filterstr = (char *) sl_malloc( strlen("entryUUID=") + syncUUID->bv_len + 1,
944 strcpy( filterstr, "entryUUID=" );
945 strcat( filterstr, syncUUID->bv_val );
948 si->syncUUID_ndn = NULL;
950 filter = str2filter( filterstr );
951 ber_str2bv( filterstr, strlen(filterstr), 1, &op->ors_filterstr );
952 ch_free( filterstr );
953 op->ors_filter = filter;
954 op->ors_scope = LDAP_SCOPE_SUBTREE;
956 /* get syncrepl cookie of shadow replica from subentry */
957 ber_str2bv( si->base, strlen(si->base), 1, &base_bv );
958 dnPrettyNormal( 0, &base_bv, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
959 ch_free( base_bv.bv_val );
961 /* set callback function */
962 op->o_callback = &cb;
963 cb.sc_response = dn_callback;
966 si->syncUUID_ndn = NULL;
968 rc = be->be_search( op, &rs );
970 ch_free( op->o_req_dn.bv_val );
971 ch_free( op->o_req_ndn.bv_val );
972 filter_free( op->ors_filter );
973 ch_free( op->ors_filterstr.bv_val );
975 cb.sc_response = null_callback;
978 if ( rc == LDAP_SUCCESS && si->syncUUID_ndn && si->sync_mode != LDAP_SYNC_LOG_MODE ) {
979 op->o_req_dn = *si->syncUUID_ndn;
980 op->o_req_ndn = *si->syncUUID_ndn;
981 op->o_tag = LDAP_REQ_DELETE;
982 rc = be->be_delete( op, &rs );
985 if ( si->syncUUID_ndn ) {
986 ber_bvfree( si->syncUUID_ndn );
989 switch ( syncstate ) {
991 case LDAP_SYNC_MODIFY :
993 if ( rc == LDAP_SUCCESS ||
994 rc == LDAP_REFERRAL ||
995 rc == LDAP_NO_SUCH_OBJECT ) {
997 attr_delete( &e->e_attrs, slap_schema.si_ad_entryUUID );
998 attr_merge_normalize_one( e, slap_schema.si_ad_entryUUID, syncUUID, op->o_tmpmemctx );
1000 op->o_tag = LDAP_REQ_ADD;
1002 op->o_req_dn = e->e_name;
1003 op->o_req_ndn = e->e_nname;
1004 rc = be->be_add( op, &rs );
1006 if ( rc != LDAP_SUCCESS ) {
1007 if ( rc == LDAP_ALREADY_EXISTS ) {
1008 op->o_tag = LDAP_REQ_MODIFY;
1009 op->orm_modlist = modlist;
1010 op->o_req_dn = e->e_name;
1011 op->o_req_ndn = e->e_nname;
1012 rc = be->be_modify( op, &rs );
1014 if ( rc != LDAP_SUCCESS ) {
1016 LDAP_LOG( OPERATION, ERR,
1017 "syncrepl_entry : be_modify failed (%d)\n",
1020 Debug( LDAP_DEBUG_ANY,
1021 "syncrepl_entry : be_modify failed (%d)\n",
1026 } else if ( rc == LDAP_REFERRAL ||
1027 rc == LDAP_NO_SUCH_OBJECT ) {
1028 syncrepl_add_glue( si, ld, op, e,
1030 syncUUID, syncCookie);
1035 LDAP_LOG( OPERATION, ERR,
1036 "syncrepl_entry : be_add failed (%d)\n",
1039 Debug( LDAP_DEBUG_ANY,
1040 "syncrepl_entry : be_add failed (%d)\n",
1048 be_entry_release_w( op, e );
1053 LDAP_LOG( OPERATION, ERR,
1054 "syncrepl_entry : be_search failed (%d)\n", rc, 0, 0 );
1056 Debug( LDAP_DEBUG_ANY,
1057 "syncrepl_entry : be_search failed (%d)\n", rc, 0, 0 );
1063 case LDAP_SYNC_DELETE :
1064 if ( si->sync_mode == LDAP_SYNC_LOG_MODE ) {
1065 op->o_req_dn = *si->syncUUID_ndn;
1066 op->o_req_ndn = *si->syncUUID_ndn;
1067 op->o_tag = LDAP_REQ_DELETE;
1068 rc = be->be_delete( op, &rs );
1070 /* Already deleted otherwise */
1075 LDAP_LOG( OPERATION, ERR,
1076 "syncrepl_entry : unknown syncstate\n", 0, 0, 0 );
1078 Debug( LDAP_DEBUG_ANY,
1079 "syncrepl_entry : unknown syncstate\n", 0, 0, 0 );
1086 syncrepl_del_nonpresent(
1091 Backend* be = op->o_bd;
1092 syncinfo_t *si = op->o_si;
1094 struct berval base_bv = {0, NULL};
1096 SlapReply rs = {REP_RESULT};
1097 struct berval filterstr_bv = {0, NULL};
1098 struct nonpresent_entry *np_list, *np_prev;
1100 ber_str2bv( si->base, strlen(si->base), 1, &base_bv );
1101 dnPrettyNormal(0, &base_bv, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
1102 ch_free( base_bv.bv_val );
1104 filter = str2filter( si->filterstr );
1106 cb.sc_response = nonpresent_callback;
1109 op->o_callback = &cb;
1110 op->o_tag = LDAP_REQ_SEARCH;
1111 op->ors_scope = si->scope;
1112 op->ors_deref = LDAP_DEREF_NEVER;
1115 op->ors_attrsonly = 0;
1116 op->ors_attrs = NULL;
1117 op->ors_filter = filter;
1118 ber_str2bv( si->filterstr, strlen( si->filterstr ), 1, &op->ors_filterstr );
1120 op->o_nocaching = 1;
1121 be->be_search( op, &rs );
1122 op->o_nocaching = 0;
1124 if ( !LDAP_LIST_EMPTY( &si->nonpresentlist ) ) {
1125 np_list = LDAP_LIST_FIRST( &si->nonpresentlist );
1126 while ( np_list != NULL ) {
1127 LDAP_LIST_REMOVE( np_list, np_link );
1129 np_list = LDAP_LIST_NEXT( np_list, np_link );
1130 op->o_tag = LDAP_REQ_DELETE;
1131 op->o_callback = &cb;
1132 cb.sc_response = null_callback;
1134 op->o_req_dn = *np_prev->dn;
1135 op->o_req_ndn = *np_prev->ndn;
1136 op->o_bd->be_delete( op, &rs );
1137 ber_bvfree( np_prev->dn );
1138 ber_bvfree( np_prev->ndn );
1139 op->o_req_dn.bv_val = NULL;
1140 op->o_req_ndn.bv_val = NULL;
1145 if ( op->o_req_dn.bv_val )
1146 ch_free( op->o_req_dn.bv_val );
1147 if ( op->o_req_ndn.bv_val )
1148 ch_free( op->o_req_ndn.bv_val );
1149 filter_free( op->ors_filter );
1150 ch_free( op->ors_filterstr.bv_val );
1162 Modifications* modlist,
1164 struct berval* syncUUID,
1165 struct berval* syncCookie
1168 Backend *be = op->o_bd;
1169 struct berval uuid_bv = {0, NULL};
1173 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
1176 struct berval dn = {0, NULL};
1177 struct berval pdn = {0, NULL};
1178 struct berval ndn = {0, NULL};
1179 struct berval rdn = {0, NULL};
1181 SlapReply rs = {REP_RESULT};
1182 Connection *conn = op->o_conn;
1185 op->o_tag = LDAP_REQ_ADD;
1186 op->o_callback = &cb;
1187 cb.sc_response = null_callback;
1190 ber_dupbv( &dn, &e->e_nname );
1191 ber_dupbv( &pdn, &e->e_nname );
1194 while ( !be_issuffix ( be, &pdn )) {
1195 dnParent( &dn, &pdn );
1196 dn.bv_val = pdn.bv_val;
1197 dn.bv_len = pdn.bv_len;
1202 for ( i = 0; i <= levels; i++ ) {
1203 glue = (Entry*) ch_calloc( 1, sizeof(Entry) );
1204 ber_dupbv( &dn, &e->e_nname );
1208 for ( k = 0; k < j; k++ ) {
1209 dnParent( &dn, &pdn );
1210 dn.bv_val = pdn.bv_val;
1211 dn.bv_len = pdn.bv_len;
1214 dnPrettyNormal( 0, &dn, &pdn, &ndn, op->o_tmpmemctx );
1215 ber_dupbv( &glue->e_name, &pdn );
1216 ber_dupbv( &glue->e_nname, &ndn );
1218 ch_free( pdn.bv_val );
1219 ch_free( ndn.bv_val );
1221 a = ch_calloc( 1, sizeof( Attribute ));
1222 a->a_desc = slap_schema.si_ad_objectClass;
1224 a->a_vals = ch_calloc( 3, sizeof( struct berval ));
1225 ber_str2bv( "top", strlen("top"), 1, &a->a_vals[0] );
1226 ber_str2bv( "glue", strlen("glue"), 1, &a->a_vals[1] );
1227 a->a_vals[2].bv_len = 0;
1228 a->a_vals[2].bv_val = NULL;
1230 a->a_nvals = ch_calloc( 3, sizeof( struct berval ));
1231 ber_str2bv( "top", strlen("top"), 1, &a->a_nvals[0] );
1232 ber_str2bv( "glue", strlen("glue"), 1, &a->a_nvals[1] );
1233 a->a_nvals[2].bv_len = 0;
1234 a->a_nvals[2].bv_val = NULL;
1236 a->a_next = glue->e_attrs;
1239 a = ch_calloc( 1, sizeof( Attribute ));
1240 a->a_desc = slap_schema.si_ad_structuralObjectClass;
1242 a->a_vals = ch_calloc( 2, sizeof( struct berval ));
1243 ber_str2bv( "glue", strlen("glue"), 1, &a->a_vals[0] );
1244 a->a_vals[1].bv_len = 0;
1245 a->a_vals[1].bv_val = NULL;
1247 a->a_nvals = ch_calloc( 2, sizeof( struct berval ));
1248 ber_str2bv( "glue", strlen("glue"), 1, &a->a_nvals[0] );
1249 a->a_nvals[1].bv_len = 0;
1250 a->a_nvals[1].bv_val = NULL;
1252 a->a_next = glue->e_attrs;
1255 if ( !strcmp( e->e_nname.bv_val, glue->e_nname.bv_val )) {
1256 op->o_req_dn = e->e_name;
1257 op->o_req_ndn = e->e_nname;
1259 rc = be->be_add ( op, &rs );
1260 if ( rc == LDAP_SUCCESS )
1261 be_entry_release_w( op, e );
1266 op->o_req_dn = glue->e_name;
1267 op->o_req_ndn = glue->e_nname;
1269 rc = be->be_add ( op, &rs );
1270 if ( rc == LDAP_SUCCESS ) {
1271 be_entry_release_w( op, glue );
1273 /* incl. ALREADY EXIST */
1283 syncrepl_updateCookie(
1288 struct berval *syncCookie
1291 Backend *be = op->o_bd;
1293 Modifications *mlnext;
1295 Modifications *modlist = NULL;
1296 Modifications **modtail = &modlist;
1298 struct berval* ocbva = NULL;
1299 struct berval* cnbva = NULL;
1300 struct berval* ssbva = NULL;
1301 struct berval* scbva = NULL;
1306 char txtbuf[SLAP_TEXT_BUFLEN];
1307 size_t textlen = sizeof txtbuf;
1312 struct berval sub_bv = { 0, NULL };
1313 struct berval psubrdn = { 0, NULL };
1316 SlapReply rs = {REP_RESULT};
1318 ocbva = ( struct berval * ) ch_calloc( 4, sizeof( struct berval ));
1319 cnbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval ));
1320 ssbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval ));
1321 scbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval ));
1323 /* update in memory cookie */
1324 if ( si->syncCookie != NULL ) {
1325 ber_bvfree( si->syncCookie );
1327 si->syncCookie = ber_dupbv( NULL, syncCookie );
1328 ber_str2bv( "top", strlen("top"), 1, &ocbva[0] );
1329 ber_str2bv( "subentry", strlen("subentry"), 1, &ocbva[1] );
1330 ber_str2bv( "syncConsumerSubentry",
1331 strlen("syncConsumerSubentry"), 1, &ocbva[2] );
1332 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1333 mod->sml_op = LDAP_MOD_REPLACE;
1334 ber_str2bv( "objectClass", strlen("objectClass"), 1, &mod->sml_type );
1335 mod->sml_bvalues = ocbva;
1337 modtail = &mod->sml_next;
1339 sprintf( substr, "syncrepl%d", si->id );
1340 sprintf( rdnstr, "cn=%s", substr );
1341 ber_str2bv( substr, strlen( substr ), 1, &cnbva[0] );
1342 ber_str2bv( rdnstr, strlen( rdnstr ), 1, &psubrdn );
1343 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1344 mod->sml_op = LDAP_MOD_REPLACE;
1345 ber_str2bv( "cn", strlen("cn"), 1, &mod->sml_type );
1346 mod->sml_bvalues = cnbva;
1348 modtail = &mod->sml_next;
1350 ber_dupbv( &scbva[0], si->syncCookie );
1351 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1352 mod->sml_op = LDAP_MOD_REPLACE;
1353 ber_str2bv( "syncreplCookie", strlen("syncreplCookie"),
1354 1, &mod->sml_type );
1355 mod->sml_bvalues = scbva;
1357 modtail = &mod->sml_next;
1359 ber_str2bv( "{}", strlen("{}"), 1, &ssbva[0] );
1360 mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ));
1361 mod->sml_op = LDAP_MOD_REPLACE;
1362 ber_str2bv( "subtreeSpecification",
1363 strlen("subtreeSpecification"), 1, &mod->sml_type );
1364 mod->sml_bvalues = ssbva;
1366 modtail = &mod->sml_next;
1368 rc = slap_mods_check( modlist, 1, &text, txtbuf, textlen, NULL );
1370 if ( rc != LDAP_SUCCESS ) {
1372 LDAP_LOG( OPERATION, ERR,
1373 "syncrepl_updateCookie: mods check (%s)\n", text, 0, 0 );
1375 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods check (%s)\n",
1380 op->o_tag = LDAP_REQ_ADD;
1381 rc = slap_mods_opattrs( op, modlist, modtail,
1382 &text,txtbuf, textlen );
1384 for ( ml = modlist; ml != NULL; ml = mlnext ) {
1385 mlnext = ml->sml_next;
1386 ml->sml_op = LDAP_MOD_REPLACE;
1389 if( rc != LDAP_SUCCESS ) {
1391 LDAP_LOG( OPERATION, ERR,
1392 "syncrepl_updateCookie: mods opattrs (%s)\n", text, 0, 0 );
1394 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods opattrs (%s)\n",
1399 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
1401 build_new_dn( &sub_bv, pdn, &psubrdn, NULL );
1402 dnPrettyNormal( NULL, &sub_bv, &e->e_name, &e->e_nname, NULL );
1403 ch_free( sub_bv.bv_val );
1404 ch_free( psubrdn.bv_val );
1408 rc = slap_mods2entry( modlist, &e, 1, 1, &text, txtbuf, textlen );
1410 if( rc != LDAP_SUCCESS ) {
1412 LDAP_LOG( OPERATION, ERR,
1413 "syncrepl_updateCookie: mods2entry (%s)\n", text, 0, 0 );
1415 Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods2entry (%s)\n",
1420 cb.sc_response = null_callback;
1423 op->o_callback = &cb;
1424 op->o_req_dn = e->e_name;
1425 op->o_req_ndn = e->e_nname;
1427 /* update persistent cookie */
1428 update_cookie_retry:
1429 op->o_tag = LDAP_REQ_MODIFY;
1430 op->orm_modlist = modlist;
1431 rc = be->be_modify( op, &rs );
1433 if ( rc != LDAP_SUCCESS ) {
1434 if ( rc == LDAP_REFERRAL ||
1435 rc == LDAP_NO_SUCH_OBJECT ) {
1436 op->o_tag = LDAP_REQ_ADD;
1438 rc = be->be_add( op, &rs );
1439 if ( rc != LDAP_SUCCESS ) {
1440 if ( rc == LDAP_ALREADY_EXISTS ) {
1441 goto update_cookie_retry;
1442 } else if ( rc == LDAP_REFERRAL ||
1443 rc == LDAP_NO_SUCH_OBJECT ) {
1445 LDAP_LOG( OPERATION, ERR,
1446 "cookie will be non-persistent\n",
1449 Debug( LDAP_DEBUG_ANY,
1450 "cookie will be non-persistent\n",
1455 LDAP_LOG( OPERATION, ERR,
1456 "be_add failed (%d)\n",
1459 Debug( LDAP_DEBUG_ANY,
1460 "be_add failed (%d)\n",
1465 be_entry_release_w( op, e );
1470 LDAP_LOG( OPERATION, ERR,
1471 "be_modify failed (%d)\n", rc, 0, 0 );
1473 Debug( LDAP_DEBUG_ANY,
1474 "be_modify failed (%d)\n", rc, 0, 0 );
1486 slap_mods_free( modlist );
1493 avl_ber_bvfree( void *bv )
1498 if ( ((struct berval *)bv)->bv_val != NULL ) {
1499 ch_free ( ((struct berval *)bv)->bv_val );
1501 ch_free ( (char *) bv );
1510 syncinfo_t *si = op->o_callback->sc_private;
1513 if ( rs->sr_type != REP_SEARCH ) return LDAP_SUCCESS;
1515 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_syncreplCookie );
1518 si->syncCookie = NULL;
1520 si->syncCookie = ber_dupbv( NULL, &a->a_vals[0] );
1522 return LDAP_SUCCESS;
1531 syncinfo_t *si = op->o_callback->sc_private;
1533 if ( rs->sr_type == REP_SEARCH ) {
1534 if ( si->syncUUID_ndn != NULL ) {
1536 LDAP_LOG( OPERATION, ERR,
1537 "dn_callback : multiple entries match dn\n", 0, 0, 0 );
1539 Debug( LDAP_DEBUG_ANY,
1540 "dn_callback : multiple entries match dn\n", 0, 0, 0 );
1543 if ( rs->sr_entry == NULL ) {
1544 si->syncUUID_ndn = NULL;
1546 si->syncUUID_ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname );
1551 return LDAP_SUCCESS;
1555 nonpresent_callback(
1560 syncinfo_t *si = op->o_callback->sc_private;
1563 struct berval* present_uuid = NULL;
1565 SlapReply rs_cb = {REP_RESULT};
1566 struct nonpresent_entry *np_entry;
1568 if ( rs->sr_type == REP_RESULT ) {
1569 count = avl_free( si->presentlist, avl_ber_bvfree );
1570 si->presentlist = NULL;
1571 return LDAP_SUCCESS;
1572 } else if ( rs->sr_type == REP_SEARCH ) {
1573 a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID );
1578 present_uuid = avl_find( si->presentlist, &a->a_vals[0], syncuuid_cmp );
1580 if ( present_uuid == NULL ) {
1581 np_entry = (struct nonpresent_entry *)
1582 ch_calloc( 1, sizeof( struct nonpresent_entry ));
1583 np_entry->dn = ber_dupbv( NULL, &rs->sr_entry->e_name );
1584 np_entry->ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname );
1585 LDAP_LIST_INSERT_HEAD( &si->nonpresentlist, np_entry, np_link );
1587 avl_delete( &si->presentlist,
1588 &a->a_vals[0], syncuuid_cmp );
1589 ch_free( present_uuid->bv_val );
1590 ch_free( present_uuid );
1592 return LDAP_SUCCESS;
1594 return LDAP_SUCCESS;
1605 syncinfo_t *si = op->o_callback->sc_private;
1607 if ( rs->sr_err != LDAP_SUCCESS &&
1608 rs->sr_err != LDAP_REFERRAL &&
1609 rs->sr_err != LDAP_ALREADY_EXISTS &&
1610 rs->sr_err != LDAP_NO_SUCH_OBJECT ) {
1612 LDAP_LOG( OPERATION, ERR,
1613 "null_callback : error code 0x%x\n",
1616 Debug( LDAP_DEBUG_ANY,
1617 "null_callback : error code 0x%x\n",
1621 return LDAP_SUCCESS;
1624 static struct berval ocbva[] = {
1626 BER_BVC("subentry"),
1627 BER_BVC("syncProviderSubentry"),
1632 slap_create_syncrepl_entry(
1634 struct berval *context_csn,
1644 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
1646 attr_merge( e, slap_schema.si_ad_objectClass, ocbva, NULL );
1648 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &ocbva[1], NULL );
1650 attr_merge_one( e, slap_schema.si_ad_cn, cn, NULL );
1652 if ( context_csn ) {
1653 attr_merge_one( e, slap_schema.si_ad_syncreplCookie,
1654 context_csn, NULL );
1658 bv.bv_len = sizeof("{}")-1;
1659 attr_merge_one( e, slap_schema.si_ad_subtreeSpecification, &bv, NULL );
1661 build_new_dn( &e->e_name, &be->be_nsuffix[0], rdn, NULL );
1662 ber_dupbv( &e->e_nname, &e->e_name );