windows_private.c 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967
  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. /* Get entry being retrieved; used for the range retrieval */
  1221. Slapi_Entry *
  1222. windows_private_get_curr_entry(const Repl_Agmt *ra)
  1223. {
  1224. Dirsync_Private *dp;
  1225. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_curr_entry\n" );
  1226. PR_ASSERT(ra);
  1227. dp = (Dirsync_Private *) agmt_get_priv(ra);
  1228. PR_ASSERT (dp);
  1229. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_curr_entry\n" );
  1230. return dp->curr_entry;
  1231. }
  1232. /* Set entry being retrieved; used for the range retrieval */
  1233. void
  1234. windows_private_set_curr_entry(const Repl_Agmt *ra, Slapi_Entry *e)
  1235. {
  1236. Dirsync_Private *dp;
  1237. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_curr_entry\n" );
  1238. PR_ASSERT(ra);
  1239. dp = (Dirsync_Private *) agmt_get_priv(ra);
  1240. PR_ASSERT (dp);
  1241. dp->curr_entry = e;
  1242. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_curr_entry\n" );
  1243. }
  1244. /* Get next range retrieval attributes */
  1245. char **
  1246. windows_private_get_range_attrs(const Repl_Agmt *ra)
  1247. {
  1248. Dirsync_Private *dp;
  1249. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_range_attrs\n" );
  1250. PR_ASSERT(ra);
  1251. dp = (Dirsync_Private *) agmt_get_priv(ra);
  1252. PR_ASSERT (dp);
  1253. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_range_attrs\n" );
  1254. return dp->range_attrs;
  1255. }
  1256. /* Set next range retrieval attributes */
  1257. void
  1258. windows_private_set_range_attrs(const Repl_Agmt *ra, char **attrs)
  1259. {
  1260. Dirsync_Private *dp;
  1261. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_move_action\n" );
  1262. PR_ASSERT(ra);
  1263. dp = (Dirsync_Private *) agmt_get_priv(ra);
  1264. PR_ASSERT (dp);
  1265. dp->range_attrs = attrs;
  1266. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_move_action\n" );
  1267. }
  1268. static PRCallOnceType winsync_callOnce = {0,0};
  1269. struct winsync_plugin {
  1270. struct winsync_plugin *next; /* see PRCList - declare here to avoid lots of casting */
  1271. struct winsync_plugin *prev; /* see PRCList - declare here to avoid lots of casting */
  1272. void **api; /* the api - array of function pointers */
  1273. int maxapi; /* the max index i.e. the api version */
  1274. int precedence; /* lower number == higher precedence */
  1275. };
  1276. static struct winsync_plugin winsync_plugin_list;
  1277. #define DECL_WINSYNC_API_IDX_FUNC(theapi,idx,maxidx,thetype,thefunc) \
  1278. thetype thefunc = (theapi && (idx <= maxidx) && theapi[idx]) ? \
  1279. (thetype)theapi[idx] : NULL;
  1280. #define WINSYNC_PLUGIN_CALL_PLUGINS_BEGIN(idx,thetype,thefunc) \
  1281. struct winsync_plugin *elem; \
  1282. for (elem = PR_LIST_HEAD(&winsync_plugin_list); \
  1283. elem && (elem != &winsync_plugin_list); \
  1284. elem = PR_NEXT_LINK(elem)) { \
  1285. DECL_WINSYNC_API_IDX_FUNC(elem->api,idx,elem->maxapi,thetype,thefunc); \
  1286. if (thefunc) {
  1287. #define WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(idx,thetype,thefunc) \
  1288. WINSYNC_PLUGIN_CALL_PLUGINS_BEGIN(idx,thetype,thefunc) \
  1289. void *cookie = winsync_plugin_cookie_find(ra, elem->api);
  1290. #define WINSYNC_PLUGIN_CALL_PLUGINS_END } /* this one matches if thefunc */ } /* this one matches the for loop */
  1291. /* this structure is per agreement - to store the cookie per agreement
  1292. for each winsync plugin */
  1293. struct winsync_plugin_cookie {
  1294. struct winsync_plugin_cookie *next; /* see PRCList - declare here to avoid lots of casting */
  1295. struct winsync_plugin_cookie *prev; /* see PRCList - declare here to avoid lots of casting */
  1296. void **api; /* the api - array of function pointers */
  1297. void *cookie; /* plugin data */
  1298. };
  1299. static struct winsync_plugin *
  1300. new_winsync_plugin(void **theapi, int maxapi, int precedence)
  1301. {
  1302. struct winsync_plugin *wpi = (struct winsync_plugin *)slapi_ch_calloc(1, sizeof(struct winsync_plugin));
  1303. wpi->api = theapi;
  1304. wpi->maxapi = maxapi;
  1305. wpi->precedence = precedence;
  1306. return wpi;
  1307. }
  1308. static struct winsync_plugin *
  1309. windows_plugin_find(void **theapi)
  1310. {
  1311. struct winsync_plugin *elem = PR_LIST_HEAD(&winsync_plugin_list);
  1312. while (elem && (elem != &winsync_plugin_list)) {
  1313. if (theapi == elem->api) {
  1314. return elem;
  1315. }
  1316. elem = PR_NEXT_LINK(elem);
  1317. }
  1318. return NULL;
  1319. }
  1320. /* returns 0 for success - 1 means already added - -1 means some error */
  1321. static int
  1322. windows_plugin_add(void **theapi, int maxapi)
  1323. {
  1324. int precedence = WINSYNC_PLUGIN_DEFAULT_PRECEDENCE;
  1325. DECL_WINSYNC_API_IDX_FUNC(theapi,WINSYNC_PLUGIN_PRECEDENCE_CB,maxapi,winsync_plugin_precedence_cb,thefunc);
  1326. if (thefunc) {
  1327. /* supports precedence */
  1328. precedence = (*thefunc)();
  1329. }
  1330. if (PR_CLIST_IS_EMPTY(&winsync_plugin_list)) {
  1331. struct winsync_plugin *wpi = new_winsync_plugin(theapi, maxapi, precedence);
  1332. PR_INSERT_LINK(wpi, &winsync_plugin_list);
  1333. return 0;
  1334. } else if (windows_plugin_find(theapi)) {
  1335. return 1; /* already in list */
  1336. } else {
  1337. struct winsync_plugin *wpi = new_winsync_plugin(theapi, maxapi, precedence);
  1338. struct winsync_plugin *elem = PR_LIST_HEAD(&winsync_plugin_list);
  1339. while (elem && (elem != &winsync_plugin_list)) {
  1340. if (precedence < elem->precedence) {
  1341. PR_INSERT_BEFORE(wpi, elem);
  1342. wpi = NULL; /* owned by list now */
  1343. break;
  1344. }
  1345. elem = PR_NEXT_LINK(elem);
  1346. }
  1347. if (elem && wpi) { /* was not added - precedence too high */
  1348. /* just add to end of list */
  1349. PR_INSERT_BEFORE(wpi, elem);
  1350. wpi = NULL; /* owned by list now */
  1351. }
  1352. /* if we got here and wpi is not NULL we need to free wpi */
  1353. slapi_ch_free((void **)&wpi);
  1354. return 0;
  1355. }
  1356. return -1;
  1357. }
  1358. static PRStatus
  1359. windows_plugin_callonce(void)
  1360. {
  1361. char *guids[] = {WINSYNC_v3_0_GUID, WINSYNC_v2_0_GUID, WINSYNC_v1_0_GUID, NULL};
  1362. int maxapis[] = {WINSYNC_PLUGIN_VERSION_3_END, WINSYNC_PLUGIN_VERSION_2_END,
  1363. WINSYNC_PLUGIN_VERSION_1_END, 0};
  1364. int ii;
  1365. PR_INIT_CLIST(&winsync_plugin_list);
  1366. /* loop through all of the registered winsync plugins - look for them in reverse
  1367. version order (e.g. look for v3 first) - if there are no plugins registered
  1368. for the given version, or we have already registered all plugins for a given
  1369. version, just go to the next lowest version */
  1370. for (ii = 0; guids[ii]; ++ii) {
  1371. char *guid = guids[ii];
  1372. int maxapi = maxapis[ii];
  1373. void ***theapis = NULL;
  1374. if (slapi_apib_get_interface_all(guid, &theapis) || (NULL == theapis)) {
  1375. LDAPDebug1Arg(LDAP_DEBUG_PLUGIN,
  1376. "<-- windows_plugin_callonce -- no more windows plugin APIs registered "
  1377. "for GUID [%s] -- end\n",
  1378. guid);
  1379. } else {
  1380. int idx;
  1381. for (idx = 0; theapis && theapis[idx]; ++idx) {
  1382. if (windows_plugin_add(theapis[idx], maxapi)) {
  1383. LDAPDebug(LDAP_DEBUG_PLUGIN,
  1384. "<-- windows_plugin_callonce -- already added windows plugin API "
  1385. "[%d][0x%p] for GUID [%s] -- end\n",
  1386. idx, theapis[idx], guid);
  1387. }
  1388. }
  1389. }
  1390. slapi_ch_free((void **)&theapis);
  1391. }
  1392. return PR_SUCCESS;
  1393. }
  1394. static struct winsync_plugin_cookie *
  1395. new_winsync_plugin_cookie(void **theapi, void *cookie)
  1396. {
  1397. struct winsync_plugin_cookie *wpc = (struct winsync_plugin_cookie *)slapi_ch_calloc(1, sizeof(struct winsync_plugin_cookie));
  1398. wpc->api = theapi;
  1399. wpc->cookie = cookie;
  1400. return wpc;
  1401. }
  1402. static void *
  1403. winsync_plugin_cookie_find(const Repl_Agmt *ra, void **theapi)
  1404. {
  1405. if (ra) {
  1406. struct winsync_plugin_cookie *list = (struct winsync_plugin_cookie *)windows_private_get_api_cookie(ra);
  1407. if (list) {
  1408. struct winsync_plugin_cookie *elem = PR_LIST_HEAD(list);
  1409. while (elem && (elem != list)) {
  1410. if (theapi == elem->api) {
  1411. return elem->cookie;
  1412. }
  1413. elem = PR_NEXT_LINK(elem);
  1414. }
  1415. }
  1416. }
  1417. return NULL;
  1418. }
  1419. static void
  1420. winsync_plugin_cookie_add(struct winsync_plugin_cookie **list, void **theapi, void *cookie)
  1421. {
  1422. struct winsync_plugin_cookie *elem = NULL;
  1423. if (!*list) {
  1424. *list = new_winsync_plugin_cookie(NULL, NULL);
  1425. PR_INIT_CLIST(*list);
  1426. }
  1427. elem = new_winsync_plugin_cookie(theapi, cookie);
  1428. PR_INSERT_BEFORE(elem, *list);
  1429. return;
  1430. }
  1431. void
  1432. windows_plugin_init(Repl_Agmt *ra)
  1433. {
  1434. struct winsync_plugin_cookie *list = NULL;
  1435. void *cookie = NULL;
  1436. LDAPDebug0Args( LDAP_DEBUG_PLUGIN, "--> windows_plugin_init_start -- begin\n");
  1437. if (PR_CallOnce(&winsync_callOnce, windows_plugin_callonce)) {
  1438. PRErrorCode prerr = PR_GetError();
  1439. slapi_log_error(SLAPI_LOG_FATAL, "windows_plugin_init",
  1440. "cannot initialize plugin: %d:%s\n", prerr,
  1441. slapi_pr_strerror(prerr));
  1442. return;
  1443. }
  1444. /* call each plugin init function in turn - store the returned cookie
  1445. indexed by the api */
  1446. {
  1447. WINSYNC_PLUGIN_CALL_PLUGINS_BEGIN(WINSYNC_PLUGIN_INIT_CB,winsync_plugin_init_cb,thefunc)
  1448. cookie = (*thefunc)(windows_private_get_directory_subtree(ra),
  1449. windows_private_get_windows_subtree(ra));
  1450. if (cookie) {
  1451. winsync_plugin_cookie_add(&list, elem->api, cookie);
  1452. }
  1453. WINSYNC_PLUGIN_CALL_PLUGINS_END
  1454. }
  1455. windows_private_set_api_cookie(ra, list);
  1456. LDAPDebug0Args( LDAP_DEBUG_PLUGIN, "<-- windows_plugin_init_start -- end\n");
  1457. return;
  1458. }
  1459. void
  1460. windows_plugin_cleanup_agmt(Repl_Agmt *ra)
  1461. {
  1462. struct winsync_plugin_cookie *list = (struct winsync_plugin_cookie *)windows_private_get_api_cookie(ra);
  1463. struct winsync_plugin_cookie *elem = NULL;
  1464. while (list && !PR_CLIST_IS_EMPTY(list)) {
  1465. elem = PR_LIST_HEAD(list);
  1466. PR_REMOVE_LINK(elem);
  1467. slapi_ch_free((void **)&elem);
  1468. }
  1469. slapi_ch_free((void **)&list);
  1470. windows_private_set_api_cookie(ra, NULL);
  1471. return;
  1472. }
  1473. void
  1474. winsync_plugin_call_dirsync_search_params_cb(const Repl_Agmt *ra, const char *agmt_dn,
  1475. char **base, int *scope, char **filter,
  1476. char ***attrs, LDAPControl ***serverctrls)
  1477. {
  1478. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_DIRSYNC_SEARCH_CB,winsync_search_params_cb,thefunc)
  1479. (*thefunc)(cookie, agmt_dn, base, scope, filter, attrs, serverctrls);
  1480. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1481. return;
  1482. }
  1483. void
  1484. winsync_plugin_call_pre_ad_search_cb(const Repl_Agmt *ra, const char *agmt_dn,
  1485. char **base, int *scope, char **filter,
  1486. char ***attrs, LDAPControl ***serverctrls)
  1487. {
  1488. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_AD_SEARCH_CB,winsync_search_params_cb,thefunc)
  1489. (*thefunc)(cookie, agmt_dn, base, scope, filter, attrs, serverctrls);
  1490. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1491. return;
  1492. }
  1493. void
  1494. winsync_plugin_call_pre_ds_search_entry_cb(const Repl_Agmt *ra, const char *agmt_dn,
  1495. char **base, int *scope, char **filter,
  1496. char ***attrs, LDAPControl ***serverctrls)
  1497. {
  1498. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_DS_SEARCH_ENTRY_CB,winsync_search_params_cb,thefunc)
  1499. (*thefunc)(cookie, agmt_dn, base, scope, filter, attrs, serverctrls);
  1500. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1501. return;
  1502. }
  1503. void
  1504. winsync_plugin_call_pre_ds_search_all_cb(const Repl_Agmt *ra, const char *agmt_dn,
  1505. char **base, int *scope, char **filter,
  1506. char ***attrs, LDAPControl ***serverctrls)
  1507. {
  1508. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_DS_SEARCH_ALL_CB,winsync_search_params_cb,thefunc)
  1509. (*thefunc)(cookie, agmt_dn, base, scope, filter, attrs, serverctrls);
  1510. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1511. return;
  1512. }
  1513. void
  1514. winsync_plugin_call_pre_ad_mod_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1515. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1516. Slapi_Mods *smods, int *do_modify)
  1517. {
  1518. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_AD_MOD_USER_CB,winsync_pre_mod_cb,thefunc)
  1519. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, smods, do_modify);
  1520. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1521. return;
  1522. }
  1523. void
  1524. winsync_plugin_call_pre_ad_mod_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1525. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1526. Slapi_Mods *smods, int *do_modify)
  1527. {
  1528. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_AD_MOD_GROUP_CB,winsync_pre_mod_cb,thefunc)
  1529. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, smods, do_modify);
  1530. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1531. return;
  1532. }
  1533. void
  1534. winsync_plugin_call_pre_ds_mod_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1535. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1536. Slapi_Mods *smods, int *do_modify)
  1537. {
  1538. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_DS_MOD_USER_CB,winsync_pre_mod_cb,thefunc)
  1539. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, smods, do_modify);
  1540. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1541. return;
  1542. }
  1543. void
  1544. winsync_plugin_call_pre_ds_mod_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1545. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1546. Slapi_Mods *smods, int *do_modify)
  1547. {
  1548. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_DS_MOD_GROUP_CB,winsync_pre_mod_cb,thefunc)
  1549. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, smods, do_modify);
  1550. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1551. return;
  1552. }
  1553. void
  1554. winsync_plugin_call_pre_ds_add_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1555. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry)
  1556. {
  1557. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_DS_ADD_USER_CB,winsync_pre_add_cb,thefunc)
  1558. (*thefunc)(cookie, rawentry, ad_entry, ds_entry);
  1559. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1560. return;
  1561. }
  1562. void
  1563. winsync_plugin_call_pre_ds_add_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1564. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry)
  1565. {
  1566. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_DS_ADD_GROUP_CB,winsync_pre_add_cb,thefunc)
  1567. (*thefunc)(cookie, rawentry, ad_entry, ds_entry);
  1568. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1569. return;
  1570. }
  1571. void
  1572. winsync_plugin_call_get_new_ds_user_dn_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1573. Slapi_Entry *ad_entry, char **new_dn_string,
  1574. const Slapi_DN *ds_suffix, const Slapi_DN *ad_suffix)
  1575. {
  1576. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_GET_NEW_DS_USER_DN_CB,winsync_get_new_dn_cb,thefunc)
  1577. (*thefunc)(cookie, rawentry, ad_entry, new_dn_string, ds_suffix, ad_suffix);
  1578. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1579. return;
  1580. }
  1581. void
  1582. winsync_plugin_call_get_new_ds_group_dn_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1583. Slapi_Entry *ad_entry, char **new_dn_string,
  1584. const Slapi_DN *ds_suffix, const Slapi_DN *ad_suffix)
  1585. {
  1586. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_GET_NEW_DS_GROUP_DN_CB,winsync_get_new_dn_cb,thefunc)
  1587. (*thefunc)(cookie, rawentry, ad_entry, new_dn_string, ds_suffix, ad_suffix);
  1588. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1589. return;
  1590. }
  1591. void
  1592. winsync_plugin_call_pre_ad_mod_user_mods_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1593. const Slapi_DN *local_dn,
  1594. const Slapi_Entry *ds_entry,
  1595. LDAPMod * const *origmods,
  1596. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  1597. {
  1598. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_AD_MOD_USER_MODS_CB,winsync_pre_ad_mod_mods_cb,thefunc)
  1599. (*thefunc)(cookie, rawentry, local_dn, ds_entry, origmods, remote_dn, modstosend);
  1600. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1601. return;
  1602. }
  1603. void
  1604. winsync_plugin_call_pre_ad_mod_group_mods_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1605. const Slapi_DN *local_dn,
  1606. const Slapi_Entry *ds_entry,
  1607. LDAPMod * const *origmods,
  1608. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  1609. {
  1610. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_AD_MOD_GROUP_MODS_CB,winsync_pre_ad_mod_mods_cb,thefunc)
  1611. (*thefunc)(cookie, rawentry, local_dn, ds_entry, origmods, remote_dn, modstosend);
  1612. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1613. return;
  1614. }
  1615. int
  1616. winsync_plugin_call_can_add_entry_to_ad_cb(const Repl_Agmt *ra, const Slapi_Entry *local_entry,
  1617. const Slapi_DN *remote_dn)
  1618. {
  1619. int canadd = 1;
  1620. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_CAN_ADD_ENTRY_TO_AD_CB,winsync_can_add_to_ad_cb,thefunc)
  1621. if (canadd) {
  1622. canadd = (*thefunc)(cookie, local_entry, remote_dn);
  1623. }
  1624. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1625. return canadd;
  1626. }
  1627. void
  1628. winsync_plugin_call_begin_update_cb(const Repl_Agmt *ra, const Slapi_DN *ds_subtree,
  1629. const Slapi_DN *ad_subtree, int is_total)
  1630. {
  1631. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_BEGIN_UPDATE_CB,winsync_plugin_update_cb,thefunc)
  1632. (*thefunc)(cookie, ds_subtree, ad_subtree, is_total);
  1633. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1634. return;
  1635. }
  1636. void
  1637. winsync_plugin_call_end_update_cb(const Repl_Agmt *ra, const Slapi_DN *ds_subtree,
  1638. const Slapi_DN *ad_subtree, int is_total)
  1639. {
  1640. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_END_UPDATE_CB,winsync_plugin_update_cb,thefunc)
  1641. (*thefunc)(cookie, ds_subtree, ad_subtree, is_total);
  1642. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1643. return;
  1644. }
  1645. void
  1646. winsync_plugin_call_destroy_agmt_cb(const Repl_Agmt *ra,
  1647. const Slapi_DN *ds_subtree,
  1648. const Slapi_DN *ad_subtree)
  1649. {
  1650. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_DESTROY_AGMT_CB,winsync_plugin_destroy_agmt_cb,thefunc)
  1651. (*thefunc)(cookie, ds_subtree, ad_subtree);
  1652. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1653. return;
  1654. }
  1655. void
  1656. winsync_plugin_call_post_ad_mod_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1657. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1658. Slapi_Mods *smods, int *result)
  1659. {
  1660. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_AD_MOD_USER_CB,winsync_post_mod_cb,thefunc)
  1661. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, smods, result);
  1662. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1663. return;
  1664. }
  1665. void
  1666. winsync_plugin_call_post_ad_mod_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1667. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1668. Slapi_Mods *smods, int *result)
  1669. {
  1670. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_AD_MOD_GROUP_CB,winsync_post_mod_cb,thefunc)
  1671. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, smods, result);
  1672. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1673. return;
  1674. }
  1675. void
  1676. winsync_plugin_call_post_ds_mod_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1677. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1678. Slapi_Mods *smods, int *result)
  1679. {
  1680. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_DS_MOD_USER_CB,winsync_post_mod_cb,thefunc)
  1681. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, smods, result);
  1682. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1683. return;
  1684. }
  1685. void
  1686. winsync_plugin_call_post_ds_mod_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1687. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1688. Slapi_Mods *smods, int *result)
  1689. {
  1690. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_DS_MOD_GROUP_CB,winsync_post_mod_cb,thefunc)
  1691. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, smods, result);
  1692. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1693. return;
  1694. }
  1695. void
  1696. winsync_plugin_call_post_ds_add_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1697. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  1698. {
  1699. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_DS_ADD_USER_CB,winsync_post_add_cb,thefunc)
  1700. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, result);
  1701. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1702. return;
  1703. }
  1704. void
  1705. winsync_plugin_call_post_ds_add_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1706. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  1707. {
  1708. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_DS_ADD_GROUP_CB,winsync_post_add_cb,thefunc)
  1709. (*thefunc)(cookie, rawentry, ad_entry, ds_entry, result);
  1710. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1711. return;
  1712. }
  1713. void
  1714. winsync_plugin_call_pre_ad_add_user_cb(const Repl_Agmt *ra, Slapi_Entry *ad_entry,
  1715. Slapi_Entry *ds_entry)
  1716. {
  1717. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_AD_ADD_USER_CB,winsync_pre_ad_add_cb,thefunc)
  1718. (*thefunc)(cookie, ad_entry, ds_entry);
  1719. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1720. return;
  1721. }
  1722. void
  1723. winsync_plugin_call_pre_ad_add_group_cb(const Repl_Agmt *ra, Slapi_Entry *ad_entry,
  1724. Slapi_Entry *ds_entry)
  1725. {
  1726. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_PRE_AD_ADD_GROUP_CB,winsync_pre_ad_add_cb,thefunc)
  1727. (*thefunc)(cookie, ad_entry, ds_entry);
  1728. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1729. return;
  1730. }
  1731. void
  1732. winsync_plugin_call_post_ad_add_user_cb(const Repl_Agmt *ra, Slapi_Entry *ad_entry,
  1733. Slapi_Entry *ds_entry, int *result)
  1734. {
  1735. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_AD_ADD_USER_CB,winsync_post_ad_add_cb,thefunc)
  1736. (*thefunc)(cookie, ad_entry, ds_entry, result);
  1737. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1738. return;
  1739. }
  1740. void
  1741. winsync_plugin_call_post_ad_add_group_cb(const Repl_Agmt *ra, Slapi_Entry *ad_entry,
  1742. Slapi_Entry *ds_entry, int *result)
  1743. {
  1744. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_AD_ADD_GROUP_CB,winsync_post_ad_add_cb,thefunc)
  1745. (*thefunc)(cookie, ad_entry, ds_entry, result);
  1746. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1747. return;
  1748. }
  1749. void
  1750. winsync_plugin_call_post_ad_mod_user_mods_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1751. const Slapi_DN *local_dn,
  1752. const Slapi_Entry *ds_entry,
  1753. LDAPMod * const *origmods,
  1754. Slapi_DN *remote_dn, LDAPMod **modstosend, int *result)
  1755. {
  1756. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_AD_MOD_USER_MODS_CB,winsync_post_ad_mod_mods_cb,thefunc)
  1757. (*thefunc)(cookie, rawentry, local_dn, ds_entry, origmods, remote_dn, modstosend, result);
  1758. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1759. return;
  1760. }
  1761. void
  1762. winsync_plugin_call_post_ad_mod_group_mods_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1763. const Slapi_DN *local_dn,
  1764. const Slapi_Entry *ds_entry,
  1765. LDAPMod * const *origmods,
  1766. Slapi_DN *remote_dn, LDAPMod **modstosend, int *result)
  1767. {
  1768. WINSYNC_PLUGIN_CALL_PLUGINS_COOKIE_BEGIN(WINSYNC_PLUGIN_POST_AD_MOD_GROUP_MODS_CB,winsync_post_ad_mod_mods_cb,thefunc)
  1769. (*thefunc)(cookie, rawentry, local_dn, ds_entry, origmods, remote_dn, modstosend, result);
  1770. WINSYNC_PLUGIN_CALL_PLUGINS_END;
  1771. return;
  1772. }
  1773. /*
  1774. The following are sample code stubs to show how to implement
  1775. a plugin which uses this api
  1776. */
  1777. #define WINSYNC_SAMPLE_CODE
  1778. #ifdef WINSYNC_SAMPLE_CODE
  1779. #include "slapi-plugin.h"
  1780. #include "winsync-plugin.h"
  1781. static char *test_winsync_plugin_name = "test_winsync_api";
  1782. static void *
  1783. test_winsync_api_init(const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree)
  1784. {
  1785. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1786. "--> test_winsync_init [%s] [%s] -- begin\n",
  1787. slapi_sdn_get_dn(ds_subtree),
  1788. slapi_sdn_get_dn(ad_subtree));
  1789. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1790. "<-- test_winsync_init -- end\n");
  1791. return NULL;
  1792. }
  1793. static void
  1794. test_winsync_dirsync_search_params_cb(void *cbdata, const char *agmt_dn,
  1795. char **base, int *scope, char **filter,
  1796. char ***attrs, LDAPControl ***serverctrls)
  1797. {
  1798. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1799. "--> test_winsync_dirsync_search_params_cb -- begin\n");
  1800. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1801. "<-- test_winsync_dirsync_search_params_cb -- end\n");
  1802. return;
  1803. }
  1804. /* called before searching for a single entry from AD - agmt_dn will be NULL */
  1805. static void
  1806. test_winsync_pre_ad_search_cb(void *cbdata, const char *agmt_dn,
  1807. char **base, int *scope, char **filter,
  1808. char ***attrs, LDAPControl ***serverctrls)
  1809. {
  1810. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1811. "--> test_winsync_pre_ad_search_cb -- begin\n");
  1812. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1813. "<-- test_winsync_pre_ad_search_cb -- end\n");
  1814. return;
  1815. }
  1816. /* called before an internal search to get a single DS entry - agmt_dn will be NULL */
  1817. static void
  1818. test_winsync_pre_ds_search_entry_cb(void *cbdata, const char *agmt_dn,
  1819. char **base, int *scope, char **filter,
  1820. char ***attrs, LDAPControl ***serverctrls)
  1821. {
  1822. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1823. "--> test_winsync_pre_ds_search_cb -- begin\n");
  1824. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1825. "<-- test_winsync_pre_ds_search_cb -- end\n");
  1826. return;
  1827. }
  1828. /* called before the total update to get all entries from the DS to sync to AD */
  1829. static void
  1830. test_winsync_pre_ds_search_all_cb(void *cbdata, const char *agmt_dn,
  1831. char **base, int *scope, char **filter,
  1832. char ***attrs, LDAPControl ***serverctrls)
  1833. {
  1834. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1835. "--> test_winsync_pre_ds_search_all_cb -- orig filter [%s] -- begin\n",
  1836. ((filter && *filter) ? *filter : "NULL"));
  1837. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1838. if (filter) {
  1839. /* We only want to grab users from the ds side - no groups */
  1840. slapi_ch_free_string(filter);
  1841. /* maybe use ntUniqueId=* - only get users that have already been
  1842. synced with AD already - ntUniqueId and ntUserDomainId are
  1843. indexed for equality only - need to add presence? */
  1844. *filter = slapi_ch_strdup("(&(objectclass=ntuser)(ntUserDomainId=*))");
  1845. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1846. "--> test_winsync_pre_ds_search_all_cb -- new filter [%s]\n",
  1847. *filter ? *filter : "NULL"));
  1848. }
  1849. #endif
  1850. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1851. "<-- test_winsync_pre_ds_search_all_cb -- end\n");
  1852. return;
  1853. }
  1854. static void
  1855. test_winsync_pre_ad_mod_user_cb(void *cbdata, const Slapi_Entry *rawentry,
  1856. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1857. Slapi_Mods *smods, int *do_modify)
  1858. {
  1859. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1860. "--> test_winsync_pre_ad_mod_user_cb -- begin\n");
  1861. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1862. "<-- test_winsync_pre_ad_mod_user_cb -- end\n");
  1863. return;
  1864. }
  1865. static void
  1866. test_winsync_pre_ad_mod_group_cb(void *cbdata, const Slapi_Entry *rawentry,
  1867. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1868. Slapi_Mods *smods, int *do_modify)
  1869. {
  1870. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1871. "--> test_winsync_pre_ad_mod_group_cb -- begin\n");
  1872. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1873. "<-- test_winsync_pre_ad_mod_group_cb -- end\n");
  1874. return;
  1875. }
  1876. static void
  1877. test_winsync_pre_ds_mod_user_cb(void *cbdata, const Slapi_Entry *rawentry,
  1878. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1879. Slapi_Mods *smods, int *do_modify)
  1880. {
  1881. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1882. "--> test_winsync_pre_ds_mod_user_cb -- begin\n");
  1883. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1884. "<-- test_winsync_pre_ds_mod_user_cb -- end\n");
  1885. return;
  1886. }
  1887. static void
  1888. test_winsync_pre_ds_mod_group_cb(void *cbdata, const Slapi_Entry *rawentry,
  1889. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1890. Slapi_Mods *smods, int *do_modify)
  1891. {
  1892. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1893. "--> test_winsync_pre_ds_mod_group_cb -- begin\n");
  1894. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1895. "<-- test_winsync_pre_ds_mod_group_cb -- end\n");
  1896. return;
  1897. }
  1898. static void
  1899. test_winsync_pre_ds_add_user_cb(void *cbdata, const Slapi_Entry *rawentry,
  1900. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry)
  1901. {
  1902. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1903. "--> test_winsync_pre_ds_add_user_cb -- begin\n");
  1904. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1905. "<-- test_winsync_pre_ds_add_user_cb -- end\n");
  1906. return;
  1907. }
  1908. static void
  1909. test_winsync_pre_ds_add_group_cb(void *cbdata, const Slapi_Entry *rawentry,
  1910. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry)
  1911. {
  1912. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1913. "--> test_winsync_pre_ds_add_group_cb -- begin\n");
  1914. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1915. "<-- test_winsync_pre_ds_add_group_cb -- end\n");
  1916. return;
  1917. }
  1918. static void
  1919. test_winsync_get_new_ds_user_dn_cb(void *cbdata, const Slapi_Entry *rawentry,
  1920. Slapi_Entry *ad_entry, char **new_dn_string,
  1921. const Slapi_DN *ds_suffix, const Slapi_DN *ad_suffix)
  1922. {
  1923. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1924. "--> test_winsync_get_new_ds_user_dn_cb -- old dn [%s] -- begin\n",
  1925. *new_dn_string);
  1926. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1927. char **rdns = slapi_ldap_explode_dn(*new_dn_string, 0);
  1928. if (!rdns || !rdns[0]) {
  1929. slapi_ldap_value_free(rdns);
  1930. return;
  1931. }
  1932. slapi_ch_free_string(new_dn_string);
  1933. *new_dn_string = PR_smprintf("%s,%s", rdns[0], slapi_sdn_get_dn(ds_suffix));
  1934. slapi_ldap_value_free(rdns);
  1935. #endif
  1936. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1937. "<-- test_winsync_get_new_ds_user_dn_cb -- new dn [%s] -- end\n",
  1938. *new_dn_string);
  1939. return;
  1940. }
  1941. static void
  1942. test_winsync_get_new_ds_group_dn_cb(void *cbdata, const Slapi_Entry *rawentry,
  1943. Slapi_Entry *ad_entry, char **new_dn_string,
  1944. const Slapi_DN *ds_suffix, const Slapi_DN *ad_suffix)
  1945. {
  1946. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1947. "--> test_winsync_get_new_ds_group_dn_cb -- begin\n");
  1948. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1949. "<-- test_winsync_get_new_ds_group_dn_cb -- end\n");
  1950. return;
  1951. }
  1952. static void
  1953. test_winsync_pre_ad_mod_user_mods_cb(void *cbdata, const Slapi_Entry *rawentry,
  1954. const Slapi_Entry *ds_entry,
  1955. const Slapi_DN *local_dn, LDAPMod * const *origmods,
  1956. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  1957. {
  1958. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1959. "--> test_winsync_pre_ad_mod_user_mods_cb -- begin\n");
  1960. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1961. "<-- test_winsync_pre_ad_mod_user_mods_cb -- end\n");
  1962. return;
  1963. }
  1964. static void
  1965. test_winsync_pre_ad_mod_group_mods_cb(void *cbdata, const Slapi_Entry *rawentry,
  1966. const Slapi_Entry *ds_entry,
  1967. const Slapi_DN *local_dn, LDAPMod * const *origmods,
  1968. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  1969. {
  1970. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1971. "--> test_winsync_pre_ad_mod_group_mods_cb -- begin\n");
  1972. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1973. "<-- test_winsync_pre_ad_mod_group_mods_cb -- end\n");
  1974. return;
  1975. }
  1976. static int
  1977. test_winsync_can_add_entry_to_ad_cb(void *cbdata, const Slapi_Entry *local_entry,
  1978. const Slapi_DN *remote_dn)
  1979. {
  1980. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1981. "--> test_winsync_can_add_entry_to_ad_cb -- begin\n");
  1982. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1983. "<-- test_winsync_can_add_entry_to_ad_cb -- end\n");
  1984. /* return 0;*/ /* false - do not allow entries to be added to ad */
  1985. return 1; /* true - allow entries to be added to ad */
  1986. }
  1987. static void
  1988. test_winsync_begin_update_cb(void *cbdata, const Slapi_DN *ds_subtree,
  1989. const Slapi_DN *ad_subtree, int is_total)
  1990. {
  1991. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1992. "--> test_winsync_begin_update_cb -- begin\n");
  1993. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  1994. "<-- test_winsync_begin_update_cb -- end\n");
  1995. return;
  1996. }
  1997. static void
  1998. test_winsync_end_update_cb(void *cbdata, const Slapi_DN *ds_subtree,
  1999. const Slapi_DN *ad_subtree, int is_total)
  2000. {
  2001. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2002. "--> test_winsync_end_update_cb -- begin\n");
  2003. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2004. "<-- test_winsync_end_update_cb -- end\n");
  2005. return;
  2006. }
  2007. static void
  2008. test_winsync_destroy_agmt_cb(void *cbdata, const Slapi_DN *ds_subtree,
  2009. const Slapi_DN *ad_subtree)
  2010. {
  2011. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2012. "--> test_winsync_destroy_agmt_cb -- begin\n");
  2013. /* free(cbdata); */
  2014. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2015. "<-- test_winsync_destroy_agmt_cb -- end\n");
  2016. return;
  2017. }
  2018. static void
  2019. 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)
  2020. {
  2021. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2022. "--> test_winsync_post_ad_mod_user_cb -- begin\n");
  2023. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2024. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2025. "Result of modifying AD entry [%s] was [%d:%s]\n",
  2026. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  2027. #endif
  2028. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2029. "<-- test_winsync_post_ad_mod_user_cb -- end\n");
  2030. return;
  2031. }
  2032. static void
  2033. 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)
  2034. {
  2035. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2036. "--> test_winsync_post_ad_mod_group_cb -- begin\n");
  2037. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2038. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2039. "Result of modifying AD entry [%s] was [%d:%s]\n",
  2040. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  2041. #endif
  2042. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2043. "<-- test_winsync_post_ad_mod_group_cb -- end\n");
  2044. return;
  2045. }
  2046. static void
  2047. 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)
  2048. {
  2049. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2050. "--> test_winsync_post_ds_mod_user_cb -- begin\n");
  2051. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2052. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2053. "Result of modifying DS entry [%s] was [%d:%s]\n",
  2054. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  2055. #endif
  2056. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2057. "<-- test_winsync_post_ds_mod_user_cb -- end\n");
  2058. return;
  2059. }
  2060. static void
  2061. 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)
  2062. {
  2063. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2064. "--> test_winsync_post_ds_mod_group_cb -- begin\n");
  2065. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2066. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2067. "Result of modifying DS entry [%s] was [%d:%s]\n",
  2068. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  2069. #endif
  2070. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2071. "<-- test_winsync_post_ds_mod_group_cb -- end\n");
  2072. return;
  2073. }
  2074. static void
  2075. test_winsync_post_ds_add_user_cb(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  2076. {
  2077. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2078. "--> test_winsync_post_ds_add_user_cb -- begin\n");
  2079. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2080. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2081. "Result of adding DS entry [%s] was [%d:%s]\n",
  2082. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  2083. #endif
  2084. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2085. "<-- test_winsync_post_ds_add_user_cb -- end\n");
  2086. return;
  2087. }
  2088. static void
  2089. test_winsync_post_ds_add_group_cb(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  2090. {
  2091. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2092. "--> test_winsync_post_ds_add_group_cb -- begin\n");
  2093. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2094. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2095. "Result of adding DS entry [%s] was [%d:%s]\n",
  2096. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  2097. #endif
  2098. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2099. "<-- test_winsync_post_ds_add_group_cb -- end\n");
  2100. return;
  2101. }
  2102. static void
  2103. test_winsync_pre_ad_add_user_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry)
  2104. {
  2105. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2106. "--> test_winsync_pre_ad_add_user_cb -- begin\n");
  2107. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2108. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2109. "Adding AD entry [%s] from add of DS entry [%s]\n",
  2110. slapi_entry_get_dn(ad_entry), slapi_entry_get_dn(ds_entry));
  2111. /* make modifications to ad_entry here */
  2112. #endif
  2113. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2114. "<-- test_winsync_pre_ad_add_user_cb -- end\n");
  2115. return;
  2116. }
  2117. static void
  2118. test_winsync_pre_ad_add_group_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry)
  2119. {
  2120. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2121. "--> test_winsync_pre_ad_add_group_cb -- begin\n");
  2122. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2123. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2124. "Adding AD entry [%s] from add of DS entry [%s]\n",
  2125. slapi_entry_get_dn(ad_entry), slapi_entry_get_dn(ds_entry));
  2126. /* make modifications to ad_entry here */
  2127. #endif
  2128. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2129. "<-- test_winsync_pre_ad_add_group_cb -- end\n");
  2130. return;
  2131. }
  2132. static void
  2133. test_winsync_post_ad_add_user_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry, int *result)
  2134. {
  2135. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2136. "--> test_winsync_post_ad_add_user_cb -- begin\n");
  2137. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2138. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2139. "Result of adding AD entry [%s] was [%d:%s]\n",
  2140. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  2141. #endif
  2142. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2143. "<-- test_winsync_post_ad_add_user_cb -- end\n");
  2144. return;
  2145. }
  2146. static void
  2147. test_winsync_post_ad_add_group_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry, int *result)
  2148. {
  2149. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2150. "--> test_winsync_post_ad_add_group_cb -- begin\n");
  2151. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2152. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2153. "Result of adding AD entry [%s] was [%d:%s]\n",
  2154. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  2155. #endif
  2156. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2157. "<-- test_winsync_post_ad_add_group_cb -- end\n");
  2158. return;
  2159. }
  2160. static void
  2161. 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)
  2162. {
  2163. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2164. "--> test_winsync_post_ad_mod_user_mods_cb -- begin\n");
  2165. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2166. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2167. "Result of modifying AD entry [%s] was [%d:%s]\n",
  2168. slapi_sdn_get_dn(remote_dn), *result, ldap_err2string(*result));
  2169. #endif
  2170. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2171. "<-- test_winsync_post_ad_mod_user_mods_cb -- end\n");
  2172. return;
  2173. }
  2174. static void
  2175. 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)
  2176. {
  2177. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2178. "--> test_winsync_post_ad_mod_group_mods_cb -- begin\n");
  2179. #ifdef THIS_IS_JUST_AN_EXAMPLE
  2180. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2181. "Result of modifying AD entry [%s] was [%d:%s]\n",
  2182. slapi_sdn_get_dn(remote_dn), *result, ldap_err2string(*result));
  2183. #endif
  2184. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2185. "<-- test_winsync_post_ad_mod_group_mods_cb -- end\n");
  2186. return;
  2187. }
  2188. static int
  2189. test_winsync_precedence(void)
  2190. {
  2191. return 99;
  2192. }
  2193. /**
  2194. * Plugin identifiers
  2195. */
  2196. static Slapi_PluginDesc test_winsync_pdesc = {
  2197. "test-winsync-plugin",
  2198. VENDOR,
  2199. DS_PACKAGE_VERSION,
  2200. "test winsync plugin"
  2201. };
  2202. static Slapi_ComponentId *test_winsync_plugin_id = NULL;
  2203. #ifdef TEST_V1_WINSYNC_API
  2204. static void *test_winsync_api_v1[] = {
  2205. NULL, /* reserved for api broker use, must be zero */
  2206. test_winsync_api_init,
  2207. test_winsync_dirsync_search_params_cb,
  2208. test_winsync_pre_ad_search_cb,
  2209. test_winsync_pre_ds_search_entry_cb,
  2210. test_winsync_pre_ds_search_all_cb,
  2211. test_winsync_pre_ad_mod_user_cb,
  2212. test_winsync_pre_ad_mod_group_cb,
  2213. test_winsync_pre_ds_mod_user_cb,
  2214. test_winsync_pre_ds_mod_group_cb,
  2215. test_winsync_pre_ds_add_user_cb,
  2216. test_winsync_pre_ds_add_group_cb,
  2217. test_winsync_get_new_ds_user_dn_cb,
  2218. test_winsync_get_new_ds_group_dn_cb,
  2219. test_winsync_pre_ad_mod_user_mods_cb,
  2220. test_winsync_pre_ad_mod_group_mods_cb,
  2221. test_winsync_can_add_entry_to_ad_cb,
  2222. test_winsync_begin_update_cb,
  2223. test_winsync_end_update_cb,
  2224. test_winsync_destroy_agmt_cb
  2225. };
  2226. #endif /* TEST_V1_WINSYNC_API */
  2227. #ifdef TEST_V2_WINSYNC_API
  2228. static void *test_winsync_api_v2[] = {
  2229. NULL, /* reserved for api broker use, must be zero */
  2230. test_winsync_api_init,
  2231. test_winsync_dirsync_search_params_cb,
  2232. test_winsync_pre_ad_search_cb,
  2233. test_winsync_pre_ds_search_entry_cb,
  2234. test_winsync_pre_ds_search_all_cb,
  2235. test_winsync_pre_ad_mod_user_cb,
  2236. test_winsync_pre_ad_mod_group_cb,
  2237. test_winsync_pre_ds_mod_user_cb,
  2238. test_winsync_pre_ds_mod_group_cb,
  2239. test_winsync_pre_ds_add_user_cb,
  2240. test_winsync_pre_ds_add_group_cb,
  2241. test_winsync_get_new_ds_user_dn_cb,
  2242. test_winsync_get_new_ds_group_dn_cb,
  2243. test_winsync_pre_ad_mod_user_mods_cb,
  2244. test_winsync_pre_ad_mod_group_mods_cb,
  2245. test_winsync_can_add_entry_to_ad_cb,
  2246. test_winsync_begin_update_cb,
  2247. test_winsync_end_update_cb,
  2248. test_winsync_destroy_agmt_cb,
  2249. test_winsync_post_ad_mod_user_cb,
  2250. test_winsync_post_ad_mod_group_cb,
  2251. test_winsync_post_ds_mod_user_cb,
  2252. test_winsync_post_ds_mod_group_cb,
  2253. test_winsync_post_ds_add_user_cb,
  2254. test_winsync_post_ds_add_group_cb,
  2255. test_winsync_pre_ad_add_user_cb,
  2256. test_winsync_pre_ad_add_group_cb,
  2257. test_winsync_post_ad_add_user_cb,
  2258. test_winsync_post_ad_add_group_cb,
  2259. test_winsync_post_ad_mod_user_mods_cb,
  2260. test_winsync_post_ad_mod_group_mods_cb
  2261. };
  2262. #endif /* TEST_V2_WINSYNC_API */
  2263. static void *test_winsync_api_v3[] = {
  2264. NULL, /* reserved for api broker use, must be zero */
  2265. test_winsync_api_init,
  2266. test_winsync_dirsync_search_params_cb,
  2267. test_winsync_pre_ad_search_cb,
  2268. test_winsync_pre_ds_search_entry_cb,
  2269. test_winsync_pre_ds_search_all_cb,
  2270. test_winsync_pre_ad_mod_user_cb,
  2271. test_winsync_pre_ad_mod_group_cb,
  2272. test_winsync_pre_ds_mod_user_cb,
  2273. test_winsync_pre_ds_mod_group_cb,
  2274. test_winsync_pre_ds_add_user_cb,
  2275. test_winsync_pre_ds_add_group_cb,
  2276. test_winsync_get_new_ds_user_dn_cb,
  2277. test_winsync_get_new_ds_group_dn_cb,
  2278. test_winsync_pre_ad_mod_user_mods_cb,
  2279. test_winsync_pre_ad_mod_group_mods_cb,
  2280. test_winsync_can_add_entry_to_ad_cb,
  2281. test_winsync_begin_update_cb,
  2282. test_winsync_end_update_cb,
  2283. test_winsync_destroy_agmt_cb,
  2284. test_winsync_post_ad_mod_user_cb,
  2285. test_winsync_post_ad_mod_group_cb,
  2286. test_winsync_post_ds_mod_user_cb,
  2287. test_winsync_post_ds_mod_group_cb,
  2288. test_winsync_post_ds_add_user_cb,
  2289. test_winsync_post_ds_add_group_cb,
  2290. test_winsync_pre_ad_add_user_cb,
  2291. test_winsync_pre_ad_add_group_cb,
  2292. test_winsync_post_ad_add_user_cb,
  2293. test_winsync_post_ad_add_group_cb,
  2294. test_winsync_post_ad_mod_user_mods_cb,
  2295. test_winsync_post_ad_mod_group_mods_cb,
  2296. test_winsync_precedence
  2297. };
  2298. static int
  2299. test_winsync_plugin_start(Slapi_PBlock *pb)
  2300. {
  2301. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2302. "--> test_winsync_plugin_start -- begin\n");
  2303. if( slapi_apib_register(WINSYNC_v3_0_GUID, test_winsync_api_v3) ) {
  2304. slapi_log_error( SLAPI_LOG_FATAL, test_winsync_plugin_name,
  2305. "<-- test_winsync_plugin_start -- failed to register winsync api -- end\n");
  2306. return -1;
  2307. }
  2308. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2309. "<-- test_winsync_plugin_start -- end\n");
  2310. return 0;
  2311. }
  2312. static int
  2313. test_winsync_plugin_close(Slapi_PBlock *pb)
  2314. {
  2315. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2316. "--> test_winsync_plugin_close -- begin\n");
  2317. slapi_apib_unregister(WINSYNC_v3_0_GUID);
  2318. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2319. "<-- test_winsync_plugin_close -- end\n");
  2320. return 0;
  2321. }
  2322. /* this is the slapi plugin init function,
  2323. not the one used by the winsync api
  2324. */
  2325. int test_winsync_plugin_init(Slapi_PBlock *pb)
  2326. {
  2327. slapi_log_error(SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2328. "--> test_winsync_plugin_init -- begin\n");
  2329. if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  2330. SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  2331. slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN,
  2332. (void *) test_winsync_plugin_start ) != 0 ||
  2333. slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN,
  2334. (void *) test_winsync_plugin_close ) != 0 ||
  2335. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  2336. (void *)&test_winsync_pdesc ) != 0 )
  2337. {
  2338. slapi_log_error( SLAPI_LOG_FATAL, test_winsync_plugin_name,
  2339. "<-- test_winsync_plugin_init -- failed to register plugin -- end\n");
  2340. return -1;
  2341. }
  2342. /* Retrieve and save the plugin identity to later pass to
  2343. internal operations */
  2344. if (slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &test_winsync_plugin_id) != 0) {
  2345. slapi_log_error(SLAPI_LOG_FATAL, test_winsync_plugin_name,
  2346. "<-- test_winsync_plugin_init -- failed to retrieve plugin identity -- end\n");
  2347. return -1;
  2348. }
  2349. slapi_log_error( SLAPI_LOG_PLUGIN, test_winsync_plugin_name,
  2350. "<-- test_winsync_plugin_init -- end\n");
  2351. return 0;
  2352. }
  2353. /*
  2354. dn: cn=Test Winsync API,cn=plugins,cn=config
  2355. objectclass: top
  2356. objectclass: nsSlapdPlugin
  2357. objectclass: extensibleObject
  2358. cn: Test Winsync API
  2359. nsslapd-pluginpath: libtestwinsync-plugin
  2360. nsslapd-plugininitfunc: test_winsync_plugin_init
  2361. nsslapd-plugintype: preoperation
  2362. nsslapd-pluginenabled: on
  2363. nsslapd-plugin-depends-on-type: database
  2364. nsslapd-pluginDescription: Test Winsync
  2365. nsslapd-pluginVendor: 389 project
  2366. nsslapd-pluginId: test-winsync
  2367. nsslapd-pluginVersion: 0.9
  2368. */
  2369. #endif /* WINSYNC_SAMPLE_CODE */
  2370. /* #define WINSYNC_TEST_IPA */
  2371. #ifdef WINSYNC_TEST_IPA
  2372. #include "ipa-winsync.c"
  2373. #include "ipa-winsync-config.c"
  2374. #endif