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::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) -> Process<'a> {
22 // Safety: 'a tied to self, object obtained through ES
23 Process::new(unsafe { self.raw.instigator.as_ref() }, self.version)
24 }
25
26 /// Result code for the operation.
27 #[inline(always)]
28 pub fn error_code(&self) -> i32 {
29 self.raw.error_code
30 }
31
32 /// The type of the account for which the password was modified.
33 #[inline(always)]
34 pub fn account_type(&self) -> es_od_account_type_t {
35 self.raw.account_type
36 }
37
38 /// The name of the account for which the password was modified.
39 #[inline(always)]
40 pub fn account_name(&self) -> &'a OsStr {
41 // Safety: 'a tied to self, object obtained through ES
42 unsafe { self.raw.account_name.as_os_str() }
43 }
44
45 /// OD node being mutated.
46 ///
47 /// Typically one of "/Local/Default", "/LDAPv3/<server>" or "/Active Directory/<domain>".
48 #[inline(always)]
49 pub fn node_name(&self) -> &'a OsStr {
50 // Safety: 'a tied to self, object obtained through ES
51 unsafe { self.raw.node_name.as_os_str() }
52 }
53
54 /// Optional. If node_name is "/Local/Default", this is, the path of the database against which
55 /// OD is authenticating.
56 #[inline(always)]
57 pub fn db_path(&self) -> Option<&'a OsStr> {
58 if self.node_name() == OsStr::new("/Local/Default") {
59 // Safety: 'a tied to self, object obtained through ES
60 Some(unsafe { self.raw.db_path.as_os_str() })
61 } else {
62 None
63 }
64 }
65}
66
67// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
68unsafe impl Send for EventOdModifyPassword<'_> {}
69// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
70unsafe impl Sync for EventOdModifyPassword<'_> {}
71
72impl_debug_eq_hash_with_functions!(EventOdModifyPassword<'a> with version; instigator, error_code, account_type, account_name, node_name, db_path);