repl5_plugins.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436
  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. /*
  42. * repl5_consumer.c - consumer plugin functions
  43. */
  44. /*
  45. * LDAP Data Model Constraints...
  46. *
  47. * 1) Parent entry must exist.
  48. * 2) RDN must be unique.
  49. * 3) RDN components must be attribute values.
  50. * 4) Must conform to the schema constraints - Single Valued Attributes.
  51. * 5) Must conform to the schema constraints - Required Attributes.
  52. * 6) Must conform to the schema constraints - No Extra Attributes.
  53. * 7) Duplicate attribute values are not permited.
  54. * 8) Cycle in the ancestry graph not permitted.
  55. *
  56. * Update Resolution Procedures...
  57. * 1) ...
  58. * 2) Add the UniqueID to the RDN.
  59. * 3) Remove the not present RDN component.
  60. * Use the UniqueID if the RDN becomes empty.
  61. * 4) Keep the most recent value.
  62. * 5) Ignore.
  63. * 6) Ignore.
  64. * 7) Keep the largest CSN for the duplicate value.
  65. * 8) Don't check for this.
  66. */
  67. #include "repl5.h"
  68. #include "repl.h"
  69. #include "cl5_api.h"
  70. #include "urp.h"
  71. static char *local_purl = NULL;
  72. static char *purl_attrs[] = {"nsslapd-localhost", "nsslapd-port", "nsslapd-secureport", NULL};
  73. /* Forward declarations */
  74. static void copy_operation_parameters(Slapi_PBlock *pb);
  75. static int write_changelog_and_ruv(Slapi_PBlock *pb);
  76. static int process_postop (Slapi_PBlock *pb);
  77. static int cancel_opcsn (Slapi_PBlock *pb);
  78. static int ruv_tombstone_op (Slapi_PBlock *pb);
  79. static PRBool process_operation (Slapi_PBlock *pb, const CSN *csn);
  80. static PRBool is_mmr_replica (Slapi_PBlock *pb);
  81. static const char *replica_get_purl_for_op (const Replica *r, Slapi_PBlock *pb, const CSN *opcsn);
  82. /*
  83. * XXXggood - what to do if both ssl and non-ssl ports available? How
  84. * do you know which to use? Offer a choice in replication config?
  85. */
  86. int
  87. multimaster_set_local_purl()
  88. {
  89. int rc = 0;
  90. Slapi_Entry **entries;
  91. Slapi_PBlock *pb = NULL;
  92. pb = slapi_pblock_new ();
  93. slapi_search_internal_set_pb (pb, "cn=config", LDAP_SCOPE_BASE,
  94. "objectclass=*", purl_attrs, 0, NULL, NULL,
  95. repl_get_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION), 0);
  96. slapi_search_internal_pb (pb);
  97. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  98. if (rc != 0)
  99. {
  100. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "multimaster_set_local_purl: "
  101. "unable to read server configuration: error %d\n", rc);
  102. }
  103. else
  104. {
  105. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
  106. if (NULL == entries || NULL == entries[0])
  107. {
  108. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "multimaster_set_local_purl: "
  109. "server configuration missing\n");
  110. rc = -1;
  111. }
  112. else
  113. {
  114. char *host = slapi_entry_attr_get_charptr(entries[0], "nsslapd-localhost");
  115. char *port = slapi_entry_attr_get_charptr(entries[0], "nsslapd-port");
  116. char *sslport = slapi_entry_attr_get_charptr(entries[0], "nsslapd-secureport");
  117. if (host == NULL || ((port == NULL && sslport == NULL)))
  118. {
  119. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  120. "multimaster_set_local_purl: invalid server "
  121. "configuration\n");
  122. }
  123. else
  124. {
  125. local_purl = slapi_ch_smprintf("ldap://%s:%s", host, port);
  126. }
  127. /* slapi_ch_free acceptS NULL pointer */
  128. slapi_ch_free ((void**)&host);
  129. slapi_ch_free ((void**)&port);
  130. slapi_ch_free ((void**)&sslport);
  131. }
  132. }
  133. slapi_free_search_results_internal(pb);
  134. slapi_pblock_destroy (pb);
  135. return rc;
  136. }
  137. const char *
  138. multimaster_get_local_purl()
  139. {
  140. return local_purl;
  141. }
  142. /* ================= Multimaster Pre-Op Plugin Points ================== */
  143. int
  144. multimaster_preop_bind (Slapi_PBlock *pb)
  145. {
  146. return 0;
  147. }
  148. int
  149. multimaster_preop_add (Slapi_PBlock *pb)
  150. {
  151. Slapi_Operation *op;
  152. int is_replicated_operation;
  153. int is_fixup_operation;
  154. int is_legacy_operation;
  155. slapi_pblock_get(pb, SLAPI_OPERATION, &op);
  156. /* If there is no replica or it is a legacy consumer - we don't need to continue.
  157. Legacy plugin is handling 4.0 consumer code */
  158. /* but if it is legacy, csngen_handler needs to be assigned here */
  159. is_legacy_operation =
  160. operation_is_flag_set(op,OP_FLAG_LEGACY_REPLICATION_DN);
  161. if (is_legacy_operation)
  162. {
  163. copy_operation_parameters(pb);
  164. slapi_operation_set_csngen_handler(op,
  165. (void*)replica_generate_next_csn);
  166. return 0;
  167. }
  168. if (!is_mmr_replica (pb))
  169. {
  170. copy_operation_parameters(pb);
  171. return 0;
  172. }
  173. is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
  174. is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
  175. if(is_replicated_operation)
  176. {
  177. if(!is_fixup_operation)
  178. {
  179. LDAPControl **ctrlp;
  180. char sessionid[REPL_SESSION_ID_SIZE];
  181. get_repl_session_id (pb, sessionid, NULL);
  182. slapi_pblock_get(pb, SLAPI_REQCONTROLS, &ctrlp);
  183. if (NULL != ctrlp)
  184. {
  185. CSN *csn = NULL;
  186. char *target_uuid = NULL;
  187. char *superior_uuid= NULL;
  188. int drc = decode_NSDS50ReplUpdateInfoControl(ctrlp, &target_uuid, &superior_uuid, &csn, NULL /* modrdn_mods */);
  189. if (-1 == drc)
  190. {
  191. slapi_log_error(SLAPI_LOG_FATAL, REPLICATION_SUBSYSTEM,
  192. "%s An error occurred while decoding the replication update "
  193. "control - Add\n", sessionid);
  194. }
  195. else if (1 == drc)
  196. {
  197. /*
  198. * For add operations, we just set the operation csn. The entry's
  199. * uniqueid should already be an attribute of the replicated entry.
  200. */
  201. struct slapi_operation_parameters *op_params;
  202. /* we don't want to process replicated operations with csn smaller
  203. than the corresponding csn in the consumer's ruv */
  204. if (!process_operation (pb, csn))
  205. {
  206. slapi_send_ldap_result(pb, LDAP_SUCCESS, 0,
  207. "replication operation not processed, replica unavailable "
  208. "or csn ignored", 0, 0);
  209. csn_free (&csn);
  210. slapi_ch_free ((void**)&target_uuid);
  211. slapi_ch_free ((void**)&superior_uuid);
  212. return -1;
  213. }
  214. operation_set_csn(op, csn);
  215. slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID, target_uuid);
  216. slapi_pblock_get( pb, SLAPI_OPERATION_PARAMETERS, &op_params );
  217. /* JCMREPL - Complain if there's no superior uuid */
  218. op_params->p.p_add.parentuniqueid= superior_uuid; /* JCMREPL - Not very elegant */
  219. /* JCMREPL - When do these things get free'd? */
  220. if(target_uuid!=NULL)
  221. {
  222. /*
  223. * Make sure that the Unique Identifier in the Control is the
  224. * same as the one in the entry.
  225. */
  226. Slapi_Entry *addentry;
  227. char *entry_uuid;
  228. slapi_pblock_get( pb, SLAPI_ADD_ENTRY, &addentry );
  229. entry_uuid= slapi_entry_attr_get_charptr( addentry, SLAPI_ATTR_UNIQUEID);
  230. if(entry_uuid==NULL)
  231. {
  232. /* Odd that the entry doesn't have a Unique Identifier. But, we can fix it. */
  233. slapi_entry_set_uniqueid(addentry, slapi_ch_strdup(target_uuid)); /* JCMREPL - strdup EVIL! There should be a uuid dup function. */
  234. }
  235. else
  236. {
  237. if(strcasecmp(entry_uuid,target_uuid)!=0)
  238. {
  239. slapi_log_error(SLAPI_LOG_FATAL, REPLICATION_SUBSYSTEM,
  240. "%s Replicated Add received with Control_UUID=%s and Entry_UUID=%s.\n",
  241. sessionid, target_uuid,entry_uuid);
  242. }
  243. slapi_ch_free ((void**)&entry_uuid);
  244. }
  245. }
  246. }
  247. }
  248. else
  249. {
  250. PR_ASSERT(0); /* JCMREPL - A Replicated Operation with no Repl Baggage control... What does that mean? */
  251. }
  252. }
  253. else
  254. {
  255. /* Replicated & Fixup Operation */
  256. }
  257. }
  258. else
  259. {
  260. slapi_operation_set_csngen_handler ( op, (void*)replica_generate_next_csn );
  261. }
  262. copy_operation_parameters(pb);
  263. return 0;
  264. }
  265. int
  266. multimaster_preop_delete (Slapi_PBlock *pb)
  267. {
  268. Slapi_Operation *op;
  269. int is_replicated_operation;
  270. int is_fixup_operation;
  271. int is_legacy_operation;
  272. slapi_pblock_get(pb, SLAPI_OPERATION, &op);
  273. /* If there is no replica or it is a legacy consumer - we don't need to continue.
  274. Legacy plugin is handling 4.0 consumer code */
  275. /* but if it is legacy, csngen_handler needs to be assigned here */
  276. is_legacy_operation =
  277. operation_is_flag_set(op,OP_FLAG_LEGACY_REPLICATION_DN);
  278. if (is_legacy_operation)
  279. {
  280. copy_operation_parameters(pb);
  281. slapi_operation_set_replica_attr_handler ( op, (void*)replica_get_attr );
  282. slapi_operation_set_csngen_handler(op,
  283. (void*)replica_generate_next_csn);
  284. return 0;
  285. }
  286. if (!is_mmr_replica (pb))
  287. {
  288. copy_operation_parameters(pb);
  289. return 0;
  290. }
  291. is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
  292. is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
  293. if(is_replicated_operation)
  294. {
  295. if(!is_fixup_operation)
  296. {
  297. LDAPControl **ctrlp;
  298. char sessionid[REPL_SESSION_ID_SIZE];
  299. get_repl_session_id (pb, sessionid, NULL);
  300. slapi_pblock_get(pb, SLAPI_REQCONTROLS, &ctrlp);
  301. if (NULL != ctrlp)
  302. {
  303. CSN *csn = NULL;
  304. char *target_uuid = NULL;
  305. int drc = decode_NSDS50ReplUpdateInfoControl(ctrlp, &target_uuid, NULL, &csn, NULL /* modrdn_mods */);
  306. if (-1 == drc)
  307. {
  308. slapi_log_error(SLAPI_LOG_FATAL, REPLICATION_SUBSYSTEM,
  309. "%s An error occurred while decoding the replication update "
  310. "control - Delete\n", sessionid);
  311. }
  312. else if (1 == drc)
  313. {
  314. /* we don't want to process replicated operations with csn smaller
  315. than the corresponding csn in the consumer's ruv */
  316. if (!process_operation (pb, csn))
  317. {
  318. slapi_send_ldap_result(pb, LDAP_SUCCESS, 0,
  319. "replication operation not processed, replica unavailable "
  320. "or csn ignored", 0, 0);
  321. slapi_log_error(SLAPI_LOG_REPL, REPLICATION_SUBSYSTEM,
  322. "%s replication operation not processed, replica unavailable "
  323. "or csn ignored\n", sessionid);
  324. csn_free (&csn);
  325. slapi_ch_free ((void**)&target_uuid);
  326. return -1;
  327. }
  328. /*
  329. * For delete operations, we pass the uniqueid of the deleted entry
  330. * to the backend and let it sort out which entry to really delete.
  331. * We also set the operation csn.
  332. */
  333. operation_set_csn(op, csn);
  334. slapi_pblock_set(pb, SLAPI_TARGET_UNIQUEID, target_uuid);
  335. }
  336. }
  337. else
  338. {
  339. PR_ASSERT(0); /* JCMREPL - A Replicated Operation with no Repl Baggage control... What does that mean? */
  340. }
  341. }
  342. else
  343. {
  344. /* Replicated & Fixup Operation */
  345. }
  346. }
  347. else
  348. {
  349. slapi_operation_set_csngen_handler ( op, (void*)replica_generate_next_csn );
  350. }
  351. copy_operation_parameters(pb);
  352. slapi_operation_set_replica_attr_handler ( op, (void*)replica_get_attr );
  353. return 0;
  354. }
  355. int
  356. multimaster_preop_modify (Slapi_PBlock *pb)
  357. {
  358. Slapi_Operation *op;
  359. int is_replicated_operation;
  360. int is_fixup_operation;
  361. int is_legacy_operation;
  362. slapi_pblock_get(pb, SLAPI_OPERATION, &op);
  363. /* If there is no replica or it is a legacy consumer - we don't need to continue.
  364. Legacy plugin is handling 4.0 consumer code */
  365. /* but if it is legacy, csngen_handler needs to be assigned here */
  366. is_legacy_operation =
  367. operation_is_flag_set(op,OP_FLAG_LEGACY_REPLICATION_DN);
  368. if (is_legacy_operation)
  369. {
  370. copy_operation_parameters(pb);
  371. slapi_operation_set_csngen_handler(op,
  372. (void*)replica_generate_next_csn);
  373. return 0;
  374. }
  375. if (!is_mmr_replica (pb))
  376. {
  377. copy_operation_parameters(pb);
  378. return 0;
  379. }
  380. is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
  381. is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
  382. if(is_replicated_operation)
  383. {
  384. if(!is_fixup_operation)
  385. {
  386. LDAPControl **ctrlp;
  387. char sessionid[REPL_SESSION_ID_SIZE];
  388. get_repl_session_id (pb, sessionid, NULL);
  389. slapi_pblock_get(pb, SLAPI_REQCONTROLS, &ctrlp);
  390. if (NULL != ctrlp)
  391. {
  392. CSN *csn = NULL;
  393. char *target_uuid = NULL;
  394. int drc = decode_NSDS50ReplUpdateInfoControl(ctrlp, &target_uuid, NULL, &csn, NULL /* modrdn_mods */);
  395. if (-1 == drc)
  396. {
  397. slapi_log_error(SLAPI_LOG_FATAL, REPLICATION_SUBSYSTEM,
  398. "%s An error occurred while decoding the replication update "
  399. "control- Modify\n", sessionid);
  400. }
  401. else if (1 == drc)
  402. {
  403. /* we don't want to process replicated operations with csn smaller
  404. than the corresponding csn in the consumer's ruv */
  405. if (!process_operation (pb, csn))
  406. {
  407. slapi_send_ldap_result(pb, LDAP_SUCCESS, 0,
  408. "replication operation not processed, replica unavailable "
  409. "or csn ignored", 0, 0);
  410. slapi_log_error(SLAPI_LOG_REPL, REPLICATION_SUBSYSTEM,
  411. "%s replication operation not processed, replica unavailable "
  412. "or csn ignored\n", sessionid);
  413. csn_free (&csn);
  414. slapi_ch_free ((void**)&target_uuid);
  415. return -1;
  416. }
  417. /*
  418. * For modify operations, we pass the uniqueid of the modified entry
  419. * to the backend and let it sort out which entry to really modify.
  420. * We also set the operation csn.
  421. */
  422. operation_set_csn(op, csn);
  423. slapi_pblock_set(pb, SLAPI_TARGET_UNIQUEID, target_uuid);
  424. }
  425. }
  426. else
  427. {
  428. PR_ASSERT(0); /* JCMREPL - A Replicated Operation with no Repl Baggage control... What does that mean? */
  429. }
  430. }
  431. else
  432. {
  433. /* Replicated & Fixup Operation */
  434. }
  435. }
  436. else
  437. {
  438. slapi_operation_set_csngen_handler ( op, (void*)replica_generate_next_csn );
  439. }
  440. copy_operation_parameters(pb);
  441. return 0;
  442. }
  443. int
  444. multimaster_preop_modrdn (Slapi_PBlock *pb)
  445. {
  446. Slapi_Operation *op;
  447. int is_replicated_operation;
  448. int is_fixup_operation;
  449. int is_legacy_operation;
  450. slapi_pblock_get(pb, SLAPI_OPERATION, &op);
  451. /* If there is no replica or it is a legacy consumer - we don't need to continue.
  452. Legacy plugin is handling 4.0 consumer code */
  453. /* but if it is legacy, csngen_handler needs to be assigned here */
  454. is_legacy_operation =
  455. operation_is_flag_set(op,OP_FLAG_LEGACY_REPLICATION_DN);
  456. if (is_legacy_operation)
  457. {
  458. copy_operation_parameters(pb);
  459. slapi_operation_set_csngen_handler(op,
  460. (void*)replica_generate_next_csn);
  461. return 0;
  462. }
  463. if (!is_mmr_replica (pb))
  464. {
  465. copy_operation_parameters(pb);
  466. return 0;
  467. }
  468. is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
  469. is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
  470. if(is_replicated_operation)
  471. {
  472. if(!is_fixup_operation)
  473. {
  474. LDAPControl **ctrlp;
  475. char sessionid[REPL_SESSION_ID_SIZE];
  476. get_repl_session_id (pb, sessionid, NULL);
  477. slapi_pblock_get(pb, SLAPI_REQCONTROLS, &ctrlp);
  478. if (NULL != ctrlp)
  479. {
  480. CSN *csn = NULL;
  481. char *target_uuid = NULL;
  482. char *newsuperior_uuid = NULL;
  483. LDAPMod **modrdn_mods = NULL;
  484. int drc = decode_NSDS50ReplUpdateInfoControl(ctrlp, &target_uuid, &newsuperior_uuid,
  485. &csn, &modrdn_mods);
  486. if (-1 == drc)
  487. {
  488. slapi_log_error(SLAPI_LOG_FATAL, REPLICATION_SUBSYSTEM,
  489. "%s An error occurred while decoding the replication update "
  490. "control - ModRDN\n", sessionid);
  491. }
  492. else if (1 == drc)
  493. {
  494. /*
  495. * For modrdn operations, we pass the uniqueid of the entry being
  496. * renamed to the backend and let it sort out which entry to really
  497. * rename. We also set the operation csn, and if the newsuperior_uuid
  498. * was sent, we decode that as well.
  499. */
  500. struct slapi_operation_parameters *op_params;
  501. /* we don't want to process replicated operations with csn smaller
  502. than the corresponding csn in the consumer's ruv */
  503. if (!process_operation (pb, csn))
  504. {
  505. slapi_send_ldap_result(pb, LDAP_SUCCESS, 0,
  506. "replication operation not processed, replica unavailable "
  507. "or csn ignored", 0, 0);
  508. csn_free (&csn);
  509. slapi_ch_free ((void**)&target_uuid);
  510. slapi_ch_free ((void**)&newsuperior_uuid);
  511. ldap_mods_free (modrdn_mods, 1);
  512. return -1;
  513. }
  514. operation_set_csn(op, csn);
  515. slapi_pblock_set(pb, SLAPI_TARGET_UNIQUEID, target_uuid);
  516. slapi_pblock_get( pb, SLAPI_OPERATION_PARAMETERS, &op_params );
  517. op_params->p.p_modrdn.modrdn_newsuperior_address.uniqueid= newsuperior_uuid; /* JCMREPL - Not very elegant */
  518. }
  519. /*
  520. * The replicated modrdn operation may also contain a sequence
  521. * that contains side effects of the modrdn operation, e.g. the
  522. * modifiersname and modifytimestamp are updated.
  523. */
  524. if (NULL != modrdn_mods)
  525. {
  526. LDAPMod **mods;
  527. Slapi_Mods smods;
  528. int i;
  529. slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &mods);
  530. slapi_mods_init_passin(&smods, mods);
  531. for (i = 0; NULL != modrdn_mods[i]; i++)
  532. {
  533. slapi_mods_add_ldapmod(&smods, modrdn_mods[i]); /* Does not copy mod */
  534. }
  535. mods = slapi_mods_get_ldapmods_passout(&smods);
  536. slapi_pblock_set(pb, SLAPI_MODIFY_MODS, mods);
  537. slapi_mods_done(&smods);
  538. slapi_ch_free((void **)&modrdn_mods); /* Free container only - contents are referred to by array "mods" */
  539. }
  540. }
  541. else
  542. {
  543. PR_ASSERT(0); /* JCMREPL - A Replicated Operation with no Repl Baggage control... What does that mean? */
  544. }
  545. }
  546. else
  547. {
  548. /* Replicated & Fixup Operation */
  549. }
  550. }
  551. else
  552. {
  553. slapi_operation_set_csngen_handler ( op, (void*)replica_generate_next_csn );
  554. }
  555. copy_operation_parameters(pb);
  556. return 0;
  557. }
  558. int
  559. multimaster_preop_search (Slapi_PBlock *pb)
  560. {
  561. return 0;
  562. }
  563. int
  564. multimaster_preop_compare (Slapi_PBlock *pb)
  565. {
  566. return 0;
  567. }
  568. static void
  569. purge_entry_state_information (Slapi_PBlock *pb)
  570. {
  571. CSN *purge_csn;
  572. Object *repl_obj;
  573. Replica *replica;
  574. /* we don't want to trim RUV tombstone because we will
  575. deadlock with ourself */
  576. if (ruv_tombstone_op (pb))
  577. return;
  578. repl_obj = replica_get_replica_for_op(pb);
  579. if (NULL != repl_obj)
  580. {
  581. replica = object_get_data(repl_obj);
  582. if (NULL != replica)
  583. {
  584. purge_csn = replica_get_purge_csn(replica);
  585. }
  586. if (NULL != purge_csn)
  587. {
  588. Slapi_Entry *e;
  589. int optype;
  590. slapi_pblock_get(pb, SLAPI_OPERATION_TYPE, &optype);
  591. switch (optype)
  592. {
  593. case SLAPI_OPERATION_MODIFY:
  594. slapi_pblock_get(pb, SLAPI_MODIFY_EXISTING_ENTRY, &e);
  595. break;
  596. case SLAPI_OPERATION_MODRDN:
  597. /* XXXggood - the following always gives a NULL entry - why? */
  598. slapi_pblock_get(pb, SLAPI_MODRDN_EXISTING_ENTRY, &e);
  599. break;
  600. case SLAPI_OPERATION_DELETE:
  601. slapi_pblock_get(pb, SLAPI_DELETE_EXISTING_ENTRY, &e);
  602. break;
  603. default:
  604. e = NULL; /* Don't purge on ADD - not needed */
  605. break;
  606. }
  607. if (NULL != e)
  608. {
  609. char csn_str[CSN_STRSIZE];
  610. entry_purge_state_information(e, purge_csn);
  611. /* conntion is always null */
  612. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name,
  613. "Purged state information from entry %s up to "
  614. "CSN %s\n", slapi_entry_get_dn(e),
  615. csn_as_string(purge_csn, PR_FALSE, csn_str));
  616. }
  617. csn_free(&purge_csn);
  618. }
  619. object_release(repl_obj);
  620. }
  621. }
  622. int
  623. multimaster_bepreop_add (Slapi_PBlock *pb)
  624. {
  625. int rc= 0;
  626. Slapi_Operation *op;
  627. int is_replicated_operation;
  628. int is_fixup_operation;
  629. slapi_pblock_get(pb, SLAPI_OPERATION, &op);
  630. is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
  631. is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
  632. /* For replicated operations, apply URP algorithm */
  633. if (is_replicated_operation && !is_fixup_operation)
  634. {
  635. rc = urp_add_operation(pb);
  636. }
  637. return rc;
  638. }
  639. int
  640. multimaster_bepreop_delete (Slapi_PBlock *pb)
  641. {
  642. int rc= 0;
  643. Slapi_Operation *op;
  644. int is_replicated_operation;
  645. int is_fixup_operation;
  646. slapi_pblock_get(pb, SLAPI_OPERATION, &op);
  647. is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
  648. is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
  649. /* For replicated operations, apply URP algorithm */
  650. if(is_replicated_operation && !is_fixup_operation)
  651. {
  652. rc = urp_delete_operation(pb);
  653. }
  654. return rc;
  655. }
  656. int
  657. multimaster_bepreop_modify (Slapi_PBlock *pb)
  658. {
  659. int rc= 0;
  660. Slapi_Operation *op;
  661. int is_replicated_operation;
  662. int is_fixup_operation;
  663. slapi_pblock_get(pb, SLAPI_OPERATION, &op);
  664. is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
  665. is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
  666. /* For replicated operations, apply URP algorithm */
  667. if(is_replicated_operation && !is_fixup_operation)
  668. {
  669. rc = urp_modify_operation(pb);
  670. }
  671. /* Clean up old state information */
  672. purge_entry_state_information(pb);
  673. return rc;
  674. }
  675. int
  676. multimaster_bepreop_modrdn (Slapi_PBlock *pb)
  677. {
  678. int rc= 0;
  679. Slapi_Operation *op;
  680. int is_replicated_operation;
  681. int is_fixup_operation;
  682. slapi_pblock_get(pb, SLAPI_OPERATION, &op);
  683. is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
  684. is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
  685. /* For replicated operations, apply URP algorithm */
  686. if(is_replicated_operation && !is_fixup_operation)
  687. {
  688. rc = urp_modrdn_operation(pb);
  689. }
  690. /* Clean up old state information */
  691. purge_entry_state_information(pb);
  692. return rc;
  693. }
  694. int
  695. multimaster_bepostop_modrdn (Slapi_PBlock *pb)
  696. {
  697. Slapi_Operation *op;
  698. slapi_pblock_get(pb, SLAPI_OPERATION, &op);
  699. if ( ! operation_is_flag_set (op, OP_FLAG_REPL_FIXUP) )
  700. {
  701. urp_post_modrdn_operation (pb);
  702. }
  703. return 0;
  704. }
  705. int
  706. multimaster_bepostop_delete (Slapi_PBlock *pb)
  707. {
  708. Slapi_Operation *op;
  709. slapi_pblock_get(pb, SLAPI_OPERATION, &op);
  710. if ( ! operation_is_flag_set (op, OP_FLAG_REPL_FIXUP) )
  711. {
  712. urp_post_delete_operation (pb);
  713. }
  714. return 0;
  715. }
  716. /* postop - write to changelog */
  717. int
  718. multimaster_postop_bind (Slapi_PBlock *pb)
  719. {
  720. return 0;
  721. }
  722. int
  723. multimaster_postop_add (Slapi_PBlock *pb)
  724. {
  725. return process_postop(pb);
  726. }
  727. int
  728. multimaster_postop_delete (Slapi_PBlock *pb)
  729. {
  730. return process_postop(pb);
  731. }
  732. int
  733. multimaster_postop_modify (Slapi_PBlock *pb)
  734. {
  735. return process_postop(pb);
  736. }
  737. int
  738. multimaster_postop_modrdn (Slapi_PBlock *pb)
  739. {
  740. return process_postop(pb);
  741. }
  742. /* Helper functions */
  743. /*
  744. * This function makes a copy of the operation parameters
  745. * and stashes them in the consumer operation extension.
  746. * This is where the 5.0 Change Log will get the operation
  747. * details from.
  748. */
  749. static void
  750. copy_operation_parameters(Slapi_PBlock *pb)
  751. {
  752. Slapi_Operation *op = NULL;
  753. struct slapi_operation_parameters *op_params;
  754. supplier_operation_extension *opext;
  755. Object *repl_obj;
  756. Replica *replica;
  757. repl_obj = replica_get_replica_for_op (pb);
  758. /* we are only interested in the updates to replicas */
  759. if (repl_obj)
  760. {
  761. /* we only save the original operation parameters for replicated operations
  762. since client operations don't go through urp engine and pblock data can be logged */
  763. slapi_pblock_get( pb, SLAPI_OPERATION, &op );
  764. PR_ASSERT (op);
  765. replica = (Replica*)object_get_data (repl_obj);
  766. PR_ASSERT (replica);
  767. opext = (supplier_operation_extension*) repl_sup_get_ext (REPL_SUP_EXT_OP, op);
  768. if (operation_is_flag_set(op,OP_FLAG_REPLICATED) &&
  769. !operation_is_flag_set(op, OP_FLAG_REPL_FIXUP))
  770. {
  771. slapi_pblock_get (pb, SLAPI_OPERATION_PARAMETERS, &op_params);
  772. opext->operation_parameters= operation_parameters_dup(op_params);
  773. }
  774. /* this condition is needed to avoid re-entering backend serial lock
  775. when ruv state is updated */
  776. if (!operation_is_flag_set(op, OP_FLAG_REPL_FIXUP))
  777. {
  778. /* save replica generation in case it changes */
  779. opext->repl_gen = replica_get_generation (replica);
  780. }
  781. object_release (repl_obj);
  782. }
  783. }
  784. /*
  785. * Helper function: update the RUV so that it reflects the
  786. * locally-processed update. This is called for both replicated
  787. * and non-replicated operations.
  788. */
  789. static void
  790. update_ruv_component(Replica *replica, CSN *opcsn, Slapi_PBlock *pb)
  791. {
  792. PRBool legacy;
  793. char *purl;
  794. if (!replica || !opcsn)
  795. return;
  796. /* Replica configured, so update its ruv */
  797. legacy = replica_is_legacy_consumer (replica);
  798. if (legacy)
  799. purl = replica_get_legacy_purl (replica);
  800. else
  801. purl = (char*)replica_get_purl_for_op (replica, pb, opcsn);
  802. replica_update_ruv(replica, opcsn, purl);
  803. if (legacy)
  804. {
  805. slapi_ch_free ((void**)&purl);
  806. }
  807. }
  808. /*
  809. * Write the changelog. Note: it is an error to call write_changelog_and_ruv() for fixup
  810. * operations. The caller should avoid calling this function if the operation is
  811. * a fixup op.
  812. * Also update the ruv - we need to do this while we have the replica lock acquired
  813. * so that the csn is written to the changelog and the ruv is updated with the csn
  814. * in one atomic operation - if there is no changelog, we still need to update
  815. * the ruv (e.g. for consumers)
  816. */
  817. static int
  818. write_changelog_and_ruv (Slapi_PBlock *pb)
  819. {
  820. int rc;
  821. slapi_operation_parameters *op_params = NULL;
  822. Object *repl_obj;
  823. int return_value = 0;
  824. Replica *r;
  825. /* we only log changes for operations applied to a replica */
  826. repl_obj = replica_get_replica_for_op (pb);
  827. if (repl_obj == NULL)
  828. return 0;
  829. r = (Replica*)object_get_data (repl_obj);
  830. PR_ASSERT (r);
  831. if (replica_is_flag_set (r, REPLICA_LOG_CHANGES) &&
  832. (cl5GetState () == CL5_STATE_OPEN))
  833. {
  834. supplier_operation_extension *opext = NULL;
  835. const char *repl_name;
  836. char *repl_gen;
  837. Slapi_Operation *op;
  838. slapi_pblock_get(pb, SLAPI_OPERATION, &op);
  839. opext = (supplier_operation_extension*) repl_sup_get_ext (REPL_SUP_EXT_OP, op);
  840. PR_ASSERT (opext);
  841. /* get replica generation and replica name to pass to the write function */
  842. repl_name = replica_get_name (r);
  843. repl_gen = opext->repl_gen;
  844. PR_ASSERT (repl_name && repl_gen);
  845. /* for replicated operations, we log the original, non-urp data which is
  846. saved in the operation extension */
  847. if (operation_is_flag_set(op,OP_FLAG_REPLICATED))
  848. {
  849. PR_ASSERT (opext->operation_parameters);
  850. op_params = opext->operation_parameters;
  851. }
  852. else /* since client operations don't go through urp, we log the operation data in pblock */
  853. {
  854. Slapi_Entry *e = NULL;
  855. const char *uniqueid = NULL;
  856. slapi_pblock_get (pb, SLAPI_OPERATION_PARAMETERS, &op_params);
  857. PR_ASSERT (op_params);
  858. /* need to set uniqueid operation parameter */
  859. /* we try to use the appropriate entry (pre op or post op)
  860. depending on the type of operation (add, delete, modify)
  861. However, in some cases, the backend operation may fail in
  862. a non fatal way (e.g. attempt to remove an attribute value
  863. that does not exist) but we still need to log the change.
  864. So, the POST_OP entry may not have been set in the FE modify
  865. code. In that case, we use the PRE_OP entry.
  866. */
  867. slapi_pblock_get (pb, SLAPI_ENTRY_POST_OP, &e);
  868. if ((e == NULL) ||
  869. (op_params->operation_type == SLAPI_OPERATION_DELETE))
  870. {
  871. slapi_pblock_get (pb, SLAPI_ENTRY_PRE_OP, &e);
  872. }
  873. PR_ASSERT (e);
  874. uniqueid = slapi_entry_get_uniqueid (e);
  875. PR_ASSERT (uniqueid);
  876. op_params->target_address.uniqueid = slapi_ch_strdup (uniqueid);
  877. }
  878. /* we might have stripped all the mods - in that case we do not
  879. log the operation */
  880. if (op_params->operation_type != SLAPI_OPERATION_MODIFY ||
  881. op_params->p.p_modify.modify_mods != NULL)
  882. {
  883. if (cl5_is_diskfull() && !cl5_diskspace_is_available())
  884. {
  885. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  886. "write_changelog_and_ruv: Skipped due to DISKFULL\n");
  887. return 0;
  888. }
  889. rc = cl5WriteOperation(repl_name, repl_gen, op_params,
  890. !operation_is_flag_set(op, OP_FLAG_REPLICATED));
  891. if (rc != CL5_SUCCESS)
  892. {
  893. char csn_str[CSN_STRSIZE];
  894. /* ONREPL - log error */
  895. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  896. "write_changelog_and_ruv: can't add a change for "
  897. "%s (uniqid: %s, optype: %lu) to changelog csn %s\n",
  898. op_params->target_address.dn,
  899. op_params->target_address.uniqueid,
  900. op_params->operation_type,
  901. csn_as_string(op_params->csn, PR_FALSE, csn_str));
  902. return_value = 1;
  903. }
  904. }
  905. if (!operation_is_flag_set(op,OP_FLAG_REPLICATED))
  906. {
  907. slapi_ch_free((void**)&op_params->target_address.uniqueid);
  908. }
  909. }
  910. /*
  911. This was moved because we need to write the changelog and update
  912. the ruv in one atomic operation - I have seen cases where the inc
  913. protocol thread interrupts this thread between the time the changelog
  914. is written and the ruv is updated - this causes confusion in several
  915. places, especially in _cl5SkipReplayEntry since it cannot find the csn it
  916. just read from the changelog in either the supplier or consumer ruv
  917. */
  918. if (0 == return_value) {
  919. Slapi_Operation *op;
  920. CSN *opcsn;
  921. slapi_pblock_get( pb, SLAPI_OPERATION, &op );
  922. opcsn = operation_get_csn(op);
  923. update_ruv_component(r, opcsn, pb);
  924. }
  925. object_release (repl_obj);
  926. return return_value;
  927. }
  928. /*
  929. * Postop processing - write the changelog if the operation resulted in
  930. * an LDAP_SUCCESS result code, update the RUV, and notify the replication
  931. * agreements about the change.
  932. * If the result code is not LDAP_SUCCESS, then cancel the operation CSN.
  933. */
  934. static int
  935. process_postop (Slapi_PBlock *pb)
  936. {
  937. int rc = LDAP_SUCCESS;
  938. Slapi_Operation *op;
  939. Slapi_Backend *be;
  940. int is_replicated_operation = 0;
  941. CSN *opcsn = NULL;
  942. char sessionid[REPL_SESSION_ID_SIZE];
  943. /* we just let fixup operations through */
  944. slapi_pblock_get( pb, SLAPI_OPERATION, &op );
  945. if ((operation_is_flag_set(op, OP_FLAG_REPL_FIXUP)) ||
  946. (operation_is_flag_set(op, OP_FLAG_TOMBSTONE_ENTRY)))
  947. {
  948. return 0;
  949. }
  950. /* ignore operations intended for chaining backends - they will be
  951. replicated back to us or should be ignored anyway
  952. replicated operations should be processed normally, as they should
  953. be going to a local backend */
  954. is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
  955. slapi_pblock_get(pb, SLAPI_BACKEND, &be);
  956. if (!is_replicated_operation &&
  957. slapi_be_is_flag_set(be,SLAPI_BE_FLAG_REMOTE_DATA))
  958. {
  959. return 0;
  960. }
  961. get_repl_session_id (pb, sessionid, &opcsn);
  962. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
  963. /*
  964. * Don't abandon writing changelog since we'd do everything
  965. * possible to keep the changelog in sync with the backend
  966. * db which was committed before this function was called.
  967. *
  968. * if (rc == LDAP_SUCCESS && !slapi_op_abandoned(pb))
  969. */
  970. if (rc == LDAP_SUCCESS)
  971. {
  972. rc = write_changelog_and_ruv(pb);
  973. if (rc == 0)
  974. {
  975. agmtlist_notify_all(pb);
  976. }
  977. else
  978. {
  979. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name, "%s process postop: error writing changelog and ruv\n", sessionid);
  980. }
  981. }
  982. else if (opcsn)
  983. {
  984. rc = cancel_opcsn (pb);
  985. /* Don't try to get session id since conn is always null */
  986. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name,
  987. "%s process postop: canceling operation csn\n", sessionid);
  988. }
  989. /* the target unique id is set in the modify_preop above, so
  990. we need to free it */
  991. /* The following bunch of frees code does not belong to this place
  992. * but rather to operation_free who should be responsible for calling
  993. * operation_parameters_free and it doesn't. I guess this is like this
  994. * because several crashes happened in the past regarding some opparams
  995. * that were getting individually freed before they should. Whatever
  996. * the case, this is not the place and we should make sure that this
  997. * code gets removed for 5.next and substituted by the strategy (operation_free).
  998. * For 5.0, such change is too risky, so this will be done here */
  999. if (is_replicated_operation)
  1000. {
  1001. slapi_operation_parameters *op_params = NULL;
  1002. int optype = 0;
  1003. /* target uid and csn are set for all repl operations. Free them */
  1004. char *target_uuid = NULL;
  1005. slapi_pblock_get(pb, SLAPI_OPERATION_TYPE, &optype);
  1006. slapi_pblock_get(pb, SLAPI_TARGET_UNIQUEID, &target_uuid);
  1007. slapi_pblock_set(pb, SLAPI_TARGET_UNIQUEID, NULL);
  1008. slapi_ch_free((void**)&target_uuid);
  1009. if (optype == SLAPI_OPERATION_ADD) {
  1010. slapi_pblock_get( pb, SLAPI_OPERATION_PARAMETERS, &op_params );
  1011. slapi_ch_free((void **) &op_params->p.p_add.parentuniqueid);
  1012. }
  1013. if (optype == SLAPI_OPERATION_MODRDN) {
  1014. slapi_pblock_get( pb, SLAPI_OPERATION_PARAMETERS, &op_params );
  1015. slapi_ch_free((void **) &op_params->p.p_modrdn.modrdn_newsuperior_address.uniqueid);
  1016. }
  1017. }
  1018. if (NULL == opcsn)
  1019. opcsn = operation_get_csn(op);
  1020. if (opcsn)
  1021. csn_free(&opcsn);
  1022. return rc;
  1023. }
  1024. /*
  1025. * Cancel an operation CSN. This removes it from any CSN pending lists.
  1026. * This function is called when a previously-generated CSN will not
  1027. * be needed, e.g. if the update operation produced an error.
  1028. */
  1029. static int
  1030. cancel_opcsn (Slapi_PBlock *pb)
  1031. {
  1032. Object *repl_obj;
  1033. Slapi_Operation *op = NULL;
  1034. PR_ASSERT (pb);
  1035. repl_obj = replica_get_replica_for_op (pb);
  1036. slapi_pblock_get(pb, SLAPI_OPERATION, &op);
  1037. PR_ASSERT (op);
  1038. if (repl_obj)
  1039. {
  1040. Replica *r;
  1041. Object *gen_obj;
  1042. CSNGen *gen;
  1043. CSN *opcsn;
  1044. r = (Replica*)object_get_data (repl_obj);
  1045. PR_ASSERT (r);
  1046. opcsn = operation_get_csn(op);
  1047. if (!operation_is_flag_set(op,OP_FLAG_REPLICATED))
  1048. {
  1049. /* get csn generator for the replica */
  1050. gen_obj = replica_get_csngen (r);
  1051. PR_ASSERT (gen_obj);
  1052. gen = (CSNGen*)object_get_data (gen_obj);
  1053. if (NULL != opcsn)
  1054. {
  1055. csngen_abort_csn (gen, operation_get_csn(op));
  1056. }
  1057. object_release (gen_obj);
  1058. }
  1059. else if (!operation_is_flag_set(op,OP_FLAG_REPL_FIXUP))
  1060. {
  1061. Object *ruv_obj;
  1062. ruv_obj = replica_get_ruv (r);
  1063. PR_ASSERT (ruv_obj);
  1064. ruv_cancel_csn_inprogress ((RUV*)object_get_data (ruv_obj), opcsn);
  1065. object_release (ruv_obj);
  1066. }
  1067. object_release (repl_obj);
  1068. }
  1069. return 0;
  1070. }
  1071. /*
  1072. * Return non-zero if the target entry DN is the DN of the RUV tombstone
  1073. * entry.
  1074. * The entry has rdn of nsuniqueid = ffffffff-ffffffff-ffffffff-ffffffff
  1075. */
  1076. static int
  1077. ruv_tombstone_op (Slapi_PBlock *pb)
  1078. {
  1079. char *uniqueid;
  1080. int rc;
  1081. slapi_pblock_get (pb, SLAPI_TARGET_UNIQUEID, &uniqueid);
  1082. rc = uniqueid && strcasecmp (uniqueid, RUV_STORAGE_ENTRY_UNIQUEID) == 0;
  1083. return rc;
  1084. }
  1085. /* we don't want to process replicated operations with csn smaller
  1086. than the corresponding csn in the consumer's ruv */
  1087. static PRBool
  1088. process_operation (Slapi_PBlock *pb, const CSN *csn)
  1089. {
  1090. Object *r_obj;
  1091. Replica *r;
  1092. Object *ruv_obj;
  1093. RUV *ruv;
  1094. int rc;
  1095. r_obj = replica_get_replica_for_op(pb);
  1096. if (r_obj == NULL)
  1097. {
  1098. char sessionid[REPL_SESSION_ID_SIZE];
  1099. get_repl_session_id (pb, sessionid, NULL);
  1100. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "%s process_operation: "
  1101. "can't locate replica for the replicated operation\n",
  1102. sessionid );
  1103. return PR_FALSE;
  1104. }
  1105. r = (Replica*)object_get_data (r_obj);
  1106. PR_ASSERT (r);
  1107. ruv_obj = replica_get_ruv (r);
  1108. PR_ASSERT (ruv_obj);
  1109. ruv = (RUV*)object_get_data (ruv_obj);
  1110. PR_ASSERT (ruv);
  1111. rc = ruv_add_csn_inprogress (ruv, csn);
  1112. object_release (ruv_obj);
  1113. object_release (r_obj);
  1114. return (rc == RUV_SUCCESS);
  1115. }
  1116. static PRBool
  1117. is_mmr_replica (Slapi_PBlock *pb)
  1118. {
  1119. Object *r_obj;
  1120. Replica *r;
  1121. PRBool mmr;
  1122. r_obj = replica_get_replica_for_op(pb);
  1123. if (r_obj == NULL)
  1124. {
  1125. return PR_FALSE;
  1126. }
  1127. r = (Replica*)object_get_data (r_obj);
  1128. PR_ASSERT (r);
  1129. mmr = !replica_is_legacy_consumer (r);
  1130. object_release (r_obj);
  1131. return mmr;
  1132. }
  1133. static const char *replica_get_purl_for_op (const Replica *r, Slapi_PBlock *pb, const CSN *opcsn)
  1134. {
  1135. int is_replicated_op;
  1136. const char *purl = NULL;
  1137. slapi_pblock_get(pb, SLAPI_IS_MMR_REPLICATED_OPERATION, &is_replicated_op);
  1138. if (!is_replicated_op)
  1139. {
  1140. purl = multimaster_get_local_purl();
  1141. }
  1142. else
  1143. {
  1144. /* Get the appropriate partial URL from the supplier RUV */
  1145. Slapi_Connection *conn;
  1146. consumer_connection_extension *connext;
  1147. slapi_pblock_get(pb, SLAPI_CONNECTION, &conn);
  1148. connext = (consumer_connection_extension *)repl_con_get_ext(
  1149. REPL_CON_EXT_CONN, conn);
  1150. if (NULL == connext || NULL == connext->supplier_ruv)
  1151. {
  1152. char sessionid[REPL_SESSION_ID_SIZE];
  1153. get_repl_session_id (pb, sessionid, NULL);
  1154. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "%s replica_get_purl_for_op: "
  1155. "cannot obtain consumer connection extension or supplier_ruv.\n",
  1156. sessionid);
  1157. }
  1158. else
  1159. {
  1160. purl = ruv_get_purl_for_replica(connext->supplier_ruv,
  1161. csn_get_replicaid(opcsn));
  1162. }
  1163. }
  1164. return purl;
  1165. }
  1166. #ifdef NOTUSED
  1167. /* ONREPL at the moment, I decided not to trim copiedFrom and copyingFrom
  1168. attributes when sending operation to replicas. This is because, each
  1169. operation results in a state information stored in the database and
  1170. if we don't replay all operations we will endup with state inconsistency.
  1171. Keeping the function just in case
  1172. */
  1173. static void strip_legacy_info (slapi_operation_parameters *op_params)
  1174. {
  1175. switch (op_params->operation_type)
  1176. {
  1177. case SLAPI_OPERATION_ADD:
  1178. slapi_entry_delete_values_sv(op_params->p.p_add.target_entry,
  1179. type_copiedFrom, NULL);
  1180. slapi_entry_delete_values_sv(op_params->p.p_add.target_entry,
  1181. type_copyingFrom, NULL);
  1182. break;
  1183. case SLAPI_OPERATION_MODIFY:
  1184. {
  1185. Slapi_Mods smods;
  1186. LDAPMod *mod;
  1187. slapi_mods_init_byref(&smods, op_params->p.p_modify.modify_mods);
  1188. mod = slapi_mods_get_first_mod(&smods);
  1189. while (mod)
  1190. {
  1191. /* modify just to update copiedFrom or copyingFrom attribute
  1192. does not contain modifiersname or modifytime - so we don't
  1193. have to strip them */
  1194. if (strcasecmp (mod->mod_type, type_copiedFrom) == 0 ||
  1195. strcasecmp (mod->mod_type, type_copyingFrom) == 0)
  1196. slapi_mods_remove(&smods);
  1197. mod = slapi_mods_get_next_mod(&smods);
  1198. }
  1199. op_params->p.p_modify.modify_mods = slapi_mods_get_ldapmods_passout (&smods);
  1200. slapi_mods_done (&smods);
  1201. break;
  1202. }
  1203. default: break;
  1204. }
  1205. }
  1206. #endif
  1207. /* this function is called when state of a backend changes */
  1208. void
  1209. multimaster_be_state_change (void *handle, char *be_name, int old_be_state, int new_be_state)
  1210. {
  1211. Object *r_obj;
  1212. Replica *r;
  1213. /* check if we have replica associated with the backend */
  1214. r_obj = replica_get_for_backend (be_name);
  1215. if (r_obj == NULL)
  1216. return;
  1217. r = (Replica*)object_get_data (r_obj);
  1218. PR_ASSERT (r);
  1219. if (new_be_state == SLAPI_BE_STATE_ON)
  1220. {
  1221. /* backend came back online - restart replication */
  1222. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "multimaster_be_state_change: "
  1223. "replica %s is coming online; enabling replication\n",
  1224. slapi_sdn_get_ndn (replica_get_root (r)));
  1225. replica_enable_replication (r);
  1226. }
  1227. else if (new_be_state == SLAPI_BE_STATE_OFFLINE)
  1228. {
  1229. /* backend is about to be taken down - disable replication */
  1230. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "multimaster_be_state_change: "
  1231. "replica %s is going offline; disabling replication\n",
  1232. slapi_sdn_get_ndn (replica_get_root (r)));
  1233. replica_disable_replication (r, r_obj);
  1234. }
  1235. else if (new_be_state == SLAPI_BE_STATE_DELETE)
  1236. {
  1237. /* backend is about to be removed - disable replication */
  1238. if (old_be_state == SLAPI_BE_STATE_ON)
  1239. {
  1240. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "multimaster_be_state_change: "
  1241. "replica %s is about to be deleted; disabling replication\n",
  1242. slapi_sdn_get_ndn (replica_get_root (r)));
  1243. replica_disable_replication (r, r_obj);
  1244. }
  1245. }
  1246. object_release (r_obj);
  1247. }
  1248. #ifdef NOTUSED
  1249. /* Keeping the function just in case */
  1250. static void
  1251. close_changelog_for_replica (Object *r_obj)
  1252. {
  1253. if (cl5GetState () == CL5_STATE_OPEN)
  1254. cl5CloseDB (r_obj);
  1255. }
  1256. #endif