mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
uds: added solaris support in the ucred module (#733)
This commit is contained in:
committed by
Toby Lawrence
parent
9153067d66
commit
32a152630f
@@ -15,6 +15,9 @@ pub use self::impl_linux::get_peer_cred;
|
|||||||
#[cfg(any(target_os = "dragonfly", target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
|
#[cfg(any(target_os = "dragonfly", target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
|
||||||
pub use self::impl_macos::get_peer_cred;
|
pub use self::impl_macos::get_peer_cred;
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "solaris"))]
|
||||||
|
pub use self::impl_solaris::get_peer_cred;
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
pub mod impl_linux {
|
pub mod impl_linux {
|
||||||
use libc::{c_void, getsockopt, socklen_t, SOL_SOCKET, SO_PEERCRED};
|
use libc::{c_void, getsockopt, socklen_t, SOL_SOCKET, SO_PEERCRED};
|
||||||
@@ -85,6 +88,51 @@ pub mod impl_macos {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "solaris"))]
|
||||||
|
pub mod impl_solaris {
|
||||||
|
use std::io;
|
||||||
|
use std::os::unix::io::AsRawFd;
|
||||||
|
use UnixStream;
|
||||||
|
use std::ptr;
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
enum ucred_t {}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
fn ucred_free(cred: *mut ucred_t);
|
||||||
|
fn ucred_geteuid(cred: *const ucred_t) -> super::uid_t;
|
||||||
|
fn ucred_getegid(cred: *const ucred_t) -> super::gid_t;
|
||||||
|
|
||||||
|
fn getpeerucred(fd: ::std::os::raw::c_int, cred: *mut *mut ucred_t) -> ::std::os::raw::c_int;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_peer_cred(sock: &UnixStream) -> io::Result<super::UCred> {
|
||||||
|
unsafe {
|
||||||
|
let raw_fd = sock.as_raw_fd();
|
||||||
|
|
||||||
|
let mut cred = ptr::null_mut::<*mut ucred_t>() as *mut ucred_t;
|
||||||
|
|
||||||
|
let ret = getpeerucred(raw_fd, &mut cred);
|
||||||
|
|
||||||
|
if ret == 0 {
|
||||||
|
let uid = ucred_geteuid(cred);
|
||||||
|
let gid = ucred_getegid(cred);
|
||||||
|
|
||||||
|
ucred_free(cred);
|
||||||
|
|
||||||
|
Ok(super::UCred {
|
||||||
|
uid,
|
||||||
|
gid,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Err(io::Error::last_os_error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Note that LOCAL_PEERCRED is not supported on DragonFly (yet). So do not run tests.
|
// Note that LOCAL_PEERCRED is not supported on DragonFly (yet). So do not run tests.
|
||||||
#[cfg(not(target_os = "dragonfly"))]
|
#[cfg(not(target_os = "dragonfly"))]
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
Reference in New Issue
Block a user