repl5_plugins.c 44 KB

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