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 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
|
/** 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
/* cl5_test.c - changelog test cases */
#include "cl5_test.h"
#include "slapi-plugin.h"
#include "cl5.h"
#define REPLICA_ROOT "dc=example,dc=com" /* replica root */
#define OP_COUNT 4 /* number of ops generated at a time */
#define MOD_COUNT 5
#define VALUE_COUNT 5
#define ENTRY_COUNT 50
#define CL_DN "cn=changelog5,cn=config"
#define INSTANCE_ATTR "nsslapd-instancedir"
#define REPLICA_OC "nsds5Replica"
#define REPLICA_RDN "cn=replica"
static void testBasic();
static void testBackupRestore();
static void testIteration();
static void testPerformance();
static void testPerformanceMT();
static void testLDIF();
static void testAll();
static int configureChangelog();
static int configureReplica();
static int populateChangelogOp();
static int populateChangelog(int entryCount, CSN ***csnList);
static int processEntries(int entryCount, CSN **csnList);
static void clearCSNList(CSN ***csnList, int count);
static void threadMain(void *data);
static char *getBaseDir(const char *dir);
static LDAPMod **buildMods();
void
testChangelog(TestType type)
{
switch (type) {
case TEST_BASIC:
testBasic();
break;
case TEST_BACKUP_RESTORE:
testBackupRestore();
break;
case TEST_ITERATION:
testIteration();
break;
case TEST_PERFORMANCE:
testPerformance();
break;
case TEST_PERFORMANCE_MT:
testPerformanceMT();
break;
case TEST_LDIF:
testLDIF();
break;
case TEST_ALL:
testAll();
break;
default:
printf("Taste case %d is not supported\n", type);
}
}
/* tests Open/Close, normal recovery, read/write/remove
of an entry */
static void
testBasic()
{
int rc = 0;
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "Starting basic test ...\n");
/* ONREPL - we can't run the tests from the startup code because
operations can't be issued until all plugins are started. So,
instead, we do it when changelog is created
rc = configureChangelog (); */
if (rc == 0) {
rc = configureReplica();
if (rc == 0) {
rc = populateChangelogOp();
}
}
if (rc == 0)
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl,
"Basic test completed successfully\n");
else
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl,
"Basic test failed\n");
}
static void
testBackupRestore()
{
char *dir;
int rc = -1;
char *baseDir;
char bkDir[MAXPATHLEN];
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "Starting backup and recovery test ...\n");
dir = cl5GetLdifDir(NULL);
if (dir) {
baseDir = getBaseDir(dir);
PR_snprintf(bkDir, sizeof(bkDir), "%s/clbackup", baseDir);
slapi_ch_free((void **)&baseDir);
rc = cl5Backup(bkDir, NULL);
if (rc == CL5_SUCCESS) {
cl5Close();
rc = cl5Restore(dir, bkDir, NULL);
if (rc == CL5_SUCCESS)
rc = cl5Open();
/* PR_RmDir (bkDir);*/
}
}
if (rc == CL5_SUCCESS)
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl,
"Backup and Restore test completed successfully\n");
else
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl,
"Backup and Restore test failed\n");
}
static void
testIteration()
{
Slapi_DN *r_root;
Replica *r;
char *replGen;
RUV *ruv;
CL5ReplayIterator *it = NULL;
slapi_operation_parameters op;
int rc;
int i;
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "Starting iteration test ...\n");
/* get replica object */
r_root = slapi_sdn_new_dn_byval(REPLICA_ROOT);
r = replica_get_replica_from_dn(r_root);
slapi_sdn_free(&r_root);
if (r == NULL) {
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "replica is not configured for (%s)\n",
REPLICA_ROOT);
return;
}
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "Starting first iteration pass ...\n");
/* configure empty consumer ruv */
replGen = replica_get_generation(r);
ruv_init_new(replGen, 0, NULL, &ruv);
/* create replay iterator */
rc = cl5CreateReplayIterator(r, ruv, &it);
if (it) {
i = 0;
while ((rc = cl5GetNextOperationToReplay(it, &op)) == CL5_SUCCESS) {
ruv_set_csns(ruv, op.csn, NULL);
operation_parameters_done(&op);
i++;
}
}
if (it)
cl5DestroyReplayIterator(&it);
if (rc == CL5_NOTFOUND) {
if (i == 0) /* success */
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "First iteration pass completed "
"successfully: no changes to replay\n");
else /* incorrect number of entries traversed */
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "First iteration pass failed: "
"traversed %d entries; expected none\n",
i);
} else /* general error */
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "First iteration pass failed\n");
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "Starting second iteration pass ...\n");
/* add some entries */
populateChangelogOp();
/* create replay iterator */
rc = cl5CreateReplayIterator(r, ruv, &it);
if (it) {
i = 0;
while ((rc = cl5GetNextOperationToReplay(it, &op)) == CL5_SUCCESS) {
ruv_set_csns(ruv, op.csn, NULL);
operation_parameters_done(&op);
i++;
}
}
if (it)
cl5DestroyReplayIterator(&it);
if (rc == CL5_NOTFOUND) {
if (i == OP_COUNT) /* success */
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "Second iteration pass completed "
"successfully: %d entries traversed\n",
i);
else /* incorrect number of entries traversed */
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "Second iteration pass failed: "
"traversed %d entries; expected %d\n",
i, OP_COUNT);
} else /* general error */
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "Second iteration pass failed\n");
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "Starting third iteration pass ...\n");
/* add more entries */
populateChangelogOp();
/* create replay iterator */
rc = cl5CreateReplayIterator(r, ruv, &it);
if (it) {
i = 0;
while ((rc = cl5GetNextOperationToReplay(it, &op)) == CL5_SUCCESS) {
ruv_set_csns(ruv, op.csn, NULL);
operation_parameters_done(&op);
i++;
}
}
if (it)
cl5DestroyReplayIterator(&it);
if (rc == CL5_NOTFOUND) {
if (i == OP_COUNT) /* success */
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "Third iteration pass completed "
"successfully: %d entries traversed\n",
i);
else /* incorrect number of entries traversed */
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "Third iteration pass failed: "
"traversed %d entries; expected %d\n",
i, OP_COUNT);
} else /* general error */
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "Second iteration pass failed\n");
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "Iteration test is complete\n");
ruv_destroy(&ruv);
slapi_ch_free((void **)&replGen);
}
static void
testPerformance()
{
PRTime starttime, endtime, totaltime;
int entryCount = 5000;
CSN **csnList = NULL;
int rc;
starttime = PR_Now();
rc = populateChangelog(entryCount, &csnList);
endtime = PR_Now();
totaltime = (endtime - starttime) / 1000; /* ms */
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "Write performance:\n"
"entry count - %d, total time - %ldms\n"
"latency = %d msec\nthroughput = %d entry/sec\n",
entryCount, totaltime,
totaltime / entryCount, entryCount * 1000 / totaltime);
starttime = endtime;
rc = processEntries(entryCount, csnList);
endtime = PR_Now();
totaltime = (endtime - starttime) / 1000; /* ms */
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "Read performance:\n"
"entry count - %d, total time - %ld\n"
"latency = %d msec\nthroughput = %d entry/sec\n",
entryCount, totaltime,
totaltime / entryCount, entryCount * 1000 / totaltime);
clearCSNList(&csnList, entryCount);
}
static int threadsLeft;
static void
testPerformanceMT()
{
PRTime starttime, endtime, totaltime;
int entryCount = 200;
int threadCount = 10;
int entryTotal;
int i;
PRIntervalTime interval;
interval = PR_MillisecondsToInterval(100);
threadsLeft = threadCount * 2;
entryTotal = threadCount * entryCount;
starttime = PR_Now();
for (i = 0; i < threadCount; i++) {
PR_CreateThread(PR_USER_THREAD, threadMain, (void *)&entryCount,
PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
PR_UNJOINABLE_THREAD, 0);
}
while (threadsLeft > 5)
DS_Sleep(interval);
endtime = PR_Now();
totaltime = (endtime - starttime) / 1000; /* ms */
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "Write performance:\n"
"entry count - %d, total time - %ld\n"
"latency = %d msec per entry\nthroughput = %d entry/sec\n",
entryCount, totaltime,
totaltime / entryTotal, entryTotal * 1000 / totaltime);
starttime = endtime;
while (threadsLeft != 0)
DS_Sleep(interval);
endtime = PR_Now();
totaltime = (endtime - starttime) / 1000; /* ms */
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "Read performance:\n"
"entry count - %d, total time - %ld\n"
"latency = %d msec per entry\nthroughput = %d entry/sec\n",
entryCount, totaltime,
totaltime / entryTotal, entryTotal * 1000 / totaltime);
}
static void
testLDIF()
{
char *clDir = cl5GetLdifDir(NULL);
int rc;
char *baseDir;
char ldifFile[MAXPATHLEN];
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "Starting LDIF test ...\n");
baseDir = getBaseDir(clDir);
PR_snprintf(ldifFile, sizeof(ldifFile), "%s/cl5.ldif", baseDir);
slapi_ch_free((void **)&baseDir);
rc = populateChangelog(ENTRY_COUNT, NULL);
if (rc == CL5_SUCCESS) {
rc = cl5ExportLDIF(ldifFile, NULL);
if (rc == CL5_SUCCESS) {
cl5Close();
rc = cl5ImportLDIF(clDir, ldifFile, NULL);
if (rc == CL5_SUCCESS)
cl5Open();
}
}
PR_Delete(ldifFile);
if (rc == CL5_SUCCESS)
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl,
"LDIF test completed successfully\n");
else
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "LDIF test failed\n");
}
static void
testAll()
{
testBasic();
testIteration();
testBackupRestore();
testLDIF();
}
static int
populateChangelog(int entryCount, CSN ***csnList)
{
CSN *csn;
int i;
slapi_operation_parameters op;
int rc;
char *uniqueid;
if (csnList) {
(*csnList) = (CSN **)slapi_ch_calloc(entryCount, sizeof(CSN *));
}
/* generate entries */
for (i = 0; i < entryCount; i++) {
/* ONREPL need to get replica object
rc = csnGetNewCSNForRepl (&csn);
if (rc != CL5_SUCCESS) */
return -1;
if (csnList)
(*csnList)[i] = csn_dup(csn);
memset(&op, 0, sizeof(op));
op.csn = csn;
slapi_uniqueIDGenerateString(&uniqueid);
op.target_address.uniqueid = uniqueid;
op.target_address.dn = slapi_ch_strdup("cn=entry,dc=example,dc=com");
if (i % 5 == 0) {
op.operation_type = SLAPI_OPERATION_MODRDN;
op.p.p_modrdn.modrdn_deloldrdn = 1;
op.p.p_modrdn.modrdn_newrdn = slapi_ch_strdup("cn=entry2,dc=example,dc=com");
op.p.p_modrdn.modrdn_newsuperior_address.dn = NULL;
op.p.p_modrdn.modrdn_newsuperior_address.uniqueid = NULL;
op.p.p_modrdn.modrdn_mods = buildMods();
} else if (i % 4 == 0) {
op.operation_type = SLAPI_OPERATION_DELETE;
} else if (i % 3 == 0) {
op.operation_type = SLAPI_OPERATION_ADD;
op.p.p_add.target_entry = slapi_entry_alloc();
slapi_entry_set_dn(op.p.p_add.target_entry, slapi_ch_strdup(op.target_address.dn));
slapi_entry_set_uniqueid(op.p.p_add.target_entry, slapi_ch_strdup(op.target_address.uniqueid));
slapi_entry_attr_set_charptr(op.p.p_add.target_entry, "objectclass", "top");
slapi_entry_attr_set_charptr(op.p.p_add.target_entry, "cn", "entry");
} else {
op.operation_type = SLAPI_OPERATION_MODIFY;
op.p.p_modify.modify_mods = buildMods();
}
/* ONREPL rc = cl5WriteOperation (&op, 1);*/
operation_parameters_done(&op);
if (rc != CL5_SUCCESS)
return -1;
}
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl,
"Successfully populated changelog with %d entries\n", entryCount);
return 0;
}
static int
processEntries(int entryCount, CSN **csnList)
{
int i;
int rc = 0;
slapi_operation_parameters op;
for (i = 0; i < entryCount; i++) {
memset(&op, 0, sizeof(op));
op.csn = csn_dup(csnList[i]);
/* rc = cl5GetOperation (&op);*/
if (rc != CL5_SUCCESS)
return -1;
operation_parameters_done(&op);
}
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl,
"Successfully read %d entries from the changelog\n", entryCount);
return 0;
}
void
clearCSNList(CSN ***csnList, int count)
{
int i;
for (i = 0; i < count; i++) {
csn_free(&((*csnList)[i]));
}
slapi_ch_free((void **)csnList);
}
static void
threadMain(void *data)
{
int entryCount = *(int *)data;
CSN **csnList;
populateChangelog(entryCount, &csnList);
PR_AtomicDecrement(&threadsLeft);
processEntries(entryCount, csnList);
PR_AtomicDecrement(&threadsLeft);
clearCSNList(&csnList, entryCount);
}
static char *
getBaseDir(const char *dir)
{
char *baseDir = slapi_ch_strdup(dir);
char *ch;
ch = &(baseDir[strlen(dir) - 2]);
while (ch >= baseDir && *ch != '\\' && *ch != '/')
ch--;
if (ch >= baseDir) {
*ch = '\0';
}
return baseDir;
}
static LDAPMod **
buildMods()
{
Slapi_Mods smods;
Slapi_Mod smod;
LDAPMod **mods;
struct berval bv;
int j, k;
slapi_mods_init(&smods, MOD_COUNT);
for (j = 0; j < MOD_COUNT; j++) {
slapi_mod_init(&smod, VALUE_COUNT);
slapi_mod_set_operation(&smod, LDAP_MOD_ADD | LDAP_MOD_BVALUES);
slapi_mod_set_type(&smod, "attr");
for (k = 0; k < VALUE_COUNT; k++) {
bv.bv_val = "bvalue";
bv.bv_len = strlen(bv.bv_val) + 1;
slapi_mod_add_value(&smod, &bv);
}
slapi_mods_add_smod(&smods, &smod);
/* ONREPL slapi_mod_done (&smod); */
}
mods = slapi_mods_get_ldapmods_passout(&smods);
slapi_mods_done(&smods);
return mods;
}
/* Format:
dn: cn=changelog5,cn=config
objectclass: top
objectclass: extensibleObject
cn: changelog5
nsslapd-changelogDir: d:/netscape/server4/slapd-elf/cl5 */
static int
configureChangelog()
{
Slapi_PBlock *pb = slapi_pblock_new();
Slapi_Entry *e = slapi_entry_alloc();
int rc;
char *attrs[] = {INSTANCE_ATTR, NULL};
Slapi_Entry **entries;
char cl_dir[256];
char *str = NULL;
/* set changelog dn */
slapi_entry_set_dn(e, slapi_ch_strdup(CL_DN));
/* set object classes */
slapi_entry_add_string(e, "objectclass", "top");
slapi_entry_add_string(e, "objectclass", "extensibleObject");
/* get directory instance dir */
slapi_search_internal_set_pb(pb, "cn=config", LDAP_SCOPE_BASE, "objectclass=*",
attrs, 0, NULL, NULL,
repl_get_plugin_identity(PLUGIN_MULTISUPPLIER_REPLICATION), 0);
slapi_search_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
if (rc != LDAP_SUCCESS) {
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "failed to get server instance "
"directory; LDAP error - %d\n",
rc);
rc = -1;
goto done;
}
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
str = (char*)slapi_entry_attr_get_ref(entries[0], INSTANCE_ATTR);
PR_snprintf(cl_dir, sizeof(cl_dir), "%s/%s", str, "cl5db");
slapi_entry_add_string(e, CONFIG_CHANGELOG_DIR_ATTRIBUTE, cl_dir);
slapi_free_search_results_internal(pb);
slapi_pblock_destroy(pb);
pb = slapi_pblock_new();
slapi_add_entry_internal_set_pb(pb, e, NULL,
repl_get_plugin_identity(PLUGIN_MULTISUPPLIER_REPLICATION), 0);
slapi_add_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
if (rc != LDAP_SUCCESS) {
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "failed to add changelog "
"configuration entry; LDAP error - %d\n",
rc);
rc = -1;
} else
rc = 0;
done:
slapi_pblock_destroy(pb);
return rc;
}
#define DN_SIZE 1024
/* Format:
dn: cn=replica,cn="o=NetscapeRoot",cn= mapping tree,cn=config
objectclass: top
objectclass: nsds5Replica
objectclass: extensibleObject
nsds5ReplicaRoot: o=NetscapeRoot
nsds5ReplicaId: 2
nsds5flags: 1
cn: replica
*/
static int
configureReplica()
{
Slapi_PBlock *pb = slapi_pblock_new();
Slapi_Entry *e = slapi_entry_alloc();
int rc;
char dn[DN_SIZE];
/* set changelog dn */
PR_snprintf(dn, sizeof(dn), "%s,cn=\"%s\",%s", REPLICA_RDN, REPLICA_ROOT,
slapi_get_mapping_tree_config_root());
slapi_entry_set_dn(e, slapi_ch_strdup(dn));
/* set object classes */
slapi_entry_add_string(e, "objectclass", "top");
slapi_entry_add_string(e, "objectclass", REPLICA_OC);
slapi_entry_add_string(e, "objectclass", "extensibleObject");
/* set other attributes */
slapi_entry_add_string(e, attr_replicaRoot, REPLICA_ROOT);
slapi_entry_add_string(e, attr_replicaId, "1");
slapi_entry_add_string(e, attr_flags, "1");
slapi_add_entry_internal_set_pb(pb, e, NULL,
repl_get_plugin_identity(PLUGIN_MULTISUPPLIER_REPLICATION), 0);
slapi_add_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
if (rc != LDAP_SUCCESS) {
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "failed to add replica for (%s) "
"configuration entry; LDAP error - %d\n",
REPLICA_ROOT, rc);
rc = -1;
} else
rc = 0;
slapi_pblock_destroy(pb);
return rc;
}
/* generates one of each ldap operations */
static int
populateChangelogOp()
{
Slapi_PBlock *pb = slapi_pblock_new();
Slapi_Entry *e = slapi_entry_alloc();
int rc;
char dn[DN_SIZE], newrdn[64];
LDAPMod *mods[2];
Slapi_Mod smod;
struct berval bv;
time_t cur_time;
/* add entry */
cur_time = time(NULL);
PR_snprintf(dn, sizeof(dn), "cn=%s,%s", ctime(&cur_time), REPLICA_ROOT);
slapi_entry_set_dn(e, slapi_ch_strdup(dn));
slapi_entry_add_string(e, "objectclass", "top");
slapi_entry_add_string(e, "objectclass", "extensibleObject");
slapi_entry_add_string(e, "mail", "jsmith@netscape.com");
slapi_add_entry_internal_set_pb(pb, e, NULL,
repl_get_plugin_identity(PLUGIN_MULTISUPPLIER_REPLICATION), 0);
slapi_add_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
slapi_pblock_destroy(pb);
if (rc != LDAP_SUCCESS) {
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "failed to add entry (%s); "
"LDAP error - %d\n",
dn, rc);
return -1;
}
/* modify entry */
pb = slapi_pblock_new();
slapi_mod_init(&smod, 1);
slapi_mod_set_type(&smod, "mail");
slapi_mod_set_operation(&smod, LDAP_MOD_REPLACE | LDAP_MOD_BVALUES);
bv.bv_val = "jsmith@aol.com";
bv.bv_len = strlen(bv.bv_val);
slapi_mod_add_value(&smod, &bv);
mods[0] = (LDAPMod *)slapi_mod_get_ldapmod_byref(&smod);
mods[1] = NULL;
slapi_modify_internal_set_pb(pb, dn, mods, NULL, NULL,
repl_get_plugin_identity(PLUGIN_MULTISUPPLIER_REPLICATION), 0);
slapi_modify_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
slapi_mod_done(&smod);
slapi_pblock_destroy(pb);
if (rc != LDAP_SUCCESS) {
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "failed to modify entry (%s); "
"LDAP error - %d\n",
dn, rc);
return -1;
}
/* rename entry */
pb = slapi_pblock_new();
cur_time = time(NULL);
PR_snprintf(newrdn, sizeof(newrdn), "cn=renamed%s", ctime(&cur_time));
slapi_rename_internal_set_pb_ext(pb, dn, newrdn, NULL, 1, NULL, NULL,
repl_get_plugin_identity(PLUGIN_MULTISUPPLIER_REPLICATION), 0);
slapi_modrdn_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
slapi_pblock_destroy(pb);
if (rc != LDAP_SUCCESS) {
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "failed to rename entry (%s); "
"LDAP error - %d\n",
dn, rc);
return -1;
}
/* delete the entry */
pb = slapi_pblock_new();
PR_snprintf(dn, sizeof(dn), "%s,%s", newrdn, REPLICA_ROOT);
slapi_delete_internal_set_pb(pb, dn, NULL, NULL,
repl_get_plugin_identity(PLUGIN_MULTISUPPLIER_REPLICATION), 0);
slapi_delete_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
slapi_pblock_destroy(pb);
if (rc != LDAP_SUCCESS) {
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl, "failed to delete entry (%s); "
"LDAP error - %d\n",
dn, rc);
return -1;
}
return 0;
}
|