| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335 |
- /** BEGIN COPYRIGHT BLOCK
- * This Program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; version 2 of the License.
- *
- * This Program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA.
- *
- * In addition, as a special exception, Red Hat, Inc. gives You the additional
- * right to link the code of this Program with code not covered under the GNU
- * General Public License ("Non-GPL Code") and to distribute linked combinations
- * including the two, subject to the limitations in this paragraph. Non-GPL Code
- * permitted under this exception must only link to the code of this Program
- * through those well defined interfaces identified in the file named EXCEPTION
- * found in the source code files (the "Approved Interfaces"). The files of
- * Non-GPL Code may instantiate templates or use macros or inline functions from
- * the Approved Interfaces without causing the resulting work to be covered by
- * the GNU General Public License. Only Red Hat, Inc. may make changes or
- * additions to the list of Approved Interfaces. You must obey the GNU General
- * Public License in all respects for all of the Program code and other code used
- * in conjunction with the Program except the Non-GPL Code covered by this
- * exception. If you modify this file, you may extend this exception to your
- * version of the file, but you are not obligated to do so. If you do not wish to
- * provide this exception without modification, you must delete this exception
- * statement from your version and license this file solely under the GPL without
- * exception.
- *
- *
- * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
- * Copyright (C) 2005 Red Hat, Inc.
- * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
- * All rights reserved.
- * END COPYRIGHT BLOCK **/
- #ifdef HAVE_CONFIG_H
- # include <config.h>
- #endif
- /* add.c - ldap ldbm back-end add routine */
- #include "back-ldbm.h"
- extern char *numsubordinates;
- extern char *hassubordinates;
- static void delete_update_entrydn_operational_attributes(struct backentry *ep);
- #define ADD_SET_ERROR(rc, error, count) \
- { \
- (rc) = (error); \
- (count) = RETRY_TIMES; /* otherwise, the transaction may not be aborted */ \
- }
- /* in order to find the parent, we must have either the parent dn or uniqueid
- This function will return true if either are set, or false otherwise */
- static int
- have_parent_address(const Slapi_DN *parentsdn, const char *parentuniqueid)
- {
- if (parentuniqueid && parentuniqueid[0]) {
- return 1; /* have parent uniqueid */
- }
- if (parentsdn && !slapi_sdn_isempty(parentsdn)) {
- return 1; /* have parent dn */
- }
- return 0; /* have no address */
- }
- int
- ldbm_back_add( Slapi_PBlock *pb )
- {
- backend *be;
- struct ldbminfo *li;
- ldbm_instance *inst;
- Slapi_Entry *e = NULL;
- struct backentry *tombstoneentry = NULL;
- struct backentry *addingentry = NULL;
- struct backentry *parententry = NULL;
- struct backentry *originalentry = NULL;
- struct backentry *tmpentry = NULL;
- ID pid;
- int isroot;
- char *errbuf= NULL;
- back_txn txn;
- back_txnid parent_txn;
- int retval = -1;
- char *msg;
- int managedsait;
- int ldap_result_code = LDAP_SUCCESS;
- char *ldap_result_message = NULL;
- char *ldap_result_matcheddn = NULL;
- int retry_count = 0;
- int disk_full = 0;
- modify_context parent_modify_c = {0};
- modify_context ruv_c = {0};
- int parent_found = 0;
- int ruv_c_init = 0;
- int rc;
- int addingentry_id_assigned= 0;
- Slapi_DN *sdn = NULL;
- Slapi_DN parentsdn;
- Slapi_Operation *operation;
- int dblock_acquired= 0;
- int is_replicated_operation= 0;
- int is_resurect_operation= 0;
- int is_tombstone_operation= 0;
- int is_fixup_operation= 0;
- int is_ruv = 0; /* True if the current entry is RUV */
- CSN *opcsn = NULL;
- entry_address addr = {0};
- int parent_switched = 0;
- int noabort = 1;
- const char *dn = NULL;
- slapi_pblock_get( pb, SLAPI_PLUGIN_PRIVATE, &li );
- slapi_pblock_get( pb, SLAPI_ADD_ENTRY, &e );
- slapi_pblock_get( pb, SLAPI_REQUESTOR_ISROOT, &isroot );
- slapi_pblock_get( pb, SLAPI_MANAGEDSAIT, &managedsait );
- slapi_pblock_get( pb, SLAPI_TXN, (void**)&parent_txn );
- slapi_pblock_get( pb, SLAPI_OPERATION, &operation );
- slapi_pblock_get( pb, SLAPI_IS_REPLICATED_OPERATION, &is_replicated_operation );
- slapi_pblock_get( pb, SLAPI_BACKEND, &be);
- is_resurect_operation= operation_is_flag_set(operation,OP_FLAG_RESURECT_ENTRY);
- is_tombstone_operation= operation_is_flag_set(operation,OP_FLAG_TOMBSTONE_ENTRY);
- is_fixup_operation = operation_is_flag_set(operation, OP_FLAG_REPL_FIXUP);
- is_ruv = operation_is_flag_set(operation, OP_FLAG_REPL_RUV);
- inst = (ldbm_instance *) be->be_instance_info;
-
- /* sdn & parentsdn need to be initialized before "goto *_return" */
- slapi_sdn_init(&parentsdn);
-
- /* Get rid of ldbm backend attributes that you are not allowed to specify yourself */
- slapi_entry_delete_values( e, hassubordinates, NULL );
- slapi_entry_delete_values( e, numsubordinates, NULL );
- dblayer_txn_init(li,&txn);
- /* the calls to perform searches require the parent txn if any
- so set txn to the parent_txn until we begin the child transaction */
- if (parent_txn) {
- txn.back_txn_txn = parent_txn;
- } else {
- parent_txn = txn.back_txn_txn;
- slapi_pblock_set( pb, SLAPI_TXN, parent_txn );
- }
- /* The dblock serializes writes to the database,
- * which reduces deadlocking in the db code,
- * which means that we run faster.
- *
- * But, this lock is re-enterant for the fixup
- * operations that the URP code in the Replication
- * plugin generates.
- */
- if(SERIALLOCK(li) && (!is_fixup_operation || is_ruv))
- {
- dblayer_lock_backend(be);
- dblock_acquired= 1;
- }
- rc= 0;
- /*
- * We are about to pass the last abandon test, so from now on we are
- * committed to finish this operation. Set status to "will complete"
- * before we make our last abandon check to avoid race conditions in
- * the code that processes abandon operations.
- */
- if (operation) {
- operation->o_status = SLAPI_OP_STATUS_WILL_COMPLETE;
- }
- if ( slapi_op_abandoned( pb ) ) {
- ldap_result_code = -1; /* needs to distinguish from "success" */
- goto error_return;
- }
- if (!is_tombstone_operation) {
- rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_DN_ENTRY);
- }
- rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_UNIQUEID_ENTRY);
- rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_PARENT_ENTRY);
- while(rc!=0)
- {
- /* JCM - copying entries can be expensive... should optimize */
- /*
- * Some present state information is passed through the PBlock to the
- * backend pre-op plugin. To ensure a consistent snapshot of this state
- * we wrap the reading of the entry with the dblock.
- */
- if(slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_UNIQUEID_ENTRY))
- {
- /* Check if an entry with the intended uniqueid already exists. */
- done_with_pblock_entry(pb,SLAPI_ADD_EXISTING_UNIQUEID_ENTRY); /* Could be through this multiple times */
- addr.udn = NULL;
- addr.sdn = NULL;
- addr.uniqueid = (char*)slapi_entry_get_uniqueid(e); /* jcm - cast away const */
- ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_EXISTING_UNIQUEID_ENTRY, !is_replicated_operation);
- }
- if(slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_DN_ENTRY))
- {
- slapi_pblock_get( pb, SLAPI_ADD_TARGET_SDN, &sdn );
- if (NULL == sdn)
- {
- LDAPDebug0Args(LDAP_DEBUG_ANY, "ldbm_back_add: FETCH_EXISTING_DN_ENTRY is set, but target dn is NULL.\n");
- ldap_result_code = LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- /* not need to check the dn syntax as this is a replicated op */
- if(!is_replicated_operation){
- ldap_result_code = slapi_dn_syntax_check(pb, slapi_sdn_get_dn(sdn), 1);
- if (ldap_result_code)
- {
- ldap_result_code = LDAP_INVALID_DN_SYNTAX;
- slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
- goto error_return;
- }
- }
- /*
- * If the parent is conflict, slapi_sdn_get_backend_parent does not support it.
- * That is, adding children to a conflict entry is not allowed.
- */
- slapi_sdn_get_backend_parent(sdn, &parentsdn, pb->pb_backend);
- /* Check if an entry with the intended DN already exists. */
- done_with_pblock_entry(pb,SLAPI_ADD_EXISTING_DN_ENTRY); /* Could be through this multiple times */
- addr.sdn = sdn;
- addr.udn = NULL;
- addr.uniqueid = NULL;
- ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_EXISTING_DN_ENTRY, !is_replicated_operation);
- if ((ldap_result_code == LDAP_OPERATIONS_ERROR) || (ldap_result_code==LDAP_INVALID_DN_SYNTAX)) {
- goto error_return;
- }
- }
- /* if we can find the parent by dn or uniqueid, and the operation has requested the parent
- then get it */
- if (have_parent_address(&parentsdn, operation->o_params.p.p_add.parentuniqueid) &&
- slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_PARENT_ENTRY)) {
- done_with_pblock_entry(pb,SLAPI_ADD_PARENT_ENTRY); /* Could be through this multiple times */
- addr.sdn = &parentsdn;
- addr.udn = NULL;
- addr.uniqueid = operation->o_params.p.p_add.parentuniqueid;
- ldap_result_code = get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_PARENT_ENTRY,
- !is_replicated_operation);
- }
- /* Call the Backend Pre Add plugins */
- ldap_result_code = LDAP_SUCCESS;
- slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- rc = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_ADD_FN);
- if (rc == -1) {
- int opreturn = 0;
- /*
- * Plugin indicated some kind of failure,
- * or that this Operation became a No-Op.
- */
- if (!ldap_result_code) {
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- }
- if (!ldap_result_code) {
- LDAPDebug0Args(LDAP_DEBUG_ANY,
- "ldbm_back_add: SLAPI_PLUGIN_BE_PRE_ADD_FN returned error but did not set SLAPI_RESULT_CODE\n");
- ldap_result_code = LDAP_OPERATIONS_ERROR;
- }
- slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
- if (!opreturn) {
- /* make sure opreturn is set for the postop plugins */
- slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &rc);
- }
- goto error_return;
- }
- /*
- * (rc!=-1 && rc!= 0) means that the plugin changed things, so we go around
- * the loop once again to get the new present state.
- */
- /* JCMREPL - Warning: A Plugin could cause an infinite loop by always returning a result code that requires some action. */
- }
- /*
- * Originally (in the U-M LDAP 3.3 code), there was a comment near this
- * code about a race condition. The race was that a 2nd entry could be
- * added between the time when we check for an already existing entry
- * and the cache_add_entry_lock() call below. A race condition no
- * longer exists, because now we keep the parent entry locked for
- * the duration of the old race condition's window of opportunity.
- */
- /*
- * Fetch the parent entry and acquire the cache lock.
- */
- if(have_parent_address(&parentsdn, operation->o_params.p.p_add.parentuniqueid))
- {
- addr.sdn = &parentsdn;
- addr.udn = NULL;
- addr.uniqueid = operation->o_params.p.p_add.parentuniqueid;
- parententry = find_entry2modify_only(pb,be,&addr,&txn);
- if (parententry && parententry->ep_entry) {
- if (!operation->o_params.p.p_add.parentuniqueid){
- /* Set the parentuniqueid now */
- operation->o_params.p.p_add.parentuniqueid = slapi_ch_strdup(slapi_entry_get_uniqueid(parententry->ep_entry));
- }
- if (slapi_sdn_isempty(&parentsdn) ||
- slapi_sdn_compare(&parentsdn, slapi_entry_get_sdn(parententry->ep_entry))) {
- /* Set the parentsdn now */
- slapi_sdn_set_dn_byval(&parentsdn, slapi_entry_get_dn_const(parententry->ep_entry));
- }
- } else {
- LDAPDebug2Args(LDAP_DEBUG_BACKLDBM, "find_entry2modify_only returned NULL parententry pdn: %s, uniqueid: %s\n",
- slapi_sdn_get_dn(&parentsdn), addr.uniqueid?addr.uniqueid:"none");
- }
- modify_init(&parent_modify_c,parententry);
- }
- /* Check if the entry we have been asked to add already exists */
- {
- Slapi_Entry *entry;
- slapi_pblock_get(pb, SLAPI_ADD_EXISTING_DN_ENTRY, &entry);
- if (entry) {
- if (is_resurect_operation) {
- Slapi_Entry *uniqentry;
- slapi_pblock_get(pb, SLAPI_ADD_EXISTING_UNIQUEID_ENTRY, &uniqentry);
- if (uniqentry == entry) {
- /*
- * adding entry having the uniqueid exists.
- * No need to resurrect.
- */
- ldap_result_code = LDAP_SUCCESS;
- } else {
- /*
- * The entry having the DN already exists.
- * But the
- */
- if (uniqentry) {
- if (PL_strcmp(slapi_entry_get_uniqueid(entry),
- slapi_entry_get_uniqueid(uniqentry))) {
- /* Not match; conflict. */
- ldap_result_code = LDAP_ALREADY_EXISTS;
- } else {
- /* Same entry; no need to resurrect. */
- ldap_result_code = LDAP_SUCCESS;
- }
- } else {
- ldap_result_code = LDAP_ALREADY_EXISTS;
- }
- }
- } else {
- /* The entry already exists */
- ldap_result_code = LDAP_ALREADY_EXISTS;
- }
- goto error_return;
- }
- else
- {
- /*
- * did not find the entry - this is good, since we're
- * trying to add it, but we have to check whether the
- * entry we did match has a referral we should return
- * instead. we do this only if managedsait is not on.
- */
- if (!managedsait && !is_tombstone_operation && !is_resurect_operation)
- {
- int err= 0;
- Slapi_DN ancestorsdn;
- struct backentry *ancestorentry;
- slapi_sdn_init(&ancestorsdn);
- ancestorentry= dn2ancestor(pb->pb_backend,sdn,&ancestorsdn,&txn,&err);
- slapi_sdn_done(&ancestorsdn);
- if ( ancestorentry != NULL )
- {
- int sentreferral= check_entry_for_referral(pb, ancestorentry->ep_entry, backentry_get_ndn(ancestorentry), "ldbm_back_add");
- CACHE_RETURN( &inst->inst_cache, &ancestorentry );
- if(sentreferral)
- {
- ldap_result_code= -1; /* The result was sent by check_entry_for_referral */
- goto error_return;
- }
- }
- }
- }
- }
- /* no need to check the schema as this is a replication add */
- if(!is_replicated_operation){
- if ((operation_is_flag_set(operation,OP_FLAG_ACTION_SCHEMA_CHECK)) && slapi_entry_schema_check(pb, e) != 0)
- {
- LDAPDebug(LDAP_DEBUG_TRACE, "entry failed schema check\n", 0, 0, 0);
- ldap_result_code = LDAP_OBJECT_CLASS_VIOLATION;
- slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
- goto error_return;
- }
- /* Check attribute syntax */
- if (slapi_entry_syntax_check(pb, e, 0) != 0)
- {
- LDAPDebug(LDAP_DEBUG_TRACE, "entry failed syntax check\n", 0, 0, 0);
- ldap_result_code = LDAP_INVALID_SYNTAX;
- slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
- goto error_return;
- }
- }
- opcsn = operation_get_csn (operation);
- if(is_resurect_operation)
- {
- char *reason = NULL;
- /*
- * When we resurect a tombstone we must use its UniqueID
- * to find the tombstone entry and lock it down in the cache.
- */
- addr.udn = NULL;
- addr.sdn = NULL;
- addr.uniqueid = (char *)slapi_entry_get_uniqueid(e); /* jcm - cast away const */
- tombstoneentry = find_entry2modify( pb, be, &addr, &txn );
- if ( tombstoneentry==NULL )
- {
- ldap_result_code= -1;
- goto error_return; /* error result sent by find_entry2modify() */
- }
- addingentry = backentry_dup( tombstoneentry );
- if ( addingentry==NULL )
- {
- ldap_result_code = LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- /*
- * To resurect a tombstone we must fix its DN and remove the
- * parent UniqueID that we stashed in there.
- *
- * The entry comes back to life as a Glue entry, so we add the
- * magic objectclass.
- */
- if (NULL == sdn) {
- LDAPDebug0Args(LDAP_DEBUG_ANY, "ldbm_back_add: Null target dn\n");
- ldap_result_code = LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- slapi_entry_set_sdn(addingentry->ep_entry, sdn); /* The DN is passed into the entry. */
- /* not just e_sdn, e_rsdn needs to be updated. */
- slapi_rdn_set_all_dn(slapi_entry_get_srdn(addingentry->ep_entry),
- slapi_entry_get_dn_const(addingentry->ep_entry));
- /* LPREPL: the DN is normalized...Somehow who should get a not normalized one */
- addingentry->ep_id = slapi_entry_attr_get_ulong(addingentry->ep_entry,"entryid");
- slapi_entry_attr_delete(addingentry->ep_entry, SLAPI_ATTR_VALUE_PARENT_UNIQUEID);
- slapi_entry_delete_string(addingentry->ep_entry, SLAPI_ATTR_OBJECTCLASS, SLAPI_ATTR_VALUE_TOMBSTONE);
- /* Now also remove the nscpEntryDN */
- if (slapi_entry_attr_delete(addingentry->ep_entry, SLAPI_ATTR_NSCP_ENTRYDN) != 0){
- LDAPDebug(LDAP_DEBUG_REPL, "Resurrection of %s - Couldn't remove %s\n",
- slapi_sdn_get_dn(sdn), SLAPI_ATTR_NSCP_ENTRYDN, 0);
- }
-
- /* And copy the reason from e */
- reason = slapi_entry_attr_get_charptr(e, "nsds5ReplConflict");
- if (reason) {
- if (!slapi_entry_attr_hasvalue(addingentry->ep_entry, "nsds5ReplConflict", reason)) {
- slapi_entry_add_string(addingentry->ep_entry, "nsds5ReplConflict", reason);
- LDAPDebug(LDAP_DEBUG_REPL, "Resurrection of %s - Added Conflict reason %s\n",
- slapi_sdn_get_dn(sdn), reason, 0);
- }
- slapi_ch_free((void **)&reason);
- }
- /* Clear the Tombstone Flag in the entry */
- slapi_entry_clear_flag(addingentry->ep_entry, SLAPI_ENTRY_FLAG_TOMBSTONE);
- /* make sure the objectclass
- - does not contain any duplicate values
- - has CSNs for the new values we added
- */
- {
- Slapi_Attr *sa = NULL;
- Slapi_Value sv;
- const struct berval *svbv = NULL;
- /* add the extensibleobject objectclass with csn if not present */
- slapi_entry_attr_find(addingentry->ep_entry, SLAPI_ATTR_OBJECTCLASS, &sa);
- slapi_value_init_string(&sv, "extensibleobject");
- svbv = slapi_value_get_berval(&sv);
- if (slapi_attr_value_find(sa, svbv)) { /* not found, so add it */
- if (opcsn) {
- value_update_csn(&sv, CSN_TYPE_VALUE_UPDATED, opcsn);
- }
- slapi_attr_add_value(sa, &sv);
- }
- value_done(&sv);
-
- /* add the glue objectclass with csn if not present */
- slapi_value_init_string(&sv, "glue");
- svbv = slapi_value_get_berval(&sv);
- if (slapi_attr_value_find(sa, svbv)) { /* not found, so add it */
- if (opcsn) {
- value_update_csn(&sv, CSN_TYPE_VALUE_UPDATED, opcsn);
- }
- slapi_attr_add_value(sa, &sv);
- }
- value_done(&sv);
- }
- }
- else
- {
- /*
- * Try to add the entry to the cache, assign it a new entryid
- * and mark it locked. This should only fail if the entry
- * already exists.
- */
- /*
- * next_id will add this id to the list of ids that are pending
- * id2entry indexing.
- */
- addingentry = backentry_init( e );
- if ( ( addingentry->ep_id = next_id( be ) ) >= MAXID ) {
- LDAPDebug( LDAP_DEBUG_ANY,
- "add: maximum ID reached, cannot add entry to "
- "backend '%s'", be->be_name, 0, 0 );
- ldap_result_code = LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- addingentry_id_assigned= 1;
- if (!is_fixup_operation)
- {
- if ( opcsn == NULL && operation->o_csngen_handler )
- {
- /*
- * Current op is a user request. Opcsn will be assigned
- * if the dn is in an updatable replica.
- */
- opcsn = entry_assign_operation_csn ( pb, e, parententry ? parententry->ep_entry : NULL );
- }
- if ( opcsn != NULL )
- {
- entry_set_csn (e, opcsn);
- entry_add_dncsn (e, opcsn);
- entry_add_rdn_csn (e, opcsn);
- entry_set_maxcsn (e, opcsn);
- }
- }
- if (is_tombstone_operation)
- {
- /* Directly add the entry as a tombstone */
- /*
- * 1) If the entry has an existing DN, change it to be
- * "nsuniqueid=<uniqueid>, <old dn>"
- * 2) Add the objectclass value "tombstone" and arrange for only
- * that value to be indexed.
- * 3) If the parent entry was found, set the nsparentuniqueid
- * attribute to be the unique id of that parent.
- */
- char *untombstoned_dn = slapi_entry_get_dn(e);
- char *tombstoned_dn = NULL;
- if (NULL == untombstoned_dn)
- {
- untombstoned_dn = "";
- }
- tombstoned_dn = compute_entry_tombstone_dn(untombstoned_dn, addr.uniqueid);
- /*
- * This needs to be done before slapi_entry_set_dn call,
- * because untombstoned_dn is released in slapi_entry_set_dn.
- */
- if (entryrdn_get_switch())
- {
- Slapi_RDN srdn = {0};
- rc = slapi_rdn_init_all_dn(&srdn, tombstoned_dn);
- if (rc) {
- LDAPDebug1Arg( LDAP_DEBUG_TRACE,
- "ldbm_back_add (tombstone_operation): failed to "
- "decompose %s to Slapi_RDN\n", tombstoned_dn);
- } else {
- slapi_entry_set_srdn(e, &srdn);
- slapi_rdn_done(&srdn);
- }
- }
- slapi_entry_set_dn(addingentry->ep_entry, tombstoned_dn);
- /* Work around pb with slapi_entry_add_string (defect 522327)
- * doesn't check duplicate values */
- if (!slapi_entry_attr_hasvalue(addingentry->ep_entry,
- SLAPI_ATTR_OBJECTCLASS, SLAPI_ATTR_VALUE_TOMBSTONE)) {
- slapi_entry_add_string(addingentry->ep_entry,
- SLAPI_ATTR_OBJECTCLASS, SLAPI_ATTR_VALUE_TOMBSTONE);
- slapi_entry_set_flag(addingentry->ep_entry,
- SLAPI_ENTRY_FLAG_TOMBSTONE);
- }
- if (NULL != operation->o_params.p.p_add.parentuniqueid)
- {
- slapi_entry_add_string(addingentry->ep_entry,
- SLAPI_ATTR_VALUE_PARENT_UNIQUEID,
- operation->o_params.p.p_add.parentuniqueid);
- }
- }
- }
- /*
- * Get the parent dn and see if the corresponding entry exists.
- * If the parent does not exist, only allow the "root" user to
- * add the entry.
- */
- if ( !slapi_sdn_isempty(&parentsdn) )
- {
- /* This is getting the parent */
- if (NULL == parententry)
- {
- /* Here means that we didn't find the parent */
- int err = 0;
- Slapi_DN ancestorsdn;
- struct backentry *ancestorentry;
- LDAPDebug1Arg(LDAP_DEBUG_BACKLDBM, "ldbm_add: Parent \"%s\" does not exist. "
- "It might be a conflict entry.\n", slapi_sdn_get_dn(&parentsdn));
- slapi_sdn_init(&ancestorsdn);
- ancestorentry = dn2ancestor(be, &parentsdn, &ancestorsdn, &txn, &err );
- CACHE_RETURN( &inst->inst_cache, &ancestorentry );
- ldap_result_code= LDAP_NO_SUCH_OBJECT;
- ldap_result_matcheddn= slapi_ch_strdup((char *)slapi_sdn_get_dn(&ancestorsdn)); /* jcm - cast away const. */
- slapi_sdn_done(&ancestorsdn);
- goto error_return;
- }
- ldap_result_code = plugin_call_acl_plugin(pb, e, NULL, NULL, SLAPI_ACL_ADD,
- ACLPLUGIN_ACCESS_DEFAULT, &errbuf );
- if ( ldap_result_code != LDAP_SUCCESS )
- {
- LDAPDebug1Arg(LDAP_DEBUG_TRACE, "no access to parent, pdn = %s\n",
- slapi_sdn_get_dn(&parentsdn));
- ldap_result_message= errbuf;
- goto error_return;
- }
- pid = parententry->ep_id;
- /* We may need to adjust the DN since parent could be a resrected conflict entry... */
- if (!slapi_sdn_isparent(slapi_entry_get_sdn_const(parententry->ep_entry),
- slapi_entry_get_sdn_const(addingentry->ep_entry))) {
- Slapi_DN adjustedsdn = {0};
- char *adjusteddn = slapi_ch_smprintf("%s,%s",
- slapi_entry_get_rdn_const(addingentry->ep_entry),
- slapi_entry_get_dn_const(parententry->ep_entry));
- LDAPDebug2Args(LDAP_DEBUG_BACKLDBM, "ldbm_add: adjusting dn: %s --> %s\n",
- slapi_entry_get_dn(addingentry->ep_entry), adjusteddn);
- slapi_sdn_set_normdn_passin(&adjustedsdn, adjusteddn);
- slapi_entry_set_sdn(addingentry->ep_entry, &adjustedsdn);
- /* not just e_sdn, e_rsdn needs to be updated. */
- slapi_rdn_set_all_dn(slapi_entry_get_srdn(addingentry->ep_entry), adjusteddn);
- slapi_sdn_done(&adjustedsdn);
- }
- }
- else
- { /* no parent */
- if (!isroot && !is_replicated_operation)
- {
- LDAPDebug0Args(LDAP_DEBUG_TRACE, "no parent & not root\n");
- ldap_result_code= LDAP_INSUFFICIENT_ACCESS;
- goto error_return;
- }
- parententry = NULL;
- pid = 0;
- }
-
- if(is_resurect_operation)
- {
- add_update_entrydn_operational_attributes(addingentry);
- }
- else if (is_tombstone_operation)
- {
- /* Remove the entrydn operational attributes from the addingentry */
- delete_update_entrydn_operational_attributes(addingentry);
- }
- else
- {
- /*
- * add the parentid, entryid and entrydn operational attributes
- */
- add_update_entry_operational_attributes(addingentry, pid);
- }
- /* Tentatively add the entry to the cache. We do this after adding any
- * operational attributes to ensure that the cache is sized correctly. */
- if ( cache_add_tentative( &inst->inst_cache, addingentry, NULL ) < 0 )
- {
- LDAPDebug1Arg(LDAP_DEBUG_CACHE, "cache_add_tentative concurrency detected: %s\n",
- slapi_entry_get_dn_const(addingentry->ep_entry));
- ldap_result_code= LDAP_ALREADY_EXISTS;
- goto error_return;
- }
- /*
- * Before we add the entry, find out if the syntax of the aci
- * aci attribute values are correct or not. We don't want to
- * the entry if the syntax is incorrect.
- */
- if ( plugin_call_acl_verify_syntax (pb, addingentry->ep_entry, &errbuf) != 0 ) {
- LDAPDebug1Arg(LDAP_DEBUG_TRACE, "ACL syntax error: %s\n",
- slapi_entry_get_dn_const(addingentry->ep_entry));
- ldap_result_code= LDAP_INVALID_SYNTAX;
- ldap_result_message= errbuf;
- goto error_return;
- }
- /* Having decided that we're really going to do the operation, let's modify
- the in-memory state of the parent to reflect the new child (update
- subordinate count specifically */
- if (parententry)
- {
- retval = parent_update_on_childchange(&parent_modify_c,
- is_resurect_operation?PARENTUPDATE_RESURECT:PARENTUPDATE_ADD,
- NULL);
- /* The modify context now contains info needed later */
- if (retval) {
- LDAPDebug2Args(LDAP_DEBUG_BACKLDBM, "parent_update_on_childchange: %s, rc=%d\n",
- slapi_entry_get_dn_const(addingentry->ep_entry), retval);
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- parent_found = 1;
- parententry = NULL;
- }
- if ( (originalentry = backentry_dup(addingentry )) == NULL ) {
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- /*
- * So, we believe that no code up till here actually added anything
- * to persistent store. From now on, we're transacted
- */
- txn.back_txn_txn = NULL; /* ready to create the child transaction */
- for (retry_count = 0; retry_count < RETRY_TIMES; retry_count++) {
- if (txn.back_txn_txn && (txn.back_txn_txn != parent_txn)) {
- dblayer_txn_abort(li,&txn);
- noabort = 1;
- slapi_pblock_set(pb, SLAPI_TXN, parent_txn);
- /* must duplicate addingentry before returning it to cache,
- * which could free the entry. */
- if ( (tmpentry = backentry_dup( addingentry )) == NULL ) {
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- if (cache_is_in_cache(&inst->inst_cache, addingentry)) {
- /* addingentry is in cache. Remove it once. */
- retval = CACHE_REMOVE(&inst->inst_cache, addingentry);
- if (retval) {
- LDAPDebug1Arg(LDAP_DEBUG_CACHE, "ldbm_add: cache_remove %s failed.\n",
- slapi_entry_get_dn_const(addingentry->ep_entry));
- }
- }
- CACHE_RETURN(&inst->inst_cache, &addingentry);
- slapi_pblock_set( pb, SLAPI_ADD_ENTRY, originalentry->ep_entry );
- addingentry = originalentry;
- originalentry = tmpentry;
- tmpentry = NULL;
- /* Adding the resetted addingentry to the cache. */
- if (cache_add_tentative(&inst->inst_cache, addingentry, NULL) < 0) {
- LDAPDebug1Arg(LDAP_DEBUG_CACHE, "cache_add_tentative concurrency detected: %s\n",
- slapi_entry_get_dn_const(addingentry->ep_entry));
- ldap_result_code = LDAP_ALREADY_EXISTS;
- goto error_return;
- }
- if (ruv_c_init) {
- /* reset the ruv txn stuff */
- modify_term(&ruv_c, be);
- ruv_c_init = 0;
- }
- /* We're re-trying */
- LDAPDebug0Args(LDAP_DEBUG_BACKLDBM, "Add Retrying Transaction\n");
- #ifndef LDBM_NO_BACKOFF_DELAY
- {
- PRIntervalTime interval;
- interval = PR_MillisecondsToInterval(slapi_rand() % 100);
- DS_Sleep(interval);
- }
- #endif
- }
- retval = dblayer_txn_begin(li,parent_txn,&txn);
- if (0 != retval) {
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) {
- disk_full = 1;
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto diskfull_return;
- }
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- noabort = 0;
- /* stash the transaction for plugins */
- slapi_pblock_set(pb, SLAPI_TXN, txn.back_txn_txn);
- /* call the transaction pre add plugins just after creating the transaction */
- if ((retval = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN))) {
- int opreturn = 0;
- LDAPDebug1Arg(LDAP_DEBUG_TRACE, "SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN plugin "
- "returned error code %d\n", retval );
- if (!ldap_result_code) {
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- }
- if (!ldap_result_code) {
- ldap_result_code = LDAP_OPERATIONS_ERROR;
- slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- }
- slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
- if (!opreturn) {
- slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &retval);
- }
- LDAPDebug1Arg(LDAP_DEBUG_ANY, "SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN plugin failed: %d",
- ldap_result_code ? ldap_result_code : retval);
- goto error_return;
- }
- retval = id2entry_add( be, addingentry, &txn );
- if (DB_LOCK_DEADLOCK == retval)
- {
- LDAPDebug( LDAP_DEBUG_ARGS, "add 1 DEADLOCK\n", 0, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (retval) {
- LDAPDebug(LDAP_DEBUG_TRACE, "id2entry_add(%s) failed, err=%d %s\n",
- slapi_entry_get_dn_const(addingentry->ep_entry),
- retval, (msg = dblayer_strerror( retval )) ? msg : "");
- ADD_SET_ERROR(ldap_result_code, LDAP_OPERATIONS_ERROR, retry_count);
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) {
- disk_full = 1;
- goto diskfull_return;
- }
- goto error_return;
- }
- if(is_resurect_operation)
- {
- retval = index_addordel_string(be,SLAPI_ATTR_OBJECTCLASS,SLAPI_ATTR_VALUE_TOMBSTONE,addingentry->ep_id,BE_INDEX_DEL,&txn);
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug( LDAP_DEBUG_ARGS, "add 2 DB_LOCK_DEADLOCK\n", 0, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (retval) {
- LDAPDebug(LDAP_DEBUG_TRACE, "index_addordel_string TOMBSTONE (%s), err=%d %s\n",
- slapi_entry_get_dn_const(addingentry->ep_entry),
- retval, (msg = dblayer_strerror( retval )) ? msg : "");
- ADD_SET_ERROR(ldap_result_code, LDAP_OPERATIONS_ERROR, retry_count);
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) {
- disk_full = 1;
- goto diskfull_return;
- }
- goto error_return;
- }
- retval = index_addordel_string(be,SLAPI_ATTR_UNIQUEID,slapi_entry_get_uniqueid(addingentry->ep_entry),addingentry->ep_id,BE_INDEX_DEL,&txn);
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug( LDAP_DEBUG_ARGS, "add 3 DB_LOCK_DEADLOCK\n", 0, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug(LDAP_DEBUG_TRACE, "index_addordel_string UNIQUEID (%s), err=%d %s\n",
- slapi_entry_get_dn_const(addingentry->ep_entry),
- retval, (msg = dblayer_strerror( retval )) ? msg : "");
- ADD_SET_ERROR(ldap_result_code, LDAP_OPERATIONS_ERROR, retry_count);
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) {
- disk_full = 1;
- goto diskfull_return;
- }
- goto error_return;
- }
- retval = index_addordel_string(be,
- SLAPI_ATTR_NSCP_ENTRYDN,
- slapi_sdn_get_ndn(sdn),
- addingentry->ep_id,
- BE_INDEX_DEL, &txn);
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug( LDAP_DEBUG_ARGS, "add 4 DB_LOCK_DEADLOCK\n", 0, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug(LDAP_DEBUG_TRACE, "index_addordel_string ENTRYDN (%s), err=%d %s\n",
- slapi_entry_get_dn_const(addingentry->ep_entry),
- retval, (msg = dblayer_strerror( retval )) ? msg : "");
- ADD_SET_ERROR(ldap_result_code, LDAP_OPERATIONS_ERROR, retry_count);
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) {
- disk_full = 1;
- goto diskfull_return;
- }
- goto error_return;
- }
- /* Need to delete the entryrdn index of the resurrected tombstone... */
- if (entryrdn_get_switch()) { /* subtree-rename: on */
- if (tombstoneentry) {
- retval = entryrdn_index_entry(be, tombstoneentry, BE_INDEX_DEL, &txn);
- if (retval) {
- LDAPDebug(LDAP_DEBUG_ANY, "Resurrecting %s: failed to remove entryrdn index, err=%d %s\n",
- slapi_entry_get_dn_const(tombstoneentry->ep_entry),
- retval, (msg = dblayer_strerror( retval )) ? msg : "");
- goto error_return;
- }
- }
- }
- }
- if (is_tombstone_operation)
- {
- retval = index_addordel_entry( be, addingentry, BE_INDEX_ADD | BE_INDEX_TOMBSTONE, &txn );
- }
- else
- {
- retval = index_addordel_entry( be, addingentry, BE_INDEX_ADD, &txn );
- }
- if (DB_LOCK_DEADLOCK == retval)
- {
- LDAPDebug( LDAP_DEBUG_ARGS, "add 5 DEADLOCK\n", 0, 0, 0 );
- /* retry txn */
- continue;
- }
- if (retval) {
- LDAPDebug2Args(LDAP_DEBUG_ANY, "add: attempt to index %lu failed; rc=%d\n",
- (u_long)addingentry->ep_id, retval);
- ADD_SET_ERROR(ldap_result_code, LDAP_OPERATIONS_ERROR, retry_count);
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) {
- disk_full = 1;
- goto diskfull_return;
- }
- goto error_return;
- }
- if (parent_found) {
- /* Push out the db modifications from the parent entry */
- retval = modify_update_all(be,pb,&parent_modify_c,&txn);
- if (DB_LOCK_DEADLOCK == retval)
- {
- LDAPDebug( LDAP_DEBUG_ARGS, "add 6 DEADLOCK\n", 0, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (retval) {
- LDAPDebug(LDAP_DEBUG_BACKLDBM, "modify_update_all: %s (%lu) failed; rc=%d\n",
- slapi_entry_get_dn(addingentry->ep_entry), (u_long)addingentry->ep_id, retval);
- ADD_SET_ERROR(ldap_result_code, LDAP_OPERATIONS_ERROR, retry_count);
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) {
- disk_full = 1;
- goto diskfull_return;
- }
- goto error_return;
- }
- }
- /*
- * Update the Virtual List View indexes
- */
- if (!is_ruv)
- {
- retval= vlv_update_all_indexes(&txn, be, pb, NULL, addingentry);
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug(LDAP_DEBUG_ARGS,
- "add DEADLOCK vlv_update_index\n", 0, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (retval) {
- LDAPDebug2Args(LDAP_DEBUG_TRACE,
- "vlv_update_index failed, err=%d %s\n",
- retval, (msg = dblayer_strerror( retval )) ? msg : "");
- ADD_SET_ERROR(ldap_result_code, LDAP_OPERATIONS_ERROR, retry_count);
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) {
- disk_full = 1;
- goto diskfull_return;
- }
- goto error_return;
- }
- }
- if (!is_ruv && !is_fixup_operation) {
- ruv_c_init = ldbm_txn_ruv_modify_context( pb, &ruv_c );
- if (-1 == ruv_c_init) {
- LDAPDebug( LDAP_DEBUG_ANY,
- "ldbm_back_add: ldbm_txn_ruv_modify_context "
- "failed to construct RUV modify context\n",
- 0, 0, 0);
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- retval = 0;
- goto error_return;
- }
- }
- if (ruv_c_init) {
- retval = modify_update_all( be, pb, &ruv_c, &txn );
- if (DB_LOCK_DEADLOCK == retval) {
- /* Abort and re-try */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_ANY,
- "modify_update_all failed, err=%d %s\n", retval,
- (msg = dblayer_strerror( retval )) ? msg : "", 0 );
- if (LDBM_OS_ERR_IS_DISKFULL(retval))
- disk_full = 1;
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- }
- if (retval == 0) {
- break;
- }
- }
- if (retry_count == RETRY_TIMES) {
- /* Failed */
- LDAPDebug( LDAP_DEBUG_ANY, "Retry count exceeded in add\n", 0, 0, 0 );
- ldap_result_code= LDAP_BUSY;
- goto error_return;
- }
- /*
- * At this point, everything's cool, and the only thing which
- * can go wrong is a transaction commit failure.
- */
- slapi_pblock_set( pb, SLAPI_ENTRY_PRE_OP, NULL );
- slapi_pblock_set( pb, SLAPI_ENTRY_POST_OP, slapi_entry_dup( addingentry->ep_entry ));
- if(is_resurect_operation)
- {
- /*
- * We can now switch the tombstone entry with the real entry.
- */
- retval = cache_replace(&inst->inst_cache, tombstoneentry, addingentry);
- if (retval) {
- /* This happens if the dn of addingentry already exists */
- ADD_SET_ERROR(ldap_result_code, LDAP_ALREADY_EXISTS, retry_count);
- LDAPDebug2Args(LDAP_DEBUG_CACHE, "ldap_add: cache_replace concurrency detected: %s (rc: %d)\n",
- slapi_entry_get_dn_const(addingentry->ep_entry), retval);
- retval = -1;
- goto error_return;
- }
- /*
- * The tombstone was locked down in the cache... we can
- * get rid of the entry in the cache now.
- * We cannot expect tombstoneentry exists from now on.
- */
- if (entryrdn_get_switch()) { /* subtree-rename: on */
- /* since the op was successful, delete the tombstone dn from the dn cache */
- struct backdn *bdn = dncache_find_id(&inst->inst_dncache,
- tombstoneentry->ep_id);
- if (bdn) { /* in the dncache, remove it. */
- CACHE_REMOVE(&inst->inst_dncache, bdn);
- CACHE_RETURN(&inst->inst_dncache, &bdn);
- }
- }
- }
- if (parent_found)
- {
- /* switch the parent entry copy into play */
- modify_switch_entries(&parent_modify_c,be);
- parent_switched = 1;
- }
- if (ruv_c_init) {
- if (modify_switch_entries(&ruv_c, be) != 0 ) {
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- LDAPDebug0Args(LDAP_DEBUG_ANY,
- "ldbm_back_add: modify_switch_entries failed\n");
- goto error_return;
- }
- }
- /* call the transaction post add plugins just before the commit */
- if ((retval = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_POST_ADD_FN))) {
- int opreturn = 0;
- LDAPDebug1Arg( LDAP_DEBUG_TRACE, "SLAPI_PLUGIN_BE_TXN_POST_ADD_FN plugin "
- "returned error code %d\n", retval );
- if (!ldap_result_code) {
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- }
- if (!ldap_result_code) {
- ldap_result_code = LDAP_OPERATIONS_ERROR;
- slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- }
- slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
- if (!opreturn) {
- slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &retval);
- }
- goto error_return;
- }
- retval = dblayer_txn_commit(li,&txn);
- /* after commit - txn is no longer valid - replace SLAPI_TXN with parent */
- slapi_pblock_set(pb, SLAPI_TXN, parent_txn);
- if (0 != retval)
- {
- ADD_SET_ERROR(ldap_result_code, LDAP_OPERATIONS_ERROR, retry_count);
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) {
- disk_full = 1;
- goto diskfull_return;
- }
- goto error_return;
- }
- rc= 0;
- goto common_return;
- error_return:
- if ( addingentry_id_assigned )
- {
- next_id_return( be, addingentry->ep_id );
- }
- if (rc == DB_RUNRECOVERY) {
- dblayer_remember_disk_filled(li);
- ldbm_nasty("Add",80,rc);
- disk_full = 1;
- } else if (0 == rc) {
- rc = SLAPI_FAIL_GENERAL;
- }
- if (parent_switched){
- /*
- * Restore the old parent entry, switch the new with the original.
- * Otherwise the numsubordinate count will be off, and could later
- * be written to disk.
- */
- modify_unswitch_entries( &parent_modify_c,be);
- }
- diskfull_return:
- if (disk_full) {
- if ( addingentry )
- {
- if (inst && cache_is_in_cache(&inst->inst_cache, addingentry)) {
- CACHE_REMOVE(&inst->inst_cache, addingentry);
- /* tell frontend not to free this entry */
- slapi_pblock_set(pb, SLAPI_ADD_ENTRY, NULL);
- }
- else if (!cache_has_otherref(&inst->inst_cache, addingentry))
- {
- if (!is_resurect_operation) { /* if resurect, tombstoneentry is dupped. */
- backentry_clear_entry(addingentry); /* e is released in the frontend */
- }
- }
- CACHE_RETURN( &inst->inst_cache, &addingentry );
- }
- rc = return_on_disk_full(li);
- } else {
- /* It is safer not to abort when the transaction is not started. */
- if (txn.back_txn_txn && (txn.back_txn_txn != parent_txn)) {
- /* make sure SLAPI_RESULT_CODE and SLAPI_PLUGIN_OPRETURN are set */
- int val = 0;
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &val);
- if (!val) {
- if (!ldap_result_code) {
- ldap_result_code = LDAP_OPERATIONS_ERROR;
- }
- slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- }
- slapi_pblock_get( pb, SLAPI_PLUGIN_OPRETURN, &val );
- if (!val) {
- val = -1;
- slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN, &val );
- }
- /* call the transaction post add plugins just before the abort */
- if ((retval = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_POST_ADD_FN))) {
- int opreturn = 0;
- LDAPDebug1Arg( LDAP_DEBUG_TRACE, "SLAPI_PLUGIN_BE_TXN_POST_ADD_FN plugin "
- "returned error code %d\n", retval );
- if (!ldap_result_code) {
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- }
- slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
- if (!opreturn) {
- opreturn = -1;
- slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
- }
- slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
- }
- if ( addingentry ) {
- if (inst && cache_is_in_cache(&inst->inst_cache, addingentry)) {
- CACHE_REMOVE(&inst->inst_cache, addingentry);
- /* tell frontend not to free this entry */
- slapi_pblock_set(pb, SLAPI_ADD_ENTRY, NULL);
- }
- else if (!cache_has_otherref(&inst->inst_cache, addingentry))
- {
- if (!is_resurect_operation) { /* if resurect, tombstoneentry is dupped. */
- backentry_clear_entry(addingentry); /* e is released in the frontend */
- }
- }
- CACHE_RETURN( &inst->inst_cache, &addingentry );
- }
- if (!noabort) {
- dblayer_txn_abort(li,&txn); /* abort crashes in case disk full */
- }
- /* txn is no longer valid - reset the txn pointer to the parent */
- slapi_pblock_set(pb, SLAPI_TXN, parent_txn);
- } else {
- if ( addingentry ) {
- if (inst && cache_is_in_cache(&inst->inst_cache, addingentry)) {
- CACHE_REMOVE(&inst->inst_cache, addingentry);
- /* tell frontend not to free this entry */
- slapi_pblock_set(pb, SLAPI_ADD_ENTRY, NULL);
- }
- else if (!cache_has_otherref(&inst->inst_cache, addingentry))
- {
- if (!is_resurect_operation) { /* if resurect, tombstoneentry is dupped. */
- backentry_clear_entry(addingentry); /* e is released in the frontend */
- }
- }
- CACHE_RETURN( &inst->inst_cache, &addingentry );
- }
- }
- rc = SLAPI_FAIL_GENERAL;
- }
-
- common_return:
- if (inst) {
- if (tombstoneentry && cache_is_in_cache(&inst->inst_cache, tombstoneentry)) {
- cache_unlock_entry(&inst->inst_cache, tombstoneentry);
- CACHE_RETURN(&inst->inst_cache, &tombstoneentry);
- }
- if (addingentry) {
- if ((0 == retval) && entryrdn_get_switch()) { /* subtree-rename: on */
- /* since adding the entry to the entry cache was successful,
- * let's add the dn to dncache, if not yet done. */
- struct backdn *bdn = dncache_find_id(&inst->inst_dncache,
- addingentry->ep_id);
- if (bdn) { /* already in the dncache */
- CACHE_RETURN(&inst->inst_dncache, &bdn);
- } else { /* not in the dncache yet */
- Slapi_DN *addingsdn = slapi_sdn_dup(slapi_entry_get_sdn(addingentry->ep_entry));
- if (addingsdn) {
- bdn = backdn_init(addingsdn, addingentry->ep_id, 0);
- if (bdn) {
- CACHE_ADD( &inst->inst_dncache, bdn, NULL );
- CACHE_RETURN(&inst->inst_dncache, &bdn);
- slapi_log_error(SLAPI_LOG_CACHE, "ldbm_back_add",
- "set %s to dn cache\n", dn);
- }
- }
- }
- }
- CACHE_RETURN( &inst->inst_cache, &addingentry );
- }
- }
- /* bepost op needs to know this result */
- slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- /* JCMREPL - The bepostop is called even if the operation fails. */
- plugin_call_plugins (pb, SLAPI_PLUGIN_BE_POST_ADD_FN);
- if (ruv_c_init) {
- modify_term(&ruv_c, be);
- }
- modify_term(&parent_modify_c,be);
- done_with_pblock_entry(pb,SLAPI_ADD_EXISTING_DN_ENTRY);
- done_with_pblock_entry(pb,SLAPI_ADD_EXISTING_UNIQUEID_ENTRY);
- done_with_pblock_entry(pb,SLAPI_ADD_PARENT_ENTRY);
- if(dblock_acquired)
- {
- dblayer_unlock_backend(be);
- }
- if(ldap_result_code!=-1)
- {
- slapi_send_ldap_result( pb, ldap_result_code, ldap_result_matcheddn, ldap_result_message, 0, NULL );
- }
- backentry_free(&originalentry);
- backentry_free(&tmpentry);
- slapi_sdn_done(&parentsdn);
- slapi_ch_free( (void**)&ldap_result_matcheddn );
- slapi_ch_free( (void**)&errbuf );
- return rc;
- }
- /*
- * add the parentid, entryid and entrydn, operational attributes.
- *
- * Note: This is called from the ldif2ldbm code.
- */
- void
- add_update_entry_operational_attributes(struct backentry *ep, ID pid)
- {
- struct berval bv;
- struct berval *bvp[2];
- char buf[40]; /* Enough for an EntryID */
- bvp[0] = &bv;
- bvp[1] = NULL;
- /* parentid */
- /* If the pid is 0, then the entry does not have a parent. It
- * may be the case that the entry is a suffix. In any case,
- * the parentid attribute should only be added if the entry
- * has a parent. */
- if (pid != 0) {
- sprintf( buf, "%lu", (u_long)pid );
- bv.bv_val = buf;
- bv.bv_len = strlen( buf );
- entry_replace_values( ep->ep_entry, LDBM_PARENTID_STR, bvp );
- }
- /* entryid */
- sprintf( buf, "%lu", (u_long)ep->ep_id );
- bv.bv_val = buf;
- bv.bv_len = strlen( buf );
- entry_replace_values( ep->ep_entry, "entryid", bvp );
- /* add the entrydn operational attribute to the entry. */
- add_update_entrydn_operational_attributes(ep);
- }
- /*
- * add the entrydn operational attribute to the entry.
- */
- void
- add_update_entrydn_operational_attributes(struct backentry *ep)
- {
- struct berval bv;
- struct berval *bvp[2];
- /* entrydn */
- bvp[0] = &bv;
- bvp[1] = NULL;
- bv.bv_val = (void*)backentry_get_ndn(ep);
- bv.bv_len = strlen( bv.bv_val );
- entry_replace_values_with_flags( ep->ep_entry, LDBM_ENTRYDN_STR, bvp,
- SLAPI_ATTR_FLAG_NORMALIZED_CIS );
- }
- /*
- * delete the entrydn operational attributes from the entry.
- */
- static void
- delete_update_entrydn_operational_attributes(struct backentry *ep)
- {
- /* entrydn */
- slapi_entry_attr_delete( ep->ep_entry, LDBM_ENTRYDN_STR);
- }
|