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 May 5, 2023
1 parent a861b30 commit 727d082
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
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

0 comments on commit 727d082

Please sign in to comment.