Skip to content

Commit

Permalink
Update to nix 0.26
Browse files Browse the repository at this point in the history
This one is important to keep up with, it's like part of a libc.
  • Loading branch information
cgwalters committed Mar 21, 2023
1 parent b997d49 commit be1504e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
43 changes: 39 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ hex = "0.4.3"
libc = "^0.2"
libsystemd = ">= 0.3, < 0.6"
log = "^0.4"
nix = ">= 0.22.1, < 0.24.0"
nix = "0.26"
openat = "0.1.20"
openat-ext = ">= 0.2.2, < 0.3.0"
openssl = "^0.10"
Expand Down
24 changes: 14 additions & 10 deletions src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use anyhow::{bail, Context, Result};
use fn_error_context::context;
use nix::sys::socket as nixsocket;
use serde::{Deserialize, Serialize};
use std::os::unix::io::RawFd;
use std::{
io::{IoSlice, IoSliceMut},
os::unix::io::RawFd,
};

pub(crate) const BOOTUPD_SOCKET: &str = "/run/bootupd.sock";
pub(crate) const MSGSIZE: usize = 1_048_576;
Expand Down Expand Up @@ -40,14 +43,13 @@ impl ClientToDaemonConnection {

#[context("connecting to {}", BOOTUPD_SOCKET)]
pub(crate) fn connect(&mut self) -> Result<()> {
use nix::sys::uio::IoVec;
self.fd = nixsocket::socket(
nixsocket::AddressFamily::Unix,
nixsocket::SockType::SeqPacket,
nixsocket::SockFlag::SOCK_CLOEXEC,
None,
)?;
let addr = nixsocket::SockAddr::new_unix(BOOTUPD_SOCKET)?;
let addr = nixsocket::UnixAddr::new(BOOTUPD_SOCKET)?;
nixsocket::connect(self.fd, &addr)?;
let creds = libc::ucred {
pid: nix::unistd::getpid().as_raw(),
Expand All @@ -56,9 +58,10 @@ impl ClientToDaemonConnection {
};
let creds = nixsocket::UnixCredentials::from(creds);
let creds = nixsocket::ControlMessage::ScmCredentials(&creds);
let _ = nixsocket::sendmsg(
let iov = IoSlice::new(BOOTUPD_HELLO_MSG.as_bytes());
let _ = nixsocket::sendmsg::<()>(
self.fd,
&[IoVec::from_slice(BOOTUPD_HELLO_MSG.as_bytes())],
&[iov],
&[creds],
nixsocket::MsgFlags::MSG_CMSG_CLOEXEC,
None,
Expand Down Expand Up @@ -110,16 +113,15 @@ impl UnauthenticatedClient {
}

pub(crate) fn authenticate(mut self) -> Result<AuthenticatedClient> {
use nix::sys::uio::IoVec;
let fd = self.fd;
let mut buf = [0u8; 1024];

nixsocket::setsockopt(fd, nix::sys::socket::sockopt::PassCred, &true)?;
let iov = IoVec::from_mut_slice(buf.as_mut());
let mut cmsgspace = nix::cmsg_space!(nixsocket::UnixCredentials);
let msg = nixsocket::recvmsg(
let iov = IoSliceMut::new(buf.as_mut());
let msg = nixsocket::recvmsg::<()>(
fd,
&[iov],
&mut [iov],
Some(&mut cmsgspace),
nixsocket::MsgFlags::MSG_CMSG_CLOEXEC,
)?;
Expand All @@ -138,7 +140,9 @@ impl UnauthenticatedClient {
} else {
bail!("No SCM credentials provided");
}
let hello = String::from_utf8_lossy(&buf[0..msg.bytes]);
// SAFETY: We provided a buffer
let iov = msg.iovs().next().unwrap();
let hello = String::from_utf8_lossy(&iov[0..msg.bytes]);
if hello != BOOTUPD_HELLO_MSG {
bail!("Didn't receive correct hello message, found: {:?}", &hello);
}
Expand Down

0 comments on commit be1504e

Please sign in to comment.