diff options
-rw-r--r-- | CHANGELOG.md | 5 | ||||
-rw-r--r-- | src/sys/socket/mod.rs | 12 | ||||
-rw-r--r-- | test/sys/test_socket.rs | 16 |
3 files changed, 18 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f36c01b..2e2e0453 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Added `User::from_uid`, `User::from_name`, `User::from_gid` and `Group::from_name`, ([#1139](https://github.com/nix-rust/nix/pull/1139)) + - Added `linkat` ([#1101](https://github.com/nix-rust/nix/pull/1101)) @@ -39,6 +40,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Changed - `sys::termios::BaudRate` now implements `TryFrom<speed_t>` instead of `From<speed_t>`. The old `From` implementation would panic on failure. + +- `sys::socket::ControlMessage::ScmCredentials` and + `sys::socket::ControlMessageOwned::ScmCredentials` now wrap `UnixCredentials` + rather than `libc::ucred`. ([#1159](https://github.com/nix-rust/nix/pull/1159)) - `sys::socket::recvmsg` now takes a plain `Vec` instead of a `CmsgBuffer` diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 5ecf088a..aa280747 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -190,7 +190,7 @@ cfg_if! { /// Unix credentials of the sending process. /// /// This struct is used with the `SO_PEERCRED` ancillary message for UNIX sockets. - #[repr(C)] + #[repr(transparent)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct UnixCredentials(libc::ucred); @@ -368,7 +368,7 @@ pub enum ControlMessageOwned { /// Received version of /// [`ControlMessage::ScmCredentials`][#enum.ControlMessage.html#variant.ScmCredentials] #[cfg(any(target_os = "android", target_os = "linux"))] - ScmCredentials(libc::ucred), + ScmCredentials(UnixCredentials), /// A message of type `SCM_TIMESTAMP`, containing the time the /// packet was received by the kernel. /// @@ -496,7 +496,7 @@ impl ControlMessageOwned { #[cfg(any(target_os = "android", target_os = "linux"))] (libc::SOL_SOCKET, libc::SCM_CREDENTIALS) => { let cred: libc::ucred = ptr::read_unaligned(p as *const _); - ControlMessageOwned::ScmCredentials(cred) + ControlMessageOwned::ScmCredentials(cred.into()) } (libc::SOL_SOCKET, libc::SCM_TIMESTAMP) => { let tv: libc::timeval = ptr::read_unaligned(p as *const _); @@ -584,10 +584,8 @@ pub enum ControlMessage<'a> { /// /// For further information, please refer to the /// [`unix(7)`](http://man7.org/linux/man-pages/man7/unix.7.html) man page. - // FIXME: When `#[repr(transparent)]` is stable, use it on `UnixCredentials` - // and put that in here instead of a raw ucred. #[cfg(any(target_os = "android", target_os = "linux"))] - ScmCredentials(&'a libc::ucred), + ScmCredentials(&'a UnixCredentials), /// Set IV for `AF_ALG` crypto API. /// @@ -655,7 +653,7 @@ impl<'a> ControlMessage<'a> { }, #[cfg(any(target_os = "android", target_os = "linux"))] ControlMessage::ScmCredentials(creds) => { - creds as *const libc::ucred as *const u8 + &creds.0 as *const libc::ucred as *const u8 } #[cfg(any(target_os = "android", target_os = "linux"))] ControlMessage::AlgSetIv(iv) => { diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 13d7b6b0..bd5c373b 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -561,7 +561,7 @@ fn test_scm_credentials() { pid: getpid().as_raw(), uid: getuid().as_raw(), gid: getgid().as_raw(), - }; + }.into(); let cmsg = ControlMessage::ScmCredentials(&cred); assert_eq!(sendmsg(send, &iov, &[cmsg], MsgFlags::empty(), None).unwrap(), 5); close(send).unwrap(); @@ -577,9 +577,9 @@ fn test_scm_credentials() { for cmsg in msg.cmsgs() { if let ControlMessageOwned::ScmCredentials(cred) = cmsg { assert!(received_cred.is_none()); - assert_eq!(cred.pid, getpid().as_raw()); - assert_eq!(cred.uid, getuid().as_raw()); - assert_eq!(cred.gid, getgid().as_raw()); + assert_eq!(cred.pid(), getpid().as_raw()); + assert_eq!(cred.uid(), getuid().as_raw()); + assert_eq!(cred.gid(), getgid().as_raw()); received_cred = Some(cred); } else { panic!("unexpected cmsg"); @@ -641,7 +641,7 @@ fn test_impl_scm_credentials_and_rights(mut space: Vec<u8>) { pid: getpid().as_raw(), uid: getuid().as_raw(), gid: getgid().as_raw(), - }; + }.into(); let fds = [r]; let cmsgs = [ ControlMessage::ScmCredentials(&cred), @@ -669,9 +669,9 @@ fn test_impl_scm_credentials_and_rights(mut space: Vec<u8>) { } ControlMessageOwned::ScmCredentials(cred) => { assert!(received_cred.is_none()); - assert_eq!(cred.pid, getpid().as_raw()); - assert_eq!(cred.uid, getuid().as_raw()); - assert_eq!(cred.gid, getgid().as_raw()); + assert_eq!(cred.pid(), getpid().as_raw()); + assert_eq!(cred.uid(), getuid().as_raw()); + assert_eq!(cred.gid(), getgid().as_raw()); received_cred = Some(cred); } _ => panic!("unexpected cmsg"), |