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.
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.
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.
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
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 **/
45
* Add an entry like the following to dse.ldif to enable this plugin:
47
dn: cn=Legacy Replication Plugin,cn=plugins,cn=config
49
objectclass: nsSlapdPlugin
50
objectclass: extensibleObject
51
cn: Legacy Replication Plugin
52
nsslapd-pluginpath: /export2/servers/Hydra-supplier/lib/replication-plugin.so
53
nsslapd-plugininitfunc: replication_legacy_plugin_init
54
nsslapd-plugintype: object
55
nsslapd-pluginenabled: on
56
nsslapd-plugin-depends-on-type: database
57
nsslapd-plugin-depends-on-named: Class of Service
58
nsslapd-plugin-depends-on-named: Multi-Master Replication Plugin
59
nsslapd-pluginid: replication-legacy
60
nsslapd-pluginversion: 5.0b1
61
nsslapd-pluginvendor: Netscape Communications
62
nsslapd-plugindescription: Legacy Replication Plugin
64
NOTE: This plugin depends on the Multi-Master Replication Plugin
68
#include "slapi-plugin.h"
71
#include "repl_shared.h"
72
#include "cl4.h" /* changelog interface */
75
int *module_ldap_debug = 0;
77
void plugin_init_debug_level(int *level_ptr)
79
module_ldap_debug = level_ptr;
83
/* ----------------------------- Legacy Replication Plugin */
85
static Slapi_PluginDesc legacydesc = { "replication-legacy", VENDOR, DS_PACKAGE_VERSION, "Legacy Replication Plugin" };
86
static Slapi_PluginDesc legacypreopdesc = { "replication-legacy-preop", VENDOR, DS_PACKAGE_VERSION, "Legacy replication pre-operation plugin" };
87
static Slapi_PluginDesc legacypostopdesc = { "replication-legacy-postop", VENDOR, DS_PACKAGE_VERSION, "Legacy replication post-operation plugin" };
88
static Slapi_PluginDesc legacyinternalpreopdesc = { "replication-legacy-internalpreop", VENDOR, DS_PACKAGE_VERSION, "Legacy replication internal pre-operation plugin" };
89
static Slapi_PluginDesc legacyinternalpostopdesc = { "replication-legacy-internalpostop", VENDOR, DS_PACKAGE_VERSION, "Legacy replication internal post-operation plugin" };
90
static Slapi_PluginDesc legacyentrydesc = { "replication-legacy-entry", VENDOR, DS_PACKAGE_VERSION, "Legacy replication entry plugin" };
92
static int legacy_stopped; /* A flag which is set when all the plugin threads are to stop */
95
/* Initialize preoperation plugin points */
97
legacy_preop_init( Slapi_PBlock *pb )
101
if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
102
slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&legacypreopdesc ) != 0 ||
103
slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_BIND_FN, (void *) legacy_preop_bind ) != 0 ||
104
slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_ADD_FN, (void *) legacy_preop_add ) != 0 ||
105
slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_DELETE_FN, (void *) legacy_preop_delete ) != 0 ||
106
slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_MODIFY_FN, (void *) legacy_preop_modify ) != 0 ||
107
slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_MODRDN_FN, (void *) legacy_preop_modrdn ) != 0 ||
108
slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_SEARCH_FN, (void *) legacy_preop_search ) != 0 ||
109
slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_COMPARE_FN, (void *) legacy_preop_compare ) != 0 ||
110
slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_ENTRY_FN, (void *) legacy_pre_entry ))
112
slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "legacy_preop_init failed\n" );
120
/* Initialize postoperation plugin points */
122
legacy_postop_init( Slapi_PBlock *pb )
126
if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
127
slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&legacypostopdesc ) != 0 ||
128
slapi_pblock_set( pb, SLAPI_PLUGIN_POST_ADD_FN, (void *) legacy_postop_add ) != 0 ||
129
slapi_pblock_set( pb, SLAPI_PLUGIN_POST_DELETE_FN, (void *) legacy_postop_delete ) != 0 ||
130
slapi_pblock_set( pb, SLAPI_PLUGIN_POST_MODIFY_FN, (void *) legacy_postop_modify ) != 0 ||
131
slapi_pblock_set( pb, SLAPI_PLUGIN_POST_MODRDN_FN, (void *) legacy_postop_modrdn ) != 0 )
133
slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "legacy_postop_init failed\n" );
142
/* Initialize internal preoperation plugin points (called for internal operations) */
144
legacy_internalpreop_init( Slapi_PBlock *pb )
148
if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
149
slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&legacyinternalpreopdesc ) != 0 ||
150
slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_PRE_ADD_FN, (void *) legacy_preop_add ) != 0 ||
151
slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_PRE_DELETE_FN, (void *) legacy_preop_delete ) != 0 ||
152
slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_PRE_MODIFY_FN, (void *) legacy_preop_modify ) != 0 ||
153
slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_PRE_MODRDN_FN, (void *) legacy_preop_modrdn ) != 0 )
155
slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "legacy_internalpreop_init failed\n" );
163
/* Initialize internal postoperation plugin points (called for internal operations) */
165
legacy_internalpostop_init( Slapi_PBlock *pb )
169
if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
170
slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&legacyinternalpostopdesc ) != 0 ||
171
slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_POST_ADD_FN, (void *) legacy_postop_add ) != 0 ||
172
slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_POST_DELETE_FN, (void *) legacy_postop_delete ) != 0 ||
173
slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_POST_MODIFY_FN, (void *) legacy_postop_modify ) != 0 ||
174
slapi_pblock_set( pb, SLAPI_PLUGIN_INTERNAL_POST_MODRDN_FN, (void *) legacy_postop_modrdn ) != 0 )
176
slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "legacy_internalpostop_init failed\n" );
185
/* Initialize the entry plugin point for the legacy replication plugin */
187
legacy_entry_init( Slapi_PBlock *pb )
191
/* Set up the fn pointers for the preop and postop operations we're interested in */
192
if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
193
slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&legacyentrydesc ) != 0 )
195
slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "legacy_entry_init failed\n" );
205
* Create the entry at the top of the replication configuration subtree.
210
/* DN part of this entry_string: no need to be optimized. */
211
char *entry_string = slapi_ch_strdup("dn: cn=replication,cn=config\nobjectclass: top\nobjectclass: extensibleobject\ncn: replication\n");
212
Slapi_PBlock *pb = slapi_pblock_new();
213
Slapi_Entry *e = slapi_str2entry(entry_string, 0);
216
slapi_add_entry_internal_set_pb(pb, e, NULL, /* controls */
217
repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION), 0 /* flags */);
218
slapi_add_internal_pb(pb);
219
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &return_value);
220
slapi_pblock_destroy(pb);
221
slapi_ch_free((void **)&entry_string);
226
/* Start the legacy replication plugin */
228
legacy_start( Slapi_PBlock *pb )
230
static int legacy_started = 0;
237
/* Initialise support for cn=monitor */
240
/* Initialise support for "" (the rootdse) */
241
/* repl_rootdse_init(); */
243
/* Decode the command line args to see if we're dumping to LDIF */
247
slapi_pblock_get( pb, SLAPI_ARGC, &argc);
248
slapi_pblock_get( pb, SLAPI_ARGV, &argv);
249
repl_entry_init(argc,argv);
252
/* Create the entry at the top of the config area, if it doesn't exist */
253
/* XXXggood this should be in the 5.0 plugin! */
254
ctrc = create_config_top();
255
if (ctrc != LDAP_SUCCESS && ctrc != LDAP_ALREADY_EXISTS)
257
slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "Warning: unable to "
258
"create configuration entry %s: %s\n", REPL_CONFIG_TOP,
259
ldap_err2string(ctrc));
261
(void)legacy_consumer_config_init();
263
/* register to be notified when backend state changes */
264
slapi_register_backend_state_change((void *)legacy_consumer_be_state_change,
265
legacy_consumer_be_state_change);
274
/* Post-start function for the legacy replication plugin */
276
legacy_poststart( Slapi_PBlock *pb )
283
/* Stop the legacy replication plugin */
285
legacy_stop( Slapi_PBlock *pb )
295
/* unregister backend state change notification */
296
slapi_unregister_backend_state_change((void *)legacy_consumer_be_state_change);
302
/* Initialize the legacy replication plugin */
304
replication_legacy_plugin_init(Slapi_PBlock *pb)
306
static int legacy_initialised= 0;
308
void *identity = NULL;
310
slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
311
PR_ASSERT (identity);
312
repl_set_plugin_identity (PLUGIN_LEGACY_REPLICATION, identity);
314
if(rc==0 && !legacy_initialised)
316
rc= slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 );
317
rc= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&legacydesc );
318
rc= slapi_pblock_set( pb, SLAPI_PLUGIN_START_FN, (void *) legacy_start );
319
rc= slapi_pblock_set( pb, SLAPI_PLUGIN_CLOSE_FN, (void *) legacy_stop );
320
rc= slapi_pblock_set( pb, SLAPI_PLUGIN_POSTSTART_FN, (void *) legacy_poststart );
322
/* Register the plugin interfaces we implement */
323
rc= slapi_register_plugin("preoperation", 1 /* Enabled */, "legacy_preop_init", legacy_preop_init, "Legacy replication preoperation plugin", NULL, identity);
324
rc= slapi_register_plugin("postoperation", 1 /* Enabled */, "legacy_postop_init", legacy_postop_init, "Legacy replication postoperation plugin", NULL, identity);
325
rc= slapi_register_plugin("internalpreoperation", 1 /* Enabled */, "legacy_internalpreop_init", legacy_internalpreop_init, "Legacy replication internal preoperation plugin", NULL, identity);
326
rc= slapi_register_plugin("internalpostoperation", 1 /* Enabled */, "legacy_internalpostop_init", legacy_internalpostop_init, "Legacy replication internal postoperation plugin", NULL, identity);
327
rc= slapi_register_plugin("entry", 1 /* Enabled */, "legacy_entry_init", legacy_entry_init, "Legacy replication entry plugin", NULL, identity);
329
legacy_initialised= 1;
338
return legacy_stopped;