winsync-plugin.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2008 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. #ifndef WINSYNC_PLUGIN_PUBLIC_API
  9. #define WINSYNC_PLUGIN_PUBLIC_API
  10. /* windows_private.c */
  11. #include "slapi-plugin.h"
  12. /*
  13. * WinSync plug-in API
  14. */
  15. #define WINSYNC_v1_0_GUID "CDA8F029-A3C6-4EBB-80B8-A2E183DB0481"
  16. #define WINSYNC_v2_0_GUID "706B83AA-FC51-444A-ACC9-53DC73D641D4"
  17. #define WINSYNC_v3_0_GUID "6D7C2E54-638C-4564-B53F-D9C5354DEBA0"
  18. /*
  19. * This callback is called when a winsync agreement is created.
  20. * The ds_subtree and ad_subtree from the agreement are read-only.
  21. * The callback can allocate some private data to return. If so
  22. * the callback must define a winsync_plugin_destroy_agmt_cb so
  23. * that the private data can be freed. This private data is passed
  24. * to every other callback function as the void *cookie argument.
  25. */
  26. typedef void * (*winsync_plugin_init_cb)(const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree);
  27. #define WINSYNC_PLUGIN_INIT_CB 1
  28. #define WINSYNC_PLUGIN_VERSION_1_BEGIN WINSYNC_PLUGIN_INIT_CB
  29. /* agmt_dn - const - the original AD base dn from the winsync agreement
  30. scope - set directly e.g. *scope = 42;
  31. base, filter - malloced - to set, free first e.g.
  32. slapi_ch_free_string(filter);
  33. *base = slapi_ch_strdup("(objectclass=foobar)");
  34. winsync code will use slapi_ch_free_string to free this value, so no static strings
  35. attrs - NULL or null terminated array of strings - can use slapi_ch_array_add to add e.g.
  36. slapi_ch_array_add(attrs, slapi_ch_strdup("myattr"));
  37. attrs will be freed with slapi_ch_array_free, so caller must own the memory
  38. serverctrls - NULL or null terminated array of LDAPControl* - can use slapi_add_control_ext to add
  39. slapi_add_control_ext(serverctrls, mynewctrl, 1 / add a copy /);
  40. serverctrls will be freed with ldap_controls_free, so caller must own memory
  41. */
  42. typedef void (*winsync_search_params_cb)(void *cookie, const char *agmt_dn, char **base, int *scope, char **filter, char ***attrs, LDAPControl ***serverctrls);
  43. #define WINSYNC_PLUGIN_DIRSYNC_SEARCH_CB 2 /* serverctrls will already contain the DirSync control */
  44. #define WINSYNC_PLUGIN_PRE_AD_SEARCH_CB 3
  45. #define WINSYNC_PLUGIN_PRE_DS_SEARCH_ENTRY_CB 4
  46. #define WINSYNC_PLUGIN_PRE_DS_SEARCH_ALL_CB 5
  47. /*
  48. * These callbacks are the main entry points that allow the plugin
  49. * to intercept modifications to local and remote entries.
  50. * rawentry - the raw AD entry, read directly from AD - this is read only
  51. * ad_entry - the "cooked" AD entry - the DN in this entry should be set
  52. * when the operation is to modify the AD entry
  53. * ds_entry - the entry from the ds - the DN in this entry should be set
  54. * when the operation is to modify the DS entry
  55. * smods - the post-processing modifications - these should be modified
  56. * by the plugin as needed
  57. * do_modify - if the code has some modifications that need to be applied, this
  58. * will be set to true - if the plugin has added some items to smods
  59. * this should be set to true - if the plugin has removed all of
  60. * the smods, and no operation should be performed, this should
  61. * be set to false
  62. */
  63. typedef void (*winsync_pre_mod_cb)(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, Slapi_Mods *smods, int *do_modify);
  64. #define WINSYNC_PLUGIN_PRE_AD_MOD_USER_CB 6
  65. #define WINSYNC_PLUGIN_PRE_AD_MOD_GROUP_CB 7
  66. #define WINSYNC_PLUGIN_PRE_DS_MOD_USER_CB 8
  67. #define WINSYNC_PLUGIN_PRE_DS_MOD_GROUP_CB 9
  68. /*
  69. * These callbacks are called when a new entry is being added to the
  70. * local directory server from AD.
  71. * rawentry - the raw AD entry, read directly from AD - this is read only
  72. * ad_entry - the "cooked" AD entry
  73. * ds_entry - the entry to be added to the DS - all modifications should
  74. * be made to this entry, including changing the DN if needed,
  75. * since the DN of this entry will be used as the ADD target DN
  76. * This entry will already have had the default schema mapping applied
  77. */
  78. typedef void (*winsync_pre_add_cb)(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry);
  79. #define WINSYNC_PLUGIN_PRE_DS_ADD_USER_CB 10
  80. #define WINSYNC_PLUGIN_PRE_DS_ADD_GROUP_CB 11
  81. /*
  82. * If a new entry has been added to AD, and we're sync'ing it over
  83. * to the DS, we may need to create a new DN for the entry. The
  84. * code tries to come up with a reasonable DN, but the plugin may
  85. * have different ideas. These callbacks allow the plugin to specify
  86. * what the new DN for the new entry should be. This is called from
  87. * map_entry_dn_inbound which is called from various places where the DN for
  88. * the new entry is needed. The winsync_plugin_call_pre_ds_add_* callbacks
  89. * can also be used to set the DN just before the entry is stored in the DS.
  90. * This is also used when we are mapping a dn valued attribute e.g. owner
  91. * or secretary
  92. * rawentry - the raw AD entry, read directly from AD - this is read only
  93. * ad_entry - the "cooked" AD entry
  94. * new_dn_string - the given value will be the default value created by the sync code
  95. * to change it, slapi_ch_free_string first, then malloc the value to use
  96. * ds_suffix - the suffix from the DS side of the sync agreement
  97. * ad_suffix - the suffix from the AD side of the sync agreement
  98. */
  99. typedef void (*winsync_get_new_dn_cb)(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, char **new_dn_string,
  100. const Slapi_DN *ds_suffix, const Slapi_DN *ad_suffix);
  101. #define WINSYNC_PLUGIN_GET_NEW_DS_USER_DN_CB 12
  102. #define WINSYNC_PLUGIN_GET_NEW_DS_GROUP_DN_CB 13
  103. /*
  104. * These callbacks are called when a mod operation is going to be replayed
  105. * to AD. This case is different than the pre add or pre mod callbacks
  106. * above because in this context, we may only have the list of modifications
  107. * and the DN to which the mods were applied.
  108. * rawentry - the raw AD entry, read directly from AD - may be NULL
  109. * local_dn - the original local DN used in the modification
  110. * ds_entry - the current DS entry that has the operation nsUniqueID
  111. * origmods - the original mod list
  112. * remote_dn - this is the DN which will be used with the remote modify operation
  113. * to AD - the winsync code may have already attempted to calculate its value
  114. * modstosend - this is the list of modifications which will be sent - the winsync
  115. * code will already have done its default mapping to these values
  116. *
  117. */
  118. typedef void (*winsync_pre_ad_mod_mods_cb)(void *cookie, const Slapi_Entry *rawentry, const Slapi_DN *local_dn, const Slapi_Entry *ds_entry, LDAPMod * const *origmods, Slapi_DN *remote_dn, LDAPMod ***modstosend);
  119. #define WINSYNC_PLUGIN_PRE_AD_MOD_USER_MODS_CB 14
  120. #define WINSYNC_PLUGIN_PRE_AD_MOD_GROUP_MODS_CB 15
  121. /*
  122. * Callbacks used to determine if an entry should be added to the
  123. * AD side if it does not already exist.
  124. * local_entry - the candidate entry to test
  125. * remote_DN - the candidate remote entry to add
  126. */
  127. typedef int (*winsync_can_add_to_ad_cb)(void *cookie, const Slapi_Entry *local_entry, const Slapi_DN *remote_dn);
  128. #define WINSYNC_PLUGIN_CAN_ADD_ENTRY_TO_AD_CB 16
  129. /*
  130. * Callbacks called at begin and end of update
  131. *
  132. * The ds subtree and the ad subtree from the sync agreement are passed in.
  133. * These are read only.
  134. * is_total will be true if this is a total update, or false if this
  135. * is an incremental update
  136. */
  137. typedef void (*winsync_plugin_update_cb)(void *cookie, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree, int is_total);
  138. #define WINSYNC_PLUGIN_BEGIN_UPDATE_CB 17
  139. #define WINSYNC_PLUGIN_END_UPDATE_CB 18
  140. /*
  141. * Callbacks called when the agreement is destroyed.
  142. *
  143. * The ds subtree and the ad subtree from the sync agreement are passed in.
  144. * These are read only.
  145. * The plugin must define this function to free the cookie allocated
  146. * in the init function, if any.
  147. */
  148. typedef void (*winsync_plugin_destroy_agmt_cb)(void *cookie, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree);
  149. #define WINSYNC_PLUGIN_DESTROY_AGMT_CB 19
  150. #define WINSYNC_PLUGIN_VERSION_1_END WINSYNC_PLUGIN_DESTROY_AGMT_CB
  151. /* Functions added for API version 2.0 */
  152. /*
  153. * These callbacks are called after a modify operation. They are called upon both
  154. * success and failure of the modify operation. The plugin is responsible for
  155. * looking at the result code of the modify to decide what action to take. The
  156. * plugin may change the result code e.g. to force an error for an otherwise
  157. * successful operation, or to ignore certain errors.
  158. * rawentry - the raw AD entry, read directly from AD - this is read only
  159. * ad_entry - the "cooked" AD entry - the entry passed to the pre_mod callback
  160. * ds_entry - the entry from the ds - the DS entry passed to the pre_mod callback
  161. * smods - the mods used in the modify operation
  162. * result - the result code from the modify operation - the plugin can change this
  163. */
  164. typedef void (*winsync_post_mod_cb)(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, Slapi_Mods *smods, int *result);
  165. #define WINSYNC_PLUGIN_POST_AD_MOD_USER_CB 20
  166. #define WINSYNC_PLUGIN_POST_AD_MOD_GROUP_CB 21
  167. #define WINSYNC_PLUGIN_POST_DS_MOD_USER_CB 22
  168. #define WINSYNC_PLUGIN_POST_DS_MOD_GROUP_CB 23
  169. #define WINSYNC_PLUGIN_VERSION_2_BEGIN WINSYNC_PLUGIN_POST_AD_MOD_USER_CB
  170. /*
  171. * These callbacks are called after an attempt to add a new entry to the
  172. * local directory server from AD. They are called upon success or failure
  173. * of the add attempt. The result code tells if the operation succeeded.
  174. * The plugin may change the result code e.g. to force an error for an
  175. * otherwise successful operation, or to ignore certain errors.
  176. * rawentry - the raw AD entry, read directly from AD - this is read only
  177. * ad_entry - the "cooked" AD entry
  178. * ds_entry - the entry attempted to be added to the DS
  179. * result - the result code from the add operation - plugin may change this
  180. */
  181. typedef void (*winsync_post_add_cb)(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result);
  182. #define WINSYNC_PLUGIN_POST_DS_ADD_USER_CB 24
  183. #define WINSYNC_PLUGIN_POST_DS_ADD_GROUP_CB 25
  184. /*
  185. * These callbacks are called when a new entry is being added to AD from
  186. * the local directory server.
  187. * ds_entry - the local DS entry
  188. * ad_entry - the entry to be added to AD - all modifications should
  189. * be made to this entry, including changing the DN if needed,
  190. * since the DN of this entry will be used as the ADD target DN
  191. * This entry will already have had the default schema mapping applied
  192. */
  193. typedef void (*winsync_pre_ad_add_cb)(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry);
  194. #define WINSYNC_PLUGIN_PRE_AD_ADD_USER_CB 26
  195. #define WINSYNC_PLUGIN_PRE_AD_ADD_GROUP_CB 27
  196. /*
  197. * These callbacks are called after an attempt to add a new entry to AD from
  198. * the local directory server. They are called upon success or failure
  199. * of the add attempt. The result code tells if the operation succeeded.
  200. * The plugin may change the result code e.g. to force an error for an
  201. * otherwise successful operation, or to ignore certain errors.
  202. * ad_entry - the AD entry
  203. * ds_entry - the DS entry
  204. * result - the result code from the add operation - plugin may change this
  205. */
  206. typedef void (*winsync_post_ad_add_cb)(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry, int *result);
  207. #define WINSYNC_PLUGIN_POST_AD_ADD_USER_CB 28
  208. #define WINSYNC_PLUGIN_POST_AD_ADD_GROUP_CB 29
  209. /*
  210. * These callbacks are called after a mod operation has been replayed
  211. * to AD. This case is different than the pre add or pre mod callbacks
  212. * above because in this context, we may only have the list of modifications
  213. * and the DN to which the mods were applied. If the plugin wants the modified
  214. * entry, the plugin can search for it from AD. The plugin is called upon
  215. * success or failure of the modify operation. The result parameter gives
  216. * the ldap result code of the operation. The plugin may change the result code
  217. * e.g. to force an error for an otherwise successful operation, or to ignore
  218. * certain errors.
  219. * rawentry - the raw AD entry, read directly from AD - may be NULL
  220. * local_dn - the original local DN used in the modification
  221. * ds_entry - the current DS entry that has the operation nsUniqueID
  222. * origmods - the original mod list
  223. * remote_dn - the DN of the AD entry
  224. * modstosend - the mods sent to AD
  225. * result - the result code of the modify operation
  226. *
  227. */
  228. typedef void (*winsync_post_ad_mod_mods_cb)(void *cookie, const Slapi_Entry *rawentry, const Slapi_DN *local_dn, const Slapi_Entry *ds_entry, LDAPMod * const *origmods, Slapi_DN *remote_dn, LDAPMod **modstosend, int *result);
  229. #define WINSYNC_PLUGIN_POST_AD_MOD_USER_MODS_CB 30
  230. #define WINSYNC_PLUGIN_POST_AD_MOD_GROUP_MODS_CB 31
  231. #define WINSYNC_PLUGIN_VERSION_2_END WINSYNC_PLUGIN_POST_AD_MOD_GROUP_MODS_CB
  232. typedef int (*winsync_plugin_precedence_cb)(void);
  233. #define WINSYNC_PLUGIN_PRECEDENCE_CB 32
  234. #define WINSYNC_PLUGIN_VERSION_3_END WINSYNC_PLUGIN_PRECEDENCE_CB
  235. /* precedence works like regular slapi plugin precedence */
  236. #define WINSYNC_PLUGIN_DEFAULT_PRECEDENCE 50
  237. #endif /* WINSYNC_PLUGIN_PUBLIC_API */