1 /* modrdn.c - bdb backend modrdn routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
20 #include <ac/string.h>
25 bdb_modrdn( Operation *op, SlapReply *rs )
27 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
28 AttributeDescription *children = slap_schema.si_ad_children;
29 AttributeDescription *entry = slap_schema.si_ad_entry;
30 struct berval p_dn, p_ndn;
31 struct berval new_dn = {0, NULL}, new_ndn = {0, NULL};
35 EntryInfo *ei = NULL, *eip = NULL, *nei = NULL, *neip = NULL;
36 /* LDAP v2 supporting correct attribute handling. */
37 LDAPRDN new_rdn = NULL;
38 LDAPRDN old_rdn = NULL;
39 char textbuf[SLAP_TEXT_BUFLEN];
40 size_t textlen = sizeof textbuf;
41 DB_TXN *ltid = NULL, *lt2;
42 struct bdb_op_info opinfo = {0};
45 Entry *np = NULL; /* newSuperior Entry */
46 struct berval *np_dn = NULL; /* newSuperior dn */
47 struct berval *np_ndn = NULL; /* newSuperior ndn */
48 struct berval *new_parent_dn = NULL; /* np_dn, p_dn, or NULL */
50 /* Used to interface with bdb_modify_internal() */
51 Modifications *mod = NULL; /* Used to delete old rdn */
53 int manageDSAit = get_manageDSAit( op );
56 DB_LOCK lock, plock, nplock;
60 LDAPControl **preread_ctrl = NULL;
61 LDAPControl **postread_ctrl = NULL;
62 LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
67 int parent_is_glue = 0;
68 int parent_is_leaf = 0;
70 ctrls[num_ctrls] = NULL;
72 Debug( LDAP_DEBUG_TRACE, "==>" LDAP_XSTRING(bdb_modrdn) "(%s,%s,%s)\n",
73 op->o_req_dn.bv_val,op->oq_modrdn.rs_newrdn.bv_val,
74 op->oq_modrdn.rs_newSup ? op->oq_modrdn.rs_newSup->bv_val : "NULL" );
77 retry: /* transaction retry */
78 if ( dummy.e_attrs ) {
79 attrs_free( dummy.e_attrs );
83 bdb_unlocked_cache_return_entry_w(&bdb->bi_cache, e);
87 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, p);
91 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, np);
94 Debug( LDAP_DEBUG_TRACE, "==>" LDAP_XSTRING(bdb_modrdn)
95 ": retrying...\n", 0, 0, 0 );
97 rs->sr_err = TXN_ABORT( ltid );
100 op->o_do_not_cache = opinfo.boi_acl_cache;
101 if( rs->sr_err != 0 ) {
102 rs->sr_err = LDAP_OTHER;
103 rs->sr_text = "internal error";
108 ldap_pvt_thread_yield();
109 bdb_trans_backoff( ++num_retries );
112 /* begin transaction */
113 rs->sr_err = TXN_BEGIN( bdb->bi_dbenv, NULL, <id,
114 bdb->bi_db_opflags );
116 if( rs->sr_err != 0 ) {
117 Debug( LDAP_DEBUG_TRACE,
118 LDAP_XSTRING(bdb_modrdn) ": txn_begin failed: "
119 "%s (%d)\n", db_strerror(rs->sr_err), rs->sr_err, 0 );
120 rs->sr_err = LDAP_OTHER;
121 rs->sr_text = "internal error";
125 locker = TXN_ID ( ltid );
127 opinfo.boi_bdb = op->o_bd;
128 opinfo.boi_txn = ltid;
129 opinfo.boi_locker = locker;
131 opinfo.boi_acl_cache = op->o_do_not_cache;
132 op->o_private = &opinfo;
135 rs->sr_err = bdb_dn2entry( op, ltid, &op->o_req_ndn, &ei, 1,
138 switch( rs->sr_err ) {
142 case DB_LOCK_DEADLOCK:
143 case DB_LOCK_NOTGRANTED:
146 rs->sr_text = "ldap server busy";
149 rs->sr_err = LDAP_OTHER;
150 rs->sr_text = "internal error";
155 /* FIXME: dn2entry() should return non-glue entry */
156 if (( rs->sr_err == DB_NOTFOUND ) ||
157 ( !manageDSAit && e && is_entry_glue( e )))
160 rs->sr_matched = ch_strdup( e->e_dn );
161 rs->sr_ref = is_entry_referral( e )
162 ? get_entry_referrals( op, e )
164 bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, e);
168 rs->sr_ref = referral_rewrite( default_referral, NULL,
169 &op->o_req_dn, LDAP_SCOPE_DEFAULT );
172 rs->sr_err = LDAP_REFERRAL;
173 send_ldap_result( op, rs );
175 ber_bvarray_free( rs->sr_ref );
176 free( (char *)rs->sr_matched );
178 rs->sr_matched = NULL;
183 if ( get_assert( op ) &&
184 ( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
186 rs->sr_err = LDAP_ASSERTION_FAILED;
190 /* check write on old entry */
191 rs->sr_err = access_allowed( op, e, entry, NULL, ACL_WRITE, NULL );
192 if ( ! rs->sr_err ) {
193 switch( opinfo.boi_err ) {
194 case DB_LOCK_DEADLOCK:
195 case DB_LOCK_NOTGRANTED:
199 Debug( LDAP_DEBUG_TRACE, "no access to entry\n", 0,
201 rs->sr_text = "no write access to old entry";
202 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
207 rs->sr_err = bdb_cache_children( op, ltid, e );
208 if ( rs->sr_err != DB_NOTFOUND ) {
209 switch( rs->sr_err ) {
210 case DB_LOCK_DEADLOCK:
211 case DB_LOCK_NOTGRANTED:
214 Debug(LDAP_DEBUG_ARGS,
215 "<=- " LDAP_XSTRING(bdb_modrdn)
217 op->o_req_dn.bv_val, 0, 0);
218 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
219 rs->sr_text = "subtree rename not supported";
222 Debug(LDAP_DEBUG_ARGS,
223 "<=- " LDAP_XSTRING(bdb_modrdn)
224 ": has_children failed: %s (%d)\n",
225 db_strerror(rs->sr_err), rs->sr_err, 0 );
226 rs->sr_err = LDAP_OTHER;
227 rs->sr_text = "internal error";
231 ei->bei_state |= CACHE_ENTRY_NO_KIDS;
234 if (!manageDSAit && is_entry_referral( e ) ) {
235 /* parent is a referral, don't allow add */
236 rs->sr_ref = get_entry_referrals( op, e );
238 Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(bdb_modrdn)
239 ": entry %s is referral\n", e->e_dn, 0, 0 );
241 rs->sr_err = LDAP_REFERRAL,
242 rs->sr_matched = e->e_name.bv_val;
243 send_ldap_result( op, rs );
245 ber_bvarray_free( rs->sr_ref );
247 rs->sr_matched = NULL;
251 if ( be_issuffix( op->o_bd, &e->e_nname ) ) {
252 p_ndn = slap_empty_bv;
254 dnParent( &e->e_nname, &p_ndn );
257 if ( p_ndn.bv_len != 0 ) {
258 /* Make sure parent entry exist and we can write its
261 eip = ei->bei_parent;
262 rs->sr_err = bdb_cache_find_id( op, ltid,
263 eip->bei_id, &eip, 0, locker, &plock );
265 switch( rs->sr_err ) {
269 case DB_LOCK_DEADLOCK:
270 case DB_LOCK_NOTGRANTED:
273 rs->sr_text = "ldap server busy";
276 rs->sr_err = LDAP_OTHER;
277 rs->sr_text = "internal error";
283 Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(bdb_modrdn)
284 ": parent does not exist\n", 0, 0, 0);
285 rs->sr_err = LDAP_OTHER;
286 rs->sr_text = "old entry's parent does not exist";
290 /* check parent for "children" acl */
291 rs->sr_err = access_allowed( op, p,
293 op->oq_modrdn.rs_newSup == NULL ?
294 ACL_WRITE : ACL_WDEL,
297 if ( ! rs->sr_err ) {
298 switch( opinfo.boi_err ) {
299 case DB_LOCK_DEADLOCK:
300 case DB_LOCK_NOTGRANTED:
304 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
305 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
307 rs->sr_text = "no write access to old parent's children";
311 Debug( LDAP_DEBUG_TRACE,
312 LDAP_XSTRING(bdb_modrdn) ": wr to children "
313 "of entry %s OK\n", p_ndn.bv_val, 0, 0 );
315 if ( p_ndn.bv_val == slap_empty_bv.bv_val ) {
316 p_dn = slap_empty_bv;
318 dnParent( &e->e_name, &p_dn );
321 Debug( LDAP_DEBUG_TRACE,
322 LDAP_XSTRING(bdb_modrdn) ": parent dn=%s\n",
326 /* no parent, modrdn entry directly under root */
327 isroot = be_isroot( op );
329 if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv )
330 || be_shadow_update( op ) ) {
332 p = (Entry *)&slap_entry_root;
334 /* check parent for "children" acl */
335 rs->sr_err = access_allowed( op, p,
337 op->oq_modrdn.rs_newSup == NULL ?
338 ACL_WRITE : ACL_WDEL,
343 if ( ! rs->sr_err ) {
344 switch( opinfo.boi_err ) {
345 case DB_LOCK_DEADLOCK:
346 case DB_LOCK_NOTGRANTED:
350 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
351 Debug( LDAP_DEBUG_TRACE,
352 "no access to parent\n",
354 rs->sr_text = "no write access to old parent";
358 Debug( LDAP_DEBUG_TRACE,
359 LDAP_XSTRING(bdb_modrdn)
360 ": wr to children of entry \"\" OK\n",
366 Debug( LDAP_DEBUG_TRACE,
367 LDAP_XSTRING(bdb_modrdn)
368 ": parent dn=\"\"\n",
372 Debug( LDAP_DEBUG_TRACE,
373 LDAP_XSTRING(bdb_modrdn)
374 ": no parent, not root "
375 "& \"\" is not suffix\n",
377 rs->sr_text = "no write access to old parent";
378 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
384 new_parent_dn = &p_dn; /* New Parent unless newSuperior given */
386 if ( op->oq_modrdn.rs_newSup != NULL ) {
387 Debug( LDAP_DEBUG_TRACE,
388 LDAP_XSTRING(bdb_modrdn)
389 ": new parent \"%s\" requested...\n",
390 op->oq_modrdn.rs_newSup->bv_val, 0, 0 );
392 /* newSuperior == oldParent? */
393 if( dn_match( &p_ndn, op->oq_modrdn.rs_nnewSup ) ) {
394 Debug( LDAP_DEBUG_TRACE, "bdb_back_modrdn: "
395 "new parent \"%s\" same as the old parent \"%s\"\n",
396 op->oq_modrdn.rs_newSup->bv_val, p_dn.bv_val, 0 );
397 op->oq_modrdn.rs_newSup = NULL; /* ignore newSuperior */
401 if ( op->oq_modrdn.rs_newSup != NULL ) {
402 if ( op->oq_modrdn.rs_newSup->bv_len ) {
403 np_dn = op->oq_modrdn.rs_newSup;
404 np_ndn = op->oq_modrdn.rs_nnewSup;
406 /* newSuperior == oldParent?, if so ==> ERROR */
407 /* newSuperior == entry being moved?, if so ==> ERROR */
408 /* Get Entry with dn=newSuperior. Does newSuperior exist? */
410 rs->sr_err = bdb_dn2entry( op, ltid, np_ndn,
411 &neip, 0, locker, &nplock );
413 switch( rs->sr_err ) {
414 case 0: np = neip->bei_e;
417 case DB_LOCK_DEADLOCK:
418 case DB_LOCK_NOTGRANTED:
421 rs->sr_text = "ldap server busy";
424 rs->sr_err = LDAP_OTHER;
425 rs->sr_text = "internal error";
430 Debug( LDAP_DEBUG_TRACE,
431 LDAP_XSTRING(bdb_modrdn)
432 ": newSup(ndn=%s) not here!\n",
433 np_ndn->bv_val, 0, 0);
434 rs->sr_text = "new superior not found";
435 rs->sr_err = LDAP_OTHER;
439 Debug( LDAP_DEBUG_TRACE,
440 LDAP_XSTRING(bdb_modrdn)
441 ": wr to new parent OK np=%p, id=%ld\n",
442 (void *) np, (long) np->e_id, 0 );
444 /* check newSuperior for "children" acl */
445 rs->sr_err = access_allowed( op, np, children,
446 NULL, ACL_WADD, NULL );
449 switch( opinfo.boi_err ) {
450 case DB_LOCK_DEADLOCK:
451 case DB_LOCK_NOTGRANTED:
455 Debug( LDAP_DEBUG_TRACE,
456 LDAP_XSTRING(bdb_modrdn)
457 ": no wr to newSup children\n",
459 rs->sr_text = "no write access to new superior's children";
460 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
464 if ( is_entry_alias( np ) ) {
465 /* parent is an alias, don't allow add */
466 Debug( LDAP_DEBUG_TRACE,
467 LDAP_XSTRING(bdb_modrdn)
468 ": entry is alias\n",
470 rs->sr_text = "new superior is an alias";
471 rs->sr_err = LDAP_ALIAS_PROBLEM;
475 if ( is_entry_referral( np ) ) {
476 /* parent is a referral, don't allow add */
477 Debug( LDAP_DEBUG_TRACE,
478 LDAP_XSTRING(bdb_modrdn)
479 ": entry is referral\n",
481 rs->sr_text = "new superior is a referral";
482 rs->sr_err = LDAP_OTHER;
487 if ( isroot == -1 ) {
488 isroot = be_isroot( op );
493 /* no parent, modrdn entry directly under root */
495 if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv )
496 || be_isupdate( op ) ) {
497 np = (Entry *)&slap_entry_root;
499 /* check parent for "children" acl */
500 rs->sr_err = access_allowed( op, np,
501 children, NULL, ACL_WADD, NULL );
505 if ( ! rs->sr_err ) {
506 switch( opinfo.boi_err ) {
507 case DB_LOCK_DEADLOCK:
508 case DB_LOCK_NOTGRANTED:
512 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
513 Debug( LDAP_DEBUG_TRACE,
514 "no access to new superior\n",
517 "no write access to new superior's children";
521 Debug( LDAP_DEBUG_TRACE,
522 LDAP_XSTRING(bdb_modrdn)
524 "of entry \"\" OK\n",
528 Debug( LDAP_DEBUG_TRACE,
529 LDAP_XSTRING(bdb_modrdn)
530 ": new superior=\"\", not root "
531 "& \"\" is not suffix\n",
533 rs->sr_text = "no write access to new superior's children";
534 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
539 Debug( LDAP_DEBUG_TRACE,
540 LDAP_XSTRING(bdb_modrdn)
541 ": new superior=\"\"\n",
545 Debug( LDAP_DEBUG_TRACE,
546 LDAP_XSTRING(bdb_modrdn)
547 ": wr to new parent's children OK\n",
550 new_parent_dn = np_dn;
553 /* Build target dn and make sure target entry doesn't exist already. */
554 if (!new_dn.bv_val) {
555 build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn, NULL );
558 if (!new_ndn.bv_val) {
559 struct berval bv = {0, NULL};
560 dnNormalize( 0, NULL, NULL, &new_dn, &bv, op->o_tmpmemctx );
561 ber_dupbv( &new_ndn, &bv );
564 Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(bdb_modrdn) ": new ndn=%s\n",
565 new_ndn.bv_val, 0, 0 );
567 /* Shortcut the search */
568 nei = neip ? neip : eip;
569 rs->sr_err = bdb_cache_find_ndn ( op, ltid, &new_ndn, &nei );
570 if ( nei ) bdb_cache_entryinfo_unlock( nei );
571 switch( rs->sr_err ) {
572 case DB_LOCK_DEADLOCK:
573 case DB_LOCK_NOTGRANTED:
578 rs->sr_err = LDAP_ALREADY_EXISTS;
581 rs->sr_err = LDAP_OTHER;
582 rs->sr_text = "internal error";
586 /* Get attribute type and attribute value of our new rdn, we will
587 * need to add that to our new entry
589 if ( !new_rdn && ldap_bv2rdn_x( &op->oq_modrdn.rs_newrdn, &new_rdn,
590 (char **)&rs->sr_text, LDAP_DN_FORMAT_LDAP, op->o_tmpmemctx ) )
592 Debug( LDAP_DEBUG_TRACE,
593 LDAP_XSTRING(bdb_modrdn) ": can't figure out "
594 "type(s)/values(s) of newrdn\n",
596 rs->sr_err = LDAP_INVALID_DN_SYNTAX;
597 rs->sr_text = "unknown type(s) used in RDN";
601 Debug( LDAP_DEBUG_TRACE,
602 LDAP_XSTRING(bdb_modrdn)
603 ": new_rdn_type=\"%s\", new_rdn_val=\"%s\"\n",
604 new_rdn[ 0 ]->la_attr.bv_val,
605 new_rdn[ 0 ]->la_value.bv_val, 0 );
607 if ( op->oq_modrdn.rs_deleteoldrdn ) {
608 if ( !old_rdn && ldap_bv2rdn_x( &op->o_req_dn, &old_rdn,
609 (char **)&rs->sr_text, LDAP_DN_FORMAT_LDAP, op->o_tmpmemctx ) )
611 Debug( LDAP_DEBUG_TRACE,
612 LDAP_XSTRING(bdb_modrdn) ": can't figure out "
613 "the old_rdn type(s)/value(s)\n",
615 rs->sr_err = LDAP_OTHER;
616 rs->sr_text = "cannot parse RDN from old DN";
621 /* prepare modlist of modifications from old/new rdn */
623 rs->sr_err = slap_modrdn2mods( op, rs, e, old_rdn, new_rdn, &mod );
624 if ( rs->sr_err != LDAP_SUCCESS ) {
629 if( op->o_preread ) {
630 if( preread_ctrl == NULL ) {
631 preread_ctrl = &ctrls[num_ctrls++];
632 ctrls[num_ctrls] = NULL;
634 if( slap_read_controls( op, rs, e,
635 &slap_pre_read_bv, preread_ctrl ) )
637 Debug( LDAP_DEBUG_TRACE,
638 "<=- " LDAP_XSTRING(bdb_modrdn)
639 ": post-read failed!\n", 0, 0, 0 );
644 /* nested transaction */
645 rs->sr_err = TXN_BEGIN( bdb->bi_dbenv, ltid, <2, bdb->bi_db_opflags );
647 if( rs->sr_err != 0 ) {
648 Debug( LDAP_DEBUG_TRACE,
649 LDAP_XSTRING(bdb_modrdn)
650 ": txn_begin(2) failed: %s (%d)\n",
651 db_strerror(rs->sr_err), rs->sr_err, 0 );
652 rs->sr_err = LDAP_OTHER;
653 rs->sr_text = "internal error";
658 rs->sr_err = bdb_dn2id_delete( op, lt2, eip, e );
659 if ( rs->sr_err != 0 ) {
660 Debug(LDAP_DEBUG_TRACE,
661 "<=- " LDAP_XSTRING(bdb_modrdn)
662 ": dn2id del failed: %s (%d)\n",
663 db_strerror(rs->sr_err), rs->sr_err, 0 );
664 switch( rs->sr_err ) {
665 case DB_LOCK_DEADLOCK:
666 case DB_LOCK_NOTGRANTED:
669 rs->sr_err = LDAP_OTHER;
670 rs->sr_text = "DN index delete fail";
674 /* copy the entry, then override some fields */
676 dummy.e_name = new_dn;
677 dummy.e_nname = new_ndn;
678 dummy.e_attrs = NULL;
681 rs->sr_err = bdb_dn2id_add( op, lt2, neip ? neip : eip, &dummy );
682 if ( rs->sr_err != 0 ) {
683 Debug(LDAP_DEBUG_TRACE,
684 "<=- " LDAP_XSTRING(bdb_modrdn)
685 ": dn2id add failed: %s (%d)\n",
686 db_strerror(rs->sr_err), rs->sr_err, 0 );
687 switch( rs->sr_err ) {
688 case DB_LOCK_DEADLOCK:
689 case DB_LOCK_NOTGRANTED:
692 rs->sr_err = LDAP_OTHER;
693 rs->sr_text = "DN index add failed";
697 dummy.e_attrs = e->e_attrs;
700 rs->sr_err = bdb_modify_internal( op, lt2, &mod[0], &dummy,
701 &rs->sr_text, textbuf, textlen );
702 if( rs->sr_err != LDAP_SUCCESS ) {
703 Debug(LDAP_DEBUG_TRACE,
704 "<=- " LDAP_XSTRING(bdb_modrdn)
705 ": modify failed: %s (%d)\n",
706 db_strerror(rs->sr_err), rs->sr_err, 0 );
707 if ( ( rs->sr_err == LDAP_INSUFFICIENT_ACCESS ) && opinfo.boi_err ) {
708 rs->sr_err = opinfo.boi_err;
710 if ( dummy.e_attrs == e->e_attrs ) dummy.e_attrs = NULL;
711 switch( rs->sr_err ) {
712 case DB_LOCK_DEADLOCK:
713 case DB_LOCK_NOTGRANTED:
720 rs->sr_err = bdb_id2entry_update( op->o_bd, lt2, &dummy );
721 if ( rs->sr_err != 0 ) {
722 Debug(LDAP_DEBUG_TRACE,
723 "<=- " LDAP_XSTRING(bdb_modrdn)
724 ": id2entry failed: %s (%d)\n",
725 db_strerror(rs->sr_err), rs->sr_err, 0 );
726 switch( rs->sr_err ) {
727 case DB_LOCK_DEADLOCK:
728 case DB_LOCK_NOTGRANTED:
731 rs->sr_err = LDAP_OTHER;
732 rs->sr_text = "entry update failed";
736 if ( p_ndn.bv_len != 0 ) {
737 parent_is_glue = is_entry_glue(p);
738 rs->sr_err = bdb_cache_children( op, lt2, p );
739 if ( rs->sr_err != DB_NOTFOUND ) {
740 switch( rs->sr_err ) {
741 case DB_LOCK_DEADLOCK:
742 case DB_LOCK_NOTGRANTED:
747 Debug(LDAP_DEBUG_ARGS,
748 "<=- " LDAP_XSTRING(bdb_modrdn)
749 ": has_children failed: %s (%d)\n",
750 db_strerror(rs->sr_err), rs->sr_err, 0 );
751 rs->sr_err = LDAP_OTHER;
752 rs->sr_text = "internal error";
757 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, p);
761 if ( TXN_COMMIT( lt2, 0 ) != 0 ) {
762 rs->sr_err = LDAP_OTHER;
763 rs->sr_text = "txn_commit(2) failed";
767 if( op->o_postread ) {
768 if( postread_ctrl == NULL ) {
769 postread_ctrl = &ctrls[num_ctrls++];
770 ctrls[num_ctrls] = NULL;
772 if( slap_read_controls( op, rs, &dummy,
773 &slap_post_read_bv, postread_ctrl ) )
775 Debug( LDAP_DEBUG_TRACE,
776 "<=- " LDAP_XSTRING(bdb_modrdn)
777 ": post-read failed!\n", 0, 0, 0 );
783 if(( rs->sr_err=TXN_ABORT( ltid )) != 0 ) {
784 rs->sr_text = "txn_abort (no-op) failed";
786 rs->sr_err = LDAP_SUCCESS;
791 rc = bdb_cache_modrdn( e, &op->orr_nnewrdn, &dummy, neip,
792 bdb->bi_dbenv, locker, &lock );
794 case DB_LOCK_DEADLOCK:
795 case DB_LOCK_NOTGRANTED:
798 dummy.e_attrs = NULL;
799 new_dn.bv_val = NULL;
800 new_ndn.bv_val = NULL;
802 if(( rs->sr_err=TXN_COMMIT( ltid, 0 )) != 0 ) {
803 rs->sr_text = "txn_commit failed";
805 rs->sr_err = LDAP_SUCCESS;
810 op->o_private = NULL;
812 if( rs->sr_err != LDAP_SUCCESS ) {
813 Debug( LDAP_DEBUG_TRACE,
814 LDAP_XSTRING(bdb_modrdn) ": %s : %s (%d)\n",
815 rs->sr_text, db_strerror(rs->sr_err), rs->sr_err );
816 rs->sr_err = LDAP_OTHER;
821 Debug(LDAP_DEBUG_TRACE,
822 LDAP_XSTRING(bdb_modrdn)
823 ": rdn modified%s id=%08lx dn=\"%s\"\n",
824 op->o_noop ? " (no-op)" : "",
825 dummy.e_id, op->o_req_dn.bv_val );
827 if( num_ctrls ) rs->sr_ctrls = ctrls;
830 if ( dummy.e_attrs ) {
831 attrs_free( dummy.e_attrs );
833 send_ldap_result( op, rs );
835 if( rs->sr_err == LDAP_SUCCESS && bdb->bi_txn_cp ) {
836 ldap_pvt_thread_yield();
837 TXN_CHECKPOINT( bdb->bi_dbenv,
838 bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
841 if ( rs->sr_err == LDAP_SUCCESS && parent_is_glue && parent_is_leaf ) {
842 op->o_delete_glue_parent = 1;
846 if( new_dn.bv_val != NULL ) free( new_dn.bv_val );
847 if( new_ndn.bv_val != NULL ) free( new_ndn.bv_val );
849 /* LDAP v2 supporting correct attribute handling. */
850 if ( new_rdn != NULL ) {
851 ldap_rdnfree_x( new_rdn, op->o_tmpmemctx );
853 if ( old_rdn != NULL ) {
854 ldap_rdnfree_x( old_rdn, op->o_tmpmemctx );
858 for (; mod; mod=tmp ) {
860 /* slap_modrdn2mods does things one way,
861 * slap_mods_opattrs does it differently
863 if ( mod->sml_op != SLAP_MOD_SOFTADD &&
864 mod->sml_op != LDAP_MOD_DELETE ) break;
865 if ( mod->sml_nvalues ) free( mod->sml_nvalues[0].bv_val );
868 slap_mods_free( mod );
871 /* LDAP v3 Support */
873 /* free new parent and reader lock */
874 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, np);
878 /* free parent and reader lock */
879 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, p);
884 bdb_unlocked_cache_return_entry_w( &bdb->bi_cache, e);
889 op->o_private = NULL;
892 if( preread_ctrl != NULL ) {
893 slap_sl_free( (*preread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
894 slap_sl_free( *preread_ctrl, op->o_tmpmemctx );
896 if( postread_ctrl != NULL ) {
897 slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
898 slap_sl_free( *postread_ctrl, op->o_tmpmemctx );