jwaadtgen.pas 13 KB

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