posix-winsync.c 81 KB

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