LDAPUserPlugin.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. // -*- Mode: c++ -*-
  18. #ifndef LDAPUSERPLUGIN_H
  19. #define LDAPUSERPLUGIN_H
  20. #include <mutex>
  21. #include <string>
  22. #include <kopano/zcdefs.h>
  23. #include <kopano/ECIConv.h>
  24. #include <set>
  25. #include <ldap.h>
  26. #define LDAP_TIMEVAL struct timeval
  27. #include "plugin.h"
  28. #include "LDAPCache.h"
  29. /**
  30. * @defgroup userplugin_ldap LDAP userplugin
  31. * @ingroup userplugin
  32. * @{
  33. */
  34. namespace KC {
  35. /**
  36. * LDAP user plugin
  37. *
  38. * User management based on LDAP.
  39. *
  40. * @todo update documentation with the right exception, some function can throw more exceptions!
  41. */
  42. class LDAPUserPlugin: public UserPlugin {
  43. public:
  44. /**
  45. * Create a connection to the LDAP server and do some
  46. * initialization.
  47. *
  48. * Configuration parameters: \c ldap_url
  49. *
  50. * Possible configuration parameters: \c ldap_use_tls, \c
  51. * ldap_bind_user, \c ldap_bind_passwd
  52. *
  53. * @param[in] pluginlock
  54. * The plugin mutex
  55. * @param[in] shareddata
  56. * The singleton shared plugin data.
  57. * @throw std::runtime_error on failure, such as being unable to
  58. * connect to the LDAP server, or when the bind credentials are
  59. * incorrect.
  60. *
  61. * @todo The constructor sets the maximum size of query results to
  62. * infinite, instead it'd be better to use ldap_search instead of
  63. * ldap_search_s.
  64. */
  65. LDAPUserPlugin(std::mutex &, ECPluginSharedData *shareddata);
  66. virtual ~LDAPUserPlugin();
  67. /**
  68. * Initialize plugin
  69. *
  70. * @throw std::exception
  71. */
  72. virtual void InitPlugin();
  73. /**
  74. * Resolve name and company to objectsignature
  75. *
  76. * @param[in] objclass
  77. * The objectclass of the name which should be resolved.
  78. * The objectclass can be partially unknown (OBJECTCLASS_UNKNOWN, MAILUSER_UNKNOWN, ...)
  79. * @param[in] name
  80. * The name which should be resolved. name should be in charset windows-1252
  81. * @param[in] company
  82. * The company beneath which the name should be searched
  83. * This objectid can be empty.
  84. * @return The object signature of the resolved object
  85. * @throw runtime_error When an unsupported objclass was requested
  86. * @throw objectnotfound When no object was found with the requested name or objectclass
  87. * @throw collison_error When more then one object was found with the requested name
  88. */
  89. virtual objectsignature_t resolveName(objectclass_t objclass, const string &name, const objectid_t &company);
  90. /**
  91. * Authenticate user with username and password
  92. *
  93. * Depending on the authentication type this will call
  94. * LDAPUserPlugin::authenticateUserPassword() or LDAPUserPlugin::authenticateUserBind()
  95. *
  96. * @param[in] username
  97. * The username of the user to be authenticated. username should be in charset windows-1252
  98. * @param[in] password
  99. * The password of the user to be authenticated. password should be in charset windows-1252
  100. * @param[in] company
  101. * The objectid of the company to which the user belongs.
  102. * This objectid can be empty.
  103. * @return The objectsignature of the authenticated user
  104. */
  105. virtual objectsignature_t authenticateUser(const string &username, const string &password, const objectid_t &company);
  106. /**
  107. * Request a list of objects for a particular company and specified objectclass.
  108. *
  109. * @param[in] company
  110. * The company beneath which the objects should be listed.
  111. * This objectid can be empty.
  112. * @param[in] objclass
  113. * The objectclass of the objects which should be returned.
  114. * The objectclass can be partially unknown (OBJECTCLASS_UNKNOWN, MAILUSER_UNKNOWN, ...)
  115. * @return The list of object signatures of all objects which were found
  116. */
  117. virtual std::unique_ptr<signatures_t> getAllObjects(const objectid_t &company, objectclass_t objclass);
  118. /**
  119. * Obtain the object details for the given object
  120. *
  121. * This will call LDAPUserPlugin::getObjectDetails(const list<objectid_t> &objectids)
  122. *
  123. * @param[in] objectid
  124. * The objectid for which is details are requested
  125. * @return The objectdetails for the given objectid
  126. * @throw objectnotfound When the object was not found
  127. */
  128. virtual std::unique_ptr<objectdetails_t> getObjectDetails(const objectid_t &objectid);
  129. /**
  130. * Obtain the object details for the given objects
  131. *
  132. * @param[in] objectids
  133. * The list of object signatures for which the details are requested
  134. * @return A map of objectid with the matching objectdetails
  135. * @throw runtime_error When the LDAP query failed
  136. *
  137. * @remarks The methode returns a whole set of objectdetails but user may be missing if the user
  138. * details cannot be retrieved for some reason.
  139. */
  140. virtual std::unique_ptr<std::map<objectid_t, objectdetails_t> > getObjectDetails(const std::list<objectid_t> &objectids);
  141. /**
  142. * Get all children for a parent for a given relation type.
  143. * For example all users in a group
  144. *
  145. * @param[in] relation
  146. * The relation type which connects the child and parent object
  147. * @param[in] parentobject
  148. * The parent object for which the children are requested
  149. * @return A list of object signatures of the children of the parent.
  150. * @throw When an unsupported object relation was requested
  151. */
  152. virtual std::unique_ptr<signatures_t> getSubObjectsForObject(userobject_relation_t relation, const objectid_t &parentobject);
  153. /**
  154. * Request all parents for a childobject for a given relation type.
  155. * For example all groups for a user
  156. *
  157. * @param[in] relation
  158. * The relation type which connects the child and parent object
  159. * @param[in] childobject
  160. * The childobject for which the parents are requested
  161. * @return A list of object signatures of the parents of the child.
  162. * @throw runtime_error When an unsupported object relation was requested
  163. */
  164. virtual std::unique_ptr<signatures_t> getParentObjectsForObject(userobject_relation_t relation, const objectid_t &childobject);
  165. /**
  166. * Search for all objects which match the given string,
  167. * the name and email address should be compared for this search.
  168. *
  169. * @param[in] match
  170. * The string which should be found
  171. * @param[in] ulFlags
  172. * If EMS_AB_ADDRESS_LOOKUP the string must exactly match the name or email address
  173. * otherwise a partial match is allowed.
  174. * @return List of object signatures which match the given string
  175. * @throw objectnotfound When no objects were found
  176. */
  177. virtual std::unique_ptr<signatures_t> searchObject(const std::string &match, unsigned int ulFlags);
  178. /**
  179. * Obtain details for the public store
  180. *
  181. * @return The public store details
  182. * @throw runtime_error When LDAP query failed or mandatory attributes are missing
  183. * @throw objectnotfound When no public store was found
  184. * @throw toomanyobjects When more then one public store has been found
  185. */
  186. virtual std::unique_ptr<objectdetails_t> getPublicStoreDetails(void);
  187. /**
  188. * Obtain the objectdetails for a server
  189. *
  190. * @param[in] server
  191. * The externid of the server
  192. * @return The server details
  193. * @throw runtime_error When LDAP query failed or mandatory attributes are missing
  194. * @throw objectnotfound When no server has been found with the given name
  195. * @throw toomanyobjects When more then one server have been found with the given name
  196. */
  197. virtual std::unique_ptr<serverdetails_t> getServerDetails(const std::string &server);
  198. /**
  199. * Obtain server list
  200. *
  201. * @return list of servers
  202. * @throw runtime_error LDAP query failure
  203. */
  204. virtual std::unique_ptr<serverlist_t> getServers(void);
  205. /**
  206. * Update an object with new details
  207. *
  208. * @note This function is not supported and will always throw an exception
  209. *
  210. * @param[in] id
  211. * The object id of the object which should be updated.
  212. * @param[in] details
  213. * The objectdetails which should be written to the object.
  214. * @param[in] lpRemove
  215. * List of configuration names which should be removed from the object
  216. * @throw notimplemented Always when the function is called.
  217. */
  218. virtual void changeObject(const objectid_t &id, const objectdetails_t &details, const std::list<std::string> *lpRemove);
  219. /**
  220. * Create object in plugin
  221. *
  222. * @note This function is not supported and will always throw an exception
  223. *
  224. * @param[in] details
  225. * The object details of the new object.
  226. * @return The objectsignature of the created object.
  227. * @throw notimplemented Always when the function is called.
  228. */
  229. virtual objectsignature_t createObject(const objectdetails_t &details);
  230. /**
  231. * Delete object from plugin
  232. *
  233. * @note This function is not supported and will always throw an exception
  234. *
  235. * @param[in] id
  236. * The objectid which should be deleted
  237. * @throw notimplemented Always when the function is called.
  238. */
  239. virtual void deleteObject(const objectid_t &id);
  240. /**
  241. * Modify id of object in plugin
  242. *
  243. * @note This function is not supported by this plugin and will always throw an exception
  244. *
  245. * @param[in] oldId
  246. * The old objectid
  247. * @param[in] newId
  248. * The new objectid
  249. * @throw notsupported Always when this function is called
  250. */
  251. virtual void modifyObjectId(const objectid_t &oldId, const objectid_t &newId);
  252. /**
  253. * Add relation between child and parent. This can be used
  254. * for example to add a user to a group or add
  255. * permission relations on companies.
  256. *
  257. * @note This function is not supported and will always throw an exception
  258. *
  259. * @param[in] relation
  260. * The relation type which should connect the
  261. * child and parent.
  262. * @param[in] parentobject
  263. * The parent object.
  264. * @param[in] childobject
  265. * The child object.
  266. * @throw notimplemented Always when the function is called.
  267. */
  268. virtual void addSubObjectRelation(userobject_relation_t relation,
  269. const objectid_t &parentobject, const objectid_t &childobject);
  270. /**
  271. * Delete relation between child and parent, this can be used
  272. * for example to delete a user from a group or delete
  273. * permission relations on companies.
  274. *
  275. * @note This function is not supported and will always throw an exception
  276. *
  277. * @param[in] relation
  278. * The relation type which connected the child and parent.
  279. * @param[in] parentobject
  280. * The parent object.
  281. * @param[in] childobject
  282. * The child object.
  283. * @throw notimplemented Always when the function is called.
  284. */
  285. virtual void deleteSubObjectRelation(userobject_relation_t relation,
  286. const objectid_t& parentobject, const objectid_t &childobject);
  287. /**
  288. * Get quota information from object.
  289. * There are two quota types, normal quota and userdefault quota,
  290. * the first quota is the quote for the object itself while the userdefault
  291. * quota can only be requested on containers (i.e. groups or companies) and
  292. * is the quota for the members of that container.
  293. *
  294. * @param[in] id
  295. * The objectid from which the quota should be read
  296. * @param[in] bGetUserDefault
  297. * Boolean to indicate if the userdefault quota must be requested.
  298. * @throw runtime_error When the LDAP query failed
  299. */
  300. virtual std::unique_ptr<quotadetails_t> getQuota(const objectid_t &id, bool bGetUserDefault);
  301. /**
  302. * Set quota information on object
  303. *
  304. * @note This function is not supported and will always throw an exception
  305. *
  306. * @param[in] id
  307. * The objectid which should be updated
  308. * @param[in] quotadetails
  309. * The quota information which should be written to the object
  310. * @throw notimplemented Always when the function is called.
  311. */
  312. virtual void setQuota(const objectid_t &id, const quotadetails_t &quotadetails);
  313. /**
  314. * Get extra properties which are set in the object details for the addressbook
  315. *
  316. * @note It is not mandatory to implement this function
  317. *
  318. * @return a list of properties
  319. */
  320. virtual std::unique_ptr<abprops_t> getExtraAddressbookProperties(void);
  321. virtual void removeAllObjects(objectid_t except);
  322. protected:
  323. /**
  324. * Pointer to the LDAP state struct.
  325. */
  326. LDAP *m_ldap;
  327. /**
  328. * converter FROM ldap TO kopano-server
  329. */
  330. ECIConv *m_iconv;
  331. /**
  332. * converter FROM kopano-server TO ldap
  333. */
  334. ECIConv *m_iconvrev;
  335. static std::unique_ptr<LDAPCache> m_lpCache;
  336. LDAP_TIMEVAL m_timeout;
  337. private:
  338. /**
  339. * Get the value of the given attribute from the search results.
  340. *
  341. * This is a convenience function that uses
  342. * getLDAPAttributeValues. Parse the result of an LDAP search
  343. * query, and retrieve exactly one string. If the attribute does
  344. * not occur in the search results, or if there are no values for
  345. * the attribute, returns an empty string.
  346. *
  347. * @param[in] attribute
  348. * The name of the attribute.
  349. * @param[in] entry
  350. * The entry result from \c ldap_first_entry &c.
  351. * @returns The first value of the attribute, or an empty string
  352. * if the attribute or a value was not found.
  353. */
  354. std::string getLDAPAttributeValue(char *attribute, LDAPMessage *entry);
  355. /**
  356. * Get multiple values of the given attribute from the search results.
  357. *
  358. * Parse the result of an LDAP search query, and retrieve all the
  359. * values for the given attribute.
  360. *
  361. * @param[in] attribute
  362. * The name of the attribute.
  363. * @param[in] entry
  364. * The entry result from \c ldap_first_entry &c.
  365. * @return list of strings containing the attribute values
  366. */
  367. std::list<std::string> getLDAPAttributeValues(char *attribute, LDAPMessage *entry);
  368. /**
  369. * Get DN for given entry
  370. *
  371. * @param[in] entry
  372. * The entry result form the \c ldap_first_entry &c.
  373. * @return The DN for the entry
  374. */
  375. std::string GetLDAPEntryDN(LDAPMessage *entry);
  376. /**
  377. * Set one attribute of \c dn to \c value
  378. *
  379. * @param[in] dn
  380. * The DN to modify.
  381. * @param[in] attribute
  382. * The name of the attribute to modify.
  383. * @param[in] value
  384. * The new value of the attribute.
  385. * @return 0 When the modification was successful, 1 otherwise (error).
  386. */
  387. int changeAttribute(const char *dn, char *attribute, const char *value);
  388. /**
  389. * Set one attribute of \c dn to the values in \c values
  390. *
  391. * @param[in] dn
  392. * The DN to modify.
  393. * @param[in] attribute
  394. * The name of the attribute to modify.
  395. * @param[in] values
  396. * A list of new values. Any old values are overwritten or removed.
  397. * @retval 0 When the modification was successful, 1 Otherwise (error).
  398. */
  399. int changeAttribute(const char *dn, char *attribute, const std::list<std::string> &values);
  400. /**
  401. * Connect to the LDAP server
  402. *
  403. * @param[in] bind_dn
  404. * The DN for the administrator
  405. * @param[in] bind_pw
  406. * The password for the administrator
  407. * @return LDAP pointer
  408. * @throw ldap_error When no connection could be established
  409. */
  410. LDAP *ConnectLDAP(const char *bind_dn, const char *bind_pw);
  411. /**
  412. * Authenticate by user bind
  413. *
  414. * @param[in] username
  415. * The username in charset windows-1252
  416. * @param[in] password
  417. * The password for the username in charset windows-1252
  418. * @param[in] company
  419. * The company to which the user belongs (optional argument)
  420. * @return The object signature of the authenticated user
  421. * @throw runtime_error When the LDAP query fails.
  422. * @throw login_error When the username and password are incorrect.
  423. */
  424. objectsignature_t authenticateUserBind(const string &username, const string &password,
  425. const objectid_t &company = objectid_t(CONTAINER_COMPANY));
  426. /**
  427. * Authenticate by username and password
  428. *
  429. * @param[in] username
  430. * The username in charset windows-1252
  431. * @param[in] password
  432. * The password for the username in charset windows-1252
  433. * @param[in] company
  434. * The company to which the user belongs (optional argument)
  435. * @return The object signature of the authenticated user
  436. * @throw runtime_error When the LDAP query fails.
  437. * @throw objectnotfound When no user with the given name has been found.
  438. * @throw login_error When the username and password are incorrect.
  439. */
  440. objectsignature_t authenticateUserPassword(const string &username, const string &password,
  441. const objectid_t &company = objectid_t(CONTAINER_COMPANY));
  442. /**
  443. * Convert objectid to a DN
  444. *
  445. * @param[in] uniqueid
  446. * The unique id which should be converted
  447. * @return the DN for the object
  448. * @throw runtime_error When an error occurred during the LDAP query.
  449. * @throw objectnotfound When no object was found with the given objectid.
  450. * @throw toomanyobjects When more then one object was returned with the objectid.
  451. */
  452. string objectUniqueIDtoObjectDN(const objectid_t &uniqueid, bool cache = true);
  453. /**
  454. * Convert a DN to an object signature
  455. *
  456. * @param[in] objclass
  457. * The objectclass to which this search should be restricted.
  458. * The objectclass can be partially unknown (OBJECTCLASS_UNKNOWN, MAILUSER_UNKNOWN, ...)
  459. * @param[in] dn
  460. * The DN to convert
  461. * @return The objectsignature
  462. * @throw objectnotfound When the DN does not exist or does not match the object class.
  463. * @throw toomanyobjects When more then one object was found
  464. */
  465. objectsignature_t objectDNtoObjectSignature(objectclass_t objclass, const string &dn);
  466. /**
  467. * Convert a list of DN's to a list of object signatures
  468. *
  469. * @param[in] objclass
  470. * The objectclass to which this search should be restricted.
  471. * The objectclass can be partially unknown (OBJECTCLASS_UNKNOWN, MAILUSER_UNKNOWN, ...)
  472. * @param[in] dn
  473. * List of DN's
  474. * @return The list of objectsignatures
  475. */
  476. std::unique_ptr<signatures_t> objectDNtoObjectSignatures(objectclass_t objclass, const std::list<std::string> &dn);
  477. /**
  478. * Escape binary data to escaped string
  479. *
  480. * @param[in] lpdata
  481. * The binary data
  482. * @param[in] size
  483. * The length of the binary data
  484. * @param[out] lpEscaped
  485. * Escaped string
  486. */
  487. HRESULT BintoEscapeSequence(const char* lpdata, size_t size, string* lpEscaped);
  488. /**
  489. * Escape binary data to escaped string
  490. *
  491. * @param[in] lpdata
  492. * The binary data
  493. * @param[in] size
  494. * The length of the binary data
  495. * @return Escaped string
  496. */
  497. std::string StringEscapeSequence(const char* lpdata, size_t size);
  498. /**
  499. * Escape binary data to escaped string
  500. *
  501. * @param[in] strData
  502. * The binary data
  503. * @return Escaped string
  504. */
  505. std::string StringEscapeSequence(const string &strData);
  506. /**
  507. * Determine the search base for a LDAP query
  508. *
  509. * @param[in] company
  510. * Optional argument, the company for which the base should be found
  511. * @return The search base
  512. * @throw runtime_error When the configuration option ldap_search_base is empty.
  513. */
  514. string getSearchBase(const objectid_t &company = objectid_t(CONTAINER_COMPANY));
  515. /**
  516. * Create a search filter for servers
  517. *
  518. * @return The server search filter
  519. */
  520. string getServerSearchFilter();
  521. /**
  522. * Create LDAP search filter based on the object class.
  523. *
  524. * @param[in] objclass
  525. * The objectclass for which the filter should be created
  526. * The objectclass can be partially unknown (OBJECTCLASS_UNKNOWN, MAILUSER_UNKNOWN, ...)
  527. * @return The search filter for the specified object class
  528. * @throw runtime_error when an invalid objectclass is requested or configuration options are missing.
  529. */
  530. string getSearchFilter(objectclass_t objclass = OBJECTCLASS_UNKNOWN);
  531. /**
  532. * Create LDAP search filter based on the object data and the attribute in which the date should
  533. * be found. If attr is NULL this function will return an empty string,
  534. *
  535. * @param[in] data
  536. * The object data
  537. * @param[in] attr
  538. * Optional argument, The attribute in which the data should be found.
  539. * @param[in] attr_type
  540. * Optional argument, The attribute type (text, DN, binary, ...)
  541. * @return The LDAP Search filter.
  542. */
  543. string getSearchFilter(const string &data, const char *attr = NULL, const char *attr_type = NULL);
  544. /**
  545. * Create LDAP search filter based on the object id and the attribute in which the object id should
  546. * be found. If attr is empty the object class will be used to discover the unique attribute for
  547. * that object class.
  548. *
  549. * @param[in] id
  550. * The object id for which the LDAP filter should be created
  551. * @param[in] attr
  552. * Optional argument, The attribute in which the object id should be found.
  553. * @param[in] attr_type
  554. * Optional argument, The attribute type (text, DN, binary, ...)
  555. * @return The LDAP Search filter.
  556. * @throw runtime_error When an invalid objectclass was requested
  557. */
  558. string getObjectSearchFilter(const objectid_t &id, const char *attr = NULL, const char *attr_type = NULL);
  559. /**
  560. * Resolve objects from attribute data
  561. *
  562. * This will call LDAPUserPlugin::resolveObjectsFromAttributes()
  563. *
  564. * @param[in] objclass
  565. * The objectclass to which this search should be restricted.
  566. * The objectclass can be partially unknown (OBJECTCLASS_UNKNOWN, MAILUSER_UNKNOWN, ...)
  567. * @param[in] objects
  568. * The list of atribute data
  569. * @param[in] lpAttr
  570. * The attribute which should contain the AttrData
  571. * @param[in] company
  572. * Optional argument, The company where the possible object should belong.
  573. * @return The list of object signatures which were found
  574. */
  575. std::unique_ptr<signatures_t> resolveObjectsFromAttribute(objectclass_t objclass, const std::list<std::string> &objects, const char *lpAttr, const objectid_t &company = objectid_t(CONTAINER_COMPANY));
  576. /**
  577. * Resolve objects from attribute data by checking if the data contains
  578. * in any of the provided attributes.
  579. *
  580. * This will call LDAPUserPlugin::getAllObjectsByFilter()
  581. *
  582. * @param[in] objclass
  583. * The objectclass to which this search should be restricted.
  584. * The objectclass can be partially unknown (OBJECTCLASS_UNKNOWN, MAILUSER_UNKNOWN, ...)
  585. * @param[in] objects
  586. * The list of atribute data
  587. * @param[in] lppAttr
  588. * The attributes which should contain the AttrData
  589. * @param[in] company
  590. * Optional argument, The company where the possible object should belong.
  591. * @return The list of object signatures which were found
  592. */
  593. std::unique_ptr<signatures_t> resolveObjectsFromAttributes(objectclass_t objclass, const std::list<std::string> &objects, const char **lppAttr, const objectid_t &company = objectid_t(CONTAINER_COMPANY));
  594. /**
  595. * Resolve object from attribute data depending on the attribute type
  596. *
  597. * This will call LDAPUserPlugin::resolveObjectsFromAttributeType()
  598. *
  599. * @param[in] objclass
  600. * The objectclass to which this search should be restricted.
  601. * The objectclass can be partially unknown (OBJECTCLASS_UNKNOWN, MAILUSER_UNKNOWN, ...)
  602. * @param[in] AttrData
  603. * The contents of the attribute
  604. * @param[in] lpAttr
  605. * The attribute which should contain the AttrData
  606. * @param[in] lpAttrType
  607. * The attribute type of the attribte, can be DN, text or binary
  608. * @param[in] company
  609. * Optional argument, The company where the possible object should belong.
  610. * @return The object signature which was found
  611. * @throw objectnotfound When no object was found with the attribute data
  612. * @throw toomanyobjects When more then one object was found with the attribute data
  613. */
  614. objectsignature_t resolveObjectFromAttributeType(objectclass_t objclass,
  615. const string &AttrData, const char* lpAttr, const char* lpAttrType,
  616. const objectid_t &company = objectid_t(CONTAINER_COMPANY));
  617. /**
  618. * Resolve objects from attribute data depending on the attribute type
  619. *
  620. * This will call LDAPUserPlugin::resolveObjectsFromAttributes()
  621. *
  622. * @param[in] objclass
  623. * The objectclass to which this search should be restricted.
  624. * The objectclass can be partially unknown (OBJECTCLASS_UNKNOWN, MAILUSER_UNKNOWN, ...)
  625. * @param[in] objects
  626. * The list of atribute data
  627. * @param[in] lpAttr
  628. * The attribute which should contain the AttrData
  629. * @param[in] lpAttrType
  630. * The attribute type of the attribtes, can be DN, text or binary
  631. * @param[in] company
  632. * Optional argument, The company where the possible object should belong.
  633. * @return The list of object signatures which were found
  634. */
  635. std::unique_ptr<signatures_t> resolveObjectsFromAttributeType(objectclass_t objclass, const std::list<std::string> &objects, const char *lpAttr, const char *lpAttrType, const objectid_t &company = objectid_t(CONTAINER_COMPANY));
  636. /**
  637. * Resolve objects from attribute data by checking if the data contains
  638. * in any of the provided attributes depending on the attribute type.
  639. *
  640. * This will call LDAPUserPlugin::objectDNtoObjectSignatures() or
  641. * LDAPUserPlugin::resolveObjectsFromAttributes() depending on the attribute type.
  642. *
  643. * @param[in] objclass
  644. * The objectclass to which this search should be restricted.
  645. * The objectclass can be partially unknown (OBJECTCLASS_UNKNOWN, MAILUSER_UNKNOWN, ...)
  646. * @param[in] objects
  647. * The list of atribute data
  648. * @param[in] lppAttr
  649. * The attributes which should contain the AttrData
  650. * @param[in] lpAttrType
  651. * The attribute type of the attribtes, can be DN, text or binary
  652. * @param[in] company
  653. * Optional argument, The company where the possible object should belong.
  654. * @return The list of object signatures which were found
  655. */
  656. std::unique_ptr<signatures_t> resolveObjectsFromAttributesType(objectclass_t objclass, const std::list<std::string> &objects, const char **lppAttr, const char *lpAttrType, const objectid_t &company = objectid_t(CONTAINER_COMPANY));
  657. /**
  658. * Determine attribute data for a specific object id
  659. *
  660. * @param[in] uniqueid
  661. * The object id which should be converted
  662. * @param[in] lpAttr
  663. * he LDAP attribute which should be read from the object
  664. * @return The attribute data from lpAtrr in the DN
  665. * @throw runtime_error When the LDAP query failed
  666. * @throw objectnotfound When DN does not point to an existing object
  667. * @throw toomanyobjects When multiple objects were found
  668. * @throw data_error When the requested attribute does not exist on the object of uniqueid
  669. */
  670. string objectUniqueIDtoAttributeData(const objectid_t &uniqueid, const char* lpAttr);
  671. /**
  672. * Apply filter to LDAP and request all object signatures
  673. * of the objects which were returned by the filter.
  674. *
  675. * @param[in] basedn
  676. * The LDAP base from where the filter should be applied
  677. * @param[in] scope
  678. * Search scope (SUB, ONE, BASE)
  679. * @param[in] search_filter
  680. * The LDAP search filter which should be applied
  681. * @param[in] strCompanyDN
  682. * Optional argument, the company to which all returned
  683. * objects should belong. This DN must be the same as basedn.
  684. * @param[in] bCache
  685. * Set to true if this query should update the LDAPCache.
  686. * @return The list of object signatures for all found objects
  687. * @throw runtime_error When the LDAP query failed
  688. */
  689. std::unique_ptr<signatures_t> getAllObjectsByFilter(const std::string &basedn, int scope, const std::string &search_filter, const std::string &strCompanyDN, bool bCache);
  690. /**
  691. * Detecmine object id from LDAP result entry
  692. *
  693. * This function must be called when the following attributes were requested:
  694. * - ldap_object_type_attribute
  695. * - ldap_nonactive_attribute
  696. * - ldap_resource_type_attribute
  697. * - ldap_group_security_attribute
  698. * - ldap_group_security_attribute_type
  699. * - ldap_user_unique_attribute
  700. * - ldap_group_unique_attribute
  701. * - ldap_company_unique_attribute
  702. * - ldap_addresslist_unique_attribute
  703. * - ldap_dynamicgroup_unique_attribute
  704. *
  705. * This will determine the object ID by first determining the object type from the
  706. * objectClass and possibly other attributes, and then get the object's unique ID
  707. * from the attribute list.
  708. *
  709. * @remarks The caller is responsible for making sure all required attributes are
  710. * available in the LDAP result entry.
  711. *
  712. * @param[in] entry
  713. * The LDAPMessage which contains the requested
  714. * attributes from LDAP
  715. * @return The Object id.
  716. */
  717. objectid_t GetObjectIdForEntry(LDAPMessage *entry);
  718. /**
  719. * Wrapper function for ldap_search_s which has reconnect features
  720. *
  721. * @param[in] base
  722. * The LDAP search base
  723. * @param[in] scope
  724. * Search scope (SUB, ONE, BASE)
  725. * @param[in] filter
  726. * The LDAP search filter
  727. * @param[in] attrs
  728. * The attributes which should be requested from the objects
  729. * @param[in] attrsonly
  730. * Set to 1 to request attribute types only. Set to 0 to request
  731. * both attributes types and attribute values.
  732. * @param[out] lppres
  733. * Contains the result of the synchronous search operation
  734. * @throw ldap_error When the LDAP query failed
  735. *
  736. * @todo return value lppres
  737. */
  738. void my_ldap_search_s(char *base, int scope, char *filter, char *attrs[], int attrsonly, LDAPMessage **lppres, LDAPControl **serverControls = NULL);
  739. /**
  740. * Get list of object classes from object class settings string
  741. *
  742. * Object classes must be separated by comma (,) and are trimmed for whitespace surrounding the
  743. * classes.
  744. *
  745. * @param[in] lpszClasses
  746. * String from settings with classes separated by comma (,)
  747. * @return std::list List of classes converted from settings
  748. */
  749. std::list<std::string> GetClasses(const char *lpszClasses);
  750. /**
  751. * Returns TRUE if all classes in lstClasses are set in setClasses
  752. *
  753. * Due to case-insensitivity of object classes, the object classes in setClasses must
  754. * be provided in UPPER CASE, while the classes in lstClasses need not be.
  755. *
  756. * @param[in] setClasses
  757. * Set of classes to look in (UPPER CASE)
  758. * @param[in] lstClasses
  759. * Set of classes that must be in setClasses
  760. * @return boolean TRUE if all classes in lstClasses are available in setClasses
  761. */
  762. bool MatchClasses(std::set<std::string> setClasses, std::list<std::string> lstClasses);
  763. /**
  764. * Creates an LDAP object class filter for a list of object classes
  765. *
  766. * Takes the list of object classes passed and converts them into an LDAP
  767. * filter that matches entries which have all the passed object classes.
  768. *
  769. * @param[in] lpszObjectClassAttr
  770. * Name of the objectClass attribute that should be matched
  771. * @param[in] lpszClasses
  772. * String with classes separated by comma (,) that should be in
  773. * the filter. The string will be convert in a list. See GetClasses
  774. * @return std::string Filter
  775. */
  776. std::string GetObjectClassFilter(const char *lpszObjectClassAttr, const char *lpszClasses);
  777. long unsigned int ldapServerIndex; // index of the last ldap server to which we could connect
  778. std::vector<std::string> ldap_servers;
  779. };
  780. } /* namespace */
  781. extern "C" {
  782. extern _kc_export UserPlugin *getUserPluginInstance(std::mutex &, ECPluginSharedData *);
  783. extern _kc_export void deleteUserPluginInstance(UserPlugin *);
  784. extern _kc_export int getUserPluginVersion(void);
  785. }
  786. /** @} */
  787. #endif