endpoint_sec/event/event_od_enable_user.rs
1//! [`EventOdEnableUser`]
2
3use std::ffi::OsStr;
4
5use endpoint_sec_sys::es_event_od_enable_user_t;
6
7use crate::Process;
8
9/// Notification that a user account was enabled.
10#[doc(alias = "es_event_od_enable_user_t")]
11pub struct EventOdEnableUser<'a> {
12 /// The raw reference.
13 pub(crate) raw: &'a es_event_od_enable_user_t,
14 /// The version of the message.
15 pub(crate) version: u32,
16}
17
18impl<'a> EventOdEnableUser<'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 name of the user account that was enabled.
33 #[inline(always)]
34 pub fn user_name(&self) -> &'a OsStr {
35 // Safety: 'a tied to self, object obtained through ES
36 unsafe { self.raw.user_name.as_os_str() }
37 }
38
39 /// OD node being mutated.
40 ///
41 /// Typically one of "/Local/Default", "/LDAPv3/<server>" or "/Active Directory/<domain>".
42 #[inline(always)]
43 pub fn node_name(&self) -> &'a OsStr {
44 // Safety: 'a tied to self, object obtained through ES
45 unsafe { self.raw.node_name.as_os_str() }
46 }
47 /// Optional. If node_name is "/Local/Default", this is, the path of the database against which
48 /// OD is authenticating.
49 #[inline(always)]
50 pub fn db_path(&self) -> Option<&'a OsStr> {
51 if self.node_name() == OsStr::new("/Local/Default") {
52 // Safety: 'a tied to self, object obtained through ES
53 Some(unsafe { self.raw.db_path.as_os_str() })
54 } else {
55 None
56 }
57 }
58}
59
60// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
61unsafe impl Send for EventOdEnableUser<'_> {}
62// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
63unsafe impl Sync for EventOdEnableUser<'_> {}
64
65impl_debug_eq_hash_with_functions!(EventOdEnableUser<'a> with version; instigator, error_code, user_name, node_name, db_path);