posix-winsync.c 93 KB

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