]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/modrdn.c
Quick patch to support struct berval dn2entry changes
[openldap] / servers / slapd / back-bdb / modrdn.c
1 /* modrdn.c - bdb backend modrdn routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 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         char            *p_dn = NULL, *p_ndn = NULL;
33         char            *new_dn = NULL, *new_ndn = 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         struct berval bv;
45
46         ID                      id;
47         char            **new_rdn_vals = NULL;  /* Vals of new rdn */
48         char            **new_rdn_types = NULL; /* Types of new rdn */
49         int             a_cnt, d_cnt;
50         char            *old_rdn = NULL;        /* Old rdn's attr type & val */
51         char            **old_rdn_types = NULL; /* Types of old rdn attr. */
52         char            **old_rdn_vals = NULL;  /* Old rdn attribute values */
53
54         Entry           *np = NULL;                             /* newSuperior Entry */
55         char            *np_dn = NULL;                  /* newSuperior dn */
56         char            *np_ndn = NULL;                 /* newSuperior ndn */
57         char            *new_parent_dn = NULL;  /* np_dn, p_dn, or NULL */
58
59         /* Used to interface with bdb_modify_internal() */
60         Modifications   *mod = NULL;            /* Used to delete old rdn */
61
62         int             manageDSAit = get_manageDSAit( op );
63
64         Debug( LDAP_DEBUG_TRACE, "==>bdb_modrdn(%s,%s,%s)\n",
65                 dn->bv_val, newrdn->bv_val,
66                 newSuperior ? newSuperior->bv_val : "NULL" );
67
68 #if 0
69         if( newSuperior != NULL ) {
70                 rc = LDAP_UNWILLING_TO_PERFORM;
71                 text = "newSuperior not implemented (yet)";
72                 goto return_results;
73         }
74 #endif
75
76         if( 0 ) {
77 retry:  /* transaction retry */
78                 Debug( LDAP_DEBUG_TRACE, "==>bdb_modrdn: retrying...\n", 0, 0, 0 );
79                 rc = txn_abort( ltid );
80                 ltid = NULL;
81                 op->o_private = NULL;
82                 if( rc != 0 ) {
83                         rc = LDAP_OTHER;
84                         text = "internal error";
85                         goto return_results;
86                 }
87         }
88
89         if( bdb->bi_txn ) {
90                 /* begin transaction */
91                 rc = txn_begin( bdb->bi_dbenv, NULL, &ltid, 
92                         bdb->bi_db_opflags );
93                 text = NULL;
94                 if( rc != 0 ) {
95                         Debug( LDAP_DEBUG_TRACE,
96                                 "bdb_delete: txn_begin failed: %s (%d)\n",
97                                 db_strerror(rc), rc, 0 );
98                         rc = LDAP_OTHER;
99                         text = "internal error";
100                         goto return_results;
101                 }
102         }
103
104         opinfo.boi_bdb = be;
105         opinfo.boi_txn = ltid;
106         opinfo.boi_err = 0;
107         op->o_private = &opinfo;
108
109         /* get entry */
110         rc = bdb_dn2entry( be, ltid, ndn, &e, &matched, 0 );
111
112         switch( rc ) {
113         case 0:
114         case DB_NOTFOUND:
115                 break;
116         case DB_LOCK_DEADLOCK:
117         case DB_LOCK_NOTGRANTED:
118                 goto retry;
119         default:
120                 rc = LDAP_OTHER;
121                 text = "internal error";
122                 goto return_results;
123         }
124
125         if ( e == NULL ) {
126                 char* matched_dn = NULL;
127                 struct berval** refs;
128
129                 if( matched != NULL ) {
130                         matched_dn = strdup( matched->e_dn );
131                         refs = is_entry_referral( matched )
132                                 ? get_entry_referrals( be, conn, op, matched )
133                                 : NULL;
134                         bdb_entry_return( be, matched );
135                         matched = NULL;
136
137                 } else {
138                         refs = referral_rewrite( default_referral,
139                                 NULL, dn, LDAP_SCOPE_DEFAULT );
140                 }
141
142                 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
143                         matched_dn, NULL, refs, NULL );
144
145                 ber_bvecfree( refs );
146                 free( matched_dn );
147
148                 goto done;
149         }
150
151         if (!manageDSAit && is_entry_referral( e ) ) {
152                 /* parent is a referral, don't allow add */
153                 /* parent is an alias, don't allow add */
154                 struct berval **refs = get_entry_referrals( be,
155                         conn, op, e );
156
157                 Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: entry %s is referral\n",
158                         e->e_dn, 0, 0 );
159
160                 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
161                         e->e_dn, NULL, refs, NULL );
162
163                 ber_bvecfree( refs );
164                 goto done;
165         }
166
167         p_ndn = dn_parent( be, e->e_ndn );
168         np_ndn = p_ndn;
169         if ( p_ndn != NULL && p_ndn[ 0 ] != '\0' ) {
170                 /* Make sure parent entry exist and we can write its 
171                  * children.
172                  */
173                 bv.bv_val = p_ndn;
174                 bv.bv_len = strlen( p_ndn );
175
176                 rc = bdb_dn2entry( be, ltid, &bv, &p, NULL, 0 );
177
178                 switch( rc ) {
179                 case 0:
180                 case DB_NOTFOUND:
181                         break;
182                 case DB_LOCK_DEADLOCK:
183                 case DB_LOCK_NOTGRANTED:
184                         goto retry;
185                 default:
186                         rc = LDAP_OTHER;
187                         text = "internal error";
188                         goto return_results;
189                 }
190
191                 if( p == NULL) {
192                         Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: parent does not exist\n",
193                                 0, 0, 0);
194                         rc = LDAP_OTHER;
195                         goto return_results;
196                 }
197
198                 /* check parent for "children" acl */
199                 if ( ! access_allowed( be, conn, op, p,
200                         children, NULL, ACL_WRITE ) )
201                 {
202                         Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
203                                 0, 0 );
204                         send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
205                                 NULL, NULL, NULL, NULL );
206                         goto return_results;
207                 }
208
209                 Debug( LDAP_DEBUG_TRACE,
210                         "bdb_modrdn: wr to children of entry %s OK\n",
211                         p_ndn, 0, 0 );
212                 
213                 p_dn = dn_parent( be, e->e_dn );
214
215                 Debug( LDAP_DEBUG_TRACE,
216                         "bdb_modrdn: parent dn=%s\n",
217                         p_dn, 0, 0 );
218
219         } else {
220                 /* no parent, modrdn entry directly under root */
221                 isroot = be_isroot( be, &op->o_ndn );
222                 if ( ! isroot ) {
223                         if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
224
225                                 p = (Entry *)&slap_entry_root;
226
227                                 /* check parent for "children" acl */
228                                 rc = access_allowed( be, conn, op, p,
229                                         children, NULL, ACL_WRITE );
230
231                                 p = NULL;
232
233                                 if ( ! rc )
234                                 {
235                                         Debug( LDAP_DEBUG_TRACE, 
236                                                 "no access to parent\n", 
237                                                 0, 0, 0 );
238                                         send_ldap_result( conn, op, 
239                                                 LDAP_INSUFFICIENT_ACCESS,
240                                                 NULL, NULL, NULL, NULL );
241                                         goto return_results;
242                                 }
243
244                                 Debug( LDAP_DEBUG_TRACE,
245                                         "bdb_modrdn: wr to children of entry \"\" OK\n",
246                                         0, 0, 0 );
247                 
248                                 p_dn = "";
249
250                                 Debug( LDAP_DEBUG_TRACE,
251                                         "bdb_modrdn: parent dn=\"\"\n",
252                                         0, 0, 0 );
253
254                         } else {
255                                 Debug( LDAP_DEBUG_TRACE,
256                                         "bdb_modrdn: no parent, not root "
257                                         "& \"\" is not suffix\n",
258                                         0, 0, 0);
259                                 rc = LDAP_INSUFFICIENT_ACCESS;
260                                 goto return_results;
261                         }
262                 }
263         }
264
265         new_parent_dn = p_dn;   /* New Parent unless newSuperior given */
266
267         if ( newSuperior != NULL ) {
268                 Debug( LDAP_DEBUG_TRACE, 
269                         "bdb_modrdn: new parent \"%s\" requested...\n",
270                         newSuperior->bv_val, 0, 0 );
271
272                 if ( newSuperior->bv_len ) {
273                         np_dn = ch_strdup( newSuperior->bv_val );
274                         np_ndn = ch_strdup( np_dn );
275                         (void) dn_normalize( np_ndn );
276
277                         /* newSuperior == oldParent?, if so ==> ERROR */
278                         /* newSuperior == entry being moved?, if so ==> ERROR */
279                         /* Get Entry with dn=newSuperior. Does newSuperior exist? */
280
281                         bv.bv_val = np_ndn;
282                         bv.bv_len = strlen( np_ndn );
283                         rc = bdb_dn2entry( be, ltid, &bv, &np, NULL, 0 );
284
285                         switch( rc ) {
286                         case 0:
287                         case DB_NOTFOUND:
288                                 break;
289                         case DB_LOCK_DEADLOCK:
290                         case DB_LOCK_NOTGRANTED:
291                                 goto retry;
292                         default:
293                                 rc = LDAP_OTHER;
294                                 text = "internal error";
295                                 goto return_results;
296                         }
297
298                         if( np == NULL) {
299                                 Debug( LDAP_DEBUG_TRACE,
300                                         "bdb_modrdn: newSup(ndn=%s) not here!\n",
301                                         np_ndn, 0, 0);
302                                 rc = LDAP_OTHER;
303                                 goto return_results;
304                         }
305
306                         Debug( LDAP_DEBUG_TRACE,
307                                 "bdb_modrdn: wr to new parent OK np=%p, id=%ld\n",
308                                 np, (long) np->e_id, 0 );
309
310                         /* check newSuperior for "children" acl */
311                         if ( !access_allowed( be, conn, op, np, children, NULL, ACL_WRITE ) ) {
312                                 Debug( LDAP_DEBUG_TRACE,
313                                         "bdb_modrdn: no wr to newSup children\n",
314                                         0, 0, 0 );
315                                 rc = LDAP_INSUFFICIENT_ACCESS;
316                                 goto return_results;
317                         }
318
319                         if ( is_entry_alias( np ) ) {
320                                 /* parent is an alias, don't allow add */
321                                 Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: entry is alias\n",
322                                         0, 0, 0 );
323
324                                 rc = LDAP_ALIAS_PROBLEM;
325                                 goto return_results;
326                         }
327
328                         if ( is_entry_referral( np ) ) {
329                                 /* parent is a referral, don't allow add */
330                                 Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: entry is referral\n",
331                                         0, 0, 0 );
332
333                                 rc = LDAP_OPERATIONS_ERROR;
334                                 goto return_results;
335                         }
336
337                 } else {
338                         if ( isroot == -1 ) {
339                                 isroot = be_isroot( be, &op->o_ndn );
340                         }
341                         
342                         np_dn = ch_strdup( "" );
343
344                         /* no parent, modrdn entry directly under root */
345                         if ( ! isroot ) {
346                                 if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
347                                         np = (Entry *)&slap_entry_root;
348
349                                         /* check parent for "children" acl */
350                                         rc = access_allowed( be, conn, op, np,
351                                                 children, NULL, ACL_WRITE );
352
353                                         np = NULL;
354
355                                         if ( ! rc )
356                                         {
357                                                 Debug( LDAP_DEBUG_TRACE, 
358                                                         "no access to new superior\n", 
359                                                         0, 0, 0 );
360                                                 send_ldap_result( conn, op, 
361                                                         LDAP_INSUFFICIENT_ACCESS,
362                                                         NULL, NULL, NULL, NULL );
363                                                 goto return_results;
364                                         }
365
366                                         Debug( LDAP_DEBUG_TRACE,
367                                                 "bdb_modrdn: wr to children of entry \"\" OK\n",
368                                                 0, 0, 0 );
369                 
370                                 } else {
371                                         Debug( LDAP_DEBUG_TRACE,
372                                                 "bdb_modrdn: new superior=\"\", not root "
373                                                 "& \"\" is not suffix\n",
374                                                 0, 0, 0);
375                                         rc = LDAP_INSUFFICIENT_ACCESS;
376                                         goto return_results;
377                                 }
378                         }
379
380                         Debug( LDAP_DEBUG_TRACE,
381                                 "bdb_modrdn: new superior=\"\"\n",
382                                 0, 0, 0 );
383                 }
384
385                 Debug( LDAP_DEBUG_TRACE,
386                         "bdb_modrdn: wr to new parent's children OK\n",
387                         0, 0, 0 );
388
389                 new_parent_dn = np_dn;
390         }
391         
392         /* Build target dn and make sure target entry doesn't exist already. */
393         build_new_dn( &new_dn, e->e_dn, new_parent_dn, newrdn->bv_val ); 
394
395         new_ndn = ch_strdup( new_dn );
396         (void) dn_normalize( new_ndn );
397
398         Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: new ndn=%s\n",
399                 new_ndn, 0, 0 );
400
401         bv.bv_val = new_ndn;
402         bv.bv_len = strlen( new_ndn );
403         rc = bdb_dn2id ( be, ltid, &bv, &id );
404         switch( rc ) {
405         case DB_LOCK_DEADLOCK:
406         case DB_LOCK_NOTGRANTED:
407                 goto retry;
408         case DB_NOTFOUND:
409                 break;
410         case 0:
411                 rc = LDAP_ALREADY_EXISTS;
412                 goto return_results;
413         default:
414                 rc = LDAP_OTHER;
415                 text = "internal error";
416                 goto return_results;
417         }
418
419         Debug( LDAP_DEBUG_TRACE,
420                 "bdb_modrdn: new ndn=%s does not exist\n",
421                 new_ndn, 0, 0 );
422
423         /* Get attribute type and attribute value of our new rdn, we will
424          * need to add that to our new entry
425          */
426
427         if ( rdn_attrs( newrdn->bv_val, &new_rdn_types, &new_rdn_vals ) ) {
428                 Debug( LDAP_DEBUG_TRACE,
429                         "bdb_modrdn: can't figure out type(s)/values(s) "
430                         "of newrdn\n", 0, 0, 0 );
431                 rc = LDAP_OPERATIONS_ERROR;
432                 text = "unknown type(s) used in RDN";
433                 goto return_results;            
434         }
435
436         Debug( LDAP_DEBUG_TRACE,
437                 "bdb_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
438                 new_rdn_vals[0], new_rdn_types[0], 0 );
439
440         /* Retrieve the old rdn from the entry's dn */
441         if ( ( old_rdn = dn_rdn( be, dn->bv_val ) ) == NULL ) {
442                 Debug( LDAP_DEBUG_TRACE,
443                         "bdb_modrdn: can't figure out old_rdn from dn\n",
444                         0, 0, 0 );
445                 rc = LDAP_OTHER;
446                 text = "could not parse old DN";
447                 goto return_results;            
448         }
449
450         if ( rdn_attrs( old_rdn, &old_rdn_types, &old_rdn_vals ) ) {
451                 Debug( LDAP_DEBUG_TRACE,
452                         "bdb_back_modrdn: can't figure out the old_rdn "
453                         "type(s)/value(s)\n", 0, 0, 0 );
454                 rc = LDAP_OTHER;
455                 text = "cannot parse RDN from old DN";
456                 goto return_results;            
457         }
458         
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
469         /* Add new attribute values to the entry */
470         for ( a_cnt = 0; new_rdn_types[ a_cnt ]; a_cnt++ ) {
471                 int                     rc;
472                 AttributeDescription    *desc = NULL;
473                 Modifications           *mod_tmp;
474                 struct berval           val;
475
476                 rc = slap_str2ad( new_rdn_types[ a_cnt ], &desc, &text );
477
478                 if ( rc != LDAP_SUCCESS ) {
479                         Debug( LDAP_DEBUG_TRACE,
480                                 "bdb_modrdn: %s: %s (new)\n",
481                                 text, new_rdn_types[ a_cnt ], 0 );
482                         goto return_results;            
483                 }
484
485                 /* ACL check of newly added attrs */
486                 val.bv_val = new_rdn_vals[ a_cnt ];
487                 val.bv_len = strlen( val.bv_val );
488                 if ( !access_allowed( be, conn, op, e, 
489                                 desc, &val, ACL_WRITE ) ) {
490                         Debug( LDAP_DEBUG_TRACE,
491                                 "bdb_modrdn: access to attr \"%s\" "
492                                 "(new) not allowed\n", 
493                                 new_rdn_types[ a_cnt ], 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                 mod_tmp->sml_desc = desc;
501                 mod_tmp->sml_bvalues = ( struct berval ** )ch_malloc( 2*sizeof( struct berval * ) );
502                 mod_tmp->sml_bvalues[ 0 ] = ber_bvstrdup( new_rdn_vals[ a_cnt ] );
503                 mod_tmp->sml_bvalues[ 1 ] = NULL;
504                 mod_tmp->sml_op = SLAP_MOD_SOFTADD;
505                 mod_tmp->sml_next = mod;
506                 mod = mod_tmp;
507         }
508
509         /* Remove old rdn value if required */
510         if ( deleteoldrdn ) {
511                 /* Get value of old rdn */
512                 if ( old_rdn_vals == NULL) {
513                         Debug( LDAP_DEBUG_TRACE,
514                                 "bdb_modrdn: can't figure out old RDN value(s) "
515                                 "from old RDN\n", 0, 0, 0 );
516                         rc = LDAP_OTHER;
517                         text = "could not parse value(s) from old RDN";
518                         goto return_results;            
519                 }
520
521                 for ( d_cnt = 0; old_rdn_types[ d_cnt ]; d_cnt++ ) {
522                         int                     rc;
523                         AttributeDescription    *desc = NULL;
524                         Modifications           *mod_tmp;
525                         struct berval           val;
526
527                         rc = slap_str2ad( old_rdn_types[ d_cnt ],
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_types[ d_cnt ], 0 );
534                                 goto return_results;            
535                         }
536
537                         /* ACL check of newly added attrs */
538                         val.bv_val = new_rdn_vals[ d_cnt ];
539                         val.bv_len = strlen( val.bv_val );
540                         if ( !access_allowed( be, conn, op, e, 
541                                         desc, &val, ACL_WRITE ) ) {
542                                 Debug( LDAP_DEBUG_TRACE,
543                                         "bdb_modrdn: access to attr \"%s\" "
544                                         "(old) not allowed\n", 
545                                         old_rdn_types[ d_cnt ], 0, 0 );
546                                 rc = LDAP_INSUFFICIENT_ACCESS;
547                                 goto return_results;
548                         }
549
550                         /* Apply modification */
551                         mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications ) );
552                         mod_tmp->sml_desc = desc;
553                         mod_tmp->sml_bvalues = ( struct berval ** )ch_malloc( 2*sizeof( struct berval * ) );
554                         mod_tmp->sml_bvalues[ 0 ] = ber_bvstrdup( old_rdn_vals[ d_cnt ] );
555                         mod_tmp->sml_bvalues[ 1 ] = NULL;
556                         mod_tmp->sml_op = LDAP_MOD_DELETE;
557                         mod_tmp->sml_next = mod;
558                         mod = mod_tmp;
559                 }
560         }
561         
562         /* delete old one */
563         rc = bdb_dn2id_delete( be, ltid, p_ndn, e );
564         if ( rc != 0 ) {
565                 switch( rc ) {
566                 case DB_LOCK_DEADLOCK:
567                 case DB_LOCK_NOTGRANTED:
568                         goto retry;
569                 }
570                 rc = LDAP_OTHER;
571                 text = "DN index delete fail";
572                 goto return_results;
573         }
574
575         /* Binary format uses a single contiguous block, cannot
576          * free individual fields. Leave new_dn/new_ndn set so
577          * they can be individually freed later.
578          */
579         e->e_dn = new_dn;
580         e->e_name.bv_len = strlen( new_dn );
581         e->e_ndn = new_ndn;
582         e->e_nname.bv_len = strlen( new_ndn );
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         if( bdb->bi_txn ) {
624                 rc = txn_commit( ltid, 0 );
625         }
626         ltid = NULL;
627         op->o_private = NULL;
628
629         if( rc != 0 ) {
630                 Debug( LDAP_DEBUG_TRACE,
631                         "bdb_modrdn: txn_commit failed: %s (%d)\n",
632                         db_strerror(rc), rc, 0 );
633                 rc = LDAP_OTHER;
634                 text = "commit failed";
635         } else {
636                 Debug( LDAP_DEBUG_TRACE,
637                         "bdb_modrdn: added id=%08lx dn=\"%s\"\n",
638                         e->e_id, e->e_dn, 0 );
639                 rc = LDAP_SUCCESS;
640                 text = NULL;
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 != NULL ) free( new_dn );
655         if( new_ndn != NULL ) free( new_ndn );
656
657         if( np_ndn == p_ndn ) np_ndn = NULL;
658
659         /* LDAP v2 supporting correct attribute handling. */
660         if( new_rdn_types != NULL ) charray_free(new_rdn_types);
661         if( new_rdn_vals != NULL ) charray_free(new_rdn_vals);
662         if( old_rdn != NULL ) free(old_rdn);
663         if( old_rdn_types != NULL ) charray_free(old_rdn_types);
664         if( old_rdn_vals != NULL ) charray_free(old_rdn_vals);
665         if( mod != NULL ) slap_mods_free(mod);
666
667         /* LDAP v3 Support */
668         if ( np_dn != NULL ) free( np_dn );
669         if ( np_ndn != NULL ) free( np_ndn );
670
671         if( np != NULL ) {
672                 /* free new parent and writer lock */
673                 bdb_entry_return( be, np );
674         }
675
676         if( p != NULL ) {
677                 /* free parent and writer lock */
678                 bdb_entry_return( be, p );
679         }
680
681         /* free entry */
682         if( e != NULL ) {
683                 bdb_entry_return( be, e );
684         }
685
686         if( ltid != NULL ) {
687                 txn_abort( ltid );
688                 op->o_private = NULL;
689         }
690
691         return rc;
692 }