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