repl5_init.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2026 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. #include <config.h>
  11. #endif
  12. /*
  13. repl5_init.c - plugin initialization functions
  14. */
  15. /*
  16. * Add an entry like the following to dse.ldif to enable this plugin:
  17. dn: cn=Multi-Supplier Replication Plugin,cn=plugins,cn=config
  18. objectclass: top
  19. objectclass: nsSlapdPlugin
  20. objectclass: extensibleObject
  21. cn: Multi-Supplier Replication Plugin
  22. nsslapd-pluginpath: /export2/servers/Hydra-supplier/lib/replication-plugin.so
  23. nsslapd-plugininitfunc: replication_multisupplier_plugin_init
  24. nsslapd-plugintype: object
  25. nsslapd-pluginenabled: on
  26. nsslapd-plugin-depends-on-type: database
  27. nsslapd-plugin-depends-on-named: Class of Service
  28. nsslapd-pluginid: replication-multisupplier
  29. nsslapd-pluginversion: 5.0b1
  30. nsslapd-pluginvendor: Netscape Communications
  31. nsslapd-plugindescription: Multi-Supplier Replication Plugin
  32. */
  33. #include "slapi-plugin.h"
  34. #include "repl5.h"
  35. #include "cl5.h" /* changelog interface */
  36. #include "plstr.h"
  37. #define NSDS_REPL_NAME_PREFIX "Netscape Replication"
  38. static char *start_oid_list[] = {
  39. REPL_START_NSDS50_REPLICATION_REQUEST_OID,
  40. REPL_START_NSDS90_REPLICATION_REQUEST_OID,
  41. NULL};
  42. static char *start_name_list[] = {
  43. NSDS_REPL_NAME_PREFIX " Start Session",
  44. NULL};
  45. static char *end_oid_list[] = {
  46. REPL_END_NSDS50_REPLICATION_REQUEST_OID,
  47. NULL};
  48. static char *end_name_list[] = {
  49. NSDS_REPL_NAME_PREFIX " End Session",
  50. NULL};
  51. static char *total_oid_list[] = {
  52. REPL_NSDS50_REPLICATION_ENTRY_REQUEST_OID,
  53. REPL_NSDS71_REPLICATION_ENTRY_REQUEST_OID,
  54. NULL};
  55. static char *total_name_list[] = {
  56. NSDS_REPL_NAME_PREFIX " Total Update Entry",
  57. NULL};
  58. static char *response_oid_list[] = {
  59. REPL_NSDS50_REPLICATION_RESPONSE_OID,
  60. NULL};
  61. static char *response_name_list[] = {
  62. NSDS_REPL_NAME_PREFIX " Response",
  63. NULL};
  64. static char *cleanruv_oid_list[] = {
  65. REPL_CLEANRUV_OID,
  66. NULL};
  67. static char *cleanruv_name_list[] = {
  68. NSDS_REPL_NAME_PREFIX " CleanAllRUV",
  69. NULL};
  70. static char *cleanruv_abort_oid_list[] = {
  71. REPL_ABORT_CLEANRUV_OID,
  72. NULL};
  73. static char *cleanruv_abort_name_list[] = {
  74. NSDS_REPL_NAME_PREFIX " CleanAllRUV Abort",
  75. NULL};
  76. static char *cleanruv_maxcsn_oid_list[] = {
  77. REPL_CLEANRUV_GET_MAXCSN_OID,
  78. NULL};
  79. static char *cleanruv_maxcsn_name_list[] = {
  80. NSDS_REPL_NAME_PREFIX " CleanAllRUV Retrieve MaxCSN",
  81. NULL};
  82. static char *cleanruv_status_oid_list[] = {
  83. REPL_CLEANRUV_CHECK_STATUS_OID,
  84. NULL};
  85. static char *cleanruv_status_name_list[] = {
  86. NSDS_REPL_NAME_PREFIX " CleanAllRUV Check Status",
  87. NULL};
  88. /* List of plugin identities for every plugin registered. Plugin identity
  89. is passed by the server in the plugin init function and must be supplied
  90. by the plugin to all internal operations it initiates
  91. */
  92. /* ----------------------------- Multi-Supplier Replication Plugin */
  93. static Slapi_PluginDesc multisupplierdesc = {"replication-multisupplier", VENDOR, DS_PACKAGE_VERSION, "Multi-supplier Replication Plugin"};
  94. static Slapi_PluginDesc multisupplierpreopdesc = {"replication-multisupplier-preop", VENDOR, DS_PACKAGE_VERSION, "Multi-supplier replication pre-operation plugin"};
  95. static Slapi_PluginDesc multisupplierpostopdesc = {"replication-multisupplier-postop", VENDOR, DS_PACKAGE_VERSION, "Multi-supplier replication post-operation plugin"};
  96. static Slapi_PluginDesc multisupplierinternalpreopdesc = {"replication-multisupplier-internalpreop", VENDOR, DS_PACKAGE_VERSION, "Multi-supplier replication internal pre-operation plugin"};
  97. static Slapi_PluginDesc multisupplierinternalpostopdesc = {"replication-multisupplier-internalpostop", VENDOR, DS_PACKAGE_VERSION, "Multisupplier replication internal post-operation plugin"};
  98. static Slapi_PluginDesc multisupplierbepreopdesc = {"replication-multisupplier-bepreop", VENDOR, DS_PACKAGE_VERSION, "Multisupplier replication bepre-operation plugin"};
  99. static Slapi_PluginDesc multisupplierbemmrdesc = {"replication-multisupplier-bepreop", VENDOR, DS_PACKAGE_VERSION, "Multisupplier replication be plugin"};
  100. static Slapi_PluginDesc multisupplierbepostopdesc = {"replication-multisupplier-bepostop", VENDOR, DS_PACKAGE_VERSION, "Multisupplier replication bepost-operation plugin"};
  101. static Slapi_PluginDesc multisupplierbetxnpostopdesc = {"replication-multisupplier-betxnpostop", VENDOR, DS_PACKAGE_VERSION, "Multisupplier replication be transaction post-operation plugin"};
  102. static Slapi_PluginDesc multisupplierextopdesc = {"replication-multisupplier-extop", VENDOR, DS_PACKAGE_VERSION, "Multisupplier replication extended-operation plugin"};
  103. static int multisupplier_stopped_flag; /* A flag which is set when all the plugin threads are to stop */
  104. static int multisupplier_started_flag = 0;
  105. /* Thread private data and interface */
  106. static PRUintn thread_private_agmtname; /* thread private index for logging*/
  107. static PRUintn thread_private_cache;
  108. static PRUintn thread_primary_csn;
  109. static int multisupplier_pre_stop(Slapi_PBlock *pb __attribute__((unused)));
  110. char *
  111. get_thread_private_agmtname()
  112. {
  113. char *agmtname = NULL;
  114. if (thread_private_agmtname)
  115. agmtname = PR_GetThreadPrivate(thread_private_agmtname);
  116. return (agmtname ? agmtname : "");
  117. }
  118. void
  119. set_thread_private_agmtname(const char *agmtname)
  120. {
  121. if (thread_private_agmtname)
  122. PR_SetThreadPrivate(thread_private_agmtname, (void *)agmtname);
  123. }
  124. CSNPL_CTX *
  125. get_thread_primary_csn(void)
  126. {
  127. CSNPL_CTX *prim_csn = NULL;
  128. if (thread_primary_csn)
  129. prim_csn = (CSNPL_CTX *)PR_GetThreadPrivate(thread_primary_csn);
  130. return prim_csn;
  131. }
  132. void
  133. set_thread_primary_csn(const CSN *prim_csn, Replica *repl)
  134. {
  135. if (thread_primary_csn) {
  136. if (prim_csn) {
  137. CSNPL_CTX *csnpl_ctx = (CSNPL_CTX *)slapi_ch_calloc(1, sizeof(CSNPL_CTX));
  138. csnpl_ctx->prim_csn = csn_dup(prim_csn);
  139. /* repl_alloc, repl_cnt and sec_repl are 0 by calloc */
  140. csnpl_ctx->prim_repl = repl;
  141. PR_SetThreadPrivate(thread_primary_csn, (void *)csnpl_ctx);
  142. } else {
  143. PR_SetThreadPrivate(thread_primary_csn, NULL);
  144. }
  145. }
  146. }
  147. void
  148. add_replica_to_primcsn(CSNPL_CTX *csnpl_ctx, Replica *repl)
  149. {
  150. size_t found = 0;
  151. size_t it = 0;
  152. if (repl == csnpl_ctx->prim_repl)
  153. return;
  154. while (it < csnpl_ctx->repl_cnt) {
  155. if (csnpl_ctx->sec_repl[it] == repl) {
  156. found = 1;
  157. break;
  158. }
  159. it++;
  160. }
  161. if (found)
  162. return;
  163. if (csnpl_ctx->repl_cnt < csnpl_ctx->repl_alloc) {
  164. csnpl_ctx->sec_repl[csnpl_ctx->repl_cnt++] = repl;
  165. return;
  166. }
  167. csnpl_ctx->repl_alloc += CSNPL_CTX_REPLCNT;
  168. if (csnpl_ctx->repl_cnt == 0) {
  169. csnpl_ctx->sec_repl = (Replica **)slapi_ch_calloc(csnpl_ctx->repl_alloc, sizeof(Replica *));
  170. } else {
  171. csnpl_ctx->sec_repl = (Replica **)slapi_ch_realloc((char *)csnpl_ctx->sec_repl, csnpl_ctx->repl_alloc * sizeof(Replica *));
  172. }
  173. csnpl_ctx->sec_repl[csnpl_ctx->repl_cnt++] = repl;
  174. return;
  175. }
  176. void *
  177. get_thread_private_cache()
  178. {
  179. void *buf = NULL;
  180. if (thread_private_cache)
  181. buf = PR_GetThreadPrivate(thread_private_cache);
  182. return buf;
  183. }
  184. void
  185. set_thread_private_cache(void *buf)
  186. {
  187. if (thread_private_cache)
  188. PR_SetThreadPrivate(thread_private_cache, buf);
  189. }
  190. char *
  191. get_repl_session_id(Slapi_PBlock *pb, char *idstr, CSN **csn)
  192. {
  193. int opid = -1;
  194. PRUint64 connid = 0;
  195. CSN *opcsn;
  196. char opcsnstr[CSN_STRSIZE];
  197. *idstr = '\0';
  198. opcsn = NULL;
  199. opcsnstr[0] = '\0';
  200. if (pb) {
  201. Slapi_Operation *op;
  202. slapi_pblock_get(pb, SLAPI_OPERATION_ID, &opid);
  203. /* Avoid "Connection is NULL and hence cannot access SLAPI_CONN_ID" */
  204. if (opid) {
  205. slapi_pblock_get(pb, SLAPI_CONN_ID, &connid);
  206. snprintf(idstr, REPL_SESSION_ID_SIZE, "conn=%" PRIu64 " op=%d",
  207. connid, opid);
  208. }
  209. slapi_pblock_get(pb, SLAPI_OPERATION, &op);
  210. opcsn = operation_get_csn(op);
  211. if (opcsn) {
  212. csn_as_string(opcsn, PR_FALSE, opcsnstr);
  213. PL_strcatn(idstr, REPL_SESSION_ID_SIZE, " csn=");
  214. PL_strcatn(idstr, REPL_SESSION_ID_SIZE, opcsnstr);
  215. }
  216. }
  217. if (csn) {
  218. *csn = opcsn;
  219. }
  220. return idstr;
  221. }
  222. /* preop acquires csn generator handle */
  223. int repl5_is_betxn = 0;
  224. int
  225. multisupplier_preop_init(Slapi_PBlock *pb)
  226. {
  227. int rc = 0; /* OK */
  228. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0 ||
  229. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multisupplierpreopdesc) != 0 ||
  230. slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_BIND_FN, (void *)multisupplier_preop_bind) != 0 ||
  231. slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ADD_FN, (void *)multisupplier_preop_add) != 0 ||
  232. slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_DELETE_FN, (void *)multisupplier_preop_delete) != 0 ||
  233. slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_MODIFY_FN, (void *)multisupplier_preop_modify) != 0 ||
  234. slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_MODRDN_FN, (void *)multisupplier_preop_modrdn) != 0 ||
  235. slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_SEARCH_FN, (void *)multisupplier_preop_search) != 0 ||
  236. slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_COMPARE_FN, (void *)multisupplier_preop_compare) != 0 ||
  237. slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ENTRY_FN, (void *)multisupplier_ruv_search) != 0) {
  238. slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "multisupplier_preop_init - Failed\n");
  239. rc = -1;
  240. }
  241. return rc;
  242. }
  243. /* process_postop (core op of post op) frees CSN,
  244. * which should be called after betxn is finieshed. */
  245. int
  246. multisupplier_postop_init(Slapi_PBlock *pb)
  247. {
  248. int rc = 0; /* OK */
  249. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0 ||
  250. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multisupplierpostopdesc) != 0 ||
  251. slapi_pblock_set(pb, SLAPI_PLUGIN_POST_BIND_FN, (void *)multisupplier_postop_bind) != 0 ||
  252. slapi_pblock_set(pb, SLAPI_PLUGIN_POST_ADD_FN, (void *)multisupplier_postop_add) != 0 ||
  253. slapi_pblock_set(pb, SLAPI_PLUGIN_POST_DELETE_FN, (void *)multisupplier_postop_delete) != 0 ||
  254. slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODIFY_FN, (void *)multisupplier_postop_modify) != 0 ||
  255. slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODRDN_FN, (void *)multisupplier_postop_modrdn) != 0) {
  256. slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "multisupplier_postop_init - Failed\n");
  257. rc = -1;
  258. }
  259. return rc;
  260. }
  261. int
  262. multisupplier_internalpreop_init(Slapi_PBlock *pb)
  263. {
  264. int rc = 0; /* OK */
  265. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0 ||
  266. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multisupplierinternalpreopdesc) != 0 ||
  267. slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_PRE_ADD_FN, (void *)multisupplier_preop_add) != 0 ||
  268. slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_PRE_DELETE_FN, (void *)multisupplier_preop_delete) != 0 ||
  269. slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_PRE_MODIFY_FN, (void *)multisupplier_preop_modify) != 0 ||
  270. slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_PRE_MODRDN_FN, (void *)multisupplier_preop_modrdn) != 0) {
  271. slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "multisupplier_internalpreop_init - Failed\n");
  272. rc = -1;
  273. }
  274. return rc;
  275. }
  276. int
  277. multisupplier_internalpostop_init(Slapi_PBlock *pb)
  278. {
  279. int rc = 0; /* OK */
  280. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0 ||
  281. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multisupplierinternalpostopdesc) != 0 ||
  282. slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_POST_ADD_FN, (void *)multisupplier_postop_add) != 0 ||
  283. slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_POST_DELETE_FN, (void *)multisupplier_postop_delete) != 0 ||
  284. slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_POST_MODIFY_FN, (void *)multisupplier_postop_modify) != 0 ||
  285. slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_POST_MODRDN_FN, (void *)multisupplier_postop_modrdn) != 0) {
  286. slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "multisupplier_internalpostop_init - Failed\n");
  287. rc = -1;
  288. }
  289. return rc;
  290. }
  291. /*
  292. * bepreop: setting SLAPI_TXN_RUV_MODS_FN, cleanup old stateinfo.
  293. * If betxn is off, preop urp is called here, too.
  294. */
  295. int
  296. multisupplier_bepreop_init(Slapi_PBlock *pb)
  297. {
  298. int rc = 0; /* OK */
  299. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0 ||
  300. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multisupplierbepreopdesc) != 0 ||
  301. /* slapi_pblock_set(pb, SLAPI_PLUGIN_BE_PRE_CLOSE_FN, (void *)cl5Cleanup) != 0) { */
  302. slapi_pblock_set(pb, SLAPI_PLUGIN_BE_PRE_CLOSE_FN, (void *)cl5Close) != 0) {
  303. slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "multisupplier_bepreop_init - Failed\n");
  304. rc = -1;
  305. }
  306. return rc;
  307. }
  308. int
  309. multisupplier_mmr_init( Slapi_PBlock *pb )
  310. {
  311. int rc= 0; /* OK */
  312. if(slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  313. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multisupplierbemmrdesc ) != 0 ||
  314. slapi_pblock_set(pb, SLAPI_PLUGIN_MMR_BETXN_PREOP, (void *) multisupplier_mmr_preop ) != 0 ||
  315. slapi_pblock_set(pb, SLAPI_PLUGIN_MMR_BETXN_POSTOP, (void *) multisupplier_mmr_postop ) != 0) {
  316. slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "multisupplier_mmr_init - Failed\n" );
  317. rc= -1;
  318. }
  319. return rc;
  320. }
  321. /*
  322. * betxnpreop: if betxn is on, call preop urp at betxnpreop.
  323. */
  324. int
  325. multisupplier_betxnpreop_init(Slapi_PBlock *pb __attribute__((unused)))
  326. {
  327. int rc = 0; /* OK */
  328. return rc;
  329. }
  330. /*
  331. * This bepostop_init is registered only if plugintype is NOT betxn.
  332. * if plugintype is betxn, callbacks are set in each multisupplier_betxnpostop
  333. * function.
  334. */
  335. int
  336. multisupplier_bepostop_init(Slapi_PBlock *pb)
  337. {
  338. int rc = 0; /* OK */
  339. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0 ||
  340. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multisupplierbepostopdesc) != 0 ||
  341. slapi_pblock_set(pb, SLAPI_PLUGIN_BE_POST_OPEN_FN, (void *)cl5Open) != 0 ||
  342. slapi_pblock_set(pb, SLAPI_PLUGIN_BE_POST_MODRDN_FN, (void *)multisupplier_bepostop_modrdn) != 0 ||
  343. slapi_pblock_set(pb, SLAPI_PLUGIN_BE_POST_DELETE_FN, (void *)multisupplier_bepostop_delete) != 0) {
  344. slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "multisupplier_bepostop_init - Failed\n");
  345. rc = -1;
  346. }
  347. return rc;
  348. }
  349. /*
  350. * This betxn_bepostop_init is registered only if plugintype is betxn.
  351. * Note: other callbacks (add/delete/modify/modrdn) are set in each
  352. * multisupplier_betxnpostop function.
  353. */
  354. int
  355. multisupplier_betxn_bepostop_init(Slapi_PBlock *pb)
  356. {
  357. int rc = 0; /* OK */
  358. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) ||
  359. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multisupplierbepostopdesc) ||
  360. slapi_pblock_set(pb, SLAPI_PLUGIN_BE_POST_OPEN_FN, (void *)cl5Open) != 0 ||
  361. slapi_pblock_set(pb, SLAPI_PLUGIN_BE_POST_EXPORT_FN, (void *)cl5Export) ||
  362. slapi_pblock_set(pb, SLAPI_PLUGIN_BE_POST_IMPORT_FN, (void *)cl5Import)) {
  363. slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "multisupplier_betxn_bepostop_init - Failed\n");
  364. rc = -1;
  365. }
  366. return rc;
  367. }
  368. int
  369. multisupplier_betxnpostop_init(Slapi_PBlock *pb)
  370. {
  371. int rc = 0; /* OK */
  372. void *add_fn;
  373. void *del_fn;
  374. void *mod_fn;
  375. void *mdn_fn;
  376. if (repl5_is_betxn) {
  377. /* add_fn = multisupplier_be_betxnpostop_add;
  378. del_fn = multisupplier_be_betxnpostop_delete;
  379. mod_fn = multisupplier_be_betxnpostop_modify;
  380. mdn_fn = multisupplier_be_betxnpostop_modrdn;
  381. */
  382. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) ||
  383. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION,
  384. (void *)&multisupplierbetxnpostopdesc)) {
  385. slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name,
  386. "multisupplier_betxnpostop_init - Failed\n");
  387. rc = -1;
  388. }
  389. } else {
  390. add_fn = multisupplier_betxnpostop_add;
  391. del_fn = multisupplier_betxnpostop_delete;
  392. mod_fn = multisupplier_betxnpostop_modify;
  393. mdn_fn = multisupplier_betxnpostop_modrdn;
  394. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) ||
  395. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION,
  396. (void *)&multisupplierbetxnpostopdesc) ||
  397. slapi_pblock_set(pb, SLAPI_PLUGIN_BE_TXN_POST_ADD_FN, add_fn) ||
  398. slapi_pblock_set(pb, SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN, del_fn) ||
  399. slapi_pblock_set(pb, SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN, mdn_fn) ||
  400. slapi_pblock_set(pb, SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN, mod_fn)) {
  401. slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name,
  402. "multisupplier_betxnpostop_init - Failed\n");
  403. rc = -1;
  404. }
  405. }
  406. return rc;
  407. }
  408. int
  409. multisupplier_start_extop_init(Slapi_PBlock *pb)
  410. {
  411. int rc = 0; /* OK */
  412. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0 ||
  413. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multisupplierextopdesc) != 0 ||
  414. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)start_oid_list) != 0 ||
  415. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)start_name_list) != 0 ||
  416. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)multisupplier_extop_StartNSDS50ReplicationRequest)) {
  417. slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "multisupplier_start_extop_init - (StartNSDS50ReplicationRequest) failed\n");
  418. rc = -1;
  419. }
  420. return rc;
  421. }
  422. int
  423. multisupplier_end_extop_init(Slapi_PBlock *pb)
  424. {
  425. int rc = 0; /* OK */
  426. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0 ||
  427. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multisupplierextopdesc) != 0 ||
  428. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)end_oid_list) != 0 ||
  429. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)end_name_list) != 0 ||
  430. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)multisupplier_extop_EndNSDS50ReplicationRequest)) {
  431. slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "multisupplier_end_extop_init - (EndNSDS50ReplicationRequest) failed\n");
  432. rc = -1;
  433. }
  434. return rc;
  435. }
  436. int
  437. multisupplier_cleanruv_maxcsn_extop_init(Slapi_PBlock *pb)
  438. {
  439. int rc = 0; /* OK */
  440. void *identity = NULL;
  441. /* get plugin identity and store it to pass to internal operations */
  442. slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &identity);
  443. PR_ASSERT(identity);
  444. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0 ||
  445. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multisupplierextopdesc) != 0 ||
  446. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)cleanruv_maxcsn_oid_list) != 0 ||
  447. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)cleanruv_maxcsn_name_list) != 0 ||
  448. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)multisupplier_extop_cleanruv_get_maxcsn)) {
  449. slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "multisupplier_cleanruv_maxcsn_extop_init - Failed\n");
  450. rc = -1;
  451. }
  452. return rc;
  453. }
  454. int
  455. multisupplier_cleanruv_status_extop_init(Slapi_PBlock *pb)
  456. {
  457. int rc = 0; /* OK */
  458. void *identity = NULL;
  459. /* get plugin identity and store it to pass to internal operations */
  460. slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &identity);
  461. PR_ASSERT(identity);
  462. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0 ||
  463. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multisupplierextopdesc) != 0 ||
  464. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)cleanruv_status_oid_list) != 0 ||
  465. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)cleanruv_status_name_list) != 0 ||
  466. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)multisupplier_extop_cleanruv_check_status)) {
  467. slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "multisupplier_cleanruv_status_extop_init - Failed\n");
  468. rc = -1;
  469. }
  470. return rc;
  471. }
  472. int
  473. multisupplier_total_extop_init(Slapi_PBlock *pb)
  474. {
  475. int rc = 0; /* OK */
  476. void *identity = NULL;
  477. /* get plugin identity and store it to pass to internal operations */
  478. slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &identity);
  479. PR_ASSERT(identity);
  480. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0 ||
  481. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multisupplierextopdesc) != 0 ||
  482. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)total_oid_list) != 0 ||
  483. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)total_name_list) != 0 ||
  484. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)multisupplier_extop_NSDS50ReplicationEntry)) {
  485. slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "multisupplier_total_extop_init - (NSDS50ReplicationEntry failed\n");
  486. rc = -1;
  487. }
  488. return rc;
  489. }
  490. int
  491. multisupplier_response_extop_init(Slapi_PBlock *pb)
  492. {
  493. int rc = 0; /* OK */
  494. void *identity = NULL;
  495. /* get plugin identity and store it to pass to internal operations */
  496. slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &identity);
  497. PR_ASSERT(identity);
  498. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0 ||
  499. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multisupplierextopdesc) != 0 ||
  500. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)response_oid_list) != 0 ||
  501. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)response_name_list) != 0 ||
  502. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)extop_noop)) {
  503. slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "multisupplier_response_extop_init - (NSDS50ReplicationResponse failed\n");
  504. rc = -1;
  505. }
  506. return rc;
  507. }
  508. int
  509. multisupplier_cleanruv_extop_init(Slapi_PBlock *pb)
  510. {
  511. int rc = 0; /* OK */
  512. void *identity = NULL;
  513. /* get plugin identity and store it to pass to internal operations */
  514. slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &identity);
  515. PR_ASSERT(identity);
  516. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0 ||
  517. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multisupplierextopdesc) != 0 ||
  518. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)cleanruv_oid_list) != 0 ||
  519. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)cleanruv_name_list) != 0 ||
  520. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)multisupplier_extop_cleanruv)) {
  521. slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "multisupplier_cleanruv_extop_init - Failed\n");
  522. rc = -1;
  523. }
  524. return rc;
  525. }
  526. int
  527. multisupplier_cleanruv_abort_extop_init(Slapi_PBlock *pb)
  528. {
  529. int rc = 0; /* OK */
  530. void *identity = NULL;
  531. /* get plugin identity and store it to pass to internal operations */
  532. slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &identity);
  533. PR_ASSERT(identity);
  534. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0 ||
  535. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multisupplierextopdesc) != 0 ||
  536. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)cleanruv_abort_oid_list) != 0 ||
  537. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)cleanruv_abort_name_list) != 0 ||
  538. slapi_pblock_set(pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)multisupplier_extop_abort_cleanruv)) {
  539. slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "multisupplier_cleanruv_abort_extop_init - Failed\n");
  540. rc = -1;
  541. }
  542. return rc;
  543. }
  544. static PRBool
  545. check_for_ldif_dump(Slapi_PBlock *pb)
  546. {
  547. int i;
  548. int argc;
  549. char **argv;
  550. PRBool return_value = PR_FALSE;
  551. slapi_pblock_get(pb, SLAPI_ARGC, &argc);
  552. slapi_pblock_get(pb, SLAPI_ARGV, &argv);
  553. for (i = 1; i < argc && !return_value; i++) {
  554. if (strcmp(argv[i], "db2ldif") == 0) {
  555. return_value = PR_TRUE;
  556. }
  557. }
  558. return return_value;
  559. }
  560. /*
  561. * If the entries do not exist, it create the entries of the schema replication policies
  562. * returns 0 if success
  563. */
  564. static int
  565. create_repl_schema_policy(void)
  566. {
  567. /* DN part of this entry_string: no need to be optimized. */
  568. char entry_string[1024];
  569. Slapi_PBlock *pb;
  570. Slapi_Entry *e;
  571. int return_value;
  572. char *repl_schema_top, *repl_schema_supplier, *repl_schema_consumer;
  573. char *default_supplier_policy = NULL;
  574. char *default_consumer_policy = NULL;
  575. int rc = 0;
  576. slapi_schema_get_repl_entries(&repl_schema_top, &repl_schema_supplier, &repl_schema_consumer, &default_supplier_policy, &default_consumer_policy);
  577. /* Create cn=replSchema,cn=config */
  578. PR_snprintf(entry_string, sizeof(entry_string), "dn: %s\nobjectclass: top\nobjectclass: nsSchemaPolicy\ncn: replSchema\n", repl_schema_top);
  579. e = slapi_str2entry(entry_string, 0);
  580. pb = slapi_pblock_new();
  581. slapi_add_entry_internal_set_pb(pb, e, NULL, /* controls */
  582. repl_get_plugin_identity(PLUGIN_MULTISUPPLIER_REPLICATION), 0 /* flags */);
  583. slapi_add_internal_pb(pb);
  584. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &return_value);
  585. if (return_value != LDAP_SUCCESS && return_value != LDAP_ALREADY_EXISTS) {
  586. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "create_repl_schema_policy - "
  587. "Unable to create configuration entry %s: %s\n",
  588. repl_schema_top,
  589. ldap_err2string(return_value));
  590. rc = -1;
  591. goto done;
  592. }
  593. slapi_pblock_destroy(pb);
  594. /* Create cn=supplierUpdatePolicy,cn=replSchema,cn=config */
  595. PR_snprintf(entry_string, sizeof(entry_string), "dn: %s\nobjectclass: top\nobjectclass: nsSchemaPolicy\ncn: supplierUpdatePolicy\n%s",
  596. repl_schema_supplier,
  597. default_supplier_policy ? default_supplier_policy : "");
  598. e = slapi_str2entry(entry_string, 0);
  599. pb = slapi_pblock_new();
  600. slapi_add_entry_internal_set_pb(pb, e, NULL, /* controls */
  601. repl_get_plugin_identity(PLUGIN_MULTISUPPLIER_REPLICATION), 0 /* flags */);
  602. slapi_add_internal_pb(pb);
  603. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &return_value);
  604. if (return_value != LDAP_SUCCESS && return_value != LDAP_ALREADY_EXISTS) {
  605. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "create_repl_schema_policy - Unable to "
  606. "create configuration entry %s: %s\n",
  607. repl_schema_supplier,
  608. ldap_err2string(return_value));
  609. rc = -1;
  610. goto done;
  611. }
  612. slapi_pblock_destroy(pb);
  613. /* Create cn=consumerUpdatePolicy,cn=replSchema,cn=config */
  614. PR_snprintf(entry_string, sizeof(entry_string), "dn: %s\nobjectclass: top\nobjectclass: nsSchemaPolicy\ncn: consumerUpdatePolicy\n%s",
  615. repl_schema_consumer,
  616. default_consumer_policy ? default_consumer_policy : "");
  617. e = slapi_str2entry(entry_string, 0);
  618. pb = slapi_pblock_new();
  619. slapi_add_entry_internal_set_pb(pb, e, NULL, /* controls */
  620. repl_get_plugin_identity(PLUGIN_MULTISUPPLIER_REPLICATION), 0 /* flags */);
  621. slapi_add_internal_pb(pb);
  622. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &return_value);
  623. if (return_value != LDAP_SUCCESS && return_value != LDAP_ALREADY_EXISTS) {
  624. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "create_repl_schema_policy - "
  625. "Unable to create configuration entry %s: %s\n",
  626. repl_schema_consumer,
  627. ldap_err2string(return_value));
  628. rc = -1;
  629. goto done;
  630. }
  631. slapi_pblock_destroy(pb);
  632. pb = NULL;
  633. /* Load the policies of the schema replication */
  634. if (slapi_schema_load_repl_policies()) {
  635. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "create_repl_schema_policy - "
  636. "Unable to load the schema replication policies\n");
  637. rc = -1;
  638. goto done;
  639. }
  640. done:
  641. slapi_pblock_destroy(pb);
  642. pb = NULL;
  643. return rc;
  644. }
  645. static PRBool is_ldif_dump = PR_FALSE;
  646. PRBool
  647. ldif_dump_is_running()
  648. {
  649. return is_ldif_dump;
  650. }
  651. int
  652. multisupplier_start(Slapi_PBlock *pb)
  653. {
  654. int rc = 0; /* OK */
  655. if (!multisupplier_started_flag) {
  656. /* Get any registered replication session API */
  657. repl_session_plugin_init();
  658. /* Initialize thread private data for logging. Ignore if fails */
  659. PR_NewThreadPrivateIndex(&thread_private_agmtname, NULL);
  660. PR_NewThreadPrivateIndex(&thread_private_cache, NULL);
  661. PR_NewThreadPrivateIndex(&thread_primary_csn, csnplFreeCSNPL_CTX);
  662. /* Decode the command line args to see if we're dumping to LDIF */
  663. is_ldif_dump = check_for_ldif_dump(pb);
  664. /* allow online replica configuration */
  665. rc = replica_config_init();
  666. if (rc != 0)
  667. goto out;
  668. slapi_register_supported_control(REPL_NSDS50_UPDATE_INFO_CONTROL_OID,
  669. SLAPI_OPERATION_ADD | SLAPI_OPERATION_DELETE |
  670. SLAPI_OPERATION_MODIFY | SLAPI_OPERATION_MODDN);
  671. /* Stash away our partial URL, used in RUVs */
  672. rc = multisupplier_set_local_purl();
  673. if (rc != 0)
  674. goto out;
  675. /* initialize name hash */
  676. rc = replica_init_name_hash();
  677. if (rc != 0)
  678. goto out;
  679. /* initialize dn hash */
  680. rc = replica_init_dn_hash();
  681. if (rc != 0)
  682. goto out;
  683. /* create replicas */
  684. multisupplier_mtnode_construct_replicas();
  685. /* Upgrade the 5.0 Changelog if it still exists */
  686. rc = changelog5_upgrade();
  687. if (rc != 0)
  688. goto out;
  689. /* perform initial changelog setup */
  690. rc = changelog5_init();
  691. if (rc != 0)
  692. goto out;
  693. rc = create_repl_schema_policy();
  694. if (rc != 0)
  695. goto out;
  696. /* check if the replica's data was reloaded offline and we need
  697. to reinitialize replica's changelog. This should be done
  698. after the changelog is initialized */
  699. replica_enumerate_replicas(replica_check_for_data_reload, NULL);
  700. /* Initialize the replication agreements, unless we're dumping LDIF */
  701. if (!is_ldif_dump) {
  702. rc = agmtlist_config_init();
  703. if (rc != 0)
  704. goto out;
  705. }
  706. /* register to be notified when backend state changes */
  707. slapi_register_backend_state_change((void *)multisupplier_be_state_change,
  708. multisupplier_be_state_change);
  709. multisupplier_started_flag = 1;
  710. multisupplier_stopped_flag = 0;
  711. }
  712. out:
  713. return rc;
  714. }
  715. int
  716. multisupplier_stop(Slapi_PBlock *pb __attribute__((unused)))
  717. {
  718. int rc = 0; /* OK */
  719. if (!multisupplier_stopped_flag) {
  720. /* if we are cleaning a ruv, stop */
  721. stop_ruv_cleaning();
  722. /* unregister backend state change notification */
  723. slapi_unregister_backend_state_change((void *)multisupplier_be_state_change);
  724. changelog5_cleanup(); /* Shut down the changelog */
  725. multisupplier_mtnode_extension_destroy(); /* Destroy mapping tree node exts */
  726. replica_destroy_name_hash(); /* destroy the hash and its remaining content */
  727. replica_config_destroy(); /* Destroy replica config info */
  728. multisupplier_stopped_flag = 1;
  729. }
  730. return rc;
  731. }
  732. static int
  733. multisupplier_pre_stop(Slapi_PBlock *pb __attribute__((unused)))
  734. {
  735. if (!multisupplier_stopped_flag) {
  736. /* Shut down replication agreements which will stop all the
  737. * replication protocol threads */
  738. agmtlist_shutdown();
  739. }
  740. return 0;
  741. }
  742. PRBool
  743. multisupplier_started()
  744. {
  745. return (multisupplier_started_flag != 0);
  746. }
  747. /*
  748. * Initialize the multisupplier replication plugin.
  749. */
  750. int
  751. replication_multisupplier_plugin_init(Slapi_PBlock *pb)
  752. {
  753. static int multisupplier_initialised = 0;
  754. int rc = 0; /* OK */
  755. void *identity = NULL;
  756. Slapi_Entry *plugin_entry = NULL;
  757. slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &identity);
  758. PR_ASSERT(identity);
  759. repl_set_plugin_identity(PLUGIN_MULTISUPPLIER_REPLICATION, identity);
  760. /* need the repl plugin path for the chain on update function */
  761. /* slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &entry);
  762. PR_ASSERT(entry);
  763. path = slapi_entry_attr_get_charptr(entry, "nsslapd-pluginpath");
  764. repl_set_repl_plugin_path(path);
  765. slapi_ch_free_string(&path);
  766. */
  767. multisupplier_mtnode_extension_init();
  768. if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &plugin_entry) == 0) &&
  769. plugin_entry) {
  770. repl5_is_betxn = slapi_entry_attr_get_bool(plugin_entry,
  771. "nsslapd-pluginbetxn");
  772. }
  773. if (!multisupplier_initialised) {
  774. /* Initialize extensions */
  775. repl_con_init_ext();
  776. repl_sup_init_ext();
  777. rc = slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01);
  778. rc = slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multisupplierdesc);
  779. rc = slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN, (void *)multisupplier_start);
  780. rc = slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN, (void *)multisupplier_stop);
  781. rc = slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_CLOSE_FN, (void *)multisupplier_pre_stop);
  782. /* Register the plugin interfaces we implement */
  783. /* preop acquires csn generator handle */
  784. rc = slapi_register_plugin("preoperation", 1 /* Enabled */,
  785. "multisupplier_preop_init",
  786. multisupplier_preop_init,
  787. "Multisupplier replication preoperation plugin",
  788. NULL, identity);
  789. /* Register the main mmr backend plugins */
  790. rc = slapi_register_plugin("mmr", 1 /* Enabled */,
  791. "multisupplier_mmr_init",
  792. multisupplier_mmr_init,
  793. "Multisupplier replication be operation plugin",
  794. NULL, identity);
  795. /* bepreop: setting SLAPI_TXN_RUV_MODS_FN and cleanup old stateinfo
  796. * -- should be done before transaction */
  797. /* if betxn is off, urp is called at bepreop. */
  798. rc = slapi_register_plugin("bepreoperation", 1 /* Enabled */,
  799. "multisupplier_bepreop_init",
  800. multisupplier_bepreop_init,
  801. "Multisupplier replication bepreoperation plugin",
  802. NULL, identity);
  803. /* is_betxn: be post ops (add/del/mod/mdn) are combined into betxn ops.
  804. * no betxn: be post ops are regsitered at bepostoperation. */
  805. rc = slapi_register_plugin("betxnpostoperation", 1 /* Enabled */,
  806. "multisupplier_betxnpostop_init",
  807. multisupplier_betxnpostop_init,
  808. "Multisupplier replication betxnpostoperation plugin",
  809. NULL, identity);
  810. if (repl5_is_betxn) {
  811. /* if betxn is on, urp is called at betxnpreop. */
  812. rc = slapi_register_plugin("betxnpreoperation", 1 /* Enabled */,
  813. "multisupplier_betxnpreop_init",
  814. multisupplier_betxnpreop_init,
  815. "Multisupplier replication betxnpreoperation plugin",
  816. NULL, identity);
  817. /* bepostop configures open and backup only (no betxn) */
  818. rc = slapi_register_plugin("bepostoperation", 1 /* Enabled */,
  819. "multisupplier_betxn_bepostop_init",
  820. multisupplier_betxn_bepostop_init,
  821. "Multisupplier replication bepostoperation plugin",
  822. NULL, identity);
  823. } else {
  824. /* bepostop configures open and backup only as well as add/del/
  825. * mod/mdn bepost ops */
  826. rc = slapi_register_plugin("bepostoperation", 1 /* Enabled */,
  827. "multisupplier_bepostop_init",
  828. multisupplier_bepostop_init,
  829. "Multisupplier replication bepostoperation2 plugin",
  830. NULL, identity);
  831. }
  832. /* process_postop (core op of post op) frees CSN,
  833. * which should wait until betxn is done. */
  834. rc = slapi_register_plugin("postoperation", 1 /* Enabled */,
  835. "multisupplier_postop_init",
  836. multisupplier_postop_init,
  837. "Multisupplier replication postoperation plugin",
  838. NULL, identity);
  839. rc = slapi_register_plugin("internalpreoperation", 1 /* Enabled */,
  840. "multisupplier_internalpreop_init",
  841. multisupplier_internalpreop_init,
  842. "Multisupplier replication internal preoperation plugin",
  843. NULL, identity);
  844. rc = slapi_register_plugin("internalpostoperation", 1 /* Enabled */,
  845. "multisupplier_internalpostop_init",
  846. multisupplier_internalpostop_init,
  847. "Multisupplier replication internal postoperation plugin",
  848. NULL, identity);
  849. rc = slapi_register_plugin("extendedop", 1 /* Enabled */, "multisupplier_start_extop_init", multisupplier_start_extop_init, "Multisupplier replication start extended operation plugin", NULL, identity);
  850. rc = slapi_register_plugin("extendedop", 1 /* Enabled */, "multisupplier_end_extop_init", multisupplier_end_extop_init, "Multisupplier replication end extended operation plugin", NULL, identity);
  851. rc = slapi_register_plugin("extendedop", 1 /* Enabled */, "multisupplier_total_extop_init", multisupplier_total_extop_init, "Multisupplier replication total update extended operation plugin", NULL, identity);
  852. rc = slapi_register_plugin("extendedop", 1 /* Enabled */, "multisupplier_response_extop_init", multisupplier_response_extop_init, "Multisupplier replication extended response plugin", NULL, identity);
  853. rc = slapi_register_plugin("extendedop", 1 /* Enabled */, "multisupplier_cleanruv_extop_init", multisupplier_cleanruv_extop_init, "Multisupplier replication cleanruv extended operation plugin", NULL, identity);
  854. rc = slapi_register_plugin("extendedop", 1 /* Enabled */, "multisupplier_cleanruv_abort_extop_init", multisupplier_cleanruv_abort_extop_init, "Multisupplier replication cleanruv abort extended operation plugin", NULL, identity);
  855. rc = slapi_register_plugin("extendedop", 1 /* Enabled */, "multisupplier_cleanruv_maxcsn_extop_init", multisupplier_cleanruv_maxcsn_extop_init, "Multisupplier replication cleanruv maxcsn extended operation plugin", NULL, identity);
  856. rc = slapi_register_plugin("extendedop", 1 /* Enabled */, "multisupplier_cleanruv_status_extop_init", multisupplier_cleanruv_status_extop_init, "Multisupplier replication cleanruv status extended operation plugin", NULL, identity);
  857. if (0 == rc) {
  858. multisupplier_initialised = 1;
  859. }
  860. }
  861. return rc;
  862. }