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