Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

234 lines
8.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: perm.cpp
  8. //
  9. // This file contains the implementation for the simple permission
  10. // editor page.
  11. //
  12. //--------------------------------------------------------------------------
  13. #include "permset.h"
  14. #include "sddl.h" // ConvertSidToStringSid
  15. #define IDN_CHECKSELECTION 1
  16. void SelectListViewItem(HWND hwndList, int iItem);
  17. //
  18. // Context Help IDs.
  19. //
  20. const static DWORD aPermPageHelpIDs[] =
  21. {
  22. IDC_SPP_GROUP_USER_NAME, IDH_SPP_PRINCIPALS,
  23. IDC_SPP_PRINCIPALS, IDH_SPP_PRINCIPALS,
  24. IDC_SPP_ADD, IDH_SPP_ADD,
  25. IDC_SPP_REMOVE, IDH_SPP_REMOVE,
  26. IDC_SPP_ACCESS, IDH_SPP_PERMS,
  27. IDC_SPP_ACCESS_BIG, IDH_SPP_PERMS,
  28. IDC_SPP_ALLOW, IDH_SPP_PERMS,
  29. IDC_SPP_DENY, IDH_SPP_PERMS,
  30. IDC_SPP_PERMS, IDH_SPP_PERMS,
  31. IDC_SPP_STATIC_ADV, IDH_SPP_ADVANCED,
  32. IDC_SPP_ADVANCED, IDH_SPP_ADVANCED,
  33. IDC_SPP_MORE_MSG, IDH_NOHELP,
  34. 0, 0,
  35. };
  36. class CPrincipal;
  37. typedef class CPrincipal *LPPRINCIPAL;
  38. class CSecurityInfo;
  39. class CPermPage : public CSecurityPage
  40. {
  41. private:
  42. SECURITY_DESCRIPTOR_CONTROL m_wSDControl;
  43. WORD m_wDaclRevision;
  44. PSI_ACCESS m_pDefaultAccess;
  45. BOOL m_fPageDirty;
  46. BOOL m_fBusy;
  47. BOOL m_bWasDenyAcl;
  48. BOOL m_bCustomPermission;
  49. HCURSOR m_hcurBusy;
  50. HWND m_hEffectivePerm;
  51. DWORD m_cInheritableAces;
  52. public:
  53. CPermPage(LPSECURITYINFO psi)
  54. : CSecurityPage(psi, SI_PAGE_PERM),
  55. m_wDaclRevision(ACL_REVISION),
  56. m_hEffectivePerm(NULL),
  57. m_cInheritableAces(0)
  58. { m_hcurBusy = LoadCursor(NULL, IDC_APPSTARTING); }
  59. private:
  60. virtual BOOL DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  61. BOOL InitDlg(HWND hDlg);
  62. void InitPrincipalList(HWND hDlg, PACL pDacl);
  63. HRESULT InitCheckList(HWND hDlg);
  64. void EnumerateAcl(HWND hwndList, PACL pAcl);
  65. HRESULT SetPrincipalNamesInList(HWND hwndList, PSID pSid = NULL);
  66. int AddPrincipalToList(HWND hwndList, LPPRINCIPAL pPrincipal);
  67. BOOL OnNotify(HWND hDlg, int idCtrl, LPNMHDR pnmh);
  68. void OnSelChange(HWND hDlg, BOOL bClearFirst = TRUE, BOOL bClearCustomAllow = FALSE, BOOL bClearCustomDeny = FALSE);
  69. void OnApply(HWND hDlg, BOOL bClose);
  70. HRESULT BuildDacl(HWND hDlg,
  71. PSECURITY_DESCRIPTOR *ppSD,
  72. BOOL fIncludeInherited);
  73. HRESULT SetDacl(HWND hDlg,
  74. PSECURITY_DESCRIPTOR psd,
  75. BOOL bDirty = FALSE);
  76. void OnAddPrincipal(HWND hDlg);
  77. void OnRemovePrincipal(HWND hDlg);
  78. void OnAdvanced(HWND hDlg);
  79. void EnablePrincipalControls(HWND hDlg, BOOL fEnable);
  80. void CommitCurrent(HWND hDlg, int iPrincipal = -1);
  81. void OnSize(HWND hDlg, DWORD dwSizeType, ULONG nWidth, ULONG nHeight);
  82. void ClearPermissions(HWND hwndList, BOOL bDisabled = TRUE);
  83. void SetDirty(HWND hDlg, BOOL bDefault = FALSE);
  84. void SetEffectivePerm(HWND hwnd){m_hEffectivePerm = hwnd;}
  85. VOID SetPermLabelText(HWND hDlg);
  86. friend class CPrincipal;
  87. friend class CSecurityInfo;
  88. };
  89. typedef class CPermPage *PPERMPAGE;
  90. class CPrincipal
  91. {
  92. private:
  93. PPERMPAGE m_pPage;
  94. LPTSTR m_pszName;
  95. LPTSTR m_pszDisplayName; //This is only name. Doesn't include Logon Name
  96. PSID m_pSID;
  97. SID_IMAGE_INDEX m_nImageIndex;
  98. BOOL m_bHaveRealName;
  99. public:
  100. CPermissionSet m_permDeny;
  101. CPermissionSet m_permAllow;
  102. CPermissionSet m_permInheritedDeny;
  103. CPermissionSet m_permInheritedAllow;
  104. HDSA m_hAdditionalAllow;
  105. HDSA m_hAdditionalDeny;
  106. public:
  107. CPrincipal(CPermPage *pPage) : m_pPage(pPage), m_nImageIndex(SID_IMAGE_UNKNOWN),
  108. m_pszDisplayName(NULL) {}
  109. ~CPrincipal();
  110. BOOL SetPrincipal(PSID pSID,
  111. SID_NAME_USE sidType = SidTypeUnknown,
  112. LPCTSTR pszName = NULL,
  113. LPCTSTR pszLogonName = NULL);
  114. BOOL SetName(LPCTSTR pszName, LPCTSTR pszLogonName = NULL);
  115. void SetSidType(SID_NAME_USE sidType) { m_nImageIndex = GetSidImageIndex(m_pSID, sidType); }
  116. PSID GetSID() const { return m_pSID; }
  117. LPCTSTR GetName() const { return m_pszName; }
  118. LPCTSTR GetDisplayName() const{ return m_pszDisplayName ? m_pszDisplayName : m_pszName; }
  119. int GetImageIndex() const { return m_nImageIndex; }
  120. BOOL HaveRealName() { return m_bHaveRealName; }
  121. BOOL AddAce(PACE_HEADER pAce);
  122. ULONG GetAclLength(DWORD dwFlags);
  123. BOOL AppendToAcl(PACL pAcl, DWORD dwFlags, PACE_HEADER *ppAcePos);
  124. BOOL HaveInheritedAces(void);
  125. void ConvertInheritedAces(BOOL bDelete);
  126. void AddPermission(BOOL bAllow, PPERMISSION pperm);
  127. void RemovePermission(BOOL bAllow, PPERMISSION pperm);
  128. private:
  129. CPermissionSet* GetPermSet(DWORD dwType, BOOL bInherited);
  130. BOOL AddNormalAce(DWORD dwType, DWORD dwFlags, ACCESS_MASK mask, const GUID *pObjectType);
  131. BOOL AddAdvancedAce(DWORD dwType, PACE_HEADER pAce);
  132. };
  133. // flag bits for GetAclLength & AppendToAcl
  134. #define ACL_NONINHERITED 0x00010000L
  135. #define ACL_INHERITED 0x00020000L
  136. #define ACL_DENY 0x00040000L
  137. #define ACL_ALLOW 0x00080000L
  138. #define ACL_CHECK_CREATOR 0x00100000L
  139. #define ACL_NONOBJECT PS_NONOBJECT
  140. #define ACL_OBJECT PS_OBJECT
  141. //
  142. // Wrapper for ISecurityInformation. Used when invoking
  143. // the advanced ACL editor
  144. //
  145. class CSecurityInfo : public ISecurityInformation, ISecurityInformation2,
  146. IEffectivePermission, ISecurityObjectTypeInfo
  147. #if(_WIN32_WINNT >= 0x0500)
  148. , IDsObjectPicker
  149. #endif
  150. {
  151. private:
  152. ULONG m_cRef;
  153. PPERMPAGE m_pPage;
  154. HWND m_hDlg;
  155. public:
  156. CSecurityInfo(PPERMPAGE pPage, HWND hDlg)
  157. : m_cRef(1), m_pPage(pPage), m_hDlg(hDlg) {}
  158. // IUnknown methods
  159. STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  160. STDMETHODIMP_(ULONG) AddRef();
  161. STDMETHODIMP_(ULONG) Release();
  162. // ISecurityInformation methods
  163. STDMETHODIMP GetObjectInformation(PSI_OBJECT_INFO pObjectInfo);
  164. STDMETHODIMP GetSecurity(SECURITY_INFORMATION si,
  165. PSECURITY_DESCRIPTOR *ppSD,
  166. BOOL fDefault);
  167. STDMETHODIMP SetSecurity(SECURITY_INFORMATION si,
  168. PSECURITY_DESCRIPTOR pSD);
  169. STDMETHODIMP GetAccessRights(const GUID* pguidObjectType,
  170. DWORD dwFlags,
  171. PSI_ACCESS *ppAccess,
  172. ULONG *pcAccesses,
  173. ULONG *piDefaultAccess);
  174. STDMETHODIMP MapGeneric(const GUID* pguidObjectType,
  175. UCHAR *pAceFlags,
  176. ACCESS_MASK *pmask);
  177. STDMETHODIMP GetInheritTypes(PSI_INHERIT_TYPE *ppInheritTypes,
  178. ULONG *pcInheritTypes);
  179. STDMETHODIMP PropertySheetPageCallback(HWND hwnd, UINT uMsg, SI_PAGE_TYPE uPage);
  180. // ISecurityInformation2 methods
  181. STDMETHODIMP_(BOOL) IsDaclCanonical(PACL pDacl);
  182. STDMETHODIMP LookupSids(ULONG cSids, PSID *rgpSids, LPDATAOBJECT *ppdo);
  183. // IDsObjectPicker methods
  184. #if(_WIN32_WINNT >= 0x0500)
  185. STDMETHODIMP Initialize(PDSOP_INIT_INFO pInitInfo);
  186. STDMETHODIMP InvokeDialog(HWND hwndParent, IDataObject **ppdoSelection);
  187. #endif
  188. STDMETHOD(GetInheritSource)(SECURITY_INFORMATION si,
  189. PACL pACL,
  190. PINHERITED_FROM *ppInheritArray);
  191. STDMETHOD(GetEffectivePermission) ( THIS_ const GUID* pguidObjectType,
  192. PSID pUserSid,
  193. LPCWSTR pszServerName,
  194. PSECURITY_DESCRIPTOR pSD,
  195. POBJECT_TYPE_LIST *ppObjectTypeList,
  196. ULONG *pcObjectTypeListLength,
  197. PACCESS_MASK *ppGrantedAccessList,
  198. ULONG *pcGrantedAccessListLength);
  199. };