ldbm_modify.c 20 KB

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