posix-winsync.c 86 KB

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