]> git.sur5r.net Git - openldap/blob - servers/slapd/back-mdb/modify.c
More porting
[openldap] / servers / slapd / back-mdb / modify.c
1 /* modify.c - mdb backend modify routine */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2000-2011 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 #include <ac/time.h>
22
23 #include "back-mdb.h"
24
25 static struct berval scbva[] = {
26         BER_BVC("glue"),
27         BER_BVNULL
28 };
29
30 static void
31 mdb_modify_idxflags(
32         Operation *op,
33         AttributeDescription *desc,
34         int got_delete,
35         Attribute *newattrs,
36         Attribute *oldattrs )
37 {
38         struct berval   ix_at;
39         AttrInfo        *ai;
40
41         /* check if modified attribute was indexed
42          * but not in case of NOOP... */
43         ai = mdb_index_mask( op->o_bd, desc, &ix_at );
44         if ( ai ) {
45                 if ( got_delete ) {
46                         Attribute       *ap;
47                         struct berval   ix2;
48
49                         ap = attr_find( oldattrs, desc );
50                         if ( ap ) ap->a_flags |= SLAP_ATTR_IXDEL;
51
52                         /* Find all other attrs that index to same slot */
53                         for ( ap = newattrs; ap; ap = ap->a_next ) {
54                                 ai = mdb_index_mask( op->o_bd, ap->a_desc, &ix2 );
55                                 if ( ai && ix2.bv_val == ix_at.bv_val )
56                                         ap->a_flags |= SLAP_ATTR_IXADD;
57                         }
58
59                 } else {
60                         Attribute       *ap;
61
62                         ap = attr_find( newattrs, desc );
63                         if ( ap ) ap->a_flags |= SLAP_ATTR_IXADD;
64                 }
65         }
66 }
67
68 int mdb_modify_internal(
69         Operation *op,
70         MDB_txn *tid,
71         Modifications *modlist,
72         Entry *e,
73         const char **text,
74         char *textbuf,
75         size_t textlen )
76 {
77         int rc, err;
78         Modification    *mod;
79         Modifications   *ml;
80         Attribute       *save_attrs;
81         Attribute       *ap;
82         int                     glue_attr_delete = 0;
83         int                     got_delete;
84
85         Debug( LDAP_DEBUG_TRACE, "mdb_modify_internal: 0x%08lx: %s\n",
86                 e->e_id, e->e_dn, 0);
87
88         if ( !acl_check_modlist( op, e, modlist )) {
89                 return LDAP_INSUFFICIENT_ACCESS;
90         }
91
92         /* save_attrs will be disposed of by mdb_cache_modify */
93         save_attrs = e->e_attrs;
94         e->e_attrs = attrs_dup( e->e_attrs );
95
96         for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
97                 int match;
98                 mod = &ml->sml_mod;
99                 switch( mod->sm_op ) {
100                 case LDAP_MOD_ADD:
101                 case LDAP_MOD_REPLACE:
102                         if ( mod->sm_desc == slap_schema.si_ad_structuralObjectClass ) {
103                                 value_match( &match, slap_schema.si_ad_structuralObjectClass,
104                                         slap_schema.si_ad_structuralObjectClass->
105                                                 ad_type->sat_equality,
106                                         SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
107                                         &mod->sm_values[0], &scbva[0], text );
108                                 if ( !match ) glue_attr_delete = 1;
109                         }
110                 }
111                 if ( glue_attr_delete )
112                         break;
113         }
114
115         if ( glue_attr_delete ) {
116                 Attribute       **app = &e->e_attrs;
117                 while ( *app != NULL ) {
118                         if ( !is_at_operational( (*app)->a_desc->ad_type )) {
119                                 Attribute *save = *app;
120                                 *app = (*app)->a_next;
121                                 attr_free( save );
122                                 continue;
123                         }
124                         app = &(*app)->a_next;
125                 }
126         }
127
128         for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
129                 mod = &ml->sml_mod;
130                 got_delete = 0;
131
132                 switch ( mod->sm_op ) {
133                 case LDAP_MOD_ADD:
134                         Debug(LDAP_DEBUG_ARGS,
135                                 "mdb_modify_internal: add %s\n",
136                                 mod->sm_desc->ad_cname.bv_val, 0, 0);
137                         err = modify_add_values( e, mod, get_permissiveModify(op),
138                                 text, textbuf, textlen );
139                         if( err != LDAP_SUCCESS ) {
140                                 Debug(LDAP_DEBUG_ARGS, "mdb_modify_internal: %d %s\n",
141                                         err, *text, 0);
142                         }
143                         break;
144
145                 case LDAP_MOD_DELETE:
146                         if ( glue_attr_delete ) {
147                                 err = LDAP_SUCCESS;
148                                 break;
149                         }
150
151                         Debug(LDAP_DEBUG_ARGS,
152                                 "mdb_modify_internal: delete %s\n",
153                                 mod->sm_desc->ad_cname.bv_val, 0, 0);
154                         err = modify_delete_values( e, mod, get_permissiveModify(op),
155                                 text, textbuf, textlen );
156                         if( err != LDAP_SUCCESS ) {
157                                 Debug(LDAP_DEBUG_ARGS, "mdb_modify_internal: %d %s\n",
158                                         err, *text, 0);
159                         } else {
160                                 got_delete = 1;
161                         }
162                         break;
163
164                 case LDAP_MOD_REPLACE:
165                         Debug(LDAP_DEBUG_ARGS,
166                                 "mdb_modify_internal: replace %s\n",
167                                 mod->sm_desc->ad_cname.bv_val, 0, 0);
168                         err = modify_replace_values( e, mod, get_permissiveModify(op),
169                                 text, textbuf, textlen );
170                         if( err != LDAP_SUCCESS ) {
171                                 Debug(LDAP_DEBUG_ARGS, "mdb_modify_internal: %d %s\n",
172                                         err, *text, 0);
173                         } else {
174                                 got_delete = 1;
175                         }
176                         break;
177
178                 case LDAP_MOD_INCREMENT:
179                         Debug(LDAP_DEBUG_ARGS,
180                                 "mdb_modify_internal: increment %s\n",
181                                 mod->sm_desc->ad_cname.bv_val, 0, 0);
182                         err = modify_increment_values( e, mod, get_permissiveModify(op),
183                                 text, textbuf, textlen );
184                         if( err != LDAP_SUCCESS ) {
185                                 Debug(LDAP_DEBUG_ARGS,
186                                         "mdb_modify_internal: %d %s\n",
187                                         err, *text, 0);
188                         } else {
189                                 got_delete = 1;
190                         }
191                         break;
192
193                 case SLAP_MOD_SOFTADD:
194                         Debug(LDAP_DEBUG_ARGS,
195                                 "mdb_modify_internal: softadd %s\n",
196                                 mod->sm_desc->ad_cname.bv_val, 0, 0);
197                         /* Avoid problems in index_add_mods()
198                          * We need to add index if necessary.
199                          */
200                         mod->sm_op = LDAP_MOD_ADD;
201
202                         err = modify_add_values( e, mod, get_permissiveModify(op),
203                                 text, textbuf, textlen );
204
205                         mod->sm_op = SLAP_MOD_SOFTADD;
206
207                         if ( err == LDAP_TYPE_OR_VALUE_EXISTS ) {
208                                 err = LDAP_SUCCESS;
209                         }
210
211                         if( err != LDAP_SUCCESS ) {
212                                 Debug(LDAP_DEBUG_ARGS, "mdb_modify_internal: %d %s\n",
213                                         err, *text, 0);
214                         }
215                         break;
216
217                 case SLAP_MOD_SOFTDEL:
218                         Debug(LDAP_DEBUG_ARGS,
219                                 "mdb_modify_internal: softdel %s\n",
220                                 mod->sm_desc->ad_cname.bv_val, 0, 0);
221                         /* Avoid problems in index_delete_mods()
222                          * We need to add index if necessary.
223                          */
224                         mod->sm_op = LDAP_MOD_DELETE;
225
226                         err = modify_delete_values( e, mod, get_permissiveModify(op),
227                                 text, textbuf, textlen );
228
229                         mod->sm_op = SLAP_MOD_SOFTDEL;
230
231                         if ( err == LDAP_NO_SUCH_ATTRIBUTE ) {
232                                 err = LDAP_SUCCESS;
233                         }
234
235                         if( err != LDAP_SUCCESS ) {
236                                 Debug(LDAP_DEBUG_ARGS, "mdb_modify_internal: %d %s\n",
237                                         err, *text, 0);
238                         }
239                         break;
240
241                 case SLAP_MOD_ADD_IF_NOT_PRESENT:
242                         if ( attr_find( e->e_attrs, mod->sm_desc ) != NULL ) {
243                                 /* skip */
244                                 err = LDAP_SUCCESS;
245                                 break;
246                         }
247
248                         Debug(LDAP_DEBUG_ARGS,
249                                 "mdb_modify_internal: add_if_not_present %s\n",
250                                 mod->sm_desc->ad_cname.bv_val, 0, 0);
251                         /* Avoid problems in index_add_mods()
252                          * We need to add index if necessary.
253                          */
254                         mod->sm_op = LDAP_MOD_ADD;
255
256                         err = modify_add_values( e, mod, get_permissiveModify(op),
257                                 text, textbuf, textlen );
258
259                         mod->sm_op = SLAP_MOD_ADD_IF_NOT_PRESENT;
260
261                         if( err != LDAP_SUCCESS ) {
262                                 Debug(LDAP_DEBUG_ARGS, "mdb_modify_internal: %d %s\n",
263                                         err, *text, 0);
264                         }
265                         break;
266
267                 default:
268                         Debug(LDAP_DEBUG_ANY, "mdb_modify_internal: invalid op %d\n",
269                                 mod->sm_op, 0, 0);
270                         *text = "Invalid modify operation";
271                         err = LDAP_OTHER;
272                         Debug(LDAP_DEBUG_ARGS, "mdb_modify_internal: %d %s\n",
273                                 err, *text, 0);
274                 }
275
276                 if ( err != LDAP_SUCCESS ) {
277                         attrs_free( e->e_attrs );
278                         e->e_attrs = save_attrs;
279                         /* unlock entry, delete from cache */
280                         return err; 
281                 }
282
283                 /* If objectClass was modified, reset the flags */
284                 if ( mod->sm_desc == slap_schema.si_ad_objectClass ) {
285                         e->e_ocflags = 0;
286                 }
287
288                 if ( glue_attr_delete ) e->e_ocflags = 0;
289
290
291                 /* check if modified attribute was indexed
292                  * but not in case of NOOP... */
293                 if ( !op->o_noop ) {
294                         mdb_modify_idxflags( op, mod->sm_desc, got_delete, e->e_attrs, save_attrs );
295                 }
296         }
297
298         /* check that the entry still obeys the schema */
299         ap = NULL;
300         rc = entry_schema_check( op, e, save_attrs, get_relax(op), 0, &ap,
301                 text, textbuf, textlen );
302         if ( rc != LDAP_SUCCESS || op->o_noop ) {
303                 attrs_free( e->e_attrs );
304                 /* clear the indexing flags */
305                 for ( ap = save_attrs; ap != NULL; ap = ap->a_next ) {
306                         ap->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
307                 }
308                 e->e_attrs = save_attrs;
309
310                 if ( rc != LDAP_SUCCESS ) {
311                         Debug( LDAP_DEBUG_ANY,
312                                 "entry failed schema check: %s\n",
313                                 *text, 0, 0 );
314                 }
315
316                 /* if NOOP then silently revert to saved attrs */
317                 return rc;
318         }
319
320         /* structuralObjectClass modified! */
321         if ( ap ) {
322                 assert( ap->a_desc == slap_schema.si_ad_structuralObjectClass );
323                 if ( !op->o_noop ) {
324                         mdb_modify_idxflags( op, slap_schema.si_ad_structuralObjectClass,
325                                 1, e->e_attrs, save_attrs );
326                 }
327         }
328
329         /* update the indices of the modified attributes */
330
331         /* start with deleting the old index entries */
332         for ( ap = save_attrs; ap != NULL; ap = ap->a_next ) {
333                 if ( ap->a_flags & SLAP_ATTR_IXDEL ) {
334                         struct berval *vals;
335                         Attribute *a2;
336                         ap->a_flags &= ~SLAP_ATTR_IXDEL;
337                         a2 = attr_find( e->e_attrs, ap->a_desc );
338                         if ( a2 ) {
339                                 /* need to detect which values were deleted */
340                                 int i, j;
341                                 vals = op->o_tmpalloc( (ap->a_numvals + 1) *
342                                         sizeof(struct berval), op->o_tmpmemctx );
343                                 j = 0;
344                                 for ( i=0; i < ap->a_numvals; i++ ) {
345                                         rc = attr_valfind( a2, SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
346                                                 &ap->a_nvals[i], NULL, op->o_tmpmemctx );
347                                         /* Save deleted values */
348                                         if ( rc == LDAP_NO_SUCH_ATTRIBUTE )
349                                                 vals[j++] = ap->a_nvals[i];
350                                 }
351                                 BER_BVZERO(vals+j);
352                         } else {
353                                 /* attribute was completely deleted */
354                                 vals = ap->a_nvals;
355                         }
356                         rc = 0;
357                         if ( !BER_BVISNULL( vals )) {
358                                 rc = mdb_index_values( op, tid, ap->a_desc,
359                                         vals, e->e_id, SLAP_INDEX_DELETE_OP );
360                                 if ( rc != LDAP_SUCCESS ) {
361                                         Debug( LDAP_DEBUG_ANY,
362                                                 "%s: attribute \"%s\" index delete failure\n",
363                                                 op->o_log_prefix, ap->a_desc->ad_cname.bv_val, 0 );
364                                         attrs_free( e->e_attrs );
365                                         e->e_attrs = save_attrs;
366                                 }
367                         }
368                         if ( vals != ap->a_nvals )
369                                 op->o_tmpfree( vals, op->o_tmpmemctx );
370                         if ( rc ) return rc;
371                 }
372         }
373
374         /* add the new index entries */
375         for ( ap = e->e_attrs; ap != NULL; ap = ap->a_next ) {
376                 if (ap->a_flags & SLAP_ATTR_IXADD) {
377                         ap->a_flags &= ~SLAP_ATTR_IXADD;
378                         rc = mdb_index_values( op, tid, ap->a_desc,
379                                 ap->a_nvals,
380                                 e->e_id, SLAP_INDEX_ADD_OP );
381                         if ( rc != LDAP_SUCCESS ) {
382                                 Debug( LDAP_DEBUG_ANY,
383                                        "%s: attribute \"%s\" index add failure\n",
384                                         op->o_log_prefix, ap->a_desc->ad_cname.bv_val, 0 );
385                                 attrs_free( e->e_attrs );
386                                 e->e_attrs = save_attrs;
387                                 return rc;
388                         }
389                 }
390         }
391
392         return rc;
393 }
394
395
396 int
397 mdb_modify( Operation *op, SlapReply *rs )
398 {
399         struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
400         Entry           *e = NULL;
401         int             manageDSAit = get_manageDSAit( op );
402         char textbuf[SLAP_TEXT_BUFLEN];
403         size_t textlen = sizeof textbuf;
404         MDB_txn *txn = NULL;
405         struct mdb_op_info opinfo = {{{ 0 }}};
406         Entry           dummy = {0};
407
408         LDAPControl **preread_ctrl = NULL;
409         LDAPControl **postread_ctrl = NULL;
410         LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
411         int num_ctrls = 0;
412
413 #ifdef LDAP_X_TXN
414         int settle = 0;
415 #endif
416
417         Debug( LDAP_DEBUG_ARGS, LDAP_XSTRING(mdb_modify) ": %s\n",
418                 op->o_req_dn.bv_val, 0, 0 );
419
420 #ifdef LDAP_X_TXN
421         if( op->o_txnSpec ) {
422                 /* acquire connection lock */
423                 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
424                 if( op->o_conn->c_txn == CONN_TXN_INACTIVE ) {
425                         rs->sr_text = "invalid transaction identifier";
426                         rs->sr_err = LDAP_X_TXN_ID_INVALID;
427                         goto txnReturn;
428                 } else if( op->o_conn->c_txn == CONN_TXN_SETTLE ) {
429                         settle=1;
430                         goto txnReturn;
431                 }
432
433                 if( op->o_conn->c_txn_backend == NULL ) {
434                         op->o_conn->c_txn_backend = op->o_bd;
435
436                 } else if( op->o_conn->c_txn_backend != op->o_bd ) {
437                         rs->sr_text = "transaction cannot span multiple database contexts";
438                         rs->sr_err = LDAP_AFFECTS_MULTIPLE_DSAS;
439                         goto txnReturn;
440                 }
441
442                 /* insert operation into transaction */
443
444                 rs->sr_text = "transaction specified";
445                 rs->sr_err = LDAP_X_TXN_SPECIFY_OKAY;
446
447 txnReturn:
448                 /* release connection lock */
449                 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
450
451                 if( !settle ) {
452                         send_ldap_result( op, rs );
453                         return rs->sr_err;
454                 }
455         }
456 #endif
457
458         ctrls[num_ctrls] = NULL;
459
460         /* Don't touch the opattrs, if this is a contextCSN update
461          * initiated from updatedn */
462         if ( !be_isupdate(op) || !op->orm_modlist || op->orm_modlist->sml_next ||
463                  op->orm_modlist->sml_desc != slap_schema.si_ad_contextCSN ) {
464
465                 slap_mods_opattrs( op, &op->orm_modlist, 1 );
466         }
467
468         /* begin transaction */
469         rs->sr_err = mdb_txn_begin( mdb->mi_dbenv, 0, &txn );
470         rs->sr_text = NULL;
471         if( rs->sr_err != 0 ) {
472                 Debug( LDAP_DEBUG_TRACE,
473                         LDAP_XSTRING(mdb_modify) ": txn_begin failed: "
474                         "%s (%d)\n", mdb_strerror(rs->sr_err), rs->sr_err, 0 );
475                 rs->sr_err = LDAP_OTHER;
476                 rs->sr_text = "internal error";
477                 goto return_results;
478         }
479
480         opinfo.moi_oe.oe_key = mdb;
481         opinfo.moi_txn = txn;
482         opinfo.moi_err = 0;
483         opinfo.moi_acl_cache = op->o_do_not_cache;
484         LDAP_SLIST_INSERT_HEAD( &op->o_extra, &opinfo.moi_oe, oe_next );
485
486         /* get entry or ancestor */
487         rs->sr_err = mdb_dn2entry( op, txn, &op->o_req_ndn, &e, 1 );
488
489         if ( rs->sr_err != 0 ) {
490                 Debug( LDAP_DEBUG_TRACE,
491                         LDAP_XSTRING(mdb_modify) ": dn2entry failed (%d)\n",
492                         rs->sr_err, 0, 0 );
493                 switch( rs->sr_err ) {
494                 case MDB_NOTFOUND:
495                         break;
496                 case LDAP_BUSY:
497                         rs->sr_text = "ldap server busy";
498                         goto return_results;
499                 default:
500                         rs->sr_err = LDAP_OTHER;
501                         rs->sr_text = "internal error";
502                         goto return_results;
503                 }
504         }
505
506         /* acquire and lock entry */
507         /* FIXME: dn2entry() should return non-glue entry */
508         if (( rs->sr_err == MDB_NOTFOUND ) ||
509                 ( !manageDSAit && e && is_entry_glue( e )))
510         {
511                 if ( e != NULL ) {
512                         rs->sr_matched = ch_strdup( e->e_dn );
513                         rs->sr_ref = is_entry_referral( e )
514                                 ? get_entry_referrals( op, e )
515                                 : NULL;
516                         mdb_entry_return( e );
517                         e = NULL;
518
519                 } else {
520                         rs->sr_ref = referral_rewrite( default_referral, NULL,
521                                 &op->o_req_dn, LDAP_SCOPE_DEFAULT );
522                 }
523
524                 rs->sr_flags = REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED;
525                 rs->sr_err = LDAP_REFERRAL;
526                 send_ldap_result( op, rs );
527                 goto done;
528         }
529
530         if ( !manageDSAit && is_entry_referral( e ) ) {
531                 /* entry is a referral, don't allow modify */
532                 rs->sr_ref = get_entry_referrals( op, e );
533
534                 Debug( LDAP_DEBUG_TRACE,
535                         LDAP_XSTRING(mdb_modify) ": entry is referral\n",
536                         0, 0, 0 );
537
538                 rs->sr_err = LDAP_REFERRAL;
539                 rs->sr_matched = e->e_name.bv_val;
540                 rs->sr_flags = REP_REF_MUSTBEFREED;
541                 send_ldap_result( op, rs );
542                 rs->sr_matched = NULL;
543                 goto done;
544         }
545
546         if ( get_assert( op ) &&
547                 ( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
548         {
549                 rs->sr_err = LDAP_ASSERTION_FAILED;
550                 goto return_results;
551         }
552
553         if( op->o_preread ) {
554                 if( preread_ctrl == NULL ) {
555                         preread_ctrl = &ctrls[num_ctrls++];
556                         ctrls[num_ctrls] = NULL;
557                 }
558                 if ( slap_read_controls( op, rs, e,
559                         &slap_pre_read_bv, preread_ctrl ) )
560                 {
561                         Debug( LDAP_DEBUG_TRACE,
562                                 "<=- " LDAP_XSTRING(mdb_modify) ": pre-read "
563                                 "failed!\n", 0, 0, 0 );
564                         if ( op->o_preread & SLAP_CONTROL_CRITICAL ) {
565                                 /* FIXME: is it correct to abort
566                                  * operation if control fails? */
567                                 goto return_results;
568                         }
569                 }
570         }
571
572         /* Modify the entry */
573         dummy = *e;
574         rs->sr_err = mdb_modify_internal( op, txn, op->orm_modlist,
575                 &dummy, &rs->sr_text, textbuf, textlen );
576
577         if( rs->sr_err != LDAP_SUCCESS ) {
578                 Debug( LDAP_DEBUG_TRACE,
579                         LDAP_XSTRING(mdb_modify) ": modify failed (%d)\n",
580                         rs->sr_err, 0, 0 );
581                 if ( (rs->sr_err == LDAP_INSUFFICIENT_ACCESS) && opinfo.moi_err ) {
582                         rs->sr_err = opinfo.moi_err;
583                 }
584                 /* Only free attrs if they were dup'd.  */
585                 if ( dummy.e_attrs == e->e_attrs ) dummy.e_attrs = NULL;
586                 goto return_results;
587         }
588
589         /* change the entry itself */
590         rs->sr_err = mdb_id2entry_update( op, txn, &dummy );
591         if ( rs->sr_err != 0 ) {
592                 Debug( LDAP_DEBUG_TRACE,
593                         LDAP_XSTRING(mdb_modify) ": id2entry update failed " "(%d)\n",
594                         rs->sr_err, 0, 0 );
595                 rs->sr_text = "entry update failed";
596                 goto return_results;
597         }
598
599         if( op->o_postread ) {
600                 if( postread_ctrl == NULL ) {
601                         postread_ctrl = &ctrls[num_ctrls++];
602                         ctrls[num_ctrls] = NULL;
603                 }
604                 if( slap_read_controls( op, rs, &dummy,
605                         &slap_post_read_bv, postread_ctrl ) )
606                 {
607                         Debug( LDAP_DEBUG_TRACE,
608                                 "<=- " LDAP_XSTRING(mdb_modify)
609                                 ": post-read failed!\n", 0, 0, 0 );
610                         if ( op->o_postread & SLAP_CONTROL_CRITICAL ) {
611                                 /* FIXME: is it correct to abort
612                                  * operation if control fails? */
613                                 goto return_results;
614                         }
615                 }
616         }
617
618         if( op->o_noop ) {
619                 mdb_txn_abort( txn );
620                 rs->sr_err = LDAP_X_NO_OPERATION;
621                 txn = NULL;
622                 /* Only free attrs if they were dup'd.  */
623                 if ( dummy.e_attrs == e->e_attrs ) dummy.e_attrs = NULL;
624                 goto return_results;
625         } else {
626                 dummy.e_attrs = NULL;
627
628                 rs->sr_err = mdb_txn_commit( txn );
629         }
630         txn = NULL;
631         LDAP_SLIST_REMOVE( &op->o_extra, &opinfo.moi_oe, OpExtra, oe_next );
632         opinfo.moi_oe.oe_key = NULL;
633
634         if( rs->sr_err != 0 ) {
635                 Debug( LDAP_DEBUG_TRACE,
636                         LDAP_XSTRING(mdb_modify) ": txn_%s failed: %s (%d)\n",
637                         op->o_noop ? "abort (no-op)" : "commit",
638                         mdb_strerror(rs->sr_err), rs->sr_err );
639                 rs->sr_err = LDAP_OTHER;
640                 rs->sr_text = "commit failed";
641
642                 goto return_results;
643         }
644
645         Debug( LDAP_DEBUG_TRACE,
646                 LDAP_XSTRING(mdb_modify) ": updated%s id=%08lx dn=\"%s\"\n",
647                 op->o_noop ? " (no-op)" : "",
648                 dummy.e_id, op->o_req_dn.bv_val );
649
650         rs->sr_err = LDAP_SUCCESS;
651         rs->sr_text = NULL;
652         if( num_ctrls ) rs->sr_ctrls = ctrls;
653
654 return_results:
655         if( dummy.e_attrs ) {
656                 attrs_free( dummy.e_attrs );
657         }
658         send_ldap_result( op, rs );
659
660 #if 0
661         if( rs->sr_err == LDAP_SUCCESS && mdb->bi_txn_cp_kbyte ) {
662                 TXN_CHECKPOINT( mdb->bi_dbenv,
663                         mdb->bi_txn_cp_kbyte, mdb->bi_txn_cp_min, 0 );
664         }
665 #endif
666
667 done:
668         slap_graduate_commit_csn( op );
669
670         if( txn != NULL ) {
671                 mdb_txn_abort( txn );
672         }
673         if ( opinfo.moi_oe.oe_key ) {
674                 LDAP_SLIST_REMOVE( &op->o_extra, &opinfo.moi_oe, OpExtra, oe_next );
675         }
676
677         if( e != NULL ) {
678                 mdb_entry_return( e );
679         }
680
681         if( preread_ctrl != NULL && (*preread_ctrl) != NULL ) {
682                 slap_sl_free( (*preread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
683                 slap_sl_free( *preread_ctrl, op->o_tmpmemctx );
684         }
685         if( postread_ctrl != NULL && (*postread_ctrl) != NULL ) {
686                 slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
687                 slap_sl_free( *postread_ctrl, op->o_tmpmemctx );
688         }
689
690         rs->sr_text = NULL;
691
692         return rs->sr_err;
693 }