posix-winsync.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460
  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. while (attr_map[i].windows_attribute_name != NULL) {
  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. i++;
  557. }
  558. if (0 == slapi_attr_type_cmp(type, "nsAccountLock", SLAPI_TYPE_CMP_SUBTYPE))
  559. sync_acct_disable(cbdata, rawentry, ds_entry, ACCT_DISABLE_TO_AD, NULL, smods,
  560. do_modify);
  561. }
  562. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  563. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  564. slapi_mod_dump(mod, 0);
  565. }
  566. }
  567. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  568. "<-- posix_winsync_pre_ad_mod_user_cb -- end\n");
  569. return;
  570. }
  571. static void
  572. posix_winsync_pre_ad_mod_group_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  573. Slapi_Entry *ds_entry, Slapi_Mods *smods, int *do_modify)
  574. {
  575. LDAPMod *mod = NULL;
  576. int rc = 0;
  577. Slapi_Attr *attr = NULL;
  578. windows_attribute_map *attr_map = group_attribute_map;
  579. if (posix_winsync_config_get_msSFUSchema())
  580. attr_map = group_mssfu_attribute_map;
  581. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  582. "--> _pre_ad_mod_group_cb -- begin DS account [%s]\n",
  583. slapi_entry_get_dn_const(ds_entry));
  584. /* called if init Replica: add nisDomain, gidnumber, memberuid, if avail */
  585. for (rc = slapi_entry_first_attr(ds_entry, &attr); rc == 0;
  586. rc = slapi_entry_next_attr(ds_entry, attr, &attr)) {
  587. char *type = NULL;
  588. size_t i = 0;
  589. slapi_attr_get_type(attr, &type);
  590. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  591. "_pre_ad_mod_group_cb -- check modify type %s\n", type);
  592. while (attr_map[i].windows_attribute_name != NULL) {
  593. if (0 == slapi_attr_type_cmp(type, attr_map[i].ldap_attribute_name,
  594. SLAPI_TYPE_CMP_SUBTYPE)) {
  595. Slapi_Attr *ad_attr = NULL;
  596. Slapi_ValueSet *vs = NULL;
  597. char *ad_type = NULL;
  598. int is_present_local;
  599. slapi_attr_get_valueset(attr, &vs);
  600. ad_type = slapi_ch_strdup(attr_map[i].windows_attribute_name);
  601. slapi_entry_attr_find(ad_entry, ad_type, &ad_attr);
  602. is_present_local = (NULL == ad_attr) ? 0 : 1;
  603. if (is_present_local) {
  604. int values_equal = 0;
  605. values_equal = attr_compare_equal(attr, ad_attr);
  606. if (!values_equal) {
  607. slapi_log_error(
  608. SLAPI_LOG_PLUGIN,
  609. posix_winsync_plugin_name,
  610. "_pre_ad_mod_group_cb -- update mods: %s, %s : values are different -> modify\n",
  611. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  612. ad_type);
  613. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, ad_type,
  614. valueset_get_valuearray(vs));
  615. *do_modify = 1;
  616. }
  617. } else {
  618. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, ad_type,
  619. valueset_get_valuearray(vs));
  620. if (0 == slapi_attr_type_cmp(type, "gidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  621. Slapi_Mod *mysmod = slapi_mod_new();
  622. addNisDomainName(mysmod, ds_entry);
  623. slapi_mods_add_ldapmod(smods, slapi_mod_get_ldapmod_passout(mysmod));
  624. slapi_mod_free(&mysmod);
  625. }
  626. *do_modify = 1;
  627. }
  628. slapi_ch_free((void**) &ad_type);
  629. slapi_valueset_free(vs);
  630. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  631. "_pre_ad_mod_group_cb -- add modify %s DS account [%s]\n",
  632. attr_map[i].windows_attribute_name,
  633. slapi_entry_get_dn_const(ds_entry));
  634. }
  635. i++;
  636. }
  637. }
  638. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "_pre_ad_mod_group_cb -- step\n");
  639. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  640. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  641. slapi_mod_dump(mod, 0);
  642. }
  643. }
  644. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  645. "<-- _pre_ad_mod_group_cb -- end\n");
  646. return;
  647. }
  648. static void
  649. posix_winsync_pre_ds_mod_user_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  650. Slapi_Entry *ds_entry, Slapi_Mods *smods, int *do_modify)
  651. {
  652. LDAPMod* mod = NULL;
  653. Slapi_Attr *attr = NULL;
  654. int is_present_local = 0;
  655. int do_modify_local = 0;
  656. int rc;
  657. windows_attribute_map *attr_map = user_attribute_map;
  658. if (posix_winsync_config_get_msSFUSchema())
  659. attr_map = user_mssfu_attribute_map;
  660. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  661. "--> _pre_ds_mod_user_cb -- begin\n");
  662. /* add objectclass: posixAccount, uidnumber ,gidnumber ,homeDirectory, loginshell */
  663. /* in the ad to ds case we have no changelog, so we have to compare the entries */
  664. for (rc = slapi_entry_first_attr(ad_entry, &attr); rc == 0;
  665. rc = slapi_entry_next_attr(ad_entry, attr, &attr)) {
  666. char *type = NULL;
  667. size_t i = 0;
  668. slapi_attr_get_type(attr, &type);
  669. while (attr_map[i].windows_attribute_name != NULL) {
  670. if (0 == slapi_attr_type_cmp(type, attr_map[i].windows_attribute_name,
  671. SLAPI_TYPE_CMP_SUBTYPE)) {
  672. Slapi_Attr *local_attr = NULL;
  673. char *local_type = NULL;
  674. Slapi_ValueSet *vs = NULL;
  675. slapi_attr_get_valueset(attr, &vs);
  676. local_type = slapi_ch_strdup(attr_map[i].ldap_attribute_name);
  677. slapi_entry_attr_find(ds_entry, local_type, &local_attr);
  678. is_present_local = (NULL == local_attr) ? 0 : 1;
  679. if (is_present_local) {
  680. int values_equal = 0;
  681. values_equal = attr_compare_equal(attr, local_attr);
  682. if (!values_equal) {
  683. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  684. "_pre_ds_mod_user_cb -- update mods: %s, %s : values are different -> modify\n",
  685. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  686. local_type);
  687. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, local_type,
  688. valueset_get_valuearray(vs));
  689. *do_modify = 1;
  690. }
  691. } else {
  692. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, local_type,
  693. valueset_get_valuearray(vs));
  694. *do_modify = do_modify_local = 1;
  695. }
  696. slapi_valueset_free(vs);
  697. slapi_ch_free((void**) &local_type);
  698. /* what about if delete all values on windows ????? */
  699. }
  700. i++;
  701. }
  702. }
  703. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  704. "<-- _pre_ds_mod_user_cb present %d modify %d\n", is_present_local,
  705. do_modify_local);
  706. if (!is_present_local && do_modify_local) {
  707. Slapi_Attr *oc_attr = NULL;
  708. Slapi_Value *voc = slapi_value_new();
  709. slapi_value_init_string(voc, "posixAccount");
  710. rc = slapi_entry_attr_find(ds_entry, "objectClass", &oc_attr);
  711. if (rc == 0) {
  712. const struct berval *bv = slapi_value_get_berval(voc);
  713. if (bv && slapi_attr_value_find(oc_attr, bv) != 0) {
  714. Slapi_ValueSet *oc_vs = slapi_valueset_new();
  715. Slapi_Value *oc_nv = slapi_value_new();
  716. slapi_attr_get_valueset(oc_attr, &oc_vs);
  717. slapi_value_init_string(oc_nv, "posixAccount");
  718. slapi_valueset_add_value(oc_vs, oc_nv);
  719. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  720. "<-- _pre_ds_mod_user_cb add oc:posixAccount\n");
  721. slapi_value_init_string(voc, "shadowAccount");
  722. if (slapi_attr_value_find(oc_attr, slapi_value_get_berval(voc)) != 0) {
  723. Slapi_Value *oc_nv = slapi_value_new();
  724. slapi_value_init_string(oc_nv, "shadowAccount");
  725. slapi_valueset_add_value(oc_vs, oc_nv);
  726. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  727. "<-- _pre_ds_mod_user_cb add oc:shadowAccount\n");
  728. }
  729. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, "objectClass",
  730. valueset_get_valuearray(oc_vs));
  731. slapi_value_free(&oc_nv);
  732. slapi_valueset_free(oc_vs);
  733. }
  734. }
  735. slapi_value_free(&voc);
  736. }
  737. sync_acct_disable(cbdata, rawentry, ds_entry, ACCT_DISABLE_TO_DS, NULL, smods, do_modify);
  738. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_mod_user_cb %s %s\n",
  739. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)), (do_modify) ? "modified"
  740. : "not modified");
  741. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  742. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  743. slapi_mod_dump(mod, 0);
  744. }
  745. }
  746. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_mod_user_cb -- end\n");
  747. return;
  748. }
  749. static void
  750. posix_winsync_pre_ds_mod_group_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  751. Slapi_Entry *ds_entry, Slapi_Mods *smods, int *do_modify)
  752. {
  753. LDAPMod* mod = NULL;
  754. Slapi_Attr *attr = NULL;
  755. int is_present_local = 0;
  756. int do_modify_local = 0;
  757. int rc;
  758. windows_attribute_map *attr_map = group_attribute_map;
  759. if (posix_winsync_config_get_msSFUSchema())
  760. attr_map = group_mssfu_attribute_map;
  761. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  762. "--> _pre_ds_mod_group_cb -- begin\n");
  763. /* in the ad to ds case we have no changelog, so we have to compare the entries */
  764. for (rc = slapi_entry_first_attr(ad_entry, &attr); rc == 0; rc
  765. = slapi_entry_next_attr(ad_entry, attr, &attr)) {
  766. char *type = NULL;
  767. Slapi_ValueSet *vs = NULL;
  768. size_t i = 0;
  769. slapi_attr_get_type(attr, &type);
  770. while (attr_map[i].windows_attribute_name != NULL) {
  771. if (0 == slapi_attr_type_cmp(type, attr_map[i].windows_attribute_name,
  772. SLAPI_TYPE_CMP_SUBTYPE)) {
  773. Slapi_Attr *local_attr = NULL;
  774. char *local_type = NULL;
  775. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "1.\n");
  776. slapi_attr_get_valueset(attr, &vs);
  777. local_type = slapi_ch_strdup(attr_map[i].ldap_attribute_name);
  778. slapi_entry_attr_find(ds_entry, local_type, &local_attr);
  779. is_present_local = (NULL == local_attr) ? 0 : 1;
  780. if (is_present_local) {
  781. int values_equal = 0;
  782. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "2.\n");
  783. values_equal = attr_compare_equal(attr, local_attr);
  784. if (!values_equal) {
  785. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  786. "_pre_ds_mod_group_cb -- update mods: %s, %s : values are different -> modify\n",
  787. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  788. local_type);
  789. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, local_type,
  790. valueset_get_valuearray(vs));
  791. *do_modify = 1;
  792. }
  793. } else {
  794. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "3.\n");
  795. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, local_type,
  796. valueset_get_valuearray(vs));
  797. *do_modify = do_modify_local = 1;
  798. }
  799. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "4.\n");
  800. slapi_ch_free((void**) &local_type);
  801. slapi_valueset_free(vs);
  802. /* what about if delete all values on windows ???? */
  803. }
  804. i++;
  805. }
  806. }
  807. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  808. "_pre_ds_mod_group_cb present %d modify %d before\n", is_present_local,
  809. do_modify_local);
  810. if (posix_winsync_config_get_mapMemberUid()) {
  811. memberUidLock();
  812. modGroupMembership(ds_entry, smods, do_modify);
  813. memberUidUnlock();
  814. }
  815. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  816. "_pre_ds_mod_group_cb present %d modify %d\n", is_present_local,
  817. do_modify_local);
  818. if (!is_present_local && do_modify_local) {
  819. Slapi_Attr *oc_attr = NULL;
  820. Slapi_Value *voc = slapi_value_new();
  821. slapi_value_init_string(voc, "posixGroup");
  822. slapi_entry_attr_find(ds_entry, "objectClass", &oc_attr);
  823. if (slapi_attr_value_find(oc_attr, slapi_value_get_berval(voc)) != 0) {
  824. Slapi_ValueSet *oc_vs = NULL;
  825. Slapi_Value *oc_nv = slapi_value_new();
  826. slapi_attr_get_valueset(oc_attr, &oc_vs);
  827. slapi_value_init_string(oc_nv, "posixGroup");
  828. slapi_valueset_add_value(oc_vs, oc_nv);
  829. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  830. "_pre_ds_mod_group_cb add oc:posixGroup\n");
  831. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, "objectClass",
  832. valueset_get_valuearray(oc_vs));
  833. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  834. "_pre_ds_mod_group_cb step\n");
  835. slapi_value_free(&oc_nv);
  836. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  837. "_pre_ds_mod_group_cb step\n");
  838. slapi_valueset_free(oc_vs);
  839. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  840. "_pre_ds_mod_group_cb step\n");
  841. }
  842. slapi_value_free(&voc);
  843. }
  844. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "_pre_ds_mod_group_cb step\n");
  845. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  846. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  847. slapi_mod_dump(mod, 0);
  848. }
  849. }
  850. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  851. "<-- _pre_ds_mod_group_cb -- end\n");
  852. return;
  853. }
  854. static void
  855. posix_winsync_pre_ds_add_user_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  856. Slapi_Entry *ds_entry)
  857. {
  858. Slapi_Attr *attr = NULL;
  859. char *type = NULL;
  860. PRBool posixval = PR_FALSE;
  861. windows_attribute_map *attr_map = user_attribute_map;
  862. if (posix_winsync_config_get_msSFUSchema())
  863. attr_map = user_mssfu_attribute_map;
  864. /* add objectclass: posixAccount, uidnumber, gidnumber, homeDirectory, loginShell */
  865. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  866. "--> _pre_ds_add_user_cb -- begin\n");
  867. for (slapi_entry_first_attr(ad_entry, &attr); attr; slapi_entry_next_attr(ad_entry, attr, &attr)) {
  868. size_t i = 0;
  869. slapi_attr_get_type(attr, &type);
  870. if (!type) {
  871. continue;
  872. }
  873. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "--> _pre_ds_add_user_cb -- "
  874. "look for [%s] to new entry [%s]\n", type, slapi_entry_get_dn_const(ds_entry));
  875. while (attr_map[i].windows_attribute_name != NULL) {
  876. if (slapi_attr_type_cmp(attr_map[i].windows_attribute_name, type,
  877. SLAPI_TYPE_CMP_SUBTYPE) == 0) {
  878. Slapi_ValueSet *svs = NULL;
  879. slapi_attr_get_valueset(attr, &svs);
  880. slapi_entry_add_valueset(ds_entry, attr_map[i].ldap_attribute_name, svs);
  881. slapi_valueset_free(svs);
  882. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  883. "--> _pre_ds_add_user_cb -- "
  884. "adding val for [%s] to new entry [%s]\n", type,
  885. slapi_entry_get_dn_const(ds_entry));
  886. posixval = PR_TRUE;
  887. }
  888. i++;
  889. }
  890. }
  891. if (posixval) {
  892. int rc;
  893. rc = slapi_entry_add_string(ds_entry, "objectClass", "posixAccount");
  894. rc |= slapi_entry_add_string(ds_entry, "objectClass", "shadowAccount");
  895. rc |= slapi_entry_add_string(ds_entry, "objectClass", "inetUser");
  896. if (rc != 0)
  897. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  898. "<-- _pre_ds_add_user_cb -- adding objectclass for new entry failed %d\n",
  899. rc);
  900. }
  901. sync_acct_disable(cbdata, rawentry, ds_entry, ACCT_DISABLE_TO_DS, ds_entry, NULL, NULL);
  902. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_add_user_cb -- end\n");
  903. return;
  904. }
  905. static void
  906. posix_winsync_pre_ds_add_group_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  907. Slapi_Entry *ds_entry)
  908. {
  909. Slapi_Attr *attr = NULL;
  910. char *type = NULL;
  911. PRBool posixval = PR_FALSE;
  912. windows_attribute_map *attr_map = group_attribute_map;
  913. if (posix_winsync_config_get_msSFUSchema())
  914. attr_map = group_mssfu_attribute_map;
  915. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  916. "--> posix_winsync_pre_ds_add_group_cb -- begin\n");
  917. for (slapi_entry_first_attr(ad_entry, &attr); attr; slapi_entry_next_attr(ad_entry, attr, &attr)) {
  918. size_t i = 0;
  919. slapi_attr_get_type(attr, &type);
  920. if (!type) {
  921. continue;
  922. }
  923. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "--> _pre_ds_add_group_cb -- "
  924. "look for [%s] to new entry [%s]\n", type, slapi_entry_get_dn_const(ds_entry));
  925. while (attr_map[i].windows_attribute_name != NULL) {
  926. if (slapi_attr_type_cmp(attr_map[i].windows_attribute_name, type,
  927. SLAPI_TYPE_CMP_SUBTYPE) == 0) {
  928. Slapi_ValueSet *svs = NULL;
  929. slapi_attr_get_valueset(attr, &svs);
  930. slapi_entry_add_valueset(ds_entry, attr_map[i].ldap_attribute_name, svs);
  931. slapi_valueset_free(svs);
  932. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  933. "--> _pre_ds_add_group_cb -- "
  934. "adding val for [%s] to new entry [%s]\n", type,
  935. slapi_entry_get_dn_const(ds_entry));
  936. posixval = PR_TRUE;
  937. }
  938. i++;
  939. }
  940. }
  941. if (posixval) {
  942. int rc;
  943. rc = slapi_entry_add_string(ds_entry, "objectClass", "posixGroup");
  944. if (rc != 0) {
  945. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  946. "<-- _pre_ds_add_group_cb -- adding objectclass for new entry failed %d\n",
  947. rc);
  948. } else {
  949. if (posix_winsync_config_get_mapMemberUid()) {
  950. memberUidLock();
  951. addGroupMembership(ds_entry, ad_entry);
  952. memberUidUnlock();
  953. }
  954. }
  955. }
  956. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  957. "<-- posix_winsync_pre_ds_add_group_cb -- end\n");
  958. return;
  959. }
  960. static void
  961. posix_winsync_get_new_ds_user_dn_cb(void *cbdata, const Slapi_Entry *rawentry,
  962. Slapi_Entry *ad_entry, char **new_dn_string, const Slapi_DN *ds_suffix,
  963. const Slapi_DN *ad_suffix)
  964. {
  965. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  966. "--> posix_winsync_get_new_ds_user_dn_cb -- old dn [%s] -- begin\n",
  967. *new_dn_string);
  968. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  969. "<-- posix_winsync_get_new_ds_user_dn_cb -- new dn [%s] -- end\n",
  970. *new_dn_string);
  971. return;
  972. }
  973. static void
  974. posix_winsync_get_new_ds_group_dn_cb(void *cbdata, const Slapi_Entry *rawentry,
  975. Slapi_Entry *ad_entry, char **new_dn_string, const Slapi_DN *ds_suffix,
  976. const Slapi_DN *ad_suffix)
  977. {
  978. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  979. "--> posix_winsync_get_new_ds_group_dn_cb -- begin\n");
  980. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  981. "<-- posix_winsync_get_new_ds_group_dn_cb -- end\n");
  982. return;
  983. }
  984. static void
  985. posix_winsync_pre_ad_mod_user_mods_cb(void *cbdata, const Slapi_Entry *rawentry,
  986. const Slapi_DN *local_dn, const Slapi_Entry *ds_entry, LDAPMod * const *origmods,
  987. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  988. {
  989. Slapi_Mods *smods = slapi_mods_new();
  990. Slapi_Mods *new_smods = slapi_mods_new();
  991. LDAPMod *mod = NULL;
  992. windows_attribute_map *attr_map = user_attribute_map;
  993. if (posix_winsync_config_get_msSFUSchema())
  994. attr_map = user_mssfu_attribute_map;
  995. /* mod if changed objectclass: posixAccount, uidnumber, gidnumber, homeDirectory, loginShell */
  996. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  997. "--> _pre_ad_mod_user_mods_cb -- begin DS account [%s] \n",
  998. slapi_entry_get_dn_const(ds_entry));
  999. /* wrap the modstosend in a Slapi_Mods for convenience */
  1000. slapi_mods_init_passin(new_smods, *modstosend);
  1001. slapi_mods_init_byref(smods, (LDAPMod**) origmods);
  1002. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  1003. size_t i = 0;
  1004. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1005. "_pre_ad_mod_user_mods_cb -- check modify type %s\n", mod->mod_type);
  1006. while (attr_map[i].windows_attribute_name != NULL) {
  1007. if (0 == slapi_attr_type_cmp(mod->mod_type, attr_map[i].ldap_attribute_name,
  1008. SLAPI_TYPE_CMP_SUBTYPE)) {
  1009. Slapi_Mod *mysmod = slapi_mod_new();
  1010. slapi_mod_init_byval(mysmod, mod);
  1011. slapi_mod_set_type(mysmod, attr_map[i].windows_attribute_name);
  1012. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(mysmod));
  1013. slapi_mod_free(&mysmod);
  1014. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1015. "_pre_ad_mod_user_mods_cb -- add modify %s DS account [%s]\n",
  1016. attr_map[i].windows_attribute_name,
  1017. slapi_entry_get_dn_const(ds_entry));
  1018. if (0 == slapi_attr_type_cmp(mod->mod_type, "uidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  1019. Slapi_Mod *ocsmod = slapi_mod_new();
  1020. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1021. "_pre_ad_mod_user_mods_cb -- add NisDomain\n");
  1022. addNisDomainName(ocsmod, ds_entry);
  1023. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(ocsmod));
  1024. slapi_mod_free(&ocsmod);
  1025. }
  1026. }
  1027. i++;
  1028. }
  1029. if (0 == slapi_attr_type_cmp(mod->mod_type, "nsRoleDN", SLAPI_TYPE_CMP_SUBTYPE)) {
  1030. int dummy = 0;
  1031. sync_acct_disable(cbdata, rawentry, (Slapi_Entry *) ds_entry, ACCT_DISABLE_TO_AD, NULL,
  1032. new_smods, &dummy);
  1033. }
  1034. }
  1035. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  1036. for (mod = slapi_mods_get_first_mod(new_smods); mod; mod
  1037. = slapi_mods_get_next_mod(new_smods)) {
  1038. slapi_mod_dump(mod, 0);
  1039. }
  1040. }
  1041. *modstosend = slapi_mods_get_ldapmods_passout(new_smods);
  1042. slapi_mods_free(&smods);
  1043. slapi_mods_free(&new_smods);
  1044. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1045. "<-- _pre_ad_mod_user_mods_cb -- end\n");
  1046. return;
  1047. }
  1048. static void
  1049. posix_winsync_pre_ad_mod_group_mods_cb(void *cbdata, const Slapi_Entry *rawentry,
  1050. const Slapi_DN *local_dn, const Slapi_Entry *ds_entry, LDAPMod * const *origmods,
  1051. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  1052. {
  1053. Slapi_Mods *smods = slapi_mods_new();
  1054. Slapi_Mods *new_smods = slapi_mods_new();
  1055. LDAPMod *mod = NULL;
  1056. windows_attribute_map *attr_map = group_attribute_map;
  1057. if (posix_winsync_config_get_msSFUSchema())
  1058. attr_map = group_mssfu_attribute_map;
  1059. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1060. "--> _pre_ad_mod_group_mods_cb -- begin\n");
  1061. /* wrap the modstosend in a Slapi_Mods for convenience */
  1062. slapi_mods_init_passin(new_smods, *modstosend);
  1063. slapi_mods_init_byref(smods, (LDAPMod**) origmods);
  1064. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  1065. size_t i = 0;
  1066. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1067. "_pre_ad_mod_group_mods_cb -- check modify type %s\n", mod->mod_type);
  1068. while (attr_map[i].windows_attribute_name != NULL) {
  1069. if (0 == slapi_attr_type_cmp(mod->mod_type, attr_map[i].ldap_attribute_name,
  1070. SLAPI_TYPE_CMP_SUBTYPE)) {
  1071. Slapi_Mod *mysmod = slapi_mod_new();
  1072. if (mod->mod_op & LDAP_MOD_DELETE) {
  1073. slapi_mod_init(mysmod, 0);
  1074. slapi_mod_set_operation(mysmod, LDAP_MOD_DELETE | LDAP_MOD_BVALUES);
  1075. slapi_mod_set_type(mysmod, attr_map[i].windows_attribute_name);
  1076. } else {
  1077. slapi_mod_init_byval(mysmod, mod);
  1078. slapi_mod_set_type(mysmod, attr_map[i].windows_attribute_name);
  1079. if (0
  1080. == slapi_attr_type_cmp(mod->mod_type, "gidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  1081. Slapi_Mod *ocsmod = slapi_mod_new();
  1082. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1083. "_pre_ad_mod_group_mods_cb -- add NisDomain\n");
  1084. addNisDomainName(ocsmod, ds_entry);
  1085. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(ocsmod));
  1086. slapi_mod_free(&ocsmod);
  1087. }
  1088. }
  1089. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(mysmod));
  1090. slapi_mod_free(&mysmod);
  1091. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1092. "_pre_ad_mod_group_mods_cb -- add modify %s DS account [%s]\n",
  1093. attr_map[i].windows_attribute_name,
  1094. slapi_entry_get_dn_const(ds_entry));
  1095. }
  1096. i++;
  1097. }
  1098. }
  1099. *modstosend = slapi_mods_get_ldapmods_passout(new_smods);
  1100. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  1101. for (mod = slapi_mods_get_first_mod(new_smods); mod;
  1102. mod = slapi_mods_get_next_mod(new_smods)) {
  1103. slapi_mod_dump(mod, 0);
  1104. }
  1105. }
  1106. slapi_mods_free(&smods);
  1107. slapi_mods_free(&new_smods);
  1108. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1109. "<-- _pre_ad_mod_group_mods_cb -- end\n");
  1110. return;
  1111. }
  1112. static int
  1113. posix_winsync_can_add_entry_to_ad_cb(void *cbdata, const Slapi_Entry *local_entry,
  1114. const Slapi_DN *remote_dn)
  1115. {
  1116. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1117. "--> posix_winsync_can_add_entry_to_ad_cb -- begin\n");
  1118. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1119. "<-- posix_winsync_can_add_entry_to_ad_cb -- end\n");
  1120. return 1; /* false - do not allow entries to be added to ad */
  1121. }
  1122. static void
  1123. posix_winsync_begin_update_cb(void *cbdata, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree,
  1124. int is_total)
  1125. {
  1126. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1127. "--> posix_winsync_begin_update_cb -- begin\n");
  1128. posix_winsync_config_reset_MOFTaskCreated();
  1129. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1130. "<-- posix_winsync_begin_update_cb -- end\n");
  1131. return;
  1132. }
  1133. static void
  1134. posix_winsync_end_update_cb(void *cbdata, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree,
  1135. int is_total)
  1136. {
  1137. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1138. "--> posix_winsync_end_update_cb -- begin %d %d\n",
  1139. posix_winsync_config_get_MOFTaskCreated(),
  1140. posix_winsync_config_get_createMOFTask());
  1141. if (posix_winsync_config_get_MOFTaskCreated() && posix_winsync_config_get_createMOFTask()) {
  1142. /* add a task to schedule memberof Plugin for fix memebrof attributs */
  1143. Slapi_PBlock *pb = slapi_pblock_new();
  1144. Slapi_Entry *e_task = slapi_entry_alloc();
  1145. int rc = 0;
  1146. char *dn = slapi_create_dn_string("cn=%s,cn=%s,cn=tasks,cn=config",
  1147. posix_winsync_plugin_name, MEMBEROFTASK);
  1148. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1149. "--> posix_winsync_end_update_cb, create task %s\n", dn);
  1150. if (NULL == dn) {
  1151. slapi_pblock_destroy(pb);
  1152. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1153. "posix_winsync_end_update_cb: "
  1154. "failed to create task dn: cn=%s,%s,cn=tasks,cn=config\n",
  1155. posix_winsync_plugin_name, MEMBEROFTASK);
  1156. return;
  1157. }
  1158. slapi_entry_init(e_task, slapi_ch_strdup(dn), NULL);
  1159. slapi_entry_add_string(e_task, "cn", slapi_ch_strdup(posix_winsync_plugin_name));
  1160. slapi_entry_add_string(e_task, "objectClass", "extensibleObject");
  1161. slapi_entry_add_string(e_task, "basedn", slapi_sdn_get_dn(ds_subtree));
  1162. slapi_add_entry_internal_set_pb(pb, e_task, NULL, posix_winsync_get_plugin_identity(), 0);
  1163. slapi_add_internal_pb(pb);
  1164. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  1165. if (rc != 0) {
  1166. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1167. "posix_winsync_end_update_cb: "
  1168. "failed to add task entry\n");
  1169. } else {
  1170. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1171. "posix_winsync_end_update_cb: "
  1172. "add task entry\n");
  1173. }
  1174. /* slapi_entry_free(e_task); */
  1175. slapi_pblock_destroy(pb);
  1176. pb = NULL;
  1177. posix_winsync_config_reset_MOFTaskCreated();
  1178. }
  1179. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1180. "<-- posix_winsync_end_update_cb -- end\n");
  1181. return;
  1182. }
  1183. static void
  1184. posix_winsync_destroy_agmt_cb(void *cbdata, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree)
  1185. {
  1186. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1187. "--> posix_winsync_destroy_agmt_cb -- begin\n");
  1188. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1189. "<-- posix_winsync_destroy_agmt_cb -- end\n");
  1190. return;
  1191. }
  1192. static void *posix_winsync_api[] = { NULL, /* reserved for api broker use, must be zero */
  1193. posix_winsync_agmt_init,
  1194. posix_winsync_dirsync_search_params_cb,
  1195. posix_winsync_pre_ad_search_cb,
  1196. posix_winsync_pre_ds_search_entry_cb,
  1197. posix_winsync_pre_ds_search_all_cb,
  1198. posix_winsync_pre_ad_mod_user_cb,
  1199. posix_winsync_pre_ad_mod_group_cb,
  1200. posix_winsync_pre_ds_mod_user_cb,
  1201. posix_winsync_pre_ds_mod_group_cb,
  1202. posix_winsync_pre_ds_add_user_cb,
  1203. posix_winsync_pre_ds_add_group_cb,
  1204. posix_winsync_get_new_ds_user_dn_cb,
  1205. posix_winsync_get_new_ds_group_dn_cb,
  1206. posix_winsync_pre_ad_mod_user_mods_cb,
  1207. posix_winsync_pre_ad_mod_group_mods_cb,
  1208. posix_winsync_can_add_entry_to_ad_cb,
  1209. posix_winsync_begin_update_cb,
  1210. posix_winsync_end_update_cb,
  1211. posix_winsync_destroy_agmt_cb };
  1212. static Slapi_ComponentId *posix_winsync_plugin_id = NULL;
  1213. /*
  1214. ** Plugin identity mgmt
  1215. */
  1216. void
  1217. posix_winsync_set_plugin_identity(void * identity)
  1218. {
  1219. posix_winsync_plugin_id = identity;
  1220. }
  1221. void *
  1222. posix_winsync_get_plugin_identity()
  1223. {
  1224. return posix_winsync_plugin_id;
  1225. }
  1226. static int
  1227. posix_winsync_plugin_start(Slapi_PBlock *pb)
  1228. {
  1229. int rc;
  1230. Slapi_Entry *config_e = NULL; /* entry containing plugin config */
  1231. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1232. "--> posix_winsync_plugin_start -- begin\n");
  1233. if (slapi_apib_register(WINSYNC_v1_0_GUID, posix_winsync_api)) {
  1234. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1235. "<-- posix_winsync_plugin_start -- failed to register winsync api -- end\n");
  1236. return -1;
  1237. }
  1238. if (slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &config_e) != 0) {
  1239. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name, "missing config entry\n");
  1240. return (-1);
  1241. }
  1242. if ((rc = posix_winsync_config(config_e)) != LDAP_SUCCESS) {
  1243. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name, "configuration failed (%s)\n",
  1244. ldap_err2string(rc));
  1245. return (-1);
  1246. }
  1247. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1248. "<-- posix_winsync_plugin_start -- registered; end\n");
  1249. return 0;
  1250. }
  1251. static int
  1252. posix_winsync_plugin_close(Slapi_PBlock *pb)
  1253. {
  1254. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1255. "--> posix_winsync_plugin_close -- begin\n");
  1256. slapi_apib_unregister(WINSYNC_v1_0_GUID);
  1257. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1258. "<-- posix_winsync_plugin_close -- end\n");
  1259. return 0;
  1260. }
  1261. /* this is the slapi plugin init function,
  1262. not the one used by the winsync api
  1263. */
  1264. int
  1265. posix_winsync_plugin_init(Slapi_PBlock *pb)
  1266. {
  1267. void *plugin_id = NULL;
  1268. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1269. "--> posix_winsync_plugin_init -- begin\n");
  1270. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0
  1271. || slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN, (void *) posix_winsync_plugin_start) != 0
  1272. || slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN, (void *) posix_winsync_plugin_close) != 0
  1273. || slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *) &posix_winsync_pdesc) != 0) {
  1274. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1275. "<-- posix_winsync_plugin_init -- failed to register plugin -- end\n");
  1276. return -1;
  1277. }
  1278. /* Retrieve and save the plugin identity to later pass to
  1279. internal operations */
  1280. if (slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &plugin_id) != 0) {
  1281. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1282. "<-- posix_winsync_plugin_init -- failed to retrieve plugin identity -- end\n");
  1283. return -1;
  1284. }
  1285. posix_winsync_set_plugin_identity(plugin_id);
  1286. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1287. "<-- posix_winsync_plugin_init -- end\n");
  1288. return 0;
  1289. }