1 /* modrdn.c - bdb backend modrdn routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2004 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};
47 Entry *np = NULL; /* newSuperior Entry */
48 struct berval *np_dn = NULL; /* newSuperior dn */
49 struct berval *np_ndn = NULL; /* newSuperior ndn */
50 struct berval *new_parent_dn = NULL; /* np_dn, p_dn, or NULL */
52 /* Used to interface with bdb_modify_internal() */
53 Modifications *mod = NULL; /* Used to delete old rdn */
55 int manageDSAit = get_manageDSAit( op );
58 DB_LOCK lock, plock, nplock;
62 LDAPControl **preread_ctrl = NULL;
63 LDAPControl **postread_ctrl = NULL;
64 LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
68 struct psid_entry *pm_list, *pm_prev;
74 int parent_is_glue = 0;
75 int parent_is_leaf = 0;
77 ctrls[num_ctrls] = NULL;
79 Debug( LDAP_DEBUG_TRACE, "==>" LDAP_XSTRING(bdb_modrdn) "(%s,%s,%s)\n",
80 op->o_req_dn.bv_val,op->oq_modrdn.rs_newrdn.bv_val,
81 op->oq_modrdn.rs_newSup ? op->oq_modrdn.rs_newSup->bv_val : "NULL" );
84 retry: /* transaction retry */
85 if ( dummy.e_attrs ) {
86 attrs_free( dummy.e_attrs );
90 bdb_unlocked_cache_return_entry_w(&bdb->bi_cache, e);
94 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, p);
98 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, np);
101 Debug( LDAP_DEBUG_TRACE, "==>" LDAP_XSTRING(bdb_modrdn)
102 ": retrying...\n", 0, 0, 0 );
104 pm_list = LDAP_LIST_FIRST(&op->o_pm_list);
105 while ( pm_list != NULL ) {
106 LDAP_LIST_REMOVE ( pm_list, ps_link );
108 pm_list = LDAP_LIST_NEXT ( pm_list, ps_link );
113 rs->sr_err = TXN_ABORT( ltid );
115 op->o_private = NULL;
116 op->o_do_not_cache = opinfo.boi_acl_cache;
117 if( rs->sr_err != 0 ) {
118 rs->sr_err = LDAP_OTHER;
119 rs->sr_text = "internal error";
124 ldap_pvt_thread_yield();
125 bdb_trans_backoff( ++num_retries );
128 /* begin transaction */
129 rs->sr_err = TXN_BEGIN( bdb->bi_dbenv, NULL, <id,
130 bdb->bi_db_opflags );
132 if( rs->sr_err != 0 ) {
133 Debug( LDAP_DEBUG_TRACE,
134 LDAP_XSTRING(bdb_modrdn) ": txn_begin failed: "
135 "%s (%d)\n", db_strerror(rs->sr_err), rs->sr_err, 0 );
136 rs->sr_err = LDAP_OTHER;
137 rs->sr_text = "internal error";
141 locker = TXN_ID ( ltid );
143 opinfo.boi_bdb = op->o_bd;
144 opinfo.boi_txn = ltid;
145 opinfo.boi_locker = locker;
147 opinfo.boi_acl_cache = op->o_do_not_cache;
148 op->o_private = &opinfo;
151 rs->sr_err = bdb_dn2entry( op, ltid, &op->o_req_ndn, &ei, 1,
154 switch( rs->sr_err ) {
158 case DB_LOCK_DEADLOCK:
159 case DB_LOCK_NOTGRANTED:
162 rs->sr_text = "ldap server busy";
165 rs->sr_err = LDAP_OTHER;
166 rs->sr_text = "internal error";
171 /* FIXME: dn2entry() should return non-glue entry */
172 if (( rs->sr_err == DB_NOTFOUND ) ||
173 ( !manageDSAit && e && is_entry_glue( e )))
175 BerVarray deref = NULL;
177 rs->sr_matched = ch_strdup( e->e_dn );
178 rs->sr_ref = is_entry_referral( e )
179 ? get_entry_referrals( op, e )
181 bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, e);
185 if ( !LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) {
187 LDAP_STAILQ_FOREACH( si, &op->o_bd->be_syncinfo, si_next ) {
189 ber_dupbv( &tmpbv, &si->si_provideruri_bv[0] );
190 ber_bvarray_add( &deref, &tmpbv );
193 deref = default_referral;
195 rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn,
196 LDAP_SCOPE_DEFAULT );
199 rs->sr_err = LDAP_REFERRAL;
200 send_ldap_result( op, rs );
202 ber_bvarray_free( rs->sr_ref );
203 if ( deref != default_referral ) {
204 ber_bvarray_free( deref );
206 free( (char *)rs->sr_matched );
208 rs->sr_matched = NULL;
213 if ( get_assert( op ) &&
214 ( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
216 rs->sr_err = LDAP_ASSERTION_FAILED;
220 /* check write on old entry */
221 rs->sr_err = access_allowed( op, e, entry, NULL, ACL_WRITE, NULL );
222 if ( ! rs->sr_err ) {
223 switch( opinfo.boi_err ) {
224 case DB_LOCK_DEADLOCK:
225 case DB_LOCK_NOTGRANTED:
229 Debug( LDAP_DEBUG_TRACE, "no access to entry\n", 0,
231 rs->sr_text = "no write access to old entry";
232 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
237 rs->sr_err = bdb_cache_children( op, ltid, e );
238 if ( rs->sr_err != DB_NOTFOUND ) {
239 switch( rs->sr_err ) {
240 case DB_LOCK_DEADLOCK:
241 case DB_LOCK_NOTGRANTED:
244 Debug(LDAP_DEBUG_ARGS,
245 "<=- " LDAP_XSTRING(bdb_modrdn)
247 op->o_req_dn.bv_val, 0, 0);
248 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
249 rs->sr_text = "subtree rename not supported";
252 Debug(LDAP_DEBUG_ARGS,
253 "<=- " LDAP_XSTRING(bdb_modrdn)
254 ": has_children failed: %s (%d)\n",
255 db_strerror(rs->sr_err), rs->sr_err, 0 );
256 rs->sr_err = LDAP_OTHER;
257 rs->sr_text = "internal error";
261 ei->bei_state |= CACHE_ENTRY_NO_KIDS;
264 if (!manageDSAit && is_entry_referral( e ) ) {
265 /* parent is a referral, don't allow add */
266 rs->sr_ref = get_entry_referrals( op, e );
268 Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(bdb_modrdn)
269 ": entry %s is referral\n", e->e_dn, 0, 0 );
271 rs->sr_err = LDAP_REFERRAL,
272 rs->sr_matched = e->e_name.bv_val;
273 send_ldap_result( op, rs );
275 ber_bvarray_free( rs->sr_ref );
277 rs->sr_matched = NULL;
281 if ( be_issuffix( op->o_bd, &e->e_nname ) ) {
282 p_ndn = slap_empty_bv;
284 dnParent( &e->e_nname, &p_ndn );
287 if ( p_ndn.bv_len != 0 ) {
288 /* Make sure parent entry exist and we can write its
291 eip = ei->bei_parent;
292 rs->sr_err = bdb_cache_find_id( op, ltid,
293 eip->bei_id, &eip, 0, locker, &plock );
295 switch( rs->sr_err ) {
299 case DB_LOCK_DEADLOCK:
300 case DB_LOCK_NOTGRANTED:
303 rs->sr_text = "ldap server busy";
306 rs->sr_err = LDAP_OTHER;
307 rs->sr_text = "internal error";
313 Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(bdb_modrdn)
314 ": parent does not exist\n", 0, 0, 0);
315 rs->sr_err = LDAP_OTHER;
316 rs->sr_text = "old entry's parent does not exist";
320 /* check parent for "children" acl */
321 rs->sr_err = access_allowed( op, p,
322 children, NULL, ACL_WRITE, NULL );
324 if ( ! rs->sr_err ) {
325 switch( opinfo.boi_err ) {
326 case DB_LOCK_DEADLOCK:
327 case DB_LOCK_NOTGRANTED:
331 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
332 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
334 rs->sr_text = "no write access to old parent's children";
338 Debug( LDAP_DEBUG_TRACE,
339 LDAP_XSTRING(bdb_modrdn) ": wr to children "
340 "of entry %s OK\n", p_ndn.bv_val, 0, 0 );
342 if ( p_ndn.bv_val == slap_empty_bv.bv_val ) {
343 p_dn = slap_empty_bv;
345 dnParent( &e->e_name, &p_dn );
348 Debug( LDAP_DEBUG_TRACE,
349 LDAP_XSTRING(bdb_modrdn) ": parent dn=%s\n",
353 /* no parent, modrdn entry directly under root */
354 isroot = be_isroot( op );
356 if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv )
357 || be_shadow_update( op ) ) {
359 p = (Entry *)&slap_entry_root;
361 /* check parent for "children" acl */
362 rs->sr_err = access_allowed( op, p,
363 children, NULL, ACL_WRITE, NULL );
367 if ( ! rs->sr_err ) {
368 switch( opinfo.boi_err ) {
369 case DB_LOCK_DEADLOCK:
370 case DB_LOCK_NOTGRANTED:
374 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
375 Debug( LDAP_DEBUG_TRACE,
376 "no access to parent\n",
378 rs->sr_text = "no write access to old parent";
382 Debug( LDAP_DEBUG_TRACE,
383 LDAP_XSTRING(bdb_modrdn)
384 ": wr to children of entry \"\" OK\n",
390 Debug( LDAP_DEBUG_TRACE,
391 LDAP_XSTRING(bdb_modrdn)
392 ": parent dn=\"\"\n",
396 Debug( LDAP_DEBUG_TRACE,
397 LDAP_XSTRING(bdb_modrdn)
398 ": no parent, not root "
399 "& \"\" is not suffix\n",
401 rs->sr_text = "no write access to old parent";
402 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
408 new_parent_dn = &p_dn; /* New Parent unless newSuperior given */
410 if ( op->oq_modrdn.rs_newSup != NULL ) {
411 Debug( LDAP_DEBUG_TRACE,
412 LDAP_XSTRING(bdb_modrdn)
413 ": new parent \"%s\" requested...\n",
414 op->oq_modrdn.rs_newSup->bv_val, 0, 0 );
416 /* newSuperior == oldParent? */
417 if( dn_match( &p_ndn, op->oq_modrdn.rs_nnewSup ) ) {
418 Debug( LDAP_DEBUG_TRACE, "bdb_back_modrdn: "
419 "new parent \"%s\" same as the old parent \"%s\"\n",
420 op->oq_modrdn.rs_newSup->bv_val, p_dn.bv_val, 0 );
421 op->oq_modrdn.rs_newSup = NULL; /* ignore newSuperior */
425 if ( op->oq_modrdn.rs_newSup != NULL ) {
426 if ( op->oq_modrdn.rs_newSup->bv_len ) {
427 np_dn = op->oq_modrdn.rs_newSup;
428 np_ndn = op->oq_modrdn.rs_nnewSup;
430 /* newSuperior == oldParent?, if so ==> ERROR */
431 /* newSuperior == entry being moved?, if so ==> ERROR */
432 /* Get Entry with dn=newSuperior. Does newSuperior exist? */
434 rs->sr_err = bdb_dn2entry( op, ltid, np_ndn,
435 &neip, 0, locker, &nplock );
437 switch( rs->sr_err ) {
438 case 0: np = neip->bei_e;
441 case DB_LOCK_DEADLOCK:
442 case DB_LOCK_NOTGRANTED:
445 rs->sr_text = "ldap server busy";
448 rs->sr_err = LDAP_OTHER;
449 rs->sr_text = "internal error";
454 Debug( LDAP_DEBUG_TRACE,
455 LDAP_XSTRING(bdb_modrdn)
456 ": newSup(ndn=%s) not here!\n",
457 np_ndn->bv_val, 0, 0);
458 rs->sr_text = "new superior not found";
459 rs->sr_err = LDAP_OTHER;
463 Debug( LDAP_DEBUG_TRACE,
464 LDAP_XSTRING(bdb_modrdn)
465 ": wr to new parent OK np=%p, id=%ld\n",
466 (void *) np, (long) np->e_id, 0 );
468 /* check newSuperior for "children" acl */
469 rs->sr_err = access_allowed( op, np, children,
470 NULL, ACL_WRITE, NULL );
473 switch( opinfo.boi_err ) {
474 case DB_LOCK_DEADLOCK:
475 case DB_LOCK_NOTGRANTED:
479 Debug( LDAP_DEBUG_TRACE,
480 LDAP_XSTRING(bdb_modrdn)
481 ": no wr to newSup children\n",
483 rs->sr_text = "no write access to new superior's children";
484 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
488 if ( is_entry_alias( np ) ) {
489 /* parent is an alias, don't allow add */
490 Debug( LDAP_DEBUG_TRACE,
491 LDAP_XSTRING(bdb_modrdn)
492 ": entry is alias\n",
494 rs->sr_text = "new superior is an alias";
495 rs->sr_err = LDAP_ALIAS_PROBLEM;
499 if ( is_entry_referral( np ) ) {
500 /* parent is a referral, don't allow add */
501 Debug( LDAP_DEBUG_TRACE,
502 LDAP_XSTRING(bdb_modrdn)
503 ": entry is referral\n",
505 rs->sr_text = "new superior is a referral";
506 rs->sr_err = LDAP_OTHER;
511 if ( isroot == -1 ) {
512 isroot = be_isroot( op );
517 /* no parent, modrdn entry directly under root */
519 if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv )
520 || be_isupdate( op ) ) {
521 np = (Entry *)&slap_entry_root;
523 /* check parent for "children" acl */
524 rs->sr_err = access_allowed( op, np,
525 children, NULL, ACL_WRITE, NULL );
529 if ( ! rs->sr_err ) {
530 switch( opinfo.boi_err ) {
531 case DB_LOCK_DEADLOCK:
532 case DB_LOCK_NOTGRANTED:
536 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
537 Debug( LDAP_DEBUG_TRACE,
538 "no access to new superior\n",
541 "no write access to new superior's children";
545 Debug( LDAP_DEBUG_TRACE,
546 LDAP_XSTRING(bdb_modrdn)
548 "of entry \"\" OK\n",
552 Debug( LDAP_DEBUG_TRACE,
553 LDAP_XSTRING(bdb_modrdn)
554 ": new superior=\"\", not root "
555 "& \"\" is not suffix\n",
557 rs->sr_text = "no write access to new superior's children";
558 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
563 Debug( LDAP_DEBUG_TRACE,
564 LDAP_XSTRING(bdb_modrdn)
565 ": new superior=\"\"\n",
569 Debug( LDAP_DEBUG_TRACE,
570 LDAP_XSTRING(bdb_modrdn)
571 ": wr to new parent's children OK\n",
574 new_parent_dn = np_dn;
577 /* Build target dn and make sure target entry doesn't exist already. */
578 if (!new_dn.bv_val) {
579 build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn, NULL );
582 if (!new_ndn.bv_val) {
583 struct berval bv = {0, NULL};
584 dnNormalize( 0, NULL, NULL, &new_dn, &bv, op->o_tmpmemctx );
585 ber_dupbv( &new_ndn, &bv );
588 Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(bdb_modrdn) ": new ndn=%s\n",
589 new_ndn.bv_val, 0, 0 );
591 /* Shortcut the search */
592 nei = neip ? neip : eip;
593 rs->sr_err = bdb_cache_find_ndn ( op, ltid, &new_ndn, &nei );
594 if ( nei ) bdb_cache_entryinfo_unlock( nei );
595 switch( rs->sr_err ) {
596 case DB_LOCK_DEADLOCK:
597 case DB_LOCK_NOTGRANTED:
602 rs->sr_err = LDAP_ALREADY_EXISTS;
605 rs->sr_err = LDAP_OTHER;
606 rs->sr_text = "internal error";
610 /* Get attribute type and attribute value of our new rdn, we will
611 * need to add that to our new entry
613 if ( !new_rdn && ldap_bv2rdn_x( &op->oq_modrdn.rs_newrdn, &new_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 "type(s)/values(s) of newrdn\n",
620 rs->sr_err = LDAP_INVALID_DN_SYNTAX;
621 rs->sr_text = "unknown type(s) used in RDN";
625 Debug( LDAP_DEBUG_TRACE,
626 LDAP_XSTRING(bdb_modrdn)
627 ": new_rdn_type=\"%s\", new_rdn_val=\"%s\"\n",
628 new_rdn[ 0 ]->la_attr.bv_val,
629 new_rdn[ 0 ]->la_value.bv_val, 0 );
631 if ( op->oq_modrdn.rs_deleteoldrdn ) {
632 if ( !old_rdn && ldap_bv2rdn_x( &op->o_req_dn, &old_rdn,
633 (char **)&rs->sr_text, LDAP_DN_FORMAT_LDAP, op->o_tmpmemctx ) )
635 Debug( LDAP_DEBUG_TRACE,
636 LDAP_XSTRING(bdb_modrdn) ": can't figure out "
637 "the old_rdn type(s)/value(s)\n",
639 rs->sr_err = LDAP_OTHER;
640 rs->sr_text = "cannot parse RDN from old DN";
645 /* prepare modlist of modifications from old/new rdn */
647 rs->sr_err = slap_modrdn2mods( op, rs, e, old_rdn, new_rdn, &mod );
648 if ( rs->sr_err != LDAP_SUCCESS ) {
653 if( op->o_preread ) {
654 if( preread_ctrl == NULL ) {
655 preread_ctrl = &ctrls[num_ctrls++];
656 ctrls[num_ctrls] = NULL;
658 if( slap_read_controls( op, rs, e,
659 &slap_pre_read_bv, preread_ctrl ) )
661 Debug( LDAP_DEBUG_TRACE,
662 "<=- " LDAP_XSTRING(bdb_modrdn)
663 ": post-read failed!\n", 0, 0, 0 );
668 /* nested transaction */
669 rs->sr_err = TXN_BEGIN( bdb->bi_dbenv, ltid, <2, bdb->bi_db_opflags );
671 if( rs->sr_err != 0 ) {
672 Debug( LDAP_DEBUG_TRACE,
673 LDAP_XSTRING(bdb_modrdn)
674 ": txn_begin(2) failed: %s (%d)\n",
675 db_strerror(rs->sr_err), rs->sr_err, 0 );
676 rs->sr_err = LDAP_OTHER;
677 rs->sr_text = "internal error";
682 rs->sr_err = bdb_dn2id_delete( op, lt2, eip, e );
683 if ( rs->sr_err != 0 ) {
684 Debug(LDAP_DEBUG_TRACE,
685 "<=- " LDAP_XSTRING(bdb_modrdn)
686 ": dn2id del failed: %s (%d)\n",
687 db_strerror(rs->sr_err), rs->sr_err, 0 );
688 switch( rs->sr_err ) {
689 case DB_LOCK_DEADLOCK:
690 case DB_LOCK_NOTGRANTED:
693 rs->sr_err = LDAP_OTHER;
694 rs->sr_text = "DN index delete fail";
698 /* copy the entry, then override some fields */
700 dummy.e_name = new_dn;
701 dummy.e_nname = new_ndn;
702 dummy.e_attrs = NULL;
705 rs->sr_err = bdb_dn2id_add( op, lt2, neip ? neip : eip, &dummy );
706 if ( rs->sr_err != 0 ) {
707 Debug(LDAP_DEBUG_TRACE,
708 "<=- " LDAP_XSTRING(bdb_modrdn)
709 ": dn2id add failed: %s (%d)\n",
710 db_strerror(rs->sr_err), rs->sr_err, 0 );
711 switch( rs->sr_err ) {
712 case DB_LOCK_DEADLOCK:
713 case DB_LOCK_NOTGRANTED:
716 rs->sr_err = LDAP_OTHER;
717 rs->sr_text = "DN index add failed";
721 dummy.e_attrs = e->e_attrs;
724 if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop && !op->o_no_psearch ) {
725 ldap_pvt_thread_rdwr_wlock( &bdb->bi_pslist_rwlock );
726 LDAP_LIST_FOREACH ( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
727 rc = bdb_psearch( op, rs, ps_list, &dummy, LDAP_PSEARCH_BY_PREMODIFY );
729 Debug( LDAP_DEBUG_TRACE,
730 LDAP_XSTRING(bdb_modrdn)
731 ": persistent search failed (%d,%d)\n",
735 ldap_pvt_thread_rdwr_wunlock( &bdb->bi_pslist_rwlock );
741 rs->sr_err = bdb_modify_internal( op, lt2, &mod[0], &dummy,
742 &rs->sr_text, textbuf, textlen );
743 if( rs->sr_err != LDAP_SUCCESS ) {
744 Debug(LDAP_DEBUG_TRACE,
745 "<=- " LDAP_XSTRING(bdb_modrdn)
746 ": modify failed: %s (%d)\n",
747 db_strerror(rs->sr_err), rs->sr_err, 0 );
748 if ( ( rs->sr_err == LDAP_INSUFFICIENT_ACCESS ) && opinfo.boi_err ) {
749 rs->sr_err = opinfo.boi_err;
751 if ( dummy.e_attrs == e->e_attrs ) dummy.e_attrs = NULL;
752 switch( rs->sr_err ) {
753 case DB_LOCK_DEADLOCK:
754 case DB_LOCK_NOTGRANTED:
761 rs->sr_err = bdb_id2entry_update( op->o_bd, lt2, &dummy );
762 if ( rs->sr_err != 0 ) {
763 Debug(LDAP_DEBUG_TRACE,
764 "<=- " LDAP_XSTRING(bdb_modrdn)
765 ": id2entry failed: %s (%d)\n",
766 db_strerror(rs->sr_err), rs->sr_err, 0 );
767 switch( rs->sr_err ) {
768 case DB_LOCK_DEADLOCK:
769 case DB_LOCK_NOTGRANTED:
772 rs->sr_err = LDAP_OTHER;
773 rs->sr_text = "entry update failed";
777 if ( p_ndn.bv_len != 0 ) {
778 parent_is_glue = is_entry_glue(p);
779 rs->sr_err = bdb_cache_children( op, lt2, p );
780 if ( rs->sr_err != DB_NOTFOUND ) {
781 switch( rs->sr_err ) {
782 case DB_LOCK_DEADLOCK:
783 case DB_LOCK_NOTGRANTED:
788 Debug(LDAP_DEBUG_ARGS,
789 "<=- " LDAP_XSTRING(bdb_modrdn)
790 ": has_children failed: %s (%d)\n",
791 db_strerror(rs->sr_err), rs->sr_err, 0 );
792 rs->sr_err = LDAP_OTHER;
793 rs->sr_text = "internal error";
798 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, p);
802 if ( TXN_COMMIT( lt2, 0 ) != 0 ) {
803 rs->sr_err = LDAP_OTHER;
804 rs->sr_text = "txn_commit(2) failed";
809 if ( LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) {
810 rc = bdb_csn_commit( op, rs, ltid, ei, &suffix_ei,
811 &ctxcsn_e, &ctxcsn_added, locker );
821 if( op->o_postread ) {
822 if( postread_ctrl == NULL ) {
823 postread_ctrl = &ctrls[num_ctrls++];
824 ctrls[num_ctrls] = NULL;
826 if( slap_read_controls( op, rs, &dummy,
827 &slap_post_read_bv, postread_ctrl ) )
829 Debug( LDAP_DEBUG_TRACE,
830 "<=- " LDAP_XSTRING(bdb_modrdn)
831 ": post-read failed!\n", 0, 0, 0 );
837 if(( rs->sr_err=TXN_ABORT( ltid )) != 0 ) {
838 rs->sr_text = "txn_abort (no-op) failed";
840 rs->sr_err = LDAP_SUCCESS;
845 rc = bdb_cache_modrdn( e, &op->orr_nnewrdn, &dummy, neip,
846 bdb->bi_dbenv, locker, &lock );
848 case DB_LOCK_DEADLOCK:
849 case DB_LOCK_NOTGRANTED:
852 dummy.e_attrs = NULL;
853 new_dn.bv_val = NULL;
854 new_ndn.bv_val = NULL;
857 if ( LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) {
858 if ( ctxcsn_added ) {
859 bdb_cache_add( bdb, suffix_ei, ctxcsn_e,
860 (struct berval *)&slap_ldapsync_cn_bv, locker );
864 if ( rs->sr_err == LDAP_SUCCESS ) {
865 /* Loop through in-scope entries for each psearch spec */
866 ldap_pvt_thread_rdwr_wlock( &bdb->bi_pslist_rwlock );
867 LDAP_LIST_FOREACH ( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
868 rc = bdb_psearch( op, rs, ps_list, e, LDAP_PSEARCH_BY_MODIFY );
870 Debug( LDAP_DEBUG_TRACE,
871 LDAP_XSTRING(bdb_modrdn)
872 ": persistent search failed "
877 pm_list = LDAP_LIST_FIRST(&op->o_pm_list);
878 while ( pm_list != NULL ) {
879 rc = bdb_psearch(op, rs, pm_list->ps_op,
880 e, LDAP_PSEARCH_BY_SCOPEOUT);
882 Debug( LDAP_DEBUG_TRACE,
883 LDAP_XSTRING(bdb_modrdn)
884 ": persistent search failed "
889 LDAP_LIST_REMOVE ( pm_list, ps_link );
890 pm_list = LDAP_LIST_NEXT ( pm_list, ps_link );
893 ldap_pvt_thread_rdwr_wunlock( &bdb->bi_pslist_rwlock );
897 if(( rs->sr_err=TXN_COMMIT( ltid, 0 )) != 0 ) {
898 rs->sr_text = "txn_commit failed";
900 rs->sr_err = LDAP_SUCCESS;
905 op->o_private = NULL;
907 if( rs->sr_err != LDAP_SUCCESS ) {
908 Debug( LDAP_DEBUG_TRACE,
909 LDAP_XSTRING(bdb_modrdn) ": %s : %s (%d)\n",
910 rs->sr_text, db_strerror(rs->sr_err), rs->sr_err );
911 rs->sr_err = LDAP_OTHER;
916 Debug(LDAP_DEBUG_TRACE,
917 LDAP_XSTRING(bdb_modrdn)
918 ": rdn modified%s id=%08lx dn=\"%s\"\n",
919 op->o_noop ? " (no-op)" : "",
920 dummy.e_id, op->o_req_dn.bv_val );
922 if( num_ctrls ) rs->sr_ctrls = ctrls;
925 if ( dummy.e_attrs ) {
926 attrs_free( dummy.e_attrs );
928 send_ldap_result( op, rs );
930 if( rs->sr_err == LDAP_SUCCESS && bdb->bi_txn_cp ) {
931 ldap_pvt_thread_yield();
932 TXN_CHECKPOINT( bdb->bi_dbenv,
933 bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
936 if ( rs->sr_err == LDAP_SUCCESS && parent_is_glue && parent_is_leaf ) {
937 op->o_delete_glue_parent = 1;
941 if( new_dn.bv_val != NULL ) free( new_dn.bv_val );
942 if( new_ndn.bv_val != NULL ) free( new_ndn.bv_val );
944 /* LDAP v2 supporting correct attribute handling. */
945 if ( new_rdn != NULL ) {
946 ldap_rdnfree_x( new_rdn, op->o_tmpmemctx );
948 if ( old_rdn != NULL ) {
949 ldap_rdnfree_x( old_rdn, op->o_tmpmemctx );
953 for (; mod; mod=tmp ) {
955 /* slap_modrdn2mods does things one way,
956 * slap_mods_opattrs does it differently
958 if ( mod->sml_op != SLAP_MOD_SOFTADD &&
959 mod->sml_op != LDAP_MOD_DELETE ) break;
960 if ( mod->sml_nvalues ) free( mod->sml_nvalues[0].bv_val );
963 slap_mods_free( mod );
966 /* LDAP v3 Support */
968 /* free new parent and reader lock */
969 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, np);
973 /* free parent and reader lock */
974 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, p);
979 bdb_unlocked_cache_return_entry_w( &bdb->bi_cache, e);
984 pm_list = LDAP_LIST_FIRST(&op->o_pm_list);
985 while ( pm_list != NULL ) {
986 LDAP_LIST_REMOVE ( pm_list, ps_link );
988 pm_list = LDAP_LIST_NEXT ( pm_list, ps_link );
993 op->o_private = NULL;
996 if( preread_ctrl != NULL ) {
997 slap_sl_free( (*preread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
998 slap_sl_free( *preread_ctrl, op->o_tmpmemctx );
1000 if( postread_ctrl != NULL ) {
1001 slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
1002 slap_sl_free( *postread_ctrl, op->o_tmpmemctx );