1 /* modrdn.c - ldbm backend modrdn routine */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
9 * LDAP v3 newSuperior support. Add new rdn as an attribute.
10 * (Full support for v2 also used software/ideas contributed
11 * by Roy Hooper rhooper@cyberus.ca, thanks to him for his
14 * Copyright 1999, Juan C. Gomez, All rights reserved.
15 * This software is not subject to any license of Silicon Graphics
16 * Inc. or Purdue University.
18 * Redistribution and use in source and binary forms are permitted
19 * without restriction or fee of any kind as long as this notice
28 #include <ac/string.h>
29 #include <ac/socket.h>
32 #include "back-ldbm.h"
33 #include "proto-back-ldbm.h"
42 struct berval *newrdn,
43 struct berval *nnewrdn,
45 struct berval *newSuperior,
46 struct berval *nnewSuperior
49 AttributeDescription *children = slap_schema.si_ad_children;
50 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
51 struct berval p_dn, p_ndn;
52 struct berval new_dn = { 0, NULL}, new_ndn = { 0, NULL };
57 #define CAN_ROLLBACK -1
58 #define MUST_DESTROY 1
59 int rc = CAN_ROLLBACK;
62 const char *text = NULL;
63 char textbuf[SLAP_TEXT_BUFLEN];
64 size_t textlen = sizeof textbuf;
65 /* Added to support LDAP v2 correctly (deleteoldrdn thing) */
69 /* Added to support newSuperior */
70 Entry *np = NULL; /* newSuperior Entry */
71 struct berval *np_ndn = NULL; /* newSuperior ndn */
72 struct berval *new_parent_dn = NULL; /* np_dn, p_dn, or NULL */
73 /* Used to interface with ldbm_modify_internal() */
74 Modifications *mod = NULL; /* Used to delete old/add new rdn */
75 int manageDSAit = get_manageDSAit( op );
78 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
79 "ldbm_back_modrdn: dn: %s newSuperior=%s\n",
80 dn->bv_len ? dn->bv_val : "NULL",
81 ( newSuperior && newSuperior->bv_len )
82 ? newSuperior->bv_val : "NULL" ));
84 Debug( LDAP_DEBUG_TRACE,
85 "==>ldbm_back_modrdn: dn: %s newSuperior=%s\n",
86 dn->bv_len ? dn->bv_val : "NULL",
87 ( newSuperior && newSuperior->bv_len )
88 ? newSuperior->bv_val : "NULL", 0 );
91 /* grab giant lock for writing */
92 ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
94 /* get entry with writer lock */
95 if ( (e = dn2entry_w( be, ndn, &matched )) == NULL ) {
96 char* matched_dn = NULL;
99 if( matched != NULL ) {
100 matched_dn = strdup( matched->e_dn );
101 refs = is_entry_referral( matched )
102 ? get_entry_referrals( be, conn, op, matched )
104 cache_return_entry_r( &li->li_cache, matched );
106 refs = referral_rewrite( default_referral,
107 NULL, dn, LDAP_SCOPE_DEFAULT );
110 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
112 send_ldap_result( conn, op, LDAP_REFERRAL,
113 matched_dn, NULL, refs, NULL );
115 if ( refs ) ber_bvarray_free( refs );
121 if (!manageDSAit && is_entry_referral( e ) ) {
122 /* parent is a referral, don't allow add */
123 /* parent is an alias, don't allow add */
124 BerVarray refs = get_entry_referrals( be,
128 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
129 "ldbm_back_modrdn: entry %s is a referral\n", e->e_dn ));
131 Debug( LDAP_DEBUG_TRACE, "entry %s is referral\n", e->e_dn,
135 send_ldap_result( conn, op, LDAP_REFERRAL,
136 e->e_dn, NULL, refs, NULL );
138 if ( refs ) ber_bvarray_free( refs );
142 if ( has_children( be, e ) ) {
144 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
145 "ldbm_back_modrdn: entry %s has children\n", e->e_dn ));
147 Debug( LDAP_DEBUG_TRACE, "entry %s has children\n", e->e_dn,
151 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
152 NULL, "subtree rename not supported", NULL, NULL );
156 if ( be_issuffix( be, &e->e_nname ) ) {
157 p_ndn = slap_empty_bv ;
159 dnParent( &e->e_nname, &p_ndn );
162 if ( p_ndn.bv_len != 0 ) {
163 /* Make sure parent entry exist and we can write its
167 if( (p = dn2entry_w( be, &p_ndn, NULL )) == NULL) {
169 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
170 "ldbm_back_modrdn: parent of %s does not exist\n", e->e_ndn ));
172 Debug( LDAP_DEBUG_TRACE, "parent does not exist\n",
176 send_ldap_result( conn, op, LDAP_OTHER,
177 NULL, "parent entry does not exist", NULL, NULL );
182 /* check parent for "children" acl */
183 if ( ! access_allowed( be, conn, op, p,
184 children, NULL, ACL_WRITE, NULL ) )
187 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
188 "ldbm_back_modrdn: no access to parent of (%s)\n", e->e_dn ));
190 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
194 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
195 NULL, NULL, NULL, NULL );
200 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
201 "ldbm_back_modrdn: wr to children of entry %s OK\n",
204 Debug( LDAP_DEBUG_TRACE,
205 "ldbm_back_modrdn: wr to children of entry %s OK\n",
206 p_ndn.bv_val, 0, 0 );
209 if ( p_ndn.bv_val == slap_empty_bv.bv_val ) {
210 p_dn = slap_empty_bv;
212 dnParent( &e->e_name, &p_dn );
216 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
217 "ldbm_back_modrdn: parent dn=%s\n", p_dn.bv_val ));
219 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: parent dn=%s\n",
224 /* no parent, must be root to modify rdn */
225 isroot = be_isroot( be, &op->o_ndn );
227 if ( be_issuffix( be, (struct berval *)&slap_empty_bv ) || be_isupdate( be, &op->o_ndn ) ) {
228 p = (Entry *)&slap_entry_root;
230 rc = access_allowed( be, conn, op, p,
231 children, NULL, ACL_WRITE, NULL );
234 /* check parent for "children" acl */
237 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
238 "ldbm_back_modrdn: no access "
239 "to parent \"\"\n" ));
241 Debug( LDAP_DEBUG_TRACE,
242 "<=- ldbm_back_modrdn: no "
243 "access to parent\n", 0, 0, 0 );
246 send_ldap_result( conn, op,
247 LDAP_INSUFFICIENT_ACCESS,
248 NULL, NULL, NULL, NULL );
254 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
255 "ldbm_back_modrdn: (%s) has no "
256 "parent & not a root.\n", dn ));
258 Debug( LDAP_DEBUG_TRACE,
259 "<=- ldbm_back_modrdn: no parent & "
260 "not root\n", 0, 0, 0);
263 send_ldap_result( conn, op,
264 LDAP_INSUFFICIENT_ACCESS,
265 NULL, NULL, NULL, NULL );
271 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
272 "ldbm_back_modrdn: (%s) no parent, locked root.\n", e->e_dn ));
274 Debug( LDAP_DEBUG_TRACE,
275 "ldbm_back_modrdn: no parent, locked root\n",
280 new_parent_dn = &p_dn; /* New Parent unless newSuperior given */
282 if ( newSuperior != NULL ) {
284 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
285 "ldbm_back_modrdn: new parent \"%s\" requested\n",
286 newSuperior->bv_val ));
288 Debug( LDAP_DEBUG_TRACE,
289 "ldbm_back_modrdn: new parent \"%s\" requested...\n",
290 newSuperior->bv_val, 0, 0 );
293 np_ndn = nnewSuperior;
295 /* newSuperior == oldParent? */
296 if ( dn_match( &p_ndn, np_ndn ) ) {
298 LDAP_LOG(( "backend", LDAP_LEVEL_INFO, "ldbm_back_modrdn: "
299 "new parent\"%s\" seems to be the same as the "
300 "old parent \"%s\"\n",
301 newSuperior->bv_val, p_dn.bv_val ));
303 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: "
304 "new parent\"%s\" seems to be the same as the "
305 "old parent \"%s\"\n",
306 newSuperior->bv_val, p_dn.bv_val, 0 );
309 newSuperior = NULL; /* ignore newSuperior */
313 if ( newSuperior != NULL ) {
314 /* newSuperior == entry being moved?, if so ==> ERROR */
315 /* Get Entry with dn=newSuperior. Does newSuperior exist? */
317 if ( nnewSuperior->bv_len ) {
318 if( (np = dn2entry_w( be, np_ndn, NULL )) == NULL) {
320 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
321 "ldbm_back_modrdn: newSup(ndn=%s) not found.\n", np_ndn->bv_val ));
323 Debug( LDAP_DEBUG_TRACE,
324 "ldbm_back_modrdn: newSup(ndn=%s) not here!\n",
325 np_ndn->bv_val, 0, 0);
328 send_ldap_result( conn, op, LDAP_OTHER,
329 NULL, "newSuperior not found", NULL, NULL );
334 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
335 "ldbm_back_modrdn: wr to new parent OK np=%p, id=%ld\n",
338 Debug( LDAP_DEBUG_TRACE,
339 "ldbm_back_modrdn: wr to new parent OK np=%p, id=%ld\n",
343 /* check newSuperior for "children" acl */
344 if ( !access_allowed( be, conn, op, np, children, NULL,
348 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
349 "ldbm_back_modrdn: no wr to newSup children.\n" ));
351 Debug( LDAP_DEBUG_TRACE,
352 "ldbm_back_modrdn: no wr to newSup children\n",
356 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
357 NULL, NULL, NULL, NULL );
361 if ( is_entry_alias( np ) ) {
362 /* parent is an alias, don't allow add */
364 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
365 "ldbm_back_modrdn: entry (%s) is an alias.\n", np->e_dn ));
367 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0, 0, 0 );
371 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
372 NULL, "newSuperior is an alias", NULL, NULL );
377 if ( is_entry_referral( np ) ) {
378 /* parent is a referral, don't allow add */
380 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
381 "ldbm_back_modrdn: entry (%s) is a referral\n",
384 Debug( LDAP_DEBUG_TRACE, "entry (%s) is referral\n",
388 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
389 NULL, "newSuperior is a referral", NULL, NULL );
396 /* no parent, must be root to modify newSuperior */
397 if ( isroot == -1 ) {
398 isroot = be_isroot( be, &op->o_ndn );
402 if ( be_issuffix( be, (struct berval *)&slap_empty_bv ) || be_isupdate( be, &op->o_ndn ) ) {
403 np = (Entry *)&slap_entry_root;
405 rc = access_allowed( be, conn, op, np,
406 children, NULL, ACL_WRITE, NULL );
409 /* check parent for "children" acl */
412 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
413 "ldbm_back_modrdn: no access "
414 "to new superior \"\"\n" ));
416 Debug( LDAP_DEBUG_TRACE,
417 "<=- ldbm_back_modrdn: no "
418 "access to new superior\n", 0, 0, 0 );
421 send_ldap_result( conn, op,
422 LDAP_INSUFFICIENT_ACCESS,
423 NULL, NULL, NULL, NULL );
429 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
430 "ldbm_back_modrdn: \"\" "
431 "not allowed as new superior\n" ));
433 Debug( LDAP_DEBUG_TRACE,
434 "<=- ldbm_back_modrdn: \"\" "
435 "not allowed as new superior\n",
439 send_ldap_result( conn, op,
440 LDAP_INSUFFICIENT_ACCESS,
441 NULL, NULL, NULL, NULL );
448 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
449 "ldbm_back_modrdn: wr to new parent's children OK.\n" ));
451 Debug( LDAP_DEBUG_TRACE,
452 "ldbm_back_modrdn: wr to new parent's children OK\n",
456 new_parent_dn = newSuperior;
459 /* Build target dn and make sure target entry doesn't exist already. */
460 build_new_dn( &new_dn, new_parent_dn, newrdn );
461 dnNormalize2( NULL, &new_dn, &new_ndn );
464 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
465 "ldbm_back_modrdn: new ndn=%s\n", new_ndn.bv_val ));
467 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: new ndn=%s\n",
468 new_ndn.bv_val, 0, 0 );
471 /* check for abandon */
472 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
473 if ( op->o_abandon ) {
474 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
478 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
479 if ( ( rc_id = dn2id ( be, &new_ndn, &id ) ) || id != NOID ) {
480 /* if (rc_id) something bad happened to ldbm cache */
481 send_ldap_result( conn, op,
482 rc_id ? LDAP_OPERATIONS_ERROR : LDAP_ALREADY_EXISTS,
483 NULL, NULL, NULL, NULL );
488 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
489 "ldbm_back_modrdn: new ndn (%s) does not exist\n", new_ndn.bv_val ));
491 Debug( LDAP_DEBUG_TRACE,
492 "ldbm_back_modrdn: new ndn=%s does not exist\n",
493 new_ndn.bv_val, 0, 0 );
497 /* Get attribute types and values of our new rdn, we will
498 * need to add that to our new entry
500 if ( ldap_bv2rdn( newrdn, &new_rdn, (char **)&text,
501 LDAP_DN_FORMAT_LDAP ) )
504 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
505 "ldbm_back_modrdn: can't figure out type(s)/value(s) of newrdn\n" ));
507 Debug( LDAP_DEBUG_TRACE,
508 "ldbm_back_modrdn: can't figure out type(s)/value(s) of newrdn\n",
512 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
513 NULL, "unable to parse type(s)/value(s) used in RDN", NULL, NULL );
518 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
519 "ldbm_back_modrdn: new_rdn_type=\"%s\", new_rdn_val=\"%s\"\n",
520 new_rdn[0][0]->la_attr.bv_val, new_rdn[0][0]->la_value.bv_val ));
522 Debug( LDAP_DEBUG_TRACE,
523 "ldbm_back_modrdn: new_rdn_type=\"%s\", new_rdn_val=\"%s\"\n",
524 new_rdn[0][0]->la_attr.bv_val, new_rdn[0][0]->la_value.bv_val, 0 );
527 /* Retrieve the old rdn from the entry's dn */
528 if ( ldap_bv2rdn( dn, &old_rdn, (char **)&text,
529 LDAP_DN_FORMAT_LDAP ) )
532 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
533 "ldbm_back_modrdn: can't figure out the old_rdn type(s)/value(s).\n" ));
535 Debug( LDAP_DEBUG_TRACE,
536 "ldbm_back_modrdn: can't figure out the old_rdn type(s)/value(s)\n",
540 send_ldap_result( conn, op, LDAP_OTHER,
541 NULL, "unable to parse type(s)/value(s) used in RDN from old DN", NULL, NULL );
546 if ( newSuperior == NULL
547 && charray_strcasecmp( (const char **)old_rdn_types, (const char **)new_rdn_types ) != 0 )
549 /* Not a big deal but we may say something */
551 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
552 "ldbm_back_modrdn: old_rdn_type=%s new_rdn_type=%s\n",
553 old_rdn_types[0], new_rdn_types[0] ));
555 Debug( LDAP_DEBUG_TRACE,
556 "ldbm_back_modrdn: old_rdn_type=%s, new_rdn_type=%s!\n",
557 old_rdn_types[0], new_rdn_types[0], 0 );
563 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
564 "ldbm_back_modrdn: DN_X500\n" ));
566 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: DN_X500\n",
571 for ( a_cnt = 0; new_rdn[0][a_cnt]; a_cnt++ ) {
573 AttributeDescription *desc = NULL;
574 Modifications *mod_tmp;
576 rc = slap_bv2ad( &new_rdn[0][a_cnt]->la_attr, &desc, &text );
578 if ( rc != LDAP_SUCCESS ) {
580 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
581 "ldbm_back_modrdn: slap_bv2ad error: %s (%s)\n",
582 text, new_rdn[0][a_cnt]->la_attr.bv_val ));
584 Debug( LDAP_DEBUG_TRACE,
585 "ldbm_back_modrdn: %s: %s (new)\n",
586 text, new_rdn[0][a_cnt]->la_attr.bv_val, 0 );
589 send_ldap_result( conn, op, rc,
590 NULL, text, NULL, NULL );
595 if ( ! access_allowed( be, conn, op, e,
596 desc, &new_rdn[0][a_cnt]->la_value, ACL_WRITE, NULL ) ) {
598 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
599 "ldbm_back_modrdn: access "
600 "not allowed to attr \"%s\"\n",
601 new_rdn[0][a_cnt]->la_attr.bv_val ));
603 Debug( LDAP_DEBUG_TRACE,
604 "ldbm_back_modrdn: access not allowed "
605 "to attr \"%s\"\n%s%s",
606 new_rdn[0][a_cnt]->la_attr.bv_val, "", "" );
608 send_ldap_result( conn, op,
609 LDAP_INSUFFICIENT_ACCESS,
610 NULL, NULL, NULL, NULL );
615 mod_tmp = (Modifications *)ch_malloc( sizeof( Modifications )
616 + 2 * sizeof( struct berval ) );
617 mod_tmp->sml_desc = desc;
618 mod_tmp->sml_bvalues = (BerVarray)( mod_tmp + 1 );
619 mod_tmp->sml_bvalues[0] = new_rdn[0][a_cnt]->la_value;
620 mod_tmp->sml_bvalues[1].bv_val = NULL;
621 mod_tmp->sml_op = SLAP_MOD_SOFTADD;
622 mod_tmp->sml_next = mod;
626 /* Remove old rdn value if required */
627 if ( deleteoldrdn ) {
628 /* Get value of old rdn */
629 if ( old_rdn == NULL ) {
631 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
632 "ldbm_back_modrdn: can't figure out old RDN value(s) from old RDN\n" ));
634 Debug( LDAP_DEBUG_TRACE,
635 "ldbm_back_modrdn: can't figure out oldRDN value(s) from old RDN\n",
639 send_ldap_result( conn, op, LDAP_OTHER,
640 NULL, "could not parse value(s) from old RDN", NULL, NULL );
644 for ( d_cnt = 0; old_rdn[0][d_cnt]; d_cnt++ ) {
646 AttributeDescription *desc = NULL;
647 Modifications *mod_tmp;
649 rc = slap_bv2ad( &old_rdn[0][d_cnt]->la_attr, &desc, &text );
651 if ( rc != LDAP_SUCCESS ) {
653 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
654 "ldbm_back_modrdn: %s: %s (old)\n",
655 text, old_rdn[0][d_cnt]->la_attr.bv_val ));
657 Debug( LDAP_DEBUG_TRACE,
658 "ldbm_back_modrdn: %s: %s (old)\n",
659 text, old_rdn[0][d_cnt]->la_attr.bv_val, 0 );
662 send_ldap_result( conn, op, rc,
663 NULL, text, NULL, NULL );
668 if ( ! access_allowed( be, conn, op, e,
669 desc, &old_rdn[0][d_cnt]->la_value, ACL_WRITE, NULL ) ) {
671 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
672 "ldbm_back_modrdn: access "
673 "not allowed to attr \"%s\"\n",
674 old_rdn[0][d_cnt]->la_attr.bv_val ));
676 Debug( LDAP_DEBUG_TRACE,
677 "ldbm_back_modrdn: access not allowed "
678 "to attr \"%s\"\n%s%s",
679 old_rdn[0][d_cnt]->la_attr.bv_val, "", "" );
681 send_ldap_result( conn, op,
682 LDAP_INSUFFICIENT_ACCESS,
683 NULL, NULL, NULL, NULL );
688 /* Remove old value of rdn as an attribute. */
689 mod_tmp = (Modifications *)ch_malloc( sizeof( Modifications )
690 + 2 * sizeof( struct berval ) );
691 mod_tmp->sml_desc = desc;
692 mod_tmp->sml_bvalues = (BerVarray)(mod_tmp+1);
693 mod_tmp->sml_bvalues[0] = old_rdn[0][d_cnt]->la_value;
694 mod_tmp->sml_bvalues[1].bv_val = NULL;
695 mod_tmp->sml_op = LDAP_MOD_DELETE;
696 mod_tmp->sml_next = mod;
700 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
701 "ldbm_back_modrdn: removing old_rdn_val=%s\n", old_rdn[0][d_cnt]->la_value.bv_val ));
703 Debug( LDAP_DEBUG_TRACE,
704 "ldbm_back_modrdn: removing old_rdn_val=%s\n",
705 old_rdn[0][d_cnt]->la_value.bv_val, 0, 0 );
711 /* check for abandon */
712 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
713 if ( op->o_abandon ) {
714 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
717 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
720 if ( dn2id_delete( be, &e->e_nname, e->e_id ) != 0 ) {
721 send_ldap_result( conn, op, LDAP_OTHER,
722 NULL, "DN index delete fail", NULL, NULL );
726 (void) cache_delete_entry( &li->li_cache, e );
729 /* XXX: there is no going back! */
734 e->e_nname = new_ndn;
735 new_dn.bv_val = NULL;
736 new_ndn.bv_val = NULL;
739 if ( dn2id_add( be, &e->e_nname, e->e_id ) != 0 ) {
740 send_ldap_result( conn, op, LDAP_OTHER,
741 NULL, "DN index add failed", NULL, NULL );
745 /* modify memory copy of entry */
746 rc = ldbm_modify_internal( be, conn, op, dn->bv_val, &mod[0], e,
747 &text, textbuf, textlen );
749 if( rc != LDAP_SUCCESS ) {
750 if( rc != SLAPD_ABANDON ) {
751 send_ldap_result( conn, op, rc,
752 NULL, text, NULL, NULL );
755 /* here we may try to delete the newly added dn */
756 if ( dn2id_delete( be, &e->e_nname, e->e_id ) != 0 ) {
757 /* we already are in trouble ... */
764 (void) cache_update_entry( &li->li_cache, e );
766 /* NOTE: after this you must not free new_dn or new_ndn!
767 * They are used by cache.
771 if ( id2entry_add( be, e ) != 0 ) {
772 send_ldap_result( conn, op, LDAP_OTHER,
773 NULL, "entry update failed", NULL, NULL );
777 send_ldap_result( conn, op, LDAP_SUCCESS,
778 NULL, NULL, NULL, NULL );
780 cache_entry_commit( e );
783 if( new_dn.bv_val != NULL ) free( new_dn.bv_val );
784 if( new_ndn.bv_val != NULL ) free( new_ndn.bv_val );
786 /* LDAP v2 supporting correct attribute handling. */
787 if( new_rdn ) ldap_rdnfree( new_rdn );
788 if( old_rdn ) ldap_rdnfree( old_rdn );
792 for (; mod; mod = tmp ) {
798 /* LDAP v3 Support */
800 /* free new parent and writer lock */
801 cache_return_entry_w( &li->li_cache, np );
805 /* free parent and writer lock */
806 cache_return_entry_w( &li->li_cache, p );
809 /* free entry and writer lock */
810 cache_return_entry_w( &li->li_cache, e );
811 if ( rc == MUST_DESTROY ) {
812 /* if rc == MUST_DESTROY the entry is uncached
813 * and its private data is destroyed;
814 * the entry must be freed */
817 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);