mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-07 00:00:08 +02:00
net: use getpeereid for QNX peer credentials (#8270)
QNX (nto) does not provide LOCAL_PEEREID, which is used by the impl_netbsd module. This causes a compilation failure on QNX. Use getpeereid() instead, following the same pattern as impl_dragonfly and impl_aix. This provides uid/gid but not pid, so UCred::pid() returns None on QNX.
This commit is contained in:
@@ -43,7 +43,7 @@ impl UCred {
|
|||||||
))]
|
))]
|
||||||
pub(crate) use self::impl_linux::get_peer_cred;
|
pub(crate) use self::impl_linux::get_peer_cred;
|
||||||
|
|
||||||
#[cfg(any(target_os = "netbsd", target_os = "nto"))]
|
#[cfg(target_os = "netbsd")]
|
||||||
pub(crate) use self::impl_netbsd::get_peer_cred;
|
pub(crate) use self::impl_netbsd::get_peer_cred;
|
||||||
|
|
||||||
#[cfg(target_os = "dragonfly")]
|
#[cfg(target_os = "dragonfly")]
|
||||||
@@ -75,6 +75,9 @@ pub(crate) use self::impl_aix::get_peer_cred;
|
|||||||
))]
|
))]
|
||||||
pub(crate) use self::impl_noproc::get_peer_cred;
|
pub(crate) use self::impl_noproc::get_peer_cred;
|
||||||
|
|
||||||
|
#[cfg(target_os = "nto")]
|
||||||
|
pub(crate) use self::impl_nto::get_peer_cred;
|
||||||
|
|
||||||
#[cfg(any(
|
#[cfg(any(
|
||||||
target_os = "linux",
|
target_os = "linux",
|
||||||
target_os = "redox",
|
target_os = "redox",
|
||||||
@@ -413,3 +416,34 @@ pub(crate) mod impl_noproc {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "nto")]
|
||||||
|
pub(crate) mod impl_nto {
|
||||||
|
use crate::net::unix::{self, UnixStream};
|
||||||
|
|
||||||
|
use libc::getpeereid;
|
||||||
|
use std::io;
|
||||||
|
use std::mem::MaybeUninit;
|
||||||
|
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 = MaybeUninit::uninit();
|
||||||
|
let mut gid = MaybeUninit::uninit();
|
||||||
|
|
||||||
|
let ret = getpeereid(raw_fd, uid.as_mut_ptr(), gid.as_mut_ptr());
|
||||||
|
|
||||||
|
if ret == 0 {
|
||||||
|
Ok(super::UCred {
|
||||||
|
uid: uid.assume_init() as unix::uid_t,
|
||||||
|
gid: gid.assume_init() as unix::gid_t,
|
||||||
|
pid: None,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Err(io::Error::last_os_error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user