1
0

posix-winsync.c 82 KB

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