posix-winsync.c 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225
  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 __attribute__((unused)), /* 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 [%" PRIu64 "]\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 [%" PRIu64 "]\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 __attribute__((unused)),
  496. const char *agmt_dn __attribute__((unused)),
  497. char **base __attribute__((unused)),
  498. int *scope __attribute__((unused)),
  499. char **filter __attribute__((unused)),
  500. char ***attrs __attribute__((unused)),
  501. LDAPControl ***serverctrls __attribute__((unused)))
  502. {
  503. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  504. "--> posix_winsync_dirsync_search_params_cb -- begin\n");
  505. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  506. "<-- posix_winsync_dirsync_search_params_cb -- end\n");
  507. return;
  508. }
  509. /* called before searching for a single entry from AD - agmt_dn will be NULL */
  510. static void
  511. posix_winsync_pre_ad_search_cb(void *cbdata __attribute__((unused)),
  512. const char *agmt_dn __attribute__((unused)),
  513. char **base __attribute__((unused)),
  514. int *scope __attribute__((unused)),
  515. char **filter __attribute__((unused)),
  516. char ***attrs __attribute__((unused)),
  517. LDAPControl ***serverctrls __attribute__((unused)))
  518. {
  519. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  520. "--> posix_winsync_pre_ad_search_cb -- begin\n");
  521. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  522. "<-- posix_winsync_pre_ad_search_cb -- end\n");
  523. return;
  524. }
  525. /* called before an internal search to get a single DS entry - agmt_dn will be NULL */
  526. static void
  527. posix_winsync_pre_ds_search_entry_cb(void *cbdata __attribute__((unused)),
  528. const char *agmt_dn __attribute__((unused)),
  529. char **base,
  530. int *scope,
  531. char **filter,
  532. char ***attrs __attribute__((unused)),
  533. LDAPControl ***serverctrls __attribute__((unused)))
  534. {
  535. /*
  536. char *tmpbase=slapi_ch_strdup(*base);
  537. char *d = *base;
  538. char *s = tmpbase;
  539. int i=0;
  540. */
  541. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "--> _pre_ds_search_cb -- begin\n");
  542. /* skip the first subtree container ou=xyz, */
  543. /* if (strlen(*base) > 3) {
  544. s++;
  545. while(*s !='\0'){
  546. if (((*(s) == ',') || (*(s) == ';' )) && (*((s)-1) != '\\')){
  547. s++;
  548. while(*s !='\0'){
  549. *d++ = *s++;
  550. }
  551. *d='\0';
  552. break;
  553. }
  554. s++;
  555. }
  556. }
  557. */
  558. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  559. "-- _pre_ds_search_cb - base [%s] "
  560. "scope [%d] filter [%s]\n", *base, *scope, *filter);
  561. /* slapi_ch_free_string(&tmpbase); */
  562. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_search_cb -- end\n");
  563. return;
  564. }
  565. /* called before the total update to get all entries from the DS to sync to AD */
  566. static void
  567. posix_winsync_pre_ds_search_all_cb(void *cbdata __attribute__((unused)),
  568. const char *agmt_dn __attribute__((unused)),
  569. char **base __attribute__((unused)),
  570. int *scope __attribute__((unused)),
  571. char **filter,
  572. char ***attrs __attribute__((unused)),
  573. LDAPControl ***serverctrls __attribute__((unused)))
  574. {
  575. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  576. "--> posix_winsync_pre_ds_search_all_cb -- orig filter [%s] -- begin\n",
  577. ((filter && *filter) ? *filter : "NULL"));
  578. /* slapi_ch_free_string(filter);
  579. *filter = slapi_ch_strdup("(|(objectclass=posixaccount)(objectclass=posixgroup))");
  580. */
  581. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  582. "<-- posix_winsync_pre_ds_search_all_cb -- end\n");
  583. return;
  584. }
  585. static void
  586. posix_winsync_pre_ad_mod_user_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  587. Slapi_Entry *ds_entry, Slapi_Mods *smods, int *do_modify)
  588. {
  589. LDAPMod *mod = NULL;
  590. int rc = 0;
  591. Slapi_Attr *attr = NULL;
  592. windows_attribute_map *attr_map = user_attribute_map;
  593. plugin_op_started();
  594. if(!get_plugin_started()){
  595. plugin_op_finished();
  596. return;
  597. }
  598. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  599. "--> posix_winsync_pre_ad_mod_user_cb -- begin DS account [%s]\n",
  600. slapi_entry_get_dn_const(ds_entry));
  601. if (posix_winsync_config_get_msSFUSchema()) {
  602. attr_map = user_mssfu_attribute_map;
  603. }
  604. /* called if init Replica: add nisDomain, uidnumber, ... if avail */
  605. for (rc = slapi_entry_first_attr(ds_entry, &attr); rc == 0;
  606. rc = slapi_entry_next_attr(ds_entry, attr, &attr)) {
  607. char *type = NULL;
  608. size_t i = 0;
  609. slapi_attr_get_type(attr, &type);
  610. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  611. "_pre_ad_mod_user_cb -- check modify type %s\n", type);
  612. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  613. if (0 == slapi_attr_type_cmp(type, attr_map[i].ldap_attribute_name,
  614. SLAPI_TYPE_CMP_SUBTYPE)) {
  615. Slapi_Attr *ad_attr = NULL;
  616. Slapi_ValueSet *vs = NULL;
  617. char *ad_type = NULL;
  618. int is_present_local;
  619. slapi_attr_get_valueset(attr, &vs);
  620. ad_type = slapi_ch_strdup(attr_map[i].windows_attribute_name);
  621. slapi_entry_attr_find(ad_entry, ad_type, &ad_attr);
  622. is_present_local = (NULL == ad_attr) ? 0 : 1;
  623. if (is_present_local) {
  624. int values_equal = 0;
  625. values_equal = attr_compare_equal(attr, ad_attr);
  626. if (!values_equal) {
  627. slapi_log_err(SLAPI_LOG_PLUGIN,
  628. posix_winsync_plugin_name,
  629. "_pre_ad_mod_user_cb -- update mods: %s, %s : values are different -> modify\n",
  630. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  631. ad_type);
  632. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, ad_type,
  633. valueset_get_valuearray(vs));
  634. *do_modify = 1;
  635. }
  636. } else {
  637. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, ad_type,
  638. valueset_get_valuearray(vs));
  639. if (0 == slapi_attr_type_cmp(type, "uidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  640. Slapi_Mod *mysmod = slapi_mod_new();
  641. addNisDomainName(mysmod, ds_entry);
  642. slapi_mods_add_ldapmod(smods, slapi_mod_get_ldapmod_passout(mysmod));
  643. slapi_mod_free(&mysmod);
  644. }
  645. *do_modify = 1;
  646. }
  647. slapi_ch_free((void**) &ad_type);
  648. slapi_valueset_free(vs);
  649. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  650. "_pre_ad_mod_user_cb -- add modify %s DS account [%s]\n",
  651. attr_map[i].windows_attribute_name,
  652. slapi_entry_get_dn_const(ds_entry));
  653. }
  654. }
  655. if (0 == slapi_attr_type_cmp(type, "nsAccountLock", SLAPI_TYPE_CMP_SUBTYPE))
  656. sync_acct_disable(cbdata, rawentry, ds_entry, ACCT_DISABLE_TO_AD, NULL, smods,
  657. do_modify);
  658. }
  659. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  660. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  661. slapi_mod_dump(mod, 0);
  662. }
  663. }
  664. plugin_op_finished();
  665. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  666. "<-- posix_winsync_pre_ad_mod_user_cb -- end\n");
  667. return;
  668. }
  669. static void
  670. posix_winsync_pre_ad_mod_group_cb(void *cbdata __attribute__((unused)),
  671. const Slapi_Entry *rawentry __attribute__((unused)),
  672. Slapi_Entry *ad_entry,
  673. Slapi_Entry *ds_entry,
  674. Slapi_Mods *smods,
  675. int *do_modify)
  676. {
  677. LDAPMod *mod = NULL;
  678. int rc = 0;
  679. Slapi_Attr *attr = NULL;
  680. windows_attribute_map *attr_map = group_attribute_map;
  681. plugin_op_started();
  682. if(!get_plugin_started()){
  683. plugin_op_finished();
  684. return;
  685. }
  686. if (posix_winsync_config_get_msSFUSchema())
  687. attr_map = group_mssfu_attribute_map;
  688. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  689. "--> _pre_ad_mod_group_cb -- begin DS account [%s]\n",
  690. slapi_entry_get_dn_const(ds_entry));
  691. /* called if init Replica: add nisDomain, gidnumber, memberuid, if avail */
  692. for (rc = slapi_entry_first_attr(ds_entry, &attr); rc == 0;
  693. rc = slapi_entry_next_attr(ds_entry, attr, &attr)) {
  694. char *type = NULL;
  695. size_t i = 0;
  696. slapi_attr_get_type(attr, &type);
  697. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  698. "_pre_ad_mod_group_cb -- check modify type %s\n", type);
  699. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  700. if (0 == slapi_attr_type_cmp(type, attr_map[i].ldap_attribute_name,
  701. SLAPI_TYPE_CMP_SUBTYPE)) {
  702. Slapi_Attr *ad_attr = NULL;
  703. Slapi_ValueSet *vs = NULL;
  704. char *ad_type = NULL;
  705. int is_present_local;
  706. if (i == 0) { /* memberUid */
  707. Slapi_Attr *dsmuid_attr = NULL;
  708. Slapi_Value *v = NULL;
  709. slapi_entry_attr_find(ds_entry, "dsonlymemberuid", &dsmuid_attr);
  710. if (dsmuid_attr) {
  711. Slapi_ValueSet *dsmuid_vs = NULL;
  712. slapi_attr_get_valueset(dsmuid_attr, &dsmuid_vs);
  713. if (dsmuid_vs) {
  714. vs = slapi_valueset_new();
  715. int j;
  716. for (j = slapi_attr_first_value(attr, &v); j != -1;
  717. j = slapi_attr_next_value(attr, i, &v)) {
  718. /* If dsOnlyMemberUid matches memberUid, add it to AD */
  719. if (slapi_valueset_find(dsmuid_attr, dsmuid_vs, v)) {
  720. slapi_valueset_add_value(vs, v);
  721. }
  722. }
  723. slapi_valueset_free(dsmuid_vs); dsmuid_vs = NULL;
  724. }
  725. }
  726. }
  727. if (!vs) {
  728. slapi_attr_get_valueset(attr, &vs);
  729. }
  730. ad_type = slapi_ch_strdup(attr_map[i].windows_attribute_name);
  731. slapi_entry_attr_find(ad_entry, ad_type, &ad_attr);
  732. is_present_local = (NULL == ad_attr) ? 0 : 1;
  733. if (is_present_local) {
  734. int values_equal = 0;
  735. values_equal = attr_compare_equal(attr, ad_attr);
  736. if (!values_equal) {
  737. slapi_log_err(SLAPI_LOG_PLUGIN,
  738. posix_winsync_plugin_name,
  739. "_pre_ad_mod_group_cb -- update mods: %s, %s : values are different -> modify\n",
  740. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  741. ad_type);
  742. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, ad_type,
  743. valueset_get_valuearray(vs));
  744. *do_modify = 1;
  745. }
  746. } else if (!slapi_valueset_isempty(vs)) {
  747. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, ad_type,
  748. valueset_get_valuearray(vs));
  749. if (0 == slapi_attr_type_cmp(type, "gidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  750. Slapi_Mod *mysmod = slapi_mod_new();
  751. addNisDomainName(mysmod, ds_entry);
  752. slapi_mods_add_ldapmod(smods, slapi_mod_get_ldapmod_passout(mysmod));
  753. slapi_mod_free(&mysmod);
  754. }
  755. *do_modify = 1;
  756. }
  757. slapi_ch_free((void**) &ad_type);
  758. slapi_valueset_free(vs);
  759. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  760. "_pre_ad_mod_group_cb -- add modify %s DS account [%s]\n",
  761. attr_map[i].windows_attribute_name,
  762. slapi_entry_get_dn_const(ds_entry));
  763. }
  764. }
  765. }
  766. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "_pre_ad_mod_group_cb -- step\n");
  767. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  768. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  769. slapi_mod_dump(mod, 0);
  770. }
  771. }
  772. plugin_op_finished();
  773. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  774. "<-- _pre_ad_mod_group_cb -- end\n");
  775. return;
  776. }
  777. static void
  778. posix_winsync_pre_ds_mod_user_cb(void *cbdata,
  779. const Slapi_Entry *rawentry __attribute__((unused)),
  780. Slapi_Entry *ad_entry,
  781. Slapi_Entry *ds_entry,
  782. Slapi_Mods *smods,
  783. int *do_modify)
  784. {
  785. LDAPMod* mod = NULL;
  786. Slapi_Attr *attr = NULL;
  787. int is_present_local = 0;
  788. int do_modify_local = 0;
  789. int rc;
  790. int i;
  791. windows_attribute_map *attr_map = user_attribute_map;
  792. PRBool posixval = PR_TRUE;
  793. plugin_op_started();
  794. if(!get_plugin_started()){
  795. plugin_op_finished();
  796. return;
  797. }
  798. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  799. "--> _pre_ds_mod_user_cb -- begin\n");
  800. if ((NULL == ad_entry) || (NULL == ds_entry)) {
  801. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  802. "<-- _pre_ds_mod_user_cb -- Empty %s entry.\n",
  803. (NULL==ad_entry)?"ad entry":"ds entry");
  804. plugin_op_finished();
  805. return;
  806. }
  807. if (posix_winsync_config_get_msSFUSchema())
  808. attr_map = user_mssfu_attribute_map;
  809. /* check all of the required attributes are in the ad_entry:
  810. * MUST (cn $ uid $ uidNumber $ gidNumber $ homeDirectory).
  811. * If any of the required attributes are missing, drop them before adding
  812. * the entry to the DS. */
  813. for (i = 0; attr_map[i].windows_attribute_name != NULL; i++) {
  814. Slapi_Attr *pa_attr;
  815. if (attr_map[i].isMUST &&
  816. slapi_entry_attr_find(ad_entry,
  817. attr_map[i].windows_attribute_name,
  818. &pa_attr)) {
  819. /* required attribute does not exist */
  820. posixval = PR_FALSE;
  821. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  822. "AD entry %s does not have required attribute %s for posixAccount objectclass.\n",
  823. slapi_entry_get_dn_const(ad_entry),
  824. attr_map[i].ldap_attribute_name);
  825. }
  826. }
  827. /* add objectclass: posixAccount, uidnumber ,gidnumber ,homeDirectory, loginshell */
  828. /* in the ad to ds case we have no changelog, so we have to compare the entries */
  829. for (rc = slapi_entry_first_attr(ad_entry, &attr); rc == 0;
  830. rc = slapi_entry_next_attr(ad_entry, attr, &attr)) {
  831. char *type = NULL;
  832. slapi_attr_get_type(attr, &type);
  833. for (i = 0; attr_map[i].windows_attribute_name != NULL; i++) {
  834. if (0 == slapi_attr_type_cmp(type, attr_map[i].windows_attribute_name,
  835. SLAPI_TYPE_CMP_SUBTYPE)) {
  836. Slapi_Attr *local_attr = NULL;
  837. char *local_type = NULL;
  838. Slapi_ValueSet *vs = NULL;
  839. slapi_attr_get_valueset(attr, &vs);
  840. local_type = slapi_ch_strdup(attr_map[i].ldap_attribute_name);
  841. slapi_entry_attr_find(ds_entry, local_type, &local_attr);
  842. is_present_local = (NULL == local_attr) ? 0 : 1;
  843. if (is_present_local) {
  844. /* DS entry has the posix attrs.
  845. * I.e., it is a posix account*/
  846. int values_equal = 0;
  847. posixval = PR_TRUE;
  848. values_equal = attr_compare_equal(attr, local_attr);
  849. if (!values_equal) {
  850. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  851. "_pre_ds_mod_user_cb -- update mods: %s, %s : values are different -> modify\n",
  852. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  853. local_type);
  854. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, local_type,
  855. valueset_get_valuearray(vs));
  856. *do_modify = 1;
  857. }
  858. } else if (posixval) {
  859. /* only if AD provides the all necessary attributes */
  860. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, local_type,
  861. valueset_get_valuearray(vs));
  862. *do_modify = do_modify_local = 1;
  863. }
  864. slapi_valueset_free(vs);
  865. slapi_ch_free((void**) &local_type);
  866. /* what about if delete all values on windows ????? */
  867. }
  868. }
  869. }
  870. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  871. "<-- _pre_ds_mod_user_cb present %d modify %d isPosixaccount %s\n",
  872. is_present_local, do_modify_local,
  873. posixval?"yes":"no");
  874. if (!is_present_local && do_modify_local && posixval) {
  875. Slapi_Attr *oc_attr = NULL;
  876. Slapi_Value *voc = slapi_value_new();
  877. slapi_value_init_string(voc, "posixAccount");
  878. rc = slapi_entry_attr_find(ds_entry, "objectClass", &oc_attr);
  879. if (rc == 0) {
  880. const struct berval *bv = slapi_value_get_berval(voc);
  881. if (bv && slapi_attr_value_find(oc_attr, bv) != 0) {
  882. Slapi_ValueSet *oc_vs = slapi_valueset_new();
  883. Slapi_Value *oc_nv = slapi_value_new();
  884. slapi_attr_get_valueset(oc_attr, &oc_vs);
  885. slapi_value_init_string(oc_nv, "posixAccount");
  886. slapi_valueset_add_value(oc_vs, oc_nv);
  887. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  888. "<-- _pre_ds_mod_user_cb add oc:posixAccount\n");
  889. slapi_value_init_string(voc, "shadowAccount");
  890. if (slapi_attr_value_find(oc_attr, slapi_value_get_berval(voc)) != 0) {
  891. Slapi_Value *oc_nv = slapi_value_new();
  892. slapi_value_init_string(oc_nv, "shadowAccount");
  893. slapi_valueset_add_value(oc_vs, oc_nv);
  894. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  895. "<-- _pre_ds_mod_user_cb add oc:shadowAccount\n");
  896. }
  897. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, "objectClass",
  898. valueset_get_valuearray(oc_vs));
  899. slapi_value_free(&oc_nv);
  900. slapi_valueset_free(oc_vs);
  901. if (posix_winsync_config_get_mapNestedGrouping()) {
  902. memberUidLock();
  903. addUserToGroupMembership(ds_entry);
  904. memberUidUnlock();
  905. }
  906. }
  907. }
  908. slapi_value_free(&voc);
  909. }
  910. sync_acct_disable(cbdata, ad_entry, ds_entry, ACCT_DISABLE_TO_DS, NULL, smods, do_modify);
  911. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_mod_user_cb %s %s\n",
  912. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)), (do_modify) ? "modified"
  913. : "not modified");
  914. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  915. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  916. slapi_mod_dump(mod, 0);
  917. }
  918. }
  919. plugin_op_finished();
  920. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_mod_user_cb -- end\n");
  921. return;
  922. }
  923. static void
  924. posix_winsync_pre_ds_mod_group_cb(void *cbdata __attribute__((unused)),
  925. const Slapi_Entry *rawentry __attribute__((unused)),
  926. Slapi_Entry *ad_entry,
  927. Slapi_Entry *ds_entry,
  928. Slapi_Mods *smods,
  929. int *do_modify)
  930. {
  931. LDAPMod* mod = NULL;
  932. Slapi_Attr *attr = NULL;
  933. int is_present_local = 0;
  934. int do_modify_local = 0;
  935. int rc;
  936. windows_attribute_map *attr_map = group_attribute_map;
  937. plugin_op_started();
  938. if(!get_plugin_started()){
  939. plugin_op_finished();
  940. return;
  941. }
  942. if (posix_winsync_config_get_msSFUSchema())
  943. attr_map = group_mssfu_attribute_map;
  944. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  945. "--> _pre_ds_mod_group_cb -- begin\n");
  946. /* in the ad to ds case we have no changelog, so we have to compare the entries */
  947. for (rc = slapi_entry_first_attr(ad_entry, &attr); rc == 0; rc
  948. = slapi_entry_next_attr(ad_entry, attr, &attr)) {
  949. char *type = NULL;
  950. Slapi_ValueSet *vs = NULL;
  951. size_t i = 0;
  952. slapi_attr_get_type(attr, &type);
  953. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  954. if (0 == slapi_attr_type_cmp(type, attr_map[i].windows_attribute_name,
  955. SLAPI_TYPE_CMP_SUBTYPE)) {
  956. Slapi_Attr *local_attr = NULL;
  957. char *local_type = NULL;
  958. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  959. "_pre_ds_mod_group_cb -- found AD attr %s\n", type);
  960. slapi_attr_get_valueset(attr, &vs);
  961. local_type = slapi_ch_strdup(attr_map[i].ldap_attribute_name);
  962. slapi_entry_attr_find(ds_entry, local_type, &local_attr);
  963. is_present_local = (NULL == local_attr) ? 0 : 1;
  964. if (is_present_local) {
  965. int values_equal = 0;
  966. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  967. "_pre_ds_mod_group_cb -- compare with DS attr %s\n", local_type);
  968. values_equal = attr_compare_equal(attr, local_attr);
  969. if (!values_equal) {
  970. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  971. "_pre_ds_mod_group_cb -- update mods: %s, %s : values are different -> modify\n",
  972. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  973. local_type);
  974. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, local_type,
  975. valueset_get_valuearray(vs));
  976. *do_modify = 1;
  977. }
  978. } else {
  979. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  980. "_pre_ds_mod_group_cb -- add attr\n");
  981. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, local_type,
  982. valueset_get_valuearray(vs));
  983. *do_modify = do_modify_local = 1;
  984. }
  985. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  986. "_pre_ds_mod_group_cb -- values compared\n");
  987. slapi_ch_free((void**) &local_type);
  988. slapi_valueset_free(vs);
  989. /* what about if delete all values on windows ???? */
  990. }
  991. }
  992. }
  993. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  994. "_pre_ds_mod_group_cb present %d modify %d before\n", is_present_local,
  995. do_modify_local);
  996. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  997. "_pre_ds_mod_group_cb present %d modify %d\n", is_present_local,
  998. do_modify_local);
  999. if (!is_present_local && do_modify_local) {
  1000. Slapi_Attr *oc_attr = NULL;
  1001. Slapi_Value *voc = slapi_value_new();
  1002. slapi_value_init_string(voc, "posixGroup");
  1003. slapi_entry_attr_find(ds_entry, "objectClass", &oc_attr);
  1004. if (slapi_attr_value_find(oc_attr, slapi_value_get_berval(voc)) != 0) {
  1005. Slapi_ValueSet *oc_vs = NULL;
  1006. Slapi_Value *oc_nv = slapi_value_new();
  1007. slapi_attr_get_valueset(oc_attr, &oc_vs);
  1008. slapi_value_init_string(oc_nv, "posixGroup");
  1009. slapi_valueset_add_value(oc_vs, oc_nv);
  1010. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1011. "_pre_ds_mod_group_cb add oc:posixGroup\n");
  1012. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, "objectClass",
  1013. valueset_get_valuearray(oc_vs));
  1014. slapi_value_free(&oc_nv);
  1015. slapi_valueset_free(oc_vs);
  1016. }
  1017. slapi_value_free(&voc);
  1018. }
  1019. if (posix_winsync_config_get_mapMemberUid() || posix_winsync_config_get_mapNestedGrouping()) {
  1020. memberUidLock();
  1021. modGroupMembership(ds_entry, smods, do_modify, do_modify_local);
  1022. memberUidUnlock();
  1023. }
  1024. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "_pre_ds_mod_group_cb step\n");
  1025. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  1026. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  1027. slapi_mod_dump(mod, 0);
  1028. }
  1029. }
  1030. plugin_op_finished();
  1031. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1032. "<-- _pre_ds_mod_group_cb -- end\n");
  1033. return;
  1034. }
  1035. static void
  1036. posix_winsync_pre_ds_add_user_cb(void *cbdata,
  1037. const Slapi_Entry *rawentry __attribute__((unused)),
  1038. Slapi_Entry *ad_entry,
  1039. Slapi_Entry *ds_entry)
  1040. {
  1041. Slapi_Attr *attr = NULL;
  1042. char *type = NULL;
  1043. PRBool posixval = PR_TRUE;
  1044. windows_attribute_map *attr_map = user_attribute_map;
  1045. int i = 0;
  1046. plugin_op_started();
  1047. if(!get_plugin_started()){
  1048. plugin_op_finished();
  1049. return;
  1050. }
  1051. if (posix_winsync_config_get_msSFUSchema())
  1052. attr_map = user_mssfu_attribute_map;
  1053. /* add objectclass: posixAccount, uidnumber, gidnumber, homeDirectory, loginShell */
  1054. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1055. "--> _pre_ds_add_user_cb -- begin\n");
  1056. /* check all of the required attributes are in the ad_entry:
  1057. * MUST (cn $ uid $ uidNumber $ gidNumber $ homeDirectory).
  1058. * If any of the required attributes are missing, drop them before adding
  1059. * the entry to the DS. */
  1060. for (i = 0; attr_map[i].windows_attribute_name != NULL; i++) {
  1061. Slapi_Attr *pa_attr;
  1062. if (attr_map[i].isMUST &&
  1063. slapi_entry_attr_find(ad_entry,
  1064. attr_map[i].windows_attribute_name,
  1065. &pa_attr)) {
  1066. /* required attribute does not exist */
  1067. posixval = PR_FALSE;
  1068. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1069. "AD entry %s does not have required attribute %s for posixAccount objectclass.\n",
  1070. slapi_entry_get_dn_const(ad_entry),
  1071. attr_map[i].ldap_attribute_name);
  1072. }
  1073. }
  1074. /* converts the AD attributes to DS posix attribute if all the posix
  1075. * required attributes are available */
  1076. if (posixval) {
  1077. int rc;
  1078. for (slapi_entry_first_attr(ad_entry, &attr); attr;
  1079. slapi_entry_next_attr(ad_entry, attr, &attr)) {
  1080. slapi_attr_get_type(attr, &type);
  1081. if (!type) {
  1082. continue;
  1083. }
  1084. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1085. "--> _pre_ds_add_user_cb -- "
  1086. "look for [%s] to new entry [%s]\n",
  1087. type, slapi_entry_get_dn_const(ds_entry));
  1088. for (i = 0; attr_map[i].windows_attribute_name != NULL; i++) {
  1089. if (slapi_attr_type_cmp(attr_map[i].windows_attribute_name,
  1090. type, SLAPI_TYPE_CMP_SUBTYPE) == 0) {
  1091. Slapi_ValueSet *svs = NULL;
  1092. slapi_attr_get_valueset(attr, &svs);
  1093. slapi_entry_add_valueset(ds_entry,
  1094. attr_map[i].ldap_attribute_name, svs);
  1095. slapi_valueset_free(svs);
  1096. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1097. "--> _pre_ds_add_user_cb -- "
  1098. "adding val for [%s] to new entry [%s]\n",
  1099. type, slapi_entry_get_dn_const(ds_entry));
  1100. }
  1101. }
  1102. }
  1103. rc = slapi_entry_add_string(ds_entry, "objectClass", "posixAccount");
  1104. rc |= slapi_entry_add_string(ds_entry, "objectClass", "shadowAccount");
  1105. rc |= slapi_entry_add_string(ds_entry, "objectClass", "inetUser");
  1106. if (rc != 0) {
  1107. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1108. "<-- _pre_ds_add_user_cb -- adding objectclass for new entry failed %d\n",
  1109. rc);
  1110. } else {
  1111. if (posix_winsync_config_get_mapNestedGrouping()) {
  1112. memberUidLock();
  1113. addUserToGroupMembership(ds_entry);
  1114. memberUidUnlock();
  1115. }
  1116. }
  1117. }
  1118. sync_acct_disable(cbdata, ad_entry, ds_entry, ACCT_DISABLE_TO_DS, ds_entry, NULL, NULL);
  1119. plugin_op_finished();
  1120. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_add_user_cb -- end\n");
  1121. return;
  1122. }
  1123. static void
  1124. posix_winsync_pre_ds_add_group_cb(void *cbdata __attribute__((unused)),
  1125. const Slapi_Entry *rawentry __attribute__((unused)),
  1126. Slapi_Entry *ad_entry,
  1127. Slapi_Entry *ds_entry)
  1128. {
  1129. Slapi_Attr *attr = NULL;
  1130. char *type = NULL;
  1131. PRBool posixval = PR_FALSE;
  1132. windows_attribute_map *attr_map = group_attribute_map;
  1133. plugin_op_started();
  1134. if(!get_plugin_started()){
  1135. plugin_op_finished();
  1136. return;
  1137. }
  1138. if (posix_winsync_config_get_msSFUSchema())
  1139. attr_map = group_mssfu_attribute_map;
  1140. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1141. "--> posix_winsync_pre_ds_add_group_cb -- begin\n");
  1142. for (slapi_entry_first_attr(ad_entry, &attr); attr; slapi_entry_next_attr(ad_entry, attr, &attr)) {
  1143. size_t i = 0;
  1144. slapi_attr_get_type(attr, &type);
  1145. if (!type) {
  1146. continue;
  1147. }
  1148. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "--> _pre_ds_add_group_cb -- "
  1149. "look for [%s] to new entry [%s]\n", type, slapi_entry_get_dn_const(ds_entry));
  1150. for (i = 0; attr_map && attr_map[i].windows_attribute_name != NULL; i++) {
  1151. if (slapi_attr_type_cmp(attr_map[i].windows_attribute_name, type,
  1152. SLAPI_TYPE_CMP_SUBTYPE) == 0) {
  1153. Slapi_ValueSet *svs = NULL;
  1154. slapi_attr_get_valueset(attr, &svs);
  1155. slapi_entry_add_valueset(ds_entry, attr_map[i].ldap_attribute_name, svs);
  1156. slapi_valueset_free(svs);
  1157. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1158. "--> _pre_ds_add_group_cb -- "
  1159. "adding val for [%s] to new entry [%s]\n", type,
  1160. slapi_entry_get_dn_const(ds_entry));
  1161. posixval = PR_TRUE;
  1162. }
  1163. }
  1164. }
  1165. if (posixval) {
  1166. int rc;
  1167. rc = slapi_entry_add_string(ds_entry, "objectClass", "posixGroup");
  1168. if (rc != 0) {
  1169. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1170. "<-- _pre_ds_add_group_cb -- adding objectclass for new entry failed %d\n",
  1171. rc);
  1172. }
  1173. }
  1174. if (posix_winsync_config_get_mapMemberUid() || posix_winsync_config_get_mapNestedGrouping()) {
  1175. memberUidLock();
  1176. addGroupMembership(ds_entry, ad_entry);
  1177. memberUidUnlock();
  1178. }
  1179. plugin_op_finished();
  1180. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1181. "<-- posix_winsync_pre_ds_add_group_cb -- end\n");
  1182. return;
  1183. }
  1184. static void
  1185. posix_winsync_get_new_ds_user_dn_cb(void *cbdata __attribute__((unused)),
  1186. const Slapi_Entry *rawentry __attribute__((unused)),
  1187. Slapi_Entry *ad_entry __attribute__((unused)),
  1188. char **new_dn_string,
  1189. const Slapi_DN *ds_suffix __attribute__((unused)),
  1190. const Slapi_DN *ad_suffix __attribute__((unused)))
  1191. {
  1192. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1193. "--> posix_winsync_get_new_ds_user_dn_cb -- old dn [%s] -- begin\n",
  1194. *new_dn_string);
  1195. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1196. "<-- posix_winsync_get_new_ds_user_dn_cb -- new dn [%s] -- end\n",
  1197. *new_dn_string);
  1198. return;
  1199. }
  1200. static void
  1201. posix_winsync_get_new_ds_group_dn_cb(void *cbdata __attribute__((unused)),
  1202. const Slapi_Entry *rawentry __attribute__((unused)),
  1203. Slapi_Entry *ad_entry __attribute__((unused)),
  1204. char **new_dn_string __attribute__((unused)),
  1205. const Slapi_DN *ds_suffix __attribute__((unused)),
  1206. const Slapi_DN *ad_suffix __attribute__((unused)))
  1207. {
  1208. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1209. "--> posix_winsync_get_new_ds_group_dn_cb -- begin\n");
  1210. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1211. "<-- posix_winsync_get_new_ds_group_dn_cb -- end\n");
  1212. return;
  1213. }
  1214. static void
  1215. posix_winsync_pre_ad_mod_user_mods_cb(void *cbdata,
  1216. const Slapi_Entry *rawentry,
  1217. const Slapi_DN *local_dn __attribute__((unused)),
  1218. const Slapi_Entry *ds_entry,
  1219. LDAPMod * const *origmods,
  1220. Slapi_DN *remote_dn __attribute__((unused)),
  1221. LDAPMod ***modstosend)
  1222. {
  1223. Slapi_Mods *smods;
  1224. Slapi_Mods *new_smods;
  1225. LDAPMod *mod = NULL;
  1226. windows_attribute_map *attr_map = user_attribute_map;
  1227. plugin_op_started();
  1228. if(!get_plugin_started()){
  1229. plugin_op_finished();
  1230. return;
  1231. }
  1232. smods = slapi_mods_new();
  1233. new_smods = slapi_mods_new();
  1234. if (posix_winsync_config_get_msSFUSchema())
  1235. attr_map = user_mssfu_attribute_map;
  1236. /* mod if changed objectclass: posixAccount, uidnumber, gidnumber, homeDirectory, loginShell */
  1237. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1238. "--> _pre_ad_mod_user_mods_cb -- begin DS account [%s] \n",
  1239. slapi_entry_get_dn_const(ds_entry));
  1240. /* wrap the modstosend in a Slapi_Mods for convenience */
  1241. slapi_mods_init_passin(new_smods, *modstosend);
  1242. slapi_mods_init_byref(smods, (LDAPMod**) origmods);
  1243. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  1244. size_t i = 0;
  1245. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1246. "_pre_ad_mod_user_mods_cb -- check modify type %s\n", mod->mod_type);
  1247. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  1248. if (0 == slapi_attr_type_cmp(mod->mod_type, attr_map[i].ldap_attribute_name,
  1249. SLAPI_TYPE_CMP_SUBTYPE)) {
  1250. Slapi_Mod *mysmod = slapi_mod_new();
  1251. slapi_mod_init_byval(mysmod, mod);
  1252. slapi_mod_set_type(mysmod, attr_map[i].windows_attribute_name);
  1253. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(mysmod));
  1254. slapi_mod_free(&mysmod);
  1255. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1256. "_pre_ad_mod_user_mods_cb -- add modify %s DS account [%s]\n",
  1257. attr_map[i].windows_attribute_name,
  1258. slapi_entry_get_dn_const(ds_entry));
  1259. if (0 == slapi_attr_type_cmp(mod->mod_type, "uidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  1260. Slapi_Mod *ocsmod = slapi_mod_new();
  1261. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1262. "_pre_ad_mod_user_mods_cb -- add NisDomain\n");
  1263. addNisDomainName(ocsmod, ds_entry);
  1264. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(ocsmod));
  1265. slapi_mod_free(&ocsmod);
  1266. }
  1267. }
  1268. }
  1269. if (0 == slapi_attr_type_cmp(mod->mod_type, "nsRoleDN", SLAPI_TYPE_CMP_SUBTYPE)) {
  1270. int dummy = 0;
  1271. sync_acct_disable(cbdata, rawentry, (Slapi_Entry *) ds_entry, ACCT_DISABLE_TO_AD, NULL,
  1272. new_smods, &dummy);
  1273. }
  1274. }
  1275. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  1276. for (mod = slapi_mods_get_first_mod(new_smods); mod; mod
  1277. = slapi_mods_get_next_mod(new_smods)) {
  1278. slapi_mod_dump(mod, 0);
  1279. }
  1280. }
  1281. *modstosend = slapi_mods_get_ldapmods_passout(new_smods);
  1282. slapi_mods_free(&smods);
  1283. slapi_mods_free(&new_smods);
  1284. plugin_op_finished();
  1285. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1286. "<-- _pre_ad_mod_user_mods_cb -- end\n");
  1287. return;
  1288. }
  1289. static void
  1290. posix_winsync_pre_ad_mod_group_mods_cb(void *cbdata __attribute__((unused)),
  1291. const Slapi_Entry *rawentry __attribute__((unused)),
  1292. const Slapi_DN *local_dn __attribute__((unused)),
  1293. const Slapi_Entry *ds_entry,
  1294. LDAPMod * const *origmods,
  1295. Slapi_DN *remote_dn __attribute__((unused)),
  1296. LDAPMod ***modstosend)
  1297. {
  1298. Slapi_Mods *smods;
  1299. Slapi_Mods *new_smods;
  1300. LDAPMod *mod = NULL;
  1301. windows_attribute_map *attr_map = group_attribute_map;
  1302. plugin_op_started();
  1303. if(!get_plugin_started()){
  1304. plugin_op_finished();
  1305. return;
  1306. }
  1307. smods = slapi_mods_new();
  1308. new_smods = slapi_mods_new();
  1309. if (posix_winsync_config_get_msSFUSchema())
  1310. attr_map = group_mssfu_attribute_map;
  1311. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1312. "--> _pre_ad_mod_group_mods_cb -- begin\n");
  1313. /* wrap the modstosend in a Slapi_Mods for convenience */
  1314. slapi_mods_init_passin(new_smods, *modstosend);
  1315. slapi_mods_init_byref(smods, (LDAPMod**) origmods);
  1316. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  1317. size_t i = 0;
  1318. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1319. "_pre_ad_mod_group_mods_cb -- check modify type %s\n", mod->mod_type);
  1320. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  1321. if (0 == slapi_attr_type_cmp(mod->mod_type, attr_map[i].ldap_attribute_name,
  1322. SLAPI_TYPE_CMP_SUBTYPE)) {
  1323. Slapi_Mod *mysmod = slapi_mod_new();
  1324. if (mod->mod_op & LDAP_MOD_DELETE) {
  1325. slapi_mod_init(mysmod, 0);
  1326. slapi_mod_set_operation(mysmod, LDAP_MOD_DELETE | LDAP_MOD_BVALUES);
  1327. slapi_mod_set_type(mysmod, attr_map[i].windows_attribute_name);
  1328. } else {
  1329. slapi_mod_init_byval(mysmod, mod);
  1330. slapi_mod_set_type(mysmod, attr_map[i].windows_attribute_name);
  1331. if (0 == slapi_attr_type_cmp(mod->mod_type, "gidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  1332. Slapi_Mod *ocsmod = slapi_mod_new();
  1333. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1334. "_pre_ad_mod_group_mods_cb -- add NisDomain\n");
  1335. addNisDomainName(ocsmod, ds_entry);
  1336. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(ocsmod));
  1337. slapi_mod_free(&ocsmod);
  1338. }
  1339. }
  1340. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(mysmod));
  1341. slapi_mod_free(&mysmod);
  1342. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1343. "_pre_ad_mod_group_mods_cb -- add modify %s DS account [%s]\n",
  1344. attr_map[i].windows_attribute_name,
  1345. slapi_entry_get_dn_const(ds_entry));
  1346. }
  1347. }
  1348. }
  1349. *modstosend = slapi_mods_get_ldapmods_passout(new_smods);
  1350. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  1351. for (mod = slapi_mods_get_first_mod(new_smods); mod;
  1352. mod = slapi_mods_get_next_mod(new_smods)) {
  1353. slapi_mod_dump(mod, 0);
  1354. }
  1355. }
  1356. slapi_mods_free(&smods);
  1357. slapi_mods_free(&new_smods);
  1358. plugin_op_finished();
  1359. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1360. "<-- _pre_ad_mod_group_mods_cb -- end\n");
  1361. return;
  1362. }
  1363. static int
  1364. posix_winsync_can_add_entry_to_ad_cb(void *cbdata __attribute__((unused)),
  1365. const Slapi_Entry *local_entry __attribute__((unused)),
  1366. const Slapi_DN *remote_dn __attribute__((unused)))
  1367. {
  1368. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1369. "--> posix_winsync_can_add_entry_to_ad_cb -- begin\n");
  1370. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1371. "<-- posix_winsync_can_add_entry_to_ad_cb -- end\n");
  1372. return 1; /* false - do not allow entries to be added to ad */
  1373. }
  1374. static void
  1375. posix_winsync_begin_update_cb(void *cbdata __attribute__((unused)),
  1376. const Slapi_DN *ds_subtree __attribute__((unused)),
  1377. const Slapi_DN *ad_subtree __attribute__((unused)),
  1378. int is_total __attribute__((unused)))
  1379. {
  1380. plugin_op_started();
  1381. if(!get_plugin_started()){
  1382. plugin_op_finished();
  1383. return;
  1384. }
  1385. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1386. "--> posix_winsync_begin_update_cb -- begin\n");
  1387. posix_winsync_config_reset_MOFTaskCreated();
  1388. plugin_op_finished();
  1389. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1390. "<-- posix_winsync_begin_update_cb -- end\n");
  1391. return;
  1392. }
  1393. static void
  1394. posix_winsync_end_update_cb(void *cbdata __attribute__((unused)),
  1395. const Slapi_DN *ds_subtree,
  1396. const Slapi_DN *ad_subtree __attribute__((unused)),
  1397. int is_total __attribute__((unused)))
  1398. {
  1399. plugin_op_started();
  1400. if(!get_plugin_started()){
  1401. plugin_op_finished();
  1402. return;
  1403. }
  1404. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1405. "--> posix_winsync_end_update_cb -- begin %d %d\n",
  1406. posix_winsync_config_get_MOFTaskCreated(),
  1407. posix_winsync_config_get_createMOFTask());
  1408. if (1 && posix_winsync_config_get_createMOFTask()) {
  1409. /* add a task to schedule memberof Plugin for fix memebrof attributs */
  1410. Slapi_PBlock *pb = slapi_pblock_new();
  1411. Slapi_Entry *e_task = slapi_entry_alloc();
  1412. int rc = 0;
  1413. char *dn = slapi_create_dn_string("cn=%s,cn=%s,cn=tasks,cn=config",
  1414. posix_winsync_plugin_name, MEMBEROFTASK);
  1415. if (NULL == dn) {
  1416. slapi_pblock_destroy(pb);
  1417. slapi_entry_free(e_task);
  1418. slapi_log_err(SLAPI_LOG_ERR, posix_winsync_plugin_name,
  1419. "posix_winsync_end_update_cb: "
  1420. "failed to create task dn: cn=%s,%s,cn=tasks,cn=config\n",
  1421. posix_winsync_plugin_name, MEMBEROFTASK);
  1422. plugin_op_finished();
  1423. return;
  1424. }
  1425. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1426. "--> posix_winsync_end_update_cb, create task %s\n", dn);
  1427. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1428. "--> posix_winsync_end_update_cb, init'ing task\n");
  1429. slapi_entry_init(e_task, dn, NULL);
  1430. slapi_entry_add_string(e_task, "cn", slapi_ch_strdup(posix_winsync_plugin_name));
  1431. slapi_entry_add_string(e_task, "objectClass", "extensibleObject");
  1432. slapi_entry_add_string(e_task, "basedn", slapi_sdn_get_dn(ds_subtree));
  1433. slapi_add_entry_internal_set_pb(pb, e_task, NULL, posix_winsync_get_plugin_identity(), 0);
  1434. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1435. "--> posix_winsync_end_update_cb, adding task\n");
  1436. slapi_add_internal_pb(pb);
  1437. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1438. "--> posix_winsync_end_update_cb, retrieving return code\n");
  1439. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  1440. if (LDAP_ALREADY_EXISTS == rc) {
  1441. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1442. "posix_winsync_end_update_cb: "
  1443. "task entry %s already exists\n",
  1444. posix_winsync_plugin_name);
  1445. } else if (rc != 0) {
  1446. slapi_log_err(SLAPI_LOG_ERR, posix_winsync_plugin_name,
  1447. "posix_winsync_end_update_cb: "
  1448. "failed to add task entry (%d)\n", rc);
  1449. } else {
  1450. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1451. "posix_winsync_end_update_cb: "
  1452. "add task entry\n");
  1453. }
  1454. /* slapi_entry_free(e_task); */
  1455. slapi_pblock_destroy(pb);
  1456. pb = NULL;
  1457. posix_winsync_config_reset_MOFTaskCreated();
  1458. }
  1459. plugin_op_finished();
  1460. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1461. "<-- posix_winsync_end_update_cb -- end\n");
  1462. return;
  1463. }
  1464. static void
  1465. posix_winsync_destroy_agmt_cb(void *cbdata __attribute__((unused)),
  1466. const Slapi_DN *ds_subtree __attribute__((unused)),
  1467. const Slapi_DN *ad_subtree __attribute__((unused)))
  1468. {
  1469. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1470. "--> posix_winsync_destroy_agmt_cb -- begin\n");
  1471. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1472. "<-- posix_winsync_destroy_agmt_cb -- end\n");
  1473. return;
  1474. }
  1475. static void
  1476. posix_winsync_post_ad_mod_user_cb(void *cookie __attribute__((unused)),
  1477. const Slapi_Entry *rawentry __attribute__((unused)),
  1478. Slapi_Entry *ad_entry __attribute__((unused)),
  1479. Slapi_Entry *ds_entry __attribute__((unused)),
  1480. Slapi_Mods *smods __attribute__((unused)),
  1481. int *result __attribute__((unused)))
  1482. {
  1483. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1484. "--> posix_winsync_post_ad_mod_user_cb -- begin\n");
  1485. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1486. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1487. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1488. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1489. #endif
  1490. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1491. "<-- posix_winsync_post_ad_mod_user_cb -- end\n");
  1492. return;
  1493. }
  1494. static void
  1495. posix_winsync_post_ad_mod_group_cb(void *cookie __attribute__((unused)),
  1496. const Slapi_Entry *rawentry __attribute__((unused)),
  1497. Slapi_Entry *ad_entry __attribute__((unused)),
  1498. Slapi_Entry *ds_entry __attribute__((unused)),
  1499. Slapi_Mods *smods __attribute__((unused)),
  1500. int *result __attribute__((unused)))
  1501. {
  1502. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1503. "--> posix_winsync_post_ad_mod_group_cb -- begin\n");
  1504. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1505. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1506. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1507. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1508. #endif
  1509. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1510. "<-- posix_winsync_post_ad_mod_group_cb -- end\n");
  1511. return;
  1512. }
  1513. static void
  1514. posix_winsync_post_ds_mod_user_cb(void *cookie __attribute__((unused)),
  1515. const Slapi_Entry *rawentry __attribute__((unused)),
  1516. Slapi_Entry *ad_entry __attribute__((unused)),
  1517. Slapi_Entry *ds_entry __attribute__((unused)),
  1518. Slapi_Mods *smods __attribute__((unused)),
  1519. int *result __attribute__((unused)))
  1520. {
  1521. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1522. "--> posix_winsync_post_ds_mod_user_cb -- begin\n");
  1523. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1524. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1525. "Result of modifying DS entry [%s] was [%d:%s]\n",
  1526. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1527. #endif
  1528. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1529. "<-- posix_winsync_post_ds_mod_user_cb -- end\n");
  1530. return;
  1531. }
  1532. static void
  1533. posix_winsync_post_ds_mod_group_cb(void *cookie __attribute__((unused)),
  1534. const Slapi_Entry *rawentry __attribute__((unused)),
  1535. Slapi_Entry *ad_entry __attribute__((unused)),
  1536. Slapi_Entry *ds_entry __attribute__((unused)),
  1537. Slapi_Mods *smods __attribute__((unused)),
  1538. int *result __attribute__((unused)))
  1539. {
  1540. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1541. "--> posix_winsync_post_ds_mod_group_cb -- begin\n");
  1542. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1543. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1544. "Result of modifying DS entry [%s] was [%d:%s]\n",
  1545. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1546. #endif
  1547. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1548. "<-- posix_winsync_post_ds_mod_group_cb -- end\n");
  1549. return;
  1550. }
  1551. static void
  1552. posix_winsync_post_ds_add_user_cb(void *cookie __attribute__((unused)),
  1553. const Slapi_Entry *rawentry __attribute__((unused)),
  1554. Slapi_Entry *ad_entry __attribute__((unused)),
  1555. Slapi_Entry *ds_entry __attribute__((unused)),
  1556. int *result __attribute__((unused)))
  1557. {
  1558. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1559. "--> posix_winsync_post_ds_add_user_cb -- begin\n");
  1560. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1561. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1562. "Result of adding DS entry [%s] was [%d:%s]\n",
  1563. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1564. #endif
  1565. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1566. "<-- posix_winsync_post_ds_add_user_cb -- end\n");
  1567. return;
  1568. }
  1569. static void
  1570. posix_winsync_post_ds_add_group_cb(void *cookie __attribute__((unused)),
  1571. const Slapi_Entry *rawentry __attribute__((unused)),
  1572. Slapi_Entry *ad_entry __attribute__((unused)),
  1573. Slapi_Entry *ds_entry __attribute__((unused)),
  1574. int *result __attribute__((unused)))
  1575. {
  1576. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1577. "--> posix_winsync_post_ds_add_group_cb -- begin\n");
  1578. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1579. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1580. "Result of adding DS entry [%s] was [%d:%s]\n",
  1581. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1582. #endif
  1583. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1584. "<-- posix_winsync_post_ds_add_group_cb -- end\n");
  1585. return;
  1586. }
  1587. /* winsync_plugin_call_pre_ad_add_user_cb(prp->agmt, mapped_entry, e); */
  1588. static void
  1589. posix_winsync_pre_ad_add_user_cb(void *cookie __attribute__((unused)),
  1590. Slapi_Entry *ad_entry,
  1591. Slapi_Entry *ds_entry)
  1592. {
  1593. Slapi_Attr * obj_attr = NULL; /* Entry attributes */
  1594. windows_attribute_map *attr_map=user_attribute_map;
  1595. int rc = 0;
  1596. plugin_op_started();
  1597. if(!get_plugin_started()){
  1598. plugin_op_finished();
  1599. return;
  1600. }
  1601. if(posix_winsync_config_get_msSFUSchema())
  1602. attr_map=user_mssfu_attribute_map;
  1603. /* if ds_entry has oc posixAccount add uidnumber, gidnumber, homeDirectory, loginShell, gecos */
  1604. /* syncing/mapping of nsaccountlock -> userAccountControl will already done by the normal Win Sync-Service */
  1605. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1606. "--> _pre_ad_add_user_cb -- begin DS account [%s] \n", slapi_entry_get_dn_const(ds_entry));
  1607. rc = slapi_entry_attr_find(ds_entry, "objectclass", &obj_attr);
  1608. if (rc == 0) { /* Found objectclasses, so... */
  1609. int i;
  1610. Slapi_Value * value = NULL; /* Attribute values */
  1611. slapi_log_err(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,"_pre_ad_add_user_cb -- test objectclass posixAccount\n");
  1612. for (
  1613. i = slapi_attr_first_value(obj_attr, &value);
  1614. i != -1;
  1615. i = slapi_attr_next_value(obj_attr, i, &value)
  1616. ) {
  1617. const char * oc = NULL;
  1618. oc = slapi_value_get_string(value);
  1619. slapi_log_err(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,"_pre_ad_add_user_cb -- oc: %s \n", oc);
  1620. if (strncasecmp(oc,"posixAccount",13)==0){ /* entry has objectclass posixAccount */
  1621. Slapi_Attr *attr = NULL;
  1622. char *nisdomainname = getNisDomainName(ds_entry);
  1623. for (rc = slapi_entry_first_attr(ds_entry, &attr); attr && (rc == 0);
  1624. rc = slapi_entry_next_attr(ds_entry, attr, &attr))
  1625. {
  1626. char *type = NULL;
  1627. size_t i = 0;
  1628. slapi_attr_get_type( attr, &type );
  1629. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1630. "_pre_ad_add_user_cb -- check add attr: %s\n", type);
  1631. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  1632. if (0 == slapi_attr_type_cmp(type,attr_map[i].ldap_attribute_name, SLAPI_TYPE_CMP_SUBTYPE)){
  1633. Slapi_ValueSet *vs = NULL;
  1634. slapi_attr_get_valueset(attr,&vs);
  1635. slapi_entry_add_valueset(ad_entry, attr_map[i].windows_attribute_name, vs);
  1636. slapi_valueset_free(vs);
  1637. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1638. "--> _pre_ad_add_user_cb -- "
  1639. "adding val for [%s] to new entry [%s]\n",
  1640. type, slapi_entry_get_dn_const(ad_entry));
  1641. }
  1642. }
  1643. }
  1644. if (nisdomainname) {
  1645. slapi_entry_add_value(ad_entry,
  1646. "msSFU30NisDomain", slapi_value_new_string(nisdomainname));
  1647. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1648. "--> _pre_ad_add_user_cb -- "
  1649. "adding val for [%s] to new entry [%s]\n",
  1650. "msSFU30NisDomain", nisdomainname);
  1651. slapi_ch_free_string(&nisdomainname);
  1652. }
  1653. }
  1654. }
  1655. }
  1656. plugin_op_finished();
  1657. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1658. "<-- _pre_ad_add_user_cb -- end\n");
  1659. return;
  1660. }
  1661. static void
  1662. posix_winsync_pre_ad_add_group_cb(void *cookie __attribute__((unused)),
  1663. Slapi_Entry *ad_entry,
  1664. Slapi_Entry *ds_entry)
  1665. {
  1666. Slapi_Attr * obj_attr = NULL; /* Entry attributes */
  1667. windows_attribute_map *attr_map = group_attribute_map;
  1668. int rc = 0;
  1669. plugin_op_started();
  1670. if(!get_plugin_started()){
  1671. plugin_op_finished();
  1672. return;
  1673. }
  1674. if (posix_winsync_config_get_msSFUSchema()) {
  1675. attr_map=group_mssfu_attribute_map;
  1676. }
  1677. /* if ds_entry has oc posixGroup add gidnumber, ... */
  1678. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1679. "--> _pre_ad_add_group_cb -- begin DS account [%s] \n", slapi_entry_get_dn_const(ds_entry));
  1680. rc = slapi_entry_attr_find(ds_entry, "objectclass", &obj_attr);
  1681. if (rc == 0) { /* Found objectclasses, so... */
  1682. int i;
  1683. Slapi_Value * value = NULL; /* Attribute values */
  1684. slapi_log_err(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,"_pre_ad_add_group_cb -- test objectclass posixGroup\n");
  1685. for (i = slapi_attr_first_value(obj_attr, &value);
  1686. i != -1;
  1687. i = slapi_attr_next_value(obj_attr, i, &value)) {
  1688. const char * oc = NULL;
  1689. oc = slapi_value_get_string(value);
  1690. if (strncasecmp(oc,"posixGroup",11)==0){ /* entry has objectclass posixGroup */
  1691. Slapi_Attr *attr = NULL;
  1692. char *nisdomainname = getNisDomainName(ds_entry);
  1693. for (rc = slapi_entry_first_attr(ds_entry, &attr); rc == 0;
  1694. rc = slapi_entry_next_attr(ds_entry, attr, &attr))
  1695. {
  1696. char *type = NULL;
  1697. int j = 0;
  1698. slapi_attr_get_type( attr, &type );
  1699. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1700. "_pre_ad_add_group_cb -- check add attr: %s\n", type);
  1701. for (j = 0; attr_map && attr_map[j].windows_attribute_name != NULL; j++) {
  1702. if (0 == slapi_attr_type_cmp(type,attr_map[j].ldap_attribute_name, SLAPI_TYPE_CMP_SUBTYPE)){
  1703. Slapi_ValueSet *vs = NULL;
  1704. slapi_attr_get_valueset(attr,&vs);
  1705. slapi_entry_add_valueset(ad_entry, attr_map[j].windows_attribute_name, vs);
  1706. slapi_valueset_free(vs);
  1707. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1708. "--> _pre_ad_add_group_cb -- "
  1709. "adding val for [%s] to new entry [%s]\n",
  1710. type, slapi_entry_get_dn_const(ad_entry));
  1711. }
  1712. }
  1713. }
  1714. if (nisdomainname) {
  1715. slapi_entry_add_value(ad_entry, "msSFU30NisDomain", slapi_value_new_string(nisdomainname));
  1716. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1717. "--> _pre_ad_add_group_cb -- "
  1718. "adding val for [%s] to new entry [%s]\n",
  1719. "msSFU30NisDomain", nisdomainname);
  1720. slapi_ch_free_string(&nisdomainname);
  1721. }
  1722. }
  1723. }
  1724. }
  1725. plugin_op_finished();
  1726. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1727. "<-- _pre_ad_add_group_cb -- end\n");
  1728. return;
  1729. }
  1730. static void
  1731. posix_winsync_post_ad_add_user_cb(void *cookie __attribute__((unused)),
  1732. Slapi_Entry *ds_entry __attribute__((unused)),
  1733. Slapi_Entry *ad_entry __attribute__((unused)),
  1734. int *result __attribute__((unused)))
  1735. {
  1736. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1737. "--> posix_winsync_post_ad_add_user_cb -- begin\n");
  1738. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1739. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1740. "Result of adding AD entry [%s] was [%d:%s]\n",
  1741. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1742. #endif
  1743. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1744. "<-- posix_winsync_post_ad_add_user_cb -- end\n");
  1745. return;
  1746. }
  1747. static void
  1748. posix_winsync_post_ad_add_group_cb(void *cookie __attribute__((unused)),
  1749. Slapi_Entry *ds_entry __attribute__((unused)),
  1750. Slapi_Entry *ad_entry __attribute__((unused)),
  1751. int *result __attribute__((unused)))
  1752. {
  1753. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1754. "--> posix_winsync_post_ad_add_group_cb -- begin\n");
  1755. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1756. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1757. "Result of adding AD entry [%s] was [%d:%s]\n",
  1758. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1759. #endif
  1760. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1761. "<-- posix_winsync_post_ad_add_group_cb -- end\n");
  1762. return;
  1763. }
  1764. static void
  1765. posix_winsync_post_ad_mod_user_mods_cb(void *cookie __attribute__((unused)),
  1766. const Slapi_Entry *rawentry __attribute__((unused)),
  1767. const Slapi_DN *local_dn __attribute__((unused)),
  1768. const Slapi_Entry *ds_entry __attribute__((unused)),
  1769. LDAPMod * const *origmods __attribute__((unused)),
  1770. Slapi_DN *remote_dn __attribute__((unused)),
  1771. LDAPMod ***modstosend __attribute__((unused)),
  1772. int *result __attribute__((unused)))
  1773. {
  1774. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1775. "--> posix_winsync_post_ad_mod_user_mods_cb -- begin\n");
  1776. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1777. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1778. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1779. slapi_sdn_get_dn(remote_dn), *result, ldap_err2string(*result));
  1780. #endif
  1781. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1782. "<-- posix_winsync_post_ad_mod_user_mods_cb -- end\n");
  1783. return;
  1784. }
  1785. static void
  1786. posix_winsync_post_ad_mod_group_mods_cb(void *cookie __attribute__((unused)),
  1787. const Slapi_Entry *rawentry __attribute__((unused)),
  1788. const Slapi_DN *local_dn __attribute__((unused)),
  1789. const Slapi_Entry *ds_entry __attribute__((unused)),
  1790. LDAPMod * const *origmods __attribute__((unused)),
  1791. Slapi_DN *remote_dn __attribute__((unused)),
  1792. LDAPMod ***modstosend __attribute__((unused)),
  1793. int *result __attribute__((unused)))
  1794. {
  1795. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1796. "--> posix_winsync_post_ad_mod_group_mods_cb -- begin\n");
  1797. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1798. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1799. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1800. slapi_sdn_get_dn(remote_dn), *result, ldap_err2string(*result));
  1801. #endif
  1802. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1803. "<-- posix_winsync_post_ad_mod_group_mods_cb -- end\n");
  1804. return;
  1805. }
  1806. #define DEFAULT_PRECEDENCE 25
  1807. static int precedence = DEFAULT_PRECEDENCE; /* default */
  1808. static int posix_winsync_precedence(void)
  1809. {
  1810. return precedence;
  1811. }
  1812. static void *posix_winsync_api[] = { NULL, /* reserved for api broker use, must be zero */
  1813. posix_winsync_agmt_init,
  1814. posix_winsync_dirsync_search_params_cb,
  1815. posix_winsync_pre_ad_search_cb,
  1816. posix_winsync_pre_ds_search_entry_cb,
  1817. posix_winsync_pre_ds_search_all_cb,
  1818. posix_winsync_pre_ad_mod_user_cb,
  1819. posix_winsync_pre_ad_mod_group_cb,
  1820. posix_winsync_pre_ds_mod_user_cb,
  1821. posix_winsync_pre_ds_mod_group_cb,
  1822. posix_winsync_pre_ds_add_user_cb,
  1823. posix_winsync_pre_ds_add_group_cb,
  1824. posix_winsync_get_new_ds_user_dn_cb,
  1825. posix_winsync_get_new_ds_group_dn_cb,
  1826. posix_winsync_pre_ad_mod_user_mods_cb,
  1827. posix_winsync_pre_ad_mod_group_mods_cb,
  1828. posix_winsync_can_add_entry_to_ad_cb,
  1829. posix_winsync_begin_update_cb,
  1830. posix_winsync_end_update_cb,
  1831. posix_winsync_destroy_agmt_cb,
  1832. posix_winsync_post_ad_mod_user_cb,
  1833. posix_winsync_post_ad_mod_group_cb,
  1834. posix_winsync_post_ds_mod_user_cb,
  1835. posix_winsync_post_ds_mod_group_cb,
  1836. posix_winsync_post_ds_add_user_cb,
  1837. posix_winsync_post_ds_add_group_cb,
  1838. posix_winsync_pre_ad_add_user_cb,
  1839. posix_winsync_pre_ad_add_group_cb,
  1840. posix_winsync_post_ad_add_user_cb,
  1841. posix_winsync_post_ad_add_group_cb,
  1842. posix_winsync_post_ad_mod_user_mods_cb,
  1843. posix_winsync_post_ad_mod_group_mods_cb,
  1844. posix_winsync_precedence
  1845. };
  1846. static Slapi_ComponentId *posix_winsync_plugin_id = NULL;
  1847. /*
  1848. ** Plugin identity mgmt
  1849. */
  1850. void
  1851. posix_winsync_set_plugin_identity(void * identity)
  1852. {
  1853. posix_winsync_plugin_id = identity;
  1854. }
  1855. void *
  1856. posix_winsync_get_plugin_identity(void)
  1857. {
  1858. return posix_winsync_plugin_id;
  1859. }
  1860. static int
  1861. posix_winsync_plugin_start(Slapi_PBlock *pb)
  1862. {
  1863. int rc;
  1864. Slapi_Entry *config_e = NULL; /* entry containing plugin config */
  1865. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1866. "--> posix_winsync_plugin_start -- begin\n");
  1867. if (slapi_apib_register(WINSYNC_v3_0_GUID, posix_winsync_api)) {
  1868. slapi_log_err(SLAPI_LOG_ERR, posix_winsync_plugin_name,
  1869. "<-- posix_winsync_plugin_start -- failed to register winsync api -- end\n");
  1870. return -1;
  1871. }
  1872. if (slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &config_e) != 0) {
  1873. slapi_log_err(SLAPI_LOG_ERR, posix_winsync_plugin_name, "posix_winsync_plugin_start - "
  1874. "Missing config entry\n");
  1875. return (-1);
  1876. }
  1877. if ((rc = posix_winsync_config(config_e)) != LDAP_SUCCESS) {
  1878. slapi_log_err(SLAPI_LOG_ERR, posix_winsync_plugin_name, "posix_winsync_plugin_start - "
  1879. "configuration failed (%s)\n", ldap_err2string(rc));
  1880. return (-1);
  1881. }
  1882. g_plugin_started = 1;
  1883. op_counter = slapi_counter_new();
  1884. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1885. "<-- posix_winsync_plugin_start -- registered; end\n");
  1886. return 0;
  1887. }
  1888. static int
  1889. posix_winsync_plugin_close(Slapi_PBlock *pb __attribute__((unused)))
  1890. {
  1891. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1892. "--> posix_winsync_plugin_close -- begin\n");
  1893. g_plugin_started = 0;
  1894. posix_winsync_plugin_op_all_finished();
  1895. slapi_apib_unregister(WINSYNC_v1_0_GUID);
  1896. posix_winsync_config_free();
  1897. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1898. "<-- posix_winsync_plugin_close -- end\n");
  1899. return 0;
  1900. }
  1901. /* this is the slapi plugin init function,
  1902. not the one used by the winsync api
  1903. */
  1904. int
  1905. posix_winsync_plugin_init(Slapi_PBlock *pb)
  1906. {
  1907. void *plugin_id = NULL;
  1908. Slapi_Entry *confige = NULL;
  1909. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1910. "--> posix_winsync_plugin_init -- begin\n");
  1911. if (slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &confige) && confige) {
  1912. precedence = slapi_entry_attr_get_int(confige, "nsslapd-pluginprecedence");
  1913. if (!precedence) {
  1914. precedence = DEFAULT_PRECEDENCE;
  1915. }
  1916. }
  1917. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0
  1918. || slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN, (void *) posix_winsync_plugin_start) != 0
  1919. || slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN, (void *) posix_winsync_plugin_close) != 0
  1920. || slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *) &posix_winsync_pdesc) != 0) {
  1921. slapi_log_err(SLAPI_LOG_ERR, posix_winsync_plugin_name,
  1922. "posix_winsync_plugin_init - Failed to register plugin -- end\n");
  1923. return -1;
  1924. }
  1925. /* Retrieve and save the plugin identity to later pass to
  1926. internal operations */
  1927. if (slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &plugin_id) != 0) {
  1928. slapi_log_err(SLAPI_LOG_ERR, posix_winsync_plugin_name,
  1929. "posix_winsync_plugin_init - Failed to retrieve plugin identity -- end\n");
  1930. return -1;
  1931. }
  1932. posix_winsync_set_plugin_identity(plugin_id);
  1933. slapi_log_err(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1934. "<-- posix_winsync_plugin_init -- end\n");
  1935. return 0;
  1936. }
  1937. PRUint64
  1938. get_plugin_started()
  1939. {
  1940. return g_plugin_started;
  1941. }
  1942. void
  1943. plugin_op_started()
  1944. {
  1945. slapi_counter_increment(op_counter);
  1946. }
  1947. void
  1948. plugin_op_finished()
  1949. {
  1950. slapi_counter_decrement(op_counter);
  1951. }
  1952. void
  1953. posix_winsync_plugin_op_all_finished()
  1954. {
  1955. while(slapi_counter_get_value(op_counter) > 0){
  1956. PR_Sleep(PR_MillisecondsToInterval(100));
  1957. }
  1958. slapi_counter_destroy(&op_counter);
  1959. }