repl5_init.c 20 KB

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