1
0

repl5_init.c 22 KB

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