repl5_replica_config.c 54 KB

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