posix-winsync.c 85 KB

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