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