1
0

windows_private.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580
  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. Slapi_DN* sdn = NULL;
  585. int rc = 0;
  586. Slapi_Mods *mods = NULL;
  587. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_save_dirsync_cookie\n" );
  588. PR_ASSERT(ra);
  589. dp = (Dirsync_Private *) agmt_get_priv(ra);
  590. PR_ASSERT (dp);
  591. pb = slapi_pblock_new ();
  592. mods = windows_private_get_cookie_mod(dp, LDAP_MOD_REPLACE);
  593. sdn = slapi_sdn_dup( agmt_get_dn_byref(ra) );
  594. slapi_modify_internal_set_pb_ext (pb, sdn,
  595. slapi_mods_get_ldapmods_byref(mods), NULL, NULL,
  596. repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION), 0);
  597. slapi_modify_internal_pb (pb);
  598. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  599. if (rc == LDAP_NO_SUCH_ATTRIBUTE)
  600. { /* try again, but as an add instead */
  601. slapi_mods_free(&mods);
  602. mods = windows_private_get_cookie_mod(dp, LDAP_MOD_ADD);
  603. slapi_modify_internal_set_pb_ext (pb, sdn,
  604. 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. static int maxapiidx = WINSYNC_PLUGIN_VERSION_1_END;
  759. #define DECL_WINSYNC_API_FUNC(idx,thetype,thefunc) \
  760. thetype thefunc = (_WinSyncAPI && (idx <= maxapiidx) && _WinSyncAPI[idx]) ? \
  761. (thetype)_WinSyncAPI[idx] : NULL;
  762. void
  763. windows_plugin_init(Repl_Agmt *ra)
  764. {
  765. void *cookie = NULL;
  766. winsync_plugin_init_cb initfunc = NULL;
  767. LDAPDebug0Args( LDAP_DEBUG_PLUGIN, "--> windows_plugin_init_start -- begin\n");
  768. /* if the function pointer array is null, get the functions - we will
  769. call init once per replication agreement, but will only grab the
  770. api once */
  771. if(NULL == _WinSyncAPI) {
  772. if (slapi_apib_get_interface(WINSYNC_v2_0_GUID, &_WinSyncAPI) ||
  773. (NULL == _WinSyncAPI))
  774. {
  775. LDAPDebug1Arg( LDAP_DEBUG_PLUGIN,
  776. "<-- windows_plugin_init_start -- no windows plugin API registered for GUID [%s] -- end\n",
  777. WINSYNC_v2_0_GUID);
  778. } else if (_WinSyncAPI) {
  779. LDAPDebug1Arg( LDAP_DEBUG_PLUGIN,
  780. "<-- windows_plugin_init_start -- found windows plugin API registered for GUID [%s] -- end\n",
  781. WINSYNC_v2_0_GUID);
  782. maxapiidx = WINSYNC_PLUGIN_VERSION_2_END;
  783. }
  784. }
  785. if (NULL == _WinSyncAPI) { /* no v2 interface - look for v1 */
  786. if (slapi_apib_get_interface(WINSYNC_v1_0_GUID, &_WinSyncAPI) ||
  787. (NULL == _WinSyncAPI))
  788. {
  789. LDAPDebug1Arg( LDAP_DEBUG_PLUGIN,
  790. "<-- windows_plugin_init_start -- no windows plugin API registered for GUID [%s] -- end\n",
  791. WINSYNC_v1_0_GUID);
  792. return;
  793. } else {
  794. LDAPDebug1Arg( LDAP_DEBUG_PLUGIN,
  795. "<-- windows_plugin_init_start -- found windows plugin API registered for GUID [%s] -- end\n",
  796. WINSYNC_v1_0_GUID);
  797. }
  798. }
  799. initfunc = (winsync_plugin_init_cb)_WinSyncAPI[WINSYNC_PLUGIN_INIT_CB];
  800. if (initfunc) {
  801. cookie = (*initfunc)(windows_private_get_directory_subtree(ra),
  802. windows_private_get_windows_subtree(ra));
  803. }
  804. windows_private_set_api_cookie(ra, cookie);
  805. LDAPDebug0Args( LDAP_DEBUG_PLUGIN, "<-- windows_plugin_init_start -- end\n");
  806. return;
  807. }
  808. void
  809. winsync_plugin_call_dirsync_search_params_cb(const Repl_Agmt *ra, const char *agmt_dn,
  810. char **base, int *scope, char **filter,
  811. char ***attrs, LDAPControl ***serverctrls)
  812. {
  813. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_DIRSYNC_SEARCH_CB,winsync_search_params_cb,thefunc);
  814. if (!thefunc) {
  815. return;
  816. }
  817. (*thefunc)(windows_private_get_api_cookie(ra), agmt_dn, base, scope, filter,
  818. attrs, serverctrls);
  819. return;
  820. }
  821. void
  822. winsync_plugin_call_pre_ad_search_cb(const Repl_Agmt *ra, const char *agmt_dn,
  823. char **base, int *scope, char **filter,
  824. char ***attrs, LDAPControl ***serverctrls)
  825. {
  826. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_AD_SEARCH_CB,winsync_search_params_cb,thefunc);
  827. if (!thefunc) {
  828. return;
  829. }
  830. (*thefunc)(windows_private_get_api_cookie(ra), agmt_dn, base, scope, filter,
  831. attrs, serverctrls);
  832. return;
  833. }
  834. void
  835. winsync_plugin_call_pre_ds_search_entry_cb(const Repl_Agmt *ra, const char *agmt_dn,
  836. char **base, int *scope, char **filter,
  837. char ***attrs, LDAPControl ***serverctrls)
  838. {
  839. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_DS_SEARCH_ENTRY_CB,winsync_search_params_cb,thefunc);
  840. if (!thefunc) {
  841. return;
  842. }
  843. (*thefunc)(windows_private_get_api_cookie(ra), agmt_dn, base, scope, filter,
  844. attrs, serverctrls);
  845. return;
  846. }
  847. void
  848. winsync_plugin_call_pre_ds_search_all_cb(const Repl_Agmt *ra, const char *agmt_dn,
  849. char **base, int *scope, char **filter,
  850. char ***attrs, LDAPControl ***serverctrls)
  851. {
  852. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_DS_SEARCH_ALL_CB,winsync_search_params_cb,thefunc);
  853. if (!thefunc) {
  854. return;
  855. }
  856. (*thefunc)(windows_private_get_api_cookie(ra), agmt_dn, base, scope, filter,
  857. attrs, serverctrls);
  858. return;
  859. }
  860. void
  861. winsync_plugin_call_pre_ad_mod_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  862. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  863. Slapi_Mods *smods, int *do_modify)
  864. {
  865. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_AD_MOD_USER_CB,winsync_pre_mod_cb,thefunc);
  866. if (!thefunc) {
  867. return;
  868. }
  869. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  870. ds_entry, smods, do_modify);
  871. return;
  872. }
  873. void
  874. winsync_plugin_call_pre_ad_mod_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  875. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  876. Slapi_Mods *smods, int *do_modify)
  877. {
  878. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_AD_MOD_GROUP_CB,winsync_pre_mod_cb,thefunc);
  879. if (!thefunc) {
  880. return;
  881. }
  882. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  883. ds_entry, smods, do_modify);
  884. return;
  885. }
  886. void
  887. winsync_plugin_call_pre_ds_mod_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  888. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  889. Slapi_Mods *smods, int *do_modify)
  890. {
  891. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_DS_MOD_USER_CB,winsync_pre_mod_cb,thefunc);
  892. if (!thefunc) {
  893. return;
  894. }
  895. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  896. ds_entry, smods, do_modify);
  897. return;
  898. }
  899. void
  900. winsync_plugin_call_pre_ds_mod_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  901. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  902. Slapi_Mods *smods, int *do_modify)
  903. {
  904. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_DS_MOD_GROUP_CB,winsync_pre_mod_cb,thefunc);
  905. if (!thefunc) {
  906. return;
  907. }
  908. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  909. ds_entry, smods, do_modify);
  910. return;
  911. }
  912. void
  913. winsync_plugin_call_pre_ds_add_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  914. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry)
  915. {
  916. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_DS_ADD_USER_CB,winsync_pre_add_cb,thefunc);
  917. if (!thefunc) {
  918. return;
  919. }
  920. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  921. ds_entry);
  922. return;
  923. }
  924. void
  925. winsync_plugin_call_pre_ds_add_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  926. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry)
  927. {
  928. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_DS_ADD_GROUP_CB,winsync_pre_add_cb,thefunc);
  929. if (!thefunc) {
  930. return;
  931. }
  932. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  933. ds_entry);
  934. return;
  935. }
  936. void
  937. winsync_plugin_call_get_new_ds_user_dn_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  938. Slapi_Entry *ad_entry, char **new_dn_string,
  939. const Slapi_DN *ds_suffix, const Slapi_DN *ad_suffix)
  940. {
  941. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_GET_NEW_DS_USER_DN_CB,winsync_get_new_dn_cb,thefunc);
  942. if (!thefunc) {
  943. return;
  944. }
  945. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  946. new_dn_string, ds_suffix, ad_suffix);
  947. return;
  948. }
  949. void
  950. winsync_plugin_call_get_new_ds_group_dn_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  951. Slapi_Entry *ad_entry, char **new_dn_string,
  952. const Slapi_DN *ds_suffix, const Slapi_DN *ad_suffix)
  953. {
  954. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_GET_NEW_DS_GROUP_DN_CB,winsync_get_new_dn_cb,thefunc);
  955. if (!thefunc) {
  956. return;
  957. }
  958. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  959. new_dn_string, ds_suffix, ad_suffix);
  960. return;
  961. }
  962. void
  963. winsync_plugin_call_pre_ad_mod_user_mods_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  964. const Slapi_DN *local_dn,
  965. const Slapi_Entry *ds_entry,
  966. LDAPMod * const *origmods,
  967. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  968. {
  969. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_AD_MOD_USER_MODS_CB,winsync_pre_ad_mod_mods_cb,thefunc);
  970. if (!thefunc) {
  971. return;
  972. }
  973. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, local_dn,
  974. ds_entry, origmods, remote_dn, modstosend);
  975. return;
  976. }
  977. void
  978. winsync_plugin_call_pre_ad_mod_group_mods_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  979. const Slapi_DN *local_dn,
  980. const Slapi_Entry *ds_entry,
  981. LDAPMod * const *origmods,
  982. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  983. {
  984. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_AD_MOD_GROUP_MODS_CB,winsync_pre_ad_mod_mods_cb,thefunc);
  985. if (!thefunc) {
  986. return;
  987. }
  988. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, local_dn,
  989. ds_entry, origmods, remote_dn, modstosend);
  990. return;
  991. }
  992. int
  993. winsync_plugin_call_can_add_entry_to_ad_cb(const Repl_Agmt *ra, const Slapi_Entry *local_entry,
  994. const Slapi_DN *remote_dn)
  995. {
  996. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_CAN_ADD_ENTRY_TO_AD_CB,winsync_can_add_to_ad_cb,thefunc);
  997. if (!thefunc) {
  998. return 1; /* default is entry can be added to AD */
  999. }
  1000. return (*thefunc)(windows_private_get_api_cookie(ra), local_entry, remote_dn);
  1001. }
  1002. void
  1003. winsync_plugin_call_begin_update_cb(const Repl_Agmt *ra, const Slapi_DN *ds_subtree,
  1004. const Slapi_DN *ad_subtree, int is_total)
  1005. {
  1006. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_BEGIN_UPDATE_CB,winsync_plugin_update_cb,thefunc);
  1007. if (!thefunc) {
  1008. return;
  1009. }
  1010. (*thefunc)(windows_private_get_api_cookie(ra), ds_subtree, ad_subtree, is_total);
  1011. return;
  1012. }
  1013. void
  1014. winsync_plugin_call_end_update_cb(const Repl_Agmt *ra, const Slapi_DN *ds_subtree,
  1015. const Slapi_DN *ad_subtree, int is_total)
  1016. {
  1017. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_END_UPDATE_CB,winsync_plugin_update_cb,thefunc);
  1018. if (!thefunc) {
  1019. return;
  1020. }
  1021. (*thefunc)(windows_private_get_api_cookie(ra), ds_subtree, ad_subtree, is_total);
  1022. return;
  1023. }
  1024. void
  1025. winsync_plugin_call_destroy_agmt_cb(const Repl_Agmt *ra,
  1026. const Slapi_DN *ds_subtree,
  1027. const Slapi_DN *ad_subtree)
  1028. {
  1029. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_DESTROY_AGMT_CB,winsync_plugin_destroy_agmt_cb,thefunc);
  1030. if (thefunc) {
  1031. (*thefunc)(windows_private_get_api_cookie(ra), ds_subtree, ad_subtree);
  1032. }
  1033. return;
  1034. }
  1035. void
  1036. winsync_plugin_call_post_ad_mod_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1037. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1038. Slapi_Mods *smods, int *result)
  1039. {
  1040. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_AD_MOD_USER_CB,winsync_post_mod_cb,thefunc);
  1041. if (!thefunc) {
  1042. return;
  1043. }
  1044. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  1045. ds_entry, smods, result);
  1046. return;
  1047. }
  1048. void
  1049. winsync_plugin_call_post_ad_mod_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1050. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1051. Slapi_Mods *smods, int *result)
  1052. {
  1053. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_AD_MOD_GROUP_CB,winsync_post_mod_cb,thefunc);
  1054. if (!thefunc) {
  1055. return;
  1056. }
  1057. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  1058. ds_entry, smods, result);
  1059. return;
  1060. }
  1061. void
  1062. winsync_plugin_call_post_ds_mod_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1063. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1064. Slapi_Mods *smods, int *result)
  1065. {
  1066. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_DS_MOD_USER_CB,winsync_post_mod_cb,thefunc);
  1067. if (!thefunc) {
  1068. return;
  1069. }
  1070. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  1071. ds_entry, smods, result);
  1072. return;
  1073. }
  1074. void
  1075. winsync_plugin_call_post_ds_mod_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1076. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1077. Slapi_Mods *smods, int *result)
  1078. {
  1079. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_DS_MOD_GROUP_CB,winsync_post_mod_cb,thefunc);
  1080. if (!thefunc) {
  1081. return;
  1082. }
  1083. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  1084. ds_entry, smods, result);
  1085. return;
  1086. }
  1087. void
  1088. winsync_plugin_call_post_ds_add_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1089. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  1090. {
  1091. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_DS_ADD_USER_CB,winsync_post_add_cb,thefunc);
  1092. if (!thefunc) {
  1093. return;
  1094. }
  1095. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  1096. ds_entry, result);
  1097. return;
  1098. }
  1099. void
  1100. winsync_plugin_call_post_ds_add_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1101. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  1102. {
  1103. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_DS_ADD_GROUP_CB,winsync_post_add_cb,thefunc);
  1104. if (!thefunc) {
  1105. return;
  1106. }
  1107. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  1108. ds_entry, result);
  1109. return;
  1110. }
  1111. void
  1112. winsync_plugin_call_pre_ad_add_user_cb(const Repl_Agmt *ra, Slapi_Entry *ad_entry,
  1113. Slapi_Entry *ds_entry)
  1114. {
  1115. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_AD_ADD_USER_CB,winsync_pre_ad_add_cb,thefunc);
  1116. if (!thefunc) {
  1117. return;
  1118. }
  1119. (*thefunc)(windows_private_get_api_cookie(ra), ad_entry, ds_entry);
  1120. return;
  1121. }
  1122. void
  1123. winsync_plugin_call_pre_ad_add_group_cb(const Repl_Agmt *ra, Slapi_Entry *ad_entry,
  1124. Slapi_Entry *ds_entry)
  1125. {
  1126. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_AD_ADD_GROUP_CB,winsync_pre_ad_add_cb,thefunc);
  1127. if (!thefunc) {
  1128. return;
  1129. }
  1130. (*thefunc)(windows_private_get_api_cookie(ra), ad_entry, ds_entry);
  1131. return;
  1132. }
  1133. void
  1134. winsync_plugin_call_post_ad_add_user_cb(const Repl_Agmt *ra, Slapi_Entry *ad_entry,
  1135. Slapi_Entry *ds_entry, int *result)
  1136. {
  1137. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_AD_ADD_USER_CB,winsync_post_ad_add_cb,thefunc);
  1138. if (!thefunc) {
  1139. return;
  1140. }
  1141. (*thefunc)(windows_private_get_api_cookie(ra), ad_entry, ds_entry, result);
  1142. return;
  1143. }
  1144. void
  1145. winsync_plugin_call_post_ad_add_group_cb(const Repl_Agmt *ra, Slapi_Entry *ad_entry,
  1146. Slapi_Entry *ds_entry, int *result)
  1147. {
  1148. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_AD_ADD_GROUP_CB,winsync_post_ad_add_cb,thefunc);
  1149. if (!thefunc) {
  1150. return;
  1151. }
  1152. (*thefunc)(windows_private_get_api_cookie(ra), ad_entry, ds_entry, result);
  1153. return;
  1154. }
  1155. void
  1156. winsync_plugin_call_post_ad_mod_user_mods_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1157. const Slapi_DN *local_dn,
  1158. const Slapi_Entry *ds_entry,
  1159. LDAPMod * const *origmods,
  1160. Slapi_DN *remote_dn, LDAPMod **modstosend, int *result)
  1161. {
  1162. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_AD_MOD_USER_MODS_CB,winsync_post_ad_mod_mods_cb,thefunc);
  1163. if (!thefunc) {
  1164. return;
  1165. }
  1166. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, local_dn,
  1167. ds_entry, origmods, remote_dn, modstosend, result);
  1168. return;
  1169. }
  1170. void
  1171. winsync_plugin_call_post_ad_mod_group_mods_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1172. const Slapi_DN *local_dn,
  1173. const Slapi_Entry *ds_entry,
  1174. LDAPMod * const *origmods,
  1175. Slapi_DN *remote_dn, LDAPMod **modstosend, int *result)
  1176. {
  1177. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_AD_MOD_GROUP_MODS_CB,winsync_post_ad_mod_mods_cb,thefunc);
  1178. if (!thefunc) {
  1179. return;
  1180. }
  1181. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, local_dn,
  1182. ds_entry, origmods, remote_dn, modstosend, result);
  1183. return;
  1184. }
  1185. /* #define WINSYNC_TEST_IPA */
  1186. #ifdef WINSYNC_TEST_IPA
  1187. #include "ipa-winsync.c"
  1188. #include "ipa-winsync-config.c"
  1189. #endif