posix-winsync.c 70 KB

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