Skip to main content

endpoint_sec_sys/
message.rs

1//! Corresponding header: `EndpointSecurity/ESMessage.h`
2//!
3//! Messages for an event are received when clients are subscribed to their related event, either
4//! auth or notify.
5
6// Types and methods should be added in the same order as they are in the original header to make
7// maintenance easier.
8
9use core::hash::Hash;
10use core::mem::ManuallyDrop;
11pub use std::os::raw::c_int;
12
13#[cfg(feature = "macos_13_0_0")]
14pub use libc::{cpu_subtype_t, cpu_type_t};
15pub use libc::{dev_t, gid_t, mode_t, pid_t, stat, statfs, timespec, timeval, uid_t};
16#[cfg(feature = "macos_14_0_0")]
17use mach2::mach_types::uuid_t;
18#[cfg(feature = "objc2")]
19use objc2::{Encoding, RefEncode};
20
21#[cfg(feature = "macos_10_15_4")]
22use super::es_proc_check_type_t;
23use super::{
24    ShouldNotBeNull, attrlist, audit_token_t, es_action_type_t, es_auth_result_t, es_cdhash_t, es_event_id_t,
25    es_event_type_t, es_result_type_t, es_string_token_t, es_token_t, user_addr_t, user_size_t,
26};
27#[cfg(feature = "macos_10_15_1")]
28use super::{acl_t, es_set_or_clear_t};
29#[cfg(feature = "macos_13_0_0")]
30use super::{es_address_type_t, es_authentication_type_t};
31#[cfg(feature = "macos_14_0_0")]
32use super::{
33    es_authorization_rule_class_t, es_od_account_type_t, es_od_member_type_t, es_od_record_type_t,
34    es_sudo_plugin_type_t, es_xpc_domain_type_t,
35};
36#[cfg(feature = "macos_15_0_0")]
37use super::{es_gatekeeper_user_override_file_type_t, es_sha256_t, es_signed_file_info_t};
38#[cfg(feature = "macos_15_4_0")]
39use super::{es_tcc_authorization_reason_t, es_tcc_authorization_right_t, es_tcc_event_type_t, es_tcc_identity_type_t};
40
41/// Provides the [`stat`][struct@stat] information and path to a file that relates to a security
42/// event. The path may be truncated, which is indicated by the `path_truncated` flag.
43///
44/// For the FAT family of filesystems the `stat.st_ino` field is set to 999999999 for empty files.
45///
46/// For files with a link count greater than 1, the absolute path given may not be the only absolute
47/// path that exists, and which hard link the emitted path points to is undefined.
48///
49/// Overlong paths are truncated at a maximum length that currently is 16K, though that number is
50/// not considered API and may change at any time.
51#[repr(C)]
52pub struct es_file_t {
53    /// Absolute path of the file
54    pub path: es_string_token_t,
55    /// Indicates if the `path` field was truncated
56    pub path_truncated: bool,
57    /// Informations about the file. See `man 2 stat` for details
58    pub stat: stat,
59}
60
61/// Information related to a thread
62#[cfg(feature = "macos_11_0_0")]
63#[repr(C)]
64#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
65pub struct es_thread_t {
66    /// Unique of the thread
67    pub thread_id: u64,
68}
69
70/// Information related to a process. This is used both for describing processes that performed an
71/// action (e.g. in the case of the [`es_message_t.process`] field, or are targets of an action (e.g.
72/// for exec events this describes the new process being executed, for signal events this describes
73/// the process that will receive the signal).
74///
75/// Values such as `pid`, `pidversion`, `uid`, `gid`, etc. can be extracted from audit tokens using
76/// API provided in `libbsm.h`.
77///
78/// ### Identifying unique process execution on a single machine
79///
80/// The tuple `(pid, pidversion)` identifies a specific process execution, and should be used to
81/// link events to the process that emitted them. Executing an executable image in a process using
82/// the `exec` or `posix_spawn` family of syscalls increments the `pidversion`. However, `(pid,
83/// pidversion)` is not meant to be unique across reboots or across multiple systems.
84///
85/// ### Multiple ES clients
86///
87/// Clients should take caution when processing events where `is_es_client` is true. If multiple ES
88/// clients exist, actions taken by one client could trigger additional actions by the other client,
89/// causing a potentially infinite cycle.
90///
91/// ### Code signing
92///
93/// Fields related to code signing in the target `es_process_t` reflect the state of the process
94/// at the time the message is generated. In the specific case of exec, this is after the exec
95/// completed in the kernel, but before any code in the process has started executing. At that
96/// point, XNU has validated the signature itself and has verified that the `CDHash` is correct
97/// in that the hash of all the individual page hashes in the Code Directory matches the signed
98/// `CDHash`, essentially verifying the signature was not tampered with. However, individual page
99/// hashes are not verified by XNU until the corresponding pages are paged in once they are accessed
100/// while the binary executes. It is not until the individual pages are paged in that XNU determines
101/// if a binary has been tampered with and will update the code signing flags accordingly.
102///
103/// Endpoint Security provides clients the current state of the CS flags in the `codesigning_flags`
104/// member of the `es_process_t` struct. The `CS_VALID` bit in the `codesigning_flags` means that
105/// everything the kernel has validated **up to that point in time** was valid, but not that there
106/// has been a full validation of all the pages in the executable file. If page content has been
107/// tampered with in the executable, we won't know until that page is paged in. At that time, the
108/// process will have its `CS_VALID` bit cleared and, if `CS_KILL` is set, the process will be
109/// killed, preventing any tampered code from being executed.
110///
111/// `CS_KILL` is generally set for platform binaries and for binaries having opted into the hardened
112/// runtime. An ES client wishing to detect tampered code before it is paged in, for example at
113/// exec time, can use the Security framework to do so, but should be cautious of the potentially
114/// significant performance cost. The Endpoint Security subsystem itself has no role in verifying
115/// the validity of code signatures.
116#[repr(C)]
117pub struct es_process_t {
118    /// Audit token of the process
119    pub audit_token: audit_token_t,
120    /// Parent pid of the process. It is recommended to instead use the `parent_audit_token` field.
121    pub ppid: pid_t,
122    /// Original ppid of the process. This field stays constant even in the event this process is
123    /// reparented.
124    pub original_ppid: pid_t,
125    /// Process group id the process belongs to
126    pub group_id: pid_t,
127    /// Session id the process belongs to
128    pub session_id: pid_t,
129    /// Code signing flags of the process. The values for these flags can be found in the include
130    /// file `cs_blobs.h` (`#include <kern/cs_blobs.h>`).
131    pub codesigning_flags: u32,
132    pub is_platform_binary: bool,
133    /// Indicates this process has the Endpoint Security entitlement
134    pub is_es_client: bool,
135    /// The code directory hash of the code signature associated with this process
136    pub cdhash: es_cdhash_t,
137    /// The signing id of the code signature associated with this process
138    pub signing_id: es_string_token_t,
139    /// The team id of the code signature associated with this process
140    pub team_id: es_string_token_t,
141    /// The executable file that is executing in this process.
142    pub executable: ShouldNotBeNull<es_file_t>,
143    /// The TTY this process is associated with, or NULL if the process does not have an associated
144    /// TTY. The TTY is a property of the POSIX session the process belongs to. A process' session
145    /// may be associated with a TTY independently from whether its stdin or any other file
146    /// descriptors point to a TTY device (as per `isatty(3)`, `tty(1)`).
147    ///
148    /// Field available only if message version >= 2.
149    #[cfg(feature = "macos_10_15_1")]
150    pub tty: *mut es_file_t,
151    /// Process start time, i.e. time of fork creating this process.
152    ///
153    /// Field available only if message version >= 3.
154    #[cfg(feature = "macos_10_15_4")]
155    pub start_time: timeval,
156    /// Audit token of the process responsible for this process, which may be the process itself in
157    /// case there is no responsible process or the responsible process has already exited.
158    ///
159    /// Field available only if message version >= 4.
160    #[cfg(feature = "macos_11_0_0")]
161    pub responsible_audit_token: audit_token_t,
162    /// Audit token of the parent process.
163    ///
164    /// Field available only if message version >= 4.
165    #[cfg(feature = "macos_11_0_0")]
166    pub parent_audit_token: audit_token_t,
167}
168
169should_not_be_null_fields!(es_process_t; executable -> es_file_t);
170#[cfg(feature = "macos_10_15_1")]
171null_fields!(es_process_t; tty -> es_file_t);
172
173/// Machine-specific thread state as used by `thread_create_running` and other Mach API functions.
174///
175/// The `size` subfield of the `state` field is in bytes, NOT `natural_t` units. Definitions for
176/// working with thread state can be found in the include file `mach/thread_status.h` and
177/// corresponding machine-dependent headers.
178#[cfg(feature = "macos_11_0_0")]
179#[repr(C)]
180pub struct es_thread_state_t {
181    /// Representation of the machine-specific thread state
182    pub flavor: c_int,
183    /// Machine-specific thread state, equivalent to `thread_state_t` in Mach APIs
184    pub state: es_token_t,
185}
186
187/// An open file descriptor
188#[cfg(feature = "macos_11_0_0")]
189#[repr(C)]
190#[derive(Copy, Clone)]
191pub struct es_fd_t {
192    /// File descriptor number
193    pub fd: i32,
194    /// File descriptor type, as `libproc` fdtype
195    pub fdtype: u32,
196    /// Available if `fdtype` is [`Self::PROX_FDTYPE_PIPE`]
197    pub anon_0: es_fd_t_anon_0,
198}
199
200#[cfg(feature = "macos_11_0_0")]
201impl es_fd_t {
202    /// Helper constant when checking if `anon_0` is valid by looking at `fdtype`
203    pub const PROX_FDTYPE_PIPE: u32 = 6;
204
205    /// Access the `pipe` member of [`es_fd_t_anon_0`] if `fdtype` is [`Self::PROX_FDTYPE_PIPE`].
206    ///
207    /// # Safety
208    ///
209    /// The `fdtype` and `anon_0` fields must be kept in sync.
210    pub unsafe fn pipe(&self) -> Option<es_fd_t_anon_0_pipe> {
211        if self.fdtype == Self::PROX_FDTYPE_PIPE {
212            // Safety: we checked `fdtype` for the correct value just before and the caller
213            // guarantees the fields are synced
214            Some(unsafe { self.anon_0.pipe })
215        } else {
216            None
217        }
218    }
219}
220
221/// See [`es_fd_t_anon_0.anon_0`]
222#[cfg(feature = "macos_11_0_0")]
223#[repr(C)]
224#[derive(Copy, Clone)]
225pub union es_fd_t_anon_0 {
226    pub pipe: es_fd_t_anon_0_pipe,
227}
228
229/// Pipe information available in [`es_fd_t`] if the `fdtype` field is `PROX_FDTYPE_PIPE`
230///
231/// See [`es_fd_t_anon_0_pipe.pipe`]
232#[cfg(feature = "macos_11_0_0")]
233#[repr(C)]
234#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
235pub struct es_fd_t_anon_0_pipe {
236    /// Unique id of the pipe for correlation with other file descriptors pointing to the same or
237    /// other end of the same pipe
238    pub pipe_id: u64,
239}
240
241#[cfg(feature = "macos_13_0_0")]
242ffi_wrap_enum!(
243    /// Type of launch item.
244    ///
245    /// See [`es_btm_launch_item_t`]
246    es_btm_item_type_t(u32);
247
248    == #[cfg(feature = "macos_13_0_0")] 13_0_0 "13.0.0";
249    ES_BTM_ITEM_TYPE_USER_ITEM = 0,
250    ES_BTM_ITEM_TYPE_APP = 1,
251    ES_BTM_ITEM_TYPE_LOGIN_ITEM = 2,
252    ES_BTM_ITEM_TYPE_AGENT = 3,
253    --
254    ES_BTM_ITEM_TYPE_DAEMON = 4,
255);
256
257/// Structure describing a BTM launch item
258#[cfg(feature = "macos_13_0_0")]
259#[repr(C)]
260pub struct es_btm_launch_item_t {
261    /// Type of launch item.
262    pub item_type: es_btm_item_type_t,
263    /// True only if item is a legacy plist.
264    pub legacy: bool,
265    /// True only if item is managed by MDM.
266    pub managed: bool,
267    /// User ID for the item (may be user `nobody` (`-2`)).
268    pub uid: uid_t,
269    /// URL for item.
270    ///
271    /// If a file URL describing a relative path, it is relative to `app_url`.
272    pub item_url: es_string_token_t,
273    /// Optional. URL for app the item is attributed to.
274    // NOTE: find out how optionality is modeled. Empty string ? Linked to an enum member ?
275    pub app_url: es_string_token_t,
276}
277
278#[cfg(feature = "macos_14_0_0")]
279ffi_wrap_enum!(
280    /// Source of profile installation (MDM/Manual Install).
281    ///
282    /// See [`es_profile_t`]
283    es_profile_source_t(u32);
284
285    == #[cfg(feature = "macos_14_0_0")] 14_0_0 "14.0.0";
286    /// MDM (managed) installation
287    ES_PROFILE_SOURCE_MANAGED = 0,
288    --
289    /// Manual installation
290    ES_PROFILE_SOURCE_INSTALL = 1,
291);
292
293#[cfg(feature = "macos_14_0_0")]
294#[repr(C)]
295pub struct es_profile_t {
296    /// Profile identifier
297    pub identifier: es_string_token_t,
298    /// Profile UUID
299    pub uuid: es_string_token_t,
300    /// Source of Profile installation (MDM/Manual Install)
301    pub install_source: es_profile_source_t,
302    /// Profile organization name
303    pub organization: es_string_token_t,
304    /// Profile display name
305    pub display_name: es_string_token_t,
306    /// Profile scope
307    pub scope: es_string_token_t,
308}
309
310/// Execute a new process
311///
312/// Process arguments, environment variables and file descriptors are packed, use API functions
313/// to access them: [`es_exec_arg()`], [`es_exec_arg_count()`], [`es_exec_env()`],
314/// [`es_exec_env_count()`],
315#[cfg_attr(feature = "macos_11_0_0", doc = "[`es_exec_fd()`] and [`es_exec_fd_count()`].")]
316#[cfg_attr(not(feature = "macos_11_0_0"), doc = "`es_exec_fd()` and `es_exec_fd_count()`.")]
317///
318/// The API may only return descriptions for a subset of open file descriptors; how many and
319/// which file descriptors are available as part of exec events is not considered API and can change
320/// in future releases.
321///
322/// The CPU type and subtype correspond to `CPU_TYPE_*` and `CPU_SUBTYPE_*` macros defined in
323/// `<mach/machine.h>`.
324///
325/// Fields related to code signing in `target` represent kernel state for the process at the
326/// point in time the exec has completed, but the binary has not started running yet. Because code
327/// pages are not validated until they are paged in, this means that modifications to code pages
328/// would not have been detected yet at this point. For a more thorough explanation, please see the
329/// documentation for [`es_process_t`].
330///
331/// There are two [`es_process_t`] fields that are represented in an [`es_message_t`] that
332/// contains an `es_event_exec_t`. The `es_process_t` within the `es_message_t` struct (named
333/// `process`) contains information about the program that calls `execve(2)` (or `posix_spawn(2)`).
334/// This information is gathered prior to the program being replaced. The other `es_process_t`,
335/// within the `es_event_exec_t` struct (named `target`), contains information about the program
336/// after the image has been replaced by `execve(2)` (or `posix_spawn(2)`). This means that both
337/// `es_process_t` structs refer to the same process (as identified by pid), but not necessarily the
338/// same program, and definitely not the same program execution (as identified by pid, pidversion
339/// tuple). The `audit_token_t` structs contained in the two different `es_process_t` structs will
340/// not be identical: the `pidversion` field will be updated, and the UID/GID values may be
341/// different if the new program had `setuid`/`setgid` permission bits set.
342///
343/// Cache key for this event type: `(process executable file, target executable file)`.
344#[repr(C)]
345// 10.15.0
346pub struct es_event_exec_t {
347    /// The new process that is being executed
348    pub target: ShouldNotBeNull<es_process_t>,
349    /// This field must not be accessed directly (see notes)
350    #[cfg(not(feature = "macos_13_3_0"))]
351    _reserved0: es_token_t,
352    /// The exec path passed up to dyld, before symlink resolution. This is the path argument
353    /// to `execve(2)` or `posix_spawn(2)`, or the interpreter from the shebang line for scripts run
354    /// through the shell script image activator.
355    ///
356    /// Field available only if message version >= 7.
357    #[cfg(feature = "macos_13_3_0")]
358    pub dyld_exec_path: es_string_token_t,
359    /// See variants of union
360    pub anon_0: es_event_exec_t_anon_0,
361}
362
363should_not_be_null_fields!(es_event_exec_t; target -> es_process_t);
364
365/// See [`es_event_exec_t.anon_0`]
366#[repr(C)]
367pub union es_event_exec_t_anon_0 {
368    _reserved: [u8; 64],
369    #[cfg(feature = "macos_10_15_1")]
370    pub anon_0: ManuallyDrop<es_event_exec_t_anon_0_anon_0>,
371}
372
373/// See [`es_event_exec_t_anon_0.anon_0`]
374#[repr(C)]
375pub struct es_event_exec_t_anon_0_anon_0 {
376    /// Script being executed by interpreter. This field is only valid if a script was executed
377    /// directly and not as an argument to the interpreter (e.g. `./foo.sh` not `/bin/sh ./foo.sh`)
378    ///
379    /// Field available only if message version >= 2.
380    #[cfg(feature = "macos_10_15_1")]
381    pub script: *mut es_file_t,
382    /// Current working directory at exec time.
383    ///
384    /// Field available only if message version >= 3.
385    #[cfg(feature = "macos_10_15_4")]
386    pub cwd: ShouldNotBeNull<es_file_t>,
387    /// Highest open file descriptor after the exec completed. This number is equal to or
388    /// larger than the highest number of file descriptors available via [`es_exec_fd_count()`] and
389    /// [`es_exec_fd()`], in which case EndpointSecurity has capped the number of file descriptors
390    /// available in the message. File descriptors for open files are not necessarily contiguous.
391    /// The exact number of open file descriptors is not available.
392    ///
393    /// Field available only if message version >= 4.
394    #[cfg(feature = "macos_11_0_0")]
395    pub last_fd: c_int,
396
397    /// The CPU type of the executable image which is being executed. In case of translation, this
398    /// may be a different architecture than the one of the system.
399    ///
400    /// Field available only if message version >= 6.
401    #[cfg(feature = "macos_13_0_0")]
402    pub image_cputype: cpu_type_t,
403    /// The CPU subtype of the executable image.
404    ///
405    /// Field available only if message version >= 6.
406    #[cfg(feature = "macos_13_0_0")]
407    pub image_cpusubtype: cpu_subtype_t,
408}
409
410#[cfg(feature = "macos_10_15_4")]
411should_not_be_null_fields!(es_event_exec_t_anon_0_anon_0; cwd -> es_file_t);
412#[cfg(feature = "macos_10_15_1")]
413null_fields!(es_event_exec_t_anon_0_anon_0; script -> es_file_t);
414
415/// Open a file system object.
416///
417/// The `fflag` field represents the mask as applied by the kernel, not as represented by
418/// typical `open(2)` `oflag` values. When responding to `ES_EVENT_TYPE_AUTH_OPEN` events using
419/// [`es_respond_flags_result()`][super::es_respond_flags_result], ensure that the same `FFLAG`
420/// values are used (e.g. `FREAD`, `FWRITE` instead of `O_RDONLY`, `O_RDWR`, etc...).
421///
422/// Cache key for this event type: `(process executable file, file that will be opened)`.
423///
424/// See `fcntl.h`
425#[repr(C)]
426// 10.15.0
427pub struct es_event_open_t {
428    /// The desired flags to be used when opening `file` (see note)
429    pub fflag: i32,
430    /// The file that will be opened
431    pub file: ShouldNotBeNull<es_file_t>,
432    _reserved: [u8; 64],
433}
434
435should_not_be_null_fields!(es_event_open_t; file -> es_file_t);
436
437/// Load a kernel extension
438///
439/// This event type does not support caching.
440///
441/// Not all AUTH_KEXTLOAD events can be delivered. In rare circumstances, when
442/// kextloading is blocking all userspace execution it will be automatically
443/// allowed. NOTIFY_KEXTLOAD will still be (eventually) delivered.
444#[repr(C)]
445// 10.15.0
446pub struct es_event_kextload_t {
447    /// The signing identifier of the kext being loaded
448    pub identifier: es_string_token_t,
449    _reserved: [u8; 64],
450}
451
452/// Unload a kernel extension
453///
454/// This event type does not support caching (notify-only).
455#[repr(C)]
456// 10.15.0
457pub struct es_event_kextunload_t {
458    /// The signing identifier of the kext being unloaded
459    pub identifier: es_string_token_t,
460    _reserved: [u8; 64],
461}
462
463/// Unlink a file system object.
464///
465/// This event can fire multiple times for a single syscall, for example when the syscall has to be
466/// retried due to racing VFS operations.
467///
468/// This event type does not support caching.
469#[repr(C)]
470// 10.15.0
471pub struct es_event_unlink_t {
472    /// The object that will be removed
473    pub target: ShouldNotBeNull<es_file_t>,
474    /// The parent directory of the `target` file system object
475    pub parent_dir: ShouldNotBeNull<es_file_t>,
476    _reserved: [u8; 64],
477}
478
479should_not_be_null_fields!(es_event_unlink_t; target -> es_file_t, parent_dir -> es_file_t);
480
481/// Memory map a file
482///
483/// Cache key for this event type: `(process executable file, source file)`.
484#[repr(C)]
485// 10.15.0
486pub struct es_event_mmap_t {
487    /// The protection (region accessibility) value
488    pub protection: i32,
489    /// The maximum allowed protection value the operating system will respect
490    pub max_protection: i32,
491    /// The type and attributes of the mapped file
492    pub flags: i32,
493    /// The offset into `source` that will be mapped
494    pub file_pos: u64,
495    /// The file system object being mapped
496    pub source: ShouldNotBeNull<es_file_t>,
497    _reserved: [u8; 64],
498}
499
500should_not_be_null_fields!(es_event_mmap_t; source -> es_file_t);
501
502/// Link to a file
503///
504/// This event type does not support caching.
505#[repr(C)]
506// 10.15.0
507pub struct es_event_link_t {
508    /// The existing object to which a hard link will be created
509    pub source: ShouldNotBeNull<es_file_t>,
510    /// The directory in which the link will be created
511    pub target_dir: ShouldNotBeNull<es_file_t>,
512    /// The name of the new object linked to `source`
513    pub target_filename: es_string_token_t,
514    _reserved: [u8; 64],
515}
516
517should_not_be_null_fields!(es_event_link_t; source -> es_file_t, target_dir -> es_file_t);
518
519#[cfg(feature = "macos_15_0_0")]
520ffi_wrap_enum!(
521    /// The type of device being mounted.
522    ///
523    /// See [`es_event_mount_t`]
524    es_mount_disposition_t(u32);
525
526    == #[cfg(feature = "macos_15_0_0")] 15_0_0 "15.0.0";
527    /// Device is external storage.
528    ES_MOUNT_DISPOSITION_EXTERNAL = 0,
529    /// Device is internal storage.
530    ES_MOUNT_DISPOSITION_INTERNAL = 1,
531    /// Device is a network share.
532    ES_MOUNT_DISPOSITION_NETWORK = 2,
533    /// Device is virtual (dmg or file).
534    ES_MOUNT_DISPOSITION_VIRTUAL = 3,
535    /// Mount uses nullfs, commonly for app translocation
536    ES_MOUNT_DISPOSITION_NULLFS = 4,
537    --
538    /// unable to determine disposition
539    ES_MOUNT_DISPOSITION_UNKNOWN = 5,
540);
541
542/// Mount a file system
543///
544/// Cache key for this event type: `(process executable file, mount point)`.
545#[repr(C)]
546// 10.15.0
547pub struct es_event_mount_t {
548    /// The file system stats for the file system being mounted
549    pub statfs: ShouldNotBeNull<statfs>,
550    /// The device disposition of the f_mntfromname.
551    ///
552    /// Field available only if message version >= 8.
553    #[cfg(feature = "macos_15_0_0")]
554    pub disposition: es_mount_disposition_t,
555    _reserved: [u8; 60],
556}
557
558should_not_be_null_fields!(es_event_mount_t; statfs -> statfs);
559
560/// Unmount a file system
561///
562/// This event type does not support caching (notify-only).
563#[repr(C)]
564// 10.15.0
565pub struct es_event_unmount_t {
566    /// The file system stats for the file system being unmounted
567    pub statfs: ShouldNotBeNull<statfs>,
568    _reserved: [u8; 64],
569}
570
571should_not_be_null_fields!(es_event_unmount_t; statfs -> statfs);
572
573/// Remount a file system
574///
575/// This event type does not support caching.
576#[cfg(feature = "macos_10_15_1")]
577#[repr(C)]
578pub struct es_event_remount_t {
579    /// The file system stats for the file system being remounted
580    pub statfs: ShouldNotBeNull<statfs>,
581    /// The provided remount flags.
582    ///
583    /// Field available only if message version >= 8.
584    #[cfg(feature = "macos_15_0_0")]
585    pub remount_flags: u64,
586    /// The device disposition of the f_mntfromname.
587    ///
588    /// Field available only if message version >= 8.
589    #[cfg(feature = "macos_15_0_0")]
590    pub disposition: es_mount_disposition_t,
591    _reserved: [u8; 52],
592}
593
594#[cfg(feature = "macos_10_15_1")]
595should_not_be_null_fields!(es_event_remount_t; statfs -> statfs);
596
597/// Fork a new process
598///
599/// This event type does not support caching (notify-only).
600#[repr(C)]
601// 10.15.0
602pub struct es_event_fork_t {
603    /// The child process that was created
604    pub child: ShouldNotBeNull<es_process_t>,
605    _reserved: [u8; 64],
606}
607
608should_not_be_null_fields!(es_event_fork_t; child -> es_process_t);
609
610/// Control protection of pages
611///
612/// This event type does not support caching.
613#[repr(C)]
614#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
615// 10.15.0
616pub struct es_event_mprotect_t {
617    /// The desired new protection value
618    pub protection: i32,
619    /// The base address to which the protection value will apply
620    pub address: user_addr_t,
621    /// The size of the memory region the protection value will apply
622    pub size: user_size_t,
623    _reserved: [u8; 64],
624}
625
626/// Send a signal to a process.
627///
628/// Signals may be sent on behalf of another process or directly. Notably
629/// launchd often sends signals on behalf of another process for service start/
630/// stop operations. If this is the case an instigator will be provided. The
631/// relationship between each process is illustrated below:
632///
633/// Delegated Signal:
634///
635/// ```
636/// Instigator Process -> IPC to Sender Process (launchd) -> Target Process
637/// ```
638///
639/// Direct Signal:
640///
641/// ```
642/// Sender Process -> Target Process
643/// ```
644///
645/// Clients may wish to block delegated signals from launchd for non-authorized
646/// instigators, while still allowing direct signals initiated by launchd for
647/// shutdown/reboot/restart.
648///
649/// This event will not fire if a process sends a signal to itself.
650///
651/// This event does not support caching on macos 15.4+. On previous versions,
652/// cache key is (process executable file, target process executable file).
653///
654/// Be aware of the nullability of some of the fiels. The instigator may not be
655/// applicable.
656#[repr(C)]
657// 10.15.0
658pub struct es_event_signal_t {
659    /// The signal number to be delivered
660    pub sig: c_int,
661    /// The process that will receive the signal
662    pub target: ShouldNotBeNull<es_process_t>,
663    /// Process information for the instigator (if applicable).
664    ///
665    /// Field available only if message version >= 9.
666    #[cfg(feature = "macos_15_4_0")]
667    pub instigator: *mut es_process_t,
668    _reserved: [u8; 56],
669}
670
671should_not_be_null_fields!(es_event_signal_t; target -> es_process_t);
672#[cfg(feature = "macos_15_4_0")]
673null_fields!(es_event_signal_t; instigator -> es_process_t);
674
675ffi_wrap_enum!(
676    es_destination_type_t(u32);
677
678    == MACOS_10_15_0;
679    ES_DESTINATION_TYPE_EXISTING_FILE = 0,
680    --
681    ES_DESTINATION_TYPE_NEW_PATH = 1,
682);
683
684/// Rename a file system object.
685///
686/// The `destination_type` field describes which member in the `destination` union should
687/// accessed. `ES_DESTINATION_TYPE_EXISTING_FILE` means that `existing_file` should be used,
688/// `ES_DESTINATION_TYPE_NEW_PATH` means that the `new_path` struct should be used.
689///
690/// This event can fire multiple times for a single syscall, for example when the syscall has to be
691/// retried due to racing VFS operations.
692///
693/// This event type does not support caching.
694#[repr(C)]
695// 10.15.0
696pub struct es_event_rename_t {
697    /// The source file that is being renamed
698    pub source: ShouldNotBeNull<es_file_t>,
699    /// Whether or not the destination refers to an existing or new file
700    pub destination_type: es_destination_type_t,
701    /// Information about the destination of the renamed file (see note)
702    pub destination: es_event_rename_t_anon_0,
703    _reserved: [u8; 64],
704}
705
706should_not_be_null_fields!(es_event_rename_t; source -> es_file_t);
707
708/// See [`es_event_rename_t`]
709#[repr(C)]
710pub union es_event_rename_t_anon_0 {
711    /// The destination file that will be overwritten
712    pub existing_file: ShouldNotBeNull<es_file_t>,
713    /// Information regarding the destination of a newly created file
714    pub new_path: ManuallyDrop<es_event_rename_t_anon_0_anon_0>,
715}
716
717/// See [`es_event_rename_t_anon_0`]
718#[repr(C)]
719pub struct es_event_rename_t_anon_0_anon_0 {
720    /// The directory into which the file will be renamed
721    pub dir: ShouldNotBeNull<es_file_t>,
722    /// The name of the new file that will be created
723    pub filename: es_string_token_t,
724}
725
726should_not_be_null_fields!(es_event_rename_t_anon_0_anon_0; dir -> es_file_t);
727
728/// Set an extended attribute
729///
730/// This event type does not support caching.
731#[repr(C)]
732// 10.15.0
733pub struct es_event_setextattr_t {
734    /// The file for which the extended attribute will be set
735    pub target: ShouldNotBeNull<es_file_t>,
736    /// The extended attribute which will be set
737    pub extattr: es_string_token_t,
738    _reserved: [u8; 64],
739}
740
741should_not_be_null_fields!(es_event_setextattr_t; target -> es_file_t);
742
743/// Retrieve an extended attribute
744///
745/// Cache key for this event type: `(process executable file, target file)`.
746#[cfg(feature = "macos_10_15_1")]
747#[repr(C)]
748pub struct es_event_getextattr_t {
749    /// The file for which the extended attribute will be retrieved
750    pub target: ShouldNotBeNull<es_file_t>,
751    /// The extended attribute which will be retrieved
752    pub extattr: es_string_token_t,
753    _reserved: [u8; 64],
754}
755
756#[cfg(feature = "macos_10_15_1")]
757should_not_be_null_fields!(es_event_getextattr_t; target -> es_file_t);
758
759/// Delete an extended attribute
760///
761/// This event type does not support caching.
762#[cfg(feature = "macos_10_15_1")]
763#[repr(C)]
764pub struct es_event_deleteextattr_t {
765    /// The file for which the extended attribute will be deleted
766    pub target: ShouldNotBeNull<es_file_t>,
767    /// The extended attribute which will be deleted
768    pub extattr: es_string_token_t,
769    _reserved: [u8; 64],
770}
771
772#[cfg(feature = "macos_10_15_1")]
773should_not_be_null_fields!(es_event_deleteextattr_t; target -> es_file_t);
774
775/// Modify file mode.
776///
777/// The `mode` member is the desired new mode. The `target` member's `stat` information contains the
778/// current mode.
779///
780/// Cache key for this event type: `(process executable file, target file)`.
781#[repr(C)]
782// 10.15.0
783pub struct es_event_setmode_t {
784    /// The desired new mode
785    pub mode: mode_t,
786    /// The file for which mode information will be modified
787    pub target: ShouldNotBeNull<es_file_t>,
788    _reserved: [u8; 64],
789}
790
791should_not_be_null_fields!(es_event_setmode_t; target -> es_file_t);
792
793/// Modify file flags information.
794///
795/// The `flags` member is the desired set of new flags. The `target` member's `stat` information
796/// contains the current set of flags.
797///
798/// Cache key for this event type: `(process executable file, target file)`.
799#[repr(C)]
800// 10.15.0
801pub struct es_event_setflags_t {
802    /// The desired new flags
803    pub flags: u32,
804    /// The file for which flags information will be modified
805    pub target: ShouldNotBeNull<es_file_t>,
806    _reserved: [u8; 64],
807}
808
809should_not_be_null_fields!(es_event_setflags_t; target -> es_file_t);
810
811/// Modify file owner information
812///
813/// The `uid` and `gid` members are the desired new values. The `target` member's `stat`
814/// information contains the current uid and gid values.
815///
816/// Cache key for this event type: `(process executable file, target file)`.
817#[repr(C)]
818// 10.15.0
819pub struct es_event_setowner_t {
820    /// The desired new UID
821    pub uid: uid_t,
822    /// The desired new GID
823    pub gid: gid_t,
824    /// The file for which owner information will be modified
825    pub target: ShouldNotBeNull<es_file_t>,
826    _reserved: [u8; 64],
827}
828
829should_not_be_null_fields!(es_event_setowner_t; target -> es_file_t);
830
831/// Close a file descriptor
832///
833/// This event type does not support caching (notify-only).
834#[repr(C)]
835// 10.15.0
836pub struct es_event_close_t {
837    /// Set to `true` if the target file being closed has been modified
838    ///
839    /// The `modified` flag only reflects that a file was or was not modified by filesystem syscall.
840    /// If a file was only modifed though a memory mapping this flag will be `false`, but
841    /// `was_mapped_writable` (message version >= 6) will be true.
842    pub modified: bool,
843    /// The file that is being closed
844    pub target: ShouldNotBeNull<es_file_t>,
845    pub anon0: es_event_close_t_anon_0,
846}
847
848should_not_be_null_fields!(es_event_close_t; target -> es_file_t);
849
850/// See [`es_event_close_t`].
851#[repr(C)]
852pub union es_event_close_t_anon_0 {
853    _reserved: [u8; 64],
854    /// Indicates that at some point in the lifetime of the target file vnode it was mapped into a
855    /// process as writable.
856    ///
857    /// `was_mapped_writable` only indicates whether the target file was mapped into writable memory
858    /// or not for the lifetime of the vnode. It does not indicate whether the file has actually
859    /// been written to by way of writing to mapped memory, and it does not indicate whether the
860    /// file is currently still mapped writable. Correct interpretation requires consideration of
861    /// vnode lifetimes in the kernel.
862    ///
863    /// Field available only if message version >= 6.
864    #[cfg(feature = "macos_13_0_0")]
865    pub was_mapped_writable: bool,
866}
867
868/// Create a file system object.
869///
870/// If an object is being created but has not yet been created, the `destination_type` will be
871/// `ES_DESTINATION_TYPE_NEW_PATH`.
872///
873/// Typically `ES_EVENT_TYPE_NOTIFY_CREATE` events are fired after the object has been created and
874/// the `destination_type` will be `ES_DESTINATION_TYPE_EXISTING_FILE`. The exception to this is
875/// for notifications that occur if an ES client responds to an `ES_EVENT_TYPE_AUTH_CREATE` event
876/// with `ES_AUTH_RESULT_DENY`.
877///
878/// This event can fire multiple times for a single syscall, for example when the syscall has to be
879/// retried due to racing VFS operations.
880///
881/// This event type does not support caching.
882#[repr(C)]
883// 10.15.0
884pub struct es_event_create_t {
885    /// Whether or not the destination refers to an existing file (see note)
886    pub destination_type: es_destination_type_t,
887    /// Information about the destination of the new file (see note)
888    pub destination: es_event_create_t_anon_0,
889    _reserved2: [u8; 16],
890    pub anon_1: es_event_create_t_anon_1,
891}
892
893/// See [`es_event_create_t`]
894#[repr(C)]
895pub union es_event_create_t_anon_0 {
896    /// The file system object that was created
897    pub existing_file: ShouldNotBeNull<es_file_t>,
898    pub new_path: ManuallyDrop<es_event_create_t_anon_0_anon_0>,
899}
900
901/// See [`es_event_create_t_anon_0`]
902#[repr(C)]
903pub struct es_event_create_t_anon_0_anon_0 {
904    /// The directory in which the new file system object will be created
905    pub dir: ShouldNotBeNull<es_file_t>,
906    /// The name of the new file system object to create
907    pub filename: es_string_token_t,
908    /// Mode of the file system object to create
909    pub mode: mode_t,
910}
911
912should_not_be_null_fields!(es_event_create_t_anon_0_anon_0; dir -> es_file_t);
913
914/// See [`es_event_create_t`]
915#[repr(C)]
916pub union es_event_create_t_anon_1 {
917    _reserved: [u8; 48],
918    #[cfg(feature = "macos_10_15_1")]
919    pub anon_0: ManuallyDrop<es_event_create_t_anon_1_anon_0>,
920}
921
922/// See [`es_event_create_t_anon_1`]
923#[repr(C)]
924#[cfg(feature = "macos_10_15_1")]
925pub struct es_event_create_t_anon_1_anon_0 {
926    /// The ACL that the new file system object got or gets created with.
927    ///
928    /// May be `NULL` if the file system object gets created without ACL.
929    ///
930    /// See warning about usage on [`acl_t`].
931    ///
932    /// Field available only if message version >= 2.
933    pub acl: acl_t,
934}
935
936/// Terminate a process
937///
938/// This event type does not support caching (notify-only).
939#[repr(C)]
940#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
941// 10.15.0
942pub struct es_event_exit_t {
943    /// The exit status of a process (same format as `wait(2)`)
944    pub stat: c_int,
945    _reserved: [u8; 64],
946}
947
948/// Exchange data atomically between two files
949///
950/// This event type does not support caching.
951#[repr(C)]
952// 10.15.0
953pub struct es_event_exchangedata_t {
954    /// The first file to be exchanged
955    pub file1: ShouldNotBeNull<es_file_t>,
956    /// The second file to be exchanged
957    pub file2: ShouldNotBeNull<es_file_t>,
958    _reserved: [u8; 64],
959}
960
961should_not_be_null_fields!(es_event_exchangedata_t; file1 -> es_file_t, file2 -> es_file_t);
962
963/// Write to a file
964///
965/// This event type does not support caching (notify-only).
966#[repr(C)]
967// 10.15.0
968pub struct es_event_write_t {
969    /// The file being written to
970    pub target: ShouldNotBeNull<es_file_t>,
971    _reserved: [u8; 64],
972}
973
974should_not_be_null_fields!(es_event_write_t; target -> es_file_t);
975
976/// Truncate to a file
977///
978/// This event type does not support caching.
979#[repr(C)]
980// 10.15.0
981pub struct es_event_truncate_t {
982    /// The file being truncated
983    pub target: ShouldNotBeNull<es_file_t>,
984    _reserved: [u8; 64],
985}
986
987should_not_be_null_fields!(es_event_truncate_t; target -> es_file_t);
988
989/// Changes directories
990///
991/// Cache key for this event type: `(process executable file, target directory)`.
992#[cfg(feature = "macos_10_15_1")]
993#[repr(C)]
994pub struct es_event_chdir_t {
995    /// The desired new current working directory
996    pub target: ShouldNotBeNull<es_file_t>,
997    _reserved: [u8; 64],
998}
999
1000#[cfg(feature = "macos_10_15_1")]
1001should_not_be_null_fields!(es_event_chdir_t; target -> es_file_t);
1002
1003/// View stat information of a file
1004///
1005/// This event type does not support caching (notify-only).
1006#[cfg(feature = "macos_10_15_1")]
1007#[repr(C)]
1008pub struct es_event_stat_t {
1009    /// The file for which stat information will be retrieved
1010    pub target: ShouldNotBeNull<es_file_t>,
1011    _reserved: [u8; 64],
1012}
1013
1014#[cfg(feature = "macos_10_15_1")]
1015should_not_be_null_fields!(es_event_stat_t; target -> es_file_t);
1016
1017/// Changes the root directory for a process
1018///
1019/// Cache key for this event type: `(process executable file, target directory)`.
1020#[cfg(feature = "macos_10_15_1")]
1021#[repr(C)]
1022pub struct es_event_chroot_t {
1023    /// The directory which will be the new root
1024    pub target: ShouldNotBeNull<es_file_t>,
1025    _reserved: [u8; 64],
1026}
1027
1028#[cfg(feature = "macos_10_15_1")]
1029should_not_be_null_fields!(es_event_chroot_t; target -> es_file_t);
1030
1031/// List extended attributes of a file
1032///
1033/// Cache key for this event type: `(process executable file, target file)`.
1034#[cfg(feature = "macos_10_15_1")]
1035#[repr(C)]
1036pub struct es_event_listextattr_t {
1037    /// The file for which extended attributes information are being retrieved
1038    pub target: ShouldNotBeNull<es_file_t>,
1039    _reserved: [u8; 64],
1040}
1041
1042#[cfg(feature = "macos_10_15_1")]
1043should_not_be_null_fields!(es_event_listextattr_t; target -> es_file_t);
1044
1045/// Open a connection to an I/O Kit IOService.
1046///
1047/// This event is fired when a process calls `IOServiceOpen()` in order to open a communications
1048/// channel with an I/O Kit driver.  The event does not correspond to driver <-> device
1049/// communication and is neither providing visibility nor access control into devices being
1050/// attached.
1051///
1052/// This event type does not support caching.
1053#[repr(C)]
1054// 10.15.0
1055pub struct es_event_iokit_open_t {
1056    /// A constant specifying the type of connection to be created, interpreted only by the
1057    /// IOService's family. This field corresponds to the type argument to `IOServiceOpen()`.
1058    pub user_client_type: u32,
1059    /// Meta class name of the user client instance
1060    pub user_client_class: es_string_token_t,
1061    _reserved: [u8; 64],
1062}
1063
1064ffi_wrap_enum!(
1065    es_get_task_type_t(u32);
1066
1067    == MACOS_10_15_0;
1068    /// Task port obtained by calling e.g. `task_for_pid()`, where the caller obtains a task port
1069    /// for a process identified by pid
1070    ES_GET_TASK_TYPE_TASK_FOR_PID = 0,
1071    /// Task port obtained by calling e.g. `processor_set_tasks()`, where the caller obtains a set
1072    /// of task ports
1073    ES_GET_TASK_TYPE_EXPOSE_TASK = 1,
1074    --
1075    /// Task port obtained by calling e.g. `task_identity_token_get_task_port()`, where the caller
1076    /// obtains a task port for a process identified by an identity token. Task identity tokens
1077    /// generally have to be given up by the target process voluntarily prior to the conversion
1078    /// into task ports.
1079    ES_GET_TASK_TYPE_IDENTITY_TOKEN = 2,
1080);
1081
1082/// Get a process's task control port.
1083///
1084/// This event is fired when a process obtains a send right to a task control port (e.g.
1085/// `task_for_pid()`, `task_identity_token_get_task_port()`, `processor_set_tasks()` and other
1086/// means).
1087///
1088/// Task control ports were formerly known as simply "task ports".
1089///
1090/// There are many legitimate reasons why a process might need to obtain a send right to a task
1091/// control port of another process, not limited to intending to debug or suspend the target
1092/// process. For instance, frameworks and their daemons may need to obtain a task control port to
1093/// fulfill requests made by the target process. Obtaining a task control port is in itself not
1094/// indicative of malicious activity. Denying system processes acquiring task control ports may
1095/// result in breaking system functionality in potentially fatal ways.
1096///
1097/// Cache key for this event type: `(process executable file, target executable file)`.
1098#[repr(C)]
1099// 10.15.0
1100pub struct es_event_get_task_t {
1101    /// The process for which the task control port will be retrieved
1102    pub target: ShouldNotBeNull<es_process_t>,
1103    /// Type indicating how the process is obtaining the task port for the target process.
1104    ///
1105    /// Field available only if message version >= 5.
1106    pub type_: es_get_task_type_t,
1107    _reserved: [u8; 60],
1108}
1109
1110should_not_be_null_fields!(es_event_get_task_t; target -> es_process_t);
1111
1112/// Get a process's task read port.
1113///
1114/// This event is fired when a process obtains a send right to a task read port (e.g.
1115/// `task_read_for_pid()`, `task_identity_token_get_task_port()`).
1116///
1117/// Cache key for this event type: `(process executable file, target executable file)`.
1118#[cfg(feature = "macos_11_3_0")]
1119#[repr(C)]
1120pub struct es_event_get_task_read_t {
1121    /// The process for which the task read port will be retrieved
1122    pub target: ShouldNotBeNull<es_process_t>,
1123    /// Type indicating how the process is obtaining the task port for the target process.
1124    ///
1125    /// Field available only if message version >= 5.
1126    pub type_: es_get_task_type_t,
1127    _reserved: [u8; 60],
1128}
1129
1130#[cfg(feature = "macos_11_3_0")]
1131should_not_be_null_fields!(es_event_get_task_read_t; target -> es_process_t);
1132
1133/// Get a process's task inspect port.
1134///
1135/// This event is fired when a process obtains a send right to a task inspect port (e.g.
1136/// `task_inspect_for_pid()`, `task_identity_token_get_task_port()`).
1137///
1138/// This event type does not support caching.
1139#[cfg(feature = "macos_11_3_0")]
1140#[repr(C)]
1141pub struct es_event_get_task_inspect_t {
1142    /// The process for which the task inspect port will be retrieved
1143    pub target: ShouldNotBeNull<es_process_t>,
1144    /// Type indicating how the process is obtaining the task port for the target process.
1145    ///
1146    /// Field available only if message version >= 5.
1147    pub type_: es_get_task_type_t,
1148    _reserved: [u8; 60],
1149}
1150
1151#[cfg(feature = "macos_11_3_0")]
1152should_not_be_null_fields!(es_event_get_task_inspect_t; target -> es_process_t);
1153
1154/// Get a process's task name port.
1155///
1156/// This event is fired when a process obtains a send right to a task name port (e.g.
1157/// `task_name_for_pid()`, `task_identity_token_get_task_port()`).
1158///
1159/// This event type does not support caching.
1160#[cfg(feature = "macos_11_0_0")]
1161#[repr(C)]
1162pub struct es_event_get_task_name_t {
1163    /// The process for which the task name port will be retrieved
1164    pub target: ShouldNotBeNull<es_process_t>,
1165    /// Type indicating how the process is obtaining the task port for the target process.
1166    ///
1167    /// Field available only if message version >= 5.
1168    pub type_: es_get_task_type_t,
1169    _reserved: [u8; 60],
1170}
1171
1172#[cfg(feature = "macos_11_0_0")]
1173should_not_be_null_fields!(es_event_get_task_name_t; target -> es_process_t);
1174
1175/// Retrieve file system attributes
1176///
1177/// Cache key for this event type: `(process executable file, target file)`.
1178#[cfg(feature = "macos_10_15_1")]
1179#[repr(C)]
1180pub struct es_event_getattrlist_t {
1181    /// The attributes that will be retrieved
1182    pub attrlist: attrlist,
1183    /// The file for which attributes will be retrieved
1184    pub target: ShouldNotBeNull<es_file_t>,
1185    _reserved: [u8; 64],
1186}
1187
1188#[cfg(feature = "macos_10_15_1")]
1189should_not_be_null_fields!(es_event_getattrlist_t; target -> es_file_t);
1190
1191/// Modify file system attributes
1192///
1193/// This event type does not support caching.
1194#[repr(C)]
1195// 10.15.0
1196pub struct es_event_setattrlist_t {
1197    /// The attributes that will be modified
1198    pub attrlist: attrlist,
1199    /// The file for which attributes will be modified
1200    pub target: ShouldNotBeNull<es_file_t>,
1201    _reserved: [u8; 64],
1202}
1203
1204should_not_be_null_fields!(es_event_setattrlist_t; target -> es_file_t);
1205
1206/// Update file contents via the `FileProvider` framework
1207///
1208/// This event type does not support caching.
1209#[repr(C)]
1210// 10.15.0
1211pub struct es_event_file_provider_update_t {
1212    /// The staged file that has had its contents updated
1213    pub source: ShouldNotBeNull<es_file_t>,
1214    /// The destination that the staged `source` file will be moved to
1215    pub target_path: es_string_token_t,
1216    _reserved: [u8; 64],
1217}
1218
1219should_not_be_null_fields!(es_event_file_provider_update_t; source -> es_file_t);
1220
1221/// Materialize a file via the `FileProvider` framework
1222///
1223/// This event type does not support caching.
1224#[repr(C)]
1225// 10.15.0
1226pub struct es_event_file_provider_materialize_t {
1227    pub instigator: *mut es_process_t,
1228    /// The staged file that has been materialized
1229    pub source: ShouldNotBeNull<es_file_t>,
1230    /// The destination of the staged `source` file
1231    pub target: ShouldNotBeNull<es_file_t>,
1232    /// The audit_token of the process instigating this event.
1233    ///
1234    /// Field available only if message version >= 8.
1235    #[cfg(feature = "macos_15_0_0")]
1236    pub instigator_token: audit_token_t,
1237    _reserved: [u8; 32],
1238}
1239
1240should_not_be_null_fields!(
1241    es_event_file_provider_materialize_t;
1242    source -> es_file_t,
1243    target -> es_file_t
1244);
1245null_fields!(es_event_file_provider_materialize_t; instigator -> es_process_t);
1246
1247/// Resolve a symbolic link.
1248///
1249/// This is not limited only to `readlink(2)`. Other operations such as path lookups can also cause
1250/// this event to be fired.
1251///
1252/// *Caching support is undocumented for this event.*
1253#[repr(C)]
1254// 10.15.0
1255pub struct es_event_readlink_t {
1256    /// The symbolic link that is attempting to be resolved
1257    pub source: ShouldNotBeNull<es_file_t>,
1258    _reserved: [u8; 64],
1259}
1260
1261should_not_be_null_fields!(es_event_readlink_t; source -> es_file_t);
1262
1263/// Lookup a file system object.
1264///
1265/// The `relative_target` data may contain untrusted user input.
1266///
1267/// This event type does not support caching (notify-only).
1268#[repr(C)]
1269// 10.15.0
1270pub struct es_event_lookup_t {
1271    /// The current directory
1272    pub source_dir: ShouldNotBeNull<es_file_t>,
1273    /// The path to lookup relative to the `source_dir`
1274    pub relative_target: es_string_token_t,
1275    _reserved: [u8; 64],
1276}
1277
1278should_not_be_null_fields!(es_event_lookup_t; source_dir -> es_file_t);
1279
1280/// Test file access
1281///
1282/// This event type does not support caching (notify-only).
1283#[cfg(feature = "macos_10_15_1")]
1284#[repr(C)]
1285pub struct es_event_access_t {
1286    /// Access permission to check
1287    pub mode: i32,
1288    /// The file to check for access
1289    pub target: ShouldNotBeNull<es_file_t>,
1290    _reserved: [u8; 64],
1291}
1292
1293#[cfg(feature = "macos_10_15_1")]
1294should_not_be_null_fields!(es_event_access_t; target -> es_file_t);
1295
1296/// Change file access and modification times (e.g. via `utimes(2)`)
1297///
1298/// Cache key for this event type: `(process executable file, target file)`.
1299#[cfg(feature = "macos_10_15_1")]
1300#[repr(C)]
1301pub struct es_event_utimes_t {
1302    /// The path which will have its times modified
1303    pub target: ShouldNotBeNull<es_file_t>,
1304    /// The desired new access time
1305    pub atime: timespec,
1306    /// The desired new modification time
1307    pub mtime: timespec,
1308    _reserved: [u8; 64],
1309}
1310
1311#[cfg(feature = "macos_10_15_1")]
1312should_not_be_null_fields!(es_event_utimes_t; target -> es_file_t);
1313
1314/// Clone a file
1315///
1316/// This event type does not support caching.
1317#[cfg(feature = "macos_10_15_1")]
1318#[repr(C)]
1319pub struct es_event_clone_t {
1320    /// The file that will be cloned
1321    pub source: ShouldNotBeNull<es_file_t>,
1322    /// The directory into which the `source` file will be cloned
1323    pub target_dir: ShouldNotBeNull<es_file_t>,
1324    /// The name of the new file to which `source` will be cloned
1325    pub target_name: es_string_token_t,
1326    _reserved: [u8; 64],
1327}
1328
1329#[cfg(feature = "macos_10_15_1")]
1330should_not_be_null_fields!(es_event_clone_t; source -> es_file_t, target_dir -> es_file_t);
1331
1332/// Copy a file using the copyfile syscall.
1333///
1334/// Not to be confused with `copyfile(3)`.
1335///
1336/// Prior to macOS 12.0, the `copyfile` syscall fired `open`, `unlink` and `auth` create events, but
1337/// no notify `create`, nor `write` or `close` events.
1338///
1339/// This event type does not support caching.
1340#[cfg(feature = "macos_12_0_0")]
1341#[repr(C)]
1342pub struct es_event_copyfile_t {
1343    /// The file that will be cloned
1344    pub source: ShouldNotBeNull<es_file_t>,
1345    /// The file existing at the target path that will be overwritten by the copyfile operation.
1346    /// `NULL` if no such file exists.
1347    pub target_file: *mut es_file_t,
1348    /// The directory into which the `source` file will be copied
1349    pub target_dir: ShouldNotBeNull<es_file_t>,
1350    /// The name of the new file to which `source` will be copied
1351    pub target_name: es_string_token_t,
1352    /// Corresponds to mode argument of the copyfile syscall
1353    pub mode: mode_t,
1354    /// Corresponds to flags argument of the copyfile syscall
1355    pub flags: i32,
1356    _reserved: [u8; 56],
1357}
1358
1359#[cfg(feature = "macos_12_0_0")]
1360should_not_be_null_fields!(es_event_copyfile_t; source -> es_file_t, target_dir -> es_file_t);
1361#[cfg(feature = "macos_12_0_0")]
1362null_fields!(es_event_copyfile_t; target_file -> es_file_t);
1363
1364/// File control
1365///
1366/// This event type does not support caching.
1367#[cfg(feature = "macos_10_15_1")]
1368#[repr(C)]
1369pub struct es_event_fcntl_t {
1370    /// The target file on which the file control command will be performed
1371    pub target: ShouldNotBeNull<es_file_t>,
1372    /// The `cmd` argument given to `fcntl(2)`
1373    pub cmd: i32,
1374    _reserved: [u8; 64],
1375}
1376
1377#[cfg(feature = "macos_10_15_1")]
1378should_not_be_null_fields!(es_event_fcntl_t; target -> es_file_t);
1379
1380/// Read directory entries
1381///
1382/// Cache key for this event type: `(process executable file, target directory)`.
1383#[cfg(feature = "macos_10_15_1")]
1384#[repr(C)]
1385pub struct es_event_readdir_t {
1386    /// The directory whose contents will be read
1387    pub target: ShouldNotBeNull<es_file_t>,
1388    _reserved: [u8; 64],
1389}
1390
1391#[cfg(feature = "macos_10_15_1")]
1392should_not_be_null_fields!(es_event_readdir_t; target -> es_file_t);
1393
1394/// Retrieve file system path based on FSID.
1395///
1396/// This event can fire multiple times for a single syscall, for example when the syscall has to be
1397/// retried due to racing VFS operations.
1398///
1399/// Cache key for this event type: `(process executable file, target file)`.
1400#[cfg(feature = "macos_10_15_1")]
1401#[repr(C)]
1402pub struct es_event_fsgetpath_t {
1403    /// Describes the file system path that will be retrieved
1404    pub target: ShouldNotBeNull<es_file_t>,
1405    _reserved: [u8; 64],
1406}
1407
1408#[cfg(feature = "macos_10_15_1")]
1409should_not_be_null_fields!(es_event_fsgetpath_t; target -> es_file_t);
1410
1411/// Modify the system time
1412///
1413/// This event is not fired if the program contains the entitlement `com.apple.private.settime`.
1414/// Additionally, even if an ES client responds to `ES_EVENT_TYPE_AUTH_SETTIME` events with
1415/// `ES_AUTH_RESULT_ALLOW`, the operation may still fail for other reasons (e.g. unprivileged user).
1416///
1417/// This event type does not support caching.
1418#[cfg(feature = "macos_10_15_1")]
1419#[repr(C)]
1420#[derive(Copy, Clone)]
1421pub struct es_event_settime_t {
1422    _reserved: [u8; 64],
1423}
1424
1425/// Duplicate a file descriptor
1426///
1427/// This event type does not support caching (notify-only).
1428#[cfg(feature = "macos_10_15_1")]
1429#[repr(C)]
1430pub struct es_event_dup_t {
1431    /// Describes the file the duplicated file descriptor points to
1432    pub target: ShouldNotBeNull<es_file_t>,
1433    _reserved: [u8; 64],
1434}
1435
1436#[cfg(feature = "macos_10_15_1")]
1437should_not_be_null_fields!(es_event_dup_t; target -> es_file_t);
1438
1439/// Fired when a UNIX-domain socket is about to be bound to a path
1440///
1441/// This event type does not support caching.
1442#[cfg(feature = "macos_10_15_1")]
1443#[repr(C)]
1444pub struct es_event_uipc_bind_t {
1445    /// Describes the directory the socket file is created in
1446    pub dir: ShouldNotBeNull<es_file_t>,
1447    /// The filename of the socket file
1448    pub filename: es_string_token_t,
1449    /// The mode of the socket file
1450    pub mode: mode_t,
1451    _reserved: [u8; 64],
1452}
1453
1454#[cfg(feature = "macos_10_15_1")]
1455should_not_be_null_fields!(es_event_uipc_bind_t; dir -> es_file_t);
1456
1457/// Fired when a UNIX-domain socket is about to be connected.
1458///
1459/// Cache key for this event type: `(process executable file, socket file)`.
1460#[cfg(feature = "macos_10_15_1")]
1461#[repr(C)]
1462pub struct es_event_uipc_connect_t {
1463    /// Describes the socket file that the socket is bound to
1464    pub file: ShouldNotBeNull<es_file_t>,
1465    /// The communications domain of the socket (see `socket(2)`)
1466    pub domain: c_int,
1467    /// The type of the socket (see `socket(2)`)
1468    pub type_: c_int,
1469    /// The protocol of the socket (see `socket(2)`)
1470    pub protocol: c_int,
1471    _reserved: [u8; 64],
1472}
1473
1474#[cfg(feature = "macos_10_15_1")]
1475should_not_be_null_fields!(es_event_uipc_connect_t; file -> es_file_t);
1476
1477/// Set a file ACL.
1478///
1479/// This event type does not support caching.
1480#[cfg(feature = "macos_10_15_1")]
1481#[repr(C)]
1482pub struct es_event_setacl_t {
1483    /// Describes the file whose ACL is being set.
1484    pub target: ShouldNotBeNull<es_file_t>,
1485    /// Describes whether or not the ACL on the `target` is being set or cleared
1486    pub set_or_clear: es_set_or_clear_t,
1487    /// Union that is valid when `set_or_clear` is set to `ES_SET`
1488    pub acl: es_event_setacl_t_anon_0,
1489    _reserved: [u8; 64],
1490}
1491
1492#[cfg(feature = "macos_10_15_1")]
1493should_not_be_null_fields!(es_event_setacl_t; target -> es_file_t);
1494
1495#[cfg(feature = "macos_10_15_1")]
1496impl es_event_setacl_t {
1497    /// `Some` if `set_or_clear` is `ES_SET`
1498    ///
1499    /// # Safety
1500    ///
1501    /// `acl_t` is a pointer to the opaque ACL, be careful not to extend it's lifetime past that
1502    /// of `self`. The `acl` and `set_or_clear` fields must be synced.
1503    pub unsafe fn acl(&self) -> Option<&acl_t> {
1504        if self.set_or_clear == es_set_or_clear_t::ES_SET {
1505            // Safety: we checked `set_or_clear` for the correct value just before and the field
1506            // are guaranteed to be in sync by the caller.
1507            Some(unsafe { &self.acl.set })
1508        } else {
1509            None
1510        }
1511    }
1512}
1513
1514/// See [`es_event_setacl_t`]
1515#[cfg(feature = "macos_10_15_1")]
1516#[repr(C)]
1517pub union es_event_setacl_t_anon_0 {
1518    /// The [`acl_t`] structure to be used by various `acl(3)` functions.
1519    ///
1520    /// See the warning on the type to learn how to use it safely.
1521    ///
1522    /// This is theoretically `ShouldNotBeNull` but since it can be absent depending on
1523    /// [`es_event_setacl_t::set_or_clear`], this is not represented in the type here
1524    pub set: acl_t,
1525}
1526
1527/// Fired when a pseudoterminal control device is granted
1528///
1529/// This event type does not support caching (notify-only).
1530#[cfg(feature = "macos_10_15_4")]
1531#[repr(C)]
1532#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1533pub struct es_event_pty_grant_t {
1534    /// Major and minor numbers of device
1535    pub dev: dev_t,
1536    _reserved: [u8; 64],
1537}
1538
1539/// Fired when a pseudoterminal control device is closed
1540///
1541/// This event type does not support caching (notify-only).
1542#[cfg(feature = "macos_10_15_4")]
1543#[repr(C)]
1544#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1545pub struct es_event_pty_close_t {
1546    /// Major and minor numbers of device
1547    pub dev: dev_t,
1548    _reserved: [u8; 64],
1549}
1550
1551/// Access control check for retrieving process information
1552///
1553/// Cache key for this event type: `(process executable file, target process executable file, type)`.
1554#[cfg(feature = "macos_10_15_4")]
1555#[repr(C)]
1556pub struct es_event_proc_check_t {
1557    /// The process for which the access will be checked
1558    pub target: *mut es_process_t,
1559    /// The type of call number used to check the access on the target process
1560    pub type_: es_proc_check_type_t,
1561    /// The flavor used to check the access on the target process
1562    pub flavor: c_int,
1563    _reserved: [u8; 64],
1564}
1565
1566#[cfg(feature = "macos_10_15_4")]
1567null_fields!(es_event_proc_check_t; target -> es_process_t);
1568
1569/// Access control check for searching a volume or a mounted file system
1570///
1571/// Cache key for this event type: `(process executable file, target file)`.
1572#[cfg(feature = "macos_11_0_0")]
1573#[repr(C)]
1574pub struct es_event_searchfs_t {
1575    /// The attributes that will be used to do the search
1576    pub attrlist: attrlist,
1577    /// The volume whose contents will be searched
1578    pub target: ShouldNotBeNull<es_file_t>,
1579    _reserved: [u8; 64],
1580}
1581
1582#[cfg(feature = "macos_11_0_0")]
1583should_not_be_null_fields!(es_event_searchfs_t; target -> es_file_t);
1584
1585ffi_wrap_enum!(
1586    /// This enum describes the type of suspend/resume operations that are currently used
1587    es_proc_suspend_resume_type_t(u32);
1588
1589    == MACOS_10_15_0;
1590    ES_PROC_SUSPEND_RESUME_TYPE_SUSPEND = 0,
1591    ES_PROC_SUSPEND_RESUME_TYPE_RESUME = 1,
1592    --
1593    ES_PROC_SUSPEND_RESUME_TYPE_SHUTDOWN_SOCKETS = 3,
1594);
1595
1596/// Fired when one of pid_suspend, pid_resume or pid_shutdown_sockets is called on a process
1597///
1598/// This event type does not support caching.
1599#[cfg(feature = "macos_11_0_0")]
1600#[repr(C)]
1601pub struct es_event_proc_suspend_resume_t {
1602    /// The process that is being suspended, resumed, or is the object of a pid_shutdown_sockets call
1603    pub target: *mut es_process_t,
1604    /// The type of operation that was called on the target process
1605    pub type_: es_proc_suspend_resume_type_t,
1606    _reserved: [u8; 64],
1607}
1608
1609#[cfg(feature = "macos_11_0_0")]
1610null_fields!(es_event_proc_suspend_resume_t; target -> es_process_t);
1611
1612/// Code signing status for process was invalidated.
1613///
1614/// This event fires when the `CS_VALID` bit is removed from a process' CS flags, that is, when the
1615/// first invalid page is paged in for a process with an otherwise valid code signature, or when a
1616/// process is explicitly invalidated by a `csops(CS_OPS_MARKINVALID)` syscall. This event does not
1617/// fire if `CS_HARD` was set, since `CS_HARD` by design prevents the process from going invalid.
1618///
1619/// This event type does not support caching (notify-only).
1620#[cfg(feature = "macos_11_0_0")]
1621#[repr(C)]
1622#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1623pub struct es_event_cs_invalidated_t {
1624    _reserved: [u8; 64],
1625}
1626
1627/// Fired when one process attempts to attach to another process
1628///
1629/// This event can fire multiple times for a single trace attempt, for example when the processes to
1630/// which is being attached is reparented during the operation
1631///
1632/// This event type does not support caching (notify-only).
1633#[cfg(feature = "macos_11_0_0")]
1634#[repr(C)]
1635pub struct es_event_trace_t {
1636    /// The process that will be attached to by the process that instigated the event
1637    pub target: ShouldNotBeNull<es_process_t>,
1638    _reserved: [u8; 64],
1639}
1640
1641#[cfg(feature = "macos_11_0_0")]
1642should_not_be_null_fields!(es_event_trace_t; target -> es_process_t);
1643
1644/// Notification that a process has attempted to create a thread in another process by calling one
1645/// of the `thread_create` or `thread_create_running` MIG routines
1646///
1647/// This event type does not support caching (notify-only).
1648#[cfg(feature = "macos_11_0_0")]
1649#[repr(C)]
1650pub struct es_event_remote_thread_create_t {
1651    /// The process in which a new thread was created
1652    pub target: ShouldNotBeNull<es_process_t>,
1653    /// The new thread state in case of `thread_create_running`, `NULL` in case of `thread_create`
1654    pub thread_state: *mut es_thread_state_t,
1655    _reserved: [u8; 64],
1656}
1657
1658#[cfg(feature = "macos_11_0_0")]
1659should_not_be_null_fields!(es_event_remote_thread_create_t; target -> es_process_t);
1660#[cfg(feature = "macos_11_0_0")]
1661null_fields!(es_event_remote_thread_create_t; thread_state -> es_thread_state_t);
1662
1663/// Notification that a process has called `setuid()`
1664///
1665/// This event type does not support caching (notify-only).
1666#[cfg(feature = "macos_12_0_0")]
1667#[repr(C)]
1668#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1669pub struct es_event_setuid_t {
1670    /// The `uid` argument to the `setuid()` syscall
1671    pub uid: uid_t,
1672    _reserved: [u8; 64],
1673}
1674
1675/// Notification that a process has called `setgid()`
1676///
1677/// This event type does not support caching (notify-only).
1678#[cfg(feature = "macos_12_0_0")]
1679#[repr(C)]
1680#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1681pub struct es_event_setgid_t {
1682    /// The `gid` argument to the `setgid()` syscall
1683    pub gid: uid_t,
1684    _reserved: [u8; 64],
1685}
1686
1687/// Notification that a process has called `seteuid()`
1688///
1689/// This event type does not support caching (notify-only).
1690#[cfg(feature = "macos_12_0_0")]
1691#[repr(C)]
1692#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1693pub struct es_event_seteuid_t {
1694    /// The `euid` argument to the `seteuid()` syscall
1695    pub euid: uid_t,
1696    _reserved: [u8; 64],
1697}
1698
1699/// Notification that a process has called `setegid()`
1700///
1701/// This event type does not support caching (notify-only).
1702#[cfg(feature = "macos_12_0_0")]
1703#[repr(C)]
1704#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1705pub struct es_event_setegid_t {
1706    /// The `egid` argument to the `setegid()` syscall
1707    pub egid: uid_t,
1708    _reserved: [u8; 64],
1709}
1710
1711/// Notification that a process has called `setreuid()`
1712///
1713/// This event type does not support caching (notify-only).
1714#[cfg(feature = "macos_12_0_0")]
1715#[repr(C)]
1716#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1717pub struct es_event_setreuid_t {
1718    /// The `ruid` argument to the `setreuid()` syscall
1719    pub ruid: uid_t,
1720    /// The `euid` argument to the `setreuid()` syscall
1721    pub euid: uid_t,
1722    _reserved: [u8; 64],
1723}
1724
1725/// Notification that a process has called `setregid()`
1726///
1727/// This event type does not support caching (notify-only).
1728#[cfg(feature = "macos_12_0_0")]
1729#[repr(C)]
1730#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1731pub struct es_event_setregid_t {
1732    /// The `rgid` argument to the `setregid()` syscall
1733    pub rgid: uid_t,
1734    /// The `egid` argument to the `setregid()` syscall
1735    pub egid: uid_t,
1736    _reserved: [u8; 64],
1737}
1738
1739/// OpenDirectory authentication data for type
1740/// [`ES_AUTHENTICATION_TYPE_OD`][crate::es_authentication_type_t].
1741#[cfg(feature = "macos_13_0_0")]
1742#[repr(C)]
1743pub struct es_event_authentication_od_t {
1744    /// Process that instigated the authentication (XPC caller that asked for authentication).
1745    pub instigator: *mut es_process_t,
1746    /// OD record type against which OD is authenticating. Typically `Users`, but other record types
1747    /// can auth too.
1748    pub record_type: es_string_token_t,
1749    /// OD record name against which OD is authenticating. For record type `Users`, this is the
1750    /// username.
1751    pub record_name: es_string_token_t,
1752    /// OD node against which OD is authenticating. Typically one of `/Local/Default`, `/LDAPv3/
1753    /// <server>` or `/Active Directory/<domain>`.
1754    pub node_name: es_string_token_t,
1755    /// Optional. If node_name is "/Local/Default", this is the path of the database against which
1756    /// OD is authenticating.
1757    pub db_path: es_string_token_t,
1758    /// Audit token of the process that instigated this event.
1759    ///
1760    /// Field available only if message version >= 8.
1761    #[cfg(feature = "macos_15_0_0")]
1762    pub instigator_token: audit_token_t,
1763}
1764
1765#[cfg(feature = "macos_13_0_0")]
1766null_fields!(es_event_authentication_od_t; instigator -> es_process_t);
1767
1768#[cfg(feature = "macos_13_0_0")]
1769ffi_wrap_enum!(
1770    /// See [`es_event_authentication_touchid_t`]
1771    es_touchid_mode_t(u32);
1772
1773    == #[cfg(feature = "macos_13_0_0")] 13_0_0 "13.0.0";
1774    ES_TOUCHID_MODE_VERIFICATION = 0,
1775    --
1776    ES_TOUCHID_MODE_IDENTIFICATION = 1,
1777);
1778
1779/// TouchID authentication data for type
1780/// [`ES_AUTHENTICATION_TYPE_TOUCHID`][crate::es_authentication_type_t].
1781#[cfg(feature = "macos_13_0_0")]
1782#[repr(C)]
1783pub struct es_event_authentication_touchid_t {
1784    /// Process that instigated the authentication (XPC caller that asked for authentication).
1785    pub instigator: *mut es_process_t,
1786    /// TouchID authentication type
1787    pub touchid_mode: es_touchid_mode_t,
1788    /// Describes whether or not the uid of the user authenticated is available
1789    pub has_uid: bool,
1790    /// Union that is valid when `has_uid` is set to `true`
1791    pub anon0: es_event_authentication_touchid_t_anon0,
1792    /// Audit token of the process that instigated this event.
1793    ///
1794    /// Field available only if message version >= 8.
1795    #[cfg(feature = "macos_15_0_0")]
1796    pub instigator_token: audit_token_t,
1797}
1798
1799#[cfg(feature = "macos_13_0_0")]
1800null_fields!(es_event_authentication_touchid_t; instigator -> es_process_t);
1801
1802/// See [`es_event_authentication_touchid_t`]
1803#[cfg(feature = "macos_13_0_0")]
1804#[repr(C)]
1805pub union es_event_authentication_touchid_t_anon0 {
1806    /// Uid of user that was authenticated. This will be set when `success` is true and
1807    /// `touchid_mode` is of verification type i.e.
1808    /// [`ES_TOUCHID_MODE_VERIFICATION`][crate::es_authentication_type_t].
1809    pub uid: uid_t,
1810}
1811
1812/// Token authentication data for type
1813/// [`ES_AUTHENTICATION_TYPE_TOKEN`][crate::es_authentication_type_t].
1814#[cfg(feature = "macos_13_0_0")]
1815#[repr(C)]
1816pub struct es_event_authentication_token_t {
1817    /// Process that instigated the authentication (XPC caller that asked for authentication).
1818    pub instigator: *mut es_process_t,
1819    /// Hash of the public key which CryptoTokenKit is authenticating.
1820    pub pubkey_hash: es_string_token_t,
1821    /// Token identifier of the event which CryptoTokenKit is authenticating.
1822    pub token_id: es_string_token_t,
1823    /// Optional. This will be available if token is used for GSS PKINIT authentication for
1824    /// obtaining a kerberos TGT. `NULL` in all other cases.
1825    pub kerberos_principal: es_string_token_t,
1826    /// Audit token of the process that instigated this event.
1827    ///
1828    /// Field available only if message version >= 8.
1829    #[cfg(feature = "macos_15_0_0")]
1830    pub instigator_token: audit_token_t,
1831}
1832
1833#[cfg(feature = "macos_13_0_0")]
1834null_fields!(es_event_authentication_token_t; instigator -> es_process_t);
1835
1836#[cfg(feature = "macos_13_0_0")]
1837ffi_wrap_enum!(
1838    /// See [`es_event_authentication_auto_unlock_t`].
1839    es_auto_unlock_type_t(u32);
1840
1841    == #[cfg(feature = "macos_13_0_0")] 13_0_0 "13.0.0";
1842    /// Unlock the machine using Apple Watch.
1843    ES_AUTO_UNLOCK_MACHINE_UNLOCK = 1,
1844    --
1845    /// Approve an authorization prompt using Apple Watch.
1846    ES_AUTO_UNLOCK_AUTH_PROMPT = 2,
1847);
1848
1849/// Auto Unlock authentication data for type
1850/// [`ES_AUTHENTICATION_TYPE_TOKEN`][crate::es_authentication_type_t].
1851///
1852/// This kind of authentication is performed when authenticating to the local Mac using an Apple
1853/// Watch for the purpose of unlocking the machine or confirming an authorization prompt. Auto
1854/// Unlock is part of Continuity.
1855///
1856/// This event type does not support caching (notify-only).
1857#[cfg(feature = "macos_13_0_0")]
1858#[repr(C)]
1859pub struct es_event_authentication_auto_unlock_t {
1860    /// Username for which the authentication was attempted.
1861    pub username: es_string_token_t,
1862    /// Purpose of the authentication.
1863    pub type_: es_auto_unlock_type_t,
1864}
1865
1866/// Notification that an authentication was performed.
1867///
1868/// This event type does not support caching (notify-only).
1869#[cfg(feature = "macos_13_0_0")]
1870#[repr(C)]
1871pub struct es_event_authentication_t {
1872    /// True iff authentication was successful.
1873    pub success: bool,
1874    /// The type of authentication.
1875    pub type_: es_authentication_type_t,
1876    /// Type-specific data describing the authentication.
1877    pub data: es_event_authentication_t_anon0,
1878}
1879
1880/// See [`es_event_authentication_t`]
1881#[cfg(feature = "macos_13_0_0")]
1882#[repr(C)]
1883#[derive(Copy, Clone)]
1884pub union es_event_authentication_t_anon0 {
1885    pub od: ShouldNotBeNull<es_event_authentication_od_t>,
1886    pub touchid: ShouldNotBeNull<es_event_authentication_touchid_t>,
1887    pub token: ShouldNotBeNull<es_event_authentication_token_t>,
1888    pub auto_unlock: ShouldNotBeNull<es_event_authentication_auto_unlock_t>,
1889}
1890
1891#[cfg(feature = "macos_13_0_0")]
1892should_not_be_null_fields!(
1893    es_event_authentication_t_anon0;
1894    od -> es_event_authentication_od_t,
1895    touchid -> es_event_authentication_touchid_t,
1896    token -> es_event_authentication_token_t,
1897    auto_unlock -> es_event_authentication_auto_unlock_t,
1898);
1899
1900/// Notification that XProtect detected malware.
1901///
1902/// For any given malware incident, XProtect may emit zero or more `xp_malware_detected` events, and
1903/// zero or more `xp_malware_remediated` events.
1904///
1905/// This event type does not support caching (notify-only).
1906#[cfg(feature = "macos_13_0_0")]
1907#[repr(C)]
1908pub struct es_event_xp_malware_detected_t {
1909    /// Version of the signatures used for detection. Currently corresponds to XProtect version.
1910    pub signature_version: es_string_token_t,
1911    /// String identifying the malware that was detected.
1912    pub malware_identifier: es_string_token_t,
1913    /// String identifying the incident, intended for linking multiple malware detected and
1914    /// remediated events.
1915    pub incident_identifier: es_string_token_t,
1916    /// Path where malware was detected. This path is not necessarily a malicious binary, it can
1917    /// also be a legitimate file containing a malicious portion.
1918    pub detected_path: es_string_token_t,
1919}
1920
1921/// Notification that XProtect remediated malware.
1922///
1923/// For any given malware incident, XProtect may emit zero or more `xp_malware_detected` events, and
1924/// zero or more `xp_malware_remediated` events.
1925///
1926/// This event type does not support caching (notify-only).
1927#[cfg(feature = "macos_13_0_0")]
1928#[repr(C)]
1929pub struct es_event_xp_malware_remediated_t {
1930    /// Version of the signatures used for remediation. Currently corresponds to XProtect version.
1931    pub signature_version: es_string_token_t,
1932    /// String identifying the malware that was detected.
1933    pub malware_identifier: es_string_token_t,
1934    /// String identifying the incident, intended for linking multiple malware detected and
1935    /// remediated events.
1936    pub incident_identifier: es_string_token_t,
1937    /// String indicating the type of action that was taken, e.g. "path_delete".
1938    pub action_type: es_string_token_t,
1939    /// True only if remediation was successful.
1940    pub success: bool,
1941    /// String describing specific reasons for failure or success.
1942    pub result_description: es_string_token_t,
1943    /// Optional. Path that was subject to remediation, if any. This path is not necessarily
1944    /// a malicious binary, it can also be a legitimate file containing a malicious portion.
1945    /// Specifically, the file at this path may still exist after successful remediation.
1946    pub remediated_path: es_string_token_t,
1947    /// Audit token of process that was subject to remediation, if any.
1948    pub remediated_process_audit_token: *mut audit_token_t,
1949}
1950
1951#[cfg(feature = "macos_13_0_0")]
1952null_fields!(es_event_xp_malware_remediated_t; remediated_process_audit_token -> audit_token_t);
1953
1954/// A session identifier identifying a on-console or off-console graphical session.
1955///
1956/// A graphical session exists and can potentially be attached to via Screen Sharing before a user
1957/// is logged in. EndpointSecurity clients should treat the `graphical_session_id` as an opaque
1958/// identifier and not assign special meaning to it beyond correlating events pertaining to the same
1959/// graphical session. Not to be confused with the audit session ID.
1960#[cfg(feature = "macos_13_0_0")]
1961pub type es_graphical_session_id_t = u32;
1962
1963/// Notification that LoginWindow has logged in a user.
1964///
1965/// This event type does not support caching (notify-only).
1966#[cfg(feature = "macos_13_0_0")]
1967#[repr(C)]
1968pub struct es_event_lw_session_login_t {
1969    /// Short username of the user.
1970    pub username: es_string_token_t,
1971    /// Graphical session id of the session.
1972    pub graphical_session_id: es_graphical_session_id_t,
1973}
1974
1975/// Notification that LoginWindow has logged out a user.
1976///
1977/// This event type does not support caching (notify-only).
1978#[cfg(feature = "macos_13_0_0")]
1979#[repr(C)]
1980pub struct es_event_lw_session_logout_t {
1981    /// Short username of the user.
1982    pub username: es_string_token_t,
1983    /// Graphical session id of the session.
1984    pub graphical_session_id: es_graphical_session_id_t,
1985}
1986
1987/// Notification that LoginWindow locked the screen of a session.
1988///
1989///
1990/// This event type does not support caching (notify-only).
1991#[cfg(feature = "macos_13_0_0")]
1992#[repr(C)]
1993pub struct es_event_lw_session_lock_t {
1994    /// Short username of the user.
1995    pub username: es_string_token_t,
1996    /// Graphical session id of the session.
1997    pub graphical_session_id: es_graphical_session_id_t,
1998}
1999
2000/// Notification that LoginWindow unlocked the screen of a session.
2001///
2002/// This event type does not support caching (notify-only).
2003#[cfg(feature = "macos_13_0_0")]
2004#[repr(C)]
2005pub struct es_event_lw_session_unlock_t {
2006    /// Short username of the user.
2007    pub username: es_string_token_t,
2008    /// Graphical session id of the session.
2009    pub graphical_session_id: es_graphical_session_id_t,
2010}
2011
2012/// Notification that Screen Sharing has attached to a graphical session.
2013///
2014/// This event type does not support caching (notify-only).
2015///
2016/// This event is not emitted when a screensharing session has the same source and destination
2017/// address. For example if device A is acting as a NAT gateway for device B, then a screensharing
2018/// session from B -> A would not emit an event.
2019#[cfg(feature = "macos_13_0_0")]
2020#[repr(C)]
2021pub struct es_event_screensharing_attach_t {
2022    /// True iff Screen Sharing successfully attached.
2023    pub success: bool,
2024    /// Type of source address.
2025    pub source_address_type: es_address_type_t,
2026    /// Optional. Source address of connection, or `NULL`. Depending on the transport used, the
2027    /// source address may or may not be available.
2028    pub source_address: es_string_token_t,
2029    /// Optional. For screen sharing initiated using an Apple ID (e.g., from Messages or FaceTime),
2030    /// this is the viewer's (client's) Apple ID. It is not necessarily the Apple ID that invited
2031    /// the screen sharing. `NULL` if unavailable.
2032    pub viewer_appleid: es_string_token_t,
2033    /// Type of authentication.
2034    pub authentication_type: es_string_token_t,
2035    /// Optional. Username used for authentication to Screen Sharing. `NULL` if authentication type
2036    /// doesn't use an username (e.g. simple VNC password).
2037    pub authentication_username: es_string_token_t,
2038    /// Optional. Username of the loginwindow session if available, `NULL` otherwise.
2039    pub session_username: es_string_token_t,
2040    /// True iff there was an existing user session.
2041    pub existing_session: bool,
2042    /// Graphical session id of the screen shared.
2043    pub graphical_session_id: es_graphical_session_id_t,
2044}
2045
2046/// Notification that Screen Sharing has detached from a graphical session.
2047///
2048/// This event type does not support caching (notify-only).
2049///
2050/// This event is not emitted when a screensharing session has the same source and destination
2051/// address.
2052#[cfg(feature = "macos_13_0_0")]
2053#[repr(C)]
2054pub struct es_event_screensharing_detach_t {
2055    /// Type of source address.
2056    pub source_address_type: es_address_type_t,
2057    /// Optional. Source address of connection, or `NULL`. Depending on the transport used, the
2058    /// source address may or may not be available.
2059    pub source_address: es_string_token_t,
2060    /// Optional. For screen sharing initiated using an Apple ID (e.g., from Messages or FaceTime),
2061    /// this is the viewer's (client's) Apple ID. It is not necessarily the Apple ID that invited
2062    /// the screen sharing. `NULL` if unavailable.
2063    pub viewer_appleid: es_string_token_t,
2064    /// Graphical session id of the screen shared.
2065    pub graphical_session_id: es_graphical_session_id_t,
2066}
2067
2068#[cfg(feature = "macos_13_0_0")]
2069ffi_wrap_enum!(
2070    /// See [`es_event_openssh_login_t`]
2071    es_openssh_login_result_type_t(u32);
2072
2073    == #[cfg(feature = "macos_13_0_0")] 13_0_0 "13.0.0";
2074    ES_OPENSSH_LOGIN_EXCEED_MAXTRIES = 0,
2075    ES_OPENSSH_LOGIN_ROOT_DENIED = 1,
2076    ES_OPENSSH_AUTH_SUCCESS = 2,
2077    ES_OPENSSH_AUTH_FAIL_NONE = 3,
2078    ES_OPENSSH_AUTH_FAIL_PASSWD = 4,
2079    ES_OPENSSH_AUTH_FAIL_KBDINT = 5,
2080    ES_OPENSSH_AUTH_FAIL_PUBKEY = 6,
2081    ES_OPENSSH_AUTH_FAIL_HOSTBASED = 7,
2082    ES_OPENSSH_AUTH_FAIL_GSSAPI = 8,
2083    --
2084    ES_OPENSSH_INVALID_USER = 9,
2085);
2086
2087/// Notification for OpenSSH login event.
2088///
2089/// This is a connection-level event. An SSH connection that is used for multiple interactive
2090/// sessions and/or non-interactive commands will emit only a single successful login event.
2091///
2092/// This event type does not support caching (notify-only).
2093#[cfg(feature = "macos_13_0_0")]
2094#[repr(C)]
2095pub struct es_event_openssh_login_t {
2096    /// True iff login was successful.
2097    pub success: bool,
2098    /// Result type for the login attempt.
2099    pub result_type: es_openssh_login_result_type_t,
2100    /// Type of source address.
2101    pub source_address_type: es_address_type_t,
2102    /// Source address of connection.
2103    pub source_address: es_string_token_t,
2104    /// Username used for login.
2105    pub username: es_string_token_t,
2106    /// Describes whether or not the uid of the user logged in is available
2107    pub has_uid: bool,
2108    /// Uid of user that was logged in.
2109    pub anon0: es_event_openssh_login_t_anon0,
2110}
2111
2112/// See [`es_event_openssh_login_t`]
2113#[cfg(feature = "macos_13_0_0")]
2114#[repr(C)]
2115pub union es_event_openssh_login_t_anon0 {
2116    /// Uid of user that was logged in.
2117    pub uid: uid_t,
2118}
2119
2120/// Notification for OpenSSH logout event.
2121///
2122/// This is a connection-level event. An SSH connection that is used for multiple interactive
2123/// sessions and/or non-interactive commands will emit only a single logout event.
2124///
2125/// This event type does not support caching (notify-only).
2126#[cfg(feature = "macos_13_0_0")]
2127#[repr(C)]
2128pub struct es_event_openssh_logout_t {
2129    /// Type of address used in the connection.
2130    pub source_address_type: es_address_type_t,
2131    /// Source address of the connection.
2132    pub source_address: es_string_token_t,
2133    /// Username which got logged out.
2134    pub username: es_string_token_t,
2135    /// uid of user that was logged out.
2136    pub uid: uid_t,
2137}
2138
2139/// Notification for authenticated login event from `/usr/bin/login`.
2140///
2141/// This event type does not support caching (notify-only).
2142#[cfg(feature = "macos_13_0_0")]
2143#[repr(C)]
2144pub struct es_event_login_login_t {
2145    /// True iff login was successful.
2146    pub success: bool,
2147    /// Optional. Failure message generated.
2148    pub failure_message: es_string_token_t,
2149    /// Username used for login.
2150    pub username: es_string_token_t,
2151    /// Describes whether or not the uid of the user logged in is available or not.
2152    pub has_uid: bool,
2153    /// Union that is valid when `has_uid` is set to `true`
2154    pub anon0: es_event_login_login_t_anon0,
2155}
2156
2157/// See [`es_event_login_login_t`]
2158#[cfg(feature = "macos_13_0_0")]
2159#[repr(C)]
2160pub union es_event_login_login_t_anon0 {
2161    /// Uid of user that was logged in.
2162    pub uid: uid_t,
2163}
2164
2165/// Notification for authenticated logout event from `/usr/bin/login`.
2166///
2167/// This event type does not support caching (notify-only).
2168#[cfg(feature = "macos_13_0_0")]
2169#[repr(C)]
2170pub struct es_event_login_logout_t {
2171    /// Username used for login.
2172    pub username: es_string_token_t,
2173    /// uid of user that was logged in.
2174    pub uid: uid_t,
2175}
2176
2177/// Notification for launch item being made known to background task management. This includes
2178/// launch agents and daemons as well as login items added by the user, via MDM or by an app.
2179///
2180/// May be emitted for items where an add was already seen previously, with or without the item
2181/// having changed.
2182///
2183/// This event type does not support caching (notify-only).
2184#[cfg(feature = "macos_13_0_0")]
2185#[repr(C)]
2186pub struct es_event_btm_launch_item_add_t {
2187    /// Optional. Process that instigated the BTM operation (XPC caller that asked for the item to
2188    /// be added).
2189    pub instigator: *mut es_process_t,
2190    /// Optional. App process that registered the item.
2191    pub app: *mut es_process_t,
2192    /// BTM launch item.
2193    pub item: ShouldNotBeNull<es_btm_launch_item_t>,
2194    /// Optional. If available and applicable, the POSIX executable path from the launchd plist. If
2195    /// the path is relative, it is relative to `item.app_url`.
2196    pub executable_path: es_string_token_t,
2197    /// Audit token of the process that instigated this event.
2198    ///
2199    /// Field available only if message version >= 8.
2200    #[cfg(feature = "macos_15_0_0")]
2201    pub instigator_token: *mut audit_token_t,
2202    /// Audit token of the app process that registered the item.
2203    ///
2204    /// Field available only if message version >= 8.
2205    #[cfg(feature = "macos_15_0_0")]
2206    pub app_token: *mut audit_token_t,
2207}
2208
2209#[cfg(feature = "macos_13_0_0")]
2210should_not_be_null_fields!(es_event_btm_launch_item_add_t; item -> es_btm_launch_item_t);
2211#[cfg(feature = "macos_13_0_0")]
2212null_fields!(
2213    es_event_btm_launch_item_add_t;
2214    instigator -> es_process_t,
2215    app -> es_process_t
2216);
2217#[cfg(feature = "macos_15_0_0")]
2218null_fields!(
2219    es_event_btm_launch_item_add_t;
2220    instigator_token -> audit_token_t,
2221    app_token -> audit_token_t,
2222);
2223
2224/// Notification for launch item being removed from background
2225///        task management.  This includes launch agents and daemons as
2226///        well as login items added by the user, via MDM or by an app.
2227///
2228/// This event type does not support caching (notify-only).
2229#[cfg(feature = "macos_13_0_0")]
2230#[repr(C)]
2231pub struct es_event_btm_launch_item_remove_t {
2232    /// Optional. Process that instigated the BTM operation (XPC caller that asked for the item to
2233    /// be added).
2234    pub instigator: *mut es_process_t,
2235    /// Optional. App process that registered the item.
2236    pub app: *mut es_process_t,
2237    /// BTM launch item.
2238    pub item: ShouldNotBeNull<es_btm_launch_item_t>,
2239    /// Audit token of the process that instigated this event.
2240    ///
2241    /// Field available only if message version >= 8.
2242    #[cfg(feature = "macos_15_0_0")]
2243    pub instigator_token: *mut audit_token_t,
2244    /// Audit token of the app process that removed the item.
2245    ///
2246    /// Field available only if message version >= 8.
2247    #[cfg(feature = "macos_15_0_0")]
2248    pub app_token: *mut audit_token_t,
2249}
2250
2251#[cfg(feature = "macos_13_0_0")]
2252should_not_be_null_fields!(es_event_btm_launch_item_remove_t; item -> es_btm_launch_item_t);
2253#[cfg(feature = "macos_13_0_0")]
2254null_fields!(
2255    es_event_btm_launch_item_remove_t;
2256    instigator -> es_process_t,
2257    app -> es_process_t,
2258);
2259#[cfg(feature = "macos_15_0_0")]
2260null_fields!(
2261    es_event_btm_launch_item_remove_t;
2262    instigator_token -> audit_token_t,
2263    app_token -> audit_token_t,
2264);
2265
2266/// Notification for a su policy decisions events.
2267///
2268/// This event type does not support caching (notify-only). Should always
2269/// emit on success but will only emit on security relevant failures. For example,
2270/// Endpoint Security clients will not get an event for `su` being passed invalid
2271/// command line arguments.
2272#[cfg(feature = "macos_14_0_0")]
2273#[repr(C)]
2274pub struct es_event_su_t {
2275    /// True iff su was successful.
2276    pub success: bool,
2277    /// Optional. If success is false, a failure message is contained in this field
2278    pub failure_message: es_string_token_t,
2279    /// The uid of the user who initiated the su
2280    pub from_uid: uid_t,
2281    /// The name of the user who initiated the su
2282    pub from_username: es_string_token_t,
2283    /// True iff su was successful, Describes whether or not the to_uid is interpretable
2284    pub has_to_uid: bool,
2285    /// Optional. If success, the user ID that is going to be substituted
2286    pub to_uid: es_event_su_t_anon0,
2287    /// Optional. If success, the user name that is going to be substituted
2288    pub to_username: es_string_token_t,
2289    /// Optional. If success, the shell is going to execute
2290    pub shell: es_string_token_t,
2291    /// The length of argv
2292    pub argc: usize,
2293    /// If success, the arguments are passed into to the shell
2294    pub argv: *mut es_string_token_t,
2295    /// The length of env
2296    pub env_count: usize,
2297    /// If success, list of environment variables that is going to be substituted
2298    pub env: *mut es_string_token_t,
2299}
2300
2301/// See [`es_event_su_t`]
2302#[cfg(feature = "macos_14_0_0")]
2303#[repr(C)]
2304pub union es_event_su_t_anon0 {
2305    pub uid: uid_t,
2306}
2307
2308/// Provides context about failures in [`es_event_sudo_t`].
2309#[cfg(feature = "macos_14_0_0")]
2310#[repr(C)]
2311pub struct es_sudo_reject_info_t {
2312    /// The sudo plugin that initiated the reject
2313    pub plugin_name: es_string_token_t,
2314    /// The sudo plugin type that initiated the reject
2315    pub plugin_type: es_sudo_plugin_type_t,
2316    /// A reason represented by a string for the failure
2317    pub failure_message: es_string_token_t,
2318}
2319
2320/// Notification for a sudo event.
2321///
2322/// This event type does not support caching (notify-only).
2323#[cfg(feature = "macos_14_0_0")]
2324#[repr(C)]
2325pub struct es_event_sudo_t {
2326    /// True iff sudo was successful
2327    pub success: bool,
2328    /// Optional. When success is false, describes why sudo was rejected
2329    pub reject_info: *mut es_sudo_reject_info_t,
2330    /// Describes whether or not the from_uid is interpretable
2331    pub has_from_uid: bool,
2332    /// Optional. The uid of the user who initiated the su
2333    pub from_uid: es_event_sudo_t_anon0,
2334    /// Optional. The name of the user who initiated the su
2335    pub from_username: es_string_token_t,
2336    /// Describes whether or not the to_uid is interpretable
2337    pub has_to_uid: bool,
2338    /// Optional. If success, the user ID that is going to be substituted
2339    pub to_uid: es_event_sudo_t_anon0,
2340    /// Optional. If success, the user name that is going to be substituted
2341    pub to_username: es_string_token_t,
2342    /// Optional. The command to be run
2343    pub command: es_string_token_t,
2344}
2345
2346#[cfg(feature = "macos_14_0_0")]
2347null_fields!(es_event_sudo_t; reject_info -> es_sudo_reject_info_t);
2348
2349/// [`es_event_sudo_t`]
2350#[cfg(feature = "macos_14_0_0")]
2351#[repr(C)]
2352pub union es_event_sudo_t_anon0 {
2353    pub uid: uid_t,
2354}
2355
2356/// Notification for Profiles installed on the system.
2357///
2358/// This event type does not support caching (notify-only).
2359#[cfg(feature = "macos_14_0_0")]
2360#[repr(C)]
2361pub struct es_event_profile_add_t {
2362    /// Process that instigated the Profile install or update.
2363    pub instigator: *mut es_process_t,
2364    /// Indicates if the profile is an update to an already installed profile.
2365    pub is_update: bool,
2366    /// Profile install item.
2367    pub profile: ShouldNotBeNull<es_profile_t>,
2368    /// Audit token of the process that instigated this event.
2369    ///
2370    /// Field available only if message version >= 8.
2371    #[cfg(feature = "macos_15_0_0")]
2372    pub instigator_token: audit_token_t,
2373}
2374
2375#[cfg(feature = "macos_14_0_0")]
2376should_not_be_null_fields!(es_event_profile_add_t; profile -> es_profile_t);
2377#[cfg(feature = "macos_14_0_0")]
2378null_fields!(es_event_profile_add_t; instigator -> es_process_t);
2379
2380/// Notification for Profiles removed on the system.
2381///
2382/// This event type does not support caching (notify-only).
2383#[cfg(feature = "macos_14_0_0")]
2384#[repr(C)]
2385pub struct es_event_profile_remove_t {
2386    /// Process that instigated the Profile removal.
2387    pub instigator: *mut es_process_t,
2388    /// Profile being removed.
2389    pub profile: ShouldNotBeNull<es_profile_t>,
2390    /// Audit token of the process that instigated this event.
2391    ///
2392    /// Field available only if message version >= 8.
2393    #[cfg(feature = "macos_15_0_0")]
2394    pub instigator_token: audit_token_t,
2395}
2396
2397#[cfg(feature = "macos_14_0_0")]
2398should_not_be_null_fields!(es_event_profile_remove_t; profile -> es_profile_t);
2399#[cfg(feature = "macos_14_0_0")]
2400null_fields!(es_event_profile_remove_t; instigator -> es_process_t);
2401
2402/// Notification that a process petitioned for certain authorization rights
2403///
2404/// This event type does not support caching (notify-only).
2405#[cfg(feature = "macos_14_0_0")]
2406#[repr(C)]
2407pub struct es_event_authorization_petition_t {
2408    /// Process that submitted the petition (XPC caller)
2409    pub instigator: *mut es_process_t,
2410    /// Process that created the petition
2411    pub petitioner: *mut es_process_t,
2412    /// Flags associated with the petition. Defined in Security framework "Authorization/Authorization.h"
2413    pub flags: u32,
2414    /// The number of elements in `rights`
2415    pub right_count: usize,
2416    /// Array of string tokens, each token is the name of a right being requested
2417    pub rights: *mut es_string_token_t,
2418    /// Audit token of the process that instigated this event.
2419    ///
2420    /// Field available only if message version >= 8.
2421    #[cfg(feature = "macos_15_0_0")]
2422    pub instigator_token: audit_token_t,
2423    /// Audit token of the process that created the petition.
2424    ///
2425    /// Field available only if message version >= 8.
2426    #[cfg(feature = "macos_15_0_0")]
2427    pub petitioner_token: audit_token_t,
2428}
2429
2430#[cfg(feature = "macos_14_0_0")]
2431null_fields!(es_event_authorization_petition_t; instigator -> es_process_t, petitioner -> es_process_t);
2432
2433/// Describes, for a single right, the class of that right and if it was granted
2434#[cfg(feature = "macos_14_0_0")]
2435#[repr(C)]
2436pub struct es_authorization_result_t {
2437    /// The name of the right being considered
2438    pub right_name: es_string_token_t,
2439    /// The class of the right being considered
2440    ///
2441    /// The rule class determines how the operating system determines if it should be granted or not
2442    pub rule_class: es_authorization_rule_class_t,
2443    /// Indicates if the right was granted or not
2444    pub granted: bool,
2445}
2446
2447/// Notification that a process had it's right petition judged
2448///
2449/// This event type does not support caching (notify-only).
2450#[cfg(feature = "macos_14_0_0")]
2451#[repr(C)]
2452pub struct es_event_authorization_judgement_t {
2453    /// Process that submitted the petition (XPC caller)
2454    pub instigator: *mut es_process_t,
2455    /// Process that created the petition
2456    pub petitioner: *mut es_process_t,
2457    /// The overall result of the petition. 0 indicates success.
2458    ///
2459    /// Possible return codes are defined in Security framework "Authorization/Authorization.h"
2460    pub return_code: i32,
2461    /// The number of elements in `results`
2462    pub result_count: usize,
2463    /// Array of results. One for each right that was petitioned
2464    pub results: *mut es_authorization_result_t,
2465    /// Audit token of the process that instigated this event.
2466    ///
2467    /// Field available only if message version >= 8.
2468    #[cfg(feature = "macos_15_0_0")]
2469    pub instigator_token: audit_token_t,
2470    /// Audit token of the process that created the petition.
2471    ///
2472    /// Field available only if message version >= 8.
2473    #[cfg(feature = "macos_15_0_0")]
2474    pub petitioner_token: audit_token_t,
2475}
2476
2477#[cfg(feature = "macos_14_0_0")]
2478null_fields!(es_event_authorization_judgement_t; instigator -> es_process_t, petitioner -> es_process_t);
2479
2480/// The identity of a group member
2481#[cfg(feature = "macos_14_0_0")]
2482#[repr(C)]
2483pub struct es_od_member_id_t {
2484    /// Indicates the type of the member, and how it is identified.
2485    ///
2486    /// Note that member_type indicates which field of member_value is initialised.
2487    pub member_type: es_od_member_type_t,
2488    /// The member identity.
2489    pub member_value: es_od_member_id_t_anon0,
2490}
2491
2492/// See [`es_od_member_id_t`]
2493#[cfg(feature = "macos_14_0_0")]
2494#[repr(C)]
2495pub union es_od_member_id_t_anon0 {
2496    pub uuid: uuid_t,
2497    pub name: ManuallyDrop<es_string_token_t>,
2498}
2499
2500/// Notification that a member was added to a group.
2501///
2502/// This event type does not support caching (notify-only).
2503///
2504/// This event does not indicate that a member was actually added. For example when adding a user
2505/// to a group they are already a member of.
2506#[cfg(feature = "macos_14_0_0")]
2507#[repr(C)]
2508pub struct es_event_od_group_add_t {
2509    /// Process that instigated operation (XPC caller).
2510    pub instigator: *mut es_process_t,
2511    /// Result code for the operation.
2512    pub error_code: i32,
2513    /// The group to which the member was added.
2514    pub group_name: es_string_token_t,
2515    /// The identity of the member added.
2516    pub member: ShouldNotBeNull<es_od_member_id_t>,
2517    /// OD node being mutated.
2518    ///
2519    /// Typically one of "/Local/Default", "/LDAPv3/<server>" or "/Active Directory/<domain>".
2520    pub node_name: es_string_token_t,
2521    /// Optional. If node_name is "/Local/Default", this is, the path of the database against which
2522    /// OD is authenticating.
2523    pub db_path: es_string_token_t,
2524    /// Audit token of the process that instigated this event.
2525    ///
2526    /// Field available only if message version >= 8.
2527    #[cfg(feature = "macos_15_0_0")]
2528    pub instigator_token: audit_token_t,
2529}
2530
2531#[cfg(feature = "macos_14_0_0")]
2532null_fields!(es_event_od_group_add_t; instigator -> es_process_t);
2533
2534/// Notification that a member was removed to a group.
2535///
2536/// This event type does not support caching (notify-only).
2537///
2538/// This event does not indicate that a member was actually removed. For example when removing a
2539/// user from a group they are not a member of.
2540#[cfg(feature = "macos_14_0_0")]
2541#[repr(C)]
2542pub struct es_event_od_group_remove_t {
2543    /// Process that instigated operation (XPC caller).
2544    pub instigator: *mut es_process_t,
2545    /// Result code for the operation.
2546    pub error_code: i32,
2547    /// The group to which the member was removed.
2548    pub group_name: es_string_token_t,
2549    /// The identity of the member removed.
2550    pub member: ShouldNotBeNull<es_od_member_id_t>,
2551    /// OD node being mutated.
2552    ///
2553    /// Typically one of "/Local/Default", "/LDAPv3/<server>" or "/Active Directory/<domain>".
2554    pub node_name: es_string_token_t,
2555    /// Optional. If node_name is "/Local/Default", this is, the path of the database against which
2556    /// OD is authenticating.
2557    pub db_path: es_string_token_t,
2558    /// Audit token of the process that instigated this event.
2559    ///
2560    /// Field available only if message version >= 8.
2561    #[cfg(feature = "macos_15_0_0")]
2562    pub instigator_token: audit_token_t,
2563}
2564
2565#[cfg(feature = "macos_14_0_0")]
2566null_fields!(es_event_od_group_remove_t; instigator -> es_process_t);
2567
2568/// An array of group member identities.
2569#[cfg(feature = "macos_14_0_0")]
2570#[repr(C)]
2571pub struct es_od_member_id_array_t {
2572    /// Indicates the type of the members, and how they are identified.
2573    ///
2574    /// Note that `member_type` indicates which field of member_array is initialised.
2575    pub member_type: es_od_member_type_t,
2576    /// The number of elements in `member_array`.
2577    pub member_count: usize,
2578    /// A union of pointers.
2579    ///
2580    /// The initialised member points to the first element of an array of member values.
2581    pub member_array: es_od_member_id_array_t_anon0,
2582}
2583
2584/// See [`es_od_member_id_array_t`]
2585#[cfg(feature = "macos_14_0_0")]
2586#[repr(C)]
2587pub union es_od_member_id_array_t_anon0 {
2588    pub uuids: ShouldNotBeNull<uuid_t>,
2589    pub names: ShouldNotBeNull<es_string_token_t>,
2590}
2591
2592/// Notification that a group had it's members initialised or replaced.
2593///
2594/// This event type does not support caching (notify-only).
2595#[cfg(feature = "macos_14_0_0")]
2596#[repr(C)]
2597pub struct es_event_od_group_set_t {
2598    /// Process that instigated operation (XPC caller).
2599    pub instigator: *mut es_process_t,
2600    /// Result code for the operation.
2601    ///
2602    /// Values indicating specific failure reasons are defined in odconstants.h.
2603    pub error_code: i32,
2604    /// The group to which members were set.
2605    pub group_name: es_string_token_t,
2606    /// Array of new members.
2607    pub members: ShouldNotBeNull<es_od_member_id_array_t>,
2608    /// OD node being mutated.
2609    ///
2610    /// Typically one of "/Local/Default", "/LDAPv3/<server>" or "/Active Directory/<domain>".
2611    pub node_name: es_string_token_t,
2612    /// Optional. If node_name is "/Local/Default", this is, the path of the database against which
2613    /// OD is authenticating.
2614    pub db_path: es_string_token_t,
2615    /// Audit token of the process that instigated this event.
2616    ///
2617    /// Field available only if message version >= 8.
2618    #[cfg(feature = "macos_15_0_0")]
2619    pub instigator_token: audit_token_t,
2620}
2621
2622#[cfg(feature = "macos_14_0_0")]
2623null_fields!(es_event_od_group_set_t; instigator -> es_process_t);
2624
2625/// Notification that an account had its password modified.
2626///
2627/// This event type does not support caching (notify-only).
2628#[cfg(feature = "macos_14_0_0")]
2629#[repr(C)]
2630pub struct es_event_od_modify_password_t {
2631    /// Process that instigated operation (XPC caller).
2632    pub instigator: *mut es_process_t,
2633    /// Result code for the operation.
2634    ///
2635    /// Values indicating specific failure reasons are defined in odconstants.h.
2636    pub error_code: i32,
2637    /// The type of the account for which the password was modified.
2638    pub account_type: es_od_account_type_t,
2639    /// The name of the account for which the password was modified.
2640    pub account_name: es_string_token_t,
2641    /// OD node being mutated.
2642    ///
2643    /// Typically one of "/Local/Default", "/LDAPv3/<server>" or "/Active Directory/<domain>".
2644    pub node_name: es_string_token_t,
2645    /// Optional. If node_name is "/Local/Default", this is, the path of the database against which
2646    /// OD is authenticating.
2647    pub db_path: es_string_token_t,
2648    /// Audit token of the process that instigated this event.
2649    ///
2650    /// Field available only if message version >= 8.
2651    #[cfg(feature = "macos_15_0_0")]
2652    pub instigator_token: audit_token_t,
2653}
2654
2655#[cfg(feature = "macos_14_0_0")]
2656null_fields!(es_event_od_modify_password_t; instigator -> es_process_t);
2657
2658/// Notification that a user account was disabled.
2659///
2660/// This event type does not support caching (notify-only).
2661#[cfg(feature = "macos_14_0_0")]
2662#[repr(C)]
2663pub struct es_event_od_disable_user_t {
2664    /// Process that instigated operation (XPC caller).
2665    pub instigator: *mut es_process_t,
2666    /// Result code for the operation.
2667    ///
2668    /// Values indicating specific failure reasons are defined in odconstants.h.
2669    pub error_code: i32,
2670    /// The name of the user account that was disabled.
2671    pub user_name: es_string_token_t,
2672    /// OD node being mutated.
2673    ///
2674    /// Typically one of "/Local/Default", "/LDAPv3/<server>" or "/Active Directory/<domain>".
2675    pub node_name: es_string_token_t,
2676    /// Optional. If node_name is "/Local/Default", this is, the path of the database against which
2677    /// OD is authenticating.
2678    pub db_path: es_string_token_t,
2679    /// Audit token of the process that instigated this event.
2680    ///
2681    /// Field available only if message version >= 8.
2682    #[cfg(feature = "macos_15_0_0")]
2683    pub instigator_token: audit_token_t,
2684}
2685
2686#[cfg(feature = "macos_14_0_0")]
2687null_fields!(es_event_od_disable_user_t; instigator -> es_process_t);
2688
2689/// Notification that a user account was enabled.
2690///
2691/// This event type does not support caching (notify-only).
2692#[cfg(feature = "macos_14_0_0")]
2693#[repr(C)]
2694pub struct es_event_od_enable_user_t {
2695    /// Process that instigated operation (XPC caller).
2696    pub instigator: *mut es_process_t,
2697    /// Result code for the operation.
2698    ///
2699    /// Values indicating specific failure reasons are defined in odconstants.h.
2700    pub error_code: i32,
2701    /// The name of the user account that was enabled.
2702    pub user_name: es_string_token_t,
2703    /// OD node being mutated.
2704    ///
2705    /// Typically one of "/Local/Default", "/LDAPv3/<server>" or "/Active Directory/<domain>".
2706    pub node_name: es_string_token_t,
2707    /// Optional. If node_name is "/Local/Default", this is, the path of the database against which
2708    /// OD is authenticating.
2709    pub db_path: es_string_token_t,
2710    /// Audit token of the process that instigated this event.
2711    ///
2712    /// Field available only if message version >= 8.
2713    #[cfg(feature = "macos_15_0_0")]
2714    pub instigator_token: audit_token_t,
2715}
2716
2717#[cfg(feature = "macos_14_0_0")]
2718null_fields!(es_event_od_enable_user_t; instigator -> es_process_t);
2719
2720/// Notification that an attribute value was added to a record.
2721///
2722/// This event type does not support caching (notify-only).
2723///
2724/// Attributes conceptually have the type `Map String (Set String)`.
2725/// Each OD record has a Map of attribute name to Set of attribute value.
2726/// When an attribute value is added, it is inserted into the set of values for that name.
2727#[cfg(feature = "macos_14_0_0")]
2728#[repr(C)]
2729pub struct es_event_od_attribute_value_add_t {
2730    /// Process that instigated operation (XPC caller).
2731    pub instigator: *mut es_process_t,
2732    /// Result code for the operation.
2733    ///
2734    /// Values indicating specific failure reasons are defined in odconstants.h.
2735    pub error_code: i32,
2736    /// The type of the record to which the attribute value was added.
2737    pub record_type: es_od_record_type_t,
2738    /// The name of the record to which the attribute value was added.
2739    pub record_name: es_string_token_t,
2740    /// The name of the attribute to which the value was added.
2741    pub attribute_name: es_string_token_t,
2742    /// The value that was added.
2743    pub attribute_value: es_string_token_t,
2744    /// OD node being mutated.
2745    ///
2746    /// Typically one of "/Local/Default", "/LDAPv3/<server>" or "/Active Directory/<domain>".
2747    pub node_name: es_string_token_t,
2748    /// Optional. If node_name is "/Local/Default", this is, the path of the database against which
2749    /// OD is authenticating.
2750    pub db_path: es_string_token_t,
2751    /// Audit token of the process that instigated this event.
2752    ///
2753    /// Field available only if message version >= 8.
2754    #[cfg(feature = "macos_15_0_0")]
2755    pub instigator_token: audit_token_t,
2756}
2757
2758#[cfg(feature = "macos_14_0_0")]
2759null_fields!(es_event_od_attribute_value_add_t; instigator -> es_process_t);
2760
2761/// Notification that an attribute value was removed to a record.
2762///
2763/// This event type does not support caching (notify-only).
2764///
2765/// Attributes conceptually have the type `Map String (Set String)`.
2766/// Each OD record has a Map of attribute name to Set of attribute value.
2767/// When an attribute value is removed, it is inserted into the set of values for that name.
2768///
2769/// Removing a value that was never added is a no-op.
2770#[cfg(feature = "macos_14_0_0")]
2771#[repr(C)]
2772pub struct es_event_od_attribute_value_remove_t {
2773    /// Process that instigated operation (XPC caller).
2774    pub instigator: *mut es_process_t,
2775    /// Result code for the operation.
2776    ///
2777    /// Values indicating specific failure reasons are defined in odconstants.h.
2778    pub error_code: i32,
2779    /// The type of the record to which the attribute value was removed.
2780    pub record_type: es_od_record_type_t,
2781    /// The name of the record to which the attribute value was removed.
2782    pub record_name: es_string_token_t,
2783    /// The name of the attribute to which the value was removed.
2784    pub attribute_name: es_string_token_t,
2785    /// The value that was removed.
2786    pub attribute_value: es_string_token_t,
2787    /// OD node being mutated.
2788    ///
2789    /// Typically one of "/Local/Default", "/LDAPv3/<server>" or "/Active Directory/<domain>".
2790    pub node_name: es_string_token_t,
2791    /// Optional. If node_name is "/Local/Default", this is, the path of the database against which
2792    /// OD is authenticating.
2793    pub db_path: es_string_token_t,
2794    /// Audit token of the process that instigated this event.
2795    ///
2796    /// Field available only if message version >= 8.
2797    #[cfg(feature = "macos_15_0_0")]
2798    pub instigator_token: audit_token_t,
2799}
2800
2801#[cfg(feature = "macos_14_0_0")]
2802null_fields!(es_event_od_attribute_value_remove_t; instigator -> es_process_t);
2803
2804/// Notification that an attribute is being set.
2805///
2806/// This event type does not support caching (notify-only).
2807///
2808/// Attributes conceptually have the type `Map String (Set String)`.
2809/// Each OD record has a Map of attribute name to Set of attribute value.
2810/// When an attribute value is added, it is inserted into the set of values for that name.
2811///
2812/// The new set of attribute values may be empty.
2813#[cfg(feature = "macos_14_0_0")]
2814#[repr(C)]
2815pub struct es_event_od_attribute_set_t {
2816    /// Process that instigated operation (XPC caller).
2817    pub instigator: *mut es_process_t,
2818    /// Result code for the operation.
2819    ///
2820    /// Values indicating specific failure reasons are defined in odconstants.h.
2821    pub error_code: i32,
2822    /// The type of the record for which the attribute is being set.
2823    pub record_type: es_od_record_type_t,
2824    /// The name of the record for which the attribute is being set.
2825    pub record_name: es_string_token_t,
2826    /// The name of the attribute that was set.
2827    pub attribute_name: es_string_token_t,
2828    /// The size of attribute_value_array.
2829    pub attribute_value_count: usize,
2830    /// Array of attribute values that were set.
2831    pub attribute_value_array: *mut es_string_token_t,
2832    /// OD node being mutated.
2833    ///
2834    /// Typically one of "/Local/Default", "/LDAPv3/<server>" or "/Active Directory/<domain>".
2835    pub node_name: es_string_token_t,
2836    /// Optional. If node_name is "/Local/Default", this is, the path of the database against which
2837    /// OD is authenticating.
2838    pub db_path: es_string_token_t,
2839    /// Audit token of the process that instigated this event.
2840    ///
2841    /// Field available only if message version >= 8.
2842    #[cfg(feature = "macos_15_0_0")]
2843    pub instigator_token: audit_token_t,
2844}
2845
2846#[cfg(feature = "macos_14_0_0")]
2847null_fields!(es_event_od_attribute_set_t; instigator -> es_process_t);
2848
2849/// Notification that a user account was created.
2850///
2851/// This event type does not support caching (notify-only).
2852#[cfg(feature = "macos_14_0_0")]
2853#[repr(C)]
2854pub struct es_event_od_create_user_t {
2855    /// Process that instigated operation (XPC caller).
2856    pub instigator: *mut es_process_t,
2857    /// Result code for the operation.
2858    ///
2859    /// Values indicating specific failure reasons are defined in odconstants.h.
2860    pub error_code: i32,
2861    /// The name of the user account that was created.
2862    pub user_name: es_string_token_t,
2863    /// OD node being mutated.
2864    ///
2865    /// Typically one of "/Local/Default", "/LDAPv3/<server>" or "/Active Directory/<domain>".
2866    pub node_name: es_string_token_t,
2867    /// Optional. If node_name is "/Local/Default", this is, the path of the database against which
2868    /// OD is authenticating.
2869    pub db_path: es_string_token_t,
2870    /// Audit token of the process that instigated this event.
2871    ///
2872    /// Field available only if message version >= 8.
2873    #[cfg(feature = "macos_15_0_0")]
2874    pub instigator_token: audit_token_t,
2875}
2876
2877#[cfg(feature = "macos_14_0_0")]
2878null_fields!(es_event_od_create_user_t; instigator -> es_process_t);
2879
2880/// Notification that a group was created.
2881///
2882/// This event type does not support caching (notify-only).
2883#[cfg(feature = "macos_14_0_0")]
2884#[repr(C)]
2885pub struct es_event_od_create_group_t {
2886    /// Process that instigated operation (XPC caller).
2887    pub instigator: *mut es_process_t,
2888    /// Result code for the operation.
2889    ///
2890    /// Values indicating specific failure reasons are defined in odconstants.h.
2891    pub error_code: i32,
2892    /// The name of the group account that was created.
2893    pub group_name: es_string_token_t,
2894    /// OD node being mutated.
2895    ///
2896    /// Typically one of "/Local/Default", "/LDAPv3/<server>" or "/Active Directory/<domain>".
2897    pub node_name: es_string_token_t,
2898    /// Optional. If node_name is "/Local/Default", this is, the path of the database against which
2899    /// OD is authenticating.
2900    pub db_path: es_string_token_t,
2901    /// Audit token of the process that instigated this event.
2902    ///
2903    /// Field available only if message version >= 8.
2904    #[cfg(feature = "macos_15_0_0")]
2905    pub instigator_token: audit_token_t,
2906}
2907
2908#[cfg(feature = "macos_14_0_0")]
2909null_fields!(es_event_od_create_group_t; instigator -> es_process_t);
2910
2911/// Notification that a user account was deleted.
2912///
2913/// This event type does not support caching (notify-only).
2914#[cfg(feature = "macos_14_0_0")]
2915#[repr(C)]
2916pub struct es_event_od_delete_user_t {
2917    /// Process that instigated operation (XPC caller).
2918    pub instigator: *mut es_process_t,
2919    /// Result code for the operation.
2920    ///
2921    /// Values indicating specific failure reasons are defined in odconstants.h.
2922    pub error_code: i32,
2923    /// The name of the user account that was deleted.
2924    pub user_name: es_string_token_t,
2925    /// OD node being mutated.
2926    ///
2927    /// Typically one of "/Local/Default", "/LDAPv3/<server>" or "/Active Directory/<domain>".
2928    pub node_name: es_string_token_t,
2929    /// Optional. If node_name is "/Local/Default", this is, the path of the database against which
2930    /// OD is authenticating.
2931    pub db_path: es_string_token_t,
2932    /// Audit token of the process that instigated this event.
2933    ///
2934    /// Field available only if message version >= 8.
2935    #[cfg(feature = "macos_15_0_0")]
2936    pub instigator_token: audit_token_t,
2937}
2938
2939#[cfg(feature = "macos_14_0_0")]
2940null_fields!(es_event_od_delete_user_t; instigator -> es_process_t);
2941
2942/// Notification that a group was deleted.
2943///
2944/// This event type does not support caching (notify-only).
2945#[cfg(feature = "macos_14_0_0")]
2946#[repr(C)]
2947pub struct es_event_od_delete_group_t {
2948    /// Process that instigated operation (XPC caller).
2949    pub instigator: *mut es_process_t,
2950    /// Result code for the operation.
2951    ///
2952    /// Values indicating specific failure reasons are defined in odconstants.h.
2953    pub error_code: i32,
2954    /// The name of the group account that was deleted.
2955    pub group_name: es_string_token_t,
2956    /// OD node being mutated.
2957    ///
2958    /// Typically one of "/Local/Default", "/LDAPv3/<server>" or "/Active Directory/<domain>".
2959    pub node_name: es_string_token_t,
2960    /// Optional. If node_name is "/Local/Default", this is, the path of the database against which
2961    /// OD is authenticating.
2962    pub db_path: es_string_token_t,
2963    /// Audit token of the process that instigated this event.
2964    ///
2965    /// Field available only if message version >= 8.
2966    #[cfg(feature = "macos_15_0_0")]
2967    pub instigator_token: audit_token_t,
2968}
2969
2970#[cfg(feature = "macos_14_0_0")]
2971null_fields!(es_event_od_delete_group_t; instigator -> es_process_t);
2972
2973/// Notification for an XPC connection being established to a named service.
2974#[cfg(feature = "macos_14_0_0")]
2975#[repr(C)]
2976pub struct es_event_xpc_connect_t {
2977    /// Service name of the named service.
2978    pub service_name: es_string_token_t,
2979    /// The type of XPC domain in which the service resides in.
2980    pub service_domain_type: es_xpc_domain_type_t,
2981}
2982
2983/// See [`es_event_gatekeeper_user_override_t`]
2984#[cfg(feature = "macos_15_0_0")]
2985#[repr(C)]
2986pub union es_event_gatekeeper_user_override_t_anon0 {
2987    pub file_path: ManuallyDrop<es_string_token_t>,
2988    pub file: ShouldNotBeNull<es_file_t>,
2989}
2990#[cfg(feature = "macos_15_0_0")]
2991should_not_be_null_fields!(es_event_gatekeeper_user_override_t_anon0; file -> es_file_t);
2992
2993/// Notification for a gatekeeper_user_override event.
2994///
2995/// This event type does not support caching (notify-only).
2996///
2997/// Hashes are calculated in usermode by Gatekeeper. There is no guarantee that
2998/// any other program including the kernel will observe the same file at the
2999/// reported path. Furthermore, there is no guarantee that the CDHash is valid
3000/// or that it matches the containing binary.
3001#[cfg(feature = "macos_15_0_0")]
3002#[repr(C)]
3003pub struct es_event_gatekeeper_user_override_t {
3004    /// The type of the file field.
3005    ///
3006    /// If Endpoint security can't lookup the file at event submission it will
3007    /// emit a path instead of an es_file_t.
3008    pub file_type: es_gatekeeper_user_override_file_type_t,
3009    /// Describes the target file that is being overridden by the user.
3010    pub file: es_event_gatekeeper_user_override_t_anon0,
3011    /// SHA256 of the file. Provided if the filesize is less than 100MB.
3012    pub sha256: *mut es_sha256_t,
3013    /// Signing Information, available if the file has been signed.
3014    pub signing_info: *mut es_signed_file_info_t,
3015}
3016
3017#[cfg(feature = "macos_15_0_0")]
3018null_fields!(
3019    es_event_gatekeeper_user_override_t;
3020    sha256 -> es_sha256_t,
3021    signing_info -> es_signed_file_info_t
3022);
3023
3024/// TCC Modification Event.
3025///
3026/// Occurs when a TCC permission is granted or revoked.
3027///
3028/// Note: This event type does not support caching.
3029#[cfg(feature = "macos_15_4_0")]
3030#[repr(C)]
3031pub struct es_event_tcc_modify_t {
3032    /// The TCC service for which permissions are being modified.
3033    pub service: es_string_token_t,
3034    /// The identity of the application that is the subject of the permission.
3035    pub identity: es_string_token_t,
3036    /// The identity type of the application string (Bundle ID, path, etc).
3037    pub identity_type: es_tcc_identity_type_t,
3038    /// The type of TCC modification event (Grant/Revoke etc)
3039    pub update_type: es_tcc_event_type_t,
3040    /// Audit token of the instigator of the modification.
3041    pub instigator_token: audit_token_t,
3042    /// (Optional) The process information for the instigator.
3043    pub instigator: *mut es_process_t,
3044    /// (Optional) Audit token of the responsible process for the modification.
3045    pub responsible_token: *mut audit_token_t,
3046    /// (Optional) The process information for the responsible process.
3047    pub responsible: *mut es_process_t,
3048    /// The resulting TCC permission of the operation/modification.
3049    pub right: es_tcc_authorization_right_t,
3050    /// The reason the TCC permissions were updated.
3051    pub reason: es_tcc_authorization_reason_t,
3052}
3053
3054#[cfg(feature = "macos_15_4_0")]
3055null_fields!(
3056    es_event_tcc_modify_t;
3057    instigator -> es_process_t,
3058    responsible_token -> audit_token_t,
3059    responsible -> es_process_t,
3060);
3061
3062/// Union of all possible events that can appear in an [`es_message_t`]
3063#[repr(C)]
3064pub union es_events_t {
3065    // Events added before macOS 13.0.0 use structs directly.
3066    //
3067    // Originally this union is sorted according to the members' names. Here we first sort it by
3068    // version to make it easy to track what was first added when. Note that events can be added
3069    // as AUTH in a version and NOTIFY in another. The first appeareance is the one used for the
3070    // sorting here.
3071
3072    // 10.15.0
3073    pub close: ManuallyDrop<es_event_close_t>,
3074    pub create: ManuallyDrop<es_event_create_t>,
3075    pub exchangedata: ManuallyDrop<es_event_exchangedata_t>,
3076    pub exec: ManuallyDrop<es_event_exec_t>,
3077    pub exit: ManuallyDrop<es_event_exit_t>,
3078    pub file_provider_materialize: ManuallyDrop<es_event_file_provider_materialize_t>,
3079    pub file_provider_update: ManuallyDrop<es_event_file_provider_update_t>,
3080    pub fork: ManuallyDrop<es_event_fork_t>,
3081    pub get_task: ManuallyDrop<es_event_get_task_t>,
3082    pub iokit_open: ManuallyDrop<es_event_iokit_open_t>,
3083    pub kextload: ManuallyDrop<es_event_kextload_t>,
3084    pub kextunload: ManuallyDrop<es_event_kextunload_t>,
3085    pub link: ManuallyDrop<es_event_link_t>,
3086    pub lookup: ManuallyDrop<es_event_lookup_t>,
3087    pub mmap: ManuallyDrop<es_event_mmap_t>,
3088    pub mount: ManuallyDrop<es_event_mount_t>,
3089    pub mprotect: ManuallyDrop<es_event_mprotect_t>,
3090    pub open: ManuallyDrop<es_event_open_t>,
3091    pub readlink: ManuallyDrop<es_event_readlink_t>,
3092    pub rename: ManuallyDrop<es_event_rename_t>,
3093    pub setattrlist: ManuallyDrop<es_event_setattrlist_t>,
3094    pub setextattr: ManuallyDrop<es_event_setextattr_t>,
3095    pub setflags: ManuallyDrop<es_event_setflags_t>,
3096    pub setmode: ManuallyDrop<es_event_setmode_t>,
3097    pub setowner: ManuallyDrop<es_event_setowner_t>,
3098    pub signal: ManuallyDrop<es_event_signal_t>,
3099    pub truncate: ManuallyDrop<es_event_truncate_t>,
3100    pub unlink: ManuallyDrop<es_event_unlink_t>,
3101    pub unmount: ManuallyDrop<es_event_unmount_t>,
3102    pub write: ManuallyDrop<es_event_write_t>,
3103
3104    // 10.15.1
3105    #[cfg(feature = "macos_10_15_1")]
3106    pub access: ManuallyDrop<es_event_access_t>,
3107    #[cfg(feature = "macos_10_15_1")]
3108    pub chdir: ManuallyDrop<es_event_chdir_t>,
3109    #[cfg(feature = "macos_10_15_1")]
3110    pub chroot: ManuallyDrop<es_event_chroot_t>,
3111    #[cfg(feature = "macos_10_15_1")]
3112    pub clone: ManuallyDrop<es_event_clone_t>,
3113    #[cfg(feature = "macos_10_15_1")]
3114    pub deleteextattr: ManuallyDrop<es_event_deleteextattr_t>,
3115    #[cfg(feature = "macos_10_15_1")]
3116    pub dup: ManuallyDrop<es_event_dup_t>,
3117    #[cfg(feature = "macos_10_15_1")]
3118    pub fcntl: ManuallyDrop<es_event_fcntl_t>,
3119    #[cfg(feature = "macos_10_15_1")]
3120    pub fsgetpath: ManuallyDrop<es_event_fsgetpath_t>,
3121    #[cfg(feature = "macos_10_15_1")]
3122    pub getattrlist: ManuallyDrop<es_event_getattrlist_t>,
3123    #[cfg(feature = "macos_10_15_1")]
3124    pub getextattr: ManuallyDrop<es_event_getextattr_t>,
3125    #[cfg(feature = "macos_10_15_1")]
3126    pub listextattr: ManuallyDrop<es_event_listextattr_t>,
3127    #[cfg(feature = "macos_10_15_1")]
3128    pub readdir: ManuallyDrop<es_event_readdir_t>,
3129    #[cfg(feature = "macos_10_15_1")]
3130    pub remount: ManuallyDrop<es_event_remount_t>,
3131    #[cfg(feature = "macos_10_15_1")]
3132    pub setacl: ManuallyDrop<es_event_setacl_t>,
3133    #[cfg(feature = "macos_10_15_1")]
3134    pub settime: ManuallyDrop<es_event_settime_t>,
3135    #[cfg(feature = "macos_10_15_1")]
3136    pub stat: ManuallyDrop<es_event_stat_t>,
3137    #[cfg(feature = "macos_10_15_1")]
3138    pub uipc_bind: ManuallyDrop<es_event_uipc_bind_t>,
3139    #[cfg(feature = "macos_10_15_1")]
3140    pub uipc_connect: ManuallyDrop<es_event_uipc_connect_t>,
3141    #[cfg(feature = "macos_10_15_1")]
3142    pub utimes: ManuallyDrop<es_event_utimes_t>,
3143
3144    // 10.15.4
3145    #[cfg(feature = "macos_10_15_4")]
3146    pub proc_check: ManuallyDrop<es_event_proc_check_t>,
3147    #[cfg(feature = "macos_10_15_4")]
3148    pub pty_close: ManuallyDrop<es_event_pty_close_t>,
3149    #[cfg(feature = "macos_10_15_4")]
3150    pub pty_grant: ManuallyDrop<es_event_pty_grant_t>,
3151
3152    // 11.0.0
3153    #[cfg(feature = "macos_11_0_0")]
3154    pub cs_invalidated: ManuallyDrop<es_event_cs_invalidated_t>,
3155    #[cfg(feature = "macos_11_0_0")]
3156    pub get_task_name: ManuallyDrop<es_event_get_task_name_t>,
3157    #[cfg(feature = "macos_11_0_0")]
3158    pub proc_suspend_resume: ManuallyDrop<es_event_proc_suspend_resume_t>,
3159    #[cfg(feature = "macos_11_0_0")]
3160    pub remote_thread_create: ManuallyDrop<es_event_remote_thread_create_t>,
3161    #[cfg(feature = "macos_11_0_0")]
3162    pub searchfs: ManuallyDrop<es_event_searchfs_t>,
3163    #[cfg(feature = "macos_11_0_0")]
3164    pub trace: ManuallyDrop<es_event_trace_t>,
3165
3166    // 11.3.0
3167    #[cfg(feature = "macos_11_3_0")]
3168    pub get_task_read: ManuallyDrop<es_event_get_task_read_t>,
3169    #[cfg(feature = "macos_11_3_0")]
3170    pub get_task_inspect: ManuallyDrop<es_event_get_task_inspect_t>,
3171
3172    // 12.0.0
3173    #[cfg(feature = "macos_12_0_0")]
3174    pub copyfile: ManuallyDrop<es_event_copyfile_t>,
3175    #[cfg(feature = "macos_12_0_0")]
3176    pub setgid: ManuallyDrop<es_event_setgid_t>,
3177    #[cfg(feature = "macos_12_0_0")]
3178    pub setuid: ManuallyDrop<es_event_setuid_t>,
3179    #[cfg(feature = "macos_12_0_0")]
3180    pub setegid: ManuallyDrop<es_event_setegid_t>,
3181    #[cfg(feature = "macos_12_0_0")]
3182    pub seteuid: ManuallyDrop<es_event_seteuid_t>,
3183    #[cfg(feature = "macos_12_0_0")]
3184    pub setregid: ManuallyDrop<es_event_setregid_t>,
3185    #[cfg(feature = "macos_12_0_0")]
3186    pub setreuid: ManuallyDrop<es_event_setreuid_t>,
3187    // Events added in macOS 13.0 or later use nonnull pointers.
3188    //
3189    // 13.0.0
3190    #[cfg(feature = "macos_13_0_0")]
3191    pub authentication: ShouldNotBeNull<es_event_authentication_t>,
3192    #[cfg(feature = "macos_13_0_0")]
3193    pub xp_malware_detected: ShouldNotBeNull<es_event_xp_malware_detected_t>,
3194    #[cfg(feature = "macos_13_0_0")]
3195    pub xp_malware_remediated: ShouldNotBeNull<es_event_xp_malware_remediated_t>,
3196    #[cfg(feature = "macos_13_0_0")]
3197    pub lw_session_login: ShouldNotBeNull<es_event_lw_session_login_t>,
3198    #[cfg(feature = "macos_13_0_0")]
3199    pub lw_session_logout: ShouldNotBeNull<es_event_lw_session_logout_t>,
3200    #[cfg(feature = "macos_13_0_0")]
3201    pub lw_session_lock: ShouldNotBeNull<es_event_lw_session_lock_t>,
3202    #[cfg(feature = "macos_13_0_0")]
3203    pub lw_session_unlock: ShouldNotBeNull<es_event_lw_session_unlock_t>,
3204    #[cfg(feature = "macos_13_0_0")]
3205    pub screensharing_attach: ShouldNotBeNull<es_event_screensharing_attach_t>,
3206    #[cfg(feature = "macos_13_0_0")]
3207    pub screensharing_detach: ShouldNotBeNull<es_event_screensharing_detach_t>,
3208    #[cfg(feature = "macos_13_0_0")]
3209    pub openssh_login: ShouldNotBeNull<es_event_openssh_login_t>,
3210    #[cfg(feature = "macos_13_0_0")]
3211    pub openssh_logout: ShouldNotBeNull<es_event_openssh_logout_t>,
3212    #[cfg(feature = "macos_13_0_0")]
3213    pub login_login: ShouldNotBeNull<es_event_login_login_t>,
3214    #[cfg(feature = "macos_13_0_0")]
3215    pub login_logout: ShouldNotBeNull<es_event_login_logout_t>,
3216    #[cfg(feature = "macos_13_0_0")]
3217    pub btm_launch_item_add: ShouldNotBeNull<es_event_btm_launch_item_add_t>,
3218    #[cfg(feature = "macos_13_0_0")]
3219    pub btm_launch_item_remove: ShouldNotBeNull<es_event_btm_launch_item_remove_t>,
3220
3221    // 14.0.0
3222    #[cfg(feature = "macos_14_0_0")]
3223    pub profile_add: ShouldNotBeNull<es_event_profile_add_t>,
3224    #[cfg(feature = "macos_14_0_0")]
3225    pub profile_remove: ShouldNotBeNull<es_event_profile_remove_t>,
3226    #[cfg(feature = "macos_14_0_0")]
3227    pub su: ShouldNotBeNull<es_event_su_t>,
3228    #[cfg(feature = "macos_14_0_0")]
3229    pub authorization_petition: ShouldNotBeNull<es_event_authorization_petition_t>,
3230    #[cfg(feature = "macos_14_0_0")]
3231    pub authorization_judgement: ShouldNotBeNull<es_event_authorization_judgement_t>,
3232    #[cfg(feature = "macos_14_0_0")]
3233    pub sudo: ShouldNotBeNull<es_event_sudo_t>,
3234    #[cfg(feature = "macos_14_0_0")]
3235    pub od_group_add: ShouldNotBeNull<es_event_od_group_add_t>,
3236    #[cfg(feature = "macos_14_0_0")]
3237    pub od_group_remove: ShouldNotBeNull<es_event_od_group_remove_t>,
3238    #[cfg(feature = "macos_14_0_0")]
3239    pub od_group_set: ShouldNotBeNull<es_event_od_group_set_t>,
3240    #[cfg(feature = "macos_14_0_0")]
3241    pub od_modify_password: ShouldNotBeNull<es_event_od_modify_password_t>,
3242    #[cfg(feature = "macos_14_0_0")]
3243    pub od_disable_user: ShouldNotBeNull<es_event_od_disable_user_t>,
3244    #[cfg(feature = "macos_14_0_0")]
3245    pub od_enable_user: ShouldNotBeNull<es_event_od_enable_user_t>,
3246    #[cfg(feature = "macos_14_0_0")]
3247    pub od_attribute_value_add: ShouldNotBeNull<es_event_od_attribute_value_add_t>,
3248    #[cfg(feature = "macos_14_0_0")]
3249    pub od_attribute_value_remove: ShouldNotBeNull<es_event_od_attribute_value_remove_t>,
3250    #[cfg(feature = "macos_14_0_0")]
3251    pub od_attribute_set: ShouldNotBeNull<es_event_od_attribute_set_t>,
3252    #[cfg(feature = "macos_14_0_0")]
3253    pub od_create_user: ShouldNotBeNull<es_event_od_create_user_t>,
3254    #[cfg(feature = "macos_14_0_0")]
3255    pub od_create_group: ShouldNotBeNull<es_event_od_create_group_t>,
3256    #[cfg(feature = "macos_14_0_0")]
3257    pub od_delete_user: ShouldNotBeNull<es_event_od_delete_user_t>,
3258    #[cfg(feature = "macos_14_0_0")]
3259    pub od_delete_group: ShouldNotBeNull<es_event_od_delete_group_t>,
3260    #[cfg(feature = "macos_14_0_0")]
3261    pub xpc_connect: ShouldNotBeNull<es_event_xpc_connect_t>,
3262
3263    // 15.0.0
3264    #[cfg(feature = "macos_15_0_0")]
3265    pub gatekeeper_user_override: ShouldNotBeNull<es_event_gatekeeper_user_override_t>,
3266
3267    // 15.4.0
3268    #[cfg(feature = "macos_15_4_0")]
3269    pub tcc_modify: ShouldNotBeNull<es_event_tcc_modify_t>,
3270}
3271
3272/// Indicates the result of the ES subsystem authorization process
3273#[repr(C)]
3274#[must_use]
3275#[derive(Copy, Clone)]
3276pub struct es_result_t {
3277    pub result_type: es_result_type_t,
3278    pub result: es_result_t_anon_0,
3279}
3280
3281/// See [`es_result_t`]
3282#[repr(C)]
3283#[derive(Copy, Clone)]
3284pub union es_result_t_anon_0 {
3285    pub auth: es_auth_result_t,
3286    pub flags: u32,
3287    _reserved: [u8; 32],
3288}
3289
3290/// This is the top level datatype that encodes information sent from the ES subsystem to its
3291/// clients. Each security event being processed by the ES subsystem will be encoded in an
3292/// `es_message_t`. A message can be an authorization request or a notification of an event that has
3293/// already taken place.
3294///
3295/// For events that can be authorized there are unique `NOTIFY` and `AUTH` event types for the same
3296/// event data, eg: `event.exec` is the correct union label for both `ES_EVENT_TYPE_AUTH_EXEC` and
3297/// `ES_EVENT_TYPE_NOTIFY_EXEC` event types.
3298///
3299/// For fields marked only available in specific message versions, all access must be guarded at
3300/// runtime by checking the value of the message version field, e.g.
3301///
3302/// ```ignore
3303/// if msg.version >= 2 {
3304///     acl = unsafe { msg.event.create.acl };
3305/// }
3306/// ```
3307///
3308/// Fields using Mach time are in the resolution matching the ES client's architecture. This means
3309/// they can be compared to `mach_absolute_time()` and converted to nanoseconds with the help of
3310/// mach_timebase_info(). Further note that on Apple silicon, x86_64 clients running under Rosetta 2
3311/// will see Mach times in a different resolution than native arm64 clients. For more information on
3312/// differences regarding Mach time on Apple silicon and Intel-based Mac computers, see "Addressing
3313/// Architectural Differences in Your macOS Code":
3314/// <https://developer.apple.com/documentation/apple_silicon/addressing_architectural_differences_in_your_macos_code>
3315///
3316/// ## Rust implementation notes
3317///
3318/// [`RefEncode`] is currently implemented with the encoding left unknown explicitly. If
3319/// `es_message_t` needs to be encoded for Objective C messages, this will require changes.
3320///
3321/// ## A note on userspace events
3322///
3323/// Before macOS 13.0 almost all ES events were created by `xnu` (the macOS kernel).
3324/// Such events are *mandatory*.
3325/// If no `es_event_setuid_t` event is emitted then no `setuid` took place. This is a security guarantee.
3326/// Most events added in macOS 13 and 14 are emitted by userspace binaries and frameworks.
3327/// ES still guarantees that if an event was not emitted *by that binary or framework* then it did not happen, but this is not quite the same guarantee.
3328///
3329/// Consider `es_event_su_t`:
3330/// This event is created by the `su` binary first shipped in macOS 14.0, but it's entirely possible for a user to install (or compile) a different `su`!
3331/// ES only guarantees that the platform binary shipped with macOS emits `es_event_su_t` events.
3332/// As such `es_event_su_t` does not provide the same security guarantee that `es_event_setuid_t` does.
3333///
3334/// When a user invokes the platform `su` binary ES will emit both `es_event_su_t` and `es_event_setuid_t` events.
3335/// When a user compiles their own `su` binary from source and executes it:
3336///
3337/// - ES will emit an `es_event_setuid_t` event.
3338/// - ES will NOT emit an `es_event_su_t`.
3339///
3340/// Userspace events are inherently discretionary.
3341/// It is at the users discretion as to whether they use the builtin binaries/frameworks or not.
3342/// Kernel events are mandatory. There is no `setuid` syscall that ES does not interdict.
3343///
3344/// The following events are created by userspace binaries or frameworks:
3345///
3346/// - [`ES_EVENT_TYPE_AUTH_FILE_PROVIDER_MATERIALIZE`]
3347/// - [`ES_EVENT_TYPE_NOTIFY_FILE_PROVIDER_MATERIALIZE`]
3348/// - [`ES_EVENT_TYPE_AUTH_FILE_PROVIDER_UPDATE`]
3349/// - [`ES_EVENT_TYPE_NOTIFY_FILE_PROVIDER_UPDATE`]
3350/// - [`ES_EVENT_TYPE_NOTIFY_AUTHENTICATION`]
3351/// - [`ES_EVENT_TYPE_NOTIFY_XP_MALWARE_DETECTED`]
3352/// - [`ES_EVENT_TYPE_NOTIFY_XP_MALWARE_REMEDIATED`]
3353/// - [`ES_EVENT_TYPE_NOTIFY_LW_SESSION_LOGIN`]
3354/// - [`ES_EVENT_TYPE_NOTIFY_LW_SESSION_LOGOUT`]
3355/// - [`ES_EVENT_TYPE_NOTIFY_LW_SESSION_LOCK`]
3356/// - [`ES_EVENT_TYPE_NOTIFY_LW_SESSION_UNLOCK`]
3357/// - [`ES_EVENT_TYPE_NOTIFY_SCREENSHARING_ATTACH`]
3358/// - [`ES_EVENT_TYPE_NOTIFY_SCREENSHARING_DETACH`]
3359/// - [`ES_EVENT_TYPE_NOTIFY_OPENSSH_LOGIN`]
3360/// - [`ES_EVENT_TYPE_NOTIFY_OPENSSH_LOGOUT`]
3361/// - [`ES_EVENT_TYPE_NOTIFY_LOGIN_LOGIN`]
3362/// - [`ES_EVENT_TYPE_NOTIFY_LOGIN_LOGOUT`]
3363/// - [`ES_EVENT_TYPE_NOTIFY_BTM_LAUNCH_ITEM_ADD`]
3364/// - [`ES_EVENT_TYPE_NOTIFY_BTM_LAUNCH_ITEM_REMOVE`]
3365/// - [`ES_EVENT_TYPE_NOTIFY_PROFILE_ADD`]
3366/// - [`ES_EVENT_TYPE_NOTIFY_PROFILE_REMOVE`]
3367/// - [`ES_EVENT_TYPE_NOTIFY_SU`]
3368/// - [`ES_EVENT_TYPE_NOTIFY_AUTHORIZATION_PETITION`]
3369/// - [`ES_EVENT_TYPE_NOTIFY_AUTHORIZATION_JUDGEMENT`]
3370/// - [`ES_EVENT_TYPE_NOTIFY_SUDO`]
3371/// - [`ES_EVENT_TYPE_NOTIFY_OD_GROUP_ADD`]
3372/// - [`ES_EVENT_TYPE_NOTIFY_OD_GROUP_REMOVE`]
3373/// - [`ES_EVENT_TYPE_NOTIFY_OD_GROUP_SET`]
3374/// - [`ES_EVENT_TYPE_NOTIFY_OD_MODIFY_PASSWORD`]
3375/// - [`ES_EVENT_TYPE_NOTIFY_OD_DISABLE_USER`]
3376/// - [`ES_EVENT_TYPE_NOTIFY_OD_ENABLE_USER`]
3377/// - [`ES_EVENT_TYPE_NOTIFY_OD_ATTRIBUTE_VALUE_ADD`]
3378/// - [`ES_EVENT_TYPE_NOTIFY_OD_ATTRIBUTE_VALUE_REMOVE`]
3379/// - [`ES_EVENT_TYPE_NOTIFY_OD_ATTRIBUTE_SET`]
3380/// - [`ES_EVENT_TYPE_NOTIFY_OD_CREATE_USER`]
3381/// - [`ES_EVENT_TYPE_NOTIFY_OD_CREATE_GROUP`]
3382/// - [`ES_EVENT_TYPE_NOTIFY_OD_DELETE_USER`]
3383/// - [`ES_EVENT_TYPE_NOTIFY_OD_DELETE_GROUP`]
3384/// - [`ES_EVENT_TYPE_NOTIFY_GATEKEEPER_USER_OVERRIDE`]
3385/// - [`ES_EVENT_TYPE_NOTIFY_TCC_MODIFY`]
3386#[repr(C)]
3387pub struct es_message_t {
3388    /// Indicates the message version; some fields are not available and must not be accessed unless
3389    /// the message version is equal to or higher than the message version at which the field was
3390    /// introduced.
3391    pub version: u32,
3392    /// The time at which the event was generated
3393    pub time: timespec,
3394    /// The Mach absolute time at which the event was generated
3395    pub mach_time: u64,
3396    /// The Mach absolute time before which an auth event must be responded to. If a client fails
3397    /// to respond to auth events prior to the `deadline`, the client will be killed. Each message
3398    /// can contain its own unique deadline, and some deadlines can vary substantially. Clients must
3399    /// take care to inspect the deadline value of each message to know how much time is allotted
3400    /// for processing.
3401    pub deadline: u64,
3402    /// Describes the process that took the action
3403    pub process: ShouldNotBeNull<es_process_t>,
3404    /// Per-client, per-event-type sequence number that can be inspected to detect whether the
3405    /// kernel had to drop events for this client. When no events are dropped for this client,
3406    /// `seq_num` increments by 1 for every message of that event type. When events have been
3407    /// dropped, the difference between the last seen sequence number of that event type plus 1 and
3408    /// `seq_num` of the received message indicates the number of events that had to be dropped.
3409    /// Dropped events generally indicate that more events were generated in the kernel than the
3410    /// client was able to handle.
3411    ///
3412    /// See `global_seq_num`.
3413    ///
3414    /// Field available only if message version >= 2.
3415    pub seq_num: u64,
3416    /// Indicates if the action field is an auth or notify action
3417    pub action_type: es_action_type_t,
3418    /// For auth events, contains the opaque auth ID that must be supplied when responding to the
3419    /// event. For notify events, describes the result of the action.
3420    pub action: es_message_t_anon_0,
3421    /// Indicates which event struct is defined in the event union
3422    pub event_type: es_event_type_t,
3423    /// Contains data specific to the event type
3424    pub event: es_events_t,
3425    /// Describes the thread that took the action. May be `NULL` when thread is not applicable,
3426    /// for example for trace events that describe the traced process calling `ptrace(PT_TRACE_ME)`
3427    /// or for cs invalidated events that are a result of another process calling
3428    /// `csops(CS_OPS_MARKINVALID)`.
3429    ///
3430    /// Field available only if message version >= 4.
3431    #[cfg(feature = "macos_11_0_0")]
3432    pub thread: *mut es_thread_t,
3433    /// Per-client sequence number that can be inspected to detect whether the kernel had to
3434    /// drop events for this client. When no events are dropped for this client, `global_seq_num`
3435    /// increments by 1 for every message. When events have been dropped, the difference between the
3436    /// last seen global sequence number and the `global_seq_num` of the received message indicates
3437    /// the number of events that had to be dropped. Dropped events generally indicate that more
3438    /// events were generated in the kernel than the client was able to handle.
3439    ///
3440    /// See also: `seq_num`.
3441    ///
3442    /// Field available only if message version >= 4.
3443    #[cfg(feature = "macos_11_0_0")]
3444    pub global_seq_num: u64,
3445    /// Opaque data that must not be accessed directly
3446    _opaque: [u64; 0],
3447}
3448
3449should_not_be_null_fields!(es_message_t; process -> es_process_t);
3450#[cfg(feature = "macos_11_0_0")]
3451null_fields!(es_message_t; thread -> es_thread_t);
3452
3453#[cfg(feature = "objc2")]
3454unsafe impl RefEncode for es_message_t {
3455    const ENCODING_REF: Encoding = Encoding::Pointer(&Encoding::Unknown);
3456}
3457
3458#[repr(C)]
3459#[derive(Copy, Clone)]
3460pub union es_message_t_anon_0 {
3461    pub auth: es_event_id_t,
3462    pub notify: es_result_t,
3463}
3464
3465#[link(name = "EndpointSecurity", kind = "dylib")]
3466unsafe extern "C" {
3467    /// Calculate the size of an [`es_message_t`].
3468    ///
3469    /// This function **MUST NOT** be used in conjunction with attempting to copy an `es_message_t`
3470    /// (e.g. by using the reported size in order to `malloc(3)` a buffer, and `memcpy(3)` an
3471    /// existing `es_message_t` into that buffer). Doing so will result in use-after-free bugs.
3472    ///
3473    ///
3474    #[cfg_attr(
3475        feature = "macos_11_0_0",
3476        doc = "**Deprecated in macOS 11+**: Please use [`es_retain_message()`] to retain an `es_message_t`."
3477    )]
3478    #[cfg_attr(
3479        not(feature = "macos_11_0_0"),
3480        doc = "**Deprecated in macOS 11+**: Please use `es_retain_message()` to retain an `es_message_t`."
3481    )]
3482    ///
3483    /// - `msg`: The message for which the size will be calculated
3484    /// - Returns the size of the message
3485    pub fn es_message_size(msg: &es_message_t) -> usize;
3486
3487    /// Retains an [`es_message_t`], returning a non-const pointer to the given `es_message_t` for
3488    /// compatibility with existing code.
3489    ///
3490    /// It is invalid to attempt to write to the returned `es_message_t`, despite being non-`const`,
3491    /// and doing so will result in a crash.
3492    ///
3493    #[cfg_attr(
3494        feature = "macos_11_0_0",
3495        doc = "**Deprecated in macOS 11+**: Please use [`es_retain_message()`] to retain an `es_message_t`."
3496    )]
3497    #[cfg_attr(
3498        not(feature = "macos_11_0_0"),
3499        doc = "**Deprecated in macOS 11+**: Please use `es_retain_message()` to retain an `es_message_t`."
3500    )]
3501    ///
3502    /// - `msg`: The message to be retained
3503    /// - Returns a non-const pointer to the retained `es_message_t`
3504    ///
3505    /// The caller must release the memory with [`es_free_message()`]
3506    pub fn es_copy_message(msg: &es_message_t) -> *mut es_message_t;
3507
3508    /// Releases the memory associated with the given [`es_message_t`] that was retained via
3509    /// [`es_copy_message()`]
3510    ///
3511    #[cfg_attr(
3512        feature = "macos_11_0_0",
3513        doc = "**Deprecated in macOS 11+**: Please use [`es_retain_message()`] to retain an `es_message_t`."
3514    )]
3515    #[cfg_attr(
3516        not(feature = "macos_11_0_0"),
3517        doc = "**Deprecated in macOS 11+**: Please use `es_retain_message()` to retain an `es_message_t`."
3518    )]
3519    ///
3520    /// - `msg`: The message to be released
3521    pub fn es_free_message(msg: &es_message_t);
3522
3523    /// Retains the given [`es_message_t`], extending its lifetime until released with [`es_release_message()`].
3524    ///
3525    /// - `msg`: The message to be retained
3526    ///
3527    /// It is necessary to retain a message when the `es_message_t` provided in the event handler block of
3528    /// [`es_new_client()`][super::es_new_client] will be processed asynchronously.
3529    ///
3530    /// Available for macos 11+
3531    #[cfg(feature = "macos_11_0_0")]
3532    pub fn es_retain_message(msg: &es_message_t);
3533
3534    /// Releases the given [`es_message_t`] that was previously retained with [`es_retain_message()`]
3535    ///
3536    /// - `msg`: The message to be released
3537    ///
3538    /// Available for macos 11+
3539    #[cfg(feature = "macos_11_0_0")]
3540    pub fn es_release_message(msg: &es_message_t);
3541
3542    /// Get the number of arguments in a message containing an [`es_event_exec_t`]
3543    ///
3544    /// - `event`: The `es_event_exec_t` being inspected
3545    /// - Returns the number of arguments
3546    pub fn es_exec_arg_count(event: &es_event_exec_t) -> u32;
3547
3548    /// Get the number of environment variables in a message containing an [`es_event_exec_t`]
3549    ///
3550    /// - `event`: The `es_event_exec_t` being inspected
3551    /// - Returns The number of environment variables
3552    pub fn es_exec_env_count(event: &es_event_exec_t) -> u32;
3553
3554    /// Get the number of file descriptors in a message containing an [`es_event_exec_t`]
3555    ///
3556    /// - `event`: The `es_event_exec_t` being inspected
3557    /// - Returns The number of file descriptors
3558    ///
3559    /// Available for macos 11+
3560    #[cfg(feature = "macos_11_0_0")]
3561    pub fn es_exec_fd_count(event: &es_event_exec_t) -> u32;
3562
3563    /// Get the argument at the specified position in the message containing an [`es_event_exec_t`]
3564    ///
3565    /// - `event`: The `es_event_exec_t` being inspected
3566    /// - `index`: Index of the argument to retrieve (starts from 0)
3567    /// - Returns an `es_string_token_t` containing a pointer to the argument and its length.
3568    ///   This is a zero-allocation operation. The returned pointer **must not** outlive `exec_event`.
3569    ///
3570    /// Reading an an argument where `index` >= [`es_exec_arg_count()`] is undefined
3571    pub fn es_exec_arg(event: &es_event_exec_t, index: u32) -> es_string_token_t;
3572
3573    /// Get the environment variable at the specified position in the message containing an
3574    /// [`es_event_exec_t`]
3575    ///
3576    /// - `event`: The `es_event_exec_t` being inspected
3577    /// - `index`: Index of the environment variable to retrieve (starts from 0)
3578    /// - Returns an `es_string_token_t` containing a pointer to the environment variable and its length.
3579    ///   This is zero-allocation operation. The returned pointer **must not** outlive `exec_event`.
3580    ///
3581    /// Reading an an env where `index` >= [`es_exec_env_count()`] is undefined.
3582    pub fn es_exec_env(event: &es_event_exec_t, index: u32) -> es_string_token_t;
3583
3584    /// Get the file descriptor at the specified position in the message containing an
3585    /// [`es_event_exec_t`]
3586    ///
3587    /// - `event`: The `es_event_exec_t` being inspected
3588    /// - `index`: Index of the file descriptor to retrieve (starts from 0)
3589    /// - Returns a pointer to an `es_fd_t` describing the file descriptor.
3590    ///   This is zero-allocation operation. The returned pointer **must not** outlive `exec_event`.
3591    ///
3592    /// Reading an fd where `index` >= [`es_exec_fd_count()`] is undefined
3593    ///
3594    /// Available for macos 11+
3595    #[cfg(feature = "macos_11_0_0")]
3596    pub fn es_exec_fd(event: &es_event_exec_t, index: u32) -> ShouldNotBeNull<es_fd_t>;
3597}