ECSecurity.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. // ECSecurity.h: interface for the ECSecurity class.
  18. //
  19. //////////////////////////////////////////////////////////////////////
  20. #ifndef ECSECURITY
  21. #define ECSECURITY
  22. #include "ECUserManagement.h"
  23. #include "plugin.h"
  24. #include <kopano/ECLogger.h>
  25. #include <kopano/ECConfig.h>
  26. #include <kopano/ECDefs.h>
  27. namespace KC {
  28. class ECSession;
  29. #define EC_NO_IMPERSONATOR ((unsigned int)-1)
  30. class ECSecurity _kc_final {
  31. public:
  32. ECSecurity(ECSession *lpSession, ECConfig *lpConfig, ECLogger *lpAudit);
  33. virtual ~ECSecurity();
  34. /* must be called once the object is created */
  35. virtual ECRESULT SetUserContext(unsigned int ulUserId, unsigned int ulImpersonatorID);
  36. virtual ECRESULT CheckDeletedParent(unsigned int id) const;
  37. virtual ECRESULT CheckPermission(unsigned int ulObjId, unsigned int ulCheckRights);
  38. virtual ECRESULT GetRights(unsigned int objid, int type, struct rightsArray *out) const;
  39. virtual ECRESULT SetRights(unsigned int objid, struct rightsArray *lpsRightsArray);
  40. virtual ECRESULT GetUserCompany(unsigned int *) const;
  41. // Functions to determine which companies are visible, and which userobjects are
  42. // visible to the currently logged in user.
  43. virtual ECRESULT GetViewableCompanyIds(unsigned int ulFlags, std::list<localobjectdetails_t> **lppObjects);
  44. virtual ECRESULT IsUserObjectVisible(unsigned int ulUserObjectId);
  45. // Get the owner of an object
  46. virtual ECRESULT GetOwner(unsigned int obj_id, unsigned int *owner) const;
  47. // get the store owner, you can give every object id
  48. virtual ECRESULT GetStoreOwner(unsigned int obj_id, unsigned int *owner) const;
  49. virtual ECRESULT GetStoreOwnerAndType(unsigned int obj_id, unsigned int *owner, unsigned int *store_type) const;
  50. virtual ECRESULT GetObjectPermission(unsigned int id, unsigned int *rights) __attribute__((nonnull));
  51. virtual unsigned int GetUserId(unsigned int ulObjId = 0);
  52. virtual ECRESULT IsOwner(unsigned int objid) const;
  53. virtual ECRESULT IsStoreOwner(unsigned int store_id) const;
  54. virtual int GetAdminLevel(void) const;
  55. // Functions to determine if the user is the Administrator
  56. // over the company to which the user/object/store belongs.
  57. virtual ECRESULT IsAdminOverUserObject(unsigned int ulUserObjectId);
  58. virtual ECRESULT IsAdminOverOwnerOfObject(unsigned int ulObjectId);
  59. // Quota functions
  60. virtual ECRESULT CheckQuota(unsigned int store_id, long long store_size, eQuotaStatus *) const;
  61. virtual ECRESULT CheckUserQuota(unsigned int user_id, long long store_size, eQuotaStatus *) const;
  62. virtual ECRESULT GetStoreSize(unsigned int obj_id, long long *store_size) const;
  63. virtual ECRESULT GetUserSize(unsigned int user_id, long long *user_size) const;
  64. virtual ECRESULT GetUserQuota(unsigned int user_id, bool usr_dfl, quotadetails_t *) const;
  65. // information for ECSessionStatsTable
  66. virtual ECRESULT GetUsername(std::string *) const;
  67. virtual ECRESULT GetImpersonator(std::string *) const;
  68. virtual size_t GetObjectSize(void) const;
  69. private:
  70. ECRESULT GetGroupsForUser(unsigned int ulUserId, std::list<localobjectdetails_t> **lppGroups);
  71. ECRESULT GetViewableCompanies(unsigned int ulFlags, std::list<localobjectdetails_t> **lppObjects) const;
  72. ECRESULT GetAdminCompanies(unsigned int ulFlags, std::list<localobjectdetails_t> **lppObjects);
  73. ECRESULT HaveObjectPermission(unsigned int ulObjId, unsigned int ulACLMask);
  74. protected:
  75. ECSession *m_lpSession;
  76. ECLogger *m_lpAudit;
  77. ECConfig *m_lpConfig;
  78. unsigned int m_ulUserID = 0; // current user id
  79. unsigned int m_ulImpersonatorID = 0; // id of user that is impersonating the current user
  80. unsigned int m_ulCompanyID = 0; // Company to which the user belongs to
  81. objectdetails_t m_details;
  82. objectdetails_t m_impersonatorDetails;
  83. bool m_bRestrictedAdmin; // True if restricted admin permissions enabled
  84. bool m_bOwnerAutoFullAccess;
  85. std::list<localobjectdetails_t> *m_lpGroups = nullptr; // current user groups
  86. std::list<localobjectdetails_t> *m_lpViewCompanies = nullptr; // current visible companies
  87. std::list<localobjectdetails_t> *m_lpAdminCompanies = nullptr; // Companies where the user has admin rights on
  88. };
  89. } /* namespace */
  90. #endif // #ifndef ECSECURITY