diff options
Diffstat (limited to 'src/net/unix/ucred.rs')
-rw-r--r-- | src/net/unix/ucred.rs | 68 |
1 files changed, 63 insertions, 5 deletions
diff --git a/src/net/unix/ucred.rs b/src/net/unix/ucred.rs index 3cb61d7..43f008b 100644 --- a/src/net/unix/ucred.rs +++ b/src/net/unix/ucred.rs @@ -31,10 +31,15 @@ impl UCred { } } -#[cfg(any(target_os = "linux", target_os = "android", target_os = "openbsd"))] +#[cfg(any( + target_os = "linux", + target_os = "redox", + target_os = "android", + target_os = "openbsd" +))] pub(crate) use self::impl_linux::get_peer_cred; -#[cfg(any(target_os = "netbsd"))] +#[cfg(target_os = "netbsd")] pub(crate) use self::impl_netbsd::get_peer_cred; #[cfg(any(target_os = "dragonfly", target_os = "freebsd"))] @@ -46,7 +51,18 @@ pub(crate) use self::impl_macos::get_peer_cred; #[cfg(any(target_os = "solaris", target_os = "illumos"))] pub(crate) use self::impl_solaris::get_peer_cred; -#[cfg(any(target_os = "linux", target_os = "android", target_os = "openbsd"))] +#[cfg(target_os = "aix")] +pub(crate) use self::impl_aix::get_peer_cred; + +#[cfg(target_os = "espidf")] +pub(crate) use self::impl_noproc::get_peer_cred; + +#[cfg(any( + target_os = "linux", + target_os = "redox", + target_os = "android", + target_os = "openbsd" +))] pub(crate) mod impl_linux { use crate::net::unix::{self, UnixStream}; @@ -55,7 +71,7 @@ pub(crate) mod impl_linux { #[cfg(target_os = "openbsd")] use libc::sockpeercred as ucred; - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(any(target_os = "linux", target_os = "redox", target_os = "android"))] use libc::ucred; pub(crate) fn get_peer_cred(sock: &UnixStream) -> io::Result<super::UCred> { @@ -98,7 +114,7 @@ pub(crate) mod impl_linux { } } -#[cfg(any(target_os = "netbsd"))] +#[cfg(target_os = "netbsd")] pub(crate) mod impl_netbsd { use crate::net::unix::{self, UnixStream}; @@ -250,3 +266,45 @@ pub(crate) mod impl_solaris { } } } + +#[cfg(target_os = "aix")] +pub(crate) mod impl_aix { + use crate::net::unix::UnixStream; + use std::io; + use std::os::unix::io::AsRawFd; + + pub(crate) fn get_peer_cred(sock: &UnixStream) -> io::Result<super::UCred> { + unsafe { + let raw_fd = sock.as_raw_fd(); + + let mut uid = std::mem::MaybeUninit::uninit(); + let mut gid = std::mem::MaybeUninit::uninit(); + + let ret = libc::getpeereid(raw_fd, uid.as_mut_ptr(), gid.as_mut_ptr()); + + if ret == 0 { + Ok(super::UCred { + uid: uid.assume_init(), + gid: gid.assume_init(), + pid: None, + }) + } else { + Err(io::Error::last_os_error()) + } + } + } +} + +#[cfg(target_os = "espidf")] +pub(crate) mod impl_noproc { + use crate::net::unix::UnixStream; + use std::io; + + pub(crate) fn get_peer_cred(_sock: &UnixStream) -> io::Result<super::UCred> { + Ok(super::UCred { + uid: 0, + gid: 0, + pid: None, + }) + } +} |