repl5_replica_config.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664
  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 CLEANALLRUV "CLEANALLRUV"
  56. #define CLEANALLRUVLEN 11
  57. #define RELEASERUV "RELEASERUV"
  58. #define RELEASERUVLEN 10
  59. #define REPLICA_RDN "cn=replica"
  60. int slapi_log_urp = SLAPI_LOG_REPL;
  61. static ReplicaId cleaned_rid = 0;
  62. static int released_rid = 0;
  63. /* Forward Declartions */
  64. static int replica_config_add (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg);
  65. static int replica_config_modify (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg);
  66. static int replica_config_post_modify (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg);
  67. static int replica_config_delete (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg);
  68. static int replica_config_search (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg);
  69. static int replica_config_change_type_and_id (Replica *r, const char *new_type, const char *new_id, char *returntext, int apply_mods);
  70. static int replica_config_change_updatedn (Replica *r, const LDAPMod *mod, char *returntext, int apply_mods);
  71. static int replica_config_change_flags (Replica *r, const char *new_flags, char *returntext, int apply_mods);
  72. static int replica_execute_task (Object *r, const char *task_name, char *returntext, int apply_mods);
  73. static int replica_execute_cl2ldif_task (Object *r, char *returntext);
  74. static int replica_execute_ldif2cl_task (Object *r, char *returntext);
  75. static int replica_execute_cleanruv_task (Object *r, ReplicaId rid, char *returntext);
  76. static int replica_execute_cleanall_ruv_task (Object *r, ReplicaId rid, char *returntext);
  77. static int replica_execute_release_ruv_task(Object *r, ReplicaId rid);
  78. static struct berval *create_ruv_payload(char *value);
  79. static int replica_cleanup_task (Object *r, const char *task_name, char *returntext, int apply_mods);
  80. static int replica_task_done(Replica *replica);
  81. static multimaster_mtnode_extension * _replica_config_get_mtnode_ext (const Slapi_Entry *e);
  82. int g_get_shutdown();
  83. /*
  84. * Note: internal add/modify/delete operations should not be run while
  85. * s_configLock is held. E.g., slapi_modify_internal_pb via replica_task_done
  86. * in replica_config_post_modify.
  87. */
  88. static PRLock *s_configLock;
  89. static int
  90. dont_allow_that(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e, int *returncode, char *returntext, void *arg)
  91. {
  92. *returncode = LDAP_UNWILLING_TO_PERFORM;
  93. return SLAPI_DSE_CALLBACK_ERROR;
  94. }
  95. int
  96. replica_config_init()
  97. {
  98. s_configLock = PR_NewLock ();
  99. if (s_configLock == NULL)
  100. {
  101. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_init: "
  102. "failed to cretate configuration lock; NSPR error - %d\n",
  103. PR_GetError ());
  104. return -1;
  105. }
  106. /* config DSE must be initialized before we get here */
  107. slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  108. CONFIG_FILTER, replica_config_add, NULL);
  109. slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  110. CONFIG_FILTER, replica_config_modify,NULL);
  111. slapi_config_register_callback(SLAPI_OPERATION_MODRDN, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  112. CONFIG_FILTER, dont_allow_that, NULL);
  113. slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  114. CONFIG_FILTER, replica_config_delete,NULL);
  115. slapi_config_register_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  116. CONFIG_FILTER, replica_config_search,NULL);
  117. slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_POSTOP,
  118. CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  119. CONFIG_FILTER, replica_config_post_modify,
  120. NULL);
  121. return 0;
  122. }
  123. void
  124. replica_config_destroy ()
  125. {
  126. if (s_configLock)
  127. {
  128. PR_DestroyLock (s_configLock);
  129. s_configLock = NULL;
  130. }
  131. /* config DSE must be initialized before we get here */
  132. slapi_config_remove_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  133. CONFIG_FILTER, replica_config_add);
  134. slapi_config_remove_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  135. CONFIG_FILTER, replica_config_modify);
  136. slapi_config_remove_callback(SLAPI_OPERATION_MODRDN, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  137. CONFIG_FILTER, dont_allow_that);
  138. slapi_config_remove_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  139. CONFIG_FILTER, replica_config_delete);
  140. slapi_config_remove_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  141. CONFIG_FILTER, replica_config_search);
  142. slapi_config_remove_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP,
  143. CONFIG_BASE, LDAP_SCOPE_SUBTREE,
  144. CONFIG_FILTER, replica_config_post_modify);
  145. }
  146. static int
  147. replica_config_add (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter,
  148. int *returncode, char *errorbuf, void *arg)
  149. {
  150. Replica *r = NULL;
  151. multimaster_mtnode_extension *mtnode_ext;
  152. char *replica_root = (char*)slapi_entry_attr_get_charptr (e, attr_replicaRoot);
  153. char buf [SLAPI_DSE_RETURNTEXT_SIZE];
  154. char *errortext = errorbuf ? errorbuf : buf;
  155. if (errorbuf)
  156. {
  157. errorbuf[0] = '\0';
  158. }
  159. *returncode = LDAP_SUCCESS;
  160. PR_Lock (s_configLock);
  161. /* add the dn to the dn hash so we can tell this replica is being configured */
  162. replica_add_by_dn(replica_root);
  163. mtnode_ext = _replica_config_get_mtnode_ext (e);
  164. PR_ASSERT (mtnode_ext);
  165. if (mtnode_ext->replica)
  166. {
  167. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE, "replica already configured for %s", replica_root);
  168. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_add: %s\n", errortext);
  169. *returncode = LDAP_UNWILLING_TO_PERFORM;
  170. goto done;
  171. }
  172. /* create replica object */
  173. r = replica_new_from_entry (e, errortext, PR_TRUE /* is a newly added entry */);
  174. if (r == NULL)
  175. {
  176. *returncode = LDAP_OPERATIONS_ERROR;
  177. goto done;
  178. }
  179. /* Set the mapping tree node state, and the referrals from the RUV */
  180. /* if this server is a 4.0 consumer the referrals are set by legacy plugin */
  181. if (!replica_is_legacy_consumer (r))
  182. consumer5_set_mapping_tree_state_for_replica(r, NULL);
  183. /* ONREPL if replica is added as writable we need to execute protocol that
  184. introduces new writable replica to the topology */
  185. mtnode_ext->replica = object_new (r, replica_destroy); /* Refcnt is 1 */
  186. /* add replica object to the hash */
  187. *returncode = replica_add_by_name (replica_get_name (r), mtnode_ext->replica); /* Increments object refcnt */
  188. /* delete the dn from the dn hash - done with configuration */
  189. replica_delete_by_dn(replica_root);
  190. done:
  191. PR_Unlock (s_configLock);
  192. /* slapi_ch_free accepts NULL pointer */
  193. slapi_ch_free ((void**)&replica_root);
  194. if (*returncode != LDAP_SUCCESS)
  195. {
  196. if (mtnode_ext->replica)
  197. object_release (mtnode_ext->replica);
  198. return SLAPI_DSE_CALLBACK_ERROR;
  199. }
  200. else
  201. return SLAPI_DSE_CALLBACK_OK;
  202. }
  203. static int
  204. replica_config_modify (Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e,
  205. int *returncode, char *returntext, void *arg)
  206. {
  207. int rc= 0;
  208. LDAPMod **mods;
  209. int i, apply_mods;
  210. multimaster_mtnode_extension *mtnode_ext;
  211. Replica *r = NULL;
  212. char *replica_root = NULL;
  213. char buf [SLAPI_DSE_RETURNTEXT_SIZE];
  214. char *errortext = returntext ? returntext : buf;
  215. char *config_attr, *config_attr_value;
  216. Slapi_Operation *op;
  217. void *identity;
  218. if (returntext)
  219. {
  220. returntext[0] = '\0';
  221. }
  222. *returncode = LDAP_SUCCESS;
  223. /* just let internal operations originated from replication plugin to go through */
  224. slapi_pblock_get (pb, SLAPI_OPERATION, &op);
  225. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
  226. if (operation_is_flag_set(op, OP_FLAG_INTERNAL) &&
  227. (identity == repl_get_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION)))
  228. {
  229. *returncode = LDAP_SUCCESS;
  230. return SLAPI_DSE_CALLBACK_OK;
  231. }
  232. replica_root = (char*)slapi_entry_attr_get_charptr (e, attr_replicaRoot);
  233. PR_Lock (s_configLock);
  234. mtnode_ext = _replica_config_get_mtnode_ext (e);
  235. PR_ASSERT (mtnode_ext);
  236. if (mtnode_ext->replica)
  237. object_acquire (mtnode_ext->replica);
  238. if (mtnode_ext->replica == NULL)
  239. {
  240. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE, "replica does not exist for %s", replica_root);
  241. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_modify: %s\n",
  242. errortext);
  243. *returncode = LDAP_OPERATIONS_ERROR;
  244. goto done;
  245. }
  246. r = object_get_data (mtnode_ext->replica);
  247. PR_ASSERT (r);
  248. slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &mods);
  249. for (apply_mods = 0; apply_mods <= 1; apply_mods++)
  250. {
  251. /* we only allow the replica ID and type to be modified together e.g.
  252. if converting a read only replica to a master or vice versa -
  253. we will need to change both the replica ID and the type at the same
  254. time - we must disallow changing the replica ID if the type is not
  255. being changed and vice versa
  256. */
  257. char *new_repl_id = NULL;
  258. char *new_repl_type = NULL;
  259. if (*returncode != LDAP_SUCCESS)
  260. break;
  261. for (i = 0; (mods[i] && (LDAP_SUCCESS == rc)); i++)
  262. {
  263. if (*returncode != LDAP_SUCCESS)
  264. break;
  265. config_attr = (char *) mods[i]->mod_type;
  266. PR_ASSERT (config_attr);
  267. /* disallow modifications or removal of replica root,
  268. replica name and replica state attributes */
  269. if (strcasecmp (config_attr, attr_replicaRoot) == 0 ||
  270. strcasecmp (config_attr, attr_replicaName) == 0 ||
  271. strcasecmp (config_attr, attr_state) == 0)
  272. {
  273. *returncode = LDAP_UNWILLING_TO_PERFORM;
  274. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE, "modification of %s attribute is not allowed",
  275. config_attr);
  276. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_modify: %s\n",
  277. errortext);
  278. }
  279. /* this is a request to delete an attribute */
  280. else if (mods[i]->mod_op & LDAP_MOD_DELETE || mods[i]->mod_bvalues == NULL
  281. || mods[i]->mod_bvalues[0]->bv_val == NULL)
  282. {
  283. /* currently, you can only remove referral,
  284. legacy consumer or bind dn attribute */
  285. if (strcasecmp (config_attr, attr_replicaBindDn) == 0)
  286. {
  287. *returncode = replica_config_change_updatedn (r, mods[i], errortext, apply_mods);
  288. }
  289. else if (strcasecmp (config_attr, attr_replicaReferral) == 0)
  290. {
  291. if (apply_mods) {
  292. replica_set_referrals(r, NULL);
  293. if (!replica_is_legacy_consumer (r)) {
  294. consumer5_set_mapping_tree_state_for_replica(r, NULL);
  295. }
  296. }
  297. }
  298. else if (strcasecmp (config_attr, type_replicaLegacyConsumer) == 0)
  299. {
  300. if (apply_mods)
  301. replica_set_legacy_consumer (r, PR_FALSE);
  302. }
  303. else
  304. {
  305. *returncode = LDAP_UNWILLING_TO_PERFORM;
  306. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE, "deletion of %s attribute is not allowed", config_attr);
  307. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_modify: %s\n",
  308. errortext);
  309. }
  310. }
  311. else /* modify an attribute */
  312. {
  313. config_attr_value = (char *) mods[i]->mod_bvalues[0]->bv_val;
  314. if (strcasecmp (config_attr, attr_replicaBindDn) == 0)
  315. {
  316. *returncode = replica_config_change_updatedn (r, mods[i],
  317. errortext, apply_mods);
  318. }
  319. else if (strcasecmp (config_attr, attr_replicaType) == 0)
  320. {
  321. new_repl_type = slapi_ch_strdup(config_attr_value);
  322. }
  323. else if (strcasecmp (config_attr, attr_replicaId) == 0)
  324. {
  325. new_repl_id = slapi_ch_strdup(config_attr_value);
  326. }
  327. else if (strcasecmp (config_attr, attr_flags) == 0)
  328. {
  329. *returncode = replica_config_change_flags (r, config_attr_value,
  330. errortext, apply_mods);
  331. }
  332. else if (strcasecmp (config_attr, TASK_ATTR) == 0)
  333. {
  334. *returncode = replica_execute_task (mtnode_ext->replica, config_attr_value,
  335. errortext, apply_mods);
  336. }
  337. else if (strcasecmp (config_attr, attr_replicaReferral) == 0)
  338. {
  339. if (apply_mods)
  340. {
  341. Slapi_Mod smod;
  342. Slapi_ValueSet *vs= slapi_valueset_new();
  343. slapi_mod_init_byref(&smod,mods[i]);
  344. slapi_valueset_set_from_smod(vs, &smod);
  345. replica_set_referrals (r, vs);
  346. slapi_mod_done(&smod);
  347. slapi_valueset_free(vs);
  348. if (!replica_is_legacy_consumer (r)) {
  349. consumer5_set_mapping_tree_state_for_replica(r, NULL);
  350. }
  351. }
  352. }
  353. else if (strcasecmp (config_attr, type_replicaPurgeDelay) == 0)
  354. {
  355. if (apply_mods && config_attr_value && config_attr_value[0])
  356. {
  357. PRUint32 delay;
  358. if (isdigit (config_attr_value[0]))
  359. {
  360. delay = (unsigned int)atoi(config_attr_value);
  361. replica_set_purge_delay(r, delay);
  362. }
  363. else
  364. *returncode = LDAP_OPERATIONS_ERROR;
  365. }
  366. }
  367. else if (strcasecmp (config_attr, type_replicaTombstonePurgeInterval) == 0)
  368. {
  369. if (apply_mods && config_attr_value && config_attr_value[0])
  370. {
  371. long interval;
  372. interval = atol (config_attr_value);
  373. replica_set_tombstone_reap_interval (r, interval);
  374. }
  375. }
  376. else if (strcasecmp (config_attr, type_replicaLegacyConsumer) == 0)
  377. {
  378. if (apply_mods)
  379. {
  380. PRBool legacy = (strcasecmp (config_attr_value, "on") == 0) ||
  381. (strcasecmp (config_attr_value, "true") == 0) ||
  382. (strcasecmp (config_attr_value, "yes") == 0) ||
  383. (strcasecmp (config_attr_value, "1") == 0);
  384. replica_set_legacy_consumer (r, legacy);
  385. }
  386. }
  387. /* ignore modifiers attributes added by the server */
  388. else if (strcasecmp (config_attr, "modifytimestamp") == 0 ||
  389. strcasecmp (config_attr, "modifiersname") == 0)
  390. {
  391. *returncode = LDAP_SUCCESS;
  392. }
  393. else
  394. {
  395. *returncode = LDAP_UNWILLING_TO_PERFORM;
  396. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE,
  397. "modification of attribute %s is not allowed in replica entry", config_attr);
  398. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_modify: %s\n",
  399. errortext);
  400. }
  401. }
  402. }
  403. if (new_repl_id || new_repl_type)
  404. {
  405. *returncode = replica_config_change_type_and_id(r, new_repl_type,
  406. new_repl_id, errortext,
  407. apply_mods);
  408. slapi_ch_free_string(&new_repl_id);
  409. slapi_ch_free_string(&new_repl_type);
  410. }
  411. }
  412. done:
  413. if (mtnode_ext->replica)
  414. object_release (mtnode_ext->replica);
  415. /* slapi_ch_free accepts NULL pointer */
  416. slapi_ch_free ((void**)&replica_root);
  417. PR_Unlock (s_configLock);
  418. if (*returncode != LDAP_SUCCESS)
  419. {
  420. return SLAPI_DSE_CALLBACK_ERROR;
  421. }
  422. else
  423. {
  424. return SLAPI_DSE_CALLBACK_OK;
  425. }
  426. }
  427. static int
  428. replica_config_post_modify(Slapi_PBlock *pb,
  429. Slapi_Entry* entryBefore,
  430. Slapi_Entry* e,
  431. int *returncode,
  432. char *returntext,
  433. void *arg)
  434. {
  435. int rc= 0;
  436. LDAPMod **mods;
  437. int i, apply_mods;
  438. multimaster_mtnode_extension *mtnode_ext;
  439. Replica *r = NULL;
  440. char *replica_root = NULL;
  441. char buf [SLAPI_DSE_RETURNTEXT_SIZE];
  442. char *errortext = returntext ? returntext : buf;
  443. char *config_attr, *config_attr_value;
  444. Slapi_Operation *op;
  445. void *identity;
  446. int flag_need_cleanup = 0;
  447. if (returntext)
  448. {
  449. returntext[0] = '\0';
  450. }
  451. *returncode = LDAP_SUCCESS;
  452. /* just let internal operations originated from replication plugin to go through */
  453. slapi_pblock_get (pb, SLAPI_OPERATION, &op);
  454. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
  455. if (operation_is_flag_set(op, OP_FLAG_INTERNAL) &&
  456. (identity == repl_get_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION)))
  457. {
  458. *returncode = LDAP_SUCCESS;
  459. return SLAPI_DSE_CALLBACK_OK;
  460. }
  461. replica_root = (char*)slapi_entry_attr_get_charptr (e, attr_replicaRoot);
  462. PR_Lock (s_configLock);
  463. mtnode_ext = _replica_config_get_mtnode_ext (e);
  464. PR_ASSERT (mtnode_ext);
  465. if (mtnode_ext->replica)
  466. object_acquire (mtnode_ext->replica);
  467. if (mtnode_ext->replica == NULL)
  468. {
  469. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE,
  470. "replica does not exist for %s", replica_root);
  471. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  472. "replica_config_post_modify: %s\n",
  473. errortext);
  474. *returncode = LDAP_OPERATIONS_ERROR;
  475. goto done;
  476. }
  477. r = object_get_data (mtnode_ext->replica);
  478. PR_ASSERT (r);
  479. slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &mods);
  480. for (apply_mods = 0; apply_mods <= 1; apply_mods++)
  481. {
  482. /* we only allow the replica ID and type to be modified together e.g.
  483. if converting a read only replica to a master or vice versa -
  484. we will need to change both the replica ID and the type at the same
  485. time - we must disallow changing the replica ID if the type is not
  486. being changed and vice versa
  487. */
  488. if (*returncode != LDAP_SUCCESS)
  489. break;
  490. for (i = 0; (mods[i] && (LDAP_SUCCESS == rc)); i++)
  491. {
  492. if (*returncode != LDAP_SUCCESS)
  493. break;
  494. config_attr = (char *) mods[i]->mod_type;
  495. PR_ASSERT (config_attr);
  496. /* disallow modifications or removal of replica root,
  497. replica name and replica state attributes */
  498. if (strcasecmp (config_attr, attr_replicaRoot) == 0 ||
  499. strcasecmp (config_attr, attr_replicaName) == 0 ||
  500. strcasecmp (config_attr, attr_state) == 0)
  501. {
  502. *returncode = LDAP_UNWILLING_TO_PERFORM;
  503. PR_snprintf (errortext, SLAPI_DSE_RETURNTEXT_SIZE,
  504. "modification of %s attribute is not allowed",
  505. config_attr);
  506. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  507. "replica_config_post_modify: %s\n",
  508. errortext);
  509. }
  510. /* this is a request to delete an attribute */
  511. else if (mods[i]->mod_op & LDAP_MOD_DELETE ||
  512. mods[i]->mod_bvalues == NULL ||
  513. mods[i]->mod_bvalues[0]->bv_val == NULL)
  514. {
  515. ;
  516. }
  517. else /* modify an attribute */
  518. {
  519. config_attr_value = (char *) mods[i]->mod_bvalues[0]->bv_val;
  520. if (strcasecmp (config_attr, TASK_ATTR) == 0)
  521. {
  522. flag_need_cleanup = 1;
  523. }
  524. }
  525. }
  526. }
  527. done:
  528. PR_Unlock (s_configLock);
  529. /* slapi_ch_free accepts NULL pointer */
  530. slapi_ch_free_string (&replica_root);
  531. /* Call replica_cleanup_task after s_configLock is reliesed */
  532. if (flag_need_cleanup)
  533. {
  534. *returncode = replica_cleanup_task(mtnode_ext->replica,
  535. config_attr_value,
  536. errortext, apply_mods);
  537. }
  538. if (mtnode_ext->replica)
  539. object_release (mtnode_ext->replica);
  540. if (*returncode != LDAP_SUCCESS)
  541. {
  542. return SLAPI_DSE_CALLBACK_ERROR;
  543. }
  544. else
  545. {
  546. return SLAPI_DSE_CALLBACK_OK;
  547. }
  548. }
  549. static int
  550. replica_config_delete (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter,
  551. int *returncode, char *returntext, void *arg)
  552. {
  553. multimaster_mtnode_extension *mtnode_ext;
  554. Replica *r;
  555. PR_Lock (s_configLock);
  556. mtnode_ext = _replica_config_get_mtnode_ext (e);
  557. PR_ASSERT (mtnode_ext);
  558. if (mtnode_ext->replica)
  559. {
  560. /* remove object from the hash */
  561. r = (Replica*)object_get_data (mtnode_ext->replica);
  562. PR_ASSERT (r);
  563. /* The changelog for this replica is no longer valid, so we should remove it. */
  564. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_delete: "
  565. "Warning: The changelog for replica %s is no longer valid since "
  566. "the replica config is being deleted. Removing the changelog.\n",
  567. slapi_sdn_get_dn(replica_get_root(r)));
  568. cl5DeleteDBSync(mtnode_ext->replica);
  569. replica_delete_by_name (replica_get_name (r));
  570. object_release (mtnode_ext->replica);
  571. mtnode_ext->replica = NULL;
  572. }
  573. PR_Unlock (s_configLock);
  574. *returncode = LDAP_SUCCESS;
  575. return SLAPI_DSE_CALLBACK_OK;
  576. }
  577. static int
  578. replica_config_search (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode,
  579. char *returntext, void *arg)
  580. {
  581. multimaster_mtnode_extension *mtnode_ext;
  582. int changeCount = 0;
  583. PRBool reapActive = PR_FALSE;
  584. char val [64];
  585. /* add attribute that contains number of entries in the changelog for this replica */
  586. PR_Lock (s_configLock);
  587. mtnode_ext = _replica_config_get_mtnode_ext (e);
  588. PR_ASSERT (mtnode_ext);
  589. if (mtnode_ext->replica) {
  590. Replica *replica;
  591. object_acquire (mtnode_ext->replica);
  592. if (cl5GetState () == CL5_STATE_OPEN) {
  593. changeCount = cl5GetOperationCount (mtnode_ext->replica);
  594. }
  595. replica = (Replica*)object_get_data (mtnode_ext->replica);
  596. if (replica) {
  597. reapActive = replica_get_tombstone_reap_active(replica);
  598. }
  599. object_release (mtnode_ext->replica);
  600. }
  601. sprintf (val, "%d", changeCount);
  602. slapi_entry_add_string (e, type_replicaChangeCount, val);
  603. slapi_entry_attr_set_int(e, "nsds5replicaReapActive", (int)reapActive);
  604. PR_Unlock (s_configLock);
  605. return SLAPI_DSE_CALLBACK_OK;
  606. }
  607. static int
  608. replica_config_change_type_and_id (Replica *r, const char *new_type,
  609. const char *new_id, char *returntext,
  610. int apply_mods)
  611. {
  612. int type;
  613. ReplicaType oldtype;
  614. ReplicaId rid;
  615. ReplicaId oldrid;
  616. PR_ASSERT (r);
  617. oldtype = replica_get_type(r);
  618. oldrid = replica_get_rid(r);
  619. if (new_type == NULL) /* by default - replica is read-only */
  620. {
  621. type = REPLICA_TYPE_READONLY;
  622. }
  623. else
  624. {
  625. type = atoi (new_type);
  626. if (type <= REPLICA_TYPE_UNKNOWN || type >= REPLICA_TYPE_END)
  627. {
  628. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "invalid replica type %d", type);
  629. return LDAP_OPERATIONS_ERROR;
  630. }
  631. }
  632. /* disallow changing type to itself just to permit a replica ID change */
  633. if (oldtype == type)
  634. {
  635. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "replica type is already %d - not changing", type);
  636. return LDAP_OPERATIONS_ERROR;
  637. }
  638. if (type == REPLICA_TYPE_READONLY)
  639. {
  640. rid = READ_ONLY_REPLICA_ID; /* default rid for read only */
  641. }
  642. else if (!new_id)
  643. {
  644. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "a replica ID is required when changing replica type to read-write");
  645. return LDAP_UNWILLING_TO_PERFORM;
  646. }
  647. else
  648. {
  649. int temprid = atoi (new_id);
  650. if (temprid <= 0 || temprid >= READ_ONLY_REPLICA_ID)
  651. {
  652. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  653. "attribute %s must have a value greater than 0 "
  654. "and less than %d",
  655. attr_replicaId, READ_ONLY_REPLICA_ID);
  656. return LDAP_UNWILLING_TO_PERFORM;
  657. }
  658. else
  659. {
  660. rid = (ReplicaId)temprid;
  661. }
  662. }
  663. /* error if old rid == new rid */
  664. if (oldrid == rid)
  665. {
  666. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "replica ID is already %d - not changing", rid);
  667. return LDAP_OPERATIONS_ERROR;
  668. }
  669. if (apply_mods)
  670. {
  671. replica_set_type (r, type);
  672. replica_set_rid(r, rid);
  673. /* Set the mapping tree node, and the list of referrals */
  674. /* if this server is a 4.0 consumer the referrals are set by legacy plugin */
  675. if (!replica_is_legacy_consumer(r))
  676. consumer5_set_mapping_tree_state_for_replica(r, NULL);
  677. }
  678. return LDAP_SUCCESS;
  679. }
  680. static int
  681. replica_config_change_updatedn (Replica *r, const LDAPMod *mod, char *returntext,
  682. int apply_mods)
  683. {
  684. PR_ASSERT (r);
  685. if (apply_mods)
  686. {
  687. Slapi_Mod smod;
  688. Slapi_ValueSet *vs= slapi_valueset_new();
  689. slapi_mod_init_byref(&smod, (LDAPMod *)mod); /* cast away const */
  690. slapi_valueset_set_from_smod(vs, &smod);
  691. replica_set_updatedn(r, vs, mod->mod_op);
  692. slapi_mod_done(&smod);
  693. slapi_valueset_free(vs);
  694. }
  695. return LDAP_SUCCESS;
  696. }
  697. static int replica_config_change_flags (Replica *r, const char *new_flags,
  698. char *returntext, int apply_mods)
  699. {
  700. PR_ASSERT (r);
  701. if (apply_mods)
  702. {
  703. PRUint32 flags;
  704. flags = atol (new_flags);
  705. replica_replace_flags (r, flags);
  706. }
  707. return LDAP_SUCCESS;
  708. }
  709. static int replica_execute_task (Object *r, const char *task_name, char *returntext,
  710. int apply_mods)
  711. {
  712. if (strcasecmp (task_name, CL2LDIF_TASK) == 0)
  713. {
  714. if (apply_mods)
  715. {
  716. return replica_execute_cl2ldif_task (r, returntext);
  717. }
  718. else
  719. return LDAP_SUCCESS;
  720. }
  721. else if (strcasecmp (task_name, LDIF2CL_TASK) == 0)
  722. {
  723. if (apply_mods)
  724. {
  725. return replica_execute_ldif2cl_task (r, returntext);
  726. }
  727. else
  728. return LDAP_SUCCESS;
  729. }
  730. else if (strncasecmp (task_name, CLEANRUV, CLEANRUVLEN) == 0)
  731. {
  732. int temprid = atoi(&(task_name[CLEANRUVLEN]));
  733. if (temprid <= 0 || temprid >= READ_ONLY_REPLICA_ID){
  734. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Invalid replica id (%d) for task - %s", temprid, task_name);
  735. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_execute_task: %s\n", returntext);
  736. return LDAP_OPERATIONS_ERROR;
  737. }
  738. if (apply_mods)
  739. {
  740. return replica_execute_cleanruv_task (r, (ReplicaId)temprid, returntext);
  741. }
  742. else
  743. return LDAP_SUCCESS;
  744. }
  745. else if (strncasecmp (task_name, CLEANALLRUV, CLEANALLRUVLEN) == 0)
  746. {
  747. int temprid = atoi(&(task_name[CLEANALLRUVLEN]));
  748. if (temprid <= 0 || temprid >= READ_ONLY_REPLICA_ID){
  749. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Invalid replica id (%d) for task - (%s)", temprid, task_name);
  750. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_execute_task: %s\n", returntext);
  751. return LDAP_OPERATIONS_ERROR;
  752. }
  753. if (apply_mods)
  754. {
  755. return replica_execute_cleanall_ruv_task(r, (ReplicaId)temprid, returntext);
  756. }
  757. else
  758. return LDAP_SUCCESS;
  759. }
  760. else
  761. {
  762. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "unsupported replica task - %s", task_name);
  763. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  764. "replica_execute_task: %s\n", returntext);
  765. return LDAP_OPERATIONS_ERROR;
  766. }
  767. }
  768. static int
  769. replica_cleanup_task (Object *r, const char *task_name, char *returntext,
  770. int apply_mods)
  771. {
  772. int rc = LDAP_SUCCESS;
  773. if (apply_mods) {
  774. Replica *replica = (Replica*)object_get_data (r);
  775. if (NULL == replica) {
  776. rc = LDAP_OPERATIONS_ERROR;
  777. } else {
  778. rc = replica_task_done(replica);
  779. }
  780. }
  781. return rc;
  782. }
  783. static int
  784. replica_task_done(Replica *replica)
  785. {
  786. int rc = LDAP_OPERATIONS_ERROR;
  787. char *replica_dn = NULL;
  788. Slapi_DN *replica_sdn = NULL;
  789. Slapi_PBlock *pb = NULL;
  790. LDAPMod *mods [2];
  791. LDAPMod mod;
  792. if (NULL == replica) {
  793. return rc;
  794. }
  795. /* dn: cn=replica,cn=dc\3Dexample\2Cdc\3Dcom,cn=mapping tree,cn=config */
  796. replica_dn = slapi_ch_smprintf("%s,cn=\"%s\",%s",
  797. REPLICA_RDN,
  798. slapi_sdn_get_dn(replica_get_root(replica)),
  799. CONFIG_BASE);
  800. if (NULL == replica_dn) {
  801. return rc;
  802. }
  803. replica_sdn = slapi_sdn_new_dn_passin(replica_dn);
  804. pb = slapi_pblock_new();
  805. mods[0] = &mod;
  806. mods[1] = NULL;
  807. mod.mod_op = LDAP_MOD_DELETE | LDAP_MOD_BVALUES;
  808. mod.mod_type = (char *)TASK_ATTR;
  809. mod.mod_bvalues = NULL;
  810. slapi_modify_internal_set_pb_ext(pb, replica_sdn, mods, NULL/* controls */,
  811. NULL/* uniqueid */,
  812. repl_get_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION),
  813. 0/* flags */);
  814. slapi_modify_internal_pb (pb);
  815. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  816. if ((rc != LDAP_SUCCESS) && (rc != LDAP_NO_SUCH_ATTRIBUTE)) {
  817. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  818. "replica_task_done: "
  819. "failed to remove (%s) attribute from (%s) entry; "
  820. "LDAP error - %d\n",
  821. TASK_ATTR, replica_dn, rc);
  822. }
  823. slapi_pblock_destroy (pb);
  824. slapi_sdn_free(&replica_sdn);
  825. return rc;
  826. }
  827. static int replica_execute_cl2ldif_task (Object *r, char *returntext)
  828. {
  829. int rc;
  830. Object *rlist [2];
  831. Replica *replica;
  832. char fName [MAXPATHLEN];
  833. char *clDir = NULL;
  834. if (cl5GetState () != CL5_STATE_OPEN)
  835. {
  836. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "changelog is not open");
  837. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  838. "replica_execute_cl2ldif_task: %s\n", returntext);
  839. rc = LDAP_OPERATIONS_ERROR;
  840. goto bail;
  841. }
  842. rlist[0] = r;
  843. rlist[1] = NULL;
  844. /* file is stored in the changelog directory and is named
  845. <replica name>.ldif */
  846. clDir = cl5GetDir ();
  847. if (NULL == clDir) {
  848. rc = LDAP_OPERATIONS_ERROR;
  849. goto bail;
  850. }
  851. replica = (Replica*)object_get_data (r);
  852. if (NULL == replica) {
  853. rc = LDAP_OPERATIONS_ERROR;
  854. goto bail;
  855. }
  856. PR_snprintf (fName, MAXPATHLEN, "%s/%s.ldif", clDir, replica_get_name (replica));
  857. slapi_ch_free_string (&clDir);
  858. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  859. "Beginning changelog export of replica \"%s\"\n",
  860. replica_get_name(replica));
  861. rc = cl5ExportLDIF (fName, rlist);
  862. if (rc == CL5_SUCCESS) {
  863. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  864. "Finished changelog export of replica \"%s\"\n",
  865. replica_get_name(replica));
  866. rc = LDAP_SUCCESS;
  867. } else {
  868. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  869. "Failed changelog export replica %s; "
  870. "changelog error - %d", replica_get_name(replica), rc);
  871. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  872. "replica_execute_cl2ldif_task: %s\n", returntext);
  873. rc = LDAP_OPERATIONS_ERROR;
  874. }
  875. bail:
  876. return rc;
  877. }
  878. static int replica_execute_ldif2cl_task (Object *r, char *returntext)
  879. {
  880. int rc, imprc = 0;
  881. Object *rlist [2];
  882. Replica *replica;
  883. char fName [MAXPATHLEN];
  884. char *clDir = NULL;
  885. changelog5Config config;
  886. if (cl5GetState () != CL5_STATE_OPEN)
  887. {
  888. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "changelog is not open");
  889. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  890. "replica_execute_ldif2cl_task: %s\n", returntext);
  891. rc = LDAP_OPERATIONS_ERROR;
  892. goto bail;
  893. }
  894. rlist[0] = r;
  895. rlist[1] = NULL;
  896. /* file is stored in the changelog directory and is named
  897. <replica name>.ldif */
  898. clDir = cl5GetDir ();
  899. if (NULL == clDir) {
  900. rc = LDAP_OPERATIONS_ERROR;
  901. goto bail;
  902. }
  903. replica = (Replica*)object_get_data (r);
  904. if (NULL == replica) {
  905. rc = LDAP_OPERATIONS_ERROR;
  906. goto bail;
  907. }
  908. PR_snprintf (fName, MAXPATHLEN, "%s/%s.ldif", clDir, replica_get_name (replica));
  909. rc = cl5Close();
  910. if (rc != CL5_SUCCESS)
  911. {
  912. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  913. "failed to close changelog to import changelog data; "
  914. "changelog error - %d", rc);
  915. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  916. "replica_execute_ldif2cl_task: %s\n", returntext);
  917. rc = LDAP_OPERATIONS_ERROR;
  918. goto bail;
  919. }
  920. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  921. "Beginning changelog import of replica \"%s\"\n",
  922. replica_get_name(replica));
  923. imprc = cl5ImportLDIF (clDir, fName, rlist);
  924. slapi_ch_free_string (&clDir);
  925. if (CL5_SUCCESS == imprc)
  926. {
  927. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  928. "Finished changelog import of replica \"%s\"\n",
  929. replica_get_name(replica));
  930. }
  931. else
  932. {
  933. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  934. "Failed changelog import replica %s; "
  935. "changelog error - %d", replica_get_name(replica), rc);
  936. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  937. "replica_execute_ldif2cl_task: %s\n", returntext);
  938. imprc = LDAP_OPERATIONS_ERROR;
  939. }
  940. changelog5_read_config (&config);
  941. /* restart changelog */
  942. rc = cl5Open (config.dir, &config.dbconfig);
  943. if (CL5_SUCCESS == rc)
  944. {
  945. rc = LDAP_SUCCESS;
  946. }
  947. else
  948. {
  949. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  950. "replica_execute_ldif2cl_task: failed to start changelog at %s\n",
  951. config.dir?config.dir:"null config dir");
  952. rc = LDAP_OPERATIONS_ERROR;
  953. }
  954. bail:
  955. changelog5_config_done(&config);
  956. /* if cl5ImportLDIF returned an error, report it first. */
  957. return imprc?imprc:rc;
  958. }
  959. static multimaster_mtnode_extension *
  960. _replica_config_get_mtnode_ext (const Slapi_Entry *e)
  961. {
  962. const char *replica_root;
  963. Slapi_DN *sdn = NULL;
  964. mapping_tree_node *mtnode;
  965. multimaster_mtnode_extension *ext = NULL;
  966. /* retirve root of the tree for which replica is configured */
  967. replica_root = slapi_entry_attr_get_charptr (e, attr_replicaRoot);
  968. if (replica_root == NULL)
  969. {
  970. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_add: "
  971. "configuration entry %s missing %s attribute\n",
  972. slapi_entry_get_dn((Slapi_Entry *)e),
  973. attr_replicaRoot);
  974. return NULL;
  975. }
  976. sdn = slapi_sdn_new_dn_passin (replica_root);
  977. /* locate mapping tree node for the specified subtree */
  978. mtnode = slapi_get_mapping_tree_node_by_dn (sdn);
  979. if (mtnode == NULL)
  980. {
  981. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "replica_config_add: "
  982. "failed to locate mapping tree node for dn %s\n",
  983. slapi_sdn_get_dn(sdn));
  984. }
  985. else
  986. {
  987. /* check if replica object already exists for the specified subtree */
  988. ext = (multimaster_mtnode_extension *)repl_con_get_ext (REPL_CON_EXT_MTNODE, mtnode);
  989. }
  990. slapi_sdn_free (&sdn);
  991. return ext;
  992. }
  993. int
  994. replica_execute_cleanruv_task_ext(Object *r, ReplicaId rid)
  995. {
  996. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "cleanruv_extop: calling clean_ruv_ext\n");
  997. return replica_execute_cleanruv_task(r, rid, NULL);
  998. }
  999. static int
  1000. replica_execute_cleanruv_task (Object *r, ReplicaId rid, char *returntext /* not used */)
  1001. {
  1002. int rc = 0;
  1003. Object *RUVObj;
  1004. RUV *local_ruv = NULL;
  1005. Replica *replica = (Replica*)object_get_data (r);
  1006. PR_ASSERT (replica);
  1007. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "cleanruv_task: cleaning rid (%d)...\n",(int)rid);
  1008. RUVObj = replica_get_ruv(replica);
  1009. PR_ASSERT(RUVObj);
  1010. local_ruv = (RUV*)object_get_data (RUVObj);
  1011. /* Need to check that :
  1012. * - rid is not the local one
  1013. * - rid is not the last one
  1014. */
  1015. if ((replica_get_rid(replica) == rid) ||
  1016. (ruv_replica_count(local_ruv) <= 1)) {
  1017. return LDAP_UNWILLING_TO_PERFORM;
  1018. }
  1019. rc = ruv_delete_replica(local_ruv, rid);
  1020. replica_set_ruv_dirty(replica);
  1021. replica_write_ruv(replica);
  1022. object_release(RUVObj);
  1023. /* Update Mapping Tree to reflect RUV changes */
  1024. consumer5_set_mapping_tree_state_for_replica(replica, NULL);
  1025. /*
  1026. * Clean the changelog RUV's, and set the rids
  1027. */
  1028. cl5CleanRUV(rid);
  1029. delete_released_rid();
  1030. if (rc != RUV_SUCCESS){
  1031. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanruv_task: task failed(%d)\n",rc);
  1032. return LDAP_OPERATIONS_ERROR;
  1033. }
  1034. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "cleanruv_task: finished successfully\n");
  1035. return LDAP_SUCCESS;
  1036. }
  1037. static int
  1038. replica_execute_cleanall_ruv_task (Object *r, ReplicaId rid, char *returntext)
  1039. {
  1040. PRThread *thread = NULL;
  1041. Repl_Connection *conn;
  1042. Replica *replica = (Replica*)object_get_data (r);
  1043. Object *agmt_obj;
  1044. Repl_Agmt *agmt;
  1045. ConnResult crc;
  1046. cleanruv_data *data = NULL;
  1047. const Slapi_DN *dn = NULL;
  1048. struct berval *payload = NULL;
  1049. char *ridstr = NULL;
  1050. int send_msgid = 0;
  1051. int agmt_count = 0;
  1052. int rc = 0;
  1053. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: cleaning rid (%d)...\n",(int)rid);
  1054. set_cleaned_rid(rid);
  1055. /*
  1056. * Create payload
  1057. */
  1058. ridstr = slapi_ch_smprintf("%d:%s", rid, slapi_sdn_get_dn(replica_get_root(replica)));
  1059. payload = create_ruv_payload(ridstr);
  1060. if(payload == NULL){
  1061. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: failed to create ext op payload, aborting task\n");
  1062. goto done;
  1063. }
  1064. agmt_obj = agmtlist_get_first_agreement_for_replica (replica);
  1065. while (agmt_obj)
  1066. {
  1067. agmt = (Repl_Agmt*)object_get_data (agmt_obj);
  1068. if(!agmt_is_enabled(agmt)){
  1069. agmt_obj = agmtlist_get_next_agreement_for_replica (replica, agmt_obj);
  1070. continue;
  1071. }
  1072. dn = agmt_get_dn_byref(agmt);
  1073. conn = (Repl_Connection *)agmt_get_connection(agmt);
  1074. if(conn == NULL){
  1075. /* no connection for this agreement, and move on */
  1076. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: the replica (%s), is "
  1077. "missing the connection. This replica will not be cleaned.\n", slapi_sdn_get_dn(dn));
  1078. agmt_obj = agmtlist_get_next_agreement_for_replica (replica, agmt_obj);
  1079. continue;
  1080. }
  1081. crc = conn_connect(conn);
  1082. if (CONN_OPERATION_FAILED == crc ){
  1083. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: failed to connect "
  1084. "to repl agreement connection (%s), error %d\n",slapi_sdn_get_dn(dn), ACQUIRE_TRANSIENT_ERROR);
  1085. } else if (CONN_SSL_NOT_ENABLED == crc){
  1086. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: failed to acquire "
  1087. "repl agmt connection (%s), errror %d\n",slapi_sdn_get_dn(dn), ACQUIRE_FATAL_ERROR);
  1088. } else {
  1089. conn_cancel_linger(conn);
  1090. crc = conn_send_extended_operation(conn, REPL_CLEANRUV_OID, payload, NULL, &send_msgid);
  1091. if (CONN_OPERATION_SUCCESS != crc){
  1092. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: failed to send "
  1093. "cleanruv extended op to repl agmt (%s), error %d\n", slapi_sdn_get_dn(dn), crc);
  1094. } else {
  1095. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: successfully sent "
  1096. "cleanruv extended op to (%s)\n",slapi_sdn_get_dn(dn));
  1097. agmt_count++;
  1098. }
  1099. conn_start_linger(conn);
  1100. }
  1101. if(crc){
  1102. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: replica (%s) has not "
  1103. "been cleaned. You will need to rerun the CLEANALLRUV task on this replica.\n", slapi_sdn_get_dn(dn));
  1104. rc = crc;
  1105. }
  1106. agmt_obj = agmtlist_get_next_agreement_for_replica (replica, agmt_obj);
  1107. }
  1108. done:
  1109. if(payload)
  1110. ber_bvfree(payload);
  1111. slapi_ch_free_string(&ridstr);
  1112. /*
  1113. * Now run the cleanruv task
  1114. */
  1115. replica_execute_cleanruv_task (r, rid, returntext);
  1116. if(rc == 0 && agmt_count > 0){ /* success, but we need to check our replicas */
  1117. /*
  1118. * Launch the cleanruv monitoring thread. Once all the replicas are cleaned it will release the rid
  1119. */
  1120. data = (cleanruv_data*)slapi_ch_calloc(1, sizeof(cleanruv_data));
  1121. if (data == NULL) {
  1122. slapi_log_error( SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: failed to allocate "
  1123. "cleanruv_data. Aborting task.\n");
  1124. return -1;
  1125. }
  1126. data->repl_obj = r;
  1127. data->rid = rid;
  1128. thread = PR_CreateThread(PR_USER_THREAD, replica_cleanallruv_monitor_thread,
  1129. (void *)data, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
  1130. PR_UNJOINABLE_THREAD, SLAPD_DEFAULT_THREAD_STACKSIZE);
  1131. if (thread == NULL) {
  1132. slapi_log_error( SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: unable to create cleanAllRUV "
  1133. "monitoring thread. Aborting task.\n");
  1134. }
  1135. } else if(r == 0){ /* success */
  1136. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: Successfully Finished.\n");
  1137. } else {
  1138. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: Task failed (%d)\n",rc);
  1139. }
  1140. return rc;
  1141. }
  1142. /*
  1143. * After all the cleanAllRUV extended ops have been sent, we need to monitoring those replicas'
  1144. * RUVs. Once the rid is cleaned, then we need to release it, and push this "release"
  1145. * to the other replicas
  1146. */
  1147. void
  1148. replica_cleanallruv_monitor_thread(void *arg)
  1149. {
  1150. Object *agmt_obj;
  1151. LDAP *ld;
  1152. Repl_Connection *conn;
  1153. Repl_Agmt *agmt;
  1154. Replica *replica;;
  1155. cleanruv_data *data = arg;
  1156. LDAPMessage *result, *entry;
  1157. BerElement *ber;
  1158. time_t start_time;
  1159. struct berval **vals;
  1160. char *rid_text;
  1161. char *attrs[2];
  1162. char *attr;
  1163. int replicas_cleaned = 0;
  1164. int found = 0;
  1165. int crc;
  1166. int rc = 0;
  1167. int i;
  1168. /*
  1169. * Initialize our settings
  1170. */
  1171. attrs[0] = "nsds50ruv";
  1172. attrs[1] = NULL;
  1173. rid_text = slapi_ch_smprintf("{replica %d ldap", data->rid);
  1174. replica = (Replica*)object_get_data (data->repl_obj);
  1175. start_time = current_time();
  1176. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: Waiting for all the replicas to get cleaned...\n");
  1177. while(!g_get_shutdown())
  1178. {
  1179. DS_Sleep(PR_SecondsToInterval(10));
  1180. found = 0;
  1181. agmt_obj = agmtlist_get_first_agreement_for_replica (replica);
  1182. while (agmt_obj){
  1183. agmt = (Repl_Agmt*)object_get_data (agmt_obj);
  1184. if(!agmt_is_enabled(agmt)){
  1185. agmt_obj = agmtlist_get_next_agreement_for_replica (replica, agmt_obj);
  1186. continue;
  1187. }
  1188. /*
  1189. * Get the replication connection
  1190. */
  1191. conn = (Repl_Connection *)agmt_get_connection(agmt);
  1192. crc = conn_connect(conn);
  1193. if (CONN_OPERATION_FAILED == crc ){
  1194. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: monitor thread failed to connect "
  1195. "to repl agreement connection (%s), error %d\n","", ACQUIRE_TRANSIENT_ERROR);
  1196. continue;
  1197. } else if (CONN_SSL_NOT_ENABLED == crc){
  1198. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: monitor thread failed to acquire "
  1199. "repl agmt connection (%s), error %d\n","", ACQUIRE_FATAL_ERROR);
  1200. continue;
  1201. }
  1202. /*
  1203. * Get the LDAP connection handle from the conn
  1204. */
  1205. ld = conn_get_ldap(conn);
  1206. if(ld == NULL){
  1207. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: monitor thread failed to get LDAP "
  1208. "handle from the replication agmt (%s). Moving on to the next agmt.\n",agmt_get_long_name(agmt));
  1209. continue;
  1210. }
  1211. /*
  1212. * Search this replica for its tombstone/ruv entry
  1213. */
  1214. conn_cancel_linger(conn);
  1215. conn_lock(conn);
  1216. rc = ldap_search_ext_s(ld, slapi_sdn_get_dn(agmt_get_replarea(agmt)), LDAP_SCOPE_SUBTREE,
  1217. "(&(nsuniqueid=ffffffff-ffffffff-ffffffff-ffffffff)(objectclass=nstombstone))",
  1218. attrs, 0, NULL, NULL, NULL, 0, &result);
  1219. if(rc != LDAP_SUCCESS){
  1220. /*
  1221. * Couldn't contact ldap server, what should we do?
  1222. *
  1223. * Skip it and move on! It's the admin's job to make sure all the replicas are up and running
  1224. */
  1225. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: monitor thread failed to contact "
  1226. "agmt (%s), moving on to the next agmt.\n", agmt_get_long_name(agmt));
  1227. conn_unlock(conn);
  1228. conn_start_linger(conn);
  1229. continue;
  1230. }
  1231. /*
  1232. * There is only one entry. Check its "nsds50ruv" for our cleaned rid
  1233. */
  1234. entry = ldap_first_entry( ld, result );
  1235. if ( entry != NULL ) {
  1236. for ( attr = ldap_first_attribute( ld, entry, &ber ); attr != NULL; attr = ldap_next_attribute( ld, entry, ber ) ){
  1237. /* make sure the attribute is nsds50ruv */
  1238. if(strcasecmp(attr,"nsds50ruv") != 0){
  1239. continue;
  1240. }
  1241. if ((vals = ldap_get_values_len( ld, entry, attr)) != NULL ) {
  1242. for ( i = 0; vals[i] && vals[i]->bv_val; i++ ) {
  1243. /* look for this replica */
  1244. if(strstr(rid_text, vals[i]->bv_val)){
  1245. /* rid has not been cleaned yet, start over */
  1246. found = 1;
  1247. break;
  1248. }
  1249. }
  1250. ldap_value_free_len(vals);
  1251. }
  1252. ldap_memfree( attr );
  1253. }
  1254. if ( ber != NULL ) {
  1255. ber_free( ber, 0 );
  1256. }
  1257. }
  1258. ldap_msgfree( result );
  1259. /*
  1260. * Unlock the connection, and start the linger timer
  1261. */
  1262. conn_unlock(conn);
  1263. conn_start_linger(conn);
  1264. if(found){
  1265. /*
  1266. * If we've been trying to clean these replicas for over an hour, just quit
  1267. */
  1268. if( (current_time() - start_time) > 3600){
  1269. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: timed out checking if replicas have "
  1270. "been cleaned. The rid has not been released, you need to rerun the task.\n");
  1271. goto done;
  1272. }
  1273. /*
  1274. * a rid has not been cleaned yet, go back to sleep and check them again
  1275. */
  1276. break;
  1277. }
  1278. agmt_obj = agmtlist_get_next_agreement_for_replica (replica, agmt_obj);
  1279. }
  1280. if(!found){
  1281. /*
  1282. * The replicas have been cleaned! Next, release the rid
  1283. */
  1284. replicas_cleaned = 1;
  1285. break;
  1286. }
  1287. } /* while */
  1288. /*
  1289. * If the replicas are cleaned, release the rid
  1290. */
  1291. if(replicas_cleaned){
  1292. rc = replica_execute_release_ruv_task(data->repl_obj, data->rid);
  1293. if(rc == 0){
  1294. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: Successfully Finished. All active "
  1295. "replicas have been cleaned.\n");
  1296. } else {
  1297. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: Failed: Replica ID was not released (%d) "
  1298. "You will need to rerun the task.\n", rc);
  1299. }
  1300. } else {
  1301. /*
  1302. * Shutdown
  1303. */
  1304. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: slapd shutting down, you will need to rerun the task.\n");
  1305. }
  1306. done:
  1307. slapi_ch_free((void **)&rid_text);
  1308. slapi_ch_free((void **)&data);
  1309. }
  1310. /*
  1311. * This function releases the cleaned rid so that it can be reused.
  1312. * We send this operation to all the known active replicas.
  1313. */
  1314. static int
  1315. replica_execute_release_ruv_task(Object *r, ReplicaId rid)
  1316. {
  1317. Repl_Connection *conn;
  1318. Replica *replica = (Replica*)object_get_data (r);
  1319. Object *agmt_obj;
  1320. Repl_Agmt *agmt;
  1321. ConnResult crc;
  1322. const Slapi_DN *dn = NULL;
  1323. struct berval *payload = NULL;
  1324. char *ridstr = NULL;
  1325. int send_msgid = 0;
  1326. int rc = 0;
  1327. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: releasing rid (%d)...\n", rid);
  1328. /*
  1329. * Set the released rid, and trigger cl trimmming
  1330. */
  1331. set_released_rid((int)rid);
  1332. trigger_cl_trimming();
  1333. /*
  1334. * Create payload
  1335. */
  1336. ridstr = slapi_ch_smprintf("%d:%s", rid, slapi_sdn_get_dn(replica_get_root(replica)));
  1337. payload = create_ruv_payload(ridstr);
  1338. if(payload == NULL){
  1339. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "releaseRUV_task: failed to create ext op payload, aborting op\n");
  1340. rc = -1;
  1341. goto done;
  1342. }
  1343. agmt_obj = agmtlist_get_first_agreement_for_replica (replica);
  1344. while (agmt_obj)
  1345. {
  1346. agmt = (Repl_Agmt*)object_get_data (agmt_obj);
  1347. if(!agmt_is_enabled(agmt)){
  1348. agmt_obj = agmtlist_get_next_agreement_for_replica (replica, agmt_obj);
  1349. continue;
  1350. }
  1351. dn = agmt_get_dn_byref(agmt);
  1352. conn = (Repl_Connection *)agmt_get_connection(agmt);
  1353. if(conn == NULL){
  1354. /* no connection for this agreement, log error, and move on */
  1355. agmt_obj = agmtlist_get_next_agreement_for_replica (replica, agmt_obj);
  1356. continue;
  1357. }
  1358. crc = conn_connect(conn);
  1359. if (CONN_OPERATION_FAILED == crc ){
  1360. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "releaseRUV_task: failed to connect "
  1361. "to repl agmt (%s), error %d\n",slapi_sdn_get_dn(dn), ACQUIRE_TRANSIENT_ERROR);
  1362. rc = LDAP_OPERATIONS_ERROR;
  1363. } else if (CONN_SSL_NOT_ENABLED == crc){
  1364. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "releaseRUV_task: failed to acquire "
  1365. "repl agmt (%s), error %d\n",slapi_sdn_get_dn(dn), ACQUIRE_FATAL_ERROR);
  1366. rc = LDAP_OPERATIONS_ERROR;
  1367. } else {
  1368. conn_cancel_linger(conn);
  1369. crc = conn_send_extended_operation(conn, REPL_RELEASERUV_OID, payload, NULL, &send_msgid);
  1370. if (CONN_OPERATION_SUCCESS != crc){
  1371. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: failed to send "
  1372. "releaseRUV extended op to repl agmt (%s), error %d\n", slapi_sdn_get_dn(dn), crc);
  1373. rc = LDAP_OPERATIONS_ERROR;
  1374. } else {
  1375. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: successfully sent "
  1376. "releaseRUV extended op to (%s)\n",slapi_sdn_get_dn(dn));
  1377. }
  1378. conn_start_linger(conn);
  1379. }
  1380. if(crc){
  1381. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: replica (%s) has not "
  1382. "been released. You will need to rerun the task\n",
  1383. slapi_sdn_get_dn(dn));
  1384. rc = crc;
  1385. }
  1386. agmt_obj = agmtlist_get_next_agreement_for_replica (replica, agmt_obj);
  1387. }
  1388. done:
  1389. /*
  1390. * reset the released/clean rid
  1391. */
  1392. if(rc == 0){
  1393. set_released_rid(ALREADY_RELEASED);
  1394. delete_cleaned_rid();
  1395. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: Successfully released rid (%d)\n", rid);
  1396. } else {
  1397. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "cleanAllRUV_task: Failed to release rid (%d), error (%d)\n", rid, rc);
  1398. }
  1399. if(payload)
  1400. ber_bvfree(payload);
  1401. slapi_ch_free_string(&ridstr);
  1402. return rc;
  1403. }
  1404. static struct berval *
  1405. create_ruv_payload(char *value){
  1406. struct berval *req_data = NULL;
  1407. BerElement *tmp_bere = NULL;
  1408. if ((tmp_bere = der_alloc()) == NULL){
  1409. goto error;
  1410. }
  1411. if (ber_printf(tmp_bere, "{s", value) == -1){
  1412. goto error;
  1413. }
  1414. if (ber_printf(tmp_bere, "}") == -1){
  1415. goto error;
  1416. }
  1417. if (ber_flatten(tmp_bere, &req_data) == -1){
  1418. goto error;
  1419. }
  1420. goto done;
  1421. error:
  1422. if (NULL != req_data){
  1423. ber_bvfree(req_data);
  1424. req_data = NULL;
  1425. }
  1426. done:
  1427. if (NULL != tmp_bere){
  1428. ber_free(tmp_bere, 1);
  1429. tmp_bere = NULL;
  1430. }
  1431. return req_data;
  1432. }
  1433. int
  1434. is_cleaned_rid(ReplicaId rid)
  1435. {
  1436. if(rid == cleaned_rid){
  1437. return 1;
  1438. } else {
  1439. return 0;
  1440. }
  1441. }
  1442. void
  1443. set_cleaned_rid( ReplicaId rid )
  1444. {
  1445. cleaned_rid = rid;
  1446. }
  1447. void
  1448. delete_cleaned_rid()
  1449. {
  1450. cleaned_rid = 0;
  1451. }
  1452. int
  1453. get_released_rid()
  1454. {
  1455. return released_rid;
  1456. }
  1457. int
  1458. is_released_rid(int rid)
  1459. {
  1460. if(rid == released_rid){
  1461. return 1;
  1462. } else {
  1463. return 0;
  1464. }
  1465. }
  1466. int
  1467. is_already_released_rid()
  1468. {
  1469. if(released_rid == ALREADY_RELEASED){
  1470. return 1;
  1471. } else {
  1472. return 0;
  1473. }
  1474. }
  1475. void
  1476. set_released_rid( int rid )
  1477. {
  1478. released_rid = rid;
  1479. }
  1480. void
  1481. delete_released_rid()
  1482. {
  1483. released_rid = 0;
  1484. }