endpoint_sec/event/event_login_login.rs
1//! [`EventLoginLogin`]
2
3use std::ffi::OsStr;
4
5use endpoint_sec_sys::{es_event_login_login_t, uid_t};
6
7/// Authenticated login event from `/usr/bin/login`.
8#[doc(alias = "es_event_login_login_t")]
9pub struct EventLoginLogin<'a> {
10 /// Raw event
11 pub(crate) raw: &'a es_event_login_login_t,
12}
13
14impl<'a> EventLoginLogin<'a> {
15 /// True iff login was successful.
16 #[inline(always)]
17 pub fn success(&self) -> bool {
18 self.raw.success
19 }
20
21 /// Optional. Failure message generated.
22 #[inline(always)]
23 pub fn failure_message(&self) -> &'a OsStr {
24 // Safety: 'a tied to self, object obtained through ES
25 unsafe { self.raw.failure_message.as_os_str() }
26 }
27
28 /// Username used for login.
29 #[inline(always)]
30 pub fn username(&self) -> &'a OsStr {
31 // Safety: 'a tied to self, object obtained through ES
32 unsafe { self.raw.username.as_os_str() }
33 }
34
35 /// Describes whether or not the uid of the user logged in is available.
36 #[inline(always)]
37 pub fn has_uid(&self) -> bool {
38 self.raw.has_uid
39 }
40
41 /// UID of user that was logged in.
42 #[inline(always)]
43 pub fn uid(&self) -> Option<uid_t> {
44 // Safety: access is gated on documented conditions
45 #[allow(clippy::unnecessary_lazy_evaluations)]
46 self.has_uid().then(|| unsafe { self.raw.anon0.uid })
47 }
48}
49
50// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
51unsafe impl Send for EventLoginLogin<'_> {}
52// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
53unsafe impl Sync for EventLoginLogin<'_> {}
54
55impl_debug_eq_hash_with_functions!(
56 EventLoginLogin<'a>;
57 success, failure_message, username, has_uid, uid,
58);