sync_init.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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) 2013 Red Hat, Inc.
  35. * All rights reserved.
  36. * END COPYRIGHT BLOCK **/
  37. #include "sync.h"
  38. static Slapi_PluginDesc pdesc = { PLUGIN_NAME, VENDOR, DS_PACKAGE_VERSION, "Context Synchronization (RFC4533) plugin" };
  39. static int sync_start(Slapi_PBlock * pb);
  40. static int sync_close(Slapi_PBlock * pb);
  41. static int sync_preop_init( Slapi_PBlock *pb );
  42. static int sync_postop_init( Slapi_PBlock *pb );
  43. int sync_init( Slapi_PBlock *pb )
  44. {
  45. char *plugin_identity = NULL;
  46. int rc = 0;
  47. slapi_log_error(SLAPI_LOG_TRACE, SYNC_PLUGIN_SUBSYSTEM,
  48. "--> sync_init\n");
  49. /**
  50. * Store the plugin identity for later use.
  51. * Used for internal operations
  52. */
  53. slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &plugin_identity);
  54. PR_ASSERT(plugin_identity);
  55. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION,
  56. SLAPI_PLUGIN_VERSION_01) != 0 ||
  57. slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN,
  58. (void *) sync_start) != 0 ||
  59. slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN,
  60. (void *) sync_close) != 0 ||
  61. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION,
  62. (void *) &pdesc) != 0 ) {
  63. slapi_log_error(SLAPI_LOG_FATAL, SYNC_PLUGIN_SUBSYSTEM,
  64. "sync_init: failed to register plugin\n");
  65. rc = 1;
  66. }
  67. if (rc == 0) {
  68. char *plugin_type = "preoperation";
  69. /* the config change checking post op */
  70. if (slapi_register_plugin(
  71. plugin_type,
  72. 1, /* Enabled */
  73. "sync_init", /* this function desc */
  74. sync_preop_init,/* init func for post op */
  75. SYNC_PREOP_DESC,/* plugin desc */
  76. NULL,
  77. plugin_identity)) {
  78. slapi_log_error(SLAPI_LOG_FATAL, SYNC_PLUGIN_SUBSYSTEM,
  79. "sync_init: failed to register preop plugin\n");
  80. rc = 1;
  81. }
  82. }
  83. if (rc == 0) {
  84. char *plugin_type = "postoperation";
  85. /* the config change checking post op */
  86. if (slapi_register_plugin(plugin_type,
  87. 1, /* Enabled */
  88. "sync_init", /* this function desc */
  89. sync_postop_init, /* init func for post op */
  90. SYNC_POSTOP_DESC, /* plugin desc */
  91. NULL,
  92. plugin_identity )) {
  93. slapi_log_error(SLAPI_LOG_FATAL, SYNC_PLUGIN_SUBSYSTEM,
  94. "sync_init: failed to register postop plugin\n");
  95. rc = 1;
  96. }
  97. }
  98. return( rc );
  99. }
  100. static int
  101. sync_preop_init( Slapi_PBlock *pb )
  102. {
  103. int rc;
  104. rc = slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_SEARCH_FN, (void *) sync_srch_refresh_pre_search);
  105. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ENTRY_FN, (void *) sync_srch_refresh_pre_entry);
  106. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_RESULT_FN, (void *) sync_srch_refresh_pre_result);
  107. rc |= sync_register_operation_extension();
  108. return(rc);
  109. }
  110. static int
  111. sync_postop_init( Slapi_PBlock *pb )
  112. {
  113. int rc;
  114. rc = slapi_pblock_set(pb, SLAPI_PLUGIN_POST_ADD_FN, (void *) sync_add_persist_post_op);
  115. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_POST_DELETE_FN, (void *) sync_del_persist_post_op);
  116. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODIFY_FN, (void *) sync_mod_persist_post_op);
  117. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODRDN_FN, (void *) sync_modrdn_persist_post_op);
  118. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_POST_SEARCH_FN, (void *) sync_srch_refresh_post_search);
  119. return(rc);
  120. }
  121. /*
  122. sync_start
  123. --------------
  124. Register the Content Synchronization Control.
  125. Initialize locks and queues for the persitent phase.
  126. */
  127. static int
  128. sync_start(Slapi_PBlock * pb)
  129. {
  130. int argc;
  131. char **argv;
  132. slapi_register_supported_control( LDAP_CONTROL_SYNC,
  133. SLAPI_OPERATION_SEARCH );
  134. slapi_log_error(SLAPI_LOG_TRACE, SYNC_PLUGIN_SUBSYSTEM,
  135. "--> sync_start\n");
  136. if ( slapi_pblock_get( pb, SLAPI_PLUGIN_ARGC, &argc ) != 0 ||
  137. slapi_pblock_get( pb, SLAPI_PLUGIN_ARGV, &argv ) != 0 ) {
  138. slapi_log_error( SLAPI_LOG_FATAL, SYNC_PLUGIN_SUBSYSTEM,
  139. "unable to get arguments\n" );
  140. return( -1 );
  141. }
  142. sync_persist_initialize(argc, argv);
  143. return (0);
  144. }
  145. /*
  146. sync_close
  147. --------------
  148. Free locks and queues allocated.
  149. */
  150. static int
  151. sync_close(Slapi_PBlock * pb)
  152. {
  153. sync_persist_terminate_all();
  154. sync_unregister_operation_entension();
  155. return (0);
  156. }