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