Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to nix 0.26 #447

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion 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.7"
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
29 changes: 19 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,11 @@ 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());
dbg!(&iov);
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,19 +114,19 @@ 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,
)?;
dbg!(&msg);
let mut creds = None;
for cmsg in msg.cmsgs() {
if let nixsocket::ControlMessageOwned::ScmCredentials(c) = cmsg {
Expand All @@ -138,7 +142,12 @@ impl UnauthenticatedClient {
} else {
bail!("No SCM credentials provided");
}
let hello = String::from_utf8_lossy(&buf[0..msg.bytes]);
let iov = msg
.iovs()
.next()
.ok_or_else(|| anyhow::anyhow!("Failed to get a buffer"))?;
dbg!(&iov);
let hello = String::from_utf8_lossy(iov);
if hello != BOOTUPD_HELLO_MSG {
bail!("Didn't receive correct hello message, found: {:?}", &hello);
}
Expand Down