repl_init.c 11 KB

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