mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
net: support AIX get_peer_cred
(#5065)
This commit is contained in:
parent
1df874ead4
commit
663e56e983
@ -46,6 +46,9 @@ pub(crate) use self::impl_macos::get_peer_cred;
|
|||||||
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
|
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
|
||||||
pub(crate) use self::impl_solaris::get_peer_cred;
|
pub(crate) use self::impl_solaris::get_peer_cred;
|
||||||
|
|
||||||
|
#[cfg(target_os = "aix")]
|
||||||
|
pub(crate) use self::impl_aix::get_peer_cred;
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "openbsd"))]
|
#[cfg(any(target_os = "linux", target_os = "android", target_os = "openbsd"))]
|
||||||
pub(crate) mod impl_linux {
|
pub(crate) mod impl_linux {
|
||||||
use crate::net::unix::{self, UnixStream};
|
use crate::net::unix::{self, UnixStream};
|
||||||
@ -250,3 +253,31 @@ 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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user