windows_private.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /* windows_private.c */
  42. #include "repl.h"
  43. #include "repl5.h"
  44. #include "slap.h"
  45. #include "slapi-plugin.h"
  46. #include "winsync-plugin.h"
  47. #include "windowsrepl.h"
  48. struct windowsprivate {
  49. Slapi_DN *windows_subtree; /* DN of synchronized subtree (on the windows side) */
  50. Slapi_DN *directory_subtree; /* DN of synchronized subtree on directory side */
  51. /* this simplifies the mapping as it's simply
  52. from the former to the latter container, or
  53. vice versa */
  54. ber_int_t dirsync_flags;
  55. ber_int_t dirsync_maxattributecount;
  56. char *dirsync_cookie;
  57. int dirsync_cookie_len;
  58. PRBool dirsync_cookie_has_more;
  59. PRBool create_users_from_dirsync;
  60. PRBool create_groups_from_dirsync;
  61. char *windows_domain;
  62. int isnt4;
  63. int iswin2k3;
  64. /* This filter is used to determine if an entry belongs to this agreement. We put it here
  65. * so we only have to allocate each filter once instead of doing it every time we receive a change. */
  66. Slapi_Filter *directory_filter; /* Used for checking if local entries need to be sync'd to AD */
  67. Slapi_Filter *deleted_filter; /* Used for checking if an entry is an AD tombstone */
  68. Slapi_Entry *raw_entry; /* "raw" un-schema processed last entry read from AD */
  69. int keep_raw_entry; /* flag to control when the raw entry is set */
  70. void *api_cookie; /* private data used by api callbacks */
  71. time_t sync_interval; /* how often to run the dirsync search, in seconds */
  72. int one_way; /* Indicates if this is a one-way agreement and which direction it is */
  73. };
  74. static void windows_private_set_windows_domain(const Repl_Agmt *ra, char *domain);
  75. static int
  76. true_value_from_string(char *val)
  77. {
  78. if (strcasecmp (val, "on") == 0 || strcasecmp (val, "yes") == 0 ||
  79. strcasecmp (val, "true") == 0 || strcasecmp (val, "1") == 0)
  80. {
  81. return 1;
  82. } else
  83. {
  84. return 0;
  85. }
  86. }
  87. static int
  88. windows_parse_config_entry(Repl_Agmt *ra, const char *type, Slapi_Entry *e)
  89. {
  90. char *tmpstr = NULL;
  91. int retval = 0;
  92. if (type == NULL || slapi_attr_types_equivalent(type,type_nsds7WindowsReplicaArea))
  93. {
  94. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7WindowsReplicaArea);
  95. if (NULL != tmpstr)
  96. {
  97. windows_private_set_windows_subtree(ra, slapi_sdn_new_dn_passin(tmpstr) );
  98. }
  99. retval = 1;
  100. }
  101. if (type == NULL || slapi_attr_types_equivalent(type,type_nsds7DirectoryReplicaArea))
  102. {
  103. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7DirectoryReplicaArea);
  104. if (NULL != tmpstr)
  105. {
  106. windows_private_set_directory_subtree(ra, slapi_sdn_new_dn_passin(tmpstr) );
  107. }
  108. retval = 1;
  109. }
  110. if (type == NULL || slapi_attr_types_equivalent(type,type_nsds7CreateNewUsers))
  111. {
  112. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7CreateNewUsers);
  113. if (NULL != tmpstr && true_value_from_string(tmpstr))
  114. {
  115. windows_private_set_create_users(ra, PR_TRUE);
  116. }
  117. else
  118. {
  119. windows_private_set_create_users(ra, PR_FALSE);
  120. }
  121. retval = 1;
  122. slapi_ch_free((void**)&tmpstr);
  123. }
  124. if (type == NULL || slapi_attr_types_equivalent(type,type_nsds7CreateNewGroups))
  125. {
  126. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7CreateNewGroups);
  127. if (NULL != tmpstr && true_value_from_string(tmpstr))
  128. {
  129. windows_private_set_create_groups(ra, PR_TRUE);
  130. }
  131. else
  132. {
  133. windows_private_set_create_groups(ra, PR_FALSE);
  134. }
  135. retval = 1;
  136. slapi_ch_free((void**)&tmpstr);
  137. }
  138. if (type == NULL || slapi_attr_types_equivalent(type,type_nsds7WindowsDomain))
  139. {
  140. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7WindowsDomain);
  141. if (NULL != tmpstr)
  142. {
  143. windows_private_set_windows_domain(ra,tmpstr);
  144. }
  145. /* No need to free tmpstr because it was aliased by the call above */
  146. tmpstr = NULL;
  147. retval = 1;
  148. }
  149. if (type == NULL || slapi_attr_types_equivalent(type,type_winSyncInterval))
  150. {
  151. tmpstr = slapi_entry_attr_get_charptr(e, type_winSyncInterval);
  152. if (NULL != tmpstr)
  153. {
  154. windows_private_set_sync_interval(ra,tmpstr);
  155. }
  156. slapi_ch_free_string(&tmpstr);
  157. retval = 1;
  158. }
  159. if (type == NULL || slapi_attr_types_equivalent(type,type_oneWaySync))
  160. {
  161. tmpstr = slapi_entry_attr_get_charptr(e, type_oneWaySync);
  162. if (NULL != tmpstr)
  163. {
  164. if (strcasecmp(tmpstr, "fromWindows") == 0) {
  165. windows_private_set_one_way(ra, ONE_WAY_SYNC_FROM_AD);
  166. } else if (strcasecmp(tmpstr, "toWindows") == 0) {
  167. windows_private_set_one_way(ra, ONE_WAY_SYNC_TO_AD);
  168. } else {
  169. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  170. "Ignoring illegal setting for %s attribute in replication "
  171. "agreement \"%s\". Valid values are \"toWindows\" or "
  172. "\"fromWindows\".\n", type_oneWaySync, slapi_entry_get_dn(e));
  173. windows_private_set_one_way(ra, ONE_WAY_SYNC_DISABLED);
  174. }
  175. }
  176. else
  177. {
  178. windows_private_set_one_way(ra, ONE_WAY_SYNC_DISABLED);
  179. }
  180. slapi_ch_free((void**)&tmpstr);
  181. retval = 1;
  182. }
  183. return retval;
  184. }
  185. /* Returns non-zero if the modify was ok, zero if not */
  186. int
  187. windows_handle_modify_agreement(Repl_Agmt *ra, const char *type, Slapi_Entry *e)
  188. {
  189. /* Is this a Windows agreement ? */
  190. if (get_agmt_agreement_type(ra) == REPLICA_TYPE_WINDOWS)
  191. {
  192. return windows_parse_config_entry(ra,type,e);
  193. } else
  194. {
  195. return 0;
  196. }
  197. }
  198. void
  199. windows_init_agreement_from_entry(Repl_Agmt *ra, Slapi_Entry *e)
  200. {
  201. agmt_set_priv(ra,windows_private_new());
  202. windows_parse_config_entry(ra,NULL,e);
  203. windows_plugin_init(ra);
  204. }
  205. const char* windows_private_get_purl(const Repl_Agmt *ra)
  206. {
  207. const char* windows_purl;
  208. char *hostname;
  209. hostname = agmt_get_hostname(ra);
  210. if(slapi_is_ipv6_addr(hostname)){
  211. /* need to put brackets around the ipv6 address */
  212. windows_purl = slapi_ch_smprintf("ldap://[%s]:%d", hostname, agmt_get_port(ra));
  213. } else {
  214. windows_purl = slapi_ch_smprintf("ldap://%s:%d", hostname, agmt_get_port(ra));
  215. }
  216. slapi_ch_free_string(&hostname);
  217. return windows_purl;
  218. }
  219. Dirsync_Private* windows_private_new()
  220. {
  221. Dirsync_Private *dp;
  222. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_new\n" );
  223. dp = (Dirsync_Private *)slapi_ch_calloc(sizeof(Dirsync_Private),1);
  224. dp->dirsync_maxattributecount = -1;
  225. dp->directory_filter = NULL;
  226. dp->deleted_filter = NULL;
  227. dp->sync_interval = PERIODIC_DIRSYNC_INTERVAL;
  228. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_new\n" );
  229. return dp;
  230. }
  231. void windows_agreement_delete(Repl_Agmt *ra)
  232. {
  233. Dirsync_Private *dp = (Dirsync_Private *) agmt_get_priv(ra);
  234. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_delete\n" );
  235. PR_ASSERT(dp != NULL);
  236. winsync_plugin_call_destroy_agmt_cb(ra, dp->directory_subtree,
  237. dp->windows_subtree);
  238. slapi_sdn_free(&dp->directory_subtree);
  239. slapi_sdn_free(&dp->windows_subtree);
  240. slapi_filter_free(dp->directory_filter, 1);
  241. slapi_filter_free(dp->deleted_filter, 1);
  242. slapi_entry_free(dp->raw_entry);
  243. dp->raw_entry = NULL;
  244. dp->api_cookie = NULL;
  245. slapi_ch_free((void **)dp);
  246. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_delete\n" );
  247. }
  248. int windows_private_get_isnt4(const Repl_Agmt *ra)
  249. {
  250. Dirsync_Private *dp;
  251. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_isnt4\n" );
  252. PR_ASSERT(ra);
  253. dp = (Dirsync_Private *) agmt_get_priv(ra);
  254. PR_ASSERT (dp);
  255. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_isnt4\n" );
  256. return dp->isnt4;
  257. }
  258. void windows_private_set_isnt4(const Repl_Agmt *ra, int isit)
  259. {
  260. Dirsync_Private *dp;
  261. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_isnt4\n" );
  262. PR_ASSERT(ra);
  263. dp = (Dirsync_Private *) agmt_get_priv(ra);
  264. PR_ASSERT (dp);
  265. dp->isnt4 = isit;
  266. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_isnt4\n" );
  267. }
  268. int windows_private_get_iswin2k3(const Repl_Agmt *ra)
  269. {
  270. Dirsync_Private *dp;
  271. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_iswin2k3\n" );
  272. PR_ASSERT(ra);
  273. dp = (Dirsync_Private *) agmt_get_priv(ra);
  274. PR_ASSERT (dp);
  275. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_iswin2k3\n" );
  276. return dp->iswin2k3;
  277. }
  278. void windows_private_set_iswin2k3(const Repl_Agmt *ra, int isit)
  279. {
  280. Dirsync_Private *dp;
  281. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_iswin2k3\n" );
  282. PR_ASSERT(ra);
  283. dp = (Dirsync_Private *) agmt_get_priv(ra);
  284. PR_ASSERT (dp);
  285. dp->iswin2k3 = isit;
  286. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_iswin2k3\n" );
  287. }
  288. /* Returns a copy of the Slapi_Filter pointer. The caller should not free it */
  289. Slapi_Filter* windows_private_get_directory_filter(const Repl_Agmt *ra)
  290. {
  291. Dirsync_Private *dp;
  292. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_directory_filter\n" );
  293. PR_ASSERT(ra);
  294. dp = (Dirsync_Private *) agmt_get_priv(ra);
  295. PR_ASSERT (dp);
  296. if (dp->directory_filter == NULL) {
  297. char *string_filter = slapi_ch_strdup("(&(|(objectclass=ntuser)(objectclass=ntgroup))(ntUserDomainId=*))");
  298. /* The filter gets freed in windows_agreement_delete() */
  299. dp->directory_filter = slapi_str2filter( string_filter );
  300. slapi_ch_free_string(&string_filter);
  301. }
  302. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_directory_filter\n" );
  303. return dp->directory_filter;
  304. }
  305. /* Returns a copy of the Slapi_Filter pointer. The caller should not free it */
  306. Slapi_Filter* windows_private_get_deleted_filter(const Repl_Agmt *ra)
  307. {
  308. Dirsync_Private *dp;
  309. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_deleted_filter\n" );
  310. PR_ASSERT(ra);
  311. dp = (Dirsync_Private *) agmt_get_priv(ra);
  312. PR_ASSERT (dp);
  313. if (dp->deleted_filter == NULL) {
  314. char *string_filter = slapi_ch_strdup("(isdeleted=*)");
  315. /* The filter gets freed in windows_agreement_delete() */
  316. dp->deleted_filter = slapi_str2filter( string_filter );
  317. slapi_ch_free_string(&string_filter);
  318. }
  319. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_deleted_filter\n" );
  320. return dp->deleted_filter;
  321. }
  322. /* Returns a copy of the Slapi_DN pointer, no need to free it */
  323. const Slapi_DN* windows_private_get_windows_subtree (const Repl_Agmt *ra)
  324. {
  325. Dirsync_Private *dp;
  326. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_windows_subtree\n" );
  327. PR_ASSERT(ra);
  328. dp = (Dirsync_Private *) agmt_get_priv(ra);
  329. PR_ASSERT (dp);
  330. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_windows_subtree\n" );
  331. return dp->windows_subtree;
  332. }
  333. const char *
  334. windows_private_get_windows_domain(const Repl_Agmt *ra)
  335. {
  336. Dirsync_Private *dp;
  337. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_windows_domain\n" );
  338. PR_ASSERT(ra);
  339. dp = (Dirsync_Private *) agmt_get_priv(ra);
  340. PR_ASSERT (dp);
  341. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_windows_domain\n" );
  342. return dp->windows_domain;
  343. }
  344. static void
  345. windows_private_set_windows_domain(const Repl_Agmt *ra, char *domain)
  346. {
  347. Dirsync_Private *dp;
  348. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_windows_domain\n" );
  349. PR_ASSERT(ra);
  350. dp = (Dirsync_Private *) agmt_get_priv(ra);
  351. PR_ASSERT (dp);
  352. dp->windows_domain = domain;
  353. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_windows_domain\n" );
  354. }
  355. /* Returns a copy of the Slapi_DN pointer, no need to free it */
  356. const Slapi_DN* windows_private_get_directory_subtree (const Repl_Agmt *ra)
  357. {
  358. Dirsync_Private *dp;
  359. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_directory_replarea\n" );
  360. PR_ASSERT(ra);
  361. dp = (Dirsync_Private *) agmt_get_priv(ra);
  362. PR_ASSERT (dp);
  363. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_directory_replarea\n" );
  364. return dp->directory_subtree;
  365. }
  366. /* Takes a copy of the sdn passed in */
  367. void windows_private_set_windows_subtree (const Repl_Agmt *ra,Slapi_DN* sdn )
  368. {
  369. Dirsync_Private *dp;
  370. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_windows_replarea\n" );
  371. PR_ASSERT(ra);
  372. PR_ASSERT(sdn);
  373. dp = (Dirsync_Private *) agmt_get_priv(ra);
  374. PR_ASSERT (dp);
  375. slapi_sdn_free(&dp->windows_subtree);
  376. dp->windows_subtree = sdn;
  377. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_windows_replarea\n" );
  378. }
  379. /* Takes a copy of the sdn passed in */
  380. void windows_private_set_directory_subtree (const Repl_Agmt *ra,Slapi_DN* sdn )
  381. {
  382. Dirsync_Private *dp;
  383. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_directory_replarea\n" );
  384. PR_ASSERT(ra);
  385. PR_ASSERT(sdn);
  386. dp = (Dirsync_Private *) agmt_get_priv(ra);
  387. PR_ASSERT (dp);
  388. slapi_sdn_free(&dp->directory_subtree);
  389. dp->directory_subtree = sdn;
  390. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_directory_replarea\n" );
  391. }
  392. PRBool windows_private_create_users(const Repl_Agmt *ra)
  393. {
  394. Dirsync_Private *dp;
  395. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_create_users\n" );
  396. PR_ASSERT(ra);
  397. dp = (Dirsync_Private *) agmt_get_priv(ra);
  398. PR_ASSERT (dp);
  399. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_create_users\n" );
  400. return dp->create_users_from_dirsync;
  401. }
  402. void windows_private_set_create_users(const Repl_Agmt *ra, PRBool value)
  403. {
  404. Dirsync_Private *dp;
  405. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_create_users\n" );
  406. PR_ASSERT(ra);
  407. dp = (Dirsync_Private *) agmt_get_priv(ra);
  408. PR_ASSERT (dp);
  409. dp->create_users_from_dirsync = value;
  410. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_create_users\n" );
  411. }
  412. PRBool windows_private_create_groups(const Repl_Agmt *ra)
  413. {
  414. Dirsync_Private *dp;
  415. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_create_groups\n" );
  416. PR_ASSERT(ra);
  417. dp = (Dirsync_Private *) agmt_get_priv(ra);
  418. PR_ASSERT (dp);
  419. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_create_groups\n" );
  420. return dp->create_groups_from_dirsync;
  421. }
  422. void windows_private_set_create_groups(const Repl_Agmt *ra, PRBool value)
  423. {
  424. Dirsync_Private *dp;
  425. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_create_groups\n" );
  426. PR_ASSERT(ra);
  427. dp = (Dirsync_Private *) agmt_get_priv(ra);
  428. PR_ASSERT (dp);
  429. dp->create_groups_from_dirsync = value;
  430. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_create_groups\n" );
  431. }
  432. int windows_private_get_one_way(const Repl_Agmt *ra)
  433. {
  434. Dirsync_Private *dp;
  435. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_one_way\n" );
  436. PR_ASSERT(ra);
  437. dp = (Dirsync_Private *) agmt_get_priv(ra);
  438. PR_ASSERT (dp);
  439. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_one_way\n" );
  440. return dp->one_way;
  441. }
  442. void windows_private_set_one_way(const Repl_Agmt *ra, int value)
  443. {
  444. Dirsync_Private *dp;
  445. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_one_way\n" );
  446. PR_ASSERT(ra);
  447. dp = (Dirsync_Private *) agmt_get_priv(ra);
  448. PR_ASSERT (dp);
  449. dp->one_way = value;
  450. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_one_way\n" );
  451. }
  452. /*
  453. This function returns the current Dirsync_Private that's inside
  454. Repl_Agmt ra as a ldap control.
  455. */
  456. LDAPControl* windows_private_dirsync_control(const Repl_Agmt *ra)
  457. {
  458. LDAPControl *control = NULL;
  459. BerElement *ber;
  460. Dirsync_Private *dp;
  461. char iscritical = PR_TRUE;
  462. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_dirsync_control\n" );
  463. PR_ASSERT(ra);
  464. dp = (Dirsync_Private *) agmt_get_priv(ra);
  465. PR_ASSERT (dp);
  466. ber = ber_alloc();
  467. ber_printf( ber, "{iio}", dp->dirsync_flags, dp->dirsync_maxattributecount, dp->dirsync_cookie ? dp->dirsync_cookie : "", dp->dirsync_cookie_len );
  468. /* Use a regular directory server instead of a real AD - for testing */
  469. if (getenv("WINSYNC_USE_DS")) {
  470. iscritical = PR_FALSE;
  471. }
  472. slapi_build_control( REPL_DIRSYNC_CONTROL_OID, ber, iscritical, &control);
  473. ber_free(ber,1);
  474. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_dirsync_control\n" );
  475. return control;
  476. }
  477. /*
  478. This function scans the array of controls and updates the Repl_Agmt's
  479. Dirsync_Private if the dirsync control is found.
  480. */
  481. void windows_private_update_dirsync_control(const Repl_Agmt *ra,LDAPControl **controls )
  482. {
  483. Dirsync_Private *dp;
  484. int foundDirsyncControl;
  485. int i;
  486. LDAPControl *dirsync = NULL;
  487. BerElement *ber = NULL;
  488. ber_int_t hasMoreData;
  489. ber_int_t maxAttributeCount;
  490. BerValue *serverCookie = NULL;
  491. #ifdef FOR_DEBUGGING
  492. int return_value = LDAP_SUCCESS;
  493. #endif
  494. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_update_dirsync_control\n" );
  495. PR_ASSERT(ra);
  496. dp = (Dirsync_Private *) agmt_get_priv(ra);
  497. PR_ASSERT (dp);
  498. if (NULL != controls )
  499. {
  500. foundDirsyncControl = 0;
  501. for ( i = 0; (( controls[i] != NULL ) && ( !foundDirsyncControl )); i++ ) {
  502. foundDirsyncControl = !strcmp( controls[i]->ldctl_oid, REPL_DIRSYNC_CONTROL_OID );
  503. }
  504. if ( !foundDirsyncControl )
  505. {
  506. #ifdef FOR_DEBUGGING
  507. return_value = LDAP_CONTROL_NOT_FOUND;
  508. #endif
  509. goto choke;
  510. }
  511. else if (!controls[i-1]->ldctl_value.bv_val) {
  512. #ifdef FOR_DEBUGGING
  513. return_value = LDAP_CONTROL_NOT_FOUND;
  514. #endif
  515. goto choke;
  516. }
  517. else
  518. {
  519. dirsync = slapi_dup_control( controls[i-1]);
  520. }
  521. ber = ber_init( &dirsync->ldctl_value ) ;
  522. if (ber_scanf( ber, "{iiO}", &hasMoreData, &maxAttributeCount, &serverCookie) == LBER_ERROR)
  523. {
  524. #ifdef FOR_DEBUGGING
  525. return_value = LDAP_CONTROL_NOT_FOUND;
  526. #endif
  527. goto choke;
  528. }
  529. slapi_ch_free_string(&dp->dirsync_cookie);
  530. dp->dirsync_cookie = ( char* ) slapi_ch_malloc(serverCookie->bv_len + 1);
  531. memcpy(dp->dirsync_cookie, serverCookie->bv_val, serverCookie->bv_len);
  532. dp->dirsync_cookie_len = (int) serverCookie->bv_len; /* XXX shouldn't cast? */
  533. /* dp->dirsync_maxattributecount = maxAttributeCount; We don't need to keep this */
  534. dp->dirsync_cookie_has_more = hasMoreData;
  535. choke:
  536. ber_bvfree(serverCookie);
  537. ber_free(ber,1);
  538. ldap_control_free(dirsync);
  539. }
  540. else
  541. {
  542. #ifdef FOR_DEBUGGING
  543. return_value = LDAP_CONTROL_NOT_FOUND;
  544. #endif
  545. }
  546. #ifdef FOR_DEBUGGING
  547. LDAPDebug1Arg( LDAP_DEBUG_TRACE, "<= windows_private_update_dirsync_control: rc=%d\n", return_value);
  548. #else
  549. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_update_dirsync_control\n" );
  550. #endif
  551. }
  552. PRBool windows_private_dirsync_has_more(const Repl_Agmt *ra)
  553. {
  554. Dirsync_Private *dp;
  555. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_dirsync_has_more\n" );
  556. PR_ASSERT(ra);
  557. dp = (Dirsync_Private *) agmt_get_priv(ra);
  558. PR_ASSERT (dp);
  559. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_dirsync_has_more\n" );
  560. return dp->dirsync_cookie_has_more;
  561. }
  562. void windows_private_null_dirsync_cookie(const Repl_Agmt *ra)
  563. {
  564. Dirsync_Private *dp;
  565. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_null_dirsync_control\n" );
  566. dp = (Dirsync_Private *) agmt_get_priv(ra);
  567. PR_ASSERT (dp);
  568. dp->dirsync_cookie_len = 0;
  569. slapi_ch_free_string(&dp->dirsync_cookie);
  570. dp->dirsync_cookie = NULL;
  571. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_null_dirsync_control\n" );
  572. }
  573. static
  574. Slapi_Mods *windows_private_get_cookie_mod(Dirsync_Private *dp, int modtype)
  575. {
  576. Slapi_Mods *smods = NULL;
  577. smods = slapi_mods_new();
  578. slapi_mods_add( smods, modtype,
  579. "nsds7DirsyncCookie", dp->dirsync_cookie_len , dp->dirsync_cookie);
  580. return smods;
  581. }
  582. /* writes the current cookie into dse.ldif under the replication agreement entry
  583. returns: ldap result code of the operation. */
  584. int
  585. windows_private_save_dirsync_cookie(const Repl_Agmt *ra)
  586. {
  587. Dirsync_Private *dp = NULL;
  588. Slapi_PBlock *pb = NULL;
  589. Slapi_DN* sdn = NULL;
  590. int rc = 0;
  591. Slapi_Mods *mods = NULL;
  592. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_save_dirsync_cookie\n" );
  593. PR_ASSERT(ra);
  594. dp = (Dirsync_Private *) agmt_get_priv(ra);
  595. PR_ASSERT (dp);
  596. pb = slapi_pblock_new ();
  597. mods = windows_private_get_cookie_mod(dp, LDAP_MOD_REPLACE);
  598. sdn = slapi_sdn_dup( agmt_get_dn_byref(ra) );
  599. slapi_modify_internal_set_pb_ext (pb, sdn,
  600. slapi_mods_get_ldapmods_byref(mods), NULL, NULL,
  601. repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION), 0);
  602. slapi_modify_internal_pb (pb);
  603. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  604. if (rc == LDAP_NO_SUCH_ATTRIBUTE)
  605. { /* try again, but as an add instead */
  606. slapi_mods_free(&mods);
  607. mods = windows_private_get_cookie_mod(dp, LDAP_MOD_ADD);
  608. slapi_modify_internal_set_pb_ext (pb, sdn,
  609. slapi_mods_get_ldapmods_byref(mods), NULL, NULL,
  610. repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION), 0);
  611. slapi_modify_internal_pb (pb);
  612. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  613. }
  614. slapi_pblock_destroy (pb);
  615. slapi_mods_free(&mods);
  616. slapi_sdn_free(&sdn);
  617. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_save_dirsync_cookie\n" );
  618. return rc;
  619. }
  620. /* reads the cookie in dse.ldif to the replication agreement entry
  621. returns: ldap result code of ldap operation, or
  622. LDAP_NO_SUCH_ATTRIBUTE. (this is the equilivent of a null cookie) */
  623. int windows_private_load_dirsync_cookie(const Repl_Agmt *ra)
  624. {
  625. Dirsync_Private *dp = NULL;
  626. Slapi_PBlock *pb = NULL;
  627. Slapi_DN* sdn = NULL;
  628. int rc = 0;
  629. Slapi_Entry *entry = NULL;
  630. Slapi_Attr *attr = NULL;
  631. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_load_dirsync_cookie\n" );
  632. PR_ASSERT(ra);
  633. dp = (Dirsync_Private *) agmt_get_priv(ra);
  634. PR_ASSERT (dp);
  635. pb = slapi_pblock_new ();
  636. sdn = slapi_sdn_dup( agmt_get_dn_byref(ra) );
  637. rc = slapi_search_internal_get_entry(sdn, NULL, &entry,
  638. repl_get_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION));
  639. if (rc == 0)
  640. {
  641. rc= slapi_entry_attr_find( entry, type_nsds7DirsyncCookie, &attr );
  642. if (attr)
  643. {
  644. struct berval **vals;
  645. rc = slapi_attr_get_bervals_copy(attr, &vals );
  646. if (vals)
  647. {
  648. dp->dirsync_cookie_len = (int) (vals[0])->bv_len;
  649. slapi_ch_free_string(&dp->dirsync_cookie);
  650. dp->dirsync_cookie = ( char* ) slapi_ch_malloc(dp->dirsync_cookie_len + 1);
  651. memcpy(dp->dirsync_cookie,(vals[0]->bv_val), (vals[0])->bv_len+1);
  652. }
  653. ber_bvecfree(vals);
  654. /* we do not free attr */
  655. }
  656. else
  657. {
  658. rc = LDAP_NO_SUCH_ATTRIBUTE;
  659. }
  660. }
  661. if (entry)
  662. {
  663. slapi_entry_free(entry);
  664. }
  665. slapi_sdn_free( &sdn);
  666. slapi_pblock_destroy (pb);
  667. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_load_dirsync_cookie\n" );
  668. return rc;
  669. }
  670. /* get returns a pointer to the structure - do not free */
  671. Slapi_Entry *windows_private_get_raw_entry(const Repl_Agmt *ra)
  672. {
  673. Dirsync_Private *dp;
  674. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_raw_entry\n" );
  675. dp = (Dirsync_Private *) agmt_get_priv(ra);
  676. PR_ASSERT (dp);
  677. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_raw_entry\n" );
  678. return dp->raw_entry;
  679. }
  680. /* this is passin - windows_private owns the pointer, not a copy */
  681. void windows_private_set_raw_entry(const Repl_Agmt *ra, Slapi_Entry *e)
  682. {
  683. Dirsync_Private *dp;
  684. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_raw_entry\n" );
  685. dp = (Dirsync_Private *) agmt_get_priv(ra);
  686. PR_ASSERT (dp);
  687. /* If the keep raw entry flag is set, just free the passed
  688. * in entry and leave the current raw entry in place. */
  689. if (windows_private_get_keep_raw_entry(ra)) {
  690. slapi_entry_free(e);
  691. } else {
  692. slapi_entry_free(dp->raw_entry);
  693. dp->raw_entry = e;
  694. }
  695. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_raw_entry\n" );
  696. }
  697. /* Setting keep to 1 will cause the current raw entry to remain, even if
  698. * windows_private_set_raw_entry() is called. This behavior will persist
  699. * until this flag is set back to 0. */
  700. void windows_private_set_keep_raw_entry(const Repl_Agmt *ra, int keep)
  701. {
  702. Dirsync_Private *dp;
  703. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_keep_raw_entry\n" );
  704. dp = (Dirsync_Private *) agmt_get_priv(ra);
  705. PR_ASSERT (dp);
  706. dp->keep_raw_entry = keep;
  707. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_keep_raw_entry\n" );
  708. }
  709. int windows_private_get_keep_raw_entry(const Repl_Agmt *ra)
  710. {
  711. Dirsync_Private *dp;
  712. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_keep_raw_entry\n" );
  713. dp = (Dirsync_Private *) agmt_get_priv(ra);
  714. PR_ASSERT (dp);
  715. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_keep_raw_entry\n" );
  716. return dp->keep_raw_entry;
  717. }
  718. void *windows_private_get_api_cookie(const Repl_Agmt *ra)
  719. {
  720. Dirsync_Private *dp;
  721. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_api_cookie\n" );
  722. dp = (Dirsync_Private *) agmt_get_priv(ra);
  723. PR_ASSERT (dp);
  724. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_api_cookie\n" );
  725. return dp->api_cookie;
  726. }
  727. void windows_private_set_api_cookie(Repl_Agmt *ra, void *api_cookie)
  728. {
  729. Dirsync_Private *dp;
  730. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_api_cookie\n" );
  731. dp = (Dirsync_Private *) agmt_get_priv(ra);
  732. PR_ASSERT (dp);
  733. dp->api_cookie = api_cookie;
  734. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_api_cookie\n" );
  735. }
  736. time_t
  737. windows_private_get_sync_interval(const Repl_Agmt *ra)
  738. {
  739. Dirsync_Private *dp;
  740. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_get_sync_interval\n" );
  741. PR_ASSERT(ra);
  742. dp = (Dirsync_Private *) agmt_get_priv(ra);
  743. PR_ASSERT (dp);
  744. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_get_sync_interval\n" );
  745. return dp->sync_interval;
  746. }
  747. void
  748. windows_private_set_sync_interval(Repl_Agmt *ra, char *str)
  749. {
  750. Dirsync_Private *dp;
  751. time_t tmpval = 0;
  752. LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_set_sync_interval\n" );
  753. PR_ASSERT(ra);
  754. dp = (Dirsync_Private *) agmt_get_priv(ra);
  755. PR_ASSERT (dp);
  756. if (str && (tmpval = (time_t)atol(str))) {
  757. dp->sync_interval = tmpval;
  758. }
  759. LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_set_sync_interval\n" );
  760. }
  761. /* an array of function pointers */
  762. static void **_WinSyncAPI = NULL;
  763. static int maxapiidx = WINSYNC_PLUGIN_VERSION_1_END;
  764. #define DECL_WINSYNC_API_FUNC(idx,thetype,thefunc) \
  765. thetype thefunc = (_WinSyncAPI && (idx <= maxapiidx) && _WinSyncAPI[idx]) ? \
  766. (thetype)_WinSyncAPI[idx] : NULL;
  767. void
  768. windows_plugin_init(Repl_Agmt *ra)
  769. {
  770. void *cookie = NULL;
  771. winsync_plugin_init_cb initfunc = NULL;
  772. LDAPDebug0Args( LDAP_DEBUG_PLUGIN, "--> windows_plugin_init_start -- begin\n");
  773. /* if the function pointer array is null, get the functions - we will
  774. call init once per replication agreement, but will only grab the
  775. api once */
  776. if(NULL == _WinSyncAPI) {
  777. if (slapi_apib_get_interface(WINSYNC_v2_0_GUID, &_WinSyncAPI) ||
  778. (NULL == _WinSyncAPI))
  779. {
  780. LDAPDebug1Arg( LDAP_DEBUG_PLUGIN,
  781. "<-- windows_plugin_init_start -- no windows plugin API registered for GUID [%s] -- end\n",
  782. WINSYNC_v2_0_GUID);
  783. } else if (_WinSyncAPI) {
  784. LDAPDebug1Arg( LDAP_DEBUG_PLUGIN,
  785. "<-- windows_plugin_init_start -- found windows plugin API registered for GUID [%s] -- end\n",
  786. WINSYNC_v2_0_GUID);
  787. maxapiidx = WINSYNC_PLUGIN_VERSION_2_END;
  788. }
  789. }
  790. if (NULL == _WinSyncAPI) { /* no v2 interface - look for v1 */
  791. if (slapi_apib_get_interface(WINSYNC_v1_0_GUID, &_WinSyncAPI) ||
  792. (NULL == _WinSyncAPI))
  793. {
  794. LDAPDebug1Arg( LDAP_DEBUG_PLUGIN,
  795. "<-- windows_plugin_init_start -- no windows plugin API registered for GUID [%s] -- end\n",
  796. WINSYNC_v1_0_GUID);
  797. return;
  798. } else {
  799. LDAPDebug1Arg( LDAP_DEBUG_PLUGIN,
  800. "<-- windows_plugin_init_start -- found windows plugin API registered for GUID [%s] -- end\n",
  801. WINSYNC_v1_0_GUID);
  802. }
  803. }
  804. initfunc = (winsync_plugin_init_cb)_WinSyncAPI[WINSYNC_PLUGIN_INIT_CB];
  805. if (initfunc) {
  806. cookie = (*initfunc)(windows_private_get_directory_subtree(ra),
  807. windows_private_get_windows_subtree(ra));
  808. }
  809. windows_private_set_api_cookie(ra, cookie);
  810. LDAPDebug0Args( LDAP_DEBUG_PLUGIN, "<-- windows_plugin_init_start -- end\n");
  811. return;
  812. }
  813. void
  814. winsync_plugin_call_dirsync_search_params_cb(const Repl_Agmt *ra, const char *agmt_dn,
  815. char **base, int *scope, char **filter,
  816. char ***attrs, LDAPControl ***serverctrls)
  817. {
  818. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_DIRSYNC_SEARCH_CB,winsync_search_params_cb,thefunc);
  819. if (!thefunc) {
  820. return;
  821. }
  822. (*thefunc)(windows_private_get_api_cookie(ra), agmt_dn, base, scope, filter,
  823. attrs, serverctrls);
  824. return;
  825. }
  826. void
  827. winsync_plugin_call_pre_ad_search_cb(const Repl_Agmt *ra, const char *agmt_dn,
  828. char **base, int *scope, char **filter,
  829. char ***attrs, LDAPControl ***serverctrls)
  830. {
  831. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_AD_SEARCH_CB,winsync_search_params_cb,thefunc);
  832. if (!thefunc) {
  833. return;
  834. }
  835. (*thefunc)(windows_private_get_api_cookie(ra), agmt_dn, base, scope, filter,
  836. attrs, serverctrls);
  837. return;
  838. }
  839. void
  840. winsync_plugin_call_pre_ds_search_entry_cb(const Repl_Agmt *ra, const char *agmt_dn,
  841. char **base, int *scope, char **filter,
  842. char ***attrs, LDAPControl ***serverctrls)
  843. {
  844. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_DS_SEARCH_ENTRY_CB,winsync_search_params_cb,thefunc);
  845. if (!thefunc) {
  846. return;
  847. }
  848. (*thefunc)(windows_private_get_api_cookie(ra), agmt_dn, base, scope, filter,
  849. attrs, serverctrls);
  850. return;
  851. }
  852. void
  853. winsync_plugin_call_pre_ds_search_all_cb(const Repl_Agmt *ra, const char *agmt_dn,
  854. char **base, int *scope, char **filter,
  855. char ***attrs, LDAPControl ***serverctrls)
  856. {
  857. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_DS_SEARCH_ALL_CB,winsync_search_params_cb,thefunc);
  858. if (!thefunc) {
  859. return;
  860. }
  861. (*thefunc)(windows_private_get_api_cookie(ra), agmt_dn, base, scope, filter,
  862. attrs, serverctrls);
  863. return;
  864. }
  865. void
  866. winsync_plugin_call_pre_ad_mod_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  867. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  868. Slapi_Mods *smods, int *do_modify)
  869. {
  870. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_AD_MOD_USER_CB,winsync_pre_mod_cb,thefunc);
  871. if (!thefunc) {
  872. return;
  873. }
  874. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  875. ds_entry, smods, do_modify);
  876. return;
  877. }
  878. void
  879. winsync_plugin_call_pre_ad_mod_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  880. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  881. Slapi_Mods *smods, int *do_modify)
  882. {
  883. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_AD_MOD_GROUP_CB,winsync_pre_mod_cb,thefunc);
  884. if (!thefunc) {
  885. return;
  886. }
  887. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  888. ds_entry, smods, do_modify);
  889. return;
  890. }
  891. void
  892. winsync_plugin_call_pre_ds_mod_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  893. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  894. Slapi_Mods *smods, int *do_modify)
  895. {
  896. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_DS_MOD_USER_CB,winsync_pre_mod_cb,thefunc);
  897. if (!thefunc) {
  898. return;
  899. }
  900. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  901. ds_entry, smods, do_modify);
  902. return;
  903. }
  904. void
  905. winsync_plugin_call_pre_ds_mod_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  906. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  907. Slapi_Mods *smods, int *do_modify)
  908. {
  909. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_DS_MOD_GROUP_CB,winsync_pre_mod_cb,thefunc);
  910. if (!thefunc) {
  911. return;
  912. }
  913. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  914. ds_entry, smods, do_modify);
  915. return;
  916. }
  917. void
  918. winsync_plugin_call_pre_ds_add_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  919. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry)
  920. {
  921. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_DS_ADD_USER_CB,winsync_pre_add_cb,thefunc);
  922. if (!thefunc) {
  923. return;
  924. }
  925. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  926. ds_entry);
  927. return;
  928. }
  929. void
  930. winsync_plugin_call_pre_ds_add_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  931. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry)
  932. {
  933. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_DS_ADD_GROUP_CB,winsync_pre_add_cb,thefunc);
  934. if (!thefunc) {
  935. return;
  936. }
  937. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  938. ds_entry);
  939. return;
  940. }
  941. void
  942. winsync_plugin_call_get_new_ds_user_dn_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  943. Slapi_Entry *ad_entry, char **new_dn_string,
  944. const Slapi_DN *ds_suffix, const Slapi_DN *ad_suffix)
  945. {
  946. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_GET_NEW_DS_USER_DN_CB,winsync_get_new_dn_cb,thefunc);
  947. if (!thefunc) {
  948. return;
  949. }
  950. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  951. new_dn_string, ds_suffix, ad_suffix);
  952. return;
  953. }
  954. void
  955. winsync_plugin_call_get_new_ds_group_dn_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  956. Slapi_Entry *ad_entry, char **new_dn_string,
  957. const Slapi_DN *ds_suffix, const Slapi_DN *ad_suffix)
  958. {
  959. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_GET_NEW_DS_GROUP_DN_CB,winsync_get_new_dn_cb,thefunc);
  960. if (!thefunc) {
  961. return;
  962. }
  963. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  964. new_dn_string, ds_suffix, ad_suffix);
  965. return;
  966. }
  967. void
  968. winsync_plugin_call_pre_ad_mod_user_mods_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  969. const Slapi_DN *local_dn,
  970. const Slapi_Entry *ds_entry,
  971. LDAPMod * const *origmods,
  972. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  973. {
  974. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_AD_MOD_USER_MODS_CB,winsync_pre_ad_mod_mods_cb,thefunc);
  975. if (!thefunc) {
  976. return;
  977. }
  978. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, local_dn,
  979. ds_entry, origmods, remote_dn, modstosend);
  980. return;
  981. }
  982. void
  983. winsync_plugin_call_pre_ad_mod_group_mods_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  984. const Slapi_DN *local_dn,
  985. const Slapi_Entry *ds_entry,
  986. LDAPMod * const *origmods,
  987. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  988. {
  989. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_AD_MOD_GROUP_MODS_CB,winsync_pre_ad_mod_mods_cb,thefunc);
  990. if (!thefunc) {
  991. return;
  992. }
  993. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, local_dn,
  994. ds_entry, origmods, remote_dn, modstosend);
  995. return;
  996. }
  997. int
  998. winsync_plugin_call_can_add_entry_to_ad_cb(const Repl_Agmt *ra, const Slapi_Entry *local_entry,
  999. const Slapi_DN *remote_dn)
  1000. {
  1001. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_CAN_ADD_ENTRY_TO_AD_CB,winsync_can_add_to_ad_cb,thefunc);
  1002. if (!thefunc) {
  1003. return 1; /* default is entry can be added to AD */
  1004. }
  1005. return (*thefunc)(windows_private_get_api_cookie(ra), local_entry, remote_dn);
  1006. }
  1007. void
  1008. winsync_plugin_call_begin_update_cb(const Repl_Agmt *ra, const Slapi_DN *ds_subtree,
  1009. const Slapi_DN *ad_subtree, int is_total)
  1010. {
  1011. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_BEGIN_UPDATE_CB,winsync_plugin_update_cb,thefunc);
  1012. if (!thefunc) {
  1013. return;
  1014. }
  1015. (*thefunc)(windows_private_get_api_cookie(ra), ds_subtree, ad_subtree, is_total);
  1016. return;
  1017. }
  1018. void
  1019. winsync_plugin_call_end_update_cb(const Repl_Agmt *ra, const Slapi_DN *ds_subtree,
  1020. const Slapi_DN *ad_subtree, int is_total)
  1021. {
  1022. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_END_UPDATE_CB,winsync_plugin_update_cb,thefunc);
  1023. if (!thefunc) {
  1024. return;
  1025. }
  1026. (*thefunc)(windows_private_get_api_cookie(ra), ds_subtree, ad_subtree, is_total);
  1027. return;
  1028. }
  1029. void
  1030. winsync_plugin_call_destroy_agmt_cb(const Repl_Agmt *ra,
  1031. const Slapi_DN *ds_subtree,
  1032. const Slapi_DN *ad_subtree)
  1033. {
  1034. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_DESTROY_AGMT_CB,winsync_plugin_destroy_agmt_cb,thefunc);
  1035. if (thefunc) {
  1036. (*thefunc)(windows_private_get_api_cookie(ra), ds_subtree, ad_subtree);
  1037. }
  1038. return;
  1039. }
  1040. void
  1041. winsync_plugin_call_post_ad_mod_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1042. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1043. Slapi_Mods *smods, int *result)
  1044. {
  1045. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_AD_MOD_USER_CB,winsync_post_mod_cb,thefunc);
  1046. if (!thefunc) {
  1047. return;
  1048. }
  1049. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  1050. ds_entry, smods, result);
  1051. return;
  1052. }
  1053. void
  1054. winsync_plugin_call_post_ad_mod_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1055. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1056. Slapi_Mods *smods, int *result)
  1057. {
  1058. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_AD_MOD_GROUP_CB,winsync_post_mod_cb,thefunc);
  1059. if (!thefunc) {
  1060. return;
  1061. }
  1062. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  1063. ds_entry, smods, result);
  1064. return;
  1065. }
  1066. void
  1067. winsync_plugin_call_post_ds_mod_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1068. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1069. Slapi_Mods *smods, int *result)
  1070. {
  1071. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_DS_MOD_USER_CB,winsync_post_mod_cb,thefunc);
  1072. if (!thefunc) {
  1073. return;
  1074. }
  1075. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  1076. ds_entry, smods, result);
  1077. return;
  1078. }
  1079. void
  1080. winsync_plugin_call_post_ds_mod_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1081. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry,
  1082. Slapi_Mods *smods, int *result)
  1083. {
  1084. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_DS_MOD_GROUP_CB,winsync_post_mod_cb,thefunc);
  1085. if (!thefunc) {
  1086. return;
  1087. }
  1088. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  1089. ds_entry, smods, result);
  1090. return;
  1091. }
  1092. void
  1093. winsync_plugin_call_post_ds_add_user_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1094. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  1095. {
  1096. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_DS_ADD_USER_CB,winsync_post_add_cb,thefunc);
  1097. if (!thefunc) {
  1098. return;
  1099. }
  1100. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  1101. ds_entry, result);
  1102. return;
  1103. }
  1104. void
  1105. winsync_plugin_call_post_ds_add_group_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1106. Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  1107. {
  1108. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_DS_ADD_GROUP_CB,winsync_post_add_cb,thefunc);
  1109. if (!thefunc) {
  1110. return;
  1111. }
  1112. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, ad_entry,
  1113. ds_entry, result);
  1114. return;
  1115. }
  1116. void
  1117. winsync_plugin_call_pre_ad_add_user_cb(const Repl_Agmt *ra, Slapi_Entry *ad_entry,
  1118. Slapi_Entry *ds_entry)
  1119. {
  1120. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_AD_ADD_USER_CB,winsync_pre_ad_add_cb,thefunc);
  1121. if (!thefunc) {
  1122. return;
  1123. }
  1124. (*thefunc)(windows_private_get_api_cookie(ra), ad_entry, ds_entry);
  1125. return;
  1126. }
  1127. void
  1128. winsync_plugin_call_pre_ad_add_group_cb(const Repl_Agmt *ra, Slapi_Entry *ad_entry,
  1129. Slapi_Entry *ds_entry)
  1130. {
  1131. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_PRE_AD_ADD_GROUP_CB,winsync_pre_ad_add_cb,thefunc);
  1132. if (!thefunc) {
  1133. return;
  1134. }
  1135. (*thefunc)(windows_private_get_api_cookie(ra), ad_entry, ds_entry);
  1136. return;
  1137. }
  1138. void
  1139. winsync_plugin_call_post_ad_add_user_cb(const Repl_Agmt *ra, Slapi_Entry *ad_entry,
  1140. Slapi_Entry *ds_entry, int *result)
  1141. {
  1142. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_AD_ADD_USER_CB,winsync_post_ad_add_cb,thefunc);
  1143. if (!thefunc) {
  1144. return;
  1145. }
  1146. (*thefunc)(windows_private_get_api_cookie(ra), ad_entry, ds_entry, result);
  1147. return;
  1148. }
  1149. void
  1150. winsync_plugin_call_post_ad_add_group_cb(const Repl_Agmt *ra, Slapi_Entry *ad_entry,
  1151. Slapi_Entry *ds_entry, int *result)
  1152. {
  1153. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_AD_ADD_GROUP_CB,winsync_post_ad_add_cb,thefunc);
  1154. if (!thefunc) {
  1155. return;
  1156. }
  1157. (*thefunc)(windows_private_get_api_cookie(ra), ad_entry, ds_entry, result);
  1158. return;
  1159. }
  1160. void
  1161. winsync_plugin_call_post_ad_mod_user_mods_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1162. const Slapi_DN *local_dn,
  1163. const Slapi_Entry *ds_entry,
  1164. LDAPMod * const *origmods,
  1165. Slapi_DN *remote_dn, LDAPMod **modstosend, int *result)
  1166. {
  1167. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_AD_MOD_USER_MODS_CB,winsync_post_ad_mod_mods_cb,thefunc);
  1168. if (!thefunc) {
  1169. return;
  1170. }
  1171. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, local_dn,
  1172. ds_entry, origmods, remote_dn, modstosend, result);
  1173. return;
  1174. }
  1175. void
  1176. winsync_plugin_call_post_ad_mod_group_mods_cb(const Repl_Agmt *ra, const Slapi_Entry *rawentry,
  1177. const Slapi_DN *local_dn,
  1178. const Slapi_Entry *ds_entry,
  1179. LDAPMod * const *origmods,
  1180. Slapi_DN *remote_dn, LDAPMod **modstosend, int *result)
  1181. {
  1182. DECL_WINSYNC_API_FUNC(WINSYNC_PLUGIN_POST_AD_MOD_GROUP_MODS_CB,winsync_post_ad_mod_mods_cb,thefunc);
  1183. if (!thefunc) {
  1184. return;
  1185. }
  1186. (*thefunc)(windows_private_get_api_cookie(ra), rawentry, local_dn,
  1187. ds_entry, origmods, remote_dn, modstosend, result);
  1188. return;
  1189. }
  1190. /* #define WINSYNC_TEST_IPA */
  1191. #ifdef WINSYNC_TEST_IPA
  1192. #include "ipa-winsync.c"
  1193. #include "ipa-winsync-config.c"
  1194. #endif