posix-winsync.c 75 KB

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