1 /* modrdn.c - bdb backend modrdn routine */
4 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
17 bdb_modrdn( Operation *op, SlapReply *rs )
19 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
20 AttributeDescription *children = slap_schema.si_ad_children;
21 AttributeDescription *entry = slap_schema.si_ad_entry;
22 struct berval p_dn, p_ndn;
23 struct berval new_dn = {0, NULL}, new_ndn = {0, NULL};
28 /* LDAP v2 supporting correct attribute handling. */
29 LDAPRDN *new_rdn = NULL;
30 LDAPRDN *old_rdn = NULL;
31 char textbuf[SLAP_TEXT_BUFLEN];
32 size_t textlen = sizeof textbuf;
34 struct bdb_op_info opinfo;
38 Entry *np = NULL; /* newSuperior Entry */
39 struct berval *np_dn = NULL; /* newSuperior dn */
40 struct berval *np_ndn = NULL; /* newSuperior ndn */
41 struct berval *new_parent_dn = NULL; /* np_dn, p_dn, or NULL */
43 /* Used to interface with bdb_modify_internal() */
44 Modifications *mod = NULL; /* Used to delete old rdn */
46 int manageDSAit = get_manageDSAit( op );
53 #if defined(LDAP_CLIENT_UPDATE) || defined(LDAP_SYNC)
55 struct psid_entry *pm_list, *pm_prev;
59 LDAP_LOG ( OPERATION, ENTRY, "==>bdb_modrdn(%s,%s,%s)\n",
60 op->o_req_dn.bv_val,op->oq_modrdn.rs_newrdn.bv_val,
61 op->oq_modrdn.rs_newSup ? op->oq_modrdn.rs_newSup->bv_val : "NULL" );
63 Debug( LDAP_DEBUG_TRACE, "==>bdb_modrdn(%s,%s,%s)\n",
64 op->o_req_dn.bv_val,op->oq_modrdn.rs_newrdn.bv_val,
65 op->oq_modrdn.rs_newSup ? op->oq_modrdn.rs_newSup->bv_val : "NULL" );
69 retry: /* transaction retry */
71 bdb_cache_delete_entry(&bdb->bi_cache, e);
72 bdb_unlocked_cache_return_entry_w(&bdb->bi_cache, e);
76 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, p);
80 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, np);
84 LDAP_LOG ( OPERATION, DETAIL1, "==>bdb_modrdn: retrying...\n", 0, 0, 0);
86 Debug( LDAP_DEBUG_TRACE, "==>bdb_modrdn: retrying...\n", 0, 0, 0 );
89 #if defined(LDAP_CLIENT_UPDATE) || defined(LDAP_SYNC)
90 pm_list = LDAP_LIST_FIRST(&op->o_pm_list);
91 while ( pm_list != NULL ) {
92 LDAP_LIST_REMOVE ( pm_list, ps_link );
94 pm_list = LDAP_LIST_NEXT ( pm_list, ps_link );
99 rs->sr_err = TXN_ABORT( ltid );
101 op->o_private = NULL;
102 op->o_do_not_cache = opinfo.boi_acl_cache;
103 if( rs->sr_err != 0 ) {
104 rs->sr_err = LDAP_OTHER;
105 rs->sr_text = "internal error";
108 ldap_pvt_thread_yield();
111 /* begin transaction */
112 rs->sr_err = TXN_BEGIN( bdb->bi_dbenv, NULL, <id,
113 bdb->bi_db_opflags );
115 if( rs->sr_err != 0 ) {
117 LDAP_LOG ( OPERATION, ERR,
118 "==>bdb_modrdn: txn_begin failed: %s (%d)\n",
119 db_strerror(rs->sr_err), rs->sr_err, 0 );
121 Debug( LDAP_DEBUG_TRACE,
122 "bdb_delete: txn_begin failed: %s (%d)\n",
123 db_strerror(rs->sr_err), rs->sr_err, 0 );
125 rs->sr_err = LDAP_OTHER;
126 rs->sr_text = "internal error";
130 locker = TXN_ID ( ltid );
132 opinfo.boi_bdb = op->o_bd;
133 opinfo.boi_txn = ltid;
134 opinfo.boi_locker = locker;
136 opinfo.boi_acl_cache = op->o_do_not_cache;
137 op->o_private = &opinfo;
140 rs->sr_err = bdb_dn2entry_w( op->o_bd, ltid, &op->o_req_ndn, &e, &matched, DB_RMW, locker, &lock );
142 switch( rs->sr_err ) {
146 case DB_LOCK_DEADLOCK:
147 case DB_LOCK_NOTGRANTED:
150 rs->sr_text = "ldap server busy";
153 rs->sr_err = LDAP_OTHER;
154 rs->sr_text = "internal error";
159 if( matched != NULL ) {
160 rs->sr_matched = ch_strdup( matched->e_dn );
161 rs->sr_ref = is_entry_referral( matched )
162 ? get_entry_referrals( op, matched )
164 bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, matched);
168 rs->sr_ref = referral_rewrite( default_referral,
169 NULL, &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 /* check write on old entry */
184 rs->sr_err = access_allowed( op, e, entry, NULL, ACL_WRITE, NULL );
186 if ( ! rs->sr_err ) {
187 switch( opinfo.boi_err ) {
188 case DB_LOCK_DEADLOCK:
189 case DB_LOCK_NOTGRANTED:
194 LDAP_LOG ( OPERATION, ERR,
195 "==>bdb_modrdn: no access to entry\n", 0, 0, 0 );
197 Debug( LDAP_DEBUG_TRACE, "no access to entry\n", 0,
200 rs->sr_text = "no write access to old entry";
201 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
206 rs->sr_err = bdb_dn2id_children( op->o_bd, ltid, &e->e_nname, 0 );
207 if ( rs->sr_err != DB_NOTFOUND ) {
208 switch( rs->sr_err ) {
209 case DB_LOCK_DEADLOCK:
210 case DB_LOCK_NOTGRANTED:
214 LDAP_LOG ( OPERATION, DETAIL1,
215 "<=- bdb_modrdn: non-leaf %s\n", op->o_req_dn.bv_val, 0, 0 );
217 Debug(LDAP_DEBUG_ARGS,
218 "<=- bdb_modrdn: non-leaf %s\n",
219 op->o_req_dn.bv_val, 0, 0);
221 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
222 rs->sr_text = "subtree rename not supported";
226 LDAP_LOG ( OPERATION, ERR,
227 "<=- bdb_modrdn: has_children failed %s (%d)\n",
228 db_strerror(rs->sr_err), rs->sr_err, 0 );
230 Debug(LDAP_DEBUG_ARGS,
231 "<=- bdb_modrdn: has_children failed: %s (%d)\n",
232 db_strerror(rs->sr_err), rs->sr_err, 0 );
234 rs->sr_err = LDAP_OTHER;
235 rs->sr_text = "internal error";
240 if (!manageDSAit && is_entry_referral( e ) ) {
241 /* parent is a referral, don't allow add */
242 rs->sr_ref = get_entry_referrals( op, e );
245 LDAP_LOG ( OPERATION, DETAIL1,
246 "==>bdb_modrdn: entry %s is referral \n", e->e_dn, 0, 0 );
248 Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: entry %s is referral\n",
252 rs->sr_err = LDAP_REFERRAL,
253 rs->sr_matched = e->e_name.bv_val;
254 send_ldap_result( op, rs );
256 ber_bvarray_free( rs->sr_ref );
258 rs->sr_matched = NULL;
262 if ( be_issuffix( op->o_bd, &e->e_nname ) ) {
263 p_ndn = slap_empty_bv;
265 dnParent( &e->e_nname, &p_ndn );
268 if ( p_ndn.bv_len != 0 ) {
269 /* Make sure parent entry exist and we can write its
272 rs->sr_err = bdb_dn2entry_r( op->o_bd, ltid, &p_ndn, &p, NULL, 0, locker, &lock );
274 switch( rs->sr_err ) {
278 case DB_LOCK_DEADLOCK:
279 case DB_LOCK_NOTGRANTED:
282 rs->sr_text = "ldap server busy";
285 rs->sr_err = LDAP_OTHER;
286 rs->sr_text = "internal error";
292 LDAP_LOG ( OPERATION, ERR,
293 "==>bdb_modrdn: parent does not exist\n", 0, 0, 0 );
295 Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: parent does not exist\n",
298 rs->sr_err = LDAP_OTHER;
299 rs->sr_text = "old entry's parent does not exist";
303 /* check parent for "children" acl */
304 rs->sr_err = access_allowed( op, p,
305 children, NULL, ACL_WRITE, NULL );
307 if ( ! rs->sr_err ) {
308 switch( opinfo.boi_err ) {
309 case DB_LOCK_DEADLOCK:
310 case DB_LOCK_NOTGRANTED:
314 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
316 LDAP_LOG ( OPERATION, ERR,
317 "==>bdb_modrdn: no access to parent\n", 0, 0, 0 );
319 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
322 rs->sr_text = "no write access to old parent's children";
327 LDAP_LOG ( OPERATION, DETAIL1,
328 "==>bdb_modrdn: wr to children %s is OK\n", p_ndn.bv_val, 0, 0 );
330 Debug( LDAP_DEBUG_TRACE,
331 "bdb_modrdn: wr to children of entry %s OK\n",
332 p_ndn.bv_val, 0, 0 );
335 if ( p_ndn.bv_val == slap_empty_bv.bv_val ) {
336 p_dn = slap_empty_bv;
338 dnParent( &e->e_name, &p_dn );
342 LDAP_LOG ( OPERATION, DETAIL1,
343 "==>bdb_modrdn: parent dn=%s\n", p_dn.bv_val, 0, 0 );
345 Debug( LDAP_DEBUG_TRACE,
346 "bdb_modrdn: parent dn=%s\n",
351 /* no parent, modrdn entry directly under root */
352 isroot = be_isroot( op->o_bd, &op->o_ndn );
354 if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv )
355 || be_isupdate( op->o_bd, &op->o_ndn ) ) {
357 p = (Entry *)&slap_entry_root;
359 /* check parent for "children" acl */
360 rs->sr_err = access_allowed( op, p,
361 children, NULL, ACL_WRITE, NULL );
365 if ( ! rs->sr_err ) {
366 switch( opinfo.boi_err ) {
367 case DB_LOCK_DEADLOCK:
368 case DB_LOCK_NOTGRANTED:
372 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
374 LDAP_LOG ( OPERATION, ERR,
375 "==>bdb_modrdn: no access to parent\n", 0, 0, 0 );
377 Debug( LDAP_DEBUG_TRACE,
378 "no access to parent\n",
381 rs->sr_text = "no write access to old parent";
386 LDAP_LOG ( OPERATION, DETAIL1,
387 "==>bdb_modrdn: wr to children of entry \"%s\" OK\n",
390 Debug( LDAP_DEBUG_TRACE,
391 "bdb_modrdn: wr to children of entry \"\" OK\n",
399 LDAP_LOG ( OPERATION, DETAIL1,
400 "==>bdb_modrdn: parent dn=\"\" \n", 0, 0, 0 );
402 Debug( LDAP_DEBUG_TRACE,
403 "bdb_modrdn: parent dn=\"\"\n",
409 LDAP_LOG ( OPERATION, ERR,
410 "==>bdb_modrdn: no parent, not root &\"\" is not "
411 "suffix\n", 0, 0, 0 );
413 Debug( LDAP_DEBUG_TRACE,
414 "bdb_modrdn: no parent, not root "
415 "& \"\" is not suffix\n",
418 rs->sr_text = "no write access to old parent";
419 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
425 new_parent_dn = &p_dn; /* New Parent unless newSuperior given */
427 if ( op->oq_modrdn.rs_newSup != NULL ) {
429 LDAP_LOG ( OPERATION, DETAIL1,
430 "==>bdb_modrdn: new parent \"%s\" requested...\n",
431 op->oq_modrdn.rs_newSup->bv_val, 0, 0 );
433 Debug( LDAP_DEBUG_TRACE,
434 "bdb_modrdn: new parent \"%s\" requested...\n",
435 op->oq_modrdn.rs_newSup->bv_val, 0, 0 );
438 /* newSuperior == oldParent? */
439 if( dn_match( &p_ndn, op->oq_modrdn.rs_nnewSup ) ) {
441 LDAP_LOG( BACK_BDB, INFO, "bdb_back_modrdn: "
442 "new parent \"%s\" same as the old parent \"%s\"\n",
443 op->oq_modrdn.rs_newSup->bv_val, p_dn.bv_val, 0 );
445 Debug( LDAP_DEBUG_TRACE, "bdb_back_modrdn: "
446 "new parent \"%s\" same as the old parent \"%s\"\n",
447 op->oq_modrdn.rs_newSup->bv_val, p_dn.bv_val, 0 );
449 op->oq_modrdn.rs_newSup = NULL; /* ignore newSuperior */
453 if ( op->oq_modrdn.rs_newSup != NULL ) {
454 if ( op->oq_modrdn.rs_newSup->bv_len ) {
455 np_dn = op->oq_modrdn.rs_newSup;
456 np_ndn = op->oq_modrdn.rs_nnewSup;
458 /* newSuperior == oldParent?, if so ==> ERROR */
459 /* newSuperior == entry being moved?, if so ==> ERROR */
460 /* Get Entry with dn=newSuperior. Does newSuperior exist? */
462 rs->sr_err = bdb_dn2entry_r( op->o_bd,
463 ltid, np_ndn, &np, NULL, 0, locker, &lock );
465 switch( rs->sr_err ) {
469 case DB_LOCK_DEADLOCK:
470 case DB_LOCK_NOTGRANTED:
473 rs->sr_text = "ldap server busy";
476 rs->sr_err = LDAP_OTHER;
477 rs->sr_text = "internal error";
483 LDAP_LOG ( OPERATION, DETAIL1,
484 "==>bdb_modrdn: newSup(ndn=%s) not here!\n",
485 np_ndn->bv_val, 0, 0 );
487 Debug( LDAP_DEBUG_TRACE,
488 "bdb_modrdn: newSup(ndn=%s) not here!\n",
489 np_ndn->bv_val, 0, 0);
491 rs->sr_text = "new superior not found";
492 rs->sr_err = LDAP_OTHER;
497 LDAP_LOG ( OPERATION, DETAIL1,
498 "==>bdb_modrdn: wr to new parent OK np=%p, id=%ld\n",
499 np, (long) np->e_id, 0 );
501 Debug( LDAP_DEBUG_TRACE,
502 "bdb_modrdn: wr to new parent OK np=%p, id=%ld\n",
503 np, (long) np->e_id, 0 );
506 /* check newSuperior for "children" acl */
507 rs->sr_err = access_allowed( op, np, children,
508 NULL, ACL_WRITE, NULL );
511 switch( opinfo.boi_err ) {
512 case DB_LOCK_DEADLOCK:
513 case DB_LOCK_NOTGRANTED:
518 LDAP_LOG ( OPERATION, DETAIL1,
519 "==>bdb_modrdn: no wr to newSup children\n", 0, 0, 0 );
521 Debug( LDAP_DEBUG_TRACE,
522 "bdb_modrdn: no wr to newSup children\n",
525 rs->sr_text = "no write access to new superior's children";
526 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
531 if ( is_entry_alias( np ) ) {
532 /* parent is an alias, don't allow add */
534 LDAP_LOG ( OPERATION, DETAIL1,
535 "==>bdb_modrdn: entry is alias\n", 0, 0, 0 );
537 Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: entry is alias\n",
540 rs->sr_text = "new superior is an alias";
541 rs->sr_err = LDAP_ALIAS_PROBLEM;
546 if ( is_entry_referral( np ) ) {
547 /* parent is a referral, don't allow add */
549 LDAP_LOG ( OPERATION, DETAIL1,
550 "==>bdb_modrdn: entry is referral\n", 0, 0, 0 );
552 Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: entry is referral\n",
555 rs->sr_text = "new superior is a referral";
556 rs->sr_err = LDAP_OTHER;
561 if ( isroot == -1 ) {
562 isroot = be_isroot( op->o_bd, &op->o_ndn );
567 /* no parent, modrdn entry directly under root */
569 if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv )
570 || be_isupdate( op->o_bd, &op->o_ndn ) ) {
571 np = (Entry *)&slap_entry_root;
573 /* check parent for "children" acl */
574 rs->sr_err = access_allowed( op, np,
575 children, NULL, ACL_WRITE, NULL );
579 if ( ! rs->sr_err ) {
580 switch( opinfo.boi_err ) {
581 case DB_LOCK_DEADLOCK:
582 case DB_LOCK_NOTGRANTED:
586 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
588 LDAP_LOG ( OPERATION, ERR,
589 "==>bdb_modrdn: no access to superior\n", 0, 0, 0 );
591 Debug( LDAP_DEBUG_TRACE,
592 "no access to new superior\n",
595 rs->sr_text = "no write access to new superior's children";
600 LDAP_LOG ( OPERATION, DETAIL1,
601 "bdb_modrdn: wr to children entry \"\" OK\n", 0, 0, 0 );
603 Debug( LDAP_DEBUG_TRACE,
604 "bdb_modrdn: wr to children of entry \"\" OK\n",
610 LDAP_LOG ( OPERATION, ERR,
611 "bdb_modrdn: new superior=\"\", not root & \"\" "
612 "is not suffix\n", 0, 0, 0 );
614 Debug( LDAP_DEBUG_TRACE,
615 "bdb_modrdn: new superior=\"\", not root "
616 "& \"\" is not suffix\n",
619 rs->sr_text = "no write access to new superior's children";
620 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
626 LDAP_LOG ( OPERATION, DETAIL1,
627 "bdb_modrdn: new superior=\"\"\n", 0, 0, 0 );
629 Debug( LDAP_DEBUG_TRACE,
630 "bdb_modrdn: new superior=\"\"\n",
636 LDAP_LOG ( OPERATION, DETAIL1,
637 "bdb_modrdn: wr to new parent's children OK\n", 0, 0, 0 );
639 Debug( LDAP_DEBUG_TRACE,
640 "bdb_modrdn: wr to new parent's children OK\n",
644 new_parent_dn = np_dn;
647 /* Build target dn and make sure target entry doesn't exist already. */
648 if (!new_dn.bv_val) build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn );
650 if (!new_ndn.bv_val) dnNormalize2( NULL, &new_dn, &new_ndn );
653 LDAP_LOG ( OPERATION, RESULTS,
654 "bdb_modrdn: new ndn=%s\n", new_ndn.bv_val, 0, 0 );
656 Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: new ndn=%s\n",
657 new_ndn.bv_val, 0, 0 );
660 rs->sr_err = bdb_dn2id ( op->o_bd, ltid, &new_ndn, &id, 0 );
661 switch( rs->sr_err ) {
662 case DB_LOCK_DEADLOCK:
663 case DB_LOCK_NOTGRANTED:
668 rs->sr_err = LDAP_ALREADY_EXISTS;
671 rs->sr_err = LDAP_OTHER;
672 rs->sr_text = "internal error";
676 /* Get attribute type and attribute value of our new rdn, we will
677 * need to add that to our new entry
679 if ( !new_rdn && ldap_bv2rdn( &op->oq_modrdn.rs_newrdn, &new_rdn, (char **)&rs->sr_text,
680 LDAP_DN_FORMAT_LDAP ) )
683 LDAP_LOG ( OPERATION, ERR,
684 "bdb_modrdn: can't figure out "
685 "type(s)/values(s) of newrdn\n",
688 Debug( LDAP_DEBUG_TRACE,
689 "bdb_modrdn: can't figure out "
690 "type(s)/values(s) of newrdn\n",
693 rs->sr_err = LDAP_INVALID_DN_SYNTAX;
694 rs->sr_text = "unknown type(s) used in RDN";
699 LDAP_LOG ( OPERATION, RESULTS,
700 "bdb_modrdn: new_rdn_type=\"%s\", "
701 "new_rdn_val=\"%s\"\n",
702 new_rdn[ 0 ][ 0 ]->la_attr.bv_val,
703 new_rdn[ 0 ][ 0 ]->la_value.bv_val, 0 );
705 Debug( LDAP_DEBUG_TRACE,
706 "bdb_modrdn: new_rdn_type=\"%s\", "
707 "new_rdn_val=\"%s\"\n",
708 new_rdn[ 0 ][ 0 ]->la_attr.bv_val,
709 new_rdn[ 0 ][ 0 ]->la_value.bv_val, 0 );
712 if ( op->oq_modrdn.rs_deleteoldrdn ) {
713 if ( !old_rdn && ldap_bv2rdn( &op->o_req_dn, &old_rdn, (char **)&rs->sr_text,
714 LDAP_DN_FORMAT_LDAP ) )
717 LDAP_LOG ( OPERATION, ERR,
718 "bdb_modrdn: can't figure out "
719 "type(s)/values(s) of old_rdn\n",
722 Debug( LDAP_DEBUG_TRACE,
723 "bdb_modrdn: can't figure out "
724 "the old_rdn type(s)/value(s)\n",
727 rs->sr_err = LDAP_OTHER;
728 rs->sr_text = "cannot parse RDN from old DN";
733 /* prepare modlist of modifications from old/new rdn */
735 rs->sr_err = slap_modrdn2mods( op, rs, e, old_rdn, new_rdn, &mod );
736 if ( rs->sr_err != LDAP_SUCCESS ) {
742 rs->sr_err = bdb_dn2id_delete( op->o_bd, ltid, p_ndn.bv_val, e );
743 if ( rs->sr_err != 0 ) {
744 switch( rs->sr_err ) {
745 case DB_LOCK_DEADLOCK:
746 case DB_LOCK_NOTGRANTED:
749 rs->sr_err = LDAP_OTHER;
750 rs->sr_text = "DN index delete fail";
754 (void) bdb_cache_delete_entry(&bdb->bi_cache, e);
756 /* Binary format uses a single contiguous block, cannot
757 * free individual fields. But if a previous modrdn has
758 * already happened, must free the names.
761 ch_free(e->e_name.bv_val);
762 e->e_name.bv_val = ch_malloc(new_dn.bv_len + new_ndn.bv_len + 2);
763 e->e_name.bv_len = new_dn.bv_len;
764 e->e_nname.bv_val = e->e_name.bv_val + new_dn.bv_len + 1;
765 e->e_nname.bv_len = new_ndn.bv_len;
766 strcpy(e->e_name.bv_val, new_dn.bv_val);
767 strcpy(e->e_nname.bv_val, new_ndn.bv_val);
769 if( e->e_nname.bv_val < e->e_bv.bv_val || e->e_nname.bv_val >
770 e->e_bv.bv_val + e->e_bv.bv_len ) {
771 ch_free(e->e_name.bv_val);
772 ch_free(e->e_nname.bv_val);
773 e->e_name.bv_val = NULL;
774 e->e_nname.bv_val = NULL;
777 e->e_nname = new_ndn;
778 new_dn.bv_val = NULL;
779 new_ndn.bv_val = NULL;
782 rs->sr_err = bdb_dn2id_add( op->o_bd, ltid, np_ndn, e );
783 if ( rs->sr_err != 0 ) {
784 switch( rs->sr_err ) {
785 case DB_LOCK_DEADLOCK:
786 case DB_LOCK_NOTGRANTED:
789 rs->sr_err = LDAP_OTHER;
790 rs->sr_text = "DN index add failed";
794 #if defined(LDAP_CLIENT_UPDATE) || defined(LDAP_SYNC)
795 if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
796 LDAP_LIST_FOREACH ( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
797 bdb_psearch( op, rs, ps_list, e, LDAP_PSEARCH_BY_PREMODIFY );
803 rs->sr_err = bdb_modify_internal( op, ltid, &mod[0], e,
804 &rs->sr_text, textbuf, textlen );
806 if( rs->sr_err != LDAP_SUCCESS ) {
807 if ( ( rs->sr_err == LDAP_INSUFFICIENT_ACCESS ) && opinfo.boi_err ) {
808 rs->sr_err = opinfo.boi_err;
810 switch( rs->sr_err ) {
811 case DB_LOCK_DEADLOCK:
812 case DB_LOCK_NOTGRANTED:
819 rs->sr_err = bdb_id2entry_update( op->o_bd, ltid, e );
820 if ( rs->sr_err != 0 ) {
821 switch( rs->sr_err ) {
822 case DB_LOCK_DEADLOCK:
823 case DB_LOCK_NOTGRANTED:
826 rs->sr_err = LDAP_OTHER;
827 rs->sr_text = "entry update failed";
832 if(( rs->sr_err=TXN_ABORT( ltid )) != 0 ) {
833 rs->sr_text = "txn_abort (no-op) failed";
836 rs->sr_err = LDAP_SUCCESS;
840 char gid[DB_XIDDATASIZE];
842 snprintf( gid, sizeof( gid ), "%s-%08lx-%08lx",
843 bdb_uuid.bv_val, (long) op->o_connid, (long) op->o_opid );
845 if(( rs->sr_err=TXN_PREPARE( ltid, gid )) != 0 ) {
846 rs->sr_text = "txn_prepare failed";
848 if( bdb_cache_update_entry(&bdb->bi_cache, e) == -1 ) {
849 if(( rs->sr_err=TXN_ABORT( ltid )) != 0 ) {
850 rs->sr_text ="cache update & txn_abort failed";
852 rs->sr_err = LDAP_OTHER;
853 rs->sr_text = "cache update failed";
857 bdb_cache_entry_commit( e );
858 if(( rs->sr_err=TXN_COMMIT( ltid, 0 )) != 0 ) {
859 rs->sr_text = "txn_commit failed";
861 rs->sr_err = LDAP_SUCCESS;
868 op->o_private = NULL;
870 if( rs->sr_err == LDAP_SUCCESS ) {
872 LDAP_LOG ( OPERATION, RESULTS,
873 "bdb_modrdn: rdn modified%s id=%08lx dn=\"%s\"\n",
874 op->o_noop ? " (no-op)" : "", e->e_id, e->e_dn );
876 Debug(LDAP_DEBUG_TRACE,
877 "bdb_modrdn: rdn modified%s id=%08lx dn=\"%s\"\n",
878 op->o_noop ? " (no-op)" : "", e->e_id, e->e_dn );
883 LDAP_LOG ( OPERATION, RESULTS, "bdb_modrdn: %s : %s (%d)\n",
884 rs->sr_text, db_strerror(rs->sr_err), rs->sr_err );
886 Debug( LDAP_DEBUG_TRACE, "bdb_add: %s : %s (%d)\n",
887 rs->sr_text, db_strerror(rs->sr_err), rs->sr_err );
889 rs->sr_err = LDAP_OTHER;
893 send_ldap_result( op, rs );
895 #if defined(LDAP_CLIENT_UPDATE) || defined(LDAP_SYNC)
896 if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
897 /* Loop through in-scope entries for each psearch spec */
898 LDAP_LIST_FOREACH ( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
899 bdb_psearch( op, rs, ps_list, e, LDAP_PSEARCH_BY_MODIFY );
901 pm_list = LDAP_LIST_FIRST(&op->o_pm_list);
902 while ( pm_list != NULL ) {
903 bdb_psearch(op, rs, pm_list->ps_op,
904 e, LDAP_PSEARCH_BY_SCOPEOUT);
906 LDAP_LIST_REMOVE ( pm_list, ps_link );
907 pm_list = LDAP_LIST_NEXT ( pm_list, ps_link );
913 if( rs->sr_err == LDAP_SUCCESS && bdb->bi_txn_cp ) {
914 ldap_pvt_thread_yield();
915 TXN_CHECKPOINT( bdb->bi_dbenv,
916 bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
920 if( new_dn.bv_val != NULL ) free( new_dn.bv_val );
921 if( new_ndn.bv_val != NULL ) free( new_ndn.bv_val );
923 /* LDAP v2 supporting correct attribute handling. */
924 if ( new_rdn != NULL ) {
925 ldap_rdnfree( new_rdn );
927 if ( old_rdn != NULL ) {
928 ldap_rdnfree( old_rdn );
932 for (; mod; mod=tmp ) {
934 if ( mod->sml_nvalues ) free( mod->sml_nvalues[0].bv_val );
939 /* LDAP v3 Support */
941 /* free new parent and reader lock */
942 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, np);
946 /* free parent and reader lock */
947 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, p);
952 bdb_unlocked_cache_return_entry_w( &bdb->bi_cache, e);
956 #if defined(LDAP_CLIENT_UPDATE) || defined(LDAP_SYNC)
957 pm_list = LDAP_LIST_FIRST(&op->o_pm_list);
958 while ( pm_list != NULL ) {
959 LDAP_LIST_REMOVE ( pm_list, ps_link );
961 pm_list = LDAP_LIST_NEXT ( pm_list, ps_link );
966 op->o_private = NULL;
969 return ( ( rs->sr_err == LDAP_SUCCESS ) ? noop : rs->sr_err );