windows_private.c 80 KB

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