jwaaclui.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. {******************************************************************************}
  2. { }
  3. { Access Control UI API interface Unit for Object Pascal }
  4. { }
  5. { Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
  6. { Corporation. All Rights Reserved. }
  7. { }
  8. { The original file is: aclui.h, released June 2000. The original Pascal }
  9. { code is: AclUI.pas, released December 2000. The initial developer of the }
  10. { Pascal code is Marcel van Brakel (brakelm att chello dott nl). }
  11. { }
  12. { Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
  13. { Marcel van Brakel. All Rights Reserved. }
  14. { }
  15. { Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
  16. { }
  17. { You may retrieve the latest version of this file at the Project JEDI }
  18. { APILIB home page, located at http://jedi-apilib.sourceforge.net }
  19. { }
  20. { The contents of this file are used with permission, subject to the Mozilla }
  21. { Public License Version 1.1 (the "License"); you may not use this file except }
  22. { in compliance with the License. You may obtain a copy of the License at }
  23. { http://www.mozilla.org/MPL/MPL-1.1.html }
  24. { }
  25. { Software distributed under the License is distributed on an "AS IS" basis, }
  26. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  27. { the specific language governing rights and limitations under the License. }
  28. { }
  29. { Alternatively, the contents of this file may be used under the terms of the }
  30. { GNU Lesser General Public License (the "LGPL License"), in which case the }
  31. { provisions of the LGPL License are applicable instead of those above. }
  32. { If you wish to allow use of your version of this file only under the terms }
  33. { of the LGPL License and not to allow others to use your version of this file }
  34. { under the MPL, indicate your decision by deleting the provisions above and }
  35. { replace them with the notice and other provisions required by the LGPL }
  36. { License. If you do not delete the provisions above, a recipient may use }
  37. { your version of this file under either the MPL or the LGPL License. }
  38. { }
  39. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  40. { }
  41. {******************************************************************************}
  42. // $Id: JwaAclUI.pas,v 1.10 2005/09/06 16:36:50 marquardt Exp $
  43. unit JwaAclUI;
  44. {$WEAKPACKAGEUNIT}
  45. {$HPPEMIT ''}
  46. {$HPPEMIT '#include "aclui.h"'}
  47. {$HPPEMIT ''}
  48. {$I jediapilib.inc}
  49. interface
  50. uses
  51. JwaAccCtrl, JwaWindows;
  52. //
  53. // ISecurityInformation interface
  54. //
  55. // Methods:
  56. //
  57. // GetObjectInformation - Allows UI to determine type of object being
  58. // edited. Also allows determining if object is a container.
  59. //
  60. // GetSecurity - Allows retrieving of ACLs from the original object
  61. // NOTE: ACLUI will LocalFree the security descriptor
  62. // returned by GetSecurity.
  63. // SetSecurity - Allows setting of the ACLs on the original object
  64. //
  65. // GetAccessRights - For retrieving the list of rights allowed
  66. // on this object.
  67. //
  68. // MapGeneric - For mapping generic rights to standard & specific rights
  69. //
  70. // GetInheritTypes - For retrieving the list of possible sub-object types
  71. // for a container.
  72. //
  73. // PropertySheetCallback - A method which is called back during the various
  74. // security UI property pages so that specialized work can be
  75. // done. Similar to PropSheetPageProc. If uMsg == PSPCB_CREATE,
  76. // then any error return value other than E_NOTIMPL will abort
  77. // the creation of that page. The type of page being created or
  78. // destroyed is indicated by the uPage parameter.
  79. //
  80. type
  81. PSI_OBJECT_INFO = ^SI_OBJECT_INFO;
  82. {$EXTERNALSYM PSI_OBJECT_INFO}
  83. _SI_OBJECT_INFO = record
  84. dwFlags: DWORD;
  85. hInstance: HINST; // resources (e.g. strings) reside here
  86. pszServerName: LPWSTR; // must be present
  87. pszObjectName: LPWSTR; // must be present
  88. pszPageTitle: LPWSTR; // only valid if SI_PAGE_TITLE is set
  89. guidObjectType: GUID; // only valid if SI_OBJECT_GUID is set
  90. end;
  91. {$EXTERNALSYM _SI_OBJECT_INFO}
  92. SI_OBJECT_INFO = _SI_OBJECT_INFO;
  93. {$EXTERNALSYM SI_OBJECT_INFO}
  94. TSiObjectInfo = SI_OBJECT_INFO;
  95. PSiObjectInfo = PSI_OBJECT_INFO;
  96. // SI_OBJECT_INFO flags
  97. const
  98. SI_EDIT_PERMS = $00000000; // always implied
  99. {$EXTERNALSYM SI_EDIT_PERMS}
  100. SI_EDIT_OWNER = $00000001;
  101. {$EXTERNALSYM SI_EDIT_OWNER}
  102. SI_EDIT_AUDITS = $00000002;
  103. {$EXTERNALSYM SI_EDIT_AUDITS}
  104. SI_CONTAINER = $00000004;
  105. {$EXTERNALSYM SI_CONTAINER}
  106. SI_READONLY = $00000008;
  107. {$EXTERNALSYM SI_READONLY}
  108. SI_ADVANCED = $00000010;
  109. {$EXTERNALSYM SI_ADVANCED}
  110. SI_RESET = $00000020; // equals to SI_RESET_DACL|SI_RESET_SACL|SI_RESET_OWNER
  111. {$EXTERNALSYM SI_RESET}
  112. SI_OWNER_READONLY = $00000040;
  113. {$EXTERNALSYM SI_OWNER_READONLY}
  114. SI_EDIT_PROPERTIES = $00000080;
  115. {$EXTERNALSYM SI_EDIT_PROPERTIES}
  116. SI_OWNER_RECURSE = $00000100;
  117. {$EXTERNALSYM SI_OWNER_RECURSE}
  118. SI_NO_ACL_PROTECT = $00000200;
  119. {$EXTERNALSYM SI_NO_ACL_PROTECT}
  120. SI_NO_TREE_APPLY = $00000400;
  121. {$EXTERNALSYM SI_NO_TREE_APPLY}
  122. SI_PAGE_TITLE = $00000800;
  123. {$EXTERNALSYM SI_PAGE_TITLE}
  124. SI_SERVER_IS_DC = $00001000;
  125. {$EXTERNALSYM SI_SERVER_IS_DC}
  126. SI_RESET_DACL_TREE = $00004000;
  127. {$EXTERNALSYM SI_RESET_DACL_TREE}
  128. SI_RESET_SACL_TREE = $00008000;
  129. {$EXTERNALSYM SI_RESET_SACL_TREE}
  130. SI_OBJECT_GUID = $00010000;
  131. {$EXTERNALSYM SI_OBJECT_GUID}
  132. SI_EDIT_EFFECTIVE = $00020000;
  133. {$EXTERNALSYM SI_EDIT_EFFECTIVE}
  134. SI_RESET_DACL = $00040000;
  135. {$EXTERNALSYM SI_RESET_DACL}
  136. SI_RESET_SACL = $00080000;
  137. {$EXTERNALSYM SI_RESET_SACL}
  138. SI_RESET_OWNER = $00100000;
  139. {$EXTERNALSYM SI_RESET_OWNER}
  140. SI_NO_ADDITIONAL_PERMISSION = $00200000;
  141. {$EXTERNALSYM SI_NO_ADDITIONAL_PERMISSION}
  142. SI_MAY_WRITE = $10000000; //not sure if user can write permission
  143. {$EXTERNALSYM SI_MAY_WRITE}
  144. SI_EDIT_ALL = SI_EDIT_PERMS or SI_EDIT_OWNER or SI_EDIT_AUDITS;
  145. {$EXTERNALSYM SI_EDIT_ALL}
  146. type
  147. PSI_ACCESS = ^SI_ACCESS;
  148. {$EXTERNALSYM PSI_ACCESS}
  149. _SI_ACCESS = record
  150. pguid: LPGUID;
  151. mask: ACCESS_MASK;
  152. pszName: LPCWSTR; // may be resource ID
  153. dwFlags: DWORD;
  154. end;
  155. {$EXTERNALSYM _SI_ACCESS}
  156. SI_ACCESS = _SI_ACCESS;
  157. {$EXTERNALSYM SI_ACCESS}
  158. TSiAccess = SI_ACCESS;
  159. PSiAccess = PSI_ACCESS;
  160. // SI_ACCESS flags
  161. const
  162. SI_ACCESS_SPECIFIC = $00010000;
  163. {$EXTERNALSYM SI_ACCESS_SPECIFIC}
  164. SI_ACCESS_GENERAL = $00020000;
  165. {$EXTERNALSYM SI_ACCESS_GENERAL}
  166. SI_ACCESS_CONTAINER = $00040000; // general access, container-only
  167. {$EXTERNALSYM SI_ACCESS_CONTAINER}
  168. SI_ACCESS_PROPERTY = $00080000;
  169. {$EXTERNALSYM SI_ACCESS_PROPERTY}
  170. // ACE inheritance flags (CONTAINER_INHERIT_ACE, etc.) may also be set.
  171. // They will be used as the inheritance when an access is turned on.
  172. type
  173. PSI_INHERIT_TYPE = ^SI_INHERIT_TYPE;
  174. {$EXTERNALSYM PSI_INHERIT_TYPE}
  175. _SI_INHERIT_TYPE = record
  176. pguid: LPGUID;
  177. dwFlags: ULONG;
  178. pszName: LPCWSTR; // may be resource ID
  179. end;
  180. {$EXTERNALSYM _SI_INHERIT_TYPE}
  181. SI_INHERIT_TYPE = _SI_INHERIT_TYPE;
  182. {$EXTERNALSYM SI_INHERIT_TYPE}
  183. TSiInheritType = SI_INHERIT_TYPE;
  184. PSiInheritType = PSI_INHERIT_TYPE;
  185. // SI_INHERIT_TYPE flags are a combination of INHERIT_ONLY_ACE,
  186. // CONTAINER_INHERIT_ACE, and OBJECT_INHERIT_ACE.
  187. _SI_PAGE_TYPE = (SI_PAGE_PERM, SI_PAGE_ADVPERM, SI_PAGE_AUDIT, SI_PAGE_OWNER, SI_PAGE_EFFECTIVE);
  188. {$EXTERNALSYM _SI_PAGE_TYPE}
  189. SI_PAGE_TYPE = _SI_PAGE_TYPE;
  190. {$EXTERNALSYM SI_PAGE_TYPE}
  191. TSiPageType = _SI_PAGE_TYPE;
  192. // Message to PropertySheetPageCallback (in addition to
  193. // PSPCB_CREATE and PSPCB_RELEASE)
  194. const
  195. PSPCB_SI_INITDIALOG = WM_USER + 1;
  196. {$EXTERNALSYM PSPCB_SI_INITDIALOG}
  197. const
  198. IID_ISecurityInformation: GUID = (
  199. D1:$965fc360; D2:$16ff; D3:$11d0; D4:($91, $cb, $0, $aa, $0, $bb, $b7, $23));
  200. {$EXTERNALSYM IID_ISecurityInformation}
  201. IID_ISecurityInformation2: GUID = (
  202. D1:$c3ccfdb4; D2:$6f88; D3:$11d2; D4:($a3, $ce, $0, $c0, $4f, $b1, $78, $2a));
  203. {$EXTERNALSYM IID_ISecurityInformation2}
  204. SID_ISecurityInformation = '{965FC360-16FF-11d0-91CB-00AA00BBB723}';
  205. SID_ISecurityInformation2 = '{c3ccfdb4-6f88-11d2-a3ce-00c04fb1782a}';
  206. type
  207. ISecurityInformation = interface(IUnknown)
  208. [SID_ISecurityInformation]
  209. function GetObjectInformation(out pObjectInfo: SI_OBJECT_INFO): HRESULT; stdcall;
  210. function GetSecurity(RequestedInformation: SECURITY_INFORMATION;
  211. out ppSecurityDescriptor: PSECURITY_DESCRIPTOR; fDefault: BOOL): HRESULT; stdcall;
  212. function SetSecurity(SecurityInformation: SECURITY_INFORMATION;
  213. pSecurityDescriptor: PSECURITY_DESCRIPTOR): HRESULT; stdcall;
  214. function GetAccessRights(pguidObjectType: LPGUID; dwFlags: DWORD;
  215. out ppAccess: PSI_ACCESS; out pcAccesses, piDefaultAccess: ULONG): HRESULT; stdcall;
  216. function MapGeneric(pguidObjectType: LPGUID; pAceFlags: PUCHAR;
  217. pMask: PACCESS_MASK): HRESULT; stdcall;
  218. function GetInheritTypes(out ppInheritTypes: PSI_INHERIT_TYPE;
  219. out pcInheritTypes: ULONG): HRESULT; stdcall;
  220. function PropertySheetPageCallback(hwnd: HWND; uMsg: UINT;
  221. uPage: SI_PAGE_TYPE): HRESULT; stdcall;
  222. end;
  223. {$EXTERNALSYM ISecurityInformation}
  224. LPSECURITYINFO = ISecurityInformation;
  225. {$EXTERNALSYM LPSECURITYINFO}
  226. ISecurityInformation2 = interface(IUnknown)
  227. [SID_ISecurityInformation]
  228. function IsDaclCanonical(pDacl: PACL): BOOL; stdcall;
  229. function LookupSids(cSids: ULONG; rgpSids: PPSID;
  230. out ppdo: Pointer{*LPDATAOBJECT}): HRESULT; stdcall;
  231. end;
  232. {$EXTERNALSYM ISecurityInformation2}
  233. LPSECURITYINFO2 = ISecurityInformation2;
  234. {$EXTERNALSYM LPSECURITYINFO2}
  235. // HGLOBAL containing SID_INFO_LIST returned by ISecurityInformation2::LookupSids
  236. const
  237. CFSTR_ACLUI_SID_INFO_LIST = 'CFSTR_ACLUI_SID_INFO_LIST';
  238. {$EXTERNALSYM CFSTR_ACLUI_SID_INFO_LIST}
  239. // Data structures corresponding to CFSTR_ACLUI_SID_INFO_LIST
  240. type
  241. PSID_INFO = ^SID_INFO;
  242. {$EXTERNALSYM PSID_INFO}
  243. _SID_INFO = record
  244. pSid: PSID;
  245. pwzCommonName: PWSTR;
  246. pwzClass: PWSTR; // Used for selecting icon, e.g. "User" or "Group"
  247. pwzUPN: PWSTR; // Optional, may be NULL
  248. end;
  249. {$EXTERNALSYM _SID_INFO}
  250. SID_INFO = _SID_INFO;
  251. {$EXTERNALSYM SID_INFO}
  252. TSidInfo = SID_INFO;
  253. PSidInfo = PSID_INFO;
  254. PSID_INFO_LIST = ^SID_INFO_LIST;
  255. {$EXTERNALSYM PSID_INFO_LIST}
  256. _SID_INFO_LIST = record
  257. cItems: ULONG;
  258. aSidInfo: array [0..ANYSIZE_ARRAY - 1] of SID_INFO;
  259. end;
  260. {$EXTERNALSYM _SID_INFO_LIST}
  261. SID_INFO_LIST = _SID_INFO_LIST;
  262. {$EXTERNALSYM SID_INFO_LIST}
  263. TSidInfoList = SID_INFO_LIST;
  264. PSidInfoList = PSID_INFO_LIST;
  265. const
  266. IID_IEffectivePermission: TGUID = '{3853DC76-9F35-407c-88A1-D19344365FBC}';
  267. {$EXTERNALSYM IID_IEffectivePermission}
  268. IID_ISecurityObjectTypeInfo: TGUID = '{fc3066eb-79ef-444b-9111-d18a75ebf2fa}';
  269. {$EXTERNALSYM IID_ISecurityObjectTypeInfo}
  270. type
  271. IEffectivePermission = interface(IUnknown)
  272. ['{3853DC76-9F35-407c-88A1-D19344365FBC}']
  273. function GetEffectivePermission(const pguidObjectType: TGUID; pUserSid: PSID;
  274. pszServerName: LPCWSTR; pSD: PSECURITY_DESCRIPTOR; var ppObjectTypeList: POBJECT_TYPE_LIST;
  275. var pcObjectTypeListLength: ULONG; var ppGrantedAccessList: PACCESS_MASK;
  276. var pcGrantedAccessListLength: ULONG): HRESULT; stdcall;
  277. end;
  278. {$EXTERNALSYM IEffectivePermission}
  279. LPEFFECTIVEPERMISSION = IEffectivePermission;
  280. {$EXTERNALSYM LPEFFECTIVEPERMISSION}
  281. ISecurityObjectTypeInfo = interface(IUnknown)
  282. ['{fc3066eb-79ef-444b-9111-d18a75ebf2fa}']
  283. function GetInheritSource(si: SECURITY_INFORMATION; pACL: PACL;
  284. var ppInheritArray: PINHERITED_FROM): HRESULT; stdcall;
  285. end;
  286. {$EXTERNALSYM ISecurityObjectTypeInfo}
  287. LPSecurityObjectTypeInfo = ISecurityObjectTypeInfo;
  288. {$EXTERNALSYM LPSecurityObjectTypeInfo}
  289. type
  290. HPROPSHEETPAGE = Pointer;
  291. {$EXTERNALSYM HPROPSHEETPAGE}
  292. function CreateSecurityPage(psi: LPSECURITYINFO): HPROPSHEETPAGE; stdcall;
  293. {$EXTERNALSYM CreateSecurityPage}
  294. function EditSecurity(hwndOwner: HWND; psi: LPSECURITYINFO): BOOL; stdcall;
  295. {$EXTERNALSYM EditSecurity}
  296. implementation
  297. uses
  298. JwaWinDLLNames;
  299. {$IFDEF DYNAMIC_LINK}
  300. var
  301. _CreateSecurityPage: Pointer;
  302. function CreateSecurityPage;
  303. begin
  304. GetProcedureAddress(_CreateSecurityPage, acluilib, 'CreateSecurityPage');
  305. asm
  306. MOV ESP, EBP
  307. POP EBP
  308. JMP [_CreateSecurityPage]
  309. end;
  310. end;
  311. var
  312. _EditSecurity: Pointer;
  313. function EditSecurity;
  314. begin
  315. GetProcedureAddress(_EditSecurity, acluilib, 'EditSecurity');
  316. asm
  317. MOV ESP, EBP
  318. POP EBP
  319. JMP [_EditSecurity]
  320. end;
  321. end;
  322. {$ELSE}
  323. function CreateSecurityPage; external acluilib name 'CreateSecurityPage';
  324. function EditSecurity; external acluilib name 'EditSecurity';
  325. {$ENDIF DYNAMIC_LINK}
  326. end.