ldbm_modify.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
  37. * All rights reserved.
  38. * END COPYRIGHT BLOCK **/
  39. #ifdef HAVE_CONFIG_H
  40. # include <config.h>
  41. #endif
  42. /* modify.c - ldbm backend modify routine */
  43. #include "back-ldbm.h"
  44. extern char *numsubordinates;
  45. extern char *hassubordinates;
  46. static void remove_illegal_mods(LDAPMod **mods);
  47. static int mods_have_effect (Slapi_Entry *entry, Slapi_Mods *smods);
  48. #define MOD_SET_ERROR(rc, error, count) \
  49. { \
  50. (rc) = (error); \
  51. (count) = RETRY_TIMES; /* otherwise, the transaction may not be aborted */ \
  52. }
  53. /* Modify context structure constructor, sans allocation */
  54. void modify_init(modify_context *mc,struct backentry *old_entry)
  55. {
  56. /* Store the old entry */
  57. PR_ASSERT(NULL == mc->old_entry);
  58. PR_ASSERT(NULL == mc->new_entry);
  59. mc->old_entry = old_entry;
  60. mc->attr_encrypt = 1;
  61. }
  62. int modify_apply_mods(modify_context *mc, Slapi_Mods *smods)
  63. {
  64. return modify_apply_mods_ignore_error(mc, smods, -1);
  65. }
  66. int modify_apply_mods_ignore_error(modify_context *mc, Slapi_Mods *smods, int error)
  67. {
  68. int ret = 0;
  69. /* Make a copy of the entry */
  70. PR_ASSERT(mc->old_entry != NULL);
  71. PR_ASSERT(mc->new_entry == NULL);
  72. mc->new_entry = backentry_dup(mc->old_entry);
  73. PR_ASSERT(smods!=NULL);
  74. if ( mods_have_effect (mc->new_entry->ep_entry, smods) ) {
  75. ret = entry_apply_mods_ignore_error( mc->new_entry->ep_entry, slapi_mods_get_ldapmods_byref(smods), error);
  76. }
  77. mc->smods= smods;
  78. if (error == ret) {
  79. ret = LDAP_SUCCESS;
  80. }
  81. return ret;
  82. }
  83. /* Modify context structure destructor */
  84. int modify_term(modify_context *mc,struct backend *be)
  85. {
  86. ldbm_instance *inst = (ldbm_instance *) be->be_instance_info;
  87. slapi_mods_free(&mc->smods);
  88. /* Unlock and return entries */
  89. if (mc->old_entry) {
  90. cache_unlock_entry(&inst->inst_cache, mc->old_entry);
  91. CACHE_RETURN( &(inst->inst_cache), &(mc->old_entry) );
  92. mc->old_entry= NULL;
  93. }
  94. CACHE_RETURN(&(inst->inst_cache), &(mc->new_entry));
  95. mc->new_entry= NULL;
  96. return 0;
  97. }
  98. /* Modify context structure member to switch entries in the cache */
  99. int modify_switch_entries(modify_context *mc,backend *be)
  100. {
  101. ldbm_instance *inst = (ldbm_instance *) be->be_instance_info;
  102. int ret = 0;
  103. if (mc->old_entry && mc->new_entry) {
  104. ret = cache_replace(&(inst->inst_cache), mc->old_entry, mc->new_entry);
  105. if (ret) {
  106. LDAPDebug(LDAP_DEBUG_CACHE, "modify_switch_entries: replacing %s with %s failed (%d)\n",
  107. slapi_entry_get_dn(mc->old_entry->ep_entry),
  108. slapi_entry_get_dn(mc->new_entry->ep_entry), ret);
  109. }
  110. }
  111. return ret;
  112. }
  113. /*
  114. * Switch the new with the old(original) - undoing modify_switch_entries()
  115. * This expects modify_term() to be called next, as the old "new" entry
  116. * is now gone(replaced by the original entry).
  117. */
  118. int
  119. modify_unswitch_entries(modify_context *mc,backend *be)
  120. {
  121. struct backentry *tmp_be;
  122. ldbm_instance *inst = (ldbm_instance *) be->be_instance_info;
  123. int ret = 0;
  124. if (mc->old_entry && mc->new_entry &&
  125. cache_is_in_cache(&inst->inst_cache, mc->new_entry)) {
  126. /* switch the entries, and reset the new, new, entry */
  127. tmp_be = mc->new_entry;
  128. mc->new_entry = mc->old_entry;
  129. mc->new_entry->ep_state = 0;
  130. if (cache_has_otherref(&(inst->inst_cache), mc->new_entry)) {
  131. /* some other thread refers the entry */
  132. CACHE_RETURN(&(inst->inst_cache), &(mc->new_entry));
  133. } else {
  134. /* don't call CACHE_RETURN, that frees the entry! */
  135. mc->new_entry->ep_refcnt = 0;
  136. }
  137. mc->old_entry = tmp_be;
  138. ret = cache_replace(&(inst->inst_cache), mc->old_entry, mc->new_entry);
  139. if (ret == 0) {
  140. /*
  141. * The new entry was originally locked, so since we did the
  142. * switch we need to unlock the "new" entry, and return the
  143. * "old" one. modify_term() will then return the "new" entry.
  144. */
  145. cache_unlock_entry(&inst->inst_cache, mc->new_entry);
  146. cache_lock_entry(&inst->inst_cache, mc->old_entry);
  147. } else {
  148. LDAPDebug(LDAP_DEBUG_CACHE, "modify_unswitch_entries: replacing %s with %s failed (%d)\n",
  149. slapi_entry_get_dn(mc->old_entry->ep_entry),
  150. slapi_entry_get_dn(mc->new_entry->ep_entry), ret);
  151. }
  152. }
  153. return ret;
  154. }
  155. /* This routine does that part of a modify operation which involves
  156. updating the on-disk data: updates idices, id2entry.
  157. Copes properly with DB_LOCK_DEADLOCK. The caller must be able to cope with
  158. DB_LOCK_DEADLOCK returned.
  159. The caller is presumed to proceed as follows:
  160. Find the entry you want to modify;
  161. Lock it for modify;
  162. Make a copy of it; (call backentry_dup() )
  163. Apply modifications to the copy in memory (call entry_apply_mods() )
  164. begin transaction;
  165. Do any other mods to on-disk data you want
  166. Call this routine;
  167. Commit transaction;
  168. You pass it environment data: struct ldbminfo, pb (not sure why, but the vlv code seems to need it)
  169. the copy of the entry before modfication, the entry after modification;
  170. an LDAPMods array containing the modifications performed
  171. */
  172. int modify_update_all(backend *be, Slapi_PBlock *pb,
  173. modify_context *mc,
  174. back_txn *txn)
  175. {
  176. static char *function_name = "modify_update_all";
  177. Slapi_Operation *operation;
  178. int is_ruv = 0; /* True if the current entry is RUV */
  179. int retval = 0;
  180. if (pb) { /* pb could be NULL if it's called from import */
  181. slapi_pblock_get( pb, SLAPI_OPERATION, &operation );
  182. is_ruv = operation_is_flag_set(operation, OP_FLAG_REPL_RUV);
  183. }
  184. /*
  185. * Update the ID to Entry index.
  186. * Note that id2entry_add replaces the entry, so the Entry ID stays the same.
  187. */
  188. retval = id2entry_add_ext( be, mc->new_entry, txn, mc->attr_encrypt, NULL );
  189. if ( 0 != retval ) {
  190. if (DB_LOCK_DEADLOCK != retval)
  191. {
  192. ldbm_nasty(function_name,66,retval);
  193. }
  194. goto error;
  195. }
  196. retval = index_add_mods( be, slapi_mods_get_ldapmods_byref(mc->smods), mc->old_entry, mc->new_entry, txn );
  197. if ( 0 != retval ) {
  198. if (DB_LOCK_DEADLOCK != retval)
  199. {
  200. ldbm_nasty(function_name,65,retval);
  201. }
  202. goto error;
  203. }
  204. /*
  205. * Remove the old entry from the Virtual List View indexes.
  206. * Add the new entry to the Virtual List View indexes.
  207. * Because the VLV code calls slapi_filter_test(), which requires a pb (why?),
  208. * we allow the caller sans pb to get everything except vlv indexing.
  209. */
  210. if (NULL != pb && !is_ruv) {
  211. retval= vlv_update_all_indexes(txn, be, pb, mc->old_entry, mc->new_entry);
  212. if ( 0 != retval ) {
  213. if (DB_LOCK_DEADLOCK != retval)
  214. {
  215. ldbm_nasty(function_name,64,retval);
  216. }
  217. goto error;
  218. }
  219. }
  220. error:
  221. return retval;
  222. }
  223. /**
  224. Apply the mods to the ec entry. Check for syntax, schema problems.
  225. Check for abandon.
  226. Return code:
  227. -1 - error - result code and message are set appropriately
  228. 0 - successfully applied and checked
  229. 1 - not an error - no mods to apply or op abandoned
  230. */
  231. static int
  232. modify_apply_check_expand(
  233. Slapi_PBlock *pb,
  234. Slapi_Operation *operation,
  235. LDAPMod **mods, /* list of mods to apply */
  236. struct backentry *e, /* original "before" entry */
  237. struct backentry *ec, /* "after" entry with mods applied */
  238. Slapi_Entry **postentry,
  239. int *ldap_result_code,
  240. char **ldap_result_message
  241. )
  242. {
  243. int rc = 0;
  244. int i;
  245. int repl_op;
  246. int change_entry = 0;
  247. Slapi_Mods smods = {0};
  248. CSN *csn = operation_get_csn(operation);
  249. slapi_pblock_get (pb, SLAPI_IS_REPLICATED_OPERATION, &repl_op);
  250. slapi_mods_init_byref( &smods, mods );
  251. if ( (change_entry = mods_have_effect (ec->ep_entry, &smods)) ) {
  252. *ldap_result_code = entry_apply_mods_wsi(ec->ep_entry, &smods, csn,
  253. operation_is_flag_set(operation, OP_FLAG_REPLICATED));
  254. /*
  255. * XXXmcs: it would be nice to get back an error message from
  256. * the above call so we could pass it along to the client, e.g.,
  257. * "duplicate value for attribute givenName."
  258. */
  259. } else {
  260. Slapi_Entry *epostop = NULL;
  261. /* If the entry was not actually changed, we still need to
  262. * set the SLAPI_ENTRY_POST_OP field in the pblock (post-op
  263. * plugins expect that field to be present for all modify
  264. * operations that return LDAP_SUCCESS).
  265. */
  266. slapi_pblock_get ( pb, SLAPI_ENTRY_POST_OP, &epostop );
  267. slapi_entry_free ( epostop ); /* free existing one, if any */
  268. slapi_pblock_set ( pb, SLAPI_ENTRY_POST_OP, slapi_entry_dup( e->ep_entry ) );
  269. *postentry = NULL; /* to avoid free in main error cleanup code */
  270. }
  271. if ( !change_entry || *ldap_result_code != 0 ) {
  272. /* change_entry == 0 is not an error just a no-op */
  273. rc = change_entry ? -1 : 1;
  274. goto done;
  275. }
  276. /*
  277. * If the objectClass attribute type was modified in any way, expand
  278. * the objectClass values to reflect the inheritance hierarchy.
  279. */
  280. for ( i = 0; (mods != NULL) && (mods[i] != NULL) && !repl_op; ++i ) {
  281. if ( 0 == strcasecmp( SLAPI_ATTR_OBJECTCLASS, mods[i]->mod_type )) {
  282. slapi_schema_expand_objectclasses( ec->ep_entry );
  283. break;
  284. }
  285. }
  286. /*
  287. * We are about to pass the last abandon test, so from now on we are
  288. * committed to finish this operation. Set status to "will complete"
  289. * before we make our last abandon check to avoid race conditions in
  290. * the code that processes abandon operations.
  291. */
  292. operation->o_status = SLAPI_OP_STATUS_WILL_COMPLETE;
  293. if ( slapi_op_abandoned( pb ) ) {
  294. rc = 1;
  295. goto done;
  296. }
  297. /* multimaster replication can result in a schema violation,
  298. * although the individual operations on each master were valid
  299. * It is too late to resolve this. But we can check schema and
  300. * add a replication conflict attribute.
  301. */
  302. /* check that the entry still obeys the schema */
  303. if ((operation_is_flag_set(operation,OP_FLAG_ACTION_SCHEMA_CHECK)) &&
  304. slapi_entry_schema_check_ext( pb, ec->ep_entry, 1 ) != 0 ) {
  305. if(repl_op){
  306. Slapi_Attr *attr;
  307. Slapi_Mods smods;
  308. LDAPMod **lmods;
  309. if (slapi_entry_attr_find (ec->ep_entry, ATTR_NSDS5_REPLCONFLICT, &attr) == 0)
  310. {
  311. /* add value */
  312. Slapi_Value *val = slapi_value_new_string("Schema violation");
  313. slapi_attr_add_value(attr,val);
  314. slapi_value_free(&val);
  315. } else {
  316. /* Add new attribute */
  317. slapi_entry_add_string (ec->ep_entry, ATTR_NSDS5_REPLCONFLICT, "Schema violation");
  318. }
  319. /* the replconflict attribute is indexed and the index is built from the mods,
  320. * so we need to extend the mods */
  321. slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &lmods);
  322. slapi_mods_init_passin(&smods, lmods);
  323. slapi_mods_add_string (&smods, LDAP_MOD_ADD, ATTR_NSDS5_REPLCONFLICT, "Schema violation");
  324. lmods = slapi_mods_get_ldapmods_passout(&smods);
  325. slapi_pblock_set(pb, SLAPI_MODIFY_MODS, lmods);
  326. slapi_mods_done(&smods);
  327. } else {
  328. *ldap_result_code = LDAP_OBJECT_CLASS_VIOLATION;
  329. slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, ldap_result_message);
  330. rc = -1;
  331. goto done;
  332. }
  333. }
  334. if(!repl_op){
  335. /* check attribute syntax for the new values */
  336. if (slapi_mods_syntax_check(pb, mods, 0) != 0) {
  337. *ldap_result_code = LDAP_INVALID_SYNTAX;
  338. slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, ldap_result_message);
  339. rc = -1;
  340. goto done;
  341. }
  342. /*
  343. * make sure the entry contains all values in the RDN.
  344. * if not, the modification must have removed them.
  345. */
  346. if ( ! slapi_entry_rdn_values_present( ec->ep_entry ) ) {
  347. *ldap_result_code= LDAP_NOT_ALLOWED_ON_RDN;
  348. rc = -1;
  349. goto done;
  350. }
  351. }
  352. done:
  353. slapi_mods_done( &smods );
  354. return rc;
  355. }
  356. int
  357. ldbm_back_modify( Slapi_PBlock *pb )
  358. {
  359. backend *be;
  360. ldbm_instance *inst = NULL;
  361. struct ldbminfo *li;
  362. struct backentry *e = NULL, *ec = NULL;
  363. struct backentry *original_entry = NULL, *tmpentry = NULL;
  364. Slapi_Entry *postentry = NULL;
  365. LDAPMod **mods = NULL;
  366. LDAPMod **mods_original = NULL;
  367. Slapi_Mods smods = {0};
  368. back_txn txn;
  369. back_txnid parent_txn;
  370. modify_context ruv_c = {0};
  371. int ruv_c_init = 0;
  372. int retval = -1;
  373. char *msg;
  374. char *errbuf = NULL;
  375. int retry_count = 0;
  376. int disk_full = 0;
  377. int ldap_result_code= LDAP_SUCCESS;
  378. char *ldap_result_message= NULL;
  379. int rc = 0;
  380. Slapi_Operation *operation;
  381. entry_address *addr;
  382. int is_fixup_operation= 0;
  383. int is_ruv = 0; /* True if the current entry is RUV */
  384. CSN *opcsn = NULL;
  385. int repl_op;
  386. int opreturn = 0;
  387. int mod_count = 0;
  388. int not_an_error = 0;
  389. int fixup_tombstone = 0;
  390. slapi_pblock_get( pb, SLAPI_BACKEND, &be);
  391. slapi_pblock_get( pb, SLAPI_PLUGIN_PRIVATE, &li );
  392. slapi_pblock_get( pb, SLAPI_TARGET_ADDRESS, &addr );
  393. slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &mods );
  394. slapi_pblock_get( pb, SLAPI_TXN, (void**)&parent_txn );
  395. slapi_pblock_get( pb, SLAPI_IS_REPLICATED_OPERATION, &repl_op);
  396. slapi_pblock_get( pb, SLAPI_OPERATION, &operation );
  397. fixup_tombstone = operation_is_flag_set(operation, OP_FLAG_TOMBSTONE_FIXUP);
  398. dblayer_txn_init(li,&txn); /* must do this before first goto error_return */
  399. /* the calls to perform searches require the parent txn if any
  400. so set txn to the parent_txn until we begin the child transaction */
  401. if (parent_txn) {
  402. txn.back_txn_txn = parent_txn;
  403. } else {
  404. parent_txn = txn.back_txn_txn;
  405. slapi_pblock_set( pb, SLAPI_TXN, parent_txn );
  406. }
  407. if (NULL == operation)
  408. {
  409. ldap_result_code = LDAP_OPERATIONS_ERROR;
  410. goto error_return;
  411. }
  412. is_fixup_operation = operation_is_flag_set(operation, OP_FLAG_REPL_FIXUP);
  413. is_ruv = operation_is_flag_set(operation, OP_FLAG_REPL_RUV);
  414. inst = (ldbm_instance *) be->be_instance_info;
  415. if (NULL == addr)
  416. {
  417. goto error_return;
  418. }
  419. if (inst && inst->inst_ref_count) {
  420. slapi_counter_increment(inst->inst_ref_count);
  421. } else {
  422. LDAPDebug1Arg(LDAP_DEBUG_ANY,
  423. "ldbm_modify: instance \"%s\" does not exist.\n",
  424. inst ? inst->inst_name : "null instance");
  425. goto error_return;
  426. }
  427. /* no need to check the dn syntax as this is a replicated op */
  428. if(!repl_op){
  429. ldap_result_code = slapi_dn_syntax_check(pb, slapi_sdn_get_dn(addr->sdn), 1);
  430. if (ldap_result_code)
  431. {
  432. ldap_result_code = LDAP_INVALID_DN_SYNTAX;
  433. slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
  434. goto error_return;
  435. }
  436. }
  437. /* The dblock serializes writes to the database,
  438. * which reduces deadlocking in the db code,
  439. * which means that we run faster.
  440. *
  441. * But, this lock is re-enterant for the fixup
  442. * operations that the URP code in the Replication
  443. * plugin generates.
  444. *
  445. * SERIALLOCK is moved to dblayer_txn_begin along with exposing be
  446. * transaction to plugins (see slapi_back_transaction_* APIs).
  447. *
  448. if(SERIALLOCK(li) && !operation_is_flag_set(operation,OP_FLAG_REPL_FIXUP)) {
  449. dblayer_lock_backend(be);
  450. dblock_acquired= 1;
  451. }
  452. */
  453. if ( MANAGE_ENTRY_BEFORE_DBLOCK(li)) {
  454. /* find and lock the entry we are about to modify */
  455. if ( (e = find_entry2modify( pb, be, addr, &txn )) == NULL ) {
  456. ldap_result_code= -1;
  457. goto error_return; /* error result sent by find_entry2modify() */
  458. }
  459. }
  460. txn.back_txn_txn = NULL; /* ready to create the child transaction */
  461. for (retry_count = 0; retry_count < RETRY_TIMES; retry_count++) {
  462. int cache_rc = 0;
  463. int new_mod_count = 0;
  464. if (txn.back_txn_txn && (txn.back_txn_txn != parent_txn)) {
  465. /* don't release SERIAL LOCK */
  466. dblayer_txn_abort_ext(li, &txn, PR_FALSE);
  467. slapi_pblock_set(pb, SLAPI_TXN, parent_txn);
  468. /*
  469. * Since be_txn_preop functions could have modified the entry/mods,
  470. * We need to grab the current mods, free them, and restore the
  471. * originals. Same thing for the entry.
  472. */
  473. slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &mods);
  474. ldap_mods_free(mods, 1);
  475. slapi_pblock_set(pb, SLAPI_MODIFY_MODS, copy_mods(mods_original));
  476. /* reset ec set cache in id2entry_add_ext */
  477. if (ec) {
  478. /* must duplicate ec before returning it to cache,
  479. * which could free the entry. */
  480. if ( (tmpentry = backentry_dup( ec )) == NULL ) {
  481. ldap_result_code= LDAP_OPERATIONS_ERROR;
  482. goto error_return;
  483. }
  484. if (cache_is_in_cache(&inst->inst_cache, ec)) {
  485. CACHE_REMOVE(&inst->inst_cache, ec);
  486. }
  487. CACHE_RETURN(&inst->inst_cache, &ec);
  488. slapi_pblock_set( pb, SLAPI_MODIFY_EXISTING_ENTRY, original_entry->ep_entry );
  489. ec = original_entry;
  490. original_entry = tmpentry;
  491. tmpentry = NULL;
  492. }
  493. if (ruv_c_init) {
  494. /* reset the ruv txn stuff */
  495. modify_term(&ruv_c, be);
  496. ruv_c_init = 0;
  497. }
  498. LDAPDebug0Args(LDAP_DEBUG_BACKLDBM,
  499. "Modify Retrying Transaction\n");
  500. #ifndef LDBM_NO_BACKOFF_DELAY
  501. {
  502. PRIntervalTime interval;
  503. interval = PR_MillisecondsToInterval(slapi_rand() % 100);
  504. DS_Sleep(interval);
  505. }
  506. #endif
  507. }
  508. /* Nothing above here modifies persistent store, everything after here is subject to the transaction */
  509. /* dblayer_txn_begin holds SERIAL lock,
  510. * which should be outside of locking the entry (find_entry2modify) */
  511. if (0 == retry_count) {
  512. /* First time, hold SERIAL LOCK */
  513. retval = dblayer_txn_begin(be, parent_txn, &txn);
  514. } else {
  515. /* Otherwise, no SERIAL LOCK */
  516. retval = dblayer_txn_begin_ext(li, parent_txn, &txn, PR_FALSE);
  517. }
  518. if (0 != retval) {
  519. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  520. ldap_result_code= LDAP_OPERATIONS_ERROR;
  521. goto error_return;
  522. }
  523. /* stash the transaction for plugins */
  524. slapi_pblock_set(pb, SLAPI_TXN, txn.back_txn_txn);
  525. if (0 == retry_count) { /* just once */
  526. if ( !MANAGE_ENTRY_BEFORE_DBLOCK(li)) {
  527. /* find and lock the entry we are about to modify */
  528. if ( (e = find_entry2modify( pb, be, addr, &txn )) == NULL ) {
  529. ldap_result_code= -1;
  530. goto error_return; /* error result sent by find_entry2modify() */
  531. }
  532. }
  533. if ( !is_fixup_operation && !fixup_tombstone)
  534. {
  535. if (!repl_op && slapi_entry_flag_is_set(e->ep_entry, SLAPI_ENTRY_FLAG_TOMBSTONE))
  536. {
  537. ldap_result_code = LDAP_UNWILLING_TO_PERFORM;
  538. ldap_result_message = "Operation not allowed on tombstone entry.";
  539. slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_modify",
  540. "Attempt to modify a tombstone entry %s\n",
  541. slapi_sdn_get_dn(slapi_entry_get_sdn_const( e->ep_entry )));
  542. goto error_return;
  543. }
  544. opcsn = operation_get_csn (operation);
  545. if (NULL == opcsn && operation->o_csngen_handler)
  546. {
  547. /*
  548. * Current op is a user request. Opcsn will be assigned
  549. * if the dn is in an updatable replica.
  550. */
  551. opcsn = entry_assign_operation_csn ( pb, e->ep_entry, NULL );
  552. }
  553. if (opcsn)
  554. {
  555. entry_set_maxcsn (e->ep_entry, opcsn);
  556. }
  557. }
  558. /* Save away a copy of the entry, before modifications */
  559. slapi_pblock_set( pb, SLAPI_ENTRY_PRE_OP, slapi_entry_dup( e->ep_entry ));
  560. if ( (ldap_result_code = plugin_call_acl_mods_access( pb, e->ep_entry, mods, &errbuf)) != LDAP_SUCCESS ) {
  561. ldap_result_message= errbuf;
  562. goto error_return;
  563. }
  564. /* create a copy of the entry and apply the changes to it */
  565. if ( (ec = backentry_dup( e )) == NULL ) {
  566. ldap_result_code= LDAP_OPERATIONS_ERROR;
  567. goto error_return;
  568. }
  569. if(!repl_op){
  570. remove_illegal_mods(mods);
  571. }
  572. /* ec is the entry that our bepreop should get to mess with */
  573. slapi_pblock_set( pb, SLAPI_MODIFY_EXISTING_ENTRY, ec->ep_entry );
  574. slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  575. opreturn = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_MODIFY_FN);
  576. if (opreturn ||
  577. (slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code) && ldap_result_code) ||
  578. (slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &opreturn) && opreturn)) {
  579. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  580. slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
  581. if (!ldap_result_code) {
  582. LDAPDebug0Args(LDAP_DEBUG_ANY, "ldbm_back_modify: SLAPI_PLUGIN_BE_PRE_MODIFY_FN "
  583. "returned error but did not set SLAPI_RESULT_CODE\n");
  584. ldap_result_code = LDAP_OPERATIONS_ERROR;
  585. }
  586. if (SLAPI_PLUGIN_NOOP == opreturn) {
  587. not_an_error = 1;
  588. rc = opreturn = LDAP_SUCCESS;
  589. } else if (!opreturn) {
  590. opreturn = SLAPI_PLUGIN_FAILURE;
  591. slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
  592. }
  593. goto error_return;
  594. }
  595. /* The Plugin may have messed about with some of the PBlock parameters... ie. mods */
  596. slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &mods );
  597. /* apply the mods, check for syntax, schema problems, etc. */
  598. if (modify_apply_check_expand(pb, operation, mods, e, ec, &postentry,
  599. &ldap_result_code, &ldap_result_message)) {
  600. goto error_return;
  601. }
  602. /* the schema check could have added a repl conflict mod
  603. * get the mods again */
  604. slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &mods );
  605. slapi_mods_init_byref(&smods,mods);
  606. mod_count = slapi_mods_get_num_mods(&smods);
  607. /*
  608. * Grab a copy of the mods and the entry in case the be_txn_preop changes
  609. * the them. If we have a failure, then we need to reset the mods to their
  610. * their original state;
  611. */
  612. mods_original = copy_mods(mods);
  613. if ( (original_entry = backentry_dup( ec )) == NULL ) {
  614. ldap_result_code= LDAP_OPERATIONS_ERROR;
  615. goto error_return;
  616. }
  617. } /* if (0 == retry_count) just once */
  618. /* call the transaction pre modify plugins just after creating the transaction */
  619. retval = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN);
  620. if (retval) {
  621. LDAPDebug1Arg( LDAP_DEBUG_TRACE, "SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN plugin "
  622. "returned error code %d\n", retval );
  623. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  624. slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
  625. if (SLAPI_PLUGIN_NOOP == retval) {
  626. not_an_error = 1;
  627. rc = retval = LDAP_SUCCESS;
  628. }
  629. if (!opreturn) {
  630. slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &retval);
  631. }
  632. slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
  633. goto error_return;
  634. }
  635. /* the mods might have been changed, so get the latest */
  636. slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &mods );
  637. /* make sure the betxnpreop did not alter any of the mods that
  638. had already previously been applied */
  639. slapi_mods_done(&smods);
  640. slapi_mods_init_byref(&smods,mods);
  641. new_mod_count = slapi_mods_get_num_mods(&smods);
  642. if (new_mod_count < mod_count) {
  643. LDAPDebug2Args( LDAP_DEBUG_ANY, "Error: BE_TXN_PRE_MODIFY plugin has removed "
  644. "mods from the original list - mod count was [%d] now [%d] "
  645. "mods will not be applied - mods list changes must be done "
  646. "in the BE_PRE_MODIFY plugin, not the BE_TXN_PRE_MODIFY\n",
  647. mod_count, new_mod_count );
  648. } else if (new_mod_count > mod_count) { /* apply the new betxnpremod mods */
  649. /* apply the mods, check for syntax, schema problems, etc. */
  650. if (modify_apply_check_expand(pb, operation, &mods[mod_count], e, ec, &postentry,
  651. &ldap_result_code, &ldap_result_message)) {
  652. goto error_return;
  653. }
  654. } /* else if new_mod_count == mod_count then betxnpremod plugin did nothing */
  655. /*
  656. * Update the ID to Entry index.
  657. * Note that id2entry_add replaces the entry, so the Entry ID
  658. * stays the same.
  659. */
  660. retval = id2entry_add_ext( be, ec, &txn, 1, &cache_rc );
  661. if (DB_LOCK_DEADLOCK == retval)
  662. {
  663. /* Abort and re-try */
  664. continue;
  665. }
  666. if (0 != retval) {
  667. LDAPDebug( LDAP_DEBUG_ANY, "id2entry_add failed, err=%d %s\n",
  668. retval, (msg = dblayer_strerror( retval )) ? msg : "", 0 );
  669. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  670. MOD_SET_ERROR(ldap_result_code, LDAP_OPERATIONS_ERROR, retry_count);
  671. goto error_return;
  672. }
  673. retval = index_add_mods( be, mods, e, ec, &txn );
  674. if (DB_LOCK_DEADLOCK == retval)
  675. {
  676. /* Abort and re-try */
  677. continue;
  678. }
  679. if (0 != retval) {
  680. LDAPDebug( LDAP_DEBUG_ANY, "index_add_mods failed, err=%d %s\n",
  681. retval, (msg = dblayer_strerror( retval )) ? msg : "", 0 );
  682. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  683. MOD_SET_ERROR(ldap_result_code, LDAP_OPERATIONS_ERROR, retry_count);
  684. goto error_return;
  685. }
  686. /*
  687. * Remove the old entry from the Virtual List View indexes.
  688. * Add the new entry to the Virtual List View indexes.
  689. * If the entry is ruv, no need to update vlv.
  690. */
  691. if (!is_ruv) {
  692. retval= vlv_update_all_indexes(&txn, be, pb, e, ec);
  693. if (DB_LOCK_DEADLOCK == retval)
  694. {
  695. /* Abort and re-try */
  696. continue;
  697. }
  698. if (0 != retval) {
  699. LDAPDebug( LDAP_DEBUG_ANY,
  700. "vlv_update_index failed, err=%d %s\n",
  701. retval, (msg = dblayer_strerror( retval )) ? msg : "", 0 );
  702. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  703. MOD_SET_ERROR(ldap_result_code,
  704. LDAP_OPERATIONS_ERROR, retry_count);
  705. goto error_return;
  706. }
  707. }
  708. if (!is_ruv && !is_fixup_operation && !NO_RUV_UPDATE(li)) {
  709. ruv_c_init = ldbm_txn_ruv_modify_context( pb, &ruv_c );
  710. if (-1 == ruv_c_init) {
  711. LDAPDebug( LDAP_DEBUG_ANY,
  712. "ldbm_back_modify: ldbm_txn_ruv_modify_context "
  713. "failed to construct RUV modify context\n",
  714. 0, 0, 0);
  715. ldap_result_code= LDAP_OPERATIONS_ERROR;
  716. retval = 0;
  717. goto error_return;
  718. }
  719. }
  720. if (ruv_c_init) {
  721. retval = modify_update_all( be, pb, &ruv_c, &txn );
  722. if (DB_LOCK_DEADLOCK == retval) {
  723. /* Abort and re-try */
  724. continue;
  725. }
  726. if (0 != retval) {
  727. LDAPDebug( LDAP_DEBUG_ANY,
  728. "modify_update_all failed, err=%d %s\n", retval,
  729. (msg = dblayer_strerror( retval )) ? msg : "", 0 );
  730. if (LDBM_OS_ERR_IS_DISKFULL(retval))
  731. disk_full = 1;
  732. ldap_result_code= LDAP_OPERATIONS_ERROR;
  733. goto error_return;
  734. }
  735. }
  736. if (0 == retval) {
  737. break;
  738. }
  739. }
  740. if (retry_count == RETRY_TIMES) {
  741. LDAPDebug( LDAP_DEBUG_ANY, "Retry count exceeded in modify\n", 0, 0, 0 );
  742. ldap_result_code= LDAP_BUSY;
  743. goto error_return;
  744. }
  745. if (ruv_c_init) {
  746. if (modify_switch_entries(&ruv_c, be) != 0 ) {
  747. ldap_result_code= LDAP_OPERATIONS_ERROR;
  748. LDAPDebug( LDAP_DEBUG_ANY,
  749. "ldbm_back_modify: modify_switch_entries failed\n", 0, 0, 0);
  750. goto error_return;
  751. }
  752. }
  753. if (cache_replace( &inst->inst_cache, e, ec ) != 0 ) {
  754. MOD_SET_ERROR(ldap_result_code, LDAP_OPERATIONS_ERROR, retry_count);
  755. goto error_return;
  756. }
  757. /* e uncached */
  758. /* we must return both e (which has been deleted) and new entry ec to cache */
  759. /* cache_replace removes e from the cache hash tables */
  760. cache_unlock_entry( &inst->inst_cache, e );
  761. CACHE_RETURN( &inst->inst_cache, &e );
  762. /* lock new entry in cache to prevent usage until we are complete */
  763. cache_lock_entry( &inst->inst_cache, ec );
  764. postentry = slapi_entry_dup( ec->ep_entry );
  765. slapi_pblock_set( pb, SLAPI_ENTRY_POST_OP, postentry );
  766. /* invalidate virtual cache */
  767. ec->ep_entry->e_virtual_watermark = 0;
  768. /*
  769. * LP Fix of crash when the commit will fail:
  770. * If the commit fail, the common error path will
  771. * try to unlock the entry again and crash (PR_ASSERT
  772. * in debug mode.
  773. * By just setting e to NULL, we avoid this. It's OK since
  774. * we don't use e after that in the normal case.
  775. */
  776. e = NULL;
  777. /* call the transaction post modify plugins just before the commit */
  778. if ((retval = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN))) {
  779. LDAPDebug1Arg( LDAP_DEBUG_TRACE, "SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN plugin "
  780. "returned error code %d\n", retval );
  781. if (!ldap_result_code) {
  782. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  783. }
  784. if (!opreturn) {
  785. slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
  786. }
  787. if (!opreturn) {
  788. slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &retval);
  789. }
  790. slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
  791. goto error_return;
  792. }
  793. /* Release SERIAL LOCK */
  794. retval = dblayer_txn_commit(be, &txn);
  795. /* after commit - txn is no longer valid - replace SLAPI_TXN with parent */
  796. slapi_pblock_set(pb, SLAPI_TXN, parent_txn);
  797. if (0 != retval) {
  798. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  799. ldap_result_code= LDAP_OPERATIONS_ERROR;
  800. goto error_return;
  801. }
  802. rc= 0;
  803. goto common_return;
  804. error_return:
  805. if ( postentry != NULL )
  806. {
  807. slapi_entry_free( postentry );
  808. postentry = NULL;
  809. slapi_pblock_set( pb, SLAPI_ENTRY_POST_OP, NULL );
  810. }
  811. if (retval == DB_RUNRECOVERY) {
  812. dblayer_remember_disk_filled(li);
  813. ldbm_nasty("Modify",81,retval);
  814. disk_full = 1;
  815. }
  816. if (disk_full) {
  817. rc= return_on_disk_full(li);
  818. } else {
  819. if (txn.back_txn_txn && (txn.back_txn_txn != parent_txn)) {
  820. /* make sure SLAPI_RESULT_CODE and SLAPI_PLUGIN_OPRETURN are set */
  821. int val = 0;
  822. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &val);
  823. if (!val) {
  824. if (!ldap_result_code) {
  825. ldap_result_code = LDAP_OPERATIONS_ERROR;
  826. }
  827. slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  828. }
  829. slapi_pblock_get( pb, SLAPI_PLUGIN_OPRETURN, &val );
  830. if (!val) {
  831. opreturn = -1;
  832. slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN, &opreturn );
  833. }
  834. /* call the transaction post modify plugins just before the abort */
  835. /* plugins called before abort should check for the OPRETURN or RESULT_CODE
  836. and skip processing if they don't want do anything - some plugins that
  837. keep track of a counter (usn, dna) may want to "rollback" the counter
  838. in this case */
  839. if ((retval = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN))) {
  840. LDAPDebug1Arg( LDAP_DEBUG_TRACE, "SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN plugin "
  841. "returned error code %d\n", retval );
  842. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  843. slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
  844. slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
  845. if (!opreturn) {
  846. slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &retval);
  847. }
  848. }
  849. /* It is safer not to abort when the transaction is not started. */
  850. /* Release SERIAL LOCK */
  851. dblayer_txn_abort(be, &txn); /* abort crashes in case disk full */
  852. /* txn is no longer valid - reset the txn pointer to the parent */
  853. slapi_pblock_set(pb, SLAPI_TXN, parent_txn);
  854. }
  855. if (!not_an_error) {
  856. rc = SLAPI_FAIL_GENERAL;
  857. }
  858. }
  859. /* if ec is in cache, remove it, then add back e if we still have it */
  860. if (inst && cache_is_in_cache(&inst->inst_cache, ec)) {
  861. CACHE_REMOVE( &inst->inst_cache, ec );
  862. /* if ec was in cache, e was not - add back e */
  863. if (e) {
  864. if (CACHE_ADD( &inst->inst_cache, e, NULL ) < 0) {
  865. LDAPDebug1Arg(LDAP_DEBUG_CACHE, "ldbm_modify: CACHE_ADD %s failed\n",
  866. slapi_entry_get_dn(e->ep_entry));
  867. }
  868. }
  869. }
  870. common_return:
  871. slapi_mods_done(&smods);
  872. if (inst) {
  873. if (cache_is_in_cache(&inst->inst_cache, ec)) {
  874. cache_unlock_entry(&inst->inst_cache, ec);
  875. } else if (e) {
  876. /* if ec was not in cache, cache_replace was not done.
  877. * i.e., e was not unlocked. */
  878. cache_unlock_entry(&inst->inst_cache, e);
  879. CACHE_RETURN(&inst->inst_cache, &e);
  880. }
  881. CACHE_RETURN(&inst->inst_cache, &ec);
  882. if (inst->inst_ref_count) {
  883. slapi_counter_decrement(inst->inst_ref_count);
  884. }
  885. }
  886. /* result code could be used in the bepost plugin functions. */
  887. slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  888. /* The bepostop is called even if the operation fails. */
  889. if (!disk_full)
  890. plugin_call_plugins (pb, SLAPI_PLUGIN_BE_POST_MODIFY_FN);
  891. if (ruv_c_init) {
  892. modify_term(&ruv_c, be);
  893. }
  894. if(ldap_result_code!=-1)
  895. {
  896. if (not_an_error) {
  897. /* This is mainly used by urp. Solved conflict is not an error.
  898. * And we don't want the supplier to halt sending the updates. */
  899. ldap_result_code = LDAP_SUCCESS;
  900. }
  901. slapi_send_ldap_result( pb, ldap_result_code, NULL, ldap_result_message, 0, NULL );
  902. }
  903. /* free our backups */
  904. ldap_mods_free(mods_original, 1);
  905. backentry_free(&original_entry);
  906. backentry_free(&tmpentry);
  907. slapi_ch_free_string(&errbuf);
  908. return rc;
  909. }
  910. /* Function removes mods which are not allowed over-the-wire */
  911. static void
  912. remove_illegal_mods(LDAPMod **mods)
  913. {
  914. int i, j;
  915. LDAPMod *tmp;
  916. /* remove any attempts by the user to modify these attrs */
  917. for ( i = 0; (mods != NULL) && (mods[i] != NULL); i++ ) {
  918. if ( strcasecmp( mods[i]->mod_type, numsubordinates ) == 0
  919. || strcasecmp( mods[i]->mod_type, hassubordinates ) == 0 )
  920. {
  921. tmp = mods[i];
  922. for ( j = i; mods[j] != NULL; j++ ) {
  923. mods[j] = mods[j + 1];
  924. }
  925. slapi_ch_free( (void**)&(tmp->mod_type) );
  926. if ( tmp->mod_bvalues != NULL ) {
  927. ber_bvecfree( tmp->mod_bvalues );
  928. }
  929. slapi_ch_free( (void**)&tmp );
  930. i--;
  931. }
  932. }
  933. }
  934. /* A mod has no effect if it is trying to replace a non-existing
  935. * attribute with null value
  936. */
  937. static int
  938. mods_have_effect (Slapi_Entry *entry, Slapi_Mods *smods)
  939. {
  940. LDAPMod *mod;
  941. Slapi_Attr *attr;
  942. int have_effect = 1;
  943. int j;
  944. /* Mods have effect if there is at least a non-replace mod or
  945. * a non-null-value mod.
  946. */
  947. for ( j = 0; j < smods->num_mods - 1; j++ ) {
  948. if ( (mod = smods->mods[j]) != NULL ) {
  949. if ( ((mod->mod_op & LDAP_MOD_REPLACE) == 0) ||
  950. (mod->mod_vals.modv_bvals &&
  951. strcasecmp (mod->mod_type, "modifiersname") &&
  952. strcasecmp (mod->mod_type, "modifytime") ) ) {
  953. goto done;
  954. }
  955. }
  956. }
  957. if ( entry && entry->e_sdn.dn ) {
  958. for ( j = 0; j < smods->num_mods - 1; j++ ) {
  959. if ((mod = smods->mods[j]) != NULL) {
  960. for ( attr = entry->e_attrs; attr; attr = attr->a_next ) {
  961. /* Mods have effect if at least a null-value-mod is
  962. * to actually remove an existing attribute
  963. */
  964. if ( strcasecmp ( mod->mod_type, attr->a_type ) == 0 ) {
  965. have_effect = 1; /* found one - mod has effect */
  966. goto done;
  967. }
  968. /* this mod type was not found in the entry - if we don't
  969. find one of the other mod types, or if there are no more
  970. mod types to look for, this mod does not apply */
  971. have_effect = 0;
  972. }
  973. }
  974. }
  975. }
  976. done:
  977. /* Return true would let the flow continue along the old path before
  978. * this function was added
  979. */
  980. return have_effect;
  981. }