1
0

repl_init.c 13 KB

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