windows_private.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412
  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) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /* windows_private.c */
  42. #include "repl.h"
  43. #include "repl5.h"
  44. #include "slap.h"
  45. #include "slapi-plugin.h"
  46. #include "winsync-plugin.h"
  47. #include "windowsrepl.h"
  48. struct windowsprivate {
  49. Slapi_DN *windows_subtree; /* DN of synchronized subtree (on the windows side) */
  50. Slapi_DN *directory_subtree; /* DN of synchronized subtree on directory side */
  51. /* this simplifies the mapping as it's simply
  52. from the former to the latter container, or
  53. vice versa */
  54. ber_int_t dirsync_flags;
  55. ber_int_t dirsync_maxattributecount;
  56. char *dirsync_cookie;
  57. int dirsync_cookie_len;
  58. PRBool dirsync_cookie_has_more;
  59. PRBool create_users_from_dirsync;
  60. PRBool create_groups_from_dirsync;
  61. char *windows_domain;
  62. int isnt4;
  63. int iswin2k3;
  64. /* This filter is used to determine if an entry belongs to this agreement. We put it here
  65. * so we only have to allocate each filter once instead of doing it every time we receive a change. */
  66. Slapi_Filter *directory_filter; /* Used for checking if local entries need to be sync'd to AD */
  67. Slapi_Filter *deleted_filter; /* Used for checking if an entry is an AD tombstone */
  68. Slapi_Entry *raw_entry; /* "raw" un-schema processed last entry read from AD */
  69. int keep_raw_entry; /* flag to control when the raw entry is set */
  70. void *api_cookie; /* private data used by api callbacks */
  71. time_t sync_interval; /* how often to run the dirsync search, in seconds */
  72. int one_way; /* Indicates if this is a one-way agreement and which direction it is */
  73. };
  74. static void windows_private_set_windows_domain(const Repl_Agmt *ra, char *domain);
  75. static int
  76. true_value_from_string(char *val)
  77. {
  78. if (strcasecmp (val, "on") == 0 || strcasecmp (val, "yes") == 0 ||
  79. strcasecmp (val, "true") == 0 || strcasecmp (val, "1") == 0)
  80. {
  81. return 1;
  82. } else
  83. {
  84. return 0;
  85. }
  86. }
  87. static int
  88. windows_parse_config_entry(Repl_Agmt *ra, const char *type, Slapi_Entry *e)
  89. {
  90. char *tmpstr = NULL;
  91. int retval = 0;
  92. if (type == NULL || slapi_attr_types_equivalent(type,type_nsds7WindowsReplicaArea))
  93. {
  94. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7WindowsReplicaArea);
  95. if (NULL != tmpstr)
  96. {
  97. windows_private_set_windows_subtree(ra, slapi_sdn_new_dn_passin(tmpstr) );
  98. }
  99. retval = 1;
  100. }
  101. if (type == NULL || slapi_attr_types_equivalent(type,type_nsds7DirectoryReplicaArea))
  102. {
  103. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7DirectoryReplicaArea);
  104. if (NULL != tmpstr)
  105. {
  106. windows_private_set_directory_subtree(ra, slapi_sdn_new_dn_passin(tmpstr) );
  107. }
  108. retval = 1;
  109. }
  110. if (type == NULL || slapi_attr_types_equivalent(type,type_nsds7CreateNewUsers))
  111. {
  112. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7CreateNewUsers);
  113. if (NULL != tmpstr && true_value_from_string(tmpstr))
  114. {
  115. windows_private_set_create_users(ra, PR_TRUE);
  116. }
  117. else
  118. {
  119. windows_private_set_create_users(ra, PR_FALSE);
  120. }
  121. retval = 1;
  122. slapi_ch_free((void**)&tmpstr);
  123. }
  124. if (type == NULL || slapi_attr_types_equivalent(type,type_nsds7CreateNewGroups))
  125. {
  126. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7CreateNewGroups);
  127. if (NULL != tmpstr && true_value_from_string(tmpstr))
  128. {
  129. windows_private_set_create_groups(ra, PR_TRUE);
  130. }
  131. else
  132. {
  133. windows_private_set_create_groups(ra, PR_FALSE);
  134. }
  135. retval = 1;
  136. slapi_ch_free((void**)&tmpstr);
  137. }
  138. if (type == NULL || slapi_attr_types_equivalent(type,type_nsds7WindowsDomain))
  139. {
  140. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7WindowsDomain);
  141. if (NULL != tmpstr)
  142. {
  143. windows_private_set_windows_domain(ra,tmpstr);
  144. }
  145. /* No need to free tmpstr because it was aliased by the call above */
  146. tmpstr = NULL;
  147. retval = 1;
  148. }
  149. if (type == NULL || slapi_attr_types_equivalent(type,type_winSyncInterval))
  150. {
  151. tmpstr = slapi_entry_attr_get_charptr(e, type_winSyncInterval);
  152. if (NULL != tmpstr)
  153. {
  154. windows_private_set_sync_interval(ra,tmpstr);
  155. }
  156. slapi_ch_free_string(&tmpstr);
  157. retval = 1;
  158. }
  159. if (type == NULL || slapi_attr_types_equivalent(type,type_oneWaySync))
  160. {
  161. tmpstr = slapi_entry_attr_get_charptr(e, type_oneWaySync);
  162. if (NULL != tmpstr)
  163. {
  164. if (strcasecmp(tmpstr, "fromWindows") == 0) {
  165. windows_private_set_one_way(ra, ONE_WAY_SYNC_FROM_AD);
  166. } else if (strcasecmp(tmpstr, "toWindows") == 0) {
  167. windows_private_set_one_way(ra, ONE_WAY_SYNC_TO_AD);
  168. } else {
  169. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  170. "Ignoring illegal setting for %s attribute in replication "
  171. "agreement \"%s\". Valid values are \"toWindows\" or "
  172. "\"fromWindows\".\n", type_oneWaySync, slapi_entry_get_dn(e));
  173. windows_private_set_one_way(ra, ONE_WAY_SYNC_DISABLED);
  174. }
  175. }
  176. else
  177. {
  178. windows_private_set_one_way(ra, ONE_WAY_SYNC_DISABLED);
  179. }
  180. slapi_ch_free((void**)&tmpstr);
  181. retval = 1;
  182. }
  183. return retval;
  184. }
  185. /* Returns non-zero if the modify was ok, zero if not */
  186. int
  187. windows_handle_modify_agreement(Repl_Agmt *ra, const char *type, Slapi_Entry *e)
  188. {
  189. /* Is this a Windows agreement ? */
  190. if (get_agmt_agreement_type(ra) == REPLICA_TYPE_WINDOWS)
  191. {
  192. return windows_parse_config_entry(ra,type,e);
  193. } else
  194. {
  195. return 0;
  196. }
  197. }
  198. void
  199. windows_init_agreement_from_entry(Repl_Agmt *ra, Slapi_Entry *e)
  200. {
  201. agmt_set_priv(ra,windows_private_new());
  202. windows_parse_config_entry(ra,NULL,e);
  203. windows_plugin_init(ra);
  204. }
  205. const char* windows_private_get_purl(const Repl_Agmt *ra)
  206. {
  207. const char* windows_purl;
  208. char *hostname;
  209. hostname = agmt_get_hostname(ra);
  210. windows_purl = slapi_ch_smprintf("ldap://%s:%d", hostname, agmt_get_port(ra));
  211. slapi_ch_free_string(&hostname);
  212. return windows_purl;
  213. }
  214. Dirsync_Private* windows_private_new()
  215. {
  216. Dirsync_Private *dp;
  217. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_new\n" );
  218. dp = (Dirsync_Private *)slapi_ch_calloc(sizeof(Dirsync_Private),1);
  219. dp->dirsync_maxattributecount = -1;
  220. dp->directory_filter = NULL;
  221. dp->deleted_filter = NULL;
  222. dp->sync_interval = PERIODIC_DIRSYNC_INTERVAL;
  223. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_new\n" );
  224. return dp;
  225. }
  226. void windows_agreement_delete(Repl_Agmt *ra)
  227. {
  228. Dirsync_Private *dp = (Dirsync_Private *) agmt_get_priv(ra);
  229. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_delete\n" );
  230. PR_ASSERT(dp != NULL);
  231. winsync_plugin_call_destroy_agmt_cb(ra, dp->directory_subtree,
  232. dp->windows_subtree);
  233. slapi_sdn_free(&dp->directory_subtree);
  234. slapi_sdn_free(&dp->windows_subtree);
  235. slapi_filter_free(dp->directory_filter, 1);
  236. slapi_filter_free(dp->deleted_filter, 1);
  237. slapi_entry_free(dp->raw_entry);
  238. dp->raw_entry = NULL;
  239. dp->api_cookie = NULL;
  240. slapi_ch_free((void **)dp);
  241. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_delete\n" );
  242. }
  243. int windows_private_get_isnt4(const Repl_Agmt *ra)
  244. {
  245. Dirsync_Private *dp;
  246. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_isnt4\n" );
  247. PR_ASSERT(ra);
  248. dp = (Dirsync_Private *) agmt_get_priv(ra);
  249. PR_ASSERT (dp);
  250. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_isnt4\n" );
  251. return dp->isnt4;
  252. }
  253. void windows_private_set_isnt4(const Repl_Agmt *ra, int isit)
  254. {
  255. Dirsync_Private *dp;
  256. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_isnt4\n" );
  257. PR_ASSERT(ra);
  258. dp = (Dirsync_Private *) agmt_get_priv(ra);
  259. PR_ASSERT (dp);
  260. dp->isnt4 = isit;
  261. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_isnt4\n" );
  262. }
  263. int windows_private_get_iswin2k3(const Repl_Agmt *ra)
  264. {
  265. Dirsync_Private *dp;
  266. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_iswin2k3\n" );
  267. PR_ASSERT(ra);
  268. dp = (Dirsync_Private *) agmt_get_priv(ra);
  269. PR_ASSERT (dp);
  270. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_iswin2k3\n" );
  271. return dp->iswin2k3;
  272. }
  273. void windows_private_set_iswin2k3(const Repl_Agmt *ra, int isit)
  274. {
  275. Dirsync_Private *dp;
  276. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_iswin2k3\n" );
  277. PR_ASSERT(ra);
  278. dp = (Dirsync_Private *) agmt_get_priv(ra);
  279. PR_ASSERT (dp);
  280. dp->iswin2k3 = isit;
  281. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_iswin2k3\n" );
  282. }
  283. /* Returns a copy of the Slapi_Filter pointer. The caller should not free it */
  284. Slapi_Filter* windows_private_get_directory_filter(const Repl_Agmt *ra)
  285. {
  286. Dirsync_Private *dp;
  287. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_directory_filter\n" );
  288. PR_ASSERT(ra);
  289. dp = (Dirsync_Private *) agmt_get_priv(ra);
  290. PR_ASSERT (dp);
  291. if (dp->directory_filter == NULL) {
  292. char *string_filter = slapi_ch_strdup("(&(|(objectclass=ntuser)(objectclass=ntgroup))(ntUserDomainId=*))");
  293. /* The filter gets freed in windows_agreement_delete() */
  294. dp->directory_filter = slapi_str2filter( string_filter );
  295. slapi_ch_free_string(&string_filter);
  296. }
  297. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_directory_filter\n" );
  298. return dp->directory_filter;
  299. }
  300. /* Returns a copy of the Slapi_Filter pointer. The caller should not free it */
  301. Slapi_Filter* windows_private_get_deleted_filter(const Repl_Agmt *ra)
  302. {
  303. Dirsync_Private *dp;
  304. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_deleted_filter\n" );
  305. PR_ASSERT(ra);
  306. dp = (Dirsync_Private *) agmt_get_priv(ra);
  307. PR_ASSERT (dp);
  308. if (dp->deleted_filter == NULL) {
  309. char *string_filter = slapi_ch_strdup("(isdeleted=*)");
  310. /* The filter gets freed in windows_agreement_delete() */
  311. dp->deleted_filter = slapi_str2filter( string_filter );
  312. slapi_ch_free_string(&string_filter);
  313. }
  314. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_deleted_filter\n" );
  315. return dp->deleted_filter;
  316. }
  317. /* Returns a copy of the Slapi_DN pointer, no need to free it */
  318. const Slapi_DN* windows_private_get_windows_subtree (const Repl_Agmt *ra)
  319. {
  320. Dirsync_Private *dp;
  321. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_windows_subtree\n" );
  322. PR_ASSERT(ra);
  323. dp = (Dirsync_Private *) agmt_get_priv(ra);
  324. PR_ASSERT (dp);
  325. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_windows_subtree\n" );
  326. return dp->windows_subtree;
  327. }
  328. const char *
  329. windows_private_get_windows_domain(const Repl_Agmt *ra)
  330. {
  331. Dirsync_Private *dp;
  332. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_windows_domain\n" );
  333. PR_ASSERT(ra);
  334. dp = (Dirsync_Private *) agmt_get_priv(ra);
  335. PR_ASSERT (dp);
  336. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_windows_domain\n" );
  337. return dp->windows_domain;
  338. }
  339. static void
  340. windows_private_set_windows_domain(const Repl_Agmt *ra, char *domain)
  341. {
  342. Dirsync_Private *dp;
  343. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_windows_domain\n" );
  344. PR_ASSERT(ra);
  345. dp = (Dirsync_Private *) agmt_get_priv(ra);
  346. PR_ASSERT (dp);
  347. dp->windows_domain = domain;
  348. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_windows_domain\n" );
  349. }
  350. /* Returns a copy of the Slapi_DN pointer, no need to free it */
  351. const Slapi_DN* windows_private_get_directory_subtree (const Repl_Agmt *ra)
  352. {
  353. Dirsync_Private *dp;
  354. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_directory_replarea\n" );
  355. PR_ASSERT(ra);
  356. dp = (Dirsync_Private *) agmt_get_priv(ra);
  357. PR_ASSERT (dp);
  358. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_directory_replarea\n" );
  359. return dp->directory_subtree;
  360. }
  361. /* Takes a copy of the sdn passed in */
  362. void windows_private_set_windows_subtree (const Repl_Agmt *ra,Slapi_DN* sdn )
  363. {
  364. Dirsync_Private *dp;
  365. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_windows_replarea\n" );
  366. PR_ASSERT(ra);
  367. PR_ASSERT(sdn);
  368. dp = (Dirsync_Private *) agmt_get_priv(ra);
  369. PR_ASSERT (dp);
  370. slapi_sdn_free(&dp->windows_subtree);
  371. dp->windows_subtree = sdn;
  372. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_windows_replarea\n" );
  373. }
  374. /* Takes a copy of the sdn passed in */
  375. void windows_private_set_directory_subtree (const Repl_Agmt *ra,Slapi_DN* sdn )
  376. {
  377. Dirsync_Private *dp;
  378. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_directory_replarea\n" );
  379. PR_ASSERT(ra);
  380. PR_ASSERT(sdn);
  381. dp = (Dirsync_Private *) agmt_get_priv(ra);
  382. PR_ASSERT (dp);
  383. slapi_sdn_free(&dp->directory_subtree);
  384. dp->directory_subtree = sdn;
  385. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_directory_replarea\n" );
  386. }
  387. PRBool windows_private_create_users(const Repl_Agmt *ra)
  388. {
  389. Dirsync_Private *dp;
  390. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_create_users\n" );
  391. PR_ASSERT(ra);
  392. dp = (Dirsync_Private *) agmt_get_priv(ra);
  393. PR_ASSERT (dp);
  394. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_create_users\n" );
  395. return dp->create_users_from_dirsync;
  396. }
  397. void windows_private_set_create_users(const Repl_Agmt *ra, PRBool value)
  398. {
  399. Dirsync_Private *dp;
  400. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_create_users\n" );
  401. PR_ASSERT(ra);
  402. dp = (Dirsync_Private *) agmt_get_priv(ra);
  403. PR_ASSERT (dp);
  404. dp->create_users_from_dirsync = value;
  405. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_create_users\n" );
  406. }
  407. PRBool windows_private_create_groups(const Repl_Agmt *ra)
  408. {
  409. Dirsync_Private *dp;
  410. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_create_groups\n" );
  411. PR_ASSERT(ra);
  412. dp = (Dirsync_Private *) agmt_get_priv(ra);
  413. PR_ASSERT (dp);
  414. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_create_groups\n" );
  415. return dp->create_groups_from_dirsync;
  416. }
  417. void windows_private_set_create_groups(const Repl_Agmt *ra, PRBool value)
  418. {
  419. Dirsync_Private *dp;
  420. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_create_groups\n" );
  421. PR_ASSERT(ra);
  422. dp = (Dirsync_Private *) agmt_get_priv(ra);
  423. PR_ASSERT (dp);
  424. dp->create_groups_from_dirsync = value;
  425. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_create_groups\n" );
  426. }
  427. int windows_private_get_one_way(const Repl_Agmt *ra)
  428. {
  429. Dirsync_Private *dp;
  430. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_one_way\n" );
  431. PR_ASSERT(ra);
  432. dp = (Dirsync_Private *) agmt_get_priv(ra);
  433. PR_ASSERT (dp);
  434. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_one_way\n" );
  435. return dp->one_way;
  436. }
  437. void windows_private_set_one_way(const Repl_Agmt *ra, int value)
  438. {
  439. Dirsync_Private *dp;
  440. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_one_way\n" );
  441. PR_ASSERT(ra);
  442. dp = (Dirsync_Private *) agmt_get_priv(ra);
  443. PR_ASSERT (dp);
  444. dp->one_way = value;
  445. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_one_way\n" );
  446. }
  447. /*
  448. This function returns the current Dirsync_Private that's inside
  449. Repl_Agmt ra as a ldap control.
  450. */
  451. LDAPControl* windows_private_dirsync_control(const Repl_Agmt *ra)
  452. {
  453. LDAPControl *control = NULL;
  454. BerElement *ber;
  455. Dirsync_Private *dp;
  456. char iscritical = PR_TRUE;
  457. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_dirsync_control\n" );
  458. PR_ASSERT(ra);
  459. dp = (Dirsync_Private *) agmt_get_priv(ra);
  460. PR_ASSERT (dp);
  461. ber = ber_alloc();
  462. ber_printf( ber, "{iio}", dp->dirsync_flags, dp->dirsync_maxattributecount, dp->dirsync_cookie ? dp->dirsync_cookie : "", dp->dirsync_cookie_len );
  463. /* Use a regular directory server instead of a real AD - for testing */
  464. if (getenv("WINSYNC_USE_DS")) {
  465. iscritical = PR_FALSE;
  466. }
  467. slapi_build_control( REPL_DIRSYNC_CONTROL_OID, ber, iscritical, &control);
  468. ber_free(ber,1);
  469. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_dirsync_control\n" );
  470. return control;
  471. }
  472. /*
  473. This function scans the array of controls and updates the Repl_Agmt's
  474. Dirsync_Private if the dirsync control is found.
  475. */
  476. void windows_private_update_dirsync_control(const Repl_Agmt *ra,LDAPControl **controls )
  477. {
  478. Dirsync_Private *dp;
  479. int foundDirsyncControl;
  480. int i;
  481. LDAPControl *dirsync = NULL;
  482. BerElement *ber = NULL;
  483. ber_int_t hasMoreData;
  484. ber_int_t maxAttributeCount;
  485. BerValue *serverCookie = NULL;
  486. #ifdef FOR_DEBUGGING
  487. int return_value = LDAP_SUCCESS;
  488. #endif
  489. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_update_dirsync_control\n" );
  490. PR_ASSERT(ra);
  491. dp = (Dirsync_Private *) agmt_get_priv(ra);
  492. PR_ASSERT (dp);
  493. if (NULL != controls )
  494. {
  495. foundDirsyncControl = 0;
  496. for ( i = 0; (( controls[i] != NULL ) && ( !foundDirsyncControl )); i++ ) {
  497. foundDirsyncControl = !strcmp( controls[i]->ldctl_oid, REPL_DIRSYNC_CONTROL_OID );
  498. }
  499. if ( !foundDirsyncControl )
  500. {
  501. #ifdef FOR_DEBUGGING
  502. return_value = LDAP_CONTROL_NOT_FOUND;
  503. #endif
  504. goto choke;
  505. }
  506. else if (!controls[i-1]->ldctl_value.bv_val) {
  507. #ifdef FOR_DEBUGGING
  508. return_value = LDAP_CONTROL_NOT_FOUND;
  509. #endif
  510. goto choke;
  511. }
  512. else
  513. {
  514. dirsync = slapi_dup_control( controls[i-1]);
  515. }
  516. ber = ber_init( &dirsync->ldctl_value ) ;
  517. if (ber_scanf( ber, "{iiO}", &hasMoreData, &maxAttributeCount, &serverCookie) == LBER_ERROR)
  518. {
  519. #ifdef FOR_DEBUGGING
  520. return_value = LDAP_CONTROL_NOT_FOUND;
  521. #endif
  522. goto choke;
  523. }
  524. slapi_ch_free_string(&dp->dirsync_cookie);
  525. dp->dirsync_cookie = ( char* ) slapi_ch_malloc(serverCookie->bv_len + 1);
  526. memcpy(dp->dirsync_cookie, serverCookie->bv_val, serverCookie->bv_len);
  527. dp->dirsync_cookie_len = (int) serverCookie->bv_len; /* XXX shouldn't cast? */
  528. /* dp->dirsync_maxattributecount = maxAttributeCount; We don't need to keep this */
  529. dp->dirsync_cookie_has_more = hasMoreData;
  530. choke:
  531. ber_bvfree(serverCookie);
  532. ber_free(ber,1);
  533. ldap_control_free(dirsync);
  534. }
  535. else
  536. {
  537. #ifdef FOR_DEBUGGING
  538. return_value = LDAP_CONTROL_NOT_FOUND;
  539. #endif
  540. }
  541. #ifdef FOR_DEBUGGING
  542. LDAPDebug1Arg( LDAP_DEBUG_TRACE, "<= windows_private_update_dirsync_control: rc=%d\n", return_value);
  543. #else
  544. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_update_dirsync_control\n" );
  545. #endif
  546. }
  547. PRBool windows_private_dirsync_has_more(const Repl_Agmt *ra)
  548. {
  549. Dirsync_Private *dp;
  550. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_dirsync_has_more\n" );
  551. PR_ASSERT(ra);
  552. dp = (Dirsync_Private *) agmt_get_priv(ra);
  553. PR_ASSERT (dp);
  554. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_dirsync_has_more\n" );
  555. return dp->dirsync_cookie_has_more;
  556. }
  557. void windows_private_null_dirsync_cookie(const Repl_Agmt *ra)
  558. {
  559. Dirsync_Private *dp;
  560. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_null_dirsync_control\n" );
  561. dp = (Dirsync_Private *) agmt_get_priv(ra);
  562. PR_ASSERT (dp);
  563. dp->dirsync_cookie_len = 0;
  564. slapi_ch_free_string(&dp->dirsync_cookie);
  565. dp->dirsync_cookie = NULL;
  566. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_null_dirsync_control\n" );
  567. }
  568. static
  569. Slapi_Mods *windows_private_get_cookie_mod(Dirsync_Private *dp, int modtype)
  570. {
  571. Slapi_Mods *smods = NULL;
  572. smods = slapi_mods_new();
  573. slapi_mods_add( smods, modtype,
  574. "nsds7DirsyncCookie", dp->dirsync_cookie_len , dp->dirsync_cookie);
  575. return smods;
  576. }
  577. /* writes the current cookie into dse.ldif under the replication agreement entry
  578. returns: ldap result code of the operation. */
  579. int
  580. windows_private_save_dirsync_cookie(const Repl_Agmt *ra)
  581. {
  582. Dirsync_Private *dp = NULL;
  583. Slapi_PBlock *pb = NULL;
  584. const char* dn = NULL;
  585. Slapi_DN* sdn = NULL;
  586. int rc = 0;
  587. Slapi_Mods *mods = NULL;
  588. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_save_dirsync_cookie\n" );
  589. PR_ASSERT(ra);
  590. dp = (Dirsync_Private *) agmt_get_priv(ra);
  591. PR_ASSERT (dp);
  592. pb = slapi_pblock_new ();
  593. mods = windows_private_get_cookie_mod(dp, LDAP_MOD_REPLACE);
  594. sdn = slapi_sdn_dup( agmt_get_dn_byref(ra) );
  595. dn = slapi_sdn_get_dn(sdn);
  596. slapi_modify_internal_set_pb (pb, dn, slapi_mods_get_ldapmods_byref(mods), NULL, NULL,
  597. repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION), 0);
  598. slapi_modify_internal_pb (pb);
  599. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  600. if (rc == LDAP_NO_SUCH_ATTRIBUTE)
  601. { /* try again, but as an add instead */
  602. slapi_mods_free(&mods);
  603. mods = windows_private_get_cookie_mod(dp, LDAP_MOD_ADD);
  604. slapi_modify_internal_set_pb (pb, dn, slapi_mods_get_ldapmods_byref(mods), NULL, NULL,
  605. repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION), 0);
  606. slapi_modify_internal_pb (pb);
  607. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  608. }
  609. slapi_pblock_destroy (pb);
  610. slapi_mods_free(&mods);
  611. slapi_sdn_free(&sdn);
  612. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_save_dirsync_cookie\n" );
  613. return rc;
  614. }
  615. /* reads the cookie in dse.ldif to the replication agreement entry
  616. returns: ldap result code of ldap operation, or
  617. LDAP_NO_SUCH_ATTRIBUTE. (this is the equilivent of a null cookie) */
  618. int windows_private_load_dirsync_cookie(const Repl_Agmt *ra)
  619. {
  620. Dirsync_Private *dp = NULL;
  621. Slapi_PBlock *pb = NULL;
  622. Slapi_DN* sdn = NULL;
  623. int rc = 0;
  624. Slapi_Entry *entry = NULL;
  625. Slapi_Attr *attr = NULL;
  626. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_load_dirsync_cookie\n" );
  627. PR_ASSERT(ra);
  628. dp = (Dirsync_Private *) agmt_get_priv(ra);
  629. PR_ASSERT (dp);
  630. pb = slapi_pblock_new ();
  631. sdn = slapi_sdn_dup( agmt_get_dn_byref(ra) );
  632. rc = slapi_search_internal_get_entry(sdn, NULL, &entry,
  633. repl_get_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION));
  634. if (rc == 0)
  635. {
  636. rc= slapi_entry_attr_find( entry, type_nsds7DirsyncCookie, &attr );
  637. if (attr)
  638. {
  639. struct berval **vals;
  640. rc = slapi_attr_get_bervals_copy(attr, &vals );
  641. if (vals)
  642. {
  643. dp->dirsync_cookie_len = (int) (vals[0])->bv_len;
  644. slapi_ch_free_string(&dp->dirsync_cookie);
  645. dp->dirsync_cookie = ( char* ) slapi_ch_malloc(dp->dirsync_cookie_len + 1);
  646. memcpy(dp->dirsync_cookie,(vals[0]->bv_val), (vals[0])->bv_len+1);
  647. }
  648. ber_bvecfree(vals);
  649. /* we do not free attr */
  650. }
  651. else
  652. {
  653. rc = LDAP_NO_SUCH_ATTRIBUTE;
  654. }
  655. }
  656. if (entry)
  657. {
  658. slapi_entry_free(entry);
  659. }
  660. slapi_sdn_free( &sdn);
  661. slapi_pblock_destroy (pb);
  662. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_load_dirsync_cookie\n" );
  663. return rc;
  664. }
  665. /* get returns a pointer to the structure - do not free */
  666. Slapi_Entry *windows_private_get_raw_entry(const Repl_Agmt *ra)
  667. {
  668. Dirsync_Private *dp;
  669. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_raw_entry\n" );
  670. dp = (Dirsync_Private *) agmt_get_priv(ra);
  671. PR_ASSERT (dp);
  672. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_raw_entry\n" );
  673. return dp->raw_entry;
  674. }
  675. /* this is passin - windows_private owns the pointer, not a copy */
  676. void windows_private_set_raw_entry(const Repl_Agmt *ra, Slapi_Entry *e)
  677. {
  678. Dirsync_Private *dp;
  679. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_raw_entry\n" );
  680. dp = (Dirsync_Private *) agmt_get_priv(ra);
  681. PR_ASSERT (dp);
  682. /* If the keep raw entry flag is set, just free the passed
  683. * in entry and leave the current raw entry in place. */
  684. if (windows_private_get_keep_raw_entry(ra)) {
  685. slapi_entry_free(e);
  686. } else {
  687. slapi_entry_free(dp->raw_entry);
  688. dp->raw_entry = e;
  689. }
  690. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_raw_entry\n" );
  691. }
  692. /* Setting keep to 1 will cause the current raw entry to remain, even if
  693. * windows_private_set_raw_entry() is called. This behavior will persist
  694. * until this flag is set back to 0. */
  695. void windows_private_set_keep_raw_entry(const Repl_Agmt *ra, int keep)
  696. {
  697. Dirsync_Private *dp;
  698. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_keep_raw_entry\n" );
  699. dp = (Dirsync_Private *) agmt_get_priv(ra);
  700. PR_ASSERT (dp);
  701. dp->keep_raw_entry = keep;
  702. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_keep_raw_entry\n" );
  703. }
  704. int windows_private_get_keep_raw_entry(const Repl_Agmt *ra)
  705. {
  706. Dirsync_Private *dp;
  707. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_keep_raw_entry\n" );
  708. dp = (Dirsync_Private *) agmt_get_priv(ra);
  709. PR_ASSERT (dp);
  710. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_keep_raw_entry\n" );
  711. return dp->keep_raw_entry;
  712. }
  713. void *windows_private_get_api_cookie(const Repl_Agmt *ra)
  714. {
  715. Dirsync_Private *dp;
  716. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_api_cookie\n" );
  717. dp = (Dirsync_Private *) agmt_get_priv(ra);
  718. PR_ASSERT (dp);
  719. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_api_cookie\n" );
  720. return dp->api_cookie;
  721. }
  722. void windows_private_set_api_cookie(Repl_Agmt *ra, void *api_cookie)
  723. {
  724. Dirsync_Private *dp;
  725. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_api_cookie\n" );
  726. dp = (Dirsync_Private *) agmt_get_priv(ra);
  727. PR_ASSERT (dp);
  728. dp->api_cookie = api_cookie;
  729. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_api_cookie\n" );
  730. }
  731. time_t
  732. windows_private_get_sync_interval(const Repl_Agmt *ra)
  733. {
  734. Dirsync_Private *dp;
  735. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_sync_interval\n" );
  736. PR_ASSERT(ra);
  737. dp = (Dirsync_Private *) agmt_get_priv(ra);
  738. PR_ASSERT (dp);
  739. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_sync_interval\n" );
  740. return dp->sync_interval;
  741. }
  742. void
  743. windows_private_set_sync_interval(Repl_Agmt *ra, char *str)
  744. {
  745. Dirsync_Private *dp;
  746. time_t tmpval = 0;
  747. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_sync_interval\n" );
  748. PR_ASSERT(ra);
  749. dp = (Dirsync_Private *) agmt_get_priv(ra);
  750. PR_ASSERT (dp);
  751. if (str && (tmpval = (time_t)atol(str))) {
  752. dp->sync_interval = tmpval;
  753. }
  754. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_sync_interval\n" );
  755. }
  756. /* an array of function pointers */
  757. static void **_WinSyncAPI = NULL;
  758. void
  759. windows_plugin_init(Repl_Agmt *ra)
  760. {
  761. void *cookie = NULL;
  762. winsync_plugin_init_cb initfunc = NULL;
  763. LDAPDebug0Args( LDAP_DEBUG_PLUGIN, "--> windows_plugin_init_start -- begin\n");
  764. /* if the function pointer array is null, get the functions - we will
  765. call init once per replication agreement, but will only grab the
  766. api once */
  767. if((NULL == _WinSyncAPI) &&
  768. (slapi_apib_get_interface(WINSYNC_v1_0_GUID, &_WinSyncAPI) ||
  769. (NULL == _WinSyncAPI)))
  770. {
  771. LDAPDebug1Arg( LDAP_DEBUG_PLUGIN,
  772. "<-- windows_plugin_init_start -- no windows plugin API registered for GUID [%s] -- end\n",
  773. WINSYNC_v1_0_GUID);
  774. return;
  775. }
  776. initfunc = (winsync_plugin_init_cb)_WinSyncAPI[WINSYNC_PLUGIN_INIT_CB];
  777. if (initfunc) {
  778. cookie = (*initfunc)(windows_private_get_directory_subtree(ra),
  779. windows_private_get_windows_subtree(ra));
  780. }
  781. windows_private_set_api_cookie(ra, cookie);
  782. LDAPDebug0Args( LDAP_DEBUG_PLUGIN, "<-- windows_plugin_init_start -- end\n");
  783. return;
  784. }
  785. void
  786. winsync_plugin_call_dirsync_search_params_cb(const Repl_Agmt *ra, const char *agmt_dn,
  787. char **base, int *scope, char **filter,
  788. char ***attrs, LDAPControl ***serverctrls)
  789. {
  790. winsync_search_params_cb thefunc =
  791. (_WinSyncAPI && _WinSyncAPI[WINSYNC_PLUGIN_DIRSYNC_SEARCH_CB]) ?
  792. (winsync_search_params_cb)_WinSyncAPI[WINSYNC_PLUGIN_DIRSYNC_SEARCH_CB] :
  793. NULL;
  794. if (!thefunc) {
  795. return;
  796. }
  797. (*thefunc)(windows_private_get_api_cookie(ra), agmt_dn, base, scope, filter,
  798. attrs, serverctrls);
  799. return;
  800. }
  801. void
  802. winsync_plugin_call_pre_ad_search_cb(const Repl_Agmt *ra, const char *agmt_dn,
  803. char **base, int *scope, char **filter,
  804. char ***attrs, LDAPControl ***serverctrls)
  805. {
  806. winsync_search_params_cb thefunc =
  807. (_WinSyncAPI && _WinSyncAPI[WINSYNC_PLUGIN_PRE_AD_SEARCH_CB]) ?
  808. (winsync_search_params_cb)_WinSyncAPI[WINSYNC_PLUGIN_PRE_AD_SEARCH_CB] :
  809. NULL;
  810. if (!thefunc) {
  811. return;
  812. }
  813. (*thefunc)(windows_private_get_api_cookie(ra), agmt_dn, base, scope, filter,
  814. attrs, serverctrls);
  815. return;
  816. }
  817. void
  818. winsync_plugin_call_pre_ds_search_entry_cb(const Repl_Agmt *ra, const char *agmt_dn,
  819. char **base, int *scope, char **filter,
  820. char ***attrs, LDAPControl ***serverctrls)
  821. {
  822. winsync_search_params_cb thefunc =
  823. (_WinSyncAPI && _WinSyncAPI[WINSYNC_PLUGIN_PRE_DS_SEARCH_ENTRY_CB]) ?
  824. (winsync_search_params_cb)_WinSyncAPI[WINSYNC_PLUGIN_PRE_DS_SEARCH_ENTRY_CB] :
  825. NULL;
  826. if (!thefunc) {
  827. return;
  828. }
  829. (*thefunc)(windows_private_get_api_cookie(ra), agmt_dn, base, scope, filter,
  830. attrs, serverctrls);
  831. return;
  832. }
  833. void
  834. winsync_plugin_call_pre_ds_search_all_cb(const Repl_Agmt *ra, const char *agmt_dn,
  835. char **base, int *scope, char **filter,
  836. char ***attrs, LDAPControl ***serverctrls)
  837. {
  838. winsync_search_params_cb thefunc =
  839. (_WinSyncAPI && _WinSyncAPI[WINSYNC_PLUGIN_PRE_DS_SEARCH_ALL_CB]) ?
  840. (winsync_search_params_cb)_WinSyncAPI[WINSYNC_PLUGIN_PRE_DS_SEARCH_ALL_CB] :
  841. NULL;
  842. if (!thefunc) {
  843. return;
  844. }
  845. (*thefunc)(windows_private_get_api_cookie(ra), agmt_dn, base, scope, filter,
  846. attrs, serverctrls);
  847. return;
  848. }
  849. void
  850. winsync_plugin_call_pre_ad_mod_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  851. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  852. Slapi_Mods *smods, int *do_modify)
  853. {
  854. winsync_pre_mod_cb thefunc =
  855. (_WinSyncAPI && _WinSyncAPI[WINSYNC_PLUGIN_PRE_AD_MOD_USER_CB]) ?
  856. (winsync_pre_mod_cb)_WinSyncAPI[WINSYNC_PLUGIN_PRE_AD_MOD_USER_CB] :
  857. NULL;
  858. if (!thefunc) {
  859. return;
  860. }
  861. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  862. ds_entry, smods, do_modify);
  863. return;
  864. }
  865. void
  866. winsync_plugin_call_pre_ad_mod_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  867. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  868. Slapi_Mods *smods, int *do_modify)
  869. {
  870. winsync_pre_mod_cb thefunc =
  871. (_WinSyncAPI && _WinSyncAPI[WINSYNC_PLUGIN_PRE_AD_MOD_GROUP_CB]) ?
  872. (winsync_pre_mod_cb)_WinSyncAPI[WINSYNC_PLUGIN_PRE_AD_MOD_GROUP_CB] :
  873. NULL;
  874. if (!thefunc) {
  875. return;
  876. }
  877. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  878. ds_entry, smods, do_modify);
  879. return;
  880. }
  881. void
  882. winsync_plugin_call_pre_ds_mod_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  883. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  884. Slapi_Mods *smods, int *do_modify)
  885. {
  886. winsync_pre_mod_cb thefunc =
  887. (_WinSyncAPI && _WinSyncAPI[WINSYNC_PLUGIN_PRE_DS_MOD_USER_CB]) ?
  888. (winsync_pre_mod_cb)_WinSyncAPI[WINSYNC_PLUGIN_PRE_DS_MOD_USER_CB] :
  889. NULL;
  890. if (!thefunc) {
  891. return;
  892. }
  893. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  894. ds_entry, smods, do_modify);
  895. return;
  896. }
  897. void
  898. winsync_plugin_call_pre_ds_mod_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  899. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  900. Slapi_Mods *smods, int *do_modify)
  901. {
  902. winsync_pre_mod_cb thefunc =
  903. (_WinSyncAPI && _WinSyncAPI[WINSYNC_PLUGIN_PRE_DS_MOD_GROUP_CB]) ?
  904. (winsync_pre_mod_cb)_WinSyncAPI[WINSYNC_PLUGIN_PRE_DS_MOD_GROUP_CB] :
  905. NULL;
  906. if (!thefunc) {
  907. return;
  908. }
  909. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  910. ds_entry, smods, do_modify);
  911. return;
  912. }
  913. void
  914. winsync_plugin_call_pre_ds_add_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  915. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry)
  916. {
  917. winsync_pre_add_cb thefunc =
  918. (_WinSyncAPI && _WinSyncAPI[WINSYNC_PLUGIN_PRE_DS_ADD_USER_CB]) ?
  919. (winsync_pre_add_cb)_WinSyncAPI[WINSYNC_PLUGIN_PRE_DS_ADD_USER_CB] :
  920. NULL;
  921. if (!thefunc) {
  922. return;
  923. }
  924. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  925. ds_entry);
  926. return;
  927. }
  928. void
  929. winsync_plugin_call_pre_ds_add_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  930. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry)
  931. {
  932. winsync_pre_add_cb thefunc =
  933. (_WinSyncAPI && _WinSyncAPI[WINSYNC_PLUGIN_PRE_DS_ADD_GROUP_CB]) ?
  934. (winsync_pre_add_cb)_WinSyncAPI[WINSYNC_PLUGIN_PRE_DS_ADD_GROUP_CB] :
  935. NULL;
  936. if (!thefunc) {
  937. return;
  938. }
  939. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  940. ds_entry);
  941. return;
  942. }
  943. void
  944. winsync_plugin_call_get_new_ds_user_dn_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  945. Slapi_Entry *ad_entry, char **new_dn_string,
  946. const Slapi_DN *ds_suffix, const Slapi_DN *ad_suffix)
  947. {
  948. winsync_get_new_dn_cb thefunc =
  949. (_WinSyncAPI && _WinSyncAPI[WINSYNC_PLUGIN_GET_NEW_DS_USER_DN_CB]) ?
  950. (winsync_get_new_dn_cb)_WinSyncAPI[WINSYNC_PLUGIN_GET_NEW_DS_USER_DN_CB] :
  951. NULL;
  952. if (!thefunc) {
  953. return;
  954. }
  955. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  956. new_dn_string, ds_suffix, ad_suffix);
  957. return;
  958. }
  959. void
  960. winsync_plugin_call_get_new_ds_group_dn_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  961. Slapi_Entry *ad_entry, char **new_dn_string,
  962. const Slapi_DN *ds_suffix, const Slapi_DN *ad_suffix)
  963. {
  964. winsync_get_new_dn_cb thefunc =
  965. (_WinSyncAPI && _WinSyncAPI[WINSYNC_PLUGIN_GET_NEW_DS_GROUP_DN_CB]) ?
  966. (winsync_get_new_dn_cb)_WinSyncAPI[WINSYNC_PLUGIN_GET_NEW_DS_GROUP_DN_CB] :
  967. NULL;
  968. if (!thefunc) {
  969. return;
  970. }
  971. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  972. new_dn_string, ds_suffix, ad_suffix);
  973. return;
  974. }
  975. void
  976. winsync_plugin_call_pre_ad_mod_user_mods_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  977. const Slapi_DN *local_dn,
  978. const Slapi_Entry *ds_entry,
  979. LDAPMod * const *origmods,
  980. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  981. {
  982. winsync_pre_ad_mod_mods_cb thefunc =
  983. (_WinSyncAPI && _WinSyncAPI[WINSYNC_PLUGIN_PRE_AD_MOD_USER_MODS_CB]) ?
  984. (winsync_pre_ad_mod_mods_cb)_WinSyncAPI[WINSYNC_PLUGIN_PRE_AD_MOD_USER_MODS_CB] :
  985. NULL;
  986. if (!thefunc) {
  987. return;
  988. }
  989. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, local_dn,
  990. ds_entry, origmods, remote_dn, modstosend);
  991. return;
  992. }
  993. void
  994. winsync_plugin_call_pre_ad_mod_group_mods_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  995. const Slapi_DN *local_dn,
  996. const Slapi_Entry *ds_entry,
  997. LDAPMod * const *origmods,
  998. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  999. {
  1000. winsync_pre_ad_mod_mods_cb thefunc =
  1001. (_WinSyncAPI && _WinSyncAPI[WINSYNC_PLUGIN_PRE_AD_MOD_GROUP_MODS_CB]) ?
  1002. (winsync_pre_ad_mod_mods_cb)_WinSyncAPI[WINSYNC_PLUGIN_PRE_AD_MOD_GROUP_MODS_CB] :
  1003. NULL;
  1004. if (!thefunc) {
  1005. return;
  1006. }
  1007. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, local_dn,
  1008. ds_entry, origmods, remote_dn, modstosend);
  1009. return;
  1010. }
  1011. int
  1012. winsync_plugin_call_can_add_entry_to_ad_cb(const Repl_Agmt *ra, const Slapi_Entry *local_entry,
  1013. const Slapi_DN *remote_dn)
  1014. {
  1015. winsync_can_add_to_ad_cb thefunc =
  1016. (_WinSyncAPI && _WinSyncAPI[WINSYNC_PLUGIN_CAN_ADD_ENTRY_TO_AD_CB]) ?
  1017. (winsync_can_add_to_ad_cb)_WinSyncAPI[WINSYNC_PLUGIN_CAN_ADD_ENTRY_TO_AD_CB] :
  1018. NULL;
  1019. if (!thefunc) {
  1020. return 1; /* default is entry can be added to AD */
  1021. }
  1022. return (*thefunc)(windows_private_get_api_cookie(ra), local_entry, remote_dn);
  1023. }
  1024. void
  1025. winsync_plugin_call_begin_update_cb(const Repl_Agmt *ra, const Slapi_DN *ds_subtree,
  1026. const Slapi_DN *ad_subtree, int is_total)
  1027. {
  1028. winsync_plugin_update_cb thefunc =
  1029. (_WinSyncAPI && _WinSyncAPI[WINSYNC_PLUGIN_BEGIN_UPDATE_CB]) ?
  1030. (winsync_plugin_update_cb)_WinSyncAPI[WINSYNC_PLUGIN_BEGIN_UPDATE_CB] :
  1031. NULL;
  1032. if (!thefunc) {
  1033. return;
  1034. }
  1035. (*thefunc)(windows_private_get_api_cookie(ra), ds_subtree, ad_subtree, is_total);
  1036. return;
  1037. }
  1038. void
  1039. winsync_plugin_call_end_update_cb(const Repl_Agmt *ra, const Slapi_DN *ds_subtree,
  1040. const Slapi_DN *ad_subtree, int is_total)
  1041. {
  1042. winsync_plugin_update_cb thefunc =
  1043. (_WinSyncAPI && _WinSyncAPI[WINSYNC_PLUGIN_END_UPDATE_CB]) ?
  1044. (winsync_plugin_update_cb)_WinSyncAPI[WINSYNC_PLUGIN_END_UPDATE_CB] :
  1045. NULL;
  1046. if (!thefunc) {
  1047. return;
  1048. }
  1049. (*thefunc)(windows_private_get_api_cookie(ra), ds_subtree, ad_subtree, is_total);
  1050. return;
  1051. }
  1052. void
  1053. winsync_plugin_call_destroy_agmt_cb(const Repl_Agmt *ra,
  1054. const Slapi_DN *ds_subtree,
  1055. const Slapi_DN *ad_subtree)
  1056. {
  1057. winsync_plugin_destroy_agmt_cb thefunc =
  1058. (_WinSyncAPI && _WinSyncAPI[WINSYNC_PLUGIN_DESTROY_AGMT_CB]) ?
  1059. (winsync_plugin_destroy_agmt_cb)_WinSyncAPI[WINSYNC_PLUGIN_DESTROY_AGMT_CB] :
  1060. NULL;
  1061. if (thefunc) {
  1062. (*thefunc)(windows_private_get_api_cookie(ra), ds_subtree, ad_subtree);
  1063. }
  1064. return;
  1065. }
  1066. /* #define WINSYNC_TEST_IPA */
  1067. #ifdef WINSYNC_TEST_IPA
  1068. #include "ipa-winsync.c"
  1069. #include "ipa-winsync-config.c"
  1070. #endif