1
0

repl_ops.c 6.5 KB

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