]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/modrdn.c
45f25b557f9c81cc05ed0c0054e6abb2a794902f
[openldap] / servers / slapd / back-bdb / modrdn.c
1 /* modrdn.c - bdb backend modrdn routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11 #include <ac/string.h>
12
13 #include "back-bdb.h"
14 #include "external.h"
15
16 int
17 bdb_modrdn(
18     Backend     *be,
19     Connection  *conn,
20     Operation   *op,
21     struct berval       *dn,
22     struct berval       *ndn,
23     struct berval       *newrdn,
24     struct berval       *nnewrdn,
25     int         deleteoldrdn,
26     struct berval       *newSuperior,
27     struct berval       *nnewSuperior
28 )
29 {
30         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
31         AttributeDescription *children = slap_schema.si_ad_children;
32         struct berval   p_dn, p_ndn;
33         struct berval   new_dn = {0, NULL}, new_ndn = {0, NULL};
34         int             isroot = -1;
35         Entry           *e, *p = NULL;
36         Entry           *matched;
37         int                     rc;
38         const char *text;
39         char textbuf[SLAP_TEXT_BUFLEN];
40         size_t textlen = sizeof textbuf;
41         DB_TXN *        ltid = NULL;
42         struct bdb_op_info opinfo;
43
44         ID                      id;
45         int             a_cnt, d_cnt;
46         LDAPRDN         *new_rdn = NULL;
47         LDAPRDN         *old_rdn = NULL;
48
49         Entry           *np = NULL;                     /* newSuperior Entry */
50         struct berval   *np_dn = NULL;                  /* newSuperior dn */
51         struct berval   *np_ndn = NULL;                 /* newSuperior ndn */
52         struct berval   *new_parent_dn = NULL;  /* np_dn, p_dn, or NULL */
53
54         /* Used to interface with bdb_modify_internal() */
55         Modifications   *mod = NULL;            /* Used to delete old rdn */
56
57         int             manageDSAit = get_manageDSAit( op );
58
59         Debug( LDAP_DEBUG_TRACE, "==>bdb_modrdn(%s,%s,%s)\n",
60                 dn->bv_val, newrdn->bv_val,
61                 newSuperior ? newSuperior->bv_val : "NULL" );
62
63 #if 0
64         if( newSuperior != NULL ) {
65                 rc = LDAP_UNWILLING_TO_PERFORM;
66                 text = "newSuperior not implemented (yet)";
67                 goto return_results;
68         }
69 #endif
70
71         if( 0 ) {
72 retry:  /* transaction retry */
73                 if (e != NULL) {
74                         bdb_cache_delete_entry(&bdb->bi_cache, e);
75                         bdb_cache_return_entry_w(&bdb->bi_cache, e);
76                 }
77                 if (p != NULL) {
78                         bdb_cache_return_entry_r(&bdb->bi_cache, p);
79                 }
80                 if (np != NULL) {
81                         bdb_cache_return_entry_r(&bdb->bi_cache, np);
82                 }
83                 Debug( LDAP_DEBUG_TRACE, "==>bdb_modrdn: retrying...\n", 0, 0, 0 );
84                 rc = txn_abort( ltid );
85                 ltid = NULL;
86                 op->o_private = NULL;
87                 if( rc != 0 ) {
88                         rc = LDAP_OTHER;
89                         text = "internal error";
90                         goto return_results;
91                 }
92                 ldap_pvt_thread_yield();
93         }
94
95         if( bdb->bi_txn ) {
96                 /* begin transaction */
97                 rc = txn_begin( bdb->bi_dbenv, NULL, &ltid, 
98                         bdb->bi_db_opflags );
99                 text = NULL;
100                 if( rc != 0 ) {
101                         Debug( LDAP_DEBUG_TRACE,
102                                 "bdb_delete: txn_begin failed: %s (%d)\n",
103                                 db_strerror(rc), rc, 0 );
104                         rc = LDAP_OTHER;
105                         text = "internal error";
106                         goto return_results;
107                 }
108         }
109
110         opinfo.boi_bdb = be;
111         opinfo.boi_txn = ltid;
112         opinfo.boi_err = 0;
113         op->o_private = &opinfo;
114
115         /* get entry */
116         rc = bdb_dn2entry_w( be, ltid, ndn, &e, &matched, 0 );
117
118         switch( rc ) {
119         case 0:
120         case DB_NOTFOUND:
121                 break;
122         case DB_LOCK_DEADLOCK:
123         case DB_LOCK_NOTGRANTED:
124                 goto retry;
125         default:
126                 rc = LDAP_OTHER;
127                 text = "internal error";
128                 goto return_results;
129         }
130
131         if ( e == NULL ) {
132                 char* matched_dn = NULL;
133                 BerVarray refs;
134
135                 if( matched != NULL ) {
136                         matched_dn = ch_strdup( matched->e_dn );
137                         refs = is_entry_referral( matched )
138                                 ? get_entry_referrals( be, conn, op, matched )
139                                 : NULL;
140                         bdb_cache_return_entry_r( &bdb->bi_cache, matched );
141                         matched = NULL;
142
143                 } else {
144                         refs = referral_rewrite( default_referral,
145                                 NULL, dn, LDAP_SCOPE_DEFAULT );
146                 }
147
148                 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
149                         matched_dn, NULL, refs, NULL );
150
151                 ber_bvarray_free( refs );
152                 free( matched_dn );
153
154                 goto done;
155         }
156
157         if (!manageDSAit && is_entry_referral( e ) ) {
158                 /* parent is a referral, don't allow add */
159                 /* parent is an alias, don't allow add */
160                 BerVarray refs = get_entry_referrals( be,
161                         conn, op, e );
162
163                 Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: entry %s is referral\n",
164                         e->e_dn, 0, 0 );
165
166                 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
167                         e->e_dn, NULL, refs, NULL );
168
169                 ber_bvarray_free( refs );
170                 goto done;
171         }
172
173         if ( be_issuffix( be, &e->e_nname ) ) {
174                 p_ndn = slap_empty_bv;
175         } else {
176                 rc = dnParent( &e->e_nname, &p_ndn );
177                 if ( rc != LDAP_SUCCESS ) {
178                         text = "internal error";
179                         goto return_results;
180                 }
181         }
182         np_ndn = &p_ndn;
183         if ( p_ndn.bv_len != 0 ) {
184                 /* Make sure parent entry exist and we can write its 
185                  * children.
186                  */
187                 rc = bdb_dn2entry_r( be, ltid, &p_ndn, &p, NULL, 0 );
188
189                 switch( rc ) {
190                 case 0:
191                 case DB_NOTFOUND:
192                         break;
193                 case DB_LOCK_DEADLOCK:
194                 case DB_LOCK_NOTGRANTED:
195                         goto retry;
196                 default:
197                         rc = LDAP_OTHER;
198                         text = "internal error";
199                         goto return_results;
200                 }
201
202                 if( p == NULL) {
203                         Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: parent does not exist\n",
204                                 0, 0, 0);
205                         rc = LDAP_OTHER;
206                         goto return_results;
207                 }
208
209                 /* check parent for "children" acl */
210                 if ( ! access_allowed( be, conn, op, p,
211                         children, NULL, ACL_WRITE ) )
212                 {
213                         Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
214                                 0, 0 );
215                         send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
216                                 NULL, NULL, NULL, NULL );
217                         goto return_results;
218                 }
219
220                 Debug( LDAP_DEBUG_TRACE,
221                         "bdb_modrdn: wr to children of entry %s OK\n",
222                         p_ndn.bv_val, 0, 0 );
223                 
224                 if ( p_ndn.bv_val == slap_empty_bv.bv_val ) {
225                         p_dn = slap_empty_bv;
226                 } else {
227                         rc = dnParent( &e->e_name, &p_dn );
228                         if ( rc != LDAP_SUCCESS ) {
229                                 text = "internal error";
230                                 goto return_results;
231                         }
232                 }
233
234                 Debug( LDAP_DEBUG_TRACE,
235                         "bdb_modrdn: parent dn=%s\n",
236                         p_dn.bv_val, 0, 0 );
237
238         } else {
239                 /* no parent, modrdn entry directly under root */
240                 isroot = be_isroot( be, &op->o_ndn );
241                 if ( ! isroot ) {
242                         if ( be_issuffix( be, (struct berval *)&slap_empty_bv )
243                                 || be_isupdate( be, &op->o_ndn ) ) {
244
245                                 p = (Entry *)&slap_entry_root;
246
247                                 /* check parent for "children" acl */
248                                 rc = access_allowed( be, conn, op, p,
249                                         children, NULL, ACL_WRITE );
250
251                                 p = NULL;
252
253                                 if ( ! rc )
254                                 {
255                                         Debug( LDAP_DEBUG_TRACE, 
256                                                 "no access to parent\n", 
257                                                 0, 0, 0 );
258                                         send_ldap_result( conn, op, 
259                                                 LDAP_INSUFFICIENT_ACCESS,
260                                                 NULL, NULL, NULL, NULL );
261                                         goto return_results;
262                                 }
263
264                                 Debug( LDAP_DEBUG_TRACE,
265                                         "bdb_modrdn: wr to children of entry \"\" OK\n",
266                                         0, 0, 0 );
267                 
268                                 p_dn.bv_val = "";
269                                 p_dn.bv_len = 0;
270
271                                 Debug( LDAP_DEBUG_TRACE,
272                                         "bdb_modrdn: parent dn=\"\"\n",
273                                         0, 0, 0 );
274
275                         } else {
276                                 Debug( LDAP_DEBUG_TRACE,
277                                         "bdb_modrdn: no parent, not root "
278                                         "& \"\" is not suffix\n",
279                                         0, 0, 0);
280                                 rc = LDAP_INSUFFICIENT_ACCESS;
281                                 goto return_results;
282                         }
283                 }
284         }
285
286         new_parent_dn = &p_dn;  /* New Parent unless newSuperior given */
287
288         if ( newSuperior != NULL ) {
289                 Debug( LDAP_DEBUG_TRACE, 
290                         "bdb_modrdn: new parent \"%s\" requested...\n",
291                         newSuperior->bv_val, 0, 0 );
292
293                 if ( newSuperior->bv_len ) {
294                         np_dn = newSuperior;
295                         np_ndn = nnewSuperior;
296
297                         /* newSuperior == oldParent?, if so ==> ERROR */
298                         /* newSuperior == entry being moved?, if so ==> ERROR */
299                         /* Get Entry with dn=newSuperior. Does newSuperior exist? */
300
301                         rc = bdb_dn2entry_r( be, ltid, nnewSuperior, &np, NULL, 0 );
302
303                         switch( rc ) {
304                         case 0:
305                         case DB_NOTFOUND:
306                                 break;
307                         case DB_LOCK_DEADLOCK:
308                         case DB_LOCK_NOTGRANTED:
309                                 goto retry;
310                         default:
311                                 rc = LDAP_OTHER;
312                                 text = "internal error";
313                                 goto return_results;
314                         }
315
316                         if( np == NULL) {
317                                 Debug( LDAP_DEBUG_TRACE,
318                                         "bdb_modrdn: newSup(ndn=%s) not here!\n",
319                                         np_ndn->bv_val, 0, 0);
320                                 rc = LDAP_OTHER;
321                                 goto return_results;
322                         }
323
324                         Debug( LDAP_DEBUG_TRACE,
325                                 "bdb_modrdn: wr to new parent OK np=%p, id=%ld\n",
326                                 np, (long) np->e_id, 0 );
327
328                         /* check newSuperior for "children" acl */
329                         if ( !access_allowed( be, conn, op, np, children, NULL, ACL_WRITE ) ) {
330                                 Debug( LDAP_DEBUG_TRACE,
331                                         "bdb_modrdn: no wr to newSup children\n",
332                                         0, 0, 0 );
333                                 rc = LDAP_INSUFFICIENT_ACCESS;
334                                 goto return_results;
335                         }
336
337                         if ( is_entry_alias( np ) ) {
338                                 /* parent is an alias, don't allow add */
339                                 Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: entry is alias\n",
340                                         0, 0, 0 );
341
342                                 rc = LDAP_ALIAS_PROBLEM;
343                                 goto return_results;
344                         }
345
346                         if ( is_entry_referral( np ) ) {
347                                 /* parent is a referral, don't allow add */
348                                 Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: entry is referral\n",
349                                         0, 0, 0 );
350
351                                 rc = LDAP_OPERATIONS_ERROR;
352                                 goto return_results;
353                         }
354
355                 } else {
356                         if ( isroot == -1 ) {
357                                 isroot = be_isroot( be, &op->o_ndn );
358                         }
359                         
360                         np_dn = NULL;
361
362                         /* no parent, modrdn entry directly under root */
363                         if ( ! isroot ) {
364                                 if ( be_issuffix( be, (struct berval *)&slap_empty_bv )
365                                         || be_isupdate( be, &op->o_ndn ) ) {
366                                         np = (Entry *)&slap_entry_root;
367
368                                         /* check parent for "children" acl */
369                                         rc = access_allowed( be, conn, op, np,
370                                                 children, NULL, ACL_WRITE );
371
372                                         np = NULL;
373
374                                         if ( ! rc )
375                                         {
376                                                 Debug( LDAP_DEBUG_TRACE, 
377                                                         "no access to new superior\n", 
378                                                         0, 0, 0 );
379                                                 send_ldap_result( conn, op, 
380                                                         LDAP_INSUFFICIENT_ACCESS,
381                                                         NULL, NULL, NULL, NULL );
382                                                 goto return_results;
383                                         }
384
385                                         Debug( LDAP_DEBUG_TRACE,
386                                                 "bdb_modrdn: wr to children of entry \"\" OK\n",
387                                                 0, 0, 0 );
388                 
389                                 } else {
390                                         Debug( LDAP_DEBUG_TRACE,
391                                                 "bdb_modrdn: new superior=\"\", not root "
392                                                 "& \"\" is not suffix\n",
393                                                 0, 0, 0);
394                                         rc = LDAP_INSUFFICIENT_ACCESS;
395                                         goto return_results;
396                                 }
397                         }
398
399                         Debug( LDAP_DEBUG_TRACE,
400                                 "bdb_modrdn: new superior=\"\"\n",
401                                 0, 0, 0 );
402                 }
403
404                 Debug( LDAP_DEBUG_TRACE,
405                         "bdb_modrdn: wr to new parent's children OK\n",
406                         0, 0, 0 );
407
408                 new_parent_dn = np_dn;
409         }
410         
411         /* Build target dn and make sure target entry doesn't exist already. */
412         build_new_dn( &new_dn, new_parent_dn, newrdn ); 
413
414         dnNormalize2( NULL, &new_dn, &new_ndn );
415
416         Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: new ndn=%s\n",
417                 new_ndn.bv_val, 0, 0 );
418
419         rc = bdb_dn2id ( be, ltid, &new_ndn, &id );
420         switch( rc ) {
421         case DB_LOCK_DEADLOCK:
422         case DB_LOCK_NOTGRANTED:
423                 goto retry;
424         case DB_NOTFOUND:
425                 break;
426         case 0:
427                 rc = LDAP_ALREADY_EXISTS;
428                 goto return_results;
429         default:
430                 rc = LDAP_OTHER;
431                 text = "internal error";
432                 goto return_results;
433         }
434
435         Debug( LDAP_DEBUG_TRACE,
436                 "bdb_modrdn: new ndn=%s does not exist\n",
437                 new_ndn.bv_val, 0, 0 );
438
439         /* Get attribute type and attribute value of our new rdn, we will
440          * need to add that to our new entry
441          */
442         if ( ldap_str2rdn( newrdn->bv_val, &new_rdn, (char **)&text,
443                 LDAP_DN_FORMAT_LDAP ) )
444         {
445                 Debug( LDAP_DEBUG_TRACE,
446                         "bdb_modrdn: can't figure out type(s)/values(s) "
447                         "of newrdn\n", 0, 0, 0 );
448                 rc = LDAP_OPERATIONS_ERROR;
449                 text = "unknown type(s) used in RDN";
450                 goto return_results;            
451         }
452
453         Debug( LDAP_DEBUG_TRACE,
454                 "bdb_modrdn: new_rdn_type=\"%s\", new_rdn_val=\"%s\"\n",
455                 new_rdn[0][0]->la_attr.bv_val, new_rdn[0][0]->la_value.bv_val, 0 );
456
457         if ( ldap_str2rdn( dn->bv_val, &old_rdn, (char **)&text,
458                 LDAP_DN_FORMAT_LDAP ) )
459         {
460                 Debug( LDAP_DEBUG_TRACE,
461                         "bdb_back_modrdn: can't figure out the old_rdn "
462                         "type(s)/value(s)\n", 0, 0, 0 );
463                 rc = LDAP_OTHER;
464                 text = "cannot parse RDN from old DN";
465                 goto return_results;            
466         }
467
468 #if 0
469         if ( newSuperior == NULL
470                 && charray_strcasecmp( ( const char ** )old_rdn_types, 
471                                 ( const char ** )new_rdn_types ) != 0 ) {
472                 /* Not a big deal but we may say something */
473                 Debug( LDAP_DEBUG_TRACE,
474                         "bdb_modrdn: old_rdn_type(s)=%s, new_rdn_type(s)=%s "
475                         "do not match\n", 
476                         old_rdn_types[ 0 ], new_rdn_types[ 0 ], 0 );
477         }               
478 #endif
479
480         /* Add new attribute values to the entry */
481         for ( a_cnt = 0; new_rdn[0][ a_cnt ]; a_cnt++ ) {
482                 int                     rc;
483                 AttributeDescription    *desc = NULL;
484                 Modifications           *mod_tmp;
485
486                 rc = slap_bv2ad( &new_rdn[0][ a_cnt ]->la_attr, &desc, &text );
487
488                 if ( rc != LDAP_SUCCESS ) {
489                         Debug( LDAP_DEBUG_TRACE,
490                                 "bdb_modrdn: %s: %s (new)\n",
491                                 text, new_rdn[0][ a_cnt ]->la_attr.bv_val, 0 );
492                         goto return_results;            
493                 }
494
495                 /* ACL check of newly added attrs */
496                 if ( !access_allowed( be, conn, op, e, desc,
497                         &new_rdn[0][ a_cnt ]->la_value, ACL_WRITE ) ) {
498                         Debug( LDAP_DEBUG_TRACE,
499                                 "bdb_modrdn: access to attr \"%s\" "
500                                 "(new) not allowed\n", 
501                                 new_rdn[0][ a_cnt ]->la_attr.bv_val, 0, 0 );
502                         rc = LDAP_INSUFFICIENT_ACCESS;
503                         goto return_results;
504                 }
505
506                 /* Apply modification */
507                 mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications )
508                         + 2 * sizeof( struct berval ) );
509                 mod_tmp->sml_desc = desc;
510                 mod_tmp->sml_bvalues = ( BerVarray )( mod_tmp + 1 );
511                 mod_tmp->sml_bvalues[ 0 ] = new_rdn[0][ a_cnt ]->la_value;
512                 mod_tmp->sml_bvalues[ 1 ].bv_val = NULL;
513                 mod_tmp->sml_op = SLAP_MOD_SOFTADD;
514                 mod_tmp->sml_next = mod;
515                 mod = mod_tmp;
516         }
517
518         /* Remove old rdn value if required */
519         if ( deleteoldrdn ) {
520                 /* Get value of old rdn */
521                 if ( old_rdn == NULL) {
522                         Debug( LDAP_DEBUG_TRACE,
523                                 "bdb_modrdn: can't figure out old RDN value(s) "
524                                 "from old RDN\n", 0, 0, 0 );
525                         rc = LDAP_OTHER;
526                         text = "could not parse value(s) from old RDN";
527                         goto return_results;            
528                 }
529
530                 for ( d_cnt = 0; old_rdn[0][ d_cnt ]; d_cnt++ ) {
531                         int                     rc;
532                         AttributeDescription    *desc = NULL;
533                         Modifications           *mod_tmp;
534
535                         rc = slap_bv2ad( &old_rdn[0][ d_cnt ]->la_attr,
536                                         &desc, &text );
537
538                         if ( rc != LDAP_SUCCESS ) {
539                                 Debug( LDAP_DEBUG_TRACE,
540                                         "bdb_modrdn: %s: %s (old)\n",
541                                         text, old_rdn[0][ d_cnt ]->la_attr.bv_val, 0 );
542                                 goto return_results;            
543                         }
544
545                         /* ACL check of newly added attrs */
546                         if ( !access_allowed( be, conn, op, e, desc,
547                                 &old_rdn[0][d_cnt]->la_value, ACL_WRITE ) ) {
548                                 Debug( LDAP_DEBUG_TRACE,
549                                         "bdb_modrdn: access to attr \"%s\" "
550                                         "(old) not allowed\n", 
551                                         old_rdn[0][ d_cnt ]->la_attr.bv_val, 0, 0 );
552                                 rc = LDAP_INSUFFICIENT_ACCESS;
553                                 goto return_results;
554                         }
555
556                         /* Apply modification */
557                         mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications )
558                                 + 2 * sizeof ( struct berval ) );
559                         mod_tmp->sml_desc = desc;
560                         mod_tmp->sml_bvalues = ( BerVarray )(mod_tmp+1);
561                         mod_tmp->sml_bvalues[ 0 ] = old_rdn[0][ d_cnt ]->la_value;
562                         mod_tmp->sml_bvalues[ 1 ].bv_val = NULL;
563                         mod_tmp->sml_op = LDAP_MOD_DELETE;
564                         mod_tmp->sml_next = mod;
565                         mod = mod_tmp;
566                 }
567         }
568         
569         /* delete old one */
570         rc = bdb_dn2id_delete( be, ltid, p_ndn.bv_val, e );
571         if ( rc != 0 ) {
572                 switch( rc ) {
573                 case DB_LOCK_DEADLOCK:
574                 case DB_LOCK_NOTGRANTED:
575                         goto retry;
576                 }
577                 rc = LDAP_OTHER;
578                 text = "DN index delete fail";
579                 goto return_results;
580         }
581
582         (void) bdb_cache_delete_entry(&bdb->bi_cache, e);
583
584         /* Binary format uses a single contiguous block, cannot
585          * free individual fields. Leave new_dn/new_ndn set so
586          * they can be individually freed later.
587          */
588         e->e_name = new_dn;
589         e->e_nname = new_ndn;
590
591         new_dn.bv_val = NULL;
592         new_ndn.bv_val = NULL;
593
594         /* add new one */
595         rc = bdb_dn2id_add( be, ltid, np_ndn, e );
596         if ( rc != 0 ) {
597                 switch( rc ) {
598                 case DB_LOCK_DEADLOCK:
599                 case DB_LOCK_NOTGRANTED:
600                         goto retry;
601                 }
602                 rc = LDAP_OTHER;
603                 text = "DN index add failed";
604                 goto return_results;
605         }
606
607         /* modify entry */
608         rc = bdb_modify_internal( be, conn, op, ltid, &mod[0], e,
609                 &text, textbuf, textlen );
610
611         if( rc != LDAP_SUCCESS ) {
612                 switch( rc ) {
613                 case DB_LOCK_DEADLOCK:
614                 case DB_LOCK_NOTGRANTED:
615                         goto retry;
616                 }
617                 goto return_results;
618         }
619         
620         /* id2entry index */
621         rc = bdb_id2entry_update( be, ltid, e );
622         if ( rc != 0 ) {
623                 switch( rc ) {
624                 case DB_LOCK_DEADLOCK:
625                 case DB_LOCK_NOTGRANTED:
626                         goto retry;
627                 }
628                 rc = LDAP_OTHER;
629                 text = "entry update failed";
630                 goto return_results;
631         }
632
633         if( bdb->bi_txn ) {
634                 rc = txn_commit( ltid, 0 );
635         }
636         ltid = NULL;
637         op->o_private = NULL;
638
639         if( rc != 0 ) {
640                 Debug( LDAP_DEBUG_TRACE,
641                         "bdb_modrdn: txn_commit failed: %s (%d)\n",
642                         db_strerror(rc), rc, 0 );
643                 rc = LDAP_OTHER;
644                 text = "commit failed";
645         } else {
646                 (void) bdb_cache_update_entry(&bdb->bi_cache, e);
647                 Debug( LDAP_DEBUG_TRACE,
648                         "bdb_modrdn: added id=%08lx dn=\"%s\"\n",
649                         e->e_id, e->e_dn, 0 );
650                 rc = LDAP_SUCCESS;
651                 text = NULL;
652                 bdb_cache_entry_commit( e );
653         }
654
655 return_results:
656         send_ldap_result( conn, op, rc,
657                 NULL, text, NULL, NULL );
658
659         if( rc == LDAP_SUCCESS && bdb->bi_txn_cp ) {
660                 ldap_pvt_thread_yield();
661                 TXN_CHECKPOINT( bdb->bi_dbenv,
662                         bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
663         }
664
665 done:
666         if( new_dn.bv_val != NULL ) free( new_dn.bv_val );
667         if( new_ndn.bv_val != NULL ) free( new_ndn.bv_val );
668
669         /* LDAP v2 supporting correct attribute handling. */
670         if( new_rdn != NULL ) ldap_rdnfree( new_rdn );
671         if( old_rdn != NULL ) ldap_rdnfree( old_rdn );
672         if( mod != NULL ) {
673                 Modifications *tmp;
674                 for (; mod; mod=tmp ) {
675                         tmp = mod->sml_next;
676                         free( mod );
677                 }
678         }
679
680         /* LDAP v3 Support */
681         if( np != NULL ) {
682                 /* free new parent and reader lock */
683                 bdb_cache_return_entry_r(&bdb->bi_cache, np);
684         }
685
686         if( p != NULL ) {
687                 /* free parent and reader lock */
688                 bdb_cache_return_entry_r(&bdb->bi_cache, p);
689         }
690
691         /* free entry */
692         if( e != NULL ) {
693                 bdb_cache_return_entry_w( &bdb->bi_cache, e );
694         }
695
696         if( ltid != NULL ) {
697                 txn_abort( ltid );
698                 op->o_private = NULL;
699         }
700
701         return rc;
702 }