-
Notifications
You must be signed in to change notification settings - Fork 80
/
retrocl.c
735 lines (637 loc) · 23 KB
/
retrocl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
/** BEGIN COPYRIGHT BLOCK
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
*
* License: GPL (version 3 or any later version).
* See LICENSE for details.
* END COPYRIGHT BLOCK **/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
/*
* Requires that create_instance.c have added a plugin entry similar to:
dn: cn=Retrocl Plugin,cn=plugins,cn=config
objectclass: top
objectclass: nsSlapdPlugin
objectclass: extensibleObject
cn: RetroCL Plugin
nsslapd-pluginpath: /export2/servers/Hydra-supplier/lib/retrocl-plugin.so
nsslapd-plugininitfunc: retrocl_plugin_init
nsslapd-plugintype: object
nsslapd-pluginenabled: on
nsslapd-plugin-depends-on-type: database
nsslapd-pluginid: retrocl
nsslapd-pluginversion: 5.0b2
nsslapd-pluginvendor: Sun Microsystems, Inc.
nsslapd-plugindescription: Retrocl Plugin
*
*/
#include "retrocl.h"
void *g_plg_identity[PLUGIN_MAX];
Slapi_Backend *retrocl_be_changelog = NULL;
PRLock *retrocl_internal_lock = NULL;
Slapi_RWLock *retrocl_cn_lock;
int retrocl_nattributes = 0;
char **retrocl_attributes = NULL;
char **retrocl_aliases = NULL;
int retrocl_log_deleted = 0;
int retrocl_nexclude_attrs = 0;
static Slapi_DN **retrocl_includes = NULL;
static Slapi_DN **retrocl_excludes = NULL;
static char **retrocl_exclude_attrs = NULL;
/* ----------------------------- Retrocl Plugin */
static Slapi_PluginDesc retrocldesc = {"retrocl", VENDOR, DS_PACKAGE_VERSION, "Retrocl Plugin"};
static Slapi_PluginDesc retroclpostopdesc = {"retrocl-postop", VENDOR, DS_PACKAGE_VERSION, "retrocl post-operation plugin"};
static Slapi_PluginDesc retroclinternalpostopdesc = {"retrocl-internalpostop", VENDOR, DS_PACKAGE_VERSION, "retrocl internal post-operation plugin"};
static int legacy_initialised = 0;
/*
* Function: retrocl_*
*
* Returns: LDAP_
*
* Arguments: Pb of operation
*
* Description: wrappers around retrocl_postob registered as callback
*
*/
int
retrocl_postop_add(Slapi_PBlock *pb)
{
return retrocl_postob(pb, OP_ADD);
}
int
retrocl_postop_delete(Slapi_PBlock *pb)
{
return retrocl_postob(pb, OP_DELETE);
}
int
retrocl_postop_modify(Slapi_PBlock *pb)
{
return retrocl_postob(pb, OP_MODIFY);
}
int
retrocl_postop_modrdn(Slapi_PBlock *pb)
{
return retrocl_postob(pb, OP_MODRDN);
}
/*
* Function: retrocl_postop_init
*
* Returns: 0/-1
*
* Arguments: Pb
*
* Description: callback function
*
*/
int
retrocl_postop_init(Slapi_PBlock *pb)
{
int rc = 0; /* OK */
Slapi_Entry *plugin_entry = NULL;
const char *plugin_type = NULL;
int postadd = SLAPI_PLUGIN_POST_ADD_FN;
int postmod = SLAPI_PLUGIN_POST_MODIFY_FN;
int postmdn = SLAPI_PLUGIN_POST_MODRDN_FN;
int postdel = SLAPI_PLUGIN_POST_DELETE_FN;
if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &plugin_entry) == 0) &&
plugin_entry &&
(plugin_type = slapi_entry_attr_get_ref(plugin_entry, "nsslapd-plugintype")) &&
plugin_type && strstr(plugin_type, "betxn")) {
postadd = SLAPI_PLUGIN_BE_TXN_POST_ADD_FN;
postmod = SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN;
postmdn = SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN;
postdel = SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN;
}
if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0 ||
slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&retroclpostopdesc) != 0 ||
slapi_pblock_set(pb, postadd, (void *)retrocl_postop_add) != 0 ||
slapi_pblock_set(pb, postdel, (void *)retrocl_postop_delete) != 0 ||
slapi_pblock_set(pb, postmod, (void *)retrocl_postop_modify) != 0 ||
slapi_pblock_set(pb, postmdn, (void *)retrocl_postop_modrdn) != 0) {
slapi_log_err(SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, "retrocl_postop_init failed\n");
rc = -1;
}
return rc;
}
/*
* Function: retrocl_internalpostop_init
*
* Returns: 0/-1
*
* Arguments: Pb
*
* Description: callback function
*
*/
int
retrocl_internalpostop_init(Slapi_PBlock *pb)
{
int rc = 0; /* OK */
if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0 ||
slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&retroclinternalpostopdesc) != 0 ||
slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_POST_ADD_FN, (void *)retrocl_postop_add) != 0 ||
slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_POST_DELETE_FN, (void *)retrocl_postop_delete) != 0 ||
slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_POST_MODIFY_FN, (void *)retrocl_postop_modify) != 0 ||
slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_POST_MODRDN_FN, (void *)retrocl_postop_modrdn) != 0) {
slapi_log_err(SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, "retrocl_internalpostop_init failed\n");
rc = -1;
}
return rc;
}
/*
* Function: retrocl_rootdse_init
*
* Returns: LDAP_SUCCESS
*
* Arguments: Slapi_PBlock
*
* Description: The FE DSE *must* be initialised before we get here.
*
*/
static int
retrocl_rootdse_init(Slapi_PBlock *pb)
{
int return_value = LDAP_SUCCESS;
slapi_config_register_callback_plugin(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP | DSE_FLAG_PLUGIN, "",
LDAP_SCOPE_BASE, "(objectclass=*)",
retrocl_rootdse_search, NULL, pb);
return return_value;
}
/*
* Function: retrocl_select_backend
*
* Returns: LDAP_
*
* Arguments: none
*
* Description: simulates an add of the changelog to see if it exists. If not,
* creates it. Then reads the changenumbers. This function should be called
* exactly once at startup.
*
*/
static int
retrocl_select_backend(void)
{
int err;
Slapi_PBlock *pb;
Slapi_Backend *be = NULL;
Slapi_Entry *referral = NULL;
Slapi_Operation *op = NULL;
char errbuf[SLAPI_DSE_RETURNTEXT_SIZE];
pb = slapi_pblock_new();
slapi_pblock_set(pb, SLAPI_PLUGIN_IDENTITY, g_plg_identity[PLUGIN_RETROCL]);
/* This is a simulated operation; no actual add is performed */
op = operation_new(OP_FLAG_INTERNAL);
operation_set_type(op, SLAPI_OPERATION_ADD); /* Ensure be not readonly */
operation_set_target_spec_str(op, RETROCL_CHANGELOG_DN);
slapi_pblock_set(pb, SLAPI_OPERATION, op);
err = slapi_mapping_tree_select(pb, &be, &referral, errbuf, sizeof(errbuf));
slapi_entry_free(referral);
if (err != LDAP_SUCCESS || be == NULL || be == defbackend_get_backend()) {
/* Could not find the backend for cn=changelog, either because
* it doesn't exist mapping tree not registered. */
slapi_log_err(SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
"retrocl_select_backend - Mapping tree select failed (%d) %s.\n", err, errbuf);
err = retrocl_create_config();
if (err != LDAP_SUCCESS)
return err;
} else {
retrocl_be_changelog = be;
}
retrocl_create_cle();
slapi_pblock_destroy(pb);
if (be)
slapi_be_Unlock(be);
return retrocl_get_changenumbers();
}
/*
* Function: retrocl_get_config_str
*
* Returns: malloc'ed string which must be freed.
*
* Arguments: attribute type name
*
* Description: reads a single-valued string attr from the plugins' own DSE.
* This is called twice: to obtain the trim max age during startup, and to
* obtain the change log directory. No callback is registered; you cannot
* change the trim max age without restarting the server.
*
*/
char *
retrocl_get_config_str(const char *attrt)
{
Slapi_Entry **entries;
Slapi_PBlock *pb = NULL;
char *ma;
int rc = 0;
char *dn;
/* RETROCL_PLUGIN_DN is no need to be normalized. */
dn = RETROCL_PLUGIN_DN;
pb = slapi_pblock_new();
slapi_search_internal_set_pb(pb, dn, LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, NULL,
NULL, g_plg_identity[PLUGIN_RETROCL], 0);
slapi_search_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
if (rc != 0) {
slapi_pblock_destroy(pb);
return NULL;
}
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
ma = slapi_entry_attr_get_charptr(entries[0], attrt);
slapi_free_search_results_internal(pb);
slapi_pblock_destroy(pb);
return ma;
}
static void
retrocl_remove_legacy_default_aci(void)
{
Slapi_PBlock *pb = NULL;
Slapi_Entry **entries;
char **aci_vals = NULL;
char *attrs[] = {"aci", NULL};
int rc;
pb = slapi_pblock_new();
slapi_search_internal_set_pb(pb, RETROCL_CHANGELOG_DN, LDAP_SCOPE_BASE, "objectclass=*",
attrs, 0, NULL, NULL, g_plg_identity[PLUGIN_RETROCL], 0);
slapi_search_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
if (rc == LDAP_SUCCESS) {
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
if (entries && entries[0]) {
if ((aci_vals = slapi_entry_attr_get_charray(entries[0], "aci"))) {
if (charray_inlist(aci_vals, RETROCL_ACL)) {
/*
* Okay, we need to remove the aci
*/
LDAPMod mod;
LDAPMod *mods[2];
char *val[2];
Slapi_PBlock *mod_pb = 0;
mod_pb = slapi_pblock_new();
mods[0] = &mod;
mods[1] = 0;
val[0] = RETROCL_ACL;
val[1] = 0;
mod.mod_op = LDAP_MOD_DELETE;
mod.mod_type = "aci";
mod.mod_values = val;
slapi_modify_internal_set_pb_ext(mod_pb, slapi_entry_get_sdn(entries[0]),
mods, 0, 0, g_plg_identity[PLUGIN_RETROCL], 0);
slapi_modify_internal_pb(mod_pb);
slapi_pblock_get(mod_pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
if (rc == LDAP_SUCCESS) {
slapi_log_err(SLAPI_LOG_NOTICE, RETROCL_PLUGIN_NAME,
"retrocl_remove_legacy_default_aci - "
"Successfully removed vulnerable legacy default aci \"%s\". "
"If the aci removal was not desired please use a different \"acl "
"name\" so it is not removed at the next plugin startup.\n",
RETROCL_ACL);
} else {
slapi_log_err(SLAPI_LOG_ERR, RETROCL_PLUGIN_NAME,
"retrocl_remove_legacy_default_aci - "
"Failed to removed vulnerable legacy default aci (%s) error %d\n",
RETROCL_ACL, rc);
}
slapi_pblock_destroy(mod_pb);
}
slapi_ch_array_free(aci_vals);
}
}
}
slapi_free_search_results_internal(pb);
slapi_pblock_destroy(pb);
}
/*
* Function: retrocl_start
*
* Returns: 0 on success
*
* Arguments: Pb
*
* Description:
*
*/
static int
retrocl_start(Slapi_PBlock *pb)
{
int rc = 0;
Slapi_Entry *e = NULL;
char **values = NULL;
int num_vals = 0;
int i = 0;
retrocl_rootdse_init(pb);
rc = retrocl_select_backend();
if (rc != 0) {
slapi_log_err(SLAPI_LOG_TRACE, RETROCL_PLUGIN_NAME, "retrocl_start - Couldn't find backend, not trimming retro changelog (%d).\n", rc);
return rc;
}
/* Remove the old default aci as it exposes passwords changes to anonymous users */
retrocl_remove_legacy_default_aci();
retrocl_init_trimming();
if (slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e) != 0) {
slapi_log_err(SLAPI_LOG_ERR, RETROCL_PLUGIN_NAME, "retrocl_start - Missing config entry.\n");
return -1;
}
/* Get the exclude attributes */
values = slapi_entry_attr_get_charray_ext(e, CONFIG_CHANGELOG_EXCLUDE_ATTRS, &num_vals);
if (values) {
retrocl_nexclude_attrs = num_vals;
retrocl_exclude_attrs = (char **)slapi_ch_calloc(num_vals + 1, sizeof(char *));
for (size_t i = 0; i < num_vals; i++) {
char *value = values[i];
char *pos = strchr(value, ':');
if (pos == NULL) {
retrocl_exclude_attrs[i] = slapi_ch_strdup(value);
} else {
retrocl_exclude_attrs[i] = slapi_ch_malloc(pos - value + 1);
strncpy(retrocl_exclude_attrs[i], value, pos - value);
retrocl_exclude_attrs[i][pos - value] = '\0';
}
slapi_log_err(SLAPI_LOG_INFO, RETROCL_PLUGIN_NAME,"retrocl_start - retrocl_exclude_attrs (%s).\n", retrocl_exclude_attrs[i]);
}
slapi_ch_array_free(values);
}
/* Get the exclude suffixes */
values = slapi_entry_attr_get_charray_ext(e, CONFIG_CHANGELOG_EXCLUDE_SUFFIX, &num_vals);
if (values) {
/* Validate the syntax before we create our DN array */
for (i = 0; i < num_vals; i++) {
if (slapi_dn_syntax_check(pb, values[i], 1)) {
/* invalid dn syntax */
slapi_log_err(SLAPI_LOG_ERR, RETROCL_PLUGIN_NAME,
"retrocl_start - Invalid DN (%s) for exclude suffix.\n", values[i]);
slapi_ch_array_free(values);
return -1;
}
}
/* Now create our SDN array */
retrocl_excludes = (Slapi_DN **)slapi_ch_calloc(sizeof(Slapi_DN *), num_vals + 1);
for (i = 0; i < num_vals; i++) {
retrocl_excludes[i] = slapi_sdn_new_dn_byval(values[i]);
}
slapi_ch_array_free(values);
}
/* Get the include suffixes */
values = slapi_entry_attr_get_charray_ext(e, CONFIG_CHANGELOG_INCLUDE_SUFFIX, &num_vals);
if (values) {
for (i = 0; i < num_vals; i++) {
/* Validate the syntax before we create our DN array */
if (slapi_dn_syntax_check(pb, values[i], 1)) {
/* invalid dn syntax */
slapi_log_err(SLAPI_LOG_ERR, RETROCL_PLUGIN_NAME,
"retrocl_start - Invalid DN (%s) for include suffix.\n", values[i]);
slapi_ch_array_free(values);
return -1;
}
}
/* Now create our SDN array */
retrocl_includes = (Slapi_DN **)slapi_ch_calloc(sizeof(Slapi_DN *), num_vals + 1);
for (i = 0; i < num_vals; i++) {
retrocl_includes[i] = slapi_sdn_new_dn_byval(values[i]);
}
slapi_ch_array_free(values);
}
if (retrocl_includes && retrocl_excludes) {
/*
* Make sure we haven't mixed the same suffix, and there are no
* conflicts between the includes and excludes
*/
int i = 0;
while (retrocl_includes[i]) {
int x = 0;
while (retrocl_excludes[x]) {
if (slapi_sdn_compare(retrocl_includes[i], retrocl_excludes[x]) == 0) {
/* we have a conflict */
slapi_log_err(SLAPI_LOG_ERR, RETROCL_PLUGIN_NAME,
"retrocl_start - Include suffix (%s) is also listed in exclude suffix list\n",
slapi_sdn_get_dn(retrocl_includes[i]));
return -1;
}
x++;
}
i++;
}
/* Check for parent/child conflicts */
i = 0;
while (retrocl_includes[i]) {
int x = 0;
while (retrocl_excludes[x]) {
if (slapi_sdn_issuffix(retrocl_includes[i], retrocl_excludes[x])) {
/* we have a conflict */
slapi_log_err(SLAPI_LOG_ERR, RETROCL_PLUGIN_NAME,
"retrocl_start - include suffix (%s) is a child of the exclude suffix(%s)\n",
slapi_sdn_get_dn(retrocl_includes[i]),
slapi_sdn_get_dn(retrocl_excludes[i]));
return -1;
}
x++;
}
i++;
}
}
values = slapi_entry_attr_get_charray(e, "nsslapd-attribute");
if (values != NULL) {
int n = 0;
int i = 0;
slapi_log_err(SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, "retrocl_start - nsslapd-attribute:\n");
for (n = 0; values && values[n]; n++) {
slapi_log_err(SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, "retrocl_start - %s\n", values[n]);
}
retrocl_nattributes = n;
retrocl_attributes = (char **)slapi_ch_calloc(n + 1, sizeof(char *));
retrocl_aliases = (char **)slapi_ch_calloc(n + 1, sizeof(char *));
slapi_log_err(SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, "retrocl_start - Attributes:\n");
for (i = 0; i < n; i++) {
char *value = values[i];
size_t length = strlen(value);
char *pos = strchr(value, ':');
if (pos == NULL) {
retrocl_attributes[i] = slapi_ch_strdup(value);
retrocl_aliases[i] = NULL;
slapi_log_err(SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, " - %s\n",
retrocl_attributes[i]);
} else {
retrocl_attributes[i] = slapi_ch_malloc(pos - value + 1);
strncpy(retrocl_attributes[i], value, pos - value);
retrocl_attributes[i][pos - value] = '\0';
retrocl_aliases[i] = slapi_ch_malloc(value + length - pos);
strcpy(retrocl_aliases[i], pos + 1);
slapi_log_err(SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, " - %s [%s]\n",
retrocl_attributes[i], retrocl_aliases[i]);
}
}
slapi_ch_array_free(values);
}
retrocl_log_deleted = 0;
values = slapi_entry_attr_get_charray(e, "nsslapd-log-deleted");
if (values != NULL) {
if (values[1] != NULL) {
slapi_log_err(SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
"retrocl_start - Multiple values specified for attribute: nsslapd-log-deleted\n");
} else if (0 == strcasecmp(values[0], "on")) {
retrocl_log_deleted = 1;
} else if (strcasecmp(values[0], "off")) {
slapi_log_err(SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
"Iretrocl_start - nvalid value (%s) specified for attribute: nsslapd-log-deleted\n", values[0]);
}
slapi_ch_array_free(values);
}
return 0;
}
/*
* Check if an entry is in the configured scope.
* Return 1 if entry is in the scope, or 0 otherwise.
* For MODRDN the caller should check both the preop
* and postop entries. If we are moving out of, or
* into scope, we should record it.
*/
int
retrocl_entry_in_scope(Slapi_Entry *e)
{
Slapi_DN *sdn = slapi_entry_get_sdn(e);
if (e == NULL) {
return 1;
}
if (retrocl_excludes) {
int i = 0;
/* check the excludes */
while (retrocl_excludes[i]) {
if (slapi_sdn_issuffix(sdn, retrocl_excludes[i])) {
return 0;
}
i++;
}
}
if (retrocl_includes) {
int i = 0;
/* check the excludes */
while (retrocl_includes[i]) {
if (slapi_sdn_issuffix(sdn, retrocl_includes[i])) {
return 1;
}
i++;
}
return 0;
}
return 1;
}
/*
* Function: retrocl_stop
*
* Returns: 0
*
* Arguments: Pb
*
* Description: called when the server is shutting down
*
*/
static int
retrocl_stop(Slapi_PBlock *pb __attribute__((unused)))
{
int rc = 0;
int i = 0;
slapi_ch_array_free(retrocl_attributes);
retrocl_attributes = NULL;
slapi_ch_array_free(retrocl_aliases);
retrocl_aliases = NULL;
slapi_ch_array_free(retrocl_exclude_attrs);
retrocl_exclude_attrs = NULL;
while (retrocl_excludes && retrocl_excludes[i]) {
slapi_sdn_free(&retrocl_excludes[i]);
i++;
}
slapi_ch_free((void **)&retrocl_excludes);
i = 0;
while (retrocl_includes && retrocl_includes[i]) {
slapi_sdn_free(&retrocl_includes[i]);
i++;
}
slapi_ch_free((void **)&retrocl_includes);
retrocl_stop_trimming();
retrocl_be_changelog = NULL;
retrocl_forget_changenumbers();
PR_DestroyLock(retrocl_internal_lock);
retrocl_internal_lock = NULL;
slapi_destroy_rwlock(retrocl_cn_lock);
retrocl_cn_lock = NULL;
legacy_initialised = 0;
slapi_config_remove_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, "",
LDAP_SCOPE_BASE, "(objectclass=*)", retrocl_rootdse_search);
return rc;
}
/*
* Function: retrocl_plugin_init
*
* Returns: 0 on successs
*
* Arguments: Pb
*
* Description: main entry point for retrocl
*
*/
int
retrocl_plugin_init(Slapi_PBlock *pb)
{
int rc = 0;
int precedence = 0;
void *identity = NULL;
Slapi_Entry *plugin_entry = NULL;
int is_betxn = 0;
const char *plugintype = "postoperation";
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &identity);
PR_ASSERT(identity);
g_plg_identity[PLUGIN_RETROCL] = identity;
slapi_pblock_get(pb, SLAPI_PLUGIN_PRECEDENCE, &precedence);
if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &plugin_entry) == 0) &&
plugin_entry) {
is_betxn = slapi_entry_attr_get_bool(plugin_entry, "nsslapd-pluginbetxn");
}
if (!legacy_initialised) {
rc = slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01);
rc = slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&retrocldesc);
rc = slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN, (void *)retrocl_start);
rc = slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN, (void *)retrocl_stop);
if (is_betxn) {
plugintype = "betxnpostoperation";
}
rc = slapi_register_plugin_ext(plugintype, 1 /* Enabled */, "retrocl_postop_init", retrocl_postop_init, "Retrocl postoperation plugin", NULL, identity, precedence);
if (!is_betxn) {
rc = slapi_register_plugin_ext("internalpostoperation", 1 /* Enabled */, "retrocl_internalpostop_init", retrocl_internalpostop_init, "Retrocl internal postoperation plugin", NULL, identity, precedence);
}
retrocl_cn_lock = slapi_new_rwlock();
if (retrocl_cn_lock == NULL)
return -1;
retrocl_internal_lock = PR_NewLock();
if (retrocl_internal_lock == NULL)
return -1;
}
legacy_initialised = 1;
return rc;
}
/*
* Function: retrocl_attr_in_exclude_attrs
*
* Return 1 if attribute exists in the retrocl_exclude_attrs list, else return 0.
*
* Arguments: attribute string, attribute length.
*
* Description: Check if an attribute is in the global exclude attribute list.
*
*/
int
retrocl_attr_in_exclude_attrs(char *attr, int attrlen)
{
int i = 0;
if (attr && attrlen > 0 && retrocl_nexclude_attrs > 0) {
while (retrocl_exclude_attrs[i]) {
if (strncmp(retrocl_exclude_attrs[i], attr, attrlen) == 0) {
slapi_log_err(SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,"retrocl_attr_in_exclude_attrs - excluding attr (%s).\n", attr);
return 1;
}
i++;
}
}
return 0;
}