winsync-plugin.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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, const Slapi_DN *ds_suffix, const Slapi_DN *ad_suffix);
  100. #define WINSYNC_PLUGIN_GET_NEW_DS_USER_DN_CB 12
  101. #define WINSYNC_PLUGIN_GET_NEW_DS_GROUP_DN_CB 13
  102. /*
  103. * These callbacks are called when a mod operation is going to be replayed
  104. * to AD. This case is different than the pre add or pre mod callbacks
  105. * above because in this context, we may only have the list of modifications
  106. * and the DN to which the mods were applied.
  107. * rawentry - the raw AD entry, read directly from AD - may be NULL
  108. * local_dn - the original local DN used in the modification
  109. * ds_entry - the current DS entry that has the operation nsUniqueID
  110. * origmods - the original mod list
  111. * remote_dn - this is the DN which will be used with the remote modify operation
  112. * to AD - the winsync code may have already attempted to calculate its value
  113. * modstosend - this is the list of modifications which will be sent - the winsync
  114. * code will already have done its default mapping to these values
  115. *
  116. */
  117. 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);
  118. #define WINSYNC_PLUGIN_PRE_AD_MOD_USER_MODS_CB 14
  119. #define WINSYNC_PLUGIN_PRE_AD_MOD_GROUP_MODS_CB 15
  120. /*
  121. * Callbacks used to determine if an entry should be added to the
  122. * AD side if it does not already exist.
  123. * local_entry - the candidate entry to test
  124. * remote_DN - the candidate remote entry to add
  125. */
  126. typedef int (*winsync_can_add_to_ad_cb)(void *cookie, const Slapi_Entry *local_entry, const Slapi_DN *remote_dn);
  127. #define WINSYNC_PLUGIN_CAN_ADD_ENTRY_TO_AD_CB 16
  128. /*
  129. * Callbacks called at begin and end of update
  130. *
  131. * The ds subtree and the ad subtree from the sync agreement are passed in.
  132. * These are read only.
  133. * is_total will be true if this is a total update, or false if this
  134. * is an incremental update
  135. */
  136. typedef void (*winsync_plugin_update_cb)(void *cookie, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree, int is_total);
  137. #define WINSYNC_PLUGIN_BEGIN_UPDATE_CB 17
  138. #define WINSYNC_PLUGIN_END_UPDATE_CB 18
  139. /*
  140. * Callbacks called when the agreement is destroyed.
  141. *
  142. * The ds subtree and the ad subtree from the sync agreement are passed in.
  143. * These are read only.
  144. * The plugin must define this function to free the cookie allocated
  145. * in the init function, if any.
  146. */
  147. typedef void (*winsync_plugin_destroy_agmt_cb)(void *cookie, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree);
  148. #define WINSYNC_PLUGIN_DESTROY_AGMT_CB 19
  149. #define WINSYNC_PLUGIN_VERSION_1_END WINSYNC_PLUGIN_DESTROY_AGMT_CB
  150. /* Functions added for API version 2.0 */
  151. /*
  152. * These callbacks are called after a modify operation. They are called upon both
  153. * success and failure of the modify operation. The plugin is responsible for
  154. * looking at the result code of the modify to decide what action to take. The
  155. * plugin may change the result code e.g. to force an error for an otherwise
  156. * successful operation, or to ignore certain errors.
  157. * rawentry - the raw AD entry, read directly from AD - this is read only
  158. * ad_entry - the "cooked" AD entry - the entry passed to the pre_mod callback
  159. * ds_entry - the entry from the ds - the DS entry passed to the pre_mod callback
  160. * smods - the mods used in the modify operation
  161. * result - the result code from the modify operation - the plugin can change this
  162. */
  163. 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);
  164. #define WINSYNC_PLUGIN_POST_AD_MOD_USER_CB 20
  165. #define WINSYNC_PLUGIN_POST_AD_MOD_GROUP_CB 21
  166. #define WINSYNC_PLUGIN_POST_DS_MOD_USER_CB 22
  167. #define WINSYNC_PLUGIN_POST_DS_MOD_GROUP_CB 23
  168. #define WINSYNC_PLUGIN_VERSION_2_BEGIN WINSYNC_PLUGIN_POST_AD_MOD_USER_CB
  169. /*
  170. * These callbacks are called after an attempt to add a new entry to the
  171. * local directory server from AD. They are called upon success or failure
  172. * of the add attempt. The result code tells if the operation succeeded.
  173. * The plugin may change the result code e.g. to force an error for an
  174. * otherwise successful operation, or to ignore certain errors.
  175. * rawentry - the raw AD entry, read directly from AD - this is read only
  176. * ad_entry - the "cooked" AD entry
  177. * ds_entry - the entry attempted to be added to the DS
  178. * result - the result code from the add operation - plugin may change this
  179. */
  180. typedef void (*winsync_post_add_cb)(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result);
  181. #define WINSYNC_PLUGIN_POST_DS_ADD_USER_CB 24
  182. #define WINSYNC_PLUGIN_POST_DS_ADD_GROUP_CB 25
  183. /*
  184. * These callbacks are called when a new entry is being added to AD from
  185. * the local directory server.
  186. * ds_entry - the local DS entry
  187. * ad_entry - the entry to be added to AD - all modifications should
  188. * be made to this entry, including changing the DN if needed,
  189. * since the DN of this entry will be used as the ADD target DN
  190. * This entry will already have had the default schema mapping applied
  191. */
  192. typedef void (*winsync_pre_ad_add_cb)(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry);
  193. #define WINSYNC_PLUGIN_PRE_AD_ADD_USER_CB 26
  194. #define WINSYNC_PLUGIN_PRE_AD_ADD_GROUP_CB 27
  195. /*
  196. * These callbacks are called after an attempt to add a new entry to AD from
  197. * the local directory server. They are called upon success or failure
  198. * of the add attempt. The result code tells if the operation succeeded.
  199. * The plugin may change the result code e.g. to force an error for an
  200. * otherwise successful operation, or to ignore certain errors.
  201. * ad_entry - the AD entry
  202. * ds_entry - the DS entry
  203. * result - the result code from the add operation - plugin may change this
  204. */
  205. typedef void (*winsync_post_ad_add_cb)(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry, int *result);
  206. #define WINSYNC_PLUGIN_POST_AD_ADD_USER_CB 28
  207. #define WINSYNC_PLUGIN_POST_AD_ADD_GROUP_CB 29
  208. /*
  209. * These callbacks are called after a mod operation has been replayed
  210. * to AD. This case is different than the pre add or pre mod callbacks
  211. * above because in this context, we may only have the list of modifications
  212. * and the DN to which the mods were applied. If the plugin wants the modified
  213. * entry, the plugin can search for it from AD. The plugin is called upon
  214. * success or failure of the modify operation. The result parameter gives
  215. * the ldap result code of the operation. The plugin may change the result code
  216. * e.g. to force an error for an otherwise successful operation, or to ignore
  217. * certain errors.
  218. * rawentry - the raw AD entry, read directly from AD - may be NULL
  219. * local_dn - the original local DN used in the modification
  220. * ds_entry - the current DS entry that has the operation nsUniqueID
  221. * origmods - the original mod list
  222. * remote_dn - the DN of the AD entry
  223. * modstosend - the mods sent to AD
  224. * result - the result code of the modify operation
  225. *
  226. */
  227. 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);
  228. #define WINSYNC_PLUGIN_POST_AD_MOD_USER_MODS_CB 30
  229. #define WINSYNC_PLUGIN_POST_AD_MOD_GROUP_MODS_CB 31
  230. #define WINSYNC_PLUGIN_VERSION_2_END WINSYNC_PLUGIN_POST_AD_MOD_GROUP_MODS_CB
  231. typedef int (*winsync_plugin_precedence_cb)(void);
  232. #define WINSYNC_PLUGIN_PRECEDENCE_CB 32
  233. #define WINSYNC_PLUGIN_VERSION_3_END WINSYNC_PLUGIN_PRECEDENCE_CB
  234. /* precedence works like regular slapi plugin precedence */
  235. #define WINSYNC_PLUGIN_DEFAULT_PRECEDENCE 50
  236. #endif /* WINSYNC_PLUGIN_PUBLIC_API */