repl_ops.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. * END COPYRIGHT BLOCK **/
  6. #include "slapi-plugin.h"
  7. #include "repl.h"
  8. #include "repl5.h"
  9. int
  10. legacy_postop( Slapi_PBlock *pb, const char *caller, int operation_type)
  11. {
  12. int rc = 0;
  13. Object *r_obj;
  14. Replica *r;
  15. r_obj = replica_get_replica_for_op (pb);
  16. if (r_obj == NULL) /* there is no replica configured for this operations */
  17. return 0;
  18. else
  19. {
  20. /* check if this replica is 4.0 consumer */
  21. r = (Replica*)object_get_data (r_obj);
  22. PR_ASSERT (r);
  23. /* this replica is not a 4.0 consumer - so we don't need to do any processing */
  24. if (!replica_is_legacy_consumer (r))
  25. {
  26. object_release (r_obj);
  27. return 0;
  28. }
  29. object_release (r_obj);
  30. }
  31. slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &rc);
  32. if (0 == rc)
  33. {
  34. if (OP_ADD == operation_type || OP_MODIFY == operation_type)
  35. {
  36. void *op;
  37. consumer_operation_extension *opext = NULL;
  38. /* Optimise out traversal of mods/entry if no cop{ied|ying}From present */
  39. slapi_pblock_get(pb, SLAPI_OPERATION, &op);
  40. opext = (consumer_operation_extension*) repl_con_get_ext (REPL_CON_EXT_OP, op);
  41. if (NULL != opext && opext->has_cf)
  42. {
  43. process_legacy_cf( pb );
  44. }
  45. }
  46. }
  47. return 0;
  48. }
  49. int
  50. legacy_preop(Slapi_PBlock *pb, const char *caller, int operation_type)
  51. {
  52. int rc = 0;
  53. Slapi_Operation *operation = NULL;
  54. consumer_operation_extension *opext = NULL;
  55. int has_cf = 0;
  56. Object *r_obj;
  57. Replica *r;
  58. int is_legacy_op = 0;
  59. slapi_pblock_get( pb, SLAPI_OPERATION, &operation );
  60. is_legacy_op = operation_is_flag_set(operation,OP_FLAG_LEGACY_REPLICATION_DN);
  61. r_obj = replica_get_replica_for_op (pb);
  62. if (r_obj == NULL) { /* there is no replica configured for this operations */
  63. if (is_legacy_op){
  64. /* This is a legacy replication operation but there are NO replica defined
  65. Just refuse it */
  66. slapi_send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL,
  67. "Replication operation refused because the consumer is not defined as a replica", 0, NULL);
  68. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  69. "Incoming replication operation was refused because "
  70. "there's no replica defined for this operation\n");
  71. return -1;
  72. }
  73. else {
  74. return 0;
  75. }
  76. }
  77. else
  78. {
  79. /* check if this replica is 4.0 consumer */
  80. r = (Replica*)object_get_data (r_obj);
  81. PR_ASSERT (r);
  82. if (!replica_is_legacy_consumer (r))
  83. {
  84. object_release (r_obj);
  85. if (is_legacy_op) {
  86. /* This is a legacy replication operation
  87. but the replica is doesn't accept from legacy
  88. Just refuse it */
  89. slapi_send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL,
  90. "Replication operation refused because "
  91. "the consumer is not defined as a legacy replica", 0, NULL);
  92. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  93. "Incoming replication operation was refused because "
  94. "there's no legacy replica defined for this operation\n");
  95. return -1;
  96. } else {
  97. return 0;
  98. }
  99. }
  100. object_release (r_obj);
  101. }
  102. opext = (consumer_operation_extension*) repl_con_get_ext (REPL_CON_EXT_OP, operation);
  103. switch (operation_type) {
  104. case OP_ADD:
  105. {
  106. Slapi_Entry *e = NULL;
  107. Slapi_Attr *attr;
  108. /*
  109. * Check if the entry being added has copiedFrom/copyingFrom
  110. * attributes.
  111. */
  112. slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e);
  113. if (NULL != e)
  114. {
  115. if (slapi_entry_attr_find(e, type_copiedFrom, &attr) == 0)
  116. {
  117. has_cf = 1;
  118. }
  119. else
  120. if (slapi_entry_attr_find(e, type_copyingFrom, &attr) == 0)
  121. {
  122. has_cf = 1;
  123. }
  124. }
  125. /* JCMREPL - If this is a replicated operation then the baggage control also contains the Unique Identifier of the superior entry. */
  126. }
  127. break;
  128. case OP_MODIFY:
  129. {
  130. LDAPMod **mods = NULL;
  131. int i;
  132. /*
  133. * Check if the modification contains copiedFrom/copyingFrom
  134. * attributes.
  135. */
  136. slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &mods);
  137. for (i = 0; NULL != mods && NULL != mods[i]; i++)
  138. {
  139. if ((strcasecmp(mods[i]->mod_type, type_copiedFrom) == 0) ||
  140. (strcasecmp(mods[i]->mod_type, type_copyingFrom) == 0))
  141. {
  142. has_cf = 1;
  143. }
  144. }
  145. }
  146. break;
  147. case OP_DELETE:
  148. break;
  149. case OP_MODDN:
  150. break;
  151. }
  152. /* Squirrel away an optimization hint for the postop plugin */
  153. opext->has_cf = has_cf;
  154. return rc;
  155. }