Skip to content

Commit 9641dac

Browse files
committed
ra-rpc: add Unix peer cred to RemoteEndpoint::Unix
1 parent 01c26b7 commit 9641dac

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

ra-rpc/src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,24 @@ pub mod client;
2222
#[cfg(feature = "openapi")]
2323
pub mod openapi;
2424

25+
#[derive(Debug, Clone, PartialEq, Eq)]
26+
pub struct UnixPeerCred {
27+
/// Peer process ID (platform-independent representation)
28+
pub pid: u64,
29+
/// Peer user ID
30+
pub uid: u64,
31+
/// Peer group ID
32+
pub gid: u64,
33+
}
34+
2535
#[derive(Debug, Clone, PartialEq, Eq)]
2636
pub enum RemoteEndpoint {
2737
Tcp(SocketAddr),
2838
Quic(SocketAddr),
29-
Unix(PathBuf),
39+
/// Unix domain socket endpoint.
40+
///
41+
/// When available, `peer` can carry SO_PEERCRED (pid/uid/gid) of the caller.
42+
Unix { path: PathBuf, peer: Option<UnixPeerCred> },
3043
Vsock { cid: u32, port: u32 },
3144
Other(String),
3245
}

ra-rpc/src/rocket_helper.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use std::convert::Infallible;
66

77
#[cfg(all(feature = "rocket", feature = "openapi"))]
8-
use crate::openapi::{OpenApiDoc, RenderedDoc};
8+
use crate::openapi::{OpenApiDoc, RenderedDoc};
99
#[cfg(all(feature = "rocket", feature = "openapi"))]
1010
use rocket::response::content::{RawHtml, RawJson};
1111
#[cfg(all(feature = "rocket", feature = "openapi"))]
@@ -265,7 +265,10 @@ impl From<Endpoint> for RemoteEndpoint {
265265
match endpoint {
266266
Endpoint::Tcp(addr) => RemoteEndpoint::Tcp(addr),
267267
Endpoint::Quic(addr) => RemoteEndpoint::Quic(addr),
268-
Endpoint::Unix(path) => RemoteEndpoint::Unix(path),
268+
Endpoint::Unix(path) => RemoteEndpoint::Unix {
269+
path,
270+
peer: None,
271+
},
269272
_ => {
270273
let address = endpoint.to_string();
271274
match address.parse::<VsockEndpoint>() {

0 commit comments

Comments
 (0)