ldbm_modify.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  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. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /* modify.c - ldbm backend modify routine */
  42. #include "back-ldbm.h"
  43. extern char *numsubordinates;
  44. extern char *hassubordinates;
  45. static void remove_illegal_mods(LDAPMod **mods);
  46. static int mods_have_effect (Slapi_Entry *entry, Slapi_Mods *smods);
  47. /* Modify context structure constructor, sans allocation */
  48. void modify_init(modify_context *mc,struct backentry *old_entry)
  49. {
  50. /* Store the old entry */
  51. PR_ASSERT(NULL == mc->old_entry);
  52. PR_ASSERT(NULL == mc->new_entry);
  53. mc->old_entry = old_entry;
  54. mc->new_entry_in_cache = 0;
  55. }
  56. int modify_apply_mods(modify_context *mc, Slapi_Mods *smods)
  57. {
  58. int ret = 0;
  59. /* Make a copy of the entry */
  60. PR_ASSERT(mc->old_entry != NULL);
  61. PR_ASSERT(mc->new_entry == NULL);
  62. mc->new_entry = backentry_dup(mc->old_entry);
  63. PR_ASSERT(smods!=NULL);
  64. if ( mods_have_effect (mc->new_entry->ep_entry, smods) ) {
  65. ret = entry_apply_mods( mc->new_entry->ep_entry, slapi_mods_get_ldapmods_byref(smods));
  66. }
  67. mc->smods= smods;
  68. return ret;
  69. }
  70. /* Modify context structure destructor */
  71. int modify_term(modify_context *mc,struct backend *be)
  72. {
  73. ldbm_instance *inst = (ldbm_instance *) be->be_instance_info;
  74. slapi_mods_free(&mc->smods);
  75. /* Unlock and return entries */
  76. if (NULL != mc->old_entry) {
  77. cache_unlock_entry(&inst->inst_cache, mc->old_entry);
  78. cache_return( &(inst->inst_cache), &(mc->old_entry) );
  79. mc->old_entry= NULL;
  80. }
  81. if (mc->new_entry_in_cache) {
  82. cache_return( &(inst->inst_cache), &(mc->new_entry) );
  83. } else {
  84. backentry_free(&(mc->new_entry));
  85. }
  86. mc->new_entry= NULL;
  87. return 0;
  88. }
  89. /* Modify context structure member to switch entries in the cache */
  90. int modify_switch_entries(modify_context *mc,backend *be)
  91. {
  92. ldbm_instance *inst = (ldbm_instance *) be->be_instance_info;
  93. int ret = 0;
  94. if (mc->old_entry!=NULL && mc->new_entry!=NULL) {
  95. ret = cache_replace(&(inst->inst_cache), mc->old_entry, mc->new_entry);
  96. if (ret == 0) mc->new_entry_in_cache = 1;
  97. }
  98. return ret;
  99. }
  100. /* This routine does that part of a modify operation which involves
  101. updating the on-disk data: updates idices, id2entry.
  102. Copes properly with DB_LOCK_DEADLOCK. The caller must be able to cope with
  103. DB_LOCK_DEADLOCK returned.
  104. The caller is presumed to proceed as follows:
  105. Find the entry you want to modify;
  106. Lock it for modify;
  107. Make a copy of it; (call backentry_dup() )
  108. Apply modifications to the copy in memory (call entry_apply_mods() )
  109. begin transaction;
  110. Do any other mods to on-disk data you want
  111. Call this routine;
  112. Commit transaction;
  113. You pass it environment data: struct ldbminfo, pb (not sure why, but the vlv code seems to need it)
  114. the copy of the entry before modfication, the entry after modification;
  115. an LDAPMods array containing the modifications performed
  116. */
  117. int modify_update_all(backend *be, Slapi_PBlock *pb,
  118. modify_context *mc,
  119. back_txn *txn)
  120. {
  121. static char *function_name = "modify_update_all";
  122. Slapi_Operation *operation;
  123. int is_ruv = 0; /* True if the current entry is RUV */
  124. int retval = 0;
  125. if (pb) { /* pb could be NULL if it's called from import */
  126. slapi_pblock_get( pb, SLAPI_OPERATION, &operation );
  127. is_ruv = operation_is_flag_set(operation, OP_FLAG_REPL_RUV);
  128. }
  129. /*
  130. * Update the ID to Entry index.
  131. * Note that id2entry_add replaces the entry, so the Entry ID stays the same.
  132. */
  133. retval = id2entry_add( be, mc->new_entry, txn );
  134. if ( 0 != retval ) {
  135. if (DB_LOCK_DEADLOCK != retval)
  136. {
  137. ldbm_nasty(function_name,66,retval);
  138. }
  139. goto error;
  140. }
  141. retval = index_add_mods( be, (const LDAPMod **)slapi_mods_get_ldapmods_byref(mc->smods), mc->old_entry, mc->new_entry, txn );
  142. if ( 0 != retval ) {
  143. if (DB_LOCK_DEADLOCK != retval)
  144. {
  145. ldbm_nasty(function_name,65,retval);
  146. }
  147. goto error;
  148. }
  149. /*
  150. * Remove the old entry from the Virtual List View indexes.
  151. * Add the new entry to the Virtual List View indexes.
  152. * Because the VLV code calls slapi_filter_test(), which requires a pb (why?),
  153. * we allow the caller sans pb to get everything except vlv indexing.
  154. */
  155. if (NULL != pb && !is_ruv) {
  156. retval= vlv_update_all_indexes(txn, be, pb, mc->old_entry, mc->new_entry);
  157. if ( 0 != retval ) {
  158. if (DB_LOCK_DEADLOCK != retval)
  159. {
  160. ldbm_nasty(function_name,64,retval);
  161. }
  162. goto error;
  163. }
  164. }
  165. error:
  166. return retval;
  167. }
  168. int
  169. ldbm_back_modify( Slapi_PBlock *pb )
  170. {
  171. backend *be;
  172. ldbm_instance *inst;
  173. struct ldbminfo *li;
  174. struct backentry *e, *ec = NULL;
  175. Slapi_Entry *postentry = NULL;
  176. LDAPMod **mods;
  177. Slapi_Mods smods = {0};
  178. back_txn txn;
  179. back_txnid parent_txn;
  180. int retval = -1;
  181. char *msg;
  182. char *errbuf = NULL;
  183. int retry_count = 0;
  184. int disk_full = 0;
  185. int ldap_result_code= LDAP_SUCCESS;
  186. char *ldap_result_message= NULL;
  187. int rc = 0;
  188. Slapi_Operation *operation;
  189. int dblock_acquired= 0;
  190. entry_address *addr;
  191. int change_entry = 0;
  192. int ec_in_cache = 0;
  193. int is_fixup_operation= 0;
  194. int is_ruv = 0; /* True if the current entry is RUV */
  195. CSN *opcsn = NULL;
  196. int i = 0;
  197. slapi_pblock_get( pb, SLAPI_BACKEND, &be);
  198. slapi_pblock_get( pb, SLAPI_PLUGIN_PRIVATE, &li );
  199. slapi_pblock_get( pb, SLAPI_TARGET_ADDRESS, &addr );
  200. slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &mods );
  201. slapi_pblock_get( pb, SLAPI_PARENT_TXN, (void**)&parent_txn );
  202. slapi_pblock_get( pb, SLAPI_OPERATION, &operation );
  203. is_fixup_operation = operation_is_flag_set(operation, OP_FLAG_REPL_FIXUP);
  204. is_ruv = operation_is_flag_set(operation, OP_FLAG_REPL_RUV);
  205. inst = (ldbm_instance *) be->be_instance_info;
  206. dblayer_txn_init(li,&txn);
  207. /* The dblock serializes writes to the database,
  208. * which reduces deadlocking in the db code,
  209. * which means that we run faster.
  210. *
  211. * But, this lock is re-enterant for the fixup
  212. * operations that the URP code in the Replication
  213. * plugin generates.
  214. */
  215. if(SERIALLOCK(li) && !operation_is_flag_set(operation,OP_FLAG_REPL_FIXUP)) {
  216. dblayer_lock_backend(be);
  217. dblock_acquired= 1;
  218. }
  219. /* find and lock the entry we are about to modify */
  220. if ( (e = find_entry2modify( pb, be, addr, NULL )) == NULL ) {
  221. ldap_result_code= -1;
  222. goto error_return; /* error result sent by find_entry2modify() */
  223. }
  224. if ( !is_fixup_operation )
  225. {
  226. opcsn = operation_get_csn (operation);
  227. if (NULL == opcsn && operation->o_csngen_handler)
  228. {
  229. /*
  230. * Current op is a user request. Opcsn will be assigned
  231. * if the dn is in an updatable replica.
  232. */
  233. opcsn = entry_assign_operation_csn ( pb, e->ep_entry, NULL );
  234. }
  235. if (opcsn)
  236. {
  237. entry_set_maxcsn (e->ep_entry, opcsn);
  238. }
  239. }
  240. /* Save away a copy of the entry, before modifications */
  241. slapi_pblock_set( pb, SLAPI_ENTRY_PRE_OP, slapi_entry_dup( e->ep_entry ));
  242. if ( (ldap_result_code = plugin_call_acl_mods_access( pb, e->ep_entry, mods, &errbuf)) != LDAP_SUCCESS ) {
  243. ldap_result_message= errbuf;
  244. goto error_return;
  245. }
  246. /* create a copy of the entry and apply the changes to it */
  247. if ( (ec = backentry_dup( e )) == NULL ) {
  248. ldap_result_code= LDAP_OPERATIONS_ERROR;
  249. goto error_return;
  250. }
  251. remove_illegal_mods(mods);
  252. /* ec is the entry that our bepreop should get to mess with */
  253. slapi_pblock_set( pb, SLAPI_MODIFY_EXISTING_ENTRY, ec->ep_entry );
  254. slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  255. plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_MODIFY_FN);
  256. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  257. /* The Plugin may have messed about with some of the PBlock parameters... ie. mods */
  258. slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &mods );
  259. slapi_mods_init_byref(&smods,mods);
  260. {
  261. CSN *csn = operation_get_csn(operation);
  262. if ( (change_entry = mods_have_effect (ec->ep_entry, &smods)) ) {
  263. ldap_result_code = entry_apply_mods_wsi(ec->ep_entry, &smods, csn, operation_is_flag_set(operation,OP_FLAG_REPLICATED));
  264. /*
  265. * XXXmcs: it would be nice to get back an error message from
  266. * the above call so we could pass it along to the client, e.g.,
  267. * "duplicate value for attribute givenName."
  268. */
  269. } else {
  270. /* If the entry was not actually changed, we still need to
  271. * set the SLAPI_ENTRY_POST_OP field in the pblock (post-op
  272. * plugins expect that field to be present for all modify
  273. * operations that return LDAP_SUCCESS).
  274. */
  275. postentry = slapi_entry_dup( e->ep_entry );
  276. slapi_pblock_set ( pb, SLAPI_ENTRY_POST_OP, postentry );
  277. postentry = NULL; /* avoid removal/free in error_return code */
  278. }
  279. if ( !change_entry || ldap_result_code != 0 ) {
  280. /* change_entry == 0 is not an error, but we need to free lock etc */
  281. slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  282. goto error_return;
  283. }
  284. }
  285. /*
  286. * If the objectClass attribute type was modified in any way, expand
  287. * the objectClass values to reflect the inheritance hierarchy.
  288. */
  289. for ( i = 0; mods[i] != NULL; ++i ) {
  290. if ( 0 == strcasecmp( SLAPI_ATTR_OBJECTCLASS, mods[i]->mod_type )) {
  291. slapi_schema_expand_objectclasses( ec->ep_entry );
  292. break;
  293. }
  294. }
  295. /*
  296. * We are about to pass the last abandon test, so from now on we are
  297. * committed to finish this operation. Set status to "will complete"
  298. * before we make our last abandon check to avoid race conditions in
  299. * the code that processes abandon operations.
  300. */
  301. if (operation) {
  302. operation->o_status = SLAPI_OP_STATUS_WILL_COMPLETE;
  303. }
  304. if ( slapi_op_abandoned( pb ) ) {
  305. goto error_return;
  306. }
  307. /* check that the entry still obeys the schema */
  308. if ( (operation_is_flag_set(operation,OP_FLAG_ACTION_SCHEMA_CHECK)) &&
  309. slapi_entry_schema_check( pb, ec->ep_entry ) != 0 ) {
  310. ldap_result_code= LDAP_OBJECT_CLASS_VIOLATION;
  311. slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
  312. goto error_return;
  313. }
  314. /* check attribute syntax for the new values */
  315. if (slapi_mods_syntax_check(pb, mods, 0) != 0)
  316. {
  317. ldap_result_code = LDAP_INVALID_SYNTAX;
  318. slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
  319. goto error_return;
  320. }
  321. /*
  322. * make sure the entry contains all values in the RDN.
  323. * if not, the modification must have removed them.
  324. */
  325. if ( ! slapi_entry_rdn_values_present( ec->ep_entry ) ) {
  326. ldap_result_code= LDAP_NOT_ALLOWED_ON_RDN;
  327. goto error_return;
  328. }
  329. for (retry_count = 0; retry_count < RETRY_TIMES; retry_count++) {
  330. if (retry_count > 0) {
  331. dblayer_txn_abort(li,&txn);
  332. LDAPDebug( LDAP_DEBUG_TRACE, "Modify Retrying Transaction\n", 0, 0, 0 );
  333. #ifndef LDBM_NO_BACKOFF_DELAY
  334. {
  335. PRIntervalTime interval;
  336. interval = PR_MillisecondsToInterval(slapi_rand() % 100);
  337. DS_Sleep(interval);
  338. }
  339. #endif
  340. }
  341. /* Nothing above here modifies persistent store, everything after here is subject to the transaction */
  342. retval = dblayer_txn_begin(li,parent_txn,&txn);
  343. if (0 != retval) {
  344. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  345. ldap_result_code= LDAP_OPERATIONS_ERROR;
  346. goto error_return;
  347. }
  348. /*
  349. * Update the ID to Entry index.
  350. * Note that id2entry_add replaces the entry, so the Entry ID stays the same.
  351. */
  352. retval = id2entry_add( be, ec, &txn );
  353. if (DB_LOCK_DEADLOCK == retval)
  354. {
  355. /* Abort and re-try */
  356. continue;
  357. }
  358. if (0 != retval) {
  359. LDAPDebug( LDAP_DEBUG_ANY, "id2entry_add failed, err=%d %s\n",
  360. retval, (msg = dblayer_strerror( retval )) ? msg : "", 0 );
  361. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  362. ldap_result_code= LDAP_OPERATIONS_ERROR;
  363. goto error_return;
  364. }
  365. ec_in_cache = 1;
  366. retval = index_add_mods( be, (const LDAPMod**)mods, e, ec, &txn );
  367. if (DB_LOCK_DEADLOCK == retval)
  368. {
  369. /* Abort and re-try */
  370. continue;
  371. }
  372. if (0 != retval) {
  373. LDAPDebug( LDAP_DEBUG_ANY, "index_add_mods failed, err=%d %s\n",
  374. retval, (msg = dblayer_strerror( retval )) ? msg : "", 0 );
  375. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  376. ldap_result_code= LDAP_OPERATIONS_ERROR;
  377. goto error_return;
  378. }
  379. /*
  380. * Remove the old entry from the Virtual List View indexes.
  381. * Add the new entry to the Virtual List View indexes.
  382. * If the entry is ruv, no need to update vlv.
  383. */
  384. if (!is_ruv) {
  385. retval= vlv_update_all_indexes(&txn, be, pb, e, ec);
  386. if (DB_LOCK_DEADLOCK == retval)
  387. {
  388. /* Abort and re-try */
  389. continue;
  390. }
  391. if (0 != retval) {
  392. LDAPDebug( LDAP_DEBUG_ANY,
  393. "vlv_update_index failed, err=%d %s\n",
  394. retval, (msg = dblayer_strerror( retval )) ? msg : "", 0 );
  395. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  396. ldap_result_code= LDAP_OPERATIONS_ERROR;
  397. goto error_return;
  398. }
  399. }
  400. if (0 == retval) {
  401. break;
  402. }
  403. }
  404. if (retry_count == RETRY_TIMES) {
  405. LDAPDebug( LDAP_DEBUG_ANY, "Retry count exceeded in modify\n", 0, 0, 0 );
  406. ldap_result_code= LDAP_OPERATIONS_ERROR;
  407. goto error_return;
  408. }
  409. if (cache_replace( &inst->inst_cache, e, ec ) != 0 ) {
  410. ldap_result_code= LDAP_OPERATIONS_ERROR;
  411. goto error_return;
  412. }
  413. postentry = slapi_entry_dup( ec->ep_entry );
  414. slapi_pblock_set( pb, SLAPI_ENTRY_POST_OP, postentry );
  415. /* invalidate virtual cache */
  416. ec->ep_entry->e_virtual_watermark = 0;
  417. /* we must return both e (which has been deleted) and new entry ec */
  418. cache_unlock_entry( &inst->inst_cache, e );
  419. cache_return( &inst->inst_cache, &e );
  420. /*
  421. * LP Fix of crash when the commit will fail:
  422. * If the commit fail, the common error path will
  423. * try to unlock the entry again and crash (PR_ASSERT
  424. * in debug mode.
  425. * By just setting e to NULL, we avoid this. It's OK since
  426. * we don't use e after that in the normal case.
  427. */
  428. e = NULL;
  429. retval = dblayer_txn_commit(li,&txn);
  430. if (0 != retval) {
  431. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  432. ldap_result_code= LDAP_OPERATIONS_ERROR;
  433. goto error_return;
  434. }
  435. rc= 0;
  436. goto common_return;
  437. error_return:
  438. if (ec_in_cache)
  439. {
  440. cache_remove( &inst->inst_cache, ec );
  441. }
  442. else
  443. {
  444. backentry_free(&ec);
  445. }
  446. if ( postentry != NULL )
  447. {
  448. slapi_entry_free( postentry );
  449. postentry = NULL;
  450. slapi_pblock_set( pb, SLAPI_ENTRY_POST_OP, NULL );
  451. }
  452. if (e!=NULL) {
  453. cache_unlock_entry( &inst->inst_cache, e);
  454. cache_return( &inst->inst_cache, &e);
  455. }
  456. if (retval == DB_RUNRECOVERY) {
  457. dblayer_remember_disk_filled(li);
  458. ldbm_nasty("Modify",81,retval);
  459. disk_full = 1;
  460. }
  461. if (disk_full)
  462. rc= return_on_disk_full(li);
  463. else if (ldap_result_code != LDAP_SUCCESS) {
  464. /* It is specifically OK to make this call even when no transaction was in progress */
  465. dblayer_txn_abort(li,&txn); /* abort crashes in case disk full */
  466. rc= SLAPI_FAIL_GENERAL;
  467. }
  468. common_return:
  469. slapi_mods_done(&smods);
  470. if (ec_in_cache)
  471. {
  472. cache_return( &inst->inst_cache, &ec );
  473. }
  474. /* JCMREPL - The bepostop is called even if the operation fails. */
  475. if (!disk_full)
  476. plugin_call_plugins (pb, SLAPI_PLUGIN_BE_POST_MODIFY_FN);
  477. if(dblock_acquired)
  478. {
  479. dblayer_unlock_backend(be);
  480. }
  481. if(ldap_result_code!=-1)
  482. {
  483. slapi_send_ldap_result( pb, ldap_result_code, NULL, ldap_result_message, 0, NULL );
  484. }
  485. slapi_ch_free( (void**)&errbuf);
  486. return rc;
  487. }
  488. /* Function removes mods which are not allowed over-the-wire */
  489. static void
  490. remove_illegal_mods(LDAPMod **mods)
  491. {
  492. int i, j;
  493. LDAPMod *tmp;
  494. /* remove any attempts by the user to modify these attrs */
  495. for ( i = 0; mods[i] != NULL; i++ ) {
  496. if ( strcasecmp( mods[i]->mod_type, numsubordinates ) == 0
  497. || strcasecmp( mods[i]->mod_type, hassubordinates ) == 0 )
  498. {
  499. tmp = mods[i];
  500. for ( j = i; mods[j] != NULL; j++ ) {
  501. mods[j] = mods[j + 1];
  502. }
  503. slapi_ch_free( (void**)&(tmp->mod_type) );
  504. if ( tmp->mod_bvalues != NULL ) {
  505. ber_bvecfree( tmp->mod_bvalues );
  506. }
  507. slapi_ch_free( (void**)&tmp );
  508. i--;
  509. }
  510. }
  511. }
  512. /* A mod has no effect if it is trying to replace a non-existing
  513. * attribute with null value
  514. */
  515. static int
  516. mods_have_effect (Slapi_Entry *entry, Slapi_Mods *smods)
  517. {
  518. LDAPMod *mod;
  519. Slapi_Attr *attr;
  520. int have_effect = 1;
  521. int j;
  522. /* Mods have effect if there is at least a non-replace mod or
  523. * a non-null-value mod.
  524. */
  525. for ( j = 0; j < smods->num_mods - 1; j++ ) {
  526. if ( (mod = smods->mods[j]) != NULL ) {
  527. if ( ((mod->mod_op & LDAP_MOD_REPLACE) == 0) ||
  528. (mod->mod_vals.modv_bvals &&
  529. strcasecmp (mod->mod_type, "modifiersname") &&
  530. strcasecmp (mod->mod_type, "modifytime") ) ) {
  531. goto done;
  532. }
  533. }
  534. }
  535. if ( entry && entry->e_sdn.dn ) {
  536. for ( j = 0; j < smods->num_mods - 1; j++ ) {
  537. if ( ((mod = smods->mods[j]) != NULL) &&
  538. strcasecmp (mod->mod_type, "modifiersname") &&
  539. strcasecmp (mod->mod_type, "modifytime") ) {
  540. for ( attr = entry->e_attrs; attr; attr = attr->a_next ) {
  541. /* Mods have effect if at least a null-value-mod is
  542. * to actually remove an existing attribute
  543. */
  544. if ( strcasecmp ( mod->mod_type, attr->a_type ) == 0 ) {
  545. goto done;
  546. }
  547. }
  548. have_effect = 0;
  549. }
  550. }
  551. }
  552. done:
  553. /* Return true would let the flow continue along the old path before
  554. * this function was added
  555. */
  556. return have_effect;
  557. }