]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/modrdn.c
Update groups to use struct berval DNs.
[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, &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 = dn_parent( be, e->e_ndn );
166         np_ndn = p_ndn;
167         if ( p_ndn != NULL && p_ndn[ 0 ] != '\0' ) {
168                 /* Make sure parent entry exist and we can write its 
169                  * children.
170                  */
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, 0, 0 );
208                 
209                 p_dn = dn_parent( be, e->e_dn );
210
211                 Debug( LDAP_DEBUG_TRACE,
212                         "bdb_modrdn: parent dn=%s\n",
213                         p_dn, 0, 0 );
214
215         } else {
216                 /* no parent, modrdn entry directly under root */
217                 isroot = be_isroot( be, &op->o_ndn );
218                 if ( ! isroot ) {
219                         if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
220
221                                 p = (Entry *)&slap_entry_root;
222
223                                 /* check parent for "children" acl */
224                                 rc = access_allowed( be, conn, op, p,
225                                         children, NULL, ACL_WRITE );
226
227                                 p = NULL;
228
229                                 if ( ! rc )
230                                 {
231                                         Debug( LDAP_DEBUG_TRACE, 
232                                                 "no access to parent\n", 
233                                                 0, 0, 0 );
234                                         send_ldap_result( conn, op, 
235                                                 LDAP_INSUFFICIENT_ACCESS,
236                                                 NULL, NULL, NULL, NULL );
237                                         goto return_results;
238                                 }
239
240                                 Debug( LDAP_DEBUG_TRACE,
241                                         "bdb_modrdn: wr to children of entry \"\" OK\n",
242                                         0, 0, 0 );
243                 
244                                 p_dn = "";
245
246                                 Debug( LDAP_DEBUG_TRACE,
247                                         "bdb_modrdn: parent dn=\"\"\n",
248                                         0, 0, 0 );
249
250                         } else {
251                                 Debug( LDAP_DEBUG_TRACE,
252                                         "bdb_modrdn: no parent, not root "
253                                         "& \"\" is not suffix\n",
254                                         0, 0, 0);
255                                 rc = LDAP_INSUFFICIENT_ACCESS;
256                                 goto return_results;
257                         }
258                 }
259         }
260
261         new_parent_dn = p_dn;   /* New Parent unless newSuperior given */
262
263         if ( newSuperior != NULL ) {
264                 Debug( LDAP_DEBUG_TRACE, 
265                         "bdb_modrdn: new parent \"%s\" requested...\n",
266                         newSuperior->bv_val, 0, 0 );
267
268                 if ( newSuperior->bv_len ) {
269                         np_dn = ch_strdup( newSuperior->bv_val );
270                         np_ndn = ch_strdup( np_dn );
271                         (void) dn_normalize( np_ndn );
272
273                         /* newSuperior == oldParent?, if so ==> ERROR */
274                         /* newSuperior == entry being moved?, if so ==> ERROR */
275                         /* Get Entry with dn=newSuperior. Does newSuperior exist? */
276
277                         rc = bdb_dn2entry( be, ltid, np_ndn, &np, NULL, 0 );
278
279                         switch( rc ) {
280                         case 0:
281                         case DB_NOTFOUND:
282                                 break;
283                         case DB_LOCK_DEADLOCK:
284                         case DB_LOCK_NOTGRANTED:
285                                 goto retry;
286                         default:
287                                 rc = LDAP_OTHER;
288                                 text = "internal error";
289                                 goto return_results;
290                         }
291
292                         if( np == NULL) {
293                                 Debug( LDAP_DEBUG_TRACE,
294                                         "bdb_modrdn: newSup(ndn=%s) not here!\n",
295                                         np_ndn, 0, 0);
296                                 rc = LDAP_OTHER;
297                                 goto return_results;
298                         }
299
300                         Debug( LDAP_DEBUG_TRACE,
301                                 "bdb_modrdn: wr to new parent OK np=%p, id=%ld\n",
302                                 np, (long) np->e_id, 0 );
303
304                         /* check newSuperior for "children" acl */
305                         if ( !access_allowed( be, conn, op, np, children, NULL, ACL_WRITE ) ) {
306                                 Debug( LDAP_DEBUG_TRACE,
307                                         "bdb_modrdn: no wr to newSup children\n",
308                                         0, 0, 0 );
309                                 rc = LDAP_INSUFFICIENT_ACCESS;
310                                 goto return_results;
311                         }
312
313                         if ( is_entry_alias( np ) ) {
314                                 /* parent is an alias, don't allow add */
315                                 Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: entry is alias\n",
316                                         0, 0, 0 );
317
318                                 rc = LDAP_ALIAS_PROBLEM;
319                                 goto return_results;
320                         }
321
322                         if ( is_entry_referral( np ) ) {
323                                 /* parent is a referral, don't allow add */
324                                 Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: entry is referral\n",
325                                         0, 0, 0 );
326
327                                 rc = LDAP_OPERATIONS_ERROR;
328                                 goto return_results;
329                         }
330
331                 } else {
332                         if ( isroot == -1 ) {
333                                 isroot = be_isroot( be, &op->o_ndn );
334                         }
335                         
336                         np_dn = ch_strdup( "" );
337
338                         /* no parent, modrdn entry directly under root */
339                         if ( ! isroot ) {
340                                 if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
341                                         np = (Entry *)&slap_entry_root;
342
343                                         /* check parent for "children" acl */
344                                         rc = access_allowed( be, conn, op, np,
345                                                 children, NULL, ACL_WRITE );
346
347                                         np = NULL;
348
349                                         if ( ! rc )
350                                         {
351                                                 Debug( LDAP_DEBUG_TRACE, 
352                                                         "no access to new superior\n", 
353                                                         0, 0, 0 );
354                                                 send_ldap_result( conn, op, 
355                                                         LDAP_INSUFFICIENT_ACCESS,
356                                                         NULL, NULL, NULL, NULL );
357                                                 goto return_results;
358                                         }
359
360                                         Debug( LDAP_DEBUG_TRACE,
361                                                 "bdb_modrdn: wr to children of entry \"\" OK\n",
362                                                 0, 0, 0 );
363                 
364                                 } else {
365                                         Debug( LDAP_DEBUG_TRACE,
366                                                 "bdb_modrdn: new superior=\"\", not root "
367                                                 "& \"\" is not suffix\n",
368                                                 0, 0, 0);
369                                         rc = LDAP_INSUFFICIENT_ACCESS;
370                                         goto return_results;
371                                 }
372                         }
373
374                         Debug( LDAP_DEBUG_TRACE,
375                                 "bdb_modrdn: new superior=\"\"\n",
376                                 0, 0, 0 );
377                 }
378
379                 Debug( LDAP_DEBUG_TRACE,
380                         "bdb_modrdn: wr to new parent's children OK\n",
381                         0, 0, 0 );
382
383                 new_parent_dn = np_dn;
384         }
385         
386         /* Build target dn and make sure target entry doesn't exist already. */
387         build_new_dn( &new_dn, e->e_dn, new_parent_dn, newrdn->bv_val ); 
388
389         new_ndn = ch_strdup( new_dn );
390         (void) dn_normalize( 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, 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_dn = new_dn;
572         e->e_name.bv_len = strlen( new_dn );
573         e->e_ndn = new_ndn;
574         e->e_nname.bv_len = strlen( new_ndn );
575
576         /* add new one */
577         rc = bdb_dn2id_add( be, ltid, np_ndn, e );
578         if ( rc != 0 ) {
579                 switch( rc ) {
580                 case DB_LOCK_DEADLOCK:
581                 case DB_LOCK_NOTGRANTED:
582                         goto retry;
583                 }
584                 rc = LDAP_OTHER;
585                 text = "DN index add failed";
586                 goto return_results;
587         }
588
589         /* modify entry */
590         rc = bdb_modify_internal( be, conn, op, ltid, &mod[0], e,
591                 &text, textbuf, textlen );
592
593         if( rc != LDAP_SUCCESS ) {
594                 switch( rc ) {
595                 case DB_LOCK_DEADLOCK:
596                 case DB_LOCK_NOTGRANTED:
597                         goto retry;
598                 }
599                 goto return_results;
600         }
601         
602         /* id2entry index */
603         rc = bdb_id2entry_update( be, ltid, e );
604         if ( rc != 0 ) {
605                 switch( rc ) {
606                 case DB_LOCK_DEADLOCK:
607                 case DB_LOCK_NOTGRANTED:
608                         goto retry;
609                 }
610                 rc = LDAP_OTHER;
611                 text = "entry update failed";
612                 goto return_results;
613         }
614
615         if( bdb->bi_txn ) {
616                 rc = txn_commit( ltid, 0 );
617         }
618         ltid = NULL;
619         op->o_private = NULL;
620
621         if( rc != 0 ) {
622                 Debug( LDAP_DEBUG_TRACE,
623                         "bdb_modrdn: txn_commit failed: %s (%d)\n",
624                         db_strerror(rc), rc, 0 );
625                 rc = LDAP_OTHER;
626                 text = "commit failed";
627         } else {
628                 Debug( LDAP_DEBUG_TRACE,
629                         "bdb_modrdn: added id=%08lx dn=\"%s\"\n",
630                         e->e_id, e->e_dn, 0 );
631                 rc = LDAP_SUCCESS;
632                 text = NULL;
633         }
634
635 return_results:
636         send_ldap_result( conn, op, rc,
637                 NULL, text, NULL, NULL );
638
639         if( rc == LDAP_SUCCESS && bdb->bi_txn_cp ) {
640                 ldap_pvt_thread_yield();
641                 TXN_CHECKPOINT( bdb->bi_dbenv,
642                         bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
643         }
644
645 done:
646         if( new_dn != NULL ) free( new_dn );
647         if( new_ndn != NULL ) free( new_ndn );
648
649         if( np_ndn == p_ndn ) np_ndn = NULL;
650
651         /* LDAP v2 supporting correct attribute handling. */
652         if( new_rdn_types != NULL ) charray_free(new_rdn_types);
653         if( new_rdn_vals != NULL ) charray_free(new_rdn_vals);
654         if( old_rdn != NULL ) free(old_rdn);
655         if( old_rdn_types != NULL ) charray_free(old_rdn_types);
656         if( old_rdn_vals != NULL ) charray_free(old_rdn_vals);
657         if( mod != NULL ) slap_mods_free(mod);
658
659         /* LDAP v3 Support */
660         if ( np_dn != NULL ) free( np_dn );
661         if ( np_ndn != NULL ) free( np_ndn );
662
663         if( np != NULL ) {
664                 /* free new parent and writer lock */
665                 bdb_entry_return( be, np );
666         }
667
668         if( p != NULL ) {
669                 /* free parent and writer lock */
670                 bdb_entry_return( be, p );
671         }
672
673         /* free entry */
674         if( e != NULL ) {
675                 bdb_entry_return( be, e );
676         }
677
678         if( ltid != NULL ) {
679                 txn_abort( ltid );
680                 op->o_private = NULL;
681         }
682
683         return rc;
684 }