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