]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/modrdn.c
a356ba437b062c14777c3be0b9ad3f37d8c8d84e
[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         char            *p_dn = NULL, *p_ndn = NULL;
33         char            *new_dn = 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         char            *np_dn = NULL;                  /* newSuperior dn */
54         char            *np_ndn = NULL;                 /* newSuperior ndn */
55         char            *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->bv_val, &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                                         dn->bv_val, LDAP_SCOPE_DEFAULT )
132                                 : NULL;
133                         bdb_entry_return( be, matched );
134                         matched = NULL;
135
136                 } else {
137                         refs = referral_rewrite( default_referral,
138                                 NULL, dn->bv_val, LDAP_SCOPE_DEFAULT );
139                 }
140
141                 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
142                         matched_dn, NULL, refs, NULL );
143
144                 ber_bvecfree( refs );
145                 free( matched_dn );
146
147                 goto done;
148         }
149
150         if (!manageDSAit && is_entry_referral( e ) ) {
151                 /* parent is a referral, don't allow add */
152                 /* parent is an alias, don't allow add */
153                 struct berval **refs = get_entry_referrals( be,
154                         conn, op, e, dn->bv_val, LDAP_SCOPE_DEFAULT );
155
156                 Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: entry %s is referral\n",
157                         e->e_dn, 0, 0 );
158
159                 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
160                         e->e_dn, NULL, refs, NULL );
161
162                 ber_bvecfree( refs );
163                 goto done;
164         }
165
166         p_ndn = dn_parent( be, e->e_ndn );
167         np_ndn = p_ndn;
168         if ( p_ndn != NULL && p_ndn[ 0 ] != '\0' ) {
169                 /* Make sure parent entry exist and we can write its 
170                  * children.
171                  */
172
173                 rc = bdb_dn2entry( be, ltid, p_ndn, &p, NULL, 0 );
174
175                 switch( rc ) {
176                 case 0:
177                 case DB_NOTFOUND:
178                         break;
179                 case DB_LOCK_DEADLOCK:
180                 case DB_LOCK_NOTGRANTED:
181                         goto retry;
182                 default:
183                         rc = LDAP_OTHER;
184                         text = "internal error";
185                         goto return_results;
186                 }
187
188                 if( p == NULL) {
189                         Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: parent does not exist\n",
190                                 0, 0, 0);
191                         rc = LDAP_OTHER;
192                         goto return_results;
193                 }
194
195                 /* check parent for "children" acl */
196                 if ( ! access_allowed( be, conn, op, p,
197                         children, NULL, ACL_WRITE ) )
198                 {
199                         Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
200                                 0, 0 );
201                         send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
202                                 NULL, NULL, NULL, NULL );
203                         goto return_results;
204                 }
205
206                 Debug( LDAP_DEBUG_TRACE,
207                         "bdb_modrdn: wr to children of entry %s OK\n",
208                         p_ndn, 0, 0 );
209                 
210                 p_dn = dn_parent( be, e->e_dn );
211
212                 Debug( LDAP_DEBUG_TRACE,
213                         "bdb_modrdn: parent dn=%s\n",
214                         p_dn, 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 = "";
246
247                                 Debug( LDAP_DEBUG_TRACE,
248                                         "bdb_modrdn: parent dn=\"\"\n",
249                                         0, 0, 0 );
250
251                         } else {
252                                 Debug( LDAP_DEBUG_TRACE,
253                                         "bdb_modrdn: no parent, not root "
254                                         "& \"\" is not suffix\n",
255                                         0, 0, 0);
256                                 rc = LDAP_INSUFFICIENT_ACCESS;
257                                 goto return_results;
258                         }
259                 }
260         }
261
262         new_parent_dn = p_dn;   /* New Parent unless newSuperior given */
263
264         if ( newSuperior != NULL ) {
265                 Debug( LDAP_DEBUG_TRACE, 
266                         "bdb_modrdn: new parent \"%s\" requested...\n",
267                         newSuperior->bv_val, 0, 0 );
268
269                 if ( newSuperior->bv_len ) {
270                         np_dn = ch_strdup( newSuperior->bv_val );
271                         np_ndn = ch_strdup( np_dn );
272                         (void) dn_normalize( np_ndn );
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, np_ndn, &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, 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 = ch_strdup( "" );
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, e->e_dn, new_parent_dn, newrdn->bv_val ); 
389
390         new_ndn = ch_strdup( new_dn );
391         (void) dn_normalize( new_ndn );
392
393         Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: new ndn=%s\n",
394                 new_ndn, 0, 0 );
395
396         rc = bdb_dn2id ( be, ltid, new_ndn, &id );
397         switch( rc ) {
398         case DB_LOCK_DEADLOCK:
399         case DB_LOCK_NOTGRANTED:
400                 goto retry;
401         case DB_NOTFOUND:
402                 break;
403         case 0:
404                 rc = LDAP_ALREADY_EXISTS;
405                 goto return_results;
406         default:
407                 rc = LDAP_OTHER;
408                 text = "internal error";
409                 goto return_results;
410         }
411
412         Debug( LDAP_DEBUG_TRACE,
413                 "bdb_modrdn: new ndn=%s does not exist\n",
414                 new_ndn, 0, 0 );
415
416         /* Get attribute type and attribute value of our new rdn, we will
417          * need to add that to our new entry
418          */
419
420         if ( rdn_attrs( newrdn->bv_val, &new_rdn_types, &new_rdn_vals ) ) {
421                 Debug( LDAP_DEBUG_TRACE,
422                         "bdb_modrdn: can't figure out type(s)/values(s) "
423                         "of newrdn\n", 0, 0, 0 );
424                 rc = LDAP_OPERATIONS_ERROR;
425                 text = "unknown type(s) used in RDN";
426                 goto return_results;            
427         }
428
429         Debug( LDAP_DEBUG_TRACE,
430                 "bdb_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
431                 new_rdn_vals[0], new_rdn_types[0], 0 );
432
433         /* Retrieve the old rdn from the entry's dn */
434         if ( ( old_rdn = dn_rdn( be, dn->bv_val ) ) == NULL ) {
435                 Debug( LDAP_DEBUG_TRACE,
436                         "bdb_modrdn: can't figure out old_rdn from dn\n",
437                         0, 0, 0 );
438                 rc = LDAP_OTHER;
439                 text = "could not parse old DN";
440                 goto return_results;            
441         }
442
443         if ( rdn_attrs( old_rdn, &old_rdn_types, &old_rdn_vals ) ) {
444                 Debug( LDAP_DEBUG_TRACE,
445                         "bdb_back_modrdn: can't figure out the old_rdn "
446                         "type(s)/value(s)\n", 0, 0, 0 );
447                 rc = LDAP_OTHER;
448                 text = "cannot parse RDN from old DN";
449                 goto return_results;            
450         }
451         
452         if ( newSuperior == NULL
453                 && charray_strcasecmp( ( const char ** )old_rdn_types, 
454                                 ( const char ** )new_rdn_types ) != 0 ) {
455                 /* Not a big deal but we may say something */
456                 Debug( LDAP_DEBUG_TRACE,
457                         "bdb_modrdn: old_rdn_type(s)=%s, new_rdn_type(s)=%s "
458                         "do not match\n", 
459                         old_rdn_types[ 0 ], new_rdn_types[ 0 ], 0 );
460         }               
461
462         /* Add new attribute values to the entry */
463         for ( a_cnt = 0; new_rdn_types[ a_cnt ]; a_cnt++ ) {
464                 int                     rc;
465                 AttributeDescription    *desc = NULL;
466                 Modifications           *mod_tmp;
467                 struct berval           val;
468
469                 rc = slap_str2ad( new_rdn_types[ a_cnt ], &desc, &text );
470
471                 if ( rc != LDAP_SUCCESS ) {
472                         Debug( LDAP_DEBUG_TRACE,
473                                 "bdb_modrdn: %s: %s (new)\n",
474                                 text, new_rdn_types[ a_cnt ], 0 );
475                         goto return_results;            
476                 }
477
478                 /* ACL check of newly added attrs */
479                 val.bv_val = new_rdn_vals[ a_cnt ];
480                 val.bv_len = strlen( val.bv_val );
481                 if ( !access_allowed( be, conn, op, e, 
482                                 desc, &val, ACL_WRITE ) ) {
483                         Debug( LDAP_DEBUG_TRACE,
484                                 "bdb_modrdn: access to attr \"%s\" "
485                                 "(new) not allowed\n", 
486                                 new_rdn_types[ a_cnt ], 0, 0 );
487                         rc = LDAP_INSUFFICIENT_ACCESS;
488                         goto return_results;
489                 }
490
491                 /* Apply modification */
492                 mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications ) );
493                 mod_tmp->sml_desc = desc;
494                 mod_tmp->sml_bvalues = ( struct berval ** )ch_malloc( 2*sizeof( struct berval * ) );
495                 mod_tmp->sml_bvalues[ 0 ] = ber_bvstrdup( new_rdn_vals[ a_cnt ] );
496                 mod_tmp->sml_bvalues[ 1 ] = NULL;
497                 mod_tmp->sml_op = SLAP_MOD_SOFTADD;
498                 mod_tmp->sml_next = mod;
499                 mod = mod_tmp;
500         }
501
502         /* Remove old rdn value if required */
503         if ( deleteoldrdn ) {
504                 /* Get value of old rdn */
505                 if ( old_rdn_vals == NULL) {
506                         Debug( LDAP_DEBUG_TRACE,
507                                 "bdb_modrdn: can't figure out old RDN value(s) "
508                                 "from old RDN\n", 0, 0, 0 );
509                         rc = LDAP_OTHER;
510                         text = "could not parse value(s) from old RDN";
511                         goto return_results;            
512                 }
513
514                 for ( d_cnt = 0; old_rdn_types[ d_cnt ]; d_cnt++ ) {
515                         int                     rc;
516                         AttributeDescription    *desc = NULL;
517                         Modifications           *mod_tmp;
518                         struct berval           val;
519
520                         rc = slap_str2ad( old_rdn_types[ d_cnt ],
521                                         &desc, &text );
522
523                         if ( rc != LDAP_SUCCESS ) {
524                                 Debug( LDAP_DEBUG_TRACE,
525                                         "bdb_modrdn: %s: %s (old)\n",
526                                         text, old_rdn_types[ d_cnt ], 0 );
527                                 goto return_results;            
528                         }
529
530                         /* ACL check of newly added attrs */
531                         val.bv_val = new_rdn_vals[ d_cnt ];
532                         val.bv_len = strlen( val.bv_val );
533                         if ( !access_allowed( be, conn, op, e, 
534                                         desc, &val, ACL_WRITE ) ) {
535                                 Debug( LDAP_DEBUG_TRACE,
536                                         "bdb_modrdn: access to attr \"%s\" "
537                                         "(old) not allowed\n", 
538                                         old_rdn_types[ d_cnt ], 0, 0 );
539                                 rc = LDAP_INSUFFICIENT_ACCESS;
540                                 goto return_results;
541                         }
542
543                         /* Apply modification */
544                         mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications ) );
545                         mod_tmp->sml_desc = desc;
546                         mod_tmp->sml_bvalues = ( struct berval ** )ch_malloc( 2*sizeof( struct berval * ) );
547                         mod_tmp->sml_bvalues[ 0 ] = ber_bvstrdup( old_rdn_vals[ d_cnt ] );
548                         mod_tmp->sml_bvalues[ 1 ] = NULL;
549                         mod_tmp->sml_op = LDAP_MOD_DELETE;
550                         mod_tmp->sml_next = mod;
551                         mod = mod_tmp;
552                 }
553         }
554         
555         /* delete old one */
556         rc = bdb_dn2id_delete( be, ltid, p_ndn, e );
557         if ( rc != 0 ) {
558                 switch( rc ) {
559                 case DB_LOCK_DEADLOCK:
560                 case DB_LOCK_NOTGRANTED:
561                         goto retry;
562                 }
563                 rc = LDAP_OTHER;
564                 text = "DN index delete fail";
565                 goto return_results;
566         }
567
568         /* Binary format uses a single contiguous block, cannot
569          * free individual fields. Leave new_dn/new_ndn set so
570          * they can be individually freed later.
571          */
572         e->e_dn = new_dn;
573         e->e_name.bv_len = strlen( new_dn );
574         e->e_ndn = new_ndn;
575         e->e_nname.bv_len = strlen( new_ndn );
576
577         /* add new one */
578         rc = bdb_dn2id_add( be, ltid, np_ndn, e );
579         if ( rc != 0 ) {
580                 switch( rc ) {
581                 case DB_LOCK_DEADLOCK:
582                 case DB_LOCK_NOTGRANTED:
583                         goto retry;
584                 }
585                 rc = LDAP_OTHER;
586                 text = "DN index add failed";
587                 goto return_results;
588         }
589
590         /* modify entry */
591         rc = bdb_modify_internal( be, conn, op, ltid, &mod[0], e,
592                 &text, textbuf, textlen );
593
594         if( rc != LDAP_SUCCESS ) {
595                 switch( rc ) {
596                 case DB_LOCK_DEADLOCK:
597                 case DB_LOCK_NOTGRANTED:
598                         goto retry;
599                 }
600                 goto return_results;
601         }
602         
603         /* id2entry index */
604         rc = bdb_id2entry_update( be, ltid, e );
605         if ( rc != 0 ) {
606                 switch( rc ) {
607                 case DB_LOCK_DEADLOCK:
608                 case DB_LOCK_NOTGRANTED:
609                         goto retry;
610                 }
611                 rc = LDAP_OTHER;
612                 text = "entry update failed";
613                 goto return_results;
614         }
615
616         if( bdb->bi_txn ) {
617                 rc = txn_commit( ltid, 0 );
618         }
619         ltid = NULL;
620         op->o_private = NULL;
621
622         if( rc != 0 ) {
623                 Debug( LDAP_DEBUG_TRACE,
624                         "bdb_modrdn: txn_commit failed: %s (%d)\n",
625                         db_strerror(rc), rc, 0 );
626                 rc = LDAP_OTHER;
627                 text = "commit failed";
628         } else {
629                 Debug( LDAP_DEBUG_TRACE,
630                         "bdb_modrdn: added id=%08lx dn=\"%s\"\n",
631                         e->e_id, e->e_dn, 0 );
632                 rc = LDAP_SUCCESS;
633                 text = NULL;
634         }
635
636 return_results:
637         send_ldap_result( conn, op, rc,
638                 NULL, text, NULL, NULL );
639
640         if( rc == LDAP_SUCCESS && bdb->bi_txn_cp ) {
641                 ldap_pvt_thread_yield();
642                 TXN_CHECKPOINT( bdb->bi_dbenv,
643                         bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
644         }
645
646 done:
647         if( new_dn != NULL ) free( new_dn );
648         if( new_ndn != NULL ) free( new_ndn );
649
650         if( np_ndn == p_ndn ) np_ndn = NULL;
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_dn != NULL ) free( np_dn );
662         if ( np_ndn != NULL ) free( np_ndn );
663
664         if( np != NULL ) {
665                 /* free new parent and writer lock */
666                 bdb_entry_return( be, np );
667         }
668
669         if( p != NULL ) {
670                 /* free parent and writer lock */
671                 bdb_entry_return( be, p );
672         }
673
674         /* free entry */
675         if( e != NULL ) {
676                 bdb_entry_return( be, e );
677         }
678
679         if( ltid != NULL ) {
680                 txn_abort( ltid );
681                 op->o_private = NULL;
682         }
683
684         return rc;
685 }