windows_private.c 36 KB

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