1
0

sync_init.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2013 Red Hat, Inc.
  3. * All rights reserved.
  4. *
  5. * License: GPL (version 3 or any later version).
  6. * See LICENSE for details.
  7. * END COPYRIGHT BLOCK **/
  8. #include "sync.h"
  9. static Slapi_PluginDesc pdesc = { PLUGIN_NAME, VENDOR, DS_PACKAGE_VERSION, "Context Synchronization (RFC4533) plugin" };
  10. static int sync_start(Slapi_PBlock * pb);
  11. static int sync_close(Slapi_PBlock * pb);
  12. static int sync_preop_init( Slapi_PBlock *pb );
  13. static int sync_postop_init( Slapi_PBlock *pb );
  14. int sync_init( Slapi_PBlock *pb )
  15. {
  16. char *plugin_identity = NULL;
  17. int rc = 0;
  18. slapi_log_error(SLAPI_LOG_TRACE, SYNC_PLUGIN_SUBSYSTEM,
  19. "--> sync_init\n");
  20. /**
  21. * Store the plugin identity for later use.
  22. * Used for internal operations
  23. */
  24. slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &plugin_identity);
  25. PR_ASSERT(plugin_identity);
  26. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION,
  27. SLAPI_PLUGIN_VERSION_01) != 0 ||
  28. slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN,
  29. (void *) sync_start) != 0 ||
  30. slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN,
  31. (void *) sync_close) != 0 ||
  32. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION,
  33. (void *) &pdesc) != 0 ) {
  34. slapi_log_error(SLAPI_LOG_FATAL, SYNC_PLUGIN_SUBSYSTEM,
  35. "sync_init: failed to register plugin\n");
  36. rc = 1;
  37. }
  38. if (rc == 0) {
  39. char *plugin_type = "preoperation";
  40. /* the config change checking post op */
  41. if (slapi_register_plugin(
  42. plugin_type,
  43. 1, /* Enabled */
  44. "sync_init", /* this function desc */
  45. sync_preop_init,/* init func for post op */
  46. SYNC_PREOP_DESC,/* plugin desc */
  47. NULL,
  48. plugin_identity)) {
  49. slapi_log_error(SLAPI_LOG_FATAL, SYNC_PLUGIN_SUBSYSTEM,
  50. "sync_init: failed to register preop plugin\n");
  51. rc = 1;
  52. }
  53. }
  54. if (rc == 0) {
  55. char *plugin_type = "postoperation";
  56. /* the config change checking post op */
  57. if (slapi_register_plugin(plugin_type,
  58. 1, /* Enabled */
  59. "sync_init", /* this function desc */
  60. sync_postop_init, /* init func for post op */
  61. SYNC_POSTOP_DESC, /* plugin desc */
  62. NULL,
  63. plugin_identity )) {
  64. slapi_log_error(SLAPI_LOG_FATAL, SYNC_PLUGIN_SUBSYSTEM,
  65. "sync_init: failed to register postop plugin\n");
  66. rc = 1;
  67. }
  68. }
  69. return( rc );
  70. }
  71. static int
  72. sync_preop_init( Slapi_PBlock *pb )
  73. {
  74. int rc;
  75. rc = slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_SEARCH_FN, (void *) sync_srch_refresh_pre_search);
  76. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ENTRY_FN, (void *) sync_srch_refresh_pre_entry);
  77. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_RESULT_FN, (void *) sync_srch_refresh_pre_result);
  78. rc |= sync_register_operation_extension();
  79. return(rc);
  80. }
  81. static int
  82. sync_postop_init( Slapi_PBlock *pb )
  83. {
  84. int rc;
  85. rc = slapi_pblock_set(pb, SLAPI_PLUGIN_POST_ADD_FN, (void *) sync_add_persist_post_op);
  86. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_POST_DELETE_FN, (void *) sync_del_persist_post_op);
  87. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODIFY_FN, (void *) sync_mod_persist_post_op);
  88. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODRDN_FN, (void *) sync_modrdn_persist_post_op);
  89. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_POST_SEARCH_FN, (void *) sync_srch_refresh_post_search);
  90. return(rc);
  91. }
  92. /*
  93. sync_start
  94. --------------
  95. Register the Content Synchronization Control.
  96. Initialize locks and queues for the persitent phase.
  97. */
  98. static int
  99. sync_start(Slapi_PBlock * pb)
  100. {
  101. int argc;
  102. char **argv;
  103. slapi_register_supported_control( LDAP_CONTROL_SYNC,
  104. SLAPI_OPERATION_SEARCH );
  105. slapi_log_error(SLAPI_LOG_TRACE, SYNC_PLUGIN_SUBSYSTEM,
  106. "--> sync_start\n");
  107. if ( slapi_pblock_get( pb, SLAPI_PLUGIN_ARGC, &argc ) != 0 ||
  108. slapi_pblock_get( pb, SLAPI_PLUGIN_ARGV, &argv ) != 0 ) {
  109. slapi_log_error( SLAPI_LOG_FATAL, SYNC_PLUGIN_SUBSYSTEM,
  110. "unable to get arguments\n" );
  111. return( -1 );
  112. }
  113. sync_persist_initialize(argc, argv);
  114. return (0);
  115. }
  116. /*
  117. sync_close
  118. --------------
  119. Free locks and queues allocated.
  120. */
  121. static int
  122. sync_close(Slapi_PBlock * pb)
  123. {
  124. sync_persist_terminate_all();
  125. sync_unregister_operation_entension();
  126. return (0);
  127. }