repl5_replica_config.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  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. /* repl5_replica_config.c - replica configuration over ldap */
  42. #include <ctype.h> /* for isdigit() */
  43. #include "repl.h" /* ONREPL - this is bad */
  44. #include "repl5.h"
  45. #include "cl5_api.h"
  46. #include "cl5.h"
  47. /* CONFIG_BASE: no need to optimize */
  48. #define CONFIG_BASE "cn=mapping tree,cn=config"
  49. #define CONFIG_FILTER "(objectclass=nsDS5Replica)"
  50. #define TASK_ATTR "nsds5Task"
  51. #define CL2LDIF_TASK "CL2LDIF"
  52. #define LDIF2CL_TASK "LDIF2CL"
  53. #define CLEANRUV "CLEANRUV"
  54. #define CLEANRUVLEN 8
  55. #define REPLICA_RDN "cn=replica"
  56. int slapi_log_urp = SLAPI_LOG_REPL;
  57. /* Forward Declartions */
  58. static int replica_config_add (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg);
  59. static int replica_config_modify (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg);
  60. static int replica_config_post_modify (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg);
  61. static int replica_config_delete (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg);
  62. static int replica_config_search (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg);
  63. static int replica_config_change_type_and_id (Replica *r, const char *new_type, const char *new_id, char *returntext, int apply_mods);
  64. static int replica_config_change_updatedn (Replica *r, const LDAPMod *mod, char *returntext, int apply_mods);
  65. static int replica_config_change_flags (Replica *r, const char *new_flags, char *returntext, int apply_mods);
  66. static int replica_execute_task (Object *r, const char *task_name, char *returntext, int apply_mods);
  67. static int replica_execute_cl2ldif_task (Object *r, char *returntext);
  68. static int replica_execute_ldif2cl_task (Object *r, char *returntext);
  69. static int replica_execute_cleanruv_task (Object *r, ReplicaId rid, char *returntext);
  70. static int replica_cleanup_task (Object *r, const char *task_name, char *returntext, int apply_mods);
  71. static int replica_task_done(Replica *replica);
  72. static multimaster_mtnode_extension * _replica_config_get_mtnode_ext (const Slapi_Entry *e);
  73. /*
  74. * Note: internal add/modify/delete operations should not be run while
  75. * s_configLock is held. E.g., slapi_modify_internal_pb via replica_task_done
  76. * in replica_config_post_modify.
  77. */
  78. static PRLock *s_configLock;
  79. static int
  80. dont_allow_that(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e, int *returncode, char *returntext, void *arg)
  81. {
  82. *returncode = LDAP_UNWILLING_TO_PERFORM;
  83. return SLAPI_DSE_CALLBACK_ERROR;
  84. }
  85. int
  86. replica_config_init()
  87. {
  88. s_configLock = PR_NewLock ();
  89. if (s_configLock == NULL)
  90. {
  91. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_init: "
  92. "failed to cretate configuration lock; NSPR error - %d\n",
  93. PR_GetError ());
  94. return -1;
  95. }
  96. /* config DSE must be initialized before we get here */
  97. slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  98. CONFIG_FILTER, replica_config_add, NULL);
  99. slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  100. CONFIG_FILTER, replica_config_modify,NULL);
  101. slapi_config_register_callback(SLAPI_OPERATION_MODRDN, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  102. CONFIG_FILTER, dont_allow_that, NULL);
  103. slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  104. CONFIG_FILTER, replica_config_delete,NULL);
  105. slapi_config_register_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  106. CONFIG_FILTER, replica_config_search,NULL);
  107. slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_POSTOP,
  108. CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  109. CONFIG_FILTER, replica_config_post_modify,
  110. NULL);
  111. return 0;
  112. }
  113. void
  114. replica_config_destroy ()
  115. {
  116. if (s_configLock)
  117. {
  118. PR_DestroyLock (s_configLock);
  119. s_configLock = NULL;
  120. }
  121. /* config DSE must be initialized before we get here */
  122. slapi_config_remove_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  123. CONFIG_FILTER, replica_config_add);
  124. slapi_config_remove_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  125. CONFIG_FILTER, replica_config_modify);
  126. slapi_config_remove_callback(SLAPI_OPERATION_MODRDN, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  127. CONFIG_FILTER, dont_allow_that);
  128. slapi_config_remove_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  129. CONFIG_FILTER, replica_config_delete);
  130. slapi_config_remove_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  131. CONFIG_FILTER, replica_config_search);
  132. slapi_config_remove_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP,
  133. CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  134. CONFIG_FILTER, replica_config_post_modify);
  135. }
  136. static int
  137. replica_config_add (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter,
  138. int *returncode, char *errorbuf, void *arg)
  139. {
  140. Replica *r = NULL;
  141. multimaster_mtnode_extension *mtnode_ext;
  142. char *replica_root = (char*)slapi_entry_attr_get_charptr (e, attr_replicaRoot);
  143. char buf [SLAPI_DSE_RETURNTEXT_SIZE];
  144. char *errortext = errorbuf ? errorbuf : buf;
  145. if (errorbuf)
  146. {
  147. errorbuf[0] = '\0';
  148. }
  149. *returncode = LDAP_SUCCESS;
  150. PR_Lock (s_configLock);
  151. /* add the dn to the dn hash so we can tell this replica is being configured */
  152. replica_add_by_dn(replica_root);
  153. mtnode_ext = _replica_config_get_mtnode_ext (e);
  154. PR_ASSERT (mtnode_ext);
  155. if (mtnode_ext->replica)
  156. {
  157. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE, "replica already configured for %s", replica_root);
  158. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_add: %s\n", errortext);
  159. *returncode = LDAP_UNWILLING_TO_PERFORM;
  160. goto done;
  161. }
  162. /* create replica object */
  163. r = replica_new_from_entry (e, errortext, PR_TRUE /* is a newly added entry */);
  164. if (r == NULL)
  165. {
  166. *returncode = LDAP_OPERATIONS_ERROR;
  167. goto done;
  168. }
  169. /* Set the mapping tree node state, and the referrals from the RUV */
  170. /* if this server is a 4.0 consumer the referrals are set by legacy plugin */
  171. if (!replica_is_legacy_consumer (r))
  172. consumer5_set_mapping_tree_state_for_replica(r, NULL);
  173. /* ONREPL if replica is added as writable we need to execute protocol that
  174. introduces new writable replica to the topology */
  175. mtnode_ext->replica = object_new (r, replica_destroy); /* Refcnt is 1 */
  176. /* add replica object to the hash */
  177. *returncode = replica_add_by_name (replica_get_name (r), mtnode_ext->replica); /* Increments object refcnt */
  178. /* delete the dn from the dn hash - done with configuration */
  179. replica_delete_by_dn(replica_root);
  180. done:
  181. PR_Unlock (s_configLock);
  182. /* slapi_ch_free accepts NULL pointer */
  183. slapi_ch_free ((void**)&replica_root);
  184. if (*returncode != LDAP_SUCCESS)
  185. {
  186. if (mtnode_ext->replica)
  187. object_release (mtnode_ext->replica);
  188. return SLAPI_DSE_CALLBACK_ERROR;
  189. }
  190. else
  191. return SLAPI_DSE_CALLBACK_OK;
  192. }
  193. static int
  194. replica_config_modify (Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e,
  195. int *returncode, char *returntext, void *arg)
  196. {
  197. int rc= 0;
  198. LDAPMod **mods;
  199. int i, apply_mods;
  200. multimaster_mtnode_extension *mtnode_ext;
  201. Replica *r = NULL;
  202. char *replica_root = NULL;
  203. char buf [SLAPI_DSE_RETURNTEXT_SIZE];
  204. char *errortext = returntext ? returntext : buf;
  205. char *config_attr, *config_attr_value;
  206. Slapi_Operation *op;
  207. void *identity;
  208. if (returntext)
  209. {
  210. returntext[0] = '\0';
  211. }
  212. *returncode = LDAP_SUCCESS;
  213. /* just let internal operations originated from replication plugin to go through */
  214. slapi_pblock_get (pb, SLAPI_OPERATION, &op);
  215. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
  216. if (operation_is_flag_set(op, OP_FLAG_INTERNAL) &&
  217. (identity == repl_get_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION)))
  218. {
  219. *returncode = LDAP_SUCCESS;
  220. return SLAPI_DSE_CALLBACK_OK;
  221. }
  222. replica_root = (char*)slapi_entry_attr_get_charptr (e, attr_replicaRoot);
  223. PR_Lock (s_configLock);
  224. mtnode_ext = _replica_config_get_mtnode_ext (e);
  225. PR_ASSERT (mtnode_ext);
  226. if (mtnode_ext->replica)
  227. object_acquire (mtnode_ext->replica);
  228. if (mtnode_ext->replica == NULL)
  229. {
  230. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE, "replica does not exist for %s", replica_root);
  231. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_modify: %s\n",
  232. errortext);
  233. *returncode = LDAP_OPERATIONS_ERROR;
  234. goto done;
  235. }
  236. r = object_get_data (mtnode_ext->replica);
  237. PR_ASSERT (r);
  238. slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &mods);
  239. for (apply_mods = 0; apply_mods <= 1; apply_mods++)
  240. {
  241. /* we only allow the replica ID and type to be modified together e.g.
  242. if converting a read only replica to a master or vice versa -
  243. we will need to change both the replica ID and the type at the same
  244. time - we must disallow changing the replica ID if the type is not
  245. being changed and vice versa
  246. */
  247. char *new_repl_id = NULL;
  248. char *new_repl_type = NULL;
  249. if (*returncode != LDAP_SUCCESS)
  250. break;
  251. for (i = 0; (mods[i] && (LDAP_SUCCESS == rc)); i++)
  252. {
  253. if (*returncode != LDAP_SUCCESS)
  254. break;
  255. config_attr = (char *) mods[i]->mod_type;
  256. PR_ASSERT (config_attr);
  257. /* disallow modifications or removal of replica root,
  258. replica name and replica state attributes */
  259. if (strcasecmp (config_attr, attr_replicaRoot) == 0 ||
  260. strcasecmp (config_attr, attr_replicaName) == 0 ||
  261. strcasecmp (config_attr, attr_state) == 0)
  262. {
  263. *returncode = LDAP_UNWILLING_TO_PERFORM;
  264. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE, "modification of %s attribute is not allowed",
  265. config_attr);
  266. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_modify: %s\n",
  267. errortext);
  268. }
  269. /* this is a request to delete an attribute */
  270. else if (mods[i]->mod_op & LDAP_MOD_DELETE || mods[i]->mod_bvalues == NULL
  271. || mods[i]->mod_bvalues[0]->bv_val == NULL)
  272. {
  273. /* currently, you can only remove referral,
  274. legacy consumer or bind dn attribute */
  275. if (strcasecmp (config_attr, attr_replicaBindDn) == 0)
  276. {
  277. *returncode = replica_config_change_updatedn (r, mods[i], errortext, apply_mods);
  278. }
  279. else if (strcasecmp (config_attr, attr_replicaReferral) == 0)
  280. {
  281. if (apply_mods) {
  282. replica_set_referrals(r, NULL);
  283. if (!replica_is_legacy_consumer (r)) {
  284. consumer5_set_mapping_tree_state_for_replica(r, NULL);
  285. }
  286. }
  287. }
  288. else if (strcasecmp (config_attr, type_replicaLegacyConsumer) == 0)
  289. {
  290. if (apply_mods)
  291. replica_set_legacy_consumer (r, PR_FALSE);
  292. }
  293. else
  294. {
  295. *returncode = LDAP_UNWILLING_TO_PERFORM;
  296. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE, "deletion of %s attribute is not allowed", config_attr);
  297. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_modify: %s\n",
  298. errortext);
  299. }
  300. }
  301. else /* modify an attribute */
  302. {
  303. config_attr_value = (char *) mods[i]->mod_bvalues[0]->bv_val;
  304. if (strcasecmp (config_attr, attr_replicaBindDn) == 0)
  305. {
  306. *returncode = replica_config_change_updatedn (r, mods[i],
  307. errortext, apply_mods);
  308. }
  309. else if (strcasecmp (config_attr, attr_replicaType) == 0)
  310. {
  311. new_repl_type = slapi_ch_strdup(config_attr_value);
  312. }
  313. else if (strcasecmp (config_attr, attr_replicaId) == 0)
  314. {
  315. new_repl_id = slapi_ch_strdup(config_attr_value);
  316. }
  317. else if (strcasecmp (config_attr, attr_flags) == 0)
  318. {
  319. *returncode = replica_config_change_flags (r, config_attr_value,
  320. errortext, apply_mods);
  321. }
  322. else if (strcasecmp (config_attr, TASK_ATTR) == 0)
  323. {
  324. *returncode = replica_execute_task (mtnode_ext->replica, config_attr_value,
  325. errortext, apply_mods);
  326. }
  327. else if (strcasecmp (config_attr, attr_replicaReferral) == 0)
  328. {
  329. if (apply_mods)
  330. {
  331. Slapi_Mod smod;
  332. Slapi_ValueSet *vs= slapi_valueset_new();
  333. slapi_mod_init_byref(&smod,mods[i]);
  334. slapi_valueset_set_from_smod(vs, &smod);
  335. replica_set_referrals (r, vs);
  336. slapi_mod_done(&smod);
  337. slapi_valueset_free(vs);
  338. if (!replica_is_legacy_consumer (r)) {
  339. consumer5_set_mapping_tree_state_for_replica(r, NULL);
  340. }
  341. }
  342. }
  343. else if (strcasecmp (config_attr, type_replicaPurgeDelay) == 0)
  344. {
  345. if (apply_mods && config_attr_value && config_attr_value[0])
  346. {
  347. PRUint32 delay;
  348. if (isdigit (config_attr_value[0]))
  349. {
  350. delay = (unsigned int)atoi(config_attr_value);
  351. replica_set_purge_delay(r, delay);
  352. }
  353. else
  354. *returncode = LDAP_OPERATIONS_ERROR;
  355. }
  356. }
  357. else if (strcasecmp (config_attr, type_replicaTombstonePurgeInterval) == 0)
  358. {
  359. if (apply_mods && config_attr_value && config_attr_value[0])
  360. {
  361. long interval;
  362. interval = atol (config_attr_value);
  363. replica_set_tombstone_reap_interval (r, interval);
  364. }
  365. }
  366. else if (strcasecmp (config_attr, type_replicaLegacyConsumer) == 0)
  367. {
  368. if (apply_mods)
  369. {
  370. PRBool legacy = (strcasecmp (config_attr_value, "on") == 0) ||
  371. (strcasecmp (config_attr_value, "true") == 0) ||
  372. (strcasecmp (config_attr_value, "yes") == 0) ||
  373. (strcasecmp (config_attr_value, "1") == 0);
  374. replica_set_legacy_consumer (r, legacy);
  375. }
  376. }
  377. /* ignore modifiers attributes added by the server */
  378. else if (strcasecmp (config_attr, "modifytimestamp") == 0 ||
  379. strcasecmp (config_attr, "modifiersname") == 0)
  380. {
  381. *returncode = LDAP_SUCCESS;
  382. }
  383. else
  384. {
  385. *returncode = LDAP_UNWILLING_TO_PERFORM;
  386. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE,
  387. "modification of attribute %s is not allowed in replica entry", config_attr);
  388. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_modify: %s\n",
  389. errortext);
  390. }
  391. }
  392. }
  393. if (new_repl_id || new_repl_type)
  394. {
  395. *returncode = replica_config_change_type_and_id(r, new_repl_type,
  396. new_repl_id, errortext,
  397. apply_mods);
  398. slapi_ch_free_string(&new_repl_id);
  399. slapi_ch_free_string(&new_repl_type);
  400. }
  401. }
  402. done:
  403. if (mtnode_ext->replica)
  404. object_release (mtnode_ext->replica);
  405. /* slapi_ch_free accepts NULL pointer */
  406. slapi_ch_free ((void**)&replica_root);
  407. PR_Unlock (s_configLock);
  408. if (*returncode != LDAP_SUCCESS)
  409. {
  410. return SLAPI_DSE_CALLBACK_ERROR;
  411. }
  412. else
  413. {
  414. return SLAPI_DSE_CALLBACK_OK;
  415. }
  416. }
  417. static int
  418. replica_config_post_modify(Slapi_PBlock *pb,
  419. Slapi_Entry* entryBefore,
  420. Slapi_Entry* e,
  421. int *returncode,
  422. char *returntext,
  423. void *arg)
  424. {
  425. int rc= 0;
  426. LDAPMod **mods;
  427. int i, apply_mods;
  428. multimaster_mtnode_extension *mtnode_ext;
  429. Replica *r = NULL;
  430. char *replica_root = NULL;
  431. char buf [SLAPI_DSE_RETURNTEXT_SIZE];
  432. char *errortext = returntext ? returntext : buf;
  433. char *config_attr, *config_attr_value;
  434. Slapi_Operation *op;
  435. void *identity;
  436. int flag_need_cleanup = 0;
  437. if (returntext)
  438. {
  439. returntext[0] = '\0';
  440. }
  441. *returncode = LDAP_SUCCESS;
  442. /* just let internal operations originated from replication plugin to go through */
  443. slapi_pblock_get (pb, SLAPI_OPERATION, &op);
  444. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
  445. if (operation_is_flag_set(op, OP_FLAG_INTERNAL) &&
  446. (identity == repl_get_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION)))
  447. {
  448. *returncode = LDAP_SUCCESS;
  449. return SLAPI_DSE_CALLBACK_OK;
  450. }
  451. replica_root = (char*)slapi_entry_attr_get_charptr (e, attr_replicaRoot);
  452. PR_Lock (s_configLock);
  453. mtnode_ext = _replica_config_get_mtnode_ext (e);
  454. PR_ASSERT (mtnode_ext);
  455. if (mtnode_ext->replica)
  456. object_acquire (mtnode_ext->replica);
  457. if (mtnode_ext->replica == NULL)
  458. {
  459. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE,
  460. "replica does not exist for %s", replica_root);
  461. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  462. "replica_config_post_modify: %s\n",
  463. errortext);
  464. *returncode = LDAP_OPERATIONS_ERROR;
  465. goto done;
  466. }
  467. r = object_get_data (mtnode_ext->replica);
  468. PR_ASSERT (r);
  469. slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &mods);
  470. for (apply_mods = 0; apply_mods <= 1; apply_mods++)
  471. {
  472. /* we only allow the replica ID and type to be modified together e.g.
  473. if converting a read only replica to a master or vice versa -
  474. we will need to change both the replica ID and the type at the same
  475. time - we must disallow changing the replica ID if the type is not
  476. being changed and vice versa
  477. */
  478. if (*returncode != LDAP_SUCCESS)
  479. break;
  480. for (i = 0; (mods[i] && (LDAP_SUCCESS == rc)); i++)
  481. {
  482. if (*returncode != LDAP_SUCCESS)
  483. break;
  484. config_attr = (char *) mods[i]->mod_type;
  485. PR_ASSERT (config_attr);
  486. /* disallow modifications or removal of replica root,
  487. replica name and replica state attributes */
  488. if (strcasecmp (config_attr, attr_replicaRoot) == 0 ||
  489. strcasecmp (config_attr, attr_replicaName) == 0 ||
  490. strcasecmp (config_attr, attr_state) == 0)
  491. {
  492. *returncode = LDAP_UNWILLING_TO_PERFORM;
  493. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE,
  494. "modification of %s attribute is not allowed",
  495. config_attr);
  496. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  497. "replica_config_post_modify: %s\n",
  498. errortext);
  499. }
  500. /* this is a request to delete an attribute */
  501. else if (mods[i]->mod_op & LDAP_MOD_DELETE ||
  502. mods[i]->mod_bvalues == NULL ||
  503. mods[i]->mod_bvalues[0]->bv_val == NULL)
  504. {
  505. ;
  506. }
  507. else /* modify an attribute */
  508. {
  509. config_attr_value = (char *) mods[i]->mod_bvalues[0]->bv_val;
  510. if (strcasecmp (config_attr, TASK_ATTR) == 0)
  511. {
  512. flag_need_cleanup = 1;
  513. }
  514. }
  515. }
  516. }
  517. done:
  518. PR_Unlock (s_configLock);
  519. /* slapi_ch_free accepts NULL pointer */
  520. slapi_ch_free_string (&replica_root);
  521. /* Call replica_cleanup_task after s_configLock is reliesed */
  522. if (flag_need_cleanup)
  523. {
  524. *returncode = replica_cleanup_task(mtnode_ext->replica,
  525. config_attr_value,
  526. errortext, apply_mods);
  527. }
  528. if (mtnode_ext->replica)
  529. object_release (mtnode_ext->replica);
  530. if (*returncode != LDAP_SUCCESS)
  531. {
  532. return SLAPI_DSE_CALLBACK_ERROR;
  533. }
  534. else
  535. {
  536. return SLAPI_DSE_CALLBACK_OK;
  537. }
  538. }
  539. static int
  540. replica_config_delete (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter,
  541. int *returncode, char *returntext, void *arg)
  542. {
  543. multimaster_mtnode_extension *mtnode_ext;
  544. Replica *r;
  545. PR_Lock (s_configLock);
  546. mtnode_ext = _replica_config_get_mtnode_ext (e);
  547. PR_ASSERT (mtnode_ext);
  548. if (mtnode_ext->replica)
  549. {
  550. char ebuf[BUFSIZ];
  551. /* remove object from the hash */
  552. r = (Replica*)object_get_data (mtnode_ext->replica);
  553. PR_ASSERT (r);
  554. /* The changelog for this replica is no longer valid, so we should remove it. */
  555. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_delete: "
  556. "Warning: The changelog for replica %s is no longer valid since "
  557. "the replica config is being deleted. Removing the changelog.\n",
  558. escape_string(slapi_sdn_get_dn(replica_get_root(r)),ebuf));
  559. cl5DeleteDBSync(mtnode_ext->replica);
  560. replica_delete_by_name (replica_get_name (r));
  561. object_release (mtnode_ext->replica);
  562. mtnode_ext->replica = NULL;
  563. }
  564. PR_Unlock (s_configLock);
  565. *returncode = LDAP_SUCCESS;
  566. return SLAPI_DSE_CALLBACK_OK;
  567. }
  568. static int
  569. replica_config_search (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode,
  570. char *returntext, void *arg)
  571. {
  572. multimaster_mtnode_extension *mtnode_ext;
  573. int changeCount = 0;
  574. PRBool reapActive = PR_FALSE;
  575. char val [64];
  576. /* add attribute that contains number of entries in the changelog for this replica */
  577. PR_Lock (s_configLock);
  578. mtnode_ext = _replica_config_get_mtnode_ext (e);
  579. PR_ASSERT (mtnode_ext);
  580. if (mtnode_ext->replica) {
  581. Replica *replica;
  582. object_acquire (mtnode_ext->replica);
  583. if (cl5GetState () == CL5_STATE_OPEN) {
  584. changeCount = cl5GetOperationCount (mtnode_ext->replica);
  585. }
  586. replica = (Replica*)object_get_data (mtnode_ext->replica);
  587. if (replica) {
  588. reapActive = replica_get_tombstone_reap_active(replica);
  589. }
  590. object_release (mtnode_ext->replica);
  591. }
  592. sprintf (val, "%d", changeCount);
  593. slapi_entry_add_string (e, type_replicaChangeCount, val);
  594. slapi_entry_attr_set_int(e, "nsds5replicaReapActive", (int)reapActive);
  595. PR_Unlock (s_configLock);
  596. return SLAPI_DSE_CALLBACK_OK;
  597. }
  598. static int
  599. replica_config_change_type_and_id (Replica *r, const char *new_type,
  600. const char *new_id, char *returntext,
  601. int apply_mods)
  602. {
  603. int type;
  604. ReplicaType oldtype;
  605. ReplicaId rid;
  606. ReplicaId oldrid;
  607. PR_ASSERT (r);
  608. oldtype = replica_get_type(r);
  609. oldrid = replica_get_rid(r);
  610. if (new_type == NULL) /* by default - replica is read-only */
  611. {
  612. type = REPLICA_TYPE_READONLY;
  613. }
  614. else
  615. {
  616. type = atoi (new_type);
  617. if (type <= REPLICA_TYPE_UNKNOWN || type >= REPLICA_TYPE_END)
  618. {
  619. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "invalid replica type %d", type);
  620. return LDAP_OPERATIONS_ERROR;
  621. }
  622. }
  623. /* disallow changing type to itself just to permit a replica ID change */
  624. if (oldtype == type)
  625. {
  626. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "replica type is already %d - not changing", type);
  627. return LDAP_OPERATIONS_ERROR;
  628. }
  629. if (type == REPLICA_TYPE_READONLY)
  630. {
  631. rid = READ_ONLY_REPLICA_ID; /* default rid for read only */
  632. }
  633. else if (!new_id)
  634. {
  635. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "a replica ID is required when changing replica type to read-write");
  636. return LDAP_UNWILLING_TO_PERFORM;
  637. }
  638. else
  639. {
  640. int temprid = atoi (new_id);
  641. if (temprid <= 0 || temprid >= READ_ONLY_REPLICA_ID)
  642. {
  643. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  644. "attribute %s must have a value greater than 0 "
  645. "and less than %d",
  646. attr_replicaId, READ_ONLY_REPLICA_ID);
  647. return LDAP_UNWILLING_TO_PERFORM;
  648. }
  649. else
  650. {
  651. rid = (ReplicaId)temprid;
  652. }
  653. }
  654. /* error if old rid == new rid */
  655. if (oldrid == rid)
  656. {
  657. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "replica ID is already %d - not changing", rid);
  658. return LDAP_OPERATIONS_ERROR;
  659. }
  660. if (apply_mods)
  661. {
  662. replica_set_type (r, type);
  663. replica_set_rid(r, rid);
  664. /* Set the mapping tree node, and the list of referrals */
  665. /* if this server is a 4.0 consumer the referrals are set by legacy plugin */
  666. if (!replica_is_legacy_consumer(r))
  667. consumer5_set_mapping_tree_state_for_replica(r, NULL);
  668. }
  669. return LDAP_SUCCESS;
  670. }
  671. static int
  672. replica_config_change_updatedn (Replica *r, const LDAPMod *mod, char *returntext,
  673. int apply_mods)
  674. {
  675. PR_ASSERT (r);
  676. if (apply_mods)
  677. {
  678. Slapi_Mod smod;
  679. Slapi_ValueSet *vs= slapi_valueset_new();
  680. slapi_mod_init_byref(&smod, (LDAPMod *)mod); /* cast away const */
  681. slapi_valueset_set_from_smod(vs, &smod);
  682. replica_set_updatedn(r, vs, mod->mod_op);
  683. slapi_mod_done(&smod);
  684. slapi_valueset_free(vs);
  685. }
  686. return LDAP_SUCCESS;
  687. }
  688. static int replica_config_change_flags (Replica *r, const char *new_flags,
  689. char *returntext, int apply_mods)
  690. {
  691. PR_ASSERT (r);
  692. if (apply_mods)
  693. {
  694. PRUint32 flags;
  695. flags = atol (new_flags);
  696. replica_replace_flags (r, flags);
  697. }
  698. return LDAP_SUCCESS;
  699. }
  700. static int replica_execute_task (Object *r, const char *task_name, char *returntext,
  701. int apply_mods)
  702. {
  703. if (strcasecmp (task_name, CL2LDIF_TASK) == 0)
  704. {
  705. if (apply_mods)
  706. {
  707. return replica_execute_cl2ldif_task (r, returntext);
  708. }
  709. else
  710. return LDAP_SUCCESS;
  711. }
  712. else if (strcasecmp (task_name, LDIF2CL_TASK) == 0)
  713. {
  714. if (apply_mods)
  715. {
  716. return replica_execute_ldif2cl_task (r, returntext);
  717. }
  718. else
  719. return LDAP_SUCCESS;
  720. }
  721. else if (strncasecmp (task_name, CLEANRUV, CLEANRUVLEN) == 0)
  722. {
  723. int temprid = atoi(&(task_name[CLEANRUVLEN]));
  724. if (temprid <= 0 || temprid >= READ_ONLY_REPLICA_ID){
  725. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  726. "Invalid replica id for task - %s", task_name);
  727. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  728. "replica_execute_task: %s\n", returntext);
  729. return LDAP_OPERATIONS_ERROR;
  730. }
  731. if (apply_mods)
  732. {
  733. return replica_execute_cleanruv_task (r, (ReplicaId)temprid, returntext);
  734. }
  735. else
  736. return LDAP_SUCCESS;
  737. }
  738. else
  739. {
  740. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "unsupported replica task - %s", task_name);
  741. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  742. "replica_execute_task: %s\n", returntext);
  743. return LDAP_OPERATIONS_ERROR;
  744. }
  745. }
  746. static int
  747. replica_cleanup_task (Object *r, const char *task_name, char *returntext,
  748. int apply_mods)
  749. {
  750. int rc = LDAP_SUCCESS;
  751. if (apply_mods) {
  752. Replica *replica = (Replica*)object_get_data (r);
  753. if (NULL == replica) {
  754. rc = LDAP_OPERATIONS_ERROR;
  755. } else {
  756. rc = replica_task_done(replica);
  757. }
  758. }
  759. return rc;
  760. }
  761. static int
  762. replica_task_done(Replica *replica)
  763. {
  764. int rc = LDAP_OPERATIONS_ERROR;
  765. char *replica_dn = NULL;
  766. Slapi_PBlock *pb = NULL;
  767. LDAPMod *mods [2];
  768. LDAPMod mod;
  769. if (NULL == replica) {
  770. return rc;
  771. }
  772. /* dn: cn=replica,cn=dc\3Dexample\2Cdc\3Dcom,cn=mapping tree,cn=config */
  773. replica_dn = slapi_create_dn_string("%s,cn=\"%s\",%s",
  774. REPLICA_RDN,
  775. slapi_sdn_get_dn(replica_get_root(replica)),
  776. CONFIG_BASE);
  777. if (NULL == replica_dn) {
  778. return rc;
  779. }
  780. pb = slapi_pblock_new();
  781. mods[0] = &mod;
  782. mods[1] = NULL;
  783. mod.mod_op = LDAP_MOD_DELETE | LDAP_MOD_BVALUES;
  784. mod.mod_type = (char *)TASK_ATTR;
  785. mod.mod_bvalues = NULL;
  786. slapi_modify_internal_set_pb(pb, replica_dn, mods, NULL/* controls */,
  787. NULL/* uniqueid */,
  788. repl_get_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION),
  789. 0/* flags */);
  790. slapi_modify_internal_pb (pb);
  791. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  792. if ((rc != LDAP_SUCCESS) && (rc != LDAP_NO_SUCH_ATTRIBUTE)) {
  793. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  794. "replica_task_done: "
  795. "failed to remove (%s) attribute from (%s) entry; "
  796. "LDAP error - %d\n",
  797. TASK_ATTR, replica_dn, rc);
  798. }
  799. slapi_pblock_destroy (pb);
  800. slapi_ch_free_string(&replica_dn);
  801. return rc;
  802. }
  803. static int replica_execute_cl2ldif_task (Object *r, char *returntext)
  804. {
  805. int rc;
  806. Object *rlist [2];
  807. Replica *replica;
  808. char fName [MAXPATHLEN];
  809. char *clDir = NULL;
  810. if (cl5GetState () != CL5_STATE_OPEN)
  811. {
  812. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "changelog is not open");
  813. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  814. "replica_execute_cl2ldif_task: %s\n", returntext);
  815. rc = LDAP_OPERATIONS_ERROR;
  816. goto bail;
  817. }
  818. rlist[0] = r;
  819. rlist[1] = NULL;
  820. /* file is stored in the changelog directory and is named
  821. <replica name>.ldif */
  822. clDir = cl5GetDir ();
  823. if (NULL == clDir) {
  824. rc = LDAP_OPERATIONS_ERROR;
  825. goto bail;
  826. }
  827. replica = (Replica*)object_get_data (r);
  828. if (NULL == replica) {
  829. rc = LDAP_OPERATIONS_ERROR;
  830. goto bail;
  831. }
  832. PR_snprintf (fName, MAXPATHLEN, "%s/%s.ldif", clDir, replica_get_name (replica));
  833. slapi_ch_free_string (&clDir);
  834. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  835. "Beginning changelog export of replica \"%s\"\n",
  836. replica_get_name(replica));
  837. rc = cl5ExportLDIF (fName, rlist);
  838. if (rc == CL5_SUCCESS) {
  839. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  840. "Finished changelog export of replica \"%s\"\n",
  841. replica_get_name(replica));
  842. rc = LDAP_SUCCESS;
  843. } else {
  844. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  845. "Failed changelog export replica %s; "
  846. "changelog error - %d", replica_get_name(replica), rc);
  847. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  848. "replica_execute_cl2ldif_task: %s\n", returntext);
  849. rc = LDAP_OPERATIONS_ERROR;
  850. }
  851. bail:
  852. return rc;
  853. }
  854. static int replica_execute_ldif2cl_task (Object *r, char *returntext)
  855. {
  856. int rc, imprc = 0;
  857. Object *rlist [2];
  858. Replica *replica;
  859. char fName [MAXPATHLEN];
  860. char *clDir = NULL;
  861. changelog5Config config;
  862. if (cl5GetState () != CL5_STATE_OPEN)
  863. {
  864. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "changelog is not open");
  865. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  866. "replica_execute_ldif2cl_task: %s\n", returntext);
  867. rc = LDAP_OPERATIONS_ERROR;
  868. goto bail;
  869. }
  870. rlist[0] = r;
  871. rlist[1] = NULL;
  872. /* file is stored in the changelog directory and is named
  873. <replica name>.ldif */
  874. clDir = cl5GetDir ();
  875. if (NULL == clDir) {
  876. rc = LDAP_OPERATIONS_ERROR;
  877. goto bail;
  878. }
  879. replica = (Replica*)object_get_data (r);
  880. if (NULL == replica) {
  881. rc = LDAP_OPERATIONS_ERROR;
  882. goto bail;
  883. }
  884. PR_snprintf (fName, MAXPATHLEN, "%s/%s.ldif", clDir, replica_get_name (replica));
  885. rc = cl5Close();
  886. if (rc != CL5_SUCCESS)
  887. {
  888. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  889. "failed to close changelog to import changelog data; "
  890. "changelog error - %d", rc);
  891. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  892. "replica_execute_ldif2cl_task: %s\n", returntext);
  893. rc = LDAP_OPERATIONS_ERROR;
  894. goto bail;
  895. }
  896. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  897. "Beginning changelog import of replica \"%s\"\n",
  898. replica_get_name(replica));
  899. imprc = cl5ImportLDIF (clDir, fName, rlist);
  900. slapi_ch_free_string (&clDir);
  901. if (CL5_SUCCESS == imprc)
  902. {
  903. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  904. "Finished changelog import of replica \"%s\"\n",
  905. replica_get_name(replica));
  906. }
  907. else
  908. {
  909. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  910. "Failed changelog import replica %s; "
  911. "changelog error - %d", replica_get_name(replica), rc);
  912. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  913. "replica_execute_ldif2cl_task: %s\n", returntext);
  914. imprc = LDAP_OPERATIONS_ERROR;
  915. }
  916. changelog5_read_config (&config);
  917. /* restart changelog */
  918. rc = cl5Open (config.dir, &config.dbconfig);
  919. if (CL5_SUCCESS == rc)
  920. {
  921. rc = LDAP_SUCCESS;
  922. }
  923. else
  924. {
  925. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  926. "replica_execute_ldif2cl_task: failed to start changelog at %s\n",
  927. config.dir);
  928. rc = LDAP_OPERATIONS_ERROR;
  929. }
  930. bail:
  931. changelog5_config_done(&config);
  932. /* if cl5ImportLDIF returned an error, report it first. */
  933. return imprc?imprc:rc;
  934. }
  935. static multimaster_mtnode_extension *
  936. _replica_config_get_mtnode_ext (const Slapi_Entry *e)
  937. {
  938. const char *replica_root;
  939. Slapi_DN *sdn = NULL;
  940. mapping_tree_node *mtnode;
  941. multimaster_mtnode_extension *ext = NULL;
  942. char ebuf[BUFSIZ];
  943. /* retirve root of the tree for which replica is configured */
  944. replica_root = slapi_entry_attr_get_charptr (e, attr_replicaRoot);
  945. if (replica_root == NULL)
  946. {
  947. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_add: "
  948. "configuration entry %s missing %s attribute\n",
  949. escape_string(slapi_entry_get_dn((Slapi_Entry *)e), ebuf),
  950. attr_replicaRoot);
  951. return NULL;
  952. }
  953. sdn = slapi_sdn_new_dn_passin (replica_root);
  954. /* locate mapping tree node for the specified subtree */
  955. mtnode = slapi_get_mapping_tree_node_by_dn (sdn);
  956. if (mtnode == NULL)
  957. {
  958. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_add: "
  959. "failed to locate mapping tree node for dn %s\n",
  960. escape_string(slapi_sdn_get_dn(sdn), ebuf));
  961. }
  962. else
  963. {
  964. /* check if replica object already exists for the specified subtree */
  965. ext = (multimaster_mtnode_extension *)repl_con_get_ext (REPL_CON_EXT_MTNODE, mtnode);
  966. }
  967. slapi_sdn_free (&sdn);
  968. return ext;
  969. }
  970. static int
  971. replica_execute_cleanruv_task (Object *r, ReplicaId rid, char *returntext)
  972. {
  973. int rc = 0;
  974. Object *RUVObj;
  975. RUV *local_ruv = NULL;
  976. Replica *replica = (Replica*)object_get_data (r);
  977. PR_ASSERT (replica);
  978. RUVObj = replica_get_ruv(replica);
  979. PR_ASSERT(RUVObj);
  980. local_ruv = (RUV*)object_get_data (RUVObj);
  981. /* Need to check that :
  982. * - rid is not the local one
  983. * - rid is not the last one
  984. */
  985. if ((replica_get_rid(replica) == rid) ||
  986. (ruv_replica_count(local_ruv) <= 1)) {
  987. return LDAP_UNWILLING_TO_PERFORM;
  988. }
  989. rc = ruv_delete_replica(local_ruv, rid);
  990. replica_set_ruv_dirty(replica);
  991. replica_write_ruv(replica);
  992. object_release(RUVObj);
  993. /* Update Mapping Tree to reflect RUV changes */
  994. consumer5_set_mapping_tree_state_for_replica(replica, NULL);
  995. if (rc != RUV_SUCCESS){
  996. return LDAP_OPERATIONS_ERROR;
  997. }
  998. return LDAP_SUCCESS;
  999. }