windows_private.c 74 KB

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