~ubuntu-branches/ubuntu/wily/389-ds-base/wily

« back to all changes in this revision

Viewing changes to ldap/servers/plugins/replication/repl_init.c

  • Committer: Package Import Robot
  • Author(s): Krzysztof Klimonda
  • Date: 2012-03-27 14:26:16 UTC
  • Revision ID: package-import@ubuntu.com-20120327142616-xt24t6nffm3f7ybz
Tags: upstream-1.2.11.7
ImportĀ upstreamĀ versionĀ 1.2.11.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#ifdef HAVE_CONFIG_H
 
40
#  include <config.h>
 
41
#endif
 
42
 
 
43
 
 
44
/*
 
45
 * Add an entry like the following to dse.ldif to enable this plugin:
 
46
 
 
47
dn: cn=Legacy Replication Plugin,cn=plugins,cn=config
 
48
objectclass: top
 
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
 
63
 
 
64
NOTE: This plugin depends on the Multi-Master Replication Plugin
 
65
 
 
66
*/
 
67
 
 
68
#include "slapi-plugin.h"
 
69
#include "repl.h"
 
70
#include "repl5.h"
 
71
#include "repl_shared.h"
 
72
#include "cl4.h"        /* changelog interface */
 
73
 
 
74
#ifdef _WIN32
 
75
int *module_ldap_debug = 0;
 
76
 
 
77
void plugin_init_debug_level(int *level_ptr)
 
78
{
 
79
        module_ldap_debug = level_ptr;
 
80
}
 
81
#endif
 
82
 
 
83
/* ----------------------------- Legacy Replication Plugin */
 
84
 
 
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" };
 
91
 
 
92
static int legacy_stopped; /* A flag which is set when all the plugin threads are to stop */        
 
93
 
 
94
 
 
95
/* Initialize preoperation plugin points */
 
96
int
 
97
legacy_preop_init( Slapi_PBlock *pb )
 
98
{
 
99
    int rc= 0; /* OK */
 
100
 
 
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 ))
 
111
        {
 
112
                slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "legacy_preop_init failed\n" );
 
113
                rc= -1;
 
114
        }
 
115
        return rc;
 
116
}
 
117
 
 
118
 
 
119
 
 
120
/* Initialize postoperation plugin points */
 
121
static int
 
122
legacy_postop_init( Slapi_PBlock *pb )
 
123
{
 
124
    int rc= 0; /* OK */
 
125
 
 
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 )
 
132
        {
 
133
                slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "legacy_postop_init failed\n" );
 
134
                rc= -1;
 
135
        }
 
136
 
 
137
        return rc;
 
138
}
 
139
 
 
140
 
 
141
 
 
142
/* Initialize internal preoperation plugin points (called for internal operations) */
 
143
static int
 
144
legacy_internalpreop_init( Slapi_PBlock *pb )
 
145
{
 
146
    int rc= 0; /* OK */
 
147
        
 
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 )
 
154
        {
 
155
                slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "legacy_internalpreop_init failed\n" );
 
156
                rc= -1;
 
157
        }
 
158
        return rc;
 
159
}
 
160
 
 
161
 
 
162
 
 
163
/* Initialize internal postoperation plugin points (called for internal operations) */
 
164
static int
 
165
legacy_internalpostop_init( Slapi_PBlock *pb )
 
166
{
 
167
    int rc= 0; /* OK */
 
168
 
 
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 )
 
175
        {
 
176
                slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "legacy_internalpostop_init failed\n" );
 
177
                rc= -1;
 
178
        }
 
179
 
 
180
        return rc;
 
181
}
 
182
 
 
183
 
 
184
 
 
185
/* Initialize the entry plugin point for the legacy replication plugin */
 
186
static int
 
187
legacy_entry_init( Slapi_PBlock *pb )
 
188
{
 
189
    int rc= 0; /* OK */
 
190
        
 
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 )
 
194
        {
 
195
                slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "legacy_entry_init failed\n" );
 
196
                rc= -1;
 
197
        }
 
198
        return rc;
 
199
}
 
200
 
 
201
 
 
202
 
 
203
 
 
204
/*
 
205
 * Create the entry at the top of the replication configuration subtree.
 
206
 */
 
207
static int
 
208
create_config_top()
 
209
{
 
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);
 
214
        int return_value;
 
215
 
 
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);
 
222
        return return_value;
 
223
}
 
224
 
 
225
 
 
226
/* Start the legacy replication plugin */
 
227
static int 
 
228
legacy_start( Slapi_PBlock *pb )
 
229
{
 
230
        static int legacy_started = 0;
 
231
    int rc= 0; /* OK */
 
232
 
 
233
    if (!legacy_started)
 
234
        {
 
235
                int ctrc;
 
236
 
 
237
                /* Initialise support for cn=monitor */
 
238
                repl_monitor_init();
 
239
 
 
240
                /* Initialise support for "" (the rootdse) */
 
241
                /* repl_rootdse_init(); */
 
242
 
 
243
                /* Decode the command line args to see if we're dumping to LDIF */
 
244
                {
 
245
                        int argc;
 
246
                        char **argv;
 
247
                        slapi_pblock_get( pb, SLAPI_ARGC, &argc);
 
248
                        slapi_pblock_get( pb, SLAPI_ARGV, &argv);
 
249
                        repl_entry_init(argc,argv);
 
250
                }
 
251
 
 
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)
 
256
                {
 
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));
 
260
                }
 
261
                (void)legacy_consumer_config_init();
 
262
 
 
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);
 
266
 
 
267
                legacy_started = 1;
 
268
                legacy_stopped = 0;
 
269
        }
 
270
    return rc;
 
271
}
 
272
 
 
273
 
 
274
/* Post-start function for the legacy replication plugin */
 
275
static int
 
276
legacy_poststart( Slapi_PBlock *pb )
 
277
{
 
278
    int rc = 0; /* OK */
 
279
    return rc;
 
280
}
 
281
 
 
282
 
 
283
/* Stop the legacy replication plugin */
 
284
static int
 
285
legacy_stop( Slapi_PBlock *pb )
 
286
{
 
287
    int rc= 0; /* OK */
 
288
 
 
289
    if (!legacy_stopped)
 
290
        {
 
291
        /*csnShutdown();*/
 
292
        legacy_stopped = 1;
 
293
        }
 
294
         
 
295
    /* unregister backend state change notification */
 
296
    slapi_unregister_backend_state_change((void *)legacy_consumer_be_state_change);
 
297
        
 
298
    return rc;
 
299
}
 
300
 
 
301
 
 
302
/* Initialize the legacy replication plugin */
 
303
int
 
304
replication_legacy_plugin_init(Slapi_PBlock *pb)
 
305
{
 
306
    static int legacy_initialised= 0;
 
307
    int rc= 0; /* OK */
 
308
        void *identity = NULL;
 
309
 
 
310
        slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &identity);
 
311
        PR_ASSERT (identity);
 
312
        repl_set_plugin_identity (PLUGIN_LEGACY_REPLICATION, identity);
 
313
 
 
314
        if(rc==0 && !legacy_initialised)
 
315
        {
 
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 );
 
321
                
 
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);
 
328
                
 
329
                legacy_initialised= 1;
 
330
        }
 
331
        return rc;
 
332
}
 
333
 
 
334
 
 
335
int
 
336
get_legacy_stop()
 
337
{
 
338
    return legacy_stopped;
 
339
}