Skip to main content

endpoint_sec_sys/
message.rs

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