repl_init.c 13 KB

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