jwaaclui.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. unit JwaAclUI;
  43. {$WEAKPACKAGEUNIT}
  44. {$HPPEMIT ''}
  45. {$HPPEMIT '#include "aclui.h"'}
  46. {$HPPEMIT ''}
  47. {$I jediapilib.inc}
  48. interface
  49. uses
  50. JwaAccCtrl, JwaWinNT, JwaWinUser, JwaWinType;
  51. //
  52. // ISecurityInformation interface
  53. //
  54. // Methods:
  55. //
  56. // GetObjectInformation - Allows UI to determine type of object being
  57. // edited. Also allows determining if object is a container.
  58. //
  59. // GetSecurity - Allows retrieving of ACLs from the original object
  60. // NOTE: ACLUI will LocalFree the security descriptor
  61. // returned by GetSecurity.
  62. // SetSecurity - Allows setting of the ACLs on the original object
  63. //
  64. // GetAccessRights - For retrieving the list of rights allowed
  65. // on this object.
  66. //
  67. // MapGeneric - For mapping generic rights to standard & specific rights
  68. //
  69. // GetInheritTypes - For retrieving the list of possible sub-object types
  70. // for a container.
  71. //
  72. // PropertySheetCallback - A method which is called back during the various
  73. // security UI property pages so that specialized work can be
  74. // done. Similar to PropSheetPageProc. If uMsg == PSPCB_CREATE,
  75. // then any error return value other than E_NOTIMPL will abort
  76. // the creation of that page. The type of page being created or
  77. // destroyed is indicated by the uPage parameter.
  78. //
  79. type
  80. PSI_OBJECT_INFO = ^SI_OBJECT_INFO;
  81. {$EXTERNALSYM PSI_OBJECT_INFO}
  82. _SI_OBJECT_INFO = record
  83. dwFlags: DWORD;
  84. hInstance: HINSTANCE; // resources (e.g. strings) reside here
  85. pszServerName: LPWSTR; // must be present
  86. pszObjectName: LPWSTR; // must be present
  87. pszPageTitle: LPWSTR; // only valid if SI_PAGE_TITLE is set
  88. guidObjectType: GUID; // only valid if SI_OBJECT_GUID is set
  89. end;
  90. {$EXTERNALSYM _SI_OBJECT_INFO}
  91. SI_OBJECT_INFO = _SI_OBJECT_INFO;
  92. {$EXTERNALSYM SI_OBJECT_INFO}
  93. TSiObjectInfo = SI_OBJECT_INFO;
  94. PSiObjectInfo = PSI_OBJECT_INFO;
  95. // SI_OBJECT_INFO flags
  96. const
  97. SI_EDIT_PERMS = $00000000; // always implied
  98. {$EXTERNALSYM SI_EDIT_PERMS}
  99. SI_EDIT_OWNER = $00000001;
  100. {$EXTERNALSYM SI_EDIT_OWNER}
  101. SI_EDIT_AUDITS = $00000002;
  102. {$EXTERNALSYM SI_EDIT_AUDITS}
  103. SI_CONTAINER = $00000004;
  104. {$EXTERNALSYM SI_CONTAINER}
  105. SI_READONLY = $00000008;
  106. {$EXTERNALSYM SI_READONLY}
  107. SI_ADVANCED = $00000010;
  108. {$EXTERNALSYM SI_ADVANCED}
  109. SI_RESET = $00000020; // equals to SI_RESET_DACL|SI_RESET_SACL|SI_RESET_OWNER
  110. {$EXTERNALSYM SI_RESET}
  111. SI_OWNER_READONLY = $00000040;
  112. {$EXTERNALSYM SI_OWNER_READONLY}
  113. SI_EDIT_PROPERTIES = $00000080;
  114. {$EXTERNALSYM SI_EDIT_PROPERTIES}
  115. SI_OWNER_RECURSE = $00000100;
  116. {$EXTERNALSYM SI_OWNER_RECURSE}
  117. SI_NO_ACL_PROTECT = $00000200;
  118. {$EXTERNALSYM SI_NO_ACL_PROTECT}
  119. SI_NO_TREE_APPLY = $00000400;
  120. {$EXTERNALSYM SI_NO_TREE_APPLY}
  121. SI_PAGE_TITLE = $00000800;
  122. {$EXTERNALSYM SI_PAGE_TITLE}
  123. SI_SERVER_IS_DC = $00001000;
  124. {$EXTERNALSYM SI_SERVER_IS_DC}
  125. SI_RESET_DACL_TREE = $00004000;
  126. {$EXTERNALSYM SI_RESET_DACL_TREE}
  127. SI_RESET_SACL_TREE = $00008000;
  128. {$EXTERNALSYM SI_RESET_SACL_TREE}
  129. SI_OBJECT_GUID = $00010000;
  130. {$EXTERNALSYM SI_OBJECT_GUID}
  131. SI_EDIT_EFFECTIVE = $00020000;
  132. {$EXTERNALSYM SI_EDIT_EFFECTIVE}
  133. SI_RESET_DACL = $00040000;
  134. {$EXTERNALSYM SI_RESET_DACL}
  135. SI_RESET_SACL = $00080000;
  136. {$EXTERNALSYM SI_RESET_SACL}
  137. SI_RESET_OWNER = $00100000;
  138. {$EXTERNALSYM SI_RESET_OWNER}
  139. SI_NO_ADDITIONAL_PERMISSION = $00200000;
  140. {$EXTERNALSYM SI_NO_ADDITIONAL_PERMISSION}
  141. SI_MAY_WRITE = $10000000; //not sure if user can write permission
  142. {$EXTERNALSYM SI_MAY_WRITE}
  143. SI_EDIT_ALL = SI_EDIT_PERMS or SI_EDIT_OWNER or SI_EDIT_AUDITS;
  144. {$EXTERNALSYM SI_EDIT_ALL}
  145. type
  146. PSI_ACCESS = ^SI_ACCESS;
  147. {$EXTERNALSYM PSI_ACCESS}
  148. _SI_ACCESS = record
  149. pguid: LPGUID;
  150. mask: ACCESS_MASK;
  151. pszName: LPCWSTR; // may be resource ID
  152. dwFlags: DWORD;
  153. end;
  154. {$EXTERNALSYM _SI_ACCESS}
  155. SI_ACCESS = _SI_ACCESS;
  156. {$EXTERNALSYM SI_ACCESS}
  157. TSiAccess = SI_ACCESS;
  158. PSiAccess = PSI_ACCESS;
  159. // SI_ACCESS flags
  160. const
  161. SI_ACCESS_SPECIFIC = $00010000;
  162. {$EXTERNALSYM SI_ACCESS_SPECIFIC}
  163. SI_ACCESS_GENERAL = $00020000;
  164. {$EXTERNALSYM SI_ACCESS_GENERAL}
  165. SI_ACCESS_CONTAINER = $00040000; // general access, container-only
  166. {$EXTERNALSYM SI_ACCESS_CONTAINER}
  167. SI_ACCESS_PROPERTY = $00080000;
  168. {$EXTERNALSYM SI_ACCESS_PROPERTY}
  169. // ACE inheritance flags (CONTAINER_INHERIT_ACE, etc.) may also be set.
  170. // They will be used as the inheritance when an access is turned on.
  171. type
  172. PSI_INHERIT_TYPE = ^SI_INHERIT_TYPE;
  173. {$EXTERNALSYM PSI_INHERIT_TYPE}
  174. _SI_INHERIT_TYPE = record
  175. pguid: LPGUID;
  176. dwFlags: ULONG;
  177. pszName: LPCWSTR; // may be resource ID
  178. end;
  179. {$EXTERNALSYM _SI_INHERIT_TYPE}
  180. SI_INHERIT_TYPE = _SI_INHERIT_TYPE;
  181. {$EXTERNALSYM SI_INHERIT_TYPE}
  182. TSiInheritType = SI_INHERIT_TYPE;
  183. PSiInheritType = PSI_INHERIT_TYPE;
  184. // SI_INHERIT_TYPE flags are a combination of INHERIT_ONLY_ACE,
  185. // CONTAINER_INHERIT_ACE, and OBJECT_INHERIT_ACE.
  186. _SI_PAGE_TYPE = (SI_PAGE_PERM, SI_PAGE_ADVPERM, SI_PAGE_AUDIT, SI_PAGE_OWNER, SI_PAGE_EFFECTIVE);
  187. {$EXTERNALSYM _SI_PAGE_TYPE}
  188. SI_PAGE_TYPE = _SI_PAGE_TYPE;
  189. {$EXTERNALSYM SI_PAGE_TYPE}
  190. TSiPageType = _SI_PAGE_TYPE;
  191. // Message to PropertySheetPageCallback (in addition to
  192. // PSPCB_CREATE and PSPCB_RELEASE)
  193. const
  194. PSPCB_SI_INITDIALOG = WM_USER + 1;
  195. {$EXTERNALSYM PSPCB_SI_INITDIALOG}
  196. const
  197. IID_ISecurityInformation: GUID = (
  198. D1:$965fc360; D2:$16ff; D3:$11d0; D4:($91, $cb, $0, $aa, $0, $bb, $b7, $23));
  199. {$EXTERNALSYM IID_ISecurityInformation}
  200. IID_ISecurityInformation2: GUID = (
  201. D1:$c3ccfdb4; D2:$6f88; D3:$11d2; D4:($a3, $ce, $0, $c0, $4f, $b1, $78, $2a));
  202. {$EXTERNALSYM IID_ISecurityInformation2}
  203. SID_ISecurityInformation = '{965FC360-16FF-11d0-91CB-00AA00BBB723}';
  204. SID_ISecurityInformation2 = '{c3ccfdb4-6f88-11d2-a3ce-00c04fb1782a}';
  205. type
  206. ISecurityInformation = interface(IUnknown)
  207. [SID_ISecurityInformation]
  208. function GetObjectInformation(out pObjectInfo: SI_OBJECT_INFO): HRESULT; stdcall;
  209. function GetSecurity(RequestedInformation: SECURITY_INFORMATION;
  210. out ppSecurityDescriptor: PSECURITY_DESCRIPTOR; fDefault: BOOL): HRESULT; stdcall;
  211. function SetSecurity(SecurityInformation: SECURITY_INFORMATION;
  212. pSecurityDescriptor: PSECURITY_DESCRIPTOR): HRESULT; stdcall;
  213. function GetAccessRights(pguidObjectType: LPGUID; dwFlags: DWORD;
  214. out ppAccess: PSI_ACCESS; out pcAccesses, piDefaultAccess: ULONG): HRESULT; stdcall;
  215. function MapGeneric(pguidObjectType: LPGUID; pAceFlags: PUCHAR;
  216. pMask: PACCESS_MASK): HRESULT; stdcall;
  217. function GetInheritTypes(out ppInheritTypes: PSI_INHERIT_TYPE;
  218. out pcInheritTypes: ULONG): HRESULT; stdcall;
  219. function PropertySheetPageCallback(hwnd: HWND; uMsg: UINT;
  220. uPage: SI_PAGE_TYPE): HRESULT; stdcall;
  221. end;
  222. {$EXTERNALSYM ISecurityInformation}
  223. LPSECURITYINFO = ISecurityInformation;
  224. {$EXTERNALSYM LPSECURITYINFO}
  225. ISecurityInformation2 = interface(IUnknown)
  226. [SID_ISecurityInformation]
  227. function IsDaclCanonical(pDacl: PACL): BOOL; stdcall;
  228. function LookupSids(cSids: ULONG; rgpSids: PPSID;
  229. out ppdo: Pointer{*LPDATAOBJECT}): HRESULT; stdcall;
  230. end;
  231. {$EXTERNALSYM ISecurityInformation2}
  232. LPSECURITYINFO2 = ISecurityInformation2;
  233. {$EXTERNALSYM LPSECURITYINFO2}
  234. // HGLOBAL containing SID_INFO_LIST returned by ISecurityInformation2::LookupSids
  235. const
  236. CFSTR_ACLUI_SID_INFO_LIST = 'CFSTR_ACLUI_SID_INFO_LIST';
  237. {$EXTERNALSYM CFSTR_ACLUI_SID_INFO_LIST}
  238. // Data structures corresponding to CFSTR_ACLUI_SID_INFO_LIST
  239. type
  240. PSID_INFO = ^SID_INFO;
  241. {$EXTERNALSYM PSID_INFO}
  242. _SID_INFO = record
  243. pSid: PSID;
  244. pwzCommonName: PWSTR;
  245. pwzClass: PWSTR; // Used for selecting icon, e.g. "User" or "Group"
  246. pwzUPN: PWSTR; // Optional, may be NULL
  247. end;
  248. {$EXTERNALSYM _SID_INFO}
  249. SID_INFO = _SID_INFO;
  250. {$EXTERNALSYM SID_INFO}
  251. TSidInfo = SID_INFO;
  252. PSidInfo = PSID_INFO;
  253. PSID_INFO_LIST = ^SID_INFO_LIST;
  254. {$EXTERNALSYM PSID_INFO_LIST}
  255. _SID_INFO_LIST = record
  256. cItems: ULONG;
  257. aSidInfo: array [0..ANYSIZE_ARRAY - 1] of SID_INFO;
  258. end;
  259. {$EXTERNALSYM _SID_INFO_LIST}
  260. SID_INFO_LIST = _SID_INFO_LIST;
  261. {$EXTERNALSYM SID_INFO_LIST}
  262. TSidInfoList = SID_INFO_LIST;
  263. PSidInfoList = PSID_INFO_LIST;
  264. const
  265. IID_IEffectivePermission: TGUID = '{3853DC76-9F35-407c-88A1-D19344365FBC}';
  266. {$EXTERNALSYM IID_IEffectivePermission}
  267. IID_ISecurityObjectTypeInfo: TGUID = '{fc3066eb-79ef-444b-9111-d18a75ebf2fa}';
  268. {$EXTERNALSYM IID_ISecurityObjectTypeInfo}
  269. type
  270. IEffectivePermission = interface(IUnknown)
  271. ['{3853DC76-9F35-407c-88A1-D19344365FBC}']
  272. function GetEffectivePermission(const pguidObjectType: TGUID; pUserSid: PSID;
  273. pszServerName: LPCWSTR; pSD: PSECURITY_DESCRIPTOR; var ppObjectTypeList: POBJECT_TYPE_LIST;
  274. var pcObjectTypeListLength: ULONG; var ppGrantedAccessList: PACCESS_MASK;
  275. var pcGrantedAccessListLength: ULONG): HRESULT; stdcall;
  276. end;
  277. {$EXTERNALSYM IEffectivePermission}
  278. LPEFFECTIVEPERMISSION = IEffectivePermission;
  279. {$EXTERNALSYM LPEFFECTIVEPERMISSION}
  280. ISecurityObjectTypeInfo = interface(IUnknown)
  281. ['{fc3066eb-79ef-444b-9111-d18a75ebf2fa}']
  282. function GetInheritSource(si: SECURITY_INFORMATION; pACL: PACL;
  283. var ppInheritArray: PINHERITED_FROM): HRESULT; stdcall;
  284. end;
  285. {$EXTERNALSYM ISecurityObjectTypeInfo}
  286. LPSecurityObjectTypeInfo = ISecurityObjectTypeInfo;
  287. {$EXTERNALSYM LPSecurityObjectTypeInfo}
  288. type
  289. HPROPSHEETPAGE = Pointer;
  290. {$EXTERNALSYM HPROPSHEETPAGE}
  291. function CreateSecurityPage(psi: LPSECURITYINFO): HPROPSHEETPAGE; stdcall;
  292. {$EXTERNALSYM CreateSecurityPage}
  293. function EditSecurity(hwndOwner: HWND; psi: LPSECURITYINFO): BOOL; stdcall;
  294. {$EXTERNALSYM EditSecurity}
  295. implementation
  296. const
  297. acluilib = 'aclui.dll';
  298. {$IFDEF DYNAMIC_LINK}
  299. var
  300. _CreateSecurityPage: Pointer;
  301. function CreateSecurityPage;
  302. begin
  303. GetProcedureAddress(_CreateSecurityPage, acluilib, 'CreateSecurityPage');
  304. asm
  305. MOV ESP, EBP
  306. POP EBP
  307. JMP [_CreateSecurityPage]
  308. end;
  309. end;
  310. var
  311. _EditSecurity: Pointer;
  312. function EditSecurity;
  313. begin
  314. GetProcedureAddress(_EditSecurity, acluilib, 'EditSecurity');
  315. asm
  316. MOV ESP, EBP
  317. POP EBP
  318. JMP [_EditSecurity]
  319. end;
  320. end;
  321. {$ELSE}
  322. function CreateSecurityPage; external acluilib name 'CreateSecurityPage';
  323. function EditSecurity; external acluilib name 'EditSecurity';
  324. {$ENDIF DYNAMIC_LINK}
  325. end.