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