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 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) */
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 struct berval *np_dn = NULL; /* newSuperior dn */
75 struct berval *np_ndn = NULL; /* newSuperior ndn */
76 struct berval *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 && newSuperior->bv_len )
86 ? newSuperior->bv_val : "NULL" ));
88 Debug( LDAP_DEBUG_TRACE,
89 "==>ldbm_back_modrdn: dn: %s newSuperior=%s\n",
90 dn->bv_len ? dn->bv_val : "NULL",
91 ( newSuperior && newSuperior->bv_len )
92 ? newSuperior->bv_val : "NULL", 0 );
95 /* get entry with writer lock */
96 if ( (e = dn2entry_w( be, ndn->bv_val, &matched )) == NULL ) {
97 char* matched_dn = NULL;
100 if( matched != NULL ) {
101 matched_dn = strdup( matched->e_dn );
102 refs = is_entry_referral( matched )
103 ? get_entry_referrals( be, conn, op, matched )
105 cache_return_entry_r( &li->li_cache, matched );
107 refs = referral_rewrite( default_referral,
108 NULL, dn, LDAP_SCOPE_DEFAULT );
111 send_ldap_result( conn, op, LDAP_REFERRAL,
112 matched_dn, NULL, refs, NULL );
114 ber_bvecfree( refs );
120 if (!manageDSAit && is_entry_referral( e ) ) {
121 /* parent is a referral, don't allow add */
122 /* parent is an alias, don't allow add */
123 struct berval **refs = get_entry_referrals( be,
127 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
128 "ldbm_back_modrdn: entry %s is a referral\n", e->e_dn ));
130 Debug( LDAP_DEBUG_TRACE, "entry %s is referral\n", e->e_dn,
134 send_ldap_result( conn, op, LDAP_REFERRAL,
135 e->e_dn, NULL, refs, NULL );
137 ber_bvecfree( refs );
141 if ( has_children( be, e ) ) {
143 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
144 "ldbm_back_modrdn: entry %s has children\n", e->e_dn ));
146 Debug( LDAP_DEBUG_TRACE, "entry %s has children\n", e->e_dn,
150 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
151 NULL, "subtree rename not supported", NULL, NULL );
155 p_ndn.bv_val = dn_parent( be, e->e_ndn );
157 p_ndn.bv_len = e->e_nname.bv_len - (p_ndn.bv_val - e->e_ndn);
161 if ( p_ndn.bv_len != 0 ) {
162 /* Make sure parent entry exist and we can write its
166 if( (p = dn2entry_w( be, p_ndn.bv_val, NULL )) == NULL) {
168 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
169 "ldbm_back_modrdn: parent of %s does not exist\n", e->e_ndn ));
171 Debug( LDAP_DEBUG_TRACE, "parent does not exist\n",
175 send_ldap_result( conn, op, LDAP_OTHER,
176 NULL, "parent entry does not exist", NULL, NULL );
181 /* check parent for "children" acl */
182 if ( ! access_allowed( be, conn, op, p,
183 children, NULL, ACL_WRITE ) )
186 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
187 "ldbm_back_modrdn: no access to parent of (%s)\n", e->e_dn ));
189 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
193 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
194 NULL, NULL, NULL, NULL );
199 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
200 "ldbm_back_modrdn: wr to children of entry %s OK\n",
203 Debug( LDAP_DEBUG_TRACE,
204 "ldbm_back_modrdn: wr to children of entry %s OK\n",
205 p_ndn.bv_val, 0, 0 );
208 p_dn.bv_val = dn_parent( be, e->e_dn );
210 p_dn.bv_len = e->e_name.bv_len - (p_dn.bv_val - e->e_dn);
215 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
216 "ldbm_back_modrdn: parent dn=%s\n", p_dn.bv_val ));
218 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: parent dn=%s\n",
223 /* no parent, must be root to modify rdn */
224 isroot = be_isroot( be, &op->o_ndn );
226 if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
227 p = (Entry *)&slap_entry_root;
229 rc = access_allowed( be, conn, op, p,
230 children, NULL, ACL_WRITE );
233 /* check parent for "children" acl */
236 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
237 "ldbm_back_modrdn: no access "
238 "to parent \"\"\n" ));
240 Debug( LDAP_DEBUG_TRACE,
241 "<=- ldbm_back_modrdn: no "
242 "access to parent\n", 0, 0, 0 );
245 send_ldap_result( conn, op,
246 LDAP_INSUFFICIENT_ACCESS,
247 NULL, NULL, NULL, NULL );
253 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
254 "ldbm_back_modrdn: (%s) has no "
255 "parent & not a root.\n", dn ));
257 Debug( LDAP_DEBUG_TRACE,
258 "<=- ldbm_back_modrdn: no parent & "
259 "not root\n", 0, 0, 0);
262 send_ldap_result( conn, op,
263 LDAP_INSUFFICIENT_ACCESS,
264 NULL, NULL, NULL, NULL );
269 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
273 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
274 "ldbm_back_modrdn: (%s) no parent, locked root.\n", e->e_dn ));
276 Debug( LDAP_DEBUG_TRACE,
277 "ldbm_back_modrdn: no parent, locked root\n",
282 new_parent_dn = &p_dn; /* New Parent unless newSuperior given */
284 if ( newSuperior != NULL ) {
286 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
287 "ldbm_back_modrdn: new parent \"%s\" requested\n",
288 newSuperior->bv_val ));
290 Debug( LDAP_DEBUG_TRACE,
291 "ldbm_back_modrdn: new parent \"%s\" requested...\n",
292 newSuperior->bv_val, 0, 0 );
296 np_ndn = nnewSuperior;
298 /* newSuperior == oldParent? */
299 if ( p_ndn.bv_len == np_ndn->bv_len &&
300 strcmp( p_ndn.bv_val, np_ndn->bv_val ) == 0 ) {
302 LDAP_LOG(( "backend", LDAP_LEVEL_INFO, "ldbm_back_modrdn: "
303 "new parent\"%s\" seems to be the same as the "
304 "old parent \"%s\"\n",
305 newSuperior->bv_val, p_dn.bv_val ));
307 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: "
308 "new parent\"%s\" seems to be the same as the "
309 "old parent \"%s\"\n",
310 newSuperior->bv_val, p_dn.bv_val, 0 );
313 newSuperior = NULL; /* ignore newSuperior */
317 if ( newSuperior != NULL ) {
318 /* newSuperior == entry being moved?, if so ==> ERROR */
319 /* Get Entry with dn=newSuperior. Does newSuperior exist? */
321 if ( nnewSuperior->bv_len ) {
322 if( (np = dn2entry_w( be, np_ndn->bv_val, NULL )) == NULL) {
324 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
325 "ldbm_back_modrdn: newSup(ndn=%s) not found.\n", np_ndn->bv_val ));
327 Debug( LDAP_DEBUG_TRACE,
328 "ldbm_back_modrdn: newSup(ndn=%s) not here!\n",
329 np_ndn->bv_val, 0, 0);
332 send_ldap_result( conn, op, LDAP_OTHER,
333 NULL, "newSuperior not found", NULL, NULL );
338 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
339 "ldbm_back_modrdn: wr to new parent OK np=%p, id=%ld\n",
342 Debug( LDAP_DEBUG_TRACE,
343 "ldbm_back_modrdn: wr to new parent OK np=%p, id=%ld\n",
347 /* check newSuperior for "children" acl */
348 if ( !access_allowed( be, conn, op, np, children, NULL,
352 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
353 "ldbm_back_modrdn: no wr to newSup children.\n" ));
355 Debug( LDAP_DEBUG_TRACE,
356 "ldbm_back_modrdn: no wr to newSup children\n",
360 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
361 NULL, NULL, NULL, NULL );
365 if ( is_entry_alias( np ) ) {
366 /* parent is an alias, don't allow add */
368 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
369 "ldbm_back_modrdn: entry (%s) is an alias.\n", np->e_dn ));
371 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0, 0, 0 );
375 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
376 NULL, "newSuperior is an alias", NULL, NULL );
381 if ( is_entry_referral( np ) ) {
382 /* parent is a referral, don't allow add */
384 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
385 "ldbm_back_modrdn: entry (%s) is a referral\n",
388 Debug( LDAP_DEBUG_TRACE, "entry (%s) is referral\n",
392 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
393 NULL, "newSuperior is a referral", NULL, NULL );
400 /* no parent, must be root to modify newSuperior */
401 if ( isroot == -1 ) {
402 isroot = be_isroot( be, &op->o_ndn );
406 if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
407 np = (Entry *)&slap_entry_root;
409 rc = access_allowed( be, conn, op, np,
410 children, NULL, ACL_WRITE );
413 /* check parent for "children" acl */
416 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
417 "ldbm_back_modrdn: no access "
418 "to new superior \"\"\n" ));
420 Debug( LDAP_DEBUG_TRACE,
421 "<=- ldbm_back_modrdn: no "
422 "access to new superior\n", 0, 0, 0 );
425 send_ldap_result( conn, op,
426 LDAP_INSUFFICIENT_ACCESS,
427 NULL, NULL, NULL, NULL );
433 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
434 "ldbm_back_modrdn: \"\" "
435 "not allowed as new superior\n" ));
437 Debug( LDAP_DEBUG_TRACE,
438 "<=- ldbm_back_modrdn: \"\" "
439 "not allowed as new superior\n",
443 send_ldap_result( conn, op,
444 LDAP_INSUFFICIENT_ACCESS,
445 NULL, NULL, NULL, NULL );
452 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
453 "ldbm_back_modrdn: wr to new parent's children OK.\n" ));
455 Debug( LDAP_DEBUG_TRACE,
456 "ldbm_back_modrdn: wr to new parent's children OK\n",
460 new_parent_dn = np_dn;
463 /* Build target dn and make sure target entry doesn't exist already. */
464 build_new_dn( &new_dn, new_parent_dn, newrdn );
465 dnNormalize2( NULL, &new_dn, &new_ndn );
468 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
469 "ldbm_back_modrdn: new ndn=%s\n", new_ndn.bv_val ));
471 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: new ndn=%s\n",
472 new_ndn.bv_val, 0, 0 );
475 /* check for abandon */
476 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
477 if ( op->o_abandon ) {
478 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
482 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
483 if ( ( rc_id = dn2id ( be, new_ndn.bv_val, &id ) ) || id != NOID ) {
484 /* if (rc_id) something bad happened to ldbm cache */
485 send_ldap_result( conn, op,
486 rc_id ? LDAP_OPERATIONS_ERROR : LDAP_ALREADY_EXISTS,
487 NULL, NULL, NULL, NULL );
492 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
493 "ldbm_back_modrdn: new ndn (%s) does not exist\n", new_ndn.bv_val ));
495 Debug( LDAP_DEBUG_TRACE,
496 "ldbm_back_modrdn: new ndn=%s does not exist\n",
497 new_ndn.bv_val, 0, 0 );
501 /* Get attribute types and values of our new rdn, we will
502 * need to add that to our new entry
504 if ( rdn_attrs( newrdn->bv_val, &new_rdn_types, &new_rdn_vals ) ) {
506 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
507 "ldbm_back_modrdn: can't figure out type(s)/value(s) of newrdn\n" ));
509 Debug( LDAP_DEBUG_TRACE,
510 "ldbm_back_modrdn: can't figure out type(s)/value(s) of newrdn\n",
514 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
515 NULL, "unable to parse type(s)/value(s) used in RDN", NULL, NULL );
520 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
521 "ldbm_back_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
522 new_rdn_vals[0], new_rdn_types[0] ));
524 Debug( LDAP_DEBUG_TRACE,
525 "ldbm_back_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
526 new_rdn_vals[0], new_rdn_types[0], 0 );
529 /* Retrieve the old rdn from the entry's dn */
530 if ( (old_rdn = dn_rdn( be, dn )) == NULL ) {
532 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
533 "ldbm_back_modrdn: can't figure out old_rdn from dn (%s)\n",
536 Debug( LDAP_DEBUG_TRACE,
537 "ldbm_back_modrdn: can't figure out old_rdn from dn\n",
541 send_ldap_result( conn, op, LDAP_OTHER,
542 NULL, "could not parse old DN", NULL, NULL );
546 if ( rdn_attrs( old_rdn, &old_rdn_types, &old_rdn_vals ) ) {
548 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
549 "ldbm_back_modrdn: can't figure out the old_rdn type(s)/value(s).\n" ));
551 Debug( LDAP_DEBUG_TRACE,
552 "ldbm_back_modrdn: can't figure out the old_rdn type(s)/value(s)\n",
556 send_ldap_result( conn, op, LDAP_OTHER,
557 NULL, "unable to parse type(s)/value(s) used in RDN from old DN", NULL, NULL );
561 if ( newSuperior == NULL
562 && charray_strcasecmp( (const char **)old_rdn_types, (const char **)new_rdn_types ) != 0 )
564 /* Not a big deal but we may say something */
566 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
567 "ldbm_back_modrdn: old_rdn_type=%s new_rdn_type=%s\n",
568 old_rdn_types[0], new_rdn_types[0] ));
570 Debug( LDAP_DEBUG_TRACE,
571 "ldbm_back_modrdn: old_rdn_type=%s, new_rdn_type=%s!\n",
572 old_rdn_types[0], new_rdn_types[0], 0 );
577 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
578 "ldbm_back_modrdn: DN_X500\n" ));
580 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: DN_X500\n",
585 for ( a_cnt = 0; new_rdn_types[a_cnt]; a_cnt++ ) {
587 AttributeDescription *desc = NULL;
588 Modifications *mod_tmp;
592 rc = slap_str2ad( new_rdn_types[a_cnt], &desc, &text );
594 if ( rc != LDAP_SUCCESS ) {
596 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
597 "ldbm_back_modrdn: slap_str2ad error: %s (%s)\n",
598 text, new_rdn_types[a_cnt] ));
600 Debug( LDAP_DEBUG_TRACE,
601 "ldbm_back_modrdn: %s: %s (new)\n",
602 text, new_rdn_types[a_cnt], 0 );
605 send_ldap_result( conn, op, rc,
606 NULL, text, NULL, NULL );
611 val.bv_val = new_rdn_vals[a_cnt];
612 val.bv_len = strlen( val.bv_val );
613 if ( ! access_allowed( be, conn, op, e,
614 desc, &val, ACL_WRITE ) ) {
616 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
617 "ldbm_back_modrdn: access "
618 "not allowed to attr \"%s\"\n",
619 new_rdn_types[a_cnt] ));
621 Debug( LDAP_DEBUG_TRACE,
622 "ldbm_back_modrdn: access not allowed "
623 "to attr \"%s\"\n%s%s",
624 new_rdn_types[a_cnt], "", "" );
626 send_ldap_result( conn, op,
627 LDAP_INSUFFICIENT_ACCESS,
628 NULL, NULL, NULL, NULL );
633 mod_tmp = (Modifications *)ch_malloc( sizeof( Modifications ) );
634 mod_tmp->sml_desc = desc;
635 mod_tmp->sml_bvalues = (struct berval **)ch_malloc( 2 * sizeof(struct berval *) );
636 mod_tmp->sml_bvalues[0] = ber_bvstrdup( new_rdn_vals[a_cnt] );
637 mod_tmp->sml_bvalues[1] = NULL;
638 mod_tmp->sml_op = SLAP_MOD_SOFTADD;
639 mod_tmp->sml_next = mod;
643 /* Remove old rdn value if required */
644 if ( deleteoldrdn ) {
645 /* Get value of old rdn */
646 if ( old_rdn_vals == NULL ) {
648 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
649 "ldbm_back_modrdn: can't figure out old RDN value(s) from old RDN\n" ));
651 Debug( LDAP_DEBUG_TRACE,
652 "ldbm_back_modrdn: can't figure out oldRDN value(s) from old RDN\n",
656 send_ldap_result( conn, op, LDAP_OTHER,
657 NULL, "could not parse value(s) from old RDN", NULL, NULL );
661 for ( d_cnt = 0; old_rdn_types[d_cnt]; d_cnt++ ) {
663 AttributeDescription *desc = NULL;
664 Modifications *mod_tmp;
668 rc = slap_str2ad( old_rdn_types[d_cnt], &desc, &text );
670 if ( rc != LDAP_SUCCESS ) {
672 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
673 "ldbm_back_modrdn: %s: %s (old)\n",
674 text, old_rdn_types[d_cnt] ));
676 Debug( LDAP_DEBUG_TRACE,
677 "ldbm_back_modrdn: %s: %s (old)\n",
678 text, old_rdn_types[d_cnt], 0 );
681 send_ldap_result( conn, op, rc,
682 NULL, text, NULL, NULL );
687 val.bv_val = old_rdn_vals[d_cnt];
688 val.bv_len = strlen( val.bv_val );
689 if ( ! access_allowed( be, conn, op, e,
690 desc, &val, ACL_WRITE ) ) {
692 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
693 "ldbm_back_modrdn: access "
694 "not allowed to attr \"%s\"\n",
695 old_rdn_types[d_cnt] ));
697 Debug( LDAP_DEBUG_TRACE,
698 "ldbm_back_modrdn: access not allowed "
699 "to attr \"%s\"\n%s%s",
700 old_rdn_types[d_cnt], "", "" );
702 send_ldap_result( conn, op,
703 LDAP_INSUFFICIENT_ACCESS,
704 NULL, NULL, NULL, NULL );
709 /* Remove old value of rdn as an attribute. */
710 mod_tmp = (Modifications *)ch_malloc( sizeof( Modifications ) );
711 mod_tmp->sml_desc = desc;
712 mod_tmp->sml_bvalues = (struct berval **)ch_malloc( 2 * sizeof(struct berval *) );
713 mod_tmp->sml_bvalues[0] = ber_bvstrdup( old_rdn_vals[d_cnt] );
714 mod_tmp->sml_bvalues[1] = NULL;
715 mod_tmp->sml_op = LDAP_MOD_DELETE;
716 mod_tmp->sml_next = mod;
720 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
721 "ldbm_back_modrdn: removing old_rdn_val=%s\n", old_rdn_vals[0] ));
723 Debug( LDAP_DEBUG_TRACE,
724 "ldbm_back_modrdn: removing old_rdn_val=%s\n",
725 old_rdn_vals[0], 0, 0 );
731 /* check for abandon */
732 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
733 if ( op->o_abandon ) {
734 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
737 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
740 if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
741 send_ldap_result( conn, op, LDAP_OTHER,
742 NULL, "DN index delete fail", NULL, NULL );
746 (void) cache_delete_entry( &li->li_cache, e );
749 /* XXX: there is no going back! */
754 e->e_nname = new_ndn;
755 new_dn.bv_val = NULL;
756 new_ndn.bv_val = NULL;
759 if ( dn2id_add( be, e->e_ndn, e->e_id ) != 0 ) {
760 send_ldap_result( conn, op, LDAP_OTHER,
761 NULL, "DN index add failed", NULL, NULL );
765 /* modify memory copy of entry */
766 rc = ldbm_modify_internal( be, conn, op, dn->bv_val, &mod[0], e,
767 &text, textbuf, textlen );
769 if( rc != LDAP_SUCCESS ) {
770 if( rc != SLAPD_ABANDON ) {
771 send_ldap_result( conn, op, rc,
772 NULL, text, NULL, NULL );
775 /* here we may try to delete the newly added dn */
776 if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
777 /* we already are in trouble ... */
784 (void) cache_update_entry( &li->li_cache, e );
786 /* NOTE: after this you must not free new_dn or new_ndn!
787 * They are used by cache.
791 if ( id2entry_add( be, e ) != 0 ) {
792 send_ldap_result( conn, op, LDAP_OTHER,
793 NULL, "entry update failed", NULL, NULL );
797 send_ldap_result( conn, op, LDAP_SUCCESS,
798 NULL, NULL, NULL, NULL );
800 cache_entry_commit( e );
803 if( new_dn.bv_val != NULL ) free( new_dn.bv_val );
804 if( new_ndn.bv_val != NULL ) free( new_ndn.bv_val );
806 /* LDAP v2 supporting correct attribute handling. */
807 if( new_rdn_types != NULL ) charray_free( new_rdn_types );
808 if( new_rdn_vals != NULL ) charray_free( new_rdn_vals );
809 if( old_rdn != NULL ) free(old_rdn);
810 if( old_rdn_types != NULL ) charray_free( old_rdn_types );
811 if( old_rdn_vals != NULL ) charray_free( old_rdn_vals );
814 slap_mods_free( mod );
817 /* LDAP v3 Support */
819 /* free new parent and writer lock */
820 cache_return_entry_w( &li->li_cache, np );
824 /* free parent and writer lock */
825 cache_return_entry_w( &li->li_cache, p );
829 /* release root writer lock */
830 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
833 /* free entry and writer lock */
834 cache_return_entry_w( &li->li_cache, e );
835 if ( rc == MUST_DESTROY ) {
836 /* if rc == MUST_DESTROY the entry is uncached
837 * and its private data is destroyed;
838 * the entry must be freed */