DBUserPlugin.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 DBUSERPLUGIN_H
  19. #define DBUSERPLUGIN_H
  20. #include <memory>
  21. #include <mutex>
  22. #include <string>
  23. #include <kopano/zcdefs.h>
  24. #include "plugin.h"
  25. #include "DBBase.h"
  26. /**
  27. * @defgroup userplugin_bi_db Build-in database user plugin
  28. * @ingroup userplugin
  29. * @{
  30. */
  31. namespace KC {
  32. /**
  33. * Build-in database user plugin.
  34. *
  35. * User management based on Mysql. This is the build-in user management system
  36. */
  37. class DBUserPlugin _kc_final : public DBPlugin {
  38. public:
  39. /**
  40. * @param[in] pluginlock
  41. * The plugin mutex
  42. * @param[in] shareddata
  43. * The singleton shared plugin data.
  44. * @throw notsupported When multi-server support is enabled
  45. */
  46. DBUserPlugin(std::mutex &, ECPluginSharedData *shareddata);
  47. /**
  48. * Initialize plugin
  49. *
  50. * Calls DBPlugin::InitPlugin()
  51. */
  52. virtual void InitPlugin();
  53. /**
  54. * Resolve name and company to objectsignature
  55. *
  56. * @param[in] objclass
  57. * The objectclass of the name which should be resolved.
  58. * The objectclass can be partially unknown (OBJECTCLASS_UNKNOWN, MAILUSER_UNKNOWN, ...)
  59. * @param[in] name
  60. * The name which should be resolved
  61. * @param[in] company
  62. * The company beneath which the name should be searched
  63. * This objectid can be empty.
  64. * @return The object signature of the resolved object
  65. * @throw runtime_error When a Database error occurred.
  66. * @throw objectnotfound When no object was found.
  67. * @throw toomanyobjects When more then one object was found.
  68. */
  69. virtual objectsignature_t resolveName(objectclass_t objclass, const string &name, const objectid_t &company);
  70. /**
  71. * Authenticate user with username and password
  72. *
  73. * @param[in] username
  74. * The username of the user to be authenticated
  75. * @param[in] password
  76. * The password of the user to be authenticated
  77. * @param[in] company
  78. * The objectid of the company to which the user belongs.
  79. * This objectid can be empty.
  80. * @return The objectsignature of the authenticated user
  81. * @throw runtime_error When a Database error occurred.
  82. * @throw login_error When no user was found or the password was incorrect.
  83. */
  84. virtual objectsignature_t authenticateUser(const string &username, const string &password, const objectid_t &company);
  85. /**
  86. * Search for all objects which match the given string,
  87. * the name and email address should be compared for this search.
  88. *
  89. * This will call DBBase::searchObjects()
  90. *
  91. * @param[in] match
  92. * The string which should be found
  93. * @param[in] ulFlags
  94. * If EMS_AB_ADDRESS_LOOKUP the string must exactly match the name or email address
  95. * otherwise a partial match is allowed.
  96. * @return List of object signatures which match the given string
  97. * @throw std::exception
  98. */
  99. virtual std::unique_ptr<signatures_t> searchObject(const std::string &match, unsigned int ulFlags);
  100. /**
  101. * Modify id of object in plugin
  102. *
  103. * @note This function is not supported by this plugin and will always throw an exception
  104. *
  105. * @param[in] oldId
  106. * The old objectid
  107. * @param[in] newId
  108. * The new objectid
  109. * @throw notsupported Always when this function is called
  110. */
  111. virtual void modifyObjectId(const objectid_t &oldId, const objectid_t &newId);
  112. /**
  113. * Set quota information on object
  114. *
  115. * This will call DBBase::setQuota()
  116. *
  117. * @param[in] id
  118. * The objectid which should be updated
  119. * @param[in] quotadetails
  120. * The quota information which should be written to the object
  121. * @throw runtime_error When a Database error occurred.
  122. * @throw objectnotfound When the object was not found.
  123. */
  124. virtual void setQuota(const objectid_t &id, const quotadetails_t &quotadetails);
  125. /**
  126. * Obtain details for the public store
  127. *
  128. * @note This function is not supported by this plugin and will always throw an exception
  129. *
  130. * @return The public store details
  131. * @throw notsupported Always when this function is called
  132. */
  133. virtual std::unique_ptr<objectdetails_t> getPublicStoreDetails(void);
  134. /**
  135. * Obtain the objectdetails for a server
  136. *
  137. * @note This function is not supported by this plugin and will always throw an exception
  138. *
  139. * @param[in] server
  140. * The externid of the server
  141. * @return The server details
  142. * @throw notsupported Always when this function is called
  143. */
  144. virtual std::unique_ptr<serverdetails_t> getServerDetails(const std::string &server);
  145. /**
  146. * Obtain server list
  147. *
  148. * @return list of servers
  149. * @throw runtime_error LDAP query failure
  150. */
  151. virtual std::unique_ptr<serverlist_t> getServers(void);
  152. /**
  153. * Add relation between child and parent. This can be used
  154. * for example to add a user to a group or add
  155. * permission relations on companies.
  156. *
  157. * This will call DBPlugin::addSubObjectRelation().
  158. *
  159. * @param[in] relation
  160. * The relation type which should connect the
  161. * child and parent.
  162. * @param[in] parentobject
  163. * The parent object.
  164. * @param[in] childobject
  165. * The child object.
  166. * @throw runtime_error When a Database error occurred
  167. * @throw objectnotfound When the parent does not exist.
  168. */
  169. virtual void addSubObjectRelation(userobject_relation_t relation,
  170. const objectid_t &parentobject, const objectid_t &childobject);
  171. };
  172. } /* namespace */
  173. extern "C" {
  174. extern _kc_export UserPlugin *getUserPluginInstance(std::mutex &, ECPluginSharedData *);
  175. extern _kc_export void deleteUserPluginInstance(UserPlugin *);
  176. extern _kc_export int getUserPluginVersion(void);
  177. }
  178. /** @} */
  179. #endif