Skip to main content

endpoint_sec/event/
event_od_modify_password.rs

1//! [`EventOdModifyPassword`]
2
3use std::ffi::OsStr;
4
5use endpoint_sec_sys::{es_event_od_modify_password_t, es_od_account_type_t};
6
7use crate::{AuditToken, Process};
8
9/// Notification that an account had its password modified.
10#[doc(alias = "es_event_od_modify_password_t")]
11pub struct EventOdModifyPassword<'a> {
12    /// The raw reference.
13    pub(crate) raw: &'a es_event_od_modify_password_t,
14    /// The version of the message.
15    pub(crate) version: u32,
16}
17
18impl<'a> EventOdModifyPassword<'a> {
19    /// Process that instigated operation (XPC caller).
20    #[inline(always)]
21    pub fn instigator(&self) -> Option<Process<'a>> {
22        // Safety: 'a tied to self, object obtained through ES
23        let process = unsafe { self.raw.instigator()? };
24        Some(Process::new(process, self.version))
25    }
26
27    /// Audit token of the process that instigated this event.
28    pub fn instigator_token(&self) -> AuditToken {
29        #[cfg(feature = "macos_15_0_0")]
30        if self.version >= 8 {
31            return AuditToken(self.raw.instigator_token);
32        }
33
34        // On old versions, the process was always non-null, and we can get
35        // its token easily.
36        self.instigator().unwrap().audit_token()
37    }
38
39    /// Result code for the operation.
40    #[inline(always)]
41    pub fn error_code(&self) -> i32 {
42        self.raw.error_code
43    }
44
45    /// The type of the account for which the password was modified.
46    #[inline(always)]
47    pub fn account_type(&self) -> es_od_account_type_t {
48        self.raw.account_type
49    }
50
51    /// The name of the account for which the password was modified.
52    #[inline(always)]
53    pub fn account_name(&self) -> &'a OsStr {
54        // Safety: 'a tied to self, object obtained through ES
55        unsafe { self.raw.account_name.as_os_str() }
56    }
57
58    /// OD node being mutated.
59    ///
60    /// Typically one of "/Local/Default", "/LDAPv3/<server>" or "/Active Directory/<domain>".
61    #[inline(always)]
62    pub fn node_name(&self) -> &'a OsStr {
63        // Safety: 'a tied to self, object obtained through ES
64        unsafe { self.raw.node_name.as_os_str() }
65    }
66
67    /// Optional. If node_name is "/Local/Default", this is, the path of the database against which
68    /// OD is authenticating.
69    #[inline(always)]
70    pub fn db_path(&self) -> Option<&'a OsStr> {
71        if self.node_name() == OsStr::new("/Local/Default") {
72            // Safety: 'a tied to self, object obtained through ES
73            Some(unsafe { self.raw.db_path.as_os_str() })
74        } else {
75            None
76        }
77    }
78}
79
80// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
81unsafe impl Send for EventOdModifyPassword<'_> {}
82// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
83unsafe impl Sync for EventOdModifyPassword<'_> {}
84
85impl_debug_eq_hash_with_functions!(EventOdModifyPassword<'a> with version; instigator, instigator_token, error_code, account_type, account_name, node_name, db_path);