summaryrefslogtreecommitdiffstats
path: root/tokio-uds
diff options
context:
space:
mode:
authorOhad Ravid <ohad.rv@gmail.com>2018-11-15 16:30:37 +0100
committerToby Lawrence <tobz@users.noreply.github.com>2018-11-15 10:30:37 -0500
commit32a152630f75f0809b63751c0926ed6cf5a26f94 (patch)
tree5b72e12b7de8e9e0a611187bbf17332417db4bfb /tokio-uds
parent9153067d66b7e93efd42561ebba812a15c5b239b (diff)
uds: added solaris support in the `ucred` module (#733)
Diffstat (limited to 'tokio-uds')
-rw-r--r--tokio-uds/src/ucred.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/tokio-uds/src/ucred.rs b/tokio-uds/src/ucred.rs
index 36a706be..bc53ea17 100644
--- a/tokio-uds/src/ucred.rs
+++ b/tokio-uds/src/ucred.rs
@@ -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"))]
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"))]
pub mod impl_linux {
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.
#[cfg(not(target_os = "dragonfly"))]
#[cfg(test)]