Leaked source code of windows server 2003
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.

240 lines
9.0 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. SI_ACCESS m_CustomAccess;
  53. //This is set to true when user cannot read and write dacl however
  54. //has right to change owner. After changing owner, user will be able
  55. //to read/write acl. ACLUI doesn't have refresh function so user needs
  56. //to close and reopen the property sheet. So if m_CustomAccess is set
  57. //to true and user changes owner we will show an error message to close
  58. //and reopen the property sheet.
  59. //NTRAID#NTBUG9-621338-2002/05/23-hiteshr
  60. BOOL m_bNoReadWriteCanWriteOwner;
  61. public:
  62. CPermPage(LPSECURITYINFO psi)
  63. : CSecurityPage(psi, SI_PAGE_PERM),
  64. m_wDaclRevision(ACL_REVISION),
  65. m_hEffectivePerm(NULL),
  66. m_cInheritableAces(0),
  67. m_bNoReadWriteCanWriteOwner(FALSE)
  68. { m_hcurBusy = LoadCursor(NULL, IDC_APPSTARTING); }
  69. private:
  70. virtual BOOL DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  71. BOOL InitDlg(HWND hDlg);
  72. void InitPrincipalList(HWND hDlg, PACL pDacl);
  73. HRESULT InitCheckList(HWND hDlg);
  74. void EnumerateAcl(HWND hwndList, PACL pAcl);
  75. HRESULT SetPrincipalNamesInList(HWND hwndList, PSID pSid = NULL);
  76. int AddPrincipalToList(HWND hwndList, LPPRINCIPAL pPrincipal);
  77. BOOL OnNotify(HWND hDlg, int idCtrl, LPNMHDR pnmh);
  78. void OnSelChange(HWND hDlg, BOOL bClearFirst = TRUE, BOOL bClearCustomAllow = FALSE, BOOL bClearCustomDeny = FALSE);
  79. void OnApply(HWND hDlg, BOOL bClose);
  80. HRESULT BuildDacl(HWND hDlg,
  81. PSECURITY_DESCRIPTOR *ppSD,
  82. BOOL fIncludeInherited);
  83. HRESULT SetDacl(HWND hDlg,
  84. PSECURITY_DESCRIPTOR psd,
  85. BOOL bDirty = FALSE);
  86. void OnAddPrincipal(HWND hDlg);
  87. void OnRemovePrincipal(HWND hDlg);
  88. void OnAdvanced(HWND hDlg);
  89. void EnablePrincipalControls(HWND hDlg, BOOL fEnable);
  90. void CommitCurrent(HWND hDlg, int iPrincipal = -1);
  91. void OnSize(HWND hDlg, DWORD dwSizeType, ULONG nWidth, ULONG nHeight);
  92. void ClearPermissions(HWND hwndList, BOOL bDisabled = TRUE);
  93. void SetDirty(HWND hDlg, BOOL bDefault = FALSE);
  94. void SetEffectivePerm(HWND hwnd){m_hEffectivePerm = hwnd;}
  95. VOID SetPermLabelText(HWND hDlg);
  96. friend class CPrincipal;
  97. friend class CSecurityInfo;
  98. };
  99. typedef class CPermPage *PPERMPAGE;
  100. class CPrincipal
  101. {
  102. private:
  103. PPERMPAGE m_pPage;
  104. LPTSTR m_pszName;
  105. LPTSTR m_pszDisplayName; //This is only name. Doesn't include Logon Name
  106. PSID m_pSID;
  107. SID_IMAGE_INDEX m_nImageIndex;
  108. BOOL m_bHaveRealName;
  109. public:
  110. CPermissionSet m_permDeny;
  111. CPermissionSet m_permAllow;
  112. CPermissionSet m_permInheritedDeny;
  113. CPermissionSet m_permInheritedAllow;
  114. HDSA m_hAdditionalAllow;
  115. HDSA m_hAdditionalDeny;
  116. public:
  117. CPrincipal(CPermPage *pPage) : m_pPage(pPage), m_nImageIndex(SID_IMAGE_UNKNOWN),
  118. m_pszDisplayName(NULL) {}
  119. ~CPrincipal();
  120. BOOL SetPrincipal(PSID pSID,
  121. SID_NAME_USE sidType = SidTypeUnknown,
  122. LPCTSTR pszName = NULL,
  123. LPCTSTR pszLogonName = NULL);
  124. BOOL SetName(LPCTSTR pszName, LPCTSTR pszLogonName = NULL);
  125. void SetSidType(SID_NAME_USE sidType) { m_nImageIndex = GetSidImageIndex(m_pSID, sidType); }
  126. PSID GetSID() const { return m_pSID; }
  127. LPCTSTR GetName() const { return m_pszName; }
  128. LPCTSTR GetDisplayName() const{ return m_pszDisplayName ? m_pszDisplayName : m_pszName; }
  129. int GetImageIndex() const { return m_nImageIndex; }
  130. BOOL HaveRealName() { return m_bHaveRealName; }
  131. BOOL AddAce(PACE_HEADER pAce);
  132. ULONG GetAclLength(DWORD dwFlags);
  133. BOOL AppendToAcl(PACL pAcl, DWORD dwFlags, PACE_HEADER *ppAcePos);
  134. BOOL HaveInheritedAces(void);
  135. void ConvertInheritedAces(BOOL bDelete);
  136. void AddPermission(BOOL bAllow, PPERMISSION pperm);
  137. void RemovePermission(BOOL bAllow, PPERMISSION pperm);
  138. private:
  139. CPermissionSet* GetPermSet(DWORD dwType, BOOL bInherited);
  140. BOOL AddNormalAce(DWORD dwType, DWORD dwFlags, ACCESS_MASK mask, const GUID *pObjectType);
  141. BOOL AddAdvancedAce(DWORD dwType, PACE_HEADER pAce);
  142. };
  143. // flag bits for GetAclLength & AppendToAcl
  144. #define ACL_NONINHERITED 0x00010000L
  145. #define ACL_INHERITED 0x00020000L
  146. #define ACL_DENY 0x00040000L
  147. #define ACL_ALLOW 0x00080000L
  148. #define ACL_CHECK_CREATOR 0x00100000L
  149. #define ACL_NONOBJECT PS_NONOBJECT
  150. #define ACL_OBJECT PS_OBJECT
  151. //
  152. // Wrapper for ISecurityInformation. Used when invoking
  153. // the advanced ACL editor
  154. //
  155. class CSecurityInfo : public ISecurityInformation, ISecurityInformation2,
  156. IEffectivePermission, ISecurityObjectTypeInfo
  157. , IDsObjectPicker
  158. {
  159. private:
  160. ULONG m_cRef;
  161. PPERMPAGE m_pPage;
  162. HWND m_hDlg;
  163. public:
  164. CSecurityInfo(PPERMPAGE pPage, HWND hDlg)
  165. : m_cRef(1), m_pPage(pPage), m_hDlg(hDlg) {}
  166. // IUnknown methods
  167. STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  168. STDMETHODIMP_(ULONG) AddRef();
  169. STDMETHODIMP_(ULONG) Release();
  170. // ISecurityInformation methods
  171. STDMETHODIMP GetObjectInformation(PSI_OBJECT_INFO pObjectInfo);
  172. STDMETHODIMP GetSecurity(SECURITY_INFORMATION si,
  173. PSECURITY_DESCRIPTOR *ppSD,
  174. BOOL fDefault);
  175. STDMETHODIMP SetSecurity(SECURITY_INFORMATION si,
  176. PSECURITY_DESCRIPTOR pSD);
  177. STDMETHODIMP GetAccessRights(const GUID* pguidObjectType,
  178. DWORD dwFlags,
  179. PSI_ACCESS *ppAccess,
  180. ULONG *pcAccesses,
  181. ULONG *piDefaultAccess);
  182. STDMETHODIMP MapGeneric(const GUID* pguidObjectType,
  183. UCHAR *pAceFlags,
  184. ACCESS_MASK *pmask);
  185. STDMETHODIMP GetInheritTypes(PSI_INHERIT_TYPE *ppInheritTypes,
  186. ULONG *pcInheritTypes);
  187. STDMETHODIMP PropertySheetPageCallback(HWND hwnd, UINT uMsg, SI_PAGE_TYPE uPage);
  188. // ISecurityInformation2 methods
  189. STDMETHODIMP_(BOOL) IsDaclCanonical(PACL pDacl);
  190. STDMETHODIMP LookupSids(ULONG cSids, PSID *rgpSids, LPDATAOBJECT *ppdo);
  191. // IDsObjectPicker methods
  192. STDMETHODIMP Initialize(PDSOP_INIT_INFO pInitInfo);
  193. STDMETHODIMP InvokeDialog(HWND hwndParent, IDataObject **ppdoSelection);
  194. STDMETHOD(GetInheritSource)(SECURITY_INFORMATION si,
  195. PACL pACL,
  196. PINHERITED_FROM *ppInheritArray);
  197. STDMETHOD(GetEffectivePermission) ( THIS_ const GUID* pguidObjectType,
  198. PSID pUserSid,
  199. LPCWSTR pszServerName,
  200. PSECURITY_DESCRIPTOR pSD,
  201. POBJECT_TYPE_LIST *ppObjectTypeList,
  202. ULONG *pcObjectTypeListLength,
  203. PACCESS_MASK *ppGrantedAccessList,
  204. ULONG *pcGrantedAccessListLength);
  205. };