endpoint_sec/event/
event_sudo.rs1use std::ffi::OsStr;
4
5use endpoint_sec_sys::{es_event_sudo_t, es_sudo_plugin_type_t, es_sudo_reject_info_t};
6use libc::uid_t;
7
8#[doc(alias = "es_event_sudo_t")]
10pub struct EventSudo<'a> {
11 pub(crate) raw: &'a es_event_sudo_t,
13}
14
15impl<'a> EventSudo<'a> {
16 #[inline(always)]
18 pub fn success(&self) -> bool {
19 self.raw.success
20 }
21
22 #[inline(always)]
24 pub fn reject_info(&self) -> Option<RejectInfo<'a>> {
25 match self.success() && (self.raw.reject_info.is_null() == false) {
26 false => None,
27 true => Some(RejectInfo {
28 raw: unsafe { &*self.raw.reject_info },
30 }),
31 }
32 }
33 #[inline(always)]
35 pub fn has_from_uid(&self) -> bool {
36 self.raw.has_from_uid
37 }
38 #[inline(always)]
40 pub fn from_uid(&self) -> Option<uid_t> {
41 #[allow(clippy::unnecessary_lazy_evaluations)]
43 self.has_from_uid().then(|| unsafe { self.raw.from_uid.uid })
44 }
45 #[inline(always)]
47 pub fn from_username(&self) -> Option<&'a OsStr> {
48 unsafe { self.raw.from_username.as_opt_os_str() }
50 }
51 #[inline(always)]
53 pub fn has_to_uid(&self) -> bool {
54 self.raw.has_to_uid
55 }
56 #[inline(always)]
58 pub fn to_uid(&self) -> Option<uid_t> {
59 if self.success() == false {
60 return None;
61 }
62 #[allow(clippy::unnecessary_lazy_evaluations)]
64 self.has_to_uid().then(|| unsafe { self.raw.to_uid.uid })
65 }
66 #[inline(always)]
68 pub fn to_username(&self) -> Option<&'a OsStr> {
69 if self.success() == false {
70 return None;
71 }
72 unsafe { Some(self.raw.to_username.as_os_str()) }
74 }
75 #[inline(always)]
77 pub fn command(&self) -> Option<&'a OsStr> {
78 unsafe { self.raw.command.as_opt_os_str() }
80 }
81}
82
83unsafe impl Send for EventSudo<'_> {}
85unsafe impl Sync for EventSudo<'_> {}
87
88impl_debug_eq_hash_with_functions!(EventSudo<'a>; success, reject_info, has_from_uid, from_uid, from_username, has_to_uid, to_uid, to_username, command);
89
90#[doc(alias = "es_sudo_reject_info_t")]
92pub struct RejectInfo<'a> {
93 raw: &'a es_sudo_reject_info_t,
95}
96
97impl<'a> RejectInfo<'a> {
98 #[inline(always)]
100 pub fn plugin_name(&self) -> &'a OsStr {
101 unsafe { self.raw.plugin_name.as_os_str() }
103 }
104 #[inline(always)]
106 pub fn plugin_type(&self) -> es_sudo_plugin_type_t {
107 self.raw.plugin_type
108 }
109 #[inline(always)]
111 pub fn failure_message(&self) -> &'a OsStr {
112 unsafe { self.raw.failure_message.as_os_str() }
114 }
115}
116
117unsafe impl Send for RejectInfo<'_> {}
119
120impl_debug_eq_hash_with_functions!(RejectInfo<'a>; plugin_name, plugin_type, failure_message);