posix-winsync.c 85 KB

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