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