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 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468
|
/** BEGIN COPYRIGHT BLOCK
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2021 Red Hat, Inc.
* Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
* 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
/*
* repl5_consumer.c - consumer plugin functions
*/
/*
* LDAP Data Model Constraints...
*
* 1) Parent entry must exist.
* 2) RDN must be unique.
* 3) RDN components must be attribute values.
* 4) Must conform to the schema constraints - Single Valued Attributes.
* 5) Must conform to the schema constraints - Required Attributes.
* 6) Must conform to the schema constraints - No Extra Attributes.
* 7) Duplicate attribute values are not permited.
* 8) Cycle in the ancestry graph not permitted.
*
* Update Resolution Procedures...
* 1) ...
* 2) Add the UniqueID to the RDN.
* 3) Remove the not present RDN component.
* Use the UniqueID if the RDN becomes empty.
* 4) Keep the most recent value.
* 5) Ignore.
* 6) Ignore.
* 7) Keep the largest CSN for the duplicate value.
* 8) Don't check for this.
*/
#include "repl5.h"
#include "cl5_api.h"
#include "urp.h"
#include "csnpl.h"
static char *local_purl = NULL;
static char *purl_attrs[] = {"nsslapd-localhost", "nsslapd-port", "nsslapd-secureport", NULL};
/* Forward declarations */
static void copy_operation_parameters(Slapi_PBlock *pb);
static int write_changelog_and_ruv(Slapi_PBlock *pb);
static int process_postop(Slapi_PBlock *pb);
static int cancel_opcsn(Slapi_PBlock *pb);
static int ruv_tombstone_op(Slapi_PBlock *pb);
static PRBool process_operation(Slapi_PBlock *pb, const CSN *csn);
static PRBool is_mmr_replica(Slapi_PBlock *pb);
static const char *replica_get_purl_for_op(const Replica *r, Slapi_PBlock *pb, const CSN *opcsn);
/*
* XXXggood - what to do if both ssl and non-ssl ports available? How
* do you know which to use? Offer a choice in replication config?
*/
int
multisupplier_set_local_purl()
{
int rc = 0;
Slapi_Entry **entries;
Slapi_PBlock *pb = NULL;
pb = slapi_pblock_new();
slapi_search_internal_set_pb(pb, "cn=config", LDAP_SCOPE_BASE,
"objectclass=*", purl_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 != 0) {
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "multisupplier_set_local_purl - "
"unable to read server configuration: error %d\n",
rc);
} else {
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
if (NULL == entries || NULL == entries[0]) {
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "multisupplier_set_local_purl - "
"Server configuration missing\n");
rc = -1;
} else {
char *host = (char *)slapi_entry_attr_get_ref(entries[0], "nsslapd-localhost");
char *port = (char *)slapi_entry_attr_get_ref(entries[0], "nsslapd-port");
char *sslport = (char *)slapi_entry_attr_get_ref(entries[0], "nsslapd-secureport");
if (host == NULL || ((port == NULL && sslport == NULL))) {
slapi_log_err(SLAPI_LOG_WARNING, repl_plugin_name,
"multisupplier_set_local_purl - Invalid server "
"configuration\n");
} else {
if (slapi_is_ipv6_addr(host)) {
/* need to put brackets around the ipv6 address */
local_purl = slapi_ch_smprintf("ldap://[%s]:%s", host, port);
} else {
local_purl = slapi_ch_smprintf("ldap://%s:%s", host, port);
}
}
}
}
slapi_free_search_results_internal(pb);
slapi_pblock_destroy(pb);
return rc;
}
const char *
multisupplier_get_local_purl()
{
return local_purl;
}
/* ================= Multisupplier Pre-Op Plugin Points ================== */
int
multisupplier_preop_bind(Slapi_PBlock *pb __attribute__((unused)))
{
return 0;
}
int
multisupplier_preop_add(Slapi_PBlock *pb)
{
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
slapi_pblock_get(pb, SLAPI_OPERATION, &op);
if (!is_mmr_replica(pb)) {
copy_operation_parameters(pb);
return SLAPI_PLUGIN_SUCCESS;
}
is_replicated_operation = operation_is_flag_set(op, OP_FLAG_REPLICATED);
is_fixup_operation = operation_is_flag_set(op, OP_FLAG_REPL_FIXUP);
if (is_replicated_operation) {
if (!is_fixup_operation) {
LDAPControl **ctrlp;
char sessionid[REPL_SESSION_ID_SIZE];
get_repl_session_id(pb, sessionid, NULL);
slapi_pblock_get(pb, SLAPI_REQCONTROLS, &ctrlp);
if (NULL != ctrlp) {
CSN *csn = NULL;
char *target_uuid = NULL;
char *superior_uuid = NULL;
int drc = decode_NSDS50ReplUpdateInfoControl(ctrlp, &target_uuid, &superior_uuid, &csn, NULL /* modrdn_mods */);
if (-1 == drc) {
slapi_log_err(SLAPI_LOG_ERR, REPLICATION_SUBSYSTEM,
"multisupplier_preop_add - %s An error occurred while decoding the replication update "
"control - Add\n",
sessionid);
} else if (1 == drc) {
/*
* For add operations, we just set the operation csn. The entry's
* uniqueid should already be an attribute of the replicated entry.
*/
struct slapi_operation_parameters *op_params;
/* we don't want to process replicated operations with csn smaller
than the corresponding csn in the consumer's ruv */
if (!process_operation(pb, csn)) {
slapi_send_ldap_result(pb, LDAP_SUCCESS, 0,
"replication operation not processed, replica unavailable "
"or csn ignored",
0, 0);
csn_free(&csn);
slapi_ch_free((void **)&target_uuid);
slapi_ch_free((void **)&superior_uuid);
return SLAPI_PLUGIN_FAILURE;
}
operation_set_csn(op, csn);
slapi_pblock_set(pb, SLAPI_TARGET_UNIQUEID, target_uuid);
slapi_pblock_get(pb, SLAPI_OPERATION_PARAMETERS, &op_params);
/* JCMREPL - Complain if there's no superior uuid */
op_params->p.p_add.parentuniqueid = superior_uuid; /* JCMREPL - Not very elegant */
/* JCMREPL - When do these things get free'd? */
if (target_uuid != NULL) {
/*
* Make sure that the Unique Identifier in the Control is the
* same as the one in the entry.
*/
Slapi_Entry *addentry;
const char *entry_uuid;
slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &addentry);
entry_uuid = slapi_entry_attr_get_ref(addentry, SLAPI_ATTR_UNIQUEID);
if (entry_uuid == NULL) {
/* Odd that the entry doesn't have a Unique Identifier. But, we can fix it. */
slapi_entry_set_uniqueid(addentry, slapi_ch_strdup(target_uuid)); /* JCMREPL - strdup EVIL! There should be a uuid dup function. */
} else {
if (strcasecmp(entry_uuid, target_uuid) != 0) {
slapi_log_err(SLAPI_LOG_WARNING, REPLICATION_SUBSYSTEM,
"multisupplier_preop_add - %s Replicated Add received with Control_UUID=%s and Entry_UUID=%s.\n",
sessionid, target_uuid, entry_uuid);
}
}
}
}
} else {
PR_ASSERT(0); /* JCMREPL - A Replicated Operation with no Repl Baggage control... What does that mean? */
}
} else {
/* Replicated & Fixup Operation */
}
} else {
slapi_operation_set_csngen_handler(op, (void *)replica_generate_next_csn);
}
copy_operation_parameters(pb);
return SLAPI_PLUGIN_SUCCESS;
}
int
multisupplier_preop_delete(Slapi_PBlock *pb)
{
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
slapi_pblock_get(pb, SLAPI_OPERATION, &op);
if (!is_mmr_replica(pb)) {
copy_operation_parameters(pb);
return SLAPI_PLUGIN_SUCCESS;
}
is_replicated_operation = operation_is_flag_set(op, OP_FLAG_REPLICATED);
is_fixup_operation = operation_is_flag_set(op, OP_FLAG_REPL_FIXUP);
if (is_replicated_operation) {
if (!is_fixup_operation) {
LDAPControl **ctrlp;
char sessionid[REPL_SESSION_ID_SIZE];
get_repl_session_id(pb, sessionid, NULL);
slapi_pblock_get(pb, SLAPI_REQCONTROLS, &ctrlp);
if (NULL != ctrlp) {
CSN *csn = NULL;
char *target_uuid = NULL;
int drc = decode_NSDS50ReplUpdateInfoControl(ctrlp, &target_uuid, NULL, &csn, NULL /* modrdn_mods */);
if (-1 == drc) {
slapi_log_err(SLAPI_LOG_ERR, REPLICATION_SUBSYSTEM,
"multisupplier_preop_delete - %s An error occurred while decoding the replication update "
"control - Delete\n",
sessionid);
} else if (1 == drc) {
/* we don't want to process replicated operations with csn smaller
than the corresponding csn in the consumer's ruv */
if (!process_operation(pb, csn)) {
slapi_send_ldap_result(pb, LDAP_SUCCESS, 0,
"replication operation not processed, replica unavailable "
"or csn ignored",
0, 0);
slapi_log_err(SLAPI_LOG_REPL, REPLICATION_SUBSYSTEM,
"multisupplier_preop_delete - %s replication operation not processed, replica unavailable "
"or csn ignored\n",
sessionid);
csn_free(&csn);
slapi_ch_free((void **)&target_uuid);
return SLAPI_PLUGIN_FAILURE;
}
/*
* For delete operations, we pass the uniqueid of the deleted entry
* to the backend and let it sort out which entry to really delete.
* We also set the operation csn.
*/
operation_set_csn(op, csn);
slapi_pblock_set(pb, SLAPI_TARGET_UNIQUEID, target_uuid);
}
} else {
PR_ASSERT(0); /* JCMREPL - A Replicated Operation with no Repl Baggage control... What does that mean? */
}
} else {
/* Replicated & Fixup Operation */
}
} else {
slapi_operation_set_csngen_handler(op, (void *)replica_generate_next_csn);
}
copy_operation_parameters(pb);
slapi_operation_set_replica_attr_handler(op, (void *)replica_get_attr);
return SLAPI_PLUGIN_SUCCESS;
}
int
multisupplier_preop_modify(Slapi_PBlock *pb)
{
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
slapi_pblock_get(pb, SLAPI_OPERATION, &op);
if (!is_mmr_replica(pb)) {
copy_operation_parameters(pb);
return SLAPI_PLUGIN_SUCCESS;
}
is_replicated_operation = operation_is_flag_set(op, OP_FLAG_REPLICATED);
is_fixup_operation = operation_is_flag_set(op, OP_FLAG_REPL_FIXUP);
if (is_replicated_operation) {
if (!is_fixup_operation) {
LDAPControl **ctrlp;
char sessionid[REPL_SESSION_ID_SIZE];
get_repl_session_id(pb, sessionid, NULL);
slapi_pblock_get(pb, SLAPI_REQCONTROLS, &ctrlp);
if (NULL != ctrlp) {
CSN *csn = NULL;
char *target_uuid = NULL;
int drc = decode_NSDS50ReplUpdateInfoControl(ctrlp, &target_uuid, NULL, &csn, NULL /* modrdn_mods */);
if (-1 == drc) {
slapi_log_err(SLAPI_LOG_ERR, REPLICATION_SUBSYSTEM,
"multisupplier_preop_modify - %s An error occurred while decoding the replication update "
"control- Modify\n",
sessionid);
} else if (1 == drc) {
/* we don't want to process replicated operations with csn smaller
than the corresponding csn in the consumer's ruv */
if (!process_operation(pb, csn)) {
slapi_send_ldap_result(pb, LDAP_SUCCESS, 0,
"replication operation not processed, replica unavailable "
"or csn ignored",
0, 0);
slapi_log_err(SLAPI_LOG_REPL, REPLICATION_SUBSYSTEM,
"multisupplier_preop_modify - %s replication operation not processed, replica unavailable "
"or csn ignored\n",
sessionid);
csn_free(&csn);
slapi_ch_free((void **)&target_uuid);
return SLAPI_PLUGIN_FAILURE;
}
/*
* For modify operations, we pass the uniqueid of the modified entry
* to the backend and let it sort out which entry to really modify.
* We also set the operation csn.
*/
operation_set_csn(op, csn);
slapi_pblock_set(pb, SLAPI_TARGET_UNIQUEID, target_uuid);
}
} else {
/* PR_ASSERT(0); JCMREPL - A Replicated Operation with no Repl Baggage control... What does that mean? */
/*
* This could be RI plugin responding to a replicated update from AD or some other supplier that is not
* using the RI plugin, so don't PR_ASSERT here. This only happens if we configure the RI plugin with
* "nsslapd-pluginAllowReplUpdates: on", also the RI plugin only issues "modifies".
*/
}
} else {
/* Replicated & Fixup Operation */
}
} else {
slapi_operation_set_csngen_handler(op, (void *)replica_generate_next_csn);
}
copy_operation_parameters(pb);
return SLAPI_PLUGIN_SUCCESS;
}
int
multisupplier_preop_modrdn(Slapi_PBlock *pb)
{
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
slapi_pblock_get(pb, SLAPI_OPERATION, &op);
if (!is_mmr_replica(pb)) {
copy_operation_parameters(pb);
return SLAPI_PLUGIN_SUCCESS;
}
is_replicated_operation = operation_is_flag_set(op, OP_FLAG_REPLICATED);
is_fixup_operation = operation_is_flag_set(op, OP_FLAG_REPL_FIXUP);
if (is_replicated_operation) {
if (!is_fixup_operation) {
LDAPControl **ctrlp;
char sessionid[REPL_SESSION_ID_SIZE];
get_repl_session_id(pb, sessionid, NULL);
slapi_pblock_get(pb, SLAPI_REQCONTROLS, &ctrlp);
if (NULL != ctrlp) {
CSN *csn = NULL;
char *target_uuid = NULL;
char *newsuperior_uuid = NULL;
LDAPMod **modrdn_mods = NULL;
int drc = decode_NSDS50ReplUpdateInfoControl(ctrlp, &target_uuid, &newsuperior_uuid,
&csn, &modrdn_mods);
if (-1 == drc) {
slapi_log_err(SLAPI_LOG_ERR, REPLICATION_SUBSYSTEM,
"multisupplier_preop_modrdn - %s An error occurred while decoding the replication update "
"control - ModRDN\n",
sessionid);
} else if (1 == drc) {
/*
* For modrdn operations, we pass the uniqueid of the entry being
* renamed to the backend and let it sort out which entry to really
* rename. We also set the operation csn, and if the newsuperior_uuid
* was sent, we decode that as well.
*/
struct slapi_operation_parameters *op_params;
/* we don't want to process replicated operations with csn smaller
than the corresponding csn in the consumer's ruv */
if (!process_operation(pb, csn)) {
slapi_send_ldap_result(pb, LDAP_SUCCESS, 0,
"replication operation not processed, replica unavailable "
"or csn ignored",
0, 0);
csn_free(&csn);
slapi_ch_free((void **)&target_uuid);
slapi_ch_free((void **)&newsuperior_uuid);
ldap_mods_free(modrdn_mods, 1);
return SLAPI_PLUGIN_FAILURE;
}
operation_set_csn(op, csn);
slapi_pblock_set(pb, SLAPI_TARGET_UNIQUEID, target_uuid);
slapi_pblock_get(pb, SLAPI_OPERATION_PARAMETERS, &op_params);
op_params->p.p_modrdn.modrdn_newsuperior_address.uniqueid = newsuperior_uuid; /* JCMREPL - Not very elegant */
}
/*
* The replicated modrdn operation may also contain a sequence
* that contains side effects of the modrdn operation, e.g. the
* modifiersname and modifytimestamp are updated.
*/
if (NULL != modrdn_mods) {
LDAPMod **mods;
Slapi_Mods smods;
int i;
slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &mods);
slapi_mods_init_passin(&smods, mods);
for (i = 0; NULL != modrdn_mods[i]; i++) {
slapi_mods_add_ldapmod(&smods, modrdn_mods[i]); /* Does not copy mod */
}
mods = slapi_mods_get_ldapmods_passout(&smods);
slapi_pblock_set(pb, SLAPI_MODIFY_MODS, mods);
slapi_mods_done(&smods);
slapi_ch_free((void **)&modrdn_mods); /* Free container only - contents are referred to by array "mods" */
}
} else {
PR_ASSERT(0); /* JCMREPL - A Replicated Operation with no Repl Baggage control... What does that mean? */
}
} else {
/* Replicated & Fixup Operation */
}
} else {
slapi_operation_set_csngen_handler(op, (void *)replica_generate_next_csn);
}
copy_operation_parameters(pb);
return SLAPI_PLUGIN_SUCCESS;
}
int
multisupplier_preop_search(Slapi_PBlock *pb __attribute__((unused)))
{
return SLAPI_PLUGIN_SUCCESS;
}
int
multisupplier_preop_compare(Slapi_PBlock *pb __attribute__((unused)))
{
return SLAPI_PLUGIN_SUCCESS;
}
int
multisupplier_ruv_search(Slapi_PBlock *pb)
{
Slapi_Entry *e, *e_alt;
Slapi_DN *suffix_sdn;
Slapi_Operation *operation;
slapi_pblock_get(pb, SLAPI_SEARCH_ENTRY_ORIG, &e);
slapi_pblock_get(pb, SLAPI_OPERATION, &operation);
if ((e == NULL) || (operation == NULL))
return SLAPI_PLUGIN_SUCCESS;
if (!operation_is_flag_set(operation, OP_FLAG_INTERNAL) && is_ruv_tombstone_entry(e)) {
/* We are about to send back the database RUV, we need to return
* in memory RUV instead
*/
/* Retrieve the suffix DN from the RUV entry */
suffix_sdn = slapi_sdn_new();
slapi_sdn_get_parent(slapi_entry_get_sdn(e), suffix_sdn);
/* Now set the in memory RUV into the pblock */
if ((e_alt = get_in_memory_ruv(suffix_sdn)) != NULL) {
slapi_pblock_set(pb, SLAPI_SEARCH_ENTRY_COPY, e_alt);
}
slapi_sdn_free(&suffix_sdn);
}
return SLAPI_PLUGIN_SUCCESS;
}
static void
purge_entry_state_information(Slapi_PBlock *pb)
{
CSN *purge_csn = NULL;
Replica *replica;
/* we don't want to trim RUV tombstone because we will
deadlock with ourself */
if (ruv_tombstone_op(pb))
return;
replica = replica_get_replica_for_op(pb);
if (NULL != replica) {
purge_csn = replica_get_purge_csn(replica);
}
if (NULL != purge_csn) {
Slapi_Entry *e;
int optype;
slapi_pblock_get(pb, SLAPI_OPERATION_TYPE, &optype);
switch (optype) {
case SLAPI_OPERATION_MODIFY:
slapi_pblock_get(pb, SLAPI_MODIFY_EXISTING_ENTRY, &e);
break;
case SLAPI_OPERATION_MODRDN:
/* XXXggood - the following always gives a NULL entry - why? */
slapi_pblock_get(pb, SLAPI_MODRDN_EXISTING_ENTRY, &e);
break;
case SLAPI_OPERATION_DELETE:
slapi_pblock_get(pb, SLAPI_DELETE_EXISTING_ENTRY, &e);
break;
default:
e = NULL; /* Don't purge on ADD - not needed */
break;
}
if (NULL != e) {
entry_purge_state_information(e, purge_csn);
/* conntion is always null */
if (slapi_is_loglevel_set(SLAPI_LOG_REPL)) {
char csn_str[CSN_STRSIZE];
slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
"purge_entry_state_information - From entry %s up to "
"CSN %s\n",
slapi_entry_get_dn(e),
csn_as_string(purge_csn, PR_FALSE, csn_str));
}
}
csn_free(&purge_csn);
}
}
int
multisupplier_mmr_preop (Slapi_PBlock *pb, int flags)
{
int rc= SLAPI_PLUGIN_SUCCESS;
if (!is_mmr_replica(pb)) {
return rc;
}
switch (flags)
{
case SLAPI_PLUGIN_BE_PRE_ADD_FN:
rc = multisupplier_bepreop_add(pb);
break;
case SLAPI_PLUGIN_BE_PRE_MODIFY_FN:
rc = multisupplier_bepreop_modify(pb);
break;
case SLAPI_PLUGIN_BE_PRE_MODRDN_FN:
rc = multisupplier_bepreop_modrdn(pb);
break;
case SLAPI_PLUGIN_BE_PRE_DELETE_FN:
rc = multisupplier_bepreop_delete(pb);
break;
}
return rc;
}
int
multisupplier_mmr_postop (Slapi_PBlock *pb, int flags)
{
int rc= SLAPI_PLUGIN_SUCCESS;
if (!is_mmr_replica(pb)) {
return rc;
}
switch (flags)
{
case SLAPI_PLUGIN_BE_TXN_POST_ADD_FN:
rc = multisupplier_be_betxnpostop_add(pb);
break;
case SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN:
rc = multisupplier_be_betxnpostop_delete(pb);
break;
case SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN:
rc = multisupplier_be_betxnpostop_modify(pb);
break;
case SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN:
rc = multisupplier_be_betxnpostop_modrdn(pb);
break;
}
if (rc) {
slapi_log_err(SLAPI_LOG_REPL, REPLICATION_SUBSYSTEM,
"multisupplier_mmr_postop - error %d for operation %d.\n", rc, flags);
}
return rc;
}
/* pure bepreop's -- should be done before transaction starts */
int
multisupplier_bepreop_add(Slapi_PBlock *pb)
{
int rc = SLAPI_PLUGIN_SUCCESS;
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
slapi_pblock_get(pb, SLAPI_OPERATION, &op);
is_replicated_operation = operation_is_flag_set(op, OP_FLAG_REPLICATED);
is_fixup_operation = operation_is_flag_set(op, OP_FLAG_REPL_FIXUP);
/* For replicated operations, apply URP algorithm */
if (!is_fixup_operation) {
slapi_pblock_set(pb, SLAPI_TXN_RUV_MODS_FN,
(void *)replica_ruv_smods_for_op);
if (is_replicated_operation) {
rc = urp_add_operation(pb);
}
}
return rc;
}
int
multisupplier_bepreop_delete(Slapi_PBlock *pb)
{
int rc = SLAPI_PLUGIN_SUCCESS;
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
slapi_pblock_get(pb, SLAPI_OPERATION, &op);
is_replicated_operation = operation_is_flag_set(op, OP_FLAG_REPLICATED);
is_fixup_operation = operation_is_flag_set(op, OP_FLAG_REPL_FIXUP);
/* For replicated operations, apply URP algorithm */
if (!is_fixup_operation) {
slapi_pblock_set(pb, SLAPI_TXN_RUV_MODS_FN,
(void *)replica_ruv_smods_for_op);
if (is_replicated_operation) {
rc = urp_delete_operation(pb);
}
}
return rc;
}
int
multisupplier_bepreop_modify(Slapi_PBlock *pb)
{
int rc = SLAPI_PLUGIN_SUCCESS;
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
slapi_pblock_get(pb, SLAPI_OPERATION, &op);
is_replicated_operation = operation_is_flag_set(op, OP_FLAG_REPLICATED);
is_fixup_operation = operation_is_flag_set(op, OP_FLAG_REPL_FIXUP);
/* For replicated operations, apply URP algorithm */
if (!is_fixup_operation) {
slapi_pblock_set(pb, SLAPI_TXN_RUV_MODS_FN,
(void *)replica_ruv_smods_for_op);
if (is_replicated_operation) {
rc = urp_modify_operation(pb);
}
}
/* Clean up old state information */
purge_entry_state_information(pb);
return rc;
}
int
multisupplier_bepreop_modrdn(Slapi_PBlock *pb)
{
int rc = SLAPI_PLUGIN_SUCCESS;
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
slapi_pblock_get(pb, SLAPI_OPERATION, &op);
is_replicated_operation = operation_is_flag_set(op, OP_FLAG_REPLICATED);
is_fixup_operation = operation_is_flag_set(op, OP_FLAG_REPL_FIXUP);
/* For replicated operations, apply URP algorithm */
if (!is_fixup_operation) {
slapi_pblock_set(pb, SLAPI_TXN_RUV_MODS_FN,
(void *)replica_ruv_smods_for_op);
if (is_replicated_operation) {
rc = urp_modrdn_operation(pb);
}
}
/* Clean up old state information */
purge_entry_state_information(pb);
return rc;
}
int
multisupplier_bepostop_add(Slapi_PBlock *pb)
{
Slapi_Operation *op;
slapi_pblock_get(pb, SLAPI_OPERATION, &op);
if ( ! operation_is_flag_set (op, OP_FLAG_REPL_FIXUP) ) {
urp_post_add_operation (pb);
}
return SLAPI_PLUGIN_SUCCESS;
}
int
multisupplier_bepostop_modrdn(Slapi_PBlock *pb)
{
Slapi_Operation *op;
slapi_pblock_get(pb, SLAPI_OPERATION, &op);
if (!operation_is_flag_set(op, OP_FLAG_REPL_FIXUP)) {
urp_post_modrdn_operation(pb);
}
return SLAPI_PLUGIN_SUCCESS;
}
int
multisupplier_bepostop_delete(Slapi_PBlock *pb)
{
Slapi_Operation *op;
slapi_pblock_get(pb, SLAPI_OPERATION, &op);
if (!operation_is_flag_set(op, OP_FLAG_REPL_FIXUP)) {
urp_post_delete_operation(pb);
}
return SLAPI_PLUGIN_SUCCESS;
}
/* postop - write to changelog */
int
multisupplier_postop_bind(Slapi_PBlock *pb __attribute__((unused)))
{
return SLAPI_PLUGIN_SUCCESS;
}
int
multisupplier_postop_add(Slapi_PBlock *pb)
{
return process_postop(pb);
}
int
multisupplier_postop_delete(Slapi_PBlock *pb)
{
return process_postop(pb);
}
int
multisupplier_postop_modify(Slapi_PBlock *pb)
{
return process_postop(pb);
}
int
multisupplier_postop_modrdn(Slapi_PBlock *pb)
{
return process_postop(pb);
}
int
multisupplier_betxnpostop_delete(Slapi_PBlock *pb)
{
return write_changelog_and_ruv(pb);
}
int
multisupplier_betxnpostop_modrdn(Slapi_PBlock *pb)
{
return write_changelog_and_ruv(pb);
}
int
multisupplier_betxnpostop_add(Slapi_PBlock *pb)
{
return write_changelog_and_ruv(pb);
}
int
multisupplier_betxnpostop_modify(Slapi_PBlock *pb)
{
return write_changelog_and_ruv(pb);
}
/* If nsslapd-pluginbetxn is on */
int
multisupplier_be_betxnpostop_delete(Slapi_PBlock *pb)
{
int rc = SLAPI_PLUGIN_SUCCESS;
/* original betxnpost */
rc = write_changelog_and_ruv(pb);
/* original bepost */
rc |= multisupplier_bepostop_delete(pb);
return rc;
}
int
multisupplier_be_betxnpostop_modrdn(Slapi_PBlock *pb)
{
int rc = 0;
/* original betxnpost */
rc = write_changelog_and_ruv(pb);
/* original bepost */
rc |= multisupplier_bepostop_modrdn(pb);
return rc;
}
int
multisupplier_be_betxnpostop_add(Slapi_PBlock *pb)
{
int rc = 0;
/* original betxnpost */
rc = write_changelog_and_ruv(pb);
rc |= multisupplier_bepostop_add(pb);
return rc;
}
int
multisupplier_be_betxnpostop_modify(Slapi_PBlock *pb)
{
int rc = 0;
/* original betxnpost */
rc = write_changelog_and_ruv(pb);
return rc;
}
/* Helper functions */
/*
* This function makes a copy of the operation parameters
* and stashes them in the consumer operation extension.
* This is where the 5.0 Change Log will get the operation
* details from.
*/
static void
copy_operation_parameters(Slapi_PBlock *pb)
{
Slapi_Operation *op = NULL;
struct slapi_operation_parameters *op_params;
supplier_operation_extension *opext;
Replica *replica;
replica = replica_get_replica_for_op(pb);
/* we are only interested in the updates to replicas */
if (NULL == replica) {
return;
}
/* we only save the original operation parameters for replicated operations
since client operations don't go through urp engine and pblock data can be logged */
slapi_pblock_get(pb, SLAPI_OPERATION, &op);
if (NULL == op) {
slapi_log_err(SLAPI_LOG_REPL, REPLICATION_SUBSYSTEM,
"copy_operation_parameters - operation is null.\n");
return;
}
opext = (supplier_operation_extension *)repl_sup_get_ext(REPL_SUP_EXT_OP, op);
if (operation_is_flag_set(op, OP_FLAG_REPLICATED) &&
!operation_is_flag_set(op, OP_FLAG_REPL_FIXUP)) {
slapi_pblock_get(pb, SLAPI_OPERATION_PARAMETERS, &op_params);
opext->operation_parameters = operation_parameters_dup(op_params);
}
/* this condition is needed to avoid re-entering backend serial lock
when ruv state is updated */
if (!operation_is_flag_set(op, OP_FLAG_REPL_FIXUP)) {
/* save replica generation in case it changes */
opext->repl_gen = replica_get_generation(replica);
}
}
/*
* Helper function: update the RUV so that it reflects the
* locally-processed update. This is called for both replicated
* and non-replicated operations.
*/
static int
update_ruv_component(Replica *replica, CSN *opcsn, Slapi_PBlock *pb)
{
char *purl;
int rc = RUV_NOTFOUND;
if (!replica || !opcsn)
return rc;
/* Replica configured, so update its ruv */
purl = (char *)replica_get_purl_for_op(replica, pb, opcsn);
rc = replica_update_ruv(replica, opcsn, purl);
return rc;
}
/*
* Write the changelog. Note: it is an error to call write_changelog_and_ruv() for fixup
* operations. The caller should avoid calling this function if the operation is
* a fixup op.
* Also update the ruv - we need to do this while we have the replica lock acquired
* so that the csn is written to the changelog and the ruv is updated with the csn
* in one atomic operation - if there is no changelog, we still need to update
* the ruv (e.g. for consumers)
*/
static int
write_changelog_and_ruv(Slapi_PBlock *pb)
{
Slapi_Operation *op = NULL;
CSN *opcsn;
CSNPL_CTX *prim_csn;
int rc;
slapi_operation_parameters *op_params = NULL;
int return_value = SLAPI_PLUGIN_SUCCESS;
Replica *r;
Slapi_Backend *be;
int is_replicated_operation = 0;
/* we just let fixup operations through */
slapi_pblock_get(pb, SLAPI_OPERATION, &op);
if (NULL == op) {
return return_value;
}
if ((operation_is_flag_set(op, OP_FLAG_REPL_FIXUP)) ||
(operation_is_flag_set(op, OP_FLAG_TOMBSTONE_ENTRY))) {
return return_value;
}
/* ignore operations intended for chaining backends - they will be
replicated back to us or should be ignored anyway
replicated operations should be processed normally, as they should
be going to a local backend */
is_replicated_operation = operation_is_flag_set(op, OP_FLAG_REPLICATED);
slapi_pblock_get(pb, SLAPI_BACKEND, &be);
if (!is_replicated_operation &&
slapi_be_is_flag_set(be, SLAPI_BE_FLAG_REMOTE_DATA)) {
return return_value;
}
/* we only log changes for operations applied to a replica */
r = replica_get_replica_for_op(pb);
if (r == NULL)
return return_value;
slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (rc) { /* op failed - just return */
cancel_opcsn(pb);
goto common_return;
}
replica_check_release_timeout(r, pb);
if (replica_is_flag_set(r, REPLICA_LOG_CHANGES)) {
supplier_operation_extension *opext = NULL;
cldb_Handle *cldb = NULL;
opext = (supplier_operation_extension *)repl_sup_get_ext(REPL_SUP_EXT_OP, op);
PR_ASSERT(opext);
/* changelog database information to pass to the write function */
cldb = replica_get_cl_info(r);
if (cldb == NULL) {
slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name_cl,
"write_changelog_and_ruv - changelog is not initialized\n");
return return_value;
}
/* for replicated operations, we log the original, non-urp data which is
saved in the operation extension */
if (operation_is_flag_set(op, OP_FLAG_REPLICATED)) {
PR_ASSERT(opext->operation_parameters);
op_params = opext->operation_parameters;
} else /* since client operations don't go through urp, we log the operation data in pblock */
{
Slapi_Entry *e = NULL;
const char *uniqueid = NULL;
slapi_pblock_get(pb, SLAPI_OPERATION_PARAMETERS, &op_params);
if (NULL == op_params) {
goto common_return;
}
/* need to set uniqueid operation parameter */
/* we try to use the appropriate entry (pre op or post op)
depending on the type of operation (add, delete, modify)
However, in some cases, the backend operation may fail in
a non fatal way (e.g. attempt to remove an attribute value
that does not exist) but we still need to log the change.
So, the POST_OP entry may not have been set in the FE modify
code. In that case, we use the PRE_OP entry.
*/
slapi_pblock_get(pb, SLAPI_ENTRY_POST_OP, &e);
if ((e == NULL) ||
(op_params->operation_type == SLAPI_OPERATION_DELETE)) {
slapi_pblock_get(pb, SLAPI_ENTRY_PRE_OP, &e);
}
if (NULL == e) {
goto common_return;
}
uniqueid = slapi_entry_get_uniqueid(e);
if (NULL == uniqueid) {
goto common_return;
}
op_params->target_address.uniqueid = slapi_ch_strdup(uniqueid);
}
if (op_params->csn && is_cleaned_rid(csn_get_replicaid(op_params->csn))) {
/* this RID has been cleaned */
if (!operation_is_flag_set(op, OP_FLAG_REPLICATED)) {
slapi_ch_free((void **)&op_params->target_address.uniqueid);
}
goto common_return;
}
/* Skip internal operations with no op csn if this is a read-only replica */
if (op_params->csn == NULL &&
operation_is_flag_set(op, OP_FLAG_INTERNAL) &&
replica_get_type(r) == REPLICA_TYPE_READONLY)
{
slapi_log_err(SLAPI_LOG_REPL, "write_changelog_and_ruv",
"Skipping internal operation on read-only replica\n");
if (!operation_is_flag_set(op, OP_FLAG_REPLICATED)) {
slapi_ch_free((void **)&op_params->target_address.uniqueid);
}
goto common_return;
}
/* we might have stripped all the mods - in that case we do not
log the operation */
if (op_params->operation_type != SLAPI_OPERATION_MODIFY ||
op_params->p.p_modify.modify_mods != NULL) {
void *txn = NULL;
char csn_str[CSN_STRSIZE];
slapi_pblock_get(pb, SLAPI_TXN, &txn);
slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
"write_changelog_and_ruv - Writing change for "
"%s (uniqid: %s, optype: %lu) to changelog csn %s\n",
REPL_GET_DN(&op_params->target_address),
op_params->target_address.uniqueid,
op_params->operation_type,
csn_as_string(op_params->csn, PR_FALSE, csn_str));
rc = cl5WriteOperationTxn(cldb, op_params, txn);
if (rc != CL5_SUCCESS) {
/* ONREPL - log error */
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
"write_changelog_and_ruv - Can't add a change for "
"%s (uniqid: %s, optype: %lu) to changelog csn %s\n",
REPL_GET_DN(&op_params->target_address),
op_params->target_address.uniqueid,
op_params->operation_type,
csn_as_string(op_params->csn, PR_FALSE, csn_str));
return_value = SLAPI_PLUGIN_FAILURE;
}
}
if (!operation_is_flag_set(op, OP_FLAG_REPLICATED)) {
slapi_ch_free((void **)&op_params->target_address.uniqueid);
}
}
/*
This was moved because we need to write the changelog and update
the ruv in one atomic operation - I have seen cases where the inc
protocol thread interrupts this thread between the time the changelog
is written and the ruv is updated - this causes confusion in several
places, especially in _cl5SkipReplayEntry since it cannot find the csn it
just read from the changelog in either the supplier or consumer ruv
*/
if (0 == return_value) {
char csn_str[CSN_STRSIZE] = {'\0'};
const char *dn = op_params ? REPL_GET_DN(&op_params->target_address) : "unknown";
Slapi_DN *sdn = op_params ? (&op_params->target_address)->sdn : NULL;
char *uniqueid = op_params ? op_params->target_address.uniqueid : "unknown";
unsigned long optype = op_params ? op_params->operation_type : 0;
CSN *oppcsn = op_params ? op_params->csn : NULL;
LDAPMod **mods = op_params ? op_params->p.p_modify.modify_mods : NULL;
slapi_pblock_get(pb, SLAPI_OPERATION, &op);
opcsn = operation_get_csn(op);
/* Update each agmt's maxcsn */
if (op_params && sdn) {
agmt_update_maxcsn(r, sdn, op_params->operation_type, mods, opcsn);
}
rc = update_ruv_component(r, opcsn, pb);
if (RUV_COVERS_CSN == rc) {
slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
"write_changelog_and_ruv - RUV already covers csn for "
"%s (uniqid: %s, optype: %lu) csn %s\n",
dn, uniqueid, optype,
csn_as_string(oppcsn, PR_FALSE, csn_str));
} else if ((rc != RUV_SUCCESS) && (rc != RUV_NOTFOUND)) {
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
"write_changelog_and_ruv - Failed to update RUV for "
"%s (uniqid: %s, optype: %lu) to changelog csn %s - rc %d\n",
dn, uniqueid, optype,
csn_as_string(oppcsn, PR_FALSE, csn_str), rc);
}
}
common_return:
opcsn = operation_get_csn(op);
prim_csn = get_thread_primary_csn();
if (csn_primary(r, opcsn, prim_csn)) {
if (return_value == 0) {
/* the primary csn was succesfully committed
* unset it in the thread local data
*/
set_thread_primary_csn(NULL, NULL);
}
}
return return_value;
}
/*
* Postop processing - write the changelog if the operation resulted in
* an LDAP_SUCCESS result code, update the RUV, and notify the replication
* agreements about the change.
* If the result code is not LDAP_SUCCESS, then cancel the operation CSN.
*/
static int
process_postop(Slapi_PBlock *pb)
{
Slapi_Operation *op;
Slapi_Backend *be;
int is_replicated_operation = 0;
CSN *opcsn = NULL;
char sessionid[REPL_SESSION_ID_SIZE];
int retval = LDAP_SUCCESS;
int rc = 0;
/* we just let fixup operations through */
slapi_pblock_get(pb, SLAPI_OPERATION, &op);
if ((operation_is_flag_set(op, OP_FLAG_REPL_FIXUP)) ||
(operation_is_flag_set(op, OP_FLAG_TOMBSTONE_ENTRY))) {
return SLAPI_PLUGIN_SUCCESS;
}
/* ignore operations intended for chaining backends - they will be
replicated back to us or should be ignored anyway
replicated operations should be processed normally, as they should
be going to a local backend */
is_replicated_operation = operation_is_flag_set(op, OP_FLAG_REPLICATED);
slapi_pblock_get(pb, SLAPI_BACKEND, &be);
if (!is_replicated_operation &&
slapi_be_is_flag_set(be, SLAPI_BE_FLAG_REMOTE_DATA)) {
return SLAPI_PLUGIN_SUCCESS;
}
get_repl_session_id(pb, sessionid, &opcsn);
slapi_pblock_get(pb, SLAPI_RESULT_CODE, &retval);
if (retval == LDAP_SUCCESS) {
agmtlist_notify_all(pb);
rc = SLAPI_PLUGIN_SUCCESS;
} else if (opcsn) {
rc = cancel_opcsn(pb);
/* Don't try to get session id since conn is always null */
slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
"process postop - %s canceling operation csn\n", sessionid);
} else {
rc = SLAPI_PLUGIN_FAILURE;
}
/* the target unique id is set in the modify_preop above, so
we need to free it */
/* The following bunch of frees code does not belong to this place
* but rather to operation_free who should be responsible for calling
* operation_parameters_free and it doesn't. I guess this is like this
* because several crashes happened in the past regarding some opparams
* that were getting individually freed before they should. Whatever
* the case, this is not the place and we should make sure that this
* code gets removed for 5.next and substituted by the strategy (operation_free).
* For 5.0, such change is too risky, so this will be done here */
if (is_replicated_operation) {
slapi_operation_parameters *op_params = NULL;
int optype = 0;
/* target uid and csn are set for all repl operations. Free them */
char *target_uuid = NULL;
slapi_pblock_get(pb, SLAPI_OPERATION_TYPE, &optype);
slapi_pblock_get(pb, SLAPI_TARGET_UNIQUEID, &target_uuid);
slapi_pblock_set(pb, SLAPI_TARGET_UNIQUEID, NULL);
slapi_ch_free((void **)&target_uuid);
if (optype == SLAPI_OPERATION_ADD) {
slapi_pblock_get(pb, SLAPI_OPERATION_PARAMETERS, &op_params);
slapi_ch_free((void **)&op_params->p.p_add.parentuniqueid);
}
if (optype == SLAPI_OPERATION_MODRDN) {
slapi_pblock_get(pb, SLAPI_OPERATION_PARAMETERS, &op_params);
slapi_ch_free((void **)&op_params->p.p_modrdn.modrdn_newsuperior_address.uniqueid);
}
if (!ignore_error_and_keep_going(retval)) {
/*
* We have an error we can't ignore. Release the replica and close
* the connection to stop the replication session.
*/
consumer_connection_extension *connext = NULL;
Slapi_Connection *conn = NULL;
char csn_str[CSN_STRSIZE] = {'\0'};
PRUint64 connid = 0;
int opid = 0;
slapi_pblock_get(pb, SLAPI_CONNECTION, &conn);
slapi_pblock_get(pb, SLAPI_OPERATION_ID, &opid);
slapi_pblock_get(pb, SLAPI_CONN_ID, &connid);
if (conn) {
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
"process_postop - Failed to apply update (%s) error (%d). "
"Aborting replication session(conn=%" PRIu64 " op=%d)\n",
csn_as_string(opcsn, PR_FALSE, csn_str), retval,
connid, opid);
/*
* Release this replica so new sessions can begin
*/
connext = consumer_connection_extension_acquire_exclusive_access(conn, connid, opid);
if (connext && connext->replica_acquired) {
int zero = 0;
replica_relinquish_exclusive_access(connext->replica_acquired, connid, opid);
connext->replica_acquired = NULL;
connext->isreplicationsession = 0;
slapi_pblock_set(pb, SLAPI_CONN_IS_REPLICATION_SESSION, &zero);
}
if (connext) {
consumer_connection_extension_relinquish_exclusive_access(conn, connid, opid, PR_FALSE);
}
/*
* Close the connection to end the current session with the
* supplier. This prevents new updates from coming in and
* updating the consumer RUV - which would cause this failed
* update to be never be replayed.
*/
slapi_disconnect_server(conn);
}
}
}
if (NULL == opcsn)
opcsn = operation_get_csn(op);
if (opcsn)
csn_free(&opcsn);
return rc;
}
/*
* Cancel an operation CSN. This removes it from any CSN pending lists.
* This function is called when a previously-generated CSN will not
* be needed, e.g. if the update operation produced an error.
*/
static int
cancel_opcsn(Slapi_PBlock *pb)
{
Replica *replica = NULL;
Slapi_Operation *op = NULL;
if (NULL == pb) {
return SLAPI_PLUGIN_SUCCESS;
}
replica = replica_get_replica_for_op(pb);
slapi_pblock_get(pb, SLAPI_OPERATION, &op);
if (NULL == op) {
return SLAPI_PLUGIN_SUCCESS;
}
if (replica) {
Object *gen_obj;
CSNGen *gen;
CSN *opcsn;
opcsn = operation_get_csn(op);
if (!operation_is_flag_set(op, OP_FLAG_REPLICATED)) {
/* get csn generator for the replica */
gen_obj = replica_get_csngen(replica);
PR_ASSERT(gen_obj);
gen = (CSNGen *)object_get_data(gen_obj);
if (NULL != opcsn) {
csngen_abort_csn(gen, operation_get_csn(op));
}
object_release(gen_obj);
} else if (!operation_is_flag_set(op, OP_FLAG_REPL_FIXUP)) {
Object *ruv_obj;
ruv_obj = replica_get_ruv(replica);
PR_ASSERT(ruv_obj);
ruv_cancel_csn_inprogress(replica, (RUV *)object_get_data(ruv_obj), opcsn, replica_get_rid(replica));
object_release(ruv_obj);
}
}
return SLAPI_PLUGIN_SUCCESS;
}
/*
* Return non-zero if the target entry DN is the DN of the RUV tombstone
* entry.
* The entry has rdn of nsuniqueid = ffffffff-ffffffff-ffffffff-ffffffff
*/
static int
ruv_tombstone_op(Slapi_PBlock *pb)
{
char *uniqueid;
int rc;
slapi_pblock_get(pb, SLAPI_TARGET_UNIQUEID, &uniqueid);
rc = uniqueid && strcasecmp(uniqueid, RUV_STORAGE_ENTRY_UNIQUEID) == 0;
return rc;
}
/* we don't want to process replicated operations with csn smaller
than the corresponding csn in the consumer's ruv */
static PRBool
process_operation(Slapi_PBlock *pb, const CSN *csn)
{
Replica *r;
Object *ruv_obj;
RUV *ruv;
int rc;
r = replica_get_replica_for_op(pb);
if (r == NULL) {
char sessionid[REPL_SESSION_ID_SIZE];
get_repl_session_id(pb, sessionid, NULL);
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "process_operation - "
"%s - Can't locate replica for the replicated operation\n",
sessionid);
return PR_FALSE;
}
ruv_obj = replica_get_ruv(r);
PR_ASSERT(ruv_obj);
ruv = (RUV *)object_get_data(ruv_obj);
PR_ASSERT(ruv);
rc = ruv_add_csn_inprogress(r, ruv, csn);
object_release(ruv_obj);
return (rc == RUV_SUCCESS);
}
static PRBool
is_mmr_replica(Slapi_PBlock *pb)
{
Replica *replica;
replica = replica_get_replica_for_op(pb);
if (replica == NULL) {
return PR_FALSE;
}
return PR_TRUE;
}
static const char *
replica_get_purl_for_op(const Replica *r __attribute__((unused)), Slapi_PBlock *pb, const CSN *opcsn)
{
int is_replicated_op;
const char *purl = NULL;
slapi_pblock_get(pb, SLAPI_IS_MMR_REPLICATED_OPERATION, &is_replicated_op);
if (!is_replicated_op) {
purl = multisupplier_get_local_purl();
} else {
/* Get the appropriate partial URL from the supplier RUV */
Slapi_Connection *conn;
consumer_connection_extension *connext;
slapi_pblock_get(pb, SLAPI_CONNECTION, &conn);
/* TEL 20120531: There is a slim chance we want to take exclusive access
* to this instead. However, it isn't clear to me that it is worth the
* risk of changing this working code. */
connext = (consumer_connection_extension *)repl_con_get_ext(
REPL_CON_EXT_CONN, conn);
if (NULL == connext || NULL == connext->supplier_ruv) {
char sessionid[REPL_SESSION_ID_SIZE];
get_repl_session_id(pb, sessionid, NULL);
slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "replica_get_purl_for_op - "
"%s - Cannot obtain consumer connection extension or supplier_ruv.\n",
sessionid);
} else {
purl = ruv_get_purl_for_replica(connext->supplier_ruv,
csn_get_replicaid(opcsn));
}
}
return purl;
}
/* this function is called when state of a backend changes */
void
multisupplier_be_state_change(void *handle __attribute__((unused)), char *be_name, int old_be_state, int new_be_state)
{
Replica *r;
/* check if we have replica associated with the backend */
r = replica_get_for_backend(be_name);
if (r == NULL) {
return;
}
if (new_be_state == SLAPI_BE_STATE_ON) {
/* backend came back online - restart replication */
slapi_log_err(SLAPI_LOG_NOTICE, repl_plugin_name, "multisupplier_be_state_change - "
"Replica %s is coming online; enabling replication\n",
slapi_sdn_get_ndn(replica_get_root(r)));
replica_enable_replication(r);
} else if (new_be_state == SLAPI_BE_STATE_OFFLINE) {
/* backend is about to be taken down - disable replication */
slapi_log_err(SLAPI_LOG_NOTICE, repl_plugin_name, "multisupplier_be_state_change - "
"Replica %s is going offline; disabling replication\n",
slapi_sdn_get_ndn(replica_get_root(r)));
replica_disable_replication(r);
} else if (new_be_state == SLAPI_BE_STATE_DELETE) {
/* backend is about to be removed - disable replication */
if (old_be_state == SLAPI_BE_STATE_ON) {
slapi_log_err(SLAPI_LOG_NOTICE, repl_plugin_name, "multisupplier_be_state_change - "
"Replica %s is about to be deleted; disabling replication\n",
slapi_sdn_get_ndn(replica_get_root(r)));
replica_disable_replication(r);
}
}
}
|