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