repl_ops.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. if (NULL == operation) {
  96. slapi_send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL,
  97. "Null replication operation is given", 0, NULL);
  98. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  99. "Null replication operation is given\n");
  100. return -1;
  101. }
  102. is_legacy_op = operation_is_flag_set(operation,OP_FLAG_LEGACY_REPLICATION_DN);
  103. r_obj = replica_get_replica_for_op (pb);
  104. if (r_obj == NULL) { /* there is no replica configured for this operations */
  105. if (is_legacy_op){
  106. /* This is a legacy replication operation but there are NO replica defined
  107. Just refuse it */
  108. slapi_send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL,
  109. "Replication operation refused because the consumer is not defined as a replica", 0, NULL);
  110. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  111. "Incoming replication operation was refused because "
  112. "there's no replica defined for this operation\n");
  113. return -1;
  114. }
  115. else {
  116. return 0;
  117. }
  118. }
  119. else
  120. {
  121. /* check if this replica is 4.0 consumer */
  122. r = (Replica*)object_get_data (r_obj);
  123. PR_ASSERT (r);
  124. if (!replica_is_legacy_consumer (r))
  125. {
  126. object_release (r_obj);
  127. if (is_legacy_op) {
  128. /* This is a legacy replication operation
  129. but the replica is doesn't accept from legacy
  130. Just refuse it */
  131. slapi_send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL,
  132. "Replication operation refused because "
  133. "the consumer is not defined as a legacy replica", 0, NULL);
  134. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  135. "Incoming replication operation was refused because "
  136. "there's no legacy replica defined for this operation\n");
  137. return -1;
  138. } else {
  139. return 0;
  140. }
  141. }
  142. object_release (r_obj);
  143. }
  144. opext = (consumer_operation_extension*) repl_con_get_ext (REPL_CON_EXT_OP, operation);
  145. switch (operation_type) {
  146. case OP_ADD:
  147. {
  148. Slapi_Entry *e = NULL;
  149. Slapi_Attr *attr;
  150. /*
  151. * Check if the entry being added has copiedFrom/copyingFrom
  152. * attributes.
  153. */
  154. slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e);
  155. if (NULL != e)
  156. {
  157. if (slapi_entry_attr_find(e, type_copiedFrom, &attr) == 0)
  158. {
  159. has_cf = 1;
  160. }
  161. else
  162. if (slapi_entry_attr_find(e, type_copyingFrom, &attr) == 0)
  163. {
  164. has_cf = 1;
  165. }
  166. }
  167. /* JCMREPL - If this is a replicated operation then the baggage control also contains the Unique Identifier of the superior entry. */
  168. }
  169. break;
  170. case OP_MODIFY:
  171. {
  172. LDAPMod **mods = NULL;
  173. int i;
  174. /*
  175. * Check if the modification contains copiedFrom/copyingFrom
  176. * attributes.
  177. */
  178. slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &mods);
  179. for (i = 0; NULL != mods && NULL != mods[i]; i++)
  180. {
  181. if ((strcasecmp(mods[i]->mod_type, type_copiedFrom) == 0) ||
  182. (strcasecmp(mods[i]->mod_type, type_copyingFrom) == 0))
  183. {
  184. has_cf = 1;
  185. }
  186. }
  187. }
  188. break;
  189. case OP_DELETE:
  190. break;
  191. case OP_MODDN:
  192. break;
  193. }
  194. /* Squirrel away an optimization hint for the postop plugin */
  195. opext->has_cf = has_cf;
  196. return rc;
  197. }