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