1
0

posix-winsync.c 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926
  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. /* look in the parent nodes of ds_entry for nis domain entry */
  358. char *
  359. getNisDomainName(const Slapi_Entry *ds_entry)
  360. {
  361. Slapi_DN* entry_sdn = slapi_entry_get_sdn((Slapi_Entry *) ds_entry);
  362. Slapi_DN* subtree_sdn = slapi_sdn_new();
  363. char *type_NisDomain = "nisDomain";
  364. Slapi_PBlock * pb;
  365. Slapi_DN *childparent = slapi_sdn_new();
  366. char* nisdomainname = NULL;
  367. Slapi_Entry *entry = NULL;
  368. int rc = -1;
  369. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "getNisDomainName start DN:%s\n",
  370. slapi_sdn_get_dn(entry_sdn));
  371. /* search NIS domain name */
  372. slapi_sdn_get_parent(entry_sdn, subtree_sdn);
  373. pb = slapi_pblock_new();
  374. do {
  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. nisdomainname = slapi_entry_attr_get_charptr(entry, type_NisDomain);
  386. if (nisdomainname != NULL){
  387. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  388. "getNisDomainName NisDomain %s found in DN:%s\n",
  389. nisdomainname, slapi_sdn_get_dn(childparent));
  390. break;
  391. }
  392. }
  393. }
  394. slapi_sdn_copy(childparent, subtree_sdn);
  395. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  396. "getNisDomainName 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 || nisdomainname == NULL ) {
  402. slapi_log_error(SLAPI_LOG_REPL, posix_winsync_plugin_name,
  403. "getNisDomainName: no nisdomainname found in %s, LDAP Err%d\n",
  404. slapi_sdn_get_dn(subtree_sdn), rc);
  405. }
  406. slapi_sdn_free(&childparent);
  407. slapi_entry_free(entry);
  408. entry = NULL;
  409. slapi_sdn_free(&subtree_sdn);
  410. return nisdomainname;
  411. }
  412. static int
  413. addNisDomainName(Slapi_Mod *smod, const Slapi_Entry *ds_entry)
  414. {
  415. int rc = LDAP_SUCCESS;
  416. char* nisdomainname = getNisDomainName(ds_entry);
  417. if ( nisdomainname == NULL ) {
  418. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  419. "addNisDomainName NisDomain not found\n");
  420. rc = LDAP_NO_SUCH_ATTRIBUTE;
  421. } else {
  422. struct berval bval;
  423. slapi_mod_init(smod, 1);
  424. slapi_mod_set_type(smod, "msSFU30NisDomain");
  425. slapi_mod_set_operation(smod, LDAP_MOD_REPLACE | LDAP_MOD_BVALUES);
  426. bval.bv_val = nisdomainname;
  427. bval.bv_len = sizeof (nisdomainname);
  428. slapi_mod_add_value(smod, &bval);
  429. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN))
  430. slapi_mod_dump((LDAPMod*) slapi_mod_get_ldapmod_byref(smod), 0);
  431. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  432. "addNisDomainName NisDomain %s found\n", nisdomainname);
  433. slapi_ch_free_string(&nisdomainname); /* allocated by slapi_entry_attr_getchrptr */
  434. }
  435. return rc;
  436. }
  437. static void
  438. posix_winsync_dirsync_search_params_cb(void *cbdata, const char *agmt_dn, char **base, int *scope,
  439. char **filter, char ***attrs, LDAPControl ***serverctrls)
  440. {
  441. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  442. "--> posix_winsync_dirsync_search_params_cb -- begin\n");
  443. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  444. "<-- posix_winsync_dirsync_search_params_cb -- end\n");
  445. return;
  446. }
  447. /* called before searching for a single entry from AD - agmt_dn will be NULL */
  448. static void
  449. posix_winsync_pre_ad_search_cb(void *cbdata, const char *agmt_dn, char **base, int *scope,
  450. char **filter, char ***attrs, LDAPControl ***serverctrls)
  451. {
  452. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  453. "--> posix_winsync_pre_ad_search_cb -- begin\n");
  454. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  455. "<-- posix_winsync_pre_ad_search_cb -- end\n");
  456. return;
  457. }
  458. /* called before an internal search to get a single DS entry - agmt_dn will be NULL */
  459. static void
  460. posix_winsync_pre_ds_search_entry_cb(void *cbdata, const char *agmt_dn, char **base, int *scope,
  461. char **filter, char ***attrs, LDAPControl ***serverctrls)
  462. {
  463. /*
  464. char *tmpbase=slapi_ch_strdup(*base);
  465. char *d = *base;
  466. char *s = tmpbase;
  467. int i=0;
  468. */
  469. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "--> _pre_ds_search_cb -- begin\n");
  470. /* skip the first subtree container ou=xyz, */
  471. /* if (strlen(*base) > 3) {
  472. s++;
  473. while(*s !='\0'){
  474. if (((*(s) == ',') || (*(s) == ';' )) && (*((s)-1) != '\\')){
  475. s++;
  476. while(*s !='\0'){
  477. *d++ = *s++;
  478. }
  479. *d='\0';
  480. break;
  481. }
  482. s++;
  483. }
  484. }
  485. */
  486. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  487. "-- _pre_ds_search_cb - base [%s] "
  488. "scope [%d] filter [%s]\n", *base, *scope, *filter);
  489. /* slapi_ch_free_string(&tmpbase); */
  490. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_search_cb -- end\n");
  491. return;
  492. }
  493. /* called before the total update to get all entries from the DS to sync to AD */
  494. static void
  495. posix_winsync_pre_ds_search_all_cb(void *cbdata, const char *agmt_dn, char **base, int *scope,
  496. char **filter, char ***attrs, LDAPControl ***serverctrls)
  497. {
  498. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  499. "--> posix_winsync_pre_ds_search_all_cb -- orig filter [%s] -- begin\n",
  500. ((filter && *filter) ? *filter : "NULL"));
  501. /* slapi_ch_free_string(filter);
  502. *filter = slapi_ch_strdup("(|(objectclass=posixaccount)(objectclass=posixgroup))");
  503. */
  504. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  505. "<-- posix_winsync_pre_ds_search_all_cb -- end\n");
  506. return;
  507. }
  508. static void
  509. posix_winsync_pre_ad_mod_user_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  510. Slapi_Entry *ds_entry, Slapi_Mods *smods, int *do_modify)
  511. {
  512. LDAPMod *mod = NULL;
  513. int rc = 0;
  514. Slapi_Attr *attr = NULL;
  515. windows_attribute_map *attr_map = user_attribute_map;
  516. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  517. "--> posix_winsync_pre_ad_mod_user_cb -- begin DS account [%s]\n",
  518. slapi_entry_get_dn_const(ds_entry));
  519. if (posix_winsync_config_get_msSFUSchema()) {
  520. attr_map = user_mssfu_attribute_map;
  521. }
  522. /* called if init Replica: add nisDomain, uidnumber, ... if avail */
  523. for (rc = slapi_entry_first_attr(ds_entry, &attr); rc == 0;
  524. rc = slapi_entry_next_attr(ds_entry, attr, &attr)) {
  525. char *type = NULL;
  526. size_t i = 0;
  527. slapi_attr_get_type(attr, &type);
  528. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  529. "_pre_ad_mod_user_cb -- check modify type %s\n", type);
  530. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  531. if (0 == slapi_attr_type_cmp(type, attr_map[i].ldap_attribute_name,
  532. SLAPI_TYPE_CMP_SUBTYPE)) {
  533. Slapi_Attr *ad_attr = NULL;
  534. Slapi_ValueSet *vs = NULL;
  535. char *ad_type = NULL;
  536. int is_present_local;
  537. slapi_attr_get_valueset(attr, &vs);
  538. ad_type = slapi_ch_strdup(attr_map[i].windows_attribute_name);
  539. slapi_entry_attr_find(ad_entry, ad_type, &ad_attr);
  540. is_present_local = (NULL == ad_attr) ? 0 : 1;
  541. if (is_present_local) {
  542. int values_equal = 0;
  543. values_equal = attr_compare_equal(attr, ad_attr);
  544. if (!values_equal) {
  545. slapi_log_error(
  546. SLAPI_LOG_PLUGIN,
  547. posix_winsync_plugin_name,
  548. "_pre_ad_mod_user_cb -- update mods: %s, %s : values are different -> modify\n",
  549. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  550. ad_type);
  551. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, ad_type,
  552. valueset_get_valuearray(vs));
  553. *do_modify = 1;
  554. }
  555. } else {
  556. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, ad_type,
  557. valueset_get_valuearray(vs));
  558. if (0 == slapi_attr_type_cmp(type, "uidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  559. Slapi_Mod *mysmod = slapi_mod_new();
  560. addNisDomainName(mysmod, ds_entry);
  561. slapi_mods_add_ldapmod(smods, slapi_mod_get_ldapmod_passout(mysmod));
  562. slapi_mod_free(&mysmod);
  563. }
  564. *do_modify = 1;
  565. }
  566. slapi_ch_free((void**) &ad_type);
  567. slapi_valueset_free(vs);
  568. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  569. "_pre_ad_mod_user_cb -- add modify %s DS account [%s]\n",
  570. attr_map[i].windows_attribute_name,
  571. slapi_entry_get_dn_const(ds_entry));
  572. }
  573. }
  574. if (0 == slapi_attr_type_cmp(type, "nsAccountLock", SLAPI_TYPE_CMP_SUBTYPE))
  575. sync_acct_disable(cbdata, rawentry, ds_entry, ACCT_DISABLE_TO_AD, NULL, smods,
  576. do_modify);
  577. }
  578. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  579. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  580. slapi_mod_dump(mod, 0);
  581. }
  582. }
  583. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  584. "<-- posix_winsync_pre_ad_mod_user_cb -- end\n");
  585. return;
  586. }
  587. static void
  588. posix_winsync_pre_ad_mod_group_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  589. Slapi_Entry *ds_entry, Slapi_Mods *smods, int *do_modify)
  590. {
  591. LDAPMod *mod = NULL;
  592. int rc = 0;
  593. Slapi_Attr *attr = NULL;
  594. windows_attribute_map *attr_map = group_attribute_map;
  595. if (posix_winsync_config_get_msSFUSchema())
  596. attr_map = group_mssfu_attribute_map;
  597. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  598. "--> _pre_ad_mod_group_cb -- begin DS account [%s]\n",
  599. slapi_entry_get_dn_const(ds_entry));
  600. /* called if init Replica: add nisDomain, gidnumber, memberuid, if avail */
  601. for (rc = slapi_entry_first_attr(ds_entry, &attr); rc == 0;
  602. rc = slapi_entry_next_attr(ds_entry, attr, &attr)) {
  603. char *type = NULL;
  604. size_t i = 0;
  605. slapi_attr_get_type(attr, &type);
  606. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  607. "_pre_ad_mod_group_cb -- check modify type %s\n", type);
  608. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  609. if (0 == slapi_attr_type_cmp(type, attr_map[i].ldap_attribute_name,
  610. SLAPI_TYPE_CMP_SUBTYPE)) {
  611. Slapi_Attr *ad_attr = NULL;
  612. Slapi_ValueSet *vs = NULL;
  613. char *ad_type = NULL;
  614. int is_present_local;
  615. if (i == 0) { /* memberUid */
  616. Slapi_Attr *dsmuid_attr = NULL;
  617. Slapi_Value *v = NULL;
  618. slapi_entry_attr_find(ds_entry, "dsonlymemberuid", &dsmuid_attr);
  619. if (dsmuid_attr) {
  620. Slapi_ValueSet *dsmuid_vs = NULL;
  621. slapi_attr_get_valueset(dsmuid_attr, &dsmuid_vs);
  622. if (dsmuid_vs) {
  623. vs = slapi_valueset_new();
  624. int j;
  625. for (j = slapi_attr_first_value(attr, &v); j != -1;
  626. j = slapi_attr_next_value(attr, i, &v)) {
  627. if (!slapi_valueset_find(dsmuid_attr, dsmuid_vs, v)) {
  628. slapi_valueset_add_value(vs, v);
  629. }
  630. }
  631. slapi_valueset_free(dsmuid_vs); dsmuid_vs = NULL;
  632. }
  633. }
  634. }
  635. if (!vs) {
  636. slapi_attr_get_valueset(attr, &vs);
  637. }
  638. ad_type = slapi_ch_strdup(attr_map[i].windows_attribute_name);
  639. slapi_entry_attr_find(ad_entry, ad_type, &ad_attr);
  640. is_present_local = (NULL == ad_attr) ? 0 : 1;
  641. if (is_present_local) {
  642. int values_equal = 0;
  643. values_equal = attr_compare_equal(attr, ad_attr);
  644. if (!values_equal) {
  645. slapi_log_error(
  646. SLAPI_LOG_PLUGIN,
  647. posix_winsync_plugin_name,
  648. "_pre_ad_mod_group_cb -- update mods: %s, %s : values are different -> modify\n",
  649. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  650. ad_type);
  651. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, ad_type,
  652. valueset_get_valuearray(vs));
  653. *do_modify = 1;
  654. }
  655. } else {
  656. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, ad_type,
  657. valueset_get_valuearray(vs));
  658. if (0 == slapi_attr_type_cmp(type, "gidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  659. Slapi_Mod *mysmod = slapi_mod_new();
  660. addNisDomainName(mysmod, ds_entry);
  661. slapi_mods_add_ldapmod(smods, slapi_mod_get_ldapmod_passout(mysmod));
  662. slapi_mod_free(&mysmod);
  663. }
  664. *do_modify = 1;
  665. }
  666. slapi_ch_free((void**) &ad_type);
  667. slapi_valueset_free(vs);
  668. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  669. "_pre_ad_mod_group_cb -- add modify %s DS account [%s]\n",
  670. attr_map[i].windows_attribute_name,
  671. slapi_entry_get_dn_const(ds_entry));
  672. }
  673. }
  674. }
  675. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "_pre_ad_mod_group_cb -- step\n");
  676. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  677. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  678. slapi_mod_dump(mod, 0);
  679. }
  680. }
  681. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  682. "<-- _pre_ad_mod_group_cb -- end\n");
  683. return;
  684. }
  685. static void
  686. posix_winsync_pre_ds_mod_user_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  687. Slapi_Entry *ds_entry, Slapi_Mods *smods, int *do_modify)
  688. {
  689. LDAPMod* mod = NULL;
  690. Slapi_Attr *attr = NULL;
  691. int is_present_local = 0;
  692. int do_modify_local = 0;
  693. int rc;
  694. int i;
  695. windows_attribute_map *attr_map = user_attribute_map;
  696. PRBool posixval = PR_TRUE;
  697. if (posix_winsync_config_get_msSFUSchema())
  698. attr_map = user_mssfu_attribute_map;
  699. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  700. "--> _pre_ds_mod_user_cb -- begin\n");
  701. /* check all of the required attributes are in the ad_entry:
  702. * MUST (cn $ uid $ uidNumber $ gidNumber $ homeDirectory).
  703. * If any of the required attributes are missing, drop them before adding
  704. * the entry to the DS. */
  705. for (i = 0; attr_map[i].windows_attribute_name != NULL; i++) {
  706. Slapi_Attr *pa_attr;
  707. if (attr_map[i].isMUST &&
  708. slapi_entry_attr_find(ad_entry,
  709. attr_map[i].windows_attribute_name,
  710. &pa_attr)) {
  711. /* required attribute does not exist */
  712. posixval = PR_FALSE;
  713. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  714. "AD entry %s does not have required attribute %s for posixAccount objectclass.\n",
  715. slapi_entry_get_dn_const(ad_entry),
  716. attr_map[i].ldap_attribute_name);
  717. }
  718. }
  719. /* add objectclass: posixAccount, uidnumber ,gidnumber ,homeDirectory, loginshell */
  720. /* in the ad to ds case we have no changelog, so we have to compare the entries */
  721. for (rc = slapi_entry_first_attr(ad_entry, &attr); rc == 0;
  722. rc = slapi_entry_next_attr(ad_entry, attr, &attr)) {
  723. char *type = NULL;
  724. slapi_attr_get_type(attr, &type);
  725. for (i = 0; attr_map[i].windows_attribute_name != NULL; i++) {
  726. if (0 == slapi_attr_type_cmp(type, attr_map[i].windows_attribute_name,
  727. SLAPI_TYPE_CMP_SUBTYPE)) {
  728. Slapi_Attr *local_attr = NULL;
  729. char *local_type = NULL;
  730. Slapi_ValueSet *vs = NULL;
  731. slapi_attr_get_valueset(attr, &vs);
  732. local_type = slapi_ch_strdup(attr_map[i].ldap_attribute_name);
  733. slapi_entry_attr_find(ds_entry, local_type, &local_attr);
  734. is_present_local = (NULL == local_attr) ? 0 : 1;
  735. if (is_present_local) {
  736. /* DS entry has the posix attrs.
  737. * I.e., it is a posix account*/
  738. int values_equal = 0;
  739. posixval = PR_TRUE;
  740. values_equal = attr_compare_equal(attr, local_attr);
  741. if (!values_equal) {
  742. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  743. "_pre_ds_mod_user_cb -- update mods: %s, %s : values are different -> modify\n",
  744. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  745. local_type);
  746. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, local_type,
  747. valueset_get_valuearray(vs));
  748. *do_modify = 1;
  749. }
  750. } else if (posixval) {
  751. /* only if AD provides the all necessary attributes */
  752. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, local_type,
  753. valueset_get_valuearray(vs));
  754. *do_modify = do_modify_local = 1;
  755. }
  756. slapi_valueset_free(vs);
  757. slapi_ch_free((void**) &local_type);
  758. /* what about if delete all values on windows ????? */
  759. }
  760. }
  761. }
  762. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  763. "<-- _pre_ds_mod_user_cb present %d modify %d isPosixaccount %s\n",
  764. is_present_local, do_modify_local,
  765. posixval?"yes":"no");
  766. if (!is_present_local && do_modify_local && posixval) {
  767. Slapi_Attr *oc_attr = NULL;
  768. Slapi_Value *voc = slapi_value_new();
  769. slapi_value_init_string(voc, "posixAccount");
  770. rc = slapi_entry_attr_find(ds_entry, "objectClass", &oc_attr);
  771. if (rc == 0) {
  772. const struct berval *bv = slapi_value_get_berval(voc);
  773. if (bv && slapi_attr_value_find(oc_attr, bv) != 0) {
  774. Slapi_ValueSet *oc_vs = slapi_valueset_new();
  775. Slapi_Value *oc_nv = slapi_value_new();
  776. slapi_attr_get_valueset(oc_attr, &oc_vs);
  777. slapi_value_init_string(oc_nv, "posixAccount");
  778. slapi_valueset_add_value(oc_vs, oc_nv);
  779. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  780. "<-- _pre_ds_mod_user_cb add oc:posixAccount\n");
  781. slapi_value_init_string(voc, "shadowAccount");
  782. if (slapi_attr_value_find(oc_attr, slapi_value_get_berval(voc)) != 0) {
  783. Slapi_Value *oc_nv = slapi_value_new();
  784. slapi_value_init_string(oc_nv, "shadowAccount");
  785. slapi_valueset_add_value(oc_vs, oc_nv);
  786. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  787. "<-- _pre_ds_mod_user_cb add oc:shadowAccount\n");
  788. }
  789. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, "objectClass",
  790. valueset_get_valuearray(oc_vs));
  791. slapi_value_free(&oc_nv);
  792. slapi_valueset_free(oc_vs);
  793. if (posix_winsync_config_get_mapNestedGrouping()) {
  794. memberUidLock();
  795. addUserToGroupMembership(ds_entry);
  796. memberUidUnlock();
  797. }
  798. }
  799. }
  800. slapi_value_free(&voc);
  801. }
  802. sync_acct_disable(cbdata, rawentry, ds_entry, ACCT_DISABLE_TO_DS, NULL, smods, do_modify);
  803. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_mod_user_cb %s %s\n",
  804. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)), (do_modify) ? "modified"
  805. : "not modified");
  806. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  807. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  808. slapi_mod_dump(mod, 0);
  809. }
  810. }
  811. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_mod_user_cb -- end\n");
  812. return;
  813. }
  814. static void
  815. posix_winsync_pre_ds_mod_group_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  816. Slapi_Entry *ds_entry, Slapi_Mods *smods, int *do_modify)
  817. {
  818. LDAPMod* mod = NULL;
  819. Slapi_Attr *attr = NULL;
  820. int is_present_local = 0;
  821. int do_modify_local = 0;
  822. int rc;
  823. windows_attribute_map *attr_map = group_attribute_map;
  824. if (posix_winsync_config_get_msSFUSchema())
  825. attr_map = group_mssfu_attribute_map;
  826. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  827. "--> _pre_ds_mod_group_cb -- begin\n");
  828. /* in the ad to ds case we have no changelog, so we have to compare the entries */
  829. for (rc = slapi_entry_first_attr(ad_entry, &attr); rc == 0; rc
  830. = slapi_entry_next_attr(ad_entry, attr, &attr)) {
  831. char *type = NULL;
  832. Slapi_ValueSet *vs = NULL;
  833. size_t i = 0;
  834. slapi_attr_get_type(attr, &type);
  835. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  836. if (0 == slapi_attr_type_cmp(type, attr_map[i].windows_attribute_name,
  837. SLAPI_TYPE_CMP_SUBTYPE)) {
  838. Slapi_Attr *local_attr = NULL;
  839. char *local_type = NULL;
  840. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "1.\n");
  841. slapi_attr_get_valueset(attr, &vs);
  842. local_type = slapi_ch_strdup(attr_map[i].ldap_attribute_name);
  843. slapi_entry_attr_find(ds_entry, local_type, &local_attr);
  844. is_present_local = (NULL == local_attr) ? 0 : 1;
  845. if (is_present_local) {
  846. int values_equal = 0;
  847. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "2.\n");
  848. values_equal = attr_compare_equal(attr, local_attr);
  849. if (!values_equal) {
  850. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  851. "_pre_ds_mod_group_cb -- update mods: %s, %s : values are different -> modify\n",
  852. slapi_sdn_get_dn(slapi_entry_get_sdn_const(ds_entry)),
  853. local_type);
  854. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, local_type,
  855. valueset_get_valuearray(vs));
  856. *do_modify = 1;
  857. }
  858. } else {
  859. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "3.\n");
  860. slapi_mods_add_mod_values(smods, LDAP_MOD_ADD, local_type,
  861. valueset_get_valuearray(vs));
  862. *do_modify = do_modify_local = 1;
  863. }
  864. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "4.\n");
  865. slapi_ch_free((void**) &local_type);
  866. slapi_valueset_free(vs);
  867. /* what about if delete all values on windows ???? */
  868. }
  869. }
  870. }
  871. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  872. "_pre_ds_mod_group_cb present %d modify %d before\n", is_present_local,
  873. do_modify_local);
  874. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  875. "_pre_ds_mod_group_cb present %d modify %d\n", is_present_local,
  876. do_modify_local);
  877. if (!is_present_local && do_modify_local) {
  878. Slapi_Attr *oc_attr = NULL;
  879. Slapi_Value *voc = slapi_value_new();
  880. slapi_value_init_string(voc, "posixGroup");
  881. slapi_entry_attr_find(ds_entry, "objectClass", &oc_attr);
  882. if (slapi_attr_value_find(oc_attr, slapi_value_get_berval(voc)) != 0) {
  883. Slapi_ValueSet *oc_vs = NULL;
  884. Slapi_Value *oc_nv = slapi_value_new();
  885. slapi_attr_get_valueset(oc_attr, &oc_vs);
  886. slapi_value_init_string(oc_nv, "posixGroup");
  887. slapi_valueset_add_value(oc_vs, oc_nv);
  888. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  889. "_pre_ds_mod_group_cb add oc:posixGroup\n");
  890. slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, "objectClass",
  891. valueset_get_valuearray(oc_vs));
  892. slapi_value_free(&oc_nv);
  893. slapi_valueset_free(oc_vs);
  894. }
  895. slapi_value_free(&voc);
  896. }
  897. if (posix_winsync_config_get_mapMemberUid() || posix_winsync_config_get_mapNestedGrouping()) {
  898. memberUidLock();
  899. modGroupMembership(ds_entry, smods, do_modify, do_modify_local);
  900. memberUidUnlock();
  901. }
  902. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "_pre_ds_mod_group_cb step\n");
  903. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  904. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  905. slapi_mod_dump(mod, 0);
  906. }
  907. }
  908. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  909. "<-- _pre_ds_mod_group_cb -- end\n");
  910. return;
  911. }
  912. static void
  913. posix_winsync_pre_ds_add_user_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  914. Slapi_Entry *ds_entry)
  915. {
  916. Slapi_Attr *attr = NULL;
  917. char *type = NULL;
  918. PRBool posixval = PR_TRUE;
  919. windows_attribute_map *attr_map = user_attribute_map;
  920. int i = 0;
  921. if (posix_winsync_config_get_msSFUSchema())
  922. attr_map = user_mssfu_attribute_map;
  923. /* add objectclass: posixAccount, uidnumber, gidnumber, homeDirectory, loginShell */
  924. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  925. "--> _pre_ds_add_user_cb -- begin\n");
  926. /* check all of the required attributes are in the ad_entry:
  927. * MUST (cn $ uid $ uidNumber $ gidNumber $ homeDirectory).
  928. * If any of the required attributes are missing, drop them before adding
  929. * the entry to the DS. */
  930. for (i = 0; attr_map[i].windows_attribute_name != NULL; i++) {
  931. Slapi_Attr *pa_attr;
  932. if (attr_map[i].isMUST &&
  933. slapi_entry_attr_find(ad_entry,
  934. attr_map[i].windows_attribute_name,
  935. &pa_attr)) {
  936. /* required attribute does not exist */
  937. posixval = PR_FALSE;
  938. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  939. "AD entry %s does not have required attribute %s for posixAccount objectclass.\n",
  940. slapi_entry_get_dn_const(ad_entry),
  941. attr_map[i].ldap_attribute_name);
  942. }
  943. }
  944. /* converts the AD attributes to DS posix attribute if all the posix
  945. * required attributes are available */
  946. if (posixval) {
  947. int rc;
  948. for (slapi_entry_first_attr(ad_entry, &attr); attr;
  949. slapi_entry_next_attr(ad_entry, attr, &attr)) {
  950. slapi_attr_get_type(attr, &type);
  951. if (!type) {
  952. continue;
  953. }
  954. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  955. "--> _pre_ds_add_user_cb -- "
  956. "look for [%s] to new entry [%s]\n",
  957. type, slapi_entry_get_dn_const(ds_entry));
  958. for (i = 0; attr_map[i].windows_attribute_name != NULL; i++) {
  959. if (slapi_attr_type_cmp(attr_map[i].windows_attribute_name,
  960. type, SLAPI_TYPE_CMP_SUBTYPE) == 0) {
  961. Slapi_ValueSet *svs = NULL;
  962. slapi_attr_get_valueset(attr, &svs);
  963. slapi_entry_add_valueset(ds_entry,
  964. attr_map[i].ldap_attribute_name, svs);
  965. slapi_valueset_free(svs);
  966. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  967. "--> _pre_ds_add_user_cb -- "
  968. "adding val for [%s] to new entry [%s]\n",
  969. type, slapi_entry_get_dn_const(ds_entry));
  970. }
  971. }
  972. }
  973. rc = slapi_entry_add_string(ds_entry, "objectClass", "posixAccount");
  974. rc |= slapi_entry_add_string(ds_entry, "objectClass", "shadowAccount");
  975. rc |= slapi_entry_add_string(ds_entry, "objectClass", "inetUser");
  976. if (rc != 0) {
  977. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  978. "<-- _pre_ds_add_user_cb -- adding objectclass for new entry failed %d\n",
  979. rc);
  980. } else {
  981. if (posix_winsync_config_get_mapNestedGrouping()) {
  982. memberUidLock();
  983. addUserToGroupMembership(ds_entry);
  984. memberUidUnlock();
  985. }
  986. }
  987. }
  988. sync_acct_disable(cbdata, rawentry, ds_entry, ACCT_DISABLE_TO_DS, ds_entry, NULL, NULL);
  989. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "<-- _pre_ds_add_user_cb -- end\n");
  990. return;
  991. }
  992. static void
  993. posix_winsync_pre_ds_add_group_cb(void *cbdata, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry,
  994. Slapi_Entry *ds_entry)
  995. {
  996. Slapi_Attr *attr = NULL;
  997. char *type = NULL;
  998. PRBool posixval = PR_FALSE;
  999. windows_attribute_map *attr_map = group_attribute_map;
  1000. if (posix_winsync_config_get_msSFUSchema())
  1001. attr_map = group_mssfu_attribute_map;
  1002. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1003. "--> posix_winsync_pre_ds_add_group_cb -- begin\n");
  1004. for (slapi_entry_first_attr(ad_entry, &attr); attr; slapi_entry_next_attr(ad_entry, attr, &attr)) {
  1005. size_t i = 0;
  1006. slapi_attr_get_type(attr, &type);
  1007. if (!type) {
  1008. continue;
  1009. }
  1010. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "--> _pre_ds_add_group_cb -- "
  1011. "look for [%s] to new entry [%s]\n", type, slapi_entry_get_dn_const(ds_entry));
  1012. for (i = 0; attr_map && attr_map[i].windows_attribute_name != NULL; i++) {
  1013. if (slapi_attr_type_cmp(attr_map[i].windows_attribute_name, type,
  1014. SLAPI_TYPE_CMP_SUBTYPE) == 0) {
  1015. Slapi_ValueSet *svs = NULL;
  1016. slapi_attr_get_valueset(attr, &svs);
  1017. slapi_entry_add_valueset(ds_entry, attr_map[i].ldap_attribute_name, svs);
  1018. slapi_valueset_free(svs);
  1019. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1020. "--> _pre_ds_add_group_cb -- "
  1021. "adding val for [%s] to new entry [%s]\n", type,
  1022. slapi_entry_get_dn_const(ds_entry));
  1023. posixval = PR_TRUE;
  1024. }
  1025. }
  1026. }
  1027. if (posixval) {
  1028. int rc;
  1029. rc = slapi_entry_add_string(ds_entry, "objectClass", "posixGroup");
  1030. if (rc != 0) {
  1031. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1032. "<-- _pre_ds_add_group_cb -- adding objectclass for new entry failed %d\n",
  1033. rc);
  1034. }
  1035. }
  1036. if (posix_winsync_config_get_mapMemberUid() || posix_winsync_config_get_mapNestedGrouping()) {
  1037. memberUidLock();
  1038. addGroupMembership(ds_entry, ad_entry);
  1039. memberUidUnlock();
  1040. }
  1041. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1042. "<-- posix_winsync_pre_ds_add_group_cb -- end\n");
  1043. return;
  1044. }
  1045. static void
  1046. posix_winsync_get_new_ds_user_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_user_dn_cb -- old dn [%s] -- begin\n",
  1052. *new_dn_string);
  1053. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1054. "<-- posix_winsync_get_new_ds_user_dn_cb -- new dn [%s] -- end\n",
  1055. *new_dn_string);
  1056. return;
  1057. }
  1058. static void
  1059. posix_winsync_get_new_ds_group_dn_cb(void *cbdata, const Slapi_Entry *rawentry,
  1060. Slapi_Entry *ad_entry, char **new_dn_string, const Slapi_DN *ds_suffix,
  1061. const Slapi_DN *ad_suffix)
  1062. {
  1063. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1064. "--> posix_winsync_get_new_ds_group_dn_cb -- begin\n");
  1065. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1066. "<-- posix_winsync_get_new_ds_group_dn_cb -- end\n");
  1067. return;
  1068. }
  1069. static void
  1070. posix_winsync_pre_ad_mod_user_mods_cb(void *cbdata, const Slapi_Entry *rawentry,
  1071. const Slapi_DN *local_dn, const Slapi_Entry *ds_entry, LDAPMod * const *origmods,
  1072. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  1073. {
  1074. Slapi_Mods *smods = slapi_mods_new();
  1075. Slapi_Mods *new_smods = slapi_mods_new();
  1076. LDAPMod *mod = NULL;
  1077. windows_attribute_map *attr_map = user_attribute_map;
  1078. if (posix_winsync_config_get_msSFUSchema())
  1079. attr_map = user_mssfu_attribute_map;
  1080. /* mod if changed objectclass: posixAccount, uidnumber, gidnumber, homeDirectory, loginShell */
  1081. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1082. "--> _pre_ad_mod_user_mods_cb -- begin DS account [%s] \n",
  1083. slapi_entry_get_dn_const(ds_entry));
  1084. /* wrap the modstosend in a Slapi_Mods for convenience */
  1085. slapi_mods_init_passin(new_smods, *modstosend);
  1086. slapi_mods_init_byref(smods, (LDAPMod**) origmods);
  1087. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  1088. size_t i = 0;
  1089. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1090. "_pre_ad_mod_user_mods_cb -- check modify type %s\n", mod->mod_type);
  1091. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  1092. if (0 == slapi_attr_type_cmp(mod->mod_type, attr_map[i].ldap_attribute_name,
  1093. SLAPI_TYPE_CMP_SUBTYPE)) {
  1094. Slapi_Mod *mysmod = slapi_mod_new();
  1095. slapi_mod_init_byval(mysmod, mod);
  1096. slapi_mod_set_type(mysmod, attr_map[i].windows_attribute_name);
  1097. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(mysmod));
  1098. slapi_mod_free(&mysmod);
  1099. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1100. "_pre_ad_mod_user_mods_cb -- add modify %s DS account [%s]\n",
  1101. attr_map[i].windows_attribute_name,
  1102. slapi_entry_get_dn_const(ds_entry));
  1103. if (0 == slapi_attr_type_cmp(mod->mod_type, "uidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  1104. Slapi_Mod *ocsmod = slapi_mod_new();
  1105. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1106. "_pre_ad_mod_user_mods_cb -- add NisDomain\n");
  1107. addNisDomainName(ocsmod, ds_entry);
  1108. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(ocsmod));
  1109. slapi_mod_free(&ocsmod);
  1110. }
  1111. }
  1112. }
  1113. if (0 == slapi_attr_type_cmp(mod->mod_type, "nsRoleDN", SLAPI_TYPE_CMP_SUBTYPE)) {
  1114. int dummy = 0;
  1115. sync_acct_disable(cbdata, rawentry, (Slapi_Entry *) ds_entry, ACCT_DISABLE_TO_AD, NULL,
  1116. new_smods, &dummy);
  1117. }
  1118. }
  1119. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  1120. for (mod = slapi_mods_get_first_mod(new_smods); mod; mod
  1121. = slapi_mods_get_next_mod(new_smods)) {
  1122. slapi_mod_dump(mod, 0);
  1123. }
  1124. }
  1125. *modstosend = slapi_mods_get_ldapmods_passout(new_smods);
  1126. slapi_mods_free(&smods);
  1127. slapi_mods_free(&new_smods);
  1128. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1129. "<-- _pre_ad_mod_user_mods_cb -- end\n");
  1130. return;
  1131. }
  1132. static void
  1133. posix_winsync_pre_ad_mod_group_mods_cb(void *cbdata, const Slapi_Entry *rawentry,
  1134. const Slapi_DN *local_dn, const Slapi_Entry *ds_entry, LDAPMod * const *origmods,
  1135. Slapi_DN *remote_dn, LDAPMod ***modstosend)
  1136. {
  1137. Slapi_Mods *smods = slapi_mods_new();
  1138. Slapi_Mods *new_smods = slapi_mods_new();
  1139. LDAPMod *mod = NULL;
  1140. windows_attribute_map *attr_map = group_attribute_map;
  1141. if (posix_winsync_config_get_msSFUSchema())
  1142. attr_map = group_mssfu_attribute_map;
  1143. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1144. "--> _pre_ad_mod_group_mods_cb -- begin\n");
  1145. /* wrap the modstosend in a Slapi_Mods for convenience */
  1146. slapi_mods_init_passin(new_smods, *modstosend);
  1147. slapi_mods_init_byref(smods, (LDAPMod**) origmods);
  1148. for (mod = slapi_mods_get_first_mod(smods); mod; mod = slapi_mods_get_next_mod(smods)) {
  1149. size_t i = 0;
  1150. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1151. "_pre_ad_mod_group_mods_cb -- check modify type %s\n", mod->mod_type);
  1152. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  1153. if (0 == slapi_attr_type_cmp(mod->mod_type, attr_map[i].ldap_attribute_name,
  1154. SLAPI_TYPE_CMP_SUBTYPE)) {
  1155. Slapi_Mod *mysmod = slapi_mod_new();
  1156. if (mod->mod_op & LDAP_MOD_DELETE) {
  1157. slapi_mod_init(mysmod, 0);
  1158. slapi_mod_set_operation(mysmod, LDAP_MOD_DELETE | LDAP_MOD_BVALUES);
  1159. slapi_mod_set_type(mysmod, attr_map[i].windows_attribute_name);
  1160. } else {
  1161. slapi_mod_init_byval(mysmod, mod);
  1162. slapi_mod_set_type(mysmod, attr_map[i].windows_attribute_name);
  1163. if (0 == slapi_attr_type_cmp(mod->mod_type, "gidNumber", SLAPI_TYPE_CMP_SUBTYPE)) {
  1164. Slapi_Mod *ocsmod = slapi_mod_new();
  1165. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1166. "_pre_ad_mod_group_mods_cb -- add NisDomain\n");
  1167. addNisDomainName(ocsmod, ds_entry);
  1168. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(ocsmod));
  1169. slapi_mod_free(&ocsmod);
  1170. }
  1171. }
  1172. slapi_mods_add_ldapmod(new_smods, slapi_mod_get_ldapmod_passout(mysmod));
  1173. slapi_mod_free(&mysmod);
  1174. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1175. "_pre_ad_mod_group_mods_cb -- add modify %s DS account [%s]\n",
  1176. attr_map[i].windows_attribute_name,
  1177. slapi_entry_get_dn_const(ds_entry));
  1178. }
  1179. }
  1180. }
  1181. *modstosend = slapi_mods_get_ldapmods_passout(new_smods);
  1182. if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
  1183. for (mod = slapi_mods_get_first_mod(new_smods); mod;
  1184. mod = slapi_mods_get_next_mod(new_smods)) {
  1185. slapi_mod_dump(mod, 0);
  1186. }
  1187. }
  1188. slapi_mods_free(&smods);
  1189. slapi_mods_free(&new_smods);
  1190. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1191. "<-- _pre_ad_mod_group_mods_cb -- end\n");
  1192. return;
  1193. }
  1194. static int
  1195. posix_winsync_can_add_entry_to_ad_cb(void *cbdata, const Slapi_Entry *local_entry,
  1196. const Slapi_DN *remote_dn)
  1197. {
  1198. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1199. "--> posix_winsync_can_add_entry_to_ad_cb -- begin\n");
  1200. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1201. "<-- posix_winsync_can_add_entry_to_ad_cb -- end\n");
  1202. return 1; /* false - do not allow entries to be added to ad */
  1203. }
  1204. static void
  1205. posix_winsync_begin_update_cb(void *cbdata, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree,
  1206. int is_total)
  1207. {
  1208. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1209. "--> posix_winsync_begin_update_cb -- begin\n");
  1210. posix_winsync_config_reset_MOFTaskCreated();
  1211. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1212. "<-- posix_winsync_begin_update_cb -- end\n");
  1213. return;
  1214. }
  1215. static void
  1216. posix_winsync_end_update_cb(void *cbdata, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree,
  1217. int is_total)
  1218. {
  1219. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1220. "--> posix_winsync_end_update_cb -- begin %d %d\n",
  1221. posix_winsync_config_get_MOFTaskCreated(),
  1222. posix_winsync_config_get_createMOFTask());
  1223. if (1 && posix_winsync_config_get_createMOFTask()) {
  1224. /* add a task to schedule memberof Plugin for fix memebrof attributs */
  1225. Slapi_PBlock *pb = slapi_pblock_new();
  1226. Slapi_Entry *e_task = slapi_entry_alloc();
  1227. int rc = 0;
  1228. char *dn = slapi_create_dn_string("cn=%s,cn=%s,cn=tasks,cn=config",
  1229. posix_winsync_plugin_name, MEMBEROFTASK);
  1230. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1231. "--> posix_winsync_end_update_cb, create task %s\n", dn);
  1232. if (NULL == dn) {
  1233. slapi_pblock_destroy(pb);
  1234. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1235. "posix_winsync_end_update_cb: "
  1236. "failed to create task dn: cn=%s,%s,cn=tasks,cn=config\n",
  1237. posix_winsync_plugin_name, MEMBEROFTASK);
  1238. return;
  1239. }
  1240. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1241. "--> posix_winsync_end_update_cb, init'ing task\n");
  1242. slapi_entry_init(e_task, slapi_ch_strdup(dn), NULL);
  1243. slapi_entry_add_string(e_task, "cn", slapi_ch_strdup(posix_winsync_plugin_name));
  1244. slapi_entry_add_string(e_task, "objectClass", "extensibleObject");
  1245. slapi_entry_add_string(e_task, "basedn", slapi_sdn_get_dn(ds_subtree));
  1246. slapi_add_entry_internal_set_pb(pb, e_task, NULL, posix_winsync_get_plugin_identity(), 0);
  1247. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1248. "--> posix_winsync_end_update_cb, adding task\n");
  1249. slapi_add_internal_pb(pb);
  1250. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1251. "--> posix_winsync_end_update_cb, retrieving return code\n");
  1252. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  1253. if (LDAP_ALREADY_EXISTS == rc) {
  1254. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1255. "posix_winsync_end_update_cb: "
  1256. "task entry %s already exists\n",
  1257. posix_winsync_plugin_name);
  1258. } else if (rc != 0) {
  1259. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1260. "posix_winsync_end_update_cb: "
  1261. "failed to add task entry (%d)\n", rc);
  1262. } else {
  1263. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1264. "posix_winsync_end_update_cb: "
  1265. "add task entry\n");
  1266. }
  1267. /* slapi_entry_free(e_task); */
  1268. slapi_pblock_destroy(pb);
  1269. pb = NULL;
  1270. posix_winsync_config_reset_MOFTaskCreated();
  1271. }
  1272. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1273. "<-- posix_winsync_end_update_cb -- end\n");
  1274. return;
  1275. }
  1276. static void
  1277. posix_winsync_destroy_agmt_cb(void *cbdata, const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree)
  1278. {
  1279. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1280. "--> posix_winsync_destroy_agmt_cb -- begin\n");
  1281. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1282. "<-- posix_winsync_destroy_agmt_cb -- end\n");
  1283. return;
  1284. }
  1285. static void
  1286. 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)
  1287. {
  1288. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1289. "--> posix_winsync_post_ad_mod_user_cb -- begin\n");
  1290. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1291. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1292. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1293. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1294. #endif
  1295. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1296. "<-- posix_winsync_post_ad_mod_user_cb -- end\n");
  1297. return;
  1298. }
  1299. static void
  1300. 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)
  1301. {
  1302. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1303. "--> posix_winsync_post_ad_mod_group_cb -- begin\n");
  1304. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1305. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1306. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1307. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1308. #endif
  1309. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1310. "<-- posix_winsync_post_ad_mod_group_cb -- end\n");
  1311. return;
  1312. }
  1313. static void
  1314. 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)
  1315. {
  1316. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1317. "--> posix_winsync_post_ds_mod_user_cb -- begin\n");
  1318. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1319. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1320. "Result of modifying DS entry [%s] was [%d:%s]\n",
  1321. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1322. #endif
  1323. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1324. "<-- posix_winsync_post_ds_mod_user_cb -- end\n");
  1325. return;
  1326. }
  1327. static void
  1328. 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)
  1329. {
  1330. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1331. "--> posix_winsync_post_ds_mod_group_cb -- begin\n");
  1332. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1333. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1334. "Result of modifying DS entry [%s] was [%d:%s]\n",
  1335. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1336. #endif
  1337. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1338. "<-- posix_winsync_post_ds_mod_group_cb -- end\n");
  1339. return;
  1340. }
  1341. static void
  1342. posix_winsync_post_ds_add_user_cb(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  1343. {
  1344. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1345. "--> posix_winsync_post_ds_add_user_cb -- begin\n");
  1346. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1347. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1348. "Result of adding DS entry [%s] was [%d:%s]\n",
  1349. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1350. #endif
  1351. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1352. "<-- posix_winsync_post_ds_add_user_cb -- end\n");
  1353. return;
  1354. }
  1355. static void
  1356. posix_winsync_post_ds_add_group_cb(void *cookie, const Slapi_Entry *rawentry, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry, int *result)
  1357. {
  1358. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1359. "--> posix_winsync_post_ds_add_group_cb -- begin\n");
  1360. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1361. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1362. "Result of adding DS entry [%s] was [%d:%s]\n",
  1363. slapi_entry_get_dn(ds_entry), *result, ldap_err2string(*result));
  1364. #endif
  1365. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1366. "<-- posix_winsync_post_ds_add_group_cb -- end\n");
  1367. return;
  1368. }
  1369. /* winsync_plugin_call_pre_ad_add_user_cb(prp->agmt, mapped_entry, e); */
  1370. static void
  1371. posix_winsync_pre_ad_add_user_cb(void *cookie, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry)
  1372. {
  1373. Slapi_Attr * obj_attr = NULL; /* Entry attributes */
  1374. windows_attribute_map *attr_map=user_attribute_map;
  1375. int rc = 0;
  1376. if(posix_winsync_config_get_msSFUSchema())
  1377. attr_map=user_mssfu_attribute_map;
  1378. /* if ds_entry has oc posixAccount add uidnumber, gidnumber, homeDirectory, loginShell, gecos */
  1379. /* syncing/mapping of nsaccountlock -> userAccountControl will already done by the normal Win Sync-Service */
  1380. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1381. "--> _pre_ad_add_user_cb -- begin DS account [%s] \n", slapi_entry_get_dn_const(ds_entry));
  1382. rc = slapi_entry_attr_find(ds_entry, "objectclass", &obj_attr);
  1383. if (rc == 0) { /* Found objectclasses, so... */
  1384. int i;
  1385. Slapi_Value * value = NULL; /* Attribute values */
  1386. slapi_log_error( SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,"_pre_ad_add_user_cb -- test objectclass posixAccount\n");
  1387. for (
  1388. i = slapi_attr_first_value(obj_attr, &value);
  1389. i != -1;
  1390. i = slapi_attr_next_value(obj_attr, i, &value)
  1391. ) {
  1392. const char * oc = NULL;
  1393. oc = slapi_value_get_string(value);
  1394. slapi_log_error( SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,"_pre_ad_add_user_cb -- oc: %s \n", oc);
  1395. if (strncasecmp(oc,"posixAccount",13)==0){ /* entry has objectclass posixAccount */
  1396. Slapi_Attr *attr = NULL;
  1397. char *nisdomainname = getNisDomainName(ds_entry);
  1398. for (rc = slapi_entry_first_attr(ds_entry, &attr); attr && (rc == 0);
  1399. rc = slapi_entry_next_attr(ds_entry, attr, &attr))
  1400. {
  1401. char *type = NULL;
  1402. size_t i = 0;
  1403. slapi_attr_get_type( attr, &type );
  1404. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1405. "_pre_ad_add_user_cb -- check add attr: %s\n", type);
  1406. for (; attr_map[i].windows_attribute_name != NULL; i++) {
  1407. if (0 == slapi_attr_type_cmp(type,attr_map[i].ldap_attribute_name, SLAPI_TYPE_CMP_SUBTYPE)){
  1408. Slapi_ValueSet *vs = NULL;
  1409. slapi_attr_get_valueset(attr,&vs);
  1410. slapi_entry_add_valueset(ad_entry, attr_map[i].windows_attribute_name, vs);
  1411. slapi_valueset_free(vs);
  1412. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1413. "--> _pre_ad_add_user_cb -- "
  1414. "adding val for [%s] to new entry [%s]\n",
  1415. type, slapi_entry_get_dn_const(ad_entry));
  1416. }
  1417. }
  1418. }
  1419. if (nisdomainname) {
  1420. slapi_entry_add_value(ad_entry,
  1421. "msSFU30NisDomain", slapi_value_new_string(nisdomainname));
  1422. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1423. "--> _pre_ad_add_user_cb -- "
  1424. "adding val for [%s] to new entry [%s]\n",
  1425. "msSFU30NisDomain", nisdomainname);
  1426. slapi_ch_free_string(&nisdomainname);
  1427. }
  1428. }
  1429. }
  1430. }
  1431. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1432. "<-- _pre_ad_add_user_cb -- end\n");
  1433. return;
  1434. }
  1435. static void
  1436. posix_winsync_pre_ad_add_group_cb(void *cookie, Slapi_Entry *ad_entry, Slapi_Entry *ds_entry)
  1437. {
  1438. Slapi_Attr * obj_attr = NULL; /* Entry attributes */
  1439. windows_attribute_map *attr_map = group_attribute_map;
  1440. int rc = 0;
  1441. if (posix_winsync_config_get_msSFUSchema()) {
  1442. attr_map=group_mssfu_attribute_map;
  1443. }
  1444. /* if ds_entry has oc posixGroup add gidnumber, ... */
  1445. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1446. "--> _pre_ad_add_group_cb -- begin DS account [%s] \n", slapi_entry_get_dn_const(ds_entry));
  1447. rc = slapi_entry_attr_find(ds_entry, "objectclass", &obj_attr);
  1448. if (rc == 0) { /* Found objectclasses, so... */
  1449. int i;
  1450. Slapi_Value * value = NULL; /* Attribute values */
  1451. slapi_log_error( SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,"_pre_ad_add_group_cb -- test objectclass posixGroup\n");
  1452. for (i = slapi_attr_first_value(obj_attr, &value);
  1453. i != -1;
  1454. i = slapi_attr_next_value(obj_attr, i, &value)) {
  1455. const char * oc = NULL;
  1456. oc = slapi_value_get_string(value);
  1457. if (strncasecmp(oc,"posixGroup",11)==0){ /* entry has objectclass posixGroup */
  1458. Slapi_Attr *attr = NULL;
  1459. char *nisdomainname = getNisDomainName(ds_entry);
  1460. for (rc = slapi_entry_first_attr(ds_entry, &attr); rc == 0;
  1461. rc = slapi_entry_next_attr(ds_entry, attr, &attr))
  1462. {
  1463. char *type = NULL;
  1464. int j = 0;
  1465. slapi_attr_get_type( attr, &type );
  1466. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1467. "_pre_ad_add_group_cb -- check add attr: %s\n", type);
  1468. for (j = 0; attr_map && attr_map[j].windows_attribute_name != NULL; j++) {
  1469. if (0 == slapi_attr_type_cmp(type,attr_map[j].ldap_attribute_name, SLAPI_TYPE_CMP_SUBTYPE)){
  1470. Slapi_ValueSet *vs = NULL;
  1471. slapi_attr_get_valueset(attr,&vs);
  1472. slapi_entry_add_valueset(ad_entry, attr_map[j].windows_attribute_name, vs);
  1473. slapi_valueset_free(vs);
  1474. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1475. "--> _pre_ad_add_group_cb -- "
  1476. "adding val for [%s] to new entry [%s]\n",
  1477. type, slapi_entry_get_dn_const(ad_entry));
  1478. }
  1479. }
  1480. }
  1481. if (nisdomainname) {
  1482. slapi_entry_add_value(ad_entry, "msSFU30NisDomain", slapi_value_new_string(nisdomainname));
  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. "msSFU30NisDomain", nisdomainname);
  1487. slapi_ch_free_string(&nisdomainname);
  1488. }
  1489. }
  1490. }
  1491. }
  1492. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1493. "<-- _pre_ad_add_group_cb -- end\n");
  1494. return;
  1495. }
  1496. static void
  1497. posix_winsync_post_ad_add_user_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry, int *result)
  1498. {
  1499. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1500. "--> posix_winsync_post_ad_add_user_cb -- begin\n");
  1501. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1502. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1503. "Result of adding AD entry [%s] was [%d:%s]\n",
  1504. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1505. #endif
  1506. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1507. "<-- posix_winsync_post_ad_add_user_cb -- end\n");
  1508. return;
  1509. }
  1510. static void
  1511. posix_winsync_post_ad_add_group_cb(void *cookie, Slapi_Entry *ds_entry, Slapi_Entry *ad_entry, int *result)
  1512. {
  1513. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1514. "--> posix_winsync_post_ad_add_group_cb -- begin\n");
  1515. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1516. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1517. "Result of adding AD entry [%s] was [%d:%s]\n",
  1518. slapi_entry_get_dn(ad_entry), *result, ldap_err2string(*result));
  1519. #endif
  1520. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1521. "<-- posix_winsync_post_ad_add_group_cb -- end\n");
  1522. return;
  1523. }
  1524. static void
  1525. 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)
  1526. {
  1527. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1528. "--> posix_winsync_post_ad_mod_user_mods_cb -- begin\n");
  1529. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1530. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1531. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1532. slapi_sdn_get_dn(remote_dn), *result, ldap_err2string(*result));
  1533. #endif
  1534. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1535. "<-- posix_winsync_post_ad_mod_user_mods_cb -- end\n");
  1536. return;
  1537. }
  1538. static void
  1539. 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)
  1540. {
  1541. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1542. "--> posix_winsync_post_ad_mod_group_mods_cb -- begin\n");
  1543. #ifdef THIS_IS_JUST_AN_EXAMPLE
  1544. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1545. "Result of modifying AD entry [%s] was [%d:%s]\n",
  1546. slapi_sdn_get_dn(remote_dn), *result, ldap_err2string(*result));
  1547. #endif
  1548. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1549. "<-- posix_winsync_post_ad_mod_group_mods_cb -- end\n");
  1550. return;
  1551. }
  1552. #define DEFAULT_PRECEDENCE 25
  1553. static int precedence = DEFAULT_PRECEDENCE; /* default */
  1554. static int posix_winsync_precedence(void)
  1555. {
  1556. return precedence;
  1557. }
  1558. static void *posix_winsync_api[] = { NULL, /* reserved for api broker use, must be zero */
  1559. posix_winsync_agmt_init,
  1560. posix_winsync_dirsync_search_params_cb,
  1561. posix_winsync_pre_ad_search_cb,
  1562. posix_winsync_pre_ds_search_entry_cb,
  1563. posix_winsync_pre_ds_search_all_cb,
  1564. posix_winsync_pre_ad_mod_user_cb,
  1565. posix_winsync_pre_ad_mod_group_cb,
  1566. posix_winsync_pre_ds_mod_user_cb,
  1567. posix_winsync_pre_ds_mod_group_cb,
  1568. posix_winsync_pre_ds_add_user_cb,
  1569. posix_winsync_pre_ds_add_group_cb,
  1570. posix_winsync_get_new_ds_user_dn_cb,
  1571. posix_winsync_get_new_ds_group_dn_cb,
  1572. posix_winsync_pre_ad_mod_user_mods_cb,
  1573. posix_winsync_pre_ad_mod_group_mods_cb,
  1574. posix_winsync_can_add_entry_to_ad_cb,
  1575. posix_winsync_begin_update_cb,
  1576. posix_winsync_end_update_cb,
  1577. posix_winsync_destroy_agmt_cb,
  1578. posix_winsync_post_ad_mod_user_cb,
  1579. posix_winsync_post_ad_mod_group_cb,
  1580. posix_winsync_post_ds_mod_user_cb,
  1581. posix_winsync_post_ds_mod_group_cb,
  1582. posix_winsync_post_ds_add_user_cb,
  1583. posix_winsync_post_ds_add_group_cb,
  1584. posix_winsync_pre_ad_add_user_cb,
  1585. posix_winsync_pre_ad_add_group_cb,
  1586. posix_winsync_post_ad_add_user_cb,
  1587. posix_winsync_post_ad_add_group_cb,
  1588. posix_winsync_post_ad_mod_user_mods_cb,
  1589. posix_winsync_post_ad_mod_group_mods_cb,
  1590. posix_winsync_precedence
  1591. };
  1592. static Slapi_ComponentId *posix_winsync_plugin_id = NULL;
  1593. /*
  1594. ** Plugin identity mgmt
  1595. */
  1596. void
  1597. posix_winsync_set_plugin_identity(void * identity)
  1598. {
  1599. posix_winsync_plugin_id = identity;
  1600. }
  1601. void *
  1602. posix_winsync_get_plugin_identity()
  1603. {
  1604. return posix_winsync_plugin_id;
  1605. }
  1606. static int
  1607. posix_winsync_plugin_start(Slapi_PBlock *pb)
  1608. {
  1609. int rc;
  1610. Slapi_Entry *config_e = NULL; /* entry containing plugin config */
  1611. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1612. "--> posix_winsync_plugin_start -- begin\n");
  1613. if (slapi_apib_register(WINSYNC_v3_0_GUID, posix_winsync_api)) {
  1614. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1615. "<-- posix_winsync_plugin_start -- failed to register winsync api -- end\n");
  1616. return -1;
  1617. }
  1618. if (slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &config_e) != 0) {
  1619. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name, "missing config entry\n");
  1620. return (-1);
  1621. }
  1622. if ((rc = posix_winsync_config(config_e)) != LDAP_SUCCESS) {
  1623. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name, "configuration failed (%s)\n",
  1624. ldap_err2string(rc));
  1625. return (-1);
  1626. }
  1627. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1628. "<-- posix_winsync_plugin_start -- registered; end\n");
  1629. return 0;
  1630. }
  1631. static int
  1632. posix_winsync_plugin_close(Slapi_PBlock *pb)
  1633. {
  1634. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1635. "--> posix_winsync_plugin_close -- begin\n");
  1636. slapi_apib_unregister(WINSYNC_v1_0_GUID);
  1637. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1638. "<-- posix_winsync_plugin_close -- end\n");
  1639. return 0;
  1640. }
  1641. /* this is the slapi plugin init function,
  1642. not the one used by the winsync api
  1643. */
  1644. int
  1645. posix_winsync_plugin_init(Slapi_PBlock *pb)
  1646. {
  1647. void *plugin_id = NULL;
  1648. Slapi_Entry *confige = NULL;
  1649. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1650. "--> posix_winsync_plugin_init -- begin\n");
  1651. if (slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &confige) && confige) {
  1652. precedence = slapi_entry_attr_get_int(confige, "nsslapd-pluginprecedence");
  1653. if (!precedence) {
  1654. precedence = DEFAULT_PRECEDENCE;
  1655. }
  1656. }
  1657. if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0
  1658. || slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN, (void *) posix_winsync_plugin_start) != 0
  1659. || slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN, (void *) posix_winsync_plugin_close) != 0
  1660. || slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *) &posix_winsync_pdesc) != 0) {
  1661. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1662. "<-- posix_winsync_plugin_init -- failed to register plugin -- end\n");
  1663. return -1;
  1664. }
  1665. /* Retrieve and save the plugin identity to later pass to
  1666. internal operations */
  1667. if (slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &plugin_id) != 0) {
  1668. slapi_log_error(SLAPI_LOG_FATAL, posix_winsync_plugin_name,
  1669. "<-- posix_winsync_plugin_init -- failed to retrieve plugin identity -- end\n");
  1670. return -1;
  1671. }
  1672. posix_winsync_set_plugin_identity(plugin_id);
  1673. slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
  1674. "<-- posix_winsync_plugin_init -- end\n");
  1675. return 0;
  1676. }