1 /* modrdn.c - ldbm backend modrdn routine */
4 * Copyright 1998-2000 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"
44 const char *newSuperior
47 AttributeDescription *children = slap_schema.si_ad_children;
48 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
49 char *p_dn = NULL, *p_ndn = NULL;
50 char *new_dn = NULL, *new_ndn = NULL;
55 #define CAN_ROLLBACK -1
56 #define MUST_DESTROY 1
57 int rc = CAN_ROLLBACK;
60 const char *text = NULL;
61 char textbuf[SLAP_TEXT_BUFLEN];
62 size_t textlen = sizeof textbuf;
63 /* Added to support LDAP v2 correctly (deleteoldrdn thing) */
64 char **new_rdn_vals = NULL; /* Vals of new rdn */
65 char **new_rdn_types = NULL; /* Types of new rdn */
67 char *old_rdn = NULL; /* Old rdn's attr type & val */
68 char **old_rdn_types = NULL; /* Types of old rdn attrs. */
69 char **old_rdn_vals = NULL; /* Old rdn attribute values */
70 /* Added to support newSuperior */
71 Entry *np = NULL; /* newSuperior Entry */
72 char *np_dn = NULL; /* newSuperior dn */
73 char *np_ndn = NULL; /* newSuperior ndn */
74 char *new_parent_dn = NULL; /* np_dn, p_dn, or NULL */
75 /* Used to interface with ldbm_modify_internal() */
76 Modifications *mod = NULL; /* Used to delete old/add new rdn */
77 int manageDSAit = get_manageDSAit( op );
80 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
81 "ldbm_back_modrdn: dn: %s newSuperior=%s\n",
82 dn ? dn : "NULL", newSuperior ? newSuperior : "NULL" ));
84 Debug( LDAP_DEBUG_TRACE, "==>ldbm_back_modrdn(newSuperior=%s)\n",
85 (newSuperior ? newSuperior : "NULL"),
89 /* get entry with writer lock */
90 if ( (e = dn2entry_w( be, ndn, &matched )) == NULL ) {
91 char* matched_dn = NULL;
94 if( matched != NULL ) {
95 matched_dn = strdup( matched->e_dn );
96 refs = is_entry_referral( matched )
97 ? get_entry_referrals( be, conn, op, matched,
98 dn, LDAP_SCOPE_DEFAULT )
100 cache_return_entry_r( &li->li_cache, matched );
102 refs = referral_rewrite( default_referral,
103 NULL, dn, LDAP_SCOPE_DEFAULT );
106 send_ldap_result( conn, op, LDAP_REFERRAL,
107 matched_dn, NULL, refs, NULL );
109 ber_bvecfree( refs );
115 if (!manageDSAit && is_entry_referral( e ) ) {
116 /* parent is a referral, don't allow add */
117 /* parent is an alias, don't allow add */
118 struct berval **refs = get_entry_referrals( be,
119 conn, op, e, dn, LDAP_SCOPE_DEFAULT );
122 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
123 "ldbm_back_modrdn: entry %s is a referral\n", e->e_dn ));
125 Debug( LDAP_DEBUG_TRACE, "entry %s is referral\n", e->e_dn,
129 send_ldap_result( conn, op, LDAP_REFERRAL,
130 e->e_dn, NULL, refs, NULL );
132 ber_bvecfree( refs );
136 if ( has_children( be, e ) ) {
138 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
139 "ldbm_back_modrdn: entry %s has children\n", e->e_dn ));
141 Debug( LDAP_DEBUG_TRACE, "entry %s has children\n", e->e_dn,
145 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
146 NULL, "subtree rename not supported", NULL, NULL );
150 if ( (p_ndn = dn_parent( be, e->e_ndn )) != NULL && p_ndn[0] != '\0' ) {
151 /* Make sure parent entry exist and we can write its
155 if( (p = dn2entry_w( be, p_ndn, NULL )) == NULL) {
157 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
158 "ldbm_back_modrdn: parent of %s does not exist\n", e->e_ndn ));
160 Debug( LDAP_DEBUG_TRACE, "parent does not exist\n",
164 send_ldap_result( conn, op, LDAP_OTHER,
165 NULL, "parent entry does not exist", NULL, NULL );
170 /* check parent for "children" acl */
171 if ( ! access_allowed( be, conn, op, p,
172 children, NULL, ACL_WRITE ) )
175 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
176 "ldbm_back_modrdn: no access to parent of (%s)\n", e->e_dn ));
178 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
182 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
183 NULL, NULL, NULL, NULL );
188 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
189 "ldbm_back_modrdn: wr to children of entry %s OK\n",
192 Debug( LDAP_DEBUG_TRACE,
193 "ldbm_back_modrdn: wr to children of entry %s OK\n",
197 p_dn = dn_parent( be, e->e_dn );
200 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
201 "ldbm_back_modrdn: parent dn=%s\n", p_dn ));
203 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: parent dn=%s\n",
208 /* no parent, must be root to modify rdn */
209 isroot = be_isroot( be, &op->o_ndn );
211 if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
212 p = (Entry *)&slap_entry_root;
214 rc = access_allowed( be, conn, op, p,
215 children, NULL, ACL_WRITE );
218 /* check parent for "children" acl */
221 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
222 "ldbm_back_modrdn: no access "
223 "to parent \"\"\n" ));
225 Debug( LDAP_DEBUG_TRACE,
226 "<=- ldbm_back_modrdn: no "
227 "access to parent\n", 0, 0, 0 );
230 send_ldap_result( conn, op,
231 LDAP_INSUFFICIENT_ACCESS,
232 NULL, NULL, NULL, NULL );
238 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
239 "ldbm_back_modrdn: (%s) has no "
240 "parent & not a root.\n", dn ));
242 Debug( LDAP_DEBUG_TRACE,
243 "<=- ldbm_back_modrdn: no parent & "
244 "not root\n", 0, 0, 0);
247 send_ldap_result( conn, op,
248 LDAP_INSUFFICIENT_ACCESS,
249 NULL, NULL, NULL, NULL );
254 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
258 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
259 "ldbm_back_modrdn: (%s) no parent, locked root.\n", e->e_dn ));
261 Debug( LDAP_DEBUG_TRACE,
262 "ldbm_back_modrdn: no parent, locked root\n",
267 new_parent_dn = p_dn; /* New Parent unless newSuperior given */
269 if ( newSuperior != NULL ) {
271 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
272 "ldbm_back_modrdn: new parent \"%s\" requested\n", newSuperior ));
274 Debug( LDAP_DEBUG_TRACE,
275 "ldbm_back_modrdn: new parent \"%s\" requested...\n",
279 np_dn = ch_strdup( newSuperior );
280 np_ndn = ch_strdup( np_dn );
281 (void) dn_normalize( np_ndn );
283 /* newSuperior == oldParent? */
284 if ( strcmp( p_ndn, np_ndn ) == 0 ) {
286 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
287 "ldbm_back_modrdn: new parent\"%s\" seems to be the same as the old parent \"%s\"\n",
288 newSuperior, p_dn ));
290 Debug( LDAP_DEBUG_TRACE,
291 "ldbm_back_modrdn: new parent \"%s\" seems to be the same as old parent \"%s\"...\n",
292 newSuperior, p_dn, 0 );
295 newSuperior = NULL; /* ignore newSuperior */
299 if ( newSuperior != NULL ) {
300 /* newSuperior == entry being moved?, if so ==> ERROR */
301 /* Get Entry with dn=newSuperior. Does newSuperior exist? */
303 if ( newSuperior[ 0 ] != '\0' ) {
305 if( (np = dn2entry_w( be, np_ndn, NULL )) == NULL) {
307 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
308 "ldbm_back_modrdn: newSup(ndn=%s) not found.\n", np_ndn ));
310 Debug( LDAP_DEBUG_TRACE,
311 "ldbm_back_modrdn: newSup(ndn=%s) not here!\n",
315 send_ldap_result( conn, op, LDAP_OTHER,
316 NULL, "newSuperior not found", NULL, NULL );
321 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
322 "ldbm_back_modrdn: wr to new parent OK np=%p, id=%ld\n",
325 Debug( LDAP_DEBUG_TRACE,
326 "ldbm_back_modrdn: wr to new parent OK np=%p, id=%ld\n",
330 /* check newSuperior for "children" acl */
331 if ( !access_allowed( be, conn, op, np, children, NULL,
335 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
336 "ldbm_back_modrdn: no wr to newSup children.\n" ));
338 Debug( LDAP_DEBUG_TRACE,
339 "ldbm_back_modrdn: no wr to newSup children\n",
343 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
344 NULL, NULL, NULL, NULL );
348 if ( is_entry_alias( np ) ) {
349 /* parent is an alias, don't allow add */
351 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
352 "ldbm_back_modrdn: entry (%s) is an alias.\n", np->e_dn ));
354 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0, 0, 0 );
358 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
359 NULL, "newSuperior is an alias", NULL, NULL );
364 if ( is_entry_referral( np ) ) {
365 /* parent is a referral, don't allow add */
367 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
368 "ldbm_back_modrdn: entry (%s) is a referral\n",
371 Debug( LDAP_DEBUG_TRACE, "entry (%s) is referral\n",
375 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
376 NULL, "newSuperior is a referral", NULL, NULL );
383 /* no parent, must be root to modify newSuperior */
384 if ( isroot == -1 ) {
385 isroot = be_isroot( be, &op->o_ndn );
389 if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
390 np = (Entry *)&slap_entry_root;
392 rc = access_allowed( be, conn, op, np,
393 children, NULL, ACL_WRITE );
396 /* check parent for "children" acl */
399 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
400 "ldbm_back_modrdn: no access "
401 "to new superior \"\"\n" ));
403 Debug( LDAP_DEBUG_TRACE,
404 "<=- ldbm_back_modrdn: no "
405 "access to new superior\n", 0, 0, 0 );
408 send_ldap_result( conn, op,
409 LDAP_INSUFFICIENT_ACCESS,
410 NULL, NULL, NULL, NULL );
416 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
417 "ldbm_back_modrdn: \"\" "
418 "not allowed as new superior\n" ));
420 Debug( LDAP_DEBUG_TRACE,
421 "<=- ldbm_back_modrdn: \"\" "
422 "not allowed as new superior\n",
426 send_ldap_result( conn, op,
427 LDAP_INSUFFICIENT_ACCESS,
428 NULL, NULL, NULL, NULL );
435 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
436 "ldbm_back_modrdn: wr to new parent's children OK.\n" ));
438 Debug( LDAP_DEBUG_TRACE,
439 "ldbm_back_modrdn: wr to new parent's children OK\n",
443 new_parent_dn = np_dn;
446 /* Build target dn and make sure target entry doesn't exist already. */
447 build_new_dn( &new_dn, e->e_dn, new_parent_dn, newrdn );
449 new_ndn = ch_strdup(new_dn);
450 (void) dn_normalize( new_ndn );
453 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
454 "ldbm_back_modrdn: new ndn=%s\n", new_ndn ));
456 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: new ndn=%s\n",
460 /* check for abandon */
461 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
462 if ( op->o_abandon ) {
463 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
467 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
468 if ( ( rc_id = dn2id ( be, new_ndn, &id ) ) || id != NOID ) {
469 /* if (rc_id) something bad happened to ldbm cache */
470 send_ldap_result( conn, op,
471 rc_id ? LDAP_OPERATIONS_ERROR : LDAP_ALREADY_EXISTS,
472 NULL, NULL, NULL, NULL );
477 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
478 "ldbm_back_modrdn: new ndn (%s) does not exist\n", new_ndn ));
480 Debug( LDAP_DEBUG_TRACE,
481 "ldbm_back_modrdn: new ndn=%s does not exist\n",
486 /* Get attribute types and values of our new rdn, we will
487 * need to add that to our new entry
489 if ( rdn_attrs( newrdn, &new_rdn_types, &new_rdn_vals ) ) {
491 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
492 "ldbm_back_modrdn: can't figure out type(s)/value(s) of newrdn\n" ));
494 Debug( LDAP_DEBUG_TRACE,
495 "ldbm_back_modrdn: can't figure out type(s)/value(s) of newrdn\n",
499 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
500 NULL, "unable to parse type(s)/value(s) used in RDN", NULL, NULL );
505 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
506 "ldbm_back_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
507 new_rdn_vals[0], new_rdn_types[0] ));
509 Debug( LDAP_DEBUG_TRACE,
510 "ldbm_back_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
511 new_rdn_vals[0], new_rdn_types[0], 0 );
514 /* Retrieve the old rdn from the entry's dn */
515 if ( (old_rdn = dn_rdn( be, dn )) == NULL ) {
517 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
518 "ldbm_back_modrdn: can't figure out old_rdn from dn (%s)\n",
521 Debug( LDAP_DEBUG_TRACE,
522 "ldbm_back_modrdn: can't figure out old_rdn from dn\n",
526 send_ldap_result( conn, op, LDAP_OTHER,
527 NULL, "could not parse old DN", NULL, NULL );
531 if ( rdn_attrs( old_rdn, &old_rdn_types, &old_rdn_vals ) ) {
533 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
534 "ldbm_back_modrdn: can't figure out the old_rdn type(s)/value(s).\n" ));
536 Debug( LDAP_DEBUG_TRACE,
537 "ldbm_back_modrdn: can't figure out the old_rdn type(s)/value(s)\n",
541 send_ldap_result( conn, op, LDAP_OTHER,
542 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 );
562 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
563 "ldbm_back_modrdn: DN_X500\n" ));
565 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: DN_X500\n",
570 for ( a_cnt = 0; new_rdn_types[a_cnt]; a_cnt++ ) {
572 AttributeDescription *desc = NULL;
573 Modifications *mod_tmp;
577 rc = slap_str2ad( new_rdn_types[a_cnt], &desc, &text );
579 if ( rc != LDAP_SUCCESS ) {
581 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
582 "ldbm_back_modrdn: slap_str2ad error: %s (%s)\n",
583 text, new_rdn_types[a_cnt] ));
585 Debug( LDAP_DEBUG_TRACE,
586 "ldbm_back_modrdn: %s: %s (new)\n",
587 text, new_rdn_types[a_cnt], 0 );
590 send_ldap_result( conn, op, rc,
591 NULL, text, NULL, NULL );
596 val.bv_val = new_rdn_vals[a_cnt];
597 val.bv_len = strlen( val.bv_val );
598 if ( ! access_allowed( be, conn, op, e,
599 desc, &val, ACL_WRITE ) ) {
601 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
602 "ldbm_back_modrdn: access "
603 "not allowed to attr \"%s\"\n",
604 new_rdn_types[a_cnt] ));
606 Debug( LDAP_DEBUG_TRACE,
607 "ldbm_back_modrdn: access not allowed "
608 "to attr \"%s\"\n%s%s",
609 new_rdn_types[a_cnt], "", "" );
611 send_ldap_result( conn, op,
612 LDAP_INSUFFICIENT_ACCESS,
613 NULL, NULL, NULL, NULL );
618 mod_tmp = (Modifications *)ch_malloc( sizeof( Modifications ) );
619 mod_tmp->sml_desc = desc;
620 mod_tmp->sml_bvalues = (struct berval **)ch_malloc( 2 * sizeof(struct berval *) );
621 mod_tmp->sml_bvalues[0] = ber_bvstrdup( new_rdn_vals[a_cnt] );
622 mod_tmp->sml_bvalues[1] = NULL;
623 mod_tmp->sml_op = SLAP_MOD_SOFTADD;
624 mod_tmp->sml_next = mod;
628 /* Remove old rdn value if required */
629 if ( deleteoldrdn ) {
630 /* Get value of old rdn */
631 if ( old_rdn_vals == NULL ) {
633 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
634 "ldbm_back_modrdn: can't figure out old RDN value(s) from old RDN\n" ));
636 Debug( LDAP_DEBUG_TRACE,
637 "ldbm_back_modrdn: can't figure out oldRDN value(s) from old RDN\n",
641 send_ldap_result( conn, op, LDAP_OTHER,
642 NULL, "could not parse value(s) from old RDN", NULL, NULL );
646 for ( d_cnt = 0; old_rdn_types[d_cnt]; d_cnt++ ) {
648 AttributeDescription *desc = NULL;
649 Modifications *mod_tmp;
653 rc = slap_str2ad( old_rdn_types[d_cnt], &desc, &text );
655 if ( rc != LDAP_SUCCESS ) {
657 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
658 "ldbm_back_modrdn: %s: %s (old)\n",
659 text, old_rdn_types[d_cnt] ));
661 Debug( LDAP_DEBUG_TRACE,
662 "ldbm_back_modrdn: %s: %s (old)\n",
663 text, old_rdn_types[d_cnt], 0 );
666 send_ldap_result( conn, op, rc,
667 NULL, text, NULL, NULL );
672 val.bv_val = old_rdn_vals[d_cnt];
673 val.bv_len = strlen( val.bv_val );
674 if ( ! access_allowed( be, conn, op, e,
675 desc, &val, ACL_WRITE ) ) {
677 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
678 "ldbm_back_modrdn: access "
679 "not allowed to attr \"%s\"\n",
680 old_rdn_types[d_cnt] ));
682 Debug( LDAP_DEBUG_TRACE,
683 "ldbm_back_modrdn: access not allowed "
684 "to attr \"%s\"\n%s%s",
685 old_rdn_types[d_cnt], "", "" );
687 send_ldap_result( conn, op,
688 LDAP_INSUFFICIENT_ACCESS,
689 NULL, NULL, NULL, NULL );
694 /* Remove old value of rdn as an attribute. */
695 mod_tmp = (Modifications *)ch_malloc( sizeof( Modifications ) );
696 mod_tmp->sml_desc = desc;
697 mod_tmp->sml_bvalues = (struct berval **)ch_malloc( 2 * sizeof(struct berval *) );
698 mod_tmp->sml_bvalues[0] = ber_bvstrdup( old_rdn_vals[d_cnt] );
699 mod_tmp->sml_bvalues[1] = NULL;
700 mod_tmp->sml_op = LDAP_MOD_DELETE;
701 mod_tmp->sml_next = mod;
705 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
706 "ldbm_back_modrdn: removing old_rdn_val=%s\n", old_rdn_vals[0] ));
708 Debug( LDAP_DEBUG_TRACE,
709 "ldbm_back_modrdn: removing old_rdn_val=%s\n",
710 old_rdn_vals[0], 0, 0 );
716 /* check for abandon */
717 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
718 if ( op->o_abandon ) {
719 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
722 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
725 if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
726 send_ldap_result( conn, op, LDAP_OTHER,
727 NULL, "DN index delete fail", NULL, NULL );
731 (void) cache_delete_entry( &li->li_cache, e );
734 /* XXX: there is no going back! */
739 e->e_name.bv_len = strlen( new_dn );
741 e->e_nname.bv_len = strlen( new_ndn );
746 if ( dn2id_add( be, e->e_ndn, e->e_id ) != 0 ) {
747 send_ldap_result( conn, op, LDAP_OTHER,
748 NULL, "DN index add failed", NULL, NULL );
752 /* modify memory copy of entry */
753 rc = ldbm_modify_internal( be, conn, op, dn, &mod[0], e,
754 &text, textbuf, textlen );
756 if( rc != LDAP_SUCCESS ) {
757 if( rc != SLAPD_ABANDON ) {
758 send_ldap_result( conn, op, rc,
759 NULL, text, NULL, NULL );
762 /* here we may try to delete the newly added dn */
763 if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
764 /* we already are in trouble ... */
771 (void) cache_update_entry( &li->li_cache, e );
773 /* NOTE: after this you must not free new_dn or new_ndn!
774 * They are used by cache.
778 if ( id2entry_add( be, e ) != 0 ) {
779 send_ldap_result( conn, op, LDAP_OTHER,
780 NULL, "entry update failed", NULL, NULL );
784 send_ldap_result( conn, op, LDAP_SUCCESS,
785 NULL, NULL, NULL, NULL );
787 cache_entry_commit( e );
790 if( new_dn != NULL ) free( new_dn );
791 if( new_ndn != NULL ) free( new_ndn );
793 /* LDAP v2 supporting correct attribute handling. */
794 if( new_rdn_types != NULL ) charray_free( new_rdn_types );
795 if( new_rdn_vals != NULL ) charray_free( new_rdn_vals );
796 if( old_rdn != NULL ) free(old_rdn);
797 if( old_rdn_types != NULL ) charray_free( old_rdn_types );
798 if( old_rdn_vals != NULL ) charray_free( old_rdn_vals );
801 slap_mods_free( mod );
804 /* LDAP v3 Support */
805 if ( np_dn != NULL ) free( np_dn );
806 if ( np_ndn != NULL ) free( np_ndn );
809 /* free new parent and writer lock */
810 cache_return_entry_w( &li->li_cache, np );
814 /* free parent and writer lock */
815 cache_return_entry_w( &li->li_cache, p );
819 /* release root writer lock */
820 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
823 /* free entry and writer lock */
824 cache_return_entry_w( &li->li_cache, e );
825 if ( rc == MUST_DESTROY ) {
826 /* if rc == MUST_DESTROY the entry is uncached
827 * and its private data is destroyed;
828 * the entry must be freed */