feat: require root privilege to call trigger
Signed-off-by: sisungo <[email protected]>
This commit is contained in:
1 parent
5700a89954
commit
bbf4250677
2 files changed
+37
-16
No files matched your search
+20
-9
@@ -18,14 +18,9 @@ impl Listener {
|
||||
}
|
||||
|
||||
pub async fn accept(&self) -> std::io::Result<Connection> {
|
||||
let stream = self.0.accept().await?.0;
|
||||
let cred = stream.peer_cred()?;
|
||||
Ok(Connection {
|
||||
stream,
|
||||
stream: self.0.accept().await?.0,
|
||||
buf: Vec::with_capacity(128),
|
||||
uid: cred.uid(),
|
||||
gid: cred.gid(),
|
||||
pid: cred.pid().unwrap_or_default() as _,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -34,9 +29,6 @@ impl Listener {
|
||||
pub struct Connection {
|
||||
stream: UnixStream,
|
||||
buf: Vec<u8>,
|
||||
pub uid: u32,
|
||||
pub gid: u32,
|
||||
pub pid: u32,
|
||||
}
|
||||
impl Connection {
|
||||
pub async fn recv(&mut self) -> std::io::Result<Request> {
|
||||
@@ -58,4 +50,23 @@ impl Connection {
|
||||
self.stream.write_all(reply.as_bytes()).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn client_identity(&self) -> Option<ClientIdentity> {
|
||||
let cred = self.stream.peer_cred().ok()?;
|
||||
Some(ClientIdentity {
|
||||
uid: cred.uid(),
|
||||
pid: cred.pid()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ClientIdentity {
|
||||
pub uid: u32,
|
||||
pub pid: i32,
|
||||
}
|
||||
impl ClientIdentity {
|
||||
pub fn is_root(&self) -> bool {
|
||||
self.uid == 0
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user