posix-winsync.c 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801
  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. static int
  358. addNisDomainName(Slapi_Mod *smod, const Slapi_Entry *ds_entry)
  359. {
  360. Slapi_Entry *entry = NULL;
  361. char *type_NisDomain = "nisDomain";
  362. Slapi_PBlock * pb;
  363. int rc = -1;
  364. char* nisdomainname = NULL;
  365. Slapi_DN* entry_sdn = slapi_entry_get_sdn((Slapi_Entry *) ds_entry);
  366. Slapi_DN* subtree_sdn = slapi_sdn_new();
  367. Slapi_DN *childparent = slapi_sdn_new();
  368. struct berval **vals;
  369. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "addNisDomainName start DN:%s\n",
  370. slapi_sdn_get_dn(entry_sdn));
  371. slapi_sdn_get_parent(entry_sdn, subtree_sdn);
  372. pb = slapi_pblock_new();
  373. do {
  374. Slapi_Attr *attr = NULL;
  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. rc = slapi_entry_attr_find(entry, type_NisDomain, &attr);
  386. if (attr) {
  387. rc = slapi_attr_get_bervals_copy(attr, &vals);
  388. break;
  389. } else {
  390. rc = LDAP_NO_SUCH_ATTRIBUTE;
  391. }
  392. }
  393. }
  394. slapi_sdn_copy(childparent, subtree_sdn);
  395. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  396. "addNisDomainName 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) {
  402. slapi_log_error(SLAPI_LOG_REPL, posix_winsync_plugin_name,
  403. "addNisDomainName: no nisdomainname found in %s, LDAP Err%d\n",
  404. slapi_sdn_get_dn(subtree_sdn), rc);
  405. } else {
  406. slapi_mod_init(smod, 1);
  407. slapi_mod_set_type(smod, "msSFU30NisDomain");
  408. slapi_mod_set_operation(smod, LDAP_MOD_REPLACE | LDAP_MOD_BVALUES);
  409. slapi_mod_add_value(smod, vals[0]);
  410. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  411. "addNisDomainName NisDomain %s found in DN:%s\n", vals[0]->bv_val,
  412. slapi_sdn_get_dn(childparent));
  413. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN))
  414. slapi_mod_dump((LDAPMod*) slapi_mod_get_ldapmod_byref(smod), 0);
  415. ber_bvecfree(vals);
  416. }
  417. slapi_sdn_free(&childparent);
  418. slapi_entry_free(entry);
  419. entry = NULL;
  420. slapi_sdn_free(&subtree_sdn);
  421. slapi_ch_free_string(&nisdomainname);
  422. return rc;
  423. }
  424. static void
  425. posix_winsync_dirsync_search_params_cb(void *cbdata, const char *agmt_dn, char **base, int *scope,
  426. char **filter, char ***attrs, LDAPControl ***serverctrls)
  427. {
  428. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  429. "--> posix_winsync_dirsync_search_params_cb -- begin\n");
  430. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  431. "<-- posix_winsync_dirsync_search_params_cb -- end\n");
  432. return;
  433. }
  434. /* called before searching for a single entry from AD - agmt_dn will be NULL */
  435. static void
  436. posix_winsync_pre_ad_search_cb(void *cbdata, const char *agmt_dn, char **base, int *scope,
  437. char **filter, char ***attrs, LDAPControl ***serverctrls)
  438. {
  439. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  440. "--> posix_winsync_pre_ad_search_cb -- begin\n");
  441. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  442. "<-- posix_winsync_pre_ad_search_cb -- end\n");
  443. return;
  444. }
  445. /* called before an internal search to get a single DS entry - agmt_dn will be NULL */
  446. static void
  447. posix_winsync_pre_ds_search_entry_cb(void *cbdata, const char *agmt_dn, char **base, int *scope,
  448. char **filter, char ***attrs, LDAPControl ***serverctrls)
  449. {
  450. /*
  451. char *tmpbase=slapi_ch_strdup(*base);
  452. char *d = *base;
  453. char *s = tmpbase;
  454. int i=0;
  455. */
  456. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "--> _pre_ds_search_cb -- begin\n");
  457. /* skip the first subtree container ou=xyz, */
  458. /* if (strlen(*base) > 3) {
  459. s++;
  460. while(*s !='\0'){
  461. if (((*(s) == ',') || (*(s) == ';' )) && (*((s)-1) != '\\')){
  462. s++;
  463. while(*s !='\0'){
  464. *d++ = *s++;
  465. }
  466. *d='\0';
  467. break;
  468. }
  469. s++;
  470. }
  471. }
  472. */
  473. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  474. "-- _pre_ds_search_cb - base [%s] "
  475. "scope [%d] filter [%s]\n", *base, *scope, *filter);
  476. /* slapi_ch_free_string(&tmpbase); */
  477. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_search_cb -- end\n");
  478. return;
  479. }
  480. /* called before the total update to get all entries from the DS to sync to AD */
  481. static void
  482. posix_winsync_pre_ds_search_all_cb(void *cbdata, const char *agmt_dn, char **base, int *scope,
  483. char **filter, char ***attrs, LDAPControl ***serverctrls)
  484. {
  485. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  486. "--> posix_winsync_pre_ds_search_all_cb -- orig filter [%s] -- begin\n",
  487. ((filter && *filter) ? *filter : "NULL"));
  488. /* slapi_ch_free_string(filter);
  489. *filter = slapi_ch_strdup("(|(objectclass=posixaccount)(objectclass=posixgroup))");
  490. */
  491. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  492. "<-- posix_winsync_pre_ds_search_all_cb -- end\n");
  493. return;
  494. }
  495. static void
  496. posix_winsync_pre_ad_mod_user_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  497. Slapi_Entry *ds_entry, Slapi_Mods *smods, int *do_modify)
  498. {
  499. LDAPMod *mod = NULL;
  500. int rc = 0;
  501. Slapi_Attr *attr = NULL;
  502. windows_attribute_map *attr_map = user_attribute_map;
  503. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  504. "--> posix_winsync_pre_ad_mod_user_cb -- begin DS account [%s]\n",
  505. slapi_entry_get_dn_const(ds_entry));
  506. if (posix_winsync_config_get_msSFUSchema()) {
  507. attr_map = user_mssfu_attribute_map;
  508. }
  509. /* called if init Replica: add nisDomain, uidnumber, ... if avail */
  510. for (rc = slapi_entry_first_attr(ds_entry, &attr); rc == 0;
  511. rc = slapi_entry_next_attr(ds_entry, attr, &attr)) {
  512. char *type = NULL;
  513. size_t i = 0;
  514. slapi_attr_get_type(attr, &type);
  515. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  516. "_pre_ad_mod_user_cb -- check modify type %s\n", type);
  517. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  518. if (0 == slapi_attr_type_cmp(type, attr_map[i].ldap_attribute_name,
  519. SLAPI_TYPE_CMP_SUBTYPE)) {
  520. Slapi_Attr *ad_attr = NULL;
  521. Slapi_ValueSet *vs = NULL;
  522. char *ad_type = NULL;
  523. int is_present_local;
  524. slapi_attr_get_valueset(attr, &vs);
  525. ad_type = slapi_ch_strdup(attr_map[i].windows_attribute_name);
  526. slapi_entry_attr_find(ad_entry, ad_type, &ad_attr);
  527. is_present_local = (NULL == ad_attr) ? 0 : 1;
  528. if (is_present_local) {
  529. int values_equal = 0;
  530. values_equal = attr_compare_equal(attr, ad_attr);
  531. if (!values_equal) {
  532. slapi_log_error(
  533. SLAPI_LOG_PLUGIN,
  534. posix_winsync_plugin_name,
  535. "_pre_ad_mod_user_cb -- update mods: %s, %s : values are different -> modify\n",
  536. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  537. ad_type);
  538. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, ad_type,
  539. valueset_get_valuearray(vs));
  540. *do_modify = 1;
  541. }
  542. } else {
  543. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, ad_type,
  544. valueset_get_valuearray(vs));
  545. if (0 == slapi_attr_type_cmp(type, "uidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  546. Slapi_Mod *mysmod = slapi_mod_new();
  547. addNisDomainName(mysmod, ds_entry);
  548. slapi_mods_add_ldapmod(smods, slapi_mod_get_ldapmod_passout(mysmod));
  549. slapi_mod_free(&mysmod);
  550. }
  551. *do_modify = 1;
  552. }
  553. slapi_ch_free((void**) &ad_type);
  554. slapi_valueset_free(vs);
  555. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  556. "_pre_ad_mod_user_cb -- add modify %s DS account [%s]\n",
  557. attr_map[i].windows_attribute_name,
  558. slapi_entry_get_dn_const(ds_entry));
  559. }
  560. }
  561. if (0 == slapi_attr_type_cmp(type, "nsAccountLock", SLAPI_TYPE_CMP_SUBTYPE))
  562. sync_acct_disable(cbdata, rawentry, ds_entry, ACCT_DISABLE_TO_AD, NULL, smods,
  563. do_modify);
  564. }
  565. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  566. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  567. slapi_mod_dump(mod, 0);
  568. }
  569. }
  570. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  571. "<-- posix_winsync_pre_ad_mod_user_cb -- end\n");
  572. return;
  573. }
  574. static void
  575. posix_winsync_pre_ad_mod_group_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  576. Slapi_Entry *ds_entry, Slapi_Mods *smods, int *do_modify)
  577. {
  578. LDAPMod *mod = NULL;
  579. int rc = 0;
  580. Slapi_Attr *attr = NULL;
  581. windows_attribute_map *attr_map = group_attribute_map;
  582. if (posix_winsync_config_get_msSFUSchema())
  583. attr_map = group_mssfu_attribute_map;
  584. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  585. "--> _pre_ad_mod_group_cb -- begin DS account [%s]\n",
  586. slapi_entry_get_dn_const(ds_entry));
  587. /* called if init Replica: add nisDomain, gidnumber, memberuid, if avail */
  588. for (rc = slapi_entry_first_attr(ds_entry, &attr); rc == 0;
  589. rc = slapi_entry_next_attr(ds_entry, attr, &attr)) {
  590. char *type = NULL;
  591. size_t i = 0;
  592. slapi_attr_get_type(attr, &type);
  593. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  594. "_pre_ad_mod_group_cb -- check modify type %s\n", type);
  595. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  596. if (0 == slapi_attr_type_cmp(type, attr_map[i].ldap_attribute_name,
  597. SLAPI_TYPE_CMP_SUBTYPE)) {
  598. Slapi_Attr *ad_attr = NULL;
  599. Slapi_ValueSet *vs = NULL;
  600. char *ad_type = NULL;
  601. int is_present_local;
  602. if (i == 0) { /* memberUid */
  603. Slapi_Attr *dsmuid_attr = NULL;
  604. Slapi_Value *v = NULL;
  605. slapi_entry_attr_find(ds_entry, "dsonlymemberuid", &dsmuid_attr);
  606. if (dsmuid_attr) {
  607. Slapi_ValueSet *dsmuid_vs = NULL;
  608. slapi_attr_get_valueset(dsmuid_attr, &dsmuid_vs);
  609. if (dsmuid_vs) {
  610. vs = slapi_valueset_new();
  611. int j;
  612. for (j = slapi_attr_first_value(attr, &v); j != -1;
  613. j = slapi_attr_next_value(attr, i, &v)) {
  614. if (!slapi_valueset_find(dsmuid_attr, dsmuid_vs, v)) {
  615. slapi_valueset_add_value(vs, v);
  616. }
  617. }
  618. slapi_valueset_free(dsmuid_vs); dsmuid_vs = NULL;
  619. }
  620. }
  621. }
  622. if (!vs) {
  623. slapi_attr_get_valueset(attr, &vs);
  624. }
  625. ad_type = slapi_ch_strdup(attr_map[i].windows_attribute_name);
  626. slapi_entry_attr_find(ad_entry, ad_type, &ad_attr);
  627. is_present_local = (NULL == ad_attr) ? 0 : 1;
  628. if (is_present_local) {
  629. int values_equal = 0;
  630. values_equal = attr_compare_equal(attr, ad_attr);
  631. if (!values_equal) {
  632. slapi_log_error(
  633. SLAPI_LOG_PLUGIN,
  634. posix_winsync_plugin_name,
  635. "_pre_ad_mod_group_cb -- update mods: %s, %s : values are different -> modify\n",
  636. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  637. ad_type);
  638. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, ad_type,
  639. valueset_get_valuearray(vs));
  640. *do_modify = 1;
  641. }
  642. } else {
  643. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, ad_type,
  644. valueset_get_valuearray(vs));
  645. if (0 == slapi_attr_type_cmp(type, "gidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  646. Slapi_Mod *mysmod = slapi_mod_new();
  647. addNisDomainName(mysmod, ds_entry);
  648. slapi_mods_add_ldapmod(smods, slapi_mod_get_ldapmod_passout(mysmod));
  649. slapi_mod_free(&mysmod);
  650. }
  651. *do_modify = 1;
  652. }
  653. slapi_ch_free((void**) &ad_type);
  654. slapi_valueset_free(vs);
  655. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  656. "_pre_ad_mod_group_cb -- add modify %s DS account [%s]\n",
  657. attr_map[i].windows_attribute_name,
  658. slapi_entry_get_dn_const(ds_entry));
  659. }
  660. }
  661. }
  662. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "_pre_ad_mod_group_cb -- step\n");
  663. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  664. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  665. slapi_mod_dump(mod, 0);
  666. }
  667. }
  668. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  669. "<-- _pre_ad_mod_group_cb -- end\n");
  670. return;
  671. }
  672. static void
  673. posix_winsync_pre_ds_mod_user_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  674. Slapi_Entry *ds_entry, Slapi_Mods *smods, int *do_modify)
  675. {
  676. LDAPMod* mod = NULL;
  677. Slapi_Attr *attr = NULL;
  678. int is_present_local = 0;
  679. int do_modify_local = 0;
  680. int rc;
  681. int i;
  682. windows_attribute_map *attr_map = user_attribute_map;
  683. PRBool posixval = PR_TRUE;
  684. if (posix_winsync_config_get_msSFUSchema())
  685. attr_map = user_mssfu_attribute_map;
  686. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  687. "--> _pre_ds_mod_user_cb -- begin\n");
  688. /* check all of the required attributes are in the ad_entry:
  689. * MUST (cn $ uid $ uidNumber $ gidNumber $ homeDirectory).
  690. * If any of the required attributes are missing, drop them before adding
  691. * the entry to the DS. */
  692. for (i = 0; attr_map[i].windows_attribute_name != NULL; i++) {
  693. Slapi_Attr *pa_attr;
  694. if (attr_map[i].isMUST &&
  695. slapi_entry_attr_find(ad_entry,
  696. attr_map[i].windows_attribute_name,
  697. &pa_attr)) {
  698. /* required attribute does not exist */
  699. posixval = PR_FALSE;
  700. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  701. "AD entry %s does not have required attribute %s for posixAccount objectclass.\n",
  702. slapi_entry_get_dn_const(ad_entry),
  703. attr_map[i].ldap_attribute_name);
  704. }
  705. }
  706. /* add objectclass: posixAccount, uidnumber ,gidnumber ,homeDirectory, loginshell */
  707. /* in the ad to ds case we have no changelog, so we have to compare the entries */
  708. for (rc = slapi_entry_first_attr(ad_entry, &attr); rc == 0;
  709. rc = slapi_entry_next_attr(ad_entry, attr, &attr)) {
  710. char *type = NULL;
  711. slapi_attr_get_type(attr, &type);
  712. for (i = 0; attr_map[i].windows_attribute_name != NULL; i++) {
  713. if (0 == slapi_attr_type_cmp(type, attr_map[i].windows_attribute_name,
  714. SLAPI_TYPE_CMP_SUBTYPE)) {
  715. Slapi_Attr *local_attr = NULL;
  716. char *local_type = NULL;
  717. Slapi_ValueSet *vs = NULL;
  718. slapi_attr_get_valueset(attr, &vs);
  719. local_type = slapi_ch_strdup(attr_map[i].ldap_attribute_name);
  720. slapi_entry_attr_find(ds_entry, local_type, &local_attr);
  721. is_present_local = (NULL == local_attr) ? 0 : 1;
  722. if (is_present_local) {
  723. /* DS entry has the posix attrs.
  724. * I.e., it is a posix account*/
  725. int values_equal = 0;
  726. posixval = PR_TRUE;
  727. values_equal = attr_compare_equal(attr, local_attr);
  728. if (!values_equal) {
  729. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  730. "_pre_ds_mod_user_cb -- update mods: %s, %s : values are different -> modify\n",
  731. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  732. local_type);
  733. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, local_type,
  734. valueset_get_valuearray(vs));
  735. *do_modify = 1;
  736. }
  737. } else if (posixval) {
  738. /* only if AD provides the all necessary attributes */
  739. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, local_type,
  740. valueset_get_valuearray(vs));
  741. *do_modify = do_modify_local = 1;
  742. }
  743. slapi_valueset_free(vs);
  744. slapi_ch_free((void**) &local_type);
  745. /* what about if delete all values on windows ????? */
  746. }
  747. }
  748. }
  749. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  750. "<-- _pre_ds_mod_user_cb present %d modify %d isPosixaccount %s\n",
  751. is_present_local, do_modify_local,
  752. posixval?"yes":"no");
  753. if (!is_present_local && do_modify_local && posixval) {
  754. Slapi_Attr *oc_attr = NULL;
  755. Slapi_Value *voc = slapi_value_new();
  756. slapi_value_init_string(voc, "posixAccount");
  757. rc = slapi_entry_attr_find(ds_entry, "objectClass", &oc_attr);
  758. if (rc == 0) {
  759. const struct berval *bv = slapi_value_get_berval(voc);
  760. if (bv && slapi_attr_value_find(oc_attr, bv) != 0) {
  761. Slapi_ValueSet *oc_vs = slapi_valueset_new();
  762. Slapi_Value *oc_nv = slapi_value_new();
  763. slapi_attr_get_valueset(oc_attr, &oc_vs);
  764. slapi_value_init_string(oc_nv, "posixAccount");
  765. slapi_valueset_add_value(oc_vs, oc_nv);
  766. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  767. "<-- _pre_ds_mod_user_cb add oc:posixAccount\n");
  768. slapi_value_init_string(voc, "shadowAccount");
  769. if (slapi_attr_value_find(oc_attr, slapi_value_get_berval(voc)) != 0) {
  770. Slapi_Value *oc_nv = slapi_value_new();
  771. slapi_value_init_string(oc_nv, "shadowAccount");
  772. slapi_valueset_add_value(oc_vs, oc_nv);
  773. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  774. "<-- _pre_ds_mod_user_cb add oc:shadowAccount\n");
  775. }
  776. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, "objectClass",
  777. valueset_get_valuearray(oc_vs));
  778. slapi_value_free(&oc_nv);
  779. slapi_valueset_free(oc_vs);
  780. if (posix_winsync_config_get_mapNestedGrouping()) {
  781. memberUidLock();
  782. addUserToGroupMembership(ds_entry);
  783. memberUidUnlock();
  784. }
  785. }
  786. }
  787. slapi_value_free(&voc);
  788. }
  789. sync_acct_disable(cbdata, rawentry, ds_entry, ACCT_DISABLE_TO_DS, NULL, smods, do_modify);
  790. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_mod_user_cb %s %s\n",
  791. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)), (do_modify) ? "modified"
  792. : "not modified");
  793. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  794. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  795. slapi_mod_dump(mod, 0);
  796. }
  797. }
  798. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_mod_user_cb -- end\n");
  799. return;
  800. }
  801. static void
  802. posix_winsync_pre_ds_mod_group_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  803. Slapi_Entry *ds_entry, Slapi_Mods *smods, int *do_modify)
  804. {
  805. LDAPMod* mod = NULL;
  806. Slapi_Attr *attr = NULL;
  807. int is_present_local = 0;
  808. int do_modify_local = 0;
  809. int rc;
  810. windows_attribute_map *attr_map = group_attribute_map;
  811. if (posix_winsync_config_get_msSFUSchema())
  812. attr_map = group_mssfu_attribute_map;
  813. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  814. "--> _pre_ds_mod_group_cb -- begin\n");
  815. /* in the ad to ds case we have no changelog, so we have to compare the entries */
  816. for (rc = slapi_entry_first_attr(ad_entry, &attr); rc == 0; rc
  817. = slapi_entry_next_attr(ad_entry, attr, &attr)) {
  818. char *type = NULL;
  819. Slapi_ValueSet *vs = NULL;
  820. size_t i = 0;
  821. slapi_attr_get_type(attr, &type);
  822. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  823. if (0 == slapi_attr_type_cmp(type, attr_map[i].windows_attribute_name,
  824. SLAPI_TYPE_CMP_SUBTYPE)) {
  825. Slapi_Attr *local_attr = NULL;
  826. char *local_type = NULL;
  827. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "1.\n");
  828. slapi_attr_get_valueset(attr, &vs);
  829. local_type = slapi_ch_strdup(attr_map[i].ldap_attribute_name);
  830. slapi_entry_attr_find(ds_entry, local_type, &local_attr);
  831. is_present_local = (NULL == local_attr) ? 0 : 1;
  832. if (is_present_local) {
  833. int values_equal = 0;
  834. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "2.\n");
  835. values_equal = attr_compare_equal(attr, local_attr);
  836. if (!values_equal) {
  837. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  838. "_pre_ds_mod_group_cb -- update mods: %s, %s : values are different -> modify\n",
  839. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  840. local_type);
  841. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, local_type,
  842. valueset_get_valuearray(vs));
  843. *do_modify = 1;
  844. }
  845. } else {
  846. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "3.\n");
  847. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, local_type,
  848. valueset_get_valuearray(vs));
  849. *do_modify = do_modify_local = 1;
  850. }
  851. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "4.\n");
  852. slapi_ch_free((void**) &local_type);
  853. slapi_valueset_free(vs);
  854. /* what about if delete all values on windows ???? */
  855. }
  856. }
  857. }
  858. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  859. "_pre_ds_mod_group_cb present %d modify %d before\n", is_present_local,
  860. do_modify_local);
  861. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  862. "_pre_ds_mod_group_cb present %d modify %d\n", is_present_local,
  863. do_modify_local);
  864. if (!is_present_local && do_modify_local) {
  865. Slapi_Attr *oc_attr = NULL;
  866. Slapi_Value *voc = slapi_value_new();
  867. slapi_value_init_string(voc, "posixGroup");
  868. slapi_entry_attr_find(ds_entry, "objectClass", &oc_attr);
  869. if (slapi_attr_value_find(oc_attr, slapi_value_get_berval(voc)) != 0) {
  870. Slapi_ValueSet *oc_vs = NULL;
  871. Slapi_Value *oc_nv = slapi_value_new();
  872. slapi_attr_get_valueset(oc_attr, &oc_vs);
  873. slapi_value_init_string(oc_nv, "posixGroup");
  874. slapi_valueset_add_value(oc_vs, oc_nv);
  875. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  876. "_pre_ds_mod_group_cb add oc:posixGroup\n");
  877. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, "objectClass",
  878. valueset_get_valuearray(oc_vs));
  879. slapi_value_free(&oc_nv);
  880. slapi_valueset_free(oc_vs);
  881. }
  882. slapi_value_free(&voc);
  883. }
  884. if (posix_winsync_config_get_mapMemberUid() || posix_winsync_config_get_mapNestedGrouping()) {
  885. memberUidLock();
  886. modGroupMembership(ds_entry, smods, do_modify, do_modify_local);
  887. memberUidUnlock();
  888. }
  889. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "_pre_ds_mod_group_cb step\n");
  890. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  891. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  892. slapi_mod_dump(mod, 0);
  893. }
  894. }
  895. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  896. "<-- _pre_ds_mod_group_cb -- end\n");
  897. return;
  898. }
  899. static void
  900. posix_winsync_pre_ds_add_user_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  901. Slapi_Entry *ds_entry)
  902. {
  903. Slapi_Attr *attr = NULL;
  904. char *type = NULL;
  905. PRBool posixval = PR_TRUE;
  906. windows_attribute_map *attr_map = user_attribute_map;
  907. int i = 0;
  908. if (posix_winsync_config_get_msSFUSchema())
  909. attr_map = user_mssfu_attribute_map;
  910. /* add objectclass: posixAccount, uidnumber, gidnumber, homeDirectory, loginShell */
  911. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  912. "--> _pre_ds_add_user_cb -- begin\n");
  913. /* check all of the required attributes are in the ad_entry:
  914. * MUST (cn $ uid $ uidNumber $ gidNumber $ homeDirectory).
  915. * If any of the required attributes are missing, drop them before adding
  916. * the entry to the DS. */
  917. for (i = 0; attr_map[i].windows_attribute_name != NULL; i++) {
  918. Slapi_Attr *pa_attr;
  919. if (attr_map[i].isMUST &&
  920. slapi_entry_attr_find(ad_entry,
  921. attr_map[i].windows_attribute_name,
  922. &pa_attr)) {
  923. /* required attribute does not exist */
  924. posixval = PR_FALSE;
  925. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  926. "AD entry %s does not have required attribute %s for posixAccount objectclass.\n",
  927. slapi_entry_get_dn_const(ad_entry),
  928. attr_map[i].ldap_attribute_name);
  929. }
  930. }
  931. /* converts the AD attributes to DS posix attribute if all the posix
  932. * required attributes are available */
  933. if (posixval) {
  934. int rc;
  935. for (slapi_entry_first_attr(ad_entry, &attr); attr;
  936. slapi_entry_next_attr(ad_entry, attr, &attr)) {
  937. slapi_attr_get_type(attr, &type);
  938. if (!type) {
  939. continue;
  940. }
  941. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  942. "--> _pre_ds_add_user_cb -- "
  943. "look for [%s] to new entry [%s]\n",
  944. type, slapi_entry_get_dn_const(ds_entry));
  945. for (i = 0; attr_map[i].windows_attribute_name != NULL; i++) {
  946. if (slapi_attr_type_cmp(attr_map[i].windows_attribute_name,
  947. type, SLAPI_TYPE_CMP_SUBTYPE) == 0) {
  948. Slapi_ValueSet *svs = NULL;
  949. slapi_attr_get_valueset(attr, &svs);
  950. slapi_entry_add_valueset(ds_entry,
  951. attr_map[i].ldap_attribute_name, svs);
  952. slapi_valueset_free(svs);
  953. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  954. "--> _pre_ds_add_user_cb -- "
  955. "adding val for [%s] to new entry [%s]\n",
  956. type, slapi_entry_get_dn_const(ds_entry));
  957. }
  958. }
  959. }
  960. rc = slapi_entry_add_string(ds_entry, "objectClass", "posixAccount");
  961. rc |= slapi_entry_add_string(ds_entry, "objectClass", "shadowAccount");
  962. rc |= slapi_entry_add_string(ds_entry, "objectClass", "inetUser");
  963. if (rc != 0) {
  964. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  965. "<-- _pre_ds_add_user_cb -- adding objectclass for new entry failed %d\n",
  966. rc);
  967. } else {
  968. if (posix_winsync_config_get_mapNestedGrouping()) {
  969. memberUidLock();
  970. addUserToGroupMembership(ds_entry);
  971. memberUidUnlock();
  972. }
  973. }
  974. }
  975. sync_acct_disable(cbdata, rawentry, ds_entry, ACCT_DISABLE_TO_DS, ds_entry, NULL, NULL);
  976. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_add_user_cb -- end\n");
  977. return;
  978. }
  979. static void
  980. posix_winsync_pre_ds_add_group_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  981. Slapi_Entry *ds_entry)
  982. {
  983. Slapi_Attr *attr = NULL;
  984. char *type = NULL;
  985. PRBool posixval = PR_FALSE;
  986. windows_attribute_map *attr_map = group_attribute_map;
  987. if (posix_winsync_config_get_msSFUSchema())
  988. attr_map = group_mssfu_attribute_map;
  989. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  990. "--> posix_winsync_pre_ds_add_group_cb -- begin\n");
  991. for (slapi_entry_first_attr(ad_entry, &attr); attr; slapi_entry_next_attr(ad_entry, attr, &attr)) {
  992. size_t i = 0;
  993. slapi_attr_get_type(attr, &type);
  994. if (!type) {
  995. continue;
  996. }
  997. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "--> _pre_ds_add_group_cb -- "
  998. "look for [%s] to new entry [%s]\n", type, slapi_entry_get_dn_const(ds_entry));
  999. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  1000. if (slapi_attr_type_cmp(attr_map[i].windows_attribute_name, type,
  1001. SLAPI_TYPE_CMP_SUBTYPE) == 0) {
  1002. Slapi_ValueSet *svs = NULL;
  1003. slapi_attr_get_valueset(attr, &svs);
  1004. slapi_entry_add_valueset(ds_entry, attr_map[i].ldap_attribute_name, svs);
  1005. slapi_valueset_free(svs);
  1006. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1007. "--> _pre_ds_add_group_cb -- "
  1008. "adding val for [%s] to new entry [%s]\n", type,
  1009. slapi_entry_get_dn_const(ds_entry));
  1010. posixval = PR_TRUE;
  1011. }
  1012. }
  1013. }
  1014. if (posixval) {
  1015. int rc;
  1016. rc = slapi_entry_add_string(ds_entry, "objectClass", "posixGroup");
  1017. if (rc != 0) {
  1018. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1019. "<-- _pre_ds_add_group_cb -- adding objectclass for new entry failed %d\n",
  1020. rc);
  1021. }
  1022. }
  1023. if (posix_winsync_config_get_mapMemberUid() || posix_winsync_config_get_mapNestedGrouping()) {
  1024. memberUidLock();
  1025. addGroupMembership(ds_entry, ad_entry);
  1026. memberUidUnlock();
  1027. }
  1028. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1029. "<-- posix_winsync_pre_ds_add_group_cb -- end\n");
  1030. return;
  1031. }
  1032. static void
  1033. posix_winsync_get_new_ds_user_dn_cb(void *cbdata, const Slapi_Entry *rawentry,
  1034. Slapi_Entry *ad_entry, char **new_dn_string, const Slapi_DN *ds_suffix,
  1035. const Slapi_DN *ad_suffix)
  1036. {
  1037. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1038. "--> posix_winsync_get_new_ds_user_dn_cb -- old dn [%s] -- begin\n",
  1039. *new_dn_string);
  1040. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1041. "<-- posix_winsync_get_new_ds_user_dn_cb -- new dn [%s] -- end\n",
  1042. *new_dn_string);
  1043. return;
  1044. }
  1045. static void
  1046. posix_winsync_get_new_ds_group_dn_cb(void *cbdata, const Slapi_Entry *rawentry,
  1047. Slapi_Entry *ad_entry, char **new_dn_string, const Slapi_DN *ds_suffix,
  1048. const Slapi_DN *ad_suffix)
  1049. {
  1050. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1051. "--> posix_winsync_get_new_ds_group_dn_cb -- begin\n");
  1052. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1053. "<-- posix_winsync_get_new_ds_group_dn_cb -- end\n");
  1054. return;
  1055. }
  1056. static void
  1057. posix_winsync_pre_ad_mod_user_mods_cb(void *cbdata, const Slapi_Entry *rawentry,
  1058. const Slapi_DN *local_dn, const Slapi_Entry *ds_entry, LDAPMod * const *origmods,
  1059. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  1060. {
  1061. Slapi_Mods *smods = slapi_mods_new();
  1062. Slapi_Mods *new_smods = slapi_mods_new();
  1063. LDAPMod *mod = NULL;
  1064. windows_attribute_map *attr_map = user_attribute_map;
  1065. if (posix_winsync_config_get_msSFUSchema())
  1066. attr_map = user_mssfu_attribute_map;
  1067. /* mod if changed objectclass: posixAccount, uidnumber, gidnumber, homeDirectory, loginShell */
  1068. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1069. "--> _pre_ad_mod_user_mods_cb -- begin DS account [%s] \n",
  1070. slapi_entry_get_dn_const(ds_entry));
  1071. /* wrap the modstosend in a Slapi_Mods for convenience */
  1072. slapi_mods_init_passin(new_smods, *modstosend);
  1073. slapi_mods_init_byref(smods, (LDAPMod**) origmods);
  1074. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  1075. size_t i = 0;
  1076. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1077. "_pre_ad_mod_user_mods_cb -- check modify type %s\n", mod->mod_type);
  1078. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  1079. if (0 == slapi_attr_type_cmp(mod->mod_type, attr_map[i].ldap_attribute_name,
  1080. SLAPI_TYPE_CMP_SUBTYPE)) {
  1081. Slapi_Mod *mysmod = slapi_mod_new();
  1082. slapi_mod_init_byval(mysmod, mod);
  1083. slapi_mod_set_type(mysmod, attr_map[i].windows_attribute_name);
  1084. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(mysmod));
  1085. slapi_mod_free(&mysmod);
  1086. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1087. "_pre_ad_mod_user_mods_cb -- add modify %s DS account [%s]\n",
  1088. attr_map[i].windows_attribute_name,
  1089. slapi_entry_get_dn_const(ds_entry));
  1090. if (0 == slapi_attr_type_cmp(mod->mod_type, "uidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  1091. Slapi_Mod *ocsmod = slapi_mod_new();
  1092. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1093. "_pre_ad_mod_user_mods_cb -- add NisDomain\n");
  1094. addNisDomainName(ocsmod, ds_entry);
  1095. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(ocsmod));
  1096. slapi_mod_free(&ocsmod);
  1097. }
  1098. }
  1099. }
  1100. if (0 == slapi_attr_type_cmp(mod->mod_type, "nsRoleDN", SLAPI_TYPE_CMP_SUBTYPE)) {
  1101. int dummy = 0;
  1102. sync_acct_disable(cbdata, rawentry, (Slapi_Entry *) ds_entry, ACCT_DISABLE_TO_AD, NULL,
  1103. new_smods, &dummy);
  1104. }
  1105. }
  1106. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  1107. for (mod = slapi_mods_get_first_mod(new_smods); mod; mod
  1108. = slapi_mods_get_next_mod(new_smods)) {
  1109. slapi_mod_dump(mod, 0);
  1110. }
  1111. }
  1112. *modstosend = slapi_mods_get_ldapmods_passout(new_smods);
  1113. slapi_mods_free(&smods);
  1114. slapi_mods_free(&new_smods);
  1115. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1116. "<-- _pre_ad_mod_user_mods_cb -- end\n");
  1117. return;
  1118. }
  1119. static void
  1120. posix_winsync_pre_ad_mod_group_mods_cb(void *cbdata, const Slapi_Entry *rawentry,
  1121. const Slapi_DN *local_dn, const Slapi_Entry *ds_entry, LDAPMod * const *origmods,
  1122. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  1123. {
  1124. Slapi_Mods *smods = slapi_mods_new();
  1125. Slapi_Mods *new_smods = slapi_mods_new();
  1126. LDAPMod *mod = NULL;
  1127. windows_attribute_map *attr_map = group_attribute_map;
  1128. if (posix_winsync_config_get_msSFUSchema())
  1129. attr_map = group_mssfu_attribute_map;
  1130. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1131. "--> _pre_ad_mod_group_mods_cb -- begin\n");
  1132. /* wrap the modstosend in a Slapi_Mods for convenience */
  1133. slapi_mods_init_passin(new_smods, *modstosend);
  1134. slapi_mods_init_byref(smods, (LDAPMod**) origmods);
  1135. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  1136. size_t i = 0;
  1137. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1138. "_pre_ad_mod_group_mods_cb -- check modify type %s\n", mod->mod_type);
  1139. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  1140. if (0 == slapi_attr_type_cmp(mod->mod_type, attr_map[i].ldap_attribute_name,
  1141. SLAPI_TYPE_CMP_SUBTYPE)) {
  1142. Slapi_Mod *mysmod = slapi_mod_new();
  1143. if (mod->mod_op & LDAP_MOD_DELETE) {
  1144. slapi_mod_init(mysmod, 0);
  1145. slapi_mod_set_operation(mysmod, LDAP_MOD_DELETE | LDAP_MOD_BVALUES);
  1146. slapi_mod_set_type(mysmod, attr_map[i].windows_attribute_name);
  1147. } else {
  1148. slapi_mod_init_byval(mysmod, mod);
  1149. slapi_mod_set_type(mysmod, attr_map[i].windows_attribute_name);
  1150. if (0
  1151. == slapi_attr_type_cmp(mod->mod_type, "gidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  1152. Slapi_Mod *ocsmod = slapi_mod_new();
  1153. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1154. "_pre_ad_mod_group_mods_cb -- add NisDomain\n");
  1155. addNisDomainName(ocsmod, ds_entry);
  1156. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(ocsmod));
  1157. slapi_mod_free(&ocsmod);
  1158. }
  1159. }
  1160. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(mysmod));
  1161. slapi_mod_free(&mysmod);
  1162. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1163. "_pre_ad_mod_group_mods_cb -- add modify %s DS account [%s]\n",
  1164. attr_map[i].windows_attribute_name,
  1165. slapi_entry_get_dn_const(ds_entry));
  1166. }
  1167. }
  1168. }
  1169. *modstosend = slapi_mods_get_ldapmods_passout(new_smods);
  1170. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  1171. for (mod = slapi_mods_get_first_mod(new_smods); mod;
  1172. mod = slapi_mods_get_next_mod(new_smods)) {
  1173. slapi_mod_dump(mod, 0);
  1174. }
  1175. }
  1176. slapi_mods_free(&smods);
  1177. slapi_mods_free(&new_smods);
  1178. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1179. "<-- _pre_ad_mod_group_mods_cb -- end\n");
  1180. return;
  1181. }
  1182. static int
  1183. posix_winsync_can_add_entry_to_ad_cb(void *cbdata, const Slapi_Entry *local_entry,
  1184. const Slapi_DN *remote_dn)
  1185. {
  1186. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1187. "--> posix_winsync_can_add_entry_to_ad_cb -- begin\n");
  1188. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1189. "<-- posix_winsync_can_add_entry_to_ad_cb -- end\n");
  1190. return 1; /* false - do not allow entries to be added to ad */
  1191. }
  1192. static void
  1193. posix_winsync_begin_update_cb(void *cbdata, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree,
  1194. int is_total)
  1195. {
  1196. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1197. "--> posix_winsync_begin_update_cb -- begin\n");
  1198. posix_winsync_config_reset_MOFTaskCreated();
  1199. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1200. "<-- posix_winsync_begin_update_cb -- end\n");
  1201. return;
  1202. }
  1203. static void
  1204. posix_winsync_end_update_cb(void *cbdata, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree,
  1205. int is_total)
  1206. {
  1207. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1208. "--> posix_winsync_end_update_cb -- begin %d %d\n",
  1209. posix_winsync_config_get_MOFTaskCreated(),
  1210. posix_winsync_config_get_createMOFTask());
  1211. if (1 && posix_winsync_config_get_createMOFTask()) {
  1212. /* add a task to schedule memberof Plugin for fix memebrof attributs */
  1213. Slapi_PBlock *pb = slapi_pblock_new();
  1214. Slapi_Entry *e_task = slapi_entry_alloc();
  1215. int rc = 0;
  1216. char *dn = slapi_create_dn_string("cn=%s,cn=%s,cn=tasks,cn=config",
  1217. posix_winsync_plugin_name, MEMBEROFTASK);
  1218. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1219. "--> posix_winsync_end_update_cb, create task %s\n", dn);
  1220. if (NULL == dn) {
  1221. slapi_pblock_destroy(pb);
  1222. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1223. "posix_winsync_end_update_cb: "
  1224. "failed to create task dn: cn=%s,%s,cn=tasks,cn=config\n",
  1225. posix_winsync_plugin_name, MEMBEROFTASK);
  1226. return;
  1227. }
  1228. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1229. "--> posix_winsync_end_update_cb, init'ing task\n");
  1230. slapi_entry_init(e_task, slapi_ch_strdup(dn), NULL);
  1231. slapi_entry_add_string(e_task, "cn", slapi_ch_strdup(posix_winsync_plugin_name));
  1232. slapi_entry_add_string(e_task, "objectClass", "extensibleObject");
  1233. slapi_entry_add_string(e_task, "basedn", slapi_sdn_get_dn(ds_subtree));
  1234. slapi_add_entry_internal_set_pb(pb, e_task, NULL, posix_winsync_get_plugin_identity(), 0);
  1235. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1236. "--> posix_winsync_end_update_cb, adding task\n");
  1237. slapi_add_internal_pb(pb);
  1238. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1239. "--> posix_winsync_end_update_cb, retrieving return code\n");
  1240. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  1241. if (LDAP_ALREADY_EXISTS == rc) {
  1242. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1243. "posix_winsync_end_update_cb: "
  1244. "task entry %s already exists\n",
  1245. posix_winsync_plugin_name);
  1246. } else if (rc != 0) {
  1247. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1248. "posix_winsync_end_update_cb: "
  1249. "failed to add task entry (%d)\n", rc);
  1250. } else {
  1251. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1252. "posix_winsync_end_update_cb: "
  1253. "add task entry\n");
  1254. }
  1255. /* slapi_entry_free(e_task); */
  1256. slapi_pblock_destroy(pb);
  1257. pb = NULL;
  1258. posix_winsync_config_reset_MOFTaskCreated();
  1259. }
  1260. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1261. "<-- posix_winsync_end_update_cb -- end\n");
  1262. return;
  1263. }
  1264. static void
  1265. posix_winsync_destroy_agmt_cb(void *cbdata, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree)
  1266. {
  1267. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1268. "--> posix_winsync_destroy_agmt_cb -- begin\n");
  1269. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1270. "<-- posix_winsync_destroy_agmt_cb -- end\n");
  1271. return;
  1272. }
  1273. static void
  1274. 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)
  1275. {
  1276. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1277. "--> posix_winsync_post_ad_mod_user_cb -- begin\n");
  1278. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1279. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1280. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1281. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1282. #endif
  1283. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1284. "<-- posix_winsync_post_ad_mod_user_cb -- end\n");
  1285. return;
  1286. }
  1287. static void
  1288. 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)
  1289. {
  1290. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1291. "--> posix_winsync_post_ad_mod_group_cb -- begin\n");
  1292. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1293. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1294. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1295. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1296. #endif
  1297. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1298. "<-- posix_winsync_post_ad_mod_group_cb -- end\n");
  1299. return;
  1300. }
  1301. static void
  1302. 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)
  1303. {
  1304. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1305. "--> posix_winsync_post_ds_mod_user_cb -- begin\n");
  1306. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1307. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1308. "Result of modifying DS entry [%s] was [%d:%s]\n",
  1309. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1310. #endif
  1311. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1312. "<-- posix_winsync_post_ds_mod_user_cb -- end\n");
  1313. return;
  1314. }
  1315. static void
  1316. 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)
  1317. {
  1318. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1319. "--> posix_winsync_post_ds_mod_group_cb -- begin\n");
  1320. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1321. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1322. "Result of modifying DS entry [%s] was [%d:%s]\n",
  1323. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1324. #endif
  1325. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1326. "<-- posix_winsync_post_ds_mod_group_cb -- end\n");
  1327. return;
  1328. }
  1329. static void
  1330. posix_winsync_post_ds_add_user_cb(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  1331. {
  1332. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1333. "--> posix_winsync_post_ds_add_user_cb -- begin\n");
  1334. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1335. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1336. "Result of adding DS entry [%s] was [%d:%s]\n",
  1337. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1338. #endif
  1339. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1340. "<-- posix_winsync_post_ds_add_user_cb -- end\n");
  1341. return;
  1342. }
  1343. static void
  1344. posix_winsync_post_ds_add_group_cb(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  1345. {
  1346. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1347. "--> posix_winsync_post_ds_add_group_cb -- begin\n");
  1348. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1349. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1350. "Result of adding DS entry [%s] was [%d:%s]\n",
  1351. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1352. #endif
  1353. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1354. "<-- posix_winsync_post_ds_add_group_cb -- end\n");
  1355. return;
  1356. }
  1357. static void
  1358. posix_winsync_pre_ad_add_user_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry)
  1359. {
  1360. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1361. "--> posix_winsync_pre_ad_add_user_cb -- begin\n");
  1362. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1363. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1364. "Adding AD entry [%s] from add of DS entry [%s]\n",
  1365. slapi_entry_get_dn(ad_entry), slapi_entry_get_dn(ds_entry));
  1366. /* make modifications to ad_entry here */
  1367. #endif
  1368. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1369. "<-- posix_winsync_pre_ad_add_user_cb -- end\n");
  1370. return;
  1371. }
  1372. static void
  1373. posix_winsync_pre_ad_add_group_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry)
  1374. {
  1375. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1376. "--> posix_winsync_pre_ad_add_group_cb -- begin\n");
  1377. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1378. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1379. "Adding AD entry [%s] from add of DS entry [%s]\n",
  1380. slapi_entry_get_dn(ad_entry), slapi_entry_get_dn(ds_entry));
  1381. /* make modifications to ad_entry here */
  1382. #endif
  1383. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1384. "<-- posix_winsync_pre_ad_add_group_cb -- end\n");
  1385. return;
  1386. }
  1387. static void
  1388. posix_winsync_post_ad_add_user_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry, int *result)
  1389. {
  1390. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1391. "--> posix_winsync_post_ad_add_user_cb -- begin\n");
  1392. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1393. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1394. "Result of adding AD entry [%s] was [%d:%s]\n",
  1395. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1396. #endif
  1397. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1398. "<-- posix_winsync_post_ad_add_user_cb -- end\n");
  1399. return;
  1400. }
  1401. static void
  1402. posix_winsync_post_ad_add_group_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry, int *result)
  1403. {
  1404. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1405. "--> posix_winsync_post_ad_add_group_cb -- begin\n");
  1406. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1407. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1408. "Result of adding AD entry [%s] was [%d:%s]\n",
  1409. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1410. #endif
  1411. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1412. "<-- posix_winsync_post_ad_add_group_cb -- end\n");
  1413. return;
  1414. }
  1415. static void
  1416. 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)
  1417. {
  1418. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1419. "--> posix_winsync_post_ad_mod_user_mods_cb -- begin\n");
  1420. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1421. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1422. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1423. slapi_sdn_get_dn(remote_dn), *result, ldap_err2string(*result));
  1424. #endif
  1425. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1426. "<-- posix_winsync_post_ad_mod_user_mods_cb -- end\n");
  1427. return;
  1428. }
  1429. static void
  1430. 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)
  1431. {
  1432. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1433. "--> posix_winsync_post_ad_mod_group_mods_cb -- begin\n");
  1434. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1435. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1436. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1437. slapi_sdn_get_dn(remote_dn), *result, ldap_err2string(*result));
  1438. #endif
  1439. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1440. "<-- posix_winsync_post_ad_mod_group_mods_cb -- end\n");
  1441. return;
  1442. }
  1443. #define DEFAULT_PRECEDENCE 25
  1444. static int precedence = DEFAULT_PRECEDENCE; /* default */
  1445. static int posix_winsync_precedence(void)
  1446. {
  1447. return precedence;
  1448. }
  1449. static void *posix_winsync_api[] = { NULL, /* reserved for api broker use, must be zero */
  1450. posix_winsync_agmt_init,
  1451. posix_winsync_dirsync_search_params_cb,
  1452. posix_winsync_pre_ad_search_cb,
  1453. posix_winsync_pre_ds_search_entry_cb,
  1454. posix_winsync_pre_ds_search_all_cb,
  1455. posix_winsync_pre_ad_mod_user_cb,
  1456. posix_winsync_pre_ad_mod_group_cb,
  1457. posix_winsync_pre_ds_mod_user_cb,
  1458. posix_winsync_pre_ds_mod_group_cb,
  1459. posix_winsync_pre_ds_add_user_cb,
  1460. posix_winsync_pre_ds_add_group_cb,
  1461. posix_winsync_get_new_ds_user_dn_cb,
  1462. posix_winsync_get_new_ds_group_dn_cb,
  1463. posix_winsync_pre_ad_mod_user_mods_cb,
  1464. posix_winsync_pre_ad_mod_group_mods_cb,
  1465. posix_winsync_can_add_entry_to_ad_cb,
  1466. posix_winsync_begin_update_cb,
  1467. posix_winsync_end_update_cb,
  1468. posix_winsync_destroy_agmt_cb,
  1469. posix_winsync_post_ad_mod_user_cb,
  1470. posix_winsync_post_ad_mod_group_cb,
  1471. posix_winsync_post_ds_mod_user_cb,
  1472. posix_winsync_post_ds_mod_group_cb,
  1473. posix_winsync_post_ds_add_user_cb,
  1474. posix_winsync_post_ds_add_group_cb,
  1475. posix_winsync_pre_ad_add_user_cb,
  1476. posix_winsync_pre_ad_add_group_cb,
  1477. posix_winsync_post_ad_add_user_cb,
  1478. posix_winsync_post_ad_add_group_cb,
  1479. posix_winsync_post_ad_mod_user_mods_cb,
  1480. posix_winsync_post_ad_mod_group_mods_cb,
  1481. posix_winsync_precedence
  1482. };
  1483. static Slapi_ComponentId *posix_winsync_plugin_id = NULL;
  1484. /*
  1485. ** Plugin identity mgmt
  1486. */
  1487. void
  1488. posix_winsync_set_plugin_identity(void * identity)
  1489. {
  1490. posix_winsync_plugin_id = identity;
  1491. }
  1492. void *
  1493. posix_winsync_get_plugin_identity()
  1494. {
  1495. return posix_winsync_plugin_id;
  1496. }
  1497. static int
  1498. posix_winsync_plugin_start(Slapi_PBlock *pb)
  1499. {
  1500. int rc;
  1501. Slapi_Entry *config_e = NULL; /* entry containing plugin config */
  1502. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1503. "--> posix_winsync_plugin_start -- begin\n");
  1504. if (slapi_apib_register(WINSYNC_v3_0_GUID, posix_winsync_api)) {
  1505. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1506. "<-- posix_winsync_plugin_start -- failed to register winsync api -- end\n");
  1507. return -1;
  1508. }
  1509. if (slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &config_e) != 0) {
  1510. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name, "missing config entry\n");
  1511. return (-1);
  1512. }
  1513. if ((rc = posix_winsync_config(config_e)) != LDAP_SUCCESS) {
  1514. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name, "configuration failed (%s)\n",
  1515. ldap_err2string(rc));
  1516. return (-1);
  1517. }
  1518. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1519. "<-- posix_winsync_plugin_start -- registered; end\n");
  1520. return 0;
  1521. }
  1522. static int
  1523. posix_winsync_plugin_close(Slapi_PBlock *pb)
  1524. {
  1525. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1526. "--> posix_winsync_plugin_close -- begin\n");
  1527. slapi_apib_unregister(WINSYNC_v1_0_GUID);
  1528. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1529. "<-- posix_winsync_plugin_close -- end\n");
  1530. return 0;
  1531. }
  1532. /* this is the slapi plugin init function,
  1533. not the one used by the winsync api
  1534. */
  1535. int
  1536. posix_winsync_plugin_init(Slapi_PBlock *pb)
  1537. {
  1538. void *plugin_id = NULL;
  1539. Slapi_Entry *confige = NULL;
  1540. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1541. "--> posix_winsync_plugin_init -- begin\n");
  1542. if (slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &confige) && confige) {
  1543. precedence = slapi_entry_attr_get_int(confige, "nsslapd-pluginprecedence");
  1544. if (!precedence) {
  1545. precedence = DEFAULT_PRECEDENCE;
  1546. }
  1547. }
  1548. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0
  1549. || slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN, (void *) posix_winsync_plugin_start) != 0
  1550. || slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN, (void *) posix_winsync_plugin_close) != 0
  1551. || slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *) &posix_winsync_pdesc) != 0) {
  1552. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1553. "<-- posix_winsync_plugin_init -- failed to register plugin -- end\n");
  1554. return -1;
  1555. }
  1556. /* Retrieve and save the plugin identity to later pass to
  1557. internal operations */
  1558. if (slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &plugin_id) != 0) {
  1559. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1560. "<-- posix_winsync_plugin_init -- failed to retrieve plugin identity -- end\n");
  1561. return -1;
  1562. }
  1563. posix_winsync_set_plugin_identity(plugin_id);
  1564. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1565. "<-- posix_winsync_plugin_init -- end\n");
  1566. return 0;
  1567. }