repl5_replica_config.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  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_DN *replica_sdn = NULL;
  767. Slapi_PBlock *pb = NULL;
  768. LDAPMod *mods [2];
  769. LDAPMod mod;
  770. if (NULL == replica) {
  771. return rc;
  772. }
  773. /* dn: cn=replica,cn=dc\3Dexample\2Cdc\3Dcom,cn=mapping tree,cn=config */
  774. replica_dn = slapi_ch_smprintf("%s,cn=\"%s\",%s",
  775. REPLICA_RDN,
  776. slapi_sdn_get_dn(replica_get_root(replica)),
  777. CONFIG_BASE);
  778. if (NULL == replica_dn) {
  779. return rc;
  780. }
  781. replica_sdn = slapi_sdn_new_dn_passin(replica_dn);
  782. pb = slapi_pblock_new();
  783. mods[0] = &mod;
  784. mods[1] = NULL;
  785. mod.mod_op = LDAP_MOD_DELETE | LDAP_MOD_BVALUES;
  786. mod.mod_type = (char *)TASK_ATTR;
  787. mod.mod_bvalues = NULL;
  788. slapi_modify_internal_set_pb_ext(pb, replica_sdn, mods, NULL/* controls */,
  789. NULL/* uniqueid */,
  790. repl_get_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION),
  791. 0/* flags */);
  792. slapi_modify_internal_pb (pb);
  793. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  794. if ((rc != LDAP_SUCCESS) && (rc != LDAP_NO_SUCH_ATTRIBUTE)) {
  795. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  796. "replica_task_done: "
  797. "failed to remove (%s) attribute from (%s) entry; "
  798. "LDAP error - %d\n",
  799. TASK_ATTR, replica_dn, rc);
  800. }
  801. slapi_pblock_destroy (pb);
  802. slapi_sdn_free(&replica_sdn);
  803. return rc;
  804. }
  805. static int replica_execute_cl2ldif_task (Object *r, char *returntext)
  806. {
  807. int rc;
  808. Object *rlist [2];
  809. Replica *replica;
  810. char fName [MAXPATHLEN];
  811. char *clDir = NULL;
  812. if (cl5GetState () != CL5_STATE_OPEN)
  813. {
  814. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "changelog is not open");
  815. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  816. "replica_execute_cl2ldif_task: %s\n", returntext);
  817. rc = LDAP_OPERATIONS_ERROR;
  818. goto bail;
  819. }
  820. rlist[0] = r;
  821. rlist[1] = NULL;
  822. /* file is stored in the changelog directory and is named
  823. <replica name>.ldif */
  824. clDir = cl5GetDir ();
  825. if (NULL == clDir) {
  826. rc = LDAP_OPERATIONS_ERROR;
  827. goto bail;
  828. }
  829. replica = (Replica*)object_get_data (r);
  830. if (NULL == replica) {
  831. rc = LDAP_OPERATIONS_ERROR;
  832. goto bail;
  833. }
  834. PR_snprintf (fName, MAXPATHLEN, "%s/%s.ldif", clDir, replica_get_name (replica));
  835. slapi_ch_free_string (&clDir);
  836. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  837. "Beginning changelog export of replica \"%s\"\n",
  838. replica_get_name(replica));
  839. rc = cl5ExportLDIF (fName, rlist);
  840. if (rc == CL5_SUCCESS) {
  841. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  842. "Finished changelog export of replica \"%s\"\n",
  843. replica_get_name(replica));
  844. rc = LDAP_SUCCESS;
  845. } else {
  846. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  847. "Failed changelog export replica %s; "
  848. "changelog error - %d", replica_get_name(replica), rc);
  849. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  850. "replica_execute_cl2ldif_task: %s\n", returntext);
  851. rc = LDAP_OPERATIONS_ERROR;
  852. }
  853. bail:
  854. return rc;
  855. }
  856. static int replica_execute_ldif2cl_task (Object *r, char *returntext)
  857. {
  858. int rc, imprc = 0;
  859. Object *rlist [2];
  860. Replica *replica;
  861. char fName [MAXPATHLEN];
  862. char *clDir = NULL;
  863. changelog5Config config;
  864. if (cl5GetState () != CL5_STATE_OPEN)
  865. {
  866. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "changelog is not open");
  867. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  868. "replica_execute_ldif2cl_task: %s\n", returntext);
  869. rc = LDAP_OPERATIONS_ERROR;
  870. goto bail;
  871. }
  872. rlist[0] = r;
  873. rlist[1] = NULL;
  874. /* file is stored in the changelog directory and is named
  875. <replica name>.ldif */
  876. clDir = cl5GetDir ();
  877. if (NULL == clDir) {
  878. rc = LDAP_OPERATIONS_ERROR;
  879. goto bail;
  880. }
  881. replica = (Replica*)object_get_data (r);
  882. if (NULL == replica) {
  883. rc = LDAP_OPERATIONS_ERROR;
  884. goto bail;
  885. }
  886. PR_snprintf (fName, MAXPATHLEN, "%s/%s.ldif", clDir, replica_get_name (replica));
  887. rc = cl5Close();
  888. if (rc != CL5_SUCCESS)
  889. {
  890. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  891. "failed to close changelog to import changelog data; "
  892. "changelog error - %d", rc);
  893. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  894. "replica_execute_ldif2cl_task: %s\n", returntext);
  895. rc = LDAP_OPERATIONS_ERROR;
  896. goto bail;
  897. }
  898. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  899. "Beginning changelog import of replica \"%s\"\n",
  900. replica_get_name(replica));
  901. imprc = cl5ImportLDIF (clDir, fName, rlist);
  902. slapi_ch_free_string (&clDir);
  903. if (CL5_SUCCESS == imprc)
  904. {
  905. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  906. "Finished changelog import of replica \"%s\"\n",
  907. replica_get_name(replica));
  908. }
  909. else
  910. {
  911. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  912. "Failed changelog import replica %s; "
  913. "changelog error - %d", replica_get_name(replica), rc);
  914. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  915. "replica_execute_ldif2cl_task: %s\n", returntext);
  916. imprc = LDAP_OPERATIONS_ERROR;
  917. }
  918. changelog5_read_config (&config);
  919. /* restart changelog */
  920. rc = cl5Open (config.dir, &config.dbconfig);
  921. if (CL5_SUCCESS == rc)
  922. {
  923. rc = LDAP_SUCCESS;
  924. }
  925. else
  926. {
  927. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  928. "replica_execute_ldif2cl_task: failed to start changelog at %s\n",
  929. config.dir?config.dir:"null config dir");
  930. rc = LDAP_OPERATIONS_ERROR;
  931. }
  932. bail:
  933. changelog5_config_done(&config);
  934. /* if cl5ImportLDIF returned an error, report it first. */
  935. return imprc?imprc:rc;
  936. }
  937. static multimaster_mtnode_extension *
  938. _replica_config_get_mtnode_ext (const Slapi_Entry *e)
  939. {
  940. const char *replica_root;
  941. Slapi_DN *sdn = NULL;
  942. mapping_tree_node *mtnode;
  943. multimaster_mtnode_extension *ext = NULL;
  944. char ebuf[BUFSIZ];
  945. /* retirve root of the tree for which replica is configured */
  946. replica_root = slapi_entry_attr_get_charptr (e, attr_replicaRoot);
  947. if (replica_root == NULL)
  948. {
  949. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_add: "
  950. "configuration entry %s missing %s attribute\n",
  951. escape_string(slapi_entry_get_dn((Slapi_Entry *)e), ebuf),
  952. attr_replicaRoot);
  953. return NULL;
  954. }
  955. sdn = slapi_sdn_new_dn_passin (replica_root);
  956. /* locate mapping tree node for the specified subtree */
  957. mtnode = slapi_get_mapping_tree_node_by_dn (sdn);
  958. if (mtnode == NULL)
  959. {
  960. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_add: "
  961. "failed to locate mapping tree node for dn %s\n",
  962. escape_string(slapi_sdn_get_dn(sdn), ebuf));
  963. }
  964. else
  965. {
  966. /* check if replica object already exists for the specified subtree */
  967. ext = (multimaster_mtnode_extension *)repl_con_get_ext (REPL_CON_EXT_MTNODE, mtnode);
  968. }
  969. slapi_sdn_free (&sdn);
  970. return ext;
  971. }
  972. static int
  973. replica_execute_cleanruv_task (Object *r, ReplicaId rid, char *returntext)
  974. {
  975. int rc = 0;
  976. Object *RUVObj;
  977. RUV *local_ruv = NULL;
  978. Replica *replica = (Replica*)object_get_data (r);
  979. PR_ASSERT (replica);
  980. RUVObj = replica_get_ruv(replica);
  981. PR_ASSERT(RUVObj);
  982. local_ruv = (RUV*)object_get_data (RUVObj);
  983. /* Need to check that :
  984. * - rid is not the local one
  985. * - rid is not the last one
  986. */
  987. if ((replica_get_rid(replica) == rid) ||
  988. (ruv_replica_count(local_ruv) <= 1)) {
  989. return LDAP_UNWILLING_TO_PERFORM;
  990. }
  991. rc = ruv_delete_replica(local_ruv, rid);
  992. replica_set_ruv_dirty(replica);
  993. replica_write_ruv(replica);
  994. object_release(RUVObj);
  995. /* Update Mapping Tree to reflect RUV changes */
  996. consumer5_set_mapping_tree_state_for_replica(replica, NULL);
  997. if (rc != RUV_SUCCESS){
  998. return LDAP_OPERATIONS_ERROR;
  999. }
  1000. return LDAP_SUCCESS;
  1001. }