posix-winsync.c 72 KB

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