windows_private.c 79 KB

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