windows_private.c 79 KB

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