1
0

repl_init.c 13 KB

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