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? - checked above */
407 /* newSuperior == entry being moved?, if so ==> ERROR */
408 if ( dnIsSuffix( np_ndn, &e->e_nname )) {
409 rs->sr_err = LDAP_NAMING_VIOLATION;
410 rs->sr_text = "new superior is invalid";
413 /* Get Entry with dn=newSuperior. Does newSuperior exist? */
415 rs->sr_err = bdb_dn2entry( op, ltid, np_ndn,
416 &neip, 0, locker, &nplock );
418 switch( rs->sr_err ) {
419 case 0: np = neip->bei_e;
422 case DB_LOCK_DEADLOCK:
423 case DB_LOCK_NOTGRANTED:
426 rs->sr_text = "ldap server busy";
429 rs->sr_err = LDAP_OTHER;
430 rs->sr_text = "internal error";
435 Debug( LDAP_DEBUG_TRACE,
436 LDAP_XSTRING(bdb_modrdn)
437 ": newSup(ndn=%s) not here!\n",
438 np_ndn->bv_val, 0, 0);
439 rs->sr_text = "new superior not found";
440 rs->sr_err = LDAP_OTHER;
444 Debug( LDAP_DEBUG_TRACE,
445 LDAP_XSTRING(bdb_modrdn)
446 ": wr to new parent OK np=%p, id=%ld\n",
447 (void *) np, (long) np->e_id, 0 );
449 /* check newSuperior for "children" acl */
450 rs->sr_err = access_allowed( op, np, children,
451 NULL, ACL_WADD, NULL );
454 switch( opinfo.boi_err ) {
455 case DB_LOCK_DEADLOCK:
456 case DB_LOCK_NOTGRANTED:
460 Debug( LDAP_DEBUG_TRACE,
461 LDAP_XSTRING(bdb_modrdn)
462 ": no wr to newSup children\n",
464 rs->sr_text = "no write access to new superior's children";
465 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
469 if ( is_entry_alias( np ) ) {
470 /* parent is an alias, don't allow add */
471 Debug( LDAP_DEBUG_TRACE,
472 LDAP_XSTRING(bdb_modrdn)
473 ": entry is alias\n",
475 rs->sr_text = "new superior is an alias";
476 rs->sr_err = LDAP_ALIAS_PROBLEM;
480 if ( is_entry_referral( np ) ) {
481 /* parent is a referral, don't allow add */
482 Debug( LDAP_DEBUG_TRACE,
483 LDAP_XSTRING(bdb_modrdn)
484 ": entry is referral\n",
486 rs->sr_text = "new superior is a referral";
487 rs->sr_err = LDAP_OTHER;
492 if ( isroot == -1 ) {
493 isroot = be_isroot( op );
498 /* no parent, modrdn entry directly under root */
500 if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv )
501 || be_isupdate( op ) ) {
502 np = (Entry *)&slap_entry_root;
504 /* check parent for "children" acl */
505 rs->sr_err = access_allowed( op, np,
506 children, NULL, ACL_WADD, NULL );
510 if ( ! rs->sr_err ) {
511 switch( opinfo.boi_err ) {
512 case DB_LOCK_DEADLOCK:
513 case DB_LOCK_NOTGRANTED:
517 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
518 Debug( LDAP_DEBUG_TRACE,
519 "no access to new superior\n",
522 "no write access to new superior's children";
526 Debug( LDAP_DEBUG_TRACE,
527 LDAP_XSTRING(bdb_modrdn)
529 "of entry \"\" OK\n",
533 Debug( LDAP_DEBUG_TRACE,
534 LDAP_XSTRING(bdb_modrdn)
535 ": new superior=\"\", not root "
536 "& \"\" is not suffix\n",
538 rs->sr_text = "no write access to new superior's children";
539 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
544 Debug( LDAP_DEBUG_TRACE,
545 LDAP_XSTRING(bdb_modrdn)
546 ": new superior=\"\"\n",
550 Debug( LDAP_DEBUG_TRACE,
551 LDAP_XSTRING(bdb_modrdn)
552 ": wr to new parent's children OK\n",
555 new_parent_dn = np_dn;
558 /* Build target dn and make sure target entry doesn't exist already. */
559 if (!new_dn.bv_val) {
560 build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn, NULL );
563 if (!new_ndn.bv_val) {
564 struct berval bv = {0, NULL};
565 dnNormalize( 0, NULL, NULL, &new_dn, &bv, op->o_tmpmemctx );
566 ber_dupbv( &new_ndn, &bv );
569 Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(bdb_modrdn) ": new ndn=%s\n",
570 new_ndn.bv_val, 0, 0 );
572 /* Shortcut the search */
573 nei = neip ? neip : eip;
574 rs->sr_err = bdb_cache_find_ndn ( op, ltid, &new_ndn, &nei );
575 if ( nei ) bdb_cache_entryinfo_unlock( nei );
576 switch( rs->sr_err ) {
577 case DB_LOCK_DEADLOCK:
578 case DB_LOCK_NOTGRANTED:
583 rs->sr_err = LDAP_ALREADY_EXISTS;
586 rs->sr_err = LDAP_OTHER;
587 rs->sr_text = "internal error";
591 /* Get attribute type and attribute value of our new rdn, we will
592 * need to add that to our new entry
594 if ( !new_rdn && ldap_bv2rdn_x( &op->oq_modrdn.rs_newrdn, &new_rdn,
595 (char **)&rs->sr_text, LDAP_DN_FORMAT_LDAP, op->o_tmpmemctx ) )
597 Debug( LDAP_DEBUG_TRACE,
598 LDAP_XSTRING(bdb_modrdn) ": can't figure out "
599 "type(s)/values(s) of newrdn\n",
601 rs->sr_err = LDAP_INVALID_DN_SYNTAX;
602 rs->sr_text = "unknown type(s) used in RDN";
606 Debug( LDAP_DEBUG_TRACE,
607 LDAP_XSTRING(bdb_modrdn)
608 ": new_rdn_type=\"%s\", new_rdn_val=\"%s\"\n",
609 new_rdn[ 0 ]->la_attr.bv_val,
610 new_rdn[ 0 ]->la_value.bv_val, 0 );
612 if ( op->oq_modrdn.rs_deleteoldrdn ) {
613 if ( !old_rdn && ldap_bv2rdn_x( &op->o_req_dn, &old_rdn,
614 (char **)&rs->sr_text, LDAP_DN_FORMAT_LDAP, op->o_tmpmemctx ) )
616 Debug( LDAP_DEBUG_TRACE,
617 LDAP_XSTRING(bdb_modrdn) ": can't figure out "
618 "the old_rdn type(s)/value(s)\n",
620 rs->sr_err = LDAP_OTHER;
621 rs->sr_text = "cannot parse RDN from old DN";
626 /* prepare modlist of modifications from old/new rdn */
628 rs->sr_err = slap_modrdn2mods( op, rs, e, old_rdn, new_rdn, &mod );
629 if ( rs->sr_err != LDAP_SUCCESS ) {
634 if( op->o_preread ) {
635 if( preread_ctrl == NULL ) {
636 preread_ctrl = &ctrls[num_ctrls++];
637 ctrls[num_ctrls] = NULL;
639 if( slap_read_controls( op, rs, e,
640 &slap_pre_read_bv, preread_ctrl ) )
642 Debug( LDAP_DEBUG_TRACE,
643 "<=- " LDAP_XSTRING(bdb_modrdn)
644 ": post-read failed!\n", 0, 0, 0 );
649 /* nested transaction */
650 rs->sr_err = TXN_BEGIN( bdb->bi_dbenv, ltid, <2, bdb->bi_db_opflags );
652 if( rs->sr_err != 0 ) {
653 Debug( LDAP_DEBUG_TRACE,
654 LDAP_XSTRING(bdb_modrdn)
655 ": txn_begin(2) failed: %s (%d)\n",
656 db_strerror(rs->sr_err), rs->sr_err, 0 );
657 rs->sr_err = LDAP_OTHER;
658 rs->sr_text = "internal error";
663 rs->sr_err = bdb_dn2id_delete( op, lt2, eip, e );
664 if ( rs->sr_err != 0 ) {
665 Debug(LDAP_DEBUG_TRACE,
666 "<=- " LDAP_XSTRING(bdb_modrdn)
667 ": dn2id del failed: %s (%d)\n",
668 db_strerror(rs->sr_err), rs->sr_err, 0 );
669 switch( rs->sr_err ) {
670 case DB_LOCK_DEADLOCK:
671 case DB_LOCK_NOTGRANTED:
674 rs->sr_err = LDAP_OTHER;
675 rs->sr_text = "DN index delete fail";
679 /* copy the entry, then override some fields */
681 dummy.e_name = new_dn;
682 dummy.e_nname = new_ndn;
683 dummy.e_attrs = NULL;
686 rs->sr_err = bdb_dn2id_add( op, lt2, neip ? neip : eip, &dummy );
687 if ( rs->sr_err != 0 ) {
688 Debug(LDAP_DEBUG_TRACE,
689 "<=- " LDAP_XSTRING(bdb_modrdn)
690 ": dn2id add failed: %s (%d)\n",
691 db_strerror(rs->sr_err), rs->sr_err, 0 );
692 switch( rs->sr_err ) {
693 case DB_LOCK_DEADLOCK:
694 case DB_LOCK_NOTGRANTED:
697 rs->sr_err = LDAP_OTHER;
698 rs->sr_text = "DN index add failed";
702 dummy.e_attrs = e->e_attrs;
705 rs->sr_err = bdb_modify_internal( op, lt2, &mod[0], &dummy,
706 &rs->sr_text, textbuf, textlen );
707 if( rs->sr_err != LDAP_SUCCESS ) {
708 Debug(LDAP_DEBUG_TRACE,
709 "<=- " LDAP_XSTRING(bdb_modrdn)
710 ": modify failed: %s (%d)\n",
711 db_strerror(rs->sr_err), rs->sr_err, 0 );
712 if ( ( rs->sr_err == LDAP_INSUFFICIENT_ACCESS ) && opinfo.boi_err ) {
713 rs->sr_err = opinfo.boi_err;
715 if ( dummy.e_attrs == e->e_attrs ) dummy.e_attrs = NULL;
716 switch( rs->sr_err ) {
717 case DB_LOCK_DEADLOCK:
718 case DB_LOCK_NOTGRANTED:
725 rs->sr_err = bdb_id2entry_update( op->o_bd, lt2, &dummy );
726 if ( rs->sr_err != 0 ) {
727 Debug(LDAP_DEBUG_TRACE,
728 "<=- " LDAP_XSTRING(bdb_modrdn)
729 ": id2entry failed: %s (%d)\n",
730 db_strerror(rs->sr_err), rs->sr_err, 0 );
731 switch( rs->sr_err ) {
732 case DB_LOCK_DEADLOCK:
733 case DB_LOCK_NOTGRANTED:
736 rs->sr_err = LDAP_OTHER;
737 rs->sr_text = "entry update failed";
741 if ( p_ndn.bv_len != 0 ) {
742 parent_is_glue = is_entry_glue(p);
743 rs->sr_err = bdb_cache_children( op, lt2, p );
744 if ( rs->sr_err != DB_NOTFOUND ) {
745 switch( rs->sr_err ) {
746 case DB_LOCK_DEADLOCK:
747 case DB_LOCK_NOTGRANTED:
752 Debug(LDAP_DEBUG_ARGS,
753 "<=- " LDAP_XSTRING(bdb_modrdn)
754 ": has_children failed: %s (%d)\n",
755 db_strerror(rs->sr_err), rs->sr_err, 0 );
756 rs->sr_err = LDAP_OTHER;
757 rs->sr_text = "internal error";
762 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, p);
766 if ( TXN_COMMIT( lt2, 0 ) != 0 ) {
767 rs->sr_err = LDAP_OTHER;
768 rs->sr_text = "txn_commit(2) failed";
772 if( op->o_postread ) {
773 if( postread_ctrl == NULL ) {
774 postread_ctrl = &ctrls[num_ctrls++];
775 ctrls[num_ctrls] = NULL;
777 if( slap_read_controls( op, rs, &dummy,
778 &slap_post_read_bv, postread_ctrl ) )
780 Debug( LDAP_DEBUG_TRACE,
781 "<=- " LDAP_XSTRING(bdb_modrdn)
782 ": post-read failed!\n", 0, 0, 0 );
788 if(( rs->sr_err=TXN_ABORT( ltid )) != 0 ) {
789 rs->sr_text = "txn_abort (no-op) failed";
791 rs->sr_err = LDAP_SUCCESS;
796 rc = bdb_cache_modrdn( e, &op->orr_nnewrdn, &dummy, neip,
797 bdb->bi_dbenv, locker, &lock );
799 case DB_LOCK_DEADLOCK:
800 case DB_LOCK_NOTGRANTED:
803 dummy.e_attrs = NULL;
804 new_dn.bv_val = NULL;
805 new_ndn.bv_val = NULL;
807 if(( rs->sr_err=TXN_COMMIT( ltid, 0 )) != 0 ) {
808 rs->sr_text = "txn_commit failed";
810 rs->sr_err = LDAP_SUCCESS;
815 op->o_private = NULL;
817 if( rs->sr_err != LDAP_SUCCESS ) {
818 Debug( LDAP_DEBUG_TRACE,
819 LDAP_XSTRING(bdb_modrdn) ": %s : %s (%d)\n",
820 rs->sr_text, db_strerror(rs->sr_err), rs->sr_err );
821 rs->sr_err = LDAP_OTHER;
826 Debug(LDAP_DEBUG_TRACE,
827 LDAP_XSTRING(bdb_modrdn)
828 ": rdn modified%s id=%08lx dn=\"%s\"\n",
829 op->o_noop ? " (no-op)" : "",
830 dummy.e_id, op->o_req_dn.bv_val );
832 if( num_ctrls ) rs->sr_ctrls = ctrls;
835 if ( dummy.e_attrs ) {
836 attrs_free( dummy.e_attrs );
838 send_ldap_result( op, rs );
840 if( rs->sr_err == LDAP_SUCCESS && bdb->bi_txn_cp ) {
841 ldap_pvt_thread_yield();
842 TXN_CHECKPOINT( bdb->bi_dbenv,
843 bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
846 if ( rs->sr_err == LDAP_SUCCESS && parent_is_glue && parent_is_leaf ) {
847 op->o_delete_glue_parent = 1;
851 if( new_dn.bv_val != NULL ) free( new_dn.bv_val );
852 if( new_ndn.bv_val != NULL ) free( new_ndn.bv_val );
854 /* LDAP v2 supporting correct attribute handling. */
855 if ( new_rdn != NULL ) {
856 ldap_rdnfree_x( new_rdn, op->o_tmpmemctx );
858 if ( old_rdn != NULL ) {
859 ldap_rdnfree_x( old_rdn, op->o_tmpmemctx );
863 for (; mod; mod=tmp ) {
865 /* slap_modrdn2mods does things one way,
866 * slap_mods_opattrs does it differently
868 if ( mod->sml_op != SLAP_MOD_SOFTADD &&
869 mod->sml_op != LDAP_MOD_DELETE ) break;
870 if ( mod->sml_nvalues ) free( mod->sml_nvalues[0].bv_val );
873 slap_mods_free( mod );
876 /* LDAP v3 Support */
878 /* free new parent and reader lock */
879 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, np);
883 /* free parent and reader lock */
884 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, p);
889 bdb_unlocked_cache_return_entry_w( &bdb->bi_cache, e);
894 op->o_private = NULL;
897 if( preread_ctrl != NULL ) {
898 slap_sl_free( (*preread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
899 slap_sl_free( *preread_ctrl, op->o_tmpmemctx );
901 if( postread_ctrl != NULL ) {
902 slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
903 slap_sl_free( *postread_ctrl, op->o_tmpmemctx );