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, "" ) ) {
212 static const Entry rootp = { NOID, "", "", NULL, NULL };
215 rc = access_allowed( be, conn, op, p,
216 children, NULL, ACL_WRITE );
219 /* check parent for "children" acl */
222 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
223 "ldbm_back_modrdn: no access "
224 "to parent \"\"\n" ));
226 Debug( LDAP_DEBUG_TRACE,
227 "<=- ldbm_back_modrdn: no "
228 "access to parent\n", 0, 0, 0 );
231 send_ldap_result( conn, op,
232 LDAP_INSUFFICIENT_ACCESS,
233 NULL, NULL, NULL, NULL );
239 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
240 "ldbm_back_modrdn: (%s) has no "
241 "parent & not a root.\n", dn ));
243 Debug( LDAP_DEBUG_TRACE,
244 "<=- ldbm_back_modrdn: no parent & "
245 "not root\n", 0, 0, 0);
248 send_ldap_result( conn, op,
249 LDAP_INSUFFICIENT_ACCESS,
250 NULL, NULL, NULL, NULL );
255 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
259 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
260 "ldbm_back_modrdn: (%s) no parent, locked root.\n", e->e_dn ));
262 Debug( LDAP_DEBUG_TRACE,
263 "ldbm_back_modrdn: no parent, locked root\n",
268 new_parent_dn = p_dn; /* New Parent unless newSuperior given */
270 if ( newSuperior != NULL ) {
272 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
273 "ldbm_back_modrdn: new parent \"%s\" requested\n", newSuperior ));
275 Debug( LDAP_DEBUG_TRACE,
276 "ldbm_back_modrdn: new parent \"%s\" requested...\n",
280 np_dn = ch_strdup( newSuperior );
281 np_ndn = ch_strdup( np_dn );
282 (void) dn_normalize( np_ndn );
284 /* newSuperior == oldParent? */
285 if ( strcmp( p_ndn, np_ndn ) == 0 ) {
287 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
288 "ldbm_back_modrdn: new parent\"%s\" seems to be the same as the old parent \"%s\"\n",
289 newSuperior, p_dn ));
291 Debug( LDAP_DEBUG_TRACE,
292 "ldbm_back_modrdn: new parent \"%s\" seems to be the same as old parent \"%s\"...\n",
293 newSuperior, p_dn, 0 );
296 newSuperior = NULL; /* ignore newSuperior */
300 if ( newSuperior != NULL ) {
301 /* newSuperior == entry being moved?, if so ==> ERROR */
302 /* Get Entry with dn=newSuperior. Does newSuperior exist? */
304 if ( newSuperior[ 0 ] != '\0' ) {
306 if( (np = dn2entry_w( be, np_ndn, NULL )) == NULL) {
308 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
309 "ldbm_back_modrdn: newSup(ndn=%s) not found.\n", np_ndn ));
311 Debug( LDAP_DEBUG_TRACE,
312 "ldbm_back_modrdn: newSup(ndn=%s) not here!\n",
316 send_ldap_result( conn, op, LDAP_OTHER,
317 NULL, "newSuperior not found", NULL, NULL );
322 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
323 "ldbm_back_modrdn: wr to new parent OK np=%p, id=%ld\n",
326 Debug( LDAP_DEBUG_TRACE,
327 "ldbm_back_modrdn: wr to new parent OK np=%p, id=%ld\n",
331 /* check newSuperior for "children" acl */
332 if ( !access_allowed( be, conn, op, np, children, NULL,
336 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
337 "ldbm_back_modrdn: no wr to newSup children.\n" ));
339 Debug( LDAP_DEBUG_TRACE,
340 "ldbm_back_modrdn: no wr to newSup children\n",
344 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
345 NULL, NULL, NULL, NULL );
349 if ( is_entry_alias( np ) ) {
350 /* parent is an alias, don't allow add */
352 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
353 "ldbm_back_modrdn: entry (%s) is an alias.\n", np->e_dn ));
355 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0, 0, 0 );
359 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
360 NULL, "newSuperior is an alias", NULL, NULL );
365 if ( is_entry_referral( np ) ) {
366 /* parent is a referral, don't allow add */
368 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
369 "ldbm_back_modrdn: entry (%s) is a referral\n",
372 Debug( LDAP_DEBUG_TRACE, "entry (%s) is referral\n",
376 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
377 NULL, "newSuperior is a referral", NULL, NULL );
384 /* no parent, must be root to modify newSuperior */
385 if ( isroot == -1 ) {
386 isroot = be_isroot( be, op->o_ndn );
390 if ( be_issuffix( be, "" ) ) {
391 static const Entry rootp = { NOID, "", "", NULL, NULL };
392 np = (Entry *)&rootp;
394 rc = access_allowed( be, conn, op, np,
395 children, NULL, ACL_WRITE );
398 /* check parent for "children" acl */
401 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
402 "ldbm_back_modrdn: no access "
403 "to new superior \"\"\n" ));
405 Debug( LDAP_DEBUG_TRACE,
406 "<=- ldbm_back_modrdn: no "
407 "access to new superior\n", 0, 0, 0 );
410 send_ldap_result( conn, op,
411 LDAP_INSUFFICIENT_ACCESS,
412 NULL, NULL, NULL, NULL );
418 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
419 "ldbm_back_modrdn: \"\" "
420 "not allowed as new superior\n" ));
422 Debug( LDAP_DEBUG_TRACE,
423 "<=- ldbm_back_modrdn: \"\" "
424 "not allowed as new superior\n",
428 send_ldap_result( conn, op,
429 LDAP_INSUFFICIENT_ACCESS,
430 NULL, NULL, NULL, NULL );
437 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
438 "ldbm_back_modrdn: wr to new parent's children OK.\n" ));
440 Debug( LDAP_DEBUG_TRACE,
441 "ldbm_back_modrdn: wr to new parent's children OK\n",
445 new_parent_dn = np_dn;
448 /* Build target dn and make sure target entry doesn't exist already. */
449 build_new_dn( &new_dn, e->e_dn, new_parent_dn, newrdn );
451 new_ndn = ch_strdup(new_dn);
452 (void) dn_normalize( new_ndn );
455 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
456 "ldbm_back_modrdn: new ndn=%s\n", new_ndn ));
458 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: new ndn=%s\n",
462 /* check for abandon */
463 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
464 if ( op->o_abandon ) {
465 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
469 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
470 if ( ( rc_id = dn2id ( be, new_ndn, &id ) ) || id != NOID ) {
471 /* if (rc_id) something bad happened to ldbm cache */
472 send_ldap_result( conn, op,
473 rc_id ? LDAP_OPERATIONS_ERROR : LDAP_ALREADY_EXISTS,
474 NULL, NULL, NULL, NULL );
479 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
480 "ldbm_back_modrdn: new ndn (%s) does not exist\n", new_ndn ));
482 Debug( LDAP_DEBUG_TRACE,
483 "ldbm_back_modrdn: new ndn=%s does not exist\n",
488 /* Get attribute types and values of our new rdn, we will
489 * need to add that to our new entry
491 if ( rdn_attrs( newrdn, &new_rdn_types, &new_rdn_vals ) ) {
493 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
494 "ldbm_back_modrdn: can't figure out type(s)/value(s) of newrdn\n" ));
496 Debug( LDAP_DEBUG_TRACE,
497 "ldbm_back_modrdn: can't figure out type(s)/value(s) of newrdn\n",
501 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
502 NULL, "unable to parse type(s)/value(s) used in RDN", NULL, NULL );
507 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
508 "ldbm_back_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
509 new_rdn_vals[0], new_rdn_types[0] ));
511 Debug( LDAP_DEBUG_TRACE,
512 "ldbm_back_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
513 new_rdn_vals[0], new_rdn_types[0], 0 );
516 /* Retrieve the old rdn from the entry's dn */
517 if ( (old_rdn = dn_rdn( be, dn )) == NULL ) {
519 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
520 "ldbm_back_modrdn: can't figure out old_rdn from dn (%s)\n",
523 Debug( LDAP_DEBUG_TRACE,
524 "ldbm_back_modrdn: can't figure out old_rdn from dn\n",
528 send_ldap_result( conn, op, LDAP_OTHER,
529 NULL, "could not parse old DN", NULL, NULL );
533 if ( rdn_attrs( old_rdn, &old_rdn_types, &old_rdn_vals ) ) {
535 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
536 "ldbm_back_modrdn: can't figure out the old_rdn type(s)/value(s).\n" ));
538 Debug( LDAP_DEBUG_TRACE,
539 "ldbm_back_modrdn: can't figure out the old_rdn type(s)/value(s)\n",
543 send_ldap_result( conn, op, LDAP_OTHER,
544 NULL, "unable to parse type(s)/value(s) used in RDN from old DN", NULL, NULL );
548 if ( newSuperior == NULL
549 && charray_strcasecmp( (const char **)old_rdn_types, (const char **)new_rdn_types ) != 0 )
551 /* Not a big deal but we may say something */
553 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
554 "ldbm_back_modrdn: old_rdn_type=%s new_rdn_type=%s\n",
555 old_rdn_types[0], new_rdn_types[0] ));
557 Debug( LDAP_DEBUG_TRACE,
558 "ldbm_back_modrdn: old_rdn_type=%s, new_rdn_type=%s!\n",
559 old_rdn_types[0], new_rdn_types[0], 0 );
564 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
565 "ldbm_back_modrdn: DN_X500\n" ));
567 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: DN_X500\n",
572 for ( a_cnt = 0; new_rdn_types[a_cnt]; a_cnt++ ) {
574 AttributeDescription *desc = NULL;
575 Modifications *mod_tmp;
579 rc = slap_str2ad( new_rdn_types[a_cnt], &desc, &text );
581 if ( rc != LDAP_SUCCESS ) {
583 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
584 "ldbm_back_modrdn: slap_str2ad error: %s (%s)\n",
585 text, new_rdn_types[a_cnt] ));
587 Debug( LDAP_DEBUG_TRACE,
588 "ldbm_back_modrdn: %s: %s (new)\n",
589 text, new_rdn_types[a_cnt], 0 );
592 send_ldap_result( conn, op, rc,
593 NULL, text, NULL, NULL );
598 val.bv_val = new_rdn_vals[a_cnt];
599 val.bv_len = strlen( val.bv_val );
600 if ( ! access_allowed( be, conn, op, e,
601 desc, &val, ACL_WRITE ) ) {
603 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
604 "ldbm_back_modrdn: access "
605 "not allowed to attr \"%s\"\n",
606 new_rdn_types[a_cnt] ));
608 Debug( LDAP_DEBUG_TRACE,
609 "ldbm_back_modrdn: access not allowed "
610 "to attr \"%s\"\n%s%s",
611 new_rdn_types[a_cnt], "", "" );
613 send_ldap_result( conn, op,
614 LDAP_INSUFFICIENT_ACCESS,
615 NULL, NULL, NULL, NULL );
620 mod_tmp = (Modifications *)ch_malloc( sizeof( Modifications ) );
621 mod_tmp->sml_desc = desc;
622 mod_tmp->sml_bvalues = (struct berval **)ch_malloc( 2 * sizeof(struct berval *) );
623 mod_tmp->sml_bvalues[0] = ber_bvstrdup( new_rdn_vals[a_cnt] );
624 mod_tmp->sml_bvalues[1] = NULL;
625 mod_tmp->sml_op = SLAP_MOD_SOFTADD;
626 mod_tmp->sml_next = mod;
630 /* Remove old rdn value if required */
631 if ( deleteoldrdn ) {
632 /* Get value of old rdn */
633 if ( old_rdn_vals == NULL ) {
635 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
636 "ldbm_back_modrdn: can't figure out old RDN value(s) from old RDN\n" ));
638 Debug( LDAP_DEBUG_TRACE,
639 "ldbm_back_modrdn: can't figure out oldRDN value(s) from old RDN\n",
643 send_ldap_result( conn, op, LDAP_OTHER,
644 NULL, "could not parse value(s) from old RDN", NULL, NULL );
648 for ( d_cnt = 0; old_rdn_types[d_cnt]; d_cnt++ ) {
650 AttributeDescription *desc = NULL;
651 Modifications *mod_tmp;
655 rc = slap_str2ad( old_rdn_types[d_cnt], &desc, &text );
657 if ( rc != LDAP_SUCCESS ) {
659 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
660 "ldbm_back_modrdn: %s: %s (old)\n",
661 text, old_rdn_types[d_cnt] ));
663 Debug( LDAP_DEBUG_TRACE,
664 "ldbm_back_modrdn: %s: %s (old)\n",
665 text, old_rdn_types[d_cnt], 0 );
668 send_ldap_result( conn, op, rc,
669 NULL, text, NULL, NULL );
674 val.bv_val = old_rdn_vals[d_cnt];
675 val.bv_len = strlen( val.bv_val );
676 if ( ! access_allowed( be, conn, op, e,
677 desc, &val, ACL_WRITE ) ) {
679 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
680 "ldbm_back_modrdn: access "
681 "not allowed to attr \"%s\"\n",
682 old_rdn_types[d_cnt] ));
684 Debug( LDAP_DEBUG_TRACE,
685 "ldbm_back_modrdn: access not allowed "
686 "to attr \"%s\"\n%s%s",
687 old_rdn_types[d_cnt], "", "" );
689 send_ldap_result( conn, op,
690 LDAP_INSUFFICIENT_ACCESS,
691 NULL, NULL, NULL, NULL );
696 /* Remove old value of rdn as an attribute. */
697 mod_tmp = (Modifications *)ch_malloc( sizeof( Modifications ) );
698 mod_tmp->sml_desc = desc;
699 mod_tmp->sml_bvalues = (struct berval **)ch_malloc( 2 * sizeof(struct berval *) );
700 mod_tmp->sml_bvalues[0] = ber_bvstrdup( old_rdn_vals[d_cnt] );
701 mod_tmp->sml_bvalues[1] = NULL;
702 mod_tmp->sml_op = LDAP_MOD_DELETE;
703 mod_tmp->sml_next = mod;
707 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
708 "ldbm_back_modrdn: removing old_rdn_val=%s\n", old_rdn_vals[0] ));
710 Debug( LDAP_DEBUG_TRACE,
711 "ldbm_back_modrdn: removing old_rdn_val=%s\n",
712 old_rdn_vals[0], 0, 0 );
718 /* check for abandon */
719 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
720 if ( op->o_abandon ) {
721 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
724 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
727 if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
728 send_ldap_result( conn, op, LDAP_OTHER,
729 NULL, "DN index delete fail", NULL, NULL );
733 (void) cache_delete_entry( &li->li_cache, e );
736 /* XXX: there is no going back! */
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 if( p_dn != NULL ) free( p_dn );
794 if( p_ndn != NULL ) free( p_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 */