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.

239 lines
7.2 KiB

  1. #ifndef __REGSEC_H_INCLUDED__
  2. #define __REGSEC_H_INCLUDED__
  3. extern "C"
  4. {
  5. #include "authz.h"
  6. }
  7. #include "objbase.h"
  8. #include "aclapi.h"
  9. #include "aclui.h"
  10. //Type def for PREDEFINED KEYS
  11. typedef enum _PREDEFINE_KEY {
  12. PREDEFINE_KEY_CLASSES_ROOT,
  13. PREDEFINE_KEY_CURRENT_USER,
  14. PREDEFINE_KEY_LOCAL_MACHINE,
  15. PREDEFINE_KEY_USERS,
  16. PREDEFINE_KEY_CURRENT_CONFIG
  17. } PREDEFINE_KEY;
  18. class CSecurityInformation : public ISecurityInformation,IEffectivePermission,ISecurityObjectTypeInfo
  19. {
  20. private:
  21. long m_cRef;
  22. public:
  23. CSecurityInformation():m_cRef(0){}
  24. virtual ~CSecurityInformation(){};
  25. // IUnknown methods
  26. STDMETHOD(QueryInterface)(REFIID, LPVOID *);
  27. STDMETHOD_(ULONG, AddRef)();
  28. STDMETHOD_(ULONG, Release)();
  29. // ISecurityInformation methods
  30. STDMETHOD(GetObjectInformation)(
  31. IN PSI_OBJECT_INFO pObjectInfo
  32. ) = 0;
  33. STDMETHOD(GetSecurity)(
  34. IN SECURITY_INFORMATION RequestedInformation,
  35. OUT PSECURITY_DESCRIPTOR *ppSecurityDescriptor,
  36. IN BOOL fDefault
  37. ) = 0;
  38. STDMETHOD(SetSecurity)(
  39. IN SECURITY_INFORMATION SecurityInformation,
  40. IN PSECURITY_DESCRIPTOR pSecurityDescriptor
  41. ) = 0;
  42. STDMETHOD(GetAccessRights)(
  43. const GUID *pguidObjectType,
  44. DWORD dwFlags,
  45. PSI_ACCESS *ppAccess,
  46. ULONG *pcAccesses,
  47. ULONG *piDefaultAccess
  48. ) = 0;
  49. STDMETHOD(MapGeneric)(
  50. const GUID *pguidObjectType,
  51. UCHAR *pAceFlags,
  52. ACCESS_MASK *pMask
  53. ) = 0;
  54. STDMETHOD(GetInheritTypes)(
  55. PSI_INHERIT_TYPE *ppInheritTypes,
  56. ULONG *pcInheritTypes
  57. ) = 0;
  58. STDMETHOD(PropertySheetPageCallback)(
  59. HWND hwnd,
  60. UINT uMsg,
  61. SI_PAGE_TYPE uPage
  62. ) = 0;
  63. STDMETHOD(GetEffectivePermission) ( const GUID* pguidObjectType,
  64. PSID pUserSid,
  65. LPCWSTR pszServerName,
  66. PSECURITY_DESCRIPTOR pSD,
  67. POBJECT_TYPE_LIST *ppObjectTypeList,
  68. ULONG *pcObjectTypeListLength,
  69. PACCESS_MASK *ppGrantedAccessList,
  70. ULONG *pcGrantedAccessListLength) =0;
  71. STDMETHOD(GetInheritSource)(SECURITY_INFORMATION si,
  72. PACL pACL,
  73. PINHERITED_FROM *ppInheritArray) PURE;
  74. };
  75. class CKeySecurityInformation : public CSecurityInformation
  76. {
  77. private:
  78. //Name of the Key, NULL for ROOT key
  79. LPCWSTR m_strKeyName;
  80. //Name of the parent Key, NULL for root and immediate child of root.
  81. LPCWSTR m_strParentName;
  82. //Name of the server, can be NULL
  83. LPCWSTR m_strMachineName;
  84. //Title of the page
  85. LPCWSTR m_strPageTitle;
  86. //if connected to Remote System, Machine name must not be null in this case
  87. BOOL m_bRemote;
  88. PREDEFINE_KEY m_PredefinedKey;
  89. BOOL m_bReadOnly;
  90. //Handle to predefined key. If handle to remote registry, close in Destructor
  91. HKEY m_hkeyPredefinedKey;
  92. LPWSTR m_strCompleteName ; //Free in Destructor
  93. DWORD m_dwFlags;
  94. //This HWND to application window
  95. HWND m_hWnd;
  96. //This is HWND to currently infocus ACLUI property Sheet. Null if none
  97. HWND m_hWndProperty;
  98. AUTHZ_RESOURCE_MANAGER_HANDLE m_ResourceManager; //Used for access check
  99. AUTHZ_RESOURCE_MANAGER_HANDLE GetAUTHZ_RM(){ return m_ResourceManager; }
  100. HWND GetInFocusHWnd() { return m_hWndProperty? m_hWndProperty : m_hWnd; }
  101. public:
  102. CKeySecurityInformation(): m_strKeyName(NULL),m_strParentName(NULL),
  103. m_strMachineName(NULL), m_strPageTitle(NULL),
  104. m_bRemote(false),m_PredefinedKey((PREDEFINE_KEY)0),
  105. m_bReadOnly(false),m_strCompleteName(NULL),
  106. m_hWnd(NULL), m_hWndProperty(NULL),
  107. m_ResourceManager(NULL){}
  108. ~CKeySecurityInformation();
  109. public:
  110. // *** ISecurityInformation methods ***
  111. STDMETHOD(GetObjectInformation) (PSI_OBJECT_INFO pObjectInfo );
  112. STDMETHOD(GetSecurity)(
  113. IN SECURITY_INFORMATION RequestedInformation,
  114. OUT PSECURITY_DESCRIPTOR *ppSecurityDescriptor,
  115. IN BOOL fDefault
  116. );
  117. STDMETHOD(SetSecurity)(
  118. IN SECURITY_INFORMATION SecurityInformation,
  119. IN PSECURITY_DESCRIPTOR pSecurityDescriptor
  120. );
  121. STDMETHOD(GetAccessRights)(
  122. const GUID *pguidObjectType,
  123. DWORD dwFlags,
  124. PSI_ACCESS *ppAccess,
  125. ULONG *pcAccesses,
  126. ULONG *piDefaultAccess
  127. );
  128. STDMETHOD(MapGeneric)(
  129. const GUID *pguidObjectType,
  130. UCHAR *pAceFlags,
  131. ACCESS_MASK *pMask
  132. );
  133. STDMETHOD(GetInheritTypes)(
  134. PSI_INHERIT_TYPE *ppInheritTypes,
  135. ULONG *pcInheritTypes
  136. );
  137. STDMETHOD(PropertySheetPageCallback)(
  138. HWND hwnd,
  139. UINT uMsg,
  140. SI_PAGE_TYPE uPage
  141. );
  142. STDMETHOD(GetEffectivePermission) ( const GUID* pguidObjectType,
  143. PSID pUserSid,
  144. LPCWSTR pszServerName,
  145. PSECURITY_DESCRIPTOR pSD,
  146. POBJECT_TYPE_LIST *ppObjectTypeList,
  147. ULONG *pcObjectTypeListLength,
  148. PACCESS_MASK *ppGrantedAccessList,
  149. ULONG *pcGrantedAccessListLength) ;
  150. STDMETHOD(GetInheritSource)(SECURITY_INFORMATION si,
  151. PACL pACL,
  152. PINHERITED_FROM *ppInheritArray);
  153. HRESULT Initialize ( LPCWSTR strKeyName,
  154. LPCWSTR strParentName,
  155. LPCWSTR strMachineName,
  156. LPCWSTR strPageTitle,
  157. BOOL bRemote,
  158. PREDEFINE_KEY PredefinedKey,
  159. BOOL bReadOnly,
  160. HWND hWnd);
  161. protected:
  162. HRESULT SetCompleteName();
  163. LPCWSTR GetCompleteName(){ return m_strCompleteName; }
  164. LPCWSTR GetCompleteName1();
  165. HRESULT SetHandleToPredefinedKey();
  166. STDMETHOD(WriteObjectSecurity)(
  167. LPCTSTR pszObject,
  168. SECURITY_INFORMATION si,
  169. PSECURITY_DESCRIPTOR pSD
  170. );
  171. STDMETHOD(WriteObjectSecurity)(
  172. HKEY hkey,
  173. SECURITY_INFORMATION si,
  174. PSECURITY_DESCRIPTOR pSD
  175. );
  176. HRESULT SetSubKeysSecurity(
  177. HKEY hkey,
  178. SECURITY_INFORMATION si,
  179. PSECURITY_DESCRIPTOR pSD,
  180. LPBOOL pbNotAllApplied,
  181. bool bFirstCall
  182. );
  183. HRESULT OpenKey(
  184. DWORD Permission,
  185. PHKEY pKey
  186. );
  187. };
  188. //
  189. extern "C"
  190. {
  191. HRESULT CreateSecurityInformation( IN LPCWSTR strKeyName,
  192. IN LPCWSTR strParentName,
  193. IN LPCWSTR strMachineName,
  194. IN LPCWSTR strPageTitle,
  195. IN BOOL bRemote,
  196. IN PREDEFINE_KEY PredefinedKey,
  197. IN BOOL bReadOnly,
  198. IN HWND hWnd,
  199. OUT LPSECURITYINFO *pSi);
  200. }
  201. BOOL DisplayMessage( HWND hWnd,
  202. HINSTANCE hInstance,
  203. DWORD dwMessageId,
  204. DWORD dwCaptionId );
  205. #endif // ~__PERMPAGE_H_INCLUDED__