jwaadtgen.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. {******************************************************************************}
  2. { }
  3. { Authz Generic Audits 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: adtgen.h, released August 2001. The original Pascal }
  9. { code is: AdtGen.pas, released October 2001. 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: JwaAdtGen.pas,v 1.10 2005/09/06 16:36:50 marquardt Exp $
  43. unit JwaAdtGen;
  44. {$WEAKPACKAGEUNIT}
  45. {$HPPEMIT ''}
  46. {$HPPEMIT '#include "adtgen.h"'}
  47. {$HPPEMIT ''}
  48. {$I jediapilib.inc}
  49. interface
  50. uses
  51. JwaWindows;
  52. //
  53. // type of audit
  54. //
  55. // AUDIT_TYPE_LEGACY
  56. // In this case the audit event schema is stored in a .mc file.
  57. //
  58. // AUDIT_TYPE_WMI
  59. // The schema is stored in WMI. (currently not supported)
  60. //
  61. const
  62. AUDIT_TYPE_LEGACY = 1;
  63. {$EXTERNALSYM AUDIT_TYPE_LEGACY}
  64. AUDIT_TYPE_WMI = 2;
  65. {$EXTERNALSYM AUDIT_TYPE_WMI}
  66. //
  67. // Type of parameters passed in the AUDIT_PARAMS.Parameters array
  68. //
  69. // Use the AdtInitParams function to initialize and prepare
  70. // an array of audit parameters.
  71. //
  72. type
  73. _AUDIT_PARAM_TYPE = (
  74. APT__0,
  75. //
  76. // do we need this?
  77. //
  78. APT_None,
  79. //
  80. // NULL terminated string
  81. //
  82. APT_String,
  83. //
  84. // unsigned long
  85. //
  86. APT_Ulong,
  87. //
  88. // a pointer. use for specifying handles/pointers
  89. // (32 bit on 32 bit systems and 64 bit on 64 bit systems)
  90. // Note that the memory to which the pointer points to
  91. // is not marshalled when using this type. Use this when you
  92. // are interested in the absolute value of the pointer.
  93. // A good example of this is when specifying HANDLE values.
  94. //
  95. APT_Pointer,
  96. //
  97. // SID
  98. //
  99. APT_Sid,
  100. //
  101. // Logon ID (LUID)
  102. //
  103. APT_LogonId,
  104. //
  105. // Object Type List
  106. //
  107. APT_ObjectTypeList,
  108. //
  109. // Luid (not translated to LogonId)
  110. //
  111. APT_Luid,
  112. //
  113. // Guid
  114. //
  115. APT_Guid,
  116. //
  117. // Time (FILETIME)
  118. //
  119. APT_Time,
  120. //
  121. // ULONGLONG
  122. //
  123. APT_Int64
  124. );
  125. {$EXTERNALSYM _AUDIT_PARAM_TYPE}
  126. AUDIT_PARAM_TYPE = _AUDIT_PARAM_TYPE;
  127. {$EXTERNALSYM AUDIT_PARAM_TYPE}
  128. TAuditParamType = AUDIT_PARAM_TYPE;
  129. //
  130. // There are two types of flags that can be used with a parameter.
  131. //
  132. // - formatting flag
  133. // This defines the appearance of a parameter when
  134. // written to the eventlog. Such flags may become obsolete
  135. // when we move to WMI auditing.
  136. //
  137. // - control flag
  138. // This causes a specified action to be taken that affects
  139. // a parameter value.
  140. //
  141. // For example:
  142. // If you use the AP_PrimaryLogonId/AP_ClientLogonId flag,
  143. // the system will capture the logon-id from the process/thread token.
  144. //
  145. const
  146. AP_ParamTypeBits = 8;
  147. {$EXTERNALSYM AP_ParamTypeBits}
  148. AP_ParamTypeMask = $000000ff;
  149. {$EXTERNALSYM AP_ParamTypeMask}
  150. //
  151. // the flags values below have overlapping values. this is ok since
  152. // the scope of each flag is limited to the type to which it applies.
  153. //
  154. //
  155. // APT_Ulong : format flag : causes a number to appear in hex
  156. //
  157. AP_FormatHex = $0001 shl AP_ParamTypeBits;
  158. {$EXTERNALSYM AP_FormatHex}
  159. //
  160. // APT_Ulong : format flag : causes a number to be treated as access-mask.
  161. // The meaning of each bit depends on the associated
  162. // object type.
  163. //
  164. AP_AccessMask = $0002 shl AP_ParamTypeBits;
  165. {$EXTERNALSYM AP_AccessMask}
  166. //
  167. // APT_String : format flag : causes a string to be treated as a file-path
  168. //
  169. AP_Filespec = $0001 shl AP_ParamTypeBits;
  170. {$EXTERNALSYM AP_Filespec}
  171. //
  172. // APT_LogonId : control flag : logon-id is captured from the process token
  173. //
  174. AP_PrimaryLogonId = $0001 shl AP_ParamTypeBits;
  175. {$EXTERNALSYM AP_PrimaryLogonId}
  176. //
  177. // APT_LogonId : control flag : logon-id is captured from the thread token
  178. //
  179. AP_ClientLogonId = $0002 shl AP_ParamTypeBits;
  180. {$EXTERNALSYM AP_ClientLogonId}
  181. //
  182. // internal helper macros
  183. //
  184. // (rom) MACRO
  185. function ApExtractType(TypeFlags: DWORD): AUDIT_PARAM_TYPE;
  186. {$EXTERNALSYM ApExtractType}
  187. // (rom) MACRO
  188. function ApExtractFlags(TypeFlags: DWORD): DWORD;
  189. {$EXTERNALSYM ApExtractFlags}
  190. //
  191. // Element of an object-type-list
  192. //
  193. // The AUDIT_OBJECT_TYPES structure identifies an object type element
  194. // in a hierarchy of object types. The AccessCheckByType functions use
  195. // an array of such structures to define a hierarchy of an object and
  196. // its subobjects, such as property sets and properties.
  197. //
  198. type
  199. PAUDIT_OBJECT_TYPE = ^AUDIT_OBJECT_TYPE;
  200. {$EXTERNALSYM PAUDIT_OBJECT_TYPE}
  201. _AUDIT_OBJECT_TYPE = record
  202. ObjectType: GUID; // guid of the (sub)object
  203. Flags: USHORT; // currently not defined
  204. Level: USHORT; // level within the hierarchy.
  205. // 0 is the root level
  206. AccessMask: ACCESS_MASK; // access-mask for this (sub)object
  207. end;
  208. {$EXTERNALSYM _AUDIT_OBJECT_TYPE}
  209. AUDIT_OBJECT_TYPE = _AUDIT_OBJECT_TYPE;
  210. {$EXTERNALSYM AUDIT_OBJECT_TYPE}
  211. TAuditObjectType = AUDIT_OBJECT_TYPE;
  212. PAuditObjectType = PAUDIT_OBJECT_TYPE;
  213. PAUDIT_OBJECT_TYPES = ^AUDIT_OBJECT_TYPES;
  214. {$EXTERNALSYM PAUDIT_OBJECT_TYPES}
  215. _AUDIT_OBJECT_TYPES = record
  216. Count: USHORT; // number of object-types in pObjectTypes
  217. Flags: USHORT; // currently not defined
  218. pObjectTypes: PAUDIT_OBJECT_TYPE; // array of object-types
  219. end;
  220. {$EXTERNALSYM _AUDIT_OBJECT_TYPES}
  221. AUDIT_OBJECT_TYPES = _AUDIT_OBJECT_TYPES;
  222. {$EXTERNALSYM AUDIT_OBJECT_TYPES}
  223. TAuditObjectTypes = AUDIT_OBJECT_TYPES;
  224. PAuditObjectTypes = PAUDIT_OBJECT_TYPES;
  225. //
  226. // Structure that defines a single audit parameter.
  227. //
  228. // LsaGenAuditEvent accepts an array of such elements to
  229. // represent the parameters of the audit to be generated.
  230. //
  231. // It is best to initialize this structure using AdtInitParams function.
  232. // This will ensure compatibility with any future changes to this
  233. // structure.
  234. //
  235. type
  236. _AUDIT_PARAM = record
  237. Type_: AUDIT_PARAM_TYPE; // type
  238. Length: ULONG; // currently unused
  239. Flags: DWORD; // currently unused
  240. U: record
  241. case Integer of
  242. 0: (Data0: ULONG_PTR);
  243. 1: (String_: PWSTR);
  244. 2: (u: ULONG_PTR);
  245. 3: (psid: PSID);
  246. 4: (pguid: LPGUID);
  247. 5: (LogonId_LowPart: ULONG);
  248. 6: (pObjectTypes: PAUDIT_OBJECT_TYPES);
  249. end;
  250. case Integer of
  251. 0: (Data1: ULONG_PTR);
  252. 1: (LogonId_HighPart: LONG);
  253. end;
  254. {$EXTERNALSYM _AUDIT_PARAM}
  255. AUDIT_PARAM = _AUDIT_PARAM;
  256. {$EXTERNALSYM AUDIT_PARAM}
  257. PAUDIT_PARAM = ^AUDIT_PARAM;
  258. {$EXTERNALSYM PAUDIT_PARAM}
  259. TAuditParam = AUDIT_PARAM;
  260. PAuditParam = PAUDIT_PARAM;
  261. //
  262. // Audit control flags. To be used with AUDIT_PARAMS.Flags
  263. //
  264. const
  265. APF_AuditFailure = $00000000; // generate a failure audit
  266. {$EXTERNALSYM APF_AuditFailure}
  267. APF_AuditSuccess = $00000001; // generate a success audit when set, a failure audit otherwise.
  268. {$EXTERNALSYM APF_AuditSuccess}
  269. //
  270. // set of valid audit control flags
  271. //
  272. APF_ValidFlags = APF_AuditSuccess;
  273. {$EXTERNALSYM APF_ValidFlags}
  274. //
  275. // Audit parameters passed to LsaGenAuditEvent
  276. //
  277. type
  278. PAUDIT_PARAMS = ^AUDIT_PARAMS;
  279. {$EXTERNALSYM PAUDIT_PARAMS}
  280. _AUDIT_PARAMS = record
  281. Length: ULONG; // size in bytes
  282. Flags: DWORD; // currently unused
  283. Count: USHORT; // number of parameters
  284. Parameters: PAUDIT_PARAM; // array of parameters
  285. end;
  286. {$EXTERNALSYM _AUDIT_PARAMS}
  287. AUDIT_PARAMS = _AUDIT_PARAMS;
  288. {$EXTERNALSYM AUDIT_PARAMS}
  289. TAuditParams = AUDIT_PARAMS;
  290. PAuditParams = PAUDIT_PARAMS;
  291. //
  292. // Defines the elements of a legacy audit event.
  293. //
  294. PAUTHZ_AUDIT_EVENT_TYPE_LEGACY = ^AUTHZ_AUDIT_EVENT_TYPE_LEGACY;
  295. {$EXTERNALSYM PAUTHZ_AUDIT_EVENT_TYPE_LEGACY}
  296. _AUTHZ_AUDIT_EVENT_TYPE_LEGACY = record
  297. //
  298. // Audit category ID
  299. //
  300. CategoryId: USHORT;
  301. //
  302. // Audit event ID
  303. //
  304. AuditId: USHORT;
  305. //
  306. // Parameter count
  307. //
  308. ParameterCount: USHORT;
  309. end;
  310. {$EXTERNALSYM _AUTHZ_AUDIT_EVENT_TYPE_LEGACY}
  311. AUTHZ_AUDIT_EVENT_TYPE_LEGACY = _AUTHZ_AUDIT_EVENT_TYPE_LEGACY;
  312. {$EXTERNALSYM AUTHZ_AUDIT_EVENT_TYPE_LEGACY}
  313. TAuthzAuditEventTypeLegacy = AUTHZ_AUDIT_EVENT_TYPE_LEGACY;
  314. PAuthzAuditEventTypeLegacy = PAUTHZ_AUDIT_EVENT_TYPE_LEGACY;
  315. _AUTHZ_AUDIT_EVENT_TYPE_UNION = record
  316. case Integer of
  317. 0: (Legacy: AUTHZ_AUDIT_EVENT_TYPE_LEGACY);
  318. end;
  319. {$EXTERNALSYM _AUTHZ_AUDIT_EVENT_TYPE_UNION}
  320. AUTHZ_AUDIT_EVENT_TYPE_UNION = _AUTHZ_AUDIT_EVENT_TYPE_UNION;
  321. {$EXTERNALSYM AUTHZ_AUDIT_EVENT_TYPE_UNION}
  322. PAUTHZ_AUDIT_EVENT_TYPE_UNION = ^AUTHZ_AUDIT_EVENT_TYPE_UNION;
  323. {$EXTERNALSYM PAUTHZ_AUDIT_EVENT_TYPE_UNION}
  324. TAuthzAuditEventTypeUnion = AUTHZ_AUDIT_EVENT_TYPE_UNION;
  325. PAuthzAuditEventTypeUnion = PAUTHZ_AUDIT_EVENT_TYPE_UNION;
  326. //
  327. // description of an audit event
  328. //
  329. _AUTHZ_AUDIT_EVENT_TYPE_OLD = record
  330. // version number
  331. Version: ULONG;
  332. dwFlags: DWORD;
  333. RefCount: LONG;
  334. hAudit: ULONG_PTR;
  335. LinkId: LUID;
  336. u: AUTHZ_AUDIT_EVENT_TYPE_UNION;
  337. end;
  338. {$EXTERNALSYM _AUTHZ_AUDIT_EVENT_TYPE_OLD}
  339. AUTHZ_AUDIT_EVENT_TYPE_OLD = _AUTHZ_AUDIT_EVENT_TYPE_OLD;
  340. {$EXTERNALSYM AUTHZ_AUDIT_EVENT_TYPE_OLD}
  341. TAuthzAuditEventTypeOld = AUTHZ_AUDIT_EVENT_TYPE_OLD;
  342. PAuthzAuditEventTypeOld = ^AUTHZ_AUDIT_EVENT_TYPE_OLD;
  343. PAUTHZ_AUDIT_EVENT_TYPE_OLD = ^AUTHZ_AUDIT_EVENT_TYPE_OLD;
  344. {$EXTERNALSYM PAUTHZ_AUDIT_EVENT_TYPE_OLD}
  345. AUDIT_HANDLE = PVOID;
  346. {$EXTERNALSYM AUDIT_HANDLE}
  347. PAUDIT_HANDLE = ^AUDIT_HANDLE;
  348. {$EXTERNALSYM PAUDIT_HANDLE}
  349. (* todo
  350. function AuthzpRegisterAuditEvent(pAuditEventType: PAUTHZ_AUDIT_EVENT_TYPE_OLD; var phAuditContext: AUDIT_HANDLE): BOOL; stdcall;
  351. {$EXTERNALSYM AuthzpRegisterAuditEvent}
  352. function AuthzpUnregisterAuditEvent(var phAuditContext: AUDIT_HANDLE): BOOL; stdcall;
  353. {$EXTERNALSYM AuthzpUnregisterAuditEvent}
  354. *)
  355. //
  356. // Begin support for extensible auditing.
  357. //
  358. const
  359. AUTHZ_ALLOW_MULTIPLE_SOURCE_INSTANCES = $1;
  360. {$EXTERNALSYM AUTHZ_ALLOW_MULTIPLE_SOURCE_INSTANCES}
  361. AUTHZ_AUDIT_INSTANCE_INFORMATION = $2;
  362. {$EXTERNALSYM AUTHZ_AUDIT_INSTANCE_INFORMATION}
  363. implementation
  364. uses
  365. JwaWinDLLNames;
  366. // (rom) MACRO implementation
  367. function ApExtractType(TypeFlags: DWORD): AUDIT_PARAM_TYPE;
  368. begin
  369. Result := AUDIT_PARAM_TYPE(TypeFlags and AP_ParamTypeMask);
  370. end;
  371. // (rom) MACRO implementation
  372. function ApExtractFlags(TypeFlags: DWORD): DWORD;
  373. begin
  374. Result := TypeFlags and not AP_ParamTypeMask;
  375. end;
  376. {
  377. AuthzpRegisterAuditEvent
  378. AuthzpUnregisterAuditEvent
  379. }
  380. end.