posix-winsync.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452
  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 *posix_winsync_api[] = { NULL, /* reserved for api broker use, must be zero */
  1185. posix_winsync_agmt_init,
  1186. posix_winsync_dirsync_search_params_cb,
  1187. posix_winsync_pre_ad_search_cb,
  1188. posix_winsync_pre_ds_search_entry_cb,
  1189. posix_winsync_pre_ds_search_all_cb,
  1190. posix_winsync_pre_ad_mod_user_cb,
  1191. posix_winsync_pre_ad_mod_group_cb,
  1192. posix_winsync_pre_ds_mod_user_cb,
  1193. posix_winsync_pre_ds_mod_group_cb,
  1194. posix_winsync_pre_ds_add_user_cb,
  1195. posix_winsync_pre_ds_add_group_cb,
  1196. posix_winsync_get_new_ds_user_dn_cb,
  1197. posix_winsync_get_new_ds_group_dn_cb,
  1198. posix_winsync_pre_ad_mod_user_mods_cb,
  1199. posix_winsync_pre_ad_mod_group_mods_cb,
  1200. posix_winsync_can_add_entry_to_ad_cb,
  1201. posix_winsync_begin_update_cb,
  1202. posix_winsync_end_update_cb,
  1203. posix_winsync_destroy_agmt_cb };
  1204. static Slapi_ComponentId *posix_winsync_plugin_id = NULL;
  1205. /*
  1206. ** Plugin identity mgmt
  1207. */
  1208. void
  1209. posix_winsync_set_plugin_identity(void * identity)
  1210. {
  1211. posix_winsync_plugin_id = identity;
  1212. }
  1213. void *
  1214. posix_winsync_get_plugin_identity()
  1215. {
  1216. return posix_winsync_plugin_id;
  1217. }
  1218. static int
  1219. posix_winsync_plugin_start(Slapi_PBlock *pb)
  1220. {
  1221. int rc;
  1222. Slapi_Entry *config_e = NULL; /* entry containing plugin config */
  1223. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1224. "--> posix_winsync_plugin_start -- begin\n");
  1225. if (slapi_apib_register(WINSYNC_v1_0_GUID, posix_winsync_api)) {
  1226. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1227. "<-- posix_winsync_plugin_start -- failed to register winsync api -- end\n");
  1228. return -1;
  1229. }
  1230. if (slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &config_e) != 0) {
  1231. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name, "missing config entry\n");
  1232. return (-1);
  1233. }
  1234. if ((rc = posix_winsync_config(config_e)) != LDAP_SUCCESS) {
  1235. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name, "configuration failed (%s)\n",
  1236. ldap_err2string(rc));
  1237. return (-1);
  1238. }
  1239. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1240. "<-- posix_winsync_plugin_start -- registered; end\n");
  1241. return 0;
  1242. }
  1243. static int
  1244. posix_winsync_plugin_close(Slapi_PBlock *pb)
  1245. {
  1246. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1247. "--> posix_winsync_plugin_close -- begin\n");
  1248. slapi_apib_unregister(WINSYNC_v1_0_GUID);
  1249. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1250. "<-- posix_winsync_plugin_close -- end\n");
  1251. return 0;
  1252. }
  1253. /* this is the slapi plugin init function,
  1254. not the one used by the winsync api
  1255. */
  1256. int
  1257. posix_winsync_plugin_init(Slapi_PBlock *pb)
  1258. {
  1259. void *plugin_id = NULL;
  1260. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1261. "--> posix_winsync_plugin_init -- begin\n");
  1262. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0
  1263. || slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN, (void *) posix_winsync_plugin_start) != 0
  1264. || slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN, (void *) posix_winsync_plugin_close) != 0
  1265. || slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *) &posix_winsync_pdesc) != 0) {
  1266. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1267. "<-- posix_winsync_plugin_init -- failed to register plugin -- end\n");
  1268. return -1;
  1269. }
  1270. /* Retrieve and save the plugin identity to later pass to
  1271. internal operations */
  1272. if (slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &plugin_id) != 0) {
  1273. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1274. "<-- posix_winsync_plugin_init -- failed to retrieve plugin identity -- end\n");
  1275. return -1;
  1276. }
  1277. posix_winsync_set_plugin_identity(plugin_id);
  1278. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1279. "<-- posix_winsync_plugin_init -- end\n");
  1280. return 0;
  1281. }