repl_ops.c 4.9 KB

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