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 /* get entry with writer lock */
92 if ( (e = dn2entry_w( be, ndn, &matched )) == NULL ) {
93 char* matched_dn = NULL;
96 if( matched != NULL ) {
97 matched_dn = strdup( matched->e_dn );
98 refs = is_entry_referral( matched )
99 ? get_entry_referrals( be, conn, op, matched )
101 cache_return_entry_r( &li->li_cache, matched );
103 refs = referral_rewrite( default_referral,
104 NULL, dn, LDAP_SCOPE_DEFAULT );
107 send_ldap_result( conn, op, LDAP_REFERRAL,
108 matched_dn, NULL, refs, NULL );
110 if ( refs ) ber_bvarray_free( refs );
116 if (!manageDSAit && is_entry_referral( e ) ) {
117 /* parent is a referral, don't allow add */
118 /* parent is an alias, don't allow add */
119 BerVarray refs = get_entry_referrals( be,
123 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
124 "ldbm_back_modrdn: entry %s is a referral\n", e->e_dn ));
126 Debug( LDAP_DEBUG_TRACE, "entry %s is referral\n", e->e_dn,
130 send_ldap_result( conn, op, LDAP_REFERRAL,
131 e->e_dn, NULL, refs, NULL );
133 if ( refs ) ber_bvarray_free( refs );
137 if ( has_children( be, e ) ) {
139 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
140 "ldbm_back_modrdn: entry %s has children\n", e->e_dn ));
142 Debug( LDAP_DEBUG_TRACE, "entry %s has children\n", e->e_dn,
146 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
147 NULL, "subtree rename not supported", NULL, NULL );
151 p_ndn.bv_val = dn_parent( be, e->e_ndn );
153 p_ndn.bv_len = e->e_nname.bv_len - (p_ndn.bv_val - e->e_ndn);
157 if ( p_ndn.bv_len != 0 ) {
158 /* Make sure parent entry exist and we can write its
162 if( (p = dn2entry_w( be, &p_ndn, NULL )) == NULL) {
164 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
165 "ldbm_back_modrdn: parent of %s does not exist\n", e->e_ndn ));
167 Debug( LDAP_DEBUG_TRACE, "parent does not exist\n",
171 send_ldap_result( conn, op, LDAP_OTHER,
172 NULL, "parent entry does not exist", NULL, NULL );
177 /* check parent for "children" acl */
178 if ( ! access_allowed( be, conn, op, p,
179 children, NULL, ACL_WRITE ) )
182 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
183 "ldbm_back_modrdn: no access to parent of (%s)\n", e->e_dn ));
185 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
189 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
190 NULL, NULL, NULL, NULL );
195 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
196 "ldbm_back_modrdn: wr to children of entry %s OK\n",
199 Debug( LDAP_DEBUG_TRACE,
200 "ldbm_back_modrdn: wr to children of entry %s OK\n",
201 p_ndn.bv_val, 0, 0 );
204 p_dn.bv_val = dn_parent( be, e->e_dn );
206 p_dn.bv_len = e->e_name.bv_len - (p_dn.bv_val - e->e_dn);
211 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
212 "ldbm_back_modrdn: parent dn=%s\n", p_dn.bv_val ));
214 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: parent dn=%s\n",
219 /* no parent, must be root to modify rdn */
220 isroot = be_isroot( be, &op->o_ndn );
222 if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
223 p = (Entry *)&slap_entry_root;
225 rc = access_allowed( be, conn, op, p,
226 children, NULL, ACL_WRITE );
229 /* check parent for "children" acl */
232 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
233 "ldbm_back_modrdn: no access "
234 "to parent \"\"\n" ));
236 Debug( LDAP_DEBUG_TRACE,
237 "<=- ldbm_back_modrdn: no "
238 "access to parent\n", 0, 0, 0 );
241 send_ldap_result( conn, op,
242 LDAP_INSUFFICIENT_ACCESS,
243 NULL, NULL, NULL, NULL );
249 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
250 "ldbm_back_modrdn: (%s) has no "
251 "parent & not a root.\n", dn ));
253 Debug( LDAP_DEBUG_TRACE,
254 "<=- ldbm_back_modrdn: no parent & "
255 "not root\n", 0, 0, 0);
258 send_ldap_result( conn, op,
259 LDAP_INSUFFICIENT_ACCESS,
260 NULL, NULL, NULL, NULL );
265 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
269 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
270 "ldbm_back_modrdn: (%s) no parent, locked root.\n", e->e_dn ));
272 Debug( LDAP_DEBUG_TRACE,
273 "ldbm_back_modrdn: no parent, locked root\n",
278 new_parent_dn = &p_dn; /* New Parent unless newSuperior given */
280 if ( newSuperior != NULL ) {
282 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
283 "ldbm_back_modrdn: new parent \"%s\" requested\n",
284 newSuperior->bv_val ));
286 Debug( LDAP_DEBUG_TRACE,
287 "ldbm_back_modrdn: new parent \"%s\" requested...\n",
288 newSuperior->bv_val, 0, 0 );
291 np_ndn = nnewSuperior;
293 /* newSuperior == oldParent? */
294 if ( dn_match( &p_ndn, np_ndn ) ) {
296 LDAP_LOG(( "backend", LDAP_LEVEL_INFO, "ldbm_back_modrdn: "
297 "new parent\"%s\" seems to be the same as the "
298 "old parent \"%s\"\n",
299 newSuperior->bv_val, p_dn.bv_val ));
301 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: "
302 "new parent\"%s\" seems to be the same as the "
303 "old parent \"%s\"\n",
304 newSuperior->bv_val, p_dn.bv_val, 0 );
307 newSuperior = NULL; /* ignore newSuperior */
311 if ( newSuperior != NULL ) {
312 /* newSuperior == entry being moved?, if so ==> ERROR */
313 /* Get Entry with dn=newSuperior. Does newSuperior exist? */
315 if ( nnewSuperior->bv_len ) {
316 if( (np = dn2entry_w( be, np_ndn, NULL )) == NULL) {
318 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
319 "ldbm_back_modrdn: newSup(ndn=%s) not found.\n", np_ndn->bv_val ));
321 Debug( LDAP_DEBUG_TRACE,
322 "ldbm_back_modrdn: newSup(ndn=%s) not here!\n",
323 np_ndn->bv_val, 0, 0);
326 send_ldap_result( conn, op, LDAP_OTHER,
327 NULL, "newSuperior not found", NULL, NULL );
332 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
333 "ldbm_back_modrdn: wr to new parent OK np=%p, id=%ld\n",
336 Debug( LDAP_DEBUG_TRACE,
337 "ldbm_back_modrdn: wr to new parent OK np=%p, id=%ld\n",
341 /* check newSuperior for "children" acl */
342 if ( !access_allowed( be, conn, op, np, children, NULL,
346 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
347 "ldbm_back_modrdn: no wr to newSup children.\n" ));
349 Debug( LDAP_DEBUG_TRACE,
350 "ldbm_back_modrdn: no wr to newSup children\n",
354 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
355 NULL, NULL, NULL, NULL );
359 if ( is_entry_alias( np ) ) {
360 /* parent is an alias, don't allow add */
362 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
363 "ldbm_back_modrdn: entry (%s) is an alias.\n", np->e_dn ));
365 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0, 0, 0 );
369 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
370 NULL, "newSuperior is an alias", NULL, NULL );
375 if ( is_entry_referral( np ) ) {
376 /* parent is a referral, don't allow add */
378 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
379 "ldbm_back_modrdn: entry (%s) is a referral\n",
382 Debug( LDAP_DEBUG_TRACE, "entry (%s) is referral\n",
386 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
387 NULL, "newSuperior is a referral", NULL, NULL );
394 /* no parent, must be root to modify newSuperior */
395 if ( isroot == -1 ) {
396 isroot = be_isroot( be, &op->o_ndn );
400 if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
401 np = (Entry *)&slap_entry_root;
403 rc = access_allowed( be, conn, op, np,
404 children, NULL, ACL_WRITE );
407 /* check parent for "children" acl */
410 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
411 "ldbm_back_modrdn: no access "
412 "to new superior \"\"\n" ));
414 Debug( LDAP_DEBUG_TRACE,
415 "<=- ldbm_back_modrdn: no "
416 "access to new superior\n", 0, 0, 0 );
419 send_ldap_result( conn, op,
420 LDAP_INSUFFICIENT_ACCESS,
421 NULL, NULL, NULL, NULL );
427 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
428 "ldbm_back_modrdn: \"\" "
429 "not allowed as new superior\n" ));
431 Debug( LDAP_DEBUG_TRACE,
432 "<=- ldbm_back_modrdn: \"\" "
433 "not allowed as new superior\n",
437 send_ldap_result( conn, op,
438 LDAP_INSUFFICIENT_ACCESS,
439 NULL, NULL, NULL, NULL );
446 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
447 "ldbm_back_modrdn: wr to new parent's children OK.\n" ));
449 Debug( LDAP_DEBUG_TRACE,
450 "ldbm_back_modrdn: wr to new parent's children OK\n",
454 new_parent_dn = newSuperior;
457 /* Build target dn and make sure target entry doesn't exist already. */
458 build_new_dn( &new_dn, new_parent_dn, newrdn );
459 dnNormalize2( NULL, &new_dn, &new_ndn );
462 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
463 "ldbm_back_modrdn: new ndn=%s\n", new_ndn.bv_val ));
465 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: new ndn=%s\n",
466 new_ndn.bv_val, 0, 0 );
469 /* check for abandon */
470 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
471 if ( op->o_abandon ) {
472 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
476 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
477 if ( ( rc_id = dn2id ( be, &new_ndn, &id ) ) || id != NOID ) {
478 /* if (rc_id) something bad happened to ldbm cache */
479 send_ldap_result( conn, op,
480 rc_id ? LDAP_OPERATIONS_ERROR : LDAP_ALREADY_EXISTS,
481 NULL, NULL, NULL, NULL );
486 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
487 "ldbm_back_modrdn: new ndn (%s) does not exist\n", new_ndn.bv_val ));
489 Debug( LDAP_DEBUG_TRACE,
490 "ldbm_back_modrdn: new ndn=%s does not exist\n",
491 new_ndn.bv_val, 0, 0 );
495 /* Get attribute types and values of our new rdn, we will
496 * need to add that to our new entry
498 if ( ldap_str2rdn( newrdn->bv_val, &new_rdn, (char **)&text,
499 LDAP_DN_FORMAT_LDAP ) )
502 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
503 "ldbm_back_modrdn: can't figure out type(s)/value(s) of newrdn\n" ));
505 Debug( LDAP_DEBUG_TRACE,
506 "ldbm_back_modrdn: can't figure out type(s)/value(s) of newrdn\n",
510 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
511 NULL, "unable to parse type(s)/value(s) used in RDN", NULL, NULL );
516 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
517 "ldbm_back_modrdn: new_rdn_type=\"%s\", new_rdn_val=\"%s\"\n",
518 new_rdn[0][0]->la_attr.bv_val, new_rdn[0][0]->la_value.bv_val ));
520 Debug( LDAP_DEBUG_TRACE,
521 "ldbm_back_modrdn: new_rdn_type=\"%s\", new_rdn_val=\"%s\"\n",
522 new_rdn[0][0]->la_attr.bv_val, new_rdn[0][0]->la_value.bv_val, 0 );
525 /* Retrieve the old rdn from the entry's dn */
526 if ( ldap_str2rdn( dn->bv_val, &old_rdn, (char **)&text,
527 LDAP_DN_FORMAT_LDAP ) )
530 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
531 "ldbm_back_modrdn: can't figure out the old_rdn type(s)/value(s).\n" ));
533 Debug( LDAP_DEBUG_TRACE,
534 "ldbm_back_modrdn: can't figure out the old_rdn type(s)/value(s)\n",
538 send_ldap_result( conn, op, LDAP_OTHER,
539 NULL, "unable to parse type(s)/value(s) used in RDN from old DN", NULL, NULL );
544 if ( newSuperior == NULL
545 && charray_strcasecmp( (const char **)old_rdn_types, (const char **)new_rdn_types ) != 0 )
547 /* Not a big deal but we may say something */
549 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
550 "ldbm_back_modrdn: old_rdn_type=%s new_rdn_type=%s\n",
551 old_rdn_types[0], new_rdn_types[0] ));
553 Debug( LDAP_DEBUG_TRACE,
554 "ldbm_back_modrdn: old_rdn_type=%s, new_rdn_type=%s!\n",
555 old_rdn_types[0], new_rdn_types[0], 0 );
561 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
562 "ldbm_back_modrdn: DN_X500\n" ));
564 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: DN_X500\n",
569 for ( a_cnt = 0; new_rdn[0][a_cnt]; a_cnt++ ) {
571 AttributeDescription *desc = NULL;
572 Modifications *mod_tmp;
574 rc = slap_bv2ad( &new_rdn[0][a_cnt]->la_attr, &desc, &text );
576 if ( rc != LDAP_SUCCESS ) {
578 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
579 "ldbm_back_modrdn: slap_bv2ad error: %s (%s)\n",
580 text, new_rdn[0][a_cnt]->la_attr.bv_val ));
582 Debug( LDAP_DEBUG_TRACE,
583 "ldbm_back_modrdn: %s: %s (new)\n",
584 text, new_rdn[0][a_cnt]->la_attr.bv_val, 0 );
587 send_ldap_result( conn, op, rc,
588 NULL, text, NULL, NULL );
593 if ( ! access_allowed( be, conn, op, e,
594 desc, &new_rdn[0][a_cnt]->la_value, ACL_WRITE ) ) {
596 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
597 "ldbm_back_modrdn: access "
598 "not allowed to attr \"%s\"\n",
599 new_rdn[0][a_cnt]->la_attr.bv_val ));
601 Debug( LDAP_DEBUG_TRACE,
602 "ldbm_back_modrdn: access not allowed "
603 "to attr \"%s\"\n%s%s",
604 new_rdn[0][a_cnt]->la_attr.bv_val, "", "" );
606 send_ldap_result( conn, op,
607 LDAP_INSUFFICIENT_ACCESS,
608 NULL, NULL, NULL, NULL );
613 mod_tmp = (Modifications *)ch_malloc( sizeof( Modifications )
614 + 2 * sizeof( struct berval ) );
615 mod_tmp->sml_desc = desc;
616 mod_tmp->sml_bvalues = (BerVarray)( mod_tmp + 1 );
617 mod_tmp->sml_bvalues[0] = new_rdn[0][a_cnt]->la_value;
618 mod_tmp->sml_bvalues[1].bv_val = NULL;
619 mod_tmp->sml_op = SLAP_MOD_SOFTADD;
620 mod_tmp->sml_next = mod;
624 /* Remove old rdn value if required */
625 if ( deleteoldrdn ) {
626 /* Get value of old rdn */
627 if ( old_rdn == NULL ) {
629 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
630 "ldbm_back_modrdn: can't figure out old RDN value(s) from old RDN\n" ));
632 Debug( LDAP_DEBUG_TRACE,
633 "ldbm_back_modrdn: can't figure out oldRDN value(s) from old RDN\n",
637 send_ldap_result( conn, op, LDAP_OTHER,
638 NULL, "could not parse value(s) from old RDN", NULL, NULL );
642 for ( d_cnt = 0; old_rdn[0][d_cnt]; d_cnt++ ) {
644 AttributeDescription *desc = NULL;
645 Modifications *mod_tmp;
647 rc = slap_bv2ad( &old_rdn[0][d_cnt]->la_attr, &desc, &text );
649 if ( rc != LDAP_SUCCESS ) {
651 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
652 "ldbm_back_modrdn: %s: %s (old)\n",
653 text, old_rdn[0][d_cnt]->la_attr.bv_val ));
655 Debug( LDAP_DEBUG_TRACE,
656 "ldbm_back_modrdn: %s: %s (old)\n",
657 text, old_rdn[0][d_cnt]->la_attr.bv_val, 0 );
660 send_ldap_result( conn, op, rc,
661 NULL, text, NULL, NULL );
666 if ( ! access_allowed( be, conn, op, e,
667 desc, &old_rdn[0][d_cnt]->la_value, ACL_WRITE ) ) {
669 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
670 "ldbm_back_modrdn: access "
671 "not allowed to attr \"%s\"\n",
672 old_rdn[0][d_cnt]->la_attr.bv_val ));
674 Debug( LDAP_DEBUG_TRACE,
675 "ldbm_back_modrdn: access not allowed "
676 "to attr \"%s\"\n%s%s",
677 old_rdn[0][d_cnt]->la_attr.bv_val, "", "" );
679 send_ldap_result( conn, op,
680 LDAP_INSUFFICIENT_ACCESS,
681 NULL, NULL, NULL, NULL );
686 /* Remove old value of rdn as an attribute. */
687 mod_tmp = (Modifications *)ch_malloc( sizeof( Modifications )
688 + 2 * sizeof( struct berval ) );
689 mod_tmp->sml_desc = desc;
690 mod_tmp->sml_bvalues = (BerVarray)(mod_tmp+1);
691 mod_tmp->sml_bvalues[0] = old_rdn[0][d_cnt]->la_value;
692 mod_tmp->sml_bvalues[1].bv_val = NULL;
693 mod_tmp->sml_op = LDAP_MOD_DELETE;
694 mod_tmp->sml_next = mod;
698 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
699 "ldbm_back_modrdn: removing old_rdn_val=%s\n", old_rdn[0][d_cnt]->la_value.bv_val ));
701 Debug( LDAP_DEBUG_TRACE,
702 "ldbm_back_modrdn: removing old_rdn_val=%s\n",
703 old_rdn[0][d_cnt]->la_value.bv_val, 0, 0 );
709 /* check for abandon */
710 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
711 if ( op->o_abandon ) {
712 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
715 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
718 if ( dn2id_delete( be, &e->e_nname, e->e_id ) != 0 ) {
719 send_ldap_result( conn, op, LDAP_OTHER,
720 NULL, "DN index delete fail", NULL, NULL );
724 (void) cache_delete_entry( &li->li_cache, e );
727 /* XXX: there is no going back! */
732 e->e_nname = new_ndn;
733 new_dn.bv_val = NULL;
734 new_ndn.bv_val = NULL;
737 if ( dn2id_add( be, &e->e_nname, e->e_id ) != 0 ) {
738 send_ldap_result( conn, op, LDAP_OTHER,
739 NULL, "DN index add failed", NULL, NULL );
743 /* modify memory copy of entry */
744 rc = ldbm_modify_internal( be, conn, op, dn->bv_val, &mod[0], e,
745 &text, textbuf, textlen );
747 if( rc != LDAP_SUCCESS ) {
748 if( rc != SLAPD_ABANDON ) {
749 send_ldap_result( conn, op, rc,
750 NULL, text, NULL, NULL );
753 /* here we may try to delete the newly added dn */
754 if ( dn2id_delete( be, &e->e_nname, e->e_id ) != 0 ) {
755 /* we already are in trouble ... */
762 (void) cache_update_entry( &li->li_cache, e );
764 /* NOTE: after this you must not free new_dn or new_ndn!
765 * They are used by cache.
769 if ( id2entry_add( be, e ) != 0 ) {
770 send_ldap_result( conn, op, LDAP_OTHER,
771 NULL, "entry update failed", NULL, NULL );
775 send_ldap_result( conn, op, LDAP_SUCCESS,
776 NULL, NULL, NULL, NULL );
778 cache_entry_commit( e );
781 if( new_dn.bv_val != NULL ) free( new_dn.bv_val );
782 if( new_ndn.bv_val != NULL ) free( new_ndn.bv_val );
784 /* LDAP v2 supporting correct attribute handling. */
785 if( new_rdn ) ldap_rdnfree( new_rdn );
786 if( old_rdn ) ldap_rdnfree( old_rdn );
790 for (; mod; mod = tmp ) {
796 /* LDAP v3 Support */
798 /* free new parent and writer lock */
799 cache_return_entry_w( &li->li_cache, np );
803 /* free parent and writer lock */
804 cache_return_entry_w( &li->li_cache, p );
808 /* release root writer lock */
809 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
812 /* free entry and writer lock */
813 cache_return_entry_w( &li->li_cache, e );
814 if ( rc == MUST_DESTROY ) {
815 /* if rc == MUST_DESTROY the entry is uncached
816 * and its private data is destroyed;
817 * the entry must be freed */