From 5bc8b181954e3a4cbce91466e44027600d4c94ef Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sun, 6 Sep 2020 19:38:26 -0400 Subject: [PATCH 01/10] Make bootstrap build on stable This is generally a good idea, and will help with being able to build bootstrap without Python over time as it means we can "just" build with cargo +beta build rather than needing the user to set environment variables. This is a minor step, but a necessary one on that road. --- src/bootstrap/bootstrap.py | 1 - src/bootstrap/lib.rs | 2 -- src/bootstrap/tool.rs | 6 ++++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index c3f1bac177de7..4ab23b40ac34b 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -714,7 +714,6 @@ def build_bootstrap(self): # See also: . if "CARGO_BUILD_TARGET" in env: del env["CARGO_BUILD_TARGET"] - env["RUSTC_BOOTSTRAP"] = '1' env["CARGO_TARGET_DIR"] = build_dir env["RUSTC"] = self.rustc() env["LD_LIBRARY_PATH"] = os.path.join(self.bin_root(), "lib") + \ diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 1b655f55fb071..3b8c9c2d58e0d 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -103,8 +103,6 @@ //! More documentation can be found in each respective module below, and you can //! also check out the `src/bootstrap/README.md` file for more information. -#![feature(drain_filter)] - use std::cell::{Cell, RefCell}; use std::collections::{HashMap, HashSet}; use std::env; diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index fe3f1e78029d7..e8d7de7a5dcaa 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -162,13 +162,15 @@ impl Step for ToolBuild { "the following dependencies are duplicated although they \ have the same features enabled:" ); - for (id, cur, prev) in duplicates.drain_filter(|(_, cur, prev)| cur.2 == prev.2) { + let (same, different): (Vec<_>, Vec<_>) = + duplicates.into_iter().partition(|(_, cur, prev)| cur.2 == prev.2); + for (id, cur, prev) in same { println!(" {}", id); // same features println!(" `{}` ({:?})\n `{}` ({:?})", cur.0, cur.1, prev.0, prev.1); } println!("the following dependencies have different features:"); - for (id, cur, prev) in duplicates { + for (id, cur, prev) in different { println!(" {}", id); let cur_features: HashSet<_> = cur.2.into_iter().collect(); let prev_features: HashSet<_> = prev.2.into_iter().collect(); From ed20eff92be7bcd29ddc74f6bfa603f6698c9504 Mon Sep 17 00:00:00 2001 From: Joe Ellis Date: Tue, 4 Aug 2020 11:18:13 +0100 Subject: [PATCH 02/10] Implementation of peer credentials for Unix sockets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code in `ucred.rs` is based on the work done in PR 13 in the tokio-uds repository on GitHub. Link below for reference: https://github.com/tokio-rs/tokio-uds/pull/13 Credit to Martin Habovštiak (GitHub username Kixunil) and contributors for this work! --- library/std/src/sys/unix/ext/mod.rs | 12 ++++ library/std/src/sys/unix/ext/net.rs | 41 ++++++++++++ library/std/src/sys/unix/ext/ucred.rs | 92 +++++++++++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 library/std/src/sys/unix/ext/ucred.rs diff --git a/library/std/src/sys/unix/ext/mod.rs b/library/std/src/sys/unix/ext/mod.rs index cbdb1c1004984..f43546880983a 100644 --- a/library/std/src/sys/unix/ext/mod.rs +++ b/library/std/src/sys/unix/ext/mod.rs @@ -37,6 +37,18 @@ pub mod process; pub mod raw; pub mod thread; +#[unstable(feature = "peer_credentials_unix_socket", issue = "42839", reason = "unstable")] +#[cfg(any( + target_os = "android", + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "openbsd" +))] +pub mod ucred; + /// A prelude for conveniently writing platform-specific code. /// /// Includes all extension traits, and some important type definitions. diff --git a/library/std/src/sys/unix/ext/net.rs b/library/std/src/sys/unix/ext/net.rs index 0e07106f5ce5c..930a67970005b 100644 --- a/library/std/src/sys/unix/ext/net.rs +++ b/library/std/src/sys/unix/ext/net.rs @@ -30,6 +30,29 @@ use crate::sys::{self, cvt}; use crate::sys_common::{self, AsInner, FromInner, IntoInner}; use crate::time::Duration; +#[cfg(any( + target_os = "android", + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "openbsd" +))] +use crate::os::unix::ucred; + +#[unstable(feature = "peer_credentials_unix_socket", issue = "42839", reason = "unstable")] +#[cfg(any( + target_os = "android", + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "openbsd" +))] +pub use ucred::UCred; + #[cfg(any( target_os = "linux", target_os = "android", @@ -405,6 +428,24 @@ impl UnixStream { SocketAddr::new(|addr, len| unsafe { libc::getpeername(*self.0.as_inner(), addr, len) }) } + /// Gets the peer credentials for this Unix domain socket. + /// + /// # Examples + /// + /// ```no_run + /// use std::os::unix::net::UnixStream; + /// + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// let peer_cred = socket.peer_cred().expect("Couldn't get peer credentials"); + /// Ok(()) + /// } + /// ``` + #[unstable(feature = "peer_credentials_unix_socket", issue = "42839", reason = "unstable")] + pub fn peer_cred(&self) -> io::Result { + ucred::peer_cred(self) + } + /// Sets the read timeout for the socket. /// /// If the provided value is [`None`], then [`read`] calls will block diff --git a/library/std/src/sys/unix/ext/ucred.rs b/library/std/src/sys/unix/ext/ucred.rs new file mode 100644 index 0000000000000..dec97ade126b1 --- /dev/null +++ b/library/std/src/sys/unix/ext/ucred.rs @@ -0,0 +1,92 @@ +//! Unix peer credentials. + +// NOTE: Code in this file is heavily based on work done in PR 13 from the tokio-uds repository on +// GitHub. +// +// For reference, the link is here: https://github.com/tokio-rs/tokio-uds/pull/13 +// Credit to Martin Habovštiak (GitHub username Kixunil) and contributors for this work. + +use libc::{gid_t, uid_t}; + +/// Credentials for a UNIX process for credentials passing. +#[unstable(feature = "peer_credentials_unix_socket", issue = "42839", reason = "unstable")] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] +pub struct UCred { + pub uid: uid_t, + pub gid: gid_t, +} + +#[cfg(any(target_os = "android", target_os = "linux"))] +pub use self::impl_linux::peer_cred; + +#[cfg(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "openbsd" +))] +pub use self::impl_bsd::peer_cred; + +#[cfg(any(target_os = "linux", target_os = "android"))] +pub mod impl_linux { + use super::UCred; + use crate::mem::MaybeUninit; + use crate::os::unix::io::AsRawFd; + use crate::os::unix::net::UnixStream; + use crate::{io, mem}; + + pub fn peer_cred(socket: &UnixStream) -> io::Result { + use libc::{c_void, ucred}; + + let ucred_size = mem::size_of::(); + + // Trivial sanity checks. + assert!(mem::size_of::() <= mem::size_of::()); + assert!(ucred_size <= u32::max_value() as usize); + + let mut ucred_size = ucred_size as u32; + + unsafe { + let mut ucred: ucred = MaybeUninit::uninit().assume_init(); + let ret = libc::getsockopt( + socket.as_raw_fd(), + libc::SOL_SOCKET, + libc::SO_PEERCRED, + &mut ucred as *mut ucred as *mut c_void, + &mut ucred_size, + ); + + if ret == 0 && ucred_size as usize == mem::size_of::() { + Ok(UCred { uid: ucred.uid, gid: ucred.gid }) + } else { + Err(io::Error::last_os_error()) + } + } + } +} + +#[cfg(any( + target_os = "dragonfly", + target_os = "macos", + target_os = "ios", + target_os = "freebsd", + target_os = "openbsd" +))] +pub mod impl_bsd { + use super::UCred; + use crate::io; + use crate::mem::MaybeUninit; + use crate::os::unix::io::AsRawFd; + use crate::os::unix::net::UnixStream; + + pub fn peer_cred(socket: &UnixStream) -> io::Result { + unsafe { + // Create `cred` and attempt to populate it. + let mut cred: UCred = MaybeUninit::uninit().assume_init(); + let ret = libc::getpeereid(socket.as_raw_fd(), &mut cred.uid, &mut cred.gid); + + if ret == 0 { Ok(cred) } else { Err(io::Error::last_os_error()) } + } + } +} From a9ec61db17b68c07816ef1be90e5d138597899e4 Mon Sep 17 00:00:00 2001 From: Joe Ellis Date: Wed, 5 Aug 2020 12:18:32 +0100 Subject: [PATCH 03/10] Remove use of `MaybeUninit` in `ucred.rs` We can simply init the struct directly. There is no real need to use uninit memory here. --- library/std/src/sys/unix/ext/net.rs | 1 + library/std/src/sys/unix/ext/ucred.rs | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/library/std/src/sys/unix/ext/net.rs b/library/std/src/sys/unix/ext/net.rs index 930a67970005b..ac8d6cf53ff8c 100644 --- a/library/std/src/sys/unix/ext/net.rs +++ b/library/std/src/sys/unix/ext/net.rs @@ -433,6 +433,7 @@ impl UnixStream { /// # Examples /// /// ```no_run + /// #![feature(peer_credentials_unix_socket)] /// use std::os::unix::net::UnixStream; /// /// fn main() -> std::io::Result<()> { diff --git a/library/std/src/sys/unix/ext/ucred.rs b/library/std/src/sys/unix/ext/ucred.rs index dec97ade126b1..efaa4d94437f9 100644 --- a/library/std/src/sys/unix/ext/ucred.rs +++ b/library/std/src/sys/unix/ext/ucred.rs @@ -31,7 +31,6 @@ pub use self::impl_bsd::peer_cred; #[cfg(any(target_os = "linux", target_os = "android"))] pub mod impl_linux { use super::UCred; - use crate::mem::MaybeUninit; use crate::os::unix::io::AsRawFd; use crate::os::unix::net::UnixStream; use crate::{io, mem}; @@ -46,9 +45,9 @@ pub mod impl_linux { assert!(ucred_size <= u32::max_value() as usize); let mut ucred_size = ucred_size as u32; + let mut ucred: ucred = ucred { pid: 1, uid: 1, gid: 1 }; unsafe { - let mut ucred: ucred = MaybeUninit::uninit().assume_init(); let ret = libc::getsockopt( socket.as_raw_fd(), libc::SOL_SOCKET, @@ -76,14 +75,12 @@ pub mod impl_linux { pub mod impl_bsd { use super::UCred; use crate::io; - use crate::mem::MaybeUninit; use crate::os::unix::io::AsRawFd; use crate::os::unix::net::UnixStream; pub fn peer_cred(socket: &UnixStream) -> io::Result { + let mut cred = UCred { uid: 1, gid: 1 }; unsafe { - // Create `cred` and attempt to populate it. - let mut cred: UCred = MaybeUninit::uninit().assume_init(); let ret = libc::getpeereid(socket.as_raw_fd(), &mut cred.uid, &mut cred.gid); if ret == 0 { Ok(cred) } else { Err(io::Error::last_os_error()) } From be2637aba7e12474a7044b5ed9ba4a6978d46462 Mon Sep 17 00:00:00 2001 From: Joe Ellis Date: Wed, 5 Aug 2020 12:19:05 +0100 Subject: [PATCH 04/10] Add basic test for Unix peer credentials --- library/std/src/sys/unix/ext/ucred.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/library/std/src/sys/unix/ext/ucred.rs b/library/std/src/sys/unix/ext/ucred.rs index efaa4d94437f9..c737a6a34fd70 100644 --- a/library/std/src/sys/unix/ext/ucred.rs +++ b/library/std/src/sys/unix/ext/ucred.rs @@ -87,3 +87,23 @@ pub mod impl_bsd { } } } + +#[cfg(test)] +mod test { + use crate::os::unix::net::UnixStream; + use libc::{getegid, geteuid}; + + #[test] + fn test_socket_pair() { + // Create two connected sockets and get their peer credentials. They should be equal. + let (sock_a, sock_b) = UnixStream::pair().unwrap(); + let (cred_a, cred_b) = (sock_a.peer_cred().unwrap(), sock_b.peer_cred().unwrap()); + assert_eq!(cred_a, cred_b); + + // Check that the UID and GIDs match up. + let uid = unsafe { geteuid() }; + let gid = unsafe { getegid() }; + assert_eq!(cred_a.uid, uid); + assert_eq!(cred_a.gid, gid); + } +} From cbcf3877b528ff0304e3da6da03349c8a30beed5 Mon Sep 17 00:00:00 2001 From: Joe Ellis Date: Wed, 5 Aug 2020 15:47:45 +0100 Subject: [PATCH 05/10] Use `u32::MAX` instead of `u32::max_value` Co-authored-by: lzutao --- library/std/src/sys/unix/ext/ucred.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/unix/ext/ucred.rs b/library/std/src/sys/unix/ext/ucred.rs index c737a6a34fd70..44df834e8d7c4 100644 --- a/library/std/src/sys/unix/ext/ucred.rs +++ b/library/std/src/sys/unix/ext/ucred.rs @@ -42,7 +42,7 @@ pub mod impl_linux { // Trivial sanity checks. assert!(mem::size_of::() <= mem::size_of::()); - assert!(ucred_size <= u32::max_value() as usize); + assert!(ucred_size <= u32::MAX as usize); let mut ucred_size = ucred_size as u32; let mut ucred: ucred = ucred { pid: 1, uid: 1, gid: 1 }; From 40a830321d82ae1dcb97cd2b964ae52a4ebc9c6a Mon Sep 17 00:00:00 2001 From: Joe Ellis Date: Tue, 8 Sep 2020 09:41:23 +0100 Subject: [PATCH 06/10] Add pid as an option to UCred struct Currently, PID will be populated for Linux, and set to None for BSDs. --- library/std/src/sys/unix/ext/ucred.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/library/std/src/sys/unix/ext/ucred.rs b/library/std/src/sys/unix/ext/ucred.rs index 44df834e8d7c4..8cce968b35ad4 100644 --- a/library/std/src/sys/unix/ext/ucred.rs +++ b/library/std/src/sys/unix/ext/ucred.rs @@ -6,7 +6,7 @@ // For reference, the link is here: https://github.com/tokio-rs/tokio-uds/pull/13 // Credit to Martin Habovštiak (GitHub username Kixunil) and contributors for this work. -use libc::{gid_t, uid_t}; +use libc::{gid_t, pid_t, uid_t}; /// Credentials for a UNIX process for credentials passing. #[unstable(feature = "peer_credentials_unix_socket", issue = "42839", reason = "unstable")] @@ -14,6 +14,8 @@ use libc::{gid_t, uid_t}; pub struct UCred { pub uid: uid_t, pub gid: gid_t, + // pid field is an option because it is not supported on some platforms. + pub pid: Option, } #[cfg(any(target_os = "android", target_os = "linux"))] @@ -57,7 +59,7 @@ pub mod impl_linux { ); if ret == 0 && ucred_size as usize == mem::size_of::() { - Ok(UCred { uid: ucred.uid, gid: ucred.gid }) + Ok(UCred { uid: ucred.uid, gid: ucred.gid, pid: Some(ucred.pid) }) } else { Err(io::Error::last_os_error()) } @@ -79,7 +81,7 @@ pub mod impl_bsd { use crate::os::unix::net::UnixStream; pub fn peer_cred(socket: &UnixStream) -> io::Result { - let mut cred = UCred { uid: 1, gid: 1 }; + let mut cred = UCred { uid: 1, gid: 1, pid: None }; unsafe { let ret = libc::getpeereid(socket.as_raw_fd(), &mut cred.uid, &mut cred.gid); From 7c20be387b1d9447289c0ddd1cd3300bf3199b35 Mon Sep 17 00:00:00 2001 From: Joe Ellis Date: Tue, 8 Sep 2020 10:31:56 +0100 Subject: [PATCH 07/10] Move Unix peer credentials tests to their own file --- library/std/src/sys/unix/ext/ucred.rs | 20 -------------------- library/std/src/sys/unix/ext/ucred/tests.rs | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 20 deletions(-) create mode 100644 library/std/src/sys/unix/ext/ucred/tests.rs diff --git a/library/std/src/sys/unix/ext/ucred.rs b/library/std/src/sys/unix/ext/ucred.rs index 8cce968b35ad4..f7af9f5e96e32 100644 --- a/library/std/src/sys/unix/ext/ucred.rs +++ b/library/std/src/sys/unix/ext/ucred.rs @@ -89,23 +89,3 @@ pub mod impl_bsd { } } } - -#[cfg(test)] -mod test { - use crate::os::unix::net::UnixStream; - use libc::{getegid, geteuid}; - - #[test] - fn test_socket_pair() { - // Create two connected sockets and get their peer credentials. They should be equal. - let (sock_a, sock_b) = UnixStream::pair().unwrap(); - let (cred_a, cred_b) = (sock_a.peer_cred().unwrap(), sock_b.peer_cred().unwrap()); - assert_eq!(cred_a, cred_b); - - // Check that the UID and GIDs match up. - let uid = unsafe { geteuid() }; - let gid = unsafe { getegid() }; - assert_eq!(cred_a.uid, uid); - assert_eq!(cred_a.gid, gid); - } -} diff --git a/library/std/src/sys/unix/ext/ucred/tests.rs b/library/std/src/sys/unix/ext/ucred/tests.rs new file mode 100644 index 0000000000000..efe9946721029 --- /dev/null +++ b/library/std/src/sys/unix/ext/ucred/tests.rs @@ -0,0 +1,16 @@ +use crate::os::unix::net::UnixStream; +use libc::{getegid, geteuid}; + +#[test] +fn test_socket_pair() { + // Create two connected sockets and get their peer credentials. They should be equal. + let (sock_a, sock_b) = UnixStream::pair().unwrap(); + let (cred_a, cred_b) = (sock_a.peer_cred().unwrap(), sock_b.peer_cred().unwrap()); + assert_eq!(cred_a, cred_b); + + // Check that the UID and GIDs match up. + let uid = unsafe { geteuid() }; + let gid = unsafe { getegid() }; + assert_eq!(cred_a.uid, uid); + assert_eq!(cred_a.gid, gid); +} From fa697dfa8179b7f5c5a1207935828e3a938f2fea Mon Sep 17 00:00:00 2001 From: Joe Ellis Date: Tue, 8 Sep 2020 13:11:13 +0100 Subject: [PATCH 08/10] Add documentation to public fields of UCred struct --- library/std/src/sys/unix/ext/ucred.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/library/std/src/sys/unix/ext/ucred.rs b/library/std/src/sys/unix/ext/ucred.rs index f7af9f5e96e32..97f10e52b066c 100644 --- a/library/std/src/sys/unix/ext/ucred.rs +++ b/library/std/src/sys/unix/ext/ucred.rs @@ -12,9 +12,16 @@ use libc::{gid_t, pid_t, uid_t}; #[unstable(feature = "peer_credentials_unix_socket", issue = "42839", reason = "unstable")] #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub struct UCred { + /// The UID part of the peer credential. This is the effective UID of the process at the domain + /// socket's endpoint. pub uid: uid_t, + /// The GID part of the peer credential. This is the effective GID of the process at the domain + /// socket's endpoint. pub gid: gid_t, - // pid field is an option because it is not supported on some platforms. + /// The PID part of the peer credential. This field is optional because the PID part of the + /// peer credentials is not supported on every platform. On platforms where the mechanism to + /// discover the PID exists, this field will be populated to the PID of the process at the + /// domain socket's endpoint. Otherwise, it will be set to None. pub pid: Option, } From 72eef6168f2a5427ccd398a60db7ee56e419b393 Mon Sep 17 00:00:00 2001 From: Joe Ellis Date: Tue, 8 Sep 2020 16:08:21 +0100 Subject: [PATCH 09/10] Conditionally compile peer credentials feature for supported platforms --- library/std/src/sys/unix/ext/net.rs | 9 +++++++++ library/std/src/sys/unix/ext/ucred/tests.rs | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/library/std/src/sys/unix/ext/net.rs b/library/std/src/sys/unix/ext/net.rs index ac8d6cf53ff8c..f664a072c6512 100644 --- a/library/std/src/sys/unix/ext/net.rs +++ b/library/std/src/sys/unix/ext/net.rs @@ -443,6 +443,15 @@ impl UnixStream { /// } /// ``` #[unstable(feature = "peer_credentials_unix_socket", issue = "42839", reason = "unstable")] + #[cfg(any( + target_os = "android", + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "openbsd" + ))] pub fn peer_cred(&self) -> io::Result { ucred::peer_cred(self) } diff --git a/library/std/src/sys/unix/ext/ucred/tests.rs b/library/std/src/sys/unix/ext/ucred/tests.rs index efe9946721029..451b534b266e3 100644 --- a/library/std/src/sys/unix/ext/ucred/tests.rs +++ b/library/std/src/sys/unix/ext/ucred/tests.rs @@ -2,6 +2,15 @@ use crate::os::unix::net::UnixStream; use libc::{getegid, geteuid}; #[test] +#[cfg(any( + target_os = "android", + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "openbsd" +))] fn test_socket_pair() { // Create two connected sockets and get their peer credentials. They should be equal. let (sock_a, sock_b) = UnixStream::pair().unwrap(); From 68ff495afa7687677cf9facf83c5130db24d3acd Mon Sep 17 00:00:00 2001 From: Joe Ellis Date: Thu, 10 Sep 2020 09:11:49 +0100 Subject: [PATCH 10/10] Fix peer credentials for Android --- library/std/src/sys/unix/ext/ucred.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/library/std/src/sys/unix/ext/ucred.rs b/library/std/src/sys/unix/ext/ucred.rs index 97f10e52b066c..ed7516c7f28f8 100644 --- a/library/std/src/sys/unix/ext/ucred.rs +++ b/library/std/src/sys/unix/ext/ucred.rs @@ -43,24 +43,23 @@ pub mod impl_linux { use crate::os::unix::io::AsRawFd; use crate::os::unix::net::UnixStream; use crate::{io, mem}; + use libc::{c_void, getsockopt, socklen_t, ucred, SOL_SOCKET, SO_PEERCRED}; pub fn peer_cred(socket: &UnixStream) -> io::Result { - use libc::{c_void, ucred}; - let ucred_size = mem::size_of::(); // Trivial sanity checks. assert!(mem::size_of::() <= mem::size_of::()); assert!(ucred_size <= u32::MAX as usize); - let mut ucred_size = ucred_size as u32; + let mut ucred_size = ucred_size as socklen_t; let mut ucred: ucred = ucred { pid: 1, uid: 1, gid: 1 }; unsafe { - let ret = libc::getsockopt( + let ret = getsockopt( socket.as_raw_fd(), - libc::SOL_SOCKET, - libc::SO_PEERCRED, + SOL_SOCKET, + SO_PEERCRED, &mut ucred as *mut ucred as *mut c_void, &mut ucred_size, );