repl_init.c 13 KB

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