repl5_init.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. * END COPYRIGHT BLOCK **/
  6. /*
  7. repl5_init.c - plugin initialization functions
  8. */
  9. /*
  10. * Add an entry like the following to dse.ldif to enable this plugin:
  11. dn: cn=Multi-Master Replication Plugin,cn=plugins,cn=config
  12. objectclass: top
  13. objectclass: nsSlapdPlugin
  14. objectclass: extensibleObject
  15. cn: Legacy Replication Plugin
  16. nsslapd-pluginpath: /export2/servers/Hydra-supplier/lib/replication-plugin.so
  17. nsslapd-plugininitfunc: replication_multimaster_plugin_init
  18. nsslapd-plugintype: object
  19. nsslapd-pluginenabled: on
  20. nsslapd-plugin-depends-on-type: database
  21. nsslapd-plugin-depends-on-named: Class of Service
  22. nsslapd-pluginid: replication-multimaster
  23. nsslapd-pluginversion: 5.0b1
  24. nsslapd-pluginvendor: Netscape Communications
  25. nsslapd-plugindescription: Multi-Master Replication Plugin
  26. */
  27. #include "slapi-plugin.h"
  28. #include "repl.h"
  29. #include "repl5.h"
  30. #include "cl5.h" /* changelog interface */
  31. #include "dirver.h"
  32. #include <dirlite_strings.h> /* PLUGIN_MAGIC_VENDOR_STR */
  33. #include "plstr.h"
  34. /* #ifdef _WIN32
  35. int *module_ldap_debug = 0;
  36. void plugin_init_debug_level(int *level_ptr)
  37. {
  38. module_ldap_debug = level_ptr;
  39. }
  40. #endif*/
  41. #define NSDS_REPL_NAME_PREFIX "Netscape Replication"
  42. static char *start_oid_list[] = {
  43. REPL_START_NSDS50_REPLICATION_REQUEST_OID,
  44. NULL
  45. };
  46. static char *start_name_list[] = {
  47. NSDS_REPL_NAME_PREFIX " Start Session",
  48. NULL
  49. };
  50. static char *end_oid_list[] = {
  51. REPL_END_NSDS50_REPLICATION_REQUEST_OID,
  52. NULL
  53. };
  54. static char *end_name_list[] = {
  55. NSDS_REPL_NAME_PREFIX " End Session",
  56. NULL
  57. };
  58. static char *total_oid_list[] = {
  59. REPL_NSDS50_REPLICATION_ENTRY_REQUEST_OID,
  60. REPL_NSDS71_REPLICATION_ENTRY_REQUEST_OID,
  61. NULL
  62. };
  63. static char *total_name_list[] = {
  64. NSDS_REPL_NAME_PREFIX " Total Update Entry",
  65. NULL
  66. };
  67. static char *response_oid_list[] = {
  68. REPL_NSDS50_REPLICATION_RESPONSE_OID,
  69. NULL
  70. };
  71. static char *response_name_list[] = {
  72. NSDS_REPL_NAME_PREFIX " Response",
  73. NULL
  74. };
  75. /* List of plugin identities for every plugin registered. Plugin identity
  76. is passed by the server in the plugin init function and must be supplied
  77. by the plugin to all internal operations it initiates
  78. */
  79. /* ----------------------------- Multi-Master Replication Plugin */
  80. static Slapi_PluginDesc multimasterdesc = {"replication-multimaster", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Multi-master Replication Plugin"};
  81. static Slapi_PluginDesc multimasterpreopdesc = {"replication-multimaster-preop", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Multi-master replication pre-operation plugin"};
  82. static Slapi_PluginDesc multimasterpostopdesc = {"replication-multimaster-postop", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Multi-master replication post-operation plugin"};
  83. static Slapi_PluginDesc multimasterinternalpreopdesc = {"replication-multimaster-internalpreop", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Multi-master replication internal pre-operation plugin"};
  84. static Slapi_PluginDesc multimasterinternalpostopdesc = {"replication-multimaster-internalpostop", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Multimaster replication internal post-operation plugin"};
  85. static Slapi_PluginDesc multimasterbepreopdesc = {"replication-multimaster-bepreop", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Multimaster replication bepre-operation plugin"};
  86. static Slapi_PluginDesc multimasterbepostopdesc = {"replication-multimaster-bepostop", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Multimaster replication bepost-operation plugin"};
  87. static Slapi_PluginDesc multimasterextopdesc = { "replication-multimaster-extop", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT, "Multimaster replication extended-operation plugin" };
  88. static int multimaster_stopped_flag; /* A flag which is set when all the plugin threads are to stop */
  89. static int multimaster_started_flag = 0;
  90. /* Thread private data and interface */
  91. static PRUintn thread_private_agmtname; /* thread private index for logging*/
  92. static PRUintn thread_private_cache;
  93. char*
  94. get_thread_private_agmtname()
  95. {
  96. char *agmtname = NULL;
  97. if (thread_private_agmtname)
  98. agmtname = PR_GetThreadPrivate(thread_private_agmtname);
  99. return (agmtname ? agmtname : "");
  100. }
  101. void
  102. set_thread_private_agmtname(const char *agmtname)
  103. {
  104. if (thread_private_agmtname)
  105. PR_SetThreadPrivate(thread_private_agmtname, (void *)agmtname);
  106. }
  107. void*
  108. get_thread_private_cache ()
  109. {
  110. void *buf = NULL;
  111. if ( thread_private_cache )
  112. buf = PR_GetThreadPrivate ( thread_private_cache );
  113. return buf;
  114. }
  115. void
  116. set_thread_private_cache ( void *buf )
  117. {
  118. if ( thread_private_cache )
  119. PR_SetThreadPrivate ( thread_private_cache, buf );
  120. }
  121. char*
  122. get_repl_session_id (Slapi_PBlock *pb, char *idstr, CSN **csn)
  123. {
  124. int connid=-1, opid=-1;
  125. CSN *opcsn;
  126. char opcsnstr[CSN_STRSIZE];
  127. *idstr = '\0';
  128. opcsn = NULL;
  129. opcsnstr[0] = '\0';
  130. if (pb) {
  131. Slapi_Operation *op;
  132. slapi_pblock_get (pb, SLAPI_OPERATION_ID, &opid);
  133. /* Avoid "Connection is NULL and hence cannot access SLAPI_CONN_ID" */
  134. if (opid) {
  135. slapi_pblock_get (pb, SLAPI_CONN_ID, &connid);
  136. PR_snprintf (idstr, REPL_SESSION_ID_SIZE, "conn=%d op=%d", connid, opid);
  137. }
  138. slapi_pblock_get ( pb, SLAPI_OPERATION, &op );
  139. opcsn = operation_get_csn (op);
  140. if (opcsn) {
  141. csn_as_string (opcsn, PR_FALSE, opcsnstr);
  142. PL_strcatn (idstr, REPL_SESSION_ID_SIZE, " csn=");
  143. PL_strcatn (idstr, REPL_SESSION_ID_SIZE, opcsnstr);
  144. }
  145. }
  146. if (csn) {
  147. *csn = opcsn;
  148. }
  149. return idstr;
  150. }
  151. int
  152. multimaster_preop_init( Slapi_PBlock *pb )
  153. {
  154. int rc= 0; /* OK */
  155. if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  156. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterpreopdesc ) != 0 ||
  157. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_BIND_FN, (void *) multimaster_preop_bind ) != 0 ||
  158. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_ADD_FN, (void *) multimaster_preop_add ) != 0 ||
  159. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_DELETE_FN, (void *) multimaster_preop_delete ) != 0 ||
  160. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_MODIFY_FN, (void *) multimaster_preop_modify ) != 0 ||
  161. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_MODRDN_FN, (void *) multimaster_preop_modrdn ) != 0 ||
  162. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_SEARCH_FN, (void *) multimaster_preop_search ) != 0 ||
  163. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_COMPARE_FN, (void *) multimaster_preop_compare ) != 0)
  164. {
  165. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_preop_init failed\n" );
  166. rc= -1;
  167. }
  168. return rc;
  169. }
  170. int
  171. multimaster_postop_init( Slapi_PBlock *pb )
  172. {
  173. int rc= 0; /* OK */
  174. if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  175. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterpostopdesc ) != 0 ||
  176. slapi_pblock_set( pb, SLAPI_PLUGIN_POST_BIND_FN, (void *) multimaster_postop_bind ) != 0 ||
  177. slapi_pblock_set( pb, SLAPI_PLUGIN_POST_ADD_FN, (void *) multimaster_postop_add ) != 0 ||
  178. slapi_pblock_set( pb, SLAPI_PLUGIN_POST_DELETE_FN, (void *) multimaster_postop_delete ) != 0 ||
  179. slapi_pblock_set( pb, SLAPI_PLUGIN_POST_MODIFY_FN, (void *) multimaster_postop_modify ) != 0 ||
  180. slapi_pblock_set( pb, SLAPI_PLUGIN_POST_MODRDN_FN, (void *) multimaster_postop_modrdn ) != 0 )
  181. {
  182. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_postop_init failed\n" );
  183. rc= -1;
  184. }
  185. return rc;
  186. }
  187. int
  188. multimaster_internalpreop_init( Slapi_PBlock *pb )
  189. {
  190. int rc= 0; /* OK */
  191. if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  192. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterinternalpreopdesc ) != 0 ||
  193. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_PRE_ADD_FN, (void *) multimaster_preop_add ) != 0 ||
  194. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_PRE_DELETE_FN, (void *) multimaster_preop_delete ) != 0 ||
  195. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_PRE_MODIFY_FN, (void *) multimaster_preop_modify ) != 0 ||
  196. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_PRE_MODRDN_FN, (void *) multimaster_preop_modrdn ) != 0 )
  197. {
  198. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_internalpreop_init failed\n" );
  199. rc= -1;
  200. }
  201. return rc;
  202. }
  203. int
  204. multimaster_internalpostop_init( Slapi_PBlock *pb )
  205. {
  206. int rc= 0; /* OK */
  207. if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  208. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterinternalpostopdesc ) != 0 ||
  209. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_POST_ADD_FN, (void *) multimaster_postop_add ) != 0 ||
  210. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_POST_DELETE_FN, (void *) multimaster_postop_delete ) != 0 ||
  211. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_POST_MODIFY_FN, (void *) multimaster_postop_modify ) != 0 ||
  212. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_POST_MODRDN_FN, (void *) multimaster_postop_modrdn ) != 0 )
  213. {
  214. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_internalpostop_init failed\n" );
  215. rc= -1;
  216. }
  217. return rc;
  218. }
  219. int
  220. multimaster_bepreop_init( Slapi_PBlock *pb )
  221. {
  222. int rc= 0; /* OK */
  223. if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  224. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterbepreopdesc ) != 0 ||
  225. slapi_pblock_set( pb, SLAPI_PLUGIN_BE_PRE_ADD_FN, (void *) multimaster_bepreop_add ) != 0 ||
  226. slapi_pblock_set( pb, SLAPI_PLUGIN_BE_PRE_DELETE_FN, (void *) multimaster_bepreop_delete ) != 0 ||
  227. slapi_pblock_set( pb, SLAPI_PLUGIN_BE_PRE_MODIFY_FN, (void *) multimaster_bepreop_modify ) != 0 ||
  228. slapi_pblock_set( pb, SLAPI_PLUGIN_BE_PRE_MODRDN_FN, (void *) multimaster_bepreop_modrdn ) != 0 )
  229. {
  230. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_bepreop_init failed\n" );
  231. rc= -1;
  232. }
  233. return rc;
  234. }
  235. int
  236. multimaster_bepostop_init( Slapi_PBlock *pb )
  237. {
  238. int rc= 0; /* OK */
  239. if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  240. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterbepostopdesc ) != 0 ||
  241. slapi_pblock_set( pb, SLAPI_PLUGIN_BE_POST_MODRDN_FN, (void *) multimaster_bepostop_modrdn ) != 0 ||
  242. slapi_pblock_set( pb, SLAPI_PLUGIN_BE_POST_DELETE_FN, (void *) multimaster_bepostop_delete ) != 0 )
  243. {
  244. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_bepostop_init failed\n" );
  245. rc= -1;
  246. }
  247. return rc;
  248. }
  249. int
  250. multimaster_start_extop_init( Slapi_PBlock *pb )
  251. {
  252. int rc= 0; /* OK */
  253. if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  254. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterextopdesc ) != 0 ||
  255. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)start_oid_list ) != 0 ||
  256. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)start_name_list ) != 0 ||
  257. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)multimaster_extop_StartNSDS50ReplicationRequest ))
  258. {
  259. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_start_extop_init (StartNSDS50ReplicationRequest) failed\n" );
  260. rc= -1;
  261. }
  262. return rc;
  263. }
  264. int
  265. multimaster_end_extop_init( Slapi_PBlock *pb )
  266. {
  267. int rc= 0; /* OK */
  268. if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  269. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterextopdesc ) != 0 ||
  270. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)end_oid_list ) != 0 ||
  271. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)end_name_list ) != 0 ||
  272. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)multimaster_extop_EndNSDS50ReplicationRequest ))
  273. {
  274. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_end_extop_init (EndNSDS50ReplicationRequest) failed\n" );
  275. rc= -1;
  276. }
  277. return rc;
  278. }
  279. int
  280. multimaster_total_extop_init( Slapi_PBlock *pb )
  281. {
  282. int rc= 0; /* OK */
  283. void *identity = NULL;
  284. /* get plugin identity and store it to pass to internal operations */
  285. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
  286. PR_ASSERT (identity);
  287. if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  288. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterextopdesc ) != 0 ||
  289. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)total_oid_list ) != 0 ||
  290. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)total_name_list ) != 0 ||
  291. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)multimaster_extop_NSDS50ReplicationEntry ))
  292. {
  293. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_start_extop_init (NSDS50ReplicationEntry failed\n" );
  294. rc= -1;
  295. }
  296. return rc;
  297. }
  298. int
  299. multimaster_response_extop_init( Slapi_PBlock *pb )
  300. {
  301. int rc= 0; /* OK */
  302. void *identity = NULL;
  303. /* get plugin identity and store it to pass to internal operations */
  304. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
  305. PR_ASSERT (identity);
  306. if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  307. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterextopdesc ) != 0 ||
  308. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, (void *)response_oid_list ) != 0 ||
  309. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, (void *)response_name_list ) != 0 ||
  310. slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_FN, (void *)extop_noop ))
  311. {
  312. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_start_extop_init (NSDS50ReplicationResponse failed\n" );
  313. rc= -1;
  314. }
  315. return rc;
  316. }
  317. static PRBool
  318. check_for_ldif_dump(Slapi_PBlock *pb)
  319. {
  320. int i;
  321. int argc;
  322. char **argv;
  323. PRBool return_value = PR_FALSE;
  324. slapi_pblock_get( pb, SLAPI_ARGC, &argc);
  325. slapi_pblock_get( pb, SLAPI_ARGV, &argv);
  326. for (i = 1; i < argc && !return_value; i++)
  327. {
  328. if (strcmp(argv[i], "db2ldif") == 0)
  329. {
  330. return_value = PR_TRUE;
  331. }
  332. }
  333. return return_value;
  334. }
  335. static PRBool is_ldif_dump = PR_FALSE;
  336. int
  337. multimaster_start( Slapi_PBlock *pb )
  338. {
  339. int rc= 0; /* OK */
  340. if (!multimaster_started_flag)
  341. {
  342. /* Initialize thread private data for logging. Ignore if fails */
  343. PR_NewThreadPrivateIndex (&thread_private_agmtname, NULL);
  344. PR_NewThreadPrivateIndex (&thread_private_cache, NULL);
  345. /* Decode the command line args to see if we're dumping to LDIF */
  346. is_ldif_dump = check_for_ldif_dump(pb);
  347. /* allow online replica configuration */
  348. rc = replica_config_init ();
  349. if (rc != 0)
  350. goto out;
  351. slapi_register_supported_control(REPL_NSDS50_UPDATE_INFO_CONTROL_OID,
  352. SLAPI_OPERATION_ADD | SLAPI_OPERATION_DELETE |
  353. SLAPI_OPERATION_MODIFY | SLAPI_OPERATION_MODDN);
  354. /* Stash away our partial URL, used in RUVs */
  355. rc = multimaster_set_local_purl();
  356. if (rc != 0)
  357. goto out;
  358. /* Initialise support for cn=monitor */
  359. rc = repl_monitor_init();
  360. if (rc != 0)
  361. goto out;
  362. /* initialize name hash */
  363. rc = replica_init_name_hash ();
  364. if (rc != 0)
  365. goto out;
  366. /* initialize dn hash */
  367. rc = replica_init_dn_hash ();
  368. if (rc != 0)
  369. goto out;
  370. /* create replicas */
  371. multimaster_mtnode_construct_replicas ();
  372. /* Initialise the 5.0 Changelog */
  373. rc = changelog5_init();
  374. if (rc != 0)
  375. goto out;
  376. /* Initialize the replication agreements, unless we're dumping LDIF */
  377. if (!is_ldif_dump)
  378. {
  379. rc = agmtlist_config_init();
  380. if (rc != 0)
  381. goto out;
  382. }
  383. /* check if the replica's data was reloaded offline and we need
  384. to reinitialize replica's changelog. This should be done
  385. after the changelog is initialized */
  386. replica_enumerate_replicas (replica_check_for_data_reload, NULL);
  387. /* register to be notified when backend state changes */
  388. slapi_register_backend_state_change((void *)multimaster_be_state_change,
  389. multimaster_be_state_change);
  390. multimaster_started_flag = 1;
  391. multimaster_stopped_flag = 0;
  392. }
  393. out:
  394. return rc;
  395. }
  396. int
  397. multimaster_stop( Slapi_PBlock *pb )
  398. {
  399. int rc= 0; /* OK */
  400. if (!multimaster_stopped_flag)
  401. {
  402. if (!is_ldif_dump)
  403. {
  404. agmtlist_shutdown(); /* Shut down replication agreements */
  405. }
  406. /* unregister backend state change notification */
  407. slapi_unregister_backend_state_change((void *)multimaster_be_state_change);
  408. changelog5_cleanup(); /* Shut down the changelog */
  409. multimaster_mtnode_extension_destroy(); /* Destroy mapping tree node exts */
  410. replica_destroy_name_hash(); /* destroy the hash and its remaining content */
  411. replica_config_destroy (); /* Destroy replica config info */
  412. multimaster_stopped_flag = 1;
  413. /* JCMREPL - Wait for all our threads to stop */
  414. /* JCMREPL - Shut down the replication plugin */
  415. /* JCMREPL - Mark all the replication plugin interfaces at not enabled. */
  416. }
  417. return rc;
  418. }
  419. PRBool
  420. multimaster_started()
  421. {
  422. return(multimaster_started_flag != 0);
  423. }
  424. /*
  425. * Initialize the multimaster replication plugin.
  426. */
  427. int replication_multimaster_plugin_init(Slapi_PBlock *pb)
  428. {
  429. static int multimaster_initialised= 0;
  430. int rc= 0; /* OK */
  431. void *identity = NULL;
  432. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
  433. PR_ASSERT (identity);
  434. repl_set_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION, identity);
  435. /* need the repl plugin path for the chain on update function */
  436. /* slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &entry);
  437. PR_ASSERT(entry);
  438. path = slapi_entry_attr_get_charptr(entry, "nsslapd-pluginpath");
  439. repl_set_repl_plugin_path(path);
  440. slapi_ch_free_string(&path);
  441. */
  442. multimaster_mtnode_extension_init ();
  443. if(config_is_slapd_lite())
  444. {
  445. slapi_log_error( SLAPI_LOG_FATAL, repl_plugin_name,
  446. "replication plugin not approved for restricted"
  447. " mode Directory Server.\n" );
  448. rc= -1;
  449. }
  450. if(rc==0 && !multimaster_initialised)
  451. {
  452. /* initialize replica hash - has to be done before mapping tree is
  453. initialized so we can't do it in the start function */
  454. if (rc != 0)
  455. {
  456. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  457. "replication_multimaster_plugin_init: failed to initialize replica hash\n");
  458. return -1;
  459. }
  460. /* Initialize extensions */
  461. repl_con_init_ext();
  462. repl_sup_init_ext();
  463. rc= slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 );
  464. rc= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterdesc );
  465. rc= slapi_pblock_set( pb, SLAPI_PLUGIN_START_FN, (void *) multimaster_start );
  466. rc= slapi_pblock_set( pb, SLAPI_PLUGIN_CLOSE_FN, (void *) multimaster_stop );
  467. /* Register the plugin interfaces we implement */
  468. rc= slapi_register_plugin("preoperation", 1 /* Enabled */, "multimaster_preop_init", multimaster_preop_init, "Multimaster replication preoperation plugin", NULL, identity);
  469. rc= slapi_register_plugin("postoperation", 1 /* Enabled */, "multimaster_postop_init", multimaster_postop_init, "Multimaster replication postoperation plugin", NULL, identity);
  470. rc= slapi_register_plugin("bepreoperation", 1 /* Enabled */, "multimaster_bepreop_init", multimaster_bepreop_init, "Multimaster replication bepreoperation plugin", NULL, identity);
  471. rc= slapi_register_plugin("bepostoperation", 1 /* Enabled */, "multimaster_bepostop_init", multimaster_bepostop_init, "Multimaster replication bepostoperation plugin", NULL, identity);
  472. rc= slapi_register_plugin("internalpreoperation", 1 /* Enabled */, "multimaster_internalpreop_init", multimaster_internalpreop_init, "Multimaster replication internal preoperation plugin", NULL, identity);
  473. rc= slapi_register_plugin("internalpostoperation", 1 /* Enabled */, "multimaster_internalpostop_init", multimaster_internalpostop_init, "Multimaster replication internal postoperation plugin", NULL, identity);
  474. rc= slapi_register_plugin("extendedop", 1 /* Enabled */, "multimaster_start_extop_init", multimaster_start_extop_init, "Multimaster replication start extended operation plugin", NULL, identity);
  475. rc= slapi_register_plugin("extendedop", 1 /* Enabled */, "multimaster_end_extop_init", multimaster_end_extop_init, "Multimaster replication end extended operation plugin", NULL, identity);
  476. rc= slapi_register_plugin("extendedop", 1 /* Enabled */, "multimaster_total_extop_init", multimaster_total_extop_init, "Multimaster replication total update extended operation plugin", NULL, identity);
  477. rc= slapi_register_plugin("extendedop", 1 /* Enabled */, "multimaster_response_extop_init", multimaster_response_extop_init, "Multimaster replication extended response plugin", NULL, identity);
  478. }
  479. return rc;
  480. }