]> git.sur5r.net Git - openldap/blob - servers/slapd/back-mdb/modrdn.c
Merge remote-tracking branch 'origin/mdb.RE/0.9'
[openldap] / servers / slapd / back-mdb / modrdn.c
1 /* modrdn.c - mdb backend modrdn routine */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2000-2016 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20 #include <ac/string.h>
21
22 #include "back-mdb.h"
23
24 int
25 mdb_modrdn( Operation   *op, SlapReply *rs )
26 {
27         struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
28         AttributeDescription *children = slap_schema.si_ad_children;
29         AttributeDescription *entry = slap_schema.si_ad_entry;
30         struct berval   p_dn, p_ndn;
31         struct berval   new_dn = {0, NULL}, new_ndn = {0, NULL};
32         Entry           *e = NULL;
33         Entry           *p = NULL;
34         /* LDAP v2 supporting correct attribute handling. */
35         char textbuf[SLAP_TEXT_BUFLEN];
36         size_t textlen = sizeof textbuf;
37         MDB_txn         *txn = NULL;
38         MDB_cursor      *mc;
39         struct mdb_op_info opinfo = {{{ 0 }}}, *moi = &opinfo;
40         Entry dummy = {0};
41
42         Entry           *np = NULL;                     /* newSuperior Entry */
43         struct berval   *np_dn = NULL;                  /* newSuperior dn */
44         struct berval   *np_ndn = NULL;                 /* newSuperior ndn */
45         struct berval   *new_parent_dn = NULL;  /* np_dn, p_dn, or NULL */
46
47         int             manageDSAit = get_manageDSAit( op );
48
49         ID nid, nsubs;
50         LDAPControl **preread_ctrl = NULL;
51         LDAPControl **postread_ctrl = NULL;
52         LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
53         int num_ctrls = 0;
54
55         int parent_is_glue = 0;
56         int parent_is_leaf = 0;
57
58         Debug( LDAP_DEBUG_TRACE, "==>" LDAP_XSTRING(mdb_modrdn) "(%s,%s,%s)\n",
59                 op->o_req_dn.bv_val,op->oq_modrdn.rs_newrdn.bv_val,
60                 op->oq_modrdn.rs_newSup ? op->oq_modrdn.rs_newSup->bv_val : "NULL" );
61
62 #ifdef LDAP_X_TXN
63         if( op->o_txnSpec && txn_preop( op, rs ))
64                 return rs->sr_err;
65 #endif
66
67         ctrls[num_ctrls] = NULL;
68
69         /* begin transaction */
70         rs->sr_err = mdb_opinfo_get( op, mdb, 0, &moi );
71         rs->sr_text = NULL;
72         if( rs->sr_err != 0 ) {
73                 Debug( LDAP_DEBUG_TRACE,
74                         LDAP_XSTRING(mdb_modrdn) ": txn_begin failed: "
75                         "%s (%d)\n", mdb_strerror(rs->sr_err), rs->sr_err, 0 );
76                 rs->sr_err = LDAP_OTHER;
77                 rs->sr_text = "internal error";
78                 goto return_results;
79         }
80         txn = moi->moi_txn;
81
82         slap_mods_opattrs( op, &op->orr_modlist, 1 );
83
84         if ( be_issuffix( op->o_bd, &op->o_req_ndn ) ) {
85 #ifdef MDB_MULTIPLE_SUFFIXES
86                 /* Allow renaming one suffix entry to another */
87                 p_ndn = slap_empty_bv;
88 #else
89                 /* There can only be one suffix entry */
90                 rs->sr_err = LDAP_NAMING_VIOLATION;
91                 rs->sr_text = "cannot rename suffix entry";
92                 goto return_results;
93 #endif
94         } else {
95                 dnParent( &op->o_req_ndn, &p_ndn );
96         }
97         np_ndn = &p_ndn;
98         /* Make sure parent entry exist and we can write its
99          * children.
100          */
101         rs->sr_err = mdb_cursor_open( txn, mdb->mi_dn2id, &mc );
102         if ( rs->sr_err != 0 ) {
103                 Debug(LDAP_DEBUG_TRACE,
104                         "<=- " LDAP_XSTRING(mdb_modrdn)
105                         ": cursor_open failed: %s (%d)\n",
106                         mdb_strerror(rs->sr_err), rs->sr_err, 0 );
107                 rs->sr_err = LDAP_OTHER;
108                 rs->sr_text = "DN cursor_open failed";
109                 goto return_results;
110         }
111         rs->sr_err = mdb_dn2entry( op, txn, mc, &p_ndn, &p, NULL, 0 );
112         switch( rs->sr_err ) {
113         case MDB_NOTFOUND:
114                 Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(mdb_modrdn)
115                         ": parent does not exist\n", 0, 0, 0);
116                 rs->sr_ref = referral_rewrite( default_referral, NULL,
117                                         &op->o_req_dn, LDAP_SCOPE_DEFAULT );
118                 rs->sr_err = LDAP_REFERRAL;
119
120                 send_ldap_result( op, rs );
121
122                 ber_bvarray_free( rs->sr_ref );
123                 goto done;
124         case 0:
125                 break;
126         case LDAP_BUSY:
127                 rs->sr_text = "ldap server busy";
128                 goto return_results;
129         default:
130                 rs->sr_err = LDAP_OTHER;
131                 rs->sr_text = "internal error";
132                 goto return_results;
133         }
134
135         /* check parent for "children" acl */
136         rs->sr_err = access_allowed( op, p,
137                 children, NULL,
138                 op->oq_modrdn.rs_newSup == NULL ?
139                         ACL_WRITE : ACL_WDEL,
140                 NULL );
141
142         if ( ! rs->sr_err ) {
143                 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
144                 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
145                         0, 0 );
146                 rs->sr_text = "no write access to parent's children";
147                 goto return_results;
148         }
149
150         Debug( LDAP_DEBUG_TRACE,
151                 LDAP_XSTRING(mdb_modrdn) ": wr to children "
152                 "of entry %s OK\n", p_ndn.bv_val, 0, 0 );
153
154         if ( p_ndn.bv_val == slap_empty_bv.bv_val ) {
155                 p_dn = slap_empty_bv;
156         } else {
157                 dnParent( &op->o_req_dn, &p_dn );
158         }
159
160         Debug( LDAP_DEBUG_TRACE,
161                 LDAP_XSTRING(mdb_modrdn) ": parent dn=%s\n",
162                 p_dn.bv_val, 0, 0 );
163
164         /* get entry */
165         rs->sr_err = mdb_dn2entry( op, txn, mc, &op->o_req_ndn, &e, &nsubs, 0 );
166         switch( rs->sr_err ) {
167         case MDB_NOTFOUND:
168                 e = p;
169                 p = NULL;
170         case 0:
171                 break;
172         case LDAP_BUSY:
173                 rs->sr_text = "ldap server busy";
174                 goto return_results;
175         default:
176                 rs->sr_err = LDAP_OTHER;
177                 rs->sr_text = "internal error";
178                 goto return_results;
179         }
180
181         /* FIXME: dn2entry() should return non-glue entry */
182         if (( rs->sr_err == MDB_NOTFOUND ) ||
183                 ( !manageDSAit && e && is_entry_glue( e )))
184         {
185                 if( e != NULL ) {
186                         rs->sr_matched = ch_strdup( e->e_dn );
187                         if ( is_entry_referral( e )) {
188                                 BerVarray ref = get_entry_referrals( op, e );
189                                 rs->sr_ref = referral_rewrite( ref, &e->e_name,
190                                         &op->o_req_dn, LDAP_SCOPE_DEFAULT );
191                                 ber_bvarray_free( ref );
192                         } else {
193                                 rs->sr_ref = NULL;
194                         }
195                         mdb_entry_return( op, e );
196                         e = NULL;
197
198                 } else {
199                         rs->sr_ref = referral_rewrite( default_referral, NULL,
200                                         &op->o_req_dn, LDAP_SCOPE_DEFAULT );
201                 }
202
203                 rs->sr_err = LDAP_REFERRAL;
204                 send_ldap_result( op, rs );
205
206                 ber_bvarray_free( rs->sr_ref );
207                 free( (char *)rs->sr_matched );
208                 rs->sr_ref = NULL;
209                 rs->sr_matched = NULL;
210
211                 goto done;
212         }
213
214         if ( get_assert( op ) &&
215                 ( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
216         {
217                 rs->sr_err = LDAP_ASSERTION_FAILED;
218                 goto return_results;
219         }
220
221         /* check write on old entry */
222         rs->sr_err = access_allowed( op, e, entry, NULL, ACL_WRITE, NULL );
223         if ( ! rs->sr_err ) {
224                 Debug( LDAP_DEBUG_TRACE, "no access to entry\n", 0,
225                         0, 0 );
226                 rs->sr_text = "no write access to old entry";
227                 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
228                 goto return_results;
229         }
230
231         if (!manageDSAit && is_entry_referral( e ) ) {
232                 /* entry is a referral, don't allow rename */
233                 rs->sr_ref = get_entry_referrals( op, e );
234
235                 Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(mdb_modrdn)
236                         ": entry %s is referral\n", e->e_dn, 0, 0 );
237
238                 rs->sr_err = LDAP_REFERRAL,
239                 rs->sr_matched = e->e_name.bv_val;
240                 send_ldap_result( op, rs );
241
242                 ber_bvarray_free( rs->sr_ref );
243                 rs->sr_ref = NULL;
244                 rs->sr_matched = NULL;
245                 goto done;
246         }
247
248         new_parent_dn = &p_dn;  /* New Parent unless newSuperior given */
249
250         if ( op->oq_modrdn.rs_newSup != NULL ) {
251                 Debug( LDAP_DEBUG_TRACE,
252                         LDAP_XSTRING(mdb_modrdn)
253                         ": new parent \"%s\" requested...\n",
254                         op->oq_modrdn.rs_newSup->bv_val, 0, 0 );
255
256                 /*  newSuperior == oldParent? */
257                 if( dn_match( &p_ndn, op->oq_modrdn.rs_nnewSup ) ) {
258                         Debug( LDAP_DEBUG_TRACE, "mdb_back_modrdn: "
259                                 "new parent \"%s\" same as the old parent \"%s\"\n",
260                                 op->oq_modrdn.rs_newSup->bv_val, p_dn.bv_val, 0 );
261                         op->oq_modrdn.rs_newSup = NULL; /* ignore newSuperior */
262                 }
263         }
264
265         /* There's a MDB_MULTIPLE_SUFFIXES case here that this code doesn't
266          * support. E.g., two suffixes dc=foo,dc=com and dc=bar,dc=net.
267          * We do not allow modDN
268          *   dc=foo,dc=com
269          *    newrdn dc=bar
270          *    newsup dc=net
271          * and we probably should. But since MULTIPLE_SUFFIXES is deprecated
272          * I'm ignoring this problem for now.
273          */
274         if ( op->oq_modrdn.rs_newSup != NULL ) {
275                 if ( op->oq_modrdn.rs_newSup->bv_len ) {
276                         np_dn = op->oq_modrdn.rs_newSup;
277                         np_ndn = op->oq_modrdn.rs_nnewSup;
278
279                         /* newSuperior == oldParent? - checked above */
280                         /* newSuperior == entry being moved?, if so ==> ERROR */
281                         if ( dnIsSuffix( np_ndn, &e->e_nname )) {
282                                 rs->sr_err = LDAP_NO_SUCH_OBJECT;
283                                 rs->sr_text = "new superior not found";
284                                 goto return_results;
285                         }
286                         /* Get Entry with dn=newSuperior. Does newSuperior exist? */
287                         rs->sr_err = mdb_dn2entry( op, txn, NULL, np_ndn, &np, NULL, 0 );
288
289                         switch( rs->sr_err ) {
290                         case 0:
291                                 break;
292                         case MDB_NOTFOUND:
293                                 Debug( LDAP_DEBUG_TRACE,
294                                         LDAP_XSTRING(mdb_modrdn)
295                                         ": newSup(ndn=%s) not here!\n",
296                                         np_ndn->bv_val, 0, 0);
297                                 rs->sr_text = "new superior not found";
298                                 rs->sr_err = LDAP_NO_SUCH_OBJECT;
299                                 goto return_results;
300                         case LDAP_BUSY:
301                                 rs->sr_text = "ldap server busy";
302                                 goto return_results;
303                         default:
304                                 rs->sr_err = LDAP_OTHER;
305                                 rs->sr_text = "internal error";
306                                 goto return_results;
307                         }
308
309                         /* check newSuperior for "children" acl */
310                         rs->sr_err = access_allowed( op, np, children,
311                                 NULL, ACL_WADD, NULL );
312
313                         if( ! rs->sr_err ) {
314                                 Debug( LDAP_DEBUG_TRACE,
315                                         LDAP_XSTRING(mdb_modrdn)
316                                         ": no wr to newSup children\n",
317                                         0, 0, 0 );
318                                 rs->sr_text = "no write access to new superior's children";
319                                 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
320                                 goto return_results;
321                         }
322
323                         Debug( LDAP_DEBUG_TRACE,
324                                 LDAP_XSTRING(mdb_modrdn)
325                                 ": wr to new parent OK np=%p, id=%ld\n",
326                                 (void *) np, (long) np->e_id, 0 );
327
328                         if ( is_entry_alias( np ) ) {
329                                 /* parent is an alias, don't allow add */
330                                 Debug( LDAP_DEBUG_TRACE,
331                                         LDAP_XSTRING(mdb_modrdn)
332                                         ": entry is alias\n",
333                                         0, 0, 0 );
334                                 rs->sr_text = "new superior is an alias";
335                                 rs->sr_err = LDAP_ALIAS_PROBLEM;
336                                 goto return_results;
337                         }
338
339                         if ( is_entry_referral( np ) ) {
340                                 /* parent is a referral, don't allow add */
341                                 Debug( LDAP_DEBUG_TRACE,
342                                         LDAP_XSTRING(mdb_modrdn)
343                                         ": entry is referral\n",
344                                         0, 0, 0 );
345                                 rs->sr_text = "new superior is a referral";
346                                 rs->sr_err = LDAP_OTHER;
347                                 goto return_results;
348                         }
349                         np_dn = &np->e_name;
350
351                 } else {
352                         np_dn = NULL;
353
354                         /* no parent, modrdn entry directly under root */
355                         if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv )
356                                 || be_isupdate( op ) ) {
357                                 np = (Entry *)&slap_entry_root;
358
359                                 /* check parent for "children" acl */
360                                 rs->sr_err = access_allowed( op, np,
361                                         children, NULL, ACL_WADD, NULL );
362
363                                 np = NULL;
364
365                                 if ( ! rs->sr_err ) {
366                                         rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
367                                         Debug( LDAP_DEBUG_TRACE,
368                                                 "no access to new superior\n",
369                                                 0, 0, 0 );
370                                         rs->sr_text =
371                                                 "no write access to new superior's children";
372                                         goto return_results;
373                                 }
374                         }
375                 }
376
377                 Debug( LDAP_DEBUG_TRACE,
378                         LDAP_XSTRING(mdb_modrdn)
379                         ": wr to new parent's children OK\n",
380                         0, 0, 0 );
381
382                 new_parent_dn = np_dn;
383         }
384
385         /* Build target dn and make sure target entry doesn't exist already. */
386         if (!new_dn.bv_val) {
387                 build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn, op->o_tmpmemctx );
388         }
389
390         if (!new_ndn.bv_val) {
391                 dnNormalize( 0, NULL, NULL, &new_dn, &new_ndn, op->o_tmpmemctx );
392         }
393
394         Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(mdb_modrdn) ": new ndn=%s\n",
395                 new_ndn.bv_val, 0, 0 );
396
397         /* Shortcut the search */
398         rs->sr_err = mdb_dn2id ( op, txn, NULL, &new_ndn, &nid, NULL, NULL, NULL );
399         switch( rs->sr_err ) {
400         case MDB_NOTFOUND:
401                 break;
402         case 0:
403                 /* Allow rename to same DN */
404                 if ( nid == e->e_id )
405                         break;
406                 rs->sr_err = LDAP_ALREADY_EXISTS;
407                 goto return_results;
408         default:
409                 rs->sr_err = LDAP_OTHER;
410                 rs->sr_text = "internal error";
411                 goto return_results;
412         }
413
414         assert( op->orr_modlist != NULL );
415
416         if( op->o_preread ) {
417                 if( preread_ctrl == NULL ) {
418                         preread_ctrl = &ctrls[num_ctrls++];
419                         ctrls[num_ctrls] = NULL;
420                 }
421                 if( slap_read_controls( op, rs, e,
422                         &slap_pre_read_bv, preread_ctrl ) )
423                 {
424                         Debug( LDAP_DEBUG_TRACE,
425                                 "<=- " LDAP_XSTRING(mdb_modrdn)
426                                 ": pre-read failed!\n", 0, 0, 0 );
427                         if ( op->o_preread & SLAP_CONTROL_CRITICAL ) {
428                                 /* FIXME: is it correct to abort
429                                  * operation if control fails? */
430                                 goto return_results;
431                         }
432                 }
433         }
434
435         /* delete old DN
436          * If moving to a new parent, must delete current subtree count,
437          * otherwise leave it unchanged since we'll be adding it right back.
438          */
439         rs->sr_err = mdb_dn2id_delete( op, mc, e->e_id, np ? nsubs : 0 );
440         if ( rs->sr_err != 0 ) {
441                 Debug(LDAP_DEBUG_TRACE,
442                         "<=- " LDAP_XSTRING(mdb_modrdn)
443                         ": dn2id del failed: %s (%d)\n",
444                         mdb_strerror(rs->sr_err), rs->sr_err, 0 );
445                 rs->sr_err = LDAP_OTHER;
446                 rs->sr_text = "DN index delete fail";
447                 goto return_results;
448         }
449
450         /* copy the entry, then override some fields */
451         dummy = *e;
452         dummy.e_name = new_dn;
453         dummy.e_nname = new_ndn;
454         dummy.e_attrs = NULL;
455
456         /* add new DN */
457         rs->sr_err = mdb_dn2id_add( op, mc, mc, np ? np->e_id : p->e_id,
458                 nsubs, np != NULL, &dummy );
459         if ( rs->sr_err != 0 ) {
460                 Debug(LDAP_DEBUG_TRACE,
461                         "<=- " LDAP_XSTRING(mdb_modrdn)
462                         ": dn2id add failed: %s (%d)\n",
463                         mdb_strerror(rs->sr_err), rs->sr_err, 0 );
464                 rs->sr_err = LDAP_OTHER;
465                 rs->sr_text = "DN index add failed";
466                 goto return_results;
467         }
468
469         dummy.e_attrs = e->e_attrs;
470
471         /* modify entry */
472         rs->sr_err = mdb_modify_internal( op, txn, op->orr_modlist, &dummy,
473                 &rs->sr_text, textbuf, textlen );
474         if( rs->sr_err != LDAP_SUCCESS ) {
475                 Debug(LDAP_DEBUG_TRACE,
476                         "<=- " LDAP_XSTRING(mdb_modrdn)
477                         ": modify failed: %s (%d)\n",
478                         mdb_strerror(rs->sr_err), rs->sr_err, 0 );
479                 if ( dummy.e_attrs == e->e_attrs ) dummy.e_attrs = NULL;
480                 goto return_results;
481         }
482
483         /* id2entry index */
484         rs->sr_err = mdb_id2entry_update( op, txn, NULL, &dummy );
485         if ( rs->sr_err != 0 ) {
486                 Debug(LDAP_DEBUG_TRACE,
487                         "<=- " LDAP_XSTRING(mdb_modrdn)
488                         ": id2entry failed: %s (%d)\n",
489                         mdb_strerror(rs->sr_err), rs->sr_err, 0 );
490                 if ( rs->sr_err == LDAP_ADMINLIMIT_EXCEEDED ) {
491                         rs->sr_text = "entry too big";
492                 } else {
493                         rs->sr_err = LDAP_OTHER;
494                         rs->sr_text = "entry update failed";
495                 }
496                 goto return_results;
497         }
498
499         if ( p_ndn.bv_len != 0 ) {
500                 if ((parent_is_glue = is_entry_glue(p))) {
501                         rs->sr_err = mdb_dn2id_children( op, txn, p );
502                         if ( rs->sr_err != MDB_NOTFOUND ) {
503                                 switch( rs->sr_err ) {
504                                 case 0:
505                                         break;
506                                 default:
507                                         Debug(LDAP_DEBUG_ARGS,
508                                                 "<=- " LDAP_XSTRING(mdb_modrdn)
509                                                 ": has_children failed: %s (%d)\n",
510                                                 mdb_strerror(rs->sr_err), rs->sr_err, 0 );
511                                         rs->sr_err = LDAP_OTHER;
512                                         rs->sr_text = "internal error";
513                                         goto return_results;
514                                 }
515                         } else {
516                                 parent_is_leaf = 1;
517                         }
518                 }
519                 mdb_entry_return( op, p );
520                 p = NULL;
521         }
522
523         if( op->o_postread ) {
524                 if( postread_ctrl == NULL ) {
525                         postread_ctrl = &ctrls[num_ctrls++];
526                         ctrls[num_ctrls] = NULL;
527                 }
528                 if( slap_read_controls( op, rs, &dummy,
529                         &slap_post_read_bv, postread_ctrl ) )
530                 {
531                         Debug( LDAP_DEBUG_TRACE,
532                                 "<=- " LDAP_XSTRING(mdb_modrdn)
533                                 ": post-read failed!\n", 0, 0, 0 );
534                         if ( op->o_postread & SLAP_CONTROL_CRITICAL ) {
535                                 /* FIXME: is it correct to abort
536                                  * operation if control fails? */
537                                 goto return_results;
538                         }
539                 }
540         }
541
542         if( moi == &opinfo ) {
543                 LDAP_SLIST_REMOVE( &op->o_extra, &opinfo.moi_oe, OpExtra, oe_next );
544                 opinfo.moi_oe.oe_key = NULL;
545                 if( op->o_noop ) {
546                         mdb_txn_abort( txn );
547                         rs->sr_err = LDAP_X_NO_OPERATION;
548                         txn = NULL;
549                         /* Only free attrs if they were dup'd.  */
550                         if ( dummy.e_attrs == e->e_attrs ) dummy.e_attrs = NULL;
551                         goto return_results;
552
553                 } else {
554                         if(( rs->sr_err=mdb_txn_commit( txn )) != 0 ) {
555                                 rs->sr_text = "txn_commit failed";
556                         } else {
557                                 rs->sr_err = LDAP_SUCCESS;
558                         }
559                         txn = NULL;
560                 }
561         }
562
563         if( rs->sr_err != LDAP_SUCCESS ) {
564                 Debug( LDAP_DEBUG_ANY,
565                         LDAP_XSTRING(mdb_modrdn) ": %s : %s (%d)\n",
566                         rs->sr_text, mdb_strerror(rs->sr_err), rs->sr_err );
567                 rs->sr_err = LDAP_OTHER;
568
569                 goto return_results;
570         }
571
572         Debug(LDAP_DEBUG_TRACE,
573                 LDAP_XSTRING(mdb_modrdn)
574                 ": rdn modified%s id=%08lx dn=\"%s\"\n",
575                 op->o_noop ? " (no-op)" : "",
576                 dummy.e_id, op->o_req_dn.bv_val );
577         rs->sr_text = NULL;
578         if( num_ctrls ) rs->sr_ctrls = ctrls;
579
580 return_results:
581         if ( dummy.e_attrs ) {
582                 attrs_free( dummy.e_attrs );
583         }
584         send_ldap_result( op, rs );
585
586 #if 0
587         if( rs->sr_err == LDAP_SUCCESS && mdb->bi_txn_cp_kbyte ) {
588                 TXN_CHECKPOINT( mdb->bi_dbenv,
589                         mdb->bi_txn_cp_kbyte, mdb->bi_txn_cp_min, 0 );
590         }
591 #endif
592
593         if ( rs->sr_err == LDAP_SUCCESS && parent_is_glue && parent_is_leaf ) {
594                 op->o_delete_glue_parent = 1;
595         }
596
597 done:
598         slap_graduate_commit_csn( op );
599
600         if( new_ndn.bv_val != NULL ) op->o_tmpfree( new_ndn.bv_val, op->o_tmpmemctx );
601         if( new_dn.bv_val != NULL ) op->o_tmpfree( new_dn.bv_val, op->o_tmpmemctx );
602
603         /* LDAP v3 Support */
604         if( np != NULL ) {
605                 /* free new parent */
606                 mdb_entry_return( op, np );
607         }
608
609         if( p != NULL ) {
610                 /* free parent */
611                 mdb_entry_return( op, p );
612         }
613
614         /* free entry */
615         if( e != NULL ) {
616                 mdb_entry_return( op, e );
617         }
618
619         if( moi == &opinfo ) {
620                 if( txn != NULL ) {
621                         mdb_txn_abort( txn );
622                 }
623                 if ( opinfo.moi_oe.oe_key ) {
624                         LDAP_SLIST_REMOVE( &op->o_extra, &opinfo.moi_oe, OpExtra, oe_next );
625                 }
626         } else {
627                 moi->moi_ref--;
628         }
629
630         if( preread_ctrl != NULL && (*preread_ctrl) != NULL ) {
631                 slap_sl_free( (*preread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
632                 slap_sl_free( *preread_ctrl, op->o_tmpmemctx );
633         }
634         if( postread_ctrl != NULL && (*postread_ctrl) != NULL ) {
635                 slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
636                 slap_sl_free( *postread_ctrl, op->o_tmpmemctx );
637         }
638         return rs->sr_err;
639 }