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