repl_init.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. *
  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. * Add an entry like the following to dse.ldif to enable this plugin:
  14. dn: cn=Legacy Replication Plugin,cn=plugins,cn=config
  15. objectclass: top
  16. objectclass: nsSlapdPlugin
  17. objectclass: extensibleObject
  18. cn: Legacy Replication Plugin
  19. nsslapd-pluginpath: /export2/servers/Hydra-supplier/lib/replication-plugin.so
  20. nsslapd-plugininitfunc: replication_legacy_plugin_init
  21. nsslapd-plugintype: object
  22. nsslapd-pluginenabled: on
  23. nsslapd-plugin-depends-on-type: database
  24. nsslapd-plugin-depends-on-named: Class of Service
  25. nsslapd-plugin-depends-on-named: Multi-Master Replication Plugin
  26. nsslapd-pluginid: replication-legacy
  27. nsslapd-pluginversion: 5.0b1
  28. nsslapd-pluginvendor: Netscape Communications
  29. nsslapd-plugindescription: Legacy Replication Plugin
  30. NOTE: This plugin depends on the Multi-Master Replication Plugin
  31. */
  32. #include "slapi-plugin.h"
  33. #include "repl.h"
  34. #include "repl5.h"
  35. #include "repl_shared.h"
  36. #include "cl4.h" /* changelog interface */
  37. /* ----------------------------- Legacy Replication Plugin */
  38. static Slapi_PluginDesc legacydesc = { "replication-legacy", VENDOR, DS_PACKAGE_VERSION, "Legacy Replication Plugin" };
  39. static Slapi_PluginDesc legacypreopdesc = { "replication-legacy-preop", VENDOR, DS_PACKAGE_VERSION, "Legacy replication pre-operation plugin" };
  40. static Slapi_PluginDesc legacypostopdesc = { "replication-legacy-postop", VENDOR, DS_PACKAGE_VERSION, "Legacy replication post-operation plugin" };
  41. static Slapi_PluginDesc legacyinternalpreopdesc = { "replication-legacy-internalpreop", VENDOR, DS_PACKAGE_VERSION, "Legacy replication internal pre-operation plugin" };
  42. static Slapi_PluginDesc legacyinternalpostopdesc = { "replication-legacy-internalpostop", VENDOR, DS_PACKAGE_VERSION, "Legacy replication internal post-operation plugin" };
  43. static Slapi_PluginDesc legacyentrydesc = { "replication-legacy-entry", VENDOR, DS_PACKAGE_VERSION, "Legacy replication entry plugin" };
  44. static int legacy_stopped; /* A flag which is set when all the plugin threads are to stop */
  45. /* Initialize preoperation plugin points */
  46. int
  47. legacy_preop_init( Slapi_PBlock *pb )
  48. {
  49. int rc= 0; /* OK */
  50. if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  51. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&legacypreopdesc ) != 0 ||
  52. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_BIND_FN, (void *) legacy_preop_bind ) != 0 ||
  53. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_ADD_FN, (void *) legacy_preop_add ) != 0 ||
  54. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_DELETE_FN, (void *) legacy_preop_delete ) != 0 ||
  55. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_MODIFY_FN, (void *) legacy_preop_modify ) != 0 ||
  56. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_MODRDN_FN, (void *) legacy_preop_modrdn ) != 0 ||
  57. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_SEARCH_FN, (void *) legacy_preop_search ) != 0 ||
  58. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_COMPARE_FN, (void *) legacy_preop_compare ) != 0 ||
  59. slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_ENTRY_FN, (void *) legacy_pre_entry ))
  60. {
  61. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "legacy_preop_init failed\n" );
  62. rc= -1;
  63. }
  64. return rc;
  65. }
  66. /* Initialize postoperation plugin points */
  67. static int
  68. legacy_postop_init( Slapi_PBlock *pb )
  69. {
  70. int rc= 0; /* OK */
  71. if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  72. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&legacypostopdesc ) != 0 ||
  73. slapi_pblock_set( pb, SLAPI_PLUGIN_POST_ADD_FN, (void *) legacy_postop_add ) != 0 ||
  74. slapi_pblock_set( pb, SLAPI_PLUGIN_POST_DELETE_FN, (void *) legacy_postop_delete ) != 0 ||
  75. slapi_pblock_set( pb, SLAPI_PLUGIN_POST_MODIFY_FN, (void *) legacy_postop_modify ) != 0 ||
  76. slapi_pblock_set( pb, SLAPI_PLUGIN_POST_MODRDN_FN, (void *) legacy_postop_modrdn ) != 0 )
  77. {
  78. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "legacy_postop_init failed\n" );
  79. rc= -1;
  80. }
  81. return rc;
  82. }
  83. /* Initialize internal preoperation plugin points (called for internal operations) */
  84. static int
  85. legacy_internalpreop_init( Slapi_PBlock *pb )
  86. {
  87. int rc= 0; /* OK */
  88. if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  89. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&legacyinternalpreopdesc ) != 0 ||
  90. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_PRE_ADD_FN, (void *) legacy_preop_add ) != 0 ||
  91. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_PRE_DELETE_FN, (void *) legacy_preop_delete ) != 0 ||
  92. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_PRE_MODIFY_FN, (void *) legacy_preop_modify ) != 0 ||
  93. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_PRE_MODRDN_FN, (void *) legacy_preop_modrdn ) != 0 )
  94. {
  95. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "legacy_internalpreop_init failed\n" );
  96. rc= -1;
  97. }
  98. return rc;
  99. }
  100. /* Initialize internal postoperation plugin points (called for internal operations) */
  101. static int
  102. legacy_internalpostop_init( Slapi_PBlock *pb )
  103. {
  104. int rc= 0; /* OK */
  105. if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  106. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&legacyinternalpostopdesc ) != 0 ||
  107. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_POST_ADD_FN, (void *) legacy_postop_add ) != 0 ||
  108. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_POST_DELETE_FN, (void *) legacy_postop_delete ) != 0 ||
  109. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_POST_MODIFY_FN, (void *) legacy_postop_modify ) != 0 ||
  110. slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_POST_MODRDN_FN, (void *) legacy_postop_modrdn ) != 0 )
  111. {
  112. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "legacy_internalpostop_init failed\n" );
  113. rc= -1;
  114. }
  115. return rc;
  116. }
  117. /* Initialize the entry plugin point for the legacy replication plugin */
  118. static int
  119. legacy_entry_init( Slapi_PBlock *pb )
  120. {
  121. int rc= 0; /* OK */
  122. /* Set up the fn pointers for the preop and postop operations we're interested in */
  123. if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  124. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&legacyentrydesc ) != 0 )
  125. {
  126. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "legacy_entry_init failed\n" );
  127. rc= -1;
  128. }
  129. return rc;
  130. }
  131. /*
  132. * Create the entry at the top of the replication configuration subtree.
  133. */
  134. static int
  135. create_config_top()
  136. {
  137. /* DN part of this entry_string: no need to be optimized. */
  138. char *entry_string = slapi_ch_strdup("dn: cn=replication,cn=config\nobjectclass: top\nobjectclass: extensibleobject\ncn: replication\n");
  139. Slapi_PBlock *pb = slapi_pblock_new();
  140. Slapi_Entry *e = slapi_str2entry(entry_string, 0);
  141. int return_value;
  142. slapi_add_entry_internal_set_pb(pb, e, NULL, /* controls */
  143. repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION), 0 /* flags */);
  144. slapi_add_internal_pb(pb);
  145. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &return_value);
  146. slapi_pblock_destroy(pb);
  147. slapi_ch_free((void **)&entry_string);
  148. return return_value;
  149. }
  150. /* Start the legacy replication plugin */
  151. static int
  152. legacy_start( Slapi_PBlock *pb )
  153. {
  154. static int legacy_started = 0;
  155. int rc= 0; /* OK */
  156. if (!legacy_started)
  157. {
  158. int ctrc;
  159. /* Initialise support for cn=monitor */
  160. repl_monitor_init();
  161. /* Initialise support for "" (the rootdse) */
  162. /* repl_rootdse_init(); */
  163. /* Decode the command line args to see if we're dumping to LDIF */
  164. {
  165. int argc;
  166. char **argv;
  167. slapi_pblock_get( pb, SLAPI_ARGC, &argc);
  168. slapi_pblock_get( pb, SLAPI_ARGV, &argv);
  169. repl_entry_init(argc,argv);
  170. }
  171. /* Create the entry at the top of the config area, if it doesn't exist */
  172. /* XXXggood this should be in the 5.0 plugin! */
  173. ctrc = create_config_top();
  174. if (ctrc != LDAP_SUCCESS && ctrc != LDAP_ALREADY_EXISTS)
  175. {
  176. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "Warning: unable to "
  177. "create configuration entry %s: %s\n", REPL_CONFIG_TOP,
  178. ldap_err2string(ctrc));
  179. }
  180. (void)legacy_consumer_config_init();
  181. /* register to be notified when backend state changes */
  182. slapi_register_backend_state_change((void *)legacy_consumer_be_state_change,
  183. legacy_consumer_be_state_change);
  184. legacy_started = 1;
  185. legacy_stopped = 0;
  186. }
  187. return rc;
  188. }
  189. /* Post-start function for the legacy replication plugin */
  190. static int
  191. legacy_poststart( Slapi_PBlock *pb )
  192. {
  193. int rc = 0; /* OK */
  194. return rc;
  195. }
  196. /* Stop the legacy replication plugin */
  197. static int
  198. legacy_stop( Slapi_PBlock *pb )
  199. {
  200. int rc= 0; /* OK */
  201. if (!legacy_stopped)
  202. {
  203. /*csnShutdown();*/
  204. legacy_stopped = 1;
  205. }
  206. /* unregister backend state change notification */
  207. slapi_unregister_backend_state_change((void *)legacy_consumer_be_state_change);
  208. return rc;
  209. }
  210. /* Initialize the legacy replication plugin */
  211. int
  212. replication_legacy_plugin_init(Slapi_PBlock *pb)
  213. {
  214. static int legacy_initialised= 0;
  215. int rc= 0; /* OK */
  216. void *identity = NULL;
  217. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
  218. PR_ASSERT (identity);
  219. repl_set_plugin_identity (PLUGIN_LEGACY_REPLICATION, identity);
  220. if(rc==0 && !legacy_initialised)
  221. {
  222. rc= slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 );
  223. rc= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&legacydesc );
  224. rc= slapi_pblock_set( pb, SLAPI_PLUGIN_START_FN, (void *) legacy_start );
  225. rc= slapi_pblock_set( pb, SLAPI_PLUGIN_CLOSE_FN, (void *) legacy_stop );
  226. rc= slapi_pblock_set( pb, SLAPI_PLUGIN_POSTSTART_FN, (void *) legacy_poststart );
  227. /* Register the plugin interfaces we implement */
  228. rc= slapi_register_plugin("preoperation", 1 /* Enabled */, "legacy_preop_init", legacy_preop_init, "Legacy replication preoperation plugin", NULL, identity);
  229. rc= slapi_register_plugin("postoperation", 1 /* Enabled */, "legacy_postop_init", legacy_postop_init, "Legacy replication postoperation plugin", NULL, identity);
  230. rc= slapi_register_plugin("internalpreoperation", 1 /* Enabled */, "legacy_internalpreop_init", legacy_internalpreop_init, "Legacy replication internal preoperation plugin", NULL, identity);
  231. rc= slapi_register_plugin("internalpostoperation", 1 /* Enabled */, "legacy_internalpostop_init", legacy_internalpostop_init, "Legacy replication internal postoperation plugin", NULL, identity);
  232. rc= slapi_register_plugin("entry", 1 /* Enabled */, "legacy_entry_init", legacy_entry_init, "Legacy replication entry plugin", NULL, identity);
  233. legacy_initialised= 1;
  234. }
  235. return rc;
  236. }
  237. int
  238. get_legacy_stop()
  239. {
  240. return legacy_stopped;
  241. }