sync_init.c 4.7 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
  15. sync_init(Slapi_PBlock *pb)
  16. {
  17. char *plugin_identity = NULL;
  18. int rc = 0;
  19. slapi_log_err(SLAPI_LOG_TRACE, SYNC_PLUGIN_SUBSYSTEM,
  20. "--> sync_init\n");
  21. /**
  22. * Store the plugin identity for later use.
  23. * Used for internal operations
  24. */
  25. slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &plugin_identity);
  26. PR_ASSERT(plugin_identity);
  27. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION,
  28. SLAPI_PLUGIN_VERSION_01) != 0 ||
  29. slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN,
  30. (void *)sync_start) != 0 ||
  31. slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN,
  32. (void *)sync_close) != 0 ||
  33. slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION,
  34. (void *)&pdesc) != 0) {
  35. slapi_log_err(SLAPI_LOG_ERR, SYNC_PLUGIN_SUBSYSTEM,
  36. "sync_init - Failed to register plugin\n");
  37. rc = 1;
  38. }
  39. if (rc == 0) {
  40. char *plugin_type = "preoperation";
  41. /* the config change checking post op */
  42. if (slapi_register_plugin(
  43. plugin_type,
  44. 1, /* Enabled */
  45. "sync_init", /* this function desc */
  46. sync_preop_init, /* init func for post op */
  47. SYNC_PREOP_DESC, /* plugin desc */
  48. NULL,
  49. plugin_identity)) {
  50. slapi_log_err(SLAPI_LOG_ERR, SYNC_PLUGIN_SUBSYSTEM,
  51. "sync_init - Failed to register preop plugin\n");
  52. rc = 1;
  53. }
  54. }
  55. if (rc == 0) {
  56. char *plugin_type = "postoperation";
  57. /* the config change checking post op */
  58. if (slapi_register_plugin(plugin_type,
  59. 1, /* Enabled */
  60. "sync_init", /* this function desc */
  61. sync_postop_init, /* init func for post op */
  62. SYNC_POSTOP_DESC, /* plugin desc */
  63. NULL,
  64. plugin_identity)) {
  65. slapi_log_err(SLAPI_LOG_ERR, SYNC_PLUGIN_SUBSYSTEM,
  66. "sync_init - Failed to register postop plugin\n");
  67. rc = 1;
  68. }
  69. }
  70. return (rc);
  71. }
  72. static int
  73. sync_preop_init(Slapi_PBlock *pb)
  74. {
  75. int rc;
  76. rc = slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_SEARCH_FN, (void *)sync_srch_refresh_pre_search);
  77. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ENTRY_FN, (void *)sync_srch_refresh_pre_entry);
  78. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_RESULT_FN, (void *)sync_srch_refresh_pre_result);
  79. rc |= sync_register_operation_extension();
  80. return (rc);
  81. }
  82. static int
  83. sync_postop_init(Slapi_PBlock *pb)
  84. {
  85. int rc;
  86. rc = slapi_pblock_set(pb, SLAPI_PLUGIN_POST_ADD_FN, (void *)sync_add_persist_post_op);
  87. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_POST_DELETE_FN, (void *)sync_del_persist_post_op);
  88. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODIFY_FN, (void *)sync_mod_persist_post_op);
  89. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODRDN_FN, (void *)sync_modrdn_persist_post_op);
  90. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_POST_SEARCH_FN, (void *)sync_srch_refresh_post_search);
  91. return (rc);
  92. }
  93. /*
  94. sync_start
  95. --------------
  96. Register the Content Synchronization Control.
  97. Initialize locks and queues for the persitent phase.
  98. */
  99. static int
  100. sync_start(Slapi_PBlock *pb)
  101. {
  102. int argc;
  103. char **argv;
  104. slapi_register_supported_control(LDAP_CONTROL_SYNC,
  105. SLAPI_OPERATION_SEARCH);
  106. slapi_log_err(SLAPI_LOG_TRACE, SYNC_PLUGIN_SUBSYSTEM,
  107. "--> sync_start\n");
  108. if (slapi_pblock_get(pb, SLAPI_PLUGIN_ARGC, &argc) != 0 ||
  109. slapi_pblock_get(pb, SLAPI_PLUGIN_ARGV, &argv) != 0) {
  110. slapi_log_err(SLAPI_LOG_ERR, SYNC_PLUGIN_SUBSYSTEM,
  111. "sync_start - Unable to get arguments\n");
  112. return (-1);
  113. }
  114. sync_persist_initialize(argc, argv);
  115. return (0);
  116. }
  117. /*
  118. sync_close
  119. --------------
  120. Free locks and queues allocated.
  121. */
  122. static int
  123. sync_close(Slapi_PBlock *pb __attribute__((unused)))
  124. {
  125. sync_persist_terminate_all();
  126. sync_unregister_operation_entension();
  127. return (0);
  128. }