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