windows_private.c 79 KB

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