Skip to main content

endpoint_sec/event/
event_setowner.rs

1//! [`EventSetOwner`]
2
3use endpoint_sec_sys::{es_event_setowner_t, gid_t, uid_t};
4
5use crate::File;
6
7/// Modify file owner information.
8#[doc(alias = "es_event_setowner_t")]
9pub struct EventSetOwner<'a> {
10    /// Raw event
11    pub(crate) raw: &'a es_event_setowner_t,
12}
13
14impl<'a> EventSetOwner<'a> {
15    /// The desired new UID.
16    #[inline(always)]
17    pub fn uid(&self) -> uid_t {
18        self.raw.uid
19    }
20
21    /// The desired new GID.
22    #[inline(always)]
23    pub fn gid(&self) -> gid_t {
24        self.raw.gid
25    }
26
27    /// The file for which owner information will be modified.
28    #[inline(always)]
29    pub fn target(&self) -> File<'a> {
30        // Safety: 'a tied to self, object obtained through ES
31        File::new(unsafe { self.raw.target() })
32    }
33}
34
35// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
36unsafe impl Send for EventSetOwner<'_> {}
37// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
38unsafe impl Sync for EventSetOwner<'_> {}
39
40impl_debug_eq_hash_with_functions!(EventSetOwner<'a>; uid, gid, target);