ldapsecurity.cpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifdef _WIN32
  14. #define AXA_API __declspec(dllexport)
  15. #endif
  16. #include "ldapsecurity.ipp"
  17. #include "ldapsecurity.hpp"
  18. #include "authmap.ipp"
  19. /**********************************************************
  20. * CLdapSecUser *
  21. **********************************************************/
  22. CLdapSecUser::CLdapSecUser(const char *name, const char *pw) :
  23. m_pw(pw), m_authenticateStatus(AS_UNKNOWN)
  24. {
  25. setName(name);
  26. }
  27. CLdapSecUser::~CLdapSecUser()
  28. {
  29. }
  30. //non-interfaced functions
  31. void CLdapSecUser::setUserID(unsigned userid)
  32. {
  33. m_userid = userid;
  34. }
  35. void CLdapSecUser::setUserSid(int sidlen, const char* sid)
  36. {
  37. m_usersid.clear();
  38. m_usersid.append(sidlen, sid);
  39. }
  40. MemoryBuffer& CLdapSecUser::getUserSid()
  41. {
  42. return m_usersid;
  43. }
  44. //interface ISecUser
  45. const char * CLdapSecUser::getName()
  46. {
  47. return m_name.get();
  48. }
  49. bool CLdapSecUser::setName(const char * name)
  50. {
  51. if(name != NULL)
  52. {
  53. const char* atsign = strchr(name, '@');
  54. if(atsign != NULL)
  55. {
  56. m_name.set(name, atsign - name);
  57. m_realm.set(atsign + 1);
  58. }
  59. else
  60. {
  61. m_name.set(name);
  62. }
  63. }
  64. return TRUE;
  65. }
  66. const char * CLdapSecUser::getFullName()
  67. {
  68. return m_fullname.get();
  69. }
  70. bool CLdapSecUser::setFullName(const char * name)
  71. {
  72. if(name != NULL)
  73. {
  74. m_fullname.set(name);
  75. }
  76. return true;
  77. }
  78. const char * CLdapSecUser::getFirstName()
  79. {
  80. return m_firstname.get();
  81. }
  82. bool CLdapSecUser::setFirstName(const char * fname)
  83. {
  84. if(fname != NULL)
  85. {
  86. m_firstname.set(fname);
  87. }
  88. return true;
  89. }
  90. const char * CLdapSecUser::getLastName()
  91. {
  92. return m_lastname.get();
  93. }
  94. bool CLdapSecUser::setLastName(const char * lname)
  95. {
  96. if(lname != NULL)
  97. {
  98. m_lastname.set(lname);
  99. }
  100. return true;
  101. }
  102. const char * CLdapSecUser::getRealm()
  103. {
  104. return m_realm.get();
  105. }
  106. bool CLdapSecUser::setRealm(const char * name)
  107. {
  108. m_realm.set(name);
  109. return TRUE;
  110. }
  111. const char * CLdapSecUser::getFqdn()
  112. {
  113. return m_Fqdn.get();
  114. }
  115. bool CLdapSecUser::setFqdn(const char * Fqdn)
  116. {
  117. m_Fqdn.set(Fqdn);
  118. return true;
  119. }
  120. const char *CLdapSecUser::getPeer()
  121. {
  122. return m_Peer.get();
  123. }
  124. bool CLdapSecUser::setPeer(const char *Peer)
  125. {
  126. m_Peer.set(Peer);
  127. return true;
  128. }
  129. ISecCredentials & CLdapSecUser::credentials()
  130. {
  131. return *this;
  132. }
  133. unsigned CLdapSecUser::getUserID()
  134. {
  135. return m_userid;
  136. }
  137. //interface ISecCredentials
  138. bool CLdapSecUser::setPassword(const char * pw)
  139. {
  140. m_pw.set(pw);
  141. return TRUE;
  142. }
  143. const char* CLdapSecUser::getPassword()
  144. {
  145. return m_pw;
  146. }
  147. bool CLdapSecUser::setEncodedPassword(SecPasswordEncoding enc, void * pw, unsigned length, void * salt, unsigned saltlen)
  148. {
  149. return FALSE; //not supported yet
  150. }
  151. bool CLdapSecUser::addToken(unsigned type, void * data, unsigned length)
  152. {
  153. return FALSE; //not supported yet
  154. }
  155. void CLdapSecUser::copyTo(ISecUser& destination)
  156. {
  157. CLdapSecUser* dest = dynamic_cast<CLdapSecUser*>(&destination);
  158. if(!dest)
  159. return;
  160. dest->setAuthenticateStatus(getAuthenticateStatus());
  161. dest->setName(getName());
  162. dest->setFullName(getFullName());
  163. dest->setFirstName(getFirstName());
  164. dest->setLastName(getLastName());
  165. dest->setRealm(getRealm());
  166. dest->credentials().setPassword(credentials().getPassword());
  167. dest->setUserSid(m_usersid.length(), m_usersid.toByteArray());
  168. dest->setUserID(m_userid);
  169. dest->setPasswordExpiration(m_passwordExpiration);
  170. }
  171. ISecUser * CLdapSecUser::clone()
  172. {
  173. CLdapSecUser* newuser = new CLdapSecUser(m_name.get(), m_pw.get());
  174. if(newuser)
  175. copyTo(*newuser);
  176. return newuser;
  177. }
  178. /**********************************************************
  179. * CLdapSecResource *
  180. **********************************************************/
  181. CLdapSecResource::CLdapSecResource(const char *name) : m_name(name), m_access(0), m_required_access(0)
  182. {
  183. m_resourcetype = RT_DEFAULT;
  184. }
  185. void CLdapSecResource::addAccess(int flags)
  186. {
  187. m_access |= flags;
  188. }
  189. void CLdapSecResource::setAccessFlags(int flags)
  190. {
  191. m_access = flags;
  192. }
  193. void CLdapSecResource::setRequiredAccessFlags(int flags)
  194. {
  195. m_required_access = flags;
  196. }
  197. int CLdapSecResource::getRequiredAccessFlags()
  198. {
  199. return m_required_access;
  200. }
  201. //interface ISecResource : extends IInterface
  202. const char * CLdapSecResource::getName()
  203. {
  204. return m_name.get();
  205. }
  206. int CLdapSecResource::getAccessFlags()
  207. {
  208. return m_access;
  209. }
  210. int CLdapSecResource::addParameter(const char* name, const char* value)
  211. {
  212. if (!m_parameters)
  213. m_parameters.setown(createProperties(false));
  214. m_parameters->setProp(name, value);
  215. return 0;
  216. }
  217. const char * CLdapSecResource::getParameter(const char * name)
  218. {
  219. if (m_parameters)
  220. {
  221. const char *value = m_parameters->queryProp(name);
  222. return value;
  223. }
  224. return NULL;
  225. }
  226. void CLdapSecResource::setDescription(const char* description)
  227. {
  228. m_description.clear().append(description);
  229. }
  230. const char* CLdapSecResource::getDescription()
  231. {
  232. return m_description.str();
  233. }
  234. void CLdapSecResource::setValue(const char* value)
  235. {
  236. m_value.clear();
  237. m_value.append(value);
  238. }
  239. const char* CLdapSecResource::getValue()
  240. {
  241. return m_value.str();
  242. }
  243. ISecResource * CLdapSecResource::clone()
  244. {
  245. CLdapSecResource* _res = new CLdapSecResource(m_name.get());
  246. if(!_res)
  247. return NULL;
  248. _res->setResourceType(m_resourcetype);
  249. _res->setValue(m_value.str());
  250. _res->m_access = m_access;
  251. _res->m_required_access = m_required_access;
  252. _res->setDescription(m_description.str());
  253. if(!m_parameters)
  254. return _res;
  255. Owned<IPropertyIterator> Itr = m_parameters->getIterator();
  256. Itr->first();
  257. while(Itr->isValid())
  258. {
  259. _res->addParameter(Itr->getPropKey(),m_parameters->queryProp(Itr->getPropKey()));
  260. Itr->next();
  261. }
  262. return _res;
  263. }
  264. void CLdapSecResource::copy(ISecResource* from)
  265. {
  266. if(!from)
  267. return;
  268. CLdapSecResource* ldapfrom = dynamic_cast<CLdapSecResource*>(from);
  269. if(!ldapfrom)
  270. return;
  271. m_access = ldapfrom->m_access;
  272. setDescription(ldapfrom->m_description.str());
  273. if(m_parameters.get())
  274. {
  275. m_parameters.clear();
  276. }
  277. if(!ldapfrom->m_parameters.get())
  278. return;
  279. Owned<IPropertyIterator> Itr = ldapfrom->m_parameters->getIterator();
  280. Itr->first();
  281. while(Itr->isValid())
  282. {
  283. addParameter(Itr->getPropKey(), ldapfrom->m_parameters->queryProp(Itr->getPropKey()));
  284. Itr->next();
  285. }
  286. return;
  287. }
  288. SecResourceType CLdapSecResource::getResourceType()
  289. {
  290. return m_resourcetype;
  291. }
  292. void CLdapSecResource::setResourceType(SecResourceType resourcetype)
  293. {
  294. m_resourcetype = resourcetype;
  295. }
  296. /**********************************************************
  297. * CLdapSecResourceList *
  298. **********************************************************/
  299. CLdapSecResourceList::CLdapSecResourceList(const char *name) : m_complete(0)
  300. {
  301. m_name.set(name);
  302. }
  303. void CLdapSecResourceList::setAuthorizationComplete(bool value)
  304. {
  305. m_complete=value;
  306. }
  307. IArrayOf<ISecResource>& CLdapSecResourceList::getResourceList()
  308. {
  309. return m_rlist;
  310. }
  311. //interface ISecResourceList : extends IInterface
  312. bool CLdapSecResourceList::isAuthorizationComplete()
  313. {
  314. return m_complete;
  315. }
  316. ISecResourceList * CLdapSecResourceList::clone()
  317. {
  318. CLdapSecResourceList* _newList = new CLdapSecResourceList(m_name.get());
  319. if(!_newList)
  320. return NULL;
  321. copyTo(*_newList);
  322. return _newList;
  323. }
  324. bool CLdapSecResourceList::copyTo(ISecResourceList& destination)
  325. {
  326. ForEachItemIn(x, m_rlist)
  327. {
  328. CLdapSecResource* res = (CLdapSecResource*)(&(m_rlist.item(x)));
  329. if(res)
  330. destination.addResource(res->clone());
  331. }
  332. return false;
  333. }
  334. ISecResource* CLdapSecResourceList::addResource(const char * name)
  335. {
  336. if(!name || !*name)
  337. return NULL;
  338. ISecResource* resource = m_rmap[name];
  339. if(resource == NULL)
  340. {
  341. resource = new CLdapSecResource(name);
  342. m_rlist.append(*resource);
  343. m_rmap[name] = resource;
  344. }
  345. return resource;
  346. }
  347. void CLdapSecResourceList::addResource(ISecResource * resource)
  348. {
  349. if(resource == NULL)
  350. return;
  351. const char* name = resource->getName();
  352. if(!name || !*name)
  353. return;
  354. ISecResource* r = m_rmap[name];
  355. if(r == NULL)
  356. {
  357. m_rlist.append(*resource);
  358. m_rmap[name] = resource;
  359. }
  360. }
  361. bool CLdapSecResourceList::addCustomResource(const char * name, const char * config)
  362. {
  363. return false;
  364. }
  365. ISecResource * CLdapSecResourceList::getResource(const char * Resource)
  366. {
  367. if(!Resource || !*Resource)
  368. return NULL;
  369. ISecResource* r = m_rmap[Resource];
  370. if(r)
  371. return LINK(r);
  372. else
  373. return NULL;
  374. }
  375. void CLdapSecResourceList::clear()
  376. {
  377. m_rlist.kill();
  378. }
  379. int CLdapSecResourceList::count()
  380. {
  381. return m_rlist.length();
  382. }
  383. const char* CLdapSecResourceList::getName()
  384. {
  385. return m_name.get();
  386. }
  387. ISecResource * CLdapSecResourceList::queryResource(unsigned seq)
  388. {
  389. if(seq < m_rlist.length())
  390. return &(m_rlist.item(seq));
  391. else
  392. return NULL;
  393. }
  394. ISecPropertyIterator * CLdapSecResourceList::getPropertyItr()
  395. {
  396. return new ArrayIIteratorOf<IArrayOf<struct ISecResource>, ISecProperty, ISecPropertyIterator>(m_rlist);
  397. }
  398. ISecProperty* CLdapSecResourceList::findProperty(const char* name)
  399. {
  400. if(!name || !*name)
  401. return NULL;
  402. return m_rmap[name];
  403. }
  404. /**********************************************************
  405. * CLdapSecManager *
  406. **********************************************************/
  407. CLdapSecManager::CLdapSecManager(const char *serviceName, const char *config)
  408. {
  409. IPropertyTree* cfg = createPTreeFromXMLString(config, ipt_caseInsensitive);
  410. if(cfg == NULL)
  411. {
  412. throw MakeStringException(-1, "createPTreeFromXMLString() failed for %s", config);
  413. }
  414. init(serviceName, cfg);
  415. }
  416. void CLdapSecManager::init(const char *serviceName, IPropertyTree* cfg)
  417. {
  418. for(int i = 0; i < RT_SCOPE_MAX; i++)
  419. m_cache_off[i] = false;
  420. m_cache_off[RT_VIEW_SCOPE] = true;
  421. m_usercache_off = false;
  422. m_cfg.setown(cfg);
  423. cfg->getProp(".//@ldapAddress", m_server);
  424. cfg->getProp(".//@description", m_description);
  425. ILdapClient* ldap_client = createLdapClient(cfg);
  426. IPermissionProcessor* pp;
  427. if(ldap_client->getServerType() == ACTIVE_DIRECTORY)
  428. pp = new PermissionProcessor(cfg);
  429. else if(ldap_client->getServerType() == IPLANET)
  430. pp = new CIPlanetAciProcessor(cfg);
  431. else if(ldap_client->getServerType() == OPEN_LDAP)
  432. {
  433. if (0 == stricmp(ldap_client->getLdapConfig()->getCfgServerType(), "389DirectoryServer"))//uses iPlanet style ACI
  434. pp = new CIPlanetAciProcessor(cfg);
  435. else
  436. pp = new COpenLdapAciProcessor(cfg);
  437. }
  438. else
  439. throwUnexpected();
  440. pp->setLdapClient(ldap_client);
  441. ldap_client->init(pp);
  442. m_ldap_client.setown(ldap_client);
  443. m_pp.setown(pp);
  444. int cachetimeout = cfg->getPropInt("@cacheTimeout", 5);
  445. if (cfg->getPropBool("@sharedCache", true))
  446. m_permissionsCache.setown(CPermissionsCache::getInstance(cfg->queryProp("@name")));
  447. else
  448. m_permissionsCache.setown(new CPermissionsCache());
  449. m_permissionsCache->setCacheTimeout( 60 * cachetimeout);
  450. m_permissionsCache->setTransactionalEnabled(true);
  451. m_permissionsCache->setSecManager(this);
  452. m_passwordExpirationWarningDays = cfg->getPropInt(".//@passwordExpirationWarningDays", 10); //Default to 10 days
  453. };
  454. CLdapSecManager::CLdapSecManager(const char *serviceName, IPropertyTree &config)
  455. {
  456. init(serviceName, &config);
  457. }
  458. CLdapSecManager::~CLdapSecManager()
  459. {
  460. }
  461. //interface ISecManager : extends IInterface
  462. ISecUser * CLdapSecManager::createUser(const char * user_name)
  463. {
  464. return (new CLdapSecUser(user_name, NULL));
  465. }
  466. ISecResourceList * CLdapSecManager::createResourceList(const char * rlname)
  467. {
  468. return (new CLdapSecResourceList(rlname));
  469. }
  470. bool CLdapSecManager::subscribe(ISecAuthenticEvents & events)
  471. {
  472. m_subscriber.set(&events);
  473. return true;
  474. }
  475. bool CLdapSecManager::unsubscribe(ISecAuthenticEvents & events)
  476. {
  477. if (&events == m_subscriber.get())
  478. {
  479. m_subscriber.set(NULL);
  480. }
  481. return true;
  482. }
  483. bool CLdapSecManager::authenticate(ISecUser* user)
  484. {
  485. if(!user)
  486. return false;
  487. if(user->getAuthenticateStatus() == AS_AUTHENTICATED)
  488. return true;
  489. if(m_permissionsCache->isCacheEnabled() && !m_usercache_off && m_permissionsCache->lookup(*user))
  490. {
  491. user->setAuthenticateStatus(AS_AUTHENTICATED);
  492. return true;
  493. }
  494. bool ok = m_ldap_client->authenticate(*user);
  495. if(ok)
  496. {
  497. if(m_permissionsCache->isCacheEnabled() && !m_usercache_off)
  498. m_permissionsCache->add(*user);
  499. user->setAuthenticateStatus(AS_AUTHENTICATED);
  500. }
  501. return ok;
  502. }
  503. bool CLdapSecManager::authorizeEx(SecResourceType rtype, ISecUser& sec_user, ISecResourceList * Resources, IEspSecureContext* secureContext)
  504. {
  505. if(!authenticate(&sec_user))
  506. {
  507. return false;
  508. }
  509. CLdapSecResourceList * reslist = (CLdapSecResourceList*)Resources;
  510. if(!reslist)
  511. return true;
  512. IArrayOf<ISecResource>& rlist = reslist->getResourceList();
  513. int nResources = rlist.length();
  514. int ri;
  515. for(ri = 0; ri < nResources; ri++)
  516. {
  517. ISecResource* res = &rlist.item(ri);
  518. if(res != NULL)
  519. res->setResourceType(rtype);
  520. }
  521. if (nResources <= 0)
  522. return true;
  523. bool rc;
  524. time_t tctime = getThreadCreateTime();
  525. if ((m_permissionsCache->isCacheEnabled() || (m_permissionsCache->isTransactionalEnabled() && tctime > 0)) && (!m_cache_off[rtype]))
  526. {
  527. bool* cached_found = (bool*)alloca(nResources*sizeof(bool));
  528. int nFound = m_permissionsCache->lookup(sec_user, rlist, cached_found);
  529. if (nFound < nResources)
  530. {
  531. IArrayOf<ISecResource> rlist2;
  532. int i;
  533. for (i=0; i < nResources; i++)
  534. {
  535. if (*(cached_found+i) == false)
  536. {
  537. ISecResource& secRes = rlist.item(i);
  538. secRes.Link();
  539. rlist2.append(secRes);
  540. //DBGLOG("CACHE: Fetching permissions for %s:%s", sec_user.getName(), secRes.getName());
  541. }
  542. }
  543. rc = m_ldap_client->authorize(rtype, sec_user, rlist2);
  544. if (rc)
  545. m_permissionsCache->add(sec_user, rlist2);
  546. }
  547. else
  548. rc = true;
  549. }
  550. else
  551. {
  552. rc = m_ldap_client->authorize(rtype, sec_user, rlist, reslist->getName());
  553. }
  554. return rc;
  555. }
  556. int CLdapSecManager::authorizeEx(SecResourceType rtype, ISecUser & user, const char * resourcename, IEspSecureContext* secureContext)
  557. {
  558. if(!resourcename || !*resourcename)
  559. return SecAccess_Full;
  560. Owned<ISecResourceList> rlist;
  561. rlist.setown(createResourceList("resources"));
  562. rlist->addResource(resourcename);
  563. bool ok = authorizeEx(rtype, user, rlist.get(), secureContext);
  564. if(ok)
  565. return rlist->queryResource(0)->getAccessFlags();
  566. else
  567. return -1;
  568. }
  569. bool CLdapSecManager::authorizeEx(SecResourceType rtype, ISecUser& sec_user, ISecResourceList * Resources, bool doAuthentication)
  570. {
  571. if(doAuthentication && !authenticate(&sec_user))
  572. {
  573. return false;
  574. }
  575. CLdapSecResourceList * reslist = (CLdapSecResourceList*)Resources;
  576. if(!reslist)
  577. return true;
  578. IArrayOf<ISecResource>& rlist = reslist->getResourceList();
  579. int nResources = rlist.length();
  580. int ri;
  581. for(ri = 0; ri < nResources; ri++)
  582. {
  583. ISecResource* res = &rlist.item(ri);
  584. if(res != NULL)
  585. res->setResourceType(rtype);
  586. }
  587. if (nResources <= 0)
  588. return true;
  589. bool rc;
  590. time_t tctime = getThreadCreateTime();
  591. if ((m_permissionsCache->isCacheEnabled() || (m_permissionsCache->isTransactionalEnabled() && tctime > 0)) && (!m_cache_off[rtype]))
  592. {
  593. bool* cached_found = (bool*)alloca(nResources*sizeof(bool));
  594. int nFound = m_permissionsCache->lookup(sec_user, rlist, cached_found);
  595. if (nFound < nResources)
  596. {
  597. IArrayOf<ISecResource> rlist2;
  598. int i;
  599. for (i=0; i < nResources; i++)
  600. {
  601. if (*(cached_found+i) == false)
  602. {
  603. ISecResource& secRes = rlist.item(i);
  604. secRes.Link();
  605. rlist2.append(secRes);
  606. //DBGLOG("CACHE: Fetching permissions for %s:%s", sec_user.getName(), secRes.getName());
  607. }
  608. }
  609. rc = m_ldap_client->authorize(rtype, sec_user, rlist2);
  610. if (rc)
  611. m_permissionsCache->add(sec_user, rlist2);
  612. }
  613. else
  614. rc = true;
  615. }
  616. else
  617. {
  618. rc = m_ldap_client->authorize(rtype, sec_user, rlist);
  619. }
  620. return rc;
  621. }
  622. int CLdapSecManager::authorizeEx(SecResourceType rtype, ISecUser & user, const char * resourcename, bool doAuthentication)
  623. {
  624. if(!resourcename || !*resourcename)
  625. return SecAccess_Full;
  626. Owned<ISecResourceList> rlist;
  627. rlist.setown(createResourceList("resources"));
  628. rlist->addResource(resourcename);
  629. bool ok = authorizeEx(rtype, user, rlist.get(), doAuthentication);
  630. if(ok)
  631. return rlist->queryResource(0)->getAccessFlags();
  632. else
  633. return -1;
  634. }
  635. int CLdapSecManager::getAccessFlagsEx(SecResourceType rtype, ISecUser & user, const char * resourcename)
  636. {
  637. if(!resourcename || !*resourcename)
  638. return -1;
  639. Owned<ISecResourceList> rlist0;
  640. rlist0.setown(createResourceList("resources"));
  641. rlist0->addResource(resourcename);
  642. CLdapSecResourceList * reslist = (CLdapSecResourceList*)rlist0.get();
  643. if(!reslist)
  644. return -1;
  645. IArrayOf<ISecResource>& rlist = reslist->getResourceList();
  646. int nResources = rlist.length();
  647. int ri;
  648. for(ri = 0; ri < nResources; ri++)
  649. {
  650. ISecResource* res = &rlist.item(ri);
  651. if(res != NULL)
  652. res->setResourceType(rtype);
  653. }
  654. if (nResources <= 0)
  655. return -1;
  656. bool ok = false;
  657. time_t tctime = getThreadCreateTime();
  658. if ((m_permissionsCache->isCacheEnabled() || (m_permissionsCache->isTransactionalEnabled() && tctime > 0)) && (!m_cache_off[rtype]))
  659. {
  660. bool* cached_found = (bool*)alloca(nResources*sizeof(bool));
  661. int nFound = m_permissionsCache->lookup(user, rlist, cached_found);
  662. if (nFound < nResources)
  663. {
  664. IArrayOf<ISecResource> rlist2;
  665. int i;
  666. for (i=0; i < nResources; i++)
  667. {
  668. if (*(cached_found+i) == false)
  669. {
  670. ISecResource& secRes = rlist.item(i);
  671. secRes.Link();
  672. rlist2.append(secRes);
  673. //DBGLOG("CACHE: Fetching permissions for %s:%s", sec_user.getName(), secRes.getName());
  674. }
  675. }
  676. ok = m_ldap_client->authorize(rtype, user, rlist2);
  677. if (ok)
  678. m_permissionsCache->add(user, rlist2);
  679. }
  680. else
  681. ok = true;
  682. }
  683. else
  684. {
  685. ok = m_ldap_client->authorize(rtype, user, rlist);
  686. }
  687. //bool ok = authorizeEx(rtype, user, rlist.get());
  688. if(ok)
  689. return rlist0->queryResource(0)->getAccessFlags();
  690. else
  691. return -1;
  692. }
  693. bool CLdapSecManager::authorize(ISecUser& sec_user, ISecResourceList * Resources, IEspSecureContext* secureContext)
  694. {
  695. return authorizeEx(RT_DEFAULT, sec_user, Resources, secureContext);
  696. }
  697. int CLdapSecManager::authorizeFileScope(ISecUser & user, const char * filescope)
  698. {
  699. if(filescope == 0 || filescope[0] == '\0')
  700. return SecAccess_Full;
  701. StringBuffer managedFilescope;
  702. if(m_permissionsCache->isCacheEnabled() && !m_usercache_off)
  703. {
  704. int accessFlags;
  705. //See if file scope in question is managed by LDAP permissions.
  706. // If not, return default file permission (dont call out to LDAP)
  707. // If is, look in cache for permission of longest matching managed scope strings. If found return that permission (no call to LDAP),
  708. // otherwise a call to LDAP "authorizeFileScope" is necessary, specifying the longest matching managed scope string
  709. bool gotPerms = m_permissionsCache->queryPermsManagedFileScope(user, filescope, managedFilescope, &accessFlags);
  710. if (gotPerms)
  711. return accessFlags;
  712. }
  713. Owned<ISecResourceList> rlist;
  714. rlist.setown(createResourceList("FileScope"));
  715. rlist->addResource(managedFilescope.length() ? managedFilescope.str() : filescope );
  716. bool ok = authorizeFileScope(user, rlist.get());
  717. if(ok)
  718. return rlist->queryResource(0)->getAccessFlags();
  719. else
  720. return -1;
  721. }
  722. bool CLdapSecManager::authorizeFileScope(ISecUser & user, ISecResourceList * resources)
  723. {
  724. return authorizeEx(RT_FILE_SCOPE, user, resources);
  725. }
  726. bool CLdapSecManager::authorizeViewScope(ISecUser & user, ISecResourceList * resources)
  727. {
  728. return authorizeEx(RT_VIEW_SCOPE, user, resources);
  729. }
  730. int CLdapSecManager::authorizeWorkunitScope(ISecUser & user, const char * wuscope)
  731. {
  732. if(wuscope == 0 || wuscope[0] == '\0')
  733. return SecAccess_Full;
  734. Owned<ISecResourceList> rlist;
  735. rlist.setown(createResourceList("WorkunitScope"));
  736. rlist->addResource(wuscope);
  737. bool ok = authorizeWorkunitScope(user, rlist.get());
  738. if(ok)
  739. return rlist->queryResource(0)->getAccessFlags();
  740. else
  741. return -1;
  742. }
  743. bool CLdapSecManager::authorizeWorkunitScope(ISecUser & user, ISecResourceList * resources)
  744. {
  745. return authorizeEx(RT_WORKUNIT_SCOPE, user, resources);
  746. }
  747. bool CLdapSecManager::addResourcesEx(SecResourceType rtype, ISecUser& sec_user, ISecResourceList * resources, SecPermissionType ptype, const char* basedn)
  748. {
  749. CLdapSecResourceList * reslist = (CLdapSecResourceList*)resources;
  750. if(!reslist)
  751. return true;
  752. IArrayOf<ISecResource>& rlist = reslist->getResourceList();
  753. if(rlist.length() <= 0)
  754. return true;
  755. return m_ldap_client->addResources(rtype, sec_user, rlist, ptype, basedn);
  756. }
  757. bool CLdapSecManager::addResourceEx(SecResourceType rtype, ISecUser& user, const char* resourcename, SecPermissionType ptype, const char* basedn)
  758. {
  759. Owned<ISecResourceList> rlist;
  760. rlist.setown(createResourceList("resources"));
  761. rlist->addResource(resourcename);
  762. return addResourcesEx(rtype, user, rlist.get(), ptype, basedn);
  763. }
  764. bool CLdapSecManager::addResources(ISecUser& sec_user, ISecResourceList * resources)
  765. {
  766. return addResourcesEx(RT_DEFAULT, sec_user, resources);
  767. }
  768. bool CLdapSecManager::addUser(ISecUser & user)
  769. {
  770. bool ok = m_ldap_client->addUser(user);
  771. if(!ok)
  772. return false;
  773. return m_pp->retrieveUserInfo(user);
  774. }
  775. ISecUser * CLdapSecManager::lookupUser(unsigned uid)
  776. {
  777. return m_ldap_client->lookupUser(uid);
  778. }
  779. ISecUser * CLdapSecManager::findUser(const char * username)
  780. {
  781. if(username == NULL || strlen(username) == 0)
  782. {
  783. DBGLOG("findUser - username is empty");
  784. return NULL;
  785. }
  786. Owned<ISecUser> user;
  787. user.setown(createUser(username));
  788. try
  789. {
  790. bool ok = m_pp->retrieveUserInfo(*user);
  791. if(ok)
  792. {
  793. return LINK(user.get());
  794. }
  795. else
  796. {
  797. return NULL;
  798. }
  799. }
  800. catch(IException*)
  801. {
  802. return NULL;
  803. }
  804. catch(...)
  805. {
  806. return NULL;
  807. }
  808. }
  809. ISecUserIterator * CLdapSecManager::getAllUsers()
  810. {
  811. synchronized block(m_monitor);
  812. m_user_array.popAll(true);
  813. m_ldap_client->retrieveUsers(m_user_array);
  814. return new ArrayIIteratorOf<IUserArray, ISecUser, ISecUserIterator>(m_user_array);
  815. }
  816. void CLdapSecManager::searchUsers(const char* searchstr, IUserArray& users)
  817. {
  818. m_ldap_client->retrieveUsers(searchstr, users);
  819. }
  820. ISecItemIterator* CLdapSecManager::getUsersSorted(const char* userName, UserField* sortOrder, const unsigned pageStartFrom,
  821. const unsigned pageSize, unsigned* total, __int64* cacheHint)
  822. {
  823. return m_ldap_client->getUsersSorted(userName, sortOrder, pageStartFrom, pageSize, total, cacheHint);
  824. }
  825. void CLdapSecManager::getAllUsers(IUserArray& users)
  826. {
  827. m_ldap_client->retrieveUsers(users);
  828. }
  829. bool CLdapSecManager::getResources(SecResourceType rtype, const char * basedn, IArrayOf<ISecResource> & resources)
  830. {
  831. return m_ldap_client->getResources(rtype, basedn, "", resources);
  832. }
  833. bool CLdapSecManager::getResourcesEx(SecResourceType rtype, const char * basedn, const char* searchstr, IArrayOf<ISecResource> & resources)
  834. {
  835. return m_ldap_client->getResourcesEx(rtype, basedn, "", searchstr, resources);
  836. }
  837. ISecItemIterator* CLdapSecManager::getResourcesSorted(SecResourceType rtype, const char * basedn, const char * resourceName, unsigned extraNameFilter,
  838. ResourceField* sortOrder, const unsigned pageStartFrom, const unsigned pageSize, unsigned *total, __int64 *cachehint)
  839. {
  840. return m_ldap_client->getResourcesSorted(rtype, basedn, resourceName, extraNameFilter, sortOrder, pageStartFrom, pageSize, total, cachehint);
  841. }
  842. void CLdapSecManager::setExtraParam(const char * name, const char * value)
  843. {
  844. if(name == NULL || name[0] == '\0')
  845. return;
  846. if (!m_extraparams)
  847. m_extraparams.setown(createProperties(false));
  848. m_extraparams->setProp(name, value);
  849. if(value != NULL && value[0] != '\0')
  850. {
  851. if(stricmp(name, "resourcesBasedn") == 0)
  852. m_ldap_client->setResourceBasedn(value, RT_DEFAULT);
  853. else if(stricmp(name, "workunitsBasedn") == 0)
  854. m_ldap_client->setResourceBasedn(value, RT_WORKUNIT_SCOPE);
  855. }
  856. }
  857. IAuthMap * CLdapSecManager::createAuthMap(IPropertyTree * authconfig)
  858. {
  859. CAuthMap* authmap = new CAuthMap(this);
  860. IPropertyTreeIterator *loc_iter = NULL;
  861. loc_iter = authconfig->getElements(".//Location");
  862. if (loc_iter != NULL)
  863. {
  864. IPropertyTree *location = NULL;
  865. loc_iter->first();
  866. while(loc_iter->isValid())
  867. {
  868. location = &loc_iter->query();
  869. if (location)
  870. {
  871. StringBuffer pathstr, rstr, required, description;
  872. location->getProp("@path", pathstr);
  873. location->getProp("@resource", rstr);
  874. location->getProp("@required", required);
  875. location->getProp("@description", description);
  876. if(pathstr.length() == 0)
  877. throw MakeStringException(-1, "path empty in Authenticate/Location");
  878. if(rstr.length() == 0)
  879. throw MakeStringException(-1, "resource empty in Authenticate/Location");
  880. ISecResourceList* rlist = authmap->queryResourceList(pathstr.str());
  881. if(rlist == NULL)
  882. {
  883. rlist = createResourceList("ldapsecurity");
  884. authmap->add(pathstr.str(), rlist);
  885. }
  886. ISecResource* rs = rlist->addResource(rstr.str());
  887. unsigned requiredaccess = str2perm(required.str());
  888. rs->setRequiredAccessFlags(requiredaccess);
  889. rs->setDescription(description.str());
  890. }
  891. loc_iter->next();
  892. }
  893. loc_iter->Release();
  894. loc_iter = NULL;
  895. }
  896. authmap->addToBackend();
  897. return authmap;
  898. }
  899. IAuthMap * CLdapSecManager::createFeatureMap(IPropertyTree * authconfig)
  900. {
  901. CAuthMap* feature_authmap = new CAuthMap(this);
  902. IPropertyTreeIterator *feature_iter = NULL;
  903. feature_iter = authconfig->getElements(".//Feature");
  904. if (feature_iter != NULL)
  905. {
  906. IPropertyTree *feature = NULL;
  907. feature_iter->first();
  908. while(feature_iter->isValid())
  909. {
  910. feature = &feature_iter->query();
  911. if (feature)
  912. {
  913. StringBuffer pathstr, rstr, required, description;
  914. feature->getProp("@path", pathstr);
  915. feature->getProp("@resource", rstr);
  916. feature->getProp("@required", required);
  917. feature->getProp("@description", description);
  918. ISecResourceList* rlist = feature_authmap->queryResourceList(pathstr.str());
  919. if(rlist == NULL)
  920. {
  921. rlist = createResourceList(pathstr.str());
  922. feature_authmap->add(pathstr.str(), rlist);
  923. }
  924. ISecResource* rs = rlist->addResource(rstr.str());
  925. unsigned requiredaccess = str2perm(required.str());
  926. rs->setRequiredAccessFlags(requiredaccess);
  927. rs->setDescription(description.str());
  928. }
  929. feature_iter->next();
  930. }
  931. feature_iter->Release();
  932. feature_iter = NULL;
  933. }
  934. feature_authmap->addToBackend();
  935. return feature_authmap;
  936. }
  937. bool CLdapSecManager::updateUserPassword(ISecUser& user, const char* newPassword, const char* currPassword)
  938. {
  939. // Authenticate User first
  940. if(!authenticate(&user) && user.getAuthenticateStatus() != AS_PASSWORD_VALID_BUT_EXPIRED)
  941. {
  942. return false;
  943. }
  944. //Update password if authenticated
  945. bool ok = m_ldap_client->updateUserPassword(user, newPassword, currPassword);
  946. if(ok && m_permissionsCache->isCacheEnabled() && !m_usercache_off)
  947. {
  948. m_permissionsCache->removeFromUserCache(user);
  949. }
  950. return ok;
  951. }
  952. bool CLdapSecManager::updateUser(const char* type, ISecUser& user)
  953. {
  954. bool ok = m_ldap_client->updateUser(type, user);
  955. if(ok && m_permissionsCache->isCacheEnabled() && !m_usercache_off)
  956. m_permissionsCache->removeFromUserCache(user);
  957. return ok;
  958. }
  959. bool CLdapSecManager::updateUserPassword(const char* username, const char* newPassword)
  960. {
  961. return m_ldap_client->updateUserPassword(username, newPassword);
  962. }
  963. void CLdapSecManager::getAllGroups(StringArray & groups, StringArray & managedBy, StringArray & descriptions)
  964. {
  965. m_ldap_client->getAllGroups(groups, managedBy, descriptions);
  966. }
  967. ISecItemIterator* CLdapSecManager::getGroupsSorted(GroupField* sortOrder, const unsigned pageStartFrom, const unsigned pageSize,
  968. unsigned *total, __int64 *cachehint)
  969. {
  970. return m_ldap_client->getGroupsSorted(sortOrder, pageStartFrom, pageSize, total, cachehint);
  971. }
  972. ISecItemIterator* CLdapSecManager::getGroupMembersSorted(const char* groupName, UserField* sortOrder, const unsigned pageStartFrom, const unsigned pageSize,
  973. unsigned *total, __int64 *cachehint)
  974. {
  975. return m_ldap_client->getGroupMembersSorted(groupName, sortOrder, pageStartFrom, pageSize, total, cachehint);
  976. }
  977. bool CLdapSecManager::getPermissionsArray(const char* basedn, SecResourceType rtype, const char* name, IArrayOf<CPermission>& permissions)
  978. {
  979. return m_ldap_client->getPermissionsArray(basedn, rtype, name, permissions);
  980. }
  981. void CLdapSecManager::addGroup(const char* groupname, const char * groupOwner, const char * groupDesc)
  982. {
  983. m_ldap_client->addGroup(groupname, groupOwner, groupDesc);
  984. }
  985. void CLdapSecManager::deleteGroup(const char* groupname)
  986. {
  987. m_ldap_client->deleteGroup(groupname);
  988. }
  989. bool CLdapSecManager::changePermission(CPermissionAction& action)
  990. {
  991. return m_ldap_client->changePermission(action);
  992. }
  993. void CLdapSecManager::getGroups(const char* username, StringArray & groups)
  994. {
  995. m_ldap_client->getGroups(username, groups);
  996. }
  997. void CLdapSecManager::changeUserGroup(const char* action, const char* username, const char* groupname)
  998. {
  999. m_ldap_client->changeUserGroup(action, username, groupname);
  1000. }
  1001. bool CLdapSecManager::deleteUser(ISecUser* user)
  1002. {
  1003. return m_ldap_client->deleteUser(user);
  1004. }
  1005. void CLdapSecManager::getGroupMembers(const char* groupname, StringArray & users)
  1006. {
  1007. m_ldap_client->getGroupMembers(groupname, users);
  1008. }
  1009. void CLdapSecManager::deleteResource(SecResourceType rtype, const char * name, const char * basedn)
  1010. {
  1011. m_ldap_client->deleteResource(rtype, name, basedn);
  1012. time_t tctime = getThreadCreateTime();
  1013. if ((m_permissionsCache->isCacheEnabled() || (m_permissionsCache->isTransactionalEnabled() && tctime > 0)) && (!m_cache_off[rtype]))
  1014. m_permissionsCache->remove(rtype, name);
  1015. }
  1016. void CLdapSecManager::renameResource(SecResourceType rtype, const char * oldname, const char * newname, const char * basedn)
  1017. {
  1018. m_ldap_client->renameResource(rtype, oldname, newname, basedn);
  1019. time_t tctime = getThreadCreateTime();
  1020. if ((m_permissionsCache->isCacheEnabled() || (m_permissionsCache->isTransactionalEnabled() && tctime > 0)) && (!m_cache_off[rtype]))
  1021. m_permissionsCache->remove(rtype, oldname);
  1022. }
  1023. void CLdapSecManager::copyResource(SecResourceType rtype, const char * oldname, const char * newname, const char * basedn)
  1024. {
  1025. m_ldap_client->copyResource(rtype, oldname, newname, basedn);
  1026. }
  1027. void CLdapSecManager::normalizeDn(const char* dn, StringBuffer& ndn)
  1028. {
  1029. m_ldap_client->normalizeDn(dn, ndn);
  1030. }
  1031. bool CLdapSecManager::isSuperUser(ISecUser* user)
  1032. {
  1033. return m_ldap_client->isSuperUser(user);
  1034. }
  1035. ILdapConfig* CLdapSecManager::queryConfig()
  1036. {
  1037. return m_ldap_client->queryConfig();
  1038. }
  1039. void CLdapSecManager::cacheSwitch(SecResourceType rtype, bool on)
  1040. {
  1041. m_cache_off[rtype] = !on;
  1042. // To make things simple, turning off any resource type's permission cache turns off the userCache.
  1043. if(!on)
  1044. m_usercache_off = true;
  1045. }
  1046. int CLdapSecManager::countUsers(const char* searchstr, int limit)
  1047. {
  1048. return m_ldap_client->countUsers(searchstr, limit);
  1049. }
  1050. int CLdapSecManager::countResources(const char* basedn, const char* searchstr, int limit)
  1051. {
  1052. return m_ldap_client->countResources(basedn, searchstr, limit);
  1053. }
  1054. bool CLdapSecManager::getUserInfo(ISecUser& user, const char* infotype)
  1055. {
  1056. return m_ldap_client->getUserInfo(user, infotype);
  1057. }
  1058. bool CLdapSecManager::createUserScopes()
  1059. {
  1060. Owned<ISecUserIterator> it = getAllUsers();
  1061. it->first();
  1062. bool rc = true;
  1063. while(it->isValid())
  1064. {
  1065. ISecUser &user = it->get();
  1066. if (!m_ldap_client->createUserScope(user))
  1067. {
  1068. PROGLOG("Error creating scope for user '%s'", user.getName());
  1069. rc = false;
  1070. }
  1071. it->next();
  1072. }
  1073. return rc;
  1074. }
  1075. aindex_t CLdapSecManager::getManagedFileScopes(IArrayOf<ISecResource>& scopes)
  1076. {
  1077. return m_ldap_client->getManagedFileScopes(scopes);
  1078. }
  1079. int CLdapSecManager::queryDefaultPermission(ISecUser& user)
  1080. {
  1081. return m_ldap_client->queryDefaultPermission(user);
  1082. }
  1083. bool CLdapSecManager::clearPermissionsCache(ISecUser& user)
  1084. {
  1085. if(m_permissionsCache->isCacheEnabled())
  1086. {
  1087. if (!authenticate(&user))
  1088. {
  1089. PROGLOG("User %s not authorized to clear permissions cache", user.getName());
  1090. return false;
  1091. }
  1092. if (!isSuperUser(&user))
  1093. {
  1094. PROGLOG("User %s denied, only a superuser can clear permissions cache", user.getName());
  1095. return false;
  1096. }
  1097. m_permissionsCache->flush();
  1098. }
  1099. return true;
  1100. }
  1101. bool CLdapSecManager::authenticateUser(ISecUser & user, bool *superUser)
  1102. {
  1103. if (!authenticate(&user))
  1104. return false;
  1105. if (superUser)
  1106. *superUser = isSuperUser(&user);
  1107. return true;
  1108. }
  1109. //Data View related interfaces
  1110. void CLdapSecManager::createView(const char* viewName, const char * viewDescription)
  1111. {
  1112. m_ldap_client->createView(viewName, viewDescription);
  1113. }
  1114. void CLdapSecManager::deleteView(const char* viewName)
  1115. {
  1116. m_ldap_client->deleteView(viewName);
  1117. }
  1118. void CLdapSecManager::queryAllViews(StringArray & viewNames, StringArray & viewDescriptions, StringArray & viewManagedBy)
  1119. {
  1120. m_ldap_client->queryAllViews(viewNames, viewDescriptions, viewManagedBy);
  1121. }
  1122. void CLdapSecManager::addViewColumns(const char* viewName, StringArray & files, StringArray & columns)
  1123. {
  1124. m_ldap_client->addViewColumns(viewName, files, columns);
  1125. }
  1126. void CLdapSecManager::removeViewColumns(const char* viewName, StringArray & files, StringArray & columns)
  1127. {
  1128. m_ldap_client->removeViewColumns(viewName, files, columns);
  1129. }
  1130. void CLdapSecManager::queryViewColumns(const char* viewName, StringArray & files, StringArray & columns)
  1131. {
  1132. m_ldap_client->queryViewColumns(viewName, files, columns);
  1133. }
  1134. void CLdapSecManager::addViewMembers(const char* viewName, StringArray & viewUsers, StringArray & viewGroups)
  1135. {
  1136. m_ldap_client->addViewMembers(viewName, viewUsers, viewGroups);
  1137. }
  1138. void CLdapSecManager::removeViewMembers(const char* viewName, StringArray & viewUsers, StringArray & viewGroups)
  1139. {
  1140. m_ldap_client->removeViewMembers(viewName, viewUsers, viewGroups);
  1141. }
  1142. void CLdapSecManager::queryViewMembers(const char* viewName, StringArray & viewUsers, StringArray & viewGroups)
  1143. {
  1144. m_ldap_client->queryViewMembers(viewName, viewUsers, viewGroups);
  1145. }
  1146. bool CLdapSecManager::userInView(const char * user, const char* viewName)
  1147. {
  1148. return m_ldap_client->userInView(user, viewName);
  1149. }
  1150. extern "C"
  1151. {
  1152. LDAPSECURITY_API ISecManager * newLdapSecManager(const char *serviceName, IPropertyTree &config)
  1153. {
  1154. return new CLdapSecManager(serviceName, config);
  1155. }
  1156. LDAPSECURITY_API IAuthMap *newDefaultAuthMap(IPropertyTree* config)
  1157. {
  1158. CAuthMap* authmap = new CAuthMap(NULL);
  1159. IPropertyTreeIterator *loc_iter = NULL;
  1160. loc_iter = config->getElements(".//Location");
  1161. if (loc_iter != NULL)
  1162. {
  1163. IPropertyTree *location = NULL;
  1164. loc_iter->first();
  1165. while(loc_iter->isValid())
  1166. {
  1167. location = &loc_iter->query();
  1168. if (location)
  1169. {
  1170. StringBuffer pathstr, rstr;
  1171. location->getProp("@path", pathstr);
  1172. authmap->add(pathstr.str(), NULL);
  1173. }
  1174. loc_iter->next();
  1175. }
  1176. loc_iter->Release();
  1177. loc_iter = NULL;
  1178. }
  1179. return authmap;
  1180. }
  1181. }