repl_init.c 11 KB

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