1
0

windows_private.c 94 KB

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