endpoint_sec/event/event_od_group_remove.rs
1//! [`EventOdGroupRemove`]
2
3use std::ffi::OsStr;
4
5use endpoint_sec_sys::es_event_od_group_remove_t;
6
7use crate::{OdMemberId, Process};
8
9/// Notification that a member was removed to a group.
10///
11/// This event does not indicate that a member was actually removed. For example when removing a
12/// user from a group they are not a member of.
13#[doc(alias = "es_event_od_group_remove_t")]
14pub struct EventOdGroupRemove<'a> {
15 /// The raw reference.
16 pub(crate) raw: &'a es_event_od_group_remove_t,
17 /// The version of the message.
18 pub(crate) version: u32,
19}
20
21impl<'a> EventOdGroupRemove<'a> {
22 /// Process that instigated operation (XPC caller).
23 #[inline(always)]
24 pub fn instigator(&self) -> Process<'a> {
25 // Safety: 'a tied to self, object obtained through ES
26 Process::new(unsafe { self.raw.instigator.as_ref() }, self.version)
27 }
28
29 /// Result code for the operation.
30 #[inline(always)]
31 pub fn error_code(&self) -> i32 {
32 self.raw.error_code
33 }
34
35 /// The group to which the member was removed.
36 #[inline(always)]
37 pub fn group_name(&self) -> &'a OsStr {
38 // Safety: 'a tied to self, object obtained through ES
39 unsafe { self.raw.group_name.as_os_str() }
40 }
41
42 /// The identity of the member removed.
43 #[inline(always)]
44 pub fn member(&self) -> OdMemberId<'a> {
45 OdMemberId {
46 // Safety: 'a tied to self, object obtained through ES
47 raw: unsafe { self.raw.member.as_ref() },
48 }
49 }
50
51 /// OD node being mutated.
52 ///
53 /// Typically one of "/Local/Default", "/LDAPv3/<server>" or "/Active Directory/<domain>".
54 #[inline(always)]
55 pub fn node_name(&self) -> &'a OsStr {
56 // Safety: 'a tied to self, object obtained through ES
57 unsafe { self.raw.node_name.as_os_str() }
58 }
59
60 /// Optional. If node_name is "/Local/Default", this is, the path of the database against which
61 /// OD is authenticating.
62 #[inline(always)]
63 pub fn db_path(&self) -> Option<&'a OsStr> {
64 if self.node_name() == OsStr::new("/Local/Default") {
65 // Safety: 'a tied to self, object obtained through ES
66 Some(unsafe { self.raw.db_path.as_os_str() })
67 } else {
68 None
69 }
70 }
71}
72
73// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
74unsafe impl Send for EventOdGroupRemove<'_> {}
75// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
76unsafe impl Sync for EventOdGroupRemove<'_> {}
77
78impl_debug_eq_hash_with_functions!(EventOdGroupRemove<'a> with version; instigator, error_code, group_name, member, node_name, db_path);