1
0

posix-winsync.c 84 KB

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