]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/modrdn.c
More struct berval fixes
[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 = 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         dnNormalize( NULL, &new_dn, &new_ndn );
397
398         Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: new ndn=%s\n",
399                 new_ndn, 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, 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
425         if ( rdn_attrs( newrdn->bv_val, &new_rdn_types, &new_rdn_vals ) ) {
426                 Debug( LDAP_DEBUG_TRACE,
427                         "bdb_modrdn: can't figure out type(s)/values(s) "
428                         "of newrdn\n", 0, 0, 0 );
429                 rc = LDAP_OPERATIONS_ERROR;
430                 text = "unknown type(s) used in RDN";
431                 goto return_results;            
432         }
433
434         Debug( LDAP_DEBUG_TRACE,
435                 "bdb_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
436                 new_rdn_vals[0], new_rdn_types[0], 0 );
437
438         /* Retrieve the old rdn from the entry's dn */
439         if ( ( old_rdn = dn_rdn( be, dn->bv_val ) ) == NULL ) {
440                 Debug( LDAP_DEBUG_TRACE,
441                         "bdb_modrdn: can't figure out old_rdn from dn\n",
442                         0, 0, 0 );
443                 rc = LDAP_OTHER;
444                 text = "could not parse old DN";
445                 goto return_results;            
446         }
447
448         if ( rdn_attrs( old_rdn, &old_rdn_types, &old_rdn_vals ) ) {
449                 Debug( LDAP_DEBUG_TRACE,
450                         "bdb_back_modrdn: can't figure out the old_rdn "
451                         "type(s)/value(s)\n", 0, 0, 0 );
452                 rc = LDAP_OTHER;
453                 text = "cannot parse RDN from old DN";
454                 goto return_results;            
455         }
456         
457         if ( newSuperior == NULL
458                 && charray_strcasecmp( ( const char ** )old_rdn_types, 
459                                 ( const char ** )new_rdn_types ) != 0 ) {
460                 /* Not a big deal but we may say something */
461                 Debug( LDAP_DEBUG_TRACE,
462                         "bdb_modrdn: old_rdn_type(s)=%s, new_rdn_type(s)=%s "
463                         "do not match\n", 
464                         old_rdn_types[ 0 ], new_rdn_types[ 0 ], 0 );
465         }               
466
467         /* Add new attribute values to the entry */
468         for ( a_cnt = 0; new_rdn_types[ a_cnt ]; a_cnt++ ) {
469                 int                     rc;
470                 AttributeDescription    *desc = NULL;
471                 Modifications           *mod_tmp;
472                 struct berval           val;
473
474                 rc = slap_str2ad( new_rdn_types[ a_cnt ], &desc, &text );
475
476                 if ( rc != LDAP_SUCCESS ) {
477                         Debug( LDAP_DEBUG_TRACE,
478                                 "bdb_modrdn: %s: %s (new)\n",
479                                 text, new_rdn_types[ a_cnt ], 0 );
480                         goto return_results;            
481                 }
482
483                 /* ACL check of newly added attrs */
484                 val.bv_val = new_rdn_vals[ a_cnt ];
485                 val.bv_len = strlen( val.bv_val );
486                 if ( !access_allowed( be, conn, op, e, 
487                                 desc, &val, ACL_WRITE ) ) {
488                         Debug( LDAP_DEBUG_TRACE,
489                                 "bdb_modrdn: access to attr \"%s\" "
490                                 "(new) not allowed\n", 
491                                 new_rdn_types[ a_cnt ], 0, 0 );
492                         rc = LDAP_INSUFFICIENT_ACCESS;
493                         goto return_results;
494                 }
495
496                 /* Apply modification */
497                 mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications ) );
498                 mod_tmp->sml_desc = desc;
499                 mod_tmp->sml_bvalues = ( struct berval ** )ch_malloc( 2*sizeof( struct berval * ) );
500                 mod_tmp->sml_bvalues[ 0 ] = ber_bvstrdup( new_rdn_vals[ a_cnt ] );
501                 mod_tmp->sml_bvalues[ 1 ] = NULL;
502                 mod_tmp->sml_op = SLAP_MOD_SOFTADD;
503                 mod_tmp->sml_next = mod;
504                 mod = mod_tmp;
505         }
506
507         /* Remove old rdn value if required */
508         if ( deleteoldrdn ) {
509                 /* Get value of old rdn */
510                 if ( old_rdn_vals == NULL) {
511                         Debug( LDAP_DEBUG_TRACE,
512                                 "bdb_modrdn: can't figure out old RDN value(s) "
513                                 "from old RDN\n", 0, 0, 0 );
514                         rc = LDAP_OTHER;
515                         text = "could not parse value(s) from old RDN";
516                         goto return_results;            
517                 }
518
519                 for ( d_cnt = 0; old_rdn_types[ d_cnt ]; d_cnt++ ) {
520                         int                     rc;
521                         AttributeDescription    *desc = NULL;
522                         Modifications           *mod_tmp;
523                         struct berval           val;
524
525                         rc = slap_str2ad( old_rdn_types[ d_cnt ],
526                                         &desc, &text );
527
528                         if ( rc != LDAP_SUCCESS ) {
529                                 Debug( LDAP_DEBUG_TRACE,
530                                         "bdb_modrdn: %s: %s (old)\n",
531                                         text, old_rdn_types[ d_cnt ], 0 );
532                                 goto return_results;            
533                         }
534
535                         /* ACL check of newly added attrs */
536                         val.bv_val = new_rdn_vals[ d_cnt ];
537                         val.bv_len = strlen( val.bv_val );
538                         if ( !access_allowed( be, conn, op, e, 
539                                         desc, &val, ACL_WRITE ) ) {
540                                 Debug( LDAP_DEBUG_TRACE,
541                                         "bdb_modrdn: access to attr \"%s\" "
542                                         "(old) not allowed\n", 
543                                         old_rdn_types[ d_cnt ], 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                         mod_tmp->sml_desc = desc;
551                         mod_tmp->sml_bvalues = ( struct berval ** )ch_malloc( 2*sizeof( struct berval * ) );
552                         mod_tmp->sml_bvalues[ 0 ] = ber_bvstrdup( old_rdn_vals[ d_cnt ] );
553                         mod_tmp->sml_bvalues[ 1 ] = 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 != NULL ) ber_bvfree( new_ndn );
652
653         /* LDAP v2 supporting correct attribute handling. */
654         if( new_rdn_types != NULL ) charray_free(new_rdn_types);
655         if( new_rdn_vals != NULL ) charray_free(new_rdn_vals);
656         if( old_rdn != NULL ) free(old_rdn);
657         if( old_rdn_types != NULL ) charray_free(old_rdn_types);
658         if( old_rdn_vals != NULL ) charray_free(old_rdn_vals);
659         if( mod != NULL ) slap_mods_free(mod);
660
661         /* LDAP v3 Support */
662         if( np != NULL ) {
663                 /* free new parent and writer lock */
664                 bdb_entry_return( be, np );
665         }
666
667         if( p != NULL ) {
668                 /* free parent and writer lock */
669                 bdb_entry_return( be, p );
670         }
671
672         /* free entry */
673         if( e != NULL ) {
674                 bdb_entry_return( be, e );
675         }
676
677         if( ltid != NULL ) {
678                 txn_abort( ltid );
679                 op->o_private = NULL;
680         }
681
682         return rc;
683 }