1
0

posix-winsync.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797
  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. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  862. "_pre_ds_mod_group_cb present %d modify %d\n", is_present_local,
  863. do_modify_local);
  864. if (!is_present_local && do_modify_local) {
  865. Slapi_Attr *oc_attr = NULL;
  866. Slapi_Value *voc = slapi_value_new();
  867. slapi_value_init_string(voc, "posixGroup");
  868. slapi_entry_attr_find(ds_entry, "objectClass", &oc_attr);
  869. if (slapi_attr_value_find(oc_attr, slapi_value_get_berval(voc)) != 0) {
  870. Slapi_ValueSet *oc_vs = NULL;
  871. Slapi_Value *oc_nv = slapi_value_new();
  872. slapi_attr_get_valueset(oc_attr, &oc_vs);
  873. slapi_value_init_string(oc_nv, "posixGroup");
  874. slapi_valueset_add_value(oc_vs, oc_nv);
  875. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  876. "_pre_ds_mod_group_cb add oc:posixGroup\n");
  877. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, "objectClass",
  878. valueset_get_valuearray(oc_vs));
  879. slapi_value_free(&oc_nv);
  880. slapi_valueset_free(oc_vs);
  881. }
  882. slapi_value_free(&voc);
  883. }
  884. if (posix_winsync_config_get_mapMemberUid() || posix_winsync_config_get_mapNestedGrouping()) {
  885. memberUidLock();
  886. modGroupMembership(ds_entry, smods, do_modify, do_modify_local);
  887. memberUidUnlock();
  888. }
  889. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "_pre_ds_mod_group_cb step\n");
  890. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  891. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  892. slapi_mod_dump(mod, 0);
  893. }
  894. }
  895. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  896. "<-- _pre_ds_mod_group_cb -- end\n");
  897. return;
  898. }
  899. static void
  900. posix_winsync_pre_ds_add_user_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  901. Slapi_Entry *ds_entry)
  902. {
  903. Slapi_Attr *attr = NULL;
  904. char *type = NULL;
  905. PRBool posixval = PR_TRUE;
  906. windows_attribute_map *attr_map = user_attribute_map;
  907. int i = 0;
  908. if (posix_winsync_config_get_msSFUSchema())
  909. attr_map = user_mssfu_attribute_map;
  910. /* add objectclass: posixAccount, uidnumber, gidnumber, homeDirectory, loginShell */
  911. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  912. "--> _pre_ds_add_user_cb -- begin\n");
  913. /* check all of the required attributes are in the ad_entry:
  914. * MUST (cn $ uid $ uidNumber $ gidNumber $ homeDirectory).
  915. * If any of the required attributes are missing, drop them before adding
  916. * the entry to the DS. */
  917. for (i = 0; attr_map[i].windows_attribute_name != NULL; i++) {
  918. Slapi_Attr *pa_attr;
  919. if (attr_map[i].isMUST &&
  920. slapi_entry_attr_find(ad_entry,
  921. attr_map[i].windows_attribute_name,
  922. &pa_attr)) {
  923. /* required attribute does not exist */
  924. posixval = PR_FALSE;
  925. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  926. "AD entry %s does not have required attribute %s for posixAccount objectclass.\n",
  927. slapi_entry_get_dn_const(ad_entry),
  928. attr_map[i].ldap_attribute_name);
  929. }
  930. }
  931. /* converts the AD attributes to DS posix attribute if all the posix
  932. * required attributes are available */
  933. if (posixval) {
  934. int rc;
  935. for (slapi_entry_first_attr(ad_entry, &attr); attr;
  936. slapi_entry_next_attr(ad_entry, attr, &attr)) {
  937. slapi_attr_get_type(attr, &type);
  938. if (!type) {
  939. continue;
  940. }
  941. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  942. "--> _pre_ds_add_user_cb -- "
  943. "look for [%s] to new entry [%s]\n",
  944. type, slapi_entry_get_dn_const(ds_entry));
  945. for (i = 0; attr_map[i].windows_attribute_name != NULL; i++) {
  946. if (slapi_attr_type_cmp(attr_map[i].windows_attribute_name,
  947. type, SLAPI_TYPE_CMP_SUBTYPE) == 0) {
  948. Slapi_ValueSet *svs = NULL;
  949. slapi_attr_get_valueset(attr, &svs);
  950. slapi_entry_add_valueset(ds_entry,
  951. attr_map[i].ldap_attribute_name, svs);
  952. slapi_valueset_free(svs);
  953. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  954. "--> _pre_ds_add_user_cb -- "
  955. "adding val for [%s] to new entry [%s]\n",
  956. type, slapi_entry_get_dn_const(ds_entry));
  957. }
  958. }
  959. }
  960. rc = slapi_entry_add_string(ds_entry, "objectClass", "posixAccount");
  961. rc |= slapi_entry_add_string(ds_entry, "objectClass", "shadowAccount");
  962. rc |= slapi_entry_add_string(ds_entry, "objectClass", "inetUser");
  963. if (rc != 0) {
  964. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  965. "<-- _pre_ds_add_user_cb -- adding objectclass for new entry failed %d\n",
  966. rc);
  967. } else {
  968. if (posix_winsync_config_get_mapNestedGrouping()) {
  969. memberUidLock();
  970. addUserToGroupMembership(ds_entry);
  971. memberUidUnlock();
  972. }
  973. }
  974. }
  975. sync_acct_disable(cbdata, rawentry, ds_entry, ACCT_DISABLE_TO_DS, ds_entry, NULL, NULL);
  976. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_add_user_cb -- end\n");
  977. return;
  978. }
  979. static void
  980. posix_winsync_pre_ds_add_group_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  981. Slapi_Entry *ds_entry)
  982. {
  983. Slapi_Attr *attr = NULL;
  984. char *type = NULL;
  985. PRBool posixval = PR_FALSE;
  986. windows_attribute_map *attr_map = group_attribute_map;
  987. if (posix_winsync_config_get_msSFUSchema())
  988. attr_map = group_mssfu_attribute_map;
  989. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  990. "--> posix_winsync_pre_ds_add_group_cb -- begin\n");
  991. for (slapi_entry_first_attr(ad_entry, &attr); attr; slapi_entry_next_attr(ad_entry, attr, &attr)) {
  992. size_t i = 0;
  993. slapi_attr_get_type(attr, &type);
  994. if (!type) {
  995. continue;
  996. }
  997. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "--> _pre_ds_add_group_cb -- "
  998. "look for [%s] to new entry [%s]\n", type, slapi_entry_get_dn_const(ds_entry));
  999. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  1000. if (slapi_attr_type_cmp(attr_map[i].windows_attribute_name, type,
  1001. SLAPI_TYPE_CMP_SUBTYPE) == 0) {
  1002. Slapi_ValueSet *svs = NULL;
  1003. slapi_attr_get_valueset(attr, &svs);
  1004. slapi_entry_add_valueset(ds_entry, attr_map[i].ldap_attribute_name, svs);
  1005. slapi_valueset_free(svs);
  1006. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1007. "--> _pre_ds_add_group_cb -- "
  1008. "adding val for [%s] to new entry [%s]\n", type,
  1009. slapi_entry_get_dn_const(ds_entry));
  1010. posixval = PR_TRUE;
  1011. }
  1012. }
  1013. }
  1014. if (posixval) {
  1015. int rc;
  1016. rc = slapi_entry_add_string(ds_entry, "objectClass", "posixGroup");
  1017. if (rc != 0) {
  1018. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1019. "<-- _pre_ds_add_group_cb -- adding objectclass for new entry failed %d\n",
  1020. rc);
  1021. }
  1022. }
  1023. if (posix_winsync_config_get_mapMemberUid() || posix_winsync_config_get_mapNestedGrouping()) {
  1024. memberUidLock();
  1025. addGroupMembership(ds_entry, ad_entry);
  1026. memberUidUnlock();
  1027. }
  1028. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1029. "<-- posix_winsync_pre_ds_add_group_cb -- end\n");
  1030. return;
  1031. }
  1032. static void
  1033. posix_winsync_get_new_ds_user_dn_cb(void *cbdata, const Slapi_Entry *rawentry,
  1034. Slapi_Entry *ad_entry, char **new_dn_string, const Slapi_DN *ds_suffix,
  1035. const Slapi_DN *ad_suffix)
  1036. {
  1037. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1038. "--> posix_winsync_get_new_ds_user_dn_cb -- old dn [%s] -- begin\n",
  1039. *new_dn_string);
  1040. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1041. "<-- posix_winsync_get_new_ds_user_dn_cb -- new dn [%s] -- end\n",
  1042. *new_dn_string);
  1043. return;
  1044. }
  1045. static void
  1046. posix_winsync_get_new_ds_group_dn_cb(void *cbdata, const Slapi_Entry *rawentry,
  1047. Slapi_Entry *ad_entry, char **new_dn_string, const Slapi_DN *ds_suffix,
  1048. const Slapi_DN *ad_suffix)
  1049. {
  1050. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1051. "--> posix_winsync_get_new_ds_group_dn_cb -- begin\n");
  1052. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1053. "<-- posix_winsync_get_new_ds_group_dn_cb -- end\n");
  1054. return;
  1055. }
  1056. static void
  1057. posix_winsync_pre_ad_mod_user_mods_cb(void *cbdata, const Slapi_Entry *rawentry,
  1058. const Slapi_DN *local_dn, const Slapi_Entry *ds_entry, LDAPMod * const *origmods,
  1059. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  1060. {
  1061. Slapi_Mods *smods = slapi_mods_new();
  1062. Slapi_Mods *new_smods = slapi_mods_new();
  1063. LDAPMod *mod = NULL;
  1064. windows_attribute_map *attr_map = user_attribute_map;
  1065. if (posix_winsync_config_get_msSFUSchema())
  1066. attr_map = user_mssfu_attribute_map;
  1067. /* mod if changed objectclass: posixAccount, uidnumber, gidnumber, homeDirectory, loginShell */
  1068. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1069. "--> _pre_ad_mod_user_mods_cb -- begin DS account [%s] \n",
  1070. slapi_entry_get_dn_const(ds_entry));
  1071. /* wrap the modstosend in a Slapi_Mods for convenience */
  1072. slapi_mods_init_passin(new_smods, *modstosend);
  1073. slapi_mods_init_byref(smods, (LDAPMod**) origmods);
  1074. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  1075. size_t i = 0;
  1076. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1077. "_pre_ad_mod_user_mods_cb -- check modify type %s\n", mod->mod_type);
  1078. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  1079. if (0 == slapi_attr_type_cmp(mod->mod_type, attr_map[i].ldap_attribute_name,
  1080. SLAPI_TYPE_CMP_SUBTYPE)) {
  1081. Slapi_Mod *mysmod = slapi_mod_new();
  1082. slapi_mod_init_byval(mysmod, mod);
  1083. slapi_mod_set_type(mysmod, attr_map[i].windows_attribute_name);
  1084. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(mysmod));
  1085. slapi_mod_free(&mysmod);
  1086. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1087. "_pre_ad_mod_user_mods_cb -- add modify %s DS account [%s]\n",
  1088. attr_map[i].windows_attribute_name,
  1089. slapi_entry_get_dn_const(ds_entry));
  1090. if (0 == slapi_attr_type_cmp(mod->mod_type, "uidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  1091. Slapi_Mod *ocsmod = slapi_mod_new();
  1092. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1093. "_pre_ad_mod_user_mods_cb -- add NisDomain\n");
  1094. addNisDomainName(ocsmod, ds_entry);
  1095. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(ocsmod));
  1096. slapi_mod_free(&ocsmod);
  1097. }
  1098. }
  1099. }
  1100. if (0 == slapi_attr_type_cmp(mod->mod_type, "nsRoleDN", SLAPI_TYPE_CMP_SUBTYPE)) {
  1101. int dummy = 0;
  1102. sync_acct_disable(cbdata, rawentry, (Slapi_Entry *) ds_entry, ACCT_DISABLE_TO_AD, NULL,
  1103. new_smods, &dummy);
  1104. }
  1105. }
  1106. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  1107. for (mod = slapi_mods_get_first_mod(new_smods); mod; mod
  1108. = slapi_mods_get_next_mod(new_smods)) {
  1109. slapi_mod_dump(mod, 0);
  1110. }
  1111. }
  1112. *modstosend = slapi_mods_get_ldapmods_passout(new_smods);
  1113. slapi_mods_free(&smods);
  1114. slapi_mods_free(&new_smods);
  1115. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1116. "<-- _pre_ad_mod_user_mods_cb -- end\n");
  1117. return;
  1118. }
  1119. static void
  1120. posix_winsync_pre_ad_mod_group_mods_cb(void *cbdata, const Slapi_Entry *rawentry,
  1121. const Slapi_DN *local_dn, const Slapi_Entry *ds_entry, LDAPMod * const *origmods,
  1122. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  1123. {
  1124. Slapi_Mods *smods = slapi_mods_new();
  1125. Slapi_Mods *new_smods = slapi_mods_new();
  1126. LDAPMod *mod = NULL;
  1127. windows_attribute_map *attr_map = group_attribute_map;
  1128. if (posix_winsync_config_get_msSFUSchema())
  1129. attr_map = group_mssfu_attribute_map;
  1130. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1131. "--> _pre_ad_mod_group_mods_cb -- begin\n");
  1132. /* wrap the modstosend in a Slapi_Mods for convenience */
  1133. slapi_mods_init_passin(new_smods, *modstosend);
  1134. slapi_mods_init_byref(smods, (LDAPMod**) origmods);
  1135. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  1136. size_t i = 0;
  1137. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1138. "_pre_ad_mod_group_mods_cb -- check modify type %s\n", mod->mod_type);
  1139. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  1140. if (0 == slapi_attr_type_cmp(mod->mod_type, attr_map[i].ldap_attribute_name,
  1141. SLAPI_TYPE_CMP_SUBTYPE)) {
  1142. Slapi_Mod *mysmod = slapi_mod_new();
  1143. if (mod->mod_op & LDAP_MOD_DELETE) {
  1144. slapi_mod_init(mysmod, 0);
  1145. slapi_mod_set_operation(mysmod, LDAP_MOD_DELETE | LDAP_MOD_BVALUES);
  1146. slapi_mod_set_type(mysmod, attr_map[i].windows_attribute_name);
  1147. } else {
  1148. slapi_mod_init_byval(mysmod, mod);
  1149. slapi_mod_set_type(mysmod, attr_map[i].windows_attribute_name);
  1150. if (0
  1151. == slapi_attr_type_cmp(mod->mod_type, "gidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  1152. Slapi_Mod *ocsmod = slapi_mod_new();
  1153. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1154. "_pre_ad_mod_group_mods_cb -- add NisDomain\n");
  1155. addNisDomainName(ocsmod, ds_entry);
  1156. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(ocsmod));
  1157. slapi_mod_free(&ocsmod);
  1158. }
  1159. }
  1160. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(mysmod));
  1161. slapi_mod_free(&mysmod);
  1162. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1163. "_pre_ad_mod_group_mods_cb -- add modify %s DS account [%s]\n",
  1164. attr_map[i].windows_attribute_name,
  1165. slapi_entry_get_dn_const(ds_entry));
  1166. }
  1167. }
  1168. }
  1169. *modstosend = slapi_mods_get_ldapmods_passout(new_smods);
  1170. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  1171. for (mod = slapi_mods_get_first_mod(new_smods); mod;
  1172. mod = slapi_mods_get_next_mod(new_smods)) {
  1173. slapi_mod_dump(mod, 0);
  1174. }
  1175. }
  1176. slapi_mods_free(&smods);
  1177. slapi_mods_free(&new_smods);
  1178. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1179. "<-- _pre_ad_mod_group_mods_cb -- end\n");
  1180. return;
  1181. }
  1182. static int
  1183. posix_winsync_can_add_entry_to_ad_cb(void *cbdata, const Slapi_Entry *local_entry,
  1184. const Slapi_DN *remote_dn)
  1185. {
  1186. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1187. "--> posix_winsync_can_add_entry_to_ad_cb -- begin\n");
  1188. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1189. "<-- posix_winsync_can_add_entry_to_ad_cb -- end\n");
  1190. return 1; /* false - do not allow entries to be added to ad */
  1191. }
  1192. static void
  1193. posix_winsync_begin_update_cb(void *cbdata, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree,
  1194. int is_total)
  1195. {
  1196. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1197. "--> posix_winsync_begin_update_cb -- begin\n");
  1198. posix_winsync_config_reset_MOFTaskCreated();
  1199. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1200. "<-- posix_winsync_begin_update_cb -- end\n");
  1201. return;
  1202. }
  1203. static void
  1204. posix_winsync_end_update_cb(void *cbdata, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree,
  1205. int is_total)
  1206. {
  1207. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1208. "--> posix_winsync_end_update_cb -- begin %d %d\n",
  1209. posix_winsync_config_get_MOFTaskCreated(),
  1210. posix_winsync_config_get_createMOFTask());
  1211. if (1 && posix_winsync_config_get_createMOFTask()) {
  1212. /* add a task to schedule memberof Plugin for fix memebrof attributs */
  1213. Slapi_PBlock *pb = slapi_pblock_new();
  1214. Slapi_Entry *e_task = slapi_entry_alloc();
  1215. int rc = 0;
  1216. char *dn = slapi_create_dn_string("cn=%s,cn=%s,cn=tasks,cn=config",
  1217. posix_winsync_plugin_name, MEMBEROFTASK);
  1218. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1219. "--> posix_winsync_end_update_cb, create task %s\n", dn);
  1220. if (NULL == dn) {
  1221. slapi_pblock_destroy(pb);
  1222. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1223. "posix_winsync_end_update_cb: "
  1224. "failed to create task dn: cn=%s,%s,cn=tasks,cn=config\n",
  1225. posix_winsync_plugin_name, MEMBEROFTASK);
  1226. return;
  1227. }
  1228. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1229. "--> posix_winsync_end_update_cb, init'ing task\n");
  1230. slapi_entry_init(e_task, slapi_ch_strdup(dn), NULL);
  1231. slapi_entry_add_string(e_task, "cn", slapi_ch_strdup(posix_winsync_plugin_name));
  1232. slapi_entry_add_string(e_task, "objectClass", "extensibleObject");
  1233. slapi_entry_add_string(e_task, "basedn", slapi_sdn_get_dn(ds_subtree));
  1234. slapi_add_entry_internal_set_pb(pb, e_task, NULL, posix_winsync_get_plugin_identity(), 0);
  1235. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1236. "--> posix_winsync_end_update_cb, adding task\n");
  1237. slapi_add_internal_pb(pb);
  1238. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1239. "--> posix_winsync_end_update_cb, retrieving return code\n");
  1240. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  1241. if (rc != 0) {
  1242. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1243. "posix_winsync_end_update_cb: "
  1244. "failed to add task entry\n");
  1245. } else {
  1246. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1247. "posix_winsync_end_update_cb: "
  1248. "add task entry\n");
  1249. }
  1250. /* slapi_entry_free(e_task); */
  1251. slapi_pblock_destroy(pb);
  1252. pb = NULL;
  1253. posix_winsync_config_reset_MOFTaskCreated();
  1254. }
  1255. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1256. "<-- posix_winsync_end_update_cb -- end\n");
  1257. return;
  1258. }
  1259. static void
  1260. posix_winsync_destroy_agmt_cb(void *cbdata, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree)
  1261. {
  1262. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1263. "--> posix_winsync_destroy_agmt_cb -- begin\n");
  1264. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1265. "<-- posix_winsync_destroy_agmt_cb -- end\n");
  1266. return;
  1267. }
  1268. static void
  1269. 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)
  1270. {
  1271. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1272. "--> posix_winsync_post_ad_mod_user_cb -- begin\n");
  1273. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1274. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1275. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1276. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1277. #endif
  1278. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1279. "<-- posix_winsync_post_ad_mod_user_cb -- end\n");
  1280. return;
  1281. }
  1282. static void
  1283. 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)
  1284. {
  1285. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1286. "--> posix_winsync_post_ad_mod_group_cb -- begin\n");
  1287. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1288. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1289. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1290. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1291. #endif
  1292. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1293. "<-- posix_winsync_post_ad_mod_group_cb -- end\n");
  1294. return;
  1295. }
  1296. static void
  1297. 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)
  1298. {
  1299. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1300. "--> posix_winsync_post_ds_mod_user_cb -- begin\n");
  1301. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1302. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1303. "Result of modifying DS entry [%s] was [%d:%s]\n",
  1304. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1305. #endif
  1306. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1307. "<-- posix_winsync_post_ds_mod_user_cb -- end\n");
  1308. return;
  1309. }
  1310. static void
  1311. 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)
  1312. {
  1313. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1314. "--> posix_winsync_post_ds_mod_group_cb -- begin\n");
  1315. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1316. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1317. "Result of modifying DS entry [%s] was [%d:%s]\n",
  1318. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1319. #endif
  1320. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1321. "<-- posix_winsync_post_ds_mod_group_cb -- end\n");
  1322. return;
  1323. }
  1324. static void
  1325. posix_winsync_post_ds_add_user_cb(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  1326. {
  1327. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1328. "--> posix_winsync_post_ds_add_user_cb -- begin\n");
  1329. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1330. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1331. "Result of adding DS entry [%s] was [%d:%s]\n",
  1332. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1333. #endif
  1334. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1335. "<-- posix_winsync_post_ds_add_user_cb -- end\n");
  1336. return;
  1337. }
  1338. static void
  1339. posix_winsync_post_ds_add_group_cb(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  1340. {
  1341. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1342. "--> posix_winsync_post_ds_add_group_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 DS entry [%s] was [%d:%s]\n",
  1346. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1347. #endif
  1348. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1349. "<-- posix_winsync_post_ds_add_group_cb -- end\n");
  1350. return;
  1351. }
  1352. static void
  1353. posix_winsync_pre_ad_add_user_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry)
  1354. {
  1355. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1356. "--> posix_winsync_pre_ad_add_user_cb -- begin\n");
  1357. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1358. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1359. "Adding AD entry [%s] from add of DS entry [%s]\n",
  1360. slapi_entry_get_dn(ad_entry), slapi_entry_get_dn(ds_entry));
  1361. /* make modifications to ad_entry here */
  1362. #endif
  1363. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1364. "<-- posix_winsync_pre_ad_add_user_cb -- end\n");
  1365. return;
  1366. }
  1367. static void
  1368. posix_winsync_pre_ad_add_group_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry)
  1369. {
  1370. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1371. "--> posix_winsync_pre_ad_add_group_cb -- begin\n");
  1372. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1373. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1374. "Adding AD entry [%s] from add of DS entry [%s]\n",
  1375. slapi_entry_get_dn(ad_entry), slapi_entry_get_dn(ds_entry));
  1376. /* make modifications to ad_entry here */
  1377. #endif
  1378. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1379. "<-- posix_winsync_pre_ad_add_group_cb -- end\n");
  1380. return;
  1381. }
  1382. static void
  1383. posix_winsync_post_ad_add_user_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry, int *result)
  1384. {
  1385. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1386. "--> posix_winsync_post_ad_add_user_cb -- begin\n");
  1387. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1388. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1389. "Result of adding AD entry [%s] was [%d:%s]\n",
  1390. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1391. #endif
  1392. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1393. "<-- posix_winsync_post_ad_add_user_cb -- end\n");
  1394. return;
  1395. }
  1396. static void
  1397. posix_winsync_post_ad_add_group_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry, int *result)
  1398. {
  1399. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1400. "--> posix_winsync_post_ad_add_group_cb -- begin\n");
  1401. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1402. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1403. "Result of adding AD entry [%s] was [%d:%s]\n",
  1404. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1405. #endif
  1406. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1407. "<-- posix_winsync_post_ad_add_group_cb -- end\n");
  1408. return;
  1409. }
  1410. static void
  1411. 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)
  1412. {
  1413. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1414. "--> posix_winsync_post_ad_mod_user_mods_cb -- begin\n");
  1415. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1416. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1417. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1418. slapi_sdn_get_dn(remote_dn), *result, ldap_err2string(*result));
  1419. #endif
  1420. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1421. "<-- posix_winsync_post_ad_mod_user_mods_cb -- end\n");
  1422. return;
  1423. }
  1424. static void
  1425. 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)
  1426. {
  1427. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1428. "--> posix_winsync_post_ad_mod_group_mods_cb -- begin\n");
  1429. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1430. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1431. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1432. slapi_sdn_get_dn(remote_dn), *result, ldap_err2string(*result));
  1433. #endif
  1434. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1435. "<-- posix_winsync_post_ad_mod_group_mods_cb -- end\n");
  1436. return;
  1437. }
  1438. #define DEFAULT_PRECEDENCE 25
  1439. static int precedence = DEFAULT_PRECEDENCE; /* default */
  1440. static int posix_winsync_precedence(void)
  1441. {
  1442. return precedence;
  1443. }
  1444. static void *posix_winsync_api[] = { NULL, /* reserved for api broker use, must be zero */
  1445. posix_winsync_agmt_init,
  1446. posix_winsync_dirsync_search_params_cb,
  1447. posix_winsync_pre_ad_search_cb,
  1448. posix_winsync_pre_ds_search_entry_cb,
  1449. posix_winsync_pre_ds_search_all_cb,
  1450. posix_winsync_pre_ad_mod_user_cb,
  1451. posix_winsync_pre_ad_mod_group_cb,
  1452. posix_winsync_pre_ds_mod_user_cb,
  1453. posix_winsync_pre_ds_mod_group_cb,
  1454. posix_winsync_pre_ds_add_user_cb,
  1455. posix_winsync_pre_ds_add_group_cb,
  1456. posix_winsync_get_new_ds_user_dn_cb,
  1457. posix_winsync_get_new_ds_group_dn_cb,
  1458. posix_winsync_pre_ad_mod_user_mods_cb,
  1459. posix_winsync_pre_ad_mod_group_mods_cb,
  1460. posix_winsync_can_add_entry_to_ad_cb,
  1461. posix_winsync_begin_update_cb,
  1462. posix_winsync_end_update_cb,
  1463. posix_winsync_destroy_agmt_cb,
  1464. posix_winsync_post_ad_mod_user_cb,
  1465. posix_winsync_post_ad_mod_group_cb,
  1466. posix_winsync_post_ds_mod_user_cb,
  1467. posix_winsync_post_ds_mod_group_cb,
  1468. posix_winsync_post_ds_add_user_cb,
  1469. posix_winsync_post_ds_add_group_cb,
  1470. posix_winsync_pre_ad_add_user_cb,
  1471. posix_winsync_pre_ad_add_group_cb,
  1472. posix_winsync_post_ad_add_user_cb,
  1473. posix_winsync_post_ad_add_group_cb,
  1474. posix_winsync_post_ad_mod_user_mods_cb,
  1475. posix_winsync_post_ad_mod_group_mods_cb,
  1476. posix_winsync_precedence
  1477. };
  1478. static Slapi_ComponentId *posix_winsync_plugin_id = NULL;
  1479. /*
  1480. ** Plugin identity mgmt
  1481. */
  1482. void
  1483. posix_winsync_set_plugin_identity(void * identity)
  1484. {
  1485. posix_winsync_plugin_id = identity;
  1486. }
  1487. void *
  1488. posix_winsync_get_plugin_identity()
  1489. {
  1490. return posix_winsync_plugin_id;
  1491. }
  1492. static int
  1493. posix_winsync_plugin_start(Slapi_PBlock *pb)
  1494. {
  1495. int rc;
  1496. Slapi_Entry *config_e = NULL; /* entry containing plugin config */
  1497. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1498. "--> posix_winsync_plugin_start -- begin\n");
  1499. if (slapi_apib_register(WINSYNC_v3_0_GUID, posix_winsync_api)) {
  1500. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1501. "<-- posix_winsync_plugin_start -- failed to register winsync api -- end\n");
  1502. return -1;
  1503. }
  1504. if (slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &config_e) != 0) {
  1505. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name, "missing config entry\n");
  1506. return (-1);
  1507. }
  1508. if ((rc = posix_winsync_config(config_e)) != LDAP_SUCCESS) {
  1509. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name, "configuration failed (%s)\n",
  1510. ldap_err2string(rc));
  1511. return (-1);
  1512. }
  1513. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1514. "<-- posix_winsync_plugin_start -- registered; end\n");
  1515. return 0;
  1516. }
  1517. static int
  1518. posix_winsync_plugin_close(Slapi_PBlock *pb)
  1519. {
  1520. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1521. "--> posix_winsync_plugin_close -- begin\n");
  1522. slapi_apib_unregister(WINSYNC_v1_0_GUID);
  1523. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1524. "<-- posix_winsync_plugin_close -- end\n");
  1525. return 0;
  1526. }
  1527. /* this is the slapi plugin init function,
  1528. not the one used by the winsync api
  1529. */
  1530. int
  1531. posix_winsync_plugin_init(Slapi_PBlock *pb)
  1532. {
  1533. void *plugin_id = NULL;
  1534. Slapi_Entry *confige = NULL;
  1535. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1536. "--> posix_winsync_plugin_init -- begin\n");
  1537. if (slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &confige) && confige) {
  1538. precedence = slapi_entry_attr_get_int(confige, "nsslapd-pluginprecedence");
  1539. if (!precedence) {
  1540. precedence = DEFAULT_PRECEDENCE;
  1541. }
  1542. }
  1543. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0
  1544. || slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN, (void *) posix_winsync_plugin_start) != 0
  1545. || slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN, (void *) posix_winsync_plugin_close) != 0
  1546. || slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *) &posix_winsync_pdesc) != 0) {
  1547. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1548. "<-- posix_winsync_plugin_init -- failed to register plugin -- end\n");
  1549. return -1;
  1550. }
  1551. /* Retrieve and save the plugin identity to later pass to
  1552. internal operations */
  1553. if (slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &plugin_id) != 0) {
  1554. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1555. "<-- posix_winsync_plugin_init -- failed to retrieve plugin identity -- end\n");
  1556. return -1;
  1557. }
  1558. posix_winsync_set_plugin_identity(plugin_id);
  1559. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1560. "<-- posix_winsync_plugin_init -- end\n");
  1561. return 0;
  1562. }