posix-winsync.c 86 KB

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