windows_private.c 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. /* windows_private.c */
  13. #include "repl.h"
  14. #include "repl5.h"
  15. #include "slap.h"
  16. #include "slapi-plugin.h"
  17. #include "winsync-plugin.h"
  18. #include "windowsrepl.h"
  19. struct windowsprivate {
  20. Slapi_DN *windows_subtree; /* DN of synchronized subtree (on the windows side) */
  21. Slapi_DN *directory_subtree; /* DN of synchronized subtree on directory side */
  22. /* this simplifies the mapping as it's simply
  23. from the former to the latter container, or
  24. vice versa */
  25. ber_int_t dirsync_flags;
  26. ber_int_t dirsync_maxattributecount;
  27. char *dirsync_cookie;
  28. int dirsync_cookie_len;
  29. PRBool dirsync_cookie_has_more;
  30. PRBool create_users_from_dirsync;
  31. PRBool create_groups_from_dirsync;
  32. char *windows_domain;
  33. int isnt4;
  34. int iswin2k3;
  35. /* This filter is used to determine if an entry belongs to this agreement. We put it here
  36. * so we only have to allocate each filter once instead of doing it every time we receive a change. */
  37. Slapi_Filter *directory_filter; /* Used for checking if local entries need to be sync'd to AD */
  38. Slapi_Filter *windows_filter; /* Used for checking if remote entries need to be sync'd to DS */
  39. Slapi_Filter *deleted_filter; /* Used for checking if an entry is an AD tombstone */
  40. Slapi_Entry *raw_entry; /* "raw" un-schema processed last entry read from AD */
  41. int keep_raw_entry; /* flag to control when the raw entry is set */
  42. void *api_cookie; /* private data used by api callbacks */
  43. time_t sync_interval; /* how often to run the dirsync search, in seconds */
  44. int one_way; /* Indicates if this is a one-way agreement and which direction it is */
  45. int move_action; /* Indicates what to do with DS entry if AD entry is moved out of scope */
  46. Slapi_Entry *curr_entry; /* entry being retrieved; used for the range retrieval */
  47. char **range_attrs; /* next attributes for the range retrieval */
  48. char *windows_userfilter;
  49. char *directory_userfilter;
  50. struct subtreepair *subtree_pairs; /* Array of subtree pairs (winSyncSubtreePair) */
  51. Slapi_DN *windows_treetop; /* Common subtree top to sync on AD */
  52. /* If winSyncSubtreePair is not set, identical to windows_subtree.
  53. * If set, ancestor node of all AD subtrees. */
  54. Slapi_DN *directory_treetop; /* Common subtree top to sync on DS */
  55. /* If winSyncSubtreePair is not set, identical to directory_subtree.
  56. * If set, ancestor node of all DS subtrees. */
  57. };
  58. static void windows_private_set_windows_domain(const Repl_Agmt *ra, char *domain);
  59. static subtreePair *create_subtree_pairs(char **pairs);
  60. static void free_subtree_pairs(subtreePair **pairs);
  61. static int
  62. true_value_from_string(char *val)
  63. {
  64. if (strcasecmp (val, "on") == 0 || strcasecmp (val, "yes") == 0 ||
  65. strcasecmp (val, "true") == 0 || strcasecmp (val, "1") == 0)
  66. {
  67. return 1;
  68. } else
  69. {
  70. return 0;
  71. }
  72. }
  73. /* yech - can't declare a constant string array because type_nsds7XX variables
  74. are not constant strings - so have to build a lookup table */
  75. static int
  76. get_next_disallow_attr_type(int *ii, const char **type)
  77. {
  78. switch (*ii) {
  79. case 0: *type = type_nsds7WindowsReplicaArea; break;
  80. case 1: *type = type_nsds7DirectoryReplicaArea; break;
  81. case 2: *type = type_nsds7WindowsDomain; break;
  82. default: *type = NULL; break;
  83. }
  84. if (*type) {
  85. (*ii)++;
  86. return 1;
  87. }
  88. return 0;
  89. }
  90. static int
  91. check_update_allowed(Repl_Agmt *ra, const char *type, Slapi_Entry *e, int *retval)
  92. {
  93. int rc = 1;
  94. /* note - it is not an error to defer setting the value in the ra */
  95. *retval = 1;
  96. if (agmt_get_update_in_progress(ra)) {
  97. const char *distype = NULL;
  98. int ii = 0;
  99. while (get_next_disallow_attr_type(&ii, &distype)) {
  100. if (slapi_attr_types_equivalent(type, distype)) {
  101. char *tmpstr = slapi_entry_attr_get_charptr(e, type);
  102. slapi_log_error(SLAPI_LOG_REPL, windows_repl_plugin_name,
  103. "windows_parse_config_entry: setting %s to %s will be "
  104. "deferred until current update is completed\n",
  105. type, tmpstr);
  106. slapi_ch_free_string(&tmpstr);
  107. rc = 0;
  108. break;
  109. }
  110. }
  111. }
  112. return rc;
  113. }
  114. static int
  115. windows_parse_config_entry(Repl_Agmt *ra, const char *type, Slapi_Entry *e)
  116. {
  117. char *tmpstr = NULL;
  118. int retval = 0;
  119. if (!check_update_allowed(ra, type, e, &retval))
  120. {
  121. return retval;
  122. }
  123. /*
  124. * if winSyncSubtreePair is set, WindowsReplicaArea and DirectoryReplicaArea
  125. * are ignored.
  126. */
  127. if (type == NULL || slapi_attr_types_equivalent(type,type_nsds7WindowsReplicaArea))
  128. {
  129. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7WindowsReplicaArea);
  130. if (NULL != tmpstr)
  131. {
  132. windows_private_set_windows_subtree(ra, slapi_sdn_new_dn_passin(tmpstr) );
  133. }
  134. retval = 1;
  135. }
  136. if (type == NULL || slapi_attr_types_equivalent(type,type_nsds7DirectoryReplicaArea))
  137. {
  138. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7DirectoryReplicaArea);
  139. if (NULL != tmpstr)
  140. {
  141. windows_private_set_directory_subtree(ra, slapi_sdn_new_dn_passin(tmpstr) );
  142. }
  143. retval = 1;
  144. }
  145. if (type == NULL || slapi_attr_types_equivalent(type,type_nsds7CreateNewUsers))
  146. {
  147. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7CreateNewUsers);
  148. if (NULL != tmpstr && true_value_from_string(tmpstr))
  149. {
  150. windows_private_set_create_users(ra, PR_TRUE);
  151. }
  152. else
  153. {
  154. windows_private_set_create_users(ra, PR_FALSE);
  155. }
  156. slapi_ch_free((void**)&tmpstr);
  157. /* If protocol is NULL; the agreement is not started yet.
  158. * So, no need to notify. */
  159. if (agmt_get_protocol(ra)) {
  160. prot_notify_agmt_changed(agmt_get_protocol(ra), (char *)agmt_get_long_name(ra));
  161. }
  162. retval = 1;
  163. }
  164. if (type == NULL || slapi_attr_types_equivalent(type,type_nsds7CreateNewGroups))
  165. {
  166. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7CreateNewGroups);
  167. if (NULL != tmpstr && true_value_from_string(tmpstr))
  168. {
  169. windows_private_set_create_groups(ra, PR_TRUE);
  170. }
  171. else
  172. {
  173. windows_private_set_create_groups(ra, PR_FALSE);
  174. }
  175. slapi_ch_free((void**)&tmpstr);
  176. /* If protocol is NULL; the agreement is not started yet.
  177. * So, no need to notify. */
  178. if (agmt_get_protocol(ra)) {
  179. prot_notify_agmt_changed(agmt_get_protocol(ra), (char *)agmt_get_long_name(ra));
  180. }
  181. retval = 1;
  182. }
  183. if (type == NULL || slapi_attr_types_equivalent(type,type_nsds7WindowsDomain))
  184. {
  185. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7WindowsDomain);
  186. if (NULL != tmpstr)
  187. {
  188. windows_private_set_windows_domain(ra,tmpstr);
  189. }
  190. /* No need to free tmpstr because it was aliased by the call above */
  191. tmpstr = NULL;
  192. retval = 1;
  193. }
  194. if (type == NULL || slapi_attr_types_equivalent(type,type_winSyncInterval))
  195. {
  196. tmpstr = slapi_entry_attr_get_charptr(e, type_winSyncInterval);
  197. if (NULL != tmpstr)
  198. {
  199. windows_private_set_sync_interval(ra,tmpstr);
  200. /* If protocol is NULL; the agreement is not started yet.
  201. * So, no need to notify. */
  202. if (agmt_get_protocol(ra)) {
  203. prot_notify_agmt_changed(agmt_get_protocol(ra), (char *)agmt_get_long_name(ra));
  204. }
  205. }
  206. slapi_ch_free_string(&tmpstr);
  207. retval = 1;
  208. }
  209. if (type == NULL || slapi_attr_types_equivalent(type,type_oneWaySync))
  210. {
  211. tmpstr = slapi_entry_attr_get_charptr(e, type_oneWaySync);
  212. if (NULL != tmpstr)
  213. {
  214. if (strcasecmp(tmpstr, "fromWindows") == 0) {
  215. windows_private_set_one_way(ra, ONE_WAY_SYNC_FROM_AD);
  216. } else if (strcasecmp(tmpstr, "toWindows") == 0) {
  217. windows_private_set_one_way(ra, ONE_WAY_SYNC_TO_AD);
  218. } else {
  219. slapi_log_error(SLAPI_LOG_FATAL, windows_repl_plugin_name,
  220. "Ignoring illegal setting for %s attribute in replication "
  221. "agreement \"%s\". Valid values are \"toWindows\" or "
  222. "\"fromWindows\".\n", type_oneWaySync, slapi_entry_get_dn(e));
  223. windows_private_set_one_way(ra, ONE_WAY_SYNC_DISABLED);
  224. }
  225. }
  226. else
  227. {
  228. windows_private_set_one_way(ra, ONE_WAY_SYNC_DISABLED);
  229. }
  230. slapi_ch_free((void**)&tmpstr);
  231. /* If protocol is NULL; the agreement is not started yet.
  232. * So, no need to notify. */
  233. if (agmt_get_protocol(ra)) {
  234. prot_notify_agmt_changed(agmt_get_protocol(ra), (char *)agmt_get_long_name(ra));
  235. }
  236. retval = 1;
  237. }
  238. if (type == NULL || slapi_attr_types_equivalent(type,type_winsyncMoveAction))
  239. {
  240. tmpstr = slapi_entry_attr_get_charptr(e, type_winsyncMoveAction);
  241. if (NULL != tmpstr)
  242. {
  243. if (strcasecmp(tmpstr, "delete") == 0) {
  244. windows_private_set_move_action(ra, MOVE_DOES_DELETE);
  245. } else if (strcasecmp(tmpstr, "unsync") == 0) {
  246. windows_private_set_move_action(ra, MOVE_DOES_UNSYNC);
  247. } else if (strcasecmp(tmpstr, "none") == 0) {
  248. windows_private_set_move_action(ra, MOVE_DOES_NOTHING);
  249. } else {
  250. slapi_log_error(SLAPI_LOG_FATAL, windows_repl_plugin_name,
  251. "Ignoring illegal setting for %s attribute in replication "
  252. "agreement \"%s\". Valid values are \"delete\" or "
  253. "\"unsync\".\n", type_winsyncMoveAction, slapi_entry_get_dn(e));
  254. windows_private_set_move_action(ra, MOVE_DOES_NOTHING);
  255. }
  256. }
  257. else
  258. {
  259. windows_private_set_move_action(ra, MOVE_DOES_NOTHING);
  260. }
  261. slapi_ch_free((void**)&tmpstr);
  262. /* If protocol is NULL; the agreement is not started yet.
  263. * So, no need to notify. */
  264. if (agmt_get_protocol(ra)) {
  265. prot_notify_agmt_changed(agmt_get_protocol(ra), (char *)agmt_get_long_name(ra));
  266. }
  267. retval = 1;
  268. }
  269. if (type == NULL || slapi_attr_types_equivalent(type,type_winSyncWindowsFilter))
  270. {
  271. tmpstr = slapi_entry_attr_get_charptr(e, type_winSyncWindowsFilter);
  272. windows_private_set_windows_userfilter(ra, tmpstr); /* if NULL, set it */
  273. retval = 1;
  274. }
  275. if (type == NULL || slapi_attr_types_equivalent(type,type_winSyncDirectoryFilter))
  276. {
  277. tmpstr = slapi_entry_attr_get_charptr(e, type_winSyncDirectoryFilter);
  278. windows_private_set_directory_userfilter(ra, tmpstr); /* if NULL, set it */
  279. retval = 1;
  280. }
  281. if (type == NULL || slapi_attr_types_equivalent(type, type_winSyncSubtreePair))
  282. {
  283. char **parray = slapi_entry_attr_get_charray(e, type_winSyncSubtreePair);
  284. /* If winSyncSubtreePair is not set, subtree_pairs is NULL */
  285. windows_private_set_subtreepairs(ra, parray);
  286. slapi_ch_array_free(parray);
  287. retval = 1;
  288. }
  289. windows_private_set_windows_treetop(ra, NULL);
  290. windows_private_set_directory_treetop(ra, NULL);
  291. return retval;
  292. }
  293. /* Returns non-zero if the modify was ok, zero if not */
  294. int
  295. windows_handle_modify_agreement(Repl_Agmt *ra, const char *type, Slapi_Entry *e)
  296. {
  297. /* Is this a Windows agreement ? */
  298. if (get_agmt_agreement_type(ra) == REPLICA_TYPE_WINDOWS)
  299. {
  300. return windows_parse_config_entry(ra,type,e);
  301. } else
  302. {
  303. return 0;
  304. }
  305. }
  306. void
  307. windows_update_done(Repl_Agmt *agmt, int is_total)
  308. {
  309. /* "flush" the changes made during the update to the agmt */
  310. /* get the agmt entry */
  311. Slapi_DN *agmtdn = slapi_sdn_dup(agmt_get_dn_byref(agmt));
  312. Slapi_Entry *agmte = NULL;
  313. int rc = slapi_search_internal_get_entry(agmtdn, NULL, &agmte,
  314. repl_get_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION));
  315. if ((rc == 0) && agmte) {
  316. int ii = 0;
  317. const char *distype = NULL;
  318. while (get_next_disallow_attr_type(&ii, &distype)) {
  319. windows_handle_modify_agreement(agmt, distype, agmte);
  320. }
  321. }
  322. slapi_entry_free(agmte);
  323. slapi_sdn_free(&agmtdn);
  324. }
  325. void
  326. windows_init_agreement_from_entry(Repl_Agmt *ra, Slapi_Entry *e)
  327. {
  328. agmt_set_priv(ra,windows_private_new());
  329. windows_parse_config_entry(ra,NULL,e);
  330. windows_plugin_init(ra);
  331. }
  332. const char* windows_private_get_purl(const Repl_Agmt *ra)
  333. {
  334. const char* windows_purl;
  335. char *hostname;
  336. hostname = agmt_get_hostname(ra);
  337. if(slapi_is_ipv6_addr(hostname)){
  338. /* need to put brackets around the ipv6 address */
  339. windows_purl = slapi_ch_smprintf("ldap://[%s]:%d", hostname, agmt_get_port(ra));
  340. } else {
  341. windows_purl = slapi_ch_smprintf("ldap://%s:%d", hostname, agmt_get_port(ra));
  342. }
  343. slapi_ch_free_string(&hostname);
  344. return windows_purl;
  345. }
  346. Dirsync_Private* windows_private_new()
  347. {
  348. Dirsync_Private *dp;
  349. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_new\n" );
  350. dp = (Dirsync_Private *)slapi_ch_calloc(sizeof(Dirsync_Private),1);
  351. dp->dirsync_maxattributecount = -1;
  352. dp->directory_filter = NULL;
  353. dp->windows_filter = NULL;
  354. dp->deleted_filter = NULL;
  355. dp->sync_interval = PERIODIC_DIRSYNC_INTERVAL;
  356. dp->windows_userfilter = NULL;
  357. dp->directory_userfilter = NULL;
  358. dp->subtree_pairs = NULL;
  359. dp->windows_treetop = NULL;
  360. dp->directory_treetop = NULL;
  361. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_new\n" );
  362. return dp;
  363. }
  364. void windows_agreement_delete(Repl_Agmt *ra)
  365. {
  366. const subtreePair *sp;
  367. Dirsync_Private *dp = (Dirsync_Private *) agmt_get_priv(ra);
  368. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_delete\n" );
  369. PR_ASSERT(dp != NULL);
  370. winsync_plugin_call_destroy_agmt_cb(ra, dp->directory_subtree,
  371. dp->windows_subtree);
  372. windows_plugin_cleanup_agmt(ra);
  373. slapi_sdn_free(&dp->directory_subtree);
  374. slapi_sdn_free(&dp->windows_subtree);
  375. slapi_filter_free(dp->directory_filter, 1);
  376. slapi_filter_free(dp->windows_filter, 1);
  377. slapi_filter_free(dp->deleted_filter, 1);
  378. slapi_entry_free(dp->raw_entry);
  379. slapi_ch_free_string(&dp->windows_domain);
  380. dp->raw_entry = NULL;
  381. dp->api_cookie = NULL;
  382. slapi_ch_free_string(&dp->dirsync_cookie);
  383. dp->dirsync_cookie_len = 0;
  384. slapi_ch_free_string(&dp->windows_userfilter);
  385. slapi_ch_free_string(&dp->directory_userfilter);
  386. slapi_sdn_free((Slapi_DN **)&dp->windows_treetop);
  387. slapi_sdn_free((Slapi_DN **)&dp->directory_treetop);
  388. for (sp = dp->subtree_pairs; sp && sp->ADsubtree && sp->DSsubtree; sp++) {
  389. slapi_sdn_free((Slapi_DN **)&sp->ADsubtree);
  390. slapi_sdn_free((Slapi_DN **)&sp->DSsubtree);
  391. }
  392. slapi_ch_free((void **)&dp->subtree_pairs);
  393. slapi_ch_free((void **)&dp);
  394. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_delete\n" );
  395. }
  396. int windows_private_get_isnt4(const Repl_Agmt *ra)
  397. {
  398. Dirsync_Private *dp;
  399. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_isnt4\n" );
  400. PR_ASSERT(ra);
  401. dp = (Dirsync_Private *) agmt_get_priv(ra);
  402. PR_ASSERT (dp);
  403. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_isnt4\n" );
  404. return dp->isnt4;
  405. }
  406. void windows_private_set_isnt4(const Repl_Agmt *ra, int isit)
  407. {
  408. Dirsync_Private *dp;
  409. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_isnt4\n" );
  410. PR_ASSERT(ra);
  411. dp = (Dirsync_Private *) agmt_get_priv(ra);
  412. PR_ASSERT (dp);
  413. dp->isnt4 = isit;
  414. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_isnt4\n" );
  415. }
  416. int windows_private_get_iswin2k3(const Repl_Agmt *ra)
  417. {
  418. Dirsync_Private *dp;
  419. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_iswin2k3\n" );
  420. PR_ASSERT(ra);
  421. dp = (Dirsync_Private *) agmt_get_priv(ra);
  422. PR_ASSERT (dp);
  423. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_iswin2k3\n" );
  424. return dp->iswin2k3;
  425. }
  426. void windows_private_set_iswin2k3(const Repl_Agmt *ra, int isit)
  427. {
  428. Dirsync_Private *dp;
  429. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_iswin2k3\n" );
  430. PR_ASSERT(ra);
  431. dp = (Dirsync_Private *) agmt_get_priv(ra);
  432. PR_ASSERT (dp);
  433. dp->iswin2k3 = isit;
  434. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_iswin2k3\n" );
  435. }
  436. /* Returns a copy of the Slapi_Filter pointer. The caller should not free it */
  437. Slapi_Filter* windows_private_get_directory_filter(const Repl_Agmt *ra)
  438. {
  439. Dirsync_Private *dp;
  440. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_directory_filter\n" );
  441. PR_ASSERT(ra);
  442. dp = (Dirsync_Private *) agmt_get_priv(ra);
  443. PR_ASSERT (dp);
  444. if (dp->directory_filter == NULL) {
  445. char *string_filter = NULL;
  446. const char *userfilter = windows_private_get_directory_userfilter(ra);
  447. if (userfilter) {
  448. if ('(' == *userfilter) {
  449. string_filter = slapi_ch_smprintf("(&(|(objectclass=ntuser)(objectclass=ntgroup))(ntUserDomainId=*)%s)",
  450. userfilter);
  451. } else {
  452. string_filter = slapi_ch_smprintf("(&(|(objectclass=ntuser)(objectclass=ntgroup))(ntUserDomainId=*)(%s))",
  453. userfilter);
  454. }
  455. } else {
  456. string_filter = slapi_ch_strdup("(&(|(objectclass=ntuser)(objectclass=ntgroup))(ntUserDomainId=*))");
  457. }
  458. /* The filter gets freed in windows_agreement_delete() */
  459. dp->directory_filter = slapi_str2filter( string_filter );
  460. slapi_ch_free_string(&string_filter);
  461. }
  462. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_directory_filter\n" );
  463. return dp->directory_filter;
  464. }
  465. /* Returns a copy of the Slapi_Filter pointer. The caller should not free it */
  466. Slapi_Filter*
  467. windows_private_get_windows_filter(const Repl_Agmt *ra)
  468. {
  469. Dirsync_Private *dp;
  470. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_windows_filter\n" );
  471. PR_ASSERT(ra);
  472. dp = (Dirsync_Private *) agmt_get_priv(ra);
  473. PR_ASSERT (dp);
  474. if (dp->windows_filter == NULL) {
  475. const char *userfilter = windows_private_get_windows_userfilter(ra);
  476. if (userfilter) {
  477. char *string_filter = NULL;
  478. if ('(' == *userfilter) {
  479. string_filter = slapi_ch_strdup(userfilter);
  480. } else {
  481. string_filter = slapi_ch_smprintf("(%s)", userfilter);
  482. }
  483. /* The filter gets freed in windows_agreement_delete() */
  484. dp->windows_filter = slapi_str2filter( string_filter );
  485. slapi_ch_free_string(&string_filter);
  486. }
  487. }
  488. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_windows_filter\n" );
  489. return dp->windows_filter;
  490. }
  491. /* Returns a copy of the Slapi_Filter pointer. The caller should not free it */
  492. Slapi_Filter* windows_private_get_deleted_filter(const Repl_Agmt *ra)
  493. {
  494. Dirsync_Private *dp;
  495. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_deleted_filter\n" );
  496. PR_ASSERT(ra);
  497. dp = (Dirsync_Private *) agmt_get_priv(ra);
  498. PR_ASSERT (dp);
  499. if (dp->deleted_filter == NULL) {
  500. char *string_filter = slapi_ch_strdup("(isdeleted=*)");
  501. /* The filter gets freed in windows_agreement_delete() */
  502. dp->deleted_filter = slapi_str2filter( string_filter );
  503. slapi_ch_free_string(&string_filter);
  504. }
  505. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_deleted_filter\n" );
  506. return dp->deleted_filter;
  507. }
  508. /* Returns a copy of the Slapi_DN pointer, no need to free it */
  509. const Slapi_DN* windows_private_get_windows_subtree (const Repl_Agmt *ra)
  510. {
  511. Dirsync_Private *dp;
  512. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_windows_subtree\n" );
  513. PR_ASSERT(ra);
  514. dp = (Dirsync_Private *) agmt_get_priv(ra);
  515. PR_ASSERT (dp);
  516. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_windows_subtree\n" );
  517. return dp->windows_subtree;
  518. }
  519. const char *
  520. windows_private_get_windows_domain(const Repl_Agmt *ra)
  521. {
  522. Dirsync_Private *dp;
  523. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_windows_domain\n" );
  524. PR_ASSERT(ra);
  525. dp = (Dirsync_Private *) agmt_get_priv(ra);
  526. PR_ASSERT (dp);
  527. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_windows_domain\n" );
  528. return dp->windows_domain;
  529. }
  530. static void
  531. windows_private_set_windows_domain(const Repl_Agmt *ra, char *domain)
  532. {
  533. Dirsync_Private *dp;
  534. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_windows_domain\n" );
  535. PR_ASSERT(ra);
  536. dp = (Dirsync_Private *) agmt_get_priv(ra);
  537. PR_ASSERT (dp);
  538. slapi_ch_free_string(&dp->windows_domain);
  539. dp->windows_domain = domain;
  540. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_windows_domain\n" );
  541. }
  542. /* Returns a copy of the Slapi_DN pointer, no need to free it */
  543. const Slapi_DN* windows_private_get_directory_subtree (const Repl_Agmt *ra)
  544. {
  545. Dirsync_Private *dp;
  546. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_directory_replarea\n" );
  547. PR_ASSERT(ra);
  548. dp = (Dirsync_Private *) agmt_get_priv(ra);
  549. PR_ASSERT (dp);
  550. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_directory_replarea\n" );
  551. return dp->directory_subtree;
  552. }
  553. /* Takes a copy of the sdn passed in */
  554. void windows_private_set_windows_subtree (const Repl_Agmt *ra,Slapi_DN* sdn )
  555. {
  556. Dirsync_Private *dp;
  557. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_windows_replarea\n" );
  558. PR_ASSERT(ra);
  559. PR_ASSERT(sdn);
  560. dp = (Dirsync_Private *) agmt_get_priv(ra);
  561. PR_ASSERT (dp);
  562. slapi_sdn_free(&dp->windows_subtree);
  563. dp->windows_subtree = sdn;
  564. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_windows_replarea\n" );
  565. }
  566. /* Takes a copy of the sdn passed in */
  567. void windows_private_set_directory_subtree (const Repl_Agmt *ra,Slapi_DN* sdn )
  568. {
  569. Dirsync_Private *dp;
  570. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_directory_replarea\n" );
  571. PR_ASSERT(ra);
  572. PR_ASSERT(sdn);
  573. dp = (Dirsync_Private *) agmt_get_priv(ra);
  574. PR_ASSERT (dp);
  575. slapi_sdn_free(&dp->directory_subtree);
  576. dp->directory_subtree = sdn;
  577. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_directory_replarea\n" );
  578. }
  579. PRBool windows_private_create_users(const Repl_Agmt *ra)
  580. {
  581. Dirsync_Private *dp;
  582. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_create_users\n" );
  583. PR_ASSERT(ra);
  584. dp = (Dirsync_Private *) agmt_get_priv(ra);
  585. PR_ASSERT (dp);
  586. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_create_users\n" );
  587. return dp->create_users_from_dirsync;
  588. }
  589. void windows_private_set_create_users(const Repl_Agmt *ra, PRBool value)
  590. {
  591. Dirsync_Private *dp;
  592. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_create_users\n" );
  593. PR_ASSERT(ra);
  594. dp = (Dirsync_Private *) agmt_get_priv(ra);
  595. PR_ASSERT (dp);
  596. dp->create_users_from_dirsync = value;
  597. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_create_users\n" );
  598. }
  599. PRBool windows_private_create_groups(const Repl_Agmt *ra)
  600. {
  601. Dirsync_Private *dp;
  602. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_create_groups\n" );
  603. PR_ASSERT(ra);
  604. dp = (Dirsync_Private *) agmt_get_priv(ra);
  605. PR_ASSERT (dp);
  606. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_create_groups\n" );
  607. return dp->create_groups_from_dirsync;
  608. }
  609. void windows_private_set_create_groups(const Repl_Agmt *ra, PRBool value)
  610. {
  611. Dirsync_Private *dp;
  612. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_create_groups\n" );
  613. PR_ASSERT(ra);
  614. dp = (Dirsync_Private *) agmt_get_priv(ra);
  615. PR_ASSERT (dp);
  616. dp->create_groups_from_dirsync = value;
  617. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_create_groups\n" );
  618. }
  619. int windows_private_get_one_way(const Repl_Agmt *ra)
  620. {
  621. Dirsync_Private *dp;
  622. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_one_way\n" );
  623. PR_ASSERT(ra);
  624. dp = (Dirsync_Private *) agmt_get_priv(ra);
  625. PR_ASSERT (dp);
  626. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_one_way\n" );
  627. return dp->one_way;
  628. }
  629. void windows_private_set_one_way(const Repl_Agmt *ra, int value)
  630. {
  631. Dirsync_Private *dp;
  632. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_one_way\n" );
  633. PR_ASSERT(ra);
  634. dp = (Dirsync_Private *) agmt_get_priv(ra);
  635. PR_ASSERT (dp);
  636. dp->one_way = value;
  637. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_one_way\n" );
  638. }
  639. const char*
  640. windows_private_get_windows_userfilter(const Repl_Agmt *ra)
  641. {
  642. Dirsync_Private *dp;
  643. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_windows_userfilter\n" );
  644. PR_ASSERT(ra);
  645. dp = (Dirsync_Private *) agmt_get_priv(ra);
  646. PR_ASSERT (dp);
  647. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_windows_userfilter\n" );
  648. return dp->windows_userfilter;
  649. }
  650. /* filter is passed in */
  651. void
  652. windows_private_set_windows_userfilter(const Repl_Agmt *ra, char *filter)
  653. {
  654. Dirsync_Private *dp;
  655. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_windows_userfilter\n" );
  656. PR_ASSERT(ra);
  657. dp = (Dirsync_Private *) agmt_get_priv(ra);
  658. PR_ASSERT (dp);
  659. slapi_ch_free_string(&dp->windows_userfilter);
  660. dp->windows_userfilter = filter;
  661. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_windows_userfilter\n" );
  662. }
  663. const char*
  664. windows_private_get_directory_userfilter(const Repl_Agmt *ra)
  665. {
  666. Dirsync_Private *dp;
  667. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_directory_userfilter\n" );
  668. PR_ASSERT(ra);
  669. dp = (Dirsync_Private *) agmt_get_priv(ra);
  670. PR_ASSERT (dp);
  671. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_directory_userfilter\n" );
  672. return dp->directory_userfilter;
  673. }
  674. /* filter is passed in */
  675. void
  676. windows_private_set_directory_userfilter(const Repl_Agmt *ra, char *filter)
  677. {
  678. Dirsync_Private *dp;
  679. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_directory_userfilter\n" );
  680. PR_ASSERT(ra);
  681. dp = (Dirsync_Private *) agmt_get_priv(ra);
  682. PR_ASSERT (dp);
  683. slapi_ch_free_string(&dp->directory_userfilter);
  684. dp->directory_userfilter = filter;
  685. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_directory_userfilter\n" );
  686. }
  687. const subtreePair*
  688. windows_private_get_subtreepairs(const Repl_Agmt *ra)
  689. {
  690. Dirsync_Private *dp;
  691. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_subtreepairs\n" );
  692. PR_ASSERT(ra);
  693. dp = (Dirsync_Private *) agmt_get_priv(ra);
  694. PR_ASSERT (dp);
  695. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_subtreepairs\n" );
  696. return dp->subtree_pairs;
  697. }
  698. /* parray is NOT passed in; caller frees it. */
  699. void
  700. windows_private_set_subtreepairs(const Repl_Agmt *ra, char **parray)
  701. {
  702. Dirsync_Private *dp;
  703. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_subtreepairs\n" );
  704. PR_ASSERT(ra);
  705. dp = (Dirsync_Private *) agmt_get_priv(ra);
  706. PR_ASSERT (dp);
  707. free_subtree_pairs(&(dp->subtree_pairs));
  708. dp->subtree_pairs = create_subtree_pairs(parray);
  709. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_subtreepairs\n" );
  710. }
  711. /*
  712. * winSyncSubtreePair: <DS_SUBTREE>:<WINDOWS_SUBTREE>
  713. * E.g.,
  714. * winSyncSubtreePair: ou=people,dc=example,dc=com:CN=users,DC=example,DC=com
  715. * winSyncSubtreePair: ou=adminpeople,dc=example,dc=com:CN=adminusers,DC=example,DC=com
  716. */
  717. static subtreePair *
  718. create_subtree_pairs(char **pairs)
  719. {
  720. subtreePair *subtree_pairs = NULL;
  721. subtreePair *spp;
  722. char **ptr;
  723. char *p0, *p1;
  724. char *saveptr = NULL;
  725. int cnt;
  726. for (cnt = 0, ptr = pairs; ptr && *ptr; cnt++, ptr++) ;
  727. if (0 == cnt) {
  728. return NULL;
  729. }
  730. subtree_pairs = (subtreePair *)slapi_ch_calloc(cnt + 1, sizeof(subtreePair));
  731. spp = subtree_pairs;
  732. for (ptr = pairs; ptr && *ptr; ptr++) {
  733. p0 = ldap_utf8strtok_r(*ptr, ":", &saveptr);
  734. p1 = ldap_utf8strtok_r(NULL, ":", &saveptr);
  735. if ((NULL == p0) || (NULL == p1)) {
  736. LDAPDebug1Arg(LDAP_DEBUG_ANY,
  737. "create_subtree_pairs: "
  738. "Ignoring invalid subtree pairs \"%s\".\n", *ptr);
  739. continue;
  740. }
  741. spp->DSsubtree = slapi_sdn_new_dn_byval(p0);
  742. if (NULL == spp->DSsubtree) {
  743. LDAPDebug1Arg(LDAP_DEBUG_ANY,
  744. "create_subtree_pairs: "
  745. "Ignoring invalid DS subtree \"%s\".\n",
  746. p0);
  747. continue;
  748. }
  749. spp->ADsubtree = slapi_sdn_new_dn_byval(p1);
  750. if (NULL == spp->ADsubtree) {
  751. LDAPDebug1Arg(LDAP_DEBUG_ANY,
  752. "create_subtree_pairs: "
  753. "Ignoring invalid AD subtree \"%s\".\n",
  754. p1);
  755. slapi_sdn_free(&(spp->DSsubtree));
  756. continue;
  757. }
  758. spp++;
  759. }
  760. return subtree_pairs;
  761. }
  762. static void
  763. free_subtree_pairs(subtreePair **pairs)
  764. {
  765. subtreePair *p;
  766. if (NULL == pairs) {
  767. return;
  768. }
  769. /*
  770. * If exists, the subtree pair is both non-NULL or NULL.
  771. * Both NULL is the condition to stop the loop.
  772. */
  773. for (p = *pairs; p && p->ADsubtree && p->DSsubtree; p++) {
  774. slapi_sdn_free(&(p->ADsubtree));
  775. slapi_sdn_free(&(p->DSsubtree));
  776. }
  777. slapi_ch_free((void **)pairs);
  778. }
  779. const Slapi_DN*
  780. windows_private_get_windows_treetop(const Repl_Agmt *ra)
  781. {
  782. Dirsync_Private *dp;
  783. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_windows_treetop\n" );
  784. PR_ASSERT(ra);
  785. dp = (Dirsync_Private *) agmt_get_priv(ra);
  786. PR_ASSERT (dp);
  787. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_windows_treetop\n" );
  788. return dp->windows_treetop;
  789. }
  790. /* treetop is NOT passed in */
  791. void
  792. windows_private_set_windows_treetop(const Repl_Agmt *ra, char *treetop)
  793. {
  794. Dirsync_Private *dp;
  795. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_windows_treetop\n" );
  796. PR_ASSERT(ra);
  797. dp = (Dirsync_Private *) agmt_get_priv(ra);
  798. PR_ASSERT (dp);
  799. slapi_sdn_free(&(dp->windows_treetop));
  800. if (treetop) {
  801. dp->windows_treetop = slapi_sdn_new_dn_byval(treetop);
  802. } else {
  803. const subtreePair *subtree_pairs = windows_private_get_subtreepairs(ra);
  804. const subtreePair *sp;
  805. if (subtree_pairs) {
  806. Slapi_DN *treetop_sdn = NULL;
  807. for (sp = subtree_pairs; sp && sp->ADsubtree; sp++) {
  808. if (NULL == treetop_sdn) {
  809. treetop_sdn = slapi_sdn_dup(sp->ADsubtree);
  810. } else {
  811. Slapi_DN *prev = treetop_sdn;
  812. treetop_sdn = slapi_sdn_common_ancestor(prev, sp->ADsubtree);
  813. slapi_sdn_free(&prev);
  814. }
  815. }
  816. if (treetop_sdn) {
  817. dp->windows_treetop = treetop_sdn;
  818. } else {
  819. LDAPDebug0Args(LDAP_DEBUG_ANY,
  820. "windows_private_set_windows_treetop: "
  821. "winSyncSubtreePair contains inconsistent Windows subtrees.\n");
  822. dp->windows_treetop = NULL;
  823. }
  824. } else {
  825. const Slapi_DN *windows_subtree = windows_private_get_windows_subtree(ra);
  826. dp->windows_treetop = slapi_sdn_dup(windows_subtree);
  827. }
  828. }
  829. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_windows_treetop\n" );
  830. }
  831. const Slapi_DN*
  832. windows_private_get_directory_treetop(const Repl_Agmt *ra)
  833. {
  834. Dirsync_Private *dp;
  835. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_directory_treetop\n" );
  836. PR_ASSERT(ra);
  837. dp = (Dirsync_Private *) agmt_get_priv(ra);
  838. PR_ASSERT (dp);
  839. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_directory_treetop\n" );
  840. return dp->directory_treetop;
  841. }
  842. /* treetop is NOT passed in */
  843. void
  844. windows_private_set_directory_treetop(const Repl_Agmt *ra, char *treetop)
  845. {
  846. Dirsync_Private *dp;
  847. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_directory_treetop\n" );
  848. PR_ASSERT(ra);
  849. dp = (Dirsync_Private *) agmt_get_priv(ra);
  850. PR_ASSERT (dp);
  851. slapi_sdn_free(&(dp->directory_treetop));
  852. if (treetop) {
  853. dp->directory_treetop = slapi_sdn_new_dn_byval(treetop);
  854. } else {
  855. const subtreePair *subtree_pairs = windows_private_get_subtreepairs(ra);
  856. if (subtree_pairs) {
  857. const subtreePair *sp;
  858. Slapi_DN *treetop_sdn = NULL;
  859. for (sp = subtree_pairs; sp && sp->DSsubtree; sp++) {
  860. if (NULL == treetop_sdn) {
  861. treetop_sdn = slapi_sdn_dup(sp->DSsubtree);
  862. } else {
  863. Slapi_DN *prev = treetop_sdn;
  864. treetop_sdn = slapi_sdn_common_ancestor(prev, sp->DSsubtree);
  865. slapi_sdn_free(&prev);
  866. }
  867. }
  868. if (treetop_sdn) {
  869. dp->directory_treetop = treetop_sdn;
  870. } else {
  871. LDAPDebug0Args(LDAP_DEBUG_ANY,
  872. "windows_private_set_directory_treetop: "
  873. "winSyncSubtreePair contains inconsistent Windows subtrees.\n");
  874. dp->directory_treetop = NULL;
  875. }
  876. } else {
  877. const Slapi_DN *directory_subtree = windows_private_get_directory_subtree(ra);
  878. dp->directory_treetop = slapi_sdn_dup(directory_subtree);
  879. }
  880. }
  881. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_directory_treetop\n" );
  882. }
  883. /*
  884. This function returns the current Dirsync_Private that's inside
  885. Repl_Agmt ra as a ldap control.
  886. */
  887. LDAPControl* windows_private_dirsync_control(const Repl_Agmt *ra)
  888. {
  889. LDAPControl *control = NULL;
  890. BerElement *ber;
  891. Dirsync_Private *dp;
  892. char iscritical = PR_TRUE;
  893. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_dirsync_control\n" );
  894. PR_ASSERT(ra);
  895. dp = (Dirsync_Private *) agmt_get_priv(ra);
  896. PR_ASSERT (dp);
  897. ber = ber_alloc();
  898. ber_printf( ber, "{iio}", dp->dirsync_flags, dp->dirsync_maxattributecount, dp->dirsync_cookie ? dp->dirsync_cookie : "", dp->dirsync_cookie_len );
  899. /* Use a regular directory server instead of a real AD - for testing */
  900. if (getenv("WINSYNC_USE_DS")) {
  901. iscritical = PR_FALSE;
  902. }
  903. slapi_build_control( REPL_DIRSYNC_CONTROL_OID, ber, iscritical, &control);
  904. ber_free(ber,1);
  905. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_dirsync_control\n" );
  906. return control;
  907. }
  908. /*
  909. This function scans the array of controls and updates the Repl_Agmt's
  910. Dirsync_Private if the dirsync control is found.
  911. */
  912. void windows_private_update_dirsync_control(const Repl_Agmt *ra,LDAPControl **controls )
  913. {
  914. Dirsync_Private *dp;
  915. int foundDirsyncControl;
  916. int i;
  917. LDAPControl *dirsync = NULL;
  918. BerElement *ber = NULL;
  919. ber_int_t hasMoreData;
  920. ber_int_t maxAttributeCount;
  921. BerValue *serverCookie = NULL;
  922. #ifdef FOR_DEBUGGING
  923. int return_value = LDAP_SUCCESS;
  924. #endif
  925. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_update_dirsync_control\n" );
  926. PR_ASSERT(ra);
  927. dp = (Dirsync_Private *) agmt_get_priv(ra);
  928. PR_ASSERT (dp);
  929. if (NULL != controls )
  930. {
  931. foundDirsyncControl = 0;
  932. for ( i = 0; (( controls[i] != NULL ) && ( !foundDirsyncControl )); i++ ) {
  933. foundDirsyncControl = !strcmp( controls[i]->ldctl_oid, REPL_DIRSYNC_CONTROL_OID );
  934. }
  935. if ( !foundDirsyncControl )
  936. {
  937. #ifdef FOR_DEBUGGING
  938. return_value = LDAP_CONTROL_NOT_FOUND;
  939. #endif
  940. goto choke;
  941. }
  942. else if (!controls[i-1]->ldctl_value.bv_val) {
  943. #ifdef FOR_DEBUGGING
  944. return_value = LDAP_CONTROL_NOT_FOUND;
  945. #endif
  946. goto choke;
  947. }
  948. else
  949. {
  950. dirsync = slapi_dup_control( controls[i-1]);
  951. }
  952. if (!dirsync || !BV_HAS_DATA((&(dirsync->ldctl_value)))) {
  953. #ifdef FOR_DEBUGGING
  954. return_value = LDAP_CONTROL_NOT_FOUND;
  955. #endif
  956. goto choke;
  957. }
  958. ber = ber_init( &dirsync->ldctl_value ) ;
  959. if (ber_scanf( ber, "{iiO}", &hasMoreData, &maxAttributeCount, &serverCookie) == LBER_ERROR)
  960. {
  961. #ifdef FOR_DEBUGGING
  962. return_value = LDAP_CONTROL_NOT_FOUND;
  963. #endif
  964. goto choke;
  965. }
  966. slapi_ch_free_string(&dp->dirsync_cookie);
  967. dp->dirsync_cookie = ( char* ) slapi_ch_malloc(serverCookie->bv_len + 1);
  968. memcpy(dp->dirsync_cookie, serverCookie->bv_val, serverCookie->bv_len);
  969. dp->dirsync_cookie_len = (int) serverCookie->bv_len; /* XXX shouldn't cast? */
  970. /* dp->dirsync_maxattributecount = maxAttributeCount; We don't need to keep this */
  971. dp->dirsync_cookie_has_more = hasMoreData;
  972. choke:
  973. ber_bvfree(serverCookie);
  974. ber_free(ber,1);
  975. ldap_control_free(dirsync);
  976. }
  977. else
  978. {
  979. #ifdef FOR_DEBUGGING
  980. return_value = LDAP_CONTROL_NOT_FOUND;
  981. #endif
  982. }
  983. #ifdef FOR_DEBUGGING
  984. LDAPDebug1Arg( LDAP_DEBUG_TRACE, "<= windows_private_update_dirsync_control: rc=%d\n", return_value);
  985. #else
  986. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_update_dirsync_control\n" );
  987. #endif
  988. }
  989. PRBool windows_private_dirsync_has_more(const Repl_Agmt *ra)
  990. {
  991. Dirsync_Private *dp;
  992. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_dirsync_has_more\n" );
  993. PR_ASSERT(ra);
  994. dp = (Dirsync_Private *) agmt_get_priv(ra);
  995. PR_ASSERT (dp);
  996. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_dirsync_has_more\n" );
  997. return dp->dirsync_cookie_has_more;
  998. }
  999. void windows_private_null_dirsync_cookie(const Repl_Agmt *ra)
  1000. {
  1001. Dirsync_Private *dp;
  1002. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_null_dirsync_control\n" );
  1003. dp = (Dirsync_Private *) agmt_get_priv(ra);
  1004. PR_ASSERT (dp);
  1005. dp->dirsync_cookie_len = 0;
  1006. slapi_ch_free_string(&dp->dirsync_cookie);
  1007. dp->dirsync_cookie = NULL;
  1008. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_null_dirsync_control\n" );
  1009. }
  1010. static
  1011. Slapi_Mods *windows_private_get_cookie_mod(Dirsync_Private *dp, int modtype)
  1012. {
  1013. Slapi_Mods *smods = NULL;
  1014. smods = slapi_mods_new();
  1015. slapi_mods_add( smods, modtype,
  1016. "nsds7DirsyncCookie", dp->dirsync_cookie_len , dp->dirsync_cookie);
  1017. return smods;
  1018. }
  1019. /* writes the current cookie into dse.ldif under the replication agreement entry
  1020. returns: ldap result code of the operation. */
  1021. int
  1022. windows_private_save_dirsync_cookie(const Repl_Agmt *ra)
  1023. {
  1024. Dirsync_Private *dp = NULL;
  1025. Slapi_PBlock *pb = NULL;
  1026. Slapi_DN* sdn = NULL;
  1027. int rc = 0;
  1028. Slapi_Mods *mods = NULL;
  1029. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_save_dirsync_cookie\n" );
  1030. PR_ASSERT(ra);
  1031. dp = (Dirsync_Private *) agmt_get_priv(ra);
  1032. PR_ASSERT (dp);
  1033. pb = slapi_pblock_new ();
  1034. mods = windows_private_get_cookie_mod(dp, LDAP_MOD_REPLACE);
  1035. sdn = slapi_sdn_dup( agmt_get_dn_byref(ra) );
  1036. slapi_modify_internal_set_pb_ext (pb, sdn,
  1037. slapi_mods_get_ldapmods_byref(mods), NULL, NULL,
  1038. repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION), 0);
  1039. slapi_modify_internal_pb (pb);
  1040. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  1041. if (rc == LDAP_NO_SUCH_ATTRIBUTE)
  1042. { /* try again, but as an add instead */
  1043. slapi_mods_free(&mods);
  1044. mods = windows_private_get_cookie_mod(dp, LDAP_MOD_ADD);
  1045. slapi_modify_internal_set_pb_ext (pb, sdn,
  1046. slapi_mods_get_ldapmods_byref(mods), NULL, NULL,
  1047. repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION), 0);
  1048. slapi_modify_internal_pb (pb);
  1049. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  1050. }
  1051. slapi_pblock_destroy (pb);
  1052. slapi_mods_free(&mods);
  1053. slapi_sdn_free(&sdn);
  1054. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_save_dirsync_cookie\n" );
  1055. return rc;
  1056. }
  1057. /* reads the cookie in dse.ldif to the replication agreement entry
  1058. returns: ldap result code of ldap operation, or
  1059. LDAP_NO_SUCH_ATTRIBUTE. (this is the equilivent of a null cookie) */
  1060. int windows_private_load_dirsync_cookie(const Repl_Agmt *ra)
  1061. {
  1062. Dirsync_Private *dp = NULL;
  1063. Slapi_PBlock *pb = NULL;
  1064. Slapi_DN* sdn = NULL;
  1065. int rc = 0;
  1066. Slapi_Entry *entry = NULL;
  1067. Slapi_Attr *attr = NULL;
  1068. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_load_dirsync_cookie\n" );
  1069. PR_ASSERT(ra);
  1070. dp = (Dirsync_Private *) agmt_get_priv(ra);
  1071. PR_ASSERT (dp);
  1072. pb = slapi_pblock_new ();
  1073. sdn = slapi_sdn_dup( agmt_get_dn_byref(ra) );
  1074. rc = slapi_search_internal_get_entry(sdn, NULL, &entry,
  1075. repl_get_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION));
  1076. if (rc == 0)
  1077. {
  1078. rc= slapi_entry_attr_find( entry, type_nsds7DirsyncCookie, &attr );
  1079. if (attr)
  1080. {
  1081. struct berval **vals;
  1082. rc = slapi_attr_get_bervals_copy(attr, &vals );
  1083. if (vals)
  1084. {
  1085. dp->dirsync_cookie_len = (int) (vals[0])->bv_len;
  1086. slapi_ch_free_string(&dp->dirsync_cookie);
  1087. dp->dirsync_cookie = ( char* ) slapi_ch_malloc(dp->dirsync_cookie_len + 1);
  1088. memcpy(dp->dirsync_cookie,(vals[0]->bv_val), (vals[0])->bv_len+1);
  1089. }
  1090. ber_bvecfree(vals);
  1091. /* we do not free attr */
  1092. }
  1093. else
  1094. {
  1095. rc = LDAP_NO_SUCH_ATTRIBUTE;
  1096. }
  1097. }
  1098. if (entry)
  1099. {
  1100. slapi_entry_free(entry);
  1101. }
  1102. slapi_sdn_free( &sdn);
  1103. slapi_pblock_destroy (pb);
  1104. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_load_dirsync_cookie\n" );
  1105. return rc;
  1106. }
  1107. /* get returns a pointer to the structure - do not free */
  1108. Slapi_Entry *windows_private_get_raw_entry(const Repl_Agmt *ra)
  1109. {
  1110. Dirsync_Private *dp;
  1111. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_raw_entry\n" );
  1112. dp = (Dirsync_Private *) agmt_get_priv(ra);
  1113. PR_ASSERT (dp);
  1114. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_raw_entry\n" );
  1115. return dp->raw_entry;
  1116. }
  1117. /* this is passin - windows_private owns the pointer, not a copy */
  1118. void windows_private_set_raw_entry(const Repl_Agmt *ra, Slapi_Entry *e)
  1119. {
  1120. Dirsync_Private *dp;
  1121. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_raw_entry\n" );
  1122. dp = (Dirsync_Private *) agmt_get_priv(ra);
  1123. PR_ASSERT (dp);
  1124. /* If the keep raw entry flag is set, just free the passed
  1125. * in entry and leave the current raw entry in place. */
  1126. if (windows_private_get_keep_raw_entry(ra)) {
  1127. slapi_entry_free(e);
  1128. } else {
  1129. slapi_entry_free(dp->raw_entry);
  1130. dp->raw_entry = e;
  1131. }
  1132. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_raw_entry\n" );
  1133. }
  1134. /* Setting keep to 1 will cause the current raw entry to remain, even if
  1135. * windows_private_set_raw_entry() is called. This behavior will persist
  1136. * until this flag is set back to 0. */
  1137. void windows_private_set_keep_raw_entry(const Repl_Agmt *ra, int keep)
  1138. {
  1139. Dirsync_Private *dp;
  1140. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_keep_raw_entry\n" );
  1141. dp = (Dirsync_Private *) agmt_get_priv(ra);
  1142. PR_ASSERT (dp);
  1143. dp->keep_raw_entry = keep;
  1144. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_keep_raw_entry\n" );
  1145. }
  1146. int windows_private_get_keep_raw_entry(const Repl_Agmt *ra)
  1147. {
  1148. Dirsync_Private *dp;
  1149. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_keep_raw_entry\n" );
  1150. dp = (Dirsync_Private *) agmt_get_priv(ra);
  1151. PR_ASSERT (dp);
  1152. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_keep_raw_entry\n" );
  1153. return dp->keep_raw_entry;
  1154. }
  1155. void *windows_private_get_api_cookie(const Repl_Agmt *ra)
  1156. {
  1157. Dirsync_Private *dp;
  1158. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_api_cookie\n" );
  1159. dp = (Dirsync_Private *) agmt_get_priv(ra);
  1160. PR_ASSERT (dp);
  1161. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_api_cookie\n" );
  1162. return dp->api_cookie;
  1163. }
  1164. void windows_private_set_api_cookie(Repl_Agmt *ra, void *api_cookie)
  1165. {
  1166. Dirsync_Private *dp;
  1167. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_api_cookie\n" );
  1168. dp = (Dirsync_Private *) agmt_get_priv(ra);
  1169. PR_ASSERT (dp);
  1170. dp->api_cookie = api_cookie;
  1171. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_api_cookie\n" );
  1172. }
  1173. time_t
  1174. windows_private_get_sync_interval(const Repl_Agmt *ra)
  1175. {
  1176. Dirsync_Private *dp;
  1177. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_sync_interval\n" );
  1178. PR_ASSERT(ra);
  1179. dp = (Dirsync_Private *) agmt_get_priv(ra);
  1180. PR_ASSERT (dp);
  1181. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_sync_interval\n" );
  1182. return dp->sync_interval;
  1183. }
  1184. void
  1185. windows_private_set_sync_interval(Repl_Agmt *ra, char *str)
  1186. {
  1187. Dirsync_Private *dp;
  1188. time_t tmpval = 0;
  1189. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_sync_interval\n" );
  1190. PR_ASSERT(ra);
  1191. dp = (Dirsync_Private *) agmt_get_priv(ra);
  1192. PR_ASSERT (dp);
  1193. if (str && (tmpval = (time_t)atol(str))) {
  1194. dp->sync_interval = tmpval;
  1195. }
  1196. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_sync_interval\n" );
  1197. }
  1198. int
  1199. windows_private_get_move_action(const Repl_Agmt *ra)
  1200. {
  1201. Dirsync_Private *dp;
  1202. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_move_action\n" );
  1203. PR_ASSERT(ra);
  1204. dp = (Dirsync_Private *) agmt_get_priv(ra);
  1205. PR_ASSERT (dp);
  1206. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_move_action\n" );
  1207. return dp->move_action;
  1208. }
  1209. void
  1210. windows_private_set_move_action(const Repl_Agmt *ra, int value)
  1211. {
  1212. Dirsync_Private *dp;
  1213. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_move_action\n" );
  1214. PR_ASSERT(ra);
  1215. dp = (Dirsync_Private *) agmt_get_priv(ra);
  1216. PR_ASSERT (dp);
  1217. dp->move_action = value;
  1218. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_move_action\n" );
  1219. }
  1220. static PRCallOnceType winsync_callOnce = {0,0};
  1221. struct winsync_plugin {
  1222. struct winsync_plugin *next; /* see PRCList - declare here to avoid lots of casting */
  1223. struct winsync_plugin *prev; /* see PRCList - declare here to avoid lots of casting */
  1224. void **api; /* the api - array of function pointers */
  1225. int maxapi; /* the max index i.e. the api version */
  1226. int precedence; /* lower number == higher precedence */
  1227. };
  1228. static struct winsync_plugin winsync_plugin_list;
  1229. #define DECL_WINSYNC_API_IDX_FUNC(theapi,idx,maxidx,thetype,thefunc) \
  1230. thetype thefunc = (theapi && (idx <= maxidx) && theapi[idx]) ? \
  1231. (thetype)theapi[idx] : NULL;
  1232. #define WINSYNC_PLUGIN_CALL_PLUGINS_BEGIN(idx,thetype,thefunc) \
  1233. struct winsync_plugin *elem; \
  1234. for (elem = PR_LIST_HEAD(&winsync_plugin_list); \
  1235. elem && (elem != &winsync_plugin_list); \
  1236. elem = PR_NEXT_LINK(elem)) { \
  1237. DECL_WINSYNC_API_IDX_FUNC(elem->api,idx,elem->maxapi,thetype,thefunc); \
  1238. if (thefunc) {
  1239. #define WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(idx,thetype,thefunc) \
  1240. WINSYNC_PLUGIN_CALL_PLUGINS_BEGIN(idx,thetype,thefunc) \
  1241. void *cookie = winsync_plugin_cookie_find(ra, elem->api);
  1242. #define WINSYNC_PLUGIN_CALL_PLUGINS_END } /* this one matches if thefunc */ } /* this one matches the for loop */
  1243. /* this structure is per agreement - to store the cookie per agreement
  1244. for each winsync plugin */
  1245. struct winsync_plugin_cookie {
  1246. struct winsync_plugin_cookie *next; /* see PRCList - declare here to avoid lots of casting */
  1247. struct winsync_plugin_cookie *prev; /* see PRCList - declare here to avoid lots of casting */
  1248. void **api; /* the api - array of function pointers */
  1249. void *cookie; /* plugin data */
  1250. };
  1251. static struct winsync_plugin *
  1252. new_winsync_plugin(void **theapi, int maxapi, int precedence)
  1253. {
  1254. struct winsync_plugin *wpi = (struct winsync_plugin *)slapi_ch_calloc(1, sizeof(struct winsync_plugin));
  1255. wpi->api = theapi;
  1256. wpi->maxapi = maxapi;
  1257. wpi->precedence = precedence;
  1258. return wpi;
  1259. }
  1260. static struct winsync_plugin *
  1261. windows_plugin_find(void **theapi)
  1262. {
  1263. struct winsync_plugin *elem = PR_LIST_HEAD(&winsync_plugin_list);
  1264. while (elem && (elem != &winsync_plugin_list)) {
  1265. if (theapi == elem->api) {
  1266. return elem;
  1267. }
  1268. elem = PR_NEXT_LINK(elem);
  1269. }
  1270. return NULL;
  1271. }
  1272. /* returns 0 for success - 1 means already added - -1 means some error */
  1273. static int
  1274. windows_plugin_add(void **theapi, int maxapi)
  1275. {
  1276. int precedence = WINSYNC_PLUGIN_DEFAULT_PRECEDENCE;
  1277. DECL_WINSYNC_API_IDX_FUNC(theapi,WINSYNC_PLUGIN_PRECEDENCE_CB,maxapi,winsync_plugin_precedence_cb,thefunc);
  1278. if (thefunc) {
  1279. /* supports precedence */
  1280. precedence = (*thefunc)();
  1281. }
  1282. if (PR_CLIST_IS_EMPTY(&winsync_plugin_list)) {
  1283. struct winsync_plugin *wpi = new_winsync_plugin(theapi, maxapi, precedence);
  1284. PR_INSERT_LINK(wpi, &winsync_plugin_list);
  1285. return 0;
  1286. } else if (windows_plugin_find(theapi)) {
  1287. return 1; /* already in list */
  1288. } else {
  1289. struct winsync_plugin *wpi = new_winsync_plugin(theapi, maxapi, precedence);
  1290. struct winsync_plugin *elem = PR_LIST_HEAD(&winsync_plugin_list);
  1291. while (elem && (elem != &winsync_plugin_list)) {
  1292. if (precedence < elem->precedence) {
  1293. PR_INSERT_BEFORE(wpi, elem);
  1294. wpi = NULL; /* owned by list now */
  1295. break;
  1296. }
  1297. elem = PR_NEXT_LINK(elem);
  1298. }
  1299. if (elem && wpi) { /* was not added - precedence too high */
  1300. /* just add to end of list */
  1301. PR_INSERT_BEFORE(wpi, elem);
  1302. wpi = NULL; /* owned by list now */
  1303. }
  1304. /* if we got here and wpi is not NULL we need to free wpi */
  1305. slapi_ch_free((void **)&wpi);
  1306. return 0;
  1307. }
  1308. return -1;
  1309. }
  1310. static PRStatus
  1311. windows_plugin_callonce(void)
  1312. {
  1313. char *guids[] = {WINSYNC_v3_0_GUID, WINSYNC_v2_0_GUID, WINSYNC_v1_0_GUID, NULL};
  1314. int maxapis[] = {WINSYNC_PLUGIN_VERSION_3_END, WINSYNC_PLUGIN_VERSION_2_END,
  1315. WINSYNC_PLUGIN_VERSION_1_END, 0};
  1316. int ii;
  1317. PR_INIT_CLIST(&winsync_plugin_list);
  1318. /* loop through all of the registered winsync plugins - look for them in reverse
  1319. version order (e.g. look for v3 first) - if there are no plugins registered
  1320. for the given version, or we have already registered all plugins for a given
  1321. version, just go to the next lowest version */
  1322. for (ii = 0; guids[ii]; ++ii) {
  1323. char *guid = guids[ii];
  1324. int maxapi = maxapis[ii];
  1325. void ***theapis = NULL;
  1326. if (slapi_apib_get_interface_all(guid, &theapis) || (NULL == theapis)) {
  1327. LDAPDebug1Arg(LDAP_DEBUG_PLUGIN,
  1328. "<-- windows_plugin_callonce -- no more windows plugin APIs registered "
  1329. "for GUID [%s] -- end\n",
  1330. guid);
  1331. } else {
  1332. int idx;
  1333. for (idx = 0; theapis && theapis[idx]; ++idx) {
  1334. if (windows_plugin_add(theapis[idx], maxapi)) {
  1335. LDAPDebug(LDAP_DEBUG_PLUGIN,
  1336. "<-- windows_plugin_callonce -- already added windows plugin API "
  1337. "[%d][0x%p] for GUID [%s] -- end\n",
  1338. idx, theapis[idx], guid);
  1339. }
  1340. }
  1341. }
  1342. slapi_ch_free((void **)&theapis);
  1343. }
  1344. return PR_SUCCESS;
  1345. }
  1346. static struct winsync_plugin_cookie *
  1347. new_winsync_plugin_cookie(void **theapi, void *cookie)
  1348. {
  1349. struct winsync_plugin_cookie *wpc = (struct winsync_plugin_cookie *)slapi_ch_calloc(1, sizeof(struct winsync_plugin_cookie));
  1350. wpc->api = theapi;
  1351. wpc->cookie = cookie;
  1352. return wpc;
  1353. }
  1354. static void *
  1355. winsync_plugin_cookie_find(const Repl_Agmt *ra, void **theapi)
  1356. {
  1357. if (ra) {
  1358. struct winsync_plugin_cookie *list = (struct winsync_plugin_cookie *)windows_private_get_api_cookie(ra);
  1359. if (list) {
  1360. struct winsync_plugin_cookie *elem = PR_LIST_HEAD(list);
  1361. while (elem && (elem != list)) {
  1362. if (theapi == elem->api) {
  1363. return elem->cookie;
  1364. }
  1365. elem = PR_NEXT_LINK(elem);
  1366. }
  1367. }
  1368. }
  1369. return NULL;
  1370. }
  1371. static void
  1372. winsync_plugin_cookie_add(struct winsync_plugin_cookie **list, void **theapi, void *cookie)
  1373. {
  1374. struct winsync_plugin_cookie *elem = NULL;
  1375. if (!*list) {
  1376. *list = new_winsync_plugin_cookie(NULL, NULL);
  1377. PR_INIT_CLIST(*list);
  1378. }
  1379. elem = new_winsync_plugin_cookie(theapi, cookie);
  1380. PR_INSERT_BEFORE(elem, *list);
  1381. return;
  1382. }
  1383. void
  1384. windows_plugin_init(Repl_Agmt *ra)
  1385. {
  1386. struct winsync_plugin_cookie *list = NULL;
  1387. void *cookie = NULL;
  1388. LDAPDebug0Args( LDAP_DEBUG_PLUGIN, "--> windows_plugin_init_start -- begin\n");
  1389. if (PR_CallOnce(&winsync_callOnce, windows_plugin_callonce)) {
  1390. PRErrorCode prerr = PR_GetError();
  1391. slapi_log_error(SLAPI_LOG_FATAL, "windows_plugin_init",
  1392. "cannot initialize plugin: %d:%s\n", prerr,
  1393. slapi_pr_strerror(prerr));
  1394. return;
  1395. }
  1396. /* call each plugin init function in turn - store the returned cookie
  1397. indexed by the api */
  1398. {
  1399. WINSYNC_PLUGIN_CALL_PLUGINS_BEGIN(WINSYNC_PLUGIN_INIT_CB,winsync_plugin_init_cb,thefunc)
  1400. cookie = (*thefunc)(windows_private_get_directory_subtree(ra),
  1401. windows_private_get_windows_subtree(ra));
  1402. if (cookie) {
  1403. winsync_plugin_cookie_add(&list, elem->api, cookie);
  1404. }
  1405. WINSYNC_PLUGIN_CALL_PLUGINS_END
  1406. }
  1407. windows_private_set_api_cookie(ra, list);
  1408. LDAPDebug0Args( LDAP_DEBUG_PLUGIN, "<-- windows_plugin_init_start -- end\n");
  1409. return;
  1410. }
  1411. void
  1412. windows_plugin_cleanup_agmt(Repl_Agmt *ra)
  1413. {
  1414. struct winsync_plugin_cookie *list = (struct winsync_plugin_cookie *)windows_private_get_api_cookie(ra);
  1415. struct winsync_plugin_cookie *elem = NULL;
  1416. while (list && !PR_CLIST_IS_EMPTY(list)) {
  1417. elem = PR_LIST_HEAD(list);
  1418. PR_REMOVE_LINK(elem);
  1419. slapi_ch_free((void **)&elem);
  1420. }
  1421. slapi_ch_free((void **)&list);
  1422. windows_private_set_api_cookie(ra, NULL);
  1423. return;
  1424. }
  1425. void
  1426. winsync_plugin_call_dirsync_search_params_cb(const Repl_Agmt *ra, const char *agmt_dn,
  1427. char **base, int *scope, char **filter,
  1428. char ***attrs, LDAPControl ***serverctrls)
  1429. {
  1430. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_DIRSYNC_SEARCH_CB,winsync_search_params_cb,thefunc)
  1431. (*thefunc)(cookie, agmt_dn, base, scope, filter, attrs, serverctrls);
  1432. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1433. return;
  1434. }
  1435. void
  1436. winsync_plugin_call_pre_ad_search_cb(const Repl_Agmt *ra, const char *agmt_dn,
  1437. char **base, int *scope, char **filter,
  1438. char ***attrs, LDAPControl ***serverctrls)
  1439. {
  1440. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_AD_SEARCH_CB,winsync_search_params_cb,thefunc)
  1441. (*thefunc)(cookie, agmt_dn, base, scope, filter, attrs, serverctrls);
  1442. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1443. return;
  1444. }
  1445. void
  1446. winsync_plugin_call_pre_ds_search_entry_cb(const Repl_Agmt *ra, const char *agmt_dn,
  1447. char **base, int *scope, char **filter,
  1448. char ***attrs, LDAPControl ***serverctrls)
  1449. {
  1450. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_DS_SEARCH_ENTRY_CB,winsync_search_params_cb,thefunc)
  1451. (*thefunc)(cookie, agmt_dn, base, scope, filter, attrs, serverctrls);
  1452. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1453. return;
  1454. }
  1455. void
  1456. winsync_plugin_call_pre_ds_search_all_cb(const Repl_Agmt *ra, const char *agmt_dn,
  1457. char **base, int *scope, char **filter,
  1458. char ***attrs, LDAPControl ***serverctrls)
  1459. {
  1460. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_DS_SEARCH_ALL_CB,winsync_search_params_cb,thefunc)
  1461. (*thefunc)(cookie, agmt_dn, base, scope, filter, attrs, serverctrls);
  1462. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1463. return;
  1464. }
  1465. void
  1466. winsync_plugin_call_pre_ad_mod_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1467. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1468. Slapi_Mods *smods, int *do_modify)
  1469. {
  1470. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_AD_MOD_USER_CB,winsync_pre_mod_cb,thefunc)
  1471. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, smods, do_modify);
  1472. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1473. return;
  1474. }
  1475. void
  1476. winsync_plugin_call_pre_ad_mod_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1477. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1478. Slapi_Mods *smods, int *do_modify)
  1479. {
  1480. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_AD_MOD_GROUP_CB,winsync_pre_mod_cb,thefunc)
  1481. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, smods, do_modify);
  1482. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1483. return;
  1484. }
  1485. void
  1486. winsync_plugin_call_pre_ds_mod_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1487. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1488. Slapi_Mods *smods, int *do_modify)
  1489. {
  1490. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_DS_MOD_USER_CB,winsync_pre_mod_cb,thefunc)
  1491. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, smods, do_modify);
  1492. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1493. return;
  1494. }
  1495. void
  1496. winsync_plugin_call_pre_ds_mod_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1497. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1498. Slapi_Mods *smods, int *do_modify)
  1499. {
  1500. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_DS_MOD_GROUP_CB,winsync_pre_mod_cb,thefunc)
  1501. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, smods, do_modify);
  1502. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1503. return;
  1504. }
  1505. void
  1506. winsync_plugin_call_pre_ds_add_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1507. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry)
  1508. {
  1509. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_DS_ADD_USER_CB,winsync_pre_add_cb,thefunc)
  1510. (*thefunc)(cookie, rawentry, ad_entry, ds_entry);
  1511. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1512. return;
  1513. }
  1514. void
  1515. winsync_plugin_call_pre_ds_add_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1516. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry)
  1517. {
  1518. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_DS_ADD_GROUP_CB,winsync_pre_add_cb,thefunc)
  1519. (*thefunc)(cookie, rawentry, ad_entry, ds_entry);
  1520. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1521. return;
  1522. }
  1523. void
  1524. winsync_plugin_call_get_new_ds_user_dn_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1525. Slapi_Entry *ad_entry, char **new_dn_string,
  1526. const Slapi_DN *ds_suffix, const Slapi_DN *ad_suffix)
  1527. {
  1528. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_GET_NEW_DS_USER_DN_CB,winsync_get_new_dn_cb,thefunc)
  1529. (*thefunc)(cookie, rawentry, ad_entry, new_dn_string, ds_suffix, ad_suffix);
  1530. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1531. return;
  1532. }
  1533. void
  1534. winsync_plugin_call_get_new_ds_group_dn_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1535. Slapi_Entry *ad_entry, char **new_dn_string,
  1536. const Slapi_DN *ds_suffix, const Slapi_DN *ad_suffix)
  1537. {
  1538. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_GET_NEW_DS_GROUP_DN_CB,winsync_get_new_dn_cb,thefunc)
  1539. (*thefunc)(cookie, rawentry, ad_entry, new_dn_string, ds_suffix, ad_suffix);
  1540. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1541. return;
  1542. }
  1543. void
  1544. winsync_plugin_call_pre_ad_mod_user_mods_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1545. const Slapi_DN *local_dn,
  1546. const Slapi_Entry *ds_entry,
  1547. LDAPMod * const *origmods,
  1548. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  1549. {
  1550. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_AD_MOD_USER_MODS_CB,winsync_pre_ad_mod_mods_cb,thefunc)
  1551. (*thefunc)(cookie, rawentry, local_dn, ds_entry, origmods, remote_dn, modstosend);
  1552. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1553. return;
  1554. }
  1555. void
  1556. winsync_plugin_call_pre_ad_mod_group_mods_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1557. const Slapi_DN *local_dn,
  1558. const Slapi_Entry *ds_entry,
  1559. LDAPMod * const *origmods,
  1560. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  1561. {
  1562. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_AD_MOD_GROUP_MODS_CB,winsync_pre_ad_mod_mods_cb,thefunc)
  1563. (*thefunc)(cookie, rawentry, local_dn, ds_entry, origmods, remote_dn, modstosend);
  1564. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1565. return;
  1566. }
  1567. int
  1568. winsync_plugin_call_can_add_entry_to_ad_cb(const Repl_Agmt *ra, const Slapi_Entry *local_entry,
  1569. const Slapi_DN *remote_dn)
  1570. {
  1571. int canadd = 1;
  1572. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_CAN_ADD_ENTRY_TO_AD_CB,winsync_can_add_to_ad_cb,thefunc)
  1573. if (canadd) {
  1574. canadd = (*thefunc)(cookie, local_entry, remote_dn);
  1575. }
  1576. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1577. return canadd;
  1578. }
  1579. void
  1580. winsync_plugin_call_begin_update_cb(const Repl_Agmt *ra, const Slapi_DN *ds_subtree,
  1581. const Slapi_DN *ad_subtree, int is_total)
  1582. {
  1583. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_BEGIN_UPDATE_CB,winsync_plugin_update_cb,thefunc)
  1584. (*thefunc)(cookie, ds_subtree, ad_subtree, is_total);
  1585. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1586. return;
  1587. }
  1588. void
  1589. winsync_plugin_call_end_update_cb(const Repl_Agmt *ra, const Slapi_DN *ds_subtree,
  1590. const Slapi_DN *ad_subtree, int is_total)
  1591. {
  1592. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_END_UPDATE_CB,winsync_plugin_update_cb,thefunc)
  1593. (*thefunc)(cookie, ds_subtree, ad_subtree, is_total);
  1594. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1595. return;
  1596. }
  1597. void
  1598. winsync_plugin_call_destroy_agmt_cb(const Repl_Agmt *ra,
  1599. const Slapi_DN *ds_subtree,
  1600. const Slapi_DN *ad_subtree)
  1601. {
  1602. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_DESTROY_AGMT_CB,winsync_plugin_destroy_agmt_cb,thefunc)
  1603. (*thefunc)(cookie, ds_subtree, ad_subtree);
  1604. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1605. return;
  1606. }
  1607. void
  1608. winsync_plugin_call_post_ad_mod_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1609. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1610. Slapi_Mods *smods, int *result)
  1611. {
  1612. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_AD_MOD_USER_CB,winsync_post_mod_cb,thefunc)
  1613. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, smods, result);
  1614. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1615. return;
  1616. }
  1617. void
  1618. winsync_plugin_call_post_ad_mod_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1619. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1620. Slapi_Mods *smods, int *result)
  1621. {
  1622. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_AD_MOD_GROUP_CB,winsync_post_mod_cb,thefunc)
  1623. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, smods, result);
  1624. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1625. return;
  1626. }
  1627. void
  1628. winsync_plugin_call_post_ds_mod_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1629. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1630. Slapi_Mods *smods, int *result)
  1631. {
  1632. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_DS_MOD_USER_CB,winsync_post_mod_cb,thefunc)
  1633. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, smods, result);
  1634. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1635. return;
  1636. }
  1637. void
  1638. winsync_plugin_call_post_ds_mod_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1639. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1640. Slapi_Mods *smods, int *result)
  1641. {
  1642. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_DS_MOD_GROUP_CB,winsync_post_mod_cb,thefunc)
  1643. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, smods, result);
  1644. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1645. return;
  1646. }
  1647. void
  1648. winsync_plugin_call_post_ds_add_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1649. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  1650. {
  1651. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_DS_ADD_USER_CB,winsync_post_add_cb,thefunc)
  1652. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, result);
  1653. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1654. return;
  1655. }
  1656. void
  1657. winsync_plugin_call_post_ds_add_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1658. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  1659. {
  1660. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_DS_ADD_GROUP_CB,winsync_post_add_cb,thefunc)
  1661. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, result);
  1662. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1663. return;
  1664. }
  1665. void
  1666. winsync_plugin_call_pre_ad_add_user_cb(const Repl_Agmt *ra, Slapi_Entry *ad_entry,
  1667. Slapi_Entry *ds_entry)
  1668. {
  1669. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_AD_ADD_USER_CB,winsync_pre_ad_add_cb,thefunc)
  1670. (*thefunc)(cookie, ad_entry, ds_entry);
  1671. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1672. return;
  1673. }
  1674. void
  1675. winsync_plugin_call_pre_ad_add_group_cb(const Repl_Agmt *ra, Slapi_Entry *ad_entry,
  1676. Slapi_Entry *ds_entry)
  1677. {
  1678. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_AD_ADD_GROUP_CB,winsync_pre_ad_add_cb,thefunc)
  1679. (*thefunc)(cookie, ad_entry, ds_entry);
  1680. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1681. return;
  1682. }
  1683. void
  1684. winsync_plugin_call_post_ad_add_user_cb(const Repl_Agmt *ra, Slapi_Entry *ad_entry,
  1685. Slapi_Entry *ds_entry, int *result)
  1686. {
  1687. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_AD_ADD_USER_CB,winsync_post_ad_add_cb,thefunc)
  1688. (*thefunc)(cookie, ad_entry, ds_entry, result);
  1689. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1690. return;
  1691. }
  1692. void
  1693. winsync_plugin_call_post_ad_add_group_cb(const Repl_Agmt *ra, Slapi_Entry *ad_entry,
  1694. Slapi_Entry *ds_entry, int *result)
  1695. {
  1696. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_AD_ADD_GROUP_CB,winsync_post_ad_add_cb,thefunc)
  1697. (*thefunc)(cookie, ad_entry, ds_entry, result);
  1698. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1699. return;
  1700. }
  1701. void
  1702. winsync_plugin_call_post_ad_mod_user_mods_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1703. const Slapi_DN *local_dn,
  1704. const Slapi_Entry *ds_entry,
  1705. LDAPMod * const *origmods,
  1706. Slapi_DN *remote_dn, LDAPMod **modstosend, int *result)
  1707. {
  1708. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_AD_MOD_USER_MODS_CB,winsync_post_ad_mod_mods_cb,thefunc)
  1709. (*thefunc)(cookie, rawentry, local_dn, ds_entry, origmods, remote_dn, modstosend, result);
  1710. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1711. return;
  1712. }
  1713. void
  1714. winsync_plugin_call_post_ad_mod_group_mods_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1715. const Slapi_DN *local_dn,
  1716. const Slapi_Entry *ds_entry,
  1717. LDAPMod * const *origmods,
  1718. Slapi_DN *remote_dn, LDAPMod **modstosend, int *result)
  1719. {
  1720. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_AD_MOD_GROUP_MODS_CB,winsync_post_ad_mod_mods_cb,thefunc)
  1721. (*thefunc)(cookie, rawentry, local_dn, ds_entry, origmods, remote_dn, modstosend, result);
  1722. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1723. return;
  1724. }
  1725. /*
  1726. The following are sample code stubs to show how to implement
  1727. a plugin which uses this api
  1728. */
  1729. #define WINSYNC_SAMPLE_CODE
  1730. #ifdef WINSYNC_SAMPLE_CODE
  1731. #include "slapi-plugin.h"
  1732. #include "winsync-plugin.h"
  1733. static char *test_winsync_plugin_name = "test_winsync_api";
  1734. static void *
  1735. test_winsync_api_init(const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree)
  1736. {
  1737. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1738. "--> test_winsync_init [%s] [%s] -- begin\n",
  1739. slapi_sdn_get_dn(ds_subtree),
  1740. slapi_sdn_get_dn(ad_subtree));
  1741. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1742. "<-- test_winsync_init -- end\n");
  1743. return NULL;
  1744. }
  1745. static void
  1746. test_winsync_dirsync_search_params_cb(void *cbdata, const char *agmt_dn,
  1747. char **base, int *scope, char **filter,
  1748. char ***attrs, LDAPControl ***serverctrls)
  1749. {
  1750. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1751. "--> test_winsync_dirsync_search_params_cb -- begin\n");
  1752. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1753. "<-- test_winsync_dirsync_search_params_cb -- end\n");
  1754. return;
  1755. }
  1756. /* called before searching for a single entry from AD - agmt_dn will be NULL */
  1757. static void
  1758. test_winsync_pre_ad_search_cb(void *cbdata, const char *agmt_dn,
  1759. char **base, int *scope, char **filter,
  1760. char ***attrs, LDAPControl ***serverctrls)
  1761. {
  1762. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1763. "--> test_winsync_pre_ad_search_cb -- begin\n");
  1764. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1765. "<-- test_winsync_pre_ad_search_cb -- end\n");
  1766. return;
  1767. }
  1768. /* called before an internal search to get a single DS entry - agmt_dn will be NULL */
  1769. static void
  1770. test_winsync_pre_ds_search_entry_cb(void *cbdata, const char *agmt_dn,
  1771. char **base, int *scope, char **filter,
  1772. char ***attrs, LDAPControl ***serverctrls)
  1773. {
  1774. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1775. "--> test_winsync_pre_ds_search_cb -- begin\n");
  1776. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1777. "<-- test_winsync_pre_ds_search_cb -- end\n");
  1778. return;
  1779. }
  1780. /* called before the total update to get all entries from the DS to sync to AD */
  1781. static void
  1782. test_winsync_pre_ds_search_all_cb(void *cbdata, const char *agmt_dn,
  1783. char **base, int *scope, char **filter,
  1784. char ***attrs, LDAPControl ***serverctrls)
  1785. {
  1786. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1787. "--> test_winsync_pre_ds_search_all_cb -- orig filter [%s] -- begin\n",
  1788. ((filter && *filter) ? *filter : "NULL"));
  1789. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1790. if (filter) {
  1791. /* We only want to grab users from the ds side - no groups */
  1792. slapi_ch_free_string(filter);
  1793. /* maybe use ntUniqueId=* - only get users that have already been
  1794. synced with AD already - ntUniqueId and ntUserDomainId are
  1795. indexed for equality only - need to add presence? */
  1796. *filter = slapi_ch_strdup("(&(objectclass=ntuser)(ntUserDomainId=*))");
  1797. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1798. "--> test_winsync_pre_ds_search_all_cb -- new filter [%s]\n",
  1799. *filter ? *filter : "NULL"));
  1800. }
  1801. #endif
  1802. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1803. "<-- test_winsync_pre_ds_search_all_cb -- end\n");
  1804. return;
  1805. }
  1806. static void
  1807. test_winsync_pre_ad_mod_user_cb(void *cbdata, const Slapi_Entry *rawentry,
  1808. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1809. Slapi_Mods *smods, int *do_modify)
  1810. {
  1811. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1812. "--> test_winsync_pre_ad_mod_user_cb -- begin\n");
  1813. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1814. "<-- test_winsync_pre_ad_mod_user_cb -- end\n");
  1815. return;
  1816. }
  1817. static void
  1818. test_winsync_pre_ad_mod_group_cb(void *cbdata, const Slapi_Entry *rawentry,
  1819. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1820. Slapi_Mods *smods, int *do_modify)
  1821. {
  1822. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1823. "--> test_winsync_pre_ad_mod_group_cb -- begin\n");
  1824. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1825. "<-- test_winsync_pre_ad_mod_group_cb -- end\n");
  1826. return;
  1827. }
  1828. static void
  1829. test_winsync_pre_ds_mod_user_cb(void *cbdata, const Slapi_Entry *rawentry,
  1830. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1831. Slapi_Mods *smods, int *do_modify)
  1832. {
  1833. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1834. "--> test_winsync_pre_ds_mod_user_cb -- begin\n");
  1835. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1836. "<-- test_winsync_pre_ds_mod_user_cb -- end\n");
  1837. return;
  1838. }
  1839. static void
  1840. test_winsync_pre_ds_mod_group_cb(void *cbdata, const Slapi_Entry *rawentry,
  1841. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1842. Slapi_Mods *smods, int *do_modify)
  1843. {
  1844. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1845. "--> test_winsync_pre_ds_mod_group_cb -- begin\n");
  1846. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1847. "<-- test_winsync_pre_ds_mod_group_cb -- end\n");
  1848. return;
  1849. }
  1850. static void
  1851. test_winsync_pre_ds_add_user_cb(void *cbdata, const Slapi_Entry *rawentry,
  1852. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry)
  1853. {
  1854. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1855. "--> test_winsync_pre_ds_add_user_cb -- begin\n");
  1856. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1857. "<-- test_winsync_pre_ds_add_user_cb -- end\n");
  1858. return;
  1859. }
  1860. static void
  1861. test_winsync_pre_ds_add_group_cb(void *cbdata, const Slapi_Entry *rawentry,
  1862. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry)
  1863. {
  1864. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1865. "--> test_winsync_pre_ds_add_group_cb -- begin\n");
  1866. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1867. "<-- test_winsync_pre_ds_add_group_cb -- end\n");
  1868. return;
  1869. }
  1870. static void
  1871. test_winsync_get_new_ds_user_dn_cb(void *cbdata, const Slapi_Entry *rawentry,
  1872. Slapi_Entry *ad_entry, char **new_dn_string,
  1873. const Slapi_DN *ds_suffix, const Slapi_DN *ad_suffix)
  1874. {
  1875. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1876. "--> test_winsync_get_new_ds_user_dn_cb -- old dn [%s] -- begin\n",
  1877. *new_dn_string);
  1878. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1879. char **rdns = slapi_ldap_explode_dn(*new_dn_string, 0);
  1880. if (!rdns || !rdns[0]) {
  1881. slapi_ldap_value_free(rdns);
  1882. return;
  1883. }
  1884. slapi_ch_free_string(new_dn_string);
  1885. *new_dn_string = PR_smprintf("%s,%s", rdns[0], slapi_sdn_get_dn(ds_suffix));
  1886. slapi_ldap_value_free(rdns);
  1887. #endif
  1888. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1889. "<-- test_winsync_get_new_ds_user_dn_cb -- new dn [%s] -- end\n",
  1890. *new_dn_string);
  1891. return;
  1892. }
  1893. static void
  1894. test_winsync_get_new_ds_group_dn_cb(void *cbdata, const Slapi_Entry *rawentry,
  1895. Slapi_Entry *ad_entry, char **new_dn_string,
  1896. const Slapi_DN *ds_suffix, const Slapi_DN *ad_suffix)
  1897. {
  1898. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1899. "--> test_winsync_get_new_ds_group_dn_cb -- begin\n");
  1900. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1901. "<-- test_winsync_get_new_ds_group_dn_cb -- end\n");
  1902. return;
  1903. }
  1904. static void
  1905. test_winsync_pre_ad_mod_user_mods_cb(void *cbdata, const Slapi_Entry *rawentry,
  1906. const Slapi_Entry *ds_entry,
  1907. const Slapi_DN *local_dn, LDAPMod * const *origmods,
  1908. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  1909. {
  1910. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1911. "--> test_winsync_pre_ad_mod_user_mods_cb -- begin\n");
  1912. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1913. "<-- test_winsync_pre_ad_mod_user_mods_cb -- end\n");
  1914. return;
  1915. }
  1916. static void
  1917. test_winsync_pre_ad_mod_group_mods_cb(void *cbdata, const Slapi_Entry *rawentry,
  1918. const Slapi_Entry *ds_entry,
  1919. const Slapi_DN *local_dn, LDAPMod * const *origmods,
  1920. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  1921. {
  1922. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1923. "--> test_winsync_pre_ad_mod_group_mods_cb -- begin\n");
  1924. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1925. "<-- test_winsync_pre_ad_mod_group_mods_cb -- end\n");
  1926. return;
  1927. }
  1928. static int
  1929. test_winsync_can_add_entry_to_ad_cb(void *cbdata, const Slapi_Entry *local_entry,
  1930. const Slapi_DN *remote_dn)
  1931. {
  1932. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1933. "--> test_winsync_can_add_entry_to_ad_cb -- begin\n");
  1934. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1935. "<-- test_winsync_can_add_entry_to_ad_cb -- end\n");
  1936. /* return 0;*/ /* false - do not allow entries to be added to ad */
  1937. return 1; /* true - allow entries to be added to ad */
  1938. }
  1939. static void
  1940. test_winsync_begin_update_cb(void *cbdata, const Slapi_DN *ds_subtree,
  1941. const Slapi_DN *ad_subtree, int is_total)
  1942. {
  1943. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1944. "--> test_winsync_begin_update_cb -- begin\n");
  1945. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1946. "<-- test_winsync_begin_update_cb -- end\n");
  1947. return;
  1948. }
  1949. static void
  1950. test_winsync_end_update_cb(void *cbdata, const Slapi_DN *ds_subtree,
  1951. const Slapi_DN *ad_subtree, int is_total)
  1952. {
  1953. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1954. "--> test_winsync_end_update_cb -- begin\n");
  1955. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1956. "<-- test_winsync_end_update_cb -- end\n");
  1957. return;
  1958. }
  1959. static void
  1960. test_winsync_destroy_agmt_cb(void *cbdata, const Slapi_DN *ds_subtree,
  1961. const Slapi_DN *ad_subtree)
  1962. {
  1963. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1964. "--> test_winsync_destroy_agmt_cb -- begin\n");
  1965. /* free(cbdata); */
  1966. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1967. "<-- test_winsync_destroy_agmt_cb -- end\n");
  1968. return;
  1969. }
  1970. static void
  1971. test_winsync_post_ad_mod_user_cb(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, Slapi_Mods *smods, int *result)
  1972. {
  1973. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1974. "--> test_winsync_post_ad_mod_user_cb -- begin\n");
  1975. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1976. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1977. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1978. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1979. #endif
  1980. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1981. "<-- test_winsync_post_ad_mod_user_cb -- end\n");
  1982. return;
  1983. }
  1984. static void
  1985. test_winsync_post_ad_mod_group_cb(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, Slapi_Mods *smods, int *result)
  1986. {
  1987. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1988. "--> test_winsync_post_ad_mod_group_cb -- begin\n");
  1989. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1990. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1991. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1992. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1993. #endif
  1994. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1995. "<-- test_winsync_post_ad_mod_group_cb -- end\n");
  1996. return;
  1997. }
  1998. static void
  1999. test_winsync_post_ds_mod_user_cb(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, Slapi_Mods *smods, int *result)
  2000. {
  2001. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2002. "--> test_winsync_post_ds_mod_user_cb -- begin\n");
  2003. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2004. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2005. "Result of modifying DS entry [%s] was [%d:%s]\n",
  2006. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  2007. #endif
  2008. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2009. "<-- test_winsync_post_ds_mod_user_cb -- end\n");
  2010. return;
  2011. }
  2012. static void
  2013. test_winsync_post_ds_mod_group_cb(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, Slapi_Mods *smods, int *result)
  2014. {
  2015. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2016. "--> test_winsync_post_ds_mod_group_cb -- begin\n");
  2017. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2018. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2019. "Result of modifying DS entry [%s] was [%d:%s]\n",
  2020. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  2021. #endif
  2022. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2023. "<-- test_winsync_post_ds_mod_group_cb -- end\n");
  2024. return;
  2025. }
  2026. static void
  2027. test_winsync_post_ds_add_user_cb(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  2028. {
  2029. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2030. "--> test_winsync_post_ds_add_user_cb -- begin\n");
  2031. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2032. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2033. "Result of adding DS entry [%s] was [%d:%s]\n",
  2034. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  2035. #endif
  2036. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2037. "<-- test_winsync_post_ds_add_user_cb -- end\n");
  2038. return;
  2039. }
  2040. static void
  2041. test_winsync_post_ds_add_group_cb(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  2042. {
  2043. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2044. "--> test_winsync_post_ds_add_group_cb -- begin\n");
  2045. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2046. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2047. "Result of adding DS entry [%s] was [%d:%s]\n",
  2048. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  2049. #endif
  2050. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2051. "<-- test_winsync_post_ds_add_group_cb -- end\n");
  2052. return;
  2053. }
  2054. static void
  2055. test_winsync_pre_ad_add_user_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry)
  2056. {
  2057. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2058. "--> test_winsync_pre_ad_add_user_cb -- begin\n");
  2059. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2060. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2061. "Adding AD entry [%s] from add of DS entry [%s]\n",
  2062. slapi_entry_get_dn(ad_entry), slapi_entry_get_dn(ds_entry));
  2063. /* make modifications to ad_entry here */
  2064. #endif
  2065. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2066. "<-- test_winsync_pre_ad_add_user_cb -- end\n");
  2067. return;
  2068. }
  2069. static void
  2070. test_winsync_pre_ad_add_group_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry)
  2071. {
  2072. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2073. "--> test_winsync_pre_ad_add_group_cb -- begin\n");
  2074. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2075. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2076. "Adding AD entry [%s] from add of DS entry [%s]\n",
  2077. slapi_entry_get_dn(ad_entry), slapi_entry_get_dn(ds_entry));
  2078. /* make modifications to ad_entry here */
  2079. #endif
  2080. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2081. "<-- test_winsync_pre_ad_add_group_cb -- end\n");
  2082. return;
  2083. }
  2084. static void
  2085. test_winsync_post_ad_add_user_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry, int *result)
  2086. {
  2087. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2088. "--> test_winsync_post_ad_add_user_cb -- begin\n");
  2089. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2090. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2091. "Result of adding AD entry [%s] was [%d:%s]\n",
  2092. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  2093. #endif
  2094. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2095. "<-- test_winsync_post_ad_add_user_cb -- end\n");
  2096. return;
  2097. }
  2098. static void
  2099. test_winsync_post_ad_add_group_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry, int *result)
  2100. {
  2101. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2102. "--> test_winsync_post_ad_add_group_cb -- begin\n");
  2103. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2104. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2105. "Result of adding AD entry [%s] was [%d:%s]\n",
  2106. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  2107. #endif
  2108. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2109. "<-- test_winsync_post_ad_add_group_cb -- end\n");
  2110. return;
  2111. }
  2112. static void
  2113. test_winsync_post_ad_mod_user_mods_cb(void *cookie, const Slapi_Entry *rawentry, const Slapi_DN *local_dn, const Slapi_Entry *ds_entry, LDAPMod * const *origmods, Slapi_DN *remote_dn, LDAPMod ***modstosend, int *result)
  2114. {
  2115. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2116. "--> test_winsync_post_ad_mod_user_mods_cb -- begin\n");
  2117. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2118. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2119. "Result of modifying AD entry [%s] was [%d:%s]\n",
  2120. slapi_sdn_get_dn(remote_dn), *result, ldap_err2string(*result));
  2121. #endif
  2122. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2123. "<-- test_winsync_post_ad_mod_user_mods_cb -- end\n");
  2124. return;
  2125. }
  2126. static void
  2127. test_winsync_post_ad_mod_group_mods_cb(void *cookie, const Slapi_Entry *rawentry, const Slapi_DN *local_dn, const Slapi_Entry *ds_entry, LDAPMod * const *origmods, Slapi_DN *remote_dn, LDAPMod ***modstosend, int *result)
  2128. {
  2129. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2130. "--> test_winsync_post_ad_mod_group_mods_cb -- begin\n");
  2131. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2132. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2133. "Result of modifying AD entry [%s] was [%d:%s]\n",
  2134. slapi_sdn_get_dn(remote_dn), *result, ldap_err2string(*result));
  2135. #endif
  2136. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2137. "<-- test_winsync_post_ad_mod_group_mods_cb -- end\n");
  2138. return;
  2139. }
  2140. static int
  2141. test_winsync_precedence(void)
  2142. {
  2143. return 99;
  2144. }
  2145. /**
  2146. * Plugin identifiers
  2147. */
  2148. static Slapi_PluginDesc test_winsync_pdesc = {
  2149. "test-winsync-plugin",
  2150. VENDOR,
  2151. DS_PACKAGE_VERSION,
  2152. "test winsync plugin"
  2153. };
  2154. static Slapi_ComponentId *test_winsync_plugin_id = NULL;
  2155. #ifdef TEST_V1_WINSYNC_API
  2156. static void *test_winsync_api_v1[] = {
  2157. NULL, /* reserved for api broker use, must be zero */
  2158. test_winsync_api_init,
  2159. test_winsync_dirsync_search_params_cb,
  2160. test_winsync_pre_ad_search_cb,
  2161. test_winsync_pre_ds_search_entry_cb,
  2162. test_winsync_pre_ds_search_all_cb,
  2163. test_winsync_pre_ad_mod_user_cb,
  2164. test_winsync_pre_ad_mod_group_cb,
  2165. test_winsync_pre_ds_mod_user_cb,
  2166. test_winsync_pre_ds_mod_group_cb,
  2167. test_winsync_pre_ds_add_user_cb,
  2168. test_winsync_pre_ds_add_group_cb,
  2169. test_winsync_get_new_ds_user_dn_cb,
  2170. test_winsync_get_new_ds_group_dn_cb,
  2171. test_winsync_pre_ad_mod_user_mods_cb,
  2172. test_winsync_pre_ad_mod_group_mods_cb,
  2173. test_winsync_can_add_entry_to_ad_cb,
  2174. test_winsync_begin_update_cb,
  2175. test_winsync_end_update_cb,
  2176. test_winsync_destroy_agmt_cb
  2177. };
  2178. #endif /* TEST_V1_WINSYNC_API */
  2179. #ifdef TEST_V2_WINSYNC_API
  2180. static void *test_winsync_api_v2[] = {
  2181. NULL, /* reserved for api broker use, must be zero */
  2182. test_winsync_api_init,
  2183. test_winsync_dirsync_search_params_cb,
  2184. test_winsync_pre_ad_search_cb,
  2185. test_winsync_pre_ds_search_entry_cb,
  2186. test_winsync_pre_ds_search_all_cb,
  2187. test_winsync_pre_ad_mod_user_cb,
  2188. test_winsync_pre_ad_mod_group_cb,
  2189. test_winsync_pre_ds_mod_user_cb,
  2190. test_winsync_pre_ds_mod_group_cb,
  2191. test_winsync_pre_ds_add_user_cb,
  2192. test_winsync_pre_ds_add_group_cb,
  2193. test_winsync_get_new_ds_user_dn_cb,
  2194. test_winsync_get_new_ds_group_dn_cb,
  2195. test_winsync_pre_ad_mod_user_mods_cb,
  2196. test_winsync_pre_ad_mod_group_mods_cb,
  2197. test_winsync_can_add_entry_to_ad_cb,
  2198. test_winsync_begin_update_cb,
  2199. test_winsync_end_update_cb,
  2200. test_winsync_destroy_agmt_cb,
  2201. test_winsync_post_ad_mod_user_cb,
  2202. test_winsync_post_ad_mod_group_cb,
  2203. test_winsync_post_ds_mod_user_cb,
  2204. test_winsync_post_ds_mod_group_cb,
  2205. test_winsync_post_ds_add_user_cb,
  2206. test_winsync_post_ds_add_group_cb,
  2207. test_winsync_pre_ad_add_user_cb,
  2208. test_winsync_pre_ad_add_group_cb,
  2209. test_winsync_post_ad_add_user_cb,
  2210. test_winsync_post_ad_add_group_cb,
  2211. test_winsync_post_ad_mod_user_mods_cb,
  2212. test_winsync_post_ad_mod_group_mods_cb
  2213. };
  2214. #endif /* TEST_V2_WINSYNC_API */
  2215. static void *test_winsync_api_v3[] = {
  2216. NULL, /* reserved for api broker use, must be zero */
  2217. test_winsync_api_init,
  2218. test_winsync_dirsync_search_params_cb,
  2219. test_winsync_pre_ad_search_cb,
  2220. test_winsync_pre_ds_search_entry_cb,
  2221. test_winsync_pre_ds_search_all_cb,
  2222. test_winsync_pre_ad_mod_user_cb,
  2223. test_winsync_pre_ad_mod_group_cb,
  2224. test_winsync_pre_ds_mod_user_cb,
  2225. test_winsync_pre_ds_mod_group_cb,
  2226. test_winsync_pre_ds_add_user_cb,
  2227. test_winsync_pre_ds_add_group_cb,
  2228. test_winsync_get_new_ds_user_dn_cb,
  2229. test_winsync_get_new_ds_group_dn_cb,
  2230. test_winsync_pre_ad_mod_user_mods_cb,
  2231. test_winsync_pre_ad_mod_group_mods_cb,
  2232. test_winsync_can_add_entry_to_ad_cb,
  2233. test_winsync_begin_update_cb,
  2234. test_winsync_end_update_cb,
  2235. test_winsync_destroy_agmt_cb,
  2236. test_winsync_post_ad_mod_user_cb,
  2237. test_winsync_post_ad_mod_group_cb,
  2238. test_winsync_post_ds_mod_user_cb,
  2239. test_winsync_post_ds_mod_group_cb,
  2240. test_winsync_post_ds_add_user_cb,
  2241. test_winsync_post_ds_add_group_cb,
  2242. test_winsync_pre_ad_add_user_cb,
  2243. test_winsync_pre_ad_add_group_cb,
  2244. test_winsync_post_ad_add_user_cb,
  2245. test_winsync_post_ad_add_group_cb,
  2246. test_winsync_post_ad_mod_user_mods_cb,
  2247. test_winsync_post_ad_mod_group_mods_cb,
  2248. test_winsync_precedence
  2249. };
  2250. static int
  2251. test_winsync_plugin_start(Slapi_PBlock *pb)
  2252. {
  2253. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2254. "--> test_winsync_plugin_start -- begin\n");
  2255. if( slapi_apib_register(WINSYNC_v3_0_GUID, test_winsync_api_v3) ) {
  2256. slapi_log_error( SLAPI_LOG_FATAL, test_winsync_plugin_name,
  2257. "<-- test_winsync_plugin_start -- failed to register winsync api -- end\n");
  2258. return -1;
  2259. }
  2260. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2261. "<-- test_winsync_plugin_start -- end\n");
  2262. return 0;
  2263. }
  2264. static int
  2265. test_winsync_plugin_close(Slapi_PBlock *pb)
  2266. {
  2267. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2268. "--> test_winsync_plugin_close -- begin\n");
  2269. slapi_apib_unregister(WINSYNC_v3_0_GUID);
  2270. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2271. "<-- test_winsync_plugin_close -- end\n");
  2272. return 0;
  2273. }
  2274. /* this is the slapi plugin init function,
  2275. not the one used by the winsync api
  2276. */
  2277. int test_winsync_plugin_init(Slapi_PBlock *pb)
  2278. {
  2279. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2280. "--> test_winsync_plugin_init -- begin\n");
  2281. if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  2282. SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  2283. slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN,
  2284. (void *) test_winsync_plugin_start ) != 0 ||
  2285. slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN,
  2286. (void *) test_winsync_plugin_close ) != 0 ||
  2287. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  2288. (void *)&test_winsync_pdesc ) != 0 )
  2289. {
  2290. slapi_log_error( SLAPI_LOG_FATAL, test_winsync_plugin_name,
  2291. "<-- test_winsync_plugin_init -- failed to register plugin -- end\n");
  2292. return -1;
  2293. }
  2294. /* Retrieve and save the plugin identity to later pass to
  2295. internal operations */
  2296. if (slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &test_winsync_plugin_id) != 0) {
  2297. slapi_log_error(SLAPI_LOG_FATAL, test_winsync_plugin_name,
  2298. "<-- test_winsync_plugin_init -- failed to retrieve plugin identity -- end\n");
  2299. return -1;
  2300. }
  2301. slapi_log_error( SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2302. "<-- test_winsync_plugin_init -- end\n");
  2303. return 0;
  2304. }
  2305. /*
  2306. dn: cn=Test Winsync API,cn=plugins,cn=config
  2307. objectclass: top
  2308. objectclass: nsSlapdPlugin
  2309. objectclass: extensibleObject
  2310. cn: Test Winsync API
  2311. nsslapd-pluginpath: libtestwinsync-plugin
  2312. nsslapd-plugininitfunc: test_winsync_plugin_init
  2313. nsslapd-plugintype: preoperation
  2314. nsslapd-pluginenabled: on
  2315. nsslapd-plugin-depends-on-type: database
  2316. nsslapd-pluginDescription: Test Winsync
  2317. nsslapd-pluginVendor: 389 project
  2318. nsslapd-pluginId: test-winsync
  2319. nsslapd-pluginVersion: 0.9
  2320. */
  2321. #endif /* WINSYNC_SAMPLE_CODE */
  2322. /* #define WINSYNC_TEST_IPA */
  2323. #ifdef WINSYNC_TEST_IPA
  2324. #include "ipa-winsync.c"
  2325. #include "ipa-winsync-config.c"
  2326. #endif