ldbm_modify.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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. back_txn txn;
  178. back_txnid parent_txn;
  179. int retval = -1;
  180. char *msg;
  181. char *errbuf = NULL;
  182. int retry_count = 0;
  183. int disk_full = 0;
  184. int ldap_result_code= LDAP_SUCCESS;
  185. char *ldap_result_message= NULL;
  186. int rc = 0;
  187. Slapi_Operation *operation;
  188. int dblock_acquired= 0;
  189. entry_address *addr;
  190. int change_entry = 0;
  191. int ec_in_cache = 0;
  192. int is_fixup_operation= 0;
  193. int is_ruv = 0; /* True if the current entry is RUV */
  194. CSN *opcsn = NULL;
  195. int i = 0;
  196. slapi_pblock_get( pb, SLAPI_BACKEND, &be);
  197. slapi_pblock_get( pb, SLAPI_PLUGIN_PRIVATE, &li );
  198. slapi_pblock_get( pb, SLAPI_TARGET_ADDRESS, &addr );
  199. slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &mods );
  200. slapi_pblock_get( pb, SLAPI_PARENT_TXN, (void**)&parent_txn );
  201. slapi_pblock_get( pb, SLAPI_OPERATION, &operation );
  202. is_fixup_operation = operation_is_flag_set(operation, OP_FLAG_REPL_FIXUP);
  203. is_ruv = operation_is_flag_set(operation, OP_FLAG_REPL_RUV);
  204. inst = (ldbm_instance *) be->be_instance_info;
  205. dblayer_txn_init(li,&txn);
  206. /* The dblock serializes writes to the database,
  207. * which reduces deadlocking in the db code,
  208. * which means that we run faster.
  209. *
  210. * But, this lock is re-enterant for the fixup
  211. * operations that the URP code in the Replication
  212. * plugin generates.
  213. */
  214. if(SERIALLOCK(li) && !operation_is_flag_set(operation,OP_FLAG_REPL_FIXUP)) {
  215. dblayer_lock_backend(be);
  216. dblock_acquired= 1;
  217. }
  218. /* find and lock the entry we are about to modify */
  219. if ( (e = find_entry2modify( pb, be, addr, NULL )) == NULL ) {
  220. ldap_result_code= -1;
  221. goto error_return; /* error result sent by find_entry2modify() */
  222. }
  223. if ( !is_fixup_operation )
  224. {
  225. opcsn = operation_get_csn (operation);
  226. if (NULL == opcsn && operation->o_csngen_handler)
  227. {
  228. /*
  229. * Current op is a user request. Opcsn will be assigned
  230. * if the dn is in an updatable replica.
  231. */
  232. opcsn = entry_assign_operation_csn ( pb, e->ep_entry, NULL );
  233. }
  234. if (opcsn)
  235. {
  236. entry_set_maxcsn (e->ep_entry, opcsn);
  237. }
  238. }
  239. /* Save away a copy of the entry, before modifications */
  240. slapi_pblock_set( pb, SLAPI_ENTRY_PRE_OP, slapi_entry_dup( e->ep_entry ));
  241. if ( (ldap_result_code = plugin_call_acl_mods_access( pb, e->ep_entry, mods, &errbuf)) != LDAP_SUCCESS ) {
  242. ldap_result_message= errbuf;
  243. goto error_return;
  244. }
  245. /* create a copy of the entry and apply the changes to it */
  246. if ( (ec = backentry_dup( e )) == NULL ) {
  247. ldap_result_code= LDAP_OPERATIONS_ERROR;
  248. goto error_return;
  249. }
  250. remove_illegal_mods(mods);
  251. /* ec is the entry that our bepreop should get to mess with */
  252. slapi_pblock_set( pb, SLAPI_MODIFY_EXISTING_ENTRY, ec->ep_entry );
  253. slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  254. plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_MODIFY_FN);
  255. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  256. /* The Plugin may have messed about with some of the PBlock parameters... ie. mods */
  257. slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &mods );
  258. {
  259. Slapi_Mods smods;
  260. CSN *csn = operation_get_csn(operation);
  261. slapi_mods_init_byref(&smods,mods);
  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. slapi_mods_done(&smods);
  280. if ( !change_entry || ldap_result_code != 0 ) {
  281. /* change_entry == 0 is not an error, but we need to free lock etc */
  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. /*
  315. * make sure the entry contains all values in the RDN.
  316. * if not, the modification must have removed them.
  317. */
  318. if ( ! slapi_entry_rdn_values_present( ec->ep_entry ) ) {
  319. ldap_result_code= LDAP_NOT_ALLOWED_ON_RDN;
  320. goto error_return;
  321. }
  322. for (retry_count = 0; retry_count < RETRY_TIMES; retry_count++) {
  323. if (retry_count > 0) {
  324. dblayer_txn_abort(li,&txn);
  325. LDAPDebug( LDAP_DEBUG_TRACE, "Modify Retrying Transaction\n", 0, 0, 0 );
  326. #ifndef LDBM_NO_BACKOFF_DELAY
  327. {
  328. PRIntervalTime interval;
  329. interval = PR_MillisecondsToInterval(slapi_rand() % 100);
  330. DS_Sleep(interval);
  331. }
  332. #endif
  333. }
  334. /* Nothing above here modifies persistent store, everything after here is subject to the transaction */
  335. retval = dblayer_txn_begin(li,parent_txn,&txn);
  336. if (0 != retval) {
  337. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  338. ldap_result_code= LDAP_OPERATIONS_ERROR;
  339. goto error_return;
  340. }
  341. /*
  342. * Update the ID to Entry index.
  343. * Note that id2entry_add replaces the entry, so the Entry ID stays the same.
  344. */
  345. retval = id2entry_add( be, ec, &txn );
  346. if (DB_LOCK_DEADLOCK == retval)
  347. {
  348. /* Abort and re-try */
  349. continue;
  350. }
  351. if (0 != retval) {
  352. LDAPDebug( LDAP_DEBUG_ANY, "id2entry_add failed, err=%d %s\n",
  353. retval, (msg = dblayer_strerror( retval )) ? msg : "", 0 );
  354. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  355. ldap_result_code= LDAP_OPERATIONS_ERROR;
  356. goto error_return;
  357. }
  358. ec_in_cache = 1;
  359. retval = index_add_mods( be, (const LDAPMod**)mods, e, ec, &txn );
  360. if (DB_LOCK_DEADLOCK == retval)
  361. {
  362. /* Abort and re-try */
  363. continue;
  364. }
  365. if (0 != retval) {
  366. LDAPDebug( LDAP_DEBUG_ANY, "index_add_mods failed, err=%d %s\n",
  367. retval, (msg = dblayer_strerror( retval )) ? msg : "", 0 );
  368. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  369. ldap_result_code= LDAP_OPERATIONS_ERROR;
  370. goto error_return;
  371. }
  372. /*
  373. * Remove the old entry from the Virtual List View indexes.
  374. * Add the new entry to the Virtual List View indexes.
  375. * If the entry is ruv, no need to update vlv.
  376. */
  377. if (!is_ruv) {
  378. retval= vlv_update_all_indexes(&txn, be, pb, e, ec);
  379. if (DB_LOCK_DEADLOCK == retval)
  380. {
  381. /* Abort and re-try */
  382. continue;
  383. }
  384. if (0 != retval) {
  385. LDAPDebug( LDAP_DEBUG_ANY,
  386. "vlv_update_index failed, err=%d %s\n",
  387. retval, (msg = dblayer_strerror( retval )) ? msg : "", 0 );
  388. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  389. ldap_result_code= LDAP_OPERATIONS_ERROR;
  390. goto error_return;
  391. }
  392. }
  393. if (0 == retval) {
  394. break;
  395. }
  396. }
  397. if (retry_count == RETRY_TIMES) {
  398. LDAPDebug( LDAP_DEBUG_ANY, "Retry count exceeded in modify\n", 0, 0, 0 );
  399. ldap_result_code= LDAP_OPERATIONS_ERROR;
  400. goto error_return;
  401. }
  402. if (cache_replace( &inst->inst_cache, e, ec ) != 0 ) {
  403. ldap_result_code= LDAP_OPERATIONS_ERROR;
  404. goto error_return;
  405. }
  406. postentry = slapi_entry_dup( ec->ep_entry );
  407. slapi_pblock_set( pb, SLAPI_ENTRY_POST_OP, postentry );
  408. /* invalidate virtual cache */
  409. ec->ep_entry->e_virtual_watermark = 0;
  410. /* we must return both e (which has been deleted) and new entry ec */
  411. cache_unlock_entry( &inst->inst_cache, e );
  412. cache_return( &inst->inst_cache, &e );
  413. /*
  414. * LP Fix of crash when the commit will fail:
  415. * If the commit fail, the common error path will
  416. * try to unlock the entry again and crash (PR_ASSERT
  417. * in debug mode.
  418. * By just setting e to NULL, we avoid this. It's OK since
  419. * we don't use e after that in the normal case.
  420. */
  421. e = NULL;
  422. retval = dblayer_txn_commit(li,&txn);
  423. if (0 != retval) {
  424. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  425. ldap_result_code= LDAP_OPERATIONS_ERROR;
  426. goto error_return;
  427. }
  428. rc= 0;
  429. goto common_return;
  430. error_return:
  431. if (ec_in_cache)
  432. {
  433. cache_remove( &inst->inst_cache, ec );
  434. }
  435. else
  436. {
  437. backentry_free(&ec);
  438. }
  439. if ( postentry != NULL )
  440. {
  441. slapi_entry_free( postentry );
  442. postentry = NULL;
  443. slapi_pblock_set( pb, SLAPI_ENTRY_POST_OP, NULL );
  444. }
  445. if (e!=NULL) {
  446. cache_unlock_entry( &inst->inst_cache, e);
  447. cache_return( &inst->inst_cache, &e);
  448. }
  449. if (retval == DB_RUNRECOVERY) {
  450. dblayer_remember_disk_filled(li);
  451. ldbm_nasty("Modify",81,retval);
  452. disk_full = 1;
  453. }
  454. if (disk_full)
  455. rc= return_on_disk_full(li);
  456. else if (ldap_result_code != LDAP_SUCCESS) {
  457. /* It is specifically OK to make this call even when no transaction was in progress */
  458. dblayer_txn_abort(li,&txn); /* abort crashes in case disk full */
  459. rc= SLAPI_FAIL_GENERAL;
  460. }
  461. common_return:
  462. if (ec_in_cache)
  463. {
  464. cache_return( &inst->inst_cache, &ec );
  465. }
  466. /* JCMREPL - The bepostop is called even if the operation fails. */
  467. if (!disk_full)
  468. plugin_call_plugins (pb, SLAPI_PLUGIN_BE_POST_MODIFY_FN);
  469. if(dblock_acquired)
  470. {
  471. dblayer_unlock_backend(be);
  472. }
  473. if(ldap_result_code!=-1)
  474. {
  475. slapi_send_ldap_result( pb, ldap_result_code, NULL, ldap_result_message, 0, NULL );
  476. }
  477. slapi_ch_free( (void**)&errbuf);
  478. return rc;
  479. }
  480. /* Function removes mods which are not allowed over-the-wire */
  481. static void
  482. remove_illegal_mods(LDAPMod **mods)
  483. {
  484. int i, j;
  485. LDAPMod *tmp;
  486. /* remove any attempts by the user to modify these attrs */
  487. for ( i = 0; mods[i] != NULL; i++ ) {
  488. if ( strcasecmp( mods[i]->mod_type, numsubordinates ) == 0
  489. || strcasecmp( mods[i]->mod_type, hassubordinates ) == 0 )
  490. {
  491. tmp = mods[i];
  492. for ( j = i; mods[j] != NULL; j++ ) {
  493. mods[j] = mods[j + 1];
  494. }
  495. slapi_ch_free( (void**)&(tmp->mod_type) );
  496. if ( tmp->mod_bvalues != NULL ) {
  497. ber_bvecfree( tmp->mod_bvalues );
  498. }
  499. slapi_ch_free( (void**)&tmp );
  500. i--;
  501. }
  502. }
  503. }
  504. /* A mod has no effect if it is trying to replace a non-existing
  505. * attribute with null value
  506. */
  507. static int
  508. mods_have_effect (Slapi_Entry *entry, Slapi_Mods *smods)
  509. {
  510. LDAPMod *mod;
  511. Slapi_Attr *attr;
  512. int have_effect = 1;
  513. int j;
  514. /* Mods have effect if there is at least a non-replace mod or
  515. * a non-null-value mod.
  516. */
  517. for ( j = 0; j < smods->num_mods - 1; j++ ) {
  518. if ( (mod = smods->mods[j]) != NULL ) {
  519. if ( ((mod->mod_op & LDAP_MOD_REPLACE) == 0) ||
  520. (mod->mod_vals.modv_bvals &&
  521. strcasecmp (mod->mod_type, "modifiersname") &&
  522. strcasecmp (mod->mod_type, "modifytime") ) ) {
  523. goto done;
  524. }
  525. }
  526. }
  527. if ( entry && entry->e_sdn.dn ) {
  528. for ( j = 0; j < smods->num_mods - 1; j++ ) {
  529. if ( ((mod = smods->mods[j]) != NULL) &&
  530. strcasecmp (mod->mod_type, "modifiersname") &&
  531. strcasecmp (mod->mod_type, "modifytime") ) {
  532. for ( attr = entry->e_attrs; attr; attr = attr->a_next ) {
  533. /* Mods have effect if at least a null-value-mod is
  534. * to actually remove an existing attribute
  535. */
  536. if ( strcasecmp ( mod->mod_type, attr->a_type ) == 0 ) {
  537. goto done;
  538. }
  539. }
  540. have_effect = 0;
  541. }
  542. }
  543. }
  544. done:
  545. /* Return true would let the flow continue along the old path before
  546. * this function was added
  547. */
  548. return have_effect;
  549. }