Back to index

openldap  2.4.31
modify.c
Go to the documentation of this file.
00001 /* modify.c - mdb backend modify routine */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2000-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 
00017 #include "portable.h"
00018 
00019 #include <stdio.h>
00020 #include <ac/string.h>
00021 #include <ac/time.h>
00022 
00023 #include "back-mdb.h"
00024 
00025 static struct berval scbva[] = {
00026        BER_BVC("glue"),
00027        BER_BVNULL
00028 };
00029 
00030 static void
00031 mdb_modify_idxflags(
00032        Operation *op,
00033        AttributeDescription *desc,
00034        int got_delete,
00035        Attribute *newattrs,
00036        Attribute *oldattrs )
00037 {
00038        struct berval ix_at;
00039        AttrInfo      *ai;
00040 
00041        /* check if modified attribute was indexed
00042         * but not in case of NOOP... */
00043        ai = mdb_index_mask( op->o_bd, desc, &ix_at );
00044        if ( ai ) {
00045               if ( got_delete ) {
00046                      Attribute     *ap;
00047                      struct berval ix2;
00048 
00049                      ap = attr_find( oldattrs, desc );
00050                      if ( ap ) ap->a_flags |= SLAP_ATTR_IXDEL;
00051 
00052                      /* Find all other attrs that index to same slot */
00053                      for ( ap = newattrs; ap; ap = ap->a_next ) {
00054                             ai = mdb_index_mask( op->o_bd, ap->a_desc, &ix2 );
00055                             if ( ai && ix2.bv_val == ix_at.bv_val )
00056                                    ap->a_flags |= SLAP_ATTR_IXADD;
00057                      }
00058 
00059               } else {
00060                      Attribute     *ap;
00061 
00062                      ap = attr_find( newattrs, desc );
00063                      if ( ap ) ap->a_flags |= SLAP_ATTR_IXADD;
00064               }
00065        }
00066 }
00067 
00068 int mdb_modify_internal(
00069        Operation *op,
00070        MDB_txn *tid,
00071        Modifications *modlist,
00072        Entry *e,
00073        const char **text,
00074        char *textbuf,
00075        size_t textlen )
00076 {
00077        int rc, err;
00078        Modification  *mod;
00079        Modifications *ml;
00080        Attribute     *save_attrs;
00081        Attribute     *ap;
00082        int                  glue_attr_delete = 0;
00083        int                  got_delete;
00084 
00085        Debug( LDAP_DEBUG_TRACE, "mdb_modify_internal: 0x%08lx: %s\n",
00086               e->e_id, e->e_dn, 0);
00087 
00088        if ( !acl_check_modlist( op, e, modlist )) {
00089               return LDAP_INSUFFICIENT_ACCESS;
00090        }
00091 
00092        /* save_attrs will be disposed of by caller */
00093        save_attrs = e->e_attrs;
00094        e->e_attrs = attrs_dup( e->e_attrs );
00095 
00096        for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
00097               int match;
00098               mod = &ml->sml_mod;
00099               switch( mod->sm_op ) {
00100               case LDAP_MOD_ADD:
00101               case LDAP_MOD_REPLACE:
00102                      if ( mod->sm_desc == slap_schema.si_ad_structuralObjectClass ) {
00103                             value_match( &match, slap_schema.si_ad_structuralObjectClass,
00104                                    slap_schema.si_ad_structuralObjectClass->
00105                                           ad_type->sat_equality,
00106                                    SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
00107                                    &mod->sm_values[0], &scbva[0], text );
00108                             if ( !match ) glue_attr_delete = 1;
00109                      }
00110               }
00111               if ( glue_attr_delete )
00112                      break;
00113        }
00114 
00115        if ( glue_attr_delete ) {
00116               Attribute     **app = &e->e_attrs;
00117               while ( *app != NULL ) {
00118                      if ( !is_at_operational( (*app)->a_desc->ad_type )) {
00119                             Attribute *save = *app;
00120                             *app = (*app)->a_next;
00121                             attr_free( save );
00122                             continue;
00123                      }
00124                      app = &(*app)->a_next;
00125               }
00126        }
00127 
00128        for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
00129               mod = &ml->sml_mod;
00130               got_delete = 0;
00131 
00132               switch ( mod->sm_op ) {
00133               case LDAP_MOD_ADD:
00134                      Debug(LDAP_DEBUG_ARGS,
00135                             "mdb_modify_internal: add %s\n",
00136                             mod->sm_desc->ad_cname.bv_val, 0, 0);
00137                      err = modify_add_values( e, mod, get_permissiveModify(op),
00138                             text, textbuf, textlen );
00139                      if( err != LDAP_SUCCESS ) {
00140                             Debug(LDAP_DEBUG_ARGS, "mdb_modify_internal: %d %s\n",
00141                                    err, *text, 0);
00142                      }
00143                      break;
00144 
00145               case LDAP_MOD_DELETE:
00146                      if ( glue_attr_delete ) {
00147                             err = LDAP_SUCCESS;
00148                             break;
00149                      }
00150 
00151                      Debug(LDAP_DEBUG_ARGS,
00152                             "mdb_modify_internal: delete %s\n",
00153                             mod->sm_desc->ad_cname.bv_val, 0, 0);
00154                      err = modify_delete_values( e, mod, get_permissiveModify(op),
00155                             text, textbuf, textlen );
00156                      if( err != LDAP_SUCCESS ) {
00157                             Debug(LDAP_DEBUG_ARGS, "mdb_modify_internal: %d %s\n",
00158                                    err, *text, 0);
00159                      } else {
00160                             got_delete = 1;
00161                      }
00162                      break;
00163 
00164               case LDAP_MOD_REPLACE:
00165                      Debug(LDAP_DEBUG_ARGS,
00166                             "mdb_modify_internal: replace %s\n",
00167                             mod->sm_desc->ad_cname.bv_val, 0, 0);
00168                      err = modify_replace_values( e, mod, get_permissiveModify(op),
00169                             text, textbuf, textlen );
00170                      if( err != LDAP_SUCCESS ) {
00171                             Debug(LDAP_DEBUG_ARGS, "mdb_modify_internal: %d %s\n",
00172                                    err, *text, 0);
00173                      } else {
00174                             got_delete = 1;
00175                      }
00176                      break;
00177 
00178               case LDAP_MOD_INCREMENT:
00179                      Debug(LDAP_DEBUG_ARGS,
00180                             "mdb_modify_internal: increment %s\n",
00181                             mod->sm_desc->ad_cname.bv_val, 0, 0);
00182                      err = modify_increment_values( e, mod, get_permissiveModify(op),
00183                             text, textbuf, textlen );
00184                      if( err != LDAP_SUCCESS ) {
00185                             Debug(LDAP_DEBUG_ARGS,
00186                                    "mdb_modify_internal: %d %s\n",
00187                                    err, *text, 0);
00188                      } else {
00189                             got_delete = 1;
00190                      }
00191                      break;
00192 
00193               case SLAP_MOD_SOFTADD:
00194                      Debug(LDAP_DEBUG_ARGS,
00195                             "mdb_modify_internal: softadd %s\n",
00196                             mod->sm_desc->ad_cname.bv_val, 0, 0);
00197                      /* Avoid problems in index_add_mods()
00198                       * We need to add index if necessary.
00199                       */
00200                      mod->sm_op = LDAP_MOD_ADD;
00201 
00202                      err = modify_add_values( e, mod, get_permissiveModify(op),
00203                             text, textbuf, textlen );
00204 
00205                      mod->sm_op = SLAP_MOD_SOFTADD;
00206 
00207                      if ( err == LDAP_TYPE_OR_VALUE_EXISTS ) {
00208                             err = LDAP_SUCCESS;
00209                      }
00210 
00211                      if( err != LDAP_SUCCESS ) {
00212                             Debug(LDAP_DEBUG_ARGS, "mdb_modify_internal: %d %s\n",
00213                                    err, *text, 0);
00214                      }
00215                      break;
00216 
00217               case SLAP_MOD_SOFTDEL:
00218                      Debug(LDAP_DEBUG_ARGS,
00219                             "mdb_modify_internal: softdel %s\n",
00220                             mod->sm_desc->ad_cname.bv_val, 0, 0);
00221                      /* Avoid problems in index_delete_mods()
00222                       * We need to add index if necessary.
00223                       */
00224                      mod->sm_op = LDAP_MOD_DELETE;
00225 
00226                      err = modify_delete_values( e, mod, get_permissiveModify(op),
00227                             text, textbuf, textlen );
00228 
00229                      mod->sm_op = SLAP_MOD_SOFTDEL;
00230 
00231                      if ( err == LDAP_NO_SUCH_ATTRIBUTE ) {
00232                             err = LDAP_SUCCESS;
00233                      }
00234 
00235                      if( err != LDAP_SUCCESS ) {
00236                             Debug(LDAP_DEBUG_ARGS, "mdb_modify_internal: %d %s\n",
00237                                    err, *text, 0);
00238                      }
00239                      break;
00240 
00241               case SLAP_MOD_ADD_IF_NOT_PRESENT:
00242                      if ( attr_find( e->e_attrs, mod->sm_desc ) != NULL ) {
00243                             /* skip */
00244                             err = LDAP_SUCCESS;
00245                             break;
00246                      }
00247 
00248                      Debug(LDAP_DEBUG_ARGS,
00249                             "mdb_modify_internal: add_if_not_present %s\n",
00250                             mod->sm_desc->ad_cname.bv_val, 0, 0);
00251                      /* Avoid problems in index_add_mods()
00252                       * We need to add index if necessary.
00253                       */
00254                      mod->sm_op = LDAP_MOD_ADD;
00255 
00256                      err = modify_add_values( e, mod, get_permissiveModify(op),
00257                             text, textbuf, textlen );
00258 
00259                      mod->sm_op = SLAP_MOD_ADD_IF_NOT_PRESENT;
00260 
00261                      if( err != LDAP_SUCCESS ) {
00262                             Debug(LDAP_DEBUG_ARGS, "mdb_modify_internal: %d %s\n",
00263                                    err, *text, 0);
00264                      }
00265                      break;
00266 
00267               default:
00268                      Debug(LDAP_DEBUG_ANY, "mdb_modify_internal: invalid op %d\n",
00269                             mod->sm_op, 0, 0);
00270                      *text = "Invalid modify operation";
00271                      err = LDAP_OTHER;
00272                      Debug(LDAP_DEBUG_ARGS, "mdb_modify_internal: %d %s\n",
00273                             err, *text, 0);
00274               }
00275 
00276               if ( err != LDAP_SUCCESS ) {
00277                      attrs_free( e->e_attrs );
00278                      e->e_attrs = save_attrs;
00279                      /* unlock entry, delete from cache */
00280                      return err; 
00281               }
00282 
00283               /* If objectClass was modified, reset the flags */
00284               if ( mod->sm_desc == slap_schema.si_ad_objectClass ) {
00285                      e->e_ocflags = 0;
00286               }
00287 
00288               if ( glue_attr_delete ) e->e_ocflags = 0;
00289 
00290 
00291               /* check if modified attribute was indexed
00292                * but not in case of NOOP... */
00293               if ( !op->o_noop ) {
00294                      mdb_modify_idxflags( op, mod->sm_desc, got_delete, e->e_attrs, save_attrs );
00295               }
00296        }
00297 
00298        /* check that the entry still obeys the schema */
00299        ap = NULL;
00300        rc = entry_schema_check( op, e, save_attrs, get_relax(op), 0, &ap,
00301               text, textbuf, textlen );
00302        if ( rc != LDAP_SUCCESS || op->o_noop ) {
00303               attrs_free( e->e_attrs );
00304               /* clear the indexing flags */
00305               for ( ap = save_attrs; ap != NULL; ap = ap->a_next ) {
00306                      ap->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
00307               }
00308               e->e_attrs = save_attrs;
00309 
00310               if ( rc != LDAP_SUCCESS ) {
00311                      Debug( LDAP_DEBUG_ANY,
00312                             "entry failed schema check: %s\n",
00313                             *text, 0, 0 );
00314               }
00315 
00316               /* if NOOP then silently revert to saved attrs */
00317               return rc;
00318        }
00319 
00320        /* structuralObjectClass modified! */
00321        if ( ap ) {
00322               assert( ap->a_desc == slap_schema.si_ad_structuralObjectClass );
00323               if ( !op->o_noop ) {
00324                      mdb_modify_idxflags( op, slap_schema.si_ad_structuralObjectClass,
00325                             1, e->e_attrs, save_attrs );
00326               }
00327        }
00328 
00329        /* update the indices of the modified attributes */
00330 
00331        /* start with deleting the old index entries */
00332        for ( ap = save_attrs; ap != NULL; ap = ap->a_next ) {
00333               if ( ap->a_flags & SLAP_ATTR_IXDEL ) {
00334                      struct berval *vals;
00335                      Attribute *a2;
00336                      ap->a_flags &= ~SLAP_ATTR_IXDEL;
00337                      a2 = attr_find( e->e_attrs, ap->a_desc );
00338                      if ( a2 ) {
00339                             /* need to detect which values were deleted */
00340                             int i, j;
00341                             vals = op->o_tmpalloc( (ap->a_numvals + 1) *
00342                                    sizeof(struct berval), op->o_tmpmemctx );
00343                             j = 0;
00344                             for ( i=0; i < ap->a_numvals; i++ ) {
00345                                    rc = attr_valfind( a2, SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
00346                                           &ap->a_nvals[i], NULL, op->o_tmpmemctx );
00347                                    /* Save deleted values */
00348                                    if ( rc == LDAP_NO_SUCH_ATTRIBUTE )
00349                                           vals[j++] = ap->a_nvals[i];
00350                             }
00351                             BER_BVZERO(vals+j);
00352                      } else {
00353                             /* attribute was completely deleted */
00354                             vals = ap->a_nvals;
00355                      }
00356                      rc = 0;
00357                      if ( !BER_BVISNULL( vals )) {
00358                             rc = mdb_index_values( op, tid, ap->a_desc,
00359                                    vals, e->e_id, SLAP_INDEX_DELETE_OP );
00360                             if ( rc != LDAP_SUCCESS ) {
00361                                    Debug( LDAP_DEBUG_ANY,
00362                                           "%s: attribute \"%s\" index delete failure\n",
00363                                           op->o_log_prefix, ap->a_desc->ad_cname.bv_val, 0 );
00364                                    attrs_free( e->e_attrs );
00365                                    e->e_attrs = save_attrs;
00366                             }
00367                      }
00368                      if ( vals != ap->a_nvals )
00369                             op->o_tmpfree( vals, op->o_tmpmemctx );
00370                      if ( rc ) return rc;
00371               }
00372        }
00373 
00374        /* add the new index entries */
00375        for ( ap = e->e_attrs; ap != NULL; ap = ap->a_next ) {
00376               if (ap->a_flags & SLAP_ATTR_IXADD) {
00377                      ap->a_flags &= ~SLAP_ATTR_IXADD;
00378                      rc = mdb_index_values( op, tid, ap->a_desc,
00379                             ap->a_nvals,
00380                             e->e_id, SLAP_INDEX_ADD_OP );
00381                      if ( rc != LDAP_SUCCESS ) {
00382                             Debug( LDAP_DEBUG_ANY,
00383                                    "%s: attribute \"%s\" index add failure\n",
00384                                    op->o_log_prefix, ap->a_desc->ad_cname.bv_val, 0 );
00385                             attrs_free( e->e_attrs );
00386                             e->e_attrs = save_attrs;
00387                             return rc;
00388                      }
00389               }
00390        }
00391 
00392        return rc;
00393 }
00394 
00395 
00396 int
00397 mdb_modify( Operation *op, SlapReply *rs )
00398 {
00399        struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
00400        Entry         *e = NULL;
00401        int           manageDSAit = get_manageDSAit( op );
00402        char textbuf[SLAP_TEXT_BUFLEN];
00403        size_t textlen = sizeof textbuf;
00404        MDB_txn       *txn = NULL;
00405        mdb_op_info opinfo = {{{ 0 }}}, *moi = &opinfo;
00406        Entry         dummy = {0};
00407 
00408        LDAPControl **preread_ctrl = NULL;
00409        LDAPControl **postread_ctrl = NULL;
00410        LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
00411        int num_ctrls = 0;
00412 
00413 #ifdef LDAP_X_TXN
00414        int settle = 0;
00415 #endif
00416 
00417        Debug( LDAP_DEBUG_ARGS, LDAP_XSTRING(mdb_modify) ": %s\n",
00418               op->o_req_dn.bv_val, 0, 0 );
00419 
00420 #ifdef LDAP_X_TXN
00421        if( op->o_txnSpec ) {
00422               /* acquire connection lock */
00423               ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
00424               if( op->o_conn->c_txn == CONN_TXN_INACTIVE ) {
00425                      rs->sr_text = "invalid transaction identifier";
00426                      rs->sr_err = LDAP_X_TXN_ID_INVALID;
00427                      goto txnReturn;
00428               } else if( op->o_conn->c_txn == CONN_TXN_SETTLE ) {
00429                      settle=1;
00430                      goto txnReturn;
00431               }
00432 
00433               if( op->o_conn->c_txn_backend == NULL ) {
00434                      op->o_conn->c_txn_backend = op->o_bd;
00435 
00436               } else if( op->o_conn->c_txn_backend != op->o_bd ) {
00437                      rs->sr_text = "transaction cannot span multiple database contexts";
00438                      rs->sr_err = LDAP_AFFECTS_MULTIPLE_DSAS;
00439                      goto txnReturn;
00440               }
00441 
00442               /* insert operation into transaction */
00443 
00444               rs->sr_text = "transaction specified";
00445               rs->sr_err = LDAP_X_TXN_SPECIFY_OKAY;
00446 
00447 txnReturn:
00448               /* release connection lock */
00449               ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
00450 
00451               if( !settle ) {
00452                      send_ldap_result( op, rs );
00453                      return rs->sr_err;
00454               }
00455        }
00456 #endif
00457 
00458        ctrls[num_ctrls] = NULL;
00459 
00460        /* Don't touch the opattrs, if this is a contextCSN update
00461         * initiated from updatedn */
00462        if ( !be_isupdate(op) || !op->orm_modlist || op->orm_modlist->sml_next ||
00463                op->orm_modlist->sml_desc != slap_schema.si_ad_contextCSN ) {
00464 
00465               slap_mods_opattrs( op, &op->orm_modlist, 1 );
00466        }
00467 
00468        /* begin transaction */
00469        rs->sr_err = mdb_opinfo_get( op, mdb, 0, &moi );
00470        rs->sr_text = NULL;
00471        if( rs->sr_err != 0 ) {
00472               Debug( LDAP_DEBUG_TRACE,
00473                      LDAP_XSTRING(mdb_modify) ": txn_begin failed: "
00474                      "%s (%d)\n", mdb_strerror(rs->sr_err), rs->sr_err, 0 );
00475               rs->sr_err = LDAP_OTHER;
00476               rs->sr_text = "internal error";
00477               goto return_results;
00478        }
00479 
00480        txn = moi->moi_txn;
00481 
00482        /* get entry or ancestor */
00483        rs->sr_err = mdb_dn2entry( op, txn, NULL, &op->o_req_ndn, &e, 1 );
00484 
00485        if ( rs->sr_err != 0 ) {
00486               Debug( LDAP_DEBUG_TRACE,
00487                      LDAP_XSTRING(mdb_modify) ": dn2entry failed (%d)\n",
00488                      rs->sr_err, 0, 0 );
00489               switch( rs->sr_err ) {
00490               case MDB_NOTFOUND:
00491                      break;
00492               case LDAP_BUSY:
00493                      rs->sr_text = "ldap server busy";
00494                      goto return_results;
00495               default:
00496                      rs->sr_err = LDAP_OTHER;
00497                      rs->sr_text = "internal error";
00498                      goto return_results;
00499               }
00500        }
00501 
00502        /* acquire and lock entry */
00503        /* FIXME: dn2entry() should return non-glue entry */
00504        if (( rs->sr_err == MDB_NOTFOUND ) ||
00505               ( !manageDSAit && e && is_entry_glue( e )))
00506        {
00507               if ( e != NULL ) {
00508                      rs->sr_matched = ch_strdup( e->e_dn );
00509                      if ( is_entry_referral( e )) {
00510                             BerVarray ref = get_entry_referrals( op, e );
00511                             rs->sr_ref = referral_rewrite( ref, &e->e_name,
00512                                    &op->o_req_dn, LDAP_SCOPE_DEFAULT );
00513                             ber_bvarray_free( ref );
00514                      } else {
00515                             rs->sr_ref = NULL;
00516                      }
00517                      mdb_entry_return( op, e );
00518                      e = NULL;
00519 
00520               } else {
00521                      rs->sr_ref = referral_rewrite( default_referral, NULL,
00522                             &op->o_req_dn, LDAP_SCOPE_DEFAULT );
00523               }
00524 
00525               rs->sr_flags = REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED;
00526               rs->sr_err = LDAP_REFERRAL;
00527               send_ldap_result( op, rs );
00528               goto done;
00529        }
00530 
00531        if ( !manageDSAit && is_entry_referral( e ) ) {
00532               /* entry is a referral, don't allow modify */
00533               rs->sr_ref = get_entry_referrals( op, e );
00534 
00535               Debug( LDAP_DEBUG_TRACE,
00536                      LDAP_XSTRING(mdb_modify) ": entry is referral\n",
00537                      0, 0, 0 );
00538 
00539               rs->sr_err = LDAP_REFERRAL;
00540               rs->sr_matched = e->e_name.bv_val;
00541               rs->sr_flags = REP_REF_MUSTBEFREED;
00542               send_ldap_result( op, rs );
00543               rs->sr_matched = NULL;
00544               goto done;
00545        }
00546 
00547        if ( get_assert( op ) &&
00548               ( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
00549        {
00550               rs->sr_err = LDAP_ASSERTION_FAILED;
00551               goto return_results;
00552        }
00553 
00554        if( op->o_preread ) {
00555               if( preread_ctrl == NULL ) {
00556                      preread_ctrl = &ctrls[num_ctrls++];
00557                      ctrls[num_ctrls] = NULL;
00558               }
00559               if ( slap_read_controls( op, rs, e,
00560                      &slap_pre_read_bv, preread_ctrl ) )
00561               {
00562                      Debug( LDAP_DEBUG_TRACE,
00563                             "<=- " LDAP_XSTRING(mdb_modify) ": pre-read "
00564                             "failed!\n", 0, 0, 0 );
00565                      if ( op->o_preread & SLAP_CONTROL_CRITICAL ) {
00566                             /* FIXME: is it correct to abort
00567                              * operation if control fails? */
00568                             goto return_results;
00569                      }
00570               }
00571        }
00572 
00573        /* Modify the entry */
00574        dummy = *e;
00575        rs->sr_err = mdb_modify_internal( op, txn, op->orm_modlist,
00576               &dummy, &rs->sr_text, textbuf, textlen );
00577 
00578        if( rs->sr_err != LDAP_SUCCESS ) {
00579               Debug( LDAP_DEBUG_TRACE,
00580                      LDAP_XSTRING(mdb_modify) ": modify failed (%d)\n",
00581                      rs->sr_err, 0, 0 );
00582               /* Only free attrs if they were dup'd.  */
00583               if ( dummy.e_attrs == e->e_attrs ) dummy.e_attrs = NULL;
00584               goto return_results;
00585        }
00586 
00587        /* change the entry itself */
00588        rs->sr_err = mdb_id2entry_update( op, txn, NULL, &dummy );
00589        if ( rs->sr_err != 0 ) {
00590               Debug( LDAP_DEBUG_TRACE,
00591                      LDAP_XSTRING(mdb_modify) ": id2entry update failed " "(%d)\n",
00592                      rs->sr_err, 0, 0 );
00593               rs->sr_text = "entry update failed";
00594               goto return_results;
00595        }
00596 
00597        if( op->o_postread ) {
00598               if( postread_ctrl == NULL ) {
00599                      postread_ctrl = &ctrls[num_ctrls++];
00600                      ctrls[num_ctrls] = NULL;
00601               }
00602               if( slap_read_controls( op, rs, &dummy,
00603                      &slap_post_read_bv, postread_ctrl ) )
00604               {
00605                      Debug( LDAP_DEBUG_TRACE,
00606                             "<=- " LDAP_XSTRING(mdb_modify)
00607                             ": post-read failed!\n", 0, 0, 0 );
00608                      if ( op->o_postread & SLAP_CONTROL_CRITICAL ) {
00609                             /* FIXME: is it correct to abort
00610                              * operation if control fails? */
00611                             goto return_results;
00612                      }
00613               }
00614        }
00615 
00616        /* Only free attrs if they were dup'd.  */
00617        if ( dummy.e_attrs == e->e_attrs ) dummy.e_attrs = NULL;
00618        if( moi == &opinfo ) {
00619               LDAP_SLIST_REMOVE( &op->o_extra, &opinfo.moi_oe, OpExtra, oe_next );
00620               opinfo.moi_oe.oe_key = NULL;
00621               if( op->o_noop ) {
00622                      mdb_txn_abort( txn );
00623                      rs->sr_err = LDAP_X_NO_OPERATION;
00624                      txn = NULL;
00625                      goto return_results;
00626               } else {
00627                      rs->sr_err = mdb_txn_commit( txn );
00628                      txn = NULL;
00629               }
00630        }
00631 
00632        if( rs->sr_err != 0 ) {
00633               Debug( LDAP_DEBUG_TRACE,
00634                      LDAP_XSTRING(mdb_modify) ": txn_%s failed: %s (%d)\n",
00635                      op->o_noop ? "abort (no-op)" : "commit",
00636                      mdb_strerror(rs->sr_err), rs->sr_err );
00637               rs->sr_err = LDAP_OTHER;
00638               rs->sr_text = "commit failed";
00639 
00640               goto return_results;
00641        }
00642 
00643        Debug( LDAP_DEBUG_TRACE,
00644               LDAP_XSTRING(mdb_modify) ": updated%s id=%08lx dn=\"%s\"\n",
00645               op->o_noop ? " (no-op)" : "",
00646               dummy.e_id, op->o_req_dn.bv_val );
00647 
00648        rs->sr_err = LDAP_SUCCESS;
00649        rs->sr_text = NULL;
00650        if( num_ctrls ) rs->sr_ctrls = ctrls;
00651 
00652 return_results:
00653        if( dummy.e_attrs ) {
00654               attrs_free( dummy.e_attrs );
00655        }
00656        send_ldap_result( op, rs );
00657 
00658 #if 0
00659        if( rs->sr_err == LDAP_SUCCESS && mdb->bi_txn_cp_kbyte ) {
00660               TXN_CHECKPOINT( mdb->bi_dbenv,
00661                      mdb->bi_txn_cp_kbyte, mdb->bi_txn_cp_min, 0 );
00662        }
00663 #endif
00664 
00665 done:
00666        slap_graduate_commit_csn( op );
00667 
00668        if( moi == &opinfo ) {
00669               if( txn != NULL ) {
00670                      mdb_txn_abort( txn );
00671               }
00672               if ( opinfo.moi_oe.oe_key ) {
00673                      LDAP_SLIST_REMOVE( &op->o_extra, &opinfo.moi_oe, OpExtra, oe_next );
00674               }
00675        }
00676 
00677        if( e != NULL ) {
00678               mdb_entry_return( op, e );
00679        }
00680 
00681        if( preread_ctrl != NULL && (*preread_ctrl) != NULL ) {
00682               slap_sl_free( (*preread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
00683               slap_sl_free( *preread_ctrl, op->o_tmpmemctx );
00684        }
00685        if( postread_ctrl != NULL && (*postread_ctrl) != NULL ) {
00686               slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
00687               slap_sl_free( *postread_ctrl, op->o_tmpmemctx );
00688        }
00689 
00690        rs->sr_text = NULL;
00691 
00692        return rs->sr_err;
00693 }