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