windows_private.c 80 KB

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