From e8106bd4de072a8578a36686c8e892b7f00d38f2 Mon Sep 17 00:00:00 2001 From: GrayJack Date: Thu, 31 Oct 2019 05:04:04 -0300 Subject: [PATCH 1/3] Implement utmpx.h itens --- src/unix/bsd/netbsdlike/netbsd/mod.rs | 158 ++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index efd0405912b64..c1e64ee20eb99 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -281,9 +281,36 @@ s! { pub msg_hdr: ::msghdr, pub msg_len: ::c_uint, } + + pub struct __exit_status { + pub e_termination: u16, + pub e_exit: u16, + } } s_no_extra_traits! { + + pub struct utmpx { + pub ut_name: [::c_char; _UTX_USERSIZE], + pub ut_id: [::c_char; _UTX_IDSIZE], + pub ut_line: [::c_char; _UTX_LINESIZE], + pub ut_host: [::c_char; _UTX_HOSTSIZE], + pub ut_session: u16, + pub ut_type: u16, + pub ut_pid: ::pid_t, + pub ut_exit: __exit_status, + pub ut_ss: sockaddr_storage, + pub ut_tv: ::timeval, + pub ut_pad: [u8; _UTX_PADSIZE], + } + + pub struct lastlogx { + pub ll_tv: ::timeval, + pub ll_line: [::c_char; _UTX_LINESIZE], + pub ll_host: [::c_char; _UTX_HOSTSIZE], + pub ll_ss: sockaddr_storage, + } + pub struct in_pktinfo { pub ipi_addr: ::in_addr, pub ipi_ifindex: ::c_uint, @@ -377,6 +404,93 @@ s_no_extra_traits! { cfg_if! { if #[cfg(feature = "extra_traits")] { + impl PartialEq for utmpx { + fn eq(&self, other: &utmpx) -> bool { + self.ut_type == other.ut_type + && self.ut_pid == other.ut_pid + && self.ut_name == other.ut_name + && self.ut_line == other.ut_line + && self.ut_id == other.ut_id + && self.ut_exit == other.ut_exit + && self.ut_session == other.ut_session + && self.ut_tv == other.ut_tv + && self.ut_ss == other.ut_ss + && self.ut_pad == other.ut_pad + && self + .ut_host + .iter() + .zip(other.ut_host.iter()) + .all(|(a,b)| a == b) + } + } + + impl Eq for utmpx {} + + impl ::fmt::Debug for utmpx { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("utmpx") + .field("ut_name", &self.ut_name) + .field("ut_id", &self.ut_id) + .field("ut_line", &self.ut_line) + .field("ut_host", &self.ut_host) + .field("ut_session", &self.ut_session) + .field("ut_type", &self.ut_type) + .field("ut_pid", &self.ut_pid) + .field("ut_exit", &self.ut_exit) + .field("ut_ss", &self.ut_ss) + .field("ut_tv", &self.ut_tv) + .field("ut_pad", &self.ut_pad) + .finish() + } + } + + impl ::hash::Hash for utmpx { + fn hash(&self, state: &mut H) { + self.ut_name.hash(state); + self.ut_type.hash(state); + self.ut_pid.hash(state); + self.ut_line.hash(state); + self.ut_id.hash(state); + self.ut_host.hash(state); + self.ut_exit.hash(state); + self.ut_session.hash(state); + self.ut_tv.hash(state); + self.ut_ss.hash(state); + self.ut_pad.hash(state); + } + } + + impl PartialEq for lastlogx { + fn eq(&self, other: &lastlogx) -> bool { + self.ll_tv == other.ll_tv + && self.ll_line == other.ll_line + && self.ll_host == other.ll_host + && self.ll_ss == other.ll_ss + } + } + + impl Eq for lastlogx {} + + impl ::fmt::Debug for lastlogx { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("lastlogx") + .field("ll_tv", &self.ll_tv) + .field("ll_line", &self.ll_line) + .field("ll_host", &self.ll_host) + .field("ll_ss", &self.ll_ss) + .finish() + } + } + + impl ::hash::Hash for lastlogx { + fn hash(&self, state: &mut H) { + self.ll_tv.hash(state); + self.ll_line.hash(state); + self.ll_host.hash(state); + self.ll_ss.hash(state); + } + } + impl PartialEq for in_pktinfo { fn eq(&self, other: &in_pktinfo) -> bool { self.ipi_addr == other.ipi_addr @@ -1378,6 +1492,28 @@ pub const ONLRET: ::tcflag_t = 0x40; pub const CDTRCTS: ::tcflag_t = 0x00020000; pub const CHWFLOW: ::tcflag_t = ::MDMBUF | ::CRTSCTS | ::CDTRCTS; +// pub const _PATH_UTMPX: &[::c_char; 14] = b"/var/run/utmpx"; +// pub const _PATH_WTMPX: &[::c_char; 14] = b"/var/log/wtmpx"; +// pub const _PATH_LASTLOGX: &[::c_char; 17] = b"/var/log/lastlogx"; +// pub const _PATH_UTMP_UPDATE: &[::c_char; 24] = b"/usr/libexec/utmp_update"; +pub const _UTX_USERSIZE: usize = 32; +pub const _UTX_LINESIZE: usize = 32; +pub const _UTX_PADSIZE: usize = 40; +pub const _UTX_IDSIZE: usize = 4; +pub const _UTX_HOSTSIZE: usize = 256; +pub const EMPTY: u16 = 0; +pub const RUN_LVL: u16 = 1; +pub const BOOT_TIME: u16 = 2; +pub const OLD_TIME: u16 = 3; +pub const NEW_TIME: u16 = 4; +pub const INIT_PROCESS: u16 = 5; +pub const LOGIN_PROCESS: u16 = 6; +pub const USER_PROCESS: u16 = 7; +pub const DEAD_PROCESS: u16 = 8; +pub const ACCOUNTING: u16 = 9; +pub const SIGNATURE: u16 = 10; +pub const DOWN_TIME: u16 = 11; + pub const SOCK_CLOEXEC: ::c_int = 0x10000000; pub const SOCK_NONBLOCK: ::c_int = 0x20000000; @@ -1738,6 +1874,28 @@ extern "C" { buflen: ::size_t, result: *mut *mut ::group, ) -> ::c_int; + + pub fn updwtmpx(file: *const ::c_char, ut: *const utmpx) -> ::c_int; + pub fn getlastlogx( + fname: *const ::c_char, + uid: ::uid_t, + ll: *mut lastlogx, + ) -> *mut lastlogx; + pub fn updlastlogx( + fname: *const ::c_char, + uid: ::uid_t, + ll: *mut lastlogx, + ) -> ::c_int; + pub fn utmpxname(file: *const ::c_char) -> ::c_int; + pub fn getutxent() -> *mut utmpx; + pub fn getutxid(ut: *const utmpx) -> *mut utmpx; + pub fn getutxline(ut: *const utmpx) -> *mut utmpx; + pub fn pututxline(ut: *const utmpx) -> *mut utmpx; + pub fn setutxent(); + pub fn endutxent(); + // TODO: uncomment after utmp implementation + // pub fn getutmp(ux: *const utmpx, u: *mut utmp); + // pub fn getutmpx(u: *const utmp, ux: *mut utmpx); } cfg_if! { From 863e106543128dfaf6812e5554eb6089851f8ec2 Mon Sep 17 00:00:00 2001 From: GrayJack Date: Tue, 19 Nov 2019 03:22:08 -0300 Subject: [PATCH 2/3] Run rustfmt --- src/unix/bsd/netbsdlike/netbsd/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index b03cfdd9fbd39..2f48aac5511f2 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -1907,9 +1907,9 @@ extern "C" { pub fn pututxline(ut: *const utmpx) -> *mut utmpx; pub fn setutxent(); pub fn endutxent(); - // TODO: uncomment after utmp implementation - // pub fn getutmp(ux: *const utmpx, u: *mut utmp); - // pub fn getutmpx(u: *const utmp, ux: *mut utmpx); +// TODO: uncomment after utmp implementation +// pub fn getutmp(ux: *const utmpx, u: *mut utmp); +// pub fn getutmpx(u: *const utmp, ux: *mut utmpx); } cfg_if! { From 40f9253fc995620f038572a90941b82c290f138d Mon Sep 17 00:00:00 2001 From: GrayJack Date: Tue, 19 Nov 2019 06:10:36 -0300 Subject: [PATCH 3/3] Fix style error that `cargo fmt` didn't got --- src/unix/bsd/netbsdlike/netbsd/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 2f48aac5511f2..000ce4431006e 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -283,7 +283,6 @@ s! { pub msg_len: ::c_uint, } - pub struct __exit_status { pub e_termination: u16, pub e_exit: u16,