repl_ops.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #include "slapi-plugin.h"
  39. #include "repl.h"
  40. #include "repl5.h"
  41. int
  42. legacy_postop( Slapi_PBlock *pb, const char *caller, int operation_type)
  43. {
  44. int rc = 0;
  45. Object *r_obj;
  46. Replica *r;
  47. r_obj = replica_get_replica_for_op (pb);
  48. if (r_obj == NULL) /* there is no replica configured for this operations */
  49. return 0;
  50. else
  51. {
  52. /* check if this replica is 4.0 consumer */
  53. r = (Replica*)object_get_data (r_obj);
  54. PR_ASSERT (r);
  55. /* this replica is not a 4.0 consumer - so we don't need to do any processing */
  56. if (!replica_is_legacy_consumer (r))
  57. {
  58. object_release (r_obj);
  59. return 0;
  60. }
  61. object_release (r_obj);
  62. }
  63. slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &rc);
  64. if (0 == rc)
  65. {
  66. if (OP_ADD == operation_type || OP_MODIFY == operation_type)
  67. {
  68. void *op;
  69. consumer_operation_extension *opext = NULL;
  70. /* Optimise out traversal of mods/entry if no cop{ied|ying}From present */
  71. slapi_pblock_get(pb, SLAPI_OPERATION, &op);
  72. opext = (consumer_operation_extension*) repl_con_get_ext (REPL_CON_EXT_OP, op);
  73. if (NULL != opext && opext->has_cf)
  74. {
  75. process_legacy_cf( pb );
  76. }
  77. }
  78. }
  79. return 0;
  80. }
  81. int
  82. legacy_preop(Slapi_PBlock *pb, const char *caller, int operation_type)
  83. {
  84. int rc = 0;
  85. Slapi_Operation *operation = NULL;
  86. consumer_operation_extension *opext = NULL;
  87. int has_cf = 0;
  88. Object *r_obj;
  89. Replica *r;
  90. int is_legacy_op = 0;
  91. slapi_pblock_get( pb, SLAPI_OPERATION, &operation );
  92. is_legacy_op = operation_is_flag_set(operation,OP_FLAG_LEGACY_REPLICATION_DN);
  93. r_obj = replica_get_replica_for_op (pb);
  94. if (r_obj == NULL) { /* there is no replica configured for this operations */
  95. if (is_legacy_op){
  96. /* This is a legacy replication operation but there are NO replica defined
  97. Just refuse it */
  98. slapi_send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL,
  99. "Replication operation refused because the consumer is not defined as a replica", 0, NULL);
  100. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  101. "Incoming replication operation was refused because "
  102. "there's no replica defined for this operation\n");
  103. return -1;
  104. }
  105. else {
  106. return 0;
  107. }
  108. }
  109. else
  110. {
  111. /* check if this replica is 4.0 consumer */
  112. r = (Replica*)object_get_data (r_obj);
  113. PR_ASSERT (r);
  114. if (!replica_is_legacy_consumer (r))
  115. {
  116. object_release (r_obj);
  117. if (is_legacy_op) {
  118. /* This is a legacy replication operation
  119. but the replica is doesn't accept from legacy
  120. Just refuse it */
  121. slapi_send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL,
  122. "Replication operation refused because "
  123. "the consumer is not defined as a legacy replica", 0, NULL);
  124. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  125. "Incoming replication operation was refused because "
  126. "there's no legacy replica defined for this operation\n");
  127. return -1;
  128. } else {
  129. return 0;
  130. }
  131. }
  132. object_release (r_obj);
  133. }
  134. opext = (consumer_operation_extension*) repl_con_get_ext (REPL_CON_EXT_OP, operation);
  135. switch (operation_type) {
  136. case OP_ADD:
  137. {
  138. Slapi_Entry *e = NULL;
  139. Slapi_Attr *attr;
  140. /*
  141. * Check if the entry being added has copiedFrom/copyingFrom
  142. * attributes.
  143. */
  144. slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e);
  145. if (NULL != e)
  146. {
  147. if (slapi_entry_attr_find(e, type_copiedFrom, &attr) == 0)
  148. {
  149. has_cf = 1;
  150. }
  151. else
  152. if (slapi_entry_attr_find(e, type_copyingFrom, &attr) == 0)
  153. {
  154. has_cf = 1;
  155. }
  156. }
  157. /* JCMREPL - If this is a replicated operation then the baggage control also contains the Unique Identifier of the superior entry. */
  158. }
  159. break;
  160. case OP_MODIFY:
  161. {
  162. LDAPMod **mods = NULL;
  163. int i;
  164. /*
  165. * Check if the modification contains copiedFrom/copyingFrom
  166. * attributes.
  167. */
  168. slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &mods);
  169. for (i = 0; NULL != mods && NULL != mods[i]; i++)
  170. {
  171. if ((strcasecmp(mods[i]->mod_type, type_copiedFrom) == 0) ||
  172. (strcasecmp(mods[i]->mod_type, type_copyingFrom) == 0))
  173. {
  174. has_cf = 1;
  175. }
  176. }
  177. }
  178. break;
  179. case OP_DELETE:
  180. break;
  181. case OP_MODDN:
  182. break;
  183. }
  184. /* Squirrel away an optimization hint for the postop plugin */
  185. opext->has_cf = has_cf;
  186. return rc;
  187. }