repl_ops.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright 2001 Sun Microsystems, Inc.
  3. * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
  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. static char *not_replicationdn_errmsg =
  50. "An operation was submitted that contained copiedFrom or "
  51. "copyingFrom attributes, but the connection was not bound "
  52. "as the replicationdn.";
  53. int
  54. legacy_preop(Slapi_PBlock *pb, const char *caller, int operation_type)
  55. {
  56. int rc = 0;
  57. Slapi_Operation *operation = NULL;
  58. consumer_operation_extension *opext = NULL;
  59. int has_cf = 0;
  60. Object *r_obj;
  61. Replica *r;
  62. int is_legacy_op = 0;
  63. slapi_pblock_get( pb, SLAPI_OPERATION, &operation );
  64. is_legacy_op = operation_is_flag_set(operation,OP_FLAG_LEGACY_REPLICATION_DN);
  65. r_obj = replica_get_replica_for_op (pb);
  66. if (r_obj == NULL) { /* there is no replica configured for this operations */
  67. if (is_legacy_op){
  68. /* This is a legacy replication operation but there are NO replica defined
  69. Just refuse it */
  70. slapi_send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL,
  71. "Replication operation refused because the consumer is not defined as a replica", 0, NULL);
  72. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  73. "Incoming replication operation was refused because "
  74. "there's no replica defined for this operation\n");
  75. return -1;
  76. }
  77. else {
  78. return 0;
  79. }
  80. }
  81. else
  82. {
  83. /* check if this replica is 4.0 consumer */
  84. r = (Replica*)object_get_data (r_obj);
  85. PR_ASSERT (r);
  86. if (!replica_is_legacy_consumer (r))
  87. {
  88. object_release (r_obj);
  89. if (is_legacy_op) {
  90. /* This is a legacy replication operation
  91. but the replica is doesn't accept from legacy
  92. Just refuse it */
  93. slapi_send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL,
  94. "Replication operation refused because "
  95. "the consumer is not defined as a legacy replica", 0, NULL);
  96. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  97. "Incoming replication operation was refused because "
  98. "there's no legacy replica defined for this operation\n");
  99. return -1;
  100. } else {
  101. return 0;
  102. }
  103. }
  104. object_release (r_obj);
  105. }
  106. opext = (consumer_operation_extension*) repl_con_get_ext (REPL_CON_EXT_OP, operation);
  107. switch (operation_type) {
  108. case OP_ADD:
  109. {
  110. Slapi_Entry *e = NULL;
  111. Slapi_Attr *attr;
  112. /*
  113. * Check if the entry being added has copiedFrom/copyingFrom
  114. * attributes.
  115. */
  116. slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e);
  117. if (NULL != e)
  118. {
  119. if (slapi_entry_attr_find(e, type_copiedFrom, &attr) == 0)
  120. {
  121. has_cf = 1;
  122. }
  123. else
  124. if (slapi_entry_attr_find(e, type_copyingFrom, &attr) == 0)
  125. {
  126. has_cf = 1;
  127. }
  128. }
  129. /* JCMREPL - If this is a replicated operation then the baggage control also contains the Unique Identifier of the superior entry. */
  130. }
  131. break;
  132. case OP_MODIFY:
  133. {
  134. LDAPMod **mods = NULL;
  135. int i;
  136. /*
  137. * Check if the modification contains copiedFrom/copyingFrom
  138. * attributes.
  139. */
  140. slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &mods);
  141. for (i = 0; NULL != mods && NULL != mods[i]; i++)
  142. {
  143. if ((strcasecmp(mods[i]->mod_type, type_copiedFrom) == 0) ||
  144. (strcasecmp(mods[i]->mod_type, type_copyingFrom) == 0))
  145. {
  146. has_cf = 1;
  147. }
  148. }
  149. }
  150. break;
  151. case OP_DELETE:
  152. break;
  153. case OP_MODDN:
  154. break;
  155. }
  156. /* Squirrel away an optimization hint for the postop plugin */
  157. opext->has_cf = has_cf;
  158. return rc;
  159. }