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;
54 int rc = -1, rc_id = 0;
56 const char *text = NULL;
57 char textbuf[SLAP_TEXT_BUFLEN];
58 size_t textlen = sizeof textbuf;
59 /* Added to support LDAP v2 correctly (deleteoldrdn thing) */
60 #ifndef MULTIATTRVAL_RDN
61 char *new_rdn_val = NULL; /* Val of new rdn */
62 char *new_rdn_type = NULL; /* Type of new rdn */
63 #else /* MULTIATTRVAL_RDN */
64 char **new_rdn_vals = NULL; /* Vals of new rdn */
65 char **new_rdn_types = NULL; /* Types of new rdn */
67 #endif /* MULTIATTRVAL_RDN */
68 char *old_rdn = NULL; /* Old rdn's attr type & val */
69 #ifndef MULTIATTRVAL_RDN
70 char *old_rdn_type = NULL; /* Type of old rdn attr. */
71 char *old_rdn_val = NULL; /* Old rdn attribute value */
72 #else /* MULTIATTRVAL_RDN */
73 char **old_rdn_types = NULL; /* Types of old rdn attrs. */
74 char **old_rdn_vals = NULL; /* Old rdn attribute values */
75 #endif /* MULTIATTRVAL_RDN */
76 /* Added to support newSuperior */
77 Entry *np = NULL; /* newSuperior Entry */
78 char *np_dn = NULL; /* newSuperior dn */
79 char *np_ndn = NULL; /* newSuperior ndn */
80 char *new_parent_dn = NULL; /* np_dn, p_dn, or NULL */
81 /* Used to interface with ldbm_modify_internal() */
82 #ifndef MULTIATTRVAL_RDN
83 struct berval add_bv; /* Stores new rdn att */
84 struct berval *add_bvals[2]; /* Stores new rdn att */
85 struct berval del_bv; /* Stores old rdn att */
86 struct berval *del_bvals[2]; /* Stores old rdn att */
87 Modifications mod[2]; /* Used to delete old rdn */
88 #else /* MULTIATTRVAL_RDN */
89 Modifications *mod = NULL; /* Used to delete old/add new rdn */
90 #endif /* MULTIATTRVAL_RDN */
91 int manageDSAit = get_manageDSAit( op );
94 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
95 "ldbm_back_modrdn: dn: %s newSuperior=%s\n",
96 dn ? dn : "NULL", newSuperior ? newSuperior : "NULL" ));
98 Debug( LDAP_DEBUG_TRACE, "==>ldbm_back_modrdn(newSuperior=%s)\n",
99 (newSuperior ? newSuperior : "NULL"),
103 /* get entry with writer lock */
104 if ( (e = dn2entry_w( be, ndn, &matched )) == NULL ) {
105 char* matched_dn = NULL;
106 struct berval** refs = NULL;
108 if( matched != NULL ) {
109 matched_dn = strdup( matched->e_dn );
110 refs = is_entry_referral( matched )
111 ? get_entry_referrals( be, conn, op, matched )
113 cache_return_entry_r( &li->li_cache, matched );
115 refs = default_referral;
118 send_ldap_result( conn, op, LDAP_REFERRAL,
119 matched_dn, NULL, refs, NULL );
121 if ( matched != NULL ) {
122 ber_bvecfree( refs );
129 if (!manageDSAit && is_entry_referral( e ) ) {
130 /* parent is a referral, don't allow add */
131 /* parent is an alias, don't allow add */
132 struct berval **refs = get_entry_referrals( be,
136 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
137 "ldbm_back_modrdn: entry %s is a referral\n", e->e_dn ));
139 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
143 send_ldap_result( conn, op, LDAP_REFERRAL,
144 e->e_dn, NULL, refs, NULL );
146 ber_bvecfree( refs );
150 if ( has_children( be, e ) ) {
152 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
153 "ldbm_back_modrdn: entry %s has children\n", e->e_dn ));
155 Debug( LDAP_DEBUG_TRACE, "entry %s referral\n", e->e_dn,
159 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
160 NULL, "subtree rename not supported", NULL, NULL );
164 if ( (p_ndn = dn_parent( be, e->e_ndn )) != NULL && p_ndn[0] != '\0' ) {
165 /* Make sure parent entry exist and we can write its
169 if( (p = dn2entry_w( be, p_ndn, NULL )) == NULL) {
171 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
172 "ldbm_back_modrdn: parent of %s does not exist\n", e->e_ndn ));
174 Debug( LDAP_DEBUG_TRACE, "parent does not exist\n",
178 send_ldap_result( conn, op, LDAP_OTHER,
179 NULL, "parent entry does not exist", NULL, NULL );
184 /* check parent for "children" acl */
185 if ( ! access_allowed( be, conn, op, p,
186 children, NULL, ACL_WRITE ) )
189 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
190 "ldbm_back_modrdn: no access to parent of (%s)\n", e->e_dn ));
192 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
196 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
197 NULL, NULL, NULL, NULL );
202 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
203 "ldbm_back_modrdn: wr to children of entry %s OK\n",
206 Debug( LDAP_DEBUG_TRACE,
207 "ldbm_back_modrdn: wr to children of entry %s OK\n",
211 p_dn = dn_parent( be, e->e_dn );
214 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
215 "ldbm_back_modrdn: parent dn=%s\n", p_dn ));
217 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: parent dn=%s\n",
222 /* no parent, modrdn entry directly under root */
223 if( ! be_isroot( be, op->o_ndn ) ) {
225 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
226 "ldbm_back_modrdn: (%s) no parent & not a root.\n",
229 Debug( LDAP_DEBUG_TRACE, "no parent & not root\n",
233 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
234 NULL, NULL, NULL, NULL );
238 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
242 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
243 "ldbm_back_modrdn: (%s) no parent, locked root.\n", e->e_dn ));
245 Debug( LDAP_DEBUG_TRACE,
246 "ldbm_back_modrdn: no parent, locked root\n",
251 new_parent_dn = p_dn; /* New Parent unless newSuperior given */
253 if ( newSuperior != NULL ) {
255 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
256 "ldbm_back_modrdn: new parent \"%s\" requested\n", newSuperior ));
258 Debug( LDAP_DEBUG_TRACE,
259 "ldbm_back_modrdn: new parent \"%s\" requested...\n",
263 np_dn = ch_strdup( newSuperior );
264 np_ndn = ch_strdup( np_dn );
265 (void) dn_normalize( np_ndn );
267 /* newSuperior == oldParent? */
268 if ( strcmp( p_ndn, np_ndn ) == 0 ) {
270 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
271 "ldbm_back_modrdn: new parent\"%s\" seems to be the same as the old parent \"%s\"\n",
272 newSuperior, p_dn ));
274 Debug( LDAP_DEBUG_TRACE,
275 "ldbm_back_modrdn: new parent \"%s\" seems to be the same as old parent \"%s\"...\n",
276 newSuperior, p_dn, 0 );
279 newSuperior = NULL; /* ignore newSuperior */
283 if ( newSuperior != NULL ) {
284 /* newSuperior == entry being moved?, if so ==> ERROR */
285 /* Get Entry with dn=newSuperior. Does newSuperior exist? */
287 if( (np = dn2entry_w( be, np_ndn, NULL )) == NULL) {
289 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
290 "ldbm_back_modrdn: newSup(ndn=%s) not found.\n", np_ndn ));
292 Debug( LDAP_DEBUG_TRACE,
293 "ldbm_back_modrdn: newSup(ndn=%s) not here!\n",
297 send_ldap_result( conn, op, LDAP_OTHER,
298 NULL, "newSuperior not found", NULL, NULL );
303 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
304 "ldbm_back_modrdn: wr to new parent OK np=%p, id=%ld\n",
307 Debug( LDAP_DEBUG_TRACE,
308 "ldbm_back_modrdn: wr to new parent OK np=%p, id=%ld\n",
312 /* check newSuperior for "children" acl */
313 if ( !access_allowed( be, conn, op, np, children, NULL,
317 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
318 "ldbm_back_modrdn: no wr to newSup children.\n" ));
320 Debug( LDAP_DEBUG_TRACE,
321 "ldbm_back_modrdn: no wr to newSup children\n",
325 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
326 NULL, NULL, NULL, NULL );
330 if ( is_entry_alias( np ) ) {
331 /* entry is an alias, don't allow bind */
333 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
334 "ldbm_back_modrdn: entry (%s) is an alias.\n", np->e_dn ));
336 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
341 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
342 NULL, "newSuperior is an alias", NULL, NULL );
347 if ( is_entry_referral( np ) ) {
348 /* parent is a referral, don't allow add */
349 /* parent is an alias, don't allow add */
351 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
352 "ldbm_back_modrdn: entry (%s) is a referral\n",
355 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
359 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
360 NULL, "newSuperior is a referral", NULL, NULL );
366 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
367 "ldbm_back_modrdn: wr to new parent's children OK.\n" ));
369 Debug( LDAP_DEBUG_TRACE,
370 "ldbm_back_modrdn: wr to new parent's children OK\n",
374 new_parent_dn = np_dn;
377 /* Build target dn and make sure target entry doesn't exist already. */
378 build_new_dn( &new_dn, e->e_dn, new_parent_dn, newrdn );
380 new_ndn = ch_strdup(new_dn);
381 (void) dn_normalize( new_ndn );
384 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
385 "ldbm_back_modrdn: new ndn=%s\n", new_ndn ));
387 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: new ndn=%s\n",
391 /* check for abandon */
392 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
393 if ( op->o_abandon ) {
394 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
398 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
399 if ( ( rc_id = dn2id ( be, new_ndn, &id ) ) || id != NOID ) {
400 /* if (rc_id) something bad happened to ldbm cache */
401 send_ldap_result( conn, op,
402 rc_id ? LDAP_OPERATIONS_ERROR : LDAP_ALREADY_EXISTS,
403 NULL, NULL, NULL, NULL );
408 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
409 "ldbm_back_modrdn: new ndn (%s) does not exist\n", new_ndn ));
411 Debug( LDAP_DEBUG_TRACE,
412 "ldbm_back_modrdn: new ndn=%s does not exist\n",
416 #ifndef MULTIATTRVAL_RDN /* Ando 2001/07/06 */
418 /* Get attribute type and attribute value of our new rdn, we will
419 * need to add that to our new entry
421 if ( (new_rdn_type = rdn_attr_type( newrdn )) == NULL ) {
423 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
424 "ldbm_back_modrdn: can't figure out type of newrdn\n" ));
426 Debug( LDAP_DEBUG_TRACE,
427 "ldbm_back_modrdn: can't figure out type of newrdn\n",
431 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
432 NULL, "unknown type used in RDN", NULL, NULL );
436 if ( (new_rdn_val = rdn_attr_value( newrdn )) == NULL ) {
438 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
439 "ldbm_back_modrdn: can't figure out val of newrdn\n"));
441 Debug( LDAP_DEBUG_TRACE,
442 "ldbm_back_modrdn: can't figure out val of newrdn\n",
446 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
447 NULL, "could not parse RDN value", NULL, NULL );
452 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
453 "ldbm_back_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
454 new_rdn_val, new_rdn_type ));
456 Debug( LDAP_DEBUG_TRACE,
457 "ldbm_back_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
458 new_rdn_val, new_rdn_type, 0 );
461 /* Retrieve the old rdn from the entry's dn */
462 if ( (old_rdn = dn_rdn( be, dn )) == NULL ) {
464 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
465 "ldbm_back_modrdn: can't figure out old_rdn from dn (%s)\n",
468 Debug( LDAP_DEBUG_TRACE,
469 "ldbm_back_modrdn: can't figure out old_rdn from dn\n",
473 send_ldap_result( conn, op, LDAP_OTHER,
474 NULL, "could not parse old DN", NULL, NULL );
478 if ( (old_rdn_type = rdn_attr_type( old_rdn )) == NULL ) {
480 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
481 "ldbm_back_modrdn: can't figure out the old_rdn type.\n" ));
483 Debug( LDAP_DEBUG_TRACE,
484 "ldbm_back_modrdn: can't figure out the old_rdn type\n",
488 send_ldap_result( conn, op, LDAP_OTHER,
489 NULL, "could not parse RDN from old DN", NULL, NULL );
493 if ( newSuperior == NULL
494 && strcasecmp( old_rdn_type, new_rdn_type ) != 0 )
496 /* Not a big deal but we may say something */
498 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
499 "ldbm_back_modrdn: old_rdn_type=%s new_rdn_type=%s\n",
500 old_rdn_type, new_rdn_type ));
502 Debug( LDAP_DEBUG_TRACE,
503 "ldbm_back_modrdn: old_rdn_type=%s, new_rdn_type=%s!\n",
504 old_rdn_type, new_rdn_type, 0 );
509 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
510 "ldbm_back_modrdn: DN_X500\n" ));
512 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: DN_X500\n",
516 /* Add new attribute value to the entry.
519 add_bvals[0] = &add_bv; /* Array of bervals */
522 add_bv.bv_val = new_rdn_val;
523 add_bv.bv_len = strlen(new_rdn_val);
528 mod[0].sml_desc = NULL;
529 rc = slap_str2ad( new_rdn_type, &mod[0].sml_desc, &text );
531 if( rc != LDAP_SUCCESS ) {
533 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
534 "ldbm_back_modrdn: slap_str2ad error: %s (%s)\n",
535 text, new_rdn_type ));
537 Debug( LDAP_DEBUG_TRACE,
538 "ldbm_back_modrdn: %s: %s (new)\n",
539 text, new_rdn_type, 0 );
542 send_ldap_result( conn, op, rc,
543 NULL, text, NULL, NULL );
548 mod[0].sml_bvalues = add_bvals;
549 mod[0].sml_op = SLAP_MOD_SOFTADD;
550 mod[0].sml_next = NULL;
552 /* Remove old rdn value if required */
554 /* Get value of old rdn */
556 if ((old_rdn_val = rdn_attr_value( old_rdn )) == NULL) {
558 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
559 "ldbm_back_modrdn: can't figure out old_rdn_val from old_rdn\n" ));
561 Debug( LDAP_DEBUG_TRACE,
562 "ldbm_back_modrdn: can't figure out old_rdn_val from old_rdn\n",
566 send_ldap_result( conn, op, LDAP_OTHER,
567 NULL, "could not parse value from old RDN", NULL, NULL );
571 del_bvals[0] = &del_bv; /* Array of bervals */
574 /* Remove old value of rdn as an attribute. */
576 del_bv.bv_val = old_rdn_val;
577 del_bv.bv_len = strlen(old_rdn_val);
582 mod[1].sml_desc = NULL;
583 rc = slap_str2ad( old_rdn_type, &mod[1].sml_desc, &text );
585 if( rc != LDAP_SUCCESS ) {
587 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
588 "ldbm_back_modrdn: %s: %s (old)\n",
589 text, old_rdn_type ));
591 Debug( LDAP_DEBUG_TRACE,
592 "ldbm_back_modrdn: %s: %s (old)\n",
593 text, old_rdn_type, 0 );
596 send_ldap_result( conn, op, rc,
597 NULL, text, NULL, NULL );
602 mod[0].sml_next = &mod[1];
603 mod[1].sml_bvalues = del_bvals;
604 mod[1].sml_op = LDAP_MOD_DELETE;
605 mod[1].sml_next = NULL;
608 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
609 "ldbm_back_modrdn: removing old_rdn_val=%s\n", old_rdn_val ));
611 Debug( LDAP_DEBUG_TRACE,
612 "ldbm_back_modrdn: removing old_rdn_val=%s\n",
617 #else /* MULTIATTRVAL_RDN */
619 /* Get attribute types and values of our new rdn, we will
620 * need to add that to our new entry
622 if ( !rdn_attrs( newrdn, &new_rdn_types, &new_rdn_vals ) ) {
624 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
625 "ldbm_back_modrdn: can't figure out type(s)/value(s) of newrdn\n" ));
627 Debug( LDAP_DEBUG_TRACE,
628 "ldbm_back_modrdn: can't figure out type(s)/value(s) of newrdn\n",
632 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
633 NULL, "unable to parse type(s)/value(s) used in RDN", NULL, NULL );
638 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
639 "ldbm_back_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
640 new_rdn_vals[0], new_rdn_types[0] ));
642 Debug( LDAP_DEBUG_TRACE,
643 "ldbm_back_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
644 new_rdn_vals[0], new_rdn_types[0], 0 );
647 /* Retrieve the old rdn from the entry's dn */
648 if ( (old_rdn = dn_rdn( be, dn )) == NULL ) {
650 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
651 "ldbm_back_modrdn: can't figure out old_rdn from dn (%s)\n",
654 Debug( LDAP_DEBUG_TRACE,
655 "ldbm_back_modrdn: can't figure out old_rdn from dn\n",
659 send_ldap_result( conn, op, LDAP_OTHER,
660 NULL, "could not parse old DN", NULL, NULL );
664 if ( !rdn_attrs( old_rdn, &old_rdn_types, &old_rdn_vals ) ) {
666 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
667 "ldbm_back_modrdn: can't figure out the old_rdn type(s)/value(s).\n" ));
669 Debug( LDAP_DEBUG_TRACE,
670 "ldbm_back_modrdn: can't figure out the old_rdn type(s)/value(s)\n",
674 send_ldap_result( conn, op, LDAP_OTHER,
675 NULL, "unable to parse type(s)/value(s) used in RDN from old DN", NULL, NULL );
679 if ( newSuperior == NULL
680 && charray_strcasecmp( (const char **)old_rdn_types, (const char **)new_rdn_types ) != 0 )
682 /* Not a big deal but we may say something */
684 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
685 "ldbm_back_modrdn: old_rdn_type=%s new_rdn_type=%s\n",
686 old_rdn_types[0], new_rdn_types[0] ));
688 Debug( LDAP_DEBUG_TRACE,
689 "ldbm_back_modrdn: old_rdn_type=%s, new_rdn_type=%s!\n",
690 old_rdn_types[0], new_rdn_types[0], 0 );
695 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
696 "ldbm_back_modrdn: DN_X500\n" ));
698 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: DN_X500\n",
703 for ( a_cnt = 0; new_rdn_types[a_cnt]; a_cnt++ ) {
705 Modifications *mod_tmp;
707 mod_tmp = (Modifications *)ch_malloc( sizeof( Modifications ) );
709 mod_tmp->sml_desc = NULL;
710 rc = slap_str2ad( new_rdn_types[a_cnt],
711 &mod_tmp->sml_desc, &text );
713 if ( rc != LDAP_SUCCESS ) {
715 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
716 "ldbm_back_modrdn: slap_str2ad error: %s (%s)\n",
717 text, new_rdn_types[a_cnt] ));
719 Debug( LDAP_DEBUG_TRACE,
720 "ldbm_back_modrdn: %s: %s (new)\n",
721 text, new_rdn_types[a_cnt], 0 );
724 send_ldap_result( conn, op, rc,
725 NULL, text, NULL, NULL );
730 mod_tmp->sml_bvalues = (struct berval **)ch_malloc( 2 * sizeof(struct berval *) );
731 mod_tmp->sml_bvalues[0] = ber_bvstrdup( new_rdn_vals[a_cnt] );
732 mod_tmp->sml_bvalues[1] = NULL;
733 mod_tmp->sml_op = SLAP_MOD_SOFTADD;
734 mod_tmp->sml_next = mod;
738 /* Remove old rdn value if required */
739 if ( deleteoldrdn ) {
740 /* Get value of old rdn */
741 if ( old_rdn_vals == NULL ) {
743 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
744 "ldbm_back_modrdn: can't figure out old RDN value(s) from old RDN\n" ));
746 Debug( LDAP_DEBUG_TRACE,
747 "ldbm_back_modrdn: can't figure out oldRDN value(s) from old RDN\n",
751 send_ldap_result( conn, op, LDAP_OTHER,
752 NULL, "could not parse value(s) from old RDN", NULL, NULL );
756 for ( d_cnt = 0; old_rdn_types[d_cnt]; d_cnt++ ) {
758 Modifications *mod_tmp;
760 mod_tmp = (Modifications *)ch_malloc( sizeof( Modifications ) );
763 mod_tmp->sml_desc = NULL;
764 rc = slap_str2ad( old_rdn_types[d_cnt],
765 &mod_tmp->sml_desc, &text );
767 if ( rc != LDAP_SUCCESS ) {
769 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
770 "ldbm_back_modrdn: %s: %s (old)\n",
771 text, old_rdn_types[d_cnt] ));
773 Debug( LDAP_DEBUG_TRACE,
774 "ldbm_back_modrdn: %s: %s (old)\n",
775 text, old_rdn_types[d_cnt], 0 );
778 send_ldap_result( conn, op, rc,
779 NULL, text, NULL, NULL );
784 /* Remove old value of rdn as an attribute. */
785 mod_tmp->sml_bvalues = (struct berval **)ch_malloc( 2 * sizeof(struct berval *) );
786 mod_tmp->sml_bvalues[0] = ber_bvstrdup( old_rdn_vals[d_cnt] );
787 mod_tmp->sml_bvalues[1] = NULL;
788 mod_tmp->sml_op = LDAP_MOD_DELETE;
789 mod_tmp->sml_next = mod;
793 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
794 "ldbm_back_modrdn: removing old_rdn_val=%s\n", old_rdn_vals[0] ));
796 Debug( LDAP_DEBUG_TRACE,
797 "ldbm_back_modrdn: removing old_rdn_val=%s\n",
798 old_rdn_vals[0], 0, 0 );
803 #endif /* MULTIATTRVAL_RDN */
805 /* check for abandon */
806 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
807 if ( op->o_abandon ) {
808 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
811 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
814 if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
815 send_ldap_result( conn, op, LDAP_OTHER,
816 NULL, "DN index delete fail", NULL, NULL );
820 (void) cache_delete_entry( &li->li_cache, e );
822 /* XXX: there is no going back! */
832 if ( dn2id_add( be, e->e_ndn, e->e_id ) != 0 ) {
833 send_ldap_result( conn, op, LDAP_OTHER,
834 NULL, "DN index add failed", NULL, NULL );
838 /* modify memory copy of entry */
839 rc = ldbm_modify_internal( be, conn, op, dn, &mod[0], e,
840 &text, textbuf, textlen );
842 if( rc != LDAP_SUCCESS ) {
843 if( rc != SLAPD_ABANDON ) {
844 send_ldap_result( conn, op, rc,
845 NULL, text, NULL, NULL );
851 (void) cache_update_entry( &li->li_cache, e );
853 /* NOTE: after this you must not free new_dn or new_ndn!
854 * They are used by cache.
858 if ( id2entry_add( be, e ) != 0 ) {
860 send_ldap_result( conn, op, LDAP_OTHER,
861 NULL, "entry update failed", NULL, NULL );
865 send_ldap_result( conn, op, LDAP_SUCCESS,
866 NULL, NULL, NULL, NULL );
870 if( new_dn != NULL ) free( new_dn );
871 if( new_ndn != NULL ) free( new_ndn );
873 if( p_dn != NULL ) free( p_dn );
874 if( p_ndn != NULL ) free( p_ndn );
876 /* LDAP v2 supporting correct attribute handling. */
877 #ifndef MULTIATTRVAL_RDN
878 if( new_rdn_type != NULL ) free(new_rdn_type);
879 if( new_rdn_val != NULL ) free(new_rdn_val);
880 #else /* MULTIATTRVAL_RDN */
881 if( new_rdn_types != NULL ) charray_free( new_rdn_types );
882 if( new_rdn_vals != NULL ) charray_free( new_rdn_vals );
883 #endif /* MULTIATTRVAL_RDN */
884 if( old_rdn != NULL ) free(old_rdn);
885 #ifndef MULTIATTRVAL_RDN
886 if( old_rdn_type != NULL ) free(old_rdn_type);
887 if( old_rdn_val != NULL ) free(old_rdn_val);
888 #else /* MULTIATTRVAL_RDN */
889 if( old_rdn_types != NULL ) charray_free( old_rdn_types );
890 if( old_rdn_vals != NULL ) charray_free( old_rdn_vals );
891 #endif /* MULTIATTRVAL_RDN */
893 #ifdef MULTIATTRVAL_RDN
895 slap_mods_free( mod );
897 #endif /* MULTIATTRVAL_RDN */
899 /* LDAP v3 Support */
900 if ( np_dn != NULL ) free( np_dn );
901 if ( np_ndn != NULL ) free( np_ndn );
904 /* free new parent and writer lock */
905 cache_return_entry_w( &li->li_cache, np );
909 /* free parent and writer lock */
910 cache_return_entry_w( &li->li_cache, p );
914 /* release root writer lock */
915 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
918 /* free entry and writer lock */
919 cache_return_entry_w( &li->li_cache, e );