posix-winsync.c 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933
  1. /** Author: Carsten Grzemba [email protected]>
  2. *
  3. * Copyright (C) 2011 contac Datentechnik GmbH
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; version 2 only
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. $Id: posix-winsync.c 40 2011-06-10 08:28:56Z grzemba $
  18. **/
  19. /*
  20. * - AD needs for Posix attributes a NIS Domainname, this software expect a attribute nisDomain with the name in a upper container on DS side
  21. * - currently the winsync API has no callbacks for new created entries on DS side
  22. compile:
  23. gcc -g -shared -m64 -fPIC -c -D WINSYNC_TEST_POSIX \
  24. -I ../fedora-ds/ds/ldap/servers/slapd \
  25. -I ../fedora-ds/ds/ldap/servers/plugins/replication \
  26. -I /usr/include/mps posix-winsync.c
  27. link:
  28. ld -G posix-winsync.o -o libposix-winsync.so
  29. configure DS with
  30. dn: cn=Posix Winsync API,cn=plugins,cn=config
  31. objectclass: top
  32. objectclass: nsSlapdPlugin
  33. objectclass: extensibleObject
  34. cn: Posix Winsync API
  35. nsslapd-pluginpath: libposix-winsync
  36. nsslapd-plugininitfunc: posix_winsync_plugin_init
  37. nsslapd-plugintype: preoperation
  38. nsslapd-pluginenabled: on
  39. nsslapd-plugin-depends-on-type: database
  40. nsslapd-pluginDescription: Sync Posix Attributes for users and groups between AD and DS if available and user lock/unlock
  41. nsslapd-pluginVendor: contac Datentechnik GmbH
  42. nsslapd-pluginId: posix-winsync-plugin
  43. nsslapd-pluginVersion: POSIX/1.0
  44. AFTER that make new replication aggrements
  45. for details see: Red_Hat_Directory_Server-8.2-Plug-in_Guide-en-US.pdf
  46. */
  47. #ifdef HAVE_CONFIG_H
  48. # include <config.h>
  49. #endif
  50. #ifdef WINSYNC_TEST_POSIX
  51. #include <slapi-plugin.h>
  52. #include "winsync-plugin.h"
  53. #else
  54. #include <dirsrv/slapi-plugin.h>
  55. #include <dirsrv/winsync-plugin.h>
  56. #endif
  57. #include <plstr.h>
  58. #include <strings.h>
  59. #include <stdlib.h>
  60. #include "posix-wsp-ident.h"
  61. #include "posix-group-func.h"
  62. #define MEMBEROFTASK "memberuid task"
  63. Slapi_Value **
  64. valueset_get_valuearray(const Slapi_ValueSet *vs); /* stolen from proto-slap.h */
  65. void *
  66. posix_winsync_get_plugin_identity();
  67. void *
  68. posix_winsync_agmt_init(const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree);
  69. /**
  70. * Plugin identifiers
  71. */
  72. static Slapi_PluginDesc posix_winsync_pdesc =
  73. { "posix-winsync-plugin", VENDOR, DS_PACKAGE_VERSION,
  74. "Sync Posix Attributs for users and groups between AD and DS if available" };
  75. typedef struct _windows_attr_map
  76. {
  77. char *windows_attribute_name;
  78. char *ldap_attribute_name;
  79. int isMUST; /* schema: required attribute */
  80. } windows_attribute_map;
  81. static windows_attribute_map user_attribute_map[] = {
  82. { "unixHomeDirectory", "homeDirectory", 1 },
  83. { "loginShell", "loginShell", 0 },
  84. { "uidNumber", "uidNumber", 1 },
  85. { "gidNumber", "gidNumber", 1 },
  86. { "gecos", "gecos", 0 },
  87. { NULL, NULL, 0 }
  88. };
  89. static windows_attribute_map user_mssfu_attribute_map[] =
  90. { { "msSFU30homedirectory", "homeDirectory" },
  91. { "msSFU30loginshell", "loginShell" },
  92. { "msSFU30uidnumber", "uidNumber" },
  93. { "msSFU30gidnumber", "gidNumber" },
  94. { "msSFU30gecos", "gecos" },
  95. { NULL, NULL } };
  96. /* memberUid must be first element or fixup in pre_ad_mod/add_group is required */
  97. static windows_attribute_map group_attribute_map[] = { { "memberUid", "memberUid" },
  98. { "gidNumber", "gidNumber" },
  99. { NULL, NULL } };
  100. static windows_attribute_map group_mssfu_attribute_map[] = { { "msSFU30memberUid", "memberUid" },
  101. { "msSFU30gidNumber", "gidNumber" },
  102. { NULL, NULL } };
  103. static char *posix_winsync_plugin_name = POSIX_WINSYNC_PLUGIN_NAME;
  104. enum
  105. {
  106. ACCT_DISABLE_INVALID, /* the invalid value */
  107. ACCT_DISABLE_NONE, /* do not sync acct disable status */
  108. ACCT_DISABLE_TO_AD, /* sync only from ds to ad */
  109. ACCT_DISABLE_TO_DS, /* sync only from ad to ds */
  110. ACCT_DISABLE_BOTH
  111. /* bi-directional sync */
  112. };
  113. /*
  114. * Check if the given entry has account lock on (i.e. entry is disabled)
  115. * Mostly copied from check_account_lock in the server code.
  116. * Returns: 0 - account is disabled (lock == "true")
  117. * 1 - account is enabled (lock == "false" or empty)
  118. * -1 - some sort of error
  119. */
  120. static int
  121. check_account_lock(Slapi_Entry *ds_entry, int *isvirt)
  122. {
  123. int rc = 1;
  124. Slapi_ValueSet *values = NULL;
  125. int type_name_disposition = 0;
  126. char *actual_type_name = NULL;
  127. int attr_free_flags = 0;
  128. char *strval;
  129. /* first, see if the attribute is a "real" attribute */
  130. strval = slapi_entry_attr_get_charptr(ds_entry, "nsAccountLock");
  131. if (strval) { /* value is real */
  132. *isvirt = 0; /* value is real */
  133. rc = 1; /* default to enabled */
  134. if (PL_strncasecmp(strval, "true", 4) == 0) {
  135. rc = 0; /* account is disabled */
  136. }
  137. slapi_ch_free_string(&strval);
  138. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  139. "<-- check_account_lock - entry [%s] has real "
  140. "attribute nsAccountLock and entry %s locked\n",
  141. slapi_entry_get_dn_const(ds_entry), rc ? "is not" : "is");
  142. return rc;
  143. }
  144. rc = slapi_vattr_values_get(ds_entry, "nsAccountLock", &values, &type_name_disposition,
  145. &actual_type_name, SLAPI_VIRTUALATTRS_REQUEST_POINTERS,
  146. &attr_free_flags);
  147. if (rc == 0) {
  148. Slapi_Value *v = NULL;
  149. const struct berval *bvp = NULL;
  150. rc = 1; /* default is enabled */
  151. *isvirt = 1; /* value is virtual */
  152. if ((slapi_valueset_first_value(values, &v) != -1) &&
  153. ((bvp = slapi_value_get_berval(v)) != NULL)) {
  154. if ((bvp != NULL) && (PL_strncasecmp(bvp->bv_val, "true", 4) == 0)) {
  155. slapi_vattr_values_free(&values, &actual_type_name, attr_free_flags);
  156. rc = 0; /* account is disabled */
  157. }
  158. }
  159. if (values != NULL) {
  160. slapi_vattr_values_free(&values, &actual_type_name, attr_free_flags);
  161. }
  162. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  163. "<-- check_account_lock - entry [%s] has virtual "
  164. "attribute nsAccountLock and entry %s locked\n",
  165. slapi_entry_get_dn_const(ds_entry), rc ? "is not" : "is");
  166. } else {
  167. rc = 1; /* no attr == entry is enabled */
  168. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  169. "<-- check_account_lock - entry [%s] does not "
  170. "have attribute nsAccountLock - entry is not locked\n",
  171. slapi_entry_get_dn_const(ds_entry));
  172. }
  173. return rc;
  174. }
  175. /*
  176. * This can be used either in the to ad direction or the to ds direction, since in both
  177. * cases we have to read both entries and compare the values.
  178. * ad_entry - entry from AD
  179. * ds_entry - entry from DS
  180. * direction - either ACCT_DISABLE_TO_AD or ACCT_DISABLE_TO_DS
  181. *
  182. * If smods is given, this is the list of mods to send in the given direction. The
  183. * appropriate modify operation will be added to this list or changed to the correct
  184. * value if it already exists.
  185. * Otherwise, if a destination entry is given, the value will be written into
  186. * that entry.
  187. */
  188. static void
  189. sync_acct_disable(void *cbdata, /* the usual domain config data */
  190. const Slapi_Entry *ad_entry, /* the AD entry */
  191. Slapi_Entry *ds_entry, /* the DS entry */
  192. int direction, /* the direction - TO_AD or TO_DS */
  193. Slapi_Entry *update_entry, /* the entry to update for ADDs */
  194. Slapi_Mods *smods, /* the mod list for MODIFYs */
  195. int *do_modify /* if not NULL, set this to true if mods were added */
  196. )
  197. {
  198. int ds_is_enabled = 1; /* default to true */
  199. int ad_is_enabled = 1; /* default to true */
  200. unsigned long adval = 0; /* raw account val from ad entry */
  201. int isvirt = 0;
  202. /* get the account lock state of the ds entry */
  203. if (0 == check_account_lock(ds_entry, &isvirt)) {
  204. ds_is_enabled = 0;
  205. }
  206. if (isvirt)
  207. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  208. "<-- sync_acct_disable - %s DS nsaccountlock is virtual!!!!\n",
  209. slapi_entry_get_dn_const(ds_entry));
  210. /* get the account lock state of the ad entry */
  211. adval = slapi_entry_attr_get_ulong(ad_entry, "UserAccountControl");
  212. if (adval & 0x2) {
  213. /* account is disabled */
  214. ad_is_enabled = 0;
  215. }
  216. if (ad_is_enabled == ds_is_enabled) { /* both have same value - nothing to do */
  217. return;
  218. }
  219. /* have to enable or disable */
  220. if (direction == ACCT_DISABLE_TO_AD) {
  221. unsigned long mask;
  222. /* set the mod or entry */
  223. if (ds_is_enabled) {
  224. mask = ~0x2;
  225. adval &= mask; /* unset the 0x2 disable bit */
  226. } else {
  227. mask = 0x2;
  228. adval |= mask; /* set the 0x2 disable bit */
  229. }
  230. if (update_entry) {
  231. slapi_entry_attr_set_ulong(update_entry, "userAccountControl", adval);
  232. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  233. "<-- sync_acct_disable - %s AD account [%s] - "
  234. "new value is [%ld]\n", (ds_is_enabled) ? "enabled" : "disabled",
  235. slapi_entry_get_dn_const(update_entry), adval);
  236. } else {
  237. /* iterate through the mods - if there is already a mod
  238. for userAccountControl, change it - otherwise, add it */
  239. char acctvalstr[32];
  240. LDAPMod *mod = NULL;
  241. struct berval *mod_bval = NULL;
  242. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  243. if (!PL_strcasecmp(mod->mod_type, "userAccountControl") && mod->mod_bvalues
  244. && mod->mod_bvalues[0]) {
  245. mod_bval = mod->mod_bvalues[0];
  246. /* mod_bval points directly to value inside mod list */
  247. break;
  248. }
  249. }
  250. if (!mod_bval) { /* not found - add it */
  251. struct berval tmpbval = { 0, NULL };
  252. Slapi_Mod *smod = slapi_mod_new();
  253. slapi_mod_init(smod, 1); /* one element */
  254. slapi_mod_set_type(smod, "userAccountControl");
  255. slapi_mod_set_operation(smod, LDAP_MOD_REPLACE | LDAP_MOD_BVALUES);
  256. slapi_mod_add_value(smod, &tmpbval);
  257. /* add_value makes a copy of the bval - so let's get a pointer
  258. to that new value - we will change the bval in place */
  259. mod_bval = slapi_mod_get_first_value(smod);
  260. /* mod_bval points directly to value inside mod list */
  261. /* now add the new mod to smods */
  262. slapi_mods_add_ldapmod(smods, slapi_mod_get_ldapmod_passout(smod));
  263. /* smods now owns the ldapmod */
  264. slapi_mod_free(&smod);
  265. if (do_modify) {
  266. *do_modify = 1; /* added mods */
  267. }
  268. }
  269. if (mod_bval) {
  270. /* this is where we set or update the actual value
  271. mod_bval points directly into the mod list we are
  272. sending */
  273. if (mod_bval->bv_val && (mod_bval->bv_len > 0)) {
  274. /* get the old val */
  275. adval = strtol(mod_bval->bv_val, NULL, 10);
  276. }
  277. if (ds_is_enabled) {
  278. mask = ~0x2;
  279. adval &= mask; /* unset the 0x2 disable bit */
  280. } else {
  281. mask = 0x2;
  282. adval |= mask; /* set the 0x2 disable bit */
  283. }
  284. PR_snprintf(acctvalstr, sizeof(acctvalstr), "%lu", adval);
  285. slapi_ch_free_string(&mod_bval->bv_val);
  286. mod_bval->bv_val = slapi_ch_strdup(acctvalstr);
  287. mod_bval->bv_len = strlen(acctvalstr);
  288. }
  289. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  290. "<-- sync_acct_disable - %s AD account [%s] - "
  291. "new value is [%ld]\n", (ds_is_enabled) ? "enabled" : "disabled",
  292. slapi_entry_get_dn_const(ad_entry), adval);
  293. }
  294. }
  295. if (direction == ACCT_DISABLE_TO_DS) {
  296. char *attrtype = NULL;
  297. char *attrval;
  298. char *val = NULL;
  299. attrtype = (isvirt) ? "nsRoleDN" : "nsAccountLock";
  300. if (ad_is_enabled) {
  301. attrval = NULL; /* will delete the value */
  302. } else {
  303. if (isvirt) {
  304. val = slapi_create_dn_string("cn=nsManagedDisabledRole,%s",
  305. slapi_sdn_get_dn(posix_winsync_config_get_suffix()));
  306. attrval = val;
  307. } else {
  308. attrval = "true";
  309. }
  310. }
  311. if (update_entry) {
  312. slapi_entry_attr_set_charptr(update_entry, attrtype, attrval);
  313. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  314. "<-- sync_acct_disable - %s DS account [%s]\n", (ad_is_enabled)
  315. ? "enable" : "disable", slapi_entry_get_dn_const(ds_entry));
  316. } else { /* do mod */
  317. Slapi_Mod *smod = slapi_mod_new();
  318. slapi_mod_init(smod, 1); /* one element */
  319. slapi_mod_set_type(smod, attrtype);
  320. if (attrval == NULL) {
  321. slapi_mod_set_operation(smod, LDAP_MOD_DELETE | LDAP_MOD_BVALUES);
  322. } else {
  323. Slapi_Value *v = NULL;
  324. v = slapi_value_new_string(attrval);
  325. slapi_mod_set_operation(smod, LDAP_MOD_REPLACE | LDAP_MOD_BVALUES);
  326. slapi_mod_add_value(smod, slapi_value_get_berval(v));
  327. slapi_value_free(&v);
  328. }
  329. slapi_mods_add_ldapmod(smods, slapi_mod_get_ldapmod_passout(smod));
  330. slapi_mod_free(&smod);
  331. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  332. "<-- sync_acct_disable - %s DS account [%s]\n", (ad_is_enabled)
  333. ? "enable" : "disable", slapi_entry_get_dn_const(ds_entry));
  334. if (do_modify) {
  335. *do_modify = 1; /* added mods */
  336. }
  337. }
  338. slapi_ch_free_string(&val);
  339. }
  340. return;
  341. }
  342. /* Returns non-zero if the attribute value sets are identical. */
  343. static int
  344. attr_compare_equal(Slapi_Attr *a, Slapi_Attr *b)
  345. {
  346. int i = 0;
  347. Slapi_Value *va = NULL;
  348. /* Iterate through values in attr a and search for each in attr b */
  349. for (i = slapi_attr_first_value(a, &va); va && (i != -1); i = slapi_attr_next_value(a, i, &va)) {
  350. /* Compare the entire attribute value */
  351. if (slapi_attr_value_find(b, slapi_value_get_berval(va)) != 0) {
  352. return 0;
  353. }
  354. }
  355. return 1;
  356. }
  357. /* look in the parent nodes of ds_entry for nis domain entry */
  358. char *
  359. getNisDomainName(const Slapi_Entry *ds_entry)
  360. {
  361. Slapi_DN* entry_sdn = slapi_entry_get_sdn((Slapi_Entry *) ds_entry);
  362. Slapi_DN* subtree_sdn = slapi_sdn_new();
  363. char *type_NisDomain = "nisDomain";
  364. Slapi_PBlock * pb;
  365. Slapi_DN *childparent = slapi_sdn_new();
  366. char* nisdomainname = NULL;
  367. Slapi_Entry *entry = NULL;
  368. int rc = -1;
  369. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "getNisDomainName start DN:%s\n",
  370. slapi_sdn_get_dn(entry_sdn));
  371. /* search NIS domain name */
  372. slapi_sdn_get_parent(entry_sdn, subtree_sdn);
  373. pb = slapi_pblock_new();
  374. do {
  375. char *nisDomainAttr[] = { type_NisDomain, NULL };
  376. slapi_sdn_get_parent(subtree_sdn, childparent);
  377. if (slapi_sdn_isempty(childparent)) {
  378. rc = -1;
  379. break;
  380. }
  381. rc = slapi_search_internal_get_entry(childparent, nisDomainAttr, &entry,
  382. posix_winsync_get_plugin_identity());
  383. if (rc == 0) {
  384. if (rc == 0 && entry) {
  385. nisdomainname = slapi_entry_attr_get_charptr(entry, type_NisDomain);
  386. if (nisdomainname != NULL){
  387. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  388. "getNisDomainName NisDomain %s found in DN:%s\n",
  389. nisdomainname, slapi_sdn_get_dn(childparent));
  390. break;
  391. }
  392. }
  393. }
  394. slapi_sdn_copy(childparent, subtree_sdn);
  395. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  396. "getNisDomainName iterate DN:%s\n", slapi_sdn_get_dn(subtree_sdn));
  397. slapi_entry_free(entry);
  398. entry = NULL;
  399. } while (PR_TRUE);
  400. slapi_pblock_destroy(pb);
  401. if (rc != 0 || nisdomainname == NULL ) {
  402. slapi_log_error(SLAPI_LOG_REPL, posix_winsync_plugin_name,
  403. "getNisDomainName: no nisdomainname found in %s, LDAP Err%d\n",
  404. slapi_sdn_get_dn(subtree_sdn), rc);
  405. }
  406. slapi_sdn_free(&childparent);
  407. slapi_entry_free(entry);
  408. entry = NULL;
  409. slapi_sdn_free(&subtree_sdn);
  410. return nisdomainname;
  411. }
  412. static int
  413. addNisDomainName(Slapi_Mod *smod, const Slapi_Entry *ds_entry)
  414. {
  415. int rc = LDAP_SUCCESS;
  416. char* nisdomainname = getNisDomainName(ds_entry);
  417. if ( nisdomainname == NULL ) {
  418. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  419. "addNisDomainName NisDomain not found\n");
  420. rc = LDAP_NO_SUCH_ATTRIBUTE;
  421. } else {
  422. struct berval bval;
  423. slapi_mod_init(smod, 1);
  424. slapi_mod_set_type(smod, "msSFU30NisDomain");
  425. slapi_mod_set_operation(smod, LDAP_MOD_REPLACE | LDAP_MOD_BVALUES);
  426. bval.bv_val = nisdomainname;
  427. bval.bv_len = sizeof (nisdomainname);
  428. slapi_mod_add_value(smod, &bval);
  429. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN))
  430. slapi_mod_dump((LDAPMod*) slapi_mod_get_ldapmod_byref(smod), 0);
  431. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  432. "addNisDomainName NisDomain %s found\n", nisdomainname);
  433. slapi_ch_free_string(&nisdomainname); /* allocated by slapi_entry_attr_getchrptr */
  434. }
  435. return rc;
  436. }
  437. static void
  438. posix_winsync_dirsync_search_params_cb(void *cbdata, const char *agmt_dn, char **base, int *scope,
  439. char **filter, char ***attrs, LDAPControl ***serverctrls)
  440. {
  441. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  442. "--> posix_winsync_dirsync_search_params_cb -- begin\n");
  443. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  444. "<-- posix_winsync_dirsync_search_params_cb -- end\n");
  445. return;
  446. }
  447. /* called before searching for a single entry from AD - agmt_dn will be NULL */
  448. static void
  449. posix_winsync_pre_ad_search_cb(void *cbdata, const char *agmt_dn, char **base, int *scope,
  450. char **filter, char ***attrs, LDAPControl ***serverctrls)
  451. {
  452. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  453. "--> posix_winsync_pre_ad_search_cb -- begin\n");
  454. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  455. "<-- posix_winsync_pre_ad_search_cb -- end\n");
  456. return;
  457. }
  458. /* called before an internal search to get a single DS entry - agmt_dn will be NULL */
  459. static void
  460. posix_winsync_pre_ds_search_entry_cb(void *cbdata, const char *agmt_dn, char **base, int *scope,
  461. char **filter, char ***attrs, LDAPControl ***serverctrls)
  462. {
  463. /*
  464. char *tmpbase=slapi_ch_strdup(*base);
  465. char *d = *base;
  466. char *s = tmpbase;
  467. int i=0;
  468. */
  469. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "--> _pre_ds_search_cb -- begin\n");
  470. /* skip the first subtree container ou=xyz, */
  471. /* if (strlen(*base) > 3) {
  472. s++;
  473. while(*s !='\0'){
  474. if (((*(s) == ',') || (*(s) == ';' )) && (*((s)-1) != '\\')){
  475. s++;
  476. while(*s !='\0'){
  477. *d++ = *s++;
  478. }
  479. *d='\0';
  480. break;
  481. }
  482. s++;
  483. }
  484. }
  485. */
  486. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  487. "-- _pre_ds_search_cb - base [%s] "
  488. "scope [%d] filter [%s]\n", *base, *scope, *filter);
  489. /* slapi_ch_free_string(&tmpbase); */
  490. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_search_cb -- end\n");
  491. return;
  492. }
  493. /* called before the total update to get all entries from the DS to sync to AD */
  494. static void
  495. posix_winsync_pre_ds_search_all_cb(void *cbdata, const char *agmt_dn, char **base, int *scope,
  496. char **filter, char ***attrs, LDAPControl ***serverctrls)
  497. {
  498. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  499. "--> posix_winsync_pre_ds_search_all_cb -- orig filter [%s] -- begin\n",
  500. ((filter && *filter) ? *filter : "NULL"));
  501. /* slapi_ch_free_string(filter);
  502. *filter = slapi_ch_strdup("(|(objectclass=posixaccount)(objectclass=posixgroup))");
  503. */
  504. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  505. "<-- posix_winsync_pre_ds_search_all_cb -- end\n");
  506. return;
  507. }
  508. static void
  509. posix_winsync_pre_ad_mod_user_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  510. Slapi_Entry *ds_entry, Slapi_Mods *smods, int *do_modify)
  511. {
  512. LDAPMod *mod = NULL;
  513. int rc = 0;
  514. Slapi_Attr *attr = NULL;
  515. windows_attribute_map *attr_map = user_attribute_map;
  516. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  517. "--> posix_winsync_pre_ad_mod_user_cb -- begin DS account [%s]\n",
  518. slapi_entry_get_dn_const(ds_entry));
  519. if (posix_winsync_config_get_msSFUSchema()) {
  520. attr_map = user_mssfu_attribute_map;
  521. }
  522. /* called if init Replica: add nisDomain, uidnumber, ... if avail */
  523. for (rc = slapi_entry_first_attr(ds_entry, &attr); rc == 0;
  524. rc = slapi_entry_next_attr(ds_entry, attr, &attr)) {
  525. char *type = NULL;
  526. size_t i = 0;
  527. slapi_attr_get_type(attr, &type);
  528. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  529. "_pre_ad_mod_user_cb -- check modify type %s\n", type);
  530. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  531. if (0 == slapi_attr_type_cmp(type, attr_map[i].ldap_attribute_name,
  532. SLAPI_TYPE_CMP_SUBTYPE)) {
  533. Slapi_Attr *ad_attr = NULL;
  534. Slapi_ValueSet *vs = NULL;
  535. char *ad_type = NULL;
  536. int is_present_local;
  537. slapi_attr_get_valueset(attr, &vs);
  538. ad_type = slapi_ch_strdup(attr_map[i].windows_attribute_name);
  539. slapi_entry_attr_find(ad_entry, ad_type, &ad_attr);
  540. is_present_local = (NULL == ad_attr) ? 0 : 1;
  541. if (is_present_local) {
  542. int values_equal = 0;
  543. values_equal = attr_compare_equal(attr, ad_attr);
  544. if (!values_equal) {
  545. slapi_log_error(
  546. SLAPI_LOG_PLUGIN,
  547. posix_winsync_plugin_name,
  548. "_pre_ad_mod_user_cb -- update mods: %s, %s : values are different -> modify\n",
  549. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  550. ad_type);
  551. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, ad_type,
  552. valueset_get_valuearray(vs));
  553. *do_modify = 1;
  554. }
  555. } else {
  556. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, ad_type,
  557. valueset_get_valuearray(vs));
  558. if (0 == slapi_attr_type_cmp(type, "uidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  559. Slapi_Mod *mysmod = slapi_mod_new();
  560. addNisDomainName(mysmod, ds_entry);
  561. slapi_mods_add_ldapmod(smods, slapi_mod_get_ldapmod_passout(mysmod));
  562. slapi_mod_free(&mysmod);
  563. }
  564. *do_modify = 1;
  565. }
  566. slapi_ch_free((void**) &ad_type);
  567. slapi_valueset_free(vs);
  568. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  569. "_pre_ad_mod_user_cb -- add modify %s DS account [%s]\n",
  570. attr_map[i].windows_attribute_name,
  571. slapi_entry_get_dn_const(ds_entry));
  572. }
  573. }
  574. if (0 == slapi_attr_type_cmp(type, "nsAccountLock", SLAPI_TYPE_CMP_SUBTYPE))
  575. sync_acct_disable(cbdata, rawentry, ds_entry, ACCT_DISABLE_TO_AD, NULL, smods,
  576. do_modify);
  577. }
  578. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  579. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  580. slapi_mod_dump(mod, 0);
  581. }
  582. }
  583. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  584. "<-- posix_winsync_pre_ad_mod_user_cb -- end\n");
  585. return;
  586. }
  587. static void
  588. posix_winsync_pre_ad_mod_group_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  589. Slapi_Entry *ds_entry, Slapi_Mods *smods, int *do_modify)
  590. {
  591. LDAPMod *mod = NULL;
  592. int rc = 0;
  593. Slapi_Attr *attr = NULL;
  594. windows_attribute_map *attr_map = group_attribute_map;
  595. if (posix_winsync_config_get_msSFUSchema())
  596. attr_map = group_mssfu_attribute_map;
  597. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  598. "--> _pre_ad_mod_group_cb -- begin DS account [%s]\n",
  599. slapi_entry_get_dn_const(ds_entry));
  600. /* called if init Replica: add nisDomain, gidnumber, memberuid, if avail */
  601. for (rc = slapi_entry_first_attr(ds_entry, &attr); rc == 0;
  602. rc = slapi_entry_next_attr(ds_entry, attr, &attr)) {
  603. char *type = NULL;
  604. size_t i = 0;
  605. slapi_attr_get_type(attr, &type);
  606. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  607. "_pre_ad_mod_group_cb -- check modify type %s\n", type);
  608. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  609. if (0 == slapi_attr_type_cmp(type, attr_map[i].ldap_attribute_name,
  610. SLAPI_TYPE_CMP_SUBTYPE)) {
  611. Slapi_Attr *ad_attr = NULL;
  612. Slapi_ValueSet *vs = NULL;
  613. char *ad_type = NULL;
  614. int is_present_local;
  615. if (i == 0) { /* memberUid */
  616. Slapi_Attr *dsmuid_attr = NULL;
  617. Slapi_Value *v = NULL;
  618. slapi_entry_attr_find(ds_entry, "dsonlymemberuid", &dsmuid_attr);
  619. if (dsmuid_attr) {
  620. Slapi_ValueSet *dsmuid_vs = NULL;
  621. slapi_attr_get_valueset(dsmuid_attr, &dsmuid_vs);
  622. if (dsmuid_vs) {
  623. vs = slapi_valueset_new();
  624. int j;
  625. for (j = slapi_attr_first_value(attr, &v); j != -1;
  626. j = slapi_attr_next_value(attr, i, &v)) {
  627. if (!slapi_valueset_find(dsmuid_attr, dsmuid_vs, v)) {
  628. slapi_valueset_add_value(vs, v);
  629. }
  630. }
  631. slapi_valueset_free(dsmuid_vs); dsmuid_vs = NULL;
  632. }
  633. }
  634. }
  635. if (!vs) {
  636. slapi_attr_get_valueset(attr, &vs);
  637. }
  638. ad_type = slapi_ch_strdup(attr_map[i].windows_attribute_name);
  639. slapi_entry_attr_find(ad_entry, ad_type, &ad_attr);
  640. is_present_local = (NULL == ad_attr) ? 0 : 1;
  641. if (is_present_local) {
  642. int values_equal = 0;
  643. values_equal = attr_compare_equal(attr, ad_attr);
  644. if (!values_equal) {
  645. slapi_log_error(
  646. SLAPI_LOG_PLUGIN,
  647. posix_winsync_plugin_name,
  648. "_pre_ad_mod_group_cb -- update mods: %s, %s : values are different -> modify\n",
  649. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  650. ad_type);
  651. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, ad_type,
  652. valueset_get_valuearray(vs));
  653. *do_modify = 1;
  654. }
  655. } else {
  656. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, ad_type,
  657. valueset_get_valuearray(vs));
  658. if (0 == slapi_attr_type_cmp(type, "gidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  659. Slapi_Mod *mysmod = slapi_mod_new();
  660. addNisDomainName(mysmod, ds_entry);
  661. slapi_mods_add_ldapmod(smods, slapi_mod_get_ldapmod_passout(mysmod));
  662. slapi_mod_free(&mysmod);
  663. }
  664. *do_modify = 1;
  665. }
  666. slapi_ch_free((void**) &ad_type);
  667. slapi_valueset_free(vs);
  668. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  669. "_pre_ad_mod_group_cb -- add modify %s DS account [%s]\n",
  670. attr_map[i].windows_attribute_name,
  671. slapi_entry_get_dn_const(ds_entry));
  672. }
  673. }
  674. }
  675. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "_pre_ad_mod_group_cb -- step\n");
  676. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  677. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  678. slapi_mod_dump(mod, 0);
  679. }
  680. }
  681. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  682. "<-- _pre_ad_mod_group_cb -- end\n");
  683. return;
  684. }
  685. static void
  686. posix_winsync_pre_ds_mod_user_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  687. Slapi_Entry *ds_entry, Slapi_Mods *smods, int *do_modify)
  688. {
  689. LDAPMod* mod = NULL;
  690. Slapi_Attr *attr = NULL;
  691. int is_present_local = 0;
  692. int do_modify_local = 0;
  693. int rc;
  694. int i;
  695. windows_attribute_map *attr_map = user_attribute_map;
  696. PRBool posixval = PR_TRUE;
  697. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  698. "--> _pre_ds_mod_user_cb -- begin\n");
  699. if ((NULL == rawentry) || (NULL == ad_entry) || (NULL == ds_entry)) {
  700. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  701. "<-- _pre_ds_mod_user_cb -- Empty %s entry.\n",
  702. (NULL==rawentry)?"rawentry":(NULL==ad_entry)?"ad entry":"ds entry");
  703. return;
  704. }
  705. if (posix_winsync_config_get_msSFUSchema())
  706. attr_map = user_mssfu_attribute_map;
  707. /* check all of the required attributes are in the ad_entry:
  708. * MUST (cn $ uid $ uidNumber $ gidNumber $ homeDirectory).
  709. * If any of the required attributes are missing, drop them before adding
  710. * the entry to the DS. */
  711. for (i = 0; attr_map[i].windows_attribute_name != NULL; i++) {
  712. Slapi_Attr *pa_attr;
  713. if (attr_map[i].isMUST &&
  714. slapi_entry_attr_find(ad_entry,
  715. attr_map[i].windows_attribute_name,
  716. &pa_attr)) {
  717. /* required attribute does not exist */
  718. posixval = PR_FALSE;
  719. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  720. "AD entry %s does not have required attribute %s for posixAccount objectclass.\n",
  721. slapi_entry_get_dn_const(ad_entry),
  722. attr_map[i].ldap_attribute_name);
  723. }
  724. }
  725. /* add objectclass: posixAccount, uidnumber ,gidnumber ,homeDirectory, loginshell */
  726. /* in the ad to ds case we have no changelog, so we have to compare the entries */
  727. for (rc = slapi_entry_first_attr(ad_entry, &attr); rc == 0;
  728. rc = slapi_entry_next_attr(ad_entry, attr, &attr)) {
  729. char *type = NULL;
  730. slapi_attr_get_type(attr, &type);
  731. for (i = 0; attr_map[i].windows_attribute_name != NULL; i++) {
  732. if (0 == slapi_attr_type_cmp(type, attr_map[i].windows_attribute_name,
  733. SLAPI_TYPE_CMP_SUBTYPE)) {
  734. Slapi_Attr *local_attr = NULL;
  735. char *local_type = NULL;
  736. Slapi_ValueSet *vs = NULL;
  737. slapi_attr_get_valueset(attr, &vs);
  738. local_type = slapi_ch_strdup(attr_map[i].ldap_attribute_name);
  739. slapi_entry_attr_find(ds_entry, local_type, &local_attr);
  740. is_present_local = (NULL == local_attr) ? 0 : 1;
  741. if (is_present_local) {
  742. /* DS entry has the posix attrs.
  743. * I.e., it is a posix account*/
  744. int values_equal = 0;
  745. posixval = PR_TRUE;
  746. values_equal = attr_compare_equal(attr, local_attr);
  747. if (!values_equal) {
  748. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  749. "_pre_ds_mod_user_cb -- update mods: %s, %s : values are different -> modify\n",
  750. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  751. local_type);
  752. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, local_type,
  753. valueset_get_valuearray(vs));
  754. *do_modify = 1;
  755. }
  756. } else if (posixval) {
  757. /* only if AD provides the all necessary attributes */
  758. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, local_type,
  759. valueset_get_valuearray(vs));
  760. *do_modify = do_modify_local = 1;
  761. }
  762. slapi_valueset_free(vs);
  763. slapi_ch_free((void**) &local_type);
  764. /* what about if delete all values on windows ????? */
  765. }
  766. }
  767. }
  768. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  769. "<-- _pre_ds_mod_user_cb present %d modify %d isPosixaccount %s\n",
  770. is_present_local, do_modify_local,
  771. posixval?"yes":"no");
  772. if (!is_present_local && do_modify_local && posixval) {
  773. Slapi_Attr *oc_attr = NULL;
  774. Slapi_Value *voc = slapi_value_new();
  775. slapi_value_init_string(voc, "posixAccount");
  776. rc = slapi_entry_attr_find(ds_entry, "objectClass", &oc_attr);
  777. if (rc == 0) {
  778. const struct berval *bv = slapi_value_get_berval(voc);
  779. if (bv && slapi_attr_value_find(oc_attr, bv) != 0) {
  780. Slapi_ValueSet *oc_vs = slapi_valueset_new();
  781. Slapi_Value *oc_nv = slapi_value_new();
  782. slapi_attr_get_valueset(oc_attr, &oc_vs);
  783. slapi_value_init_string(oc_nv, "posixAccount");
  784. slapi_valueset_add_value(oc_vs, oc_nv);
  785. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  786. "<-- _pre_ds_mod_user_cb add oc:posixAccount\n");
  787. slapi_value_init_string(voc, "shadowAccount");
  788. if (slapi_attr_value_find(oc_attr, slapi_value_get_berval(voc)) != 0) {
  789. Slapi_Value *oc_nv = slapi_value_new();
  790. slapi_value_init_string(oc_nv, "shadowAccount");
  791. slapi_valueset_add_value(oc_vs, oc_nv);
  792. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  793. "<-- _pre_ds_mod_user_cb add oc:shadowAccount\n");
  794. }
  795. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, "objectClass",
  796. valueset_get_valuearray(oc_vs));
  797. slapi_value_free(&oc_nv);
  798. slapi_valueset_free(oc_vs);
  799. if (posix_winsync_config_get_mapNestedGrouping()) {
  800. memberUidLock();
  801. addUserToGroupMembership(ds_entry);
  802. memberUidUnlock();
  803. }
  804. }
  805. }
  806. slapi_value_free(&voc);
  807. }
  808. sync_acct_disable(cbdata, rawentry, ds_entry, ACCT_DISABLE_TO_DS, NULL, smods, do_modify);
  809. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_mod_user_cb %s %s\n",
  810. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)), (do_modify) ? "modified"
  811. : "not modified");
  812. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  813. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  814. slapi_mod_dump(mod, 0);
  815. }
  816. }
  817. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_mod_user_cb -- end\n");
  818. return;
  819. }
  820. static void
  821. posix_winsync_pre_ds_mod_group_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  822. Slapi_Entry *ds_entry, Slapi_Mods *smods, int *do_modify)
  823. {
  824. LDAPMod* mod = NULL;
  825. Slapi_Attr *attr = NULL;
  826. int is_present_local = 0;
  827. int do_modify_local = 0;
  828. int rc;
  829. windows_attribute_map *attr_map = group_attribute_map;
  830. if (posix_winsync_config_get_msSFUSchema())
  831. attr_map = group_mssfu_attribute_map;
  832. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  833. "--> _pre_ds_mod_group_cb -- begin\n");
  834. /* in the ad to ds case we have no changelog, so we have to compare the entries */
  835. for (rc = slapi_entry_first_attr(ad_entry, &attr); rc == 0; rc
  836. = slapi_entry_next_attr(ad_entry, attr, &attr)) {
  837. char *type = NULL;
  838. Slapi_ValueSet *vs = NULL;
  839. size_t i = 0;
  840. slapi_attr_get_type(attr, &type);
  841. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  842. if (0 == slapi_attr_type_cmp(type, attr_map[i].windows_attribute_name,
  843. SLAPI_TYPE_CMP_SUBTYPE)) {
  844. Slapi_Attr *local_attr = NULL;
  845. char *local_type = NULL;
  846. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "1.\n");
  847. slapi_attr_get_valueset(attr, &vs);
  848. local_type = slapi_ch_strdup(attr_map[i].ldap_attribute_name);
  849. slapi_entry_attr_find(ds_entry, local_type, &local_attr);
  850. is_present_local = (NULL == local_attr) ? 0 : 1;
  851. if (is_present_local) {
  852. int values_equal = 0;
  853. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "2.\n");
  854. values_equal = attr_compare_equal(attr, local_attr);
  855. if (!values_equal) {
  856. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  857. "_pre_ds_mod_group_cb -- update mods: %s, %s : values are different -> modify\n",
  858. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  859. local_type);
  860. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, local_type,
  861. valueset_get_valuearray(vs));
  862. *do_modify = 1;
  863. }
  864. } else {
  865. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "3.\n");
  866. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, local_type,
  867. valueset_get_valuearray(vs));
  868. *do_modify = do_modify_local = 1;
  869. }
  870. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "4.\n");
  871. slapi_ch_free((void**) &local_type);
  872. slapi_valueset_free(vs);
  873. /* what about if delete all values on windows ???? */
  874. }
  875. }
  876. }
  877. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  878. "_pre_ds_mod_group_cb present %d modify %d before\n", is_present_local,
  879. do_modify_local);
  880. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  881. "_pre_ds_mod_group_cb present %d modify %d\n", is_present_local,
  882. do_modify_local);
  883. if (!is_present_local && do_modify_local) {
  884. Slapi_Attr *oc_attr = NULL;
  885. Slapi_Value *voc = slapi_value_new();
  886. slapi_value_init_string(voc, "posixGroup");
  887. slapi_entry_attr_find(ds_entry, "objectClass", &oc_attr);
  888. if (slapi_attr_value_find(oc_attr, slapi_value_get_berval(voc)) != 0) {
  889. Slapi_ValueSet *oc_vs = NULL;
  890. Slapi_Value *oc_nv = slapi_value_new();
  891. slapi_attr_get_valueset(oc_attr, &oc_vs);
  892. slapi_value_init_string(oc_nv, "posixGroup");
  893. slapi_valueset_add_value(oc_vs, oc_nv);
  894. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  895. "_pre_ds_mod_group_cb add oc:posixGroup\n");
  896. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, "objectClass",
  897. valueset_get_valuearray(oc_vs));
  898. slapi_value_free(&oc_nv);
  899. slapi_valueset_free(oc_vs);
  900. }
  901. slapi_value_free(&voc);
  902. }
  903. if (posix_winsync_config_get_mapMemberUid() || posix_winsync_config_get_mapNestedGrouping()) {
  904. memberUidLock();
  905. modGroupMembership(ds_entry, smods, do_modify, do_modify_local);
  906. memberUidUnlock();
  907. }
  908. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "_pre_ds_mod_group_cb step\n");
  909. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  910. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  911. slapi_mod_dump(mod, 0);
  912. }
  913. }
  914. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  915. "<-- _pre_ds_mod_group_cb -- end\n");
  916. return;
  917. }
  918. static void
  919. posix_winsync_pre_ds_add_user_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  920. Slapi_Entry *ds_entry)
  921. {
  922. Slapi_Attr *attr = NULL;
  923. char *type = NULL;
  924. PRBool posixval = PR_TRUE;
  925. windows_attribute_map *attr_map = user_attribute_map;
  926. int i = 0;
  927. if (posix_winsync_config_get_msSFUSchema())
  928. attr_map = user_mssfu_attribute_map;
  929. /* add objectclass: posixAccount, uidnumber, gidnumber, homeDirectory, loginShell */
  930. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  931. "--> _pre_ds_add_user_cb -- begin\n");
  932. /* check all of the required attributes are in the ad_entry:
  933. * MUST (cn $ uid $ uidNumber $ gidNumber $ homeDirectory).
  934. * If any of the required attributes are missing, drop them before adding
  935. * the entry to the DS. */
  936. for (i = 0; attr_map[i].windows_attribute_name != NULL; i++) {
  937. Slapi_Attr *pa_attr;
  938. if (attr_map[i].isMUST &&
  939. slapi_entry_attr_find(ad_entry,
  940. attr_map[i].windows_attribute_name,
  941. &pa_attr)) {
  942. /* required attribute does not exist */
  943. posixval = PR_FALSE;
  944. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  945. "AD entry %s does not have required attribute %s for posixAccount objectclass.\n",
  946. slapi_entry_get_dn_const(ad_entry),
  947. attr_map[i].ldap_attribute_name);
  948. }
  949. }
  950. /* converts the AD attributes to DS posix attribute if all the posix
  951. * required attributes are available */
  952. if (posixval) {
  953. int rc;
  954. for (slapi_entry_first_attr(ad_entry, &attr); attr;
  955. slapi_entry_next_attr(ad_entry, attr, &attr)) {
  956. slapi_attr_get_type(attr, &type);
  957. if (!type) {
  958. continue;
  959. }
  960. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  961. "--> _pre_ds_add_user_cb -- "
  962. "look for [%s] to new entry [%s]\n",
  963. type, slapi_entry_get_dn_const(ds_entry));
  964. for (i = 0; attr_map[i].windows_attribute_name != NULL; i++) {
  965. if (slapi_attr_type_cmp(attr_map[i].windows_attribute_name,
  966. type, SLAPI_TYPE_CMP_SUBTYPE) == 0) {
  967. Slapi_ValueSet *svs = NULL;
  968. slapi_attr_get_valueset(attr, &svs);
  969. slapi_entry_add_valueset(ds_entry,
  970. attr_map[i].ldap_attribute_name, svs);
  971. slapi_valueset_free(svs);
  972. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  973. "--> _pre_ds_add_user_cb -- "
  974. "adding val for [%s] to new entry [%s]\n",
  975. type, slapi_entry_get_dn_const(ds_entry));
  976. }
  977. }
  978. }
  979. rc = slapi_entry_add_string(ds_entry, "objectClass", "posixAccount");
  980. rc |= slapi_entry_add_string(ds_entry, "objectClass", "shadowAccount");
  981. rc |= slapi_entry_add_string(ds_entry, "objectClass", "inetUser");
  982. if (rc != 0) {
  983. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  984. "<-- _pre_ds_add_user_cb -- adding objectclass for new entry failed %d\n",
  985. rc);
  986. } else {
  987. if (posix_winsync_config_get_mapNestedGrouping()) {
  988. memberUidLock();
  989. addUserToGroupMembership(ds_entry);
  990. memberUidUnlock();
  991. }
  992. }
  993. }
  994. sync_acct_disable(cbdata, rawentry, ds_entry, ACCT_DISABLE_TO_DS, ds_entry, NULL, NULL);
  995. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_add_user_cb -- end\n");
  996. return;
  997. }
  998. static void
  999. posix_winsync_pre_ds_add_group_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  1000. Slapi_Entry *ds_entry)
  1001. {
  1002. Slapi_Attr *attr = NULL;
  1003. char *type = NULL;
  1004. PRBool posixval = PR_FALSE;
  1005. windows_attribute_map *attr_map = group_attribute_map;
  1006. if (posix_winsync_config_get_msSFUSchema())
  1007. attr_map = group_mssfu_attribute_map;
  1008. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1009. "--> posix_winsync_pre_ds_add_group_cb -- begin\n");
  1010. for (slapi_entry_first_attr(ad_entry, &attr); attr; slapi_entry_next_attr(ad_entry, attr, &attr)) {
  1011. size_t i = 0;
  1012. slapi_attr_get_type(attr, &type);
  1013. if (!type) {
  1014. continue;
  1015. }
  1016. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "--> _pre_ds_add_group_cb -- "
  1017. "look for [%s] to new entry [%s]\n", type, slapi_entry_get_dn_const(ds_entry));
  1018. for (i = 0; attr_map && attr_map[i].windows_attribute_name != NULL; i++) {
  1019. if (slapi_attr_type_cmp(attr_map[i].windows_attribute_name, type,
  1020. SLAPI_TYPE_CMP_SUBTYPE) == 0) {
  1021. Slapi_ValueSet *svs = NULL;
  1022. slapi_attr_get_valueset(attr, &svs);
  1023. slapi_entry_add_valueset(ds_entry, attr_map[i].ldap_attribute_name, svs);
  1024. slapi_valueset_free(svs);
  1025. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1026. "--> _pre_ds_add_group_cb -- "
  1027. "adding val for [%s] to new entry [%s]\n", type,
  1028. slapi_entry_get_dn_const(ds_entry));
  1029. posixval = PR_TRUE;
  1030. }
  1031. }
  1032. }
  1033. if (posixval) {
  1034. int rc;
  1035. rc = slapi_entry_add_string(ds_entry, "objectClass", "posixGroup");
  1036. if (rc != 0) {
  1037. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1038. "<-- _pre_ds_add_group_cb -- adding objectclass for new entry failed %d\n",
  1039. rc);
  1040. }
  1041. }
  1042. if (posix_winsync_config_get_mapMemberUid() || posix_winsync_config_get_mapNestedGrouping()) {
  1043. memberUidLock();
  1044. addGroupMembership(ds_entry, ad_entry);
  1045. memberUidUnlock();
  1046. }
  1047. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1048. "<-- posix_winsync_pre_ds_add_group_cb -- end\n");
  1049. return;
  1050. }
  1051. static void
  1052. posix_winsync_get_new_ds_user_dn_cb(void *cbdata, const Slapi_Entry *rawentry,
  1053. Slapi_Entry *ad_entry, char **new_dn_string, const Slapi_DN *ds_suffix,
  1054. const Slapi_DN *ad_suffix)
  1055. {
  1056. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1057. "--> posix_winsync_get_new_ds_user_dn_cb -- old dn [%s] -- begin\n",
  1058. *new_dn_string);
  1059. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1060. "<-- posix_winsync_get_new_ds_user_dn_cb -- new dn [%s] -- end\n",
  1061. *new_dn_string);
  1062. return;
  1063. }
  1064. static void
  1065. posix_winsync_get_new_ds_group_dn_cb(void *cbdata, const Slapi_Entry *rawentry,
  1066. Slapi_Entry *ad_entry, char **new_dn_string, const Slapi_DN *ds_suffix,
  1067. const Slapi_DN *ad_suffix)
  1068. {
  1069. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1070. "--> posix_winsync_get_new_ds_group_dn_cb -- begin\n");
  1071. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1072. "<-- posix_winsync_get_new_ds_group_dn_cb -- end\n");
  1073. return;
  1074. }
  1075. static void
  1076. posix_winsync_pre_ad_mod_user_mods_cb(void *cbdata, const Slapi_Entry *rawentry,
  1077. const Slapi_DN *local_dn, const Slapi_Entry *ds_entry, LDAPMod * const *origmods,
  1078. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  1079. {
  1080. Slapi_Mods *smods = slapi_mods_new();
  1081. Slapi_Mods *new_smods = slapi_mods_new();
  1082. LDAPMod *mod = NULL;
  1083. windows_attribute_map *attr_map = user_attribute_map;
  1084. if (posix_winsync_config_get_msSFUSchema())
  1085. attr_map = user_mssfu_attribute_map;
  1086. /* mod if changed objectclass: posixAccount, uidnumber, gidnumber, homeDirectory, loginShell */
  1087. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1088. "--> _pre_ad_mod_user_mods_cb -- begin DS account [%s] \n",
  1089. slapi_entry_get_dn_const(ds_entry));
  1090. /* wrap the modstosend in a Slapi_Mods for convenience */
  1091. slapi_mods_init_passin(new_smods, *modstosend);
  1092. slapi_mods_init_byref(smods, (LDAPMod**) origmods);
  1093. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  1094. size_t i = 0;
  1095. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1096. "_pre_ad_mod_user_mods_cb -- check modify type %s\n", mod->mod_type);
  1097. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  1098. if (0 == slapi_attr_type_cmp(mod->mod_type, attr_map[i].ldap_attribute_name,
  1099. SLAPI_TYPE_CMP_SUBTYPE)) {
  1100. Slapi_Mod *mysmod = slapi_mod_new();
  1101. slapi_mod_init_byval(mysmod, mod);
  1102. slapi_mod_set_type(mysmod, attr_map[i].windows_attribute_name);
  1103. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(mysmod));
  1104. slapi_mod_free(&mysmod);
  1105. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1106. "_pre_ad_mod_user_mods_cb -- add modify %s DS account [%s]\n",
  1107. attr_map[i].windows_attribute_name,
  1108. slapi_entry_get_dn_const(ds_entry));
  1109. if (0 == slapi_attr_type_cmp(mod->mod_type, "uidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  1110. Slapi_Mod *ocsmod = slapi_mod_new();
  1111. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1112. "_pre_ad_mod_user_mods_cb -- add NisDomain\n");
  1113. addNisDomainName(ocsmod, ds_entry);
  1114. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(ocsmod));
  1115. slapi_mod_free(&ocsmod);
  1116. }
  1117. }
  1118. }
  1119. if (0 == slapi_attr_type_cmp(mod->mod_type, "nsRoleDN", SLAPI_TYPE_CMP_SUBTYPE)) {
  1120. int dummy = 0;
  1121. sync_acct_disable(cbdata, rawentry, (Slapi_Entry *) ds_entry, ACCT_DISABLE_TO_AD, NULL,
  1122. new_smods, &dummy);
  1123. }
  1124. }
  1125. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  1126. for (mod = slapi_mods_get_first_mod(new_smods); mod; mod
  1127. = slapi_mods_get_next_mod(new_smods)) {
  1128. slapi_mod_dump(mod, 0);
  1129. }
  1130. }
  1131. *modstosend = slapi_mods_get_ldapmods_passout(new_smods);
  1132. slapi_mods_free(&smods);
  1133. slapi_mods_free(&new_smods);
  1134. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1135. "<-- _pre_ad_mod_user_mods_cb -- end\n");
  1136. return;
  1137. }
  1138. static void
  1139. posix_winsync_pre_ad_mod_group_mods_cb(void *cbdata, const Slapi_Entry *rawentry,
  1140. const Slapi_DN *local_dn, const Slapi_Entry *ds_entry, LDAPMod * const *origmods,
  1141. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  1142. {
  1143. Slapi_Mods *smods = slapi_mods_new();
  1144. Slapi_Mods *new_smods = slapi_mods_new();
  1145. LDAPMod *mod = NULL;
  1146. windows_attribute_map *attr_map = group_attribute_map;
  1147. if (posix_winsync_config_get_msSFUSchema())
  1148. attr_map = group_mssfu_attribute_map;
  1149. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1150. "--> _pre_ad_mod_group_mods_cb -- begin\n");
  1151. /* wrap the modstosend in a Slapi_Mods for convenience */
  1152. slapi_mods_init_passin(new_smods, *modstosend);
  1153. slapi_mods_init_byref(smods, (LDAPMod**) origmods);
  1154. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  1155. size_t i = 0;
  1156. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1157. "_pre_ad_mod_group_mods_cb -- check modify type %s\n", mod->mod_type);
  1158. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  1159. if (0 == slapi_attr_type_cmp(mod->mod_type, attr_map[i].ldap_attribute_name,
  1160. SLAPI_TYPE_CMP_SUBTYPE)) {
  1161. Slapi_Mod *mysmod = slapi_mod_new();
  1162. if (mod->mod_op & LDAP_MOD_DELETE) {
  1163. slapi_mod_init(mysmod, 0);
  1164. slapi_mod_set_operation(mysmod, LDAP_MOD_DELETE | LDAP_MOD_BVALUES);
  1165. slapi_mod_set_type(mysmod, attr_map[i].windows_attribute_name);
  1166. } else {
  1167. slapi_mod_init_byval(mysmod, mod);
  1168. slapi_mod_set_type(mysmod, attr_map[i].windows_attribute_name);
  1169. if (0 == slapi_attr_type_cmp(mod->mod_type, "gidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  1170. Slapi_Mod *ocsmod = slapi_mod_new();
  1171. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1172. "_pre_ad_mod_group_mods_cb -- add NisDomain\n");
  1173. addNisDomainName(ocsmod, ds_entry);
  1174. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(ocsmod));
  1175. slapi_mod_free(&ocsmod);
  1176. }
  1177. }
  1178. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(mysmod));
  1179. slapi_mod_free(&mysmod);
  1180. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1181. "_pre_ad_mod_group_mods_cb -- add modify %s DS account [%s]\n",
  1182. attr_map[i].windows_attribute_name,
  1183. slapi_entry_get_dn_const(ds_entry));
  1184. }
  1185. }
  1186. }
  1187. *modstosend = slapi_mods_get_ldapmods_passout(new_smods);
  1188. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  1189. for (mod = slapi_mods_get_first_mod(new_smods); mod;
  1190. mod = slapi_mods_get_next_mod(new_smods)) {
  1191. slapi_mod_dump(mod, 0);
  1192. }
  1193. }
  1194. slapi_mods_free(&smods);
  1195. slapi_mods_free(&new_smods);
  1196. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1197. "<-- _pre_ad_mod_group_mods_cb -- end\n");
  1198. return;
  1199. }
  1200. static int
  1201. posix_winsync_can_add_entry_to_ad_cb(void *cbdata, const Slapi_Entry *local_entry,
  1202. const Slapi_DN *remote_dn)
  1203. {
  1204. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1205. "--> posix_winsync_can_add_entry_to_ad_cb -- begin\n");
  1206. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1207. "<-- posix_winsync_can_add_entry_to_ad_cb -- end\n");
  1208. return 1; /* false - do not allow entries to be added to ad */
  1209. }
  1210. static void
  1211. posix_winsync_begin_update_cb(void *cbdata, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree,
  1212. int is_total)
  1213. {
  1214. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1215. "--> posix_winsync_begin_update_cb -- begin\n");
  1216. posix_winsync_config_reset_MOFTaskCreated();
  1217. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1218. "<-- posix_winsync_begin_update_cb -- end\n");
  1219. return;
  1220. }
  1221. static void
  1222. posix_winsync_end_update_cb(void *cbdata, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree,
  1223. int is_total)
  1224. {
  1225. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1226. "--> posix_winsync_end_update_cb -- begin %d %d\n",
  1227. posix_winsync_config_get_MOFTaskCreated(),
  1228. posix_winsync_config_get_createMOFTask());
  1229. if (1 && posix_winsync_config_get_createMOFTask()) {
  1230. /* add a task to schedule memberof Plugin for fix memebrof attributs */
  1231. Slapi_PBlock *pb = slapi_pblock_new();
  1232. Slapi_Entry *e_task = slapi_entry_alloc();
  1233. int rc = 0;
  1234. char *dn = slapi_create_dn_string("cn=%s,cn=%s,cn=tasks,cn=config",
  1235. posix_winsync_plugin_name, MEMBEROFTASK);
  1236. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1237. "--> posix_winsync_end_update_cb, create task %s\n", dn);
  1238. if (NULL == dn) {
  1239. slapi_pblock_destroy(pb);
  1240. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1241. "posix_winsync_end_update_cb: "
  1242. "failed to create task dn: cn=%s,%s,cn=tasks,cn=config\n",
  1243. posix_winsync_plugin_name, MEMBEROFTASK);
  1244. return;
  1245. }
  1246. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1247. "--> posix_winsync_end_update_cb, init'ing task\n");
  1248. slapi_entry_init(e_task, slapi_ch_strdup(dn), NULL);
  1249. slapi_entry_add_string(e_task, "cn", slapi_ch_strdup(posix_winsync_plugin_name));
  1250. slapi_entry_add_string(e_task, "objectClass", "extensibleObject");
  1251. slapi_entry_add_string(e_task, "basedn", slapi_sdn_get_dn(ds_subtree));
  1252. slapi_add_entry_internal_set_pb(pb, e_task, NULL, posix_winsync_get_plugin_identity(), 0);
  1253. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1254. "--> posix_winsync_end_update_cb, adding task\n");
  1255. slapi_add_internal_pb(pb);
  1256. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1257. "--> posix_winsync_end_update_cb, retrieving return code\n");
  1258. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  1259. if (LDAP_ALREADY_EXISTS == rc) {
  1260. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1261. "posix_winsync_end_update_cb: "
  1262. "task entry %s already exists\n",
  1263. posix_winsync_plugin_name);
  1264. } else if (rc != 0) {
  1265. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1266. "posix_winsync_end_update_cb: "
  1267. "failed to add task entry (%d)\n", rc);
  1268. } else {
  1269. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1270. "posix_winsync_end_update_cb: "
  1271. "add task entry\n");
  1272. }
  1273. /* slapi_entry_free(e_task); */
  1274. slapi_pblock_destroy(pb);
  1275. pb = NULL;
  1276. posix_winsync_config_reset_MOFTaskCreated();
  1277. }
  1278. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1279. "<-- posix_winsync_end_update_cb -- end\n");
  1280. return;
  1281. }
  1282. static void
  1283. posix_winsync_destroy_agmt_cb(void *cbdata, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree)
  1284. {
  1285. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1286. "--> posix_winsync_destroy_agmt_cb -- begin\n");
  1287. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1288. "<-- posix_winsync_destroy_agmt_cb -- end\n");
  1289. return;
  1290. }
  1291. static void
  1292. posix_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)
  1293. {
  1294. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1295. "--> posix_winsync_post_ad_mod_user_cb -- begin\n");
  1296. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1297. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1298. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1299. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1300. #endif
  1301. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1302. "<-- posix_winsync_post_ad_mod_user_cb -- end\n");
  1303. return;
  1304. }
  1305. static void
  1306. posix_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)
  1307. {
  1308. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1309. "--> posix_winsync_post_ad_mod_group_cb -- begin\n");
  1310. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1311. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1312. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1313. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1314. #endif
  1315. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1316. "<-- posix_winsync_post_ad_mod_group_cb -- end\n");
  1317. return;
  1318. }
  1319. static void
  1320. posix_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)
  1321. {
  1322. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1323. "--> posix_winsync_post_ds_mod_user_cb -- begin\n");
  1324. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1325. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1326. "Result of modifying DS entry [%s] was [%d:%s]\n",
  1327. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1328. #endif
  1329. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1330. "<-- posix_winsync_post_ds_mod_user_cb -- end\n");
  1331. return;
  1332. }
  1333. static void
  1334. posix_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)
  1335. {
  1336. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1337. "--> posix_winsync_post_ds_mod_group_cb -- begin\n");
  1338. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1339. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1340. "Result of modifying DS entry [%s] was [%d:%s]\n",
  1341. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1342. #endif
  1343. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1344. "<-- posix_winsync_post_ds_mod_group_cb -- end\n");
  1345. return;
  1346. }
  1347. static void
  1348. posix_winsync_post_ds_add_user_cb(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  1349. {
  1350. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1351. "--> posix_winsync_post_ds_add_user_cb -- begin\n");
  1352. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1353. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1354. "Result of adding DS entry [%s] was [%d:%s]\n",
  1355. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1356. #endif
  1357. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1358. "<-- posix_winsync_post_ds_add_user_cb -- end\n");
  1359. return;
  1360. }
  1361. static void
  1362. posix_winsync_post_ds_add_group_cb(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  1363. {
  1364. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1365. "--> posix_winsync_post_ds_add_group_cb -- begin\n");
  1366. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1367. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1368. "Result of adding DS entry [%s] was [%d:%s]\n",
  1369. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1370. #endif
  1371. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1372. "<-- posix_winsync_post_ds_add_group_cb -- end\n");
  1373. return;
  1374. }
  1375. /* winsync_plugin_call_pre_ad_add_user_cb(prp->agmt, mapped_entry, e); */
  1376. static void
  1377. posix_winsync_pre_ad_add_user_cb(void *cookie, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry)
  1378. {
  1379. Slapi_Attr * obj_attr = NULL; /* Entry attributes */
  1380. windows_attribute_map *attr_map=user_attribute_map;
  1381. int rc = 0;
  1382. if(posix_winsync_config_get_msSFUSchema())
  1383. attr_map=user_mssfu_attribute_map;
  1384. /* if ds_entry has oc posixAccount add uidnumber, gidnumber, homeDirectory, loginShell, gecos */
  1385. /* syncing/mapping of nsaccountlock -> userAccountControl will already done by the normal Win Sync-Service */
  1386. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1387. "--> _pre_ad_add_user_cb -- begin DS account [%s] \n", slapi_entry_get_dn_const(ds_entry));
  1388. rc = slapi_entry_attr_find(ds_entry, "objectclass", &obj_attr);
  1389. if (rc == 0) { /* Found objectclasses, so... */
  1390. int i;
  1391. Slapi_Value * value = NULL; /* Attribute values */
  1392. slapi_log_error( SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,"_pre_ad_add_user_cb -- test objectclass posixAccount\n");
  1393. for (
  1394. i = slapi_attr_first_value(obj_attr, &value);
  1395. i != -1;
  1396. i = slapi_attr_next_value(obj_attr, i, &value)
  1397. ) {
  1398. const char * oc = NULL;
  1399. oc = slapi_value_get_string(value);
  1400. slapi_log_error( SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,"_pre_ad_add_user_cb -- oc: %s \n", oc);
  1401. if (strncasecmp(oc,"posixAccount",13)==0){ /* entry has objectclass posixAccount */
  1402. Slapi_Attr *attr = NULL;
  1403. char *nisdomainname = getNisDomainName(ds_entry);
  1404. for (rc = slapi_entry_first_attr(ds_entry, &attr); attr && (rc == 0);
  1405. rc = slapi_entry_next_attr(ds_entry, attr, &attr))
  1406. {
  1407. char *type = NULL;
  1408. size_t i = 0;
  1409. slapi_attr_get_type( attr, &type );
  1410. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1411. "_pre_ad_add_user_cb -- check add attr: %s\n", type);
  1412. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  1413. if (0 == slapi_attr_type_cmp(type,attr_map[i].ldap_attribute_name, SLAPI_TYPE_CMP_SUBTYPE)){
  1414. Slapi_ValueSet *vs = NULL;
  1415. slapi_attr_get_valueset(attr,&vs);
  1416. slapi_entry_add_valueset(ad_entry, attr_map[i].windows_attribute_name, vs);
  1417. slapi_valueset_free(vs);
  1418. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1419. "--> _pre_ad_add_user_cb -- "
  1420. "adding val for [%s] to new entry [%s]\n",
  1421. type, slapi_entry_get_dn_const(ad_entry));
  1422. }
  1423. }
  1424. }
  1425. if (nisdomainname) {
  1426. slapi_entry_add_value(ad_entry,
  1427. "msSFU30NisDomain", slapi_value_new_string(nisdomainname));
  1428. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1429. "--> _pre_ad_add_user_cb -- "
  1430. "adding val for [%s] to new entry [%s]\n",
  1431. "msSFU30NisDomain", nisdomainname);
  1432. slapi_ch_free_string(&nisdomainname);
  1433. }
  1434. }
  1435. }
  1436. }
  1437. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1438. "<-- _pre_ad_add_user_cb -- end\n");
  1439. return;
  1440. }
  1441. static void
  1442. posix_winsync_pre_ad_add_group_cb(void *cookie, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry)
  1443. {
  1444. Slapi_Attr * obj_attr = NULL; /* Entry attributes */
  1445. windows_attribute_map *attr_map = group_attribute_map;
  1446. int rc = 0;
  1447. if (posix_winsync_config_get_msSFUSchema()) {
  1448. attr_map=group_mssfu_attribute_map;
  1449. }
  1450. /* if ds_entry has oc posixGroup add gidnumber, ... */
  1451. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1452. "--> _pre_ad_add_group_cb -- begin DS account [%s] \n", slapi_entry_get_dn_const(ds_entry));
  1453. rc = slapi_entry_attr_find(ds_entry, "objectclass", &obj_attr);
  1454. if (rc == 0) { /* Found objectclasses, so... */
  1455. int i;
  1456. Slapi_Value * value = NULL; /* Attribute values */
  1457. slapi_log_error( SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,"_pre_ad_add_group_cb -- test objectclass posixGroup\n");
  1458. for (i = slapi_attr_first_value(obj_attr, &value);
  1459. i != -1;
  1460. i = slapi_attr_next_value(obj_attr, i, &value)) {
  1461. const char * oc = NULL;
  1462. oc = slapi_value_get_string(value);
  1463. if (strncasecmp(oc,"posixGroup",11)==0){ /* entry has objectclass posixGroup */
  1464. Slapi_Attr *attr = NULL;
  1465. char *nisdomainname = getNisDomainName(ds_entry);
  1466. for (rc = slapi_entry_first_attr(ds_entry, &attr); rc == 0;
  1467. rc = slapi_entry_next_attr(ds_entry, attr, &attr))
  1468. {
  1469. char *type = NULL;
  1470. int j = 0;
  1471. slapi_attr_get_type( attr, &type );
  1472. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1473. "_pre_ad_add_group_cb -- check add attr: %s\n", type);
  1474. for (j = 0; attr_map && attr_map[j].windows_attribute_name != NULL; j++) {
  1475. if (0 == slapi_attr_type_cmp(type,attr_map[j].ldap_attribute_name, SLAPI_TYPE_CMP_SUBTYPE)){
  1476. Slapi_ValueSet *vs = NULL;
  1477. slapi_attr_get_valueset(attr,&vs);
  1478. slapi_entry_add_valueset(ad_entry, attr_map[j].windows_attribute_name, vs);
  1479. slapi_valueset_free(vs);
  1480. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1481. "--> _pre_ad_add_group_cb -- "
  1482. "adding val for [%s] to new entry [%s]\n",
  1483. type, slapi_entry_get_dn_const(ad_entry));
  1484. }
  1485. }
  1486. }
  1487. if (nisdomainname) {
  1488. slapi_entry_add_value(ad_entry, "msSFU30NisDomain", slapi_value_new_string(nisdomainname));
  1489. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1490. "--> _pre_ad_add_group_cb -- "
  1491. "adding val for [%s] to new entry [%s]\n",
  1492. "msSFU30NisDomain", nisdomainname);
  1493. slapi_ch_free_string(&nisdomainname);
  1494. }
  1495. }
  1496. }
  1497. }
  1498. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1499. "<-- _pre_ad_add_group_cb -- end\n");
  1500. return;
  1501. }
  1502. static void
  1503. posix_winsync_post_ad_add_user_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry, int *result)
  1504. {
  1505. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1506. "--> posix_winsync_post_ad_add_user_cb -- begin\n");
  1507. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1508. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1509. "Result of adding AD entry [%s] was [%d:%s]\n",
  1510. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1511. #endif
  1512. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1513. "<-- posix_winsync_post_ad_add_user_cb -- end\n");
  1514. return;
  1515. }
  1516. static void
  1517. posix_winsync_post_ad_add_group_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry, int *result)
  1518. {
  1519. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1520. "--> posix_winsync_post_ad_add_group_cb -- begin\n");
  1521. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1522. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1523. "Result of adding AD entry [%s] was [%d:%s]\n",
  1524. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1525. #endif
  1526. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1527. "<-- posix_winsync_post_ad_add_group_cb -- end\n");
  1528. return;
  1529. }
  1530. static void
  1531. posix_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)
  1532. {
  1533. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1534. "--> posix_winsync_post_ad_mod_user_mods_cb -- begin\n");
  1535. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1536. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1537. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1538. slapi_sdn_get_dn(remote_dn), *result, ldap_err2string(*result));
  1539. #endif
  1540. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1541. "<-- posix_winsync_post_ad_mod_user_mods_cb -- end\n");
  1542. return;
  1543. }
  1544. static void
  1545. posix_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)
  1546. {
  1547. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1548. "--> posix_winsync_post_ad_mod_group_mods_cb -- begin\n");
  1549. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1550. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1551. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1552. slapi_sdn_get_dn(remote_dn), *result, ldap_err2string(*result));
  1553. #endif
  1554. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1555. "<-- posix_winsync_post_ad_mod_group_mods_cb -- end\n");
  1556. return;
  1557. }
  1558. #define DEFAULT_PRECEDENCE 25
  1559. static int precedence = DEFAULT_PRECEDENCE; /* default */
  1560. static int posix_winsync_precedence(void)
  1561. {
  1562. return precedence;
  1563. }
  1564. static void *posix_winsync_api[] = { NULL, /* reserved for api broker use, must be zero */
  1565. posix_winsync_agmt_init,
  1566. posix_winsync_dirsync_search_params_cb,
  1567. posix_winsync_pre_ad_search_cb,
  1568. posix_winsync_pre_ds_search_entry_cb,
  1569. posix_winsync_pre_ds_search_all_cb,
  1570. posix_winsync_pre_ad_mod_user_cb,
  1571. posix_winsync_pre_ad_mod_group_cb,
  1572. posix_winsync_pre_ds_mod_user_cb,
  1573. posix_winsync_pre_ds_mod_group_cb,
  1574. posix_winsync_pre_ds_add_user_cb,
  1575. posix_winsync_pre_ds_add_group_cb,
  1576. posix_winsync_get_new_ds_user_dn_cb,
  1577. posix_winsync_get_new_ds_group_dn_cb,
  1578. posix_winsync_pre_ad_mod_user_mods_cb,
  1579. posix_winsync_pre_ad_mod_group_mods_cb,
  1580. posix_winsync_can_add_entry_to_ad_cb,
  1581. posix_winsync_begin_update_cb,
  1582. posix_winsync_end_update_cb,
  1583. posix_winsync_destroy_agmt_cb,
  1584. posix_winsync_post_ad_mod_user_cb,
  1585. posix_winsync_post_ad_mod_group_cb,
  1586. posix_winsync_post_ds_mod_user_cb,
  1587. posix_winsync_post_ds_mod_group_cb,
  1588. posix_winsync_post_ds_add_user_cb,
  1589. posix_winsync_post_ds_add_group_cb,
  1590. posix_winsync_pre_ad_add_user_cb,
  1591. posix_winsync_pre_ad_add_group_cb,
  1592. posix_winsync_post_ad_add_user_cb,
  1593. posix_winsync_post_ad_add_group_cb,
  1594. posix_winsync_post_ad_mod_user_mods_cb,
  1595. posix_winsync_post_ad_mod_group_mods_cb,
  1596. posix_winsync_precedence
  1597. };
  1598. static Slapi_ComponentId *posix_winsync_plugin_id = NULL;
  1599. /*
  1600. ** Plugin identity mgmt
  1601. */
  1602. void
  1603. posix_winsync_set_plugin_identity(void * identity)
  1604. {
  1605. posix_winsync_plugin_id = identity;
  1606. }
  1607. void *
  1608. posix_winsync_get_plugin_identity()
  1609. {
  1610. return posix_winsync_plugin_id;
  1611. }
  1612. static int
  1613. posix_winsync_plugin_start(Slapi_PBlock *pb)
  1614. {
  1615. int rc;
  1616. Slapi_Entry *config_e = NULL; /* entry containing plugin config */
  1617. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1618. "--> posix_winsync_plugin_start -- begin\n");
  1619. if (slapi_apib_register(WINSYNC_v3_0_GUID, posix_winsync_api)) {
  1620. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1621. "<-- posix_winsync_plugin_start -- failed to register winsync api -- end\n");
  1622. return -1;
  1623. }
  1624. if (slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &config_e) != 0) {
  1625. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name, "missing config entry\n");
  1626. return (-1);
  1627. }
  1628. if ((rc = posix_winsync_config(config_e)) != LDAP_SUCCESS) {
  1629. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name, "configuration failed (%s)\n",
  1630. ldap_err2string(rc));
  1631. return (-1);
  1632. }
  1633. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1634. "<-- posix_winsync_plugin_start -- registered; end\n");
  1635. return 0;
  1636. }
  1637. static int
  1638. posix_winsync_plugin_close(Slapi_PBlock *pb)
  1639. {
  1640. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1641. "--> posix_winsync_plugin_close -- begin\n");
  1642. slapi_apib_unregister(WINSYNC_v1_0_GUID);
  1643. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1644. "<-- posix_winsync_plugin_close -- end\n");
  1645. return 0;
  1646. }
  1647. /* this is the slapi plugin init function,
  1648. not the one used by the winsync api
  1649. */
  1650. int
  1651. posix_winsync_plugin_init(Slapi_PBlock *pb)
  1652. {
  1653. void *plugin_id = NULL;
  1654. Slapi_Entry *confige = NULL;
  1655. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1656. "--> posix_winsync_plugin_init -- begin\n");
  1657. if (slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &confige) && confige) {
  1658. precedence = slapi_entry_attr_get_int(confige, "nsslapd-pluginprecedence");
  1659. if (!precedence) {
  1660. precedence = DEFAULT_PRECEDENCE;
  1661. }
  1662. }
  1663. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0
  1664. || slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN, (void *) posix_winsync_plugin_start) != 0
  1665. || slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN, (void *) posix_winsync_plugin_close) != 0
  1666. || slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *) &posix_winsync_pdesc) != 0) {
  1667. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1668. "<-- posix_winsync_plugin_init -- failed to register plugin -- end\n");
  1669. return -1;
  1670. }
  1671. /* Retrieve and save the plugin identity to later pass to
  1672. internal operations */
  1673. if (slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &plugin_id) != 0) {
  1674. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1675. "<-- posix_winsync_plugin_init -- failed to retrieve plugin identity -- end\n");
  1676. return -1;
  1677. }
  1678. posix_winsync_set_plugin_identity(plugin_id);
  1679. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1680. "<-- posix_winsync_plugin_init -- end\n");
  1681. return 0;
  1682. }