windows_private.c 79 KB

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