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"
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 char *p_dn = NULL, *p_ndn = NULL;
52 char *new_dn = NULL, *new_ndn = 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) */
66 char **new_rdn_vals = NULL; /* Vals of new rdn */
67 char **new_rdn_types = NULL; /* Types of new rdn */
69 char *old_rdn = NULL; /* Old rdn's attr type & val */
70 char **old_rdn_types = NULL; /* Types of old rdn attrs. */
71 char **old_rdn_vals = NULL; /* Old rdn attribute values */
72 /* Added to support newSuperior */
73 Entry *np = NULL; /* newSuperior Entry */
74 char *np_dn = NULL; /* newSuperior dn */
75 char *np_ndn = NULL; /* newSuperior ndn */
76 char *new_parent_dn = NULL; /* np_dn, p_dn, or NULL */
77 /* Used to interface with ldbm_modify_internal() */
78 Modifications *mod = NULL; /* Used to delete old/add new rdn */
79 int manageDSAit = get_manageDSAit( op );
82 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
83 "ldbm_back_modrdn: dn: %s newSuperior=%s\n",
84 dn->bv_len ? dn->bv_val : "NULL",
85 newSuperior->bv_len ? newSuperior->bv_val : "NULL" ));
87 Debug( LDAP_DEBUG_TRACE,
88 "==>ldbm_back_modrdn: dn: %s newSuperior=%s\n",
89 dn->bv_len ? dn->bv_val : "NULL",
90 newSuperior->bv_len ? newSuperior->bv_val : "NULL", 0 );
93 /* get entry with writer lock */
94 if ( (e = dn2entry_w( be, ndn->bv_val, &matched )) == NULL ) {
95 char* matched_dn = NULL;
98 if( matched != NULL ) {
99 matched_dn = strdup( matched->e_dn );
100 refs = is_entry_referral( matched )
101 ? get_entry_referrals( be, conn, op, matched,
102 dn->bv_val, LDAP_SCOPE_DEFAULT )
104 cache_return_entry_r( &li->li_cache, matched );
106 refs = referral_rewrite( default_referral,
107 NULL, dn->bv_val, LDAP_SCOPE_DEFAULT );
110 send_ldap_result( conn, op, LDAP_REFERRAL,
111 matched_dn, NULL, refs, NULL );
113 ber_bvecfree( refs );
119 if (!manageDSAit && is_entry_referral( e ) ) {
120 /* parent is a referral, don't allow add */
121 /* parent is an alias, don't allow add */
122 struct berval **refs = get_entry_referrals( be,
123 conn, op, e, dn->bv_val, LDAP_SCOPE_DEFAULT );
126 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
127 "ldbm_back_modrdn: entry %s is a referral\n", e->e_dn ));
129 Debug( LDAP_DEBUG_TRACE, "entry %s is referral\n", e->e_dn,
133 send_ldap_result( conn, op, LDAP_REFERRAL,
134 e->e_dn, NULL, refs, NULL );
136 ber_bvecfree( refs );
140 if ( has_children( be, e ) ) {
142 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
143 "ldbm_back_modrdn: entry %s has children\n", e->e_dn ));
145 Debug( LDAP_DEBUG_TRACE, "entry %s has children\n", e->e_dn,
149 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
150 NULL, "subtree rename not supported", NULL, NULL );
154 if ( (p_ndn = dn_parent( be, e->e_ndn )) != NULL && p_ndn[0] != '\0' ) {
155 /* Make sure parent entry exist and we can write its
159 if( (p = dn2entry_w( be, p_ndn, NULL )) == NULL) {
161 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
162 "ldbm_back_modrdn: parent of %s does not exist\n", e->e_ndn ));
164 Debug( LDAP_DEBUG_TRACE, "parent does not exist\n",
168 send_ldap_result( conn, op, LDAP_OTHER,
169 NULL, "parent entry does not exist", NULL, NULL );
174 /* check parent for "children" acl */
175 if ( ! access_allowed( be, conn, op, p,
176 children, NULL, ACL_WRITE ) )
179 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
180 "ldbm_back_modrdn: no access to parent of (%s)\n", e->e_dn ));
182 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
186 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
187 NULL, NULL, NULL, NULL );
192 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
193 "ldbm_back_modrdn: wr to children of entry %s OK\n",
196 Debug( LDAP_DEBUG_TRACE,
197 "ldbm_back_modrdn: wr to children of entry %s OK\n",
201 p_dn = dn_parent( be, e->e_dn );
204 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
205 "ldbm_back_modrdn: parent dn=%s\n", p_dn ));
207 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: parent dn=%s\n",
212 /* no parent, must be root to modify rdn */
213 isroot = be_isroot( be, &op->o_ndn );
215 if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
216 p = (Entry *)&slap_entry_root;
218 rc = access_allowed( be, conn, op, p,
219 children, NULL, ACL_WRITE );
222 /* check parent for "children" acl */
225 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
226 "ldbm_back_modrdn: no access "
227 "to parent \"\"\n" ));
229 Debug( LDAP_DEBUG_TRACE,
230 "<=- ldbm_back_modrdn: no "
231 "access to parent\n", 0, 0, 0 );
234 send_ldap_result( conn, op,
235 LDAP_INSUFFICIENT_ACCESS,
236 NULL, NULL, NULL, NULL );
242 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
243 "ldbm_back_modrdn: (%s) has no "
244 "parent & not a root.\n", dn ));
246 Debug( LDAP_DEBUG_TRACE,
247 "<=- ldbm_back_modrdn: no parent & "
248 "not root\n", 0, 0, 0);
251 send_ldap_result( conn, op,
252 LDAP_INSUFFICIENT_ACCESS,
253 NULL, NULL, NULL, NULL );
258 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
262 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
263 "ldbm_back_modrdn: (%s) no parent, locked root.\n", e->e_dn ));
265 Debug( LDAP_DEBUG_TRACE,
266 "ldbm_back_modrdn: no parent, locked root\n",
271 new_parent_dn = p_dn; /* New Parent unless newSuperior given */
273 if ( newSuperior != NULL ) {
275 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
276 "ldbm_back_modrdn: new parent \"%s\" requested\n", newSuperior ));
278 Debug( LDAP_DEBUG_TRACE,
279 "ldbm_back_modrdn: new parent \"%s\" requested...\n",
283 np_dn = ch_strdup( newSuperior->bv_val );
284 np_ndn = ch_strdup( np_dn );
285 (void) dn_normalize( np_ndn );
287 /* newSuperior == oldParent? */
288 if ( strcmp( p_ndn, np_ndn ) == 0 ) {
290 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
291 "ldbm_back_modrdn: new parent\"%s\" seems to be the same as the old parent \"%s\"\n",
292 newSuperior, p_dn ));
294 Debug( LDAP_DEBUG_TRACE,
295 "ldbm_back_modrdn: new parent \"%s\" seems to be the same as old parent \"%s\"...\n",
296 newSuperior, p_dn, 0 );
299 newSuperior = NULL; /* ignore newSuperior */
303 if ( newSuperior != NULL ) {
304 /* newSuperior == entry being moved?, if so ==> ERROR */
305 /* Get Entry with dn=newSuperior. Does newSuperior exist? */
307 if ( nnewSuperior->bv_len ) {
308 if( (np = dn2entry_w( be, np_ndn, NULL )) == NULL) {
310 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
311 "ldbm_back_modrdn: newSup(ndn=%s) not found.\n", np_ndn ));
313 Debug( LDAP_DEBUG_TRACE,
314 "ldbm_back_modrdn: newSup(ndn=%s) not here!\n",
318 send_ldap_result( conn, op, LDAP_OTHER,
319 NULL, "newSuperior not found", NULL, NULL );
324 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
325 "ldbm_back_modrdn: wr to new parent OK np=%p, id=%ld\n",
328 Debug( LDAP_DEBUG_TRACE,
329 "ldbm_back_modrdn: wr to new parent OK np=%p, id=%ld\n",
333 /* check newSuperior for "children" acl */
334 if ( !access_allowed( be, conn, op, np, children, NULL,
338 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
339 "ldbm_back_modrdn: no wr to newSup children.\n" ));
341 Debug( LDAP_DEBUG_TRACE,
342 "ldbm_back_modrdn: no wr to newSup children\n",
346 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
347 NULL, NULL, NULL, NULL );
351 if ( is_entry_alias( np ) ) {
352 /* parent is an alias, don't allow add */
354 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
355 "ldbm_back_modrdn: entry (%s) is an alias.\n", np->e_dn ));
357 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0, 0, 0 );
361 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
362 NULL, "newSuperior is an alias", NULL, NULL );
367 if ( is_entry_referral( np ) ) {
368 /* parent is a referral, don't allow add */
370 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
371 "ldbm_back_modrdn: entry (%s) is a referral\n",
374 Debug( LDAP_DEBUG_TRACE, "entry (%s) is referral\n",
378 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
379 NULL, "newSuperior is a referral", NULL, NULL );
386 /* no parent, must be root to modify newSuperior */
387 if ( isroot == -1 ) {
388 isroot = be_isroot( be, &op->o_ndn );
392 if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
393 np = (Entry *)&slap_entry_root;
395 rc = access_allowed( be, conn, op, np,
396 children, NULL, ACL_WRITE );
399 /* check parent for "children" acl */
402 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
403 "ldbm_back_modrdn: no access "
404 "to new superior \"\"\n" ));
406 Debug( LDAP_DEBUG_TRACE,
407 "<=- ldbm_back_modrdn: no "
408 "access to new superior\n", 0, 0, 0 );
411 send_ldap_result( conn, op,
412 LDAP_INSUFFICIENT_ACCESS,
413 NULL, NULL, NULL, NULL );
419 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
420 "ldbm_back_modrdn: \"\" "
421 "not allowed as new superior\n" ));
423 Debug( LDAP_DEBUG_TRACE,
424 "<=- ldbm_back_modrdn: \"\" "
425 "not allowed as new superior\n",
429 send_ldap_result( conn, op,
430 LDAP_INSUFFICIENT_ACCESS,
431 NULL, NULL, NULL, NULL );
438 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
439 "ldbm_back_modrdn: wr to new parent's children OK.\n" ));
441 Debug( LDAP_DEBUG_TRACE,
442 "ldbm_back_modrdn: wr to new parent's children OK\n",
446 new_parent_dn = np_dn;
449 /* Build target dn and make sure target entry doesn't exist already. */
450 build_new_dn( &new_dn, e->e_dn, new_parent_dn, newrdn->bv_val );
452 new_ndn = ch_strdup( new_dn );
453 (void) dn_normalize( new_ndn );
456 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
457 "ldbm_back_modrdn: new ndn=%s\n", new_ndn ));
459 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: new ndn=%s\n",
463 /* check for abandon */
464 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
465 if ( op->o_abandon ) {
466 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
470 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
471 if ( ( rc_id = dn2id ( be, new_ndn, &id ) ) || id != NOID ) {
472 /* if (rc_id) something bad happened to ldbm cache */
473 send_ldap_result( conn, op,
474 rc_id ? LDAP_OPERATIONS_ERROR : LDAP_ALREADY_EXISTS,
475 NULL, NULL, NULL, NULL );
480 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
481 "ldbm_back_modrdn: new ndn (%s) does not exist\n", new_ndn ));
483 Debug( LDAP_DEBUG_TRACE,
484 "ldbm_back_modrdn: new ndn=%s does not exist\n",
489 /* Get attribute types and values of our new rdn, we will
490 * need to add that to our new entry
492 if ( rdn_attrs( newrdn->bv_val, &new_rdn_types, &new_rdn_vals ) ) {
494 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
495 "ldbm_back_modrdn: can't figure out type(s)/value(s) of newrdn\n" ));
497 Debug( LDAP_DEBUG_TRACE,
498 "ldbm_back_modrdn: can't figure out type(s)/value(s) of newrdn\n",
502 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
503 NULL, "unable to parse type(s)/value(s) used in RDN", NULL, NULL );
508 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
509 "ldbm_back_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
510 new_rdn_vals[0], new_rdn_types[0] ));
512 Debug( LDAP_DEBUG_TRACE,
513 "ldbm_back_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
514 new_rdn_vals[0], new_rdn_types[0], 0 );
517 /* Retrieve the old rdn from the entry's dn */
518 if ( (old_rdn = dn_rdn( be, dn->bv_val )) == NULL ) {
520 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
521 "ldbm_back_modrdn: can't figure out old_rdn from dn (%s)\n",
524 Debug( LDAP_DEBUG_TRACE,
525 "ldbm_back_modrdn: can't figure out old_rdn from dn\n",
529 send_ldap_result( conn, op, LDAP_OTHER,
530 NULL, "could not parse old DN", NULL, NULL );
534 if ( rdn_attrs( old_rdn, &old_rdn_types, &old_rdn_vals ) ) {
536 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
537 "ldbm_back_modrdn: can't figure out the old_rdn type(s)/value(s).\n" ));
539 Debug( LDAP_DEBUG_TRACE,
540 "ldbm_back_modrdn: can't figure out the old_rdn type(s)/value(s)\n",
544 send_ldap_result( conn, op, LDAP_OTHER,
545 NULL, "unable to parse type(s)/value(s) used in RDN from old DN", NULL, NULL );
549 if ( newSuperior == NULL
550 && charray_strcasecmp( (const char **)old_rdn_types, (const char **)new_rdn_types ) != 0 )
552 /* Not a big deal but we may say something */
554 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
555 "ldbm_back_modrdn: old_rdn_type=%s new_rdn_type=%s\n",
556 old_rdn_types[0], new_rdn_types[0] ));
558 Debug( LDAP_DEBUG_TRACE,
559 "ldbm_back_modrdn: old_rdn_type=%s, new_rdn_type=%s!\n",
560 old_rdn_types[0], new_rdn_types[0], 0 );
565 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
566 "ldbm_back_modrdn: DN_X500\n" ));
568 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: DN_X500\n",
573 for ( a_cnt = 0; new_rdn_types[a_cnt]; a_cnt++ ) {
575 AttributeDescription *desc = NULL;
576 Modifications *mod_tmp;
580 rc = slap_str2ad( new_rdn_types[a_cnt], &desc, &text );
582 if ( rc != LDAP_SUCCESS ) {
584 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
585 "ldbm_back_modrdn: slap_str2ad error: %s (%s)\n",
586 text, new_rdn_types[a_cnt] ));
588 Debug( LDAP_DEBUG_TRACE,
589 "ldbm_back_modrdn: %s: %s (new)\n",
590 text, new_rdn_types[a_cnt], 0 );
593 send_ldap_result( conn, op, rc,
594 NULL, text, NULL, NULL );
599 val.bv_val = new_rdn_vals[a_cnt];
600 val.bv_len = strlen( val.bv_val );
601 if ( ! access_allowed( be, conn, op, e,
602 desc, &val, ACL_WRITE ) ) {
604 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
605 "ldbm_back_modrdn: access "
606 "not allowed to attr \"%s\"\n",
607 new_rdn_types[a_cnt] ));
609 Debug( LDAP_DEBUG_TRACE,
610 "ldbm_back_modrdn: access not allowed "
611 "to attr \"%s\"\n%s%s",
612 new_rdn_types[a_cnt], "", "" );
614 send_ldap_result( conn, op,
615 LDAP_INSUFFICIENT_ACCESS,
616 NULL, NULL, NULL, NULL );
621 mod_tmp = (Modifications *)ch_malloc( sizeof( Modifications ) );
622 mod_tmp->sml_desc = desc;
623 mod_tmp->sml_bvalues = (struct berval **)ch_malloc( 2 * sizeof(struct berval *) );
624 mod_tmp->sml_bvalues[0] = ber_bvstrdup( new_rdn_vals[a_cnt] );
625 mod_tmp->sml_bvalues[1] = NULL;
626 mod_tmp->sml_op = SLAP_MOD_SOFTADD;
627 mod_tmp->sml_next = mod;
631 /* Remove old rdn value if required */
632 if ( deleteoldrdn ) {
633 /* Get value of old rdn */
634 if ( old_rdn_vals == NULL ) {
636 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
637 "ldbm_back_modrdn: can't figure out old RDN value(s) from old RDN\n" ));
639 Debug( LDAP_DEBUG_TRACE,
640 "ldbm_back_modrdn: can't figure out oldRDN value(s) from old RDN\n",
644 send_ldap_result( conn, op, LDAP_OTHER,
645 NULL, "could not parse value(s) from old RDN", NULL, NULL );
649 for ( d_cnt = 0; old_rdn_types[d_cnt]; d_cnt++ ) {
651 AttributeDescription *desc = NULL;
652 Modifications *mod_tmp;
656 rc = slap_str2ad( old_rdn_types[d_cnt], &desc, &text );
658 if ( rc != LDAP_SUCCESS ) {
660 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
661 "ldbm_back_modrdn: %s: %s (old)\n",
662 text, old_rdn_types[d_cnt] ));
664 Debug( LDAP_DEBUG_TRACE,
665 "ldbm_back_modrdn: %s: %s (old)\n",
666 text, old_rdn_types[d_cnt], 0 );
669 send_ldap_result( conn, op, rc,
670 NULL, text, NULL, NULL );
675 val.bv_val = old_rdn_vals[d_cnt];
676 val.bv_len = strlen( val.bv_val );
677 if ( ! access_allowed( be, conn, op, e,
678 desc, &val, ACL_WRITE ) ) {
680 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
681 "ldbm_back_modrdn: access "
682 "not allowed to attr \"%s\"\n",
683 old_rdn_types[d_cnt] ));
685 Debug( LDAP_DEBUG_TRACE,
686 "ldbm_back_modrdn: access not allowed "
687 "to attr \"%s\"\n%s%s",
688 old_rdn_types[d_cnt], "", "" );
690 send_ldap_result( conn, op,
691 LDAP_INSUFFICIENT_ACCESS,
692 NULL, NULL, NULL, NULL );
697 /* Remove old value of rdn as an attribute. */
698 mod_tmp = (Modifications *)ch_malloc( sizeof( Modifications ) );
699 mod_tmp->sml_desc = desc;
700 mod_tmp->sml_bvalues = (struct berval **)ch_malloc( 2 * sizeof(struct berval *) );
701 mod_tmp->sml_bvalues[0] = ber_bvstrdup( old_rdn_vals[d_cnt] );
702 mod_tmp->sml_bvalues[1] = NULL;
703 mod_tmp->sml_op = LDAP_MOD_DELETE;
704 mod_tmp->sml_next = mod;
708 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
709 "ldbm_back_modrdn: removing old_rdn_val=%s\n", old_rdn_vals[0] ));
711 Debug( LDAP_DEBUG_TRACE,
712 "ldbm_back_modrdn: removing old_rdn_val=%s\n",
713 old_rdn_vals[0], 0, 0 );
719 /* check for abandon */
720 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
721 if ( op->o_abandon ) {
722 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
725 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
728 if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
729 send_ldap_result( conn, op, LDAP_OTHER,
730 NULL, "DN index delete fail", NULL, NULL );
734 (void) cache_delete_entry( &li->li_cache, e );
737 /* XXX: there is no going back! */
742 e->e_name.bv_len = strlen( new_dn );
744 e->e_nname.bv_len = strlen( new_ndn );
749 if ( dn2id_add( be, e->e_ndn, e->e_id ) != 0 ) {
750 send_ldap_result( conn, op, LDAP_OTHER,
751 NULL, "DN index add failed", NULL, NULL );
755 /* modify memory copy of entry */
756 rc = ldbm_modify_internal( be, conn, op, dn->bv_val, &mod[0], e,
757 &text, textbuf, textlen );
759 if( rc != LDAP_SUCCESS ) {
760 if( rc != SLAPD_ABANDON ) {
761 send_ldap_result( conn, op, rc,
762 NULL, text, NULL, NULL );
765 /* here we may try to delete the newly added dn */
766 if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
767 /* we already are in trouble ... */
774 (void) cache_update_entry( &li->li_cache, e );
776 /* NOTE: after this you must not free new_dn or new_ndn!
777 * They are used by cache.
781 if ( id2entry_add( be, e ) != 0 ) {
782 send_ldap_result( conn, op, LDAP_OTHER,
783 NULL, "entry update failed", NULL, NULL );
787 send_ldap_result( conn, op, LDAP_SUCCESS,
788 NULL, NULL, NULL, NULL );
790 cache_entry_commit( e );
793 if( new_dn != NULL ) free( new_dn );
794 if( new_ndn != NULL ) free( new_ndn );
796 /* LDAP v2 supporting correct attribute handling. */
797 if( new_rdn_types != NULL ) charray_free( new_rdn_types );
798 if( new_rdn_vals != NULL ) charray_free( new_rdn_vals );
799 if( old_rdn != NULL ) free(old_rdn);
800 if( old_rdn_types != NULL ) charray_free( old_rdn_types );
801 if( old_rdn_vals != NULL ) charray_free( old_rdn_vals );
804 slap_mods_free( mod );
807 /* LDAP v3 Support */
808 if ( np_dn != NULL ) free( np_dn );
809 if ( np_ndn != NULL ) free( np_ndn );
812 /* free new parent and writer lock */
813 cache_return_entry_w( &li->li_cache, np );
817 /* free parent and writer lock */
818 cache_return_entry_w( &li->li_cache, p );
822 /* release root writer lock */
823 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
826 /* free entry and writer lock */
827 cache_return_entry_w( &li->li_cache, e );
828 if ( rc == MUST_DESTROY ) {
829 /* if rc == MUST_DESTROY the entry is uncached
830 * and its private data is destroyed;
831 * the entry must be freed */